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

Albert Mingkun Yang ayang at openjdk.org
Wed Feb 18 09:11:21 UTC 2026


On Tue, 17 Feb 2026 09:50:17 GMT, Leo Korinth <lkorinth at openjdk.org> wrote:

> 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...

I agree that casts are often a smell, and enabling warnings for implicit narrowing conversions is absolutely the right goal.

I also see that `sizeof_auto` removes narrowing at the source for `sizeof`, which is nice. However, `sizeof` is only one source of narrowing conversions. If we use `sizeof_auto` for this specific case but still rely on `checked_cast` elsewhere, we end up with two different mechanisms addressing the same problem. That might introduce more conceptual overhead than simply using one consistent approach.

There’s also the broader consistency question: once we introduce `sizeof_auto`, developers need to decide between `sizeof` and `sizeof_auto`. Is this intended to replace most `sizeof` usages in size computations, or only specific ones? Without a clear rule, we may end up with mixed semantics in the codebase.

Since we already have `checked_cast` for explicit narrowing, keeping a single, consistent mechanism feels simpler to me.

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

PR Comment: https://git.openjdk.org/jdk/pull/29716#issuecomment-3919567930


More information about the hotspot-dev mailing list