public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: satisfaction of non-dep member alias template-id
@ 2023-05-02 21:13 Patrick Palka
  2023-05-03 19:37 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2023-05-02 21:13 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, Patrick Palka

constraints_satisfied_p already carefully checks dependence of template
arguments before proceeding with satisfaction, so the dependence check
in instantiate_alias_template is unnecessary and overly conservative.
Getting rid of it allows us to check satisfaction ahead of time in more
cases as in the below testcase.

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

gcc/cp/ChangeLog:

	* pt.cc (instantiate_alias_template): Exit early upon
	error from coerce_template_parms.  Remove dependence test
	guarding constraints_satisfied_p.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/concepts-alias6.C: New test.
---
 gcc/cp/pt.cc                                 |  6 +++---
 gcc/testsuite/g++.dg/cpp2a/concepts-alias6.C | 15 +++++++++++++++
 2 files changed, 18 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-alias6.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 3f1cf139bbd..930291917f2 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -22178,11 +22178,11 @@ instantiate_alias_template (tree tmpl, tree args, tsubst_flags_t complain)
 
   args = coerce_template_parms (DECL_TEMPLATE_PARMS (tmpl),
 				args, tmpl, complain);
+  if (args == error_mark_node)
+    return args;
 
   /* FIXME check for satisfaction in check_instantiated_args.  */
-  if (flag_concepts
-      && !any_dependent_template_arguments_p (args)
-      && !constraints_satisfied_p (tmpl, args))
+  if (!constraints_satisfied_p (tmpl, args))
     {
       if (complain & tf_error)
 	{
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-alias6.C b/gcc/testsuite/g++.dg/cpp2a/concepts-alias6.C
new file mode 100644
index 00000000000..4acd57d36e6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-alias6.C
@@ -0,0 +1,15 @@
+// Verify we can check satisfaction of non-dependent member alias
+// template-ids whose constraints don't depend on outer template
+// arguments ahead of time.
+// { dg-do compile { target c++20 } }
+
+template<class T>
+struct A {
+  template<int N> requires (N > 0)
+  using at = T;
+
+  void f() {
+    using ty1 = at<0>; // { dg-error "constraint" }
+    using ty2 = at<1>;
+  }
+};
-- 
2.40.1.459.g48d89b51b3


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

* Re: [PATCH] c++: satisfaction of non-dep member alias template-id
  2023-05-02 21:13 [PATCH] c++: satisfaction of non-dep member alias template-id Patrick Palka
@ 2023-05-03 19:37 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2023-05-03 19:37 UTC (permalink / raw)
  To: Patrick Palka, gcc-patches

On 5/2/23 17:13, Patrick Palka wrote:
> constraints_satisfied_p already carefully checks dependence of template
> arguments before proceeding with satisfaction, so the dependence check
> in instantiate_alias_template is unnecessary and overly conservative.
> Getting rid of it allows us to check satisfaction ahead of time in more
> cases as in the below testcase.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk?

OK.

> gcc/cp/ChangeLog:
> 
> 	* pt.cc (instantiate_alias_template): Exit early upon
> 	error from coerce_template_parms.  Remove dependence test
> 	guarding constraints_satisfied_p.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp2a/concepts-alias6.C: New test.
> ---
>   gcc/cp/pt.cc                                 |  6 +++---
>   gcc/testsuite/g++.dg/cpp2a/concepts-alias6.C | 15 +++++++++++++++
>   2 files changed, 18 insertions(+), 3 deletions(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-alias6.C
> 
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index 3f1cf139bbd..930291917f2 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -22178,11 +22178,11 @@ instantiate_alias_template (tree tmpl, tree args, tsubst_flags_t complain)
>   
>     args = coerce_template_parms (DECL_TEMPLATE_PARMS (tmpl),
>   				args, tmpl, complain);
> +  if (args == error_mark_node)
> +    return args;
>   
>     /* FIXME check for satisfaction in check_instantiated_args.  */
> -  if (flag_concepts
> -      && !any_dependent_template_arguments_p (args)
> -      && !constraints_satisfied_p (tmpl, args))
> +  if (!constraints_satisfied_p (tmpl, args))
>       {
>         if (complain & tf_error)
>   	{
> diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-alias6.C b/gcc/testsuite/g++.dg/cpp2a/concepts-alias6.C
> new file mode 100644
> index 00000000000..4acd57d36e6
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-alias6.C
> @@ -0,0 +1,15 @@
> +// Verify we can check satisfaction of non-dependent member alias
> +// template-ids whose constraints don't depend on outer template
> +// arguments ahead of time.
> +// { dg-do compile { target c++20 } }
> +
> +template<class T>
> +struct A {
> +  template<int N> requires (N > 0)
> +  using at = T;
> +
> +  void f() {
> +    using ty1 = at<0>; // { dg-error "constraint" }
> +    using ty2 = at<1>;
> +  }
> +};


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

end of thread, other threads:[~2023-05-03 19:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-02 21:13 [PATCH] c++: satisfaction of non-dep member alias template-id Patrick Palka
2023-05-03 19:37 ` 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).