RFR: 8377895: Create sizeof_auto, to reduce narrowing conversions [v2]
Leo Korinth
lkorinth at openjdk.org
Tue Feb 17 09:52:34 UTC 2026
On Mon, 16 Feb 2026 17:05:55 GMT, Albert Mingkun Yang <ayang at openjdk.org> wrote:
> > it is checked at runtime, not compile time.
> > it is checked only on debug builds
>
> Both points are true, but for the specific goal here—reducing narrowing conversion warnings—I don’t think either of those limitations are material. The compiler will still complain at any remaining implicit narrowing sites, so we’re not relying on runtime checking to catch them.
>
> > you need to use it, it will make the code harder to read, it is easier to use sizeof_auto
>
> On the readability point, I think that’s somewhat subjective. Introducing a new `sizeof`-like API changes the type semantics of `sizeof`, which feels like a broader conceptual shift. Since we already have `checked_cast` to make narrowing explicit, using it seems more localized and avoids adding another abstraction to the codebase.
>
> Just my 2c.
I see every cast as a potential bug. That is why I want to have warnings enabled for implicit narrowing conversions, because they hide bugs. If I can have an assignment or expression without a cast, that makes it so much easier to read, because I do not need to consider if I am loosing information (when erroring on implicit narrowing conversions). Using `sizeof_auto` will create safe promotions instead of unsafe narrowing conversions needing a cast.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/29716#issuecomment-3913482711
More information about the hotspot-dev
mailing list