Skip to content
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

overloading operator new and operator delete #455

Closed
venkat-gvk opened this issue Mar 19, 2022 · 3 comments
Closed

overloading operator new and operator delete #455

venkat-gvk opened this issue Mar 19, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@venkat-gvk
Copy link

Shouldn't the generated output prefix the keyword 'static' in member function as operator new and delete functions are static by default?

operator new and delete

@andreasfertig
Copy link
Owner

andreasfertig commented Mar 21, 2022

Hello @venkat-gvk,

thanks for bringing this up! I believe what C++ Insights shows is correct. We can have both a static and non-static version. It is up to us to say when the operator should be static. See cppreference.com/w/cpp/memory/new/operator_new

... Both single-object and array allocation functions may be defined as public static member functions of a class (versions (15-18)). ...

See below for the correct answer.

Andreas

@venkat-gvk
Copy link
Author

Thanks for the reference

Venkat

@andreasfertig
Copy link
Owner

Hello @venkat-gvk,

my appologies but my initial answer was wrong. You're right, the overloaded operators new and delete are implicitly static. Here is the correct source: [class.free]

A fix is on its way.

Andreas

@andreasfertig andreasfertig added the bug Something isn't working label May 1, 2022
andreasfertig added a commit that referenced this issue May 1, 2022
Fixed #455: Overloaded class new/delete operators are implicitly static.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants