Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix enum constant in boolean context warnings #123

Open
shenki opened this issue Nov 14, 2017 · 2 comments
Open

Fix enum constant in boolean context warnings #123

shenki opened this issue Nov 14, 2017 · 2 comments
Labels

Comments

@shenki
Copy link
Member

shenki commented Nov 14, 2017

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);
}
@dcrowell77
Copy link
Collaborator

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::readable == AttributeTraits::readable) { }
Or would the compiler optimize that out?

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

@bofferdn
Copy link
Collaborator

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.

@pragupta pragupta added the bug label Aug 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants