[LLVMbugs] [Bug 18787] clang: Re-declaration of a local variable inside a for-loop is allowed

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Feb 9 23:11:31 PST 2014


jonathan.sauer at gmx.de changed:

           What    |Removed                     |Added
             Status|NEW                         |RESOLVED
                 CC|                            |jonathan.sauer at gmx.de
         Resolution|---                         |WORKSFORME

--- Comment #4 from jonathan.sauer at gmx.de ---
gcc 4.2.1 doesn't complain when specifying C99 as the standard (-std=c99). In
C89 (-std=c89) it (correctly) complains about "redeclaration of ā€˜iā€™ with no
linkage", because in C89 the definitions in the first clause of a for statement
are in the surrounding scope instead of the loop body's scope.

clang also complains when using C89:

% ~/LLVM/build/Release+Asserts/bin/clang -std=c89 clang.c
clang.c:5:14: error: redefinition of 'i'
    for (int i = 0; i < 100; ++i) { }
clang.c:3:9: note: previous definition is here
    int i;
1 error generated.

I guess gcc and clang use different C standards as default, which is why you
got the differing results.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140210/f0a4002c/attachment.html>

More information about the llvm-bugs mailing list