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). */
33 extern void warning ();
43 int mark_addressable
PROTO((tree
));
44 static tree convert_for_assignment
PROTO((tree
, tree
, char*, tree
, int));
45 /* static */ tree convert_for_initialization
PROTO((tree
, tree
, tree
, int, char*, tree
, int));
46 extern tree
shorten_compare ();
47 static tree pointer_int_sum
PROTO((enum tree_code
, register tree
, register tree
));
48 static tree pointer_diff
PROTO((register tree
, register tree
));
49 static int comp_target_parms
PROTO((tree
, tree
, int));
50 static int comp_ptr_ttypes_const
PROTO((tree
, tree
));
51 static int comp_ptr_ttypes_reinterpret
PROTO((tree
, tree
));
53 static tree
convert_sequence ();
55 /* static */ tree unary_complex_lvalue
PROTO((enum tree_code
, tree
));
56 static tree get_delta_difference
PROTO((tree
, tree
, int));
58 /* Return the target type of TYPE, which meas return T for:
59 T*, T&, T[], T (...), and otherwise, just T. */
65 if (TREE_CODE (type
) == REFERENCE_TYPE
)
66 type
= TREE_TYPE (type
);
67 while (TREE_CODE (type
) == POINTER_TYPE
68 || TREE_CODE (type
) == ARRAY_TYPE
69 || TREE_CODE (type
) == FUNCTION_TYPE
70 || TREE_CODE (type
) == METHOD_TYPE
71 || TREE_CODE (type
) == OFFSET_TYPE
)
72 type
= TREE_TYPE (type
);
76 /* Do `exp = require_complete_type (exp);' to make sure exp
77 does not have an incomplete type. (That includes void types.) */
80 require_complete_type (value
)
85 if (processing_template_decl
)
88 type
= TREE_TYPE (value
);
90 /* First, detect a valid value with a complete type. */
91 if (TYPE_SIZE (type
) != 0
92 && type
!= void_type_node
93 && ! (TYPE_LANG_SPECIFIC (type
)
94 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
))
95 && TYPE_SIZE (SIGNATURE_TYPE (type
)) == 0))
98 /* If we see X::Y, we build an OFFSET_TYPE which has
99 not been laid out. Try to avoid an error by interpreting
100 it as this->X::Y, if reasonable. */
101 if (TREE_CODE (value
) == OFFSET_REF
102 && current_class_ref
!= 0
103 && TREE_OPERAND (value
, 0) == current_class_ref
)
105 tree base
, member
= TREE_OPERAND (value
, 1);
106 tree basetype
= TYPE_OFFSET_BASETYPE (type
);
107 my_friendly_assert (TREE_CODE (member
) == FIELD_DECL
, 305);
108 base
= convert_pointer_to (basetype
, current_class_ptr
);
109 value
= build (COMPONENT_REF
, TREE_TYPE (member
),
110 build_indirect_ref (base
, NULL_PTR
), member
);
111 return require_complete_type (value
);
114 if (IS_AGGR_TYPE (type
) && CLASSTYPE_TEMPLATE_INSTANTIATION (type
))
116 instantiate_class_template (TYPE_MAIN_VARIANT (type
));
117 if (TYPE_SIZE (type
) != 0)
121 incomplete_type_error (value
, type
);
122 return error_mark_node
;
129 if (type
== error_mark_node
|| TYPE_SIZE (type
) != NULL_TREE
)
131 else if (TREE_CODE (type
) == ARRAY_TYPE
&& TYPE_DOMAIN (type
))
133 tree t
= complete_type (TREE_TYPE (type
));
134 if (TYPE_SIZE (t
) != NULL_TREE
&& ! processing_template_decl
)
136 TYPE_NEEDS_CONSTRUCTING (type
)
137 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (t
));
138 TYPE_NEEDS_DESTRUCTOR (type
)
139 = TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (t
));
141 else if (IS_AGGR_TYPE (type
) && CLASSTYPE_TEMPLATE_INSTANTIATION (type
))
142 instantiate_class_template (TYPE_MAIN_VARIANT (type
));
147 /* Return truthvalue of whether type of EXP is instantiated. */
153 return (TREE_CODE (exp
) == TREE_LIST
154 || TREE_TYPE (exp
) == unknown_type_node
155 || (TREE_CODE (TREE_TYPE (exp
)) == OFFSET_TYPE
156 && TREE_TYPE (TREE_TYPE (exp
)) == unknown_type_node
));
159 /* Return truthvalue of whether T is function (or pfn) type. */
165 return (TREE_CODE (t
) == FUNCTION_TYPE
|| TREE_CODE (t
) == METHOD_TYPE
166 || (TREE_CODE (t
) == POINTER_TYPE
167 && (TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
168 || TREE_CODE (TREE_TYPE (t
)) == METHOD_TYPE
)));
171 /* Do `exp = require_instantiated_type (type, exp);' to make sure EXP
172 does not have an uninstantiated type.
173 TYPE is type to instantiate with, if uninstantiated. */
176 require_instantiated_type (type
, exp
, errval
)
177 tree type
, exp
, errval
;
179 if (TREE_TYPE (exp
) == NULL_TREE
)
181 error ("argument list may not have an initializer list");
185 if (TREE_TYPE (exp
) == unknown_type_node
186 || (TREE_CODE (TREE_TYPE (exp
)) == OFFSET_TYPE
187 && TREE_TYPE (TREE_TYPE (exp
)) == unknown_type_node
))
189 exp
= instantiate_type (type
, exp
, 1);
190 if (TREE_TYPE (exp
) == error_mark_node
)
196 /* Return a variant of TYPE which has all the type qualifiers of LIKE
197 as well as those of TYPE. */
200 qualify_type (type
, like
)
203 int constflag
= TYPE_READONLY (type
) || TYPE_READONLY (like
);
204 int volflag
= TYPE_VOLATILE (type
) || TYPE_VOLATILE (like
);
205 /* @@ Must do member pointers here. */
206 return cp_build_type_variant (type
, constflag
, volflag
);
209 /* Return the common type of two parameter lists.
210 We assume that comptypes has already been done and returned 1;
211 if that isn't so, this may crash.
213 As an optimization, free the space we allocate if the parameter
214 lists are already common. */
220 tree oldargs
= p1
, newargs
, n
;
223 char *first_obj
= (char *) oballoc (0);
225 len
= list_length (p1
);
226 newargs
= tree_last (p1
);
228 if (newargs
== void_list_node
)
237 newargs
= tree_cons (NULL_TREE
, NULL_TREE
, newargs
);
242 p1
= TREE_CHAIN (p1
), p2
= TREE_CHAIN (p2
), n
= TREE_CHAIN (n
), i
++)
244 if (TREE_PURPOSE (p1
) && !TREE_PURPOSE (p2
))
246 TREE_PURPOSE (n
) = TREE_PURPOSE (p1
);
249 else if (! TREE_PURPOSE (p1
))
251 if (TREE_PURPOSE (p2
))
253 TREE_PURPOSE (n
) = TREE_PURPOSE (p2
);
259 if (1 != simple_cst_equal (TREE_PURPOSE (p1
), TREE_PURPOSE (p2
)))
261 TREE_PURPOSE (n
) = TREE_PURPOSE (p2
);
263 if (TREE_VALUE (p1
) != TREE_VALUE (p2
))
266 TREE_VALUE (n
) = common_type (TREE_VALUE (p1
), TREE_VALUE (p2
));
269 TREE_VALUE (n
) = TREE_VALUE (p1
);
280 /* Return the common type of two types.
281 We assume that comptypes has already been done and returned 1;
282 if that isn't so, this may crash.
284 This is the type for the result of most arithmetic operations
285 if the operands have the given two types.
287 We do not deal with enumeral types here because they have already been
288 converted to integer types. */
294 register enum tree_code code1
;
295 register enum tree_code code2
;
298 /* Save time if the two types are the same. */
300 if (t1
== t2
) return t1
;
302 /* If one type is nonsense, use the other. */
303 if (t1
== error_mark_node
)
305 if (t2
== error_mark_node
)
308 /* Merge the attributes */
310 { register tree a1
, a2
;
311 a1
= TYPE_ATTRIBUTES (t1
);
312 a2
= TYPE_ATTRIBUTES (t2
);
314 /* Either one unset? Take the set one. */
316 if (!(attributes
= a1
))
319 /* One that completely contains the other? Take it. */
321 else if (a2
&& !attribute_list_contained (a1
, a2
))
322 if (attribute_list_contained (a2
, a1
))
326 /* Pick the longest list, and hang on the other list. */
327 /* ??? For the moment we punt on the issue of attrs with args. */
329 if (list_length (a1
) < list_length (a2
))
330 attributes
= a2
, a2
= a1
;
332 for (; a2
; a2
= TREE_CHAIN (a2
))
333 if (lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2
)),
334 attributes
) == NULL_TREE
)
337 TREE_CHAIN (a1
) = attributes
;
343 /* Treat an enum type as the unsigned integer type of the same width. */
345 if (TREE_CODE (t1
) == ENUMERAL_TYPE
)
346 t1
= type_for_size (TYPE_PRECISION (t1
), 1);
347 if (TREE_CODE (t2
) == ENUMERAL_TYPE
)
348 t2
= type_for_size (TYPE_PRECISION (t2
), 1);
350 if (TYPE_PTRMEMFUNC_P (t1
))
351 t1
= TYPE_PTRMEMFUNC_FN_TYPE (t1
);
352 if (TYPE_PTRMEMFUNC_P (t2
))
353 t2
= TYPE_PTRMEMFUNC_FN_TYPE (t2
);
355 code1
= TREE_CODE (t1
);
356 code2
= TREE_CODE (t2
);
358 /* If one type is complex, form the common type of the non-complex
359 components, then make that complex. Use T1 or T2 if it is the
361 if (code1
== COMPLEX_TYPE
|| code2
== COMPLEX_TYPE
)
363 tree subtype1
= code1
== COMPLEX_TYPE
? TREE_TYPE (t1
) : t1
;
364 tree subtype2
= code2
== COMPLEX_TYPE
? TREE_TYPE (t2
) : t2
;
365 tree subtype
= common_type (subtype1
, subtype2
);
367 if (code1
== COMPLEX_TYPE
&& TREE_TYPE (t1
) == subtype
)
368 return build_type_attribute_variant (t1
, attributes
);
369 else if (code2
== COMPLEX_TYPE
&& TREE_TYPE (t2
) == subtype
)
370 return build_type_attribute_variant (t2
, attributes
);
372 return build_type_attribute_variant (build_complex_type (subtype
),
380 /* If only one is real, use it as the result. */
382 if (code1
== REAL_TYPE
&& code2
!= REAL_TYPE
)
383 return build_type_attribute_variant (t1
, attributes
);
385 if (code2
== REAL_TYPE
&& code1
!= REAL_TYPE
)
386 return build_type_attribute_variant (t2
, attributes
);
388 /* Both real or both integers; use the one with greater precision. */
390 if (TYPE_PRECISION (t1
) > TYPE_PRECISION (t2
))
391 return build_type_attribute_variant (t1
, attributes
);
392 else if (TYPE_PRECISION (t2
) > TYPE_PRECISION (t1
))
393 return build_type_attribute_variant (t2
, attributes
);
395 /* Same precision. Prefer longs to ints even when same size. */
397 if (TYPE_MAIN_VARIANT (t1
) == long_unsigned_type_node
398 || TYPE_MAIN_VARIANT (t2
) == long_unsigned_type_node
)
399 return build_type_attribute_variant (long_unsigned_type_node
,
402 if (TYPE_MAIN_VARIANT (t1
) == long_integer_type_node
403 || TYPE_MAIN_VARIANT (t2
) == long_integer_type_node
)
405 /* But preserve unsignedness from the other type,
406 since long cannot hold all the values of an unsigned int. */
407 if (TREE_UNSIGNED (t1
) || TREE_UNSIGNED (t2
))
408 t1
= long_unsigned_type_node
;
410 t1
= long_integer_type_node
;
411 return build_type_attribute_variant (t1
, attributes
);
414 if (TYPE_MAIN_VARIANT (t1
) == long_double_type_node
415 || TYPE_MAIN_VARIANT (t2
) == long_double_type_node
)
416 return build_type_attribute_variant (long_double_type_node
,
419 /* Otherwise prefer the unsigned one. */
421 if (TREE_UNSIGNED (t1
))
422 return build_type_attribute_variant (t1
, attributes
);
424 return build_type_attribute_variant (t2
, attributes
);
428 /* For two pointers, do this recursively on the target type,
429 and combine the qualifiers of the two types' targets. */
430 /* This code was turned off; I don't know why.
431 But ANSI C++ specifies doing this with the qualifiers.
432 So I turned it on again. */
434 tree tt1
= TYPE_MAIN_VARIANT (TREE_TYPE (t1
));
435 tree tt2
= TYPE_MAIN_VARIANT (TREE_TYPE (t2
));
437 = TYPE_READONLY (TREE_TYPE (t1
)) || TYPE_READONLY (TREE_TYPE (t2
));
439 = TYPE_VOLATILE (TREE_TYPE (t1
)) || TYPE_VOLATILE (TREE_TYPE (t2
));
444 else if (tt1
== void_type_node
|| tt2
== void_type_node
)
445 target
= void_type_node
;
447 target
= common_type (tt1
, tt2
);
449 target
= cp_build_type_variant (target
, constp
, volatilep
);
450 if (code1
== POINTER_TYPE
)
451 t1
= build_pointer_type (target
);
453 t1
= build_reference_type (target
);
454 t1
= build_type_attribute_variant (t1
, attributes
);
456 if (TREE_CODE (target
) == METHOD_TYPE
)
457 t1
= build_ptrmemfunc_type (t1
);
464 tree elt
= common_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
465 /* Save space: see if the result is identical to one of the args. */
466 if (elt
== TREE_TYPE (t1
) && TYPE_DOMAIN (t1
))
467 return build_type_attribute_variant (t1
, attributes
);
468 if (elt
== TREE_TYPE (t2
) && TYPE_DOMAIN (t2
))
469 return build_type_attribute_variant (t2
, attributes
);
470 /* Merge the element types, and have a size if either arg has one. */
471 t1
= build_cplus_array_type
472 (elt
, TYPE_DOMAIN (TYPE_DOMAIN (t1
) ? t1
: t2
));
473 return build_type_attribute_variant (t1
, attributes
);
477 /* Function types: prefer the one that specified arg types.
478 If both do, merge the arg types. Also merge the return types. */
480 tree valtype
= common_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
481 tree p1
= TYPE_ARG_TYPES (t1
);
482 tree p2
= TYPE_ARG_TYPES (t2
);
485 /* Save space: see if the result is identical to one of the args. */
486 if (valtype
== TREE_TYPE (t1
) && ! p2
)
487 return build_type_attribute_variant (t1
, attributes
);
488 if (valtype
== TREE_TYPE (t2
) && ! p1
)
489 return build_type_attribute_variant (t2
, attributes
);
491 /* Simple way if one arg fails to specify argument types. */
492 if (p1
== NULL_TREE
|| TREE_VALUE (p1
) == void_type_node
)
494 rval
= build_function_type (valtype
, p2
);
495 if ((raises
= TYPE_RAISES_EXCEPTIONS (t2
)))
496 rval
= build_exception_variant (rval
, raises
);
497 return build_type_attribute_variant (rval
, attributes
);
499 raises
= TYPE_RAISES_EXCEPTIONS (t1
);
500 if (p2
== NULL_TREE
|| TREE_VALUE (p2
) == void_type_node
)
502 rval
= build_function_type (valtype
, p1
);
504 rval
= build_exception_variant (rval
, raises
);
505 return build_type_attribute_variant (rval
, attributes
);
508 rval
= build_function_type (valtype
, commonparms (p1
, p2
));
509 rval
= build_exception_variant (rval
, raises
);
510 return build_type_attribute_variant (rval
, attributes
);
515 my_friendly_assert (TYPE_MAIN_VARIANT (t1
) == t1
516 && TYPE_MAIN_VARIANT (t2
) == t2
, 306);
518 if (DERIVED_FROM_P (t1
, t2
) && binfo_or_else (t1
, t2
))
519 return build_type_attribute_variant (t1
, attributes
);
520 else if (binfo_or_else (t2
, t1
))
521 return build_type_attribute_variant (t2
, attributes
);
523 compiler_error ("common_type called with uncommon aggregate types");
526 if (TREE_CODE (TREE_TYPE (t1
)) == TREE_CODE (TREE_TYPE (t2
)))
528 /* Get this value the long way, since TYPE_METHOD_BASETYPE
529 is just the main variant of this. */
533 tree b1
= TYPE_OFFSET_BASETYPE (t1
);
534 tree b2
= TYPE_OFFSET_BASETYPE (t2
);
536 if (comptypes (b1
, b2
, 1)
537 || (DERIVED_FROM_P (b1
, b2
) && binfo_or_else (b1
, b2
)))
538 basetype
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t2
)));
541 if (binfo_or_else (b2
, b1
) == NULL_TREE
)
542 compiler_error ("common_type called with uncommon method types");
543 basetype
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t1
)));
546 raises
= TYPE_RAISES_EXCEPTIONS (t1
);
548 /* If this was a member function type, get back to the
549 original type of type member function (i.e., without
550 the class instance variable up front. */
551 t1
= build_function_type (TREE_TYPE (t1
), TREE_CHAIN (TYPE_ARG_TYPES (t1
)));
552 t2
= build_function_type (TREE_TYPE (t2
), TREE_CHAIN (TYPE_ARG_TYPES (t2
)));
553 t3
= common_type (t1
, t2
);
554 t3
= build_cplus_method_type (basetype
, TREE_TYPE (t3
), TYPE_ARG_TYPES (t3
));
555 t1
= build_exception_variant (t3
, raises
);
558 compiler_error ("common_type called with uncommon method types");
560 return build_type_attribute_variant (t1
, attributes
);
563 if (TREE_TYPE (t1
) == TREE_TYPE (t2
))
565 tree b1
= TYPE_OFFSET_BASETYPE (t1
);
566 tree b2
= TYPE_OFFSET_BASETYPE (t2
);
568 if (comptypes (b1
, b2
, 1)
569 || (DERIVED_FROM_P (b1
, b2
) && binfo_or_else (b1
, b2
)))
570 return build_type_attribute_variant (t2
, attributes
);
571 else if (binfo_or_else (b2
, b1
))
572 return build_type_attribute_variant (t1
, attributes
);
574 compiler_error ("common_type called with uncommon member types");
577 return build_type_attribute_variant (t1
, attributes
);
581 /* Return 1 if TYPE1 and TYPE2 raise the same exceptions. */
584 compexcepttypes (t1
, t2
)
587 return TYPE_RAISES_EXCEPTIONS (t1
) == TYPE_RAISES_EXCEPTIONS (t2
);
591 comp_array_types (cmp
, t1
, t2
, strict
)
592 register int (*cmp
)();
596 tree d1
= TYPE_DOMAIN (t1
);
597 tree d2
= TYPE_DOMAIN (t2
);
599 /* Target types must match incl. qualifiers. */
600 if (!(TREE_TYPE (t1
) == TREE_TYPE (t2
)
601 || (*cmp
) (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
)))
604 /* Sizes must match unless one is missing or variable. */
605 if (d1
== 0 || d2
== 0 || d1
== d2
606 || TREE_CODE (TYPE_MIN_VALUE (d1
)) != INTEGER_CST
607 || TREE_CODE (TYPE_MIN_VALUE (d2
)) != INTEGER_CST
608 || TREE_CODE (TYPE_MAX_VALUE (d1
)) != INTEGER_CST
609 || TREE_CODE (TYPE_MAX_VALUE (d2
)) != INTEGER_CST
)
612 return ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1
))
613 == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2
)))
614 && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1
))
615 == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2
)))
616 && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1
))
617 == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2
)))
618 && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1
))
619 == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2
))));
622 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
623 or various other operations. This is what ANSI C++ speaks of as
626 For C++: argument STRICT says we should be strict about this
629 2 : strict, except that if one type is a reference and
630 the other is not, compare the target type of the
631 reference to the type that's not a reference (ARM, p308).
632 This is used for checking for invalid overloading.
633 1 : strict (compared according to ANSI C)
634 This is used for checking whether two function decls match.
635 0 : <= (compared according to C++)
636 -1: <= or >= (relaxed)
638 Otherwise, pointers involving base classes and derived classes
639 can be mixed as valid: i.e. a pointer to a base class may be assigned
640 to a pointer to one of its derived classes, as per C++. A pointer to
641 a derived class may be passed as a parameter to a function expecting a
642 pointer to a base classes. These allowances do not commute. In this
643 case, TYPE1 is assumed to be the base class, and TYPE2 is assumed to
644 be the derived class. */
647 comptypes (type1
, type2
, strict
)
651 register tree t1
= type1
;
652 register tree t2
= type2
;
655 /* Suppress errors caused by previously reported errors */
660 /* This should never happen. */
661 my_friendly_assert (t1
!= error_mark_node
, 307);
663 if (t2
== error_mark_node
)
668 /* Treat an enum type as the unsigned integer type of the same width. */
670 if (TREE_CODE (t1
) == ENUMERAL_TYPE
)
671 t1
= type_for_size (TYPE_PRECISION (t1
), 1);
672 if (TREE_CODE (t2
) == ENUMERAL_TYPE
)
673 t2
= type_for_size (TYPE_PRECISION (t2
), 1);
679 if (TYPE_PTRMEMFUNC_P (t1
))
680 t1
= TYPE_PTRMEMFUNC_FN_TYPE (t1
);
681 if (TYPE_PTRMEMFUNC_P (t2
))
682 t2
= TYPE_PTRMEMFUNC_FN_TYPE (t2
);
684 /* Different classes of types can't be compatible. */
686 if (TREE_CODE (t1
) != TREE_CODE (t2
))
689 && ((TREE_CODE (t1
) == REFERENCE_TYPE
)
690 ^ (TREE_CODE (t2
) == REFERENCE_TYPE
)))
692 if (TREE_CODE (t1
) == REFERENCE_TYPE
)
693 return comptypes (TREE_TYPE (t1
), t2
, 1);
694 return comptypes (t1
, TREE_TYPE (t2
), 1);
702 /* Qualifiers must match. */
704 if (TYPE_READONLY (t1
) != TYPE_READONLY (t2
))
706 if (TYPE_VOLATILE (t1
) != TYPE_VOLATILE (t2
))
709 /* Allow for two different type nodes which have essentially the same
710 definition. Note that we already checked for equality of the type
711 type qualifiers (just above). */
713 if (TYPE_MAIN_VARIANT (t1
) == TYPE_MAIN_VARIANT (t2
))
716 /* ??? COMP_TYPE_ATTRIBUTES is currently useless for variables as each
717 attribute is its own main variant (`val' will remain 0). */
718 #ifndef COMP_TYPE_ATTRIBUTES
719 #define COMP_TYPE_ATTRIBUTES(t1,t2) 1
722 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
723 if (! (attrval
= COMP_TYPE_ATTRIBUTES (t1
, t2
)))
726 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
729 switch (TREE_CODE (t1
))
733 if (CLASSTYPE_TEMPLATE_INFO (t1
) && CLASSTYPE_TEMPLATE_INFO (t2
)
734 && CLASSTYPE_TI_TEMPLATE (t1
) == CLASSTYPE_TI_TEMPLATE (t2
))
736 int i
= TREE_VEC_LENGTH (CLASSTYPE_TI_ARGS (t1
));
737 tree
*p1
= &TREE_VEC_ELT (CLASSTYPE_TI_ARGS (t1
), 0);
738 tree
*p2
= &TREE_VEC_ELT (CLASSTYPE_TI_ARGS (t2
), 0);
742 if (TREE_CODE_CLASS (TREE_CODE (p1
[i
])) == 't')
744 if (! comptypes (p1
[i
], p2
[i
], 1))
749 if (simple_cst_equal (p1
[i
], p2
[i
]) <= 0)
760 val
= (comptypes (build_pointer_type (TYPE_OFFSET_BASETYPE (t1
)),
761 build_pointer_type (TYPE_OFFSET_BASETYPE (t2
)), strict
)
762 && comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
));
766 if (! compexcepttypes (t1
, t2
))
769 /* This case is anti-symmetrical!
770 One can pass a base member (or member function)
771 to something expecting a derived member (or member function),
772 but not vice-versa! */
774 val
= (comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
)
775 && compparms (TYPE_ARG_TYPES (t1
),
776 TYPE_ARG_TYPES (t2
), strict
));
790 if (TREE_CODE (t1
) == RECORD_TYPE
&& TREE_CODE (t2
) == RECORD_TYPE
)
794 rval
= t1
== t2
|| DERIVED_FROM_P (t1
, t2
);
803 val
= DERIVED_FROM_P (t2
, t1
);
810 val
= comptypes (t1
, t2
, strict
);
814 if (! compexcepttypes (t1
, t2
))
817 val
= ((TREE_TYPE (t1
) == TREE_TYPE (t2
)
818 || comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
))
819 && compparms (TYPE_ARG_TYPES (t1
), TYPE_ARG_TYPES (t2
), strict
));
823 /* Target types must match incl. qualifiers. */
824 val
= comp_array_types (comptypes
, t1
, t2
, strict
);
827 case TEMPLATE_TYPE_PARM
:
828 return TEMPLATE_TYPE_IDX (t1
) == TEMPLATE_TYPE_IDX (t2
);
831 if (TYPE_IDENTIFIER (t1
) != TYPE_IDENTIFIER (t2
))
833 return comptypes (TYPE_CONTEXT (t1
), TYPE_CONTEXT (t2
), 1);
835 return attrval
== 2 && val
== 1 ? 2 : val
;
838 /* Return 1 if TTL and TTR are pointers to types that are equivalent,
839 ignoring their qualifiers.
841 NPTRS is the number of pointers we can strip off and keep cool.
842 This is used to permit (for aggr A, aggr B) A, B* to convert to A*,
843 but to not permit B** to convert to A**. */
846 comp_target_types (ttl
, ttr
, nptrs
)
850 ttl
= TYPE_MAIN_VARIANT (ttl
);
851 ttr
= TYPE_MAIN_VARIANT (ttr
);
855 if (TREE_CODE (ttr
) != TREE_CODE (ttl
))
858 if (TREE_CODE (ttr
) == POINTER_TYPE
)
860 ttl
= TREE_TYPE (ttl
);
861 ttr
= TREE_TYPE (ttr
);
865 if (TREE_CODE (ttl
) == VOID_TYPE
866 && TREE_CODE (ttr
) != FUNCTION_TYPE
867 && TREE_CODE (ttr
) != METHOD_TYPE
868 && TREE_CODE (ttr
) != OFFSET_TYPE
)
870 else if (TREE_CODE (ttr
) == VOID_TYPE
871 && TREE_CODE (ttl
) != FUNCTION_TYPE
872 && TREE_CODE (ttl
) != METHOD_TYPE
873 && TREE_CODE (ttl
) != OFFSET_TYPE
)
875 else if (TREE_CODE (ttl
) == POINTER_TYPE
876 || TREE_CODE (ttl
) == ARRAY_TYPE
)
878 if (comp_ptr_ttypes (ttl
, ttr
))
880 else if (comp_ptr_ttypes (ttr
, ttl
))
886 /* Const and volatile mean something different for function types,
887 so the usual checks are not appropriate. */
888 if (TREE_CODE (ttl
) == FUNCTION_TYPE
|| TREE_CODE (ttl
) == METHOD_TYPE
)
889 return comp_target_types (ttl
, ttr
, nptrs
- 1);
891 /* Make sure that the cv-quals change only in the same direction as
895 int c
= TYPE_READONLY (ttl
) - TYPE_READONLY (ttr
);
896 int v
= TYPE_VOLATILE (ttl
) - TYPE_VOLATILE (ttr
);
898 if ((c
> 0 && v
< 0) || (c
< 0 && v
> 0))
901 if (TYPE_MAIN_VARIANT (ttl
) == TYPE_MAIN_VARIANT (ttr
))
902 return (c
+ v
< 0) ? -1 : 1;
904 t
= comp_target_types (ttl
, ttr
, nptrs
- 1);
905 if ((t
== 1 && c
+ v
>= 0) || (t
== -1 && c
+ v
<= 0))
912 if (TREE_CODE (ttr
) == REFERENCE_TYPE
)
913 return comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
);
914 if (TREE_CODE (ttr
) == ARRAY_TYPE
)
915 return comp_array_types (comp_target_types
, ttl
, ttr
, 0);
916 else if (TREE_CODE (ttr
) == FUNCTION_TYPE
|| TREE_CODE (ttr
) == METHOD_TYPE
)
917 if (comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
))
918 switch (comp_target_parms (TYPE_ARG_TYPES (ttl
), TYPE_ARG_TYPES (ttr
), 1))
927 my_friendly_abort (112);
933 else if (TREE_CODE (ttr
) == OFFSET_TYPE
)
935 /* Contravariance: we can assign a pointer to base member to a pointer
936 to derived member. Note difference from simple pointer case, where
937 we can pass a pointer to derived to a pointer to base. */
938 if (comptypes (TYPE_OFFSET_BASETYPE (ttr
), TYPE_OFFSET_BASETYPE (ttl
), 0))
939 return comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
);
940 else if (comptypes (TYPE_OFFSET_BASETYPE (ttl
), TYPE_OFFSET_BASETYPE (ttr
), 0)
941 && comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
))
944 else if (IS_AGGR_TYPE (ttl
))
948 if (comptypes (build_pointer_type (ttl
), build_pointer_type (ttr
), 0))
950 if (comptypes (build_pointer_type (ttr
), build_pointer_type (ttl
), 0))
958 /* If two types share a common base type, return that basetype.
959 If there is not a unique most-derived base type, this function
960 returns ERROR_MARK_NODE. */
963 common_base_type (tt1
, tt2
)
966 tree best
= NULL_TREE
;
969 /* If one is a baseclass of another, that's good enough. */
970 if (UNIQUELY_DERIVED_FROM_P (tt1
, tt2
))
972 if (UNIQUELY_DERIVED_FROM_P (tt2
, tt1
))
975 /* Otherwise, try to find a unique baseclass of TT1
976 that is shared by TT2, and follow that down. */
977 for (i
= CLASSTYPE_N_BASECLASSES (tt1
)-1; i
>= 0; i
--)
979 tree basetype
= TYPE_BINFO_BASETYPE (tt1
, i
);
980 tree trial
= common_base_type (basetype
, tt2
);
983 if (trial
== error_mark_node
)
985 if (best
== NULL_TREE
)
987 else if (best
!= trial
)
988 return error_mark_node
;
993 for (i
= CLASSTYPE_N_BASECLASSES (tt2
)-1; i
>= 0; i
--)
995 tree basetype
= TYPE_BINFO_BASETYPE (tt2
, i
);
996 tree trial
= common_base_type (tt1
, basetype
);
999 if (trial
== error_mark_node
)
1001 if (best
== NULL_TREE
)
1003 else if (best
!= trial
)
1004 return error_mark_node
;
1010 /* Subroutines of `comptypes'. */
1012 /* Return 1 if two parameter type lists PARMS1 and PARMS2
1013 are equivalent in the sense that functions with those parameter types
1014 can have equivalent types.
1015 If either list is empty, we win.
1016 Otherwise, the two lists must be equivalent, element by element.
1018 C++: See comment above about TYPE1, TYPE2, STRICT.
1019 If STRICT == 3, it means checking is strict, but do not compare
1020 default parameter values. */
1023 compparms (parms1
, parms2
, strict
)
1024 tree parms1
, parms2
;
1027 register tree t1
= parms1
, t2
= parms2
;
1029 /* An unspecified parmlist matches any specified parmlist
1030 whose argument types don't need default promotions. */
1032 if (strict
<= 0 && t1
== 0)
1033 return self_promoting_args_p (t2
);
1034 if (strict
< 0 && t2
== 0)
1035 return self_promoting_args_p (t1
);
1039 if (t1
== 0 && t2
== 0)
1041 /* If one parmlist is shorter than the other,
1042 they fail to match, unless STRICT is <= 0. */
1043 if (t1
== 0 || t2
== 0)
1050 return t1
&& TREE_PURPOSE (t1
);
1052 if (! comptypes (TREE_VALUE (t2
), TREE_VALUE (t1
), strict
))
1057 return t2
== void_list_node
&& TREE_PURPOSE (t1
);
1058 return TREE_PURPOSE (t1
) || TREE_PURPOSE (t2
);
1061 t1
= TREE_CHAIN (t1
);
1062 t2
= TREE_CHAIN (t2
);
1066 /* This really wants return whether or not parameter type lists
1067 would make their owning functions assignment compatible or not. */
1070 comp_target_parms (parms1
, parms2
, strict
)
1071 tree parms1
, parms2
;
1074 register tree t1
= parms1
, t2
= parms2
;
1075 int warn_contravariance
= 0;
1077 /* An unspecified parmlist matches any specified parmlist
1078 whose argument types don't need default promotions.
1079 @@@ see 13.3.3 for a counterexample... */
1081 if (t1
== 0 && t2
!= 0)
1083 cp_pedwarn ("ANSI C++ prohibits conversion from `(%#T)' to `(...)'",
1085 return self_promoting_args_p (t2
);
1088 return self_promoting_args_p (t1
);
1090 for (; t1
|| t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
1094 /* If one parmlist is shorter than the other,
1095 they fail to match, unless STRICT is <= 0. */
1096 if (t1
== 0 || t2
== 0)
1101 return 1 + warn_contravariance
;
1102 return ((t1
&& TREE_PURPOSE (t1
)) + warn_contravariance
);
1104 p1
= TREE_VALUE (t1
);
1105 p2
= TREE_VALUE (t2
);
1109 if ((TREE_CODE (p1
) == POINTER_TYPE
&& TREE_CODE (p2
) == POINTER_TYPE
)
1110 || (TREE_CODE (p1
) == REFERENCE_TYPE
&& TREE_CODE (p2
) == REFERENCE_TYPE
))
1113 && (TYPE_MAIN_VARIANT (TREE_TYPE (p1
))
1114 == TYPE_MAIN_VARIANT (TREE_TYPE (p2
))))
1117 /* The following is wrong for contravariance,
1118 but many programs depend on it. */
1119 if (TREE_TYPE (p1
) == void_type_node
)
1121 if (TREE_TYPE (p2
) == void_type_node
)
1123 warn_contravariance
= 1;
1126 if (IS_AGGR_TYPE (TREE_TYPE (p1
)))
1128 if (comptypes (p2
, p1
, 0) == 0)
1130 if (comptypes (p1
, p2
, 0) != 0)
1131 warn_contravariance
= 1;
1138 /* Note backwards order due to contravariance. */
1139 if (comp_target_types (p2
, p1
, 1) == 0)
1141 if (comp_target_types (p1
, p2
, 1))
1143 warn_contravariance
= 1;
1149 /* Target types are compatible--just make sure that if
1150 we use parameter lists, that they are ok as well. */
1151 if (TREE_CODE (p1
) == FUNCTION_TYPE
|| TREE_CODE (p1
) == METHOD_TYPE
)
1152 switch (comp_target_parms (TYPE_ARG_TYPES (p1
),
1153 TYPE_ARG_TYPES (p2
),
1161 warn_contravariance
= 1;
1164 if (TREE_PURPOSE (t1
) && TREE_PURPOSE (t2
))
1166 int cmp
= simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
));
1168 my_friendly_abort (114);
1173 return 1 + warn_contravariance
;
1176 /* Return 1 if PARMS specifies a fixed number of parameters
1177 and none of their types is affected by default promotions. */
1180 self_promoting_args_p (parms
)
1184 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
1186 register tree type
= TREE_VALUE (t
);
1188 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
1194 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
1197 if (C_PROMOTING_INTEGER_TYPE_P (type
))
1203 /* Return an unsigned type the same as TYPE in other respects.
1205 C++: must make these work for type variants as well. */
1208 unsigned_type (type
)
1211 tree type1
= TYPE_MAIN_VARIANT (type
);
1212 if (type1
== signed_char_type_node
|| type1
== char_type_node
)
1213 return unsigned_char_type_node
;
1214 if (type1
== integer_type_node
)
1215 return unsigned_type_node
;
1216 if (type1
== short_integer_type_node
)
1217 return short_unsigned_type_node
;
1218 if (type1
== long_integer_type_node
)
1219 return long_unsigned_type_node
;
1220 if (type1
== long_long_integer_type_node
)
1221 return long_long_unsigned_type_node
;
1222 if (type1
== intDI_type_node
)
1223 return unsigned_intDI_type_node
;
1224 if (type1
== intSI_type_node
)
1225 return unsigned_intSI_type_node
;
1226 if (type1
== intHI_type_node
)
1227 return unsigned_intHI_type_node
;
1228 if (type1
== intQI_type_node
)
1229 return unsigned_intQI_type_node
;
1231 return signed_or_unsigned_type (1, type
);
1234 /* Return a signed type the same as TYPE in other respects. */
1240 tree type1
= TYPE_MAIN_VARIANT (type
);
1241 if (type1
== unsigned_char_type_node
|| type1
== char_type_node
)
1242 return signed_char_type_node
;
1243 if (type1
== unsigned_type_node
)
1244 return integer_type_node
;
1245 if (type1
== short_unsigned_type_node
)
1246 return short_integer_type_node
;
1247 if (type1
== long_unsigned_type_node
)
1248 return long_integer_type_node
;
1249 if (type1
== long_long_unsigned_type_node
)
1250 return long_long_integer_type_node
;
1251 if (type1
== unsigned_intDI_type_node
)
1252 return intDI_type_node
;
1253 if (type1
== unsigned_intSI_type_node
)
1254 return intSI_type_node
;
1255 if (type1
== unsigned_intHI_type_node
)
1256 return intHI_type_node
;
1257 if (type1
== unsigned_intQI_type_node
)
1258 return intQI_type_node
;
1260 return signed_or_unsigned_type (0, type
);
1263 /* Return a type the same as TYPE except unsigned or
1264 signed according to UNSIGNEDP. */
1267 signed_or_unsigned_type (unsignedp
, type
)
1271 if (! INTEGRAL_TYPE_P (type
)
1272 || TREE_UNSIGNED (type
) == unsignedp
)
1275 if (TYPE_PRECISION (type
) == TYPE_PRECISION (signed_char_type_node
))
1276 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
1277 if (TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
))
1278 return unsignedp
? unsigned_type_node
: integer_type_node
;
1279 if (TYPE_PRECISION (type
) == TYPE_PRECISION (short_integer_type_node
))
1280 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
1281 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_integer_type_node
))
1282 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
1283 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_long_integer_type_node
))
1284 return (unsignedp
? long_long_unsigned_type_node
1285 : long_long_integer_type_node
);
1289 /* Compute the value of the `sizeof' operator. */
1295 enum tree_code code
= TREE_CODE (type
);
1298 if (processing_template_decl
)
1299 return build_min (SIZEOF_EXPR
, sizetype
, type
);
1301 if (code
== FUNCTION_TYPE
)
1303 if (pedantic
|| warn_pointer_arith
)
1304 pedwarn ("ANSI C++ forbids taking the sizeof a function type");
1305 return size_int (1);
1307 if (code
== METHOD_TYPE
)
1309 if (pedantic
|| warn_pointer_arith
)
1310 pedwarn ("ANSI C++ forbids taking the sizeof a method type");
1311 return size_int (1);
1313 if (code
== VOID_TYPE
)
1315 if (pedantic
|| warn_pointer_arith
)
1316 pedwarn ("ANSI C++ forbids taking the sizeof a void type");
1317 return size_int (1);
1319 if (code
== ERROR_MARK
)
1320 return size_int (1);
1322 /* ARM $5.3.2: ``When applied to a reference, the result is the size of the
1323 referenced object.'' */
1324 if (code
== REFERENCE_TYPE
)
1325 type
= TREE_TYPE (type
);
1327 /* We couldn't find anything in the ARM or the draft standard that says,
1328 one way or the other, if doing sizeof on something that doesn't have
1329 an object associated with it is correct or incorrect. For example, if
1330 you declare `struct S { char str[16]; };', and in your program do
1331 a `sizeof (S::str)', should we flag that as an error or should we give
1332 the size of it? Since it seems like a reasonable thing to do, we'll go
1333 with giving the value. */
1334 if (code
== OFFSET_TYPE
)
1335 type
= TREE_TYPE (type
);
1337 /* @@ This also produces an error for a signature ref.
1338 In that case we should be able to do better. */
1339 if (IS_SIGNATURE (type
))
1341 error ("`sizeof' applied to a signature type");
1342 return size_int (0);
1345 if (TYPE_SIZE (complete_type (type
)) == 0)
1347 cp_error ("`sizeof' applied to incomplete type `%T'", type
);
1348 return size_int (0);
1351 /* Convert in case a char is more than one unit. */
1352 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
1353 size_int (TYPE_PRECISION (char_type_node
)));
1354 /* size_binop does not put the constant in range, so do it now. */
1355 if (TREE_CODE (t
) == INTEGER_CST
&& force_fit_type (t
, 0))
1356 TREE_CONSTANT_OVERFLOW (t
) = TREE_OVERFLOW (t
) = 1;
1364 if (processing_template_decl
)
1365 return build_min (SIZEOF_EXPR
, sizetype
, e
);
1367 if (TREE_CODE (e
) == COMPONENT_REF
1368 && DECL_BIT_FIELD (TREE_OPERAND (e
, 1)))
1369 error ("sizeof applied to a bit-field");
1370 /* ANSI says arrays and functions are converted inside comma.
1371 But we can't really convert them in build_compound_expr
1372 because that would break commas in lvalues.
1373 So do the conversion here if operand was a comma. */
1374 if (TREE_CODE (e
) == COMPOUND_EXPR
1375 && (TREE_CODE (TREE_TYPE (e
)) == ARRAY_TYPE
1376 || TREE_CODE (TREE_TYPE (e
)) == FUNCTION_TYPE
))
1377 e
= default_conversion (e
);
1378 else if (TREE_CODE (e
) == TREE_LIST
)
1380 tree t
= TREE_VALUE (e
);
1383 && TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
1384 || is_overloaded_fn (t
)))
1385 pedwarn ("ANSI C++ forbids taking the sizeof a function type");
1387 return c_sizeof (TREE_TYPE (e
));
1391 c_sizeof_nowarn (type
)
1394 enum tree_code code
= TREE_CODE (type
);
1397 if (code
== FUNCTION_TYPE
1398 || code
== METHOD_TYPE
1399 || code
== VOID_TYPE
1400 || code
== ERROR_MARK
)
1401 return size_int (1);
1402 if (code
== REFERENCE_TYPE
)
1403 type
= TREE_TYPE (type
);
1405 if (TYPE_SIZE (type
) == 0)
1406 return size_int (0);
1408 /* Convert in case a char is more than one unit. */
1409 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
1410 size_int (TYPE_PRECISION (char_type_node
)));
1411 force_fit_type (t
, 0);
1415 /* Implement the __alignof keyword: Return the minimum required
1416 alignment of TYPE, measured in bytes. */
1422 enum tree_code code
= TREE_CODE (type
);
1425 if (code
== FUNCTION_TYPE
|| code
== METHOD_TYPE
)
1426 return size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
1428 if (code
== VOID_TYPE
|| code
== ERROR_MARK
)
1429 return size_int (1);
1431 /* C++: this is really correct! */
1432 if (code
== REFERENCE_TYPE
)
1433 type
= TREE_TYPE (type
);
1435 /* @@ This also produces an error for a signature ref.
1436 In that case we should be able to do better. */
1437 if (IS_SIGNATURE (type
))
1439 error ("`__alignof' applied to a signature type");
1440 return size_int (1);
1443 t
= size_int (TYPE_ALIGN (type
) / BITS_PER_UNIT
);
1444 force_fit_type (t
, 0);
1448 /* Perform default promotions for C data used in expressions.
1449 Arrays and functions are converted to pointers;
1450 enumeral types or short or char, to int.
1451 In addition, manifest constants symbols are replaced by their values.
1453 C++: this will automatically bash references to their target type. */
1456 decay_conversion (exp
)
1459 register tree type
= TREE_TYPE (exp
);
1460 register enum tree_code code
= TREE_CODE (type
);
1462 if (code
== OFFSET_TYPE
)
1464 if (TREE_CODE (exp
) == OFFSET_REF
)
1465 return decay_conversion (resolve_offset_ref (exp
));
1467 type
= TREE_TYPE (type
);
1468 code
= TREE_CODE (type
);
1470 if (type
== unknown_type_node
)
1472 cp_pedwarn ("assuming & on overloaded member function");
1473 return build_unary_op (ADDR_EXPR
, exp
, 0);
1477 if (code
== REFERENCE_TYPE
)
1479 exp
= convert_from_reference (exp
);
1480 type
= TREE_TYPE (exp
);
1481 code
= TREE_CODE (type
);
1484 /* Constants can be used directly unless they're not loadable. */
1485 if (TREE_CODE (exp
) == CONST_DECL
)
1486 exp
= DECL_INITIAL (exp
);
1487 /* Replace a nonvolatile const static variable with its value. */
1488 else if (TREE_READONLY_DECL_P (exp
))
1490 exp
= decl_constant_value (exp
);
1491 type
= TREE_TYPE (exp
);
1494 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
1495 Leave such NOP_EXPRs, since RHS is being used in non-lvalue context. */
1497 if (code
== VOID_TYPE
)
1499 error ("void value not ignored as it ought to be");
1500 return error_mark_node
;
1502 if (code
== FUNCTION_TYPE
)
1504 return build_unary_op (ADDR_EXPR
, exp
, 0);
1506 if (code
== METHOD_TYPE
)
1508 cp_pedwarn ("assuming & on `%E'", exp
);
1509 return build_unary_op (ADDR_EXPR
, exp
, 0);
1511 if (code
== ARRAY_TYPE
)
1516 int constp
, volatilep
;
1518 if (TREE_CODE (exp
) == INDIRECT_REF
)
1520 /* Stripping away the INDIRECT_REF is not the right
1521 thing to do for references... */
1522 tree inner
= TREE_OPERAND (exp
, 0);
1523 if (TREE_CODE (TREE_TYPE (inner
)) == REFERENCE_TYPE
)
1525 inner
= build1 (CONVERT_EXPR
,
1526 build_pointer_type (TREE_TYPE (TREE_TYPE (inner
))),
1528 TREE_CONSTANT (inner
) = TREE_CONSTANT (TREE_OPERAND (inner
, 0));
1530 return cp_convert (build_pointer_type (TREE_TYPE (type
)), inner
);
1533 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
1535 tree op1
= decay_conversion (TREE_OPERAND (exp
, 1));
1536 return build (COMPOUND_EXPR
, TREE_TYPE (op1
),
1537 TREE_OPERAND (exp
, 0), op1
);
1541 && ! (TREE_CODE (exp
) == CONSTRUCTOR
&& TREE_STATIC (exp
)))
1543 error ("invalid use of non-lvalue array");
1544 return error_mark_node
;
1547 constp
= volatilep
= 0;
1548 if (TREE_CODE_CLASS (TREE_CODE (exp
)) == 'r'
1549 || TREE_CODE_CLASS (TREE_CODE (exp
)) == 'd')
1551 constp
= TREE_READONLY (exp
);
1552 volatilep
= TREE_THIS_VOLATILE (exp
);
1555 restype
= TREE_TYPE (type
);
1556 if (TYPE_READONLY (type
) || TYPE_VOLATILE (type
)
1557 || constp
|| volatilep
)
1558 restype
= cp_build_type_variant (restype
,
1559 TYPE_READONLY (type
) || constp
,
1560 TYPE_VOLATILE (type
) || volatilep
);
1561 ptrtype
= build_pointer_type (restype
);
1563 if (TREE_CODE (exp
) == VAR_DECL
)
1565 /* ??? This is not really quite correct
1566 in that the type of the operand of ADDR_EXPR
1567 is not the target type of the type of the ADDR_EXPR itself.
1568 Question is, can this lossage be avoided? */
1569 adr
= build1 (ADDR_EXPR
, ptrtype
, exp
);
1570 if (mark_addressable (exp
) == 0)
1571 return error_mark_node
;
1572 TREE_CONSTANT (adr
) = staticp (exp
);
1573 TREE_SIDE_EFFECTS (adr
) = 0; /* Default would be, same as EXP. */
1576 /* This way is better for a COMPONENT_REF since it can
1577 simplify the offset for a component. */
1578 adr
= build_unary_op (ADDR_EXPR
, exp
, 1);
1579 return cp_convert (ptrtype
, adr
);
1586 default_conversion (exp
)
1590 enum tree_code code
;
1592 exp
= decay_conversion (exp
);
1594 type
= TREE_TYPE (exp
);
1595 code
= TREE_CODE (type
);
1597 if (INTEGRAL_CODE_P (code
))
1599 tree t
= type_promotes_to (type
);
1601 return cp_convert (t
, exp
);
1607 /* Take the address of an inline function without setting TREE_ADDRESSABLE
1611 inline_conversion (exp
)
1614 if (TREE_CODE (exp
) == FUNCTION_DECL
)
1616 tree type
= build_type_variant
1617 (TREE_TYPE (exp
), TREE_READONLY (exp
), TREE_THIS_VOLATILE (exp
));
1618 exp
= build1 (ADDR_EXPR
, build_pointer_type (type
), exp
);
1624 build_object_ref (datum
, basetype
, field
)
1625 tree datum
, basetype
, field
;
1628 if (datum
== error_mark_node
)
1629 return error_mark_node
;
1631 dtype
= TREE_TYPE (datum
);
1632 if (TREE_CODE (dtype
) == REFERENCE_TYPE
)
1633 dtype
= TREE_TYPE (dtype
);
1634 if (! IS_AGGR_TYPE_CODE (TREE_CODE (dtype
)))
1636 cp_error ("request for member `%T::%D' in expression of non-aggregate type `%T'",
1637 basetype
, field
, dtype
);
1638 return error_mark_node
;
1640 else if (IS_SIGNATURE (basetype
))
1642 warning ("signature name in scope resolution ignored");
1643 return build_component_ref (datum
, field
, NULL_TREE
, 1);
1645 else if (is_aggr_type (basetype
, 1))
1647 tree binfo
= binfo_or_else (basetype
, dtype
);
1649 return build_x_component_ref (build_scoped_ref (datum
, basetype
),
1652 return error_mark_node
;
1655 /* Like `build_component_ref, but uses an already found field.
1656 Must compute access for current_class_ref. Otherwise, ok. */
1659 build_component_ref_1 (datum
, field
, protect
)
1663 return build_component_ref (datum
, field
, NULL_TREE
, protect
);
1666 /* Given a COND_EXPR in T, return it in a form that we can, for
1667 example, use as an lvalue. This code used to be in unary_complex_lvalue,
1668 but we needed it to deal with `a = (d == c) ? b : c' expressions, where
1669 we're dealing with aggregates. So, we now call this in unary_complex_lvalue,
1670 and in build_modify_expr. The case (in particular) that led to this was
1671 with CODE == ADDR_EXPR, since it's not an lvalue when we'd get it there. */
1674 rationalize_conditional_expr (code
, t
)
1675 enum tree_code code
;
1679 build_conditional_expr (TREE_OPERAND (t
, 0),
1680 build_unary_op (code
, TREE_OPERAND (t
, 1), 0),
1681 build_unary_op (code
, TREE_OPERAND (t
, 2), 0));
1684 /* Given the TYPE of an anonymous union field inside T, return the
1685 FIELD_DECL for the field. If not found return NULL_TREE. Because
1686 anonymous unions can nest, we must also search all anonymous unions
1687 that are directly reachable. */
1690 lookup_anon_field (t
, type
)
1695 for (field
= TYPE_FIELDS (t
); field
; field
= TREE_CHAIN (field
))
1697 if (TREE_STATIC (field
))
1699 if (TREE_CODE (field
) != FIELD_DECL
)
1702 /* If we find it directly, return the field. */
1703 if (DECL_NAME (field
) == NULL_TREE
1704 && type
== TREE_TYPE (field
))
1709 /* Otherwise, it could be nested, search harder. */
1710 if (DECL_NAME (field
) == NULL_TREE
1711 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
1713 tree subfield
= lookup_anon_field (TREE_TYPE (field
), type
);
1721 /* Build a COMPONENT_REF for a given DATUM, and it's member COMPONENT.
1722 COMPONENT can be an IDENTIFIER_NODE that is the name of the member
1723 that we are interested in, or it can be a FIELD_DECL. */
1726 build_component_ref (datum
, component
, basetype_path
, protect
)
1727 tree datum
, component
, basetype_path
;
1730 register tree basetype
= TREE_TYPE (datum
);
1731 register enum tree_code code
;
1732 register tree field
= NULL
;
1735 if (processing_template_decl
)
1736 return build_min_nt (COMPONENT_REF
, datum
, component
);
1738 /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference
1740 switch (TREE_CODE (datum
))
1744 tree value
= build_component_ref (TREE_OPERAND (datum
, 1), component
,
1745 basetype_path
, protect
);
1746 return build (COMPOUND_EXPR
, TREE_TYPE (value
),
1747 TREE_OPERAND (datum
, 0), value
);
1750 return build_conditional_expr
1751 (TREE_OPERAND (datum
, 0),
1752 build_component_ref (TREE_OPERAND (datum
, 1), component
,
1753 basetype_path
, protect
),
1754 build_component_ref (TREE_OPERAND (datum
, 2), component
,
1755 basetype_path
, protect
));
1758 code
= TREE_CODE (basetype
);
1760 if (code
== REFERENCE_TYPE
)
1762 datum
= convert_from_reference (datum
);
1763 basetype
= TREE_TYPE (datum
);
1764 code
= TREE_CODE (basetype
);
1766 if (TREE_CODE (datum
) == OFFSET_REF
)
1768 datum
= resolve_offset_ref (datum
);
1769 basetype
= TREE_TYPE (datum
);
1770 code
= TREE_CODE (basetype
);
1773 /* First, see if there is a field or component with name COMPONENT. */
1774 if (TREE_CODE (component
) == TREE_LIST
)
1776 my_friendly_assert (!(TREE_CHAIN (component
) == NULL_TREE
1777 && DECL_CHAIN (TREE_VALUE (component
)) == NULL_TREE
), 309);
1778 return build (COMPONENT_REF
, TREE_TYPE (component
), datum
, component
);
1781 if (! IS_AGGR_TYPE_CODE (code
))
1783 if (code
!= ERROR_MARK
)
1784 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
1785 component
, datum
, basetype
);
1786 return error_mark_node
;
1789 if (TYPE_SIZE (complete_type (basetype
)) == 0)
1791 incomplete_type_error (0, basetype
);
1792 return error_mark_node
;
1795 if (TREE_CODE (component
) == BIT_NOT_EXPR
)
1797 if (TYPE_IDENTIFIER (basetype
) != TREE_OPERAND (component
, 0))
1799 cp_error ("destructor specifier `%T::~%T' must have matching names",
1800 basetype
, TREE_OPERAND (component
, 0));
1801 return error_mark_node
;
1803 if (! TYPE_HAS_DESTRUCTOR (basetype
))
1805 cp_error ("type `%T' has no destructor", basetype
);
1806 return error_mark_node
;
1808 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype
), 1);
1811 /* Look up component name in the structure type definition. */
1812 if (CLASSTYPE_VFIELD (basetype
)
1813 && DECL_NAME (CLASSTYPE_VFIELD (basetype
)) == component
)
1814 /* Special-case this because if we use normal lookups in an ambiguous
1815 hierarchy, the compiler will abort (because vptr lookups are
1816 not supposed to be ambiguous. */
1817 field
= CLASSTYPE_VFIELD (basetype
);
1818 else if (TREE_CODE (component
) == FIELD_DECL
1819 || TREE_CODE (component
) == TYPE_DECL
)
1825 tree name
= component
;
1826 if (TREE_CODE (component
) == VAR_DECL
)
1827 name
= DECL_NAME (component
);
1828 if (basetype_path
== NULL_TREE
)
1829 basetype_path
= TYPE_BINFO (basetype
);
1830 field
= lookup_field (basetype_path
, name
,
1831 protect
&& !VFIELD_NAME_P (name
), 0);
1832 if (field
== error_mark_node
)
1833 return error_mark_node
;
1835 if (field
== NULL_TREE
)
1837 /* Not found as a data field, look for it as a method. If found,
1838 then if this is the only possible one, return it, else
1839 report ambiguity error. */
1840 tree fndecls
= lookup_fnfields (basetype_path
, name
, 1);
1841 if (fndecls
== error_mark_node
)
1842 return error_mark_node
;
1845 if (TREE_CHAIN (fndecls
) == NULL_TREE
1846 && DECL_CHAIN (TREE_VALUE (fndecls
)) == NULL_TREE
)
1848 tree access
, fndecl
;
1850 /* Unique, so use this one now. */
1851 basetype
= TREE_PURPOSE (fndecls
);
1852 fndecl
= TREE_VALUE (fndecls
);
1853 access
= compute_access (TREE_PURPOSE (fndecls
), fndecl
);
1854 if (access
== access_public_node
)
1856 if (DECL_VINDEX (fndecl
)
1857 && ! resolves_to_fixed_type_p (datum
, 0))
1859 tree addr
= build_unary_op (ADDR_EXPR
, datum
, 0);
1860 tree fntype
= TREE_TYPE (fndecl
);
1862 addr
= convert_pointer_to (DECL_CONTEXT (fndecl
), addr
);
1863 datum
= build_indirect_ref (addr
, NULL_PTR
);
1864 my_friendly_assert (datum
!= error_mark_node
, 310);
1865 fndecl
= build_vfn_ref (&addr
, datum
, DECL_VINDEX (fndecl
));
1866 TREE_TYPE (fndecl
) = build_pointer_type (fntype
);
1870 return build (OFFSET_REF
, TREE_TYPE (fndecl
), datum
, fndecl
);
1872 if (access
== access_protected_node
)
1873 cp_error ("member function `%D' is protected", fndecl
);
1875 cp_error ("member function `%D' is private", fndecl
);
1876 return error_mark_node
;
1880 /* Just act like build_offset_ref, since the object does
1881 not matter unless we're actually calling the function. */
1884 t
= build_tree_list (error_mark_node
, fndecls
);
1885 TREE_TYPE (t
) = build_offset_type (basetype
,
1891 cp_error ("`%#T' has no member named `%D'", basetype
, name
);
1892 return error_mark_node
;
1894 else if (TREE_TYPE (field
) == error_mark_node
)
1895 return error_mark_node
;
1897 if (TREE_CODE (field
) != FIELD_DECL
)
1899 if (TREE_CODE (field
) == TYPE_DECL
)
1901 cp_error ("invalid use of type decl `%#D' as expression", field
);
1902 return error_mark_node
;
1904 else if (DECL_RTL (field
) != 0)
1907 TREE_USED (field
) = 1;
1912 /* See if we have to do any conversions so that we pick up the field from the
1914 if (DECL_FIELD_CONTEXT (field
) != basetype
)
1916 tree context
= DECL_FIELD_CONTEXT (field
);
1917 tree base
= context
;
1918 while (base
!= basetype
&& TYPE_NAME (base
)
1919 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (base
)))
1921 base
= TYPE_CONTEXT (base
);
1924 /* Handle base classes here... */
1925 if (base
!= basetype
&& TYPE_USES_COMPLEX_INHERITANCE (basetype
))
1927 tree addr
= build_unary_op (ADDR_EXPR
, datum
, 0);
1928 if (integer_zerop (addr
))
1930 error ("invalid reference to NULL ptr, use ptr-to-member instead");
1931 return error_mark_node
;
1933 if (VBASE_NAME_P (DECL_NAME (field
)))
1935 /* It doesn't matter which vbase pointer we grab, just
1936 find one of them. */
1937 tree binfo
= get_binfo (base
,
1938 TREE_TYPE (TREE_TYPE (addr
)), 0);
1939 addr
= convert_pointer_to_real (binfo
, addr
);
1942 addr
= convert_pointer_to (base
, addr
);
1943 datum
= build_indirect_ref (addr
, NULL_PTR
);
1944 my_friendly_assert (datum
!= error_mark_node
, 311);
1948 /* Handle things from anon unions here... */
1949 if (TYPE_NAME (context
) && ANON_AGGRNAME_P (TYPE_IDENTIFIER (context
)))
1951 tree subfield
= lookup_anon_field (basetype
, context
);
1952 tree subdatum
= build_component_ref (datum
, subfield
,
1953 basetype_path
, protect
);
1954 return build_component_ref (subdatum
, field
, basetype_path
, protect
);
1958 ref
= fold (build (COMPONENT_REF
, TREE_TYPE (field
),
1959 break_out_cleanups (datum
), field
));
1961 if (TREE_READONLY (datum
) || TREE_READONLY (field
))
1962 TREE_READONLY (ref
) = 1;
1963 if (TREE_THIS_VOLATILE (datum
) || TREE_THIS_VOLATILE (field
))
1964 TREE_THIS_VOLATILE (ref
) = 1;
1965 if (DECL_MUTABLE_P (field
))
1966 TREE_READONLY (ref
) = 0;
1971 /* Variant of build_component_ref for use in expressions, which should
1972 never have REFERENCE_TYPE. */
1975 build_x_component_ref (datum
, component
, basetype_path
, protect
)
1976 tree datum
, component
, basetype_path
;
1979 tree t
= build_component_ref (datum
, component
, basetype_path
, protect
);
1981 if (! processing_template_decl
)
1982 t
= convert_from_reference (t
);
1987 /* Given an expression PTR for a pointer, return an expression
1988 for the value pointed to.
1989 ERRORSTRING is the name of the operator to appear in error messages.
1991 This function may need to overload OPERATOR_FNNAME.
1992 Must also handle REFERENCE_TYPEs for C++. */
1995 build_x_indirect_ref (ptr
, errorstring
)
2001 if (processing_template_decl
)
2002 return build_min_nt (INDIRECT_REF
, ptr
);
2004 rval
= build_opfncall (INDIRECT_REF
, LOOKUP_NORMAL
, ptr
, NULL_TREE
, NULL_TREE
);
2007 return build_indirect_ref (ptr
, errorstring
);
2011 build_indirect_ref (ptr
, errorstring
)
2015 register tree pointer
, type
;
2017 if (ptr
== error_mark_node
)
2018 return error_mark_node
;
2020 pointer
= (TREE_CODE (TREE_TYPE (ptr
)) == REFERENCE_TYPE
2021 ? ptr
: default_conversion (ptr
));
2022 type
= TREE_TYPE (pointer
);
2024 if (ptr
== current_class_ptr
)
2025 return current_class_ref
;
2027 if (IS_AGGR_TYPE (type
))
2029 ptr
= build_expr_type_conversion (WANT_POINTER
, pointer
, 1);
2034 type
= TREE_TYPE (pointer
);
2038 if (TREE_CODE (type
) == POINTER_TYPE
|| TREE_CODE (type
) == REFERENCE_TYPE
)
2040 if (TREE_CODE (pointer
) == ADDR_EXPR
2041 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (pointer
, 0)))
2042 == TYPE_MAIN_VARIANT (TREE_TYPE (type
)))
2043 && (TREE_READONLY (TREE_OPERAND (pointer
, 0))
2044 == TYPE_READONLY (TREE_TYPE (type
)))
2045 && (TREE_THIS_VOLATILE (TREE_OPERAND (pointer
, 0))
2046 == TYPE_VOLATILE (TREE_TYPE (type
))))
2047 return TREE_OPERAND (pointer
, 0);
2050 tree t
= TREE_TYPE (type
);
2051 register tree ref
= build1 (INDIRECT_REF
,
2052 TYPE_MAIN_VARIANT (t
), pointer
);
2054 TREE_READONLY (ref
) = TYPE_READONLY (t
);
2055 TREE_THIS_VOLATILE (ref
) = TYPE_VOLATILE (t
);
2056 TREE_SIDE_EFFECTS (ref
)
2057 = TYPE_VOLATILE (t
) || TREE_SIDE_EFFECTS (pointer
);
2061 /* `pointer' won't be an error_mark_node if we were given a
2062 pointer to member, so it's cool to check for this here. */
2063 else if (TYPE_PTRMEMFUNC_P (type
))
2064 error ("invalid use of `%s' on pointer to member function", errorstring
);
2065 else if (TREE_CODE (type
) == RECORD_TYPE
2066 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
)))
2067 error ("cannot dereference signature pointer/reference");
2068 else if (pointer
!= error_mark_node
)
2071 error ("invalid type argument of `%s'", errorstring
);
2073 error ("invalid type argument");
2075 return error_mark_node
;
2078 /* This handles expressions of the form "a[i]", which denotes
2081 This is logically equivalent in C to *(a+i), but we may do it differently.
2082 If A is a variable or a member, we generate a primitive ARRAY_REF.
2083 This avoids forcing the array out of registers, and can work on
2084 arrays that are not lvalues (for example, members of structures returned
2087 If INDEX is of some user-defined type, it must be converted to
2088 integer type. Otherwise, to make a compatible PLUS_EXPR, it
2089 will inherit the type of the array, which will be some pointer type. */
2092 build_array_ref (array
, idx
)
2097 error ("subscript missing in array reference");
2098 return error_mark_node
;
2101 if (TREE_TYPE (array
) == error_mark_node
2102 || TREE_TYPE (idx
) == error_mark_node
)
2103 return error_mark_node
;
2105 if (TREE_CODE (TREE_TYPE (array
)) == ARRAY_TYPE
2106 && TREE_CODE (array
) != INDIRECT_REF
)
2110 /* Subscripting with type char is likely to lose
2111 on a machine where chars are signed.
2112 So warn on any machine, but optionally.
2113 Don't warn for unsigned char since that type is safe.
2114 Don't warn for signed char because anyone who uses that
2115 must have done so deliberately. */
2116 if (warn_char_subscripts
2117 && TYPE_MAIN_VARIANT (TREE_TYPE (idx
)) == char_type_node
)
2118 warning ("array subscript has type `char'");
2120 /* Apply default promotions *after* noticing character types. */
2121 idx
= default_conversion (idx
);
2123 if (TREE_CODE (TREE_TYPE (idx
)) != INTEGER_TYPE
)
2125 error ("array subscript is not an integer");
2126 return error_mark_node
;
2129 /* An array that is indexed by a non-constant
2130 cannot be stored in a register; we must be able to do
2131 address arithmetic on its address.
2132 Likewise an array of elements of variable size. */
2133 if (TREE_CODE (idx
) != INTEGER_CST
2134 || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
))) != 0
2135 && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
)))) != INTEGER_CST
))
2137 if (mark_addressable (array
) == 0)
2138 return error_mark_node
;
2140 /* An array that is indexed by a constant value which is not within
2141 the array bounds cannot be stored in a register either; because we
2142 would get a crash in store_bit_field/extract_bit_field when trying
2143 to access a non-existent part of the register. */
2144 if (TREE_CODE (idx
) == INTEGER_CST
2145 && TYPE_VALUES (TREE_TYPE (array
))
2146 && ! int_fits_type_p (idx
, TYPE_VALUES (TREE_TYPE (array
))))
2148 if (mark_addressable (array
) == 0)
2149 return error_mark_node
;
2152 if (pedantic
&& !lvalue_p (array
))
2153 pedwarn ("ANSI C++ forbids subscripting non-lvalue array");
2155 /* Note in C++ it is valid to subscript a `register' array, since
2156 it is valid to take the address of something with that
2157 storage specification. */
2161 while (TREE_CODE (foo
) == COMPONENT_REF
)
2162 foo
= TREE_OPERAND (foo
, 0);
2163 if (TREE_CODE (foo
) == VAR_DECL
&& DECL_REGISTER (foo
))
2164 warning ("subscripting array declared `register'");
2167 type
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array
)));
2168 rval
= build (ARRAY_REF
, type
, array
, idx
);
2169 /* Array ref is const/volatile if the array elements are
2170 or if the array is.. */
2171 TREE_READONLY (rval
)
2172 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array
)))
2173 | TREE_READONLY (array
));
2174 TREE_SIDE_EFFECTS (rval
)
2175 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
2176 | TREE_SIDE_EFFECTS (array
));
2177 TREE_THIS_VOLATILE (rval
)
2178 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
2179 /* This was added by rms on 16 Nov 91.
2180 It fixes vol struct foo *a; a->elts[1]
2181 in an inline function.
2182 Hope it doesn't break something else. */
2183 | TREE_THIS_VOLATILE (array
));
2184 return require_complete_type (fold (rval
));
2188 tree ar
= default_conversion (array
);
2189 tree ind
= default_conversion (idx
);
2191 /* Put the integer in IND to simplify error checking. */
2192 if (TREE_CODE (TREE_TYPE (ar
)) == INTEGER_TYPE
)
2199 if (ar
== error_mark_node
)
2202 if (TREE_CODE (TREE_TYPE (ar
)) != POINTER_TYPE
)
2204 error ("subscripted value is neither array nor pointer");
2205 return error_mark_node
;
2207 if (TREE_CODE (TREE_TYPE (ind
)) != INTEGER_TYPE
)
2209 error ("array subscript is not an integer");
2210 return error_mark_node
;
2213 return build_indirect_ref (build_binary_op_nodefault (PLUS_EXPR
, ar
, ind
, PLUS_EXPR
),
2218 /* Build a function call to function FUNCTION with parameters PARAMS.
2219 PARAMS is a list--a chain of TREE_LIST nodes--in which the
2220 TREE_VALUE of each node is a parameter-expression. The PARAMS do
2221 not include any object pointer that may be required. FUNCTION's
2222 data type may be a function type or a pointer-to-function.
2224 For C++: If FUNCTION's data type is a TREE_LIST, then the tree list
2225 is the list of possible methods that FUNCTION could conceivably
2226 be. If the list of methods comes from a class, then it will be
2227 a list of lists (where each element is associated with the class
2228 that produced it), otherwise it will be a simple list (for
2229 functions overloaded in global scope).
2231 In the first case, TREE_VALUE (function) is the head of one of those
2232 lists, and TREE_PURPOSE is the name of the function.
2234 In the second case, TREE_PURPOSE (function) is the function's
2237 DECL is the class instance variable, usually CURRENT_CLASS_REF.
2239 When calling a TEMPLATE_DECL, we don't require a complete return
2243 build_x_function_call (function
, params
, decl
)
2244 tree function
, params
, decl
;
2249 if (function
== error_mark_node
)
2250 return error_mark_node
;
2252 if (processing_template_decl
)
2253 return build_min_nt (CALL_EXPR
, function
, params
, NULL_TREE
);
2255 type
= TREE_TYPE (function
);
2257 if (TREE_CODE (type
) == OFFSET_TYPE
2258 && TREE_TYPE (type
) == unknown_type_node
2259 && TREE_CODE (function
) == TREE_LIST
2260 && TREE_CHAIN (function
) == NULL_TREE
)
2262 /* Undo (Foo:bar)()... */
2263 type
= TYPE_OFFSET_BASETYPE (type
);
2264 function
= TREE_VALUE (function
);
2265 my_friendly_assert (TREE_CODE (function
) == TREE_LIST
, 999);
2266 my_friendly_assert (TREE_CHAIN (function
) == NULL_TREE
, 999);
2267 function
= TREE_VALUE (function
);
2268 my_friendly_assert (TREE_CODE (function
) == FUNCTION_DECL
, 999);
2269 function
= DECL_NAME (function
);
2270 return build_method_call (decl
, function
, params
, TYPE_BINFO (type
), LOOKUP_NORMAL
);
2273 is_method
= ((TREE_CODE (function
) == TREE_LIST
2274 && current_class_type
!= NULL_TREE
2275 && IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (function
)) == function
)
2276 || TREE_CODE (function
) == IDENTIFIER_NODE
2277 || TREE_CODE (type
) == METHOD_TYPE
2278 || TYPE_PTRMEMFUNC_P (type
));
2280 if (TREE_CODE (function
) == FUNCTION_DECL
2281 && DECL_STATIC_FUNCTION_P (function
))
2282 return build_member_call
2283 (DECL_CONTEXT (function
), DECL_NAME (function
), params
);
2285 /* Handle methods, friends, and overloaded functions, respectively. */
2288 tree basetype
= NULL_TREE
;
2290 if (TREE_CODE (function
) == FUNCTION_DECL
)
2292 basetype
= DECL_CLASS_CONTEXT (function
);
2294 if (DECL_NAME (function
))
2295 function
= DECL_NAME (function
);
2297 function
= TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function
));
2299 else if (TREE_CODE (function
) == TREE_LIST
)
2301 my_friendly_assert (TREE_CODE (TREE_VALUE (function
)) == FUNCTION_DECL
, 312);
2302 basetype
= DECL_CLASS_CONTEXT (TREE_VALUE (function
));
2303 function
= TREE_PURPOSE (function
);
2305 else if (TREE_CODE (function
) != IDENTIFIER_NODE
)
2307 if (TREE_CODE (function
) == OFFSET_REF
)
2309 if (TREE_OPERAND (function
, 0))
2310 decl
= TREE_OPERAND (function
, 0);
2312 /* Call via a pointer to member function. */
2313 if (decl
== NULL_TREE
)
2315 error ("pointer to member function called, but not in class scope");
2316 return error_mark_node
;
2318 /* What other type of POINTER_TYPE could this be? */
2319 if (TREE_CODE (TREE_TYPE (function
)) != POINTER_TYPE
2320 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (function
))
2321 && TREE_CODE (function
) != OFFSET_REF
)
2322 function
= build (OFFSET_REF
, TREE_TYPE (type
), NULL_TREE
, function
);
2326 /* this is an abbreviated method call.
2327 must go through here in case it is a virtual function.
2328 @@ Perhaps this could be optimized. */
2330 if (basetype
&& (! current_class_type
2331 || ! DERIVED_FROM_P (basetype
, current_class_type
)))
2332 return build_member_call (basetype
, function
, params
);
2334 if (decl
== NULL_TREE
)
2336 if (current_class_type
== NULL_TREE
)
2338 error ("object missing in call to method `%s'",
2339 IDENTIFIER_POINTER (function
));
2340 return error_mark_node
;
2342 /* Yow: call from a static member function. */
2343 decl
= build1 (NOP_EXPR
, build_pointer_type (current_class_type
),
2345 decl
= build_indirect_ref (decl
, NULL_PTR
);
2348 return build_method_call (decl
, function
, params
,
2349 NULL_TREE
, LOOKUP_NORMAL
);
2351 else if (TREE_CODE (function
) == COMPONENT_REF
2352 && type
== unknown_type_node
)
2354 /* Should we undo what was done in build_component_ref? */
2355 if (TREE_CODE (TREE_PURPOSE (TREE_OPERAND (function
, 1))) == TREE_VEC
)
2356 /* Get the name that build_component_ref hid. */
2357 function
= DECL_NAME (TREE_VALUE (TREE_OPERAND (function
, 1)));
2359 function
= TREE_PURPOSE (TREE_OPERAND (function
, 1));
2360 return build_method_call (decl
, function
, params
,
2361 NULL_TREE
, LOOKUP_NORMAL
);
2363 else if (TREE_CODE (function
) == TREE_LIST
)
2365 if (TREE_VALUE (function
) == NULL_TREE
)
2367 cp_error ("function `%D' declared overloaded, but no definitions appear with which to resolve it?!?",
2368 TREE_PURPOSE (function
));
2369 return error_mark_node
;
2373 tree val
= TREE_VALUE (function
);
2375 if (flag_ansi_overloading
)
2376 return build_new_function_call (function
, params
, NULL_TREE
);
2378 if (TREE_CODE (val
) == TEMPLATE_DECL
)
2379 return build_overload_call_real
2380 (function
, params
, LOOKUP_COMPLAIN
, (struct candidate
*)0, 0);
2381 else if (DECL_CHAIN (val
) != NULL_TREE
)
2382 return build_overload_call
2383 (function
, params
, LOOKUP_COMPLAIN
);
2385 my_friendly_abort (360);
2390 if (TREE_CODE (function
) == OFFSET_REF
)
2392 /* If the component is a data element (or a virtual function), we play
2393 games here to make things work. */
2396 if (TREE_OPERAND (function
, 0))
2397 decl
= TREE_OPERAND (function
, 0);
2399 decl
= current_class_ref
;
2401 decl_addr
= build_unary_op (ADDR_EXPR
, decl
, 0);
2402 function
= get_member_function_from_ptrfunc (&decl_addr
,
2403 TREE_OPERAND (function
, 1));
2404 params
= tree_cons (NULL_TREE
, decl_addr
, params
);
2405 return build_function_call (function
, params
);
2408 type
= TREE_TYPE (function
);
2409 if (type
!= error_mark_node
)
2411 if (TREE_CODE (type
) == REFERENCE_TYPE
)
2412 type
= TREE_TYPE (type
);
2414 if (IS_AGGR_TYPE (type
))
2415 return build_opfncall (CALL_EXPR
, LOOKUP_NORMAL
, function
, params
, NULL_TREE
);
2420 tree fntype
= TREE_TYPE (function
);
2423 /* Explicitly named method? */
2424 if (TREE_CODE (function
) == FUNCTION_DECL
)
2425 ctypeptr
= build_pointer_type (DECL_CLASS_CONTEXT (function
));
2426 /* Expression with ptr-to-method type? It could either be a plain
2427 usage, or it might be a case where the ptr-to-method is being
2428 passed in as an argument. */
2429 else if (TYPE_PTRMEMFUNC_P (fntype
))
2431 tree rec
= TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (fntype
)));
2432 ctypeptr
= build_pointer_type (rec
);
2434 /* Unexpected node type? */
2436 my_friendly_abort (116);
2437 if (decl
== NULL_TREE
)
2439 if (current_function_decl
2440 && DECL_STATIC_FUNCTION_P (current_function_decl
))
2441 error ("invalid call to member function needing `this' in static member function scope");
2443 error ("pointer to member function called, but not in class scope");
2444 return error_mark_node
;
2446 if (TREE_CODE (TREE_TYPE (decl
)) != POINTER_TYPE
2447 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (decl
)))
2449 decl
= build_unary_op (ADDR_EXPR
, decl
, 0);
2450 decl
= convert_pointer_to (TREE_TYPE (ctypeptr
), decl
);
2453 decl
= build_c_cast (ctypeptr
, decl
);
2454 params
= tree_cons (NULL_TREE
, decl
, params
);
2457 return build_function_call (function
, params
);
2460 /* Resolve a pointer to member function. INSTANCE is the object
2461 instance to use, if the member points to a virtual member. */
2464 get_member_function_from_ptrfunc (instance_ptrptr
, function
)
2465 tree
*instance_ptrptr
;
2468 if (TREE_CODE (function
) == OFFSET_REF
)
2470 function
= TREE_OPERAND (function
, 1);
2473 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function
)))
2475 tree fntype
, idx
, e1
, delta
, delta2
, e2
, e3
, aref
, vtbl
;
2478 tree instance_ptr
= *instance_ptrptr
;
2480 if (TREE_SIDE_EFFECTS (instance_ptr
))
2481 instance_ptr
= save_expr (instance_ptr
);
2483 if (TREE_SIDE_EFFECTS (function
))
2484 function
= save_expr (function
);
2486 fntype
= TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (function
));
2487 idx
= save_expr (build_component_ref (function
,
2490 e1
= fold (build (GT_EXPR
, boolean_type_node
, idx
,
2491 cp_convert (delta_type_node
, integer_zero_node
)));
2492 delta
= cp_convert (ptrdiff_type_node
,
2493 build_component_ref (function
, delta_identifier
, NULL_TREE
, 0));
2494 delta2
= DELTA2_FROM_PTRMEMFUNC (function
);
2496 /* Convert down to the right base, before using the instance. */
2498 = convert_pointer_to_real (TYPE_METHOD_BASETYPE (TREE_TYPE (fntype
)),
2500 if (instance
== error_mark_node
&& instance_ptr
!= error_mark_node
)
2503 vtbl
= convert_pointer_to (ptr_type_node
, instance
);
2506 build_pointer_type (build_pointer_type (vtable_entry_type
)),
2507 vtbl
, cp_convert (ptrdiff_type_node
, delta2
));
2508 vtbl
= build_indirect_ref (vtbl
, NULL_PTR
);
2509 aref
= build_array_ref (vtbl
, build_binary_op (MINUS_EXPR
,
2511 integer_one_node
, 1));
2512 if (! flag_vtable_thunks
)
2514 aref
= save_expr (aref
);
2516 delta
= build_binary_op (PLUS_EXPR
,
2517 build_conditional_expr (e1
, build_component_ref (aref
, delta_identifier
, NULL_TREE
, 0), integer_zero_node
),
2521 *instance_ptrptr
= build (PLUS_EXPR
, TREE_TYPE (instance_ptr
),
2522 instance_ptr
, delta
);
2523 if (flag_vtable_thunks
)
2526 e2
= build_component_ref (aref
, pfn_identifier
, NULL_TREE
, 0);
2528 e3
= PFN_FROM_PTRMEMFUNC (function
);
2529 TREE_TYPE (e2
) = TREE_TYPE (e3
);
2530 e1
= build_conditional_expr (e1
, e2
, e3
);
2532 if (instance_ptr
== error_mark_node
2533 && TREE_CODE (e1
) != ADDR_EXPR
2534 && TREE_CODE (TREE_OPERAND (e1
, 0)) != FUNCTION_DECL
)
2535 cp_error ("object missing in `%E'", function
);
2539 /* Make sure this doesn't get evaluated first inside one of the
2540 branches of the COND_EXPR. */
2541 if (TREE_CODE (instance_ptr
) == SAVE_EXPR
)
2542 function
= build (COMPOUND_EXPR
, TREE_TYPE (function
),
2543 instance_ptr
, function
);
2549 build_function_call_real (function
, params
, require_complete
, flags
)
2550 tree function
, params
;
2551 int require_complete
, flags
;
2553 register tree fntype
, fndecl
;
2554 register tree value_type
;
2555 register tree coerced_params
;
2556 tree name
= NULL_TREE
, assembler_name
= NULL_TREE
;
2559 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
2560 Strip such NOP_EXPRs, since FUNCTION is used in non-lvalue context. */
2561 if (TREE_CODE (function
) == NOP_EXPR
2562 && TREE_TYPE (function
) == TREE_TYPE (TREE_OPERAND (function
, 0)))
2563 function
= TREE_OPERAND (function
, 0);
2565 if (TREE_CODE (function
) == FUNCTION_DECL
)
2567 name
= DECL_NAME (function
);
2568 assembler_name
= DECL_ASSEMBLER_NAME (function
);
2570 GNU_xref_call (current_function_decl
,
2571 IDENTIFIER_POINTER (name
? name
2572 : TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function
))));
2573 mark_used (function
);
2576 /* Convert anything with function type to a pointer-to-function. */
2579 && IDENTIFIER_LENGTH (name
) == 4
2580 && ! strcmp (IDENTIFIER_POINTER (name
), "main")
2581 && DECL_CONTEXT (function
) == NULL_TREE
)
2583 pedwarn ("ANSI C++ forbids calling `main' from within program");
2586 if (pedantic
&& DECL_THIS_INLINE (function
) && ! DECL_INITIAL (function
)
2587 && ! DECL_ARTIFICIAL (function
)
2588 && ! DECL_PENDING_INLINE_INFO (function
))
2589 cp_pedwarn ("inline function `%#D' called before definition",
2592 /* Differs from default_conversion by not setting TREE_ADDRESSABLE
2593 (because calling an inline function does not mean the function
2594 needs to be separately compiled). */
2596 if (DECL_INLINE (function
))
2597 function
= inline_conversion (function
);
2599 function
= build_addr_func (function
);
2605 function
= build_addr_func (function
);
2608 if (function
== error_mark_node
)
2609 return error_mark_node
;
2611 fntype
= TREE_TYPE (function
);
2613 if (TYPE_PTRMEMFUNC_P (fntype
))
2615 cp_error ("must use .* or ->* to call pointer-to-member function in `%E (...)'",
2617 return error_mark_node
;
2620 is_method
= (TREE_CODE (fntype
) == POINTER_TYPE
2621 && TREE_CODE (TREE_TYPE (fntype
)) == METHOD_TYPE
);
2623 if (!((TREE_CODE (fntype
) == POINTER_TYPE
2624 && TREE_CODE (TREE_TYPE (fntype
)) == FUNCTION_TYPE
)
2627 cp_error ("`%E' cannot be used as a function", function
);
2628 return error_mark_node
;
2631 /* fntype now gets the type of function pointed to. */
2632 fntype
= TREE_TYPE (fntype
);
2634 /* Convert the parameters to the types declared in the
2635 function prototype, or apply default promotions. */
2637 if (flags
& LOOKUP_COMPLAIN
)
2638 coerced_params
= convert_arguments (NULL_TREE
, TYPE_ARG_TYPES (fntype
),
2639 params
, fndecl
, LOOKUP_NORMAL
);
2641 coerced_params
= convert_arguments (NULL_TREE
, TYPE_ARG_TYPES (fntype
),
2644 if (coerced_params
== error_mark_node
)
2645 if (flags
& LOOKUP_SPECULATIVELY
)
2648 return error_mark_node
;
2650 /* Check for errors in format strings. */
2652 if (warn_format
&& (name
|| assembler_name
))
2653 check_function_format (name
, assembler_name
, coerced_params
);
2655 /* Recognize certain built-in functions so we can make tree-codes
2656 other than CALL_EXPR. We do this when it enables fold-const.c
2657 to do something useful. */
2659 if (TREE_CODE (function
) == ADDR_EXPR
2660 && TREE_CODE (TREE_OPERAND (function
, 0)) == FUNCTION_DECL
2661 && DECL_BUILT_IN (TREE_OPERAND (function
, 0)))
2662 switch (DECL_FUNCTION_CODE (TREE_OPERAND (function
, 0)))
2667 if (coerced_params
== 0)
2668 return integer_zero_node
;
2669 return build_unary_op (ABS_EXPR
, TREE_VALUE (coerced_params
), 0);
2673 value_type
= TREE_TYPE (fntype
) ? TREE_TYPE (fntype
) : void_type_node
;
2675 register tree result
2676 = build_call (function
, value_type
, coerced_params
);
2678 if (require_complete
)
2680 if (value_type
== void_type_node
)
2682 result
= require_complete_type (result
);
2684 if (IS_AGGR_TYPE (value_type
))
2685 result
= build_cplus_new (value_type
, result
);
2686 return convert_from_reference (result
);
2691 build_function_call (function
, params
)
2692 tree function
, params
;
2694 return build_function_call_real (function
, params
, 1, LOOKUP_NORMAL
);
2697 /* Convert the actual parameter expressions in the list VALUES
2698 to the types in the list TYPELIST.
2699 If parmdecls is exhausted, or when an element has NULL as its type,
2700 perform the default conversions.
2702 RETURN_LOC is the location of the return value, if known, NULL_TREE
2703 otherwise. This is useful in the case where we can avoid creating
2704 a temporary variable in the case where we can initialize the return
2705 value directly. If we are not eliding constructors, then we set this
2706 to NULL_TREE to avoid this avoidance.
2708 NAME is an IDENTIFIER_NODE or 0. It is used only for error messages.
2710 This is also where warnings about wrong number of args are generated.
2712 Return a list of expressions for the parameters as converted.
2714 Both VALUES and the returned value are chains of TREE_LIST nodes
2715 with the elements of the list in the TREE_VALUE slots of those nodes.
2717 In C++, unspecified trailing parameters can be filled in with their
2718 default arguments, if such were specified. Do so here. */
2721 convert_arguments (return_loc
, typelist
, values
, fndecl
, flags
)
2722 tree return_loc
, typelist
, values
, fndecl
;
2725 register tree typetail
, valtail
;
2726 register tree result
= NULL_TREE
;
2730 if (! flag_elide_constructors
)
2733 /* Argument passing is always copy-initialization. */
2734 flags
|= LOOKUP_ONLYCONVERTING
;
2738 if (TREE_CODE (TREE_TYPE (fndecl
)) == METHOD_TYPE
)
2740 if (DECL_NAME (fndecl
) == NULL_TREE
2741 || IDENTIFIER_HAS_TYPE_VALUE (DECL_NAME (fndecl
)))
2742 called_thing
= "constructor";
2744 called_thing
= "member function";
2747 called_thing
= "function";
2750 for (valtail
= values
, typetail
= typelist
;
2752 valtail
= TREE_CHAIN (valtail
), i
++)
2754 register tree type
= typetail
? TREE_VALUE (typetail
) : 0;
2755 register tree val
= TREE_VALUE (valtail
);
2757 if (val
== error_mark_node
)
2758 return error_mark_node
;
2760 if (type
== void_type_node
)
2764 cp_error_at ("too many arguments to %s `%+D'", called_thing
,
2766 error ("at this point in file");
2769 error ("too many arguments to function");
2770 /* In case anybody wants to know if this argument
2773 TREE_TYPE (tree_last (result
)) = error_mark_node
;
2777 /* The tree type of the parameter being passed may not yet be
2778 known. In this case, its type is TYPE_UNKNOWN, and will
2779 be instantiated by the type given by TYPE. If TYPE
2780 is also NULL, the tree type of VAL is ERROR_MARK_NODE. */
2781 if (type
&& type_unknown_p (val
))
2782 val
= require_instantiated_type (type
, val
, integer_zero_node
);
2783 else if (type_unknown_p (val
))
2785 /* Strip the `&' from an overloaded FUNCTION_DECL. */
2786 if (TREE_CODE (val
) == ADDR_EXPR
)
2787 val
= TREE_OPERAND (val
, 0);
2788 if (TREE_CODE (val
) == TREE_LIST
2789 && TREE_CHAIN (val
) == NULL_TREE
2790 && TREE_TYPE (TREE_VALUE (val
)) != NULL_TREE
2791 && (TREE_TYPE (val
) == unknown_type_node
2792 || DECL_CHAIN (TREE_VALUE (val
)) == NULL_TREE
))
2793 /* Instantiates automatically. */
2794 val
= TREE_VALUE (val
);
2797 error ("insufficient type information in parameter list");
2798 val
= integer_zero_node
;
2801 else if (TREE_CODE (val
) == OFFSET_REF
2802 && TREE_CODE (TREE_TYPE (val
)) == METHOD_TYPE
)
2804 /* This is unclean. Should be handled elsewhere. */
2805 val
= build_unary_op (ADDR_EXPR
, val
, 0);
2807 else if (TREE_CODE (val
) == OFFSET_REF
)
2808 val
= resolve_offset_ref (val
);
2810 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
2811 Strip such NOP_EXPRs, since VAL is used in non-lvalue context. */
2812 if (TREE_CODE (val
) == NOP_EXPR
2813 && TREE_TYPE (val
) == TREE_TYPE (TREE_OPERAND (val
, 0))
2814 && (type
== 0 || TREE_CODE (type
) != REFERENCE_TYPE
))
2815 val
= TREE_OPERAND (val
, 0);
2817 if (type
== 0 || TREE_CODE (type
) != REFERENCE_TYPE
)
2819 if (TREE_CODE (TREE_TYPE (val
)) == ARRAY_TYPE
2820 || TREE_CODE (TREE_TYPE (val
)) == FUNCTION_TYPE
2821 || TREE_CODE (TREE_TYPE (val
)) == METHOD_TYPE
)
2822 val
= default_conversion (val
);
2824 val
= require_complete_type (val
);
2827 if (val
== error_mark_node
)
2828 return error_mark_node
;
2832 /* Formal parm type is specified by a function prototype. */
2835 if (TYPE_SIZE (complete_type (type
)) == 0)
2837 error ("parameter type of called function is incomplete");
2842 parmval
= convert_for_initialization
2843 (return_loc
, type
, val
, flags
,
2844 "argument passing", fndecl
, i
);
2845 #ifdef PROMOTE_PROTOTYPES
2846 if ((TREE_CODE (type
) == INTEGER_TYPE
2847 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2848 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
2849 parmval
= default_conversion (parmval
);
2853 if (parmval
== error_mark_node
)
2854 return error_mark_node
;
2856 result
= tree_cons (NULL_TREE
, parmval
, result
);
2860 if (TREE_CODE (TREE_TYPE (val
)) == REFERENCE_TYPE
)
2861 val
= convert_from_reference (val
);
2863 if (TREE_CODE (TREE_TYPE (val
)) == REAL_TYPE
2864 && (TYPE_PRECISION (TREE_TYPE (val
))
2865 < TYPE_PRECISION (double_type_node
)))
2866 /* Convert `float' to `double'. */
2867 result
= tree_cons (NULL_TREE
, cp_convert (double_type_node
, val
), result
);
2868 else if (TYPE_LANG_SPECIFIC (TREE_TYPE (val
))
2869 && ! TYPE_HAS_TRIVIAL_INIT_REF (TREE_TYPE (val
)))
2871 cp_warning ("cannot pass objects of type `%T' through `...'",
2873 result
= tree_cons (NULL_TREE
, val
, result
);
2876 /* Convert `short' and `char' to full-size `int'. */
2877 result
= tree_cons (NULL_TREE
, default_conversion (val
), result
);
2881 typetail
= TREE_CHAIN (typetail
);
2884 if (typetail
!= 0 && typetail
!= void_list_node
)
2886 /* See if there are default arguments that can be used */
2887 if (TREE_PURPOSE (typetail
))
2889 for (; typetail
!= void_list_node
; ++i
)
2891 tree type
= TREE_VALUE (typetail
);
2892 tree val
= break_out_target_exprs (TREE_PURPOSE (typetail
));
2895 if (val
== NULL_TREE
)
2896 parmval
= error_mark_node
;
2897 else if (TREE_CODE (val
) == CONSTRUCTOR
)
2899 parmval
= digest_init (type
, val
, (tree
*)0);
2900 parmval
= convert_for_initialization (return_loc
, type
, parmval
, flags
,
2901 "default constructor", fndecl
, i
);
2905 /* This could get clobbered by the following call. */
2906 if (TREE_HAS_CONSTRUCTOR (val
))
2907 val
= copy_node (val
);
2909 parmval
= convert_for_initialization (return_loc
, type
, val
, flags
,
2910 "default argument", fndecl
, i
);
2911 #ifdef PROMOTE_PROTOTYPES
2912 if ((TREE_CODE (type
) == INTEGER_TYPE
2913 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2914 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
2915 parmval
= default_conversion (parmval
);
2919 if (parmval
== error_mark_node
)
2920 return error_mark_node
;
2922 result
= tree_cons (0, parmval
, result
);
2923 typetail
= TREE_CHAIN (typetail
);
2924 /* ends with `...'. */
2925 if (typetail
== NULL_TREE
)
2933 char *buf
= (char *)alloca (32 + strlen (called_thing
));
2934 sprintf (buf
, "too few arguments to %s `%%#D'", called_thing
);
2935 cp_error_at (buf
, fndecl
);
2936 error ("at this point in file");
2939 error ("too few arguments to function");
2940 return error_mark_list
;
2944 return nreverse (result
);
2947 /* Build a binary-operation expression, after performing default
2948 conversions on the operands. CODE is the kind of expression to build. */
2951 build_x_binary_op (code
, arg1
, arg2
)
2952 enum tree_code code
;
2957 if (processing_template_decl
)
2958 return build_min_nt (code
, arg1
, arg2
);
2960 if (flag_ansi_overloading
)
2961 return build_new_op (code
, LOOKUP_NORMAL
, arg1
, arg2
, NULL_TREE
);
2963 rval
= build_opfncall (code
, LOOKUP_SPECULATIVELY
,
2964 arg1
, arg2
, NULL_TREE
);
2966 return build_opfncall (code
, LOOKUP_NORMAL
, arg1
, arg2
, NULL_TREE
);
2967 if (code
== MEMBER_REF
)
2968 return build_m_component_ref (build_indirect_ref (arg1
, NULL_PTR
),
2970 return build_binary_op (code
, arg1
, arg2
, 1);
2974 build_binary_op (code
, arg1
, arg2
, convert_p
)
2975 enum tree_code code
;
2987 args
[0] = decay_conversion (args
[0]);
2988 args
[1] = decay_conversion (args
[1]);
2990 if (args
[0] == error_mark_node
|| args
[1] == error_mark_node
)
2991 return error_mark_node
;
2993 type0
= TREE_TYPE (args
[0]);
2994 type1
= TREE_TYPE (args
[1]);
2996 if (type_unknown_p (args
[0]))
2998 args
[0] = instantiate_type (type1
, args
[0], 1);
2999 args
[0] = decay_conversion (args
[0]);
3001 else if (type_unknown_p (args
[1]))
3003 args
[1] = require_instantiated_type (type0
, args
[1],
3005 args
[1] = decay_conversion (args
[1]);
3008 if (IS_AGGR_TYPE (type0
) || IS_AGGR_TYPE (type1
))
3010 /* Try to convert this to something reasonable. */
3011 if (! build_default_binary_type_conversion(code
, &args
[0], &args
[1]))
3013 cp_error ("no match for `%O(%#T, %#T)'", code
,
3014 TREE_TYPE (arg1
), TREE_TYPE (arg2
));
3015 return error_mark_node
;
3019 return build_binary_op_nodefault (code
, args
[0], args
[1], code
);
3022 /* Build a binary-operation expression without default conversions.
3023 CODE is the kind of expression to build.
3024 This function differs from `build' in several ways:
3025 the data type of the result is computed and recorded in it,
3026 warnings are generated if arg data types are invalid,
3027 special handling for addition and subtraction of pointers is known,
3028 and some optimization is done (operations on narrow ints
3029 are done in the narrower type when that gives the same result).
3030 Constant folding is also done before the result is returned.
3032 ERROR_CODE is the code that determines what to say in error messages.
3033 It is usually, but not always, the same as CODE.
3035 Note that the operands will never have enumeral types
3036 because either they have just had the default conversions performed
3037 or they have both just been converted to some other type in which
3038 the arithmetic is to be done.
3040 C++: must do special pointer arithmetic when implementing
3041 multiple inheritance, and deal with pointer to member functions. */
3044 build_binary_op_nodefault (code
, orig_op0
, orig_op1
, error_code
)
3045 enum tree_code code
;
3046 tree orig_op0
, orig_op1
;
3047 enum tree_code error_code
;
3050 register enum tree_code code0
, code1
;
3053 /* Expression code to give to the expression when it is built.
3054 Normally this is CODE, which is what the caller asked for,
3055 but in some special cases we change it. */
3056 register enum tree_code resultcode
= code
;
3058 /* Data type in which the computation is to be performed.
3059 In the simplest cases this is the common type of the arguments. */
3060 register tree result_type
= NULL
;
3062 /* Nonzero means operands have already been type-converted
3063 in whatever way is necessary.
3064 Zero means they need to be converted to RESULT_TYPE. */
3067 /* Nonzero means create the expression with this type, rather than
3069 tree build_type
= 0;
3071 /* Nonzero means after finally constructing the expression
3072 convert it to this type. */
3073 tree final_type
= 0;
3075 /* Nonzero if this is an operation like MIN or MAX which can
3076 safely be computed in short if both args are promoted shorts.
3077 Also implies COMMON.
3078 -1 indicates a bitwise operation; this makes a difference
3079 in the exact conditions for when it is safe to do the operation
3080 in a narrower mode. */
3083 /* Nonzero if this is a comparison operation;
3084 if both args are promoted shorts, compare the original shorts.
3085 Also implies COMMON. */
3086 int short_compare
= 0;
3088 /* Nonzero if this is a right-shift operation, which can be computed on the
3089 original short and then promoted if the operand is a promoted short. */
3090 int short_shift
= 0;
3092 /* Nonzero means set RESULT_TYPE to the common type of the args. */
3095 /* Apply default conversions. */
3096 if (code
== TRUTH_AND_EXPR
|| code
== TRUTH_ANDIF_EXPR
3097 || code
== TRUTH_OR_EXPR
|| code
== TRUTH_ORIF_EXPR
3098 || code
== TRUTH_XOR_EXPR
)
3100 op0
= decay_conversion (orig_op0
);
3101 op1
= decay_conversion (orig_op1
);
3105 op0
= default_conversion (orig_op0
);
3106 op1
= default_conversion (orig_op1
);
3109 type0
= TREE_TYPE (op0
);
3110 type1
= TREE_TYPE (op1
);
3112 /* The expression codes of the data types of the arguments tell us
3113 whether the arguments are integers, floating, pointers, etc. */
3114 code0
= TREE_CODE (type0
);
3115 code1
= TREE_CODE (type1
);
3117 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
3118 STRIP_TYPE_NOPS (op0
);
3119 STRIP_TYPE_NOPS (op1
);
3121 /* If an error was already reported for one of the arguments,
3122 avoid reporting another error. */
3124 if (code0
== ERROR_MARK
|| code1
== ERROR_MARK
)
3125 return error_mark_node
;
3130 /* Handle the pointer + int case. */
3131 if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3132 return pointer_int_sum (PLUS_EXPR
, op0
, op1
);
3133 else if (code1
== POINTER_TYPE
&& code0
== INTEGER_TYPE
)
3134 return pointer_int_sum (PLUS_EXPR
, op1
, op0
);
3140 /* Subtraction of two similar pointers.
3141 We must subtract them as integers, then divide by object size. */
3142 if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
3143 && comp_target_types (type0
, type1
, 1))
3144 return pointer_diff (op0
, op1
);
3145 /* Handle pointer minus int. Just like pointer plus int. */
3146 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3147 return pointer_int_sum (MINUS_EXPR
, op0
, op1
);
3156 case TRUNC_DIV_EXPR
:
3158 case FLOOR_DIV_EXPR
:
3159 case ROUND_DIV_EXPR
:
3160 case EXACT_DIV_EXPR
:
3161 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
3162 || code0
== COMPLEX_TYPE
)
3163 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
3164 || code1
== COMPLEX_TYPE
))
3166 if (TREE_CODE (op1
) == INTEGER_CST
&& integer_zerop (op1
))
3167 cp_warning ("division by zero in `%E / 0'", op0
);
3168 else if (TREE_CODE (op1
) == REAL_CST
&& real_zerop (op1
))
3169 cp_warning ("division by zero in `%E / 0.'", op0
);
3171 if (!(code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
))
3172 resultcode
= RDIV_EXPR
;
3174 /* When dividing two signed integers, we have to promote to int.
3175 unless we divide by a constant != -1. Note that default
3176 conversion will have been performed on the operands at this
3177 point, so we have to dig out the original type to find out if
3179 shorten
= ((TREE_CODE (op0
) == NOP_EXPR
3180 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3181 || (TREE_CODE (op1
) == INTEGER_CST
3182 && (TREE_INT_CST_LOW (op1
) != -1
3183 || TREE_INT_CST_HIGH (op1
) != -1)));
3189 case BIT_ANDTC_EXPR
:
3192 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3194 /* If one operand is a constant, and the other is a short type
3195 that has been converted to an int,
3196 really do the work in the short type and then convert the
3197 result to int. If we are lucky, the constant will be 0 or 1
3198 in the short type, making the entire operation go away. */
3199 if (TREE_CODE (op0
) == INTEGER_CST
3200 && TREE_CODE (op1
) == NOP_EXPR
3201 && TYPE_PRECISION (type1
) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1
, 0)))
3202 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1
, 0))))
3204 final_type
= result_type
;
3205 op1
= TREE_OPERAND (op1
, 0);
3206 result_type
= TREE_TYPE (op1
);
3208 if (TREE_CODE (op1
) == INTEGER_CST
3209 && TREE_CODE (op0
) == NOP_EXPR
3210 && TYPE_PRECISION (type0
) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0
, 0)))
3211 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3213 final_type
= result_type
;
3214 op0
= TREE_OPERAND (op0
, 0);
3215 result_type
= TREE_TYPE (op0
);
3219 case TRUNC_MOD_EXPR
:
3220 case FLOOR_MOD_EXPR
:
3221 if (code1
== INTEGER_TYPE
&& integer_zerop (op1
))
3222 cp_warning ("division by zero in `%E % 0'", op0
);
3223 else if (code1
== REAL_TYPE
&& real_zerop (op1
))
3224 cp_warning ("division by zero in `%E % 0.'", op0
);
3226 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3228 /* Although it would be tempting to shorten always here, that loses
3229 on some targets, since the modulo instruction is undefined if the
3230 quotient can't be represented in the computation mode. We shorten
3231 only if unsigned or if dividing by something we know != -1. */
3232 shorten
= ((TREE_CODE (op0
) == NOP_EXPR
3233 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3234 || (TREE_CODE (op1
) == INTEGER_CST
3235 && (TREE_INT_CST_LOW (op1
) != -1
3236 || TREE_INT_CST_HIGH (op1
) != -1)));
3241 case TRUTH_ANDIF_EXPR
:
3242 case TRUTH_ORIF_EXPR
:
3243 case TRUTH_AND_EXPR
:
3245 result_type
= boolean_type_node
;
3248 /* Shift operations: result has same type as first operand;
3249 always convert second operand to int.
3250 Also set SHORT_SHIFT if shifting rightward. */
3253 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3255 result_type
= type0
;
3256 if (TREE_CODE (op1
) == INTEGER_CST
)
3258 if (tree_int_cst_lt (op1
, integer_zero_node
))
3259 warning ("right shift count is negative");
3262 if (TREE_INT_CST_LOW (op1
) | TREE_INT_CST_HIGH (op1
))
3264 if (TREE_INT_CST_HIGH (op1
) != 0
3265 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3266 >= TYPE_PRECISION (type0
)))
3267 warning ("right shift count >= width of type");
3270 /* Convert the shift-count to an integer, regardless of
3271 size of value being shifted. */
3272 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3273 op1
= cp_convert (integer_type_node
, op1
);
3274 /* Avoid converting op1 to result_type later. */
3280 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3282 result_type
= type0
;
3283 if (TREE_CODE (op1
) == INTEGER_CST
)
3285 if (tree_int_cst_lt (op1
, integer_zero_node
))
3286 warning ("left shift count is negative");
3287 else if (TREE_INT_CST_HIGH (op1
) != 0
3288 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3289 >= TYPE_PRECISION (type0
)))
3290 warning ("left shift count >= width of type");
3292 /* Convert the shift-count to an integer, regardless of
3293 size of value being shifted. */
3294 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3295 op1
= cp_convert (integer_type_node
, op1
);
3296 /* Avoid converting op1 to result_type later. */
3303 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3305 result_type
= type0
;
3306 if (TREE_CODE (op1
) == INTEGER_CST
)
3308 if (tree_int_cst_lt (op1
, integer_zero_node
))
3309 warning ("%s rotate count is negative",
3310 (code
== LROTATE_EXPR
) ? "left" : "right");
3311 else if (TREE_INT_CST_HIGH (op1
) != 0
3312 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3313 >= TYPE_PRECISION (type0
)))
3314 warning ("%s rotate count >= width of type",
3315 (code
== LROTATE_EXPR
) ? "left" : "right");
3317 /* Convert the shift-count to an integer, regardless of
3318 size of value being shifted. */
3319 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3320 op1
= cp_convert (integer_type_node
, op1
);
3326 build_type
= boolean_type_node
;
3327 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
3328 || code0
== COMPLEX_TYPE
)
3329 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
3330 || code1
== COMPLEX_TYPE
))
3332 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3334 register tree tt0
= TYPE_MAIN_VARIANT (TREE_TYPE (type0
));
3335 register tree tt1
= TYPE_MAIN_VARIANT (TREE_TYPE (type1
));
3337 if (comp_target_types (type0
, type1
, 1))
3338 result_type
= common_type (type0
, type1
);
3339 else if (tt0
== void_type_node
)
3341 if (pedantic
&& TREE_CODE (tt1
) == FUNCTION_TYPE
3342 && tree_int_cst_lt (TYPE_SIZE (type0
), TYPE_SIZE (type1
)))
3343 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3344 else if (TREE_CODE (tt1
) == OFFSET_TYPE
)
3345 pedwarn ("ANSI C++ forbids conversion of a pointer to member to `void *'");
3347 else if (tt1
== void_type_node
)
3349 if (pedantic
&& TREE_CODE (tt0
) == FUNCTION_TYPE
3350 && tree_int_cst_lt (TYPE_SIZE (type1
), TYPE_SIZE (type0
)))
3351 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3354 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3357 if (result_type
== NULL_TREE
)
3358 result_type
= ptr_type_node
;
3360 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
3361 && integer_zerop (op1
))
3362 result_type
= type0
;
3363 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
3364 && integer_zerop (op0
))
3365 result_type
= type1
;
3366 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3368 result_type
= type0
;
3369 error ("ANSI C++ forbids comparison between pointer and integer");
3371 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
3373 result_type
= type1
;
3374 error ("ANSI C++ forbids comparison between pointer and integer");
3376 else if (TYPE_PTRMEMFUNC_P (type0
) && TREE_CODE (op1
) == INTEGER_CST
3377 && integer_zerop (op1
))
3379 op0
= build_component_ref (op0
, index_identifier
, NULL_TREE
, 0);
3380 op1
= integer_zero_node
;
3381 result_type
= TREE_TYPE (op0
);
3383 else if (TYPE_PTRMEMFUNC_P (type1
) && TREE_CODE (op0
) == INTEGER_CST
3384 && integer_zerop (op0
))
3386 op0
= build_component_ref (op1
, index_identifier
, NULL_TREE
, 0);
3387 op1
= integer_zero_node
;
3388 result_type
= TREE_TYPE (op0
);
3390 else if (TYPE_PTRMEMFUNC_P (type0
) && TYPE_PTRMEMFUNC_P (type1
)
3391 && (TYPE_PTRMEMFUNC_FN_TYPE (type0
)
3392 == TYPE_PTRMEMFUNC_FN_TYPE (type1
)))
3394 /* The code we generate for the test is:
3396 (op0.index == op1.index
3397 && ((op1.index != -1 && op0.delta2 == op1.delta2)
3398 || op0.pfn == op1.pfn)) */
3400 tree index0
= build_component_ref (op0
, index_identifier
, NULL_TREE
, 0);
3401 tree index1
= save_expr (build_component_ref (op1
, index_identifier
, NULL_TREE
, 0));
3402 tree pfn0
= PFN_FROM_PTRMEMFUNC (op0
);
3403 tree pfn1
= PFN_FROM_PTRMEMFUNC (op1
);
3404 tree delta20
= DELTA2_FROM_PTRMEMFUNC (op0
);
3405 tree delta21
= DELTA2_FROM_PTRMEMFUNC (op1
);
3407 tree integer_neg_one_node
3408 = build_binary_op (MINUS_EXPR
, integer_zero_node
, integer_one_node
, 1);
3409 e1
= build_binary_op (EQ_EXPR
, index0
, index1
, 1);
3410 e2
= build_binary_op (NE_EXPR
, index1
, integer_neg_one_node
, 1);
3411 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e2
, build_binary_op (EQ_EXPR
, delta20
, delta21
, 1), 1);
3412 e3
= build_binary_op (EQ_EXPR
, pfn0
, pfn1
, 1);
3413 e2
= build_binary_op (TRUTH_ORIF_EXPR
, e2
, e3
, 1);
3414 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e1
, e2
, 1);
3415 if (code
== EQ_EXPR
)
3417 return build_binary_op (EQ_EXPR
, e2
, integer_zero_node
, 1);
3419 else if (TYPE_PTRMEMFUNC_P (type0
)
3420 && TYPE_PTRMEMFUNC_FN_TYPE (type0
) == type1
)
3422 tree index0
= build_component_ref (op0
, index_identifier
, NULL_TREE
, 0);
3424 tree pfn0
= PFN_FROM_PTRMEMFUNC (op0
);
3425 tree delta20
= DELTA2_FROM_PTRMEMFUNC (op0
);
3426 tree delta21
= integer_zero_node
;
3428 tree integer_neg_one_node
3429 = build_binary_op (MINUS_EXPR
, integer_zero_node
, integer_one_node
, 1);
3430 if (TREE_CODE (TREE_OPERAND (op1
, 0)) == FUNCTION_DECL
3431 && DECL_VINDEX (TREE_OPERAND (op1
, 0)))
3433 /* Map everything down one to make room for the null pointer to member. */
3434 index1
= size_binop (PLUS_EXPR
,
3435 DECL_VINDEX (TREE_OPERAND (op1
, 0)),
3437 op1
= integer_zero_node
;
3438 delta21
= CLASSTYPE_VFIELD (TYPE_METHOD_BASETYPE (TREE_TYPE (type1
)));
3439 delta21
= DECL_FIELD_BITPOS (delta21
);
3440 delta21
= size_binop (FLOOR_DIV_EXPR
, delta21
, size_int (BITS_PER_UNIT
));
3443 index1
= integer_neg_one_node
;
3445 tree nop1
= build1 (NOP_EXPR
, TYPE_PTRMEMFUNC_FN_TYPE (type0
), op1
);
3446 TREE_CONSTANT (nop1
) = TREE_CONSTANT (op1
);
3449 e1
= build_binary_op (EQ_EXPR
, index0
, index1
, 1);
3450 e2
= build_binary_op (NE_EXPR
, index1
, integer_neg_one_node
, 1);
3451 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e2
, build_binary_op (EQ_EXPR
, delta20
, delta21
, 1), 1);
3452 e3
= build_binary_op (EQ_EXPR
, pfn0
, op1
, 1);
3453 e2
= build_binary_op (TRUTH_ORIF_EXPR
, e2
, e3
, 1);
3454 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e1
, e2
, 1);
3455 if (code
== EQ_EXPR
)
3457 return build_binary_op (EQ_EXPR
, e2
, integer_zero_node
, 1);
3459 else if (TYPE_PTRMEMFUNC_P (type1
)
3460 && TYPE_PTRMEMFUNC_FN_TYPE (type1
) == type0
)
3462 return build_binary_op (code
, op1
, op0
, 1);
3468 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3469 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3471 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3473 if (comp_target_types (type0
, type1
, 1))
3474 result_type
= common_type (type0
, type1
);
3477 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3479 result_type
= ptr_type_node
;
3488 build_type
= boolean_type_node
;
3489 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3490 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3492 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3494 if (comp_target_types (type0
, type1
, 1))
3495 result_type
= common_type (type0
, type1
);
3498 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3500 result_type
= ptr_type_node
;
3503 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
3504 && integer_zerop (op1
))
3505 result_type
= type0
;
3506 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
3507 && integer_zerop (op0
))
3508 result_type
= type1
;
3509 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3511 result_type
= type0
;
3512 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3514 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
3516 result_type
= type1
;
3517 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3522 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
|| code0
== COMPLEX_TYPE
)
3524 (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
|| code1
== COMPLEX_TYPE
))
3526 int none_complex
= (code0
!= COMPLEX_TYPE
&& code1
!= COMPLEX_TYPE
);
3528 if (shorten
|| common
|| short_compare
)
3529 result_type
= common_type (type0
, type1
);
3531 /* For certain operations (which identify themselves by shorten != 0)
3532 if both args were extended from the same smaller type,
3533 do the arithmetic in that type and then extend.
3535 shorten !=0 and !=1 indicates a bitwise operation.
3536 For them, this optimization is safe only if
3537 both args are zero-extended or both are sign-extended.
3538 Otherwise, we might change the result.
3539 Eg, (short)-1 | (unsigned short)-1 is (int)-1
3540 but calculated in (unsigned short) it would be (unsigned short)-1. */
3542 if (shorten
&& none_complex
)
3544 int unsigned0
, unsigned1
;
3545 tree arg0
= get_narrower (op0
, &unsigned0
);
3546 tree arg1
= get_narrower (op1
, &unsigned1
);
3547 /* UNS is 1 if the operation to be done is an unsigned one. */
3548 int uns
= TREE_UNSIGNED (result_type
);
3551 final_type
= result_type
;
3553 /* Handle the case that OP0 does not *contain* a conversion
3554 but it *requires* conversion to FINAL_TYPE. */
3556 if (op0
== arg0
&& TREE_TYPE (op0
) != final_type
)
3557 unsigned0
= TREE_UNSIGNED (TREE_TYPE (op0
));
3558 if (op1
== arg1
&& TREE_TYPE (op1
) != final_type
)
3559 unsigned1
= TREE_UNSIGNED (TREE_TYPE (op1
));
3561 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
3563 /* For bitwise operations, signedness of nominal type
3564 does not matter. Consider only how operands were extended. */
3568 /* Note that in all three cases below we refrain from optimizing
3569 an unsigned operation on sign-extended args.
3570 That would not be valid. */
3572 /* Both args variable: if both extended in same way
3573 from same width, do it in that width.
3574 Do it unsigned if args were zero-extended. */
3575 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
3576 < TYPE_PRECISION (result_type
))
3577 && (TYPE_PRECISION (TREE_TYPE (arg1
))
3578 == TYPE_PRECISION (TREE_TYPE (arg0
)))
3579 && unsigned0
== unsigned1
3580 && (unsigned0
|| !uns
))
3582 = signed_or_unsigned_type (unsigned0
,
3583 common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
3584 else if (TREE_CODE (arg0
) == INTEGER_CST
3585 && (unsigned1
|| !uns
)
3586 && (TYPE_PRECISION (TREE_TYPE (arg1
))
3587 < TYPE_PRECISION (result_type
))
3588 && (type
= signed_or_unsigned_type (unsigned1
,
3590 int_fits_type_p (arg0
, type
)))
3592 else if (TREE_CODE (arg1
) == INTEGER_CST
3593 && (unsigned0
|| !uns
)
3594 && (TYPE_PRECISION (TREE_TYPE (arg0
))
3595 < TYPE_PRECISION (result_type
))
3596 && (type
= signed_or_unsigned_type (unsigned0
,
3598 int_fits_type_p (arg1
, type
)))
3602 /* Shifts can be shortened if shifting right. */
3607 tree arg0
= get_narrower (op0
, &unsigned_arg
);
3609 final_type
= result_type
;
3611 if (arg0
== op0
&& final_type
== TREE_TYPE (op0
))
3612 unsigned_arg
= TREE_UNSIGNED (TREE_TYPE (op0
));
3614 if (TYPE_PRECISION (TREE_TYPE (arg0
)) < TYPE_PRECISION (result_type
)
3615 /* We can shorten only if the shift count is less than the
3616 number of bits in the smaller type size. */
3617 && TREE_INT_CST_HIGH (op1
) == 0
3618 && TYPE_PRECISION (TREE_TYPE (arg0
)) > TREE_INT_CST_LOW (op1
)
3619 /* If arg is sign-extended and then unsigned-shifted,
3620 we can simulate this with a signed shift in arg's type
3621 only if the extended result is at least twice as wide
3622 as the arg. Otherwise, the shift could use up all the
3623 ones made by sign-extension and bring in zeros.
3624 We can't optimize that case at all, but in most machines
3625 it never happens because available widths are 2**N. */
3626 && (!TREE_UNSIGNED (final_type
)
3628 || (((unsigned) 2 * TYPE_PRECISION (TREE_TYPE (arg0
)))
3629 <= TYPE_PRECISION (result_type
))))
3631 /* Do an unsigned shift if the operand was zero-extended. */
3633 = signed_or_unsigned_type (unsigned_arg
,
3635 /* Convert value-to-be-shifted to that type. */
3636 if (TREE_TYPE (op0
) != result_type
)
3637 op0
= cp_convert (result_type
, op0
);
3642 /* Comparison operations are shortened too but differently.
3643 They identify themselves by setting short_compare = 1. */
3647 /* Don't write &op0, etc., because that would prevent op0
3648 from being kept in a register.
3649 Instead, make copies of the our local variables and
3650 pass the copies by reference, then copy them back afterward. */
3651 tree xop0
= op0
, xop1
= op1
, xresult_type
= result_type
;
3652 enum tree_code xresultcode
= resultcode
;
3654 = shorten_compare (&xop0
, &xop1
, &xresult_type
, &xresultcode
);
3656 return cp_convert (boolean_type_node
, val
);
3657 op0
= xop0
, op1
= xop1
;
3659 resultcode
= xresultcode
;
3662 if (short_compare
&& warn_sign_compare
)
3664 int op0_signed
= ! TREE_UNSIGNED (TREE_TYPE (orig_op0
));
3665 int op1_signed
= ! TREE_UNSIGNED (TREE_TYPE (orig_op1
));
3667 int unsignedp0
, unsignedp1
;
3668 tree primop0
= get_narrower (op0
, &unsignedp0
);
3669 tree primop1
= get_narrower (op1
, &unsignedp1
);
3671 /* Check for comparison of different enum types. */
3672 if (flag_int_enum_equivalence
== 0
3673 && TREE_CODE (TREE_TYPE (orig_op0
)) == ENUMERAL_TYPE
3674 && TREE_CODE (TREE_TYPE (orig_op1
)) == ENUMERAL_TYPE
3675 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0
))
3676 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1
)))
3678 cp_warning ("comparison between `%#T' and `%#T'",
3679 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
));
3682 /* Give warnings for comparisons between signed and unsigned
3683 quantities that may fail. */
3684 /* Do the checking based on the original operand trees, so that
3685 casts will be considered, but default promotions won't be. */
3687 /* Do not warn if the comparison is being done in a signed type,
3688 since the signed type will only be chosen if it can represent
3689 all the values of the unsigned type. */
3690 if (! TREE_UNSIGNED (result_type
))
3692 /* Do not warn if both operands are unsigned. */
3693 else if (op0_signed
== op1_signed
)
3695 /* Do not warn if the signed quantity is an unsuffixed
3696 integer literal (or some static constant expression
3697 involving such literals) and it is non-negative. */
3698 else if ((op0_signed
&& TREE_CODE (orig_op0
) == INTEGER_CST
3699 && tree_int_cst_sgn (orig_op0
) >= 0)
3700 || (op1_signed
&& TREE_CODE (orig_op1
) == INTEGER_CST
3701 && tree_int_cst_sgn (orig_op1
) >= 0))
3703 /* Do not warn if the comparison is an equality operation,
3704 the unsigned quantity is an integral constant and it does
3705 not use the most significant bit of result_type. */
3706 else if ((resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
3707 && ((op0_signed
&& TREE_CODE (orig_op1
) == INTEGER_CST
3708 && int_fits_type_p (orig_op1
, signed_type (result_type
))
3709 || (op1_signed
&& TREE_CODE (orig_op0
) == INTEGER_CST
3710 && int_fits_type_p (orig_op0
, signed_type (result_type
))))))
3713 warning ("comparison between signed and unsigned");
3715 /* Warn if two unsigned values are being compared in a size
3716 larger than their original size, and one (and only one) is the
3717 result of a `~' operator. This comparison will always fail.
3719 Also warn if one operand is a constant, and the constant does not
3720 have all bits set that are set in the ~ operand when it is
3723 if ((TREE_CODE (primop0
) == BIT_NOT_EXPR
)
3724 ^ (TREE_CODE (primop1
) == BIT_NOT_EXPR
))
3726 if (TREE_CODE (primop0
) == BIT_NOT_EXPR
)
3727 primop0
= get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
3728 if (TREE_CODE (primop1
) == BIT_NOT_EXPR
)
3729 primop1
= get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
3731 if (TREE_CODE (primop0
) == INTEGER_CST
3732 || TREE_CODE (primop1
) == INTEGER_CST
)
3735 HOST_WIDE_INT constant
, mask
;
3739 if (TREE_CODE (primop0
) == INTEGER_CST
)
3742 unsignedp
= unsignedp1
;
3743 constant
= TREE_INT_CST_LOW (primop0
);
3748 unsignedp
= unsignedp0
;
3749 constant
= TREE_INT_CST_LOW (primop1
);
3752 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
3753 if (bits
< TYPE_PRECISION (result_type
)
3754 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
3756 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
3757 if ((mask
& constant
) != mask
)
3758 warning ("comparison of promoted ~unsigned with constant");
3761 else if (unsignedp0
&& unsignedp1
3762 && (TYPE_PRECISION (TREE_TYPE (primop0
))
3763 < TYPE_PRECISION (result_type
))
3764 && (TYPE_PRECISION (TREE_TYPE (primop1
))
3765 < TYPE_PRECISION (result_type
)))
3766 warning ("comparison of promoted ~unsigned with unsigned");
3771 /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
3772 If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
3773 Then the expression will be built.
3774 It will be given type FINAL_TYPE if that is nonzero;
3775 otherwise, it will be given type RESULT_TYPE. */
3779 cp_error ("invalid operands `%T' and `%T' to binary `%O'",
3780 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
), error_code
);
3781 return error_mark_node
;
3786 if (TREE_TYPE (op0
) != result_type
)
3787 op0
= cp_convert (result_type
, op0
);
3788 if (TREE_TYPE (op1
) != result_type
)
3789 op1
= cp_convert (result_type
, op1
);
3792 if (build_type
== NULL_TREE
)
3793 build_type
= result_type
;
3796 register tree result
= build (resultcode
, build_type
, op0
, op1
);
3797 register tree folded
;
3799 folded
= fold (result
);
3800 if (folded
== result
)
3801 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
3802 if (final_type
!= 0)
3803 return cp_convert (final_type
, folded
);
3808 /* Return a tree for the sum or difference (RESULTCODE says which)
3809 of pointer PTROP and integer INTOP. */
3812 pointer_int_sum (resultcode
, ptrop
, intop
)
3813 enum tree_code resultcode
;
3814 register tree ptrop
, intop
;
3818 register tree result
;
3819 register tree folded
= fold (intop
);
3821 /* The result is a pointer of the same type that is being added. */
3823 register tree result_type
= TREE_TYPE (ptrop
);
3825 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
3827 if (pedantic
|| warn_pointer_arith
)
3828 pedwarn ("ANSI C++ forbids using pointer of type `void *' in arithmetic");
3829 size_exp
= integer_one_node
;
3831 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
3833 if (pedantic
|| warn_pointer_arith
)
3834 pedwarn ("ANSI C++ forbids using pointer to a function in arithmetic");
3835 size_exp
= integer_one_node
;
3837 else if (TREE_CODE (TREE_TYPE (result_type
)) == METHOD_TYPE
)
3839 if (pedantic
|| warn_pointer_arith
)
3840 pedwarn ("ANSI C++ forbids using pointer to a method in arithmetic");
3841 size_exp
= integer_one_node
;
3843 else if (TREE_CODE (TREE_TYPE (result_type
)) == OFFSET_TYPE
)
3845 if (pedantic
|| warn_pointer_arith
)
3846 pedwarn ("ANSI C++ forbids using pointer to a member in arithmetic");
3847 size_exp
= integer_one_node
;
3850 size_exp
= size_in_bytes (complete_type (TREE_TYPE (result_type
)));
3852 /* Needed to make OOPS V2R3 work. */
3854 if (TREE_CODE (intop
) == INTEGER_CST
3855 && TREE_INT_CST_LOW (intop
) == 0
3856 && TREE_INT_CST_HIGH (intop
) == 0)
3859 /* If what we are about to multiply by the size of the elements
3860 contains a constant term, apply distributive law
3861 and multiply that constant term separately.
3862 This helps produce common subexpressions. */
3864 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
3865 && ! TREE_CONSTANT (intop
)
3866 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
3867 && TREE_CONSTANT (size_exp
))
3869 enum tree_code subcode
= resultcode
;
3870 if (TREE_CODE (intop
) == MINUS_EXPR
)
3871 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
3872 ptrop
= build_binary_op (subcode
, ptrop
, TREE_OPERAND (intop
, 1), 1);
3873 intop
= TREE_OPERAND (intop
, 0);
3876 /* Convert the integer argument to a type the same size as sizetype
3877 so the multiply won't overflow spuriously. */
3879 if (TYPE_PRECISION (TREE_TYPE (intop
)) != TYPE_PRECISION (sizetype
))
3880 intop
= cp_convert (type_for_size (TYPE_PRECISION (sizetype
), 0), intop
);
3882 /* Replace the integer argument with a suitable product by the object size.
3883 Do this multiplication as signed, then convert to the appropriate
3884 pointer type (actually unsigned integral). */
3886 intop
= cp_convert (result_type
,
3887 build_binary_op (MULT_EXPR
, intop
,
3888 cp_convert (TREE_TYPE (intop
), size_exp
), 1));
3890 /* Create the sum or difference. */
3892 result
= build (resultcode
, result_type
, ptrop
, intop
);
3894 folded
= fold (result
);
3895 if (folded
== result
)
3896 TREE_CONSTANT (folded
) = TREE_CONSTANT (ptrop
) & TREE_CONSTANT (intop
);
3900 /* Return a tree for the difference of pointers OP0 and OP1.
3901 The resulting tree has type int. */
3904 pointer_diff (op0
, op1
)
3905 register tree op0
, op1
;
3907 register tree result
, folded
;
3908 tree restype
= ptrdiff_type_node
;
3909 tree target_type
= TREE_TYPE (TREE_TYPE (op0
));
3911 if (pedantic
|| warn_pointer_arith
)
3913 if (TREE_CODE (target_type
) == VOID_TYPE
)
3914 pedwarn ("ANSI C++ forbids using pointer of type `void *' in subtraction");
3915 if (TREE_CODE (target_type
) == FUNCTION_TYPE
)
3916 pedwarn ("ANSI C++ forbids using pointer to a function in subtraction");
3917 if (TREE_CODE (target_type
) == METHOD_TYPE
)
3918 pedwarn ("ANSI C++ forbids using pointer to a method in subtraction");
3919 if (TREE_CODE (target_type
) == OFFSET_TYPE
)
3920 pedwarn ("ANSI C++ forbids using pointer to a member in subtraction");
3923 /* First do the subtraction as integers;
3924 then drop through to build the divide operator. */
3926 op0
= build_binary_op (MINUS_EXPR
,
3927 cp_convert (restype
, op0
), cp_convert (restype
, op1
), 1);
3929 /* This generates an error if op1 is a pointer to an incomplete type. */
3930 if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1
))) == 0)
3931 error ("arithmetic on pointer to an incomplete type");
3933 op1
= ((TREE_CODE (target_type
) == VOID_TYPE
3934 || TREE_CODE (target_type
) == FUNCTION_TYPE
3935 || TREE_CODE (target_type
) == METHOD_TYPE
3936 || TREE_CODE (target_type
) == OFFSET_TYPE
)
3938 : size_in_bytes (target_type
));
3940 /* Do the division. */
3942 result
= build (EXACT_DIV_EXPR
, restype
, op0
, cp_convert (restype
, op1
));
3944 folded
= fold (result
);
3945 if (folded
== result
)
3946 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
3950 /* Handle the case of taking the address of a COMPONENT_REF.
3951 Called by `build_unary_op' and `build_up_reference'.
3953 ARG is the COMPONENT_REF whose address we want.
3954 ARGTYPE is the pointer type that this address should have.
3955 MSG is an error message to print if this COMPONENT_REF is not
3956 addressable (such as a bitfield). */
3959 build_component_addr (arg
, argtype
, msg
)
3963 tree field
= TREE_OPERAND (arg
, 1);
3964 tree basetype
= decl_type_context (field
);
3965 tree rval
= build_unary_op (ADDR_EXPR
, TREE_OPERAND (arg
, 0), 0);
3967 if (DECL_BIT_FIELD (field
))
3969 error (msg
, IDENTIFIER_POINTER (DECL_NAME (field
)));
3970 return error_mark_node
;
3973 if (TREE_CODE (field
) == FIELD_DECL
3974 && TYPE_USES_COMPLEX_INHERITANCE (basetype
))
3976 /* Can't convert directly to ARGTYPE, since that
3977 may have the same pointer type as one of our
3979 rval
= build1 (NOP_EXPR
, argtype
,
3980 convert_pointer_to (basetype
, rval
));
3981 TREE_CONSTANT (rval
) = TREE_CONSTANT (TREE_OPERAND (rval
, 0));
3984 /* This conversion is harmless. */
3985 rval
= convert_force (argtype
, rval
, 0);
3987 if (! integer_zerop (DECL_FIELD_BITPOS (field
)))
3989 tree offset
= size_binop (EASY_DIV_EXPR
, DECL_FIELD_BITPOS (field
),
3990 size_int (BITS_PER_UNIT
));
3991 int flag
= TREE_CONSTANT (rval
);
3992 rval
= fold (build (PLUS_EXPR
, argtype
,
3993 rval
, cp_convert (argtype
, offset
)));
3994 TREE_CONSTANT (rval
) = flag
;
3999 /* Construct and perhaps optimize a tree representation
4000 for a unary operation. CODE, a tree_code, specifies the operation
4001 and XARG is the operand. */
4004 build_x_unary_op (code
, xarg
)
4005 enum tree_code code
;
4008 if (processing_template_decl
)
4009 return build_min_nt (code
, xarg
, NULL_TREE
);
4011 /* & rec, on incomplete RECORD_TYPEs is the simple opr &, not an
4013 if (code
== ADDR_EXPR
4014 && ((IS_AGGR_TYPE_CODE (TREE_CODE (TREE_TYPE (xarg
)))
4015 && TYPE_SIZE (TREE_TYPE (xarg
)) == NULL_TREE
)
4016 || (TREE_CODE (xarg
) == OFFSET_REF
)))
4017 /* don't look for a function */;
4022 if (flag_ansi_overloading
)
4024 rval
= build_new_op (code
, LOOKUP_NORMAL
, xarg
,
4025 NULL_TREE
, NULL_TREE
);
4026 if (rval
|| code
!= ADDR_EXPR
)
4031 rval
= build_opfncall (code
, LOOKUP_SPECULATIVELY
, xarg
,
4032 NULL_TREE
, NULL_TREE
);
4034 return build_opfncall (code
, LOOKUP_NORMAL
, xarg
,
4035 NULL_TREE
, NULL_TREE
);
4039 if (code
== ADDR_EXPR
)
4041 if (TREE_CODE (xarg
) == TARGET_EXPR
)
4042 warning ("taking address of temporary");
4045 return build_unary_op (code
, xarg
, 0);
4048 /* Just like truthvalue_conversion, but we want a CLEANUP_POINT_EXPR. */
4051 condition_conversion (expr
)
4055 if (processing_template_decl
)
4057 t
= cp_convert (boolean_type_node
, expr
);
4058 t
= fold (build1 (CLEANUP_POINT_EXPR
, boolean_type_node
, t
));
4062 /* C++: Must handle pointers to members.
4064 Perhaps type instantiation should be extended to handle conversion
4065 from aggregates to types we don't yet know we want? (Or are those
4066 cases typically errors which should be reported?)
4068 NOCONVERT nonzero suppresses the default promotions
4069 (such as from short to int). */
4072 build_unary_op (code
, xarg
, noconvert
)
4073 enum tree_code code
;
4077 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
4078 register tree arg
= xarg
;
4079 register tree argtype
= 0;
4080 char *errstring
= NULL
;
4083 if (arg
== error_mark_node
)
4084 return error_mark_node
;
4089 /* This is used for unary plus, because a CONVERT_EXPR
4090 is enough to prevent anybody from looking inside for
4091 associativity, but won't generate any code. */
4092 if (!(arg
= build_expr_type_conversion
4093 (WANT_ARITH
| WANT_ENUM
| WANT_POINTER
, arg
, 1)))
4094 errstring
= "wrong type argument to unary plus";
4098 arg
= default_conversion (arg
);
4099 arg
= build1 (NON_LVALUE_EXPR
, TREE_TYPE (arg
), arg
);
4104 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
4105 errstring
= "wrong type argument to unary minus";
4106 else if (!noconvert
)
4107 arg
= default_conversion (arg
);
4111 if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
4115 arg
= default_conversion (arg
);
4117 else if (!(arg
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
,
4119 errstring
= "wrong type argument to bit-complement";
4120 else if (!noconvert
)
4121 arg
= default_conversion (arg
);
4125 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
4126 errstring
= "wrong type argument to abs";
4127 else if (!noconvert
)
4128 arg
= default_conversion (arg
);
4132 /* Conjugating a real value is a no-op, but allow it anyway. */
4133 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
4134 errstring
= "wrong type argument to conjugation";
4135 else if (!noconvert
)
4136 arg
= default_conversion (arg
);
4139 case TRUTH_NOT_EXPR
:
4140 arg
= cp_convert (boolean_type_node
, arg
);
4141 val
= invert_truthvalue (arg
);
4142 if (arg
!= error_mark_node
)
4144 errstring
= "in argument to unary !";
4151 if (TREE_CODE (arg
) == COMPLEX_CST
)
4152 return TREE_REALPART (arg
);
4153 else if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
4154 return fold (build1 (REALPART_EXPR
, TREE_TYPE (TREE_TYPE (arg
)), arg
));
4159 if (TREE_CODE (arg
) == COMPLEX_CST
)
4160 return TREE_IMAGPART (arg
);
4161 else if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
4162 return fold (build1 (IMAGPART_EXPR
, TREE_TYPE (TREE_TYPE (arg
)), arg
));
4164 return cp_convert (TREE_TYPE (arg
), integer_zero_node
);
4166 case PREINCREMENT_EXPR
:
4167 case POSTINCREMENT_EXPR
:
4168 case PREDECREMENT_EXPR
:
4169 case POSTDECREMENT_EXPR
:
4170 /* Handle complex lvalues (when permitted)
4171 by reduction to simpler cases. */
4173 val
= unary_complex_lvalue (code
, arg
);
4177 /* Increment or decrement the real part of the value,
4178 and don't change the imaginary part. */
4179 if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
4183 arg
= stabilize_reference (arg
);
4184 real
= build_unary_op (REALPART_EXPR
, arg
, 1);
4185 imag
= build_unary_op (IMAGPART_EXPR
, arg
, 1);
4186 return build (COMPLEX_EXPR
, TREE_TYPE (arg
),
4187 build_unary_op (code
, real
, 1), imag
);
4190 /* Report invalid types. */
4192 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_POINTER
,
4195 if (code
== PREINCREMENT_EXPR
)
4196 errstring
="no pre-increment operator for type";
4197 else if (code
== POSTINCREMENT_EXPR
)
4198 errstring
="no post-increment operator for type";
4199 else if (code
== PREDECREMENT_EXPR
)
4200 errstring
="no pre-decrement operator for type";
4202 errstring
="no post-decrement operator for type";
4206 /* Report something read-only. */
4208 if (TYPE_READONLY (TREE_TYPE (arg
))
4209 || TREE_READONLY (arg
))
4210 readonly_error (arg
, ((code
== PREINCREMENT_EXPR
4211 || code
== POSTINCREMENT_EXPR
)
4212 ? "increment" : "decrement"),
4217 tree result_type
= TREE_TYPE (arg
);
4219 arg
= get_unwidened (arg
, 0);
4220 argtype
= TREE_TYPE (arg
);
4222 /* ARM $5.2.5 last annotation says this should be forbidden. */
4223 if (TREE_CODE (argtype
) == ENUMERAL_TYPE
)
4224 pedwarn ("ANSI C++ forbids %sing an enum",
4225 (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
4226 ? "increment" : "decrement");
4228 /* Compute the increment. */
4230 if (TREE_CODE (argtype
) == POINTER_TYPE
)
4232 enum tree_code tmp
= TREE_CODE (TREE_TYPE (argtype
));
4233 if (TYPE_SIZE (complete_type (TREE_TYPE (argtype
))) == 0)
4234 cp_error ("cannot %s a pointer to incomplete type `%T'",
4235 ((code
== PREINCREMENT_EXPR
4236 || code
== POSTINCREMENT_EXPR
)
4237 ? "increment" : "decrement"), TREE_TYPE (argtype
));
4238 else if (tmp
== FUNCTION_TYPE
|| tmp
== METHOD_TYPE
4239 || tmp
== VOID_TYPE
|| tmp
== OFFSET_TYPE
)
4240 cp_pedwarn ("ANSI C++ forbids %sing a pointer of type `%T'",
4241 ((code
== PREINCREMENT_EXPR
4242 || code
== POSTINCREMENT_EXPR
)
4243 ? "increment" : "decrement"), argtype
);
4244 inc
= c_sizeof_nowarn (TREE_TYPE (argtype
));
4247 inc
= integer_one_node
;
4249 inc
= cp_convert (argtype
, inc
);
4251 /* Handle incrementing a cast-expression. */
4253 switch (TREE_CODE (arg
))
4258 case FIX_TRUNC_EXPR
:
4259 case FIX_FLOOR_EXPR
:
4260 case FIX_ROUND_EXPR
:
4263 tree incremented
, modify
, value
, compound
;
4264 if (! lvalue_p (arg
) && pedantic
)
4265 pedwarn ("cast to non-reference type used as lvalue");
4266 arg
= stabilize_reference (arg
);
4267 if (code
== PREINCREMENT_EXPR
|| code
== PREDECREMENT_EXPR
)
4270 value
= save_expr (arg
);
4271 incremented
= build (((code
== PREINCREMENT_EXPR
4272 || code
== POSTINCREMENT_EXPR
)
4273 ? PLUS_EXPR
: MINUS_EXPR
),
4274 argtype
, value
, inc
);
4275 TREE_SIDE_EFFECTS (incremented
) = 1;
4277 modify
= build_modify_expr (arg
, NOP_EXPR
, incremented
);
4278 compound
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), modify
, value
);
4280 /* Eliminate warning about unused result of + or -. */
4281 TREE_NO_UNUSED_WARNING (compound
) = 1;
4286 /* Complain about anything else that is not a true lvalue. */
4287 if (!lvalue_or_else (arg
, ((code
== PREINCREMENT_EXPR
4288 || code
== POSTINCREMENT_EXPR
)
4289 ? "increment" : "decrement")))
4290 return error_mark_node
;
4292 /* Forbid using -- on `bool'. */
4293 if (TREE_TYPE (arg
) == boolean_type_node
)
4295 if (code
== POSTDECREMENT_EXPR
|| code
== PREDECREMENT_EXPR
)
4297 cp_error ("invalid use of `--' on bool variable `%D'", arg
);
4298 return error_mark_node
;
4301 /* This will only work if someone can convince Kenner to accept
4302 my patch to expand_increment. (jason) */
4303 val
= build (code
, TREE_TYPE (arg
), arg
, inc
);
4305 if (code
== POSTINCREMENT_EXPR
)
4307 arg
= stabilize_reference (arg
);
4308 val
= build (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
4310 TREE_SIDE_EFFECTS (val
) = 1;
4311 arg
= save_expr (arg
);
4312 val
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
4313 val
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
4316 val
= build (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
4321 val
= build (code
, TREE_TYPE (arg
), arg
, inc
);
4323 TREE_SIDE_EFFECTS (val
) = 1;
4324 return cp_convert (result_type
, val
);
4328 /* Note that this operation never does default_conversion
4329 regardless of NOCONVERT. */
4331 argtype
= TREE_TYPE (arg
);
4332 if (TREE_CODE (argtype
) == REFERENCE_TYPE
)
4336 build_pointer_type (TREE_TYPE (TREE_TYPE (arg
))), arg
);
4337 TREE_CONSTANT (arg
) = TREE_CONSTANT (TREE_OPERAND (arg
, 0));
4341 && TREE_CODE (arg
) == FUNCTION_DECL
4343 && DECL_CONTEXT (arg
) == NULL_TREE
4344 && IDENTIFIER_LENGTH (DECL_NAME (arg
)) == 4
4345 && IDENTIFIER_POINTER (DECL_NAME (arg
))[0] == 'm'
4346 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (arg
)), "main"))
4348 pedwarn ("taking address of function `main'");
4350 /* Let &* cancel out to simplify resulting code. */
4351 if (TREE_CODE (arg
) == INDIRECT_REF
)
4353 /* We don't need to have `current_class_ptr' wrapped in a
4354 NON_LVALUE_EXPR node. */
4355 if (arg
== current_class_ref
)
4356 return current_class_ptr
;
4358 arg
= TREE_OPERAND (arg
, 0);
4359 if (TREE_CODE (TREE_TYPE (arg
)) == REFERENCE_TYPE
)
4363 build_pointer_type (TREE_TYPE (TREE_TYPE (arg
))), arg
);
4364 TREE_CONSTANT (arg
) = TREE_CONSTANT (TREE_OPERAND (arg
, 0));
4366 else if (lvalue_p (arg
))
4367 /* Don't let this be an lvalue. */
4368 return non_lvalue (arg
);
4372 /* For &x[y], return x+y */
4373 if (TREE_CODE (arg
) == ARRAY_REF
)
4375 if (mark_addressable (TREE_OPERAND (arg
, 0)) == 0)
4376 return error_mark_node
;
4377 return build_binary_op (PLUS_EXPR
, TREE_OPERAND (arg
, 0),
4378 TREE_OPERAND (arg
, 1), 1);
4381 /* Uninstantiated types are all functions. Taking the
4382 address of a function is a no-op, so just return the
4385 if (TREE_CODE (arg
) == IDENTIFIER_NODE
4386 && IDENTIFIER_OPNAME_P (arg
))
4388 my_friendly_abort (117);
4389 /* We don't know the type yet, so just work around the problem.
4390 We know that this will resolve to an lvalue. */
4391 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4394 if (TREE_CODE (arg
) == TREE_LIST
)
4396 if (TREE_CODE (TREE_VALUE (arg
)) == FUNCTION_DECL
4397 && DECL_CHAIN (TREE_VALUE (arg
)) == NULL_TREE
)
4398 /* Unique overloaded non-member function. */
4399 return build_unary_op (ADDR_EXPR
, TREE_VALUE (arg
), 0);
4400 if (TREE_CHAIN (arg
) == NULL_TREE
4401 && TREE_CODE (TREE_VALUE (arg
)) == TREE_LIST
4402 && DECL_CHAIN (TREE_VALUE (TREE_VALUE (arg
))) == NULL_TREE
)
4403 /* Unique overloaded member function. */
4404 return build_unary_op (ADDR_EXPR
, TREE_VALUE (TREE_VALUE (arg
)),
4406 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4409 /* Handle complex lvalues (when permitted)
4410 by reduction to simpler cases. */
4411 val
= unary_complex_lvalue (code
, arg
);
4415 switch (TREE_CODE (arg
))
4420 case FIX_TRUNC_EXPR
:
4421 case FIX_FLOOR_EXPR
:
4422 case FIX_ROUND_EXPR
:
4424 if (! lvalue_p (arg
) && pedantic
)
4425 pedwarn ("taking the address of a cast to non-reference type");
4428 /* Allow the address of a constructor if all the elements
4430 if (TREE_CODE (arg
) == CONSTRUCTOR
&& TREE_CONSTANT (arg
))
4432 /* Anything not already handled and not a true memory reference
4434 else if (TREE_CODE (argtype
) != FUNCTION_TYPE
4435 && TREE_CODE (argtype
) != METHOD_TYPE
4436 && !lvalue_or_else (arg
, "unary `&'"))
4437 return error_mark_node
;
4439 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
4440 /* If the lvalue is const or volatile,
4441 merge that into the type that the address will point to. */
4442 if (TREE_CODE_CLASS (TREE_CODE (arg
)) == 'd'
4443 || TREE_CODE_CLASS (TREE_CODE (arg
)) == 'r')
4445 if (TREE_READONLY (arg
) || TREE_THIS_VOLATILE (arg
))
4446 argtype
= cp_build_type_variant (argtype
,
4447 TREE_READONLY (arg
),
4448 TREE_THIS_VOLATILE (arg
));
4451 argtype
= build_pointer_type (argtype
);
4453 if (mark_addressable (arg
) == 0)
4454 return error_mark_node
;
4459 if (TREE_CODE (arg
) == COMPONENT_REF
)
4460 addr
= build_component_addr (arg
, argtype
,
4461 "attempt to take address of bit-field structure member `%s'");
4463 addr
= build1 (code
, argtype
, arg
);
4465 /* Address of a static or external variable or
4466 function counts as a constant */
4468 TREE_CONSTANT (addr
) = 1;
4470 if (TREE_CODE (argtype
) == POINTER_TYPE
4471 && TREE_CODE (TREE_TYPE (argtype
)) == METHOD_TYPE
)
4473 build_ptrmemfunc_type (argtype
);
4474 addr
= build_ptrmemfunc (argtype
, addr
, 0);
4484 argtype
= TREE_TYPE (arg
);
4485 return fold (build1 (code
, argtype
, arg
));
4489 return error_mark_node
;
4493 /* If CONVERSIONS is a conversion expression or a nested sequence of such,
4494 convert ARG with the same conversions in the same order
4495 and return the result. */
4498 convert_sequence (conversions
, arg
)
4502 switch (TREE_CODE (conversions
))
4507 case FIX_TRUNC_EXPR
:
4508 case FIX_FLOOR_EXPR
:
4509 case FIX_ROUND_EXPR
:
4511 return cp_convert (TREE_TYPE (conversions
),
4512 convert_sequence (TREE_OPERAND (conversions
, 0),
4521 /* Apply unary lvalue-demanding operator CODE to the expression ARG
4522 for certain kinds of expressions which are not really lvalues
4523 but which we can accept as lvalues.
4525 If ARG is not a kind of expression we can handle, return zero. */
4528 unary_complex_lvalue (code
, arg
)
4529 enum tree_code code
;
4532 /* Handle (a, b) used as an "lvalue". */
4533 if (TREE_CODE (arg
) == COMPOUND_EXPR
)
4535 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 1), 0);
4536 return build (COMPOUND_EXPR
, TREE_TYPE (real_result
),
4537 TREE_OPERAND (arg
, 0), real_result
);
4540 /* Handle (a ? b : c) used as an "lvalue". */
4541 if (TREE_CODE (arg
) == COND_EXPR
)
4542 return rationalize_conditional_expr (code
, arg
);
4544 if (TREE_CODE (arg
) == MODIFY_EXPR
4545 || TREE_CODE (arg
) == PREINCREMENT_EXPR
4546 || TREE_CODE (arg
) == PREDECREMENT_EXPR
)
4547 return unary_complex_lvalue
4548 (code
, build (COMPOUND_EXPR
, TREE_TYPE (TREE_OPERAND (arg
, 0)),
4549 arg
, TREE_OPERAND (arg
, 0)));
4551 if (code
!= ADDR_EXPR
)
4554 /* Handle (a = b) used as an "lvalue" for `&'. */
4555 if (TREE_CODE (arg
) == MODIFY_EXPR
4556 || TREE_CODE (arg
) == INIT_EXPR
)
4558 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 0), 0);
4559 arg
= build (COMPOUND_EXPR
, TREE_TYPE (real_result
), arg
, real_result
);
4560 TREE_NO_UNUSED_WARNING (arg
) = 1;
4564 if (TREE_CODE (TREE_TYPE (arg
)) == FUNCTION_TYPE
4565 || TREE_CODE (TREE_TYPE (arg
)) == METHOD_TYPE
4566 || TREE_CODE (TREE_TYPE (arg
)) == OFFSET_TYPE
)
4568 /* The representation of something of type OFFSET_TYPE
4569 is really the representation of a pointer to it.
4570 Here give the representation its true type. */
4573 my_friendly_assert (TREE_CODE (arg
) != SCOPE_REF
, 313);
4575 if (TREE_CODE (arg
) != OFFSET_REF
)
4578 t
= TREE_OPERAND (arg
, 1);
4580 if (TREE_CODE (t
) == FUNCTION_DECL
) /* Check all this code for right semantics. */
4581 return build_unary_op (ADDR_EXPR
, t
, 0);
4582 if (TREE_CODE (t
) == VAR_DECL
)
4583 return build_unary_op (ADDR_EXPR
, t
, 0);
4587 tree offset
= integer_zero_node
;
4589 if (TREE_OPERAND (arg
, 0)
4590 && (TREE_CODE (TREE_OPERAND (arg
, 0)) != NOP_EXPR
4591 || TREE_OPERAND (TREE_OPERAND (arg
, 0), 0) != error_mark_node
))
4592 if (TREE_CODE (t
) != FIELD_DECL
)
4594 /* Don't know if this should return address to just
4595 _DECL, or actual address resolved in this expression. */
4596 sorry ("address of bound pointer-to-member expression");
4597 return error_mark_node
;
4600 type
= TREE_TYPE (TREE_OPERAND (arg
, 0));
4602 if (TREE_CODE (TREE_TYPE (arg
)) == OFFSET_TYPE
)
4604 /* Add in the offset to the intermediate subobject, if any. */
4605 offset
= get_delta_difference (TYPE_OFFSET_BASETYPE (TREE_TYPE (arg
)),
4608 type
= TYPE_OFFSET_BASETYPE (TREE_TYPE (arg
));
4611 /* Now in the offset to the final subobject. */
4612 offset
= size_binop (PLUS_EXPR
,
4614 get_delta_difference (DECL_FIELD_CONTEXT (t
),
4618 /* Add in the offset to the field. */
4619 offset
= size_binop (PLUS_EXPR
, offset
,
4620 size_binop (EASY_DIV_EXPR
,
4621 DECL_FIELD_BITPOS (t
),
4622 size_int (BITS_PER_UNIT
)));
4624 /* We offset all pointer to data memebers by 1 so that we can
4625 distinguish between a null pointer to data member and the first
4626 data member of a structure. */
4627 offset
= size_binop (PLUS_EXPR
, offset
, size_int (1));
4629 return cp_convert (build_pointer_type (TREE_TYPE (arg
)), offset
);
4634 /* We permit compiler to make function calls returning
4635 objects of aggregate type look like lvalues. */
4639 if (TREE_CODE (targ
) == SAVE_EXPR
)
4640 targ
= TREE_OPERAND (targ
, 0);
4642 if (TREE_CODE (targ
) == CALL_EXPR
&& IS_AGGR_TYPE (TREE_TYPE (targ
)))
4644 if (TREE_CODE (arg
) == SAVE_EXPR
)
4647 targ
= build_cplus_new (TREE_TYPE (arg
), arg
);
4648 return build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (arg
)), targ
);
4651 if (TREE_CODE (arg
) == SAVE_EXPR
&& TREE_CODE (targ
) == INDIRECT_REF
)
4652 return build (SAVE_EXPR
, build_pointer_type (TREE_TYPE (arg
)),
4653 TREE_OPERAND (targ
, 0), current_function_decl
, NULL
);
4656 /* Don't let anything else be handled specially. */
4660 /* Mark EXP saying that we need to be able to take the
4661 address of it; it should not be allocated in a register.
4662 Value is 1 if successful.
4664 C++: we do not allow `current_class_ptr' to be addressable. */
4667 mark_addressable (exp
)
4670 register tree x
= exp
;
4672 if (TREE_ADDRESSABLE (x
) == 1)
4676 switch (TREE_CODE (x
))
4683 x
= TREE_OPERAND (x
, 0);
4687 if (x
== current_class_ptr
)
4689 if (! flag_this_is_variable
)
4690 error ("address of `this' not available");
4691 TREE_ADDRESSABLE (x
) = 1; /* so compiler doesn't die later */
4692 put_var_into_stack (x
);
4696 if (TREE_STATIC (x
) && TREE_READONLY (x
)
4697 && DECL_RTL (x
) != 0
4698 && ! DECL_IN_MEMORY_P (x
))
4700 /* We thought this would make a good constant variable,
4701 but we were wrong. */
4702 push_obstacks_nochange ();
4703 end_temporary_allocation ();
4705 TREE_ASM_WRITTEN (x
) = 0;
4707 rest_of_decl_compilation (x
, 0, IDENTIFIER_LOCAL_VALUE (x
) == 0, 0);
4708 TREE_ADDRESSABLE (x
) = 1;
4714 /* Caller should not be trying to mark initialized
4715 constant fields addressable. */
4716 my_friendly_assert (DECL_LANG_SPECIFIC (x
) == 0
4717 || DECL_IN_AGGR_P (x
) == 0
4719 || DECL_EXTERNAL (x
), 314);
4723 if (DECL_REGISTER (x
) && !TREE_ADDRESSABLE (x
)
4724 && !DECL_ARTIFICIAL (x
) && extra_warnings
)
4725 cp_warning ("address requested for `%D', which is declared `register'",
4727 put_var_into_stack (x
);
4728 TREE_ADDRESSABLE (x
) = 1;
4732 /* We have to test both conditions here. The first may
4733 be non-zero in the case of processing a default function.
4734 The second may be non-zero in the case of a template function. */
4735 x
= DECL_MAIN_VARIANT (x
);
4736 if ((DECL_THIS_INLINE (x
) || DECL_PENDING_INLINE_INFO (x
))
4737 && (DECL_CONTEXT (x
) == NULL_TREE
4738 || TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (x
))) != 't'
4739 || ! CLASSTYPE_INTERFACE_ONLY (DECL_CONTEXT (x
))))
4741 mark_inline_for_output (x
);
4742 if (x
== current_function_decl
)
4743 DECL_EXTERNAL (x
) = 0;
4745 TREE_ADDRESSABLE (x
) = 1;
4747 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x
)) = 1;
4751 TREE_ADDRESSABLE (x
) = 1;
4755 TREE_ADDRESSABLE (x
) = 1;
4756 mark_addressable (TREE_OPERAND (x
, 0));
4764 /* Build and return a conditional expression IFEXP ? OP1 : OP2. */
4767 build_x_conditional_expr (ifexp
, op1
, op2
)
4768 tree ifexp
, op1
, op2
;
4770 tree rval
= NULL_TREE
;
4772 if (processing_template_decl
)
4773 return build_min_nt (COND_EXPR
, ifexp
, op1
, op2
);
4775 if (flag_ansi_overloading
)
4776 return build_new_op (COND_EXPR
, LOOKUP_NORMAL
, ifexp
, op1
, op2
);
4778 /* See comments in `build_x_binary_op'. */
4780 rval
= build_opfncall (COND_EXPR
, LOOKUP_SPECULATIVELY
, ifexp
, op1
, op2
);
4782 return build_opfncall (COND_EXPR
, LOOKUP_NORMAL
, ifexp
, op1
, op2
);
4784 return build_conditional_expr (ifexp
, op1
, op2
);
4788 build_conditional_expr (ifexp
, op1
, op2
)
4789 tree ifexp
, op1
, op2
;
4791 register tree type1
;
4792 register tree type2
;
4793 register enum tree_code code1
;
4794 register enum tree_code code2
;
4795 register tree result_type
= NULL_TREE
;
4797 /* If second operand is omitted, it is the same as the first one;
4798 make sure it is calculated only once. */
4802 pedwarn ("ANSI C++ forbids omitting the middle term of a ?: expression");
4803 ifexp
= op1
= save_expr (ifexp
);
4806 ifexp
= cp_convert (boolean_type_node
, ifexp
);
4808 if (TREE_CODE (ifexp
) == ERROR_MARK
)
4809 return error_mark_node
;
4811 op1
= require_instantiated_type (TREE_TYPE (op2
), op1
, error_mark_node
);
4812 if (op1
== error_mark_node
)
4813 return error_mark_node
;
4814 op2
= require_instantiated_type (TREE_TYPE (op1
), op2
, error_mark_node
);
4815 if (op2
== error_mark_node
)
4816 return error_mark_node
;
4818 /* C++: REFERENCE_TYPES must be dereferenced. */
4819 type1
= TREE_TYPE (op1
);
4820 code1
= TREE_CODE (type1
);
4821 type2
= TREE_TYPE (op2
);
4822 code2
= TREE_CODE (type2
);
4824 if (code1
== REFERENCE_TYPE
)
4826 op1
= convert_from_reference (op1
);
4827 type1
= TREE_TYPE (op1
);
4828 code1
= TREE_CODE (type1
);
4830 if (code2
== REFERENCE_TYPE
)
4832 op2
= convert_from_reference (op2
);
4833 type2
= TREE_TYPE (op2
);
4834 code2
= TREE_CODE (type2
);
4837 /* Don't promote the operands separately if they promote
4838 the same way. Return the unpromoted type and let the combined
4839 value get promoted if necessary. */
4841 if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
)
4842 && code2
!= ARRAY_TYPE
4843 && code2
!= FUNCTION_TYPE
4844 && code2
!= METHOD_TYPE
)
4848 if (TREE_CONSTANT (ifexp
)
4849 && (TREE_CODE (ifexp
) == INTEGER_CST
4850 || TREE_CODE (ifexp
) == ADDR_EXPR
))
4851 return (integer_zerop (ifexp
) ? op2
: op1
);
4853 if (TREE_CODE (op1
) == CONST_DECL
)
4854 op1
= DECL_INITIAL (op1
);
4855 else if (TREE_READONLY_DECL_P (op1
))
4856 op1
= decl_constant_value (op1
);
4857 if (TREE_CODE (op2
) == CONST_DECL
)
4858 op2
= DECL_INITIAL (op2
);
4859 else if (TREE_READONLY_DECL_P (op2
))
4860 op2
= decl_constant_value (op2
);
4862 type1
= cp_build_type_variant
4864 TREE_READONLY (op1
) || TREE_READONLY (op2
),
4865 TREE_THIS_VOLATILE (op1
) || TREE_THIS_VOLATILE (op2
));
4866 /* ??? This is a kludge to deal with the fact that
4867 we don't sort out integers and enums properly, yet. */
4868 result
= fold (build (COND_EXPR
, type1
, ifexp
, op1
, op2
));
4869 if (TREE_TYPE (result
) != type1
)
4870 result
= build1 (NOP_EXPR
, type1
, result
);
4871 /* Expand both sides into the same slot,
4872 hopefully the target of the ?: expression. */
4873 if (TREE_CODE (op1
) == TARGET_EXPR
&& TREE_CODE (op2
) == TARGET_EXPR
)
4875 tree slot
= build (VAR_DECL
, TREE_TYPE (result
));
4876 layout_decl (slot
, 0);
4877 result
= build (TARGET_EXPR
, TREE_TYPE (result
),
4878 slot
, result
, NULL_TREE
, NULL_TREE
);
4883 /* They don't match; promote them both and then try to reconcile them.
4884 But don't permit mismatching enum types. */
4885 if (code1
== ENUMERAL_TYPE
)
4887 if (code2
== ENUMERAL_TYPE
)
4889 cp_error ("enumeral mismatch in conditional expression: `%T' vs `%T'", type1
, type2
);
4890 return error_mark_node
;
4892 else if (extra_warnings
&& ! IS_AGGR_TYPE_CODE (code2
)
4893 && type2
!= type_promotes_to (type1
))
4894 warning ("enumeral and non-enumeral type in conditional expression");
4896 else if (extra_warnings
4897 && code2
== ENUMERAL_TYPE
&& ! IS_AGGR_TYPE_CODE (code1
)
4898 && type1
!= type_promotes_to (type2
))
4899 warning ("enumeral and non-enumeral type in conditional expression");
4901 if (code1
!= VOID_TYPE
)
4903 op1
= default_conversion (op1
);
4904 type1
= TREE_TYPE (op1
);
4905 if (TYPE_PTRMEMFUNC_P (type1
))
4906 type1
= TYPE_PTRMEMFUNC_FN_TYPE (type1
);
4907 code1
= TREE_CODE (type1
);
4909 if (code2
!= VOID_TYPE
)
4911 op2
= default_conversion (op2
);
4912 type2
= TREE_TYPE (op2
);
4913 if (TYPE_PTRMEMFUNC_P (type2
))
4914 type2
= TYPE_PTRMEMFUNC_FN_TYPE (type2
);
4915 code2
= TREE_CODE (type2
);
4918 if (code1
== RECORD_TYPE
&& code2
== RECORD_TYPE
4919 && real_lvalue_p (op1
) && real_lvalue_p (op2
)
4920 && comptypes (type1
, type2
, -1))
4922 type1
= build_reference_type (type1
);
4923 type2
= build_reference_type (type2
);
4924 result_type
= common_type (type1
, type2
);
4925 op1
= convert_to_reference (result_type
, op1
, CONV_IMPLICIT
,
4926 LOOKUP_NORMAL
, NULL_TREE
);
4927 op2
= convert_to_reference (result_type
, op2
, CONV_IMPLICIT
,
4928 LOOKUP_NORMAL
, NULL_TREE
);
4930 /* Quickly detect the usual case where op1 and op2 have the same type
4932 else if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
))
4935 result_type
= type1
;
4937 result_type
= cp_build_type_variant
4939 TREE_READONLY (op1
) || TREE_READONLY (op2
),
4940 TREE_THIS_VOLATILE (op1
) || TREE_THIS_VOLATILE (op2
));
4942 else if ((code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
)
4943 && (code2
== INTEGER_TYPE
|| code2
== REAL_TYPE
))
4945 result_type
= common_type (type1
, type2
);
4947 else if (code1
== VOID_TYPE
|| code2
== VOID_TYPE
)
4949 if (pedantic
&& (code1
!= VOID_TYPE
|| code2
!= VOID_TYPE
))
4950 pedwarn ("ANSI C++ forbids conditional expr with only one void side");
4951 result_type
= void_type_node
;
4953 else if (code1
== POINTER_TYPE
&& null_ptr_cst_p (op2
))
4954 result_type
= qualify_type (type1
, type2
);
4955 else if (code2
== POINTER_TYPE
&& null_ptr_cst_p (op1
))
4956 result_type
= qualify_type (type2
, type1
);
4957 else if (code1
== POINTER_TYPE
&& code2
== POINTER_TYPE
)
4959 if (comp_target_types (type1
, type2
, 1))
4960 result_type
= common_type (type1
, type2
);
4961 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1
)) == void_type_node
)
4963 if (pedantic
&& TREE_CODE (type2
) == FUNCTION_TYPE
)
4964 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
4965 result_type
= qualify_type (type1
, type2
);
4967 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2
)) == void_type_node
)
4969 if (pedantic
&& TREE_CODE (type1
) == FUNCTION_TYPE
)
4970 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
4971 result_type
= qualify_type (type2
, type1
);
4974 else if (comptypes (type2
, type1
, 0))
4975 result_type
= type2
;
4976 else if (IS_AGGR_TYPE (TREE_TYPE (type1
))
4977 && IS_AGGR_TYPE (TREE_TYPE (type2
))
4978 && (result_type
= common_base_type (TREE_TYPE (type1
), TREE_TYPE (type2
))))
4980 if (result_type
== error_mark_node
)
4982 cp_error ("common base type of types `%T' and `%T' is ambiguous",
4983 TREE_TYPE (type1
), TREE_TYPE (type2
));
4984 result_type
= ptr_type_node
;
4989 && result_type
!= TREE_TYPE (type1
)
4990 && result_type
!= TREE_TYPE (type2
))
4991 cp_pedwarn ("`%T' and `%T' converted to `%T *' in conditional expression",
4992 type1
, type2
, result_type
);
4994 result_type
= build_pointer_type (result_type
);
4999 pedwarn ("pointer type mismatch in conditional expression");
5000 result_type
= ptr_type_node
;
5003 else if (code1
== POINTER_TYPE
&& code2
== INTEGER_TYPE
)
5005 pedwarn ("pointer/integer type mismatch in conditional expression");
5006 result_type
= type1
;
5008 else if (code2
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
5010 pedwarn ("pointer/integer type mismatch in conditional expression");
5011 result_type
= type2
;
5016 /* The match does not look good. If either is
5017 an aggregate value, try converting to a scalar type. */
5018 if (code1
== RECORD_TYPE
&& code2
== RECORD_TYPE
)
5020 cp_error ("aggregate mismatch in conditional expression: `%T' vs `%T'", type1
, type2
);
5021 return error_mark_node
;
5023 /* Warning: this code assumes that conversion between cv-variants of
5024 a type is done using NOP_EXPRs. */
5025 if (code1
== RECORD_TYPE
&& TYPE_HAS_CONVERSION (type1
))
5027 /* There are other types besides pointers and records. */
5029 if (code2
== POINTER_TYPE
)
5030 tmp
= build_pointer_type
5031 (build_type_variant (TREE_TYPE (type2
), 1, 1));
5034 tmp
= build_type_conversion (CONVERT_EXPR
, tmp
, op1
, 0);
5035 if (tmp
== NULL_TREE
)
5037 cp_error ("incompatible types `%T' and `%T' in `?:'",
5039 return error_mark_node
;
5041 if (tmp
== error_mark_node
)
5042 error ("ambiguous pointer conversion");
5045 result_type
= common_type (type2
, TREE_TYPE (tmp
));
5048 else if (code2
== RECORD_TYPE
&& TYPE_HAS_CONVERSION (type2
))
5051 if (code1
== POINTER_TYPE
)
5052 tmp
= build_pointer_type
5053 (build_type_variant (TREE_TYPE (type1
), 1, 1));
5057 tmp
= build_type_conversion (CONVERT_EXPR
, tmp
, op2
, 0);
5058 if (tmp
== NULL_TREE
)
5060 cp_error ("incompatible types `%T' and `%T' in `?:'",
5062 return error_mark_node
;
5064 if (tmp
== error_mark_node
)
5065 error ("ambiguous pointer conversion");
5068 result_type
= common_type (type1
, TREE_TYPE (tmp
));
5071 else if (flag_cond_mismatch
)
5072 result_type
= void_type_node
;
5075 error ("type mismatch in conditional expression");
5076 return error_mark_node
;
5080 if (TREE_CODE (result_type
) == POINTER_TYPE
5081 && TREE_CODE (TREE_TYPE (result_type
)) == METHOD_TYPE
)
5082 result_type
= build_ptrmemfunc_type (result_type
);
5084 if (result_type
!= TREE_TYPE (op1
))
5085 op1
= convert_and_check (result_type
, op1
);
5086 if (result_type
!= TREE_TYPE (op2
))
5087 op2
= convert_and_check (result_type
, op2
);
5089 if (TREE_CONSTANT (ifexp
))
5090 return integer_zerop (ifexp
) ? op2
: op1
;
5092 return convert_from_reference
5093 (fold (build (COND_EXPR
, result_type
, ifexp
, op1
, op2
)));
5096 /* Handle overloading of the ',' operator when needed. Otherwise,
5097 this function just builds an expression list. */
5100 build_x_compound_expr (list
)
5103 tree rest
= TREE_CHAIN (list
);
5106 if (processing_template_decl
)
5107 return build_min_nt (COMPOUND_EXPR
, list
, NULL_TREE
);
5109 if (rest
== NULL_TREE
)
5110 return build_compound_expr (list
);
5112 result
= build_opfncall (COMPOUND_EXPR
, LOOKUP_NORMAL
,
5113 TREE_VALUE (list
), TREE_VALUE (rest
), NULL_TREE
);
5115 return build_x_compound_expr (tree_cons (NULL_TREE
, result
, TREE_CHAIN (rest
)));
5117 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list
)))
5119 /* the left-hand operand of a comma expression is like an expression
5120 statement: we should warn if it doesn't have any side-effects,
5121 unless it was explicitly cast to (void). */
5122 if ((extra_warnings
|| warn_unused
)
5123 && !(TREE_CODE (TREE_VALUE(list
)) == CONVERT_EXPR
5124 && TREE_TYPE (TREE_VALUE(list
)) == void_type_node
))
5125 warning("left-hand operand of comma expression has no effect");
5127 #if 0 /* this requires a gcc backend patch to export warn_if_unused_value */
5128 else if (warn_unused
)
5129 warn_if_unused_value (TREE_VALUE(list
));
5132 return build_compound_expr (tree_cons (NULL_TREE
, TREE_VALUE (list
),
5133 build_tree_list (NULL_TREE
, build_x_compound_expr (rest
))));
5136 /* Given a list of expressions, return a compound expression
5137 that performs them all and returns the value of the last of them. */
5140 build_compound_expr (list
)
5145 if (TREE_READONLY_DECL_P (TREE_VALUE (list
)))
5146 TREE_VALUE (list
) = decl_constant_value (TREE_VALUE (list
));
5148 if (TREE_CHAIN (list
) == 0)
5150 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5151 Strip such NOP_EXPRs, since LIST is used in non-lvalue context. */
5152 if (TREE_CODE (list
) == NOP_EXPR
5153 && TREE_TYPE (list
) == TREE_TYPE (TREE_OPERAND (list
, 0)))
5154 list
= TREE_OPERAND (list
, 0);
5156 /* Convert arrays to pointers. */
5157 if (TREE_CODE (TREE_TYPE (TREE_VALUE (list
))) == ARRAY_TYPE
)
5158 return default_conversion (TREE_VALUE (list
));
5160 return TREE_VALUE (list
);
5163 rest
= build_compound_expr (TREE_CHAIN (list
));
5165 /* When pedantic, a compound expression cannot be a constant expression. */
5166 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list
)) && ! pedantic
)
5169 return build (COMPOUND_EXPR
, TREE_TYPE (rest
),
5170 break_out_cleanups (TREE_VALUE (list
)), rest
);
5174 build_static_cast (type
, expr
)
5180 if (type
== error_mark_node
|| expr
== error_mark_node
)
5181 return error_mark_node
;
5183 if (TREE_CODE (expr
) == OFFSET_REF
)
5184 expr
= resolve_offset_ref (expr
);
5186 if (processing_template_decl
)
5188 tree t
= build_min (STATIC_CAST_EXPR
, type
, expr
);
5192 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5193 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5194 if (TREE_CODE (type
) != REFERENCE_TYPE
5195 && TREE_CODE (expr
) == NOP_EXPR
5196 && TREE_TYPE (expr
) == TREE_TYPE (TREE_OPERAND (expr
, 0)))
5197 expr
= TREE_OPERAND (expr
, 0);
5199 if (TREE_CODE (type
) == VOID_TYPE
)
5200 return build1 (CONVERT_EXPR
, type
, expr
);
5202 if (type_unknown_p (expr
))
5204 expr
= instantiate_type (type
, expr
, 1);
5205 if (expr
== error_mark_node
)
5206 return error_mark_node
;
5209 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5210 return (convert_from_reference
5211 (convert_to_reference (type
, expr
, CONV_STATIC
|CONV_IMPLICIT
,
5212 LOOKUP_COMPLAIN
, NULL_TREE
)));
5214 if (IS_AGGR_TYPE (type
))
5215 return build_cplus_new
5216 (type
, (build_method_call
5217 (NULL_TREE
, ctor_identifier
, build_tree_list (NULL_TREE
, expr
),
5218 TYPE_BINFO (type
), LOOKUP_NORMAL
)));
5220 expr
= decay_conversion (expr
);
5221 intype
= TREE_TYPE (expr
);
5223 /* FIXME handle casting to array type. */
5226 if (can_convert_arg (type
, intype
, expr
))
5228 else if (TYPE_PTROB_P (type
) && TYPE_PTROB_P (intype
))
5231 if (IS_AGGR_TYPE (TREE_TYPE (type
)) && IS_AGGR_TYPE (TREE_TYPE (intype
))
5232 && (TYPE_READONLY (TREE_TYPE (type
))
5233 >= TYPE_READONLY (TREE_TYPE (intype
)))
5234 && (TYPE_VOLATILE (TREE_TYPE (type
))
5235 >= TYPE_VOLATILE (TREE_TYPE (intype
)))
5236 && (binfo
= get_binfo (TREE_TYPE (intype
), TREE_TYPE (type
), 0))
5237 && ! TREE_VIA_VIRTUAL (binfo
))
5240 else if (TYPE_PTRMEM_P (type
) && TYPE_PTRMEM_P (intype
))
5242 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
))),
5243 TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (intype
))), 1)
5244 && (TYPE_READONLY (TREE_TYPE (TREE_TYPE (type
)))
5245 >= TYPE_READONLY (TREE_TYPE (TREE_TYPE (intype
))))
5246 && (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (type
)))
5247 >= TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (intype
))))
5248 && (binfo
= get_binfo (TYPE_OFFSET_BASETYPE (intype
),
5249 TYPE_OFFSET_BASETYPE (type
), 0))
5250 && ! TREE_VIA_VIRTUAL (binfo
))
5253 else if (TREE_CODE (intype
) != BOOLEAN_TYPE
5254 && TREE_CODE (type
) != ARRAY_TYPE
5255 && TREE_CODE (type
) != FUNCTION_TYPE
5256 && can_convert (intype
, type
))
5260 return build_c_cast (type
, expr
);
5262 cp_error ("static_cast from `%T' to `%T'", intype
, type
);
5263 return error_mark_node
;
5267 build_reinterpret_cast (type
, expr
)
5272 if (type
== error_mark_node
|| expr
== error_mark_node
)
5273 return error_mark_node
;
5275 if (TREE_CODE (expr
) == OFFSET_REF
)
5276 expr
= resolve_offset_ref (expr
);
5278 if (processing_template_decl
)
5280 tree t
= build_min (REINTERPRET_CAST_EXPR
, type
, expr
);
5284 if (TREE_CODE (type
) != REFERENCE_TYPE
)
5286 expr
= decay_conversion (expr
);
5288 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5289 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5290 if (TREE_CODE (expr
) == NOP_EXPR
5291 && TREE_TYPE (expr
) == TREE_TYPE (TREE_OPERAND (expr
, 0)))
5292 expr
= TREE_OPERAND (expr
, 0);
5295 if (type_unknown_p (expr
))
5297 expr
= instantiate_type (type
, expr
, 1);
5298 if (expr
== error_mark_node
)
5299 return error_mark_node
;
5302 intype
= TREE_TYPE (expr
);
5304 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5306 if (! real_lvalue_p (expr
))
5308 cp_error ("reinterpret_cast from `%T' rvalue to `%T'", intype
, type
);
5309 return error_mark_node
;
5311 expr
= build_unary_op (ADDR_EXPR
, expr
, 0);
5312 if (expr
!= error_mark_node
)
5313 expr
= build_reinterpret_cast
5314 (build_pointer_type (TREE_TYPE (type
)), expr
);
5315 if (expr
!= error_mark_node
)
5316 expr
= build_indirect_ref (expr
, 0);
5319 else if (comptypes (TYPE_MAIN_VARIANT (intype
), TYPE_MAIN_VARIANT (type
), 1))
5320 return build_static_cast (type
, expr
);
5322 if (TYPE_PTR_P (type
) && (TREE_CODE (intype
) == INTEGER_TYPE
5323 || TREE_CODE (intype
) == ENUMERAL_TYPE
))
5325 else if (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_PTR_P (intype
))
5327 if (TYPE_PRECISION (type
) < TYPE_PRECISION (intype
))
5328 cp_pedwarn ("reinterpret_cast from `%T' to `%T' loses precision",
5331 else if ((TYPE_PTRFN_P (type
) && TYPE_PTRFN_P (intype
))
5332 || (TYPE_PTRMEMFUNC_P (type
) && TYPE_PTRMEMFUNC_P (intype
)))
5334 if (TREE_READONLY_DECL_P (expr
))
5335 expr
= decl_constant_value (expr
);
5336 return fold (build1 (NOP_EXPR
, type
, expr
));
5338 else if ((TYPE_PTRMEM_P (type
) && TYPE_PTRMEM_P (intype
))
5339 || (TYPE_PTROBV_P (type
) && TYPE_PTROBV_P (intype
)))
5341 if (! comp_ptr_ttypes_reinterpret (TREE_TYPE (type
), TREE_TYPE (intype
)))
5342 cp_pedwarn ("reinterpret_cast from `%T' to `%T' casts away const (or volatile)",
5345 if (TREE_READONLY_DECL_P (expr
))
5346 expr
= decl_constant_value (expr
);
5347 return fold (build1 (NOP_EXPR
, type
, expr
));
5351 cp_error ("reinterpret_cast from `%T' to `%T'", intype
, type
);
5352 return error_mark_node
;
5355 return cp_convert (type
, expr
);
5359 build_const_cast (type
, expr
)
5364 if (type
== error_mark_node
|| expr
== error_mark_node
)
5365 return error_mark_node
;
5367 if (TREE_CODE (expr
) == OFFSET_REF
)
5368 expr
= resolve_offset_ref (expr
);
5370 if (processing_template_decl
)
5372 tree t
= build_min (CONST_CAST_EXPR
, type
, expr
);
5376 if (TREE_CODE (type
) != REFERENCE_TYPE
)
5378 expr
= decay_conversion (expr
);
5380 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5381 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5382 if (TREE_CODE (expr
) == NOP_EXPR
5383 && TREE_TYPE (expr
) == TREE_TYPE (TREE_OPERAND (expr
, 0)))
5384 expr
= TREE_OPERAND (expr
, 0);
5387 if (type_unknown_p (expr
))
5389 expr
= instantiate_type (type
, expr
, 1);
5390 if (expr
== error_mark_node
)
5391 return error_mark_node
;
5394 intype
= TREE_TYPE (expr
);
5396 if (comptypes (TYPE_MAIN_VARIANT (intype
), TYPE_MAIN_VARIANT (type
), 1))
5397 return build_static_cast (type
, expr
);
5398 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
5400 if (! real_lvalue_p (expr
))
5402 cp_error ("const_cast from `%T' rvalue to `%T'", intype
, type
);
5403 return error_mark_node
;
5406 if (comp_ptr_ttypes_const (TREE_TYPE (type
), intype
))
5407 return (convert_from_reference
5408 (convert_to_reference (type
, expr
, CONV_CONST
|CONV_IMPLICIT
,
5409 LOOKUP_COMPLAIN
, NULL_TREE
)));
5411 else if (TREE_CODE (type
) == POINTER_TYPE
5412 && TREE_CODE (intype
) == POINTER_TYPE
5413 && comp_ptr_ttypes_const (TREE_TYPE (type
), TREE_TYPE (intype
)))
5414 return cp_convert (type
, expr
);
5416 cp_error ("const_cast from `%T' to `%T'", intype
, type
);
5417 return error_mark_node
;
5420 /* Build an expression representing a cast to type TYPE of expression EXPR.
5422 ALLOW_NONCONVERTING is true if we should allow non-converting constructors
5423 when doing the cast. */
5426 build_c_cast (type
, expr
)
5429 register tree value
= expr
;
5431 if (type
== error_mark_node
|| expr
== error_mark_node
)
5432 return error_mark_node
;
5434 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5435 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5436 if (TREE_CODE (type
) != REFERENCE_TYPE
5437 && TREE_CODE (value
) == NOP_EXPR
5438 && TREE_TYPE (value
) == TREE_TYPE (TREE_OPERAND (value
, 0)))
5439 value
= TREE_OPERAND (value
, 0);
5441 if (TREE_TYPE (expr
)
5442 && TREE_CODE (TREE_TYPE (expr
)) == OFFSET_TYPE
5443 && TREE_CODE (type
) != OFFSET_TYPE
)
5444 value
= resolve_offset_ref (value
);
5446 if (TREE_CODE (type
) == ARRAY_TYPE
)
5448 /* Allow casting from T1* to T2[] because Cfront allows it.
5449 NIHCL uses it. It is not valid ANSI C however, and hence, not
5451 if (TREE_CODE (TREE_TYPE (expr
)) == POINTER_TYPE
)
5454 pedwarn ("ANSI C++ forbids casting to an array type");
5455 type
= build_pointer_type (TREE_TYPE (type
));
5459 error ("ANSI C++ forbids casting to an array type");
5460 return error_mark_node
;
5464 if (TREE_CODE (type
) == FUNCTION_TYPE
5465 || TREE_CODE (type
) == METHOD_TYPE
)
5467 cp_error ("casting to function type `%T'", type
);
5468 return error_mark_node
;
5471 if (IS_SIGNATURE (type
))
5473 error ("cast specifies signature type");
5474 return error_mark_node
;
5477 if (processing_template_decl
)
5479 tree t
= build_min (CAST_EXPR
, type
,
5480 min_tree_cons (NULL_TREE
, value
, NULL_TREE
));
5484 if (TREE_CODE (type
) == VOID_TYPE
)
5485 value
= build1 (CONVERT_EXPR
, type
, value
);
5486 else if (TREE_TYPE (value
) == NULL_TREE
5487 || type_unknown_p (value
))
5489 value
= instantiate_type (type
, value
, 1);
5491 if (value
== error_mark_node
)
5492 return error_mark_node
;
5498 /* Convert functions and arrays to pointers and
5499 convert references to their expanded types,
5500 but don't convert any other types. */
5501 if (TREE_CODE (TREE_TYPE (value
)) == FUNCTION_TYPE
5502 || (TREE_CODE (TREE_TYPE (value
)) == METHOD_TYPE
5503 /* Don't do the default conversion if we want a
5504 pointer to a function. */
5505 && ! (TREE_CODE (type
) == POINTER_TYPE
5506 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
))
5507 || TREE_CODE (TREE_TYPE (value
)) == ARRAY_TYPE
5508 || TREE_CODE (TREE_TYPE (value
)) == REFERENCE_TYPE
)
5509 value
= default_conversion (value
);
5510 otype
= TREE_TYPE (value
);
5512 /* Optionally warn about potentially worrisome casts. */
5515 && TREE_CODE (type
) == POINTER_TYPE
5516 && TREE_CODE (otype
) == POINTER_TYPE
)
5518 /* For C++ we make these regular warnings, rather than
5519 softening them into pedwarns. */
5520 if (TYPE_VOLATILE (TREE_TYPE (otype
))
5521 && ! TYPE_VOLATILE (TREE_TYPE (type
)))
5522 warning ("cast discards `volatile' from pointer target type");
5523 if (TYPE_READONLY (TREE_TYPE (otype
))
5524 && ! TYPE_READONLY (TREE_TYPE (type
)))
5525 warning ("cast discards `const' from pointer target type");
5528 /* Warn about possible alignment problems. */
5529 if (STRICT_ALIGNMENT
&& warn_cast_align
5530 && TREE_CODE (type
) == POINTER_TYPE
5531 && TREE_CODE (otype
) == POINTER_TYPE
5532 && TREE_CODE (TREE_TYPE (otype
)) != VOID_TYPE
5533 && TREE_CODE (TREE_TYPE (otype
)) != FUNCTION_TYPE
5534 && TYPE_ALIGN (TREE_TYPE (type
)) > TYPE_ALIGN (TREE_TYPE (otype
)))
5535 warning ("cast increases required alignment of target type");
5538 /* We should see about re-enabling these, they seem useful to
5540 if (TREE_CODE (type
) == INTEGER_TYPE
5541 && TREE_CODE (otype
) == POINTER_TYPE
5542 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
))
5543 warning ("cast from pointer to integer of different size");
5545 if (TREE_CODE (type
) == POINTER_TYPE
5546 && TREE_CODE (otype
) == INTEGER_TYPE
5547 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
)
5548 /* Don't warn about converting 0 to pointer,
5549 provided the 0 was explicit--not cast or made by folding. */
5550 && !(TREE_CODE (value
) == INTEGER_CST
&& integer_zerop (value
)))
5551 warning ("cast to pointer from integer of different size");
5554 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5555 value
= (convert_from_reference
5556 (convert_to_reference (type
, value
, CONV_C_CAST
,
5557 LOOKUP_COMPLAIN
, NULL_TREE
)));
5562 if (TREE_READONLY_DECL_P (value
))
5563 value
= decl_constant_value (value
);
5566 value
= convert_force (type
, value
, CONV_C_CAST
);
5568 /* Ignore any integer overflow caused by the cast. */
5569 if (TREE_CODE (value
) == INTEGER_CST
)
5571 TREE_OVERFLOW (value
) = TREE_OVERFLOW (ovalue
);
5572 TREE_CONSTANT_OVERFLOW (value
) = TREE_CONSTANT_OVERFLOW (ovalue
);
5577 /* Always produce some operator for an explicit cast,
5578 so we can tell (for -pedantic) that the cast is no lvalue. */
5579 if (TREE_CODE (type
) != REFERENCE_TYPE
&& value
== expr
5580 && real_lvalue_p (value
))
5581 value
= non_lvalue (value
);
5587 expand_target_expr (t
)
5590 extern int temp_slot_level
;
5591 extern int target_temp_slot_level
;
5592 int old_temp_level
= target_temp_slot_level
;
5594 tree xval
= make_node (RTL_EXPR
);
5597 /* Any TARGET_EXPR temps live only as long as the outer temp level.
5598 Since they are preserved in this new inner level, we know they
5599 will make it into the outer level. */
5601 target_temp_slot_level
= temp_slot_level
;
5603 do_pending_stack_adjust ();
5604 start_sequence_for_rtl_expr (xval
);
5606 rtxval
= expand_expr (t
, NULL_RTX
, VOIDmode
, 0);
5607 do_pending_stack_adjust ();
5608 TREE_SIDE_EFFECTS (xval
) = 1;
5609 RTL_EXPR_SEQUENCE (xval
) = get_insns ();
5611 RTL_EXPR_RTL (xval
) = rtxval
;
5612 TREE_TYPE (xval
) = TREE_TYPE (t
);
5615 target_temp_slot_level
= old_temp_level
;
5620 /* Build an assignment expression of lvalue LHS from value RHS.
5621 MODIFYCODE is the code for a binary operator that we use
5622 to combine the old value of LHS with RHS to get the new value.
5623 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
5625 C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed. */
5628 build_modify_expr (lhs
, modifycode
, rhs
)
5630 enum tree_code modifycode
;
5633 register tree result
;
5635 tree lhstype
= TREE_TYPE (lhs
);
5636 tree olhstype
= lhstype
;
5639 /* Avoid duplicate error messages from operands that had errors. */
5640 if (lhs
== error_mark_node
|| rhs
== error_mark_node
)
5641 return error_mark_node
;
5643 /* Types that aren't fully specified cannot be used in assignments. */
5644 lhs
= require_complete_type (lhs
);
5648 /* Handle assignment to signature pointers/refs. */
5650 if (TYPE_LANG_SPECIFIC (lhstype
)
5651 && (IS_SIGNATURE_POINTER (lhstype
) || IS_SIGNATURE_REFERENCE (lhstype
)))
5653 return build_signature_pointer_constructor (lhs
, rhs
);
5656 /* Handle control structure constructs used as "lvalues". */
5658 switch (TREE_CODE (lhs
))
5660 /* Handle --foo = 5; as these are valid constructs in C++ */
5661 case PREDECREMENT_EXPR
:
5662 case PREINCREMENT_EXPR
:
5663 if (TREE_SIDE_EFFECTS (TREE_OPERAND (lhs
, 0)))
5664 lhs
= build (TREE_CODE (lhs
), TREE_TYPE (lhs
),
5665 stabilize_reference (TREE_OPERAND (lhs
, 0)),
5666 TREE_OPERAND (lhs
, 1));
5667 return build (COMPOUND_EXPR
, lhstype
,
5669 build_modify_expr (TREE_OPERAND (lhs
, 0),
5672 /* Handle (a, b) used as an "lvalue". */
5674 newrhs
= build_modify_expr (TREE_OPERAND (lhs
, 1),
5676 if (newrhs
== error_mark_node
)
5677 return error_mark_node
;
5678 return build (COMPOUND_EXPR
, lhstype
,
5679 TREE_OPERAND (lhs
, 0), newrhs
);
5682 newrhs
= build_modify_expr (TREE_OPERAND (lhs
, 0), modifycode
, rhs
);
5683 if (newrhs
== error_mark_node
)
5684 return error_mark_node
;
5685 return build (COMPOUND_EXPR
, lhstype
, lhs
, newrhs
);
5687 /* Handle (a ? b : c) used as an "lvalue". */
5689 rhs
= save_expr (rhs
);
5691 /* Produce (a ? (b = rhs) : (c = rhs))
5692 except that the RHS goes through a save-expr
5693 so the code to compute it is only emitted once. */
5695 = build_conditional_expr (TREE_OPERAND (lhs
, 0),
5696 build_modify_expr (cp_convert (TREE_TYPE (lhs
), TREE_OPERAND (lhs
, 1)),
5698 build_modify_expr (cp_convert (TREE_TYPE (lhs
), TREE_OPERAND (lhs
, 2)),
5700 if (cond
== error_mark_node
)
5702 /* Make sure the code to compute the rhs comes out
5703 before the split. */
5704 return build (COMPOUND_EXPR
, TREE_TYPE (lhs
),
5705 /* Case to void to suppress warning
5706 from warn_if_unused_value. */
5707 cp_convert (void_type_node
, rhs
), cond
);
5711 if (TREE_CODE (lhs
) == OFFSET_REF
)
5713 if (TREE_OPERAND (lhs
, 0) == NULL_TREE
)
5715 /* Static class member? */
5716 tree member
= TREE_OPERAND (lhs
, 1);
5717 if (TREE_CODE (member
) == VAR_DECL
)
5721 compiler_error ("invalid static class member");
5722 return error_mark_node
;
5726 lhs
= resolve_offset_ref (lhs
);
5728 olhstype
= lhstype
= TREE_TYPE (lhs
);
5731 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
5732 && modifycode
!= INIT_EXPR
)
5734 lhs
= convert_from_reference (lhs
);
5735 olhstype
= lhstype
= TREE_TYPE (lhs
);
5738 /* If a binary op has been requested, combine the old LHS value with the RHS
5739 producing the value we should actually store into the LHS. */
5741 if (modifycode
== INIT_EXPR
)
5743 if (! IS_AGGR_TYPE (lhstype
))
5744 /* Do the default thing */;
5745 else if (! TYPE_HAS_CONSTRUCTOR (lhstype
))
5747 cp_error ("`%T' has no constructors", lhstype
);
5748 return error_mark_node
;
5750 else if (TYPE_HAS_TRIVIAL_INIT_REF (lhstype
)
5751 && TYPE_MAIN_VARIANT (lhstype
) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs
)))
5752 /* Do the default thing */;
5755 result
= build_method_call (lhs
, ctor_identifier
,
5756 build_tree_list (NULL_TREE
, rhs
),
5757 TYPE_BINFO (lhstype
), LOOKUP_NORMAL
);
5758 if (result
== NULL_TREE
)
5759 return error_mark_node
;
5763 else if (modifycode
== NOP_EXPR
)
5765 /* `operator=' is not an inheritable operator. */
5766 if (! IS_AGGR_TYPE (lhstype
))
5767 /* Do the default thing */;
5768 else if (! TYPE_HAS_ASSIGNMENT (lhstype
))
5770 cp_error ("`%T' does not define operator=", lhstype
);
5771 return error_mark_node
;
5773 else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (lhstype
)
5774 && TYPE_MAIN_VARIANT (lhstype
) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs
)))
5776 build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
,
5777 lhs
, rhs
, make_node (NOP_EXPR
));
5779 /* Do the default thing */;
5783 result
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
,
5784 lhs
, rhs
, make_node (NOP_EXPR
));
5785 if (result
== NULL_TREE
)
5786 return error_mark_node
;
5791 else if (PROMOTES_TO_AGGR_TYPE (lhstype
, REFERENCE_TYPE
))
5793 /* This case must convert to some sort of lvalue that
5794 can participate in an op= operation. */
5797 if (build_default_binary_type_conversion (modifycode
, &lhs_tmp
, &rhs_tmp
))
5799 lhs
= stabilize_reference (lhs_tmp
);
5800 /* Forget it was ever anything else. */
5801 olhstype
= lhstype
= TREE_TYPE (lhs
);
5802 newrhs
= build_binary_op (modifycode
, lhs
, rhs_tmp
, 1);
5806 cp_error ("no match for `%Q(%#T, %#T)'", modifycode
,
5807 TREE_TYPE (lhs
), TREE_TYPE (rhs
));
5808 return error_mark_node
;
5813 lhs
= stabilize_reference (lhs
);
5814 newrhs
= build_binary_op (modifycode
, lhs
, rhs
, 1);
5815 if (newrhs
== error_mark_node
)
5817 cp_error (" in evaluation of `%Q(%#T, %#T)'", modifycode
,
5818 TREE_TYPE (lhs
), TREE_TYPE (rhs
));
5819 return error_mark_node
;
5823 /* Handle a cast used as an "lvalue".
5824 We have already performed any binary operator using the value as cast.
5825 Now convert the result to the cast type of the lhs,
5826 and then true type of the lhs and store it there;
5827 then convert result back to the cast type to be the value
5828 of the assignment. */
5830 switch (TREE_CODE (lhs
))
5835 case FIX_TRUNC_EXPR
:
5836 case FIX_FLOOR_EXPR
:
5837 case FIX_ROUND_EXPR
:
5839 if (TREE_CODE (TREE_TYPE (newrhs
)) == ARRAY_TYPE
5840 || TREE_CODE (TREE_TYPE (newrhs
)) == FUNCTION_TYPE
5841 || TREE_CODE (TREE_TYPE (newrhs
)) == METHOD_TYPE
5842 || TREE_CODE (TREE_TYPE (newrhs
)) == OFFSET_TYPE
)
5843 newrhs
= default_conversion (newrhs
);
5845 tree inner_lhs
= TREE_OPERAND (lhs
, 0);
5848 /* WP 5.4.1: The result is an lvalue if T is a reference type,
5849 otherwise the result is an rvalue. */
5850 if (! lvalue_p (lhs
))
5851 pedwarn ("ANSI C++ forbids cast to non-reference type used as lvalue");
5853 result
= build_modify_expr (inner_lhs
, NOP_EXPR
,
5854 cp_convert (TREE_TYPE (inner_lhs
),
5855 cp_convert (lhstype
, newrhs
)));
5856 if (result
== error_mark_node
)
5858 return cp_convert (TREE_TYPE (lhs
), result
);
5862 /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
5863 Reject anything strange now. */
5865 if (!lvalue_or_else (lhs
, "assignment"))
5866 return error_mark_node
;
5868 GNU_xref_assign (lhs
);
5870 /* Warn about storing in something that is `const'. */
5871 /* For C++, don't warn if this is initialization. */
5872 if (modifycode
!= INIT_EXPR
5873 /* For assignment to `const' signature pointer/reference fields,
5874 don't warn either, we already printed a better message before. */
5875 && ! (TREE_CODE (lhs
) == COMPONENT_REF
5876 && (IS_SIGNATURE_POINTER (TREE_TYPE (TREE_OPERAND (lhs
, 0)))
5877 || IS_SIGNATURE_REFERENCE (TREE_TYPE (TREE_OPERAND (lhs
, 0)))))
5878 && (TREE_READONLY (lhs
) || TYPE_READONLY (lhstype
)
5879 || ((TREE_CODE (lhstype
) == RECORD_TYPE
5880 || TREE_CODE (lhstype
) == UNION_TYPE
)
5881 && C_TYPE_FIELDS_READONLY (lhstype
))
5882 || (TREE_CODE (lhstype
) == REFERENCE_TYPE
5883 && TYPE_READONLY (TREE_TYPE (lhstype
)))))
5884 readonly_error (lhs
, "assignment", 0);
5886 /* If storing into a structure or union member,
5887 it has probably been given type `int'.
5888 Compute the type that would go with
5889 the actual amount of storage the member occupies. */
5891 if (TREE_CODE (lhs
) == COMPONENT_REF
5892 && (TREE_CODE (lhstype
) == INTEGER_TYPE
5893 || TREE_CODE (lhstype
) == REAL_TYPE
5894 || TREE_CODE (lhstype
) == ENUMERAL_TYPE
))
5896 lhstype
= TREE_TYPE (get_unwidened (lhs
, 0));
5898 /* If storing in a field that is in actuality a short or narrower
5899 than one, we must store in the field in its actual type. */
5901 if (lhstype
!= TREE_TYPE (lhs
))
5903 lhs
= copy_node (lhs
);
5904 TREE_TYPE (lhs
) = lhstype
;
5908 /* check to see if there is an assignment to `this' */
5909 if (lhs
== current_class_ptr
)
5911 if (flag_this_is_variable
> 0
5912 && DECL_NAME (current_function_decl
) != NULL_TREE
5913 && (DECL_NAME (current_function_decl
)
5914 != constructor_name (current_class_type
)))
5915 warning ("assignment to `this' not in constructor or destructor");
5916 current_function_just_assigned_this
= 1;
5919 /* The TREE_TYPE of RHS may be TYPE_UNKNOWN. This can happen
5920 when the type of RHS is not yet known, i.e. its type
5921 is inherited from LHS. */
5922 rhs
= require_instantiated_type (lhstype
, newrhs
, error_mark_node
);
5923 if (rhs
== error_mark_node
)
5924 return error_mark_node
;
5927 if (modifycode
!= INIT_EXPR
)
5929 /* Make modifycode now either a NOP_EXPR or an INIT_EXPR. */
5930 modifycode
= NOP_EXPR
;
5931 /* Reference-bashing */
5932 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
)
5934 tree tmp
= convert_from_reference (lhs
);
5935 lhstype
= TREE_TYPE (tmp
);
5936 if (TYPE_SIZE (lhstype
) == 0)
5938 incomplete_type_error (lhs
, lhstype
);
5939 return error_mark_node
;
5944 if (TREE_CODE (TREE_TYPE (newrhs
)) == REFERENCE_TYPE
)
5946 tree tmp
= convert_from_reference (newrhs
);
5947 if (TYPE_SIZE (TREE_TYPE (tmp
)) == 0)
5949 incomplete_type_error (newrhs
, TREE_TYPE (tmp
));
5950 return error_mark_node
;
5956 if (TREE_SIDE_EFFECTS (lhs
))
5957 lhs
= stabilize_reference (lhs
);
5958 if (TREE_SIDE_EFFECTS (newrhs
))
5959 newrhs
= stabilize_reference (newrhs
);
5961 /* Convert new value to destination type. */
5963 if (TREE_CODE (lhstype
) == ARRAY_TYPE
)
5967 if (! comptypes (lhstype
, TREE_TYPE (rhs
), 0))
5969 cp_error ("incompatible types in assignment of `%T' to `%T'",
5970 TREE_TYPE (rhs
), lhstype
);
5971 return error_mark_node
;
5974 /* Allow array assignment in compiler-generated code. */
5975 if (pedantic
&& ! DECL_ARTIFICIAL (current_function_decl
))
5976 pedwarn ("ANSI C++ forbids assignment of arrays");
5978 /* Have to wrap this in RTL_EXPR for two cases:
5979 in base or member initialization and if we
5980 are a branch of a ?: operator. Since we
5981 can't easily know the latter, just do it always. */
5983 result
= make_node (RTL_EXPR
);
5985 TREE_TYPE (result
) = void_type_node
;
5986 do_pending_stack_adjust ();
5987 start_sequence_for_rtl_expr (result
);
5989 /* As a matter of principle, `start_sequence' should do this. */
5992 from_array
= TREE_CODE (TREE_TYPE (newrhs
)) == ARRAY_TYPE
5993 ? 1 + (modifycode
!= INIT_EXPR
): 0;
5994 expand_vec_init (lhs
, lhs
, array_type_nelts (lhstype
), newrhs
,
5997 do_pending_stack_adjust ();
5999 TREE_SIDE_EFFECTS (result
) = 1;
6000 RTL_EXPR_SEQUENCE (result
) = get_insns ();
6001 RTL_EXPR_RTL (result
) = const0_rtx
;
6006 if (modifycode
== INIT_EXPR
)
6008 newrhs
= convert_for_initialization (lhs
, lhstype
, newrhs
, LOOKUP_NORMAL
,
6009 "assignment", NULL_TREE
, 0);
6010 if (lhs
== DECL_RESULT (current_function_decl
))
6012 if (DECL_INITIAL (lhs
))
6013 warning ("return value from function receives multiple initializations");
6014 DECL_INITIAL (lhs
) = newrhs
;
6019 /* Avoid warnings on enum bit fields. */
6020 if (TREE_CODE (olhstype
) == ENUMERAL_TYPE
6021 && TREE_CODE (lhstype
) == INTEGER_TYPE
)
6023 newrhs
= convert_for_assignment (olhstype
, newrhs
, "assignment",
6025 newrhs
= convert_force (lhstype
, newrhs
, 0);
6028 newrhs
= convert_for_assignment (lhstype
, newrhs
, "assignment",
6030 if (TREE_CODE (newrhs
) == CALL_EXPR
6031 && TYPE_NEEDS_CONSTRUCTING (lhstype
))
6032 newrhs
= build_cplus_new (lhstype
, newrhs
);
6034 /* Can't initialize directly from a TARGET_EXPR, since that would
6035 cause the lhs to be constructed twice, and possibly result in
6036 accidental self-initialization. So we force the TARGET_EXPR to be
6037 expanded without a target. */
6038 if (TREE_CODE (newrhs
) == TARGET_EXPR
)
6039 newrhs
= build (COMPOUND_EXPR
, TREE_TYPE (newrhs
), newrhs
,
6040 TREE_OPERAND (newrhs
, 0));
6043 if (newrhs
== error_mark_node
)
6044 return error_mark_node
;
6046 if (TREE_CODE (newrhs
) == COND_EXPR
)
6049 tree cond
= TREE_OPERAND (newrhs
, 0);
6051 if (TREE_SIDE_EFFECTS (lhs
))
6052 cond
= build_compound_expr (tree_cons
6054 build_tree_list (NULL_TREE
, cond
)));
6056 /* Cannot have two identical lhs on this one tree (result) as preexpand
6057 calls will rip them out and fill in RTL for them, but when the
6058 rtl is generated, the calls will only be in the first side of the
6059 condition, not on both, or before the conditional jump! (mrs) */
6060 lhs1
= break_out_calls (lhs
);
6063 /* If there's no change, the COND_EXPR behaves like any other rhs. */
6064 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
6065 lhstype
, lhs
, newrhs
);
6068 tree result_type
= TREE_TYPE (newrhs
);
6069 /* We have to convert each arm to the proper type because the
6070 types may have been munged by constant folding. */
6072 = build (COND_EXPR
, result_type
, cond
,
6073 build_modify_expr (lhs
, modifycode
,
6074 cp_convert (result_type
,
6075 TREE_OPERAND (newrhs
, 1))),
6076 build_modify_expr (lhs1
, modifycode
,
6077 cp_convert (result_type
,
6078 TREE_OPERAND (newrhs
, 2))));
6082 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
6083 lhstype
, lhs
, newrhs
);
6085 TREE_SIDE_EFFECTS (result
) = 1;
6087 /* If we got the LHS in a different type for storing in,
6088 convert the result back to the nominal type of LHS
6089 so that the value we return always has the same type
6090 as the LHS argument. */
6092 if (olhstype
== TREE_TYPE (result
))
6094 /* Avoid warnings converting integral types back into enums
6095 for enum bit fields. */
6096 if (TREE_CODE (TREE_TYPE (result
)) == INTEGER_TYPE
6097 && TREE_CODE (olhstype
) == ENUMERAL_TYPE
)
6099 result
= build (COMPOUND_EXPR
, olhstype
, result
, olhs
);
6100 TREE_NO_UNUSED_WARNING (result
) = 1;
6103 return convert_for_assignment (olhstype
, result
, "assignment",
6108 build_x_modify_expr (lhs
, modifycode
, rhs
)
6110 enum tree_code modifycode
;
6113 if (processing_template_decl
)
6114 return build_min_nt (MODOP_EXPR
, lhs
,
6115 build_min_nt (modifycode
, NULL_TREE
, NULL_TREE
), rhs
);
6117 if (modifycode
!= NOP_EXPR
)
6119 tree rval
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
, lhs
, rhs
,
6120 make_node (modifycode
));
6124 return build_modify_expr (lhs
, modifycode
, rhs
);
6127 /* Return 0 if EXP is not a valid lvalue in this language
6128 even though `lvalue_or_else' would accept it. */
6131 language_lvalue_valid (exp
)
6137 /* Get difference in deltas for different pointer to member function
6138 types. Return integer_zero_node, if FROM cannot be converted to a
6139 TO type. If FORCE is true, then allow reverse conversions as well. */
6142 get_delta_difference (from
, to
, force
)
6146 tree delta
= integer_zero_node
;
6152 /* Should get_base_distance here, so we can check if any thing along the
6153 path is virtual, and we need to make sure we stay
6154 inside the real binfos when going through virtual bases.
6155 Maybe we should replace virtual bases with
6156 binfo_member (...CLASSTYPE_VBASECLASSES...)... (mrs) */
6157 binfo
= get_binfo (from
, to
, 1);
6158 if (binfo
== error_mark_node
)
6160 error (" in pointer to member function conversiona");
6167 error_not_base_type (from
, to
);
6168 error (" in pointer to member conversion");
6171 binfo
= get_binfo (to
, from
, 1);
6172 if (binfo
== error_mark_node
)
6175 error (" in pointer to member conversion");
6181 cp_error ("cannot convert pointer to member of type %T to unrelated pointer to member of type %T", from
, to
);
6184 if (TREE_VIA_VIRTUAL (binfo
))
6186 binfo
= binfo_member (BINFO_TYPE (binfo
),
6187 CLASSTYPE_VBASECLASSES (from
));
6188 warning ("pointer to member conversion to virtual base class will only work if you are very careful");
6190 delta
= BINFO_OFFSET (binfo
);
6191 delta
= cp_convert (ptrdiff_type_node
, delta
);
6193 return build_binary_op (MINUS_EXPR
,
6197 if (TREE_VIA_VIRTUAL (binfo
))
6199 warning ("pointer to member conversion from virtual base class will only work if you are very careful");
6201 return BINFO_OFFSET (binfo
);
6205 build_ptrmemfunc1 (type
, delta
, idx
, pfn
, delta2
)
6206 tree type
, delta
, idx
, pfn
, delta2
;
6211 /* This is the old way we did it. We want to avoid calling
6212 digest_init, so that it can give an error if we use { } when
6213 initializing a pointer to member function. */
6217 u
= build_nt (CONSTRUCTOR
, NULL_TREE
,
6218 tree_cons (pfn_identifier
, pfn
, NULL_TREE
));
6222 u
= build_nt (CONSTRUCTOR
, NULL_TREE
,
6223 tree_cons (delta2_identifier
, delta2
, NULL_TREE
));
6226 u
= build_nt (CONSTRUCTOR
, NULL_TREE
,
6227 tree_cons (NULL_TREE
, delta
,
6228 tree_cons (NULL_TREE
, idx
,
6229 tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6231 return digest_init (type
, u
, (tree
*)0);
6233 tree delta_field
, idx_field
, pfn_or_delta2_field
, pfn_field
, delta2_field
;
6235 int allconstant
, allsimple
;
6237 delta_field
= TYPE_FIELDS (type
);
6238 idx_field
= TREE_CHAIN (delta_field
);
6239 pfn_or_delta2_field
= TREE_CHAIN (idx_field
);
6240 subtype
= TREE_TYPE (pfn_or_delta2_field
);
6241 pfn_field
= TYPE_FIELDS (subtype
);
6242 delta2_field
= TREE_CHAIN (pfn_field
);
6246 allconstant
= TREE_CONSTANT (pfn
);
6247 allsimple
= initializer_constant_valid_p (pfn
, TREE_TYPE (pfn
));
6248 u
= tree_cons (pfn_field
, pfn
, NULL_TREE
);
6252 delta2
= convert_and_check (delta_type_node
, delta2
);
6253 allconstant
= TREE_CONSTANT (delta2
);
6254 allsimple
= initializer_constant_valid_p (delta2
, TREE_TYPE (delta2
));
6255 u
= tree_cons (delta2_field
, delta2
, NULL_TREE
);
6258 delta
= convert_and_check (delta_type_node
, delta
);
6259 idx
= convert_and_check (delta_type_node
, idx
);
6261 allconstant
= allconstant
&& TREE_CONSTANT (delta
) && TREE_CONSTANT (idx
);
6262 allsimple
= allsimple
6263 && initializer_constant_valid_p (delta
, TREE_TYPE (delta
))
6264 && initializer_constant_valid_p (idx
, TREE_TYPE (idx
));
6266 u
= build (CONSTRUCTOR
, subtype
, NULL_TREE
, u
);
6267 u
= tree_cons (delta_field
, delta
,
6268 tree_cons (idx_field
, idx
,
6269 tree_cons (pfn_or_delta2_field
, u
, NULL_TREE
)));
6270 u
= build (CONSTRUCTOR
, type
, NULL_TREE
, u
);
6271 TREE_CONSTANT (u
) = allconstant
;
6272 TREE_STATIC (u
) = allconstant
&& allsimple
;
6277 /* Build a constructor for a pointer to member function. It can be
6278 used to initialize global variables, local variable, or used
6279 as a value in expressions. TYPE is the POINTER to METHOD_TYPE we
6282 If FORCE is non-zero, then force this conversion, even if
6283 we would rather not do it. Usually set when using an explicit
6286 Return error_mark_node, if something goes wrong. */
6289 build_ptrmemfunc (type
, pfn
, force
)
6293 tree idx
= integer_zero_node
;
6294 tree delta
= integer_zero_node
;
6295 tree delta2
= integer_zero_node
;
6297 tree npfn
= NULL_TREE
;
6299 /* Handle multiple conversions of pointer to member functions. */
6300 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (pfn
)))
6302 tree ndelta
, ndelta2
;
6305 /* Is is already the right type? */
6306 if (type
== TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))
6309 ndelta
= cp_convert (ptrdiff_type_node
, build_component_ref (pfn
, delta_identifier
, NULL_TREE
, 0));
6310 ndelta2
= cp_convert (ptrdiff_type_node
, DELTA2_FROM_PTRMEMFUNC (pfn
));
6311 idx
= build_component_ref (pfn
, index_identifier
, NULL_TREE
, 0);
6313 n
= get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))),
6314 TYPE_METHOD_BASETYPE (TREE_TYPE (type
)),
6317 delta
= build_binary_op (PLUS_EXPR
, ndelta
, n
, 1);
6318 delta2
= build_binary_op (PLUS_EXPR
, ndelta2
, n
, 1);
6319 e1
= fold (build (GT_EXPR
, boolean_type_node
, idx
, integer_zero_node
));
6321 e2
= build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type
), delta
, idx
,
6324 pfn
= PFN_FROM_PTRMEMFUNC (pfn
);
6325 npfn
= build1 (NOP_EXPR
, type
, pfn
);
6326 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6328 e3
= build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type
), delta
, idx
, npfn
,
6330 return build_conditional_expr (e1
, e2
, e3
);
6333 /* Handle null pointer to member function conversions. */
6334 if (integer_zerop (pfn
))
6336 pfn
= build_c_cast (type
, integer_zero_node
);
6337 return build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type
),
6338 integer_zero_node
, integer_zero_node
,
6342 if (TREE_CODE (pfn
) == TREE_LIST
6343 || (TREE_CODE (pfn
) == ADDR_EXPR
6344 && TREE_CODE (TREE_OPERAND (pfn
, 0)) == TREE_LIST
))
6345 return instantiate_type (type
, pfn
, 1);
6347 /* Allow pointer to member conversions here. */
6348 delta
= get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TREE_TYPE (pfn
))),
6349 TYPE_METHOD_BASETYPE (TREE_TYPE (type
)),
6351 delta2
= build_binary_op (PLUS_EXPR
, delta2
, delta
, 1);
6354 /* We need to check the argument types to see if they are compatible
6355 (any const or volatile violations. */
6356 something like
this:
6357 comptype (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (type
))),
6358 TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (TREE_TYPE (pfn
)))), ?);
6361 if (TREE_CODE (TREE_OPERAND (pfn
, 0)) != FUNCTION_DECL
)
6362 warning ("assuming pointer to member function is non-virtual");
6364 if (TREE_CODE (TREE_OPERAND (pfn
, 0)) == FUNCTION_DECL
6365 && DECL_VINDEX (TREE_OPERAND (pfn
, 0)))
6367 /* Find the offset to the vfield pointer in the object. */
6368 vfield_offset
= get_binfo (DECL_CONTEXT (TREE_OPERAND (pfn
, 0)),
6369 DECL_CLASS_CONTEXT (TREE_OPERAND (pfn
, 0)),
6371 vfield_offset
= get_vfield_offset (vfield_offset
);
6372 delta2
= size_binop (PLUS_EXPR
, vfield_offset
, delta2
);
6374 /* Map everything down one to make room for the null pointer to member. */
6375 idx
= size_binop (PLUS_EXPR
,
6376 DECL_VINDEX (TREE_OPERAND (pfn
, 0)),
6381 idx
= size_binop (MINUS_EXPR
, integer_zero_node
, integer_one_node
);
6383 if (type
== TREE_TYPE (pfn
))
6389 npfn
= build1 (NOP_EXPR
, type
, pfn
);
6390 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6394 return build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type
), delta
, idx
, npfn
, delta2
);
6397 /* Convert value RHS to type TYPE as preparation for an assignment
6398 to an lvalue of type TYPE.
6399 The real work of conversion is done by `convert'.
6400 The purpose of this function is to generate error messages
6401 for assignments that are not allowed in C.
6402 ERRTYPE is a string to use in error messages:
6403 "assignment", "return", etc.
6405 C++: attempts to allow `convert' to find conversions involving
6406 implicit type conversion between aggregate and scalar types
6407 as per 8.5.6 of C++ manual. Does not randomly dereference
6408 pointers to aggregates! */
6411 convert_for_assignment (type
, rhs
, errtype
, fndecl
, parmnum
)
6417 register enum tree_code codel
= TREE_CODE (type
);
6418 register tree rhstype
;
6419 register enum tree_code coder
= TREE_CODE (TREE_TYPE (rhs
));
6421 if (coder
== UNKNOWN_TYPE
)
6422 rhs
= instantiate_type (type
, rhs
, 1);
6424 if (coder
== ERROR_MARK
)
6425 return error_mark_node
;
6427 if (codel
== OFFSET_TYPE
)
6429 type
= TREE_TYPE (type
);
6430 codel
= TREE_CODE (type
);
6433 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
6434 if (TREE_CODE (rhs
) == NON_LVALUE_EXPR
)
6435 rhs
= TREE_OPERAND (rhs
, 0);
6437 if (rhs
== error_mark_node
)
6438 return error_mark_node
;
6440 if (TREE_VALUE (rhs
) == error_mark_node
)
6441 return error_mark_node
;
6443 if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
6445 rhs
= resolve_offset_ref (rhs
);
6446 if (rhs
== error_mark_node
)
6447 return error_mark_node
;
6448 rhstype
= TREE_TYPE (rhs
);
6449 coder
= TREE_CODE (rhstype
);
6452 if (TREE_CODE (TREE_TYPE (rhs
)) == ARRAY_TYPE
6453 || TREE_CODE (TREE_TYPE (rhs
)) == FUNCTION_TYPE
6454 || TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
6455 rhs
= default_conversion (rhs
);
6456 else if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
6457 rhs
= convert_from_reference (rhs
);
6459 rhstype
= TREE_TYPE (rhs
);
6460 coder
= TREE_CODE (rhstype
);
6462 /* This should no longer change types on us. */
6463 if (TREE_CODE (rhs
) == CONST_DECL
)
6464 rhs
= DECL_INITIAL (rhs
);
6465 else if (TREE_READONLY_DECL_P (rhs
))
6466 rhs
= decl_constant_value (rhs
);
6468 if (type
== rhstype
)
6470 overflow_warning (rhs
);
6474 if (coder
== VOID_TYPE
)
6476 error ("void value not ignored as it ought to be");
6477 return error_mark_node
;
6479 /* Arithmetic types all interconvert. */
6480 if ((codel
== INTEGER_TYPE
|| codel
== REAL_TYPE
|| codel
== BOOLEAN_TYPE
6481 || codel
== COMPLEX_TYPE
)
6482 && (coder
== INTEGER_TYPE
|| coder
== REAL_TYPE
|| coder
== BOOLEAN_TYPE
6483 || coder
== COMPLEX_TYPE
))
6485 /* But we should warn if assigning REAL_TYPE to INTEGER_TYPE. */
6486 if (coder
== REAL_TYPE
&& codel
== INTEGER_TYPE
)
6489 cp_warning ("`%T' used for argument %P of `%D'",
6490 rhstype
, parmnum
, fndecl
);
6492 cp_warning ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6494 /* And we should warn if assigning a negative value to
6495 an unsigned variable. */
6496 else if (TREE_UNSIGNED (type
) && codel
!= BOOLEAN_TYPE
)
6498 if (TREE_CODE (rhs
) == INTEGER_CST
6499 && TREE_NEGATED_INT (rhs
))
6502 cp_warning ("negative value `%E' passed as argument %P of `%D'",
6503 rhs
, parmnum
, fndecl
);
6505 cp_warning ("%s of negative value `%E' to `%T'",
6506 errtype
, rhs
, type
);
6508 overflow_warning (rhs
);
6509 if (TREE_CONSTANT (rhs
))
6513 return convert_and_check (type
, rhs
);
6515 /* Conversions involving enums. */
6516 else if ((codel
== ENUMERAL_TYPE
6517 && (INTEGRAL_CODE_P (coder
) || coder
== REAL_TYPE
))
6518 || (coder
== ENUMERAL_TYPE
6519 && (INTEGRAL_CODE_P (codel
) || codel
== REAL_TYPE
)))
6521 return ocp_convert (type
, rhs
, CONV_IMPLICIT
, LOOKUP_NORMAL
);
6523 /* Conversions among pointers */
6524 else if (codel
== POINTER_TYPE
6525 && (coder
== POINTER_TYPE
6526 || (coder
== RECORD_TYPE
6527 && (IS_SIGNATURE_POINTER (rhstype
)
6528 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6530 register tree ttl
= TREE_TYPE (type
);
6534 if (coder
== RECORD_TYPE
)
6536 rhs
= build_optr_ref (rhs
);
6537 rhstype
= TREE_TYPE (rhs
);
6539 ttr
= TREE_TYPE (rhstype
);
6541 /* If both pointers are of aggregate type, then we
6542 can give better error messages, and save some work
6544 if (TREE_CODE (ttl
) == RECORD_TYPE
&& TREE_CODE (ttr
) == RECORD_TYPE
)
6548 if (TYPE_MAIN_VARIANT (ttl
) == TYPE_MAIN_VARIANT (ttr
)
6549 || type
== class_star_type_node
6550 || rhstype
== class_star_type_node
)
6551 binfo
= TYPE_BINFO (ttl
);
6553 binfo
= get_binfo (ttl
, ttr
, 1);
6555 if (binfo
== error_mark_node
)
6556 return error_mark_node
;
6558 return error_not_base_type (ttl
, ttr
);
6560 if (! TYPE_READONLY (ttl
) && TYPE_READONLY (ttr
))
6563 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6564 rhstype
, parmnum
, fndecl
);
6566 cp_pedwarn ("%s to `%T' from `%T' discards const",
6567 errtype
, type
, rhstype
);
6569 if (! TYPE_VOLATILE (ttl
) && TYPE_VOLATILE (ttr
))
6572 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6573 rhstype
, parmnum
, fndecl
);
6575 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6576 errtype
, type
, rhstype
);
6580 /* Any non-function converts to a [const][volatile] void *
6581 and vice versa; otherwise, targets must be the same.
6582 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
6583 else if (TYPE_MAIN_VARIANT (ttl
) == void_type_node
6584 || TYPE_MAIN_VARIANT (ttr
) == void_type_node
6585 || (ctt
= comp_target_types (type
, rhstype
, 1))
6586 || (unsigned_type (TYPE_MAIN_VARIANT (ttl
))
6587 == unsigned_type (TYPE_MAIN_VARIANT (ttr
))))
6589 /* ARM $4.8, commentary on p39. */
6590 if (TYPE_MAIN_VARIANT (ttl
) == void_type_node
6591 && TREE_CODE (ttr
) == OFFSET_TYPE
)
6593 cp_error ("no standard conversion from `%T' to `void *'", ttr
);
6594 return error_mark_node
;
6597 if (ctt
< 0 && TYPE_MAIN_VARIANT (ttl
) != TYPE_MAIN_VARIANT (ttr
))
6598 cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
6601 if (TYPE_MAIN_VARIANT (ttl
) != void_type_node
6602 && TYPE_MAIN_VARIANT (ttr
) == void_type_node
6603 && ! null_ptr_cst_p (rhs
))
6605 if (coder
== RECORD_TYPE
)
6606 cp_pedwarn ("implicit conversion of signature pointer to type `%T'",
6609 pedwarn ("ANSI C++ forbids implicit conversion from `void *' in %s",
6612 /* Const and volatile mean something different for function types,
6613 so the usual warnings are not appropriate. */
6614 else if ((TREE_CODE (ttr
) != FUNCTION_TYPE
&& TREE_CODE (ttr
) != METHOD_TYPE
)
6615 || (TREE_CODE (ttl
) != FUNCTION_TYPE
&& TREE_CODE (ttl
) != METHOD_TYPE
))
6617 if (TREE_CODE (ttl
) == OFFSET_TYPE
6618 && binfo_member (TYPE_OFFSET_BASETYPE (ttr
),
6619 CLASSTYPE_VBASECLASSES (TYPE_OFFSET_BASETYPE (ttl
))))
6621 sorry ("%s between pointer to members converting across virtual baseclasses", errtype
);
6622 return error_mark_node
;
6624 else if (! TYPE_READONLY (ttl
) && TYPE_READONLY (ttr
))
6627 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6628 rhstype
, parmnum
, fndecl
);
6630 cp_pedwarn ("%s to `%T' from `%T' discards const",
6631 errtype
, type
, rhstype
);
6633 else if (! TYPE_VOLATILE (ttl
) && TYPE_VOLATILE (ttr
))
6636 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6637 rhstype
, parmnum
, fndecl
);
6639 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6640 errtype
, type
, rhstype
);
6642 else if (TREE_CODE (ttl
) == TREE_CODE (ttr
)
6643 && ! comp_target_types (type
, rhstype
, 1))
6646 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signedness",
6647 rhstype
, parmnum
, fndecl
);
6649 cp_pedwarn ("%s to `%T' from `%T' changes signedness",
6650 errtype
, type
, rhstype
);
6656 int add_quals
= 0, const_parity
= 0, volatile_parity
= 0;
6658 int unsigned_parity
;
6661 /* This code is basically a duplicate of comp_ptr_ttypes_real. */
6662 for (; ; ttl
= TREE_TYPE (ttl
), ttr
= TREE_TYPE (ttr
))
6665 const_parity
|= (TYPE_READONLY (ttl
) < TYPE_READONLY (ttr
));
6666 volatile_parity
|= (TYPE_VOLATILE (ttl
) < TYPE_VOLATILE (ttr
));
6669 && (TYPE_READONLY (ttl
) > TYPE_READONLY (ttr
)
6670 || TYPE_VOLATILE (ttl
) > TYPE_VOLATILE (ttr
)))
6672 left_const
&= TYPE_READONLY (ttl
);
6674 if (TREE_CODE (ttl
) != POINTER_TYPE
6675 || TREE_CODE (ttr
) != POINTER_TYPE
)
6678 unsigned_parity
= TREE_UNSIGNED (ttl
) - TREE_UNSIGNED (ttr
);
6679 if (unsigned_parity
)
6681 if (TREE_UNSIGNED (ttl
))
6682 ttr
= unsigned_type (ttr
);
6684 ttl
= unsigned_type (ttl
);
6687 if (comp_target_types (ttl
, ttr
, nptrs
) > 0)
6692 cp_pedwarn ("passing `%T' as argument %P of `%D' adds cv-quals without intervening `const'",
6693 rhstype
, parmnum
, fndecl
);
6695 cp_pedwarn ("%s to `%T' from `%T' adds cv-quals without intervening `const'",
6696 errtype
, type
, rhstype
);
6701 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6702 rhstype
, parmnum
, fndecl
);
6704 cp_pedwarn ("%s to `%T' from `%T' discards const",
6705 errtype
, type
, rhstype
);
6707 if (volatile_parity
)
6710 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6711 rhstype
, parmnum
, fndecl
);
6713 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6714 errtype
, type
, rhstype
);
6716 if (unsigned_parity
> 0)
6719 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signed to unsigned",
6720 rhstype
, parmnum
, fndecl
);
6722 cp_pedwarn ("%s to `%T' from `%T' changes signed to unsigned",
6723 errtype
, type
, rhstype
);
6725 else if (unsigned_parity
< 0)
6728 cp_pedwarn ("passing `%T' as argument %P of `%D' changes unsigned to signed",
6729 rhstype
, parmnum
, fndecl
);
6731 cp_pedwarn ("%s to `%T' from `%T' changes unsigned to signed",
6732 errtype
, type
, rhstype
);
6735 /* C++ is not so friendly about converting function and
6736 member function pointers as C. Emit warnings here. */
6737 if (TREE_CODE (ttl
) == FUNCTION_TYPE
6738 || TREE_CODE (ttl
) == METHOD_TYPE
)
6739 if (! comptypes (ttl
, ttr
, 0))
6741 warning ("conflicting function types in %s:", errtype
);
6742 cp_warning ("\t`%T' != `%T'", type
, rhstype
);
6748 cp_error ("passing `%T' as argument %P of `%D'",
6749 rhstype
, parmnum
, fndecl
);
6751 cp_error ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6752 return error_mark_node
;
6755 return cp_convert (type
, rhs
);
6757 else if (codel
== POINTER_TYPE
&& coder
== INTEGER_TYPE
)
6759 /* An explicit constant 0 can convert to a pointer,
6760 but not a 0 that results from casting or folding. */
6761 if (! (TREE_CODE (rhs
) == INTEGER_CST
&& integer_zerop (rhs
)))
6764 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6765 rhstype
, parmnum
, fndecl
);
6767 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
6768 errtype
, type
, rhstype
);
6770 return cp_convert (type
, rhs
);
6772 else if (codel
== INTEGER_TYPE
6773 && (coder
== POINTER_TYPE
6774 || (coder
== RECORD_TYPE
6775 && (IS_SIGNATURE_POINTER (rhstype
)
6776 || TYPE_PTRMEMFUNC_FLAG (rhstype
)
6777 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6780 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6781 rhstype
, parmnum
, fndecl
);
6783 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
6784 errtype
, type
, rhstype
);
6785 return cp_convert (type
, rhs
);
6787 else if (codel
== BOOLEAN_TYPE
6788 && (coder
== POINTER_TYPE
6789 || (coder
== RECORD_TYPE
6790 && (IS_SIGNATURE_POINTER (rhstype
)
6791 || TYPE_PTRMEMFUNC_FLAG (rhstype
)
6792 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6793 return cp_convert (type
, rhs
);
6796 else if (((coder
== POINTER_TYPE
6797 && TREE_CODE (TREE_TYPE (rhstype
)) == METHOD_TYPE
)
6798 || integer_zerop (rhs
)
6799 || TYPE_PTRMEMFUNC_P (rhstype
))
6800 && TYPE_PTRMEMFUNC_P (type
))
6802 tree ttl
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
6803 tree ttr
= (TREE_CODE (rhstype
) == POINTER_TYPE
? rhstype
6804 : TYPE_PTRMEMFUNC_FN_TYPE (type
));
6805 int ctt
= comp_target_types (ttl
, ttr
, 1);
6808 cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
6811 cp_error ("%s to `%T' from `%T'", errtype
, ttl
, ttr
);
6813 /* compatible pointer to member functions. */
6814 return build_ptrmemfunc (ttl
, rhs
, 0);
6816 else if (codel
== ERROR_MARK
|| coder
== ERROR_MARK
)
6817 return error_mark_node
;
6819 /* This should no longer happen. References are initialized via
6820 `convert_for_initialization'. They should otherwise be
6821 bashed before coming here. */
6822 else if (codel
== REFERENCE_TYPE
)
6823 my_friendly_abort (317);
6824 else if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (TREE_TYPE (rhs
)))
6826 tree nrhs
= build1 (NOP_EXPR
, type
, rhs
);
6827 TREE_CONSTANT (nrhs
) = TREE_CONSTANT (rhs
);
6830 else if (TYPE_HAS_CONSTRUCTOR (type
) || IS_AGGR_TYPE (TREE_TYPE (rhs
)))
6831 return cp_convert (type
, rhs
);
6832 /* Handle anachronistic conversions from (::*)() to cv void* or (*)(). */
6833 else if (TREE_CODE (type
) == POINTER_TYPE
6834 && (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
6835 || TYPE_MAIN_VARIANT (TREE_TYPE (type
)) == void_type_node
)
6837 && TYPE_PTRMEMFUNC_P (TREE_TYPE (rhs
)))
6838 return cp_convert (type
, rhs
);
6840 cp_error ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6841 return error_mark_node
;
6844 /* Convert RHS to be of type TYPE. If EXP is non-zero,
6845 it is the target of the initialization.
6846 ERRTYPE is a string to use in error messages.
6848 Two major differences between the behavior of
6849 `convert_for_assignment' and `convert_for_initialization'
6850 are that references are bashed in the former, while
6851 copied in the latter, and aggregates are assigned in
6852 the former (operator=) while initialized in the
6855 If using constructor make sure no conversion operator exists, if one does
6856 exist, an ambiguity exists.
6858 If flags doesn't include LOOKUP_COMPLAIN, don't complain about anything. */
6861 convert_for_initialization (exp
, type
, rhs
, flags
, errtype
, fndecl
, parmnum
)
6862 tree exp
, type
, rhs
;
6868 register enum tree_code codel
= TREE_CODE (type
);
6869 register tree rhstype
;
6870 register enum tree_code coder
;
6872 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
6873 Strip such NOP_EXPRs, since RHS is used in non-lvalue context. */
6874 if (TREE_CODE (rhs
) == NOP_EXPR
6875 && TREE_TYPE (rhs
) == TREE_TYPE (TREE_OPERAND (rhs
, 0))
6876 && codel
!= REFERENCE_TYPE
)
6877 rhs
= TREE_OPERAND (rhs
, 0);
6879 if (rhs
== error_mark_node
6880 || (TREE_CODE (rhs
) == TREE_LIST
&& TREE_VALUE (rhs
) == error_mark_node
))
6881 return error_mark_node
;
6883 if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
6885 rhs
= resolve_offset_ref (rhs
);
6886 if (rhs
== error_mark_node
)
6887 return error_mark_node
;
6890 if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
6891 rhs
= convert_from_reference (rhs
);
6893 if ((TREE_CODE (TREE_TYPE (rhs
)) == ARRAY_TYPE
6894 && TREE_CODE (type
) != ARRAY_TYPE
6895 && (TREE_CODE (type
) != REFERENCE_TYPE
6896 || TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
))
6897 || TREE_CODE (TREE_TYPE (rhs
)) == FUNCTION_TYPE
6898 || TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
6899 rhs
= default_conversion (rhs
);
6901 rhstype
= TREE_TYPE (rhs
);
6902 coder
= TREE_CODE (rhstype
);
6904 if (coder
== UNKNOWN_TYPE
)
6906 rhs
= instantiate_type (type
, rhs
, 1);
6907 rhstype
= TREE_TYPE (rhs
);
6908 coder
= TREE_CODE (rhstype
);
6911 if (coder
== ERROR_MARK
)
6912 return error_mark_node
;
6914 /* We accept references to incomplete types, so we can
6915 return here before checking if RHS is of complete type. */
6917 if (codel
== REFERENCE_TYPE
)
6919 /* This should eventually happen in convert_arguments. */
6920 extern int warningcount
, errorcount
;
6924 savew
= warningcount
, savee
= errorcount
;
6925 rhs
= convert_to_reference (type
, rhs
, CONV_IMPLICIT
, flags
,
6926 exp
? exp
: error_mark_node
);
6929 if (warningcount
> savew
)
6930 cp_warning_at ("in passing argument %P of `%+D'", parmnum
, fndecl
);
6931 else if (errorcount
> savee
)
6932 cp_error_at ("in passing argument %P of `%+D'", parmnum
, fndecl
);
6937 rhs
= require_complete_type (rhs
);
6938 if (rhs
== error_mark_node
)
6939 return error_mark_node
;
6941 if (exp
!= 0) exp
= require_complete_type (exp
);
6942 if (exp
== error_mark_node
)
6943 return error_mark_node
;
6945 if (TREE_CODE (rhstype
) == REFERENCE_TYPE
)
6946 rhstype
= TREE_TYPE (rhstype
);
6948 type
= complete_type (type
);
6950 if (TYPE_LANG_SPECIFIC (type
)
6951 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
)))
6952 return build_signature_pointer_constructor (type
, rhs
);
6954 if (IS_AGGR_TYPE (type
)
6955 && (TYPE_NEEDS_CONSTRUCTING (type
) || TREE_HAS_CONSTRUCTOR (rhs
)))
6957 if (flag_ansi_overloading
)
6958 return ocp_convert (type
, rhs
, CONV_IMPLICIT
|CONV_FORCE_TEMP
, flags
);
6960 if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (rhstype
))
6962 /* This is sufficient to perform initialization. No need,
6963 apparently, to go through X(X&) to do first-cut
6964 initialization. Return through a TARGET_EXPR so that we get
6965 cleanups if it is used. */
6966 if (TREE_CODE (rhs
) == CALL_EXPR
)
6968 rhs
= build_cplus_new (type
, rhs
);
6971 /* Handle the case of default parameter initialization and
6972 initialization of static variables. */
6973 else if (TREE_CODE (rhs
) == TARGET_EXPR
)
6975 else if (TREE_CODE (rhs
) == INDIRECT_REF
&& TREE_HAS_CONSTRUCTOR (rhs
))
6977 my_friendly_assert (TREE_CODE (TREE_OPERAND (rhs
, 0)) == CALL_EXPR
, 318);
6980 my_friendly_assert (TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs
, 0), 1)) == NULL_TREE
, 316);
6981 TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs
, 0), 1))
6982 = build_unary_op (ADDR_EXPR
, exp
, 0);
6985 rhs
= build_cplus_new (type
, TREE_OPERAND (rhs
, 0));
6988 else if (TYPE_HAS_TRIVIAL_INIT_REF (type
))
6991 if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (rhstype
)
6992 || (IS_AGGR_TYPE (rhstype
) && UNIQUELY_DERIVED_FROM_P (type
, rhstype
)))
6994 if (TYPE_HAS_INIT_REF (type
))
6996 tree init
= build_method_call (exp
, ctor_identifier
,
6997 build_tree_list (NULL_TREE
, rhs
),
6998 TYPE_BINFO (type
), LOOKUP_NORMAL
);
7000 if (init
== error_mark_node
)
7001 return error_mark_node
;
7005 exp
= build_cplus_new (type
, init
);
7009 return build (COMPOUND_EXPR
, type
, init
, exp
);
7012 /* ??? The following warnings are turned off because
7013 this is another place where the default X(X&) constructor
7015 if (TYPE_HAS_ASSIGNMENT (type
))
7016 cp_warning ("bitwise copy: `%T' defines operator=", type
);
7018 if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
7019 rhs
= convert_from_reference (rhs
);
7020 if (type
!= rhstype
)
7022 tree nrhs
= build1 (NOP_EXPR
, type
, rhs
);
7023 TREE_CONSTANT (nrhs
) = TREE_CONSTANT (rhs
);
7029 return ocp_convert (type
, rhs
, CONV_OLD_CONVERT
,
7030 flags
| LOOKUP_NO_CONVERSION
);
7033 if (type
== TREE_TYPE (rhs
))
7035 if (TREE_READONLY_DECL_P (rhs
))
7036 rhs
= decl_constant_value (rhs
);
7040 return convert_for_assignment (type
, rhs
, errtype
, fndecl
, parmnum
);
7043 /* Expand an ASM statement with operands, handling output operands
7044 that are not variables or INDIRECT_REFS by transforming such
7045 cases into cases that expand_asm_operands can handle.
7047 Arguments are same as for expand_asm_operands.
7049 We don't do default conversions on all inputs, because it can screw
7050 up operands that are expected to be in memory. */
7053 c_expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, filename
, line
)
7054 tree string
, outputs
, inputs
, clobbers
;
7059 int noutputs
= list_length (outputs
);
7061 /* o[I] is the place that output number I should be written. */
7062 register tree
*o
= (tree
*) alloca (noutputs
* sizeof (tree
));
7065 /* Record the contents of OUTPUTS before it is modified. */
7066 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
7067 o
[i
] = TREE_VALUE (tail
);
7069 /* Generate the ASM_OPERANDS insn;
7070 store into the TREE_VALUEs of OUTPUTS some trees for
7071 where the values were actually stored. */
7072 expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, filename
, line
);
7074 /* Copy all the intermediate outputs into the specified outputs. */
7075 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
7077 if (o
[i
] != TREE_VALUE (tail
))
7079 expand_expr (build_modify_expr (o
[i
], NOP_EXPR
, TREE_VALUE (tail
)),
7080 const0_rtx
, VOIDmode
, 0);
7083 /* Detect modification of read-only values.
7084 (Otherwise done by build_modify_expr.) */
7087 tree type
= TREE_TYPE (o
[i
]);
7088 if (TYPE_READONLY (type
)
7089 || ((TREE_CODE (type
) == RECORD_TYPE
7090 || TREE_CODE (type
) == UNION_TYPE
)
7091 && C_TYPE_FIELDS_READONLY (type
)))
7092 readonly_error (o
[i
], "modification by `asm'", 1);
7096 /* Those MODIFY_EXPRs could do autoincrements. */
7100 /* Expand a C `return' statement.
7101 RETVAL is the expression for what to return,
7102 or a null pointer for `return;' with no value.
7104 C++: upon seeing a `return', we must call destructors on all
7105 variables in scope which had constructors called on them.
7106 This means that if in a destructor, the base class destructors
7107 must be called before returning.
7109 The RETURN statement in C++ has initialization semantics. */
7112 c_expand_return (retval
)
7115 extern struct nesting
*cond_stack
, *loop_stack
, *case_stack
;
7116 extern tree dtor_label
, ctor_label
;
7117 tree result
= DECL_RESULT (current_function_decl
);
7118 tree valtype
= TREE_TYPE (result
);
7120 if (TREE_THIS_VOLATILE (current_function_decl
))
7121 warning ("function declared `noreturn' has a `return' statement");
7123 if (retval
== error_mark_node
)
7125 current_function_returns_null
= 1;
7129 if (processing_template_decl
)
7131 add_tree (build_min_nt (RETURN_STMT
, retval
));
7135 if (retval
== NULL_TREE
)
7137 /* A non-named return value does not count. */
7139 /* Can't just return from a destructor. */
7142 expand_goto (dtor_label
);
7146 if (DECL_CONSTRUCTOR_P (current_function_decl
))
7147 retval
= current_class_ptr
;
7148 else if (DECL_NAME (result
) != NULL_TREE
7149 && TREE_CODE (valtype
) != VOID_TYPE
)
7153 current_function_returns_null
= 1;
7155 if (valtype
!= NULL_TREE
&& TREE_CODE (valtype
) != VOID_TYPE
)
7157 if (DECL_NAME (DECL_RESULT (current_function_decl
)) == NULL_TREE
)
7159 pedwarn ("`return' with no value, in function returning non-void");
7160 /* Clear this, so finish_function won't say that we
7161 reach the end of a non-void function (which we don't,
7162 we gave a return!). */
7163 current_function_returns_null
= 0;
7167 expand_null_return ();
7171 else if (DECL_CONSTRUCTOR_P (current_function_decl
)
7172 && retval
!= current_class_ptr
)
7174 if (flag_this_is_variable
)
7175 error ("return from a constructor: use `this = ...' instead");
7177 error ("return from a constructor");
7178 retval
= current_class_ptr
;
7181 /* Effective C++ rule 15. See also start_function. */
7183 && DECL_NAME (current_function_decl
) == ansi_opname
[(int) MODIFY_EXPR
]
7184 && retval
!= current_class_ref
)
7185 cp_warning ("`operator=' should return a reference to `*this'");
7187 if (valtype
== NULL_TREE
|| TREE_CODE (valtype
) == VOID_TYPE
)
7189 current_function_returns_null
= 1;
7190 if ((pedantic
&& ! DECL_ARTIFICIAL (current_function_decl
))
7191 || TREE_CODE (TREE_TYPE (retval
)) != VOID_TYPE
)
7192 pedwarn ("`return' with a value, in function returning void");
7193 expand_return (retval
);
7196 /* Add some useful error checking for C++. */
7197 else if (TREE_CODE (valtype
) == REFERENCE_TYPE
)
7199 tree whats_returned
;
7200 tree tmp_result
= result
;
7202 /* Don't initialize directly into a non-BLKmode retval, since that
7203 could lose when being inlined by another caller. (GCC can't
7204 read the function return register in an inline function when
7205 the return value is being ignored). */
7206 if (result
&& TYPE_MODE (TREE_TYPE (tmp_result
)) != BLKmode
)
7209 /* convert to reference now, so we can give error if we
7210 return an reference to a non-lvalue. */
7211 retval
= convert_for_initialization
7212 (tmp_result
, valtype
, retval
, LOOKUP_NORMAL
|LOOKUP_ONLYCONVERTING
,
7213 "return", NULL_TREE
, 0);
7215 /* Sort through common things to see what it is
7216 we are returning. */
7217 whats_returned
= retval
;
7218 if (TREE_CODE (whats_returned
) == COMPOUND_EXPR
)
7220 whats_returned
= TREE_OPERAND (whats_returned
, 1);
7221 if (TREE_CODE (whats_returned
) == ADDR_EXPR
)
7222 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7224 if (TREE_CODE (whats_returned
) == CONVERT_EXPR
)
7225 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7226 if (TREE_CODE (whats_returned
) == ADDR_EXPR
)
7228 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7229 while (TREE_CODE (whats_returned
) == NEW_EXPR
7230 || TREE_CODE (whats_returned
) == TARGET_EXPR
)
7232 /* Get the target. */
7233 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7234 warning ("returning reference to temporary");
7238 if (TREE_CODE (whats_returned
) == VAR_DECL
&& DECL_NAME (whats_returned
))
7240 if (TEMP_NAME_P (DECL_NAME (whats_returned
)))
7241 warning ("reference to non-lvalue returned");
7242 else if (! TREE_STATIC (whats_returned
)
7243 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned
))
7244 && !TREE_PUBLIC (whats_returned
))
7245 cp_warning_at ("reference to local variable `%D' returned", whats_returned
);
7248 else if (TREE_CODE (retval
) == ADDR_EXPR
)
7250 tree whats_returned
= TREE_OPERAND (retval
, 0);
7252 if (TREE_CODE (whats_returned
) == VAR_DECL
7253 && DECL_NAME (whats_returned
)
7254 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned
))
7255 && !TREE_STATIC (whats_returned
)
7256 && !TREE_PUBLIC (whats_returned
))
7257 cp_warning_at ("address of local variable `%D' returned", whats_returned
);
7259 else if (TREE_CODE (retval
) == VAR_DECL
)
7261 if (TREE_CODE (TREE_TYPE (retval
)) == ARRAY_TYPE
7262 && DECL_NAME (retval
)
7263 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (retval
))
7264 && !TREE_STATIC (retval
)
7265 && !TREE_PUBLIC (retval
))
7266 cp_warning_at ("address of local array `%D' returned", retval
);
7269 /* Now deal with possible C++ hair:
7270 (1) Compute the return value.
7271 (2) If there are aggregate values with destructors which
7272 must be cleaned up, clean them (taking care
7273 not to clobber the return value).
7274 (3) If an X(X&) constructor is defined, the return
7275 value must be returned via that. */
7277 if (retval
== result
7278 || DECL_CONSTRUCTOR_P (current_function_decl
))
7279 /* It's already done for us. */;
7280 else if (TREE_TYPE (retval
) == void_type_node
)
7282 pedwarn ("return of void value in function returning non-void");
7283 expand_expr_stmt (retval
);
7288 /* We already did this above for refs, don't do it again. */
7289 if (TREE_CODE (valtype
) != REFERENCE_TYPE
)
7290 retval
= convert_for_initialization
7291 (NULL_TREE
, valtype
, retval
, LOOKUP_NORMAL
|LOOKUP_ONLYCONVERTING
,
7292 "return", NULL_TREE
, 0);
7294 /* We can't initialize a register from a NEW_EXPR. */
7295 if (! current_function_returns_struct
7296 && TREE_CODE (retval
) == TARGET_EXPR
7297 && TREE_CODE (TREE_OPERAND (retval
, 1)) == NEW_EXPR
)
7298 retval
= build (COMPOUND_EXPR
, TREE_TYPE (retval
), retval
,
7299 TREE_OPERAND (retval
, 0));
7301 if (retval
== error_mark_node
)
7303 /* Avoid warning about control reaching end of function. */
7304 expand_null_return ();
7309 if (retval
!= NULL_TREE
7310 && TREE_CODE_CLASS (TREE_CODE (retval
)) == 'd'
7311 && cond_stack
== 0 && loop_stack
== 0 && case_stack
== 0)
7312 current_function_return_value
= retval
;
7314 if (ctor_label
&& TREE_CODE (ctor_label
) != ERROR_MARK
)
7316 /* Here RETVAL is CURRENT_CLASS_PTR, so there's nothing to do. */
7317 expand_goto (ctor_label
);
7320 if (retval
&& retval
!= result
)
7322 result
= build (INIT_EXPR
, TREE_TYPE (result
), result
, retval
);
7323 TREE_SIDE_EFFECTS (result
) = 1;
7325 expand_return (result
);
7326 current_function_returns_value
= 1;
7329 /* Start a C switch statement, testing expression EXP.
7330 Return EXP if it is valid, an error node otherwise. */
7333 c_expand_start_case (exp
)
7337 register enum tree_code code
;
7339 /* Convert from references, etc. */
7340 exp
= default_conversion (exp
);
7341 type
= TREE_TYPE (exp
);
7342 code
= TREE_CODE (type
);
7344 if (IS_AGGR_TYPE_CODE (code
))
7345 exp
= build_type_conversion (CONVERT_EXPR
, integer_type_node
, exp
, 1);
7347 if (exp
== NULL_TREE
)
7349 error ("switch quantity not an integer");
7350 exp
= error_mark_node
;
7352 type
= TREE_TYPE (exp
);
7353 code
= TREE_CODE (type
);
7355 if (code
!= INTEGER_TYPE
&& code
!= ENUMERAL_TYPE
&& code
!= ERROR_MARK
)
7357 error ("switch quantity not an integer");
7358 exp
= error_mark_node
;
7364 exp
= default_conversion (exp
);
7365 type
= TREE_TYPE (exp
);
7366 idx
= get_unwidened (exp
, 0);
7367 /* We can't strip a conversion from a signed type to an unsigned,
7368 because if we did, int_fits_type_p would do the wrong thing
7369 when checking case values for being in range,
7370 and it's too hard to do the right thing. */
7371 if (TREE_UNSIGNED (TREE_TYPE (exp
))
7372 == TREE_UNSIGNED (TREE_TYPE (idx
)))
7377 (1, fold (build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (exp
), exp
)),
7378 type
, "switch statement");
7383 /* CONSTP remembers whether or not all the intervening pointers in the `to'
7384 type have been const. */
7387 comp_ptr_ttypes_real (to
, from
, constp
)
7391 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7393 if (TREE_CODE (to
) != TREE_CODE (from
))
7396 if (TREE_CODE (from
) == OFFSET_TYPE
7397 && comptypes (TYPE_OFFSET_BASETYPE (from
),
7398 TYPE_OFFSET_BASETYPE (to
), 1))
7401 /* Const and volatile mean something different for function types,
7402 so the usual checks are not appropriate. */
7403 if (TREE_CODE (to
) != FUNCTION_TYPE
&& TREE_CODE (to
) != METHOD_TYPE
)
7405 if (TYPE_READONLY (from
) > TYPE_READONLY (to
)
7406 || TYPE_VOLATILE (from
) > TYPE_VOLATILE (to
))
7410 && (TYPE_READONLY (to
) > TYPE_READONLY (from
)
7411 || TYPE_VOLATILE (to
) > TYPE_READONLY (from
)))
7413 constp
&= TYPE_READONLY (to
);
7416 if (TREE_CODE (to
) != POINTER_TYPE
)
7417 return comptypes (TYPE_MAIN_VARIANT (to
), TYPE_MAIN_VARIANT (from
), 1);
7421 /* When comparing, say, char ** to char const **, this function takes the
7422 'char *' and 'char const *'. Do not pass non-pointer types to this
7426 comp_ptr_ttypes (to
, from
)
7429 return comp_ptr_ttypes_real (to
, from
, 1);
7432 /* Returns 1 if to and from are (possibly multi-level) pointers to the same
7433 type or inheritance-related types, regardless of cv-quals. */
7436 ptr_reasonably_similar (to
, from
)
7439 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7441 if (TREE_CODE (to
) != TREE_CODE (from
))
7444 if (TREE_CODE (from
) == OFFSET_TYPE
7445 && comptypes (TYPE_OFFSET_BASETYPE (to
),
7446 TYPE_OFFSET_BASETYPE (from
), -1))
7449 if (TREE_CODE (to
) != POINTER_TYPE
)
7451 (TYPE_MAIN_VARIANT (to
), TYPE_MAIN_VARIANT (from
), -1);
7455 /* Like comp_ptr_ttypes, for const_cast. */
7458 comp_ptr_ttypes_const (to
, from
)
7461 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7463 if (TREE_CODE (to
) != TREE_CODE (from
))
7466 if (TREE_CODE (from
) == OFFSET_TYPE
7467 && comptypes (TYPE_OFFSET_BASETYPE (from
),
7468 TYPE_OFFSET_BASETYPE (to
), 1))
7471 if (TREE_CODE (to
) != POINTER_TYPE
)
7472 return comptypes (TYPE_MAIN_VARIANT (to
), TYPE_MAIN_VARIANT (from
), 1);
7476 /* Like comp_ptr_ttypes, for reinterpret_cast. */
7479 comp_ptr_ttypes_reinterpret (to
, from
)
7484 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7486 if (TREE_CODE (from
) == OFFSET_TYPE
)
7487 from
= TREE_TYPE (from
);
7488 if (TREE_CODE (to
) == OFFSET_TYPE
)
7489 to
= TREE_TYPE (to
);
7491 if (TREE_CODE (to
) != TREE_CODE (from
))
7494 /* Const and volatile mean something different for function types,
7495 so the usual checks are not appropriate. */
7496 if (TREE_CODE (to
) != FUNCTION_TYPE
&& TREE_CODE (to
) != METHOD_TYPE
)
7498 if (TYPE_READONLY (from
) > TYPE_READONLY (to
)
7499 || TYPE_VOLATILE (from
) > TYPE_VOLATILE (to
))
7503 && (TYPE_READONLY (to
) > TYPE_READONLY (from
)
7504 || TYPE_VOLATILE (to
) > TYPE_READONLY (from
)))
7506 constp
&= TYPE_READONLY (to
);
7509 if (TREE_CODE (to
) != POINTER_TYPE
)