diff options
author | Nico Weber <nicolasweber@gmx.de> | 2016-10-27 16:32:06 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2016-10-27 16:32:06 +0000 |
commit | 44f6f2ee423325e6157846593a74e5ed01ab3062 (patch) | |
tree | 7bb39737f18a1789a24d402a2e9e3f4f24109c1d /clang/test/SemaCXX/warn-logical-not-compare.cpp | |
parent | 6c273763a366de3b1e22348b638795795fb7e005 (diff) | |
download | bcm5719-llvm-44f6f2ee423325e6157846593a74e5ed01ab3062.tar.gz bcm5719-llvm-44f6f2ee423325e6157846593a74e5ed01ab3062.zip |
Expand -Wlogical-not-parentheses to also fire on `!x & A`.
This is a misspelling of the intended !(x & A) negated bit test that happens in
practice every now and then.
I ran this on Chromium and all its dependencies, and it fired 0 times -- no
false or true positives, but it would've caught a bug in an in-progress change
that had to be caught by a Visual Studio warning instead.
https://reviews.llvm.org/D26035
llvm-svn: 285310
Diffstat (limited to 'clang/test/SemaCXX/warn-logical-not-compare.cpp')
-rw-r--r-- | clang/test/SemaCXX/warn-logical-not-compare.cpp | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/clang/test/SemaCXX/warn-logical-not-compare.cpp b/clang/test/SemaCXX/warn-logical-not-compare.cpp index 280ab22d723..8b332c3c0e8 100644 --- a/clang/test/SemaCXX/warn-logical-not-compare.cpp +++ b/clang/test/SemaCXX/warn-logical-not-compare.cpp @@ -1,5 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -Wlogical-not-parentheses -verify %s -// RUN: %clang_cc1 -fsyntax-only -Wlogical-not-parentheses -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s +// RUN: not %clang_cc1 -fsyntax-only -Wlogical-not-parentheses -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s bool getBool(); int getInt(); @@ -189,6 +189,45 @@ bool test2 (E e) { return ret; } +bool test_bitwise_op(int x) { + bool ret; + + ret = !x & 1; + // expected-warning@-1 {{logical not is only applied to the left hand side of this bitwise operator}} + // expected-note@-2 {{add parentheses after the '!' to evaluate the bitwise operator first}} + // expected-note@-3 {{add parentheses around left hand side expression to silence this warning}} + // CHECK: warn-logical-not-compare.cpp:[[line:[0-9]*]]:9: warning + // CHECK: to evaluate the bitwise operator first + // CHECK: fix-it:"{{.*}}":{[[line]]:10-[[line]]:10}:"(" + // CHECK: fix-it:"{{.*}}":{[[line]]:15-[[line]]:15}:")" + // CHECK: to silence this warning + // CHECK: fix-it:"{{.*}}":{[[line]]:9-[[line]]:9}:"(" + // CHECK: fix-it:"{{.*}}":{[[line]]:11-[[line]]:11}:")" + ret = !(x & 1); + ret = (!x) & 1; + + // This warning is really about !x & FOO since that's a common misspelling + // of the negated bit test !(x & FOO). Don't warn for | and ^, since + // it's at least conceivable that the user wants to use | as an + // alternative to || that evaluates both branches. (The warning above is + // only emitted if the operand to ! is not a bool, but in C that's common.) + // And there's no logical ^. + ret = !x | 1; + ret = !(x | 1); + ret = (!x) | 1; + + ret = !x ^ 1; + ret = !(x ^ 1); + ret = (!x) ^ 1; + + // These already err, don't also warn. + !x &= 1; // expected-error{{expression is not assignable}} + !x |= 1; // expected-error{{expression is not assignable}} + !x ^= 1; // expected-error{{expression is not assignable}} + + return ret; +} + bool PR16673(int x) { bool ret; // Make sure we don't emit a fixit for the left paren, but not the right paren. |