OSDN Git Service

* call.c (reference_binding): Allow direct binding to an array
[pf3gnuchains/gcc-fork.git] / gcc / cp / decl.c
index f772d60..895527c 100644 (file)
@@ -1,6 +1,6 @@
 /* Process declarations and variables for C++ compiler.
    Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
    Free Software Foundation, Inc.
    Contributed by Michael Tiemann (tiemann@cygnus.com)
 
@@ -45,6 +45,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tm_p.h"
 #include "target.h"
 #include "c-family/c-common.h"
+#include "c-family/c-objc.h"
 #include "c-family/c-pragma.h"
 #include "diagnostic.h"
 #include "intl.h"
@@ -177,7 +178,7 @@ tree integer_two_node;
 /* Used only for jumps to as-yet undefined labels, since jumps to
    defined labels can have their validity checked immediately.  */
 
-struct GTY(()) named_label_use_entry {
+struct GTY((chain_next ("%h.next"))) named_label_use_entry {
   struct named_label_use_entry *next;
   /* The binding level to which this entry is *currently* attached.
      This is initially the binding level in which the goto appeared,
@@ -982,7 +983,7 @@ decls_match (tree newdecl, tree olddecl)
 
       if (same_type_p (TREE_TYPE (f1), TREE_TYPE (f2)))
        {
-         if (p2 == NULL_TREE && DECL_EXTERN_C_P (olddecl)
+         if (!prototype_p (f2) && DECL_EXTERN_C_P (olddecl)
              && (DECL_BUILT_IN (olddecl)
 #ifndef NO_IMPLICIT_EXTERN_C
                  || (DECL_IN_SYSTEM_HEADER (newdecl) && !DECL_CLASS_SCOPE_P (newdecl))
@@ -995,7 +996,7 @@ decls_match (tree newdecl, tree olddecl)
                TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
            }
 #ifndef NO_IMPLICIT_EXTERN_C
-         else if (p1 == NULL_TREE
+         else if (!prototype_p (f1)
                   && (DECL_EXTERN_C_P (olddecl)
                       && DECL_IN_SYSTEM_HEADER (olddecl)
                       && !DECL_CLASS_SCOPE_P (olddecl))
@@ -1008,7 +1009,11 @@ decls_match (tree newdecl, tree olddecl)
            }
 #endif
          else
-           types_match = compparms (p1, p2);
+           types_match =
+             compparms (p1, p2)
+             && (TYPE_ATTRIBUTES (TREE_TYPE (newdecl)) == NULL_TREE
+                 || comp_type_attributes (TREE_TYPE (newdecl),
+                                          TREE_TYPE (olddecl)) != 0);
        }
       else
        types_match = 0;
@@ -1451,6 +1456,7 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend)
              error ("declaration of C function %q#D conflicts with",
                     newdecl);
              error ("previous declaration %q+#D here", olddecl);
+             return NULL_TREE;
            }
          else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
                              TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
@@ -1535,8 +1541,8 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend)
        }
       else if (TREE_CODE (olddecl) == FUNCTION_DECL
               && DECL_INITIAL (olddecl) != NULL_TREE
-              && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE
-              && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE)
+              && !prototype_p (TREE_TYPE (olddecl))
+              && prototype_p (TREE_TYPE (newdecl)))
        {
          /* Prototype decl follows defn w/o prototype.  */
          warning_at (input_location, 0, "prototype for %q+#D", newdecl);
@@ -3329,17 +3335,22 @@ record_builtin_java_type (const char* name, int size)
 {
   tree type, decl;
   if (size > 0)
-    type = build_nonstandard_integer_type (size, 0);
+    {
+      type = build_nonstandard_integer_type (size, 0);
+      type = build_distinct_type_copy (type);
+    }
   else if (size > -32)
     {
       tree stype;
       /* "__java_char" or ""__java_boolean".  */
       type = build_nonstandard_integer_type (-size, 1);
+      type = build_distinct_type_copy (type);
       /* Get the signed type cached and attached to the unsigned type,
         so it doesn't get garbage-collected at "random" times,
         causing potential codegen differences out of different UIDs
         and different alias set numbers.  */
       stype = build_nonstandard_integer_type (-size, 0);
+      stype = build_distinct_type_copy (stype);
       TREE_CHAIN (type) = stype;
       /*if (size == -1)        TREE_SET_CODE (type, BOOLEAN_TYPE);*/
     }
@@ -3696,7 +3707,10 @@ cp_make_fname_decl (location_t loc, tree id, int type_dep)
                      LOOKUP_ONLYCONVERTING);
     }
   else
-    pushdecl_top_level_and_finish (decl, init);
+    {
+      DECL_THIS_STATIC (decl) = true;
+      pushdecl_top_level_and_finish (decl, init);
+    }
 
   return decl;
 }
@@ -4583,6 +4597,9 @@ check_array_designated_initializer (const constructor_elt *ce)
       if (ce->index == error_mark_node)
        error ("name used in a GNU-style designated "
               "initializer for an array");
+      else if (TREE_CODE (ce->index) == INTEGER_CST)
+       /* An index added by reshape_init.  */
+       return true;
       else
        {
          gcc_assert (TREE_CODE (ce->index) == IDENTIFIER_NODE);
@@ -4886,7 +4903,8 @@ reshape_init_array_1 (tree elt_type, tree max_index, reshape_iter *d)
       elt_init = reshape_init_r (elt_type, d, /*first_initializer_p=*/false);
       if (elt_init == error_mark_node)
        return error_mark_node;
-      CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init), NULL_TREE, elt_init);
+      CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
+                             size_int (index), elt_init);
     }
 
   return new_init;
@@ -5811,12 +5829,10 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
   if (init && TREE_CODE (decl) == VAR_DECL)
     {
       DECL_NONTRIVIALLY_INITIALIZED_P (decl) = 1;
-      /* FIXME we rely on TREE_CONSTANT below; basing that on
-        init_const_expr_p is probably wrong for C++0x.  */
       if (init_const_expr_p)
        {
-         /* Set these flags now for C++98 templates.  We'll update the
-            flags in store_init_value for instantiations and C++0x.  */
+         /* Set these flags now for templates.  We'll update the flags in
+            store_init_value for instantiations.  */
          DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
          if (decl_maybe_constant_var_p (decl))
            TREE_CONSTANT (decl) = 1;
@@ -6093,7 +6109,9 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
                {
                  /* An out-of-class default definition is defined at
                     the point where it is explicitly defaulted.  */
-                 if (DECL_INITIAL (decl) == error_mark_node)
+                 if (DECL_DELETED_FN (decl))
+                   maybe_explain_implicit_delete (decl);
+                 else if (DECL_INITIAL (decl) == error_mark_node)
                    synthesize_method (decl);
                }
              else
@@ -7507,9 +7525,14 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
              if (size == error_mark_node)
                return error_mark_node;
              type = TREE_TYPE (size);
+             /* We didn't support this case in GCC 3.2, so don't bother
+                trying to model it now in ABI v1.  */
+             abi_1_itype = error_mark_node;
            }
 
          size = maybe_constant_value (size);
+         if (!TREE_CONSTANT (size))
+           size = osize;
        }
 
       if (error_operand_p (size))
@@ -7549,7 +7572,8 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
       return itype;
     }
   
-  if (!abi_version_at_least (2) && processing_template_decl)
+  if (!abi_version_at_least (2) && processing_template_decl
+      && abi_1_itype == NULL_TREE)
     /* For abi-1, we handled all instances in templates the same way,
        even when they were non-dependent. This affects the manglings
        produced.  So, we do the normal checking for non-dependent
@@ -7663,7 +7687,7 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
     }
 
   /* Create and return the appropriate index type.  */
-  if (abi_1_itype)
+  if (abi_1_itype && abi_1_itype != error_mark_node)
     {
       tree t = build_index_type (itype);
       TYPE_CANONICAL (abi_1_itype) = TYPE_CANONICAL (t);
@@ -9202,6 +9226,12 @@ grokdeclarator (const cp_declarator *declarator,
          error ("const %qs cannot be declared %<mutable%>", name);
          storage_class = sc_none;
        }
+      else if (TREE_CODE (type) == REFERENCE_TYPE)
+       {
+         permerror (input_location, "reference %qs cannot be declared "
+                    "%<mutable%>", name);
+         storage_class = sc_none;
+       }
     }
 
   /* If this is declaring a typedef name, return a TYPE_DECL.  */
@@ -9755,6 +9785,13 @@ grokdeclarator (const cp_declarator *declarator,
 
                if (thread_p)
                  DECL_TLS_MODEL (decl) = decl_default_tls_model (decl);
+
+               if (constexpr_p && !initialized)
+                 {
+                   error ("constexpr static data member %qD must have an "
+                          "initializer", decl);
+                   constexpr_p = false;
+                 }
              }
            else
              {
@@ -11844,7 +11881,8 @@ build_enumerator (tree name, tree value, tree enumtype, location_t loc)
        {
          value = cxx_constant_value (value);
 
-         if (TREE_CODE (value) == INTEGER_CST)
+         if (TREE_CODE (value) == INTEGER_CST
+             && INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (value)))
            {
              value = perform_integral_promotions (value);
            }
@@ -13095,8 +13133,7 @@ grokmethod (cp_decl_specifier_seq *declspecs,
 
   if (DECL_IN_AGGR_P (fndecl))
     {
-      if (DECL_CONTEXT (fndecl)
-         && TREE_CODE (DECL_CONTEXT (fndecl)) != NAMESPACE_DECL)
+      if (DECL_CLASS_SCOPE_P (fndecl))
        error ("%qD is already defined in class %qT", fndecl,
               DECL_CONTEXT (fndecl));
       return error_mark_node;
@@ -13307,10 +13344,14 @@ static_fn_type (tree memfntype)
 void
 revert_static_member_fn (tree decl)
 {
-  TREE_TYPE (decl) = static_fn_type (decl);
+  tree stype = static_fn_type (decl);
 
-  if (cp_type_quals (TREE_TYPE (decl)) != TYPE_UNQUALIFIED)
-    error ("static member function %q#D declared with type qualifiers", decl);
+  if (type_memfn_quals (stype) != TYPE_UNQUALIFIED)
+    {
+      error ("static member function %q#D declared with type qualifiers", decl);
+      stype = apply_memfn_quals (stype, TYPE_UNQUALIFIED);
+    }
+  TREE_TYPE (decl) = stype;
 
   if (DECL_ARGUMENTS (decl))
     DECL_ARGUMENTS (decl) = DECL_CHAIN (DECL_ARGUMENTS (decl));