Question

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.

Was it helpful?

Solution

The members of enum classes are not meant to convert to int implicitly or vice versa. You can either make sure that your bitmask type is converted to int or use the zero value of the enum class. I'd think the latter is preferable:

(std::launch::async & std::launch::async) != std::launch()

(I have also added parenthesis around the bitwise and operation since it has higher precedence than the comparison and it doesn't really make much sense to bitwise and a Boolean value with a bitmask type).

The easiest way to see this is 7.2 [enum.dcl] paragraph 9:

... Note that this implicit enum to int conversion is not provided for a scoped enumeration: ...

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top