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.) */
86 require_complete_type (value
)
91 if (processing_template_decl
)
94 type
= TREE_TYPE (value
);
96 /* First, detect a valid value with a complete type. */
97 if (TYPE_SIZE (type
) != 0
98 && type
!= void_type_node
99 && ! (TYPE_LANG_SPECIFIC (type
)
100 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
))
101 && TYPE_SIZE (SIGNATURE_TYPE (type
)) == 0))
104 /* If we see X::Y, we build an OFFSET_TYPE which has
105 not been laid out. Try to avoid an error by interpreting
106 it as this->X::Y, if reasonable. */
107 if (TREE_CODE (value
) == OFFSET_REF
108 && current_class_ref
!= 0
109 && TREE_OPERAND (value
, 0) == current_class_ref
)
111 tree base
, member
= TREE_OPERAND (value
, 1);
112 tree basetype
= TYPE_OFFSET_BASETYPE (type
);
113 my_friendly_assert (TREE_CODE (member
) == FIELD_DECL
, 305);
114 base
= convert_pointer_to (basetype
, current_class_ptr
);
115 value
= build (COMPONENT_REF
, TREE_TYPE (member
),
116 build_indirect_ref (base
, NULL_PTR
), member
);
117 return require_complete_type (value
);
120 if (IS_AGGR_TYPE (type
) && CLASSTYPE_TEMPLATE_INSTANTIATION (type
))
122 instantiate_class_template (TYPE_MAIN_VARIANT (type
));
123 if (TYPE_SIZE (type
) != 0)
127 incomplete_type_error (value
, type
);
128 return error_mark_node
;
135 if (type
== NULL_TREE
)
136 /* Rather than crash, we return something sure to cause an error
138 return error_mark_node
;
140 if (type
== error_mark_node
|| TYPE_SIZE (type
) != NULL_TREE
)
142 else if (TREE_CODE (type
) == ARRAY_TYPE
&& TYPE_DOMAIN (type
))
144 tree t
= complete_type (TREE_TYPE (type
));
145 if (TYPE_SIZE (t
) != NULL_TREE
&& ! processing_template_decl
)
147 TYPE_NEEDS_CONSTRUCTING (type
)
148 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (t
));
149 TYPE_NEEDS_DESTRUCTOR (type
)
150 = TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (t
));
152 else if (IS_AGGR_TYPE (type
) && CLASSTYPE_TEMPLATE_INSTANTIATION (type
))
153 instantiate_class_template (TYPE_MAIN_VARIANT (type
));
158 /* Return truthvalue of whether type of EXP is instantiated. */
164 return (TREE_CODE (exp
) == TREE_LIST
165 || TREE_TYPE (exp
) == unknown_type_node
166 || (TREE_CODE (TREE_TYPE (exp
)) == OFFSET_TYPE
167 && TREE_TYPE (TREE_TYPE (exp
)) == unknown_type_node
));
170 /* Return truthvalue of whether T is function (or pfn) type. */
176 return (TREE_CODE (t
) == FUNCTION_TYPE
|| TREE_CODE (t
) == METHOD_TYPE
177 || (TREE_CODE (t
) == POINTER_TYPE
178 && (TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
179 || TREE_CODE (TREE_TYPE (t
)) == METHOD_TYPE
)));
182 /* Do `exp = require_instantiated_type (type, exp);' to make sure EXP
183 does not have an uninstantiated type.
184 TYPE is type to instantiate with, if uninstantiated. */
187 require_instantiated_type (type
, exp
, errval
)
188 tree type
, exp
, errval
;
190 if (TREE_TYPE (exp
) == NULL_TREE
)
192 error ("argument list may not have an initializer list");
196 if (TREE_TYPE (exp
) == unknown_type_node
197 || (TREE_CODE (TREE_TYPE (exp
)) == OFFSET_TYPE
198 && TREE_TYPE (TREE_TYPE (exp
)) == unknown_type_node
))
200 exp
= instantiate_type (type
, exp
, 1);
201 if (TREE_TYPE (exp
) == error_mark_node
)
207 /* Return a variant of TYPE which has all the type qualifiers of LIKE
208 as well as those of TYPE. */
211 qualify_type (type
, like
)
214 int constflag
= TYPE_READONLY (type
) || TYPE_READONLY (like
);
215 int volflag
= TYPE_VOLATILE (type
) || TYPE_VOLATILE (like
);
216 /* @@ Must do member pointers here. */
217 return cp_build_type_variant (type
, constflag
, volflag
);
220 /* Return the common type of two parameter lists.
221 We assume that comptypes has already been done and returned 1;
222 if that isn't so, this may crash.
224 As an optimization, free the space we allocate if the parameter
225 lists are already common. */
231 tree oldargs
= p1
, newargs
, n
;
234 char *first_obj
= (char *) oballoc (0);
236 len
= list_length (p1
);
237 newargs
= tree_last (p1
);
239 if (newargs
== void_list_node
)
248 newargs
= tree_cons (NULL_TREE
, NULL_TREE
, newargs
);
253 p1
= TREE_CHAIN (p1
), p2
= TREE_CHAIN (p2
), n
= TREE_CHAIN (n
), i
++)
255 if (TREE_PURPOSE (p1
) && !TREE_PURPOSE (p2
))
257 TREE_PURPOSE (n
) = TREE_PURPOSE (p1
);
260 else if (! TREE_PURPOSE (p1
))
262 if (TREE_PURPOSE (p2
))
264 TREE_PURPOSE (n
) = TREE_PURPOSE (p2
);
270 if (1 != simple_cst_equal (TREE_PURPOSE (p1
), TREE_PURPOSE (p2
)))
272 TREE_PURPOSE (n
) = TREE_PURPOSE (p2
);
274 if (TREE_VALUE (p1
) != TREE_VALUE (p2
))
277 TREE_VALUE (n
) = common_type (TREE_VALUE (p1
), TREE_VALUE (p2
));
280 TREE_VALUE (n
) = TREE_VALUE (p1
);
291 /* Return the common type of two types.
292 We assume that comptypes has already been done and returned 1;
293 if that isn't so, this may crash.
295 This is the type for the result of most arithmetic operations
296 if the operands have the given two types.
298 We do not deal with enumeral types here because they have already been
299 converted to integer types. */
305 register enum tree_code code1
;
306 register enum tree_code code2
;
309 /* Save time if the two types are the same. */
311 if (t1
== t2
) return t1
;
313 /* If one type is nonsense, use the other. */
314 if (t1
== error_mark_node
)
316 if (t2
== error_mark_node
)
319 /* Merge the attributes. */
320 attributes
= merge_machine_type_attributes (t1
, t2
);
322 { register tree a1
, a2
;
323 a1
= TYPE_ATTRIBUTES (t1
);
324 a2
= TYPE_ATTRIBUTES (t2
);
326 /* Either one unset? Take the set one. */
328 if (!(attributes
= a1
))
331 /* One that completely contains the other? Take it. */
333 else if (a2
&& !attribute_list_contained (a1
, a2
))
335 if (attribute_list_contained (a2
, a1
))
339 /* Pick the longest list, and hang on the other list. */
340 /* ??? For the moment we punt on the issue of attrs with args. */
342 if (list_length (a1
) < list_length (a2
))
343 attributes
= a2
, a2
= a1
;
345 for (; a2
; a2
= TREE_CHAIN (a2
))
346 if (lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2
)),
347 attributes
) == NULL_TREE
)
350 TREE_CHAIN (a1
) = attributes
;
357 /* Treat an enum type as the unsigned integer type of the same width. */
359 if (TREE_CODE (t1
) == ENUMERAL_TYPE
)
360 t1
= type_for_size (TYPE_PRECISION (t1
), 1);
361 if (TREE_CODE (t2
) == ENUMERAL_TYPE
)
362 t2
= type_for_size (TYPE_PRECISION (t2
), 1);
364 if (TYPE_PTRMEMFUNC_P (t1
))
365 t1
= TYPE_PTRMEMFUNC_FN_TYPE (t1
);
366 if (TYPE_PTRMEMFUNC_P (t2
))
367 t2
= TYPE_PTRMEMFUNC_FN_TYPE (t2
);
369 code1
= TREE_CODE (t1
);
370 code2
= TREE_CODE (t2
);
372 /* If one type is complex, form the common type of the non-complex
373 components, then make that complex. Use T1 or T2 if it is the
375 if (code1
== COMPLEX_TYPE
|| code2
== COMPLEX_TYPE
)
377 tree subtype1
= code1
== COMPLEX_TYPE
? TREE_TYPE (t1
) : t1
;
378 tree subtype2
= code2
== COMPLEX_TYPE
? TREE_TYPE (t2
) : t2
;
379 tree subtype
= common_type (subtype1
, subtype2
);
381 if (code1
== COMPLEX_TYPE
&& TREE_TYPE (t1
) == subtype
)
382 return build_type_attribute_variant (t1
, attributes
);
383 else if (code2
== COMPLEX_TYPE
&& TREE_TYPE (t2
) == subtype
)
384 return build_type_attribute_variant (t2
, attributes
);
386 return build_type_attribute_variant (build_complex_type (subtype
),
394 /* If only one is real, use it as the result. */
396 if (code1
== REAL_TYPE
&& code2
!= REAL_TYPE
)
397 return build_type_attribute_variant (t1
, attributes
);
399 if (code2
== REAL_TYPE
&& code1
!= REAL_TYPE
)
400 return build_type_attribute_variant (t2
, attributes
);
402 /* Both real or both integers; use the one with greater precision. */
404 if (TYPE_PRECISION (t1
) > TYPE_PRECISION (t2
))
405 return build_type_attribute_variant (t1
, attributes
);
406 else if (TYPE_PRECISION (t2
) > TYPE_PRECISION (t1
))
407 return build_type_attribute_variant (t2
, attributes
);
409 /* Same precision. Prefer longs to ints even when same size. */
411 if (TYPE_MAIN_VARIANT (t1
) == long_unsigned_type_node
412 || TYPE_MAIN_VARIANT (t2
) == long_unsigned_type_node
)
413 return build_type_attribute_variant (long_unsigned_type_node
,
416 if (TYPE_MAIN_VARIANT (t1
) == long_integer_type_node
417 || TYPE_MAIN_VARIANT (t2
) == long_integer_type_node
)
419 /* But preserve unsignedness from the other type,
420 since long cannot hold all the values of an unsigned int. */
421 if (TREE_UNSIGNED (t1
) || TREE_UNSIGNED (t2
))
422 t1
= long_unsigned_type_node
;
424 t1
= long_integer_type_node
;
425 return build_type_attribute_variant (t1
, attributes
);
428 if (TYPE_MAIN_VARIANT (t1
) == long_double_type_node
429 || TYPE_MAIN_VARIANT (t2
) == long_double_type_node
)
430 return build_type_attribute_variant (long_double_type_node
,
433 /* Otherwise prefer the unsigned one. */
435 if (TREE_UNSIGNED (t1
))
436 return build_type_attribute_variant (t1
, attributes
);
438 return build_type_attribute_variant (t2
, attributes
);
442 /* For two pointers, do this recursively on the target type,
443 and combine the qualifiers of the two types' targets. */
444 /* This code was turned off; I don't know why.
445 But ANSI C++ specifies doing this with the qualifiers.
446 So I turned it on again. */
448 tree tt1
= TYPE_MAIN_VARIANT (TREE_TYPE (t1
));
449 tree tt2
= TYPE_MAIN_VARIANT (TREE_TYPE (t2
));
451 = TYPE_READONLY (TREE_TYPE (t1
)) || TYPE_READONLY (TREE_TYPE (t2
));
453 = TYPE_VOLATILE (TREE_TYPE (t1
)) || TYPE_VOLATILE (TREE_TYPE (t2
));
458 else if (tt1
== void_type_node
|| tt2
== void_type_node
)
459 target
= void_type_node
;
460 else if (tt1
== unknown_type_node
)
462 else if (tt2
== unknown_type_node
)
465 target
= common_type (tt1
, tt2
);
467 target
= cp_build_type_variant (target
, constp
, volatilep
);
468 if (code1
== POINTER_TYPE
)
469 t1
= build_pointer_type (target
);
471 t1
= build_reference_type (target
);
472 t1
= build_type_attribute_variant (t1
, attributes
);
474 if (TREE_CODE (target
) == METHOD_TYPE
)
475 t1
= build_ptrmemfunc_type (t1
);
482 tree elt
= common_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
483 /* Save space: see if the result is identical to one of the args. */
484 if (elt
== TREE_TYPE (t1
) && TYPE_DOMAIN (t1
))
485 return build_type_attribute_variant (t1
, attributes
);
486 if (elt
== TREE_TYPE (t2
) && TYPE_DOMAIN (t2
))
487 return build_type_attribute_variant (t2
, attributes
);
488 /* Merge the element types, and have a size if either arg has one. */
489 t1
= build_cplus_array_type
490 (elt
, TYPE_DOMAIN (TYPE_DOMAIN (t1
) ? t1
: t2
));
491 return build_type_attribute_variant (t1
, attributes
);
495 /* Function types: prefer the one that specified arg types.
496 If both do, merge the arg types. Also merge the return types. */
498 tree valtype
= common_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
499 tree p1
= TYPE_ARG_TYPES (t1
);
500 tree p2
= TYPE_ARG_TYPES (t2
);
503 /* Save space: see if the result is identical to one of the args. */
504 if (valtype
== TREE_TYPE (t1
) && ! p2
)
505 return build_type_attribute_variant (t1
, attributes
);
506 if (valtype
== TREE_TYPE (t2
) && ! p1
)
507 return build_type_attribute_variant (t2
, attributes
);
509 /* Simple way if one arg fails to specify argument types. */
510 if (p1
== NULL_TREE
|| TREE_VALUE (p1
) == void_type_node
)
512 rval
= build_function_type (valtype
, p2
);
513 if ((raises
= TYPE_RAISES_EXCEPTIONS (t2
)))
514 rval
= build_exception_variant (rval
, raises
);
515 return build_type_attribute_variant (rval
, attributes
);
517 raises
= TYPE_RAISES_EXCEPTIONS (t1
);
518 if (p2
== NULL_TREE
|| TREE_VALUE (p2
) == void_type_node
)
520 rval
= build_function_type (valtype
, p1
);
522 rval
= build_exception_variant (rval
, raises
);
523 return build_type_attribute_variant (rval
, attributes
);
526 rval
= build_function_type (valtype
, commonparms (p1
, p2
));
527 rval
= build_exception_variant (rval
, raises
);
528 return build_type_attribute_variant (rval
, attributes
);
533 t1
= TYPE_MAIN_VARIANT (t1
);
534 t2
= TYPE_MAIN_VARIANT (t2
);
536 if (DERIVED_FROM_P (t1
, t2
) && binfo_or_else (t1
, t2
))
537 return build_type_attribute_variant (t1
, attributes
);
538 else if (binfo_or_else (t2
, t1
))
539 return build_type_attribute_variant (t2
, attributes
);
541 compiler_error ("common_type called with uncommon aggregate types");
544 if (TREE_CODE (TREE_TYPE (t1
)) == TREE_CODE (TREE_TYPE (t2
)))
546 /* Get this value the long way, since TYPE_METHOD_BASETYPE
547 is just the main variant of this. */
551 tree b1
= TYPE_OFFSET_BASETYPE (t1
);
552 tree b2
= TYPE_OFFSET_BASETYPE (t2
);
554 if (comptypes (b1
, b2
, 1)
555 || (DERIVED_FROM_P (b1
, b2
) && binfo_or_else (b1
, b2
)))
556 basetype
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t2
)));
559 if (binfo_or_else (b2
, b1
) == NULL_TREE
)
560 compiler_error ("common_type called with uncommon method types");
561 basetype
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t1
)));
564 raises
= TYPE_RAISES_EXCEPTIONS (t1
);
566 /* If this was a member function type, get back to the
567 original type of type member function (i.e., without
568 the class instance variable up front. */
569 t1
= build_function_type (TREE_TYPE (t1
),
570 TREE_CHAIN (TYPE_ARG_TYPES (t1
)));
571 t2
= build_function_type (TREE_TYPE (t2
),
572 TREE_CHAIN (TYPE_ARG_TYPES (t2
)));
573 t3
= common_type (t1
, t2
);
574 t3
= build_cplus_method_type (basetype
, TREE_TYPE (t3
),
575 TYPE_ARG_TYPES (t3
));
576 t1
= build_exception_variant (t3
, raises
);
579 compiler_error ("common_type called with uncommon method types");
581 return build_type_attribute_variant (t1
, attributes
);
584 if (TREE_TYPE (t1
) == TREE_TYPE (t2
))
586 tree b1
= TYPE_OFFSET_BASETYPE (t1
);
587 tree b2
= TYPE_OFFSET_BASETYPE (t2
);
589 if (comptypes (b1
, b2
, 1)
590 || (DERIVED_FROM_P (b1
, b2
) && binfo_or_else (b1
, b2
)))
591 return build_type_attribute_variant (t2
, attributes
);
592 else if (binfo_or_else (b2
, b1
))
593 return build_type_attribute_variant (t1
, attributes
);
595 compiler_error ("common_type called with uncommon member types");
598 return build_type_attribute_variant (t1
, attributes
);
602 /* Return 1 if TYPE1 and TYPE2 raise the same exceptions. */
605 compexcepttypes (t1
, t2
)
608 return TYPE_RAISES_EXCEPTIONS (t1
) == TYPE_RAISES_EXCEPTIONS (t2
);
612 comp_array_types (cmp
, t1
, t2
, strict
)
613 register int (*cmp
) PROTO((tree
, tree
, int));
617 tree d1
= TYPE_DOMAIN (t1
);
618 tree d2
= TYPE_DOMAIN (t2
);
620 /* Target types must match incl. qualifiers. */
621 if (!(TREE_TYPE (t1
) == TREE_TYPE (t2
)
622 || (*cmp
) (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
)))
625 /* Sizes must match unless one is missing or variable. */
626 if (d1
== 0 || d2
== 0 || d1
== d2
627 || TREE_CODE (TYPE_MIN_VALUE (d1
)) != INTEGER_CST
628 || TREE_CODE (TYPE_MIN_VALUE (d2
)) != INTEGER_CST
629 || TREE_CODE (TYPE_MAX_VALUE (d1
)) != INTEGER_CST
630 || TREE_CODE (TYPE_MAX_VALUE (d2
)) != INTEGER_CST
)
633 return ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1
))
634 == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2
)))
635 && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1
))
636 == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2
)))
637 && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1
))
638 == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2
)))
639 && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1
))
640 == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2
))));
643 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
644 or various other operations. This is what ANSI C++ speaks of as
647 For C++: argument STRICT says we should be strict about this
650 2 : strict, except that if one type is a reference and
651 the other is not, compare the target type of the
652 reference to the type that's not a reference (ARM, p308).
653 This is used for checking for invalid overloading.
654 1 : strict (compared according to ANSI C)
655 This is used for checking whether two function decls match.
656 0 : <= (compared according to C++)
657 -1: <= or >= (relaxed)
659 Otherwise, pointers involving base classes and derived classes can
660 be mixed as valid: i.e. a pointer to a derived class may be converted
661 to a pointer to one of its base classes, as per C++. A pointer to
662 a derived class may be passed as a parameter to a function expecting a
663 pointer to a base classes. These allowances do not commute. In this
664 case, TYPE1 is assumed to be the base class, and TYPE2 is assumed to
665 be the derived class. */
668 comptypes (type1
, type2
, strict
)
672 register tree t1
= type1
;
673 register tree t2
= type2
;
676 /* Suppress errors caused by previously reported errors */
681 /* This should never happen. */
682 my_friendly_assert (t1
!= error_mark_node
, 307);
684 if (t2
== error_mark_node
)
689 /* Treat an enum type as the unsigned integer type of the same width. */
691 if (TREE_CODE (t1
) == ENUMERAL_TYPE
)
692 t1
= type_for_size (TYPE_PRECISION (t1
), 1);
693 if (TREE_CODE (t2
) == ENUMERAL_TYPE
)
694 t2
= type_for_size (TYPE_PRECISION (t2
), 1);
700 if (TYPE_PTRMEMFUNC_P (t1
))
701 t1
= TYPE_PTRMEMFUNC_FN_TYPE (t1
);
702 if (TYPE_PTRMEMFUNC_P (t2
))
703 t2
= TYPE_PTRMEMFUNC_FN_TYPE (t2
);
705 /* Different classes of types can't be compatible. */
707 if (TREE_CODE (t1
) != TREE_CODE (t2
))
710 && ((TREE_CODE (t1
) == REFERENCE_TYPE
)
711 ^ (TREE_CODE (t2
) == REFERENCE_TYPE
)))
713 if (TREE_CODE (t1
) == REFERENCE_TYPE
)
714 return comptypes (TREE_TYPE (t1
), t2
, 1);
715 return comptypes (t1
, TREE_TYPE (t2
), 1);
723 /* Qualifiers must match. */
725 if (TYPE_READONLY (t1
) != TYPE_READONLY (t2
))
727 if (TYPE_VOLATILE (t1
) != TYPE_VOLATILE (t2
))
730 /* Allow for two different type nodes which have essentially the same
731 definition. Note that we already checked for equality of the type
732 qualifiers (just above). */
734 if (TYPE_MAIN_VARIANT (t1
) == TYPE_MAIN_VARIANT (t2
))
737 /* ??? COMP_TYPE_ATTRIBUTES is currently useless for variables as each
738 attribute is its own main variant (`val' will remain 0). */
739 #ifndef COMP_TYPE_ATTRIBUTES
740 #define COMP_TYPE_ATTRIBUTES(t1,t2) 1
743 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
744 if (! (attrval
= COMP_TYPE_ATTRIBUTES (t1
, t2
)))
747 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
750 switch (TREE_CODE (t1
))
752 case TEMPLATE_TEMPLATE_PARM
:
753 if (TEMPLATE_TYPE_IDX (t1
) != TEMPLATE_TYPE_IDX (t2
)
754 || TEMPLATE_TYPE_LEVEL (t1
) != TEMPLATE_TYPE_LEVEL (t2
))
756 if (! CLASSTYPE_TEMPLATE_INFO (t1
) && ! CLASSTYPE_TEMPLATE_INFO (t2
))
758 /* Don't check inheritance. */
764 if (CLASSTYPE_TEMPLATE_INFO (t1
) && CLASSTYPE_TEMPLATE_INFO (t2
)
765 && (CLASSTYPE_TI_TEMPLATE (t1
) == CLASSTYPE_TI_TEMPLATE (t2
)
766 || TREE_CODE (t1
) == TEMPLATE_TEMPLATE_PARM
))
767 return comp_template_args (CLASSTYPE_TI_ARGS (t1
),
768 CLASSTYPE_TI_ARGS (t2
));
774 val
= (comptypes (build_pointer_type (TYPE_OFFSET_BASETYPE (t1
)),
775 build_pointer_type (TYPE_OFFSET_BASETYPE (t2
)), strict
)
776 && comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
));
780 if (! compexcepttypes (t1
, t2
))
783 /* This case is anti-symmetrical!
784 One can pass a base member (or member function)
785 to something expecting a derived member (or member function),
786 but not vice-versa! */
788 val
= (comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
)
789 && compparms (TYPE_ARG_TYPES (t1
),
790 TYPE_ARG_TYPES (t2
), strict
));
804 if (TREE_CODE (t1
) == RECORD_TYPE
&& TREE_CODE (t2
) == RECORD_TYPE
)
808 rval
= t1
== t2
|| DERIVED_FROM_P (t1
, t2
);
817 val
= DERIVED_FROM_P (t2
, t1
);
824 val
= comptypes (t1
, t2
, strict
);
828 if (! compexcepttypes (t1
, t2
))
831 val
= ((TREE_TYPE (t1
) == TREE_TYPE (t2
)
832 || comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
))
833 && compparms (TYPE_ARG_TYPES (t1
), TYPE_ARG_TYPES (t2
), strict
));
837 /* Target types must match incl. qualifiers. */
838 val
= comp_array_types (comptypes
, t1
, t2
, strict
);
841 case TEMPLATE_TYPE_PARM
:
842 return TEMPLATE_TYPE_IDX (t1
) == TEMPLATE_TYPE_IDX (t2
)
843 && TEMPLATE_TYPE_LEVEL (t1
) == TEMPLATE_TYPE_LEVEL (t2
);
846 if (TYPE_IDENTIFIER (t1
) != TYPE_IDENTIFIER (t2
))
848 return comptypes (TYPE_CONTEXT (t1
), TYPE_CONTEXT (t2
), 1);
853 return attrval
== 2 && val
== 1 ? 2 : val
;
856 /* Return 1 or -1 if TTL and TTR are pointers to types that are equivalent,
857 ignoring their qualifiers, 0 if not. Return 1 means that TTR can be
858 converted to TTL. Return -1 means that TTL can be converted to TTR but
861 NPTRS is the number of pointers we can strip off and keep cool.
862 This is used to permit (for aggr A, aggr B) A, B* to convert to A*,
863 but to not permit B** to convert to A**.
865 This should go away. Callers should use can_convert or something
866 similar instead. (jason 17 Apr 1997) */
869 comp_target_types (ttl
, ttr
, nptrs
)
873 ttl
= TYPE_MAIN_VARIANT (ttl
);
874 ttr
= TYPE_MAIN_VARIANT (ttr
);
878 if (TREE_CODE (ttr
) != TREE_CODE (ttl
))
881 if (TREE_CODE (ttr
) == POINTER_TYPE
882 || (TREE_CODE (ttr
) == REFERENCE_TYPE
))
884 int is_ptr
= TREE_CODE (ttr
) == POINTER_TYPE
;
886 ttl
= TREE_TYPE (ttl
);
887 ttr
= TREE_TYPE (ttr
);
889 if (nptrs
> 0 && is_ptr
)
891 if (TREE_CODE (ttl
) == UNKNOWN_TYPE
892 || TREE_CODE (ttr
) == UNKNOWN_TYPE
)
894 else if (TREE_CODE (ttl
) == VOID_TYPE
895 && TREE_CODE (ttr
) != FUNCTION_TYPE
896 && TREE_CODE (ttr
) != METHOD_TYPE
897 && TREE_CODE (ttr
) != OFFSET_TYPE
)
899 else if (TREE_CODE (ttr
) == VOID_TYPE
900 && TREE_CODE (ttl
) != FUNCTION_TYPE
901 && TREE_CODE (ttl
) != METHOD_TYPE
902 && TREE_CODE (ttl
) != OFFSET_TYPE
)
904 else if (TREE_CODE (ttl
) == POINTER_TYPE
905 || TREE_CODE (ttl
) == ARRAY_TYPE
)
907 if (comp_ptr_ttypes (ttl
, ttr
))
909 else if (comp_ptr_ttypes (ttr
, ttl
))
915 /* Const and volatile mean something different for function types,
916 so the usual checks are not appropriate. */
917 if (TREE_CODE (ttl
) == FUNCTION_TYPE
|| TREE_CODE (ttl
) == METHOD_TYPE
)
918 return comp_target_types (ttl
, ttr
, nptrs
- 1);
920 /* Make sure that the cv-quals change only in the same direction as
924 int c
= TYPE_READONLY (ttl
) - TYPE_READONLY (ttr
);
925 int v
= TYPE_VOLATILE (ttl
) - TYPE_VOLATILE (ttr
);
927 if ((c
> 0 && v
< 0) || (c
< 0 && v
> 0))
930 if (TYPE_MAIN_VARIANT (ttl
) == TYPE_MAIN_VARIANT (ttr
))
931 return (c
+ v
< 0) ? -1 : 1;
933 t
= comp_target_types (ttl
, ttr
, nptrs
- 1);
934 if ((t
== 1 && c
+ v
>= 0) || (t
== -1 && c
+ v
<= 0))
941 if (TREE_CODE (ttr
) == ARRAY_TYPE
)
942 return comp_array_types (comp_target_types
, ttl
, ttr
, 0);
943 else if (TREE_CODE (ttr
) == FUNCTION_TYPE
|| TREE_CODE (ttr
) == METHOD_TYPE
)
950 if (comptypes (TREE_TYPE (ttl
), TREE_TYPE (ttr
), 1) == 0)
955 switch (comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), -1))
964 argsl
= TYPE_ARG_TYPES (ttl
);
965 argsr
= TYPE_ARG_TYPES (ttr
);
967 /* Compare 'this' here, not in comp_target_parms. */
968 if (TREE_CODE (ttr
) == METHOD_TYPE
)
970 tree tl
= TYPE_METHOD_BASETYPE (ttl
);
971 tree tr
= TYPE_METHOD_BASETYPE (ttr
);
973 if (comptypes (tr
, tl
, 0) == 0)
975 if (comptypes (tl
, tr
, 0))
981 argsl
= TREE_CHAIN (argsl
);
982 argsr
= TREE_CHAIN (argsr
);
985 switch (comp_target_parms (argsl
, argsr
, 1))
993 return saw_contra
? -1 : 1;
996 else if (TREE_CODE (ttr
) == OFFSET_TYPE
)
998 /* Contravariance: we can assign a pointer to base member to a pointer
999 to derived member. Note difference from simple pointer case, where
1000 we can pass a pointer to derived to a pointer to base. */
1001 if (comptypes (TYPE_OFFSET_BASETYPE (ttr
),
1002 TYPE_OFFSET_BASETYPE (ttl
), 0))
1003 return comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
);
1004 else if (comptypes (TYPE_OFFSET_BASETYPE (ttl
),
1005 TYPE_OFFSET_BASETYPE (ttr
), 0)
1006 && comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
))
1009 else if (IS_AGGR_TYPE (ttl
))
1013 if (comptypes (build_pointer_type (ttl
), build_pointer_type (ttr
), 0))
1015 if (comptypes (build_pointer_type (ttr
), build_pointer_type (ttl
), 0))
1023 /* If two types share a common base type, return that basetype.
1024 If there is not a unique most-derived base type, this function
1025 returns ERROR_MARK_NODE. */
1028 common_base_type (tt1
, tt2
)
1031 tree best
= NULL_TREE
;
1034 /* If one is a baseclass of another, that's good enough. */
1035 if (UNIQUELY_DERIVED_FROM_P (tt1
, tt2
))
1037 if (UNIQUELY_DERIVED_FROM_P (tt2
, tt1
))
1040 /* Otherwise, try to find a unique baseclass of TT1
1041 that is shared by TT2, and follow that down. */
1042 for (i
= CLASSTYPE_N_BASECLASSES (tt1
)-1; i
>= 0; i
--)
1044 tree basetype
= TYPE_BINFO_BASETYPE (tt1
, i
);
1045 tree trial
= common_base_type (basetype
, tt2
);
1048 if (trial
== error_mark_node
)
1050 if (best
== NULL_TREE
)
1052 else if (best
!= trial
)
1053 return error_mark_node
;
1058 for (i
= CLASSTYPE_N_BASECLASSES (tt2
)-1; i
>= 0; i
--)
1060 tree basetype
= TYPE_BINFO_BASETYPE (tt2
, i
);
1061 tree trial
= common_base_type (tt1
, basetype
);
1064 if (trial
== error_mark_node
)
1066 if (best
== NULL_TREE
)
1068 else if (best
!= trial
)
1069 return error_mark_node
;
1075 /* Subroutines of `comptypes'. */
1077 /* Return 1 if two parameter type lists PARMS1 and PARMS2
1078 are equivalent in the sense that functions with those parameter types
1079 can have equivalent types.
1080 If either list is empty, we win.
1081 Otherwise, the two lists must be equivalent, element by element.
1083 C++: See comment above about TYPE1, TYPE2.
1085 STRICT is no longer used. */
1088 compparms (parms1
, parms2
, strict
)
1089 tree parms1
, parms2
;
1092 register tree t1
= parms1
, t2
= parms2
;
1094 /* An unspecified parmlist matches any specified parmlist
1095 whose argument types don't need default promotions. */
1099 if (t1
== 0 && t2
== 0)
1101 /* If one parmlist is shorter than the other,
1102 they fail to match. */
1103 if (t1
== 0 || t2
== 0)
1105 if (! comptypes (TREE_VALUE (t2
), TREE_VALUE (t1
), 1))
1108 t1
= TREE_CHAIN (t1
);
1109 t2
= TREE_CHAIN (t2
);
1113 /* This really wants return whether or not parameter type lists
1114 would make their owning functions assignment compatible or not.
1116 The return value is like for comp_target_types.
1118 This should go away, possibly with the exception of the empty parmlist
1119 conversion; there are no conversions between function types in C++.
1120 (jason 17 Apr 1997) */
1123 comp_target_parms (parms1
, parms2
, strict
)
1124 tree parms1
, parms2
;
1127 register tree t1
= parms1
, t2
= parms2
;
1128 int warn_contravariance
= 0;
1130 /* In C, an unspecified parmlist matches any specified parmlist
1131 whose argument types don't need default promotions. This is not
1132 true for C++, but let's do it anyway for unfixed headers. */
1134 if (t1
== 0 && t2
!= 0)
1136 cp_pedwarn ("ANSI C++ prohibits conversion from `(%#T)' to `(...)'",
1138 return self_promoting_args_p (t2
);
1141 return self_promoting_args_p (t1
);
1143 for (; t1
|| t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
1147 /* If one parmlist is shorter than the other,
1148 they fail to match, unless STRICT is <= 0. */
1149 if (t1
== 0 || t2
== 0)
1154 return 1 + warn_contravariance
;
1155 return ((t1
&& TREE_PURPOSE (t1
)) + warn_contravariance
);
1157 p1
= TREE_VALUE (t1
);
1158 p2
= TREE_VALUE (t2
);
1159 if (comptypes (p1
, p2
, 1))
1165 if ((TREE_CODE (p1
) == POINTER_TYPE
&& TREE_CODE (p2
) == POINTER_TYPE
)
1166 || (TREE_CODE (p1
) == REFERENCE_TYPE
1167 && TREE_CODE (p2
) == REFERENCE_TYPE
))
1170 && (TYPE_MAIN_VARIANT (TREE_TYPE (p1
))
1171 == TYPE_MAIN_VARIANT (TREE_TYPE (p2
))))
1174 /* The following is wrong for contravariance,
1175 but many programs depend on it. */
1176 if (TREE_TYPE (p1
) == void_type_node
)
1178 if (TREE_TYPE (p2
) == void_type_node
)
1180 warn_contravariance
= 1;
1183 if (IS_AGGR_TYPE (TREE_TYPE (p1
)))
1185 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (p1
)),
1186 TYPE_MAIN_VARIANT (TREE_TYPE (p2
)), 1) == 0)
1190 /* Note backwards order due to contravariance. */
1191 if (comp_target_types (p2
, p1
, 1) <= 0)
1193 if (comp_target_types (p1
, p2
, 1) > 0)
1195 warn_contravariance
= 1;
1202 return warn_contravariance
? -1 : 1;
1205 /* Return 1 if PARMS specifies a fixed number of parameters
1206 and none of their types is affected by default promotions. */
1209 self_promoting_args_p (parms
)
1213 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
1215 register tree type
= TREE_VALUE (t
);
1217 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
1223 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
1226 if (C_PROMOTING_INTEGER_TYPE_P (type
))
1232 /* Return an unsigned type the same as TYPE in other respects.
1234 C++: must make these work for type variants as well. */
1237 unsigned_type (type
)
1240 tree type1
= TYPE_MAIN_VARIANT (type
);
1241 if (type1
== signed_char_type_node
|| type1
== char_type_node
)
1242 return unsigned_char_type_node
;
1243 if (type1
== integer_type_node
)
1244 return unsigned_type_node
;
1245 if (type1
== short_integer_type_node
)
1246 return short_unsigned_type_node
;
1247 if (type1
== long_integer_type_node
)
1248 return long_unsigned_type_node
;
1249 if (type1
== long_long_integer_type_node
)
1250 return long_long_unsigned_type_node
;
1251 if (type1
== intTI_type_node
)
1252 return unsigned_intTI_type_node
;
1253 if (type1
== intDI_type_node
)
1254 return unsigned_intDI_type_node
;
1255 if (type1
== intSI_type_node
)
1256 return unsigned_intSI_type_node
;
1257 if (type1
== intHI_type_node
)
1258 return unsigned_intHI_type_node
;
1259 if (type1
== intQI_type_node
)
1260 return unsigned_intQI_type_node
;
1262 return signed_or_unsigned_type (1, type
);
1265 /* Return a signed type the same as TYPE in other respects. */
1271 tree type1
= TYPE_MAIN_VARIANT (type
);
1272 if (type1
== unsigned_char_type_node
|| type1
== char_type_node
)
1273 return signed_char_type_node
;
1274 if (type1
== unsigned_type_node
)
1275 return integer_type_node
;
1276 if (type1
== short_unsigned_type_node
)
1277 return short_integer_type_node
;
1278 if (type1
== long_unsigned_type_node
)
1279 return long_integer_type_node
;
1280 if (type1
== long_long_unsigned_type_node
)
1281 return long_long_integer_type_node
;
1282 if (type1
== unsigned_intTI_type_node
)
1283 return intTI_type_node
;
1284 if (type1
== unsigned_intDI_type_node
)
1285 return intDI_type_node
;
1286 if (type1
== unsigned_intSI_type_node
)
1287 return intSI_type_node
;
1288 if (type1
== unsigned_intHI_type_node
)
1289 return intHI_type_node
;
1290 if (type1
== unsigned_intQI_type_node
)
1291 return intQI_type_node
;
1293 return signed_or_unsigned_type (0, type
);
1296 /* Return a type the same as TYPE except unsigned or
1297 signed according to UNSIGNEDP. */
1300 signed_or_unsigned_type (unsignedp
, type
)
1304 if (! INTEGRAL_TYPE_P (type
)
1305 || TREE_UNSIGNED (type
) == unsignedp
)
1308 if (TYPE_PRECISION (type
) == TYPE_PRECISION (signed_char_type_node
))
1309 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
1310 if (TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
))
1311 return unsignedp
? unsigned_type_node
: integer_type_node
;
1312 if (TYPE_PRECISION (type
) == TYPE_PRECISION (short_integer_type_node
))
1313 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
1314 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_integer_type_node
))
1315 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
1316 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_long_integer_type_node
))
1317 return (unsignedp
? long_long_unsigned_type_node
1318 : long_long_integer_type_node
);
1322 /* Compute the value of the `sizeof' operator. */
1328 enum tree_code code
= TREE_CODE (type
);
1331 if (processing_template_decl
)
1332 return build_min (SIZEOF_EXPR
, sizetype
, type
);
1334 if (code
== FUNCTION_TYPE
)
1336 if (pedantic
|| warn_pointer_arith
)
1337 pedwarn ("ANSI C++ forbids taking the sizeof a function type");
1338 return size_int (1);
1340 if (code
== METHOD_TYPE
)
1342 if (pedantic
|| warn_pointer_arith
)
1343 pedwarn ("ANSI C++ forbids taking the sizeof a method type");
1344 return size_int (1);
1346 if (code
== VOID_TYPE
)
1348 if (pedantic
|| warn_pointer_arith
)
1349 pedwarn ("ANSI C++ forbids taking the sizeof a void type");
1350 return size_int (1);
1352 if (code
== ERROR_MARK
)
1353 return size_int (1);
1355 /* ARM $5.3.2: ``When applied to a reference, the result is the size of the
1356 referenced object.'' */
1357 if (code
== REFERENCE_TYPE
)
1358 type
= TREE_TYPE (type
);
1360 /* We couldn't find anything in the ARM or the draft standard that says,
1361 one way or the other, if doing sizeof on something that doesn't have
1362 an object associated with it is correct or incorrect. For example, if
1363 you declare `struct S { char str[16]; };', and in your program do
1364 a `sizeof (S::str)', should we flag that as an error or should we give
1365 the size of it? Since it seems like a reasonable thing to do, we'll go
1366 with giving the value. */
1367 if (code
== OFFSET_TYPE
)
1368 type
= TREE_TYPE (type
);
1370 /* @@ This also produces an error for a signature ref.
1371 In that case we should be able to do better. */
1372 if (IS_SIGNATURE (type
))
1374 error ("`sizeof' applied to a signature type");
1375 return size_int (0);
1378 if (TYPE_SIZE (complete_type (type
)) == 0)
1380 cp_error ("`sizeof' applied to incomplete type `%T'", type
);
1381 return size_int (0);
1384 /* Convert in case a char is more than one unit. */
1385 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
1386 size_int (TYPE_PRECISION (char_type_node
)));
1387 t
= convert (sizetype
, t
);
1388 /* size_binop does not put the constant in range, so do it now. */
1389 if (TREE_CODE (t
) == INTEGER_CST
&& force_fit_type (t
, 0))
1390 TREE_CONSTANT_OVERFLOW (t
) = TREE_OVERFLOW (t
) = 1;
1398 if (processing_template_decl
)
1399 return build_min (SIZEOF_EXPR
, sizetype
, e
);
1401 if (TREE_CODE (e
) == COMPONENT_REF
1402 && DECL_BIT_FIELD (TREE_OPERAND (e
, 1)))
1403 error ("sizeof applied to a bit-field");
1404 /* ANSI says arrays and functions are converted inside comma.
1405 But we can't really convert them in build_compound_expr
1406 because that would break commas in lvalues.
1407 So do the conversion here if operand was a comma. */
1408 if (TREE_CODE (e
) == COMPOUND_EXPR
1409 && (TREE_CODE (TREE_TYPE (e
)) == ARRAY_TYPE
1410 || TREE_CODE (TREE_TYPE (e
)) == FUNCTION_TYPE
))
1411 e
= default_conversion (e
);
1412 else if (TREE_CODE (e
) == TREE_LIST
)
1414 tree t
= TREE_VALUE (e
);
1417 && TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
1418 || is_overloaded_fn (t
)))
1419 pedwarn ("ANSI C++ forbids taking the sizeof a function type");
1421 return c_sizeof (TREE_TYPE (e
));
1425 c_sizeof_nowarn (type
)
1428 enum tree_code code
= TREE_CODE (type
);
1431 if (code
== FUNCTION_TYPE
1432 || code
== METHOD_TYPE
1433 || code
== VOID_TYPE
1434 || code
== ERROR_MARK
)
1435 return size_int (1);
1436 if (code
== REFERENCE_TYPE
)
1437 type
= TREE_TYPE (type
);
1439 if (TYPE_SIZE (type
) == 0)
1440 return size_int (0);
1442 /* Convert in case a char is more than one unit. */
1443 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
1444 size_int (TYPE_PRECISION (char_type_node
)));
1445 t
= convert (sizetype
, t
);
1446 force_fit_type (t
, 0);
1450 /* Implement the __alignof keyword: Return the minimum required
1451 alignment of TYPE, measured in bytes. */
1457 enum tree_code code
= TREE_CODE (type
);
1460 if (processing_template_decl
)
1461 return build_min (ALIGNOF_EXPR
, sizetype
, type
);
1463 if (code
== FUNCTION_TYPE
|| code
== METHOD_TYPE
)
1464 return size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
1466 if (code
== VOID_TYPE
|| code
== ERROR_MARK
)
1467 return size_int (1);
1469 /* C++: this is really correct! */
1470 if (code
== REFERENCE_TYPE
)
1471 type
= TREE_TYPE (type
);
1473 /* @@ This also produces an error for a signature ref.
1474 In that case we should be able to do better. */
1475 if (IS_SIGNATURE (type
))
1477 error ("`__alignof' applied to a signature type");
1478 return size_int (1);
1481 t
= size_int (TYPE_ALIGN (type
) / BITS_PER_UNIT
);
1482 force_fit_type (t
, 0);
1486 /* Perform default promotions for C data used in expressions.
1487 Arrays and functions are converted to pointers;
1488 enumeral types or short or char, to int.
1489 In addition, manifest constants symbols are replaced by their values.
1491 C++: this will automatically bash references to their target type. */
1494 decay_conversion (exp
)
1497 register tree type
= TREE_TYPE (exp
);
1498 register enum tree_code code
= TREE_CODE (type
);
1500 if (code
== OFFSET_TYPE
)
1502 if (TREE_CODE (exp
) == OFFSET_REF
)
1503 return decay_conversion (resolve_offset_ref (exp
));
1505 type
= TREE_TYPE (type
);
1506 code
= TREE_CODE (type
);
1508 if (type
== unknown_type_node
)
1510 cp_pedwarn ("assuming & on overloaded member function");
1511 return build_unary_op (ADDR_EXPR
, exp
, 0);
1515 if (code
== REFERENCE_TYPE
)
1517 exp
= convert_from_reference (exp
);
1518 type
= TREE_TYPE (exp
);
1519 code
= TREE_CODE (type
);
1522 /* Constants can be used directly unless they're not loadable. */
1523 if (TREE_CODE (exp
) == CONST_DECL
)
1524 exp
= DECL_INITIAL (exp
);
1525 /* Replace a nonvolatile const static variable with its value. */
1526 else if (TREE_READONLY_DECL_P (exp
))
1528 exp
= decl_constant_value (exp
);
1529 type
= TREE_TYPE (exp
);
1532 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
1533 Leave such NOP_EXPRs, since RHS is being used in non-lvalue context. */
1535 if (code
== VOID_TYPE
)
1537 error ("void value not ignored as it ought to be");
1538 return error_mark_node
;
1540 if (code
== FUNCTION_TYPE
)
1542 return build_unary_op (ADDR_EXPR
, exp
, 0);
1544 if (code
== METHOD_TYPE
)
1546 cp_pedwarn ("assuming & on `%E'", exp
);
1547 return build_unary_op (ADDR_EXPR
, exp
, 0);
1549 if (code
== ARRAY_TYPE
)
1554 int constp
, volatilep
;
1556 if (TREE_CODE (exp
) == INDIRECT_REF
)
1558 /* Stripping away the INDIRECT_REF is not the right
1559 thing to do for references... */
1560 tree inner
= TREE_OPERAND (exp
, 0);
1561 if (TREE_CODE (TREE_TYPE (inner
)) == REFERENCE_TYPE
)
1563 inner
= build1 (CONVERT_EXPR
,
1564 build_pointer_type (TREE_TYPE
1565 (TREE_TYPE (inner
))),
1567 TREE_CONSTANT (inner
) = TREE_CONSTANT (TREE_OPERAND (inner
, 0));
1569 return cp_convert (build_pointer_type (TREE_TYPE (type
)), inner
);
1572 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
1574 tree op1
= decay_conversion (TREE_OPERAND (exp
, 1));
1575 return build (COMPOUND_EXPR
, TREE_TYPE (op1
),
1576 TREE_OPERAND (exp
, 0), op1
);
1580 && ! (TREE_CODE (exp
) == CONSTRUCTOR
&& TREE_STATIC (exp
)))
1582 error ("invalid use of non-lvalue array");
1583 return error_mark_node
;
1586 constp
= volatilep
= 0;
1587 if (TREE_CODE_CLASS (TREE_CODE (exp
)) == 'r'
1588 || TREE_CODE_CLASS (TREE_CODE (exp
)) == 'd')
1590 constp
= TREE_READONLY (exp
);
1591 volatilep
= TREE_THIS_VOLATILE (exp
);
1594 restype
= TREE_TYPE (type
);
1595 if (TYPE_READONLY (type
) || TYPE_VOLATILE (type
)
1596 || constp
|| volatilep
)
1597 restype
= cp_build_type_variant (restype
,
1598 TYPE_READONLY (type
) || constp
,
1599 TYPE_VOLATILE (type
) || volatilep
);
1600 ptrtype
= build_pointer_type (restype
);
1602 if (TREE_CODE (exp
) == VAR_DECL
)
1604 /* ??? This is not really quite correct
1605 in that the type of the operand of ADDR_EXPR
1606 is not the target type of the type of the ADDR_EXPR itself.
1607 Question is, can this lossage be avoided? */
1608 adr
= build1 (ADDR_EXPR
, ptrtype
, exp
);
1609 if (mark_addressable (exp
) == 0)
1610 return error_mark_node
;
1611 TREE_CONSTANT (adr
) = staticp (exp
);
1612 TREE_SIDE_EFFECTS (adr
) = 0; /* Default would be, same as EXP. */
1615 /* This way is better for a COMPONENT_REF since it can
1616 simplify the offset for a component. */
1617 adr
= build_unary_op (ADDR_EXPR
, exp
, 1);
1618 return cp_convert (ptrtype
, adr
);
1625 default_conversion (exp
)
1629 enum tree_code code
;
1631 exp
= decay_conversion (exp
);
1633 type
= TREE_TYPE (exp
);
1634 code
= TREE_CODE (type
);
1636 if (INTEGRAL_CODE_P (code
))
1638 tree t
= type_promotes_to (type
);
1640 return cp_convert (t
, exp
);
1646 /* Take the address of an inline function without setting TREE_ADDRESSABLE
1650 inline_conversion (exp
)
1653 if (TREE_CODE (exp
) == FUNCTION_DECL
)
1655 tree type
= build_type_variant
1656 (TREE_TYPE (exp
), TREE_READONLY (exp
), TREE_THIS_VOLATILE (exp
));
1657 exp
= build1 (ADDR_EXPR
, build_pointer_type (type
), exp
);
1663 build_object_ref (datum
, basetype
, field
)
1664 tree datum
, basetype
, field
;
1667 if (datum
== error_mark_node
)
1668 return error_mark_node
;
1670 dtype
= TREE_TYPE (datum
);
1671 if (TREE_CODE (dtype
) == REFERENCE_TYPE
)
1672 dtype
= TREE_TYPE (dtype
);
1673 if (! IS_AGGR_TYPE_CODE (TREE_CODE (dtype
)))
1675 cp_error ("request for member `%T::%D' in expression of non-aggregate type `%T'",
1676 basetype
, field
, dtype
);
1677 return error_mark_node
;
1679 else if (IS_SIGNATURE (basetype
))
1681 warning ("signature name in scope resolution ignored");
1682 return build_component_ref (datum
, field
, NULL_TREE
, 1);
1684 else if (is_aggr_type (basetype
, 1))
1686 tree binfo
= binfo_or_else (basetype
, dtype
);
1688 return build_x_component_ref (build_scoped_ref (datum
, basetype
),
1691 return error_mark_node
;
1694 /* Like `build_component_ref, but uses an already found field, and converts
1695 from a reference. Must compute access for current_class_ref.
1699 build_component_ref_1 (datum
, field
, protect
)
1703 return convert_from_reference
1704 (build_component_ref (datum
, field
, NULL_TREE
, protect
));
1707 /* Given a COND_EXPR, MIN_EXPR, or MAX_EXPR in T, return it in a form that we
1708 can, for example, use as an lvalue. This code used to be in
1709 unary_complex_lvalue, but we needed it to deal with `a = (d == c) ? b : c'
1710 expressions, where we're dealing with aggregates. But now it's again only
1711 called from unary_complex_lvalue. The case (in particular) that led to
1712 this was with CODE == ADDR_EXPR, since it's not an lvalue when we'd
1716 rationalize_conditional_expr (code
, t
)
1717 enum tree_code code
;
1720 /* For MIN_EXPR or MAX_EXPR, fold-const.c has arranged things so that
1721 the first operand is always the one to be used if both operands
1722 are equal, so we know what conditional expression this used to be. */
1723 if (TREE_CODE (t
) == MIN_EXPR
|| TREE_CODE (t
) == MAX_EXPR
)
1726 build_conditional_expr (build_x_binary_op ((TREE_CODE (t
) == MIN_EXPR
1727 ? LE_EXPR
: GE_EXPR
),
1728 TREE_OPERAND (t
, 0),
1729 TREE_OPERAND (t
, 1)),
1730 build_unary_op (code
, TREE_OPERAND (t
, 0), 0),
1731 build_unary_op (code
, TREE_OPERAND (t
, 1), 0));
1735 build_conditional_expr (TREE_OPERAND (t
, 0),
1736 build_unary_op (code
, TREE_OPERAND (t
, 1), 0),
1737 build_unary_op (code
, TREE_OPERAND (t
, 2), 0));
1740 /* Given the TYPE of an anonymous union field inside T, return the
1741 FIELD_DECL for the field. If not found return NULL_TREE. Because
1742 anonymous unions can nest, we must also search all anonymous unions
1743 that are directly reachable. */
1746 lookup_anon_field (t
, type
)
1751 for (field
= TYPE_FIELDS (t
); field
; field
= TREE_CHAIN (field
))
1753 if (TREE_STATIC (field
))
1755 if (TREE_CODE (field
) != FIELD_DECL
)
1758 /* If we find it directly, return the field. */
1759 if (DECL_NAME (field
) == NULL_TREE
1760 && type
== TREE_TYPE (field
))
1765 /* Otherwise, it could be nested, search harder. */
1766 if (DECL_NAME (field
) == NULL_TREE
1767 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
1769 tree subfield
= lookup_anon_field (TREE_TYPE (field
), type
);
1777 /* Build a COMPONENT_REF for a given DATUM, and it's member COMPONENT.
1778 COMPONENT can be an IDENTIFIER_NODE that is the name of the member
1779 that we are interested in, or it can be a FIELD_DECL. */
1782 build_component_ref (datum
, component
, basetype_path
, protect
)
1783 tree datum
, component
, basetype_path
;
1786 register tree basetype
= TREE_TYPE (datum
);
1787 register enum tree_code code
;
1788 register tree field
= NULL
;
1791 if (processing_template_decl
)
1792 return build_min_nt (COMPONENT_REF
, datum
, component
);
1794 /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference
1796 switch (TREE_CODE (datum
))
1800 tree value
= build_component_ref (TREE_OPERAND (datum
, 1), component
,
1801 basetype_path
, protect
);
1802 return build (COMPOUND_EXPR
, TREE_TYPE (value
),
1803 TREE_OPERAND (datum
, 0), value
);
1806 return build_conditional_expr
1807 (TREE_OPERAND (datum
, 0),
1808 build_component_ref (TREE_OPERAND (datum
, 1), component
,
1809 basetype_path
, protect
),
1810 build_component_ref (TREE_OPERAND (datum
, 2), component
,
1811 basetype_path
, protect
));
1814 cp_error ("invalid use of %D", datum
);
1815 datum
= error_mark_node
;
1822 code
= TREE_CODE (basetype
);
1824 if (code
== REFERENCE_TYPE
)
1826 datum
= convert_from_reference (datum
);
1827 basetype
= TREE_TYPE (datum
);
1828 code
= TREE_CODE (basetype
);
1830 if (TREE_CODE (datum
) == OFFSET_REF
)
1832 datum
= resolve_offset_ref (datum
);
1833 basetype
= TREE_TYPE (datum
);
1834 code
= TREE_CODE (basetype
);
1837 /* First, see if there is a field or component with name COMPONENT. */
1838 if (TREE_CODE (component
) == TREE_LIST
)
1840 my_friendly_assert (!(TREE_CHAIN (component
) == NULL_TREE
1841 && DECL_CHAIN (TREE_VALUE (component
)) == NULL_TREE
), 309);
1842 return build (COMPONENT_REF
, TREE_TYPE (component
), datum
, component
);
1845 if (! IS_AGGR_TYPE_CODE (code
))
1847 if (code
!= ERROR_MARK
)
1848 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
1849 component
, datum
, basetype
);
1850 return error_mark_node
;
1853 if (TYPE_SIZE (complete_type (basetype
)) == 0)
1855 incomplete_type_error (0, basetype
);
1856 return error_mark_node
;
1859 if (TREE_CODE (component
) == BIT_NOT_EXPR
)
1861 if (TYPE_IDENTIFIER (basetype
) != TREE_OPERAND (component
, 0))
1863 cp_error ("destructor specifier `%T::~%T' must have matching names",
1864 basetype
, TREE_OPERAND (component
, 0));
1865 return error_mark_node
;
1867 if (! TYPE_HAS_DESTRUCTOR (basetype
))
1869 cp_error ("type `%T' has no destructor", basetype
);
1870 return error_mark_node
;
1872 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype
), 1);
1875 /* Look up component name in the structure type definition. */
1876 if (CLASSTYPE_VFIELD (basetype
)
1877 && DECL_NAME (CLASSTYPE_VFIELD (basetype
)) == component
)
1878 /* Special-case this because if we use normal lookups in an ambiguous
1879 hierarchy, the compiler will abort (because vptr lookups are
1880 not supposed to be ambiguous. */
1881 field
= CLASSTYPE_VFIELD (basetype
);
1882 else if (TREE_CODE (component
) == FIELD_DECL
1883 || TREE_CODE (component
) == TYPE_DECL
)
1889 tree name
= component
;
1890 if (TREE_CODE (component
) == VAR_DECL
)
1891 name
= DECL_NAME (component
);
1892 if (basetype_path
== NULL_TREE
)
1893 basetype_path
= TYPE_BINFO (basetype
);
1894 field
= lookup_field (basetype_path
, name
,
1895 protect
&& !VFIELD_NAME_P (name
), 0);
1896 if (field
== error_mark_node
)
1897 return error_mark_node
;
1899 if (field
== NULL_TREE
)
1901 /* Not found as a data field, look for it as a method. If found,
1902 then if this is the only possible one, return it, else
1903 report ambiguity error. */
1904 tree fndecls
= lookup_fnfields (basetype_path
, name
, 1);
1905 if (fndecls
== error_mark_node
)
1906 return error_mark_node
;
1909 if (TREE_CHAIN (fndecls
) == NULL_TREE
1910 && DECL_CHAIN (TREE_VALUE (fndecls
)) == NULL_TREE
)
1912 tree access
, fndecl
;
1914 /* Unique, so use this one now. */
1915 basetype
= TREE_PURPOSE (fndecls
);
1916 fndecl
= TREE_VALUE (fndecls
);
1917 access
= compute_access (TREE_PURPOSE (fndecls
), fndecl
);
1918 if (access
== access_public_node
)
1920 if (DECL_VINDEX (fndecl
)
1921 && ! resolves_to_fixed_type_p (datum
, 0))
1923 tree addr
= build_unary_op (ADDR_EXPR
, datum
, 0);
1924 tree fntype
= TREE_TYPE (fndecl
);
1926 addr
= convert_pointer_to (DECL_CONTEXT (fndecl
),
1928 datum
= build_indirect_ref (addr
, NULL_PTR
);
1929 my_friendly_assert (datum
!= error_mark_node
, 310);
1930 fndecl
= build_vfn_ref (&addr
, datum
,
1931 DECL_VINDEX (fndecl
));
1932 /* The type of fndecl is a function type,
1933 not a pointer-to-function type, since
1934 build_vfn_ref returns not the correct
1935 vtable slot, but the indirection of the
1936 correct vtable slot. */
1937 TREE_TYPE (fndecl
) = fntype
;
1941 return build (OFFSET_REF
, TREE_TYPE (fndecl
),
1944 if (access
== access_protected_node
)
1945 cp_error ("member function `%D' is protected", fndecl
);
1947 cp_error ("member function `%D' is private", fndecl
);
1948 return error_mark_node
;
1952 /* Just act like build_offset_ref, since the object does
1953 not matter unless we're actually calling the function. */
1956 t
= build_tree_list (error_mark_node
, fndecls
);
1957 TREE_TYPE (t
) = build_offset_type (basetype
,
1963 cp_error ("`%#T' has no member named `%D'", basetype
, name
);
1964 return error_mark_node
;
1966 else if (TREE_TYPE (field
) == error_mark_node
)
1967 return error_mark_node
;
1969 if (TREE_CODE (field
) != FIELD_DECL
)
1971 if (TREE_CODE (field
) == TYPE_DECL
)
1973 cp_error ("invalid use of type decl `%#D' as expression", field
);
1974 return error_mark_node
;
1976 else if (DECL_RTL (field
) != 0)
1979 TREE_USED (field
) = 1;
1984 /* See if we have to do any conversions so that we pick up the field from the
1986 if (DECL_FIELD_CONTEXT (field
) != basetype
)
1988 tree context
= DECL_FIELD_CONTEXT (field
);
1989 tree base
= context
;
1990 while (base
!= basetype
&& TYPE_NAME (base
)
1991 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (base
)))
1993 base
= TYPE_CONTEXT (base
);
1996 /* Handle base classes here... */
1997 if (base
!= basetype
&& TYPE_USES_COMPLEX_INHERITANCE (basetype
))
1999 tree addr
= build_unary_op (ADDR_EXPR
, datum
, 0);
2000 if (integer_zerop (addr
))
2002 error ("invalid reference to NULL ptr, use ptr-to-member instead");
2003 return error_mark_node
;
2005 if (VBASE_NAME_P (DECL_NAME (field
)))
2007 /* It doesn't matter which vbase pointer we grab, just
2008 find one of them. */
2009 tree binfo
= get_binfo (base
,
2010 TREE_TYPE (TREE_TYPE (addr
)), 0);
2011 addr
= convert_pointer_to_real (binfo
, addr
);
2014 addr
= convert_pointer_to (base
, addr
);
2015 datum
= build_indirect_ref (addr
, NULL_PTR
);
2016 my_friendly_assert (datum
!= error_mark_node
, 311);
2020 /* Handle things from anon unions here... */
2021 if (TYPE_NAME (context
) && ANON_AGGRNAME_P (TYPE_IDENTIFIER (context
)))
2023 tree subfield
= lookup_anon_field (basetype
, context
);
2024 tree subdatum
= build_component_ref (datum
, subfield
,
2025 basetype_path
, protect
);
2026 return build_component_ref (subdatum
, field
, basetype_path
, protect
);
2030 ref
= fold (build (COMPONENT_REF
, TREE_TYPE (field
),
2031 break_out_cleanups (datum
), field
));
2033 if (TREE_READONLY (datum
) || TREE_READONLY (field
))
2034 TREE_READONLY (ref
) = 1;
2035 if (TREE_THIS_VOLATILE (datum
) || TREE_THIS_VOLATILE (field
))
2036 TREE_THIS_VOLATILE (ref
) = 1;
2037 if (DECL_MUTABLE_P (field
))
2038 TREE_READONLY (ref
) = 0;
2043 /* Variant of build_component_ref for use in expressions, which should
2044 never have REFERENCE_TYPE. */
2047 build_x_component_ref (datum
, component
, basetype_path
, protect
)
2048 tree datum
, component
, basetype_path
;
2051 tree t
= build_component_ref (datum
, component
, basetype_path
, protect
);
2053 if (! processing_template_decl
)
2054 t
= convert_from_reference (t
);
2059 /* Given an expression PTR for a pointer, return an expression
2060 for the value pointed to.
2061 ERRORSTRING is the name of the operator to appear in error messages.
2063 This function may need to overload OPERATOR_FNNAME.
2064 Must also handle REFERENCE_TYPEs for C++. */
2067 build_x_indirect_ref (ptr
, errorstring
)
2073 if (processing_template_decl
)
2074 return build_min_nt (INDIRECT_REF
, ptr
);
2076 rval
= build_opfncall (INDIRECT_REF
, LOOKUP_NORMAL
, ptr
, NULL_TREE
,
2080 return build_indirect_ref (ptr
, errorstring
);
2084 build_indirect_ref (ptr
, errorstring
)
2088 register tree pointer
, type
;
2090 if (ptr
== error_mark_node
)
2091 return error_mark_node
;
2093 pointer
= (TREE_CODE (TREE_TYPE (ptr
)) == REFERENCE_TYPE
2094 ? ptr
: default_conversion (ptr
));
2095 type
= TREE_TYPE (pointer
);
2097 if (ptr
== current_class_ptr
)
2098 return current_class_ref
;
2100 if (TREE_CODE (type
) == POINTER_TYPE
|| TREE_CODE (type
) == REFERENCE_TYPE
)
2102 if (TREE_CODE (pointer
) == ADDR_EXPR
2104 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (pointer
, 0)))
2105 == TYPE_MAIN_VARIANT (TREE_TYPE (type
)))
2106 && (TREE_READONLY (TREE_OPERAND (pointer
, 0))
2107 == TYPE_READONLY (TREE_TYPE (type
)))
2108 && (TREE_THIS_VOLATILE (TREE_OPERAND (pointer
, 0))
2109 == TYPE_VOLATILE (TREE_TYPE (type
))))
2110 return TREE_OPERAND (pointer
, 0);
2113 tree t
= TREE_TYPE (type
);
2114 register tree ref
= build1 (INDIRECT_REF
,
2115 TYPE_MAIN_VARIANT (t
), pointer
);
2117 /* We *must* set TREE_READONLY when dereferencing a pointer to const,
2118 so that we get the proper error message if the result is used
2119 to assign to. Also, &* is supposed to be a no-op. */
2120 TREE_READONLY (ref
) = TYPE_READONLY (t
);
2121 TREE_SIDE_EFFECTS (ref
)
2122 = (TYPE_VOLATILE (t
) || TREE_SIDE_EFFECTS (pointer
)
2124 TREE_THIS_VOLATILE (ref
) = TYPE_VOLATILE (t
);
2128 /* `pointer' won't be an error_mark_node if we were given a
2129 pointer to member, so it's cool to check for this here. */
2130 else if (TYPE_PTRMEMFUNC_P (type
))
2131 error ("invalid use of `%s' on pointer to member function", errorstring
);
2132 else if (TREE_CODE (type
) == RECORD_TYPE
2133 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
)))
2134 error ("cannot dereference signature pointer/reference");
2135 else if (pointer
!= error_mark_node
)
2138 error ("invalid type argument of `%s'", errorstring
);
2140 error ("invalid type argument");
2142 return error_mark_node
;
2145 /* This handles expressions of the form "a[i]", which denotes
2148 This is logically equivalent in C to *(a+i), but we may do it differently.
2149 If A is a variable or a member, we generate a primitive ARRAY_REF.
2150 This avoids forcing the array out of registers, and can work on
2151 arrays that are not lvalues (for example, members of structures returned
2154 If INDEX is of some user-defined type, it must be converted to
2155 integer type. Otherwise, to make a compatible PLUS_EXPR, it
2156 will inherit the type of the array, which will be some pointer type. */
2159 build_array_ref (array
, idx
)
2164 error ("subscript missing in array reference");
2165 return error_mark_node
;
2168 if (TREE_TYPE (array
) == error_mark_node
2169 || TREE_TYPE (idx
) == error_mark_node
)
2170 return error_mark_node
;
2172 if (TREE_CODE (TREE_TYPE (array
)) == ARRAY_TYPE
2173 && TREE_CODE (array
) != INDIRECT_REF
)
2177 /* Subscripting with type char is likely to lose
2178 on a machine where chars are signed.
2179 So warn on any machine, but optionally.
2180 Don't warn for unsigned char since that type is safe.
2181 Don't warn for signed char because anyone who uses that
2182 must have done so deliberately. */
2183 if (warn_char_subscripts
2184 && TYPE_MAIN_VARIANT (TREE_TYPE (idx
)) == char_type_node
)
2185 warning ("array subscript has type `char'");
2187 /* Apply default promotions *after* noticing character types. */
2188 idx
= default_conversion (idx
);
2190 if (TREE_CODE (TREE_TYPE (idx
)) != INTEGER_TYPE
)
2192 error ("array subscript is not an integer");
2193 return error_mark_node
;
2196 /* An array that is indexed by a non-constant
2197 cannot be stored in a register; we must be able to do
2198 address arithmetic on its address.
2199 Likewise an array of elements of variable size. */
2200 if (TREE_CODE (idx
) != INTEGER_CST
2201 || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
))) != 0
2202 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
))))
2205 if (mark_addressable (array
) == 0)
2206 return error_mark_node
;
2208 /* An array that is indexed by a constant value which is not within
2209 the array bounds cannot be stored in a register either; because we
2210 would get a crash in store_bit_field/extract_bit_field when trying
2211 to access a non-existent part of the register. */
2212 if (TREE_CODE (idx
) == INTEGER_CST
2213 && TYPE_VALUES (TREE_TYPE (array
))
2214 && ! int_fits_type_p (idx
, TYPE_VALUES (TREE_TYPE (array
))))
2216 if (mark_addressable (array
) == 0)
2217 return error_mark_node
;
2220 if (pedantic
&& !lvalue_p (array
))
2221 pedwarn ("ANSI C++ forbids subscripting non-lvalue array");
2223 /* Note in C++ it is valid to subscript a `register' array, since
2224 it is valid to take the address of something with that
2225 storage specification. */
2229 while (TREE_CODE (foo
) == COMPONENT_REF
)
2230 foo
= TREE_OPERAND (foo
, 0);
2231 if (TREE_CODE (foo
) == VAR_DECL
&& DECL_REGISTER (foo
))
2232 warning ("subscripting array declared `register'");
2235 type
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array
)));
2236 rval
= build (ARRAY_REF
, type
, array
, idx
);
2237 /* Array ref is const/volatile if the array elements are
2238 or if the array is.. */
2239 TREE_READONLY (rval
)
2240 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array
)))
2241 | TREE_READONLY (array
));
2242 TREE_SIDE_EFFECTS (rval
)
2243 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
2244 | TREE_SIDE_EFFECTS (array
));
2245 TREE_THIS_VOLATILE (rval
)
2246 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
2247 /* This was added by rms on 16 Nov 91.
2248 It fixes vol struct foo *a; a->elts[1]
2249 in an inline function.
2250 Hope it doesn't break something else. */
2251 | TREE_THIS_VOLATILE (array
));
2252 return require_complete_type (fold (rval
));
2256 tree ar
= default_conversion (array
);
2257 tree ind
= default_conversion (idx
);
2259 /* Put the integer in IND to simplify error checking. */
2260 if (TREE_CODE (TREE_TYPE (ar
)) == INTEGER_TYPE
)
2267 if (ar
== error_mark_node
)
2270 if (TREE_CODE (TREE_TYPE (ar
)) != POINTER_TYPE
)
2272 error ("subscripted value is neither array nor pointer");
2273 return error_mark_node
;
2275 if (TREE_CODE (TREE_TYPE (ind
)) != INTEGER_TYPE
)
2277 error ("array subscript is not an integer");
2278 return error_mark_node
;
2281 return build_indirect_ref (build_binary_op_nodefault (PLUS_EXPR
, ar
,
2287 /* Build a function call to function FUNCTION with parameters PARAMS.
2288 PARAMS is a list--a chain of TREE_LIST nodes--in which the
2289 TREE_VALUE of each node is a parameter-expression. The PARAMS do
2290 not include any object pointer that may be required. FUNCTION's
2291 data type may be a function type or a pointer-to-function.
2293 For C++: If FUNCTION's data type is a TREE_LIST, then the tree list
2294 is the list of possible methods that FUNCTION could conceivably
2295 be. If the list of methods comes from a class, then it will be
2296 a list of lists (where each element is associated with the class
2297 that produced it), otherwise it will be a simple list (for
2298 functions overloaded in global scope).
2300 In the first case, TREE_VALUE (function) is the head of one of those
2301 lists, and TREE_PURPOSE is the name of the function.
2303 In the second case, TREE_PURPOSE (function) is the function's
2306 DECL is the class instance variable, usually CURRENT_CLASS_REF.
2308 When calling a TEMPLATE_DECL, we don't require a complete return
2312 build_x_function_call (function
, params
, decl
)
2313 tree function
, params
, decl
;
2316 tree template_id
= NULL_TREE
;
2319 if (function
== error_mark_node
)
2320 return error_mark_node
;
2322 if (processing_template_decl
)
2323 return build_min_nt (CALL_EXPR
, function
, params
, NULL_TREE
);
2325 /* Save explicit template arguments if found */
2326 if (TREE_CODE (function
) == TEMPLATE_ID_EXPR
)
2328 template_id
= function
;
2329 function
= TREE_OPERAND (function
, 0);
2332 type
= TREE_TYPE (function
);
2334 if (TREE_CODE (type
) == OFFSET_TYPE
2335 && TREE_TYPE (type
) == unknown_type_node
2336 && TREE_CODE (function
) == TREE_LIST
2337 && TREE_CHAIN (function
) == NULL_TREE
)
2339 /* Undo (Foo:bar)()... */
2340 type
= TYPE_OFFSET_BASETYPE (type
);
2341 function
= TREE_VALUE (function
);
2342 my_friendly_assert (TREE_CODE (function
) == TREE_LIST
, 999);
2343 my_friendly_assert (TREE_CHAIN (function
) == NULL_TREE
, 999);
2344 function
= TREE_VALUE (function
);
2345 my_friendly_assert (TREE_CODE (function
) == FUNCTION_DECL
, 999);
2346 function
= DECL_NAME (function
);
2347 return build_method_call (decl
, function
, params
,
2348 TYPE_BINFO (type
), LOOKUP_NORMAL
);
2351 is_method
= ((TREE_CODE (function
) == TREE_LIST
2352 && current_class_type
!= NULL_TREE
2353 && (IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (function
))
2355 || TREE_CODE (function
) == IDENTIFIER_NODE
2356 || TREE_CODE (type
) == METHOD_TYPE
2357 || TYPE_PTRMEMFUNC_P (type
));
2359 if ((TREE_CODE (function
) == FUNCTION_DECL
2360 && DECL_STATIC_FUNCTION_P (function
))
2361 || (TREE_CODE (function
) == TEMPLATE_DECL
2362 && DECL_STATIC_FUNCTION_P (DECL_RESULT (function
))))
2363 return build_member_call
2364 (DECL_CONTEXT (function
), DECL_NAME (function
), params
);
2366 /* A friend template. Make it look like a toplevel declaration. */
2367 if (! is_method
&& TREE_CODE (function
) == TEMPLATE_DECL
)
2368 function
= build_scratch_list (NULL_TREE
, function
);
2370 /* Handle methods, friends, and overloaded functions, respectively. */
2373 tree basetype
= NULL_TREE
;
2375 if (TREE_CODE (function
) == FUNCTION_DECL
2376 || DECL_FUNCTION_TEMPLATE_P (function
))
2378 basetype
= DECL_CLASS_CONTEXT (function
);
2380 if (DECL_NAME (function
))
2381 function
= DECL_NAME (function
);
2383 function
= TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function
));
2385 else if (TREE_CODE (function
) == TREE_LIST
)
2387 my_friendly_assert (TREE_CODE (TREE_VALUE (function
))
2388 == FUNCTION_DECL
, 312);
2389 basetype
= DECL_CLASS_CONTEXT (TREE_VALUE (function
));
2390 function
= TREE_PURPOSE (function
);
2392 else if (TREE_CODE (function
) != IDENTIFIER_NODE
)
2394 if (TREE_CODE (function
) == OFFSET_REF
)
2396 if (TREE_OPERAND (function
, 0))
2397 decl
= TREE_OPERAND (function
, 0);
2399 /* Call via a pointer to member function. */
2400 if (decl
== NULL_TREE
)
2402 error ("pointer to member function called, but not in class scope");
2403 return error_mark_node
;
2405 /* What other type of POINTER_TYPE could this be? */
2406 if (TREE_CODE (TREE_TYPE (function
)) != POINTER_TYPE
2407 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (function
))
2408 && TREE_CODE (function
) != OFFSET_REF
)
2409 function
= build (OFFSET_REF
, TREE_TYPE (type
), NULL_TREE
,
2414 /* this is an abbreviated method call.
2415 must go through here in case it is a virtual function.
2416 @@ Perhaps this could be optimized. */
2418 if (basetype
&& (! current_class_type
2419 || ! DERIVED_FROM_P (basetype
, current_class_type
)))
2420 return build_member_call (basetype
, function
, params
);
2422 if (decl
== NULL_TREE
)
2424 if (current_class_type
== NULL_TREE
)
2426 error ("object missing in call to method `%s'",
2427 IDENTIFIER_POINTER (function
));
2428 return error_mark_node
;
2430 /* Yow: call from a static member function. */
2431 decl
= build1 (NOP_EXPR
, build_pointer_type (current_class_type
),
2433 decl
= build_indirect_ref (decl
, NULL_PTR
);
2436 /* Put back explicit template arguments, if any. */
2438 function
= template_id
;
2439 return build_method_call (decl
, function
, params
,
2440 NULL_TREE
, LOOKUP_NORMAL
);
2442 else if (TREE_CODE (function
) == COMPONENT_REF
2443 && type
== unknown_type_node
)
2445 /* Should we undo what was done in build_component_ref? */
2446 if (TREE_CODE (TREE_PURPOSE (TREE_OPERAND (function
, 1))) == TREE_VEC
)
2447 /* Get the name that build_component_ref hid. */
2448 function
= DECL_NAME (TREE_VALUE (TREE_OPERAND (function
, 1)));
2450 function
= TREE_PURPOSE (TREE_OPERAND (function
, 1));
2451 return build_method_call (decl
, function
, params
,
2452 NULL_TREE
, LOOKUP_NORMAL
);
2454 else if (really_overloaded_fn (function
))
2456 if (TREE_VALUE (function
) == NULL_TREE
)
2458 cp_error ("function `%D' declared overloaded, but no definitions appear with which to resolve it?!?",
2459 TREE_PURPOSE (function
));
2460 return error_mark_node
;
2464 /* Put back explicit template arguments, if any. */
2466 function
= template_id
;
2467 return build_new_function_call (function
, params
);
2472 if (TREE_CODE (function
) == OFFSET_REF
)
2474 /* If the component is a data element (or a virtual function), we play
2475 games here to make things work. */
2478 if (TREE_OPERAND (function
, 0))
2479 decl
= TREE_OPERAND (function
, 0);
2481 decl
= current_class_ref
;
2483 decl_addr
= build_unary_op (ADDR_EXPR
, decl
, 0);
2484 function
= get_member_function_from_ptrfunc (&decl_addr
,
2485 TREE_OPERAND (function
, 1));
2486 params
= expr_tree_cons (NULL_TREE
, decl_addr
, params
);
2487 return build_function_call (function
, params
);
2490 type
= TREE_TYPE (function
);
2491 if (type
!= error_mark_node
)
2493 if (TREE_CODE (type
) == REFERENCE_TYPE
)
2494 type
= TREE_TYPE (type
);
2496 if (IS_AGGR_TYPE (type
))
2497 return build_opfncall (CALL_EXPR
, LOOKUP_NORMAL
, function
, params
, NULL_TREE
);
2502 tree fntype
= TREE_TYPE (function
);
2503 tree ctypeptr
= NULL_TREE
;
2505 /* Explicitly named method? */
2506 if (TREE_CODE (function
) == FUNCTION_DECL
)
2507 ctypeptr
= build_pointer_type (DECL_CLASS_CONTEXT (function
));
2508 /* Expression with ptr-to-method type? It could either be a plain
2509 usage, or it might be a case where the ptr-to-method is being
2510 passed in as an argument. */
2511 else if (TYPE_PTRMEMFUNC_P (fntype
))
2513 tree rec
= TYPE_METHOD_BASETYPE (TREE_TYPE
2514 (TYPE_PTRMEMFUNC_FN_TYPE (fntype
)));
2515 ctypeptr
= build_pointer_type (rec
);
2517 /* Unexpected node type? */
2519 my_friendly_abort (116);
2520 if (decl
== NULL_TREE
)
2522 if (current_function_decl
2523 && DECL_STATIC_FUNCTION_P (current_function_decl
))
2524 error ("invalid call to member function needing `this' in static member function scope");
2526 error ("pointer to member function called, but not in class scope");
2527 return error_mark_node
;
2529 if (TREE_CODE (TREE_TYPE (decl
)) != POINTER_TYPE
2530 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (decl
)))
2532 decl
= build_unary_op (ADDR_EXPR
, decl
, 0);
2533 decl
= convert_pointer_to (TREE_TYPE (ctypeptr
), decl
);
2536 decl
= build_c_cast (ctypeptr
, decl
);
2537 params
= expr_tree_cons (NULL_TREE
, decl
, params
);
2540 return build_function_call (function
, params
);
2543 /* Resolve a pointer to member function. INSTANCE is the object
2544 instance to use, if the member points to a virtual member. */
2547 get_member_function_from_ptrfunc (instance_ptrptr
, function
)
2548 tree
*instance_ptrptr
;
2551 if (TREE_CODE (function
) == OFFSET_REF
)
2553 function
= TREE_OPERAND (function
, 1);
2556 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function
)))
2558 tree fntype
, idx
, e1
, delta
, delta2
, e2
, e3
, aref
, vtbl
;
2561 tree instance_ptr
= *instance_ptrptr
;
2563 if (TREE_SIDE_EFFECTS (instance_ptr
))
2564 instance_ptr
= save_expr (instance_ptr
);
2566 if (TREE_SIDE_EFFECTS (function
))
2567 function
= save_expr (function
);
2569 fntype
= TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (function
));
2571 /* Promoting idx before saving it improves performance on RISC
2572 targets. Without promoting, the first compare used
2573 load-with-sign-extend, while the second used normal load then
2574 shift to sign-extend. An optimizer flaw, perhaps, but it's easier
2575 to make this change. */
2576 idx
= save_expr (default_conversion
2577 (build_component_ref (function
,
2580 e1
= build_binary_op (GT_EXPR
, idx
, integer_zero_node
, 1);
2581 delta
= cp_convert (ptrdiff_type_node
,
2582 build_component_ref (function
, delta_identifier
,
2584 delta2
= DELTA2_FROM_PTRMEMFUNC (function
);
2586 /* Convert down to the right base, before using the instance. */
2588 = convert_pointer_to_real (TYPE_METHOD_BASETYPE (TREE_TYPE (fntype
)),
2590 if (instance
== error_mark_node
&& instance_ptr
!= error_mark_node
)
2593 vtbl
= convert_pointer_to (ptr_type_node
, instance
);
2596 build_pointer_type (build_pointer_type (vtable_entry_type
)),
2597 vtbl
, cp_convert (ptrdiff_type_node
, delta2
));
2598 vtbl
= build_indirect_ref (vtbl
, NULL_PTR
);
2599 aref
= build_array_ref (vtbl
, build_binary_op (MINUS_EXPR
,
2601 integer_one_node
, 1));
2602 if (! flag_vtable_thunks
)
2604 aref
= save_expr (aref
);
2606 delta
= build_binary_op
2608 build_conditional_expr (e1
, build_component_ref (aref
,
2615 *instance_ptrptr
= build (PLUS_EXPR
, TREE_TYPE (instance_ptr
),
2616 instance_ptr
, delta
);
2617 if (flag_vtable_thunks
)
2620 e2
= build_component_ref (aref
, pfn_identifier
, NULL_TREE
, 0);
2622 e3
= PFN_FROM_PTRMEMFUNC (function
);
2623 TREE_TYPE (e2
) = TREE_TYPE (e3
);
2624 e1
= build_conditional_expr (e1
, e2
, e3
);
2626 if (instance_ptr
== error_mark_node
2627 && TREE_CODE (e1
) != ADDR_EXPR
2628 && TREE_CODE (TREE_OPERAND (e1
, 0)) != FUNCTION_DECL
)
2629 cp_error ("object missing in `%E'", function
);
2633 /* Make sure this doesn't get evaluated first inside one of the
2634 branches of the COND_EXPR. */
2635 if (TREE_CODE (instance_ptr
) == SAVE_EXPR
)
2636 function
= build (COMPOUND_EXPR
, TREE_TYPE (function
),
2637 instance_ptr
, function
);
2643 build_function_call_real (function
, params
, require_complete
, flags
)
2644 tree function
, params
;
2645 int require_complete
, flags
;
2647 register tree fntype
, fndecl
;
2648 register tree value_type
;
2649 register tree coerced_params
;
2650 tree name
= NULL_TREE
, assembler_name
= NULL_TREE
;
2653 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
2654 Strip such NOP_EXPRs, since FUNCTION is used in non-lvalue context. */
2655 if (TREE_CODE (function
) == NOP_EXPR
2656 && TREE_TYPE (function
) == TREE_TYPE (TREE_OPERAND (function
, 0)))
2657 function
= TREE_OPERAND (function
, 0);
2659 if (TREE_CODE (function
) == FUNCTION_DECL
)
2661 name
= DECL_NAME (function
);
2662 assembler_name
= DECL_ASSEMBLER_NAME (function
);
2664 GNU_xref_call (current_function_decl
,
2665 IDENTIFIER_POINTER (name
? name
2666 : TYPE_IDENTIFIER (DECL_CLASS_CONTEXT
2668 mark_used (function
);
2671 /* Convert anything with function type to a pointer-to-function. */
2674 && IDENTIFIER_LENGTH (name
) == 4
2675 && ! strcmp (IDENTIFIER_POINTER (name
), "main")
2676 && DECL_CONTEXT (function
) == NULL_TREE
)
2678 pedwarn ("ANSI C++ forbids calling `main' from within program");
2681 /* Differs from default_conversion by not setting TREE_ADDRESSABLE
2682 (because calling an inline function does not mean the function
2683 needs to be separately compiled). */
2685 if (DECL_INLINE (function
))
2686 function
= inline_conversion (function
);
2688 function
= build_addr_func (function
);
2694 function
= build_addr_func (function
);
2697 if (function
== error_mark_node
)
2698 return error_mark_node
;
2700 fntype
= TREE_TYPE (function
);
2702 if (TYPE_PTRMEMFUNC_P (fntype
))
2704 cp_error ("must use .* or ->* to call pointer-to-member function in `%E (...)'",
2706 return error_mark_node
;
2709 is_method
= (TREE_CODE (fntype
) == POINTER_TYPE
2710 && TREE_CODE (TREE_TYPE (fntype
)) == METHOD_TYPE
);
2712 if (!((TREE_CODE (fntype
) == POINTER_TYPE
2713 && TREE_CODE (TREE_TYPE (fntype
)) == FUNCTION_TYPE
)
2715 || TREE_CODE (function
) == TEMPLATE_ID_EXPR
))
2717 cp_error ("`%E' cannot be used as a function", function
);
2718 return error_mark_node
;
2721 /* fntype now gets the type of function pointed to. */
2722 fntype
= TREE_TYPE (fntype
);
2724 /* Convert the parameters to the types declared in the
2725 function prototype, or apply default promotions. */
2727 if (flags
& LOOKUP_COMPLAIN
)
2728 coerced_params
= convert_arguments (NULL_TREE
, TYPE_ARG_TYPES (fntype
),
2729 params
, fndecl
, LOOKUP_NORMAL
);
2731 coerced_params
= convert_arguments (NULL_TREE
, TYPE_ARG_TYPES (fntype
),
2734 if (coerced_params
== error_mark_node
)
2736 if (flags
& LOOKUP_SPECULATIVELY
)
2739 return error_mark_node
;
2742 /* Check for errors in format strings. */
2744 if (warn_format
&& (name
|| assembler_name
))
2745 check_function_format (name
, assembler_name
, coerced_params
);
2747 /* Recognize certain built-in functions so we can make tree-codes
2748 other than CALL_EXPR. We do this when it enables fold-const.c
2749 to do something useful. */
2751 if (TREE_CODE (function
) == ADDR_EXPR
2752 && TREE_CODE (TREE_OPERAND (function
, 0)) == FUNCTION_DECL
2753 && DECL_BUILT_IN (TREE_OPERAND (function
, 0)))
2754 switch (DECL_FUNCTION_CODE (TREE_OPERAND (function
, 0)))
2759 if (coerced_params
== 0)
2760 return integer_zero_node
;
2761 return build_unary_op (ABS_EXPR
, TREE_VALUE (coerced_params
), 0);
2768 value_type
= TREE_TYPE (fntype
) ? TREE_TYPE (fntype
) : void_type_node
;
2770 register tree result
2771 = build_call (function
, value_type
, coerced_params
);
2773 if (require_complete
)
2775 if (value_type
== void_type_node
)
2777 result
= require_complete_type (result
);
2779 if (IS_AGGR_TYPE (value_type
))
2780 result
= build_cplus_new (value_type
, result
);
2781 return convert_from_reference (result
);
2786 build_function_call (function
, params
)
2787 tree function
, params
;
2789 return build_function_call_real (function
, params
, 1, LOOKUP_NORMAL
);
2792 /* Convert the actual parameter expressions in the list VALUES
2793 to the types in the list TYPELIST.
2794 If parmdecls is exhausted, or when an element has NULL as its type,
2795 perform the default conversions.
2797 RETURN_LOC is the location of the return value, if known, NULL_TREE
2798 otherwise. This is useful in the case where we can avoid creating
2799 a temporary variable in the case where we can initialize the return
2800 value directly. If we are not eliding constructors, then we set this
2801 to NULL_TREE to avoid this avoidance.
2803 NAME is an IDENTIFIER_NODE or 0. It is used only for error messages.
2805 This is also where warnings about wrong number of args are generated.
2807 Return a list of expressions for the parameters as converted.
2809 Both VALUES and the returned value are chains of TREE_LIST nodes
2810 with the elements of the list in the TREE_VALUE slots of those nodes.
2812 In C++, unspecified trailing parameters can be filled in with their
2813 default arguments, if such were specified. Do so here. */
2816 convert_arguments (return_loc
, typelist
, values
, fndecl
, flags
)
2817 tree return_loc
, typelist
, values
, fndecl
;
2820 register tree typetail
, valtail
;
2821 register tree result
= NULL_TREE
;
2822 char *called_thing
= 0;
2825 if (! flag_elide_constructors
)
2828 /* Argument passing is always copy-initialization. */
2829 flags
|= LOOKUP_ONLYCONVERTING
;
2833 if (TREE_CODE (TREE_TYPE (fndecl
)) == METHOD_TYPE
)
2835 if (DECL_NAME (fndecl
) == NULL_TREE
2836 || IDENTIFIER_HAS_TYPE_VALUE (DECL_NAME (fndecl
)))
2837 called_thing
= "constructor";
2839 called_thing
= "member function";
2842 called_thing
= "function";
2845 for (valtail
= values
, typetail
= typelist
;
2847 valtail
= TREE_CHAIN (valtail
), i
++)
2849 register tree type
= typetail
? TREE_VALUE (typetail
) : 0;
2850 register tree val
= TREE_VALUE (valtail
);
2852 if (val
== error_mark_node
)
2853 return error_mark_node
;
2855 if (type
== void_type_node
)
2859 cp_error_at ("too many arguments to %s `%+D'", called_thing
,
2861 error ("at this point in file");
2864 error ("too many arguments to function");
2865 /* In case anybody wants to know if this argument
2868 TREE_TYPE (tree_last (result
)) = error_mark_node
;
2872 /* The tree type of the parameter being passed may not yet be
2873 known. In this case, its type is TYPE_UNKNOWN, and will
2874 be instantiated by the type given by TYPE. If TYPE
2875 is also NULL, the tree type of VAL is ERROR_MARK_NODE. */
2876 if (type
&& type_unknown_p (val
))
2877 val
= require_instantiated_type (type
, val
, integer_zero_node
);
2878 else if (type_unknown_p (val
))
2880 /* Strip the `&' from an overloaded FUNCTION_DECL. */
2881 if (TREE_CODE (val
) == ADDR_EXPR
)
2882 val
= TREE_OPERAND (val
, 0);
2883 if (really_overloaded_fn (val
))
2884 cp_error ("insufficient type information to resolve address of overloaded function `%D'",
2885 DECL_NAME (get_first_fn (val
)));
2887 error ("insufficient type information in parameter list");
2888 val
= integer_zero_node
;
2890 else if (TREE_CODE (val
) == OFFSET_REF
2891 && TREE_CODE (TREE_TYPE (val
)) == METHOD_TYPE
)
2893 /* This is unclean. Should be handled elsewhere. */
2894 val
= build_unary_op (ADDR_EXPR
, val
, 0);
2896 else if (TREE_CODE (val
) == OFFSET_REF
)
2897 val
= resolve_offset_ref (val
);
2899 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
2900 Strip such NOP_EXPRs, since VAL is used in non-lvalue context. */
2901 if (TREE_CODE (val
) == NOP_EXPR
2902 && TREE_TYPE (val
) == TREE_TYPE (TREE_OPERAND (val
, 0))
2903 && (type
== 0 || TREE_CODE (type
) != REFERENCE_TYPE
))
2904 val
= TREE_OPERAND (val
, 0);
2906 if (type
== 0 || TREE_CODE (type
) != REFERENCE_TYPE
)
2908 if (TREE_CODE (TREE_TYPE (val
)) == ARRAY_TYPE
2909 || TREE_CODE (TREE_TYPE (val
)) == FUNCTION_TYPE
2910 || TREE_CODE (TREE_TYPE (val
)) == METHOD_TYPE
)
2911 val
= default_conversion (val
);
2913 val
= require_complete_type (val
);
2916 if (val
== error_mark_node
)
2917 return error_mark_node
;
2921 /* Formal parm type is specified by a function prototype. */
2924 if (TYPE_SIZE (complete_type (type
)) == 0)
2926 error ("parameter type of called function is incomplete");
2931 parmval
= convert_for_initialization
2932 (return_loc
, type
, val
, flags
,
2933 "argument passing", fndecl
, i
);
2934 #ifdef PROMOTE_PROTOTYPES
2935 if ((TREE_CODE (type
) == INTEGER_TYPE
2936 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2937 && (TYPE_PRECISION (type
)
2938 < TYPE_PRECISION (integer_type_node
)))
2939 parmval
= default_conversion (parmval
);
2943 if (parmval
== error_mark_node
)
2944 return error_mark_node
;
2946 result
= expr_tree_cons (NULL_TREE
, parmval
, result
);
2950 if (TREE_CODE (TREE_TYPE (val
)) == REFERENCE_TYPE
)
2951 val
= convert_from_reference (val
);
2953 if (TREE_CODE (TREE_TYPE (val
)) == REAL_TYPE
2954 && (TYPE_PRECISION (TREE_TYPE (val
))
2955 < TYPE_PRECISION (double_type_node
)))
2956 /* Convert `float' to `double'. */
2957 result
= expr_tree_cons (NULL_TREE
,
2958 cp_convert (double_type_node
, val
),
2960 else if (IS_AGGR_TYPE (TREE_TYPE (val
))
2961 && ! TYPE_HAS_TRIVIAL_INIT_REF (TREE_TYPE (val
)))
2963 cp_warning ("cannot pass objects of type `%T' through `...'",
2965 result
= expr_tree_cons (NULL_TREE
, val
, result
);
2968 /* Convert `short' and `char' to full-size `int'. */
2969 result
= expr_tree_cons (NULL_TREE
, default_conversion (val
),
2974 typetail
= TREE_CHAIN (typetail
);
2977 if (typetail
!= 0 && typetail
!= void_list_node
)
2979 /* See if there are default arguments that can be used */
2980 if (TREE_PURPOSE (typetail
))
2982 for (; typetail
!= void_list_node
; ++i
)
2984 tree type
= TREE_VALUE (typetail
);
2985 tree val
= break_out_target_exprs (TREE_PURPOSE (typetail
));
2988 if (val
== NULL_TREE
)
2989 parmval
= error_mark_node
;
2990 else if (TREE_CODE (val
) == CONSTRUCTOR
)
2992 parmval
= digest_init (type
, val
, (tree
*)0);
2993 parmval
= convert_for_initialization (return_loc
, type
,
2995 "default constructor",
3000 /* This could get clobbered by the following call. */
3001 if (TREE_HAS_CONSTRUCTOR (val
))
3002 val
= copy_node (val
);
3004 parmval
= convert_for_initialization (return_loc
, type
,
3008 #ifdef PROMOTE_PROTOTYPES
3009 if ((TREE_CODE (type
) == INTEGER_TYPE
3010 || TREE_CODE (type
) == ENUMERAL_TYPE
)
3011 && (TYPE_PRECISION (type
)
3012 < TYPE_PRECISION (integer_type_node
)))
3013 parmval
= default_conversion (parmval
);
3017 if (parmval
== error_mark_node
)
3018 return error_mark_node
;
3020 result
= expr_tree_cons (0, parmval
, result
);
3021 typetail
= TREE_CHAIN (typetail
);
3022 /* ends with `...'. */
3023 if (typetail
== NULL_TREE
)
3031 char *buf
= (char *)alloca (32 + strlen (called_thing
));
3032 sprintf (buf
, "too few arguments to %s `%%#D'", called_thing
);
3033 cp_error_at (buf
, fndecl
);
3034 error ("at this point in file");
3037 error ("too few arguments to function");
3038 return error_mark_list
;
3042 return nreverse (result
);
3045 /* Build a binary-operation expression, after performing default
3046 conversions on the operands. CODE is the kind of expression to build. */
3049 build_x_binary_op (code
, arg1
, arg2
)
3050 enum tree_code code
;
3053 if (processing_template_decl
)
3054 return build_min_nt (code
, arg1
, arg2
);
3056 return build_new_op (code
, LOOKUP_NORMAL
, arg1
, arg2
, NULL_TREE
);
3060 build_binary_op (code
, arg1
, arg2
, convert_p
)
3061 enum tree_code code
;
3073 args
[0] = decay_conversion (args
[0]);
3074 args
[1] = decay_conversion (args
[1]);
3076 if (args
[0] == error_mark_node
|| args
[1] == error_mark_node
)
3077 return error_mark_node
;
3079 type0
= TREE_TYPE (args
[0]);
3080 type1
= TREE_TYPE (args
[1]);
3082 if (type_unknown_p (args
[0]))
3084 args
[0] = instantiate_type (type1
, args
[0], 1);
3085 args
[0] = decay_conversion (args
[0]);
3087 else if (type_unknown_p (args
[1]))
3089 args
[1] = require_instantiated_type (type0
, args
[1],
3091 args
[1] = decay_conversion (args
[1]);
3094 if (IS_AGGR_TYPE (type0
) || IS_AGGR_TYPE (type1
))
3095 my_friendly_abort (754867);
3097 return build_binary_op_nodefault (code
, args
[0], args
[1], code
);
3100 /* Build a binary-operation expression without default conversions.
3101 CODE is the kind of expression to build.
3102 This function differs from `build' in several ways:
3103 the data type of the result is computed and recorded in it,
3104 warnings are generated if arg data types are invalid,
3105 special handling for addition and subtraction of pointers is known,
3106 and some optimization is done (operations on narrow ints
3107 are done in the narrower type when that gives the same result).
3108 Constant folding is also done before the result is returned.
3110 ERROR_CODE is the code that determines what to say in error messages.
3111 It is usually, but not always, the same as CODE.
3113 Note that the operands will never have enumeral types
3114 because either they have just had the default conversions performed
3115 or they have both just been converted to some other type in which
3116 the arithmetic is to be done.
3118 C++: must do special pointer arithmetic when implementing
3119 multiple inheritance, and deal with pointer to member functions. */
3122 build_binary_op_nodefault (code
, orig_op0
, orig_op1
, error_code
)
3123 enum tree_code code
;
3124 tree orig_op0
, orig_op1
;
3125 enum tree_code error_code
;
3128 register enum tree_code code0
, code1
;
3131 /* Expression code to give to the expression when it is built.
3132 Normally this is CODE, which is what the caller asked for,
3133 but in some special cases we change it. */
3134 register enum tree_code resultcode
= code
;
3136 /* Data type in which the computation is to be performed.
3137 In the simplest cases this is the common type of the arguments. */
3138 register tree result_type
= NULL
;
3140 /* Nonzero means operands have already been type-converted
3141 in whatever way is necessary.
3142 Zero means they need to be converted to RESULT_TYPE. */
3145 /* Nonzero means create the expression with this type, rather than
3147 tree build_type
= 0;
3149 /* Nonzero means after finally constructing the expression
3150 convert it to this type. */
3151 tree final_type
= 0;
3153 /* Nonzero if this is an operation like MIN or MAX which can
3154 safely be computed in short if both args are promoted shorts.
3155 Also implies COMMON.
3156 -1 indicates a bitwise operation; this makes a difference
3157 in the exact conditions for when it is safe to do the operation
3158 in a narrower mode. */
3161 /* Nonzero if this is a comparison operation;
3162 if both args are promoted shorts, compare the original shorts.
3163 Also implies COMMON. */
3164 int short_compare
= 0;
3166 /* Nonzero if this is a right-shift operation, which can be computed on the
3167 original short and then promoted if the operand is a promoted short. */
3168 int short_shift
= 0;
3170 /* Nonzero means set RESULT_TYPE to the common type of the args. */
3173 /* Apply default conversions. */
3174 if (code
== TRUTH_AND_EXPR
|| code
== TRUTH_ANDIF_EXPR
3175 || code
== TRUTH_OR_EXPR
|| code
== TRUTH_ORIF_EXPR
3176 || code
== TRUTH_XOR_EXPR
)
3178 op0
= decay_conversion (orig_op0
);
3179 op1
= decay_conversion (orig_op1
);
3183 op0
= default_conversion (orig_op0
);
3184 op1
= default_conversion (orig_op1
);
3187 type0
= TREE_TYPE (op0
);
3188 type1
= TREE_TYPE (op1
);
3190 /* The expression codes of the data types of the arguments tell us
3191 whether the arguments are integers, floating, pointers, etc. */
3192 code0
= TREE_CODE (type0
);
3193 code1
= TREE_CODE (type1
);
3195 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
3196 STRIP_TYPE_NOPS (op0
);
3197 STRIP_TYPE_NOPS (op1
);
3199 /* If an error was already reported for one of the arguments,
3200 avoid reporting another error. */
3202 if (code0
== ERROR_MARK
|| code1
== ERROR_MARK
)
3203 return error_mark_node
;
3208 /* Handle the pointer + int case. */
3209 if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3210 return pointer_int_sum (PLUS_EXPR
, op0
, op1
);
3211 else if (code1
== POINTER_TYPE
&& code0
== INTEGER_TYPE
)
3212 return pointer_int_sum (PLUS_EXPR
, op1
, op0
);
3218 /* Subtraction of two similar pointers.
3219 We must subtract them as integers, then divide by object size. */
3220 if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
3221 && comp_target_types (type0
, type1
, 1))
3222 return pointer_diff (op0
, op1
, common_type (type0
, type1
));
3223 /* Handle pointer minus int. Just like pointer plus int. */
3224 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3225 return pointer_int_sum (MINUS_EXPR
, op0
, op1
);
3234 case TRUNC_DIV_EXPR
:
3236 case FLOOR_DIV_EXPR
:
3237 case ROUND_DIV_EXPR
:
3238 case EXACT_DIV_EXPR
:
3239 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
3240 || code0
== COMPLEX_TYPE
)
3241 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
3242 || code1
== COMPLEX_TYPE
))
3244 if (TREE_CODE (op1
) == INTEGER_CST
&& integer_zerop (op1
))
3245 cp_warning ("division by zero in `%E / 0'", op0
);
3246 else if (TREE_CODE (op1
) == REAL_CST
&& real_zerop (op1
))
3247 cp_warning ("division by zero in `%E / 0.'", op0
);
3249 if (!(code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
))
3250 resultcode
= RDIV_EXPR
;
3252 /* When dividing two signed integers, we have to promote to int.
3253 unless we divide by a constant != -1. Note that default
3254 conversion will have been performed on the operands at this
3255 point, so we have to dig out the original type to find out if
3257 shorten
= ((TREE_CODE (op0
) == NOP_EXPR
3258 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3259 || (TREE_CODE (op1
) == INTEGER_CST
3260 && (TREE_INT_CST_LOW (op1
) != -1
3261 || TREE_INT_CST_HIGH (op1
) != -1)));
3267 case BIT_ANDTC_EXPR
:
3270 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3272 /* If one operand is a constant, and the other is a short type
3273 that has been converted to an int,
3274 really do the work in the short type and then convert the
3275 result to int. If we are lucky, the constant will be 0 or 1
3276 in the short type, making the entire operation go away. */
3277 if (TREE_CODE (op0
) == INTEGER_CST
3278 && TREE_CODE (op1
) == NOP_EXPR
3279 && (TYPE_PRECISION (type1
)
3280 > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1
, 0))))
3281 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1
, 0))))
3283 final_type
= result_type
;
3284 op1
= TREE_OPERAND (op1
, 0);
3285 result_type
= TREE_TYPE (op1
);
3287 if (TREE_CODE (op1
) == INTEGER_CST
3288 && TREE_CODE (op0
) == NOP_EXPR
3289 && (TYPE_PRECISION (type0
)
3290 > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3291 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3293 final_type
= result_type
;
3294 op0
= TREE_OPERAND (op0
, 0);
3295 result_type
= TREE_TYPE (op0
);
3299 case TRUNC_MOD_EXPR
:
3300 case FLOOR_MOD_EXPR
:
3301 if (code1
== INTEGER_TYPE
&& integer_zerop (op1
))
3302 cp_warning ("division by zero in `%E % 0'", op0
);
3303 else if (code1
== REAL_TYPE
&& real_zerop (op1
))
3304 cp_warning ("division by zero in `%E % 0.'", op0
);
3306 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3308 /* Although it would be tempting to shorten always here, that loses
3309 on some targets, since the modulo instruction is undefined if the
3310 quotient can't be represented in the computation mode. We shorten
3311 only if unsigned or if dividing by something we know != -1. */
3312 shorten
= ((TREE_CODE (op0
) == NOP_EXPR
3313 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3314 || (TREE_CODE (op1
) == INTEGER_CST
3315 && (TREE_INT_CST_LOW (op1
) != -1
3316 || TREE_INT_CST_HIGH (op1
) != -1)));
3321 case TRUTH_ANDIF_EXPR
:
3322 case TRUTH_ORIF_EXPR
:
3323 case TRUTH_AND_EXPR
:
3325 result_type
= boolean_type_node
;
3328 /* Shift operations: result has same type as first operand;
3329 always convert second operand to int.
3330 Also set SHORT_SHIFT if shifting rightward. */
3333 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3335 result_type
= type0
;
3336 if (TREE_CODE (op1
) == INTEGER_CST
)
3338 if (tree_int_cst_lt (op1
, integer_zero_node
))
3339 warning ("right shift count is negative");
3342 if (TREE_INT_CST_LOW (op1
) | TREE_INT_CST_HIGH (op1
))
3344 if (TREE_INT_CST_HIGH (op1
) != 0
3345 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3346 >= TYPE_PRECISION (type0
)))
3347 warning ("right shift count >= width of type");
3350 /* Convert the shift-count to an integer, regardless of
3351 size of value being shifted. */
3352 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3353 op1
= cp_convert (integer_type_node
, op1
);
3354 /* Avoid converting op1 to result_type later. */
3360 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3362 result_type
= type0
;
3363 if (TREE_CODE (op1
) == INTEGER_CST
)
3365 if (tree_int_cst_lt (op1
, integer_zero_node
))
3366 warning ("left shift count is negative");
3367 else if (TREE_INT_CST_HIGH (op1
) != 0
3368 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3369 >= TYPE_PRECISION (type0
)))
3370 warning ("left shift count >= width of type");
3372 /* Convert the shift-count to an integer, regardless of
3373 size of value being shifted. */
3374 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3375 op1
= cp_convert (integer_type_node
, op1
);
3376 /* Avoid converting op1 to result_type later. */
3383 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3385 result_type
= type0
;
3386 if (TREE_CODE (op1
) == INTEGER_CST
)
3388 if (tree_int_cst_lt (op1
, integer_zero_node
))
3389 warning ("%s rotate count is negative",
3390 (code
== LROTATE_EXPR
) ? "left" : "right");
3391 else if (TREE_INT_CST_HIGH (op1
) != 0
3392 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3393 >= TYPE_PRECISION (type0
)))
3394 warning ("%s rotate count >= width of type",
3395 (code
== LROTATE_EXPR
) ? "left" : "right");
3397 /* Convert the shift-count to an integer, regardless of
3398 size of value being shifted. */
3399 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3400 op1
= cp_convert (integer_type_node
, op1
);
3406 build_type
= boolean_type_node
;
3407 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
3408 || code0
== COMPLEX_TYPE
)
3409 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
3410 || code1
== COMPLEX_TYPE
))
3412 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3414 register tree tt0
= TYPE_MAIN_VARIANT (TREE_TYPE (type0
));
3415 register tree tt1
= TYPE_MAIN_VARIANT (TREE_TYPE (type1
));
3417 if (comp_target_types (type0
, type1
, 1))
3418 result_type
= common_type (type0
, type1
);
3419 else if (tt0
== void_type_node
)
3421 if (pedantic
&& TREE_CODE (tt1
) == FUNCTION_TYPE
3422 && tree_int_cst_lt (TYPE_SIZE (type0
), TYPE_SIZE (type1
)))
3423 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3424 else if (TREE_CODE (tt1
) == OFFSET_TYPE
)
3425 pedwarn ("ANSI C++ forbids conversion of a pointer to member to `void *'");
3427 else if (tt1
== void_type_node
)
3429 if (pedantic
&& TREE_CODE (tt0
) == FUNCTION_TYPE
3430 && tree_int_cst_lt (TYPE_SIZE (type1
), TYPE_SIZE (type0
)))
3431 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3434 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3437 if (result_type
== NULL_TREE
)
3438 result_type
= ptr_type_node
;
3440 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
3441 && integer_zerop (op1
))
3442 result_type
= type0
;
3443 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
3444 && integer_zerop (op0
))
3445 result_type
= type1
;
3446 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3448 result_type
= type0
;
3449 error ("ANSI C++ forbids comparison between pointer and integer");
3451 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
3453 result_type
= type1
;
3454 error ("ANSI C++ forbids comparison between pointer and integer");
3456 else if (TYPE_PTRMEMFUNC_P (type0
) && TREE_CODE (op1
) == INTEGER_CST
3457 && integer_zerop (op1
))
3459 op0
= build_component_ref (op0
, index_identifier
, NULL_TREE
, 0);
3460 op1
= integer_zero_node
;
3461 result_type
= TREE_TYPE (op0
);
3463 else if (TYPE_PTRMEMFUNC_P (type1
) && TREE_CODE (op0
) == INTEGER_CST
3464 && integer_zerop (op0
))
3466 op0
= build_component_ref (op1
, index_identifier
, NULL_TREE
, 0);
3467 op1
= integer_zero_node
;
3468 result_type
= TREE_TYPE (op0
);
3470 else if (TYPE_PTRMEMFUNC_P (type0
) && TYPE_PTRMEMFUNC_P (type1
)
3471 && (TYPE_PTRMEMFUNC_FN_TYPE (type0
)
3472 == TYPE_PTRMEMFUNC_FN_TYPE (type1
)))
3474 /* The code we generate for the test is:
3476 (op0.index == op1.index
3477 && ((op1.index != -1 && op0.delta2 == op1.delta2)
3478 || op0.pfn == op1.pfn)) */
3480 tree index0
= build_component_ref (op0
, index_identifier
,
3482 tree index1
= save_expr (build_component_ref (op1
, index_identifier
,
3484 tree pfn0
= PFN_FROM_PTRMEMFUNC (op0
);
3485 tree pfn1
= PFN_FROM_PTRMEMFUNC (op1
);
3486 tree delta20
= DELTA2_FROM_PTRMEMFUNC (op0
);
3487 tree delta21
= DELTA2_FROM_PTRMEMFUNC (op1
);
3489 tree integer_neg_one_node
3490 = build_binary_op (MINUS_EXPR
, integer_zero_node
,
3491 integer_one_node
, 1);
3492 e1
= build_binary_op (EQ_EXPR
, index0
, index1
, 1);
3493 e2
= build_binary_op (NE_EXPR
, index1
, integer_neg_one_node
, 1);
3494 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e2
,
3495 build_binary_op (EQ_EXPR
, delta20
, delta21
, 1),
3497 e3
= build_binary_op (EQ_EXPR
, pfn0
, pfn1
, 1);
3498 e2
= build_binary_op (TRUTH_ORIF_EXPR
, e2
, e3
, 1);
3499 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e1
, e2
, 1);
3500 if (code
== EQ_EXPR
)
3502 return build_binary_op (EQ_EXPR
, e2
, integer_zero_node
, 1);
3504 else if (TYPE_PTRMEMFUNC_P (type0
)
3505 && TYPE_PTRMEMFUNC_FN_TYPE (type0
) == type1
)
3507 tree index0
= build_component_ref (op0
, index_identifier
,
3510 tree pfn0
= PFN_FROM_PTRMEMFUNC (op0
);
3511 tree delta20
= DELTA2_FROM_PTRMEMFUNC (op0
);
3512 tree delta21
= integer_zero_node
;
3514 tree integer_neg_one_node
3515 = build_binary_op (MINUS_EXPR
, integer_zero_node
, integer_one_node
, 1);
3516 if (TREE_CODE (TREE_OPERAND (op1
, 0)) == FUNCTION_DECL
3517 && DECL_VINDEX (TREE_OPERAND (op1
, 0)))
3519 /* Map everything down one to make room for
3520 the null pointer to member. */
3521 index1
= size_binop (PLUS_EXPR
,
3522 DECL_VINDEX (TREE_OPERAND (op1
, 0)),
3524 op1
= integer_zero_node
;
3525 delta21
= CLASSTYPE_VFIELD (TYPE_METHOD_BASETYPE
3526 (TREE_TYPE (type1
)));
3527 delta21
= DECL_FIELD_BITPOS (delta21
);
3528 delta21
= size_binop (FLOOR_DIV_EXPR
, delta21
,
3529 size_int (BITS_PER_UNIT
));
3530 delta21
= convert (sizetype
, delta21
);
3533 index1
= integer_neg_one_node
;
3535 tree nop1
= build1 (NOP_EXPR
, TYPE_PTRMEMFUNC_FN_TYPE (type0
),
3537 TREE_CONSTANT (nop1
) = TREE_CONSTANT (op1
);
3540 e1
= build_binary_op (EQ_EXPR
, index0
, index1
, 1);
3541 e2
= build_binary_op (NE_EXPR
, index1
, integer_neg_one_node
, 1);
3542 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e2
,
3543 build_binary_op (EQ_EXPR
, delta20
, delta21
, 1),
3545 e3
= build_binary_op (EQ_EXPR
, pfn0
, op1
, 1);
3546 e2
= build_binary_op (TRUTH_ORIF_EXPR
, e2
, e3
, 1);
3547 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e1
, e2
, 1);
3548 if (code
== EQ_EXPR
)
3550 return build_binary_op (EQ_EXPR
, e2
, integer_zero_node
, 1);
3552 else if (TYPE_PTRMEMFUNC_P (type1
)
3553 && TYPE_PTRMEMFUNC_FN_TYPE (type1
) == type0
)
3555 return build_binary_op (code
, op1
, op0
, 1);
3561 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3562 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3564 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3566 if (comp_target_types (type0
, type1
, 1))
3567 result_type
= common_type (type0
, type1
);
3570 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3572 result_type
= ptr_type_node
;
3581 build_type
= boolean_type_node
;
3582 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3583 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3585 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3587 if (comp_target_types (type0
, type1
, 1))
3588 result_type
= common_type (type0
, type1
);
3591 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3593 result_type
= ptr_type_node
;
3596 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
3597 && integer_zerop (op1
))
3598 result_type
= type0
;
3599 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
3600 && integer_zerop (op0
))
3601 result_type
= type1
;
3602 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3604 result_type
= type0
;
3605 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3607 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
3609 result_type
= type1
;
3610 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3618 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
|| code0
== COMPLEX_TYPE
)
3620 (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
|| code1
== COMPLEX_TYPE
))
3622 int none_complex
= (code0
!= COMPLEX_TYPE
&& code1
!= COMPLEX_TYPE
);
3624 if (shorten
|| common
|| short_compare
)
3625 result_type
= common_type (type0
, type1
);
3627 /* For certain operations (which identify themselves by shorten != 0)
3628 if both args were extended from the same smaller type,
3629 do the arithmetic in that type and then extend.
3631 shorten !=0 and !=1 indicates a bitwise operation.
3632 For them, this optimization is safe only if
3633 both args are zero-extended or both are sign-extended.
3634 Otherwise, we might change the result.
3635 Eg, (short)-1 | (unsigned short)-1 is (int)-1
3636 but calculated in (unsigned short) it would be (unsigned short)-1. */
3638 if (shorten
&& none_complex
)
3640 int unsigned0
, unsigned1
;
3641 tree arg0
= get_narrower (op0
, &unsigned0
);
3642 tree arg1
= get_narrower (op1
, &unsigned1
);
3643 /* UNS is 1 if the operation to be done is an unsigned one. */
3644 int uns
= TREE_UNSIGNED (result_type
);
3647 final_type
= result_type
;
3649 /* Handle the case that OP0 does not *contain* a conversion
3650 but it *requires* conversion to FINAL_TYPE. */
3652 if (op0
== arg0
&& TREE_TYPE (op0
) != final_type
)
3653 unsigned0
= TREE_UNSIGNED (TREE_TYPE (op0
));
3654 if (op1
== arg1
&& TREE_TYPE (op1
) != final_type
)
3655 unsigned1
= TREE_UNSIGNED (TREE_TYPE (op1
));
3657 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
3659 /* For bitwise operations, signedness of nominal type
3660 does not matter. Consider only how operands were extended. */
3664 /* Note that in all three cases below we refrain from optimizing
3665 an unsigned operation on sign-extended args.
3666 That would not be valid. */
3668 /* Both args variable: if both extended in same way
3669 from same width, do it in that width.
3670 Do it unsigned if args were zero-extended. */
3671 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
3672 < TYPE_PRECISION (result_type
))
3673 && (TYPE_PRECISION (TREE_TYPE (arg1
))
3674 == TYPE_PRECISION (TREE_TYPE (arg0
)))
3675 && unsigned0
== unsigned1
3676 && (unsigned0
|| !uns
))
3678 = signed_or_unsigned_type (unsigned0
,
3679 common_type (TREE_TYPE (arg0
),
3681 else if (TREE_CODE (arg0
) == INTEGER_CST
3682 && (unsigned1
|| !uns
)
3683 && (TYPE_PRECISION (TREE_TYPE (arg1
))
3684 < TYPE_PRECISION (result_type
))
3685 && (type
= signed_or_unsigned_type (unsigned1
,
3687 int_fits_type_p (arg0
, type
)))
3689 else if (TREE_CODE (arg1
) == INTEGER_CST
3690 && (unsigned0
|| !uns
)
3691 && (TYPE_PRECISION (TREE_TYPE (arg0
))
3692 < TYPE_PRECISION (result_type
))
3693 && (type
= signed_or_unsigned_type (unsigned0
,
3695 int_fits_type_p (arg1
, type
)))
3699 /* Shifts can be shortened if shifting right. */
3704 tree arg0
= get_narrower (op0
, &unsigned_arg
);
3706 final_type
= result_type
;
3708 if (arg0
== op0
&& final_type
== TREE_TYPE (op0
))
3709 unsigned_arg
= TREE_UNSIGNED (TREE_TYPE (op0
));
3711 if (TYPE_PRECISION (TREE_TYPE (arg0
)) < TYPE_PRECISION (result_type
)
3712 /* We can shorten only if the shift count is less than the
3713 number of bits in the smaller type size. */
3714 && TREE_INT_CST_HIGH (op1
) == 0
3715 && TYPE_PRECISION (TREE_TYPE (arg0
)) > TREE_INT_CST_LOW (op1
)
3716 /* If arg is sign-extended and then unsigned-shifted,
3717 we can simulate this with a signed shift in arg's type
3718 only if the extended result is at least twice as wide
3719 as the arg. Otherwise, the shift could use up all the
3720 ones made by sign-extension and bring in zeros.
3721 We can't optimize that case at all, but in most machines
3722 it never happens because available widths are 2**N. */
3723 && (!TREE_UNSIGNED (final_type
)
3725 || (((unsigned) 2 * TYPE_PRECISION (TREE_TYPE (arg0
)))
3726 <= TYPE_PRECISION (result_type
))))
3728 /* Do an unsigned shift if the operand was zero-extended. */
3730 = signed_or_unsigned_type (unsigned_arg
,
3732 /* Convert value-to-be-shifted to that type. */
3733 if (TREE_TYPE (op0
) != result_type
)
3734 op0
= cp_convert (result_type
, op0
);
3739 /* Comparison operations are shortened too but differently.
3740 They identify themselves by setting short_compare = 1. */
3744 /* Don't write &op0, etc., because that would prevent op0
3745 from being kept in a register.
3746 Instead, make copies of the our local variables and
3747 pass the copies by reference, then copy them back afterward. */
3748 tree xop0
= op0
, xop1
= op1
, xresult_type
= result_type
;
3749 enum tree_code xresultcode
= resultcode
;
3751 = shorten_compare (&xop0
, &xop1
, &xresult_type
, &xresultcode
);
3753 return cp_convert (boolean_type_node
, val
);
3754 op0
= xop0
, op1
= xop1
;
3756 resultcode
= xresultcode
;
3759 if (short_compare
&& warn_sign_compare
)
3761 int op0_signed
= ! TREE_UNSIGNED (TREE_TYPE (orig_op0
));
3762 int op1_signed
= ! TREE_UNSIGNED (TREE_TYPE (orig_op1
));
3764 int unsignedp0
, unsignedp1
;
3765 tree primop0
= get_narrower (op0
, &unsignedp0
);
3766 tree primop1
= get_narrower (op1
, &unsignedp1
);
3768 /* Check for comparison of different enum types. */
3769 if (flag_int_enum_equivalence
== 0
3770 && TREE_CODE (TREE_TYPE (orig_op0
)) == ENUMERAL_TYPE
3771 && TREE_CODE (TREE_TYPE (orig_op1
)) == ENUMERAL_TYPE
3772 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0
))
3773 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1
)))
3775 cp_warning ("comparison between `%#T' and `%#T'",
3776 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
));
3779 /* Give warnings for comparisons between signed and unsigned
3780 quantities that may fail. */
3781 /* Do the checking based on the original operand trees, so that
3782 casts will be considered, but default promotions won't be. */
3784 /* Do not warn if the comparison is being done in a signed type,
3785 since the signed type will only be chosen if it can represent
3786 all the values of the unsigned type. */
3787 if (! TREE_UNSIGNED (result_type
))
3789 /* Do not warn if both operands are unsigned. */
3790 else if (op0_signed
== op1_signed
)
3792 /* Do not warn if the signed quantity is an unsuffixed
3793 integer literal (or some static constant expression
3794 involving such literals) and it is non-negative. */
3795 else if ((op0_signed
&& TREE_CODE (orig_op0
) == INTEGER_CST
3796 && tree_int_cst_sgn (orig_op0
) >= 0)
3797 || (op1_signed
&& TREE_CODE (orig_op1
) == INTEGER_CST
3798 && tree_int_cst_sgn (orig_op1
) >= 0))
3800 /* Do not warn if the comparison is an equality operation,
3801 the unsigned quantity is an integral constant and it does
3802 not use the most significant bit of result_type. */
3803 else if ((resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
3804 && ((op0_signed
&& TREE_CODE (orig_op1
) == INTEGER_CST
3805 && int_fits_type_p (orig_op1
,
3806 signed_type (result_type
)))
3807 || (op1_signed
&& TREE_CODE (orig_op0
) == INTEGER_CST
3808 && int_fits_type_p (orig_op0
,
3809 signed_type (result_type
)))))
3812 warning ("comparison between signed and unsigned");
3814 /* Warn if two unsigned values are being compared in a size
3815 larger than their original size, and one (and only one) is the
3816 result of a `~' operator. This comparison will always fail.
3818 Also warn if one operand is a constant, and the constant does not
3819 have all bits set that are set in the ~ operand when it is
3822 if ((TREE_CODE (primop0
) == BIT_NOT_EXPR
)
3823 ^ (TREE_CODE (primop1
) == BIT_NOT_EXPR
))
3825 if (TREE_CODE (primop0
) == BIT_NOT_EXPR
)
3826 primop0
= get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
3827 if (TREE_CODE (primop1
) == BIT_NOT_EXPR
)
3828 primop1
= get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
3830 if (TREE_CODE (primop0
) == INTEGER_CST
3831 || TREE_CODE (primop1
) == INTEGER_CST
)
3834 HOST_WIDE_INT constant
, mask
;
3838 if (TREE_CODE (primop0
) == INTEGER_CST
)
3841 unsignedp
= unsignedp1
;
3842 constant
= TREE_INT_CST_LOW (primop0
);
3847 unsignedp
= unsignedp0
;
3848 constant
= TREE_INT_CST_LOW (primop1
);
3851 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
3852 if (bits
< TYPE_PRECISION (result_type
)
3853 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
3855 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
3856 if ((mask
& constant
) != mask
)
3857 warning ("comparison of promoted ~unsigned with constant");
3860 else if (unsignedp0
&& unsignedp1
3861 && (TYPE_PRECISION (TREE_TYPE (primop0
))
3862 < TYPE_PRECISION (result_type
))
3863 && (TYPE_PRECISION (TREE_TYPE (primop1
))
3864 < TYPE_PRECISION (result_type
)))
3865 warning ("comparison of promoted ~unsigned with unsigned");
3870 /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
3871 If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
3872 Then the expression will be built.
3873 It will be given type FINAL_TYPE if that is nonzero;
3874 otherwise, it will be given type RESULT_TYPE. */
3878 cp_error ("invalid operands `%T' and `%T' to binary `%O'",
3879 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
), error_code
);
3880 return error_mark_node
;
3885 if (TREE_TYPE (op0
) != result_type
)
3886 op0
= cp_convert (result_type
, op0
);
3887 if (TREE_TYPE (op1
) != result_type
)
3888 op1
= cp_convert (result_type
, op1
);
3891 if (build_type
== NULL_TREE
)
3892 build_type
= result_type
;
3895 register tree result
= build (resultcode
, build_type
, op0
, op1
);
3896 register tree folded
;
3898 folded
= fold (result
);
3899 if (folded
== result
)
3900 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
3901 if (final_type
!= 0)
3902 return cp_convert (final_type
, folded
);
3907 /* Return a tree for the sum or difference (RESULTCODE says which)
3908 of pointer PTROP and integer INTOP. */
3911 pointer_int_sum (resultcode
, ptrop
, intop
)
3912 enum tree_code resultcode
;
3913 register tree ptrop
, intop
;
3917 register tree result
;
3918 register tree folded
= fold (intop
);
3920 /* The result is a pointer of the same type that is being added. */
3922 register tree result_type
= TREE_TYPE (ptrop
);
3924 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
3926 if (pedantic
|| warn_pointer_arith
)
3927 pedwarn ("ANSI C++ forbids using pointer of type `void *' in arithmetic");
3928 size_exp
= integer_one_node
;
3930 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
3932 if (pedantic
|| warn_pointer_arith
)
3933 pedwarn ("ANSI C++ forbids using pointer to a function in arithmetic");
3934 size_exp
= integer_one_node
;
3936 else if (TREE_CODE (TREE_TYPE (result_type
)) == METHOD_TYPE
)
3938 if (pedantic
|| warn_pointer_arith
)
3939 pedwarn ("ANSI C++ forbids using pointer to a method in arithmetic");
3940 size_exp
= integer_one_node
;
3942 else if (TREE_CODE (TREE_TYPE (result_type
)) == OFFSET_TYPE
)
3944 if (pedantic
|| warn_pointer_arith
)
3945 pedwarn ("ANSI C++ forbids using pointer to a member in arithmetic");
3946 size_exp
= integer_one_node
;
3949 size_exp
= size_in_bytes (complete_type (TREE_TYPE (result_type
)));
3951 /* Needed to make OOPS V2R3 work. */
3953 if (TREE_CODE (intop
) == INTEGER_CST
3954 && TREE_INT_CST_LOW (intop
) == 0
3955 && TREE_INT_CST_HIGH (intop
) == 0)
3958 /* If what we are about to multiply by the size of the elements
3959 contains a constant term, apply distributive law
3960 and multiply that constant term separately.
3961 This helps produce common subexpressions. */
3963 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
3964 && ! TREE_CONSTANT (intop
)
3965 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
3966 && TREE_CONSTANT (size_exp
))
3968 enum tree_code subcode
= resultcode
;
3969 if (TREE_CODE (intop
) == MINUS_EXPR
)
3970 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
3971 ptrop
= build_binary_op (subcode
, ptrop
, TREE_OPERAND (intop
, 1), 1);
3972 intop
= TREE_OPERAND (intop
, 0);
3975 /* Convert the integer argument to a type the same size as sizetype
3976 so the multiply won't overflow spuriously. */
3978 if (TYPE_PRECISION (TREE_TYPE (intop
)) != TYPE_PRECISION (sizetype
))
3979 intop
= cp_convert (type_for_size (TYPE_PRECISION (sizetype
), 0), intop
);
3981 /* Replace the integer argument with a suitable product by the object size.
3982 Do this multiplication as signed, then convert to the appropriate
3983 pointer type (actually unsigned integral). */
3985 intop
= cp_convert (result_type
,
3986 build_binary_op (MULT_EXPR
, intop
,
3987 cp_convert (TREE_TYPE (intop
),
3991 /* Create the sum or difference. */
3993 result
= build (resultcode
, result_type
, ptrop
, intop
);
3995 folded
= fold (result
);
3996 if (folded
== result
)
3997 TREE_CONSTANT (folded
) = TREE_CONSTANT (ptrop
) & TREE_CONSTANT (intop
);
4001 /* Return a tree for the difference of pointers OP0 and OP1.
4002 The resulting tree has type int. */
4005 pointer_diff (op0
, op1
, ptrtype
)
4006 register tree op0
, op1
;
4007 register tree ptrtype
;
4009 register tree result
, folded
;
4010 tree restype
= ptrdiff_type_node
;
4011 tree target_type
= TREE_TYPE (ptrtype
);
4013 if (pedantic
|| warn_pointer_arith
)
4015 if (TREE_CODE (target_type
) == VOID_TYPE
)
4016 pedwarn ("ANSI C++ forbids using pointer of type `void *' in subtraction");
4017 if (TREE_CODE (target_type
) == FUNCTION_TYPE
)
4018 pedwarn ("ANSI C++ forbids using pointer to a function in subtraction");
4019 if (TREE_CODE (target_type
) == METHOD_TYPE
)
4020 pedwarn ("ANSI C++ forbids using pointer to a method in subtraction");
4021 if (TREE_CODE (target_type
) == OFFSET_TYPE
)
4022 pedwarn ("ANSI C++ forbids using pointer to a member in subtraction");
4025 /* First do the subtraction as integers;
4026 then drop through to build the divide operator. */
4028 op0
= build_binary_op (MINUS_EXPR
, cp_convert (restype
, op0
),
4029 cp_convert (restype
, op1
), 1);
4031 /* This generates an error if op1 is a pointer to an incomplete type. */
4032 if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1
))) == 0)
4033 error ("arithmetic on pointer to an incomplete type");
4035 op1
= ((TREE_CODE (target_type
) == VOID_TYPE
4036 || TREE_CODE (target_type
) == FUNCTION_TYPE
4037 || TREE_CODE (target_type
) == METHOD_TYPE
4038 || TREE_CODE (target_type
) == OFFSET_TYPE
)
4040 : size_in_bytes (target_type
));
4042 /* Do the division. */
4044 result
= build (EXACT_DIV_EXPR
, restype
, op0
, cp_convert (restype
, op1
));
4046 folded
= fold (result
);
4047 if (folded
== result
)
4048 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
4052 /* Handle the case of taking the address of a COMPONENT_REF.
4053 Called by `build_unary_op' and `build_up_reference'.
4055 ARG is the COMPONENT_REF whose address we want.
4056 ARGTYPE is the pointer type that this address should have.
4057 MSG is an error message to print if this COMPONENT_REF is not
4058 addressable (such as a bitfield). */
4061 build_component_addr (arg
, argtype
, msg
)
4065 tree field
= TREE_OPERAND (arg
, 1);
4066 tree basetype
= decl_type_context (field
);
4067 tree rval
= build_unary_op (ADDR_EXPR
, TREE_OPERAND (arg
, 0), 0);
4069 if (DECL_BIT_FIELD (field
))
4071 error (msg
, IDENTIFIER_POINTER (DECL_NAME (field
)));
4072 return error_mark_node
;
4075 if (TREE_CODE (field
) == FIELD_DECL
4076 && TYPE_USES_COMPLEX_INHERITANCE (basetype
))
4078 /* Can't convert directly to ARGTYPE, since that
4079 may have the same pointer type as one of our
4081 rval
= build1 (NOP_EXPR
, argtype
,
4082 convert_pointer_to (basetype
, rval
));
4083 TREE_CONSTANT (rval
) = TREE_CONSTANT (TREE_OPERAND (rval
, 0));
4086 /* This conversion is harmless. */
4087 rval
= convert_force (argtype
, rval
, 0);
4089 if (! integer_zerop (DECL_FIELD_BITPOS (field
)))
4091 tree offset
= size_binop (EASY_DIV_EXPR
, DECL_FIELD_BITPOS (field
),
4092 size_int (BITS_PER_UNIT
));
4093 int flag
= TREE_CONSTANT (rval
);
4094 offset
= convert (sizetype
, offset
);
4095 rval
= fold (build (PLUS_EXPR
, argtype
,
4096 rval
, cp_convert (argtype
, offset
)));
4097 TREE_CONSTANT (rval
) = flag
;
4102 /* Construct and perhaps optimize a tree representation
4103 for a unary operation. CODE, a tree_code, specifies the operation
4104 and XARG is the operand. */
4107 build_x_unary_op (code
, xarg
)
4108 enum tree_code code
;
4111 if (processing_template_decl
)
4112 return build_min_nt (code
, xarg
, NULL_TREE
);
4114 /* & rec, on incomplete RECORD_TYPEs is the simple opr &, not an
4116 if (code
== ADDR_EXPR
4117 && TREE_CODE (xarg
) != TEMPLATE_ID_EXPR
4118 && ((IS_AGGR_TYPE_CODE (TREE_CODE (TREE_TYPE (xarg
)))
4119 && TYPE_SIZE (TREE_TYPE (xarg
)) == NULL_TREE
)
4120 || (TREE_CODE (xarg
) == OFFSET_REF
)))
4121 /* don't look for a function */;
4126 rval
= build_new_op (code
, LOOKUP_NORMAL
, xarg
,
4127 NULL_TREE
, NULL_TREE
);
4128 if (rval
|| code
!= ADDR_EXPR
)
4132 if (code
== ADDR_EXPR
)
4134 if (TREE_CODE (xarg
) == TARGET_EXPR
)
4135 warning ("taking address of temporary");
4138 return build_unary_op (code
, xarg
, 0);
4141 /* Just like truthvalue_conversion, but we want a CLEANUP_POINT_EXPR. */
4144 condition_conversion (expr
)
4148 if (processing_template_decl
)
4150 t
= cp_convert (boolean_type_node
, expr
);
4151 t
= fold (build1 (CLEANUP_POINT_EXPR
, boolean_type_node
, t
));
4155 /* C++: Must handle pointers to members.
4157 Perhaps type instantiation should be extended to handle conversion
4158 from aggregates to types we don't yet know we want? (Or are those
4159 cases typically errors which should be reported?)
4161 NOCONVERT nonzero suppresses the default promotions
4162 (such as from short to int). */
4165 build_unary_op (code
, xarg
, noconvert
)
4166 enum tree_code code
;
4170 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
4171 register tree arg
= xarg
;
4172 register tree argtype
= 0;
4173 char *errstring
= NULL
;
4176 if (arg
== error_mark_node
)
4177 return error_mark_node
;
4182 /* This is used for unary plus, because a CONVERT_EXPR
4183 is enough to prevent anybody from looking inside for
4184 associativity, but won't generate any code. */
4185 if (!(arg
= build_expr_type_conversion
4186 (WANT_ARITH
| WANT_ENUM
| WANT_POINTER
, arg
, 1)))
4187 errstring
= "wrong type argument to unary plus";
4191 arg
= default_conversion (arg
);
4192 arg
= build1 (NON_LVALUE_EXPR
, TREE_TYPE (arg
), arg
);
4197 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
4198 errstring
= "wrong type argument to unary minus";
4199 else if (!noconvert
)
4200 arg
= default_conversion (arg
);
4204 if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
4208 arg
= default_conversion (arg
);
4210 else if (!(arg
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
,
4212 errstring
= "wrong type argument to bit-complement";
4213 else if (!noconvert
)
4214 arg
= default_conversion (arg
);
4218 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
4219 errstring
= "wrong type argument to abs";
4220 else if (!noconvert
)
4221 arg
= default_conversion (arg
);
4225 /* Conjugating a real value is a no-op, but allow it anyway. */
4226 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
4227 errstring
= "wrong type argument to conjugation";
4228 else if (!noconvert
)
4229 arg
= default_conversion (arg
);
4232 case TRUTH_NOT_EXPR
:
4233 arg
= cp_convert (boolean_type_node
, arg
);
4234 val
= invert_truthvalue (arg
);
4235 if (arg
!= error_mark_node
)
4237 errstring
= "in argument to unary !";
4244 if (TREE_CODE (arg
) == COMPLEX_CST
)
4245 return TREE_REALPART (arg
);
4246 else if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
4247 return fold (build1 (REALPART_EXPR
, TREE_TYPE (TREE_TYPE (arg
)), arg
));
4252 if (TREE_CODE (arg
) == COMPLEX_CST
)
4253 return TREE_IMAGPART (arg
);
4254 else if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
4255 return fold (build1 (IMAGPART_EXPR
, TREE_TYPE (TREE_TYPE (arg
)), arg
));
4257 return cp_convert (TREE_TYPE (arg
), integer_zero_node
);
4259 case PREINCREMENT_EXPR
:
4260 case POSTINCREMENT_EXPR
:
4261 case PREDECREMENT_EXPR
:
4262 case POSTDECREMENT_EXPR
:
4263 /* Handle complex lvalues (when permitted)
4264 by reduction to simpler cases. */
4266 val
= unary_complex_lvalue (code
, arg
);
4270 /* Increment or decrement the real part of the value,
4271 and don't change the imaginary part. */
4272 if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
4276 arg
= stabilize_reference (arg
);
4277 real
= build_unary_op (REALPART_EXPR
, arg
, 1);
4278 imag
= build_unary_op (IMAGPART_EXPR
, arg
, 1);
4279 return build (COMPLEX_EXPR
, TREE_TYPE (arg
),
4280 build_unary_op (code
, real
, 1), imag
);
4283 /* Report invalid types. */
4285 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_POINTER
,
4288 if (code
== PREINCREMENT_EXPR
)
4289 errstring
="no pre-increment operator for type";
4290 else if (code
== POSTINCREMENT_EXPR
)
4291 errstring
="no post-increment operator for type";
4292 else if (code
== PREDECREMENT_EXPR
)
4293 errstring
="no pre-decrement operator for type";
4295 errstring
="no post-decrement operator for type";
4299 /* Report something read-only. */
4301 if (TYPE_READONLY (TREE_TYPE (arg
))
4302 || TREE_READONLY (arg
))
4303 readonly_error (arg
, ((code
== PREINCREMENT_EXPR
4304 || code
== POSTINCREMENT_EXPR
)
4305 ? "increment" : "decrement"),
4310 tree result_type
= TREE_TYPE (arg
);
4312 arg
= get_unwidened (arg
, 0);
4313 argtype
= TREE_TYPE (arg
);
4315 /* ARM $5.2.5 last annotation says this should be forbidden. */
4316 if (TREE_CODE (argtype
) == ENUMERAL_TYPE
)
4317 pedwarn ("ANSI C++ forbids %sing an enum",
4318 (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
4319 ? "increment" : "decrement");
4321 /* Compute the increment. */
4323 if (TREE_CODE (argtype
) == POINTER_TYPE
)
4325 enum tree_code tmp
= TREE_CODE (TREE_TYPE (argtype
));
4326 if (TYPE_SIZE (complete_type (TREE_TYPE (argtype
))) == 0)
4327 cp_error ("cannot %s a pointer to incomplete type `%T'",
4328 ((code
== PREINCREMENT_EXPR
4329 || code
== POSTINCREMENT_EXPR
)
4330 ? "increment" : "decrement"), TREE_TYPE (argtype
));
4331 else if ((pedantic
|| warn_pointer_arith
)
4332 && (tmp
== FUNCTION_TYPE
|| tmp
== METHOD_TYPE
4333 || tmp
== VOID_TYPE
|| tmp
== OFFSET_TYPE
))
4334 cp_pedwarn ("ANSI C++ forbids %sing a pointer of type `%T'",
4335 ((code
== PREINCREMENT_EXPR
4336 || code
== POSTINCREMENT_EXPR
)
4337 ? "increment" : "decrement"), argtype
);
4338 inc
= c_sizeof_nowarn (TREE_TYPE (argtype
));
4341 inc
= integer_one_node
;
4343 inc
= cp_convert (argtype
, inc
);
4345 /* Handle incrementing a cast-expression. */
4347 switch (TREE_CODE (arg
))
4352 case FIX_TRUNC_EXPR
:
4353 case FIX_FLOOR_EXPR
:
4354 case FIX_ROUND_EXPR
:
4357 tree incremented
, modify
, value
, compound
;
4358 if (! lvalue_p (arg
) && pedantic
)
4359 pedwarn ("cast to non-reference type used as lvalue");
4360 arg
= stabilize_reference (arg
);
4361 if (code
== PREINCREMENT_EXPR
|| code
== PREDECREMENT_EXPR
)
4364 value
= save_expr (arg
);
4365 incremented
= build (((code
== PREINCREMENT_EXPR
4366 || code
== POSTINCREMENT_EXPR
)
4367 ? PLUS_EXPR
: MINUS_EXPR
),
4368 argtype
, value
, inc
);
4369 TREE_SIDE_EFFECTS (incremented
) = 1;
4371 modify
= build_modify_expr (arg
, NOP_EXPR
, incremented
);
4372 compound
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), modify
, value
);
4374 /* Eliminate warning about unused result of + or -. */
4375 TREE_NO_UNUSED_WARNING (compound
) = 1;
4383 /* Complain about anything else that is not a true lvalue. */
4384 if (!lvalue_or_else (arg
, ((code
== PREINCREMENT_EXPR
4385 || code
== POSTINCREMENT_EXPR
)
4386 ? "increment" : "decrement")))
4387 return error_mark_node
;
4389 /* Forbid using -- on `bool'. */
4390 if (TREE_TYPE (arg
) == boolean_type_node
)
4392 if (code
== POSTDECREMENT_EXPR
|| code
== PREDECREMENT_EXPR
)
4394 cp_error ("invalid use of `--' on bool variable `%D'", arg
);
4395 return error_mark_node
;
4398 /* This will only work if someone can convince Kenner to accept
4399 my patch to expand_increment. (jason) */
4400 val
= build (code
, TREE_TYPE (arg
), arg
, inc
);
4402 if (code
== POSTINCREMENT_EXPR
)
4404 arg
= stabilize_reference (arg
);
4405 val
= build (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
4407 TREE_SIDE_EFFECTS (val
) = 1;
4408 arg
= save_expr (arg
);
4409 val
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
4410 val
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
4413 val
= build (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
4418 val
= build (code
, TREE_TYPE (arg
), arg
, inc
);
4420 TREE_SIDE_EFFECTS (val
) = 1;
4421 return cp_convert (result_type
, val
);
4425 /* Note that this operation never does default_conversion
4426 regardless of NOCONVERT. */
4428 argtype
= TREE_TYPE (arg
);
4429 if (TREE_CODE (argtype
) == REFERENCE_TYPE
)
4433 build_pointer_type (TREE_TYPE (TREE_TYPE (arg
))), arg
);
4434 TREE_CONSTANT (arg
) = TREE_CONSTANT (TREE_OPERAND (arg
, 0));
4438 && TREE_CODE (arg
) == FUNCTION_DECL
4440 && DECL_CONTEXT (arg
) == NULL_TREE
4441 && IDENTIFIER_LENGTH (DECL_NAME (arg
)) == 4
4442 && IDENTIFIER_POINTER (DECL_NAME (arg
))[0] == 'm'
4443 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (arg
)), "main"))
4445 pedwarn ("taking address of function `main'");
4447 /* Let &* cancel out to simplify resulting code. */
4448 if (TREE_CODE (arg
) == INDIRECT_REF
)
4450 /* We don't need to have `current_class_ptr' wrapped in a
4451 NON_LVALUE_EXPR node. */
4452 if (arg
== current_class_ref
)
4453 return current_class_ptr
;
4455 arg
= TREE_OPERAND (arg
, 0);
4456 if (TREE_CODE (TREE_TYPE (arg
)) == REFERENCE_TYPE
)
4460 build_pointer_type (TREE_TYPE (TREE_TYPE (arg
))), arg
);
4461 TREE_CONSTANT (arg
) = TREE_CONSTANT (TREE_OPERAND (arg
, 0));
4463 else if (lvalue_p (arg
))
4464 /* Don't let this be an lvalue. */
4465 return non_lvalue (arg
);
4469 /* For &x[y], return x+y */
4470 if (TREE_CODE (arg
) == ARRAY_REF
)
4472 if (mark_addressable (TREE_OPERAND (arg
, 0)) == 0)
4473 return error_mark_node
;
4474 return build_binary_op (PLUS_EXPR
, TREE_OPERAND (arg
, 0),
4475 TREE_OPERAND (arg
, 1), 1);
4478 /* Uninstantiated types are all functions. Taking the
4479 address of a function is a no-op, so just return the
4482 if (TREE_CODE (arg
) == IDENTIFIER_NODE
4483 && IDENTIFIER_OPNAME_P (arg
))
4485 my_friendly_abort (117);
4486 /* We don't know the type yet, so just work around the problem.
4487 We know that this will resolve to an lvalue. */
4488 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4491 if (TREE_CODE (arg
) == TREE_LIST
)
4493 if (TREE_CODE (TREE_VALUE (arg
)) == FUNCTION_DECL
4494 && DECL_CHAIN (TREE_VALUE (arg
)) == NULL_TREE
)
4495 /* Unique overloaded non-member function. */
4496 return build_unary_op (ADDR_EXPR
, TREE_VALUE (arg
), 0);
4497 if (TREE_CHAIN (arg
) == NULL_TREE
4498 && TREE_CODE (TREE_VALUE (arg
)) == TREE_LIST
4499 && DECL_CHAIN (TREE_VALUE (TREE_VALUE (arg
))) == NULL_TREE
)
4500 /* Unique overloaded member function. */
4501 return build_unary_op (ADDR_EXPR
, TREE_VALUE (TREE_VALUE (arg
)),
4503 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4505 else if (TREE_CODE (arg
) == TEMPLATE_ID_EXPR
)
4510 /* We don't require a match here; it's possible that the
4511 context (like a cast to a particular type) will resolve
4512 the particular choice of template. */
4513 fn
= determine_specialization (arg
,
4521 fn
= instantiate_template (fn
, targs
);
4522 mark_addressable (fn
);
4523 return build_unary_op (ADDR_EXPR
, fn
, 0);
4526 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4529 /* Handle complex lvalues (when permitted)
4530 by reduction to simpler cases. */
4531 val
= unary_complex_lvalue (code
, arg
);
4535 switch (TREE_CODE (arg
))
4540 case FIX_TRUNC_EXPR
:
4541 case FIX_FLOOR_EXPR
:
4542 case FIX_ROUND_EXPR
:
4544 if (! lvalue_p (arg
) && pedantic
)
4545 pedwarn ("taking the address of a cast to non-reference type");
4552 /* Allow the address of a constructor if all the elements
4554 if (TREE_CODE (arg
) == CONSTRUCTOR
&& TREE_HAS_CONSTRUCTOR (arg
)
4555 && TREE_CONSTANT (arg
))
4557 /* Anything not already handled and not a true memory reference
4559 else if (TREE_CODE (argtype
) != FUNCTION_TYPE
4560 && TREE_CODE (argtype
) != METHOD_TYPE
4561 && !lvalue_or_else (arg
, "unary `&'"))
4562 return error_mark_node
;
4564 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
4565 /* If the lvalue is const or volatile,
4566 merge that into the type that the address will point to. */
4567 if (TREE_CODE_CLASS (TREE_CODE (arg
)) == 'd'
4568 || TREE_CODE_CLASS (TREE_CODE (arg
)) == 'r')
4570 if (TREE_READONLY (arg
) || TREE_THIS_VOLATILE (arg
))
4571 argtype
= cp_build_type_variant (argtype
,
4572 TREE_READONLY (arg
),
4573 TREE_THIS_VOLATILE (arg
));
4576 argtype
= build_pointer_type (argtype
);
4578 if (mark_addressable (arg
) == 0)
4579 return error_mark_node
;
4584 if (TREE_CODE (arg
) == COMPONENT_REF
)
4585 addr
= build_component_addr
4587 "attempt to take address of bit-field structure member `%s'");
4589 addr
= build1 (code
, argtype
, arg
);
4591 /* Address of a static or external variable or
4592 function counts as a constant */
4594 TREE_CONSTANT (addr
) = 1;
4596 if (TREE_CODE (argtype
) == POINTER_TYPE
4597 && TREE_CODE (TREE_TYPE (argtype
)) == METHOD_TYPE
)
4599 build_ptrmemfunc_type (argtype
);
4600 addr
= build_ptrmemfunc (argtype
, addr
, 0);
4613 argtype
= TREE_TYPE (arg
);
4614 return fold (build1 (code
, argtype
, arg
));
4618 return error_mark_node
;
4622 /* If CONVERSIONS is a conversion expression or a nested sequence of such,
4623 convert ARG with the same conversions in the same order
4624 and return the result. */
4627 convert_sequence (conversions
, arg
)
4631 switch (TREE_CODE (conversions
))
4636 case FIX_TRUNC_EXPR
:
4637 case FIX_FLOOR_EXPR
:
4638 case FIX_ROUND_EXPR
:
4640 return cp_convert (TREE_TYPE (conversions
),
4641 convert_sequence (TREE_OPERAND (conversions
, 0),
4650 /* Apply unary lvalue-demanding operator CODE to the expression ARG
4651 for certain kinds of expressions which are not really lvalues
4652 but which we can accept as lvalues.
4654 If ARG is not a kind of expression we can handle, return zero. */
4657 unary_complex_lvalue (code
, arg
)
4658 enum tree_code code
;
4661 /* Handle (a, b) used as an "lvalue". */
4662 if (TREE_CODE (arg
) == COMPOUND_EXPR
)
4664 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 1), 0);
4665 return build (COMPOUND_EXPR
, TREE_TYPE (real_result
),
4666 TREE_OPERAND (arg
, 0), real_result
);
4669 /* Handle (a ? b : c) used as an "lvalue". */
4670 if (TREE_CODE (arg
) == COND_EXPR
4671 || TREE_CODE (arg
) == MIN_EXPR
|| TREE_CODE (arg
) == MAX_EXPR
)
4672 return rationalize_conditional_expr (code
, arg
);
4674 if (TREE_CODE (arg
) == MODIFY_EXPR
4675 || TREE_CODE (arg
) == PREINCREMENT_EXPR
4676 || TREE_CODE (arg
) == PREDECREMENT_EXPR
)
4677 return unary_complex_lvalue
4678 (code
, build (COMPOUND_EXPR
, TREE_TYPE (TREE_OPERAND (arg
, 0)),
4679 arg
, TREE_OPERAND (arg
, 0)));
4681 if (code
!= ADDR_EXPR
)
4684 /* Handle (a = b) used as an "lvalue" for `&'. */
4685 if (TREE_CODE (arg
) == MODIFY_EXPR
4686 || TREE_CODE (arg
) == INIT_EXPR
)
4688 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 0), 0);
4689 arg
= build (COMPOUND_EXPR
, TREE_TYPE (real_result
), arg
, real_result
);
4690 TREE_NO_UNUSED_WARNING (arg
) = 1;
4694 if (TREE_CODE (TREE_TYPE (arg
)) == FUNCTION_TYPE
4695 || TREE_CODE (TREE_TYPE (arg
)) == METHOD_TYPE
4696 || TREE_CODE (TREE_TYPE (arg
)) == OFFSET_TYPE
)
4698 /* The representation of something of type OFFSET_TYPE
4699 is really the representation of a pointer to it.
4700 Here give the representation its true type. */
4703 my_friendly_assert (TREE_CODE (arg
) != SCOPE_REF
, 313);
4705 if (TREE_CODE (arg
) != OFFSET_REF
)
4708 t
= TREE_OPERAND (arg
, 1);
4710 /* Check all this code for right semantics. */
4711 if (TREE_CODE (t
) == FUNCTION_DECL
)
4712 return build_unary_op (ADDR_EXPR
, t
, 0);
4713 if (TREE_CODE (t
) == VAR_DECL
)
4714 return build_unary_op (ADDR_EXPR
, t
, 0);
4720 if (TREE_OPERAND (arg
, 0)
4721 && (TREE_CODE (TREE_OPERAND (arg
, 0)) != NOP_EXPR
4722 || (TREE_OPERAND (TREE_OPERAND (arg
, 0), 0)
4723 != error_mark_node
)))
4724 if (TREE_CODE (t
) != FIELD_DECL
)
4726 /* Don't know if this should return address to just
4727 _DECL, or actual address resolved in this expression. */
4728 sorry ("address of bound pointer-to-member expression");
4729 return error_mark_node
;
4732 /* Add in the offset to the field. */
4733 offset
= convert (sizetype
,
4734 size_binop (EASY_DIV_EXPR
,
4735 DECL_FIELD_BITPOS (t
),
4736 size_int (BITS_PER_UNIT
)));
4738 /* We offset all pointer to data members by 1 so that we can
4739 distinguish between a null pointer to data member and the first
4740 data member of a structure. */
4741 offset
= size_binop (PLUS_EXPR
, offset
, size_int (1));
4743 type
= build_offset_type (DECL_FIELD_CONTEXT (t
), TREE_TYPE (t
));
4744 type
= build_pointer_type (type
);
4746 return cp_convert (type
, offset
);
4751 /* We permit compiler to make function calls returning
4752 objects of aggregate type look like lvalues. */
4756 if (TREE_CODE (targ
) == SAVE_EXPR
)
4757 targ
= TREE_OPERAND (targ
, 0);
4759 if (TREE_CODE (targ
) == CALL_EXPR
&& IS_AGGR_TYPE (TREE_TYPE (targ
)))
4761 if (TREE_CODE (arg
) == SAVE_EXPR
)
4764 targ
= build_cplus_new (TREE_TYPE (arg
), arg
);
4765 return build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (arg
)), targ
);
4768 if (TREE_CODE (arg
) == SAVE_EXPR
&& TREE_CODE (targ
) == INDIRECT_REF
)
4769 return build (SAVE_EXPR
, build_pointer_type (TREE_TYPE (arg
)),
4770 TREE_OPERAND (targ
, 0), current_function_decl
, NULL
);
4773 /* Don't let anything else be handled specially. */
4777 /* Mark EXP saying that we need to be able to take the
4778 address of it; it should not be allocated in a register.
4779 Value is 1 if successful.
4781 C++: we do not allow `current_class_ptr' to be addressable. */
4784 mark_addressable (exp
)
4787 register tree x
= exp
;
4789 if (TREE_ADDRESSABLE (x
) == 1)
4793 switch (TREE_CODE (x
))
4800 x
= TREE_OPERAND (x
, 0);
4804 if (x
== current_class_ptr
)
4806 if (! flag_this_is_variable
)
4807 error ("address of `this' not available");
4808 TREE_ADDRESSABLE (x
) = 1; /* so compiler doesn't die later */
4809 put_var_into_stack (x
);
4813 if (TREE_STATIC (x
) && TREE_READONLY (x
)
4814 && DECL_RTL (x
) != 0
4815 && ! DECL_IN_MEMORY_P (x
))
4817 /* We thought this would make a good constant variable,
4818 but we were wrong. */
4819 push_obstacks_nochange ();
4820 end_temporary_allocation ();
4822 TREE_ASM_WRITTEN (x
) = 0;
4824 rest_of_decl_compilation (x
, 0, IDENTIFIER_LOCAL_VALUE (x
) == 0,
4826 TREE_ADDRESSABLE (x
) = 1;
4832 /* Caller should not be trying to mark initialized
4833 constant fields addressable. */
4834 my_friendly_assert (DECL_LANG_SPECIFIC (x
) == 0
4835 || DECL_IN_AGGR_P (x
) == 0
4837 || DECL_EXTERNAL (x
), 314);
4841 if (DECL_REGISTER (x
) && !TREE_ADDRESSABLE (x
)
4842 && !DECL_ARTIFICIAL (x
) && extra_warnings
)
4843 cp_warning ("address requested for `%D', which is declared `register'",
4845 put_var_into_stack (x
);
4846 TREE_ADDRESSABLE (x
) = 1;
4850 if (DECL_LANG_SPECIFIC (x
) != 0)
4852 x
= DECL_MAIN_VARIANT (x
);
4853 /* We have to test both conditions here. The first may be
4854 non-zero in the case of processing a default function. The
4855 second may be non-zero in the case of a template function. */
4856 if (DECL_TEMPLATE_INFO (x
) && !DECL_TEMPLATE_SPECIALIZATION (x
))
4859 TREE_ADDRESSABLE (x
) = 1;
4861 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x
)) = 1;
4865 TREE_ADDRESSABLE (x
) = 1;
4869 TREE_ADDRESSABLE (x
) = 1;
4870 mark_addressable (TREE_OPERAND (x
, 0));
4878 /* Build and return a conditional expression IFEXP ? OP1 : OP2. */
4881 build_x_conditional_expr (ifexp
, op1
, op2
)
4882 tree ifexp
, op1
, op2
;
4884 if (processing_template_decl
)
4885 return build_min_nt (COND_EXPR
, ifexp
, op1
, op2
);
4887 return build_new_op (COND_EXPR
, LOOKUP_NORMAL
, ifexp
, op1
, op2
);
4891 build_conditional_expr (ifexp
, op1
, op2
)
4892 tree ifexp
, op1
, op2
;
4894 register tree type1
;
4895 register tree type2
;
4896 register enum tree_code code1
;
4897 register enum tree_code code2
;
4898 register tree result_type
= NULL_TREE
;
4900 /* If second operand is omitted, it is the same as the first one;
4901 make sure it is calculated only once. */
4905 pedwarn ("ANSI C++ forbids omitting the middle term of a ?: expression");
4906 ifexp
= op1
= save_expr (ifexp
);
4909 ifexp
= cp_convert (boolean_type_node
, ifexp
);
4911 if (TREE_CODE (ifexp
) == ERROR_MARK
)
4912 return error_mark_node
;
4914 op1
= require_instantiated_type (TREE_TYPE (op2
), op1
, error_mark_node
);
4915 if (op1
== error_mark_node
)
4916 return error_mark_node
;
4917 op2
= require_instantiated_type (TREE_TYPE (op1
), op2
, error_mark_node
);
4918 if (op2
== error_mark_node
)
4919 return error_mark_node
;
4921 /* C++: REFERENCE_TYPES must be dereferenced. */
4922 type1
= TREE_TYPE (op1
);
4923 code1
= TREE_CODE (type1
);
4924 type2
= TREE_TYPE (op2
);
4925 code2
= TREE_CODE (type2
);
4927 if (code1
== REFERENCE_TYPE
)
4929 op1
= convert_from_reference (op1
);
4930 type1
= TREE_TYPE (op1
);
4931 code1
= TREE_CODE (type1
);
4933 if (code2
== REFERENCE_TYPE
)
4935 op2
= convert_from_reference (op2
);
4936 type2
= TREE_TYPE (op2
);
4937 code2
= TREE_CODE (type2
);
4940 /* Don't promote the operands separately if they promote
4941 the same way. Return the unpromoted type and let the combined
4942 value get promoted if necessary. */
4944 if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
)
4945 && code2
!= ARRAY_TYPE
4946 && code2
!= FUNCTION_TYPE
4947 && code2
!= METHOD_TYPE
)
4951 if (TREE_CONSTANT (ifexp
)
4952 && (TREE_CODE (ifexp
) == INTEGER_CST
4953 || TREE_CODE (ifexp
) == ADDR_EXPR
))
4954 return (integer_zerop (ifexp
) ? op2
: op1
);
4956 if (TREE_CODE (op1
) == CONST_DECL
)
4957 op1
= DECL_INITIAL (op1
);
4958 else if (TREE_READONLY_DECL_P (op1
))
4959 op1
= decl_constant_value (op1
);
4960 if (TREE_CODE (op2
) == CONST_DECL
)
4961 op2
= DECL_INITIAL (op2
);
4962 else if (TREE_READONLY_DECL_P (op2
))
4963 op2
= decl_constant_value (op2
);
4965 type1
= cp_build_type_variant
4967 TREE_READONLY (op1
) || TREE_READONLY (op2
),
4968 TREE_THIS_VOLATILE (op1
) || TREE_THIS_VOLATILE (op2
));
4969 /* ??? This is a kludge to deal with the fact that
4970 we don't sort out integers and enums properly, yet. */
4971 result
= fold (build (COND_EXPR
, type1
, ifexp
, op1
, op2
));
4972 if (TREE_TYPE (result
) != type1
)
4973 result
= build1 (NOP_EXPR
, type1
, result
);
4974 /* Expand both sides into the same slot,
4975 hopefully the target of the ?: expression. */
4976 if (TREE_CODE (op1
) == TARGET_EXPR
&& TREE_CODE (op2
) == TARGET_EXPR
)
4978 tree slot
= build (VAR_DECL
, TREE_TYPE (result
));
4979 layout_decl (slot
, 0);
4980 result
= build (TARGET_EXPR
, TREE_TYPE (result
),
4981 slot
, result
, NULL_TREE
, NULL_TREE
);
4986 /* They don't match; promote them both and then try to reconcile them.
4987 But don't permit mismatching enum types. */
4988 if (code1
== ENUMERAL_TYPE
)
4990 if (code2
== ENUMERAL_TYPE
)
4992 cp_error ("enumeral mismatch in conditional expression: `%T' vs `%T'",
4994 return error_mark_node
;
4996 else if (extra_warnings
&& ! IS_AGGR_TYPE_CODE (code2
)
4997 && type2
!= type_promotes_to (type1
))
4998 warning ("enumeral and non-enumeral type in conditional expression");
5000 else if (extra_warnings
5001 && code2
== ENUMERAL_TYPE
&& ! IS_AGGR_TYPE_CODE (code1
)
5002 && type1
!= type_promotes_to (type2
))
5003 warning ("enumeral and non-enumeral type in conditional expression");
5005 if (code1
!= VOID_TYPE
)
5007 op1
= default_conversion (op1
);
5008 type1
= TREE_TYPE (op1
);
5009 if (TYPE_PTRMEMFUNC_P (type1
))
5010 type1
= TYPE_PTRMEMFUNC_FN_TYPE (type1
);
5011 code1
= TREE_CODE (type1
);
5013 if (code2
!= VOID_TYPE
)
5015 op2
= default_conversion (op2
);
5016 type2
= TREE_TYPE (op2
);
5017 if (TYPE_PTRMEMFUNC_P (type2
))
5018 type2
= TYPE_PTRMEMFUNC_FN_TYPE (type2
);
5019 code2
= TREE_CODE (type2
);
5022 if (code1
== RECORD_TYPE
&& code2
== RECORD_TYPE
5023 && real_lvalue_p (op1
) && real_lvalue_p (op2
)
5024 && comptypes (type1
, type2
, -1))
5026 type1
= build_reference_type (type1
);
5027 type2
= build_reference_type (type2
);
5028 result_type
= common_type (type1
, type2
);
5029 op1
= convert_to_reference (result_type
, op1
, CONV_IMPLICIT
,
5030 LOOKUP_NORMAL
, NULL_TREE
);
5031 op2
= convert_to_reference (result_type
, op2
, CONV_IMPLICIT
,
5032 LOOKUP_NORMAL
, NULL_TREE
);
5034 /* Quickly detect the usual case where op1 and op2 have the same type
5036 else if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
))
5039 result_type
= type1
;
5041 result_type
= cp_build_type_variant
5043 TREE_READONLY (op1
) || TREE_READONLY (op2
),
5044 TREE_THIS_VOLATILE (op1
) || TREE_THIS_VOLATILE (op2
));
5046 else if ((code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
)
5047 && (code2
== INTEGER_TYPE
|| code2
== REAL_TYPE
))
5049 result_type
= common_type (type1
, type2
);
5051 else if (code1
== VOID_TYPE
|| code2
== VOID_TYPE
)
5053 if (pedantic
&& (code1
!= VOID_TYPE
|| code2
!= VOID_TYPE
))
5054 pedwarn ("ANSI C++ forbids conditional expr with only one void side");
5055 result_type
= void_type_node
;
5057 else if (code1
== POINTER_TYPE
&& null_ptr_cst_p (op2
))
5058 result_type
= qualify_type (type1
, type2
);
5059 else if (code2
== POINTER_TYPE
&& null_ptr_cst_p (op1
))
5060 result_type
= qualify_type (type2
, type1
);
5061 else if (code1
== POINTER_TYPE
&& code2
== POINTER_TYPE
)
5063 if (comp_target_types (type1
, type2
, 1))
5064 result_type
= common_type (type1
, type2
);
5065 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1
)) == void_type_node
)
5067 if (pedantic
&& TREE_CODE (type2
) == FUNCTION_TYPE
)
5068 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
5069 result_type
= qualify_type (type1
, type2
);
5071 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2
)) == void_type_node
)
5073 if (pedantic
&& TREE_CODE (type1
) == FUNCTION_TYPE
)
5074 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
5075 result_type
= qualify_type (type2
, type1
);
5078 else if (comptypes (type2
, type1
, 0))
5079 result_type
= type2
;
5080 else if (IS_AGGR_TYPE (TREE_TYPE (type1
))
5081 && IS_AGGR_TYPE (TREE_TYPE (type2
))
5082 && (result_type
= common_base_type (TREE_TYPE (type1
),
5083 TREE_TYPE (type2
))))
5085 if (result_type
== error_mark_node
)
5087 cp_error ("common base type of types `%T' and `%T' is ambiguous",
5088 TREE_TYPE (type1
), TREE_TYPE (type2
));
5089 result_type
= ptr_type_node
;
5094 && result_type
!= TREE_TYPE (type1
)
5095 && result_type
!= TREE_TYPE (type2
))
5096 cp_pedwarn ("`%T' and `%T' converted to `%T *' in conditional expression",
5097 type1
, type2
, result_type
);
5099 result_type
= build_pointer_type (result_type
);
5104 pedwarn ("pointer type mismatch in conditional expression");
5105 result_type
= ptr_type_node
;
5108 else if (code1
== POINTER_TYPE
&& code2
== INTEGER_TYPE
)
5110 pedwarn ("pointer/integer type mismatch in conditional expression");
5111 result_type
= type1
;
5113 else if (code2
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
5115 pedwarn ("pointer/integer type mismatch in conditional expression");
5116 result_type
= type2
;
5121 /* The match does not look good. If either is
5122 an aggregate value, try converting to a scalar type. */
5123 if (code1
== RECORD_TYPE
&& code2
== RECORD_TYPE
)
5125 cp_error ("aggregate mismatch in conditional expression: `%T' vs `%T'",
5127 return error_mark_node
;
5129 /* Warning: this code assumes that conversion between cv-variants of
5130 a type is done using NOP_EXPRs. */
5131 if (code1
== RECORD_TYPE
&& TYPE_HAS_CONVERSION (type1
))
5133 /* There are other types besides pointers and records. */
5135 if (code2
== POINTER_TYPE
)
5136 tmp
= build_pointer_type
5137 (build_type_variant (TREE_TYPE (type2
), 1, 1));
5140 tmp
= build_type_conversion (CONVERT_EXPR
, tmp
, op1
, 0);
5141 if (tmp
== NULL_TREE
)
5143 cp_error ("incompatible types `%T' and `%T' in `?:'",
5145 return error_mark_node
;
5147 if (tmp
== error_mark_node
)
5148 error ("ambiguous pointer conversion");
5151 result_type
= common_type (type2
, TREE_TYPE (tmp
));
5154 else if (code2
== RECORD_TYPE
&& TYPE_HAS_CONVERSION (type2
))
5157 if (code1
== POINTER_TYPE
)
5158 tmp
= build_pointer_type
5159 (build_type_variant (TREE_TYPE (type1
), 1, 1));
5163 tmp
= build_type_conversion (CONVERT_EXPR
, tmp
, op2
, 0);
5164 if (tmp
== NULL_TREE
)
5166 cp_error ("incompatible types `%T' and `%T' in `?:'",
5168 return error_mark_node
;
5170 if (tmp
== error_mark_node
)
5171 error ("ambiguous pointer conversion");
5174 result_type
= common_type (type1
, TREE_TYPE (tmp
));
5177 else if (flag_cond_mismatch
)
5178 result_type
= void_type_node
;
5181 error ("type mismatch in conditional expression");
5182 return error_mark_node
;
5186 if (TREE_CODE (result_type
) == POINTER_TYPE
5187 && TREE_CODE (TREE_TYPE (result_type
)) == METHOD_TYPE
)
5188 result_type
= build_ptrmemfunc_type (result_type
);
5190 if (result_type
!= TREE_TYPE (op1
))
5191 op1
= convert_for_initialization
5192 (NULL_TREE
, result_type
, op1
, LOOKUP_NORMAL
, "converting", NULL_TREE
, 0);
5193 if (result_type
!= TREE_TYPE (op2
))
5194 op2
= convert_for_initialization
5195 (NULL_TREE
, result_type
, op2
, LOOKUP_NORMAL
, "converting", NULL_TREE
, 0);
5197 if (TREE_CONSTANT (ifexp
))
5198 return integer_zerop (ifexp
) ? op2
: op1
;
5200 return convert_from_reference
5201 (fold (build (COND_EXPR
, result_type
, ifexp
, op1
, op2
)));
5204 /* Handle overloading of the ',' operator when needed. Otherwise,
5205 this function just builds an expression list. */
5208 build_x_compound_expr (list
)
5211 tree rest
= TREE_CHAIN (list
);
5214 if (processing_template_decl
)
5215 return build_min_nt (COMPOUND_EXPR
, list
, NULL_TREE
);
5217 if (rest
== NULL_TREE
)
5218 return build_compound_expr (list
);
5220 result
= build_opfncall (COMPOUND_EXPR
, LOOKUP_NORMAL
,
5221 TREE_VALUE (list
), TREE_VALUE (rest
), NULL_TREE
);
5223 return build_x_compound_expr (expr_tree_cons (NULL_TREE
, result
,
5224 TREE_CHAIN (rest
)));
5226 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list
)))
5228 /* the left-hand operand of a comma expression is like an expression
5229 statement: we should warn if it doesn't have any side-effects,
5230 unless it was explicitly cast to (void). */
5231 if ((extra_warnings
|| warn_unused
)
5232 && !(TREE_CODE (TREE_VALUE(list
)) == CONVERT_EXPR
5233 && TREE_TYPE (TREE_VALUE(list
)) == void_type_node
))
5234 warning("left-hand operand of comma expression has no effect");
5236 #if 0 /* this requires a gcc backend patch to export warn_if_unused_value */
5237 else if (warn_unused
)
5238 warn_if_unused_value (TREE_VALUE(list
));
5241 return build_compound_expr
5242 (expr_tree_cons (NULL_TREE
, TREE_VALUE (list
),
5243 build_expr_list (NULL_TREE
,
5244 build_x_compound_expr (rest
))));
5247 /* Given a list of expressions, return a compound expression
5248 that performs them all and returns the value of the last of them. */
5251 build_compound_expr (list
)
5256 if (TREE_READONLY_DECL_P (TREE_VALUE (list
)))
5257 TREE_VALUE (list
) = decl_constant_value (TREE_VALUE (list
));
5259 if (TREE_CHAIN (list
) == 0)
5261 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5262 Strip such NOP_EXPRs, since LIST is used in non-lvalue context. */
5263 if (TREE_CODE (list
) == NOP_EXPR
5264 && TREE_TYPE (list
) == TREE_TYPE (TREE_OPERAND (list
, 0)))
5265 list
= TREE_OPERAND (list
, 0);
5267 /* Convert arrays to pointers. */
5268 if (TREE_CODE (TREE_TYPE (TREE_VALUE (list
))) == ARRAY_TYPE
)
5269 return default_conversion (TREE_VALUE (list
));
5271 return TREE_VALUE (list
);
5274 rest
= build_compound_expr (TREE_CHAIN (list
));
5276 /* When pedantic, a compound expression cannot be a constant expression. */
5277 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list
)) && ! pedantic
)
5280 return build (COMPOUND_EXPR
, TREE_TYPE (rest
),
5281 break_out_cleanups (TREE_VALUE (list
)), rest
);
5285 build_static_cast (type
, expr
)
5291 if (type
== error_mark_node
|| expr
== error_mark_node
)
5292 return error_mark_node
;
5294 if (TREE_CODE (expr
) == OFFSET_REF
)
5295 expr
= resolve_offset_ref (expr
);
5297 if (processing_template_decl
)
5299 tree t
= build_min (STATIC_CAST_EXPR
, copy_to_permanent (type
),
5304 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5305 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5306 if (TREE_CODE (type
) != REFERENCE_TYPE
5307 && TREE_CODE (expr
) == NOP_EXPR
5308 && TREE_TYPE (expr
) == TREE_TYPE (TREE_OPERAND (expr
, 0)))
5309 expr
= TREE_OPERAND (expr
, 0);
5311 if (TREE_CODE (type
) == VOID_TYPE
)
5312 return build1 (CONVERT_EXPR
, type
, expr
);
5314 if (type_unknown_p (expr
))
5316 expr
= instantiate_type (type
, expr
, 1);
5317 if (expr
== error_mark_node
)
5318 return error_mark_node
;
5321 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5322 return (convert_from_reference
5323 (convert_to_reference (type
, expr
, CONV_STATIC
|CONV_IMPLICIT
,
5324 LOOKUP_COMPLAIN
, NULL_TREE
)));
5326 if (IS_AGGR_TYPE (type
))
5327 return build_cplus_new
5328 (type
, (build_method_call
5329 (NULL_TREE
, ctor_identifier
, build_expr_list (NULL_TREE
, expr
),
5330 TYPE_BINFO (type
), LOOKUP_NORMAL
)));
5332 expr
= decay_conversion (expr
);
5333 intype
= TREE_TYPE (expr
);
5335 /* FIXME handle casting to array type. */
5338 if (can_convert_arg (type
, intype
, expr
))
5340 else if (TYPE_PTROB_P (type
) && TYPE_PTROB_P (intype
))
5343 if (IS_AGGR_TYPE (TREE_TYPE (type
)) && IS_AGGR_TYPE (TREE_TYPE (intype
))
5344 && (TYPE_READONLY (TREE_TYPE (type
))
5345 >= TYPE_READONLY (TREE_TYPE (intype
)))
5346 && (TYPE_VOLATILE (TREE_TYPE (type
))
5347 >= TYPE_VOLATILE (TREE_TYPE (intype
)))
5348 && (binfo
= get_binfo (TREE_TYPE (intype
), TREE_TYPE (type
), 0))
5349 && ! TREE_VIA_VIRTUAL (binfo
))
5352 else if (TYPE_PTRMEM_P (type
) && TYPE_PTRMEM_P (intype
))
5354 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
))),
5355 TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (intype
))), 1)
5356 && (TYPE_READONLY (TREE_TYPE (TREE_TYPE (type
)))
5357 >= TYPE_READONLY (TREE_TYPE (TREE_TYPE (intype
))))
5358 && (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (type
)))
5359 >= TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (intype
))))
5360 && (binfo
= get_binfo (TYPE_OFFSET_BASETYPE (intype
),
5361 TYPE_OFFSET_BASETYPE (type
), 0))
5362 && ! TREE_VIA_VIRTUAL (binfo
))
5365 else if (TREE_CODE (intype
) != BOOLEAN_TYPE
5366 && TREE_CODE (type
) != ARRAY_TYPE
5367 && TREE_CODE (type
) != FUNCTION_TYPE
5368 && can_convert (intype
, type
))
5372 return build_c_cast (type
, expr
);
5374 cp_error ("static_cast from `%T' to `%T'", intype
, type
);
5375 return error_mark_node
;
5379 build_reinterpret_cast (type
, expr
)
5384 if (type
== error_mark_node
|| expr
== error_mark_node
)
5385 return error_mark_node
;
5387 if (TREE_CODE (expr
) == OFFSET_REF
)
5388 expr
= resolve_offset_ref (expr
);
5390 if (processing_template_decl
)
5392 tree t
= build_min (REINTERPRET_CAST_EXPR
,
5393 copy_to_permanent (type
), expr
);
5397 if (TREE_CODE (type
) != REFERENCE_TYPE
)
5399 expr
= decay_conversion (expr
);
5401 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5402 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5403 if (TREE_CODE (expr
) == NOP_EXPR
5404 && TREE_TYPE (expr
) == TREE_TYPE (TREE_OPERAND (expr
, 0)))
5405 expr
= TREE_OPERAND (expr
, 0);
5408 if (type_unknown_p (expr
))
5410 expr
= instantiate_type (type
, expr
, 1);
5411 if (expr
== error_mark_node
)
5412 return error_mark_node
;
5415 intype
= TREE_TYPE (expr
);
5417 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5419 if (! real_lvalue_p (expr
))
5421 cp_error ("reinterpret_cast from `%T' rvalue to `%T'", intype
, type
);
5422 return error_mark_node
;
5424 expr
= build_unary_op (ADDR_EXPR
, expr
, 0);
5425 if (expr
!= error_mark_node
)
5426 expr
= build_reinterpret_cast
5427 (build_pointer_type (TREE_TYPE (type
)), expr
);
5428 if (expr
!= error_mark_node
)
5429 expr
= build_indirect_ref (expr
, 0);
5432 else if (comptypes (TYPE_MAIN_VARIANT (intype
), TYPE_MAIN_VARIANT (type
), 1))
5433 return build_static_cast (type
, expr
);
5435 if (TYPE_PTR_P (type
) && (TREE_CODE (intype
) == INTEGER_TYPE
5436 || TREE_CODE (intype
) == ENUMERAL_TYPE
))
5438 else if (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_PTR_P (intype
))
5440 if (TYPE_PRECISION (type
) < TYPE_PRECISION (intype
))
5441 cp_pedwarn ("reinterpret_cast from `%T' to `%T' loses precision",
5444 else if ((TYPE_PTRFN_P (type
) && TYPE_PTRFN_P (intype
))
5445 || (TYPE_PTRMEMFUNC_P (type
) && TYPE_PTRMEMFUNC_P (intype
)))
5447 if (TREE_READONLY_DECL_P (expr
))
5448 expr
= decl_constant_value (expr
);
5449 return fold (build1 (NOP_EXPR
, type
, expr
));
5451 else if ((TYPE_PTRMEM_P (type
) && TYPE_PTRMEM_P (intype
))
5452 || (TYPE_PTROBV_P (type
) && TYPE_PTROBV_P (intype
)))
5454 if (! comp_ptr_ttypes_reinterpret (TREE_TYPE (type
), TREE_TYPE (intype
)))
5455 cp_pedwarn ("reinterpret_cast from `%T' to `%T' casts away const (or volatile)",
5458 if (TREE_READONLY_DECL_P (expr
))
5459 expr
= decl_constant_value (expr
);
5460 return fold (build1 (NOP_EXPR
, type
, expr
));
5462 else if ((TYPE_PTRFN_P (type
) && TYPE_PTROBV_P (intype
))
5463 || (TYPE_PTRFN_P (type
) && TYPE_PTROBV_P (intype
)))
5465 pedwarn ("ANSI C++ forbids casting between pointers to functions and objects");
5466 if (TREE_READONLY_DECL_P (expr
))
5467 expr
= decl_constant_value (expr
);
5468 return fold (build1 (NOP_EXPR
, type
, expr
));
5472 cp_error ("reinterpret_cast from `%T' to `%T'", intype
, type
);
5473 return error_mark_node
;
5476 return cp_convert (type
, expr
);
5480 build_const_cast (type
, expr
)
5485 if (type
== error_mark_node
|| expr
== error_mark_node
)
5486 return error_mark_node
;
5488 if (TREE_CODE (expr
) == OFFSET_REF
)
5489 expr
= resolve_offset_ref (expr
);
5491 if (processing_template_decl
)
5493 tree t
= build_min (CONST_CAST_EXPR
, copy_to_permanent (type
),
5498 if (TREE_CODE (type
) != REFERENCE_TYPE
)
5500 expr
= decay_conversion (expr
);
5502 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5503 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5504 if (TREE_CODE (expr
) == NOP_EXPR
5505 && TREE_TYPE (expr
) == TREE_TYPE (TREE_OPERAND (expr
, 0)))
5506 expr
= TREE_OPERAND (expr
, 0);
5509 if (type_unknown_p (expr
))
5511 expr
= instantiate_type (type
, expr
, 1);
5512 if (expr
== error_mark_node
)
5513 return error_mark_node
;
5516 intype
= TREE_TYPE (expr
);
5518 if (comptypes (TYPE_MAIN_VARIANT (intype
), TYPE_MAIN_VARIANT (type
), 1))
5519 return build_static_cast (type
, expr
);
5520 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
5522 if (! real_lvalue_p (expr
))
5524 cp_error ("const_cast from `%T' rvalue to `%T'", intype
, type
);
5525 return error_mark_node
;
5528 if (comp_ptr_ttypes_const (TREE_TYPE (type
), intype
))
5530 expr
= build_unary_op (ADDR_EXPR
, expr
, 0);
5531 expr
= build1 (NOP_EXPR
, type
, expr
);
5532 return convert_from_reference (expr
);
5535 else if (TREE_CODE (type
) == POINTER_TYPE
5536 && TREE_CODE (intype
) == POINTER_TYPE
5537 && comp_ptr_ttypes_const (TREE_TYPE (type
), TREE_TYPE (intype
)))
5538 return cp_convert (type
, expr
);
5540 cp_error ("const_cast from `%T' to `%T'", intype
, type
);
5541 return error_mark_node
;
5544 /* Build an expression representing a cast to type TYPE of expression EXPR.
5546 ALLOW_NONCONVERTING is true if we should allow non-converting constructors
5547 when doing the cast. */
5550 build_c_cast (type
, expr
)
5553 register tree value
= expr
;
5555 if (type
== error_mark_node
|| expr
== error_mark_node
)
5556 return error_mark_node
;
5558 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5559 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5560 if (TREE_CODE (type
) != REFERENCE_TYPE
5561 && TREE_CODE (value
) == NOP_EXPR
5562 && TREE_TYPE (value
) == TREE_TYPE (TREE_OPERAND (value
, 0)))
5563 value
= TREE_OPERAND (value
, 0);
5565 if (TREE_TYPE (expr
)
5566 && TREE_CODE (TREE_TYPE (expr
)) == OFFSET_TYPE
5567 && TREE_CODE (type
) != OFFSET_TYPE
)
5568 value
= resolve_offset_ref (value
);
5570 if (TREE_CODE (type
) == ARRAY_TYPE
)
5572 /* Allow casting from T1* to T2[] because Cfront allows it.
5573 NIHCL uses it. It is not valid ANSI C however, and hence, not
5575 if (TREE_CODE (TREE_TYPE (expr
)) == POINTER_TYPE
)
5578 pedwarn ("ANSI C++ forbids casting to an array type");
5579 type
= build_pointer_type (TREE_TYPE (type
));
5583 error ("ANSI C++ forbids casting to an array type");
5584 return error_mark_node
;
5588 if (TREE_CODE (type
) == FUNCTION_TYPE
5589 || TREE_CODE (type
) == METHOD_TYPE
)
5591 cp_error ("casting to function type `%T'", type
);
5592 return error_mark_node
;
5595 if (IS_SIGNATURE (type
))
5597 error ("cast specifies signature type");
5598 return error_mark_node
;
5601 if (processing_template_decl
)
5603 tree t
= build_min (CAST_EXPR
, type
,
5604 min_tree_cons (NULL_TREE
, value
, NULL_TREE
));
5608 if (TREE_CODE (type
) == VOID_TYPE
)
5609 value
= build1 (CONVERT_EXPR
, type
, value
);
5610 else if (TREE_TYPE (value
) == NULL_TREE
5611 || type_unknown_p (value
))
5613 value
= instantiate_type (type
, value
, 1);
5615 if (value
== error_mark_node
)
5616 return error_mark_node
;
5622 /* Convert functions and arrays to pointers and
5623 convert references to their expanded types,
5624 but don't convert any other types. */
5625 if (TREE_CODE (TREE_TYPE (value
)) == FUNCTION_TYPE
5626 || (TREE_CODE (TREE_TYPE (value
)) == METHOD_TYPE
5627 /* Don't do the default conversion if we want a
5628 pointer to a function. */
5629 && ! (TREE_CODE (type
) == POINTER_TYPE
5630 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
))
5631 || TREE_CODE (TREE_TYPE (value
)) == ARRAY_TYPE
5632 || TREE_CODE (TREE_TYPE (value
)) == REFERENCE_TYPE
)
5633 value
= default_conversion (value
);
5634 otype
= TREE_TYPE (value
);
5636 /* Optionally warn about potentially worrisome casts. */
5639 && TREE_CODE (type
) == POINTER_TYPE
5640 && TREE_CODE (otype
) == POINTER_TYPE
)
5642 /* For C++ we make these regular warnings, rather than
5643 softening them into pedwarns. */
5644 if (TYPE_VOLATILE (TREE_TYPE (otype
))
5645 && ! TYPE_VOLATILE (TREE_TYPE (type
)))
5646 warning ("cast discards `volatile' from pointer target type");
5647 if (TYPE_READONLY (TREE_TYPE (otype
))
5648 && ! TYPE_READONLY (TREE_TYPE (type
)))
5649 warning ("cast discards `const' from pointer target type");
5652 /* Warn about possible alignment problems. */
5653 if (STRICT_ALIGNMENT
&& warn_cast_align
5654 && TREE_CODE (type
) == POINTER_TYPE
5655 && TREE_CODE (otype
) == POINTER_TYPE
5656 && TREE_CODE (TREE_TYPE (otype
)) != VOID_TYPE
5657 && TREE_CODE (TREE_TYPE (otype
)) != FUNCTION_TYPE
5658 && TYPE_ALIGN (TREE_TYPE (type
)) > TYPE_ALIGN (TREE_TYPE (otype
)))
5659 warning ("cast increases required alignment of target type");
5662 /* We should see about re-enabling these, they seem useful to
5664 if (TREE_CODE (type
) == INTEGER_TYPE
5665 && TREE_CODE (otype
) == POINTER_TYPE
5666 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
))
5667 warning ("cast from pointer to integer of different size");
5669 if (TREE_CODE (type
) == POINTER_TYPE
5670 && TREE_CODE (otype
) == INTEGER_TYPE
5671 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
)
5672 /* Don't warn about converting 0 to pointer,
5673 provided the 0 was explicit--not cast or made by folding. */
5674 && !(TREE_CODE (value
) == INTEGER_CST
&& integer_zerop (value
)))
5675 warning ("cast to pointer from integer of different size");
5678 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5679 value
= (convert_from_reference
5680 (convert_to_reference (type
, value
, CONV_C_CAST
,
5681 LOOKUP_COMPLAIN
, NULL_TREE
)));
5686 if (TREE_READONLY_DECL_P (value
))
5687 value
= decl_constant_value (value
);
5690 value
= convert_force (type
, value
, CONV_C_CAST
);
5692 /* Ignore any integer overflow caused by the cast. */
5693 if (TREE_CODE (value
) == INTEGER_CST
)
5695 TREE_OVERFLOW (value
) = TREE_OVERFLOW (ovalue
);
5696 TREE_CONSTANT_OVERFLOW (value
) = TREE_CONSTANT_OVERFLOW (ovalue
);
5701 /* Always produce some operator for an explicit cast,
5702 so we can tell (for -pedantic) that the cast is no lvalue. */
5703 if (TREE_CODE (type
) != REFERENCE_TYPE
&& value
== expr
5704 && real_lvalue_p (value
))
5705 value
= non_lvalue (value
);
5710 /* Build an assignment expression of lvalue LHS from value RHS.
5711 MODIFYCODE is the code for a binary operator that we use
5712 to combine the old value of LHS with RHS to get the new value.
5713 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
5715 C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed. */
5718 build_modify_expr (lhs
, modifycode
, rhs
)
5720 enum tree_code modifycode
;
5723 register tree result
;
5725 tree lhstype
= TREE_TYPE (lhs
);
5726 tree olhstype
= lhstype
;
5729 /* Avoid duplicate error messages from operands that had errors. */
5730 if (lhs
== error_mark_node
|| rhs
== error_mark_node
)
5731 return error_mark_node
;
5733 /* Types that aren't fully specified cannot be used in assignments. */
5734 lhs
= require_complete_type (lhs
);
5738 /* Handle assignment to signature pointers/refs. */
5740 if (TYPE_LANG_SPECIFIC (lhstype
)
5741 && (IS_SIGNATURE_POINTER (lhstype
) || IS_SIGNATURE_REFERENCE (lhstype
)))
5743 return build_signature_pointer_constructor (lhs
, rhs
);
5746 /* Handle control structure constructs used as "lvalues". */
5748 switch (TREE_CODE (lhs
))
5750 /* Handle --foo = 5; as these are valid constructs in C++ */
5751 case PREDECREMENT_EXPR
:
5752 case PREINCREMENT_EXPR
:
5753 if (TREE_SIDE_EFFECTS (TREE_OPERAND (lhs
, 0)))
5754 lhs
= build (TREE_CODE (lhs
), TREE_TYPE (lhs
),
5755 stabilize_reference (TREE_OPERAND (lhs
, 0)),
5756 TREE_OPERAND (lhs
, 1));
5757 return build (COMPOUND_EXPR
, lhstype
,
5759 build_modify_expr (TREE_OPERAND (lhs
, 0),
5762 /* Handle (a, b) used as an "lvalue". */
5764 newrhs
= build_modify_expr (TREE_OPERAND (lhs
, 1),
5766 if (newrhs
== error_mark_node
)
5767 return error_mark_node
;
5768 return build (COMPOUND_EXPR
, lhstype
,
5769 TREE_OPERAND (lhs
, 0), newrhs
);
5772 newrhs
= build_modify_expr (TREE_OPERAND (lhs
, 0), modifycode
, rhs
);
5773 if (newrhs
== error_mark_node
)
5774 return error_mark_node
;
5775 return build (COMPOUND_EXPR
, lhstype
, lhs
, newrhs
);
5777 /* Handle (a ? b : c) used as an "lvalue". */
5779 rhs
= save_expr (rhs
);
5781 /* Produce (a ? (b = rhs) : (c = rhs))
5782 except that the RHS goes through a save-expr
5783 so the code to compute it is only emitted once. */
5785 = build_conditional_expr (TREE_OPERAND (lhs
, 0),
5786 build_modify_expr (cp_convert (TREE_TYPE (lhs
), TREE_OPERAND (lhs
, 1)),
5788 build_modify_expr (cp_convert (TREE_TYPE (lhs
), TREE_OPERAND (lhs
, 2)),
5790 if (cond
== error_mark_node
)
5792 /* Make sure the code to compute the rhs comes out
5793 before the split. */
5794 return build (COMPOUND_EXPR
, TREE_TYPE (lhs
),
5795 /* Case to void to suppress warning
5796 from warn_if_unused_value. */
5797 cp_convert (void_type_node
, rhs
), cond
);
5804 if (TREE_CODE (lhs
) == OFFSET_REF
)
5806 if (TREE_OPERAND (lhs
, 0) == NULL_TREE
)
5808 /* Static class member? */
5809 tree member
= TREE_OPERAND (lhs
, 1);
5810 if (TREE_CODE (member
) == VAR_DECL
)
5814 compiler_error ("invalid static class member");
5815 return error_mark_node
;
5819 lhs
= resolve_offset_ref (lhs
);
5821 olhstype
= lhstype
= TREE_TYPE (lhs
);
5824 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
5825 && modifycode
!= INIT_EXPR
)
5827 lhs
= convert_from_reference (lhs
);
5828 olhstype
= lhstype
= TREE_TYPE (lhs
);
5831 /* If a binary op has been requested, combine the old LHS value with the RHS
5832 producing the value we should actually store into the LHS. */
5834 if (modifycode
== INIT_EXPR
)
5836 if (! IS_AGGR_TYPE (lhstype
))
5837 /* Do the default thing */;
5840 result
= build_method_call (lhs
, ctor_identifier
,
5841 build_expr_list (NULL_TREE
, rhs
),
5842 TYPE_BINFO (lhstype
), LOOKUP_NORMAL
);
5843 if (result
== NULL_TREE
)
5844 return error_mark_node
;
5848 else if (modifycode
== NOP_EXPR
)
5850 /* `operator=' is not an inheritable operator. */
5851 if (! IS_AGGR_TYPE (lhstype
))
5852 /* Do the default thing */;
5855 result
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
,
5856 lhs
, rhs
, make_node (NOP_EXPR
));
5857 if (result
== NULL_TREE
)
5858 return error_mark_node
;
5863 else if (PROMOTES_TO_AGGR_TYPE (lhstype
, REFERENCE_TYPE
))
5865 my_friendly_abort (978652);
5869 lhs
= stabilize_reference (lhs
);
5870 newrhs
= build_binary_op (modifycode
, lhs
, rhs
, 1);
5871 if (newrhs
== error_mark_node
)
5873 cp_error (" in evaluation of `%Q(%#T, %#T)'", modifycode
,
5874 TREE_TYPE (lhs
), TREE_TYPE (rhs
));
5875 return error_mark_node
;
5879 /* Handle a cast used as an "lvalue".
5880 We have already performed any binary operator using the value as cast.
5881 Now convert the result to the cast type of the lhs,
5882 and then true type of the lhs and store it there;
5883 then convert result back to the cast type to be the value
5884 of the assignment. */
5886 switch (TREE_CODE (lhs
))
5891 case FIX_TRUNC_EXPR
:
5892 case FIX_FLOOR_EXPR
:
5893 case FIX_ROUND_EXPR
:
5895 if (TREE_CODE (TREE_TYPE (newrhs
)) == ARRAY_TYPE
5896 || TREE_CODE (TREE_TYPE (newrhs
)) == FUNCTION_TYPE
5897 || TREE_CODE (TREE_TYPE (newrhs
)) == METHOD_TYPE
5898 || TREE_CODE (TREE_TYPE (newrhs
)) == OFFSET_TYPE
)
5899 newrhs
= default_conversion (newrhs
);
5901 tree inner_lhs
= TREE_OPERAND (lhs
, 0);
5904 /* WP 5.4.1: The result is an lvalue if T is a reference type,
5905 otherwise the result is an rvalue. */
5906 if (! lvalue_p (lhs
))
5907 pedwarn ("ANSI C++ forbids cast to non-reference type used as lvalue");
5909 result
= build_modify_expr (inner_lhs
, NOP_EXPR
,
5910 cp_convert (TREE_TYPE (inner_lhs
),
5911 cp_convert (lhstype
, newrhs
)));
5912 if (result
== error_mark_node
)
5914 return cp_convert (TREE_TYPE (lhs
), result
);
5921 /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
5922 Reject anything strange now. */
5924 if (!lvalue_or_else (lhs
, "assignment"))
5925 return error_mark_node
;
5927 GNU_xref_assign (lhs
);
5929 /* Warn about storing in something that is `const'. */
5930 /* For C++, don't warn if this is initialization. */
5931 if (modifycode
!= INIT_EXPR
5932 /* For assignment to `const' signature pointer/reference fields,
5933 don't warn either, we already printed a better message before. */
5934 && ! (TREE_CODE (lhs
) == COMPONENT_REF
5935 && (IS_SIGNATURE_POINTER (TREE_TYPE (TREE_OPERAND (lhs
, 0)))
5936 || IS_SIGNATURE_REFERENCE (TREE_TYPE (TREE_OPERAND (lhs
, 0)))))
5937 && (TREE_READONLY (lhs
) || TYPE_READONLY (lhstype
)
5938 || ((TREE_CODE (lhstype
) == RECORD_TYPE
5939 || TREE_CODE (lhstype
) == UNION_TYPE
)
5940 && C_TYPE_FIELDS_READONLY (lhstype
))
5941 || (TREE_CODE (lhstype
) == REFERENCE_TYPE
5942 && TYPE_READONLY (TREE_TYPE (lhstype
)))))
5943 readonly_error (lhs
, "assignment", 0);
5945 /* If storing into a structure or union member,
5946 it has probably been given type `int'.
5947 Compute the type that would go with
5948 the actual amount of storage the member occupies. */
5950 if (TREE_CODE (lhs
) == COMPONENT_REF
5951 && (TREE_CODE (lhstype
) == INTEGER_TYPE
5952 || TREE_CODE (lhstype
) == REAL_TYPE
5953 || TREE_CODE (lhstype
) == ENUMERAL_TYPE
))
5955 lhstype
= TREE_TYPE (get_unwidened (lhs
, 0));
5957 /* If storing in a field that is in actuality a short or narrower
5958 than one, we must store in the field in its actual type. */
5960 if (lhstype
!= TREE_TYPE (lhs
))
5962 lhs
= copy_node (lhs
);
5963 TREE_TYPE (lhs
) = lhstype
;
5967 /* check to see if there is an assignment to `this' */
5968 if (lhs
== current_class_ptr
)
5970 if (flag_this_is_variable
> 0
5971 && DECL_NAME (current_function_decl
) != NULL_TREE
5972 && (DECL_NAME (current_function_decl
)
5973 != constructor_name (current_class_type
)))
5974 warning ("assignment to `this' not in constructor or destructor");
5975 current_function_just_assigned_this
= 1;
5978 /* The TREE_TYPE of RHS may be TYPE_UNKNOWN. This can happen
5979 when the type of RHS is not yet known, i.e. its type
5980 is inherited from LHS. */
5981 rhs
= require_instantiated_type (lhstype
, newrhs
, error_mark_node
);
5982 if (rhs
== error_mark_node
)
5983 return error_mark_node
;
5986 if (modifycode
!= INIT_EXPR
)
5988 /* Make modifycode now either a NOP_EXPR or an INIT_EXPR. */
5989 modifycode
= NOP_EXPR
;
5990 /* Reference-bashing */
5991 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
)
5993 tree tmp
= convert_from_reference (lhs
);
5994 lhstype
= TREE_TYPE (tmp
);
5995 if (TYPE_SIZE (lhstype
) == 0)
5997 incomplete_type_error (lhs
, lhstype
);
5998 return error_mark_node
;
6003 if (TREE_CODE (TREE_TYPE (newrhs
)) == REFERENCE_TYPE
)
6005 tree tmp
= convert_from_reference (newrhs
);
6006 if (TYPE_SIZE (TREE_TYPE (tmp
)) == 0)
6008 incomplete_type_error (newrhs
, TREE_TYPE (tmp
));
6009 return error_mark_node
;
6015 if (TREE_SIDE_EFFECTS (lhs
))
6016 lhs
= stabilize_reference (lhs
);
6017 if (TREE_SIDE_EFFECTS (newrhs
))
6018 newrhs
= stabilize_reference (newrhs
);
6020 /* Convert new value to destination type. */
6022 if (TREE_CODE (lhstype
) == ARRAY_TYPE
)
6026 if (! comptypes (lhstype
, TREE_TYPE (rhs
), 0))
6028 cp_error ("incompatible types in assignment of `%T' to `%T'",
6029 TREE_TYPE (rhs
), lhstype
);
6030 return error_mark_node
;
6033 /* Allow array assignment in compiler-generated code. */
6034 if (pedantic
&& ! DECL_ARTIFICIAL (current_function_decl
))
6035 pedwarn ("ANSI C++ forbids assignment of arrays");
6037 /* Have to wrap this in RTL_EXPR for two cases:
6038 in base or member initialization and if we
6039 are a branch of a ?: operator. Since we
6040 can't easily know the latter, just do it always. */
6042 result
= make_node (RTL_EXPR
);
6044 TREE_TYPE (result
) = void_type_node
;
6045 do_pending_stack_adjust ();
6046 start_sequence_for_rtl_expr (result
);
6048 /* As a matter of principle, `start_sequence' should do this. */
6051 from_array
= TREE_CODE (TREE_TYPE (newrhs
)) == ARRAY_TYPE
6052 ? 1 + (modifycode
!= INIT_EXPR
): 0;
6053 expand_vec_init (lhs
, lhs
, array_type_nelts (lhstype
), newrhs
,
6056 do_pending_stack_adjust ();
6058 TREE_SIDE_EFFECTS (result
) = 1;
6059 RTL_EXPR_SEQUENCE (result
) = get_insns ();
6060 RTL_EXPR_RTL (result
) = const0_rtx
;
6065 if (modifycode
== INIT_EXPR
)
6067 newrhs
= convert_for_initialization (lhs
, lhstype
, newrhs
, LOOKUP_NORMAL
,
6068 "assignment", NULL_TREE
, 0);
6069 if (lhs
== DECL_RESULT (current_function_decl
))
6071 if (DECL_INITIAL (lhs
))
6072 warning ("return value from function receives multiple initializations");
6073 DECL_INITIAL (lhs
) = newrhs
;
6078 /* Avoid warnings on enum bit fields. */
6079 if (TREE_CODE (olhstype
) == ENUMERAL_TYPE
6080 && TREE_CODE (lhstype
) == INTEGER_TYPE
)
6082 newrhs
= convert_for_assignment (olhstype
, newrhs
, "assignment",
6084 newrhs
= convert_force (lhstype
, newrhs
, 0);
6087 newrhs
= convert_for_assignment (lhstype
, newrhs
, "assignment",
6089 if (TREE_CODE (newrhs
) == CALL_EXPR
6090 && TYPE_NEEDS_CONSTRUCTING (lhstype
))
6091 newrhs
= build_cplus_new (lhstype
, newrhs
);
6093 /* Can't initialize directly from a TARGET_EXPR, since that would
6094 cause the lhs to be constructed twice, and possibly result in
6095 accidental self-initialization. So we force the TARGET_EXPR to be
6096 expanded without a target. */
6097 if (TREE_CODE (newrhs
) == TARGET_EXPR
)
6098 newrhs
= build (COMPOUND_EXPR
, TREE_TYPE (newrhs
), newrhs
,
6099 TREE_OPERAND (newrhs
, 0));
6102 if (newrhs
== error_mark_node
)
6103 return error_mark_node
;
6105 if (TREE_CODE (newrhs
) == COND_EXPR
)
6108 tree cond
= TREE_OPERAND (newrhs
, 0);
6110 if (TREE_SIDE_EFFECTS (lhs
))
6111 cond
= build_compound_expr (tree_cons
6113 build_expr_list (NULL_TREE
, cond
)));
6115 /* Cannot have two identical lhs on this one tree (result) as preexpand
6116 calls will rip them out and fill in RTL for them, but when the
6117 rtl is generated, the calls will only be in the first side of the
6118 condition, not on both, or before the conditional jump! (mrs) */
6119 lhs1
= break_out_calls (lhs
);
6122 /* If there's no change, the COND_EXPR behaves like any other rhs. */
6123 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
6124 lhstype
, lhs
, newrhs
);
6127 tree result_type
= TREE_TYPE (newrhs
);
6128 /* We have to convert each arm to the proper type because the
6129 types may have been munged by constant folding. */
6131 = build (COND_EXPR
, result_type
, cond
,
6132 build_modify_expr (lhs
, modifycode
,
6133 cp_convert (result_type
,
6134 TREE_OPERAND (newrhs
, 1))),
6135 build_modify_expr (lhs1
, modifycode
,
6136 cp_convert (result_type
,
6137 TREE_OPERAND (newrhs
, 2))));
6141 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
6142 lhstype
, lhs
, newrhs
);
6144 TREE_SIDE_EFFECTS (result
) = 1;
6146 /* If we got the LHS in a different type for storing in,
6147 convert the result back to the nominal type of LHS
6148 so that the value we return always has the same type
6149 as the LHS argument. */
6151 if (olhstype
== TREE_TYPE (result
))
6153 /* Avoid warnings converting integral types back into enums
6154 for enum bit fields. */
6155 if (TREE_CODE (TREE_TYPE (result
)) == INTEGER_TYPE
6156 && TREE_CODE (olhstype
) == ENUMERAL_TYPE
)
6158 result
= build (COMPOUND_EXPR
, olhstype
, result
, olhs
);
6159 TREE_NO_UNUSED_WARNING (result
) = 1;
6162 return convert_for_assignment (olhstype
, result
, "assignment",
6167 build_x_modify_expr (lhs
, modifycode
, rhs
)
6169 enum tree_code modifycode
;
6172 if (processing_template_decl
)
6173 return build_min_nt (MODOP_EXPR
, lhs
,
6174 build_min_nt (modifycode
, NULL_TREE
, NULL_TREE
), rhs
);
6176 if (modifycode
!= NOP_EXPR
)
6178 tree rval
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
, lhs
, rhs
,
6179 make_node (modifycode
));
6183 return build_modify_expr (lhs
, modifycode
, rhs
);
6186 /* Return 0 if EXP is not a valid lvalue in this language
6187 even though `lvalue_or_else' would accept it. */
6190 language_lvalue_valid (exp
)
6196 /* Get difference in deltas for different pointer to member function
6197 types. Return integer_zero_node, if FROM cannot be converted to a
6198 TO type. If FORCE is true, then allow reverse conversions as well. */
6201 get_delta_difference (from
, to
, force
)
6205 tree delta
= integer_zero_node
;
6211 /* Should get_base_distance here, so we can check if any thing along the
6212 path is virtual, and we need to make sure we stay
6213 inside the real binfos when going through virtual bases.
6214 Maybe we should replace virtual bases with
6215 binfo_member (...CLASSTYPE_VBASECLASSES...)... (mrs) */
6216 binfo
= get_binfo (from
, to
, 1);
6217 if (binfo
== error_mark_node
)
6219 error (" in pointer to member function conversion");
6226 error_not_base_type (from
, to
);
6227 error (" in pointer to member conversion");
6230 binfo
= get_binfo (to
, from
, 1);
6231 if (binfo
== 0 || binfo
== error_mark_node
)
6233 if (TREE_VIA_VIRTUAL (binfo
))
6235 binfo
= binfo_member (BINFO_TYPE (binfo
),
6236 CLASSTYPE_VBASECLASSES (from
));
6237 cp_warning ("pointer to member cast to virtual base `%T'",
6238 BINFO_TYPE (binfo
));
6239 warning (" will only work if you are very careful");
6241 delta
= BINFO_OFFSET (binfo
);
6242 delta
= cp_convert (ptrdiff_type_node
, delta
);
6244 return build_binary_op (MINUS_EXPR
,
6249 if (TREE_VIA_VIRTUAL (binfo
))
6253 cp_warning ("pointer to member cast from virtual base `%T'",
6254 BINFO_TYPE (binfo
));
6255 warning (" will only work if you are very careful");
6258 cp_error ("pointer to member conversion from virtual base `%T'",
6259 BINFO_TYPE (binfo
));
6262 return BINFO_OFFSET (binfo
);
6266 build_ptrmemfunc1 (type
, delta
, idx
, pfn
, delta2
)
6267 tree type
, delta
, idx
, pfn
, delta2
;
6272 /* This is the old way we did it. We want to avoid calling
6273 digest_init, so that it can give an error if we use { } when
6274 initializing a pointer to member function. */
6278 u
= build_nt (CONSTRUCTOR
, NULL_TREE
,
6279 expr_tree_cons (pfn_identifier
, pfn
, NULL_TREE
));
6283 u
= build_nt (CONSTRUCTOR
, NULL_TREE
,
6284 expr_tree_cons (delta2_identifier
, delta2
, NULL_TREE
));
6287 u
= build_nt (CONSTRUCTOR
, NULL_TREE
,
6288 expr_tree_cons (NULL_TREE
, delta
,
6289 expr_tree_cons (NULL_TREE
, idx
,
6290 expr_tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6292 return digest_init (type
, u
, (tree
*)0);
6294 tree delta_field
, idx_field
, pfn_or_delta2_field
, pfn_field
, delta2_field
;
6296 int allconstant
, allsimple
;
6298 delta_field
= TYPE_FIELDS (type
);
6299 idx_field
= TREE_CHAIN (delta_field
);
6300 pfn_or_delta2_field
= TREE_CHAIN (idx_field
);
6301 subtype
= TREE_TYPE (pfn_or_delta2_field
);
6302 pfn_field
= TYPE_FIELDS (subtype
);
6303 delta2_field
= TREE_CHAIN (pfn_field
);
6307 allconstant
= TREE_CONSTANT (pfn
);
6308 allsimple
= !! initializer_constant_valid_p (pfn
, TREE_TYPE (pfn
));
6309 u
= expr_tree_cons (pfn_field
, pfn
, NULL_TREE
);
6313 delta2
= convert_and_check (delta_type_node
, delta2
);
6314 allconstant
= TREE_CONSTANT (delta2
);
6315 allsimple
= !! initializer_constant_valid_p (delta2
, TREE_TYPE (delta2
));
6316 u
= expr_tree_cons (delta2_field
, delta2
, NULL_TREE
);
6319 delta
= convert_and_check (delta_type_node
, delta
);
6320 idx
= convert_and_check (delta_type_node
, idx
);
6322 allconstant
= allconstant
&& TREE_CONSTANT (delta
) && TREE_CONSTANT (idx
);
6323 allsimple
= allsimple
6324 && initializer_constant_valid_p (delta
, TREE_TYPE (delta
))
6325 && initializer_constant_valid_p (idx
, TREE_TYPE (idx
));
6327 u
= build (CONSTRUCTOR
, subtype
, NULL_TREE
, u
);
6328 u
= expr_tree_cons (delta_field
, delta
,
6329 expr_tree_cons (idx_field
, idx
,
6330 expr_tree_cons (pfn_or_delta2_field
, u
, NULL_TREE
)));
6331 u
= build (CONSTRUCTOR
, type
, NULL_TREE
, u
);
6332 TREE_CONSTANT (u
) = allconstant
;
6333 TREE_STATIC (u
) = allconstant
&& allsimple
;
6338 /* Build a constructor for a pointer to member function. It can be
6339 used to initialize global variables, local variable, or used
6340 as a value in expressions. TYPE is the POINTER to METHOD_TYPE we
6343 If FORCE is non-zero, then force this conversion, even if
6344 we would rather not do it. Usually set when using an explicit
6347 Return error_mark_node, if something goes wrong. */
6350 build_ptrmemfunc (type
, pfn
, force
)
6354 tree idx
= integer_zero_node
;
6355 tree delta
= integer_zero_node
;
6356 tree delta2
= integer_zero_node
;
6358 tree npfn
= NULL_TREE
;
6360 /* Handle multiple conversions of pointer to member functions. */
6361 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (pfn
)))
6363 tree ndelta
, ndelta2
;
6367 /* Is is already the right type? */
6368 if (type
== TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))
6371 pfn_type
= TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
));
6373 && comp_target_types (type
, pfn_type
, 0) != 1)
6374 cp_error ("conversion to `%T' from `%T'", type
, pfn_type
);
6376 ndelta
= cp_convert (ptrdiff_type_node
, build_component_ref (pfn
, delta_identifier
, NULL_TREE
, 0));
6377 ndelta2
= cp_convert (ptrdiff_type_node
, DELTA2_FROM_PTRMEMFUNC (pfn
));
6378 idx
= build_component_ref (pfn
, index_identifier
, NULL_TREE
, 0);
6380 n
= get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (pfn_type
)),
6381 TYPE_METHOD_BASETYPE (TREE_TYPE (type
)),
6384 delta
= build_binary_op (PLUS_EXPR
, ndelta
, n
, 1);
6385 delta2
= build_binary_op (PLUS_EXPR
, ndelta2
, n
, 1);
6386 e1
= fold (build (GT_EXPR
, boolean_type_node
, idx
, integer_zero_node
));
6388 e2
= build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type
), delta
, idx
,
6391 pfn
= PFN_FROM_PTRMEMFUNC (pfn
);
6392 npfn
= build1 (NOP_EXPR
, type
, pfn
);
6393 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6395 e3
= build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type
), delta
, idx
, npfn
,
6397 return build_conditional_expr (e1
, e2
, e3
);
6400 /* Handle null pointer to member function conversions. */
6401 if (integer_zerop (pfn
))
6403 pfn
= build_c_cast (type
, integer_zero_node
);
6404 return build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type
),
6405 integer_zero_node
, integer_zero_node
,
6409 if (TREE_CODE (pfn
) == TREE_LIST
6410 || (TREE_CODE (pfn
) == ADDR_EXPR
6411 && TREE_CODE (TREE_OPERAND (pfn
, 0)) == TREE_LIST
))
6412 return instantiate_type (type
, pfn
, 1);
6415 && comp_target_types (type
, TREE_TYPE (pfn
), 0) != 1)
6416 cp_error ("conversion to `%T' from `%T'", type
, TREE_TYPE (pfn
));
6418 /* Allow pointer to member conversions here. */
6419 delta
= get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TREE_TYPE (pfn
))),
6420 TYPE_METHOD_BASETYPE (TREE_TYPE (type
)),
6422 delta2
= build_binary_op (PLUS_EXPR
, delta2
, delta
, 1);
6424 if (TREE_CODE (TREE_OPERAND (pfn
, 0)) != FUNCTION_DECL
)
6425 warning ("assuming pointer to member function is non-virtual");
6427 if (TREE_CODE (TREE_OPERAND (pfn
, 0)) == FUNCTION_DECL
6428 && DECL_VINDEX (TREE_OPERAND (pfn
, 0)))
6430 /* Find the offset to the vfield pointer in the object. */
6431 vfield_offset
= get_binfo (DECL_CONTEXT (TREE_OPERAND (pfn
, 0)),
6432 DECL_CLASS_CONTEXT (TREE_OPERAND (pfn
, 0)),
6434 vfield_offset
= get_vfield_offset (vfield_offset
);
6435 delta2
= size_binop (PLUS_EXPR
, vfield_offset
, delta2
);
6437 /* Map everything down one to make room for the null pointer to member. */
6438 idx
= size_binop (PLUS_EXPR
,
6439 DECL_VINDEX (TREE_OPERAND (pfn
, 0)),
6444 idx
= size_binop (MINUS_EXPR
, integer_zero_node
, integer_one_node
);
6446 if (type
== TREE_TYPE (pfn
))
6452 npfn
= build1 (NOP_EXPR
, type
, pfn
);
6453 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6457 return build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type
), delta
, idx
, npfn
, delta2
);
6460 /* Convert value RHS to type TYPE as preparation for an assignment
6461 to an lvalue of type TYPE.
6462 The real work of conversion is done by `convert'.
6463 The purpose of this function is to generate error messages
6464 for assignments that are not allowed in C.
6465 ERRTYPE is a string to use in error messages:
6466 "assignment", "return", etc.
6468 C++: attempts to allow `convert' to find conversions involving
6469 implicit type conversion between aggregate and scalar types
6470 as per 8.5.6 of C++ manual. Does not randomly dereference
6471 pointers to aggregates! */
6474 convert_for_assignment (type
, rhs
, errtype
, fndecl
, parmnum
)
6480 register enum tree_code codel
= TREE_CODE (type
);
6481 register tree rhstype
;
6482 register enum tree_code coder
= TREE_CODE (TREE_TYPE (rhs
));
6484 if (coder
== UNKNOWN_TYPE
)
6485 rhs
= instantiate_type (type
, rhs
, 1);
6487 if (coder
== ERROR_MARK
)
6488 return error_mark_node
;
6490 if (codel
== OFFSET_TYPE
)
6492 type
= TREE_TYPE (type
);
6493 codel
= TREE_CODE (type
);
6496 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
6497 if (TREE_CODE (rhs
) == NON_LVALUE_EXPR
)
6498 rhs
= TREE_OPERAND (rhs
, 0);
6500 if (rhs
== error_mark_node
)
6501 return error_mark_node
;
6503 if (TREE_VALUE (rhs
) == error_mark_node
)
6504 return error_mark_node
;
6506 if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
6508 rhs
= resolve_offset_ref (rhs
);
6509 if (rhs
== error_mark_node
)
6510 return error_mark_node
;
6511 rhstype
= TREE_TYPE (rhs
);
6512 coder
= TREE_CODE (rhstype
);
6515 if (TREE_CODE (TREE_TYPE (rhs
)) == ARRAY_TYPE
6516 || TREE_CODE (TREE_TYPE (rhs
)) == FUNCTION_TYPE
6517 || TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
6518 rhs
= default_conversion (rhs
);
6519 else if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
6520 rhs
= convert_from_reference (rhs
);
6522 rhstype
= TREE_TYPE (rhs
);
6523 coder
= TREE_CODE (rhstype
);
6525 /* This should no longer change types on us. */
6526 if (TREE_CODE (rhs
) == CONST_DECL
)
6527 rhs
= DECL_INITIAL (rhs
);
6528 else if (TREE_READONLY_DECL_P (rhs
))
6529 rhs
= decl_constant_value (rhs
);
6531 if (type
== rhstype
)
6533 overflow_warning (rhs
);
6537 if (coder
== VOID_TYPE
)
6539 error ("void value not ignored as it ought to be");
6540 return error_mark_node
;
6542 /* Arithmetic types all interconvert. */
6543 if ((codel
== INTEGER_TYPE
|| codel
== REAL_TYPE
|| codel
== BOOLEAN_TYPE
6544 || codel
== COMPLEX_TYPE
)
6545 && (coder
== INTEGER_TYPE
|| coder
== REAL_TYPE
|| coder
== BOOLEAN_TYPE
6546 || coder
== COMPLEX_TYPE
))
6548 /* But we should warn if assigning REAL_TYPE to INTEGER_TYPE. */
6549 if (coder
== REAL_TYPE
&& codel
== INTEGER_TYPE
)
6552 cp_warning ("`%T' used for argument %P of `%D'",
6553 rhstype
, parmnum
, fndecl
);
6555 cp_warning ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6557 /* And we should warn if assigning a negative value to
6558 an unsigned variable. */
6559 else if (TREE_UNSIGNED (type
) && codel
!= BOOLEAN_TYPE
)
6561 if (TREE_CODE (rhs
) == INTEGER_CST
6562 && TREE_NEGATED_INT (rhs
))
6565 cp_warning ("negative value `%E' passed as argument %P of `%D'",
6566 rhs
, parmnum
, fndecl
);
6568 cp_warning ("%s of negative value `%E' to `%T'",
6569 errtype
, rhs
, type
);
6571 overflow_warning (rhs
);
6572 if (TREE_CONSTANT (rhs
))
6576 return convert_and_check (type
, rhs
);
6578 /* Conversions involving enums. */
6579 else if ((codel
== ENUMERAL_TYPE
6580 && (INTEGRAL_CODE_P (coder
) || coder
== REAL_TYPE
))
6581 || (coder
== ENUMERAL_TYPE
6582 && (INTEGRAL_CODE_P (codel
) || codel
== REAL_TYPE
)))
6584 return ocp_convert (type
, rhs
, CONV_IMPLICIT
, LOOKUP_NORMAL
);
6586 /* Conversions among pointers */
6587 else if (codel
== POINTER_TYPE
6588 && (coder
== POINTER_TYPE
6589 || (coder
== RECORD_TYPE
6590 && (IS_SIGNATURE_POINTER (rhstype
)
6591 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6593 register tree ttl
= TREE_TYPE (type
);
6597 if (coder
== RECORD_TYPE
)
6599 rhs
= build_optr_ref (rhs
);
6600 rhstype
= TREE_TYPE (rhs
);
6602 ttr
= TREE_TYPE (rhstype
);
6604 /* If both pointers are of aggregate type, then we
6605 can give better error messages, and save some work
6607 if (TREE_CODE (ttl
) == RECORD_TYPE
&& TREE_CODE (ttr
) == RECORD_TYPE
)
6611 if (TYPE_MAIN_VARIANT (ttl
) == TYPE_MAIN_VARIANT (ttr
)
6612 || type
== class_star_type_node
6613 || rhstype
== class_star_type_node
)
6614 binfo
= TYPE_BINFO (ttl
);
6616 binfo
= get_binfo (ttl
, ttr
, 1);
6618 if (binfo
== error_mark_node
)
6619 return error_mark_node
;
6621 return error_not_base_type (ttl
, ttr
);
6623 if (! TYPE_READONLY (ttl
) && TYPE_READONLY (ttr
))
6626 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6627 rhstype
, parmnum
, fndecl
);
6629 cp_pedwarn ("%s to `%T' from `%T' discards const",
6630 errtype
, type
, rhstype
);
6632 if (! TYPE_VOLATILE (ttl
) && TYPE_VOLATILE (ttr
))
6635 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6636 rhstype
, parmnum
, fndecl
);
6638 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6639 errtype
, type
, rhstype
);
6643 /* Any non-function converts to a [const][volatile] void *
6644 and vice versa; otherwise, targets must be the same.
6645 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
6646 else if (TYPE_MAIN_VARIANT (ttl
) == void_type_node
6647 || TYPE_MAIN_VARIANT (ttr
) == void_type_node
6648 || (ctt
= comp_target_types (type
, rhstype
, 1))
6649 || (unsigned_type (TYPE_MAIN_VARIANT (ttl
))
6650 == unsigned_type (TYPE_MAIN_VARIANT (ttr
))))
6652 /* ARM $4.8, commentary on p39. */
6653 if (TYPE_MAIN_VARIANT (ttl
) == void_type_node
6654 && TREE_CODE (ttr
) == OFFSET_TYPE
)
6656 cp_error ("no standard conversion from `%T' to `void *'", ttr
);
6657 return error_mark_node
;
6660 if (ctt
< 0 && TYPE_MAIN_VARIANT (ttl
) != TYPE_MAIN_VARIANT (ttr
))
6661 cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
6664 if (TYPE_MAIN_VARIANT (ttl
) != void_type_node
6665 && TYPE_MAIN_VARIANT (ttr
) == void_type_node
6666 && ! null_ptr_cst_p (rhs
))
6668 if (coder
== RECORD_TYPE
)
6669 cp_pedwarn ("implicit conversion of signature pointer to type `%T'",
6672 pedwarn ("ANSI C++ forbids implicit conversion from `void *' in %s",
6675 /* Const and volatile mean something different for function types,
6676 so the usual warnings are not appropriate. */
6677 else if ((TREE_CODE (ttr
) != FUNCTION_TYPE
&& TREE_CODE (ttr
) != METHOD_TYPE
)
6678 || (TREE_CODE (ttl
) != FUNCTION_TYPE
&& TREE_CODE (ttl
) != METHOD_TYPE
))
6680 if (TREE_CODE (ttl
) == OFFSET_TYPE
6681 && binfo_member (TYPE_OFFSET_BASETYPE (ttr
),
6682 CLASSTYPE_VBASECLASSES (TYPE_OFFSET_BASETYPE (ttl
))))
6684 sorry ("%s between pointer to members converting across virtual baseclasses", errtype
);
6685 return error_mark_node
;
6687 else if (! TYPE_READONLY (ttl
) && TYPE_READONLY (ttr
))
6690 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6691 rhstype
, parmnum
, fndecl
);
6693 cp_pedwarn ("%s to `%T' from `%T' discards const",
6694 errtype
, type
, rhstype
);
6696 else if (! TYPE_VOLATILE (ttl
) && TYPE_VOLATILE (ttr
))
6699 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6700 rhstype
, parmnum
, fndecl
);
6702 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6703 errtype
, type
, rhstype
);
6705 else if (TREE_CODE (ttl
) == TREE_CODE (ttr
)
6706 && ! comp_target_types (type
, rhstype
, 1))
6709 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signedness",
6710 rhstype
, parmnum
, fndecl
);
6712 cp_pedwarn ("%s to `%T' from `%T' changes signedness",
6713 errtype
, type
, rhstype
);
6719 int add_quals
= 0, const_parity
= 0, volatile_parity
= 0;
6721 int unsigned_parity
;
6724 /* This code is basically a duplicate of comp_ptr_ttypes_real. */
6725 for (; ; ttl
= TREE_TYPE (ttl
), ttr
= TREE_TYPE (ttr
))
6728 const_parity
|= (TYPE_READONLY (ttl
) < TYPE_READONLY (ttr
));
6729 volatile_parity
|= (TYPE_VOLATILE (ttl
) < TYPE_VOLATILE (ttr
));
6732 && (TYPE_READONLY (ttl
) > TYPE_READONLY (ttr
)
6733 || TYPE_VOLATILE (ttl
) > TYPE_VOLATILE (ttr
)))
6735 left_const
&= TYPE_READONLY (ttl
);
6737 if (TREE_CODE (ttl
) != POINTER_TYPE
6738 || TREE_CODE (ttr
) != POINTER_TYPE
)
6741 unsigned_parity
= TREE_UNSIGNED (ttl
) - TREE_UNSIGNED (ttr
);
6742 if (unsigned_parity
)
6744 if (TREE_UNSIGNED (ttl
))
6745 ttr
= unsigned_type (ttr
);
6747 ttl
= unsigned_type (ttl
);
6750 if (comp_target_types (ttl
, ttr
, nptrs
) > 0)
6755 cp_pedwarn ("passing `%T' as argument %P of `%D' adds cv-quals without intervening `const'",
6756 rhstype
, parmnum
, fndecl
);
6758 cp_pedwarn ("%s to `%T' from `%T' adds cv-quals without intervening `const'",
6759 errtype
, type
, rhstype
);
6764 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6765 rhstype
, parmnum
, fndecl
);
6767 cp_pedwarn ("%s to `%T' from `%T' discards const",
6768 errtype
, type
, rhstype
);
6770 if (volatile_parity
)
6773 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6774 rhstype
, parmnum
, fndecl
);
6776 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6777 errtype
, type
, rhstype
);
6779 if (unsigned_parity
> 0)
6782 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signed to unsigned",
6783 rhstype
, parmnum
, fndecl
);
6785 cp_pedwarn ("%s to `%T' from `%T' changes signed to unsigned",
6786 errtype
, type
, rhstype
);
6788 else if (unsigned_parity
< 0)
6791 cp_pedwarn ("passing `%T' as argument %P of `%D' changes unsigned to signed",
6792 rhstype
, parmnum
, fndecl
);
6794 cp_pedwarn ("%s to `%T' from `%T' changes unsigned to signed",
6795 errtype
, type
, rhstype
);
6798 /* C++ is not so friendly about converting function and
6799 member function pointers as C. Emit warnings here. */
6800 if (TREE_CODE (ttl
) == FUNCTION_TYPE
6801 || TREE_CODE (ttl
) == METHOD_TYPE
)
6802 if (! comptypes (ttl
, ttr
, 0))
6804 warning ("conflicting function types in %s:", errtype
);
6805 cp_warning ("\t`%T' != `%T'", type
, rhstype
);
6811 cp_error ("passing `%T' as argument %P of `%D'",
6812 rhstype
, parmnum
, fndecl
);
6814 cp_error ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6815 return error_mark_node
;
6818 return cp_convert (type
, rhs
);
6820 else if (codel
== POINTER_TYPE
&& coder
== INTEGER_TYPE
)
6822 /* An explicit constant 0 can convert to a pointer,
6823 but not a 0 that results from casting or folding. */
6824 if (! (TREE_CODE (rhs
) == INTEGER_CST
&& integer_zerop (rhs
)))
6827 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6828 rhstype
, parmnum
, fndecl
);
6830 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
6831 errtype
, type
, rhstype
);
6833 return cp_convert (type
, rhs
);
6835 else if (codel
== INTEGER_TYPE
6836 && (coder
== POINTER_TYPE
6837 || (coder
== RECORD_TYPE
6838 && (IS_SIGNATURE_POINTER (rhstype
)
6839 || TYPE_PTRMEMFUNC_FLAG (rhstype
)
6840 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6843 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6844 rhstype
, parmnum
, fndecl
);
6846 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
6847 errtype
, type
, rhstype
);
6848 return cp_convert (type
, rhs
);
6850 else if (codel
== BOOLEAN_TYPE
6851 && (coder
== POINTER_TYPE
6852 || (coder
== RECORD_TYPE
6853 && (IS_SIGNATURE_POINTER (rhstype
)
6854 || TYPE_PTRMEMFUNC_FLAG (rhstype
)
6855 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6856 return cp_convert (type
, rhs
);
6859 else if (((coder
== POINTER_TYPE
6860 && TREE_CODE (TREE_TYPE (rhstype
)) == METHOD_TYPE
)
6861 || integer_zerop (rhs
)
6862 || TYPE_PTRMEMFUNC_P (rhstype
))
6863 && TYPE_PTRMEMFUNC_P (type
))
6865 tree ttl
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
6866 tree ttr
= (TYPE_PTRMEMFUNC_P (rhstype
)
6867 ? TYPE_PTRMEMFUNC_FN_TYPE (rhstype
)
6869 int ctt
= (TREE_CODE (rhstype
) == INTEGER_TYPE
? 1
6870 : comp_target_types (ttl
, ttr
, 1));
6873 cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
6876 cp_error ("%s to `%T' from `%T'", errtype
, ttl
, ttr
);
6878 /* compatible pointer to member functions. */
6879 return build_ptrmemfunc (ttl
, rhs
, 0);
6881 else if (codel
== ERROR_MARK
|| coder
== ERROR_MARK
)
6882 return error_mark_node
;
6884 /* This should no longer happen. References are initialized via
6885 `convert_for_initialization'. They should otherwise be
6886 bashed before coming here. */
6887 else if (codel
== REFERENCE_TYPE
)
6888 my_friendly_abort (317);
6889 else if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (TREE_TYPE (rhs
)))
6891 tree nrhs
= build1 (NOP_EXPR
, type
, rhs
);
6892 TREE_CONSTANT (nrhs
) = TREE_CONSTANT (rhs
);
6895 else if (TYPE_HAS_CONSTRUCTOR (type
) || IS_AGGR_TYPE (TREE_TYPE (rhs
)))
6896 return cp_convert (type
, rhs
);
6897 /* Handle anachronistic conversions from (::*)() to cv void* or (*)(). */
6898 else if (TREE_CODE (type
) == POINTER_TYPE
6899 && (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
6900 || TYPE_MAIN_VARIANT (TREE_TYPE (type
)) == void_type_node
)
6902 && TYPE_PTRMEMFUNC_P (TREE_TYPE (rhs
)))
6903 return cp_convert (type
, rhs
);
6905 cp_error ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6906 return error_mark_node
;
6909 /* Convert RHS to be of type TYPE. If EXP is non-zero,
6910 it is the target of the initialization.
6911 ERRTYPE is a string to use in error messages.
6913 Two major differences between the behavior of
6914 `convert_for_assignment' and `convert_for_initialization'
6915 are that references are bashed in the former, while
6916 copied in the latter, and aggregates are assigned in
6917 the former (operator=) while initialized in the
6920 If using constructor make sure no conversion operator exists, if one does
6921 exist, an ambiguity exists.
6923 If flags doesn't include LOOKUP_COMPLAIN, don't complain about anything. */
6926 convert_for_initialization (exp
, type
, rhs
, flags
, errtype
, fndecl
, parmnum
)
6927 tree exp
, type
, rhs
;
6933 register enum tree_code codel
= TREE_CODE (type
);
6934 register tree rhstype
;
6935 register enum tree_code coder
;
6937 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
6938 Strip such NOP_EXPRs, since RHS is used in non-lvalue context. */
6939 if (TREE_CODE (rhs
) == NOP_EXPR
6940 && TREE_TYPE (rhs
) == TREE_TYPE (TREE_OPERAND (rhs
, 0))
6941 && codel
!= REFERENCE_TYPE
)
6942 rhs
= TREE_OPERAND (rhs
, 0);
6944 if (rhs
== error_mark_node
6945 || (TREE_CODE (rhs
) == TREE_LIST
&& TREE_VALUE (rhs
) == error_mark_node
))
6946 return error_mark_node
;
6948 if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
6950 rhs
= resolve_offset_ref (rhs
);
6951 if (rhs
== error_mark_node
)
6952 return error_mark_node
;
6955 if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
6956 rhs
= convert_from_reference (rhs
);
6958 if ((TREE_CODE (TREE_TYPE (rhs
)) == ARRAY_TYPE
6959 && TREE_CODE (type
) != ARRAY_TYPE
6960 && (TREE_CODE (type
) != REFERENCE_TYPE
6961 || TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
))
6962 || TREE_CODE (TREE_TYPE (rhs
)) == FUNCTION_TYPE
6963 || TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
6964 rhs
= default_conversion (rhs
);
6966 rhstype
= TREE_TYPE (rhs
);
6967 coder
= TREE_CODE (rhstype
);
6969 if (coder
== UNKNOWN_TYPE
)
6971 rhs
= instantiate_type (type
, rhs
, 1);
6972 rhstype
= TREE_TYPE (rhs
);
6973 coder
= TREE_CODE (rhstype
);
6976 if (coder
== ERROR_MARK
)
6977 return error_mark_node
;
6979 /* We accept references to incomplete types, so we can
6980 return here before checking if RHS is of complete type. */
6982 if (codel
== REFERENCE_TYPE
)
6984 /* This should eventually happen in convert_arguments. */
6985 extern int warningcount
, errorcount
;
6986 int savew
= 0, savee
= 0;
6989 savew
= warningcount
, savee
= errorcount
;
6990 rhs
= convert_to_reference (type
, rhs
, CONV_IMPLICIT
, flags
,
6991 exp
? exp
: error_mark_node
);
6994 if (warningcount
> savew
)
6995 cp_warning_at ("in passing argument %P of `%+D'", parmnum
, fndecl
);
6996 else if (errorcount
> savee
)
6997 cp_error_at ("in passing argument %P of `%+D'", parmnum
, fndecl
);
7002 rhs
= require_complete_type (rhs
);
7003 if (rhs
== error_mark_node
)
7004 return error_mark_node
;
7006 if (exp
!= 0) exp
= require_complete_type (exp
);
7007 if (exp
== error_mark_node
)
7008 return error_mark_node
;
7010 if (TREE_CODE (rhstype
) == REFERENCE_TYPE
)
7011 rhstype
= TREE_TYPE (rhstype
);
7013 type
= complete_type (type
);
7015 if (TYPE_LANG_SPECIFIC (type
)
7016 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
)))
7017 return build_signature_pointer_constructor (type
, rhs
);
7019 if (IS_AGGR_TYPE (type
))
7020 return ocp_convert (type
, rhs
, CONV_IMPLICIT
|CONV_FORCE_TEMP
, flags
);
7022 if (type
== TREE_TYPE (rhs
))
7024 if (TREE_READONLY_DECL_P (rhs
))
7025 rhs
= decl_constant_value (rhs
);
7029 return convert_for_assignment (type
, rhs
, errtype
, fndecl
, parmnum
);
7032 /* Expand an ASM statement with operands, handling output operands
7033 that are not variables or INDIRECT_REFS by transforming such
7034 cases into cases that expand_asm_operands can handle.
7036 Arguments are same as for expand_asm_operands.
7038 We don't do default conversions on all inputs, because it can screw
7039 up operands that are expected to be in memory. */
7042 c_expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, filename
, line
)
7043 tree string
, outputs
, inputs
, clobbers
;
7048 int noutputs
= list_length (outputs
);
7050 /* o[I] is the place that output number I should be written. */
7051 register tree
*o
= (tree
*) alloca (noutputs
* sizeof (tree
));
7054 /* Record the contents of OUTPUTS before it is modified. */
7055 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
7056 o
[i
] = TREE_VALUE (tail
);
7058 /* Generate the ASM_OPERANDS insn;
7059 store into the TREE_VALUEs of OUTPUTS some trees for
7060 where the values were actually stored. */
7061 expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, filename
, line
);
7063 /* Copy all the intermediate outputs into the specified outputs. */
7064 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
7066 if (o
[i
] != TREE_VALUE (tail
))
7068 expand_expr (build_modify_expr (o
[i
], NOP_EXPR
, TREE_VALUE (tail
)),
7069 const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
7072 /* Detect modification of read-only values.
7073 (Otherwise done by build_modify_expr.) */
7076 tree type
= TREE_TYPE (o
[i
]);
7077 if (TYPE_READONLY (type
)
7078 || ((TREE_CODE (type
) == RECORD_TYPE
7079 || TREE_CODE (type
) == UNION_TYPE
)
7080 && C_TYPE_FIELDS_READONLY (type
)))
7081 readonly_error (o
[i
], "modification by `asm'", 1);
7085 /* Those MODIFY_EXPRs could do autoincrements. */
7089 /* Expand a C `return' statement.
7090 RETVAL is the expression for what to return,
7091 or a null pointer for `return;' with no value.
7093 C++: upon seeing a `return', we must call destructors on all
7094 variables in scope which had constructors called on them.
7095 This means that if in a destructor, the base class destructors
7096 must be called before returning.
7098 The RETURN statement in C++ has initialization semantics. */
7101 c_expand_return (retval
)
7104 extern struct nesting
*cond_stack
, *loop_stack
, *case_stack
;
7105 extern tree dtor_label
, ctor_label
;
7106 tree result
= DECL_RESULT (current_function_decl
);
7107 tree valtype
= TREE_TYPE (result
);
7109 if (TREE_THIS_VOLATILE (current_function_decl
))
7110 warning ("function declared `noreturn' has a `return' statement");
7112 if (retval
== error_mark_node
)
7114 current_function_returns_null
= 1;
7118 if (processing_template_decl
)
7120 add_tree (build_min_nt (RETURN_STMT
, retval
));
7124 if (retval
== NULL_TREE
)
7126 /* A non-named return value does not count. */
7128 /* Can't just return from a destructor. */
7131 expand_goto (dtor_label
);
7135 if (DECL_CONSTRUCTOR_P (current_function_decl
))
7136 retval
= current_class_ptr
;
7137 else if (DECL_NAME (result
) != NULL_TREE
7138 && TREE_CODE (valtype
) != VOID_TYPE
)
7142 current_function_returns_null
= 1;
7144 if (valtype
!= NULL_TREE
&& TREE_CODE (valtype
) != VOID_TYPE
)
7146 if (DECL_NAME (DECL_RESULT (current_function_decl
)) == NULL_TREE
)
7148 pedwarn ("`return' with no value, in function returning non-void");
7149 /* Clear this, so finish_function won't say that we
7150 reach the end of a non-void function (which we don't,
7151 we gave a return!). */
7152 current_function_returns_null
= 0;
7156 expand_null_return ();
7160 else if (DECL_CONSTRUCTOR_P (current_function_decl
)
7161 && retval
!= current_class_ptr
)
7163 if (flag_this_is_variable
)
7164 error ("return from a constructor: use `this = ...' instead");
7166 error ("return from a constructor");
7167 retval
= current_class_ptr
;
7170 /* Effective C++ rule 15. See also start_function. */
7172 && DECL_NAME (current_function_decl
) == ansi_opname
[(int) MODIFY_EXPR
]
7173 && retval
!= current_class_ref
)
7174 cp_warning ("`operator=' should return a reference to `*this'");
7176 if (valtype
== NULL_TREE
|| TREE_CODE (valtype
) == VOID_TYPE
)
7178 current_function_returns_null
= 1;
7179 if ((pedantic
&& ! DECL_ARTIFICIAL (current_function_decl
))
7180 || TREE_CODE (TREE_TYPE (retval
)) != VOID_TYPE
)
7181 pedwarn ("`return' with a value, in function returning void");
7182 expand_return (retval
);
7186 /* Now deal with possible C++ hair:
7187 (1) Compute the return value.
7188 (2) If there are aggregate values with destructors which
7189 must be cleaned up, clean them (taking care
7190 not to clobber the return value).
7191 (3) If an X(X&) constructor is defined, the return
7192 value must be returned via that. */
7194 if (retval
== result
7195 || DECL_CONSTRUCTOR_P (current_function_decl
))
7196 /* It's already done for us. */;
7197 else if (TREE_TYPE (retval
) == void_type_node
)
7199 pedwarn ("return of void value in function returning non-void");
7200 expand_expr_stmt (retval
);
7205 retval
= convert_for_initialization
7206 (NULL_TREE
, valtype
, retval
, LOOKUP_NORMAL
|LOOKUP_ONLYCONVERTING
,
7207 "return", NULL_TREE
, 0);
7209 if (retval
== error_mark_node
)
7211 /* Avoid warning about control reaching end of function. */
7212 expand_null_return ();
7216 /* We can't initialize a register from a AGGR_INIT_EXPR. */
7217 else if (! current_function_returns_struct
7218 && TREE_CODE (retval
) == TARGET_EXPR
7219 && TREE_CODE (TREE_OPERAND (retval
, 1)) == AGGR_INIT_EXPR
)
7220 retval
= build (COMPOUND_EXPR
, TREE_TYPE (retval
), retval
,
7221 TREE_OPERAND (retval
, 0));
7223 /* Add some useful error checking for C++. */
7224 else if (TREE_CODE (valtype
) == REFERENCE_TYPE
)
7226 tree whats_returned
;
7228 /* Sort through common things to see what it is
7229 we are returning. */
7230 whats_returned
= retval
;
7231 if (TREE_CODE (whats_returned
) == COMPOUND_EXPR
)
7233 whats_returned
= TREE_OPERAND (whats_returned
, 1);
7234 if (TREE_CODE (whats_returned
) == ADDR_EXPR
)
7235 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7237 while (TREE_CODE (whats_returned
) == CONVERT_EXPR
7238 || TREE_CODE (whats_returned
) == NOP_EXPR
)
7239 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7240 if (TREE_CODE (whats_returned
) == ADDR_EXPR
)
7242 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7243 while (TREE_CODE (whats_returned
) == AGGR_INIT_EXPR
7244 || TREE_CODE (whats_returned
) == TARGET_EXPR
)
7246 /* Get the target. */
7247 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7248 warning ("returning reference to temporary");
7252 if (TREE_CODE (whats_returned
) == VAR_DECL
&& DECL_NAME (whats_returned
))
7254 if (TEMP_NAME_P (DECL_NAME (whats_returned
)))
7255 warning ("reference to non-lvalue returned");
7256 else if (TREE_CODE (TREE_TYPE (whats_returned
)) != REFERENCE_TYPE
7257 && ! TREE_STATIC (whats_returned
)
7258 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned
))
7259 && !TREE_PUBLIC (whats_returned
))
7260 cp_warning_at ("reference to local variable `%D' returned", whats_returned
);
7263 else if (TREE_CODE (retval
) == ADDR_EXPR
)
7265 tree whats_returned
= TREE_OPERAND (retval
, 0);
7267 if (TREE_CODE (whats_returned
) == VAR_DECL
7268 && DECL_NAME (whats_returned
)
7269 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned
))
7270 && !TREE_STATIC (whats_returned
)
7271 && !TREE_PUBLIC (whats_returned
))
7272 cp_warning_at ("address of local variable `%D' returned", whats_returned
);
7276 if (retval
!= NULL_TREE
7277 && TREE_CODE_CLASS (TREE_CODE (retval
)) == 'd'
7278 && cond_stack
== 0 && loop_stack
== 0 && case_stack
== 0)
7279 current_function_return_value
= retval
;
7281 if (ctor_label
&& TREE_CODE (ctor_label
) != ERROR_MARK
)
7283 /* Here RETVAL is CURRENT_CLASS_PTR, so there's nothing to do. */
7284 expand_goto (ctor_label
);
7287 if (retval
&& retval
!= result
)
7289 result
= build (INIT_EXPR
, TREE_TYPE (result
), result
, retval
);
7290 TREE_SIDE_EFFECTS (result
) = 1;
7293 expand_start_target_temps ();
7295 expand_return (result
);
7297 expand_end_target_temps ();
7299 current_function_returns_value
= 1;
7302 /* Start a C switch statement, testing expression EXP.
7303 Return EXP if it is valid, an error node otherwise. */
7306 c_expand_start_case (exp
)
7310 register enum tree_code code
;
7312 /* Convert from references, etc. */
7313 exp
= default_conversion (exp
);
7314 type
= TREE_TYPE (exp
);
7315 code
= TREE_CODE (type
);
7317 if (IS_AGGR_TYPE_CODE (code
))
7318 exp
= build_type_conversion (CONVERT_EXPR
, integer_type_node
, exp
, 1);
7320 if (exp
== NULL_TREE
)
7322 error ("switch quantity not an integer");
7323 exp
= error_mark_node
;
7325 type
= TREE_TYPE (exp
);
7326 code
= TREE_CODE (type
);
7328 if (code
!= INTEGER_TYPE
&& code
!= ENUMERAL_TYPE
&& code
!= ERROR_MARK
)
7330 error ("switch quantity not an integer");
7331 exp
= error_mark_node
;
7337 exp
= default_conversion (exp
);
7338 type
= TREE_TYPE (exp
);
7339 idx
= get_unwidened (exp
, 0);
7340 /* We can't strip a conversion from a signed type to an unsigned,
7341 because if we did, int_fits_type_p would do the wrong thing
7342 when checking case values for being in range,
7343 and it's too hard to do the right thing. */
7344 if (TREE_UNSIGNED (TREE_TYPE (exp
))
7345 == TREE_UNSIGNED (TREE_TYPE (idx
)))
7350 (1, fold (build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (exp
), exp
)),
7351 type
, "switch statement");
7356 /* CONSTP remembers whether or not all the intervening pointers in the `to'
7357 type have been const. */
7360 comp_ptr_ttypes_real (to
, from
, constp
)
7364 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7366 if (TREE_CODE (to
) != TREE_CODE (from
))
7369 if (TREE_CODE (from
) == OFFSET_TYPE
7370 && comptypes (TYPE_OFFSET_BASETYPE (from
),
7371 TYPE_OFFSET_BASETYPE (to
), 1))
7374 /* Const and volatile mean something different for function types,
7375 so the usual checks are not appropriate. */
7376 if (TREE_CODE (to
) != FUNCTION_TYPE
&& TREE_CODE (to
) != METHOD_TYPE
)
7378 if (TYPE_READONLY (from
) > TYPE_READONLY (to
)
7379 || TYPE_VOLATILE (from
) > TYPE_VOLATILE (to
))
7383 && (TYPE_READONLY (to
) > TYPE_READONLY (from
)
7384 || TYPE_VOLATILE (to
) > TYPE_READONLY (from
)))
7386 constp
&= TYPE_READONLY (to
);
7389 if (TREE_CODE (to
) != POINTER_TYPE
)
7390 return comptypes (TYPE_MAIN_VARIANT (to
), TYPE_MAIN_VARIANT (from
), 1);
7394 /* When comparing, say, char ** to char const **, this function takes the
7395 'char *' and 'char const *'. Do not pass non-pointer types to this
7399 comp_ptr_ttypes (to
, from
)
7402 return comp_ptr_ttypes_real (to
, from
, 1);
7405 /* Returns 1 if to and from are (possibly multi-level) pointers to the same
7406 type or inheritance-related types, regardless of cv-quals. */
7409 ptr_reasonably_similar (to
, from
)
7412 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7414 if (TREE_CODE (to
) != TREE_CODE (from
))
7417 if (TREE_CODE (from
) == OFFSET_TYPE
7418 && comptypes (TYPE_OFFSET_BASETYPE (to
),
7419 TYPE_OFFSET_BASETYPE (from
), -1))
7422 if (TREE_CODE (to
) != POINTER_TYPE
)
7424 (TYPE_MAIN_VARIANT (to
), TYPE_MAIN_VARIANT (from
), -1);
7428 /* Like comp_ptr_ttypes, for const_cast. */
7431 comp_ptr_ttypes_const (to
, from
)
7434 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7436 if (TREE_CODE (to
) != TREE_CODE (from
))
7439 if (TREE_CODE (from
) == OFFSET_TYPE
7440 && comptypes (TYPE_OFFSET_BASETYPE (from
),
7441 TYPE_OFFSET_BASETYPE (to
), 1))
7444 if (TREE_CODE (to
) != POINTER_TYPE
)
7445 return comptypes (TYPE_MAIN_VARIANT (to
), TYPE_MAIN_VARIANT (from
), 1);
7449 /* Like comp_ptr_ttypes, for reinterpret_cast. */
7452 comp_ptr_ttypes_reinterpret (to
, from
)
7457 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7459 if (TREE_CODE (from
) == OFFSET_TYPE
)
7460 from
= TREE_TYPE (from
);
7461 if (TREE_CODE (to
) == OFFSET_TYPE
)
7462 to
= TREE_TYPE (to
);
7464 if (TREE_CODE (to
) != TREE_CODE (from
))
7467 /* Const and volatile mean something different for function types,
7468 so the usual checks are not appropriate. */
7469 if (TREE_CODE (to
) != FUNCTION_TYPE
&& TREE_CODE (to
) != METHOD_TYPE
)
7471 if (TYPE_READONLY (from
) > TYPE_READONLY (to
)
7472 || TYPE_VOLATILE (from
) > TYPE_VOLATILE (to
))
7476 && (TYPE_READONLY (to
) > TYPE_READONLY (from
)
7477 || TYPE_VOLATILE (to
) > TYPE_READONLY (from
)))
7479 constp
&= TYPE_READONLY (to
);
7482 if (TREE_CODE (to
) != POINTER_TYPE
)