Skip to content

Commit cf42677

Browse files
committed
[Clang] Fix a partial ordering bug involving CTAD injected template arguments
1 parent 34951f7 commit cf42677

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5525,6 +5525,8 @@ static TemplateDeductionResult CheckDeductionConsistency(
55255525
// FIXME: A substitution can be incomplete on a non-structural part of the
55265526
// type. Use the canonical type for now, until the TemplateInstantiator can
55275527
// deal with that.
5528+
if (auto *Injected = dyn_cast<InjectedClassNameType>(P))
5529+
P = Injected->getInjectedSpecializationType();
55285530
QualType InstP = S.SubstType(P.getCanonicalType(), MLTAL, FTD->getLocation(),
55295531
FTD->getDeclName(), &IsIncompleteSubstitution);
55305532
if (InstP.isNull() && !IsIncompleteSubstitution)
@@ -5539,9 +5541,13 @@ static TemplateDeductionResult CheckDeductionConsistency(
55395541
if (auto *PA = dyn_cast<PackExpansionType>(A);
55405542
PA && !isa<PackExpansionType>(InstP))
55415543
A = PA->getPattern();
5542-
if (!S.Context.hasSameType(
5543-
S.Context.getUnqualifiedArrayType(InstP.getNonReferenceType()),
5544-
S.Context.getUnqualifiedArrayType(A.getNonReferenceType())))
5544+
auto T1 = S.Context.getUnqualifiedArrayType(InstP.getNonReferenceType());
5545+
auto T2 = S.Context.getUnqualifiedArrayType(A.getNonReferenceType());
5546+
if (auto *Injected = T1->getAs<InjectedClassNameType>())
5547+
T1 = Injected->getInjectedSpecializationType();
5548+
if (auto *Injected = T2->getAs<InjectedClassNameType>())
5549+
T2 = Injected->getInjectedSpecializationType();
5550+
if (!S.Context.hasSameType(T1, T2))
55455551
return TemplateDeductionResult::NonDeducedMismatch;
55465552
return TemplateDeductionResult::Success;
55475553
}

clang/test/SemaTemplate/deduction-guide.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,3 +966,19 @@ Expand<Type, Invocable<>> _{};
966966
// CHECK-NEXT: | `-ParmVarDecl {{.+}} 'T...' pack
967967

968968
}
969+
970+
namespace GH134613 {
971+
template <typename R> struct Foo {
972+
using value_type = R;
973+
974+
Foo() = default;
975+
Foo(Foo<Foo<R>> &&rhs) {}
976+
};
977+
978+
void main() {
979+
auto r1 = Foo(Foo<Foo<int>>{});
980+
981+
static_assert(__is_same(decltype(r1)::value_type, int));
982+
}
983+
984+
}

0 commit comments

Comments
 (0)