Commit 77df40e8 by Marek Polacek Committed by Marek Polacek

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.

From-SVN: r275557
parent fa412b7c
2019-09-09 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.
2019-09-06 Nathan Sidwell <nathan@acm.org> 2019-09-06 Nathan Sidwell <nathan@acm.org>
PR c++/91125 PR c++/91125
......
...@@ -11681,6 +11681,16 @@ grokdeclarator (const cp_declarator *declarator, ...@@ -11681,6 +11681,16 @@ grokdeclarator (const cp_declarator *declarator,
"allowed"); "allowed");
return error_mark_node; return error_mark_node;
} }
/* Only plain decltype(auto) is allowed. */
if (tree a = type_uses_auto (type))
{
if (AUTO_IS_DECLTYPE (a) && a != type)
{
error_at (typespec_loc, "%qT as type rather than "
"plain %<decltype(auto)%>", type);
return error_mark_node;
}
}
if (ctype == NULL_TREE if (ctype == NULL_TREE
&& decl_context == FIELD && decl_context == FIELD
......
2019-09-09 Marek Polacek <polacek@redhat.com>
PR c++/84374 - diagnose invalid uses of decltype(auto).
* g++.dg/cpp1y/auto-fn57.C: New test.
2019-09-09 Segher Boessenkool <segher@kernel.crashing.org> 2019-09-09 Segher Boessenkool <segher@kernel.crashing.org>
* gcc.target/powerpc/rlwinm-0.c: Adjust expected instruction counts. * gcc.target/powerpc/rlwinm-0.c: Adjust expected instruction counts.
......
// PR c++/84374 - diagnose invalid uses of decltype(auto).
// { dg-do compile { target c++14 } }
auto l = [](auto* r)->decltype(auto)* { return r; }; // { dg-error "as type rather than plain" }
auto m = [](auto* r)->decltype(auto)& { return *r; }; // { dg-error "as type rather than plain" }
decltype(auto)* f(); // { dg-error "as type rather than plain" }
decltype(auto)& f2(); // { dg-error "as type rather than plain" }
decltype(auto)* f3() { return 42; } // { dg-error "as type rather than plain" }
decltype(auto)& f4() { return 42; } // { dg-error "as type rather than plain" }
class C {
decltype(auto)* g(); // { dg-error "as type rather than plain" }
decltype(auto)& g2(); // { dg-error "as type rather than plain" }
decltype(auto)* g3() { } // { dg-error "as type rather than plain" }
decltype(auto)& g4() { } // { dg-error "as type rather than plain" }
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment