1 /* Build expressions with type checking for C++ compiler.
2 Copyright (C) 1987, 88, 89, 92-97, 1998 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* This file is part of the C++ front end.
24 It contains routines to build C++ expressions given their operands,
25 including computing the types of the result, C and C++ specific error
26 checks, and some optimization.
28 There are also routines to build RETURN_STMT nodes and CASE_STMT nodes,
29 and to process initializations in declarations (since they work
30 like a strange sort of assignment). */
42 extern void compiler_error ();
44 static tree convert_for_assignment
PROTO((tree
, tree
, char*, tree
,
46 static tree pointer_int_sum
PROTO((enum tree_code
, tree
, tree
));
47 static tree rationalize_conditional_expr
PROTO((enum tree_code
, tree
));
48 static int comp_target_parms
PROTO((tree
, tree
, int));
49 static int comp_ptr_ttypes_real
PROTO((tree
, tree
, int));
50 static int comp_ptr_ttypes_const
PROTO((tree
, tree
));
51 static int comp_ptr_ttypes_reinterpret
PROTO((tree
, tree
));
52 static int comp_array_types
PROTO((int (*) (tree
, tree
, int), tree
,
54 static tree build_ptrmemfunc1
PROTO((tree
, tree
, tree
, tree
, tree
));
55 static tree common_base_type
PROTO((tree
, tree
));
57 static tree convert_sequence
PROTO((tree
, tree
));
59 static tree lookup_anon_field
PROTO((tree
, tree
));
60 static tree pointer_diff
PROTO((tree
, tree
, tree
));
61 static tree qualify_type
PROTO((tree
, tree
));
62 static tree get_delta_difference
PROTO((tree
, tree
, int));
64 /* Return the target type of TYPE, which meas return T for:
65 T*, T&, T[], T (...), and otherwise, just T. */
71 if (TREE_CODE (type
) == REFERENCE_TYPE
)
72 type
= TREE_TYPE (type
);
73 while (TREE_CODE (type
) == POINTER_TYPE
74 || TREE_CODE (type
) == ARRAY_TYPE
75 || TREE_CODE (type
) == FUNCTION_TYPE
76 || TREE_CODE (type
) == METHOD_TYPE
77 || TREE_CODE (type
) == OFFSET_TYPE
)
78 type
= TREE_TYPE (type
);
82 /* Do `exp = require_complete_type (exp);' to make sure exp
83 does not have an incomplete type. (That includes void types.)
84 Returns the error_mark_node if the VALUE does not have
85 complete type when this function returns. */
88 require_complete_type (value
)
93 if (processing_template_decl
)
96 if (TREE_CODE (value
) == OVERLOAD
)
97 type
= unknown_type_node
;
99 type
= TREE_TYPE (value
);
101 /* First, detect a valid value with a complete type. */
102 if (TYPE_SIZE (type
) != 0
103 && type
!= void_type_node
104 && ! (TYPE_LANG_SPECIFIC (type
)
105 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
))
106 && TYPE_SIZE (SIGNATURE_TYPE (type
)) == 0))
109 /* If we see X::Y, we build an OFFSET_TYPE which has
110 not been laid out. Try to avoid an error by interpreting
111 it as this->X::Y, if reasonable. */
112 if (TREE_CODE (value
) == OFFSET_REF
113 && current_class_ref
!= 0
114 && TREE_OPERAND (value
, 0) == current_class_ref
)
116 tree base
, member
= TREE_OPERAND (value
, 1);
117 tree basetype
= TYPE_OFFSET_BASETYPE (type
);
118 my_friendly_assert (TREE_CODE (member
) == FIELD_DECL
, 305);
119 base
= convert_pointer_to (basetype
, current_class_ptr
);
120 value
= build (COMPONENT_REF
, TREE_TYPE (member
),
121 build_indirect_ref (base
, NULL_PTR
), member
);
122 return require_complete_type (value
);
125 if (complete_type_or_else (type
))
128 return error_mark_node
;
131 /* Try to complete TYPE, if it is incomplete. For example, if TYPE is
132 a template instantiation, do the instantiation. Returns TYPE,
133 whether or not it could be completed, unless something goes
134 horribly wrong, in which case the error_mark_node is returned. */
140 if (type
== NULL_TREE
)
141 /* Rather than crash, we return something sure to cause an error
143 return error_mark_node
;
145 if (type
== error_mark_node
|| TYPE_SIZE (type
) != NULL_TREE
)
147 else if (TREE_CODE (type
) == ARRAY_TYPE
&& TYPE_DOMAIN (type
))
149 tree t
= complete_type (TREE_TYPE (type
));
150 if (TYPE_SIZE (t
) != NULL_TREE
&& ! processing_template_decl
)
152 TYPE_NEEDS_CONSTRUCTING (type
)
153 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (t
));
154 TYPE_NEEDS_DESTRUCTOR (type
)
155 = TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (t
));
157 else if (IS_AGGR_TYPE (type
) && CLASSTYPE_TEMPLATE_INSTANTIATION (type
))
158 instantiate_class_template (TYPE_MAIN_VARIANT (type
));
163 /* Like complete_type, but issue an error if the TYPE cannot be
164 completed. Returns NULL_TREE if the type cannot be made
168 complete_type_or_else (type
)
171 type
= complete_type (type
);
172 if (type
== error_mark_node
)
173 /* We already issued an error. */
175 else if (!TYPE_SIZE (type
))
177 incomplete_type_error (NULL_TREE
, type
);
184 /* Return truthvalue of whether type of EXP is instantiated. */
190 return (TREE_CODE (exp
) == OVERLOAD
191 || TREE_CODE (exp
) == TREE_LIST
192 || TREE_TYPE (exp
) == unknown_type_node
193 || (TREE_CODE (TREE_TYPE (exp
)) == OFFSET_TYPE
194 && TREE_TYPE (TREE_TYPE (exp
)) == unknown_type_node
));
197 /* Return truthvalue of whether T is function (or pfn) type. */
203 return (TREE_CODE (t
) == FUNCTION_TYPE
|| TREE_CODE (t
) == METHOD_TYPE
204 || (TREE_CODE (t
) == POINTER_TYPE
205 && (TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
206 || TREE_CODE (TREE_TYPE (t
)) == METHOD_TYPE
)));
209 /* Do `exp = require_instantiated_type (type, exp);' to make sure EXP
210 does not have an uninstantiated type.
211 TYPE is type to instantiate with, if uninstantiated. */
214 require_instantiated_type (type
, exp
, errval
)
215 tree type
, exp
, errval
;
217 if (TREE_TYPE (exp
) == NULL_TREE
)
219 error ("argument list may not have an initializer list");
223 if (TREE_CODE (exp
) == OVERLOAD
224 || TREE_TYPE (exp
) == unknown_type_node
225 || (TREE_CODE (TREE_TYPE (exp
)) == OFFSET_TYPE
226 && TREE_TYPE (TREE_TYPE (exp
)) == unknown_type_node
))
228 exp
= instantiate_type (type
, exp
, 1);
229 if (TREE_TYPE (exp
) == error_mark_node
)
235 /* Return a variant of TYPE which has all the type qualifiers of LIKE
236 as well as those of TYPE. */
239 qualify_type (type
, like
)
242 int constflag
= TYPE_READONLY (type
) || TYPE_READONLY (like
);
243 int volflag
= TYPE_VOLATILE (type
) || TYPE_VOLATILE (like
);
244 /* @@ Must do member pointers here. */
245 return cp_build_type_variant (type
, constflag
, volflag
);
248 /* Return the common type of two parameter lists.
249 We assume that comptypes has already been done and returned 1;
250 if that isn't so, this may crash.
252 As an optimization, free the space we allocate if the parameter
253 lists are already common. */
259 tree oldargs
= p1
, newargs
, n
;
262 char *first_obj
= (char *) oballoc (0);
264 len
= list_length (p1
);
265 newargs
= tree_last (p1
);
267 if (newargs
== void_list_node
)
276 newargs
= tree_cons (NULL_TREE
, NULL_TREE
, newargs
);
281 p1
= TREE_CHAIN (p1
), p2
= TREE_CHAIN (p2
), n
= TREE_CHAIN (n
), i
++)
283 if (TREE_PURPOSE (p1
) && !TREE_PURPOSE (p2
))
285 TREE_PURPOSE (n
) = TREE_PURPOSE (p1
);
288 else if (! TREE_PURPOSE (p1
))
290 if (TREE_PURPOSE (p2
))
292 TREE_PURPOSE (n
) = TREE_PURPOSE (p2
);
298 if (1 != simple_cst_equal (TREE_PURPOSE (p1
), TREE_PURPOSE (p2
)))
300 TREE_PURPOSE (n
) = TREE_PURPOSE (p2
);
302 if (TREE_VALUE (p1
) != TREE_VALUE (p2
))
305 TREE_VALUE (n
) = common_type (TREE_VALUE (p1
), TREE_VALUE (p2
));
308 TREE_VALUE (n
) = TREE_VALUE (p1
);
319 /* Given a type, perhaps copied for a typedef,
320 find the "original" version of it. */
325 while (TYPE_NAME (t
) != NULL_TREE
)
327 tree x
= TYPE_NAME (t
);
328 if (TREE_CODE (x
) != TYPE_DECL
)
330 x
= DECL_ORIGINAL_TYPE (x
);
338 /* Return the common type of two types.
339 We assume that comptypes has already been done and returned 1;
340 if that isn't so, this may crash.
342 This is the type for the result of most arithmetic operations
343 if the operands have the given two types.
345 We do not deal with enumeral types here because they have already been
346 converted to integer types. */
352 register enum tree_code code1
;
353 register enum tree_code code2
;
356 /* Save time if the two types are the same. */
359 t1
= original_type (t1
);
360 t2
= original_type (t2
);
364 /* If one type is nonsense, use the other. */
365 if (t1
== error_mark_node
)
367 if (t2
== error_mark_node
)
370 /* Merge the attributes. */
371 attributes
= merge_machine_type_attributes (t1
, t2
);
373 { register tree a1
, a2
;
374 a1
= TYPE_ATTRIBUTES (t1
);
375 a2
= TYPE_ATTRIBUTES (t2
);
377 /* Either one unset? Take the set one. */
379 if (!(attributes
= a1
))
382 /* One that completely contains the other? Take it. */
384 else if (a2
&& !attribute_list_contained (a1
, a2
))
386 if (attribute_list_contained (a2
, a1
))
390 /* Pick the longest list, and hang on the other list. */
391 /* ??? For the moment we punt on the issue of attrs with args. */
393 if (list_length (a1
) < list_length (a2
))
394 attributes
= a2
, a2
= a1
;
396 for (; a2
; a2
= TREE_CHAIN (a2
))
397 if (lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2
)),
398 attributes
) == NULL_TREE
)
401 TREE_CHAIN (a1
) = attributes
;
408 /* Treat an enum type as the unsigned integer type of the same width. */
410 if (TREE_CODE (t1
) == ENUMERAL_TYPE
)
411 t1
= type_for_size (TYPE_PRECISION (t1
), 1);
412 if (TREE_CODE (t2
) == ENUMERAL_TYPE
)
413 t2
= type_for_size (TYPE_PRECISION (t2
), 1);
415 if (TYPE_PTRMEMFUNC_P (t1
))
416 t1
= TYPE_PTRMEMFUNC_FN_TYPE (t1
);
417 if (TYPE_PTRMEMFUNC_P (t2
))
418 t2
= TYPE_PTRMEMFUNC_FN_TYPE (t2
);
420 code1
= TREE_CODE (t1
);
421 code2
= TREE_CODE (t2
);
423 /* If one type is complex, form the common type of the non-complex
424 components, then make that complex. Use T1 or T2 if it is the
426 if (code1
== COMPLEX_TYPE
|| code2
== COMPLEX_TYPE
)
428 tree subtype1
= code1
== COMPLEX_TYPE
? TREE_TYPE (t1
) : t1
;
429 tree subtype2
= code2
== COMPLEX_TYPE
? TREE_TYPE (t2
) : t2
;
430 tree subtype
= common_type (subtype1
, subtype2
);
432 if (code1
== COMPLEX_TYPE
&& TREE_TYPE (t1
) == subtype
)
433 return build_type_attribute_variant (t1
, attributes
);
434 else if (code2
== COMPLEX_TYPE
&& TREE_TYPE (t2
) == subtype
)
435 return build_type_attribute_variant (t2
, attributes
);
437 return build_type_attribute_variant (build_complex_type (subtype
),
445 /* If only one is real, use it as the result. */
447 if (code1
== REAL_TYPE
&& code2
!= REAL_TYPE
)
448 return build_type_attribute_variant (t1
, attributes
);
450 if (code2
== REAL_TYPE
&& code1
!= REAL_TYPE
)
451 return build_type_attribute_variant (t2
, attributes
);
453 /* Both real or both integers; use the one with greater precision. */
455 if (TYPE_PRECISION (t1
) > TYPE_PRECISION (t2
))
456 return build_type_attribute_variant (t1
, attributes
);
457 else if (TYPE_PRECISION (t2
) > TYPE_PRECISION (t1
))
458 return build_type_attribute_variant (t2
, attributes
);
460 /* Same precision. Prefer longs to ints even when same size. */
462 if (TYPE_MAIN_VARIANT (t1
) == long_unsigned_type_node
463 || TYPE_MAIN_VARIANT (t2
) == long_unsigned_type_node
)
464 return build_type_attribute_variant (long_unsigned_type_node
,
467 if (TYPE_MAIN_VARIANT (t1
) == long_integer_type_node
468 || TYPE_MAIN_VARIANT (t2
) == long_integer_type_node
)
470 /* But preserve unsignedness from the other type,
471 since long cannot hold all the values of an unsigned int. */
472 if (TREE_UNSIGNED (t1
) || TREE_UNSIGNED (t2
))
473 t1
= long_unsigned_type_node
;
475 t1
= long_integer_type_node
;
476 return build_type_attribute_variant (t1
, attributes
);
479 if (TYPE_MAIN_VARIANT (t1
) == long_double_type_node
480 || TYPE_MAIN_VARIANT (t2
) == long_double_type_node
)
481 return build_type_attribute_variant (long_double_type_node
,
484 /* Otherwise prefer the unsigned one. */
486 if (TREE_UNSIGNED (t1
))
487 return build_type_attribute_variant (t1
, attributes
);
489 return build_type_attribute_variant (t2
, attributes
);
493 /* For two pointers, do this recursively on the target type,
494 and combine the qualifiers of the two types' targets. */
495 /* This code was turned off; I don't know why.
496 But ANSI C++ specifies doing this with the qualifiers.
497 So I turned it on again. */
499 tree tt1
= TYPE_MAIN_VARIANT (TREE_TYPE (t1
));
500 tree tt2
= TYPE_MAIN_VARIANT (TREE_TYPE (t2
));
502 = TYPE_READONLY (TREE_TYPE (t1
)) || TYPE_READONLY (TREE_TYPE (t2
));
504 = TYPE_VOLATILE (TREE_TYPE (t1
)) || TYPE_VOLATILE (TREE_TYPE (t2
));
509 else if (tt1
== void_type_node
|| tt2
== void_type_node
)
510 target
= void_type_node
;
511 else if (tt1
== unknown_type_node
)
513 else if (tt2
== unknown_type_node
)
516 target
= common_type (tt1
, tt2
);
518 target
= cp_build_type_variant (target
, constp
, volatilep
);
519 if (code1
== POINTER_TYPE
)
520 t1
= build_pointer_type (target
);
522 t1
= build_reference_type (target
);
523 t1
= build_type_attribute_variant (t1
, attributes
);
525 if (TREE_CODE (target
) == METHOD_TYPE
)
526 t1
= build_ptrmemfunc_type (t1
);
533 tree elt
= common_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
534 /* Save space: see if the result is identical to one of the args. */
535 if (elt
== TREE_TYPE (t1
) && TYPE_DOMAIN (t1
))
536 return build_type_attribute_variant (t1
, attributes
);
537 if (elt
== TREE_TYPE (t2
) && TYPE_DOMAIN (t2
))
538 return build_type_attribute_variant (t2
, attributes
);
539 /* Merge the element types, and have a size if either arg has one. */
540 t1
= build_cplus_array_type
541 (elt
, TYPE_DOMAIN (TYPE_DOMAIN (t1
) ? t1
: t2
));
542 return build_type_attribute_variant (t1
, attributes
);
546 /* Function types: prefer the one that specified arg types.
547 If both do, merge the arg types. Also merge the return types. */
549 tree valtype
= common_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
550 tree p1
= TYPE_ARG_TYPES (t1
);
551 tree p2
= TYPE_ARG_TYPES (t2
);
554 /* Save space: see if the result is identical to one of the args. */
555 if (valtype
== TREE_TYPE (t1
) && ! p2
)
556 return build_type_attribute_variant (t1
, attributes
);
557 if (valtype
== TREE_TYPE (t2
) && ! p1
)
558 return build_type_attribute_variant (t2
, attributes
);
560 /* Simple way if one arg fails to specify argument types. */
561 if (p1
== NULL_TREE
|| TREE_VALUE (p1
) == void_type_node
)
563 rval
= build_function_type (valtype
, p2
);
564 if ((raises
= TYPE_RAISES_EXCEPTIONS (t2
)))
565 rval
= build_exception_variant (rval
, raises
);
566 return build_type_attribute_variant (rval
, attributes
);
568 raises
= TYPE_RAISES_EXCEPTIONS (t1
);
569 if (p2
== NULL_TREE
|| TREE_VALUE (p2
) == void_type_node
)
571 rval
= build_function_type (valtype
, p1
);
573 rval
= build_exception_variant (rval
, raises
);
574 return build_type_attribute_variant (rval
, attributes
);
577 rval
= build_function_type (valtype
, commonparms (p1
, p2
));
578 rval
= build_exception_variant (rval
, raises
);
579 return build_type_attribute_variant (rval
, attributes
);
584 t1
= TYPE_MAIN_VARIANT (t1
);
585 t2
= TYPE_MAIN_VARIANT (t2
);
587 if (DERIVED_FROM_P (t1
, t2
) && binfo_or_else (t1
, t2
))
588 return build_type_attribute_variant (t1
, attributes
);
589 else if (binfo_or_else (t2
, t1
))
590 return build_type_attribute_variant (t2
, attributes
);
593 compiler_error ("common_type called with uncommon aggregate types");
594 return error_mark_node
;
598 if (TREE_CODE (TREE_TYPE (t1
)) == TREE_CODE (TREE_TYPE (t2
)))
600 /* Get this value the long way, since TYPE_METHOD_BASETYPE
601 is just the main variant of this. */
605 tree b1
= TYPE_OFFSET_BASETYPE (t1
);
606 tree b2
= TYPE_OFFSET_BASETYPE (t2
);
608 if (comptypes (b1
, b2
, 1)
609 || (DERIVED_FROM_P (b1
, b2
) && binfo_or_else (b1
, b2
)))
610 basetype
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t2
)));
613 if (binfo_or_else (b2
, b1
) == NULL_TREE
)
614 compiler_error ("common_type called with uncommon method types");
615 basetype
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t1
)));
618 raises
= TYPE_RAISES_EXCEPTIONS (t1
);
620 /* If this was a member function type, get back to the
621 original type of type member function (i.e., without
622 the class instance variable up front. */
623 t1
= build_function_type (TREE_TYPE (t1
),
624 TREE_CHAIN (TYPE_ARG_TYPES (t1
)));
625 t2
= build_function_type (TREE_TYPE (t2
),
626 TREE_CHAIN (TYPE_ARG_TYPES (t2
)));
627 t3
= common_type (t1
, t2
);
628 t3
= build_cplus_method_type (basetype
, TREE_TYPE (t3
),
629 TYPE_ARG_TYPES (t3
));
630 t1
= build_exception_variant (t3
, raises
);
633 compiler_error ("common_type called with uncommon method types");
635 return build_type_attribute_variant (t1
, attributes
);
638 if (TREE_TYPE (t1
) == TREE_TYPE (t2
))
640 tree b1
= TYPE_OFFSET_BASETYPE (t1
);
641 tree b2
= TYPE_OFFSET_BASETYPE (t2
);
643 if (comptypes (b1
, b2
, 1)
644 || (DERIVED_FROM_P (b1
, b2
) && binfo_or_else (b1
, b2
)))
645 return build_type_attribute_variant (t2
, attributes
);
646 else if (binfo_or_else (b2
, b1
))
647 return build_type_attribute_variant (t1
, attributes
);
649 compiler_error ("common_type called with uncommon member types");
652 return build_type_attribute_variant (t1
, attributes
);
656 /* Return 1 if TYPE1 and TYPE2 raise the same exceptions. */
659 compexcepttypes (t1
, t2
)
662 return TYPE_RAISES_EXCEPTIONS (t1
) == TYPE_RAISES_EXCEPTIONS (t2
);
666 comp_array_types (cmp
, t1
, t2
, strict
)
667 register int (*cmp
) PROTO((tree
, tree
, int));
671 tree d1
= TYPE_DOMAIN (t1
);
672 tree d2
= TYPE_DOMAIN (t2
);
674 /* Target types must match incl. qualifiers. */
675 if (!(TREE_TYPE (t1
) == TREE_TYPE (t2
)
676 || (*cmp
) (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
)))
679 /* Sizes must match unless one is missing or variable. */
680 if (d1
== 0 || d2
== 0 || d1
== d2
681 || TREE_CODE (TYPE_MIN_VALUE (d1
)) != INTEGER_CST
682 || TREE_CODE (TYPE_MIN_VALUE (d2
)) != INTEGER_CST
683 || TREE_CODE (TYPE_MAX_VALUE (d1
)) != INTEGER_CST
684 || TREE_CODE (TYPE_MAX_VALUE (d2
)) != INTEGER_CST
)
687 return ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1
))
688 == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2
)))
689 && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1
))
690 == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2
)))
691 && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1
))
692 == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2
)))
693 && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1
))
694 == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2
))));
697 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
698 or various other operations. This is what ANSI C++ speaks of as
701 For C++: argument STRICT says we should be strict about this
704 2 : strict, except that if one type is a reference and
705 the other is not, compare the target type of the
706 reference to the type that's not a reference (ARM, p308).
707 This is used for checking for invalid overloading.
708 1 : strict (compared according to ANSI C)
709 This is used for checking whether two function decls match.
710 0 : <= (compared according to C++)
711 -1: <= or >= (relaxed)
713 Otherwise, pointers involving base classes and derived classes can
714 be mixed as valid: i.e. a pointer to a derived class may be converted
715 to a pointer to one of its base classes, as per C++. A pointer to
716 a derived class may be passed as a parameter to a function expecting a
717 pointer to a base classes. These allowances do not commute. In this
718 case, TYPE1 is assumed to be the base class, and TYPE2 is assumed to
719 be the derived class. */
722 comptypes (type1
, type2
, strict
)
726 register tree t1
= type1
;
727 register tree t2
= type2
;
730 /* Suppress errors caused by previously reported errors */
735 /* This should never happen. */
736 my_friendly_assert (t1
!= error_mark_node
, 307);
738 if (t2
== error_mark_node
)
743 /* Treat an enum type as the unsigned integer type of the same width. */
745 if (TREE_CODE (t1
) == ENUMERAL_TYPE
)
746 t1
= type_for_size (TYPE_PRECISION (t1
), 1);
747 if (TREE_CODE (t2
) == ENUMERAL_TYPE
)
748 t2
= type_for_size (TYPE_PRECISION (t2
), 1);
754 if (TYPE_PTRMEMFUNC_P (t1
))
755 t1
= TYPE_PTRMEMFUNC_FN_TYPE (t1
);
756 if (TYPE_PTRMEMFUNC_P (t2
))
757 t2
= TYPE_PTRMEMFUNC_FN_TYPE (t2
);
759 /* Different classes of types can't be compatible. */
761 if (TREE_CODE (t1
) != TREE_CODE (t2
))
764 && ((TREE_CODE (t1
) == REFERENCE_TYPE
)
765 ^ (TREE_CODE (t2
) == REFERENCE_TYPE
)))
767 if (TREE_CODE (t1
) == REFERENCE_TYPE
)
768 return comptypes (TREE_TYPE (t1
), t2
, 1);
769 return comptypes (t1
, TREE_TYPE (t2
), 1);
777 /* Qualifiers must match. */
779 if (TYPE_READONLY (t1
) != TYPE_READONLY (t2
))
781 if (TYPE_VOLATILE (t1
) != TYPE_VOLATILE (t2
))
783 if (strict
> 0 && TYPE_FOR_JAVA (t1
) != TYPE_FOR_JAVA (t2
))
786 /* Allow for two different type nodes which have essentially the same
787 definition. Note that we already checked for equality of the type
788 qualifiers (just above). */
790 if (TYPE_MAIN_VARIANT (t1
) == TYPE_MAIN_VARIANT (t2
))
793 /* ??? COMP_TYPE_ATTRIBUTES is currently useless for variables as each
794 attribute is its own main variant (`val' will remain 0). */
795 #ifndef COMP_TYPE_ATTRIBUTES
796 #define COMP_TYPE_ATTRIBUTES(t1,t2) 1
799 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
800 if (! (attrval
= COMP_TYPE_ATTRIBUTES (t1
, t2
)))
803 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
806 switch (TREE_CODE (t1
))
808 case TEMPLATE_TEMPLATE_PARM
:
809 if (TEMPLATE_TYPE_IDX (t1
) != TEMPLATE_TYPE_IDX (t2
)
810 || TEMPLATE_TYPE_LEVEL (t1
) != TEMPLATE_TYPE_LEVEL (t2
))
812 if (! comp_template_parms (DECL_TEMPLATE_PARMS (TYPE_NAME (t1
)),
813 DECL_TEMPLATE_PARMS (TYPE_NAME (t2
))))
815 if (! CLASSTYPE_TEMPLATE_INFO (t1
) && ! CLASSTYPE_TEMPLATE_INFO (t2
))
817 /* Don't check inheritance. */
823 if (CLASSTYPE_TEMPLATE_INFO (t1
) && CLASSTYPE_TEMPLATE_INFO (t2
)
824 && (CLASSTYPE_TI_TEMPLATE (t1
) == CLASSTYPE_TI_TEMPLATE (t2
)
825 || TREE_CODE (t1
) == TEMPLATE_TEMPLATE_PARM
))
826 return comp_template_args (CLASSTYPE_TI_ARGS (t1
),
827 CLASSTYPE_TI_ARGS (t2
));
833 val
= (comptypes (build_pointer_type (TYPE_OFFSET_BASETYPE (t1
)),
834 build_pointer_type (TYPE_OFFSET_BASETYPE (t2
)), strict
)
835 && comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
));
839 if (! compexcepttypes (t1
, t2
))
842 /* This case is anti-symmetrical!
843 One can pass a base member (or member function)
844 to something expecting a derived member (or member function),
845 but not vice-versa! */
847 val
= (comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
)
848 && compparms (TYPE_ARG_TYPES (t1
),
849 TYPE_ARG_TYPES (t2
), strict
));
856 /* first, check whether the referred types match with the
857 required level of strictness */
858 val
= comptypes (t1
, t2
, strict
);
861 /* if they do not, try more relaxed alternatives */
864 if (TREE_CODE (t1
) == RECORD_TYPE
&& TREE_CODE (t2
) == RECORD_TYPE
)
868 rval
= t1
== t2
|| DERIVED_FROM_P (t1
, t2
);
877 val
= DERIVED_FROM_P (t2
, t1
);
886 if (! compexcepttypes (t1
, t2
))
889 val
= ((TREE_TYPE (t1
) == TREE_TYPE (t2
)
890 || comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
))
891 && compparms (TYPE_ARG_TYPES (t1
), TYPE_ARG_TYPES (t2
), strict
));
895 /* Target types must match incl. qualifiers. */
896 val
= comp_array_types (comptypes
, t1
, t2
, strict
);
899 case TEMPLATE_TYPE_PARM
:
900 return TEMPLATE_TYPE_IDX (t1
) == TEMPLATE_TYPE_IDX (t2
)
901 && TEMPLATE_TYPE_LEVEL (t1
) == TEMPLATE_TYPE_LEVEL (t2
);
904 if (TYPE_IDENTIFIER (t1
) != TYPE_IDENTIFIER (t2
))
906 return comptypes (TYPE_CONTEXT (t1
), TYPE_CONTEXT (t2
), 1);
911 return attrval
== 2 && val
== 1 ? 2 : val
;
914 /* Subroutine of comp_target-types. Make sure that the cv-quals change
915 only in the same direction as the target type. */
918 comp_cv_target_types (ttl
, ttr
, nptrs
)
923 int c
= TYPE_READONLY (ttl
) - TYPE_READONLY (ttr
);
924 int v
= TYPE_VOLATILE (ttl
) - TYPE_VOLATILE (ttr
);
926 if ((c
> 0 && v
< 0) || (c
< 0 && v
> 0))
929 if (TYPE_MAIN_VARIANT (ttl
) == TYPE_MAIN_VARIANT (ttr
))
930 return (c
+ v
< 0) ? -1 : 1;
932 t
= comp_target_types (ttl
, ttr
, nptrs
);
933 if ((t
== 1 && c
+ v
>= 0) || (t
== -1 && c
+ v
<= 0))
939 /* Return 1 or -1 if TTL and TTR are pointers to types that are equivalent,
940 ignoring their qualifiers, 0 if not. Return 1 means that TTR can be
941 converted to TTL. Return -1 means that TTL can be converted to TTR but
944 NPTRS is the number of pointers we can strip off and keep cool.
945 This is used to permit (for aggr A, aggr B) A, B* to convert to A*,
946 but to not permit B** to convert to A**.
948 This should go away. Callers should use can_convert or something
949 similar instead. (jason 17 Apr 1997) */
952 comp_target_types (ttl
, ttr
, nptrs
)
956 ttl
= TYPE_MAIN_VARIANT (ttl
);
957 ttr
= TYPE_MAIN_VARIANT (ttr
);
961 if (TREE_CODE (ttr
) != TREE_CODE (ttl
))
964 if ((TREE_CODE (ttr
) == POINTER_TYPE
965 || TREE_CODE (ttr
) == REFERENCE_TYPE
)
966 /* If we get a pointer with nptrs == 0, we don't allow any tweaking
967 of the type pointed to. This is necessary for reference init
968 semantics. We won't get here from a previous call with nptrs == 1;
969 for multi-level pointers we end up in comp_ptr_ttypes. */
972 int is_ptr
= TREE_CODE (ttr
) == POINTER_TYPE
;
974 ttl
= TREE_TYPE (ttl
);
975 ttr
= TREE_TYPE (ttr
);
979 if (TREE_CODE (ttl
) == UNKNOWN_TYPE
980 || TREE_CODE (ttr
) == UNKNOWN_TYPE
)
982 else if (TREE_CODE (ttl
) == VOID_TYPE
983 && TREE_CODE (ttr
) != FUNCTION_TYPE
984 && TREE_CODE (ttr
) != METHOD_TYPE
985 && TREE_CODE (ttr
) != OFFSET_TYPE
)
987 else if (TREE_CODE (ttr
) == VOID_TYPE
988 && TREE_CODE (ttl
) != FUNCTION_TYPE
989 && TREE_CODE (ttl
) != METHOD_TYPE
990 && TREE_CODE (ttl
) != OFFSET_TYPE
)
992 else if (TREE_CODE (ttl
) == POINTER_TYPE
993 || TREE_CODE (ttl
) == ARRAY_TYPE
)
995 if (comp_ptr_ttypes (ttl
, ttr
))
997 else if (comp_ptr_ttypes (ttr
, ttl
))
1003 /* Const and volatile mean something different for function types,
1004 so the usual checks are not appropriate. */
1005 if (TREE_CODE (ttl
) == FUNCTION_TYPE
|| TREE_CODE (ttl
) == METHOD_TYPE
)
1006 return comp_target_types (ttl
, ttr
, nptrs
- 1);
1008 return comp_cv_target_types (ttl
, ttr
, nptrs
- 1);
1011 if (TREE_CODE (ttr
) == ARRAY_TYPE
)
1012 return comp_array_types (comp_target_types
, ttl
, ttr
, 0);
1013 else if (TREE_CODE (ttr
) == FUNCTION_TYPE
|| TREE_CODE (ttr
) == METHOD_TYPE
)
1020 if (comptypes (TREE_TYPE (ttl
), TREE_TYPE (ttr
), 1) == 0)
1025 switch (comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), -1))
1034 argsl
= TYPE_ARG_TYPES (ttl
);
1035 argsr
= TYPE_ARG_TYPES (ttr
);
1037 /* Compare 'this' here, not in comp_target_parms. */
1038 if (TREE_CODE (ttr
) == METHOD_TYPE
)
1040 tree tl
= TYPE_METHOD_BASETYPE (ttl
);
1041 tree tr
= TYPE_METHOD_BASETYPE (ttr
);
1043 if (comptypes (tr
, tl
, 0) == 0)
1045 if (comptypes (tl
, tr
, 0))
1051 argsl
= TREE_CHAIN (argsl
);
1052 argsr
= TREE_CHAIN (argsr
);
1055 switch (comp_target_parms (argsl
, argsr
, 1))
1063 return saw_contra
? -1 : 1;
1066 else if (TREE_CODE (ttr
) == OFFSET_TYPE
)
1070 /* Contravariance: we can assign a pointer to base member to a pointer
1071 to derived member. Note difference from simple pointer case, where
1072 we can pass a pointer to derived to a pointer to base. */
1073 if (comptypes (TYPE_OFFSET_BASETYPE (ttr
),
1074 TYPE_OFFSET_BASETYPE (ttl
), 0))
1076 else if (comptypes (TYPE_OFFSET_BASETYPE (ttl
),
1077 TYPE_OFFSET_BASETYPE (ttr
), 0))
1087 ttl
= TREE_TYPE (ttl
);
1088 ttr
= TREE_TYPE (ttr
);
1090 if (TREE_CODE (ttl
) == POINTER_TYPE
1091 || TREE_CODE (ttl
) == ARRAY_TYPE
)
1093 if (comp_ptr_ttypes (ttl
, ttr
))
1099 if (comp_cv_target_types (ttl
, ttr
, nptrs
) == 1)
1104 else if (IS_AGGR_TYPE (ttl
))
1108 if (comptypes (build_pointer_type (ttl
), build_pointer_type (ttr
), 0))
1110 if (comptypes (build_pointer_type (ttr
), build_pointer_type (ttl
), 0))
1118 /* Returns 1 if TYPE1 is more cv-qualified than TYPE2, -1 if TYPE2 is
1119 more cv-qualified that TYPE1, and 0 otherwise. */
1122 comp_cv_qualification (type1
, type2
)
1126 if (TYPE_READONLY (type1
) == TYPE_READONLY (type2
)
1127 && TYPE_VOLATILE (type1
) == TYPE_VOLATILE (type2
))
1130 if (TYPE_READONLY (type1
) >= TYPE_READONLY (type2
)
1131 && TYPE_VOLATILE (type1
) >= TYPE_VOLATILE (type2
))
1134 if (TYPE_READONLY (type2
) >= TYPE_READONLY (type1
)
1135 && TYPE_VOLATILE (type2
) >= TYPE_VOLATILE (type1
))
1141 /* Returns 1 if the cv-qualification signature of TYPE1 is a proper
1142 subset of the cv-qualification signature of TYPE2, and the types
1143 are similar. Returns -1 if the other way 'round, and 0 otherwise. */
1146 comp_cv_qual_signature (type1
, type2
)
1150 if (comp_ptr_ttypes_real (type2
, type1
, -1))
1152 else if (comp_ptr_ttypes_real (type1
, type2
, -1))
1158 /* If two types share a common base type, return that basetype.
1159 If there is not a unique most-derived base type, this function
1160 returns ERROR_MARK_NODE. */
1163 common_base_type (tt1
, tt2
)
1166 tree best
= NULL_TREE
;
1169 /* If one is a baseclass of another, that's good enough. */
1170 if (UNIQUELY_DERIVED_FROM_P (tt1
, tt2
))
1172 if (UNIQUELY_DERIVED_FROM_P (tt2
, tt1
))
1175 /* Otherwise, try to find a unique baseclass of TT1
1176 that is shared by TT2, and follow that down. */
1177 for (i
= CLASSTYPE_N_BASECLASSES (tt1
)-1; i
>= 0; i
--)
1179 tree basetype
= TYPE_BINFO_BASETYPE (tt1
, i
);
1180 tree trial
= common_base_type (basetype
, tt2
);
1183 if (trial
== error_mark_node
)
1185 if (best
== NULL_TREE
)
1187 else if (best
!= trial
)
1188 return error_mark_node
;
1193 for (i
= CLASSTYPE_N_BASECLASSES (tt2
)-1; i
>= 0; i
--)
1195 tree basetype
= TYPE_BINFO_BASETYPE (tt2
, i
);
1196 tree trial
= common_base_type (tt1
, basetype
);
1199 if (trial
== error_mark_node
)
1201 if (best
== NULL_TREE
)
1203 else if (best
!= trial
)
1204 return error_mark_node
;
1210 /* Subroutines of `comptypes'. */
1212 /* Return 1 if two parameter type lists PARMS1 and PARMS2
1213 are equivalent in the sense that functions with those parameter types
1214 can have equivalent types.
1215 If either list is empty, we win.
1216 Otherwise, the two lists must be equivalent, element by element.
1218 C++: See comment above about TYPE1, TYPE2.
1220 STRICT is no longer used. */
1223 compparms (parms1
, parms2
, strict
)
1224 tree parms1
, parms2
;
1227 register tree t1
= parms1
, t2
= parms2
;
1229 /* An unspecified parmlist matches any specified parmlist
1230 whose argument types don't need default promotions. */
1234 if (t1
== 0 && t2
== 0)
1236 /* If one parmlist is shorter than the other,
1237 they fail to match. */
1238 if (t1
== 0 || t2
== 0)
1240 if (! comptypes (TREE_VALUE (t2
), TREE_VALUE (t1
), 1))
1243 t1
= TREE_CHAIN (t1
);
1244 t2
= TREE_CHAIN (t2
);
1248 /* This really wants return whether or not parameter type lists
1249 would make their owning functions assignment compatible or not.
1251 The return value is like for comp_target_types.
1253 This should go away, possibly with the exception of the empty parmlist
1254 conversion; there are no conversions between function types in C++.
1255 (jason 17 Apr 1997) */
1258 comp_target_parms (parms1
, parms2
, strict
)
1259 tree parms1
, parms2
;
1262 register tree t1
= parms1
, t2
= parms2
;
1263 int warn_contravariance
= 0;
1265 /* In C, an unspecified parmlist matches any specified parmlist
1266 whose argument types don't need default promotions. This is not
1267 true for C++, but let's do it anyway for unfixed headers. */
1269 if (t1
== 0 && t2
!= 0)
1271 cp_pedwarn ("ANSI C++ prohibits conversion from `(%#T)' to `(...)'",
1273 return self_promoting_args_p (t2
);
1276 return self_promoting_args_p (t1
);
1278 for (; t1
|| t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
1282 /* If one parmlist is shorter than the other,
1283 they fail to match, unless STRICT is <= 0. */
1284 if (t1
== 0 || t2
== 0)
1289 return 1 + warn_contravariance
;
1290 return ((t1
&& TREE_PURPOSE (t1
)) + warn_contravariance
);
1292 p1
= TREE_VALUE (t1
);
1293 p2
= TREE_VALUE (t2
);
1294 if (comptypes (p1
, p2
, 1))
1300 if ((TREE_CODE (p1
) == POINTER_TYPE
&& TREE_CODE (p2
) == POINTER_TYPE
)
1301 || (TREE_CODE (p1
) == REFERENCE_TYPE
1302 && TREE_CODE (p2
) == REFERENCE_TYPE
))
1305 && (TYPE_MAIN_VARIANT (TREE_TYPE (p1
))
1306 == TYPE_MAIN_VARIANT (TREE_TYPE (p2
))))
1309 /* The following is wrong for contravariance,
1310 but many programs depend on it. */
1311 if (TREE_TYPE (p1
) == void_type_node
)
1313 if (TREE_TYPE (p2
) == void_type_node
)
1315 warn_contravariance
= 1;
1318 if (IS_AGGR_TYPE (TREE_TYPE (p1
)))
1320 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (p1
)),
1321 TYPE_MAIN_VARIANT (TREE_TYPE (p2
)), 1) == 0)
1325 /* Note backwards order due to contravariance. */
1326 if (comp_target_types (p2
, p1
, 1) <= 0)
1328 if (comp_target_types (p1
, p2
, 1) > 0)
1330 warn_contravariance
= 1;
1337 return warn_contravariance
? -1 : 1;
1340 /* Return 1 if PARMS specifies a fixed number of parameters
1341 and none of their types is affected by default promotions. */
1344 self_promoting_args_p (parms
)
1348 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
1350 register tree type
= TREE_VALUE (t
);
1352 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
1358 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
1361 if (C_PROMOTING_INTEGER_TYPE_P (type
))
1367 /* Return an unsigned type the same as TYPE in other respects.
1369 C++: must make these work for type variants as well. */
1372 unsigned_type (type
)
1375 tree type1
= TYPE_MAIN_VARIANT (type
);
1376 if (type1
== signed_char_type_node
|| type1
== char_type_node
)
1377 return unsigned_char_type_node
;
1378 if (type1
== integer_type_node
)
1379 return unsigned_type_node
;
1380 if (type1
== short_integer_type_node
)
1381 return short_unsigned_type_node
;
1382 if (type1
== long_integer_type_node
)
1383 return long_unsigned_type_node
;
1384 if (type1
== long_long_integer_type_node
)
1385 return long_long_unsigned_type_node
;
1386 if (type1
== intTI_type_node
)
1387 return unsigned_intTI_type_node
;
1388 if (type1
== intDI_type_node
)
1389 return unsigned_intDI_type_node
;
1390 if (type1
== intSI_type_node
)
1391 return unsigned_intSI_type_node
;
1392 if (type1
== intHI_type_node
)
1393 return unsigned_intHI_type_node
;
1394 if (type1
== intQI_type_node
)
1395 return unsigned_intQI_type_node
;
1397 return signed_or_unsigned_type (1, type
);
1400 /* Return a signed type the same as TYPE in other respects. */
1406 tree type1
= TYPE_MAIN_VARIANT (type
);
1407 if (type1
== unsigned_char_type_node
|| type1
== char_type_node
)
1408 return signed_char_type_node
;
1409 if (type1
== unsigned_type_node
)
1410 return integer_type_node
;
1411 if (type1
== short_unsigned_type_node
)
1412 return short_integer_type_node
;
1413 if (type1
== long_unsigned_type_node
)
1414 return long_integer_type_node
;
1415 if (type1
== long_long_unsigned_type_node
)
1416 return long_long_integer_type_node
;
1417 if (type1
== unsigned_intTI_type_node
)
1418 return intTI_type_node
;
1419 if (type1
== unsigned_intDI_type_node
)
1420 return intDI_type_node
;
1421 if (type1
== unsigned_intSI_type_node
)
1422 return intSI_type_node
;
1423 if (type1
== unsigned_intHI_type_node
)
1424 return intHI_type_node
;
1425 if (type1
== unsigned_intQI_type_node
)
1426 return intQI_type_node
;
1428 return signed_or_unsigned_type (0, type
);
1431 /* Return a type the same as TYPE except unsigned or
1432 signed according to UNSIGNEDP. */
1435 signed_or_unsigned_type (unsignedp
, type
)
1439 if (! INTEGRAL_TYPE_P (type
)
1440 || TREE_UNSIGNED (type
) == unsignedp
)
1443 if (TYPE_PRECISION (type
) == TYPE_PRECISION (signed_char_type_node
))
1444 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
1445 if (TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
))
1446 return unsignedp
? unsigned_type_node
: integer_type_node
;
1447 if (TYPE_PRECISION (type
) == TYPE_PRECISION (short_integer_type_node
))
1448 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
1449 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_integer_type_node
))
1450 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
1451 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_long_integer_type_node
))
1452 return (unsignedp
? long_long_unsigned_type_node
1453 : long_long_integer_type_node
);
1457 /* Compute the value of the `sizeof' operator. */
1463 enum tree_code code
= TREE_CODE (type
);
1466 if (processing_template_decl
)
1467 return build_min (SIZEOF_EXPR
, sizetype
, type
);
1469 if (code
== FUNCTION_TYPE
)
1471 if (pedantic
|| warn_pointer_arith
)
1472 pedwarn ("ANSI C++ forbids taking the sizeof a function type");
1473 return size_int (1);
1475 if (code
== METHOD_TYPE
)
1477 if (pedantic
|| warn_pointer_arith
)
1478 pedwarn ("ANSI C++ forbids taking the sizeof a method type");
1479 return size_int (1);
1481 if (code
== VOID_TYPE
)
1483 if (pedantic
|| warn_pointer_arith
)
1484 pedwarn ("ANSI C++ forbids taking the sizeof a void type");
1485 return size_int (1);
1487 if (code
== ERROR_MARK
)
1488 return size_int (1);
1490 /* ARM $5.3.2: ``When applied to a reference, the result is the size of the
1491 referenced object.'' */
1492 if (code
== REFERENCE_TYPE
)
1493 type
= TREE_TYPE (type
);
1495 /* We couldn't find anything in the ARM or the draft standard that says,
1496 one way or the other, if doing sizeof on something that doesn't have
1497 an object associated with it is correct or incorrect. For example, if
1498 you declare `struct S { char str[16]; };', and in your program do
1499 a `sizeof (S::str)', should we flag that as an error or should we give
1500 the size of it? Since it seems like a reasonable thing to do, we'll go
1501 with giving the value. */
1502 if (code
== OFFSET_TYPE
)
1503 type
= TREE_TYPE (type
);
1505 /* @@ This also produces an error for a signature ref.
1506 In that case we should be able to do better. */
1507 if (IS_SIGNATURE (type
))
1509 error ("`sizeof' applied to a signature type");
1510 return size_int (0);
1513 if (TYPE_SIZE (complete_type (type
)) == 0)
1515 cp_error ("`sizeof' applied to incomplete type `%T'", type
);
1516 return size_int (0);
1519 /* Convert in case a char is more than one unit. */
1520 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
1521 size_int (TYPE_PRECISION (char_type_node
)));
1522 t
= convert (sizetype
, t
);
1523 /* size_binop does not put the constant in range, so do it now. */
1524 if (TREE_CODE (t
) == INTEGER_CST
&& force_fit_type (t
, 0))
1525 TREE_CONSTANT_OVERFLOW (t
) = TREE_OVERFLOW (t
) = 1;
1533 if (processing_template_decl
)
1534 return build_min (SIZEOF_EXPR
, sizetype
, e
);
1536 if (TREE_CODE (e
) == COMPONENT_REF
1537 && DECL_BIT_FIELD (TREE_OPERAND (e
, 1)))
1538 error ("sizeof applied to a bit-field");
1539 /* ANSI says arrays and functions are converted inside comma.
1540 But we can't really convert them in build_compound_expr
1541 because that would break commas in lvalues.
1542 So do the conversion here if operand was a comma. */
1543 if (TREE_CODE (e
) == COMPOUND_EXPR
1544 && (TREE_CODE (TREE_TYPE (e
)) == ARRAY_TYPE
1545 || TREE_CODE (TREE_TYPE (e
)) == FUNCTION_TYPE
))
1546 e
= default_conversion (e
);
1547 else if (TREE_CODE (e
) == TREE_LIST
)
1549 tree t
= TREE_VALUE (e
);
1552 && TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
1553 || is_overloaded_fn (t
)))
1554 pedwarn ("ANSI C++ forbids taking the sizeof a function type");
1556 return c_sizeof (TREE_TYPE (e
));
1560 c_sizeof_nowarn (type
)
1563 enum tree_code code
= TREE_CODE (type
);
1566 if (code
== FUNCTION_TYPE
1567 || code
== METHOD_TYPE
1568 || code
== VOID_TYPE
1569 || code
== ERROR_MARK
)
1570 return size_int (1);
1571 if (code
== REFERENCE_TYPE
)
1572 type
= TREE_TYPE (type
);
1574 if (TYPE_SIZE (type
) == 0)
1575 return size_int (0);
1577 /* Convert in case a char is more than one unit. */
1578 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
1579 size_int (TYPE_PRECISION (char_type_node
)));
1580 t
= convert (sizetype
, t
);
1581 force_fit_type (t
, 0);
1585 /* Implement the __alignof keyword: Return the minimum required
1586 alignment of TYPE, measured in bytes. */
1592 enum tree_code code
= TREE_CODE (type
);
1595 if (processing_template_decl
)
1596 return build_min (ALIGNOF_EXPR
, sizetype
, type
);
1598 if (code
== FUNCTION_TYPE
|| code
== METHOD_TYPE
)
1599 return size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
1601 if (code
== VOID_TYPE
|| code
== ERROR_MARK
)
1602 return size_int (1);
1604 /* C++: this is really correct! */
1605 if (code
== REFERENCE_TYPE
)
1606 type
= TREE_TYPE (type
);
1608 /* @@ This also produces an error for a signature ref.
1609 In that case we should be able to do better. */
1610 if (IS_SIGNATURE (type
))
1612 error ("`__alignof' applied to a signature type");
1613 return size_int (1);
1616 t
= size_int (TYPE_ALIGN (type
) / BITS_PER_UNIT
);
1617 force_fit_type (t
, 0);
1621 /* Perform default promotions for C data used in expressions.
1622 Arrays and functions are converted to pointers;
1623 enumeral types or short or char, to int.
1624 In addition, manifest constants symbols are replaced by their values.
1626 C++: this will automatically bash references to their target type. */
1629 decay_conversion (exp
)
1632 register tree type
= TREE_TYPE (exp
);
1633 register enum tree_code code
= TREE_CODE (type
);
1635 if (code
== OFFSET_TYPE
)
1637 if (TREE_CODE (exp
) == OFFSET_REF
)
1638 return decay_conversion (resolve_offset_ref (exp
));
1640 type
= TREE_TYPE (type
);
1641 code
= TREE_CODE (type
);
1643 if (type
== unknown_type_node
)
1645 cp_pedwarn ("assuming & on overloaded member function");
1646 return build_unary_op (ADDR_EXPR
, exp
, 0);
1650 if (code
== REFERENCE_TYPE
)
1652 exp
= convert_from_reference (exp
);
1653 type
= TREE_TYPE (exp
);
1654 code
= TREE_CODE (type
);
1657 /* Constants can be used directly unless they're not loadable. */
1658 if (TREE_CODE (exp
) == CONST_DECL
)
1659 exp
= DECL_INITIAL (exp
);
1660 /* Replace a nonvolatile const static variable with its value. */
1661 else if (TREE_READONLY_DECL_P (exp
))
1663 exp
= decl_constant_value (exp
);
1664 type
= TREE_TYPE (exp
);
1667 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
1668 Leave such NOP_EXPRs, since RHS is being used in non-lvalue context. */
1670 if (code
== VOID_TYPE
)
1672 error ("void value not ignored as it ought to be");
1673 return error_mark_node
;
1675 if (code
== FUNCTION_TYPE
)
1677 return build_unary_op (ADDR_EXPR
, exp
, 0);
1679 if (code
== METHOD_TYPE
)
1681 cp_pedwarn ("assuming & on `%E'", exp
);
1682 return build_unary_op (ADDR_EXPR
, exp
, 0);
1684 if (code
== ARRAY_TYPE
)
1689 int constp
, volatilep
;
1691 if (TREE_CODE (exp
) == INDIRECT_REF
)
1693 /* Stripping away the INDIRECT_REF is not the right
1694 thing to do for references... */
1695 tree inner
= TREE_OPERAND (exp
, 0);
1696 if (TREE_CODE (TREE_TYPE (inner
)) == REFERENCE_TYPE
)
1698 inner
= build1 (CONVERT_EXPR
,
1699 build_pointer_type (TREE_TYPE
1700 (TREE_TYPE (inner
))),
1702 TREE_CONSTANT (inner
) = TREE_CONSTANT (TREE_OPERAND (inner
, 0));
1704 return cp_convert (build_pointer_type (TREE_TYPE (type
)), inner
);
1707 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
1709 tree op1
= decay_conversion (TREE_OPERAND (exp
, 1));
1710 return build (COMPOUND_EXPR
, TREE_TYPE (op1
),
1711 TREE_OPERAND (exp
, 0), op1
);
1715 && ! (TREE_CODE (exp
) == CONSTRUCTOR
&& TREE_STATIC (exp
)))
1717 error ("invalid use of non-lvalue array");
1718 return error_mark_node
;
1721 constp
= volatilep
= 0;
1722 if (TREE_CODE_CLASS (TREE_CODE (exp
)) == 'r'
1723 || TREE_CODE_CLASS (TREE_CODE (exp
)) == 'd')
1725 constp
= TREE_READONLY (exp
);
1726 volatilep
= TREE_THIS_VOLATILE (exp
);
1729 restype
= TREE_TYPE (type
);
1730 if (TYPE_READONLY (type
) || TYPE_VOLATILE (type
)
1731 || constp
|| volatilep
)
1732 restype
= cp_build_type_variant (restype
,
1733 TYPE_READONLY (type
) || constp
,
1734 TYPE_VOLATILE (type
) || volatilep
);
1735 ptrtype
= build_pointer_type (restype
);
1737 if (TREE_CODE (exp
) == VAR_DECL
)
1739 /* ??? This is not really quite correct
1740 in that the type of the operand of ADDR_EXPR
1741 is not the target type of the type of the ADDR_EXPR itself.
1742 Question is, can this lossage be avoided? */
1743 adr
= build1 (ADDR_EXPR
, ptrtype
, exp
);
1744 if (mark_addressable (exp
) == 0)
1745 return error_mark_node
;
1746 TREE_CONSTANT (adr
) = staticp (exp
);
1747 TREE_SIDE_EFFECTS (adr
) = 0; /* Default would be, same as EXP. */
1750 /* This way is better for a COMPONENT_REF since it can
1751 simplify the offset for a component. */
1752 adr
= build_unary_op (ADDR_EXPR
, exp
, 1);
1753 return cp_convert (ptrtype
, adr
);
1760 default_conversion (exp
)
1764 enum tree_code code
;
1766 exp
= decay_conversion (exp
);
1768 type
= TREE_TYPE (exp
);
1769 code
= TREE_CODE (type
);
1771 if (INTEGRAL_CODE_P (code
))
1773 tree t
= type_promotes_to (type
);
1775 return cp_convert (t
, exp
);
1781 /* Take the address of an inline function without setting TREE_ADDRESSABLE
1785 inline_conversion (exp
)
1788 if (TREE_CODE (exp
) == FUNCTION_DECL
)
1790 tree type
= build_type_variant
1791 (TREE_TYPE (exp
), TREE_READONLY (exp
), TREE_THIS_VOLATILE (exp
));
1792 exp
= build1 (ADDR_EXPR
, build_pointer_type (type
), exp
);
1797 /* Returns nonzero iff exp is a STRING_CST or the result of applying
1798 decay_conversion to one. */
1801 string_conv_p (totype
, exp
, warn
)
1807 if (! flag_const_strings
|| TREE_CODE (totype
) != POINTER_TYPE
)
1810 t
= TREE_TYPE (totype
);
1811 if (! comptypes (t
, char_type_node
, 1)
1812 && ! comptypes (t
, wchar_type_node
, 1))
1815 if (TREE_CODE (exp
) != STRING_CST
)
1817 t
= build_pointer_type (build_type_variant (t
, 1, 0));
1818 if (! comptypes (TREE_TYPE (exp
), t
, 1))
1821 if (TREE_CODE (exp
) != ADDR_EXPR
1822 || TREE_CODE (TREE_OPERAND (exp
, 0)) != STRING_CST
)
1826 /* This warning is not very useful, as it complains about printf. */
1827 if (warn
&& warn_write_strings
)
1828 cp_warning ("deprecated conversion from string constant to `char *'");
1834 build_object_ref (datum
, basetype
, field
)
1835 tree datum
, basetype
, field
;
1838 if (datum
== error_mark_node
)
1839 return error_mark_node
;
1841 dtype
= TREE_TYPE (datum
);
1842 if (TREE_CODE (dtype
) == REFERENCE_TYPE
)
1843 dtype
= TREE_TYPE (dtype
);
1844 if (! IS_AGGR_TYPE_CODE (TREE_CODE (dtype
)))
1846 cp_error ("request for member `%T::%D' in expression of non-aggregate type `%T'",
1847 basetype
, field
, dtype
);
1848 return error_mark_node
;
1850 else if (IS_SIGNATURE (basetype
))
1852 warning ("signature name in scope resolution ignored");
1853 return build_component_ref (datum
, field
, NULL_TREE
, 1);
1855 else if (is_aggr_type (basetype
, 1))
1857 tree binfo
= binfo_or_else (basetype
, dtype
);
1859 return build_x_component_ref (build_scoped_ref (datum
, basetype
),
1862 return error_mark_node
;
1865 /* Like `build_component_ref, but uses an already found field, and converts
1866 from a reference. Must compute access for current_class_ref.
1870 build_component_ref_1 (datum
, field
, protect
)
1874 return convert_from_reference
1875 (build_component_ref (datum
, field
, NULL_TREE
, protect
));
1878 /* Given a COND_EXPR, MIN_EXPR, or MAX_EXPR in T, return it in a form that we
1879 can, for example, use as an lvalue. This code used to be in
1880 unary_complex_lvalue, but we needed it to deal with `a = (d == c) ? b : c'
1881 expressions, where we're dealing with aggregates. But now it's again only
1882 called from unary_complex_lvalue. The case (in particular) that led to
1883 this was with CODE == ADDR_EXPR, since it's not an lvalue when we'd
1887 rationalize_conditional_expr (code
, t
)
1888 enum tree_code code
;
1891 /* For MIN_EXPR or MAX_EXPR, fold-const.c has arranged things so that
1892 the first operand is always the one to be used if both operands
1893 are equal, so we know what conditional expression this used to be. */
1894 if (TREE_CODE (t
) == MIN_EXPR
|| TREE_CODE (t
) == MAX_EXPR
)
1897 build_conditional_expr (build_x_binary_op ((TREE_CODE (t
) == MIN_EXPR
1898 ? LE_EXPR
: GE_EXPR
),
1899 TREE_OPERAND (t
, 0),
1900 TREE_OPERAND (t
, 1)),
1901 build_unary_op (code
, TREE_OPERAND (t
, 0), 0),
1902 build_unary_op (code
, TREE_OPERAND (t
, 1), 0));
1906 build_conditional_expr (TREE_OPERAND (t
, 0),
1907 build_unary_op (code
, TREE_OPERAND (t
, 1), 0),
1908 build_unary_op (code
, TREE_OPERAND (t
, 2), 0));
1911 /* Given the TYPE of an anonymous union field inside T, return the
1912 FIELD_DECL for the field. If not found return NULL_TREE. Because
1913 anonymous unions can nest, we must also search all anonymous unions
1914 that are directly reachable. */
1917 lookup_anon_field (t
, type
)
1922 for (field
= TYPE_FIELDS (t
); field
; field
= TREE_CHAIN (field
))
1924 if (TREE_STATIC (field
))
1926 if (TREE_CODE (field
) != FIELD_DECL
)
1929 /* If we find it directly, return the field. */
1930 if (DECL_NAME (field
) == NULL_TREE
1931 && type
== TREE_TYPE (field
))
1936 /* Otherwise, it could be nested, search harder. */
1937 if (DECL_NAME (field
) == NULL_TREE
1938 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
1940 tree subfield
= lookup_anon_field (TREE_TYPE (field
), type
);
1948 /* Build a COMPONENT_REF for a given DATUM, and it's member COMPONENT.
1949 COMPONENT can be an IDENTIFIER_NODE that is the name of the member
1950 that we are interested in, or it can be a FIELD_DECL. */
1953 build_component_ref (datum
, component
, basetype_path
, protect
)
1954 tree datum
, component
, basetype_path
;
1957 register tree basetype
= TREE_TYPE (datum
);
1958 register enum tree_code code
;
1959 register tree field
= NULL
;
1962 if (processing_template_decl
)
1963 return build_min_nt (COMPONENT_REF
, datum
, component
);
1965 /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference
1967 switch (TREE_CODE (datum
))
1971 tree value
= build_component_ref (TREE_OPERAND (datum
, 1), component
,
1972 basetype_path
, protect
);
1973 return build (COMPOUND_EXPR
, TREE_TYPE (value
),
1974 TREE_OPERAND (datum
, 0), value
);
1977 return build_conditional_expr
1978 (TREE_OPERAND (datum
, 0),
1979 build_component_ref (TREE_OPERAND (datum
, 1), component
,
1980 basetype_path
, protect
),
1981 build_component_ref (TREE_OPERAND (datum
, 2), component
,
1982 basetype_path
, protect
));
1985 cp_error ("invalid use of %D", datum
);
1986 datum
= error_mark_node
;
1993 code
= TREE_CODE (basetype
);
1995 if (code
== REFERENCE_TYPE
)
1997 datum
= convert_from_reference (datum
);
1998 basetype
= TREE_TYPE (datum
);
1999 code
= TREE_CODE (basetype
);
2001 if (TREE_CODE (datum
) == OFFSET_REF
)
2003 datum
= resolve_offset_ref (datum
);
2004 basetype
= TREE_TYPE (datum
);
2005 code
= TREE_CODE (basetype
);
2008 /* First, see if there is a field or component with name COMPONENT. */
2009 if (TREE_CODE (component
) == TREE_LIST
)
2011 /* I could not trigger this code. MvL */
2012 my_friendly_abort (980326);
2014 my_friendly_assert (!(TREE_CHAIN (component
) == NULL_TREE
2015 && DECL_CHAIN (TREE_VALUE (component
)) == NULL_TREE
), 309);
2017 return build (COMPONENT_REF
, TREE_TYPE (component
), datum
, component
);
2020 if (! IS_AGGR_TYPE_CODE (code
))
2022 if (code
!= ERROR_MARK
)
2023 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
2024 component
, datum
, basetype
);
2025 return error_mark_node
;
2028 if (!complete_type_or_else (basetype
))
2029 return error_mark_node
;
2031 if (TREE_CODE (component
) == BIT_NOT_EXPR
)
2033 if (TYPE_IDENTIFIER (basetype
) != TREE_OPERAND (component
, 0))
2035 cp_error ("destructor specifier `%T::~%T' must have matching names",
2036 basetype
, TREE_OPERAND (component
, 0));
2037 return error_mark_node
;
2039 if (! TYPE_HAS_DESTRUCTOR (basetype
))
2041 cp_error ("type `%T' has no destructor", basetype
);
2042 return error_mark_node
;
2044 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype
), 1);
2047 /* Look up component name in the structure type definition. */
2048 if (CLASSTYPE_VFIELD (basetype
)
2049 && DECL_NAME (CLASSTYPE_VFIELD (basetype
)) == component
)
2050 /* Special-case this because if we use normal lookups in an ambiguous
2051 hierarchy, the compiler will abort (because vptr lookups are
2052 not supposed to be ambiguous. */
2053 field
= CLASSTYPE_VFIELD (basetype
);
2054 else if (TREE_CODE (component
) == FIELD_DECL
)
2056 else if (TREE_CODE (component
) == TYPE_DECL
)
2058 cp_pedwarn ("invalid use of type decl `%#D' as expression", component
);
2063 tree name
= component
;
2064 if (TREE_CODE (component
) == VAR_DECL
)
2065 name
= DECL_NAME (component
);
2066 if (basetype_path
== NULL_TREE
)
2067 basetype_path
= TYPE_BINFO (basetype
);
2068 field
= lookup_field (basetype_path
, name
,
2069 protect
&& !VFIELD_NAME_P (name
), 0);
2070 if (field
== error_mark_node
)
2071 return error_mark_node
;
2073 if (field
== NULL_TREE
)
2075 /* Not found as a data field, look for it as a method. If found,
2076 then if this is the only possible one, return it, else
2077 report ambiguity error. */
2078 tree fndecls
= lookup_fnfields (basetype_path
, name
, 1);
2079 if (fndecls
== error_mark_node
)
2080 return error_mark_node
;
2083 if (TREE_CHAIN (fndecls
) == NULL_TREE
2084 && TREE_CODE (TREE_VALUE (fndecls
)) != OVERLOAD
)
2086 tree access
, fndecl
;
2088 /* Unique, so use this one now. */
2089 basetype
= TREE_PURPOSE (fndecls
);
2090 fndecl
= TREE_VALUE (fndecls
);
2091 access
= compute_access (TREE_PURPOSE (fndecls
), fndecl
);
2092 if (access
== access_public_node
)
2094 if (DECL_VINDEX (fndecl
)
2095 && ! resolves_to_fixed_type_p (datum
, 0))
2097 tree addr
= build_unary_op (ADDR_EXPR
, datum
, 0);
2098 tree fntype
= TREE_TYPE (fndecl
);
2100 addr
= convert_pointer_to (DECL_CONTEXT (fndecl
),
2102 datum
= build_indirect_ref (addr
, NULL_PTR
);
2103 my_friendly_assert (datum
!= error_mark_node
, 310);
2104 fndecl
= build_vfn_ref (&addr
, datum
,
2105 DECL_VINDEX (fndecl
));
2106 /* The type of fndecl is a function type,
2107 not a pointer-to-function type, since
2108 build_vfn_ref returns not the correct
2109 vtable slot, but the indirection of the
2110 correct vtable slot. */
2111 TREE_TYPE (fndecl
) = fntype
;
2115 return build (OFFSET_REF
, TREE_TYPE (fndecl
),
2118 if (access
== access_protected_node
)
2119 cp_error ("member function `%D' is protected", fndecl
);
2121 cp_error ("member function `%D' is private", fndecl
);
2122 return error_mark_node
;
2126 /* Just act like build_offset_ref, since the object does
2127 not matter unless we're actually calling the function. */
2130 t
= build_tree_list (error_mark_node
, fndecls
);
2131 TREE_TYPE (t
) = build_offset_type (basetype
,
2137 cp_error ("`%#T' has no member named `%D'", basetype
, name
);
2138 return error_mark_node
;
2140 else if (TREE_TYPE (field
) == error_mark_node
)
2141 return error_mark_node
;
2143 if (TREE_CODE (field
) != FIELD_DECL
)
2145 if (TREE_CODE (field
) == TYPE_DECL
)
2146 cp_pedwarn ("invalid use of type decl `%#D' as expression", field
);
2147 else if (DECL_RTL (field
) != 0)
2150 TREE_USED (field
) = 1;
2155 /* See if we have to do any conversions so that we pick up the field from the
2157 if (DECL_FIELD_CONTEXT (field
) != basetype
)
2159 tree context
= DECL_FIELD_CONTEXT (field
);
2160 tree base
= context
;
2161 while (!comptypes (base
, basetype
,1) && TYPE_NAME (base
)
2162 && ANON_UNION_TYPE_P (base
))
2164 base
= TYPE_CONTEXT (base
);
2167 /* Handle base classes here... */
2168 if (base
!= basetype
&& TYPE_USES_COMPLEX_INHERITANCE (basetype
))
2170 tree addr
= build_unary_op (ADDR_EXPR
, datum
, 0);
2171 if (integer_zerop (addr
))
2173 error ("invalid reference to NULL ptr, use ptr-to-member instead");
2174 return error_mark_node
;
2176 if (VBASE_NAME_P (DECL_NAME (field
)))
2178 /* It doesn't matter which vbase pointer we grab, just
2179 find one of them. */
2180 tree binfo
= get_binfo (base
,
2181 TREE_TYPE (TREE_TYPE (addr
)), 0);
2182 addr
= convert_pointer_to_real (binfo
, addr
);
2185 addr
= convert_pointer_to (base
, addr
);
2186 datum
= build_indirect_ref (addr
, NULL_PTR
);
2187 my_friendly_assert (datum
!= error_mark_node
, 311);
2191 /* Handle things from anon unions here... */
2192 if (TYPE_NAME (context
) && ANON_UNION_TYPE_P (context
))
2194 tree subfield
= lookup_anon_field (basetype
, context
);
2195 tree subdatum
= build_component_ref (datum
, subfield
,
2196 basetype_path
, protect
);
2197 return build_component_ref (subdatum
, field
, basetype_path
, protect
);
2201 ref
= fold (build (COMPONENT_REF
, TREE_TYPE (field
),
2202 break_out_cleanups (datum
), field
));
2204 if (TREE_READONLY (datum
) || TREE_READONLY (field
))
2205 TREE_READONLY (ref
) = 1;
2206 if (TREE_THIS_VOLATILE (datum
) || TREE_THIS_VOLATILE (field
))
2207 TREE_THIS_VOLATILE (ref
) = 1;
2208 if (DECL_LANG_SPECIFIC (field
) && DECL_MUTABLE_P (field
))
2209 TREE_READONLY (ref
) = 0;
2214 /* Variant of build_component_ref for use in expressions, which should
2215 never have REFERENCE_TYPE. */
2218 build_x_component_ref (datum
, component
, basetype_path
, protect
)
2219 tree datum
, component
, basetype_path
;
2222 tree t
= build_component_ref (datum
, component
, basetype_path
, protect
);
2224 if (! processing_template_decl
)
2225 t
= convert_from_reference (t
);
2230 /* Given an expression PTR for a pointer, return an expression
2231 for the value pointed to.
2232 ERRORSTRING is the name of the operator to appear in error messages.
2234 This function may need to overload OPERATOR_FNNAME.
2235 Must also handle REFERENCE_TYPEs for C++. */
2238 build_x_indirect_ref (ptr
, errorstring
)
2244 if (processing_template_decl
)
2245 return build_min_nt (INDIRECT_REF
, ptr
);
2247 rval
= build_opfncall (INDIRECT_REF
, LOOKUP_NORMAL
, ptr
, NULL_TREE
,
2251 return build_indirect_ref (ptr
, errorstring
);
2255 build_indirect_ref (ptr
, errorstring
)
2259 register tree pointer
, type
;
2261 if (ptr
== error_mark_node
)
2262 return error_mark_node
;
2264 pointer
= (TREE_CODE (TREE_TYPE (ptr
)) == REFERENCE_TYPE
2265 ? ptr
: default_conversion (ptr
));
2266 type
= TREE_TYPE (pointer
);
2268 if (ptr
== current_class_ptr
)
2269 return current_class_ref
;
2271 if (TREE_CODE (type
) == POINTER_TYPE
|| TREE_CODE (type
) == REFERENCE_TYPE
)
2273 if (TREE_CODE (pointer
) == ADDR_EXPR
2275 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (pointer
, 0)))
2276 == TYPE_MAIN_VARIANT (TREE_TYPE (type
)))
2277 && (TREE_READONLY (TREE_OPERAND (pointer
, 0))
2278 == TYPE_READONLY (TREE_TYPE (type
)))
2279 && (TREE_THIS_VOLATILE (TREE_OPERAND (pointer
, 0))
2280 == TYPE_VOLATILE (TREE_TYPE (type
))))
2281 return TREE_OPERAND (pointer
, 0);
2284 tree t
= TREE_TYPE (type
);
2285 register tree ref
= build1 (INDIRECT_REF
,
2286 TYPE_MAIN_VARIANT (t
), pointer
);
2288 /* We *must* set TREE_READONLY when dereferencing a pointer to const,
2289 so that we get the proper error message if the result is used
2290 to assign to. Also, &* is supposed to be a no-op. */
2291 TREE_READONLY (ref
) = TYPE_READONLY (t
);
2292 TREE_SIDE_EFFECTS (ref
)
2293 = (TYPE_VOLATILE (t
) || TREE_SIDE_EFFECTS (pointer
)
2295 TREE_THIS_VOLATILE (ref
) = TYPE_VOLATILE (t
);
2299 /* `pointer' won't be an error_mark_node if we were given a
2300 pointer to member, so it's cool to check for this here. */
2301 else if (TYPE_PTRMEMFUNC_P (type
))
2302 error ("invalid use of `%s' on pointer to member function", errorstring
);
2303 else if (TREE_CODE (type
) == RECORD_TYPE
2304 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
)))
2305 error ("cannot dereference signature pointer/reference");
2306 else if (pointer
!= error_mark_node
)
2309 error ("invalid type argument of `%s'", errorstring
);
2311 error ("invalid type argument");
2313 return error_mark_node
;
2316 /* This handles expressions of the form "a[i]", which denotes
2319 This is logically equivalent in C to *(a+i), but we may do it differently.
2320 If A is a variable or a member, we generate a primitive ARRAY_REF.
2321 This avoids forcing the array out of registers, and can work on
2322 arrays that are not lvalues (for example, members of structures returned
2325 If INDEX is of some user-defined type, it must be converted to
2326 integer type. Otherwise, to make a compatible PLUS_EXPR, it
2327 will inherit the type of the array, which will be some pointer type. */
2330 build_array_ref (array
, idx
)
2335 error ("subscript missing in array reference");
2336 return error_mark_node
;
2339 if (TREE_TYPE (array
) == error_mark_node
2340 || TREE_TYPE (idx
) == error_mark_node
)
2341 return error_mark_node
;
2343 if (TREE_CODE (TREE_TYPE (array
)) == ARRAY_TYPE
2344 && TREE_CODE (array
) != INDIRECT_REF
)
2348 /* Subscripting with type char is likely to lose
2349 on a machine where chars are signed.
2350 So warn on any machine, but optionally.
2351 Don't warn for unsigned char since that type is safe.
2352 Don't warn for signed char because anyone who uses that
2353 must have done so deliberately. */
2354 if (warn_char_subscripts
2355 && TYPE_MAIN_VARIANT (TREE_TYPE (idx
)) == char_type_node
)
2356 warning ("array subscript has type `char'");
2358 /* Apply default promotions *after* noticing character types. */
2359 idx
= default_conversion (idx
);
2361 if (TREE_CODE (TREE_TYPE (idx
)) != INTEGER_TYPE
)
2363 error ("array subscript is not an integer");
2364 return error_mark_node
;
2367 /* An array that is indexed by a non-constant
2368 cannot be stored in a register; we must be able to do
2369 address arithmetic on its address.
2370 Likewise an array of elements of variable size. */
2371 if (TREE_CODE (idx
) != INTEGER_CST
2372 || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
))) != 0
2373 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
))))
2376 if (mark_addressable (array
) == 0)
2377 return error_mark_node
;
2379 /* An array that is indexed by a constant value which is not within
2380 the array bounds cannot be stored in a register either; because we
2381 would get a crash in store_bit_field/extract_bit_field when trying
2382 to access a non-existent part of the register. */
2383 if (TREE_CODE (idx
) == INTEGER_CST
2384 && TYPE_VALUES (TREE_TYPE (array
))
2385 && ! int_fits_type_p (idx
, TYPE_VALUES (TREE_TYPE (array
))))
2387 if (mark_addressable (array
) == 0)
2388 return error_mark_node
;
2391 if (pedantic
&& !lvalue_p (array
))
2392 pedwarn ("ANSI C++ forbids subscripting non-lvalue array");
2394 /* Note in C++ it is valid to subscript a `register' array, since
2395 it is valid to take the address of something with that
2396 storage specification. */
2400 while (TREE_CODE (foo
) == COMPONENT_REF
)
2401 foo
= TREE_OPERAND (foo
, 0);
2402 if (TREE_CODE (foo
) == VAR_DECL
&& DECL_REGISTER (foo
))
2403 warning ("subscripting array declared `register'");
2406 type
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array
)));
2407 rval
= build (ARRAY_REF
, type
, array
, idx
);
2408 /* Array ref is const/volatile if the array elements are
2409 or if the array is.. */
2410 TREE_READONLY (rval
)
2411 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array
)))
2412 | TREE_READONLY (array
));
2413 TREE_SIDE_EFFECTS (rval
)
2414 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
2415 | TREE_SIDE_EFFECTS (array
));
2416 TREE_THIS_VOLATILE (rval
)
2417 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
2418 /* This was added by rms on 16 Nov 91.
2419 It fixes vol struct foo *a; a->elts[1]
2420 in an inline function.
2421 Hope it doesn't break something else. */
2422 | TREE_THIS_VOLATILE (array
));
2423 return require_complete_type (fold (rval
));
2427 tree ar
= default_conversion (array
);
2428 tree ind
= default_conversion (idx
);
2430 /* Put the integer in IND to simplify error checking. */
2431 if (TREE_CODE (TREE_TYPE (ar
)) == INTEGER_TYPE
)
2438 if (ar
== error_mark_node
)
2441 if (TREE_CODE (TREE_TYPE (ar
)) != POINTER_TYPE
)
2443 error ("subscripted value is neither array nor pointer");
2444 return error_mark_node
;
2446 if (TREE_CODE (TREE_TYPE (ind
)) != INTEGER_TYPE
)
2448 error ("array subscript is not an integer");
2449 return error_mark_node
;
2452 return build_indirect_ref (build_binary_op_nodefault (PLUS_EXPR
, ar
,
2458 /* Build a function call to function FUNCTION with parameters PARAMS.
2459 PARAMS is a list--a chain of TREE_LIST nodes--in which the
2460 TREE_VALUE of each node is a parameter-expression. The PARAMS do
2461 not include any object pointer that may be required. FUNCTION's
2462 data type may be a function type or a pointer-to-function.
2464 For C++: If FUNCTION's data type is a TREE_LIST, then the tree list
2465 is the list of possible methods that FUNCTION could conceivably
2466 be. If the list of methods comes from a class, then it will be
2467 a list of lists (where each element is associated with the class
2468 that produced it), otherwise it will be a simple list (for
2469 functions overloaded in global scope).
2471 In the first case, TREE_VALUE (function) is the head of one of those
2472 lists, and TREE_PURPOSE is the name of the function.
2474 In the second case, TREE_PURPOSE (function) is the function's
2477 DECL is the class instance variable, usually CURRENT_CLASS_REF.
2479 When calling a TEMPLATE_DECL, we don't require a complete return
2483 build_x_function_call (function
, params
, decl
)
2484 tree function
, params
, decl
;
2487 tree template_id
= NULL_TREE
;
2490 if (function
== error_mark_node
)
2491 return error_mark_node
;
2493 if (processing_template_decl
)
2494 return build_min_nt (CALL_EXPR
, function
, params
, NULL_TREE
);
2496 /* Save explicit template arguments if found */
2497 if (TREE_CODE (function
) == TEMPLATE_ID_EXPR
)
2499 template_id
= function
;
2500 function
= TREE_OPERAND (function
, 0);
2503 type
= TREE_TYPE (function
);
2505 if (TREE_CODE (type
) == OFFSET_TYPE
2506 && TREE_TYPE (type
) == unknown_type_node
2507 && TREE_CODE (function
) == TREE_LIST
2508 && TREE_CHAIN (function
) == NULL_TREE
)
2510 /* Undo (Foo:bar)()... */
2511 type
= TYPE_OFFSET_BASETYPE (type
);
2512 function
= TREE_VALUE (function
);
2513 my_friendly_assert (TREE_CODE (function
) == TREE_LIST
, 999);
2514 my_friendly_assert (TREE_CHAIN (function
) == NULL_TREE
, 999);
2515 function
= TREE_VALUE (function
);
2516 if (TREE_CODE (function
) == OVERLOAD
)
2517 function
= OVL_FUNCTION (function
);
2518 my_friendly_assert (TREE_CODE (function
) == FUNCTION_DECL
, 999);
2519 function
= DECL_NAME (function
);
2520 return build_method_call (decl
, function
, params
,
2521 TYPE_BINFO (type
), LOOKUP_NORMAL
);
2524 is_method
= ((TREE_CODE (function
) == TREE_LIST
2525 && current_class_type
!= NULL_TREE
2526 && (IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (function
))
2528 || TREE_CODE (function
) == IDENTIFIER_NODE
2529 || TREE_CODE (type
) == METHOD_TYPE
2530 || TYPE_PTRMEMFUNC_P (type
));
2532 if ((TREE_CODE (function
) == FUNCTION_DECL
2533 && DECL_STATIC_FUNCTION_P (function
))
2534 || (TREE_CODE (function
) == TEMPLATE_DECL
2535 && DECL_STATIC_FUNCTION_P (DECL_RESULT (function
))))
2536 return build_member_call
2537 (DECL_CONTEXT (function
), DECL_NAME (function
), params
);
2539 /* A friend template. Make it look like a toplevel declaration. */
2540 if (! is_method
&& TREE_CODE (function
) == TEMPLATE_DECL
)
2541 function
= scratch_ovl_cons (function
, NULL_TREE
);
2543 /* Handle methods, friends, and overloaded functions, respectively. */
2546 tree basetype
= NULL_TREE
;
2548 if (TREE_CODE (function
) == FUNCTION_DECL
2549 || DECL_FUNCTION_TEMPLATE_P (function
))
2551 basetype
= DECL_CLASS_CONTEXT (function
);
2553 if (DECL_NAME (function
))
2554 function
= DECL_NAME (function
);
2556 function
= TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function
));
2558 else if (TREE_CODE (function
) == TREE_LIST
)
2560 my_friendly_assert (TREE_CODE (TREE_VALUE (function
))
2561 == FUNCTION_DECL
, 312);
2562 basetype
= DECL_CLASS_CONTEXT (TREE_VALUE (function
));
2563 function
= TREE_PURPOSE (function
);
2565 else if (TREE_CODE (function
) != IDENTIFIER_NODE
)
2567 if (TREE_CODE (function
) == OFFSET_REF
)
2569 if (TREE_OPERAND (function
, 0))
2570 decl
= TREE_OPERAND (function
, 0);
2572 /* Call via a pointer to member function. */
2573 if (decl
== NULL_TREE
)
2575 error ("pointer to member function called, but not in class scope");
2576 return error_mark_node
;
2578 /* What other type of POINTER_TYPE could this be? */
2579 if (TREE_CODE (TREE_TYPE (function
)) != POINTER_TYPE
2580 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (function
))
2581 && TREE_CODE (function
) != OFFSET_REF
)
2582 function
= build (OFFSET_REF
, TREE_TYPE (type
), NULL_TREE
,
2587 /* this is an abbreviated method call.
2588 must go through here in case it is a virtual function.
2589 @@ Perhaps this could be optimized. */
2591 if (basetype
&& (! current_class_type
2592 || ! DERIVED_FROM_P (basetype
, current_class_type
)))
2593 return build_member_call (basetype
, function
, params
);
2595 if (decl
== NULL_TREE
)
2597 if (current_class_type
== NULL_TREE
)
2599 error ("object missing in call to method `%s'",
2600 IDENTIFIER_POINTER (function
));
2601 return error_mark_node
;
2603 /* Yow: call from a static member function. */
2604 decl
= build1 (NOP_EXPR
, build_pointer_type (current_class_type
),
2606 decl
= build_indirect_ref (decl
, NULL_PTR
);
2609 /* Put back explicit template arguments, if any. */
2611 function
= template_id
;
2612 return build_method_call (decl
, function
, params
,
2613 NULL_TREE
, LOOKUP_NORMAL
);
2615 else if (TREE_CODE (function
) == COMPONENT_REF
2616 && type
== unknown_type_node
)
2618 /* Should we undo what was done in build_component_ref? */
2619 if (TREE_CODE (TREE_PURPOSE (TREE_OPERAND (function
, 1))) == TREE_VEC
)
2620 /* Get the name that build_component_ref hid. */
2621 function
= DECL_NAME (TREE_VALUE (TREE_OPERAND (function
, 1)));
2623 function
= TREE_PURPOSE (TREE_OPERAND (function
, 1));
2624 return build_method_call (decl
, function
, params
,
2625 NULL_TREE
, LOOKUP_NORMAL
);
2627 else if (really_overloaded_fn (function
))
2629 if (OVL_FUNCTION (function
) == NULL_TREE
)
2631 cp_error ("function `%D' declared overloaded, but no definitions appear with which to resolve it?!?",
2632 TREE_PURPOSE (function
));
2633 return error_mark_node
;
2637 /* Put back explicit template arguments, if any. */
2639 function
= template_id
;
2640 return build_new_function_call (function
, params
);
2644 /* Remove a potential OVERLOAD around it */
2645 function
= OVL_CURRENT (function
);
2648 if (TREE_CODE (function
) == OFFSET_REF
)
2650 /* If the component is a data element (or a virtual function), we play
2651 games here to make things work. */
2654 if (TREE_OPERAND (function
, 0))
2655 decl
= TREE_OPERAND (function
, 0);
2657 decl
= current_class_ref
;
2659 decl_addr
= build_unary_op (ADDR_EXPR
, decl
, 0);
2661 /* Sigh. OFFSET_REFs are being used for too many things.
2662 They're being used both for -> and ->*, and we want to resolve
2663 the -> cases here, but leave the ->*. We could use
2664 resolve_offset_ref for those, too, but it would call
2665 get_member_function_from_ptrfunc and decl_addr wouldn't get
2666 updated properly. Nasty. */
2667 if (TREE_CODE (TREE_OPERAND (function
, 1)) == FIELD_DECL
)
2668 function
= resolve_offset_ref (function
);
2670 function
= TREE_OPERAND (function
, 1);
2672 function
= get_member_function_from_ptrfunc (&decl_addr
, function
);
2673 params
= expr_tree_cons (NULL_TREE
, decl_addr
, params
);
2674 return build_function_call (function
, params
);
2677 type
= TREE_TYPE (function
);
2678 if (type
!= error_mark_node
)
2680 if (TREE_CODE (type
) == REFERENCE_TYPE
)
2681 type
= TREE_TYPE (type
);
2683 if (IS_AGGR_TYPE (type
))
2684 return build_opfncall (CALL_EXPR
, LOOKUP_NORMAL
, function
, params
, NULL_TREE
);
2689 tree fntype
= TREE_TYPE (function
);
2690 tree ctypeptr
= NULL_TREE
;
2692 /* Explicitly named method? */
2693 if (TREE_CODE (function
) == FUNCTION_DECL
)
2694 ctypeptr
= build_pointer_type (DECL_CLASS_CONTEXT (function
));
2695 /* Expression with ptr-to-method type? It could either be a plain
2696 usage, or it might be a case where the ptr-to-method is being
2697 passed in as an argument. */
2698 else if (TYPE_PTRMEMFUNC_P (fntype
))
2700 tree rec
= TYPE_METHOD_BASETYPE (TREE_TYPE
2701 (TYPE_PTRMEMFUNC_FN_TYPE (fntype
)));
2702 ctypeptr
= build_pointer_type (rec
);
2704 /* Unexpected node type? */
2706 my_friendly_abort (116);
2707 if (decl
== NULL_TREE
)
2709 if (current_function_decl
2710 && DECL_STATIC_FUNCTION_P (current_function_decl
))
2711 error ("invalid call to member function needing `this' in static member function scope");
2713 error ("pointer to member function called, but not in class scope");
2714 return error_mark_node
;
2716 if (TREE_CODE (TREE_TYPE (decl
)) != POINTER_TYPE
2717 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (decl
)))
2719 decl
= build_unary_op (ADDR_EXPR
, decl
, 0);
2720 decl
= convert_pointer_to (TREE_TYPE (ctypeptr
), decl
);
2723 decl
= build_c_cast (ctypeptr
, decl
);
2724 params
= expr_tree_cons (NULL_TREE
, decl
, params
);
2727 return build_function_call (function
, params
);
2730 /* Resolve a pointer to member function. INSTANCE is the object
2731 instance to use, if the member points to a virtual member. */
2734 get_member_function_from_ptrfunc (instance_ptrptr
, function
)
2735 tree
*instance_ptrptr
;
2738 if (TREE_CODE (function
) == OFFSET_REF
)
2740 function
= TREE_OPERAND (function
, 1);
2743 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function
)))
2745 tree fntype
, idx
, e1
, delta
, delta2
, e2
, e3
, aref
, vtbl
;
2746 tree instance
, basetype
;
2748 tree instance_ptr
= *instance_ptrptr
;
2750 if (TREE_SIDE_EFFECTS (instance_ptr
))
2751 instance_ptr
= save_expr (instance_ptr
);
2753 if (TREE_SIDE_EFFECTS (function
))
2754 function
= save_expr (function
);
2756 fntype
= TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (function
));
2757 basetype
= TYPE_METHOD_BASETYPE (TREE_TYPE (fntype
));
2759 delta
= cp_convert (ptrdiff_type_node
,
2760 build_component_ref (function
, delta_identifier
,
2762 e3
= PFN_FROM_PTRMEMFUNC (function
);
2764 if (TYPE_SIZE (basetype
) != NULL_TREE
2765 && ! TYPE_VIRTUAL_P (basetype
))
2766 /* If basetype doesn't have virtual functions, don't emit code to
2767 handle that case. */
2771 /* Promoting idx before saving it improves performance on RISC
2772 targets. Without promoting, the first compare used
2773 load-with-sign-extend, while the second used normal load then
2774 shift to sign-extend. An optimizer flaw, perhaps, but it's
2775 easier to make this change. */
2776 idx
= save_expr (default_conversion
2777 (build_component_ref (function
,
2780 e1
= build_binary_op (GT_EXPR
, idx
, integer_zero_node
, 1);
2782 /* Convert down to the right base, before using the instance. */
2783 instance
= convert_pointer_to_real (basetype
, instance_ptr
);
2784 if (instance
== error_mark_node
&& instance_ptr
!= error_mark_node
)
2787 vtbl
= convert_pointer_to (ptr_type_node
, instance
);
2788 delta2
= DELTA2_FROM_PTRMEMFUNC (function
);
2791 build_pointer_type (build_pointer_type (vtable_entry_type
)),
2792 vtbl
, cp_convert (ptrdiff_type_node
, delta2
));
2793 vtbl
= build_indirect_ref (vtbl
, NULL_PTR
);
2794 aref
= build_array_ref (vtbl
, build_binary_op (MINUS_EXPR
,
2796 integer_one_node
, 1));
2797 if (! flag_vtable_thunks
)
2799 aref
= save_expr (aref
);
2801 delta
= build_binary_op
2803 build_conditional_expr (e1
,
2804 build_component_ref (aref
,
2811 if (flag_vtable_thunks
)
2814 e2
= build_component_ref (aref
, pfn_identifier
, NULL_TREE
, 0);
2815 TREE_TYPE (e2
) = TREE_TYPE (e3
);
2816 e1
= build_conditional_expr (e1
, e2
, e3
);
2818 /* Make sure this doesn't get evaluated first inside one of the
2819 branches of the COND_EXPR. */
2820 if (TREE_CODE (instance_ptr
) == SAVE_EXPR
)
2821 e1
= build (COMPOUND_EXPR
, TREE_TYPE (e1
),
2825 *instance_ptrptr
= build (PLUS_EXPR
, TREE_TYPE (instance_ptr
),
2826 instance_ptr
, delta
);
2828 if (instance_ptr
== error_mark_node
2829 && TREE_CODE (e1
) != ADDR_EXPR
2830 && TREE_CODE (TREE_OPERAND (e1
, 0)) != FUNCTION_DECL
)
2831 cp_error ("object missing in `%E'", function
);
2839 build_function_call_real (function
, params
, require_complete
, flags
)
2840 tree function
, params
;
2841 int require_complete
, flags
;
2843 register tree fntype
, fndecl
;
2844 register tree value_type
;
2845 register tree coerced_params
;
2846 tree name
= NULL_TREE
, assembler_name
= NULL_TREE
;
2849 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
2850 Strip such NOP_EXPRs, since FUNCTION is used in non-lvalue context. */
2851 if (TREE_CODE (function
) == NOP_EXPR
2852 && TREE_TYPE (function
) == TREE_TYPE (TREE_OPERAND (function
, 0)))
2853 function
= TREE_OPERAND (function
, 0);
2855 if (TREE_CODE (function
) == FUNCTION_DECL
)
2857 name
= DECL_NAME (function
);
2858 assembler_name
= DECL_ASSEMBLER_NAME (function
);
2860 GNU_xref_call (current_function_decl
,
2861 IDENTIFIER_POINTER (name
? name
2862 : TYPE_IDENTIFIER (DECL_CLASS_CONTEXT
2864 mark_used (function
);
2867 /* Convert anything with function type to a pointer-to-function. */
2868 if (pedantic
&& DECL_MAIN_P (function
))
2869 pedwarn ("ANSI C++ forbids calling `main' from within program");
2871 /* Differs from default_conversion by not setting TREE_ADDRESSABLE
2872 (because calling an inline function does not mean the function
2873 needs to be separately compiled). */
2875 if (DECL_INLINE (function
))
2876 function
= inline_conversion (function
);
2878 function
= build_addr_func (function
);
2884 function
= build_addr_func (function
);
2887 if (function
== error_mark_node
)
2888 return error_mark_node
;
2890 fntype
= TREE_TYPE (function
);
2892 if (TYPE_PTRMEMFUNC_P (fntype
))
2894 cp_error ("must use .* or ->* to call pointer-to-member function in `%E (...)'",
2896 return error_mark_node
;
2899 is_method
= (TREE_CODE (fntype
) == POINTER_TYPE
2900 && TREE_CODE (TREE_TYPE (fntype
)) == METHOD_TYPE
);
2902 if (!((TREE_CODE (fntype
) == POINTER_TYPE
2903 && TREE_CODE (TREE_TYPE (fntype
)) == FUNCTION_TYPE
)
2905 || TREE_CODE (function
) == TEMPLATE_ID_EXPR
))
2907 cp_error ("`%E' cannot be used as a function", function
);
2908 return error_mark_node
;
2911 /* fntype now gets the type of function pointed to. */
2912 fntype
= TREE_TYPE (fntype
);
2914 /* Convert the parameters to the types declared in the
2915 function prototype, or apply default promotions. */
2917 if (flags
& LOOKUP_COMPLAIN
)
2918 coerced_params
= convert_arguments (TYPE_ARG_TYPES (fntype
),
2919 params
, fndecl
, LOOKUP_NORMAL
);
2921 coerced_params
= convert_arguments (TYPE_ARG_TYPES (fntype
),
2924 if (coerced_params
== error_mark_node
)
2926 if (flags
& LOOKUP_SPECULATIVELY
)
2929 return error_mark_node
;
2932 /* Check for errors in format strings. */
2934 if (warn_format
&& (name
|| assembler_name
))
2935 check_function_format (name
, assembler_name
, coerced_params
);
2937 /* Recognize certain built-in functions so we can make tree-codes
2938 other than CALL_EXPR. We do this when it enables fold-const.c
2939 to do something useful. */
2941 if (TREE_CODE (function
) == ADDR_EXPR
2942 && TREE_CODE (TREE_OPERAND (function
, 0)) == FUNCTION_DECL
2943 && DECL_BUILT_IN (TREE_OPERAND (function
, 0)))
2944 switch (DECL_FUNCTION_CODE (TREE_OPERAND (function
, 0)))
2949 if (coerced_params
== 0)
2950 return integer_zero_node
;
2951 return build_unary_op (ABS_EXPR
, TREE_VALUE (coerced_params
), 0);
2958 value_type
= TREE_TYPE (fntype
) ? TREE_TYPE (fntype
) : void_type_node
;
2960 register tree result
2961 = build_call (function
, value_type
, coerced_params
);
2963 if (require_complete
)
2965 if (value_type
== void_type_node
)
2967 result
= require_complete_type (result
);
2969 if (IS_AGGR_TYPE (value_type
))
2970 result
= build_cplus_new (value_type
, result
);
2971 return convert_from_reference (result
);
2976 build_function_call (function
, params
)
2977 tree function
, params
;
2979 return build_function_call_real (function
, params
, 1, LOOKUP_NORMAL
);
2982 /* Convert the actual parameter expressions in the list VALUES
2983 to the types in the list TYPELIST.
2984 If parmdecls is exhausted, or when an element has NULL as its type,
2985 perform the default conversions.
2987 NAME is an IDENTIFIER_NODE or 0. It is used only for error messages.
2989 This is also where warnings about wrong number of args are generated.
2991 Return a list of expressions for the parameters as converted.
2993 Both VALUES and the returned value are chains of TREE_LIST nodes
2994 with the elements of the list in the TREE_VALUE slots of those nodes.
2996 In C++, unspecified trailing parameters can be filled in with their
2997 default arguments, if such were specified. Do so here. */
3000 convert_arguments (typelist
, values
, fndecl
, flags
)
3001 tree typelist
, values
, fndecl
;
3004 register tree typetail
, valtail
;
3005 register tree result
= NULL_TREE
;
3006 char *called_thing
= 0;
3009 /* Argument passing is always copy-initialization. */
3010 flags
|= LOOKUP_ONLYCONVERTING
;
3014 if (TREE_CODE (TREE_TYPE (fndecl
)) == METHOD_TYPE
)
3016 if (DECL_NAME (fndecl
) == NULL_TREE
3017 || IDENTIFIER_HAS_TYPE_VALUE (DECL_NAME (fndecl
)))
3018 called_thing
= "constructor";
3020 called_thing
= "member function";
3023 called_thing
= "function";
3026 for (valtail
= values
, typetail
= typelist
;
3028 valtail
= TREE_CHAIN (valtail
), i
++)
3030 register tree type
= typetail
? TREE_VALUE (typetail
) : 0;
3031 register tree val
= TREE_VALUE (valtail
);
3033 if (val
== error_mark_node
)
3034 return error_mark_node
;
3036 if (type
== void_type_node
)
3040 cp_error_at ("too many arguments to %s `%+D'", called_thing
,
3042 error ("at this point in file");
3045 error ("too many arguments to function");
3046 /* In case anybody wants to know if this argument
3049 TREE_TYPE (tree_last (result
)) = error_mark_node
;
3053 /* The tree type of the parameter being passed may not yet be
3054 known. In this case, its type is TYPE_UNKNOWN, and will
3055 be instantiated by the type given by TYPE. If TYPE
3056 is also NULL, the tree type of VAL is ERROR_MARK_NODE. */
3057 if (type
&& type_unknown_p (val
))
3058 val
= require_instantiated_type (type
, val
, integer_zero_node
);
3059 else if (type_unknown_p (val
))
3061 /* Strip the `&' from an overloaded FUNCTION_DECL. */
3062 if (TREE_CODE (val
) == ADDR_EXPR
)
3063 val
= TREE_OPERAND (val
, 0);
3064 if (really_overloaded_fn (val
))
3065 cp_error ("insufficient type information to resolve address of overloaded function `%D'",
3066 DECL_NAME (get_first_fn (val
)));
3068 error ("insufficient type information in parameter list");
3069 val
= integer_zero_node
;
3071 else if (TREE_CODE (val
) == OFFSET_REF
3072 && TREE_CODE (TREE_TYPE (val
)) == METHOD_TYPE
)
3074 /* This is unclean. Should be handled elsewhere. */
3075 val
= build_unary_op (ADDR_EXPR
, val
, 0);
3077 else if (TREE_CODE (val
) == OFFSET_REF
)
3078 val
= resolve_offset_ref (val
);
3080 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
3081 Strip such NOP_EXPRs, since VAL is used in non-lvalue context. */
3082 if (TREE_CODE (val
) == NOP_EXPR
3083 && TREE_TYPE (val
) == TREE_TYPE (TREE_OPERAND (val
, 0))
3084 && (type
== 0 || TREE_CODE (type
) != REFERENCE_TYPE
))
3085 val
= TREE_OPERAND (val
, 0);
3087 if (type
== 0 || TREE_CODE (type
) != REFERENCE_TYPE
)
3089 if (TREE_CODE (TREE_TYPE (val
)) == ARRAY_TYPE
3090 || TREE_CODE (TREE_TYPE (val
)) == FUNCTION_TYPE
3091 || TREE_CODE (TREE_TYPE (val
)) == METHOD_TYPE
)
3092 val
= default_conversion (val
);
3094 val
= require_complete_type (val
);
3097 if (val
== error_mark_node
)
3098 return error_mark_node
;
3102 /* Formal parm type is specified by a function prototype. */
3105 if (TYPE_SIZE (complete_type (type
)) == 0)
3107 error ("parameter type of called function is incomplete");
3112 parmval
= convert_for_initialization
3113 (NULL_TREE
, type
, val
, flags
,
3114 "argument passing", fndecl
, i
);
3115 #ifdef PROMOTE_PROTOTYPES
3116 if ((TREE_CODE (type
) == INTEGER_TYPE
3117 || TREE_CODE (type
) == ENUMERAL_TYPE
)
3118 && (TYPE_PRECISION (type
)
3119 < TYPE_PRECISION (integer_type_node
)))
3120 parmval
= default_conversion (parmval
);
3124 if (parmval
== error_mark_node
)
3125 return error_mark_node
;
3127 result
= expr_tree_cons (NULL_TREE
, parmval
, result
);
3131 if (TREE_CODE (TREE_TYPE (val
)) == REFERENCE_TYPE
)
3132 val
= convert_from_reference (val
);
3134 result
= expr_tree_cons (NULL_TREE
,
3135 convert_arg_to_ellipsis (val
),
3140 typetail
= TREE_CHAIN (typetail
);
3143 if (typetail
!= 0 && typetail
!= void_list_node
)
3145 /* See if there are default arguments that can be used */
3146 if (TREE_PURPOSE (typetail
))
3148 for (; typetail
!= void_list_node
; ++i
)
3150 tree type
= TREE_VALUE (typetail
);
3151 tree val
= TREE_PURPOSE (typetail
);
3152 tree parmval
= convert_default_arg (type
, val
);
3154 if (parmval
== error_mark_node
)
3155 return error_mark_node
;
3157 result
= expr_tree_cons (0, parmval
, result
);
3158 typetail
= TREE_CHAIN (typetail
);
3159 /* ends with `...'. */
3160 if (typetail
== NULL_TREE
)
3168 char *buf
= (char *)alloca (32 + strlen (called_thing
));
3169 sprintf (buf
, "too few arguments to %s `%%#D'", called_thing
);
3170 cp_error_at (buf
, fndecl
);
3171 error ("at this point in file");
3174 error ("too few arguments to function");
3175 return error_mark_list
;
3179 return nreverse (result
);
3182 /* Build a binary-operation expression, after performing default
3183 conversions on the operands. CODE is the kind of expression to build. */
3186 build_x_binary_op (code
, arg1
, arg2
)
3187 enum tree_code code
;
3190 if (processing_template_decl
)
3191 return build_min_nt (code
, arg1
, arg2
);
3193 return build_new_op (code
, LOOKUP_NORMAL
, arg1
, arg2
, NULL_TREE
);
3197 build_binary_op (code
, arg1
, arg2
, convert_p
)
3198 enum tree_code code
;
3210 args
[0] = decay_conversion (args
[0]);
3211 args
[1] = decay_conversion (args
[1]);
3213 if (args
[0] == error_mark_node
|| args
[1] == error_mark_node
)
3214 return error_mark_node
;
3216 type0
= TREE_TYPE (args
[0]);
3217 type1
= TREE_TYPE (args
[1]);
3219 if (type_unknown_p (args
[0]))
3221 args
[0] = instantiate_type (type1
, args
[0], 1);
3222 args
[0] = decay_conversion (args
[0]);
3224 else if (type_unknown_p (args
[1]))
3226 args
[1] = require_instantiated_type (type0
, args
[1],
3228 args
[1] = decay_conversion (args
[1]);
3231 if (IS_AGGR_TYPE (type0
) || IS_AGGR_TYPE (type1
))
3232 my_friendly_abort (754867);
3234 return build_binary_op_nodefault (code
, args
[0], args
[1], code
);
3237 /* Build a binary-operation expression without default conversions.
3238 CODE is the kind of expression to build.
3239 This function differs from `build' in several ways:
3240 the data type of the result is computed and recorded in it,
3241 warnings are generated if arg data types are invalid,
3242 special handling for addition and subtraction of pointers is known,
3243 and some optimization is done (operations on narrow ints
3244 are done in the narrower type when that gives the same result).
3245 Constant folding is also done before the result is returned.
3247 ERROR_CODE is the code that determines what to say in error messages.
3248 It is usually, but not always, the same as CODE.
3250 Note that the operands will never have enumeral types
3251 because either they have just had the default conversions performed
3252 or they have both just been converted to some other type in which
3253 the arithmetic is to be done.
3255 C++: must do special pointer arithmetic when implementing
3256 multiple inheritance, and deal with pointer to member functions. */
3259 build_binary_op_nodefault (code
, orig_op0
, orig_op1
, error_code
)
3260 enum tree_code code
;
3261 tree orig_op0
, orig_op1
;
3262 enum tree_code error_code
;
3265 register enum tree_code code0
, code1
;
3268 /* Expression code to give to the expression when it is built.
3269 Normally this is CODE, which is what the caller asked for,
3270 but in some special cases we change it. */
3271 register enum tree_code resultcode
= code
;
3273 /* Data type in which the computation is to be performed.
3274 In the simplest cases this is the common type of the arguments. */
3275 register tree result_type
= NULL
;
3277 /* Nonzero means operands have already been type-converted
3278 in whatever way is necessary.
3279 Zero means they need to be converted to RESULT_TYPE. */
3282 /* Nonzero means create the expression with this type, rather than
3284 tree build_type
= 0;
3286 /* Nonzero means after finally constructing the expression
3287 convert it to this type. */
3288 tree final_type
= 0;
3290 /* Nonzero if this is an operation like MIN or MAX which can
3291 safely be computed in short if both args are promoted shorts.
3292 Also implies COMMON.
3293 -1 indicates a bitwise operation; this makes a difference
3294 in the exact conditions for when it is safe to do the operation
3295 in a narrower mode. */
3298 /* Nonzero if this is a comparison operation;
3299 if both args are promoted shorts, compare the original shorts.
3300 Also implies COMMON. */
3301 int short_compare
= 0;
3303 /* Nonzero if this is a right-shift operation, which can be computed on the
3304 original short and then promoted if the operand is a promoted short. */
3305 int short_shift
= 0;
3307 /* Nonzero means set RESULT_TYPE to the common type of the args. */
3310 /* Apply default conversions. */
3311 if (code
== TRUTH_AND_EXPR
|| code
== TRUTH_ANDIF_EXPR
3312 || code
== TRUTH_OR_EXPR
|| code
== TRUTH_ORIF_EXPR
3313 || code
== TRUTH_XOR_EXPR
)
3315 op0
= decay_conversion (orig_op0
);
3316 op1
= decay_conversion (orig_op1
);
3320 op0
= default_conversion (orig_op0
);
3321 op1
= default_conversion (orig_op1
);
3324 type0
= TREE_TYPE (op0
);
3325 type1
= TREE_TYPE (op1
);
3327 /* The expression codes of the data types of the arguments tell us
3328 whether the arguments are integers, floating, pointers, etc. */
3329 code0
= TREE_CODE (type0
);
3330 code1
= TREE_CODE (type1
);
3332 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
3333 STRIP_TYPE_NOPS (op0
);
3334 STRIP_TYPE_NOPS (op1
);
3336 /* If an error was already reported for one of the arguments,
3337 avoid reporting another error. */
3339 if (code0
== ERROR_MARK
|| code1
== ERROR_MARK
)
3340 return error_mark_node
;
3345 /* Handle the pointer + int case. */
3346 if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3347 return pointer_int_sum (PLUS_EXPR
, op0
, op1
);
3348 else if (code1
== POINTER_TYPE
&& code0
== INTEGER_TYPE
)
3349 return pointer_int_sum (PLUS_EXPR
, op1
, op0
);
3355 /* Subtraction of two similar pointers.
3356 We must subtract them as integers, then divide by object size. */
3357 if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
3358 && comp_target_types (type0
, type1
, 1))
3359 return pointer_diff (op0
, op1
, common_type (type0
, type1
));
3360 /* Handle pointer minus int. Just like pointer plus int. */
3361 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3362 return pointer_int_sum (MINUS_EXPR
, op0
, op1
);
3371 case TRUNC_DIV_EXPR
:
3373 case FLOOR_DIV_EXPR
:
3374 case ROUND_DIV_EXPR
:
3375 case EXACT_DIV_EXPR
:
3376 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
3377 || code0
== COMPLEX_TYPE
)
3378 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
3379 || code1
== COMPLEX_TYPE
))
3381 if (TREE_CODE (op1
) == INTEGER_CST
&& integer_zerop (op1
))
3382 cp_warning ("division by zero in `%E / 0'", op0
);
3383 else if (TREE_CODE (op1
) == REAL_CST
&& real_zerop (op1
))
3384 cp_warning ("division by zero in `%E / 0.'", op0
);
3386 if (!(code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
))
3387 resultcode
= RDIV_EXPR
;
3389 /* When dividing two signed integers, we have to promote to int.
3390 unless we divide by a constant != -1. Note that default
3391 conversion will have been performed on the operands at this
3392 point, so we have to dig out the original type to find out if
3394 shorten
= ((TREE_CODE (op0
) == NOP_EXPR
3395 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3396 || (TREE_CODE (op1
) == INTEGER_CST
3397 && (TREE_INT_CST_LOW (op1
) != -1
3398 || TREE_INT_CST_HIGH (op1
) != -1)));
3404 case BIT_ANDTC_EXPR
:
3407 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3409 /* If one operand is a constant, and the other is a short type
3410 that has been converted to an int,
3411 really do the work in the short type and then convert the
3412 result to int. If we are lucky, the constant will be 0 or 1
3413 in the short type, making the entire operation go away. */
3414 if (TREE_CODE (op0
) == INTEGER_CST
3415 && TREE_CODE (op1
) == NOP_EXPR
3416 && (TYPE_PRECISION (type1
)
3417 > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1
, 0))))
3418 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1
, 0))))
3420 final_type
= result_type
;
3421 op1
= TREE_OPERAND (op1
, 0);
3422 result_type
= TREE_TYPE (op1
);
3424 if (TREE_CODE (op1
) == INTEGER_CST
3425 && TREE_CODE (op0
) == NOP_EXPR
3426 && (TYPE_PRECISION (type0
)
3427 > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3428 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3430 final_type
= result_type
;
3431 op0
= TREE_OPERAND (op0
, 0);
3432 result_type
= TREE_TYPE (op0
);
3436 case TRUNC_MOD_EXPR
:
3437 case FLOOR_MOD_EXPR
:
3438 if (code1
== INTEGER_TYPE
&& integer_zerop (op1
))
3439 cp_warning ("division by zero in `%E %% 0'", op0
);
3440 else if (code1
== REAL_TYPE
&& real_zerop (op1
))
3441 cp_warning ("division by zero in `%E %% 0.'", op0
);
3443 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3445 /* Although it would be tempting to shorten always here, that loses
3446 on some targets, since the modulo instruction is undefined if the
3447 quotient can't be represented in the computation mode. We shorten
3448 only if unsigned or if dividing by something we know != -1. */
3449 shorten
= ((TREE_CODE (op0
) == NOP_EXPR
3450 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3451 || (TREE_CODE (op1
) == INTEGER_CST
3452 && (TREE_INT_CST_LOW (op1
) != -1
3453 || TREE_INT_CST_HIGH (op1
) != -1)));
3458 case TRUTH_ANDIF_EXPR
:
3459 case TRUTH_ORIF_EXPR
:
3460 case TRUTH_AND_EXPR
:
3462 result_type
= boolean_type_node
;
3465 /* Shift operations: result has same type as first operand;
3466 always convert second operand to int.
3467 Also set SHORT_SHIFT if shifting rightward. */
3470 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3472 result_type
= type0
;
3473 if (TREE_CODE (op1
) == INTEGER_CST
)
3475 if (tree_int_cst_lt (op1
, integer_zero_node
))
3476 warning ("right shift count is negative");
3479 if (TREE_INT_CST_LOW (op1
) | TREE_INT_CST_HIGH (op1
))
3481 if (TREE_INT_CST_HIGH (op1
) != 0
3482 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3483 >= TYPE_PRECISION (type0
)))
3484 warning ("right shift count >= width of type");
3487 /* Convert the shift-count to an integer, regardless of
3488 size of value being shifted. */
3489 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3490 op1
= cp_convert (integer_type_node
, op1
);
3491 /* Avoid converting op1 to result_type later. */
3497 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3499 result_type
= type0
;
3500 if (TREE_CODE (op1
) == INTEGER_CST
)
3502 if (tree_int_cst_lt (op1
, integer_zero_node
))
3503 warning ("left shift count is negative");
3504 else if (TREE_INT_CST_HIGH (op1
) != 0
3505 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3506 >= TYPE_PRECISION (type0
)))
3507 warning ("left shift count >= width of type");
3509 /* Convert the shift-count to an integer, regardless of
3510 size of value being shifted. */
3511 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3512 op1
= cp_convert (integer_type_node
, op1
);
3513 /* Avoid converting op1 to result_type later. */
3520 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3522 result_type
= type0
;
3523 if (TREE_CODE (op1
) == INTEGER_CST
)
3525 if (tree_int_cst_lt (op1
, integer_zero_node
))
3526 warning ("%s rotate count is negative",
3527 (code
== LROTATE_EXPR
) ? "left" : "right");
3528 else if (TREE_INT_CST_HIGH (op1
) != 0
3529 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3530 >= TYPE_PRECISION (type0
)))
3531 warning ("%s rotate count >= width of type",
3532 (code
== LROTATE_EXPR
) ? "left" : "right");
3534 /* Convert the shift-count to an integer, regardless of
3535 size of value being shifted. */
3536 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3537 op1
= cp_convert (integer_type_node
, op1
);
3543 build_type
= boolean_type_node
;
3544 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
3545 || code0
== COMPLEX_TYPE
)
3546 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
3547 || code1
== COMPLEX_TYPE
))
3549 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3551 register tree tt0
= TYPE_MAIN_VARIANT (TREE_TYPE (type0
));
3552 register tree tt1
= TYPE_MAIN_VARIANT (TREE_TYPE (type1
));
3554 if (comp_target_types (type0
, type1
, 1))
3555 result_type
= common_type (type0
, type1
);
3556 else if (tt0
== void_type_node
)
3558 if (pedantic
&& TREE_CODE (tt1
) == FUNCTION_TYPE
3559 && tree_int_cst_lt (TYPE_SIZE (type0
), TYPE_SIZE (type1
)))
3560 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3561 else if (TREE_CODE (tt1
) == OFFSET_TYPE
)
3562 pedwarn ("ANSI C++ forbids conversion of a pointer to member to `void *'");
3564 else if (tt1
== void_type_node
)
3566 if (pedantic
&& TREE_CODE (tt0
) == FUNCTION_TYPE
3567 && tree_int_cst_lt (TYPE_SIZE (type1
), TYPE_SIZE (type0
)))
3568 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3571 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3574 if (result_type
== NULL_TREE
)
3575 result_type
= ptr_type_node
;
3577 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
3578 && integer_zerop (op1
))
3579 result_type
= type0
;
3580 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
3581 && integer_zerop (op0
))
3582 result_type
= type1
;
3583 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3585 result_type
= type0
;
3586 error ("ANSI C++ forbids comparison between pointer and integer");
3588 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
3590 result_type
= type1
;
3591 error ("ANSI C++ forbids comparison between pointer and integer");
3593 else if (TYPE_PTRMEMFUNC_P (type0
) && TREE_CODE (op1
) == INTEGER_CST
3594 && integer_zerop (op1
))
3596 op0
= build_component_ref (op0
, index_identifier
, NULL_TREE
, 0);
3597 op1
= integer_zero_node
;
3598 result_type
= TREE_TYPE (op0
);
3600 else if (TYPE_PTRMEMFUNC_P (type1
) && TREE_CODE (op0
) == INTEGER_CST
3601 && integer_zerop (op0
))
3603 op0
= build_component_ref (op1
, index_identifier
, NULL_TREE
, 0);
3604 op1
= integer_zero_node
;
3605 result_type
= TREE_TYPE (op0
);
3607 else if (TYPE_PTRMEMFUNC_P (type0
) && TYPE_PTRMEMFUNC_P (type1
)
3608 && (TYPE_PTRMEMFUNC_FN_TYPE (type0
)
3609 == TYPE_PTRMEMFUNC_FN_TYPE (type1
)))
3611 /* The code we generate for the test is:
3613 (op0.index == op1.index
3614 && ((op1.index != -1 && op0.delta2 == op1.delta2)
3615 || op0.pfn == op1.pfn)) */
3617 tree index0
= build_component_ref (op0
, index_identifier
,
3619 tree index1
= save_expr (build_component_ref (op1
, index_identifier
,
3621 tree pfn0
= PFN_FROM_PTRMEMFUNC (op0
);
3622 tree pfn1
= PFN_FROM_PTRMEMFUNC (op1
);
3623 tree delta20
= DELTA2_FROM_PTRMEMFUNC (op0
);
3624 tree delta21
= DELTA2_FROM_PTRMEMFUNC (op1
);
3626 tree integer_neg_one_node
3627 = build_binary_op (MINUS_EXPR
, integer_zero_node
,
3628 integer_one_node
, 1);
3629 e1
= build_binary_op (EQ_EXPR
, index0
, index1
, 1);
3630 e2
= build_binary_op (NE_EXPR
, index1
, integer_neg_one_node
, 1);
3631 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e2
,
3632 build_binary_op (EQ_EXPR
, delta20
, delta21
, 1),
3634 e3
= build_binary_op (EQ_EXPR
, pfn0
, pfn1
, 1);
3635 e2
= build_binary_op (TRUTH_ORIF_EXPR
, e2
, e3
, 1);
3636 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e1
, e2
, 1);
3637 if (code
== EQ_EXPR
)
3639 return build_binary_op (EQ_EXPR
, e2
, integer_zero_node
, 1);
3641 else if (TYPE_PTRMEMFUNC_P (type0
)
3642 && TYPE_PTRMEMFUNC_FN_TYPE (type0
) == type1
)
3644 tree index0
= build_component_ref (op0
, index_identifier
,
3647 tree pfn0
= PFN_FROM_PTRMEMFUNC (op0
);
3648 tree delta20
= DELTA2_FROM_PTRMEMFUNC (op0
);
3649 tree delta21
= integer_zero_node
;
3651 tree integer_neg_one_node
3652 = build_binary_op (MINUS_EXPR
, integer_zero_node
, integer_one_node
, 1);
3653 if (TREE_CODE (TREE_OPERAND (op1
, 0)) == FUNCTION_DECL
3654 && DECL_VINDEX (TREE_OPERAND (op1
, 0)))
3656 /* Map everything down one to make room for
3657 the null pointer to member. */
3658 index1
= size_binop (PLUS_EXPR
,
3659 DECL_VINDEX (TREE_OPERAND (op1
, 0)),
3661 op1
= integer_zero_node
;
3662 delta21
= CLASSTYPE_VFIELD (TYPE_METHOD_BASETYPE
3663 (TREE_TYPE (type1
)));
3664 delta21
= DECL_FIELD_BITPOS (delta21
);
3665 delta21
= size_binop (FLOOR_DIV_EXPR
, delta21
,
3666 size_int (BITS_PER_UNIT
));
3667 delta21
= convert (sizetype
, delta21
);
3670 index1
= integer_neg_one_node
;
3672 tree nop1
= build1 (NOP_EXPR
, TYPE_PTRMEMFUNC_FN_TYPE (type0
),
3674 TREE_CONSTANT (nop1
) = TREE_CONSTANT (op1
);
3677 e1
= build_binary_op (EQ_EXPR
, index0
, index1
, 1);
3678 e2
= build_binary_op (NE_EXPR
, index1
, integer_neg_one_node
, 1);
3679 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e2
,
3680 build_binary_op (EQ_EXPR
, delta20
, delta21
, 1),
3682 e3
= build_binary_op (EQ_EXPR
, pfn0
, op1
, 1);
3683 e2
= build_binary_op (TRUTH_ORIF_EXPR
, e2
, e3
, 1);
3684 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e1
, e2
, 1);
3685 if (code
== EQ_EXPR
)
3687 return build_binary_op (EQ_EXPR
, e2
, integer_zero_node
, 1);
3689 else if (TYPE_PTRMEMFUNC_P (type1
)
3690 && TYPE_PTRMEMFUNC_FN_TYPE (type1
) == type0
)
3692 return build_binary_op (code
, op1
, op0
, 1);
3698 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3699 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3701 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3703 if (comp_target_types (type0
, type1
, 1))
3704 result_type
= common_type (type0
, type1
);
3707 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3709 result_type
= ptr_type_node
;
3718 build_type
= boolean_type_node
;
3719 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3720 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3722 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3724 if (comp_target_types (type0
, type1
, 1))
3725 result_type
= common_type (type0
, type1
);
3728 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3730 result_type
= ptr_type_node
;
3733 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
3734 && integer_zerop (op1
))
3735 result_type
= type0
;
3736 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
3737 && integer_zerop (op0
))
3738 result_type
= type1
;
3739 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3741 result_type
= type0
;
3742 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3744 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
3746 result_type
= type1
;
3747 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3755 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
|| code0
== COMPLEX_TYPE
)
3757 (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
|| code1
== COMPLEX_TYPE
))
3759 int none_complex
= (code0
!= COMPLEX_TYPE
&& code1
!= COMPLEX_TYPE
);
3761 if (shorten
|| common
|| short_compare
)
3762 result_type
= common_type (type0
, type1
);
3764 /* For certain operations (which identify themselves by shorten != 0)
3765 if both args were extended from the same smaller type,
3766 do the arithmetic in that type and then extend.
3768 shorten !=0 and !=1 indicates a bitwise operation.
3769 For them, this optimization is safe only if
3770 both args are zero-extended or both are sign-extended.
3771 Otherwise, we might change the result.
3772 Eg, (short)-1 | (unsigned short)-1 is (int)-1
3773 but calculated in (unsigned short) it would be (unsigned short)-1. */
3775 if (shorten
&& none_complex
)
3777 int unsigned0
, unsigned1
;
3778 tree arg0
= get_narrower (op0
, &unsigned0
);
3779 tree arg1
= get_narrower (op1
, &unsigned1
);
3780 /* UNS is 1 if the operation to be done is an unsigned one. */
3781 int uns
= TREE_UNSIGNED (result_type
);
3784 final_type
= result_type
;
3786 /* Handle the case that OP0 does not *contain* a conversion
3787 but it *requires* conversion to FINAL_TYPE. */
3789 if (op0
== arg0
&& TREE_TYPE (op0
) != final_type
)
3790 unsigned0
= TREE_UNSIGNED (TREE_TYPE (op0
));
3791 if (op1
== arg1
&& TREE_TYPE (op1
) != final_type
)
3792 unsigned1
= TREE_UNSIGNED (TREE_TYPE (op1
));
3794 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
3796 /* For bitwise operations, signedness of nominal type
3797 does not matter. Consider only how operands were extended. */
3801 /* Note that in all three cases below we refrain from optimizing
3802 an unsigned operation on sign-extended args.
3803 That would not be valid. */
3805 /* Both args variable: if both extended in same way
3806 from same width, do it in that width.
3807 Do it unsigned if args were zero-extended. */
3808 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
3809 < TYPE_PRECISION (result_type
))
3810 && (TYPE_PRECISION (TREE_TYPE (arg1
))
3811 == TYPE_PRECISION (TREE_TYPE (arg0
)))
3812 && unsigned0
== unsigned1
3813 && (unsigned0
|| !uns
))
3815 = signed_or_unsigned_type (unsigned0
,
3816 common_type (TREE_TYPE (arg0
),
3818 else if (TREE_CODE (arg0
) == INTEGER_CST
3819 && (unsigned1
|| !uns
)
3820 && (TYPE_PRECISION (TREE_TYPE (arg1
))
3821 < TYPE_PRECISION (result_type
))
3822 && (type
= signed_or_unsigned_type (unsigned1
,
3824 int_fits_type_p (arg0
, type
)))
3826 else if (TREE_CODE (arg1
) == INTEGER_CST
3827 && (unsigned0
|| !uns
)
3828 && (TYPE_PRECISION (TREE_TYPE (arg0
))
3829 < TYPE_PRECISION (result_type
))
3830 && (type
= signed_or_unsigned_type (unsigned0
,
3832 int_fits_type_p (arg1
, type
)))
3836 /* Shifts can be shortened if shifting right. */
3841 tree arg0
= get_narrower (op0
, &unsigned_arg
);
3843 final_type
= result_type
;
3845 if (arg0
== op0
&& final_type
== TREE_TYPE (op0
))
3846 unsigned_arg
= TREE_UNSIGNED (TREE_TYPE (op0
));
3848 if (TYPE_PRECISION (TREE_TYPE (arg0
)) < TYPE_PRECISION (result_type
)
3849 /* We can shorten only if the shift count is less than the
3850 number of bits in the smaller type size. */
3851 && TREE_INT_CST_HIGH (op1
) == 0
3852 && TYPE_PRECISION (TREE_TYPE (arg0
)) > TREE_INT_CST_LOW (op1
)
3853 /* If arg is sign-extended and then unsigned-shifted,
3854 we can simulate this with a signed shift in arg's type
3855 only if the extended result is at least twice as wide
3856 as the arg. Otherwise, the shift could use up all the
3857 ones made by sign-extension and bring in zeros.
3858 We can't optimize that case at all, but in most machines
3859 it never happens because available widths are 2**N. */
3860 && (!TREE_UNSIGNED (final_type
)
3862 || (((unsigned) 2 * TYPE_PRECISION (TREE_TYPE (arg0
)))
3863 <= TYPE_PRECISION (result_type
))))
3865 /* Do an unsigned shift if the operand was zero-extended. */
3867 = signed_or_unsigned_type (unsigned_arg
,
3869 /* Convert value-to-be-shifted to that type. */
3870 if (TREE_TYPE (op0
) != result_type
)
3871 op0
= cp_convert (result_type
, op0
);
3876 /* Comparison operations are shortened too but differently.
3877 They identify themselves by setting short_compare = 1. */
3881 /* Don't write &op0, etc., because that would prevent op0
3882 from being kept in a register.
3883 Instead, make copies of the our local variables and
3884 pass the copies by reference, then copy them back afterward. */
3885 tree xop0
= op0
, xop1
= op1
, xresult_type
= result_type
;
3886 enum tree_code xresultcode
= resultcode
;
3888 = shorten_compare (&xop0
, &xop1
, &xresult_type
, &xresultcode
);
3890 return cp_convert (boolean_type_node
, val
);
3891 op0
= xop0
, op1
= xop1
;
3893 resultcode
= xresultcode
;
3896 if (short_compare
&& warn_sign_compare
)
3898 int op0_signed
= ! TREE_UNSIGNED (TREE_TYPE (orig_op0
));
3899 int op1_signed
= ! TREE_UNSIGNED (TREE_TYPE (orig_op1
));
3901 int unsignedp0
, unsignedp1
;
3902 tree primop0
= get_narrower (op0
, &unsignedp0
);
3903 tree primop1
= get_narrower (op1
, &unsignedp1
);
3905 /* Check for comparison of different enum types. */
3906 if (TREE_CODE (TREE_TYPE (orig_op0
)) == ENUMERAL_TYPE
3907 && TREE_CODE (TREE_TYPE (orig_op1
)) == ENUMERAL_TYPE
3908 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0
))
3909 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1
)))
3911 cp_warning ("comparison between `%#T' and `%#T'",
3912 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
));
3915 /* Give warnings for comparisons between signed and unsigned
3916 quantities that may fail. */
3917 /* Do the checking based on the original operand trees, so that
3918 casts will be considered, but default promotions won't be. */
3920 /* Do not warn if the comparison is being done in a signed type,
3921 since the signed type will only be chosen if it can represent
3922 all the values of the unsigned type. */
3923 if (! TREE_UNSIGNED (result_type
))
3925 /* Do not warn if both operands are unsigned. */
3926 else if (op0_signed
== op1_signed
)
3928 /* Do not warn if the signed quantity is an unsuffixed
3929 integer literal (or some static constant expression
3930 involving such literals) and it is non-negative. */
3931 else if ((op0_signed
&& TREE_CODE (orig_op0
) == INTEGER_CST
3932 && tree_int_cst_sgn (orig_op0
) >= 0)
3933 || (op1_signed
&& TREE_CODE (orig_op1
) == INTEGER_CST
3934 && tree_int_cst_sgn (orig_op1
) >= 0))
3936 /* Do not warn if the comparison is an equality operation,
3937 the unsigned quantity is an integral constant and it does
3938 not use the most significant bit of result_type. */
3939 else if ((resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
3940 && ((op0_signed
&& TREE_CODE (orig_op1
) == INTEGER_CST
3941 && int_fits_type_p (orig_op1
,
3942 signed_type (result_type
)))
3943 || (op1_signed
&& TREE_CODE (orig_op0
) == INTEGER_CST
3944 && int_fits_type_p (orig_op0
,
3945 signed_type (result_type
)))))
3948 warning ("comparison between signed and unsigned");
3950 /* Warn if two unsigned values are being compared in a size
3951 larger than their original size, and one (and only one) is the
3952 result of a `~' operator. This comparison will always fail.
3954 Also warn if one operand is a constant, and the constant does not
3955 have all bits set that are set in the ~ operand when it is
3958 if ((TREE_CODE (primop0
) == BIT_NOT_EXPR
)
3959 ^ (TREE_CODE (primop1
) == BIT_NOT_EXPR
))
3961 if (TREE_CODE (primop0
) == BIT_NOT_EXPR
)
3962 primop0
= get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
3963 if (TREE_CODE (primop1
) == BIT_NOT_EXPR
)
3964 primop1
= get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
3966 if (TREE_CODE (primop0
) == INTEGER_CST
3967 || TREE_CODE (primop1
) == INTEGER_CST
)
3970 HOST_WIDE_INT constant
, mask
;
3974 if (TREE_CODE (primop0
) == INTEGER_CST
)
3977 unsignedp
= unsignedp1
;
3978 constant
= TREE_INT_CST_LOW (primop0
);
3983 unsignedp
= unsignedp0
;
3984 constant
= TREE_INT_CST_LOW (primop1
);
3987 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
3988 if (bits
< TYPE_PRECISION (result_type
)
3989 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
3991 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
3992 if ((mask
& constant
) != mask
)
3993 warning ("comparison of promoted ~unsigned with constant");
3996 else if (unsignedp0
&& unsignedp1
3997 && (TYPE_PRECISION (TREE_TYPE (primop0
))
3998 < TYPE_PRECISION (result_type
))
3999 && (TYPE_PRECISION (TREE_TYPE (primop1
))
4000 < TYPE_PRECISION (result_type
)))
4001 warning ("comparison of promoted ~unsigned with unsigned");
4006 /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
4007 If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
4008 Then the expression will be built.
4009 It will be given type FINAL_TYPE if that is nonzero;
4010 otherwise, it will be given type RESULT_TYPE. */
4014 cp_error ("invalid operands `%T' and `%T' to binary `%O'",
4015 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
), error_code
);
4016 return error_mark_node
;
4019 /* Issue warnings about peculiar, but legal, uses of NULL. */
4020 if (/* It's reasonable to use pointer values as operands of &&
4021 and ||, so NULL is no exception. */
4022 !(code
== TRUTH_ANDIF_EXPR
|| code
== TRUTH_ORIF_EXPR
)
4023 && (/* If OP0 is NULL and OP1 is not a pointer, or vice versa. */
4024 (orig_op0
== null_node
4025 && TREE_CODE (TREE_TYPE (op1
)) != POINTER_TYPE
)
4026 /* Or vice versa. */
4027 || (orig_op1
== null_node
4028 && TREE_CODE (TREE_TYPE (op0
)) != POINTER_TYPE
)
4029 /* Or, both are NULL and the operation was not a comparison. */
4030 || (orig_op0
== null_node
&& orig_op1
== null_node
4031 && code
!= EQ_EXPR
&& code
!= NE_EXPR
)))
4032 /* Some sort of arithmetic operation involving NULL was
4033 performed. Note that pointer-difference and pointer-addition
4034 have already been handled above, and so we don't end up here in
4036 cp_warning ("NULL used in arithmetic");
4040 if (TREE_TYPE (op0
) != result_type
)
4041 op0
= cp_convert (result_type
, op0
);
4042 if (TREE_TYPE (op1
) != result_type
)
4043 op1
= cp_convert (result_type
, op1
);
4046 if (build_type
== NULL_TREE
)
4047 build_type
= result_type
;
4050 register tree result
= build (resultcode
, build_type
, op0
, op1
);
4051 register tree folded
;
4053 folded
= fold (result
);
4054 if (folded
== result
)
4055 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
4056 if (final_type
!= 0)
4057 return cp_convert (final_type
, folded
);
4062 /* Return a tree for the sum or difference (RESULTCODE says which)
4063 of pointer PTROP and integer INTOP. */
4066 pointer_int_sum (resultcode
, ptrop
, intop
)
4067 enum tree_code resultcode
;
4068 register tree ptrop
, intop
;
4072 register tree result
;
4073 register tree folded
= fold (intop
);
4075 /* The result is a pointer of the same type that is being added. */
4077 register tree result_type
= TREE_TYPE (ptrop
);
4079 if (!complete_type_or_else (result_type
))
4080 return error_mark_node
;
4082 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
4084 if (pedantic
|| warn_pointer_arith
)
4085 pedwarn ("ANSI C++ forbids using pointer of type `void *' in arithmetic");
4086 size_exp
= integer_one_node
;
4088 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
4090 if (pedantic
|| warn_pointer_arith
)
4091 pedwarn ("ANSI C++ forbids using pointer to a function in arithmetic");
4092 size_exp
= integer_one_node
;
4094 else if (TREE_CODE (TREE_TYPE (result_type
)) == METHOD_TYPE
)
4096 if (pedantic
|| warn_pointer_arith
)
4097 pedwarn ("ANSI C++ forbids using pointer to a method in arithmetic");
4098 size_exp
= integer_one_node
;
4100 else if (TREE_CODE (TREE_TYPE (result_type
)) == OFFSET_TYPE
)
4102 if (pedantic
|| warn_pointer_arith
)
4103 pedwarn ("ANSI C++ forbids using pointer to a member in arithmetic");
4104 size_exp
= integer_one_node
;
4107 size_exp
= size_in_bytes (complete_type (TREE_TYPE (result_type
)));
4109 /* Needed to make OOPS V2R3 work. */
4111 if (TREE_CODE (intop
) == INTEGER_CST
4112 && TREE_INT_CST_LOW (intop
) == 0
4113 && TREE_INT_CST_HIGH (intop
) == 0)
4116 /* If what we are about to multiply by the size of the elements
4117 contains a constant term, apply distributive law
4118 and multiply that constant term separately.
4119 This helps produce common subexpressions. */
4121 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
4122 && ! TREE_CONSTANT (intop
)
4123 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
4124 && TREE_CONSTANT (size_exp
))
4126 enum tree_code subcode
= resultcode
;
4127 if (TREE_CODE (intop
) == MINUS_EXPR
)
4128 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
4129 ptrop
= build_binary_op (subcode
, ptrop
, TREE_OPERAND (intop
, 1), 1);
4130 intop
= TREE_OPERAND (intop
, 0);
4133 /* Convert the integer argument to a type the same size as sizetype
4134 so the multiply won't overflow spuriously. */
4136 if (TYPE_PRECISION (TREE_TYPE (intop
)) != TYPE_PRECISION (sizetype
))
4137 intop
= cp_convert (type_for_size (TYPE_PRECISION (sizetype
), 0), intop
);
4139 /* Replace the integer argument with a suitable product by the object size.
4140 Do this multiplication as signed, then convert to the appropriate
4141 pointer type (actually unsigned integral). */
4143 intop
= cp_convert (result_type
,
4144 build_binary_op (MULT_EXPR
, intop
,
4145 cp_convert (TREE_TYPE (intop
),
4149 /* Create the sum or difference. */
4151 result
= build (resultcode
, result_type
, ptrop
, intop
);
4153 folded
= fold (result
);
4154 if (folded
== result
)
4155 TREE_CONSTANT (folded
) = TREE_CONSTANT (ptrop
) & TREE_CONSTANT (intop
);
4159 /* Return a tree for the difference of pointers OP0 and OP1.
4160 The resulting tree has type int. */
4163 pointer_diff (op0
, op1
, ptrtype
)
4164 register tree op0
, op1
;
4165 register tree ptrtype
;
4167 register tree result
, folded
;
4168 tree restype
= ptrdiff_type_node
;
4169 tree target_type
= TREE_TYPE (ptrtype
);
4171 if (!complete_type_or_else (target_type
))
4172 return error_mark_node
;
4174 if (pedantic
|| warn_pointer_arith
)
4176 if (TREE_CODE (target_type
) == VOID_TYPE
)
4177 pedwarn ("ANSI C++ forbids using pointer of type `void *' in subtraction");
4178 if (TREE_CODE (target_type
) == FUNCTION_TYPE
)
4179 pedwarn ("ANSI C++ forbids using pointer to a function in subtraction");
4180 if (TREE_CODE (target_type
) == METHOD_TYPE
)
4181 pedwarn ("ANSI C++ forbids using pointer to a method in subtraction");
4182 if (TREE_CODE (target_type
) == OFFSET_TYPE
)
4183 pedwarn ("ANSI C++ forbids using pointer to a member in subtraction");
4186 /* First do the subtraction as integers;
4187 then drop through to build the divide operator. */
4189 op0
= build_binary_op (MINUS_EXPR
, cp_convert (restype
, op0
),
4190 cp_convert (restype
, op1
), 1);
4192 /* This generates an error if op1 is a pointer to an incomplete type. */
4193 if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1
))) == 0)
4194 error ("arithmetic on pointer to an incomplete type");
4196 op1
= ((TREE_CODE (target_type
) == VOID_TYPE
4197 || TREE_CODE (target_type
) == FUNCTION_TYPE
4198 || TREE_CODE (target_type
) == METHOD_TYPE
4199 || TREE_CODE (target_type
) == OFFSET_TYPE
)
4201 : size_in_bytes (target_type
));
4203 /* Do the division. */
4205 result
= build (EXACT_DIV_EXPR
, restype
, op0
, cp_convert (restype
, op1
));
4207 folded
= fold (result
);
4208 if (folded
== result
)
4209 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
4213 /* Handle the case of taking the address of a COMPONENT_REF.
4214 Called by `build_unary_op' and `build_up_reference'.
4216 ARG is the COMPONENT_REF whose address we want.
4217 ARGTYPE is the pointer type that this address should have.
4218 MSG is an error message to print if this COMPONENT_REF is not
4219 addressable (such as a bitfield). */
4222 build_component_addr (arg
, argtype
, msg
)
4226 tree field
= TREE_OPERAND (arg
, 1);
4227 tree basetype
= decl_type_context (field
);
4228 tree rval
= build_unary_op (ADDR_EXPR
, TREE_OPERAND (arg
, 0), 0);
4230 if (DECL_BIT_FIELD (field
))
4232 error (msg
, IDENTIFIER_POINTER (DECL_NAME (field
)));
4233 return error_mark_node
;
4236 if (TREE_CODE (field
) == FIELD_DECL
4237 && TYPE_USES_COMPLEX_INHERITANCE (basetype
))
4239 /* Can't convert directly to ARGTYPE, since that
4240 may have the same pointer type as one of our
4242 rval
= build1 (NOP_EXPR
, argtype
,
4243 convert_pointer_to (basetype
, rval
));
4244 TREE_CONSTANT (rval
) = TREE_CONSTANT (TREE_OPERAND (rval
, 0));
4247 /* This conversion is harmless. */
4248 rval
= convert_force (argtype
, rval
, 0);
4250 if (! integer_zerop (DECL_FIELD_BITPOS (field
)))
4252 tree offset
= size_binop (EASY_DIV_EXPR
, DECL_FIELD_BITPOS (field
),
4253 size_int (BITS_PER_UNIT
));
4254 int flag
= TREE_CONSTANT (rval
);
4255 offset
= convert (sizetype
, offset
);
4256 rval
= fold (build (PLUS_EXPR
, argtype
,
4257 rval
, cp_convert (argtype
, offset
)));
4258 TREE_CONSTANT (rval
) = flag
;
4263 /* Construct and perhaps optimize a tree representation
4264 for a unary operation. CODE, a tree_code, specifies the operation
4265 and XARG is the operand. */
4268 build_x_unary_op (code
, xarg
)
4269 enum tree_code code
;
4272 if (processing_template_decl
)
4273 return build_min_nt (code
, xarg
, NULL_TREE
);
4275 /* & rec, on incomplete RECORD_TYPEs is the simple opr &, not an
4277 if (code
== ADDR_EXPR
4278 && TREE_CODE (xarg
) != TEMPLATE_ID_EXPR
4279 && ((IS_AGGR_TYPE_CODE (TREE_CODE (TREE_TYPE (xarg
)))
4280 && TYPE_SIZE (TREE_TYPE (xarg
)) == NULL_TREE
)
4281 || (TREE_CODE (xarg
) == OFFSET_REF
)))
4282 /* don't look for a function */;
4287 rval
= build_new_op (code
, LOOKUP_NORMAL
, xarg
,
4288 NULL_TREE
, NULL_TREE
);
4289 if (rval
|| code
!= ADDR_EXPR
)
4293 if (code
== ADDR_EXPR
)
4295 if (TREE_CODE (xarg
) == TARGET_EXPR
)
4296 warning ("taking address of temporary");
4299 return build_unary_op (code
, xarg
, 0);
4302 /* Just like truthvalue_conversion, but we want a CLEANUP_POINT_EXPR. */
4305 condition_conversion (expr
)
4309 if (processing_template_decl
)
4311 t
= cp_convert (boolean_type_node
, expr
);
4312 t
= fold (build1 (CLEANUP_POINT_EXPR
, boolean_type_node
, t
));
4316 /* C++: Must handle pointers to members.
4318 Perhaps type instantiation should be extended to handle conversion
4319 from aggregates to types we don't yet know we want? (Or are those
4320 cases typically errors which should be reported?)
4322 NOCONVERT nonzero suppresses the default promotions
4323 (such as from short to int). */
4326 build_unary_op (code
, xarg
, noconvert
)
4327 enum tree_code code
;
4331 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
4332 register tree arg
= xarg
;
4333 register tree argtype
= 0;
4334 char *errstring
= NULL
;
4337 if (arg
== error_mark_node
)
4338 return error_mark_node
;
4343 /* This is used for unary plus, because a CONVERT_EXPR
4344 is enough to prevent anybody from looking inside for
4345 associativity, but won't generate any code. */
4346 if (!(arg
= build_expr_type_conversion
4347 (WANT_ARITH
| WANT_ENUM
| WANT_POINTER
, arg
, 1)))
4348 errstring
= "wrong type argument to unary plus";
4352 arg
= default_conversion (arg
);
4353 arg
= build1 (NON_LVALUE_EXPR
, TREE_TYPE (arg
), arg
);
4354 TREE_CONSTANT (arg
) = TREE_CONSTANT (TREE_OPERAND (arg
, 0));
4359 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
4360 errstring
= "wrong type argument to unary minus";
4361 else if (!noconvert
)
4362 arg
= default_conversion (arg
);
4366 if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
4370 arg
= default_conversion (arg
);
4372 else if (!(arg
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
,
4374 errstring
= "wrong type argument to bit-complement";
4375 else if (!noconvert
)
4376 arg
= default_conversion (arg
);
4380 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
4381 errstring
= "wrong type argument to abs";
4382 else if (!noconvert
)
4383 arg
= default_conversion (arg
);
4387 /* Conjugating a real value is a no-op, but allow it anyway. */
4388 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
4389 errstring
= "wrong type argument to conjugation";
4390 else if (!noconvert
)
4391 arg
= default_conversion (arg
);
4394 case TRUTH_NOT_EXPR
:
4395 arg
= cp_convert (boolean_type_node
, arg
);
4396 val
= invert_truthvalue (arg
);
4397 if (arg
!= error_mark_node
)
4399 errstring
= "in argument to unary !";
4406 if (TREE_CODE (arg
) == COMPLEX_CST
)
4407 return TREE_REALPART (arg
);
4408 else if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
4409 return fold (build1 (REALPART_EXPR
, TREE_TYPE (TREE_TYPE (arg
)), arg
));
4414 if (TREE_CODE (arg
) == COMPLEX_CST
)
4415 return TREE_IMAGPART (arg
);
4416 else if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
4417 return fold (build1 (IMAGPART_EXPR
, TREE_TYPE (TREE_TYPE (arg
)), arg
));
4419 return cp_convert (TREE_TYPE (arg
), integer_zero_node
);
4421 case PREINCREMENT_EXPR
:
4422 case POSTINCREMENT_EXPR
:
4423 case PREDECREMENT_EXPR
:
4424 case POSTDECREMENT_EXPR
:
4425 /* Handle complex lvalues (when permitted)
4426 by reduction to simpler cases. */
4428 val
= unary_complex_lvalue (code
, arg
);
4432 /* Increment or decrement the real part of the value,
4433 and don't change the imaginary part. */
4434 if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
4438 arg
= stabilize_reference (arg
);
4439 real
= build_unary_op (REALPART_EXPR
, arg
, 1);
4440 imag
= build_unary_op (IMAGPART_EXPR
, arg
, 1);
4441 return build (COMPLEX_EXPR
, TREE_TYPE (arg
),
4442 build_unary_op (code
, real
, 1), imag
);
4445 /* Report invalid types. */
4447 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_POINTER
,
4450 if (code
== PREINCREMENT_EXPR
)
4451 errstring
="no pre-increment operator for type";
4452 else if (code
== POSTINCREMENT_EXPR
)
4453 errstring
="no post-increment operator for type";
4454 else if (code
== PREDECREMENT_EXPR
)
4455 errstring
="no pre-decrement operator for type";
4457 errstring
="no post-decrement operator for type";
4461 /* Report something read-only. */
4463 if (TYPE_READONLY (TREE_TYPE (arg
))
4464 || TREE_READONLY (arg
))
4465 readonly_error (arg
, ((code
== PREINCREMENT_EXPR
4466 || code
== POSTINCREMENT_EXPR
)
4467 ? "increment" : "decrement"),
4472 tree result_type
= TREE_TYPE (arg
);
4474 arg
= get_unwidened (arg
, 0);
4475 argtype
= TREE_TYPE (arg
);
4477 /* ARM $5.2.5 last annotation says this should be forbidden. */
4478 if (TREE_CODE (argtype
) == ENUMERAL_TYPE
)
4479 pedwarn ("ANSI C++ forbids %sing an enum",
4480 (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
4481 ? "increment" : "decrement");
4483 /* Compute the increment. */
4485 if (TREE_CODE (argtype
) == POINTER_TYPE
)
4487 enum tree_code tmp
= TREE_CODE (TREE_TYPE (argtype
));
4488 if (TYPE_SIZE (complete_type (TREE_TYPE (argtype
))) == 0)
4489 cp_error ("cannot %s a pointer to incomplete type `%T'",
4490 ((code
== PREINCREMENT_EXPR
4491 || code
== POSTINCREMENT_EXPR
)
4492 ? "increment" : "decrement"), TREE_TYPE (argtype
));
4493 else if ((pedantic
|| warn_pointer_arith
)
4494 && (tmp
== FUNCTION_TYPE
|| tmp
== METHOD_TYPE
4495 || tmp
== VOID_TYPE
|| tmp
== OFFSET_TYPE
))
4496 cp_pedwarn ("ANSI C++ forbids %sing a pointer of type `%T'",
4497 ((code
== PREINCREMENT_EXPR
4498 || code
== POSTINCREMENT_EXPR
)
4499 ? "increment" : "decrement"), argtype
);
4500 inc
= c_sizeof_nowarn (TREE_TYPE (argtype
));
4503 inc
= integer_one_node
;
4505 inc
= cp_convert (argtype
, inc
);
4507 /* Handle incrementing a cast-expression. */
4509 switch (TREE_CODE (arg
))
4514 case FIX_TRUNC_EXPR
:
4515 case FIX_FLOOR_EXPR
:
4516 case FIX_ROUND_EXPR
:
4519 tree incremented
, modify
, value
, compound
;
4520 if (! lvalue_p (arg
) && pedantic
)
4521 pedwarn ("cast to non-reference type used as lvalue");
4522 arg
= stabilize_reference (arg
);
4523 if (code
== PREINCREMENT_EXPR
|| code
== PREDECREMENT_EXPR
)
4526 value
= save_expr (arg
);
4527 incremented
= build (((code
== PREINCREMENT_EXPR
4528 || code
== POSTINCREMENT_EXPR
)
4529 ? PLUS_EXPR
: MINUS_EXPR
),
4530 argtype
, value
, inc
);
4531 TREE_SIDE_EFFECTS (incremented
) = 1;
4533 modify
= build_modify_expr (arg
, NOP_EXPR
, incremented
);
4534 compound
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), modify
, value
);
4536 /* Eliminate warning about unused result of + or -. */
4537 TREE_NO_UNUSED_WARNING (compound
) = 1;
4545 /* Complain about anything else that is not a true lvalue. */
4546 if (!lvalue_or_else (arg
, ((code
== PREINCREMENT_EXPR
4547 || code
== POSTINCREMENT_EXPR
)
4548 ? "increment" : "decrement")))
4549 return error_mark_node
;
4551 /* Forbid using -- on `bool'. */
4552 if (TREE_TYPE (arg
) == boolean_type_node
)
4554 if (code
== POSTDECREMENT_EXPR
|| code
== PREDECREMENT_EXPR
)
4556 cp_error ("invalid use of `--' on bool variable `%D'", arg
);
4557 return error_mark_node
;
4560 /* This will only work if someone can convince Kenner to accept
4561 my patch to expand_increment. (jason) */
4562 val
= build (code
, TREE_TYPE (arg
), arg
, inc
);
4564 if (code
== POSTINCREMENT_EXPR
)
4566 arg
= stabilize_reference (arg
);
4567 val
= build (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
4569 TREE_SIDE_EFFECTS (val
) = 1;
4570 arg
= save_expr (arg
);
4571 val
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
4572 val
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
4575 val
= build (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
4580 val
= build (code
, TREE_TYPE (arg
), arg
, inc
);
4582 TREE_SIDE_EFFECTS (val
) = 1;
4583 return cp_convert (result_type
, val
);
4587 /* Note that this operation never does default_conversion
4588 regardless of NOCONVERT. */
4590 argtype
= lvalue_type (arg
);
4591 if (TREE_CODE (argtype
) == REFERENCE_TYPE
)
4595 build_pointer_type (TREE_TYPE (argtype
)), arg
);
4596 TREE_CONSTANT (arg
) = TREE_CONSTANT (TREE_OPERAND (arg
, 0));
4599 else if (pedantic
&& DECL_MAIN_P (arg
))
4601 pedwarn ("taking address of function `main'");
4603 /* Let &* cancel out to simplify resulting code. */
4604 if (TREE_CODE (arg
) == INDIRECT_REF
)
4606 /* We don't need to have `current_class_ptr' wrapped in a
4607 NON_LVALUE_EXPR node. */
4608 if (arg
== current_class_ref
)
4609 return current_class_ptr
;
4611 arg
= TREE_OPERAND (arg
, 0);
4612 if (TREE_CODE (TREE_TYPE (arg
)) == REFERENCE_TYPE
)
4616 build_pointer_type (TREE_TYPE (TREE_TYPE (arg
))), arg
);
4617 TREE_CONSTANT (arg
) = TREE_CONSTANT (TREE_OPERAND (arg
, 0));
4619 else if (lvalue_p (arg
))
4620 /* Don't let this be an lvalue. */
4621 return non_lvalue (arg
);
4625 /* For &x[y], return x+y */
4626 if (TREE_CODE (arg
) == ARRAY_REF
)
4628 if (mark_addressable (TREE_OPERAND (arg
, 0)) == 0)
4629 return error_mark_node
;
4630 return build_binary_op (PLUS_EXPR
, TREE_OPERAND (arg
, 0),
4631 TREE_OPERAND (arg
, 1), 1);
4634 /* Uninstantiated types are all functions. Taking the
4635 address of a function is a no-op, so just return the
4638 if (TREE_CODE (arg
) == IDENTIFIER_NODE
4639 && IDENTIFIER_OPNAME_P (arg
))
4641 my_friendly_abort (117);
4642 /* We don't know the type yet, so just work around the problem.
4643 We know that this will resolve to an lvalue. */
4644 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4647 if (TREE_CODE (arg
) == OVERLOAD
4648 || (TREE_CODE (arg
) == OFFSET_REF
4649 && TREE_CODE (TREE_OPERAND (arg
, 1)) == TEMPLATE_ID_EXPR
))
4650 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4651 else if (TREE_CODE (arg
) == TREE_LIST
)
4653 if (TREE_CODE (TREE_VALUE (arg
)) == FUNCTION_DECL
)
4654 /* Unique overloaded non-member function. */
4655 return build_unary_op (ADDR_EXPR
, TREE_VALUE (arg
), 0);
4656 if (TREE_CHAIN (arg
) == NULL_TREE
4657 && TREE_CODE (TREE_VALUE (arg
)) == TREE_LIST
4658 && TREE_CODE (TREE_VALUE (TREE_VALUE (arg
))) != OVERLOAD
)
4659 /* Unique overloaded member function. */
4660 return build_unary_op (ADDR_EXPR
, TREE_VALUE (TREE_VALUE (arg
)),
4662 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4664 else if (TREE_CODE (arg
) == TEMPLATE_ID_EXPR
)
4669 /* We don't require a match here; it's possible that the
4670 context (like a cast to a particular type) will resolve
4671 the particular choice of template. */
4672 fn
= determine_specialization (arg
,
4680 fn
= instantiate_template (fn
, targs
);
4681 mark_addressable (fn
);
4682 return build_unary_op (ADDR_EXPR
, fn
, 0);
4685 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4688 /* Handle complex lvalues (when permitted)
4689 by reduction to simpler cases. */
4690 val
= unary_complex_lvalue (code
, arg
);
4694 switch (TREE_CODE (arg
))
4699 case FIX_TRUNC_EXPR
:
4700 case FIX_FLOOR_EXPR
:
4701 case FIX_ROUND_EXPR
:
4703 if (! lvalue_p (arg
) && pedantic
)
4704 pedwarn ("taking the address of a cast to non-reference type");
4711 /* Allow the address of a constructor if all the elements
4713 if (TREE_CODE (arg
) == CONSTRUCTOR
&& TREE_HAS_CONSTRUCTOR (arg
)
4714 && TREE_CONSTANT (arg
))
4716 /* Anything not already handled and not a true memory reference
4718 else if (TREE_CODE (argtype
) != FUNCTION_TYPE
4719 && TREE_CODE (argtype
) != METHOD_TYPE
4720 && !lvalue_or_else (arg
, "unary `&'"))
4721 return error_mark_node
;
4723 argtype
= build_pointer_type (argtype
);
4725 if (mark_addressable (arg
) == 0)
4726 return error_mark_node
;
4731 if (TREE_CODE (arg
) == COMPONENT_REF
)
4732 addr
= build_component_addr
4734 "attempt to take address of bit-field structure member `%s'");
4736 addr
= build1 (code
, argtype
, arg
);
4738 /* Address of a static or external variable or
4739 function counts as a constant */
4741 TREE_CONSTANT (addr
) = 1;
4743 if (TREE_CODE (argtype
) == POINTER_TYPE
4744 && TREE_CODE (TREE_TYPE (argtype
)) == METHOD_TYPE
)
4746 build_ptrmemfunc_type (argtype
);
4747 addr
= build_ptrmemfunc (argtype
, addr
, 0);
4760 argtype
= TREE_TYPE (arg
);
4761 return fold (build1 (code
, argtype
, arg
));
4765 return error_mark_node
;
4769 /* If CONVERSIONS is a conversion expression or a nested sequence of such,
4770 convert ARG with the same conversions in the same order
4771 and return the result. */
4774 convert_sequence (conversions
, arg
)
4778 switch (TREE_CODE (conversions
))
4783 case FIX_TRUNC_EXPR
:
4784 case FIX_FLOOR_EXPR
:
4785 case FIX_ROUND_EXPR
:
4787 return cp_convert (TREE_TYPE (conversions
),
4788 convert_sequence (TREE_OPERAND (conversions
, 0),
4797 /* Apply unary lvalue-demanding operator CODE to the expression ARG
4798 for certain kinds of expressions which are not really lvalues
4799 but which we can accept as lvalues.
4801 If ARG is not a kind of expression we can handle, return zero. */
4804 unary_complex_lvalue (code
, arg
)
4805 enum tree_code code
;
4808 /* Handle (a, b) used as an "lvalue". */
4809 if (TREE_CODE (arg
) == COMPOUND_EXPR
)
4811 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 1), 0);
4812 return build (COMPOUND_EXPR
, TREE_TYPE (real_result
),
4813 TREE_OPERAND (arg
, 0), real_result
);
4816 /* Handle (a ? b : c) used as an "lvalue". */
4817 if (TREE_CODE (arg
) == COND_EXPR
4818 || TREE_CODE (arg
) == MIN_EXPR
|| TREE_CODE (arg
) == MAX_EXPR
)
4819 return rationalize_conditional_expr (code
, arg
);
4821 if (TREE_CODE (arg
) == MODIFY_EXPR
4822 || TREE_CODE (arg
) == PREINCREMENT_EXPR
4823 || TREE_CODE (arg
) == PREDECREMENT_EXPR
)
4824 return unary_complex_lvalue
4825 (code
, build (COMPOUND_EXPR
, TREE_TYPE (TREE_OPERAND (arg
, 0)),
4826 arg
, TREE_OPERAND (arg
, 0)));
4828 if (code
!= ADDR_EXPR
)
4831 /* Handle (a = b) used as an "lvalue" for `&'. */
4832 if (TREE_CODE (arg
) == MODIFY_EXPR
4833 || TREE_CODE (arg
) == INIT_EXPR
)
4835 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 0), 0);
4836 arg
= build (COMPOUND_EXPR
, TREE_TYPE (real_result
), arg
, real_result
);
4837 TREE_NO_UNUSED_WARNING (arg
) = 1;
4841 if (TREE_CODE (TREE_TYPE (arg
)) == FUNCTION_TYPE
4842 || TREE_CODE (TREE_TYPE (arg
)) == METHOD_TYPE
4843 || TREE_CODE (TREE_TYPE (arg
)) == OFFSET_TYPE
)
4845 /* The representation of something of type OFFSET_TYPE
4846 is really the representation of a pointer to it.
4847 Here give the representation its true type. */
4850 my_friendly_assert (TREE_CODE (arg
) != SCOPE_REF
, 313);
4852 if (TREE_CODE (arg
) != OFFSET_REF
)
4855 t
= TREE_OPERAND (arg
, 1);
4857 /* Check all this code for right semantics. */
4858 if (TREE_CODE (t
) == FUNCTION_DECL
)
4860 if (DECL_DESTRUCTOR_P (t
))
4861 cp_error ("taking address of destructor");
4862 return build_unary_op (ADDR_EXPR
, t
, 0);
4864 if (TREE_CODE (t
) == VAR_DECL
)
4865 return build_unary_op (ADDR_EXPR
, t
, 0);
4871 if (TREE_OPERAND (arg
, 0)
4872 && (TREE_CODE (TREE_OPERAND (arg
, 0)) != NOP_EXPR
4873 || (TREE_OPERAND (TREE_OPERAND (arg
, 0), 0)
4874 != error_mark_node
)))
4875 if (TREE_CODE (t
) != FIELD_DECL
)
4877 /* Don't know if this should return address to just
4878 _DECL, or actual address resolved in this expression. */
4879 sorry ("address of bound pointer-to-member expression");
4880 return error_mark_node
;
4883 /* Add in the offset to the field. */
4884 offset
= convert (sizetype
,
4885 size_binop (EASY_DIV_EXPR
,
4886 DECL_FIELD_BITPOS (t
),
4887 size_int (BITS_PER_UNIT
)));
4889 /* We offset all pointer to data members by 1 so that we can
4890 distinguish between a null pointer to data member and the first
4891 data member of a structure. */
4892 offset
= size_binop (PLUS_EXPR
, offset
, size_int (1));
4894 type
= build_offset_type (DECL_FIELD_CONTEXT (t
), TREE_TYPE (t
));
4895 type
= build_pointer_type (type
);
4897 return cp_convert (type
, offset
);
4902 /* We permit compiler to make function calls returning
4903 objects of aggregate type look like lvalues. */
4907 if (TREE_CODE (targ
) == SAVE_EXPR
)
4908 targ
= TREE_OPERAND (targ
, 0);
4910 if (TREE_CODE (targ
) == CALL_EXPR
&& IS_AGGR_TYPE (TREE_TYPE (targ
)))
4912 if (TREE_CODE (arg
) == SAVE_EXPR
)
4915 targ
= build_cplus_new (TREE_TYPE (arg
), arg
);
4916 return build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (arg
)), targ
);
4919 if (TREE_CODE (arg
) == SAVE_EXPR
&& TREE_CODE (targ
) == INDIRECT_REF
)
4920 return build (SAVE_EXPR
, build_pointer_type (TREE_TYPE (arg
)),
4921 TREE_OPERAND (targ
, 0), current_function_decl
, NULL
);
4924 /* Don't let anything else be handled specially. */
4928 /* Mark EXP saying that we need to be able to take the
4929 address of it; it should not be allocated in a register.
4930 Value is 1 if successful.
4932 C++: we do not allow `current_class_ptr' to be addressable. */
4935 mark_addressable (exp
)
4938 register tree x
= exp
;
4940 if (TREE_ADDRESSABLE (x
) == 1)
4944 switch (TREE_CODE (x
))
4951 x
= TREE_OPERAND (x
, 0);
4955 if (x
== current_class_ptr
)
4957 if (! flag_this_is_variable
)
4958 error ("address of `this' not available");
4959 TREE_ADDRESSABLE (x
) = 1; /* so compiler doesn't die later */
4960 put_var_into_stack (x
);
4964 if (TREE_STATIC (x
) && TREE_READONLY (x
)
4965 && DECL_RTL (x
) != 0
4966 && ! DECL_IN_MEMORY_P (x
))
4968 /* We thought this would make a good constant variable,
4969 but we were wrong. */
4970 push_obstacks_nochange ();
4971 end_temporary_allocation ();
4973 TREE_ASM_WRITTEN (x
) = 0;
4975 rest_of_decl_compilation (x
, 0, IDENTIFIER_LOCAL_VALUE (x
) == 0,
4977 TREE_ADDRESSABLE (x
) = 1;
4983 /* Caller should not be trying to mark initialized
4984 constant fields addressable. */
4985 my_friendly_assert (DECL_LANG_SPECIFIC (x
) == 0
4986 || DECL_IN_AGGR_P (x
) == 0
4988 || DECL_EXTERNAL (x
), 314);
4992 if (DECL_REGISTER (x
) && !TREE_ADDRESSABLE (x
)
4993 && !DECL_ARTIFICIAL (x
) && extra_warnings
)
4994 cp_warning ("address requested for `%D', which is declared `register'",
4996 put_var_into_stack (x
);
4997 TREE_ADDRESSABLE (x
) = 1;
5001 if (DECL_LANG_SPECIFIC (x
) != 0)
5003 x
= DECL_MAIN_VARIANT (x
);
5004 /* We have to test both conditions here. The first may be
5005 non-zero in the case of processing a default function. The
5006 second may be non-zero in the case of a template function. */
5007 if (DECL_TEMPLATE_INFO (x
) && !DECL_TEMPLATE_SPECIALIZATION (x
))
5010 TREE_ADDRESSABLE (x
) = 1;
5012 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x
)) = 1;
5016 TREE_ADDRESSABLE (x
) = 1;
5020 TREE_ADDRESSABLE (x
) = 1;
5021 mark_addressable (TREE_OPERAND (x
, 0));
5029 /* Build and return a conditional expression IFEXP ? OP1 : OP2. */
5032 build_x_conditional_expr (ifexp
, op1
, op2
)
5033 tree ifexp
, op1
, op2
;
5035 if (processing_template_decl
)
5036 return build_min_nt (COND_EXPR
, ifexp
, op1
, op2
);
5038 return build_new_op (COND_EXPR
, LOOKUP_NORMAL
, ifexp
, op1
, op2
);
5042 build_conditional_expr (ifexp
, op1
, op2
)
5043 tree ifexp
, op1
, op2
;
5045 register tree type1
;
5046 register tree type2
;
5047 register enum tree_code code1
;
5048 register enum tree_code code2
;
5049 register tree result_type
= NULL_TREE
;
5051 /* If second operand is omitted, it is the same as the first one;
5052 make sure it is calculated only once. */
5056 pedwarn ("ANSI C++ forbids omitting the middle term of a ?: expression");
5057 ifexp
= op1
= save_expr (ifexp
);
5060 ifexp
= cp_convert (boolean_type_node
, ifexp
);
5062 if (TREE_CODE (ifexp
) == ERROR_MARK
)
5063 return error_mark_node
;
5065 op1
= require_instantiated_type (TREE_TYPE (op2
), op1
, error_mark_node
);
5066 if (op1
== error_mark_node
)
5067 return error_mark_node
;
5068 op2
= require_instantiated_type (TREE_TYPE (op1
), op2
, error_mark_node
);
5069 if (op2
== error_mark_node
)
5070 return error_mark_node
;
5072 /* C++: REFERENCE_TYPES must be dereferenced. */
5073 type1
= TREE_TYPE (op1
);
5074 code1
= TREE_CODE (type1
);
5075 type2
= TREE_TYPE (op2
);
5076 code2
= TREE_CODE (type2
);
5078 if (code1
== REFERENCE_TYPE
)
5080 op1
= convert_from_reference (op1
);
5081 type1
= TREE_TYPE (op1
);
5082 code1
= TREE_CODE (type1
);
5084 if (code2
== REFERENCE_TYPE
)
5086 op2
= convert_from_reference (op2
);
5087 type2
= TREE_TYPE (op2
);
5088 code2
= TREE_CODE (type2
);
5091 /* Don't promote the operands separately if they promote
5092 the same way. Return the unpromoted type and let the combined
5093 value get promoted if necessary. */
5095 if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
)
5096 && code2
!= ARRAY_TYPE
5097 && code2
!= FUNCTION_TYPE
5098 && code2
!= METHOD_TYPE
)
5102 if (TREE_CONSTANT (ifexp
)
5103 && (TREE_CODE (ifexp
) == INTEGER_CST
5104 || TREE_CODE (ifexp
) == ADDR_EXPR
))
5105 return (integer_zerop (ifexp
) ? op2
: op1
);
5107 if (TREE_CODE (op1
) == CONST_DECL
)
5108 op1
= DECL_INITIAL (op1
);
5109 else if (TREE_READONLY_DECL_P (op1
))
5110 op1
= decl_constant_value (op1
);
5111 if (TREE_CODE (op2
) == CONST_DECL
)
5112 op2
= DECL_INITIAL (op2
);
5113 else if (TREE_READONLY_DECL_P (op2
))
5114 op2
= decl_constant_value (op2
);
5116 type1
= cp_build_type_variant
5118 TREE_READONLY (op1
) || TREE_READONLY (op2
),
5119 TREE_THIS_VOLATILE (op1
) || TREE_THIS_VOLATILE (op2
));
5120 /* ??? This is a kludge to deal with the fact that
5121 we don't sort out integers and enums properly, yet. */
5122 result
= fold (build (COND_EXPR
, type1
, ifexp
, op1
, op2
));
5123 if (TREE_TYPE (result
) != type1
)
5124 result
= build1 (NOP_EXPR
, type1
, result
);
5125 /* Expand both sides into the same slot,
5126 hopefully the target of the ?: expression. */
5127 if (TREE_CODE (op1
) == TARGET_EXPR
&& TREE_CODE (op2
) == TARGET_EXPR
)
5129 tree slot
= build (VAR_DECL
, TREE_TYPE (result
));
5130 layout_decl (slot
, 0);
5131 result
= build (TARGET_EXPR
, TREE_TYPE (result
),
5132 slot
, result
, NULL_TREE
, NULL_TREE
);
5137 /* They don't match; promote them both and then try to reconcile them.
5138 But don't permit mismatching enum types. */
5139 if (code1
== ENUMERAL_TYPE
)
5141 if (code2
== ENUMERAL_TYPE
)
5143 cp_error ("enumeral mismatch in conditional expression: `%T' vs `%T'",
5145 return error_mark_node
;
5147 else if (extra_warnings
&& ! IS_AGGR_TYPE_CODE (code2
)
5148 && type2
!= type_promotes_to (type1
))
5149 warning ("enumeral and non-enumeral type in conditional expression");
5151 else if (extra_warnings
5152 && code2
== ENUMERAL_TYPE
&& ! IS_AGGR_TYPE_CODE (code1
)
5153 && type1
!= type_promotes_to (type2
))
5154 warning ("enumeral and non-enumeral type in conditional expression");
5156 if (code1
!= VOID_TYPE
)
5158 op1
= default_conversion (op1
);
5159 type1
= TREE_TYPE (op1
);
5160 if (TYPE_PTRMEMFUNC_P (type1
))
5161 type1
= TYPE_PTRMEMFUNC_FN_TYPE (type1
);
5162 code1
= TREE_CODE (type1
);
5164 if (code2
!= VOID_TYPE
)
5166 op2
= default_conversion (op2
);
5167 type2
= TREE_TYPE (op2
);
5168 if (TYPE_PTRMEMFUNC_P (type2
))
5169 type2
= TYPE_PTRMEMFUNC_FN_TYPE (type2
);
5170 code2
= TREE_CODE (type2
);
5173 if (code1
== RECORD_TYPE
&& code2
== RECORD_TYPE
5174 && real_lvalue_p (op1
) && real_lvalue_p (op2
)
5175 && comptypes (type1
, type2
, -1))
5177 type1
= build_reference_type (type1
);
5178 type2
= build_reference_type (type2
);
5179 result_type
= common_type (type1
, type2
);
5180 op1
= convert_to_reference (result_type
, op1
, CONV_IMPLICIT
,
5181 LOOKUP_NORMAL
, NULL_TREE
);
5182 op2
= convert_to_reference (result_type
, op2
, CONV_IMPLICIT
,
5183 LOOKUP_NORMAL
, NULL_TREE
);
5185 /* Quickly detect the usual case where op1 and op2 have the same type
5187 else if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
))
5190 result_type
= type1
;
5192 result_type
= cp_build_type_variant
5194 TREE_READONLY (op1
) || TREE_READONLY (op2
),
5195 TREE_THIS_VOLATILE (op1
) || TREE_THIS_VOLATILE (op2
));
5197 else if ((code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
)
5198 && (code2
== INTEGER_TYPE
|| code2
== REAL_TYPE
))
5200 result_type
= common_type (type1
, type2
);
5202 else if (code1
== VOID_TYPE
|| code2
== VOID_TYPE
)
5204 if (pedantic
&& (code1
!= VOID_TYPE
|| code2
!= VOID_TYPE
))
5205 pedwarn ("ANSI C++ forbids conditional expr with only one void side");
5206 result_type
= void_type_node
;
5208 else if (code1
== POINTER_TYPE
&& null_ptr_cst_p (op2
))
5209 result_type
= qualify_type (type1
, type2
);
5210 else if (code2
== POINTER_TYPE
&& null_ptr_cst_p (op1
))
5211 result_type
= qualify_type (type2
, type1
);
5212 else if (code1
== POINTER_TYPE
&& code2
== POINTER_TYPE
)
5214 if (comp_target_types (type1
, type2
, 1))
5215 result_type
= common_type (type1
, type2
);
5216 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1
)) == void_type_node
)
5218 if (pedantic
&& TREE_CODE (type2
) == FUNCTION_TYPE
)
5219 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
5220 result_type
= qualify_type (type1
, type2
);
5222 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2
)) == void_type_node
)
5224 if (pedantic
&& TREE_CODE (type1
) == FUNCTION_TYPE
)
5225 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
5226 result_type
= qualify_type (type2
, type1
);
5229 else if (comptypes (type2
, type1
, 0))
5230 result_type
= type2
;
5231 else if (IS_AGGR_TYPE (TREE_TYPE (type1
))
5232 && IS_AGGR_TYPE (TREE_TYPE (type2
))
5233 && (result_type
= common_base_type (TREE_TYPE (type1
),
5234 TREE_TYPE (type2
))))
5236 if (result_type
== error_mark_node
)
5238 cp_error ("common base type of types `%T' and `%T' is ambiguous",
5239 TREE_TYPE (type1
), TREE_TYPE (type2
));
5240 result_type
= ptr_type_node
;
5245 && result_type
!= TREE_TYPE (type1
)
5246 && result_type
!= TREE_TYPE (type2
))
5247 cp_pedwarn ("`%T' and `%T' converted to `%T *' in conditional expression",
5248 type1
, type2
, result_type
);
5250 result_type
= build_pointer_type (result_type
);
5255 pedwarn ("pointer type mismatch in conditional expression");
5256 result_type
= ptr_type_node
;
5259 else if (code1
== POINTER_TYPE
&& code2
== INTEGER_TYPE
)
5261 pedwarn ("pointer/integer type mismatch in conditional expression");
5262 result_type
= type1
;
5264 else if (code2
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
5266 pedwarn ("pointer/integer type mismatch in conditional expression");
5267 result_type
= type2
;
5272 /* The match does not look good. If either is
5273 an aggregate value, try converting to a scalar type. */
5274 if (code1
== RECORD_TYPE
&& code2
== RECORD_TYPE
)
5276 cp_error ("aggregate mismatch in conditional expression: `%T' vs `%T'",
5278 return error_mark_node
;
5280 /* Warning: this code assumes that conversion between cv-variants of
5281 a type is done using NOP_EXPRs. */
5282 if (code1
== RECORD_TYPE
&& TYPE_HAS_CONVERSION (type1
))
5284 /* There are other types besides pointers and records. */
5286 if (code2
== POINTER_TYPE
)
5287 tmp
= build_pointer_type
5288 (build_type_variant (TREE_TYPE (type2
), 1, 1));
5291 tmp
= build_type_conversion (CONVERT_EXPR
, tmp
, op1
, 0);
5292 if (tmp
== NULL_TREE
)
5294 cp_error ("incompatible types `%T' and `%T' in `?:'",
5296 return error_mark_node
;
5298 if (tmp
== error_mark_node
)
5299 error ("ambiguous pointer conversion");
5302 result_type
= common_type (type2
, TREE_TYPE (tmp
));
5305 else if (code2
== RECORD_TYPE
&& TYPE_HAS_CONVERSION (type2
))
5308 if (code1
== POINTER_TYPE
)
5309 tmp
= build_pointer_type
5310 (build_type_variant (TREE_TYPE (type1
), 1, 1));
5314 tmp
= build_type_conversion (CONVERT_EXPR
, tmp
, op2
, 0);
5315 if (tmp
== NULL_TREE
)
5317 cp_error ("incompatible types `%T' and `%T' in `?:'",
5319 return error_mark_node
;
5321 if (tmp
== error_mark_node
)
5322 error ("ambiguous pointer conversion");
5325 result_type
= common_type (type1
, TREE_TYPE (tmp
));
5328 else if (flag_cond_mismatch
)
5329 result_type
= void_type_node
;
5332 error ("type mismatch in conditional expression");
5333 return error_mark_node
;
5337 if (TREE_CODE (result_type
) == POINTER_TYPE
5338 && TREE_CODE (TREE_TYPE (result_type
)) == METHOD_TYPE
)
5339 result_type
= build_ptrmemfunc_type (result_type
);
5341 if (result_type
!= TREE_TYPE (op1
))
5342 op1
= convert_for_initialization
5343 (NULL_TREE
, result_type
, op1
, LOOKUP_NORMAL
, "converting", NULL_TREE
, 0);
5344 if (result_type
!= TREE_TYPE (op2
))
5345 op2
= convert_for_initialization
5346 (NULL_TREE
, result_type
, op2
, LOOKUP_NORMAL
, "converting", NULL_TREE
, 0);
5348 if (TREE_CONSTANT (ifexp
))
5349 return integer_zerop (ifexp
) ? op2
: op1
;
5351 return convert_from_reference
5352 (fold (build (COND_EXPR
, result_type
, ifexp
, op1
, op2
)));
5355 /* Handle overloading of the ',' operator when needed. Otherwise,
5356 this function just builds an expression list. */
5359 build_x_compound_expr (list
)
5362 tree rest
= TREE_CHAIN (list
);
5365 if (processing_template_decl
)
5366 return build_min_nt (COMPOUND_EXPR
, list
, NULL_TREE
);
5368 if (rest
== NULL_TREE
)
5369 return build_compound_expr (list
);
5371 result
= build_opfncall (COMPOUND_EXPR
, LOOKUP_NORMAL
,
5372 TREE_VALUE (list
), TREE_VALUE (rest
), NULL_TREE
);
5374 return build_x_compound_expr (expr_tree_cons (NULL_TREE
, result
,
5375 TREE_CHAIN (rest
)));
5377 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list
)))
5379 /* the left-hand operand of a comma expression is like an expression
5380 statement: we should warn if it doesn't have any side-effects,
5381 unless it was explicitly cast to (void). */
5382 if ((extra_warnings
|| warn_unused
)
5383 && !(TREE_CODE (TREE_VALUE(list
)) == CONVERT_EXPR
5384 && TREE_TYPE (TREE_VALUE(list
)) == void_type_node
))
5385 warning("left-hand operand of comma expression has no effect");
5387 #if 0 /* this requires a gcc backend patch to export warn_if_unused_value */
5388 else if (warn_unused
)
5389 warn_if_unused_value (TREE_VALUE(list
));
5392 return build_compound_expr
5393 (expr_tree_cons (NULL_TREE
, TREE_VALUE (list
),
5394 build_expr_list (NULL_TREE
,
5395 build_x_compound_expr (rest
))));
5398 /* Given a list of expressions, return a compound expression
5399 that performs them all and returns the value of the last of them. */
5402 build_compound_expr (list
)
5407 if (TREE_READONLY_DECL_P (TREE_VALUE (list
)))
5408 TREE_VALUE (list
) = decl_constant_value (TREE_VALUE (list
));
5410 if (TREE_CHAIN (list
) == 0)
5412 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5413 Strip such NOP_EXPRs, since LIST is used in non-lvalue context. */
5414 if (TREE_CODE (list
) == NOP_EXPR
5415 && TREE_TYPE (list
) == TREE_TYPE (TREE_OPERAND (list
, 0)))
5416 list
= TREE_OPERAND (list
, 0);
5418 /* Convert arrays to pointers. */
5419 if (TREE_CODE (TREE_TYPE (TREE_VALUE (list
))) == ARRAY_TYPE
)
5420 return default_conversion (TREE_VALUE (list
));
5422 return TREE_VALUE (list
);
5425 rest
= build_compound_expr (TREE_CHAIN (list
));
5427 /* When pedantic, a compound expression cannot be a constant expression. */
5428 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list
)) && ! pedantic
)
5431 return build (COMPOUND_EXPR
, TREE_TYPE (rest
),
5432 break_out_cleanups (TREE_VALUE (list
)), rest
);
5436 build_static_cast (type
, expr
)
5442 if (type
== error_mark_node
|| expr
== error_mark_node
)
5443 return error_mark_node
;
5445 if (TREE_CODE (expr
) == OFFSET_REF
)
5446 expr
= resolve_offset_ref (expr
);
5448 if (processing_template_decl
)
5450 tree t
= build_min (STATIC_CAST_EXPR
, copy_to_permanent (type
),
5455 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5456 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5457 if (TREE_CODE (type
) != REFERENCE_TYPE
5458 && TREE_CODE (expr
) == NOP_EXPR
5459 && TREE_TYPE (expr
) == TREE_TYPE (TREE_OPERAND (expr
, 0)))
5460 expr
= TREE_OPERAND (expr
, 0);
5462 if (TREE_CODE (type
) == VOID_TYPE
)
5463 return build1 (CONVERT_EXPR
, type
, expr
);
5465 if (type_unknown_p (expr
))
5467 expr
= instantiate_type (type
, expr
, 1);
5468 if (expr
== error_mark_node
)
5469 return error_mark_node
;
5472 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5473 return (convert_from_reference
5474 (convert_to_reference (type
, expr
, CONV_STATIC
|CONV_IMPLICIT
,
5475 LOOKUP_COMPLAIN
, NULL_TREE
)));
5477 if (IS_AGGR_TYPE (type
))
5478 return build_cplus_new
5479 (type
, (build_method_call
5480 (NULL_TREE
, ctor_identifier
, build_expr_list (NULL_TREE
, expr
),
5481 TYPE_BINFO (type
), LOOKUP_NORMAL
)));
5483 expr
= decay_conversion (expr
);
5484 intype
= TREE_TYPE (expr
);
5486 /* FIXME handle casting to array type. */
5489 if (can_convert_arg (type
, intype
, expr
))
5491 else if (TYPE_PTROB_P (type
) && TYPE_PTROB_P (intype
))
5494 if (IS_AGGR_TYPE (TREE_TYPE (type
)) && IS_AGGR_TYPE (TREE_TYPE (intype
))
5495 && (TYPE_READONLY (TREE_TYPE (type
))
5496 >= TYPE_READONLY (TREE_TYPE (intype
)))
5497 && (TYPE_VOLATILE (TREE_TYPE (type
))
5498 >= TYPE_VOLATILE (TREE_TYPE (intype
)))
5499 && (binfo
= get_binfo (TREE_TYPE (intype
), TREE_TYPE (type
), 0))
5500 && ! TREE_VIA_VIRTUAL (binfo
))
5503 else if (TYPE_PTRMEM_P (type
) && TYPE_PTRMEM_P (intype
))
5505 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
))),
5506 TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (intype
))), 1)
5507 && (TYPE_READONLY (TREE_TYPE (TREE_TYPE (type
)))
5508 >= TYPE_READONLY (TREE_TYPE (TREE_TYPE (intype
))))
5509 && (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (type
)))
5510 >= TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (intype
))))
5511 && (binfo
= get_binfo (TYPE_OFFSET_BASETYPE (TREE_TYPE (type
)),
5512 TYPE_OFFSET_BASETYPE (TREE_TYPE (intype
)), 0))
5513 && ! TREE_VIA_VIRTUAL (binfo
))
5516 else if (TREE_CODE (intype
) != BOOLEAN_TYPE
5517 && TREE_CODE (type
) != ARRAY_TYPE
5518 && TREE_CODE (type
) != FUNCTION_TYPE
5519 && can_convert (intype
, type
))
5523 return build_c_cast (type
, expr
);
5525 cp_error ("static_cast from `%T' to `%T'", intype
, type
);
5526 return error_mark_node
;
5530 build_reinterpret_cast (type
, expr
)
5535 if (type
== error_mark_node
|| expr
== error_mark_node
)
5536 return error_mark_node
;
5538 if (TREE_CODE (expr
) == OFFSET_REF
)
5539 expr
= resolve_offset_ref (expr
);
5541 if (processing_template_decl
)
5543 tree t
= build_min (REINTERPRET_CAST_EXPR
,
5544 copy_to_permanent (type
), expr
);
5548 if (TREE_CODE (type
) != REFERENCE_TYPE
)
5550 expr
= decay_conversion (expr
);
5552 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5553 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5554 if (TREE_CODE (expr
) == NOP_EXPR
5555 && TREE_TYPE (expr
) == TREE_TYPE (TREE_OPERAND (expr
, 0)))
5556 expr
= TREE_OPERAND (expr
, 0);
5559 if (type_unknown_p (expr
))
5561 expr
= instantiate_type (type
, expr
, 1);
5562 if (expr
== error_mark_node
)
5563 return error_mark_node
;
5566 intype
= TREE_TYPE (expr
);
5568 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5570 if (! real_lvalue_p (expr
))
5572 cp_error ("reinterpret_cast from `%T' rvalue to `%T'", intype
, type
);
5573 return error_mark_node
;
5575 expr
= build_unary_op (ADDR_EXPR
, expr
, 0);
5576 if (expr
!= error_mark_node
)
5577 expr
= build_reinterpret_cast
5578 (build_pointer_type (TREE_TYPE (type
)), expr
);
5579 if (expr
!= error_mark_node
)
5580 expr
= build_indirect_ref (expr
, 0);
5583 else if (comptypes (TYPE_MAIN_VARIANT (intype
), TYPE_MAIN_VARIANT (type
), 1))
5584 return build_static_cast (type
, expr
);
5586 if (TYPE_PTR_P (type
) && (TREE_CODE (intype
) == INTEGER_TYPE
5587 || TREE_CODE (intype
) == ENUMERAL_TYPE
))
5589 else if (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_PTR_P (intype
))
5591 if (TYPE_PRECISION (type
) < TYPE_PRECISION (intype
))
5592 cp_pedwarn ("reinterpret_cast from `%T' to `%T' loses precision",
5595 else if ((TYPE_PTRFN_P (type
) && TYPE_PTRFN_P (intype
))
5596 || (TYPE_PTRMEMFUNC_P (type
) && TYPE_PTRMEMFUNC_P (intype
)))
5598 if (TREE_READONLY_DECL_P (expr
))
5599 expr
= decl_constant_value (expr
);
5600 return fold (build1 (NOP_EXPR
, type
, expr
));
5602 else if ((TYPE_PTRMEM_P (type
) && TYPE_PTRMEM_P (intype
))
5603 || (TYPE_PTROBV_P (type
) && TYPE_PTROBV_P (intype
)))
5605 if (! comp_ptr_ttypes_reinterpret (TREE_TYPE (type
), TREE_TYPE (intype
)))
5606 cp_pedwarn ("reinterpret_cast from `%T' to `%T' casts away const (or volatile)",
5609 if (TREE_READONLY_DECL_P (expr
))
5610 expr
= decl_constant_value (expr
);
5611 return fold (build1 (NOP_EXPR
, type
, expr
));
5613 else if ((TYPE_PTRFN_P (type
) && TYPE_PTROBV_P (intype
))
5614 || (TYPE_PTRFN_P (type
) && TYPE_PTROBV_P (intype
)))
5616 pedwarn ("ANSI C++ forbids casting between pointers to functions and objects");
5617 if (TREE_READONLY_DECL_P (expr
))
5618 expr
= decl_constant_value (expr
);
5619 return fold (build1 (NOP_EXPR
, type
, expr
));
5623 cp_error ("reinterpret_cast from `%T' to `%T'", intype
, type
);
5624 return error_mark_node
;
5627 return cp_convert (type
, expr
);
5631 build_const_cast (type
, expr
)
5636 if (type
== error_mark_node
|| expr
== error_mark_node
)
5637 return error_mark_node
;
5639 if (TREE_CODE (expr
) == OFFSET_REF
)
5640 expr
= resolve_offset_ref (expr
);
5642 if (processing_template_decl
)
5644 tree t
= build_min (CONST_CAST_EXPR
, copy_to_permanent (type
),
5649 if (TREE_CODE (type
) != REFERENCE_TYPE
)
5651 expr
= decay_conversion (expr
);
5653 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5654 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5655 if (TREE_CODE (expr
) == NOP_EXPR
5656 && TREE_TYPE (expr
) == TREE_TYPE (TREE_OPERAND (expr
, 0)))
5657 expr
= TREE_OPERAND (expr
, 0);
5660 if (type_unknown_p (expr
))
5662 expr
= instantiate_type (type
, expr
, 1);
5663 if (expr
== error_mark_node
)
5664 return error_mark_node
;
5667 intype
= TREE_TYPE (expr
);
5669 if (comptypes (TYPE_MAIN_VARIANT (intype
), TYPE_MAIN_VARIANT (type
), 1))
5670 return build_static_cast (type
, expr
);
5671 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
5673 if (! real_lvalue_p (expr
))
5675 cp_error ("const_cast from `%T' rvalue to `%T'", intype
, type
);
5676 return error_mark_node
;
5679 if (comp_ptr_ttypes_const (TREE_TYPE (type
), intype
))
5681 expr
= build_unary_op (ADDR_EXPR
, expr
, 0);
5682 expr
= build1 (NOP_EXPR
, type
, expr
);
5683 return convert_from_reference (expr
);
5686 else if (TREE_CODE (type
) == POINTER_TYPE
5687 && TREE_CODE (intype
) == POINTER_TYPE
5688 && comp_ptr_ttypes_const (TREE_TYPE (type
), TREE_TYPE (intype
)))
5689 return cp_convert (type
, expr
);
5691 cp_error ("const_cast from `%T' to `%T'", intype
, type
);
5692 return error_mark_node
;
5695 /* Build an expression representing a cast to type TYPE of expression EXPR.
5697 ALLOW_NONCONVERTING is true if we should allow non-converting constructors
5698 when doing the cast. */
5701 build_c_cast (type
, expr
)
5704 register tree value
= expr
;
5706 if (type
== error_mark_node
|| expr
== error_mark_node
)
5707 return error_mark_node
;
5709 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5710 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5711 if (TREE_CODE (type
) != REFERENCE_TYPE
5712 && TREE_CODE (value
) == NOP_EXPR
5713 && TREE_TYPE (value
) == TREE_TYPE (TREE_OPERAND (value
, 0)))
5714 value
= TREE_OPERAND (value
, 0);
5716 if (TREE_TYPE (expr
)
5717 && TREE_CODE (TREE_TYPE (expr
)) == OFFSET_TYPE
5718 && TREE_CODE (type
) != OFFSET_TYPE
)
5719 value
= resolve_offset_ref (value
);
5721 if (TREE_CODE (type
) == ARRAY_TYPE
)
5723 /* Allow casting from T1* to T2[] because Cfront allows it.
5724 NIHCL uses it. It is not valid ANSI C however, and hence, not
5726 if (TREE_CODE (TREE_TYPE (expr
)) == POINTER_TYPE
)
5729 pedwarn ("ANSI C++ forbids casting to an array type");
5730 type
= build_pointer_type (TREE_TYPE (type
));
5734 error ("ANSI C++ forbids casting to an array type");
5735 return error_mark_node
;
5739 if (TREE_CODE (type
) == FUNCTION_TYPE
5740 || TREE_CODE (type
) == METHOD_TYPE
)
5742 cp_error ("casting to function type `%T'", type
);
5743 return error_mark_node
;
5746 if (IS_SIGNATURE (type
))
5748 error ("cast specifies signature type");
5749 return error_mark_node
;
5752 if (processing_template_decl
)
5754 tree t
= build_min (CAST_EXPR
, type
,
5755 min_tree_cons (NULL_TREE
, value
, NULL_TREE
));
5759 if (TREE_CODE (type
) == VOID_TYPE
)
5760 value
= build1 (CONVERT_EXPR
, type
, value
);
5761 else if (TREE_TYPE (value
) == NULL_TREE
5762 || type_unknown_p (value
))
5764 value
= instantiate_type (type
, value
, 1);
5766 if (value
== error_mark_node
)
5767 return error_mark_node
;
5773 /* Convert functions and arrays to pointers and
5774 convert references to their expanded types,
5775 but don't convert any other types. If, however, we are
5776 casting to a class type, there's no reason to do this: the
5777 cast will only succeed if there is a converting constructor,
5778 and the default conversions will be done at that point. In
5779 fact, doing the default conversion here is actually harmful
5783 struct S { S(const A&); };
5785 since we don't want the array-to-pointer conversion done. */
5786 if (!IS_AGGR_TYPE (type
))
5788 if (TREE_CODE (TREE_TYPE (value
)) == FUNCTION_TYPE
5789 || (TREE_CODE (TREE_TYPE (value
)) == METHOD_TYPE
5790 /* Don't do the default conversion if we want a
5791 pointer to a function. */
5792 && ! (TREE_CODE (type
) == POINTER_TYPE
5793 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
))
5794 || TREE_CODE (TREE_TYPE (value
)) == ARRAY_TYPE
5795 || TREE_CODE (TREE_TYPE (value
)) == REFERENCE_TYPE
)
5796 value
= default_conversion (value
);
5798 else if (TREE_CODE (TREE_TYPE (value
)) == REFERENCE_TYPE
)
5799 /* However, even for class types, we still need to strip away
5800 the reference type, since the call to convert_force below
5801 does not expect the input expression to be of reference
5803 value
= convert_from_reference (value
);
5805 otype
= TREE_TYPE (value
);
5807 /* Optionally warn about potentially worrisome casts. */
5810 && TREE_CODE (type
) == POINTER_TYPE
5811 && TREE_CODE (otype
) == POINTER_TYPE
)
5813 /* For C++ we make these regular warnings, rather than
5814 softening them into pedwarns. */
5815 if (TYPE_VOLATILE (TREE_TYPE (otype
))
5816 && ! TYPE_VOLATILE (TREE_TYPE (type
)))
5817 warning ("cast discards `volatile' from pointer target type");
5818 if (TYPE_READONLY (TREE_TYPE (otype
))
5819 && ! TYPE_READONLY (TREE_TYPE (type
)))
5820 warning ("cast discards `const' from pointer target type");
5823 /* Warn about possible alignment problems. */
5824 if (STRICT_ALIGNMENT
&& warn_cast_align
5825 && TREE_CODE (type
) == POINTER_TYPE
5826 && TREE_CODE (otype
) == POINTER_TYPE
5827 && TREE_CODE (TREE_TYPE (otype
)) != VOID_TYPE
5828 && TREE_CODE (TREE_TYPE (otype
)) != FUNCTION_TYPE
5829 && TYPE_ALIGN (TREE_TYPE (type
)) > TYPE_ALIGN (TREE_TYPE (otype
)))
5830 warning ("cast increases required alignment of target type");
5833 /* We should see about re-enabling these, they seem useful to
5835 if (TREE_CODE (type
) == INTEGER_TYPE
5836 && TREE_CODE (otype
) == POINTER_TYPE
5837 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
))
5838 warning ("cast from pointer to integer of different size");
5840 if (TREE_CODE (type
) == POINTER_TYPE
5841 && TREE_CODE (otype
) == INTEGER_TYPE
5842 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
)
5843 /* Don't warn about converting 0 to pointer,
5844 provided the 0 was explicit--not cast or made by folding. */
5845 && !(TREE_CODE (value
) == INTEGER_CST
&& integer_zerop (value
)))
5846 warning ("cast to pointer from integer of different size");
5849 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5850 value
= (convert_from_reference
5851 (convert_to_reference (type
, value
, CONV_C_CAST
,
5852 LOOKUP_COMPLAIN
, NULL_TREE
)));
5857 if (TREE_READONLY_DECL_P (value
))
5858 value
= decl_constant_value (value
);
5861 value
= convert_force (type
, value
, CONV_C_CAST
);
5863 /* Ignore any integer overflow caused by the cast. */
5864 if (TREE_CODE (value
) == INTEGER_CST
)
5866 TREE_OVERFLOW (value
) = TREE_OVERFLOW (ovalue
);
5867 TREE_CONSTANT_OVERFLOW (value
) = TREE_CONSTANT_OVERFLOW (ovalue
);
5872 /* Always produce some operator for an explicit cast,
5873 so we can tell (for -pedantic) that the cast is no lvalue. */
5874 if (TREE_CODE (type
) != REFERENCE_TYPE
&& value
== expr
5875 && real_lvalue_p (value
))
5876 value
= non_lvalue (value
);
5881 /* Build an assignment expression of lvalue LHS from value RHS.
5882 MODIFYCODE is the code for a binary operator that we use
5883 to combine the old value of LHS with RHS to get the new value.
5884 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
5886 C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed. */
5889 build_modify_expr (lhs
, modifycode
, rhs
)
5891 enum tree_code modifycode
;
5894 register tree result
;
5896 tree lhstype
= TREE_TYPE (lhs
);
5897 tree olhstype
= lhstype
;
5900 /* Avoid duplicate error messages from operands that had errors. */
5901 if (lhs
== error_mark_node
|| rhs
== error_mark_node
)
5902 return error_mark_node
;
5904 /* Types that aren't fully specified cannot be used in assignments. */
5905 lhs
= require_complete_type (lhs
);
5909 /* Handle assignment to signature pointers/refs. */
5911 if (TYPE_LANG_SPECIFIC (lhstype
)
5912 && (IS_SIGNATURE_POINTER (lhstype
) || IS_SIGNATURE_REFERENCE (lhstype
)))
5914 return build_signature_pointer_constructor (lhs
, rhs
);
5917 /* Handle control structure constructs used as "lvalues". */
5919 switch (TREE_CODE (lhs
))
5921 /* Handle --foo = 5; as these are valid constructs in C++ */
5922 case PREDECREMENT_EXPR
:
5923 case PREINCREMENT_EXPR
:
5924 if (TREE_SIDE_EFFECTS (TREE_OPERAND (lhs
, 0)))
5925 lhs
= build (TREE_CODE (lhs
), TREE_TYPE (lhs
),
5926 stabilize_reference (TREE_OPERAND (lhs
, 0)),
5927 TREE_OPERAND (lhs
, 1));
5928 return build (COMPOUND_EXPR
, lhstype
,
5930 build_modify_expr (TREE_OPERAND (lhs
, 0),
5933 /* Handle (a, b) used as an "lvalue". */
5935 newrhs
= build_modify_expr (TREE_OPERAND (lhs
, 1),
5937 if (newrhs
== error_mark_node
)
5938 return error_mark_node
;
5939 return build (COMPOUND_EXPR
, lhstype
,
5940 TREE_OPERAND (lhs
, 0), newrhs
);
5943 newrhs
= build_modify_expr (TREE_OPERAND (lhs
, 0), modifycode
, rhs
);
5944 if (newrhs
== error_mark_node
)
5945 return error_mark_node
;
5946 return build (COMPOUND_EXPR
, lhstype
, lhs
, newrhs
);
5948 /* Handle (a ? b : c) used as an "lvalue". */
5950 rhs
= save_expr (rhs
);
5952 /* Produce (a ? (b = rhs) : (c = rhs))
5953 except that the RHS goes through a save-expr
5954 so the code to compute it is only emitted once. */
5956 = build_conditional_expr (TREE_OPERAND (lhs
, 0),
5957 build_modify_expr (cp_convert (TREE_TYPE (lhs
), TREE_OPERAND (lhs
, 1)),
5959 build_modify_expr (cp_convert (TREE_TYPE (lhs
), TREE_OPERAND (lhs
, 2)),
5961 if (cond
== error_mark_node
)
5963 /* Make sure the code to compute the rhs comes out
5964 before the split. */
5965 return build (COMPOUND_EXPR
, TREE_TYPE (lhs
),
5966 /* Case to void to suppress warning
5967 from warn_if_unused_value. */
5968 cp_convert (void_type_node
, rhs
), cond
);
5975 if (TREE_CODE (lhs
) == OFFSET_REF
)
5977 if (TREE_OPERAND (lhs
, 0) == NULL_TREE
)
5979 /* Static class member? */
5980 tree member
= TREE_OPERAND (lhs
, 1);
5981 if (TREE_CODE (member
) == VAR_DECL
)
5985 compiler_error ("invalid static class member");
5986 return error_mark_node
;
5990 lhs
= resolve_offset_ref (lhs
);
5992 olhstype
= lhstype
= TREE_TYPE (lhs
);
5995 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
5996 && modifycode
!= INIT_EXPR
)
5998 lhs
= convert_from_reference (lhs
);
5999 olhstype
= lhstype
= TREE_TYPE (lhs
);
6002 /* If a binary op has been requested, combine the old LHS value with the RHS
6003 producing the value we should actually store into the LHS. */
6005 if (modifycode
== INIT_EXPR
)
6007 if (! IS_AGGR_TYPE (lhstype
))
6008 /* Do the default thing */;
6011 result
= build_method_call (lhs
, ctor_identifier
,
6012 build_expr_list (NULL_TREE
, rhs
),
6013 TYPE_BINFO (lhstype
), LOOKUP_NORMAL
);
6014 if (result
== NULL_TREE
)
6015 return error_mark_node
;
6019 else if (modifycode
== NOP_EXPR
)
6021 /* `operator=' is not an inheritable operator. */
6022 if (! IS_AGGR_TYPE (lhstype
))
6023 /* Do the default thing */;
6026 result
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
,
6027 lhs
, rhs
, make_node (NOP_EXPR
));
6028 if (result
== NULL_TREE
)
6029 return error_mark_node
;
6034 else if (PROMOTES_TO_AGGR_TYPE (lhstype
, REFERENCE_TYPE
))
6036 my_friendly_abort (978652);
6040 lhs
= stabilize_reference (lhs
);
6041 newrhs
= build_binary_op (modifycode
, lhs
, rhs
, 1);
6042 if (newrhs
== error_mark_node
)
6044 cp_error (" in evaluation of `%Q(%#T, %#T)'", modifycode
,
6045 TREE_TYPE (lhs
), TREE_TYPE (rhs
));
6046 return error_mark_node
;
6050 /* Handle a cast used as an "lvalue".
6051 We have already performed any binary operator using the value as cast.
6052 Now convert the result to the cast type of the lhs,
6053 and then true type of the lhs and store it there;
6054 then convert result back to the cast type to be the value
6055 of the assignment. */
6057 switch (TREE_CODE (lhs
))
6062 case FIX_TRUNC_EXPR
:
6063 case FIX_FLOOR_EXPR
:
6064 case FIX_ROUND_EXPR
:
6066 if (TREE_CODE (TREE_TYPE (newrhs
)) == ARRAY_TYPE
6067 || TREE_CODE (TREE_TYPE (newrhs
)) == FUNCTION_TYPE
6068 || TREE_CODE (TREE_TYPE (newrhs
)) == METHOD_TYPE
6069 || TREE_CODE (TREE_TYPE (newrhs
)) == OFFSET_TYPE
)
6070 newrhs
= default_conversion (newrhs
);
6072 tree inner_lhs
= TREE_OPERAND (lhs
, 0);
6075 /* WP 5.4.1: The result is an lvalue if T is a reference type,
6076 otherwise the result is an rvalue. */
6077 if (! lvalue_p (lhs
))
6078 pedwarn ("ANSI C++ forbids cast to non-reference type used as lvalue");
6080 result
= build_modify_expr (inner_lhs
, NOP_EXPR
,
6081 cp_convert (TREE_TYPE (inner_lhs
),
6082 cp_convert (lhstype
, newrhs
)));
6083 if (result
== error_mark_node
)
6085 return cp_convert (TREE_TYPE (lhs
), result
);
6092 /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
6093 Reject anything strange now. */
6095 if (!lvalue_or_else (lhs
, "assignment"))
6096 return error_mark_node
;
6098 GNU_xref_assign (lhs
);
6100 /* Warn about storing in something that is `const'. */
6101 /* For C++, don't warn if this is initialization. */
6102 if (modifycode
!= INIT_EXPR
6103 /* For assignment to `const' signature pointer/reference fields,
6104 don't warn either, we already printed a better message before. */
6105 && ! (TREE_CODE (lhs
) == COMPONENT_REF
6106 && (IS_SIGNATURE_POINTER (TREE_TYPE (TREE_OPERAND (lhs
, 0)))
6107 || IS_SIGNATURE_REFERENCE (TREE_TYPE (TREE_OPERAND (lhs
, 0)))))
6108 && (TREE_READONLY (lhs
) || TYPE_READONLY (lhstype
)
6109 /* Functions are not modifiable, even though they are
6111 || TREE_CODE (TREE_TYPE (lhs
)) == FUNCTION_TYPE
6112 || ((TREE_CODE (lhstype
) == RECORD_TYPE
6113 || TREE_CODE (lhstype
) == UNION_TYPE
)
6114 && C_TYPE_FIELDS_READONLY (lhstype
))
6115 || (TREE_CODE (lhstype
) == REFERENCE_TYPE
6116 && TYPE_READONLY (TREE_TYPE (lhstype
)))))
6117 readonly_error (lhs
, "assignment", 0);
6119 /* If storing into a structure or union member,
6120 it has probably been given type `int'.
6121 Compute the type that would go with
6122 the actual amount of storage the member occupies. */
6124 if (TREE_CODE (lhs
) == COMPONENT_REF
6125 && (TREE_CODE (lhstype
) == INTEGER_TYPE
6126 || TREE_CODE (lhstype
) == REAL_TYPE
6127 || TREE_CODE (lhstype
) == ENUMERAL_TYPE
))
6129 lhstype
= TREE_TYPE (get_unwidened (lhs
, 0));
6131 /* If storing in a field that is in actuality a short or narrower
6132 than one, we must store in the field in its actual type. */
6134 if (lhstype
!= TREE_TYPE (lhs
))
6136 lhs
= copy_node (lhs
);
6137 TREE_TYPE (lhs
) = lhstype
;
6141 /* check to see if there is an assignment to `this' */
6142 if (lhs
== current_class_ptr
)
6144 if (flag_this_is_variable
> 0
6145 && DECL_NAME (current_function_decl
) != NULL_TREE
6146 && (DECL_NAME (current_function_decl
)
6147 != constructor_name (current_class_type
)))
6148 warning ("assignment to `this' not in constructor or destructor");
6149 current_function_just_assigned_this
= 1;
6152 /* The TREE_TYPE of RHS may be TYPE_UNKNOWN. This can happen
6153 when the type of RHS is not yet known, i.e. its type
6154 is inherited from LHS. */
6155 rhs
= require_instantiated_type (lhstype
, newrhs
, error_mark_node
);
6156 if (rhs
== error_mark_node
)
6157 return error_mark_node
;
6160 if (modifycode
!= INIT_EXPR
)
6162 /* Make modifycode now either a NOP_EXPR or an INIT_EXPR. */
6163 modifycode
= NOP_EXPR
;
6164 /* Reference-bashing */
6165 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
)
6167 tree tmp
= convert_from_reference (lhs
);
6168 lhstype
= TREE_TYPE (tmp
);
6169 if (TYPE_SIZE (lhstype
) == 0)
6171 incomplete_type_error (lhs
, lhstype
);
6172 return error_mark_node
;
6177 if (TREE_CODE (TREE_TYPE (newrhs
)) == REFERENCE_TYPE
)
6179 tree tmp
= convert_from_reference (newrhs
);
6180 if (TYPE_SIZE (TREE_TYPE (tmp
)) == 0)
6182 incomplete_type_error (newrhs
, TREE_TYPE (tmp
));
6183 return error_mark_node
;
6189 if (TREE_SIDE_EFFECTS (lhs
))
6190 lhs
= stabilize_reference (lhs
);
6191 if (TREE_SIDE_EFFECTS (newrhs
))
6192 newrhs
= stabilize_reference (newrhs
);
6194 /* Convert new value to destination type. */
6196 if (TREE_CODE (lhstype
) == ARRAY_TYPE
)
6200 if (! comptypes (lhstype
, TREE_TYPE (rhs
), 0))
6202 cp_error ("incompatible types in assignment of `%T' to `%T'",
6203 TREE_TYPE (rhs
), lhstype
);
6204 return error_mark_node
;
6207 /* Allow array assignment in compiler-generated code. */
6208 if (pedantic
&& ! DECL_ARTIFICIAL (current_function_decl
))
6209 pedwarn ("ANSI C++ forbids assignment of arrays");
6211 /* Have to wrap this in RTL_EXPR for two cases:
6212 in base or member initialization and if we
6213 are a branch of a ?: operator. Since we
6214 can't easily know the latter, just do it always. */
6216 result
= make_node (RTL_EXPR
);
6218 TREE_TYPE (result
) = void_type_node
;
6219 do_pending_stack_adjust ();
6220 start_sequence_for_rtl_expr (result
);
6222 /* As a matter of principle, `start_sequence' should do this. */
6225 from_array
= TREE_CODE (TREE_TYPE (newrhs
)) == ARRAY_TYPE
6226 ? 1 + (modifycode
!= INIT_EXPR
): 0;
6227 expand_vec_init (lhs
, lhs
, array_type_nelts (lhstype
), newrhs
,
6230 do_pending_stack_adjust ();
6232 TREE_SIDE_EFFECTS (result
) = 1;
6233 RTL_EXPR_SEQUENCE (result
) = get_insns ();
6234 RTL_EXPR_RTL (result
) = const0_rtx
;
6239 if (modifycode
== INIT_EXPR
)
6241 newrhs
= convert_for_initialization (lhs
, lhstype
, newrhs
, LOOKUP_NORMAL
,
6242 "assignment", NULL_TREE
, 0);
6243 if (lhs
== DECL_RESULT (current_function_decl
))
6245 if (DECL_INITIAL (lhs
))
6246 warning ("return value from function receives multiple initializations");
6247 DECL_INITIAL (lhs
) = newrhs
;
6252 /* Avoid warnings on enum bit fields. */
6253 if (TREE_CODE (olhstype
) == ENUMERAL_TYPE
6254 && TREE_CODE (lhstype
) == INTEGER_TYPE
)
6256 newrhs
= convert_for_assignment (olhstype
, newrhs
, "assignment",
6258 newrhs
= convert_force (lhstype
, newrhs
, 0);
6261 newrhs
= convert_for_assignment (lhstype
, newrhs
, "assignment",
6263 if (TREE_CODE (newrhs
) == CALL_EXPR
6264 && TYPE_NEEDS_CONSTRUCTING (lhstype
))
6265 newrhs
= build_cplus_new (lhstype
, newrhs
);
6267 /* Can't initialize directly from a TARGET_EXPR, since that would
6268 cause the lhs to be constructed twice, and possibly result in
6269 accidental self-initialization. So we force the TARGET_EXPR to be
6270 expanded without a target. */
6271 if (TREE_CODE (newrhs
) == TARGET_EXPR
)
6272 newrhs
= build (COMPOUND_EXPR
, TREE_TYPE (newrhs
), newrhs
,
6273 TREE_OPERAND (newrhs
, 0));
6276 if (newrhs
== error_mark_node
)
6277 return error_mark_node
;
6279 if (TREE_CODE (newrhs
) == COND_EXPR
)
6282 tree cond
= TREE_OPERAND (newrhs
, 0);
6284 if (TREE_SIDE_EFFECTS (lhs
))
6285 cond
= build_compound_expr (tree_cons
6287 build_expr_list (NULL_TREE
, cond
)));
6289 /* Cannot have two identical lhs on this one tree (result) as preexpand
6290 calls will rip them out and fill in RTL for them, but when the
6291 rtl is generated, the calls will only be in the first side of the
6292 condition, not on both, or before the conditional jump! (mrs) */
6293 lhs1
= break_out_calls (lhs
);
6296 /* If there's no change, the COND_EXPR behaves like any other rhs. */
6297 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
6298 lhstype
, lhs
, newrhs
);
6301 tree result_type
= TREE_TYPE (newrhs
);
6302 /* We have to convert each arm to the proper type because the
6303 types may have been munged by constant folding. */
6305 = build (COND_EXPR
, result_type
, cond
,
6306 build_modify_expr (lhs
, modifycode
,
6307 cp_convert (result_type
,
6308 TREE_OPERAND (newrhs
, 1))),
6309 build_modify_expr (lhs1
, modifycode
,
6310 cp_convert (result_type
,
6311 TREE_OPERAND (newrhs
, 2))));
6315 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
6316 lhstype
, lhs
, newrhs
);
6318 TREE_SIDE_EFFECTS (result
) = 1;
6320 /* If we got the LHS in a different type for storing in,
6321 convert the result back to the nominal type of LHS
6322 so that the value we return always has the same type
6323 as the LHS argument. */
6325 if (olhstype
== TREE_TYPE (result
))
6327 /* Avoid warnings converting integral types back into enums
6328 for enum bit fields. */
6329 if (TREE_CODE (TREE_TYPE (result
)) == INTEGER_TYPE
6330 && TREE_CODE (olhstype
) == ENUMERAL_TYPE
)
6332 result
= build (COMPOUND_EXPR
, olhstype
, result
, olhs
);
6333 TREE_NO_UNUSED_WARNING (result
) = 1;
6336 return convert_for_assignment (olhstype
, result
, "assignment",
6341 build_x_modify_expr (lhs
, modifycode
, rhs
)
6343 enum tree_code modifycode
;
6346 if (processing_template_decl
)
6347 return build_min_nt (MODOP_EXPR
, lhs
,
6348 build_min_nt (modifycode
, NULL_TREE
, NULL_TREE
), rhs
);
6350 if (modifycode
!= NOP_EXPR
)
6352 tree rval
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
, lhs
, rhs
,
6353 make_node (modifycode
));
6357 return build_modify_expr (lhs
, modifycode
, rhs
);
6361 /* Get difference in deltas for different pointer to member function
6362 types. Return integer_zero_node, if FROM cannot be converted to a
6363 TO type. If FORCE is true, then allow reverse conversions as well. */
6366 get_delta_difference (from
, to
, force
)
6370 tree delta
= integer_zero_node
;
6376 /* Should get_base_distance here, so we can check if any thing along the
6377 path is virtual, and we need to make sure we stay
6378 inside the real binfos when going through virtual bases.
6379 Maybe we should replace virtual bases with
6380 binfo_member (...CLASSTYPE_VBASECLASSES...)... (mrs) */
6381 binfo
= get_binfo (from
, to
, 1);
6382 if (binfo
== error_mark_node
)
6384 error (" in pointer to member function conversion");
6391 error_not_base_type (from
, to
);
6392 error (" in pointer to member conversion");
6395 binfo
= get_binfo (to
, from
, 1);
6396 if (binfo
== 0 || binfo
== error_mark_node
)
6398 if (TREE_VIA_VIRTUAL (binfo
))
6400 binfo
= binfo_member (BINFO_TYPE (binfo
),
6401 CLASSTYPE_VBASECLASSES (from
));
6402 cp_warning ("pointer to member cast to virtual base `%T'",
6403 BINFO_TYPE (binfo
));
6404 warning (" will only work if you are very careful");
6406 delta
= BINFO_OFFSET (binfo
);
6407 delta
= cp_convert (ptrdiff_type_node
, delta
);
6409 return build_binary_op (MINUS_EXPR
,
6414 if (TREE_VIA_VIRTUAL (binfo
))
6418 cp_warning ("pointer to member cast from virtual base `%T'",
6419 BINFO_TYPE (binfo
));
6420 warning (" will only work if you are very careful");
6423 cp_error ("pointer to member conversion from virtual base `%T'",
6424 BINFO_TYPE (binfo
));
6427 return BINFO_OFFSET (binfo
);
6431 build_ptrmemfunc1 (type
, delta
, idx
, pfn
, delta2
)
6432 tree type
, delta
, idx
, pfn
, delta2
;
6437 /* This is the old way we did it. We want to avoid calling
6438 digest_init, so that it can give an error if we use { } when
6439 initializing a pointer to member function. */
6443 u
= build_nt (CONSTRUCTOR
, NULL_TREE
,
6444 expr_tree_cons (pfn_identifier
, pfn
, NULL_TREE
));
6448 u
= build_nt (CONSTRUCTOR
, NULL_TREE
,
6449 expr_tree_cons (delta2_identifier
, delta2
, NULL_TREE
));
6452 u
= build_nt (CONSTRUCTOR
, NULL_TREE
,
6453 expr_tree_cons (NULL_TREE
, delta
,
6454 expr_tree_cons (NULL_TREE
, idx
,
6455 expr_tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6457 return digest_init (type
, u
, (tree
*)0);
6459 tree delta_field
, idx_field
, pfn_or_delta2_field
, pfn_field
, delta2_field
;
6461 int allconstant
, allsimple
;
6463 delta_field
= TYPE_FIELDS (type
);
6464 idx_field
= TREE_CHAIN (delta_field
);
6465 pfn_or_delta2_field
= TREE_CHAIN (idx_field
);
6466 subtype
= TREE_TYPE (pfn_or_delta2_field
);
6467 pfn_field
= TYPE_FIELDS (subtype
);
6468 delta2_field
= TREE_CHAIN (pfn_field
);
6472 allconstant
= TREE_CONSTANT (pfn
);
6473 allsimple
= !! initializer_constant_valid_p (pfn
, TREE_TYPE (pfn
));
6474 u
= expr_tree_cons (pfn_field
, pfn
, NULL_TREE
);
6478 delta2
= convert_and_check (delta_type_node
, delta2
);
6479 allconstant
= TREE_CONSTANT (delta2
);
6480 allsimple
= !! initializer_constant_valid_p (delta2
, TREE_TYPE (delta2
));
6481 u
= expr_tree_cons (delta2_field
, delta2
, NULL_TREE
);
6484 delta
= convert_and_check (delta_type_node
, delta
);
6485 idx
= convert_and_check (delta_type_node
, idx
);
6487 allconstant
= allconstant
&& TREE_CONSTANT (delta
) && TREE_CONSTANT (idx
);
6488 allsimple
= allsimple
6489 && initializer_constant_valid_p (delta
, TREE_TYPE (delta
))
6490 && initializer_constant_valid_p (idx
, TREE_TYPE (idx
));
6492 u
= build (CONSTRUCTOR
, subtype
, NULL_TREE
, u
);
6493 u
= expr_tree_cons (delta_field
, delta
,
6494 expr_tree_cons (idx_field
, idx
,
6495 expr_tree_cons (pfn_or_delta2_field
, u
, NULL_TREE
)));
6496 u
= build (CONSTRUCTOR
, type
, NULL_TREE
, u
);
6497 TREE_CONSTANT (u
) = allconstant
;
6498 TREE_STATIC (u
) = allconstant
&& allsimple
;
6503 /* Build a constructor for a pointer to member function. It can be
6504 used to initialize global variables, local variable, or used
6505 as a value in expressions. TYPE is the POINTER to METHOD_TYPE we
6508 If FORCE is non-zero, then force this conversion, even if
6509 we would rather not do it. Usually set when using an explicit
6512 Return error_mark_node, if something goes wrong. */
6515 build_ptrmemfunc (type
, pfn
, force
)
6519 tree idx
= integer_zero_node
;
6520 tree delta
= integer_zero_node
;
6521 tree delta2
= integer_zero_node
;
6523 tree npfn
= NULL_TREE
;
6525 /* Handle multiple conversions of pointer to member functions. */
6526 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (pfn
)))
6528 tree ndelta
, ndelta2
;
6532 /* Is is already the right type? */
6533 if (type
== TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))
6536 pfn_type
= TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
));
6538 && comp_target_types (type
, pfn_type
, 1) != 1)
6539 cp_error ("conversion to `%T' from `%T'", type
, pfn_type
);
6541 ndelta
= cp_convert (ptrdiff_type_node
, build_component_ref (pfn
, delta_identifier
, NULL_TREE
, 0));
6542 ndelta2
= cp_convert (ptrdiff_type_node
, DELTA2_FROM_PTRMEMFUNC (pfn
));
6543 idx
= build_component_ref (pfn
, index_identifier
, NULL_TREE
, 0);
6545 n
= get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (pfn_type
)),
6546 TYPE_METHOD_BASETYPE (TREE_TYPE (type
)),
6549 delta
= build_binary_op (PLUS_EXPR
, ndelta
, n
, 1);
6550 delta2
= build_binary_op (PLUS_EXPR
, ndelta2
, n
, 1);
6551 e1
= fold (build (GT_EXPR
, boolean_type_node
, idx
, integer_zero_node
));
6553 e2
= build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type
), delta
, idx
,
6556 pfn
= PFN_FROM_PTRMEMFUNC (pfn
);
6557 npfn
= build1 (NOP_EXPR
, type
, pfn
);
6558 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6560 e3
= build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type
), delta
, idx
, npfn
,
6562 return build_conditional_expr (e1
, e2
, e3
);
6565 /* Handle null pointer to member function conversions. */
6566 if (integer_zerop (pfn
))
6568 pfn
= build_c_cast (type
, integer_zero_node
);
6569 return build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type
),
6570 integer_zero_node
, integer_zero_node
,
6574 if (TREE_CODE (pfn
) == TREE_LIST
6575 || (TREE_CODE (pfn
) == ADDR_EXPR
6576 && TREE_CODE (TREE_OPERAND (pfn
, 0)) == TREE_LIST
))
6577 return instantiate_type (type
, pfn
, 1);
6580 && comp_target_types (type
, TREE_TYPE (pfn
), 0) != 1)
6581 cp_error ("conversion to `%T' from `%T'", type
, TREE_TYPE (pfn
));
6583 /* Allow pointer to member conversions here. */
6584 delta
= get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TREE_TYPE (pfn
))),
6585 TYPE_METHOD_BASETYPE (TREE_TYPE (type
)),
6587 delta2
= build_binary_op (PLUS_EXPR
, delta2
, delta
, 1);
6589 if (TREE_CODE (TREE_OPERAND (pfn
, 0)) != FUNCTION_DECL
)
6590 warning ("assuming pointer to member function is non-virtual");
6592 if (TREE_CODE (TREE_OPERAND (pfn
, 0)) == FUNCTION_DECL
6593 && DECL_VINDEX (TREE_OPERAND (pfn
, 0)))
6595 /* Find the offset to the vfield pointer in the object. */
6596 vfield_offset
= get_binfo (DECL_CONTEXT (TREE_OPERAND (pfn
, 0)),
6597 DECL_CLASS_CONTEXT (TREE_OPERAND (pfn
, 0)),
6599 vfield_offset
= get_vfield_offset (vfield_offset
);
6600 delta2
= size_binop (PLUS_EXPR
, vfield_offset
, delta2
);
6602 /* Map everything down one to make room for the null pointer to member. */
6603 idx
= size_binop (PLUS_EXPR
,
6604 DECL_VINDEX (TREE_OPERAND (pfn
, 0)),
6609 idx
= size_binop (MINUS_EXPR
, integer_zero_node
, integer_one_node
);
6611 if (type
== TREE_TYPE (pfn
))
6617 npfn
= build1 (NOP_EXPR
, type
, pfn
);
6618 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6622 return build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type
), delta
, idx
, npfn
, delta2
);
6625 /* Convert value RHS to type TYPE as preparation for an assignment
6626 to an lvalue of type TYPE.
6627 The real work of conversion is done by `convert'.
6628 The purpose of this function is to generate error messages
6629 for assignments that are not allowed in C.
6630 ERRTYPE is a string to use in error messages:
6631 "assignment", "return", etc.
6633 C++: attempts to allow `convert' to find conversions involving
6634 implicit type conversion between aggregate and scalar types
6635 as per 8.5.6 of C++ manual. Does not randomly dereference
6636 pointers to aggregates! */
6639 convert_for_assignment (type
, rhs
, errtype
, fndecl
, parmnum
)
6645 register enum tree_code codel
= TREE_CODE (type
);
6646 register tree rhstype
;
6647 register enum tree_code coder
= TREE_CODE (TREE_TYPE (rhs
));
6649 /* Issue warnings about peculiar, but legal, uses of NULL. */
6650 if (ARITHMETIC_TYPE_P (type
) && rhs
== null_node
)
6651 cp_warning ("converting NULL to non-pointer type");
6653 if (coder
== UNKNOWN_TYPE
)
6654 rhs
= instantiate_type (type
, rhs
, 1);
6656 if (coder
== ERROR_MARK
)
6657 return error_mark_node
;
6659 if (codel
== OFFSET_TYPE
)
6661 type
= TREE_TYPE (type
);
6662 codel
= TREE_CODE (type
);
6665 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
6666 if (TREE_CODE (rhs
) == NON_LVALUE_EXPR
)
6667 rhs
= TREE_OPERAND (rhs
, 0);
6669 if (rhs
== error_mark_node
)
6670 return error_mark_node
;
6672 if (TREE_CODE (rhs
) == TREE_LIST
&& TREE_VALUE (rhs
) == error_mark_node
)
6673 return error_mark_node
;
6675 if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
6677 rhs
= resolve_offset_ref (rhs
);
6678 if (rhs
== error_mark_node
)
6679 return error_mark_node
;
6680 rhstype
= TREE_TYPE (rhs
);
6681 coder
= TREE_CODE (rhstype
);
6684 if (TREE_CODE (TREE_TYPE (rhs
)) == ARRAY_TYPE
6685 || TREE_CODE (TREE_TYPE (rhs
)) == FUNCTION_TYPE
6686 || TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
6687 rhs
= default_conversion (rhs
);
6688 else if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
6689 rhs
= convert_from_reference (rhs
);
6691 rhstype
= TREE_TYPE (rhs
);
6692 coder
= TREE_CODE (rhstype
);
6694 /* This should no longer change types on us. */
6695 if (TREE_CODE (rhs
) == CONST_DECL
)
6696 rhs
= DECL_INITIAL (rhs
);
6697 else if (TREE_READONLY_DECL_P (rhs
))
6698 rhs
= decl_constant_value (rhs
);
6700 if (comptypes (type
, rhstype
, 1))
6702 overflow_warning (rhs
);
6706 if (coder
== VOID_TYPE
)
6708 error ("void value not ignored as it ought to be");
6709 return error_mark_node
;
6711 /* Arithmetic types all interconvert. */
6712 if ((codel
== INTEGER_TYPE
|| codel
== REAL_TYPE
|| codel
== BOOLEAN_TYPE
6713 || codel
== COMPLEX_TYPE
)
6714 && (coder
== INTEGER_TYPE
|| coder
== REAL_TYPE
|| coder
== BOOLEAN_TYPE
6715 || coder
== COMPLEX_TYPE
))
6717 /* But we should warn if assigning REAL_TYPE to INTEGER_TYPE. */
6718 if (coder
== REAL_TYPE
&& codel
== INTEGER_TYPE
)
6721 cp_warning ("`%T' used for argument %P of `%D'",
6722 rhstype
, parmnum
, fndecl
);
6724 cp_warning ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6726 /* And we should warn if assigning a negative value to
6727 an unsigned variable. */
6728 else if (TREE_UNSIGNED (type
) && codel
!= BOOLEAN_TYPE
)
6730 if (TREE_CODE (rhs
) == INTEGER_CST
6731 && TREE_NEGATED_INT (rhs
))
6734 cp_warning ("negative value `%E' passed as argument %P of `%D'",
6735 rhs
, parmnum
, fndecl
);
6737 cp_warning ("%s of negative value `%E' to `%T'",
6738 errtype
, rhs
, type
);
6740 overflow_warning (rhs
);
6741 if (TREE_CONSTANT (rhs
))
6745 return convert_and_check (type
, rhs
);
6747 /* Conversions involving enums. */
6748 else if ((codel
== ENUMERAL_TYPE
6749 && (INTEGRAL_CODE_P (coder
) || coder
== REAL_TYPE
))
6750 || (coder
== ENUMERAL_TYPE
6751 && (INTEGRAL_CODE_P (codel
) || codel
== REAL_TYPE
)))
6753 return ocp_convert (type
, rhs
, CONV_IMPLICIT
, LOOKUP_NORMAL
);
6755 /* Conversions among pointers */
6756 else if (codel
== POINTER_TYPE
6757 && (coder
== POINTER_TYPE
6758 || (coder
== RECORD_TYPE
6759 && (IS_SIGNATURE_POINTER (rhstype
)
6760 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6762 register tree ttl
= TREE_TYPE (type
);
6766 if (coder
== RECORD_TYPE
)
6768 rhs
= build_optr_ref (rhs
);
6769 rhstype
= TREE_TYPE (rhs
);
6771 ttr
= TREE_TYPE (rhstype
);
6773 /* If both pointers are of aggregate type, then we
6774 can give better error messages, and save some work
6776 if (TREE_CODE (ttl
) == RECORD_TYPE
&& TREE_CODE (ttr
) == RECORD_TYPE
)
6780 if (TYPE_MAIN_VARIANT (ttl
) == TYPE_MAIN_VARIANT (ttr
)
6781 || type
== class_star_type_node
6782 || rhstype
== class_star_type_node
)
6783 binfo
= TYPE_BINFO (ttl
);
6785 binfo
= get_binfo (ttl
, ttr
, 1);
6787 if (binfo
== error_mark_node
)
6788 return error_mark_node
;
6790 return error_not_base_type (ttl
, ttr
);
6792 if (! TYPE_READONLY (ttl
) && TYPE_READONLY (ttr
))
6795 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6796 rhstype
, parmnum
, fndecl
);
6798 cp_pedwarn ("%s to `%T' from `%T' discards const",
6799 errtype
, type
, rhstype
);
6801 if (! TYPE_VOLATILE (ttl
) && TYPE_VOLATILE (ttr
))
6804 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6805 rhstype
, parmnum
, fndecl
);
6807 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6808 errtype
, type
, rhstype
);
6812 /* Any non-function converts to a [const][volatile] void *
6813 and vice versa; otherwise, targets must be the same.
6814 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
6815 else if (TYPE_MAIN_VARIANT (ttl
) == void_type_node
6816 || TYPE_MAIN_VARIANT (ttr
) == void_type_node
6817 || (ctt
= comp_target_types (type
, rhstype
, 1))
6818 || (unsigned_type (TYPE_MAIN_VARIANT (ttl
))
6819 == unsigned_type (TYPE_MAIN_VARIANT (ttr
))))
6821 /* ARM $4.8, commentary on p39. */
6822 if (TYPE_MAIN_VARIANT (ttl
) == void_type_node
6823 && TREE_CODE (ttr
) == OFFSET_TYPE
)
6825 cp_error ("no standard conversion from `%T' to `void *'", ttr
);
6826 return error_mark_node
;
6829 if (ctt
< 0 && TYPE_MAIN_VARIANT (ttl
) != TYPE_MAIN_VARIANT (ttr
))
6830 cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
6833 if (TYPE_MAIN_VARIANT (ttl
) != void_type_node
6834 && TYPE_MAIN_VARIANT (ttr
) == void_type_node
6835 && ! null_ptr_cst_p (rhs
))
6837 if (coder
== RECORD_TYPE
)
6838 cp_pedwarn ("implicit conversion of signature pointer to type `%T'",
6841 pedwarn ("ANSI C++ forbids implicit conversion from `void *' in %s",
6844 /* Const and volatile mean something different for function types,
6845 so the usual warnings are not appropriate. */
6846 else if ((TREE_CODE (ttr
) != FUNCTION_TYPE
&& TREE_CODE (ttr
) != METHOD_TYPE
)
6847 || (TREE_CODE (ttl
) != FUNCTION_TYPE
&& TREE_CODE (ttl
) != METHOD_TYPE
))
6849 if (TREE_CODE (ttl
) == OFFSET_TYPE
6850 && binfo_member (TYPE_OFFSET_BASETYPE (ttr
),
6851 CLASSTYPE_VBASECLASSES (TYPE_OFFSET_BASETYPE (ttl
))))
6853 error ("%s between pointer to members converting across virtual baseclasses", errtype
);
6854 return error_mark_node
;
6856 else if (! TYPE_READONLY (ttl
) && TYPE_READONLY (ttr
))
6858 if (string_conv_p (type
, rhs
, 1))
6859 /* converting from string constant to char *, OK. */;
6861 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6862 rhstype
, parmnum
, fndecl
);
6864 cp_pedwarn ("%s to `%T' from `%T' discards const",
6865 errtype
, type
, rhstype
);
6867 else if (! TYPE_VOLATILE (ttl
) && TYPE_VOLATILE (ttr
))
6870 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6871 rhstype
, parmnum
, fndecl
);
6873 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6874 errtype
, type
, rhstype
);
6876 else if (TREE_CODE (ttl
) == TREE_CODE (ttr
)
6877 && ! comp_target_types (type
, rhstype
, 1))
6880 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signedness",
6881 rhstype
, parmnum
, fndecl
);
6883 cp_pedwarn ("%s to `%T' from `%T' changes signedness",
6884 errtype
, type
, rhstype
);
6890 int add_quals
= 0, const_parity
= 0, volatile_parity
= 0;
6892 int unsigned_parity
;
6895 /* This code is basically a duplicate of comp_ptr_ttypes_real. */
6896 for (; ; ttl
= TREE_TYPE (ttl
), ttr
= TREE_TYPE (ttr
))
6899 const_parity
|= (TYPE_READONLY (ttl
) < TYPE_READONLY (ttr
));
6900 volatile_parity
|= (TYPE_VOLATILE (ttl
) < TYPE_VOLATILE (ttr
));
6903 && (TYPE_READONLY (ttl
) > TYPE_READONLY (ttr
)
6904 || TYPE_VOLATILE (ttl
) > TYPE_VOLATILE (ttr
)))
6906 left_const
&= TYPE_READONLY (ttl
);
6908 if (TREE_CODE (ttl
) != POINTER_TYPE
6909 || TREE_CODE (ttr
) != POINTER_TYPE
)
6912 unsigned_parity
= TREE_UNSIGNED (ttl
) - TREE_UNSIGNED (ttr
);
6913 if (unsigned_parity
)
6915 if (TREE_UNSIGNED (ttl
))
6916 ttr
= unsigned_type (ttr
);
6918 ttl
= unsigned_type (ttl
);
6921 if (comp_target_types (ttl
, ttr
, nptrs
) > 0)
6926 cp_pedwarn ("passing `%T' as argument %P of `%D' adds cv-quals without intervening `const'",
6927 rhstype
, parmnum
, fndecl
);
6929 cp_pedwarn ("%s to `%T' from `%T' adds cv-quals without intervening `const'",
6930 errtype
, type
, rhstype
);
6935 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6936 rhstype
, parmnum
, fndecl
);
6938 cp_pedwarn ("%s to `%T' from `%T' discards const",
6939 errtype
, type
, rhstype
);
6941 if (volatile_parity
)
6944 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6945 rhstype
, parmnum
, fndecl
);
6947 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6948 errtype
, type
, rhstype
);
6950 if (unsigned_parity
> 0)
6953 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signed to unsigned",
6954 rhstype
, parmnum
, fndecl
);
6956 cp_pedwarn ("%s to `%T' from `%T' changes signed to unsigned",
6957 errtype
, type
, rhstype
);
6959 else if (unsigned_parity
< 0)
6962 cp_pedwarn ("passing `%T' as argument %P of `%D' changes unsigned to signed",
6963 rhstype
, parmnum
, fndecl
);
6965 cp_pedwarn ("%s to `%T' from `%T' changes unsigned to signed",
6966 errtype
, type
, rhstype
);
6969 /* C++ is not so friendly about converting function and
6970 member function pointers as C. Emit warnings here. */
6971 if (TREE_CODE (ttl
) == FUNCTION_TYPE
6972 || TREE_CODE (ttl
) == METHOD_TYPE
)
6973 if (! comptypes (ttl
, ttr
, 0))
6975 warning ("conflicting function types in %s:", errtype
);
6976 cp_warning ("\t`%T' != `%T'", type
, rhstype
);
6982 cp_error ("passing `%T' as argument %P of `%D'",
6983 rhstype
, parmnum
, fndecl
);
6985 cp_error ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6986 return error_mark_node
;
6989 return cp_convert (type
, rhs
);
6991 else if (codel
== POINTER_TYPE
&& coder
== INTEGER_TYPE
)
6993 /* An explicit constant 0 can convert to a pointer,
6994 but not a 0 that results from casting or folding. */
6995 if (! (TREE_CODE (rhs
) == INTEGER_CST
&& integer_zerop (rhs
)))
6998 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6999 rhstype
, parmnum
, fndecl
);
7001 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
7002 errtype
, type
, rhstype
);
7004 return cp_convert (type
, rhs
);
7006 else if (codel
== INTEGER_TYPE
7007 && (coder
== POINTER_TYPE
7008 || (coder
== RECORD_TYPE
7009 && (IS_SIGNATURE_POINTER (rhstype
)
7010 || TYPE_PTRMEMFUNC_FLAG (rhstype
)
7011 || IS_SIGNATURE_REFERENCE (rhstype
)))))
7014 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
7015 rhstype
, parmnum
, fndecl
);
7017 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
7018 errtype
, type
, rhstype
);
7019 return cp_convert (type
, rhs
);
7021 else if (codel
== BOOLEAN_TYPE
7022 && (coder
== POINTER_TYPE
7023 || (coder
== RECORD_TYPE
7024 && (IS_SIGNATURE_POINTER (rhstype
)
7025 || TYPE_PTRMEMFUNC_FLAG (rhstype
)
7026 || IS_SIGNATURE_REFERENCE (rhstype
)))))
7027 return cp_convert (type
, rhs
);
7030 else if (((coder
== POINTER_TYPE
7031 && TREE_CODE (TREE_TYPE (rhstype
)) == METHOD_TYPE
)
7032 || integer_zerop (rhs
)
7033 || TYPE_PTRMEMFUNC_P (rhstype
))
7034 && TYPE_PTRMEMFUNC_P (type
))
7036 tree ttl
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
7037 tree ttr
= (TYPE_PTRMEMFUNC_P (rhstype
)
7038 ? TYPE_PTRMEMFUNC_FN_TYPE (rhstype
)
7040 int ctt
= (TREE_CODE (rhstype
) == INTEGER_TYPE
? 1
7041 : comp_target_types (ttl
, ttr
, 1));
7044 cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
7047 cp_error ("%s to `%T' from `%T'", errtype
, ttl
, ttr
);
7049 /* compatible pointer to member functions. */
7050 return build_ptrmemfunc (ttl
, rhs
, 0);
7052 else if (codel
== ERROR_MARK
|| coder
== ERROR_MARK
)
7053 return error_mark_node
;
7055 /* This should no longer happen. References are initialized via
7056 `convert_for_initialization'. They should otherwise be
7057 bashed before coming here. */
7058 else if (codel
== REFERENCE_TYPE
)
7059 my_friendly_abort (317);
7060 else if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (TREE_TYPE (rhs
)))
7062 tree nrhs
= build1 (NOP_EXPR
, type
, rhs
);
7063 TREE_CONSTANT (nrhs
) = TREE_CONSTANT (rhs
);
7066 else if (TYPE_HAS_CONSTRUCTOR (type
) || IS_AGGR_TYPE (TREE_TYPE (rhs
)))
7067 return cp_convert (type
, rhs
);
7068 /* Handle anachronistic conversions from (::*)() to cv void* or (*)(). */
7069 else if (TREE_CODE (type
) == POINTER_TYPE
7070 && (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
7071 || TYPE_MAIN_VARIANT (TREE_TYPE (type
)) == void_type_node
)
7073 && TYPE_PTRMEMFUNC_P (TREE_TYPE (rhs
)))
7074 return cp_convert (type
, rhs
);
7076 cp_error ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
7077 return error_mark_node
;
7080 /* Convert RHS to be of type TYPE.
7081 If EXP is non-zero, it is the target of the initialization.
7082 ERRTYPE is a string to use in error messages.
7084 Two major differences between the behavior of
7085 `convert_for_assignment' and `convert_for_initialization'
7086 are that references are bashed in the former, while
7087 copied in the latter, and aggregates are assigned in
7088 the former (operator=) while initialized in the
7091 If using constructor make sure no conversion operator exists, if one does
7092 exist, an ambiguity exists.
7094 If flags doesn't include LOOKUP_COMPLAIN, don't complain about anything. */
7097 convert_for_initialization (exp
, type
, rhs
, flags
, errtype
, fndecl
, parmnum
)
7098 tree exp
, type
, rhs
;
7104 register enum tree_code codel
= TREE_CODE (type
);
7105 register tree rhstype
;
7106 register enum tree_code coder
;
7108 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
7109 Strip such NOP_EXPRs, since RHS is used in non-lvalue context. */
7110 if (TREE_CODE (rhs
) == NOP_EXPR
7111 && TREE_TYPE (rhs
) == TREE_TYPE (TREE_OPERAND (rhs
, 0))
7112 && codel
!= REFERENCE_TYPE
)
7113 rhs
= TREE_OPERAND (rhs
, 0);
7115 if (rhs
== error_mark_node
7116 || (TREE_CODE (rhs
) == TREE_LIST
&& TREE_VALUE (rhs
) == error_mark_node
))
7117 return error_mark_node
;
7119 if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
7121 rhs
= resolve_offset_ref (rhs
);
7122 if (rhs
== error_mark_node
)
7123 return error_mark_node
;
7126 if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
7127 rhs
= convert_from_reference (rhs
);
7129 if ((TREE_CODE (TREE_TYPE (rhs
)) == ARRAY_TYPE
7130 && TREE_CODE (type
) != ARRAY_TYPE
7131 && (TREE_CODE (type
) != REFERENCE_TYPE
7132 || TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
))
7133 || TREE_CODE (TREE_TYPE (rhs
)) == FUNCTION_TYPE
7134 || TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
7135 rhs
= default_conversion (rhs
);
7137 rhstype
= TREE_TYPE (rhs
);
7138 coder
= TREE_CODE (rhstype
);
7140 if (coder
== UNKNOWN_TYPE
)
7142 rhs
= instantiate_type (type
, rhs
, 1);
7143 rhstype
= TREE_TYPE (rhs
);
7144 coder
= TREE_CODE (rhstype
);
7147 if (coder
== ERROR_MARK
)
7148 return error_mark_node
;
7150 /* We accept references to incomplete types, so we can
7151 return here before checking if RHS is of complete type. */
7153 if (codel
== REFERENCE_TYPE
)
7155 /* This should eventually happen in convert_arguments. */
7156 extern int warningcount
, errorcount
;
7157 int savew
= 0, savee
= 0;
7160 savew
= warningcount
, savee
= errorcount
;
7161 rhs
= convert_to_reference (type
, rhs
, CONV_IMPLICIT
, flags
,
7162 exp
? exp
: error_mark_node
);
7165 if (warningcount
> savew
)
7166 cp_warning_at ("in passing argument %P of `%+D'", parmnum
, fndecl
);
7167 else if (errorcount
> savee
)
7168 cp_error_at ("in passing argument %P of `%+D'", parmnum
, fndecl
);
7173 rhs
= require_complete_type (rhs
);
7174 if (rhs
== error_mark_node
)
7175 return error_mark_node
;
7177 if (exp
!= 0) exp
= require_complete_type (exp
);
7178 if (exp
== error_mark_node
)
7179 return error_mark_node
;
7181 if (TREE_CODE (rhstype
) == REFERENCE_TYPE
)
7182 rhstype
= TREE_TYPE (rhstype
);
7184 type
= complete_type (type
);
7186 if (TYPE_LANG_SPECIFIC (type
)
7187 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
)))
7188 return build_signature_pointer_constructor (type
, rhs
);
7190 if (IS_AGGR_TYPE (type
))
7191 return ocp_convert (type
, rhs
, CONV_IMPLICIT
|CONV_FORCE_TEMP
, flags
);
7193 if (type
== TREE_TYPE (rhs
))
7195 /* Issue warnings about peculiar, but legal, uses of NULL. We
7196 do this *before* the call to decl_constant_value so as to
7197 avoid duplicate warnings on code like `const int I = NULL;
7199 if (ARITHMETIC_TYPE_P (type
) && rhs
== null_node
)
7200 cp_warning ("converting NULL to non-pointer type");
7202 if (TREE_READONLY_DECL_P (rhs
))
7203 rhs
= decl_constant_value (rhs
);
7208 return convert_for_assignment (type
, rhs
, errtype
, fndecl
, parmnum
);
7211 /* Expand an ASM statement with operands, handling output operands
7212 that are not variables or INDIRECT_REFS by transforming such
7213 cases into cases that expand_asm_operands can handle.
7215 Arguments are same as for expand_asm_operands.
7217 We don't do default conversions on all inputs, because it can screw
7218 up operands that are expected to be in memory. */
7221 c_expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, filename
, line
)
7222 tree string
, outputs
, inputs
, clobbers
;
7227 int noutputs
= list_length (outputs
);
7229 /* o[I] is the place that output number I should be written. */
7230 register tree
*o
= (tree
*) alloca (noutputs
* sizeof (tree
));
7233 /* Record the contents of OUTPUTS before it is modified. */
7234 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
7235 o
[i
] = TREE_VALUE (tail
);
7237 /* Generate the ASM_OPERANDS insn;
7238 store into the TREE_VALUEs of OUTPUTS some trees for
7239 where the values were actually stored. */
7240 expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, filename
, line
);
7242 /* Copy all the intermediate outputs into the specified outputs. */
7243 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
7245 if (o
[i
] != TREE_VALUE (tail
))
7247 expand_expr (build_modify_expr (o
[i
], NOP_EXPR
, TREE_VALUE (tail
)),
7248 const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
7251 /* Detect modification of read-only values.
7252 (Otherwise done by build_modify_expr.) */
7255 tree type
= TREE_TYPE (o
[i
]);
7256 if (TYPE_READONLY (type
)
7257 || ((TREE_CODE (type
) == RECORD_TYPE
7258 || TREE_CODE (type
) == UNION_TYPE
)
7259 && C_TYPE_FIELDS_READONLY (type
)))
7260 readonly_error (o
[i
], "modification by `asm'", 1);
7264 /* Those MODIFY_EXPRs could do autoincrements. */
7268 /* Expand a C `return' statement.
7269 RETVAL is the expression for what to return,
7270 or a null pointer for `return;' with no value.
7272 C++: upon seeing a `return', we must call destructors on all
7273 variables in scope which had constructors called on them.
7274 This means that if in a destructor, the base class destructors
7275 must be called before returning.
7277 The RETURN statement in C++ has initialization semantics. */
7280 c_expand_return (retval
)
7283 extern struct nesting
*cond_stack
, *loop_stack
, *case_stack
;
7284 extern tree dtor_label
, ctor_label
;
7285 tree result
= DECL_RESULT (current_function_decl
);
7286 tree valtype
= TREE_TYPE (result
);
7288 if (TREE_THIS_VOLATILE (current_function_decl
))
7289 warning ("function declared `noreturn' has a `return' statement");
7291 if (retval
== error_mark_node
)
7293 current_function_returns_null
= 1;
7297 if (processing_template_decl
)
7299 add_tree (build_min_nt (RETURN_STMT
, retval
));
7306 error ("returning a value from a destructor");
7308 /* Can't just return from a destructor. */
7309 expand_goto (dtor_label
);
7313 if (retval
== NULL_TREE
)
7315 /* A non-named return value does not count. */
7317 if (DECL_CONSTRUCTOR_P (current_function_decl
))
7318 retval
= current_class_ptr
;
7319 else if (DECL_NAME (result
) != NULL_TREE
7320 && TREE_CODE (valtype
) != VOID_TYPE
)
7324 current_function_returns_null
= 1;
7326 if (valtype
!= NULL_TREE
&& TREE_CODE (valtype
) != VOID_TYPE
)
7328 if (DECL_NAME (DECL_RESULT (current_function_decl
)) == NULL_TREE
)
7330 pedwarn ("`return' with no value, in function returning non-void");
7331 /* Clear this, so finish_function won't say that we
7332 reach the end of a non-void function (which we don't,
7333 we gave a return!). */
7334 current_function_returns_null
= 0;
7338 expand_null_return ();
7342 else if (DECL_CONSTRUCTOR_P (current_function_decl
))
7344 if (flag_this_is_variable
)
7345 error ("return from a constructor: use `this = ...' instead");
7347 error ("returning a value from a constructor");
7348 retval
= current_class_ptr
;
7351 /* Effective C++ rule 15. See also start_function. */
7353 && DECL_NAME (current_function_decl
) == ansi_opname
[(int) MODIFY_EXPR
]
7354 && retval
!= current_class_ref
)
7355 cp_warning ("`operator=' should return a reference to `*this'");
7357 if (valtype
== NULL_TREE
|| TREE_CODE (valtype
) == VOID_TYPE
)
7359 current_function_returns_null
= 1;
7360 if (TREE_CODE (TREE_TYPE (retval
)) != VOID_TYPE
)
7361 pedwarn ("`return' with a value, in function returning void");
7362 expand_return (retval
);
7366 /* Now deal with possible C++ hair:
7367 (1) Compute the return value.
7368 (2) If there are aggregate values with destructors which
7369 must be cleaned up, clean them (taking care
7370 not to clobber the return value).
7371 (3) If an X(X&) constructor is defined, the return
7372 value must be returned via that. */
7374 if (retval
== result
7375 || DECL_CONSTRUCTOR_P (current_function_decl
))
7376 /* It's already done for us. */;
7377 else if (TREE_TYPE (retval
) == void_type_node
)
7379 pedwarn ("return of void value in function returning non-void");
7380 expand_expr_stmt (retval
);
7385 tree functype
= TREE_TYPE (TREE_TYPE (current_function_decl
));
7387 /* First convert the value to the function's return type, then
7388 to the type of return value's location to handle the
7389 case that functype is thiner than the valtype. */
7391 retval
= convert_for_initialization
7392 (NULL_TREE
, functype
, retval
, LOOKUP_NORMAL
|LOOKUP_ONLYCONVERTING
,
7393 "return", NULL_TREE
, 0);
7395 retval
= convert (valtype
, retval
);
7397 if (retval
== error_mark_node
)
7399 /* Avoid warning about control reaching end of function. */
7400 expand_null_return ();
7404 /* We can't initialize a register from a AGGR_INIT_EXPR. */
7405 else if (! current_function_returns_struct
7406 && TREE_CODE (retval
) == TARGET_EXPR
7407 && TREE_CODE (TREE_OPERAND (retval
, 1)) == AGGR_INIT_EXPR
)
7408 retval
= build (COMPOUND_EXPR
, TREE_TYPE (retval
), retval
,
7409 TREE_OPERAND (retval
, 0));
7411 /* Add some useful error checking for C++. */
7412 else if (TREE_CODE (valtype
) == REFERENCE_TYPE
)
7414 tree whats_returned
;
7416 /* Sort through common things to see what it is
7417 we are returning. */
7418 whats_returned
= retval
;
7419 if (TREE_CODE (whats_returned
) == COMPOUND_EXPR
)
7421 whats_returned
= TREE_OPERAND (whats_returned
, 1);
7422 if (TREE_CODE (whats_returned
) == ADDR_EXPR
)
7423 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7425 while (TREE_CODE (whats_returned
) == CONVERT_EXPR
7426 || TREE_CODE (whats_returned
) == NOP_EXPR
)
7427 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7428 if (TREE_CODE (whats_returned
) == ADDR_EXPR
)
7430 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7431 while (TREE_CODE (whats_returned
) == AGGR_INIT_EXPR
7432 || TREE_CODE (whats_returned
) == TARGET_EXPR
)
7434 /* Get the target. */
7435 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7436 warning ("returning reference to temporary");
7440 if (TREE_CODE (whats_returned
) == VAR_DECL
&& DECL_NAME (whats_returned
))
7442 if (TEMP_NAME_P (DECL_NAME (whats_returned
)))
7443 warning ("reference to non-lvalue returned");
7444 else if (TREE_CODE (TREE_TYPE (whats_returned
)) != REFERENCE_TYPE
7445 && ! TREE_STATIC (whats_returned
)
7446 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned
))
7447 && !TREE_PUBLIC (whats_returned
))
7448 cp_warning_at ("reference to local variable `%D' returned", whats_returned
);
7451 else if (TREE_CODE (retval
) == ADDR_EXPR
)
7453 tree whats_returned
= TREE_OPERAND (retval
, 0);
7455 if (TREE_CODE (whats_returned
) == VAR_DECL
7456 && DECL_NAME (whats_returned
)
7457 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned
))
7458 && !TREE_STATIC (whats_returned
)
7459 && !TREE_PUBLIC (whats_returned
))
7460 cp_warning_at ("address of local variable `%D' returned", whats_returned
);
7464 if (retval
!= NULL_TREE
7465 && TREE_CODE_CLASS (TREE_CODE (retval
)) == 'd'
7466 && cond_stack
== 0 && loop_stack
== 0 && case_stack
== 0)
7467 current_function_return_value
= retval
;
7469 if (ctor_label
&& TREE_CODE (ctor_label
) != ERROR_MARK
)
7471 /* Here RETVAL is CURRENT_CLASS_PTR, so there's nothing to do. */
7472 expand_goto (ctor_label
);
7475 if (retval
&& retval
!= result
)
7477 result
= build (INIT_EXPR
, TREE_TYPE (result
), result
, retval
);
7478 TREE_SIDE_EFFECTS (result
) = 1;
7481 expand_start_target_temps ();
7483 expand_return (result
);
7485 expand_end_target_temps ();
7487 current_function_returns_value
= 1;
7490 /* Start a C switch statement, testing expression EXP.
7491 Return EXP if it is valid, an error node otherwise. */
7494 c_expand_start_case (exp
)
7498 register enum tree_code code
;
7500 /* Convert from references, etc. */
7501 exp
= default_conversion (exp
);
7502 type
= TREE_TYPE (exp
);
7503 code
= TREE_CODE (type
);
7505 if (IS_AGGR_TYPE_CODE (code
))
7506 exp
= build_type_conversion (CONVERT_EXPR
, integer_type_node
, exp
, 1);
7508 if (exp
== NULL_TREE
)
7510 error ("switch quantity not an integer");
7511 exp
= error_mark_node
;
7513 type
= TREE_TYPE (exp
);
7514 code
= TREE_CODE (type
);
7516 if (code
!= INTEGER_TYPE
&& code
!= ENUMERAL_TYPE
&& code
!= ERROR_MARK
)
7518 error ("switch quantity not an integer");
7519 exp
= error_mark_node
;
7525 exp
= default_conversion (exp
);
7526 type
= TREE_TYPE (exp
);
7527 idx
= get_unwidened (exp
, 0);
7528 /* We can't strip a conversion from a signed type to an unsigned,
7529 because if we did, int_fits_type_p would do the wrong thing
7530 when checking case values for being in range,
7531 and it's too hard to do the right thing. */
7532 if (TREE_UNSIGNED (TREE_TYPE (exp
))
7533 == TREE_UNSIGNED (TREE_TYPE (idx
)))
7538 (1, fold (build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (exp
), exp
)),
7539 type
, "switch statement");
7544 /* Returns non-zero if the pointer-type FROM can be converted to the
7545 pointer-type TO via a qualification conversion. If CONSTP is -1,
7546 then we return non-zero if the pointers are similar, and the
7547 cv-qualification signature of FROM is a proper subset of that of TO.
7549 If CONSTP is positive, then all outer pointers have been
7553 comp_ptr_ttypes_real (to
, from
, constp
)
7557 int to_more_cv_qualified
= 0;
7559 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7561 if (TREE_CODE (to
) != TREE_CODE (from
))
7564 if (TREE_CODE (from
) == OFFSET_TYPE
7565 && comptypes (TYPE_OFFSET_BASETYPE (from
),
7566 TYPE_OFFSET_BASETYPE (to
), 1))
7569 /* Const and volatile mean something different for function types,
7570 so the usual checks are not appropriate. */
7571 if (TREE_CODE (to
) != FUNCTION_TYPE
&& TREE_CODE (to
) != METHOD_TYPE
)
7573 if (TYPE_READONLY (from
) > TYPE_READONLY (to
)
7574 || TYPE_VOLATILE (from
) > TYPE_VOLATILE (to
))
7577 if (TYPE_READONLY (to
) > TYPE_READONLY (from
)
7578 || TYPE_VOLATILE (to
) > TYPE_VOLATILE (from
))
7583 ++to_more_cv_qualified
;
7587 constp
&= TYPE_READONLY (to
);
7590 if (TREE_CODE (to
) != POINTER_TYPE
)
7592 comptypes (TYPE_MAIN_VARIANT (to
), TYPE_MAIN_VARIANT (from
), 1)
7593 && (constp
>= 0 || to_more_cv_qualified
);
7597 /* When comparing, say, char ** to char const **, this function takes the
7598 'char *' and 'char const *'. Do not pass non-pointer types to this
7602 comp_ptr_ttypes (to
, from
)
7605 return comp_ptr_ttypes_real (to
, from
, 1);
7608 /* Returns 1 if to and from are (possibly multi-level) pointers to the same
7609 type or inheritance-related types, regardless of cv-quals. */
7612 ptr_reasonably_similar (to
, from
)
7615 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7617 if (TREE_CODE (to
) != TREE_CODE (from
))
7620 if (TREE_CODE (from
) == OFFSET_TYPE
7621 && comptypes (TYPE_OFFSET_BASETYPE (to
),
7622 TYPE_OFFSET_BASETYPE (from
), -1))
7625 if (TREE_CODE (to
) != POINTER_TYPE
)
7627 (TYPE_MAIN_VARIANT (to
), TYPE_MAIN_VARIANT (from
), -1);
7631 /* Like comp_ptr_ttypes, for const_cast. */
7634 comp_ptr_ttypes_const (to
, from
)
7637 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7639 if (TREE_CODE (to
) != TREE_CODE (from
))
7642 if (TREE_CODE (from
) == OFFSET_TYPE
7643 && comptypes (TYPE_OFFSET_BASETYPE (from
),
7644 TYPE_OFFSET_BASETYPE (to
), 1))
7647 if (TREE_CODE (to
) != POINTER_TYPE
)
7648 return comptypes (TYPE_MAIN_VARIANT (to
), TYPE_MAIN_VARIANT (from
), 1);
7652 /* Like comp_ptr_ttypes, for reinterpret_cast. */
7655 comp_ptr_ttypes_reinterpret (to
, from
)
7660 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7662 if (TREE_CODE (from
) == OFFSET_TYPE
)
7663 from
= TREE_TYPE (from
);
7664 if (TREE_CODE (to
) == OFFSET_TYPE
)
7665 to
= TREE_TYPE (to
);
7667 if (TREE_CODE (to
) != TREE_CODE (from
))
7670 /* Const and volatile mean something different for function types,
7671 so the usual checks are not appropriate. */
7672 if (TREE_CODE (to
) != FUNCTION_TYPE
&& TREE_CODE (to
) != METHOD_TYPE
)
7674 if (TYPE_READONLY (from
) > TYPE_READONLY (to
)
7675 || TYPE_VOLATILE (from
) > TYPE_VOLATILE (to
))
7679 && (TYPE_READONLY (to
) > TYPE_READONLY (from
)
7680 || TYPE_VOLATILE (to
) > TYPE_READONLY (from
)))
7682 constp
&= TYPE_READONLY (to
);
7685 if (TREE_CODE (to
) != POINTER_TYPE
)