Hi,

On 02/03/2015 03:19 PM, Jason Merrill wrote:
On 02/03/2015 05:45 AM, Paolo Carlini wrote:
+          if (TREE_CODE (pfn0) != ADDR_EXPR
+          || !decl_with_nonnull_addr_p (TREE_OPERAND (pfn0, 0)))

I don't like duplicating the logic for when we might know the pfn is non-null; that seems fragile.
I agree, seems fragile, on the other hand would be rather precise, IMHO. We could at least have a function wrapping the above and a comment in both places. Anyway...
I'd rather go with the tf_none approach, or otherwise suppress the warning.
There are so many ways to fix this, and I'm a bit confused by the range of warning suppression mechanisms we have got at this point (eg, TREE_NO_WARNING, c_inhibit_evaluation_warnings, the new warning_sentinel in pt.c, tf_none, etc.. ;) But this case should be at least relatively safe because the expression is internally generated, right? Fiddling with tf_none, as mentioned by Manuel, should indeed work, but then, how far we would go with that? Only the 'e2 = cp_build_binary_op (location, EQ_EXPR, pfn0, ...)' lines or more of the calls for synthesized expressions? Would it be Ok for 5.0 to just use TREE_NO_WARNING like in the below?

Thanks,
Paolo.

/////////////////////

Index: cp/typeck.c
===================================================================
--- cp/typeck.c (revision 220371)
+++ cp/typeck.c (working copy)
@@ -4415,7 +4415,8 @@ cp_build_binary_op (location_t location,
              && decl_with_nonnull_addr_p (TREE_OPERAND (op0, 0)))
            {
              if ((complain & tf_warning)
-                 && c_inhibit_evaluation_warnings == 0)
+                 && c_inhibit_evaluation_warnings == 0
+                 && !TREE_NO_WARNING (op0))
                warning (OPT_Waddress, "the address of %qD will never be NULL",
                         TREE_OPERAND (op0, 0));
            }
@@ -4436,7 +4437,8 @@ cp_build_binary_op (location_t location,
              && decl_with_nonnull_addr_p (TREE_OPERAND (op1, 0)))
            {
              if ((complain & tf_warning)
-                 && c_inhibit_evaluation_warnings == 0)
+                 && c_inhibit_evaluation_warnings == 0
+                 && !TREE_NO_WARNING (op1))
                warning (OPT_Waddress, "the address of %qD will never be NULL",
                         TREE_OPERAND (op1, 0));
            }
@@ -4537,6 +4539,8 @@ cp_build_binary_op (location_t location,
            op1 = save_expr (op1);
 
          pfn0 = pfn_from_ptrmemfunc (op0);
+         /* Avoid -Waddress warnings (c++/64877).  */
+         TREE_NO_WARNING (pfn0) = 1;
          pfn1 = pfn_from_ptrmemfunc (op1);
          delta0 = delta_from_ptrmemfunc (op0);
          delta1 = delta_from_ptrmemfunc (op1);
Index: testsuite/g++.dg/warn/Waddress-2.C
===================================================================
--- testsuite/g++.dg/warn/Waddress-2.C  (revision 0)
+++ testsuite/g++.dg/warn/Waddress-2.C  (working copy)
@@ -0,0 +1,24 @@
+// PR c++/64877
+// { dg-options "-Waddress" }
+
+template<class Derived>
+struct S
+{
+  void m() {
+  }
+
+  S()
+  {
+    if (&S<Derived>::Unwrap != &Derived::Unwrap)
+      m();
+  }
+
+  void Unwrap() {
+  }
+};
+
+struct T : public S<T>
+{
+};
+
+T t;

Reply via email to