RFR: 8338331: Fix -Wzero-as-null-pointer-constant warnings from CHECK_0 in jni.cpp

Kim Barrett kbarrett at openjdk.org
Thu Aug 15 17:53:59 UTC 2024


On Tue, 13 Aug 2024 22:51:34 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> Please review this change to some macros in jni.cpp.  These macros were using
>> CHECK_0 when calling functions that can "throw" exceptions.  However, the
>> return type involved is provided by a macro argument, and is a pointer type
>> for some uses of the macros.  This triggered -Wzero-as-null-pointer-constant
>> warnings when enabled.
>> 
>> To remove the warnings, these CHECK_0() uses are changed to CHECK_() with an
>> argument expression that constructs and value-initializes a temporary of that
>> return type, e.g. `ResultType{}`.  Value-initialization of a scalar type is
>> zero-initialization. Zero-initialization of a scalar type initializes it to
>> the value obtained by convertion a literal 0 to that type.  So a zero of the
>> appropriate type for arithmetic types.  For pointer types it's initialized to
>> nullptr, without triggering the warning.
>> 
>> Testing: mach5 tier1
>
> Okay. Thanks

Thanks for reviews @dholmes-ora and @shipilev

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

PR Comment: https://git.openjdk.org/jdk/pull/20575#issuecomment-2291848592


More information about the hotspot-dev mailing list