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

Warning for parentheses around comparison in operand of ‘==’ #870

Closed
barsan-md opened this issue Mar 27, 2017 · 6 comments
Closed

Warning for parentheses around comparison in operand of ‘==’ #870

barsan-md opened this issue Mar 27, 2017 · 6 comments

Comments

@barsan-md
Copy link

I know this was reported many times and maybe fixed (at least for gcc 4.7) but I'm gaving this issue with GCC 6.3 on Linux Mint 18.

Anyway a temporary solution that works for me is to add
#pragma GCC diagnostic ignored "-Wparentheses"
in the source code

@barsan-md barsan-md changed the title Worning for parentheses around comparison Worning for parentheses around comparison in operand of ‘==’ Mar 27, 2017
@horenmar
Copy link
Member

We are currently attempting to suppress the warning by using _Pragma for GCC versions 4.8 and newer.

This would let us suppress it only for the assertion macros, but as it turns out, GCC likely has a long-standing bug in handling _Pragmas in C++ mode, as can be seen in this example

#include <stdio.h>

#define TEST(expr) \
    int a = 1; \
    _Pragma( "GCC diagnostic push" ) \
    _Pragma( "GCC diagnostic ignored \"-Wparentheses\"" ) \
    if (a <= expr) { \
        printf("filler\n"); \
    } \
    _Pragma( "GCC diagnostic pop" )

int main(){
    int b = 2, c = 3;
    TEST(b == c);
}

If you compile this using current GCC as C, it will not trigger the warning. If you compile this as C++, it will warn about bad parentheses.

We will likely end-up using plain pragma to suppress the warning globally in the next release.

@onqtam
Copy link

onqtam commented Mar 29, 2017

I have the same experience in doctest with _Pragma() not working for the g++ frontend - related reports:

It's weird that I don't get the -Wparentheses warning though - but my expression decomposition uses operator<< (like lest does) instead of operator<= so it might be related to operator precedence - << is before the comparison ones

@aldanor
Copy link

aldanor commented Mar 30, 2017

Same for me (GCC 5.2).

In my case, enabling CATCH_CONFIG_FAST_COMPILE upgrading to Catch v1.8.2 triggers a bajillion of -Wparentheses warnings that weren't there in the normal mode, and the build is in fact slower.

(there were also a few of these spurious warnings with 1.7.2 version that I had to wrap in parens manually -- I couldn't figure out the logic behind those)

@aldanor
Copy link

aldanor commented Mar 30, 2017

Related: #565

@horenmar
Copy link
Member

@aldanor Basically, at some point in the past (can't tell you version on top of my head, but a recent one), we switched to using _Pragmas for GCC that support them and only using #pragma for older ones. As it turns out, the _Pragma support in GCC is very spotty: I can compile a small Catch example file using g++-4.8 on my machine without warnings, but on different machine, with newer g++, the warnings come back. Also it has trouble with templates...

We will probably end up just using #pragma for all gcc versions and let it leak into the test files.

@horenmar horenmar changed the title Worning for parentheses around comparison in operand of ‘==’ Warning for parentheses around comparison in operand of ‘==’ Apr 5, 2017
@horenmar
Copy link
Member

horenmar commented Apr 5, 2017

I am going to close this, as I moved Catch back to force disabling Wparentheses everywhere using #pragma in 8f85d08.

This means that we disable the warning for GCC users even outside our assertions, but the spotty _Pragma support meant that the status quo was untenable.

@horenmar horenmar closed this as completed Apr 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants