https://gcc.gnu.org/g:53d1f6cdb5a82e859176e854636400faba0bf0bf
commit r15-7354-g53d1f6cdb5a82e859176e854636400faba0bf0bf Author: Marek Polacek <pola...@redhat.com> Date: Fri Jan 31 14:52:36 2025 -0500 c++: bogus -Wvexing-parse with trailing-return-type [PR118718] This warning should not warn for auto f1 () -> auto; because that cannot be confused with initializing a variable. PR c++/118718 gcc/cp/ChangeLog: * parser.cc (warn_about_ambiguous_parse): Don't warn when a trailing return type is present. gcc/testsuite/ChangeLog: * g++.dg/warn/Wvexing-parse10.C: New test. Reviewed-by: Jason Merrill <ja...@redhat.com> Diff: --- gcc/cp/parser.cc | 4 ++++ gcc/testsuite/g++.dg/warn/Wvexing-parse10.C | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 44515bb9074a..1da881e295b4 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -23617,6 +23617,10 @@ warn_about_ambiguous_parse (const cp_decl_specifier_seq *decl_specifiers, (const_cast<cp_declarator *>(declarator)))) return; + /* Don't warn for auto f () -> auto. */ + if (declarator->u.function.late_return_type) + return; + /* Don't warn when the whole declarator (not just the declarator-id!) was parenthesized. That is, don't warn for int(n()) but do warn for int(f)(). */ diff --git a/gcc/testsuite/g++.dg/warn/Wvexing-parse10.C b/gcc/testsuite/g++.dg/warn/Wvexing-parse10.C new file mode 100644 index 000000000000..3fbe88b7d00b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wvexing-parse10.C @@ -0,0 +1,9 @@ +// PR c++/118718 +// { dg-do compile { target c++14 } } + +void +fn () +{ + auto f1 () -> auto; + auto f2 (); // { dg-warning "empty parentheses" } +}