In the below testcase, the expression of the atomic constraint after
substitution is (int *) NON_LVALUE_EXPR <1> != 0B which is not a C++
constant expression, but its TREE_CONSTANT flag is set (from build2),
so satisfy_atom fails to notice that it's non-constant (and we end
up tripping over the assert in satisfaction_value).

Since TREE_CONSTANT doesn't necessarily correspond to C++ constantness,
this patch makes satisfy_atom instead check is_rvalue_constant_expression.

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk/10?

gcc/cp/ChangeLog:

        PR c++/98644
        * constraint.cc (satisfy_atom): Check is_rvalue_constant_expression
        instead of TREE_CONSTANT.

gcc/testsuite/ChangeLog:

        PR c++/98644
        * g++.dg/cpp2a/concepts-pr98644.C: New test.
---
 gcc/cp/constraint.cc                          | 2 +-
 gcc/testsuite/g++.dg/cpp2a/concepts-pr98644.C | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-pr98644.C

diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 9049d087859..f99a25dc8a4 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -2969,7 +2969,7 @@ satisfy_atom (tree t, tree args, sat_info info)
     {
       result = maybe_constant_value (result, NULL_TREE,
                                     /*manifestly_const_eval=*/true);
-      if (!TREE_CONSTANT (result))
+      if (!is_rvalue_constant_expression (result))
        result = error_mark_node;
     }
   result = satisfaction_value (result);
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-pr98644.C 
b/gcc/testsuite/g++.dg/cpp2a/concepts-pr98644.C
new file mode 100644
index 00000000000..6772f72a3ce
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-pr98644.C
@@ -0,0 +1,7 @@
+// PR c++/98644
+// { dg-do compile { target c++20 } }
+
+template<class T> concept Signed = bool(T(1)); // { dg-error 
"reinterpret_cast" }
+static_assert(Signed<int*>); // { dg-error "non-constant" }
+
+constexpr bool B = requires { requires bool((char *)1); }; // { dg-error 
"reinterpret_cast" }
-- 
2.30.0

Reply via email to