| 1 |
// { dg-do run } |
| 2 |
// GROUPS passed templates |
| 3 |
extern "C" int printf (const char *, ...); |
| 4 |
extern "C" void exit (int); |
| 5 |
|
| 6 |
int count = 0; |
| 7 |
|
| 8 |
void |
| 9 |
die (int x) |
| 10 |
{ |
| 11 |
if (x != ++count) |
| 12 |
{ |
| 13 |
printf ("FAIL\n"); |
| 14 |
exit (1); |
| 15 |
} |
| 16 |
} |
| 17 |
|
| 18 |
class A { |
| 19 |
public: |
| 20 |
void f() const { die (-1); } |
| 21 |
}; |
| 22 |
|
| 23 |
|
| 24 |
template <class Item> |
| 25 |
class B : public A { |
| 26 |
public: |
| 27 |
void f() const; |
| 28 |
}; |
| 29 |
|
| 30 |
template <class Item> |
| 31 |
inline void B<Item>::f() const { die (1); } |
| 32 |
|
| 33 |
template <class Item> |
| 34 |
class C : public A { |
| 35 |
public: |
| 36 |
void f() const { die (2); } |
| 37 |
}; |
| 38 |
|
| 39 |
|
| 40 |
int main() |
| 41 |
{ |
| 42 |
B<int> b; |
| 43 |
C<int> c; |
| 44 |
|
| 45 |
b.f(); //- bugged, (A::f() called instead of B::f()) |
| 46 |
c.f(); //- works fine (C::f() called) |
| 47 |
|
| 48 |
printf ("PASS\n"); |
| 49 |
return 0; |
| 50 |
} |