Enable /Zc:throwingNew when building with MSVC#381
Closed
jjuhl wants to merge 1 commit into
Closed
Conversation
From Microsoft's documentation (https://learn.microsoft.com/en-us/cpp/build/reference/zc-throwingnew-assume-operator-new-throws?view=msvc-170) : "When the /Zc:throwingNew option is specified, the compiler optimizes calls to operator new to skip checks for a null pointer return. This option tells the compiler to assume that all linked implementations of operator new and custom allocators conform to the C++ standard and throw on allocation failure. By default in Visual Studio, the compiler pessimistically generates null checks (/Zc:throwingNew-) for these calls, because users can link with a non-throwing implementation of operator new or write custom allocator routines that return null pointers." Nothing in TGUI assumes that `new` returns nullptr on failure and if any users write an allocator that does so or explicitly link to a non-conforming, non-throwing allocator, then they are advanced enough to know to locally disable this option. We should not penalize the common user to cater to an obscure corner case (and this also better matches behaviour with other compilers). Let's default to the standard compliant, and better performing, behaviour.
Contributor
Author
|
Need to check for clang. Never mind for now. I'll get back to this at some point in the future. |
Owner
|
I've added a section for MSVC-specific compiler flags now. Clang-CL already assumes the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
From Microsoft's documentation
(https://learn.microsoft.com/en-us/cpp/build/reference/zc-throwingnew-assume-operator-new-throws?view=msvc-170) :
"When the /Zc:throwingNew option is specified, the compiler optimizes calls to operator new to skip checks for a null pointer return. This option tells the compiler to assume that all linked implementations of operator new and custom allocators conform to the C++ standard and throw on allocation failure. By default in Visual Studio, the compiler pessimistically generates null checks (/Zc:throwingNew-) for these calls, because users can link with a non-throwing implementation of operator new or write custom allocator routines that return null pointers."
Nothing in TGUI assumes that
newreturns nullptr on failure and if any users write an allocator that does so or explicitly link to a non-conforming, non-throwing allocator, then they are advanced enough to know to locally disable this option. We should not penalize the common user to cater to an obscure corner case (and this also better matches behaviour with other compilers). Let's default to the standard compliant, and better performing, behaviour.