Commit c8a209ca by Nathan Sidwell Committed by Nathan Sidwell

cp-tree.h (COMPARE_RELAXED): Rename to ...

	* cp-tree.h (COMPARE_RELAXED): Rename to ...
	(COMPARE_DERIVED): ... here. Adjust comment.
	(resolve_typename_type_in_current_instantiation): Remove.
	(cp_tree_equal, comptypes): Return a bool.
	* cvt.c (convert_to_reference): Adjust comptypes call.
	* pt.c (template_args_equal, unify,): Adjust cp_tree_equal call.
	(resolve_typename_type_in_current_instantiation): Remove.
	* tree.c (cp_tree_equal): Return bool. Cope with TEMPLATE_DECLs and
	IDENTIFIER_NODEs. Abort if undeciderable. Adjust recursive
	calls. Refactor code.
	* typeck.c (comp_array_types): Return bool. Lose callback.
	parameter. Adjust cp_tree_equal calls.
	(comptypes): Return bool. Adjust strict handling. Remove relaxed
	enumeration and java type handling. Deal with typename types here.
	Adjust recursive and cp_tree_equals calls. Adjust base and derived
	checking.
	(comp_target_types): Remove unreachable code. Adjust
	same_or_base_type_p calls.
	(ptr_reasonably_similar): Adjust base and derived check.

	* typeck.c (maybe_warn_about_returning_address_of_local): Remove
	unused calculation.
	(check_return_expr): Adjust error messages.
	* cp-tree.def (SCOPE_REF): Correct comment.

From-SVN: r68155
parent c76abc12
2003-06-18 Nathan Sidwell <nathan@codesourcery.com>
* cp-tree.h (COMPARE_RELAXED): Rename to ...
(COMPARE_DERIVED): ... here. Adjust comment.
(resolve_typename_type_in_current_instantiation): Remove.
(cp_tree_equal, comptypes): Return a bool.
* cvt.c (convert_to_reference): Adjust comptypes call.
* pt.c (template_args_equal, unify,): Adjust cp_tree_equal call.
(resolve_typename_type_in_current_instantiation): Remove.
* tree.c (cp_tree_equal): Return bool. Cope with TEMPLATE_DECLs and
IDENTIFIER_NODEs. Abort if undeciderable. Adjust recursive
calls. Refactor code.
* typeck.c (comp_array_types): Return bool. Lose callback.
parameter. Adjust cp_tree_equal calls.
(comptypes): Return bool. Adjust strict handling. Remove relaxed
enumeration and java type handling. Deal with typename types here.
Adjust recursive and cp_tree_equals calls. Adjust base and derived
checking.
(comp_target_types): Remove unreachable code. Adjust
same_or_base_type_p calls.
(ptr_reasonably_similar): Adjust base and derived check.
* typeck.c (maybe_warn_about_returning_address_of_local): Remove
unused calculation.
(check_return_expr): Adjust error messages.
* cp-tree.def (SCOPE_REF): Correct comment.
2003-06-17 Mark Mitchell <mark@codesourcery.com> 2003-06-17 Mark Mitchell <mark@codesourcery.com>
* mangle.c (mangle_conv_op_name_for_type): Correct sprintf format * mangle.c (mangle_conv_op_name_for_type): Correct sprintf format
......
...@@ -62,8 +62,7 @@ DEFTREECODE (DELETE_EXPR, "dl_expr", 'e', 2) ...@@ -62,8 +62,7 @@ DEFTREECODE (DELETE_EXPR, "dl_expr", 'e', 2)
DEFTREECODE (VEC_DELETE_EXPR, "vec_dl_expr", 'e', 2) DEFTREECODE (VEC_DELETE_EXPR, "vec_dl_expr", 'e', 2)
/* Value is reference to particular overloaded class method. /* Value is reference to particular overloaded class method.
Operand 0 is the class name (an IDENTIFIER_NODE); Operand 0 is the class, operand 1 is the field
operand 1 is the field (also an IDENTIFIER_NODE).
The COMPLEXITY field holds the class level (usually 0). */ The COMPLEXITY field holds the class level (usually 0). */
DEFTREECODE (SCOPE_REF, "scope_ref", 'r', 2) DEFTREECODE (SCOPE_REF, "scope_ref", 'r', 2)
......
...@@ -3367,15 +3367,9 @@ enum overload_flags { NO_SPECIAL = 0, DTOR_FLAG, OP_FLAG, TYPENAME_FLAG }; ...@@ -3367,15 +3367,9 @@ enum overload_flags { NO_SPECIAL = 0, DTOR_FLAG, OP_FLAG, TYPENAME_FLAG };
#define COMPARE_STRICT 0 /* Just check if the types are the #define COMPARE_STRICT 0 /* Just check if the types are the
same. */ same. */
#define COMPARE_BASE 1 /* Check to see if the second type is #define COMPARE_BASE 1 /* Check to see if the second type is
derived from the first, or if both derived from the first. */
are pointers (or references) and #define COMPARE_DERIVED 2 /* Like COMPARE_BASE, but in
the types pointed to by the second reverse. */
type is derived from the pointed to
by the first. */
#define COMPARE_RELAXED 2 /* Like COMPARE_DERIVED, but in
reverse. Also treat enumeration
types as the same as integer types
of the same width. */
#define COMPARE_REDECLARATION 4 /* The comparsion is being done when #define COMPARE_REDECLARATION 4 /* The comparsion is being done when
another declaration of an existing another declaration of an existing
entity is seen. */ entity is seen. */
...@@ -3982,7 +3976,6 @@ extern bool dependent_template_p (tree); ...@@ -3982,7 +3976,6 @@ extern bool dependent_template_p (tree);
extern bool type_dependent_expression_p (tree); extern bool type_dependent_expression_p (tree);
extern bool value_dependent_expression_p (tree); extern bool value_dependent_expression_p (tree);
extern tree resolve_typename_type (tree, bool); extern tree resolve_typename_type (tree, bool);
extern tree resolve_typename_type_in_current_instantiation (tree);
extern tree template_for_substitution (tree); extern tree template_for_substitution (tree);
/* in repo.c */ /* in repo.c */
...@@ -4204,7 +4197,7 @@ extern tree error_type (tree); ...@@ -4204,7 +4197,7 @@ extern tree error_type (tree);
extern tree build_zc_wrapper (struct z_candidate *); extern tree build_zc_wrapper (struct z_candidate *);
extern int varargs_function_p (tree); extern int varargs_function_p (tree);
extern int really_overloaded_fn (tree); extern int really_overloaded_fn (tree);
extern int cp_tree_equal (tree, tree); extern bool cp_tree_equal (tree, tree);
extern tree no_linkage_check (tree); extern tree no_linkage_check (tree);
extern void debug_binfo (tree); extern void debug_binfo (tree);
extern tree build_dummy_object (tree); extern tree build_dummy_object (tree);
...@@ -4247,7 +4240,7 @@ extern int type_unknown_p (tree); ...@@ -4247,7 +4240,7 @@ extern int type_unknown_p (tree);
extern tree commonparms (tree, tree); extern tree commonparms (tree, tree);
extern tree original_type (tree); extern tree original_type (tree);
extern int comp_except_specs (tree, tree, int); extern int comp_except_specs (tree, tree, int);
extern int comptypes (tree, tree, int); extern bool comptypes (tree, tree, int);
extern int comp_target_types (tree, tree, int); extern int comp_target_types (tree, tree, int);
extern int compparms (tree, tree); extern int compparms (tree, tree);
extern int comp_cv_qualification (tree, tree); extern int comp_cv_qualification (tree, tree);
......
...@@ -508,7 +508,7 @@ convert_to_reference (tree reftype, tree expr, int convtype, ...@@ -508,7 +508,7 @@ convert_to_reference (tree reftype, tree expr, int convtype,
meant. */ meant. */
if (TREE_CODE (intype) == POINTER_TYPE if (TREE_CODE (intype) == POINTER_TYPE
&& (comptypes (TREE_TYPE (intype), type, && (comptypes (TREE_TYPE (intype), type,
COMPARE_BASE | COMPARE_RELAXED ))) COMPARE_BASE | COMPARE_DERIVED)))
warning ("casting `%T' to `%T' does not dereference pointer", warning ("casting `%T' to `%T' does not dereference pointer",
intype, reftype); intype, reftype);
......
...@@ -3811,7 +3811,7 @@ template_args_equal (ot, nt) ...@@ -3811,7 +3811,7 @@ template_args_equal (ot, nt)
else if (TREE_CODE (ot) == TREE_VEC || TYPE_P (ot)) else if (TREE_CODE (ot) == TREE_VEC || TYPE_P (ot))
return 0; return 0;
else else
return (cp_tree_equal (ot, nt) > 0); return cp_tree_equal (ot, nt);
} }
/* Returns 1 iff the OLDARGS and NEWARGS are in fact identical sets /* Returns 1 iff the OLDARGS and NEWARGS are in fact identical sets
...@@ -9638,22 +9638,14 @@ unify (tparms, targs, parm, arg, strict) ...@@ -9638,22 +9638,14 @@ unify (tparms, targs, parm, arg, strict)
!= template_decl_level (tparm)) != template_decl_level (tparm))
/* The PARM is not one we're trying to unify. Just check /* The PARM is not one we're trying to unify. Just check
to see if it matches ARG. */ to see if it matches ARG. */
return (TREE_CODE (arg) == TREE_CODE (parm) return !(TREE_CODE (arg) == TREE_CODE (parm)
&& cp_tree_equal (parm, arg) > 0) ? 0 : 1; && cp_tree_equal (parm, arg));
idx = TEMPLATE_PARM_IDX (parm); idx = TEMPLATE_PARM_IDX (parm);
targ = TREE_VEC_ELT (targs, idx); targ = TREE_VEC_ELT (targs, idx);
if (targ) if (targ)
{ return !cp_tree_equal (targ, arg);
int i = (cp_tree_equal (targ, arg) > 0);
if (i == 1)
return 0;
else if (i == 0)
return 1;
else
abort ();
}
/* [temp.deduct.type] If, in the declaration of a function template /* [temp.deduct.type] If, in the declaration of a function template
with a non-type template-parameter, the non-type with a non-type template-parameter, the non-type
...@@ -11798,13 +11790,4 @@ resolve_typename_type (tree type, bool only_current_p) ...@@ -11798,13 +11790,4 @@ resolve_typename_type (tree type, bool only_current_p)
return type; return type;
} }
tree
resolve_typename_type_in_current_instantiation (tree type)
{
tree t;
t = resolve_typename_type (type, /*only_current_p=*/true);
return (t != error_mark_node) ? t : type;
}
#include "gt-cp-pt.h" #include "gt-cp-pt.h"
...@@ -1552,38 +1552,35 @@ decl_namespace_context (tree decl) ...@@ -1552,38 +1552,35 @@ decl_namespace_context (tree decl)
} }
/* Return truthvalue of whether T1 is the same tree structure as T2. /* Return truthvalue of whether T1 is the same tree structure as T2.
Return 1 if they are the same. Return 1 if they are the same. Return 0 if they are different. */
Return 0 if they are understandably different.
Return -1 if either contains tree structure not understood by
this function. */
int bool
cp_tree_equal (tree t1, tree t2) cp_tree_equal (tree t1, tree t2)
{ {
register enum tree_code code1, code2; register enum tree_code code1, code2;
int cmp;
if (t1 == t2) if (t1 == t2)
return 1; return true;
if (t1 == 0 || t2 == 0) if (!t1 || !t2)
return 0; return false;
code1 = TREE_CODE (t1); for (code1 = TREE_CODE (t1);
code2 = TREE_CODE (t2); code1 == NOP_EXPR || code1 == CONVERT_EXPR
|| code1 == NON_LVALUE_EXPR;
if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR) code1 = TREE_CODE (t1))
{ t1 = TREE_OPERAND (t1, 0);
if (code2 == NOP_EXPR || code2 == CONVERT_EXPR || code2 == NON_LVALUE_EXPR) for (code2 = TREE_CODE (t2);
return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); code2 == NOP_EXPR || code2 == CONVERT_EXPR
else || code1 == NON_LVALUE_EXPR;
return cp_tree_equal (TREE_OPERAND (t1, 0), t2); code2 = TREE_CODE (t2))
} t2 = TREE_OPERAND (t2, 0);
else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
|| code2 == NON_LVALUE_EXPR) /* They might have become equal now. */
return cp_tree_equal (t1, TREE_OPERAND (t2, 0)); if (t1 == t2)
return true;
if (code1 != code2) if (code1 != code2)
return 0; return false;
switch (code1) switch (code1)
{ {
...@@ -1606,61 +1603,62 @@ cp_tree_equal (tree t1, tree t2) ...@@ -1606,61 +1603,62 @@ cp_tree_equal (tree t1, tree t2)
if (!(same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)) if (!(same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
/* The first operand is RTL. */ /* The first operand is RTL. */
&& TREE_OPERAND (t1, 0) == TREE_OPERAND (t2, 0))) && TREE_OPERAND (t1, 0) == TREE_OPERAND (t2, 0)))
return 0; return false;
return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)); return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
case TREE_LIST: case TREE_LIST:
cmp = cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)); if (!cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
if (cmp <= 0) return false;
return cmp; if (!cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
cmp = cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)); return false;
if (cmp <= 0)
return cmp;
return cp_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2)); return cp_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
case SAVE_EXPR: case SAVE_EXPR:
return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
case CALL_EXPR: case CALL_EXPR:
cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
if (cmp <= 0) return false;
return cmp; return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
return simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
case TARGET_EXPR: case TARGET_EXPR:
{
tree o1 = TREE_OPERAND (t1, 0);
tree o2 = TREE_OPERAND (t2, 0);
/* Special case: if either target is an unallocated VAR_DECL, /* Special case: if either target is an unallocated VAR_DECL,
it means that it's going to be unified with whatever the it means that it's going to be unified with whatever the
TARGET_EXPR is really supposed to initialize, so treat it TARGET_EXPR is really supposed to initialize, so treat it
as being equivalent to anything. */ as being equivalent to anything. */
if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL if (TREE_CODE (o1) == VAR_DECL && DECL_NAME (o1) == NULL_TREE
&& DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE && !DECL_RTL_SET_P (o1))
&& !DECL_RTL_SET_P (TREE_OPERAND (t1, 0))) /*Nop*/;
|| (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL else if (TREE_CODE (o2) == VAR_DECL && DECL_NAME (o2) == NULL_TREE
&& DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE && !DECL_RTL_SET_P (o2))
&& !DECL_RTL_SET_P (TREE_OPERAND (t2, 0)))) /*Nop*/;
cmp = 1; else if (!cp_tree_equal (o1, o2))
else return false;
cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
if (cmp <= 0)
return cmp;
return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)); return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
}
case WITH_CLEANUP_EXPR: case WITH_CLEANUP_EXPR:
cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
if (cmp <= 0) return false;
return cmp;
return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1)); return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
case COMPONENT_REF: case COMPONENT_REF:
if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1)) if (TREE_OPERAND (t1, 1) != TREE_OPERAND (t2, 1))
return false;
return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
return 0;
case VAR_DECL: case VAR_DECL:
case PARM_DECL: case PARM_DECL:
case CONST_DECL: case CONST_DECL:
case FUNCTION_DECL: case FUNCTION_DECL:
return 0; case TEMPLATE_DECL:
case IDENTIFIER_NODE:
return false;
case TEMPLATE_PARM_INDEX: case TEMPLATE_PARM_INDEX:
return (TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2) return (TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2)
...@@ -1670,17 +1668,25 @@ cp_tree_equal (tree t1, tree t2) ...@@ -1670,17 +1668,25 @@ cp_tree_equal (tree t1, tree t2)
case SIZEOF_EXPR: case SIZEOF_EXPR:
case ALIGNOF_EXPR: case ALIGNOF_EXPR:
if (TREE_CODE (TREE_OPERAND (t1, 0)) != TREE_CODE (TREE_OPERAND (t2, 0))) {
return 0; tree o1 = TREE_OPERAND (t1, 0);
if (TYPE_P (TREE_OPERAND (t1, 0))) tree o2 = TREE_OPERAND (t2, 0);
return same_type_p (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
break; if (TREE_CODE (o1) != TREE_CODE (o2))
return false;
if (TYPE_P (o1))
return same_type_p (o1, o2);
else
return cp_tree_equal (o1, o2);
}
case PTRMEM_CST: case PTRMEM_CST:
/* Two pointer-to-members are the same if they point to the same /* Two pointer-to-members are the same if they point to the same
field or function in the same class. */ field or function in the same class. */
return (PTRMEM_CST_MEMBER (t1) == PTRMEM_CST_MEMBER (t2) if (PTRMEM_CST_MEMBER (t1) != PTRMEM_CST_MEMBER (t2))
&& same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2))); return false;
return same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2));
default: default:
break; break;
...@@ -1697,21 +1703,19 @@ cp_tree_equal (tree t1, tree t2) ...@@ -1697,21 +1703,19 @@ cp_tree_equal (tree t1, tree t2)
{ {
int i; int i;
cmp = 1;
for (i = 0; i < TREE_CODE_LENGTH (code1); ++i) for (i = 0; i < TREE_CODE_LENGTH (code1); ++i)
{ if (!cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
cmp = cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)); return false;
if (cmp <= 0)
return cmp; return true;
}
return cmp;
} }
case 't': case 't':
return same_type_p (t1, t2) ? 1 : 0; return same_type_p (t1, t2);
} }
return -1; my_friendly_assert (0, 20030617);
return false;
} }
/* Build a wrapper around a 'struct z_candidate' so we can use it as a /* Build a wrapper around a 'struct z_candidate' so we can use it as a
......
...@@ -54,8 +54,7 @@ static int comp_ptr_ttypes_real PARAMS ((tree, tree, int)); ...@@ -54,8 +54,7 @@ static int comp_ptr_ttypes_real PARAMS ((tree, tree, int));
static int comp_ptr_ttypes_const PARAMS ((tree, tree)); static int comp_ptr_ttypes_const PARAMS ((tree, tree));
static int comp_ptr_ttypes_reinterpret PARAMS ((tree, tree)); static int comp_ptr_ttypes_reinterpret PARAMS ((tree, tree));
static int comp_except_types PARAMS ((tree, tree, int)); static int comp_except_types PARAMS ((tree, tree, int));
static int comp_array_types PARAMS ((int (*) (tree, tree, int), tree, static bool comp_array_types PARAMS ((tree, tree, int));
tree, int));
static tree common_base_type PARAMS ((tree, tree)); static tree common_base_type PARAMS ((tree, tree));
static tree lookup_anon_field PARAMS ((tree, tree)); static tree lookup_anon_field PARAMS ((tree, tree));
static tree pointer_diff PARAMS ((tree, tree, tree)); static tree pointer_diff PARAMS ((tree, tree, tree));
...@@ -837,12 +836,10 @@ comp_except_specs (t1, t2, exact) ...@@ -837,12 +836,10 @@ comp_except_specs (t1, t2, exact)
return !exact || base == NULL_TREE || length == list_length (t1); return !exact || base == NULL_TREE || length == list_length (t1);
} }
/* Compare the array types T1 and T2, using CMP as the type comparison /* Compare the array types T1 and T2. STRICT is as for comptypes. */
function for the element types. STRICT is as for comptypes. */
static int static bool
comp_array_types (cmp, t1, t2, strict) comp_array_types (t1, t2, strict)
register int (*cmp) PARAMS ((tree, tree, int));
tree t1, t2; tree t1, t2;
int strict; int strict;
{ {
...@@ -853,16 +850,15 @@ comp_array_types (cmp, t1, t2, strict) ...@@ -853,16 +850,15 @@ comp_array_types (cmp, t1, t2, strict)
return 1; return 1;
/* The type of the array elements must be the same. */ /* The type of the array elements must be the same. */
if (!(TREE_TYPE (t1) == TREE_TYPE (t2) if (!comptypes (TREE_TYPE (t1), TREE_TYPE (t2),
|| (*cmp) (TREE_TYPE (t1), TREE_TYPE (t2), strict & ~COMPARE_REDECLARATION))
strict & ~COMPARE_REDECLARATION))) return false;
return 0;
d1 = TYPE_DOMAIN (t1); d1 = TYPE_DOMAIN (t1);
d2 = TYPE_DOMAIN (t2); d2 = TYPE_DOMAIN (t2);
if (d1 == d2) if (d1 == d2)
return 1; return true;
/* If one of the arrays is dimensionless, and the other has a /* If one of the arrays is dimensionless, and the other has a
dimension, they are of different types. However, it is valid to dimension, they are of different types. However, it is valid to
...@@ -880,103 +876,85 @@ comp_array_types (cmp, t1, t2, strict) ...@@ -880,103 +876,85 @@ comp_array_types (cmp, t1, t2, strict)
return strict & COMPARE_REDECLARATION; return strict & COMPARE_REDECLARATION;
/* Check that the dimensions are the same. */ /* Check that the dimensions are the same. */
return (cp_tree_equal (TYPE_MIN_VALUE (d1), return (cp_tree_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2))
TYPE_MIN_VALUE (d2)) && cp_tree_equal (TYPE_MAX_VALUE (d1), TYPE_MAX_VALUE (d2)));
&& cp_tree_equal (TYPE_MAX_VALUE (d1),
TYPE_MAX_VALUE (d2)));
} }
/* Return 1 if T1 and T2 are compatible types for assignment or /* Return true if T1 and T2 are related as allowed by STRICT. STRICT
various other operations. STRICT is a bitwise-or of the COMPARE_* is a bitwise-or of the COMPARE_* flags. */
flags. */
int bool
comptypes (t1, t2, strict) comptypes (t1, t2, strict)
tree t1; tree t1;
tree t2; tree t2;
int strict; int strict;
{ {
int attrval, val;
int orig_strict = strict; int orig_strict = strict;
/* The special exemption for redeclaring array types without an
array bound only applies at the top level:
extern int (*i)[];
int (*i)[8];
is invalid, for example. */
strict &= ~COMPARE_REDECLARATION;
/* Suppress errors caused by previously reported errors */
if (t1 == t2) if (t1 == t2)
return 1; return true;
strict &= ~(COMPARE_REDECLARATION | COMPARE_BASE | COMPARE_DERIVED);
/* This should never happen. */ /* This should never happen. */
my_friendly_assert (t1 != error_mark_node, 307); my_friendly_assert (t1 != error_mark_node, 307);
/* Suppress errors caused by previously reported errors */
if (t2 == error_mark_node) if (t2 == error_mark_node)
return 0; return false;
/* If either type is the internal version of sizetype, return the /* TYPENAME_TYPEs should be resolved if the qualifying scope is the
current instantiation. */
if (TREE_CODE (t1) == TYPENAME_TYPE)
{
tree resolved = resolve_typename_type (t1, /*only_current_p=*/true);
if (resolved != error_mark_node)
t1 = resolved;
}
if (TREE_CODE (t2) == TYPENAME_TYPE)
{
tree resolved = resolve_typename_type (t2, /*only_current_p=*/true);
if (resolved != error_mark_node)
t2 = resolved;
}
/* If either type is the internal version of sizetype, use the
language version. */ language version. */
if (TREE_CODE (t1) == INTEGER_TYPE && TYPE_IS_SIZETYPE (t1) if (TREE_CODE (t1) == INTEGER_TYPE && TYPE_IS_SIZETYPE (t1)
&& TYPE_DOMAIN (t1) != 0) && TYPE_DOMAIN (t1))
t1 = TYPE_DOMAIN (t1); t1 = TYPE_DOMAIN (t1);
if (TREE_CODE (t2) == INTEGER_TYPE && TYPE_IS_SIZETYPE (t2) if (TREE_CODE (t2) == INTEGER_TYPE && TYPE_IS_SIZETYPE (t2)
&& TYPE_DOMAIN (t2) != 0) && TYPE_DOMAIN (t2))
t2 = TYPE_DOMAIN (t2); t2 = TYPE_DOMAIN (t2);
if (strict & COMPARE_RELAXED)
{
/* Treat an enum type as the unsigned integer type of the same width. */
if (TREE_CODE (t1) == ENUMERAL_TYPE)
t1 = c_common_type_for_size (TYPE_PRECISION (t1), 1);
if (TREE_CODE (t2) == ENUMERAL_TYPE)
t2 = c_common_type_for_size (TYPE_PRECISION (t2), 1);
if (t1 == t2)
return 1;
}
if (TYPE_PTRMEMFUNC_P (t1)) if (TYPE_PTRMEMFUNC_P (t1))
t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1); t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1);
if (TYPE_PTRMEMFUNC_P (t2)) if (TYPE_PTRMEMFUNC_P (t2))
t2 = TYPE_PTRMEMFUNC_FN_TYPE (t2); t2 = TYPE_PTRMEMFUNC_FN_TYPE (t2);
/* TYPENAME_TYPEs should be resolved if the qualifying scope is the
current instantiation. */
if (TREE_CODE (t1) == TYPENAME_TYPE)
t1 = resolve_typename_type_in_current_instantiation (t1);
if (TREE_CODE (t2) == TYPENAME_TYPE)
t2 = resolve_typename_type_in_current_instantiation (t2);
/* Different classes of types can't be compatible. */ /* Different classes of types can't be compatible. */
if (TREE_CODE (t1) != TREE_CODE (t2)) if (TREE_CODE (t1) != TREE_CODE (t2))
return 0; return false;
/* Qualifiers must match. */ /* Qualifiers must match. */
if (cp_type_quals (t1) != cp_type_quals (t2)) if (cp_type_quals (t1) != cp_type_quals (t2))
return 0; return false;
if (strict == COMPARE_STRICT if (TYPE_FOR_JAVA (t1) != TYPE_FOR_JAVA (t2))
&& TYPE_FOR_JAVA (t1) != TYPE_FOR_JAVA (t2)) return false;
return 0;
/* Allow for two different type nodes which have essentially the same /* Allow for two different type nodes which have essentially the same
definition. Note that we already checked for equality of the type definition. Note that we already checked for equality of the type
qualifiers (just above). */ qualifiers (just above). */
if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2)) if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
return 1; return true;
/* 1 if no need for warning yet, 2 if warning cause has been seen. */
if (! (attrval = (*targetm.comp_type_attributes) (t1, t2)))
return 0;
/* 1 if no need for warning yet, 2 if warning cause has been seen. */ if (!(*targetm.comp_type_attributes) (t1, t2))
val = 0; return false;
switch (TREE_CODE (t1)) switch (TREE_CODE (t1))
{ {
...@@ -984,79 +962,67 @@ comptypes (t1, t2, strict) ...@@ -984,79 +962,67 @@ comptypes (t1, t2, strict)
case BOUND_TEMPLATE_TEMPLATE_PARM: case BOUND_TEMPLATE_TEMPLATE_PARM:
if (TEMPLATE_TYPE_IDX (t1) != TEMPLATE_TYPE_IDX (t2) if (TEMPLATE_TYPE_IDX (t1) != TEMPLATE_TYPE_IDX (t2)
|| TEMPLATE_TYPE_LEVEL (t1) != TEMPLATE_TYPE_LEVEL (t2)) || TEMPLATE_TYPE_LEVEL (t1) != TEMPLATE_TYPE_LEVEL (t2))
return 0; return false;
if (! comp_template_parms if (!comp_template_parms
(DECL_TEMPLATE_PARMS (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t1)), (DECL_TEMPLATE_PARMS (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t1)),
DECL_TEMPLATE_PARMS (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t2)))) DECL_TEMPLATE_PARMS (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t2))))
return 0; return false;
if (TREE_CODE (t1) == TEMPLATE_TEMPLATE_PARM) if (TREE_CODE (t1) == TEMPLATE_TEMPLATE_PARM)
return 1; return true;
/* Don't check inheritance. */ /* Don't check inheritance. */
strict = COMPARE_STRICT; orig_strict = COMPARE_STRICT;
/* fall through */ /* fall through */
case RECORD_TYPE: case RECORD_TYPE:
case UNION_TYPE: case UNION_TYPE:
if (TYPE_TEMPLATE_INFO (t1) && TYPE_TEMPLATE_INFO (t2) if (TYPE_TEMPLATE_INFO (t1) && TYPE_TEMPLATE_INFO (t2)
&& (TYPE_TI_TEMPLATE (t1) == TYPE_TI_TEMPLATE (t2) && (TYPE_TI_TEMPLATE (t1) == TYPE_TI_TEMPLATE (t2)
|| TREE_CODE (t1) == BOUND_TEMPLATE_TEMPLATE_PARM)) || TREE_CODE (t1) == BOUND_TEMPLATE_TEMPLATE_PARM)
val = comp_template_args (TYPE_TI_ARGS (t1), && comp_template_args (TYPE_TI_ARGS (t1), TYPE_TI_ARGS (t2)))
TYPE_TI_ARGS (t2)); return true;
look_hard:
if ((strict & COMPARE_BASE) && DERIVED_FROM_P (t1, t2)) if ((orig_strict & COMPARE_BASE) && DERIVED_FROM_P (t1, t2))
val = 1; return true;
else if ((strict & COMPARE_RELAXED) && DERIVED_FROM_P (t2, t1)) else if ((orig_strict & COMPARE_DERIVED) && DERIVED_FROM_P (t2, t1))
val = 1; return true;
break;
return false;
case OFFSET_TYPE: case OFFSET_TYPE:
val = (comptypes (build_pointer_type (TYPE_OFFSET_BASETYPE (t1)), if (!comptypes (TYPE_OFFSET_BASETYPE (t1), TYPE_OFFSET_BASETYPE (t2),
build_pointer_type (TYPE_OFFSET_BASETYPE (t2)), strict) orig_strict))
&& comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict)); return false;
break; return comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict);
case POINTER_TYPE: case POINTER_TYPE:
case REFERENCE_TYPE: case REFERENCE_TYPE:
t1 = TREE_TYPE (t1); return comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict);
t2 = TREE_TYPE (t2);
/* first, check whether the referred types match with the
required level of strictness */
val = comptypes (t1, t2, strict);
if (val)
break;
if (TREE_CODE (t1) == RECORD_TYPE
&& TREE_CODE (t2) == RECORD_TYPE)
goto look_hard;
break;
case METHOD_TYPE: case METHOD_TYPE:
case FUNCTION_TYPE: case FUNCTION_TYPE:
val = ((TREE_TYPE (t1) == TREE_TYPE (t2) if (!comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict))
|| comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict)) return false;
&& compparms (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2))); return compparms (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2));
break;
case ARRAY_TYPE: case ARRAY_TYPE:
/* Target types must match incl. qualifiers. We use ORIG_STRICT /* Target types must match incl. qualifiers. We use ORIG_STRICT
here since this is the one place where here since this is the one place where
COMPARE_REDECLARATION should be used. */ COMPARE_REDECLARATION should be used. */
val = comp_array_types (comptypes, t1, t2, orig_strict); return comp_array_types (t1, t2, orig_strict & COMPARE_REDECLARATION);
break;
case TEMPLATE_TYPE_PARM: case TEMPLATE_TYPE_PARM:
return TEMPLATE_TYPE_IDX (t1) == TEMPLATE_TYPE_IDX (t2) return (TEMPLATE_TYPE_IDX (t1) == TEMPLATE_TYPE_IDX (t2)
&& TEMPLATE_TYPE_LEVEL (t1) == TEMPLATE_TYPE_LEVEL (t2); && TEMPLATE_TYPE_LEVEL (t1) == TEMPLATE_TYPE_LEVEL (t2));
case TYPENAME_TYPE: case TYPENAME_TYPE:
if (cp_tree_equal (TYPENAME_TYPE_FULLNAME (t1), if (!cp_tree_equal (TYPENAME_TYPE_FULLNAME (t1),
TYPENAME_TYPE_FULLNAME (t2)) < 1) TYPENAME_TYPE_FULLNAME (t2)))
return 0; return false;
return same_type_p (TYPE_CONTEXT (t1), TYPE_CONTEXT (t2)); return same_type_p (TYPE_CONTEXT (t1), TYPE_CONTEXT (t2));
case UNBOUND_CLASS_TEMPLATE: case UNBOUND_CLASS_TEMPLATE:
if (cp_tree_equal (TYPE_IDENTIFIER (t1), if (!cp_tree_equal (TYPE_IDENTIFIER (t1), TYPE_IDENTIFIER (t2)))
TYPE_IDENTIFIER (t2)) < 1) return false;
return 0;
return same_type_p (TYPE_CONTEXT (t1), TYPE_CONTEXT (t2)); return same_type_p (TYPE_CONTEXT (t1), TYPE_CONTEXT (t2));
case COMPLEX_TYPE: case COMPLEX_TYPE:
...@@ -1065,7 +1031,7 @@ comptypes (t1, t2, strict) ...@@ -1065,7 +1031,7 @@ comptypes (t1, t2, strict)
default: default:
break; break;
} }
return attrval == 2 && val == 1 ? 2 : val; return false;
} }
/* Subroutine of comp_target-types. Make sure that the cv-quals change /* Subroutine of comp_target-types. Make sure that the cv-quals change
...@@ -1166,9 +1132,8 @@ comp_target_types (ttl, ttr, nptrs) ...@@ -1166,9 +1132,8 @@ comp_target_types (ttl, ttr, nptrs)
return comp_cv_target_types (ttl, ttr, nptrs - 1); return comp_cv_target_types (ttl, ttr, nptrs - 1);
} }
if (TREE_CODE (ttr) == ARRAY_TYPE) my_friendly_assert (TREE_CODE (ttr) != ARRAY_TYPE, 20030617);
return comp_array_types (comp_target_types, ttl, ttr, COMPARE_STRICT); if (TREE_CODE (ttr) == FUNCTION_TYPE || TREE_CODE (ttr) == METHOD_TYPE)
else if (TREE_CODE (ttr) == FUNCTION_TYPE || TREE_CODE (ttr) == METHOD_TYPE)
{ {
tree argsl, argsr; tree argsl, argsr;
int saw_contra = 0; int saw_contra = 0;
...@@ -1263,11 +1228,9 @@ comp_target_types (ttl, ttr, nptrs) ...@@ -1263,11 +1228,9 @@ comp_target_types (ttl, ttr, nptrs)
{ {
if (nptrs < 0) if (nptrs < 0)
return 0; return 0;
if (same_or_base_type_p (build_pointer_type (ttl), if (same_or_base_type_p (ttl, ttr))
build_pointer_type (ttr)))
return 1; return 1;
if (same_or_base_type_p (build_pointer_type (ttr), if (same_or_base_type_p (ttr, ttl))
build_pointer_type (ttl)))
return -1; return -1;
return 0; return 0;
} }
...@@ -1454,9 +1417,8 @@ comp_target_parms (parms1, parms2) ...@@ -1454,9 +1417,8 @@ comp_target_parms (parms1, parms2)
{ {
tree p1, p2; tree p1, p2;
/* If one parmlist is shorter than the other, /* If one parmlist is shorter than the other, they fail to match. */
they fail to match, unless STRICT is <= 0. */ if (!t1 || !t2)
if (t1 == 0 || t2 == 0)
return 0; return 0;
p1 = TREE_VALUE (t1); p1 = TREE_VALUE (t1);
p2 = TREE_VALUE (t2); p2 = TREE_VALUE (t2);
...@@ -6313,8 +6275,6 @@ maybe_warn_about_returning_address_of_local (retval) ...@@ -6313,8 +6275,6 @@ maybe_warn_about_returning_address_of_local (retval)
if (TREE_CODE (whats_returned) == AGGR_INIT_EXPR if (TREE_CODE (whats_returned) == AGGR_INIT_EXPR
|| TREE_CODE (whats_returned) == TARGET_EXPR) || TREE_CODE (whats_returned) == TARGET_EXPR)
{ {
/* Get the target. */
whats_returned = TREE_OPERAND (whats_returned, 0);
warning ("returning reference to temporary"); warning ("returning reference to temporary");
return; return;
} }
...@@ -6402,7 +6362,8 @@ check_return_expr (retval) ...@@ -6402,7 +6362,8 @@ check_return_expr (retval)
that's supposed to return a value. */ that's supposed to return a value. */
if (!retval && fn_returns_value_p) if (!retval && fn_returns_value_p)
{ {
pedwarn ("return-statement with no value, in function declared with a non-void return type"); pedwarn ("return-statement with no value, in function returning `%D'",
valtype);
/* Clear this, so finish_function won't say that we reach the /* Clear this, so finish_function won't say that we reach the
end of a non-void function (which we don't, we gave a end of a non-void function (which we don't, we gave a
return!). */ return!). */
...@@ -6418,7 +6379,8 @@ check_return_expr (retval) ...@@ -6418,7 +6379,8 @@ check_return_expr (retval)
its side-effects. */ its side-effects. */
finish_expr_stmt (retval); finish_expr_stmt (retval);
else else
pedwarn ("return-statement with a value, in function declared with a void return type"); pedwarn ("return-statement with a value, in function returning `%D'",
retval);
current_function_returns_null = 1; current_function_returns_null = 1;
...@@ -6610,7 +6572,7 @@ ptr_reasonably_similar (to, from) ...@@ -6610,7 +6572,7 @@ ptr_reasonably_similar (to, from)
if (TREE_CODE (from) == OFFSET_TYPE if (TREE_CODE (from) == OFFSET_TYPE
&& comptypes (TYPE_OFFSET_BASETYPE (to), && comptypes (TYPE_OFFSET_BASETYPE (to),
TYPE_OFFSET_BASETYPE (from), TYPE_OFFSET_BASETYPE (from),
COMPARE_BASE | COMPARE_RELAXED)) COMPARE_BASE | COMPARE_DERIVED))
continue; continue;
if (TREE_CODE (to) == INTEGER_TYPE if (TREE_CODE (to) == INTEGER_TYPE
...@@ -6623,7 +6585,7 @@ ptr_reasonably_similar (to, from) ...@@ -6623,7 +6585,7 @@ ptr_reasonably_similar (to, from)
if (TREE_CODE (to) != POINTER_TYPE) if (TREE_CODE (to) != POINTER_TYPE)
return comptypes return comptypes
(TYPE_MAIN_VARIANT (to), TYPE_MAIN_VARIANT (from), (TYPE_MAIN_VARIANT (to), TYPE_MAIN_VARIANT (from),
COMPARE_BASE | COMPARE_RELAXED); COMPARE_BASE | COMPARE_DERIVED);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment