Here one operand of the comparison had been reduced to an INTEGER_CST
and the other was still a PTRMEM_CST.  We should deal with that
situation by reducing the PTRMEM_CST.

Tested x86_64-pc-linux-gnu, applying to trunk and 6.
commit 984c524f8a302059a1f71f84935dcae5f9914c7f
Author: Jason Merrill <ja...@redhat.com>
Date:   Wed Jul 20 17:11:00 2016 -0400

        PR c++/71896 - constexpr pointer-to-member comparison.
    
        * constexpr.c (cxx_eval_binary_expression): Handle comparison
        between lowered and unlowered PTRMEM_CST.

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 346fdfa..240c606 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -1838,6 +1838,10 @@ cxx_eval_binary_expression (const constexpr_ctx *ctx, 
tree t,
               && (null_member_pointer_value_p (lhs)
                   || null_member_pointer_value_p (rhs)))
        r = constant_boolean_node (!is_code_eq, type);
+      else if (TREE_CODE (lhs) == PTRMEM_CST)
+       lhs = cplus_expand_constant (lhs);
+      else if (TREE_CODE (rhs) == PTRMEM_CST)
+       rhs = cplus_expand_constant (rhs);
     }
 
   if (r == NULL_TREE)
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ptrmem6.C 
b/gcc/testsuite/g++.dg/cpp0x/constexpr-ptrmem6.C
new file mode 100644
index 0000000..ed18ab1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ptrmem6.C
@@ -0,0 +1,13 @@
+// PR c++/71896
+// { dg-do compile { target c++11 } }
+
+struct Foo {
+  int x;
+};
+
+constexpr bool compare(int Foo::*t) { return t == &Foo::x; }
+
+constexpr bool b = compare(&Foo::x);
+
+#define SA(X) static_assert ((X),#X)
+SA(b);

Reply via email to