aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/template/friend10.C
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/g++.dg/template/friend10.C')
-rw-r--r--gcc/testsuite/g++.dg/template/friend10.C45
1 files changed, 45 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/template/friend10.C b/gcc/testsuite/g++.dg/template/friend10.C
new file mode 100644
index 00000000000..cab5e346f0b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/friend10.C
@@ -0,0 +1,45 @@
+// { dg-do run }
+
+// Copyright (C) 2002 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 24 Dec 2002 <nathan@codesourcery.com>
+
+// PR 5116. template instantiation can add a friend into a namespace,
+// and thus change overload resolution.
+
+#include <iostream>
+
+static int right;
+static int wrong;
+
+struct Buggy {};
+
+template <typename T>struct Handle
+{
+ Handle(T* p) {}
+
+ operator bool() const { wrong++; return true; }
+
+ friend std::ostream& operator<<(std::ostream& ostr, const Handle& r)
+ {
+ right++;
+
+ return ostr << "in operator<<(ostream&, const Handle&)";
+ }
+};
+
+typedef Handle<Buggy> Buggy_h;
+
+bool cmp (const Buggy_h& b1, const Buggy_h& b2)
+{
+ std::cout << b1 << " " << b2 << std::endl;
+ return false;
+}
+
+int main()
+{
+ Buggy o;
+
+ cmp (&o, &o);
+
+ return !(right == 2 && !wrong);
+}