]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: bogus -Wvexing-parse with trailing-return-type [PR118718]
authorMarek Polacek <polacek@redhat.com>
Fri, 31 Jan 2025 19:52:36 +0000 (14:52 -0500)
committerMarek Polacek <polacek@redhat.com>
Tue, 4 Feb 2025 14:09:09 +0000 (09:09 -0500)
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 <jason@redhat.com>
gcc/cp/parser.cc
gcc/testsuite/g++.dg/warn/Wvexing-parse10.C [new file with mode: 0644]

index 44515bb9074ad9aa9b9fd03c109b00d5475455db..1da881e295b4f88e6a2a18200a76228b824e05f4 100644 (file)
@@ -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 (file)
index 0000000..3fbe88b
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/118718
+// { dg-do compile { target c++14 } }
+
+void
+fn ()
+{
+  auto f1 () -> auto;
+  auto f2 (); // { dg-warning "empty parentheses" }
+}