[clang] [Clang][WIP][RFC] Bypass TAD during overload resolution if a perfect match exists (PR #133426)

Younan Zhang via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 28 04:52:04 PDT 2025


================
@@ -10905,6 +10983,93 @@ bool OverloadCandidate::NotValidBecauseConstraintExprHasError() const {
              ->Satisfaction.ContainsErrors;
 }
 
+void OverloadCandidateSet::AddNonDeducedTemplateCandidate(
+    FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl,
+    ArrayRef<Expr *> Args, bool SuppressUserConversions,
+    bool PartialOverloading, bool AllowExplicit,
+    CallExpr::ADLCallKind IsADLCandidate, OverloadCandidateParamOrder PO,
+    bool AggregateCandidateDeduction) {
+  NonDeducedFunctionTemplateOverloadCandidate C{FunctionTemplate,
+                                                FoundDecl,
+                                                Args,
+                                                IsADLCandidate,
+                                                PO,
+                                                SuppressUserConversions,
+                                                PartialOverloading,
+                                                AllowExplicit,
+                                                AggregateCandidateDeduction};
+  NonDeducedCandidates.emplace_back(std::move(C));
+}
+
+void OverloadCandidateSet::AddNonDeducedMethodTemplateCandidate(
+    FunctionTemplateDecl *MethodTmpl, DeclAccessPair FoundDecl,
+    CXXRecordDecl *ActingContext, QualType ObjectType,
+    Expr::Classification ObjectClassification, ArrayRef<Expr *> Args,
+    bool SuppressUserConversions, bool PartialOverloading,
+    OverloadCandidateParamOrder PO) {
+  NonDeducedMethodTemplateOverloadCandidate C{
+      MethodTmpl,           FoundDecl,  Args, ActingContext,
+      ObjectClassification, ObjectType, PO,   SuppressUserConversions,
+      PartialOverloading};
+  NonDeducedCandidates.emplace_back(std::move(C));
+}
+
+void OverloadCandidateSet::AddNonDeducedConversionTemplateCandidate(
+    FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl,
+    CXXRecordDecl *ActingContext, Expr *From, QualType ToType,
+    bool AllowObjCConversionOnExplicit, bool AllowExplicit,
+    bool AllowResultConversion) {
+
+  NonDeducedConversionTemplateOverloadCandidate C{
+      FunctionTemplate, FoundDecl,
+      ActingContext,    From,
+      ToType,           AllowObjCConversionOnExplicit,
+      AllowExplicit,    AllowResultConversion};
+
+  NonDeducedCandidates.emplace_back(std::move(C));
+}
+
+static void
+AddTemplateOverloadCandidate(Sema &S, OverloadCandidateSet &CandidateSet,
+                             NonDeducedMethodTemplateOverloadCandidate &&C) {
+
+  S.AddMethodTemplateCandidateImmediately(
+      CandidateSet, C.FunctionTemplate, C.FoundDecl, C.ActingContext,
+      /*ExplicitTemplateArgs=*/nullptr, C.ObjectType, C.ObjectClassification,
+      C.Args, C.SuppressUserConversions, C.PartialOverloading, C.PO);
+}
+
+static void
+AddTemplateOverloadCandidate(Sema &S, OverloadCandidateSet &CandidateSet,
+                             NonDeducedFunctionTemplateOverloadCandidate &&C) {
+  S.AddTemplateOverloadCandidateImmediately(
+      CandidateSet, C.FunctionTemplate, C.FoundDecl,
+      /*ExplicitTemplateArgs=*/nullptr, C.Args, C.SuppressUserConversions,
+      C.PartialOverloading, C.AllowExplicit, C.IsADLCandidate, C.PO,
+      C.AggregateCandidateDeduction);
+}
+
+static void AddTemplateOverloadCandidate(
+    Sema &S, OverloadCandidateSet &CandidateSet,
+    NonDeducedConversionTemplateOverloadCandidate &&C) {
+  return S.AddTemplateConversionCandidateImmediately(
----------------
zyn0217 wrote:

Can we reuse `InjectNonDeducedTemplateCandidates` for `*Immediately` functions or vice versa?

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


More information about the cfe-commits mailing list