The following fixes up the handling of trailing returns with cv/ref specifiers mentioned by TC in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69139#c3. I've added handling of exception and transaction specs too.
--- gcc/cp/parser.c | 12 ++++++++++-- gcc/testsuite/g++.dg/cpp0x/trailing12.C | 10 ++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index c1a9674..f51fac4 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -16055,8 +16055,16 @@ cp_parser_simple_type_specifier (cp_parser* parser, /*recovering*/false, /*or_comma*/false, /*consume_paren*/true))) - have_trailing_return_fn_decl - = cp_lexer_next_token_is (parser->lexer, CPP_DEREF); + { + /* Consume any cv-qualifier-seq, ref-qualifier, + tx-qualifier and/or exception specifier. */ + cp_parser_cv_qualifier_seq_opt (parser); + cp_parser_ref_qualifier_opt (parser); + cp_parser_tx_qualifier_opt (parser); + cp_parser_exception_specification_opt (parser); + have_trailing_return_fn_decl + = cp_lexer_next_token_is (parser->lexer, CPP_DEREF); + } } cp_parser_abort_tentative_parse (parser); } diff --git a/gcc/testsuite/g++.dg/cpp0x/trailing12.C b/gcc/testsuite/g++.dg/cpp0x/trailing12.C index f3e02a8..707b753 100644 --- a/gcc/testsuite/g++.dg/cpp0x/trailing12.C +++ b/gcc/testsuite/g++.dg/cpp0x/trailing12.C @@ -4,3 +4,13 @@ auto get(int) -> int { return {}; } template <class R> int f(auto (*)(int) -> R) { return {}; } int i = f(get); + +struct X { + auto get(int) const & throw() -> int { return {}; } + auto get(int) && -> long { return {}; } +}; + +template <class R> auto f(auto (X::*)(int) const & -> R) -> R {} + +using I = decltype(f(&X::get)); +using I = int; -- 2.7.0