[clang] [Clang] support friend declarations with a dependent nested-name-specifier (PR #191268)
Matheus Izvekov via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 29 09:30:23 PDT 2026
================
@@ -274,6 +276,110 @@ struct AccessTarget : public AccessedEntity {
}
+static bool CanDeduceTemplateArguments(Sema &S, TemplateParameterList *TPL,
+ TemplateDecl *TD,
+ ArrayRef<TemplateArgument> PatternArgs,
+ ArrayRef<TemplateArgument> Args,
+ SourceLocation Loc) {
+ auto Equal =
+ llvm::equal(PatternArgs, Args,
+ [](const TemplateArgument &LHS, const TemplateArgument &RHS) {
+ return LHS.structurallyEquals(RHS);
+ });
+ if (Equal)
+ return true;
+
+ EnterExpressionEvaluationContext Unevaluated(
+ S, Sema::ExpressionEvaluationContext::Unevaluated);
+ TemplateDeductionInfo Info(Loc);
+ Sema::SFINAETrap Trap(S, Info);
+ LocalInstantiationScope InstantiationScope(S);
+ SmallVector<DeducedTemplateArgument, 4> Deduced(TPL->size());
+ if (S.DeduceTemplateArguments(TPL, PatternArgs, Args, Info, Deduced,
+ /*NumberOfArgumentsMustMatch=*/false) !=
+ TemplateDeductionResult::Success)
+ return false;
+
+ SmallVector<TemplateArgument, 4> DeducedArgs(Deduced.begin(), Deduced.end());
+ Sema::InstantiatingTemplate Inst(S, Info.getLocation(), TD, DeducedArgs);
+ if (Inst.isInvalid())
+ return false;
+
+ if (S.FinishTemplateArgumentDeduction(
+ TD, TPL, PatternArgs, Args, Deduced, Info,
+ /*CopyDeducedArgs=*/false) != TemplateDeductionResult::Success)
+ return false;
+
+ return !Trap.hasErrorOccurred();
----------------
mizvekov wrote:
Well, what if all of this fails, what do we do with the information produced from these failures?
Shouldn't the user know somehow?
For example, why does this function even take in a SourceLocation, if it never produces anything with it?
https://github.com/llvm/llvm-project/pull/191268
More information about the cfe-commits
mailing list