Skip to content

Commit 57d81c2

Browse files
authored
[Clang] Remove explicit object from non member function. (llvm#148807)
To avoid crashing later (as we assume only member functions can have explicit object parameters) Fixes llvm#113185
1 parent 8cbcaee commit 57d81c2

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,7 @@ Bug Fixes to C++ Support
953953
- Fix a bug where private access specifier of overloaded function not respected. (#GH107629)
954954
- Correctly handles calling an explicit object member function template overload set
955955
through its address (``(&Foo::bar<baz>)()``).
956+
- Fix a crash when using an explicit object parameter in a non-member function. (#GH113185)
956957
- Fix a crash when forming an invalid call to an operator with an explicit object member. (#GH147121)
957958
- Correctly handle allocations in the condition of a ``if constexpr``.(#GH120197) (#GH134820)
958959
- Fixed a crash when handling invalid member using-declaration in C++20+ mode. (#GH63254)

clang/lib/Sema/SemaType.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4860,7 +4860,9 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
48604860
S.Diag(First->getBeginLoc(),
48614861
diag::err_explicit_object_parameter_invalid)
48624862
<< First->getSourceRange();
4863-
4863+
// Do let non-member function have explicit parameters
4864+
// to not break assumptions elsewhere in the code.
4865+
First->setExplicitObjectParameterLoc(SourceLocation());
48644866
D.setInvalidType();
48654867
AreDeclaratorChunksValid = false;
48664868
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,3 +1347,13 @@ int main() {
13471347
// expected-note@#S3-f-cand2 {{candidate function not viable: no known conversion from 'S3' to 'int' for object argument}}
13481348
}
13491349
}
1350+
1351+
namespace GH113185 {
1352+
1353+
void Bar(this int) { // expected-note {{candidate function}}
1354+
// expected-error@-1 {{an explicit object parameter cannot appear in a non-member function}}
1355+
Bar(0);
1356+
Bar(); // expected-error {{no matching function for call to 'Bar'}}
1357+
}
1358+
1359+
}

0 commit comments

Comments
 (0)