diff mbox series

C++ PATCH for c++/67012, diagnose decltype(auto) f() -> int;

Message ID 20180815184502.GQ7399@redhat.com
State New
Headers show
Series C++ PATCH for c++/67012, diagnose decltype(auto) f() -> int; | expand

Commit Message

Marek Polacek Aug. 15, 2018, 6:45 p.m. UTC
I think that [dcl.fct] says that a function with trailing-return-type should
have plain auto as the return type, so this test should not compile.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2018-08-15  Marek Polacek  <polacek@redhat.com>

	PR c++/67012
	* decl.c (grokdeclarator): Disallow functions with trailing return
	type with decltype(auto) as its type.

	* g++.dg/cpp1y/auto-fn52.C: New test.

Comments

Marek Polacek Aug. 15, 2018, 8:23 p.m. UTC | #1
On Wed, Aug 15, 2018 at 02:45:02PM -0400, Marek Polacek wrote:
> I think that [dcl.fct] says that a function with trailing-return-type should
> have plain auto as the return type, so this test should not compile.
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk?

Looking at 86942, I think we need a fix that handles both PRs.  So ignore this
patch.

Marek
diff mbox series

Patch

diff --git gcc/cp/decl.c gcc/cp/decl.c
index fa58bc4d2b3..05f4991c184 100644
--- gcc/cp/decl.c
+++ gcc/cp/decl.c
@@ -11263,7 +11263,10 @@  grokdeclarator (const cp_declarator *declarator,
 			    virtualp = false;
 			  }
 		      }
-		    else if (!is_auto (type) && sfk != sfk_conversion)
+		    else if ((!is_auto (type) && sfk != sfk_conversion)
+			     || (is_auto (type)
+				 && (TYPE_IDENTIFIER (type)
+				     == decltype_auto_identifier)))
 		      {
 			error ("%qs function with trailing return type has"
 			       " %qT as its type rather than plain %<auto%>",
diff --git gcc/testsuite/g++.dg/cpp1y/auto-fn52.C gcc/testsuite/g++.dg/cpp1y/auto-fn52.C
index e69de29bb2d..e239bc27dc2 100644
--- gcc/testsuite/g++.dg/cpp1y/auto-fn52.C
+++ gcc/testsuite/g++.dg/cpp1y/auto-fn52.C
@@ -0,0 +1,4 @@ 
+// PR c++/67012
+// { dg-do compile { target c++14 } }
+
+decltype(auto) f() -> int; // { dg-error "function with trailing return type has" }