[PATCH] D47687: fix: [Bug 18971] - Missing -Wparentheses warning
eric via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 3 10:04:10 PDT 2018
Higuoxing added a comment.
As for some test cases,
$ cat a.cc
#include <iostream>
#include <cassert>
#define bar(x) \
( \
( std::cout << x ) \
)
bool x;
int val;
void foo(bool b) {
std::cout << b << std::endl;
}
int main () {
foo(x && val == 4 || (!x && val == 5));
bar(x && val == 4 || (!x && val == 5));
assert(x && val == 4 || (!x && val == 5));
assert(x || val == 4 && "test");
return 0;
}
And clang will emits
a.cc:20:9: warning: '&&' within '||' [-Wlogical-op-parentheses]
foo(x && val == 4 || (!x && val == 5));
~~^~~~~~~~~~~ ~~
a.cc:20:9: note: place parentheses around the '&&' expression to silence this warning
foo(x && val == 4 || (!x && val == 5));
^
( )
a.cc:21:9: warning: '&&' within '||' [-Wlogical-op-parentheses]
bar(x && val == 4 || (!x && val == 5));
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:7:20: note: expanded from macro 'bar'
( std::cout << x ) \
~~~~~~~~~~~~~^
a.cc:21:9: note: place parentheses around the '&&' expression to silence this warning
bar(x && val == 4 || (!x && val == 5));
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:7:20: note: expanded from macro 'bar'
( std::cout << x ) \
~~~~~~~~~~~~~^
a.cc:22:12: warning: '&&' within '||' [-Wlogical-op-parentheses]
assert(x && val == 4 || (!x && val == 5));
~~^~~~~~~~~~~ ~~
/usr/include/assert.h:93:25: note: expanded from macro 'assert'
(__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __FILE__, __LINE__, #e) : (void)0)
^
a.cc:22:12: note: place parentheses around the '&&' expression to silence this warning
assert(x && val == 4 || (!x && val == 5));
~~^~~~~~~~~~~
/usr/include/assert.h:93:25: note: expanded from macro 'assert'
(__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __FILE__, __LINE__, #e) : (void)0)
^
3 warnings generated.
Repository:
rC Clang
https://reviews.llvm.org/D47687
More information about the cfe-commits
mailing list