public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH to overloaded friend hiding
@ 2015-08-20 20:58 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2015-08-20 20:58 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 201 bytes --]

Someone on the C++ committee pointed out that G++ unqualified lookup 
could see through one hidden friend, but not two, and not a template. 
Fixed thus.

Tested x86_64-pc-linux-gnu, applying to trunk.

[-- Attachment #2: friend.patch --]
[-- Type: text/x-patch, Size: 2999 bytes --]

commit bef61f4085710822782a462def4a7032c8a91668
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Aug 20 14:40:55 2015 -0400

    	* name-lookup.c (hidden_name_p): Handle OVERLOAD.

diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 79e2863..baaf3e7 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -4346,6 +4346,13 @@ hidden_name_p (tree val)
       && TYPE_FUNCTION_OR_TEMPLATE_DECL_P (val)
       && DECL_ANTICIPATED (val))
     return true;
+  if (TREE_CODE (val) == OVERLOAD)
+    {
+      for (tree o = val; o; o = OVL_CHAIN (o))
+	if (!hidden_name_p (OVL_FUNCTION (o)))
+	  return false;
+      return true;
+    }
   return false;
 }
 
diff --git a/gcc/testsuite/g++.dg/lookup/friend16.C b/gcc/testsuite/g++.dg/lookup/friend16.C
new file mode 100644
index 0000000..bb27773
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lookup/friend16.C
@@ -0,0 +1,24 @@
+namespace std {
+  class ostream;
+}
+
+namespace N2 {
+  class C0 {};
+}
+
+std::ostream& operator<<( std::ostream& os_, const N2::C0& m_);
+
+namespace N1 {
+  class C1 {
+    friend std::ostream& operator<<(std::ostream& os, const C1& what);
+  };
+
+  class C2 {
+    friend std::ostream& operator<<(std::ostream& os, const C2& what);
+  };
+
+  void foo(std::ostream & os, const N2::C0& m)
+  {
+    os << m; // Is this line valid?
+  }
+}
diff --git a/gcc/testsuite/g++.dg/template/friend15.C b/gcc/testsuite/g++.dg/template/friend15.C
index 4acbf2d..15ba1c2 100644
--- a/gcc/testsuite/g++.dg/template/friend15.C
+++ b/gcc/testsuite/g++.dg/template/friend15.C
@@ -10,10 +10,11 @@ template <typename> class X {
     struct Inner;
 
     template <typename R>
-    friend typename X<R>::Inner * foo () { return 0; }
+    friend typename X<R>::Inner * foo (X<R>*) { return 0; }
 };
 template class X<void>;
+X<void>* p;
 
 struct U {
-    void bar () { foo<void> (); }
+  void bar () { foo (p); }
 };
diff --git a/gcc/testsuite/g++.dg/template/friend18.C b/gcc/testsuite/g++.dg/template/friend18.C
index 04ba26e..712d488 100644
--- a/gcc/testsuite/g++.dg/template/friend18.C
+++ b/gcc/testsuite/g++.dg/template/friend18.C
@@ -7,13 +7,14 @@
 
 template <int N> struct X
 {
-  template <int M> friend int foo(X const &)
+  template <int M> friend int foo(X const &, X<M> const&)
   {
     return N * 10000 + M;
   }
 };
 X<1234> bring;
+X<5678> brung;
 
 int main() {
-  return foo<5678> (bring) != 12345678;
+  return foo (bring, brung) != 12345678;
 }
diff --git a/gcc/testsuite/g++.old-deja/g++.pt/friend32.C b/gcc/testsuite/g++.old-deja/g++.pt/friend32.C
index 512a69a..db8b724 100644
--- a/gcc/testsuite/g++.old-deja/g++.pt/friend32.C
+++ b/gcc/testsuite/g++.old-deja/g++.pt/friend32.C
@@ -7,8 +7,8 @@ struct S {
 };
 
 template class S<int, double>;
-template char f(char, long, short);
-template char* f(char*, long*, short*);
+template char f(char, long, short); // { dg-error "f" }
+template char* f(char*, long*, short*); // { dg-error "f" }
 
 template <class X, class Y, class Z>
 X f(X x, Y, Z) {

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-08-20 20:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-20 20:58 C++ PATCH to overloaded friend hiding Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).