aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.old-deja/g++.benjamin/tem03.C
blob: fb9830e689d937e6089c902e6298b45ecf44a65b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// { dg-do assemble  }
// 980808-980824 bkoz
// template parameter redeclaration bugs

// 14.1 Template parameters
// p 13
// The scope of a template-parameter extens from its point of
// declartion until the end of its template. In particular, a
// template-parameter can be used in the declaration of subsequent
// template-parameters and their default arguments. 

// 14.6.1 Locally declared names
// p 4
// A template-parameter shall not be redeclared within its scope
// (including nested scopes). A template-parameter shall not have the
// sname name as the template name.


// 01 
// declared friend template
template <class T4>// { dg-error "" } .*
class Xone {
protected:
  T4* next;
  T4* prev;
  T4 value;
public:
  Xone(): next(0), prev(0), value(1999){}
  Xone(T4 init): value(init) {}

  // these are ok:
  // can also do template-decl and then can ditch the foward-declaration
  // template <class T5> friend bool isequal (Xone<T5>& lhs, Xone<T5>& rhs);
  // this is not ok:
  template <class T4> friend bool isequal (Xone<T4>& lhs, Xone<T4>& rhs);// { dg-error "" } .*
};


// 02
// nested template class
template <class T6>// { dg-error "" } .*
class Xtwo {
protected:
  T6* next;
  T6* prev;
  T6 value;
public:
  Xtwo(): next(0), prev(0), value(1999){}
  Xtwo(T6 init): value(init) {}

  template <class T6> class nested {// { dg-error "" } .*
    T6 value;
  public:
    nested(): value( T6(0)) {}
  };
};


// 03
// member templates
template <class T8>// { dg-error "" } .*
class Xthree {
protected:
  T8* next;
  T8* prev;
  T8 value;
public:
  Xthree(): next(0), prev(0), value(1999){}
  Xthree(T8 init): value(init) {}

  template <class T8> T8 comp_ge(T8 test) {// { dg-error "" } .*
    T8 local_value;
    if (local_value > value) 
      return local_value;
    else
      return value;
  }
};


// 04
// local names (14.6.1 p 4)
template <class T10, int i> struct Xfour {// { dg-error "" } .*
  int T10; // { dg-error "" } .*
  void f(){
    char T10; // { dg-error "declaration of 'char T10'" }
  }
};


// 05
// using different tempate-parms for out-of-line defs
template <class T12, int i> struct Xfive {
  void f();
};

template <class T13, int i> void Xfive<T13,i>::f() {// { dg-error "" } .*
  int T13; // { dg-error "" } .*
  int T12; //should be ok
}


// 06
// multiple names at the same level
template <class T14, class T14> class Xsix { // { dg-error "" } .*
private:
public:
  void f();
};


// 07
// multiple names, one in template parameter one in class-name
template <class T12> class T12; // { dg-error "" } .*


// 08 
// with multiple template params, and second (third) one is redeclared
template <class T16, int i, class T161> class Xseven { // { dg-error "" } .*
private:
  char T161; // { dg-error "" } .*
public:
  template <class U>
  friend bool fooy(U u);

  template <class T161> // { dg-error "declaration of 'class T161'" }
  friend bool foo(T161 u)
    {
      Xseven<T161, 5, int> obj;
      return (obj.inst == u.inst);
    }

};


// 09 
// check for correct scoping of member templates
template <class T>
struct S1
{
  template <class U>
  void f(U u)
    {
      S1<U> s2u(u);
      s2u.g();
    }

  template <class U> //ok
  void f2(U u)
    {
      S1<U> s2u(u);
      s2u.g();
    }

};


// 10 
// check for non-type parameters, should still be able to redeclare?
// local names (14.6.1 p 4)
template <class T18, int i> class Xten {// { dg-error "" } .*
  float i; // { dg-error "" } .*
};


// 11 
// declared friend template, non-type parameters
template <long l>// { dg-error "" } .*
class Xeleven {
public:
  template <long l> friend bool isequal (Xeleven<5> lhs, Xeleven<5> rhs);  // { dg-error "" } .*
};



// 12
// nested template class, non-type parameters
template <long l>// { dg-error "" } .*
class Xtwelve {
public:
  template <long l> class nested {// { dg-error "" } .
    long value;
  public:
    nested(): value(0) {}
  };
};


// 13
// member templates, non-type parameters
template <long l>// { dg-error "" } .*
struct Xthirteen {
  template <long l> long comp_ge(long test) {// { dg-error "" } .
    long local_value;
    if (local_value > value) // { dg-error "" } .*
      return local_value;
    else
      return value;
  }
};