RFR: 8377895: Create sizeof_auto, to reduce narrowing conversions [v7]
Kim Barrett
kbarrett at openjdk.org
Mon Feb 23 19:44:27 UTC 2026
On Mon, 23 Feb 2026 13:22:40 GMT, Leo Korinth <lkorinth at openjdk.org> wrote:
>> src/hotspot/share/utilities/globalDefinitions.hpp line 179:
>>
>>> 177: std::conditional_t<N <= std::numeric_limits<uint32_t>::max(), uint32_t, uint64_t>>>;
>>> 178: return static_cast<unsigned_auto>(N);
>>> 179: }
>>
>> If I may butt in... This function has nothing to do with `sizeof`, so its name should not contain "sizeof". Its current name is misleading.
>> This function is of general use, so much so that it perhaps could even be part of the standard C++ language. `auto_size()` is not a bad choice of name for such a function.
>
> I agree that the template is more general than what the name implies. I think the current name is not misleading at all. I will change it if you can create a name that Kim approves.
>
> I propose that we leave the renaming to the next user of the method.
In it's current form, no, this is not a general utility. It takes a `size_t` as
the template parameter, because that is what `sizeof` returns, and it is only
intended to support that. A general utility would need to take a `uintmax_t`
or something like that, and should deal with potentially > 64bit integer types
like gcc's `unsigned __int128`. Because of platform vagaries in this area that
is on or beyond the edge of the standard, such a function may not be easy to
write. That complexity shouldn't be inflicted on this change.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/29716#discussion_r2842702040
More information about the hotspot-dev
mailing list