[PATCH] c++: satisfaction of non-dep member alias template-id
Patrick Palka
ppalka@redhat.com
Tue May 2 21:13:10 GMT 2023
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
More information about the Gcc-patches
mailing list