2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.dg / template / friend10.C
blobcab5e346f0bf397454d09926fbcc68689f0d4a65
1 // { dg-do run }
3 // Copyright (C) 2002 Free Software Foundation, Inc.
4 // Contributed by Nathan Sidwell 24 Dec 2002 <nathan@codesourcery.com>
6 // PR 5116. template instantiation can add a friend into a namespace,
7 // and thus change overload resolution.
9 #include <iostream>
11 static int right;
12 static int wrong;
14 struct Buggy {};
16 template <typename T>struct Handle
18   Handle(T* p) {}
19   
20   operator bool() const { wrong++; return true; }
21   
22   friend std::ostream& operator<<(std::ostream& ostr, const Handle& r)
23   {
24     right++;
25     
26     return ostr << "in operator<<(ostream&, const Handle&)";
27   }
30 typedef Handle<Buggy>     Buggy_h;
32 bool cmp (const Buggy_h& b1, const Buggy_h& b2)
34   std::cout << b1 << " " << b2 << std::endl;
35   return false;
38 int main()
40   Buggy o;
41   
42   cmp (&o, &o);
44   return !(right == 2 && !wrong);