xref: /llvm-project/clang/test/CXX/class.access/class.access.nest/p1.cpp (revision 3155f573f5ad55a4838d7ea73bfa819ef6be82d3)
1*3155f573SJohn McCall // RUN: %clang_cc1 -fsyntax-only -verify %s
2fb803d7dSJohn McCall 
3fb803d7dSJohn McCall // Derived from GNU's std::string
4fb803d7dSJohn McCall namespace test0 {
5fb803d7dSJohn McCall   class A {
6fb803d7dSJohn McCall     struct B {
7fb803d7dSJohn McCall       unsigned long length;
8fb803d7dSJohn McCall     };
9fb803d7dSJohn McCall     struct C : B {
10fb803d7dSJohn McCall       static const unsigned long max_length;
11fb803d7dSJohn McCall     };
12fb803d7dSJohn McCall   };
13fb803d7dSJohn McCall 
14fb803d7dSJohn McCall   const unsigned long A::C::max_length = sizeof(B);
15fb803d7dSJohn McCall }
16fb803d7dSJohn McCall 
17fb803d7dSJohn McCall // Example from the standard.
18fb803d7dSJohn McCall namespace test1 {
19fb803d7dSJohn McCall   class E {
20fb803d7dSJohn McCall     int x;
21fb803d7dSJohn McCall     class B {};
22fb803d7dSJohn McCall 
23fb803d7dSJohn McCall     class I {
24fb803d7dSJohn McCall       B b;
25fb803d7dSJohn McCall       int y; // expected-note {{declared private here}}
f(E * p,int i)26fb803d7dSJohn McCall       void f(E* p, int i) {
27fb803d7dSJohn McCall         p->x = i;
28fb803d7dSJohn McCall       }
29fb803d7dSJohn McCall     };
30fb803d7dSJohn McCall 
g(I * p)31fb803d7dSJohn McCall     int g(I* p) { return p->y; } // expected-error {{'y' is a private member of 'test1::E::I'}}
32fb803d7dSJohn McCall   };
33fb803d7dSJohn McCall }
34