[clang] [Clang][Sema] Fix exception specification comparison for functions with different template depths (PR #111561)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 8 17:10:22 PDT 2024
================
@@ -501,6 +519,89 @@ bool Sema::CheckEquivalentExceptionSpec(
return Result;
}
+static const Expr *SubstituteExceptionSpecWithoutEvaluation(
+ Sema &S, const Sema::TemplateCompareNewDeclInfo &DeclInfo,
+ const Expr *ExceptionSpec) {
+ MultiLevelTemplateArgumentList MLTAL = S.getTemplateInstantiationArgs(
+ DeclInfo.getDecl(), DeclInfo.getLexicalDeclContext(),
+ /*Final=*/false, /*Innermost=*/std::nullopt,
+ /*RelativeToPrimary=*/true, /*ForConstraintInstantiation=*/true);
+
+ if (!MLTAL.getNumSubstitutedLevels())
+ return ExceptionSpec;
+
+ Sema::SFINAETrap SFINAE(S, /*AccessCheckingSFINAE=*/false);
+
+ Sema::InstantiatingTemplate Inst(
+ S, DeclInfo.getLocation(),
+ const_cast<FunctionDecl *>(DeclInfo.getDecl()->getAsFunction()),
+ Sema::InstantiatingTemplate::ExceptionSpecification());
+ if (Inst.isInvalid())
+ return nullptr;
+
+ // Set up a dummy 'instantiation' scope in the case of reference to function
+ // parameters that the surrounding function hasn't been instantiated yet. Note
+ // this may happen while we're comparing two templates' constraint
+ // equivalence.
+ LocalInstantiationScope ScopeForParameters(S);
+ if (auto *FD = DeclInfo.getDecl()->getAsFunction())
+ for (auto *PVD : FD->parameters())
+ ScopeForParameters.InstantiatedLocal(PVD, PVD);
----------------
zyn0217 wrote:
This seems different from the latest version of AreConstraintExpressionEquivalent(), which expands parameter packs to a size-of-1 pack argument. Can you explain why there is a difference?
https://github.com/llvm/llvm-project/pull/111561
More information about the cfe-commits
mailing list