[cfe-dev] C++: Reference to member in sizeof expression of another member declaration

Florian Weimer fweimer at redhat.com
Sun May 12 21:59:05 PDT 2013


On 05/13/2013 01:41 AM, Richard Smith wrote:
> On Sun, May 12, 2013 at 1:18 AM, Florian Weimer <fweimer at redhat.com
> <mailto:fweimer at redhat.com>> wrote:
>
>     clang++ (trunk, both C++03 and C++11 modes) rejects the following
>     program:
>
>     union u {
>        int a;
>        char b[sizeof(a)];
>     };
>
>     t.cpp:3:17: error: invalid use of non-static data member 'a'
>        char b[sizeof(a)];
>                      ^
>
>     This seems valid C++, considering this language in
>     [expr.prim.general]: "An id-expression that denotes a non-static
>     data member […] can only be used […] if that id-expression […]
>     appears in an unevaluated operand"
>
>
> Trunk accepts this for me in C++11, and rejects in C++98, which IIRC is
> correct behavior.

You are right, I found the matching location in the C++98 standard and 
it does not contain the exception for unevaluated operands.

-- 
Florian Weimer / Red Hat Product Security Team



More information about the cfe-dev mailing list