Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang: warning about operator<< precedence #27

Open
genbattle opened this issue Jan 6, 2016 · 4 comments
Open

clang: warning about operator<< precedence #27

genbattle opened this issue Jan 6, 2016 · 4 comments
Labels

Comments

@genbattle
Copy link

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 ) )
@martinmoene
Copy link
Owner

...and defeats the expression decomposition...

See also:

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") \

@genbattle
Copy link
Author

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.

@martinmoene
Copy link
Owner

As an aside:

For some time lest does contain:

#ifdef __clang__
...
# pragma clang diagnostic ignored "-Woverloaded-shift-op-parentheses"
...

@martinmoene
Copy link
Owner

Keeping this open to remind myself about this ongoing discussion with Catch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants