public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: satisfaction value of type const bool [PR104410]
@ 2022-02-07 14:57 Patrick Palka
  2022-02-07 20:35 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2022-02-07 14:57 UTC (permalink / raw)
  To: gcc-patches

Here constant evaluation of the atomic constraint use_func_v<T> with T=int
sensibly yields an INTEGER_CST of type const bool, but the assert in
satisfaction_value expects unqualified bool.  Let's just relax the
assert to accept cv-qualified bool more generally.

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

	PR c++/104410

gcc/cp/ChangeLog:

	* constraint.cc (satisfaction_value): Relax assert to accept
	cv-qualified bool.

gcc/testsuite/ChangeLog:

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

diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index cc4df4216ef..06ebbd1d19e 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -2818,7 +2818,8 @@ satisfaction_value (tree t)
     return t;
 
   gcc_assert (TREE_CODE (t) == INTEGER_CST
-	      && same_type_p (TREE_TYPE (t), boolean_type_node));
+	      && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (t),
+							    boolean_type_node));
   if (integer_zerop (t))
     return boolean_false_node;
   else
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-pr104410.C b/gcc/testsuite/g++.dg/cpp2a/concepts-pr104410.C
new file mode 100644
index 00000000000..dac08e10a0f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-pr104410.C
@@ -0,0 +1,6 @@
+// PR c++/104410
+// { dg-do compile { target c++20 } }
+
+template<class T> constexpr bool use_func_v{};
+template<class T> void f() requires use_func_v<T> || true { }
+template void f<int>();
-- 
2.35.1.46.g38062e73e0


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

* Re: [PATCH] c++: satisfaction value of type const bool [PR104410]
  2022-02-07 14:57 [PATCH] c++: satisfaction value of type const bool [PR104410] Patrick Palka
@ 2022-02-07 20:35 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2022-02-07 20:35 UTC (permalink / raw)
  To: Patrick Palka, gcc-patches

On 2/7/22 09:57, Patrick Palka wrote:
> Here constant evaluation of the atomic constraint use_func_v<T> with T=int
> sensibly yields an INTEGER_CST of type const bool, but the assert in
> satisfaction_value expects unqualified bool.  Let's just relax the
> assert to accept cv-qualified bool more generally.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk and 11?

OK for both.

> 	PR c++/104410
> 
> gcc/cp/ChangeLog:
> 
> 	* constraint.cc (satisfaction_value): Relax assert to accept
> 	cv-qualified bool.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp2a/concepts-pr104410.C: New test.
> ---
>   gcc/cp/constraint.cc                           | 3 ++-
>   gcc/testsuite/g++.dg/cpp2a/concepts-pr104410.C | 6 ++++++
>   2 files changed, 8 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-pr104410.C
> 
> diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
> index cc4df4216ef..06ebbd1d19e 100644
> --- a/gcc/cp/constraint.cc
> +++ b/gcc/cp/constraint.cc
> @@ -2818,7 +2818,8 @@ satisfaction_value (tree t)
>       return t;
>   
>     gcc_assert (TREE_CODE (t) == INTEGER_CST
> -	      && same_type_p (TREE_TYPE (t), boolean_type_node));
> +	      && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (t),
> +							    boolean_type_node));
>     if (integer_zerop (t))
>       return boolean_false_node;
>     else
> diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-pr104410.C b/gcc/testsuite/g++.dg/cpp2a/concepts-pr104410.C
> new file mode 100644
> index 00000000000..dac08e10a0f
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-pr104410.C
> @@ -0,0 +1,6 @@
> +// PR c++/104410
> +// { dg-do compile { target c++20 } }
> +
> +template<class T> constexpr bool use_func_v{};
> +template<class T> void f() requires use_func_v<T> || true { }
> +template void f<int>();


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

end of thread, other threads:[~2022-02-07 20:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-07 14:57 [PATCH] c++: satisfaction value of type const bool [PR104410] Patrick Palka
2022-02-07 20:35 ` 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).