| 1 |
// { dg-do run } |
| 2 |
// { dg-skip-if "requires hosted libstdc++ for iostream" { ! hostedlib } } |
| 3 |
|
| 4 |
// Copyright (C) 2002 Free Software Foundation, Inc. |
| 5 |
// Contributed by Nathan Sidwell 24 Dec 2002 <[email protected]> |
| 6 |
|
| 7 |
// PR 5116. template instantiation can add a friend into a namespace, |
| 8 |
// and thus change overload resolution. |
| 9 |
|
| 10 |
#include <iostream> |
| 11 |
|
| 12 |
static int right; |
| 13 |
static int wrong; |
| 14 |
|
| 15 |
struct Buggy {}; |
| 16 |
|
| 17 |
template <typename T>struct Handle |
| 18 |
{ |
| 19 |
Handle(T* p) {} |
| 20 |
|
| 21 |
operator bool() const { wrong++; return true; } |
| 22 |
|
| 23 |
friend std::ostream& operator<<(std::ostream& ostr, const Handle& r) |
| 24 |
{ |
| 25 |
right++; |
| 26 |
|
| 27 |
return ostr << "in operator<<(ostream&, const Handle&)"; |
| 28 |
} |
| 29 |
}; |
| 30 |
|
| 31 |
typedef Handle<Buggy> Buggy_h; |
| 32 |
|
| 33 |
bool cmp (const Buggy_h& b1, const Buggy_h& b2) |
| 34 |
{ |
| 35 |
std::cout << b1 << " " << b2 << std::endl; |
| 36 |
return false; |
| 37 |
} |
| 38 |
|
| 39 |
int main() |
| 40 |
{ |
| 41 |
Buggy o; |
| 42 |
|
| 43 |
cmp (&o, &o); |
| 44 |
|
| 45 |
return !(right == 2 && !wrong); |
| 46 |
} |