Sample code (t0.c):
static int arr[ ];
int main( void )
{
return arr[ 0 ];
}
static int arr[ ] = { 0 };
Invocations:
$ gcc t0.c -std=c11 -Wall -Wextra
<nothing>
$ clang t0.c -std=c11 -Wall -Wextra
<nothing>
$ cl t0.c /std:c11 /Za
t0.c(1): error C2133: 'arr': unknown size
$ gcc t0.c -std=c11 -Wall -Wextra -pedantic
t0.c:1:12: error: array size missing in ‘arr’
$ clang t0.c -std=c11 -Wall -Wextra -pedantic
<nothing>
C11, 6.2.5 Types, 22:
An array type of unknown size is an incomplete type. It is completed, for an identifier of that type, by specifying the size in a later declaration (with internal or external linkage).
C11, 6.9.2 External object definitions, 3:
If the declaration of an identifier for an object is a tentative definition and has internal linkage, the declared type shall not be an incomplete type.
C11, J.2 Undefined behavior, 1:
An identifier for an object with internal linkage and an incomplete type is declared with a tentative definition (6.9.2).
Question: Why do conforming implementations show different behavior? Which one behaves correctly?
UPD1. Created https://bugs.llvm.org/show_bug.cgi?id=51319.