| 1 |
// { dg-do assemble } |
| 2 |
// 980827 bkoz |
| 3 |
// template parameter redeclaration bugs, part two: |
| 4 |
// template template params and expanded template non-type parms |
| 5 |
|
| 6 |
// 14.1 Template parameters |
| 7 |
// p 13 |
| 8 |
// The scope of a template-parameter extens from its point of |
| 9 |
// declartion until the end of its template. In particular, a |
| 10 |
// template-parameter can be used in the declaration of subsequent |
| 11 |
// template-parameters and their default arguments. |
| 12 |
|
| 13 |
// 14.6.1 Locally declared names |
| 14 |
// p 4 |
| 15 |
// A template-parameter shall not be redeclared within its scope |
| 16 |
// (including nested scopes). A template-parameter shall not have the |
| 17 |
// same name as the template name. |
| 18 |
|
| 19 |
// 14 |
| 20 |
// declared friend template (v3, template type parameters) |
| 21 |
template <class T4>// { dg-message "" } .* |
| 22 |
class Xfourteen { |
| 23 |
protected: |
| 24 |
T4 value; |
| 25 |
public: |
| 26 |
Xfourteen(T4 init): value(init) {} |
| 27 |
template <template <typename T4> class T5> // { dg-error "" } .* |
| 28 |
friend bool isequal (Xfourteen<int>& lhs, Xfourteen<int>& rhs); |
| 29 |
}; |
| 30 |
|
| 31 |
|
| 32 |
// 15 |
| 33 |
// nested template class (v3, template type parameters) |
| 34 |
template <class T6>// { dg-message "" } .* |
| 35 |
class Xfifteen { |
| 36 |
protected: |
| 37 |
T6 value; |
| 38 |
public: |
| 39 |
Xfifteen(T6 init): value(init) {} |
| 40 |
|
| 41 |
template <template <typename T6> class T7> class nested {// { dg-error "" } .* |
| 42 |
int value; |
| 43 |
public: |
| 44 |
nested(): value( int(0)) {} |
| 45 |
}; |
| 46 |
}; |
| 47 |
|
| 48 |
|
| 49 |
// 16 |
| 50 |
// member templates (v3, template type parameters) |
| 51 |
template <class T8>// { dg-message "" } .* |
| 52 |
class Xsixteen { |
| 53 |
protected: |
| 54 |
T8 value; |
| 55 |
public: |
| 56 |
Xsixteen(T8 init): value(init) {} |
| 57 |
|
| 58 |
template <template <typename T8> class T9> int comp_ge(int test) {// { dg-error "" } .* |
| 59 |
int local_value; |
| 60 |
if (local_value > value) |
| 61 |
return local_value; |
| 62 |
else |
| 63 |
return value; |
| 64 |
} |
| 65 |
}; |
| 66 |
|
| 67 |
|
| 68 |
// 17 |
| 69 |
// declared friend template (v4, template type parameters on the class) |
| 70 |
template <typename T9> class tem_base { |
| 71 |
public: |
| 72 |
T9 value; |
| 73 |
}; |
| 74 |
|
| 75 |
template <typename T10, template <typename T12> class C10> |
| 76 |
class Xseventeen { |
| 77 |
protected: |
| 78 |
C10<T10> value; |
| 79 |
public: |
| 80 |
Xseventeen(){} |
| 81 |
template <typename T12> // ok?? |
| 82 |
friend bool isequal (Xseventeen<T10, tem_base>& lhs, |
| 83 |
Xseventeen<T10, tem_base>& rhs); |
| 84 |
}; |
| 85 |
|
| 86 |
//template class Xseventeen<int, tem_base>; |
| 87 |
|
| 88 |
|
| 89 |
// 18 |
| 90 |
// more template template redecl tests |
| 91 |
template <typename T14, template <typename T15> class C12>// { dg-message "" } .* |
| 92 |
class Xeighteen { |
| 93 |
protected: |
| 94 |
C12<T14> value; |
| 95 |
int C12; // { dg-error "" } .* |
| 96 |
}; |
| 97 |
|
| 98 |
|
| 99 |
// 19 |
| 100 |
// more template template redecl tests |
| 101 |
template <typename T16, template <typename T17> class C14>// { dg-message "" } .* |
| 102 |
class Xnineteen{ |
| 103 |
protected: |
| 104 |
C14<T16> value; |
| 105 |
template <class C14> class nested {// { dg-error "" } .* |
| 106 |
T16 value; |
| 107 |
public: |
| 108 |
nested(): value( T16(0)) {} |
| 109 |
}; |
| 110 |
}; |
| 111 |
|
| 112 |
|
| 113 |
// 20 |
| 114 |
// local names (14.6.1 p 4) part two, variable names as template param |
| 115 |
template <class T17, int i> struct Xtwenty { |
| 116 |
void f(){ |
| 117 |
T17 my_type; //ok |
| 118 |
for (int j = 0; j < 5; ++j) |
| 119 |
{ |
| 120 |
T17 my_type; //ok |
| 121 |
++my_type; |
| 122 |
} |
| 123 |
} |
| 124 |
}; |
| 125 |
|
| 126 |
|
| 127 |
// 14.1 Template parameters |
| 128 |
// p 4 |
| 129 |
// A non-type templat- parameter shall have one of the following |
| 130 |
// (optionally cv-qualified) types: |
| 131 |
// integral or enumeration type |
| 132 |
// pointer to object or pointer to function |
| 133 |
// referenct to object or referece to function |
| 134 |
// pointer to member |
| 135 |
|
| 136 |
// 21 |
| 137 |
// non-type template parameters v1: enum |
| 138 |
enum my_enum {my_A = 45, my_B, my_C}; |
| 139 |
|
| 140 |
template <my_enum T18> class Xtwentyone {// { dg-message "" } .* |
| 141 |
float T18; // { dg-error "" } .* |
| 142 |
}; |
| 143 |
|
| 144 |
|
| 145 |
// 22 |
| 146 |
// non-type template parameters v1: pointer to object |
| 147 |
struct base { |
| 148 |
int gcount; |
| 149 |
int ret_gcount() {return gcount;} |
| 150 |
}; |
| 151 |
|
| 152 |
template <class T20, base* b> class Xtwentytwo {// { dg-message "" } .* |
| 153 |
float b; // { dg-error "" } .* |
| 154 |
}; |
| 155 |
|
| 156 |
|
| 157 |
// 23 |
| 158 |
// non-type template parameters v2: reference to object |
| 159 |
template <class T20, base& b2> class Xtwentythree {// { dg-message "" } .* |
| 160 |
float b2; // { dg-error "" } .* |
| 161 |
}; |
| 162 |
|
| 163 |
|
| 164 |
// 24 |
| 165 |
// non-type template parameters v3: pointer to member |
| 166 |
template <class T20, int base::* b3> class Xtwentyfour {// { dg-message "" } .* |
| 167 |
float b3; // { dg-error "" } .* |
| 168 |
}; |
| 169 |
|
| 170 |
|
| 171 |
// 25 |
| 172 |
// non-type template parms that use push_class_level |
| 173 |
template <class T22> void f1() {// { dg-message "" } .* |
| 174 |
struct foo { |
| 175 |
enum T22 { un, du, toi }; // { dg-error "" } .* |
| 176 |
}; |
| 177 |
} |