This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [buildrobot] OMP: r203408 probably needs another operator& returning bool
- From: Jason Merrill <jason at redhat dot com>
- To: Jakub Jelinek <jakub at redhat dot com>, Jan-Benedict Glaw <jbglaw at lug-owl dot de>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Fri, 11 Oct 2013 10:11:21 -0400
- Subject: Re: [buildrobot] OMP: r203408 probably needs another operator& returning bool
- Authentication-results: sourceware.org; auth=none
- References: <20131011124416 dot GP24222 at lug-owl dot de> <20131011135601 dot GT30970 at tucnak dot zalov dot cz>
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