-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Behaviour of new with std::nothrow #20132
Comments
Most likely you want to set Lines 124 to 144 in e69b6cf
|
Oh wait, sorry I didn't see that is actually If you can come up with a patch the keeps the existing behaviour for folks that don't use |
M-Mueller
pushed a commit
to M-Mueller/emscripten
that referenced
this issue
Aug 29, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm currently porting some code that uses
std::nothrow
for allocations. However, if I build without exception support, the application aborts if the allocation fails instead of returning 0.The issue can be reproduced with the following code:
Build with:
If I run this in the browser I get:
If I build with
-fexception
the code works as expected, i.e. the "Cannot enlarge memory" errors are still there but the program doesn't abort and prints "Result: 0".I think the problem is in system/lib/libcxx/src/new.cpp: the
operator new(size_t size, const std::nothrow_t&)
just callsoperator new(std::size_t size)
internally which always aborts in case of failure.I agree with the reasons for
abort
in #11042 for the current behaviour ofoperator new(std::size_t size)
. However, I think thestd::nothrow
variant aborting is not correct. Without exceptions enabled, this is the only method to check whether an allocation failed. Also code that uses this should be aware that it might return 0.Version of emscripten/emsdk:
The text was updated successfully, but these errors were encountered: