[LLVMbugs] [Bug 10013] New: Scope of extern declarations extend past enclosing block

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed May 25 13:56:27 PDT 2011


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

           Summary: Scope of extern declarations extend past enclosing
                    block
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: rgamble99 at gmail.com
                CC: llvmbugs at cs.uiuc.edu


When multiple extern declarations for an identifier exist at block scope, the
scope of the declaration incorrectly extends past the block containing the
declaration.

For example, the following program prints 10 instead of 20 when compiled with
clang:

    #include <stdio.h>

    int i = 10;

    int main(void) {
        int i = 20;
        {
            extern int i;
            extern int i;
        }
        printf("%d\n", i);
        return 0;
    }

If one of the "extern int i;" lines is removed, 20 will be printed.  gcc and
Intel print 20 both cases.  The same issue occurs if the second extern
declaration is in a nested block:

    #include <stdio.h>

    int i = 10;

    int main(void) {
        int i = 20;
        {
            extern int i;
            {
                extern int i;
            }
        }

        printf("%d\n", i);
        return 0;
    }

This was tested with clang version 3.0 (trunk 131958).

-- 
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