[clang] [Clang] Remove the wrong assumption when rebuilding SizeOfPackExprs for constraint normalization (PR #115120)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 6 22:47:20 PST 2024
================
@@ -1881,6 +1871,15 @@ Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) {
TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition());
if (TTP->isParameterPack()) {
+ // We might not have an index for pack expansion when normalizing
+ // constraint expressions. In that case, resort to instantiation scopes
+ // for the transformed declarations.
+ if (SemaRef.ArgumentPackSubstitutionIndex == -1 &&
+ SemaRef.CodeSynthesisContexts.back().Kind ==
+ Sema::CodeSynthesisContext::ConstraintNormalization) {
+ return SemaRef.FindInstantiatedDecl(Loc, cast<NamedDecl>(D),
+ TemplateArgs);
----------------
zyn0217 wrote:
An example would be like
```cpp
template <typename T> struct C {
template <template <typename> class... TTp> requires(sizeof...(TTp) > 0) // #1
friend class TTP;
};
template <template <typename> class... TTp>
requires(sizeof...(TTp) > 0) // #2
class TTP;
C c;
```
When comparing `#1` and `#2`, we would directly substitute into them with a pack argument `TTp`.
At least for now, I don't see a chance for us to specify an index to substitute with. Probably, if we want an index in the future, we could turn the constraint expression into some form of template argument whose transformation would set up an index as it goes.
https://github.com/llvm/llvm-project/pull/115120
More information about the cfe-commits
mailing list