[LLVMbugs] [Bug 10433] New: clang fails with internal linkage, 'extern' at block scope and tentative definitions.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Jul 21 11:58:06 PDT 2011


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

           Summary: clang fails with internal linkage, 'extern' at block
                    scope and tentative definitions.
           Product: clang
           Version: 2.9
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: nbowler at draconx.ca
                CC: llvmbugs at cs.uiuc.edu


According to C99ยง6.2.2#4:

  For an identifier declared with the storage-class specifier extern in a scope
  in which a prior declaration of that identifier is visible, if the prior
  declaration specifies internal or external linkage, the linkage of the
  identifier at the later declaration is the same as the linkage specified at
  the prior declaration.

However, clang does not seem to handle this properly at block scope if the only
earlier declarations with internal linkage are also tentative definitions, as
in the following program:

  /* Tentative definition of x; declares x with internal linkage. */
  static int x;

  int main(void)
  {
    /*
     * A prior declaration of x with internal linkage is visible, so this
     * declares x with internal linkage, too.
     */
    extern int x;

    return x;
  }

  /* Definition of x, again with internal linkage. */
  static int x = 42;

Attempting to compile this with clang yields an error:

  % clang -std=c99 -pedantic test.c
  test.c:16:12: error: static declaration of 'x' follows non-static declaration
  static int x = 42;
             ^
  test.c:10:14: note: previous definition is here
    extern int x;
               ^
  1 error generated.

The problems go away if the 'static int x = 42;' is moved above the declaration
of main, or if the 'extern int x;' is moved outside of main to file scope.

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