"extern void v"

PR16131 describes an analyzer assertion on taking the address of an extern void variable:

extern void v;
static void f(void) {

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?

(I suppose like an incomplete object it provides a way to name an address without allowing access.)


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++?