aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2021-04-08 13:07:37 -0400
committerPatrick Palka <ppalka@redhat.com>2021-04-08 13:07:37 -0400
commit05708d6eef87a3dd0c68b1aed7f8d9c3824062b8 (patch)
tree71f82a4fb51036fb05439ae45b5aabf9ea4bab18
parent0567998287649833744ad728b1dfb785fe17c545 (diff)
downloadgcc-05708d6eef87a3dd0c68b1aed7f8d9c3824062b8.zip
gcc-05708d6eef87a3dd0c68b1aed7f8d9c3824062b8.tar.gz
gcc-05708d6eef87a3dd0c68b1aed7f8d9c3824062b8.tar.bz2
c++: constrained CTAD for nested class template [PR97679]
In the testcase below, we're crashing during constraint checking of the implicitly generated deduction guides for the nested class template A::B because we never substitute the outer template arguments (for A) into the constraint, neither ahead of time nor as part of satisfaction. Ideally we'd like to avoid substituting into a constraint ahead of time, but the "flattening" vector 'tsubst_args' is constructed under the assumption that all outer template arguments are already substituted in, and eliminating this assumption to yield a flattening vector that includes outer (generic) template arguments suitable for substituting into the constraint would be tricky and error-prone. So this patch takes the approximate approach of substituting the outer arguments into the constraint ahead of time, so that the subsequent substitution of 'tsubst_args' is coherent and so later satisfaction just works. gcc/cp/ChangeLog: PR c++/97679 * pt.c (build_deduction_guide): Document OUTER_ARGS. Substitute them into the propagated constraints. gcc/testsuite/ChangeLog: PR c++/97679 * g++.dg/cpp2a/concepts-ctad3.C: New test.
-rw-r--r--gcc/cp/pt.c20
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/concepts-ctad3.C16
2 files changed, 33 insertions, 3 deletions
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 46b237f..842a58c 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -28602,7 +28602,8 @@ rewrite_tparm_list (tree oldelt, unsigned index, unsigned level,
/* Returns a C++17 class deduction guide template based on the constructor
CTOR. As a special case, CTOR can be a RECORD_TYPE for an implicit default
guide, REFERENCE_TYPE for an implicit copy/move guide, or TREE_LIST for an
- aggregate initialization guide. */
+ aggregate initialization guide. OUTER_ARGS are the template arguments
+ for the enclosing scope of the class. */
static tree
build_deduction_guide (tree type, tree ctor, tree outer_args, tsubst_flags_t complain)
@@ -28728,7 +28729,15 @@ build_deduction_guide (tree type, tree ctor, tree outer_args, tsubst_flags_t com
if (fparms == error_mark_node)
ok = false;
if (ci)
- ci = tsubst_constraint_info (ci, tsubst_args, complain, ctor);
+ {
+ if (outer_args)
+ /* FIXME: We'd like to avoid substituting outer template
+ arguments into the constraint ahead of time, but the
+ construction of tsubst_args assumes that outer arguments
+ are already substituted in. */
+ ci = tsubst_constraint_info (ci, outer_args, complain, ctor);
+ ci = tsubst_constraint_info (ci, tsubst_args, complain, ctor);
+ }
/* Parms are to have DECL_CHAIN tsubsted, which would be skipped if
cp_unevaluated_operand. */
@@ -28744,7 +28753,12 @@ build_deduction_guide (tree type, tree ctor, tree outer_args, tsubst_flags_t com
fparms = tsubst_arg_types (fparms, targs, NULL_TREE, complain, ctor);
fargs = tsubst (fargs, targs, complain, ctor);
if (ci)
- ci = tsubst_constraint_info (ci, targs, complain, ctor);
+ {
+ if (outer_args)
+ /* FIXME: As above. */
+ ci = tsubst_constraint_info (ci, outer_args, complain, ctor);
+ ci = tsubst_constraint_info (ci, targs, complain, ctor);
+ }
}
--processing_template_decl;
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-ctad3.C b/gcc/testsuite/g++.dg/cpp2a/concepts-ctad3.C
new file mode 100644
index 0000000..3546b74
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-ctad3.C
@@ -0,0 +1,16 @@
+// PR c++/97679
+// { dg-do compile { target c++20 } }
+
+template <bool V> struct A {
+ template <class T> struct B {
+ B(T) requires V;
+ template <class U> B(T, U) requires V || (__is_same(T, char) && __is_same(U, int));
+ };
+};
+
+A<true>::B x1(0);
+A<false>::B x2(0); // { dg-error "deduction|no match" }
+
+A<true>::B y1(0, '0');
+A<false>::B y2(0, '0'); // { dg-error "deduction|no match" }
+A<false>::B y3('0', 0);