Skip to content

Commit 7332713

Browse files
authored
[Clang] prevent null explicit object argument from being deduced (#104328)
Fixes #102025
1 parent e398da2 commit 7332713

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ Bug Fixes to C++ Support
257257
- Properly reject defaulted relational operators with invalid types for explicit object parameters,
258258
e.g., ``bool operator==(this int, const Foo&)`` (#GH100329), and rvalue reference parameters.
259259
- Properly reject defaulted copy/move assignment operators that have a non-reference explicit object parameter.
260+
- Fixed an assertion failure by preventing null explicit object arguments from being deduced. (#GH102025).
260261

261262
Bug Fixes to AST Handling
262263
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4462,6 +4462,9 @@ TemplateDeductionResult Sema::DeduceTemplateArguments(
44624462
ParamTypesForArgChecking.push_back(ParamType);
44634463

44644464
if (ParamIdx == 0 && HasExplicitObject) {
4465+
if (ObjectType.isNull())
4466+
return TemplateDeductionResult::InvalidExplicitArguments;
4467+
44654468
if (auto Result = DeduceCallArgument(ParamType, 0,
44664469
/*ExplicitObjectArgument=*/true);
44674470
Result != TemplateDeductionResult::Success)

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,3 +1011,22 @@ struct X;
10111011
static_assert(__is_same(X<B{0}>, X<B{0}>));
10121012
static_assert(!__is_same(X<B{0}>, X<B{1}>));
10131013
} // namespace defaulted_compare
1014+
1015+
namespace GH102025 {
1016+
struct Foo {
1017+
template <class T>
1018+
constexpr auto operator[](this T &&self, auto... i) // expected-note {{candidate template ignored: substitution failure [with T = Foo &, i:auto = <>]: member '_evaluate' used before its declaration}}
1019+
-> decltype(_evaluate(self, i...)) {
1020+
return self._evaluate(i...);
1021+
}
1022+
1023+
private:
1024+
template <class T>
1025+
constexpr auto _evaluate(this T &&self, auto... i) -> decltype((i + ...));
1026+
};
1027+
1028+
int main() {
1029+
Foo foo;
1030+
return foo[]; // expected-error {{no viable overloaded operator[] for type 'Foo'}}
1031+
}
1032+
}

0 commit comments

Comments
 (0)