[cfe-dev] "extern void v"

John McCall rjmccall at apple.com
Tue May 28 11:42:02 PDT 2013


On May 28, 2013, at 11:34 AM, Richard Smith <richard at metafoo.co.uk> wrote:
> On Sun, May 26, 2013 at 1:49 PM, John McCall <rjmccall at apple.com> wrote:
> On May 24, 2013, at 9:45 AM, Jordan Rose <jordan_rose at apple.com> wrote:
>> PR16131 describes an analyzer assertion on taking the address of an extern void variable:
>> 
>> extern void v;
>> static void f(void) {
>>         &v;
>> }
>> 
>> Clearly the analyzer shouldn't crash, but I'm surprised that this is legal at all. Yet I can't find anything in the standard actually forbidding it—you can certainly do the same thing with any incomplete struct type. Can somebody confirm that this is at least grammatically correct?
> 
> This is definitely well-formed.
> 
> In C, I think you're right. In C++, I think it's ill-formed (and gcc and EDG agree). In particular, 'void' is not an object type ([basic.types]p8), so 'v' cannot be a declaration of an object ([intro.object]p1), so it cannot be a declaration of a variable ([basic]p6). Therefore, the 'extern' keyword cannot be applied to the declaration of 'v' ([dcl.stc]p6).

Yes, I agree, it should only be legal in C.  Are we allowing it in C++?

John.



More information about the cfe-dev mailing list