RFR: 8377895: Create sizeof_auto, to reduce narrowing conversions [v3]

Leo Korinth lkorinth at openjdk.org
Thu Feb 19 15:59:31 UTC 2026


On Wed, 18 Feb 2026 14:58:31 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

>> Leo Korinth has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   using Kim's suggestions
>
> test/hotspot/gtest/utilities/test_globalDefinitions.cpp line 354:
> 
>> 352:   static_assert(sizeof(sizeof_auto(char[std::numeric_limits<uint16_t>::max() + 1LL])) == sizeof(uint32_t));
>> 353: #if defined(_LP64) && !defined(_WINDOWS)
>> 354:   // char array sometimes limited to 2 gig length on 32 bit platforms (signed), and on windows (even 64 bit!!!)
> 
> Does it work to have an array of some larger type (like a struct with a bunch of members)
> to get a larger sizeof?  Or is it that somehow the array byte size is limited?  The latter would
> seem pretty surprising to me, but I don't know windows at all well.

It is a strange limitation. 
this works: `const char* c = new char[3'000'000'000];`
this does not work: `sizeof (char[3'000'000'000]);`

I get: 

error C2148: total size of array must not exceed 0x7fffffff bytes
error C2070: 'char [-1294967296]': ill-formed sizeof operand


I think the compiler confuses `sizeof` expressions with limitations of static arrays. Which is extra confusing because there is no problem allocating the array dynamically with `new`.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/29716#discussion_r2828682103


More information about the hotspot-dev mailing list