PR c++/71896 - constexpr pointer-to-member comparison.
authorJason Merrill <jason@redhat.com>
Thu, 21 Jul 2016 06:05:51 +0000 (02:05 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 21 Jul 2016 06:05:51 +0000 (02:05 -0400)
* constexpr.c (cxx_eval_binary_expression): Handle comparison
between lowered and unlowered PTRMEM_CST.

From-SVN: r238562

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/testsuite/g++.dg/cpp0x/constexpr-ptrmem6.C [new file with mode: 0644]

index be223f2c17799be3c180e556d96fd67c6d86287c..78487eac174a14da264270737c8ac8c82b321bdd 100644 (file)
@@ -1,5 +1,9 @@
 2016-07-21  Jason Merrill  <jason@redhat.com>
 
+       PR c++/71896
+       * constexpr.c (cxx_eval_binary_expression): Handle comparison
+       between lowered and unlowered PTRMEM_CST.
+
        PR c++/65168
        * typeck.c (cp_truthvalue_conversion): Compare pointers to nullptr.
        Don't set c_inhibit_evaluation_warnings.
index 346fdfad90868234c3e8a5a6086dac44cb18b305..240c606f82c817bbeea47d97c9f1f4c1462a09b5 100644 (file)
@@ -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 (file)
index 0000000..ed18ab1
--- /dev/null
@@ -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);