Skip to content

Commit 0ab1e31

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>
1 parent f647d4f commit 0ab1e31

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
@@ -1365,14 +1365,14 @@ add_method (tree type, tree method, bool via_using)
13651365
{
13661366
if (TREE_CODE (fn) == TEMPLATE_DECL)
13671367
++processing_template_decl;
1368-
if (tree ti = CLASSTYPE_TEMPLATE_INFO (DECL_CONTEXT (fn)))
1368+
if (tree outer_args = outer_template_args (fn))
13691369
fn_constraints = tsubst_constraint_info (fn_constraints,
1370-
TI_ARGS (ti),
1370+
outer_args,
13711371
tf_warning_or_error,
13721372
fn);
1373-
if (tree ti = CLASSTYPE_TEMPLATE_INFO (DECL_CONTEXT (method)))
1373+
if (tree outer_args = outer_template_args (method))
13741374
method_constraints = tsubst_constraint_info (method_constraints,
1375-
TI_ARGS (ti),
1375+
outer_args,
13761376
tf_warning_or_error,
13771377
method);
13781378
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)