Skip to content

Commit 8fd5e1b

Browse files
committed
[clang] [SemaCXX] Disallow deducing "this" on operator new and delete
Resolves Issue #82249
1 parent 0ca74c3 commit 8fd5e1b

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ Bug Fixes to C++ Support
254254
Fixes (`#68490 <https://github.com/llvm/llvm-project/issues/68490>`_)
255255
- Fix a crash when trying to call a varargs function that also has an explicit object parameter.
256256
Fixes (`#80971 ICE when explicit object parameter be a function parameter pack`)
257+
- Reject explicit object parameters on implicitly static member functions.
258+
Fixes (`#82249 <https://github.com/llvm/llvm-project/issues/82249>` _)
257259
- Fixed a bug where abbreviated function templates would append their invented template parameters to
258260
an empty template parameter lists.
259261
- Clang now classifies aggregate initialization in C++17 and newer as constant

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11395,7 +11395,9 @@ void Sema::CheckExplicitObjectMemberFunction(Declarator &D,
1139511395
<< ExplicitObjectParam->getSourceRange();
1139611396
}
1139711397

11398-
if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static) {
11398+
if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||
11399+
(D.getContext() == clang::DeclaratorContext::Member &&
11400+
D.isStaticMember())) {
1139911401
Diag(ExplicitObjectParam->getBeginLoc(),
1140011402
diag::err_explicit_object_parameter_nonmember)
1140111403
<< D.getSourceRange() << /*static=*/0 << IsLambda;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ struct S {
1616
static void f(this auto); // expected-error{{an explicit object parameter cannot appear in a static function}}
1717
virtual void f(this S); // expected-error{{an explicit object parameter cannot appear in a virtual function}}
1818

19+
// new and delete are implicitly static
20+
void *operator new(this unsigned long); // expected-error{{an explicit object parameter cannot appear in a static function}}
21+
void operator delete(this void*); // expected-error{{an explicit object parameter cannot appear in a static function}}
22+
1923
void g(this auto) const; // expected-error{{explicit object member function cannot have 'const' qualifier}}
2024
void h(this auto) &; // expected-error{{explicit object member function cannot have '&' qualifier}}
2125
void i(this auto) &&; // expected-error{{explicit object member function cannot have '&&' qualifier}}

0 commit comments

Comments
 (0)