]> gcc.gnu.org Git - gcc.git/blobdiff - gcc/cp/cp-objcp-common.c
cp-tree.def (STATIC_ASSERT): New.
[gcc.git] / gcc / cp / cp-objcp-common.c
index a58549b7326894c3921813eb2be7bf37e663c01e..a3e19db244fc4b3d7e39364b3c1c54b55571c430 100644 (file)
@@ -16,8 +16,8 @@ for more details.
 
 You should have received a copy of the GNU General Public License
 along with GCC; see the file COPYING.  If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.  */
+Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA.  */
 
 #include "config.h"
 #include "system.h"
@@ -75,21 +75,36 @@ cxx_warn_unused_global_decl (tree decl)
 tree
 cp_expr_size (tree exp)
 {
-  if (CLASS_TYPE_P (TREE_TYPE (exp)))
+  tree type = TREE_TYPE (exp);
+
+  if (CLASS_TYPE_P (type))
     {
       /* The backend should not be interested in the size of an expression
         of a type with both of these set; all copies of such types must go
         through a constructor or assignment op.  */
-      gcc_assert (!TYPE_HAS_COMPLEX_INIT_REF (TREE_TYPE (exp))
-                 || !TYPE_HAS_COMPLEX_ASSIGN_REF (TREE_TYPE (exp))
+      gcc_assert (!TYPE_HAS_COMPLEX_INIT_REF (type)
+                 || !TYPE_HAS_COMPLEX_ASSIGN_REF (type)
                  /* But storing a CONSTRUCTOR isn't a copy.  */
-                 || TREE_CODE (exp) == CONSTRUCTOR);
-      
+                 || TREE_CODE (exp) == CONSTRUCTOR
+                 /* And, the gimplifier will sometimes make a copy of
+                    an aggregate.  In particular, for a case like:
+
+                       struct S { S(); };
+                       struct X { int a; S s; };
+                       X x = { 0 };
+
+                    the gimplifier will create a temporary with
+                    static storage duration, perform static
+                    initialization of the temporary, and then copy
+                    the result.  Since the "s" subobject is never
+                    constructed, this is a valid transformation.  */
+                 || CP_AGGREGATE_TYPE_P (type));
+
       /* This would be wrong for a type with virtual bases, but they are
         caught by the assert above.  */
-      return (is_empty_class (TREE_TYPE (exp))
+      return (is_empty_class (type)
              ? size_zero_node
-             : CLASSTYPE_SIZE_UNIT (TREE_TYPE (exp)));
+             : CLASSTYPE_SIZE_UNIT (type));
     }
   else
     /* Use the default code.  */
@@ -103,11 +118,12 @@ cp_tree_size (enum tree_code code)
   switch (code)
     {
     case TINST_LEVEL:          return sizeof (struct tinst_level_s);
-    case PTRMEM_CST:           return sizeof (struct ptrmem_cst);
+    case PTRMEM_CST:           return sizeof (struct ptrmem_cst);
     case BASELINK:             return sizeof (struct tree_baselink);
-    case TEMPLATE_PARM_INDEX:  return sizeof (template_parm_index);
+    case TEMPLATE_PARM_INDEX:  return sizeof (template_parm_index);
     case DEFAULT_ARG:          return sizeof (struct tree_default_arg);
     case OVERLOAD:             return sizeof (struct tree_overload);
+    case STATIC_ASSERT:         return sizeof (struct tree_static_assert);
     default:
       gcc_unreachable ();
     }
@@ -139,7 +155,7 @@ void
 cxx_initialize_diagnostics (diagnostic_context *context)
 {
   pretty_printer *base = context->printer;
-  cxx_pretty_printer *pp = xmalloc (sizeof (cxx_pretty_printer));
+  cxx_pretty_printer *pp = XNEW (cxx_pretty_printer);
   memcpy (pp_base (pp), base, sizeof (pretty_printer));
   pp_cxx_pretty_printer_init (pp);
   context->printer = (pretty_printer *) pp;
@@ -162,12 +178,29 @@ cxx_types_compatible_p (tree x, tree y)
      interchangeable.  FIXME should we try to replace all references with
      pointers?  */
   if (POINTER_TYPE_P (x) && POINTER_TYPE_P (y)
+      && TYPE_MODE (x) == TYPE_MODE (y)
+      && TYPE_REF_CAN_ALIAS_ALL (x) == TYPE_REF_CAN_ALIAS_ALL (y)
       && same_type_p (TREE_TYPE (x), TREE_TYPE (y)))
     return 1;
 
   return 0;
 }
 
+tree
+cxx_staticp (tree arg)
+{
+  switch (TREE_CODE (arg))
+    {
+    case BASELINK:
+      return staticp (BASELINK_FUNCTIONS (arg));
+
+    default:
+      break;
+    }
+  
+  return NULL_TREE;
+}
+
 /* Stubs to keep c-opts.c happy.  */
 void
 push_file_scope (void)
@@ -185,3 +218,47 @@ has_c_linkage (tree decl)
 {
   return DECL_EXTERN_C_P (decl);
 }
+
+static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
+     htab_t shadowed_var_for_decl;
+
+/* Lookup a shadowed var for FROM, and return it if we find one.  */
+
+tree
+decl_shadowed_for_var_lookup (tree from)
+{
+  struct tree_map *h, in;
+  in.from = from;
+
+  h = (struct tree_map *) htab_find_with_hash (shadowed_var_for_decl, &in,
+                                              htab_hash_pointer (from));
+  if (h)
+    return h->to;
+  return NULL_TREE;
+}
+
+/* Insert a mapping FROM->TO in the shadowed var hashtable.  */
+
+void
+decl_shadowed_for_var_insert (tree from, tree to)
+{
+  struct tree_map *h;
+  void **loc;
+
+  h = GGC_NEW (struct tree_map);
+  h->hash = htab_hash_pointer (from);
+  h->from = from;
+  h->to = to;
+  loc = htab_find_slot_with_hash (shadowed_var_for_decl, h, h->hash, INSERT);
+  *(struct tree_map **) loc = h;
+}
+
+void
+init_shadowed_var_for_decl (void)
+{
+  shadowed_var_for_decl = htab_create_ggc (512, tree_map_hash,
+                                          tree_map_eq, 0);
+}
+
+
+#include "gt-cp-cp-objcp-common.h"
This page took 0.029434 seconds and 5 git commands to generate.