Skip to content

Define void operator delete[](void *p, std::size_t n) in new_delete.cpp #430

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/rp2_common/pico_standard_link/new_delete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ void *operator new[](std::size_t n) {
return std::malloc(n);
}

void operator delete(void *p, __unused std::size_t n) noexcept { std::free(p); }

void operator delete(void *p) { std::free(p); }

void operator delete[](void *p) noexcept { std::free(p); }

#if __cpp_sized_deallocation

void operator delete(void *p, __unused std::size_t n) noexcept { std::free(p); }

void operator delete[](void *p, __unused std::size_t n) noexcept { std::free(p); }
Copy link
Contributor

@fivdi fivdi May 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The C++ new header only adds the declarations for the sized deallocation functions if __cpp_sized_deallocation is true.

So, should the sized deallocation function that is being added with this PR (and the already existing size deallocation function on line 20) be conditionally compiled using __cpp_sized_deallocation (see here)?

Here is what the new header has:

#if __cpp_sized_deallocation
void operator delete(void*, std::size_t) _GLIBCXX_USE_NOEXCEPT
  __attribute__((__externally_visible__));
void operator delete[](void*, std::size_t) _GLIBCXX_USE_NOEXCEPT
  __attribute__((__externally_visible__));
#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will work either way. I looked up some other implementations of this fix and found one case where the conditional is included (here), and two where it was not (here and here).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure it will work too, however, I'm not sure if it's a good idea to make functions intended for C++14 and higher available in C++11.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated


#endif

#endif