[clang] [Clang] prevent assertion failure from an invalid template instantiation pattern when adding instantiated params to the scope in friend functions with defaulted params (PR #113777)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 31 20:16:47 PDT 2024
================
@@ -3437,10 +3437,10 @@ bool Sema::SubstDefaultArgument(
// template<typename T> void f(T a, int = decltype(a)());
// void g() { f(0); }
LIS = std::make_unique<LocalInstantiationScope>(*this);
- FunctionDecl *PatternFD = FD->getTemplateInstantiationPattern(
- /*ForDefinition*/ false);
- if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
- return true;
+ if (FunctionDecl *PatternFD =
+ FD->getTemplateInstantiationPattern(/*ForDefinition*/ false))
+ if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
+ return true;
----------------
zyn0217 wrote:
OTOH I'm wondering if we could avoid substituting into default arguments if we already know the friend declaration is not a definition. The function declaration instantiation seems to intentionally avoid adding connections to the primary template if the friend declaration is not a definition, which is why `getTemplateInstantiationPattern()` returns nullptr here.
https://github.com/llvm/llvm-project/pull/113777
More information about the cfe-commits
mailing list