[cfe-dev] Compound Literal semantic analysis...

Chris Lattner clattner at apple.com
Fri Jan 11 13:13:25 PST 2008


On Jan 11, 2008, at 1:00 PM, Eli Friedman wrote:

> On Jan 11, 2008 12:34 PM, Steve Naroff <snaroff at apple.com> wrote:
>> In any event, now I understand why EDG/NEILCC allow my original
>> example (but not the revised example).
>
> I'm not sure I'm following... are EDG/NEILCC assuming that compound
> literals in initializers for static local variables have static
> storage duration?  It doesn't appear to be a legal extension per the
> spec, because the spec explicitly states that because they are within
> a function body, such compound literals have automatic storage
> duration.  clang could do the same thing as EDG/NEILCC's as an
> extension, since it doesn't break any compliant C99 programs, but it
> doesn't seem like an especially useful extension...

I agree with Eli here.  I don't understand why Neil and EDG are  
accepting the constant case.

Do they accept this?

void a(void) {
static int *a = &(int){1};    // implicit automatic variable.
}

GCC says "initializer element is not constant"

GCC also rejects this:

void a(void) {
static int *a = (int[]){1};
}

-chris



More information about the cfe-dev mailing list