]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[c++] suppress redundant null-addr warn in pfn from pmfn
authorAlexandre Oliva <oliva@adacore.com>
Fri, 3 Mar 2023 04:46:56 +0000 (01:46 -0300)
committerAlexandre Oliva <oliva@gnu.org>
Fri, 3 Mar 2023 04:46:56 +0000 (01:46 -0300)
When TARGET_PTRMEMFUNC_VBIT_LOCATION == ptrmemfunc_vbit_in_delta, when
we warn about comparing a pointer-to-member-function with NULL, we
also warn about comparing the pointer-to-function extracted from it
with NULL, which is redundant.  Suppress the redundant warning.

for  gcc/cp/ChangeLog

* typeck.cc (cp_build_binary_op): Suppress redundant warning
for pfn null test in pmfn test with vbit-in-delta.

gcc/cp/typeck.cc

index 4afb5e4f0d420792e63a8b5793518693cd074f3f..d5a3e501d8e9121c4d878beddea7c82d9121c2c4 100644 (file)
@@ -5780,11 +5780,18 @@ cp_build_binary_op (const op_location_t &location,
 
              pfn0 = pfn_from_ptrmemfunc (op0);
              delta0 = delta_from_ptrmemfunc (op0);
-             e1 = cp_build_binary_op (location,
-                                      EQ_EXPR,
-                                      pfn0,
-                                      build_zero_cst (TREE_TYPE (pfn0)),
-                                      complain);
+             {
+               /* If we will warn below about a null-address compare
+                  involving the orig_op0 ptrmemfunc, we'd likely also
+                  warn about the pfn0's null-address compare, and
+                  that would be redundant, so suppress it.  */
+               warning_sentinel ws (warn_address);
+               e1 = cp_build_binary_op (location,
+                                        EQ_EXPR,
+                                        pfn0,
+                                        build_zero_cst (TREE_TYPE (pfn0)),
+                                        complain);
+             }
              e2 = cp_build_binary_op (location,
                                       BIT_AND_EXPR,
                                       delta0,