public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: std::is_constant_evaluated inside a constraint [PR97051]
@ 2020-09-17 16:36 Patrick Palka
  2020-09-18 19:59 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2020-09-17 16:36 UTC (permalink / raw)
  To: gcc-patches

According to [expr.const]/14, the result of substitution into an atomic
constraint is manifestly constant-evaluated; this patch adjusts the call
to maybe_constant_value in satisfy_atom to that effect.

Tested on x86_64-pc-linux-gnu, and also tested on the cmcstl2 and
range-v3 libraries.  Does this look OK to commit?

gcc/cp/ChangeLog:

	PR c++/97051
	* constraint.cc (satisfy_atom): Pass true as the
	manifestly_const_eval argument to maybe_constant_value.

gcc/testsuite/ChangeLog:

	PR c++/97051
	* g++.dg/cpp2a/is-constant-evaluated11.C: New test.
---
 gcc/cp/constraint.cc                             |  3 ++-
 .../g++.dg/cpp2a/is-constant-evaluated11.C       | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated11.C

diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 0aab3073cc1..8137df59e37 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -2643,7 +2643,8 @@ satisfy_atom (tree t, tree args, subst_info info)
     result = cxx_constant_value (result);
   else
     {
-      result = maybe_constant_value (result);
+      result = maybe_constant_value (result, NULL_TREE,
+				     /*manifestly_const_eval=*/true);
       if (!TREE_CONSTANT (result))
 	result = error_mark_node;
     }
diff --git a/gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated11.C b/gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated11.C
new file mode 100644
index 00000000000..a31867f74fb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated11.C
@@ -0,0 +1,16 @@
+// PR c++/97051
+// { dg-do compile { target c++20 } }
+
+namespace std {
+  constexpr inline bool
+  is_constant_evaluated () noexcept
+  {
+    return __builtin_is_constant_evaluated ();
+  }
+}
+
+template<typename>
+  requires (std::is_constant_evaluated())
+constexpr int a = 0;
+
+constexpr int b = a<int>;
-- 
2.28.0.497.g54e85e7af1


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

* Re: [PATCH] c++: std::is_constant_evaluated inside a constraint [PR97051]
  2020-09-17 16:36 [PATCH] c++: std::is_constant_evaluated inside a constraint [PR97051] Patrick Palka
@ 2020-09-18 19:59 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2020-09-18 19:59 UTC (permalink / raw)
  To: Patrick Palka, gcc-patches

On 9/17/20 12:36 PM, Patrick Palka wrote:
> According to [expr.const]/14, the result of substitution into an atomic
> constraint is manifestly constant-evaluated; this patch adjusts the call
> to maybe_constant_value in satisfy_atom to that effect.
> 
> Tested on x86_64-pc-linux-gnu, and also tested on the cmcstl2 and
> range-v3 libraries.  Does this look OK to commit?

OK.

> gcc/cp/ChangeLog:
> 
> 	PR c++/97051
> 	* constraint.cc (satisfy_atom): Pass true as the
> 	manifestly_const_eval argument to maybe_constant_value.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR c++/97051
> 	* g++.dg/cpp2a/is-constant-evaluated11.C: New test.
> ---
>   gcc/cp/constraint.cc                             |  3 ++-
>   .../g++.dg/cpp2a/is-constant-evaluated11.C       | 16 ++++++++++++++++
>   2 files changed, 18 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated11.C
> 
> diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
> index 0aab3073cc1..8137df59e37 100644
> --- a/gcc/cp/constraint.cc
> +++ b/gcc/cp/constraint.cc
> @@ -2643,7 +2643,8 @@ satisfy_atom (tree t, tree args, subst_info info)
>       result = cxx_constant_value (result);
>     else
>       {
> -      result = maybe_constant_value (result);
> +      result = maybe_constant_value (result, NULL_TREE,
> +				     /*manifestly_const_eval=*/true);
>         if (!TREE_CONSTANT (result))
>   	result = error_mark_node;
>       }
> diff --git a/gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated11.C b/gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated11.C
> new file mode 100644
> index 00000000000..a31867f74fb
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated11.C
> @@ -0,0 +1,16 @@
> +// PR c++/97051
> +// { dg-do compile { target c++20 } }
> +
> +namespace std {
> +  constexpr inline bool
> +  is_constant_evaluated () noexcept
> +  {
> +    return __builtin_is_constant_evaluated ();
> +  }
> +}
> +
> +template<typename>
> +  requires (std::is_constant_evaluated())
> +constexpr int a = 0;
> +
> +constexpr int b = a<int>;
> 


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

end of thread, other threads:[~2020-09-18 19:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-17 16:36 [PATCH] c++: std::is_constant_evaluated inside a constraint [PR97051] Patrick Palka
2020-09-18 19:59 ` 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).