Skip to content

Commit 2515d25

Browse files
author
git apple-llvm automerger
committed
Merge commit '19c571a631d9' from llvm.org/release/19.x into stable/20240723
2 parents d910d4b + 19c571a commit 2515d25

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

clang/lib/Sema/SemaTemplateDeductionGuide.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ class ExtractTypeForDeductionGuide
6969
ExtractTypeForDeductionGuide(
7070
Sema &SemaRef,
7171
llvm::SmallVectorImpl<TypedefNameDecl *> &MaterializedTypedefs,
72-
ClassTemplateDecl *NestedPattern,
73-
const MultiLevelTemplateArgumentList *OuterInstantiationArgs)
72+
ClassTemplateDecl *NestedPattern = nullptr,
73+
const MultiLevelTemplateArgumentList *OuterInstantiationArgs = nullptr)
7474
: Base(SemaRef), MaterializedTypedefs(MaterializedTypedefs),
7575
NestedPattern(NestedPattern),
7676
OuterInstantiationArgs(OuterInstantiationArgs) {
@@ -1263,10 +1263,25 @@ FunctionTemplateDecl *DeclareAggregateDeductionGuideForTypeAlias(
12631263
getRHSTemplateDeclAndArgs(SemaRef, AliasTemplate).first;
12641264
if (!RHSTemplate)
12651265
return nullptr;
1266+
1267+
llvm::SmallVector<TypedefNameDecl *> TypedefDecls;
1268+
llvm::SmallVector<QualType> NewParamTypes;
1269+
ExtractTypeForDeductionGuide TypeAliasTransformer(SemaRef, TypedefDecls);
1270+
for (QualType P : ParamTypes) {
1271+
QualType Type = TypeAliasTransformer.TransformType(P);
1272+
if (Type.isNull())
1273+
return nullptr;
1274+
NewParamTypes.push_back(Type);
1275+
}
1276+
12661277
auto *RHSDeductionGuide = SemaRef.DeclareAggregateDeductionGuideFromInitList(
1267-
RHSTemplate, ParamTypes, Loc);
1278+
RHSTemplate, NewParamTypes, Loc);
12681279
if (!RHSDeductionGuide)
12691280
return nullptr;
1281+
1282+
for (TypedefNameDecl *TD : TypedefDecls)
1283+
TD->setDeclContext(RHSDeductionGuide->getTemplatedDecl());
1284+
12701285
return BuildDeductionGuideForTypeAlias(SemaRef, AliasTemplate,
12711286
RHSDeductionGuide, Loc);
12721287
}

clang/test/SemaCXX/cxx20-ctad-type-alias.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,3 +481,16 @@ struct Out {
481481
Out<float>::B out(100); // deduced to Out<float>::A<float>;
482482
static_assert(__is_same(decltype(out), Out<float>::A<float>));
483483
}
484+
485+
namespace GH111508 {
486+
487+
template <typename V> struct S {
488+
using T = V;
489+
T Data;
490+
};
491+
492+
template <typename V> using Alias = S<V>;
493+
494+
Alias A(42);
495+
496+
} // namespace GH111508

0 commit comments

Comments
 (0)