Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ Bug Fixes in This Version
first parameter. (#GH113323).
- Fixed a crash with incompatible pointer to integer conversions in designated
initializers involving string literals. (#GH154046)
- Fix crash on CTAD for alias template. (#GH131342)
- Fix crash on CTAD for alias template. (#GH131342), (#GH131408)
- Clang now emits a frontend error when a function marked with the `flatten` attribute
calls another function that requires target features not enabled in the caller. This
prevents a fatal error in the backend.
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/Sema/SemaInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8219,8 +8219,8 @@ ExprResult InitializationSequence::Perform(Sema &S,
// InitializeTemporary entity for our target type.
QualType Ty = Step->Type;
bool IsTemporary = !S.Context.hasSameType(Entity.getType(), Ty);
InitializedEntity TempEntity = InitializedEntity::InitializeTemporary(Ty);
InitializedEntity InitEntity = IsTemporary ? TempEntity : Entity;
InitializedEntity InitEntity =
IsTemporary ? InitializedEntity::InitializeTemporary(Ty) : Entity;
InitListChecker PerformInitList(S, InitEntity,
InitList, Ty, /*VerifyOnly=*/false,
/*TreatUnavailableAsInvalid=*/false);
Expand All @@ -8242,7 +8242,6 @@ ExprResult InitializationSequence::Perform(Sema &S,

InitListExpr *StructuredInitList =
PerformInitList.getFullyStructuredList();
CurInit.get();
CurInit = shouldBindAsTemporary(InitEntity)
? S.MaybeBindToTemporary(StructuredInitList)
: StructuredInitList;
Expand Down
42 changes: 38 additions & 4 deletions clang/lib/Sema/SemaTemplateDeductionGuide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1171,17 +1171,38 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
Args.addOuterTemplateArguments(TransformedDeducedAliasArgs);
for (unsigned Index = 0; Index < DeduceResults.size(); ++Index) {
const auto &D = DeduceResults[Index];
auto *TP = F->getTemplateParameters()->getParam(Index);
if (IsNonDeducedArgument(D)) {
// 2): Non-deduced template parameters would be substituted later.
continue;
}
TemplateArgumentLoc Input =
SemaRef.getTrivialTemplateArgumentLoc(D, QualType(), SourceLocation{});
TemplateArgumentLoc Output;
if (!SemaRef.SubstTemplateArgument(Input, Args, Output)) {
TemplateArgumentListInfo Output;
if (!SemaRef.SubstTemplateArguments(Input, Args, Output)) {
assert(TemplateArgsForBuildingFPrime[Index].isNull() &&
"InstantiatedArgs must be null before setting");
TemplateArgsForBuildingFPrime[Index] = Output.getArgument();
Sema::CheckTemplateArgumentInfo CTAI;
if (Input.getArgument().getKind() == TemplateArgument::Pack) {
for (auto TA : Output.arguments()) {
if (SemaRef.CheckTemplateArgument(
TP, TA, F, F->getLocation(), F->getLocation(),
/*ArgumentPackIndex=*/-1, CTAI,
Sema::CheckTemplateArgumentKind::CTAK_Specified))
return nullptr;
}
TemplateArgsForBuildingFPrime[Index] =
TemplateArgument::CreatePackCopy(Context, CTAI.SugaredConverted);
} else {
assert(Output.arguments().size() == 1);
TemplateArgumentLoc Transformed = Output.arguments()[0];
if (SemaRef.CheckTemplateArgument(
TP, Transformed, F, F->getLocation(), F->getLocation(),
/*ArgumentPackIndex=*/-1, CTAI,
Sema::CheckTemplateArgumentKind::CTAK_Specified))
return nullptr;
TemplateArgsForBuildingFPrime[Index] = CTAI.SugaredConverted[0];
}
}
}

Expand All @@ -1202,8 +1223,21 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,

assert(TemplateArgsForBuildingFPrime[FTemplateParamIdx].isNull() &&
"The argument must be null before setting");
TemplateArgument Transformed = Context.getInjectedTemplateArg(NewParam);
if (NewParam->isTemplateParameterPack())
Transformed = *Transformed.pack_begin();
TemplateArgumentLoc TALoc = SemaRef.getTrivialTemplateArgumentLoc(
Transformed, QualType(), NewParam->getBeginLoc());
Sema::CheckTemplateArgumentInfo CTAI;
if (SemaRef.CheckTemplateArgument(
TP, TALoc, F, F->getLocation(), F->getLocation(),
/*ArgumentPackIndex=*/-1, CTAI,
Sema::CheckTemplateArgumentKind::CTAK_Specified))
return nullptr;
TemplateArgsForBuildingFPrime[FTemplateParamIdx] =
Context.getInjectedTemplateArg(NewParam);
NewParam->isTemplateParameterPack()
? TemplateArgument::CreatePackCopy(Context, CTAI.SugaredConverted)
: CTAI.SugaredConverted[0];
}

auto *TemplateArgListForBuildingFPrime =
Expand Down
18 changes: 18 additions & 0 deletions clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,3 +586,21 @@ Baz a{};
static_assert(__is_same(decltype(a), A<A<int>>));

} // namespace GH133132

namespace GH131408 {

struct Node {};

template <class T, Node>
struct A {
A(T) {}
};

template <class T>
using AA = A<T, {}>;

AA a{0};

static_assert(__is_same(decltype(a), A<int, Node{}>));

}
Loading