r373743 - [NFCI] Improve the -Wbool-operation's warning message

Nico Weber via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 7 07:54:09 PDT 2019


FWIW I found the "always evaluates to 'true'" bit important to understand
the warning.

We did hit this (at least once) in Chromium after all [1] (looks like a
real bug – nothing for you to do about that, and thanks for the warning),
and I don't think I would've understood what the warning wanted from me if
I hadn't seen the old warning text in the commit.

[1]: https://bugs.chromium.org/p/chromium/issues/detail?id=1011810

On Fri, Oct 4, 2019 at 8:53 AM David Bolvansky via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> Author: xbolva00
> Date: Fri Oct  4 05:55:13 2019
> New Revision: 373743
>
> URL: http://llvm.org/viewvc/llvm-project?rev=373743&view=rev
> Log:
> [NFCI] Improve the -Wbool-operation's warning message
>
> Based on the request from the post commit review. Also added one new test.
>
>
> Modified:
>     cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>     cfe/trunk/test/Sema/warn-bitwise-negation-bool.c
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=373743&r1=373742&r2=373743&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Oct  4
> 05:55:13 2019
> @@ -6638,7 +6638,7 @@ def note_member_declared_here : Note<
>  def note_member_first_declared_here : Note<
>    "member %0 first declared here">;
>  def warn_bitwise_negation_bool : Warning<
> -  "bitwise negation of a boolean expression always evaluates to 'true'">,
> +  "bitwise negation of a boolean expression; did you mean a logicial
> negation?">,
>    InGroup<DiagGroup<"bool-operation">>;
>  def err_decrement_bool : Error<"cannot decrement expression of type
> bool">;
>  def warn_increment_bool : Warning<
>
> Modified: cfe/trunk/test/Sema/warn-bitwise-negation-bool.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-bitwise-negation-bool.c?rev=373743&r1=373742&r2=373743&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Sema/warn-bitwise-negation-bool.c (original)
> +++ cfe/trunk/test/Sema/warn-bitwise-negation-bool.c Fri Oct  4 05:55:13
> 2019
> @@ -12,9 +12,11 @@ typedef _Bool boolean;
>  #endif
>
>  void test(boolean b, int i) {
> -  b = ~b; // expected-warning {{bitwise negation of a boolean expression
> always evaluates to 'true'}}
> +  b = ~b; // expected-warning {{bitwise negation of a boolean expression;
> did you mean a logicial negation?}}
>    // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!"
> -  b = ~(b); // expected-warning {{bitwise negation of a boolean
> expression always evaluates to 'true'}}
> +  b = ~(b); // expected-warning {{bitwise negation of a boolean
> expression; did you mean a logicial negation?}}
>    // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!"
>    b = ~i;
> +  i = ~b; // expected-warning {{bitwise negation of a boolean expression;
> did you mean a logicial negation?}}
> +  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!"
>  }
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191007/8ca8571e/attachment.html>


More information about the cfe-commits mailing list