/* Build expressions with type checking for C++ compiler.
Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
- 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
Hacked by Michael Tiemann (tiemann@cygnus.com)
This file is part of GCC.
static bool casts_away_constness (tree, tree);
static void maybe_warn_about_returning_address_of_local (tree);
static tree lookup_destructor (tree, tree, tree);
+static tree convert_arguments (tree, tree, tree, int);
/* Return the target type of TYPE, which means return T for:
T*, T&, T[], T (...), and otherwise, just T. */
}
/* Like complete_type, but issue an error if the TYPE cannot be completed.
- VALUE is used for informative diagnostics. DIAG_TYPE indicates the type
- of diagnostic: 0 for an error, 1 for a warning, 2 for a pedwarn.
+ VALUE is used for informative diagnostics.
Returns NULL_TREE if the type cannot be made complete. */
tree
-complete_type_or_diagnostic (tree type, tree value, int diag_type)
+complete_type_or_else (tree type, tree value)
{
type = complete_type (type);
if (type == error_mark_node)
return NULL_TREE;
else if (!COMPLETE_TYPE_P (type))
{
- cxx_incomplete_type_diagnostic (value, type, diag_type);
+ cxx_incomplete_type_diagnostic (value, type, 0);
return NULL_TREE;
}
else
As an optimization, free the space we allocate if the parameter
lists are already common. */
-tree
+static tree
commonparms (tree p1, tree p2)
{
tree oldargs = p1, newargs, n;
/* We may be dealing with Objective-C instances... */
if (TREE_CODE (t1) == RECORD_TYPE
- && (retval = objc_comptypes (t1, t2, 0) >= 0))
+ && ((retval = objc_comptypes (t1, t2, 0)) >= 0))
return retval;
/* ...but fall through if we are not. */
return (q1 & q2) == q2;
}
-/* Returns 1 if TYPE1 is more qualified than TYPE2. */
-
-bool
-more_qualified_p (tree type1, tree type2)
-{
- int q1 = cp_type_quals (type1);
- int q2 = cp_type_quals (type2);
-
- return q1 != q2 && (q1 & q2) == q2;
-}
-
/* Returns 1 if TYPE1 is more cv-qualified than TYPE2, -1 if TYPE2 is
more cv-qualified that TYPE1, and 0 otherwise. */
type = TREE_TYPE (exp);
code = TREE_CODE (type);
- if (code == REFERENCE_TYPE)
- {
- exp = convert_from_reference (exp);
- type = TREE_TYPE (exp);
- code = TREE_CODE (type);
- }
-
if (type == error_mark_node)
return error_mark_node;
cxx_incomplete_type_error (exp, TREE_TYPE (exp));
return error_mark_node;
}
-
- /* Constants can be used directly unless they're not loadable. */
- if (TREE_CODE (exp) == CONST_DECL)
- exp = DECL_INITIAL (exp);
- /* Replace a nonvolatile const static variable with its value. We
- don't do this for arrays, though; we want the address of the
- first element of the array, not the address of the first element
- of its initializing constant. */
- else if (code != ARRAY_TYPE)
- {
- exp = decl_constant_value (exp);
- type = TREE_TYPE (exp);
- }
+ exp = integral_constant_value (exp);
+
/* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
Leave such NOP_EXPRs, since RHS is being used in non-lvalue context. */
if (object == error_mark_node || member == error_mark_node)
return error_mark_node;
- if (TREE_CODE (member) == PSEUDO_DTOR_EXPR)
- return member;
-
gcc_assert (DECL_P (member) || BASELINK_P (member));
/* [expr.ref]
expression itself. */
if (type_quals & TYPE_QUAL_CONST)
TREE_READONLY (result) = 1;
- else if (type_quals & TYPE_QUAL_VOLATILE)
+ if (type_quals & TYPE_QUAL_VOLATILE)
TREE_THIS_VOLATILE (result) = 1;
}
else if (BASELINK_P (member))
TYPE_MAIN_VARIANT (object_type), dtor_type);
return error_mark_node;
}
- if (!TYPE_HAS_DESTRUCTOR (dtor_type))
- return build3 (PSEUDO_DTOR_EXPR, void_type_node, object, scope,
- dtor_type);
expr = lookup_member (dtor_type, complete_dtor_identifier,
/*protect=*/1, /*want_type=*/false);
expr = (adjust_result_of_qualified_name_lookup
object = build_non_dependent_expr (object);
}
- if (TREE_CODE (object_type) == REFERENCE_TYPE)
- {
- object = convert_from_reference (object);
- object_type = TREE_TYPE (object);
- }
-
/* [expr.ref]
The type of the first expression shall be "class object" (of a
? ptr : decay_conversion (ptr));
type = TREE_TYPE (pointer);
- if (TYPE_PTR_P (type) || TREE_CODE (type) == REFERENCE_TYPE)
+ if (POINTER_TYPE_P (type))
{
/* [expr.unary.op]
/* Apply integral promotions *after* noticing character types.
(It is unclear why we do these promotions -- the standard
- does not say that we should. In fact, the natual thing would
+ does not say that we should. In fact, the natural thing would
seem to be to convert IDX to ptrdiff_t; we're performing
pointer arithmetic.) */
idx = perform_integral_promotions (idx);
function = save_expr (function);
/* Start by extracting all the information from the PMF itself. */
- e3 = PFN_FROM_PTRMEMFUNC (function);
+ e3 = pfn_from_ptrmemfunc (function);
delta = build_ptrmemfunc_access_expr (function, delta_identifier);
idx = build1 (NOP_EXPR, vtable_index_type, e3);
switch (TARGET_PTRMEMFUNC_VBIT_LOCATION)
In C++, unspecified trailing parameters can be filled in with their
default arguments, if such were specified. Do so here. */
-tree
+static tree
convert_arguments (tree typelist, tree values, tree fndecl, int flags)
{
tree typetail, valtail;
}
else
{
- if (TREE_CODE (TREE_TYPE (val)) == REFERENCE_TYPE)
- val = convert_from_reference (val);
-
if (fndecl && DECL_BUILT_IN (fndecl)
&& DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CONSTANT_P)
/* Don't do ellipsis conversion for __built_in_constant_p
/* CONVERT_EXPR stands for unary plus in this context. */
case CONVERT_EXPR:
case NEGATE_EXPR:
- {\r
- int flags = WANT_ARITH | WANT_ENUM;\r
- /* Unary plus (but not unary minus) is allowed on pointers. */\r
- if (code == CONVERT_EXPR)\r
- flags |= WANT_POINTER;\r
- arg = build_expr_type_conversion (flags, arg, true);\r
+ {
+ int flags = WANT_ARITH | WANT_ENUM;
+ /* Unary plus (but not unary minus) is allowed on pointers. */
+ if (code == CONVERT_EXPR)
+ flags |= WANT_POINTER;
+ arg = build_expr_type_conversion (flags, arg, true);
if (!arg)
errstring = (code == NEGATE_EXPR
? "wrong type argument to unary minus"
for certain kinds of expressions which are not really lvalues
but which we can accept as lvalues.
- If ARG is not a kind of expression we can handle, return zero. */
+ If ARG is not a kind of expression we can handle, return
+ NULL_TREE. */
tree
unary_complex_lvalue (enum tree_code code, tree arg)
{
+ /* Inside a template, making these kinds of adjustments is
+ pointless; we are only concerned with the type of the
+ expression. */
+ if (processing_template_decl)
+ return NULL_TREE;
+
/* Handle (a, b) used as an "lvalue". */
if (TREE_CODE (arg) == COMPOUND_EXPR)
{
tree
build_compound_expr (tree lhs, tree rhs)
{
- lhs = decl_constant_value (lhs);
lhs = convert_to_void (lhs, "left-hand operand of comma");
if (lhs == error_mark_node || rhs == error_mark_node)
|| (INTEGRAL_OR_ENUMERATION_TYPE_P (type)
&& INTEGRAL_OR_ENUMERATION_TYPE_P (intype)))
{
- expr = decl_constant_value (expr);
expr = ocp_convert (type, expr, CONV_C_CAST, LOOKUP_NORMAL);
/* Ignore any integer overflow caused by the cast. */
expr = build_min (STATIC_CAST_EXPR, type, expr);
/* We don't know if it will or will not have side effects. */
TREE_SIDE_EFFECTS (expr) = 1;
- return expr;
+ return convert_from_reference (expr);
}
/* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
;
else if ((TYPE_PTRFN_P (type) && TYPE_PTRFN_P (intype))
|| (TYPE_PTRMEMFUNC_P (type) && TYPE_PTRMEMFUNC_P (intype)))
- {
- expr = decl_constant_value (expr);
- return fold_if_not_in_template (build_nop (type, expr));
- }
+ return fold_if_not_in_template (build_nop (type, expr));
else if ((TYPE_PTRMEM_P (type) && TYPE_PTRMEM_P (intype))
|| (TYPE_PTROBV_P (type) && TYPE_PTROBV_P (intype)))
{
warning ("cast from %qT to %qT increases required alignment of "
"target type",
intype, type);
- expr = decl_constant_value (expr);
+
return fold_if_not_in_template (build_nop (type, expr));
}
else if ((TYPE_PTRFN_P (type) && TYPE_PTROBV_P (intype))
addresses this issue, but as of 2004/10/26 is still in
drafting. */
warning ("ISO C++ forbids casting between pointer-to-function and pointer-to-object");
-
- expr = decl_constant_value (expr);
return fold_if_not_in_template (build_nop (type, expr));
}
else if (TREE_CODE (type) == VECTOR_TYPE)
return fold_if_not_in_template (convert_to_vector (type, expr));
+ else if (TREE_CODE (intype) == VECTOR_TYPE)
+ return fold_if_not_in_template (convert_to_integer (type, expr));
else
{
if (valid_p)
&& type_dependent_expression_p (expr))
/* There might turn out to be side effects inside expr. */
TREE_SIDE_EFFECTS (t) = 1;
- return t;
+ return convert_from_reference (t);
}
return build_reinterpret_cast_1 (type, expr, /*c_cast_p=*/false,
&& type_dependent_expression_p (expr))
/* There might turn out to be side effects inside expr. */
TREE_SIDE_EFFECTS (t) = 1;
- return t;
+ return convert_from_reference (t);
}
return build_const_cast_1 (type, expr, /*complain=*/true,
tree_cons (NULL_TREE, value, NULL_TREE));
/* We don't know if it will or will not have side effects. */
TREE_SIDE_EFFECTS (t) = 1;
- return t;
+ return convert_from_reference (t);
}
/* Casts to a (pointer to a) specific ObjC class (or 'id' or
}
else
{
- if (TREE_CODE (lhstype) == REFERENCE_TYPE)
- {
- lhs = convert_from_reference (lhs);
- olhstype = lhstype = TREE_TYPE (lhs);
- }
lhs = require_complete_type (lhs);
if (lhs == error_mark_node)
return error_mark_node;
return build_ptrmemfunc_access_expr (t, pfn_identifier);
}
-/* Expression EXPR is about to be implicitly converted to TYPE. Warn
- if this is a potentially dangerous thing to do. Returns a possibly
- marked EXPR. */
-
-tree
-dubious_conversion_warnings (tree type, tree expr,
- const char *errtype, tree fndecl, int parmnum)
-{
- type = non_reference (type);
-
- /* Issue warnings about peculiar, but valid, uses of NULL. */
- if (ARITHMETIC_TYPE_P (type) && expr == null_node)
- {
- if (fndecl)
- warning ("passing NULL used for non-pointer %s %P of %qD",
- errtype, parmnum, fndecl);
- else
- warning ("%s to non-pointer type %qT from NULL", errtype, type);
- }
-
- /* Warn about assigning a floating-point type to an integer type. */
- if (TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE
- && TREE_CODE (type) == INTEGER_TYPE)
- {
- if (fndecl)
- warning ("passing %qT for %s %P of %qD",
- TREE_TYPE (expr), errtype, parmnum, fndecl);
- else
- warning ("%s to %qT from %qT", errtype, type, TREE_TYPE (expr));
- }
- /* And warn about assigning a negative value to an unsigned
- variable. */
- else if (TYPE_UNSIGNED (type) && TREE_CODE (type) != BOOLEAN_TYPE)
- {
- if (TREE_CODE (expr) == INTEGER_CST && TREE_NEGATED_INT (expr))
- {
- if (fndecl)
- warning ("passing negative value %qE for %s %P of %qD",
- expr, errtype, parmnum, fndecl);
- else
- warning ("%s of negative value %qE to %qT", errtype, expr, type);
- }
-
- overflow_warning (expr);
-
- if (TREE_CONSTANT (expr))
- expr = fold_if_not_in_template (expr);
- }
- return expr;
-}
-
/* Convert value RHS to type TYPE as preparation for an assignment to
an lvalue of type TYPE. ERRTYPE is a string to use in error
messages: "assignment", "return", etc. If FNDECL is non-NULL, we
if (TREE_CODE (rhs) == CONST_DECL)
rhs = DECL_INITIAL (rhs);
- /* We do not use decl_constant_value here because of this case:
-
- const char* const s = "s";
-
- The conversion rules for a string literal are more lax than for a
- variable; in particular, a string literal can be converted to a
- "char *" but the variable "s" cannot be converted in the same
- way. If the conversion is allowed, the optimization should be
- performed while creating the converted expression. */
-
/* [expr.ass]
The expression is implicitly converted (clause _conv_) to the
|| (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node))
return error_mark_node;
- if (TREE_CODE (TREE_TYPE (rhs)) == REFERENCE_TYPE)
- rhs = convert_from_reference (rhs);
-
if ((TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
&& TREE_CODE (type) != ARRAY_TYPE
&& (TREE_CODE (type) != REFERENCE_TYPE
/* Remember that this function did return a value. */
current_function_returns_value = 1;
- /* Check for errnoneous operands -- but after giving ourselves a
+ /* Check for erroneous operands -- but after giving ourselves a
chance to provide an error about returning a value from a void
function. */
if (error_operand_p (retval))
return CLASS_TYPE_P (type) && CLASSTYPE_HAS_MUTABLE (type);
}
+/* Apply the TYPE_QUALS to the new DECL. */
+void
+cp_apply_type_quals_to_decl (int type_quals, tree decl)
+{
+ tree type = TREE_TYPE (decl);
+
+ if (type == error_mark_node)
+ return;
+
+ if (TREE_CODE (type) == FUNCTION_TYPE
+ && type_quals != TYPE_UNQUALIFIED)
+ {
+ /* This was an error in C++98 (cv-qualifiers cannot be added to
+ a function type), but DR 295 makes the code well-formed by
+ dropping the extra qualifiers. */
+ if (pedantic)
+ {
+ tree bad_type = build_qualified_type (type, type_quals);
+ pedwarn ("ignoring %qV qualifiers added to function type %qT",
+ bad_type, type);
+ }
+
+ TREE_TYPE (decl) = TYPE_MAIN_VARIANT (type);
+ return;
+ }
+
+ /* Avoid setting TREE_READONLY incorrectly. */
+ if (/* If the object has a constructor, the constructor may modify
+ the object. */
+ TYPE_NEEDS_CONSTRUCTING (type)
+ /* If the type isn't complete, we don't know yet if it will need
+ constructing. */
+ || !COMPLETE_TYPE_P (type)
+ /* If the type has a mutable component, that component might be
+ modified. */
+ || TYPE_HAS_MUTABLE_P (type))
+ type_quals &= ~TYPE_QUAL_CONST;
+
+ c_apply_type_quals_to_decl (type_quals, decl);
+}
+
/* Subroutine of casts_away_constness. Make T1 and T2 point at
exemplar types such that casting T1 to T2 is casting away constness
if and only if there is no implicit conversion from T1 to T2. */