Clang static analysis results for dmd

Don nospam at nospam.com
Sun Jul 31 02:47:26 PDT 2011


dennis luehring wrote:
> Am 29.07.2011 22:02, schrieb Walter Bright:
>> Here's another one:
>>
>>    T* p;
>>    ...
>>    if (A)
>>        p = &t;
>>    ...
>>    if (B)
>>        ... *p ...
>>
>> B is true if and only if A is true. B can even be the same expression as
>> A, such as a->b->c. Clang complains on the *p that p is "uninitialized".
>> Ok, so I rewrite as:
>>
>>    T* p = NULL;
>>    ...
>>    if (A)
>>        p = &t;
>>    ...
>>    if (B)
>>        ... *p ...
>>
>> but now clang says I'm dereferencing a NULL pointer. At this point, I'm
>> faced with some significant trial-and-error refactoring to get rid of
>> the message.
>>
>> At what point does this cease to be fixing "bugs" and become "contort to
>> fit clang's quirks"?
> 
> but your code does not reflect your "B is true if and only if A is
> true." statement

The example I posted was clearer.

Where p is just a variable:

if (!p) {  ... }
if (p) { ... }

it thinks that NEITHER of the code paths is taken.
I would rate that as a show-stopper bug. Don't waste any more time on 
clang until that's fixed.



More information about the Digitalmars-d mailing list