hostboot icon indicating copy to clipboard operation
hostboot copied to clipboard

Fix enum constant in boolean context warnings

Open shenki opened this issue 7 years ago • 2 comments

target.H contains some code that checks AttributeTraits, which are enums. With GCC 7 testing an enum cases a warning:

../../../../../src/include/usr/targeting/common/target.H:668:5: warning: enum constant in boolean context [-Wint-in-bool-context]
template<const ATTRIBUTE_ID A>
bool Target::tryGetAttr(typename AttributeTraits<A>::Type& o_attrValue) const
{
    if(AttributeTraits<A>::readable) { } 
    if(AttributeTraits<A>::notHbMutex) { }
    if(AttributeTraits<A>::notFspMutex) { }
    return _tryGetAttr(A,sizeof(o_attrValue),&o_attrValue);
}

shenki avatar Nov 14 '17 06:11 shenki

I believe this code is actually only there to force build failures when the enums don't exist. I'm not quite sure how to fix it, I guess change it to this maybe? if(AttributeTraits<A>::readable == AttributeTraits<A>::readable) { } Or would the compiler optimize that out?

Maybe @bofferdn has some thoughts, think he added this way back when.

dcrowell77 avatar Nov 14 '17 16:11 dcrowell77

the idea was to force a compile fail if you tried to write code that wrote an attribute when it's not writeable. The compiler optimizes all that stuff away.

bofferdn avatar May 23 '18 16:05 bofferdn