RFR: 8263718: unused-result warning happens at os_linux.cpp
Magnus Ihse Bursie
ihse at openjdk.java.net
Thu Mar 18 09:52:15 UTC 2021
On Wed, 17 Mar 2021 23:08:31 GMT, Yasumasa Suenaga <ysuenaga at openjdk.org> wrote:
>> Did you notice this workaround in the gcc bug report?
>>
>> "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;
>> }
>> "
>
>> "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 :-)
-------------
PR: https://git.openjdk.java.net/jdk/pull/3042
More information about the hotspot-dev
mailing list