OSDN Git Service

* init.c (resolve_offset_ref): Don't return a raw method.
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 7 May 1999 09:47:57 +0000 (09:47 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 7 May 1999 09:47:57 +0000 (09:47 +0000)
Use BASELINK_P.
* typeck.c (decay_conversion): Don't handle a raw method.
Resolve all OFFSET_REFs.
(get_member_function_from_ptrfunc): 0 is a valid vtable index.
(build_binary_op_nodefault): Handle resolving overloaded fns.  Use
same_type_p for pmf bits.  Don't use build_binary_op to compare
raw pointers to methods.
(convert_for_assignment): Check for OFFSET_REF, not OFFSET_TYPE,
to decide when to call resolve_offset_ref.
(build_c_cast, convert_for_initialization): Likewise.
* cvt.c (build_expr_type_conversion): Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@26815 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/cvt.c
gcc/cp/init.c
gcc/cp/typeck.c

index 5d1c6a3..2bf5027 100644 (file)
@@ -1,3 +1,18 @@
+1999-05-07  Jason Merrill  <jason@yorick.cygnus.com>
+
+       * init.c (resolve_offset_ref): Don't return a raw method.
+       Use BASELINK_P.
+       * typeck.c (decay_conversion): Don't handle a raw method.
+       Resolve all OFFSET_REFs.
+       (get_member_function_from_ptrfunc): 0 is a valid vtable index.
+       (build_binary_op_nodefault): Handle resolving overloaded fns.  Use
+       same_type_p for pmf bits.  Don't use build_binary_op to compare
+       raw pointers to methods.
+       (convert_for_assignment): Check for OFFSET_REF, not OFFSET_TYPE,
+       to decide when to call resolve_offset_ref.
+       (build_c_cast, convert_for_initialization): Likewise.
+       * cvt.c (build_expr_type_conversion): Likewise.
+
 1999-05-06  Nathan Sidwell  <nathan@acm.org>
 
        * call.c (build_new_method_call): Use TYPE_MAIN_VARIANT of class.
index cef8bc8..c9c4100 100644 (file)
@@ -976,7 +976,7 @@ build_expr_type_conversion (desires, expr, complain)
       && !(desires & WANT_NULL))
     cp_warning ("converting NULL to non-pointer type");
     
-  if (TREE_CODE (basetype) == OFFSET_TYPE)
+  if (TREE_CODE (expr) == OFFSET_REF || BASELINK_P (expr))
     expr = resolve_offset_ref (expr);
   expr = convert_from_reference (expr);
   basetype = TREE_TYPE (expr);
index e9fe895..d54d6f6 100644 (file)
@@ -1692,7 +1692,7 @@ resolve_offset_ref (exp)
   tree member;
   tree basetype, addr;
 
-  if (TREE_CODE (exp) == TREE_LIST)
+  if (BASELINK_P (exp))
     {
       cp_pedwarn ("assuming & on overloaded member function");
       return build_unary_op (ADDR_EXPR, exp, 0);
@@ -1719,8 +1719,7 @@ resolve_offset_ref (exp)
   if ((TREE_CODE (member) == VAR_DECL
        && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (member))
        && ! TYPE_PTRMEM_P (TREE_TYPE (member)))
-      || TREE_CODE (TREE_TYPE (member)) == FUNCTION_TYPE
-      || TREE_CODE (TREE_TYPE (member)) == METHOD_TYPE)
+      || TREE_CODE (TREE_TYPE (member)) == FUNCTION_TYPE)
     {
       /* These were static members.  */
       if (mark_addressable (member) == 0)
@@ -1728,6 +1727,12 @@ resolve_offset_ref (exp)
       return member;
     }
 
+  if (TREE_CODE (TREE_TYPE (member)) == METHOD_TYPE)
+    {
+      cp_pedwarn ("assuming & on `%E'", member);
+      return build_unary_op (ADDR_EXPR, exp, 0);
+    }
+
   if (TREE_CODE (TREE_TYPE (member)) == POINTER_TYPE
       && TREE_CODE (TREE_TYPE (TREE_TYPE (member))) == METHOD_TYPE)
     return member;
index fd02051..fe4f509 100644 (file)
@@ -1714,23 +1714,14 @@ tree
 decay_conversion (exp)
      tree exp;
 {
-  register tree type = TREE_TYPE (exp);
-  register enum tree_code code = TREE_CODE (type);
+  register tree type;
+  register enum tree_code code;
 
-  if (code == OFFSET_TYPE)
-    {
-      if (TREE_CODE (exp) == OFFSET_REF)
-       return decay_conversion (resolve_offset_ref (exp));
+  if (TREE_CODE (exp) == OFFSET_REF || BASELINK_P (exp))
+    exp = resolve_offset_ref (exp);
 
-      type = TREE_TYPE (type);
-      code = TREE_CODE (type);
-
-      if (type == unknown_type_node)
-       {
-         cp_pedwarn ("assuming & on overloaded member function");
-         return build_unary_op (ADDR_EXPR, exp, 0);
-       }
-    }
+  type = TREE_TYPE (exp);
+  code = TREE_CODE (type);
 
   if (code == REFERENCE_TYPE)
     {
@@ -1765,10 +1756,7 @@ decay_conversion (exp)
       return error_mark_node;
     }
   if (code == METHOD_TYPE)
-    {
-      cp_pedwarn ("assuming & on `%E'", exp);
-      return build_unary_op (ADDR_EXPR, exp, 0);
-    }
+    my_friendly_abort (990506);
   if (code == FUNCTION_TYPE || is_overloaded_fn (exp))
     return build_unary_op (ADDR_EXPR, exp, 0);
   if (code == ARRAY_TYPE)
@@ -2871,7 +2859,7 @@ get_member_function_from_ptrfunc (instance_ptrptr, function)
                           (build_component_ref (function,
                                                 index_identifier,
                                                 NULL_TREE, 0)));
-         e1 = build_binary_op (GT_EXPR, idx, integer_zero_node);
+         e1 = build_binary_op (GE_EXPR, idx, integer_zero_node);
 
          /* Convert down to the right base, before using the instance.  */
          instance = convert_pointer_to_real (basetype, instance_ptr);
@@ -3356,6 +3344,32 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code)
       op1 = default_conversion (orig_op1);
     }
 
+  /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
+  STRIP_TYPE_NOPS (op0);
+  STRIP_TYPE_NOPS (op1);
+
+  /* DTRT if one side is an overloaded function, but complain about it.  */
+  if (type_unknown_p (op0))
+    {
+      tree t = instantiate_type (TREE_TYPE (op1), op0, 0);
+      if (t != error_mark_node)
+       {
+         cp_pedwarn ("assuming cast to `%T' from overloaded function",
+                     TREE_TYPE (t));
+         op0 = t;
+       }
+    }
+  if (type_unknown_p (op1))
+    {
+      tree t = instantiate_type (TREE_TYPE (op0), op1, 0);
+      if (t != error_mark_node)
+       {
+         cp_pedwarn ("assuming cast to `%T' from overloaded function",
+                     TREE_TYPE (t));
+         op1 = t;
+       }
+    }
+
   type0 = TREE_TYPE (op0);
   type1 = TREE_TYPE (op1);
 
@@ -3364,10 +3378,6 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code)
   code0 = TREE_CODE (type0);
   code1 = TREE_CODE (type1);
 
-  /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
-  STRIP_TYPE_NOPS (op0);
-  STRIP_TYPE_NOPS (op1);
-
   /* If an error was already reported for one of the arguments,
      avoid reporting another error.  */
 
@@ -3640,8 +3650,7 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code)
          result_type = TREE_TYPE (op0);
        }
       else if (TYPE_PTRMEMFUNC_P (type0) && TYPE_PTRMEMFUNC_P (type1)
-              && (TYPE_PTRMEMFUNC_FN_TYPE (type0)
-                  == TYPE_PTRMEMFUNC_FN_TYPE (type1)))
+              && same_type_p (type0, type1))
        {
          /* The code we generate for the test is:
 
@@ -3665,7 +3674,9 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code)
          e2 = build_binary_op (NE_EXPR, index1, integer_neg_one_node);
          e2 = build_binary_op (TRUTH_ANDIF_EXPR, e2,
                                build_binary_op (EQ_EXPR, delta20, delta21));
-         e3 = build_binary_op (EQ_EXPR, pfn0, pfn1);
+         /* We can't use build_binary_op for this cmp because it would get
+            confused by the ptr to method types and think we want pmfs.  */
+         e3 = build (EQ_EXPR, boolean_type_node, pfn0, pfn1);
          e2 = build_binary_op (TRUTH_ORIF_EXPR, e2, e3);
          e2 = build_binary_op (TRUTH_ANDIF_EXPR, e1, e2);
          if (code == EQ_EXPR)
@@ -3673,7 +3684,7 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code)
          return build_binary_op (EQ_EXPR, e2, integer_zero_node);
        }
       else if (TYPE_PTRMEMFUNC_P (type0)
-              && TYPE_PTRMEMFUNC_FN_TYPE (type0) == type1)
+              && same_type_p (TYPE_PTRMEMFUNC_FN_TYPE (type0), type1))
        {
          tree index0 = build_component_ref (op0, index_identifier,
                                             NULL_TREE, 0);
@@ -3712,7 +3723,9 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code)
          e2 = build_binary_op (NE_EXPR, index1, integer_neg_one_node);
          e2 = build_binary_op (TRUTH_ANDIF_EXPR, e2,
                                build_binary_op (EQ_EXPR, delta20, delta21));
-         e3 = build_binary_op (EQ_EXPR, pfn0, op1);
+         /* We can't use build_binary_op for this cmp because it would get
+            confused by the ptr to method types and think we want pmfs.  */
+         e3 = build (EQ_EXPR, boolean_type_node, pfn0, op1);
          e2 = build_binary_op (TRUTH_ORIF_EXPR, e2, e3);
          e2 = build_binary_op (TRUTH_ANDIF_EXPR, e1, e2);
          if (code == EQ_EXPR)
@@ -3720,7 +3733,7 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code)
          return build_binary_op (EQ_EXPR, e2, integer_zero_node);
        }
       else if (TYPE_PTRMEMFUNC_P (type1)
-              && TYPE_PTRMEMFUNC_FN_TYPE (type1) == type0)
+              && same_type_p (TYPE_PTRMEMFUNC_FN_TYPE (type1), type0))
        return build_binary_op (code, op1, op0);
       break;
 
@@ -5718,9 +5731,7 @@ build_c_cast (type, expr)
       && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
     value = TREE_OPERAND (value, 0);
 
-  if (TREE_TYPE (expr)
-      && TREE_CODE (TREE_TYPE (expr)) == OFFSET_TYPE
-      && TREE_CODE (type) != OFFSET_TYPE)
+  if (TREE_CODE (value) == OFFSET_REF || BASELINK_P (value))
     value = resolve_offset_ref (value);
 
   if (TREE_CODE (type) == ARRAY_TYPE)
@@ -6687,40 +6698,23 @@ convert_for_assignment (type, rhs, errtype, fndecl, parmnum)
 {
   register enum tree_code codel = TREE_CODE (type);
   register tree rhstype;
-  register enum tree_code coder = TREE_CODE (TREE_TYPE (rhs));
-
-  /* Issue warnings about peculiar, but legal, uses of NULL.  */
-  if (ARITHMETIC_TYPE_P (type) && rhs == null_node)
-    cp_warning ("converting NULL to non-pointer type");
-
-  if (coder == ERROR_MARK)
-    return error_mark_node;
+  register enum tree_code coder;
 
   if (codel == OFFSET_TYPE)
-    {
-      type = TREE_TYPE (type);
-      codel = TREE_CODE (type);
-    }
+    my_friendly_abort (990505);
+
+  if (TREE_CODE (rhs) == OFFSET_REF || BASELINK_P (rhs))
+    rhs = resolve_offset_ref (rhs);
 
   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
   if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
     rhs = TREE_OPERAND (rhs, 0);
 
-  if (rhs == error_mark_node)
+  if (rhs == error_mark_node || TREE_TYPE (rhs) == error_mark_node)
     return error_mark_node;
-
   if (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node)
     return error_mark_node;
 
-  if (TREE_CODE (TREE_TYPE (rhs)) == OFFSET_TYPE)
-    {
-      rhs = resolve_offset_ref (rhs);
-      if (rhs == error_mark_node)
-       return error_mark_node;
-      rhstype = TREE_TYPE (rhs);
-      coder = TREE_CODE (rhstype);
-    }
-
   if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
       || is_overloaded_fn (rhs))
     rhs = default_conversion (rhs);
@@ -6736,6 +6730,10 @@ convert_for_assignment (type, rhs, errtype, fndecl, parmnum)
   rhstype = TREE_TYPE (rhs);
   coder = TREE_CODE (rhstype);
 
+  /* Issue warnings about peculiar, but legal, uses of NULL.  */
+  if (ARITHMETIC_TYPE_P (type) && rhs == null_node)
+    cp_warning ("converting NULL to non-pointer type");
+
   /* This should no longer change types on us.  */
   if (TREE_CODE (rhs) == CONST_DECL)
     rhs = DECL_INITIAL (rhs);
@@ -7135,7 +7133,7 @@ convert_for_initialization (exp, type, rhs, flags, errtype, fndecl, parmnum)
       || (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node))
     return error_mark_node;
 
-  if (TREE_CODE (TREE_TYPE (rhs)) == OFFSET_TYPE)
+  if (TREE_CODE (rhs) == OFFSET_REF || BASELINK_P (rhs))
     {
       rhs = resolve_offset_ref (rhs);
       if (rhs == error_mark_node)