According to the BitmaskType concept, the implementation has to assure that the following statement is well formend: (listed in §17.5.2.1.3.4)
The value Y is set in the object X if the expression X & Y is nonzero.
where X and Y are of concept-type BitmaskType.
When trying the following simple code snippet with gcc 4.7 I get template deduction errors:
#include <future>
int main() {
(std::launch::async & std::launch::async) != 0;
}
Error:
error: no match for 'operator!=' in '(std::launch)1 != 0'
... followed by tons of deduction errors
Is this a bug in gcc or am I just getting something wrong here? If yes, what is the proper way to perform this kind of check?
I already checked gcc buglist but couldn’t find anything covering this topic.
The members of
enumclasses are not meant to convert tointimplicitly or vice versa. You can either make sure that your bitmask type is converted tointor use the zero value of theenumclass. I’d think the latter is preferable:(I have also added parenthesis around the bitwise
andoperation since it has higher precedence than the comparison and it doesn’t really make much sense to bitwiseanda Boolean value with a bitmask type).The easiest way to see this is 7.2 [enum.dcl] paragraph 9:
This is, however, within a non-normative Example. Tracking the rules for scoped rules in the standard may require ruling out all the cases where conversions are allowed and currently don’t quite fancy this exercise.