+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
}
\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;
{
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;
}
}
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
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). */
/* 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
((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));
}
}
\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
+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
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));
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));
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:
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);
}
/* 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. */
{
/* 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);
}
}
\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;
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;
}
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.
((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;