From 8c90d6111171ea07b4cbc39789f898f4e304a69f Mon Sep 17 00:00:00 2001
From: Jason Merrill <jason@gcc.gnu.org>
Date: Wed, 27 May 1998 20:11:24 -0400
Subject: [PATCH] call.c (build_method_call): Make sure get_type_value returns
 something before we try to use its...

	* call.c (build_method_call): Make sure get_type_value returns
	something before we try to use its TYPE_MAIN_VARIANT.
	* typeck2.c (digest_init): Complain about getting a TREE_LIST to
	initialize an array.
	* search.c (expand_upcast_fixups): Don't set DECL_CONTEXT and
	DECL_VIRTUAL_P.

From-SVN: r20110
---
 gcc/cp/ChangeLog | 11 +++++++++++
 gcc/cp/call.c    |  6 ++++--
 gcc/cp/search.c  | 33 ++++++++++++++++++++++-----------
 gcc/cp/typeck2.c | 10 +++++++++-
 4 files changed, 46 insertions(+), 14 deletions(-)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index f47ae9459ee0..d37a619fbfcf 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,16 @@
+1998-05-27  Brendan Kehoe  <brendan@cygnus.com>
+
+	* call.c (build_method_call): Make sure get_type_value returns
+	something before we try to use its TYPE_MAIN_VARIANT.
+
 1998-05-27  Jason Merrill  <jason@yorick.cygnus.com>
 
+	* typeck2.c (digest_init): Complain about getting a TREE_LIST to
+	initialize an array.
+
+	* search.c (expand_upcast_fixups): Don't set DECL_CONTEXT and
+	DECL_VIRTUAL_P.
+
 	* friend.c (do_friend): Clarify template warning.
 
 1998-05-27  Mark Mitchell  <mark@markmitchell.com>
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index fb280ebf2bf7..f10aae85a7db 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -632,6 +632,7 @@ build_method_call (instance, name, parms, basetype_path, flags)
 
   if (TREE_CODE (name) == BIT_NOT_EXPR)
     {
+      tree tmp;
       flags |= LOOKUP_DESTRUCTOR;
       name = TREE_OPERAND (name, 0);
       if (parms)
@@ -642,8 +643,9 @@ build_method_call (instance, name, parms, basetype_path, flags)
       if (! (name == TYPE_MAIN_VARIANT (basetype)
 	     || (IS_AGGR_TYPE (basetype)
 		 && name == constructor_name (basetype))
-	     || (TYPE_MAIN_VARIANT (basetype)
-		 == TYPE_MAIN_VARIANT (get_type_value (name)))))
+	     || ((tmp = get_type_value (name))
+		 && (TYPE_MAIN_VARIANT (basetype)
+		     == TYPE_MAIN_VARIANT (tmp)))))
 	{
 	  cp_error ("destructor name `~%D' does not match type `%T' of expression",
 		    name, basetype);
diff --git a/gcc/cp/search.c b/gcc/cp/search.c
index c0db0572ee50..f199b2f2cc18 100644
--- a/gcc/cp/search.c
+++ b/gcc/cp/search.c
@@ -2918,32 +2918,43 @@ expand_upcast_fixups (binfo, addr, orig_addr, vbase, vbase_addr, t,
 	      || nvtbl == IDENTIFIER_GLOBAL_VALUE (DECL_NAME (vtbl)))
 	    {
 	      /* Dup it if it isn't in local scope yet.  */
-	      nvtbl = build_decl (VAR_DECL,
-				  DECL_NAME (vtbl),
-				  TYPE_MAIN_VARIANT (TREE_TYPE (BINFO_VTABLE (binfo))));
+	      nvtbl = build_decl
+		(VAR_DECL, DECL_NAME (vtbl),
+		 TYPE_MAIN_VARIANT (TREE_TYPE (BINFO_VTABLE (binfo))));
 	      DECL_ALIGN (nvtbl) = MAX (TYPE_ALIGN (double_type_node),
 					DECL_ALIGN (nvtbl));
 	      TREE_READONLY (nvtbl) = 0;
 	      DECL_ARTIFICIAL (nvtbl) = 1;
 	      nvtbl = pushdecl (nvtbl);
 	      init = NULL_TREE;
-	      cp_finish_decl (nvtbl, init, NULL_TREE, 0, LOOKUP_ONLYCONVERTING);
-	      DECL_VIRTUAL_P (nvtbl) = 1;
-	      DECL_CONTEXT (nvtbl) = t;
+	      cp_finish_decl (nvtbl, init, NULL_TREE, 0,
+			      LOOKUP_ONLYCONVERTING);
+
+	      /* We don't set DECL_VIRTUAL_P and DECL_CONTEXT on nvtbl
+		 because they wouldn't be useful; everything that wants to
+		 look at the vtable will look at the decl for the normal
+		 vtable.  Setting DECL_CONTEXT also screws up
+		 decl_function_context.  */
+
 	      init = build (MODIFY_EXPR, TREE_TYPE (nvtbl),
 			    nvtbl, vtbl);
 	      TREE_SIDE_EFFECTS (init) = 1;
 	      expand_expr_stmt (init);
 	      /* Update the vtable pointers as necessary.  */
-	      ref = build_vfield_ref (build_indirect_ref (addr, NULL_PTR), DECL_CONTEXT (CLASSTYPE_VFIELD (BINFO_TYPE (binfo))));
-	      expand_expr_stmt (build_modify_expr (ref, NOP_EXPR,
-						   build_unary_op (ADDR_EXPR, nvtbl, 0)));
+	      ref = build_vfield_ref
+		(build_indirect_ref (addr, NULL_PTR),
+		 DECL_CONTEXT (CLASSTYPE_VFIELD (BINFO_TYPE (binfo))));
+	      expand_expr_stmt
+		(build_modify_expr (ref, NOP_EXPR,
+				    build_unary_op (ADDR_EXPR, nvtbl, 0)));
 	    }
 	  assemble_external (vtbl);
 	  aref = build_array_ref (vtbl, idx);
 	  naref = build_array_ref (nvtbl, idx);
-	  old_delta = build_component_ref (aref, delta_identifier, NULL_TREE, 0);
-	  new_delta = build_component_ref (naref, delta_identifier, NULL_TREE, 0);
+	  old_delta = build_component_ref (aref, delta_identifier,
+					   NULL_TREE, 0);
+	  new_delta = build_component_ref (naref, delta_identifier,
+					   NULL_TREE, 0);
 
 	  /* This is a upcast, so we have to add the offset for the
 	     virtual base.  */
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index e53f2ac14ba3..e27d86a3a3c9 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -781,7 +781,15 @@ digest_init (type, init, tail)
 
   if (code == ARRAY_TYPE)
     {
-      tree typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type));
+      tree typ1;
+
+      if (TREE_CODE (init) == TREE_LIST)
+	{
+	  error ("initializing array with parameter list");
+	  return error_mark_node;
+	}
+
+      typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type));
       if ((typ1 == char_type_node
 	   || typ1 == signed_char_type_node
 	   || typ1 == unsigned_char_type_node
-- 
GitLab