]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Honor complain in cp_build_function_call_vec for check_function_arguments warnin...
authorJakub Jelinek <jakub@redhat.com>
Wed, 8 Jan 2025 22:12:02 +0000 (23:12 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 13 Jun 2025 09:48:31 +0000 (11:48 +0200)
The following testcase ICEs due to re-entering diagnostics.
When diagnosing -Wformat-security warning, we try to print instantiation
context, which calls tsubst with tf_none, but that in the end calls
cp_build_function_call_vec which calls check_function_arguments which
diagnoses another warning (again -Wformat-security).

The other check_function_arguments caller, build_over_call, doesn't call
that function if !(complain & tf_warning), so I think the best fix is
to do it the same in cp_build_function_call_vec as well.

2025-01-08  Jakub Jelinek  <jakub@redhat.com>

PR c++/117825
* typeck.cc (cp_build_function_call_vec): Don't call
check_function_arguments if complain doesn't have tf_warning bit set.

* g++.dg/warn/pr117825.C: New test.

(cherry picked from commit e5180fbcbcc356c71154413588288cbd30e5198d)

gcc/cp/typeck.cc
gcc/testsuite/g++.dg/warn/pr117825.C [new file with mode: 0644]

index 949155cecad758a48e9aedd6bf98155dbca521fa..304f6b0c30e5527c334cd98e372b3978bba09c0a 100644 (file)
@@ -4315,8 +4315,10 @@ cp_build_function_call_vec (tree function, vec<tree, va_gc> **params,
 
   /* Check for errors in format strings and inappropriately
      null parameters.  */
-  bool warned_p = check_function_arguments (input_location, fndecl, fntype,
-                                           nargs, argarray, NULL);
+  bool warned_p
+    = ((complain & tf_warning)
+       && check_function_arguments (input_location, fndecl, fntype,
+                                   nargs, argarray, NULL));
 
   ret = build_cxx_call (function, nargs, argarray, complain, orig_fndecl);
 
diff --git a/gcc/testsuite/g++.dg/warn/pr117825.C b/gcc/testsuite/g++.dg/warn/pr117825.C
new file mode 100644 (file)
index 0000000..077e09d
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/117825
+// { dg-do compile { target c++17 } }
+// { dg-options "-Wformat -Wformat-security" }
+
+__attribute__((format (printf, 1, 2)))
+int fails (const char *, ...) { return 0; }
+
+template <auto func, typename... Args>
+auto wrap (Args... args) -> decltype (func (args...))
+{
+  return func (args...);       // { dg-warning "format not a string literal and no format arguments" }
+}
+
+int
+main ()
+{
+  wrap<fails> ("Test!");
+}