PR c++/51473 - ICE with invalid auto
authorDodji Seketeli <dodji@redhat.com>
Thu, 15 Dec 2011 15:40:25 +0000 (15:40 +0000)
committerDodji Seketeli <dodji@gcc.gnu.org>
Thu, 15 Dec 2011 15:40:25 +0000 (16:40 +0100)
gcc/cp/

PR c++/51473
* decl.c (check_tag_decl): Error out on auto specifier with no
declarator.

gcc/testsuite/

PR c++/51473
* g++.dg/cpp0x/auto30.C: New test.

From-SVN: r182375

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/auto30.C [new file with mode: 0644]

index 7e99f58f037176453f7737e060533ffdf8618cff..3e56008703c0c2fb19f21890beca43345d732b99 100644 (file)
@@ -1,3 +1,9 @@
+2011-12-15  Dodji Seketeli  <dodji@redhat.com>
+
+       PR c++/51473
+       * decl.c (check_tag_decl): Error out on auto specifier with no
+       declarator.
+
 2011-12-15  Jonathan Wakely  <jwakely.gcc@gmail.com>
 
        PR libstdc++/51365
index 480d211871a2a265b934dce0b123280f21633571..1fe63bb3564ca1342c8fa39fa16b5604cce4ed58 100644 (file)
@@ -4140,6 +4140,12 @@ check_tag_decl (cp_decl_specifier_seq *declspecs)
     error_p = true;
   if (declared_type == NULL_TREE && ! saw_friend && !error_p)
     permerror (input_location, "declaration does not declare anything");
+  else if (declared_type != NULL_TREE && type_uses_auto (declared_type))
+    {
+      error ("%<auto%> can only be specified for variables "
+            "or function declarations");
+      return error_mark_node;
+    }
   /* Check for an anonymous union.  */
   else if (declared_type && RECORD_OR_UNION_CODE_P (TREE_CODE (declared_type))
           && TYPE_ANONYMOUS_P (declared_type))
index 465097785cdc4b36a35a9eba22b1c4374a56eac4..331ef1c9d45d5c0aa1cdee4125a9bff614235a59 100644 (file)
@@ -1,3 +1,8 @@
+2011-12-15  Dodji Seketeli  <dodji@redhat.com>
+
+       PR c++/51473
+       * g++.dg/cpp0x/auto30.C: New test.
+
 2011-12-15  Tobias Burnus  <burnus@net-b.de>
 
        * gfortran.dg/coarray/poly_run_3.f90: New.
diff --git a/gcc/testsuite/g++.dg/cpp0x/auto30.C b/gcc/testsuite/g++.dg/cpp0x/auto30.C
new file mode 100644 (file)
index 0000000..d26e290
--- /dev/null
@@ -0,0 +1,9 @@
+// Origin PR c++/51473
+// { dg-options "-std=c++11" }
+
+struct A
+{
+    auto friend struct B; // { dg-error "multiple types|can only be specified|friend" }
+};
+
+auto int; // { dg-error "multiple types|can only be specified for variables" }