public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/57979] New: G++ accepts constant expression defined using floating point glvalue
@ 2013-07-25 8:13 jogojapan at gmail dot com
2013-07-25 9:16 ` [Bug c++/57979] G++ accepts constant expression defined using floating point non-constexpr glvalue jogojapan at gmail dot com
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: jogojapan at gmail dot com @ 2013-07-25 8:13 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57979
Bug ID: 57979
Summary: G++ accepts constant expression defined using floating
point glvalue
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jogojapan at gmail dot com
The following code is accepted and compiled without error by G++:
int main()
{
const float f1 = 0.0;
constexpr float f2 = f1;
return 0;
}
Note that the declaration of f2 as constexpr requires f1 to be a constant
expression, which it isn't, according to §5.19/2:
====(QUOTE)========
A condition-expression is a core constant expression unless it involves
[...]
[..9th item..]
- an lvalue-to-rvalue conversion (4.1) unless it is applied to [...] a glvalue
of integral or enumeration type that refers to a non-volatile const object with
a preceding initialization, initialized with a constant expresion, or
[...]
====(ENDQUOTE)====
So if f1 had been declared as const int, the code would be acceptable, but
there is no such exception for floating point (or any other non-integral or
non-enum type).
Tested with a 20130708 snapshot checkout from the master branch of the
git-mirror of the repository. (I'll test with a more recent version soon.)
>From gcc-bugs-return-426666-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Jul 25 08:20:39 2013
Return-Path: <gcc-bugs-return-426666-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 26049 invoked by alias); 25 Jul 2013 08:20:38 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 25957 invoked by uid 48); 25 Jul 2013 08:20:33 -0000
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/57979] G++ accepts constant expression defined using floating point non-constexpr glvalue
Date: Thu, 25 Jul 2013 08:20:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: redi at gcc dot gnu.org
X-Bugzilla-Status: NEW
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_status cf_reconfirmed_on everconfirmed
Message-ID: <bug-57979-4-OwOpt2R7u1@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-57979-4@http.gcc.gnu.org/bugzilla/>
References: <bug-57979-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2013-07/txt/msg01173.txt.bz2
Content-length: 501
http://gcc.gnu.org/bugzilla/show_bug.cgi?idW979
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2013-07-25
Ever confirmed|0 |1
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It's accepted even with -pedantic
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/57979] G++ accepts constant expression defined using floating point non-constexpr glvalue
2013-07-25 8:13 [Bug c++/57979] New: G++ accepts constant expression defined using floating point glvalue jogojapan at gmail dot com
@ 2013-07-25 9:16 ` jogojapan at gmail dot com
2014-09-05 9:38 ` paolo.carlini at oracle dot com
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jogojapan at gmail dot com @ 2013-07-25 9:16 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57979
--- Comment #2 from Johannes Goller <jogojapan at gmail dot com> ---
Confirmed that the problem exists in the most recent version of GCC 4.9, i.e. a
20130725 snapshot from the master branch.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/57979] G++ accepts constant expression defined using floating point non-constexpr glvalue
2013-07-25 8:13 [Bug c++/57979] New: G++ accepts constant expression defined using floating point glvalue jogojapan at gmail dot com
2013-07-25 9:16 ` [Bug c++/57979] G++ accepts constant expression defined using floating point non-constexpr glvalue jogojapan at gmail dot com
@ 2014-09-05 9:38 ` paolo.carlini at oracle dot com
2014-11-18 14:03 ` jason at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-09-05 9:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57979
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ville.voutilainen at gmail dot com
--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> ---
*** Bug 59676 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/57979] G++ accepts constant expression defined using floating point non-constexpr glvalue
2013-07-25 8:13 [Bug c++/57979] New: G++ accepts constant expression defined using floating point glvalue jogojapan at gmail dot com
2013-07-25 9:16 ` [Bug c++/57979] G++ accepts constant expression defined using floating point non-constexpr glvalue jogojapan at gmail dot com
2014-09-05 9:38 ` paolo.carlini at oracle dot com
@ 2014-11-18 14:03 ` jason at gcc dot gnu.org
2014-11-18 14:16 ` ville.voutilainen at gmail dot com
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2014-11-18 14:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57979
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at gcc dot gnu.org
--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> ---
This was introduced by the fix for bug 21089; decay_conversion and
convert_like_real shouldn't be pulling values out of variables that are not
decl_const_var_p. The trick is fixing that without breaking the static
initialization optimization that 21089 is about. I guess allowing
maybe_constant_init to be more aggressive than *_constant_value is the way to
approach this.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/57979] G++ accepts constant expression defined using floating point non-constexpr glvalue
2013-07-25 8:13 [Bug c++/57979] New: G++ accepts constant expression defined using floating point glvalue jogojapan at gmail dot com
` (2 preceding siblings ...)
2014-11-18 14:03 ` jason at gcc dot gnu.org
@ 2014-11-18 14:16 ` ville.voutilainen at gmail dot com
2014-11-18 14:17 ` ville.voutilainen at gmail dot com
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: ville.voutilainen at gmail dot com @ 2014-11-18 14:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57979
--- Comment #5 from Ville Voutilainen <ville.voutilainen at gmail dot com> ---
I think this should be put on hold, since EWG told CWG in Rapperswil
that const floats should perform the same magic as const ints do, see
http://open-std.org/JTC1/SC22/WG21/docs/cwg_closed.html#1826
which EWG suggested CWG to reopen and resolve.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/57979] G++ accepts constant expression defined using floating point non-constexpr glvalue
2013-07-25 8:13 [Bug c++/57979] New: G++ accepts constant expression defined using floating point glvalue jogojapan at gmail dot com
` (3 preceding siblings ...)
2014-11-18 14:16 ` ville.voutilainen at gmail dot com
@ 2014-11-18 14:17 ` ville.voutilainen at gmail dot com
2014-11-19 22:06 ` jason at gcc dot gnu.org
2014-11-20 3:43 ` jason at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: ville.voutilainen at gmail dot com @ 2014-11-18 14:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57979
--- Comment #6 from Ville Voutilainen <ville.voutilainen at gmail dot com> ---
In other words, EWG wants the standard to be changed so that GCC's behavior
actually becomes conforming, as far as I understand the intent.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/57979] G++ accepts constant expression defined using floating point non-constexpr glvalue
2013-07-25 8:13 [Bug c++/57979] New: G++ accepts constant expression defined using floating point glvalue jogojapan at gmail dot com
` (4 preceding siblings ...)
2014-11-18 14:17 ` ville.voutilainen at gmail dot com
@ 2014-11-19 22:06 ` jason at gcc dot gnu.org
2014-11-20 3:43 ` jason at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2014-11-19 22:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57979
--- Comment #7 from Jason Merrill <jason at gcc dot gnu.org> ---
Author: jason
Date: Wed Nov 19 22:06:17 2014
New Revision: 217814
URL: https://gcc.gnu.org/viewcvs?rev=217814&root=gcc&view=rev
Log:
PR c++/57979
* init.c (decl_really_constant_value): Rename from
integral_constant_value.
(scalar_constant_value): Similar but limited to scalar results.
(decl_constant_value_safe): Remove.
(constant_value_1): Respect return_aggregate_cst_ok_p.
* typeck.c (decay_conversion): Use scalar_constant_value.
* call.c (convert_like_real): Likewise.
* cvt.c (ocp_convert): No need to check CLASS_TYPE_P.
* typeck.c (decay_conversion): Or ARRAY_TYPE.
* constexpr.c (struct constexpr_ctx): Add strict field.
(cxx_eval_constant_expression) [VAR_DECL]: Use it to select between
decl_constant_value and decl_really_constant_value.
(cxx_eval_outermost_constant_expr): Add strict parm.
(maybe_constant_init): Not strict.
(potential_constant_expression_1): Add strict parm.
Shorten most internal calls with RECUR macro.
* cp-tree.h, pt.c, semantics.c: Adjust.
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/call.c
trunk/gcc/cp/constexpr.c
trunk/gcc/cp/cp-tree.h
trunk/gcc/cp/cvt.c
trunk/gcc/cp/decl.c
trunk/gcc/cp/init.c
trunk/gcc/cp/pt.c
trunk/gcc/cp/semantics.c
trunk/gcc/cp/typeck.c
trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-object2.C
trunk/gcc/testsuite/g++.dg/cpp0x/nullptr06.C
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/57979] G++ accepts constant expression defined using floating point non-constexpr glvalue
2013-07-25 8:13 [Bug c++/57979] New: G++ accepts constant expression defined using floating point glvalue jogojapan at gmail dot com
` (5 preceding siblings ...)
2014-11-19 22:06 ` jason at gcc dot gnu.org
@ 2014-11-20 3:43 ` jason at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2014-11-20 3:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57979
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
Assignee|unassigned at gcc dot gnu.org |jason at gcc dot gnu.org
Target Milestone|--- |5.0
--- Comment #8 from Jason Merrill <jason at gcc dot gnu.org> ---
(In reply to Ville Voutilainen from comment #5)
> I think this should be put on hold, since EWG told CWG in Rapperswil
> that const floats should perform the same magic as const ints do, see
> http://open-std.org/JTC1/SC22/WG21/docs/cwg_closed.html#1826
> which EWG suggested CWG to reopen and resolve.
I had already done most of the work before you made this comment. :)
You might want to ping Mike about that again, as I don't think it came up in
core at the Urbana meeting.
Fixed for gcc 5.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-11-20 3:43 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-25 8:13 [Bug c++/57979] New: G++ accepts constant expression defined using floating point glvalue jogojapan at gmail dot com
2013-07-25 9:16 ` [Bug c++/57979] G++ accepts constant expression defined using floating point non-constexpr glvalue jogojapan at gmail dot com
2014-09-05 9:38 ` paolo.carlini at oracle dot com
2014-11-18 14:03 ` jason at gcc dot gnu.org
2014-11-18 14:16 ` ville.voutilainen at gmail dot com
2014-11-18 14:17 ` ville.voutilainen at gmail dot com
2014-11-19 22:06 ` jason at gcc dot gnu.org
2014-11-20 3:43 ` jason at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).