This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C++ PATCH for c++/84374 - diagnose invalid uses of decltype(auto)


On 9/8/19 11:47 AM, Marek Polacek wrote:
[dcl.type.auto.deduct]/5 "If the placeholder-type-specifier is of the
form type-constraintopt decltype(auto), T shall be the placeholder alone."

So, only plain decltype(auto) is allowed.  But we aren't diagnosing it in
function declarations, because do_auto_deduction is never called for those.

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

2019-09-08  Marek Polacek  <polacek@redhat.com>

	PR c++/84374 - diagnose invalid uses of decltype(auto).
	* decl.c (grokdeclarator): Diagnose wrong usage of decltype(auto) in
	a function declaration.

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

diff --git gcc/cp/decl.c gcc/cp/decl.c
index 88e2c3beb2b..b1777730934 100644
--- gcc/cp/decl.c
+++ gcc/cp/decl.c
@@ -11560,6 +11560,14 @@ grokdeclarator (const cp_declarator *declarator,
  				      "cannot have deduced return type");
  			    virtualp = false;
  			  }
+			else if (is_auto (auto_node)
+				 && AUTO_IS_DECLTYPE (auto_node)
+				 && type != auto_node)
+			  {
+			    error_at (typespec_loc, "%qT as type rather than "
+				      "plain %<decltype(auto)%>", type);
+			    return error_mark_node;
+			  }
  		      }
  		    else if (!is_auto (type) && sfk != sfk_conversion)
  		      {
@@ -11580,6 +11588,16 @@ grokdeclarator (const cp_declarator *declarator,
  				    "invalid use of %<decltype(auto)%>");
  			return error_mark_node;
  		      }
+		    else if (tree a = type_uses_auto (late_return_type))
+		      {
+			if (AUTO_IS_DECLTYPE (a) && a != late_return_type)
+			  {
+			    error_at (typespec_loc, "%qT as type rather than "
+				      "plain %<decltype(auto)%>",
+				      late_return_type);
+			    return error_mark_node;
+			  }
+		      }

Maybe check this in one place, after splice_late_return_type?

Jason


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]