aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-08-10 17:53:46 +0200
committerGiuliano Belinassi <giuliano.belinassi@usp.br>2020-08-17 15:07:55 -0300
commitc2574d63c52a690a703b802142ffaeca115fad84 (patch)
tree29871e9d718d9ed5404eb6c7d5edc4245b0833a0
parent53cf2ed28ca11ff19b73ab73065e20c9d3c47861 (diff)
downloadgcc-c2574d63c52a690a703b802142ffaeca115fad84.zip
gcc-c2574d63c52a690a703b802142ffaeca115fad84.tar.gz
gcc-c2574d63c52a690a703b802142ffaeca115fad84.tar.bz2
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.
-rw-r--r--gcc/cp/constexpr.c4
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/spaceship-constexpr3.C7
2 files changed, 9 insertions, 2 deletions
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index ab747a5..8ee0f2a 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -3085,8 +3085,8 @@ cxx_eval_binary_expression (const constexpr_ctx *ctx, tree t,
else if (code == SPACESHIP_EXPR)
{
r = genericize_spaceship (type, lhs, rhs);
- r = cxx_eval_constant_expression (ctx, r, lval, non_constant_p,
- overflow_p);
+ return cxx_eval_constant_expression (ctx, r, lval, non_constant_p,
+ overflow_p);
}
if (r == NULL_TREE)
diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-constexpr3.C b/gcc/testsuite/g++.dg/cpp2a/spaceship-constexpr3.C
new file mode 100644
index 0000000..95f03e6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-constexpr3.C
@@ -0,0 +1,7 @@
+// PR c++/96497
+// { dg-do compile { target c++20 } }
+
+#include <compare>
+
+static_assert(std::partial_ordering(std::strong_ordering::less) < 0);
+static_assert(std::partial_ordering(1 <=> 2) < 0);