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 <pola...@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. 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" }