Skip to content

[Clang][Sema] Fix last argument not being used when comparing function template specializations when one has an explicit object argument #92263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,8 @@ Bug Fixes to C++ Support
templates during partial ordering when deducing template arguments from a function declaration or when
taking the address of a function template.
- Fix a bug with checking constrained non-type template parameters for equivalence. Fixes (#GH77377).
- Fix a bug where the last argument was not considered when considering the most viable function for
explicit object argument member functions. Fixes (#GH92188).

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
9 changes: 7 additions & 2 deletions clang/lib/Sema/SemaTemplateDeduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5638,7 +5638,8 @@ static bool isAtLeastAsSpecializedAs(Sema &S, SourceLocation Loc,
/// function templates.
///
/// \param NumCallArguments1 The number of arguments in the call to FT1, used
/// only when \c TPOC is \c TPOC_Call.
/// only when \c TPOC is \c TPOC_Call. Does not include the object argument when
/// calling a member function.
///
/// \param RawObj1Ty The type of the object parameter of FT1 if a member
/// function only used if \c TPOC is \c TPOC_Call and FT1 is a Function
Expand Down Expand Up @@ -5707,7 +5708,11 @@ FunctionTemplateDecl *Sema::getMoreSpecializedTemplate(
IsRValRef1);
Args2.push_back(Obj2Ty);
}
size_t NumComparedArguments = NumCallArguments1 + ShouldConvert1;
size_t NumComparedArguments = NumCallArguments1;
// Either added an argument above or the prototype includes an explicit
// object argument we need to count
if (Method1)
++NumComparedArguments;

Args1.insert(Args1.end(), Proto1->param_type_begin(),
Proto1->param_type_end());
Expand Down
57 changes: 57 additions & 0 deletions clang/test/SemaCXX/cxx2b-deducing-this.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,3 +836,60 @@ int h() {
}();
}
}

namespace GH92188 {
struct A {
template<auto N>
void operator+=(this auto &&, const char (&)[N]);
void operator+=(this auto &&, auto &&) = delete;

void f1(this A &, auto &);
void f1(this A &, auto &&) = delete;

void f2(this auto&);
void f2(this auto&&) = delete;

void f3(auto&) &;
void f3(this A&, auto&&) = delete;

void f4(auto&&) & = delete;
void f4(this A&, auto&);

static void f5(auto&);
void f5(this A&, auto&&) = delete;

static void f6(auto&&) = delete;
void f6(this A&, auto&);

void implicit_this() {
int lval;
operator+=("123");
f1(lval);
f2();
f3(lval);
f4(lval);
f5(lval);
f6(lval);
}

void operator-(this A&, auto&&) = delete;
friend void operator-(A&, auto&);

void operator*(this A&, auto&);
friend void operator*(A&, auto&&) = delete;
};

void g() {
A a;
int lval;
a += "123";
a.f1(lval);
a.f2();
a.f3(lval);
a.f4(lval);
a.f5(lval);
a.f6(lval);
a - lval;
a * lval;
}
}
Loading