[llvm-bugs] [Bug 42240] New: variable previously declared `static' redeclared `extern' is valid ISO C - 3.4 and 4.0

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jun 11 17:15:34 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=42240

            Bug ID: 42240
           Summary: variable previously declared `static' redeclared
                    `extern' is valid ISO C - 3.4 and 4.0
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: zhonghao at pku.org.cn
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

This testcase:

static int i;

void f ()
{
  extern int i;
}

is rejected by clang 9.0.0:

source>:2:26: error: redefinition of 'in_toc' as different kind of symbol

int f(void) { extern int in_toc; }

                         ^

<source>:1:19: note: previous definition is here

enum in_section { in_toc };

                  ^

1 error generated.

Compiler returned: 1

The ISO 9899:1990 standard says in 6.1.2.2 Linkages of identifiers:

If the declaration of an identifier for an object or a function contains the
storage class specifier extern, the identifier has the same linkage as any
visible declaration of the identifier with file scope.

Therefore, for 9899:1990 both my testcase should pass.

In ISO 9899:1999 6.2.2 Linkage of identifiers 4 it says:

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 daclaration is the same as the linkage specified
at the prior declaration.  If no prior declaration is visible, or if the
prior declaration specifies no linkage, then the identifer has external
linkage.
... 7 If, within a translation unit, the same identifier appears both with
internal and external linkage, the behaviour is undefined.

Thus, for ISO 9899:1999, my testcase should still pass.

-- 
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/20190612/f5515d98/attachment.html>


More information about the llvm-bugs mailing list