[clang] [clang] Bugfix for choosing the more specialized overload (PR #83279)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 28 07:54:55 PST 2024


Botond =?utf-8?q?István_Horváth?Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/83279 at github.com>


================
@@ -5548,13 +5514,113 @@ static bool isAtLeastAsSpecializedAs(Sema &S,
 FunctionTemplateDecl *Sema::getMoreSpecializedTemplate(
     FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc,
     TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1,
-    unsigned NumCallArguments2, bool Reversed) {
+    unsigned NumCallArguments2, QualType RawObjType1, QualType RawObjType2,
+    bool Reversed) {
+  SmallVector<QualType, 4> Args1;
+  SmallVector<QualType, 4> Args2;
+  const FunctionDecl *FD1 = FT1->getTemplatedDecl();
+  const FunctionDecl *FD2 = FT2->getTemplatedDecl();
+  bool shouldConvert1 = false;
+  bool shouldConvert2 = false;
+  QualType ObjType1;
+  QualType ObjType2;
+  if (TPOC == TPOC_Call) {
+    const FunctionProtoType *Proto1 =
+        FD1->getType()->getAs<FunctionProtoType>();
+    const FunctionProtoType *Proto2 =
+        FD2->getType()->getAs<FunctionProtoType>();
 
-  bool Better1 = isAtLeastAsSpecializedAs(*this, Loc, FT1, FT2, TPOC,
-                                          NumCallArguments1, Reversed);
-  bool Better2 = isAtLeastAsSpecializedAs(*this, Loc, FT2, FT1, TPOC,
-                                          NumCallArguments2, Reversed);
+    //   - In the context of a function call, the function parameter types are
+    //     used.
+    const CXXMethodDecl *Method1 = dyn_cast<CXXMethodDecl>(FD1);
+    const CXXMethodDecl *Method2 = dyn_cast<CXXMethodDecl>(FD2);
+
+    if (getLangOpts().CPlusPlus20) {
+      // C++20 [temp.func.order]p3
+      //   [...] Each function template M that is a member function is
+      //   considered to have a new first parameter of type
+      //   X(M), described below, inserted in its function parameter list.
+      //
+      // Note that we interpret "that is a member function" as
+      // "that is a member function with no expicit object argument".
+      // Otherwise the ordering rules for methods with expicit objet arguments
+      // against anything else make no sense.
+      shouldConvert1 = Method1 && !Method1->isExplicitObjectMemberFunction();
+      shouldConvert2 = Method2 && !Method2->isExplicitObjectMemberFunction();
+      if (shouldConvert1) {
+        bool isR2 =
+            Method2 && !Method2->isExplicitObjectMemberFunction()
----------------
erichkeane wrote:

This whole line is `shouldConvert2`.

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


More information about the cfe-commits mailing list