Deleted Added
full compact
typeck.c (50397) typeck.c (52284)
1/* Build expressions with type checking for C++ compiler.
1/* Build expressions with type checking for C++ compiler.
2 Copyright (C) 1987, 88, 89, 92-97, 1998 Free Software Foundation, Inc.
2 Copyright (C) 1987, 88, 89, 92-98, 1999 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.

--- 23 unchanged lines hidden (view full) ---

34#include "tree.h"
35#include "rtl.h"
36#include "cp-tree.h"
37#include "flags.h"
38#include "output.h"
39#include "expr.h"
40#include "toplev.h"
41
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.

--- 23 unchanged lines hidden (view full) ---

34#include "tree.h"
35#include "rtl.h"
36#include "cp-tree.h"
37#include "flags.h"
38#include "output.h"
39#include "expr.h"
40#include "toplev.h"
41
42extern void compiler_error ();
43
44static tree convert_for_assignment PROTO((tree, tree, char*, tree,
42static tree convert_for_assignment PROTO((tree, tree, const char *, tree,
45 int));
46static tree pointer_int_sum PROTO((enum tree_code, tree, tree));
47static tree rationalize_conditional_expr PROTO((enum tree_code, tree));
48static int comp_target_parms PROTO((tree, tree, int));
49static int comp_ptr_ttypes_real PROTO((tree, tree, int));
50static int comp_ptr_ttypes_const PROTO((tree, tree));
51static int comp_ptr_ttypes_reinterpret PROTO((tree, tree));
52static int comp_array_types PROTO((int (*) (tree, tree, int), tree,
53 tree, int));
43 int));
44static tree pointer_int_sum PROTO((enum tree_code, tree, tree));
45static tree rationalize_conditional_expr PROTO((enum tree_code, tree));
46static int comp_target_parms PROTO((tree, tree, int));
47static int comp_ptr_ttypes_real PROTO((tree, tree, int));
48static int comp_ptr_ttypes_const PROTO((tree, tree));
49static int comp_ptr_ttypes_reinterpret PROTO((tree, tree));
50static int comp_array_types PROTO((int (*) (tree, tree, int), tree,
51 tree, int));
54static tree build_ptrmemfunc1 PROTO((tree, tree, tree, tree, tree));
55static tree common_base_type PROTO((tree, tree));
56#if 0
57static tree convert_sequence PROTO((tree, tree));
58#endif
59static tree lookup_anon_field PROTO((tree, tree));
60static tree pointer_diff PROTO((tree, tree, tree));
52static tree common_base_type PROTO((tree, tree));
53#if 0
54static tree convert_sequence PROTO((tree, tree));
55#endif
56static tree lookup_anon_field PROTO((tree, tree));
57static tree pointer_diff PROTO((tree, tree, tree));
58static tree build_component_addr PROTO((tree, tree));
61static tree qualify_type PROTO((tree, tree));
62static tree get_delta_difference PROTO((tree, tree, int));
59static tree qualify_type PROTO((tree, tree));
60static tree get_delta_difference PROTO((tree, tree, int));
61static int comp_cv_target_types PROTO((tree, tree, int));
63
64/* Return the target type of TYPE, which meas return T for:
65 T*, T&, T[], T (...), and otherwise, just T. */
66
67tree
68target_type (type)
69 tree type;
70{

--- 4 unchanged lines hidden (view full) ---

75 || TREE_CODE (type) == FUNCTION_TYPE
76 || TREE_CODE (type) == METHOD_TYPE
77 || TREE_CODE (type) == OFFSET_TYPE)
78 type = TREE_TYPE (type);
79 return type;
80}
81
82/* Do `exp = require_complete_type (exp);' to make sure exp
62
63/* Return the target type of TYPE, which meas return T for:
64 T*, T&, T[], T (...), and otherwise, just T. */
65
66tree
67target_type (type)
68 tree type;
69{

--- 4 unchanged lines hidden (view full) ---

74 || TREE_CODE (type) == FUNCTION_TYPE
75 || TREE_CODE (type) == METHOD_TYPE
76 || TREE_CODE (type) == OFFSET_TYPE)
77 type = TREE_TYPE (type);
78 return type;
79}
80
81/* Do `exp = require_complete_type (exp);' to make sure exp
83 does not have an incomplete type. (That includes void types.) */
82 does not have an incomplete type. (That includes void types.)
83 Returns the error_mark_node if the VALUE does not have
84 complete type when this function returns. */
84
85tree
86require_complete_type (value)
87 tree value;
88{
89 tree type;
90
85
86tree
87require_complete_type (value)
88 tree value;
89{
90 tree type;
91
91 if (processing_template_decl)
92 if (processing_template_decl || value == error_mark_node)
92 return value;
93
94 if (TREE_CODE (value) == OVERLOAD)
95 type = unknown_type_node;
96 else
97 type = TREE_TYPE (value);
98
99 /* First, detect a valid value with a complete type. */
100 if (TYPE_SIZE (type) != 0
93 return value;
94
95 if (TREE_CODE (value) == OVERLOAD)
96 type = unknown_type_node;
97 else
98 type = TREE_TYPE (value);
99
100 /* First, detect a valid value with a complete type. */
101 if (TYPE_SIZE (type) != 0
101 && type != void_type_node
102 && TYPE_SIZE (type) != size_zero_node
102 && ! (TYPE_LANG_SPECIFIC (type)
103 && (IS_SIGNATURE_POINTER (type) || IS_SIGNATURE_REFERENCE (type))
104 && TYPE_SIZE (SIGNATURE_TYPE (type)) == 0))
105 return value;
106
107 /* If we see X::Y, we build an OFFSET_TYPE which has
108 not been laid out. Try to avoid an error by interpreting
109 it as this->X::Y, if reasonable. */

--- 5 unchanged lines hidden (view full) ---

115 tree basetype = TYPE_OFFSET_BASETYPE (type);
116 my_friendly_assert (TREE_CODE (member) == FIELD_DECL, 305);
117 base = convert_pointer_to (basetype, current_class_ptr);
118 value = build (COMPONENT_REF, TREE_TYPE (member),
119 build_indirect_ref (base, NULL_PTR), member);
120 return require_complete_type (value);
121 }
122
103 && ! (TYPE_LANG_SPECIFIC (type)
104 && (IS_SIGNATURE_POINTER (type) || IS_SIGNATURE_REFERENCE (type))
105 && TYPE_SIZE (SIGNATURE_TYPE (type)) == 0))
106 return value;
107
108 /* If we see X::Y, we build an OFFSET_TYPE which has
109 not been laid out. Try to avoid an error by interpreting
110 it as this->X::Y, if reasonable. */

--- 5 unchanged lines hidden (view full) ---

116 tree basetype = TYPE_OFFSET_BASETYPE (type);
117 my_friendly_assert (TREE_CODE (member) == FIELD_DECL, 305);
118 base = convert_pointer_to (basetype, current_class_ptr);
119 value = build (COMPONENT_REF, TREE_TYPE (member),
120 build_indirect_ref (base, NULL_PTR), member);
121 return require_complete_type (value);
122 }
123
123 if (TYPE_SIZE (complete_type (type)))
124 if (complete_type_or_else (type, value))
124 return value;
125 else
125 return value;
126 else
127 return error_mark_node;
128}
129
130/* Makes sure EXPR is a complete type when used in a void context, like a
131 whole expression, or lhs of a comma operator. Issue a diagnostic and
132 return error_mark_node on failure. This is a little tricky, because some
133 valid void types look stunningly similar to invalid void types. We err on
134 the side of caution */
135
136tree
137require_complete_type_in_void (expr)
138 tree expr;
139{
140 switch (TREE_CODE (expr))
126 {
141 {
127 incomplete_type_error (value, type);
128 return error_mark_node;
142 case COND_EXPR:
143 {
144 tree op;
145
146 op = TREE_OPERAND (expr,2);
147 op = require_complete_type_in_void (op);
148 TREE_OPERAND (expr,2) = op;
149 if (op == error_mark_node)
150 {
151 expr = op;
152 break;
153 }
154
155 /* fallthrough */
156 }
157
158 case COMPOUND_EXPR:
159 {
160 tree op;
161
162 op = TREE_OPERAND (expr,1);
163 op = require_complete_type_in_void (op);
164 TREE_OPERAND (expr,1) = op;
165 if (op == error_mark_node)
166 {
167 expr = op;
168 break;
169 }
170
171 break;
172 }
173
174 case NON_LVALUE_EXPR:
175 case NOP_EXPR:
176 {
177 tree op;
178
179 op = TREE_OPERAND (expr,0);
180 op = require_complete_type_in_void (op);
181 TREE_OPERAND (expr,0) = op;
182 if (op == error_mark_node)
183 {
184 expr = op;
185 break;
186 }
187 break;
188 }
189
190 case CALL_EXPR: /* function call return can be ignored */
191 case RTL_EXPR: /* RTL nodes have no value */
192 case DELETE_EXPR: /* delete expressions have no type */
193 case VEC_DELETE_EXPR:
194 case INTEGER_CST: /* used for null pointer */
195 case EXIT_EXPR: /* have no return */
196 case LOOP_EXPR: /* have no return */
197 case BIND_EXPR: /* have no return */
198 case THROW_EXPR: /* have no return */
199 case MODIFY_EXPR: /* sometimes this has a void type, but that's ok */
200 case CONVERT_EXPR: /* sometimes has a void type */
201 break;
202
203 case INDIRECT_REF:
204 {
205 tree op = TREE_OPERAND (expr,0);
206
207 /* Calling a function returning a reference has an implicit
208 dereference applied. We don't want to make that an error. */
209 if (TREE_CODE (op) == CALL_EXPR
210 && TREE_CODE (TREE_TYPE (op)) == REFERENCE_TYPE)
211 break;
212 /* else fallthrough */
213 }
214
215 default:
216 expr = require_complete_type (expr);
217 break;
129 }
218 }
219
220 return expr;
130}
131
132/* Try to complete TYPE, if it is incomplete. For example, if TYPE is
133 a template instantiation, do the instantiation. Returns TYPE,
134 whether or not it could be completed, unless something goes
135 horribly wrong, in which case the error_mark_node is returned. */
136
137tree

--- 12 unchanged lines hidden (view full) ---

150 tree t = complete_type (TREE_TYPE (type));
151 if (TYPE_SIZE (t) != NULL_TREE && ! processing_template_decl)
152 layout_type (type);
153 TYPE_NEEDS_CONSTRUCTING (type)
154 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (t));
155 TYPE_NEEDS_DESTRUCTOR (type)
156 = TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (t));
157 }
221}
222
223/* Try to complete TYPE, if it is incomplete. For example, if TYPE is
224 a template instantiation, do the instantiation. Returns TYPE,
225 whether or not it could be completed, unless something goes
226 horribly wrong, in which case the error_mark_node is returned. */
227
228tree

--- 12 unchanged lines hidden (view full) ---

241 tree t = complete_type (TREE_TYPE (type));
242 if (TYPE_SIZE (t) != NULL_TREE && ! processing_template_decl)
243 layout_type (type);
244 TYPE_NEEDS_CONSTRUCTING (type)
245 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (t));
246 TYPE_NEEDS_DESTRUCTOR (type)
247 = TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (t));
248 }
158 else if (IS_AGGR_TYPE (type) && CLASSTYPE_TEMPLATE_INSTANTIATION (type))
249 else if (CLASS_TYPE_P (type) && CLASSTYPE_TEMPLATE_INSTANTIATION (type))
159 instantiate_class_template (TYPE_MAIN_VARIANT (type));
160
161 return type;
162}
163
164/* Like complete_type, but issue an error if the TYPE cannot be
250 instantiate_class_template (TYPE_MAIN_VARIANT (type));
251
252 return type;
253}
254
255/* Like complete_type, but issue an error if the TYPE cannot be
165 completed. Returns NULL_TREE if the type cannot be made
166 complete. */
256 completed. VALUE is used for informative diagnostics.
257 Returns NULL_TREE if the type cannot be made complete. */
167
168tree
258
259tree
169complete_type_or_else (type)
260complete_type_or_else (type, value)
170 tree type;
261 tree type;
262 tree value;
171{
172 type = complete_type (type);
263{
264 type = complete_type (type);
173 if (type != error_mark_node && !TYPE_SIZE (type))
265 if (type == error_mark_node)
266 /* We already issued an error. */
267 return NULL_TREE;
268 else if (!TYPE_SIZE (type) || TYPE_SIZE (type) == size_zero_node)
174 {
269 {
175 incomplete_type_error (NULL_TREE, type);
270 incomplete_type_error (value, type);
176 return NULL_TREE;
177 }
178 else
179 return type;
180}
181
182/* Return truthvalue of whether type of EXP is instantiated. */
183

--- 15 unchanged lines hidden (view full) ---

199 tree t;
200{
201 return (TREE_CODE (t) == FUNCTION_TYPE || TREE_CODE (t) == METHOD_TYPE
202 || (TREE_CODE (t) == POINTER_TYPE
203 && (TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE
204 || TREE_CODE (TREE_TYPE (t)) == METHOD_TYPE)));
205}
206
271 return NULL_TREE;
272 }
273 else
274 return type;
275}
276
277/* Return truthvalue of whether type of EXP is instantiated. */
278

--- 15 unchanged lines hidden (view full) ---

294 tree t;
295{
296 return (TREE_CODE (t) == FUNCTION_TYPE || TREE_CODE (t) == METHOD_TYPE
297 || (TREE_CODE (t) == POINTER_TYPE
298 && (TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE
299 || TREE_CODE (TREE_TYPE (t)) == METHOD_TYPE)));
300}
301
207/* Do `exp = require_instantiated_type (type, exp);' to make sure EXP
208 does not have an uninstantiated type.
209 TYPE is type to instantiate with, if uninstantiated. */
210
211tree
212require_instantiated_type (type, exp, errval)
213 tree type, exp, errval;
214{
215 if (TREE_TYPE (exp) == NULL_TREE)
216 {
217 error ("argument list may not have an initializer list");
218 return errval;
219 }
220
221 if (TREE_CODE (exp) == OVERLOAD
222 || TREE_TYPE (exp) == unknown_type_node
223 || (TREE_CODE (TREE_TYPE (exp)) == OFFSET_TYPE
224 && TREE_TYPE (TREE_TYPE (exp)) == unknown_type_node))
225 {
226 exp = instantiate_type (type, exp, 1);
227 if (TREE_TYPE (exp) == error_mark_node)
228 return errval;
229 }
230 return exp;
231}
232
233/* Return a variant of TYPE which has all the type qualifiers of LIKE
234 as well as those of TYPE. */
235
236static tree
237qualify_type (type, like)
238 tree type, like;
239{
302/* Return a variant of TYPE which has all the type qualifiers of LIKE
303 as well as those of TYPE. */
304
305static tree
306qualify_type (type, like)
307 tree type, like;
308{
240 int constflag = TYPE_READONLY (type) || TYPE_READONLY (like);
241 int volflag = TYPE_VOLATILE (type) || TYPE_VOLATILE (like);
242 /* @@ Must do member pointers here. */
309 /* @@ Must do member pointers here. */
243 return cp_build_type_variant (type, constflag, volflag);
310 return cp_build_qualified_type (type, (CP_TYPE_QUALS (type)
311 | CP_TYPE_QUALS (like)));
244}
245
246/* Return the common type of two parameter lists.
247 We assume that comptypes has already been done and returned 1;
248 if that isn't so, this may crash.
249
250 As an optimization, free the space we allocate if the parameter
251 lists are already common. */

--- 237 unchanged lines hidden (view full) ---

489 case POINTER_TYPE:
490 case REFERENCE_TYPE:
491 /* For two pointers, do this recursively on the target type,
492 and combine the qualifiers of the two types' targets. */
493 /* This code was turned off; I don't know why.
494 But ANSI C++ specifies doing this with the qualifiers.
495 So I turned it on again. */
496 {
312}
313
314/* Return the common type of two parameter lists.
315 We assume that comptypes has already been done and returned 1;
316 if that isn't so, this may crash.
317
318 As an optimization, free the space we allocate if the parameter
319 lists are already common. */

--- 237 unchanged lines hidden (view full) ---

557 case POINTER_TYPE:
558 case REFERENCE_TYPE:
559 /* For two pointers, do this recursively on the target type,
560 and combine the qualifiers of the two types' targets. */
561 /* This code was turned off; I don't know why.
562 But ANSI C++ specifies doing this with the qualifiers.
563 So I turned it on again. */
564 {
497 tree tt1 = TYPE_MAIN_VARIANT (TREE_TYPE (t1));
498 tree tt2 = TYPE_MAIN_VARIANT (TREE_TYPE (t2));
499 int constp
500 = TYPE_READONLY (TREE_TYPE (t1)) || TYPE_READONLY (TREE_TYPE (t2));
501 int volatilep
502 = TYPE_VOLATILE (TREE_TYPE (t1)) || TYPE_VOLATILE (TREE_TYPE (t2));
565 tree tt1 = TREE_TYPE (t1);
566 tree tt2 = TREE_TYPE (t2);
567 tree b1, b2;
568 int type_quals;
503 tree target;
504
569 tree target;
570
571 if (TREE_CODE (tt1) == OFFSET_TYPE)
572 {
573 b1 = TYPE_OFFSET_BASETYPE (tt1);
574 b2 = TYPE_OFFSET_BASETYPE (tt2);
575 tt1 = TREE_TYPE (tt1);
576 tt2 = TREE_TYPE (tt2);
577 }
578 else
579 b1 = b2 = NULL_TREE;
580
581 type_quals = (CP_TYPE_QUALS (tt1) | CP_TYPE_QUALS (tt2));
582 tt1 = TYPE_MAIN_VARIANT (tt1);
583 tt2 = TYPE_MAIN_VARIANT (tt2);
584
505 if (tt1 == tt2)
506 target = tt1;
585 if (tt1 == tt2)
586 target = tt1;
587 else if (b1)
588 {
589 compiler_error ("common_type called with uncommon member types");
590 target = tt1;
591 }
507 else if (tt1 == void_type_node || tt2 == void_type_node)
508 target = void_type_node;
509 else if (tt1 == unknown_type_node)
510 target = tt2;
511 else if (tt2 == unknown_type_node)
512 target = tt1;
513 else
514 target = common_type (tt1, tt2);
515
592 else if (tt1 == void_type_node || tt2 == void_type_node)
593 target = void_type_node;
594 else if (tt1 == unknown_type_node)
595 target = tt2;
596 else if (tt2 == unknown_type_node)
597 target = tt1;
598 else
599 target = common_type (tt1, tt2);
600
516 target = cp_build_type_variant (target, constp, volatilep);
601 target = cp_build_qualified_type (target, type_quals);
602
603 if (b1)
604 {
605 if (same_type_p (b1, b2)
606 || (DERIVED_FROM_P (b1, b2) && binfo_or_else (b1, b2)))
607 target = build_offset_type (b2, target);
608 else if (binfo_or_else (b2, b1))
609 target = build_offset_type (b1, target);
610 }
611
517 if (code1 == POINTER_TYPE)
518 t1 = build_pointer_type (target);
519 else
520 t1 = build_reference_type (target);
521 t1 = build_type_attribute_variant (t1, attributes);
522
523 if (TREE_CODE (target) == METHOD_TYPE)
524 t1 = build_ptrmemfunc_type (t1);

--- 57 unchanged lines hidden (view full) ---

582 t1 = TYPE_MAIN_VARIANT (t1);
583 t2 = TYPE_MAIN_VARIANT (t2);
584
585 if (DERIVED_FROM_P (t1, t2) && binfo_or_else (t1, t2))
586 return build_type_attribute_variant (t1, attributes);
587 else if (binfo_or_else (t2, t1))
588 return build_type_attribute_variant (t2, attributes);
589 else
612 if (code1 == POINTER_TYPE)
613 t1 = build_pointer_type (target);
614 else
615 t1 = build_reference_type (target);
616 t1 = build_type_attribute_variant (t1, attributes);
617
618 if (TREE_CODE (target) == METHOD_TYPE)
619 t1 = build_ptrmemfunc_type (t1);

--- 57 unchanged lines hidden (view full) ---

677 t1 = TYPE_MAIN_VARIANT (t1);
678 t2 = TYPE_MAIN_VARIANT (t2);
679
680 if (DERIVED_FROM_P (t1, t2) && binfo_or_else (t1, t2))
681 return build_type_attribute_variant (t1, attributes);
682 else if (binfo_or_else (t2, t1))
683 return build_type_attribute_variant (t2, attributes);
684 else
590 compiler_error ("common_type called with uncommon aggregate types");
685 {
686 compiler_error ("common_type called with uncommon aggregate types");
687 return error_mark_node;
688 }
591
592 case METHOD_TYPE:
593 if (TREE_CODE (TREE_TYPE (t1)) == TREE_CODE (TREE_TYPE (t2)))
594 {
595 /* Get this value the long way, since TYPE_METHOD_BASETYPE
596 is just the main variant of this. */
597 tree basetype;
598 tree raises, t3;
599
600 tree b1 = TYPE_OFFSET_BASETYPE (t1);
601 tree b2 = TYPE_OFFSET_BASETYPE (t2);
602
689
690 case METHOD_TYPE:
691 if (TREE_CODE (TREE_TYPE (t1)) == TREE_CODE (TREE_TYPE (t2)))
692 {
693 /* Get this value the long way, since TYPE_METHOD_BASETYPE
694 is just the main variant of this. */
695 tree basetype;
696 tree raises, t3;
697
698 tree b1 = TYPE_OFFSET_BASETYPE (t1);
699 tree b2 = TYPE_OFFSET_BASETYPE (t2);
700
603 if (comptypes (b1, b2, 1)
701 if (same_type_p (b1, b2)
604 || (DERIVED_FROM_P (b1, b2) && binfo_or_else (b1, b2)))
605 basetype = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t2)));
606 else
607 {
608 if (binfo_or_else (b2, b1) == NULL_TREE)
609 compiler_error ("common_type called with uncommon method types");
610 basetype = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t1)));
611 }

--- 13 unchanged lines hidden (view full) ---

625 t1 = build_exception_variant (t3, raises);
626 }
627 else
628 compiler_error ("common_type called with uncommon method types");
629
630 return build_type_attribute_variant (t1, attributes);
631
632 case OFFSET_TYPE:
702 || (DERIVED_FROM_P (b1, b2) && binfo_or_else (b1, b2)))
703 basetype = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t2)));
704 else
705 {
706 if (binfo_or_else (b2, b1) == NULL_TREE)
707 compiler_error ("common_type called with uncommon method types");
708 basetype = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t1)));
709 }

--- 13 unchanged lines hidden (view full) ---

723 t1 = build_exception_variant (t3, raises);
724 }
725 else
726 compiler_error ("common_type called with uncommon method types");
727
728 return build_type_attribute_variant (t1, attributes);
729
730 case OFFSET_TYPE:
633 if (TREE_TYPE (t1) == TREE_TYPE (t2))
634 {
635 tree b1 = TYPE_OFFSET_BASETYPE (t1);
636 tree b2 = TYPE_OFFSET_BASETYPE (t2);
731 /* Pointers to members should now be handled by the POINTER_TYPE
732 case above. */
733 my_friendly_abort (990325);
637
734
638 if (comptypes (b1, b2, 1)
639 || (DERIVED_FROM_P (b1, b2) && binfo_or_else (b1, b2)))
640 return build_type_attribute_variant (t2, attributes);
641 else if (binfo_or_else (b2, b1))
642 return build_type_attribute_variant (t1, attributes);
643 }
644 compiler_error ("common_type called with uncommon member types");
645
646 default:
647 return build_type_attribute_variant (t1, attributes);
648 }
649}
650
651/* Return 1 if TYPE1 and TYPE2 raise the same exceptions. */
652
653int
654compexcepttypes (t1, t2)
655 tree t1, t2;
656{
657 return TYPE_RAISES_EXCEPTIONS (t1) == TYPE_RAISES_EXCEPTIONS (t2);
658}
659
735 default:
736 return build_type_attribute_variant (t1, attributes);
737 }
738}
739
740/* Return 1 if TYPE1 and TYPE2 raise the same exceptions. */
741
742int
743compexcepttypes (t1, t2)
744 tree t1, t2;
745{
746 return TYPE_RAISES_EXCEPTIONS (t1) == TYPE_RAISES_EXCEPTIONS (t2);
747}
748
749/* Compare the array types T1 and T2, using CMP as the type comparison
750 function for the element types. STRICT is as for comptypes. */
751
660static int
661comp_array_types (cmp, t1, t2, strict)
662 register int (*cmp) PROTO((tree, tree, int));
663 tree t1, t2;
664 int strict;
665{
752static int
753comp_array_types (cmp, t1, t2, strict)
754 register int (*cmp) PROTO((tree, tree, int));
755 tree t1, t2;
756 int strict;
757{
666 tree d1 = TYPE_DOMAIN (t1);
667 tree d2 = TYPE_DOMAIN (t2);
758 tree d1;
759 tree d2;
668
760
669 /* Target types must match incl. qualifiers. */
761 if (t1 == t2)
762 return 1;
763
764 /* The type of the array elements must be the same. */
670 if (!(TREE_TYPE (t1) == TREE_TYPE (t2)
765 if (!(TREE_TYPE (t1) == TREE_TYPE (t2)
671 || (*cmp) (TREE_TYPE (t1), TREE_TYPE (t2), strict)))
766 || (*cmp) (TREE_TYPE (t1), TREE_TYPE (t2),
767 strict & ~COMPARE_REDECLARATION)))
672 return 0;
673
768 return 0;
769
674 /* Sizes must match unless one is missing or variable. */
675 if (d1 == 0 || d2 == 0 || d1 == d2
676 || TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
677 || TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
678 || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST
679 || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST)
770 d1 = TYPE_DOMAIN (t1);
771 d2 = TYPE_DOMAIN (t2);
772
773 if (d1 == d2)
680 return 1;
681
774 return 1;
775
682 return ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1))
683 == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2)))
684 && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1))
685 == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2)))
686 && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1))
687 == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2)))
688 && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1))
689 == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2))));
690}
776 /* If one of the arrays is dimensionless, and the other has a
777 dimension, they are of different types. However, it is legal to
778 write:
691
779
692/* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
693 or various other operations. This is what ANSI C++ speaks of as
694 "being the same".
780 extern int a[];
781 int a[3];
695
782
696 For C++: argument STRICT says we should be strict about this
697 comparison:
783 by [basic.link]:
698
784
699 2 : strict, except that if one type is a reference and
700 the other is not, compare the target type of the
701 reference to the type that's not a reference (ARM, p308).
702 This is used for checking for invalid overloading.
703 1 : strict (compared according to ANSI C)
704 This is used for checking whether two function decls match.
705 0 : <= (compared according to C++)
706 -1: <= or >= (relaxed)
785 declarations for an array object can specify
786 array types that differ by the presence or absence of a major
787 array bound (_dcl.array_). */
788 if (!d1 || !d2)
789 return strict & COMPARE_REDECLARATION;
707
790
708 Otherwise, pointers involving base classes and derived classes can
709 be mixed as valid: i.e. a pointer to a derived class may be converted
710 to a pointer to one of its base classes, as per C++. A pointer to
711 a derived class may be passed as a parameter to a function expecting a
712 pointer to a base classes. These allowances do not commute. In this
713 case, TYPE1 is assumed to be the base class, and TYPE2 is assumed to
714 be the derived class. */
791 /* Check that the dimensions are the same. */
792 return (cp_tree_equal (TYPE_MIN_VALUE (d1),
793 TYPE_MIN_VALUE (d2))
794 && cp_tree_equal (TYPE_MAX_VALUE (d1),
795 TYPE_MAX_VALUE (d2)));
796}
715
797
798/* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
799 or various other operations. STRICT is a bitwise-or of the
800 COMPARE_* flags. */
801
716int
717comptypes (type1, type2, strict)
718 tree type1, type2;
719 int strict;
720{
721 register tree t1 = type1;
722 register tree t2 = type2;
723 int attrval, val;
802int
803comptypes (type1, type2, strict)
804 tree type1, type2;
805 int strict;
806{
807 register tree t1 = type1;
808 register tree t2 = type2;
809 int attrval, val;
810 int orig_strict = strict;
724
811
725 /* Suppress errors caused by previously reported errors */
812 /* The special exemption for redeclaring array types without an
813 array bound only applies at the top level:
726
814
815 extern int (*i)[];
816 int (*i)[8];
817
818 is not legal, for example. */
819 strict &= ~COMPARE_REDECLARATION;
820
821 /* Suppress errors caused by previously reported errors */
727 if (t1 == t2)
728 return 1;
729
730 /* This should never happen. */
731 my_friendly_assert (t1 != error_mark_node, 307);
732
733 if (t2 == error_mark_node)
734 return 0;
735
822 if (t1 == t2)
823 return 1;
824
825 /* This should never happen. */
826 my_friendly_assert (t1 != error_mark_node, 307);
827
828 if (t2 == error_mark_node)
829 return 0;
830
736 if (strict < 0)
831 if (strict & COMPARE_RELAXED)
737 {
738 /* Treat an enum type as the unsigned integer type of the same width. */
739
740 if (TREE_CODE (t1) == ENUMERAL_TYPE)
741 t1 = type_for_size (TYPE_PRECISION (t1), 1);
742 if (TREE_CODE (t2) == ENUMERAL_TYPE)
743 t2 = type_for_size (TYPE_PRECISION (t2), 1);
744
745 if (t1 == t2)
746 return 1;
747 }
748
749 if (TYPE_PTRMEMFUNC_P (t1))
750 t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1);
751 if (TYPE_PTRMEMFUNC_P (t2))
752 t2 = TYPE_PTRMEMFUNC_FN_TYPE (t2);
753
754 /* Different classes of types can't be compatible. */
832 {
833 /* Treat an enum type as the unsigned integer type of the same width. */
834
835 if (TREE_CODE (t1) == ENUMERAL_TYPE)
836 t1 = type_for_size (TYPE_PRECISION (t1), 1);
837 if (TREE_CODE (t2) == ENUMERAL_TYPE)
838 t2 = type_for_size (TYPE_PRECISION (t2), 1);
839
840 if (t1 == t2)
841 return 1;
842 }
843
844 if (TYPE_PTRMEMFUNC_P (t1))
845 t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1);
846 if (TYPE_PTRMEMFUNC_P (t2))
847 t2 = TYPE_PTRMEMFUNC_FN_TYPE (t2);
848
849 /* Different classes of types can't be compatible. */
755
756 if (TREE_CODE (t1) != TREE_CODE (t2))
850 if (TREE_CODE (t1) != TREE_CODE (t2))
757 {
758 if (strict == 2
759 && ((TREE_CODE (t1) == REFERENCE_TYPE)
760 ^ (TREE_CODE (t2) == REFERENCE_TYPE)))
761 {
762 if (TREE_CODE (t1) == REFERENCE_TYPE)
763 return comptypes (TREE_TYPE (t1), t2, 1);
764 return comptypes (t1, TREE_TYPE (t2), 1);
765 }
851 return 0;
766
852
767 return 0;
768 }
769 if (strict > 1)
770 strict = 1;
771
772 /* Qualifiers must match. */
853 /* Qualifiers must match. */
773
774 if (TYPE_READONLY (t1) != TYPE_READONLY (t2))
854 if (CP_TYPE_QUALS (t1) != CP_TYPE_QUALS (t2))
775 return 0;
855 return 0;
776 if (TYPE_VOLATILE (t1) != TYPE_VOLATILE (t2))
856 if (strict == COMPARE_STRICT
857 && TYPE_FOR_JAVA (t1) != TYPE_FOR_JAVA (t2))
777 return 0;
858 return 0;
778 if (strict > 0 && TYPE_FOR_JAVA (t1) != TYPE_FOR_JAVA (t2))
779 return 0;
780
781 /* Allow for two different type nodes which have essentially the same
782 definition. Note that we already checked for equality of the type
783 qualifiers (just above). */
784
785 if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
786 return 1;
787
788 /* ??? COMP_TYPE_ATTRIBUTES is currently useless for variables as each
789 attribute is its own main variant (`val' will remain 0). */
790#ifndef COMP_TYPE_ATTRIBUTES
791#define COMP_TYPE_ATTRIBUTES(t1,t2) 1
792#endif
793
859
860 /* Allow for two different type nodes which have essentially the same
861 definition. Note that we already checked for equality of the type
862 qualifiers (just above). */
863
864 if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
865 return 1;
866
867 /* ??? COMP_TYPE_ATTRIBUTES is currently useless for variables as each
868 attribute is its own main variant (`val' will remain 0). */
869#ifndef COMP_TYPE_ATTRIBUTES
870#define COMP_TYPE_ATTRIBUTES(t1,t2) 1
871#endif
872
873 if (strict & COMPARE_NO_ATTRIBUTES)
874 attrval = 1;
794 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
875 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
795 if (! (attrval = COMP_TYPE_ATTRIBUTES (t1, t2)))
876 else if (! (attrval = COMP_TYPE_ATTRIBUTES (t1, t2)))
796 return 0;
797
798 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
799 val = 0;
800
801 switch (TREE_CODE (t1))
802 {
803 case TEMPLATE_TEMPLATE_PARM:
804 if (TEMPLATE_TYPE_IDX (t1) != TEMPLATE_TYPE_IDX (t2)
805 || TEMPLATE_TYPE_LEVEL (t1) != TEMPLATE_TYPE_LEVEL (t2))
806 return 0;
807 if (! comp_template_parms (DECL_TEMPLATE_PARMS (TYPE_NAME (t1)),
808 DECL_TEMPLATE_PARMS (TYPE_NAME (t2))))
809 return 0;
877 return 0;
878
879 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
880 val = 0;
881
882 switch (TREE_CODE (t1))
883 {
884 case TEMPLATE_TEMPLATE_PARM:
885 if (TEMPLATE_TYPE_IDX (t1) != TEMPLATE_TYPE_IDX (t2)
886 || TEMPLATE_TYPE_LEVEL (t1) != TEMPLATE_TYPE_LEVEL (t2))
887 return 0;
888 if (! comp_template_parms (DECL_TEMPLATE_PARMS (TYPE_NAME (t1)),
889 DECL_TEMPLATE_PARMS (TYPE_NAME (t2))))
890 return 0;
810 if (! CLASSTYPE_TEMPLATE_INFO (t1) && ! CLASSTYPE_TEMPLATE_INFO (t2))
891 if (!TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t1)
892 && ! TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2))
811 return 1;
812 /* Don't check inheritance. */
893 return 1;
894 /* Don't check inheritance. */
813 strict = 1;
895 strict = COMPARE_STRICT;
814 /* fall through */
815
816 case RECORD_TYPE:
817 case UNION_TYPE:
896 /* fall through */
897
898 case RECORD_TYPE:
899 case UNION_TYPE:
818 if (CLASSTYPE_TEMPLATE_INFO (t1) && CLASSTYPE_TEMPLATE_INFO (t2)
819 && (CLASSTYPE_TI_TEMPLATE (t1) == CLASSTYPE_TI_TEMPLATE (t2)
900 if (TYPE_TEMPLATE_INFO (t1) && TYPE_TEMPLATE_INFO (t2)
901 && (TYPE_TI_TEMPLATE (t1) == TYPE_TI_TEMPLATE (t2)
820 || TREE_CODE (t1) == TEMPLATE_TEMPLATE_PARM))
902 || TREE_CODE (t1) == TEMPLATE_TEMPLATE_PARM))
821 return comp_template_args (CLASSTYPE_TI_ARGS (t1),
822 CLASSTYPE_TI_ARGS (t2));
823 if (strict <= 0)
824 goto look_hard;
825 return 0;
903 val = comp_template_args (TYPE_TI_ARGS (t1),
904 TYPE_TI_ARGS (t2));
905 look_hard:
906 if ((strict & COMPARE_BASE) && DERIVED_FROM_P (t1, t2))
907 {
908 val = 1;
909 break;
910 }
911 if ((strict & COMPARE_RELAXED) && DERIVED_FROM_P (t2, t1))
912 {
913 val = 1;
914 break;
915 }
916 break;
826
827 case OFFSET_TYPE:
828 val = (comptypes (build_pointer_type (TYPE_OFFSET_BASETYPE (t1)),
829 build_pointer_type (TYPE_OFFSET_BASETYPE (t2)), strict)
830 && comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict));
831 break;
832
833 case METHOD_TYPE:
834 if (! compexcepttypes (t1, t2))
835 return 0;
836
837 /* This case is anti-symmetrical!
838 One can pass a base member (or member function)
839 to something expecting a derived member (or member function),
840 but not vice-versa! */
841
842 val = (comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict)
917
918 case OFFSET_TYPE:
919 val = (comptypes (build_pointer_type (TYPE_OFFSET_BASETYPE (t1)),
920 build_pointer_type (TYPE_OFFSET_BASETYPE (t2)), strict)
921 && comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict));
922 break;
923
924 case METHOD_TYPE:
925 if (! compexcepttypes (t1, t2))
926 return 0;
927
928 /* This case is anti-symmetrical!
929 One can pass a base member (or member function)
930 to something expecting a derived member (or member function),
931 but not vice-versa! */
932
933 val = (comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict)
843 && compparms (TYPE_ARG_TYPES (t1),
844 TYPE_ARG_TYPES (t2), strict));
934 && compparms (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2)));
845 break;
846
847 case POINTER_TYPE:
848 case REFERENCE_TYPE:
849 t1 = TREE_TYPE (t1);
850 t2 = TREE_TYPE (t2);
935 break;
936
937 case POINTER_TYPE:
938 case REFERENCE_TYPE:
939 t1 = TREE_TYPE (t1);
940 t2 = TREE_TYPE (t2);
851 if (t1 == t2)
852 {
853 val = 1;
854 break;
855 }
856 if (strict <= 0)
857 {
858 if (TREE_CODE (t1) == RECORD_TYPE && TREE_CODE (t2) == RECORD_TYPE)
859 {
860 int rval;
861 look_hard:
862 rval = t1 == t2 || DERIVED_FROM_P (t1, t2);
863
864 if (rval)
865 {
866 val = 1;
867 break;
868 }
869 if (strict < 0)
870 {
871 val = DERIVED_FROM_P (t2, t1);
872 break;
873 }
874 }
875 return 0;
876 }
877 else
878 val = comptypes (t1, t2, strict);
941 /* first, check whether the referred types match with the
942 required level of strictness */
943 val = comptypes (t1, t2, strict);
944 if (val)
945 break;
946 if (TREE_CODE (t1) == RECORD_TYPE
947 && TREE_CODE (t2) == RECORD_TYPE)
948 goto look_hard;
879 break;
880
881 case FUNCTION_TYPE:
882 if (! compexcepttypes (t1, t2))
883 return 0;
884
885 val = ((TREE_TYPE (t1) == TREE_TYPE (t2)
886 || comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict))
949 break;
950
951 case FUNCTION_TYPE:
952 if (! compexcepttypes (t1, t2))
953 return 0;
954
955 val = ((TREE_TYPE (t1) == TREE_TYPE (t2)
956 || comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict))
887 && compparms (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2), strict));
957 && compparms (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2)));
888 break;
889
890 case ARRAY_TYPE:
958 break;
959
960 case ARRAY_TYPE:
891 /* Target types must match incl. qualifiers. */
892 val = comp_array_types (comptypes, t1, t2, strict);
961 /* Target types must match incl. qualifiers. We use ORIG_STRICT
962 here since this is the one place where
963 COMPARE_REDECLARATION should be used. */
964 val = comp_array_types (comptypes, t1, t2, orig_strict);
893 break;
894
895 case TEMPLATE_TYPE_PARM:
896 return TEMPLATE_TYPE_IDX (t1) == TEMPLATE_TYPE_IDX (t2)
897 && TEMPLATE_TYPE_LEVEL (t1) == TEMPLATE_TYPE_LEVEL (t2);
898
899 case TYPENAME_TYPE:
900 if (TYPE_IDENTIFIER (t1) != TYPE_IDENTIFIER (t2))
901 return 0;
965 break;
966
967 case TEMPLATE_TYPE_PARM:
968 return TEMPLATE_TYPE_IDX (t1) == TEMPLATE_TYPE_IDX (t2)
969 && TEMPLATE_TYPE_LEVEL (t1) == TEMPLATE_TYPE_LEVEL (t2);
970
971 case TYPENAME_TYPE:
972 if (TYPE_IDENTIFIER (t1) != TYPE_IDENTIFIER (t2))
973 return 0;
902 return comptypes (TYPE_CONTEXT (t1), TYPE_CONTEXT (t2), 1);
974 return same_type_p (TYPE_CONTEXT (t1), TYPE_CONTEXT (t2));
903
904 default:
905 break;
906 }
907 return attrval == 2 && val == 1 ? 2 : val;
908}
909
975
976 default:
977 break;
978 }
979 return attrval == 2 && val == 1 ? 2 : val;
980}
981
982/* Subroutine of comp_target-types. Make sure that the cv-quals change
983 only in the same direction as the target type. */
984
985static int
986comp_cv_target_types (ttl, ttr, nptrs)
987 tree ttl, ttr;
988 int nptrs;
989{
990 int t;
991
992 if (!at_least_as_qualified_p (ttl, ttr)
993 && !at_least_as_qualified_p (ttr, ttl))
994 /* The qualifications are incomparable. */
995 return 0;
996
997 if (TYPE_MAIN_VARIANT (ttl) == TYPE_MAIN_VARIANT (ttr))
998 return more_qualified_p (ttr, ttl) ? -1 : 1;
999
1000 t = comp_target_types (ttl, ttr, nptrs);
1001 if ((t == 1 && at_least_as_qualified_p (ttl, ttr))
1002 || (t == -1 && at_least_as_qualified_p (ttr, ttl)))
1003 return t;
1004
1005 return 0;
1006}
1007
910/* Return 1 or -1 if TTL and TTR are pointers to types that are equivalent,
911 ignoring their qualifiers, 0 if not. Return 1 means that TTR can be
912 converted to TTL. Return -1 means that TTL can be converted to TTR but
913 not vice versa.
914
915 NPTRS is the number of pointers we can strip off and keep cool.
916 This is used to permit (for aggr A, aggr B) A, B* to convert to A*,
917 but to not permit B** to convert to A**.
918
919 This should go away. Callers should use can_convert or something
920 similar instead. (jason 17 Apr 1997) */
921
922int
923comp_target_types (ttl, ttr, nptrs)
924 tree ttl, ttr;
925 int nptrs;
926{
927 ttl = TYPE_MAIN_VARIANT (ttl);
928 ttr = TYPE_MAIN_VARIANT (ttr);
1008/* Return 1 or -1 if TTL and TTR are pointers to types that are equivalent,
1009 ignoring their qualifiers, 0 if not. Return 1 means that TTR can be
1010 converted to TTL. Return -1 means that TTL can be converted to TTR but
1011 not vice versa.
1012
1013 NPTRS is the number of pointers we can strip off and keep cool.
1014 This is used to permit (for aggr A, aggr B) A, B* to convert to A*,
1015 but to not permit B** to convert to A**.
1016
1017 This should go away. Callers should use can_convert or something
1018 similar instead. (jason 17 Apr 1997) */
1019
1020int
1021comp_target_types (ttl, ttr, nptrs)
1022 tree ttl, ttr;
1023 int nptrs;
1024{
1025 ttl = TYPE_MAIN_VARIANT (ttl);
1026 ttr = TYPE_MAIN_VARIANT (ttr);
929 if (ttl == ttr)
1027 if (same_type_p (ttl, ttr))
930 return 1;
931
932 if (TREE_CODE (ttr) != TREE_CODE (ttl))
933 return 0;
934
1028 return 1;
1029
1030 if (TREE_CODE (ttr) != TREE_CODE (ttl))
1031 return 0;
1032
935 if (TREE_CODE (ttr) == POINTER_TYPE
936 || (TREE_CODE (ttr) == REFERENCE_TYPE))
1033 if ((TREE_CODE (ttr) == POINTER_TYPE
1034 || TREE_CODE (ttr) == REFERENCE_TYPE)
1035 /* If we get a pointer with nptrs == 0, we don't allow any tweaking
1036 of the type pointed to. This is necessary for reference init
1037 semantics. We won't get here from a previous call with nptrs == 1;
1038 for multi-level pointers we end up in comp_ptr_ttypes. */
1039 && nptrs > 0)
937 {
938 int is_ptr = TREE_CODE (ttr) == POINTER_TYPE;
939
940 ttl = TREE_TYPE (ttl);
941 ttr = TREE_TYPE (ttr);
942
1040 {
1041 int is_ptr = TREE_CODE (ttr) == POINTER_TYPE;
1042
1043 ttl = TREE_TYPE (ttl);
1044 ttr = TREE_TYPE (ttr);
1045
943 if (nptrs > 0 && is_ptr)
1046 if (is_ptr)
944 {
945 if (TREE_CODE (ttl) == UNKNOWN_TYPE
946 || TREE_CODE (ttr) == UNKNOWN_TYPE)
947 return 1;
948 else if (TREE_CODE (ttl) == VOID_TYPE
949 && TREE_CODE (ttr) != FUNCTION_TYPE
950 && TREE_CODE (ttr) != METHOD_TYPE
951 && TREE_CODE (ttr) != OFFSET_TYPE)

--- 14 unchanged lines hidden (view full) ---

966 }
967 }
968
969 /* Const and volatile mean something different for function types,
970 so the usual checks are not appropriate. */
971 if (TREE_CODE (ttl) == FUNCTION_TYPE || TREE_CODE (ttl) == METHOD_TYPE)
972 return comp_target_types (ttl, ttr, nptrs - 1);
973
1047 {
1048 if (TREE_CODE (ttl) == UNKNOWN_TYPE
1049 || TREE_CODE (ttr) == UNKNOWN_TYPE)
1050 return 1;
1051 else if (TREE_CODE (ttl) == VOID_TYPE
1052 && TREE_CODE (ttr) != FUNCTION_TYPE
1053 && TREE_CODE (ttr) != METHOD_TYPE
1054 && TREE_CODE (ttr) != OFFSET_TYPE)

--- 14 unchanged lines hidden (view full) ---

1069 }
1070 }
1071
1072 /* Const and volatile mean something different for function types,
1073 so the usual checks are not appropriate. */
1074 if (TREE_CODE (ttl) == FUNCTION_TYPE || TREE_CODE (ttl) == METHOD_TYPE)
1075 return comp_target_types (ttl, ttr, nptrs - 1);
1076
974 /* Make sure that the cv-quals change only in the same direction as
975 the target type. */
976 {
977 int t;
978 int c = TYPE_READONLY (ttl) - TYPE_READONLY (ttr);
979 int v = TYPE_VOLATILE (ttl) - TYPE_VOLATILE (ttr);
980
981 if ((c > 0 && v < 0) || (c < 0 && v > 0))
982 return 0;
983
984 if (TYPE_MAIN_VARIANT (ttl) == TYPE_MAIN_VARIANT (ttr))
985 return (c + v < 0) ? -1 : 1;
986
987 t = comp_target_types (ttl, ttr, nptrs - 1);
988 if ((t == 1 && c + v >= 0) || (t == -1 && c + v <= 0))
989 return t;
990
991 return 0;
992 }
1077 return comp_cv_target_types (ttl, ttr, nptrs - 1);
993 }
994
995 if (TREE_CODE (ttr) == ARRAY_TYPE)
1078 }
1079
1080 if (TREE_CODE (ttr) == ARRAY_TYPE)
996 return comp_array_types (comp_target_types, ttl, ttr, 0);
1081 return comp_array_types (comp_target_types, ttl, ttr, COMPARE_STRICT);
997 else if (TREE_CODE (ttr) == FUNCTION_TYPE || TREE_CODE (ttr) == METHOD_TYPE)
998 {
999 tree argsl, argsr;
1000 int saw_contra = 0;
1001
1002 if (pedantic)
1003 {
1082 else if (TREE_CODE (ttr) == FUNCTION_TYPE || TREE_CODE (ttr) == METHOD_TYPE)
1083 {
1084 tree argsl, argsr;
1085 int saw_contra = 0;
1086
1087 if (pedantic)
1088 {
1004 if (comptypes (TREE_TYPE (ttl), TREE_TYPE (ttr), 1) == 0)
1089 if (!same_type_p (TREE_TYPE (ttl), TREE_TYPE (ttr)))
1005 return 0;
1006 }
1007 else
1008 {
1009 switch (comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), -1))
1010 {
1011 case 0:
1012 return 0;

--- 6 unchanged lines hidden (view full) ---

1019 argsr = TYPE_ARG_TYPES (ttr);
1020
1021 /* Compare 'this' here, not in comp_target_parms. */
1022 if (TREE_CODE (ttr) == METHOD_TYPE)
1023 {
1024 tree tl = TYPE_METHOD_BASETYPE (ttl);
1025 tree tr = TYPE_METHOD_BASETYPE (ttr);
1026
1090 return 0;
1091 }
1092 else
1093 {
1094 switch (comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), -1))
1095 {
1096 case 0:
1097 return 0;

--- 6 unchanged lines hidden (view full) ---

1104 argsr = TYPE_ARG_TYPES (ttr);
1105
1106 /* Compare 'this' here, not in comp_target_parms. */
1107 if (TREE_CODE (ttr) == METHOD_TYPE)
1108 {
1109 tree tl = TYPE_METHOD_BASETYPE (ttl);
1110 tree tr = TYPE_METHOD_BASETYPE (ttr);
1111
1027 if (comptypes (tr, tl, 0) == 0)
1112 if (!same_or_base_type_p (tr, tl))
1028 {
1113 {
1029 if (comptypes (tl, tr, 0))
1114 if (same_or_base_type_p (tl, tr))
1030 saw_contra = 1;
1031 else
1032 return 0;
1033 }
1034
1035 argsl = TREE_CHAIN (argsl);
1036 argsr = TREE_CHAIN (argsr);
1037 }

--- 6 unchanged lines hidden (view full) ---

1044 saw_contra = 1;
1045 }
1046
1047 return saw_contra ? -1 : 1;
1048 }
1049 /* for C++ */
1050 else if (TREE_CODE (ttr) == OFFSET_TYPE)
1051 {
1115 saw_contra = 1;
1116 else
1117 return 0;
1118 }
1119
1120 argsl = TREE_CHAIN (argsl);
1121 argsr = TREE_CHAIN (argsr);
1122 }

--- 6 unchanged lines hidden (view full) ---

1129 saw_contra = 1;
1130 }
1131
1132 return saw_contra ? -1 : 1;
1133 }
1134 /* for C++ */
1135 else if (TREE_CODE (ttr) == OFFSET_TYPE)
1136 {
1137 int base;
1138
1052 /* Contravariance: we can assign a pointer to base member to a pointer
1053 to derived member. Note difference from simple pointer case, where
1054 we can pass a pointer to derived to a pointer to base. */
1139 /* Contravariance: we can assign a pointer to base member to a pointer
1140 to derived member. Note difference from simple pointer case, where
1141 we can pass a pointer to derived to a pointer to base. */
1055 if (comptypes (TYPE_OFFSET_BASETYPE (ttr),
1056 TYPE_OFFSET_BASETYPE (ttl), 0))
1057 return comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs);
1058 else if (comptypes (TYPE_OFFSET_BASETYPE (ttl),
1059 TYPE_OFFSET_BASETYPE (ttr), 0)
1060 && comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs))
1061 return -1;
1142 if (same_or_base_type_p (TYPE_OFFSET_BASETYPE (ttr),
1143 TYPE_OFFSET_BASETYPE (ttl)))
1144 base = 1;
1145 else if (same_or_base_type_p (TYPE_OFFSET_BASETYPE (ttl),
1146 TYPE_OFFSET_BASETYPE (ttr)))
1147 {
1148 tree tmp = ttl;
1149 ttl = ttr;
1150 ttr = tmp;
1151 base = -1;
1152 }
1153 else
1154 return 0;
1155
1156 ttl = TREE_TYPE (ttl);
1157 ttr = TREE_TYPE (ttr);
1158
1159 if (TREE_CODE (ttl) == POINTER_TYPE
1160 || TREE_CODE (ttl) == ARRAY_TYPE)
1161 {
1162 if (comp_ptr_ttypes (ttl, ttr))
1163 return base;
1164 return 0;
1165 }
1166 else
1167 {
1168 if (comp_cv_target_types (ttl, ttr, nptrs) == 1)
1169 return base;
1170 return 0;
1171 }
1062 }
1063 else if (IS_AGGR_TYPE (ttl))
1064 {
1065 if (nptrs < 0)
1066 return 0;
1172 }
1173 else if (IS_AGGR_TYPE (ttl))
1174 {
1175 if (nptrs < 0)
1176 return 0;
1067 if (comptypes (build_pointer_type (ttl), build_pointer_type (ttr), 0))
1177 if (same_or_base_type_p (build_pointer_type (ttl),
1178 build_pointer_type (ttr)))
1068 return 1;
1179 return 1;
1069 if (comptypes (build_pointer_type (ttr), build_pointer_type (ttl), 0))
1180 if (same_or_base_type_p (build_pointer_type (ttr),
1181 build_pointer_type (ttl)))
1070 return -1;
1071 return 0;
1072 }
1073
1074 return 0;
1075}
1076
1182 return -1;
1183 return 0;
1184 }
1185
1186 return 0;
1187}
1188
1189/* Returns 1 if TYPE1 is at least as qualified as TYPE2. */
1190
1191int
1192at_least_as_qualified_p (type1, type2)
1193 tree type1;
1194 tree type2;
1195{
1196 /* All qualifiers for TYPE2 must also appear in TYPE1. */
1197 return ((CP_TYPE_QUALS (type1) & CP_TYPE_QUALS (type2))
1198 == CP_TYPE_QUALS (type2));
1199}
1200
1201/* Returns 1 if TYPE1 is more qualified than TYPE2. */
1202
1203int
1204more_qualified_p (type1, type2)
1205 tree type1;
1206 tree type2;
1207{
1208 return (CP_TYPE_QUALS (type1) != CP_TYPE_QUALS (type2)
1209 && at_least_as_qualified_p (type1, type2));
1210}
1211
1077/* Returns 1 if TYPE1 is more cv-qualified than TYPE2, -1 if TYPE2 is
1078 more cv-qualified that TYPE1, and 0 otherwise. */
1079
1080int
1081comp_cv_qualification (type1, type2)
1082 tree type1;
1083 tree type2;
1084{
1212/* Returns 1 if TYPE1 is more cv-qualified than TYPE2, -1 if TYPE2 is
1213 more cv-qualified that TYPE1, and 0 otherwise. */
1214
1215int
1216comp_cv_qualification (type1, type2)
1217 tree type1;
1218 tree type2;
1219{
1085 if (TYPE_READONLY (type1) == TYPE_READONLY (type2)
1086 && TYPE_VOLATILE (type1) == TYPE_VOLATILE (type2))
1220 if (CP_TYPE_QUALS (type1) == CP_TYPE_QUALS (type2))
1087 return 0;
1088
1221 return 0;
1222
1089 if (TYPE_READONLY (type1) >= TYPE_READONLY (type2)
1090 && TYPE_VOLATILE (type1) >= TYPE_VOLATILE (type2))
1223 if (at_least_as_qualified_p (type1, type2))
1091 return 1;
1092
1224 return 1;
1225
1093 if (TYPE_READONLY (type2) >= TYPE_READONLY (type1)
1094 && TYPE_VOLATILE (type2) >= TYPE_VOLATILE (type1))
1226 else if (at_least_as_qualified_p (type2, type1))
1095 return -1;
1096
1097 return 0;
1098}
1099
1100/* Returns 1 if the cv-qualification signature of TYPE1 is a proper
1101 subset of the cv-qualification signature of TYPE2, and the types
1102 are similar. Returns -1 if the other way 'round, and 0 otherwise. */

--- 60 unchanged lines hidden (view full) ---

1163 return error_mark_node;
1164 }
1165 }
1166 return best;
1167}
1168
1169/* Subroutines of `comptypes'. */
1170
1227 return -1;
1228
1229 return 0;
1230}
1231
1232/* Returns 1 if the cv-qualification signature of TYPE1 is a proper
1233 subset of the cv-qualification signature of TYPE2, and the types
1234 are similar. Returns -1 if the other way 'round, and 0 otherwise. */

--- 60 unchanged lines hidden (view full) ---

1295 return error_mark_node;
1296 }
1297 }
1298 return best;
1299}
1300
1301/* Subroutines of `comptypes'. */
1302
1171/* Return 1 if two parameter type lists PARMS1 and PARMS2
1172 are equivalent in the sense that functions with those parameter types
1173 can have equivalent types.
1174 If either list is empty, we win.
1175 Otherwise, the two lists must be equivalent, element by element.
1303/* Return 1 if two parameter type lists PARMS1 and PARMS2 are
1304 equivalent in the sense that functions with those parameter types
1305 can have equivalent types. The two lists must be equivalent,
1306 element by element.
1176
1307
1177 C++: See comment above about TYPE1, TYPE2.
1308 C++: See comment above about TYPE1, TYPE2. */
1178
1309
1179 STRICT is no longer used. */
1180
1181int
1310int
1182compparms (parms1, parms2, strict)
1311compparms (parms1, parms2)
1183 tree parms1, parms2;
1312 tree parms1, parms2;
1184 int strict;
1185{
1186 register tree t1 = parms1, t2 = parms2;
1187
1188 /* An unspecified parmlist matches any specified parmlist
1189 whose argument types don't need default promotions. */
1190
1191 while (1)
1192 {
1193 if (t1 == 0 && t2 == 0)
1194 return 1;
1195 /* If one parmlist is shorter than the other,
1196 they fail to match. */
1197 if (t1 == 0 || t2 == 0)
1198 return 0;
1313{
1314 register tree t1 = parms1, t2 = parms2;
1315
1316 /* An unspecified parmlist matches any specified parmlist
1317 whose argument types don't need default promotions. */
1318
1319 while (1)
1320 {
1321 if (t1 == 0 && t2 == 0)
1322 return 1;
1323 /* If one parmlist is shorter than the other,
1324 they fail to match. */
1325 if (t1 == 0 || t2 == 0)
1326 return 0;
1199 if (! comptypes (TREE_VALUE (t2), TREE_VALUE (t1), 1))
1327 if (!same_type_p (TREE_VALUE (t2), TREE_VALUE (t1)))
1200 return 0;
1201
1202 t1 = TREE_CHAIN (t1);
1203 t2 = TREE_CHAIN (t2);
1204 }
1205}
1206
1207/* This really wants return whether or not parameter type lists

--- 14 unchanged lines hidden (view full) ---

1222 int warn_contravariance = 0;
1223
1224 /* In C, an unspecified parmlist matches any specified parmlist
1225 whose argument types don't need default promotions. This is not
1226 true for C++, but let's do it anyway for unfixed headers. */
1227
1228 if (t1 == 0 && t2 != 0)
1229 {
1328 return 0;
1329
1330 t1 = TREE_CHAIN (t1);
1331 t2 = TREE_CHAIN (t2);
1332 }
1333}
1334
1335/* This really wants return whether or not parameter type lists

--- 14 unchanged lines hidden (view full) ---

1350 int warn_contravariance = 0;
1351
1352 /* In C, an unspecified parmlist matches any specified parmlist
1353 whose argument types don't need default promotions. This is not
1354 true for C++, but let's do it anyway for unfixed headers. */
1355
1356 if (t1 == 0 && t2 != 0)
1357 {
1230 cp_pedwarn ("ANSI C++ prohibits conversion from `(%#T)' to `(...)'",
1231 parms2);
1358 if (! flag_strict_prototype && t2 == void_list_node)
1359 /* t1 might be the arglist of a function pointer in extern "C"
1360 declared to take (), which we fudged to (...). Don't make the
1361 user pay for our mistake. */;
1362 else
1363 cp_pedwarn ("ANSI C++ prohibits conversion from `%#T' to `(...)'",
1364 parms2);
1232 return self_promoting_args_p (t2);
1233 }
1234 if (t2 == 0)
1235 return self_promoting_args_p (t1);
1236
1237 for (; t1 || t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
1238 {
1239 tree p1, p2;

--- 5 unchanged lines hidden (view full) ---

1245 if (strict > 0)
1246 return 0;
1247 if (strict < 0)
1248 return 1 + warn_contravariance;
1249 return ((t1 && TREE_PURPOSE (t1)) + warn_contravariance);
1250 }
1251 p1 = TREE_VALUE (t1);
1252 p2 = TREE_VALUE (t2);
1365 return self_promoting_args_p (t2);
1366 }
1367 if (t2 == 0)
1368 return self_promoting_args_p (t1);
1369
1370 for (; t1 || t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
1371 {
1372 tree p1, p2;

--- 5 unchanged lines hidden (view full) ---

1378 if (strict > 0)
1379 return 0;
1380 if (strict < 0)
1381 return 1 + warn_contravariance;
1382 return ((t1 && TREE_PURPOSE (t1)) + warn_contravariance);
1383 }
1384 p1 = TREE_VALUE (t1);
1385 p2 = TREE_VALUE (t2);
1253 if (comptypes (p1, p2, 1))
1386 if (same_type_p (p1, p2))
1254 continue;
1255
1256 if (pedantic)
1257 return 0;
1258
1259 if ((TREE_CODE (p1) == POINTER_TYPE && TREE_CODE (p2) == POINTER_TYPE)
1260 || (TREE_CODE (p1) == REFERENCE_TYPE
1261 && TREE_CODE (p2) == REFERENCE_TYPE))

--- 7 unchanged lines hidden (view full) ---

1269 but many programs depend on it. */
1270 if (TREE_TYPE (p1) == void_type_node)
1271 continue;
1272 if (TREE_TYPE (p2) == void_type_node)
1273 {
1274 warn_contravariance = 1;
1275 continue;
1276 }
1387 continue;
1388
1389 if (pedantic)
1390 return 0;
1391
1392 if ((TREE_CODE (p1) == POINTER_TYPE && TREE_CODE (p2) == POINTER_TYPE)
1393 || (TREE_CODE (p1) == REFERENCE_TYPE
1394 && TREE_CODE (p2) == REFERENCE_TYPE))

--- 7 unchanged lines hidden (view full) ---

1402 but many programs depend on it. */
1403 if (TREE_TYPE (p1) == void_type_node)
1404 continue;
1405 if (TREE_TYPE (p2) == void_type_node)
1406 {
1407 warn_contravariance = 1;
1408 continue;
1409 }
1277 if (IS_AGGR_TYPE (TREE_TYPE (p1)))
1278 {
1279 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (p1)),
1280 TYPE_MAIN_VARIANT (TREE_TYPE (p2)), 1) == 0)
1281 return 0;
1282 }
1410 if (IS_AGGR_TYPE (TREE_TYPE (p1))
1411 && !same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (p1)),
1412 TYPE_MAIN_VARIANT (TREE_TYPE (p2))))
1413 return 0;
1283 }
1284 /* Note backwards order due to contravariance. */
1285 if (comp_target_types (p2, p1, 1) <= 0)
1286 {
1287 if (comp_target_types (p1, p2, 1) > 0)
1288 {
1289 warn_contravariance = 1;
1290 continue;

--- 46 unchanged lines hidden (view full) ---

1337 if (type1 == integer_type_node)
1338 return unsigned_type_node;
1339 if (type1 == short_integer_type_node)
1340 return short_unsigned_type_node;
1341 if (type1 == long_integer_type_node)
1342 return long_unsigned_type_node;
1343 if (type1 == long_long_integer_type_node)
1344 return long_long_unsigned_type_node;
1414 }
1415 /* Note backwards order due to contravariance. */
1416 if (comp_target_types (p2, p1, 1) <= 0)
1417 {
1418 if (comp_target_types (p1, p2, 1) > 0)
1419 {
1420 warn_contravariance = 1;
1421 continue;

--- 46 unchanged lines hidden (view full) ---

1468 if (type1 == integer_type_node)
1469 return unsigned_type_node;
1470 if (type1 == short_integer_type_node)
1471 return short_unsigned_type_node;
1472 if (type1 == long_integer_type_node)
1473 return long_unsigned_type_node;
1474 if (type1 == long_long_integer_type_node)
1475 return long_long_unsigned_type_node;
1476#if HOST_BITS_PER_WIDE_INT >= 64
1345 if (type1 == intTI_type_node)
1346 return unsigned_intTI_type_node;
1477 if (type1 == intTI_type_node)
1478 return unsigned_intTI_type_node;
1479#endif
1347 if (type1 == intDI_type_node)
1348 return unsigned_intDI_type_node;
1349 if (type1 == intSI_type_node)
1350 return unsigned_intSI_type_node;
1351 if (type1 == intHI_type_node)
1352 return unsigned_intHI_type_node;
1353 if (type1 == intQI_type_node)
1354 return unsigned_intQI_type_node;

--- 13 unchanged lines hidden (view full) ---

1368 if (type1 == unsigned_type_node)
1369 return integer_type_node;
1370 if (type1 == short_unsigned_type_node)
1371 return short_integer_type_node;
1372 if (type1 == long_unsigned_type_node)
1373 return long_integer_type_node;
1374 if (type1 == long_long_unsigned_type_node)
1375 return long_long_integer_type_node;
1480 if (type1 == intDI_type_node)
1481 return unsigned_intDI_type_node;
1482 if (type1 == intSI_type_node)
1483 return unsigned_intSI_type_node;
1484 if (type1 == intHI_type_node)
1485 return unsigned_intHI_type_node;
1486 if (type1 == intQI_type_node)
1487 return unsigned_intQI_type_node;

--- 13 unchanged lines hidden (view full) ---

1501 if (type1 == unsigned_type_node)
1502 return integer_type_node;
1503 if (type1 == short_unsigned_type_node)
1504 return short_integer_type_node;
1505 if (type1 == long_unsigned_type_node)
1506 return long_integer_type_node;
1507 if (type1 == long_long_unsigned_type_node)
1508 return long_long_integer_type_node;
1509#if HOST_BITS_PER_WIDE_INT >= 64
1376 if (type1 == unsigned_intTI_type_node)
1377 return intTI_type_node;
1510 if (type1 == unsigned_intTI_type_node)
1511 return intTI_type_node;
1512#endif
1378 if (type1 == unsigned_intDI_type_node)
1379 return intDI_type_node;
1380 if (type1 == unsigned_intSI_type_node)
1381 return intSI_type_node;
1382 if (type1 == unsigned_intHI_type_node)
1383 return intHI_type_node;
1384 if (type1 == unsigned_intQI_type_node)
1385 return intQI_type_node;

--- 102 unchanged lines hidden (view full) ---

1488tree
1489expr_sizeof (e)
1490 tree e;
1491{
1492 if (processing_template_decl)
1493 return build_min (SIZEOF_EXPR, sizetype, e);
1494
1495 if (TREE_CODE (e) == COMPONENT_REF
1513 if (type1 == unsigned_intDI_type_node)
1514 return intDI_type_node;
1515 if (type1 == unsigned_intSI_type_node)
1516 return intSI_type_node;
1517 if (type1 == unsigned_intHI_type_node)
1518 return intHI_type_node;
1519 if (type1 == unsigned_intQI_type_node)
1520 return intQI_type_node;

--- 102 unchanged lines hidden (view full) ---

1623tree
1624expr_sizeof (e)
1625 tree e;
1626{
1627 if (processing_template_decl)
1628 return build_min (SIZEOF_EXPR, sizetype, e);
1629
1630 if (TREE_CODE (e) == COMPONENT_REF
1496 && DECL_BIT_FIELD (TREE_OPERAND (e, 1)))
1631 && DECL_C_BIT_FIELD (TREE_OPERAND (e, 1)))
1497 error ("sizeof applied to a bit-field");
1498 /* ANSI says arrays and functions are converted inside comma.
1499 But we can't really convert them in build_compound_expr
1500 because that would break commas in lvalues.
1501 So do the conversion here if operand was a comma. */
1502 if (TREE_CODE (e) == COMPOUND_EXPR
1503 && (TREE_CODE (TREE_TYPE (e)) == ARRAY_TYPE
1504 || TREE_CODE (TREE_TYPE (e)) == FUNCTION_TYPE))
1505 e = default_conversion (e);
1632 error ("sizeof applied to a bit-field");
1633 /* ANSI says arrays and functions are converted inside comma.
1634 But we can't really convert them in build_compound_expr
1635 because that would break commas in lvalues.
1636 So do the conversion here if operand was a comma. */
1637 if (TREE_CODE (e) == COMPOUND_EXPR
1638 && (TREE_CODE (TREE_TYPE (e)) == ARRAY_TYPE
1639 || TREE_CODE (TREE_TYPE (e)) == FUNCTION_TYPE))
1640 e = default_conversion (e);
1506 else if (TREE_CODE (e) == TREE_LIST)
1641 else if (is_overloaded_fn (e))
1507 {
1642 {
1508 tree t = TREE_VALUE (e);
1509 if (t != NULL_TREE
1510 && ((TREE_TYPE (t)
1511 && TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
1512 || is_overloaded_fn (t)))
1513 pedwarn ("ANSI C++ forbids taking the sizeof a function type");
1643 pedwarn ("ANSI C++ forbids taking the sizeof a function type");
1644 return size_int (1);
1514 }
1645 }
1646 else if (type_unknown_p (e))
1647 {
1648 incomplete_type_error (e, TREE_TYPE (e));
1649 return size_int (1);
1650 }
1651
1515 return c_sizeof (TREE_TYPE (e));
1516}
1517
1518tree
1519c_sizeof_nowarn (type)
1520 tree type;
1521{
1522 enum tree_code code = TREE_CODE (type);

--- 49 unchanged lines hidden (view full) ---

1572 return size_int (1);
1573 }
1574
1575 t = size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
1576 force_fit_type (t, 0);
1577 return t;
1578}
1579
1652 return c_sizeof (TREE_TYPE (e));
1653}
1654
1655tree
1656c_sizeof_nowarn (type)
1657 tree type;
1658{
1659 enum tree_code code = TREE_CODE (type);

--- 49 unchanged lines hidden (view full) ---

1709 return size_int (1);
1710 }
1711
1712 t = size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
1713 force_fit_type (t, 0);
1714 return t;
1715}
1716
1580/* Perform default promotions for C data used in expressions.
1581 Arrays and functions are converted to pointers;
1582 enumeral types or short or char, to int.
1583 In addition, manifest constants symbols are replaced by their values.
1717/* Perform the array-to-pointer and function-to-pointer conversions
1718 for EXP.
1584
1719
1585 C++: this will automatically bash references to their target type. */
1720 In addition, references are converted to rvalues and manifest
1721 constants are replaced by their values. */
1586
1587tree
1588decay_conversion (exp)
1589 tree exp;
1590{
1722
1723tree
1724decay_conversion (exp)
1725 tree exp;
1726{
1591 register tree type = TREE_TYPE (exp);
1592 register enum tree_code code = TREE_CODE (type);
1727 register tree type;
1728 register enum tree_code code;
1593
1729
1594 if (code == OFFSET_TYPE)
1595 {
1596 if (TREE_CODE (exp) == OFFSET_REF)
1597 return decay_conversion (resolve_offset_ref (exp));
1730 if (TREE_CODE (exp) == OFFSET_REF)
1731 exp = resolve_offset_ref (exp);
1598
1732
1599 type = TREE_TYPE (type);
1600 code = TREE_CODE (type);
1733 type = TREE_TYPE (exp);
1734 code = TREE_CODE (type);
1601
1735
1602 if (type == unknown_type_node)
1603 {
1604 cp_pedwarn ("assuming & on overloaded member function");
1605 return build_unary_op (ADDR_EXPR, exp, 0);
1606 }
1607 }
1608
1609 if (code == REFERENCE_TYPE)
1610 {
1611 exp = convert_from_reference (exp);
1612 type = TREE_TYPE (exp);
1613 code = TREE_CODE (type);
1614 }
1615
1616 /* Constants can be used directly unless they're not loadable. */
1617 if (TREE_CODE (exp) == CONST_DECL)
1618 exp = DECL_INITIAL (exp);
1736 if (code == REFERENCE_TYPE)
1737 {
1738 exp = convert_from_reference (exp);
1739 type = TREE_TYPE (exp);
1740 code = TREE_CODE (type);
1741 }
1742
1743 /* Constants can be used directly unless they're not loadable. */
1744 if (TREE_CODE (exp) == CONST_DECL)
1745 exp = DECL_INITIAL (exp);
1619 /* Replace a nonvolatile const static variable with its value. */
1620 else if (TREE_READONLY_DECL_P (exp))
1746 /* Replace a nonvolatile const static variable with its value. We
1747 don't do this for arrays, though; we want the address of the
1748 first element of the array, not the address of the first element
1749 of its initializing constant. We *do* replace variables that the
1750 user isn't really supposed to know about; this is a hack to deal
1751 with __PRETTY_FUNCTION__ and the like. */
1752 else if (TREE_READONLY_DECL_P (exp)
1753 && (code != ARRAY_TYPE
1754 || (TREE_CODE (exp) == VAR_DECL && DECL_IGNORED_P (exp))))
1621 {
1622 exp = decl_constant_value (exp);
1623 type = TREE_TYPE (exp);
1624 }
1625
1626 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
1627 Leave such NOP_EXPRs, since RHS is being used in non-lvalue context. */
1628
1629 if (code == VOID_TYPE)
1630 {
1631 error ("void value not ignored as it ought to be");
1632 return error_mark_node;
1633 }
1755 {
1756 exp = decl_constant_value (exp);
1757 type = TREE_TYPE (exp);
1758 }
1759
1760 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
1761 Leave such NOP_EXPRs, since RHS is being used in non-lvalue context. */
1762
1763 if (code == VOID_TYPE)
1764 {
1765 error ("void value not ignored as it ought to be");
1766 return error_mark_node;
1767 }
1634 if (code == FUNCTION_TYPE)
1635 {
1636 return build_unary_op (ADDR_EXPR, exp, 0);
1637 }
1638 if (code == METHOD_TYPE)
1768 if (code == METHOD_TYPE)
1639 {
1640 cp_pedwarn ("assuming & on `%E'", exp);
1641 return build_unary_op (ADDR_EXPR, exp, 0);
1642 }
1769 my_friendly_abort (990506);
1770 if (code == FUNCTION_TYPE || is_overloaded_fn (exp))
1771 return build_unary_op (ADDR_EXPR, exp, 0);
1643 if (code == ARRAY_TYPE)
1644 {
1645 register tree adr;
1772 if (code == ARRAY_TYPE)
1773 {
1774 register tree adr;
1646 tree restype;
1647 tree ptrtype;
1775 tree ptrtype;
1648 int constp, volatilep;
1649
1650 if (TREE_CODE (exp) == INDIRECT_REF)
1651 {
1652 /* Stripping away the INDIRECT_REF is not the right
1653 thing to do for references... */
1654 tree inner = TREE_OPERAND (exp, 0);
1655 if (TREE_CODE (TREE_TYPE (inner)) == REFERENCE_TYPE)
1656 {

--- 15 unchanged lines hidden (view full) ---

1672
1673 if (!lvalue_p (exp)
1674 && ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp)))
1675 {
1676 error ("invalid use of non-lvalue array");
1677 return error_mark_node;
1678 }
1679
1776
1777 if (TREE_CODE (exp) == INDIRECT_REF)
1778 {
1779 /* Stripping away the INDIRECT_REF is not the right
1780 thing to do for references... */
1781 tree inner = TREE_OPERAND (exp, 0);
1782 if (TREE_CODE (TREE_TYPE (inner)) == REFERENCE_TYPE)
1783 {

--- 15 unchanged lines hidden (view full) ---

1799
1800 if (!lvalue_p (exp)
1801 && ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp)))
1802 {
1803 error ("invalid use of non-lvalue array");
1804 return error_mark_node;
1805 }
1806
1680 constp = volatilep = 0;
1681 if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'r'
1682 || TREE_CODE_CLASS (TREE_CODE (exp)) == 'd')
1683 {
1684 constp = TREE_READONLY (exp);
1685 volatilep = TREE_THIS_VOLATILE (exp);
1686 }
1807 ptrtype = build_pointer_type (TREE_TYPE (type));
1687
1808
1688 restype = TREE_TYPE (type);
1689 if (TYPE_READONLY (type) || TYPE_VOLATILE (type)
1690 || constp || volatilep)
1691 restype = cp_build_type_variant (restype,
1692 TYPE_READONLY (type) || constp,
1693 TYPE_VOLATILE (type) || volatilep);
1694 ptrtype = build_pointer_type (restype);
1695
1696 if (TREE_CODE (exp) == VAR_DECL)
1697 {
1698 /* ??? This is not really quite correct
1699 in that the type of the operand of ADDR_EXPR
1700 is not the target type of the type of the ADDR_EXPR itself.
1701 Question is, can this lossage be avoided? */
1702 adr = build1 (ADDR_EXPR, ptrtype, exp);
1703 if (mark_addressable (exp) == 0)

--- 36 unchanged lines hidden (view full) ---

1740/* Take the address of an inline function without setting TREE_ADDRESSABLE
1741 or TREE_USED. */
1742
1743tree
1744inline_conversion (exp)
1745 tree exp;
1746{
1747 if (TREE_CODE (exp) == FUNCTION_DECL)
1809 if (TREE_CODE (exp) == VAR_DECL)
1810 {
1811 /* ??? This is not really quite correct
1812 in that the type of the operand of ADDR_EXPR
1813 is not the target type of the type of the ADDR_EXPR itself.
1814 Question is, can this lossage be avoided? */
1815 adr = build1 (ADDR_EXPR, ptrtype, exp);
1816 if (mark_addressable (exp) == 0)

--- 36 unchanged lines hidden (view full) ---

1853/* Take the address of an inline function without setting TREE_ADDRESSABLE
1854 or TREE_USED. */
1855
1856tree
1857inline_conversion (exp)
1858 tree exp;
1859{
1860 if (TREE_CODE (exp) == FUNCTION_DECL)
1861 exp = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (exp)), exp);
1862
1863 return exp;
1864}
1865
1866/* Returns nonzero iff exp is a STRING_CST or the result of applying
1867 decay_conversion to one. */
1868
1869int
1870string_conv_p (totype, exp, warn)
1871 tree totype, exp;
1872 int warn;
1873{
1874 tree t;
1875
1876 if (! flag_const_strings || TREE_CODE (totype) != POINTER_TYPE)
1877 return 0;
1878
1879 t = TREE_TYPE (totype);
1880 if (!same_type_p (t, char_type_node)
1881 && !same_type_p (t, wchar_type_node))
1882 return 0;
1883
1884 if (TREE_CODE (exp) == STRING_CST)
1748 {
1885 {
1749 tree type = build_type_variant
1750 (TREE_TYPE (exp), TREE_READONLY (exp), TREE_THIS_VOLATILE (exp));
1751 exp = build1 (ADDR_EXPR, build_pointer_type (type), exp);
1886 /* Make sure that we don't try to convert between char and wchar_t. */
1887 if (!same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (exp))), t))
1888 return 0;
1752 }
1889 }
1753 return exp;
1890 else
1891 {
1892 /* Is this a string constant which has decayed to 'const char *'? */
1893 t = build_pointer_type (build_qualified_type (t, TYPE_QUAL_CONST));
1894 if (!same_type_p (TREE_TYPE (exp), t))
1895 return 0;
1896 STRIP_NOPS (exp);
1897 if (TREE_CODE (exp) != ADDR_EXPR
1898 || TREE_CODE (TREE_OPERAND (exp, 0)) != STRING_CST)
1899 return 0;
1900 }
1901
1902 /* This warning is not very useful, as it complains about printf. */
1903 if (warn && warn_write_strings)
1904 cp_warning ("deprecated conversion from string constant to `%T'", totype);
1905
1906 return 1;
1754}
1755
1756tree
1757build_object_ref (datum, basetype, field)
1758 tree datum, basetype, field;
1759{
1760 tree dtype;
1761 if (datum == error_mark_node)

--- 110 unchanged lines hidden (view full) ---

1872 COMPONENT can be an IDENTIFIER_NODE that is the name of the member
1873 that we are interested in, or it can be a FIELD_DECL. */
1874
1875tree
1876build_component_ref (datum, component, basetype_path, protect)
1877 tree datum, component, basetype_path;
1878 int protect;
1879{
1907}
1908
1909tree
1910build_object_ref (datum, basetype, field)
1911 tree datum, basetype, field;
1912{
1913 tree dtype;
1914 if (datum == error_mark_node)

--- 110 unchanged lines hidden (view full) ---

2025 COMPONENT can be an IDENTIFIER_NODE that is the name of the member
2026 that we are interested in, or it can be a FIELD_DECL. */
2027
2028tree
2029build_component_ref (datum, component, basetype_path, protect)
2030 tree datum, component, basetype_path;
2031 int protect;
2032{
1880 register tree basetype = TREE_TYPE (datum);
2033 register tree basetype;
1881 register enum tree_code code;
1882 register tree field = NULL;
1883 register tree ref;
2034 register enum tree_code code;
2035 register tree field = NULL;
2036 register tree ref;
2037 tree field_type;
2038 int type_quals;
1884
1885 if (processing_template_decl)
1886 return build_min_nt (COMPONENT_REF, datum, component);
2039
2040 if (processing_template_decl)
2041 return build_min_nt (COMPONENT_REF, datum, component);
2042
2043 if (datum == error_mark_node
2044 || TREE_TYPE (datum) == error_mark_node)
2045 return error_mark_node;
1887
2046
2047 /* BASETYPE holds the type of the class containing the COMPONENT. */
2048 basetype = TYPE_MAIN_VARIANT (TREE_TYPE (datum));
2049
1888 /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference
1889 inside it. */
1890 switch (TREE_CODE (datum))
1891 {
1892 case COMPOUND_EXPR:
1893 {
1894 tree value = build_component_ref (TREE_OPERAND (datum, 1), component,
1895 basetype_path, protect);

--- 17 unchanged lines hidden (view full) ---

1913 break;
1914 }
1915
1916 code = TREE_CODE (basetype);
1917
1918 if (code == REFERENCE_TYPE)
1919 {
1920 datum = convert_from_reference (datum);
2050 /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference
2051 inside it. */
2052 switch (TREE_CODE (datum))
2053 {
2054 case COMPOUND_EXPR:
2055 {
2056 tree value = build_component_ref (TREE_OPERAND (datum, 1), component,
2057 basetype_path, protect);

--- 17 unchanged lines hidden (view full) ---

2075 break;
2076 }
2077
2078 code = TREE_CODE (basetype);
2079
2080 if (code == REFERENCE_TYPE)
2081 {
2082 datum = convert_from_reference (datum);
1921 basetype = TREE_TYPE (datum);
2083 basetype = TYPE_MAIN_VARIANT (TREE_TYPE (datum));
1922 code = TREE_CODE (basetype);
1923 }
1924 if (TREE_CODE (datum) == OFFSET_REF)
1925 {
1926 datum = resolve_offset_ref (datum);
2084 code = TREE_CODE (basetype);
2085 }
2086 if (TREE_CODE (datum) == OFFSET_REF)
2087 {
2088 datum = resolve_offset_ref (datum);
1927 basetype = TREE_TYPE (datum);
2089 basetype = TYPE_MAIN_VARIANT (TREE_TYPE (datum));
1928 code = TREE_CODE (basetype);
1929 }
1930
1931 /* First, see if there is a field or component with name COMPONENT. */
1932 if (TREE_CODE (component) == TREE_LIST)
1933 {
1934 /* I could not trigger this code. MvL */
1935 my_friendly_abort (980326);

--- 7 unchanged lines hidden (view full) ---

1943 if (! IS_AGGR_TYPE_CODE (code))
1944 {
1945 if (code != ERROR_MARK)
1946 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
1947 component, datum, basetype);
1948 return error_mark_node;
1949 }
1950
2090 code = TREE_CODE (basetype);
2091 }
2092
2093 /* First, see if there is a field or component with name COMPONENT. */
2094 if (TREE_CODE (component) == TREE_LIST)
2095 {
2096 /* I could not trigger this code. MvL */
2097 my_friendly_abort (980326);

--- 7 unchanged lines hidden (view full) ---

2105 if (! IS_AGGR_TYPE_CODE (code))
2106 {
2107 if (code != ERROR_MARK)
2108 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
2109 component, datum, basetype);
2110 return error_mark_node;
2111 }
2112
1951 if (!complete_type_or_else (basetype))
2113 if (!complete_type_or_else (basetype, datum))
1952 return error_mark_node;
1953
1954 if (TREE_CODE (component) == BIT_NOT_EXPR)
1955 {
1956 if (TYPE_IDENTIFIER (basetype) != TREE_OPERAND (component, 0))
1957 {
1958 cp_error ("destructor specifier `%T::~%T' must have matching names",
1959 basetype, TREE_OPERAND (component, 0));

--- 13 unchanged lines hidden (view full) ---

1973 /* Special-case this because if we use normal lookups in an ambiguous
1974 hierarchy, the compiler will abort (because vptr lookups are
1975 not supposed to be ambiguous. */
1976 field = CLASSTYPE_VFIELD (basetype);
1977 else if (TREE_CODE (component) == FIELD_DECL)
1978 field = component;
1979 else if (TREE_CODE (component) == TYPE_DECL)
1980 {
2114 return error_mark_node;
2115
2116 if (TREE_CODE (component) == BIT_NOT_EXPR)
2117 {
2118 if (TYPE_IDENTIFIER (basetype) != TREE_OPERAND (component, 0))
2119 {
2120 cp_error ("destructor specifier `%T::~%T' must have matching names",
2121 basetype, TREE_OPERAND (component, 0));

--- 13 unchanged lines hidden (view full) ---

2135 /* Special-case this because if we use normal lookups in an ambiguous
2136 hierarchy, the compiler will abort (because vptr lookups are
2137 not supposed to be ambiguous. */
2138 field = CLASSTYPE_VFIELD (basetype);
2139 else if (TREE_CODE (component) == FIELD_DECL)
2140 field = component;
2141 else if (TREE_CODE (component) == TYPE_DECL)
2142 {
1981 cp_pedwarn ("invalid use of type decl `%#D' as expression", component);
1982 return component;
2143 cp_error ("invalid use of type decl `%#D' as expression", component);
2144 return error_mark_node;
1983 }
1984 else
1985 {
1986 tree name = component;
1987 if (TREE_CODE (component) == VAR_DECL)
1988 name = DECL_NAME (component);
1989 if (basetype_path == NULL_TREE)
1990 basetype_path = TYPE_BINFO (basetype);

--- 7 unchanged lines hidden (view full) ---

1998 /* Not found as a data field, look for it as a method. If found,
1999 then if this is the only possible one, return it, else
2000 report ambiguity error. */
2001 tree fndecls = lookup_fnfields (basetype_path, name, 1);
2002 if (fndecls == error_mark_node)
2003 return error_mark_node;
2004 if (fndecls)
2005 {
2145 }
2146 else
2147 {
2148 tree name = component;
2149 if (TREE_CODE (component) == VAR_DECL)
2150 name = DECL_NAME (component);
2151 if (basetype_path == NULL_TREE)
2152 basetype_path = TYPE_BINFO (basetype);

--- 7 unchanged lines hidden (view full) ---

2160 /* Not found as a data field, look for it as a method. If found,
2161 then if this is the only possible one, return it, else
2162 report ambiguity error. */
2163 tree fndecls = lookup_fnfields (basetype_path, name, 1);
2164 if (fndecls == error_mark_node)
2165 return error_mark_node;
2166 if (fndecls)
2167 {
2168 /* If the function is unique and static, we can resolve it
2169 now. Otherwise, we have to wait and see what context it is
2170 used in; a component_ref involving a non-static member
2171 function can only be used in a call (expr.ref). */
2172
2006 if (TREE_CHAIN (fndecls) == NULL_TREE
2173 if (TREE_CHAIN (fndecls) == NULL_TREE
2007 && TREE_CODE (TREE_VALUE (fndecls)) != OVERLOAD)
2174 && TREE_CODE (TREE_VALUE (fndecls)) == FUNCTION_DECL)
2008 {
2175 {
2009 tree access, fndecl;
2010
2011 /* Unique, so use this one now. */
2012 basetype = TREE_PURPOSE (fndecls);
2013 fndecl = TREE_VALUE (fndecls);
2014 access = compute_access (TREE_PURPOSE (fndecls), fndecl);
2015 if (access == access_public_node)
2176 if (DECL_STATIC_FUNCTION_P (TREE_VALUE (fndecls)))
2016 {
2177 {
2017 if (DECL_VINDEX (fndecl)
2018 && ! resolves_to_fixed_type_p (datum, 0))
2019 {
2020 tree addr = build_unary_op (ADDR_EXPR, datum, 0);
2021 tree fntype = TREE_TYPE (fndecl);
2022
2023 addr = convert_pointer_to (DECL_CONTEXT (fndecl),
2024 addr);
2025 datum = build_indirect_ref (addr, NULL_PTR);
2026 my_friendly_assert (datum != error_mark_node, 310);
2027 fndecl = build_vfn_ref (&addr, datum,
2028 DECL_VINDEX (fndecl));
2029 /* The type of fndecl is a function type,
2030 not a pointer-to-function type, since
2031 build_vfn_ref returns not the correct
2032 vtable slot, but the indirection of the
2033 correct vtable slot. */
2034 TREE_TYPE (fndecl) = fntype;
2035 }
2036 else
2037 mark_used (fndecl);
2038 return build (OFFSET_REF, TREE_TYPE (fndecl),
2039 datum, fndecl);
2178 tree fndecl = TREE_VALUE (fndecls);
2179 enforce_access (TREE_PURPOSE (fndecls), fndecl);
2180 mark_used (fndecl);
2181 return fndecl;
2040 }
2182 }
2041 if (access == access_protected_node)
2042 cp_error ("member function `%D' is protected", fndecl);
2043 else
2183 else
2044 cp_error ("member function `%D' is private", fndecl);
2045 return error_mark_node;
2184 {
2185 /* A unique non-static member function. Other parts
2186 of the compiler expect something with
2187 unknown_type_node to be really overloaded, so
2188 let's oblige. */
2189 TREE_VALUE (fndecls)
2190 = scratch_ovl_cons (TREE_VALUE (fndecls), NULL_TREE);
2191 }
2046 }
2192 }
2047 else
2048 {
2049 /* Just act like build_offset_ref, since the object does
2050 not matter unless we're actually calling the function. */
2051 tree t;
2052
2193
2053 t = build_tree_list (error_mark_node, fndecls);
2054 TREE_TYPE (t) = build_offset_type (basetype,
2055 unknown_type_node);
2056 return t;
2057 }
2194 ref = build (COMPONENT_REF, unknown_type_node,
2195 datum, TREE_VALUE (fndecls));
2196 return ref;
2058 }
2059
2060 cp_error ("`%#T' has no member named `%D'", basetype, name);
2061 return error_mark_node;
2062 }
2063 else if (TREE_TYPE (field) == error_mark_node)
2064 return error_mark_node;
2065

--- 10 unchanged lines hidden (view full) ---

2076 }
2077
2078 /* See if we have to do any conversions so that we pick up the field from the
2079 right context. */
2080 if (DECL_FIELD_CONTEXT (field) != basetype)
2081 {
2082 tree context = DECL_FIELD_CONTEXT (field);
2083 tree base = context;
2197 }
2198
2199 cp_error ("`%#T' has no member named `%D'", basetype, name);
2200 return error_mark_node;
2201 }
2202 else if (TREE_TYPE (field) == error_mark_node)
2203 return error_mark_node;
2204

--- 10 unchanged lines hidden (view full) ---

2215 }
2216
2217 /* See if we have to do any conversions so that we pick up the field from the
2218 right context. */
2219 if (DECL_FIELD_CONTEXT (field) != basetype)
2220 {
2221 tree context = DECL_FIELD_CONTEXT (field);
2222 tree base = context;
2084 while (!comptypes (base, basetype,1) && TYPE_NAME (base)
2223 while (!same_type_p (base, basetype) && TYPE_NAME (base)
2085 && ANON_UNION_TYPE_P (base))
2086 {
2087 base = TYPE_CONTEXT (base);
2088 }
2089
2090 /* Handle base classes here... */
2091 if (base != basetype && TYPE_USES_COMPLEX_INHERITANCE (basetype))
2092 {

--- 23 unchanged lines hidden (view full) ---

2116 {
2117 tree subfield = lookup_anon_field (basetype, context);
2118 tree subdatum = build_component_ref (datum, subfield,
2119 basetype_path, protect);
2120 return build_component_ref (subdatum, field, basetype_path, protect);
2121 }
2122 }
2123
2224 && ANON_UNION_TYPE_P (base))
2225 {
2226 base = TYPE_CONTEXT (base);
2227 }
2228
2229 /* Handle base classes here... */
2230 if (base != basetype && TYPE_USES_COMPLEX_INHERITANCE (basetype))
2231 {

--- 23 unchanged lines hidden (view full) ---

2255 {
2256 tree subfield = lookup_anon_field (basetype, context);
2257 tree subdatum = build_component_ref (datum, subfield,
2258 basetype_path, protect);
2259 return build_component_ref (subdatum, field, basetype_path, protect);
2260 }
2261 }
2262
2124 ref = fold (build (COMPONENT_REF, TREE_TYPE (field),
2263 /* Compute the type of the field, as described in [expr.ref]. */
2264 type_quals = TYPE_UNQUALIFIED;
2265 field_type = TREE_TYPE (field);
2266 if (TREE_CODE (field_type) == REFERENCE_TYPE)
2267 /* The standard says that the type of the result should be the
2268 type referred to by the reference. But for now, at least, we
2269 do the conversion from reference type later. */
2270 ;
2271 else
2272 {
2273 type_quals = (CP_TYPE_QUALS (field_type)
2274 | CP_TYPE_QUALS (TREE_TYPE (datum)));
2275
2276 /* A field is const (volatile) if the enclosing object, or the
2277 field itself, is const (volatile). But, a mutable field is
2278 not const, even within a const object. */
2279 if (DECL_LANG_SPECIFIC (field) && DECL_MUTABLE_P (field))
2280 type_quals &= ~TYPE_QUAL_CONST;
2281 if (!IS_SIGNATURE (field_type))
2282 field_type = cp_build_qualified_type (field_type, type_quals);
2283 }
2284
2285 ref = fold (build (COMPONENT_REF, field_type,
2125 break_out_cleanups (datum), field));
2126
2286 break_out_cleanups (datum), field));
2287
2127 if (TREE_READONLY (datum) || TREE_READONLY (field))
2288 /* Mark the expression const or volatile, as appropriate. Even
2289 though we've dealt with the type above, we still have to mark the
2290 expression itself. */
2291 if (type_quals & TYPE_QUAL_CONST)
2128 TREE_READONLY (ref) = 1;
2292 TREE_READONLY (ref) = 1;
2129 if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (field))
2293 else if (type_quals & TYPE_QUAL_VOLATILE)
2130 TREE_THIS_VOLATILE (ref) = 1;
2294 TREE_THIS_VOLATILE (ref) = 1;
2131 if (DECL_LANG_SPECIFIC (field) && DECL_MUTABLE_P (field))
2132 TREE_READONLY (ref) = 0;
2133
2134 return ref;
2135}
2136
2137/* Variant of build_component_ref for use in expressions, which should
2138 never have REFERENCE_TYPE. */
2139
2140tree

--- 14 unchanged lines hidden (view full) ---

2155 ERRORSTRING is the name of the operator to appear in error messages.
2156
2157 This function may need to overload OPERATOR_FNNAME.
2158 Must also handle REFERENCE_TYPEs for C++. */
2159
2160tree
2161build_x_indirect_ref (ptr, errorstring)
2162 tree ptr;
2295
2296 return ref;
2297}
2298
2299/* Variant of build_component_ref for use in expressions, which should
2300 never have REFERENCE_TYPE. */
2301
2302tree

--- 14 unchanged lines hidden (view full) ---

2317 ERRORSTRING is the name of the operator to appear in error messages.
2318
2319 This function may need to overload OPERATOR_FNNAME.
2320 Must also handle REFERENCE_TYPEs for C++. */
2321
2322tree
2323build_x_indirect_ref (ptr, errorstring)
2324 tree ptr;
2163 char *errorstring;
2325 const char *errorstring;
2164{
2165 tree rval;
2166
2167 if (processing_template_decl)
2168 return build_min_nt (INDIRECT_REF, ptr);
2169
2170 rval = build_opfncall (INDIRECT_REF, LOOKUP_NORMAL, ptr, NULL_TREE,
2171 NULL_TREE);
2172 if (rval)
2173 return rval;
2174 return build_indirect_ref (ptr, errorstring);
2175}
2176
2177tree
2178build_indirect_ref (ptr, errorstring)
2179 tree ptr;
2326{
2327 tree rval;
2328
2329 if (processing_template_decl)
2330 return build_min_nt (INDIRECT_REF, ptr);
2331
2332 rval = build_opfncall (INDIRECT_REF, LOOKUP_NORMAL, ptr, NULL_TREE,
2333 NULL_TREE);
2334 if (rval)
2335 return rval;
2336 return build_indirect_ref (ptr, errorstring);
2337}
2338
2339tree
2340build_indirect_ref (ptr, errorstring)
2341 tree ptr;
2180 char *errorstring;
2342 const char *errorstring;
2181{
2182 register tree pointer, type;
2183
2184 if (ptr == error_mark_node)
2185 return error_mark_node;
2186
2343{
2344 register tree pointer, type;
2345
2346 if (ptr == error_mark_node)
2347 return error_mark_node;
2348
2349 if (ptr == current_class_ptr)
2350 return current_class_ref;
2351
2187 pointer = (TREE_CODE (TREE_TYPE (ptr)) == REFERENCE_TYPE
2188 ? ptr : default_conversion (ptr));
2189 type = TREE_TYPE (pointer);
2190
2352 pointer = (TREE_CODE (TREE_TYPE (ptr)) == REFERENCE_TYPE
2353 ? ptr : default_conversion (ptr));
2354 type = TREE_TYPE (pointer);
2355
2191 if (ptr == current_class_ptr)
2192 return current_class_ref;
2193
2194 if (TREE_CODE (type) == POINTER_TYPE || TREE_CODE (type) == REFERENCE_TYPE)
2356 if (TYPE_PTR_P (type) || TREE_CODE (type) == REFERENCE_TYPE)
2195 {
2357 {
2358 /* [expr.unary.op]
2359
2360 If the type of the expression is "pointer to T," the type
2361 of the result is "T."
2362
2363 We must use the canonical variant because certain parts of
2364 the back end, like fold, do pointer comparisons between
2365 types. */
2366 tree t = canonical_type_variant (TREE_TYPE (type));
2367
2196 if (TREE_CODE (pointer) == ADDR_EXPR
2197 && !flag_volatile
2368 if (TREE_CODE (pointer) == ADDR_EXPR
2369 && !flag_volatile
2198 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (pointer, 0)))
2199 == TYPE_MAIN_VARIANT (TREE_TYPE (type)))
2200 && (TREE_READONLY (TREE_OPERAND (pointer, 0))
2201 == TYPE_READONLY (TREE_TYPE (type)))
2202 && (TREE_THIS_VOLATILE (TREE_OPERAND (pointer, 0))
2203 == TYPE_VOLATILE (TREE_TYPE (type))))
2370 && same_type_p (t, TREE_TYPE (TREE_OPERAND (pointer, 0))))
2371 /* The POINTER was something like `&x'. We simplify `*&x' to
2372 `x'. */
2204 return TREE_OPERAND (pointer, 0);
2205 else
2206 {
2373 return TREE_OPERAND (pointer, 0);
2374 else
2375 {
2207 tree t = TREE_TYPE (type);
2208 register tree ref = build1 (INDIRECT_REF,
2209 TYPE_MAIN_VARIANT (t), pointer);
2376 tree ref = build1 (INDIRECT_REF, t, pointer);
2210
2211 /* We *must* set TREE_READONLY when dereferencing a pointer to const,
2212 so that we get the proper error message if the result is used
2213 to assign to. Also, &* is supposed to be a no-op. */
2377
2378 /* We *must* set TREE_READONLY when dereferencing a pointer to const,
2379 so that we get the proper error message if the result is used
2380 to assign to. Also, &* is supposed to be a no-op. */
2214 TREE_READONLY (ref) = TYPE_READONLY (t);
2381 TREE_READONLY (ref) = CP_TYPE_CONST_P (t);
2382 TREE_THIS_VOLATILE (ref) = CP_TYPE_VOLATILE_P (t);
2215 TREE_SIDE_EFFECTS (ref)
2383 TREE_SIDE_EFFECTS (ref)
2216 = (TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer)
2384 = (TREE_THIS_VOLATILE (ref) || TREE_SIDE_EFFECTS (pointer)
2217 || flag_volatile);
2385 || flag_volatile);
2218 TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t);
2219 return ref;
2220 }
2221 }
2222 /* `pointer' won't be an error_mark_node if we were given a
2223 pointer to member, so it's cool to check for this here. */
2386 return ref;
2387 }
2388 }
2389 /* `pointer' won't be an error_mark_node if we were given a
2390 pointer to member, so it's cool to check for this here. */
2224 else if (TYPE_PTRMEMFUNC_P (type))
2225 error ("invalid use of `%s' on pointer to member function", errorstring);
2391 else if (TYPE_PTRMEM_P (type) || TYPE_PTRMEMFUNC_P (type))
2392 error ("invalid use of `%s' on pointer to member", errorstring);
2226 else if (TREE_CODE (type) == RECORD_TYPE
2227 && (IS_SIGNATURE_POINTER (type) || IS_SIGNATURE_REFERENCE (type)))
2228 error ("cannot dereference signature pointer/reference");
2229 else if (pointer != error_mark_node)
2230 {
2231 if (errorstring)
2232 error ("invalid type argument of `%s'", errorstring);
2233 else

--- 87 unchanged lines hidden (view full) ---

2321 {
2322 tree foo = array;
2323 while (TREE_CODE (foo) == COMPONENT_REF)
2324 foo = TREE_OPERAND (foo, 0);
2325 if (TREE_CODE (foo) == VAR_DECL && DECL_REGISTER (foo))
2326 warning ("subscripting array declared `register'");
2327 }
2328
2393 else if (TREE_CODE (type) == RECORD_TYPE
2394 && (IS_SIGNATURE_POINTER (type) || IS_SIGNATURE_REFERENCE (type)))
2395 error ("cannot dereference signature pointer/reference");
2396 else if (pointer != error_mark_node)
2397 {
2398 if (errorstring)
2399 error ("invalid type argument of `%s'", errorstring);
2400 else

--- 87 unchanged lines hidden (view full) ---

2488 {
2489 tree foo = array;
2490 while (TREE_CODE (foo) == COMPONENT_REF)
2491 foo = TREE_OPERAND (foo, 0);
2492 if (TREE_CODE (foo) == VAR_DECL && DECL_REGISTER (foo))
2493 warning ("subscripting array declared `register'");
2494 }
2495
2329 type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array)));
2496 type = TREE_TYPE (TREE_TYPE (array));
2330 rval = build (ARRAY_REF, type, array, idx);
2331 /* Array ref is const/volatile if the array elements are
2332 or if the array is.. */
2333 TREE_READONLY (rval)
2497 rval = build (ARRAY_REF, type, array, idx);
2498 /* Array ref is const/volatile if the array elements are
2499 or if the array is.. */
2500 TREE_READONLY (rval)
2334 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
2335 | TREE_READONLY (array));
2501 |= (CP_TYPE_CONST_P (type) | TREE_READONLY (array));
2336 TREE_SIDE_EFFECTS (rval)
2502 TREE_SIDE_EFFECTS (rval)
2337 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
2338 | TREE_SIDE_EFFECTS (array));
2503 |= (CP_TYPE_VOLATILE_P (type) | TREE_SIDE_EFFECTS (array));
2339 TREE_THIS_VOLATILE (rval)
2504 TREE_THIS_VOLATILE (rval)
2340 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
2341 /* This was added by rms on 16 Nov 91.
2342 It fixes vol struct foo *a; a->elts[1]
2343 in an inline function.
2344 Hope it doesn't break something else. */
2345 | TREE_THIS_VOLATILE (array));
2505 |= (CP_TYPE_VOLATILE_P (type) | TREE_THIS_VOLATILE (array));
2346 return require_complete_type (fold (rval));
2347 }
2348
2349 {
2350 tree ar = default_conversion (array);
2351 tree ind = default_conversion (idx);
2352
2353 /* Put the integer in IND to simplify error checking. */

--- 85 unchanged lines hidden (view full) ---

2439 if (TREE_CODE (function) == OVERLOAD)
2440 function = OVL_FUNCTION (function);
2441 my_friendly_assert (TREE_CODE (function) == FUNCTION_DECL, 999);
2442 function = DECL_NAME (function);
2443 return build_method_call (decl, function, params,
2444 TYPE_BINFO (type), LOOKUP_NORMAL);
2445 }
2446
2506 return require_complete_type (fold (rval));
2507 }
2508
2509 {
2510 tree ar = default_conversion (array);
2511 tree ind = default_conversion (idx);
2512
2513 /* Put the integer in IND to simplify error checking. */

--- 85 unchanged lines hidden (view full) ---

2599 if (TREE_CODE (function) == OVERLOAD)
2600 function = OVL_FUNCTION (function);
2601 my_friendly_assert (TREE_CODE (function) == FUNCTION_DECL, 999);
2602 function = DECL_NAME (function);
2603 return build_method_call (decl, function, params,
2604 TYPE_BINFO (type), LOOKUP_NORMAL);
2605 }
2606
2607 if ((TREE_CODE (function) == FUNCTION_DECL
2608 && DECL_STATIC_FUNCTION_P (function))
2609 || (TREE_CODE (function) == TEMPLATE_DECL
2610 && DECL_STATIC_FUNCTION_P (DECL_RESULT (function))))
2611 return build_member_call(DECL_CONTEXT (function),
2612 template_id
2613 ? template_id : DECL_NAME (function),
2614 params);
2615
2447 is_method = ((TREE_CODE (function) == TREE_LIST
2448 && current_class_type != NULL_TREE
2449 && (IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (function))
2450 == function))
2616 is_method = ((TREE_CODE (function) == TREE_LIST
2617 && current_class_type != NULL_TREE
2618 && (IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (function))
2619 == function))
2620 || (TREE_CODE (function) == OVERLOAD
2621 && DECL_FUNCTION_MEMBER_P (OVL_CURRENT (function)))
2451 || TREE_CODE (function) == IDENTIFIER_NODE
2452 || TREE_CODE (type) == METHOD_TYPE
2453 || TYPE_PTRMEMFUNC_P (type));
2454
2622 || TREE_CODE (function) == IDENTIFIER_NODE
2623 || TREE_CODE (type) == METHOD_TYPE
2624 || TYPE_PTRMEMFUNC_P (type));
2625
2455 if ((TREE_CODE (function) == FUNCTION_DECL
2456 && DECL_STATIC_FUNCTION_P (function))
2457 || (TREE_CODE (function) == TEMPLATE_DECL
2458 && DECL_STATIC_FUNCTION_P (DECL_RESULT (function))))
2459 return build_member_call
2460 (DECL_CONTEXT (function), DECL_NAME (function), params);
2461
2462 /* A friend template. Make it look like a toplevel declaration. */
2463 if (! is_method && TREE_CODE (function) == TEMPLATE_DECL)
2464 function = scratch_ovl_cons (function, NULL_TREE);
2465
2466 /* Handle methods, friends, and overloaded functions, respectively. */
2467 if (is_method)
2468 {
2469 tree basetype = NULL_TREE;
2470
2626 /* A friend template. Make it look like a toplevel declaration. */
2627 if (! is_method && TREE_CODE (function) == TEMPLATE_DECL)
2628 function = scratch_ovl_cons (function, NULL_TREE);
2629
2630 /* Handle methods, friends, and overloaded functions, respectively. */
2631 if (is_method)
2632 {
2633 tree basetype = NULL_TREE;
2634
2635 if (TREE_CODE (function) == OVERLOAD)
2636 function = OVL_CURRENT (function);
2637
2471 if (TREE_CODE (function) == FUNCTION_DECL
2472 || DECL_FUNCTION_TEMPLATE_P (function))
2473 {
2474 basetype = DECL_CLASS_CONTEXT (function);
2475
2476 if (DECL_NAME (function))
2477 function = DECL_NAME (function);
2478 else

--- 35 unchanged lines hidden (view full) ---

2514 if (basetype && (! current_class_type
2515 || ! DERIVED_FROM_P (basetype, current_class_type)))
2516 return build_member_call (basetype, function, params);
2517
2518 if (decl == NULL_TREE)
2519 {
2520 if (current_class_type == NULL_TREE)
2521 {
2638 if (TREE_CODE (function) == FUNCTION_DECL
2639 || DECL_FUNCTION_TEMPLATE_P (function))
2640 {
2641 basetype = DECL_CLASS_CONTEXT (function);
2642
2643 if (DECL_NAME (function))
2644 function = DECL_NAME (function);
2645 else

--- 35 unchanged lines hidden (view full) ---

2681 if (basetype && (! current_class_type
2682 || ! DERIVED_FROM_P (basetype, current_class_type)))
2683 return build_member_call (basetype, function, params);
2684
2685 if (decl == NULL_TREE)
2686 {
2687 if (current_class_type == NULL_TREE)
2688 {
2522 error ("object missing in call to method `%s'",
2523 IDENTIFIER_POINTER (function));
2689 cp_error ("object missing in call to method `%D'", function);
2524 return error_mark_node;
2525 }
2526 /* Yow: call from a static member function. */
2690 return error_mark_node;
2691 }
2692 /* Yow: call from a static member function. */
2527 decl = build1 (NOP_EXPR, build_pointer_type (current_class_type),
2528 error_mark_node);
2529 decl = build_indirect_ref (decl, NULL_PTR);
2693 decl = build_dummy_object (current_class_type);
2530 }
2531
2532 /* Put back explicit template arguments, if any. */
2533 if (template_id)
2534 function = template_id;
2535 return build_method_call (decl, function, params,
2536 NULL_TREE, LOOKUP_NORMAL);
2537 }
2538 else if (TREE_CODE (function) == COMPONENT_REF
2539 && type == unknown_type_node)
2540 {
2694 }
2695
2696 /* Put back explicit template arguments, if any. */
2697 if (template_id)
2698 function = template_id;
2699 return build_method_call (decl, function, params,
2700 NULL_TREE, LOOKUP_NORMAL);
2701 }
2702 else if (TREE_CODE (function) == COMPONENT_REF
2703 && type == unknown_type_node)
2704 {
2541 /* Should we undo what was done in build_component_ref? */
2542 if (TREE_CODE (TREE_PURPOSE (TREE_OPERAND (function, 1))) == TREE_VEC)
2543 /* Get the name that build_component_ref hid. */
2544 function = DECL_NAME (TREE_VALUE (TREE_OPERAND (function, 1)));
2545 else
2546 function = TREE_PURPOSE (TREE_OPERAND (function, 1));
2705 /* Undo what we did in build_component_ref. */
2706 decl = TREE_OPERAND (function, 0);
2707 function = TREE_OPERAND (function, 1);
2708 function = DECL_NAME (OVL_CURRENT (function));
2709
2710 if (template_id)
2711 {
2712 TREE_OPERAND (template_id, 0) = function;
2713 function = template_id;
2714 }
2715
2547 return build_method_call (decl, function, params,
2548 NULL_TREE, LOOKUP_NORMAL);
2549 }
2550 else if (really_overloaded_fn (function))
2551 {
2552 if (OVL_FUNCTION (function) == NULL_TREE)
2553 {
2554 cp_error ("function `%D' declared overloaded, but no definitions appear with which to resolve it?!?",

--- 106 unchanged lines hidden (view full) ---

2661 if (TREE_CODE (function) == OFFSET_REF)
2662 {
2663 function = TREE_OPERAND (function, 1);
2664 }
2665
2666 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function)))
2667 {
2668 tree fntype, idx, e1, delta, delta2, e2, e3, aref, vtbl;
2716 return build_method_call (decl, function, params,
2717 NULL_TREE, LOOKUP_NORMAL);
2718 }
2719 else if (really_overloaded_fn (function))
2720 {
2721 if (OVL_FUNCTION (function) == NULL_TREE)
2722 {
2723 cp_error ("function `%D' declared overloaded, but no definitions appear with which to resolve it?!?",

--- 106 unchanged lines hidden (view full) ---

2830 if (TREE_CODE (function) == OFFSET_REF)
2831 {
2832 function = TREE_OPERAND (function, 1);
2833 }
2834
2835 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function)))
2836 {
2837 tree fntype, idx, e1, delta, delta2, e2, e3, aref, vtbl;
2669 tree instance;
2838 tree instance, basetype;
2670
2671 tree instance_ptr = *instance_ptrptr;
2672
2673 if (TREE_SIDE_EFFECTS (instance_ptr))
2674 instance_ptr = save_expr (instance_ptr);
2675
2676 if (TREE_SIDE_EFFECTS (function))
2677 function = save_expr (function);
2678
2679 fntype = TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (function));
2839
2840 tree instance_ptr = *instance_ptrptr;
2841
2842 if (TREE_SIDE_EFFECTS (instance_ptr))
2843 instance_ptr = save_expr (instance_ptr);
2844
2845 if (TREE_SIDE_EFFECTS (function))
2846 function = save_expr (function);
2847
2848 fntype = TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (function));
2849 basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (fntype));
2680
2850
2681 /* Promoting idx before saving it improves performance on RISC
2682 targets. Without promoting, the first compare used
2683 load-with-sign-extend, while the second used normal load then
2684 shift to sign-extend. An optimizer flaw, perhaps, but it's easier
2685 to make this change. */
2686 idx = save_expr (default_conversion
2687 (build_component_ref (function,
2688 index_identifier,
2689 NULL_TREE, 0)));
2690 e1 = build_binary_op (GT_EXPR, idx, integer_zero_node, 1);
2691 delta = cp_convert (ptrdiff_type_node,
2692 build_component_ref (function, delta_identifier,
2693 NULL_TREE, 0));
2851 delta = cp_convert (ptrdiff_type_node,
2852 build_component_ref (function, delta_identifier,
2853 NULL_TREE, 0));
2694 delta2 = DELTA2_FROM_PTRMEMFUNC (function);
2854 e3 = PFN_FROM_PTRMEMFUNC (function);
2695
2855
2696 /* Convert down to the right base, before using the instance. */
2697 instance
2698 = convert_pointer_to_real (TYPE_METHOD_BASETYPE (TREE_TYPE (fntype)),
2699 instance_ptr);
2700 if (instance == error_mark_node && instance_ptr != error_mark_node)
2701 return instance;
2702
2703 vtbl = convert_pointer_to (ptr_type_node, instance);
2704 vtbl
2705 = build (PLUS_EXPR,
2706 build_pointer_type (build_pointer_type (vtable_entry_type)),
2707 vtbl, cp_convert (ptrdiff_type_node, delta2));
2708 vtbl = build_indirect_ref (vtbl, NULL_PTR);
2709 aref = build_array_ref (vtbl, build_binary_op (MINUS_EXPR,
2710 idx,
2711 integer_one_node, 1));
2712 if (! flag_vtable_thunks)
2856 if (TYPE_SIZE (basetype) != NULL_TREE
2857 && ! TYPE_VIRTUAL_P (basetype))
2858 /* If basetype doesn't have virtual functions, don't emit code to
2859 handle that case. */
2860 e1 = e3;
2861 else
2713 {
2862 {
2714 aref = save_expr (aref);
2863 /* Promoting idx before saving it improves performance on RISC
2864 targets. Without promoting, the first compare used
2865 load-with-sign-extend, while the second used normal load then
2866 shift to sign-extend. An optimizer flaw, perhaps, but it's
2867 easier to make this change. */
2868 idx = save_expr (default_conversion
2869 (build_component_ref (function,
2870 index_identifier,
2871 NULL_TREE, 0)));
2872 e1 = build_binary_op (GE_EXPR, idx, integer_zero_node);
2715
2873
2716 delta = build_binary_op
2874 /* Convert down to the right base, before using the instance. */
2875 instance = convert_pointer_to_real (basetype, instance_ptr);
2876 if (instance == error_mark_node && instance_ptr != error_mark_node)
2877 return instance;
2878
2879 vtbl = convert_pointer_to (ptr_type_node, instance);
2880 delta2 = DELTA2_FROM_PTRMEMFUNC (function);
2881 vtbl = build
2717 (PLUS_EXPR,
2882 (PLUS_EXPR,
2718 build_conditional_expr (e1, build_component_ref (aref,
2883 build_pointer_type (build_pointer_type (vtable_entry_type)),
2884 vtbl, cp_convert (ptrdiff_type_node, delta2));
2885 vtbl = build_indirect_ref (vtbl, NULL_PTR);
2886 aref = build_array_ref (vtbl, build_binary_op (MINUS_EXPR,
2887 idx,
2888 integer_one_node));
2889 if (! flag_vtable_thunks)
2890 {
2891 aref = save_expr (aref);
2892
2893 delta = build_binary_op
2894 (PLUS_EXPR,
2895 build_conditional_expr (e1,
2896 build_component_ref (aref,
2719 delta_identifier,
2720 NULL_TREE, 0),
2897 delta_identifier,
2898 NULL_TREE, 0),
2721 integer_zero_node),
2722 delta, 1);
2899 integer_zero_node),
2900 delta);
2901 }
2902
2903 if (flag_vtable_thunks)
2904 e2 = aref;
2905 else
2906 e2 = build_component_ref (aref, pfn_identifier, NULL_TREE, 0);
2907 TREE_TYPE (e2) = TREE_TYPE (e3);
2908 e1 = build_conditional_expr (e1, e2, e3);
2909
2910 /* Make sure this doesn't get evaluated first inside one of the
2911 branches of the COND_EXPR. */
2912 if (TREE_CODE (instance_ptr) == SAVE_EXPR)
2913 e1 = build (COMPOUND_EXPR, TREE_TYPE (e1),
2914 instance_ptr, e1);
2723 }
2724
2725 *instance_ptrptr = build (PLUS_EXPR, TREE_TYPE (instance_ptr),
2726 instance_ptr, delta);
2915 }
2916
2917 *instance_ptrptr = build (PLUS_EXPR, TREE_TYPE (instance_ptr),
2918 instance_ptr, delta);
2727 if (flag_vtable_thunks)
2728 e2 = aref;
2729 else
2730 e2 = build_component_ref (aref, pfn_identifier, NULL_TREE, 0);
2731
2919
2732 e3 = PFN_FROM_PTRMEMFUNC (function);
2733 TREE_TYPE (e2) = TREE_TYPE (e3);
2734 e1 = build_conditional_expr (e1, e2, e3);
2735
2736 if (instance_ptr == error_mark_node
2737 && TREE_CODE (e1) != ADDR_EXPR
2738 && TREE_CODE (TREE_OPERAND (e1, 0)) != FUNCTION_DECL)
2739 cp_error ("object missing in `%E'", function);
2740
2741 function = e1;
2920 if (instance_ptr == error_mark_node
2921 && TREE_CODE (e1) != ADDR_EXPR
2922 && TREE_CODE (TREE_OPERAND (e1, 0)) != FUNCTION_DECL)
2923 cp_error ("object missing in `%E'", function);
2924
2925 function = e1;
2742
2743 /* Make sure this doesn't get evaluated first inside one of the
2744 branches of the COND_EXPR. */
2745 if (TREE_CODE (instance_ptr) == SAVE_EXPR)
2746 function = build (COMPOUND_EXPR, TREE_TYPE (function),
2747 instance_ptr, function);
2748 }
2749 return function;
2750}
2751
2752tree
2753build_function_call_real (function, params, require_complete, flags)
2754 tree function, params;
2755 int require_complete, flags;

--- 68 unchanged lines hidden (view full) ---

2824
2825 /* fntype now gets the type of function pointed to. */
2826 fntype = TREE_TYPE (fntype);
2827
2828 /* Convert the parameters to the types declared in the
2829 function prototype, or apply default promotions. */
2830
2831 if (flags & LOOKUP_COMPLAIN)
2926 }
2927 return function;
2928}
2929
2930tree
2931build_function_call_real (function, params, require_complete, flags)
2932 tree function, params;
2933 int require_complete, flags;

--- 68 unchanged lines hidden (view full) ---

3002
3003 /* fntype now gets the type of function pointed to. */
3004 fntype = TREE_TYPE (fntype);
3005
3006 /* Convert the parameters to the types declared in the
3007 function prototype, or apply default promotions. */
3008
3009 if (flags & LOOKUP_COMPLAIN)
2832 coerced_params = convert_arguments (NULL_TREE, TYPE_ARG_TYPES (fntype),
3010 coerced_params = convert_arguments (TYPE_ARG_TYPES (fntype),
2833 params, fndecl, LOOKUP_NORMAL);
2834 else
3011 params, fndecl, LOOKUP_NORMAL);
3012 else
2835 coerced_params = convert_arguments (NULL_TREE, TYPE_ARG_TYPES (fntype),
3013 coerced_params = convert_arguments (TYPE_ARG_TYPES (fntype),
2836 params, fndecl, 0);
2837
2838 if (coerced_params == error_mark_node)
2839 {
2840 if (flags & LOOKUP_SPECULATIVELY)
2841 return NULL_TREE;
2842 else
2843 return error_mark_node;

--- 27 unchanged lines hidden (view full) ---

2871 /* C++ */
2872 value_type = TREE_TYPE (fntype) ? TREE_TYPE (fntype) : void_type_node;
2873 {
2874 register tree result
2875 = build_call (function, value_type, coerced_params);
2876
2877 if (require_complete)
2878 {
3014 params, fndecl, 0);
3015
3016 if (coerced_params == error_mark_node)
3017 {
3018 if (flags & LOOKUP_SPECULATIVELY)
3019 return NULL_TREE;
3020 else
3021 return error_mark_node;

--- 27 unchanged lines hidden (view full) ---

3049 /* C++ */
3050 value_type = TREE_TYPE (fntype) ? TREE_TYPE (fntype) : void_type_node;
3051 {
3052 register tree result
3053 = build_call (function, value_type, coerced_params);
3054
3055 if (require_complete)
3056 {
2879 if (value_type == void_type_node)
3057 if (TREE_CODE (value_type) == VOID_TYPE)
2880 return result;
2881 result = require_complete_type (result);
2882 }
2883 if (IS_AGGR_TYPE (value_type))
2884 result = build_cplus_new (value_type, result);
2885 return convert_from_reference (result);
2886 }
2887}

--- 5 unchanged lines hidden (view full) ---

2893 return build_function_call_real (function, params, 1, LOOKUP_NORMAL);
2894}
2895
2896/* Convert the actual parameter expressions in the list VALUES
2897 to the types in the list TYPELIST.
2898 If parmdecls is exhausted, or when an element has NULL as its type,
2899 perform the default conversions.
2900
3058 return result;
3059 result = require_complete_type (result);
3060 }
3061 if (IS_AGGR_TYPE (value_type))
3062 result = build_cplus_new (value_type, result);
3063 return convert_from_reference (result);
3064 }
3065}

--- 5 unchanged lines hidden (view full) ---

3071 return build_function_call_real (function, params, 1, LOOKUP_NORMAL);
3072}
3073
3074/* Convert the actual parameter expressions in the list VALUES
3075 to the types in the list TYPELIST.
3076 If parmdecls is exhausted, or when an element has NULL as its type,
3077 perform the default conversions.
3078
2901 RETURN_LOC is the location of the return value, if known, NULL_TREE
2902 otherwise. This is useful in the case where we can avoid creating
2903 a temporary variable in the case where we can initialize the return
2904 value directly. If we are not eliding constructors, then we set this
2905 to NULL_TREE to avoid this avoidance.
2906
2907 NAME is an IDENTIFIER_NODE or 0. It is used only for error messages.
2908
2909 This is also where warnings about wrong number of args are generated.
2910
2911 Return a list of expressions for the parameters as converted.
2912
2913 Both VALUES and the returned value are chains of TREE_LIST nodes
2914 with the elements of the list in the TREE_VALUE slots of those nodes.
2915
2916 In C++, unspecified trailing parameters can be filled in with their
2917 default arguments, if such were specified. Do so here. */
2918
2919tree
3079 NAME is an IDENTIFIER_NODE or 0. It is used only for error messages.
3080
3081 This is also where warnings about wrong number of args are generated.
3082
3083 Return a list of expressions for the parameters as converted.
3084
3085 Both VALUES and the returned value are chains of TREE_LIST nodes
3086 with the elements of the list in the TREE_VALUE slots of those nodes.
3087
3088 In C++, unspecified trailing parameters can be filled in with their
3089 default arguments, if such were specified. Do so here. */
3090
3091tree
2920convert_arguments (return_loc, typelist, values, fndecl, flags)
2921 tree return_loc, typelist, values, fndecl;
3092convert_arguments (typelist, values, fndecl, flags)
3093 tree typelist, values, fndecl;
2922 int flags;
2923{
2924 register tree typetail, valtail;
2925 register tree result = NULL_TREE;
3094 int flags;
3095{
3096 register tree typetail, valtail;
3097 register tree result = NULL_TREE;
2926 char *called_thing = 0;
3098 const char *called_thing = 0;
2927 int i = 0;
2928
3099 int i = 0;
3100
2929 if (! flag_elide_constructors)
2930 return_loc = 0;
2931
2932 /* Argument passing is always copy-initialization. */
2933 flags |= LOOKUP_ONLYCONVERTING;
2934
2935 if (fndecl)
2936 {
2937 if (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE)
2938 {
2939 if (DECL_NAME (fndecl) == NULL_TREE

--- 15 unchanged lines hidden (view full) ---

2955
2956 if (val == error_mark_node)
2957 return error_mark_node;
2958
2959 if (type == void_type_node)
2960 {
2961 if (fndecl)
2962 {
3101 /* Argument passing is always copy-initialization. */
3102 flags |= LOOKUP_ONLYCONVERTING;
3103
3104 if (fndecl)
3105 {
3106 if (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE)
3107 {
3108 if (DECL_NAME (fndecl) == NULL_TREE

--- 15 unchanged lines hidden (view full) ---

3124
3125 if (val == error_mark_node)
3126 return error_mark_node;
3127
3128 if (type == void_type_node)
3129 {
3130 if (fndecl)
3131 {
2963 cp_error_at ("too many arguments to %s `%+D'", called_thing,
3132 cp_error_at ("too many arguments to %s `%+#D'", called_thing,
2964 fndecl);
2965 error ("at this point in file");
2966 }
2967 else
2968 error ("too many arguments to function");
2969 /* In case anybody wants to know if this argument
2970 list is valid. */
2971 if (result)
2972 TREE_TYPE (tree_last (result)) = error_mark_node;
2973 break;
2974 }
2975
3133 fndecl);
3134 error ("at this point in file");
3135 }
3136 else
3137 error ("too many arguments to function");
3138 /* In case anybody wants to know if this argument
3139 list is valid. */
3140 if (result)
3141 TREE_TYPE (tree_last (result)) = error_mark_node;
3142 break;
3143 }
3144
2976 /* The tree type of the parameter being passed may not yet be
2977 known. In this case, its type is TYPE_UNKNOWN, and will
2978 be instantiated by the type given by TYPE. If TYPE
2979 is also NULL, the tree type of VAL is ERROR_MARK_NODE. */
2980 if (type && type_unknown_p (val))
2981 val = require_instantiated_type (type, val, integer_zero_node);
2982 else if (type_unknown_p (val))
2983 {
2984 /* Strip the `&' from an overloaded FUNCTION_DECL. */
2985 if (TREE_CODE (val) == ADDR_EXPR)
2986 val = TREE_OPERAND (val, 0);
2987 if (really_overloaded_fn (val))
2988 cp_error ("insufficient type information to resolve address of overloaded function `%D'",
2989 DECL_NAME (get_first_fn (val)));
2990 else
2991 error ("insufficient type information in parameter list");
2992 val = integer_zero_node;
2993 }
2994 else if (TREE_CODE (val) == OFFSET_REF
2995 && TREE_CODE (TREE_TYPE (val)) == METHOD_TYPE)
2996 {
2997 /* This is unclean. Should be handled elsewhere. */
2998 val = build_unary_op (ADDR_EXPR, val, 0);
2999 }
3000 else if (TREE_CODE (val) == OFFSET_REF)
3145 if (TREE_CODE (val) == OFFSET_REF)
3001 val = resolve_offset_ref (val);
3002
3003 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
3004 Strip such NOP_EXPRs, since VAL is used in non-lvalue context. */
3005 if (TREE_CODE (val) == NOP_EXPR
3006 && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0))
3007 && (type == 0 || TREE_CODE (type) != REFERENCE_TYPE))
3008 val = TREE_OPERAND (val, 0);
3009
3010 if (type == 0 || TREE_CODE (type) != REFERENCE_TYPE)
3011 {
3012 if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE
3013 || TREE_CODE (TREE_TYPE (val)) == FUNCTION_TYPE
3014 || TREE_CODE (TREE_TYPE (val)) == METHOD_TYPE)
3015 val = default_conversion (val);
3146 val = resolve_offset_ref (val);
3147
3148 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
3149 Strip such NOP_EXPRs, since VAL is used in non-lvalue context. */
3150 if (TREE_CODE (val) == NOP_EXPR
3151 && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0))
3152 && (type == 0 || TREE_CODE (type) != REFERENCE_TYPE))
3153 val = TREE_OPERAND (val, 0);
3154
3155 if (type == 0 || TREE_CODE (type) != REFERENCE_TYPE)
3156 {
3157 if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE
3158 || TREE_CODE (TREE_TYPE (val)) == FUNCTION_TYPE
3159 || TREE_CODE (TREE_TYPE (val)) == METHOD_TYPE)
3160 val = default_conversion (val);
3016
3017 val = require_complete_type (val);
3018 }
3019
3020 if (val == error_mark_node)
3021 return error_mark_node;
3022
3023 if (type != 0)
3024 {
3025 /* Formal parm type is specified by a function prototype. */
3026 tree parmval;
3027
3028 if (TYPE_SIZE (complete_type (type)) == 0)
3029 {
3030 error ("parameter type of called function is incomplete");
3031 parmval = val;
3032 }
3033 else
3034 {
3035 parmval = convert_for_initialization
3161 }
3162
3163 if (val == error_mark_node)
3164 return error_mark_node;
3165
3166 if (type != 0)
3167 {
3168 /* Formal parm type is specified by a function prototype. */
3169 tree parmval;
3170
3171 if (TYPE_SIZE (complete_type (type)) == 0)
3172 {
3173 error ("parameter type of called function is incomplete");
3174 parmval = val;
3175 }
3176 else
3177 {
3178 parmval = convert_for_initialization
3036 (return_loc, type, val, flags,
3179 (NULL_TREE, type, val, flags,
3037 "argument passing", fndecl, i);
3038#ifdef PROMOTE_PROTOTYPES
3039 if ((TREE_CODE (type) == INTEGER_TYPE
3040 || TREE_CODE (type) == ENUMERAL_TYPE)
3041 && (TYPE_PRECISION (type)
3042 < TYPE_PRECISION (integer_type_node)))
3043 parmval = default_conversion (parmval);
3044#endif

--- 20 unchanged lines hidden (view full) ---

3065
3066 if (typetail != 0 && typetail != void_list_node)
3067 {
3068 /* See if there are default arguments that can be used */
3069 if (TREE_PURPOSE (typetail))
3070 {
3071 for (; typetail != void_list_node; ++i)
3072 {
3180 "argument passing", fndecl, i);
3181#ifdef PROMOTE_PROTOTYPES
3182 if ((TREE_CODE (type) == INTEGER_TYPE
3183 || TREE_CODE (type) == ENUMERAL_TYPE)
3184 && (TYPE_PRECISION (type)
3185 < TYPE_PRECISION (integer_type_node)))
3186 parmval = default_conversion (parmval);
3187#endif

--- 20 unchanged lines hidden (view full) ---

3208
3209 if (typetail != 0 && typetail != void_list_node)
3210 {
3211 /* See if there are default arguments that can be used */
3212 if (TREE_PURPOSE (typetail))
3213 {
3214 for (; typetail != void_list_node; ++i)
3215 {
3073 tree type = TREE_VALUE (typetail);
3074 tree val = TREE_PURPOSE (typetail);
3075 tree parmval = convert_default_arg (type, val);
3216 tree parmval
3217 = convert_default_arg (TREE_VALUE (typetail),
3218 TREE_PURPOSE (typetail),
3219 fndecl);
3076
3077 if (parmval == error_mark_node)
3078 return error_mark_node;
3079
3080 result = expr_tree_cons (0, parmval, result);
3081 typetail = TREE_CHAIN (typetail);
3082 /* ends with `...'. */
3083 if (typetail == NULL_TREE)
3084 break;
3085 }
3086 }
3087 else
3088 {
3089 if (fndecl)
3090 {
3220
3221 if (parmval == error_mark_node)
3222 return error_mark_node;
3223
3224 result = expr_tree_cons (0, parmval, result);
3225 typetail = TREE_CHAIN (typetail);
3226 /* ends with `...'. */
3227 if (typetail == NULL_TREE)
3228 break;
3229 }
3230 }
3231 else
3232 {
3233 if (fndecl)
3234 {
3091 char *buf = (char *)alloca (32 + strlen (called_thing));
3092 sprintf (buf, "too few arguments to %s `%%#D'", called_thing);
3093 cp_error_at (buf, fndecl);
3235 cp_error_at ("too few arguments to %s `%+#D'",
3236 called_thing, fndecl);
3094 error ("at this point in file");
3095 }
3096 else
3097 error ("too few arguments to function");
3098 return error_mark_list;
3099 }
3100 }
3101

--- 10 unchanged lines hidden (view full) ---

3112{
3113 if (processing_template_decl)
3114 return build_min_nt (code, arg1, arg2);
3115
3116 return build_new_op (code, LOOKUP_NORMAL, arg1, arg2, NULL_TREE);
3117}
3118
3119tree
3237 error ("at this point in file");
3238 }
3239 else
3240 error ("too few arguments to function");
3241 return error_mark_list;
3242 }
3243 }
3244

--- 10 unchanged lines hidden (view full) ---

3255{
3256 if (processing_template_decl)
3257 return build_min_nt (code, arg1, arg2);
3258
3259 return build_new_op (code, LOOKUP_NORMAL, arg1, arg2, NULL_TREE);
3260}
3261
3262tree
3120build_binary_op (code, arg1, arg2, convert_p)
3263build_binary_op (code, arg1, arg2)
3121 enum tree_code code;
3122 tree arg1, arg2;
3264 enum tree_code code;
3265 tree arg1, arg2;
3123 int convert_p;
3124{
3266{
3125 tree args[2];
3126
3127 args[0] = arg1;
3128 args[1] = arg2;
3129
3130 if (convert_p)
3131 {
3132 tree type0, type1;
3133 args[0] = decay_conversion (args[0]);
3134 args[1] = decay_conversion (args[1]);
3135
3136 if (args[0] == error_mark_node || args[1] == error_mark_node)
3137 return error_mark_node;
3138
3139 type0 = TREE_TYPE (args[0]);
3140 type1 = TREE_TYPE (args[1]);
3141
3142 if (type_unknown_p (args[0]))
3143 {
3144 args[0] = instantiate_type (type1, args[0], 1);
3145 args[0] = decay_conversion (args[0]);
3146 }
3147 else if (type_unknown_p (args[1]))
3148 {
3149 args[1] = require_instantiated_type (type0, args[1],
3150 error_mark_node);
3151 args[1] = decay_conversion (args[1]);
3152 }
3153
3154 if (IS_AGGR_TYPE (type0) || IS_AGGR_TYPE (type1))
3155 my_friendly_abort (754867);
3156 }
3157 return build_binary_op_nodefault (code, args[0], args[1], code);
3267 return build_binary_op_nodefault (code, arg1, arg2, code);
3158}
3159
3160/* Build a binary-operation expression without default conversions.
3161 CODE is the kind of expression to build.
3162 This function differs from `build' in several ways:
3163 the data type of the result is computed and recorded in it,
3164 warnings are generated if arg data types are invalid,
3165 special handling for addition and subtraction of pointers is known,

--- 73 unchanged lines hidden (view full) ---

3239 op1 = decay_conversion (orig_op1);
3240 }
3241 else
3242 {
3243 op0 = default_conversion (orig_op0);
3244 op1 = default_conversion (orig_op1);
3245 }
3246
3268}
3269
3270/* Build a binary-operation expression without default conversions.
3271 CODE is the kind of expression to build.
3272 This function differs from `build' in several ways:
3273 the data type of the result is computed and recorded in it,
3274 warnings are generated if arg data types are invalid,
3275 special handling for addition and subtraction of pointers is known,

--- 73 unchanged lines hidden (view full) ---

3349 op1 = decay_conversion (orig_op1);
3350 }
3351 else
3352 {
3353 op0 = default_conversion (orig_op0);
3354 op1 = default_conversion (orig_op1);
3355 }
3356
3357 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
3358 STRIP_TYPE_NOPS (op0);
3359 STRIP_TYPE_NOPS (op1);
3360
3361 /* DTRT if one side is an overloaded function, but complain about it. */
3362 if (type_unknown_p (op0))
3363 {
3364 tree t = instantiate_type (TREE_TYPE (op1), op0, 0);
3365 if (t != error_mark_node)
3366 {
3367 cp_pedwarn ("assuming cast to `%T' from overloaded function",
3368 TREE_TYPE (t));
3369 op0 = t;
3370 }
3371 }
3372 if (type_unknown_p (op1))
3373 {
3374 tree t = instantiate_type (TREE_TYPE (op0), op1, 0);
3375 if (t != error_mark_node)
3376 {
3377 cp_pedwarn ("assuming cast to `%T' from overloaded function",
3378 TREE_TYPE (t));
3379 op1 = t;
3380 }
3381 }
3382
3247 type0 = TREE_TYPE (op0);
3248 type1 = TREE_TYPE (op1);
3249
3250 /* The expression codes of the data types of the arguments tell us
3251 whether the arguments are integers, floating, pointers, etc. */
3252 code0 = TREE_CODE (type0);
3253 code1 = TREE_CODE (type1);
3254
3383 type0 = TREE_TYPE (op0);
3384 type1 = TREE_TYPE (op1);
3385
3386 /* The expression codes of the data types of the arguments tell us
3387 whether the arguments are integers, floating, pointers, etc. */
3388 code0 = TREE_CODE (type0);
3389 code1 = TREE_CODE (type1);
3390
3255 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
3256 STRIP_TYPE_NOPS (op0);
3257 STRIP_TYPE_NOPS (op1);
3258
3259 /* If an error was already reported for one of the arguments,
3260 avoid reporting another error. */
3261
3262 if (code0 == ERROR_MARK || code1 == ERROR_MARK)
3263 return error_mark_node;
3264
3265 switch (code)
3266 {

--- 256 unchanged lines hidden (view full) ---

3523 else if (TYPE_PTRMEMFUNC_P (type1) && TREE_CODE (op0) == INTEGER_CST
3524 && integer_zerop (op0))
3525 {
3526 op0 = build_component_ref (op1, index_identifier, NULL_TREE, 0);
3527 op1 = integer_zero_node;
3528 result_type = TREE_TYPE (op0);
3529 }
3530 else if (TYPE_PTRMEMFUNC_P (type0) && TYPE_PTRMEMFUNC_P (type1)
3391 /* If an error was already reported for one of the arguments,
3392 avoid reporting another error. */
3393
3394 if (code0 == ERROR_MARK || code1 == ERROR_MARK)
3395 return error_mark_node;
3396
3397 switch (code)
3398 {

--- 256 unchanged lines hidden (view full) ---

3655 else if (TYPE_PTRMEMFUNC_P (type1) && TREE_CODE (op0) == INTEGER_CST
3656 && integer_zerop (op0))
3657 {
3658 op0 = build_component_ref (op1, index_identifier, NULL_TREE, 0);
3659 op1 = integer_zero_node;
3660 result_type = TREE_TYPE (op0);
3661 }
3662 else if (TYPE_PTRMEMFUNC_P (type0) && TYPE_PTRMEMFUNC_P (type1)
3531 && (TYPE_PTRMEMFUNC_FN_TYPE (type0)
3532 == TYPE_PTRMEMFUNC_FN_TYPE (type1)))
3663 && same_type_p (type0, type1))
3533 {
3534 /* The code we generate for the test is:
3535
3536 (op0.index == op1.index
3537 && ((op1.index != -1 && op0.delta2 == op1.delta2)
3538 || op0.pfn == op1.pfn)) */
3539
3540 tree index0 = build_component_ref (op0, index_identifier,
3541 NULL_TREE, 0);
3542 tree index1 = save_expr (build_component_ref (op1, index_identifier,
3543 NULL_TREE, 0));
3544 tree pfn0 = PFN_FROM_PTRMEMFUNC (op0);
3545 tree pfn1 = PFN_FROM_PTRMEMFUNC (op1);
3546 tree delta20 = DELTA2_FROM_PTRMEMFUNC (op0);
3547 tree delta21 = DELTA2_FROM_PTRMEMFUNC (op1);
3548 tree e1, e2, e3;
3549 tree integer_neg_one_node
3550 = build_binary_op (MINUS_EXPR, integer_zero_node,
3664 {
3665 /* The code we generate for the test is:
3666
3667 (op0.index == op1.index
3668 && ((op1.index != -1 && op0.delta2 == op1.delta2)
3669 || op0.pfn == op1.pfn)) */
3670
3671 tree index0 = build_component_ref (op0, index_identifier,
3672 NULL_TREE, 0);
3673 tree index1 = save_expr (build_component_ref (op1, index_identifier,
3674 NULL_TREE, 0));
3675 tree pfn0 = PFN_FROM_PTRMEMFUNC (op0);
3676 tree pfn1 = PFN_FROM_PTRMEMFUNC (op1);
3677 tree delta20 = DELTA2_FROM_PTRMEMFUNC (op0);
3678 tree delta21 = DELTA2_FROM_PTRMEMFUNC (op1);
3679 tree e1, e2, e3;
3680 tree integer_neg_one_node
3681 = build_binary_op (MINUS_EXPR, integer_zero_node,
3551 integer_one_node, 1);
3552 e1 = build_binary_op (EQ_EXPR, index0, index1, 1);
3553 e2 = build_binary_op (NE_EXPR, index1, integer_neg_one_node, 1);
3682 integer_one_node);
3683 e1 = build_binary_op (EQ_EXPR, index0, index1);
3684 e2 = build_binary_op (NE_EXPR, index1, integer_neg_one_node);
3554 e2 = build_binary_op (TRUTH_ANDIF_EXPR, e2,
3685 e2 = build_binary_op (TRUTH_ANDIF_EXPR, e2,
3555 build_binary_op (EQ_EXPR, delta20, delta21, 1),
3556 1);
3557 e3 = build_binary_op (EQ_EXPR, pfn0, pfn1, 1);
3558 e2 = build_binary_op (TRUTH_ORIF_EXPR, e2, e3, 1);
3559 e2 = build_binary_op (TRUTH_ANDIF_EXPR, e1, e2, 1);
3686 build_binary_op (EQ_EXPR, delta20, delta21));
3687 /* We can't use build_binary_op for this cmp because it would get
3688 confused by the ptr to method types and think we want pmfs. */
3689 e3 = build (EQ_EXPR, boolean_type_node, pfn0, pfn1);
3690 e2 = build_binary_op (TRUTH_ORIF_EXPR, e2, e3);
3691 e2 = build_binary_op (TRUTH_ANDIF_EXPR, e1, e2);
3560 if (code == EQ_EXPR)
3561 return e2;
3692 if (code == EQ_EXPR)
3693 return e2;
3562 return build_binary_op (EQ_EXPR, e2, integer_zero_node, 1);
3694 return build_binary_op (EQ_EXPR, e2, integer_zero_node);
3563 }
3564 else if (TYPE_PTRMEMFUNC_P (type0)
3695 }
3696 else if (TYPE_PTRMEMFUNC_P (type0)
3565 && TYPE_PTRMEMFUNC_FN_TYPE (type0) == type1)
3697 && same_type_p (TYPE_PTRMEMFUNC_FN_TYPE (type0), type1))
3566 {
3567 tree index0 = build_component_ref (op0, index_identifier,
3568 NULL_TREE, 0);
3569 tree index1;
3570 tree pfn0 = PFN_FROM_PTRMEMFUNC (op0);
3571 tree delta20 = DELTA2_FROM_PTRMEMFUNC (op0);
3572 tree delta21 = integer_zero_node;
3573 tree e1, e2, e3;
3574 tree integer_neg_one_node
3698 {
3699 tree index0 = build_component_ref (op0, index_identifier,
3700 NULL_TREE, 0);
3701 tree index1;
3702 tree pfn0 = PFN_FROM_PTRMEMFUNC (op0);
3703 tree delta20 = DELTA2_FROM_PTRMEMFUNC (op0);
3704 tree delta21 = integer_zero_node;
3705 tree e1, e2, e3;
3706 tree integer_neg_one_node
3575 = build_binary_op (MINUS_EXPR, integer_zero_node, integer_one_node, 1);
3707 = build_binary_op (MINUS_EXPR, integer_zero_node, integer_one_node);
3576 if (TREE_CODE (TREE_OPERAND (op1, 0)) == FUNCTION_DECL
3577 && DECL_VINDEX (TREE_OPERAND (op1, 0)))
3578 {
3579 /* Map everything down one to make room for
3580 the null pointer to member. */
3581 index1 = size_binop (PLUS_EXPR,
3582 DECL_VINDEX (TREE_OPERAND (op1, 0)),
3583 integer_one_node);

--- 8 unchanged lines hidden (view full) ---

3592 else
3593 index1 = integer_neg_one_node;
3594 {
3595 tree nop1 = build1 (NOP_EXPR, TYPE_PTRMEMFUNC_FN_TYPE (type0),
3596 op1);
3597 TREE_CONSTANT (nop1) = TREE_CONSTANT (op1);
3598 op1 = nop1;
3599 }
3708 if (TREE_CODE (TREE_OPERAND (op1, 0)) == FUNCTION_DECL
3709 && DECL_VINDEX (TREE_OPERAND (op1, 0)))
3710 {
3711 /* Map everything down one to make room for
3712 the null pointer to member. */
3713 index1 = size_binop (PLUS_EXPR,
3714 DECL_VINDEX (TREE_OPERAND (op1, 0)),
3715 integer_one_node);

--- 8 unchanged lines hidden (view full) ---

3724 else
3725 index1 = integer_neg_one_node;
3726 {
3727 tree nop1 = build1 (NOP_EXPR, TYPE_PTRMEMFUNC_FN_TYPE (type0),
3728 op1);
3729 TREE_CONSTANT (nop1) = TREE_CONSTANT (op1);
3730 op1 = nop1;
3731 }
3600 e1 = build_binary_op (EQ_EXPR, index0, index1, 1);
3601 e2 = build_binary_op (NE_EXPR, index1, integer_neg_one_node, 1);
3732 e1 = build_binary_op (EQ_EXPR, index0, index1);
3733 e2 = build_binary_op (NE_EXPR, index1, integer_neg_one_node);
3602 e2 = build_binary_op (TRUTH_ANDIF_EXPR, e2,
3734 e2 = build_binary_op (TRUTH_ANDIF_EXPR, e2,
3603 build_binary_op (EQ_EXPR, delta20, delta21, 1),
3604 1);
3605 e3 = build_binary_op (EQ_EXPR, pfn0, op1, 1);
3606 e2 = build_binary_op (TRUTH_ORIF_EXPR, e2, e3, 1);
3607 e2 = build_binary_op (TRUTH_ANDIF_EXPR, e1, e2, 1);
3735 build_binary_op (EQ_EXPR, delta20, delta21));
3736 /* We can't use build_binary_op for this cmp because it would get
3737 confused by the ptr to method types and think we want pmfs. */
3738 e3 = build (EQ_EXPR, boolean_type_node, pfn0, op1);
3739 e2 = build_binary_op (TRUTH_ORIF_EXPR, e2, e3);
3740 e2 = build_binary_op (TRUTH_ANDIF_EXPR, e1, e2);
3608 if (code == EQ_EXPR)
3609 return e2;
3741 if (code == EQ_EXPR)
3742 return e2;
3610 return build_binary_op (EQ_EXPR, e2, integer_zero_node, 1);
3743 return build_binary_op (EQ_EXPR, e2, integer_zero_node);
3611 }
3612 else if (TYPE_PTRMEMFUNC_P (type1)
3744 }
3745 else if (TYPE_PTRMEMFUNC_P (type1)
3613 && TYPE_PTRMEMFUNC_FN_TYPE (type1) == type0)
3614 {
3615 return build_binary_op (code, op1, op0, 1);
3616 }
3746 && same_type_p (TYPE_PTRMEMFUNC_FN_TYPE (type1), type0))
3747 return build_binary_op (code, op1, op0);
3617 break;
3618
3619 case MAX_EXPR:
3620 case MIN_EXPR:
3621 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
3622 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
3623 shorten = 1;
3624 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)

--- 196 unchanged lines hidden (view full) ---

3821 int op0_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op0));
3822 int op1_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op1));
3823
3824 int unsignedp0, unsignedp1;
3825 tree primop0 = get_narrower (op0, &unsignedp0);
3826 tree primop1 = get_narrower (op1, &unsignedp1);
3827
3828 /* Check for comparison of different enum types. */
3748 break;
3749
3750 case MAX_EXPR:
3751 case MIN_EXPR:
3752 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
3753 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
3754 shorten = 1;
3755 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)

--- 196 unchanged lines hidden (view full) ---

3952 int op0_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op0));
3953 int op1_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op1));
3954
3955 int unsignedp0, unsignedp1;
3956 tree primop0 = get_narrower (op0, &unsignedp0);
3957 tree primop1 = get_narrower (op1, &unsignedp1);
3958
3959 /* Check for comparison of different enum types. */
3829 if (flag_int_enum_equivalence == 0
3830 && TREE_CODE (TREE_TYPE (orig_op0)) == ENUMERAL_TYPE
3960 if (TREE_CODE (TREE_TYPE (orig_op0)) == ENUMERAL_TYPE
3831 && TREE_CODE (TREE_TYPE (orig_op1)) == ENUMERAL_TYPE
3832 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0))
3833 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1)))
3834 {
3835 cp_warning ("comparison between `%#T' and `%#T'",
3836 TREE_TYPE (orig_op0), TREE_TYPE (orig_op1));
3837 }
3838

--- 96 unchanged lines hidden (view full) ---

3935
3936 if (!result_type)
3937 {
3938 cp_error ("invalid operands `%T' and `%T' to binary `%O'",
3939 TREE_TYPE (orig_op0), TREE_TYPE (orig_op1), error_code);
3940 return error_mark_node;
3941 }
3942
3961 && TREE_CODE (TREE_TYPE (orig_op1)) == ENUMERAL_TYPE
3962 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0))
3963 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1)))
3964 {
3965 cp_warning ("comparison between `%#T' and `%#T'",
3966 TREE_TYPE (orig_op0), TREE_TYPE (orig_op1));
3967 }
3968

--- 96 unchanged lines hidden (view full) ---

4065
4066 if (!result_type)
4067 {
4068 cp_error ("invalid operands `%T' and `%T' to binary `%O'",
4069 TREE_TYPE (orig_op0), TREE_TYPE (orig_op1), error_code);
4070 return error_mark_node;
4071 }
4072
4073 /* Issue warnings about peculiar, but legal, uses of NULL. */
4074 if (/* It's reasonable to use pointer values as operands of &&
4075 and ||, so NULL is no exception. */
4076 !(code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR)
4077 && (/* If OP0 is NULL and OP1 is not a pointer, or vice versa. */
4078 (orig_op0 == null_node
4079 && TREE_CODE (TREE_TYPE (op1)) != POINTER_TYPE)
4080 /* Or vice versa. */
4081 || (orig_op1 == null_node
4082 && TREE_CODE (TREE_TYPE (op0)) != POINTER_TYPE)
4083 /* Or, both are NULL and the operation was not a comparison. */
4084 || (orig_op0 == null_node && orig_op1 == null_node
4085 && code != EQ_EXPR && code != NE_EXPR)))
4086 /* Some sort of arithmetic operation involving NULL was
4087 performed. Note that pointer-difference and pointer-addition
4088 have already been handled above, and so we don't end up here in
4089 that case. */
4090 cp_warning ("NULL used in arithmetic");
4091
3943 if (! converted)
3944 {
3945 if (TREE_TYPE (op0) != result_type)
3946 op0 = cp_convert (result_type, op0);
3947 if (TREE_TYPE (op1) != result_type)
3948 op1 = cp_convert (result_type, op1);
4092 if (! converted)
4093 {
4094 if (TREE_TYPE (op0) != result_type)
4095 op0 = cp_convert (result_type, op0);
4096 if (TREE_TYPE (op1) != result_type)
4097 op1 = cp_convert (result_type, op1);
4098
4099 if (op0 == error_mark_node || op1 == error_mark_node)
4100 return error_mark_node;
3949 }
3950
3951 if (build_type == NULL_TREE)
3952 build_type = result_type;
3953
3954 {
3955 register tree result = build (resultcode, build_type, op0, op1);
3956 register tree folded;

--- 19 unchanged lines hidden (view full) ---

3976
3977 register tree result;
3978 register tree folded = fold (intop);
3979
3980 /* The result is a pointer of the same type that is being added. */
3981
3982 register tree result_type = TREE_TYPE (ptrop);
3983
4101 }
4102
4103 if (build_type == NULL_TREE)
4104 build_type = result_type;
4105
4106 {
4107 register tree result = build (resultcode, build_type, op0, op1);
4108 register tree folded;

--- 19 unchanged lines hidden (view full) ---

4128
4129 register tree result;
4130 register tree folded = fold (intop);
4131
4132 /* The result is a pointer of the same type that is being added. */
4133
4134 register tree result_type = TREE_TYPE (ptrop);
4135
3984 if (!complete_type_or_else (result_type))
4136 if (!complete_type_or_else (result_type, ptrop))
3985 return error_mark_node;
3986
3987 if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE)
3988 {
3989 if (pedantic || warn_pointer_arith)
3990 pedwarn ("ANSI C++ forbids using pointer of type `void *' in arithmetic");
3991 size_exp = integer_one_node;
3992 }

--- 33 unchanged lines hidden (view full) ---

4026 if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
4027 && ! TREE_CONSTANT (intop)
4028 && TREE_CONSTANT (TREE_OPERAND (intop, 1))
4029 && TREE_CONSTANT (size_exp))
4030 {
4031 enum tree_code subcode = resultcode;
4032 if (TREE_CODE (intop) == MINUS_EXPR)
4033 subcode = (subcode == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR);
4137 return error_mark_node;
4138
4139 if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE)
4140 {
4141 if (pedantic || warn_pointer_arith)
4142 pedwarn ("ANSI C++ forbids using pointer of type `void *' in arithmetic");
4143 size_exp = integer_one_node;
4144 }

--- 33 unchanged lines hidden (view full) ---

4178 if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
4179 && ! TREE_CONSTANT (intop)
4180 && TREE_CONSTANT (TREE_OPERAND (intop, 1))
4181 && TREE_CONSTANT (size_exp))
4182 {
4183 enum tree_code subcode = resultcode;
4184 if (TREE_CODE (intop) == MINUS_EXPR)
4185 subcode = (subcode == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR);
4034 ptrop = build_binary_op (subcode, ptrop, TREE_OPERAND (intop, 1), 1);
4186 ptrop = build_binary_op (subcode, ptrop, TREE_OPERAND (intop, 1));
4035 intop = TREE_OPERAND (intop, 0);
4036 }
4037
4038 /* Convert the integer argument to a type the same size as sizetype
4039 so the multiply won't overflow spuriously. */
4040
4041 if (TYPE_PRECISION (TREE_TYPE (intop)) != TYPE_PRECISION (sizetype))
4042 intop = cp_convert (type_for_size (TYPE_PRECISION (sizetype), 0), intop);
4043
4044 /* Replace the integer argument with a suitable product by the object size.
4045 Do this multiplication as signed, then convert to the appropriate
4046 pointer type (actually unsigned integral). */
4047
4048 intop = cp_convert (result_type,
4049 build_binary_op (MULT_EXPR, intop,
4050 cp_convert (TREE_TYPE (intop),
4187 intop = TREE_OPERAND (intop, 0);
4188 }
4189
4190 /* Convert the integer argument to a type the same size as sizetype
4191 so the multiply won't overflow spuriously. */
4192
4193 if (TYPE_PRECISION (TREE_TYPE (intop)) != TYPE_PRECISION (sizetype))
4194 intop = cp_convert (type_for_size (TYPE_PRECISION (sizetype), 0), intop);
4195
4196 /* Replace the integer argument with a suitable product by the object size.
4197 Do this multiplication as signed, then convert to the appropriate
4198 pointer type (actually unsigned integral). */
4199
4200 intop = cp_convert (result_type,
4201 build_binary_op (MULT_EXPR, intop,
4202 cp_convert (TREE_TYPE (intop),
4051 size_exp),
4052 1));
4203 size_exp)));
4053
4054 /* Create the sum or difference. */
4055
4056 result = build (resultcode, result_type, ptrop, intop);
4057
4058 folded = fold (result);
4059 if (folded == result)
4060 TREE_CONSTANT (folded) = TREE_CONSTANT (ptrop) & TREE_CONSTANT (intop);

--- 7 unchanged lines hidden (view full) ---

4068pointer_diff (op0, op1, ptrtype)
4069 register tree op0, op1;
4070 register tree ptrtype;
4071{
4072 register tree result, folded;
4073 tree restype = ptrdiff_type_node;
4074 tree target_type = TREE_TYPE (ptrtype);
4075
4204
4205 /* Create the sum or difference. */
4206
4207 result = build (resultcode, result_type, ptrop, intop);
4208
4209 folded = fold (result);
4210 if (folded == result)
4211 TREE_CONSTANT (folded) = TREE_CONSTANT (ptrop) & TREE_CONSTANT (intop);

--- 7 unchanged lines hidden (view full) ---

4219pointer_diff (op0, op1, ptrtype)
4220 register tree op0, op1;
4221 register tree ptrtype;
4222{
4223 register tree result, folded;
4224 tree restype = ptrdiff_type_node;
4225 tree target_type = TREE_TYPE (ptrtype);
4226
4076 if (!complete_type_or_else (target_type))
4227 if (!complete_type_or_else (target_type, NULL_TREE))
4077 return error_mark_node;
4078
4079 if (pedantic || warn_pointer_arith)
4080 {
4081 if (TREE_CODE (target_type) == VOID_TYPE)
4082 pedwarn ("ANSI C++ forbids using pointer of type `void *' in subtraction");
4083 if (TREE_CODE (target_type) == FUNCTION_TYPE)
4084 pedwarn ("ANSI C++ forbids using pointer to a function in subtraction");
4085 if (TREE_CODE (target_type) == METHOD_TYPE)
4086 pedwarn ("ANSI C++ forbids using pointer to a method in subtraction");
4087 if (TREE_CODE (target_type) == OFFSET_TYPE)
4088 pedwarn ("ANSI C++ forbids using pointer to a member in subtraction");
4089 }
4090
4091 /* First do the subtraction as integers;
4092 then drop through to build the divide operator. */
4093
4094 op0 = build_binary_op (MINUS_EXPR, cp_convert (restype, op0),
4228 return error_mark_node;
4229
4230 if (pedantic || warn_pointer_arith)
4231 {
4232 if (TREE_CODE (target_type) == VOID_TYPE)
4233 pedwarn ("ANSI C++ forbids using pointer of type `void *' in subtraction");
4234 if (TREE_CODE (target_type) == FUNCTION_TYPE)
4235 pedwarn ("ANSI C++ forbids using pointer to a function in subtraction");
4236 if (TREE_CODE (target_type) == METHOD_TYPE)
4237 pedwarn ("ANSI C++ forbids using pointer to a method in subtraction");
4238 if (TREE_CODE (target_type) == OFFSET_TYPE)
4239 pedwarn ("ANSI C++ forbids using pointer to a member in subtraction");
4240 }
4241
4242 /* First do the subtraction as integers;
4243 then drop through to build the divide operator. */
4244
4245 op0 = build_binary_op (MINUS_EXPR, cp_convert (restype, op0),
4095 cp_convert (restype, op1), 1);
4246 cp_convert (restype, op1));
4096
4097 /* This generates an error if op1 is a pointer to an incomplete type. */
4098 if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1))) == 0)
4099 error ("arithmetic on pointer to an incomplete type");
4100
4101 op1 = ((TREE_CODE (target_type) == VOID_TYPE
4102 || TREE_CODE (target_type) == FUNCTION_TYPE
4103 || TREE_CODE (target_type) == METHOD_TYPE

--- 7 unchanged lines hidden (view full) ---

4111
4112 folded = fold (result);
4113 if (folded == result)
4114 TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
4115 return folded;
4116}
4117
4118/* Handle the case of taking the address of a COMPONENT_REF.
4247
4248 /* This generates an error if op1 is a pointer to an incomplete type. */
4249 if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1))) == 0)
4250 error ("arithmetic on pointer to an incomplete type");
4251
4252 op1 = ((TREE_CODE (target_type) == VOID_TYPE
4253 || TREE_CODE (target_type) == FUNCTION_TYPE
4254 || TREE_CODE (target_type) == METHOD_TYPE

--- 7 unchanged lines hidden (view full) ---

4262
4263 folded = fold (result);
4264 if (folded == result)
4265 TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
4266 return folded;
4267}
4268
4269/* Handle the case of taking the address of a COMPONENT_REF.
4119 Called by `build_unary_op' and `build_up_reference'.
4270 Called by `build_unary_op'.
4120
4121 ARG is the COMPONENT_REF whose address we want.
4271
4272 ARG is the COMPONENT_REF whose address we want.
4122 ARGTYPE is the pointer type that this address should have.
4123 MSG is an error message to print if this COMPONENT_REF is not
4124 addressable (such as a bitfield). */
4273 ARGTYPE is the pointer type that this address should have. */
4125
4274
4126tree
4127build_component_addr (arg, argtype, msg)
4275static tree
4276build_component_addr (arg, argtype)
4128 tree arg, argtype;
4277 tree arg, argtype;
4129 char *msg;
4130{
4131 tree field = TREE_OPERAND (arg, 1);
4132 tree basetype = decl_type_context (field);
4133 tree rval = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
4134
4278{
4279 tree field = TREE_OPERAND (arg, 1);
4280 tree basetype = decl_type_context (field);
4281 tree rval = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
4282
4135 if (DECL_BIT_FIELD (field))
4283 my_friendly_assert (TREE_CODE (field) == FIELD_DECL, 981018);
4284
4285 if (DECL_C_BIT_FIELD (field))
4136 {
4286 {
4137 error (msg, IDENTIFIER_POINTER (DECL_NAME (field)));
4287 cp_error ("attempt to take address of bit-field structure member `%D'",
4288 field);
4138 return error_mark_node;
4139 }
4140
4141 if (TREE_CODE (field) == FIELD_DECL
4142 && TYPE_USES_COMPLEX_INHERITANCE (basetype))
4143 {
4144 /* Can't convert directly to ARGTYPE, since that
4145 may have the same pointer type as one of our

--- 85 unchanged lines hidden (view full) ---

4231build_unary_op (code, xarg, noconvert)
4232 enum tree_code code;
4233 tree xarg;
4234 int noconvert;
4235{
4236 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
4237 register tree arg = xarg;
4238 register tree argtype = 0;
4289 return error_mark_node;
4290 }
4291
4292 if (TREE_CODE (field) == FIELD_DECL
4293 && TYPE_USES_COMPLEX_INHERITANCE (basetype))
4294 {
4295 /* Can't convert directly to ARGTYPE, since that
4296 may have the same pointer type as one of our

--- 85 unchanged lines hidden (view full) ---

4382build_unary_op (code, xarg, noconvert)
4383 enum tree_code code;
4384 tree xarg;
4385 int noconvert;
4386{
4387 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
4388 register tree arg = xarg;
4389 register tree argtype = 0;
4239 char *errstring = NULL;
4390 const char *errstring = NULL;
4240 tree val;
4241
4242 if (arg == error_mark_node)
4243 return error_mark_node;
4244
4245 switch (code)
4246 {
4247 case CONVERT_EXPR:

--- 112 unchanged lines hidden (view full) ---

4360 errstring ="no pre-decrement operator for type";
4361 else
4362 errstring ="no post-decrement operator for type";
4363 break;
4364 }
4365
4366 /* Report something read-only. */
4367
4391 tree val;
4392
4393 if (arg == error_mark_node)
4394 return error_mark_node;
4395
4396 switch (code)
4397 {
4398 case CONVERT_EXPR:

--- 112 unchanged lines hidden (view full) ---

4511 errstring ="no pre-decrement operator for type";
4512 else
4513 errstring ="no post-decrement operator for type";
4514 break;
4515 }
4516
4517 /* Report something read-only. */
4518
4368 if (TYPE_READONLY (TREE_TYPE (arg))
4519 if (CP_TYPE_CONST_P (TREE_TYPE (arg))
4369 || TREE_READONLY (arg))
4370 readonly_error (arg, ((code == PREINCREMENT_EXPR
4371 || code == POSTINCREMENT_EXPR)
4372 ? "increment" : "decrement"),
4373 0);
4374
4375 {
4376 register tree inc;

--- 110 unchanged lines hidden (view full) ---

4487 TREE_SIDE_EFFECTS (val) = 1;
4488 return cp_convert (result_type, val);
4489 }
4490
4491 case ADDR_EXPR:
4492 /* Note that this operation never does default_conversion
4493 regardless of NOCONVERT. */
4494
4520 || TREE_READONLY (arg))
4521 readonly_error (arg, ((code == PREINCREMENT_EXPR
4522 || code == POSTINCREMENT_EXPR)
4523 ? "increment" : "decrement"),
4524 0);
4525
4526 {
4527 register tree inc;

--- 110 unchanged lines hidden (view full) ---

4638 TREE_SIDE_EFFECTS (val) = 1;
4639 return cp_convert (result_type, val);
4640 }
4641
4642 case ADDR_EXPR:
4643 /* Note that this operation never does default_conversion
4644 regardless of NOCONVERT. */
4645
4495 argtype = TREE_TYPE (arg);
4646 argtype = lvalue_type (arg);
4496 if (TREE_CODE (argtype) == REFERENCE_TYPE)
4497 {
4498 arg = build1
4499 (CONVERT_EXPR,
4647 if (TREE_CODE (argtype) == REFERENCE_TYPE)
4648 {
4649 arg = build1
4650 (CONVERT_EXPR,
4500 build_pointer_type (TREE_TYPE (TREE_TYPE (arg))), arg);
4651 build_pointer_type (TREE_TYPE (argtype)), arg);
4501 TREE_CONSTANT (arg) = TREE_CONSTANT (TREE_OPERAND (arg, 0));
4502 return arg;
4503 }
4504 else if (pedantic && DECL_MAIN_P (arg))
4505 /* ARM $3.4 */
4506 pedwarn ("taking address of function `main'");
4507
4508 /* Let &* cancel out to simplify resulting code. */

--- 19 unchanged lines hidden (view full) ---

4528 }
4529
4530 /* For &x[y], return x+y */
4531 if (TREE_CODE (arg) == ARRAY_REF)
4532 {
4533 if (mark_addressable (TREE_OPERAND (arg, 0)) == 0)
4534 return error_mark_node;
4535 return build_binary_op (PLUS_EXPR, TREE_OPERAND (arg, 0),
4652 TREE_CONSTANT (arg) = TREE_CONSTANT (TREE_OPERAND (arg, 0));
4653 return arg;
4654 }
4655 else if (pedantic && DECL_MAIN_P (arg))
4656 /* ARM $3.4 */
4657 pedwarn ("taking address of function `main'");
4658
4659 /* Let &* cancel out to simplify resulting code. */

--- 19 unchanged lines hidden (view full) ---

4679 }
4680
4681 /* For &x[y], return x+y */
4682 if (TREE_CODE (arg) == ARRAY_REF)
4683 {
4684 if (mark_addressable (TREE_OPERAND (arg, 0)) == 0)
4685 return error_mark_node;
4686 return build_binary_op (PLUS_EXPR, TREE_OPERAND (arg, 0),
4536 TREE_OPERAND (arg, 1), 1);
4687 TREE_OPERAND (arg, 1));
4537 }
4538
4539 /* Uninstantiated types are all functions. Taking the
4540 address of a function is a no-op, so just return the
4541 argument. */
4542
4543 if (TREE_CODE (arg) == IDENTIFIER_NODE
4544 && IDENTIFIER_OPNAME_P (arg))
4545 {
4546 my_friendly_abort (117);
4547 /* We don't know the type yet, so just work around the problem.
4548 We know that this will resolve to an lvalue. */
4549 return build1 (ADDR_EXPR, unknown_type_node, arg);
4550 }
4551
4688 }
4689
4690 /* Uninstantiated types are all functions. Taking the
4691 address of a function is a no-op, so just return the
4692 argument. */
4693
4694 if (TREE_CODE (arg) == IDENTIFIER_NODE
4695 && IDENTIFIER_OPNAME_P (arg))
4696 {
4697 my_friendly_abort (117);
4698 /* We don't know the type yet, so just work around the problem.
4699 We know that this will resolve to an lvalue. */
4700 return build1 (ADDR_EXPR, unknown_type_node, arg);
4701 }
4702
4552 if (TREE_CODE (arg) == OVERLOAD
4553 || (TREE_CODE (arg) == OFFSET_REF
4554 && TREE_CODE (TREE_OPERAND (arg, 1)) == TEMPLATE_ID_EXPR))
4555 return build1 (ADDR_EXPR, unknown_type_node, arg);
4556 else if (TREE_CODE (arg) == TREE_LIST)
4703 if (TREE_CODE (arg) == COMPONENT_REF && type_unknown_p (arg)
4704 && OVL_NEXT (TREE_OPERAND (arg, 1)) == NULL_TREE)
4557 {
4705 {
4558 if (TREE_CODE (TREE_VALUE (arg)) == FUNCTION_DECL)
4559 /* Unique overloaded non-member function. */
4560 return build_unary_op (ADDR_EXPR, TREE_VALUE (arg), 0);
4561 if (TREE_CHAIN (arg) == NULL_TREE
4562 && TREE_CODE (TREE_VALUE (arg)) == TREE_LIST
4563 && TREE_CODE (TREE_VALUE (TREE_VALUE (arg))) != OVERLOAD)
4564 /* Unique overloaded member function. */
4565 return build_unary_op (ADDR_EXPR, TREE_VALUE (TREE_VALUE (arg)),
4566 0);
4567 return build1 (ADDR_EXPR, unknown_type_node, arg);
4568 }
4569 else if (TREE_CODE (arg) == TEMPLATE_ID_EXPR)
4570 {
4571 tree targs;
4572 tree fn;
4573
4574 /* We don't require a match here; it's possible that the
4575 context (like a cast to a particular type) will resolve
4576 the particular choice of template. */
4577 fn = determine_specialization (arg,
4578 NULL_TREE,
4579 &targs,
4580 0,
4581 0);
4706 /* They're trying to take the address of a unique non-static
4707 member function. This is ill-formed, but let's try to DTRT. */
4708 tree base, name;
4582
4709
4583 if (fn)
4584 {
4585 fn = instantiate_template (fn, targs);
4586 mark_addressable (fn);
4587 return build_unary_op (ADDR_EXPR, fn, 0);
4588 }
4710 if (current_class_type
4711 && TREE_OPERAND (arg, 0) == current_class_ref)
4712 /* An expression like &memfn. */
4713 pedwarn ("taking the address of a non-static member function");
4714 else
4715 pedwarn ("taking the address of a bound member function");
4589
4716
4590 return build1 (ADDR_EXPR, unknown_type_node, arg);
4717 base = TREE_TYPE (TREE_OPERAND (arg, 0));
4718 name = DECL_NAME (OVL_CURRENT (TREE_OPERAND (arg, 1)));
4719
4720 cp_pedwarn (" to form a pointer to member function, say `&%T::%D'",
4721 base, name);
4722 arg = build_offset_ref (base, name);
4591 }
4592
4723 }
4724
4725 if (type_unknown_p (arg))
4726 return build1 (ADDR_EXPR, unknown_type_node, arg);
4727
4593 /* Handle complex lvalues (when permitted)
4594 by reduction to simpler cases. */
4595 val = unary_complex_lvalue (code, arg);
4596 if (val != 0)
4597 return val;
4598
4599 switch (TREE_CODE (arg))
4600 {

--- 19 unchanged lines hidden (view full) ---

4620 ;
4621 /* Anything not already handled and not a true memory reference
4622 is an error. */
4623 else if (TREE_CODE (argtype) != FUNCTION_TYPE
4624 && TREE_CODE (argtype) != METHOD_TYPE
4625 && !lvalue_or_else (arg, "unary `&'"))
4626 return error_mark_node;
4627
4728 /* Handle complex lvalues (when permitted)
4729 by reduction to simpler cases. */
4730 val = unary_complex_lvalue (code, arg);
4731 if (val != 0)
4732 return val;
4733
4734 switch (TREE_CODE (arg))
4735 {

--- 19 unchanged lines hidden (view full) ---

4755 ;
4756 /* Anything not already handled and not a true memory reference
4757 is an error. */
4758 else if (TREE_CODE (argtype) != FUNCTION_TYPE
4759 && TREE_CODE (argtype) != METHOD_TYPE
4760 && !lvalue_or_else (arg, "unary `&'"))
4761 return error_mark_node;
4762
4628 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
4629 /* If the lvalue is const or volatile,
4630 merge that into the type that the address will point to. */
4631 if (TREE_CODE_CLASS (TREE_CODE (arg)) == 'd'
4632 || TREE_CODE_CLASS (TREE_CODE (arg)) == 'r')
4633 {
4634 if (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
4635 argtype = cp_build_type_variant (argtype,
4636 TREE_READONLY (arg),
4637 TREE_THIS_VOLATILE (arg));
4638 }
4763 if (argtype != error_mark_node)
4764 argtype = build_pointer_type (argtype);
4639
4765
4640 argtype = build_pointer_type (argtype);
4641
4642 if (mark_addressable (arg) == 0)
4643 return error_mark_node;
4644
4645 {
4646 tree addr;
4647
4648 if (TREE_CODE (arg) == COMPONENT_REF)
4766 if (mark_addressable (arg) == 0)
4767 return error_mark_node;
4768
4769 {
4770 tree addr;
4771
4772 if (TREE_CODE (arg) == COMPONENT_REF)
4649 addr = build_component_addr
4650 (arg, argtype,
4651 "attempt to take address of bit-field structure member `%s'");
4773 addr = build_component_addr (arg, argtype);
4652 else
4774 else
4653 addr = build1 (code, argtype, arg);
4775 addr = build1 (ADDR_EXPR, argtype, arg);
4654
4655 /* Address of a static or external variable or
4656 function counts as a constant */
4657 if (staticp (arg))
4658 TREE_CONSTANT (addr) = 1;
4659
4660 if (TREE_CODE (argtype) == POINTER_TYPE
4661 && TREE_CODE (TREE_TYPE (argtype)) == METHOD_TYPE)

--- 116 unchanged lines hidden (view full) ---

4778 cp_error ("taking address of destructor");
4779 return build_unary_op (ADDR_EXPR, t, 0);
4780 }
4781 if (TREE_CODE (t) == VAR_DECL)
4782 return build_unary_op (ADDR_EXPR, t, 0);
4783 else
4784 {
4785 tree type;
4776
4777 /* Address of a static or external variable or
4778 function counts as a constant */
4779 if (staticp (arg))
4780 TREE_CONSTANT (addr) = 1;
4781
4782 if (TREE_CODE (argtype) == POINTER_TYPE
4783 && TREE_CODE (TREE_TYPE (argtype)) == METHOD_TYPE)

--- 116 unchanged lines hidden (view full) ---

4900 cp_error ("taking address of destructor");
4901 return build_unary_op (ADDR_EXPR, t, 0);
4902 }
4903 if (TREE_CODE (t) == VAR_DECL)
4904 return build_unary_op (ADDR_EXPR, t, 0);
4905 else
4906 {
4907 tree type;
4786 tree offset;
4787
4788 if (TREE_OPERAND (arg, 0)
4908
4909 if (TREE_OPERAND (arg, 0)
4789 && (TREE_CODE (TREE_OPERAND (arg, 0)) != NOP_EXPR
4790 || (TREE_OPERAND (TREE_OPERAND (arg, 0), 0)
4791 != error_mark_node)))
4792 if (TREE_CODE (t) != FIELD_DECL)
4793 {
4794 /* Don't know if this should return address to just
4795 _DECL, or actual address resolved in this expression. */
4796 sorry ("address of bound pointer-to-member expression");
4797 return error_mark_node;
4798 }
4910 && ! is_dummy_object (TREE_OPERAND (arg, 0))
4911 && TREE_CODE (t) != FIELD_DECL)
4912 {
4913 cp_error ("taking address of bound pointer-to-member expression");
4914 return error_mark_node;
4915 }
4799
4916
4800 /* Add in the offset to the field. */
4801 offset = convert (sizetype,
4802 size_binop (EASY_DIV_EXPR,
4803 DECL_FIELD_BITPOS (t),
4804 size_int (BITS_PER_UNIT)));
4805
4806 /* We offset all pointer to data members by 1 so that we can
4807 distinguish between a null pointer to data member and the first
4808 data member of a structure. */
4809 offset = size_binop (PLUS_EXPR, offset, size_int (1));
4810
4811 type = build_offset_type (DECL_FIELD_CONTEXT (t), TREE_TYPE (t));
4812 type = build_pointer_type (type);
4813
4917 type = build_offset_type (DECL_FIELD_CONTEXT (t), TREE_TYPE (t));
4918 type = build_pointer_type (type);
4919
4814 return cp_convert (type, offset);
4920 t = make_ptrmem_cst (type, TREE_OPERAND (arg, 1));
4921 return t;
4815 }
4816 }
4817
4818
4819 /* We permit compiler to make function calls returning
4820 objects of aggregate type look like lvalues. */
4821 {
4822 tree targ = arg;

--- 61 unchanged lines hidden (view full) ---

4884 {
4885 /* We thought this would make a good constant variable,
4886 but we were wrong. */
4887 push_obstacks_nochange ();
4888 end_temporary_allocation ();
4889
4890 TREE_ASM_WRITTEN (x) = 0;
4891 DECL_RTL (x) = 0;
4922 }
4923 }
4924
4925
4926 /* We permit compiler to make function calls returning
4927 objects of aggregate type look like lvalues. */
4928 {
4929 tree targ = arg;

--- 61 unchanged lines hidden (view full) ---

4991 {
4992 /* We thought this would make a good constant variable,
4993 but we were wrong. */
4994 push_obstacks_nochange ();
4995 end_temporary_allocation ();
4996
4997 TREE_ASM_WRITTEN (x) = 0;
4998 DECL_RTL (x) = 0;
4892 rest_of_decl_compilation (x, 0, IDENTIFIER_LOCAL_VALUE (x) == 0,
4999 rest_of_decl_compilation (x, 0,
5000 !DECL_FUNCTION_SCOPE_P (x),
4893 0);
4894 TREE_ADDRESSABLE (x) = 1;
4895
4896 pop_obstacks ();
4897
4898 return 1;
4899 }
4900 /* Caller should not be trying to mark initialized

--- 68 unchanged lines hidden (view full) ---

4969 make sure it is calculated only once. */
4970 if (op1 == 0)
4971 {
4972 if (pedantic)
4973 pedwarn ("ANSI C++ forbids omitting the middle term of a ?: expression");
4974 ifexp = op1 = save_expr (ifexp);
4975 }
4976
5001 0);
5002 TREE_ADDRESSABLE (x) = 1;
5003
5004 pop_obstacks ();
5005
5006 return 1;
5007 }
5008 /* Caller should not be trying to mark initialized

--- 68 unchanged lines hidden (view full) ---

5077 make sure it is calculated only once. */
5078 if (op1 == 0)
5079 {
5080 if (pedantic)
5081 pedwarn ("ANSI C++ forbids omitting the middle term of a ?: expression");
5082 ifexp = op1 = save_expr (ifexp);
5083 }
5084
5085 type1 = TREE_TYPE (op1);
5086 code1 = TREE_CODE (type1);
5087 type2 = TREE_TYPE (op2);
5088 code2 = TREE_CODE (type2);
5089 if (op1 == error_mark_node || op2 == error_mark_node
5090 || type1 == error_mark_node || type2 == error_mark_node)
5091 return error_mark_node;
5092
4977 ifexp = cp_convert (boolean_type_node, ifexp);
4978
4979 if (TREE_CODE (ifexp) == ERROR_MARK)
4980 return error_mark_node;
4981
5093 ifexp = cp_convert (boolean_type_node, ifexp);
5094
5095 if (TREE_CODE (ifexp) == ERROR_MARK)
5096 return error_mark_node;
5097
4982 op1 = require_instantiated_type (TREE_TYPE (op2), op1, error_mark_node);
4983 if (op1 == error_mark_node)
4984 return error_mark_node;
4985 op2 = require_instantiated_type (TREE_TYPE (op1), op2, error_mark_node);
4986 if (op2 == error_mark_node)
4987 return error_mark_node;
4988
4989 /* C++: REFERENCE_TYPES must be dereferenced. */
5098 /* C++: REFERENCE_TYPES must be dereferenced. */
4990 type1 = TREE_TYPE (op1);
4991 code1 = TREE_CODE (type1);
4992 type2 = TREE_TYPE (op2);
4993 code2 = TREE_CODE (type2);
4994
4995 if (code1 == REFERENCE_TYPE)
4996 {
4997 op1 = convert_from_reference (op1);
4998 type1 = TREE_TYPE (op1);
4999 code1 = TREE_CODE (type1);
5000 }
5001 if (code2 == REFERENCE_TYPE)
5002 {

--- 22 unchanged lines hidden (view full) ---

5025 op1 = DECL_INITIAL (op1);
5026 else if (TREE_READONLY_DECL_P (op1))
5027 op1 = decl_constant_value (op1);
5028 if (TREE_CODE (op2) == CONST_DECL)
5029 op2 = DECL_INITIAL (op2);
5030 else if (TREE_READONLY_DECL_P (op2))
5031 op2 = decl_constant_value (op2);
5032 if (type1 != type2)
5099 if (code1 == REFERENCE_TYPE)
5100 {
5101 op1 = convert_from_reference (op1);
5102 type1 = TREE_TYPE (op1);
5103 code1 = TREE_CODE (type1);
5104 }
5105 if (code2 == REFERENCE_TYPE)
5106 {

--- 22 unchanged lines hidden (view full) ---

5129 op1 = DECL_INITIAL (op1);
5130 else if (TREE_READONLY_DECL_P (op1))
5131 op1 = decl_constant_value (op1);
5132 if (TREE_CODE (op2) == CONST_DECL)
5133 op2 = DECL_INITIAL (op2);
5134 else if (TREE_READONLY_DECL_P (op2))
5135 op2 = decl_constant_value (op2);
5136 if (type1 != type2)
5033 type1 = cp_build_type_variant
5034 (type1,
5035 TREE_READONLY (op1) || TREE_READONLY (op2),
5036 TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2));
5137 type1 = cp_build_qualified_type
5138 (type1, (CP_TYPE_QUALS (TREE_TYPE (op1))
5139 | CP_TYPE_QUALS (TREE_TYPE (op2))));
5037 /* ??? This is a kludge to deal with the fact that
5038 we don't sort out integers and enums properly, yet. */
5039 result = fold (build (COND_EXPR, type1, ifexp, op1, op2));
5040 if (TREE_TYPE (result) != type1)
5041 result = build1 (NOP_EXPR, type1, result);
5042 /* Expand both sides into the same slot,
5043 hopefully the target of the ?: expression. */
5044 if (TREE_CODE (op1) == TARGET_EXPR && TREE_CODE (op2) == TARGET_EXPR)

--- 39 unchanged lines hidden (view full) ---

5084 type2 = TREE_TYPE (op2);
5085 if (TYPE_PTRMEMFUNC_P (type2))
5086 type2 = TYPE_PTRMEMFUNC_FN_TYPE (type2);
5087 code2 = TREE_CODE (type2);
5088 }
5089
5090 if (code1 == RECORD_TYPE && code2 == RECORD_TYPE
5091 && real_lvalue_p (op1) && real_lvalue_p (op2)
5140 /* ??? This is a kludge to deal with the fact that
5141 we don't sort out integers and enums properly, yet. */
5142 result = fold (build (COND_EXPR, type1, ifexp, op1, op2));
5143 if (TREE_TYPE (result) != type1)
5144 result = build1 (NOP_EXPR, type1, result);
5145 /* Expand both sides into the same slot,
5146 hopefully the target of the ?: expression. */
5147 if (TREE_CODE (op1) == TARGET_EXPR && TREE_CODE (op2) == TARGET_EXPR)

--- 39 unchanged lines hidden (view full) ---

5187 type2 = TREE_TYPE (op2);
5188 if (TYPE_PTRMEMFUNC_P (type2))
5189 type2 = TYPE_PTRMEMFUNC_FN_TYPE (type2);
5190 code2 = TREE_CODE (type2);
5191 }
5192
5193 if (code1 == RECORD_TYPE && code2 == RECORD_TYPE
5194 && real_lvalue_p (op1) && real_lvalue_p (op2)
5092 && comptypes (type1, type2, -1))
5195 && comptypes (type1, type2, COMPARE_BASE | COMPARE_RELAXED))
5093 {
5094 type1 = build_reference_type (type1);
5095 type2 = build_reference_type (type2);
5096 result_type = common_type (type1, type2);
5097 op1 = convert_to_reference (result_type, op1, CONV_IMPLICIT,
5098 LOOKUP_NORMAL, NULL_TREE);
5099 op2 = convert_to_reference (result_type, op2, CONV_IMPLICIT,
5100 LOOKUP_NORMAL, NULL_TREE);
5101 }
5102 /* Quickly detect the usual case where op1 and op2 have the same type
5103 after promotion. */
5104 else if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
5105 {
5106 if (type1 == type2)
5107 result_type = type1;
5108 else
5196 {
5197 type1 = build_reference_type (type1);
5198 type2 = build_reference_type (type2);
5199 result_type = common_type (type1, type2);
5200 op1 = convert_to_reference (result_type, op1, CONV_IMPLICIT,
5201 LOOKUP_NORMAL, NULL_TREE);
5202 op2 = convert_to_reference (result_type, op2, CONV_IMPLICIT,
5203 LOOKUP_NORMAL, NULL_TREE);
5204 }
5205 /* Quickly detect the usual case where op1 and op2 have the same type
5206 after promotion. */
5207 else if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
5208 {
5209 if (type1 == type2)
5210 result_type = type1;
5211 else
5109 result_type = cp_build_type_variant
5110 (type1,
5111 TREE_READONLY (op1) || TREE_READONLY (op2),
5112 TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2));
5212 result_type =
5213 cp_build_qualified_type (type1,
5214 CP_TYPE_QUALS (TREE_TYPE (op1))
5215 | CP_TYPE_QUALS (TREE_TYPE (op2)));
5113 }
5114 else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE)
5115 && (code2 == INTEGER_TYPE || code2 == REAL_TYPE))
5116 {
5117 result_type = common_type (type1, type2);
5118 }
5119 else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
5120 {

--- 17 unchanged lines hidden (view full) ---

5138 }
5139 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2)) == void_type_node)
5140 {
5141 if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE)
5142 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
5143 result_type = qualify_type (type2, type1);
5144 }
5145 /* C++ */
5216 }
5217 else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE)
5218 && (code2 == INTEGER_TYPE || code2 == REAL_TYPE))
5219 {
5220 result_type = common_type (type1, type2);
5221 }
5222 else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
5223 {

--- 17 unchanged lines hidden (view full) ---

5241 }
5242 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2)) == void_type_node)
5243 {
5244 if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE)
5245 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
5246 result_type = qualify_type (type2, type1);
5247 }
5248 /* C++ */
5146 else if (comptypes (type2, type1, 0))
5249 else if (same_or_base_type_p (type2, type1))
5147 result_type = type2;
5148 else if (IS_AGGR_TYPE (TREE_TYPE (type1))
5149 && IS_AGGR_TYPE (TREE_TYPE (type2))
5150 && (result_type = common_base_type (TREE_TYPE (type1),
5151 TREE_TYPE (type2))))
5152 {
5153 if (result_type == error_mark_node)
5154 {

--- 23 unchanged lines hidden (view full) ---

5178 pedwarn ("pointer/integer type mismatch in conditional expression");
5179 result_type = type1;
5180 }
5181 else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE)
5182 {
5183 pedwarn ("pointer/integer type mismatch in conditional expression");
5184 result_type = type2;
5185 }
5250 result_type = type2;
5251 else if (IS_AGGR_TYPE (TREE_TYPE (type1))
5252 && IS_AGGR_TYPE (TREE_TYPE (type2))
5253 && (result_type = common_base_type (TREE_TYPE (type1),
5254 TREE_TYPE (type2))))
5255 {
5256 if (result_type == error_mark_node)
5257 {

--- 23 unchanged lines hidden (view full) ---

5281 pedwarn ("pointer/integer type mismatch in conditional expression");
5282 result_type = type1;
5283 }
5284 else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE)
5285 {
5286 pedwarn ("pointer/integer type mismatch in conditional expression");
5287 result_type = type2;
5288 }
5289 if (type2 == unknown_type_node)
5290 result_type = type1;
5291 else if (type1 == unknown_type_node)
5292 result_type = type2;
5186
5187 if (!result_type)
5188 {
5189 /* The match does not look good. If either is
5190 an aggregate value, try converting to a scalar type. */
5191 if (code1 == RECORD_TYPE && code2 == RECORD_TYPE)
5192 {
5193 cp_error ("aggregate mismatch in conditional expression: `%T' vs `%T'",
5194 type1, type2);
5195 return error_mark_node;
5196 }
5197 /* Warning: this code assumes that conversion between cv-variants of
5198 a type is done using NOP_EXPRs. */
5199 if (code1 == RECORD_TYPE && TYPE_HAS_CONVERSION (type1))
5200 {
5201 /* There are other types besides pointers and records. */
5202 tree tmp;
5203 if (code2 == POINTER_TYPE)
5204 tmp = build_pointer_type
5293
5294 if (!result_type)
5295 {
5296 /* The match does not look good. If either is
5297 an aggregate value, try converting to a scalar type. */
5298 if (code1 == RECORD_TYPE && code2 == RECORD_TYPE)
5299 {
5300 cp_error ("aggregate mismatch in conditional expression: `%T' vs `%T'",
5301 type1, type2);
5302 return error_mark_node;
5303 }
5304 /* Warning: this code assumes that conversion between cv-variants of
5305 a type is done using NOP_EXPRs. */
5306 if (code1 == RECORD_TYPE && TYPE_HAS_CONVERSION (type1))
5307 {
5308 /* There are other types besides pointers and records. */
5309 tree tmp;
5310 if (code2 == POINTER_TYPE)
5311 tmp = build_pointer_type
5205 (build_type_variant (TREE_TYPE (type2), 1, 1));
5312 (cp_build_qualified_type (TREE_TYPE (type2),
5313 TYPE_QUAL_CONST
5314 | TYPE_QUAL_VOLATILE
5315 | TYPE_QUAL_RESTRICT));
5206 else
5207 tmp = type2;
5316 else
5317 tmp = type2;
5208 tmp = build_type_conversion (CONVERT_EXPR, tmp, op1, 0);
5318 tmp = build_type_conversion (tmp, op1, 0);
5209 if (tmp == NULL_TREE)
5210 {
5211 cp_error ("incompatible types `%T' and `%T' in `?:'",
5212 type1, type2);
5213 return error_mark_node;
5214 }
5215 if (tmp == error_mark_node)
5216 error ("ambiguous pointer conversion");
5217 else
5218 STRIP_NOPS (tmp);
5219 result_type = common_type (type2, TREE_TYPE (tmp));
5220 op1 = tmp;
5221 }
5222 else if (code2 == RECORD_TYPE && TYPE_HAS_CONVERSION (type2))
5223 {
5224 tree tmp;
5225 if (code1 == POINTER_TYPE)
5226 tmp = build_pointer_type
5319 if (tmp == NULL_TREE)
5320 {
5321 cp_error ("incompatible types `%T' and `%T' in `?:'",
5322 type1, type2);
5323 return error_mark_node;
5324 }
5325 if (tmp == error_mark_node)
5326 error ("ambiguous pointer conversion");
5327 else
5328 STRIP_NOPS (tmp);
5329 result_type = common_type (type2, TREE_TYPE (tmp));
5330 op1 = tmp;
5331 }
5332 else if (code2 == RECORD_TYPE && TYPE_HAS_CONVERSION (type2))
5333 {
5334 tree tmp;
5335 if (code1 == POINTER_TYPE)
5336 tmp = build_pointer_type
5227 (build_type_variant (TREE_TYPE (type1), 1, 1));
5337 (cp_build_qualified_type (TREE_TYPE (type1),
5338 TYPE_QUAL_CONST
5339 | TYPE_QUAL_VOLATILE
5340 | TYPE_QUAL_RESTRICT));
5228 else
5229 tmp = type1;
5230
5341 else
5342 tmp = type1;
5343
5231 tmp = build_type_conversion (CONVERT_EXPR, tmp, op2, 0);
5344 tmp = build_type_conversion (tmp, op2, 0);
5232 if (tmp == NULL_TREE)
5233 {
5234 cp_error ("incompatible types `%T' and `%T' in `?:'",
5235 type1, type2);
5236 return error_mark_node;
5237 }
5238 if (tmp == error_mark_node)
5239 error ("ambiguous pointer conversion");

--- 75 unchanged lines hidden (view full) ---

5315/* Given a list of expressions, return a compound expression
5316 that performs them all and returns the value of the last of them. */
5317
5318tree
5319build_compound_expr (list)
5320 tree list;
5321{
5322 register tree rest;
5345 if (tmp == NULL_TREE)
5346 {
5347 cp_error ("incompatible types `%T' and `%T' in `?:'",
5348 type1, type2);
5349 return error_mark_node;
5350 }
5351 if (tmp == error_mark_node)
5352 error ("ambiguous pointer conversion");

--- 75 unchanged lines hidden (view full) ---

5428/* Given a list of expressions, return a compound expression
5429 that performs them all and returns the value of the last of them. */
5430
5431tree
5432build_compound_expr (list)
5433 tree list;
5434{
5435 register tree rest;
5436 tree first;
5323
5324 if (TREE_READONLY_DECL_P (TREE_VALUE (list)))
5325 TREE_VALUE (list) = decl_constant_value (TREE_VALUE (list));
5326
5327 if (TREE_CHAIN (list) == 0)
5328 {
5329 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5330 Strip such NOP_EXPRs, since LIST is used in non-lvalue context. */
5331 if (TREE_CODE (list) == NOP_EXPR
5332 && TREE_TYPE (list) == TREE_TYPE (TREE_OPERAND (list, 0)))
5333 list = TREE_OPERAND (list, 0);
5334
5335 /* Convert arrays to pointers. */
5336 if (TREE_CODE (TREE_TYPE (TREE_VALUE (list))) == ARRAY_TYPE)
5337 return default_conversion (TREE_VALUE (list));
5338 else
5339 return TREE_VALUE (list);
5340 }
5341
5437
5438 if (TREE_READONLY_DECL_P (TREE_VALUE (list)))
5439 TREE_VALUE (list) = decl_constant_value (TREE_VALUE (list));
5440
5441 if (TREE_CHAIN (list) == 0)
5442 {
5443 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5444 Strip such NOP_EXPRs, since LIST is used in non-lvalue context. */
5445 if (TREE_CODE (list) == NOP_EXPR
5446 && TREE_TYPE (list) == TREE_TYPE (TREE_OPERAND (list, 0)))
5447 list = TREE_OPERAND (list, 0);
5448
5449 /* Convert arrays to pointers. */
5450 if (TREE_CODE (TREE_TYPE (TREE_VALUE (list))) == ARRAY_TYPE)
5451 return default_conversion (TREE_VALUE (list));
5452 else
5453 return TREE_VALUE (list);
5454 }
5455
5456 first = TREE_VALUE (list);
5457 first = require_complete_type_in_void (first);
5458 if (first == error_mark_node)
5459 return error_mark_node;
5460
5342 rest = build_compound_expr (TREE_CHAIN (list));
5461 rest = build_compound_expr (TREE_CHAIN (list));
5462 if (rest == error_mark_node)
5463 return error_mark_node;
5343
5344 /* When pedantic, a compound expression cannot be a constant expression. */
5464
5465 /* When pedantic, a compound expression cannot be a constant expression. */
5345 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list)) && ! pedantic)
5466 if (! TREE_SIDE_EFFECTS (first) && ! pedantic)
5346 return rest;
5347
5348 return build (COMPOUND_EXPR, TREE_TYPE (rest),
5467 return rest;
5468
5469 return build (COMPOUND_EXPR, TREE_TYPE (rest),
5349 break_out_cleanups (TREE_VALUE (list)), rest);
5470 break_out_cleanups (first), rest);
5350}
5351
5352tree
5353build_static_cast (type, expr)
5354 tree type, expr;
5355{
5356 tree intype, binfo;
5357 int ok;

--- 16 unchanged lines hidden (view full) ---

5374 if (TREE_CODE (type) != REFERENCE_TYPE
5375 && TREE_CODE (expr) == NOP_EXPR
5376 && TREE_TYPE (expr) == TREE_TYPE (TREE_OPERAND (expr, 0)))
5377 expr = TREE_OPERAND (expr, 0);
5378
5379 if (TREE_CODE (type) == VOID_TYPE)
5380 return build1 (CONVERT_EXPR, type, expr);
5381
5471}
5472
5473tree
5474build_static_cast (type, expr)
5475 tree type, expr;
5476{
5477 tree intype, binfo;
5478 int ok;

--- 16 unchanged lines hidden (view full) ---

5495 if (TREE_CODE (type) != REFERENCE_TYPE
5496 && TREE_CODE (expr) == NOP_EXPR
5497 && TREE_TYPE (expr) == TREE_TYPE (TREE_OPERAND (expr, 0)))
5498 expr = TREE_OPERAND (expr, 0);
5499
5500 if (TREE_CODE (type) == VOID_TYPE)
5501 return build1 (CONVERT_EXPR, type, expr);
5502
5382 if (type_unknown_p (expr))
5383 {
5384 expr = instantiate_type (type, expr, 1);
5385 if (expr == error_mark_node)
5386 return error_mark_node;
5387 }
5388
5389 if (TREE_CODE (type) == REFERENCE_TYPE)
5390 return (convert_from_reference
5391 (convert_to_reference (type, expr, CONV_STATIC|CONV_IMPLICIT,
5392 LOOKUP_COMPLAIN, NULL_TREE)));
5393
5394 if (IS_AGGR_TYPE (type))
5395 return build_cplus_new
5396 (type, (build_method_call

--- 7 unchanged lines hidden (view full) ---

5404
5405 ok = 0;
5406 if (can_convert_arg (type, intype, expr))
5407 ok = 1;
5408 else if (TYPE_PTROB_P (type) && TYPE_PTROB_P (intype))
5409 {
5410 tree binfo;
5411 if (IS_AGGR_TYPE (TREE_TYPE (type)) && IS_AGGR_TYPE (TREE_TYPE (intype))
5503 if (TREE_CODE (type) == REFERENCE_TYPE)
5504 return (convert_from_reference
5505 (convert_to_reference (type, expr, CONV_STATIC|CONV_IMPLICIT,
5506 LOOKUP_COMPLAIN, NULL_TREE)));
5507
5508 if (IS_AGGR_TYPE (type))
5509 return build_cplus_new
5510 (type, (build_method_call

--- 7 unchanged lines hidden (view full) ---

5518
5519 ok = 0;
5520 if (can_convert_arg (type, intype, expr))
5521 ok = 1;
5522 else if (TYPE_PTROB_P (type) && TYPE_PTROB_P (intype))
5523 {
5524 tree binfo;
5525 if (IS_AGGR_TYPE (TREE_TYPE (type)) && IS_AGGR_TYPE (TREE_TYPE (intype))
5412 && (TYPE_READONLY (TREE_TYPE (type))
5413 >= TYPE_READONLY (TREE_TYPE (intype)))
5414 && (TYPE_VOLATILE (TREE_TYPE (type))
5415 >= TYPE_VOLATILE (TREE_TYPE (intype)))
5526 && at_least_as_qualified_p (TREE_TYPE (type),
5527 TREE_TYPE (intype))
5416 && (binfo = get_binfo (TREE_TYPE (intype), TREE_TYPE (type), 0))
5417 && ! TREE_VIA_VIRTUAL (binfo))
5418 ok = 1;
5419 }
5420 else if (TYPE_PTRMEM_P (type) && TYPE_PTRMEM_P (intype))
5421 {
5528 && (binfo = get_binfo (TREE_TYPE (intype), TREE_TYPE (type), 0))
5529 && ! TREE_VIA_VIRTUAL (binfo))
5530 ok = 1;
5531 }
5532 else if (TYPE_PTRMEM_P (type) && TYPE_PTRMEM_P (intype))
5533 {
5422 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type))),
5423 TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (intype))), 1)
5424 && (TYPE_READONLY (TREE_TYPE (TREE_TYPE (type)))
5425 >= TYPE_READONLY (TREE_TYPE (TREE_TYPE (intype))))
5426 && (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (type)))
5427 >= TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (intype))))
5534 if (same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type))),
5535 TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (intype))))
5536 && at_least_as_qualified_p (TREE_TYPE (TREE_TYPE (type)),
5537 TREE_TYPE (TREE_TYPE (intype)))
5428 && (binfo = get_binfo (TYPE_OFFSET_BASETYPE (TREE_TYPE (type)),
5429 TYPE_OFFSET_BASETYPE (TREE_TYPE (intype)), 0))
5430 && ! TREE_VIA_VIRTUAL (binfo))
5431 ok = 1;
5432 }
5433 else if (TREE_CODE (intype) != BOOLEAN_TYPE
5434 && TREE_CODE (type) != ARRAY_TYPE
5435 && TREE_CODE (type) != FUNCTION_TYPE

--- 32 unchanged lines hidden (view full) ---

5468
5469 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5470 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5471 if (TREE_CODE (expr) == NOP_EXPR
5472 && TREE_TYPE (expr) == TREE_TYPE (TREE_OPERAND (expr, 0)))
5473 expr = TREE_OPERAND (expr, 0);
5474 }
5475
5538 && (binfo = get_binfo (TYPE_OFFSET_BASETYPE (TREE_TYPE (type)),
5539 TYPE_OFFSET_BASETYPE (TREE_TYPE (intype)), 0))
5540 && ! TREE_VIA_VIRTUAL (binfo))
5541 ok = 1;
5542 }
5543 else if (TREE_CODE (intype) != BOOLEAN_TYPE
5544 && TREE_CODE (type) != ARRAY_TYPE
5545 && TREE_CODE (type) != FUNCTION_TYPE

--- 32 unchanged lines hidden (view full) ---

5578
5579 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5580 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5581 if (TREE_CODE (expr) == NOP_EXPR
5582 && TREE_TYPE (expr) == TREE_TYPE (TREE_OPERAND (expr, 0)))
5583 expr = TREE_OPERAND (expr, 0);
5584 }
5585
5476 if (type_unknown_p (expr))
5477 {
5478 expr = instantiate_type (type, expr, 1);
5479 if (expr == error_mark_node)
5480 return error_mark_node;
5481 }
5482
5483 intype = TREE_TYPE (expr);
5484
5485 if (TREE_CODE (type) == REFERENCE_TYPE)
5486 {
5487 if (! real_lvalue_p (expr))
5488 {
5489 cp_error ("reinterpret_cast from `%T' rvalue to `%T'", intype, type);
5490 return error_mark_node;
5491 }
5492 expr = build_unary_op (ADDR_EXPR, expr, 0);
5493 if (expr != error_mark_node)
5494 expr = build_reinterpret_cast
5495 (build_pointer_type (TREE_TYPE (type)), expr);
5496 if (expr != error_mark_node)
5497 expr = build_indirect_ref (expr, 0);
5498 return expr;
5499 }
5586 intype = TREE_TYPE (expr);
5587
5588 if (TREE_CODE (type) == REFERENCE_TYPE)
5589 {
5590 if (! real_lvalue_p (expr))
5591 {
5592 cp_error ("reinterpret_cast from `%T' rvalue to `%T'", intype, type);
5593 return error_mark_node;
5594 }
5595 expr = build_unary_op (ADDR_EXPR, expr, 0);
5596 if (expr != error_mark_node)
5597 expr = build_reinterpret_cast
5598 (build_pointer_type (TREE_TYPE (type)), expr);
5599 if (expr != error_mark_node)
5600 expr = build_indirect_ref (expr, 0);
5601 return expr;
5602 }
5500 else if (comptypes (TYPE_MAIN_VARIANT (intype), TYPE_MAIN_VARIANT (type), 1))
5603 else if (same_type_p (TYPE_MAIN_VARIANT (intype),
5604 TYPE_MAIN_VARIANT (type)))
5501 return build_static_cast (type, expr);
5502
5503 if (TYPE_PTR_P (type) && (TREE_CODE (intype) == INTEGER_TYPE
5504 || TREE_CODE (intype) == ENUMERAL_TYPE))
5505 /* OK */;
5506 else if (TREE_CODE (type) == INTEGER_TYPE && TYPE_PTR_P (intype))
5507 {
5508 if (TYPE_PRECISION (type) < TYPE_PRECISION (intype))

--- 14 unchanged lines hidden (view full) ---

5523 cp_pedwarn ("reinterpret_cast from `%T' to `%T' casts away const (or volatile)",
5524 intype, type);
5525
5526 if (TREE_READONLY_DECL_P (expr))
5527 expr = decl_constant_value (expr);
5528 return fold (build1 (NOP_EXPR, type, expr));
5529 }
5530 else if ((TYPE_PTRFN_P (type) && TYPE_PTROBV_P (intype))
5605 return build_static_cast (type, expr);
5606
5607 if (TYPE_PTR_P (type) && (TREE_CODE (intype) == INTEGER_TYPE
5608 || TREE_CODE (intype) == ENUMERAL_TYPE))
5609 /* OK */;
5610 else if (TREE_CODE (type) == INTEGER_TYPE && TYPE_PTR_P (intype))
5611 {
5612 if (TYPE_PRECISION (type) < TYPE_PRECISION (intype))

--- 14 unchanged lines hidden (view full) ---

5627 cp_pedwarn ("reinterpret_cast from `%T' to `%T' casts away const (or volatile)",
5628 intype, type);
5629
5630 if (TREE_READONLY_DECL_P (expr))
5631 expr = decl_constant_value (expr);
5632 return fold (build1 (NOP_EXPR, type, expr));
5633 }
5634 else if ((TYPE_PTRFN_P (type) && TYPE_PTROBV_P (intype))
5531 || (TYPE_PTRFN_P (type) && TYPE_PTROBV_P (intype)))
5635 || (TYPE_PTRFN_P (intype) && TYPE_PTROBV_P (type)))
5532 {
5533 pedwarn ("ANSI C++ forbids casting between pointers to functions and objects");
5534 if (TREE_READONLY_DECL_P (expr))
5535 expr = decl_constant_value (expr);
5536 return fold (build1 (NOP_EXPR, type, expr));
5537 }
5538 else
5539 {

--- 18 unchanged lines hidden (view full) ---

5558
5559 if (processing_template_decl)
5560 {
5561 tree t = build_min (CONST_CAST_EXPR, copy_to_permanent (type),
5562 expr);
5563 return t;
5564 }
5565
5636 {
5637 pedwarn ("ANSI C++ forbids casting between pointers to functions and objects");
5638 if (TREE_READONLY_DECL_P (expr))
5639 expr = decl_constant_value (expr);
5640 return fold (build1 (NOP_EXPR, type, expr));
5641 }
5642 else
5643 {

--- 18 unchanged lines hidden (view full) ---

5662
5663 if (processing_template_decl)
5664 {
5665 tree t = build_min (CONST_CAST_EXPR, copy_to_permanent (type),
5666 expr);
5667 return t;
5668 }
5669
5670 if (!POINTER_TYPE_P (type))
5671 {
5672 cp_error ("`%T' is not a pointer, reference, or pointer-to-data-member type",
5673 type);
5674 cp_error ("as required by const_cast");
5675 }
5676 else if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
5677 {
5678 cp_error ("`%T' is a pointer or reference to a function type",
5679 type);
5680 cp_error ("which is forbidden by const_cast");
5681 return error_mark_node;
5682 }
5683
5566 if (TREE_CODE (type) != REFERENCE_TYPE)
5567 {
5568 expr = decay_conversion (expr);
5569
5570 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5571 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5572 if (TREE_CODE (expr) == NOP_EXPR
5573 && TREE_TYPE (expr) == TREE_TYPE (TREE_OPERAND (expr, 0)))
5574 expr = TREE_OPERAND (expr, 0);
5575 }
5576
5684 if (TREE_CODE (type) != REFERENCE_TYPE)
5685 {
5686 expr = decay_conversion (expr);
5687
5688 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5689 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5690 if (TREE_CODE (expr) == NOP_EXPR
5691 && TREE_TYPE (expr) == TREE_TYPE (TREE_OPERAND (expr, 0)))
5692 expr = TREE_OPERAND (expr, 0);
5693 }
5694
5577 if (type_unknown_p (expr))
5578 {
5579 expr = instantiate_type (type, expr, 1);
5580 if (expr == error_mark_node)
5581 return error_mark_node;
5582 }
5583
5584 intype = TREE_TYPE (expr);
5585
5695 intype = TREE_TYPE (expr);
5696
5586 if (comptypes (TYPE_MAIN_VARIANT (intype), TYPE_MAIN_VARIANT (type), 1))
5697 if (same_type_p (TYPE_MAIN_VARIANT (intype), TYPE_MAIN_VARIANT (type)))
5587 return build_static_cast (type, expr);
5588 else if (TREE_CODE (type) == REFERENCE_TYPE)
5589 {
5590 if (! real_lvalue_p (expr))
5591 {
5592 cp_error ("const_cast from `%T' rvalue to `%T'", intype, type);
5593 return error_mark_node;
5594 }

--- 19 unchanged lines hidden (view full) ---

5614 ALLOW_NONCONVERTING is true if we should allow non-converting constructors
5615 when doing the cast. */
5616
5617tree
5618build_c_cast (type, expr)
5619 tree type, expr;
5620{
5621 register tree value = expr;
5698 return build_static_cast (type, expr);
5699 else if (TREE_CODE (type) == REFERENCE_TYPE)
5700 {
5701 if (! real_lvalue_p (expr))
5702 {
5703 cp_error ("const_cast from `%T' rvalue to `%T'", intype, type);
5704 return error_mark_node;
5705 }

--- 19 unchanged lines hidden (view full) ---

5725 ALLOW_NONCONVERTING is true if we should allow non-converting constructors
5726 when doing the cast. */
5727
5728tree
5729build_c_cast (type, expr)
5730 tree type, expr;
5731{
5732 register tree value = expr;
5733 tree otype;
5622
5623 if (type == error_mark_node || expr == error_mark_node)
5624 return error_mark_node;
5625
5626 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5627 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5628 if (TREE_CODE (type) != REFERENCE_TYPE
5629 && TREE_CODE (value) == NOP_EXPR
5630 && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
5631 value = TREE_OPERAND (value, 0);
5632
5734
5735 if (type == error_mark_node || expr == error_mark_node)
5736 return error_mark_node;
5737
5738 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5739 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5740 if (TREE_CODE (type) != REFERENCE_TYPE
5741 && TREE_CODE (value) == NOP_EXPR
5742 && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
5743 value = TREE_OPERAND (value, 0);
5744
5633 if (TREE_TYPE (expr)
5634 && TREE_CODE (TREE_TYPE (expr)) == OFFSET_TYPE
5635 && TREE_CODE (type) != OFFSET_TYPE)
5745 if (TREE_CODE (value) == OFFSET_REF)
5636 value = resolve_offset_ref (value);
5637
5638 if (TREE_CODE (type) == ARRAY_TYPE)
5639 {
5640 /* Allow casting from T1* to T2[] because Cfront allows it.
5641 NIHCL uses it. It is not valid ANSI C however, and hence, not
5642 valid ANSI C++. */
5643 if (TREE_CODE (TREE_TYPE (expr)) == POINTER_TYPE)

--- 24 unchanged lines hidden (view full) ---

5668
5669 if (processing_template_decl)
5670 {
5671 tree t = build_min (CAST_EXPR, type,
5672 min_tree_cons (NULL_TREE, value, NULL_TREE));
5673 return t;
5674 }
5675
5746 value = resolve_offset_ref (value);
5747
5748 if (TREE_CODE (type) == ARRAY_TYPE)
5749 {
5750 /* Allow casting from T1* to T2[] because Cfront allows it.
5751 NIHCL uses it. It is not valid ANSI C however, and hence, not
5752 valid ANSI C++. */
5753 if (TREE_CODE (TREE_TYPE (expr)) == POINTER_TYPE)

--- 24 unchanged lines hidden (view full) ---

5778
5779 if (processing_template_decl)
5780 {
5781 tree t = build_min (CAST_EXPR, type,
5782 min_tree_cons (NULL_TREE, value, NULL_TREE));
5783 return t;
5784 }
5785
5676 if (TREE_CODE (type) == VOID_TYPE)
5677 value = build1 (CONVERT_EXPR, type, value);
5678 else if (TREE_TYPE (value) == NULL_TREE
5679 || type_unknown_p (value))
5680 {
5681 value = instantiate_type (type, value, 1);
5682 /* Did we lose? */
5683 if (value == error_mark_node)
5684 return error_mark_node;
5685 }
5686 else
5687 {
5688 tree otype;
5786 /* Convert functions and arrays to pointers and
5787 convert references to their expanded types,
5788 but don't convert any other types. If, however, we are
5789 casting to a class type, there's no reason to do this: the
5790 cast will only succeed if there is a converting constructor,
5791 and the default conversions will be done at that point. In
5792 fact, doing the default conversion here is actually harmful
5793 in cases like this:
5689
5794
5690 /* Convert functions and arrays to pointers and
5691 convert references to their expanded types,
5692 but don't convert any other types. If, however, we are
5693 casting to a class type, there's no reason to do this: the
5694 cast will only succeed if there is a converting constructor,
5695 and the default conversions will be done at that point. In
5696 fact, doing the default conversion here is actually harmful
5697 in cases like this:
5795 typedef int A[2];
5796 struct S { S(const A&); };
5698
5797
5699 typedef int A[2];
5700 struct S { S(const A&); };
5701
5702 since we don't want the array-to-pointer conversion done. */
5703 if (!IS_AGGR_TYPE (type))
5704 {
5705 if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE
5706 || (TREE_CODE (TREE_TYPE (value)) == METHOD_TYPE
5707 /* Don't do the default conversion if we want a
5708 pointer to a function. */
5709 && ! (TREE_CODE (type) == POINTER_TYPE
5710 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE))
5711 || TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
5712 || TREE_CODE (TREE_TYPE (value)) == REFERENCE_TYPE)
5713 value = default_conversion (value);
5714 }
5715 else if (TREE_CODE (TREE_TYPE (value)) == REFERENCE_TYPE)
5716 /* However, even for class types, we still need to strip away
5717 the reference type, since the call to convert_force below
5718 does not expect the input expression to be of reference
5719 type. */
5720 value = convert_from_reference (value);
5798 since we don't want the array-to-pointer conversion done. */
5799 if (!IS_AGGR_TYPE (type))
5800 {
5801 if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE
5802 || (TREE_CODE (TREE_TYPE (value)) == METHOD_TYPE
5803 /* Don't do the default conversion on a ->* expression. */
5804 && ! (TREE_CODE (type) == POINTER_TYPE
5805 && bound_pmf_p (value)))
5806 || TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
5807 || TREE_CODE (TREE_TYPE (value)) == REFERENCE_TYPE)
5808 value = default_conversion (value);
5809 }
5810 else if (TREE_CODE (TREE_TYPE (value)) == REFERENCE_TYPE)
5811 /* However, even for class types, we still need to strip away
5812 the reference type, since the call to convert_force below
5813 does not expect the input expression to be of reference
5814 type. */
5815 value = convert_from_reference (value);
5721
5816
5722 otype = TREE_TYPE (value);
5817 otype = TREE_TYPE (value);
5723
5818
5724 /* Optionally warn about potentially worrisome casts. */
5819 /* Optionally warn about potentially worrisome casts. */
5725
5820
5726 if (warn_cast_qual
5727 && TREE_CODE (type) == POINTER_TYPE
5728 && TREE_CODE (otype) == POINTER_TYPE)
5729 {
5730 /* For C++ we make these regular warnings, rather than
5731 softening them into pedwarns. */
5732 if (TYPE_VOLATILE (TREE_TYPE (otype))
5733 && ! TYPE_VOLATILE (TREE_TYPE (type)))
5734 warning ("cast discards `volatile' from pointer target type");
5735 if (TYPE_READONLY (TREE_TYPE (otype))
5736 && ! TYPE_READONLY (TREE_TYPE (type)))
5737 warning ("cast discards `const' from pointer target type");
5738 }
5821 if (warn_cast_qual
5822 && TREE_CODE (type) == POINTER_TYPE
5823 && TREE_CODE (otype) == POINTER_TYPE
5824 && !at_least_as_qualified_p (TREE_TYPE (type),
5825 TREE_TYPE (otype)))
5826 cp_warning ("cast discards qualifiers from pointer target type");
5739
5827
5740 /* Warn about possible alignment problems. */
5741 if (STRICT_ALIGNMENT && warn_cast_align
5742 && TREE_CODE (type) == POINTER_TYPE
5743 && TREE_CODE (otype) == POINTER_TYPE
5744 && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
5745 && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
5746 && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype)))
5747 warning ("cast increases required alignment of target type");
5828 /* Warn about possible alignment problems. */
5829 if (STRICT_ALIGNMENT && warn_cast_align
5830 && TREE_CODE (type) == POINTER_TYPE
5831 && TREE_CODE (otype) == POINTER_TYPE
5832 && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
5833 && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
5834 && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype)))
5835 warning ("cast increases required alignment of target type");
5748
5749#if 0
5836
5837#if 0
5750 /* We should see about re-enabling these, they seem useful to
5751 me. */
5752 if (TREE_CODE (type) == INTEGER_TYPE
5753 && TREE_CODE (otype) == POINTER_TYPE
5754 && TYPE_PRECISION (type) != TYPE_PRECISION (otype))
5755 warning ("cast from pointer to integer of different size");
5838 /* We should see about re-enabling these, they seem useful to
5839 me. */
5840 if (TREE_CODE (type) == INTEGER_TYPE
5841 && TREE_CODE (otype) == POINTER_TYPE
5842 && TYPE_PRECISION (type) != TYPE_PRECISION (otype))
5843 warning ("cast from pointer to integer of different size");
5756
5844
5757 if (TREE_CODE (type) == POINTER_TYPE
5758 && TREE_CODE (otype) == INTEGER_TYPE
5759 && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
5760 /* Don't warn about converting 0 to pointer,
5761 provided the 0 was explicit--not cast or made by folding. */
5762 && !(TREE_CODE (value) == INTEGER_CST && integer_zerop (value)))
5763 warning ("cast to pointer from integer of different size");
5845 if (TREE_CODE (type) == POINTER_TYPE
5846 && TREE_CODE (otype) == INTEGER_TYPE
5847 && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
5848 /* Don't warn about converting 0 to pointer,
5849 provided the 0 was explicit--not cast or made by folding. */
5850 && !(TREE_CODE (value) == INTEGER_CST && integer_zerop (value)))
5851 warning ("cast to pointer from integer of different size");
5764#endif
5765
5852#endif
5853
5766 if (TREE_CODE (type) == REFERENCE_TYPE)
5767 value = (convert_from_reference
5768 (convert_to_reference (type, value, CONV_C_CAST,
5769 LOOKUP_COMPLAIN, NULL_TREE)));
5770 else
5771 {
5772 tree ovalue;
5854 if (TREE_CODE (type) == VOID_TYPE)
5855 {
5856 value = require_complete_type_in_void (value);
5857 if (value != error_mark_node)
5858 value = build1 (CONVERT_EXPR, void_type_node, value);
5859 }
5860 else if (TREE_CODE (type) == REFERENCE_TYPE)
5861 value = (convert_from_reference
5862 (convert_to_reference (type, value, CONV_C_CAST,
5863 LOOKUP_COMPLAIN, NULL_TREE)));
5864 else
5865 {
5866 tree ovalue;
5773
5867
5774 if (TREE_READONLY_DECL_P (value))
5775 value = decl_constant_value (value);
5868 if (TREE_READONLY_DECL_P (value))
5869 value = decl_constant_value (value);
5776
5870
5777 ovalue = value;
5778 value = convert_force (type, value, CONV_C_CAST);
5871 ovalue = value;
5872 value = convert_force (type, value, CONV_C_CAST);
5779
5873
5780 /* Ignore any integer overflow caused by the cast. */
5781 if (TREE_CODE (value) == INTEGER_CST)
5782 {
5783 TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
5784 TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (ovalue);
5785 }
5874 /* Ignore any integer overflow caused by the cast. */
5875 if (TREE_CODE (value) == INTEGER_CST)
5876 {
5877 TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
5878 TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (ovalue);
5786 }
5787 }
5788
5789 /* Always produce some operator for an explicit cast,
5790 so we can tell (for -pedantic) that the cast is no lvalue. */
5791 if (TREE_CODE (type) != REFERENCE_TYPE && value == expr
5792 && real_lvalue_p (value))
5793 value = non_lvalue (value);

--- 110 unchanged lines hidden (view full) ---

5904 }
5905 }
5906 else
5907 lhs = resolve_offset_ref (lhs);
5908
5909 olhstype = lhstype = TREE_TYPE (lhs);
5910 }
5911
5879 }
5880 }
5881
5882 /* Always produce some operator for an explicit cast,
5883 so we can tell (for -pedantic) that the cast is no lvalue. */
5884 if (TREE_CODE (type) != REFERENCE_TYPE && value == expr
5885 && real_lvalue_p (value))
5886 value = non_lvalue (value);

--- 110 unchanged lines hidden (view full) ---

5997 }
5998 }
5999 else
6000 lhs = resolve_offset_ref (lhs);
6001
6002 olhstype = lhstype = TREE_TYPE (lhs);
6003 }
6004
6005 if (lhs == error_mark_node)
6006 return lhs;
6007
5912 if (TREE_CODE (lhstype) == REFERENCE_TYPE
5913 && modifycode != INIT_EXPR)
5914 {
5915 lhs = convert_from_reference (lhs);
5916 olhstype = lhstype = TREE_TYPE (lhs);
5917 }
5918
5919 /* If a binary op has been requested, combine the old LHS value with the RHS

--- 30 unchanged lines hidden (view full) ---

5950 }
5951 else if (PROMOTES_TO_AGGR_TYPE (lhstype, REFERENCE_TYPE))
5952 {
5953 my_friendly_abort (978652);
5954 }
5955 else
5956 {
5957 lhs = stabilize_reference (lhs);
6008 if (TREE_CODE (lhstype) == REFERENCE_TYPE
6009 && modifycode != INIT_EXPR)
6010 {
6011 lhs = convert_from_reference (lhs);
6012 olhstype = lhstype = TREE_TYPE (lhs);
6013 }
6014
6015 /* If a binary op has been requested, combine the old LHS value with the RHS

--- 30 unchanged lines hidden (view full) ---

6046 }
6047 else if (PROMOTES_TO_AGGR_TYPE (lhstype, REFERENCE_TYPE))
6048 {
6049 my_friendly_abort (978652);
6050 }
6051 else
6052 {
6053 lhs = stabilize_reference (lhs);
5958 newrhs = build_binary_op (modifycode, lhs, rhs, 1);
6054 newrhs = build_binary_op (modifycode, lhs, rhs);
5959 if (newrhs == error_mark_node)
5960 {
5961 cp_error (" in evaluation of `%Q(%#T, %#T)'", modifycode,
5962 TREE_TYPE (lhs), TREE_TYPE (rhs));
5963 return error_mark_node;
5964 }
5965 }
5966

--- 50 unchanged lines hidden (view full) ---

6017 /* Warn about storing in something that is `const'. */
6018 /* For C++, don't warn if this is initialization. */
6019 if (modifycode != INIT_EXPR
6020 /* For assignment to `const' signature pointer/reference fields,
6021 don't warn either, we already printed a better message before. */
6022 && ! (TREE_CODE (lhs) == COMPONENT_REF
6023 && (IS_SIGNATURE_POINTER (TREE_TYPE (TREE_OPERAND (lhs, 0)))
6024 || IS_SIGNATURE_REFERENCE (TREE_TYPE (TREE_OPERAND (lhs, 0)))))
6055 if (newrhs == error_mark_node)
6056 {
6057 cp_error (" in evaluation of `%Q(%#T, %#T)'", modifycode,
6058 TREE_TYPE (lhs), TREE_TYPE (rhs));
6059 return error_mark_node;
6060 }
6061 }
6062

--- 50 unchanged lines hidden (view full) ---

6113 /* Warn about storing in something that is `const'. */
6114 /* For C++, don't warn if this is initialization. */
6115 if (modifycode != INIT_EXPR
6116 /* For assignment to `const' signature pointer/reference fields,
6117 don't warn either, we already printed a better message before. */
6118 && ! (TREE_CODE (lhs) == COMPONENT_REF
6119 && (IS_SIGNATURE_POINTER (TREE_TYPE (TREE_OPERAND (lhs, 0)))
6120 || IS_SIGNATURE_REFERENCE (TREE_TYPE (TREE_OPERAND (lhs, 0)))))
6025 && (TREE_READONLY (lhs) || TYPE_READONLY (lhstype)
6121 && (TREE_READONLY (lhs) || CP_TYPE_CONST_P (lhstype)
6122 /* Functions are not modifiable, even though they are
6123 lvalues. */
6124 || TREE_CODE (TREE_TYPE (lhs)) == FUNCTION_TYPE
6026 || ((TREE_CODE (lhstype) == RECORD_TYPE
6027 || TREE_CODE (lhstype) == UNION_TYPE)
6028 && C_TYPE_FIELDS_READONLY (lhstype))
6029 || (TREE_CODE (lhstype) == REFERENCE_TYPE
6125 || ((TREE_CODE (lhstype) == RECORD_TYPE
6126 || TREE_CODE (lhstype) == UNION_TYPE)
6127 && C_TYPE_FIELDS_READONLY (lhstype))
6128 || (TREE_CODE (lhstype) == REFERENCE_TYPE
6030 && TYPE_READONLY (TREE_TYPE (lhstype)))))
6129 && CP_TYPE_CONST_P (TREE_TYPE (lhstype)))))
6031 readonly_error (lhs, "assignment", 0);
6032
6033 /* If storing into a structure or union member,
6034 it has probably been given type `int'.
6035 Compute the type that would go with
6036 the actual amount of storage the member occupies. */
6037
6038 if (TREE_CODE (lhs) == COMPONENT_REF

--- 19 unchanged lines hidden (view full) ---

6058 if (flag_this_is_variable > 0
6059 && DECL_NAME (current_function_decl) != NULL_TREE
6060 && (DECL_NAME (current_function_decl)
6061 != constructor_name (current_class_type)))
6062 warning ("assignment to `this' not in constructor or destructor");
6063 current_function_just_assigned_this = 1;
6064 }
6065
6130 readonly_error (lhs, "assignment", 0);
6131
6132 /* If storing into a structure or union member,
6133 it has probably been given type `int'.
6134 Compute the type that would go with
6135 the actual amount of storage the member occupies. */
6136
6137 if (TREE_CODE (lhs) == COMPONENT_REF

--- 19 unchanged lines hidden (view full) ---

6157 if (flag_this_is_variable > 0
6158 && DECL_NAME (current_function_decl) != NULL_TREE
6159 && (DECL_NAME (current_function_decl)
6160 != constructor_name (current_class_type)))
6161 warning ("assignment to `this' not in constructor or destructor");
6162 current_function_just_assigned_this = 1;
6163 }
6164
6066 /* The TREE_TYPE of RHS may be TYPE_UNKNOWN. This can happen
6067 when the type of RHS is not yet known, i.e. its type
6068 is inherited from LHS. */
6069 rhs = require_instantiated_type (lhstype, newrhs, error_mark_node);
6070 if (rhs == error_mark_node)
6071 return error_mark_node;
6072 newrhs = rhs;
6073
6074 if (modifycode != INIT_EXPR)
6075 {
6076 /* Make modifycode now either a NOP_EXPR or an INIT_EXPR. */
6077 modifycode = NOP_EXPR;
6078 /* Reference-bashing */
6079 if (TREE_CODE (lhstype) == REFERENCE_TYPE)
6080 {
6081 tree tmp = convert_from_reference (lhs);

--- 24 unchanged lines hidden (view full) ---

6106 newrhs = stabilize_reference (newrhs);
6107
6108 /* Convert new value to destination type. */
6109
6110 if (TREE_CODE (lhstype) == ARRAY_TYPE)
6111 {
6112 int from_array;
6113
6165 if (modifycode != INIT_EXPR)
6166 {
6167 /* Make modifycode now either a NOP_EXPR or an INIT_EXPR. */
6168 modifycode = NOP_EXPR;
6169 /* Reference-bashing */
6170 if (TREE_CODE (lhstype) == REFERENCE_TYPE)
6171 {
6172 tree tmp = convert_from_reference (lhs);

--- 24 unchanged lines hidden (view full) ---

6197 newrhs = stabilize_reference (newrhs);
6198
6199 /* Convert new value to destination type. */
6200
6201 if (TREE_CODE (lhstype) == ARRAY_TYPE)
6202 {
6203 int from_array;
6204
6114 if (! comptypes (lhstype, TREE_TYPE (rhs), 0))
6205 if (!same_or_base_type_p (lhstype, TREE_TYPE (rhs)))
6115 {
6116 cp_error ("incompatible types in assignment of `%T' to `%T'",
6117 TREE_TYPE (rhs), lhstype);
6118 return error_mark_node;
6119 }
6120
6121 /* Allow array assignment in compiler-generated code. */
6122 if (pedantic && ! DECL_ARTIFICIAL (current_function_decl))

--- 143 unchanged lines hidden (view full) ---

6266 tree rval = build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL, lhs, rhs,
6267 make_node (modifycode));
6268 if (rval)
6269 return rval;
6270 }
6271 return build_modify_expr (lhs, modifycode, rhs);
6272}
6273
6206 {
6207 cp_error ("incompatible types in assignment of `%T' to `%T'",
6208 TREE_TYPE (rhs), lhstype);
6209 return error_mark_node;
6210 }
6211
6212 /* Allow array assignment in compiler-generated code. */
6213 if (pedantic && ! DECL_ARTIFICIAL (current_function_decl))

--- 143 unchanged lines hidden (view full) ---

6357 tree rval = build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL, lhs, rhs,
6358 make_node (modifycode));
6359 if (rval)
6360 return rval;
6361 }
6362 return build_modify_expr (lhs, modifycode, rhs);
6363}
6364
6274/* Return 0 if EXP is not a valid lvalue in this language
6275 even though `lvalue_or_else' would accept it. */
6276
6277int
6278language_lvalue_valid (exp)
6279 tree exp ATTRIBUTE_UNUSED;
6280{
6281 return 1;
6282}
6283
6284/* Get difference in deltas for different pointer to member function
6285 types. Return integer_zero_node, if FROM cannot be converted to a
6365
6366/* Get difference in deltas for different pointer to member function
6367 types. Return integer_zero_node, if FROM cannot be converted to a
6286 TO type. If FORCE is true, then allow reverse conversions as well. */
6368 TO type. If FORCE is true, then allow reverse conversions as well.
6287
6369
6370 Note that the naming of FROM and TO is kind of backwards; the return
6371 value is what we add to a TO in order to get a FROM. They are named
6372 this way because we call this function to find out how to convert from
6373 a pointer to member of FROM to a pointer to member of TO. */
6374
6288static tree
6289get_delta_difference (from, to, force)
6290 tree from, to;
6291 int force;
6292{
6293 tree delta = integer_zero_node;
6294 tree binfo;
6295

--- 30 unchanged lines hidden (view full) ---

6326 BINFO_TYPE (binfo));
6327 warning (" will only work if you are very careful");
6328 }
6329 delta = BINFO_OFFSET (binfo);
6330 delta = cp_convert (ptrdiff_type_node, delta);
6331
6332 return build_binary_op (MINUS_EXPR,
6333 integer_zero_node,
6375static tree
6376get_delta_difference (from, to, force)
6377 tree from, to;
6378 int force;
6379{
6380 tree delta = integer_zero_node;
6381 tree binfo;
6382

--- 30 unchanged lines hidden (view full) ---

6413 BINFO_TYPE (binfo));
6414 warning (" will only work if you are very careful");
6415 }
6416 delta = BINFO_OFFSET (binfo);
6417 delta = cp_convert (ptrdiff_type_node, delta);
6418
6419 return build_binary_op (MINUS_EXPR,
6420 integer_zero_node,
6334 delta, 1);
6421 delta);
6335 }
6336
6337 if (TREE_VIA_VIRTUAL (binfo))
6338 {
6339 if (force)
6340 {
6341 cp_warning ("pointer to member cast from virtual base `%T'",
6342 BINFO_TYPE (binfo));
6343 warning (" will only work if you are very careful");
6344 }
6345 else
6346 cp_error ("pointer to member conversion from virtual base `%T'",
6347 BINFO_TYPE (binfo));
6348 }
6349
6350 return BINFO_OFFSET (binfo);
6351}
6352
6422 }
6423
6424 if (TREE_VIA_VIRTUAL (binfo))
6425 {
6426 if (force)
6427 {
6428 cp_warning ("pointer to member cast from virtual base `%T'",
6429 BINFO_TYPE (binfo));
6430 warning (" will only work if you are very careful");
6431 }
6432 else
6433 cp_error ("pointer to member conversion from virtual base `%T'",
6434 BINFO_TYPE (binfo));
6435 }
6436
6437 return BINFO_OFFSET (binfo);
6438}
6439
6353static tree
6440tree
6354build_ptrmemfunc1 (type, delta, idx, pfn, delta2)
6355 tree type, delta, idx, pfn, delta2;
6356{
6357 tree u;
6358
6359#if 0
6360 /* This is the old way we did it. We want to avoid calling
6361 digest_init, so that it can give an error if we use { } when

--- 72 unchanged lines hidden (view full) ---

6434
6435 Return error_mark_node, if something goes wrong. */
6436
6437tree
6438build_ptrmemfunc (type, pfn, force)
6439 tree type, pfn;
6440 int force;
6441{
6441build_ptrmemfunc1 (type, delta, idx, pfn, delta2)
6442 tree type, delta, idx, pfn, delta2;
6443{
6444 tree u;
6445
6446#if 0
6447 /* This is the old way we did it. We want to avoid calling
6448 digest_init, so that it can give an error if we use { } when

--- 72 unchanged lines hidden (view full) ---

6521
6522 Return error_mark_node, if something goes wrong. */
6523
6524tree
6525build_ptrmemfunc (type, pfn, force)
6526 tree type, pfn;
6527 int force;
6528{
6442 tree idx = integer_zero_node;
6443 tree delta = integer_zero_node;
6444 tree delta2 = integer_zero_node;
6445 tree vfield_offset;
6446 tree npfn = NULL_TREE;
6447
6529 tree fn;
6530
6448 /* Handle multiple conversions of pointer to member functions. */
6449 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (pfn)))
6450 {
6531 /* Handle multiple conversions of pointer to member functions. */
6532 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (pfn)))
6533 {
6534 tree idx = integer_zero_node;
6535 tree delta = integer_zero_node;
6536 tree delta2 = integer_zero_node;
6537 tree npfn = NULL_TREE;
6451 tree ndelta, ndelta2;
6452 tree e1, e2, e3, n;
6453 tree pfn_type;
6454
6455 /* Is is already the right type? */
6456 if (type == TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn)))
6457 return pfn;
6458
6459 pfn_type = TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn));
6460 if (!force
6538 tree ndelta, ndelta2;
6539 tree e1, e2, e3, n;
6540 tree pfn_type;
6541
6542 /* Is is already the right type? */
6543 if (type == TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn)))
6544 return pfn;
6545
6546 pfn_type = TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn));
6547 if (!force
6461 && comp_target_types (type, pfn_type, 0) != 1)
6548 && comp_target_types (type, pfn_type, 1) != 1)
6462 cp_error ("conversion to `%T' from `%T'", type, pfn_type);
6463
6549 cp_error ("conversion to `%T' from `%T'", type, pfn_type);
6550
6464 ndelta = cp_convert (ptrdiff_type_node, build_component_ref (pfn, delta_identifier, NULL_TREE, 0));
6465 ndelta2 = cp_convert (ptrdiff_type_node, DELTA2_FROM_PTRMEMFUNC (pfn));
6466 idx = build_component_ref (pfn, index_identifier, NULL_TREE, 0);
6551 if (TREE_CODE (pfn) == PTRMEM_CST)
6552 {
6553 /* We could just build the resulting CONSTRUCTOR now, but we
6554 don't, relying on the general machinery below, together
6555 with constant-folding, to do the right thing. We don't
6556 want to return a PTRMEM_CST here, even though we could,
6557 because a pointer-to-member constant ceases to be a
6558 constant (from the point of view of the language) when it
6559 is cast to another type. */
6467
6560
6561 expand_ptrmemfunc_cst (pfn, &ndelta, &idx, &npfn, &ndelta2);
6562 if (npfn)
6563 /* This constant points to a non-virtual function.
6564 NDELTA2 will be NULL, but it's value doesn't really
6565 matter since we won't use it anyhow. */
6566 ndelta2 = integer_zero_node;
6567 }
6568 else
6569 {
6570 ndelta = cp_convert (ptrdiff_type_node,
6571 build_component_ref (pfn,
6572 delta_identifier,
6573 NULL_TREE, 0));
6574 ndelta2 = cp_convert (ptrdiff_type_node,
6575 DELTA2_FROM_PTRMEMFUNC (pfn));
6576 idx = build_component_ref (pfn, index_identifier, NULL_TREE, 0);
6577 }
6578
6468 n = get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (pfn_type)),
6469 TYPE_METHOD_BASETYPE (TREE_TYPE (type)),
6470 force);
6579 n = get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (pfn_type)),
6580 TYPE_METHOD_BASETYPE (TREE_TYPE (type)),
6581 force);
6471
6472 delta = build_binary_op (PLUS_EXPR, ndelta, n, 1);
6473 delta2 = build_binary_op (PLUS_EXPR, ndelta2, n, 1);
6582 delta = build_binary_op (PLUS_EXPR, ndelta, n);
6583 delta2 = build_binary_op (PLUS_EXPR, ndelta2, n);
6474 e1 = fold (build (GT_EXPR, boolean_type_node, idx, integer_zero_node));
6475
6584 e1 = fold (build (GT_EXPR, boolean_type_node, idx, integer_zero_node));
6585
6586 /* If it's a virtual function, this is what we want. */
6476 e2 = build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type), delta, idx,
6477 NULL_TREE, delta2);
6478
6479 pfn = PFN_FROM_PTRMEMFUNC (pfn);
6480 npfn = build1 (NOP_EXPR, type, pfn);
6481 TREE_CONSTANT (npfn) = TREE_CONSTANT (pfn);
6482
6587 e2 = build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type), delta, idx,
6588 NULL_TREE, delta2);
6589
6590 pfn = PFN_FROM_PTRMEMFUNC (pfn);
6591 npfn = build1 (NOP_EXPR, type, pfn);
6592 TREE_CONSTANT (npfn) = TREE_CONSTANT (pfn);
6593
6483 e3 = build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type), delta, idx, npfn,
6484 NULL_TREE);
6594 /* But if it's a non-virtual function, or NULL, we use this
6595 instead. */
6596 e3 = build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type), delta,
6597 idx, npfn, NULL_TREE);
6485 return build_conditional_expr (e1, e2, e3);
6486 }
6487
6488 /* Handle null pointer to member function conversions. */
6489 if (integer_zerop (pfn))
6490 {
6491 pfn = build_c_cast (type, integer_zero_node);
6492 return build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type),
6493 integer_zero_node, integer_zero_node,
6494 pfn, NULL_TREE);
6495 }
6496
6598 return build_conditional_expr (e1, e2, e3);
6599 }
6600
6601 /* Handle null pointer to member function conversions. */
6602 if (integer_zerop (pfn))
6603 {
6604 pfn = build_c_cast (type, integer_zero_node);
6605 return build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type),
6606 integer_zero_node, integer_zero_node,
6607 pfn, NULL_TREE);
6608 }
6609
6497 if (TREE_CODE (pfn) == TREE_LIST
6498 || (TREE_CODE (pfn) == ADDR_EXPR
6499 && TREE_CODE (TREE_OPERAND (pfn, 0)) == TREE_LIST))
6610 if (type_unknown_p (pfn))
6500 return instantiate_type (type, pfn, 1);
6501
6611 return instantiate_type (type, pfn, 1);
6612
6502 if (!force
6503 && comp_target_types (type, TREE_TYPE (pfn), 0) != 1)
6504 cp_error ("conversion to `%T' from `%T'", type, TREE_TYPE (pfn));
6613 fn = TREE_OPERAND (pfn, 0);
6614 my_friendly_assert (TREE_CODE (fn) == FUNCTION_DECL, 0);
6615 return make_ptrmem_cst (build_ptrmemfunc_type (type), fn);
6616}
6505
6617
6506 /* Allow pointer to member conversions here. */
6507 delta = get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TREE_TYPE (pfn))),
6508 TYPE_METHOD_BASETYPE (TREE_TYPE (type)),
6509 force);
6510 delta2 = build_binary_op (PLUS_EXPR, delta2, delta, 1);
6618/* Return the DELTA, IDX, PFN, and DELTA2 values for the PTRMEM_CST
6619 given by CST. */
6511
6620
6512 if (TREE_CODE (TREE_OPERAND (pfn, 0)) != FUNCTION_DECL)
6513 warning ("assuming pointer to member function is non-virtual");
6621void
6622expand_ptrmemfunc_cst (cst, delta, idx, pfn, delta2)
6623 tree cst;
6624 tree *delta;
6625 tree *idx;
6626 tree *pfn;
6627 tree *delta2;
6628{
6629 tree type = TREE_TYPE (cst);
6630 tree fn = PTRMEM_CST_MEMBER (cst);
6631 tree ptr_class, fn_class;
6514
6632
6515 if (TREE_CODE (TREE_OPERAND (pfn, 0)) == FUNCTION_DECL
6516 && DECL_VINDEX (TREE_OPERAND (pfn, 0)))
6517 {
6518 /* Find the offset to the vfield pointer in the object. */
6519 vfield_offset = get_binfo (DECL_CONTEXT (TREE_OPERAND (pfn, 0)),
6520 DECL_CLASS_CONTEXT (TREE_OPERAND (pfn, 0)),
6521 0);
6522 vfield_offset = get_vfield_offset (vfield_offset);
6523 delta2 = size_binop (PLUS_EXPR, vfield_offset, delta2);
6633 my_friendly_assert (TREE_CODE (fn) == FUNCTION_DECL, 0);
6524
6634
6525 /* Map everything down one to make room for the null pointer to member. */
6526 idx = size_binop (PLUS_EXPR,
6527 DECL_VINDEX (TREE_OPERAND (pfn, 0)),
6528 integer_one_node);
6635 /* The class that the function belongs to. */
6636 fn_class = DECL_CLASS_CONTEXT (fn);
6637
6638 /* The class that we're creating a pointer to member of. */
6639 ptr_class = TYPE_PTRMEMFUNC_OBJECT_TYPE (type);
6640
6641 /* First, calculate the adjustment to the function's class. */
6642 *delta = get_delta_difference (fn_class, ptr_class, /*force=*/0);
6643
6644 if (!DECL_VIRTUAL_P (fn))
6645 {
6646 *idx = size_binop (MINUS_EXPR, integer_zero_node, integer_one_node);
6647 *pfn = convert (TYPE_PTRMEMFUNC_FN_TYPE (type), build_addr_func (fn));
6648 *delta2 = NULL_TREE;
6529 }
6530 else
6531 {
6649 }
6650 else
6651 {
6532 idx = size_binop (MINUS_EXPR, integer_zero_node, integer_one_node);
6652 /* If we're dealing with a virtual function, we have to adjust 'this'
6653 again, to point to the base which provides the vtable entry for
6654 fn; the call will do the opposite adjustment. */
6655 tree orig_class = DECL_VIRTUAL_CONTEXT (fn);
6656 tree binfo = binfo_or_else (orig_class, fn_class);
6657 *delta = size_binop (PLUS_EXPR, *delta, BINFO_OFFSET (binfo));
6533
6658
6534 if (type == TREE_TYPE (pfn))
6535 {
6536 npfn = pfn;
6537 }
6538 else
6539 {
6540 npfn = build1 (NOP_EXPR, type, pfn);
6541 TREE_CONSTANT (npfn) = TREE_CONSTANT (pfn);
6542 }
6659 /* Map everything down one to make room for the null PMF. */
6660 *idx = size_binop (PLUS_EXPR, DECL_VINDEX (fn), integer_one_node);
6661 *pfn = NULL_TREE;
6662
6663 /* Offset from an object of PTR_CLASS to the vptr for ORIG_CLASS. */
6664 *delta2 = size_binop (PLUS_EXPR, *delta,
6665 get_vfield_offset (TYPE_BINFO (orig_class)));
6543 }
6666 }
6667}
6544
6668
6545 return build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type), delta, idx, npfn, delta2);
6669/* Return an expression for DELTA2 from the pointer-to-member function
6670 given by T. */
6671
6672tree
6673delta2_from_ptrmemfunc (t)
6674 tree t;
6675{
6676 if (TREE_CODE (t) == PTRMEM_CST)
6677 {
6678 tree delta;
6679 tree idx;
6680 tree pfn;
6681 tree delta2;
6682
6683 expand_ptrmemfunc_cst (t, &delta, &idx, &pfn, &delta2);
6684 if (delta2)
6685 return delta2;
6686 }
6687
6688 return (build_component_ref
6689 (build_component_ref (t,
6690 pfn_or_delta2_identifier, NULL_TREE,
6691 0),
6692 delta2_identifier, NULL_TREE, 0));
6546}
6547
6693}
6694
6695/* Return an expression for PFN from the pointer-to-member function
6696 given by T. */
6697
6698tree
6699pfn_from_ptrmemfunc (t)
6700 tree t;
6701{
6702 if (TREE_CODE (t) == PTRMEM_CST)
6703 {
6704 tree delta;
6705 tree idx;
6706 tree pfn;
6707 tree delta2;
6708
6709 expand_ptrmemfunc_cst (t, &delta, &idx, &pfn, &delta2);
6710 if (pfn)
6711 return pfn;
6712 }
6713
6714 return (build_component_ref
6715 (build_component_ref (t,
6716 pfn_or_delta2_identifier, NULL_TREE,
6717 0),
6718 pfn_identifier, NULL_TREE, 0));
6719}
6720
6548/* Convert value RHS to type TYPE as preparation for an assignment
6549 to an lvalue of type TYPE.
6550 The real work of conversion is done by `convert'.
6551 The purpose of this function is to generate error messages
6552 for assignments that are not allowed in C.
6553 ERRTYPE is a string to use in error messages:
6554 "assignment", "return", etc.
6555
6556 C++: attempts to allow `convert' to find conversions involving
6557 implicit type conversion between aggregate and scalar types
6558 as per 8.5.6 of C++ manual. Does not randomly dereference
6559 pointers to aggregates! */
6560
6561static tree
6562convert_for_assignment (type, rhs, errtype, fndecl, parmnum)
6563 tree type, rhs;
6721/* Convert value RHS to type TYPE as preparation for an assignment
6722 to an lvalue of type TYPE.
6723 The real work of conversion is done by `convert'.
6724 The purpose of this function is to generate error messages
6725 for assignments that are not allowed in C.
6726 ERRTYPE is a string to use in error messages:
6727 "assignment", "return", etc.
6728
6729 C++: attempts to allow `convert' to find conversions involving
6730 implicit type conversion between aggregate and scalar types
6731 as per 8.5.6 of C++ manual. Does not randomly dereference
6732 pointers to aggregates! */
6733
6734static tree
6735convert_for_assignment (type, rhs, errtype, fndecl, parmnum)
6736 tree type, rhs;
6564 char *errtype;
6737 const char *errtype;
6565 tree fndecl;
6566 int parmnum;
6567{
6568 register enum tree_code codel = TREE_CODE (type);
6569 register tree rhstype;
6738 tree fndecl;
6739 int parmnum;
6740{
6741 register enum tree_code codel = TREE_CODE (type);
6742 register tree rhstype;
6570 register enum tree_code coder = TREE_CODE (TREE_TYPE (rhs));
6743 register enum tree_code coder;
6571
6744
6572 if (coder == UNKNOWN_TYPE)
6573 rhs = instantiate_type (type, rhs, 1);
6574
6575 if (coder == ERROR_MARK)
6576 return error_mark_node;
6577
6578 if (codel == OFFSET_TYPE)
6745 if (codel == OFFSET_TYPE)
6579 {
6580 type = TREE_TYPE (type);
6581 codel = TREE_CODE (type);
6582 }
6746 my_friendly_abort (990505);
6583
6747
6748 if (TREE_CODE (rhs) == OFFSET_REF)
6749 rhs = resolve_offset_ref (rhs);
6750
6584 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
6585 if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
6586 rhs = TREE_OPERAND (rhs, 0);
6587
6751 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
6752 if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
6753 rhs = TREE_OPERAND (rhs, 0);
6754
6588 if (rhs == error_mark_node)
6755 if (rhs == error_mark_node || TREE_TYPE (rhs) == error_mark_node)
6589 return error_mark_node;
6756 return error_mark_node;
6590
6591 if (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node)
6592 return error_mark_node;
6593
6757 if (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node)
6758 return error_mark_node;
6759
6594 if (TREE_CODE (TREE_TYPE (rhs)) == OFFSET_TYPE)
6595 {
6596 rhs = resolve_offset_ref (rhs);
6597 if (rhs == error_mark_node)
6598 return error_mark_node;
6599 rhstype = TREE_TYPE (rhs);
6600 coder = TREE_CODE (rhstype);
6601 }
6602
6603 if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
6760 if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
6604 || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE
6605 || TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE)
6761 || is_overloaded_fn (rhs))
6606 rhs = default_conversion (rhs);
6607 else if (TREE_CODE (TREE_TYPE (rhs)) == REFERENCE_TYPE)
6608 rhs = convert_from_reference (rhs);
6609
6762 rhs = default_conversion (rhs);
6763 else if (TREE_CODE (TREE_TYPE (rhs)) == REFERENCE_TYPE)
6764 rhs = convert_from_reference (rhs);
6765
6766 /* If rhs is some sort of overloaded function, ocp_convert will either
6767 do the right thing or complain; we don't need to check anything else.
6768 So just hand off. */
6769 if (type_unknown_p (rhs))
6770 return ocp_convert (type, rhs, CONV_IMPLICIT, LOOKUP_NORMAL);
6771
6610 rhstype = TREE_TYPE (rhs);
6611 coder = TREE_CODE (rhstype);
6612
6772 rhstype = TREE_TYPE (rhs);
6773 coder = TREE_CODE (rhstype);
6774
6775 /* Issue warnings about peculiar, but legal, uses of NULL. */
6776 if (ARITHMETIC_TYPE_P (type) && rhs == null_node)
6777 cp_warning ("converting NULL to non-pointer type");
6778
6613 /* This should no longer change types on us. */
6614 if (TREE_CODE (rhs) == CONST_DECL)
6615 rhs = DECL_INITIAL (rhs);
6616 else if (TREE_READONLY_DECL_P (rhs))
6617 rhs = decl_constant_value (rhs);
6618
6779 /* This should no longer change types on us. */
6780 if (TREE_CODE (rhs) == CONST_DECL)
6781 rhs = DECL_INITIAL (rhs);
6782 else if (TREE_READONLY_DECL_P (rhs))
6783 rhs = decl_constant_value (rhs);
6784
6619 if (comptypes (type, rhstype, 1))
6785 if (same_type_p (type, rhstype))
6620 {
6621 overflow_warning (rhs);
6622 return rhs;
6623 }
6624
6625 if (coder == VOID_TYPE)
6626 {
6627 error ("void value not ignored as it ought to be");

--- 75 unchanged lines hidden (view full) ---

6703 else
6704 binfo = get_binfo (ttl, ttr, 1);
6705
6706 if (binfo == error_mark_node)
6707 return error_mark_node;
6708 if (binfo == 0)
6709 return error_not_base_type (ttl, ttr);
6710
6786 {
6787 overflow_warning (rhs);
6788 return rhs;
6789 }
6790
6791 if (coder == VOID_TYPE)
6792 {
6793 error ("void value not ignored as it ought to be");

--- 75 unchanged lines hidden (view full) ---

6869 else
6870 binfo = get_binfo (ttl, ttr, 1);
6871
6872 if (binfo == error_mark_node)
6873 return error_mark_node;
6874 if (binfo == 0)
6875 return error_not_base_type (ttl, ttr);
6876
6711 if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr))
6877 if (!at_least_as_qualified_p (ttl, ttr))
6712 {
6713 if (fndecl)
6878 {
6879 if (fndecl)
6714 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6880 cp_pedwarn ("passing `%T' as argument %P of `%D' discards qualifiers",
6715 rhstype, parmnum, fndecl);
6716 else
6881 rhstype, parmnum, fndecl);
6882 else
6717 cp_pedwarn ("%s to `%T' from `%T' discards const",
6883 cp_pedwarn ("%s to `%T' from `%T' discards qualifiers",
6718 errtype, type, rhstype);
6719 }
6884 errtype, type, rhstype);
6885 }
6720 if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr))
6721 {
6722 if (fndecl)
6723 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6724 rhstype, parmnum, fndecl);
6725 else
6726 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6727 errtype, type, rhstype);
6728 }
6729 }
6730
6731 /* Any non-function converts to a [const][volatile] void *
6732 and vice versa; otherwise, targets must be the same.
6733 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
6734 else if (TYPE_MAIN_VARIANT (ttl) == void_type_node
6735 || TYPE_MAIN_VARIANT (ttr) == void_type_node
6736 || (ctt = comp_target_types (type, rhstype, 1))

--- 27 unchanged lines hidden (view full) ---

6764 so the usual warnings are not appropriate. */
6765 else if ((TREE_CODE (ttr) != FUNCTION_TYPE && TREE_CODE (ttr) != METHOD_TYPE)
6766 || (TREE_CODE (ttl) != FUNCTION_TYPE && TREE_CODE (ttl) != METHOD_TYPE))
6767 {
6768 if (TREE_CODE (ttl) == OFFSET_TYPE
6769 && binfo_member (TYPE_OFFSET_BASETYPE (ttr),
6770 CLASSTYPE_VBASECLASSES (TYPE_OFFSET_BASETYPE (ttl))))
6771 {
6886 }
6887
6888 /* Any non-function converts to a [const][volatile] void *
6889 and vice versa; otherwise, targets must be the same.
6890 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
6891 else if (TYPE_MAIN_VARIANT (ttl) == void_type_node
6892 || TYPE_MAIN_VARIANT (ttr) == void_type_node
6893 || (ctt = comp_target_types (type, rhstype, 1))

--- 27 unchanged lines hidden (view full) ---

6921 so the usual warnings are not appropriate. */
6922 else if ((TREE_CODE (ttr) != FUNCTION_TYPE && TREE_CODE (ttr) != METHOD_TYPE)
6923 || (TREE_CODE (ttl) != FUNCTION_TYPE && TREE_CODE (ttl) != METHOD_TYPE))
6924 {
6925 if (TREE_CODE (ttl) == OFFSET_TYPE
6926 && binfo_member (TYPE_OFFSET_BASETYPE (ttr),
6927 CLASSTYPE_VBASECLASSES (TYPE_OFFSET_BASETYPE (ttl))))
6928 {
6772 sorry ("%s between pointer to members converting across virtual baseclasses", errtype);
6929 error ("%s between pointer to members converting across virtual baseclasses", errtype);
6773 return error_mark_node;
6774 }
6930 return error_mark_node;
6931 }
6775 else if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr))
6932 else if (!at_least_as_qualified_p (ttl, ttr))
6776 {
6933 {
6777 if (fndecl)
6778 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6934 if (string_conv_p (type, rhs, 1))
6935 /* converting from string constant to char *, OK. */;
6936 else if (fndecl)
6937 cp_pedwarn ("passing `%T' as argument %P of `%D' discards qualifiers",
6779 rhstype, parmnum, fndecl);
6780 else
6938 rhstype, parmnum, fndecl);
6939 else
6781 cp_pedwarn ("%s to `%T' from `%T' discards const",
6940 cp_pedwarn ("%s to `%T' from `%T' discards qualifiers",
6782 errtype, type, rhstype);
6783 }
6941 errtype, type, rhstype);
6942 }
6784 else if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr))
6785 {
6786 if (fndecl)
6787 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6788 rhstype, parmnum, fndecl);
6789 else
6790 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6791 errtype, type, rhstype);
6792 }
6793 else if (TREE_CODE (ttl) == TREE_CODE (ttr)
6794 && ! comp_target_types (type, rhstype, 1))
6795 {
6796 if (fndecl)
6797 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signedness",
6798 rhstype, parmnum, fndecl);
6799 else
6800 cp_pedwarn ("%s to `%T' from `%T' changes signedness",
6801 errtype, type, rhstype);
6802 }
6803 }
6804 }
6805 else
6806 {
6943 else if (TREE_CODE (ttl) == TREE_CODE (ttr)
6944 && ! comp_target_types (type, rhstype, 1))
6945 {
6946 if (fndecl)
6947 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signedness",
6948 rhstype, parmnum, fndecl);
6949 else
6950 cp_pedwarn ("%s to `%T' from `%T' changes signedness",
6951 errtype, type, rhstype);
6952 }
6953 }
6954 }
6955 else
6956 {
6807 int add_quals = 0, const_parity = 0, volatile_parity = 0;
6957 int add_quals = 0;
6958 int drops_quals = 0;
6808 int left_const = 1;
6809 int unsigned_parity;
6810 int nptrs = 0;
6811
6812 /* This code is basically a duplicate of comp_ptr_ttypes_real. */
6813 for (; ; ttl = TREE_TYPE (ttl), ttr = TREE_TYPE (ttr))
6814 {
6815 nptrs -= 1;
6959 int left_const = 1;
6960 int unsigned_parity;
6961 int nptrs = 0;
6962
6963 /* This code is basically a duplicate of comp_ptr_ttypes_real. */
6964 for (; ; ttl = TREE_TYPE (ttl), ttr = TREE_TYPE (ttr))
6965 {
6966 nptrs -= 1;
6816 const_parity |= (TYPE_READONLY (ttl) < TYPE_READONLY (ttr));
6817 volatile_parity |= (TYPE_VOLATILE (ttl) < TYPE_VOLATILE (ttr));
6967 drops_quals |= !at_least_as_qualified_p (ttl, ttr);
6818
6819 if (! left_const
6968
6969 if (! left_const
6820 && (TYPE_READONLY (ttl) > TYPE_READONLY (ttr)
6821 || TYPE_VOLATILE (ttl) > TYPE_VOLATILE (ttr)))
6970 && !at_least_as_qualified_p (ttr, ttl))
6822 add_quals = 1;
6823 left_const &= TYPE_READONLY (ttl);
6824
6825 if (TREE_CODE (ttl) != POINTER_TYPE
6826 || TREE_CODE (ttr) != POINTER_TYPE)
6827 break;
6828 }
6829 unsigned_parity = TREE_UNSIGNED (ttl) - TREE_UNSIGNED (ttr);

--- 11 unchanged lines hidden (view full) ---

6841 {
6842 if (fndecl)
6843 cp_pedwarn ("passing `%T' as argument %P of `%D' adds cv-quals without intervening `const'",
6844 rhstype, parmnum, fndecl);
6845 else
6846 cp_pedwarn ("%s to `%T' from `%T' adds cv-quals without intervening `const'",
6847 errtype, type, rhstype);
6848 }
6971 add_quals = 1;
6972 left_const &= TYPE_READONLY (ttl);
6973
6974 if (TREE_CODE (ttl) != POINTER_TYPE
6975 || TREE_CODE (ttr) != POINTER_TYPE)
6976 break;
6977 }
6978 unsigned_parity = TREE_UNSIGNED (ttl) - TREE_UNSIGNED (ttr);

--- 11 unchanged lines hidden (view full) ---

6990 {
6991 if (fndecl)
6992 cp_pedwarn ("passing `%T' as argument %P of `%D' adds cv-quals without intervening `const'",
6993 rhstype, parmnum, fndecl);
6994 else
6995 cp_pedwarn ("%s to `%T' from `%T' adds cv-quals without intervening `const'",
6996 errtype, type, rhstype);
6997 }
6849 if (const_parity)
6998 if (drops_quals)
6850 {
6851 if (fndecl)
6999 {
7000 if (fndecl)
6852 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
7001 cp_pedwarn ("passing `%T' as argument %P of `%D' discards qualifiers",
6853 rhstype, parmnum, fndecl);
6854 else
7002 rhstype, parmnum, fndecl);
7003 else
6855 cp_pedwarn ("%s to `%T' from `%T' discards const",
7004 cp_pedwarn ("%s to `%T' from `%T' discards qualifiers",
6856 errtype, type, rhstype);
6857 }
7005 errtype, type, rhstype);
7006 }
6858 if (volatile_parity)
6859 {
6860 if (fndecl)
6861 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6862 rhstype, parmnum, fndecl);
6863 else
6864 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6865 errtype, type, rhstype);
6866 }
6867 if (unsigned_parity > 0)
6868 {
6869 if (fndecl)
6870 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signed to unsigned",
6871 rhstype, parmnum, fndecl);
6872 else
6873 cp_pedwarn ("%s to `%T' from `%T' changes signed to unsigned",
6874 errtype, type, rhstype);

--- 7 unchanged lines hidden (view full) ---

6882 cp_pedwarn ("%s to `%T' from `%T' changes unsigned to signed",
6883 errtype, type, rhstype);
6884 }
6885
6886 /* C++ is not so friendly about converting function and
6887 member function pointers as C. Emit warnings here. */
6888 if (TREE_CODE (ttl) == FUNCTION_TYPE
6889 || TREE_CODE (ttl) == METHOD_TYPE)
7007 if (unsigned_parity > 0)
7008 {
7009 if (fndecl)
7010 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signed to unsigned",
7011 rhstype, parmnum, fndecl);
7012 else
7013 cp_pedwarn ("%s to `%T' from `%T' changes signed to unsigned",
7014 errtype, type, rhstype);

--- 7 unchanged lines hidden (view full) ---

7022 cp_pedwarn ("%s to `%T' from `%T' changes unsigned to signed",
7023 errtype, type, rhstype);
7024 }
7025
7026 /* C++ is not so friendly about converting function and
7027 member function pointers as C. Emit warnings here. */
7028 if (TREE_CODE (ttl) == FUNCTION_TYPE
7029 || TREE_CODE (ttl) == METHOD_TYPE)
6890 if (! comptypes (ttl, ttr, 0))
7030 if (!same_or_base_type_p (ttl, ttr))
6891 {
6892 warning ("conflicting function types in %s:", errtype);
6893 cp_warning ("\t`%T' != `%T'", type, rhstype);
6894 }
6895 }
6896 else
6897 {
6898 if (fndecl)
6899 cp_error ("passing `%T' as argument %P of `%D'",
6900 rhstype, parmnum, fndecl);
6901 else
6902 cp_error ("%s to `%T' from `%T'", errtype, type, rhstype);
6903 return error_mark_node;
6904 }
6905 }
6906 return cp_convert (type, rhs);
6907 }
7031 {
7032 warning ("conflicting function types in %s:", errtype);
7033 cp_warning ("\t`%T' != `%T'", type, rhstype);
7034 }
7035 }
7036 else
7037 {
7038 if (fndecl)
7039 cp_error ("passing `%T' as argument %P of `%D'",
7040 rhstype, parmnum, fndecl);
7041 else
7042 cp_error ("%s to `%T' from `%T'", errtype, type, rhstype);
7043 return error_mark_node;
7044 }
7045 }
7046 return cp_convert (type, rhs);
7047 }
6908 else if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
7048 else if (codel == POINTER_TYPE
7049 && (coder == INTEGER_TYPE
7050 || coder == BOOLEAN_TYPE))
6909 {
6910 /* An explicit constant 0 can convert to a pointer,
6911 but not a 0 that results from casting or folding. */
6912 if (! (TREE_CODE (rhs) == INTEGER_CST && integer_zerop (rhs)))
6913 {
6914 if (fndecl)
6915 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6916 rhstype, parmnum, fndecl);

--- 72 unchanged lines hidden (view full) ---

6989 && TREE_TYPE (rhs)
6990 && TYPE_PTRMEMFUNC_P (TREE_TYPE (rhs)))
6991 return cp_convert (type, rhs);
6992
6993 cp_error ("%s to `%T' from `%T'", errtype, type, rhstype);
6994 return error_mark_node;
6995}
6996
7051 {
7052 /* An explicit constant 0 can convert to a pointer,
7053 but not a 0 that results from casting or folding. */
7054 if (! (TREE_CODE (rhs) == INTEGER_CST && integer_zerop (rhs)))
7055 {
7056 if (fndecl)
7057 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
7058 rhstype, parmnum, fndecl);

--- 72 unchanged lines hidden (view full) ---

7131 && TREE_TYPE (rhs)
7132 && TYPE_PTRMEMFUNC_P (TREE_TYPE (rhs)))
7133 return cp_convert (type, rhs);
7134
7135 cp_error ("%s to `%T' from `%T'", errtype, type, rhstype);
7136 return error_mark_node;
7137}
7138
6997/* Convert RHS to be of type TYPE. If EXP is non-zero,
6998 it is the target of the initialization.
7139/* Convert RHS to be of type TYPE.
7140 If EXP is non-zero, it is the target of the initialization.
6999 ERRTYPE is a string to use in error messages.
7000
7001 Two major differences between the behavior of
7002 `convert_for_assignment' and `convert_for_initialization'
7003 are that references are bashed in the former, while
7004 copied in the latter, and aggregates are assigned in
7005 the former (operator=) while initialized in the
7006 latter (X(X&)).
7007
7008 If using constructor make sure no conversion operator exists, if one does
7009 exist, an ambiguity exists.
7010
7011 If flags doesn't include LOOKUP_COMPLAIN, don't complain about anything. */
7012
7013tree
7014convert_for_initialization (exp, type, rhs, flags, errtype, fndecl, parmnum)
7015 tree exp, type, rhs;
7016 int flags;
7141 ERRTYPE is a string to use in error messages.
7142
7143 Two major differences between the behavior of
7144 `convert_for_assignment' and `convert_for_initialization'
7145 are that references are bashed in the former, while
7146 copied in the latter, and aggregates are assigned in
7147 the former (operator=) while initialized in the
7148 latter (X(X&)).
7149
7150 If using constructor make sure no conversion operator exists, if one does
7151 exist, an ambiguity exists.
7152
7153 If flags doesn't include LOOKUP_COMPLAIN, don't complain about anything. */
7154
7155tree
7156convert_for_initialization (exp, type, rhs, flags, errtype, fndecl, parmnum)
7157 tree exp, type, rhs;
7158 int flags;
7017 char *errtype;
7159 const char *errtype;
7018 tree fndecl;
7019 int parmnum;
7020{
7021 register enum tree_code codel = TREE_CODE (type);
7022 register tree rhstype;
7023 register enum tree_code coder;
7024
7025 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
7026 Strip such NOP_EXPRs, since RHS is used in non-lvalue context. */
7027 if (TREE_CODE (rhs) == NOP_EXPR
7028 && TREE_TYPE (rhs) == TREE_TYPE (TREE_OPERAND (rhs, 0))
7029 && codel != REFERENCE_TYPE)
7030 rhs = TREE_OPERAND (rhs, 0);
7031
7032 if (rhs == error_mark_node
7033 || (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node))
7034 return error_mark_node;
7035
7160 tree fndecl;
7161 int parmnum;
7162{
7163 register enum tree_code codel = TREE_CODE (type);
7164 register tree rhstype;
7165 register enum tree_code coder;
7166
7167 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
7168 Strip such NOP_EXPRs, since RHS is used in non-lvalue context. */
7169 if (TREE_CODE (rhs) == NOP_EXPR
7170 && TREE_TYPE (rhs) == TREE_TYPE (TREE_OPERAND (rhs, 0))
7171 && codel != REFERENCE_TYPE)
7172 rhs = TREE_OPERAND (rhs, 0);
7173
7174 if (rhs == error_mark_node
7175 || (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node))
7176 return error_mark_node;
7177
7036 if (TREE_CODE (TREE_TYPE (rhs)) == OFFSET_TYPE)
7178 if (TREE_CODE (rhs) == OFFSET_REF)
7037 {
7038 rhs = resolve_offset_ref (rhs);
7039 if (rhs == error_mark_node)
7040 return error_mark_node;
7041 }
7042
7043 if (TREE_CODE (TREE_TYPE (rhs)) == REFERENCE_TYPE)
7044 rhs = convert_from_reference (rhs);
7045
7046 if ((TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
7047 && TREE_CODE (type) != ARRAY_TYPE
7048 && (TREE_CODE (type) != REFERENCE_TYPE
7049 || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
7179 {
7180 rhs = resolve_offset_ref (rhs);
7181 if (rhs == error_mark_node)
7182 return error_mark_node;
7183 }
7184
7185 if (TREE_CODE (TREE_TYPE (rhs)) == REFERENCE_TYPE)
7186 rhs = convert_from_reference (rhs);
7187
7188 if ((TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
7189 && TREE_CODE (type) != ARRAY_TYPE
7190 && (TREE_CODE (type) != REFERENCE_TYPE
7191 || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
7050 || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE
7192 || (TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE
7193 && (TREE_CODE (type) != REFERENCE_TYPE
7194 || TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE))
7051 || TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE)
7052 rhs = default_conversion (rhs);
7053
7054 rhstype = TREE_TYPE (rhs);
7055 coder = TREE_CODE (rhstype);
7056
7195 || TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE)
7196 rhs = default_conversion (rhs);
7197
7198 rhstype = TREE_TYPE (rhs);
7199 coder = TREE_CODE (rhstype);
7200
7057 if (coder == UNKNOWN_TYPE)
7058 {
7059 rhs = instantiate_type (type, rhs, 1);
7060 rhstype = TREE_TYPE (rhs);
7061 coder = TREE_CODE (rhstype);
7062 }
7063
7064 if (coder == ERROR_MARK)
7065 return error_mark_node;
7066
7067 /* We accept references to incomplete types, so we can
7068 return here before checking if RHS is of complete type. */
7069
7070 if (codel == REFERENCE_TYPE)
7071 {

--- 10 unchanged lines hidden (view full) ---

7082 if (warningcount > savew)
7083 cp_warning_at ("in passing argument %P of `%+D'", parmnum, fndecl);
7084 else if (errorcount > savee)
7085 cp_error_at ("in passing argument %P of `%+D'", parmnum, fndecl);
7086 }
7087 return rhs;
7088 }
7089
7201 if (coder == ERROR_MARK)
7202 return error_mark_node;
7203
7204 /* We accept references to incomplete types, so we can
7205 return here before checking if RHS is of complete type. */
7206
7207 if (codel == REFERENCE_TYPE)
7208 {

--- 10 unchanged lines hidden (view full) ---

7219 if (warningcount > savew)
7220 cp_warning_at ("in passing argument %P of `%+D'", parmnum, fndecl);
7221 else if (errorcount > savee)
7222 cp_error_at ("in passing argument %P of `%+D'", parmnum, fndecl);
7223 }
7224 return rhs;
7225 }
7226
7090 rhs = require_complete_type (rhs);
7091 if (rhs == error_mark_node)
7092 return error_mark_node;
7093
7094 if (exp != 0) exp = require_complete_type (exp);
7227 if (exp != 0)
7228 exp = require_complete_type (exp);
7095 if (exp == error_mark_node)
7096 return error_mark_node;
7097
7098 if (TREE_CODE (rhstype) == REFERENCE_TYPE)
7099 rhstype = TREE_TYPE (rhstype);
7100
7101 type = complete_type (type);
7102
7103 if (TYPE_LANG_SPECIFIC (type)
7104 && (IS_SIGNATURE_POINTER (type) || IS_SIGNATURE_REFERENCE (type)))
7105 return build_signature_pointer_constructor (type, rhs);
7106
7107 if (IS_AGGR_TYPE (type))
7108 return ocp_convert (type, rhs, CONV_IMPLICIT|CONV_FORCE_TEMP, flags);
7109
7110 if (type == TREE_TYPE (rhs))
7111 {
7229 if (exp == error_mark_node)
7230 return error_mark_node;
7231
7232 if (TREE_CODE (rhstype) == REFERENCE_TYPE)
7233 rhstype = TREE_TYPE (rhstype);
7234
7235 type = complete_type (type);
7236
7237 if (TYPE_LANG_SPECIFIC (type)
7238 && (IS_SIGNATURE_POINTER (type) || IS_SIGNATURE_REFERENCE (type)))
7239 return build_signature_pointer_constructor (type, rhs);
7240
7241 if (IS_AGGR_TYPE (type))
7242 return ocp_convert (type, rhs, CONV_IMPLICIT|CONV_FORCE_TEMP, flags);
7243
7244 if (type == TREE_TYPE (rhs))
7245 {
7246 /* Issue warnings about peculiar, but legal, uses of NULL. We
7247 do this *before* the call to decl_constant_value so as to
7248 avoid duplicate warnings on code like `const int I = NULL;
7249 f(I);'. */
7250 if (ARITHMETIC_TYPE_P (type) && rhs == null_node)
7251 cp_warning ("converting NULL to non-pointer type");
7252
7112 if (TREE_READONLY_DECL_P (rhs))
7113 rhs = decl_constant_value (rhs);
7253 if (TREE_READONLY_DECL_P (rhs))
7254 rhs = decl_constant_value (rhs);
7255
7114 return rhs;
7115 }
7116
7117 return convert_for_assignment (type, rhs, errtype, fndecl, parmnum);
7118}
7119
7120/* Expand an ASM statement with operands, handling output operands
7121 that are not variables or INDIRECT_REFS by transforming such

--- 35 unchanged lines hidden (view full) ---

7157 const0_rtx, VOIDmode, EXPAND_NORMAL);
7158 free_temp_slots ();
7159 }
7160 /* Detect modification of read-only values.
7161 (Otherwise done by build_modify_expr.) */
7162 else
7163 {
7164 tree type = TREE_TYPE (o[i]);
7256 return rhs;
7257 }
7258
7259 return convert_for_assignment (type, rhs, errtype, fndecl, parmnum);
7260}
7261
7262/* Expand an ASM statement with operands, handling output operands
7263 that are not variables or INDIRECT_REFS by transforming such

--- 35 unchanged lines hidden (view full) ---

7299 const0_rtx, VOIDmode, EXPAND_NORMAL);
7300 free_temp_slots ();
7301 }
7302 /* Detect modification of read-only values.
7303 (Otherwise done by build_modify_expr.) */
7304 else
7305 {
7306 tree type = TREE_TYPE (o[i]);
7165 if (TYPE_READONLY (type)
7307 if (CP_TYPE_CONST_P (type)
7166 || ((TREE_CODE (type) == RECORD_TYPE
7167 || TREE_CODE (type) == UNION_TYPE)
7168 && C_TYPE_FIELDS_READONLY (type)))
7169 readonly_error (o[i], "modification by `asm'", 1);
7170 }
7171 }
7172
7173 /* Those MODIFY_EXPRs could do autoincrements. */

--- 40 unchanged lines hidden (view full) ---

7214 if (retval)
7215 error ("returning a value from a destructor");
7216
7217 /* Can't just return from a destructor. */
7218 expand_goto (dtor_label);
7219 return;
7220 }
7221
7308 || ((TREE_CODE (type) == RECORD_TYPE
7309 || TREE_CODE (type) == UNION_TYPE)
7310 && C_TYPE_FIELDS_READONLY (type)))
7311 readonly_error (o[i], "modification by `asm'", 1);
7312 }
7313 }
7314
7315 /* Those MODIFY_EXPRs could do autoincrements. */

--- 40 unchanged lines hidden (view full) ---

7356 if (retval)
7357 error ("returning a value from a destructor");
7358
7359 /* Can't just return from a destructor. */
7360 expand_goto (dtor_label);
7361 return;
7362 }
7363
7364 /* Only operator new(...) throw(), can return NULL [expr.new/13]. */
7365 if ((DECL_NAME (current_function_decl) == ansi_opname[(int) NEW_EXPR]
7366 || DECL_NAME (current_function_decl) == ansi_opname[(int) VEC_NEW_EXPR])
7367 && !TYPE_NOTHROW_P (TREE_TYPE (current_function_decl))
7368 && null_ptr_cst_p (retval))
7369 cp_warning ("operator new should throw an exception, not return NULL");
7370
7222 if (retval == NULL_TREE)
7223 {
7224 /* A non-named return value does not count. */
7225
7226 if (DECL_CONSTRUCTOR_P (current_function_decl))
7227 retval = current_class_ptr;
7228 else if (DECL_NAME (result) != NULL_TREE
7229 && TREE_CODE (valtype) != VOID_TYPE)

--- 48 unchanged lines hidden (view full) ---

7278 must be cleaned up, clean them (taking care
7279 not to clobber the return value).
7280 (3) If an X(X&) constructor is defined, the return
7281 value must be returned via that. */
7282
7283 if (retval == result
7284 || DECL_CONSTRUCTOR_P (current_function_decl))
7285 /* It's already done for us. */;
7371 if (retval == NULL_TREE)
7372 {
7373 /* A non-named return value does not count. */
7374
7375 if (DECL_CONSTRUCTOR_P (current_function_decl))
7376 retval = current_class_ptr;
7377 else if (DECL_NAME (result) != NULL_TREE
7378 && TREE_CODE (valtype) != VOID_TYPE)

--- 48 unchanged lines hidden (view full) ---

7427 must be cleaned up, clean them (taking care
7428 not to clobber the return value).
7429 (3) If an X(X&) constructor is defined, the return
7430 value must be returned via that. */
7431
7432 if (retval == result
7433 || DECL_CONSTRUCTOR_P (current_function_decl))
7434 /* It's already done for us. */;
7286 else if (TREE_TYPE (retval) == void_type_node)
7435 else if (TREE_CODE (TREE_TYPE (retval)) == VOID_TYPE)
7287 {
7288 pedwarn ("return of void value in function returning non-void");
7289 expand_expr_stmt (retval);
7290 retval = 0;
7291 }
7292 else
7293 {
7294 tree functype = TREE_TYPE (TREE_TYPE (current_function_decl));

--- 51 unchanged lines hidden (view full) ---

7346 }
7347 }
7348
7349 if (TREE_CODE (whats_returned) == VAR_DECL && DECL_NAME (whats_returned))
7350 {
7351 if (TEMP_NAME_P (DECL_NAME (whats_returned)))
7352 warning ("reference to non-lvalue returned");
7353 else if (TREE_CODE (TREE_TYPE (whats_returned)) != REFERENCE_TYPE
7436 {
7437 pedwarn ("return of void value in function returning non-void");
7438 expand_expr_stmt (retval);
7439 retval = 0;
7440 }
7441 else
7442 {
7443 tree functype = TREE_TYPE (TREE_TYPE (current_function_decl));

--- 51 unchanged lines hidden (view full) ---

7495 }
7496 }
7497
7498 if (TREE_CODE (whats_returned) == VAR_DECL && DECL_NAME (whats_returned))
7499 {
7500 if (TEMP_NAME_P (DECL_NAME (whats_returned)))
7501 warning ("reference to non-lvalue returned");
7502 else if (TREE_CODE (TREE_TYPE (whats_returned)) != REFERENCE_TYPE
7354 && ! TREE_STATIC (whats_returned)
7355 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned))
7356 && !TREE_PUBLIC (whats_returned))
7503 && DECL_FUNCTION_SCOPE_P (whats_returned)
7504 && !(TREE_STATIC (whats_returned)
7505 || TREE_PUBLIC (whats_returned)))
7357 cp_warning_at ("reference to local variable `%D' returned", whats_returned);
7358 }
7359 }
7360 else if (TREE_CODE (retval) == ADDR_EXPR)
7361 {
7362 tree whats_returned = TREE_OPERAND (retval, 0);
7363
7364 if (TREE_CODE (whats_returned) == VAR_DECL
7365 && DECL_NAME (whats_returned)
7506 cp_warning_at ("reference to local variable `%D' returned", whats_returned);
7507 }
7508 }
7509 else if (TREE_CODE (retval) == ADDR_EXPR)
7510 {
7511 tree whats_returned = TREE_OPERAND (retval, 0);
7512
7513 if (TREE_CODE (whats_returned) == VAR_DECL
7514 && DECL_NAME (whats_returned)
7366 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned))
7367 && !TREE_STATIC (whats_returned)
7368 && !TREE_PUBLIC (whats_returned))
7515 && DECL_FUNCTION_SCOPE_P (whats_returned)
7516 && !(TREE_STATIC (whats_returned)
7517 || TREE_PUBLIC (whats_returned)))
7369 cp_warning_at ("address of local variable `%D' returned", whats_returned);
7370 }
7371 }
7372
7373 if (retval != NULL_TREE
7374 && TREE_CODE_CLASS (TREE_CODE (retval)) == 'd'
7375 && cond_stack == 0 && loop_stack == 0 && case_stack == 0)
7376 current_function_return_value = retval;

--- 21 unchanged lines hidden (view full) ---

7398
7399/* Start a C switch statement, testing expression EXP.
7400 Return EXP if it is valid, an error node otherwise. */
7401
7402tree
7403c_expand_start_case (exp)
7404 tree exp;
7405{
7518 cp_warning_at ("address of local variable `%D' returned", whats_returned);
7519 }
7520 }
7521
7522 if (retval != NULL_TREE
7523 && TREE_CODE_CLASS (TREE_CODE (retval)) == 'd'
7524 && cond_stack == 0 && loop_stack == 0 && case_stack == 0)
7525 current_function_return_value = retval;

--- 21 unchanged lines hidden (view full) ---

7547
7548/* Start a C switch statement, testing expression EXP.
7549 Return EXP if it is valid, an error node otherwise. */
7550
7551tree
7552c_expand_start_case (exp)
7553 tree exp;
7554{
7406 tree type;
7407 register enum tree_code code;
7555 tree type, idx;
7408
7556
7409 /* Convert from references, etc. */
7410 exp = default_conversion (exp);
7411 type = TREE_TYPE (exp);
7412 code = TREE_CODE (type);
7413
7414 if (IS_AGGR_TYPE_CODE (code))
7415 exp = build_type_conversion (CONVERT_EXPR, integer_type_node, exp, 1);
7416
7557 exp = build_expr_type_conversion (WANT_INT | WANT_ENUM, exp, 1);
7417 if (exp == NULL_TREE)
7418 {
7419 error ("switch quantity not an integer");
7420 exp = error_mark_node;
7421 }
7558 if (exp == NULL_TREE)
7559 {
7560 error ("switch quantity not an integer");
7561 exp = error_mark_node;
7562 }
7563 if (exp == error_mark_node)
7564 return error_mark_node;
7565
7566 exp = default_conversion (exp);
7422 type = TREE_TYPE (exp);
7567 type = TREE_TYPE (exp);
7423 code = TREE_CODE (type);
7568 idx = get_unwidened (exp, 0);
7569 /* We can't strip a conversion from a signed type to an unsigned,
7570 because if we did, int_fits_type_p would do the wrong thing
7571 when checking case values for being in range,
7572 and it's too hard to do the right thing. */
7573 if (TREE_UNSIGNED (TREE_TYPE (exp)) == TREE_UNSIGNED (TREE_TYPE (idx)))
7574 exp = idx;
7424
7575
7425 if (code != INTEGER_TYPE && code != ENUMERAL_TYPE && code != ERROR_MARK)
7426 {
7427 error ("switch quantity not an integer");
7428 exp = error_mark_node;
7429 }
7430 else
7431 {
7432 tree idx;
7433
7434 exp = default_conversion (exp);
7435 type = TREE_TYPE (exp);
7436 idx = get_unwidened (exp, 0);
7437 /* We can't strip a conversion from a signed type to an unsigned,
7438 because if we did, int_fits_type_p would do the wrong thing
7439 when checking case values for being in range,
7440 and it's too hard to do the right thing. */
7441 if (TREE_UNSIGNED (TREE_TYPE (exp))
7442 == TREE_UNSIGNED (TREE_TYPE (idx)))
7443 exp = idx;
7444 }
7445
7446 expand_start_case
7447 (1, fold (build1 (CLEANUP_POINT_EXPR, TREE_TYPE (exp), exp)),
7448 type, "switch statement");
7449
7450 return exp;
7451}
7452
7453/* Returns non-zero if the pointer-type FROM can be converted to the

--- 12 unchanged lines hidden (view full) ---

7466 int to_more_cv_qualified = 0;
7467
7468 for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
7469 {
7470 if (TREE_CODE (to) != TREE_CODE (from))
7471 return 0;
7472
7473 if (TREE_CODE (from) == OFFSET_TYPE
7576 expand_start_case
7577 (1, fold (build1 (CLEANUP_POINT_EXPR, TREE_TYPE (exp), exp)),
7578 type, "switch statement");
7579
7580 return exp;
7581}
7582
7583/* Returns non-zero if the pointer-type FROM can be converted to the

--- 12 unchanged lines hidden (view full) ---

7596 int to_more_cv_qualified = 0;
7597
7598 for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
7599 {
7600 if (TREE_CODE (to) != TREE_CODE (from))
7601 return 0;
7602
7603 if (TREE_CODE (from) == OFFSET_TYPE
7474 && comptypes (TYPE_OFFSET_BASETYPE (from),
7475 TYPE_OFFSET_BASETYPE (to), 1))
7604 && same_type_p (TYPE_OFFSET_BASETYPE (from),
7605 TYPE_OFFSET_BASETYPE (to)))
7476 continue;
7477
7478 /* Const and volatile mean something different for function types,
7479 so the usual checks are not appropriate. */
7480 if (TREE_CODE (to) != FUNCTION_TYPE && TREE_CODE (to) != METHOD_TYPE)
7481 {
7606 continue;
7607
7608 /* Const and volatile mean something different for function types,
7609 so the usual checks are not appropriate. */
7610 if (TREE_CODE (to) != FUNCTION_TYPE && TREE_CODE (to) != METHOD_TYPE)
7611 {
7482 if (TYPE_READONLY (from) > TYPE_READONLY (to)
7483 || TYPE_VOLATILE (from) > TYPE_VOLATILE (to))
7612 if (!at_least_as_qualified_p (to, from))
7484 return 0;
7485
7613 return 0;
7614
7486 if (TYPE_READONLY (to) > TYPE_READONLY (from)
7487 || TYPE_VOLATILE (to) > TYPE_VOLATILE (from))
7615 if (!at_least_as_qualified_p (from, to))
7488 {
7489 if (constp == 0)
7490 return 0;
7491 else
7492 ++to_more_cv_qualified;
7493 }
7494
7495 if (constp > 0)
7496 constp &= TYPE_READONLY (to);
7497 }
7498
7499 if (TREE_CODE (to) != POINTER_TYPE)
7500 return
7616 {
7617 if (constp == 0)
7618 return 0;
7619 else
7620 ++to_more_cv_qualified;
7621 }
7622
7623 if (constp > 0)
7624 constp &= TYPE_READONLY (to);
7625 }
7626
7627 if (TREE_CODE (to) != POINTER_TYPE)
7628 return
7501 comptypes (TYPE_MAIN_VARIANT (to), TYPE_MAIN_VARIANT (from), 1)
7629 same_type_p (TYPE_MAIN_VARIANT (to), TYPE_MAIN_VARIANT (from))
7502 && (constp >= 0 || to_more_cv_qualified);
7503 }
7504}
7505
7506/* When comparing, say, char ** to char const **, this function takes the
7507 'char *' and 'char const *'. Do not pass non-pointer types to this
7508 function. */
7509

--- 13 unchanged lines hidden (view full) ---

7523{
7524 for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
7525 {
7526 if (TREE_CODE (to) != TREE_CODE (from))
7527 return 0;
7528
7529 if (TREE_CODE (from) == OFFSET_TYPE
7530 && comptypes (TYPE_OFFSET_BASETYPE (to),
7630 && (constp >= 0 || to_more_cv_qualified);
7631 }
7632}
7633
7634/* When comparing, say, char ** to char const **, this function takes the
7635 'char *' and 'char const *'. Do not pass non-pointer types to this
7636 function. */
7637

--- 13 unchanged lines hidden (view full) ---

7651{
7652 for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
7653 {
7654 if (TREE_CODE (to) != TREE_CODE (from))
7655 return 0;
7656
7657 if (TREE_CODE (from) == OFFSET_TYPE
7658 && comptypes (TYPE_OFFSET_BASETYPE (to),
7531 TYPE_OFFSET_BASETYPE (from), -1))
7659 TYPE_OFFSET_BASETYPE (from),
7660 COMPARE_BASE | COMPARE_RELAXED))
7532 continue;
7533
7534 if (TREE_CODE (to) != POINTER_TYPE)
7535 return comptypes
7661 continue;
7662
7663 if (TREE_CODE (to) != POINTER_TYPE)
7664 return comptypes
7536 (TYPE_MAIN_VARIANT (to), TYPE_MAIN_VARIANT (from), -1);
7665 (TYPE_MAIN_VARIANT (to), TYPE_MAIN_VARIANT (from),
7666 COMPARE_BASE | COMPARE_RELAXED);
7537 }
7538}
7539
7540/* Like comp_ptr_ttypes, for const_cast. */
7541
7542static int
7543comp_ptr_ttypes_const (to, from)
7544 tree to, from;
7545{
7546 for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
7547 {
7548 if (TREE_CODE (to) != TREE_CODE (from))
7549 return 0;
7550
7551 if (TREE_CODE (from) == OFFSET_TYPE
7667 }
7668}
7669
7670/* Like comp_ptr_ttypes, for const_cast. */
7671
7672static int
7673comp_ptr_ttypes_const (to, from)
7674 tree to, from;
7675{
7676 for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
7677 {
7678 if (TREE_CODE (to) != TREE_CODE (from))
7679 return 0;
7680
7681 if (TREE_CODE (from) == OFFSET_TYPE
7552 && comptypes (TYPE_OFFSET_BASETYPE (from),
7553 TYPE_OFFSET_BASETYPE (to), 1))
7682 && same_type_p (TYPE_OFFSET_BASETYPE (from),
7683 TYPE_OFFSET_BASETYPE (to)))
7554 continue;
7555
7556 if (TREE_CODE (to) != POINTER_TYPE)
7684 continue;
7685
7686 if (TREE_CODE (to) != POINTER_TYPE)
7557 return comptypes (TYPE_MAIN_VARIANT (to), TYPE_MAIN_VARIANT (from), 1);
7687 return same_type_p (TYPE_MAIN_VARIANT (to),
7688 TYPE_MAIN_VARIANT (from));
7558 }
7559}
7560
7561/* Like comp_ptr_ttypes, for reinterpret_cast. */
7562
7563static int
7564comp_ptr_ttypes_reinterpret (to, from)
7565 tree to, from;
7566{
7567 int constp = 1;
7568
7569 for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
7570 {
7571 if (TREE_CODE (from) == OFFSET_TYPE)
7572 from = TREE_TYPE (from);
7573 if (TREE_CODE (to) == OFFSET_TYPE)
7574 to = TREE_TYPE (to);
7575
7689 }
7690}
7691
7692/* Like comp_ptr_ttypes, for reinterpret_cast. */
7693
7694static int
7695comp_ptr_ttypes_reinterpret (to, from)
7696 tree to, from;
7697{
7698 int constp = 1;
7699
7700 for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
7701 {
7702 if (TREE_CODE (from) == OFFSET_TYPE)
7703 from = TREE_TYPE (from);
7704 if (TREE_CODE (to) == OFFSET_TYPE)
7705 to = TREE_TYPE (to);
7706
7576 if (TREE_CODE (to) != TREE_CODE (from))
7577 return 1;
7578
7579 /* Const and volatile mean something different for function types,
7580 so the usual checks are not appropriate. */
7707 /* Const and volatile mean something different for function types,
7708 so the usual checks are not appropriate. */
7581 if (TREE_CODE (to) != FUNCTION_TYPE && TREE_CODE (to) != METHOD_TYPE)
7709 if (TREE_CODE (from) != FUNCTION_TYPE && TREE_CODE (from) != METHOD_TYPE
7710 && TREE_CODE (to) != FUNCTION_TYPE && TREE_CODE (to) != METHOD_TYPE)
7582 {
7711 {
7583 if (TYPE_READONLY (from) > TYPE_READONLY (to)
7584 || TYPE_VOLATILE (from) > TYPE_VOLATILE (to))
7712 if (!at_least_as_qualified_p (to, from))
7585 return 0;
7586
7587 if (! constp
7713 return 0;
7714
7715 if (! constp
7588 && (TYPE_READONLY (to) > TYPE_READONLY (from)
7589 || TYPE_VOLATILE (to) > TYPE_READONLY (from)))
7716 && !at_least_as_qualified_p (from, to))
7590 return 0;
7591 constp &= TYPE_READONLY (to);
7592 }
7593
7717 return 0;
7718 constp &= TYPE_READONLY (to);
7719 }
7720
7594 if (TREE_CODE (to) != POINTER_TYPE)
7721 if (TREE_CODE (from) != POINTER_TYPE
7722 || TREE_CODE (to) != POINTER_TYPE)
7595 return 1;
7596 }
7597}
7723 return 1;
7724 }
7725}
7726
7727/* Returns the type-qualifier set corresponding to TYPE. */
7728
7729int
7730cp_type_quals (type)
7731 tree type;
7732{
7733 while (TREE_CODE (type) == ARRAY_TYPE)
7734 type = TREE_TYPE (type);
7735
7736 return TYPE_QUALS (type);
7737}
7738
7739/* Returns non-zero if the TYPE contains a mutable member */
7740
7741int
7742cp_has_mutable_p (type)
7743 tree type;
7744{
7745 while (TREE_CODE (type) == ARRAY_TYPE)
7746 type = TREE_TYPE (type);
7747
7748 return CLASS_TYPE_P (type) && CLASSTYPE_HAS_MUTABLE (type);
7749}