]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/37965 (ICE with invalid auto variable in template)
authorJakub Jelinek <jakub@redhat.com>
Fri, 31 Oct 2008 21:30:05 +0000 (22:30 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 31 Oct 2008 21:30:05 +0000 (22:30 +0100)
PR c++/37965
* decl.c (cp_finish_decl): Diagnose type_uses_auto type with
no initializer.

* g++.dg/cpp0x/auto7.C: New test.

From-SVN: r141501

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

index 8370307aaaa8d267b642d5cebcb80c8cb8e533e9..5c20f458e139eea5a4ec7c354aab5661fee72589 100644 (file)
@@ -1,3 +1,9 @@
+2008-10-31  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/37965
+       * decl.c (cp_finish_decl): Diagnose type_uses_auto type with
+       no initializer.
+
 2008-10-29  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
 
        PR 11492
index c9cac551a558631a451a4804f2a0558857d944ea..091edd5234f8c59b81e82081eb7adf661fc3fdab 100644 (file)
@@ -5488,11 +5488,20 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
     DECL_INITIALIZED_IN_CLASS_P (decl) = 1;
 
   auto_node = type_uses_auto (type);
-  if (auto_node && !type_dependent_expression_p (init))
+  if (auto_node)
     {
-      type = TREE_TYPE (decl) = do_auto_deduction (type, init, auto_node);
-      if (type == error_mark_node)
-       return;
+      if (init == NULL_TREE)
+       {
+         error ("declaration of %q#D has no initializer", decl);
+         TREE_TYPE (decl) = error_mark_node;
+         return;
+       }
+      else if (!type_dependent_expression_p (init))
+       {
+         type = TREE_TYPE (decl) = do_auto_deduction (type, init, auto_node);
+         if (type == error_mark_node)
+           return;
+       }
     }
 
   if (processing_template_decl)
index 5d4dd1034becb12a7c37d64e740e1f303e6d6f03..f0e517944bfb6e695077aecadcfeeec87f029468 100644 (file)
@@ -1,3 +1,8 @@
+2008-10-31  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/37965
+       * g++.dg/cpp0x/auto7.C: New test.
+
 2008-10-31  Mikael Morin  <mikael.morin@tele2.fr>
 
        PR fortran/35840
diff --git a/gcc/testsuite/g++.dg/cpp0x/auto7.C b/gcc/testsuite/g++.dg/cpp0x/auto7.C
new file mode 100644 (file)
index 0000000..9ef5a80
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/37965
+// Negative test for auto
+// { dg-options "-std=c++0x" }
+
+auto i = 6;
+auto j;                        // { dg-error "has no initializer" }
+
+template<int> struct A
+{
+  static auto k = 7;
+  static auto l;       // { dg-error "has no initializer" }
+  auto m;              // { dg-error "has no initializer" }
+};