diff options
author | Jason Merrill <jason@redhat.com> | 2016-07-21 02:05:51 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2016-07-21 02:05:51 -0400 |
commit | dd5dda561e34151f0145d0c0ceabf4d4a14509a3 (patch) | |
tree | d5526e15a599d07e8725ca86188cdca31c1ff634 /gcc | |
parent | 4683f47cff862d23d48c2b9c6938b8b0e6b3253c (diff) | |
download | gcc-dd5dda561e34151f0145d0c0ceabf4d4a14509a3.zip gcc-dd5dda561e34151f0145d0c0ceabf4d4a14509a3.tar.gz gcc-dd5dda561e34151f0145d0c0ceabf4d4a14509a3.tar.bz2 |
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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/cp/constexpr.c | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/constexpr-ptrmem6.C | 13 |
3 files changed, 21 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index be223f2..78487ea 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -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. 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); |