Skip to content

Commit ab7ce5d

Browse files
author
Patrick Palka
committed
c++: constrained corresponding using from partial spec [PR121351]
When comparing constraints during correspondence checking for a using from a partial specialization, we need to substitute the partial specialization arguments into the constraints rather than the primary template arguments. Otherwise we incorrectly reject e.g. the below testcase as ambiguous since we substitute T=int* instead of T=int into #1's constraints and don't notice the correspondence. This patch corrects the recent r16-2771-gb9f1cc4e119da9 fix by using outer_template_args instead of TI_ARGS of the DECL_CONTEXT, which should always give the correct outer arguments for substitution. PR c++/121351 gcc/cp/ChangeLog: * class.cc (add_method): Use outer_template_args when substituting outer template arguments into constraints. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-using7.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com> (cherry picked from commit 0ab1e31)
1 parent 34999e0 commit ab7ce5d

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

gcc/cp/class.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,14 +1360,14 @@ add_method (tree type, tree method, bool via_using)
13601360
{
13611361
if (TREE_CODE (fn) == TEMPLATE_DECL)
13621362
++processing_template_decl;
1363-
if (tree ti = CLASSTYPE_TEMPLATE_INFO (DECL_CONTEXT (fn)))
1363+
if (tree outer_args = outer_template_args (fn))
13641364
fn_constraints = tsubst_constraint_info (fn_constraints,
1365-
TI_ARGS (ti),
1365+
outer_args,
13661366
tf_warning_or_error,
13671367
fn);
1368-
if (tree ti = CLASSTYPE_TEMPLATE_INFO (DECL_CONTEXT (method)))
1368+
if (tree outer_args = outer_template_args (method))
13691369
method_constraints = tsubst_constraint_info (method_constraints,
1370-
TI_ARGS (ti),
1370+
outer_args,
13711371
tf_warning_or_error,
13721372
method);
13731373
if (TREE_CODE (fn) == TEMPLATE_DECL)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// PR c++/121351
2+
// { dg-do compile { target c++20 } }
3+
4+
template<class T> concept C = true;
5+
6+
template<class T>
7+
struct A;
8+
9+
template<class T>
10+
struct A<T*> {
11+
template<class U> void f(U) requires C<T>; // #1
12+
};
13+
14+
template<class T>
15+
struct B : A<T> {
16+
using A<T>::f;
17+
template<class U> void f(U) requires C<int>; // #2
18+
};
19+
20+
int main() {
21+
B<int*> b;
22+
b.f(42); // OK, #2 corresponds to and therefore hides #1
23+
}

0 commit comments

Comments
 (0)