clang: warning about operator<< precedence
Compiling tests that use lest under clang++ (3.7) yields warnings for each EXPECT such as the following:
/home/nick/Projects/km/src/test/test.cpp:67:62: error: overloaded operator <<
has higher precedence than comparison operator
[-Werror,-Woverloaded-shift-op-parentheses]
...EXPECT(std::count(clusters.cbegin(), clusters.cend(), 3) == 0);
^ ~
/home/nick/Projects/km/src/test/lest.hpp:132:55: note: expanded from macro
'lest_EXPECT'
if ( lest::result score = lest_DECOMPOSE( expr ) ) \
^
/home/nick/Projects/km/src/test/lest.hpp:215:67: note: expanded from macro
'lest_DECOMPOSE'
#define lest_DECOMPOSE( expr ) ( lest::expression_decomposer() << expr )
The warning is talking about this line in lest.hpp:
#define lest_DECOMPOSE( expr ) ( lest::expression_decomposer() << expr )
Adding extra parenthesis prevents this warning, and a potentially catastrophic evaluation order mess:
#define lest_DECOMPOSE( expr ) ( lest::expression_decomposer() << ( expr ) )
...and defeats the expression decomposition...
See also:
- DGtal - Fix parentheses warning with Catch PR1067
- Catch - Disable -Wparentheses warnings for g++ < 4.8 PR528
- Catch - switch from ->* to <= in expression decomposer PR247
I'm following this discussion and see what comes out of it.
I might try to change lest_DECOMPOSE() to use:
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Woverloaded-shift-op-parentheses\"") \
( lest::expression_decomposer() << expr ) \
_Pragma("clang diagnostic pop") \
Ah, it appears I didn't fully understand the intention of the code. Ignoring the warning may be a better solution in this case if the behaviour is intended.
As an aside:
For some time lest does contain:
#ifdef __clang__
...
# pragma clang diagnostic ignored "-Woverloaded-shift-op-parentheses"
...
Keeping this open to remind myself about this ongoing discussion with Catch.