]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Avoid informs without a warning [PR109278]
authorJakub Jelinek <jakub@redhat.com>
Thu, 30 Mar 2023 07:34:12 +0000 (09:34 +0200)
committerJakub Jelinek <jakub@redhat.com>
Thu, 30 Mar 2023 07:34:12 +0000 (09:34 +0200)
On the following testcase we emit notes in
maybe_inform_about_fndecl_for_bogus_argument_init
despite no warning/error being printed before it.
This is for the extended floating point type conversions where pedwarn
is used, and complained is used there for 2 different purposes,
one is whether an unspecific error should be emitted if we haven't
complained otherwise, and one whether
maybe_inform_about_fndecl_for_bogus_argument_init should be called.
For the 2 pedwarns, currently it sets complained to true regardless of
whether pedwarn succeeded, which results in the undesirable notes printed
with -w.  If complained is initialized to result of pedwarn, we would
emit an error later on.

So, the following patch makes complained a tristate, the additional
error isn't printed if complained != 0, and
maybe_inform_about_fndecl_for_bogus_argument_init is called only if
complained == 1, so if pedwarn returns false, we can use complained = -1
to tell later code not to emit an error and not to call
maybe_inform_about_fndecl_for_bogus_argument_init.

2023-03-30  Jakub Jelinek  <jakub@redhat.com>

PR c++/109278
* call.cc (convert_like_internal): If pedwarn for extended float
type conversions doesn't report anything, avoid calling
maybe_inform_about_fndecl_for_bogus_argument_init.

* g++.dg/cpp23/ext-floating15.C: New test.

gcc/cp/call.cc
gcc/testsuite/g++.dg/cpp23/ext-floating15.C [new file with mode: 0644]

index 5df0f7ddee93aefeea2c21c479361c575375ae0d..cdd7701b9e77c25e7b04cf3dfb15a5698e19b860 100644 (file)
@@ -8296,7 +8296,7 @@ convert_like_internal (conversion *convs, tree expr, tree fn, int argnum,
          || SCALAR_TYPE_P (totype))
       && convs->kind != ck_base)
     {
-      bool complained = false;
+      int complained = 0;
       conversion *t = convs;
 
       /* Give a helpful error if this is bad because of excess braces.  */
@@ -8328,14 +8328,18 @@ convert_like_internal (conversion *convs, tree expr, tree fn, int argnum,
                                                            totype))
          {
          case 2:
-           pedwarn (loc, 0, "converting to %qH from %qI with greater "
-                            "conversion rank", totype, TREE_TYPE (expr));
-           complained = true;
+           if (pedwarn (loc, 0, "converting to %qH from %qI with greater "
+                                "conversion rank", totype, TREE_TYPE (expr)))
+             complained = 1;
+           else if (!complained)
+             complained = -1;
            break;
          case 3:
-           pedwarn (loc, 0, "converting to %qH from %qI with unordered "
-                            "conversion ranks", totype, TREE_TYPE (expr));
-           complained = true;
+           if (pedwarn (loc, 0, "converting to %qH from %qI with unordered "
+                                "conversion ranks", totype, TREE_TYPE (expr)))
+             complained = 1;
+           else if (!complained)
+             complained = -1;
            break;
          default:
            break;
@@ -8389,7 +8393,7 @@ convert_like_internal (conversion *convs, tree expr, tree fn, int argnum,
                                  "invalid conversion from %qH to %qI",
                                  TREE_TYPE (expr), totype);
        }
-      if (complained)
+      if (complained == 1)
        maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum);
 
       return cp_convert (totype, expr, complain);
diff --git a/gcc/testsuite/g++.dg/cpp23/ext-floating15.C b/gcc/testsuite/g++.dg/cpp23/ext-floating15.C
new file mode 100644 (file)
index 0000000..316dd5a
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/109278
+// { dg-do compile { target float128 } }
+// { dg-options "-w" }
+
+void foo (long double);        // { dg-bogus "initializing argument 1 of" }
+
+void
+bar (_Float128 x)
+{
+  foo (x);
+}