Skip to content

Clang MSVC and GNU C mode error: redefinition of 'index' as different kind of symbol #56607

Closed
@zufuliu

Description

@zufuliu

for following C code (see https://godbolt.org/z/rc1bzrY3s, related to issue #16513):

int index;

int get(void) {
	return index;
}

clang -std=gnu99 emits an error:

<source>:1:5: error: redefinition of 'index' as different kind of symbol
int index;
    ^
<source>:1:5: note: unguarded header; consider using #ifdef guards or #pragma once
<source>:1:5: note: previous definition is here
<source>:4:9: warning: incompatible pointer to integer conversion returning 'char *(const char *, int)' from a function with result type 'int' [-Wint-conversion]
        return index;
               ^~~~~
1 warning and 1 error generated.

however -std=gnu2x is OK.

while gcc -std=gnu99 emits a warning (also in -std=gnu2x mode):

<source>:1:5: warning: built-in function 'index' declared as non-function [-Wbuiltin-declaration-mismatch]
    1 | int index;
      |     ^~~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions