[cfe-dev] "extern void v"

Richard Smith richard at metafoo.co.uk
Tue May 28 11:34:49 PDT 2013


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 <http://llvm.org/bugs/show_bug.cgi?id=16131> 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).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130528/22ae4702/attachment.html>


More information about the cfe-dev mailing list