OSDN Git Service

* typeck.c (build_array_ref): Take complain parm.
[pf3gnuchains/gcc-fork.git] / gcc / cp / decl2.c
index 53f66ad..ae7c2ab 100644 (file)
@@ -139,6 +139,34 @@ build_memfn_type (tree fntype, tree ctype, cp_cv_quals quals)
   return fntype;
 }
 
+/* Return a variant of FNTYPE, a FUNCTION_TYPE or METHOD_TYPE, with its
+   return type changed to NEW_RET.  */
+
+tree
+change_return_type (tree new_ret, tree fntype)
+{
+  tree newtype;
+  tree args = TYPE_ARG_TYPES (fntype);
+  tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
+  tree attrs = TYPE_ATTRIBUTES (fntype);
+
+  if (same_type_p (new_ret, TREE_TYPE (fntype)))
+    return fntype;
+
+  if (TREE_CODE (fntype) == FUNCTION_TYPE)
+    newtype = build_function_type (new_ret, args);
+  else
+    newtype = build_method_type_directly
+      (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))),
+       new_ret, TREE_CHAIN (args));
+  if (raises)
+    newtype = build_exception_variant (newtype, raises);
+  if (attrs)
+    newtype = cp_build_type_attribute_variant (newtype, attrs);
+
+  return newtype;
+}
+
 /* Build a PARM_DECL with NAME and TYPE, and set DECL_ARG_TYPE
    appropriately.  */
 
@@ -371,7 +399,8 @@ grok_array_decl (tree array_expr, tree index_exp)
       if (array_expr == error_mark_node || index_exp == error_mark_node)
        error ("ambiguous conversion for array subscript");
 
-      expr = build_array_ref (input_location, array_expr, index_exp);
+      expr = build_array_ref (input_location, array_expr, index_exp,
+                             tf_warning_or_error);
     }
   if (processing_template_decl && expr != error_mark_node)
     return build_min_non_dep (ARRAY_REF, expr, orig_array_expr, orig_index_exp,
@@ -757,6 +786,10 @@ finish_static_data_member_decl (tree decl,
   DECL_INITIAL (decl) = init;
   DECL_IN_AGGR_P (decl) = 1;
 
+  if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
+      && TYPE_DOMAIN (TREE_TYPE (decl)) == NULL_TREE)
+    SET_VAR_HAD_UNKNOWN_BOUND (decl);
+
   cp_finish_decl (decl, init, init_const_expr_p, asmspec_tree, flags);
 }
 
@@ -789,7 +822,7 @@ grokfield (const cp_declarator *declarator,
 
   if (TREE_CODE (value) == TYPE_DECL && init)
     {
-      error ("typedef %qD is initialized (use __typeof__ instead)", value);
+      error ("typedef %qD is initialized (use decltype instead)", value);
       init = NULL_TREE;
     }
 
@@ -844,7 +877,7 @@ grokfield (const cp_declarator *declarator,
       if (declspecs->specs[(int)ds_typedef]
           && TREE_TYPE (value) != error_mark_node
           && TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (value))) != value)
-       set_underlying_type (value);
+       cp_set_underlying_type (value);
 
       return value;
     }
@@ -881,8 +914,13 @@ grokfield (const cp_declarator *declarator,
            }
          else if (TREE_CODE (TREE_TYPE (value)) == METHOD_TYPE)
            {
-             gcc_assert (error_operand_p (init) || integer_zerop (init));
-             DECL_PURE_VIRTUAL_P (value) = 1;
+             if (integer_zerop (init))
+               DECL_PURE_VIRTUAL_P (value) = 1;
+             else if (error_operand_p (init))
+               ; /* An error has already been reported.  */
+             else
+               error ("invalid initializer for member function %qD",
+                      value);
            }
          else
            {
@@ -1313,6 +1351,7 @@ build_anon_union_vars (tree type, tree object)
          decl = build_decl (input_location,
                             VAR_DECL, DECL_NAME (field), TREE_TYPE (field));
          DECL_ANON_UNION_VAR_P (decl) = 1;
+         DECL_ARTIFICIAL (decl) = 1;
 
          base = get_base_address (object);
          TREE_PUBLIC (decl) = TREE_PUBLIC (base);
@@ -1573,8 +1612,7 @@ comdat_linkage (tree decl)
        }
     }
 
-  if (DECL_LANG_SPECIFIC (decl))
-    DECL_COMDAT (decl) = 1;
+  DECL_COMDAT (decl) = 1;
 }
 
 /* For win32 we also want to put explicit instantiations in
@@ -1615,20 +1653,22 @@ maybe_make_one_only (tree decl)
     }
 }
 
-/* Returns true iff DECL, a FUNCTION_DECL, has vague linkage.  This
-   predicate will give the right answer during parsing of the function,
-   which other tests may not.  */
+/* Returns true iff DECL, a FUNCTION_DECL or VAR_DECL, has vague linkage.
+   This predicate will give the right answer during parsing of the
+   function, which other tests may not.  */
 
 bool
-vague_linkage_fn_p (tree fn)
+vague_linkage_p (tree decl)
 {
   /* Unfortunately, import_export_decl has not always been called
      before the function is processed, so we cannot simply check
      DECL_COMDAT.  */
-  return (DECL_COMDAT (fn)
-         || ((DECL_DECLARED_INLINE_P (fn)
-              || DECL_TEMPLATE_INSTANTIATION (fn))
-             && TREE_PUBLIC (fn)));
+  return (DECL_COMDAT (decl)
+         || (((TREE_CODE (decl) == FUNCTION_DECL
+               && DECL_DECLARED_INLINE_P (decl))
+              || (DECL_LANG_SPECIFIC (decl)
+                  && DECL_TEMPLATE_INSTANTIATION (decl)))
+             && TREE_PUBLIC (decl)));
 }
 
 /* Determine whether or not we want to specifically import or export CTYPE,
@@ -1883,6 +1923,8 @@ constrain_visibility (tree decl, int visibility)
       if (!DECL_EXTERN_C_P (decl))
        {
          TREE_PUBLIC (decl) = 0;
+         DECL_WEAK (decl) = 0;
+         DECL_COMMON (decl) = 0;
          DECL_COMDAT_GROUP (decl) = NULL_TREE;
          DECL_INTERFACE_KNOWN (decl) = 1;
          if (DECL_LANG_SPECIFIC (decl))
@@ -2552,7 +2594,9 @@ get_guard (tree decl)
       TREE_PUBLIC (guard) = TREE_PUBLIC (decl);
       TREE_STATIC (guard) = TREE_STATIC (decl);
       DECL_COMMON (guard) = DECL_COMMON (decl);
-      DECL_COMDAT_GROUP (guard) = DECL_COMDAT_GROUP (decl);
+      DECL_COMDAT (guard) = DECL_COMDAT (decl);
+      if (DECL_ONE_ONLY (decl))
+       make_decl_one_only (guard, cxx_comdat_group (guard));
       if (TREE_PUBLIC (decl))
        DECL_WEAK (guard) = DECL_WEAK (decl);
       DECL_VISIBILITY (guard) = DECL_VISIBILITY (decl);
@@ -3655,7 +3699,36 @@ cp_write_global_declarations (void)
          if (DECL_NOT_REALLY_EXTERN (decl)
              && DECL_INITIAL (decl)
              && decl_needed_p (decl))
-           DECL_EXTERNAL (decl) = 0;
+           {
+             struct cgraph_node *node = cgraph_get_node (decl), *alias, *next;
+
+             DECL_EXTERNAL (decl) = 0;
+             /* If we mark !DECL_EXTERNAL one of the same body aliases,
+                we need to mark all of them that way.  */
+             if (node && node->same_body)
+               {
+                 DECL_EXTERNAL (node->decl) = 0;
+                 for (alias = node->same_body; alias; alias = alias->next)
+                   DECL_EXTERNAL (alias->decl) = 0;
+               }
+             /* If we mark !DECL_EXTERNAL one of the symbols in some comdat
+                group, we need to mark all symbols in the same comdat group
+                that way.  */
+             if (node->same_comdat_group)
+               for (next = node->same_comdat_group;
+                    next != node;
+                    next = next->same_comdat_group)
+                 {
+                   DECL_EXTERNAL (next->decl) = 0;
+                   if (next->same_body)
+                     {
+                       for (alias = next->same_body;
+                            alias;
+                            alias = alias->next)
+                         DECL_EXTERNAL (alias->decl) = 0;
+                     }
+                 }
+           }
 
          /* If we're going to need to write this function out, and
             there's already a body for it, create RTL for it now.
@@ -3939,6 +4012,18 @@ mark_used (tree decl)
   if (TREE_CODE (decl) == FUNCTION_DECL
       && DECL_DELETED_FN (decl))
     {
+      if (DECL_ARTIFICIAL (decl))
+       {
+         if (DECL_OVERLOADED_OPERATOR_P (decl) == TYPE_EXPR
+             && LAMBDA_TYPE_P (DECL_CONTEXT (decl)))
+           {
+             /* We mark a lambda conversion op as deleted if we can't
+                generate it properly; see maybe_add_lambda_conv_op.  */
+             sorry ("converting lambda which uses %<...%> to "
+                    "function pointer");
+             return;
+           }
+       }
       error ("deleted function %q+D", decl);
       error ("used here");
       return;