[cfe-dev] Compound Literal semantic analysis...
Steve Naroff
snaroff at apple.com
Fri Jan 11 12:34:01 PST 2008
On Jan 11, 2008, at 12:22 PM, Eli Friedman wrote:
> On Jan 11, 2008 11:38 AM, Steve Naroff <snaroff at apple.com> wrote:
>> void a(void) {
>> int explicit;
>> int anylocal;
>> static int *t = &explicit; // error for explicit automatic
>> variables.
>> static int *a = (int[]){anylocal}; // implicit automatic variable.
>> EDG and NEILCC permit this, while GCC error.
>> }
>>
>> Is my analogy flawed? Since the compound literal can refer to any
>> local variable, I don't see how it could ever be constant...
>
> http://www.comeaucomputing.com/tryitout/ over the following:
>
> void a(void) {
> int anylocal;
> static int *a = (int[]){anylocal};
> }
>
> gives the following (in C99 mode):
>
> "ComeauTest.c", line 3: error: expression must have a constant value
> static int *a = (int[]){anylocal};
> ^
>
> "ComeauTest.c", line 3: warning: variable "a" was declared but never
> referenced
> static int *a = (int[]){anylocal};
>
> What were you testing with?
I never tested the example above. I just tested my original example
(which had a constant, not a variable reference).
In any event, now I understand why EDG/NEILCC allow my original
example (but not the revised example).
I guess clang should only complain if the expression isn't constant.
It appears my analogy was flawed and GCC is incorrect...
snaroff
>
>
> -Eli
More information about the cfe-dev
mailing list