[multiple changes]
authorJason Merrill <jason@gcc.gnu.org>
Sun, 7 Dec 1997 10:01:16 +0000 (05:01 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Sun, 7 Dec 1997 10:01:16 +0000 (05:01 -0500)
Sun Dec  7 01:46:33 1997  Bruno Haible  <bruno@linuix.mathematik.uni-karlsruhe.de>

* typeck.c (build_binary_op_nodefault, pointer_diff): Symmetric
handling of pointer difference expressions.

* typeck.c (comp_target_types): Comparison of function/method types
is independent of nptrs.

Sun Dec  7 01:40:27 1997  Mark Mitchell  <mmitchell@usa.net>

* pt.c (tsubst): Avoid creating pointer to reference and
reference to reference types.

From-SVN: r16990

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/cp/typeck.c

index 5c988a22da444535dac971b02770d0575e3b8717..2d01038dfcba2f56ddd57c3fb09edb4187165d81 100644 (file)
@@ -1,3 +1,16 @@
+Sun Dec  7 01:46:33 1997  Bruno Haible  <bruno@linuix.mathematik.uni-karlsruhe.de>
+
+       * typeck.c (build_binary_op_nodefault, pointer_diff): Symmetric
+       handling of pointer difference expressions.
+
+       * typeck.c (comp_target_types): Comparison of function/method types
+       is independent of nptrs.
+
+Sun Dec  7 01:40:27 1997  Mark Mitchell  <mmitchell@usa.net>
+
+       * pt.c (tsubst): Avoid creating pointer to reference and
+       reference to reference types.
+
 Sat Dec  6 01:29:37 1997  Jason Merrill  <jason@yorick.cygnus.com>
 
        * parse.y (do_id): New nonterminal.
index 2567127fd2fc9f76d088fb24729d07eda08076e2..ec581d5873786c5579b1142f2e77d1b1308965e9 100644 (file)
@@ -2675,15 +2675,43 @@ tsubst (t, args, nargs, in_decl)
       {
        tree r;
        enum tree_code code;
+
        if (type == TREE_TYPE (t))
          return t;
 
        code = TREE_CODE (t);
-       if (code == POINTER_TYPE)
+       if (TREE_CODE (type) == REFERENCE_TYPE) 
+         {
+           static int   last_line = 0;
+           static char* last_file = 0;
+
+           /* We keep track of the last time we issued this error
+              message to avoid spewing a ton of messages during a
+              single bad template instantiation.  */
+           if (last_line != lineno ||
+               last_file != input_filename)
+             {
+               cp_error ("cannot form type %s to reference type %T during template instantiation",
+                         (code == POINTER_TYPE) ? "pointer" : "reference",
+                         type);
+               last_line = lineno;
+               last_file = input_filename;
+             }
+
+           /* Use the underlying type in an attempt at error
+              recovery; maybe the user meant vector<int> and wrote
+              vector<int&>, or some such.  */
+           if (code == REFERENCE_TYPE)
+             r = type;
+           else
+             r = build_pointer_type (TREE_TYPE (type));
+         }
+       else if (code == POINTER_TYPE)
          r = build_pointer_type (type);
        else
          r = build_reference_type (type);
        r = cp_build_type_variant (r, TYPE_READONLY (t), TYPE_VOLATILE (t));
+
        /* Will this ever be needed for TYPE_..._TO values?  */
        layout_type (r);
        return r;
index 10e25178f3b57ba0bcb742cc70c5b4d1b784d07b..2739333e5338490a21acdfc2bf86f49752f7eade 100644 (file)
@@ -58,7 +58,7 @@ static tree build_ptrmemfunc1 PROTO((tree, tree, tree, tree, tree));
 static tree common_base_type PROTO((tree, tree));
 static tree convert_sequence PROTO((tree, tree));
 static tree lookup_anon_field PROTO((tree, tree));
-static tree pointer_diff PROTO((tree, tree));
+static tree pointer_diff PROTO((tree, tree, tree));
 static tree qualify_type PROTO((tree, tree));
 static tree expand_target_expr PROTO((tree));
 static tree get_delta_difference PROTO((tree, tree, int));
@@ -647,9 +647,9 @@ comp_array_types (cmp, t1, t2, strict)
        0 : <= (compared according to C++)
        -1: <= or >= (relaxed)
 
-   Otherwise, pointers involving base classes and derived classes
-   can be mixed as valid: i.e. a pointer to a base class may be assigned
-   to a pointer to one of its derived classes, as per C++. A pointer to
+   Otherwise, pointers involving base classes and derived classes can
+   be mixed as valid: i.e. a pointer to a derived class may be converted
+   to a pointer to one of its base classes, as per C++. A pointer to
    a derived class may be passed as a parameter to a function expecting a
    pointer to a base classes. These allowances do not commute. In this
    case, TYPE1 is assumed to be the base class, and TYPE2 is assumed to
@@ -848,8 +848,10 @@ comptypes (type1, type2, strict)
   return attrval == 2 && val == 1 ? 2 : val;
 }
 
-/* Return 1 if TTL and TTR are pointers to types that are equivalent,
-   ignoring their qualifiers.
+/* Return 1 or -1 if TTL and TTR are pointers to types that are equivalent,
+   ignoring their qualifiers, 0 if not. Return 1 means that TTR can be
+   converted to TTL. Return -1 means that TTL can be converted to TTR but
+   not vice versa.
 
    NPTRS is the number of pointers we can strip off and keep cool.
    This is used to permit (for aggr A, aggr B) A, B* to convert to A*,
@@ -930,7 +932,7 @@ comp_target_types (ttl, ttr, nptrs)
   if (TREE_CODE (ttr) == ARRAY_TYPE)
     return comp_array_types (comp_target_types, ttl, ttr, 0);
   else if (TREE_CODE (ttr) == FUNCTION_TYPE || TREE_CODE (ttr) == METHOD_TYPE)
-    if (comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs))
+    if (comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), -1))
       switch (comp_target_parms (TYPE_ARG_TYPES (ttl), TYPE_ARG_TYPES (ttr), 1))
        {
        case 0:
@@ -3196,7 +3198,7 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code)
         We must subtract them as integers, then divide by object size.  */
       if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
          && comp_target_types (type0, type1, 1))
-       return pointer_diff (op0, op1);
+       return pointer_diff (op0, op1, common_type (type0, type1));
       /* Handle pointer minus int.  Just like pointer plus int.  */
       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
        return pointer_int_sum (MINUS_EXPR, op0, op1);
@@ -3956,12 +3958,13 @@ pointer_int_sum (resultcode, ptrop, intop)
    The resulting tree has type int.  */
 
 static tree
-pointer_diff (op0, op1)
+pointer_diff (op0, op1, ptrtype)
      register tree op0, op1;
+     register tree ptrtype;
 {
   register tree result, folded;
   tree restype = ptrdiff_type_node;
-  tree target_type = TREE_TYPE (TREE_TYPE (op0));
+  tree target_type = TREE_TYPE (ptrtype);
 
   if (pedantic || warn_pointer_arith)
     {