re PR c++/5388 (Incorrect message "operands to ?: have different types")
authorJason Merrill <jason@gcc.gnu.org>
Thu, 15 May 2003 22:25:51 +0000 (18:25 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 15 May 2003 22:25:51 +0000 (18:25 -0400)
        PR c++/5388
        * call.c (conditional_conversion): Don't consider implicit
        conversions if T2 is a base of T1.
        * cp-tree.h (DERIVED_FROM_P, UNIQUELY_DERIVED_FROM_P): Make boolean.
        (ACCESSIBLY_UNIQUELY_DERIVED_P, PUBLICLY_UNIQUELY_DERIVED_P): Likewise.

        * parser.c (cp_parser_primary_expression): Convert a static data
        member from reference.

From-SVN: r66844

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/cp-tree.h
gcc/cp/parser.c

index 8e8d3e9a76aad82a01f12f34ec9df729c5347c7d..403c7fede1dcdd36ac2dfaa161d4ad4f674563c0 100644 (file)
@@ -1,3 +1,14 @@
+2003-05-15  Jason Merrill  <jason@redhat.com>
+
+       PR c++/5388
+       * call.c (conditional_conversion): Don't consider implicit
+       conversions if T2 is a base of T1. 
+       * cp-tree.h (DERIVED_FROM_P, UNIQUELY_DERIVED_FROM_P): Make boolean.
+       (ACCESSIBLY_UNIQUELY_DERIVED_P, PUBLICLY_UNIQUELY_DERIVED_P): Likewise.
+
+       * parser.c (cp_parser_primary_expression): Convert a static data
+       member from reference.
+
 2003-05-15  Mark Mitchell  <mark@codesourcery.com>
 
        * call.c (build_op_delete_call): Avoid creating unnecessary types.
 
 2003-05-07  Richard Henderson  <rth@redhat.com>
 
-        PR c++/10570
-        * cfns.gperf: Comment out POSIX thread cancellation points,
-        plus abort and raise.
-        * cfns.h: Regenerate.
+       PR c++/10570
+       * cfns.gperf: Comment out POSIX thread cancellation points,
+       plus abort and raise.
+       * cfns.h: Regenerate.
 
 2003-05-07  Jason Merrill  <jason@redhat.com>
 
index 1d40e4251072402f2952361ac5c2005f157221ee..d40a60cc7a1cd35b86f76eb7257400c155490e21 100644 (file)
@@ -3161,6 +3161,7 @@ conditional_conversion (tree e1, tree e2)
   tree t1 = non_reference (TREE_TYPE (e1));
   tree t2 = non_reference (TREE_TYPE (e2));
   tree conv;
+  bool good_base;
 
   /* [expr.cond]
 
@@ -3192,10 +3193,9 @@ conditional_conversion (tree e1, tree e2)
      FIXME we can't express an rvalue that refers to the original object;
      we have to create a new one.  */
   if (CLASS_TYPE_P (t1) && CLASS_TYPE_P (t2)
-      && same_or_base_type_p (TYPE_MAIN_VARIANT (t2), 
-                             TYPE_MAIN_VARIANT (t1)))
+      && ((good_base = DERIVED_FROM_P (t2, t1)) || DERIVED_FROM_P (t1, t2)))
     {
-      if (at_least_as_qualified_p (t2, t1))
+      if (good_base && at_least_as_qualified_p (t2, t1))
        {
          conv = build1 (IDENTITY_CONV, t1, e1);
          if (!same_type_p (TYPE_MAIN_VARIANT (t1), 
@@ -3211,13 +3211,13 @@ conditional_conversion (tree e1, tree e2)
       else
        return NULL_TREE;
     }
+  else
+    /* [expr.cond]
 
-  /* [expr.cond]
-
-     E1 can be converted to match E2 if E1 can be implicitly converted
-     to the type that expression E2 would have if E2 were converted to
-     an rvalue (or the type it has, if E2 is an rvalue).  */
-  return implicit_conversion (t2, t1, e1, LOOKUP_NORMAL);
+       Otherwise: E1 can be converted to match E2 if E1 can be implicitly
+       converted to the type that expression E2 would have if E2 were
+       converted to an rvalue (or the type it has, if E2 is an rvalue).  */
+    return implicit_conversion (t2, t1, e1, LOOKUP_NORMAL);
 }
 
 /* Implement [expr.cond].  ARG1, ARG2, and ARG3 are the three
index 78568edec2bebed6de49d7428db0c7904ebe3304..6bb2e0ddc51fd6ec2b4b8c8aa1b216a102157216 100644 (file)
@@ -992,18 +992,19 @@ enum languages { lang_c, lang_cplusplus, lang_java };
 /* Nonzero iff TYPE is derived from PARENT. Ignores accessibility and
    ambiguity issues.  */
 #define DERIVED_FROM_P(PARENT, TYPE) \
-  lookup_base ((TYPE), PARENT, ba_any, NULL)
+  (lookup_base ((TYPE), PARENT, ba_any, NULL) != NULL_TREE)
 /* Nonzero iff TYPE is uniquely derived from PARENT. Ignores
    accessibility.  */
 #define UNIQUELY_DERIVED_FROM_P(PARENT, TYPE) \
-  lookup_base ((TYPE), (PARENT), ba_ignore | ba_quiet, NULL)
+  (lookup_base ((TYPE), (PARENT), ba_ignore | ba_quiet, NULL) != NULL_TREE)
 /* Nonzero iff TYPE is accessible in the current scope and uniquely
    derived from PARENT.  */
 #define ACCESSIBLY_UNIQUELY_DERIVED_P(PARENT, TYPE) \
-  lookup_base ((TYPE), (PARENT), ba_check | ba_quiet, NULL)
+  (lookup_base ((TYPE), (PARENT), ba_check | ba_quiet, NULL) != NULL_TREE)
 /* Nonzero iff TYPE is publicly & uniquely derived from PARENT.  */
 #define PUBLICLY_UNIQUELY_DERIVED_P(PARENT, TYPE) \
-  lookup_base ((TYPE), (PARENT),  ba_not_special | ba_quiet, NULL)
+  (lookup_base ((TYPE), (PARENT),  ba_not_special | ba_quiet, NULL) \
+   != NULL_TREE)
 \f
 /* This is a few header flags for 'struct lang_type'.  Actually,
    all but the first are used only for lang_type_class; they
@@ -3364,7 +3365,7 @@ enum overload_flags { NO_SPECIAL = 0, DTOR_FLAG, OP_FLAG, TYPENAME_FLAG };
                                   type is derived from the pointed to
                                   by the first.  */
 #define COMPARE_RELAXED       2 /* Like COMPARE_DERIVED, but in
-                                  reverse.  Also treat enmeration
+                                  reverse.  Also treat enumeration
                                   types as the same as integer types
                                   of the same width.  */
 #define COMPARE_REDECLARATION 4 /* The comparsion is being done when
index 1d0ab40b4cf21a8fbe5e835fde56c5117d4a0db6..cf768e0ac8db68ba99a5edaa9850e1a7c202b4ba 100644 (file)
@@ -2800,6 +2800,8 @@ cp_parser_primary_expression (cp_parser *parser,
                        (decl, parser->scope, current_class_type));
                if (TREE_CODE (decl) == FIELD_DECL || BASELINK_P (decl))
                  *qualifying_class = parser->scope;
+               else if (!processing_template_decl)
+                 decl = convert_from_reference (decl);
              }
            else
              /* Transform references to non-static data members into