RFR: 8255389: ConcurrentHashTable::NoOp omits return in non-void return method

Kim Barrett kbarrett at openjdk.java.net
Mon Oct 26 11:44:16 UTC 2020


On Mon, 26 Oct 2020 11:39:09 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

>> Static analysis complains there is a non-void return method without a return statement:
>> 
>>   struct NoOp {
>>     void operator()(VALUE*) {}
>>     const VALUE& operator()() {} // <--- here
>>     void operator()(bool, VALUE*) {}
>>   } noOp;
>> 
>> AFAICS, this is UB, and we have seen cases like these break compilers in other places. Not in this case, though, because `noOp` is only used as the default functor in `remove`, which does not use this getter-like definition. Still, it would be good to remove that risky definition, so that it is not used accidentally.
>
> src/hotspot/share/utilities/concurrentHashTable.hpp line 201:
> 
>> 199:     void operator()(VALUE*) {}
>> 200:     void operator()(bool, VALUE*) {}
>> 201:   } noOp;
> 
> I don't think the noOp object is useful.  I think it would be clearer to just use a constructed object of this type in the one place it's used, i.e. `NoOp()` or (if name is changed) `IgnoreValue()`.

If we were using lambdas we could delete this class and just use `[](VALUE*) {}` in the one place it's being used.

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

PR: https://git.openjdk.java.net/jdk/pull/863


More information about the hotspot-dev mailing list