re PR c++/51186 (declaring main() with auto but without --std=c++11 gives inconsisten...
authorJason Merrill <jason@redhat.com>
Thu, 17 Nov 2011 21:00:30 +0000 (16:00 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 17 Nov 2011 21:00:30 +0000 (16:00 -0500)
PR c++/51186
* decl.c (grokdeclarator): Improve C++98 trailing return diagnostic.

From-SVN: r181455

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

index 89f845edc9f153116aced82c203ac26b0a42e4fe..c5f2a7b4851cd2c520bd3bf4c357f46b81d400d8 100644 (file)
@@ -1,5 +1,8 @@
 2011-11-17  Jason Merrill  <jason@redhat.com>
 
+       PR c++/51186
+       * decl.c (grokdeclarator): Improve C++98 trailing return diagnostic.
+
        N3203
        * class.c (add_implicitly_declared_members): Update move
        conditions.
index d744da85f3e510b4a43073c84fe77566e09d3061..b77963b72df26da9cdaca16d10b49df1dc743ac1 100644 (file)
@@ -9126,12 +9126,12 @@ grokdeclarator (const cp_declarator *declarator,
                    if (!declarator->u.function.late_return_type)
                      {
                        error ("%qs function uses %<auto%> type specifier without"
-                              " late return type", name);
+                              " trailing return type", name);
                        return error_mark_node;
                      }
                    else if (!is_auto (type))
                      {
-                       error ("%qs function with late return type has"
+                       error ("%qs function with trailing return type has"
                               " %qT as its type rather than plain %<auto%>",
                               name, type);
                        return error_mark_node;
@@ -9139,8 +9139,14 @@ grokdeclarator (const cp_declarator *declarator,
                  }
                else if (declarator->u.function.late_return_type)
                  {
-                   error ("%qs function with late return type not declared"
-                          " with %<auto%> type specifier", name);
+                   if (cxx_dialect < cxx0x)
+                     /* Not using maybe_warn_cpp0x because this should
+                        always be an error.  */
+                     error ("trailing return type only available with "
+                            "-std=c++11 or -std=gnu++11");
+                   else
+                     error ("%qs function with trailing return type not "
+                            "declared with %<auto%> type specifier", name);
                    return error_mark_node;
                  }
              }
index 7d94e14f6c8d67495413f024646b4e76283f16b9..fa4ab0d59694ee9f1de2f8c4367cd885b4ecde88 100644 (file)
@@ -1,3 +1,9 @@
+2011-11-17  Jason Merrill  <jason@redhat.com>
+
+       PR c++/51186
+       * g++.dg/cpp0x/auto27.C: New.
+       * g++.dg/cpp0x/trailing2.C: Adjust messages.
+
 2011-11-17  Andrew MacLeod  <amacleod@redhat.com>
 
        * gcc.dg/atomic-generic-aux.c (__atomic_compare_exchange): Fail if 
diff --git a/gcc/testsuite/g++.dg/cpp0x/auto27.C b/gcc/testsuite/g++.dg/cpp0x/auto27.C
new file mode 100644 (file)
index 0000000..c1041df
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c++/51186
+
+auto main()->int              // { dg-error "std=" "" { target c++98 } }
+                              // { dg-error "auto" "" { target c++98 } 3 }
+                              // { dg-error "no type" "" { target c++98 } 3 }
+{ }
index e45204fe715f593785a1964e353a627b72c621b3..5f5af22947ffd7f956ee4162509b8f96b4dd1063 100644 (file)
@@ -3,14 +3,14 @@
 // { dg-options "-std=c++0x" }
 
 auto f1 () -> int;
-auto f2 ();            // { dg-error "without late return type" }
-int f3 () -> int;      // { dg-error "late return type" }
-auto *f4 () -> int;    // { dg-error "late return type" }
+auto f2 ();            // { dg-error "without trailing return type" }
+int f3 () -> int;      // { dg-error "trailing return type" }
+auto *f4 () -> int;    // { dg-error "trailing return type" }
 
 struct A
 {
   auto f5 () const -> int;
-  auto f6 ();          // { dg-error "without late return type" }
-  int f7 () -> int;    // { dg-error "late return type" }
-  auto *f8 () -> int;  // { dg-error "late return type" }
+  auto f6 ();          // { dg-error "without trailing return type" }
+  int f7 () -> int;    // { dg-error "trailing return type" }
+  auto *f8 () -> int;  // { dg-error "trailing return type" }
 };