-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang] [SemaCXX] Disallow deducing "this" on operator new
and delete
#82251
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
Conversation
@llvm/pr-subscribers-clang Author: Rajveer Singh Bharadwaj (Rajveer100) ChangesResolves Issue #82249 As described in the issue, any deallocation function for a Full diff: https://github.com/llvm/llvm-project/pull/82251.diff 2 Files Affected:
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index ab8a967b06a456..7a7b544d82b640 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11391,7 +11391,9 @@ void Sema::CheckExplicitObjectMemberFunction(Declarator &D,
<< ExplicitObjectParam->getSourceRange();
}
- if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static) {
+ if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||
+ (D.getContext() == clang::DeclaratorContext::Member &&
+ D.isStaticMember())) {
Diag(ExplicitObjectParam->getBeginLoc(),
diag::err_explicit_object_parameter_nonmember)
<< D.getSourceRange() << /*static=*/0 << IsLambda;
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index aab35828096a8e..530f8bf6af1b6b 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -16,6 +16,10 @@ struct S {
static void f(this auto); // expected-error{{an explicit object parameter cannot appear in a static function}}
virtual void f(this S); // expected-error{{an explicit object parameter cannot appear in a virtual function}}
+ // new and delete are implicitly static
+ void *operator new(this unsigned long); // expected-error{{an explicit object parameter cannot appear in a static function}}
+ void operator delete(this void*); // expected-error{{an explicit object parameter cannot appear in a static function}}
+
void g(this auto) const; // expected-error{{explicit object member function cannot have 'const' qualifier}}
void h(this auto) &; // expected-error{{explicit object member function cannot have '&' qualifier}}
void i(this auto) &&; // expected-error{{explicit object member function cannot have '&&' qualifier}}
|
This change needs a release note. Besides that, I think the change makes sense, thanks! |
3ad4e85
to
8fd5e1b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM modulo nit
…ete` Resolves Issue llvm#82249
8fd5e1b
to
05dbfac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for submitting a fix.
@Rajveer100 you need us to merge that for you? |
3ccd24a
to
05dbfac
Compare
Considering the PR sounds good to the reviewers, yes it would be great to have it merged. |
Thanks for working on this! |
Resolves Issue #82249
As described in the issue, any deallocation function for a
class X
is a static member (even if not explicitly declared static).