[clang] [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (PR #102131)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 25 22:45:03 PDT 2024
================
@@ -972,8 +972,30 @@ static const Expr *SubstituteConstraintExpressionWithoutSatisfaction(
// equivalence.
LocalInstantiationScope ScopeForParameters(S);
if (auto *FD = DeclInfo.getDecl()->getAsFunction())
- for (auto *PVD : FD->parameters())
- ScopeForParameters.InstantiatedLocal(PVD, PVD);
+ for (auto *PVD : FD->parameters()) {
+ if (!PVD->isParameterPack()) {
+ ScopeForParameters.InstantiatedLocal(PVD, PVD);
+ continue;
+ }
+ // This is hacky: we're mapping the parameter pack to a size-of-1 argument
+ // to avoid building SubstTemplateTypeParmPackTypes for
+ // PackExpansionTypes. The SubstTemplateTypeParmPackType node would
+ // otherwise reference the AssociatedDecl of the template arguments, which
+ // is, in this case, the template declaration.
+ //
+ // However, as we're also calculating the redeclarations of the template,
+ // the canonical declarations thereof are actually themselves at the
+ // moment. So if we didn't expand these packs, we would end up with an
+ // incorrect profile difference because we will be profiling the
+ // canonical types!
+ //
+ // FIXME: Improve the "no-transform" machinery in FindInstantiatedDecl so
+ // that we can eliminate the Scope in the cases where the declarations are
+ // not necessarily instantiated. It would also benefit the noexcept
+ // specifier comparison.
----------------
zyn0217 wrote:
> I wonder if we could temporarily pretend that the declarations are equivalent while checking their constraint so that their canonical type matches.
I tried that approach in https://github.com/llvm/llvm-project/commit/0727e47124af564826a22a718a64a1da79e6131d. While it works, I don't think I like it quite much because it looks unnatural/dirty to me.
https://github.com/llvm/llvm-project/pull/102131
More information about the cfe-commits
mailing list