[cfe-commits] [Patch] Extend -Wliteral-conversion to warn on string literals to bool conversion

Richard Trieu rtrieu at google.com
Tue Sep 20 21:18:30 PDT 2011


On Tue, Sep 13, 2011 at 5:54 PM, Richard Trieu <rtrieu at google.com> wrote:
> On Fri, Sep 9, 2011 at 4:13 PM, Richard Trieu <rtrieu at google.com> wrote:
>> Add a new warning and bundle it into -Wliteral-conversion.  This
>> warning triggers on cases where a string literal is implicitly
>> converted to a bool.  For the common case of:
>>
>> assert(condition && "Error text");
>>
>> an exception for string literals in logical operations has also been included.
>>
>
> Currently, the patch has this new warning bundled in with
> -Wliteral-conversion.  It's been brought up that -Wbool-conversions
> might be a more suitable place for this warning.  Any thoughts on
> this?
>

A few changes to the new warning and catching a few more things in
LLVM/Clang.  Now, it should be able to catch string literal to bool in
if, while, do-while, and for statements and in function calls.
r140232 & r140234 were minor changes caught by this warning, basically
changing assert(!"error") to assert(0 && "error").  r140231 was a
change for a string argument for a bool parameter in a function call.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: string-literal-to-bool2.patch
Type: text/x-patch
Size: 4247 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110920/6e4059bc/attachment.bin>


More information about the cfe-commits mailing list