On 10/11/2013 09:56 AM, Jakub Jelinek wrote:
With the operator bool (), there is ambiguity in the
if (((mask >> something) & 1) == 0)
tests (so had to use OMP_CLAUSE_MASK_{1,0} instead of {1,0})
This is an example of why operator bool is a bad idea in general. If we
were using C++11, we could make the operator 'explicit' so that it's
only used in actual boolean context, but without 'explicit' it gets hit
too often.
To deal with this issue, C++98 programmers tend to use a conversion to
pointer-to-member, which is also testable as a boolean, instead.
http://www.artima.com/cppsource/safebool.html
another
possibility is not to add operator bool () overload that introduces that
ambiguity, but then if (mask & something) needs to be replaced with
if ((mask & something) != 0) and operator != (int) added.
I guess I slightly prefer the first patch since it is smaller.
Since the coding standards say "Conversion operators should be avoided"
(because they can't be explicit), I think this is the way to go.
But it would be better to add operator!=(omp_clause_mask).
Jason