[cfe-dev] Compound Literal semantic analysis...
Chris Lattner
clattner at apple.com
Fri Jan 11 09:54:49 PST 2008
>> C99 6.5.2.5p6 says the following:
>>
>> The value of the compound literal is that of an unnamed object
>> initialized by the
>> initializer list. If the compound literal occurs outside the body
>> of a
>> function, the object
>> has static storage duration; otherwise, it has automatic storage
>> duration associated with
>> the enclosing block.
>>
>> This seems pretty clear to me...GCC is right and EDG is wrong.
>>
>> Anyone disagree?
>
> I'm curious about your reasoning. My front end, which is pretty
> good about most things but a tad weak on compuond literals emits:
>
> neil at duron:~/src/c$ ../cfe/cfe /tmp/bug.c
> "/tmp/bug.c", line 3: error: expression must be a constant
> static int *t = &tmp; // Both GCC and EDG issue an error
> ^
> "/tmp/bug.c", line 4: warning: declaration hides function "a" declared
> at line 1
> static int *a = (int[]){1}; // GCC issues an error diagnostic for this
> ^
> "/tmp/bug.c", line 3: warning: variable "t" declared but not used
> static int *t = &tmp; // Both GCC and EDG issue an error
> ^
> "/tmp/bug.c", line 4: warning: variable "a" declared but not used
> static int *a = (int[]){1}; // GCC issues an error diagnostic for this
> ^
>
> 1 error found compiling "/tmp/bug.c".
>
> Which agrees with GCC and seems pretty reasonable to me :)
Compatibility with GCC isn't as important as compatibility with the
spec (i.e. we should accept this, but as an explicit extension). The
spec says:
"If the compound literal occurs outside the body of a
function, the object
has static storage duration; otherwise, it has automatic storage
duration associated with
the enclosing block."
Doesn't that preclude this example from being accepted, or does
"automatic storage" still mean it can be a constant somehow?
-Chris
More information about the cfe-dev
mailing list