tinfo.h (__class_type_info): Fix illegal declaration.
[gcc.git] / gcc / testsuite / g++.old-deja / g++.benjamin / tem03.C
1 // Build don't link:
2 // 980808-980824 bkoz
3 // template parameter redeclaration bugs
4
5 // 14.1 Template parameters
6 // p 13
7 // The scope of a template-parameter extens from its point of
8 // declartion until the end of its template. In particular, a
9 // template-parameter can be used in the declaration of subsequent
10 // template-parameters and their default arguments.
11
12 // 14.6.1 Locally declared names
13 // p 4
14 // A template-parameter shall not be redeclared within its scope
15 // (including nested scopes). A template-parameter shall not have the
16 // sname name as the template name.
17
18
19 // 01
20 // declared friend template
21 template <class T4>// ERROR - .*
22 class Xone {
23 protected:
24 T4* next;
25 T4* prev;
26 T4 value;
27 public:
28 Xone(): next(0), prev(0), value(1999){}
29 Xone(T4 init): value(init) {}
30
31 // these are ok:
32 // can also do template-decl and then can ditch the foward-declaration
33 // template <class T5> friend bool isequal (Xone<T5>& lhs, Xone<T5>& rhs);
34 // this is not ok:
35 template <class T4> friend bool isequal (Xone<T4>& lhs, Xone<T4>& rhs);// ERROR - .*
36 };
37
38
39 // 02
40 // nested template class
41 template <class T6>// ERROR - .*
42 class Xtwo {
43 protected:
44 T6* next;
45 T6* prev;
46 T6 value;
47 public:
48 Xtwo(): next(0), prev(0), value(1999){}
49 Xtwo(T6 init): value(init) {}
50
51 template <class T6> class nested {// ERROR - .*
52 T6 value;
53 public:
54 nested(): value( T6(0)) {}
55 };
56 };
57
58
59 // 03
60 // member templates
61 template <class T8>// ERROR - .*
62 class Xthree {
63 protected:
64 T8* next;
65 T8* prev;
66 T8 value;
67 public:
68 Xthree(): next(0), prev(0), value(1999){}
69 Xthree(T8 init): value(init) {}
70
71 template <class T8> T8 comp_ge(T8 test) {// ERROR - .*
72 T8 local_value;
73 if (local_value > value)
74 return local_value;
75 else
76 return value;
77 }
78 };
79
80
81 // 04
82 // local names (14.6.1 p 4)
83 template <class T10, int i> struct Xfour {// ERROR - .*
84 int T10; // ERROR - .*
85 void f(){
86 char T10;
87 }
88 };
89
90
91 // 05
92 // using different tempate-parms for out-of-line defs
93 template <class T12, int i> struct Xfive {
94 void f();
95 };
96
97 template <class T13, int i> void Xfive<T13,i>::f() {// ERROR - .*
98 int T13; // ERROR - .*
99 int T12; //should be ok
100 }
101
102
103 // 06
104 // multiple names at the same level
105 template <class T14, class T14> class Xsix { // ERROR - .*
106 private:
107 public:
108 void f();
109 };
110
111
112 // 07
113 // multiple names, one in template parameter one in class-name
114 template <class T12> class T12; // ERROR - .*
115
116
117 // 08
118 // with multiple template params, and second (third) one is redeclared
119 template <class T16, int i, class T161> class Xseven { // ERROR - .*
120 private:
121 char T161; // ERROR - .*
122 public:
123 template <class U>
124 friend bool fooy(U u);
125
126 template <class T161>
127 friend bool foo(T161 u)
128 {
129 Xseven<T161, 5, int> obj;
130 return (obj.inst == u.inst);
131 }
132
133 };
134
135
136 // 09
137 // check for correct scoping of member templates
138 template <class T>
139 struct S1
140 {
141 template <class U>
142 void f(U u)
143 {
144 S1<U> s2u(u);
145 s2u.g();
146 }
147
148 template <class U> //ok
149 void f2(U u)
150 {
151 S1<U> s2u(u);
152 s2u.g();
153 }
154
155 };
156
157
158 // 10
159 // check for non-type parameters, should still be able to redeclare?
160 // local names (14.6.1 p 4)
161 template <class T18, int i> class Xten {// ERROR - .*
162 float i; // ERROR - .*
163 };
164
165
166 // 11
167 // declared friend template, non-type parameters
168 template <long l>// ERROR - .*
169 class Xeleven {
170 public:
171 template <long l> friend bool isequal (Xeleven<5> lhs, Xeleven<5> rhs); // ERROR - .*
172 };
173
174
175
176 // 12
177 // nested template class, non-type parameters
178 template <long l>// ERROR - .*
179 class Xtwelve {
180 public:
181 template <long l> class nested {// ERROR - .
182 long value;
183 public:
184 nested(): value(0) {}
185 };
186 };
187
188
189 // 13
190 // member templates, non-type parameters
191 template <long l>// ERROR - .*
192 struct Xthirteen {
193 template <long l> long comp_ge(long test) {// ERROR - .
194 long local_value;
195 if (local_value > value)
196 return local_value;
197 else
198 return value;
199 }
200 };
201
202
203
204
205
206
207
208
209