-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[Clang] Distinguish expanding-packs-in-place cases for SubstTemplateTypeParmTypes #114220
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 1 commit
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 |
|---|---|---|
|
|
@@ -1648,14 +1648,16 @@ namespace { | |
| QualType | ||
| TransformSubstTemplateTypeParmType(TypeLocBuilder &TLB, | ||
| SubstTemplateTypeParmTypeLoc TL) { | ||
| if (SemaRef.CodeSynthesisContexts.back().Kind != | ||
| Sema::CodeSynthesisContext::ConstraintSubstitution) | ||
| const SubstTemplateTypeParmType *Type = TL.getTypePtr(); | ||
| if (!Type->expandPacksInPlace()) | ||
| return inherited::TransformSubstTemplateTypeParmType(TLB, TL); | ||
|
|
||
| auto PackIndex = TL.getTypePtr()->getPackIndex(); | ||
| std::optional<Sema::ArgumentPackSubstitutionIndexRAII> SubstIndex; | ||
| if (SemaRef.ArgumentPackSubstitutionIndex == -1 && PackIndex) | ||
| SubstIndex.emplace(SemaRef, *PackIndex); | ||
| assert(Type->getPackIndex()); | ||
| TemplateArgument TA = TemplateArgs( | ||
| Type->getReplacedParameter()->getDepth(), Type->getIndex()); | ||
| assert(*Type->getPackIndex() + 1 <= TA.pack_size()); | ||
| Sema::ArgumentPackSubstitutionIndexRAII SubstIndex( | ||
| SemaRef, TA.pack_size() - 1 - *Type->getPackIndex()); | ||
|
|
||
| return inherited::TransformSubstTemplateTypeParmType(TLB, TL); | ||
| } | ||
|
|
@@ -3133,7 +3135,11 @@ struct ExpandPackedTypeConstraints | |
|
|
||
| using inherited = TreeTransform<ExpandPackedTypeConstraints>; | ||
|
|
||
| ExpandPackedTypeConstraints(Sema &SemaRef) : inherited(SemaRef) {} | ||
| const MultiLevelTemplateArgumentList &TemplateArgs; | ||
|
|
||
| ExpandPackedTypeConstraints( | ||
| Sema &SemaRef, const MultiLevelTemplateArgumentList &TemplateArgs) | ||
| : inherited(SemaRef), TemplateArgs(TemplateArgs) {} | ||
|
|
||
| using inherited::TransformTemplateTypeParmType; | ||
|
|
||
|
|
@@ -3149,9 +3155,15 @@ struct ExpandPackedTypeConstraints | |
|
|
||
| assert(SemaRef.ArgumentPackSubstitutionIndex != -1); | ||
|
|
||
| TemplateArgument Arg = TemplateArgs(T->getDepth(), T->getIndex()); | ||
|
|
||
| std::optional<unsigned> PackIndex; | ||
| if (Arg.getKind() == TemplateArgument::Pack) | ||
| PackIndex = Arg.pack_size() - 1 - SemaRef.ArgumentPackSubstitutionIndex; | ||
|
Collaborator
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.
Contributor
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. These index transformations also come up in other places, where some other index is used, instead of the current Sema pack subst index. That would be worth refactoring, also consolidating asserts.
Collaborator
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. Agreed, it seems like a valuable refactor to me. When I see hand math like that it always raises my spidey senses and I look to see where else we are doing something like that. |
||
|
|
||
| QualType Result = SemaRef.Context.getSubstTemplateTypeParmType( | ||
| TL.getType(), T->getDecl(), T->getIndex(), | ||
| SemaRef.ArgumentPackSubstitutionIndex); | ||
| TL.getType(), T->getDecl(), T->getIndex(), PackIndex, | ||
| /*ExpandPacksInPlace=*/true); | ||
| SubstTemplateTypeParmTypeLoc NewTL = | ||
| TLB.push<SubstTemplateTypeParmTypeLoc>(Result); | ||
| NewTL.setNameLoc(TL.getNameLoc()); | ||
|
|
@@ -3210,8 +3222,8 @@ bool Sema::SubstTypeConstraint( | |
| TemplateArgumentListInfo InstArgs; | ||
| InstArgs.setLAngleLoc(TemplArgInfo->LAngleLoc); | ||
| InstArgs.setRAngleLoc(TemplArgInfo->RAngleLoc); | ||
| if (ExpandPackedTypeConstraints(*this).SubstTemplateArguments( | ||
| TemplArgInfo->arguments(), InstArgs)) | ||
| if (ExpandPackedTypeConstraints(*this, TemplateArgs) | ||
| .SubstTemplateArguments(TemplArgInfo->arguments(), InstArgs)) | ||
| return true; | ||
|
|
||
| // The type of the original parameter. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.