re PR c++/50298 ([C++0x][constexpr] References cannot be bound to static constexpr...
authorJason Merrill <jason@redhat.com>
Wed, 7 Sep 2011 17:11:49 +0000 (13:11 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 7 Sep 2011 17:11:49 +0000 (13:11 -0400)
PR c++/50298
* parser.c (cp_parser_member_declaration): Don't require a constant
rvalue here in C++0x.

From-SVN: r178652

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/constexpr-ref3.C [new file with mode: 0644]

index ea67d2d5d5a0f31541c7984c06c81a68326e8095..1c6c5a160c0b6526b59435059664b747769764b3 100644 (file)
@@ -1,5 +1,9 @@
 2011-09-07  Jason Merrill  <jason@redhat.com>
 
+       PR c++/50298
+       * parser.c (cp_parser_member_declaration): Don't require a constant
+       rvalue here in C++0x.
+
        * pt.c (type_unification_real): Correct complain arg for tsubsting
        default template args.
 
index 7d766d130caf4bcdc684eff1947ad20f5debe8d6..6346aa0386a17737ea3f033da97e720a90c61086 100644 (file)
@@ -18187,6 +18187,17 @@ cp_parser_member_declaration (cp_parser* parser)
                  initializer_token_start = cp_lexer_peek_token (parser->lexer);
                  if (function_declarator_p (declarator))
                    initializer = cp_parser_pure_specifier (parser);
+                 else if (cxx_dialect >= cxx0x)
+                   {
+                     bool nonconst;
+                     /* Don't require a constant rvalue in C++11, since we
+                        might want a reference constant.  We'll enforce
+                        constancy later.  */
+                     cp_lexer_consume_token (parser->lexer);
+                     /* Parse the initializer.  */
+                     initializer = cp_parser_initializer_clause (parser,
+                                                                 &nonconst);
+                   }
                  else
                    /* Parse the initializer.  */
                    initializer = cp_parser_constant_initializer (parser);
index 5247ac6b98499b4d738d39f9dca63540f3e0c806..f3d6ddb6bfff4249cefce2879b012430cf1f9a1f 100644 (file)
@@ -1,5 +1,7 @@
 2011-09-07  Jason Merrill  <jason@redhat.com>
 
+       * g++.dg/cpp0x/constexpr-ref3.C: New.
+
        * g++.dg/cpp0x/sfinae11.C: Check for explanatory diagnostic.
 
 2011-09-07  Georg-Johann Lay  <avr@gjlay.de>
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ref3.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ref3.C
new file mode 100644 (file)
index 0000000..24cc9c8
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/50298
+// { dg-options -std=c++0x }
+
+int global_variable;
+
+template <class T> struct X {
+  static constexpr T r = global_variable;
+};
+
+X<int&> x;