diff mbox

C++ PATCH for c++/51186 (confusing message about trailing return type in C++98 mode)

Message ID 4EC574A1.3010503@redhat.com
State New
Headers show

Commit Message

Jason Merrill Nov. 17, 2011, 8:54 p.m. UTC
Let's give a more helpful message in this case.

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

commit 303f975019af8e6048120b1d27a5f46cbf0db27d
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Nov 17 15:19:20 2011 -0500

    	PR c++/51186
    	* decl.c (grokdeclarator): Improve C++98 trailing return diagnostic.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index d744da8..b77963b 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -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;
 		  }
 	      }
diff --git a/gcc/testsuite/g++.dg/cpp0x/auto27.C b/gcc/testsuite/g++.dg/cpp0x/auto27.C
new file mode 100644
index 0000000..c1041df
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/auto27.C
@@ -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 }
+{ }
diff --git a/gcc/testsuite/g++.dg/cpp0x/trailing2.C b/gcc/testsuite/g++.dg/cpp0x/trailing2.C
index e45204f..5f5af22 100644
--- a/gcc/testsuite/g++.dg/cpp0x/trailing2.C
+++ b/gcc/testsuite/g++.dg/cpp0x/trailing2.C
@@ -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" }
 };