-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Clang] Fix various bugs in alias CTAD transform #132061
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1348,6 +1348,16 @@ std::optional<TemplateDeductionInfo *> Sema::isSFINAEContext() const { | |
return std::nullopt; | ||
} | ||
|
||
static TemplateArgument | ||
getPackSubstitutedTemplateArgument(Sema &S, TemplateArgument Arg) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is pre-existing - do I have to rename that? |
||
assert(S.ArgumentPackSubstitutionIndex >= 0); | ||
assert(S.ArgumentPackSubstitutionIndex < (int)Arg.pack_size()); | ||
Arg = Arg.pack_begin()[S.ArgumentPackSubstitutionIndex]; | ||
if (Arg.isPackExpansion()) | ||
Arg = Arg.getPackExpansionPattern(); | ||
return Arg; | ||
} | ||
|
||
//===----------------------------------------------------------------------===/ | ||
// Template Instantiation for Types | ||
//===----------------------------------------------------------------------===/ | ||
|
@@ -1467,11 +1477,13 @@ namespace { | |
} | ||
} | ||
|
||
static TemplateArgument | ||
TemplateArgument | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. static is gone There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is intended because we need to access |
||
getTemplateArgumentPackPatternForRewrite(const TemplateArgument &TA) { | ||
if (TA.getKind() != TemplateArgument::Pack) | ||
return TA; | ||
assert(TA.pack_size() == 1 && | ||
if (SemaRef.ArgumentPackSubstitutionIndex != -1) | ||
return getPackSubstitutedTemplateArgument(SemaRef, TA); | ||
assert(TA.pack_size() == 1 && TA.pack_begin()->isPackExpansion() && | ||
"unexpected pack arguments in template rewrite"); | ||
TemplateArgument Arg = *TA.pack_begin(); | ||
if (Arg.isPackExpansion()) | ||
|
@@ -1630,6 +1642,9 @@ namespace { | |
std::vector<TemplateArgument> TArgs; | ||
switch (Arg.getKind()) { | ||
case TemplateArgument::Pack: | ||
assert(SemaRef.CodeSynthesisContexts.empty() || | ||
SemaRef.CodeSynthesisContexts.back().Kind == | ||
Sema::CodeSynthesisContext::BuildingDeductionGuides); | ||
// Literally rewrite the template argument pack, instead of unpacking | ||
// it. | ||
for (auto &pack : Arg.getPackAsArray()) { | ||
|
@@ -1650,6 +1665,23 @@ namespace { | |
return inherited::TransformTemplateArgument(Input, Output, Uneval); | ||
} | ||
|
||
std::optional<unsigned> ComputeSizeOfPackExprWithoutSubstitution( | ||
ArrayRef<TemplateArgument> PackArgs) { | ||
// Don't do this when rewriting template parameters for CTAD: | ||
// 1) The heuristic needs the unpacked Subst* nodes to figure out the | ||
// expanded size, but this never applies since Subst* nodes are not | ||
// created in rewrite scenarios. | ||
// | ||
// 2) The heuristic substitutes into the pattern with pack expansion | ||
// suppressed, which does not meet the requirements for argument | ||
// rewriting when template arguments include a non-pack matching against | ||
// a pack, particularly when rewriting an alias CTAD. | ||
if (TemplateArgs.isRewrite()) | ||
return std::nullopt; | ||
mizvekov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return inherited::ComputeSizeOfPackExprWithoutSubstitution(PackArgs); | ||
} | ||
|
||
template<typename Fn> | ||
QualType TransformFunctionProtoType(TypeLocBuilder &TLB, | ||
FunctionProtoTypeLoc TL, | ||
|
@@ -1869,16 +1901,6 @@ bool TemplateInstantiator::AlreadyTransformed(QualType T) { | |
return true; | ||
} | ||
|
||
static TemplateArgument | ||
getPackSubstitutedTemplateArgument(Sema &S, TemplateArgument Arg) { | ||
assert(S.ArgumentPackSubstitutionIndex >= 0); | ||
assert(S.ArgumentPackSubstitutionIndex < (int)Arg.pack_size()); | ||
Arg = Arg.pack_begin()[S.ArgumentPackSubstitutionIndex]; | ||
if (Arg.isPackExpansion()) | ||
Arg = Arg.getPackExpansionPattern(); | ||
return Arg; | ||
} | ||
|
||
Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) { | ||
if (!D) | ||
return nullptr; | ||
|
Uh oh!
There was an error while loading. Please reload this page.