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

Richtarsky, Martin martin.richtarsky at sap.com
Thu May 10 09:09:03 PDT 2012


Hi all,


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?

Best regards,
Martin




More information about the cfe-dev mailing list