[clang] [Clang][Sema] Fix last argument not being used when comparing function template specializations when one has an explicit object argument (PR #92263)
Sirraide wrote: > Oh I didn't see the conflict It may not have been there before; conflicts in the release notes happen all the time https://github.com/llvm/llvm-project/pull/92263 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Fix last argument not being used when comparing function template specializations when one has an explicit object argument (PR #92263)
MitalAshok wrote: @Sirraide Oh I didn't see the conflict, thanks. It should be fine now? https://github.com/llvm/llvm-project/pull/92263 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Fix last argument not being used when comparing function template specializations when one has an explicit object argument (PR #92263)
https://github.com/Sirraide closed https://github.com/llvm/llvm-project/pull/92263 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Fix last argument not being used when comparing function template specializations when one has an explicit object argument (PR #92263)
https://github.com/MitalAshok updated https://github.com/llvm/llvm-project/pull/92263 >From 6496dbfc8100812c8d3ea5a668af0593b532e4fe Mon Sep 17 00:00:00 2001 From: Mital Ashok Date: Wed, 15 May 2024 14:23:17 +0100 Subject: [PATCH 1/2] [Clang][Sema] Fix last argument not being used when comparing function template specializations when one has an explicit object argument Fixes #92188 --- clang/docs/ReleaseNotes.rst| 2 + clang/lib/Sema/SemaTemplateDeduction.cpp | 9 +++- clang/test/SemaCXX/cxx2b-deducing-this.cpp | 49 ++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ae699ebfc6038..9850fc9f8e0b4 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -713,6 +713,8 @@ Bug Fixes to C++ Support - Correctly treat the compound statement of an ``if consteval`` as an immediate context. Fixes (#GH91509). - When partial ordering alias templates against template template parameters, allow pack expansions when the alias has a fixed-size parameter list. Fixes (#GH62529). +- 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 ^ diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index 853c0e1b50619..094f767399e2a 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -5522,7 +5522,8 @@ static bool isAtLeastAsSpecializedAs(Sema , 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 @@ -5591,7 +5592,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()); diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp b/clang/test/SemaCXX/cxx2b-deducing-this.cpp index 5f29a955e053c..55792e1448ac5 100644 --- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp +++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp @@ -838,3 +838,52 @@ int h() { }(); } } + +namespace GH92188 { +struct A { + template + 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 g() { + A a; + int lval; + a += "123"; + a.f1(lval); + a.f2(); + a.f3(lval); + a.f4(lval); + a.f5(lval); + a.f6(lval); +} +} >From 64e31749874a231956b898e89f00d63790d9f083 Mon Sep 17 00:00:00 2001 From: Mital Ashok Date: Wed, 15 May 2024 15:05:55 +0100 Subject: [PATCH 2/2] Add test where one template isn't a method --- clang/test/SemaCXX/cxx2b-deducing-this.cpp | 8 1 file changed, 8 insertions(+) diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp b/clang/test/SemaCXX/cxx2b-deducing-this.cpp index 55792e1448ac5..58372aaff96ea 100644 --- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp +++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp @@ -873,6 +873,12 @@ struct A { 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() { @@ -885,5 +891,7 @@ void g() { a.f4(lval); a.f5(lval); a.f6(lval); + a - lval; + a * lval; } } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Fix last argument not being used when comparing function template specializations when one has an explicit object argument (PR #92263)
Sirraide wrote: @MitalAshok Just a reminder to resolve the merge conflicts in the release notes locally so we can get this merged. https://github.com/llvm/llvm-project/pull/92263 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Fix last argument not being used when comparing function template specializations when one has an explicit object argument (PR #92263)
https://github.com/mizvekov approved this pull request. LGTM, thanks for the fix! https://github.com/llvm/llvm-project/pull/92263 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Fix last argument not being used when comparing function template specializations when one has an explicit object argument (PR #92263)
@@ -5591,7 +5592,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; MitalAshok wrote: @mizvekov It would look something like this: b19a252f50e3b6d5dd50b0e51ec2865bb83fd5c9 But I think it's more error-prone because instead of `+1` in one place, it's sometimes a `+1` in all the places `ExplicitCallArguments` is set https://github.com/llvm/llvm-project/pull/92263 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Fix last argument not being used when comparing function template specializations when one has an explicit object argument (PR #92263)
@@ -5591,7 +5592,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; mizvekov wrote: It seems like changing the `ExplicitCallArguments` member of `OverloadCandidate` into just `CallArguments` might simplify this whole thing. https://github.com/llvm/llvm-project/pull/92263 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Fix last argument not being used when comparing function template specializations when one has an explicit object argument (PR #92263)
https://github.com/Sirraide approved this pull request. Fix seems reasonable to me. https://github.com/llvm/llvm-project/pull/92263 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Fix last argument not being used when comparing function template specializations when one has an explicit object argument (PR #92263)
https://github.com/MitalAshok updated https://github.com/llvm/llvm-project/pull/92263 >From 6496dbfc8100812c8d3ea5a668af0593b532e4fe Mon Sep 17 00:00:00 2001 From: Mital Ashok Date: Wed, 15 May 2024 14:23:17 +0100 Subject: [PATCH 1/2] [Clang][Sema] Fix last argument not being used when comparing function template specializations when one has an explicit object argument Fixes #92188 --- clang/docs/ReleaseNotes.rst| 2 + clang/lib/Sema/SemaTemplateDeduction.cpp | 9 +++- clang/test/SemaCXX/cxx2b-deducing-this.cpp | 49 ++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ae699ebfc6038..9850fc9f8e0b4 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -713,6 +713,8 @@ Bug Fixes to C++ Support - Correctly treat the compound statement of an ``if consteval`` as an immediate context. Fixes (#GH91509). - When partial ordering alias templates against template template parameters, allow pack expansions when the alias has a fixed-size parameter list. Fixes (#GH62529). +- 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 ^ diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index 853c0e1b50619..094f767399e2a 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -5522,7 +5522,8 @@ static bool isAtLeastAsSpecializedAs(Sema , 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 @@ -5591,7 +5592,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()); diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp b/clang/test/SemaCXX/cxx2b-deducing-this.cpp index 5f29a955e053c..55792e1448ac5 100644 --- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp +++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp @@ -838,3 +838,52 @@ int h() { }(); } } + +namespace GH92188 { +struct A { + template + 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 g() { + A a; + int lval; + a += "123"; + a.f1(lval); + a.f2(); + a.f3(lval); + a.f4(lval); + a.f5(lval); + a.f6(lval); +} +} >From 64e31749874a231956b898e89f00d63790d9f083 Mon Sep 17 00:00:00 2001 From: Mital Ashok Date: Wed, 15 May 2024 15:05:55 +0100 Subject: [PATCH 2/2] Add test where one template isn't a method --- clang/test/SemaCXX/cxx2b-deducing-this.cpp | 8 1 file changed, 8 insertions(+) diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp b/clang/test/SemaCXX/cxx2b-deducing-this.cpp index 55792e1448ac5..58372aaff96ea 100644 --- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp +++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp @@ -873,6 +873,12 @@ struct A { 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() { @@ -885,5 +891,7 @@ void g() { a.f4(lval); a.f5(lval); a.f6(lval); + a - lval; + a * lval; } } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Fix last argument not being used when comparing function template specializations when one has an explicit object argument (PR #92263)
MitalAshok wrote: See also: #83279 https://github.com/llvm/llvm-project/pull/92263 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Fix last argument not being used when comparing function template specializations when one has an explicit object argument (PR #92263)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Mital Ashok (MitalAshok) Changes Fixes #92188 --- Full diff: https://github.com/llvm/llvm-project/pull/92263.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+2) - (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+7-2) - (modified) clang/test/SemaCXX/cxx2b-deducing-this.cpp (+49) ``diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ae699ebfc6038..9850fc9f8e0b4 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -713,6 +713,8 @@ Bug Fixes to C++ Support - Correctly treat the compound statement of an ``if consteval`` as an immediate context. Fixes (#GH91509). - When partial ordering alias templates against template template parameters, allow pack expansions when the alias has a fixed-size parameter list. Fixes (#GH62529). +- 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 ^ diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index 853c0e1b50619..094f767399e2a 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -5522,7 +5522,8 @@ static bool isAtLeastAsSpecializedAs(Sema , 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 @@ -5591,7 +5592,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()); diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp b/clang/test/SemaCXX/cxx2b-deducing-this.cpp index 5f29a955e053c..55792e1448ac5 100644 --- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp +++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp @@ -838,3 +838,52 @@ int h() { }(); } } + +namespace GH92188 { +struct A { + template + 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 g() { + A a; + int lval; + a += "123"; + a.f1(lval); + a.f2(); + a.f3(lval); + a.f4(lval); + a.f5(lval); + a.f6(lval); +} +} `` https://github.com/llvm/llvm-project/pull/92263 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Fix last argument not being used when comparing function template specializations when one has an explicit object argument (PR #92263)
https://github.com/MitalAshok created https://github.com/llvm/llvm-project/pull/92263 Fixes #92188 >From 6496dbfc8100812c8d3ea5a668af0593b532e4fe Mon Sep 17 00:00:00 2001 From: Mital Ashok Date: Wed, 15 May 2024 14:23:17 +0100 Subject: [PATCH] [Clang][Sema] Fix last argument not being used when comparing function template specializations when one has an explicit object argument Fixes #92188 --- clang/docs/ReleaseNotes.rst| 2 + clang/lib/Sema/SemaTemplateDeduction.cpp | 9 +++- clang/test/SemaCXX/cxx2b-deducing-this.cpp | 49 ++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ae699ebfc6038..9850fc9f8e0b4 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -713,6 +713,8 @@ Bug Fixes to C++ Support - Correctly treat the compound statement of an ``if consteval`` as an immediate context. Fixes (#GH91509). - When partial ordering alias templates against template template parameters, allow pack expansions when the alias has a fixed-size parameter list. Fixes (#GH62529). +- 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 ^ diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index 853c0e1b50619..094f767399e2a 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -5522,7 +5522,8 @@ static bool isAtLeastAsSpecializedAs(Sema , 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 @@ -5591,7 +5592,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()); diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp b/clang/test/SemaCXX/cxx2b-deducing-this.cpp index 5f29a955e053c..55792e1448ac5 100644 --- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp +++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp @@ -838,3 +838,52 @@ int h() { }(); } } + +namespace GH92188 { +struct A { + template + 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 g() { + A a; + int lval; + a += "123"; + a.f1(lval); + a.f2(); + a.f3(lval); + a.f4(lval); + a.f5(lval); + a.f6(lval); +} +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits