On 1/31/25 4:21 PM, Marek Polacek wrote:
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

OK.

-- >8 --
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.
---
  gcc/cp/parser.cc                            | 4 ++++
  gcc/testsuite/g++.dg/warn/Wvexing-parse10.C | 9 +++++++++
  2 files changed, 13 insertions(+)
  create mode 100644 gcc/testsuite/g++.dg/warn/Wvexing-parse10.C

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<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 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" }
+}

base-commit: d6418fe22684f9335474d1fd405ade45954c069d

Reply via email to