]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/37967 (ICE with function returning auto)
authorJakub Jelinek <jakub@redhat.com>
Fri, 31 Oct 2008 21:33:47 +0000 (22:33 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 31 Oct 2008 21:33:47 +0000 (22:33 +0100)
PR c++/37967
* decl.c (grokdeclarator): Diagnose auto function decl without
late return type and late return type function decl where type
is not auto.

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

From-SVN: r141502

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

index 5c20f458e139eea5a4ec7c354aab5661fee72589..34257e582ec471b34bda2f5797225fcec530c1fa 100644 (file)
@@ -1,5 +1,10 @@
 2008-10-31  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/37967
+       * decl.c (grokdeclarator): Diagnose auto function decl without
+       late return type and late return type function decl where type
+       is not auto.
+
        PR c++/37965
        * decl.c (cp_finish_decl): Diagnose type_uses_auto type with
        no initializer.
index 091edd5234f8c59b81e82081eb7adf661fc3fdab..754f433c30ada4d7bbb779f6efca66eb7075f64c 100644 (file)
@@ -8237,16 +8237,40 @@ grokdeclarator (const cp_declarator *declarator,
            /* Pick up the exception specifications.  */
            raises = declarator->u.function.exception_specification;
 
+           /* Say it's a definition only for the CALL_EXPR
+              closest to the identifier.  */
+           funcdecl_p = inner_declarator && inner_declarator->kind == cdk_id;
+
            /* Handle a late-specified return type.  */
+           if (funcdecl_p)
+             {
+               if (type_uses_auto (type))
+                 {
+                   if (!declarator->u.function.late_return_type)
+                     {
+                       error ("%qs function uses auto type specifier without"
+                              " late return type", name);
+                       return error_mark_node;
+                     }
+                   else if (!is_auto (type))
+                     {
+                       error ("%qs function with late return type not using"
+                              " auto type specifier as its type", name);
+                       return error_mark_node;
+                     }
+                 }
+               else if (declarator->u.function.late_return_type)
+                 {
+                   error ("%qs function with late return type not declared"
+                          " with auto type specifier", name);
+                   return error_mark_node;
+                 }
+             }
            type = splice_late_return_type
              (type, declarator->u.function.late_return_type);
            if (type == error_mark_node)
              return error_mark_node;
 
-           /* Say it's a definition only for the CALL_EXPR
-              closest to the identifier.  */
-           funcdecl_p = inner_declarator && inner_declarator->kind == cdk_id;
-
            if (ctype == NULL_TREE
                && decl_context == FIELD
                && funcdecl_p
index f0e517944bfb6e695077aecadcfeeec87f029468..616e10b5bf22f2dae62d4d9761e9bd6e5c874a86 100644 (file)
@@ -1,5 +1,8 @@
 2008-10-31  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/37967
+       * g++.dg/cpp0x/auto8.C: New test.
+
        PR c++/37965
        * g++.dg/cpp0x/auto7.C: New test.
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/auto8.C b/gcc/testsuite/g++.dg/cpp0x/auto8.C
new file mode 100644 (file)
index 0000000..d724d79
--- /dev/null
@@ -0,0 +1,16 @@
+// PR c++/37967
+// Negative test for auto
+// { dg-options "-std=c++0x" }
+
+auto f1 () -> int;
+auto f2 ();            // { dg-error "without late return type" }
+int f3 () -> int;      // { dg-error "with auto type specifier" }
+auto *f4 () -> int;    // { dg-error "not using auto" }
+
+struct A
+{
+  auto f5 () const -> int;
+  auto f6 ();          // { dg-error "without late return type" }
+  int f7 () -> int;    // { dg-error "with auto type specifier" }
+  auto *f8 () -> int;  // { dg-error "not using auto" }
+};