From ab04e34bff7a8090fdfe86e50eb88bae7d717ed3 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell <nathan@codesourcery.com>
Date: Mon, 11 Mar 2002 20:51:00 +0000
Subject: [PATCH] Revert 2001-03-26 Nathan Sidwell <nathan@codesourcery.com>,
 DR209 is now not a defect.

cp:
	Revert 2001-03-26  Nathan Sidwell  <nathan@codesourcery.com>,
	DR209 is now not a defect.
	* cp-tree.h (skip_type_access_control): Remove.
	* decl.c (grokdeclarator): Do type access control for friend
	declarations.
	* semantics.c (decl_type_access_control): Don't reset
	current_type_lookups.
	(save_type_access_control): Always save the lookups.
	(skip_type_access_control): Remove.
	(finish_class_definition): Don't change type_lookups.
testsuite:
	* testsuite/g++.old-deja/g++.other/friend9.C: Revert DR 209 changes.
	* testsuite/g++.old-deja/g++.robertl/eb56.C: Likewise.

From-SVN: r50595
---
 gcc/cp/ChangeLog                              | 13 +++++
 gcc/cp/cp-tree.h                              |  3 +-
 gcc/cp/decl.c                                 | 53 +++++++++----------
 gcc/cp/semantics.c                            | 23 +-------
 gcc/testsuite/ChangeLog                       |  5 ++
 .../g++.old-deja/g++.other/friend9.C          |  6 +--
 gcc/testsuite/g++.old-deja/g++.robertl/eb56.C |  2 +-
 7 files changed, 48 insertions(+), 57 deletions(-)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 513dd00cb5b7..1ad21d39d113 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,16 @@
+2002-03-11  Nathan Sidwell  <nathan@codesourcery.com>
+
+	Revert 2001-03-26  Nathan Sidwell  <nathan@codesourcery.com>,
+	DR209 is now not a defect.
+	* cp-tree.h (skip_type_access_control): Remove.
+	* decl.c (grokdeclarator): Do type access control for friend
+	declarations.
+	* semantics.c (decl_type_access_control): Don't reset
+	current_type_lookups.
+	(save_type_access_control): Always save the lookups.
+	(skip_type_access_control): Remove.
+	(finish_class_definition): Don't change type_lookups.
+
 2002-03-11  Nathan Sidwell  <nathan@codesourcery.com>
 
 	Revert 2000-12-01  Nathan Sidwell  <nathan@codesourcery.com>,
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index a2686c1c4505..cae147550177 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -4062,8 +4062,6 @@ extern int types_overlap_p			PARAMS ((tree, tree));
 extern tree get_vbase				PARAMS ((tree, tree));
 extern tree get_dynamic_cast_base_type          PARAMS ((tree, tree));
 extern void type_access_control			PARAMS ((tree, tree));
-extern void skip_type_access_control            PARAMS ((void));
-extern void reset_type_access_control           PARAMS ((void));
 extern int accessible_p                         PARAMS ((tree, tree));
 extern tree lookup_field			PARAMS ((tree, tree, int, int));
 extern int lookup_fnfields_1                    PARAMS ((tree, tree));
@@ -4171,6 +4169,7 @@ extern tree finish_qualified_call_expr          PARAMS ((tree, tree));
 extern tree finish_unary_op_expr                PARAMS ((enum tree_code, tree));
 extern tree finish_id_expr                      PARAMS ((tree));
 extern void save_type_access_control		PARAMS ((tree));
+extern void reset_type_access_control           PARAMS ((void));
 extern void decl_type_access_control		PARAMS ((tree));
 extern int begin_function_definition            PARAMS ((tree, tree));
 extern tree begin_constructor_declarator        PARAMS ((tree, tree));
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 9eb31bac4035..d7047fcdbfeb 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -11293,9 +11293,7 @@ friend declaration requires class-key, i.e. `friend %#T'",
 	  /* Only try to do this stuff if we didn't already give up.  */
 	  if (type != integer_type_node)
 	    {
-	      /* DR 209. The friendly class does not need to be accessible
-                 in the scope of the class granting friendship. */
-	      skip_type_access_control ();
+	      decl_type_access_control (TYPE_NAME (type));
 
 	      /* A friendly class?  */
 	      if (current_class_type)
@@ -11557,33 +11555,32 @@ friend declaration requires class-key, i.e. `friend %#T'",
 	if (friendp)
 	  {
 	    /* Friends are treated specially.  */
-            tree t = NULL_TREE;
-	    
-	    /* DR 209. The friend does not need to be accessible at this
-               point. */
-	    skip_type_access_control ();
-	    
 	    if (ctype == current_class_type)
 	      warning ("member functions are implicitly friends of their class");
-
-            if (decl && DECL_NAME (decl))
-              {
-                if (template_class_depth (current_class_type) == 0)
-                  {
-              	    decl = check_explicit_specialization
-              	            (declarator, decl,
-              	             template_count, 2 * (funcdef_flag != 0) + 4);
-              	    if (decl == error_mark_node)
-              	      return error_mark_node;
-                  }
-              
-                t = do_friend (ctype, declarator, decl,
-              		       last_function_parms, *attrlist, flags, quals,
-              		       funcdef_flag);
-              }
-            if (t && funcdef_flag)
-              return t;
-	    return void_type_node;
+ 	    else
+ 	      {
+ 		tree t = NULL_TREE;
+ 		if (decl && DECL_NAME (decl))
+ 		  {
+ 		    if (template_class_depth (current_class_type) == 0)
+ 		      {
+ 			decl
+ 			  = check_explicit_specialization
+ 			  (declarator, decl,
+ 			   template_count, 2 * (funcdef_flag != 0) + 4);
+ 			if (decl == error_mark_node)
+ 			  return error_mark_node;
+ 		      }
+		    
+ 		    t = do_friend (ctype, declarator, decl,
+ 				   last_function_parms, *attrlist,
+				   flags, quals, funcdef_flag);
+ 		  }
+ 		if (t && funcdef_flag)
+ 		  return t;
+  
+ 		return void_type_node;
+ 	      }
 	  }
 
 	/* Structure field.  It may not be a function, except for C++ */
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index e77e9299ec1a..3ec15a9bb910 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -1502,32 +1502,13 @@ decl_type_access_control (decl)
      added to type_lookups after typed_declspecs saved the copy that
      ended up in current_type_lookups.  */
   type_lookups = current_type_lookups;
-  
-  current_type_lookups = NULL_TREE;
 }
 
-/* Record the lookups, if we're doing deferred access control.  */
-
 void
 save_type_access_control (lookups)
      tree lookups;
 {
-  if (type_lookups != error_mark_node)
-    {
-      my_friendly_assert (!current_type_lookups, 20010301);
-      current_type_lookups = lookups;
-    }
-  else
-    my_friendly_assert (!lookups || lookups == error_mark_node, 20010301);
-}
-
-/* Set things up so that the next deferred access control will succeed.
-   This is needed for friend declarations see grokdeclarator for details.  */
-
-void
-skip_type_access_control ()
-{
-  type_lookups = NULL_TREE;
+  current_type_lookups = lookups;
 }
 
 /* Reset the deferred access control.  */
@@ -1911,8 +1892,6 @@ finish_class_definition (t, attributes, semi, pop_scope_p)
     check_for_missing_semicolon (t); 
   if (pop_scope_p)
     pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t)));
-  if (current_function_decl)
-    type_lookups = error_mark_node;
   if (current_scope () == current_function_decl)
     do_pending_defargs ();
 
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 354e9616129c..87c3e74a21cc 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2002-03-11  Nathan Sidwell  <nathan@codesourcery.com>
+
+	* testsuite/g++.old-deja/g++.other/friend9.C: Revert DR 209 changes.
+	* testsuite/g++.old-deja/g++.robertl/eb56.C: Likewise.
+
 2002-03-11  Nathan Sidwell  <nathan@codesourcery.com>
 
 	* testsuite/g++.dg/overload/pmf1.C: New test.
diff --git a/gcc/testsuite/g++.old-deja/g++.other/friend9.C b/gcc/testsuite/g++.old-deja/g++.other/friend9.C
index e51b0274c665..442d9899e3a7 100644
--- a/gcc/testsuite/g++.old-deja/g++.other/friend9.C
+++ b/gcc/testsuite/g++.old-deja/g++.other/friend9.C
@@ -5,16 +5,14 @@
 
 // Bug 853: We reported the wrong line no for a friend access violation
 
-// Since DR 209, friend declaration access is not checked.
-
 class F
 {
-  class Internal;
+  class Internal;   // ERROR - is private
 };
 
 class C
 {
-  friend class F::Internal;
+  friend class F::Internal; // ERROR - in this context
   public:
   typedef enum { A, B } e;
 
diff --git a/gcc/testsuite/g++.old-deja/g++.robertl/eb56.C b/gcc/testsuite/g++.old-deja/g++.robertl/eb56.C
index 2249a40b24cc..0b4bb7dbe399 100644
--- a/gcc/testsuite/g++.old-deja/g++.robertl/eb56.C
+++ b/gcc/testsuite/g++.old-deja/g++.robertl/eb56.C
@@ -3,7 +3,7 @@
 
 class foo {
   public:
-        typedef int sometype;
+  typedef int sometype;
 };
 
 struct die : public foo::sometype { // ERROR - invalid base type
-- 
GitLab