From: Jason Merrill Date: Thu, 21 Jul 2016 06:05:51 +0000 (-0400) Subject: PR c++/71896 - constexpr pointer-to-member comparison. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=dd5dda561e34151f0145d0c0ceabf4d4a14509a3;p=gcc.git PR c++/71896 - constexpr pointer-to-member comparison. * constexpr.c (cxx_eval_binary_expression): Handle comparison between lowered and unlowered PTRMEM_CST. From-SVN: r238562 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index be223f2c177..78487eac174 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2016-07-21 Jason Merrill + 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. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 346fdfad908..240c606f82c 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 00000000000..ed18ab1a630 --- /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);