From: Marek Polacek Date: Fri, 31 Jan 2025 19:52:36 +0000 (-0500) Subject: c++: bogus -Wvexing-parse with trailing-return-type [PR118718] X-Git-Tag: basepoints/gcc-16~2199 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=53d1f6cdb5a82e859176e854636400faba0bf0bf;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 44515bb9074..1da881e295b 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(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 00000000000..3fbe88b7d00 --- /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" } +}