[clang] [Clang] support friend declarations with a dependent nested-name-specifier (PR #191268)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 16 09:27:58 PDT 2026


================
@@ -274,6 +275,99 @@ struct AccessTarget : public AccessedEntity {
 
 }
 
+static bool CanDeduceTemplateArguments(Sema &S, TemplateParameterList *TPL,
+                                       ArrayRef<TemplateArgument> PatternArgs,
+                                       ArrayRef<TemplateArgument> Args,
+                                       SourceLocation Loc) {
+  if (PatternArgs.size() != Args.size())
+    return false;
+
+  auto Equal =
+      llvm::equal(PatternArgs, Args,
+                  [](const TemplateArgument &LHS, const TemplateArgument &RHS) {
+                    return LHS.structurallyEquals(RHS);
+                  });
+  if (Equal)
+    return true;
+
+  TemplateDeductionInfo Info(Loc);
+  SmallVector<DeducedTemplateArgument, 4> Deduced(TPL->size());
+  S.DeduceTemplateArguments(TPL, PatternArgs, Args, Info, Deduced,
+                            /*NumberOfArgumentsMustMatch=*/false);
+
+  for (const DeducedTemplateArgument &Arg : Deduced)
+    if (Arg.isNull())
+      return false;
+
+  return true;
----------------
mizvekov wrote:

Also, this is a pretty non-standard use of the deduction facility, because you would normally not stop here, there is an extra step where you finish deduction by checking if substituting the deduced arguments into the deduced parameter produces an instantiation that is equivalent to the deduction argument.

Also, what about the results of this deduction, wouldn't we want to be providing diagnostics?

https://github.com/llvm/llvm-project/pull/191268


More information about the cfe-commits mailing list