]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Fix constexpr evaluation of SPACESHIP_EXPR [PR96497]
authorJakub Jelinek <jakub@redhat.com>
Mon, 10 Aug 2020 15:53:46 +0000 (17:53 +0200)
committerJakub Jelinek <jakub@redhat.com>
Tue, 25 Aug 2020 14:37:32 +0000 (16:37 +0200)
commitaaac798d29acb61ab510c6106d10fc641becfcb7
treead7ad631346b1aa4b5216b054ef8b267b71b1c2a
parentcbde60ab63e7b94a664fb8fef8640d0d6a63b13c
c++: Fix constexpr evaluation of SPACESHIP_EXPR [PR96497]

The following valid testcase is rejected, because cxx_eval_binary_expression
is called on the SPACESHIP_EXPR with lval = true, as the address of the
spaceship needs to be passed to a method call.
After recursing on the operands and calling genericize_spaceship which turns
it into a TARGET_EXPR with initialization, we call cxx_eval_constant_expression
on it which succeeds, but then we fall through into code that will
VERIFY_CONSTANT (r) which FAILs because it is an address of a variable.  Rather
than avoiding that for lval = true and SPACESHIP_EXPR, the patch just tail
calls cxx_eval_constant_expression - I believe that call should perform all
the needed verifications.

2020-08-10  Jakub Jelinek  <jakub@redhat.com>

PR c++/96497
* constexpr.c (cxx_eval_binary_expression): For SPACESHIP_EXPR, tail
call cxx_eval_constant_expression after genericize_spaceship to avoid
undesirable further VERIFY_CONSTANT.

* g++.dg/cpp2a/spaceship-constexpr3.C: New test.

(cherry picked from commit 5c64df80df274c753bfc8415bd902e1180e76f6a)
gcc/cp/constexpr.c
gcc/testsuite/g++.dg/cpp2a/spaceship-constexpr3.C [new file with mode: 0644]