llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.68k stars 11.86k forks source link

struct definition leaks out of function prototype scope #39272

Open ebdd6ebc-1612-4e9b-aee1-f7d2b6361d5f opened 5 years ago

ebdd6ebc-1612-4e9b-aee1-f7d2b6361d5f commented 5 years ago
Bugzilla Link 39925
Version trunk
OS All
CC @zygoloid

Extended Description

The following C11 program (prog.c) should compile without error:

struct T;

void f( struct S { struct T { int a; } *b; } );

struct T { int c; };

int main() { }

When I compile it with clang prog.c -std=c11 -pedantic-errors "-w" i get the following unexpected error:

error: redefinition of 'T'

This is wrong since the struct definition inside the function declaration has function prototype scope and therefore should be independent of the struct definition in the file scope.

Online compiler link:

https://wandbox.org/permlink/UpaD0znT5jkohSNP

Note that gcc does not give any errors.

AaronBallman commented 1 year ago

The issue still reproduces as of Clang 16.0.0: https://gcc.godbolt.org/z/7zeKdEYPT

Interesting to note that removing the forward declaration on line 1 causes the diagnostic to go away, so I suspect the issue has to do with redeclaration merging.

llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-frontend

llvmbot commented 1 year ago

@llvm/issue-subscribers-c