This is GCC Bugzilla
This is GCC Bugzilla Version 2.20+
View Bug Activity | Format For Printing | Clone This Bug
// Illegal access to private member not detected, program compiles silently. // bug found in: // g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44) // g++ (Ubuntu 4.3.3-5ubuntu4) 4.3.3 #include <iostream> class A { enum { value=1 }; // private }; template <int i> // bug appears only if B is a template struct B { enum { value=A::value }; // <- silently access private member }; int main() { std::cout << B<1>::value << std::endl; return 0; }
I think this is a duplicate of bug 21008.
(In reply to comment #1) > I think this is a duplicate of bug 21008. > Not shure, A::value may not be accessible neither at the template definition, nor at the instantiation time.
Also present in gcc 4.4.0
// More similar cases. Static members also may be accessed #include <iostream> class A { enum { value=1 }; // private static const int ci=2; static int fi() { return 3; } }; template <int i> // bug appears only if B is a template struct B { enum { value=A::value }; // <- silently access private member // enum { v2=A::ci }; // this error is detected @ any instantiation static const int v3=A::value; // not detected static const int v4=A::ci; // not detected static int f5() { return A::value; } // not detected static int f6() { return A::ci; } // detected only if f6() accessed static int f7() { return A::fi(); } // detected only if f7() accessed, reported twice }; int main() { std::cout << B<1>::value << B<1>::v3 << B<1>::v4 << B<1>::f5() // << B<1>::f6() // error will be detected // << B<1>::f7() // error will be detected, and reported TWICE << std::endl; return 0; }