RFR: 8306579: Consider building with /Zc:throwingNew

Julian Waters jwaters at openjdk.org
Tue Nov 12 14:35:58 UTC 2024


[JDK-8305590](https://bugs.openjdk.org/browse/JDK-8305590) removed `-fcheck-new` when building with gcc. It turns out Visual Studio has a similar option, though inverted in behavior and default.

It seems like /Zc:throwingNew- (the default) corresponds to gcc -fcheck-new, and /Zc:throwingNew corresponds to -fno-check-new (the default).

The Visual Studio documentation strongly recommends using /Zc:throwingNew if possible, as turning it off (the default) seriously bloats code and inhibits optimizations.
https://learn.microsoft.com/en-us/cpp/build/reference/zc-throwingnew-assume-operator-new-throws?view=msvc-170

As mentioned in [JDK-8305590](https://bugs.openjdk.org/browse/JDK-8305590), the standard says that an allocation function can report allocation failure either by returning null (when it must have a nothrow exception specification), or by throwing `std::bad_alloc` (so obviously must not be declared as non-throwing). HotSpot allocation functions terminate the program instead of throwing on allocation failure, so similarly don't need the result checked for null.

The documentation for /Zc:throwingNew is somewhat vague and confusing, so some investigation is probably needed to verify it really has the desired effect for us.

-------------

Commit messages:
 - -Zc:throwingNew in flags-cflags.m4
 - 8306579

Changes: https://git.openjdk.org/jdk/pull/22039/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=22039&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8306579
  Stats: 13 lines in 2 files changed: 0 ins; 11 del; 2 mod
  Patch: https://git.openjdk.org/jdk/pull/22039.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/22039/head:pull/22039

PR: https://git.openjdk.org/jdk/pull/22039


More information about the build-dev mailing list