150397Sobrien// Build don't link:
250397Sobrien// 980808-980824 bkoz
350397Sobrien// template parameter redeclaration bugs
450397Sobrien
550397Sobrien// 14.1 Template parameters
650397Sobrien// p 13
750397Sobrien// The scope of a template-parameter extens from its point of
850397Sobrien// declartion until the end of its template. In particular, a
950397Sobrien// template-parameter can be used in the declaration of subsequent
1050397Sobrien// template-parameters and their default arguments.
1150397Sobrien
1250397Sobrien// 14.6.1 Locally declared names
1350397Sobrien// p 4
1450397Sobrien// A template-parameter shall not be redeclared within its scope
1550397Sobrien// (including nested scopes). A template-parameter shall not have the
1650397Sobrien// sname name as the template name.
1750397Sobrien
1850397Sobrien
1950397Sobrien// 01
2050397Sobrien// declared friend template
2150397Sobrientemplate <class T4>// ERROR - .*
2250397Sobrienclass Xone {
2350397Sobrienprotected:
2450397Sobrien  T4* next;
2550397Sobrien  T4* prev;
2650397Sobrien  T4 value;
2750397Sobrienpublic:
2850397Sobrien  Xone(): next(0), prev(0), value(1999){}
2950397Sobrien  Xone(T4 init): value(init) {}
3050397Sobrien
3150397Sobrien  // these are ok:
3250397Sobrien  // can also do template-decl and then can ditch the foward-declaration
3350397Sobrien  // template <class T5> friend bool isequal (Xone<T5>& lhs, Xone<T5>& rhs);
3450397Sobrien  // this is not ok:
3550397Sobrien  template <class T4> friend bool isequal (Xone<T4>& lhs, Xone<T4>& rhs);// ERROR - .*
3650397Sobrien};
3750397Sobrien
3850397Sobrien
3950397Sobrien// 02
4050397Sobrien// nested template class
4150397Sobrientemplate <class T6>// ERROR - .*
4250397Sobrienclass Xtwo {
4350397Sobrienprotected:
4450397Sobrien  T6* next;
4550397Sobrien  T6* prev;
4650397Sobrien  T6 value;
4750397Sobrienpublic:
4850397Sobrien  Xtwo(): next(0), prev(0), value(1999){}
4950397Sobrien  Xtwo(T6 init): value(init) {}
5050397Sobrien
5150397Sobrien  template <class T6> class nested {// ERROR - .*
5250397Sobrien    T6 value;
5350397Sobrien  public:
5450397Sobrien    nested(): value( T6(0)) {}
5550397Sobrien  };
5650397Sobrien};
5750397Sobrien
5850397Sobrien
5950397Sobrien// 03
6050397Sobrien// member templates
6150397Sobrientemplate <class T8>// ERROR - .*
6250397Sobrienclass Xthree {
6350397Sobrienprotected:
6450397Sobrien  T8* next;
6550397Sobrien  T8* prev;
6650397Sobrien  T8 value;
6750397Sobrienpublic:
6850397Sobrien  Xthree(): next(0), prev(0), value(1999){}
6950397Sobrien  Xthree(T8 init): value(init) {}
7050397Sobrien
7150397Sobrien  template <class T8> T8 comp_ge(T8 test) {// ERROR - .*
7250397Sobrien    T8 local_value;
7350397Sobrien    if (local_value > value)
7450397Sobrien      return local_value;
7550397Sobrien    else
7650397Sobrien      return value;
7750397Sobrien  }
7850397Sobrien};
7950397Sobrien
8050397Sobrien
8150397Sobrien// 04
8250397Sobrien// local names (14.6.1 p 4)
8350397Sobrientemplate <class T10, int i> struct Xfour {// ERROR - .*
8450397Sobrien  int T10; // ERROR - .*
8550397Sobrien  void f(){
8650397Sobrien    char T10;
8750397Sobrien  }
88};
89
90
91// 05
92// using different tempate-parms for out-of-line defs
93template <class T12, int i> struct Xfive {
94  void f();
95};
96
97template <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
105template <class T14, class T14> class Xsix { // ERROR - .*
106private:
107public:
108  void f();
109};
110
111
112// 07
113// multiple names, one in template parameter one in class-name
114template <class T12> class T12; // ERROR - .*
115
116
117// 08
118// with multiple template params, and second (third) one is redeclared
119template <class T16, int i, class T161> class Xseven { // ERROR - .*
120private:
121  char T161; // ERROR - .*
122public:
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
138template <class T>
139struct 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)
161template <class T18, int i> class Xten {// ERROR - .*
162  float i; // ERROR - .*
163};
164
165
166// 11
167// declared friend template, non-type parameters
168template <long l>// ERROR - .*
169class Xeleven {
170public:
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
178template <long l>// ERROR - .*
179class Xtwelve {
180public:
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
191template <long l>// ERROR - .*
192struct 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
210