public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54020] New: [c++0x] incorrectly accepted constexpr functions
@ 2012-07-18 19:34 luto at mit dot edu
2012-07-19 6:40 ` [Bug c++/54020] " jakub at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: luto at mit dot edu @ 2012-07-18 19:34 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54020
Bug #: 54020
Summary: [c++0x] incorrectly accepted constexpr functions
Classification: Unclassified
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: luto@mit.edu
Tested on a somewhat recent trunk build as well as 4.7-some branch version.
// Preliminaries.
extern int nonconst_func(int);
constexpr int identity(int x) { return x; }
constexpr int zero() { return identity(0); }
constexpr int one() { return identity(1); }
// Correctly accepted.
constexpr int three = one() ? 3 : nonconst_func(0);
// Incorrectly accepted. See [dcl.constexpr] #5:
// For a constexpr function, if no function argument values exist
// such that the function invocation sub-stitution would produce a
// constant expression (5.19), the program is ill-formed; no diagnostic
// required.
constexpr int bogus() { return zero () ? 3 : nonconst_func(0); }
// Correctly rejected (not sure why).
constexpr int correct_error() { return nonconst_func(0); }
// Correctly rejected.
constexpr int z = bogus();
// This is also correctly rejected.
constexpr int correct_failure() { return 0 ? 3 : nonconst_func(0); }
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/54020] [c++0x] incorrectly accepted constexpr functions
2012-07-18 19:34 [Bug c++/54020] New: [c++0x] incorrectly accepted constexpr functions luto at mit dot edu
@ 2012-07-19 6:40 ` jakub at gcc dot gnu.org
2012-07-19 15:42 ` luto at mit dot edu
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-07-19 6:40 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54020
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-07-19 06:40:41 UTC ---
... the program is ill-formed; no diagnostic required.
^^^^^^^^^^^^^^^^^^^^^^^
GCC doesn't immediately see that the first operand of ?: is zero or non-zero in
that function, so assumes it could be either zero or non-zero and doesn't
diagnose, you get diagnostics only when you are actually using the function in
some constexpr var initializer or other context where a constant expression is
required.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/54020] [c++0x] incorrectly accepted constexpr functions
2012-07-18 19:34 [Bug c++/54020] New: [c++0x] incorrectly accepted constexpr functions luto at mit dot edu
2012-07-19 6:40 ` [Bug c++/54020] " jakub at gcc dot gnu.org
@ 2012-07-19 15:42 ` luto at mit dot edu
2012-07-25 9:40 ` paolo.carlini at oracle dot com
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: luto at mit dot edu @ 2012-07-19 15:42 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54020
--- Comment #2 from Andy Lutomirski <luto at mit dot edu> 2012-07-19 15:41:51 UTC ---
I clearly failed at reading comprehension yesterday.
Maybe this should be considered as more of an enhancement request (like
PR54021): it would be nicer for the user if constexpr worked the same with an
without optimization. Otherwise there'll probably be reports of code that
builds at -O2 but not -O0.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/54020] [c++0x] incorrectly accepted constexpr functions
2012-07-18 19:34 [Bug c++/54020] New: [c++0x] incorrectly accepted constexpr functions luto at mit dot edu
2012-07-19 6:40 ` [Bug c++/54020] " jakub at gcc dot gnu.org
2012-07-19 15:42 ` luto at mit dot edu
@ 2012-07-25 9:40 ` paolo.carlini at oracle dot com
2012-07-25 13:53 ` jason at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-07-25 9:40 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54020
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at gcc dot gnu.org
--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-07-25 09:39:36 UTC ---
Let's add Jason in CC (about the -O0 vs -O2 thing, in particular)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/54020] [c++0x] incorrectly accepted constexpr functions
2012-07-18 19:34 [Bug c++/54020] New: [c++0x] incorrectly accepted constexpr functions luto at mit dot edu
` (2 preceding siblings ...)
2012-07-25 9:40 ` paolo.carlini at oracle dot com
@ 2012-07-25 13:53 ` jason at gcc dot gnu.org
2012-07-25 14:57 ` jason at gcc dot gnu.org
2012-07-25 15:04 ` jason at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2012-07-25 13:53 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54020
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2012-07-25
AssignedTo|unassigned at gcc dot |jason at gcc dot gnu.org
|gnu.org |
Ever Confirmed|0 |1
--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> 2012-07-25 13:53:22 UTC ---
This testcase behaves the same at -O0 or -O2. Seems like a simple enough
enhancement, though.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/54020] [c++0x] incorrectly accepted constexpr functions
2012-07-18 19:34 [Bug c++/54020] New: [c++0x] incorrectly accepted constexpr functions luto at mit dot edu
` (3 preceding siblings ...)
2012-07-25 13:53 ` jason at gcc dot gnu.org
@ 2012-07-25 14:57 ` jason at gcc dot gnu.org
2012-07-25 15:04 ` jason at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2012-07-25 14:57 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54020
--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> 2012-07-25 14:57:01 UTC ---
Author: jason
Date: Wed Jul 25 14:56:57 2012
New Revision: 189851
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=189851
Log:
PR c++/54020
* semantics.c (potential_constant_expression_1) [COND_EXPR]: Call
maybe_constant_value.
Added:
trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-neg2.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/semantics.c
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/54020] [c++0x] incorrectly accepted constexpr functions
2012-07-18 19:34 [Bug c++/54020] New: [c++0x] incorrectly accepted constexpr functions luto at mit dot edu
` (4 preceding siblings ...)
2012-07-25 14:57 ` jason at gcc dot gnu.org
@ 2012-07-25 15:04 ` jason at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2012-07-25 15:04 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54020
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
Target Milestone|--- |4.8.0
Severity|normal |enhancement
--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> 2012-07-25 15:04:27 UTC ---
Fixed for 4.8.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-07-25 15:04 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-18 19:34 [Bug c++/54020] New: [c++0x] incorrectly accepted constexpr functions luto at mit dot edu
2012-07-19 6:40 ` [Bug c++/54020] " jakub at gcc dot gnu.org
2012-07-19 15:42 ` luto at mit dot edu
2012-07-25 9:40 ` paolo.carlini at oracle dot com
2012-07-25 13:53 ` jason at gcc dot gnu.org
2012-07-25 14:57 ` jason at gcc dot gnu.org
2012-07-25 15:04 ` 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).