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
));
863 if (TREE_CODE (t1
) == RECORD_TYPE
&& TREE_CODE (t2
) == RECORD_TYPE
)
867 rval
= t1
== t2
|| DERIVED_FROM_P (t1
, t2
);
876 val
= DERIVED_FROM_P (t2
, t1
);
883 val
= comptypes (t1
, t2
, strict
);
887 if (! compexcepttypes (t1
, t2
))
890 val
= ((TREE_TYPE (t1
) == TREE_TYPE (t2
)
891 || comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
))
892 && compparms (TYPE_ARG_TYPES (t1
), TYPE_ARG_TYPES (t2
), strict
));
896 /* Target types must match incl. qualifiers. */
897 val
= comp_array_types (comptypes
, t1
, t2
, strict
);
900 case TEMPLATE_TYPE_PARM
:
901 return TEMPLATE_TYPE_IDX (t1
) == TEMPLATE_TYPE_IDX (t2
)
902 && TEMPLATE_TYPE_LEVEL (t1
) == TEMPLATE_TYPE_LEVEL (t2
);
905 if (TYPE_IDENTIFIER (t1
) != TYPE_IDENTIFIER (t2
))
907 return comptypes (TYPE_CONTEXT (t1
), TYPE_CONTEXT (t2
), 1);
912 return attrval
== 2 && val
== 1 ? 2 : val
;
915 /* Return 1 or -1 if TTL and TTR are pointers to types that are equivalent,
916 ignoring their qualifiers, 0 if not. Return 1 means that TTR can be
917 converted to TTL. Return -1 means that TTL can be converted to TTR but
920 NPTRS is the number of pointers we can strip off and keep cool.
921 This is used to permit (for aggr A, aggr B) A, B* to convert to A*,
922 but to not permit B** to convert to A**.
924 This should go away. Callers should use can_convert or something
925 similar instead. (jason 17 Apr 1997) */
928 comp_target_types (ttl
, ttr
, nptrs
)
932 ttl
= TYPE_MAIN_VARIANT (ttl
);
933 ttr
= TYPE_MAIN_VARIANT (ttr
);
937 if (TREE_CODE (ttr
) != TREE_CODE (ttl
))
940 if (TREE_CODE (ttr
) == POINTER_TYPE
941 || (TREE_CODE (ttr
) == REFERENCE_TYPE
))
943 int is_ptr
= TREE_CODE (ttr
) == POINTER_TYPE
;
945 ttl
= TREE_TYPE (ttl
);
946 ttr
= TREE_TYPE (ttr
);
948 if (nptrs
> 0 && is_ptr
)
950 if (TREE_CODE (ttl
) == UNKNOWN_TYPE
951 || TREE_CODE (ttr
) == UNKNOWN_TYPE
)
953 else if (TREE_CODE (ttl
) == VOID_TYPE
954 && TREE_CODE (ttr
) != FUNCTION_TYPE
955 && TREE_CODE (ttr
) != METHOD_TYPE
956 && TREE_CODE (ttr
) != OFFSET_TYPE
)
958 else if (TREE_CODE (ttr
) == VOID_TYPE
959 && TREE_CODE (ttl
) != FUNCTION_TYPE
960 && TREE_CODE (ttl
) != METHOD_TYPE
961 && TREE_CODE (ttl
) != OFFSET_TYPE
)
963 else if (TREE_CODE (ttl
) == POINTER_TYPE
964 || TREE_CODE (ttl
) == ARRAY_TYPE
)
966 if (comp_ptr_ttypes (ttl
, ttr
))
968 else if (comp_ptr_ttypes (ttr
, ttl
))
974 /* Const and volatile mean something different for function types,
975 so the usual checks are not appropriate. */
976 if (TREE_CODE (ttl
) == FUNCTION_TYPE
|| TREE_CODE (ttl
) == METHOD_TYPE
)
977 return comp_target_types (ttl
, ttr
, nptrs
- 1);
979 /* Make sure that the cv-quals change only in the same direction as
983 int c
= TYPE_READONLY (ttl
) - TYPE_READONLY (ttr
);
984 int v
= TYPE_VOLATILE (ttl
) - TYPE_VOLATILE (ttr
);
986 if ((c
> 0 && v
< 0) || (c
< 0 && v
> 0))
989 if (TYPE_MAIN_VARIANT (ttl
) == TYPE_MAIN_VARIANT (ttr
))
990 return (c
+ v
< 0) ? -1 : 1;
992 t
= comp_target_types (ttl
, ttr
, nptrs
- 1);
993 if ((t
== 1 && c
+ v
>= 0) || (t
== -1 && c
+ v
<= 0))
1000 if (TREE_CODE (ttr
) == ARRAY_TYPE
)
1001 return comp_array_types (comp_target_types
, ttl
, ttr
, 0);
1002 else if (TREE_CODE (ttr
) == FUNCTION_TYPE
|| TREE_CODE (ttr
) == METHOD_TYPE
)
1009 if (comptypes (TREE_TYPE (ttl
), TREE_TYPE (ttr
), 1) == 0)
1014 switch (comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), -1))
1023 argsl
= TYPE_ARG_TYPES (ttl
);
1024 argsr
= TYPE_ARG_TYPES (ttr
);
1026 /* Compare 'this' here, not in comp_target_parms. */
1027 if (TREE_CODE (ttr
) == METHOD_TYPE
)
1029 tree tl
= TYPE_METHOD_BASETYPE (ttl
);
1030 tree tr
= TYPE_METHOD_BASETYPE (ttr
);
1032 if (comptypes (tr
, tl
, 0) == 0)
1034 if (comptypes (tl
, tr
, 0))
1040 argsl
= TREE_CHAIN (argsl
);
1041 argsr
= TREE_CHAIN (argsr
);
1044 switch (comp_target_parms (argsl
, argsr
, 1))
1052 return saw_contra
? -1 : 1;
1055 else if (TREE_CODE (ttr
) == OFFSET_TYPE
)
1057 /* Contravariance: we can assign a pointer to base member to a pointer
1058 to derived member. Note difference from simple pointer case, where
1059 we can pass a pointer to derived to a pointer to base. */
1060 if (comptypes (TYPE_OFFSET_BASETYPE (ttr
),
1061 TYPE_OFFSET_BASETYPE (ttl
), 0))
1062 return comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
);
1063 else if (comptypes (TYPE_OFFSET_BASETYPE (ttl
),
1064 TYPE_OFFSET_BASETYPE (ttr
), 0)
1065 && comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
))
1068 else if (IS_AGGR_TYPE (ttl
))
1072 if (comptypes (build_pointer_type (ttl
), build_pointer_type (ttr
), 0))
1074 if (comptypes (build_pointer_type (ttr
), build_pointer_type (ttl
), 0))
1082 /* Returns 1 if TYPE1 is more cv-qualified than TYPE2, -1 if TYPE2 is
1083 more cv-qualified that TYPE1, and 0 otherwise. */
1086 comp_cv_qualification (type1
, type2
)
1090 if (TYPE_READONLY (type1
) == TYPE_READONLY (type2
)
1091 && TYPE_VOLATILE (type1
) == TYPE_VOLATILE (type2
))
1094 if (TYPE_READONLY (type1
) >= TYPE_READONLY (type2
)
1095 && TYPE_VOLATILE (type1
) >= TYPE_VOLATILE (type2
))
1098 if (TYPE_READONLY (type2
) >= TYPE_READONLY (type1
)
1099 && TYPE_VOLATILE (type2
) >= TYPE_VOLATILE (type1
))
1105 /* Returns 1 if the cv-qualification signature of TYPE1 is a proper
1106 subset of the cv-qualification signature of TYPE2, and the types
1107 are similar. Returns -1 if the other way 'round, and 0 otherwise. */
1110 comp_cv_qual_signature (type1
, type2
)
1114 if (comp_ptr_ttypes_real (type2
, type1
, -1))
1116 else if (comp_ptr_ttypes_real (type1
, type2
, -1))
1122 /* If two types share a common base type, return that basetype.
1123 If there is not a unique most-derived base type, this function
1124 returns ERROR_MARK_NODE. */
1127 common_base_type (tt1
, tt2
)
1130 tree best
= NULL_TREE
;
1133 /* If one is a baseclass of another, that's good enough. */
1134 if (UNIQUELY_DERIVED_FROM_P (tt1
, tt2
))
1136 if (UNIQUELY_DERIVED_FROM_P (tt2
, tt1
))
1139 /* Otherwise, try to find a unique baseclass of TT1
1140 that is shared by TT2, and follow that down. */
1141 for (i
= CLASSTYPE_N_BASECLASSES (tt1
)-1; i
>= 0; i
--)
1143 tree basetype
= TYPE_BINFO_BASETYPE (tt1
, i
);
1144 tree trial
= common_base_type (basetype
, tt2
);
1147 if (trial
== error_mark_node
)
1149 if (best
== NULL_TREE
)
1151 else if (best
!= trial
)
1152 return error_mark_node
;
1157 for (i
= CLASSTYPE_N_BASECLASSES (tt2
)-1; i
>= 0; i
--)
1159 tree basetype
= TYPE_BINFO_BASETYPE (tt2
, i
);
1160 tree trial
= common_base_type (tt1
, basetype
);
1163 if (trial
== error_mark_node
)
1165 if (best
== NULL_TREE
)
1167 else if (best
!= trial
)
1168 return error_mark_node
;
1174 /* Subroutines of `comptypes'. */
1176 /* Return 1 if two parameter type lists PARMS1 and PARMS2
1177 are equivalent in the sense that functions with those parameter types
1178 can have equivalent types.
1179 If either list is empty, we win.
1180 Otherwise, the two lists must be equivalent, element by element.
1182 C++: See comment above about TYPE1, TYPE2.
1184 STRICT is no longer used. */
1187 compparms (parms1
, parms2
, strict
)
1188 tree parms1
, parms2
;
1191 register tree t1
= parms1
, t2
= parms2
;
1193 /* An unspecified parmlist matches any specified parmlist
1194 whose argument types don't need default promotions. */
1198 if (t1
== 0 && t2
== 0)
1200 /* If one parmlist is shorter than the other,
1201 they fail to match. */
1202 if (t1
== 0 || t2
== 0)
1204 if (! comptypes (TREE_VALUE (t2
), TREE_VALUE (t1
), 1))
1207 t1
= TREE_CHAIN (t1
);
1208 t2
= TREE_CHAIN (t2
);
1212 /* This really wants return whether or not parameter type lists
1213 would make their owning functions assignment compatible or not.
1215 The return value is like for comp_target_types.
1217 This should go away, possibly with the exception of the empty parmlist
1218 conversion; there are no conversions between function types in C++.
1219 (jason 17 Apr 1997) */
1222 comp_target_parms (parms1
, parms2
, strict
)
1223 tree parms1
, parms2
;
1226 register tree t1
= parms1
, t2
= parms2
;
1227 int warn_contravariance
= 0;
1229 /* In C, an unspecified parmlist matches any specified parmlist
1230 whose argument types don't need default promotions. This is not
1231 true for C++, but let's do it anyway for unfixed headers. */
1233 if (t1
== 0 && t2
!= 0)
1235 cp_pedwarn ("ANSI C++ prohibits conversion from `(%#T)' to `(...)'",
1237 return self_promoting_args_p (t2
);
1240 return self_promoting_args_p (t1
);
1242 for (; t1
|| t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
1246 /* If one parmlist is shorter than the other,
1247 they fail to match, unless STRICT is <= 0. */
1248 if (t1
== 0 || t2
== 0)
1253 return 1 + warn_contravariance
;
1254 return ((t1
&& TREE_PURPOSE (t1
)) + warn_contravariance
);
1256 p1
= TREE_VALUE (t1
);
1257 p2
= TREE_VALUE (t2
);
1258 if (comptypes (p1
, p2
, 1))
1264 if ((TREE_CODE (p1
) == POINTER_TYPE
&& TREE_CODE (p2
) == POINTER_TYPE
)
1265 || (TREE_CODE (p1
) == REFERENCE_TYPE
1266 && TREE_CODE (p2
) == REFERENCE_TYPE
))
1269 && (TYPE_MAIN_VARIANT (TREE_TYPE (p1
))
1270 == TYPE_MAIN_VARIANT (TREE_TYPE (p2
))))
1273 /* The following is wrong for contravariance,
1274 but many programs depend on it. */
1275 if (TREE_TYPE (p1
) == void_type_node
)
1277 if (TREE_TYPE (p2
) == void_type_node
)
1279 warn_contravariance
= 1;
1282 if (IS_AGGR_TYPE (TREE_TYPE (p1
)))
1284 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (p1
)),
1285 TYPE_MAIN_VARIANT (TREE_TYPE (p2
)), 1) == 0)
1289 /* Note backwards order due to contravariance. */
1290 if (comp_target_types (p2
, p1
, 1) <= 0)
1292 if (comp_target_types (p1
, p2
, 1) > 0)
1294 warn_contravariance
= 1;
1301 return warn_contravariance
? -1 : 1;
1304 /* Return 1 if PARMS specifies a fixed number of parameters
1305 and none of their types is affected by default promotions. */
1308 self_promoting_args_p (parms
)
1312 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
1314 register tree type
= TREE_VALUE (t
);
1316 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
1322 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
1325 if (C_PROMOTING_INTEGER_TYPE_P (type
))
1331 /* Return an unsigned type the same as TYPE in other respects.
1333 C++: must make these work for type variants as well. */
1336 unsigned_type (type
)
1339 tree type1
= TYPE_MAIN_VARIANT (type
);
1340 if (type1
== signed_char_type_node
|| type1
== char_type_node
)
1341 return unsigned_char_type_node
;
1342 if (type1
== integer_type_node
)
1343 return unsigned_type_node
;
1344 if (type1
== short_integer_type_node
)
1345 return short_unsigned_type_node
;
1346 if (type1
== long_integer_type_node
)
1347 return long_unsigned_type_node
;
1348 if (type1
== long_long_integer_type_node
)
1349 return long_long_unsigned_type_node
;
1350 if (type1
== intTI_type_node
)
1351 return unsigned_intTI_type_node
;
1352 if (type1
== intDI_type_node
)
1353 return unsigned_intDI_type_node
;
1354 if (type1
== intSI_type_node
)
1355 return unsigned_intSI_type_node
;
1356 if (type1
== intHI_type_node
)
1357 return unsigned_intHI_type_node
;
1358 if (type1
== intQI_type_node
)
1359 return unsigned_intQI_type_node
;
1361 return signed_or_unsigned_type (1, type
);
1364 /* Return a signed type the same as TYPE in other respects. */
1370 tree type1
= TYPE_MAIN_VARIANT (type
);
1371 if (type1
== unsigned_char_type_node
|| type1
== char_type_node
)
1372 return signed_char_type_node
;
1373 if (type1
== unsigned_type_node
)
1374 return integer_type_node
;
1375 if (type1
== short_unsigned_type_node
)
1376 return short_integer_type_node
;
1377 if (type1
== long_unsigned_type_node
)
1378 return long_integer_type_node
;
1379 if (type1
== long_long_unsigned_type_node
)
1380 return long_long_integer_type_node
;
1381 if (type1
== unsigned_intTI_type_node
)
1382 return intTI_type_node
;
1383 if (type1
== unsigned_intDI_type_node
)
1384 return intDI_type_node
;
1385 if (type1
== unsigned_intSI_type_node
)
1386 return intSI_type_node
;
1387 if (type1
== unsigned_intHI_type_node
)
1388 return intHI_type_node
;
1389 if (type1
== unsigned_intQI_type_node
)
1390 return intQI_type_node
;
1392 return signed_or_unsigned_type (0, type
);
1395 /* Return a type the same as TYPE except unsigned or
1396 signed according to UNSIGNEDP. */
1399 signed_or_unsigned_type (unsignedp
, type
)
1403 if (! INTEGRAL_TYPE_P (type
)
1404 || TREE_UNSIGNED (type
) == unsignedp
)
1407 if (TYPE_PRECISION (type
) == TYPE_PRECISION (signed_char_type_node
))
1408 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
1409 if (TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
))
1410 return unsignedp
? unsigned_type_node
: integer_type_node
;
1411 if (TYPE_PRECISION (type
) == TYPE_PRECISION (short_integer_type_node
))
1412 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
1413 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_integer_type_node
))
1414 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
1415 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_long_integer_type_node
))
1416 return (unsignedp
? long_long_unsigned_type_node
1417 : long_long_integer_type_node
);
1421 /* Compute the value of the `sizeof' operator. */
1427 enum tree_code code
= TREE_CODE (type
);
1430 if (processing_template_decl
)
1431 return build_min (SIZEOF_EXPR
, sizetype
, type
);
1433 if (code
== FUNCTION_TYPE
)
1435 if (pedantic
|| warn_pointer_arith
)
1436 pedwarn ("ANSI C++ forbids taking the sizeof a function type");
1437 return size_int (1);
1439 if (code
== METHOD_TYPE
)
1441 if (pedantic
|| warn_pointer_arith
)
1442 pedwarn ("ANSI C++ forbids taking the sizeof a method type");
1443 return size_int (1);
1445 if (code
== VOID_TYPE
)
1447 if (pedantic
|| warn_pointer_arith
)
1448 pedwarn ("ANSI C++ forbids taking the sizeof a void type");
1449 return size_int (1);
1451 if (code
== ERROR_MARK
)
1452 return size_int (1);
1454 /* ARM $5.3.2: ``When applied to a reference, the result is the size of the
1455 referenced object.'' */
1456 if (code
== REFERENCE_TYPE
)
1457 type
= TREE_TYPE (type
);
1459 /* We couldn't find anything in the ARM or the draft standard that says,
1460 one way or the other, if doing sizeof on something that doesn't have
1461 an object associated with it is correct or incorrect. For example, if
1462 you declare `struct S { char str[16]; };', and in your program do
1463 a `sizeof (S::str)', should we flag that as an error or should we give
1464 the size of it? Since it seems like a reasonable thing to do, we'll go
1465 with giving the value. */
1466 if (code
== OFFSET_TYPE
)
1467 type
= TREE_TYPE (type
);
1469 /* @@ This also produces an error for a signature ref.
1470 In that case we should be able to do better. */
1471 if (IS_SIGNATURE (type
))
1473 error ("`sizeof' applied to a signature type");
1474 return size_int (0);
1477 if (TYPE_SIZE (complete_type (type
)) == 0)
1479 cp_error ("`sizeof' applied to incomplete type `%T'", type
);
1480 return size_int (0);
1483 /* Convert in case a char is more than one unit. */
1484 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
1485 size_int (TYPE_PRECISION (char_type_node
)));
1486 t
= convert (sizetype
, t
);
1487 /* size_binop does not put the constant in range, so do it now. */
1488 if (TREE_CODE (t
) == INTEGER_CST
&& force_fit_type (t
, 0))
1489 TREE_CONSTANT_OVERFLOW (t
) = TREE_OVERFLOW (t
) = 1;
1497 if (processing_template_decl
)
1498 return build_min (SIZEOF_EXPR
, sizetype
, e
);
1500 if (TREE_CODE (e
) == COMPONENT_REF
1501 && DECL_BIT_FIELD (TREE_OPERAND (e
, 1)))
1502 error ("sizeof applied to a bit-field");
1503 /* ANSI says arrays and functions are converted inside comma.
1504 But we can't really convert them in build_compound_expr
1505 because that would break commas in lvalues.
1506 So do the conversion here if operand was a comma. */
1507 if (TREE_CODE (e
) == COMPOUND_EXPR
1508 && (TREE_CODE (TREE_TYPE (e
)) == ARRAY_TYPE
1509 || TREE_CODE (TREE_TYPE (e
)) == FUNCTION_TYPE
))
1510 e
= default_conversion (e
);
1511 else if (TREE_CODE (e
) == TREE_LIST
)
1513 tree t
= TREE_VALUE (e
);
1516 && TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
1517 || is_overloaded_fn (t
)))
1518 pedwarn ("ANSI C++ forbids taking the sizeof a function type");
1520 return c_sizeof (TREE_TYPE (e
));
1524 c_sizeof_nowarn (type
)
1527 enum tree_code code
= TREE_CODE (type
);
1530 if (code
== FUNCTION_TYPE
1531 || code
== METHOD_TYPE
1532 || code
== VOID_TYPE
1533 || code
== ERROR_MARK
)
1534 return size_int (1);
1535 if (code
== REFERENCE_TYPE
)
1536 type
= TREE_TYPE (type
);
1538 if (TYPE_SIZE (type
) == 0)
1539 return size_int (0);
1541 /* Convert in case a char is more than one unit. */
1542 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
1543 size_int (TYPE_PRECISION (char_type_node
)));
1544 t
= convert (sizetype
, t
);
1545 force_fit_type (t
, 0);
1549 /* Implement the __alignof keyword: Return the minimum required
1550 alignment of TYPE, measured in bytes. */
1556 enum tree_code code
= TREE_CODE (type
);
1559 if (processing_template_decl
)
1560 return build_min (ALIGNOF_EXPR
, sizetype
, type
);
1562 if (code
== FUNCTION_TYPE
|| code
== METHOD_TYPE
)
1563 return size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
1565 if (code
== VOID_TYPE
|| code
== ERROR_MARK
)
1566 return size_int (1);
1568 /* C++: this is really correct! */
1569 if (code
== REFERENCE_TYPE
)
1570 type
= TREE_TYPE (type
);
1572 /* @@ This also produces an error for a signature ref.
1573 In that case we should be able to do better. */
1574 if (IS_SIGNATURE (type
))
1576 error ("`__alignof' applied to a signature type");
1577 return size_int (1);
1580 t
= size_int (TYPE_ALIGN (type
) / BITS_PER_UNIT
);
1581 force_fit_type (t
, 0);
1585 /* Perform default promotions for C data used in expressions.
1586 Arrays and functions are converted to pointers;
1587 enumeral types or short or char, to int.
1588 In addition, manifest constants symbols are replaced by their values.
1590 C++: this will automatically bash references to their target type. */
1593 decay_conversion (exp
)
1596 register tree type
= TREE_TYPE (exp
);
1597 register enum tree_code code
= TREE_CODE (type
);
1599 if (code
== OFFSET_TYPE
)
1601 if (TREE_CODE (exp
) == OFFSET_REF
)
1602 return decay_conversion (resolve_offset_ref (exp
));
1604 type
= TREE_TYPE (type
);
1605 code
= TREE_CODE (type
);
1607 if (type
== unknown_type_node
)
1609 cp_pedwarn ("assuming & on overloaded member function");
1610 return build_unary_op (ADDR_EXPR
, exp
, 0);
1614 if (code
== REFERENCE_TYPE
)
1616 exp
= convert_from_reference (exp
);
1617 type
= TREE_TYPE (exp
);
1618 code
= TREE_CODE (type
);
1621 /* Constants can be used directly unless they're not loadable. */
1622 if (TREE_CODE (exp
) == CONST_DECL
)
1623 exp
= DECL_INITIAL (exp
);
1624 /* Replace a nonvolatile const static variable with its value. */
1625 else if (TREE_READONLY_DECL_P (exp
))
1627 exp
= decl_constant_value (exp
);
1628 type
= TREE_TYPE (exp
);
1631 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
1632 Leave such NOP_EXPRs, since RHS is being used in non-lvalue context. */
1634 if (code
== VOID_TYPE
)
1636 error ("void value not ignored as it ought to be");
1637 return error_mark_node
;
1639 if (code
== FUNCTION_TYPE
)
1641 return build_unary_op (ADDR_EXPR
, exp
, 0);
1643 if (code
== METHOD_TYPE
)
1645 cp_pedwarn ("assuming & on `%E'", exp
);
1646 return build_unary_op (ADDR_EXPR
, exp
, 0);
1648 if (code
== ARRAY_TYPE
)
1653 int constp
, volatilep
;
1655 if (TREE_CODE (exp
) == INDIRECT_REF
)
1657 /* Stripping away the INDIRECT_REF is not the right
1658 thing to do for references... */
1659 tree inner
= TREE_OPERAND (exp
, 0);
1660 if (TREE_CODE (TREE_TYPE (inner
)) == REFERENCE_TYPE
)
1662 inner
= build1 (CONVERT_EXPR
,
1663 build_pointer_type (TREE_TYPE
1664 (TREE_TYPE (inner
))),
1666 TREE_CONSTANT (inner
) = TREE_CONSTANT (TREE_OPERAND (inner
, 0));
1668 return cp_convert (build_pointer_type (TREE_TYPE (type
)), inner
);
1671 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
1673 tree op1
= decay_conversion (TREE_OPERAND (exp
, 1));
1674 return build (COMPOUND_EXPR
, TREE_TYPE (op1
),
1675 TREE_OPERAND (exp
, 0), op1
);
1679 && ! (TREE_CODE (exp
) == CONSTRUCTOR
&& TREE_STATIC (exp
)))
1681 error ("invalid use of non-lvalue array");
1682 return error_mark_node
;
1685 constp
= volatilep
= 0;
1686 if (TREE_CODE_CLASS (TREE_CODE (exp
)) == 'r'
1687 || TREE_CODE_CLASS (TREE_CODE (exp
)) == 'd')
1689 constp
= TREE_READONLY (exp
);
1690 volatilep
= TREE_THIS_VOLATILE (exp
);
1693 restype
= TREE_TYPE (type
);
1694 if (TYPE_READONLY (type
) || TYPE_VOLATILE (type
)
1695 || constp
|| volatilep
)
1696 restype
= cp_build_type_variant (restype
,
1697 TYPE_READONLY (type
) || constp
,
1698 TYPE_VOLATILE (type
) || volatilep
);
1699 ptrtype
= build_pointer_type (restype
);
1701 if (TREE_CODE (exp
) == VAR_DECL
)
1703 /* ??? This is not really quite correct
1704 in that the type of the operand of ADDR_EXPR
1705 is not the target type of the type of the ADDR_EXPR itself.
1706 Question is, can this lossage be avoided? */
1707 adr
= build1 (ADDR_EXPR
, ptrtype
, exp
);
1708 if (mark_addressable (exp
) == 0)
1709 return error_mark_node
;
1710 TREE_CONSTANT (adr
) = staticp (exp
);
1711 TREE_SIDE_EFFECTS (adr
) = 0; /* Default would be, same as EXP. */
1714 /* This way is better for a COMPONENT_REF since it can
1715 simplify the offset for a component. */
1716 adr
= build_unary_op (ADDR_EXPR
, exp
, 1);
1717 return cp_convert (ptrtype
, adr
);
1724 default_conversion (exp
)
1728 enum tree_code code
;
1730 exp
= decay_conversion (exp
);
1732 type
= TREE_TYPE (exp
);
1733 code
= TREE_CODE (type
);
1735 if (INTEGRAL_CODE_P (code
))
1737 tree t
= type_promotes_to (type
);
1739 return cp_convert (t
, exp
);
1745 /* Take the address of an inline function without setting TREE_ADDRESSABLE
1749 inline_conversion (exp
)
1752 if (TREE_CODE (exp
) == FUNCTION_DECL
)
1754 tree type
= build_type_variant
1755 (TREE_TYPE (exp
), TREE_READONLY (exp
), TREE_THIS_VOLATILE (exp
));
1756 exp
= build1 (ADDR_EXPR
, build_pointer_type (type
), exp
);
1761 /* Returns nonzero iff exp is a STRING_CST or the result of applying
1762 decay_conversion to one. */
1765 string_conv_p (totype
, exp
, warn
)
1771 if (! flag_const_strings
|| TREE_CODE (totype
) != POINTER_TYPE
)
1774 t
= TREE_TYPE (totype
);
1775 if (! comptypes (t
, char_type_node
, 1)
1776 && ! comptypes (t
, wchar_type_node
, 1))
1779 if (TREE_CODE (exp
) != STRING_CST
)
1781 t
= build_pointer_type (build_type_variant (t
, 1, 0));
1782 if (! comptypes (TREE_TYPE (exp
), t
, 1))
1785 if (TREE_CODE (exp
) != ADDR_EXPR
1786 || TREE_CODE (TREE_OPERAND (exp
, 0)) != STRING_CST
)
1790 /* This warning is not very useful, as it complains about printf. */
1791 if (warn
&& warn_write_strings
)
1792 cp_warning ("deprecated conversion from string constant to `char *'");
1798 build_object_ref (datum
, basetype
, field
)
1799 tree datum
, basetype
, field
;
1802 if (datum
== error_mark_node
)
1803 return error_mark_node
;
1805 dtype
= TREE_TYPE (datum
);
1806 if (TREE_CODE (dtype
) == REFERENCE_TYPE
)
1807 dtype
= TREE_TYPE (dtype
);
1808 if (! IS_AGGR_TYPE_CODE (TREE_CODE (dtype
)))
1810 cp_error ("request for member `%T::%D' in expression of non-aggregate type `%T'",
1811 basetype
, field
, dtype
);
1812 return error_mark_node
;
1814 else if (IS_SIGNATURE (basetype
))
1816 warning ("signature name in scope resolution ignored");
1817 return build_component_ref (datum
, field
, NULL_TREE
, 1);
1819 else if (is_aggr_type (basetype
, 1))
1821 tree binfo
= binfo_or_else (basetype
, dtype
);
1823 return build_x_component_ref (build_scoped_ref (datum
, basetype
),
1826 return error_mark_node
;
1829 /* Like `build_component_ref, but uses an already found field, and converts
1830 from a reference. Must compute access for current_class_ref.
1834 build_component_ref_1 (datum
, field
, protect
)
1838 return convert_from_reference
1839 (build_component_ref (datum
, field
, NULL_TREE
, protect
));
1842 /* Given a COND_EXPR, MIN_EXPR, or MAX_EXPR in T, return it in a form that we
1843 can, for example, use as an lvalue. This code used to be in
1844 unary_complex_lvalue, but we needed it to deal with `a = (d == c) ? b : c'
1845 expressions, where we're dealing with aggregates. But now it's again only
1846 called from unary_complex_lvalue. The case (in particular) that led to
1847 this was with CODE == ADDR_EXPR, since it's not an lvalue when we'd
1851 rationalize_conditional_expr (code
, t
)
1852 enum tree_code code
;
1855 /* For MIN_EXPR or MAX_EXPR, fold-const.c has arranged things so that
1856 the first operand is always the one to be used if both operands
1857 are equal, so we know what conditional expression this used to be. */
1858 if (TREE_CODE (t
) == MIN_EXPR
|| TREE_CODE (t
) == MAX_EXPR
)
1861 build_conditional_expr (build_x_binary_op ((TREE_CODE (t
) == MIN_EXPR
1862 ? LE_EXPR
: GE_EXPR
),
1863 TREE_OPERAND (t
, 0),
1864 TREE_OPERAND (t
, 1)),
1865 build_unary_op (code
, TREE_OPERAND (t
, 0), 0),
1866 build_unary_op (code
, TREE_OPERAND (t
, 1), 0));
1870 build_conditional_expr (TREE_OPERAND (t
, 0),
1871 build_unary_op (code
, TREE_OPERAND (t
, 1), 0),
1872 build_unary_op (code
, TREE_OPERAND (t
, 2), 0));
1875 /* Given the TYPE of an anonymous union field inside T, return the
1876 FIELD_DECL for the field. If not found return NULL_TREE. Because
1877 anonymous unions can nest, we must also search all anonymous unions
1878 that are directly reachable. */
1881 lookup_anon_field (t
, type
)
1886 for (field
= TYPE_FIELDS (t
); field
; field
= TREE_CHAIN (field
))
1888 if (TREE_STATIC (field
))
1890 if (TREE_CODE (field
) != FIELD_DECL
)
1893 /* If we find it directly, return the field. */
1894 if (DECL_NAME (field
) == NULL_TREE
1895 && type
== TREE_TYPE (field
))
1900 /* Otherwise, it could be nested, search harder. */
1901 if (DECL_NAME (field
) == NULL_TREE
1902 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
1904 tree subfield
= lookup_anon_field (TREE_TYPE (field
), type
);
1912 /* Build a COMPONENT_REF for a given DATUM, and it's member COMPONENT.
1913 COMPONENT can be an IDENTIFIER_NODE that is the name of the member
1914 that we are interested in, or it can be a FIELD_DECL. */
1917 build_component_ref (datum
, component
, basetype_path
, protect
)
1918 tree datum
, component
, basetype_path
;
1921 register tree basetype
= TREE_TYPE (datum
);
1922 register enum tree_code code
;
1923 register tree field
= NULL
;
1926 if (processing_template_decl
)
1927 return build_min_nt (COMPONENT_REF
, datum
, component
);
1929 /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference
1931 switch (TREE_CODE (datum
))
1935 tree value
= build_component_ref (TREE_OPERAND (datum
, 1), component
,
1936 basetype_path
, protect
);
1937 return build (COMPOUND_EXPR
, TREE_TYPE (value
),
1938 TREE_OPERAND (datum
, 0), value
);
1941 return build_conditional_expr
1942 (TREE_OPERAND (datum
, 0),
1943 build_component_ref (TREE_OPERAND (datum
, 1), component
,
1944 basetype_path
, protect
),
1945 build_component_ref (TREE_OPERAND (datum
, 2), component
,
1946 basetype_path
, protect
));
1949 cp_error ("invalid use of %D", datum
);
1950 datum
= error_mark_node
;
1957 code
= TREE_CODE (basetype
);
1959 if (code
== REFERENCE_TYPE
)
1961 datum
= convert_from_reference (datum
);
1962 basetype
= TREE_TYPE (datum
);
1963 code
= TREE_CODE (basetype
);
1965 if (TREE_CODE (datum
) == OFFSET_REF
)
1967 datum
= resolve_offset_ref (datum
);
1968 basetype
= TREE_TYPE (datum
);
1969 code
= TREE_CODE (basetype
);
1972 /* First, see if there is a field or component with name COMPONENT. */
1973 if (TREE_CODE (component
) == TREE_LIST
)
1975 /* I could not trigger this code. MvL */
1976 my_friendly_abort (980326);
1978 my_friendly_assert (!(TREE_CHAIN (component
) == NULL_TREE
1979 && DECL_CHAIN (TREE_VALUE (component
)) == NULL_TREE
), 309);
1981 return build (COMPONENT_REF
, TREE_TYPE (component
), datum
, component
);
1984 if (! IS_AGGR_TYPE_CODE (code
))
1986 if (code
!= ERROR_MARK
)
1987 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
1988 component
, datum
, basetype
);
1989 return error_mark_node
;
1992 if (!complete_type_or_else (basetype
))
1993 return error_mark_node
;
1995 if (TREE_CODE (component
) == BIT_NOT_EXPR
)
1997 if (TYPE_IDENTIFIER (basetype
) != TREE_OPERAND (component
, 0))
1999 cp_error ("destructor specifier `%T::~%T' must have matching names",
2000 basetype
, TREE_OPERAND (component
, 0));
2001 return error_mark_node
;
2003 if (! TYPE_HAS_DESTRUCTOR (basetype
))
2005 cp_error ("type `%T' has no destructor", basetype
);
2006 return error_mark_node
;
2008 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype
), 1);
2011 /* Look up component name in the structure type definition. */
2012 if (CLASSTYPE_VFIELD (basetype
)
2013 && DECL_NAME (CLASSTYPE_VFIELD (basetype
)) == component
)
2014 /* Special-case this because if we use normal lookups in an ambiguous
2015 hierarchy, the compiler will abort (because vptr lookups are
2016 not supposed to be ambiguous. */
2017 field
= CLASSTYPE_VFIELD (basetype
);
2018 else if (TREE_CODE (component
) == FIELD_DECL
)
2020 else if (TREE_CODE (component
) == TYPE_DECL
)
2022 cp_pedwarn ("invalid use of type decl `%#D' as expression", component
);
2027 tree name
= component
;
2028 if (TREE_CODE (component
) == VAR_DECL
)
2029 name
= DECL_NAME (component
);
2030 if (basetype_path
== NULL_TREE
)
2031 basetype_path
= TYPE_BINFO (basetype
);
2032 field
= lookup_field (basetype_path
, name
,
2033 protect
&& !VFIELD_NAME_P (name
), 0);
2034 if (field
== error_mark_node
)
2035 return error_mark_node
;
2037 if (field
== NULL_TREE
)
2039 /* Not found as a data field, look for it as a method. If found,
2040 then if this is the only possible one, return it, else
2041 report ambiguity error. */
2042 tree fndecls
= lookup_fnfields (basetype_path
, name
, 1);
2043 if (fndecls
== error_mark_node
)
2044 return error_mark_node
;
2047 if (TREE_CHAIN (fndecls
) == NULL_TREE
2048 && TREE_CODE (TREE_VALUE (fndecls
)) != OVERLOAD
)
2050 tree access
, fndecl
;
2052 /* Unique, so use this one now. */
2053 basetype
= TREE_PURPOSE (fndecls
);
2054 fndecl
= TREE_VALUE (fndecls
);
2055 access
= compute_access (TREE_PURPOSE (fndecls
), fndecl
);
2056 if (access
== access_public_node
)
2058 if (DECL_VINDEX (fndecl
)
2059 && ! resolves_to_fixed_type_p (datum
, 0))
2061 tree addr
= build_unary_op (ADDR_EXPR
, datum
, 0);
2062 tree fntype
= TREE_TYPE (fndecl
);
2064 addr
= convert_pointer_to (DECL_CONTEXT (fndecl
),
2066 datum
= build_indirect_ref (addr
, NULL_PTR
);
2067 my_friendly_assert (datum
!= error_mark_node
, 310);
2068 fndecl
= build_vfn_ref (&addr
, datum
,
2069 DECL_VINDEX (fndecl
));
2070 /* The type of fndecl is a function type,
2071 not a pointer-to-function type, since
2072 build_vfn_ref returns not the correct
2073 vtable slot, but the indirection of the
2074 correct vtable slot. */
2075 TREE_TYPE (fndecl
) = fntype
;
2079 return build (OFFSET_REF
, TREE_TYPE (fndecl
),
2082 if (access
== access_protected_node
)
2083 cp_error ("member function `%D' is protected", fndecl
);
2085 cp_error ("member function `%D' is private", fndecl
);
2086 return error_mark_node
;
2090 /* Just act like build_offset_ref, since the object does
2091 not matter unless we're actually calling the function. */
2094 t
= build_tree_list (error_mark_node
, fndecls
);
2095 TREE_TYPE (t
) = build_offset_type (basetype
,
2101 cp_error ("`%#T' has no member named `%D'", basetype
, name
);
2102 return error_mark_node
;
2104 else if (TREE_TYPE (field
) == error_mark_node
)
2105 return error_mark_node
;
2107 if (TREE_CODE (field
) != FIELD_DECL
)
2109 if (TREE_CODE (field
) == TYPE_DECL
)
2110 cp_pedwarn ("invalid use of type decl `%#D' as expression", field
);
2111 else if (DECL_RTL (field
) != 0)
2114 TREE_USED (field
) = 1;
2119 /* See if we have to do any conversions so that we pick up the field from the
2121 if (DECL_FIELD_CONTEXT (field
) != basetype
)
2123 tree context
= DECL_FIELD_CONTEXT (field
);
2124 tree base
= context
;
2125 while (!comptypes (base
, basetype
,1) && TYPE_NAME (base
)
2126 && ANON_UNION_TYPE_P (base
))
2128 base
= TYPE_CONTEXT (base
);
2131 /* Handle base classes here... */
2132 if (base
!= basetype
&& TYPE_USES_COMPLEX_INHERITANCE (basetype
))
2134 tree addr
= build_unary_op (ADDR_EXPR
, datum
, 0);
2135 if (integer_zerop (addr
))
2137 error ("invalid reference to NULL ptr, use ptr-to-member instead");
2138 return error_mark_node
;
2140 if (VBASE_NAME_P (DECL_NAME (field
)))
2142 /* It doesn't matter which vbase pointer we grab, just
2143 find one of them. */
2144 tree binfo
= get_binfo (base
,
2145 TREE_TYPE (TREE_TYPE (addr
)), 0);
2146 addr
= convert_pointer_to_real (binfo
, addr
);
2149 addr
= convert_pointer_to (base
, addr
);
2150 datum
= build_indirect_ref (addr
, NULL_PTR
);
2151 my_friendly_assert (datum
!= error_mark_node
, 311);
2155 /* Handle things from anon unions here... */
2156 if (TYPE_NAME (context
) && ANON_UNION_TYPE_P (context
))
2158 tree subfield
= lookup_anon_field (basetype
, context
);
2159 tree subdatum
= build_component_ref (datum
, subfield
,
2160 basetype_path
, protect
);
2161 return build_component_ref (subdatum
, field
, basetype_path
, protect
);
2165 ref
= fold (build (COMPONENT_REF
, TREE_TYPE (field
),
2166 break_out_cleanups (datum
), field
));
2168 if (TREE_READONLY (datum
) || TREE_READONLY (field
))
2169 TREE_READONLY (ref
) = 1;
2170 if (TREE_THIS_VOLATILE (datum
) || TREE_THIS_VOLATILE (field
))
2171 TREE_THIS_VOLATILE (ref
) = 1;
2172 if (DECL_LANG_SPECIFIC (field
) && DECL_MUTABLE_P (field
))
2173 TREE_READONLY (ref
) = 0;
2178 /* Variant of build_component_ref for use in expressions, which should
2179 never have REFERENCE_TYPE. */
2182 build_x_component_ref (datum
, component
, basetype_path
, protect
)
2183 tree datum
, component
, basetype_path
;
2186 tree t
= build_component_ref (datum
, component
, basetype_path
, protect
);
2188 if (! processing_template_decl
)
2189 t
= convert_from_reference (t
);
2194 /* Given an expression PTR for a pointer, return an expression
2195 for the value pointed to.
2196 ERRORSTRING is the name of the operator to appear in error messages.
2198 This function may need to overload OPERATOR_FNNAME.
2199 Must also handle REFERENCE_TYPEs for C++. */
2202 build_x_indirect_ref (ptr
, errorstring
)
2208 if (processing_template_decl
)
2209 return build_min_nt (INDIRECT_REF
, ptr
);
2211 rval
= build_opfncall (INDIRECT_REF
, LOOKUP_NORMAL
, ptr
, NULL_TREE
,
2215 return build_indirect_ref (ptr
, errorstring
);
2219 build_indirect_ref (ptr
, errorstring
)
2223 register tree pointer
, type
;
2225 if (ptr
== error_mark_node
)
2226 return error_mark_node
;
2228 pointer
= (TREE_CODE (TREE_TYPE (ptr
)) == REFERENCE_TYPE
2229 ? ptr
: default_conversion (ptr
));
2230 type
= TREE_TYPE (pointer
);
2232 if (ptr
== current_class_ptr
)
2233 return current_class_ref
;
2235 if (TREE_CODE (type
) == POINTER_TYPE
|| TREE_CODE (type
) == REFERENCE_TYPE
)
2237 if (TREE_CODE (pointer
) == ADDR_EXPR
2239 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (pointer
, 0)))
2240 == TYPE_MAIN_VARIANT (TREE_TYPE (type
)))
2241 && (TREE_READONLY (TREE_OPERAND (pointer
, 0))
2242 == TYPE_READONLY (TREE_TYPE (type
)))
2243 && (TREE_THIS_VOLATILE (TREE_OPERAND (pointer
, 0))
2244 == TYPE_VOLATILE (TREE_TYPE (type
))))
2245 return TREE_OPERAND (pointer
, 0);
2248 tree t
= TREE_TYPE (type
);
2249 register tree ref
= build1 (INDIRECT_REF
,
2250 TYPE_MAIN_VARIANT (t
), pointer
);
2252 /* We *must* set TREE_READONLY when dereferencing a pointer to const,
2253 so that we get the proper error message if the result is used
2254 to assign to. Also, &* is supposed to be a no-op. */
2255 TREE_READONLY (ref
) = TYPE_READONLY (t
);
2256 TREE_SIDE_EFFECTS (ref
)
2257 = (TYPE_VOLATILE (t
) || TREE_SIDE_EFFECTS (pointer
)
2259 TREE_THIS_VOLATILE (ref
) = TYPE_VOLATILE (t
);
2263 /* `pointer' won't be an error_mark_node if we were given a
2264 pointer to member, so it's cool to check for this here. */
2265 else if (TYPE_PTRMEMFUNC_P (type
))
2266 error ("invalid use of `%s' on pointer to member function", errorstring
);
2267 else if (TREE_CODE (type
) == RECORD_TYPE
2268 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
)))
2269 error ("cannot dereference signature pointer/reference");
2270 else if (pointer
!= error_mark_node
)
2273 error ("invalid type argument of `%s'", errorstring
);
2275 error ("invalid type argument");
2277 return error_mark_node
;
2280 /* This handles expressions of the form "a[i]", which denotes
2283 This is logically equivalent in C to *(a+i), but we may do it differently.
2284 If A is a variable or a member, we generate a primitive ARRAY_REF.
2285 This avoids forcing the array out of registers, and can work on
2286 arrays that are not lvalues (for example, members of structures returned
2289 If INDEX is of some user-defined type, it must be converted to
2290 integer type. Otherwise, to make a compatible PLUS_EXPR, it
2291 will inherit the type of the array, which will be some pointer type. */
2294 build_array_ref (array
, idx
)
2299 error ("subscript missing in array reference");
2300 return error_mark_node
;
2303 if (TREE_TYPE (array
) == error_mark_node
2304 || TREE_TYPE (idx
) == error_mark_node
)
2305 return error_mark_node
;
2307 if (TREE_CODE (TREE_TYPE (array
)) == ARRAY_TYPE
2308 && TREE_CODE (array
) != INDIRECT_REF
)
2312 /* Subscripting with type char is likely to lose
2313 on a machine where chars are signed.
2314 So warn on any machine, but optionally.
2315 Don't warn for unsigned char since that type is safe.
2316 Don't warn for signed char because anyone who uses that
2317 must have done so deliberately. */
2318 if (warn_char_subscripts
2319 && TYPE_MAIN_VARIANT (TREE_TYPE (idx
)) == char_type_node
)
2320 warning ("array subscript has type `char'");
2322 /* Apply default promotions *after* noticing character types. */
2323 idx
= default_conversion (idx
);
2325 if (TREE_CODE (TREE_TYPE (idx
)) != INTEGER_TYPE
)
2327 error ("array subscript is not an integer");
2328 return error_mark_node
;
2331 /* An array that is indexed by a non-constant
2332 cannot be stored in a register; we must be able to do
2333 address arithmetic on its address.
2334 Likewise an array of elements of variable size. */
2335 if (TREE_CODE (idx
) != INTEGER_CST
2336 || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
))) != 0
2337 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
))))
2340 if (mark_addressable (array
) == 0)
2341 return error_mark_node
;
2343 /* An array that is indexed by a constant value which is not within
2344 the array bounds cannot be stored in a register either; because we
2345 would get a crash in store_bit_field/extract_bit_field when trying
2346 to access a non-existent part of the register. */
2347 if (TREE_CODE (idx
) == INTEGER_CST
2348 && TYPE_VALUES (TREE_TYPE (array
))
2349 && ! int_fits_type_p (idx
, TYPE_VALUES (TREE_TYPE (array
))))
2351 if (mark_addressable (array
) == 0)
2352 return error_mark_node
;
2355 if (pedantic
&& !lvalue_p (array
))
2356 pedwarn ("ANSI C++ forbids subscripting non-lvalue array");
2358 /* Note in C++ it is valid to subscript a `register' array, since
2359 it is valid to take the address of something with that
2360 storage specification. */
2364 while (TREE_CODE (foo
) == COMPONENT_REF
)
2365 foo
= TREE_OPERAND (foo
, 0);
2366 if (TREE_CODE (foo
) == VAR_DECL
&& DECL_REGISTER (foo
))
2367 warning ("subscripting array declared `register'");
2370 type
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array
)));
2371 rval
= build (ARRAY_REF
, type
, array
, idx
);
2372 /* Array ref is const/volatile if the array elements are
2373 or if the array is.. */
2374 TREE_READONLY (rval
)
2375 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array
)))
2376 | TREE_READONLY (array
));
2377 TREE_SIDE_EFFECTS (rval
)
2378 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
2379 | TREE_SIDE_EFFECTS (array
));
2380 TREE_THIS_VOLATILE (rval
)
2381 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
2382 /* This was added by rms on 16 Nov 91.
2383 It fixes vol struct foo *a; a->elts[1]
2384 in an inline function.
2385 Hope it doesn't break something else. */
2386 | TREE_THIS_VOLATILE (array
));
2387 return require_complete_type (fold (rval
));
2391 tree ar
= default_conversion (array
);
2392 tree ind
= default_conversion (idx
);
2394 /* Put the integer in IND to simplify error checking. */
2395 if (TREE_CODE (TREE_TYPE (ar
)) == INTEGER_TYPE
)
2402 if (ar
== error_mark_node
)
2405 if (TREE_CODE (TREE_TYPE (ar
)) != POINTER_TYPE
)
2407 error ("subscripted value is neither array nor pointer");
2408 return error_mark_node
;
2410 if (TREE_CODE (TREE_TYPE (ind
)) != INTEGER_TYPE
)
2412 error ("array subscript is not an integer");
2413 return error_mark_node
;
2416 return build_indirect_ref (build_binary_op_nodefault (PLUS_EXPR
, ar
,
2422 /* Build a function call to function FUNCTION with parameters PARAMS.
2423 PARAMS is a list--a chain of TREE_LIST nodes--in which the
2424 TREE_VALUE of each node is a parameter-expression. The PARAMS do
2425 not include any object pointer that may be required. FUNCTION's
2426 data type may be a function type or a pointer-to-function.
2428 For C++: If FUNCTION's data type is a TREE_LIST, then the tree list
2429 is the list of possible methods that FUNCTION could conceivably
2430 be. If the list of methods comes from a class, then it will be
2431 a list of lists (where each element is associated with the class
2432 that produced it), otherwise it will be a simple list (for
2433 functions overloaded in global scope).
2435 In the first case, TREE_VALUE (function) is the head of one of those
2436 lists, and TREE_PURPOSE is the name of the function.
2438 In the second case, TREE_PURPOSE (function) is the function's
2441 DECL is the class instance variable, usually CURRENT_CLASS_REF.
2443 When calling a TEMPLATE_DECL, we don't require a complete return
2447 build_x_function_call (function
, params
, decl
)
2448 tree function
, params
, decl
;
2451 tree template_id
= NULL_TREE
;
2454 if (function
== error_mark_node
)
2455 return error_mark_node
;
2457 if (processing_template_decl
)
2458 return build_min_nt (CALL_EXPR
, function
, params
, NULL_TREE
);
2460 /* Save explicit template arguments if found */
2461 if (TREE_CODE (function
) == TEMPLATE_ID_EXPR
)
2463 template_id
= function
;
2464 function
= TREE_OPERAND (function
, 0);
2467 type
= TREE_TYPE (function
);
2469 if (TREE_CODE (type
) == OFFSET_TYPE
2470 && TREE_TYPE (type
) == unknown_type_node
2471 && TREE_CODE (function
) == TREE_LIST
2472 && TREE_CHAIN (function
) == NULL_TREE
)
2474 /* Undo (Foo:bar)()... */
2475 type
= TYPE_OFFSET_BASETYPE (type
);
2476 function
= TREE_VALUE (function
);
2477 my_friendly_assert (TREE_CODE (function
) == TREE_LIST
, 999);
2478 my_friendly_assert (TREE_CHAIN (function
) == NULL_TREE
, 999);
2479 function
= TREE_VALUE (function
);
2480 if (TREE_CODE (function
) == OVERLOAD
)
2481 function
= OVL_FUNCTION (function
);
2482 my_friendly_assert (TREE_CODE (function
) == FUNCTION_DECL
, 999);
2483 function
= DECL_NAME (function
);
2484 return build_method_call (decl
, function
, params
,
2485 TYPE_BINFO (type
), LOOKUP_NORMAL
);
2488 is_method
= ((TREE_CODE (function
) == TREE_LIST
2489 && current_class_type
!= NULL_TREE
2490 && (IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (function
))
2492 || TREE_CODE (function
) == IDENTIFIER_NODE
2493 || TREE_CODE (type
) == METHOD_TYPE
2494 || TYPE_PTRMEMFUNC_P (type
));
2496 if ((TREE_CODE (function
) == FUNCTION_DECL
2497 && DECL_STATIC_FUNCTION_P (function
))
2498 || (TREE_CODE (function
) == TEMPLATE_DECL
2499 && DECL_STATIC_FUNCTION_P (DECL_RESULT (function
))))
2500 return build_member_call
2501 (DECL_CONTEXT (function
), DECL_NAME (function
), params
);
2503 /* A friend template. Make it look like a toplevel declaration. */
2504 if (! is_method
&& TREE_CODE (function
) == TEMPLATE_DECL
)
2505 function
= scratch_ovl_cons (function
, NULL_TREE
);
2507 /* Handle methods, friends, and overloaded functions, respectively. */
2510 tree basetype
= NULL_TREE
;
2512 if (TREE_CODE (function
) == FUNCTION_DECL
2513 || DECL_FUNCTION_TEMPLATE_P (function
))
2515 basetype
= DECL_CLASS_CONTEXT (function
);
2517 if (DECL_NAME (function
))
2518 function
= DECL_NAME (function
);
2520 function
= TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function
));
2522 else if (TREE_CODE (function
) == TREE_LIST
)
2524 my_friendly_assert (TREE_CODE (TREE_VALUE (function
))
2525 == FUNCTION_DECL
, 312);
2526 basetype
= DECL_CLASS_CONTEXT (TREE_VALUE (function
));
2527 function
= TREE_PURPOSE (function
);
2529 else if (TREE_CODE (function
) != IDENTIFIER_NODE
)
2531 if (TREE_CODE (function
) == OFFSET_REF
)
2533 if (TREE_OPERAND (function
, 0))
2534 decl
= TREE_OPERAND (function
, 0);
2536 /* Call via a pointer to member function. */
2537 if (decl
== NULL_TREE
)
2539 error ("pointer to member function called, but not in class scope");
2540 return error_mark_node
;
2542 /* What other type of POINTER_TYPE could this be? */
2543 if (TREE_CODE (TREE_TYPE (function
)) != POINTER_TYPE
2544 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (function
))
2545 && TREE_CODE (function
) != OFFSET_REF
)
2546 function
= build (OFFSET_REF
, TREE_TYPE (type
), NULL_TREE
,
2551 /* this is an abbreviated method call.
2552 must go through here in case it is a virtual function.
2553 @@ Perhaps this could be optimized. */
2555 if (basetype
&& (! current_class_type
2556 || ! DERIVED_FROM_P (basetype
, current_class_type
)))
2557 return build_member_call (basetype
, function
, params
);
2559 if (decl
== NULL_TREE
)
2561 if (current_class_type
== NULL_TREE
)
2563 error ("object missing in call to method `%s'",
2564 IDENTIFIER_POINTER (function
));
2565 return error_mark_node
;
2567 /* Yow: call from a static member function. */
2568 decl
= build1 (NOP_EXPR
, build_pointer_type (current_class_type
),
2570 decl
= build_indirect_ref (decl
, NULL_PTR
);
2573 /* Put back explicit template arguments, if any. */
2575 function
= template_id
;
2576 return build_method_call (decl
, function
, params
,
2577 NULL_TREE
, LOOKUP_NORMAL
);
2579 else if (TREE_CODE (function
) == COMPONENT_REF
2580 && type
== unknown_type_node
)
2582 /* Should we undo what was done in build_component_ref? */
2583 if (TREE_CODE (TREE_PURPOSE (TREE_OPERAND (function
, 1))) == TREE_VEC
)
2584 /* Get the name that build_component_ref hid. */
2585 function
= DECL_NAME (TREE_VALUE (TREE_OPERAND (function
, 1)));
2587 function
= TREE_PURPOSE (TREE_OPERAND (function
, 1));
2588 return build_method_call (decl
, function
, params
,
2589 NULL_TREE
, LOOKUP_NORMAL
);
2591 else if (really_overloaded_fn (function
))
2593 if (OVL_FUNCTION (function
) == NULL_TREE
)
2595 cp_error ("function `%D' declared overloaded, but no definitions appear with which to resolve it?!?",
2596 TREE_PURPOSE (function
));
2597 return error_mark_node
;
2601 /* Put back explicit template arguments, if any. */
2603 function
= template_id
;
2604 return build_new_function_call (function
, params
);
2608 /* Remove a potential OVERLOAD around it */
2609 function
= OVL_CURRENT (function
);
2612 if (TREE_CODE (function
) == OFFSET_REF
)
2614 /* If the component is a data element (or a virtual function), we play
2615 games here to make things work. */
2618 if (TREE_OPERAND (function
, 0))
2619 decl
= TREE_OPERAND (function
, 0);
2621 decl
= current_class_ref
;
2623 decl_addr
= build_unary_op (ADDR_EXPR
, decl
, 0);
2625 /* Sigh. OFFSET_REFs are being used for too many things.
2626 They're being used both for -> and ->*, and we want to resolve
2627 the -> cases here, but leave the ->*. We could use
2628 resolve_offset_ref for those, too, but it would call
2629 get_member_function_from_ptrfunc and decl_addr wouldn't get
2630 updated properly. Nasty. */
2631 if (TREE_CODE (TREE_OPERAND (function
, 1)) == FIELD_DECL
)
2632 function
= resolve_offset_ref (function
);
2634 function
= TREE_OPERAND (function
, 1);
2636 function
= get_member_function_from_ptrfunc (&decl_addr
, function
);
2637 params
= expr_tree_cons (NULL_TREE
, decl_addr
, params
);
2638 return build_function_call (function
, params
);
2641 type
= TREE_TYPE (function
);
2642 if (type
!= error_mark_node
)
2644 if (TREE_CODE (type
) == REFERENCE_TYPE
)
2645 type
= TREE_TYPE (type
);
2647 if (IS_AGGR_TYPE (type
))
2648 return build_opfncall (CALL_EXPR
, LOOKUP_NORMAL
, function
, params
, NULL_TREE
);
2653 tree fntype
= TREE_TYPE (function
);
2654 tree ctypeptr
= NULL_TREE
;
2656 /* Explicitly named method? */
2657 if (TREE_CODE (function
) == FUNCTION_DECL
)
2658 ctypeptr
= build_pointer_type (DECL_CLASS_CONTEXT (function
));
2659 /* Expression with ptr-to-method type? It could either be a plain
2660 usage, or it might be a case where the ptr-to-method is being
2661 passed in as an argument. */
2662 else if (TYPE_PTRMEMFUNC_P (fntype
))
2664 tree rec
= TYPE_METHOD_BASETYPE (TREE_TYPE
2665 (TYPE_PTRMEMFUNC_FN_TYPE (fntype
)));
2666 ctypeptr
= build_pointer_type (rec
);
2668 /* Unexpected node type? */
2670 my_friendly_abort (116);
2671 if (decl
== NULL_TREE
)
2673 if (current_function_decl
2674 && DECL_STATIC_FUNCTION_P (current_function_decl
))
2675 error ("invalid call to member function needing `this' in static member function scope");
2677 error ("pointer to member function called, but not in class scope");
2678 return error_mark_node
;
2680 if (TREE_CODE (TREE_TYPE (decl
)) != POINTER_TYPE
2681 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (decl
)))
2683 decl
= build_unary_op (ADDR_EXPR
, decl
, 0);
2684 decl
= convert_pointer_to (TREE_TYPE (ctypeptr
), decl
);
2687 decl
= build_c_cast (ctypeptr
, decl
);
2688 params
= expr_tree_cons (NULL_TREE
, decl
, params
);
2691 return build_function_call (function
, params
);
2694 /* Resolve a pointer to member function. INSTANCE is the object
2695 instance to use, if the member points to a virtual member. */
2698 get_member_function_from_ptrfunc (instance_ptrptr
, function
)
2699 tree
*instance_ptrptr
;
2702 if (TREE_CODE (function
) == OFFSET_REF
)
2704 function
= TREE_OPERAND (function
, 1);
2707 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function
)))
2709 tree fntype
, idx
, e1
, delta
, delta2
, e2
, e3
, aref
, vtbl
;
2710 tree instance
, basetype
;
2712 tree instance_ptr
= *instance_ptrptr
;
2714 if (TREE_SIDE_EFFECTS (instance_ptr
))
2715 instance_ptr
= save_expr (instance_ptr
);
2717 if (TREE_SIDE_EFFECTS (function
))
2718 function
= save_expr (function
);
2720 fntype
= TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (function
));
2721 basetype
= TYPE_METHOD_BASETYPE (TREE_TYPE (fntype
));
2723 delta
= cp_convert (ptrdiff_type_node
,
2724 build_component_ref (function
, delta_identifier
,
2726 e3
= PFN_FROM_PTRMEMFUNC (function
);
2728 if (TYPE_SIZE (basetype
) != NULL_TREE
2729 && ! TYPE_VIRTUAL_P (basetype
))
2730 /* If basetype doesn't have virtual functions, don't emit code to
2731 handle that case. */
2735 /* Promoting idx before saving it improves performance on RISC
2736 targets. Without promoting, the first compare used
2737 load-with-sign-extend, while the second used normal load then
2738 shift to sign-extend. An optimizer flaw, perhaps, but it's
2739 easier to make this change. */
2740 idx
= save_expr (default_conversion
2741 (build_component_ref (function
,
2744 e1
= build_binary_op (GT_EXPR
, idx
, integer_zero_node
, 1);
2746 /* Convert down to the right base, before using the instance. */
2747 instance
= convert_pointer_to_real (basetype
, instance_ptr
);
2748 if (instance
== error_mark_node
&& instance_ptr
!= error_mark_node
)
2751 vtbl
= convert_pointer_to (ptr_type_node
, instance
);
2752 delta2
= DELTA2_FROM_PTRMEMFUNC (function
);
2755 build_pointer_type (build_pointer_type (vtable_entry_type
)),
2756 vtbl
, cp_convert (ptrdiff_type_node
, delta2
));
2757 vtbl
= build_indirect_ref (vtbl
, NULL_PTR
);
2758 aref
= build_array_ref (vtbl
, build_binary_op (MINUS_EXPR
,
2760 integer_one_node
, 1));
2761 if (! flag_vtable_thunks
)
2763 aref
= save_expr (aref
);
2765 delta
= build_binary_op
2767 build_conditional_expr (e1
,
2768 build_component_ref (aref
,
2775 if (flag_vtable_thunks
)
2778 e2
= build_component_ref (aref
, pfn_identifier
, NULL_TREE
, 0);
2779 TREE_TYPE (e2
) = TREE_TYPE (e3
);
2780 e1
= build_conditional_expr (e1
, e2
, e3
);
2782 /* Make sure this doesn't get evaluated first inside one of the
2783 branches of the COND_EXPR. */
2784 if (TREE_CODE (instance_ptr
) == SAVE_EXPR
)
2785 e1
= build (COMPOUND_EXPR
, TREE_TYPE (e1
),
2789 *instance_ptrptr
= build (PLUS_EXPR
, TREE_TYPE (instance_ptr
),
2790 instance_ptr
, delta
);
2792 if (instance_ptr
== error_mark_node
2793 && TREE_CODE (e1
) != ADDR_EXPR
2794 && TREE_CODE (TREE_OPERAND (e1
, 0)) != FUNCTION_DECL
)
2795 cp_error ("object missing in `%E'", function
);
2803 build_function_call_real (function
, params
, require_complete
, flags
)
2804 tree function
, params
;
2805 int require_complete
, flags
;
2807 register tree fntype
, fndecl
;
2808 register tree value_type
;
2809 register tree coerced_params
;
2810 tree name
= NULL_TREE
, assembler_name
= NULL_TREE
;
2813 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
2814 Strip such NOP_EXPRs, since FUNCTION is used in non-lvalue context. */
2815 if (TREE_CODE (function
) == NOP_EXPR
2816 && TREE_TYPE (function
) == TREE_TYPE (TREE_OPERAND (function
, 0)))
2817 function
= TREE_OPERAND (function
, 0);
2819 if (TREE_CODE (function
) == FUNCTION_DECL
)
2821 name
= DECL_NAME (function
);
2822 assembler_name
= DECL_ASSEMBLER_NAME (function
);
2824 GNU_xref_call (current_function_decl
,
2825 IDENTIFIER_POINTER (name
? name
2826 : TYPE_IDENTIFIER (DECL_CLASS_CONTEXT
2828 mark_used (function
);
2831 /* Convert anything with function type to a pointer-to-function. */
2832 if (pedantic
&& DECL_MAIN_P (function
))
2833 pedwarn ("ANSI C++ forbids calling `main' from within program");
2835 /* Differs from default_conversion by not setting TREE_ADDRESSABLE
2836 (because calling an inline function does not mean the function
2837 needs to be separately compiled). */
2839 if (DECL_INLINE (function
))
2840 function
= inline_conversion (function
);
2842 function
= build_addr_func (function
);
2848 function
= build_addr_func (function
);
2851 if (function
== error_mark_node
)
2852 return error_mark_node
;
2854 fntype
= TREE_TYPE (function
);
2856 if (TYPE_PTRMEMFUNC_P (fntype
))
2858 cp_error ("must use .* or ->* to call pointer-to-member function in `%E (...)'",
2860 return error_mark_node
;
2863 is_method
= (TREE_CODE (fntype
) == POINTER_TYPE
2864 && TREE_CODE (TREE_TYPE (fntype
)) == METHOD_TYPE
);
2866 if (!((TREE_CODE (fntype
) == POINTER_TYPE
2867 && TREE_CODE (TREE_TYPE (fntype
)) == FUNCTION_TYPE
)
2869 || TREE_CODE (function
) == TEMPLATE_ID_EXPR
))
2871 cp_error ("`%E' cannot be used as a function", function
);
2872 return error_mark_node
;
2875 /* fntype now gets the type of function pointed to. */
2876 fntype
= TREE_TYPE (fntype
);
2878 /* Convert the parameters to the types declared in the
2879 function prototype, or apply default promotions. */
2881 if (flags
& LOOKUP_COMPLAIN
)
2882 coerced_params
= convert_arguments (NULL_TREE
, TYPE_ARG_TYPES (fntype
),
2883 params
, fndecl
, LOOKUP_NORMAL
);
2885 coerced_params
= convert_arguments (NULL_TREE
, TYPE_ARG_TYPES (fntype
),
2888 if (coerced_params
== error_mark_node
)
2890 if (flags
& LOOKUP_SPECULATIVELY
)
2893 return error_mark_node
;
2896 /* Check for errors in format strings. */
2898 if (warn_format
&& (name
|| assembler_name
))
2899 check_function_format (name
, assembler_name
, coerced_params
);
2901 /* Recognize certain built-in functions so we can make tree-codes
2902 other than CALL_EXPR. We do this when it enables fold-const.c
2903 to do something useful. */
2905 if (TREE_CODE (function
) == ADDR_EXPR
2906 && TREE_CODE (TREE_OPERAND (function
, 0)) == FUNCTION_DECL
2907 && DECL_BUILT_IN (TREE_OPERAND (function
, 0)))
2908 switch (DECL_FUNCTION_CODE (TREE_OPERAND (function
, 0)))
2913 if (coerced_params
== 0)
2914 return integer_zero_node
;
2915 return build_unary_op (ABS_EXPR
, TREE_VALUE (coerced_params
), 0);
2922 value_type
= TREE_TYPE (fntype
) ? TREE_TYPE (fntype
) : void_type_node
;
2924 register tree result
2925 = build_call (function
, value_type
, coerced_params
);
2927 if (require_complete
)
2929 if (value_type
== void_type_node
)
2931 result
= require_complete_type (result
);
2933 if (IS_AGGR_TYPE (value_type
))
2934 result
= build_cplus_new (value_type
, result
);
2935 return convert_from_reference (result
);
2940 build_function_call (function
, params
)
2941 tree function
, params
;
2943 return build_function_call_real (function
, params
, 1, LOOKUP_NORMAL
);
2946 /* Convert the actual parameter expressions in the list VALUES
2947 to the types in the list TYPELIST.
2948 If parmdecls is exhausted, or when an element has NULL as its type,
2949 perform the default conversions.
2951 RETURN_LOC is the location of the return value, if known, NULL_TREE
2952 otherwise. This is useful in the case where we can avoid creating
2953 a temporary variable in the case where we can initialize the return
2954 value directly. If we are not eliding constructors, then we set this
2955 to NULL_TREE to avoid this avoidance.
2957 NAME is an IDENTIFIER_NODE or 0. It is used only for error messages.
2959 This is also where warnings about wrong number of args are generated.
2961 Return a list of expressions for the parameters as converted.
2963 Both VALUES and the returned value are chains of TREE_LIST nodes
2964 with the elements of the list in the TREE_VALUE slots of those nodes.
2966 In C++, unspecified trailing parameters can be filled in with their
2967 default arguments, if such were specified. Do so here. */
2970 convert_arguments (return_loc
, typelist
, values
, fndecl
, flags
)
2971 tree return_loc
, typelist
, values
, fndecl
;
2974 register tree typetail
, valtail
;
2975 register tree result
= NULL_TREE
;
2976 char *called_thing
= 0;
2979 if (! flag_elide_constructors
)
2982 /* Argument passing is always copy-initialization. */
2983 flags
|= LOOKUP_ONLYCONVERTING
;
2987 if (TREE_CODE (TREE_TYPE (fndecl
)) == METHOD_TYPE
)
2989 if (DECL_NAME (fndecl
) == NULL_TREE
2990 || IDENTIFIER_HAS_TYPE_VALUE (DECL_NAME (fndecl
)))
2991 called_thing
= "constructor";
2993 called_thing
= "member function";
2996 called_thing
= "function";
2999 for (valtail
= values
, typetail
= typelist
;
3001 valtail
= TREE_CHAIN (valtail
), i
++)
3003 register tree type
= typetail
? TREE_VALUE (typetail
) : 0;
3004 register tree val
= TREE_VALUE (valtail
);
3006 if (val
== error_mark_node
)
3007 return error_mark_node
;
3009 if (type
== void_type_node
)
3013 cp_error_at ("too many arguments to %s `%+D'", called_thing
,
3015 error ("at this point in file");
3018 error ("too many arguments to function");
3019 /* In case anybody wants to know if this argument
3022 TREE_TYPE (tree_last (result
)) = error_mark_node
;
3026 /* The tree type of the parameter being passed may not yet be
3027 known. In this case, its type is TYPE_UNKNOWN, and will
3028 be instantiated by the type given by TYPE. If TYPE
3029 is also NULL, the tree type of VAL is ERROR_MARK_NODE. */
3030 if (type
&& type_unknown_p (val
))
3031 val
= require_instantiated_type (type
, val
, integer_zero_node
);
3032 else if (type_unknown_p (val
))
3034 /* Strip the `&' from an overloaded FUNCTION_DECL. */
3035 if (TREE_CODE (val
) == ADDR_EXPR
)
3036 val
= TREE_OPERAND (val
, 0);
3037 if (really_overloaded_fn (val
))
3038 cp_error ("insufficient type information to resolve address of overloaded function `%D'",
3039 DECL_NAME (get_first_fn (val
)));
3041 error ("insufficient type information in parameter list");
3042 val
= integer_zero_node
;
3044 else if (TREE_CODE (val
) == OFFSET_REF
3045 && TREE_CODE (TREE_TYPE (val
)) == METHOD_TYPE
)
3047 /* This is unclean. Should be handled elsewhere. */
3048 val
= build_unary_op (ADDR_EXPR
, val
, 0);
3050 else if (TREE_CODE (val
) == OFFSET_REF
)
3051 val
= resolve_offset_ref (val
);
3053 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
3054 Strip such NOP_EXPRs, since VAL is used in non-lvalue context. */
3055 if (TREE_CODE (val
) == NOP_EXPR
3056 && TREE_TYPE (val
) == TREE_TYPE (TREE_OPERAND (val
, 0))
3057 && (type
== 0 || TREE_CODE (type
) != REFERENCE_TYPE
))
3058 val
= TREE_OPERAND (val
, 0);
3060 if (type
== 0 || TREE_CODE (type
) != REFERENCE_TYPE
)
3062 if (TREE_CODE (TREE_TYPE (val
)) == ARRAY_TYPE
3063 || TREE_CODE (TREE_TYPE (val
)) == FUNCTION_TYPE
3064 || TREE_CODE (TREE_TYPE (val
)) == METHOD_TYPE
)
3065 val
= default_conversion (val
);
3067 val
= require_complete_type (val
);
3070 if (val
== error_mark_node
)
3071 return error_mark_node
;
3075 /* Formal parm type is specified by a function prototype. */
3078 if (TYPE_SIZE (complete_type (type
)) == 0)
3080 error ("parameter type of called function is incomplete");
3085 parmval
= convert_for_initialization
3086 (return_loc
, type
, val
, flags
,
3087 "argument passing", fndecl
, i
);
3088 #ifdef PROMOTE_PROTOTYPES
3089 if ((TREE_CODE (type
) == INTEGER_TYPE
3090 || TREE_CODE (type
) == ENUMERAL_TYPE
)
3091 && (TYPE_PRECISION (type
)
3092 < TYPE_PRECISION (integer_type_node
)))
3093 parmval
= default_conversion (parmval
);
3097 if (parmval
== error_mark_node
)
3098 return error_mark_node
;
3100 result
= expr_tree_cons (NULL_TREE
, parmval
, result
);
3104 if (TREE_CODE (TREE_TYPE (val
)) == REFERENCE_TYPE
)
3105 val
= convert_from_reference (val
);
3107 result
= expr_tree_cons (NULL_TREE
,
3108 convert_arg_to_ellipsis (val
),
3113 typetail
= TREE_CHAIN (typetail
);
3116 if (typetail
!= 0 && typetail
!= void_list_node
)
3118 /* See if there are default arguments that can be used */
3119 if (TREE_PURPOSE (typetail
))
3121 for (; typetail
!= void_list_node
; ++i
)
3123 tree type
= TREE_VALUE (typetail
);
3124 tree val
= TREE_PURPOSE (typetail
);
3125 tree parmval
= convert_default_arg (type
, val
);
3127 if (parmval
== error_mark_node
)
3128 return error_mark_node
;
3130 result
= expr_tree_cons (0, parmval
, result
);
3131 typetail
= TREE_CHAIN (typetail
);
3132 /* ends with `...'. */
3133 if (typetail
== NULL_TREE
)
3141 char *buf
= (char *)alloca (32 + strlen (called_thing
));
3142 sprintf (buf
, "too few arguments to %s `%%#D'", called_thing
);
3143 cp_error_at (buf
, fndecl
);
3144 error ("at this point in file");
3147 error ("too few arguments to function");
3148 return error_mark_list
;
3152 return nreverse (result
);
3155 /* Build a binary-operation expression, after performing default
3156 conversions on the operands. CODE is the kind of expression to build. */
3159 build_x_binary_op (code
, arg1
, arg2
)
3160 enum tree_code code
;
3163 if (processing_template_decl
)
3164 return build_min_nt (code
, arg1
, arg2
);
3166 return build_new_op (code
, LOOKUP_NORMAL
, arg1
, arg2
, NULL_TREE
);
3170 build_binary_op (code
, arg1
, arg2
, convert_p
)
3171 enum tree_code code
;
3183 args
[0] = decay_conversion (args
[0]);
3184 args
[1] = decay_conversion (args
[1]);
3186 if (args
[0] == error_mark_node
|| args
[1] == error_mark_node
)
3187 return error_mark_node
;
3189 type0
= TREE_TYPE (args
[0]);
3190 type1
= TREE_TYPE (args
[1]);
3192 if (type_unknown_p (args
[0]))
3194 args
[0] = instantiate_type (type1
, args
[0], 1);
3195 args
[0] = decay_conversion (args
[0]);
3197 else if (type_unknown_p (args
[1]))
3199 args
[1] = require_instantiated_type (type0
, args
[1],
3201 args
[1] = decay_conversion (args
[1]);
3204 if (IS_AGGR_TYPE (type0
) || IS_AGGR_TYPE (type1
))
3205 my_friendly_abort (754867);
3207 return build_binary_op_nodefault (code
, args
[0], args
[1], code
);
3210 /* Build a binary-operation expression without default conversions.
3211 CODE is the kind of expression to build.
3212 This function differs from `build' in several ways:
3213 the data type of the result is computed and recorded in it,
3214 warnings are generated if arg data types are invalid,
3215 special handling for addition and subtraction of pointers is known,
3216 and some optimization is done (operations on narrow ints
3217 are done in the narrower type when that gives the same result).
3218 Constant folding is also done before the result is returned.
3220 ERROR_CODE is the code that determines what to say in error messages.
3221 It is usually, but not always, the same as CODE.
3223 Note that the operands will never have enumeral types
3224 because either they have just had the default conversions performed
3225 or they have both just been converted to some other type in which
3226 the arithmetic is to be done.
3228 C++: must do special pointer arithmetic when implementing
3229 multiple inheritance, and deal with pointer to member functions. */
3232 build_binary_op_nodefault (code
, orig_op0
, orig_op1
, error_code
)
3233 enum tree_code code
;
3234 tree orig_op0
, orig_op1
;
3235 enum tree_code error_code
;
3238 register enum tree_code code0
, code1
;
3241 /* Expression code to give to the expression when it is built.
3242 Normally this is CODE, which is what the caller asked for,
3243 but in some special cases we change it. */
3244 register enum tree_code resultcode
= code
;
3246 /* Data type in which the computation is to be performed.
3247 In the simplest cases this is the common type of the arguments. */
3248 register tree result_type
= NULL
;
3250 /* Nonzero means operands have already been type-converted
3251 in whatever way is necessary.
3252 Zero means they need to be converted to RESULT_TYPE. */
3255 /* Nonzero means create the expression with this type, rather than
3257 tree build_type
= 0;
3259 /* Nonzero means after finally constructing the expression
3260 convert it to this type. */
3261 tree final_type
= 0;
3263 /* Nonzero if this is an operation like MIN or MAX which can
3264 safely be computed in short if both args are promoted shorts.
3265 Also implies COMMON.
3266 -1 indicates a bitwise operation; this makes a difference
3267 in the exact conditions for when it is safe to do the operation
3268 in a narrower mode. */
3271 /* Nonzero if this is a comparison operation;
3272 if both args are promoted shorts, compare the original shorts.
3273 Also implies COMMON. */
3274 int short_compare
= 0;
3276 /* Nonzero if this is a right-shift operation, which can be computed on the
3277 original short and then promoted if the operand is a promoted short. */
3278 int short_shift
= 0;
3280 /* Nonzero means set RESULT_TYPE to the common type of the args. */
3283 /* Apply default conversions. */
3284 if (code
== TRUTH_AND_EXPR
|| code
== TRUTH_ANDIF_EXPR
3285 || code
== TRUTH_OR_EXPR
|| code
== TRUTH_ORIF_EXPR
3286 || code
== TRUTH_XOR_EXPR
)
3288 op0
= decay_conversion (orig_op0
);
3289 op1
= decay_conversion (orig_op1
);
3293 op0
= default_conversion (orig_op0
);
3294 op1
= default_conversion (orig_op1
);
3297 type0
= TREE_TYPE (op0
);
3298 type1
= TREE_TYPE (op1
);
3300 /* The expression codes of the data types of the arguments tell us
3301 whether the arguments are integers, floating, pointers, etc. */
3302 code0
= TREE_CODE (type0
);
3303 code1
= TREE_CODE (type1
);
3305 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
3306 STRIP_TYPE_NOPS (op0
);
3307 STRIP_TYPE_NOPS (op1
);
3309 /* If an error was already reported for one of the arguments,
3310 avoid reporting another error. */
3312 if (code0
== ERROR_MARK
|| code1
== ERROR_MARK
)
3313 return error_mark_node
;
3318 /* Handle the pointer + int case. */
3319 if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3320 return pointer_int_sum (PLUS_EXPR
, op0
, op1
);
3321 else if (code1
== POINTER_TYPE
&& code0
== INTEGER_TYPE
)
3322 return pointer_int_sum (PLUS_EXPR
, op1
, op0
);
3328 /* Subtraction of two similar pointers.
3329 We must subtract them as integers, then divide by object size. */
3330 if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
3331 && comp_target_types (type0
, type1
, 1))
3332 return pointer_diff (op0
, op1
, common_type (type0
, type1
));
3333 /* Handle pointer minus int. Just like pointer plus int. */
3334 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3335 return pointer_int_sum (MINUS_EXPR
, op0
, op1
);
3344 case TRUNC_DIV_EXPR
:
3346 case FLOOR_DIV_EXPR
:
3347 case ROUND_DIV_EXPR
:
3348 case EXACT_DIV_EXPR
:
3349 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
3350 || code0
== COMPLEX_TYPE
)
3351 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
3352 || code1
== COMPLEX_TYPE
))
3354 if (TREE_CODE (op1
) == INTEGER_CST
&& integer_zerop (op1
))
3355 cp_warning ("division by zero in `%E / 0'", op0
);
3356 else if (TREE_CODE (op1
) == REAL_CST
&& real_zerop (op1
))
3357 cp_warning ("division by zero in `%E / 0.'", op0
);
3359 if (!(code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
))
3360 resultcode
= RDIV_EXPR
;
3362 /* When dividing two signed integers, we have to promote to int.
3363 unless we divide by a constant != -1. Note that default
3364 conversion will have been performed on the operands at this
3365 point, so we have to dig out the original type to find out if
3367 shorten
= ((TREE_CODE (op0
) == NOP_EXPR
3368 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3369 || (TREE_CODE (op1
) == INTEGER_CST
3370 && (TREE_INT_CST_LOW (op1
) != -1
3371 || TREE_INT_CST_HIGH (op1
) != -1)));
3377 case BIT_ANDTC_EXPR
:
3380 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3382 /* If one operand is a constant, and the other is a short type
3383 that has been converted to an int,
3384 really do the work in the short type and then convert the
3385 result to int. If we are lucky, the constant will be 0 or 1
3386 in the short type, making the entire operation go away. */
3387 if (TREE_CODE (op0
) == INTEGER_CST
3388 && TREE_CODE (op1
) == NOP_EXPR
3389 && (TYPE_PRECISION (type1
)
3390 > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1
, 0))))
3391 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1
, 0))))
3393 final_type
= result_type
;
3394 op1
= TREE_OPERAND (op1
, 0);
3395 result_type
= TREE_TYPE (op1
);
3397 if (TREE_CODE (op1
) == INTEGER_CST
3398 && TREE_CODE (op0
) == NOP_EXPR
3399 && (TYPE_PRECISION (type0
)
3400 > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3401 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3403 final_type
= result_type
;
3404 op0
= TREE_OPERAND (op0
, 0);
3405 result_type
= TREE_TYPE (op0
);
3409 case TRUNC_MOD_EXPR
:
3410 case FLOOR_MOD_EXPR
:
3411 if (code1
== INTEGER_TYPE
&& integer_zerop (op1
))
3412 cp_warning ("division by zero in `%E %% 0'", op0
);
3413 else if (code1
== REAL_TYPE
&& real_zerop (op1
))
3414 cp_warning ("division by zero in `%E %% 0.'", op0
);
3416 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3418 /* Although it would be tempting to shorten always here, that loses
3419 on some targets, since the modulo instruction is undefined if the
3420 quotient can't be represented in the computation mode. We shorten
3421 only if unsigned or if dividing by something we know != -1. */
3422 shorten
= ((TREE_CODE (op0
) == NOP_EXPR
3423 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3424 || (TREE_CODE (op1
) == INTEGER_CST
3425 && (TREE_INT_CST_LOW (op1
) != -1
3426 || TREE_INT_CST_HIGH (op1
) != -1)));
3431 case TRUTH_ANDIF_EXPR
:
3432 case TRUTH_ORIF_EXPR
:
3433 case TRUTH_AND_EXPR
:
3435 result_type
= boolean_type_node
;
3438 /* Shift operations: result has same type as first operand;
3439 always convert second operand to int.
3440 Also set SHORT_SHIFT if shifting rightward. */
3443 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3445 result_type
= type0
;
3446 if (TREE_CODE (op1
) == INTEGER_CST
)
3448 if (tree_int_cst_lt (op1
, integer_zero_node
))
3449 warning ("right shift count is negative");
3452 if (TREE_INT_CST_LOW (op1
) | TREE_INT_CST_HIGH (op1
))
3454 if (TREE_INT_CST_HIGH (op1
) != 0
3455 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3456 >= TYPE_PRECISION (type0
)))
3457 warning ("right shift count >= width of type");
3460 /* Convert the shift-count to an integer, regardless of
3461 size of value being shifted. */
3462 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3463 op1
= cp_convert (integer_type_node
, op1
);
3464 /* Avoid converting op1 to result_type later. */
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 ("left shift count is negative");
3477 else if (TREE_INT_CST_HIGH (op1
) != 0
3478 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3479 >= TYPE_PRECISION (type0
)))
3480 warning ("left shift count >= width of type");
3482 /* Convert the shift-count to an integer, regardless of
3483 size of value being shifted. */
3484 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3485 op1
= cp_convert (integer_type_node
, op1
);
3486 /* Avoid converting op1 to result_type later. */
3493 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3495 result_type
= type0
;
3496 if (TREE_CODE (op1
) == INTEGER_CST
)
3498 if (tree_int_cst_lt (op1
, integer_zero_node
))
3499 warning ("%s rotate count is negative",
3500 (code
== LROTATE_EXPR
) ? "left" : "right");
3501 else if (TREE_INT_CST_HIGH (op1
) != 0
3502 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3503 >= TYPE_PRECISION (type0
)))
3504 warning ("%s rotate count >= width of type",
3505 (code
== LROTATE_EXPR
) ? "left" : "right");
3507 /* Convert the shift-count to an integer, regardless of
3508 size of value being shifted. */
3509 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3510 op1
= cp_convert (integer_type_node
, op1
);
3516 build_type
= boolean_type_node
;
3517 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
3518 || code0
== COMPLEX_TYPE
)
3519 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
3520 || code1
== COMPLEX_TYPE
))
3522 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3524 register tree tt0
= TYPE_MAIN_VARIANT (TREE_TYPE (type0
));
3525 register tree tt1
= TYPE_MAIN_VARIANT (TREE_TYPE (type1
));
3527 if (comp_target_types (type0
, type1
, 1))
3528 result_type
= common_type (type0
, type1
);
3529 else if (tt0
== void_type_node
)
3531 if (pedantic
&& TREE_CODE (tt1
) == FUNCTION_TYPE
3532 && tree_int_cst_lt (TYPE_SIZE (type0
), TYPE_SIZE (type1
)))
3533 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3534 else if (TREE_CODE (tt1
) == OFFSET_TYPE
)
3535 pedwarn ("ANSI C++ forbids conversion of a pointer to member to `void *'");
3537 else if (tt1
== void_type_node
)
3539 if (pedantic
&& TREE_CODE (tt0
) == FUNCTION_TYPE
3540 && tree_int_cst_lt (TYPE_SIZE (type1
), TYPE_SIZE (type0
)))
3541 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3544 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3547 if (result_type
== NULL_TREE
)
3548 result_type
= ptr_type_node
;
3550 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
3551 && integer_zerop (op1
))
3552 result_type
= type0
;
3553 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
3554 && integer_zerop (op0
))
3555 result_type
= type1
;
3556 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3558 result_type
= type0
;
3559 error ("ANSI C++ forbids comparison between pointer and integer");
3561 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
3563 result_type
= type1
;
3564 error ("ANSI C++ forbids comparison between pointer and integer");
3566 else if (TYPE_PTRMEMFUNC_P (type0
) && TREE_CODE (op1
) == INTEGER_CST
3567 && integer_zerop (op1
))
3569 op0
= build_component_ref (op0
, index_identifier
, NULL_TREE
, 0);
3570 op1
= integer_zero_node
;
3571 result_type
= TREE_TYPE (op0
);
3573 else if (TYPE_PTRMEMFUNC_P (type1
) && TREE_CODE (op0
) == INTEGER_CST
3574 && integer_zerop (op0
))
3576 op0
= build_component_ref (op1
, index_identifier
, NULL_TREE
, 0);
3577 op1
= integer_zero_node
;
3578 result_type
= TREE_TYPE (op0
);
3580 else if (TYPE_PTRMEMFUNC_P (type0
) && TYPE_PTRMEMFUNC_P (type1
)
3581 && (TYPE_PTRMEMFUNC_FN_TYPE (type0
)
3582 == TYPE_PTRMEMFUNC_FN_TYPE (type1
)))
3584 /* The code we generate for the test is:
3586 (op0.index == op1.index
3587 && ((op1.index != -1 && op0.delta2 == op1.delta2)
3588 || op0.pfn == op1.pfn)) */
3590 tree index0
= build_component_ref (op0
, index_identifier
,
3592 tree index1
= save_expr (build_component_ref (op1
, index_identifier
,
3594 tree pfn0
= PFN_FROM_PTRMEMFUNC (op0
);
3595 tree pfn1
= PFN_FROM_PTRMEMFUNC (op1
);
3596 tree delta20
= DELTA2_FROM_PTRMEMFUNC (op0
);
3597 tree delta21
= DELTA2_FROM_PTRMEMFUNC (op1
);
3599 tree integer_neg_one_node
3600 = build_binary_op (MINUS_EXPR
, integer_zero_node
,
3601 integer_one_node
, 1);
3602 e1
= build_binary_op (EQ_EXPR
, index0
, index1
, 1);
3603 e2
= build_binary_op (NE_EXPR
, index1
, integer_neg_one_node
, 1);
3604 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e2
,
3605 build_binary_op (EQ_EXPR
, delta20
, delta21
, 1),
3607 e3
= build_binary_op (EQ_EXPR
, pfn0
, pfn1
, 1);
3608 e2
= build_binary_op (TRUTH_ORIF_EXPR
, e2
, e3
, 1);
3609 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e1
, e2
, 1);
3610 if (code
== EQ_EXPR
)
3612 return build_binary_op (EQ_EXPR
, e2
, integer_zero_node
, 1);
3614 else if (TYPE_PTRMEMFUNC_P (type0
)
3615 && TYPE_PTRMEMFUNC_FN_TYPE (type0
) == type1
)
3617 tree index0
= build_component_ref (op0
, index_identifier
,
3620 tree pfn0
= PFN_FROM_PTRMEMFUNC (op0
);
3621 tree delta20
= DELTA2_FROM_PTRMEMFUNC (op0
);
3622 tree delta21
= integer_zero_node
;
3624 tree integer_neg_one_node
3625 = build_binary_op (MINUS_EXPR
, integer_zero_node
, integer_one_node
, 1);
3626 if (TREE_CODE (TREE_OPERAND (op1
, 0)) == FUNCTION_DECL
3627 && DECL_VINDEX (TREE_OPERAND (op1
, 0)))
3629 /* Map everything down one to make room for
3630 the null pointer to member. */
3631 index1
= size_binop (PLUS_EXPR
,
3632 DECL_VINDEX (TREE_OPERAND (op1
, 0)),
3634 op1
= integer_zero_node
;
3635 delta21
= CLASSTYPE_VFIELD (TYPE_METHOD_BASETYPE
3636 (TREE_TYPE (type1
)));
3637 delta21
= DECL_FIELD_BITPOS (delta21
);
3638 delta21
= size_binop (FLOOR_DIV_EXPR
, delta21
,
3639 size_int (BITS_PER_UNIT
));
3640 delta21
= convert (sizetype
, delta21
);
3643 index1
= integer_neg_one_node
;
3645 tree nop1
= build1 (NOP_EXPR
, TYPE_PTRMEMFUNC_FN_TYPE (type0
),
3647 TREE_CONSTANT (nop1
) = TREE_CONSTANT (op1
);
3650 e1
= build_binary_op (EQ_EXPR
, index0
, index1
, 1);
3651 e2
= build_binary_op (NE_EXPR
, index1
, integer_neg_one_node
, 1);
3652 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e2
,
3653 build_binary_op (EQ_EXPR
, delta20
, delta21
, 1),
3655 e3
= build_binary_op (EQ_EXPR
, pfn0
, op1
, 1);
3656 e2
= build_binary_op (TRUTH_ORIF_EXPR
, e2
, e3
, 1);
3657 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e1
, e2
, 1);
3658 if (code
== EQ_EXPR
)
3660 return build_binary_op (EQ_EXPR
, e2
, integer_zero_node
, 1);
3662 else if (TYPE_PTRMEMFUNC_P (type1
)
3663 && TYPE_PTRMEMFUNC_FN_TYPE (type1
) == type0
)
3665 return build_binary_op (code
, op1
, op0
, 1);
3671 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3672 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3674 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3676 if (comp_target_types (type0
, type1
, 1))
3677 result_type
= common_type (type0
, type1
);
3680 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3682 result_type
= ptr_type_node
;
3691 build_type
= boolean_type_node
;
3692 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3693 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3695 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3697 if (comp_target_types (type0
, type1
, 1))
3698 result_type
= common_type (type0
, type1
);
3701 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3703 result_type
= ptr_type_node
;
3706 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
3707 && integer_zerop (op1
))
3708 result_type
= type0
;
3709 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
3710 && integer_zerop (op0
))
3711 result_type
= type1
;
3712 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3714 result_type
= type0
;
3715 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3717 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
3719 result_type
= type1
;
3720 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3728 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
|| code0
== COMPLEX_TYPE
)
3730 (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
|| code1
== COMPLEX_TYPE
))
3732 int none_complex
= (code0
!= COMPLEX_TYPE
&& code1
!= COMPLEX_TYPE
);
3734 if (shorten
|| common
|| short_compare
)
3735 result_type
= common_type (type0
, type1
);
3737 /* For certain operations (which identify themselves by shorten != 0)
3738 if both args were extended from the same smaller type,
3739 do the arithmetic in that type and then extend.
3741 shorten !=0 and !=1 indicates a bitwise operation.
3742 For them, this optimization is safe only if
3743 both args are zero-extended or both are sign-extended.
3744 Otherwise, we might change the result.
3745 Eg, (short)-1 | (unsigned short)-1 is (int)-1
3746 but calculated in (unsigned short) it would be (unsigned short)-1. */
3748 if (shorten
&& none_complex
)
3750 int unsigned0
, unsigned1
;
3751 tree arg0
= get_narrower (op0
, &unsigned0
);
3752 tree arg1
= get_narrower (op1
, &unsigned1
);
3753 /* UNS is 1 if the operation to be done is an unsigned one. */
3754 int uns
= TREE_UNSIGNED (result_type
);
3757 final_type
= result_type
;
3759 /* Handle the case that OP0 does not *contain* a conversion
3760 but it *requires* conversion to FINAL_TYPE. */
3762 if (op0
== arg0
&& TREE_TYPE (op0
) != final_type
)
3763 unsigned0
= TREE_UNSIGNED (TREE_TYPE (op0
));
3764 if (op1
== arg1
&& TREE_TYPE (op1
) != final_type
)
3765 unsigned1
= TREE_UNSIGNED (TREE_TYPE (op1
));
3767 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
3769 /* For bitwise operations, signedness of nominal type
3770 does not matter. Consider only how operands were extended. */
3774 /* Note that in all three cases below we refrain from optimizing
3775 an unsigned operation on sign-extended args.
3776 That would not be valid. */
3778 /* Both args variable: if both extended in same way
3779 from same width, do it in that width.
3780 Do it unsigned if args were zero-extended. */
3781 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
3782 < TYPE_PRECISION (result_type
))
3783 && (TYPE_PRECISION (TREE_TYPE (arg1
))
3784 == TYPE_PRECISION (TREE_TYPE (arg0
)))
3785 && unsigned0
== unsigned1
3786 && (unsigned0
|| !uns
))
3788 = signed_or_unsigned_type (unsigned0
,
3789 common_type (TREE_TYPE (arg0
),
3791 else if (TREE_CODE (arg0
) == INTEGER_CST
3792 && (unsigned1
|| !uns
)
3793 && (TYPE_PRECISION (TREE_TYPE (arg1
))
3794 < TYPE_PRECISION (result_type
))
3795 && (type
= signed_or_unsigned_type (unsigned1
,
3797 int_fits_type_p (arg0
, type
)))
3799 else if (TREE_CODE (arg1
) == INTEGER_CST
3800 && (unsigned0
|| !uns
)
3801 && (TYPE_PRECISION (TREE_TYPE (arg0
))
3802 < TYPE_PRECISION (result_type
))
3803 && (type
= signed_or_unsigned_type (unsigned0
,
3805 int_fits_type_p (arg1
, type
)))
3809 /* Shifts can be shortened if shifting right. */
3814 tree arg0
= get_narrower (op0
, &unsigned_arg
);
3816 final_type
= result_type
;
3818 if (arg0
== op0
&& final_type
== TREE_TYPE (op0
))
3819 unsigned_arg
= TREE_UNSIGNED (TREE_TYPE (op0
));
3821 if (TYPE_PRECISION (TREE_TYPE (arg0
)) < TYPE_PRECISION (result_type
)
3822 /* We can shorten only if the shift count is less than the
3823 number of bits in the smaller type size. */
3824 && TREE_INT_CST_HIGH (op1
) == 0
3825 && TYPE_PRECISION (TREE_TYPE (arg0
)) > TREE_INT_CST_LOW (op1
)
3826 /* If arg is sign-extended and then unsigned-shifted,
3827 we can simulate this with a signed shift in arg's type
3828 only if the extended result is at least twice as wide
3829 as the arg. Otherwise, the shift could use up all the
3830 ones made by sign-extension and bring in zeros.
3831 We can't optimize that case at all, but in most machines
3832 it never happens because available widths are 2**N. */
3833 && (!TREE_UNSIGNED (final_type
)
3835 || (((unsigned) 2 * TYPE_PRECISION (TREE_TYPE (arg0
)))
3836 <= TYPE_PRECISION (result_type
))))
3838 /* Do an unsigned shift if the operand was zero-extended. */
3840 = signed_or_unsigned_type (unsigned_arg
,
3842 /* Convert value-to-be-shifted to that type. */
3843 if (TREE_TYPE (op0
) != result_type
)
3844 op0
= cp_convert (result_type
, op0
);
3849 /* Comparison operations are shortened too but differently.
3850 They identify themselves by setting short_compare = 1. */
3854 /* Don't write &op0, etc., because that would prevent op0
3855 from being kept in a register.
3856 Instead, make copies of the our local variables and
3857 pass the copies by reference, then copy them back afterward. */
3858 tree xop0
= op0
, xop1
= op1
, xresult_type
= result_type
;
3859 enum tree_code xresultcode
= resultcode
;
3861 = shorten_compare (&xop0
, &xop1
, &xresult_type
, &xresultcode
);
3863 return cp_convert (boolean_type_node
, val
);
3864 op0
= xop0
, op1
= xop1
;
3866 resultcode
= xresultcode
;
3869 if (short_compare
&& warn_sign_compare
)
3871 int op0_signed
= ! TREE_UNSIGNED (TREE_TYPE (orig_op0
));
3872 int op1_signed
= ! TREE_UNSIGNED (TREE_TYPE (orig_op1
));
3874 int unsignedp0
, unsignedp1
;
3875 tree primop0
= get_narrower (op0
, &unsignedp0
);
3876 tree primop1
= get_narrower (op1
, &unsignedp1
);
3878 /* Check for comparison of different enum types. */
3879 if (flag_int_enum_equivalence
== 0
3880 && TREE_CODE (TREE_TYPE (orig_op0
)) == ENUMERAL_TYPE
3881 && TREE_CODE (TREE_TYPE (orig_op1
)) == ENUMERAL_TYPE
3882 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0
))
3883 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1
)))
3885 cp_warning ("comparison between `%#T' and `%#T'",
3886 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
));
3889 /* Give warnings for comparisons between signed and unsigned
3890 quantities that may fail. */
3891 /* Do the checking based on the original operand trees, so that
3892 casts will be considered, but default promotions won't be. */
3894 /* Do not warn if the comparison is being done in a signed type,
3895 since the signed type will only be chosen if it can represent
3896 all the values of the unsigned type. */
3897 if (! TREE_UNSIGNED (result_type
))
3899 /* Do not warn if both operands are unsigned. */
3900 else if (op0_signed
== op1_signed
)
3902 /* Do not warn if the signed quantity is an unsuffixed
3903 integer literal (or some static constant expression
3904 involving such literals) and it is non-negative. */
3905 else if ((op0_signed
&& TREE_CODE (orig_op0
) == INTEGER_CST
3906 && tree_int_cst_sgn (orig_op0
) >= 0)
3907 || (op1_signed
&& TREE_CODE (orig_op1
) == INTEGER_CST
3908 && tree_int_cst_sgn (orig_op1
) >= 0))
3910 /* Do not warn if the comparison is an equality operation,
3911 the unsigned quantity is an integral constant and it does
3912 not use the most significant bit of result_type. */
3913 else if ((resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
3914 && ((op0_signed
&& TREE_CODE (orig_op1
) == INTEGER_CST
3915 && int_fits_type_p (orig_op1
,
3916 signed_type (result_type
)))
3917 || (op1_signed
&& TREE_CODE (orig_op0
) == INTEGER_CST
3918 && int_fits_type_p (orig_op0
,
3919 signed_type (result_type
)))))
3922 warning ("comparison between signed and unsigned");
3924 /* Warn if two unsigned values are being compared in a size
3925 larger than their original size, and one (and only one) is the
3926 result of a `~' operator. This comparison will always fail.
3928 Also warn if one operand is a constant, and the constant does not
3929 have all bits set that are set in the ~ operand when it is
3932 if ((TREE_CODE (primop0
) == BIT_NOT_EXPR
)
3933 ^ (TREE_CODE (primop1
) == BIT_NOT_EXPR
))
3935 if (TREE_CODE (primop0
) == BIT_NOT_EXPR
)
3936 primop0
= get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
3937 if (TREE_CODE (primop1
) == BIT_NOT_EXPR
)
3938 primop1
= get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
3940 if (TREE_CODE (primop0
) == INTEGER_CST
3941 || TREE_CODE (primop1
) == INTEGER_CST
)
3944 HOST_WIDE_INT constant
, mask
;
3948 if (TREE_CODE (primop0
) == INTEGER_CST
)
3951 unsignedp
= unsignedp1
;
3952 constant
= TREE_INT_CST_LOW (primop0
);
3957 unsignedp
= unsignedp0
;
3958 constant
= TREE_INT_CST_LOW (primop1
);
3961 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
3962 if (bits
< TYPE_PRECISION (result_type
)
3963 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
3965 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
3966 if ((mask
& constant
) != mask
)
3967 warning ("comparison of promoted ~unsigned with constant");
3970 else if (unsignedp0
&& unsignedp1
3971 && (TYPE_PRECISION (TREE_TYPE (primop0
))
3972 < TYPE_PRECISION (result_type
))
3973 && (TYPE_PRECISION (TREE_TYPE (primop1
))
3974 < TYPE_PRECISION (result_type
)))
3975 warning ("comparison of promoted ~unsigned with unsigned");
3980 /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
3981 If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
3982 Then the expression will be built.
3983 It will be given type FINAL_TYPE if that is nonzero;
3984 otherwise, it will be given type RESULT_TYPE. */
3988 cp_error ("invalid operands `%T' and `%T' to binary `%O'",
3989 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
), error_code
);
3990 return error_mark_node
;
3993 /* Issue warnings about peculiar, but legal, uses of NULL. */
3994 if (/* It's reasonable to use pointer values as operands of &&
3995 and ||, so NULL is no exception. */
3996 !(code
== TRUTH_ANDIF_EXPR
|| code
== TRUTH_ORIF_EXPR
)
3997 && (/* If OP0 is NULL and OP1 is not a pointer, or vice versa. */
3998 (orig_op0
== null_node
3999 && TREE_CODE (TREE_TYPE (op1
)) != POINTER_TYPE
)
4000 /* Or vice versa. */
4001 || (orig_op1
== null_node
4002 && TREE_CODE (TREE_TYPE (op0
)) != POINTER_TYPE
)
4003 /* Or, both are NULL and the operation was not a comparison. */
4004 || (orig_op0
== null_node
&& orig_op1
== null_node
4005 && code
!= EQ_EXPR
&& code
!= NE_EXPR
)))
4006 /* Some sort of arithmetic operation involving NULL was
4007 performed. Note that pointer-difference and pointer-addition
4008 have already been handled above, and so we don't end up here in
4010 cp_warning ("NULL used in arithmetic");
4014 if (TREE_TYPE (op0
) != result_type
)
4015 op0
= cp_convert (result_type
, op0
);
4016 if (TREE_TYPE (op1
) != result_type
)
4017 op1
= cp_convert (result_type
, op1
);
4020 if (build_type
== NULL_TREE
)
4021 build_type
= result_type
;
4024 register tree result
= build (resultcode
, build_type
, op0
, op1
);
4025 register tree folded
;
4027 folded
= fold (result
);
4028 if (folded
== result
)
4029 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
4030 if (final_type
!= 0)
4031 return cp_convert (final_type
, folded
);
4036 /* Return a tree for the sum or difference (RESULTCODE says which)
4037 of pointer PTROP and integer INTOP. */
4040 pointer_int_sum (resultcode
, ptrop
, intop
)
4041 enum tree_code resultcode
;
4042 register tree ptrop
, intop
;
4046 register tree result
;
4047 register tree folded
= fold (intop
);
4049 /* The result is a pointer of the same type that is being added. */
4051 register tree result_type
= TREE_TYPE (ptrop
);
4053 if (!complete_type_or_else (result_type
))
4054 return error_mark_node
;
4056 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
4058 if (pedantic
|| warn_pointer_arith
)
4059 pedwarn ("ANSI C++ forbids using pointer of type `void *' in arithmetic");
4060 size_exp
= integer_one_node
;
4062 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
4064 if (pedantic
|| warn_pointer_arith
)
4065 pedwarn ("ANSI C++ forbids using pointer to a function in arithmetic");
4066 size_exp
= integer_one_node
;
4068 else if (TREE_CODE (TREE_TYPE (result_type
)) == METHOD_TYPE
)
4070 if (pedantic
|| warn_pointer_arith
)
4071 pedwarn ("ANSI C++ forbids using pointer to a method in arithmetic");
4072 size_exp
= integer_one_node
;
4074 else if (TREE_CODE (TREE_TYPE (result_type
)) == OFFSET_TYPE
)
4076 if (pedantic
|| warn_pointer_arith
)
4077 pedwarn ("ANSI C++ forbids using pointer to a member in arithmetic");
4078 size_exp
= integer_one_node
;
4081 size_exp
= size_in_bytes (complete_type (TREE_TYPE (result_type
)));
4083 /* Needed to make OOPS V2R3 work. */
4085 if (TREE_CODE (intop
) == INTEGER_CST
4086 && TREE_INT_CST_LOW (intop
) == 0
4087 && TREE_INT_CST_HIGH (intop
) == 0)
4090 /* If what we are about to multiply by the size of the elements
4091 contains a constant term, apply distributive law
4092 and multiply that constant term separately.
4093 This helps produce common subexpressions. */
4095 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
4096 && ! TREE_CONSTANT (intop
)
4097 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
4098 && TREE_CONSTANT (size_exp
))
4100 enum tree_code subcode
= resultcode
;
4101 if (TREE_CODE (intop
) == MINUS_EXPR
)
4102 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
4103 ptrop
= build_binary_op (subcode
, ptrop
, TREE_OPERAND (intop
, 1), 1);
4104 intop
= TREE_OPERAND (intop
, 0);
4107 /* Convert the integer argument to a type the same size as sizetype
4108 so the multiply won't overflow spuriously. */
4110 if (TYPE_PRECISION (TREE_TYPE (intop
)) != TYPE_PRECISION (sizetype
))
4111 intop
= cp_convert (type_for_size (TYPE_PRECISION (sizetype
), 0), intop
);
4113 /* Replace the integer argument with a suitable product by the object size.
4114 Do this multiplication as signed, then convert to the appropriate
4115 pointer type (actually unsigned integral). */
4117 intop
= cp_convert (result_type
,
4118 build_binary_op (MULT_EXPR
, intop
,
4119 cp_convert (TREE_TYPE (intop
),
4123 /* Create the sum or difference. */
4125 result
= build (resultcode
, result_type
, ptrop
, intop
);
4127 folded
= fold (result
);
4128 if (folded
== result
)
4129 TREE_CONSTANT (folded
) = TREE_CONSTANT (ptrop
) & TREE_CONSTANT (intop
);
4133 /* Return a tree for the difference of pointers OP0 and OP1.
4134 The resulting tree has type int. */
4137 pointer_diff (op0
, op1
, ptrtype
)
4138 register tree op0
, op1
;
4139 register tree ptrtype
;
4141 register tree result
, folded
;
4142 tree restype
= ptrdiff_type_node
;
4143 tree target_type
= TREE_TYPE (ptrtype
);
4145 if (!complete_type_or_else (target_type
))
4146 return error_mark_node
;
4148 if (pedantic
|| warn_pointer_arith
)
4150 if (TREE_CODE (target_type
) == VOID_TYPE
)
4151 pedwarn ("ANSI C++ forbids using pointer of type `void *' in subtraction");
4152 if (TREE_CODE (target_type
) == FUNCTION_TYPE
)
4153 pedwarn ("ANSI C++ forbids using pointer to a function in subtraction");
4154 if (TREE_CODE (target_type
) == METHOD_TYPE
)
4155 pedwarn ("ANSI C++ forbids using pointer to a method in subtraction");
4156 if (TREE_CODE (target_type
) == OFFSET_TYPE
)
4157 pedwarn ("ANSI C++ forbids using pointer to a member in subtraction");
4160 /* First do the subtraction as integers;
4161 then drop through to build the divide operator. */
4163 op0
= build_binary_op (MINUS_EXPR
, cp_convert (restype
, op0
),
4164 cp_convert (restype
, op1
), 1);
4166 /* This generates an error if op1 is a pointer to an incomplete type. */
4167 if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1
))) == 0)
4168 error ("arithmetic on pointer to an incomplete type");
4170 op1
= ((TREE_CODE (target_type
) == VOID_TYPE
4171 || TREE_CODE (target_type
) == FUNCTION_TYPE
4172 || TREE_CODE (target_type
) == METHOD_TYPE
4173 || TREE_CODE (target_type
) == OFFSET_TYPE
)
4175 : size_in_bytes (target_type
));
4177 /* Do the division. */
4179 result
= build (EXACT_DIV_EXPR
, restype
, op0
, cp_convert (restype
, op1
));
4181 folded
= fold (result
);
4182 if (folded
== result
)
4183 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
4187 /* Handle the case of taking the address of a COMPONENT_REF.
4188 Called by `build_unary_op' and `build_up_reference'.
4190 ARG is the COMPONENT_REF whose address we want.
4191 ARGTYPE is the pointer type that this address should have.
4192 MSG is an error message to print if this COMPONENT_REF is not
4193 addressable (such as a bitfield). */
4196 build_component_addr (arg
, argtype
, msg
)
4200 tree field
= TREE_OPERAND (arg
, 1);
4201 tree basetype
= decl_type_context (field
);
4202 tree rval
= build_unary_op (ADDR_EXPR
, TREE_OPERAND (arg
, 0), 0);
4204 if (DECL_BIT_FIELD (field
))
4206 error (msg
, IDENTIFIER_POINTER (DECL_NAME (field
)));
4207 return error_mark_node
;
4210 if (TREE_CODE (field
) == FIELD_DECL
4211 && TYPE_USES_COMPLEX_INHERITANCE (basetype
))
4213 /* Can't convert directly to ARGTYPE, since that
4214 may have the same pointer type as one of our
4216 rval
= build1 (NOP_EXPR
, argtype
,
4217 convert_pointer_to (basetype
, rval
));
4218 TREE_CONSTANT (rval
) = TREE_CONSTANT (TREE_OPERAND (rval
, 0));
4221 /* This conversion is harmless. */
4222 rval
= convert_force (argtype
, rval
, 0);
4224 if (! integer_zerop (DECL_FIELD_BITPOS (field
)))
4226 tree offset
= size_binop (EASY_DIV_EXPR
, DECL_FIELD_BITPOS (field
),
4227 size_int (BITS_PER_UNIT
));
4228 int flag
= TREE_CONSTANT (rval
);
4229 offset
= convert (sizetype
, offset
);
4230 rval
= fold (build (PLUS_EXPR
, argtype
,
4231 rval
, cp_convert (argtype
, offset
)));
4232 TREE_CONSTANT (rval
) = flag
;
4237 /* Construct and perhaps optimize a tree representation
4238 for a unary operation. CODE, a tree_code, specifies the operation
4239 and XARG is the operand. */
4242 build_x_unary_op (code
, xarg
)
4243 enum tree_code code
;
4246 if (processing_template_decl
)
4247 return build_min_nt (code
, xarg
, NULL_TREE
);
4249 /* & rec, on incomplete RECORD_TYPEs is the simple opr &, not an
4251 if (code
== ADDR_EXPR
4252 && TREE_CODE (xarg
) != TEMPLATE_ID_EXPR
4253 && ((IS_AGGR_TYPE_CODE (TREE_CODE (TREE_TYPE (xarg
)))
4254 && TYPE_SIZE (TREE_TYPE (xarg
)) == NULL_TREE
)
4255 || (TREE_CODE (xarg
) == OFFSET_REF
)))
4256 /* don't look for a function */;
4261 rval
= build_new_op (code
, LOOKUP_NORMAL
, xarg
,
4262 NULL_TREE
, NULL_TREE
);
4263 if (rval
|| code
!= ADDR_EXPR
)
4267 if (code
== ADDR_EXPR
)
4269 if (TREE_CODE (xarg
) == TARGET_EXPR
)
4270 warning ("taking address of temporary");
4273 return build_unary_op (code
, xarg
, 0);
4276 /* Just like truthvalue_conversion, but we want a CLEANUP_POINT_EXPR. */
4279 condition_conversion (expr
)
4283 if (processing_template_decl
)
4285 t
= cp_convert (boolean_type_node
, expr
);
4286 t
= fold (build1 (CLEANUP_POINT_EXPR
, boolean_type_node
, t
));
4290 /* C++: Must handle pointers to members.
4292 Perhaps type instantiation should be extended to handle conversion
4293 from aggregates to types we don't yet know we want? (Or are those
4294 cases typically errors which should be reported?)
4296 NOCONVERT nonzero suppresses the default promotions
4297 (such as from short to int). */
4300 build_unary_op (code
, xarg
, noconvert
)
4301 enum tree_code code
;
4305 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
4306 register tree arg
= xarg
;
4307 register tree argtype
= 0;
4308 char *errstring
= NULL
;
4311 if (arg
== error_mark_node
)
4312 return error_mark_node
;
4317 /* This is used for unary plus, because a CONVERT_EXPR
4318 is enough to prevent anybody from looking inside for
4319 associativity, but won't generate any code. */
4320 if (!(arg
= build_expr_type_conversion
4321 (WANT_ARITH
| WANT_ENUM
| WANT_POINTER
, arg
, 1)))
4322 errstring
= "wrong type argument to unary plus";
4326 arg
= default_conversion (arg
);
4327 arg
= build1 (NON_LVALUE_EXPR
, TREE_TYPE (arg
), arg
);
4328 TREE_CONSTANT (arg
) = TREE_CONSTANT (TREE_OPERAND (arg
, 0));
4333 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
4334 errstring
= "wrong type argument to unary minus";
4335 else if (!noconvert
)
4336 arg
= default_conversion (arg
);
4340 if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
4344 arg
= default_conversion (arg
);
4346 else if (!(arg
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
,
4348 errstring
= "wrong type argument to bit-complement";
4349 else if (!noconvert
)
4350 arg
= default_conversion (arg
);
4354 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
4355 errstring
= "wrong type argument to abs";
4356 else if (!noconvert
)
4357 arg
= default_conversion (arg
);
4361 /* Conjugating a real value is a no-op, but allow it anyway. */
4362 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
4363 errstring
= "wrong type argument to conjugation";
4364 else if (!noconvert
)
4365 arg
= default_conversion (arg
);
4368 case TRUTH_NOT_EXPR
:
4369 arg
= cp_convert (boolean_type_node
, arg
);
4370 val
= invert_truthvalue (arg
);
4371 if (arg
!= error_mark_node
)
4373 errstring
= "in argument to unary !";
4380 if (TREE_CODE (arg
) == COMPLEX_CST
)
4381 return TREE_REALPART (arg
);
4382 else if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
4383 return fold (build1 (REALPART_EXPR
, TREE_TYPE (TREE_TYPE (arg
)), arg
));
4388 if (TREE_CODE (arg
) == COMPLEX_CST
)
4389 return TREE_IMAGPART (arg
);
4390 else if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
4391 return fold (build1 (IMAGPART_EXPR
, TREE_TYPE (TREE_TYPE (arg
)), arg
));
4393 return cp_convert (TREE_TYPE (arg
), integer_zero_node
);
4395 case PREINCREMENT_EXPR
:
4396 case POSTINCREMENT_EXPR
:
4397 case PREDECREMENT_EXPR
:
4398 case POSTDECREMENT_EXPR
:
4399 /* Handle complex lvalues (when permitted)
4400 by reduction to simpler cases. */
4402 val
= unary_complex_lvalue (code
, arg
);
4406 /* Increment or decrement the real part of the value,
4407 and don't change the imaginary part. */
4408 if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
4412 arg
= stabilize_reference (arg
);
4413 real
= build_unary_op (REALPART_EXPR
, arg
, 1);
4414 imag
= build_unary_op (IMAGPART_EXPR
, arg
, 1);
4415 return build (COMPLEX_EXPR
, TREE_TYPE (arg
),
4416 build_unary_op (code
, real
, 1), imag
);
4419 /* Report invalid types. */
4421 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_POINTER
,
4424 if (code
== PREINCREMENT_EXPR
)
4425 errstring
="no pre-increment operator for type";
4426 else if (code
== POSTINCREMENT_EXPR
)
4427 errstring
="no post-increment operator for type";
4428 else if (code
== PREDECREMENT_EXPR
)
4429 errstring
="no pre-decrement operator for type";
4431 errstring
="no post-decrement operator for type";
4435 /* Report something read-only. */
4437 if (TYPE_READONLY (TREE_TYPE (arg
))
4438 || TREE_READONLY (arg
))
4439 readonly_error (arg
, ((code
== PREINCREMENT_EXPR
4440 || code
== POSTINCREMENT_EXPR
)
4441 ? "increment" : "decrement"),
4446 tree result_type
= TREE_TYPE (arg
);
4448 arg
= get_unwidened (arg
, 0);
4449 argtype
= TREE_TYPE (arg
);
4451 /* ARM $5.2.5 last annotation says this should be forbidden. */
4452 if (TREE_CODE (argtype
) == ENUMERAL_TYPE
)
4453 pedwarn ("ANSI C++ forbids %sing an enum",
4454 (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
4455 ? "increment" : "decrement");
4457 /* Compute the increment. */
4459 if (TREE_CODE (argtype
) == POINTER_TYPE
)
4461 enum tree_code tmp
= TREE_CODE (TREE_TYPE (argtype
));
4462 if (TYPE_SIZE (complete_type (TREE_TYPE (argtype
))) == 0)
4463 cp_error ("cannot %s a pointer to incomplete type `%T'",
4464 ((code
== PREINCREMENT_EXPR
4465 || code
== POSTINCREMENT_EXPR
)
4466 ? "increment" : "decrement"), TREE_TYPE (argtype
));
4467 else if ((pedantic
|| warn_pointer_arith
)
4468 && (tmp
== FUNCTION_TYPE
|| tmp
== METHOD_TYPE
4469 || tmp
== VOID_TYPE
|| tmp
== OFFSET_TYPE
))
4470 cp_pedwarn ("ANSI C++ forbids %sing a pointer of type `%T'",
4471 ((code
== PREINCREMENT_EXPR
4472 || code
== POSTINCREMENT_EXPR
)
4473 ? "increment" : "decrement"), argtype
);
4474 inc
= c_sizeof_nowarn (TREE_TYPE (argtype
));
4477 inc
= integer_one_node
;
4479 inc
= cp_convert (argtype
, inc
);
4481 /* Handle incrementing a cast-expression. */
4483 switch (TREE_CODE (arg
))
4488 case FIX_TRUNC_EXPR
:
4489 case FIX_FLOOR_EXPR
:
4490 case FIX_ROUND_EXPR
:
4493 tree incremented
, modify
, value
, compound
;
4494 if (! lvalue_p (arg
) && pedantic
)
4495 pedwarn ("cast to non-reference type used as lvalue");
4496 arg
= stabilize_reference (arg
);
4497 if (code
== PREINCREMENT_EXPR
|| code
== PREDECREMENT_EXPR
)
4500 value
= save_expr (arg
);
4501 incremented
= build (((code
== PREINCREMENT_EXPR
4502 || code
== POSTINCREMENT_EXPR
)
4503 ? PLUS_EXPR
: MINUS_EXPR
),
4504 argtype
, value
, inc
);
4505 TREE_SIDE_EFFECTS (incremented
) = 1;
4507 modify
= build_modify_expr (arg
, NOP_EXPR
, incremented
);
4508 compound
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), modify
, value
);
4510 /* Eliminate warning about unused result of + or -. */
4511 TREE_NO_UNUSED_WARNING (compound
) = 1;
4519 /* Complain about anything else that is not a true lvalue. */
4520 if (!lvalue_or_else (arg
, ((code
== PREINCREMENT_EXPR
4521 || code
== POSTINCREMENT_EXPR
)
4522 ? "increment" : "decrement")))
4523 return error_mark_node
;
4525 /* Forbid using -- on `bool'. */
4526 if (TREE_TYPE (arg
) == boolean_type_node
)
4528 if (code
== POSTDECREMENT_EXPR
|| code
== PREDECREMENT_EXPR
)
4530 cp_error ("invalid use of `--' on bool variable `%D'", arg
);
4531 return error_mark_node
;
4534 /* This will only work if someone can convince Kenner to accept
4535 my patch to expand_increment. (jason) */
4536 val
= build (code
, TREE_TYPE (arg
), arg
, inc
);
4538 if (code
== POSTINCREMENT_EXPR
)
4540 arg
= stabilize_reference (arg
);
4541 val
= build (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
4543 TREE_SIDE_EFFECTS (val
) = 1;
4544 arg
= save_expr (arg
);
4545 val
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
4546 val
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
4549 val
= build (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
4554 val
= build (code
, TREE_TYPE (arg
), arg
, inc
);
4556 TREE_SIDE_EFFECTS (val
) = 1;
4557 return cp_convert (result_type
, val
);
4561 /* Note that this operation never does default_conversion
4562 regardless of NOCONVERT. */
4564 argtype
= lvalue_type (arg
);
4565 if (TREE_CODE (argtype
) == REFERENCE_TYPE
)
4569 build_pointer_type (TREE_TYPE (argtype
)), arg
);
4570 TREE_CONSTANT (arg
) = TREE_CONSTANT (TREE_OPERAND (arg
, 0));
4573 else if (pedantic
&& DECL_MAIN_P (arg
))
4575 pedwarn ("taking address of function `main'");
4577 /* Let &* cancel out to simplify resulting code. */
4578 if (TREE_CODE (arg
) == INDIRECT_REF
)
4580 /* We don't need to have `current_class_ptr' wrapped in a
4581 NON_LVALUE_EXPR node. */
4582 if (arg
== current_class_ref
)
4583 return current_class_ptr
;
4585 arg
= TREE_OPERAND (arg
, 0);
4586 if (TREE_CODE (TREE_TYPE (arg
)) == REFERENCE_TYPE
)
4590 build_pointer_type (TREE_TYPE (TREE_TYPE (arg
))), arg
);
4591 TREE_CONSTANT (arg
) = TREE_CONSTANT (TREE_OPERAND (arg
, 0));
4593 else if (lvalue_p (arg
))
4594 /* Don't let this be an lvalue. */
4595 return non_lvalue (arg
);
4599 /* For &x[y], return x+y */
4600 if (TREE_CODE (arg
) == ARRAY_REF
)
4602 if (mark_addressable (TREE_OPERAND (arg
, 0)) == 0)
4603 return error_mark_node
;
4604 return build_binary_op (PLUS_EXPR
, TREE_OPERAND (arg
, 0),
4605 TREE_OPERAND (arg
, 1), 1);
4608 /* Uninstantiated types are all functions. Taking the
4609 address of a function is a no-op, so just return the
4612 if (TREE_CODE (arg
) == IDENTIFIER_NODE
4613 && IDENTIFIER_OPNAME_P (arg
))
4615 my_friendly_abort (117);
4616 /* We don't know the type yet, so just work around the problem.
4617 We know that this will resolve to an lvalue. */
4618 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4621 if (TREE_CODE (arg
) == OVERLOAD
4622 || (TREE_CODE (arg
) == OFFSET_REF
4623 && TREE_CODE (TREE_OPERAND (arg
, 1)) == TEMPLATE_ID_EXPR
))
4624 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4625 else if (TREE_CODE (arg
) == TREE_LIST
)
4627 if (TREE_CODE (TREE_VALUE (arg
)) == FUNCTION_DECL
)
4628 /* Unique overloaded non-member function. */
4629 return build_unary_op (ADDR_EXPR
, TREE_VALUE (arg
), 0);
4630 if (TREE_CHAIN (arg
) == NULL_TREE
4631 && TREE_CODE (TREE_VALUE (arg
)) == TREE_LIST
4632 && TREE_CODE (TREE_VALUE (TREE_VALUE (arg
))) != OVERLOAD
)
4633 /* Unique overloaded member function. */
4634 return build_unary_op (ADDR_EXPR
, TREE_VALUE (TREE_VALUE (arg
)),
4636 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4638 else if (TREE_CODE (arg
) == TEMPLATE_ID_EXPR
)
4643 /* We don't require a match here; it's possible that the
4644 context (like a cast to a particular type) will resolve
4645 the particular choice of template. */
4646 fn
= determine_specialization (arg
,
4654 fn
= instantiate_template (fn
, targs
);
4655 mark_addressable (fn
);
4656 return build_unary_op (ADDR_EXPR
, fn
, 0);
4659 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4662 /* Handle complex lvalues (when permitted)
4663 by reduction to simpler cases. */
4664 val
= unary_complex_lvalue (code
, arg
);
4668 switch (TREE_CODE (arg
))
4673 case FIX_TRUNC_EXPR
:
4674 case FIX_FLOOR_EXPR
:
4675 case FIX_ROUND_EXPR
:
4677 if (! lvalue_p (arg
) && pedantic
)
4678 pedwarn ("taking the address of a cast to non-reference type");
4685 /* Allow the address of a constructor if all the elements
4687 if (TREE_CODE (arg
) == CONSTRUCTOR
&& TREE_HAS_CONSTRUCTOR (arg
)
4688 && TREE_CONSTANT (arg
))
4690 /* Anything not already handled and not a true memory reference
4692 else if (TREE_CODE (argtype
) != FUNCTION_TYPE
4693 && TREE_CODE (argtype
) != METHOD_TYPE
4694 && !lvalue_or_else (arg
, "unary `&'"))
4695 return error_mark_node
;
4697 argtype
= build_pointer_type (argtype
);
4699 if (mark_addressable (arg
) == 0)
4700 return error_mark_node
;
4705 if (TREE_CODE (arg
) == COMPONENT_REF
)
4706 addr
= build_component_addr
4708 "attempt to take address of bit-field structure member `%s'");
4710 addr
= build1 (code
, argtype
, arg
);
4712 /* Address of a static or external variable or
4713 function counts as a constant */
4715 TREE_CONSTANT (addr
) = 1;
4717 if (TREE_CODE (argtype
) == POINTER_TYPE
4718 && TREE_CODE (TREE_TYPE (argtype
)) == METHOD_TYPE
)
4720 build_ptrmemfunc_type (argtype
);
4721 addr
= build_ptrmemfunc (argtype
, addr
, 0);
4734 argtype
= TREE_TYPE (arg
);
4735 return fold (build1 (code
, argtype
, arg
));
4739 return error_mark_node
;
4743 /* If CONVERSIONS is a conversion expression or a nested sequence of such,
4744 convert ARG with the same conversions in the same order
4745 and return the result. */
4748 convert_sequence (conversions
, arg
)
4752 switch (TREE_CODE (conversions
))
4757 case FIX_TRUNC_EXPR
:
4758 case FIX_FLOOR_EXPR
:
4759 case FIX_ROUND_EXPR
:
4761 return cp_convert (TREE_TYPE (conversions
),
4762 convert_sequence (TREE_OPERAND (conversions
, 0),
4771 /* Apply unary lvalue-demanding operator CODE to the expression ARG
4772 for certain kinds of expressions which are not really lvalues
4773 but which we can accept as lvalues.
4775 If ARG is not a kind of expression we can handle, return zero. */
4778 unary_complex_lvalue (code
, arg
)
4779 enum tree_code code
;
4782 /* Handle (a, b) used as an "lvalue". */
4783 if (TREE_CODE (arg
) == COMPOUND_EXPR
)
4785 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 1), 0);
4786 return build (COMPOUND_EXPR
, TREE_TYPE (real_result
),
4787 TREE_OPERAND (arg
, 0), real_result
);
4790 /* Handle (a ? b : c) used as an "lvalue". */
4791 if (TREE_CODE (arg
) == COND_EXPR
4792 || TREE_CODE (arg
) == MIN_EXPR
|| TREE_CODE (arg
) == MAX_EXPR
)
4793 return rationalize_conditional_expr (code
, arg
);
4795 if (TREE_CODE (arg
) == MODIFY_EXPR
4796 || TREE_CODE (arg
) == PREINCREMENT_EXPR
4797 || TREE_CODE (arg
) == PREDECREMENT_EXPR
)
4798 return unary_complex_lvalue
4799 (code
, build (COMPOUND_EXPR
, TREE_TYPE (TREE_OPERAND (arg
, 0)),
4800 arg
, TREE_OPERAND (arg
, 0)));
4802 if (code
!= ADDR_EXPR
)
4805 /* Handle (a = b) used as an "lvalue" for `&'. */
4806 if (TREE_CODE (arg
) == MODIFY_EXPR
4807 || TREE_CODE (arg
) == INIT_EXPR
)
4809 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 0), 0);
4810 arg
= build (COMPOUND_EXPR
, TREE_TYPE (real_result
), arg
, real_result
);
4811 TREE_NO_UNUSED_WARNING (arg
) = 1;
4815 if (TREE_CODE (TREE_TYPE (arg
)) == FUNCTION_TYPE
4816 || TREE_CODE (TREE_TYPE (arg
)) == METHOD_TYPE
4817 || TREE_CODE (TREE_TYPE (arg
)) == OFFSET_TYPE
)
4819 /* The representation of something of type OFFSET_TYPE
4820 is really the representation of a pointer to it.
4821 Here give the representation its true type. */
4824 my_friendly_assert (TREE_CODE (arg
) != SCOPE_REF
, 313);
4826 if (TREE_CODE (arg
) != OFFSET_REF
)
4829 t
= TREE_OPERAND (arg
, 1);
4831 /* Check all this code for right semantics. */
4832 if (TREE_CODE (t
) == FUNCTION_DECL
)
4834 if (DECL_DESTRUCTOR_P (t
))
4835 cp_error ("taking address of destructor");
4836 return build_unary_op (ADDR_EXPR
, t
, 0);
4838 if (TREE_CODE (t
) == VAR_DECL
)
4839 return build_unary_op (ADDR_EXPR
, t
, 0);
4845 if (TREE_OPERAND (arg
, 0)
4846 && (TREE_CODE (TREE_OPERAND (arg
, 0)) != NOP_EXPR
4847 || (TREE_OPERAND (TREE_OPERAND (arg
, 0), 0)
4848 != error_mark_node
)))
4849 if (TREE_CODE (t
) != FIELD_DECL
)
4851 /* Don't know if this should return address to just
4852 _DECL, or actual address resolved in this expression. */
4853 sorry ("address of bound pointer-to-member expression");
4854 return error_mark_node
;
4857 /* Add in the offset to the field. */
4858 offset
= convert (sizetype
,
4859 size_binop (EASY_DIV_EXPR
,
4860 DECL_FIELD_BITPOS (t
),
4861 size_int (BITS_PER_UNIT
)));
4863 /* We offset all pointer to data members by 1 so that we can
4864 distinguish between a null pointer to data member and the first
4865 data member of a structure. */
4866 offset
= size_binop (PLUS_EXPR
, offset
, size_int (1));
4868 type
= build_offset_type (DECL_FIELD_CONTEXT (t
), TREE_TYPE (t
));
4869 type
= build_pointer_type (type
);
4871 return cp_convert (type
, offset
);
4876 /* We permit compiler to make function calls returning
4877 objects of aggregate type look like lvalues. */
4881 if (TREE_CODE (targ
) == SAVE_EXPR
)
4882 targ
= TREE_OPERAND (targ
, 0);
4884 if (TREE_CODE (targ
) == CALL_EXPR
&& IS_AGGR_TYPE (TREE_TYPE (targ
)))
4886 if (TREE_CODE (arg
) == SAVE_EXPR
)
4889 targ
= build_cplus_new (TREE_TYPE (arg
), arg
);
4890 return build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (arg
)), targ
);
4893 if (TREE_CODE (arg
) == SAVE_EXPR
&& TREE_CODE (targ
) == INDIRECT_REF
)
4894 return build (SAVE_EXPR
, build_pointer_type (TREE_TYPE (arg
)),
4895 TREE_OPERAND (targ
, 0), current_function_decl
, NULL
);
4898 /* Don't let anything else be handled specially. */
4902 /* Mark EXP saying that we need to be able to take the
4903 address of it; it should not be allocated in a register.
4904 Value is 1 if successful.
4906 C++: we do not allow `current_class_ptr' to be addressable. */
4909 mark_addressable (exp
)
4912 register tree x
= exp
;
4914 if (TREE_ADDRESSABLE (x
) == 1)
4918 switch (TREE_CODE (x
))
4925 x
= TREE_OPERAND (x
, 0);
4929 if (x
== current_class_ptr
)
4931 if (! flag_this_is_variable
)
4932 error ("address of `this' not available");
4933 TREE_ADDRESSABLE (x
) = 1; /* so compiler doesn't die later */
4934 put_var_into_stack (x
);
4938 if (TREE_STATIC (x
) && TREE_READONLY (x
)
4939 && DECL_RTL (x
) != 0
4940 && ! DECL_IN_MEMORY_P (x
))
4942 /* We thought this would make a good constant variable,
4943 but we were wrong. */
4944 push_obstacks_nochange ();
4945 end_temporary_allocation ();
4947 TREE_ASM_WRITTEN (x
) = 0;
4949 rest_of_decl_compilation (x
, 0, IDENTIFIER_LOCAL_VALUE (x
) == 0,
4951 TREE_ADDRESSABLE (x
) = 1;
4957 /* Caller should not be trying to mark initialized
4958 constant fields addressable. */
4959 my_friendly_assert (DECL_LANG_SPECIFIC (x
) == 0
4960 || DECL_IN_AGGR_P (x
) == 0
4962 || DECL_EXTERNAL (x
), 314);
4966 if (DECL_REGISTER (x
) && !TREE_ADDRESSABLE (x
)
4967 && !DECL_ARTIFICIAL (x
) && extra_warnings
)
4968 cp_warning ("address requested for `%D', which is declared `register'",
4970 put_var_into_stack (x
);
4971 TREE_ADDRESSABLE (x
) = 1;
4975 if (DECL_LANG_SPECIFIC (x
) != 0)
4977 x
= DECL_MAIN_VARIANT (x
);
4978 /* We have to test both conditions here. The first may be
4979 non-zero in the case of processing a default function. The
4980 second may be non-zero in the case of a template function. */
4981 if (DECL_TEMPLATE_INFO (x
) && !DECL_TEMPLATE_SPECIALIZATION (x
))
4984 TREE_ADDRESSABLE (x
) = 1;
4986 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x
)) = 1;
4990 TREE_ADDRESSABLE (x
) = 1;
4994 TREE_ADDRESSABLE (x
) = 1;
4995 mark_addressable (TREE_OPERAND (x
, 0));
5003 /* Build and return a conditional expression IFEXP ? OP1 : OP2. */
5006 build_x_conditional_expr (ifexp
, op1
, op2
)
5007 tree ifexp
, op1
, op2
;
5009 if (processing_template_decl
)
5010 return build_min_nt (COND_EXPR
, ifexp
, op1
, op2
);
5012 return build_new_op (COND_EXPR
, LOOKUP_NORMAL
, ifexp
, op1
, op2
);
5016 build_conditional_expr (ifexp
, op1
, op2
)
5017 tree ifexp
, op1
, op2
;
5019 register tree type1
;
5020 register tree type2
;
5021 register enum tree_code code1
;
5022 register enum tree_code code2
;
5023 register tree result_type
= NULL_TREE
;
5025 /* If second operand is omitted, it is the same as the first one;
5026 make sure it is calculated only once. */
5030 pedwarn ("ANSI C++ forbids omitting the middle term of a ?: expression");
5031 ifexp
= op1
= save_expr (ifexp
);
5034 ifexp
= cp_convert (boolean_type_node
, ifexp
);
5036 if (TREE_CODE (ifexp
) == ERROR_MARK
)
5037 return error_mark_node
;
5039 op1
= require_instantiated_type (TREE_TYPE (op2
), op1
, error_mark_node
);
5040 if (op1
== error_mark_node
)
5041 return error_mark_node
;
5042 op2
= require_instantiated_type (TREE_TYPE (op1
), op2
, error_mark_node
);
5043 if (op2
== error_mark_node
)
5044 return error_mark_node
;
5046 /* C++: REFERENCE_TYPES must be dereferenced. */
5047 type1
= TREE_TYPE (op1
);
5048 code1
= TREE_CODE (type1
);
5049 type2
= TREE_TYPE (op2
);
5050 code2
= TREE_CODE (type2
);
5052 if (code1
== REFERENCE_TYPE
)
5054 op1
= convert_from_reference (op1
);
5055 type1
= TREE_TYPE (op1
);
5056 code1
= TREE_CODE (type1
);
5058 if (code2
== REFERENCE_TYPE
)
5060 op2
= convert_from_reference (op2
);
5061 type2
= TREE_TYPE (op2
);
5062 code2
= TREE_CODE (type2
);
5065 /* Don't promote the operands separately if they promote
5066 the same way. Return the unpromoted type and let the combined
5067 value get promoted if necessary. */
5069 if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
)
5070 && code2
!= ARRAY_TYPE
5071 && code2
!= FUNCTION_TYPE
5072 && code2
!= METHOD_TYPE
)
5076 if (TREE_CONSTANT (ifexp
)
5077 && (TREE_CODE (ifexp
) == INTEGER_CST
5078 || TREE_CODE (ifexp
) == ADDR_EXPR
))
5079 return (integer_zerop (ifexp
) ? op2
: op1
);
5081 if (TREE_CODE (op1
) == CONST_DECL
)
5082 op1
= DECL_INITIAL (op1
);
5083 else if (TREE_READONLY_DECL_P (op1
))
5084 op1
= decl_constant_value (op1
);
5085 if (TREE_CODE (op2
) == CONST_DECL
)
5086 op2
= DECL_INITIAL (op2
);
5087 else if (TREE_READONLY_DECL_P (op2
))
5088 op2
= decl_constant_value (op2
);
5090 type1
= cp_build_type_variant
5092 TREE_READONLY (op1
) || TREE_READONLY (op2
),
5093 TREE_THIS_VOLATILE (op1
) || TREE_THIS_VOLATILE (op2
));
5094 /* ??? This is a kludge to deal with the fact that
5095 we don't sort out integers and enums properly, yet. */
5096 result
= fold (build (COND_EXPR
, type1
, ifexp
, op1
, op2
));
5097 if (TREE_TYPE (result
) != type1
)
5098 result
= build1 (NOP_EXPR
, type1
, result
);
5099 /* Expand both sides into the same slot,
5100 hopefully the target of the ?: expression. */
5101 if (TREE_CODE (op1
) == TARGET_EXPR
&& TREE_CODE (op2
) == TARGET_EXPR
)
5103 tree slot
= build (VAR_DECL
, TREE_TYPE (result
));
5104 layout_decl (slot
, 0);
5105 result
= build (TARGET_EXPR
, TREE_TYPE (result
),
5106 slot
, result
, NULL_TREE
, NULL_TREE
);
5111 /* They don't match; promote them both and then try to reconcile them.
5112 But don't permit mismatching enum types. */
5113 if (code1
== ENUMERAL_TYPE
)
5115 if (code2
== ENUMERAL_TYPE
)
5117 cp_error ("enumeral mismatch in conditional expression: `%T' vs `%T'",
5119 return error_mark_node
;
5121 else if (extra_warnings
&& ! IS_AGGR_TYPE_CODE (code2
)
5122 && type2
!= type_promotes_to (type1
))
5123 warning ("enumeral and non-enumeral type in conditional expression");
5125 else if (extra_warnings
5126 && code2
== ENUMERAL_TYPE
&& ! IS_AGGR_TYPE_CODE (code1
)
5127 && type1
!= type_promotes_to (type2
))
5128 warning ("enumeral and non-enumeral type in conditional expression");
5130 if (code1
!= VOID_TYPE
)
5132 op1
= default_conversion (op1
);
5133 type1
= TREE_TYPE (op1
);
5134 if (TYPE_PTRMEMFUNC_P (type1
))
5135 type1
= TYPE_PTRMEMFUNC_FN_TYPE (type1
);
5136 code1
= TREE_CODE (type1
);
5138 if (code2
!= VOID_TYPE
)
5140 op2
= default_conversion (op2
);
5141 type2
= TREE_TYPE (op2
);
5142 if (TYPE_PTRMEMFUNC_P (type2
))
5143 type2
= TYPE_PTRMEMFUNC_FN_TYPE (type2
);
5144 code2
= TREE_CODE (type2
);
5147 if (code1
== RECORD_TYPE
&& code2
== RECORD_TYPE
5148 && real_lvalue_p (op1
) && real_lvalue_p (op2
)
5149 && comptypes (type1
, type2
, -1))
5151 type1
= build_reference_type (type1
);
5152 type2
= build_reference_type (type2
);
5153 result_type
= common_type (type1
, type2
);
5154 op1
= convert_to_reference (result_type
, op1
, CONV_IMPLICIT
,
5155 LOOKUP_NORMAL
, NULL_TREE
);
5156 op2
= convert_to_reference (result_type
, op2
, CONV_IMPLICIT
,
5157 LOOKUP_NORMAL
, NULL_TREE
);
5159 /* Quickly detect the usual case where op1 and op2 have the same type
5161 else if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
))
5164 result_type
= type1
;
5166 result_type
= cp_build_type_variant
5168 TREE_READONLY (op1
) || TREE_READONLY (op2
),
5169 TREE_THIS_VOLATILE (op1
) || TREE_THIS_VOLATILE (op2
));
5171 else if ((code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
)
5172 && (code2
== INTEGER_TYPE
|| code2
== REAL_TYPE
))
5174 result_type
= common_type (type1
, type2
);
5176 else if (code1
== VOID_TYPE
|| code2
== VOID_TYPE
)
5178 if (pedantic
&& (code1
!= VOID_TYPE
|| code2
!= VOID_TYPE
))
5179 pedwarn ("ANSI C++ forbids conditional expr with only one void side");
5180 result_type
= void_type_node
;
5182 else if (code1
== POINTER_TYPE
&& null_ptr_cst_p (op2
))
5183 result_type
= qualify_type (type1
, type2
);
5184 else if (code2
== POINTER_TYPE
&& null_ptr_cst_p (op1
))
5185 result_type
= qualify_type (type2
, type1
);
5186 else if (code1
== POINTER_TYPE
&& code2
== POINTER_TYPE
)
5188 if (comp_target_types (type1
, type2
, 1))
5189 result_type
= common_type (type1
, type2
);
5190 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1
)) == void_type_node
)
5192 if (pedantic
&& TREE_CODE (type2
) == FUNCTION_TYPE
)
5193 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
5194 result_type
= qualify_type (type1
, type2
);
5196 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2
)) == void_type_node
)
5198 if (pedantic
&& TREE_CODE (type1
) == FUNCTION_TYPE
)
5199 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
5200 result_type
= qualify_type (type2
, type1
);
5203 else if (comptypes (type2
, type1
, 0))
5204 result_type
= type2
;
5205 else if (IS_AGGR_TYPE (TREE_TYPE (type1
))
5206 && IS_AGGR_TYPE (TREE_TYPE (type2
))
5207 && (result_type
= common_base_type (TREE_TYPE (type1
),
5208 TREE_TYPE (type2
))))
5210 if (result_type
== error_mark_node
)
5212 cp_error ("common base type of types `%T' and `%T' is ambiguous",
5213 TREE_TYPE (type1
), TREE_TYPE (type2
));
5214 result_type
= ptr_type_node
;
5219 && result_type
!= TREE_TYPE (type1
)
5220 && result_type
!= TREE_TYPE (type2
))
5221 cp_pedwarn ("`%T' and `%T' converted to `%T *' in conditional expression",
5222 type1
, type2
, result_type
);
5224 result_type
= build_pointer_type (result_type
);
5229 pedwarn ("pointer type mismatch in conditional expression");
5230 result_type
= ptr_type_node
;
5233 else if (code1
== POINTER_TYPE
&& code2
== INTEGER_TYPE
)
5235 pedwarn ("pointer/integer type mismatch in conditional expression");
5236 result_type
= type1
;
5238 else if (code2
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
5240 pedwarn ("pointer/integer type mismatch in conditional expression");
5241 result_type
= type2
;
5246 /* The match does not look good. If either is
5247 an aggregate value, try converting to a scalar type. */
5248 if (code1
== RECORD_TYPE
&& code2
== RECORD_TYPE
)
5250 cp_error ("aggregate mismatch in conditional expression: `%T' vs `%T'",
5252 return error_mark_node
;
5254 /* Warning: this code assumes that conversion between cv-variants of
5255 a type is done using NOP_EXPRs. */
5256 if (code1
== RECORD_TYPE
&& TYPE_HAS_CONVERSION (type1
))
5258 /* There are other types besides pointers and records. */
5260 if (code2
== POINTER_TYPE
)
5261 tmp
= build_pointer_type
5262 (build_type_variant (TREE_TYPE (type2
), 1, 1));
5265 tmp
= build_type_conversion (CONVERT_EXPR
, tmp
, op1
, 0);
5266 if (tmp
== NULL_TREE
)
5268 cp_error ("incompatible types `%T' and `%T' in `?:'",
5270 return error_mark_node
;
5272 if (tmp
== error_mark_node
)
5273 error ("ambiguous pointer conversion");
5276 result_type
= common_type (type2
, TREE_TYPE (tmp
));
5279 else if (code2
== RECORD_TYPE
&& TYPE_HAS_CONVERSION (type2
))
5282 if (code1
== POINTER_TYPE
)
5283 tmp
= build_pointer_type
5284 (build_type_variant (TREE_TYPE (type1
), 1, 1));
5288 tmp
= build_type_conversion (CONVERT_EXPR
, tmp
, op2
, 0);
5289 if (tmp
== NULL_TREE
)
5291 cp_error ("incompatible types `%T' and `%T' in `?:'",
5293 return error_mark_node
;
5295 if (tmp
== error_mark_node
)
5296 error ("ambiguous pointer conversion");
5299 result_type
= common_type (type1
, TREE_TYPE (tmp
));
5302 else if (flag_cond_mismatch
)
5303 result_type
= void_type_node
;
5306 error ("type mismatch in conditional expression");
5307 return error_mark_node
;
5311 if (TREE_CODE (result_type
) == POINTER_TYPE
5312 && TREE_CODE (TREE_TYPE (result_type
)) == METHOD_TYPE
)
5313 result_type
= build_ptrmemfunc_type (result_type
);
5315 if (result_type
!= TREE_TYPE (op1
))
5316 op1
= convert_for_initialization
5317 (NULL_TREE
, result_type
, op1
, LOOKUP_NORMAL
, "converting", NULL_TREE
, 0);
5318 if (result_type
!= TREE_TYPE (op2
))
5319 op2
= convert_for_initialization
5320 (NULL_TREE
, result_type
, op2
, LOOKUP_NORMAL
, "converting", NULL_TREE
, 0);
5322 if (TREE_CONSTANT (ifexp
))
5323 return integer_zerop (ifexp
) ? op2
: op1
;
5325 return convert_from_reference
5326 (fold (build (COND_EXPR
, result_type
, ifexp
, op1
, op2
)));
5329 /* Handle overloading of the ',' operator when needed. Otherwise,
5330 this function just builds an expression list. */
5333 build_x_compound_expr (list
)
5336 tree rest
= TREE_CHAIN (list
);
5339 if (processing_template_decl
)
5340 return build_min_nt (COMPOUND_EXPR
, list
, NULL_TREE
);
5342 if (rest
== NULL_TREE
)
5343 return build_compound_expr (list
);
5345 result
= build_opfncall (COMPOUND_EXPR
, LOOKUP_NORMAL
,
5346 TREE_VALUE (list
), TREE_VALUE (rest
), NULL_TREE
);
5348 return build_x_compound_expr (expr_tree_cons (NULL_TREE
, result
,
5349 TREE_CHAIN (rest
)));
5351 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list
)))
5353 /* the left-hand operand of a comma expression is like an expression
5354 statement: we should warn if it doesn't have any side-effects,
5355 unless it was explicitly cast to (void). */
5356 if ((extra_warnings
|| warn_unused
)
5357 && !(TREE_CODE (TREE_VALUE(list
)) == CONVERT_EXPR
5358 && TREE_TYPE (TREE_VALUE(list
)) == void_type_node
))
5359 warning("left-hand operand of comma expression has no effect");
5361 #if 0 /* this requires a gcc backend patch to export warn_if_unused_value */
5362 else if (warn_unused
)
5363 warn_if_unused_value (TREE_VALUE(list
));
5366 return build_compound_expr
5367 (expr_tree_cons (NULL_TREE
, TREE_VALUE (list
),
5368 build_expr_list (NULL_TREE
,
5369 build_x_compound_expr (rest
))));
5372 /* Given a list of expressions, return a compound expression
5373 that performs them all and returns the value of the last of them. */
5376 build_compound_expr (list
)
5381 if (TREE_READONLY_DECL_P (TREE_VALUE (list
)))
5382 TREE_VALUE (list
) = decl_constant_value (TREE_VALUE (list
));
5384 if (TREE_CHAIN (list
) == 0)
5386 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5387 Strip such NOP_EXPRs, since LIST is used in non-lvalue context. */
5388 if (TREE_CODE (list
) == NOP_EXPR
5389 && TREE_TYPE (list
) == TREE_TYPE (TREE_OPERAND (list
, 0)))
5390 list
= TREE_OPERAND (list
, 0);
5392 /* Convert arrays to pointers. */
5393 if (TREE_CODE (TREE_TYPE (TREE_VALUE (list
))) == ARRAY_TYPE
)
5394 return default_conversion (TREE_VALUE (list
));
5396 return TREE_VALUE (list
);
5399 rest
= build_compound_expr (TREE_CHAIN (list
));
5401 /* When pedantic, a compound expression cannot be a constant expression. */
5402 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list
)) && ! pedantic
)
5405 return build (COMPOUND_EXPR
, TREE_TYPE (rest
),
5406 break_out_cleanups (TREE_VALUE (list
)), rest
);
5410 build_static_cast (type
, expr
)
5416 if (type
== error_mark_node
|| expr
== error_mark_node
)
5417 return error_mark_node
;
5419 if (TREE_CODE (expr
) == OFFSET_REF
)
5420 expr
= resolve_offset_ref (expr
);
5422 if (processing_template_decl
)
5424 tree t
= build_min (STATIC_CAST_EXPR
, copy_to_permanent (type
),
5429 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5430 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5431 if (TREE_CODE (type
) != REFERENCE_TYPE
5432 && TREE_CODE (expr
) == NOP_EXPR
5433 && TREE_TYPE (expr
) == TREE_TYPE (TREE_OPERAND (expr
, 0)))
5434 expr
= TREE_OPERAND (expr
, 0);
5436 if (TREE_CODE (type
) == VOID_TYPE
)
5437 return build1 (CONVERT_EXPR
, type
, expr
);
5439 if (type_unknown_p (expr
))
5441 expr
= instantiate_type (type
, expr
, 1);
5442 if (expr
== error_mark_node
)
5443 return error_mark_node
;
5446 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5447 return (convert_from_reference
5448 (convert_to_reference (type
, expr
, CONV_STATIC
|CONV_IMPLICIT
,
5449 LOOKUP_COMPLAIN
, NULL_TREE
)));
5451 if (IS_AGGR_TYPE (type
))
5452 return build_cplus_new
5453 (type
, (build_method_call
5454 (NULL_TREE
, ctor_identifier
, build_expr_list (NULL_TREE
, expr
),
5455 TYPE_BINFO (type
), LOOKUP_NORMAL
)));
5457 expr
= decay_conversion (expr
);
5458 intype
= TREE_TYPE (expr
);
5460 /* FIXME handle casting to array type. */
5463 if (can_convert_arg (type
, intype
, expr
))
5465 else if (TYPE_PTROB_P (type
) && TYPE_PTROB_P (intype
))
5468 if (IS_AGGR_TYPE (TREE_TYPE (type
)) && IS_AGGR_TYPE (TREE_TYPE (intype
))
5469 && (TYPE_READONLY (TREE_TYPE (type
))
5470 >= TYPE_READONLY (TREE_TYPE (intype
)))
5471 && (TYPE_VOLATILE (TREE_TYPE (type
))
5472 >= TYPE_VOLATILE (TREE_TYPE (intype
)))
5473 && (binfo
= get_binfo (TREE_TYPE (intype
), TREE_TYPE (type
), 0))
5474 && ! TREE_VIA_VIRTUAL (binfo
))
5477 else if (TYPE_PTRMEM_P (type
) && TYPE_PTRMEM_P (intype
))
5479 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
))),
5480 TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (intype
))), 1)
5481 && (TYPE_READONLY (TREE_TYPE (TREE_TYPE (type
)))
5482 >= TYPE_READONLY (TREE_TYPE (TREE_TYPE (intype
))))
5483 && (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (type
)))
5484 >= TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (intype
))))
5485 && (binfo
= get_binfo (TYPE_OFFSET_BASETYPE (TREE_TYPE (type
)),
5486 TYPE_OFFSET_BASETYPE (TREE_TYPE (intype
)), 0))
5487 && ! TREE_VIA_VIRTUAL (binfo
))
5490 else if (TREE_CODE (intype
) != BOOLEAN_TYPE
5491 && TREE_CODE (type
) != ARRAY_TYPE
5492 && TREE_CODE (type
) != FUNCTION_TYPE
5493 && can_convert (intype
, type
))
5497 return build_c_cast (type
, expr
);
5499 cp_error ("static_cast from `%T' to `%T'", intype
, type
);
5500 return error_mark_node
;
5504 build_reinterpret_cast (type
, expr
)
5509 if (type
== error_mark_node
|| expr
== error_mark_node
)
5510 return error_mark_node
;
5512 if (TREE_CODE (expr
) == OFFSET_REF
)
5513 expr
= resolve_offset_ref (expr
);
5515 if (processing_template_decl
)
5517 tree t
= build_min (REINTERPRET_CAST_EXPR
,
5518 copy_to_permanent (type
), expr
);
5522 if (TREE_CODE (type
) != REFERENCE_TYPE
)
5524 expr
= decay_conversion (expr
);
5526 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5527 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5528 if (TREE_CODE (expr
) == NOP_EXPR
5529 && TREE_TYPE (expr
) == TREE_TYPE (TREE_OPERAND (expr
, 0)))
5530 expr
= TREE_OPERAND (expr
, 0);
5533 if (type_unknown_p (expr
))
5535 expr
= instantiate_type (type
, expr
, 1);
5536 if (expr
== error_mark_node
)
5537 return error_mark_node
;
5540 intype
= TREE_TYPE (expr
);
5542 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5544 if (! real_lvalue_p (expr
))
5546 cp_error ("reinterpret_cast from `%T' rvalue to `%T'", intype
, type
);
5547 return error_mark_node
;
5549 expr
= build_unary_op (ADDR_EXPR
, expr
, 0);
5550 if (expr
!= error_mark_node
)
5551 expr
= build_reinterpret_cast
5552 (build_pointer_type (TREE_TYPE (type
)), expr
);
5553 if (expr
!= error_mark_node
)
5554 expr
= build_indirect_ref (expr
, 0);
5557 else if (comptypes (TYPE_MAIN_VARIANT (intype
), TYPE_MAIN_VARIANT (type
), 1))
5558 return build_static_cast (type
, expr
);
5560 if (TYPE_PTR_P (type
) && (TREE_CODE (intype
) == INTEGER_TYPE
5561 || TREE_CODE (intype
) == ENUMERAL_TYPE
))
5563 else if (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_PTR_P (intype
))
5565 if (TYPE_PRECISION (type
) < TYPE_PRECISION (intype
))
5566 cp_pedwarn ("reinterpret_cast from `%T' to `%T' loses precision",
5569 else if ((TYPE_PTRFN_P (type
) && TYPE_PTRFN_P (intype
))
5570 || (TYPE_PTRMEMFUNC_P (type
) && TYPE_PTRMEMFUNC_P (intype
)))
5572 if (TREE_READONLY_DECL_P (expr
))
5573 expr
= decl_constant_value (expr
);
5574 return fold (build1 (NOP_EXPR
, type
, expr
));
5576 else if ((TYPE_PTRMEM_P (type
) && TYPE_PTRMEM_P (intype
))
5577 || (TYPE_PTROBV_P (type
) && TYPE_PTROBV_P (intype
)))
5579 if (! comp_ptr_ttypes_reinterpret (TREE_TYPE (type
), TREE_TYPE (intype
)))
5580 cp_pedwarn ("reinterpret_cast from `%T' to `%T' casts away const (or volatile)",
5583 if (TREE_READONLY_DECL_P (expr
))
5584 expr
= decl_constant_value (expr
);
5585 return fold (build1 (NOP_EXPR
, type
, expr
));
5587 else if ((TYPE_PTRFN_P (type
) && TYPE_PTROBV_P (intype
))
5588 || (TYPE_PTRFN_P (type
) && TYPE_PTROBV_P (intype
)))
5590 pedwarn ("ANSI C++ forbids casting between pointers to functions and objects");
5591 if (TREE_READONLY_DECL_P (expr
))
5592 expr
= decl_constant_value (expr
);
5593 return fold (build1 (NOP_EXPR
, type
, expr
));
5597 cp_error ("reinterpret_cast from `%T' to `%T'", intype
, type
);
5598 return error_mark_node
;
5601 return cp_convert (type
, expr
);
5605 build_const_cast (type
, expr
)
5610 if (type
== error_mark_node
|| expr
== error_mark_node
)
5611 return error_mark_node
;
5613 if (TREE_CODE (expr
) == OFFSET_REF
)
5614 expr
= resolve_offset_ref (expr
);
5616 if (processing_template_decl
)
5618 tree t
= build_min (CONST_CAST_EXPR
, copy_to_permanent (type
),
5623 if (TREE_CODE (type
) != REFERENCE_TYPE
)
5625 expr
= decay_conversion (expr
);
5627 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5628 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5629 if (TREE_CODE (expr
) == NOP_EXPR
5630 && TREE_TYPE (expr
) == TREE_TYPE (TREE_OPERAND (expr
, 0)))
5631 expr
= TREE_OPERAND (expr
, 0);
5634 if (type_unknown_p (expr
))
5636 expr
= instantiate_type (type
, expr
, 1);
5637 if (expr
== error_mark_node
)
5638 return error_mark_node
;
5641 intype
= TREE_TYPE (expr
);
5643 if (comptypes (TYPE_MAIN_VARIANT (intype
), TYPE_MAIN_VARIANT (type
), 1))
5644 return build_static_cast (type
, expr
);
5645 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
5647 if (! real_lvalue_p (expr
))
5649 cp_error ("const_cast from `%T' rvalue to `%T'", intype
, type
);
5650 return error_mark_node
;
5653 if (comp_ptr_ttypes_const (TREE_TYPE (type
), intype
))
5655 expr
= build_unary_op (ADDR_EXPR
, expr
, 0);
5656 expr
= build1 (NOP_EXPR
, type
, expr
);
5657 return convert_from_reference (expr
);
5660 else if (TREE_CODE (type
) == POINTER_TYPE
5661 && TREE_CODE (intype
) == POINTER_TYPE
5662 && comp_ptr_ttypes_const (TREE_TYPE (type
), TREE_TYPE (intype
)))
5663 return cp_convert (type
, expr
);
5665 cp_error ("const_cast from `%T' to `%T'", intype
, type
);
5666 return error_mark_node
;
5669 /* Build an expression representing a cast to type TYPE of expression EXPR.
5671 ALLOW_NONCONVERTING is true if we should allow non-converting constructors
5672 when doing the cast. */
5675 build_c_cast (type
, expr
)
5678 register tree value
= expr
;
5680 if (type
== error_mark_node
|| expr
== error_mark_node
)
5681 return error_mark_node
;
5683 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5684 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5685 if (TREE_CODE (type
) != REFERENCE_TYPE
5686 && TREE_CODE (value
) == NOP_EXPR
5687 && TREE_TYPE (value
) == TREE_TYPE (TREE_OPERAND (value
, 0)))
5688 value
= TREE_OPERAND (value
, 0);
5690 if (TREE_TYPE (expr
)
5691 && TREE_CODE (TREE_TYPE (expr
)) == OFFSET_TYPE
5692 && TREE_CODE (type
) != OFFSET_TYPE
)
5693 value
= resolve_offset_ref (value
);
5695 if (TREE_CODE (type
) == ARRAY_TYPE
)
5697 /* Allow casting from T1* to T2[] because Cfront allows it.
5698 NIHCL uses it. It is not valid ANSI C however, and hence, not
5700 if (TREE_CODE (TREE_TYPE (expr
)) == POINTER_TYPE
)
5703 pedwarn ("ANSI C++ forbids casting to an array type");
5704 type
= build_pointer_type (TREE_TYPE (type
));
5708 error ("ANSI C++ forbids casting to an array type");
5709 return error_mark_node
;
5713 if (TREE_CODE (type
) == FUNCTION_TYPE
5714 || TREE_CODE (type
) == METHOD_TYPE
)
5716 cp_error ("casting to function type `%T'", type
);
5717 return error_mark_node
;
5720 if (IS_SIGNATURE (type
))
5722 error ("cast specifies signature type");
5723 return error_mark_node
;
5726 if (processing_template_decl
)
5728 tree t
= build_min (CAST_EXPR
, type
,
5729 min_tree_cons (NULL_TREE
, value
, NULL_TREE
));
5733 if (TREE_CODE (type
) == VOID_TYPE
)
5734 value
= build1 (CONVERT_EXPR
, type
, value
);
5735 else if (TREE_TYPE (value
) == NULL_TREE
5736 || type_unknown_p (value
))
5738 value
= instantiate_type (type
, value
, 1);
5740 if (value
== error_mark_node
)
5741 return error_mark_node
;
5747 /* Convert functions and arrays to pointers and
5748 convert references to their expanded types,
5749 but don't convert any other types. If, however, we are
5750 casting to a class type, there's no reason to do this: the
5751 cast will only succeed if there is a converting constructor,
5752 and the default conversions will be done at that point. In
5753 fact, doing the default conversion here is actually harmful
5757 struct S { S(const A&); };
5759 since we don't want the array-to-pointer conversion done. */
5760 if (!IS_AGGR_TYPE (type
))
5762 if (TREE_CODE (TREE_TYPE (value
)) == FUNCTION_TYPE
5763 || (TREE_CODE (TREE_TYPE (value
)) == METHOD_TYPE
5764 /* Don't do the default conversion if we want a
5765 pointer to a function. */
5766 && ! (TREE_CODE (type
) == POINTER_TYPE
5767 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
))
5768 || TREE_CODE (TREE_TYPE (value
)) == ARRAY_TYPE
5769 || TREE_CODE (TREE_TYPE (value
)) == REFERENCE_TYPE
)
5770 value
= default_conversion (value
);
5772 else if (TREE_CODE (TREE_TYPE (value
)) == REFERENCE_TYPE
)
5773 /* However, even for class types, we still need to strip away
5774 the reference type, since the call to convert_force below
5775 does not expect the input expression to be of reference
5777 value
= convert_from_reference (value
);
5779 otype
= TREE_TYPE (value
);
5781 /* Optionally warn about potentially worrisome casts. */
5784 && TREE_CODE (type
) == POINTER_TYPE
5785 && TREE_CODE (otype
) == POINTER_TYPE
)
5787 /* For C++ we make these regular warnings, rather than
5788 softening them into pedwarns. */
5789 if (TYPE_VOLATILE (TREE_TYPE (otype
))
5790 && ! TYPE_VOLATILE (TREE_TYPE (type
)))
5791 warning ("cast discards `volatile' from pointer target type");
5792 if (TYPE_READONLY (TREE_TYPE (otype
))
5793 && ! TYPE_READONLY (TREE_TYPE (type
)))
5794 warning ("cast discards `const' from pointer target type");
5797 /* Warn about possible alignment problems. */
5798 if (STRICT_ALIGNMENT
&& warn_cast_align
5799 && TREE_CODE (type
) == POINTER_TYPE
5800 && TREE_CODE (otype
) == POINTER_TYPE
5801 && TREE_CODE (TREE_TYPE (otype
)) != VOID_TYPE
5802 && TREE_CODE (TREE_TYPE (otype
)) != FUNCTION_TYPE
5803 && TYPE_ALIGN (TREE_TYPE (type
)) > TYPE_ALIGN (TREE_TYPE (otype
)))
5804 warning ("cast increases required alignment of target type");
5807 /* We should see about re-enabling these, they seem useful to
5809 if (TREE_CODE (type
) == INTEGER_TYPE
5810 && TREE_CODE (otype
) == POINTER_TYPE
5811 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
))
5812 warning ("cast from pointer to integer of different size");
5814 if (TREE_CODE (type
) == POINTER_TYPE
5815 && TREE_CODE (otype
) == INTEGER_TYPE
5816 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
)
5817 /* Don't warn about converting 0 to pointer,
5818 provided the 0 was explicit--not cast or made by folding. */
5819 && !(TREE_CODE (value
) == INTEGER_CST
&& integer_zerop (value
)))
5820 warning ("cast to pointer from integer of different size");
5823 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5824 value
= (convert_from_reference
5825 (convert_to_reference (type
, value
, CONV_C_CAST
,
5826 LOOKUP_COMPLAIN
, NULL_TREE
)));
5831 if (TREE_READONLY_DECL_P (value
))
5832 value
= decl_constant_value (value
);
5835 value
= convert_force (type
, value
, CONV_C_CAST
);
5837 /* Ignore any integer overflow caused by the cast. */
5838 if (TREE_CODE (value
) == INTEGER_CST
)
5840 TREE_OVERFLOW (value
) = TREE_OVERFLOW (ovalue
);
5841 TREE_CONSTANT_OVERFLOW (value
) = TREE_CONSTANT_OVERFLOW (ovalue
);
5846 /* Always produce some operator for an explicit cast,
5847 so we can tell (for -pedantic) that the cast is no lvalue. */
5848 if (TREE_CODE (type
) != REFERENCE_TYPE
&& value
== expr
5849 && real_lvalue_p (value
))
5850 value
= non_lvalue (value
);
5855 /* Build an assignment expression of lvalue LHS from value RHS.
5856 MODIFYCODE is the code for a binary operator that we use
5857 to combine the old value of LHS with RHS to get the new value.
5858 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
5860 C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed. */
5863 build_modify_expr (lhs
, modifycode
, rhs
)
5865 enum tree_code modifycode
;
5868 register tree result
;
5870 tree lhstype
= TREE_TYPE (lhs
);
5871 tree olhstype
= lhstype
;
5874 /* Avoid duplicate error messages from operands that had errors. */
5875 if (lhs
== error_mark_node
|| rhs
== error_mark_node
)
5876 return error_mark_node
;
5878 /* Types that aren't fully specified cannot be used in assignments. */
5879 lhs
= require_complete_type (lhs
);
5883 /* Handle assignment to signature pointers/refs. */
5885 if (TYPE_LANG_SPECIFIC (lhstype
)
5886 && (IS_SIGNATURE_POINTER (lhstype
) || IS_SIGNATURE_REFERENCE (lhstype
)))
5888 return build_signature_pointer_constructor (lhs
, rhs
);
5891 /* Handle control structure constructs used as "lvalues". */
5893 switch (TREE_CODE (lhs
))
5895 /* Handle --foo = 5; as these are valid constructs in C++ */
5896 case PREDECREMENT_EXPR
:
5897 case PREINCREMENT_EXPR
:
5898 if (TREE_SIDE_EFFECTS (TREE_OPERAND (lhs
, 0)))
5899 lhs
= build (TREE_CODE (lhs
), TREE_TYPE (lhs
),
5900 stabilize_reference (TREE_OPERAND (lhs
, 0)),
5901 TREE_OPERAND (lhs
, 1));
5902 return build (COMPOUND_EXPR
, lhstype
,
5904 build_modify_expr (TREE_OPERAND (lhs
, 0),
5907 /* Handle (a, b) used as an "lvalue". */
5909 newrhs
= build_modify_expr (TREE_OPERAND (lhs
, 1),
5911 if (newrhs
== error_mark_node
)
5912 return error_mark_node
;
5913 return build (COMPOUND_EXPR
, lhstype
,
5914 TREE_OPERAND (lhs
, 0), newrhs
);
5917 newrhs
= build_modify_expr (TREE_OPERAND (lhs
, 0), modifycode
, rhs
);
5918 if (newrhs
== error_mark_node
)
5919 return error_mark_node
;
5920 return build (COMPOUND_EXPR
, lhstype
, lhs
, newrhs
);
5922 /* Handle (a ? b : c) used as an "lvalue". */
5924 rhs
= save_expr (rhs
);
5926 /* Produce (a ? (b = rhs) : (c = rhs))
5927 except that the RHS goes through a save-expr
5928 so the code to compute it is only emitted once. */
5930 = build_conditional_expr (TREE_OPERAND (lhs
, 0),
5931 build_modify_expr (cp_convert (TREE_TYPE (lhs
), TREE_OPERAND (lhs
, 1)),
5933 build_modify_expr (cp_convert (TREE_TYPE (lhs
), TREE_OPERAND (lhs
, 2)),
5935 if (cond
== error_mark_node
)
5937 /* Make sure the code to compute the rhs comes out
5938 before the split. */
5939 return build (COMPOUND_EXPR
, TREE_TYPE (lhs
),
5940 /* Case to void to suppress warning
5941 from warn_if_unused_value. */
5942 cp_convert (void_type_node
, rhs
), cond
);
5949 if (TREE_CODE (lhs
) == OFFSET_REF
)
5951 if (TREE_OPERAND (lhs
, 0) == NULL_TREE
)
5953 /* Static class member? */
5954 tree member
= TREE_OPERAND (lhs
, 1);
5955 if (TREE_CODE (member
) == VAR_DECL
)
5959 compiler_error ("invalid static class member");
5960 return error_mark_node
;
5964 lhs
= resolve_offset_ref (lhs
);
5966 olhstype
= lhstype
= TREE_TYPE (lhs
);
5969 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
5970 && modifycode
!= INIT_EXPR
)
5972 lhs
= convert_from_reference (lhs
);
5973 olhstype
= lhstype
= TREE_TYPE (lhs
);
5976 /* If a binary op has been requested, combine the old LHS value with the RHS
5977 producing the value we should actually store into the LHS. */
5979 if (modifycode
== INIT_EXPR
)
5981 if (! IS_AGGR_TYPE (lhstype
))
5982 /* Do the default thing */;
5985 result
= build_method_call (lhs
, ctor_identifier
,
5986 build_expr_list (NULL_TREE
, rhs
),
5987 TYPE_BINFO (lhstype
), LOOKUP_NORMAL
);
5988 if (result
== NULL_TREE
)
5989 return error_mark_node
;
5993 else if (modifycode
== NOP_EXPR
)
5995 /* `operator=' is not an inheritable operator. */
5996 if (! IS_AGGR_TYPE (lhstype
))
5997 /* Do the default thing */;
6000 result
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
,
6001 lhs
, rhs
, make_node (NOP_EXPR
));
6002 if (result
== NULL_TREE
)
6003 return error_mark_node
;
6008 else if (PROMOTES_TO_AGGR_TYPE (lhstype
, REFERENCE_TYPE
))
6010 my_friendly_abort (978652);
6014 lhs
= stabilize_reference (lhs
);
6015 newrhs
= build_binary_op (modifycode
, lhs
, rhs
, 1);
6016 if (newrhs
== error_mark_node
)
6018 cp_error (" in evaluation of `%Q(%#T, %#T)'", modifycode
,
6019 TREE_TYPE (lhs
), TREE_TYPE (rhs
));
6020 return error_mark_node
;
6024 /* Handle a cast used as an "lvalue".
6025 We have already performed any binary operator using the value as cast.
6026 Now convert the result to the cast type of the lhs,
6027 and then true type of the lhs and store it there;
6028 then convert result back to the cast type to be the value
6029 of the assignment. */
6031 switch (TREE_CODE (lhs
))
6036 case FIX_TRUNC_EXPR
:
6037 case FIX_FLOOR_EXPR
:
6038 case FIX_ROUND_EXPR
:
6040 if (TREE_CODE (TREE_TYPE (newrhs
)) == ARRAY_TYPE
6041 || TREE_CODE (TREE_TYPE (newrhs
)) == FUNCTION_TYPE
6042 || TREE_CODE (TREE_TYPE (newrhs
)) == METHOD_TYPE
6043 || TREE_CODE (TREE_TYPE (newrhs
)) == OFFSET_TYPE
)
6044 newrhs
= default_conversion (newrhs
);
6046 tree inner_lhs
= TREE_OPERAND (lhs
, 0);
6049 /* WP 5.4.1: The result is an lvalue if T is a reference type,
6050 otherwise the result is an rvalue. */
6051 if (! lvalue_p (lhs
))
6052 pedwarn ("ANSI C++ forbids cast to non-reference type used as lvalue");
6054 result
= build_modify_expr (inner_lhs
, NOP_EXPR
,
6055 cp_convert (TREE_TYPE (inner_lhs
),
6056 cp_convert (lhstype
, newrhs
)));
6057 if (result
== error_mark_node
)
6059 return cp_convert (TREE_TYPE (lhs
), result
);
6066 /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
6067 Reject anything strange now. */
6069 if (!lvalue_or_else (lhs
, "assignment"))
6070 return error_mark_node
;
6072 GNU_xref_assign (lhs
);
6074 /* Warn about storing in something that is `const'. */
6075 /* For C++, don't warn if this is initialization. */
6076 if (modifycode
!= INIT_EXPR
6077 /* For assignment to `const' signature pointer/reference fields,
6078 don't warn either, we already printed a better message before. */
6079 && ! (TREE_CODE (lhs
) == COMPONENT_REF
6080 && (IS_SIGNATURE_POINTER (TREE_TYPE (TREE_OPERAND (lhs
, 0)))
6081 || IS_SIGNATURE_REFERENCE (TREE_TYPE (TREE_OPERAND (lhs
, 0)))))
6082 && (TREE_READONLY (lhs
) || TYPE_READONLY (lhstype
)
6083 || ((TREE_CODE (lhstype
) == RECORD_TYPE
6084 || TREE_CODE (lhstype
) == UNION_TYPE
)
6085 && C_TYPE_FIELDS_READONLY (lhstype
))
6086 || (TREE_CODE (lhstype
) == REFERENCE_TYPE
6087 && TYPE_READONLY (TREE_TYPE (lhstype
)))))
6088 readonly_error (lhs
, "assignment", 0);
6090 /* If storing into a structure or union member,
6091 it has probably been given type `int'.
6092 Compute the type that would go with
6093 the actual amount of storage the member occupies. */
6095 if (TREE_CODE (lhs
) == COMPONENT_REF
6096 && (TREE_CODE (lhstype
) == INTEGER_TYPE
6097 || TREE_CODE (lhstype
) == REAL_TYPE
6098 || TREE_CODE (lhstype
) == ENUMERAL_TYPE
))
6100 lhstype
= TREE_TYPE (get_unwidened (lhs
, 0));
6102 /* If storing in a field that is in actuality a short or narrower
6103 than one, we must store in the field in its actual type. */
6105 if (lhstype
!= TREE_TYPE (lhs
))
6107 lhs
= copy_node (lhs
);
6108 TREE_TYPE (lhs
) = lhstype
;
6112 /* check to see if there is an assignment to `this' */
6113 if (lhs
== current_class_ptr
)
6115 if (flag_this_is_variable
> 0
6116 && DECL_NAME (current_function_decl
) != NULL_TREE
6117 && (DECL_NAME (current_function_decl
)
6118 != constructor_name (current_class_type
)))
6119 warning ("assignment to `this' not in constructor or destructor");
6120 current_function_just_assigned_this
= 1;
6123 /* The TREE_TYPE of RHS may be TYPE_UNKNOWN. This can happen
6124 when the type of RHS is not yet known, i.e. its type
6125 is inherited from LHS. */
6126 rhs
= require_instantiated_type (lhstype
, newrhs
, error_mark_node
);
6127 if (rhs
== error_mark_node
)
6128 return error_mark_node
;
6131 if (modifycode
!= INIT_EXPR
)
6133 /* Make modifycode now either a NOP_EXPR or an INIT_EXPR. */
6134 modifycode
= NOP_EXPR
;
6135 /* Reference-bashing */
6136 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
)
6138 tree tmp
= convert_from_reference (lhs
);
6139 lhstype
= TREE_TYPE (tmp
);
6140 if (TYPE_SIZE (lhstype
) == 0)
6142 incomplete_type_error (lhs
, lhstype
);
6143 return error_mark_node
;
6148 if (TREE_CODE (TREE_TYPE (newrhs
)) == REFERENCE_TYPE
)
6150 tree tmp
= convert_from_reference (newrhs
);
6151 if (TYPE_SIZE (TREE_TYPE (tmp
)) == 0)
6153 incomplete_type_error (newrhs
, TREE_TYPE (tmp
));
6154 return error_mark_node
;
6160 if (TREE_SIDE_EFFECTS (lhs
))
6161 lhs
= stabilize_reference (lhs
);
6162 if (TREE_SIDE_EFFECTS (newrhs
))
6163 newrhs
= stabilize_reference (newrhs
);
6165 /* Convert new value to destination type. */
6167 if (TREE_CODE (lhstype
) == ARRAY_TYPE
)
6171 if (! comptypes (lhstype
, TREE_TYPE (rhs
), 0))
6173 cp_error ("incompatible types in assignment of `%T' to `%T'",
6174 TREE_TYPE (rhs
), lhstype
);
6175 return error_mark_node
;
6178 /* Allow array assignment in compiler-generated code. */
6179 if (pedantic
&& ! DECL_ARTIFICIAL (current_function_decl
))
6180 pedwarn ("ANSI C++ forbids assignment of arrays");
6182 /* Have to wrap this in RTL_EXPR for two cases:
6183 in base or member initialization and if we
6184 are a branch of a ?: operator. Since we
6185 can't easily know the latter, just do it always. */
6187 result
= make_node (RTL_EXPR
);
6189 TREE_TYPE (result
) = void_type_node
;
6190 do_pending_stack_adjust ();
6191 start_sequence_for_rtl_expr (result
);
6193 /* As a matter of principle, `start_sequence' should do this. */
6196 from_array
= TREE_CODE (TREE_TYPE (newrhs
)) == ARRAY_TYPE
6197 ? 1 + (modifycode
!= INIT_EXPR
): 0;
6198 expand_vec_init (lhs
, lhs
, array_type_nelts (lhstype
), newrhs
,
6201 do_pending_stack_adjust ();
6203 TREE_SIDE_EFFECTS (result
) = 1;
6204 RTL_EXPR_SEQUENCE (result
) = get_insns ();
6205 RTL_EXPR_RTL (result
) = const0_rtx
;
6210 if (modifycode
== INIT_EXPR
)
6212 newrhs
= convert_for_initialization (lhs
, lhstype
, newrhs
, LOOKUP_NORMAL
,
6213 "assignment", NULL_TREE
, 0);
6214 if (lhs
== DECL_RESULT (current_function_decl
))
6216 if (DECL_INITIAL (lhs
))
6217 warning ("return value from function receives multiple initializations");
6218 DECL_INITIAL (lhs
) = newrhs
;
6223 /* Avoid warnings on enum bit fields. */
6224 if (TREE_CODE (olhstype
) == ENUMERAL_TYPE
6225 && TREE_CODE (lhstype
) == INTEGER_TYPE
)
6227 newrhs
= convert_for_assignment (olhstype
, newrhs
, "assignment",
6229 newrhs
= convert_force (lhstype
, newrhs
, 0);
6232 newrhs
= convert_for_assignment (lhstype
, newrhs
, "assignment",
6234 if (TREE_CODE (newrhs
) == CALL_EXPR
6235 && TYPE_NEEDS_CONSTRUCTING (lhstype
))
6236 newrhs
= build_cplus_new (lhstype
, newrhs
);
6238 /* Can't initialize directly from a TARGET_EXPR, since that would
6239 cause the lhs to be constructed twice, and possibly result in
6240 accidental self-initialization. So we force the TARGET_EXPR to be
6241 expanded without a target. */
6242 if (TREE_CODE (newrhs
) == TARGET_EXPR
)
6243 newrhs
= build (COMPOUND_EXPR
, TREE_TYPE (newrhs
), newrhs
,
6244 TREE_OPERAND (newrhs
, 0));
6247 if (newrhs
== error_mark_node
)
6248 return error_mark_node
;
6250 if (TREE_CODE (newrhs
) == COND_EXPR
)
6253 tree cond
= TREE_OPERAND (newrhs
, 0);
6255 if (TREE_SIDE_EFFECTS (lhs
))
6256 cond
= build_compound_expr (tree_cons
6258 build_expr_list (NULL_TREE
, cond
)));
6260 /* Cannot have two identical lhs on this one tree (result) as preexpand
6261 calls will rip them out and fill in RTL for them, but when the
6262 rtl is generated, the calls will only be in the first side of the
6263 condition, not on both, or before the conditional jump! (mrs) */
6264 lhs1
= break_out_calls (lhs
);
6267 /* If there's no change, the COND_EXPR behaves like any other rhs. */
6268 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
6269 lhstype
, lhs
, newrhs
);
6272 tree result_type
= TREE_TYPE (newrhs
);
6273 /* We have to convert each arm to the proper type because the
6274 types may have been munged by constant folding. */
6276 = build (COND_EXPR
, result_type
, cond
,
6277 build_modify_expr (lhs
, modifycode
,
6278 cp_convert (result_type
,
6279 TREE_OPERAND (newrhs
, 1))),
6280 build_modify_expr (lhs1
, modifycode
,
6281 cp_convert (result_type
,
6282 TREE_OPERAND (newrhs
, 2))));
6286 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
6287 lhstype
, lhs
, newrhs
);
6289 TREE_SIDE_EFFECTS (result
) = 1;
6291 /* If we got the LHS in a different type for storing in,
6292 convert the result back to the nominal type of LHS
6293 so that the value we return always has the same type
6294 as the LHS argument. */
6296 if (olhstype
== TREE_TYPE (result
))
6298 /* Avoid warnings converting integral types back into enums
6299 for enum bit fields. */
6300 if (TREE_CODE (TREE_TYPE (result
)) == INTEGER_TYPE
6301 && TREE_CODE (olhstype
) == ENUMERAL_TYPE
)
6303 result
= build (COMPOUND_EXPR
, olhstype
, result
, olhs
);
6304 TREE_NO_UNUSED_WARNING (result
) = 1;
6307 return convert_for_assignment (olhstype
, result
, "assignment",
6312 build_x_modify_expr (lhs
, modifycode
, rhs
)
6314 enum tree_code modifycode
;
6317 if (processing_template_decl
)
6318 return build_min_nt (MODOP_EXPR
, lhs
,
6319 build_min_nt (modifycode
, NULL_TREE
, NULL_TREE
), rhs
);
6321 if (modifycode
!= NOP_EXPR
)
6323 tree rval
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
, lhs
, rhs
,
6324 make_node (modifycode
));
6328 return build_modify_expr (lhs
, modifycode
, rhs
);
6331 /* Return 0 if EXP is not a valid lvalue in this language
6332 even though `lvalue_or_else' would accept it. */
6335 language_lvalue_valid (exp
)
6336 tree exp ATTRIBUTE_UNUSED
;
6341 /* Get difference in deltas for different pointer to member function
6342 types. Return integer_zero_node, if FROM cannot be converted to a
6343 TO type. If FORCE is true, then allow reverse conversions as well. */
6346 get_delta_difference (from
, to
, force
)
6350 tree delta
= integer_zero_node
;
6356 /* Should get_base_distance here, so we can check if any thing along the
6357 path is virtual, and we need to make sure we stay
6358 inside the real binfos when going through virtual bases.
6359 Maybe we should replace virtual bases with
6360 binfo_member (...CLASSTYPE_VBASECLASSES...)... (mrs) */
6361 binfo
= get_binfo (from
, to
, 1);
6362 if (binfo
== error_mark_node
)
6364 error (" in pointer to member function conversion");
6371 error_not_base_type (from
, to
);
6372 error (" in pointer to member conversion");
6375 binfo
= get_binfo (to
, from
, 1);
6376 if (binfo
== 0 || binfo
== error_mark_node
)
6378 if (TREE_VIA_VIRTUAL (binfo
))
6380 binfo
= binfo_member (BINFO_TYPE (binfo
),
6381 CLASSTYPE_VBASECLASSES (from
));
6382 cp_warning ("pointer to member cast to virtual base `%T'",
6383 BINFO_TYPE (binfo
));
6384 warning (" will only work if you are very careful");
6386 delta
= BINFO_OFFSET (binfo
);
6387 delta
= cp_convert (ptrdiff_type_node
, delta
);
6389 return build_binary_op (MINUS_EXPR
,
6394 if (TREE_VIA_VIRTUAL (binfo
))
6398 cp_warning ("pointer to member cast from virtual base `%T'",
6399 BINFO_TYPE (binfo
));
6400 warning (" will only work if you are very careful");
6403 cp_error ("pointer to member conversion from virtual base `%T'",
6404 BINFO_TYPE (binfo
));
6407 return BINFO_OFFSET (binfo
);
6411 build_ptrmemfunc1 (type
, delta
, idx
, pfn
, delta2
)
6412 tree type
, delta
, idx
, pfn
, delta2
;
6417 /* This is the old way we did it. We want to avoid calling
6418 digest_init, so that it can give an error if we use { } when
6419 initializing a pointer to member function. */
6423 u
= build_nt (CONSTRUCTOR
, NULL_TREE
,
6424 expr_tree_cons (pfn_identifier
, pfn
, NULL_TREE
));
6428 u
= build_nt (CONSTRUCTOR
, NULL_TREE
,
6429 expr_tree_cons (delta2_identifier
, delta2
, NULL_TREE
));
6432 u
= build_nt (CONSTRUCTOR
, NULL_TREE
,
6433 expr_tree_cons (NULL_TREE
, delta
,
6434 expr_tree_cons (NULL_TREE
, idx
,
6435 expr_tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6437 return digest_init (type
, u
, (tree
*)0);
6439 tree delta_field
, idx_field
, pfn_or_delta2_field
, pfn_field
, delta2_field
;
6441 int allconstant
, allsimple
;
6443 delta_field
= TYPE_FIELDS (type
);
6444 idx_field
= TREE_CHAIN (delta_field
);
6445 pfn_or_delta2_field
= TREE_CHAIN (idx_field
);
6446 subtype
= TREE_TYPE (pfn_or_delta2_field
);
6447 pfn_field
= TYPE_FIELDS (subtype
);
6448 delta2_field
= TREE_CHAIN (pfn_field
);
6452 allconstant
= TREE_CONSTANT (pfn
);
6453 allsimple
= !! initializer_constant_valid_p (pfn
, TREE_TYPE (pfn
));
6454 u
= expr_tree_cons (pfn_field
, pfn
, NULL_TREE
);
6458 delta2
= convert_and_check (delta_type_node
, delta2
);
6459 allconstant
= TREE_CONSTANT (delta2
);
6460 allsimple
= !! initializer_constant_valid_p (delta2
, TREE_TYPE (delta2
));
6461 u
= expr_tree_cons (delta2_field
, delta2
, NULL_TREE
);
6464 delta
= convert_and_check (delta_type_node
, delta
);
6465 idx
= convert_and_check (delta_type_node
, idx
);
6467 allconstant
= allconstant
&& TREE_CONSTANT (delta
) && TREE_CONSTANT (idx
);
6468 allsimple
= allsimple
6469 && initializer_constant_valid_p (delta
, TREE_TYPE (delta
))
6470 && initializer_constant_valid_p (idx
, TREE_TYPE (idx
));
6472 u
= build (CONSTRUCTOR
, subtype
, NULL_TREE
, u
);
6473 u
= expr_tree_cons (delta_field
, delta
,
6474 expr_tree_cons (idx_field
, idx
,
6475 expr_tree_cons (pfn_or_delta2_field
, u
, NULL_TREE
)));
6476 u
= build (CONSTRUCTOR
, type
, NULL_TREE
, u
);
6477 TREE_CONSTANT (u
) = allconstant
;
6478 TREE_STATIC (u
) = allconstant
&& allsimple
;
6483 /* Build a constructor for a pointer to member function. It can be
6484 used to initialize global variables, local variable, or used
6485 as a value in expressions. TYPE is the POINTER to METHOD_TYPE we
6488 If FORCE is non-zero, then force this conversion, even if
6489 we would rather not do it. Usually set when using an explicit
6492 Return error_mark_node, if something goes wrong. */
6495 build_ptrmemfunc (type
, pfn
, force
)
6499 tree idx
= integer_zero_node
;
6500 tree delta
= integer_zero_node
;
6501 tree delta2
= integer_zero_node
;
6503 tree npfn
= NULL_TREE
;
6505 /* Handle multiple conversions of pointer to member functions. */
6506 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (pfn
)))
6508 tree ndelta
, ndelta2
;
6512 /* Is is already the right type? */
6513 if (type
== TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))
6516 pfn_type
= TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
));
6518 && comp_target_types (type
, pfn_type
, 0) != 1)
6519 cp_error ("conversion to `%T' from `%T'", type
, pfn_type
);
6521 ndelta
= cp_convert (ptrdiff_type_node
, build_component_ref (pfn
, delta_identifier
, NULL_TREE
, 0));
6522 ndelta2
= cp_convert (ptrdiff_type_node
, DELTA2_FROM_PTRMEMFUNC (pfn
));
6523 idx
= build_component_ref (pfn
, index_identifier
, NULL_TREE
, 0);
6525 n
= get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (pfn_type
)),
6526 TYPE_METHOD_BASETYPE (TREE_TYPE (type
)),
6529 delta
= build_binary_op (PLUS_EXPR
, ndelta
, n
, 1);
6530 delta2
= build_binary_op (PLUS_EXPR
, ndelta2
, n
, 1);
6531 e1
= fold (build (GT_EXPR
, boolean_type_node
, idx
, integer_zero_node
));
6533 e2
= build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type
), delta
, idx
,
6536 pfn
= PFN_FROM_PTRMEMFUNC (pfn
);
6537 npfn
= build1 (NOP_EXPR
, type
, pfn
);
6538 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6540 e3
= build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type
), delta
, idx
, npfn
,
6542 return build_conditional_expr (e1
, e2
, e3
);
6545 /* Handle null pointer to member function conversions. */
6546 if (integer_zerop (pfn
))
6548 pfn
= build_c_cast (type
, integer_zero_node
);
6549 return build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type
),
6550 integer_zero_node
, integer_zero_node
,
6554 if (TREE_CODE (pfn
) == TREE_LIST
6555 || (TREE_CODE (pfn
) == ADDR_EXPR
6556 && TREE_CODE (TREE_OPERAND (pfn
, 0)) == TREE_LIST
))
6557 return instantiate_type (type
, pfn
, 1);
6560 && comp_target_types (type
, TREE_TYPE (pfn
), 0) != 1)
6561 cp_error ("conversion to `%T' from `%T'", type
, TREE_TYPE (pfn
));
6563 /* Allow pointer to member conversions here. */
6564 delta
= get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TREE_TYPE (pfn
))),
6565 TYPE_METHOD_BASETYPE (TREE_TYPE (type
)),
6567 delta2
= build_binary_op (PLUS_EXPR
, delta2
, delta
, 1);
6569 if (TREE_CODE (TREE_OPERAND (pfn
, 0)) != FUNCTION_DECL
)
6570 warning ("assuming pointer to member function is non-virtual");
6572 if (TREE_CODE (TREE_OPERAND (pfn
, 0)) == FUNCTION_DECL
6573 && DECL_VINDEX (TREE_OPERAND (pfn
, 0)))
6575 /* Find the offset to the vfield pointer in the object. */
6576 vfield_offset
= get_binfo (DECL_CONTEXT (TREE_OPERAND (pfn
, 0)),
6577 DECL_CLASS_CONTEXT (TREE_OPERAND (pfn
, 0)),
6579 vfield_offset
= get_vfield_offset (vfield_offset
);
6580 delta2
= size_binop (PLUS_EXPR
, vfield_offset
, delta2
);
6582 /* Map everything down one to make room for the null pointer to member. */
6583 idx
= size_binop (PLUS_EXPR
,
6584 DECL_VINDEX (TREE_OPERAND (pfn
, 0)),
6589 idx
= size_binop (MINUS_EXPR
, integer_zero_node
, integer_one_node
);
6591 if (type
== TREE_TYPE (pfn
))
6597 npfn
= build1 (NOP_EXPR
, type
, pfn
);
6598 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6602 return build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type
), delta
, idx
, npfn
, delta2
);
6605 /* Convert value RHS to type TYPE as preparation for an assignment
6606 to an lvalue of type TYPE.
6607 The real work of conversion is done by `convert'.
6608 The purpose of this function is to generate error messages
6609 for assignments that are not allowed in C.
6610 ERRTYPE is a string to use in error messages:
6611 "assignment", "return", etc.
6613 C++: attempts to allow `convert' to find conversions involving
6614 implicit type conversion between aggregate and scalar types
6615 as per 8.5.6 of C++ manual. Does not randomly dereference
6616 pointers to aggregates! */
6619 convert_for_assignment (type
, rhs
, errtype
, fndecl
, parmnum
)
6625 register enum tree_code codel
= TREE_CODE (type
);
6626 register tree rhstype
;
6627 register enum tree_code coder
= TREE_CODE (TREE_TYPE (rhs
));
6629 /* Issue warnings about peculiar, but legal, uses of NULL. */
6630 if (ARITHMETIC_TYPE_P (type
) && rhs
== null_node
)
6631 cp_warning ("converting NULL to non-pointer type");
6633 if (coder
== UNKNOWN_TYPE
)
6634 rhs
= instantiate_type (type
, rhs
, 1);
6636 if (coder
== ERROR_MARK
)
6637 return error_mark_node
;
6639 if (codel
== OFFSET_TYPE
)
6641 type
= TREE_TYPE (type
);
6642 codel
= TREE_CODE (type
);
6645 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
6646 if (TREE_CODE (rhs
) == NON_LVALUE_EXPR
)
6647 rhs
= TREE_OPERAND (rhs
, 0);
6649 if (rhs
== error_mark_node
)
6650 return error_mark_node
;
6652 if (TREE_CODE (rhs
) == TREE_LIST
&& TREE_VALUE (rhs
) == error_mark_node
)
6653 return error_mark_node
;
6655 if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
6657 rhs
= resolve_offset_ref (rhs
);
6658 if (rhs
== error_mark_node
)
6659 return error_mark_node
;
6660 rhstype
= TREE_TYPE (rhs
);
6661 coder
= TREE_CODE (rhstype
);
6664 if (TREE_CODE (TREE_TYPE (rhs
)) == ARRAY_TYPE
6665 || TREE_CODE (TREE_TYPE (rhs
)) == FUNCTION_TYPE
6666 || TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
6667 rhs
= default_conversion (rhs
);
6668 else if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
6669 rhs
= convert_from_reference (rhs
);
6671 rhstype
= TREE_TYPE (rhs
);
6672 coder
= TREE_CODE (rhstype
);
6674 /* This should no longer change types on us. */
6675 if (TREE_CODE (rhs
) == CONST_DECL
)
6676 rhs
= DECL_INITIAL (rhs
);
6677 else if (TREE_READONLY_DECL_P (rhs
))
6678 rhs
= decl_constant_value (rhs
);
6680 if (comptypes (type
, rhstype
, 1))
6682 overflow_warning (rhs
);
6686 if (coder
== VOID_TYPE
)
6688 error ("void value not ignored as it ought to be");
6689 return error_mark_node
;
6691 /* Arithmetic types all interconvert. */
6692 if ((codel
== INTEGER_TYPE
|| codel
== REAL_TYPE
|| codel
== BOOLEAN_TYPE
6693 || codel
== COMPLEX_TYPE
)
6694 && (coder
== INTEGER_TYPE
|| coder
== REAL_TYPE
|| coder
== BOOLEAN_TYPE
6695 || coder
== COMPLEX_TYPE
))
6697 /* But we should warn if assigning REAL_TYPE to INTEGER_TYPE. */
6698 if (coder
== REAL_TYPE
&& codel
== INTEGER_TYPE
)
6701 cp_warning ("`%T' used for argument %P of `%D'",
6702 rhstype
, parmnum
, fndecl
);
6704 cp_warning ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6706 /* And we should warn if assigning a negative value to
6707 an unsigned variable. */
6708 else if (TREE_UNSIGNED (type
) && codel
!= BOOLEAN_TYPE
)
6710 if (TREE_CODE (rhs
) == INTEGER_CST
6711 && TREE_NEGATED_INT (rhs
))
6714 cp_warning ("negative value `%E' passed as argument %P of `%D'",
6715 rhs
, parmnum
, fndecl
);
6717 cp_warning ("%s of negative value `%E' to `%T'",
6718 errtype
, rhs
, type
);
6720 overflow_warning (rhs
);
6721 if (TREE_CONSTANT (rhs
))
6725 return convert_and_check (type
, rhs
);
6727 /* Conversions involving enums. */
6728 else if ((codel
== ENUMERAL_TYPE
6729 && (INTEGRAL_CODE_P (coder
) || coder
== REAL_TYPE
))
6730 || (coder
== ENUMERAL_TYPE
6731 && (INTEGRAL_CODE_P (codel
) || codel
== REAL_TYPE
)))
6733 return ocp_convert (type
, rhs
, CONV_IMPLICIT
, LOOKUP_NORMAL
);
6735 /* Conversions among pointers */
6736 else if (codel
== POINTER_TYPE
6737 && (coder
== POINTER_TYPE
6738 || (coder
== RECORD_TYPE
6739 && (IS_SIGNATURE_POINTER (rhstype
)
6740 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6742 register tree ttl
= TREE_TYPE (type
);
6746 if (coder
== RECORD_TYPE
)
6748 rhs
= build_optr_ref (rhs
);
6749 rhstype
= TREE_TYPE (rhs
);
6751 ttr
= TREE_TYPE (rhstype
);
6753 /* If both pointers are of aggregate type, then we
6754 can give better error messages, and save some work
6756 if (TREE_CODE (ttl
) == RECORD_TYPE
&& TREE_CODE (ttr
) == RECORD_TYPE
)
6760 if (TYPE_MAIN_VARIANT (ttl
) == TYPE_MAIN_VARIANT (ttr
)
6761 || type
== class_star_type_node
6762 || rhstype
== class_star_type_node
)
6763 binfo
= TYPE_BINFO (ttl
);
6765 binfo
= get_binfo (ttl
, ttr
, 1);
6767 if (binfo
== error_mark_node
)
6768 return error_mark_node
;
6770 return error_not_base_type (ttl
, ttr
);
6772 if (! TYPE_READONLY (ttl
) && TYPE_READONLY (ttr
))
6775 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6776 rhstype
, parmnum
, fndecl
);
6778 cp_pedwarn ("%s to `%T' from `%T' discards const",
6779 errtype
, type
, rhstype
);
6781 if (! TYPE_VOLATILE (ttl
) && TYPE_VOLATILE (ttr
))
6784 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6785 rhstype
, parmnum
, fndecl
);
6787 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6788 errtype
, type
, rhstype
);
6792 /* Any non-function converts to a [const][volatile] void *
6793 and vice versa; otherwise, targets must be the same.
6794 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
6795 else if (TYPE_MAIN_VARIANT (ttl
) == void_type_node
6796 || TYPE_MAIN_VARIANT (ttr
) == void_type_node
6797 || (ctt
= comp_target_types (type
, rhstype
, 1))
6798 || (unsigned_type (TYPE_MAIN_VARIANT (ttl
))
6799 == unsigned_type (TYPE_MAIN_VARIANT (ttr
))))
6801 /* ARM $4.8, commentary on p39. */
6802 if (TYPE_MAIN_VARIANT (ttl
) == void_type_node
6803 && TREE_CODE (ttr
) == OFFSET_TYPE
)
6805 cp_error ("no standard conversion from `%T' to `void *'", ttr
);
6806 return error_mark_node
;
6809 if (ctt
< 0 && TYPE_MAIN_VARIANT (ttl
) != TYPE_MAIN_VARIANT (ttr
))
6810 cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
6813 if (TYPE_MAIN_VARIANT (ttl
) != void_type_node
6814 && TYPE_MAIN_VARIANT (ttr
) == void_type_node
6815 && ! null_ptr_cst_p (rhs
))
6817 if (coder
== RECORD_TYPE
)
6818 cp_pedwarn ("implicit conversion of signature pointer to type `%T'",
6821 pedwarn ("ANSI C++ forbids implicit conversion from `void *' in %s",
6824 /* Const and volatile mean something different for function types,
6825 so the usual warnings are not appropriate. */
6826 else if ((TREE_CODE (ttr
) != FUNCTION_TYPE
&& TREE_CODE (ttr
) != METHOD_TYPE
)
6827 || (TREE_CODE (ttl
) != FUNCTION_TYPE
&& TREE_CODE (ttl
) != METHOD_TYPE
))
6829 if (TREE_CODE (ttl
) == OFFSET_TYPE
6830 && binfo_member (TYPE_OFFSET_BASETYPE (ttr
),
6831 CLASSTYPE_VBASECLASSES (TYPE_OFFSET_BASETYPE (ttl
))))
6833 sorry ("%s between pointer to members converting across virtual baseclasses", errtype
);
6834 return error_mark_node
;
6836 else if (! TYPE_READONLY (ttl
) && TYPE_READONLY (ttr
))
6838 if (string_conv_p (type
, rhs
, 1))
6839 /* converting from string constant to char *, OK. */;
6841 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6842 rhstype
, parmnum
, fndecl
);
6844 cp_pedwarn ("%s to `%T' from `%T' discards const",
6845 errtype
, type
, rhstype
);
6847 else if (! TYPE_VOLATILE (ttl
) && TYPE_VOLATILE (ttr
))
6850 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6851 rhstype
, parmnum
, fndecl
);
6853 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6854 errtype
, type
, rhstype
);
6856 else if (TREE_CODE (ttl
) == TREE_CODE (ttr
)
6857 && ! comp_target_types (type
, rhstype
, 1))
6860 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signedness",
6861 rhstype
, parmnum
, fndecl
);
6863 cp_pedwarn ("%s to `%T' from `%T' changes signedness",
6864 errtype
, type
, rhstype
);
6870 int add_quals
= 0, const_parity
= 0, volatile_parity
= 0;
6872 int unsigned_parity
;
6875 /* This code is basically a duplicate of comp_ptr_ttypes_real. */
6876 for (; ; ttl
= TREE_TYPE (ttl
), ttr
= TREE_TYPE (ttr
))
6879 const_parity
|= (TYPE_READONLY (ttl
) < TYPE_READONLY (ttr
));
6880 volatile_parity
|= (TYPE_VOLATILE (ttl
) < TYPE_VOLATILE (ttr
));
6883 && (TYPE_READONLY (ttl
) > TYPE_READONLY (ttr
)
6884 || TYPE_VOLATILE (ttl
) > TYPE_VOLATILE (ttr
)))
6886 left_const
&= TYPE_READONLY (ttl
);
6888 if (TREE_CODE (ttl
) != POINTER_TYPE
6889 || TREE_CODE (ttr
) != POINTER_TYPE
)
6892 unsigned_parity
= TREE_UNSIGNED (ttl
) - TREE_UNSIGNED (ttr
);
6893 if (unsigned_parity
)
6895 if (TREE_UNSIGNED (ttl
))
6896 ttr
= unsigned_type (ttr
);
6898 ttl
= unsigned_type (ttl
);
6901 if (comp_target_types (ttl
, ttr
, nptrs
) > 0)
6906 cp_pedwarn ("passing `%T' as argument %P of `%D' adds cv-quals without intervening `const'",
6907 rhstype
, parmnum
, fndecl
);
6909 cp_pedwarn ("%s to `%T' from `%T' adds cv-quals without intervening `const'",
6910 errtype
, type
, rhstype
);
6915 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6916 rhstype
, parmnum
, fndecl
);
6918 cp_pedwarn ("%s to `%T' from `%T' discards const",
6919 errtype
, type
, rhstype
);
6921 if (volatile_parity
)
6924 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6925 rhstype
, parmnum
, fndecl
);
6927 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6928 errtype
, type
, rhstype
);
6930 if (unsigned_parity
> 0)
6933 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signed to unsigned",
6934 rhstype
, parmnum
, fndecl
);
6936 cp_pedwarn ("%s to `%T' from `%T' changes signed to unsigned",
6937 errtype
, type
, rhstype
);
6939 else if (unsigned_parity
< 0)
6942 cp_pedwarn ("passing `%T' as argument %P of `%D' changes unsigned to signed",
6943 rhstype
, parmnum
, fndecl
);
6945 cp_pedwarn ("%s to `%T' from `%T' changes unsigned to signed",
6946 errtype
, type
, rhstype
);
6949 /* C++ is not so friendly about converting function and
6950 member function pointers as C. Emit warnings here. */
6951 if (TREE_CODE (ttl
) == FUNCTION_TYPE
6952 || TREE_CODE (ttl
) == METHOD_TYPE
)
6953 if (! comptypes (ttl
, ttr
, 0))
6955 warning ("conflicting function types in %s:", errtype
);
6956 cp_warning ("\t`%T' != `%T'", type
, rhstype
);
6962 cp_error ("passing `%T' as argument %P of `%D'",
6963 rhstype
, parmnum
, fndecl
);
6965 cp_error ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6966 return error_mark_node
;
6969 return cp_convert (type
, rhs
);
6971 else if (codel
== POINTER_TYPE
&& coder
== INTEGER_TYPE
)
6973 /* An explicit constant 0 can convert to a pointer,
6974 but not a 0 that results from casting or folding. */
6975 if (! (TREE_CODE (rhs
) == INTEGER_CST
&& integer_zerop (rhs
)))
6978 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6979 rhstype
, parmnum
, fndecl
);
6981 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
6982 errtype
, type
, rhstype
);
6984 return cp_convert (type
, rhs
);
6986 else if (codel
== INTEGER_TYPE
6987 && (coder
== POINTER_TYPE
6988 || (coder
== RECORD_TYPE
6989 && (IS_SIGNATURE_POINTER (rhstype
)
6990 || TYPE_PTRMEMFUNC_FLAG (rhstype
)
6991 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6994 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6995 rhstype
, parmnum
, fndecl
);
6997 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
6998 errtype
, type
, rhstype
);
6999 return cp_convert (type
, rhs
);
7001 else if (codel
== BOOLEAN_TYPE
7002 && (coder
== POINTER_TYPE
7003 || (coder
== RECORD_TYPE
7004 && (IS_SIGNATURE_POINTER (rhstype
)
7005 || TYPE_PTRMEMFUNC_FLAG (rhstype
)
7006 || IS_SIGNATURE_REFERENCE (rhstype
)))))
7007 return cp_convert (type
, rhs
);
7010 else if (((coder
== POINTER_TYPE
7011 && TREE_CODE (TREE_TYPE (rhstype
)) == METHOD_TYPE
)
7012 || integer_zerop (rhs
)
7013 || TYPE_PTRMEMFUNC_P (rhstype
))
7014 && TYPE_PTRMEMFUNC_P (type
))
7016 tree ttl
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
7017 tree ttr
= (TYPE_PTRMEMFUNC_P (rhstype
)
7018 ? TYPE_PTRMEMFUNC_FN_TYPE (rhstype
)
7020 int ctt
= (TREE_CODE (rhstype
) == INTEGER_TYPE
? 1
7021 : comp_target_types (ttl
, ttr
, 1));
7024 cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
7027 cp_error ("%s to `%T' from `%T'", errtype
, ttl
, ttr
);
7029 /* compatible pointer to member functions. */
7030 return build_ptrmemfunc (ttl
, rhs
, 0);
7032 else if (codel
== ERROR_MARK
|| coder
== ERROR_MARK
)
7033 return error_mark_node
;
7035 /* This should no longer happen. References are initialized via
7036 `convert_for_initialization'. They should otherwise be
7037 bashed before coming here. */
7038 else if (codel
== REFERENCE_TYPE
)
7039 my_friendly_abort (317);
7040 else if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (TREE_TYPE (rhs
)))
7042 tree nrhs
= build1 (NOP_EXPR
, type
, rhs
);
7043 TREE_CONSTANT (nrhs
) = TREE_CONSTANT (rhs
);
7046 else if (TYPE_HAS_CONSTRUCTOR (type
) || IS_AGGR_TYPE (TREE_TYPE (rhs
)))
7047 return cp_convert (type
, rhs
);
7048 /* Handle anachronistic conversions from (::*)() to cv void* or (*)(). */
7049 else if (TREE_CODE (type
) == POINTER_TYPE
7050 && (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
7051 || TYPE_MAIN_VARIANT (TREE_TYPE (type
)) == void_type_node
)
7053 && TYPE_PTRMEMFUNC_P (TREE_TYPE (rhs
)))
7054 return cp_convert (type
, rhs
);
7056 cp_error ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
7057 return error_mark_node
;
7060 /* Convert RHS to be of type TYPE. If EXP is non-zero,
7061 it is the target of the initialization.
7062 ERRTYPE is a string to use in error messages.
7064 Two major differences between the behavior of
7065 `convert_for_assignment' and `convert_for_initialization'
7066 are that references are bashed in the former, while
7067 copied in the latter, and aggregates are assigned in
7068 the former (operator=) while initialized in the
7071 If using constructor make sure no conversion operator exists, if one does
7072 exist, an ambiguity exists.
7074 If flags doesn't include LOOKUP_COMPLAIN, don't complain about anything. */
7077 convert_for_initialization (exp
, type
, rhs
, flags
, errtype
, fndecl
, parmnum
)
7078 tree exp
, type
, rhs
;
7084 register enum tree_code codel
= TREE_CODE (type
);
7085 register tree rhstype
;
7086 register enum tree_code coder
;
7088 /* Issue warnings about peculiar, but legal, uses of NULL. */
7089 if (ARITHMETIC_TYPE_P (type
) && rhs
== null_node
)
7090 cp_warning ("converting NULL to non-pointer type");
7092 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
7093 Strip such NOP_EXPRs, since RHS is used in non-lvalue context. */
7094 if (TREE_CODE (rhs
) == NOP_EXPR
7095 && TREE_TYPE (rhs
) == TREE_TYPE (TREE_OPERAND (rhs
, 0))
7096 && codel
!= REFERENCE_TYPE
)
7097 rhs
= TREE_OPERAND (rhs
, 0);
7099 if (rhs
== error_mark_node
7100 || (TREE_CODE (rhs
) == TREE_LIST
&& TREE_VALUE (rhs
) == error_mark_node
))
7101 return error_mark_node
;
7103 if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
7105 rhs
= resolve_offset_ref (rhs
);
7106 if (rhs
== error_mark_node
)
7107 return error_mark_node
;
7110 if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
7111 rhs
= convert_from_reference (rhs
);
7113 if ((TREE_CODE (TREE_TYPE (rhs
)) == ARRAY_TYPE
7114 && TREE_CODE (type
) != ARRAY_TYPE
7115 && (TREE_CODE (type
) != REFERENCE_TYPE
7116 || TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
))
7117 || TREE_CODE (TREE_TYPE (rhs
)) == FUNCTION_TYPE
7118 || TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
7119 rhs
= default_conversion (rhs
);
7121 rhstype
= TREE_TYPE (rhs
);
7122 coder
= TREE_CODE (rhstype
);
7124 if (coder
== UNKNOWN_TYPE
)
7126 rhs
= instantiate_type (type
, rhs
, 1);
7127 rhstype
= TREE_TYPE (rhs
);
7128 coder
= TREE_CODE (rhstype
);
7131 if (coder
== ERROR_MARK
)
7132 return error_mark_node
;
7134 /* We accept references to incomplete types, so we can
7135 return here before checking if RHS is of complete type. */
7137 if (codel
== REFERENCE_TYPE
)
7139 /* This should eventually happen in convert_arguments. */
7140 extern int warningcount
, errorcount
;
7141 int savew
= 0, savee
= 0;
7144 savew
= warningcount
, savee
= errorcount
;
7145 rhs
= convert_to_reference (type
, rhs
, CONV_IMPLICIT
, flags
,
7146 exp
? exp
: error_mark_node
);
7149 if (warningcount
> savew
)
7150 cp_warning_at ("in passing argument %P of `%+D'", parmnum
, fndecl
);
7151 else if (errorcount
> savee
)
7152 cp_error_at ("in passing argument %P of `%+D'", parmnum
, fndecl
);
7157 rhs
= require_complete_type (rhs
);
7158 if (rhs
== error_mark_node
)
7159 return error_mark_node
;
7161 if (exp
!= 0) exp
= require_complete_type (exp
);
7162 if (exp
== error_mark_node
)
7163 return error_mark_node
;
7165 if (TREE_CODE (rhstype
) == REFERENCE_TYPE
)
7166 rhstype
= TREE_TYPE (rhstype
);
7168 type
= complete_type (type
);
7170 if (TYPE_LANG_SPECIFIC (type
)
7171 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
)))
7172 return build_signature_pointer_constructor (type
, rhs
);
7174 if (IS_AGGR_TYPE (type
))
7175 return ocp_convert (type
, rhs
, CONV_IMPLICIT
|CONV_FORCE_TEMP
, flags
);
7177 if (type
== TREE_TYPE (rhs
))
7179 if (TREE_READONLY_DECL_P (rhs
))
7180 rhs
= decl_constant_value (rhs
);
7184 return convert_for_assignment (type
, rhs
, errtype
, fndecl
, parmnum
);
7187 /* Expand an ASM statement with operands, handling output operands
7188 that are not variables or INDIRECT_REFS by transforming such
7189 cases into cases that expand_asm_operands can handle.
7191 Arguments are same as for expand_asm_operands.
7193 We don't do default conversions on all inputs, because it can screw
7194 up operands that are expected to be in memory. */
7197 c_expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, filename
, line
)
7198 tree string
, outputs
, inputs
, clobbers
;
7203 int noutputs
= list_length (outputs
);
7205 /* o[I] is the place that output number I should be written. */
7206 register tree
*o
= (tree
*) alloca (noutputs
* sizeof (tree
));
7209 /* Record the contents of OUTPUTS before it is modified. */
7210 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
7211 o
[i
] = TREE_VALUE (tail
);
7213 /* Generate the ASM_OPERANDS insn;
7214 store into the TREE_VALUEs of OUTPUTS some trees for
7215 where the values were actually stored. */
7216 expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, filename
, line
);
7218 /* Copy all the intermediate outputs into the specified outputs. */
7219 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
7221 if (o
[i
] != TREE_VALUE (tail
))
7223 expand_expr (build_modify_expr (o
[i
], NOP_EXPR
, TREE_VALUE (tail
)),
7224 const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
7227 /* Detect modification of read-only values.
7228 (Otherwise done by build_modify_expr.) */
7231 tree type
= TREE_TYPE (o
[i
]);
7232 if (TYPE_READONLY (type
)
7233 || ((TREE_CODE (type
) == RECORD_TYPE
7234 || TREE_CODE (type
) == UNION_TYPE
)
7235 && C_TYPE_FIELDS_READONLY (type
)))
7236 readonly_error (o
[i
], "modification by `asm'", 1);
7240 /* Those MODIFY_EXPRs could do autoincrements. */
7244 /* Expand a C `return' statement.
7245 RETVAL is the expression for what to return,
7246 or a null pointer for `return;' with no value.
7248 C++: upon seeing a `return', we must call destructors on all
7249 variables in scope which had constructors called on them.
7250 This means that if in a destructor, the base class destructors
7251 must be called before returning.
7253 The RETURN statement in C++ has initialization semantics. */
7256 c_expand_return (retval
)
7259 extern struct nesting
*cond_stack
, *loop_stack
, *case_stack
;
7260 extern tree dtor_label
, ctor_label
;
7261 tree result
= DECL_RESULT (current_function_decl
);
7262 tree valtype
= TREE_TYPE (result
);
7264 if (TREE_THIS_VOLATILE (current_function_decl
))
7265 warning ("function declared `noreturn' has a `return' statement");
7267 if (retval
== error_mark_node
)
7269 current_function_returns_null
= 1;
7273 if (processing_template_decl
)
7275 add_tree (build_min_nt (RETURN_STMT
, retval
));
7282 error ("returning a value from a destructor");
7284 /* Can't just return from a destructor. */
7285 expand_goto (dtor_label
);
7289 if (retval
== NULL_TREE
)
7291 /* A non-named return value does not count. */
7293 if (DECL_CONSTRUCTOR_P (current_function_decl
))
7294 retval
= current_class_ptr
;
7295 else if (DECL_NAME (result
) != NULL_TREE
7296 && TREE_CODE (valtype
) != VOID_TYPE
)
7300 current_function_returns_null
= 1;
7302 if (valtype
!= NULL_TREE
&& TREE_CODE (valtype
) != VOID_TYPE
)
7304 if (DECL_NAME (DECL_RESULT (current_function_decl
)) == NULL_TREE
)
7306 pedwarn ("`return' with no value, in function returning non-void");
7307 /* Clear this, so finish_function won't say that we
7308 reach the end of a non-void function (which we don't,
7309 we gave a return!). */
7310 current_function_returns_null
= 0;
7314 expand_null_return ();
7318 else if (DECL_CONSTRUCTOR_P (current_function_decl
))
7320 if (flag_this_is_variable
)
7321 error ("return from a constructor: use `this = ...' instead");
7323 error ("returning a value from a constructor");
7324 retval
= current_class_ptr
;
7327 /* Effective C++ rule 15. See also start_function. */
7329 && DECL_NAME (current_function_decl
) == ansi_opname
[(int) MODIFY_EXPR
]
7330 && retval
!= current_class_ref
)
7331 cp_warning ("`operator=' should return a reference to `*this'");
7333 if (valtype
== NULL_TREE
|| TREE_CODE (valtype
) == VOID_TYPE
)
7335 current_function_returns_null
= 1;
7336 if (TREE_CODE (TREE_TYPE (retval
)) != VOID_TYPE
)
7337 pedwarn ("`return' with a value, in function returning void");
7338 expand_return (retval
);
7342 /* Now deal with possible C++ hair:
7343 (1) Compute the return value.
7344 (2) If there are aggregate values with destructors which
7345 must be cleaned up, clean them (taking care
7346 not to clobber the return value).
7347 (3) If an X(X&) constructor is defined, the return
7348 value must be returned via that. */
7350 if (retval
== result
7351 || DECL_CONSTRUCTOR_P (current_function_decl
))
7352 /* It's already done for us. */;
7353 else if (TREE_TYPE (retval
) == void_type_node
)
7355 pedwarn ("return of void value in function returning non-void");
7356 expand_expr_stmt (retval
);
7361 retval
= convert_for_initialization
7362 (NULL_TREE
, valtype
, retval
, LOOKUP_NORMAL
|LOOKUP_ONLYCONVERTING
,
7363 "return", NULL_TREE
, 0);
7365 if (retval
== error_mark_node
)
7367 /* Avoid warning about control reaching end of function. */
7368 expand_null_return ();
7372 /* We can't initialize a register from a AGGR_INIT_EXPR. */
7373 else if (! current_function_returns_struct
7374 && TREE_CODE (retval
) == TARGET_EXPR
7375 && TREE_CODE (TREE_OPERAND (retval
, 1)) == AGGR_INIT_EXPR
)
7376 retval
= build (COMPOUND_EXPR
, TREE_TYPE (retval
), retval
,
7377 TREE_OPERAND (retval
, 0));
7379 /* Add some useful error checking for C++. */
7380 else if (TREE_CODE (valtype
) == REFERENCE_TYPE
)
7382 tree whats_returned
;
7384 /* Sort through common things to see what it is
7385 we are returning. */
7386 whats_returned
= retval
;
7387 if (TREE_CODE (whats_returned
) == COMPOUND_EXPR
)
7389 whats_returned
= TREE_OPERAND (whats_returned
, 1);
7390 if (TREE_CODE (whats_returned
) == ADDR_EXPR
)
7391 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7393 while (TREE_CODE (whats_returned
) == CONVERT_EXPR
7394 || TREE_CODE (whats_returned
) == NOP_EXPR
)
7395 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7396 if (TREE_CODE (whats_returned
) == ADDR_EXPR
)
7398 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7399 while (TREE_CODE (whats_returned
) == AGGR_INIT_EXPR
7400 || TREE_CODE (whats_returned
) == TARGET_EXPR
)
7402 /* Get the target. */
7403 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7404 warning ("returning reference to temporary");
7408 if (TREE_CODE (whats_returned
) == VAR_DECL
&& DECL_NAME (whats_returned
))
7410 if (TEMP_NAME_P (DECL_NAME (whats_returned
)))
7411 warning ("reference to non-lvalue returned");
7412 else if (TREE_CODE (TREE_TYPE (whats_returned
)) != REFERENCE_TYPE
7413 && ! TREE_STATIC (whats_returned
)
7414 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned
))
7415 && !TREE_PUBLIC (whats_returned
))
7416 cp_warning_at ("reference to local variable `%D' returned", whats_returned
);
7419 else if (TREE_CODE (retval
) == ADDR_EXPR
)
7421 tree whats_returned
= TREE_OPERAND (retval
, 0);
7423 if (TREE_CODE (whats_returned
) == VAR_DECL
7424 && DECL_NAME (whats_returned
)
7425 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned
))
7426 && !TREE_STATIC (whats_returned
)
7427 && !TREE_PUBLIC (whats_returned
))
7428 cp_warning_at ("address of local variable `%D' returned", whats_returned
);
7432 if (retval
!= NULL_TREE
7433 && TREE_CODE_CLASS (TREE_CODE (retval
)) == 'd'
7434 && cond_stack
== 0 && loop_stack
== 0 && case_stack
== 0)
7435 current_function_return_value
= retval
;
7437 if (ctor_label
&& TREE_CODE (ctor_label
) != ERROR_MARK
)
7439 /* Here RETVAL is CURRENT_CLASS_PTR, so there's nothing to do. */
7440 expand_goto (ctor_label
);
7443 if (retval
&& retval
!= result
)
7445 result
= build (INIT_EXPR
, TREE_TYPE (result
), result
, retval
);
7446 TREE_SIDE_EFFECTS (result
) = 1;
7449 expand_start_target_temps ();
7451 expand_return (result
);
7453 expand_end_target_temps ();
7455 current_function_returns_value
= 1;
7458 /* Start a C switch statement, testing expression EXP.
7459 Return EXP if it is valid, an error node otherwise. */
7462 c_expand_start_case (exp
)
7466 register enum tree_code code
;
7468 /* Convert from references, etc. */
7469 exp
= default_conversion (exp
);
7470 type
= TREE_TYPE (exp
);
7471 code
= TREE_CODE (type
);
7473 if (IS_AGGR_TYPE_CODE (code
))
7474 exp
= build_type_conversion (CONVERT_EXPR
, integer_type_node
, exp
, 1);
7476 if (exp
== NULL_TREE
)
7478 error ("switch quantity not an integer");
7479 exp
= error_mark_node
;
7481 type
= TREE_TYPE (exp
);
7482 code
= TREE_CODE (type
);
7484 if (code
!= INTEGER_TYPE
&& code
!= ENUMERAL_TYPE
&& code
!= ERROR_MARK
)
7486 error ("switch quantity not an integer");
7487 exp
= error_mark_node
;
7493 exp
= default_conversion (exp
);
7494 type
= TREE_TYPE (exp
);
7495 idx
= get_unwidened (exp
, 0);
7496 /* We can't strip a conversion from a signed type to an unsigned,
7497 because if we did, int_fits_type_p would do the wrong thing
7498 when checking case values for being in range,
7499 and it's too hard to do the right thing. */
7500 if (TREE_UNSIGNED (TREE_TYPE (exp
))
7501 == TREE_UNSIGNED (TREE_TYPE (idx
)))
7506 (1, fold (build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (exp
), exp
)),
7507 type
, "switch statement");
7512 /* Returns non-zero if the pointer-type FROM can be converted to the
7513 pointer-type TO via a qualification conversion. If CONSTP is -1,
7514 then we return non-zero if the pointers are similar, and the
7515 cv-qualification signature of FROM is a proper subset of that of TO.
7517 If CONSTP is positive, then all outer pointers have been
7521 comp_ptr_ttypes_real (to
, from
, constp
)
7525 int to_more_cv_qualified
= 0;
7527 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7529 if (TREE_CODE (to
) != TREE_CODE (from
))
7532 if (TREE_CODE (from
) == OFFSET_TYPE
7533 && comptypes (TYPE_OFFSET_BASETYPE (from
),
7534 TYPE_OFFSET_BASETYPE (to
), 1))
7537 /* Const and volatile mean something different for function types,
7538 so the usual checks are not appropriate. */
7539 if (TREE_CODE (to
) != FUNCTION_TYPE
&& TREE_CODE (to
) != METHOD_TYPE
)
7541 if (TYPE_READONLY (from
) > TYPE_READONLY (to
)
7542 || TYPE_VOLATILE (from
) > TYPE_VOLATILE (to
))
7545 if (TYPE_READONLY (to
) > TYPE_READONLY (from
)
7546 || TYPE_VOLATILE (to
) > TYPE_VOLATILE (from
))
7551 ++to_more_cv_qualified
;
7555 constp
&= TYPE_READONLY (to
);
7558 if (TREE_CODE (to
) != POINTER_TYPE
)
7560 comptypes (TYPE_MAIN_VARIANT (to
), TYPE_MAIN_VARIANT (from
), 1)
7561 && (constp
>= 0 || to_more_cv_qualified
);
7565 /* When comparing, say, char ** to char const **, this function takes the
7566 'char *' and 'char const *'. Do not pass non-pointer types to this
7570 comp_ptr_ttypes (to
, from
)
7573 return comp_ptr_ttypes_real (to
, from
, 1);
7576 /* Returns 1 if to and from are (possibly multi-level) pointers to the same
7577 type or inheritance-related types, regardless of cv-quals. */
7580 ptr_reasonably_similar (to
, from
)
7583 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7585 if (TREE_CODE (to
) != TREE_CODE (from
))
7588 if (TREE_CODE (from
) == OFFSET_TYPE
7589 && comptypes (TYPE_OFFSET_BASETYPE (to
),
7590 TYPE_OFFSET_BASETYPE (from
), -1))
7593 if (TREE_CODE (to
) != POINTER_TYPE
)
7595 (TYPE_MAIN_VARIANT (to
), TYPE_MAIN_VARIANT (from
), -1);
7599 /* Like comp_ptr_ttypes, for const_cast. */
7602 comp_ptr_ttypes_const (to
, from
)
7605 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7607 if (TREE_CODE (to
) != TREE_CODE (from
))
7610 if (TREE_CODE (from
) == OFFSET_TYPE
7611 && comptypes (TYPE_OFFSET_BASETYPE (from
),
7612 TYPE_OFFSET_BASETYPE (to
), 1))
7615 if (TREE_CODE (to
) != POINTER_TYPE
)
7616 return comptypes (TYPE_MAIN_VARIANT (to
), TYPE_MAIN_VARIANT (from
), 1);
7620 /* Like comp_ptr_ttypes, for reinterpret_cast. */
7623 comp_ptr_ttypes_reinterpret (to
, from
)
7628 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7630 if (TREE_CODE (from
) == OFFSET_TYPE
)
7631 from
= TREE_TYPE (from
);
7632 if (TREE_CODE (to
) == OFFSET_TYPE
)
7633 to
= TREE_TYPE (to
);
7635 if (TREE_CODE (to
) != TREE_CODE (from
))
7638 /* Const and volatile mean something different for function types,
7639 so the usual checks are not appropriate. */
7640 if (TREE_CODE (to
) != FUNCTION_TYPE
&& TREE_CODE (to
) != METHOD_TYPE
)
7642 if (TYPE_READONLY (from
) > TYPE_READONLY (to
)
7643 || TYPE_VOLATILE (from
) > TYPE_VOLATILE (to
))
7647 && (TYPE_READONLY (to
) > TYPE_READONLY (from
)
7648 || TYPE_VOLATILE (to
) > TYPE_READONLY (from
)))
7650 constp
&= TYPE_READONLY (to
);
7653 if (TREE_CODE (to
) != POINTER_TYPE
)