2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.benjamin / tem03.C
blob73b99659e121d4264c6b6bec7af185e933d9b907
1 // { dg-do assemble  }
2 // 980808-980824 bkoz
3 // template parameter redeclaration bugs
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. 
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.
19 // 01 
20 // declared friend template
21 template <class T4>// { dg-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) {}
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 "" } .*
39 // 02
40 // nested template class
41 template <class T6>// { dg-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) {}
51   template <class T6> class nested {// { dg-error "" } .*
52     T6 value;
53   public:
54     nested(): value( T6(0)) {}
55   };
59 // 03
60 // member templates
61 template <class T8>// { dg-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) {}
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   }
81 // 04
82 // local names (14.6.1 p 4)
83 template <class T10, int i> struct Xfour {// { dg-error "" } .*
84   int T10; // { dg-error "" } .*
85   void f(){
86     char T10;
87   }
91 // 05
92 // using different tempate-parms for out-of-line defs
93 template <class T12, int i> struct Xfive {
94   void f();
97 template <class T13, int i> void Xfive<T13,i>::f() {// { dg-error "" } .*
98   int T13; // { dg-error "" } .*
99   int T12; //should be ok
103 // 06
104 // multiple names at the same level
105 template <class T14, class T14> class Xsix { // { dg-error "" } .*
106 private:
107 public:
108   void f();
112 // 07
113 // multiple names, one in template parameter one in class-name
114 template <class T12> class T12; // { dg-error "" } .*
117 // 08 
118 // with multiple template params, and second (third) one is redeclared
119 template <class T16, int i, class T161> class Xseven { // { dg-error "" } .*
120 private:
121   char T161; // { dg-error "" } .*
122 public:
123   template <class U>
124   friend bool fooy(U u);
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     }
136 // 09 
137 // check for correct scoping of member templates
138 template <class T>
139 struct S1
141   template <class U>
142   void f(U u)
143     {
144       S1<U> s2u(u);
145       s2u.g();
146     }
148   template <class U> //ok
149   void f2(U u)
150     {
151       S1<U> s2u(u);
152       s2u.g();
153     }
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 {// { dg-error "" } .*
162   float i; // { dg-error "" } .*
166 // 11 
167 // declared friend template, non-type parameters
168 template <long l>// { dg-error "" } .*
169 class Xeleven {
170 public:
171   template <long l> friend bool isequal (Xeleven<5> lhs, Xeleven<5> rhs);  // { dg-error "" } .*
176 // 12
177 // nested template class, non-type parameters
178 template <long l>// { dg-error "" } .*
179 class Xtwelve {
180 public:
181   template <long l> class nested {// { dg-error "" } .
182     long value;
183   public:
184     nested(): value(0) {}
185   };
189 // 13
190 // member templates, non-type parameters
191 template <long l>// { dg-error "" } .*
192 struct 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   }