[cfe-dev] Compound Literal semantic analysis...
Neil Booth
neil at daikokuya.co.uk
Fri Jan 11 08:21:47 PST 2008
Steve Naroff wrote:-
> Folks,
>
> Eli and I have been on improving clang's support for Compound Literals.
>
> GCC and EDG produce different diagnostics for the following program.
>
> void a(void) {
> int tmp;
> static int *t = &tmp; // Both GCC and EDG issue an error
> diagnostic ("initializer element is not constant").
> static int *a = (int[]){1}; // GCC issues an error diagnostic for this
> as well (but EDG allows it).
> }
>
> 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 :)
Neil.
More information about the cfe-dev
mailing list