Skip to content

Commit 621d0f3

Browse files
authored
[Clang][Sema] Fix last argument not being used when comparing function template specializations when one has an explicit object argument (#92263)
Fixes #92188
1 parent 9e39a0c commit 621d0f3

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,8 @@ Bug Fixes to C++ Support
737737
templates during partial ordering when deducing template arguments from a function declaration or when
738738
taking the address of a function template.
739739
- Fix a bug with checking constrained non-type template parameters for equivalence. Fixes (#GH77377).
740+
- Fix a bug where the last argument was not considered when considering the most viable function for
741+
explicit object argument member functions. Fixes (#GH92188).
740742

741743
Bug Fixes to AST Handling
742744
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5638,7 +5638,8 @@ static bool isAtLeastAsSpecializedAs(Sema &S, SourceLocation Loc,
56385638
/// function templates.
56395639
///
56405640
/// \param NumCallArguments1 The number of arguments in the call to FT1, used
5641-
/// only when \c TPOC is \c TPOC_Call.
5641+
/// only when \c TPOC is \c TPOC_Call. Does not include the object argument when
5642+
/// calling a member function.
56425643
///
56435644
/// \param RawObj1Ty The type of the object parameter of FT1 if a member
56445645
/// function only used if \c TPOC is \c TPOC_Call and FT1 is a Function
@@ -5707,7 +5708,11 @@ FunctionTemplateDecl *Sema::getMoreSpecializedTemplate(
57075708
IsRValRef1);
57085709
Args2.push_back(Obj2Ty);
57095710
}
5710-
size_t NumComparedArguments = NumCallArguments1 + ShouldConvert1;
5711+
size_t NumComparedArguments = NumCallArguments1;
5712+
// Either added an argument above or the prototype includes an explicit
5713+
// object argument we need to count
5714+
if (Method1)
5715+
++NumComparedArguments;
57115716

57125717
Args1.insert(Args1.end(), Proto1->param_type_begin(),
57135718
Proto1->param_type_end());

clang/test/SemaCXX/cxx2b-deducing-this.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,3 +836,60 @@ int h() {
836836
}();
837837
}
838838
}
839+
840+
namespace GH92188 {
841+
struct A {
842+
template<auto N>
843+
void operator+=(this auto &&, const char (&)[N]);
844+
void operator+=(this auto &&, auto &&) = delete;
845+
846+
void f1(this A &, auto &);
847+
void f1(this A &, auto &&) = delete;
848+
849+
void f2(this auto&);
850+
void f2(this auto&&) = delete;
851+
852+
void f3(auto&) &;
853+
void f3(this A&, auto&&) = delete;
854+
855+
void f4(auto&&) & = delete;
856+
void f4(this A&, auto&);
857+
858+
static void f5(auto&);
859+
void f5(this A&, auto&&) = delete;
860+
861+
static void f6(auto&&) = delete;
862+
void f6(this A&, auto&);
863+
864+
void implicit_this() {
865+
int lval;
866+
operator+=("123");
867+
f1(lval);
868+
f2();
869+
f3(lval);
870+
f4(lval);
871+
f5(lval);
872+
f6(lval);
873+
}
874+
875+
void operator-(this A&, auto&&) = delete;
876+
friend void operator-(A&, auto&);
877+
878+
void operator*(this A&, auto&);
879+
friend void operator*(A&, auto&&) = delete;
880+
};
881+
882+
void g() {
883+
A a;
884+
int lval;
885+
a += "123";
886+
a.f1(lval);
887+
a.f2();
888+
a.f3(lval);
889+
a.f4(lval);
890+
a.f5(lval);
891+
a.f6(lval);
892+
a - lval;
893+
a * lval;
894+
}
895+
}

0 commit comments

Comments
 (0)