Aug 14, 2015

[gcc][C++] bug

bug in g++(still):
class Base{
protected:
static const int a{0};
};

class Derived1 : public Base{
};

class Derived2 : public Base{
public:
void bug(){
(void)Derived1::a; // g++ yells error: ‘const int Base::a’ is protected
}
};

int main(){
Derived2{}.bug();
}


A member m is accessible at the point R when named in class N if

m as a member of N is public, or
m as a member of N is private, and R occurs in a member or friend of class N, or
m as a member of N is protected, and R occurs in a member or friend of class N, or in a member of a class P derived from N, where m as a member of P is public, private, or protected, or
there exists a base class B of N that is accessible at R, and m is accessible at R when named in class B.

g++ compilation error “… is protected from within this context” while there's no error with clang

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.