public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Ollie Wild" <aaw@google.com>
To: "GCC Patches" <gcc-patches@gcc.gnu.org>
Subject: PATCH: fixes c++ friend class declaration lookup bugs
Date: Fri, 18 May 2007 17:34:00 -0000	[thread overview]
Message-ID: <65dd6fd50705181034p69d509b3y2b5ccc3b1d3f2294@mail.gmail.com> (raw)

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

If a friend class declaration has no prior declarations, the class
name is hidden from name lookup until it is subsequently declared.  In
some cases, the hidden name is stored in the type member of its
cxx_binding structure.  However, the name lookup code was not always
checking this.  This resulted in types being found prior to their
declaration and, in one case, an internal compiler error.  This patch
adds missing checks via the hidden_name_p macro.

Tested with a C/C++/Java bootstrap and testsuite run on i686-pc-linux-gnu.

Ollie

:ADDPATCH c++:

2007-05-18  Ollie Wild  <aaw@google.com>

       * name-lookup.c (ambiguous_decl): Adds check for hidden types.
       (unqualified_namespace_lookup): Adds check for hidden types.

2007-05-18  Ollie Wild  <aaw@google.com>

       * g++.dg/lookup/hidden-class10.C: New test.
       * g++.dg/lookup/hidden-class11.C: New test.

[-- Attachment #2: hidden-class.patch --]
[-- Type: text/x-patch, Size: 2036 bytes --]

diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index a7a12cd..befc2d3 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -3543,7 +3543,7 @@ ambiguous_decl (tree name, struct scope_binding *old, cxx_binding *new,
     }
   /* ... and copy the type.  */
   type = new->type;
-  if (LOOKUP_NAMESPACES_ONLY (flags))
+  if (LOOKUP_NAMESPACES_ONLY (flags) || (type && hidden_name_p (type)))
     type = NULL_TREE;
   if (!old->type)
     old->type = type;
@@ -3699,7 +3699,9 @@ unqualified_namespace_lookup (tree name, int flags)
 	  if (b->value
 	      && ((flags & LOOKUP_HIDDEN) || !hidden_name_p (b->value)))
 	    binding.value = b->value;
-	  binding.type = b->type;
+	  if (b->type
+	      && ((flags & LOOKUP_HIDDEN) || !hidden_name_p (b->type)))
+	    binding.type = b->type;
 	}
 
       /* Add all _DECLs seen through local using-directives.  */
diff --git a/gcc/testsuite/g++.dg/lookup/hidden-class10.C b/gcc/testsuite/g++.dg/lookup/hidden-class10.C
new file mode 100644
index 0000000..f68196f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lookup/hidden-class10.C
@@ -0,0 +1,11 @@
+// Copyright (C) 2007 Free Software Foundation
+// Contributed by Ollie Wild <aaw@google.com>
+// { dg-do compile }
+
+// Verify that a friend class is hidden even if it overrides a builtin
+// function name.
+
+class A {
+  friend class abort;
+  abort *b;	// { dg-error "no type|expected" }
+};
diff --git a/gcc/testsuite/g++.dg/lookup/hidden-class11.C b/gcc/testsuite/g++.dg/lookup/hidden-class11.C
new file mode 100644
index 0000000..8432e32
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lookup/hidden-class11.C
@@ -0,0 +1,23 @@
+// Copyright (C) 2007 Free Software Foundation
+// Contributed by Ollie Wild <aaw@google.com>
+// { dg-do compile }
+
+// Verify that a friend class is hidden even if it is hidden by a non-builtin
+// function name.
+
+namespace M {
+  void F (void);
+  class F;
+}
+
+namespace N {
+  void F(void);
+  class A {
+    friend class F;
+  };
+}
+
+using namespace M;
+using namespace N;
+
+class F *b;

             reply	other threads:[~2007-05-18 17:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-18 17:34 Ollie Wild [this message]
2007-05-21 21:15 ` Mark Mitchell
2007-05-22 18:13   ` Ollie Wild
2007-05-22 18:21     ` Mark Mitchell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=65dd6fd50705181034p69d509b3y2b5ccc3b1d3f2294@mail.gmail.com \
    --to=aaw@google.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).