public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* c++: fix injected friend of template class
@ 2020-09-22 16:05 Nathan Sidwell
  0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2020-09-22 16:05 UTC (permalink / raw)
  To: GCC Patches

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


In working on fixing hiddenness, I discovered some suspicious code in
template instantiation.  I suspect it dates from when we didn't do the
hidden friend injection thing at all.  The xreftag finds the same
class, but makes it visible to name lookup.  Which is wrong.
hurrah, fixing a bug by deleting code!

         gcc/cp/
         * pt.c (instantiate_class_template_1): Do not repush and unhide
         injected friend.
         gcc/testsuite/
         * g++.old-deja/g++.pt/friend34.C: Check injected friend is still
         invisible.

pushed to trunk

nathan

-- 
Nathan Sidwell

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

diff --git i/gcc/cp/pt.c w/gcc/cp/pt.c
index 97d0c245f7e..44ca14afc4e 100644
--- i/gcc/cp/pt.c
+++ w/gcc/cp/pt.c
@@ -12030,25 +12030,6 @@ instantiate_class_template_1 (tree type)
 		    adjust_processing_template_decl = true;
 		  --processing_template_decl;
 		}
-	      else if (TREE_CODE (friend_type) != BOUND_TEMPLATE_TEMPLATE_PARM
-		       && !CLASSTYPE_USE_TEMPLATE (friend_type)
-		       && TYPE_HIDDEN_P (friend_type))
-		{
-		  /* friend class C;
-
-		     where C hasn't been declared yet.  Let's lookup name
-		     from namespace scope directly, bypassing any name that
-		     come from dependent base class.  */
-		  tree ns = decl_namespace_context (TYPE_MAIN_DECL (friend_type));
-
-		  /* The call to xref_tag_from_type does injection for friend
-		     classes.  */
-		  push_nested_namespace (ns);
-		  friend_type =
-		    xref_tag_from_type (friend_type, NULL_TREE,
-					/*tag_scope=*/ts_current);
-		  pop_nested_namespace (ns);
-		}
 	      else if (uses_template_parms (friend_type))
 		/* friend class C<T>;  */
 		friend_type = tsubst (friend_type, args,
diff --git i/gcc/testsuite/g++.old-deja/g++.pt/friend34.C w/gcc/testsuite/g++.old-deja/g++.pt/friend34.C
index 5e80ab98b2e..dcd6df0ce55 100644
--- i/gcc/testsuite/g++.old-deja/g++.pt/friend34.C
+++ w/gcc/testsuite/g++.old-deja/g++.pt/friend34.C
@@ -6,9 +6,12 @@
 template <typename T = void>
 class bar {
 public:
-  friend class foo; // this is not bar::foo, it forward-declares ::foo
+  friend class foo; // this is not bar::foo, it injects hidden ::foo
   class foo {};
   bar() { foo(); } // but this should refer to bar::foo
 };
 
 bar<> baz;
+
+// We still have not made foo visible.
+foo *b;  // { dg-error "does not name a type" }

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

only message in thread, other threads:[~2020-09-22 16:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-22 16:05 c++: fix injected friend of template class Nathan Sidwell

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).