1 // { dg-do run } 2 3 // Copyright (C) 2002 Free Software Foundation, Inc. 4 // Contributed by Nathan Sidwell 24 Dec 2002 <nathan@codesourcery.com> 5 6 // PR 5116. template instantiation can add a friend into a namespace, 7 // and thus change overload resolution. 8 9 #include <iostream> 10 11 static int right; 12 static int wrong; 13 14 struct Buggy {}; 15 16 template <typename T>struct Handle 17 { HandleHandle18 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 } 28 }; 29 30 typedef Handle<Buggy> Buggy_h; 31 cmp(const Buggy_h & b1,const Buggy_h & b2)32bool cmp (const Buggy_h& b1, const Buggy_h& b2) 33 { 34 std::cout << b1 << " " << b2 << std::endl; 35 return false; 36 } 37 main()38int main() 39 { 40 Buggy o; 41 42 cmp (&o, &o); 43 44 return !(right == 2 && !wrong); 45 } 46