1// { dg-do assemble  }
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
21template <class T4>// { dg-error "" } .*
22class Xone {
23protected:
24  T4* next;
25  T4* prev;
26  T4 value;
27public:
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);// { dg-error "" } .*
36};
37
38
39// 02
40// nested template class
41template <class T6>// { dg-error "" } .*
42class Xtwo {
43protected:
44  T6* next;
45  T6* prev;
46  T6 value;
47public:
48  Xtwo(): next(0), prev(0), value(1999){}
49  Xtwo(T6 init): value(init) {}
50
51  template <class T6> class nested {// { dg-error "" } .*
52    T6 value;
53  public:
54    nested(): value( T6(0)) {}
55  };
56};
57
58
59// 03
60// member templates
61template <class T8>// { dg-error "" } .*
62class Xthree {
63protected:
64  T8* next;
65  T8* prev;
66  T8 value;
67public:
68  Xthree(): next(0), prev(0), value(1999){}
69  Xthree(T8 init): value(init) {}
70
71  template <class T8> T8 comp_ge(T8 test) {// { dg-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)
83template <class T10, int i> struct Xfour {// { dg-error "" } .*
84  int T10; // { dg-error "" } .*
85  void f(){
86    char T10;
87  }
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() {// { dg-error "" } .*
98  int T13; // { dg-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 { // { dg-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; // { dg-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 { // { dg-error "" } .*
120private:
121  char T161; // { dg-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; // { dg-error "" } .*
130      return (obj.inst == u.inst); // { dg-error "" } .*
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 {// { dg-error "" } .*
162  float i; // { dg-error "" } .*
163};
164
165
166// 11
167// declared friend template, non-type parameters
168template <long l>// { dg-error "" } .*
169class Xeleven {
170public:
171  template <long l> friend bool isequal (Xeleven<5> lhs, Xeleven<5> rhs);  // { dg-error "" } .*
172};
173
174
175
176// 12
177// nested template class, non-type parameters
178template <long l>// { dg-error "" } .*
179class Xtwelve {
180public:
181  template <long l> class nested {// { dg-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>// { dg-error "" } .*
192struct Xthirteen {
193  template <long l> long comp_ge(long test) {// { dg-error "" } .
194    long local_value;
195    if (local_value > value) // { dg-error "" } .*
196      return local_value;
197    else
198      return value;
199  }
200};
201
202
203
204
205
206
207
208
209
210