Here, we were just giving a pedwarn about the invalid-in-C++11
declaration of 'auto foo()' and then not giving the C++1y error about
using a function with an undeduced return type in the initializer of fp,
leading to confusion in LTO. The simplest fix is to raise the pedwarn
to a hard error.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit a3027fa4dc4869f90fb4228b5ba67c7f1df3f108
Author: Jason Merrill <ja...@redhat.com>
Date: Fri Jan 24 12:07:11 2014 -0500
PR c++/58550
* decl.c (grokdeclarator): Turn pedwarn about auto return type in
c++11 into error.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index f4819a6..aaafaa8 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -9599,9 +9599,14 @@ grokdeclarator (const cp_declarator *declarator,
&& LAMBDA_TYPE_P (current_class_type))
/* OK for C++11 lambdas. */;
else if (cxx_dialect < cxx1y)
- pedwarn (input_location, 0, "%qs function uses "
+ {
+ error ("%qs function uses "
"%<auto%> type specifier without trailing "
"return type", name);
+ inform (input_location, "deduced return type "
+ "only available with -std=c++1y or "
+ "-std=gnu++1y");
+ }
else if (virtualp)
permerror (input_location, "virtual function cannot "
"have deduced return type");
diff --git a/gcc/testsuite/g++.dg/cpp0x/auto41.C b/gcc/testsuite/g++.dg/cpp0x/auto41.C
new file mode 100644
index 0000000..6f102e7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/auto41.C
@@ -0,0 +1,5 @@
+// PR c++/58550
+// { dg-options "-std=c++11" }
+
+auto foo(); // { dg-error "auto" }
+auto fp = foo;