public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/65327] New: GCC rejects "constexpr volatile int i = 5;"
@ 2015-03-05 17:44 Casey at Carter dot net
2015-03-05 18:49 ` [Bug c++/65327] " yaghmour.shafik at gmail dot com
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Casey at Carter dot net @ 2015-03-05 17:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65327
Bug ID: 65327
Summary: GCC rejects "constexpr volatile int i = 5;"
Product: gcc
Version: 5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: Casey at Carter dot net
See
http://stackoverflow.com/questions/28883510/can-constexpr-be-combined-with-volatile
for discussion. GCC 5 (Identified as "5.0.0 HEAD 20150304" on Wandbox at
http://melpon.org/wandbox/permlink/u7BC3wFEfMv0zrVN) rejects this program:
int main() {
constexpr volatile int i = 5;
}
with the diagnostic:
prog.cc: In function 'int main()':
prog.cc:3:28: error: both 'volatile' and 'constexpr' cannot be used here
constexpr volatile int i = 5;
AFAICT, this program is well-formed: `constexpr` can be applied to literal
types, which includes scalar types, which includes cv-qualified arithmetic
types. Semantically, I *think* "constexpr volatile" is equivalent to "const
volatile" since "constexpr" objects are implicitly "const" but lvalue-to-rvalue
conversions applied to volatile glvalues cannot be part of a
core-constant-expression.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/65327] GCC rejects "constexpr volatile int i = 5;"
2015-03-05 17:44 [Bug c++/65327] New: GCC rejects "constexpr volatile int i = 5;" Casey at Carter dot net
@ 2015-03-05 18:49 ` yaghmour.shafik at gmail dot com
2015-03-16 9:42 ` mpolacek at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: yaghmour.shafik at gmail dot com @ 2015-03-05 18:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65327
Shafik Yaghmour <yaghmour.shafik at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |yaghmour.shafik at gmail dot com
--- Comment #1 from Shafik Yaghmour <yaghmour.shafik at gmail dot com> ---
Defect report 1688:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4093.html#1688
confirms that this is valid, and it says:
"The combination is intentionally permitted and could be used in some
circumstances to force constant initialization."
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/65327] GCC rejects "constexpr volatile int i = 5;"
2015-03-05 17:44 [Bug c++/65327] New: GCC rejects "constexpr volatile int i = 5;" Casey at Carter dot net
2015-03-05 18:49 ` [Bug c++/65327] " yaghmour.shafik at gmail dot com
@ 2015-03-16 9:42 ` mpolacek at gcc dot gnu.org
2015-03-16 9:56 ` mpolacek at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-03-16 9:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65327
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2015-03-16
CC| |mpolacek at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed then. I wonder if
--- gcc/cp/decl.c
+++ gcc/cp/decl.c
@@ -10134,8 +10134,9 @@ grokdeclarator (const cp_declarator *declarator,
the object as `const'. */
if (constexpr_p && innermost_code != cdk_function)
{
- if (type_quals & TYPE_QUAL_VOLATILE)
- error ("both %<volatile%> and %<constexpr%> cannot be used here");
+ /* DR1688 says that a `constexpr' specifier in combination with
+ `volatile' is valid. */
+
if (TREE_CODE (type) != REFERENCE_TYPE)
{
type_quals |= TYPE_QUAL_CONST;
is enough...
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/65327] GCC rejects "constexpr volatile int i = 5;"
2015-03-05 17:44 [Bug c++/65327] New: GCC rejects "constexpr volatile int i = 5;" Casey at Carter dot net
2015-03-05 18:49 ` [Bug c++/65327] " yaghmour.shafik at gmail dot com
2015-03-16 9:42 ` mpolacek at gcc dot gnu.org
@ 2015-03-16 9:56 ` mpolacek at gcc dot gnu.org
2015-03-16 10:29 ` mpolacek at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-03-16 9:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65327
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
Target Milestone|--- |4.8.5
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Seems it is, taking. 4.8/4.9 have the same problem.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/65327] GCC rejects "constexpr volatile int i = 5;"
2015-03-05 17:44 [Bug c++/65327] New: GCC rejects "constexpr volatile int i = 5;" Casey at Carter dot net
` (2 preceding siblings ...)
2015-03-16 9:56 ` mpolacek at gcc dot gnu.org
@ 2015-03-16 10:29 ` mpolacek at gcc dot gnu.org
2015-03-16 18:31 ` mpolacek at gcc dot gnu.org
2015-03-16 18:32 ` mpolacek at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-03-16 10:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65327
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Presumably started with r166013.
Note that in
constexpr volatile int a = 42;
constexpr int b = a;
the initialization of b should be rejected, but it is not. This is a related
problem though, my patch doesn't change it.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/65327] GCC rejects "constexpr volatile int i = 5;"
2015-03-05 17:44 [Bug c++/65327] New: GCC rejects "constexpr volatile int i = 5;" Casey at Carter dot net
` (3 preceding siblings ...)
2015-03-16 10:29 ` mpolacek at gcc dot gnu.org
@ 2015-03-16 18:31 ` mpolacek at gcc dot gnu.org
2015-03-16 18:32 ` mpolacek at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-03-16 18:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65327
--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Author: mpolacek
Date: Mon Mar 16 18:30:49 2015
New Revision: 221463
URL: https://gcc.gnu.org/viewcvs?rev=221463&root=gcc&view=rev
Log:
DR 1688
PR c++/65327
* decl.c (grokdeclarator): Allow volatile and constexpr together.
* g++.dg/cpp0x/constexpr-object1.C: Change dg-error to dg-bogus.
* g++.dg/cpp0x/pr65327.C: New test.
Added:
trunk/gcc/testsuite/g++.dg/cpp0x/pr65327.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/decl.c
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-object1.C
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/65327] GCC rejects "constexpr volatile int i = 5;"
2015-03-05 17:44 [Bug c++/65327] New: GCC rejects "constexpr volatile int i = 5;" Casey at Carter dot net
` (4 preceding siblings ...)
2015-03-16 18:31 ` mpolacek at gcc dot gnu.org
@ 2015-03-16 18:32 ` mpolacek at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-03-16 18:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65327
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed for GCC 5. Not going to backport it.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-03-16 18:32 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-05 17:44 [Bug c++/65327] New: GCC rejects "constexpr volatile int i = 5;" Casey at Carter dot net
2015-03-05 18:49 ` [Bug c++/65327] " yaghmour.shafik at gmail dot com
2015-03-16 9:42 ` mpolacek at gcc dot gnu.org
2015-03-16 9:56 ` mpolacek at gcc dot gnu.org
2015-03-16 10:29 ` mpolacek at gcc dot gnu.org
2015-03-16 18:31 ` mpolacek at gcc dot gnu.org
2015-03-16 18:32 ` mpolacek 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).