OSDN Git Service

PR c++/44157
[pf3gnuchains/gcc-fork.git] / gcc / cp / tree.c
index 7097f8c..67bbd60 100644 (file)
@@ -41,7 +41,6 @@ along with GCC; see the file COPYING3.  If not see
 
 static tree bot_manip (tree *, int *, void *);
 static tree bot_replace (tree *, int *, void *);
-static tree build_cplus_array_type_1 (tree, tree);
 static int list_hash_eq (const void *, const void *);
 static hashval_t list_hash_pieces (tree, tree, tree);
 static hashval_t list_hash (const void *);
@@ -552,6 +551,8 @@ rvalue (tree expr)
   if (error_operand_p (expr))
     return expr;
 
+  expr = mark_rvalue_use (expr);
+
   /* [basic.lval]
 
      Non-class rvalues always have cv-unqualified types.  */
@@ -601,14 +602,14 @@ cplus_array_compare (const void * k1, const void * k2)
   return (TREE_TYPE (t1) == t2->type && TYPE_DOMAIN (t1) == t2->domain);
 }
 
-/* Hash table containing all of the C++ array types, including
-   dependent array types and array types whose element type is
-   cv-qualified.  */
+/* Hash table containing dependent array types, which are unsuitable for
+   the language-independent type hash table.  */
 static GTY ((param_is (union tree_node))) htab_t cplus_array_htab;
 
+/* Like build_array_type, but handle special C++ semantics.  */
 
-static tree
-build_cplus_array_type_1 (tree elt_type, tree index_type)
+tree
+build_cplus_array_type (tree elt_type, tree index_type)
 {
   tree t;
 
@@ -665,6 +666,20 @@ build_cplus_array_type_1 (tree elt_type, tree index_type)
   else
     t = build_array_type (elt_type, index_type);
 
+  /* We want TYPE_MAIN_VARIANT of an array to strip cv-quals from the
+     element type as well, so fix it up if needed.  */
+  if (elt_type != TYPE_MAIN_VARIANT (elt_type))
+    {
+      tree m = build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type),
+                                      index_type);
+      if (TYPE_MAIN_VARIANT (t) != m)
+       {
+         TYPE_MAIN_VARIANT (t) = m;
+         TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
+         TYPE_NEXT_VARIANT (m) = t;
+       }
+    }
+
   /* Push these needs up so that initialization takes place
      more easily.  */
   TYPE_NEEDS_CONSTRUCTING (t)
@@ -674,23 +689,6 @@ build_cplus_array_type_1 (tree elt_type, tree index_type)
   return t;
 }
 
-tree
-build_cplus_array_type (tree elt_type, tree index_type)
-{
-  tree t;
-  int type_quals = cp_type_quals (elt_type);
-
-  if (type_quals != TYPE_UNQUALIFIED)
-    elt_type = cp_build_qualified_type (elt_type, TYPE_UNQUALIFIED);
-
-  t = build_cplus_array_type_1 (elt_type, index_type);
-
-  if (type_quals != TYPE_UNQUALIFIED)
-    t = cp_build_qualified_type (t, type_quals);
-
-  return t;
-}
-
 /* Return an ARRAY_TYPE with element type ELT and length N.  */
 
 tree
@@ -811,41 +809,27 @@ cp_build_qualified_type_real (tree type,
       if (element_type == error_mark_node)
        return error_mark_node;
 
-      /* See if we already have an identically qualified type.  */
+      /* See if we already have an identically qualified type.  Tests
+        should be equivalent to those in check_qualified_type.  */
       for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
        if (cp_type_quals (t) == type_quals
            && TYPE_NAME (t) == TYPE_NAME (type)
-           && TYPE_CONTEXT (t) == TYPE_CONTEXT (type))
+           && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
+           && attribute_list_equal (TYPE_ATTRIBUTES (t),
+                                    TYPE_ATTRIBUTES (type)))
          break;
 
       if (!t)
-      {
-       t = build_cplus_array_type_1 (element_type, TYPE_DOMAIN (type));
+       {
+         t = build_cplus_array_type (element_type, TYPE_DOMAIN (type));
 
-       if (TYPE_MAIN_VARIANT (t) != TYPE_MAIN_VARIANT (type))
-         {
-           /* Set the main variant of the newly-created ARRAY_TYPE
-              (with cv-qualified element type) to the main variant of
-              the unqualified ARRAY_TYPE we started with.  */
-           tree last_variant = t;
-           tree m = TYPE_MAIN_VARIANT (type);
-
-           /* Find the last variant on the new ARRAY_TYPEs list of
-              variants, setting the main variant of each of the other
-              types to the main variant of our unqualified
-              ARRAY_TYPE.  */
-           while (TYPE_NEXT_VARIANT (last_variant))
-             {
-               TYPE_MAIN_VARIANT (last_variant) = m;
-               last_variant = TYPE_NEXT_VARIANT (last_variant);
-             }
-
-           /* Splice in the newly-created variants.  */
-           TYPE_NEXT_VARIANT (last_variant) = TYPE_NEXT_VARIANT (m);
-           TYPE_NEXT_VARIANT (m) = t;
-           TYPE_MAIN_VARIANT (last_variant) = m;
-         }
-      }
+         /* Keep the typedef name.  */
+         if (TYPE_NAME (t) != TYPE_NAME (type))
+           {
+             t = build_variant_type_copy (t);
+             TYPE_NAME (t) = TYPE_NAME (type);
+           }
+       }
 
       /* Even if we already had this variant, we update
         TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case
@@ -952,7 +936,12 @@ cp_build_qualified_type_real (tree type,
 tree
 cv_unqualified (tree type)
 {
-  int quals = TYPE_QUALS (type);
+  int quals;
+
+  if (type == error_mark_node)
+    return type;
+
+  quals = TYPE_QUALS (type);
   quals &= ~(TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE);
   return cp_build_qualified_type (type, quals);
 }
@@ -1083,12 +1072,11 @@ void
 cp_set_underlying_type (tree t)
 {
   set_underlying_type (t);
-  /* If the typedef variant type is dependent, make it require
-     structural equality.
-     This is useful when comparing two dependent typedef variant types,
+  /* If T is a template type parm, make it require structural equality.
+     This is useful when comparing two template type parms,
      because it forces the comparison of the template parameters of their
-     decls for instance.  */
-  if (dependent_type_p (TREE_TYPE (t)))
+     decls.  */
+  if (TREE_CODE (TREE_TYPE (t)) == TEMPLATE_TYPE_PARM)
     SET_TYPE_STRUCTURAL_EQUALITY (TREE_TYPE (t));
 }
 
@@ -1366,7 +1354,7 @@ really_overloaded_fn (tree x)
 }
 
 tree
-get_first_fn (tree from)
+get_fns (tree from)
 {
   gcc_assert (is_overloaded_fn (from));
   /* A baselink is also considered an overloaded function.  */
@@ -1377,7 +1365,13 @@ get_first_fn (tree from)
     from = BASELINK_FUNCTIONS (from);
   if (TREE_CODE (from) == TEMPLATE_ID_EXPR)
     from = TREE_OPERAND (from, 0);
-  return OVL_CURRENT (from);
+  return from;
+}
+
+tree
+get_first_fn (tree from)
+{
+  return OVL_CURRENT (get_fns (from));
 }
 
 /* Return a new OVL node, concatenating it with the old one.  */
@@ -1613,7 +1607,7 @@ no_linkage_check (tree t, bool relaxed_p)
       /* Fall through.  */
     case ENUMERAL_TYPE:
       /* Only treat anonymous types as having no linkage if they're at
-        namespace scope.  This doesn't have a core issue number yet.  */
+        namespace scope.  This is core issue 966.  */
       if (TYPE_ANONYMOUS_P (t) && TYPE_NAMESPACE_SCOPE_P (t))
        return t;
 
@@ -1626,7 +1620,7 @@ no_linkage_check (tree t, bool relaxed_p)
            return no_linkage_check (TYPE_CONTEXT (t), relaxed_p);
          else if (TREE_CODE (r) == FUNCTION_DECL)
            {
-             if (!relaxed_p || !vague_linkage_fn_p (r))
+             if (!relaxed_p || !vague_linkage_p (r))
                return t;
              else
                r = CP_DECL_CONTEXT (r);
@@ -1683,6 +1677,7 @@ cxx_print_statistics (void)
 {
   print_search_statistics ();
   print_class_statistics ();
+  print_template_statistics ();
 #ifdef GATHER_STATISTICS
   fprintf (stderr, "maximum template instantiation depth reached: %d\n",
           depth_reached);
@@ -2061,7 +2056,9 @@ cp_tree_equal (tree t1, tree t2)
               arg2 = next_call_expr_arg (&iter2))
          if (!cp_tree_equal (arg1, arg2))
            return false;
-       return (arg1 || arg2);
+       if (arg1 || arg2)
+         return false;
+       return true;
       }
 
     case TARGET_EXPR:
@@ -2292,7 +2289,7 @@ tree
 build_dummy_object (tree type)
 {
   tree decl = build1 (NOP_EXPR, build_pointer_type (type), void_zero_node);
-  return cp_build_indirect_ref (decl, NULL, tf_warning_or_error);
+  return cp_build_indirect_ref (decl, RO_NULL, tf_warning_or_error);
 }
 
 /* We've gotten a reference to a member of TYPE.  Return *this if appropriate,
@@ -2304,11 +2301,11 @@ maybe_dummy_object (tree type, tree* binfop)
 {
   tree decl, context;
   tree binfo;
+  tree current = current_nonlambda_class_type ();
 
-  if (current_class_type
-      && (binfo = lookup_base (current_class_type, type,
-                              ba_unique | ba_quiet, NULL)))
-    context = current_class_type;
+  if (current
+      && (binfo = lookup_base (current, type, ba_any, NULL)))
+    context = current;
   else
     {
       /* Reference from a nested class member function.  */
@@ -2326,6 +2323,13 @@ maybe_dummy_object (tree type, tree* binfop)
       && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (current_class_ref)),
                      current_class_type))
     decl = current_class_ref;
+  else if (current != current_class_type
+          && context == nonlambda_method_basetype ())
+    /* In a lambda, need to go through 'this' capture.  */
+    decl = (cp_build_indirect_ref
+           ((lambda_expr_this_capture
+             (CLASSTYPE_LAMBDA_EXPR (current_class_type))),
+            RO_NULL, tf_warning_or_error));
   else
     decl = build_dummy_object (context);
 
@@ -2407,7 +2411,9 @@ pod_type_p (const_tree t)
      argument unmodified and we assign it to a const_tree.  */
   t = strip_array_types (CONST_CAST_TREE(t));
 
-  if (CLASS_TYPE_P (t))
+  if (!CLASS_TYPE_P (t))
+    return scalarish_type_p (t);
+  else if (cxx_dialect > cxx98)
     /* [class]/10: A POD struct is a class that is both a trivial class and a
        standard-layout class, and has no non-static data members of type
        non-POD struct, non-POD union (or array of such types).
@@ -2416,7 +2422,8 @@ pod_type_p (const_tree t)
        non-std-layout or non-trivial, the class will be too.  */
     return (std_layout_type_p (t) && trivial_type_p (t));
   else
-    return scalarish_type_p (t);
+    /* The C++98 definition of POD is different.  */
+    return !CLASSTYPE_NON_LAYOUT_POD_P (t);
 }
 
 /* Returns true iff T is POD for the purpose of layout, as defined in the
@@ -2956,7 +2963,7 @@ stabilize_expr (tree exp, tree* initp)
       exp = cp_build_unary_op (ADDR_EXPR, exp, 1, tf_warning_or_error);
       init_expr = get_target_expr (exp);
       exp = TARGET_EXPR_SLOT (init_expr);
-      exp = cp_build_indirect_ref (exp, 0, tf_warning_or_error);
+      exp = cp_build_indirect_ref (exp, RO_NULL, tf_warning_or_error);
     }
   *initp = init_expr;