diff mbox

C++ PATCH for C++/71121 (wrong -Waddress warning with PMF and constexpr)

Message ID CADzB+2kMQKQR-t0LrWWDEpJeL6b+zastzsOUVEneggc4Hs+Jiw@mail.gmail.com
State New
Headers show

Commit Message

Jason Merrill July 21, 2016, 5:55 a.m. UTC
The problem here was that the code that tries to prevent the -Waddress
warning used cp_fully_fold, and later code used maybe_constant_value,
and the latter simplified the operand more so that it exposed the
ADDR_EXPR to the -Waddress warning.  Fixed by calling
maybe_constant_value from cp_fully_fold.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 16703ee40f25fc3afab05b4d25741eb27ce70825
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Jul 20 13:10:40 2016 -0400

    	PR c++/71121 - -Waddress, constexpr, and PMFs.
    
    	* cp-gimplify.c (cp_fully_fold): First call maybe_constant_value.
diff mbox

Patch

diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index 41ab35f..ee28ba5 100644
--- a/gcc/cp/cp-gimplify.c
+++ b/gcc/cp/cp-gimplify.c
@@ -1954,6 +1954,11 @@  cxx_omp_disregard_value_expr (tree decl, bool shared)
 tree
 cp_fully_fold (tree x)
 {
+  if (processing_template_decl)
+    return x;
+  /* FIXME cp_fold ought to be a superset of maybe_constant_value so we don't
+     have to call both.  */
+  x = maybe_constant_value (x);
   return cp_fold (x);
 }
 
diff --git a/gcc/testsuite/g++.dg/warn/Waddress-4.C b/gcc/testsuite/g++.dg/warn/Waddress-4.C
new file mode 100644
index 0000000..a9fdfc4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Waddress-4.C
@@ -0,0 +1,15 @@ 
+// PR c++/71121
+// { dg-do compile { target c++14 } }
+// { dg-options -Waddress }
+
+struct CC { void mbr(); };
+
+constexpr auto getFunc() {
+    return &CC::mbr;
+}
+
+constexpr bool xxx(void (CC::*_a)())
+{
+    constexpr auto f = getFunc();
+    return (f == _a);
+}
diff --git a/gcc/testsuite/g++.dg/warn/overflow-warn-7.C b/gcc/testsuite/g++.dg/warn/overflow-warn-7.C
deleted file mode 100644
index b536563..0000000
--- a/gcc/testsuite/g++.dg/warn/overflow-warn-7.C
+++ /dev/null
@@ -1,17 +0,0 @@ 
-// PR c/62096 - unexpected warning overflow in implicit constant conversion
-// { dg-do compile { target c++11 } }
-
-enum E {
-    E_val  = 1,
-};
-
-inline constexpr E operator~(E e)
-{
-  return E(~static_cast<int>(e));
-}
-
-int main()
-{
-  int val = ~E_val;   // { dg-bogus "overflow in implicit constant conversion" }
-  (void) val;
-}