[PATCH] Extend -Wint-in-bool-context to warn for multiplications

Bernd Edlinger bernd.edlinger@hotmail.de
Sun Oct 23 11:31:00 GMT 2016


On 10/22/16 08:52, Bernd Edlinger wrote:
> On 10/22/16 04:17, Martin Sebor wrote:
>> On 10/21/2016 04:37 PM, Joseph Myers wrote:
>>> The quoting in the diagnostic should be %<&&%>, not '&&'.
>>
>> Presumably same for '*' (i.e., %<*%>).
>>
>> But I would actually suggest a somewhat more formal phrasing than
>> "better use xxx here" such as "suggest %<&&%> instead" or something
>> akin to what's already in place elsewhere in gcc.pot.
>>
>
> Aehm, yes.  That would be better then:
>
>
> Index: c-common.c
> ===================================================================
> --- c-common.c    (revision 241400)
> +++ c-common.c    (working copy)
> @@ -3327,6 +3327,11 @@
>      return c_common_truthvalue_conversion (location,
>                             TREE_OPERAND (expr, 0));
>
> +    case MULT_EXPR:
> +      warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
> +          "%<*%> in boolean context, suggest %<&&%> instead");
> +      break;
> +
>      case LSHIFT_EXPR:
>        /* We will only warn on signed shifts here, because the majority of
>       false positive warnings happen in code where unsigned arithmetic
>
>
> I assume then I should adjust the warning a few lines below as well:
>
>         warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
>                     "<< in boolean context, did you mean '<' ?");
>
>

Attached is the updated patch with those quotes fixed.

I have now put the << and < in correct quotes, but left the ?: in
the next two warnings unquoted:

  "?: using integer constants in boolean context, "
  "the expression will always evaluate to %<true%>"

I copied that style from the warning about omitted middle operand of
conditional expressions:

"the omitted middle operand in ?: will always be %<true%>, suggest 
explicit "
"middle operand"

I think that could be explained because ?: is not really a keyword
like <<, and is just a shorter phrase than "conditional expression".


Bootstrapped and reg-tested on x86_64-pc-linux-gnu.
Is it OK for trunk?


Thanks
Bernd.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch-bool-context5.diff
Type: text/x-patch
Size: 3816 bytes
Desc: patch-bool-context5.diff
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20161023/e3e20e8b/attachment.bin>


More information about the Gcc-patches mailing list