diff options
author | Patrick Palka <ppalka@redhat.com> | 2023-03-14 19:14:29 -0400 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2023-03-14 19:14:29 -0400 |
commit | cd5baeb4489b6a953abbc7f02fea457fd9ed2f83 (patch) | |
tree | a29cdf36c2d282ce80bc3bccf90006b6678f8639 /gcc/cp | |
parent | ec62dc95c4f8776c9f4eff2a9a06f9aef6a2d98a (diff) | |
download | gcc-cd5baeb4489b6a953abbc7f02fea457fd9ed2f83.zip gcc-cd5baeb4489b6a953abbc7f02fea457fd9ed2f83.tar.gz gcc-cd5baeb4489b6a953abbc7f02fea457fd9ed2f83.tar.bz2 |
c++: redeclaring member of constrained class template [PR96830]
An out-of-line definition of a member of a constrained class template
needs to repeat the template's constraints, but it turns out we don't
verify anywhere that the two sets of constraints match. This patch
adds such a check to push_template_decl, nearby a similar consistency
check for the template parameter list lengths.
PR c++/96830
gcc/cp/ChangeLog:
* pt.cc (push_inline_template_parms_recursive): Set
TEMPLATE_PARMS_CONSTRAINTS.
(push_template_decl): For an out-of-line declaration, verify
constraints for each enclosing template scope match those of the
original template declaratation.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/concepts-class5.C: New test.
* g++.dg/cpp2a/concepts-class5a.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/pt.cc | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index eb153ad..84021c2 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -471,6 +471,8 @@ push_inline_template_parms_recursive (tree parmlist, int levels) current_template_parms = tree_cons (size_int (current_template_depth + 1), parms, current_template_parms); + TEMPLATE_PARMS_CONSTRAINTS (current_template_parms) + = TEMPLATE_PARMS_CONSTRAINTS (parmlist); TEMPLATE_PARMS_FOR_INLINE (current_template_parms) = 1; begin_scope (TREE_VEC_LENGTH (parms) ? sk_template_parms : sk_template_spec, @@ -6134,6 +6136,30 @@ push_template_decl (tree decl, bool is_friend) DECL_INTERFACE_KNOWN (decl) = 1; return error_mark_node; } + + /* Check that the constraints for each enclosing template scope are + consistent with the original declarations. */ + if (flag_concepts) + { + tree decl_parms = DECL_TEMPLATE_PARMS (tmpl); + tree scope_parms = current_template_parms; + if (PRIMARY_TEMPLATE_P (tmpl)) + { + decl_parms = TREE_CHAIN (decl_parms); + scope_parms = TREE_CHAIN (scope_parms); + } + while (decl_parms) + { + if (!template_requirements_equivalent_p (decl_parms, scope_parms)) + { + error ("redeclaration of %qD with different constraints", + TPARMS_PRIMARY_TEMPLATE (TREE_VALUE (decl_parms))); + break; + } + decl_parms = TREE_CHAIN (decl_parms); + scope_parms = TREE_CHAIN (scope_parms); + } + } } gcc_checking_assert (!tmpl || DECL_TEMPLATE_RESULT (tmpl) == decl); |