[cfe-dev] Protected union member not visible in derived class

John McCall rjmccall at apple.com
Thu May 10 11:45:43 PDT 2012


On May 10, 2012, at 9:09 AM, Richtarsky, Martin wrote:
> I have this test program:
> 
> ---
> class A
> {
> public:
>    union {
>        const char* ptr1;
>    };
> protected:
>    union {
>        const char* ptr2;
>    };
> };
> 
> class B: public A
> {
> public:
>    void f()
>    {
>        A::ptr1 = 0;  // works
>        A::ptr2 = 0;  // doesn't work
>    }
> };
> ---
> 
> which throws this error during compilation using current trunk:
> 
> /tmp/prot_access.cpp:19:12: error: 'ptr2' is a protected member of 'A'
>        A::ptr2 = 0;  // doesn't work
>           ^
> /tmp/prot_access.cpp:9:21: note: must name member using the type of the current context 'B'
>        const char* ptr2;
>                    ^
> 
> 
> The protected union member of the base class is not visible in B. Is there something in the standard that mandates this, or should I file a bug?

It's a bug;  the access logic is not "looking through" anonymous struct and union members correctly when imposing the class.protected restriction.

John.



More information about the cfe-dev mailing list