decl.c (grokdeclarator): Don't ICE on constexpr non-static data member.
authorJason Merrill <jason@redhat.com>
Mon, 1 Nov 2010 02:04:30 +0000 (22:04 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 1 Nov 2010 02:04:30 +0000 (22:04 -0400)
* decl.c (grokdeclarator): Don't ICE on constexpr non-static data
member.

* parser.c (cp_parser_diagnose_invalid_type_name): Give helpful
message about constexpr without -std=c++0x.

From-SVN: r166122

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

index 8df704f2bd33b7e5ac164ecfe4140d19e4245a5e..1a8837cff94b2eab3389b44f4f3b46ed31ecc55e 100644 (file)
@@ -1,3 +1,11 @@
+2010-10-31  Jason Merrill  <jason@redhat.com>
+
+       * parser.c (cp_parser_diagnose_invalid_type_name): Give helpful
+       message about constexpr without -std=c++0x.
+
+       * decl.c (grokdeclarator): Don't ICE on constexpr non-static data
+       member.
+
 2010-10-30  Nathan Froyd  <froydnj@codesourcery.com>
 
        * class.c (layout_vtable_decl): Call build_array_of_n_type.
index d73d109af819b5ec1d55b2844230914e5d7266de..dfe37d92a32056e3ca2eafb97bdee32fbdd061e9 100644 (file)
@@ -9652,8 +9652,11 @@ grokdeclarator (const cp_declarator *declarator,
            else
              {
                 if (constexpr_p)
-                  error ("non-static data member %qE declared %<constexpr%>",
-                         unqualified_id);
+                 {
+                   error ("non-static data member %qE declared %<constexpr%>",
+                          unqualified_id);
+                   constexpr_p = false;
+                 }
                decl = build_decl (input_location,
                                   FIELD_DECL, unqualified_id, type);
                DECL_NONADDRESSABLE_P (decl) = bitfield;
index 851e9c4c36d7c7159851d7c5e77930734ec7459a..33d8561603bc9a025d194409493ed15fb527c877 100644 (file)
@@ -2698,8 +2698,11 @@ cp_parser_diagnose_invalid_type_name (cp_parser *parser,
           template <typename T> struct B : public A<T> { X x; };
 
         The user should have said "typename A<T>::X".  */
-      if (processing_template_decl && current_class_type
-         && TYPE_BINFO (current_class_type))
+      if (cxx_dialect < cxx0x && id == ridpointers[(int)RID_CONSTEXPR])
+       inform (location, "C++0x %<constexpr%> only available with "
+               "-std=c++0x or -std=gnu++0x");
+      else if (processing_template_decl && current_class_type
+              && TYPE_BINFO (current_class_type))
        {
          tree b;
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-98.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-98.C
new file mode 100644 (file)
index 0000000..4ae3944
--- /dev/null
@@ -0,0 +1,4 @@
+// { dg-options "-std=c++98" }
+
+constexpr int i = 42;    // { dg-message "std=c\\+\\+0x" }
+// { dg-error "constexpr" "" { target *-*-* } 3 }
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-nonstatic.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-nonstatic.C
new file mode 100644 (file)
index 0000000..3951fbd
--- /dev/null
@@ -0,0 +1,6 @@
+// { dg-options -std=c++0x }
+
+struct A
+{
+  constexpr int i;             // { dg-error "" }
+};