Skip to content

Commit 93009fc

Browse files
author
git apple-llvm automerger
committed
Merge commit '2ec38abcba12' from llvm.org/release/21.x into stable/21.x
2 parents d84effc + 2ec38ab commit 93009fc

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5561,6 +5561,15 @@ static TemplateDeductionResult CheckDeductionConsistency(
55615561
// FIXME: A substitution can be incomplete on a non-structural part of the
55625562
// type. Use the canonical type for now, until the TemplateInstantiator can
55635563
// deal with that.
5564+
5565+
// Workaround: Implicit deduction guides use InjectedClassNameTypes, whereas
5566+
// the explicit guides don't. The substitution doesn't transform these types,
5567+
// so let it transform their specializations instead.
5568+
bool IsDeductionGuide = isa<CXXDeductionGuideDecl>(FTD->getTemplatedDecl());
5569+
if (IsDeductionGuide) {
5570+
if (auto *Injected = P->getAs<InjectedClassNameType>())
5571+
P = Injected->getInjectedSpecializationType();
5572+
}
55645573
QualType InstP = S.SubstType(P.getCanonicalType(), MLTAL, FTD->getLocation(),
55655574
FTD->getDeclName(), &IsIncompleteSubstitution);
55665575
if (InstP.isNull() && !IsIncompleteSubstitution)
@@ -5575,9 +5584,15 @@ static TemplateDeductionResult CheckDeductionConsistency(
55755584
if (auto *PA = dyn_cast<PackExpansionType>(A);
55765585
PA && !isa<PackExpansionType>(InstP))
55775586
A = PA->getPattern();
5578-
if (!S.Context.hasSameType(
5579-
S.Context.getUnqualifiedArrayType(InstP.getNonReferenceType()),
5580-
S.Context.getUnqualifiedArrayType(A.getNonReferenceType())))
5587+
auto T1 = S.Context.getUnqualifiedArrayType(InstP.getNonReferenceType());
5588+
auto T2 = S.Context.getUnqualifiedArrayType(A.getNonReferenceType());
5589+
if (IsDeductionGuide) {
5590+
if (auto *Injected = T1->getAs<InjectedClassNameType>())
5591+
T1 = Injected->getInjectedSpecializationType();
5592+
if (auto *Injected = T2->getAs<InjectedClassNameType>())
5593+
T2 = Injected->getInjectedSpecializationType();
5594+
}
5595+
if (!S.Context.hasSameType(T1, T2))
55815596
return TemplateDeductionResult::NonDeducedMismatch;
55825597
return TemplateDeductionResult::Success;
55835598
}

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)