public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: Fix ICE with non-constant satisfaction [PR98644]
@ 2021-01-13 17:05 Patrick Palka
  2021-01-19 20:40 ` Jason Merrill
  0 siblings, 1 reply; 6+ messages in thread
From: Patrick Palka @ 2021-01-13 17:05 UTC (permalink / raw)
  To: gcc-patches

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-03-11 22:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-13 17:05 [PATCH] c++: Fix ICE with non-constant satisfaction [PR98644] Patrick Palka
2021-01-19 20:40 ` Jason Merrill
2022-03-01  4:10   ` Patrick Palka
2022-03-10 20:05     ` Jason Merrill
2022-03-11 15:46       ` Patrick Palka
2022-03-11 22:16         ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).