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

            Bug ID: 18046
           Summary: uninitialized warning refers to practically irrelevant
                    code
           Product: clang
           Version: trunk
          Hardware: PC
                OS: FreeBSD
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

1. Source code (x.c):

int main(void)
{
    for(const char *p = ""; p; ) { }
    for(const char *q; (q = q + 1); ) { }
}

2. Command line:

clang -Wall x.c

3. Output:

x.c:3:26: warning: variable 'q' is used uninitialized whenever 'for' loop exits
because its condition is false [-Wsometimes-uninitialized]
        for(const char *p = ""; p; ) { }
                                ^
x.c:4:26: note: uninitialized use occurs here
        for(const char *q; (q = q + 1); ) { }
                                ^
x.c:3:26: note: remove the condition if it is always true
        for(const char *p = ""; p; ) { }
                                ^
x.c:4:19: note: initialize the variable 'q' to silence this warning
        for(const char *q; (q = q + 1); ) { }
                         ^
                          = 0
1 warning generated.

4. Notes:

   a) Using ``++q'' instead of ``(q = q + 1)'' causes the reference to the
other loop to go away (the uninitialized warning for ``q'' is still given).

   b) If ``q'' is instead created and used (without initialization) in a
non-loop block (eg., ``{ const char *q; (q = q + 1); }''), then the reference
also goes away.

   c) Changing the condition of the 1st loop to ``1'' (always true) causes the
said warnings to go away.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to