[LLVMbugs] [Bug 7100] New: False accusation of NULL-ness after ingenious control flow

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sat May 8 12:39:45 PDT 2010


http://llvm.org/bugs/show_bug.cgi?id=7100

           Summary: False accusation of NULL-ness after ingenious control
                    flow
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: jyasskin at google.com
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com,
                    zhanyong.wan at gmail.com


$ cat test.cc
#include <stdio.h>
int main() {
    puts(0);  // Generates the first line, containing "(null)"
    if (const char* msg = "") {
        goto label;
    } else
    label:
        puts(msg);  // Generates the second line, blank
}
$ clang++ test.cc -o test -Wall
test.cc:8:14: warning: 'msg' is always NULL in this context
        puts(msg);
             ^
1 warning generated.
$ ./test
(null)

$ 


Note that msg will always be non-NULL (""), so the if branch will be taken. It
then jumps into the else branch and uses msg, so msg will never be NULL,
contrary to the warning.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list