]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c-common.c (c_sizeof_or_alignof_type): Take a third argument for complaining.
authorGabriel Dos Reis <gdr@nerim.net>
Thu, 25 Jul 2002 08:58:07 +0000 (08:58 +0000)
committerGabriel Dos Reis <gdr@gcc.gnu.org>
Thu, 25 Jul 2002 08:58:07 +0000 (08:58 +0000)
* c-common.c (c_sizeof_or_alignof_type): Take a third argument for
complaining.
* c-common.h (c_sizeof): Adjust definition.
(c_alignof): Likewise.
* c-tree.h (c_sizeof_nowarn): Now macro.
* c-typeck.c (c_sizeof_nowarn): Remove definition.
cp/
* cp-tree.h (cxx_sizeof_nowarn): Now a macro.
(cxx_sizeof_or_alignof_type): Take a third argument.
(cxx_sizeof): Adjust definition.
(cxx_alignof): Likewise.
* init.c (build_delete): Use cxx_sizeof_nowarn to reflect reality.
* typeck.c (cxx_sizeof_or_alignof_type): Take a third argument for
complaining.
(c_sizeof_nowarn): Remove definition.
(build_unary_op): Use cxx_sizeof_nowarn.

From-SVN: r55744

gcc/ChangeLog
gcc/c-common.c
gcc/c-common.h
gcc/c-tree.h
gcc/c-typeck.c
gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/decl2.c
gcc/cp/init.c
gcc/cp/typeck.c

index efb68c087c04dedb68d4075ac968481784f81893..926ca173e27bcc2a16f0c5af87905d32d17ea78d 100644 (file)
@@ -1,3 +1,12 @@
+2002-07-25  Gabriel Dos Reis  <gdr@nerim.net>
+
+       * c-common.c (c_sizeof_or_alignof_type): Take a third argument for
+       complaining. 
+       * c-common.h (c_sizeof): Adjust definition.
+       (c_alignof): Likewise.
+       * c-tree.h (c_sizeof_nowarn): Now macro.
+       * c-typeck.c (c_sizeof_nowarn): Remove definition.
+
 2002-07-25  Neil Booth  <neil@daikokuya.co.uk>
 
        * c-decl.c (c_decode_option): No need to handle switches
index d7be6c812d1f46d755cdc59f45c7e0ee6f424e8d..88c3ef5534dfb79c221d2a727c8361ea440dc2eb 100644 (file)
@@ -2602,11 +2602,14 @@ c_common_get_alias_set (t)
 }
 \f
 /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where the
-   second parameter indicates which OPERATOR is being applied.  */
+   second parameter indicates which OPERATOR is being applied.  The COMPLAIN
+   flag controls whether we should diagnose possibly ill-formed
+   constructs or not.  */
 tree
-c_sizeof_or_alignof_type (type, op)
+c_sizeof_or_alignof_type (type, op, complain)
      tree type;
      enum tree_code op;
+     int complain;
 {
   const char *op_name;
   tree value = NULL;
@@ -2619,7 +2622,7 @@ c_sizeof_or_alignof_type (type, op)
     {
       if (op == SIZEOF_EXPR)
        {
-         if (pedantic || warn_pointer_arith)
+         if (complain && (pedantic || warn_pointer_arith))
            pedwarn ("invalid application of `sizeof' to a function type");
          value = size_one_node;
        }
@@ -2628,13 +2631,15 @@ c_sizeof_or_alignof_type (type, op)
     }
   else if (type_code == VOID_TYPE || type_code == ERROR_MARK)
     {
-      if (type_code == VOID_TYPE && (pedantic || warn_pointer_arith))
+      if (type_code == VOID_TYPE 
+         && complain && (pedantic || warn_pointer_arith))
        pedwarn ("invalid application of `%s' to a void type", op_name);
       value = size_one_node;
     }
   else if (!COMPLETE_TYPE_P (type))
     {
-      error ("invalid application of `%s' to an incomplete type", op_name);
+      if (complain)
+       error ("invalid application of `%s' to an incomplete type", op_name);
       value = size_zero_node;
     }
   else
index fabfb1642a1f2c01026f7f8a6222f50091e7c6df..5dfa2d610f4dfd3fabf8b1c5fc5f5445068a05c2 100644 (file)
@@ -548,7 +548,7 @@ extern tree c_common_signed_type            PARAMS ((tree));
 extern tree c_common_signed_or_unsigned_type   PARAMS ((int, tree));
 extern tree c_common_truthvalue_conversion     PARAMS ((tree));
 extern void c_apply_type_quals_to_decl         PARAMS ((int, tree));
-extern tree c_sizeof_or_alignof_type   PARAMS ((tree, enum tree_code));
+extern tree c_sizeof_or_alignof_type   PARAMS ((tree, enum tree_code, int));
 extern tree c_alignof_expr                     PARAMS ((tree));
 /* Print an error message for invalid operands to arith operation CODE.
    NOP_EXPR is used as a special case (see truthvalue_conversion).  */
@@ -575,8 +575,8 @@ extern void unsigned_conversion_warning             PARAMS ((tree, tree));
 /* Read the rest of the current #-directive line.  */
 extern char *get_directive_line                        PARAMS ((void));
 #define GET_DIRECTIVE_LINE() get_directive_line ()
-#define c_sizeof(T)  c_sizeof_or_alignof_type (T, SIZEOF_EXPR)
-#define c_alignof(T) c_sizeof_or_alignof_type (T, ALIGNOF_EXPR)
+#define c_sizeof(T)  c_sizeof_or_alignof_type (T, SIZEOF_EXPR, 1)
+#define c_alignof(T) c_sizeof_or_alignof_type (T, ALIGNOF_EXPR, 1)
 
 /* Subroutine of build_binary_op, used for comparison operations.
    See if the operands have both been converted from subword integer types
index 64eb2e14135c620c4541f57186fb12907c2b5ba8..a2bf5424985c63d642cf787ae6c3ccfe13db393d 100644 (file)
@@ -255,10 +255,10 @@ extern bool c_warn_unused_global_decl             PARAMS ((tree));
                          ((CONST_P) ? TYPE_QUAL_CONST : 0) |     \
                          ((VOLATILE_P) ? TYPE_QUAL_VOLATILE : 0))
 
+#define c_sizeof_nowarn(T)  c_sizeof_or_alignof_type (T, SIZEOF_EXPR, 0)
 /* in c-typeck.c */
 extern tree require_complete_type              PARAMS ((tree));
 extern int comptypes                           PARAMS ((tree, tree));
-extern tree c_sizeof_nowarn                    PARAMS ((tree));
 extern tree c_size_in_bytes                     PARAMS ((tree));
 extern bool c_mark_addressable                 PARAMS ((tree));
 extern void c_incomplete_type_error            PARAMS ((tree, tree));
index f6e8d538d7531a5229bda9e011d47a91c3e56a40..e9c846e06c4371b803ea86a8dd8c70cffe0ccbb5 100644 (file)
@@ -736,30 +736,6 @@ type_lists_compatible_p (args1, args2)
     }
 }
 \f
-tree
-c_sizeof_nowarn (type)
-     tree type;
-{
-  enum tree_code code = TREE_CODE (type);
-  tree size;
-
-  if (code == FUNCTION_TYPE || code == VOID_TYPE || code == ERROR_MARK)
-    size = size_one_node;
-  else if (!COMPLETE_TYPE_P (type))
-    size = size_zero_node;
-  else
-    /* Convert in case a char is more than one unit.  */
-    size = size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
-                      size_int (TYPE_PRECISION (char_type_node)
-                                / BITS_PER_UNIT));
-
-  /* SIZE will have an integer type with TYPE_IS_SIZETYPE set.
-     TYPE_IS_SIZETYPE means that certain things (like overflow) will
-     never happen.  However, this node should really have type
-     `size_t', which is just a typedef for an ordinary integer type.  */
-  return fold (build1 (NOP_EXPR, c_size_type_node, size));
-}
-
 /* Compute the size to increment a pointer by.  */
 
 tree
index 659ecfa5f3b4cc7159c628e3a074ca05c89ca4bc..d8289b92d3a10273e07fd7ccdbe16f14e8fd2297 100644 (file)
@@ -1,3 +1,15 @@
+2002-07-25  Gabriel Dos Reis  <gdr@nerim.net>
+
+       * cp-tree.h (cxx_sizeof_nowarn): Now a macro.
+       (cxx_sizeof_or_alignof_type): Take a third argument.
+       (cxx_sizeof): Adjust definition.
+       (cxx_alignof): Likewise.
+       * init.c (build_delete): Use cxx_sizeof_nowarn to reflect reality.
+       * typeck.c (cxx_sizeof_or_alignof_type): Take a third argument for
+       complaining.
+       (c_sizeof_nowarn): Remove definition.
+       (build_unary_op): Use cxx_sizeof_nowarn.
+
 2002-07-24  Geoffrey Keating  <geoffk@redhat.com>
 
        * tree.c (cp_build_qualified_type_real): When copying
index a859d497a8931d25022d103cfd536c61d43514ee..291caf65a3fca27327dc9f9c178a02b2e068b1ad 100644 (file)
@@ -4436,8 +4436,8 @@ extern int compparms                              PARAMS ((tree, tree));
 extern int comp_cv_qualification                PARAMS ((tree, tree));
 extern int comp_cv_qual_signature               PARAMS ((tree, tree));
 extern tree expr_sizeof                                PARAMS ((tree));
-extern tree cxx_sizeof_or_alignof_type    PARAMS ((tree, enum tree_code));
-extern tree c_sizeof_nowarn                    PARAMS ((tree));
+extern tree cxx_sizeof_or_alignof_type    PARAMS ((tree, enum tree_code, int));
+#define cxx_sizeof_nowarn(T) cxx_sizeof_or_alignof_type (T, SIZEOF_EXPR, false)
 extern tree inline_conversion                  PARAMS ((tree));
 extern tree decay_conversion                   PARAMS ((tree));
 extern tree build_object_ref                   PARAMS ((tree, tree, tree));
@@ -4483,8 +4483,8 @@ extern tree merge_types                           PARAMS ((tree, tree));
 extern tree check_return_expr                   PARAMS ((tree));
 #define cp_build_binary_op(code, arg1, arg2) \
   build_binary_op(code, arg1, arg2, 1)
-#define cxx_sizeof(T)  cxx_sizeof_or_alignof_type (T, SIZEOF_EXPR)
-#define cxx_alignof(T) cxx_sizeof_or_alignof_type (T, ALIGNOF_EXPR)
+#define cxx_sizeof(T)  cxx_sizeof_or_alignof_type (T, SIZEOF_EXPR, true)
+#define cxx_alignof(T) cxx_sizeof_or_alignof_type (T, ALIGNOF_EXPR, true)
 
 /* in typeck2.c */
 extern void cxx_incomplete_type_diagnostic     PARAMS ((tree, tree, int));
index 30f718871d852e7a3915deb3ccc67df37fc077f0..2b6bd254e5f4bed237854aa8dc7b2838ad7ab37b 100644 (file)
@@ -3771,7 +3771,7 @@ build_expr_from_tree (t)
        if (!TYPE_P (r))
          return TREE_CODE (t) == SIZEOF_EXPR ? expr_sizeof (r) : c_alignof_expr (r);
        else
-         return cxx_sizeof_or_alignof_type (r, TREE_CODE (t));
+         return cxx_sizeof_or_alignof_type (r, TREE_CODE (t), true);
       }
 
     case MODOP_EXPR:
index 1fa75b2521ec1957846a33c8d059e7aec218efd3..31c1505afa6a3118537d6acdc873aaf4ac003ea4 100644 (file)
@@ -3177,7 +3177,7 @@ build_delete (type, addr, auto_delete, flags, use_global_delete)
        return void_zero_node;
 
       return build_op_delete_call
-       (DELETE_EXPR, addr, c_sizeof_nowarn (type),
+       (DELETE_EXPR, addr, cxx_sizeof_nowarn (type),
         LOOKUP_NORMAL | (use_global_delete * LOOKUP_GLOBAL),
         NULL_TREE);
     }
@@ -3212,7 +3212,7 @@ build_delete (type, addr, auto_delete, flags, use_global_delete)
          /* Build the call.  */
          do_delete = build_op_delete_call (DELETE_EXPR,
                                            addr,
-                                           c_sizeof_nowarn (type),
+                                           cxx_sizeof_nowarn (type),
                                            LOOKUP_NORMAL,
                                            NULL_TREE);
          /* Call the complete object destructor.  */
@@ -3223,7 +3223,7 @@ build_delete (type, addr, auto_delete, flags, use_global_delete)
        {
          /* Make sure we have access to the member op delete, even though
             we'll actually be calling it from the destructor.  */
-         build_op_delete_call (DELETE_EXPR, addr, c_sizeof_nowarn (type),
+         build_op_delete_call (DELETE_EXPR, addr, cxx_sizeof_nowarn (type),
                                LOOKUP_NORMAL, NULL_TREE);
        }
 
index 6d810f592ae61a3063e3514b2ebecbf10608dbdb..e333d3e5877031ddb0748c81fbcc75a270283ce6 100644 (file)
@@ -1487,9 +1487,10 @@ comp_target_parms (parms1, parms2)
 }
 \f
 tree
-cxx_sizeof_or_alignof_type (type, op)
+cxx_sizeof_or_alignof_type (type, op, complain)
      tree type;
      enum tree_code op;
+     int complain;
 {
   enum tree_code type_code;
   tree value;
@@ -1507,17 +1508,18 @@ cxx_sizeof_or_alignof_type (type, op)
 
   if (type_code == METHOD_TYPE)
     {
-      if (pedantic || warn_pointer_arith)
+      if (complain && (pedantic || warn_pointer_arith))
        pedwarn ("invalid application of `%s' to a member function", op_name);
       value = size_one_node;
     }
   else if (type_code == OFFSET_TYPE)
     {
-      error ("invalid application of `%s' to non-static member", op_name);
+      if (complain)
+       error ("invalid application of `%s' to non-static member", op_name);
       value = size_zero_node;
     }
   else
-    value = c_sizeof_or_alignof_type (complete_type (type), op);
+    value = c_sizeof_or_alignof_type (complete_type (type), op, complain);
 
   return value;
 }
@@ -1554,41 +1556,6 @@ expr_sizeof (e)
   return cxx_sizeof (TREE_TYPE (e));
 }
   
-tree
-c_sizeof_nowarn (type)
-     tree type;
-{
-  enum tree_code code = TREE_CODE (type);
-  tree size;
-
-  if (code == FUNCTION_TYPE
-      || code == METHOD_TYPE
-      || code == VOID_TYPE
-      || code == ERROR_MARK)
-    size = size_one_node;
-  else
-    {
-      if (code == REFERENCE_TYPE)
-       type = TREE_TYPE (type);
-
-      if (!COMPLETE_TYPE_P (type))
-       size = size_zero_node;
-      else
-       /* Convert in case a char is more than one unit.  */
-       size = size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
-                          size_int (TYPE_PRECISION (char_type_node)
-                                    / BITS_PER_UNIT));
-    }
-
-  /* SIZE will have an integer type with TYPE_IS_SIZETYPE set.
-     TYPE_IS_SIZETYPE means that certain things (like overflow) will
-     never happen.  However, this node should really have type
-     `size_t', which is just a typedef for an ordinary integer type.  */
-  size = fold (build1 (NOP_EXPR, c_size_type_node, size));
-  my_friendly_assert (!TYPE_IS_SIZETYPE (TREE_TYPE (size)), 
-                     20001021);
-  return size;
-}
 \f
 /* Perform the array-to-pointer and function-to-pointer conversions
    for EXP.  
@@ -4377,7 +4344,7 @@ build_unary_op (code, xarg, noconvert)
                          ((code == PREINCREMENT_EXPR
                            || code == POSTINCREMENT_EXPR)
                           ? "increment" : "decrement"), argtype);
-           inc = c_sizeof_nowarn (TREE_TYPE (argtype));
+           inc = cxx_sizeof_nowarn (TREE_TYPE (argtype));
          }
        else
          inc = integer_one_node;