PR c++/51401
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 8 Dec 2011 00:50:26 +0000 (00:50 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 8 Dec 2011 00:50:26 +0000 (00:50 +0000)
* decl.c (grokdeclarator): Error for auto on non-static data members.

* g++.dg/cpp0x/auto7.C: Adjust expected error message.
* g++.dg/cpp0x/auto29.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@182097 138bc75d-0d04-0410-961f-82ee72b054a4

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

index 19bbfed..ebb636e 100644 (file)
@@ -1,5 +1,8 @@
 2011-12-07  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/51401
+       * decl.c (grokdeclarator): Error for auto on non-static data members.
+
        PR c++/51429
        * typeck2.c (cxx_incomplete_type_diagnostic): Don't
        ICE if TREE_OPERAND (value, 1) is overloaded.
index 07cc9e6..5a4e027 100644 (file)
@@ -9971,6 +9971,12 @@ grokdeclarator (const cp_declarator *declarator,
       }
     else if (decl_context == FIELD)
       {
+       if (!staticp && type_uses_auto (type))
+         {
+           error ("non-static data member declared %<auto%>");
+           type = error_mark_node;
+         }
+
        /* The C99 flexible array extension.  */
        if (!staticp && TREE_CODE (type) == ARRAY_TYPE
            && TYPE_DOMAIN (type) == NULL_TREE)
index e95eb49..31b2d2e 100644 (file)
@@ -1,5 +1,9 @@
 2011-12-07  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/51401
+       * g++.dg/cpp0x/auto7.C: Adjust expected error message.
+       * g++.dg/cpp0x/auto29.C: New test.
+
        PR c++/51429
        * g++.dg/parse/error45.C: New test.
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/auto29.C b/gcc/testsuite/g++.dg/cpp0x/auto29.C
new file mode 100644 (file)
index 0000000..8187457
--- /dev/null
@@ -0,0 +1,25 @@
+// PR c++/51401
+// { dg-do compile }
+// { dg-options "-std=c++11" }
+
+template <int>
+struct A
+{
+  auto i;      // { dg-error "non-static data member declared" }
+};
+
+template <int>
+struct B
+{
+  auto i = 0;  // { dg-error "non-static data member declared" }
+};
+
+struct C
+{
+  auto i;      // { dg-error "non-static data member declared" }
+};
+
+struct D
+{
+  auto i = 0;  // { dg-error "non-static data member declared" }
+};
index e7ab723..3b3b829 100644 (file)
@@ -9,5 +9,5 @@ template<int> struct A
 {
   static auto k = 7;   // { dg-error "non-const" }
   static auto l;       // { dg-error "has no initializer" }
-  auto m;              // { dg-error "has no initializer" }
+  auto m;              // { dg-error "non-static data member declared" }
 };