This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/70194] [6 regression] missing -Waddress on constexpr pointer


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70194

--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
This patch fixes the missing warning:

--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -4520,14 +4520,16 @@ cp_build_binary_op (location_t location,
      else
        result_type = type0;

-     if (TREE_CODE (op0) == ADDR_EXPR
-         && decl_with_nonnull_addr_p (TREE_OPERAND (op0, 0)))
+     tree cop0 = fold_non_dependent_expr (op0);
+
+     if (TREE_CODE (cop0) == ADDR_EXPR
+         && decl_with_nonnull_addr_p (TREE_OPERAND (cop0, 0)))
        {
          if ((complain & tf_warning)
          && c_inhibit_evaluation_warnings == 0
-         && !TREE_NO_WARNING (op0))
+         && !TREE_NO_WARNING (cop0))
        warning (OPT_Waddress, "the address of %qD will never be NULL",
-            TREE_OPERAND (op0, 0));
+            TREE_OPERAND (cop0, 0));
        }

      if (CONVERT_EXPR_P (op0)
@@ -4559,14 +4561,16 @@ cp_build_binary_op (location_t location,
      else
        result_type = type1;

-     if (TREE_CODE (op1) == ADDR_EXPR 
-         && decl_with_nonnull_addr_p (TREE_OPERAND (op1, 0)))
+     tree cop1 = fold_non_dependent_expr (op1);
+
+     if (TREE_CODE (cop1) == ADDR_EXPR
+         && decl_with_nonnull_addr_p (TREE_OPERAND (cop1, 0)))
        {
          if ((complain & tf_warning)
          && c_inhibit_evaluation_warnings == 0
-         && !TREE_NO_WARNING (op1))
+         && !TREE_NO_WARNING (cop1))
        warning (OPT_Waddress, "the address of %qD will never be NULL",
-            TREE_OPERAND (op1, 0));
+            TREE_OPERAND (cop1, 0));
        }

      if (CONVERT_EXPR_P (op1)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]