r222009 - [Sema]. Warn when logical expression is a pointer

jahanian fjahanian at apple.com
Tue Nov 18 09:35:45 PST 2014



> On Nov 18, 2014, at 6:40 AM, Timur Iskhodzhanov <timurrrr at google.com> wrote:
> 
> $ cat test.cpp
> #define MY_ASSERT(cond) ((cond)? (void)0 : (void)1)
> #define BUG(description) MY_ASSERT(!description)
> 
> void foo (int some_condition)
> {
>   if (some_condition)
>     BUG("oh this is broken");
> }
> $ clang -Werror -Wstring-conversion -c test.cpp

I see, warning requires -Wstring-conversion  which is off by default.
This warning has always been there in c++ mode.
My patch has brought this warning to c. I think the warning is correct.
Can you fix the builedbot by casting the string to “const char*”?

- Fariborz

> test.cpp:7:9: error: implicit conversion turns string literal into bool:
>       'const char [18]' to 'bool' [-Werror,-Wstring-conversion]
>     BUG("oh this is broken");
>     ~~~~^~~~~~~~~~~~~~~~~~~~
> test.cpp:2:37: note: expanded from macro 'BUG'
> #define BUG(description) MY_ASSERT(!description)
>                                     ^
> test.cpp:1:27: note: expanded from macro 'MY_ASSERT'
> #define MY_ASSERT(cond) ((cond)? (void)0 : (void)1)
>                           ^
> 1 error generated.
> 
> On Mon Nov 17 2014 at 9:01:09 PM jahanian <fjahanian at apple.com <mailto:fjahanian at apple.com>> wrote:
> 
>> On Nov 17, 2014, at 7:18 AM, Timur Iskhodzhanov <timurrrr at google.com <mailto:timurrrr at google.com>> wrote:
>> 
>> Hi,
>> 
>> This has broken our -Werror internal build.
>> One specific thing that I consider a [noisy] false positive:
>> 
>> #define MY_ASSERT(cond) ((cond)? (void)0 : blah)
>> #define BUG(description) MY_ASSERT(!description)
>> ...
>> if (some_condition)
>>   BUG("oh this is broken")
> 
> 
> I cannot reproduce this warning. This is the test I used:
> 
> #define MY_ASSERT(cond) ((cond)? (void)0 : (void)1)
> #define BUG(description) MY_ASSERT(!description)
> 
> void foo (int some_condition)
> {
>   if (some_condition)
>     BUG("oh this is broken");
> }
> 
> Can you give a test case producing the warning?
> 
> - Fariborz
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141118/ecf6a824/attachment.html>


More information about the cfe-commits mailing list