[clang] [Clang] Ensure default arguments in friend declarations are only allowed in defining declarations to prevent multiple reachable declarations (PR #113777)
Oleksandr T. via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 6 06:18:55 PST 2024
================
@@ -3430,15 +3430,17 @@ bool Sema::SubstDefaultArgument(
ContextRAII SavedContext(*this, FD);
std::unique_ptr<LocalInstantiationScope> LIS;
- if (ForCallExpr) {
+ FunctionDecl *PatternFD =
+ ForCallExpr
+ ? FD->getTemplateInstantiationPattern(/*ForDefinition*/ false)
+ : nullptr;
+ if (PatternFD) {
// When instantiating a default argument due to use in a call expression,
// an instantiation scope that includes the parameters of the callee is
// required to satisfy references from the default argument. For example:
// 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);
----------------
a-tarasyuk wrote:
@zyn0217 @mizvekov I've moved the condition to `InstantiateDefaultArgument` and added an additional test. Do the recent updates look acceptable?
https://github.com/llvm/llvm-project/pull/113777
More information about the cfe-commits
mailing list