RFR: 8313249: Fix -Wconversion warnings in verifier code [v2]
Coleen Phillimore
coleenp at openjdk.org
Mon Jul 31 12:45:53 UTC 2023
On Sun, 30 Jul 2023 11:52:57 GMT, David Holmes <dholmes at openjdk.org> wrote:
>> To me, the two lines serves two purposes:
>>
>>
>> assert(appends > 0 && appends < 4, "Invalid append amount");
>>
>> This is the input expected by this function.
>>
>>
>> return static_cast<u1>(251 + appends);
>>
>>
>> This is a mechanical check that the code is actually correctly written (i.e., you didn't mess up and wrote (253 + appends). That way the reader doesn't have do the math in order to trust this code.
>
> True - the assert is checking a precondition; the checked_cast would be checking a postcondition.
What Ioi said. The explicit assert gives a better, more helpful error message than
assert(static_cast<T1>(result) == thing, "must be");
And so in this case I always choose an existing assert rather than checked_cast. I'll change it to static_cast<> instead of the C style cast. I always find static_cast<> a noisier and mentally more effort than the C style cast, but it doesn't matter.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/15056#discussion_r1279237899
More information about the hotspot-runtime-dev
mailing list