re PR c++/64877 (strange warning message from -Waddress)
authorPaolo Carlini <paolo@gcc.gnu.org>
Tue, 3 Feb 2015 17:21:49 +0000 (17:21 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Tue, 3 Feb 2015 17:21:49 +0000 (17:21 +0000)
/cp
2015-02-03  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/64877
* typeck.c (cp_build_binary_op): Avoid spurious -Waddress warnings
for generated expressions.

/testsuite
2015-02-03  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/64877
* g++.dg/warn/Waddress-2.C: New.

From-SVN: r220374

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Waddress-2.C [new file with mode: 0644]

index 7c200d629a275bc7d104c053efab856898f92d73..60d7e676d9578501a633cf6a95c3add25fb0f961 100644 (file)
@@ -1,3 +1,9 @@
+2015-02-03  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/64877
+       * typeck.c (cp_build_binary_op): Avoid spurious -Waddress warnings
+       for generated expressions.
+
 2015-02-02  Ville Voutilainen  <ville.voutilainen@gmail.com>
 
        PR c++/64901
index 32ee78ec307014f36d6bca98019d308331d25406..4c128b7ebe472cf255094da12080acaa65043800 100644 (file)
@@ -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,9 @@ cp_build_binary_op (location_t location,
            op1 = save_expr (op1);
 
          pfn0 = pfn_from_ptrmemfunc (op0);
+         /* Avoid -Waddress warnings (c++/64877).  */
+         if (TREE_CODE (pfn0) == ADDR_EXPR)
+           TREE_NO_WARNING (pfn0) = 1;
          pfn1 = pfn_from_ptrmemfunc (op1);
          delta0 = delta_from_ptrmemfunc (op0);
          delta1 = delta_from_ptrmemfunc (op1);
index 335f2dad494827c77538317a532d960db223a4de..00c0450dbb597aac433f7b8f5b6edbbc514b6490 100644 (file)
@@ -1,9 +1,14 @@
+2015-02-03  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/64877
+       * g++.dg/warn/Waddress-2.C: New.
+
 2015-02-03  Segher Boessenkool  <segher@kernel.crashing.org>
 
        PR middle-end/61225
-       gcc.target/i386/pr49095.c: XFAIL for ia32.
+       gcc.target/i386/pr49095.c: XFAIL for ia32.
 
-2015-02-03    <dodji@redhat.com>
+2015-02-03  Dodji Seketeli  <dodji@redhat.com>
 
        PR preprocessor/64803
        * gcc.dg/cpp/builtin-macro-1.c: New test case.
diff --git a/gcc/testsuite/g++.dg/warn/Waddress-2.C b/gcc/testsuite/g++.dg/warn/Waddress-2.C
new file mode 100644 (file)
index 0000000..58594f9
--- /dev/null
@@ -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;