RFR: 8263718: unused-result warning happens at os_linux.cpp
Thomas Stuefe
stuefe at openjdk.java.net
Thu Mar 18 10:06:00 UTC 2021
On Thu, 18 Mar 2021 09:48:27 GMT, Magnus Ihse Bursie <ihse at openjdk.org> wrote:
>>> "Note that a logical negation prior to cast to void is sufficient to suppress the warning:
>>>
>>> ```
>>> int void_cast_should_not_warn() {
>>> (void) !foo();
>>> // ^-- here
>>> return 0;
>>> }
>>> ```
>>>
>>> "
>>
>> The warning has gone with `(void)!`, but isn't is strange a bit? IMHO code changes or pragma (or compiler option) are suitable than it.
>
> I can't really comment on which is better -- it's up to you hotspot developers.
>
> Nevertheless, my personal preference is that `(void)` would have been best since it's a well-established idiom. If gcc is buggy about this, then I think I'd preferred to use this workaround with a comment `// the ! is needed to workaround gcc bug`, to keep with the idiom as much as possible. Pragmas also work, but I personally consider them ugly and a last resort. But once again, don't listen to what I'm saying :-)
I agree with Magnus. BTW, we are sure that alloca() call is not simply optimized away, right? Otherwise I would assign the return value to some file static volatile holder.
-------------
PR: https://git.openjdk.java.net/jdk/pull/3042
More information about the hotspot-dev
mailing list