| 1 |
// { dg-do assemble } |
| 2 |
// { dg-skip-if "requires hosted libstdc++ for iostream" { ! hostedlib } } |
| 3 |
// Origin: Gerald Pfeifer <[email protected]> |
| 4 |
|
| 5 |
#include <iostream> |
| 6 |
|
| 7 |
struct IDENT |
| 8 |
{ |
| 9 |
enum TYPE { Variable, Constant } type; |
| 10 |
|
| 11 |
std::ostream& printTo(std::ostream& out) const |
| 12 |
{ |
| 13 |
switch (type) |
| 14 |
{ |
| 15 |
case Variable: |
| 16 |
out << '_'; |
| 17 |
break; |
| 18 |
default: |
| 19 |
break; |
| 20 |
} |
| 21 |
return out; |
| 22 |
} |
| 23 |
}; |
| 24 |
|
| 25 |
|
| 26 |
template <class T> |
| 27 |
struct TC |
| 28 |
{ |
| 29 |
IDENT i; |
| 30 |
|
| 31 |
const IDENT& getIdent() const |
| 32 |
{ |
| 33 |
return i; |
| 34 |
} |
| 35 |
}; |
| 36 |
|
| 37 |
template <class T> |
| 38 |
inline std::ostream& operator<< (std::ostream& out, const TC<T> &c) |
| 39 |
{ |
| 40 |
c.getIdent().printTo(out); |
| 41 |
return out; |
| 42 |
} |
| 43 |
|
| 44 |
void foo(const TC<IDENT> &c) |
| 45 |
{ |
| 46 |
std::cerr << c |
| 47 |
<< ": " // This line is crucial! |
| 48 |
<< c |
| 49 |
<< std::endl; |
| 50 |
} |