OSDN Git Service

PR c++/52906
[pf3gnuchains/gcc-fork.git] / gcc / cp / decl.c
index 7daac5f..1cf78b0 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, 2011
+   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
    Free Software Foundation, Inc.
    Contributed by Michael Tiemann (tiemann@cygnus.com)
 
@@ -952,6 +952,8 @@ decls_match (tree newdecl, tree olddecl)
        interested in their types.  */
     return 0;
 
+  gcc_assert (DECL_P (newdecl));
+
   if (TREE_CODE (newdecl) == FUNCTION_DECL)
     {
       tree f1 = TREE_TYPE (newdecl);
@@ -2212,7 +2214,12 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend)
       SET_DECL_INIT_PRIORITY (olddecl, DECL_INIT_PRIORITY (newdecl));
       DECL_HAS_INIT_PRIORITY_P (olddecl) = 1;
     }
-  /* Likewise for DECL_USER_ALIGN and DECL_PACKED.  */
+  /* Likewise for DECL_ALIGN, DECL_USER_ALIGN and DECL_PACKED.  */
+  if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
+    {
+      DECL_ALIGN (newdecl) = DECL_ALIGN (olddecl);
+      DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl);
+    }
   DECL_USER_ALIGN (olddecl) = DECL_USER_ALIGN (newdecl);
   if (TREE_CODE (newdecl) == FIELD_DECL)
     DECL_PACKED (olddecl) = DECL_PACKED (newdecl);
@@ -2940,9 +2947,9 @@ tree
 define_label (location_t location, tree name)
 {
   tree ret;
-  timevar_start (TV_NAME_LOOKUP);
+  bool running = timevar_cond_start (TV_NAME_LOOKUP);
   ret = define_label_1 (location, name);
-  timevar_stop (TV_NAME_LOOKUP);
+  timevar_cond_stop (TV_NAME_LOOKUP, running);
   return ret;
 }
 
@@ -4209,6 +4216,20 @@ check_tag_decl (cp_decl_specifier_seq *declspecs)
         error ("%<constexpr%> cannot be used for type declarations");
     }
 
+  if (declspecs->attributes && declared_type)
+    {
+      location_t loc = input_location;
+      if (!CLASS_TYPE_P (declared_type)
+         || !CLASSTYPE_TEMPLATE_INSTANTIATION (declared_type))
+       /* For a non-template class, use the name location; for a template
+          class (an explicit instantiation), use the current location.  */
+       input_location = location_of (declared_type);
+      warning (0, "attribute ignored in declaration of %q#T", declared_type);
+      warning (0, "attribute for %q#T must follow the %qs keyword",
+              declared_type, class_key_or_enum_as_string (declared_type));
+      input_location = loc;
+    }
+
   return declared_type;
 }
 
@@ -4233,14 +4254,6 @@ shadow_tag (cp_decl_specifier_seq *declspecs)
   if (!t)
     return NULL_TREE;
 
-  if (declspecs->attributes)
-    {
-      warning (0, "attribute ignored in declaration of %q+#T", t);
-      warning (0, "attribute for %q+#T must follow the %qs keyword",
-              t, class_key_or_enum_as_string (t));
-
-    }
-
   if (maybe_process_partial_specialization (t) == error_mark_node)
     return NULL_TREE;
 
@@ -4407,7 +4420,8 @@ start_decl (const cp_declarator *declarator,
     }
 
   /* If #pragma weak was used, mark the decl weak now.  */
-  maybe_apply_pragma_weak (decl);
+  if (!processing_template_decl)
+    maybe_apply_pragma_weak (decl);
 
   if (TREE_CODE (decl) == FUNCTION_DECL
       && DECL_DECLARED_INLINE_P (decl)
@@ -10502,7 +10516,9 @@ static tree
 local_variable_p_walkfn (tree *tp, int *walk_subtrees,
                         void *data ATTRIBUTE_UNUSED)
 {
-  if (local_variable_p (*tp) && !DECL_ARTIFICIAL (*tp))
+  /* Check DECL_NAME to avoid including temporaries.  We don't check
+     DECL_ARTIFICIAL because we do want to complain about 'this'.  */
+  if (local_variable_p (*tp) && DECL_NAME (*tp))
     return *tp;
   else if (TYPE_P (*tp))
     *walk_subtrees = 0;
@@ -10510,7 +10526,6 @@ local_variable_p_walkfn (tree *tp, int *walk_subtrees,
   return NULL_TREE;
 }
 
-
 /* Check that ARG, which is a default-argument expression for a
    parameter DECL, is valid.  Returns ARG, or ERROR_MARK_NODE, if
    something goes wrong.  DECL may also be a _TYPE node, rather than a
@@ -10561,6 +10576,17 @@ check_default_argument (tree decl, tree arg)
       return error_mark_node;
     }
 
+  if (warn_zero_as_null_pointer_constant
+      && c_inhibit_evaluation_warnings == 0
+      && (POINTER_TYPE_P (decl_type) || TYPE_PTR_TO_MEMBER_P (decl_type))
+      && null_ptr_cst_p (arg)
+      && !NULLPTR_TYPE_P (TREE_TYPE (arg)))
+    {
+      warning (OPT_Wzero_as_null_pointer_constant,
+              "zero as null pointer constant");
+      return nullptr_node;
+    }
+
   /* [dcl.fct.default]
 
      Local variables shall not be used in default argument
@@ -10571,7 +10597,10 @@ check_default_argument (tree decl, tree arg)
   var = cp_walk_tree_without_duplicates (&arg, local_variable_p_walkfn, NULL);
   if (var)
     {
-      error ("default argument %qE uses local variable %qD", arg, var);
+      if (DECL_NAME (var) == this_identifier)
+       permerror (input_location, "default argument %qE uses %qD", arg, var);
+      else
+       error ("default argument %qE uses local variable %qD", arg, var);
       return error_mark_node;
     }
 
@@ -11869,7 +11898,7 @@ xref_basetypes (tree ref, tree base_list)
        TYPE_FOR_JAVA (ref) = 1;
 
       base_binfo = NULL_TREE;
-      if (CLASS_TYPE_P (basetype) && !dependent_type_p (basetype))
+      if (CLASS_TYPE_P (basetype) && !dependent_scope_p (basetype))
        {
          base_binfo = TYPE_BINFO (basetype);
          /* The original basetype could have been a typedef'd type.  */
@@ -11914,8 +11943,8 @@ xref_basetypes (tree ref, tree base_list)
       BINFO_BASE_ACCESS_APPEND (binfo, access);
     }
 
-  if (VEC_space (tree, CLASSTYPE_VBASECLASSES (ref), 1))
-    /* If we have space in the vbase vector, we must have shared at
+  if (VEC_length (tree, CLASSTYPE_VBASECLASSES (ref)) < max_vbases)
+    /* If we didn't get max_vbases vbases, we must have shared at
        least one of them, and are therefore diamond shaped.  */
     CLASSTYPE_DIAMOND_SHAPED_P (ref) = 1;