2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.benjamin / scope02.C
blob1ff541b88464a64f4c7efe2c8a9d2ea5c3f4bb91
1 // { dg-do assemble  }
2 //980529 bkoz
3 //3.4.5 Class member access via pointer and non-pointer
4 // non-nested dtor calls
6 int counter = 0;
8 struct X {
9   int rank;
10   X(int init = 64) : rank(init) { }
11   ~X() { ++counter; }
12   typedef X classtype;
14 typedef X globaltype;
16 #if 0
17 template <typename T>
18 struct X_tem {
19   T rank;
20   X_tem(T init = T(64) ) : rank(init) { }
21   ~X_tem() { ++counter; }
22   typedef X_tem classtype_tem;
24 typedef X_tem<int> globaltype_tem;
25 #endif
30 int main(void)
32   // 3.4.5 Class member access
33   // p 2
34   // if the id-expression in a class member access is an
35   // unqualified-id, and the type of the object expression is of class
36   // type C (or pointer to class type C), the unqualified-id is looked
37   // up in the scope of class C. If the type of the object-expression
38   // is of pointer to scalar type, the unqualified-id is looked up in
39   // the context of the complete postfix-expression.
41   // p 3
42   // if the unqualitified id is ~type-name, and the type of the object
43   // expression is of a class type C (or pointer to class type C), the
44   // type-name is looked up in the context of the entire
45   // postfix-expression and in the scope of class C. The type-name
46   // shall refer to a class-name. If type-name is found in both
47   // contexts, the name shall refer to the same class type. If the
48   // type of the object expression is of scalar type, the type-name is
49   // looked up in the complete postfix-expression.
50   
51   typedef X localtype;
53   //
54   // 1 non-templatized, pointer, unqualified
55   //
56   X x01 ;
57   X *px = &x01;
58   px->~X(); 
60   X x02 (66);
61   px = &x02;
62   px->~localtype();
64   X x03 (68);
65   px = &x03;
66   px->~classtype(); //-g++  //p3: unqual-id lookup in object and postfix-expr
68   X x04 (70);
69   px = &x04;
70   px->~globaltype();
73   // p 1
74   // . . . the id-expression is first looked up in the class of the
75   // object-expression. If the identifier is not found, itis then
76   // looked up in the context of the entier postfix-expression and
77   // shall name a class or function template. If the lookup in the
78   // class of the object-expression finds a template, the name is also
79   // looked up in teh context of the entier postfix-expression and
80   // 1 if the name is not found, use the name from the object-expr
81   // 2 if the name found in postfix-expr != class template, use object-expr
82   // 3 if name found is class template, name must match object-expr or error
84   // p 4 
86   // if the id-expr in a class member acess is a qualified-id, the
87   // id-expression is looked up in both the context of the entire
88   // postfix-expr and in the scope of the class of the object-expr. If
89   // the name is found in both contexts, the id-expr shall refer to
90   // the same entity.
93   //
94   // 2 non-templatized, pointer, qualified
95   //
96   X x05 ;
97   px = &x05;
98   px->X::~X(); 
100   X x06 (66);
101   px = &x06;
102   px->X::~localtype();
104   X x07 (68);
105   px = &x07;
106   px->X::~classtype(); // -edg
108   X x08 (70);
109   px = &x08;
110   px->X::~globaltype();
112   X x09 (66);
113   px = &x09;
114   px->localtype::~localtype();
116   X x10 (68);
117   px = &x10;
118   px->classtype::~classtype();
120   X x11 (70);
121   px = &x11;
122   px->globaltype::~globaltype();
124   X x12 (66);
125   px = &x12;
126   px->classtype::~localtype();
128   X x13 (68);
129   px = &x13;
130   px->globaltype::~localtype();
132   X x14 (70);
133   px = &x14;
134   px->localtype::~globaltype();
136   X x15 (70);
137   px = &x15;
138   px->classtype::~globaltype();
140   X x16 (70);
141   px = &x16;
142   px->localtype::~classtype(); //-edg
144   X x17 (70);
145   px = &x17;
146   px->globaltype::~classtype(); //-edg
148 #if 0
149   //
150   // non-templatized, non-pointer
151   //
152   X xo5 ;
153   xo5.~X(); //unqualified
155   localtype xo6 (66);
156   xo6.~localtype();
158   X xo7 (68);
159   xo7.~classtype();
161   X xo8 (70);
162   xo8.~globaltype();
165   //
166   // templatized, pointer
167   //
168   X_tem<int> xto1 ;
169   X_tem<int> *pxt = &xto1;
170   pxt->~X_tem(); //unqualified
172   typedef X_tem<int> localtype_tem;
173   localtype_tem xto2 (66);
174   pxt = &xto2;
175   pxt->~localtype_tem();
177   //paragraph 2:  unqualitifed id looked up in scope of post-fix expr if object
178   X_tem<int> xto3 (68);
179   pxt = &xto3;
180   pxt->~classtype_tem();
182   X_tem<int> xto4 (70);
183   pxt = &xto4;
184   pxt->~globaltype_tem();
186   //
187   // templatized, non-pointer
188   //
189   X_tem<int> xto5 ;
190   xto5.~X_tem(); //unqualified
192   localtype_tem xto6 (66);
193   xto6.~localtype_tem();
195   X_tem<int> xto7 (68);
196   xto7.~classtype_tem();
198   X_tem<int> xto8 (70);
199   xto8.~globaltype_tem();
200 #endif
201   return 0;