1 /* Build expressions with type checking for C++ compiler.
2 Copyright (C) 1987, 88, 89, 92, 93, 94, 95, 1996 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). */
45 extern void compiler_error ();
47 static tree convert_for_assignment
PROTO((tree
, tree
, char*, tree
,
49 static tree pointer_int_sum
PROTO((enum tree_code
, tree
, tree
));
50 static tree rationalize_conditional_expr
PROTO((enum tree_code
, tree
));
51 static int comp_target_parms
PROTO((tree
, tree
, int));
52 static int comp_ptr_ttypes_real
PROTO((tree
, tree
, int));
53 static int comp_ptr_ttypes_const
PROTO((tree
, tree
));
54 static int comp_ptr_ttypes_reinterpret
PROTO((tree
, tree
));
55 static int comp_array_types
PROTO((int (*) (tree
, tree
, int), tree
,
57 static tree build_ptrmemfunc1
PROTO((tree
, tree
, tree
, tree
, tree
));
58 static tree common_base_type
PROTO((tree
, tree
));
59 static tree convert_sequence
PROTO((tree
, tree
));
60 static tree lookup_anon_field
PROTO((tree
, tree
));
61 static tree pointer_diff
PROTO((tree
, tree
));
62 static tree qualify_type
PROTO((tree
, tree
));
63 static tree expand_target_expr
PROTO((tree
));
64 static tree get_delta_difference
PROTO((tree
, tree
, int));
66 /* Return the target type of TYPE, which meas return T for:
67 T*, T&, T[], T (...), and otherwise, just T. */
73 if (TREE_CODE (type
) == REFERENCE_TYPE
)
74 type
= TREE_TYPE (type
);
75 while (TREE_CODE (type
) == POINTER_TYPE
76 || TREE_CODE (type
) == ARRAY_TYPE
77 || TREE_CODE (type
) == FUNCTION_TYPE
78 || TREE_CODE (type
) == METHOD_TYPE
79 || TREE_CODE (type
) == OFFSET_TYPE
)
80 type
= TREE_TYPE (type
);
84 /* Do `exp = require_complete_type (exp);' to make sure exp
85 does not have an incomplete type. (That includes void types.) */
88 require_complete_type (value
)
93 if (processing_template_decl
)
96 type
= TREE_TYPE (value
);
98 /* First, detect a valid value with a complete type. */
99 if (TYPE_SIZE (type
) != 0
100 && type
!= void_type_node
101 && ! (TYPE_LANG_SPECIFIC (type
)
102 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
))
103 && TYPE_SIZE (SIGNATURE_TYPE (type
)) == 0))
106 /* If we see X::Y, we build an OFFSET_TYPE which has
107 not been laid out. Try to avoid an error by interpreting
108 it as this->X::Y, if reasonable. */
109 if (TREE_CODE (value
) == OFFSET_REF
110 && current_class_ref
!= 0
111 && TREE_OPERAND (value
, 0) == current_class_ref
)
113 tree base
, member
= TREE_OPERAND (value
, 1);
114 tree basetype
= TYPE_OFFSET_BASETYPE (type
);
115 my_friendly_assert (TREE_CODE (member
) == FIELD_DECL
, 305);
116 base
= convert_pointer_to (basetype
, current_class_ptr
);
117 value
= build (COMPONENT_REF
, TREE_TYPE (member
),
118 build_indirect_ref (base
, NULL_PTR
), member
);
119 return require_complete_type (value
);
122 if (IS_AGGR_TYPE (type
) && CLASSTYPE_TEMPLATE_INSTANTIATION (type
))
124 instantiate_class_template (TYPE_MAIN_VARIANT (type
));
125 if (TYPE_SIZE (type
) != 0)
129 incomplete_type_error (value
, type
);
130 return error_mark_node
;
137 if (type
== error_mark_node
|| TYPE_SIZE (type
) != NULL_TREE
)
139 else if (TREE_CODE (type
) == ARRAY_TYPE
&& TYPE_DOMAIN (type
))
141 tree t
= complete_type (TREE_TYPE (type
));
142 if (TYPE_SIZE (t
) != NULL_TREE
&& ! processing_template_decl
)
144 TYPE_NEEDS_CONSTRUCTING (type
)
145 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (t
));
146 TYPE_NEEDS_DESTRUCTOR (type
)
147 = TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (t
));
149 else if (IS_AGGR_TYPE (type
) && CLASSTYPE_TEMPLATE_INSTANTIATION (type
))
150 instantiate_class_template (TYPE_MAIN_VARIANT (type
));
155 /* Return truthvalue of whether type of EXP is instantiated. */
161 return (TREE_CODE (exp
) == TREE_LIST
162 || TREE_TYPE (exp
) == unknown_type_node
163 || (TREE_CODE (TREE_TYPE (exp
)) == OFFSET_TYPE
164 && TREE_TYPE (TREE_TYPE (exp
)) == unknown_type_node
));
167 /* Return truthvalue of whether T is function (or pfn) type. */
173 return (TREE_CODE (t
) == FUNCTION_TYPE
|| TREE_CODE (t
) == METHOD_TYPE
174 || (TREE_CODE (t
) == POINTER_TYPE
175 && (TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
176 || TREE_CODE (TREE_TYPE (t
)) == METHOD_TYPE
)));
179 /* Do `exp = require_instantiated_type (type, exp);' to make sure EXP
180 does not have an uninstantiated type.
181 TYPE is type to instantiate with, if uninstantiated. */
184 require_instantiated_type (type
, exp
, errval
)
185 tree type
, exp
, errval
;
187 if (TREE_TYPE (exp
) == NULL_TREE
)
189 error ("argument list may not have an initializer list");
193 if (TREE_TYPE (exp
) == unknown_type_node
194 || (TREE_CODE (TREE_TYPE (exp
)) == OFFSET_TYPE
195 && TREE_TYPE (TREE_TYPE (exp
)) == unknown_type_node
))
197 exp
= instantiate_type (type
, exp
, 1);
198 if (TREE_TYPE (exp
) == error_mark_node
)
204 /* Return a variant of TYPE which has all the type qualifiers of LIKE
205 as well as those of TYPE. */
208 qualify_type (type
, like
)
211 int constflag
= TYPE_READONLY (type
) || TYPE_READONLY (like
);
212 int volflag
= TYPE_VOLATILE (type
) || TYPE_VOLATILE (like
);
213 /* @@ Must do member pointers here. */
214 return cp_build_type_variant (type
, constflag
, volflag
);
217 /* Return the common type of two parameter lists.
218 We assume that comptypes has already been done and returned 1;
219 if that isn't so, this may crash.
221 As an optimization, free the space we allocate if the parameter
222 lists are already common. */
228 tree oldargs
= p1
, newargs
, n
;
231 char *first_obj
= (char *) oballoc (0);
233 len
= list_length (p1
);
234 newargs
= tree_last (p1
);
236 if (newargs
== void_list_node
)
245 newargs
= tree_cons (NULL_TREE
, NULL_TREE
, newargs
);
250 p1
= TREE_CHAIN (p1
), p2
= TREE_CHAIN (p2
), n
= TREE_CHAIN (n
), i
++)
252 if (TREE_PURPOSE (p1
) && !TREE_PURPOSE (p2
))
254 TREE_PURPOSE (n
) = TREE_PURPOSE (p1
);
257 else if (! TREE_PURPOSE (p1
))
259 if (TREE_PURPOSE (p2
))
261 TREE_PURPOSE (n
) = TREE_PURPOSE (p2
);
267 if (1 != simple_cst_equal (TREE_PURPOSE (p1
), TREE_PURPOSE (p2
)))
269 TREE_PURPOSE (n
) = TREE_PURPOSE (p2
);
271 if (TREE_VALUE (p1
) != TREE_VALUE (p2
))
274 TREE_VALUE (n
) = common_type (TREE_VALUE (p1
), TREE_VALUE (p2
));
277 TREE_VALUE (n
) = TREE_VALUE (p1
);
288 /* Return the common type of two types.
289 We assume that comptypes has already been done and returned 1;
290 if that isn't so, this may crash.
292 This is the type for the result of most arithmetic operations
293 if the operands have the given two types.
295 We do not deal with enumeral types here because they have already been
296 converted to integer types. */
302 register enum tree_code code1
;
303 register enum tree_code code2
;
306 /* Save time if the two types are the same. */
308 if (t1
== t2
) return t1
;
310 /* If one type is nonsense, use the other. */
311 if (t1
== error_mark_node
)
313 if (t2
== error_mark_node
)
316 /* Merge the attributes */
318 { register tree a1
, a2
;
319 a1
= TYPE_ATTRIBUTES (t1
);
320 a2
= TYPE_ATTRIBUTES (t2
);
322 /* Either one unset? Take the set one. */
324 if (!(attributes
= a1
))
327 /* One that completely contains the other? Take it. */
329 else if (a2
&& !attribute_list_contained (a1
, a2
))
330 if (attribute_list_contained (a2
, a1
))
334 /* Pick the longest list, and hang on the other list. */
335 /* ??? For the moment we punt on the issue of attrs with args. */
337 if (list_length (a1
) < list_length (a2
))
338 attributes
= a2
, a2
= a1
;
340 for (; a2
; a2
= TREE_CHAIN (a2
))
341 if (lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2
)),
342 attributes
) == NULL_TREE
)
345 TREE_CHAIN (a1
) = attributes
;
351 /* Treat an enum type as the unsigned integer type of the same width. */
353 if (TREE_CODE (t1
) == ENUMERAL_TYPE
)
354 t1
= type_for_size (TYPE_PRECISION (t1
), 1);
355 if (TREE_CODE (t2
) == ENUMERAL_TYPE
)
356 t2
= type_for_size (TYPE_PRECISION (t2
), 1);
358 if (TYPE_PTRMEMFUNC_P (t1
))
359 t1
= TYPE_PTRMEMFUNC_FN_TYPE (t1
);
360 if (TYPE_PTRMEMFUNC_P (t2
))
361 t2
= TYPE_PTRMEMFUNC_FN_TYPE (t2
);
363 code1
= TREE_CODE (t1
);
364 code2
= TREE_CODE (t2
);
366 /* If one type is complex, form the common type of the non-complex
367 components, then make that complex. Use T1 or T2 if it is the
369 if (code1
== COMPLEX_TYPE
|| code2
== COMPLEX_TYPE
)
371 tree subtype1
= code1
== COMPLEX_TYPE
? TREE_TYPE (t1
) : t1
;
372 tree subtype2
= code2
== COMPLEX_TYPE
? TREE_TYPE (t2
) : t2
;
373 tree subtype
= common_type (subtype1
, subtype2
);
375 if (code1
== COMPLEX_TYPE
&& TREE_TYPE (t1
) == subtype
)
376 return build_type_attribute_variant (t1
, attributes
);
377 else if (code2
== COMPLEX_TYPE
&& TREE_TYPE (t2
) == subtype
)
378 return build_type_attribute_variant (t2
, attributes
);
380 return build_type_attribute_variant (build_complex_type (subtype
),
388 /* If only one is real, use it as the result. */
390 if (code1
== REAL_TYPE
&& code2
!= REAL_TYPE
)
391 return build_type_attribute_variant (t1
, attributes
);
393 if (code2
== REAL_TYPE
&& code1
!= REAL_TYPE
)
394 return build_type_attribute_variant (t2
, attributes
);
396 /* Both real or both integers; use the one with greater precision. */
398 if (TYPE_PRECISION (t1
) > TYPE_PRECISION (t2
))
399 return build_type_attribute_variant (t1
, attributes
);
400 else if (TYPE_PRECISION (t2
) > TYPE_PRECISION (t1
))
401 return build_type_attribute_variant (t2
, attributes
);
403 /* Same precision. Prefer longs to ints even when same size. */
405 if (TYPE_MAIN_VARIANT (t1
) == long_unsigned_type_node
406 || TYPE_MAIN_VARIANT (t2
) == long_unsigned_type_node
)
407 return build_type_attribute_variant (long_unsigned_type_node
,
410 if (TYPE_MAIN_VARIANT (t1
) == long_integer_type_node
411 || TYPE_MAIN_VARIANT (t2
) == long_integer_type_node
)
413 /* But preserve unsignedness from the other type,
414 since long cannot hold all the values of an unsigned int. */
415 if (TREE_UNSIGNED (t1
) || TREE_UNSIGNED (t2
))
416 t1
= long_unsigned_type_node
;
418 t1
= long_integer_type_node
;
419 return build_type_attribute_variant (t1
, attributes
);
422 if (TYPE_MAIN_VARIANT (t1
) == long_double_type_node
423 || TYPE_MAIN_VARIANT (t2
) == long_double_type_node
)
424 return build_type_attribute_variant (long_double_type_node
,
427 /* Otherwise prefer the unsigned one. */
429 if (TREE_UNSIGNED (t1
))
430 return build_type_attribute_variant (t1
, attributes
);
432 return build_type_attribute_variant (t2
, attributes
);
436 /* For two pointers, do this recursively on the target type,
437 and combine the qualifiers of the two types' targets. */
438 /* This code was turned off; I don't know why.
439 But ANSI C++ specifies doing this with the qualifiers.
440 So I turned it on again. */
442 tree tt1
= TYPE_MAIN_VARIANT (TREE_TYPE (t1
));
443 tree tt2
= TYPE_MAIN_VARIANT (TREE_TYPE (t2
));
445 = TYPE_READONLY (TREE_TYPE (t1
)) || TYPE_READONLY (TREE_TYPE (t2
));
447 = TYPE_VOLATILE (TREE_TYPE (t1
)) || TYPE_VOLATILE (TREE_TYPE (t2
));
452 else if (tt1
== void_type_node
|| tt2
== void_type_node
)
453 target
= void_type_node
;
455 target
= common_type (tt1
, tt2
);
457 target
= cp_build_type_variant (target
, constp
, volatilep
);
458 if (code1
== POINTER_TYPE
)
459 t1
= build_pointer_type (target
);
461 t1
= build_reference_type (target
);
462 t1
= build_type_attribute_variant (t1
, attributes
);
464 if (TREE_CODE (target
) == METHOD_TYPE
)
465 t1
= build_ptrmemfunc_type (t1
);
472 tree elt
= common_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
473 /* Save space: see if the result is identical to one of the args. */
474 if (elt
== TREE_TYPE (t1
) && TYPE_DOMAIN (t1
))
475 return build_type_attribute_variant (t1
, attributes
);
476 if (elt
== TREE_TYPE (t2
) && TYPE_DOMAIN (t2
))
477 return build_type_attribute_variant (t2
, attributes
);
478 /* Merge the element types, and have a size if either arg has one. */
479 t1
= build_cplus_array_type
480 (elt
, TYPE_DOMAIN (TYPE_DOMAIN (t1
) ? t1
: t2
));
481 return build_type_attribute_variant (t1
, attributes
);
485 /* Function types: prefer the one that specified arg types.
486 If both do, merge the arg types. Also merge the return types. */
488 tree valtype
= common_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
489 tree p1
= TYPE_ARG_TYPES (t1
);
490 tree p2
= TYPE_ARG_TYPES (t2
);
493 /* Save space: see if the result is identical to one of the args. */
494 if (valtype
== TREE_TYPE (t1
) && ! p2
)
495 return build_type_attribute_variant (t1
, attributes
);
496 if (valtype
== TREE_TYPE (t2
) && ! p1
)
497 return build_type_attribute_variant (t2
, attributes
);
499 /* Simple way if one arg fails to specify argument types. */
500 if (p1
== NULL_TREE
|| TREE_VALUE (p1
) == void_type_node
)
502 rval
= build_function_type (valtype
, p2
);
503 if ((raises
= TYPE_RAISES_EXCEPTIONS (t2
)))
504 rval
= build_exception_variant (rval
, raises
);
505 return build_type_attribute_variant (rval
, attributes
);
507 raises
= TYPE_RAISES_EXCEPTIONS (t1
);
508 if (p2
== NULL_TREE
|| TREE_VALUE (p2
) == void_type_node
)
510 rval
= build_function_type (valtype
, p1
);
512 rval
= build_exception_variant (rval
, raises
);
513 return build_type_attribute_variant (rval
, attributes
);
516 rval
= build_function_type (valtype
, commonparms (p1
, p2
));
517 rval
= build_exception_variant (rval
, raises
);
518 return build_type_attribute_variant (rval
, attributes
);
523 my_friendly_assert (TYPE_MAIN_VARIANT (t1
) == t1
524 && TYPE_MAIN_VARIANT (t2
) == t2
, 306);
526 if (DERIVED_FROM_P (t1
, t2
) && binfo_or_else (t1
, t2
))
527 return build_type_attribute_variant (t1
, attributes
);
528 else if (binfo_or_else (t2
, t1
))
529 return build_type_attribute_variant (t2
, attributes
);
531 compiler_error ("common_type called with uncommon aggregate types");
534 if (TREE_CODE (TREE_TYPE (t1
)) == TREE_CODE (TREE_TYPE (t2
)))
536 /* Get this value the long way, since TYPE_METHOD_BASETYPE
537 is just the main variant of this. */
541 tree b1
= TYPE_OFFSET_BASETYPE (t1
);
542 tree b2
= TYPE_OFFSET_BASETYPE (t2
);
544 if (comptypes (b1
, b2
, 1)
545 || (DERIVED_FROM_P (b1
, b2
) && binfo_or_else (b1
, b2
)))
546 basetype
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t2
)));
549 if (binfo_or_else (b2
, b1
) == NULL_TREE
)
550 compiler_error ("common_type called with uncommon method types");
551 basetype
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t1
)));
554 raises
= TYPE_RAISES_EXCEPTIONS (t1
);
556 /* If this was a member function type, get back to the
557 original type of type member function (i.e., without
558 the class instance variable up front. */
559 t1
= build_function_type (TREE_TYPE (t1
), TREE_CHAIN (TYPE_ARG_TYPES (t1
)));
560 t2
= build_function_type (TREE_TYPE (t2
), TREE_CHAIN (TYPE_ARG_TYPES (t2
)));
561 t3
= common_type (t1
, t2
);
562 t3
= build_cplus_method_type (basetype
, TREE_TYPE (t3
), TYPE_ARG_TYPES (t3
));
563 t1
= build_exception_variant (t3
, raises
);
566 compiler_error ("common_type called with uncommon method types");
568 return build_type_attribute_variant (t1
, attributes
);
571 if (TREE_TYPE (t1
) == TREE_TYPE (t2
))
573 tree b1
= TYPE_OFFSET_BASETYPE (t1
);
574 tree b2
= TYPE_OFFSET_BASETYPE (t2
);
576 if (comptypes (b1
, b2
, 1)
577 || (DERIVED_FROM_P (b1
, b2
) && binfo_or_else (b1
, b2
)))
578 return build_type_attribute_variant (t2
, attributes
);
579 else if (binfo_or_else (b2
, b1
))
580 return build_type_attribute_variant (t1
, attributes
);
582 compiler_error ("common_type called with uncommon member types");
585 return build_type_attribute_variant (t1
, attributes
);
589 /* Return 1 if TYPE1 and TYPE2 raise the same exceptions. */
592 compexcepttypes (t1
, t2
)
595 return TYPE_RAISES_EXCEPTIONS (t1
) == TYPE_RAISES_EXCEPTIONS (t2
);
599 comp_array_types (cmp
, t1
, t2
, strict
)
600 register int (*cmp
) PROTO((tree
, tree
, int));
604 tree d1
= TYPE_DOMAIN (t1
);
605 tree d2
= TYPE_DOMAIN (t2
);
607 /* Target types must match incl. qualifiers. */
608 if (!(TREE_TYPE (t1
) == TREE_TYPE (t2
)
609 || (*cmp
) (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
)))
612 /* Sizes must match unless one is missing or variable. */
613 if (d1
== 0 || d2
== 0 || d1
== d2
614 || TREE_CODE (TYPE_MIN_VALUE (d1
)) != INTEGER_CST
615 || TREE_CODE (TYPE_MIN_VALUE (d2
)) != INTEGER_CST
616 || TREE_CODE (TYPE_MAX_VALUE (d1
)) != INTEGER_CST
617 || TREE_CODE (TYPE_MAX_VALUE (d2
)) != INTEGER_CST
)
620 return ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1
))
621 == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2
)))
622 && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1
))
623 == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2
)))
624 && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1
))
625 == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2
)))
626 && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1
))
627 == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2
))));
630 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
631 or various other operations. This is what ANSI C++ speaks of as
634 For C++: argument STRICT says we should be strict about this
637 2 : strict, except that if one type is a reference and
638 the other is not, compare the target type of the
639 reference to the type that's not a reference (ARM, p308).
640 This is used for checking for invalid overloading.
641 1 : strict (compared according to ANSI C)
642 This is used for checking whether two function decls match.
643 0 : <= (compared according to C++)
644 -1: <= or >= (relaxed)
646 Otherwise, pointers involving base classes and derived classes
647 can be mixed as valid: i.e. a pointer to a base class may be assigned
648 to a pointer to one of its derived classes, as per C++. A pointer to
649 a derived class may be passed as a parameter to a function expecting a
650 pointer to a base classes. These allowances do not commute. In this
651 case, TYPE1 is assumed to be the base class, and TYPE2 is assumed to
652 be the derived class. */
655 comptypes (type1
, type2
, strict
)
659 register tree t1
= type1
;
660 register tree t2
= type2
;
663 /* Suppress errors caused by previously reported errors */
668 /* This should never happen. */
669 my_friendly_assert (t1
!= error_mark_node
, 307);
671 if (t2
== error_mark_node
)
676 /* Treat an enum type as the unsigned integer type of the same width. */
678 if (TREE_CODE (t1
) == ENUMERAL_TYPE
)
679 t1
= type_for_size (TYPE_PRECISION (t1
), 1);
680 if (TREE_CODE (t2
) == ENUMERAL_TYPE
)
681 t2
= type_for_size (TYPE_PRECISION (t2
), 1);
687 if (TYPE_PTRMEMFUNC_P (t1
))
688 t1
= TYPE_PTRMEMFUNC_FN_TYPE (t1
);
689 if (TYPE_PTRMEMFUNC_P (t2
))
690 t2
= TYPE_PTRMEMFUNC_FN_TYPE (t2
);
692 /* Different classes of types can't be compatible. */
694 if (TREE_CODE (t1
) != TREE_CODE (t2
))
697 && ((TREE_CODE (t1
) == REFERENCE_TYPE
)
698 ^ (TREE_CODE (t2
) == REFERENCE_TYPE
)))
700 if (TREE_CODE (t1
) == REFERENCE_TYPE
)
701 return comptypes (TREE_TYPE (t1
), t2
, 1);
702 return comptypes (t1
, TREE_TYPE (t2
), 1);
710 /* Qualifiers must match. */
712 if (TYPE_READONLY (t1
) != TYPE_READONLY (t2
))
714 if (TYPE_VOLATILE (t1
) != TYPE_VOLATILE (t2
))
717 /* Allow for two different type nodes which have essentially the same
718 definition. Note that we already checked for equality of the type
719 type qualifiers (just above). */
721 if (TYPE_MAIN_VARIANT (t1
) == TYPE_MAIN_VARIANT (t2
))
724 /* ??? COMP_TYPE_ATTRIBUTES is currently useless for variables as each
725 attribute is its own main variant (`val' will remain 0). */
726 #ifndef COMP_TYPE_ATTRIBUTES
727 #define COMP_TYPE_ATTRIBUTES(t1,t2) 1
730 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
731 if (! (attrval
= COMP_TYPE_ATTRIBUTES (t1
, t2
)))
734 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
737 switch (TREE_CODE (t1
))
741 if (CLASSTYPE_TEMPLATE_INFO (t1
) && CLASSTYPE_TEMPLATE_INFO (t2
)
742 && CLASSTYPE_TI_TEMPLATE (t1
) == CLASSTYPE_TI_TEMPLATE (t2
))
744 int i
= TREE_VEC_LENGTH (CLASSTYPE_TI_ARGS (t1
));
745 tree
*p1
= &TREE_VEC_ELT (CLASSTYPE_TI_ARGS (t1
), 0);
746 tree
*p2
= &TREE_VEC_ELT (CLASSTYPE_TI_ARGS (t2
), 0);
750 if (TREE_CODE_CLASS (TREE_CODE (p1
[i
])) == 't')
752 if (! comptypes (p1
[i
], p2
[i
], 1))
757 if (simple_cst_equal (p1
[i
], p2
[i
]) <= 0)
768 val
= (comptypes (build_pointer_type (TYPE_OFFSET_BASETYPE (t1
)),
769 build_pointer_type (TYPE_OFFSET_BASETYPE (t2
)), strict
)
770 && comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
));
774 if (! compexcepttypes (t1
, t2
))
777 /* This case is anti-symmetrical!
778 One can pass a base member (or member function)
779 to something expecting a derived member (or member function),
780 but not vice-versa! */
782 val
= (comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
)
783 && compparms (TYPE_ARG_TYPES (t1
),
784 TYPE_ARG_TYPES (t2
), strict
));
798 if (TREE_CODE (t1
) == RECORD_TYPE
&& TREE_CODE (t2
) == RECORD_TYPE
)
802 rval
= t1
== t2
|| DERIVED_FROM_P (t1
, t2
);
811 val
= DERIVED_FROM_P (t2
, t1
);
818 val
= comptypes (t1
, t2
, strict
);
822 if (! compexcepttypes (t1
, t2
))
825 val
= ((TREE_TYPE (t1
) == TREE_TYPE (t2
)
826 || comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
))
827 && compparms (TYPE_ARG_TYPES (t1
), TYPE_ARG_TYPES (t2
), strict
));
831 /* Target types must match incl. qualifiers. */
832 val
= comp_array_types (comptypes
, t1
, t2
, strict
);
835 case TEMPLATE_TYPE_PARM
:
836 return TEMPLATE_TYPE_IDX (t1
) == TEMPLATE_TYPE_IDX (t2
)
837 && TEMPLATE_TYPE_LEVEL (t1
) == TEMPLATE_TYPE_LEVEL (t2
);
840 if (TYPE_IDENTIFIER (t1
) != TYPE_IDENTIFIER (t2
))
842 return comptypes (TYPE_CONTEXT (t1
), TYPE_CONTEXT (t2
), 1);
844 return attrval
== 2 && val
== 1 ? 2 : val
;
847 /* Return 1 if TTL and TTR are pointers to types that are equivalent,
848 ignoring their qualifiers.
850 NPTRS is the number of pointers we can strip off and keep cool.
851 This is used to permit (for aggr A, aggr B) A, B* to convert to A*,
852 but to not permit B** to convert to A**. */
855 comp_target_types (ttl
, ttr
, nptrs
)
859 ttl
= TYPE_MAIN_VARIANT (ttl
);
860 ttr
= TYPE_MAIN_VARIANT (ttr
);
864 if (TREE_CODE (ttr
) != TREE_CODE (ttl
))
867 if (TREE_CODE (ttr
) == POINTER_TYPE
)
869 ttl
= TREE_TYPE (ttl
);
870 ttr
= TREE_TYPE (ttr
);
874 if (TREE_CODE (ttl
) == VOID_TYPE
875 && TREE_CODE (ttr
) != FUNCTION_TYPE
876 && TREE_CODE (ttr
) != METHOD_TYPE
877 && TREE_CODE (ttr
) != OFFSET_TYPE
)
879 else if (TREE_CODE (ttr
) == VOID_TYPE
880 && TREE_CODE (ttl
) != FUNCTION_TYPE
881 && TREE_CODE (ttl
) != METHOD_TYPE
882 && TREE_CODE (ttl
) != OFFSET_TYPE
)
884 else if (TREE_CODE (ttl
) == POINTER_TYPE
885 || TREE_CODE (ttl
) == ARRAY_TYPE
)
887 if (comp_ptr_ttypes (ttl
, ttr
))
889 else if (comp_ptr_ttypes (ttr
, ttl
))
895 /* Const and volatile mean something different for function types,
896 so the usual checks are not appropriate. */
897 if (TREE_CODE (ttl
) == FUNCTION_TYPE
|| TREE_CODE (ttl
) == METHOD_TYPE
)
898 return comp_target_types (ttl
, ttr
, nptrs
- 1);
900 /* Make sure that the cv-quals change only in the same direction as
904 int c
= TYPE_READONLY (ttl
) - TYPE_READONLY (ttr
);
905 int v
= TYPE_VOLATILE (ttl
) - TYPE_VOLATILE (ttr
);
907 if ((c
> 0 && v
< 0) || (c
< 0 && v
> 0))
910 if (TYPE_MAIN_VARIANT (ttl
) == TYPE_MAIN_VARIANT (ttr
))
911 return (c
+ v
< 0) ? -1 : 1;
913 t
= comp_target_types (ttl
, ttr
, nptrs
- 1);
914 if ((t
== 1 && c
+ v
>= 0) || (t
== -1 && c
+ v
<= 0))
921 if (TREE_CODE (ttr
) == REFERENCE_TYPE
)
922 return comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
);
923 if (TREE_CODE (ttr
) == ARRAY_TYPE
)
924 return comp_array_types (comp_target_types
, ttl
, ttr
, 0);
925 else if (TREE_CODE (ttr
) == FUNCTION_TYPE
|| TREE_CODE (ttr
) == METHOD_TYPE
)
926 if (comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
))
927 switch (comp_target_parms (TYPE_ARG_TYPES (ttl
), TYPE_ARG_TYPES (ttr
), 1))
936 my_friendly_abort (112);
942 else if (TREE_CODE (ttr
) == OFFSET_TYPE
)
944 /* Contravariance: we can assign a pointer to base member to a pointer
945 to derived member. Note difference from simple pointer case, where
946 we can pass a pointer to derived to a pointer to base. */
947 if (comptypes (TYPE_OFFSET_BASETYPE (ttr
), TYPE_OFFSET_BASETYPE (ttl
), 0))
948 return comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
);
949 else if (comptypes (TYPE_OFFSET_BASETYPE (ttl
), TYPE_OFFSET_BASETYPE (ttr
), 0)
950 && comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
))
953 else if (IS_AGGR_TYPE (ttl
))
957 if (comptypes (build_pointer_type (ttl
), build_pointer_type (ttr
), 0))
959 if (comptypes (build_pointer_type (ttr
), build_pointer_type (ttl
), 0))
967 /* If two types share a common base type, return that basetype.
968 If there is not a unique most-derived base type, this function
969 returns ERROR_MARK_NODE. */
972 common_base_type (tt1
, tt2
)
975 tree best
= NULL_TREE
;
978 /* If one is a baseclass of another, that's good enough. */
979 if (UNIQUELY_DERIVED_FROM_P (tt1
, tt2
))
981 if (UNIQUELY_DERIVED_FROM_P (tt2
, tt1
))
984 /* Otherwise, try to find a unique baseclass of TT1
985 that is shared by TT2, and follow that down. */
986 for (i
= CLASSTYPE_N_BASECLASSES (tt1
)-1; i
>= 0; i
--)
988 tree basetype
= TYPE_BINFO_BASETYPE (tt1
, i
);
989 tree trial
= common_base_type (basetype
, tt2
);
992 if (trial
== error_mark_node
)
994 if (best
== NULL_TREE
)
996 else if (best
!= trial
)
997 return error_mark_node
;
1002 for (i
= CLASSTYPE_N_BASECLASSES (tt2
)-1; i
>= 0; i
--)
1004 tree basetype
= TYPE_BINFO_BASETYPE (tt2
, i
);
1005 tree trial
= common_base_type (tt1
, basetype
);
1008 if (trial
== error_mark_node
)
1010 if (best
== NULL_TREE
)
1012 else if (best
!= trial
)
1013 return error_mark_node
;
1019 /* Subroutines of `comptypes'. */
1021 /* Return 1 if two parameter type lists PARMS1 and PARMS2
1022 are equivalent in the sense that functions with those parameter types
1023 can have equivalent types.
1024 If either list is empty, we win.
1025 Otherwise, the two lists must be equivalent, element by element.
1027 C++: See comment above about TYPE1, TYPE2, STRICT.
1028 If STRICT == 3, it means checking is strict, but do not compare
1029 default parameter values. */
1032 compparms (parms1
, parms2
, strict
)
1033 tree parms1
, parms2
;
1036 register tree t1
= parms1
, t2
= parms2
;
1038 /* An unspecified parmlist matches any specified parmlist
1039 whose argument types don't need default promotions. */
1041 if (strict
<= 0 && t1
== 0)
1042 return self_promoting_args_p (t2
);
1043 if (strict
< 0 && t2
== 0)
1044 return self_promoting_args_p (t1
);
1048 if (t1
== 0 && t2
== 0)
1050 /* If one parmlist is shorter than the other,
1051 they fail to match, unless STRICT is <= 0. */
1052 if (t1
== 0 || t2
== 0)
1059 return t1
&& TREE_PURPOSE (t1
);
1061 if (! comptypes (TREE_VALUE (t2
), TREE_VALUE (t1
), strict
))
1066 return t2
== void_list_node
&& TREE_PURPOSE (t1
);
1067 return TREE_PURPOSE (t1
) || TREE_PURPOSE (t2
);
1070 t1
= TREE_CHAIN (t1
);
1071 t2
= TREE_CHAIN (t2
);
1075 /* This really wants return whether or not parameter type lists
1076 would make their owning functions assignment compatible or not. */
1079 comp_target_parms (parms1
, parms2
, strict
)
1080 tree parms1
, parms2
;
1083 register tree t1
= parms1
, t2
= parms2
;
1084 int warn_contravariance
= 0;
1086 /* An unspecified parmlist matches any specified parmlist
1087 whose argument types don't need default promotions.
1088 @@@ see 13.3.3 for a counterexample... */
1090 if (t1
== 0 && t2
!= 0)
1092 cp_pedwarn ("ANSI C++ prohibits conversion from `(%#T)' to `(...)'",
1094 return self_promoting_args_p (t2
);
1097 return self_promoting_args_p (t1
);
1099 for (; t1
|| t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
1103 /* If one parmlist is shorter than the other,
1104 they fail to match, unless STRICT is <= 0. */
1105 if (t1
== 0 || t2
== 0)
1110 return 1 + warn_contravariance
;
1111 return ((t1
&& TREE_PURPOSE (t1
)) + warn_contravariance
);
1113 p1
= TREE_VALUE (t1
);
1114 p2
= TREE_VALUE (t2
);
1118 if ((TREE_CODE (p1
) == POINTER_TYPE
&& TREE_CODE (p2
) == POINTER_TYPE
)
1119 || (TREE_CODE (p1
) == REFERENCE_TYPE
&& TREE_CODE (p2
) == REFERENCE_TYPE
))
1122 && (TYPE_MAIN_VARIANT (TREE_TYPE (p1
))
1123 == TYPE_MAIN_VARIANT (TREE_TYPE (p2
))))
1126 /* The following is wrong for contravariance,
1127 but many programs depend on it. */
1128 if (TREE_TYPE (p1
) == void_type_node
)
1130 if (TREE_TYPE (p2
) == void_type_node
)
1132 warn_contravariance
= 1;
1135 if (IS_AGGR_TYPE (TREE_TYPE (p1
)))
1137 if (comptypes (p2
, p1
, 0) == 0)
1139 if (comptypes (p1
, p2
, 0) != 0)
1140 warn_contravariance
= 1;
1147 /* Note backwards order due to contravariance. */
1148 if (comp_target_types (p2
, p1
, 1) == 0)
1150 if (comp_target_types (p1
, p2
, 1))
1152 warn_contravariance
= 1;
1158 /* Target types are compatible--just make sure that if
1159 we use parameter lists, that they are ok as well. */
1160 if (TREE_CODE (p1
) == FUNCTION_TYPE
|| TREE_CODE (p1
) == METHOD_TYPE
)
1161 switch (comp_target_parms (TYPE_ARG_TYPES (p1
),
1162 TYPE_ARG_TYPES (p2
),
1170 warn_contravariance
= 1;
1173 if (TREE_PURPOSE (t1
) && TREE_PURPOSE (t2
))
1175 int cmp
= simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
));
1177 my_friendly_abort (114);
1182 return 1 + warn_contravariance
;
1185 /* Return 1 if PARMS specifies a fixed number of parameters
1186 and none of their types is affected by default promotions. */
1189 self_promoting_args_p (parms
)
1193 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
1195 register tree type
= TREE_VALUE (t
);
1197 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
1203 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
1206 if (C_PROMOTING_INTEGER_TYPE_P (type
))
1212 /* Return an unsigned type the same as TYPE in other respects.
1214 C++: must make these work for type variants as well. */
1217 unsigned_type (type
)
1220 tree type1
= TYPE_MAIN_VARIANT (type
);
1221 if (type1
== signed_char_type_node
|| type1
== char_type_node
)
1222 return unsigned_char_type_node
;
1223 if (type1
== integer_type_node
)
1224 return unsigned_type_node
;
1225 if (type1
== short_integer_type_node
)
1226 return short_unsigned_type_node
;
1227 if (type1
== long_integer_type_node
)
1228 return long_unsigned_type_node
;
1229 if (type1
== long_long_integer_type_node
)
1230 return long_long_unsigned_type_node
;
1231 if (type1
== intDI_type_node
)
1232 return unsigned_intDI_type_node
;
1233 if (type1
== intSI_type_node
)
1234 return unsigned_intSI_type_node
;
1235 if (type1
== intHI_type_node
)
1236 return unsigned_intHI_type_node
;
1237 if (type1
== intQI_type_node
)
1238 return unsigned_intQI_type_node
;
1240 return signed_or_unsigned_type (1, type
);
1243 /* Return a signed type the same as TYPE in other respects. */
1249 tree type1
= TYPE_MAIN_VARIANT (type
);
1250 if (type1
== unsigned_char_type_node
|| type1
== char_type_node
)
1251 return signed_char_type_node
;
1252 if (type1
== unsigned_type_node
)
1253 return integer_type_node
;
1254 if (type1
== short_unsigned_type_node
)
1255 return short_integer_type_node
;
1256 if (type1
== long_unsigned_type_node
)
1257 return long_integer_type_node
;
1258 if (type1
== long_long_unsigned_type_node
)
1259 return long_long_integer_type_node
;
1260 if (type1
== unsigned_intDI_type_node
)
1261 return intDI_type_node
;
1262 if (type1
== unsigned_intSI_type_node
)
1263 return intSI_type_node
;
1264 if (type1
== unsigned_intHI_type_node
)
1265 return intHI_type_node
;
1266 if (type1
== unsigned_intQI_type_node
)
1267 return intQI_type_node
;
1269 return signed_or_unsigned_type (0, type
);
1272 /* Return a type the same as TYPE except unsigned or
1273 signed according to UNSIGNEDP. */
1276 signed_or_unsigned_type (unsignedp
, type
)
1280 if (! INTEGRAL_TYPE_P (type
)
1281 || TREE_UNSIGNED (type
) == unsignedp
)
1284 if (TYPE_PRECISION (type
) == TYPE_PRECISION (signed_char_type_node
))
1285 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
1286 if (TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
))
1287 return unsignedp
? unsigned_type_node
: integer_type_node
;
1288 if (TYPE_PRECISION (type
) == TYPE_PRECISION (short_integer_type_node
))
1289 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
1290 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_integer_type_node
))
1291 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
1292 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_long_integer_type_node
))
1293 return (unsignedp
? long_long_unsigned_type_node
1294 : long_long_integer_type_node
);
1298 /* Compute the value of the `sizeof' operator. */
1304 enum tree_code code
= TREE_CODE (type
);
1307 if (processing_template_decl
)
1308 return build_min (SIZEOF_EXPR
, sizetype
, type
);
1310 if (code
== FUNCTION_TYPE
)
1312 if (pedantic
|| warn_pointer_arith
)
1313 pedwarn ("ANSI C++ forbids taking the sizeof a function type");
1314 return size_int (1);
1316 if (code
== METHOD_TYPE
)
1318 if (pedantic
|| warn_pointer_arith
)
1319 pedwarn ("ANSI C++ forbids taking the sizeof a method type");
1320 return size_int (1);
1322 if (code
== VOID_TYPE
)
1324 if (pedantic
|| warn_pointer_arith
)
1325 pedwarn ("ANSI C++ forbids taking the sizeof a void type");
1326 return size_int (1);
1328 if (code
== ERROR_MARK
)
1329 return size_int (1);
1331 /* ARM $5.3.2: ``When applied to a reference, the result is the size of the
1332 referenced object.'' */
1333 if (code
== REFERENCE_TYPE
)
1334 type
= TREE_TYPE (type
);
1336 /* We couldn't find anything in the ARM or the draft standard that says,
1337 one way or the other, if doing sizeof on something that doesn't have
1338 an object associated with it is correct or incorrect. For example, if
1339 you declare `struct S { char str[16]; };', and in your program do
1340 a `sizeof (S::str)', should we flag that as an error or should we give
1341 the size of it? Since it seems like a reasonable thing to do, we'll go
1342 with giving the value. */
1343 if (code
== OFFSET_TYPE
)
1344 type
= TREE_TYPE (type
);
1346 /* @@ This also produces an error for a signature ref.
1347 In that case we should be able to do better. */
1348 if (IS_SIGNATURE (type
))
1350 error ("`sizeof' applied to a signature type");
1351 return size_int (0);
1354 if (TYPE_SIZE (complete_type (type
)) == 0)
1356 cp_error ("`sizeof' applied to incomplete type `%T'", type
);
1357 return size_int (0);
1360 /* Convert in case a char is more than one unit. */
1361 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
1362 size_int (TYPE_PRECISION (char_type_node
)));
1363 /* size_binop does not put the constant in range, so do it now. */
1364 if (TREE_CODE (t
) == INTEGER_CST
&& force_fit_type (t
, 0))
1365 TREE_CONSTANT_OVERFLOW (t
) = TREE_OVERFLOW (t
) = 1;
1373 if (processing_template_decl
)
1374 return build_min (SIZEOF_EXPR
, sizetype
, e
);
1376 if (TREE_CODE (e
) == COMPONENT_REF
1377 && DECL_BIT_FIELD (TREE_OPERAND (e
, 1)))
1378 error ("sizeof applied to a bit-field");
1379 /* ANSI says arrays and functions are converted inside comma.
1380 But we can't really convert them in build_compound_expr
1381 because that would break commas in lvalues.
1382 So do the conversion here if operand was a comma. */
1383 if (TREE_CODE (e
) == COMPOUND_EXPR
1384 && (TREE_CODE (TREE_TYPE (e
)) == ARRAY_TYPE
1385 || TREE_CODE (TREE_TYPE (e
)) == FUNCTION_TYPE
))
1386 e
= default_conversion (e
);
1387 else if (TREE_CODE (e
) == TREE_LIST
)
1389 tree t
= TREE_VALUE (e
);
1392 && TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
1393 || is_overloaded_fn (t
)))
1394 pedwarn ("ANSI C++ forbids taking the sizeof a function type");
1396 return c_sizeof (TREE_TYPE (e
));
1400 c_sizeof_nowarn (type
)
1403 enum tree_code code
= TREE_CODE (type
);
1406 if (code
== FUNCTION_TYPE
1407 || code
== METHOD_TYPE
1408 || code
== VOID_TYPE
1409 || code
== ERROR_MARK
)
1410 return size_int (1);
1411 if (code
== REFERENCE_TYPE
)
1412 type
= TREE_TYPE (type
);
1414 if (TYPE_SIZE (type
) == 0)
1415 return size_int (0);
1417 /* Convert in case a char is more than one unit. */
1418 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
1419 size_int (TYPE_PRECISION (char_type_node
)));
1420 force_fit_type (t
, 0);
1424 /* Implement the __alignof keyword: Return the minimum required
1425 alignment of TYPE, measured in bytes. */
1431 enum tree_code code
= TREE_CODE (type
);
1434 if (code
== FUNCTION_TYPE
|| code
== METHOD_TYPE
)
1435 return size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
1437 if (code
== VOID_TYPE
|| code
== ERROR_MARK
)
1438 return size_int (1);
1440 /* C++: this is really correct! */
1441 if (code
== REFERENCE_TYPE
)
1442 type
= TREE_TYPE (type
);
1444 /* @@ This also produces an error for a signature ref.
1445 In that case we should be able to do better. */
1446 if (IS_SIGNATURE (type
))
1448 error ("`__alignof' applied to a signature type");
1449 return size_int (1);
1452 t
= size_int (TYPE_ALIGN (type
) / BITS_PER_UNIT
);
1453 force_fit_type (t
, 0);
1457 /* Perform default promotions for C data used in expressions.
1458 Arrays and functions are converted to pointers;
1459 enumeral types or short or char, to int.
1460 In addition, manifest constants symbols are replaced by their values.
1462 C++: this will automatically bash references to their target type. */
1465 decay_conversion (exp
)
1468 register tree type
= TREE_TYPE (exp
);
1469 register enum tree_code code
= TREE_CODE (type
);
1471 if (code
== OFFSET_TYPE
)
1473 if (TREE_CODE (exp
) == OFFSET_REF
)
1474 return decay_conversion (resolve_offset_ref (exp
));
1476 type
= TREE_TYPE (type
);
1477 code
= TREE_CODE (type
);
1479 if (type
== unknown_type_node
)
1481 cp_pedwarn ("assuming & on overloaded member function");
1482 return build_unary_op (ADDR_EXPR
, exp
, 0);
1486 if (code
== REFERENCE_TYPE
)
1488 exp
= convert_from_reference (exp
);
1489 type
= TREE_TYPE (exp
);
1490 code
= TREE_CODE (type
);
1493 /* Constants can be used directly unless they're not loadable. */
1494 if (TREE_CODE (exp
) == CONST_DECL
)
1495 exp
= DECL_INITIAL (exp
);
1496 /* Replace a nonvolatile const static variable with its value. */
1497 else if (TREE_READONLY_DECL_P (exp
))
1499 exp
= decl_constant_value (exp
);
1500 type
= TREE_TYPE (exp
);
1503 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
1504 Leave such NOP_EXPRs, since RHS is being used in non-lvalue context. */
1506 if (code
== VOID_TYPE
)
1508 error ("void value not ignored as it ought to be");
1509 return error_mark_node
;
1511 if (code
== FUNCTION_TYPE
)
1513 return build_unary_op (ADDR_EXPR
, exp
, 0);
1515 if (code
== METHOD_TYPE
)
1517 cp_pedwarn ("assuming & on `%E'", exp
);
1518 return build_unary_op (ADDR_EXPR
, exp
, 0);
1520 if (code
== ARRAY_TYPE
)
1525 int constp
, volatilep
;
1527 if (TREE_CODE (exp
) == INDIRECT_REF
)
1529 /* Stripping away the INDIRECT_REF is not the right
1530 thing to do for references... */
1531 tree inner
= TREE_OPERAND (exp
, 0);
1532 if (TREE_CODE (TREE_TYPE (inner
)) == REFERENCE_TYPE
)
1534 inner
= build1 (CONVERT_EXPR
,
1535 build_pointer_type (TREE_TYPE (TREE_TYPE (inner
))),
1537 TREE_CONSTANT (inner
) = TREE_CONSTANT (TREE_OPERAND (inner
, 0));
1539 return cp_convert (build_pointer_type (TREE_TYPE (type
)), inner
);
1542 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
1544 tree op1
= decay_conversion (TREE_OPERAND (exp
, 1));
1545 return build (COMPOUND_EXPR
, TREE_TYPE (op1
),
1546 TREE_OPERAND (exp
, 0), op1
);
1550 && ! (TREE_CODE (exp
) == CONSTRUCTOR
&& TREE_STATIC (exp
)))
1552 error ("invalid use of non-lvalue array");
1553 return error_mark_node
;
1556 constp
= volatilep
= 0;
1557 if (TREE_CODE_CLASS (TREE_CODE (exp
)) == 'r'
1558 || TREE_CODE_CLASS (TREE_CODE (exp
)) == 'd')
1560 constp
= TREE_READONLY (exp
);
1561 volatilep
= TREE_THIS_VOLATILE (exp
);
1564 restype
= TREE_TYPE (type
);
1565 if (TYPE_READONLY (type
) || TYPE_VOLATILE (type
)
1566 || constp
|| volatilep
)
1567 restype
= cp_build_type_variant (restype
,
1568 TYPE_READONLY (type
) || constp
,
1569 TYPE_VOLATILE (type
) || volatilep
);
1570 ptrtype
= build_pointer_type (restype
);
1572 if (TREE_CODE (exp
) == VAR_DECL
)
1574 /* ??? This is not really quite correct
1575 in that the type of the operand of ADDR_EXPR
1576 is not the target type of the type of the ADDR_EXPR itself.
1577 Question is, can this lossage be avoided? */
1578 adr
= build1 (ADDR_EXPR
, ptrtype
, exp
);
1579 if (mark_addressable (exp
) == 0)
1580 return error_mark_node
;
1581 TREE_CONSTANT (adr
) = staticp (exp
);
1582 TREE_SIDE_EFFECTS (adr
) = 0; /* Default would be, same as EXP. */
1585 /* This way is better for a COMPONENT_REF since it can
1586 simplify the offset for a component. */
1587 adr
= build_unary_op (ADDR_EXPR
, exp
, 1);
1588 return cp_convert (ptrtype
, adr
);
1595 default_conversion (exp
)
1599 enum tree_code code
;
1601 exp
= decay_conversion (exp
);
1603 type
= TREE_TYPE (exp
);
1604 code
= TREE_CODE (type
);
1606 if (INTEGRAL_CODE_P (code
))
1608 tree t
= type_promotes_to (type
);
1610 return cp_convert (t
, exp
);
1616 /* Take the address of an inline function without setting TREE_ADDRESSABLE
1620 inline_conversion (exp
)
1623 if (TREE_CODE (exp
) == FUNCTION_DECL
)
1625 tree type
= build_type_variant
1626 (TREE_TYPE (exp
), TREE_READONLY (exp
), TREE_THIS_VOLATILE (exp
));
1627 exp
= build1 (ADDR_EXPR
, build_pointer_type (type
), exp
);
1633 build_object_ref (datum
, basetype
, field
)
1634 tree datum
, basetype
, field
;
1637 if (datum
== error_mark_node
)
1638 return error_mark_node
;
1640 dtype
= TREE_TYPE (datum
);
1641 if (TREE_CODE (dtype
) == REFERENCE_TYPE
)
1642 dtype
= TREE_TYPE (dtype
);
1643 if (! IS_AGGR_TYPE_CODE (TREE_CODE (dtype
)))
1645 cp_error ("request for member `%T::%D' in expression of non-aggregate type `%T'",
1646 basetype
, field
, dtype
);
1647 return error_mark_node
;
1649 else if (IS_SIGNATURE (basetype
))
1651 warning ("signature name in scope resolution ignored");
1652 return build_component_ref (datum
, field
, NULL_TREE
, 1);
1654 else if (is_aggr_type (basetype
, 1))
1656 tree binfo
= binfo_or_else (basetype
, dtype
);
1658 return build_x_component_ref (build_scoped_ref (datum
, basetype
),
1661 return error_mark_node
;
1664 /* Like `build_component_ref, but uses an already found field, and converts
1665 from a reference. Must compute access for current_class_ref.
1669 build_component_ref_1 (datum
, field
, protect
)
1673 return convert_from_reference
1674 (build_component_ref (datum
, field
, NULL_TREE
, protect
));
1677 /* Given a COND_EXPR in T, return it in a form that we can, for
1678 example, use as an lvalue. This code used to be in unary_complex_lvalue,
1679 but we needed it to deal with `a = (d == c) ? b : c' expressions, where
1680 we're dealing with aggregates. So, we now call this in unary_complex_lvalue,
1681 and in build_modify_expr. The case (in particular) that led to this was
1682 with CODE == ADDR_EXPR, since it's not an lvalue when we'd get it there. */
1685 rationalize_conditional_expr (code
, t
)
1686 enum tree_code code
;
1690 build_conditional_expr (TREE_OPERAND (t
, 0),
1691 build_unary_op (code
, TREE_OPERAND (t
, 1), 0),
1692 build_unary_op (code
, TREE_OPERAND (t
, 2), 0));
1695 /* Given the TYPE of an anonymous union field inside T, return the
1696 FIELD_DECL for the field. If not found return NULL_TREE. Because
1697 anonymous unions can nest, we must also search all anonymous unions
1698 that are directly reachable. */
1701 lookup_anon_field (t
, type
)
1706 for (field
= TYPE_FIELDS (t
); field
; field
= TREE_CHAIN (field
))
1708 if (TREE_STATIC (field
))
1710 if (TREE_CODE (field
) != FIELD_DECL
)
1713 /* If we find it directly, return the field. */
1714 if (DECL_NAME (field
) == NULL_TREE
1715 && type
== TREE_TYPE (field
))
1720 /* Otherwise, it could be nested, search harder. */
1721 if (DECL_NAME (field
) == NULL_TREE
1722 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
1724 tree subfield
= lookup_anon_field (TREE_TYPE (field
), type
);
1732 /* Build a COMPONENT_REF for a given DATUM, and it's member COMPONENT.
1733 COMPONENT can be an IDENTIFIER_NODE that is the name of the member
1734 that we are interested in, or it can be a FIELD_DECL. */
1737 build_component_ref (datum
, component
, basetype_path
, protect
)
1738 tree datum
, component
, basetype_path
;
1741 register tree basetype
= TREE_TYPE (datum
);
1742 register enum tree_code code
;
1743 register tree field
= NULL
;
1746 if (processing_template_decl
)
1747 return build_min_nt (COMPONENT_REF
, datum
, component
);
1749 /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference
1751 switch (TREE_CODE (datum
))
1755 tree value
= build_component_ref (TREE_OPERAND (datum
, 1), component
,
1756 basetype_path
, protect
);
1757 return build (COMPOUND_EXPR
, TREE_TYPE (value
),
1758 TREE_OPERAND (datum
, 0), value
);
1761 return build_conditional_expr
1762 (TREE_OPERAND (datum
, 0),
1763 build_component_ref (TREE_OPERAND (datum
, 1), component
,
1764 basetype_path
, protect
),
1765 build_component_ref (TREE_OPERAND (datum
, 2), component
,
1766 basetype_path
, protect
));
1769 code
= TREE_CODE (basetype
);
1771 if (code
== REFERENCE_TYPE
)
1773 datum
= convert_from_reference (datum
);
1774 basetype
= TREE_TYPE (datum
);
1775 code
= TREE_CODE (basetype
);
1777 if (TREE_CODE (datum
) == OFFSET_REF
)
1779 datum
= resolve_offset_ref (datum
);
1780 basetype
= TREE_TYPE (datum
);
1781 code
= TREE_CODE (basetype
);
1784 /* First, see if there is a field or component with name COMPONENT. */
1785 if (TREE_CODE (component
) == TREE_LIST
)
1787 my_friendly_assert (!(TREE_CHAIN (component
) == NULL_TREE
1788 && DECL_CHAIN (TREE_VALUE (component
)) == NULL_TREE
), 309);
1789 return build (COMPONENT_REF
, TREE_TYPE (component
), datum
, component
);
1792 if (! IS_AGGR_TYPE_CODE (code
))
1794 if (code
!= ERROR_MARK
)
1795 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
1796 component
, datum
, basetype
);
1797 return error_mark_node
;
1800 if (TYPE_SIZE (complete_type (basetype
)) == 0)
1802 incomplete_type_error (0, basetype
);
1803 return error_mark_node
;
1806 if (TREE_CODE (component
) == BIT_NOT_EXPR
)
1808 if (TYPE_IDENTIFIER (basetype
) != TREE_OPERAND (component
, 0))
1810 cp_error ("destructor specifier `%T::~%T' must have matching names",
1811 basetype
, TREE_OPERAND (component
, 0));
1812 return error_mark_node
;
1814 if (! TYPE_HAS_DESTRUCTOR (basetype
))
1816 cp_error ("type `%T' has no destructor", basetype
);
1817 return error_mark_node
;
1819 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype
), 1);
1822 /* Look up component name in the structure type definition. */
1823 if (CLASSTYPE_VFIELD (basetype
)
1824 && DECL_NAME (CLASSTYPE_VFIELD (basetype
)) == component
)
1825 /* Special-case this because if we use normal lookups in an ambiguous
1826 hierarchy, the compiler will abort (because vptr lookups are
1827 not supposed to be ambiguous. */
1828 field
= CLASSTYPE_VFIELD (basetype
);
1829 else if (TREE_CODE (component
) == FIELD_DECL
1830 || TREE_CODE (component
) == TYPE_DECL
)
1836 tree name
= component
;
1837 if (TREE_CODE (component
) == VAR_DECL
)
1838 name
= DECL_NAME (component
);
1839 if (basetype_path
== NULL_TREE
)
1840 basetype_path
= TYPE_BINFO (basetype
);
1841 field
= lookup_field (basetype_path
, name
,
1842 protect
&& !VFIELD_NAME_P (name
), 0);
1843 if (field
== error_mark_node
)
1844 return error_mark_node
;
1846 if (field
== NULL_TREE
)
1848 /* Not found as a data field, look for it as a method. If found,
1849 then if this is the only possible one, return it, else
1850 report ambiguity error. */
1851 tree fndecls
= lookup_fnfields (basetype_path
, name
, 1);
1852 if (fndecls
== error_mark_node
)
1853 return error_mark_node
;
1856 if (TREE_CHAIN (fndecls
) == NULL_TREE
1857 && DECL_CHAIN (TREE_VALUE (fndecls
)) == NULL_TREE
)
1859 tree access
, fndecl
;
1861 /* Unique, so use this one now. */
1862 basetype
= TREE_PURPOSE (fndecls
);
1863 fndecl
= TREE_VALUE (fndecls
);
1864 access
= compute_access (TREE_PURPOSE (fndecls
), fndecl
);
1865 if (access
== access_public_node
)
1867 if (DECL_VINDEX (fndecl
)
1868 && ! resolves_to_fixed_type_p (datum
, 0))
1870 tree addr
= build_unary_op (ADDR_EXPR
, datum
, 0);
1871 tree fntype
= TREE_TYPE (fndecl
);
1873 addr
= convert_pointer_to (DECL_CONTEXT (fndecl
), addr
);
1874 datum
= build_indirect_ref (addr
, NULL_PTR
);
1875 my_friendly_assert (datum
!= error_mark_node
, 310);
1876 fndecl
= build_vfn_ref (&addr
, datum
, DECL_VINDEX (fndecl
));
1877 TREE_TYPE (fndecl
) = build_pointer_type (fntype
);
1881 return build (OFFSET_REF
, TREE_TYPE (fndecl
), datum
, fndecl
);
1883 if (access
== access_protected_node
)
1884 cp_error ("member function `%D' is protected", fndecl
);
1886 cp_error ("member function `%D' is private", fndecl
);
1887 return error_mark_node
;
1891 /* Just act like build_offset_ref, since the object does
1892 not matter unless we're actually calling the function. */
1895 t
= build_tree_list (error_mark_node
, fndecls
);
1896 TREE_TYPE (t
) = build_offset_type (basetype
,
1902 cp_error ("`%#T' has no member named `%D'", basetype
, name
);
1903 return error_mark_node
;
1905 else if (TREE_TYPE (field
) == error_mark_node
)
1906 return error_mark_node
;
1908 if (TREE_CODE (field
) != FIELD_DECL
)
1910 if (TREE_CODE (field
) == TYPE_DECL
)
1912 cp_error ("invalid use of type decl `%#D' as expression", field
);
1913 return error_mark_node
;
1915 else if (DECL_RTL (field
) != 0)
1918 TREE_USED (field
) = 1;
1923 /* See if we have to do any conversions so that we pick up the field from the
1925 if (DECL_FIELD_CONTEXT (field
) != basetype
)
1927 tree context
= DECL_FIELD_CONTEXT (field
);
1928 tree base
= context
;
1929 while (base
!= basetype
&& TYPE_NAME (base
)
1930 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (base
)))
1932 base
= TYPE_CONTEXT (base
);
1935 /* Handle base classes here... */
1936 if (base
!= basetype
&& TYPE_USES_COMPLEX_INHERITANCE (basetype
))
1938 tree addr
= build_unary_op (ADDR_EXPR
, datum
, 0);
1939 if (integer_zerop (addr
))
1941 error ("invalid reference to NULL ptr, use ptr-to-member instead");
1942 return error_mark_node
;
1944 if (VBASE_NAME_P (DECL_NAME (field
)))
1946 /* It doesn't matter which vbase pointer we grab, just
1947 find one of them. */
1948 tree binfo
= get_binfo (base
,
1949 TREE_TYPE (TREE_TYPE (addr
)), 0);
1950 addr
= convert_pointer_to_real (binfo
, addr
);
1953 addr
= convert_pointer_to (base
, addr
);
1954 datum
= build_indirect_ref (addr
, NULL_PTR
);
1955 my_friendly_assert (datum
!= error_mark_node
, 311);
1959 /* Handle things from anon unions here... */
1960 if (TYPE_NAME (context
) && ANON_AGGRNAME_P (TYPE_IDENTIFIER (context
)))
1962 tree subfield
= lookup_anon_field (basetype
, context
);
1963 tree subdatum
= build_component_ref (datum
, subfield
,
1964 basetype_path
, protect
);
1965 return build_component_ref (subdatum
, field
, basetype_path
, protect
);
1969 ref
= fold (build (COMPONENT_REF
, TREE_TYPE (field
),
1970 break_out_cleanups (datum
), field
));
1972 if (TREE_READONLY (datum
) || TREE_READONLY (field
))
1973 TREE_READONLY (ref
) = 1;
1974 if (TREE_THIS_VOLATILE (datum
) || TREE_THIS_VOLATILE (field
))
1975 TREE_THIS_VOLATILE (ref
) = 1;
1976 if (DECL_MUTABLE_P (field
))
1977 TREE_READONLY (ref
) = 0;
1982 /* Variant of build_component_ref for use in expressions, which should
1983 never have REFERENCE_TYPE. */
1986 build_x_component_ref (datum
, component
, basetype_path
, protect
)
1987 tree datum
, component
, basetype_path
;
1990 tree t
= build_component_ref (datum
, component
, basetype_path
, protect
);
1992 if (! processing_template_decl
)
1993 t
= convert_from_reference (t
);
1998 /* Given an expression PTR for a pointer, return an expression
1999 for the value pointed to.
2000 ERRORSTRING is the name of the operator to appear in error messages.
2002 This function may need to overload OPERATOR_FNNAME.
2003 Must also handle REFERENCE_TYPEs for C++. */
2006 build_x_indirect_ref (ptr
, errorstring
)
2012 if (processing_template_decl
)
2013 return build_min_nt (INDIRECT_REF
, ptr
);
2015 rval
= build_opfncall (INDIRECT_REF
, LOOKUP_NORMAL
, ptr
, NULL_TREE
, NULL_TREE
);
2018 return build_indirect_ref (ptr
, errorstring
);
2022 build_indirect_ref (ptr
, errorstring
)
2026 register tree pointer
, type
;
2028 if (ptr
== error_mark_node
)
2029 return error_mark_node
;
2031 pointer
= (TREE_CODE (TREE_TYPE (ptr
)) == REFERENCE_TYPE
2032 ? ptr
: default_conversion (ptr
));
2033 type
= TREE_TYPE (pointer
);
2035 if (ptr
== current_class_ptr
)
2036 return current_class_ref
;
2038 if (IS_AGGR_TYPE (type
))
2040 ptr
= build_expr_type_conversion (WANT_POINTER
, pointer
, 1);
2045 type
= TREE_TYPE (pointer
);
2049 if (TREE_CODE (type
) == POINTER_TYPE
|| TREE_CODE (type
) == REFERENCE_TYPE
)
2051 if (TREE_CODE (pointer
) == ADDR_EXPR
2053 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (pointer
, 0)))
2054 == TYPE_MAIN_VARIANT (TREE_TYPE (type
)))
2055 && (TREE_READONLY (TREE_OPERAND (pointer
, 0))
2056 == TYPE_READONLY (TREE_TYPE (type
)))
2057 && (TREE_THIS_VOLATILE (TREE_OPERAND (pointer
, 0))
2058 == TYPE_VOLATILE (TREE_TYPE (type
))))
2059 return TREE_OPERAND (pointer
, 0);
2062 tree t
= TREE_TYPE (type
);
2063 register tree ref
= build1 (INDIRECT_REF
,
2064 TYPE_MAIN_VARIANT (t
), pointer
);
2066 /* We *must* set TREE_READONLY when dereferencing a pointer to const,
2067 so that we get the proper error message if the result is used
2068 to assign to. Also, &* is supposed to be a no-op. */
2069 TREE_READONLY (ref
) = TYPE_READONLY (t
);
2070 TREE_SIDE_EFFECTS (ref
)
2071 = TYPE_VOLATILE (t
) || TREE_SIDE_EFFECTS (pointer
) || flag_volatile
;
2072 TREE_THIS_VOLATILE (ref
) = TYPE_VOLATILE (t
);
2076 /* `pointer' won't be an error_mark_node if we were given a
2077 pointer to member, so it's cool to check for this here. */
2078 else if (TYPE_PTRMEMFUNC_P (type
))
2079 error ("invalid use of `%s' on pointer to member function", errorstring
);
2080 else if (TREE_CODE (type
) == RECORD_TYPE
2081 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
)))
2082 error ("cannot dereference signature pointer/reference");
2083 else if (pointer
!= error_mark_node
)
2086 error ("invalid type argument of `%s'", errorstring
);
2088 error ("invalid type argument");
2090 return error_mark_node
;
2093 /* This handles expressions of the form "a[i]", which denotes
2096 This is logically equivalent in C to *(a+i), but we may do it differently.
2097 If A is a variable or a member, we generate a primitive ARRAY_REF.
2098 This avoids forcing the array out of registers, and can work on
2099 arrays that are not lvalues (for example, members of structures returned
2102 If INDEX is of some user-defined type, it must be converted to
2103 integer type. Otherwise, to make a compatible PLUS_EXPR, it
2104 will inherit the type of the array, which will be some pointer type. */
2107 build_array_ref (array
, idx
)
2112 error ("subscript missing in array reference");
2113 return error_mark_node
;
2116 if (TREE_TYPE (array
) == error_mark_node
2117 || TREE_TYPE (idx
) == error_mark_node
)
2118 return error_mark_node
;
2120 if (TREE_CODE (TREE_TYPE (array
)) == ARRAY_TYPE
2121 && TREE_CODE (array
) != INDIRECT_REF
)
2125 /* Subscripting with type char is likely to lose
2126 on a machine where chars are signed.
2127 So warn on any machine, but optionally.
2128 Don't warn for unsigned char since that type is safe.
2129 Don't warn for signed char because anyone who uses that
2130 must have done so deliberately. */
2131 if (warn_char_subscripts
2132 && TYPE_MAIN_VARIANT (TREE_TYPE (idx
)) == char_type_node
)
2133 warning ("array subscript has type `char'");
2135 /* Apply default promotions *after* noticing character types. */
2136 idx
= default_conversion (idx
);
2138 if (TREE_CODE (TREE_TYPE (idx
)) != INTEGER_TYPE
)
2140 error ("array subscript is not an integer");
2141 return error_mark_node
;
2144 /* An array that is indexed by a non-constant
2145 cannot be stored in a register; we must be able to do
2146 address arithmetic on its address.
2147 Likewise an array of elements of variable size. */
2148 if (TREE_CODE (idx
) != INTEGER_CST
2149 || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
))) != 0
2150 && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
)))) != INTEGER_CST
))
2152 if (mark_addressable (array
) == 0)
2153 return error_mark_node
;
2155 /* An array that is indexed by a constant value which is not within
2156 the array bounds cannot be stored in a register either; because we
2157 would get a crash in store_bit_field/extract_bit_field when trying
2158 to access a non-existent part of the register. */
2159 if (TREE_CODE (idx
) == INTEGER_CST
2160 && TYPE_VALUES (TREE_TYPE (array
))
2161 && ! int_fits_type_p (idx
, TYPE_VALUES (TREE_TYPE (array
))))
2163 if (mark_addressable (array
) == 0)
2164 return error_mark_node
;
2167 if (pedantic
&& !lvalue_p (array
))
2168 pedwarn ("ANSI C++ forbids subscripting non-lvalue array");
2170 /* Note in C++ it is valid to subscript a `register' array, since
2171 it is valid to take the address of something with that
2172 storage specification. */
2176 while (TREE_CODE (foo
) == COMPONENT_REF
)
2177 foo
= TREE_OPERAND (foo
, 0);
2178 if (TREE_CODE (foo
) == VAR_DECL
&& DECL_REGISTER (foo
))
2179 warning ("subscripting array declared `register'");
2182 type
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array
)));
2183 rval
= build (ARRAY_REF
, type
, array
, idx
);
2184 /* Array ref is const/volatile if the array elements are
2185 or if the array is.. */
2186 TREE_READONLY (rval
)
2187 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array
)))
2188 | TREE_READONLY (array
));
2189 TREE_SIDE_EFFECTS (rval
)
2190 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
2191 | TREE_SIDE_EFFECTS (array
));
2192 TREE_THIS_VOLATILE (rval
)
2193 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
2194 /* This was added by rms on 16 Nov 91.
2195 It fixes vol struct foo *a; a->elts[1]
2196 in an inline function.
2197 Hope it doesn't break something else. */
2198 | TREE_THIS_VOLATILE (array
));
2199 return require_complete_type (fold (rval
));
2203 tree ar
= default_conversion (array
);
2204 tree ind
= default_conversion (idx
);
2206 /* Put the integer in IND to simplify error checking. */
2207 if (TREE_CODE (TREE_TYPE (ar
)) == INTEGER_TYPE
)
2214 if (ar
== error_mark_node
)
2217 if (TREE_CODE (TREE_TYPE (ar
)) != POINTER_TYPE
)
2219 error ("subscripted value is neither array nor pointer");
2220 return error_mark_node
;
2222 if (TREE_CODE (TREE_TYPE (ind
)) != INTEGER_TYPE
)
2224 error ("array subscript is not an integer");
2225 return error_mark_node
;
2228 return build_indirect_ref (build_binary_op_nodefault (PLUS_EXPR
, ar
, ind
, PLUS_EXPR
),
2233 /* Build a function call to function FUNCTION with parameters PARAMS.
2234 PARAMS is a list--a chain of TREE_LIST nodes--in which the
2235 TREE_VALUE of each node is a parameter-expression. The PARAMS do
2236 not include any object pointer that may be required. FUNCTION's
2237 data type may be a function type or a pointer-to-function.
2239 For C++: If FUNCTION's data type is a TREE_LIST, then the tree list
2240 is the list of possible methods that FUNCTION could conceivably
2241 be. If the list of methods comes from a class, then it will be
2242 a list of lists (where each element is associated with the class
2243 that produced it), otherwise it will be a simple list (for
2244 functions overloaded in global scope).
2246 In the first case, TREE_VALUE (function) is the head of one of those
2247 lists, and TREE_PURPOSE is the name of the function.
2249 In the second case, TREE_PURPOSE (function) is the function's
2252 DECL is the class instance variable, usually CURRENT_CLASS_REF.
2254 When calling a TEMPLATE_DECL, we don't require a complete return
2258 build_x_function_call (function
, params
, decl
)
2259 tree function
, params
, decl
;
2264 if (function
== error_mark_node
)
2265 return error_mark_node
;
2267 if (processing_template_decl
)
2268 return build_min_nt (CALL_EXPR
, function
, params
, NULL_TREE
);
2270 type
= TREE_TYPE (function
);
2272 if (TREE_CODE (type
) == OFFSET_TYPE
2273 && TREE_TYPE (type
) == unknown_type_node
2274 && TREE_CODE (function
) == TREE_LIST
2275 && TREE_CHAIN (function
) == NULL_TREE
)
2277 /* Undo (Foo:bar)()... */
2278 type
= TYPE_OFFSET_BASETYPE (type
);
2279 function
= TREE_VALUE (function
);
2280 my_friendly_assert (TREE_CODE (function
) == TREE_LIST
, 999);
2281 my_friendly_assert (TREE_CHAIN (function
) == NULL_TREE
, 999);
2282 function
= TREE_VALUE (function
);
2283 my_friendly_assert (TREE_CODE (function
) == FUNCTION_DECL
, 999);
2284 function
= DECL_NAME (function
);
2285 return build_method_call (decl
, function
, params
, TYPE_BINFO (type
), LOOKUP_NORMAL
);
2288 is_method
= ((TREE_CODE (function
) == TREE_LIST
2289 && current_class_type
!= NULL_TREE
2290 && IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (function
)) == function
)
2291 || TREE_CODE (function
) == IDENTIFIER_NODE
2292 || TREE_CODE (type
) == METHOD_TYPE
2293 || TYPE_PTRMEMFUNC_P (type
));
2295 if (TREE_CODE (function
) == FUNCTION_DECL
2296 && DECL_STATIC_FUNCTION_P (function
))
2297 return build_member_call
2298 (DECL_CONTEXT (function
), DECL_NAME (function
), params
);
2300 /* Handle methods, friends, and overloaded functions, respectively. */
2303 tree basetype
= NULL_TREE
;
2305 if (TREE_CODE (function
) == FUNCTION_DECL
2306 || DECL_FUNCTION_TEMPLATE_P (function
))
2308 basetype
= DECL_CLASS_CONTEXT (function
);
2310 if (DECL_NAME (function
))
2311 function
= DECL_NAME (function
);
2313 function
= TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function
));
2315 else if (TREE_CODE (function
) == TREE_LIST
)
2317 my_friendly_assert (TREE_CODE (TREE_VALUE (function
)) == FUNCTION_DECL
, 312);
2318 basetype
= DECL_CLASS_CONTEXT (TREE_VALUE (function
));
2319 function
= TREE_PURPOSE (function
);
2321 else if (TREE_CODE (function
) != IDENTIFIER_NODE
)
2323 if (TREE_CODE (function
) == OFFSET_REF
)
2325 if (TREE_OPERAND (function
, 0))
2326 decl
= TREE_OPERAND (function
, 0);
2328 /* Call via a pointer to member function. */
2329 if (decl
== NULL_TREE
)
2331 error ("pointer to member function called, but not in class scope");
2332 return error_mark_node
;
2334 /* What other type of POINTER_TYPE could this be? */
2335 if (TREE_CODE (TREE_TYPE (function
)) != POINTER_TYPE
2336 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (function
))
2337 && TREE_CODE (function
) != OFFSET_REF
)
2338 function
= build (OFFSET_REF
, TREE_TYPE (type
), NULL_TREE
, function
);
2342 /* this is an abbreviated method call.
2343 must go through here in case it is a virtual function.
2344 @@ Perhaps this could be optimized. */
2346 if (basetype
&& (! current_class_type
2347 || ! DERIVED_FROM_P (basetype
, current_class_type
)))
2348 return build_member_call (basetype
, function
, params
);
2350 if (decl
== NULL_TREE
)
2352 if (current_class_type
== NULL_TREE
)
2354 error ("object missing in call to method `%s'",
2355 IDENTIFIER_POINTER (function
));
2356 return error_mark_node
;
2358 /* Yow: call from a static member function. */
2359 decl
= build1 (NOP_EXPR
, build_pointer_type (current_class_type
),
2361 decl
= build_indirect_ref (decl
, NULL_PTR
);
2364 return build_method_call (decl
, function
, params
,
2365 NULL_TREE
, LOOKUP_NORMAL
);
2367 else if (TREE_CODE (function
) == COMPONENT_REF
2368 && type
== unknown_type_node
)
2370 /* Should we undo what was done in build_component_ref? */
2371 if (TREE_CODE (TREE_PURPOSE (TREE_OPERAND (function
, 1))) == TREE_VEC
)
2372 /* Get the name that build_component_ref hid. */
2373 function
= DECL_NAME (TREE_VALUE (TREE_OPERAND (function
, 1)));
2375 function
= TREE_PURPOSE (TREE_OPERAND (function
, 1));
2376 return build_method_call (decl
, function
, params
,
2377 NULL_TREE
, LOOKUP_NORMAL
);
2379 else if (really_overloaded_fn (function
))
2381 if (TREE_VALUE (function
) == NULL_TREE
)
2383 cp_error ("function `%D' declared overloaded, but no definitions appear with which to resolve it?!?",
2384 TREE_PURPOSE (function
));
2385 return error_mark_node
;
2389 tree val
= TREE_VALUE (function
);
2391 if (flag_ansi_overloading
)
2392 return build_new_function_call (function
, params
, NULL_TREE
);
2394 if (TREE_CODE (val
) == TEMPLATE_DECL
)
2395 return build_overload_call_real
2396 (function
, params
, LOOKUP_COMPLAIN
, (struct candidate
*)0, 0);
2397 else if (DECL_CHAIN (val
) != NULL_TREE
)
2398 return build_overload_call
2399 (function
, params
, LOOKUP_COMPLAIN
);
2401 my_friendly_abort (360);
2406 if (TREE_CODE (function
) == OFFSET_REF
)
2408 /* If the component is a data element (or a virtual function), we play
2409 games here to make things work. */
2412 if (TREE_OPERAND (function
, 0))
2413 decl
= TREE_OPERAND (function
, 0);
2415 decl
= current_class_ref
;
2417 decl_addr
= build_unary_op (ADDR_EXPR
, decl
, 0);
2418 function
= get_member_function_from_ptrfunc (&decl_addr
,
2419 TREE_OPERAND (function
, 1));
2420 params
= tree_cons (NULL_TREE
, decl_addr
, params
);
2421 return build_function_call (function
, params
);
2424 type
= TREE_TYPE (function
);
2425 if (type
!= error_mark_node
)
2427 if (TREE_CODE (type
) == REFERENCE_TYPE
)
2428 type
= TREE_TYPE (type
);
2430 if (IS_AGGR_TYPE (type
))
2431 return build_opfncall (CALL_EXPR
, LOOKUP_NORMAL
, function
, params
, NULL_TREE
);
2436 tree fntype
= TREE_TYPE (function
);
2439 /* Explicitly named method? */
2440 if (TREE_CODE (function
) == FUNCTION_DECL
)
2441 ctypeptr
= build_pointer_type (DECL_CLASS_CONTEXT (function
));
2442 /* Expression with ptr-to-method type? It could either be a plain
2443 usage, or it might be a case where the ptr-to-method is being
2444 passed in as an argument. */
2445 else if (TYPE_PTRMEMFUNC_P (fntype
))
2447 tree rec
= TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (fntype
)));
2448 ctypeptr
= build_pointer_type (rec
);
2450 /* Unexpected node type? */
2452 my_friendly_abort (116);
2453 if (decl
== NULL_TREE
)
2455 if (current_function_decl
2456 && DECL_STATIC_FUNCTION_P (current_function_decl
))
2457 error ("invalid call to member function needing `this' in static member function scope");
2459 error ("pointer to member function called, but not in class scope");
2460 return error_mark_node
;
2462 if (TREE_CODE (TREE_TYPE (decl
)) != POINTER_TYPE
2463 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (decl
)))
2465 decl
= build_unary_op (ADDR_EXPR
, decl
, 0);
2466 decl
= convert_pointer_to (TREE_TYPE (ctypeptr
), decl
);
2469 decl
= build_c_cast (ctypeptr
, decl
);
2470 params
= tree_cons (NULL_TREE
, decl
, params
);
2473 return build_function_call (function
, params
);
2476 /* Resolve a pointer to member function. INSTANCE is the object
2477 instance to use, if the member points to a virtual member. */
2480 get_member_function_from_ptrfunc (instance_ptrptr
, function
)
2481 tree
*instance_ptrptr
;
2484 if (TREE_CODE (function
) == OFFSET_REF
)
2486 function
= TREE_OPERAND (function
, 1);
2489 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function
)))
2491 tree fntype
, idx
, e1
, delta
, delta2
, e2
, e3
, aref
, vtbl
;
2494 tree instance_ptr
= *instance_ptrptr
;
2496 if (TREE_SIDE_EFFECTS (instance_ptr
))
2497 instance_ptr
= save_expr (instance_ptr
);
2499 if (TREE_SIDE_EFFECTS (function
))
2500 function
= save_expr (function
);
2502 fntype
= TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (function
));
2504 /* Promoting idx before saving it improves performance on RISC
2505 targets. Without promoting, the first compare used
2506 load-with-sign-extend, while the second used normal load then
2507 shift to sign-extend. An optimizer flaw, perhaps, but it's easier
2508 to make this change. */
2509 idx
= save_expr (default_conversion
2510 (build_component_ref (function
,
2513 e1
= build_binary_op (GT_EXPR
, idx
, integer_zero_node
, 1);
2514 delta
= cp_convert (ptrdiff_type_node
,
2515 build_component_ref (function
, delta_identifier
, NULL_TREE
, 0));
2516 delta2
= DELTA2_FROM_PTRMEMFUNC (function
);
2518 /* Convert down to the right base, before using the instance. */
2520 = convert_pointer_to_real (TYPE_METHOD_BASETYPE (TREE_TYPE (fntype
)),
2522 if (instance
== error_mark_node
&& instance_ptr
!= error_mark_node
)
2525 vtbl
= convert_pointer_to (ptr_type_node
, instance
);
2528 build_pointer_type (build_pointer_type (vtable_entry_type
)),
2529 vtbl
, cp_convert (ptrdiff_type_node
, delta2
));
2530 vtbl
= build_indirect_ref (vtbl
, NULL_PTR
);
2531 aref
= build_array_ref (vtbl
, build_binary_op (MINUS_EXPR
,
2533 integer_one_node
, 1));
2534 if (! flag_vtable_thunks
)
2536 aref
= save_expr (aref
);
2538 delta
= build_binary_op (PLUS_EXPR
,
2539 build_conditional_expr (e1
, build_component_ref (aref
, delta_identifier
, NULL_TREE
, 0), integer_zero_node
),
2543 *instance_ptrptr
= build (PLUS_EXPR
, TREE_TYPE (instance_ptr
),
2544 instance_ptr
, delta
);
2545 if (flag_vtable_thunks
)
2548 e2
= build_component_ref (aref
, pfn_identifier
, NULL_TREE
, 0);
2550 e3
= PFN_FROM_PTRMEMFUNC (function
);
2551 TREE_TYPE (e2
) = TREE_TYPE (e3
);
2552 e1
= build_conditional_expr (e1
, e2
, e3
);
2554 if (instance_ptr
== error_mark_node
2555 && TREE_CODE (e1
) != ADDR_EXPR
2556 && TREE_CODE (TREE_OPERAND (e1
, 0)) != FUNCTION_DECL
)
2557 cp_error ("object missing in `%E'", function
);
2561 /* Make sure this doesn't get evaluated first inside one of the
2562 branches of the COND_EXPR. */
2563 if (TREE_CODE (instance_ptr
) == SAVE_EXPR
)
2564 function
= build (COMPOUND_EXPR
, TREE_TYPE (function
),
2565 instance_ptr
, function
);
2571 build_function_call_real (function
, params
, require_complete
, flags
)
2572 tree function
, params
;
2573 int require_complete
, flags
;
2575 register tree fntype
, fndecl
;
2576 register tree value_type
;
2577 register tree coerced_params
;
2578 tree name
= NULL_TREE
, assembler_name
= NULL_TREE
;
2581 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
2582 Strip such NOP_EXPRs, since FUNCTION is used in non-lvalue context. */
2583 if (TREE_CODE (function
) == NOP_EXPR
2584 && TREE_TYPE (function
) == TREE_TYPE (TREE_OPERAND (function
, 0)))
2585 function
= TREE_OPERAND (function
, 0);
2587 if (TREE_CODE (function
) == FUNCTION_DECL
)
2589 name
= DECL_NAME (function
);
2590 assembler_name
= DECL_ASSEMBLER_NAME (function
);
2592 GNU_xref_call (current_function_decl
,
2593 IDENTIFIER_POINTER (name
? name
2594 : TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function
))));
2595 mark_used (function
);
2598 /* Convert anything with function type to a pointer-to-function. */
2601 && IDENTIFIER_LENGTH (name
) == 4
2602 && ! strcmp (IDENTIFIER_POINTER (name
), "main")
2603 && DECL_CONTEXT (function
) == NULL_TREE
)
2605 pedwarn ("ANSI C++ forbids calling `main' from within program");
2608 if (pedantic
&& DECL_THIS_INLINE (function
) && ! DECL_INITIAL (function
)
2609 && ! DECL_ARTIFICIAL (function
)
2610 && ! DECL_PENDING_INLINE_INFO (function
))
2611 cp_pedwarn ("inline function `%#D' called before definition",
2614 /* Differs from default_conversion by not setting TREE_ADDRESSABLE
2615 (because calling an inline function does not mean the function
2616 needs to be separately compiled). */
2618 if (DECL_INLINE (function
))
2619 function
= inline_conversion (function
);
2621 function
= build_addr_func (function
);
2627 function
= build_addr_func (function
);
2630 if (function
== error_mark_node
)
2631 return error_mark_node
;
2633 fntype
= TREE_TYPE (function
);
2635 if (TYPE_PTRMEMFUNC_P (fntype
))
2637 cp_error ("must use .* or ->* to call pointer-to-member function in `%E (...)'",
2639 return error_mark_node
;
2642 is_method
= (TREE_CODE (fntype
) == POINTER_TYPE
2643 && TREE_CODE (TREE_TYPE (fntype
)) == METHOD_TYPE
);
2645 if (!((TREE_CODE (fntype
) == POINTER_TYPE
2646 && TREE_CODE (TREE_TYPE (fntype
)) == FUNCTION_TYPE
)
2648 || TREE_CODE (function
) == TEMPLATE_ID_EXPR
))
2650 cp_error ("`%E' cannot be used as a function", function
);
2651 return error_mark_node
;
2654 /* fntype now gets the type of function pointed to. */
2655 fntype
= TREE_TYPE (fntype
);
2657 /* Convert the parameters to the types declared in the
2658 function prototype, or apply default promotions. */
2660 if (flags
& LOOKUP_COMPLAIN
)
2661 coerced_params
= convert_arguments (NULL_TREE
, TYPE_ARG_TYPES (fntype
),
2662 params
, fndecl
, LOOKUP_NORMAL
);
2664 coerced_params
= convert_arguments (NULL_TREE
, TYPE_ARG_TYPES (fntype
),
2667 if (coerced_params
== error_mark_node
)
2668 if (flags
& LOOKUP_SPECULATIVELY
)
2671 return error_mark_node
;
2673 /* Check for errors in format strings. */
2675 if (warn_format
&& (name
|| assembler_name
))
2676 check_function_format (name
, assembler_name
, coerced_params
);
2678 /* Recognize certain built-in functions so we can make tree-codes
2679 other than CALL_EXPR. We do this when it enables fold-const.c
2680 to do something useful. */
2682 if (TREE_CODE (function
) == ADDR_EXPR
2683 && TREE_CODE (TREE_OPERAND (function
, 0)) == FUNCTION_DECL
2684 && DECL_BUILT_IN (TREE_OPERAND (function
, 0)))
2685 switch (DECL_FUNCTION_CODE (TREE_OPERAND (function
, 0)))
2690 if (coerced_params
== 0)
2691 return integer_zero_node
;
2692 return build_unary_op (ABS_EXPR
, TREE_VALUE (coerced_params
), 0);
2696 value_type
= TREE_TYPE (fntype
) ? TREE_TYPE (fntype
) : void_type_node
;
2698 register tree result
2699 = build_call (function
, value_type
, coerced_params
);
2701 if (require_complete
)
2703 if (value_type
== void_type_node
)
2705 result
= require_complete_type (result
);
2707 if (IS_AGGR_TYPE (value_type
))
2708 result
= build_cplus_new (value_type
, result
);
2709 return convert_from_reference (result
);
2714 build_function_call (function
, params
)
2715 tree function
, params
;
2717 return build_function_call_real (function
, params
, 1, LOOKUP_NORMAL
);
2720 /* Convert the actual parameter expressions in the list VALUES
2721 to the types in the list TYPELIST.
2722 If parmdecls is exhausted, or when an element has NULL as its type,
2723 perform the default conversions.
2725 RETURN_LOC is the location of the return value, if known, NULL_TREE
2726 otherwise. This is useful in the case where we can avoid creating
2727 a temporary variable in the case where we can initialize the return
2728 value directly. If we are not eliding constructors, then we set this
2729 to NULL_TREE to avoid this avoidance.
2731 NAME is an IDENTIFIER_NODE or 0. It is used only for error messages.
2733 This is also where warnings about wrong number of args are generated.
2735 Return a list of expressions for the parameters as converted.
2737 Both VALUES and the returned value are chains of TREE_LIST nodes
2738 with the elements of the list in the TREE_VALUE slots of those nodes.
2740 In C++, unspecified trailing parameters can be filled in with their
2741 default arguments, if such were specified. Do so here. */
2744 convert_arguments (return_loc
, typelist
, values
, fndecl
, flags
)
2745 tree return_loc
, typelist
, values
, fndecl
;
2748 register tree typetail
, valtail
;
2749 register tree result
= NULL_TREE
;
2753 if (! flag_elide_constructors
)
2756 /* Argument passing is always copy-initialization. */
2757 flags
|= LOOKUP_ONLYCONVERTING
;
2761 if (TREE_CODE (TREE_TYPE (fndecl
)) == METHOD_TYPE
)
2763 if (DECL_NAME (fndecl
) == NULL_TREE
2764 || IDENTIFIER_HAS_TYPE_VALUE (DECL_NAME (fndecl
)))
2765 called_thing
= "constructor";
2767 called_thing
= "member function";
2770 called_thing
= "function";
2773 for (valtail
= values
, typetail
= typelist
;
2775 valtail
= TREE_CHAIN (valtail
), i
++)
2777 register tree type
= typetail
? TREE_VALUE (typetail
) : 0;
2778 register tree val
= TREE_VALUE (valtail
);
2780 if (val
== error_mark_node
)
2781 return error_mark_node
;
2783 if (type
== void_type_node
)
2787 cp_error_at ("too many arguments to %s `%+D'", called_thing
,
2789 error ("at this point in file");
2792 error ("too many arguments to function");
2793 /* In case anybody wants to know if this argument
2796 TREE_TYPE (tree_last (result
)) = error_mark_node
;
2800 /* The tree type of the parameter being passed may not yet be
2801 known. In this case, its type is TYPE_UNKNOWN, and will
2802 be instantiated by the type given by TYPE. If TYPE
2803 is also NULL, the tree type of VAL is ERROR_MARK_NODE. */
2804 if (type
&& type_unknown_p (val
))
2805 val
= require_instantiated_type (type
, val
, integer_zero_node
);
2806 else if (type_unknown_p (val
))
2808 /* Strip the `&' from an overloaded FUNCTION_DECL. */
2809 if (TREE_CODE (val
) == ADDR_EXPR
)
2810 val
= TREE_OPERAND (val
, 0);
2811 if (really_overloaded_fn (val
))
2812 cp_error ("insufficient type information to resolve address of overloaded function `%D'",
2813 DECL_NAME (get_first_fn (val
)));
2815 error ("insufficient type information in parameter list");
2816 val
= integer_zero_node
;
2818 else if (TREE_CODE (val
) == OFFSET_REF
2819 && TREE_CODE (TREE_TYPE (val
)) == METHOD_TYPE
)
2821 /* This is unclean. Should be handled elsewhere. */
2822 val
= build_unary_op (ADDR_EXPR
, val
, 0);
2824 else if (TREE_CODE (val
) == OFFSET_REF
)
2825 val
= resolve_offset_ref (val
);
2827 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
2828 Strip such NOP_EXPRs, since VAL is used in non-lvalue context. */
2829 if (TREE_CODE (val
) == NOP_EXPR
2830 && TREE_TYPE (val
) == TREE_TYPE (TREE_OPERAND (val
, 0))
2831 && (type
== 0 || TREE_CODE (type
) != REFERENCE_TYPE
))
2832 val
= TREE_OPERAND (val
, 0);
2834 if (type
== 0 || TREE_CODE (type
) != REFERENCE_TYPE
)
2836 if (TREE_CODE (TREE_TYPE (val
)) == ARRAY_TYPE
2837 || TREE_CODE (TREE_TYPE (val
)) == FUNCTION_TYPE
2838 || TREE_CODE (TREE_TYPE (val
)) == METHOD_TYPE
)
2839 val
= default_conversion (val
);
2841 val
= require_complete_type (val
);
2844 if (val
== error_mark_node
)
2845 return error_mark_node
;
2849 /* Formal parm type is specified by a function prototype. */
2852 if (TYPE_SIZE (complete_type (type
)) == 0)
2854 error ("parameter type of called function is incomplete");
2859 parmval
= convert_for_initialization
2860 (return_loc
, type
, val
, flags
,
2861 "argument passing", fndecl
, i
);
2862 #ifdef PROMOTE_PROTOTYPES
2863 if ((TREE_CODE (type
) == INTEGER_TYPE
2864 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2865 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
2866 parmval
= default_conversion (parmval
);
2870 if (parmval
== error_mark_node
)
2871 return error_mark_node
;
2873 result
= tree_cons (NULL_TREE
, parmval
, result
);
2877 if (TREE_CODE (TREE_TYPE (val
)) == REFERENCE_TYPE
)
2878 val
= convert_from_reference (val
);
2880 if (TREE_CODE (TREE_TYPE (val
)) == REAL_TYPE
2881 && (TYPE_PRECISION (TREE_TYPE (val
))
2882 < TYPE_PRECISION (double_type_node
)))
2883 /* Convert `float' to `double'. */
2884 result
= tree_cons (NULL_TREE
, cp_convert (double_type_node
, val
), result
);
2885 else if (TYPE_LANG_SPECIFIC (TREE_TYPE (val
))
2886 && ! TYPE_HAS_TRIVIAL_INIT_REF (TREE_TYPE (val
)))
2888 cp_warning ("cannot pass objects of type `%T' through `...'",
2890 result
= tree_cons (NULL_TREE
, val
, result
);
2893 /* Convert `short' and `char' to full-size `int'. */
2894 result
= tree_cons (NULL_TREE
, default_conversion (val
), result
);
2898 typetail
= TREE_CHAIN (typetail
);
2901 if (typetail
!= 0 && typetail
!= void_list_node
)
2903 /* See if there are default arguments that can be used */
2904 if (TREE_PURPOSE (typetail
))
2906 for (; typetail
!= void_list_node
; ++i
)
2908 tree type
= TREE_VALUE (typetail
);
2909 tree val
= break_out_target_exprs (TREE_PURPOSE (typetail
));
2912 if (val
== NULL_TREE
)
2913 parmval
= error_mark_node
;
2914 else if (TREE_CODE (val
) == CONSTRUCTOR
)
2916 parmval
= digest_init (type
, val
, (tree
*)0);
2917 parmval
= convert_for_initialization (return_loc
, type
, parmval
, flags
,
2918 "default constructor", fndecl
, i
);
2922 /* This could get clobbered by the following call. */
2923 if (TREE_HAS_CONSTRUCTOR (val
))
2924 val
= copy_node (val
);
2926 parmval
= convert_for_initialization (return_loc
, type
, val
, flags
,
2927 "default argument", fndecl
, i
);
2928 #ifdef PROMOTE_PROTOTYPES
2929 if ((TREE_CODE (type
) == INTEGER_TYPE
2930 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2931 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
2932 parmval
= default_conversion (parmval
);
2936 if (parmval
== error_mark_node
)
2937 return error_mark_node
;
2939 result
= tree_cons (0, parmval
, result
);
2940 typetail
= TREE_CHAIN (typetail
);
2941 /* ends with `...'. */
2942 if (typetail
== NULL_TREE
)
2950 char *buf
= (char *)alloca (32 + strlen (called_thing
));
2951 sprintf (buf
, "too few arguments to %s `%%#D'", called_thing
);
2952 cp_error_at (buf
, fndecl
);
2953 error ("at this point in file");
2956 error ("too few arguments to function");
2957 return error_mark_list
;
2961 return nreverse (result
);
2964 /* Build a binary-operation expression, after performing default
2965 conversions on the operands. CODE is the kind of expression to build. */
2968 build_x_binary_op (code
, arg1
, arg2
)
2969 enum tree_code code
;
2974 if (processing_template_decl
)
2975 return build_min_nt (code
, arg1
, arg2
);
2977 if (flag_ansi_overloading
)
2978 return build_new_op (code
, LOOKUP_NORMAL
, arg1
, arg2
, NULL_TREE
);
2980 rval
= build_opfncall (code
, LOOKUP_SPECULATIVELY
,
2981 arg1
, arg2
, NULL_TREE
);
2983 return build_opfncall (code
, LOOKUP_NORMAL
, arg1
, arg2
, NULL_TREE
);
2984 if (code
== MEMBER_REF
)
2985 return build_m_component_ref (build_indirect_ref (arg1
, NULL_PTR
),
2987 return build_binary_op (code
, arg1
, arg2
, 1);
2991 build_binary_op (code
, arg1
, arg2
, convert_p
)
2992 enum tree_code code
;
3004 args
[0] = decay_conversion (args
[0]);
3005 args
[1] = decay_conversion (args
[1]);
3007 if (args
[0] == error_mark_node
|| args
[1] == error_mark_node
)
3008 return error_mark_node
;
3010 type0
= TREE_TYPE (args
[0]);
3011 type1
= TREE_TYPE (args
[1]);
3013 if (type_unknown_p (args
[0]))
3015 args
[0] = instantiate_type (type1
, args
[0], 1);
3016 args
[0] = decay_conversion (args
[0]);
3018 else if (type_unknown_p (args
[1]))
3020 args
[1] = require_instantiated_type (type0
, args
[1],
3022 args
[1] = decay_conversion (args
[1]);
3025 if (IS_AGGR_TYPE (type0
) || IS_AGGR_TYPE (type1
))
3027 /* Try to convert this to something reasonable. */
3028 if (! build_default_binary_type_conversion(code
, &args
[0], &args
[1]))
3030 cp_error ("no match for `%O(%#T, %#T)'", code
,
3031 TREE_TYPE (arg1
), TREE_TYPE (arg2
));
3032 return error_mark_node
;
3036 return build_binary_op_nodefault (code
, args
[0], args
[1], code
);
3039 /* Build a binary-operation expression without default conversions.
3040 CODE is the kind of expression to build.
3041 This function differs from `build' in several ways:
3042 the data type of the result is computed and recorded in it,
3043 warnings are generated if arg data types are invalid,
3044 special handling for addition and subtraction of pointers is known,
3045 and some optimization is done (operations on narrow ints
3046 are done in the narrower type when that gives the same result).
3047 Constant folding is also done before the result is returned.
3049 ERROR_CODE is the code that determines what to say in error messages.
3050 It is usually, but not always, the same as CODE.
3052 Note that the operands will never have enumeral types
3053 because either they have just had the default conversions performed
3054 or they have both just been converted to some other type in which
3055 the arithmetic is to be done.
3057 C++: must do special pointer arithmetic when implementing
3058 multiple inheritance, and deal with pointer to member functions. */
3061 build_binary_op_nodefault (code
, orig_op0
, orig_op1
, error_code
)
3062 enum tree_code code
;
3063 tree orig_op0
, orig_op1
;
3064 enum tree_code error_code
;
3067 register enum tree_code code0
, code1
;
3070 /* Expression code to give to the expression when it is built.
3071 Normally this is CODE, which is what the caller asked for,
3072 but in some special cases we change it. */
3073 register enum tree_code resultcode
= code
;
3075 /* Data type in which the computation is to be performed.
3076 In the simplest cases this is the common type of the arguments. */
3077 register tree result_type
= NULL
;
3079 /* Nonzero means operands have already been type-converted
3080 in whatever way is necessary.
3081 Zero means they need to be converted to RESULT_TYPE. */
3084 /* Nonzero means create the expression with this type, rather than
3086 tree build_type
= 0;
3088 /* Nonzero means after finally constructing the expression
3089 convert it to this type. */
3090 tree final_type
= 0;
3092 /* Nonzero if this is an operation like MIN or MAX which can
3093 safely be computed in short if both args are promoted shorts.
3094 Also implies COMMON.
3095 -1 indicates a bitwise operation; this makes a difference
3096 in the exact conditions for when it is safe to do the operation
3097 in a narrower mode. */
3100 /* Nonzero if this is a comparison operation;
3101 if both args are promoted shorts, compare the original shorts.
3102 Also implies COMMON. */
3103 int short_compare
= 0;
3105 /* Nonzero if this is a right-shift operation, which can be computed on the
3106 original short and then promoted if the operand is a promoted short. */
3107 int short_shift
= 0;
3109 /* Nonzero means set RESULT_TYPE to the common type of the args. */
3112 /* Apply default conversions. */
3113 if (code
== TRUTH_AND_EXPR
|| code
== TRUTH_ANDIF_EXPR
3114 || code
== TRUTH_OR_EXPR
|| code
== TRUTH_ORIF_EXPR
3115 || code
== TRUTH_XOR_EXPR
)
3117 op0
= decay_conversion (orig_op0
);
3118 op1
= decay_conversion (orig_op1
);
3122 op0
= default_conversion (orig_op0
);
3123 op1
= default_conversion (orig_op1
);
3126 type0
= TREE_TYPE (op0
);
3127 type1
= TREE_TYPE (op1
);
3129 /* The expression codes of the data types of the arguments tell us
3130 whether the arguments are integers, floating, pointers, etc. */
3131 code0
= TREE_CODE (type0
);
3132 code1
= TREE_CODE (type1
);
3134 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
3135 STRIP_TYPE_NOPS (op0
);
3136 STRIP_TYPE_NOPS (op1
);
3138 /* If an error was already reported for one of the arguments,
3139 avoid reporting another error. */
3141 if (code0
== ERROR_MARK
|| code1
== ERROR_MARK
)
3142 return error_mark_node
;
3147 /* Handle the pointer + int case. */
3148 if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3149 return pointer_int_sum (PLUS_EXPR
, op0
, op1
);
3150 else if (code1
== POINTER_TYPE
&& code0
== INTEGER_TYPE
)
3151 return pointer_int_sum (PLUS_EXPR
, op1
, op0
);
3157 /* Subtraction of two similar pointers.
3158 We must subtract them as integers, then divide by object size. */
3159 if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
3160 && comp_target_types (type0
, type1
, 1))
3161 return pointer_diff (op0
, op1
);
3162 /* Handle pointer minus int. Just like pointer plus int. */
3163 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3164 return pointer_int_sum (MINUS_EXPR
, op0
, op1
);
3173 case TRUNC_DIV_EXPR
:
3175 case FLOOR_DIV_EXPR
:
3176 case ROUND_DIV_EXPR
:
3177 case EXACT_DIV_EXPR
:
3178 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
3179 || code0
== COMPLEX_TYPE
)
3180 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
3181 || code1
== COMPLEX_TYPE
))
3183 if (TREE_CODE (op1
) == INTEGER_CST
&& integer_zerop (op1
))
3184 cp_warning ("division by zero in `%E / 0'", op0
);
3185 else if (TREE_CODE (op1
) == REAL_CST
&& real_zerop (op1
))
3186 cp_warning ("division by zero in `%E / 0.'", op0
);
3188 if (!(code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
))
3189 resultcode
= RDIV_EXPR
;
3191 /* When dividing two signed integers, we have to promote to int.
3192 unless we divide by a constant != -1. Note that default
3193 conversion will have been performed on the operands at this
3194 point, so we have to dig out the original type to find out if
3196 shorten
= ((TREE_CODE (op0
) == NOP_EXPR
3197 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3198 || (TREE_CODE (op1
) == INTEGER_CST
3199 && (TREE_INT_CST_LOW (op1
) != -1
3200 || TREE_INT_CST_HIGH (op1
) != -1)));
3206 case BIT_ANDTC_EXPR
:
3209 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3211 /* If one operand is a constant, and the other is a short type
3212 that has been converted to an int,
3213 really do the work in the short type and then convert the
3214 result to int. If we are lucky, the constant will be 0 or 1
3215 in the short type, making the entire operation go away. */
3216 if (TREE_CODE (op0
) == INTEGER_CST
3217 && TREE_CODE (op1
) == NOP_EXPR
3218 && TYPE_PRECISION (type1
) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1
, 0)))
3219 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1
, 0))))
3221 final_type
= result_type
;
3222 op1
= TREE_OPERAND (op1
, 0);
3223 result_type
= TREE_TYPE (op1
);
3225 if (TREE_CODE (op1
) == INTEGER_CST
3226 && TREE_CODE (op0
) == NOP_EXPR
3227 && TYPE_PRECISION (type0
) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0
, 0)))
3228 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3230 final_type
= result_type
;
3231 op0
= TREE_OPERAND (op0
, 0);
3232 result_type
= TREE_TYPE (op0
);
3236 case TRUNC_MOD_EXPR
:
3237 case FLOOR_MOD_EXPR
:
3238 if (code1
== INTEGER_TYPE
&& integer_zerop (op1
))
3239 cp_warning ("division by zero in `%E % 0'", op0
);
3240 else if (code1
== REAL_TYPE
&& real_zerop (op1
))
3241 cp_warning ("division by zero in `%E % 0.'", op0
);
3243 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3245 /* Although it would be tempting to shorten always here, that loses
3246 on some targets, since the modulo instruction is undefined if the
3247 quotient can't be represented in the computation mode. We shorten
3248 only if unsigned or if dividing by something we know != -1. */
3249 shorten
= ((TREE_CODE (op0
) == NOP_EXPR
3250 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3251 || (TREE_CODE (op1
) == INTEGER_CST
3252 && (TREE_INT_CST_LOW (op1
) != -1
3253 || TREE_INT_CST_HIGH (op1
) != -1)));
3258 case TRUTH_ANDIF_EXPR
:
3259 case TRUTH_ORIF_EXPR
:
3260 case TRUTH_AND_EXPR
:
3262 result_type
= boolean_type_node
;
3265 /* Shift operations: result has same type as first operand;
3266 always convert second operand to int.
3267 Also set SHORT_SHIFT if shifting rightward. */
3270 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3272 result_type
= type0
;
3273 if (TREE_CODE (op1
) == INTEGER_CST
)
3275 if (tree_int_cst_lt (op1
, integer_zero_node
))
3276 warning ("right shift count is negative");
3279 if (TREE_INT_CST_LOW (op1
) | TREE_INT_CST_HIGH (op1
))
3281 if (TREE_INT_CST_HIGH (op1
) != 0
3282 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3283 >= TYPE_PRECISION (type0
)))
3284 warning ("right shift count >= width of type");
3287 /* Convert the shift-count to an integer, regardless of
3288 size of value being shifted. */
3289 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3290 op1
= cp_convert (integer_type_node
, op1
);
3291 /* Avoid converting op1 to result_type later. */
3297 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3299 result_type
= type0
;
3300 if (TREE_CODE (op1
) == INTEGER_CST
)
3302 if (tree_int_cst_lt (op1
, integer_zero_node
))
3303 warning ("left shift count is negative");
3304 else if (TREE_INT_CST_HIGH (op1
) != 0
3305 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3306 >= TYPE_PRECISION (type0
)))
3307 warning ("left shift count >= width of type");
3309 /* Convert the shift-count to an integer, regardless of
3310 size of value being shifted. */
3311 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3312 op1
= cp_convert (integer_type_node
, op1
);
3313 /* Avoid converting op1 to result_type later. */
3320 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3322 result_type
= type0
;
3323 if (TREE_CODE (op1
) == INTEGER_CST
)
3325 if (tree_int_cst_lt (op1
, integer_zero_node
))
3326 warning ("%s rotate count is negative",
3327 (code
== LROTATE_EXPR
) ? "left" : "right");
3328 else if (TREE_INT_CST_HIGH (op1
) != 0
3329 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3330 >= TYPE_PRECISION (type0
)))
3331 warning ("%s rotate count >= width of type",
3332 (code
== LROTATE_EXPR
) ? "left" : "right");
3334 /* Convert the shift-count to an integer, regardless of
3335 size of value being shifted. */
3336 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3337 op1
= cp_convert (integer_type_node
, op1
);
3343 build_type
= boolean_type_node
;
3344 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
3345 || code0
== COMPLEX_TYPE
)
3346 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
3347 || code1
== COMPLEX_TYPE
))
3349 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3351 register tree tt0
= TYPE_MAIN_VARIANT (TREE_TYPE (type0
));
3352 register tree tt1
= TYPE_MAIN_VARIANT (TREE_TYPE (type1
));
3354 if (comp_target_types (type0
, type1
, 1))
3355 result_type
= common_type (type0
, type1
);
3356 else if (tt0
== void_type_node
)
3358 if (pedantic
&& TREE_CODE (tt1
) == FUNCTION_TYPE
3359 && tree_int_cst_lt (TYPE_SIZE (type0
), TYPE_SIZE (type1
)))
3360 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3361 else if (TREE_CODE (tt1
) == OFFSET_TYPE
)
3362 pedwarn ("ANSI C++ forbids conversion of a pointer to member to `void *'");
3364 else if (tt1
== void_type_node
)
3366 if (pedantic
&& TREE_CODE (tt0
) == FUNCTION_TYPE
3367 && tree_int_cst_lt (TYPE_SIZE (type1
), TYPE_SIZE (type0
)))
3368 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3371 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3374 if (result_type
== NULL_TREE
)
3375 result_type
= ptr_type_node
;
3377 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
3378 && integer_zerop (op1
))
3379 result_type
= type0
;
3380 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
3381 && integer_zerop (op0
))
3382 result_type
= type1
;
3383 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3385 result_type
= type0
;
3386 error ("ANSI C++ forbids comparison between pointer and integer");
3388 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
3390 result_type
= type1
;
3391 error ("ANSI C++ forbids comparison between pointer and integer");
3393 else if (TYPE_PTRMEMFUNC_P (type0
) && TREE_CODE (op1
) == INTEGER_CST
3394 && integer_zerop (op1
))
3396 op0
= build_component_ref (op0
, index_identifier
, NULL_TREE
, 0);
3397 op1
= integer_zero_node
;
3398 result_type
= TREE_TYPE (op0
);
3400 else if (TYPE_PTRMEMFUNC_P (type1
) && TREE_CODE (op0
) == INTEGER_CST
3401 && integer_zerop (op0
))
3403 op0
= build_component_ref (op1
, index_identifier
, NULL_TREE
, 0);
3404 op1
= integer_zero_node
;
3405 result_type
= TREE_TYPE (op0
);
3407 else if (TYPE_PTRMEMFUNC_P (type0
) && TYPE_PTRMEMFUNC_P (type1
)
3408 && (TYPE_PTRMEMFUNC_FN_TYPE (type0
)
3409 == TYPE_PTRMEMFUNC_FN_TYPE (type1
)))
3411 /* The code we generate for the test is:
3413 (op0.index == op1.index
3414 && ((op1.index != -1 && op0.delta2 == op1.delta2)
3415 || op0.pfn == op1.pfn)) */
3417 tree index0
= build_component_ref (op0
, index_identifier
, NULL_TREE
, 0);
3418 tree index1
= save_expr (build_component_ref (op1
, index_identifier
, NULL_TREE
, 0));
3419 tree pfn0
= PFN_FROM_PTRMEMFUNC (op0
);
3420 tree pfn1
= PFN_FROM_PTRMEMFUNC (op1
);
3421 tree delta20
= DELTA2_FROM_PTRMEMFUNC (op0
);
3422 tree delta21
= DELTA2_FROM_PTRMEMFUNC (op1
);
3424 tree integer_neg_one_node
3425 = build_binary_op (MINUS_EXPR
, integer_zero_node
, integer_one_node
, 1);
3426 e1
= build_binary_op (EQ_EXPR
, index0
, index1
, 1);
3427 e2
= build_binary_op (NE_EXPR
, index1
, integer_neg_one_node
, 1);
3428 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e2
, build_binary_op (EQ_EXPR
, delta20
, delta21
, 1), 1);
3429 e3
= build_binary_op (EQ_EXPR
, pfn0
, pfn1
, 1);
3430 e2
= build_binary_op (TRUTH_ORIF_EXPR
, e2
, e3
, 1);
3431 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e1
, e2
, 1);
3432 if (code
== EQ_EXPR
)
3434 return build_binary_op (EQ_EXPR
, e2
, integer_zero_node
, 1);
3436 else if (TYPE_PTRMEMFUNC_P (type0
)
3437 && TYPE_PTRMEMFUNC_FN_TYPE (type0
) == type1
)
3439 tree index0
= build_component_ref (op0
, index_identifier
, NULL_TREE
, 0);
3441 tree pfn0
= PFN_FROM_PTRMEMFUNC (op0
);
3442 tree delta20
= DELTA2_FROM_PTRMEMFUNC (op0
);
3443 tree delta21
= integer_zero_node
;
3445 tree integer_neg_one_node
3446 = build_binary_op (MINUS_EXPR
, integer_zero_node
, integer_one_node
, 1);
3447 if (TREE_CODE (TREE_OPERAND (op1
, 0)) == FUNCTION_DECL
3448 && DECL_VINDEX (TREE_OPERAND (op1
, 0)))
3450 /* Map everything down one to make room for the null pointer to member. */
3451 index1
= size_binop (PLUS_EXPR
,
3452 DECL_VINDEX (TREE_OPERAND (op1
, 0)),
3454 op1
= integer_zero_node
;
3455 delta21
= CLASSTYPE_VFIELD (TYPE_METHOD_BASETYPE (TREE_TYPE (type1
)));
3456 delta21
= DECL_FIELD_BITPOS (delta21
);
3457 delta21
= size_binop (FLOOR_DIV_EXPR
, delta21
, size_int (BITS_PER_UNIT
));
3460 index1
= integer_neg_one_node
;
3462 tree nop1
= build1 (NOP_EXPR
, TYPE_PTRMEMFUNC_FN_TYPE (type0
), op1
);
3463 TREE_CONSTANT (nop1
) = TREE_CONSTANT (op1
);
3466 e1
= build_binary_op (EQ_EXPR
, index0
, index1
, 1);
3467 e2
= build_binary_op (NE_EXPR
, index1
, integer_neg_one_node
, 1);
3468 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e2
, build_binary_op (EQ_EXPR
, delta20
, delta21
, 1), 1);
3469 e3
= build_binary_op (EQ_EXPR
, pfn0
, op1
, 1);
3470 e2
= build_binary_op (TRUTH_ORIF_EXPR
, e2
, e3
, 1);
3471 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e1
, e2
, 1);
3472 if (code
== EQ_EXPR
)
3474 return build_binary_op (EQ_EXPR
, e2
, integer_zero_node
, 1);
3476 else if (TYPE_PTRMEMFUNC_P (type1
)
3477 && TYPE_PTRMEMFUNC_FN_TYPE (type1
) == type0
)
3479 return build_binary_op (code
, op1
, op0
, 1);
3485 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3486 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3488 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3490 if (comp_target_types (type0
, type1
, 1))
3491 result_type
= common_type (type0
, type1
);
3494 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3496 result_type
= ptr_type_node
;
3505 build_type
= boolean_type_node
;
3506 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3507 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3509 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3511 if (comp_target_types (type0
, type1
, 1))
3512 result_type
= common_type (type0
, type1
);
3515 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3517 result_type
= ptr_type_node
;
3520 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
3521 && integer_zerop (op1
))
3522 result_type
= type0
;
3523 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
3524 && integer_zerop (op0
))
3525 result_type
= type1
;
3526 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3528 result_type
= type0
;
3529 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3531 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
3533 result_type
= type1
;
3534 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3539 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
|| code0
== COMPLEX_TYPE
)
3541 (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
|| code1
== COMPLEX_TYPE
))
3543 int none_complex
= (code0
!= COMPLEX_TYPE
&& code1
!= COMPLEX_TYPE
);
3545 if (shorten
|| common
|| short_compare
)
3546 result_type
= common_type (type0
, type1
);
3548 /* For certain operations (which identify themselves by shorten != 0)
3549 if both args were extended from the same smaller type,
3550 do the arithmetic in that type and then extend.
3552 shorten !=0 and !=1 indicates a bitwise operation.
3553 For them, this optimization is safe only if
3554 both args are zero-extended or both are sign-extended.
3555 Otherwise, we might change the result.
3556 Eg, (short)-1 | (unsigned short)-1 is (int)-1
3557 but calculated in (unsigned short) it would be (unsigned short)-1. */
3559 if (shorten
&& none_complex
)
3561 int unsigned0
, unsigned1
;
3562 tree arg0
= get_narrower (op0
, &unsigned0
);
3563 tree arg1
= get_narrower (op1
, &unsigned1
);
3564 /* UNS is 1 if the operation to be done is an unsigned one. */
3565 int uns
= TREE_UNSIGNED (result_type
);
3568 final_type
= result_type
;
3570 /* Handle the case that OP0 does not *contain* a conversion
3571 but it *requires* conversion to FINAL_TYPE. */
3573 if (op0
== arg0
&& TREE_TYPE (op0
) != final_type
)
3574 unsigned0
= TREE_UNSIGNED (TREE_TYPE (op0
));
3575 if (op1
== arg1
&& TREE_TYPE (op1
) != final_type
)
3576 unsigned1
= TREE_UNSIGNED (TREE_TYPE (op1
));
3578 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
3580 /* For bitwise operations, signedness of nominal type
3581 does not matter. Consider only how operands were extended. */
3585 /* Note that in all three cases below we refrain from optimizing
3586 an unsigned operation on sign-extended args.
3587 That would not be valid. */
3589 /* Both args variable: if both extended in same way
3590 from same width, do it in that width.
3591 Do it unsigned if args were zero-extended. */
3592 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
3593 < TYPE_PRECISION (result_type
))
3594 && (TYPE_PRECISION (TREE_TYPE (arg1
))
3595 == TYPE_PRECISION (TREE_TYPE (arg0
)))
3596 && unsigned0
== unsigned1
3597 && (unsigned0
|| !uns
))
3599 = signed_or_unsigned_type (unsigned0
,
3600 common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
3601 else if (TREE_CODE (arg0
) == INTEGER_CST
3602 && (unsigned1
|| !uns
)
3603 && (TYPE_PRECISION (TREE_TYPE (arg1
))
3604 < TYPE_PRECISION (result_type
))
3605 && (type
= signed_or_unsigned_type (unsigned1
,
3607 int_fits_type_p (arg0
, type
)))
3609 else if (TREE_CODE (arg1
) == INTEGER_CST
3610 && (unsigned0
|| !uns
)
3611 && (TYPE_PRECISION (TREE_TYPE (arg0
))
3612 < TYPE_PRECISION (result_type
))
3613 && (type
= signed_or_unsigned_type (unsigned0
,
3615 int_fits_type_p (arg1
, type
)))
3619 /* Shifts can be shortened if shifting right. */
3624 tree arg0
= get_narrower (op0
, &unsigned_arg
);
3626 final_type
= result_type
;
3628 if (arg0
== op0
&& final_type
== TREE_TYPE (op0
))
3629 unsigned_arg
= TREE_UNSIGNED (TREE_TYPE (op0
));
3631 if (TYPE_PRECISION (TREE_TYPE (arg0
)) < TYPE_PRECISION (result_type
)
3632 /* We can shorten only if the shift count is less than the
3633 number of bits in the smaller type size. */
3634 && TREE_INT_CST_HIGH (op1
) == 0
3635 && TYPE_PRECISION (TREE_TYPE (arg0
)) > TREE_INT_CST_LOW (op1
)
3636 /* If arg is sign-extended and then unsigned-shifted,
3637 we can simulate this with a signed shift in arg's type
3638 only if the extended result is at least twice as wide
3639 as the arg. Otherwise, the shift could use up all the
3640 ones made by sign-extension and bring in zeros.
3641 We can't optimize that case at all, but in most machines
3642 it never happens because available widths are 2**N. */
3643 && (!TREE_UNSIGNED (final_type
)
3645 || (((unsigned) 2 * TYPE_PRECISION (TREE_TYPE (arg0
)))
3646 <= TYPE_PRECISION (result_type
))))
3648 /* Do an unsigned shift if the operand was zero-extended. */
3650 = signed_or_unsigned_type (unsigned_arg
,
3652 /* Convert value-to-be-shifted to that type. */
3653 if (TREE_TYPE (op0
) != result_type
)
3654 op0
= cp_convert (result_type
, op0
);
3659 /* Comparison operations are shortened too but differently.
3660 They identify themselves by setting short_compare = 1. */
3664 /* Don't write &op0, etc., because that would prevent op0
3665 from being kept in a register.
3666 Instead, make copies of the our local variables and
3667 pass the copies by reference, then copy them back afterward. */
3668 tree xop0
= op0
, xop1
= op1
, xresult_type
= result_type
;
3669 enum tree_code xresultcode
= resultcode
;
3671 = shorten_compare (&xop0
, &xop1
, &xresult_type
, &xresultcode
);
3673 return cp_convert (boolean_type_node
, val
);
3674 op0
= xop0
, op1
= xop1
;
3676 resultcode
= xresultcode
;
3679 if (short_compare
&& warn_sign_compare
)
3681 int op0_signed
= ! TREE_UNSIGNED (TREE_TYPE (orig_op0
));
3682 int op1_signed
= ! TREE_UNSIGNED (TREE_TYPE (orig_op1
));
3684 int unsignedp0
, unsignedp1
;
3685 tree primop0
= get_narrower (op0
, &unsignedp0
);
3686 tree primop1
= get_narrower (op1
, &unsignedp1
);
3688 /* Check for comparison of different enum types. */
3689 if (flag_int_enum_equivalence
== 0
3690 && TREE_CODE (TREE_TYPE (orig_op0
)) == ENUMERAL_TYPE
3691 && TREE_CODE (TREE_TYPE (orig_op1
)) == ENUMERAL_TYPE
3692 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0
))
3693 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1
)))
3695 cp_warning ("comparison between `%#T' and `%#T'",
3696 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
));
3699 /* Give warnings for comparisons between signed and unsigned
3700 quantities that may fail. */
3701 /* Do the checking based on the original operand trees, so that
3702 casts will be considered, but default promotions won't be. */
3704 /* Do not warn if the comparison is being done in a signed type,
3705 since the signed type will only be chosen if it can represent
3706 all the values of the unsigned type. */
3707 if (! TREE_UNSIGNED (result_type
))
3709 /* Do not warn if both operands are unsigned. */
3710 else if (op0_signed
== op1_signed
)
3712 /* Do not warn if the signed quantity is an unsuffixed
3713 integer literal (or some static constant expression
3714 involving such literals) and it is non-negative. */
3715 else if ((op0_signed
&& TREE_CODE (orig_op0
) == INTEGER_CST
3716 && tree_int_cst_sgn (orig_op0
) >= 0)
3717 || (op1_signed
&& TREE_CODE (orig_op1
) == INTEGER_CST
3718 && tree_int_cst_sgn (orig_op1
) >= 0))
3720 /* Do not warn if the comparison is an equality operation,
3721 the unsigned quantity is an integral constant and it does
3722 not use the most significant bit of result_type. */
3723 else if ((resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
3724 && ((op0_signed
&& TREE_CODE (orig_op1
) == INTEGER_CST
3725 && int_fits_type_p (orig_op1
, signed_type (result_type
))
3726 || (op1_signed
&& TREE_CODE (orig_op0
) == INTEGER_CST
3727 && int_fits_type_p (orig_op0
, signed_type (result_type
))))))
3730 warning ("comparison between signed and unsigned");
3732 /* Warn if two unsigned values are being compared in a size
3733 larger than their original size, and one (and only one) is the
3734 result of a `~' operator. This comparison will always fail.
3736 Also warn if one operand is a constant, and the constant does not
3737 have all bits set that are set in the ~ operand when it is
3740 if ((TREE_CODE (primop0
) == BIT_NOT_EXPR
)
3741 ^ (TREE_CODE (primop1
) == BIT_NOT_EXPR
))
3743 if (TREE_CODE (primop0
) == BIT_NOT_EXPR
)
3744 primop0
= get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
3745 if (TREE_CODE (primop1
) == BIT_NOT_EXPR
)
3746 primop1
= get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
3748 if (TREE_CODE (primop0
) == INTEGER_CST
3749 || TREE_CODE (primop1
) == INTEGER_CST
)
3752 HOST_WIDE_INT constant
, mask
;
3756 if (TREE_CODE (primop0
) == INTEGER_CST
)
3759 unsignedp
= unsignedp1
;
3760 constant
= TREE_INT_CST_LOW (primop0
);
3765 unsignedp
= unsignedp0
;
3766 constant
= TREE_INT_CST_LOW (primop1
);
3769 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
3770 if (bits
< TYPE_PRECISION (result_type
)
3771 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
3773 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
3774 if ((mask
& constant
) != mask
)
3775 warning ("comparison of promoted ~unsigned with constant");
3778 else if (unsignedp0
&& unsignedp1
3779 && (TYPE_PRECISION (TREE_TYPE (primop0
))
3780 < TYPE_PRECISION (result_type
))
3781 && (TYPE_PRECISION (TREE_TYPE (primop1
))
3782 < TYPE_PRECISION (result_type
)))
3783 warning ("comparison of promoted ~unsigned with unsigned");
3788 /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
3789 If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
3790 Then the expression will be built.
3791 It will be given type FINAL_TYPE if that is nonzero;
3792 otherwise, it will be given type RESULT_TYPE. */
3796 cp_error ("invalid operands `%T' and `%T' to binary `%O'",
3797 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
), error_code
);
3798 return error_mark_node
;
3803 if (TREE_TYPE (op0
) != result_type
)
3804 op0
= cp_convert (result_type
, op0
);
3805 if (TREE_TYPE (op1
) != result_type
)
3806 op1
= cp_convert (result_type
, op1
);
3809 if (build_type
== NULL_TREE
)
3810 build_type
= result_type
;
3813 register tree result
= build (resultcode
, build_type
, op0
, op1
);
3814 register tree folded
;
3816 folded
= fold (result
);
3817 if (folded
== result
)
3818 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
3819 if (final_type
!= 0)
3820 return cp_convert (final_type
, folded
);
3825 /* Return a tree for the sum or difference (RESULTCODE says which)
3826 of pointer PTROP and integer INTOP. */
3829 pointer_int_sum (resultcode
, ptrop
, intop
)
3830 enum tree_code resultcode
;
3831 register tree ptrop
, intop
;
3835 register tree result
;
3836 register tree folded
= fold (intop
);
3838 /* The result is a pointer of the same type that is being added. */
3840 register tree result_type
= TREE_TYPE (ptrop
);
3842 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
3844 if (pedantic
|| warn_pointer_arith
)
3845 pedwarn ("ANSI C++ forbids using pointer of type `void *' in arithmetic");
3846 size_exp
= integer_one_node
;
3848 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
3850 if (pedantic
|| warn_pointer_arith
)
3851 pedwarn ("ANSI C++ forbids using pointer to a function in arithmetic");
3852 size_exp
= integer_one_node
;
3854 else if (TREE_CODE (TREE_TYPE (result_type
)) == METHOD_TYPE
)
3856 if (pedantic
|| warn_pointer_arith
)
3857 pedwarn ("ANSI C++ forbids using pointer to a method in arithmetic");
3858 size_exp
= integer_one_node
;
3860 else if (TREE_CODE (TREE_TYPE (result_type
)) == OFFSET_TYPE
)
3862 if (pedantic
|| warn_pointer_arith
)
3863 pedwarn ("ANSI C++ forbids using pointer to a member in arithmetic");
3864 size_exp
= integer_one_node
;
3867 size_exp
= size_in_bytes (complete_type (TREE_TYPE (result_type
)));
3869 /* Needed to make OOPS V2R3 work. */
3871 if (TREE_CODE (intop
) == INTEGER_CST
3872 && TREE_INT_CST_LOW (intop
) == 0
3873 && TREE_INT_CST_HIGH (intop
) == 0)
3876 /* If what we are about to multiply by the size of the elements
3877 contains a constant term, apply distributive law
3878 and multiply that constant term separately.
3879 This helps produce common subexpressions. */
3881 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
3882 && ! TREE_CONSTANT (intop
)
3883 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
3884 && TREE_CONSTANT (size_exp
))
3886 enum tree_code subcode
= resultcode
;
3887 if (TREE_CODE (intop
) == MINUS_EXPR
)
3888 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
3889 ptrop
= build_binary_op (subcode
, ptrop
, TREE_OPERAND (intop
, 1), 1);
3890 intop
= TREE_OPERAND (intop
, 0);
3893 /* Convert the integer argument to a type the same size as sizetype
3894 so the multiply won't overflow spuriously. */
3896 if (TYPE_PRECISION (TREE_TYPE (intop
)) != TYPE_PRECISION (sizetype
))
3897 intop
= cp_convert (type_for_size (TYPE_PRECISION (sizetype
), 0), intop
);
3899 /* Replace the integer argument with a suitable product by the object size.
3900 Do this multiplication as signed, then convert to the appropriate
3901 pointer type (actually unsigned integral). */
3903 intop
= cp_convert (result_type
,
3904 build_binary_op (MULT_EXPR
, intop
,
3905 cp_convert (TREE_TYPE (intop
), size_exp
), 1));
3907 /* Create the sum or difference. */
3909 result
= build (resultcode
, result_type
, ptrop
, intop
);
3911 folded
= fold (result
);
3912 if (folded
== result
)
3913 TREE_CONSTANT (folded
) = TREE_CONSTANT (ptrop
) & TREE_CONSTANT (intop
);
3917 /* Return a tree for the difference of pointers OP0 and OP1.
3918 The resulting tree has type int. */
3921 pointer_diff (op0
, op1
)
3922 register tree op0
, op1
;
3924 register tree result
, folded
;
3925 tree restype
= ptrdiff_type_node
;
3926 tree target_type
= TREE_TYPE (TREE_TYPE (op0
));
3928 if (pedantic
|| warn_pointer_arith
)
3930 if (TREE_CODE (target_type
) == VOID_TYPE
)
3931 pedwarn ("ANSI C++ forbids using pointer of type `void *' in subtraction");
3932 if (TREE_CODE (target_type
) == FUNCTION_TYPE
)
3933 pedwarn ("ANSI C++ forbids using pointer to a function in subtraction");
3934 if (TREE_CODE (target_type
) == METHOD_TYPE
)
3935 pedwarn ("ANSI C++ forbids using pointer to a method in subtraction");
3936 if (TREE_CODE (target_type
) == OFFSET_TYPE
)
3937 pedwarn ("ANSI C++ forbids using pointer to a member in subtraction");
3940 /* First do the subtraction as integers;
3941 then drop through to build the divide operator. */
3943 op0
= build_binary_op (MINUS_EXPR
,
3944 cp_convert (restype
, op0
), cp_convert (restype
, op1
), 1);
3946 /* This generates an error if op1 is a pointer to an incomplete type. */
3947 if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1
))) == 0)
3948 error ("arithmetic on pointer to an incomplete type");
3950 op1
= ((TREE_CODE (target_type
) == VOID_TYPE
3951 || TREE_CODE (target_type
) == FUNCTION_TYPE
3952 || TREE_CODE (target_type
) == METHOD_TYPE
3953 || TREE_CODE (target_type
) == OFFSET_TYPE
)
3955 : size_in_bytes (target_type
));
3957 /* Do the division. */
3959 result
= build (EXACT_DIV_EXPR
, restype
, op0
, cp_convert (restype
, op1
));
3961 folded
= fold (result
);
3962 if (folded
== result
)
3963 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
3967 /* Handle the case of taking the address of a COMPONENT_REF.
3968 Called by `build_unary_op' and `build_up_reference'.
3970 ARG is the COMPONENT_REF whose address we want.
3971 ARGTYPE is the pointer type that this address should have.
3972 MSG is an error message to print if this COMPONENT_REF is not
3973 addressable (such as a bitfield). */
3976 build_component_addr (arg
, argtype
, msg
)
3980 tree field
= TREE_OPERAND (arg
, 1);
3981 tree basetype
= decl_type_context (field
);
3982 tree rval
= build_unary_op (ADDR_EXPR
, TREE_OPERAND (arg
, 0), 0);
3984 if (DECL_BIT_FIELD (field
))
3986 error (msg
, IDENTIFIER_POINTER (DECL_NAME (field
)));
3987 return error_mark_node
;
3990 if (TREE_CODE (field
) == FIELD_DECL
3991 && TYPE_USES_COMPLEX_INHERITANCE (basetype
))
3993 /* Can't convert directly to ARGTYPE, since that
3994 may have the same pointer type as one of our
3996 rval
= build1 (NOP_EXPR
, argtype
,
3997 convert_pointer_to (basetype
, rval
));
3998 TREE_CONSTANT (rval
) = TREE_CONSTANT (TREE_OPERAND (rval
, 0));
4001 /* This conversion is harmless. */
4002 rval
= convert_force (argtype
, rval
, 0);
4004 if (! integer_zerop (DECL_FIELD_BITPOS (field
)))
4006 tree offset
= size_binop (EASY_DIV_EXPR
, DECL_FIELD_BITPOS (field
),
4007 size_int (BITS_PER_UNIT
));
4008 int flag
= TREE_CONSTANT (rval
);
4009 rval
= fold (build (PLUS_EXPR
, argtype
,
4010 rval
, cp_convert (argtype
, offset
)));
4011 TREE_CONSTANT (rval
) = flag
;
4016 /* Construct and perhaps optimize a tree representation
4017 for a unary operation. CODE, a tree_code, specifies the operation
4018 and XARG is the operand. */
4021 build_x_unary_op (code
, xarg
)
4022 enum tree_code code
;
4025 if (processing_template_decl
)
4026 return build_min_nt (code
, xarg
, NULL_TREE
);
4028 /* & rec, on incomplete RECORD_TYPEs is the simple opr &, not an
4030 if (code
== ADDR_EXPR
4031 && TREE_CODE (xarg
) != TEMPLATE_ID_EXPR
4032 && ((IS_AGGR_TYPE_CODE (TREE_CODE (TREE_TYPE (xarg
)))
4033 && TYPE_SIZE (TREE_TYPE (xarg
)) == NULL_TREE
)
4034 || (TREE_CODE (xarg
) == OFFSET_REF
)))
4035 /* don't look for a function */;
4040 if (flag_ansi_overloading
)
4042 rval
= build_new_op (code
, LOOKUP_NORMAL
, xarg
,
4043 NULL_TREE
, NULL_TREE
);
4044 if (rval
|| code
!= ADDR_EXPR
)
4049 rval
= build_opfncall (code
, LOOKUP_SPECULATIVELY
, xarg
,
4050 NULL_TREE
, NULL_TREE
);
4052 return build_opfncall (code
, LOOKUP_NORMAL
, xarg
,
4053 NULL_TREE
, NULL_TREE
);
4057 if (code
== ADDR_EXPR
)
4059 if (TREE_CODE (xarg
) == TARGET_EXPR
)
4060 warning ("taking address of temporary");
4063 return build_unary_op (code
, xarg
, 0);
4066 /* Just like truthvalue_conversion, but we want a CLEANUP_POINT_EXPR. */
4069 condition_conversion (expr
)
4073 if (processing_template_decl
)
4075 t
= cp_convert (boolean_type_node
, expr
);
4076 t
= fold (build1 (CLEANUP_POINT_EXPR
, boolean_type_node
, t
));
4080 /* C++: Must handle pointers to members.
4082 Perhaps type instantiation should be extended to handle conversion
4083 from aggregates to types we don't yet know we want? (Or are those
4084 cases typically errors which should be reported?)
4086 NOCONVERT nonzero suppresses the default promotions
4087 (such as from short to int). */
4090 build_unary_op (code
, xarg
, noconvert
)
4091 enum tree_code code
;
4095 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
4096 register tree arg
= xarg
;
4097 register tree argtype
= 0;
4098 char *errstring
= NULL
;
4101 if (arg
== error_mark_node
)
4102 return error_mark_node
;
4107 /* This is used for unary plus, because a CONVERT_EXPR
4108 is enough to prevent anybody from looking inside for
4109 associativity, but won't generate any code. */
4110 if (!(arg
= build_expr_type_conversion
4111 (WANT_ARITH
| WANT_ENUM
| WANT_POINTER
, arg
, 1)))
4112 errstring
= "wrong type argument to unary plus";
4116 arg
= default_conversion (arg
);
4117 arg
= build1 (NON_LVALUE_EXPR
, TREE_TYPE (arg
), arg
);
4122 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
4123 errstring
= "wrong type argument to unary minus";
4124 else if (!noconvert
)
4125 arg
= default_conversion (arg
);
4129 if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
4133 arg
= default_conversion (arg
);
4135 else if (!(arg
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
,
4137 errstring
= "wrong type argument to bit-complement";
4138 else if (!noconvert
)
4139 arg
= default_conversion (arg
);
4143 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
4144 errstring
= "wrong type argument to abs";
4145 else if (!noconvert
)
4146 arg
= default_conversion (arg
);
4150 /* Conjugating a real value is a no-op, but allow it anyway. */
4151 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
4152 errstring
= "wrong type argument to conjugation";
4153 else if (!noconvert
)
4154 arg
= default_conversion (arg
);
4157 case TRUTH_NOT_EXPR
:
4158 arg
= cp_convert (boolean_type_node
, arg
);
4159 val
= invert_truthvalue (arg
);
4160 if (arg
!= error_mark_node
)
4162 errstring
= "in argument to unary !";
4169 if (TREE_CODE (arg
) == COMPLEX_CST
)
4170 return TREE_REALPART (arg
);
4171 else if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
4172 return fold (build1 (REALPART_EXPR
, TREE_TYPE (TREE_TYPE (arg
)), arg
));
4177 if (TREE_CODE (arg
) == COMPLEX_CST
)
4178 return TREE_IMAGPART (arg
);
4179 else if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
4180 return fold (build1 (IMAGPART_EXPR
, TREE_TYPE (TREE_TYPE (arg
)), arg
));
4182 return cp_convert (TREE_TYPE (arg
), integer_zero_node
);
4184 case PREINCREMENT_EXPR
:
4185 case POSTINCREMENT_EXPR
:
4186 case PREDECREMENT_EXPR
:
4187 case POSTDECREMENT_EXPR
:
4188 /* Handle complex lvalues (when permitted)
4189 by reduction to simpler cases. */
4191 val
= unary_complex_lvalue (code
, arg
);
4195 /* Increment or decrement the real part of the value,
4196 and don't change the imaginary part. */
4197 if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
4201 arg
= stabilize_reference (arg
);
4202 real
= build_unary_op (REALPART_EXPR
, arg
, 1);
4203 imag
= build_unary_op (IMAGPART_EXPR
, arg
, 1);
4204 return build (COMPLEX_EXPR
, TREE_TYPE (arg
),
4205 build_unary_op (code
, real
, 1), imag
);
4208 /* Report invalid types. */
4210 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_POINTER
,
4213 if (code
== PREINCREMENT_EXPR
)
4214 errstring
="no pre-increment operator for type";
4215 else if (code
== POSTINCREMENT_EXPR
)
4216 errstring
="no post-increment operator for type";
4217 else if (code
== PREDECREMENT_EXPR
)
4218 errstring
="no pre-decrement operator for type";
4220 errstring
="no post-decrement operator for type";
4224 /* Report something read-only. */
4226 if (TYPE_READONLY (TREE_TYPE (arg
))
4227 || TREE_READONLY (arg
))
4228 readonly_error (arg
, ((code
== PREINCREMENT_EXPR
4229 || code
== POSTINCREMENT_EXPR
)
4230 ? "increment" : "decrement"),
4235 tree result_type
= TREE_TYPE (arg
);
4237 arg
= get_unwidened (arg
, 0);
4238 argtype
= TREE_TYPE (arg
);
4240 /* ARM $5.2.5 last annotation says this should be forbidden. */
4241 if (TREE_CODE (argtype
) == ENUMERAL_TYPE
)
4242 pedwarn ("ANSI C++ forbids %sing an enum",
4243 (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
4244 ? "increment" : "decrement");
4246 /* Compute the increment. */
4248 if (TREE_CODE (argtype
) == POINTER_TYPE
)
4250 enum tree_code tmp
= TREE_CODE (TREE_TYPE (argtype
));
4251 if (TYPE_SIZE (complete_type (TREE_TYPE (argtype
))) == 0)
4252 cp_error ("cannot %s a pointer to incomplete type `%T'",
4253 ((code
== PREINCREMENT_EXPR
4254 || code
== POSTINCREMENT_EXPR
)
4255 ? "increment" : "decrement"), TREE_TYPE (argtype
));
4256 else if (tmp
== FUNCTION_TYPE
|| tmp
== METHOD_TYPE
4257 || tmp
== VOID_TYPE
|| tmp
== OFFSET_TYPE
)
4258 cp_pedwarn ("ANSI C++ forbids %sing a pointer of type `%T'",
4259 ((code
== PREINCREMENT_EXPR
4260 || code
== POSTINCREMENT_EXPR
)
4261 ? "increment" : "decrement"), argtype
);
4262 inc
= c_sizeof_nowarn (TREE_TYPE (argtype
));
4265 inc
= integer_one_node
;
4267 inc
= cp_convert (argtype
, inc
);
4269 /* Handle incrementing a cast-expression. */
4271 switch (TREE_CODE (arg
))
4276 case FIX_TRUNC_EXPR
:
4277 case FIX_FLOOR_EXPR
:
4278 case FIX_ROUND_EXPR
:
4281 tree incremented
, modify
, value
, compound
;
4282 if (! lvalue_p (arg
) && pedantic
)
4283 pedwarn ("cast to non-reference type used as lvalue");
4284 arg
= stabilize_reference (arg
);
4285 if (code
== PREINCREMENT_EXPR
|| code
== PREDECREMENT_EXPR
)
4288 value
= save_expr (arg
);
4289 incremented
= build (((code
== PREINCREMENT_EXPR
4290 || code
== POSTINCREMENT_EXPR
)
4291 ? PLUS_EXPR
: MINUS_EXPR
),
4292 argtype
, value
, inc
);
4293 TREE_SIDE_EFFECTS (incremented
) = 1;
4295 modify
= build_modify_expr (arg
, NOP_EXPR
, incremented
);
4296 compound
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), modify
, value
);
4298 /* Eliminate warning about unused result of + or -. */
4299 TREE_NO_UNUSED_WARNING (compound
) = 1;
4304 /* Complain about anything else that is not a true lvalue. */
4305 if (!lvalue_or_else (arg
, ((code
== PREINCREMENT_EXPR
4306 || code
== POSTINCREMENT_EXPR
)
4307 ? "increment" : "decrement")))
4308 return error_mark_node
;
4310 /* Forbid using -- on `bool'. */
4311 if (TREE_TYPE (arg
) == boolean_type_node
)
4313 if (code
== POSTDECREMENT_EXPR
|| code
== PREDECREMENT_EXPR
)
4315 cp_error ("invalid use of `--' on bool variable `%D'", arg
);
4316 return error_mark_node
;
4319 /* This will only work if someone can convince Kenner to accept
4320 my patch to expand_increment. (jason) */
4321 val
= build (code
, TREE_TYPE (arg
), arg
, inc
);
4323 if (code
== POSTINCREMENT_EXPR
)
4325 arg
= stabilize_reference (arg
);
4326 val
= build (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
4328 TREE_SIDE_EFFECTS (val
) = 1;
4329 arg
= save_expr (arg
);
4330 val
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
4331 val
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
4334 val
= build (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
4339 val
= build (code
, TREE_TYPE (arg
), arg
, inc
);
4341 TREE_SIDE_EFFECTS (val
) = 1;
4342 return cp_convert (result_type
, val
);
4346 /* Note that this operation never does default_conversion
4347 regardless of NOCONVERT. */
4349 argtype
= TREE_TYPE (arg
);
4350 if (TREE_CODE (argtype
) == REFERENCE_TYPE
)
4354 build_pointer_type (TREE_TYPE (TREE_TYPE (arg
))), arg
);
4355 TREE_CONSTANT (arg
) = TREE_CONSTANT (TREE_OPERAND (arg
, 0));
4359 && TREE_CODE (arg
) == FUNCTION_DECL
4361 && DECL_CONTEXT (arg
) == NULL_TREE
4362 && IDENTIFIER_LENGTH (DECL_NAME (arg
)) == 4
4363 && IDENTIFIER_POINTER (DECL_NAME (arg
))[0] == 'm'
4364 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (arg
)), "main"))
4366 pedwarn ("taking address of function `main'");
4368 /* Let &* cancel out to simplify resulting code. */
4369 if (TREE_CODE (arg
) == INDIRECT_REF
)
4371 /* We don't need to have `current_class_ptr' wrapped in a
4372 NON_LVALUE_EXPR node. */
4373 if (arg
== current_class_ref
)
4374 return current_class_ptr
;
4376 arg
= TREE_OPERAND (arg
, 0);
4377 if (TREE_CODE (TREE_TYPE (arg
)) == REFERENCE_TYPE
)
4381 build_pointer_type (TREE_TYPE (TREE_TYPE (arg
))), arg
);
4382 TREE_CONSTANT (arg
) = TREE_CONSTANT (TREE_OPERAND (arg
, 0));
4384 else if (lvalue_p (arg
))
4385 /* Don't let this be an lvalue. */
4386 return non_lvalue (arg
);
4390 /* For &x[y], return x+y */
4391 if (TREE_CODE (arg
) == ARRAY_REF
)
4393 if (mark_addressable (TREE_OPERAND (arg
, 0)) == 0)
4394 return error_mark_node
;
4395 return build_binary_op (PLUS_EXPR
, TREE_OPERAND (arg
, 0),
4396 TREE_OPERAND (arg
, 1), 1);
4399 /* Uninstantiated types are all functions. Taking the
4400 address of a function is a no-op, so just return the
4403 if (TREE_CODE (arg
) == IDENTIFIER_NODE
4404 && IDENTIFIER_OPNAME_P (arg
))
4406 my_friendly_abort (117);
4407 /* We don't know the type yet, so just work around the problem.
4408 We know that this will resolve to an lvalue. */
4409 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4412 if (TREE_CODE (arg
) == TREE_LIST
)
4414 if (TREE_CODE (TREE_VALUE (arg
)) == FUNCTION_DECL
4415 && DECL_CHAIN (TREE_VALUE (arg
)) == NULL_TREE
)
4416 /* Unique overloaded non-member function. */
4417 return build_unary_op (ADDR_EXPR
, TREE_VALUE (arg
), 0);
4418 if (TREE_CHAIN (arg
) == NULL_TREE
4419 && TREE_CODE (TREE_VALUE (arg
)) == TREE_LIST
4420 && DECL_CHAIN (TREE_VALUE (TREE_VALUE (arg
))) == NULL_TREE
)
4421 /* Unique overloaded member function. */
4422 return build_unary_op (ADDR_EXPR
, TREE_VALUE (TREE_VALUE (arg
)),
4424 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4426 else if (TREE_CODE (arg
) == TEMPLATE_ID_EXPR
)
4431 /* We don't require a match here; it's possible that the
4432 context (like a cast to a particular type) will resolve
4433 the particular choice of template. */
4434 fn
= determine_explicit_specialization (arg
, NULL_TREE
,
4440 fn
= instantiate_template (fn
, targs
);
4441 mark_addressable (fn
);
4442 return build_unary_op (ADDR_EXPR
, fn
, 0);
4445 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4448 /* Handle complex lvalues (when permitted)
4449 by reduction to simpler cases. */
4450 val
= unary_complex_lvalue (code
, arg
);
4454 switch (TREE_CODE (arg
))
4459 case FIX_TRUNC_EXPR
:
4460 case FIX_FLOOR_EXPR
:
4461 case FIX_ROUND_EXPR
:
4463 if (! lvalue_p (arg
) && pedantic
)
4464 pedwarn ("taking the address of a cast to non-reference type");
4467 /* Allow the address of a constructor if all the elements
4469 if (TREE_CODE (arg
) == CONSTRUCTOR
&& TREE_CONSTANT (arg
))
4471 /* Anything not already handled and not a true memory reference
4473 else if (TREE_CODE (argtype
) != FUNCTION_TYPE
4474 && TREE_CODE (argtype
) != METHOD_TYPE
4475 && !lvalue_or_else (arg
, "unary `&'"))
4476 return error_mark_node
;
4478 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
4479 /* If the lvalue is const or volatile,
4480 merge that into the type that the address will point to. */
4481 if (TREE_CODE_CLASS (TREE_CODE (arg
)) == 'd'
4482 || TREE_CODE_CLASS (TREE_CODE (arg
)) == 'r')
4484 if (TREE_READONLY (arg
) || TREE_THIS_VOLATILE (arg
))
4485 argtype
= cp_build_type_variant (argtype
,
4486 TREE_READONLY (arg
),
4487 TREE_THIS_VOLATILE (arg
));
4490 argtype
= build_pointer_type (argtype
);
4492 if (mark_addressable (arg
) == 0)
4493 return error_mark_node
;
4498 if (TREE_CODE (arg
) == COMPONENT_REF
)
4499 addr
= build_component_addr (arg
, argtype
,
4500 "attempt to take address of bit-field structure member `%s'");
4502 addr
= build1 (code
, argtype
, arg
);
4504 /* Address of a static or external variable or
4505 function counts as a constant */
4507 TREE_CONSTANT (addr
) = 1;
4509 if (TREE_CODE (argtype
) == POINTER_TYPE
4510 && TREE_CODE (TREE_TYPE (argtype
)) == METHOD_TYPE
)
4512 build_ptrmemfunc_type (argtype
);
4513 addr
= build_ptrmemfunc (argtype
, addr
, 0);
4523 argtype
= TREE_TYPE (arg
);
4524 return fold (build1 (code
, argtype
, arg
));
4528 return error_mark_node
;
4532 /* If CONVERSIONS is a conversion expression or a nested sequence of such,
4533 convert ARG with the same conversions in the same order
4534 and return the result. */
4537 convert_sequence (conversions
, arg
)
4541 switch (TREE_CODE (conversions
))
4546 case FIX_TRUNC_EXPR
:
4547 case FIX_FLOOR_EXPR
:
4548 case FIX_ROUND_EXPR
:
4550 return cp_convert (TREE_TYPE (conversions
),
4551 convert_sequence (TREE_OPERAND (conversions
, 0),
4560 /* Apply unary lvalue-demanding operator CODE to the expression ARG
4561 for certain kinds of expressions which are not really lvalues
4562 but which we can accept as lvalues.
4564 If ARG is not a kind of expression we can handle, return zero. */
4567 unary_complex_lvalue (code
, arg
)
4568 enum tree_code code
;
4571 /* Handle (a, b) used as an "lvalue". */
4572 if (TREE_CODE (arg
) == COMPOUND_EXPR
)
4574 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 1), 0);
4575 return build (COMPOUND_EXPR
, TREE_TYPE (real_result
),
4576 TREE_OPERAND (arg
, 0), real_result
);
4579 /* Handle (a ? b : c) used as an "lvalue". */
4580 if (TREE_CODE (arg
) == COND_EXPR
)
4581 return rationalize_conditional_expr (code
, arg
);
4583 if (TREE_CODE (arg
) == MODIFY_EXPR
4584 || TREE_CODE (arg
) == PREINCREMENT_EXPR
4585 || TREE_CODE (arg
) == PREDECREMENT_EXPR
)
4586 return unary_complex_lvalue
4587 (code
, build (COMPOUND_EXPR
, TREE_TYPE (TREE_OPERAND (arg
, 0)),
4588 arg
, TREE_OPERAND (arg
, 0)));
4590 if (code
!= ADDR_EXPR
)
4593 /* Handle (a = b) used as an "lvalue" for `&'. */
4594 if (TREE_CODE (arg
) == MODIFY_EXPR
4595 || TREE_CODE (arg
) == INIT_EXPR
)
4597 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 0), 0);
4598 arg
= build (COMPOUND_EXPR
, TREE_TYPE (real_result
), arg
, real_result
);
4599 TREE_NO_UNUSED_WARNING (arg
) = 1;
4603 if (TREE_CODE (TREE_TYPE (arg
)) == FUNCTION_TYPE
4604 || TREE_CODE (TREE_TYPE (arg
)) == METHOD_TYPE
4605 || TREE_CODE (TREE_TYPE (arg
)) == OFFSET_TYPE
)
4607 /* The representation of something of type OFFSET_TYPE
4608 is really the representation of a pointer to it.
4609 Here give the representation its true type. */
4612 my_friendly_assert (TREE_CODE (arg
) != SCOPE_REF
, 313);
4614 if (TREE_CODE (arg
) != OFFSET_REF
)
4617 t
= TREE_OPERAND (arg
, 1);
4619 if (TREE_CODE (t
) == FUNCTION_DECL
) /* Check all this code for right semantics. */
4620 return build_unary_op (ADDR_EXPR
, t
, 0);
4621 if (TREE_CODE (t
) == VAR_DECL
)
4622 return build_unary_op (ADDR_EXPR
, t
, 0);
4626 tree offset
= integer_zero_node
;
4628 if (TREE_OPERAND (arg
, 0)
4629 && (TREE_CODE (TREE_OPERAND (arg
, 0)) != NOP_EXPR
4630 || TREE_OPERAND (TREE_OPERAND (arg
, 0), 0) != error_mark_node
))
4631 if (TREE_CODE (t
) != FIELD_DECL
)
4633 /* Don't know if this should return address to just
4634 _DECL, or actual address resolved in this expression. */
4635 sorry ("address of bound pointer-to-member expression");
4636 return error_mark_node
;
4639 type
= TREE_TYPE (TREE_OPERAND (arg
, 0));
4641 if (TREE_CODE (TREE_TYPE (arg
)) == OFFSET_TYPE
)
4643 /* Add in the offset to the intermediate subobject, if any. */
4644 offset
= get_delta_difference (TYPE_OFFSET_BASETYPE (TREE_TYPE (arg
)),
4647 type
= TYPE_OFFSET_BASETYPE (TREE_TYPE (arg
));
4650 /* Now in the offset to the final subobject. */
4651 offset
= size_binop (PLUS_EXPR
,
4653 get_delta_difference (DECL_FIELD_CONTEXT (t
),
4657 /* Add in the offset to the field. */
4658 offset
= size_binop (PLUS_EXPR
, offset
,
4659 size_binop (EASY_DIV_EXPR
,
4660 DECL_FIELD_BITPOS (t
),
4661 size_int (BITS_PER_UNIT
)));
4663 /* We offset all pointer to data memebers by 1 so that we can
4664 distinguish between a null pointer to data member and the first
4665 data member of a structure. */
4666 offset
= size_binop (PLUS_EXPR
, offset
, size_int (1));
4668 return cp_convert (build_pointer_type (TREE_TYPE (arg
)), offset
);
4673 /* We permit compiler to make function calls returning
4674 objects of aggregate type look like lvalues. */
4678 if (TREE_CODE (targ
) == SAVE_EXPR
)
4679 targ
= TREE_OPERAND (targ
, 0);
4681 if (TREE_CODE (targ
) == CALL_EXPR
&& IS_AGGR_TYPE (TREE_TYPE (targ
)))
4683 if (TREE_CODE (arg
) == SAVE_EXPR
)
4686 targ
= build_cplus_new (TREE_TYPE (arg
), arg
);
4687 return build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (arg
)), targ
);
4690 if (TREE_CODE (arg
) == SAVE_EXPR
&& TREE_CODE (targ
) == INDIRECT_REF
)
4691 return build (SAVE_EXPR
, build_pointer_type (TREE_TYPE (arg
)),
4692 TREE_OPERAND (targ
, 0), current_function_decl
, NULL
);
4695 /* Don't let anything else be handled specially. */
4699 /* Mark EXP saying that we need to be able to take the
4700 address of it; it should not be allocated in a register.
4701 Value is 1 if successful.
4703 C++: we do not allow `current_class_ptr' to be addressable. */
4706 mark_addressable (exp
)
4709 register tree x
= exp
;
4711 if (TREE_ADDRESSABLE (x
) == 1)
4715 switch (TREE_CODE (x
))
4722 x
= TREE_OPERAND (x
, 0);
4726 if (x
== current_class_ptr
)
4728 if (! flag_this_is_variable
)
4729 error ("address of `this' not available");
4730 TREE_ADDRESSABLE (x
) = 1; /* so compiler doesn't die later */
4731 put_var_into_stack (x
);
4735 if (TREE_STATIC (x
) && TREE_READONLY (x
)
4736 && DECL_RTL (x
) != 0
4737 && ! DECL_IN_MEMORY_P (x
))
4739 /* We thought this would make a good constant variable,
4740 but we were wrong. */
4741 push_obstacks_nochange ();
4742 end_temporary_allocation ();
4744 TREE_ASM_WRITTEN (x
) = 0;
4746 rest_of_decl_compilation (x
, 0, IDENTIFIER_LOCAL_VALUE (x
) == 0, 0);
4747 TREE_ADDRESSABLE (x
) = 1;
4753 /* Caller should not be trying to mark initialized
4754 constant fields addressable. */
4755 my_friendly_assert (DECL_LANG_SPECIFIC (x
) == 0
4756 || DECL_IN_AGGR_P (x
) == 0
4758 || DECL_EXTERNAL (x
), 314);
4762 if (DECL_REGISTER (x
) && !TREE_ADDRESSABLE (x
)
4763 && !DECL_ARTIFICIAL (x
) && extra_warnings
)
4764 cp_warning ("address requested for `%D', which is declared `register'",
4766 put_var_into_stack (x
);
4767 TREE_ADDRESSABLE (x
) = 1;
4771 /* We have to test both conditions here. The first may
4772 be non-zero in the case of processing a default function.
4773 The second may be non-zero in the case of a template function. */
4774 x
= DECL_MAIN_VARIANT (x
);
4775 if (DECL_TEMPLATE_INFO (x
) && !DECL_TEMPLATE_SPECIALIZATION (x
))
4777 TREE_ADDRESSABLE (x
) = 1;
4779 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x
)) = 1;
4783 TREE_ADDRESSABLE (x
) = 1;
4787 TREE_ADDRESSABLE (x
) = 1;
4788 mark_addressable (TREE_OPERAND (x
, 0));
4796 /* Build and return a conditional expression IFEXP ? OP1 : OP2. */
4799 build_x_conditional_expr (ifexp
, op1
, op2
)
4800 tree ifexp
, op1
, op2
;
4802 tree rval
= NULL_TREE
;
4804 if (processing_template_decl
)
4805 return build_min_nt (COND_EXPR
, ifexp
, op1
, op2
);
4807 if (flag_ansi_overloading
)
4808 return build_new_op (COND_EXPR
, LOOKUP_NORMAL
, ifexp
, op1
, op2
);
4810 /* See comments in `build_x_binary_op'. */
4812 rval
= build_opfncall (COND_EXPR
, LOOKUP_SPECULATIVELY
, ifexp
, op1
, op2
);
4814 return build_opfncall (COND_EXPR
, LOOKUP_NORMAL
, ifexp
, op1
, op2
);
4816 return build_conditional_expr (ifexp
, op1
, op2
);
4820 build_conditional_expr (ifexp
, op1
, op2
)
4821 tree ifexp
, op1
, op2
;
4823 register tree type1
;
4824 register tree type2
;
4825 register enum tree_code code1
;
4826 register enum tree_code code2
;
4827 register tree result_type
= NULL_TREE
;
4829 /* If second operand is omitted, it is the same as the first one;
4830 make sure it is calculated only once. */
4834 pedwarn ("ANSI C++ forbids omitting the middle term of a ?: expression");
4835 ifexp
= op1
= save_expr (ifexp
);
4838 ifexp
= cp_convert (boolean_type_node
, ifexp
);
4840 if (TREE_CODE (ifexp
) == ERROR_MARK
)
4841 return error_mark_node
;
4843 op1
= require_instantiated_type (TREE_TYPE (op2
), op1
, error_mark_node
);
4844 if (op1
== error_mark_node
)
4845 return error_mark_node
;
4846 op2
= require_instantiated_type (TREE_TYPE (op1
), op2
, error_mark_node
);
4847 if (op2
== error_mark_node
)
4848 return error_mark_node
;
4850 /* C++: REFERENCE_TYPES must be dereferenced. */
4851 type1
= TREE_TYPE (op1
);
4852 code1
= TREE_CODE (type1
);
4853 type2
= TREE_TYPE (op2
);
4854 code2
= TREE_CODE (type2
);
4856 if (code1
== REFERENCE_TYPE
)
4858 op1
= convert_from_reference (op1
);
4859 type1
= TREE_TYPE (op1
);
4860 code1
= TREE_CODE (type1
);
4862 if (code2
== REFERENCE_TYPE
)
4864 op2
= convert_from_reference (op2
);
4865 type2
= TREE_TYPE (op2
);
4866 code2
= TREE_CODE (type2
);
4869 /* Don't promote the operands separately if they promote
4870 the same way. Return the unpromoted type and let the combined
4871 value get promoted if necessary. */
4873 if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
)
4874 && code2
!= ARRAY_TYPE
4875 && code2
!= FUNCTION_TYPE
4876 && code2
!= METHOD_TYPE
)
4880 if (TREE_CONSTANT (ifexp
)
4881 && (TREE_CODE (ifexp
) == INTEGER_CST
4882 || TREE_CODE (ifexp
) == ADDR_EXPR
))
4883 return (integer_zerop (ifexp
) ? op2
: op1
);
4885 if (TREE_CODE (op1
) == CONST_DECL
)
4886 op1
= DECL_INITIAL (op1
);
4887 else if (TREE_READONLY_DECL_P (op1
))
4888 op1
= decl_constant_value (op1
);
4889 if (TREE_CODE (op2
) == CONST_DECL
)
4890 op2
= DECL_INITIAL (op2
);
4891 else if (TREE_READONLY_DECL_P (op2
))
4892 op2
= decl_constant_value (op2
);
4894 type1
= cp_build_type_variant
4896 TREE_READONLY (op1
) || TREE_READONLY (op2
),
4897 TREE_THIS_VOLATILE (op1
) || TREE_THIS_VOLATILE (op2
));
4898 /* ??? This is a kludge to deal with the fact that
4899 we don't sort out integers and enums properly, yet. */
4900 result
= fold (build (COND_EXPR
, type1
, ifexp
, op1
, op2
));
4901 if (TREE_TYPE (result
) != type1
)
4902 result
= build1 (NOP_EXPR
, type1
, result
);
4903 /* Expand both sides into the same slot,
4904 hopefully the target of the ?: expression. */
4905 if (TREE_CODE (op1
) == TARGET_EXPR
&& TREE_CODE (op2
) == TARGET_EXPR
)
4907 tree slot
= build (VAR_DECL
, TREE_TYPE (result
));
4908 layout_decl (slot
, 0);
4909 result
= build (TARGET_EXPR
, TREE_TYPE (result
),
4910 slot
, result
, NULL_TREE
, NULL_TREE
);
4915 /* They don't match; promote them both and then try to reconcile them.
4916 But don't permit mismatching enum types. */
4917 if (code1
== ENUMERAL_TYPE
)
4919 if (code2
== ENUMERAL_TYPE
)
4921 cp_error ("enumeral mismatch in conditional expression: `%T' vs `%T'", type1
, type2
);
4922 return error_mark_node
;
4924 else if (extra_warnings
&& ! IS_AGGR_TYPE_CODE (code2
)
4925 && type2
!= type_promotes_to (type1
))
4926 warning ("enumeral and non-enumeral type in conditional expression");
4928 else if (extra_warnings
4929 && code2
== ENUMERAL_TYPE
&& ! IS_AGGR_TYPE_CODE (code1
)
4930 && type1
!= type_promotes_to (type2
))
4931 warning ("enumeral and non-enumeral type in conditional expression");
4933 if (code1
!= VOID_TYPE
)
4935 op1
= default_conversion (op1
);
4936 type1
= TREE_TYPE (op1
);
4937 if (TYPE_PTRMEMFUNC_P (type1
))
4938 type1
= TYPE_PTRMEMFUNC_FN_TYPE (type1
);
4939 code1
= TREE_CODE (type1
);
4941 if (code2
!= VOID_TYPE
)
4943 op2
= default_conversion (op2
);
4944 type2
= TREE_TYPE (op2
);
4945 if (TYPE_PTRMEMFUNC_P (type2
))
4946 type2
= TYPE_PTRMEMFUNC_FN_TYPE (type2
);
4947 code2
= TREE_CODE (type2
);
4950 if (code1
== RECORD_TYPE
&& code2
== RECORD_TYPE
4951 && real_lvalue_p (op1
) && real_lvalue_p (op2
)
4952 && comptypes (type1
, type2
, -1))
4954 type1
= build_reference_type (type1
);
4955 type2
= build_reference_type (type2
);
4956 result_type
= common_type (type1
, type2
);
4957 op1
= convert_to_reference (result_type
, op1
, CONV_IMPLICIT
,
4958 LOOKUP_NORMAL
, NULL_TREE
);
4959 op2
= convert_to_reference (result_type
, op2
, CONV_IMPLICIT
,
4960 LOOKUP_NORMAL
, NULL_TREE
);
4962 /* Quickly detect the usual case where op1 and op2 have the same type
4964 else if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
))
4967 result_type
= type1
;
4969 result_type
= cp_build_type_variant
4971 TREE_READONLY (op1
) || TREE_READONLY (op2
),
4972 TREE_THIS_VOLATILE (op1
) || TREE_THIS_VOLATILE (op2
));
4974 else if ((code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
)
4975 && (code2
== INTEGER_TYPE
|| code2
== REAL_TYPE
))
4977 result_type
= common_type (type1
, type2
);
4979 else if (code1
== VOID_TYPE
|| code2
== VOID_TYPE
)
4981 if (pedantic
&& (code1
!= VOID_TYPE
|| code2
!= VOID_TYPE
))
4982 pedwarn ("ANSI C++ forbids conditional expr with only one void side");
4983 result_type
= void_type_node
;
4985 else if (code1
== POINTER_TYPE
&& null_ptr_cst_p (op2
))
4986 result_type
= qualify_type (type1
, type2
);
4987 else if (code2
== POINTER_TYPE
&& null_ptr_cst_p (op1
))
4988 result_type
= qualify_type (type2
, type1
);
4989 else if (code1
== POINTER_TYPE
&& code2
== POINTER_TYPE
)
4991 if (comp_target_types (type1
, type2
, 1))
4992 result_type
= common_type (type1
, type2
);
4993 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1
)) == void_type_node
)
4995 if (pedantic
&& TREE_CODE (type2
) == FUNCTION_TYPE
)
4996 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
4997 result_type
= qualify_type (type1
, type2
);
4999 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2
)) == void_type_node
)
5001 if (pedantic
&& TREE_CODE (type1
) == FUNCTION_TYPE
)
5002 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
5003 result_type
= qualify_type (type2
, type1
);
5006 else if (comptypes (type2
, type1
, 0))
5007 result_type
= type2
;
5008 else if (IS_AGGR_TYPE (TREE_TYPE (type1
))
5009 && IS_AGGR_TYPE (TREE_TYPE (type2
))
5010 && (result_type
= common_base_type (TREE_TYPE (type1
), TREE_TYPE (type2
))))
5012 if (result_type
== error_mark_node
)
5014 cp_error ("common base type of types `%T' and `%T' is ambiguous",
5015 TREE_TYPE (type1
), TREE_TYPE (type2
));
5016 result_type
= ptr_type_node
;
5021 && result_type
!= TREE_TYPE (type1
)
5022 && result_type
!= TREE_TYPE (type2
))
5023 cp_pedwarn ("`%T' and `%T' converted to `%T *' in conditional expression",
5024 type1
, type2
, result_type
);
5026 result_type
= build_pointer_type (result_type
);
5031 pedwarn ("pointer type mismatch in conditional expression");
5032 result_type
= ptr_type_node
;
5035 else if (code1
== POINTER_TYPE
&& code2
== INTEGER_TYPE
)
5037 pedwarn ("pointer/integer type mismatch in conditional expression");
5038 result_type
= type1
;
5040 else if (code2
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
5042 pedwarn ("pointer/integer type mismatch in conditional expression");
5043 result_type
= type2
;
5048 /* The match does not look good. If either is
5049 an aggregate value, try converting to a scalar type. */
5050 if (code1
== RECORD_TYPE
&& code2
== RECORD_TYPE
)
5052 cp_error ("aggregate mismatch in conditional expression: `%T' vs `%T'", type1
, type2
);
5053 return error_mark_node
;
5055 /* Warning: this code assumes that conversion between cv-variants of
5056 a type is done using NOP_EXPRs. */
5057 if (code1
== RECORD_TYPE
&& TYPE_HAS_CONVERSION (type1
))
5059 /* There are other types besides pointers and records. */
5061 if (code2
== POINTER_TYPE
)
5062 tmp
= build_pointer_type
5063 (build_type_variant (TREE_TYPE (type2
), 1, 1));
5066 tmp
= build_type_conversion (CONVERT_EXPR
, tmp
, op1
, 0);
5067 if (tmp
== NULL_TREE
)
5069 cp_error ("incompatible types `%T' and `%T' in `?:'",
5071 return error_mark_node
;
5073 if (tmp
== error_mark_node
)
5074 error ("ambiguous pointer conversion");
5077 result_type
= common_type (type2
, TREE_TYPE (tmp
));
5080 else if (code2
== RECORD_TYPE
&& TYPE_HAS_CONVERSION (type2
))
5083 if (code1
== POINTER_TYPE
)
5084 tmp
= build_pointer_type
5085 (build_type_variant (TREE_TYPE (type1
), 1, 1));
5089 tmp
= build_type_conversion (CONVERT_EXPR
, tmp
, op2
, 0);
5090 if (tmp
== NULL_TREE
)
5092 cp_error ("incompatible types `%T' and `%T' in `?:'",
5094 return error_mark_node
;
5096 if (tmp
== error_mark_node
)
5097 error ("ambiguous pointer conversion");
5100 result_type
= common_type (type1
, TREE_TYPE (tmp
));
5103 else if (flag_cond_mismatch
)
5104 result_type
= void_type_node
;
5107 error ("type mismatch in conditional expression");
5108 return error_mark_node
;
5112 if (TREE_CODE (result_type
) == POINTER_TYPE
5113 && TREE_CODE (TREE_TYPE (result_type
)) == METHOD_TYPE
)
5114 result_type
= build_ptrmemfunc_type (result_type
);
5116 if (result_type
!= TREE_TYPE (op1
))
5117 op1
= convert_for_initialization
5118 (NULL_TREE
, result_type
, op1
, LOOKUP_NORMAL
, "converting", NULL_TREE
, 0);
5119 if (result_type
!= TREE_TYPE (op2
))
5120 op2
= convert_for_initialization
5121 (NULL_TREE
, result_type
, op2
, LOOKUP_NORMAL
, "converting", NULL_TREE
, 0);
5123 if (TREE_CONSTANT (ifexp
))
5124 return integer_zerop (ifexp
) ? op2
: op1
;
5126 return convert_from_reference
5127 (fold (build (COND_EXPR
, result_type
, ifexp
, op1
, op2
)));
5130 /* Handle overloading of the ',' operator when needed. Otherwise,
5131 this function just builds an expression list. */
5134 build_x_compound_expr (list
)
5137 tree rest
= TREE_CHAIN (list
);
5140 if (processing_template_decl
)
5141 return build_min_nt (COMPOUND_EXPR
, list
, NULL_TREE
);
5143 if (rest
== NULL_TREE
)
5144 return build_compound_expr (list
);
5146 result
= build_opfncall (COMPOUND_EXPR
, LOOKUP_NORMAL
,
5147 TREE_VALUE (list
), TREE_VALUE (rest
), NULL_TREE
);
5149 return build_x_compound_expr (tree_cons (NULL_TREE
, result
, TREE_CHAIN (rest
)));
5151 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list
)))
5153 /* the left-hand operand of a comma expression is like an expression
5154 statement: we should warn if it doesn't have any side-effects,
5155 unless it was explicitly cast to (void). */
5156 if ((extra_warnings
|| warn_unused
)
5157 && !(TREE_CODE (TREE_VALUE(list
)) == CONVERT_EXPR
5158 && TREE_TYPE (TREE_VALUE(list
)) == void_type_node
))
5159 warning("left-hand operand of comma expression has no effect");
5161 #if 0 /* this requires a gcc backend patch to export warn_if_unused_value */
5162 else if (warn_unused
)
5163 warn_if_unused_value (TREE_VALUE(list
));
5166 return build_compound_expr (tree_cons (NULL_TREE
, TREE_VALUE (list
),
5167 build_tree_list (NULL_TREE
, build_x_compound_expr (rest
))));
5170 /* Given a list of expressions, return a compound expression
5171 that performs them all and returns the value of the last of them. */
5174 build_compound_expr (list
)
5179 if (TREE_READONLY_DECL_P (TREE_VALUE (list
)))
5180 TREE_VALUE (list
) = decl_constant_value (TREE_VALUE (list
));
5182 if (TREE_CHAIN (list
) == 0)
5184 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5185 Strip such NOP_EXPRs, since LIST is used in non-lvalue context. */
5186 if (TREE_CODE (list
) == NOP_EXPR
5187 && TREE_TYPE (list
) == TREE_TYPE (TREE_OPERAND (list
, 0)))
5188 list
= TREE_OPERAND (list
, 0);
5190 /* Convert arrays to pointers. */
5191 if (TREE_CODE (TREE_TYPE (TREE_VALUE (list
))) == ARRAY_TYPE
)
5192 return default_conversion (TREE_VALUE (list
));
5194 return TREE_VALUE (list
);
5197 rest
= build_compound_expr (TREE_CHAIN (list
));
5199 /* When pedantic, a compound expression cannot be a constant expression. */
5200 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list
)) && ! pedantic
)
5203 return build (COMPOUND_EXPR
, TREE_TYPE (rest
),
5204 break_out_cleanups (TREE_VALUE (list
)), rest
);
5208 build_static_cast (type
, expr
)
5214 if (type
== error_mark_node
|| expr
== error_mark_node
)
5215 return error_mark_node
;
5217 if (TREE_CODE (expr
) == OFFSET_REF
)
5218 expr
= resolve_offset_ref (expr
);
5220 if (processing_template_decl
)
5222 tree t
= build_min (STATIC_CAST_EXPR
, type
, expr
);
5226 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5227 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5228 if (TREE_CODE (type
) != REFERENCE_TYPE
5229 && TREE_CODE (expr
) == NOP_EXPR
5230 && TREE_TYPE (expr
) == TREE_TYPE (TREE_OPERAND (expr
, 0)))
5231 expr
= TREE_OPERAND (expr
, 0);
5233 if (TREE_CODE (type
) == VOID_TYPE
)
5234 return build1 (CONVERT_EXPR
, type
, expr
);
5236 if (type_unknown_p (expr
))
5238 expr
= instantiate_type (type
, expr
, 1);
5239 if (expr
== error_mark_node
)
5240 return error_mark_node
;
5243 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5244 return (convert_from_reference
5245 (convert_to_reference (type
, expr
, CONV_STATIC
|CONV_IMPLICIT
,
5246 LOOKUP_COMPLAIN
, NULL_TREE
)));
5248 if (IS_AGGR_TYPE (type
))
5249 return build_cplus_new
5250 (type
, (build_method_call
5251 (NULL_TREE
, ctor_identifier
, build_tree_list (NULL_TREE
, expr
),
5252 TYPE_BINFO (type
), LOOKUP_NORMAL
)));
5254 expr
= decay_conversion (expr
);
5255 intype
= TREE_TYPE (expr
);
5257 /* FIXME handle casting to array type. */
5260 if (can_convert_arg (type
, intype
, expr
))
5262 else if (TYPE_PTROB_P (type
) && TYPE_PTROB_P (intype
))
5265 if (IS_AGGR_TYPE (TREE_TYPE (type
)) && IS_AGGR_TYPE (TREE_TYPE (intype
))
5266 && (TYPE_READONLY (TREE_TYPE (type
))
5267 >= TYPE_READONLY (TREE_TYPE (intype
)))
5268 && (TYPE_VOLATILE (TREE_TYPE (type
))
5269 >= TYPE_VOLATILE (TREE_TYPE (intype
)))
5270 && (binfo
= get_binfo (TREE_TYPE (intype
), TREE_TYPE (type
), 0))
5271 && ! TREE_VIA_VIRTUAL (binfo
))
5274 else if (TYPE_PTRMEM_P (type
) && TYPE_PTRMEM_P (intype
))
5276 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
))),
5277 TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (intype
))), 1)
5278 && (TYPE_READONLY (TREE_TYPE (TREE_TYPE (type
)))
5279 >= TYPE_READONLY (TREE_TYPE (TREE_TYPE (intype
))))
5280 && (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (type
)))
5281 >= TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (intype
))))
5282 && (binfo
= get_binfo (TYPE_OFFSET_BASETYPE (intype
),
5283 TYPE_OFFSET_BASETYPE (type
), 0))
5284 && ! TREE_VIA_VIRTUAL (binfo
))
5287 else if (TREE_CODE (intype
) != BOOLEAN_TYPE
5288 && TREE_CODE (type
) != ARRAY_TYPE
5289 && TREE_CODE (type
) != FUNCTION_TYPE
5290 && can_convert (intype
, type
))
5294 return build_c_cast (type
, expr
);
5296 cp_error ("static_cast from `%T' to `%T'", intype
, type
);
5297 return error_mark_node
;
5301 build_reinterpret_cast (type
, expr
)
5306 if (type
== error_mark_node
|| expr
== error_mark_node
)
5307 return error_mark_node
;
5309 if (TREE_CODE (expr
) == OFFSET_REF
)
5310 expr
= resolve_offset_ref (expr
);
5312 if (processing_template_decl
)
5314 tree t
= build_min (REINTERPRET_CAST_EXPR
, type
, expr
);
5318 if (TREE_CODE (type
) != REFERENCE_TYPE
)
5320 expr
= decay_conversion (expr
);
5322 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5323 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5324 if (TREE_CODE (expr
) == NOP_EXPR
5325 && TREE_TYPE (expr
) == TREE_TYPE (TREE_OPERAND (expr
, 0)))
5326 expr
= TREE_OPERAND (expr
, 0);
5329 if (type_unknown_p (expr
))
5331 expr
= instantiate_type (type
, expr
, 1);
5332 if (expr
== error_mark_node
)
5333 return error_mark_node
;
5336 intype
= TREE_TYPE (expr
);
5338 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5340 if (! real_lvalue_p (expr
))
5342 cp_error ("reinterpret_cast from `%T' rvalue to `%T'", intype
, type
);
5343 return error_mark_node
;
5345 expr
= build_unary_op (ADDR_EXPR
, expr
, 0);
5346 if (expr
!= error_mark_node
)
5347 expr
= build_reinterpret_cast
5348 (build_pointer_type (TREE_TYPE (type
)), expr
);
5349 if (expr
!= error_mark_node
)
5350 expr
= build_indirect_ref (expr
, 0);
5353 else if (comptypes (TYPE_MAIN_VARIANT (intype
), TYPE_MAIN_VARIANT (type
), 1))
5354 return build_static_cast (type
, expr
);
5356 if (TYPE_PTR_P (type
) && (TREE_CODE (intype
) == INTEGER_TYPE
5357 || TREE_CODE (intype
) == ENUMERAL_TYPE
))
5359 else if (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_PTR_P (intype
))
5361 if (TYPE_PRECISION (type
) < TYPE_PRECISION (intype
))
5362 cp_pedwarn ("reinterpret_cast from `%T' to `%T' loses precision",
5365 else if ((TYPE_PTRFN_P (type
) && TYPE_PTRFN_P (intype
))
5366 || (TYPE_PTRMEMFUNC_P (type
) && TYPE_PTRMEMFUNC_P (intype
)))
5368 if (TREE_READONLY_DECL_P (expr
))
5369 expr
= decl_constant_value (expr
);
5370 return fold (build1 (NOP_EXPR
, type
, expr
));
5372 else if ((TYPE_PTRMEM_P (type
) && TYPE_PTRMEM_P (intype
))
5373 || (TYPE_PTROBV_P (type
) && TYPE_PTROBV_P (intype
)))
5375 if (! comp_ptr_ttypes_reinterpret (TREE_TYPE (type
), TREE_TYPE (intype
)))
5376 cp_pedwarn ("reinterpret_cast from `%T' to `%T' casts away const (or volatile)",
5379 if (TREE_READONLY_DECL_P (expr
))
5380 expr
= decl_constant_value (expr
);
5381 return fold (build1 (NOP_EXPR
, type
, expr
));
5383 else if ((TYPE_PTRFN_P (type
) && TYPE_PTROBV_P (intype
))
5384 || (TYPE_PTRFN_P (type
) && TYPE_PTROBV_P (intype
)))
5386 pedwarn ("ANSI C++ forbids casting between pointers to functions and objects");
5387 if (TREE_READONLY_DECL_P (expr
))
5388 expr
= decl_constant_value (expr
);
5389 return fold (build1 (NOP_EXPR
, type
, expr
));
5393 cp_error ("reinterpret_cast from `%T' to `%T'", intype
, type
);
5394 return error_mark_node
;
5397 return cp_convert (type
, expr
);
5401 build_const_cast (type
, expr
)
5406 if (type
== error_mark_node
|| expr
== error_mark_node
)
5407 return error_mark_node
;
5409 if (TREE_CODE (expr
) == OFFSET_REF
)
5410 expr
= resolve_offset_ref (expr
);
5412 if (processing_template_decl
)
5414 tree t
= build_min (CONST_CAST_EXPR
, type
, expr
);
5418 if (TREE_CODE (type
) != REFERENCE_TYPE
)
5420 expr
= decay_conversion (expr
);
5422 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5423 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5424 if (TREE_CODE (expr
) == NOP_EXPR
5425 && TREE_TYPE (expr
) == TREE_TYPE (TREE_OPERAND (expr
, 0)))
5426 expr
= TREE_OPERAND (expr
, 0);
5429 if (type_unknown_p (expr
))
5431 expr
= instantiate_type (type
, expr
, 1);
5432 if (expr
== error_mark_node
)
5433 return error_mark_node
;
5436 intype
= TREE_TYPE (expr
);
5438 if (comptypes (TYPE_MAIN_VARIANT (intype
), TYPE_MAIN_VARIANT (type
), 1))
5439 return build_static_cast (type
, expr
);
5440 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
5442 if (! real_lvalue_p (expr
))
5444 cp_error ("const_cast from `%T' rvalue to `%T'", intype
, type
);
5445 return error_mark_node
;
5448 if (comp_ptr_ttypes_const (TREE_TYPE (type
), intype
))
5449 return (convert_from_reference
5450 (convert_to_reference (type
, expr
, CONV_CONST
|CONV_IMPLICIT
,
5451 LOOKUP_COMPLAIN
, NULL_TREE
)));
5453 else if (TREE_CODE (type
) == POINTER_TYPE
5454 && TREE_CODE (intype
) == POINTER_TYPE
5455 && comp_ptr_ttypes_const (TREE_TYPE (type
), TREE_TYPE (intype
)))
5456 return cp_convert (type
, expr
);
5458 cp_error ("const_cast from `%T' to `%T'", intype
, type
);
5459 return error_mark_node
;
5462 /* Build an expression representing a cast to type TYPE of expression EXPR.
5464 ALLOW_NONCONVERTING is true if we should allow non-converting constructors
5465 when doing the cast. */
5468 build_c_cast (type
, expr
)
5471 register tree value
= expr
;
5473 if (type
== error_mark_node
|| expr
== error_mark_node
)
5474 return error_mark_node
;
5476 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5477 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5478 if (TREE_CODE (type
) != REFERENCE_TYPE
5479 && TREE_CODE (value
) == NOP_EXPR
5480 && TREE_TYPE (value
) == TREE_TYPE (TREE_OPERAND (value
, 0)))
5481 value
= TREE_OPERAND (value
, 0);
5483 if (TREE_TYPE (expr
)
5484 && TREE_CODE (TREE_TYPE (expr
)) == OFFSET_TYPE
5485 && TREE_CODE (type
) != OFFSET_TYPE
)
5486 value
= resolve_offset_ref (value
);
5488 if (TREE_CODE (type
) == ARRAY_TYPE
)
5490 /* Allow casting from T1* to T2[] because Cfront allows it.
5491 NIHCL uses it. It is not valid ANSI C however, and hence, not
5493 if (TREE_CODE (TREE_TYPE (expr
)) == POINTER_TYPE
)
5496 pedwarn ("ANSI C++ forbids casting to an array type");
5497 type
= build_pointer_type (TREE_TYPE (type
));
5501 error ("ANSI C++ forbids casting to an array type");
5502 return error_mark_node
;
5506 if (TREE_CODE (type
) == FUNCTION_TYPE
5507 || TREE_CODE (type
) == METHOD_TYPE
)
5509 cp_error ("casting to function type `%T'", type
);
5510 return error_mark_node
;
5513 if (IS_SIGNATURE (type
))
5515 error ("cast specifies signature type");
5516 return error_mark_node
;
5519 if (processing_template_decl
)
5521 tree t
= build_min (CAST_EXPR
, type
,
5522 min_tree_cons (NULL_TREE
, value
, NULL_TREE
));
5526 if (TREE_CODE (type
) == VOID_TYPE
)
5527 value
= build1 (CONVERT_EXPR
, type
, value
);
5528 else if (TREE_TYPE (value
) == NULL_TREE
5529 || type_unknown_p (value
))
5531 value
= instantiate_type (type
, value
, 1);
5533 if (value
== error_mark_node
)
5534 return error_mark_node
;
5540 /* Convert functions and arrays to pointers and
5541 convert references to their expanded types,
5542 but don't convert any other types. */
5543 if (TREE_CODE (TREE_TYPE (value
)) == FUNCTION_TYPE
5544 || (TREE_CODE (TREE_TYPE (value
)) == METHOD_TYPE
5545 /* Don't do the default conversion if we want a
5546 pointer to a function. */
5547 && ! (TREE_CODE (type
) == POINTER_TYPE
5548 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
))
5549 || TREE_CODE (TREE_TYPE (value
)) == ARRAY_TYPE
5550 || TREE_CODE (TREE_TYPE (value
)) == REFERENCE_TYPE
)
5551 value
= default_conversion (value
);
5552 otype
= TREE_TYPE (value
);
5554 /* Optionally warn about potentially worrisome casts. */
5557 && TREE_CODE (type
) == POINTER_TYPE
5558 && TREE_CODE (otype
) == POINTER_TYPE
)
5560 /* For C++ we make these regular warnings, rather than
5561 softening them into pedwarns. */
5562 if (TYPE_VOLATILE (TREE_TYPE (otype
))
5563 && ! TYPE_VOLATILE (TREE_TYPE (type
)))
5564 warning ("cast discards `volatile' from pointer target type");
5565 if (TYPE_READONLY (TREE_TYPE (otype
))
5566 && ! TYPE_READONLY (TREE_TYPE (type
)))
5567 warning ("cast discards `const' from pointer target type");
5570 /* Warn about possible alignment problems. */
5571 if (STRICT_ALIGNMENT
&& warn_cast_align
5572 && TREE_CODE (type
) == POINTER_TYPE
5573 && TREE_CODE (otype
) == POINTER_TYPE
5574 && TREE_CODE (TREE_TYPE (otype
)) != VOID_TYPE
5575 && TREE_CODE (TREE_TYPE (otype
)) != FUNCTION_TYPE
5576 && TYPE_ALIGN (TREE_TYPE (type
)) > TYPE_ALIGN (TREE_TYPE (otype
)))
5577 warning ("cast increases required alignment of target type");
5580 /* We should see about re-enabling these, they seem useful to
5582 if (TREE_CODE (type
) == INTEGER_TYPE
5583 && TREE_CODE (otype
) == POINTER_TYPE
5584 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
))
5585 warning ("cast from pointer to integer of different size");
5587 if (TREE_CODE (type
) == POINTER_TYPE
5588 && TREE_CODE (otype
) == INTEGER_TYPE
5589 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
)
5590 /* Don't warn about converting 0 to pointer,
5591 provided the 0 was explicit--not cast or made by folding. */
5592 && !(TREE_CODE (value
) == INTEGER_CST
&& integer_zerop (value
)))
5593 warning ("cast to pointer from integer of different size");
5596 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5597 value
= (convert_from_reference
5598 (convert_to_reference (type
, value
, CONV_C_CAST
,
5599 LOOKUP_COMPLAIN
, NULL_TREE
)));
5604 if (TREE_READONLY_DECL_P (value
))
5605 value
= decl_constant_value (value
);
5608 value
= convert_force (type
, value
, CONV_C_CAST
);
5610 /* Ignore any integer overflow caused by the cast. */
5611 if (TREE_CODE (value
) == INTEGER_CST
)
5613 TREE_OVERFLOW (value
) = TREE_OVERFLOW (ovalue
);
5614 TREE_CONSTANT_OVERFLOW (value
) = TREE_CONSTANT_OVERFLOW (ovalue
);
5619 /* Always produce some operator for an explicit cast,
5620 so we can tell (for -pedantic) that the cast is no lvalue. */
5621 if (TREE_CODE (type
) != REFERENCE_TYPE
&& value
== expr
5622 && real_lvalue_p (value
))
5623 value
= non_lvalue (value
);
5629 expand_target_expr (t
)
5632 extern int temp_slot_level
;
5633 extern int target_temp_slot_level
;
5634 int old_temp_level
= target_temp_slot_level
;
5636 tree xval
= make_node (RTL_EXPR
);
5639 /* Any TARGET_EXPR temps live only as long as the outer temp level.
5640 Since they are preserved in this new inner level, we know they
5641 will make it into the outer level. */
5643 target_temp_slot_level
= temp_slot_level
;
5645 do_pending_stack_adjust ();
5646 start_sequence_for_rtl_expr (xval
);
5648 rtxval
= expand_expr (t
, NULL_RTX
, VOIDmode
, EXPAND_NORMAL
);
5649 do_pending_stack_adjust ();
5650 TREE_SIDE_EFFECTS (xval
) = 1;
5651 RTL_EXPR_SEQUENCE (xval
) = get_insns ();
5653 RTL_EXPR_RTL (xval
) = rtxval
;
5654 TREE_TYPE (xval
) = TREE_TYPE (t
);
5657 target_temp_slot_level
= old_temp_level
;
5662 /* Build an assignment expression of lvalue LHS from value RHS.
5663 MODIFYCODE is the code for a binary operator that we use
5664 to combine the old value of LHS with RHS to get the new value.
5665 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
5667 C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed. */
5670 build_modify_expr (lhs
, modifycode
, rhs
)
5672 enum tree_code modifycode
;
5675 register tree result
;
5677 tree lhstype
= TREE_TYPE (lhs
);
5678 tree olhstype
= lhstype
;
5681 /* Avoid duplicate error messages from operands that had errors. */
5682 if (lhs
== error_mark_node
|| rhs
== error_mark_node
)
5683 return error_mark_node
;
5685 /* Types that aren't fully specified cannot be used in assignments. */
5686 lhs
= require_complete_type (lhs
);
5690 /* Handle assignment to signature pointers/refs. */
5692 if (TYPE_LANG_SPECIFIC (lhstype
)
5693 && (IS_SIGNATURE_POINTER (lhstype
) || IS_SIGNATURE_REFERENCE (lhstype
)))
5695 return build_signature_pointer_constructor (lhs
, rhs
);
5698 /* Handle control structure constructs used as "lvalues". */
5700 switch (TREE_CODE (lhs
))
5702 /* Handle --foo = 5; as these are valid constructs in C++ */
5703 case PREDECREMENT_EXPR
:
5704 case PREINCREMENT_EXPR
:
5705 if (TREE_SIDE_EFFECTS (TREE_OPERAND (lhs
, 0)))
5706 lhs
= build (TREE_CODE (lhs
), TREE_TYPE (lhs
),
5707 stabilize_reference (TREE_OPERAND (lhs
, 0)),
5708 TREE_OPERAND (lhs
, 1));
5709 return build (COMPOUND_EXPR
, lhstype
,
5711 build_modify_expr (TREE_OPERAND (lhs
, 0),
5714 /* Handle (a, b) used as an "lvalue". */
5716 newrhs
= build_modify_expr (TREE_OPERAND (lhs
, 1),
5718 if (newrhs
== error_mark_node
)
5719 return error_mark_node
;
5720 return build (COMPOUND_EXPR
, lhstype
,
5721 TREE_OPERAND (lhs
, 0), newrhs
);
5724 newrhs
= build_modify_expr (TREE_OPERAND (lhs
, 0), modifycode
, rhs
);
5725 if (newrhs
== error_mark_node
)
5726 return error_mark_node
;
5727 return build (COMPOUND_EXPR
, lhstype
, lhs
, newrhs
);
5729 /* Handle (a ? b : c) used as an "lvalue". */
5731 rhs
= save_expr (rhs
);
5733 /* Produce (a ? (b = rhs) : (c = rhs))
5734 except that the RHS goes through a save-expr
5735 so the code to compute it is only emitted once. */
5737 = build_conditional_expr (TREE_OPERAND (lhs
, 0),
5738 build_modify_expr (cp_convert (TREE_TYPE (lhs
), TREE_OPERAND (lhs
, 1)),
5740 build_modify_expr (cp_convert (TREE_TYPE (lhs
), TREE_OPERAND (lhs
, 2)),
5742 if (cond
== error_mark_node
)
5744 /* Make sure the code to compute the rhs comes out
5745 before the split. */
5746 return build (COMPOUND_EXPR
, TREE_TYPE (lhs
),
5747 /* Case to void to suppress warning
5748 from warn_if_unused_value. */
5749 cp_convert (void_type_node
, rhs
), cond
);
5753 if (TREE_CODE (lhs
) == OFFSET_REF
)
5755 if (TREE_OPERAND (lhs
, 0) == NULL_TREE
)
5757 /* Static class member? */
5758 tree member
= TREE_OPERAND (lhs
, 1);
5759 if (TREE_CODE (member
) == VAR_DECL
)
5763 compiler_error ("invalid static class member");
5764 return error_mark_node
;
5768 lhs
= resolve_offset_ref (lhs
);
5770 olhstype
= lhstype
= TREE_TYPE (lhs
);
5773 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
5774 && modifycode
!= INIT_EXPR
)
5776 lhs
= convert_from_reference (lhs
);
5777 olhstype
= lhstype
= TREE_TYPE (lhs
);
5780 /* If a binary op has been requested, combine the old LHS value with the RHS
5781 producing the value we should actually store into the LHS. */
5783 if (modifycode
== INIT_EXPR
)
5785 if (! IS_AGGR_TYPE (lhstype
))
5786 /* Do the default thing */;
5787 else if (! TYPE_HAS_CONSTRUCTOR (lhstype
))
5789 cp_error ("`%T' has no constructors", lhstype
);
5790 return error_mark_node
;
5792 else if (TYPE_HAS_TRIVIAL_INIT_REF (lhstype
)
5793 && TYPE_MAIN_VARIANT (lhstype
) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs
)))
5794 /* Do the default thing */;
5797 result
= build_method_call (lhs
, ctor_identifier
,
5798 build_tree_list (NULL_TREE
, rhs
),
5799 TYPE_BINFO (lhstype
), LOOKUP_NORMAL
);
5800 if (result
== NULL_TREE
)
5801 return error_mark_node
;
5805 else if (modifycode
== NOP_EXPR
)
5807 /* `operator=' is not an inheritable operator. */
5808 if (! IS_AGGR_TYPE (lhstype
))
5809 /* Do the default thing */;
5810 else if (! TYPE_HAS_ASSIGNMENT (lhstype
))
5812 cp_error ("`%T' does not define operator=", lhstype
);
5813 return error_mark_node
;
5815 else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (lhstype
)
5816 && TYPE_MAIN_VARIANT (lhstype
) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs
)))
5818 build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
,
5819 lhs
, rhs
, make_node (NOP_EXPR
));
5821 /* Do the default thing */;
5825 result
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
,
5826 lhs
, rhs
, make_node (NOP_EXPR
));
5827 if (result
== NULL_TREE
)
5828 return error_mark_node
;
5833 else if (PROMOTES_TO_AGGR_TYPE (lhstype
, REFERENCE_TYPE
))
5835 /* This case must convert to some sort of lvalue that
5836 can participate in an op= operation. */
5839 if (build_default_binary_type_conversion (modifycode
, &lhs_tmp
, &rhs_tmp
))
5841 lhs
= stabilize_reference (lhs_tmp
);
5842 /* Forget it was ever anything else. */
5843 olhstype
= lhstype
= TREE_TYPE (lhs
);
5844 newrhs
= build_binary_op (modifycode
, lhs
, rhs_tmp
, 1);
5848 cp_error ("no match for `%Q(%#T, %#T)'", modifycode
,
5849 TREE_TYPE (lhs
), TREE_TYPE (rhs
));
5850 return error_mark_node
;
5855 lhs
= stabilize_reference (lhs
);
5856 newrhs
= build_binary_op (modifycode
, lhs
, rhs
, 1);
5857 if (newrhs
== error_mark_node
)
5859 cp_error (" in evaluation of `%Q(%#T, %#T)'", modifycode
,
5860 TREE_TYPE (lhs
), TREE_TYPE (rhs
));
5861 return error_mark_node
;
5865 /* Handle a cast used as an "lvalue".
5866 We have already performed any binary operator using the value as cast.
5867 Now convert the result to the cast type of the lhs,
5868 and then true type of the lhs and store it there;
5869 then convert result back to the cast type to be the value
5870 of the assignment. */
5872 switch (TREE_CODE (lhs
))
5877 case FIX_TRUNC_EXPR
:
5878 case FIX_FLOOR_EXPR
:
5879 case FIX_ROUND_EXPR
:
5881 if (TREE_CODE (TREE_TYPE (newrhs
)) == ARRAY_TYPE
5882 || TREE_CODE (TREE_TYPE (newrhs
)) == FUNCTION_TYPE
5883 || TREE_CODE (TREE_TYPE (newrhs
)) == METHOD_TYPE
5884 || TREE_CODE (TREE_TYPE (newrhs
)) == OFFSET_TYPE
)
5885 newrhs
= default_conversion (newrhs
);
5887 tree inner_lhs
= TREE_OPERAND (lhs
, 0);
5890 /* WP 5.4.1: The result is an lvalue if T is a reference type,
5891 otherwise the result is an rvalue. */
5892 if (! lvalue_p (lhs
))
5893 pedwarn ("ANSI C++ forbids cast to non-reference type used as lvalue");
5895 result
= build_modify_expr (inner_lhs
, NOP_EXPR
,
5896 cp_convert (TREE_TYPE (inner_lhs
),
5897 cp_convert (lhstype
, newrhs
)));
5898 if (result
== error_mark_node
)
5900 return cp_convert (TREE_TYPE (lhs
), result
);
5904 /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
5905 Reject anything strange now. */
5907 if (!lvalue_or_else (lhs
, "assignment"))
5908 return error_mark_node
;
5910 GNU_xref_assign (lhs
);
5912 /* Warn about storing in something that is `const'. */
5913 /* For C++, don't warn if this is initialization. */
5914 if (modifycode
!= INIT_EXPR
5915 /* For assignment to `const' signature pointer/reference fields,
5916 don't warn either, we already printed a better message before. */
5917 && ! (TREE_CODE (lhs
) == COMPONENT_REF
5918 && (IS_SIGNATURE_POINTER (TREE_TYPE (TREE_OPERAND (lhs
, 0)))
5919 || IS_SIGNATURE_REFERENCE (TREE_TYPE (TREE_OPERAND (lhs
, 0)))))
5920 && (TREE_READONLY (lhs
) || TYPE_READONLY (lhstype
)
5921 || ((TREE_CODE (lhstype
) == RECORD_TYPE
5922 || TREE_CODE (lhstype
) == UNION_TYPE
)
5923 && C_TYPE_FIELDS_READONLY (lhstype
))
5924 || (TREE_CODE (lhstype
) == REFERENCE_TYPE
5925 && TYPE_READONLY (TREE_TYPE (lhstype
)))))
5926 readonly_error (lhs
, "assignment", 0);
5928 /* If storing into a structure or union member,
5929 it has probably been given type `int'.
5930 Compute the type that would go with
5931 the actual amount of storage the member occupies. */
5933 if (TREE_CODE (lhs
) == COMPONENT_REF
5934 && (TREE_CODE (lhstype
) == INTEGER_TYPE
5935 || TREE_CODE (lhstype
) == REAL_TYPE
5936 || TREE_CODE (lhstype
) == ENUMERAL_TYPE
))
5938 lhstype
= TREE_TYPE (get_unwidened (lhs
, 0));
5940 /* If storing in a field that is in actuality a short or narrower
5941 than one, we must store in the field in its actual type. */
5943 if (lhstype
!= TREE_TYPE (lhs
))
5945 lhs
= copy_node (lhs
);
5946 TREE_TYPE (lhs
) = lhstype
;
5950 /* check to see if there is an assignment to `this' */
5951 if (lhs
== current_class_ptr
)
5953 if (flag_this_is_variable
> 0
5954 && DECL_NAME (current_function_decl
) != NULL_TREE
5955 && (DECL_NAME (current_function_decl
)
5956 != constructor_name (current_class_type
)))
5957 warning ("assignment to `this' not in constructor or destructor");
5958 current_function_just_assigned_this
= 1;
5961 /* The TREE_TYPE of RHS may be TYPE_UNKNOWN. This can happen
5962 when the type of RHS is not yet known, i.e. its type
5963 is inherited from LHS. */
5964 rhs
= require_instantiated_type (lhstype
, newrhs
, error_mark_node
);
5965 if (rhs
== error_mark_node
)
5966 return error_mark_node
;
5969 if (modifycode
!= INIT_EXPR
)
5971 /* Make modifycode now either a NOP_EXPR or an INIT_EXPR. */
5972 modifycode
= NOP_EXPR
;
5973 /* Reference-bashing */
5974 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
)
5976 tree tmp
= convert_from_reference (lhs
);
5977 lhstype
= TREE_TYPE (tmp
);
5978 if (TYPE_SIZE (lhstype
) == 0)
5980 incomplete_type_error (lhs
, lhstype
);
5981 return error_mark_node
;
5986 if (TREE_CODE (TREE_TYPE (newrhs
)) == REFERENCE_TYPE
)
5988 tree tmp
= convert_from_reference (newrhs
);
5989 if (TYPE_SIZE (TREE_TYPE (tmp
)) == 0)
5991 incomplete_type_error (newrhs
, TREE_TYPE (tmp
));
5992 return error_mark_node
;
5998 if (TREE_SIDE_EFFECTS (lhs
))
5999 lhs
= stabilize_reference (lhs
);
6000 if (TREE_SIDE_EFFECTS (newrhs
))
6001 newrhs
= stabilize_reference (newrhs
);
6003 /* Convert new value to destination type. */
6005 if (TREE_CODE (lhstype
) == ARRAY_TYPE
)
6009 if (! comptypes (lhstype
, TREE_TYPE (rhs
), 0))
6011 cp_error ("incompatible types in assignment of `%T' to `%T'",
6012 TREE_TYPE (rhs
), lhstype
);
6013 return error_mark_node
;
6016 /* Allow array assignment in compiler-generated code. */
6017 if (pedantic
&& ! DECL_ARTIFICIAL (current_function_decl
))
6018 pedwarn ("ANSI C++ forbids assignment of arrays");
6020 /* Have to wrap this in RTL_EXPR for two cases:
6021 in base or member initialization and if we
6022 are a branch of a ?: operator. Since we
6023 can't easily know the latter, just do it always. */
6025 result
= make_node (RTL_EXPR
);
6027 TREE_TYPE (result
) = void_type_node
;
6028 do_pending_stack_adjust ();
6029 start_sequence_for_rtl_expr (result
);
6031 /* As a matter of principle, `start_sequence' should do this. */
6034 from_array
= TREE_CODE (TREE_TYPE (newrhs
)) == ARRAY_TYPE
6035 ? 1 + (modifycode
!= INIT_EXPR
): 0;
6036 expand_vec_init (lhs
, lhs
, array_type_nelts (lhstype
), newrhs
,
6039 do_pending_stack_adjust ();
6041 TREE_SIDE_EFFECTS (result
) = 1;
6042 RTL_EXPR_SEQUENCE (result
) = get_insns ();
6043 RTL_EXPR_RTL (result
) = const0_rtx
;
6048 if (modifycode
== INIT_EXPR
)
6050 newrhs
= convert_for_initialization (lhs
, lhstype
, newrhs
, LOOKUP_NORMAL
,
6051 "assignment", NULL_TREE
, 0);
6052 if (lhs
== DECL_RESULT (current_function_decl
))
6054 if (DECL_INITIAL (lhs
))
6055 warning ("return value from function receives multiple initializations");
6056 DECL_INITIAL (lhs
) = newrhs
;
6061 /* Avoid warnings on enum bit fields. */
6062 if (TREE_CODE (olhstype
) == ENUMERAL_TYPE
6063 && TREE_CODE (lhstype
) == INTEGER_TYPE
)
6065 newrhs
= convert_for_assignment (olhstype
, newrhs
, "assignment",
6067 newrhs
= convert_force (lhstype
, newrhs
, 0);
6070 newrhs
= convert_for_assignment (lhstype
, newrhs
, "assignment",
6072 if (TREE_CODE (newrhs
) == CALL_EXPR
6073 && TYPE_NEEDS_CONSTRUCTING (lhstype
))
6074 newrhs
= build_cplus_new (lhstype
, newrhs
);
6076 /* Can't initialize directly from a TARGET_EXPR, since that would
6077 cause the lhs to be constructed twice, and possibly result in
6078 accidental self-initialization. So we force the TARGET_EXPR to be
6079 expanded without a target. */
6080 if (TREE_CODE (newrhs
) == TARGET_EXPR
)
6081 newrhs
= build (COMPOUND_EXPR
, TREE_TYPE (newrhs
), newrhs
,
6082 TREE_OPERAND (newrhs
, 0));
6085 if (newrhs
== error_mark_node
)
6086 return error_mark_node
;
6088 if (TREE_CODE (newrhs
) == COND_EXPR
)
6091 tree cond
= TREE_OPERAND (newrhs
, 0);
6093 if (TREE_SIDE_EFFECTS (lhs
))
6094 cond
= build_compound_expr (tree_cons
6096 build_tree_list (NULL_TREE
, cond
)));
6098 /* Cannot have two identical lhs on this one tree (result) as preexpand
6099 calls will rip them out and fill in RTL for them, but when the
6100 rtl is generated, the calls will only be in the first side of the
6101 condition, not on both, or before the conditional jump! (mrs) */
6102 lhs1
= break_out_calls (lhs
);
6105 /* If there's no change, the COND_EXPR behaves like any other rhs. */
6106 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
6107 lhstype
, lhs
, newrhs
);
6110 tree result_type
= TREE_TYPE (newrhs
);
6111 /* We have to convert each arm to the proper type because the
6112 types may have been munged by constant folding. */
6114 = build (COND_EXPR
, result_type
, cond
,
6115 build_modify_expr (lhs
, modifycode
,
6116 cp_convert (result_type
,
6117 TREE_OPERAND (newrhs
, 1))),
6118 build_modify_expr (lhs1
, modifycode
,
6119 cp_convert (result_type
,
6120 TREE_OPERAND (newrhs
, 2))));
6124 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
6125 lhstype
, lhs
, newrhs
);
6127 TREE_SIDE_EFFECTS (result
) = 1;
6129 /* If we got the LHS in a different type for storing in,
6130 convert the result back to the nominal type of LHS
6131 so that the value we return always has the same type
6132 as the LHS argument. */
6134 if (olhstype
== TREE_TYPE (result
))
6136 /* Avoid warnings converting integral types back into enums
6137 for enum bit fields. */
6138 if (TREE_CODE (TREE_TYPE (result
)) == INTEGER_TYPE
6139 && TREE_CODE (olhstype
) == ENUMERAL_TYPE
)
6141 result
= build (COMPOUND_EXPR
, olhstype
, result
, olhs
);
6142 TREE_NO_UNUSED_WARNING (result
) = 1;
6145 return convert_for_assignment (olhstype
, result
, "assignment",
6150 build_x_modify_expr (lhs
, modifycode
, rhs
)
6152 enum tree_code modifycode
;
6155 if (processing_template_decl
)
6156 return build_min_nt (MODOP_EXPR
, lhs
,
6157 build_min_nt (modifycode
, NULL_TREE
, NULL_TREE
), rhs
);
6159 if (modifycode
!= NOP_EXPR
)
6161 tree rval
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
, lhs
, rhs
,
6162 make_node (modifycode
));
6166 return build_modify_expr (lhs
, modifycode
, rhs
);
6169 /* Return 0 if EXP is not a valid lvalue in this language
6170 even though `lvalue_or_else' would accept it. */
6173 language_lvalue_valid (exp
)
6179 /* Get difference in deltas for different pointer to member function
6180 types. Return integer_zero_node, if FROM cannot be converted to a
6181 TO type. If FORCE is true, then allow reverse conversions as well. */
6184 get_delta_difference (from
, to
, force
)
6188 tree delta
= integer_zero_node
;
6194 /* Should get_base_distance here, so we can check if any thing along the
6195 path is virtual, and we need to make sure we stay
6196 inside the real binfos when going through virtual bases.
6197 Maybe we should replace virtual bases with
6198 binfo_member (...CLASSTYPE_VBASECLASSES...)... (mrs) */
6199 binfo
= get_binfo (from
, to
, 1);
6200 if (binfo
== error_mark_node
)
6202 error (" in pointer to member function conversiona");
6209 error_not_base_type (from
, to
);
6210 error (" in pointer to member conversion");
6213 binfo
= get_binfo (to
, from
, 1);
6214 if (binfo
== error_mark_node
)
6217 error (" in pointer to member conversion");
6223 cp_error ("cannot convert pointer to member of type %T to unrelated pointer to member of type %T", from
, to
);
6226 if (TREE_VIA_VIRTUAL (binfo
))
6228 binfo
= binfo_member (BINFO_TYPE (binfo
),
6229 CLASSTYPE_VBASECLASSES (from
));
6230 warning ("pointer to member conversion to virtual base class will only work if you are very careful");
6232 delta
= BINFO_OFFSET (binfo
);
6233 delta
= cp_convert (ptrdiff_type_node
, delta
);
6235 return build_binary_op (MINUS_EXPR
,
6239 if (TREE_VIA_VIRTUAL (binfo
))
6241 warning ("pointer to member conversion from virtual base class will only work if you are very careful");
6243 return BINFO_OFFSET (binfo
);
6247 build_ptrmemfunc1 (type
, delta
, idx
, pfn
, delta2
)
6248 tree type
, delta
, idx
, pfn
, delta2
;
6253 /* This is the old way we did it. We want to avoid calling
6254 digest_init, so that it can give an error if we use { } when
6255 initializing a pointer to member function. */
6259 u
= build_nt (CONSTRUCTOR
, NULL_TREE
,
6260 tree_cons (pfn_identifier
, pfn
, NULL_TREE
));
6264 u
= build_nt (CONSTRUCTOR
, NULL_TREE
,
6265 tree_cons (delta2_identifier
, delta2
, NULL_TREE
));
6268 u
= build_nt (CONSTRUCTOR
, NULL_TREE
,
6269 tree_cons (NULL_TREE
, delta
,
6270 tree_cons (NULL_TREE
, idx
,
6271 tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6273 return digest_init (type
, u
, (tree
*)0);
6275 tree delta_field
, idx_field
, pfn_or_delta2_field
, pfn_field
, delta2_field
;
6277 int allconstant
, allsimple
;
6279 delta_field
= TYPE_FIELDS (type
);
6280 idx_field
= TREE_CHAIN (delta_field
);
6281 pfn_or_delta2_field
= TREE_CHAIN (idx_field
);
6282 subtype
= TREE_TYPE (pfn_or_delta2_field
);
6283 pfn_field
= TYPE_FIELDS (subtype
);
6284 delta2_field
= TREE_CHAIN (pfn_field
);
6288 allconstant
= TREE_CONSTANT (pfn
);
6289 allsimple
= !! initializer_constant_valid_p (pfn
, TREE_TYPE (pfn
));
6290 u
= tree_cons (pfn_field
, pfn
, NULL_TREE
);
6294 delta2
= convert_and_check (delta_type_node
, delta2
);
6295 allconstant
= TREE_CONSTANT (delta2
);
6296 allsimple
= !! initializer_constant_valid_p (delta2
, TREE_TYPE (delta2
));
6297 u
= tree_cons (delta2_field
, delta2
, NULL_TREE
);
6300 delta
= convert_and_check (delta_type_node
, delta
);
6301 idx
= convert_and_check (delta_type_node
, idx
);
6303 allconstant
= allconstant
&& TREE_CONSTANT (delta
) && TREE_CONSTANT (idx
);
6304 allsimple
= allsimple
6305 && initializer_constant_valid_p (delta
, TREE_TYPE (delta
))
6306 && initializer_constant_valid_p (idx
, TREE_TYPE (idx
));
6308 u
= build (CONSTRUCTOR
, subtype
, NULL_TREE
, u
);
6309 u
= tree_cons (delta_field
, delta
,
6310 tree_cons (idx_field
, idx
,
6311 tree_cons (pfn_or_delta2_field
, u
, NULL_TREE
)));
6312 u
= build (CONSTRUCTOR
, type
, NULL_TREE
, u
);
6313 TREE_CONSTANT (u
) = allconstant
;
6314 TREE_STATIC (u
) = allconstant
&& allsimple
;
6319 /* Build a constructor for a pointer to member function. It can be
6320 used to initialize global variables, local variable, or used
6321 as a value in expressions. TYPE is the POINTER to METHOD_TYPE we
6324 If FORCE is non-zero, then force this conversion, even if
6325 we would rather not do it. Usually set when using an explicit
6328 Return error_mark_node, if something goes wrong. */
6331 build_ptrmemfunc (type
, pfn
, force
)
6335 tree idx
= integer_zero_node
;
6336 tree delta
= integer_zero_node
;
6337 tree delta2
= integer_zero_node
;
6339 tree npfn
= NULL_TREE
;
6341 /* Handle multiple conversions of pointer to member functions. */
6342 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (pfn
)))
6344 tree ndelta
, ndelta2
;
6347 /* Is is already the right type? */
6348 if (type
== TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))
6351 ndelta
= cp_convert (ptrdiff_type_node
, build_component_ref (pfn
, delta_identifier
, NULL_TREE
, 0));
6352 ndelta2
= cp_convert (ptrdiff_type_node
, DELTA2_FROM_PTRMEMFUNC (pfn
));
6353 idx
= build_component_ref (pfn
, index_identifier
, NULL_TREE
, 0);
6355 n
= get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))),
6356 TYPE_METHOD_BASETYPE (TREE_TYPE (type
)),
6359 delta
= build_binary_op (PLUS_EXPR
, ndelta
, n
, 1);
6360 delta2
= build_binary_op (PLUS_EXPR
, ndelta2
, n
, 1);
6361 e1
= fold (build (GT_EXPR
, boolean_type_node
, idx
, integer_zero_node
));
6363 e2
= build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type
), delta
, idx
,
6366 pfn
= PFN_FROM_PTRMEMFUNC (pfn
);
6367 npfn
= build1 (NOP_EXPR
, type
, pfn
);
6368 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6370 e3
= build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type
), delta
, idx
, npfn
,
6372 return build_conditional_expr (e1
, e2
, e3
);
6375 /* Handle null pointer to member function conversions. */
6376 if (integer_zerop (pfn
))
6378 pfn
= build_c_cast (type
, integer_zero_node
);
6379 return build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type
),
6380 integer_zero_node
, integer_zero_node
,
6384 if (TREE_CODE (pfn
) == TREE_LIST
6385 || (TREE_CODE (pfn
) == ADDR_EXPR
6386 && TREE_CODE (TREE_OPERAND (pfn
, 0)) == TREE_LIST
))
6387 return instantiate_type (type
, pfn
, 1);
6389 /* Allow pointer to member conversions here. */
6390 delta
= get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TREE_TYPE (pfn
))),
6391 TYPE_METHOD_BASETYPE (TREE_TYPE (type
)),
6393 delta2
= build_binary_op (PLUS_EXPR
, delta2
, delta
, 1);
6396 /* We need to check the argument types to see if they are compatible
6397 (any const or volatile violations. */
6398 something like
this:
6399 comptype (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (type
))),
6400 TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (TREE_TYPE (pfn
)))), ?);
6403 if (TREE_CODE (TREE_OPERAND (pfn
, 0)) != FUNCTION_DECL
)
6404 warning ("assuming pointer to member function is non-virtual");
6406 if (TREE_CODE (TREE_OPERAND (pfn
, 0)) == FUNCTION_DECL
6407 && DECL_VINDEX (TREE_OPERAND (pfn
, 0)))
6409 /* Find the offset to the vfield pointer in the object. */
6410 vfield_offset
= get_binfo (DECL_CONTEXT (TREE_OPERAND (pfn
, 0)),
6411 DECL_CLASS_CONTEXT (TREE_OPERAND (pfn
, 0)),
6413 vfield_offset
= get_vfield_offset (vfield_offset
);
6414 delta2
= size_binop (PLUS_EXPR
, vfield_offset
, delta2
);
6416 /* Map everything down one to make room for the null pointer to member. */
6417 idx
= size_binop (PLUS_EXPR
,
6418 DECL_VINDEX (TREE_OPERAND (pfn
, 0)),
6423 idx
= size_binop (MINUS_EXPR
, integer_zero_node
, integer_one_node
);
6425 if (type
== TREE_TYPE (pfn
))
6431 npfn
= build1 (NOP_EXPR
, type
, pfn
);
6432 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6436 return build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type
), delta
, idx
, npfn
, delta2
);
6439 /* Convert value RHS to type TYPE as preparation for an assignment
6440 to an lvalue of type TYPE.
6441 The real work of conversion is done by `convert'.
6442 The purpose of this function is to generate error messages
6443 for assignments that are not allowed in C.
6444 ERRTYPE is a string to use in error messages:
6445 "assignment", "return", etc.
6447 C++: attempts to allow `convert' to find conversions involving
6448 implicit type conversion between aggregate and scalar types
6449 as per 8.5.6 of C++ manual. Does not randomly dereference
6450 pointers to aggregates! */
6453 convert_for_assignment (type
, rhs
, errtype
, fndecl
, parmnum
)
6459 register enum tree_code codel
= TREE_CODE (type
);
6460 register tree rhstype
;
6461 register enum tree_code coder
= TREE_CODE (TREE_TYPE (rhs
));
6463 if (coder
== UNKNOWN_TYPE
)
6464 rhs
= instantiate_type (type
, rhs
, 1);
6466 if (coder
== ERROR_MARK
)
6467 return error_mark_node
;
6469 if (codel
== OFFSET_TYPE
)
6471 type
= TREE_TYPE (type
);
6472 codel
= TREE_CODE (type
);
6475 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
6476 if (TREE_CODE (rhs
) == NON_LVALUE_EXPR
)
6477 rhs
= TREE_OPERAND (rhs
, 0);
6479 if (rhs
== error_mark_node
)
6480 return error_mark_node
;
6482 if (TREE_VALUE (rhs
) == error_mark_node
)
6483 return error_mark_node
;
6485 if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
6487 rhs
= resolve_offset_ref (rhs
);
6488 if (rhs
== error_mark_node
)
6489 return error_mark_node
;
6490 rhstype
= TREE_TYPE (rhs
);
6491 coder
= TREE_CODE (rhstype
);
6494 if (TREE_CODE (TREE_TYPE (rhs
)) == ARRAY_TYPE
6495 || TREE_CODE (TREE_TYPE (rhs
)) == FUNCTION_TYPE
6496 || TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
6497 rhs
= default_conversion (rhs
);
6498 else if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
6499 rhs
= convert_from_reference (rhs
);
6501 rhstype
= TREE_TYPE (rhs
);
6502 coder
= TREE_CODE (rhstype
);
6504 /* This should no longer change types on us. */
6505 if (TREE_CODE (rhs
) == CONST_DECL
)
6506 rhs
= DECL_INITIAL (rhs
);
6507 else if (TREE_READONLY_DECL_P (rhs
))
6508 rhs
= decl_constant_value (rhs
);
6510 if (type
== rhstype
)
6512 overflow_warning (rhs
);
6516 if (coder
== VOID_TYPE
)
6518 error ("void value not ignored as it ought to be");
6519 return error_mark_node
;
6521 /* Arithmetic types all interconvert. */
6522 if ((codel
== INTEGER_TYPE
|| codel
== REAL_TYPE
|| codel
== BOOLEAN_TYPE
6523 || codel
== COMPLEX_TYPE
)
6524 && (coder
== INTEGER_TYPE
|| coder
== REAL_TYPE
|| coder
== BOOLEAN_TYPE
6525 || coder
== COMPLEX_TYPE
))
6527 /* But we should warn if assigning REAL_TYPE to INTEGER_TYPE. */
6528 if (coder
== REAL_TYPE
&& codel
== INTEGER_TYPE
)
6531 cp_warning ("`%T' used for argument %P of `%D'",
6532 rhstype
, parmnum
, fndecl
);
6534 cp_warning ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6536 /* And we should warn if assigning a negative value to
6537 an unsigned variable. */
6538 else if (TREE_UNSIGNED (type
) && codel
!= BOOLEAN_TYPE
)
6540 if (TREE_CODE (rhs
) == INTEGER_CST
6541 && TREE_NEGATED_INT (rhs
))
6544 cp_warning ("negative value `%E' passed as argument %P of `%D'",
6545 rhs
, parmnum
, fndecl
);
6547 cp_warning ("%s of negative value `%E' to `%T'",
6548 errtype
, rhs
, type
);
6550 overflow_warning (rhs
);
6551 if (TREE_CONSTANT (rhs
))
6555 return convert_and_check (type
, rhs
);
6557 /* Conversions involving enums. */
6558 else if ((codel
== ENUMERAL_TYPE
6559 && (INTEGRAL_CODE_P (coder
) || coder
== REAL_TYPE
))
6560 || (coder
== ENUMERAL_TYPE
6561 && (INTEGRAL_CODE_P (codel
) || codel
== REAL_TYPE
)))
6563 return ocp_convert (type
, rhs
, CONV_IMPLICIT
, LOOKUP_NORMAL
);
6565 /* Conversions among pointers */
6566 else if (codel
== POINTER_TYPE
6567 && (coder
== POINTER_TYPE
6568 || (coder
== RECORD_TYPE
6569 && (IS_SIGNATURE_POINTER (rhstype
)
6570 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6572 register tree ttl
= TREE_TYPE (type
);
6576 if (coder
== RECORD_TYPE
)
6578 rhs
= build_optr_ref (rhs
);
6579 rhstype
= TREE_TYPE (rhs
);
6581 ttr
= TREE_TYPE (rhstype
);
6583 /* If both pointers are of aggregate type, then we
6584 can give better error messages, and save some work
6586 if (TREE_CODE (ttl
) == RECORD_TYPE
&& TREE_CODE (ttr
) == RECORD_TYPE
)
6590 if (TYPE_MAIN_VARIANT (ttl
) == TYPE_MAIN_VARIANT (ttr
)
6591 || type
== class_star_type_node
6592 || rhstype
== class_star_type_node
)
6593 binfo
= TYPE_BINFO (ttl
);
6595 binfo
= get_binfo (ttl
, ttr
, 1);
6597 if (binfo
== error_mark_node
)
6598 return error_mark_node
;
6600 return error_not_base_type (ttl
, ttr
);
6602 if (! TYPE_READONLY (ttl
) && TYPE_READONLY (ttr
))
6605 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6606 rhstype
, parmnum
, fndecl
);
6608 cp_pedwarn ("%s to `%T' from `%T' discards const",
6609 errtype
, type
, rhstype
);
6611 if (! TYPE_VOLATILE (ttl
) && TYPE_VOLATILE (ttr
))
6614 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6615 rhstype
, parmnum
, fndecl
);
6617 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6618 errtype
, type
, rhstype
);
6622 /* Any non-function converts to a [const][volatile] void *
6623 and vice versa; otherwise, targets must be the same.
6624 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
6625 else if (TYPE_MAIN_VARIANT (ttl
) == void_type_node
6626 || TYPE_MAIN_VARIANT (ttr
) == void_type_node
6627 || (ctt
= comp_target_types (type
, rhstype
, 1))
6628 || (unsigned_type (TYPE_MAIN_VARIANT (ttl
))
6629 == unsigned_type (TYPE_MAIN_VARIANT (ttr
))))
6631 /* ARM $4.8, commentary on p39. */
6632 if (TYPE_MAIN_VARIANT (ttl
) == void_type_node
6633 && TREE_CODE (ttr
) == OFFSET_TYPE
)
6635 cp_error ("no standard conversion from `%T' to `void *'", ttr
);
6636 return error_mark_node
;
6639 if (ctt
< 0 && TYPE_MAIN_VARIANT (ttl
) != TYPE_MAIN_VARIANT (ttr
))
6640 cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
6643 if (TYPE_MAIN_VARIANT (ttl
) != void_type_node
6644 && TYPE_MAIN_VARIANT (ttr
) == void_type_node
6645 && ! null_ptr_cst_p (rhs
))
6647 if (coder
== RECORD_TYPE
)
6648 cp_pedwarn ("implicit conversion of signature pointer to type `%T'",
6651 pedwarn ("ANSI C++ forbids implicit conversion from `void *' in %s",
6654 /* Const and volatile mean something different for function types,
6655 so the usual warnings are not appropriate. */
6656 else if ((TREE_CODE (ttr
) != FUNCTION_TYPE
&& TREE_CODE (ttr
) != METHOD_TYPE
)
6657 || (TREE_CODE (ttl
) != FUNCTION_TYPE
&& TREE_CODE (ttl
) != METHOD_TYPE
))
6659 if (TREE_CODE (ttl
) == OFFSET_TYPE
6660 && binfo_member (TYPE_OFFSET_BASETYPE (ttr
),
6661 CLASSTYPE_VBASECLASSES (TYPE_OFFSET_BASETYPE (ttl
))))
6663 sorry ("%s between pointer to members converting across virtual baseclasses", errtype
);
6664 return error_mark_node
;
6666 else if (! TYPE_READONLY (ttl
) && TYPE_READONLY (ttr
))
6669 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6670 rhstype
, parmnum
, fndecl
);
6672 cp_pedwarn ("%s to `%T' from `%T' discards const",
6673 errtype
, type
, rhstype
);
6675 else if (! TYPE_VOLATILE (ttl
) && TYPE_VOLATILE (ttr
))
6678 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6679 rhstype
, parmnum
, fndecl
);
6681 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6682 errtype
, type
, rhstype
);
6684 else if (TREE_CODE (ttl
) == TREE_CODE (ttr
)
6685 && ! comp_target_types (type
, rhstype
, 1))
6688 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signedness",
6689 rhstype
, parmnum
, fndecl
);
6691 cp_pedwarn ("%s to `%T' from `%T' changes signedness",
6692 errtype
, type
, rhstype
);
6698 int add_quals
= 0, const_parity
= 0, volatile_parity
= 0;
6700 int unsigned_parity
;
6703 /* This code is basically a duplicate of comp_ptr_ttypes_real. */
6704 for (; ; ttl
= TREE_TYPE (ttl
), ttr
= TREE_TYPE (ttr
))
6707 const_parity
|= (TYPE_READONLY (ttl
) < TYPE_READONLY (ttr
));
6708 volatile_parity
|= (TYPE_VOLATILE (ttl
) < TYPE_VOLATILE (ttr
));
6711 && (TYPE_READONLY (ttl
) > TYPE_READONLY (ttr
)
6712 || TYPE_VOLATILE (ttl
) > TYPE_VOLATILE (ttr
)))
6714 left_const
&= TYPE_READONLY (ttl
);
6716 if (TREE_CODE (ttl
) != POINTER_TYPE
6717 || TREE_CODE (ttr
) != POINTER_TYPE
)
6720 unsigned_parity
= TREE_UNSIGNED (ttl
) - TREE_UNSIGNED (ttr
);
6721 if (unsigned_parity
)
6723 if (TREE_UNSIGNED (ttl
))
6724 ttr
= unsigned_type (ttr
);
6726 ttl
= unsigned_type (ttl
);
6729 if (comp_target_types (ttl
, ttr
, nptrs
) > 0)
6734 cp_pedwarn ("passing `%T' as argument %P of `%D' adds cv-quals without intervening `const'",
6735 rhstype
, parmnum
, fndecl
);
6737 cp_pedwarn ("%s to `%T' from `%T' adds cv-quals without intervening `const'",
6738 errtype
, type
, rhstype
);
6743 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6744 rhstype
, parmnum
, fndecl
);
6746 cp_pedwarn ("%s to `%T' from `%T' discards const",
6747 errtype
, type
, rhstype
);
6749 if (volatile_parity
)
6752 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6753 rhstype
, parmnum
, fndecl
);
6755 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6756 errtype
, type
, rhstype
);
6758 if (unsigned_parity
> 0)
6761 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signed to unsigned",
6762 rhstype
, parmnum
, fndecl
);
6764 cp_pedwarn ("%s to `%T' from `%T' changes signed to unsigned",
6765 errtype
, type
, rhstype
);
6767 else if (unsigned_parity
< 0)
6770 cp_pedwarn ("passing `%T' as argument %P of `%D' changes unsigned to signed",
6771 rhstype
, parmnum
, fndecl
);
6773 cp_pedwarn ("%s to `%T' from `%T' changes unsigned to signed",
6774 errtype
, type
, rhstype
);
6777 /* C++ is not so friendly about converting function and
6778 member function pointers as C. Emit warnings here. */
6779 if (TREE_CODE (ttl
) == FUNCTION_TYPE
6780 || TREE_CODE (ttl
) == METHOD_TYPE
)
6781 if (! comptypes (ttl
, ttr
, 0))
6783 warning ("conflicting function types in %s:", errtype
);
6784 cp_warning ("\t`%T' != `%T'", type
, rhstype
);
6790 cp_error ("passing `%T' as argument %P of `%D'",
6791 rhstype
, parmnum
, fndecl
);
6793 cp_error ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6794 return error_mark_node
;
6797 return cp_convert (type
, rhs
);
6799 else if (codel
== POINTER_TYPE
&& coder
== INTEGER_TYPE
)
6801 /* An explicit constant 0 can convert to a pointer,
6802 but not a 0 that results from casting or folding. */
6803 if (! (TREE_CODE (rhs
) == INTEGER_CST
&& integer_zerop (rhs
)))
6806 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6807 rhstype
, parmnum
, fndecl
);
6809 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
6810 errtype
, type
, rhstype
);
6812 return cp_convert (type
, rhs
);
6814 else if (codel
== INTEGER_TYPE
6815 && (coder
== POINTER_TYPE
6816 || (coder
== RECORD_TYPE
6817 && (IS_SIGNATURE_POINTER (rhstype
)
6818 || TYPE_PTRMEMFUNC_FLAG (rhstype
)
6819 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6822 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6823 rhstype
, parmnum
, fndecl
);
6825 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
6826 errtype
, type
, rhstype
);
6827 return cp_convert (type
, rhs
);
6829 else if (codel
== BOOLEAN_TYPE
6830 && (coder
== POINTER_TYPE
6831 || (coder
== RECORD_TYPE
6832 && (IS_SIGNATURE_POINTER (rhstype
)
6833 || TYPE_PTRMEMFUNC_FLAG (rhstype
)
6834 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6835 return cp_convert (type
, rhs
);
6838 else if (((coder
== POINTER_TYPE
6839 && TREE_CODE (TREE_TYPE (rhstype
)) == METHOD_TYPE
)
6840 || integer_zerop (rhs
)
6841 || TYPE_PTRMEMFUNC_P (rhstype
))
6842 && TYPE_PTRMEMFUNC_P (type
))
6844 tree ttl
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
6845 tree ttr
= (TREE_CODE (rhstype
) == POINTER_TYPE
? rhstype
6846 : TYPE_PTRMEMFUNC_FN_TYPE (type
));
6847 int ctt
= comp_target_types (ttl
, ttr
, 1);
6850 cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
6853 cp_error ("%s to `%T' from `%T'", errtype
, ttl
, ttr
);
6855 /* compatible pointer to member functions. */
6856 return build_ptrmemfunc (ttl
, rhs
, 0);
6858 else if (codel
== ERROR_MARK
|| coder
== ERROR_MARK
)
6859 return error_mark_node
;
6861 /* This should no longer happen. References are initialized via
6862 `convert_for_initialization'. They should otherwise be
6863 bashed before coming here. */
6864 else if (codel
== REFERENCE_TYPE
)
6865 my_friendly_abort (317);
6866 else if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (TREE_TYPE (rhs
)))
6868 tree nrhs
= build1 (NOP_EXPR
, type
, rhs
);
6869 TREE_CONSTANT (nrhs
) = TREE_CONSTANT (rhs
);
6872 else if (TYPE_HAS_CONSTRUCTOR (type
) || IS_AGGR_TYPE (TREE_TYPE (rhs
)))
6873 return cp_convert (type
, rhs
);
6874 /* Handle anachronistic conversions from (::*)() to cv void* or (*)(). */
6875 else if (TREE_CODE (type
) == POINTER_TYPE
6876 && (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
6877 || TYPE_MAIN_VARIANT (TREE_TYPE (type
)) == void_type_node
)
6879 && TYPE_PTRMEMFUNC_P (TREE_TYPE (rhs
)))
6880 return cp_convert (type
, rhs
);
6882 cp_error ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6883 return error_mark_node
;
6886 /* Convert RHS to be of type TYPE. If EXP is non-zero,
6887 it is the target of the initialization.
6888 ERRTYPE is a string to use in error messages.
6890 Two major differences between the behavior of
6891 `convert_for_assignment' and `convert_for_initialization'
6892 are that references are bashed in the former, while
6893 copied in the latter, and aggregates are assigned in
6894 the former (operator=) while initialized in the
6897 If using constructor make sure no conversion operator exists, if one does
6898 exist, an ambiguity exists.
6900 If flags doesn't include LOOKUP_COMPLAIN, don't complain about anything. */
6903 convert_for_initialization (exp
, type
, rhs
, flags
, errtype
, fndecl
, parmnum
)
6904 tree exp
, type
, rhs
;
6910 register enum tree_code codel
= TREE_CODE (type
);
6911 register tree rhstype
;
6912 register enum tree_code coder
;
6914 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
6915 Strip such NOP_EXPRs, since RHS is used in non-lvalue context. */
6916 if (TREE_CODE (rhs
) == NOP_EXPR
6917 && TREE_TYPE (rhs
) == TREE_TYPE (TREE_OPERAND (rhs
, 0))
6918 && codel
!= REFERENCE_TYPE
)
6919 rhs
= TREE_OPERAND (rhs
, 0);
6921 if (rhs
== error_mark_node
6922 || (TREE_CODE (rhs
) == TREE_LIST
&& TREE_VALUE (rhs
) == error_mark_node
))
6923 return error_mark_node
;
6925 if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
6927 rhs
= resolve_offset_ref (rhs
);
6928 if (rhs
== error_mark_node
)
6929 return error_mark_node
;
6932 if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
6933 rhs
= convert_from_reference (rhs
);
6935 if ((TREE_CODE (TREE_TYPE (rhs
)) == ARRAY_TYPE
6936 && TREE_CODE (type
) != ARRAY_TYPE
6937 && (TREE_CODE (type
) != REFERENCE_TYPE
6938 || TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
))
6939 || TREE_CODE (TREE_TYPE (rhs
)) == FUNCTION_TYPE
6940 || TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
6941 rhs
= default_conversion (rhs
);
6943 rhstype
= TREE_TYPE (rhs
);
6944 coder
= TREE_CODE (rhstype
);
6946 if (coder
== UNKNOWN_TYPE
)
6948 rhs
= instantiate_type (type
, rhs
, 1);
6949 rhstype
= TREE_TYPE (rhs
);
6950 coder
= TREE_CODE (rhstype
);
6953 if (coder
== ERROR_MARK
)
6954 return error_mark_node
;
6956 /* We accept references to incomplete types, so we can
6957 return here before checking if RHS is of complete type. */
6959 if (codel
== REFERENCE_TYPE
)
6961 /* This should eventually happen in convert_arguments. */
6962 extern int warningcount
, errorcount
;
6966 savew
= warningcount
, savee
= errorcount
;
6967 rhs
= convert_to_reference (type
, rhs
, CONV_IMPLICIT
, flags
,
6968 exp
? exp
: error_mark_node
);
6971 if (warningcount
> savew
)
6972 cp_warning_at ("in passing argument %P of `%+D'", parmnum
, fndecl
);
6973 else if (errorcount
> savee
)
6974 cp_error_at ("in passing argument %P of `%+D'", parmnum
, fndecl
);
6979 rhs
= require_complete_type (rhs
);
6980 if (rhs
== error_mark_node
)
6981 return error_mark_node
;
6983 if (exp
!= 0) exp
= require_complete_type (exp
);
6984 if (exp
== error_mark_node
)
6985 return error_mark_node
;
6987 if (TREE_CODE (rhstype
) == REFERENCE_TYPE
)
6988 rhstype
= TREE_TYPE (rhstype
);
6990 type
= complete_type (type
);
6992 if (TYPE_LANG_SPECIFIC (type
)
6993 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
)))
6994 return build_signature_pointer_constructor (type
, rhs
);
6996 if (IS_AGGR_TYPE (type
)
6997 && (TYPE_NEEDS_CONSTRUCTING (type
) || TREE_HAS_CONSTRUCTOR (rhs
)))
6999 if (flag_ansi_overloading
)
7000 return ocp_convert (type
, rhs
, CONV_IMPLICIT
|CONV_FORCE_TEMP
, flags
);
7002 if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (rhstype
))
7004 /* This is sufficient to perform initialization. No need,
7005 apparently, to go through X(X&) to do first-cut
7006 initialization. Return through a TARGET_EXPR so that we get
7007 cleanups if it is used. */
7008 if (TREE_CODE (rhs
) == CALL_EXPR
)
7010 rhs
= build_cplus_new (type
, rhs
);
7013 /* Handle the case of default parameter initialization and
7014 initialization of static variables. */
7015 else if (TREE_CODE (rhs
) == TARGET_EXPR
)
7017 else if (TREE_CODE (rhs
) == INDIRECT_REF
&& TREE_HAS_CONSTRUCTOR (rhs
))
7019 my_friendly_assert (TREE_CODE (TREE_OPERAND (rhs
, 0)) == CALL_EXPR
, 318);
7022 my_friendly_assert (TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs
, 0), 1)) == NULL_TREE
, 316);
7023 TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs
, 0), 1))
7024 = build_unary_op (ADDR_EXPR
, exp
, 0);
7027 rhs
= build_cplus_new (type
, TREE_OPERAND (rhs
, 0));
7030 else if (TYPE_HAS_TRIVIAL_INIT_REF (type
))
7033 if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (rhstype
)
7034 || (IS_AGGR_TYPE (rhstype
) && UNIQUELY_DERIVED_FROM_P (type
, rhstype
)))
7036 if (TYPE_HAS_INIT_REF (type
))
7038 tree init
= build_method_call (exp
, ctor_identifier
,
7039 build_tree_list (NULL_TREE
, rhs
),
7040 TYPE_BINFO (type
), LOOKUP_NORMAL
);
7042 if (init
== error_mark_node
)
7043 return error_mark_node
;
7047 exp
= build_cplus_new (type
, init
);
7051 return build (COMPOUND_EXPR
, type
, init
, exp
);
7054 /* ??? The following warnings are turned off because
7055 this is another place where the default X(X&) constructor
7057 if (TYPE_HAS_ASSIGNMENT (type
))
7058 cp_warning ("bitwise copy: `%T' defines operator=", type
);
7060 if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
7061 rhs
= convert_from_reference (rhs
);
7062 if (type
!= rhstype
)
7064 tree nrhs
= build1 (NOP_EXPR
, type
, rhs
);
7065 TREE_CONSTANT (nrhs
) = TREE_CONSTANT (rhs
);
7071 return ocp_convert (type
, rhs
, CONV_OLD_CONVERT
,
7072 flags
| LOOKUP_NO_CONVERSION
);
7075 if (type
== TREE_TYPE (rhs
))
7077 if (TREE_READONLY_DECL_P (rhs
))
7078 rhs
= decl_constant_value (rhs
);
7082 return convert_for_assignment (type
, rhs
, errtype
, fndecl
, parmnum
);
7085 /* Expand an ASM statement with operands, handling output operands
7086 that are not variables or INDIRECT_REFS by transforming such
7087 cases into cases that expand_asm_operands can handle.
7089 Arguments are same as for expand_asm_operands.
7091 We don't do default conversions on all inputs, because it can screw
7092 up operands that are expected to be in memory. */
7095 c_expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, filename
, line
)
7096 tree string
, outputs
, inputs
, clobbers
;
7101 int noutputs
= list_length (outputs
);
7103 /* o[I] is the place that output number I should be written. */
7104 register tree
*o
= (tree
*) alloca (noutputs
* sizeof (tree
));
7107 /* Record the contents of OUTPUTS before it is modified. */
7108 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
7109 o
[i
] = TREE_VALUE (tail
);
7111 /* Generate the ASM_OPERANDS insn;
7112 store into the TREE_VALUEs of OUTPUTS some trees for
7113 where the values were actually stored. */
7114 expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, filename
, line
);
7116 /* Copy all the intermediate outputs into the specified outputs. */
7117 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
7119 if (o
[i
] != TREE_VALUE (tail
))
7121 expand_expr (build_modify_expr (o
[i
], NOP_EXPR
, TREE_VALUE (tail
)),
7122 const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
7125 /* Detect modification of read-only values.
7126 (Otherwise done by build_modify_expr.) */
7129 tree type
= TREE_TYPE (o
[i
]);
7130 if (TYPE_READONLY (type
)
7131 || ((TREE_CODE (type
) == RECORD_TYPE
7132 || TREE_CODE (type
) == UNION_TYPE
)
7133 && C_TYPE_FIELDS_READONLY (type
)))
7134 readonly_error (o
[i
], "modification by `asm'", 1);
7138 /* Those MODIFY_EXPRs could do autoincrements. */
7142 /* Expand a C `return' statement.
7143 RETVAL is the expression for what to return,
7144 or a null pointer for `return;' with no value.
7146 C++: upon seeing a `return', we must call destructors on all
7147 variables in scope which had constructors called on them.
7148 This means that if in a destructor, the base class destructors
7149 must be called before returning.
7151 The RETURN statement in C++ has initialization semantics. */
7154 c_expand_return (retval
)
7157 extern struct nesting
*cond_stack
, *loop_stack
, *case_stack
;
7158 extern tree dtor_label
, ctor_label
;
7159 tree result
= DECL_RESULT (current_function_decl
);
7160 tree valtype
= TREE_TYPE (result
);
7162 if (TREE_THIS_VOLATILE (current_function_decl
))
7163 warning ("function declared `noreturn' has a `return' statement");
7165 if (retval
== error_mark_node
)
7167 current_function_returns_null
= 1;
7171 if (processing_template_decl
)
7173 add_tree (build_min_nt (RETURN_STMT
, retval
));
7177 if (retval
== NULL_TREE
)
7179 /* A non-named return value does not count. */
7181 /* Can't just return from a destructor. */
7184 expand_goto (dtor_label
);
7188 if (DECL_CONSTRUCTOR_P (current_function_decl
))
7189 retval
= current_class_ptr
;
7190 else if (DECL_NAME (result
) != NULL_TREE
7191 && TREE_CODE (valtype
) != VOID_TYPE
)
7195 current_function_returns_null
= 1;
7197 if (valtype
!= NULL_TREE
&& TREE_CODE (valtype
) != VOID_TYPE
)
7199 if (DECL_NAME (DECL_RESULT (current_function_decl
)) == NULL_TREE
)
7201 pedwarn ("`return' with no value, in function returning non-void");
7202 /* Clear this, so finish_function won't say that we
7203 reach the end of a non-void function (which we don't,
7204 we gave a return!). */
7205 current_function_returns_null
= 0;
7209 expand_null_return ();
7213 else if (DECL_CONSTRUCTOR_P (current_function_decl
)
7214 && retval
!= current_class_ptr
)
7216 if (flag_this_is_variable
)
7217 error ("return from a constructor: use `this = ...' instead");
7219 error ("return from a constructor");
7220 retval
= current_class_ptr
;
7223 /* Effective C++ rule 15. See also start_function. */
7225 && DECL_NAME (current_function_decl
) == ansi_opname
[(int) MODIFY_EXPR
]
7226 && retval
!= current_class_ref
)
7227 cp_warning ("`operator=' should return a reference to `*this'");
7229 if (valtype
== NULL_TREE
|| TREE_CODE (valtype
) == VOID_TYPE
)
7231 current_function_returns_null
= 1;
7232 if ((pedantic
&& ! DECL_ARTIFICIAL (current_function_decl
))
7233 || TREE_CODE (TREE_TYPE (retval
)) != VOID_TYPE
)
7234 pedwarn ("`return' with a value, in function returning void");
7235 expand_return (retval
);
7239 /* Now deal with possible C++ hair:
7240 (1) Compute the return value.
7241 (2) If there are aggregate values with destructors which
7242 must be cleaned up, clean them (taking care
7243 not to clobber the return value).
7244 (3) If an X(X&) constructor is defined, the return
7245 value must be returned via that. */
7247 if (retval
== result
7248 || DECL_CONSTRUCTOR_P (current_function_decl
))
7249 /* It's already done for us. */;
7250 else if (TREE_TYPE (retval
) == void_type_node
)
7252 pedwarn ("return of void value in function returning non-void");
7253 expand_expr_stmt (retval
);
7258 retval
= convert_for_initialization
7259 (NULL_TREE
, valtype
, retval
, LOOKUP_NORMAL
|LOOKUP_ONLYCONVERTING
,
7260 "return", NULL_TREE
, 0);
7262 if (retval
== error_mark_node
)
7264 /* Avoid warning about control reaching end of function. */
7265 expand_null_return ();
7269 /* We can't initialize a register from a NEW_EXPR. */
7270 else if (! current_function_returns_struct
7271 && TREE_CODE (retval
) == TARGET_EXPR
7272 && TREE_CODE (TREE_OPERAND (retval
, 1)) == NEW_EXPR
)
7273 retval
= build (COMPOUND_EXPR
, TREE_TYPE (retval
), retval
,
7274 TREE_OPERAND (retval
, 0));
7276 /* Add some useful error checking for C++. */
7277 else if (TREE_CODE (valtype
) == REFERENCE_TYPE
)
7279 tree whats_returned
;
7281 /* Sort through common things to see what it is
7282 we are returning. */
7283 whats_returned
= retval
;
7284 if (TREE_CODE (whats_returned
) == COMPOUND_EXPR
)
7286 whats_returned
= TREE_OPERAND (whats_returned
, 1);
7287 if (TREE_CODE (whats_returned
) == ADDR_EXPR
)
7288 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7290 while (TREE_CODE (whats_returned
) == CONVERT_EXPR
7291 || TREE_CODE (whats_returned
) == NOP_EXPR
)
7292 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7293 if (TREE_CODE (whats_returned
) == ADDR_EXPR
)
7295 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7296 while (TREE_CODE (whats_returned
) == NEW_EXPR
7297 || TREE_CODE (whats_returned
) == TARGET_EXPR
)
7299 /* Get the target. */
7300 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7301 warning ("returning reference to temporary");
7305 if (TREE_CODE (whats_returned
) == VAR_DECL
&& DECL_NAME (whats_returned
))
7307 if (TEMP_NAME_P (DECL_NAME (whats_returned
)))
7308 warning ("reference to non-lvalue returned");
7309 else if (TREE_CODE (TREE_TYPE (whats_returned
)) != REFERENCE_TYPE
7310 && ! TREE_STATIC (whats_returned
)
7311 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned
))
7312 && !TREE_PUBLIC (whats_returned
))
7313 cp_warning_at ("reference to local variable `%D' returned", whats_returned
);
7316 else if (TREE_CODE (retval
) == ADDR_EXPR
)
7318 tree whats_returned
= TREE_OPERAND (retval
, 0);
7320 if (TREE_CODE (whats_returned
) == VAR_DECL
7321 && DECL_NAME (whats_returned
)
7322 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned
))
7323 && !TREE_STATIC (whats_returned
)
7324 && !TREE_PUBLIC (whats_returned
))
7325 cp_warning_at ("address of local variable `%D' returned", whats_returned
);
7329 if (retval
!= NULL_TREE
7330 && TREE_CODE_CLASS (TREE_CODE (retval
)) == 'd'
7331 && cond_stack
== 0 && loop_stack
== 0 && case_stack
== 0)
7332 current_function_return_value
= retval
;
7334 if (ctor_label
&& TREE_CODE (ctor_label
) != ERROR_MARK
)
7336 /* Here RETVAL is CURRENT_CLASS_PTR, so there's nothing to do. */
7337 expand_goto (ctor_label
);
7340 if (retval
&& retval
!= result
)
7342 result
= build (INIT_EXPR
, TREE_TYPE (result
), result
, retval
);
7343 TREE_SIDE_EFFECTS (result
) = 1;
7346 expand_start_target_temps ();
7348 expand_return (result
);
7350 expand_end_target_temps ();
7352 current_function_returns_value
= 1;
7355 /* Start a C switch statement, testing expression EXP.
7356 Return EXP if it is valid, an error node otherwise. */
7359 c_expand_start_case (exp
)
7363 register enum tree_code code
;
7365 /* Convert from references, etc. */
7366 exp
= default_conversion (exp
);
7367 type
= TREE_TYPE (exp
);
7368 code
= TREE_CODE (type
);
7370 if (IS_AGGR_TYPE_CODE (code
))
7371 exp
= build_type_conversion (CONVERT_EXPR
, integer_type_node
, exp
, 1);
7373 if (exp
== NULL_TREE
)
7375 error ("switch quantity not an integer");
7376 exp
= error_mark_node
;
7378 type
= TREE_TYPE (exp
);
7379 code
= TREE_CODE (type
);
7381 if (code
!= INTEGER_TYPE
&& code
!= ENUMERAL_TYPE
&& code
!= ERROR_MARK
)
7383 error ("switch quantity not an integer");
7384 exp
= error_mark_node
;
7390 exp
= default_conversion (exp
);
7391 type
= TREE_TYPE (exp
);
7392 idx
= get_unwidened (exp
, 0);
7393 /* We can't strip a conversion from a signed type to an unsigned,
7394 because if we did, int_fits_type_p would do the wrong thing
7395 when checking case values for being in range,
7396 and it's too hard to do the right thing. */
7397 if (TREE_UNSIGNED (TREE_TYPE (exp
))
7398 == TREE_UNSIGNED (TREE_TYPE (idx
)))
7403 (1, fold (build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (exp
), exp
)),
7404 type
, "switch statement");
7409 /* CONSTP remembers whether or not all the intervening pointers in the `to'
7410 type have been const. */
7413 comp_ptr_ttypes_real (to
, from
, constp
)
7417 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7419 if (TREE_CODE (to
) != TREE_CODE (from
))
7422 if (TREE_CODE (from
) == OFFSET_TYPE
7423 && comptypes (TYPE_OFFSET_BASETYPE (from
),
7424 TYPE_OFFSET_BASETYPE (to
), 1))
7427 /* Const and volatile mean something different for function types,
7428 so the usual checks are not appropriate. */
7429 if (TREE_CODE (to
) != FUNCTION_TYPE
&& TREE_CODE (to
) != METHOD_TYPE
)
7431 if (TYPE_READONLY (from
) > TYPE_READONLY (to
)
7432 || TYPE_VOLATILE (from
) > TYPE_VOLATILE (to
))
7436 && (TYPE_READONLY (to
) > TYPE_READONLY (from
)
7437 || TYPE_VOLATILE (to
) > TYPE_READONLY (from
)))
7439 constp
&= TYPE_READONLY (to
);
7442 if (TREE_CODE (to
) != POINTER_TYPE
)
7443 return comptypes (TYPE_MAIN_VARIANT (to
), TYPE_MAIN_VARIANT (from
), 1);
7447 /* When comparing, say, char ** to char const **, this function takes the
7448 'char *' and 'char const *'. Do not pass non-pointer types to this
7452 comp_ptr_ttypes (to
, from
)
7455 return comp_ptr_ttypes_real (to
, from
, 1);
7458 /* Returns 1 if to and from are (possibly multi-level) pointers to the same
7459 type or inheritance-related types, regardless of cv-quals. */
7462 ptr_reasonably_similar (to
, from
)
7465 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7467 if (TREE_CODE (to
) != TREE_CODE (from
))
7470 if (TREE_CODE (from
) == OFFSET_TYPE
7471 && comptypes (TYPE_OFFSET_BASETYPE (to
),
7472 TYPE_OFFSET_BASETYPE (from
), -1))
7475 if (TREE_CODE (to
) != POINTER_TYPE
)
7477 (TYPE_MAIN_VARIANT (to
), TYPE_MAIN_VARIANT (from
), -1);
7481 /* Like comp_ptr_ttypes, for const_cast. */
7484 comp_ptr_ttypes_const (to
, from
)
7487 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7489 if (TREE_CODE (to
) != TREE_CODE (from
))
7492 if (TREE_CODE (from
) == OFFSET_TYPE
7493 && comptypes (TYPE_OFFSET_BASETYPE (from
),
7494 TYPE_OFFSET_BASETYPE (to
), 1))
7497 if (TREE_CODE (to
) != POINTER_TYPE
)
7498 return comptypes (TYPE_MAIN_VARIANT (to
), TYPE_MAIN_VARIANT (from
), 1);
7502 /* Like comp_ptr_ttypes, for reinterpret_cast. */
7505 comp_ptr_ttypes_reinterpret (to
, from
)
7510 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7512 if (TREE_CODE (from
) == OFFSET_TYPE
)
7513 from
= TREE_TYPE (from
);
7514 if (TREE_CODE (to
) == OFFSET_TYPE
)
7515 to
= TREE_TYPE (to
);
7517 if (TREE_CODE (to
) != TREE_CODE (from
))
7520 /* Const and volatile mean something different for function types,
7521 so the usual checks are not appropriate. */
7522 if (TREE_CODE (to
) != FUNCTION_TYPE
&& TREE_CODE (to
) != METHOD_TYPE
)
7524 if (TYPE_READONLY (from
) > TYPE_READONLY (to
)
7525 || TYPE_VOLATILE (from
) > TYPE_VOLATILE (to
))
7529 && (TYPE_READONLY (to
) > TYPE_READONLY (from
)
7530 || TYPE_VOLATILE (to
) > TYPE_READONLY (from
)))
7532 constp
&= TYPE_READONLY (to
);
7535 if (TREE_CODE (to
) != POINTER_TYPE
)