]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: satisfaction of non-dep member alias template-id
authorPatrick Palka <ppalka@redhat.com>
Sun, 7 May 2023 16:05:24 +0000 (12:05 -0400)
committerPatrick Palka <ppalka@redhat.com>
Sun, 7 May 2023 16:05:24 +0000 (12:05 -0400)
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.

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
gcc/testsuite/g++.dg/cpp2a/concepts-alias6.C [new file with mode: 0644]

index bb4e275d714bf798c195976d2bdf3ed305fb8b06..d400b9f3eb2523962ec62ac0473a7c5522e62c7c 100644 (file)
@@ -22181,11 +22181,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 error_mark_node;
 
   /* 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 (file)
index 0000000..55f25a7
--- /dev/null
@@ -0,0 +1,15 @@
+// Verify we can check satisfaction of a non-dependent member alias
+// template-id whose constraints don't depend on outer template
+// parameters 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>;
+  }
+};