1 /* Report error messages, build initializers, and perform
2 some front-end optimizations for C++ compiler.
3 Copyright (C) 1987, 88, 89, 92, 93, 94, 1995 Free Software Foundation, Inc.
4 Hacked by Michael Tiemann (tiemann@cygnus.com)
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 /* This file is part of the C++ front end.
25 It contains routines to build C++ expressions given their operands,
26 including computing the types of the result, C and C++ specific error
27 checks, and some optimization.
29 There are also routines to build RETURN_STMT nodes and CASE_STMT nodes,
30 and to process initializations in declarations (since they work
31 like a strange sort of assignment). */
39 static tree process_init_constructor
PROTO((tree
, tree
, tree
*));
41 extern int errorcount
;
42 extern int sorrycount
;
44 /* Print an error message stemming from an attempt to use
45 BASETYPE as a base class for TYPE. */
48 error_not_base_type (basetype
, type
)
51 if (TREE_CODE (basetype
) == FUNCTION_DECL
)
52 basetype
= DECL_CLASS_CONTEXT (basetype
);
53 cp_error ("type `%T' is not a base type for type `%T'", basetype
, type
);
54 return error_mark_node
;
58 binfo_or_else (parent_or_type
, type
)
59 tree parent_or_type
, type
;
62 if (TYPE_MAIN_VARIANT (parent_or_type
) == TYPE_MAIN_VARIANT (type
))
63 return TYPE_BINFO (parent_or_type
);
64 if ((binfo
= get_binfo (parent_or_type
, TYPE_MAIN_VARIANT (type
), 0)))
66 if (binfo
== error_mark_node
)
70 error_not_base_type (parent_or_type
, type
);
74 /* According to ARM $7.1.6, "A `const' object may be initialized, but its
75 value may not be changed thereafter. Thus, we emit hard errors for these,
76 rather than just pedwarns. If `SOFT' is 1, then we just pedwarn. (For
77 example, conversions to references.) */
80 readonly_error (arg
, string
, soft
)
93 if (TREE_CODE (arg
) == COMPONENT_REF
)
95 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg
, 0))))
96 fmt
= "%s of member `%D' in read-only structure";
98 fmt
= "%s of read-only member `%D'";
99 (*fn
) (fmt
, string
, TREE_OPERAND (arg
, 1));
101 else if (TREE_CODE (arg
) == VAR_DECL
)
103 if (DECL_LANG_SPECIFIC (arg
)
104 && DECL_IN_AGGR_P (arg
)
105 && !TREE_STATIC (arg
))
106 fmt
= "%s of constant field `%D'";
108 fmt
= "%s of read-only variable `%D'";
109 (*fn
) (fmt
, string
, arg
);
111 else if (TREE_CODE (arg
) == PARM_DECL
)
112 (*fn
) ("%s of read-only parameter `%D'", string
, arg
);
113 else if (TREE_CODE (arg
) == INDIRECT_REF
114 && TREE_CODE (TREE_TYPE (TREE_OPERAND (arg
, 0))) == REFERENCE_TYPE
115 && (TREE_CODE (TREE_OPERAND (arg
, 0)) == VAR_DECL
116 || TREE_CODE (TREE_OPERAND (arg
, 0)) == PARM_DECL
))
117 (*fn
) ("%s of read-only reference `%D'", string
, TREE_OPERAND (arg
, 0));
118 else if (TREE_CODE (arg
) == RESULT_DECL
)
119 (*fn
) ("%s of read-only named return value `%D'", string
, arg
);
121 (*fn
) ("%s of read-only location", string
);
124 /* Print an error message for invalid use of a type which declares
125 virtual functions which are not inheritable. */
128 abstract_virtuals_error (decl
, type
)
132 tree u
= CLASSTYPE_ABSTRACT_VIRTUALS (type
);
133 int has_abstract_virtuals
, needs_final_overriders
;
136 /* Count how many abstract methods need to be defined. */
137 for (has_abstract_virtuals
= 0, tu
= u
; tu
; tu
= TREE_CHAIN (tu
))
139 if (DECL_ABSTRACT_VIRTUAL_P (TREE_VALUE (tu
))
140 && ! DECL_NEEDS_FINAL_OVERRIDER_P (TREE_VALUE (tu
)))
142 has_abstract_virtuals
= 1;
147 /* Count how many virtual methods need a final overrider. */
148 for (needs_final_overriders
= 0, tu
= u
; tu
; tu
= TREE_CHAIN (tu
))
150 if (DECL_NEEDS_FINAL_OVERRIDER_P (TREE_VALUE (tu
)))
152 needs_final_overriders
= 1;
159 if (TREE_CODE (decl
) == RESULT_DECL
)
162 if (TREE_CODE (decl
) == VAR_DECL
)
163 cp_error ("cannot declare variable `%D' to be of type `%T'",
165 else if (TREE_CODE (decl
) == PARM_DECL
)
166 cp_error ("cannot declare parameter `%D' to be of type `%T'",
168 else if (TREE_CODE (decl
) == FIELD_DECL
)
169 cp_error ("cannot declare field `%D' to be of type `%T'",
171 else if (TREE_CODE (decl
) == FUNCTION_DECL
172 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
)
173 cp_error ("invalid return type for method `%#D'", decl
);
174 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
175 cp_error ("invalid return type for function `%#D'", decl
);
178 cp_error ("cannot allocate an object of type `%T'", type
);
180 /* Only go through this once. */
181 if (TREE_PURPOSE (u
) == NULL_TREE
)
183 TREE_PURPOSE (u
) = error_mark_node
;
185 if (has_abstract_virtuals
)
186 error (" since the following virtual functions are abstract:");
190 if (DECL_ABSTRACT_VIRTUAL_P (TREE_VALUE (tu
))
191 && ! DECL_NEEDS_FINAL_OVERRIDER_P (TREE_VALUE (tu
)))
192 cp_error ("\t%#D", TREE_VALUE (tu
));
193 tu
= TREE_CHAIN (tu
);
196 if (needs_final_overriders
)
198 if (has_abstract_virtuals
)
199 error (" and the following virtual functions need a final overrider:");
201 error (" since the following virtual functions need a final overrider:");
206 if (DECL_NEEDS_FINAL_OVERRIDER_P (TREE_VALUE (tu
)))
207 cp_error ("\t%#D", TREE_VALUE (tu
));
208 tu
= TREE_CHAIN (tu
);
213 if (has_abstract_virtuals
)
215 if (needs_final_overriders
)
216 cp_error (" since type `%T' has abstract virtual functions and must override virtual functions", type
);
218 cp_error (" since type `%T' has abstract virtual functions", type
);
221 cp_error (" since type `%T' must override virtual functions", type
);
225 /* Print an error message for invalid use of a signature type.
226 Signatures are treated similar to abstract classes here, they
227 cannot be instantiated. */
230 signature_error (decl
, type
)
236 if (TREE_CODE (decl
) == RESULT_DECL
)
239 if (TREE_CODE (decl
) == VAR_DECL
)
240 cp_error ("cannot declare variable `%D' to be of signature type `%T'",
242 else if (TREE_CODE (decl
) == PARM_DECL
)
243 cp_error ("cannot declare parameter `%D' to be of signature type `%T'",
245 else if (TREE_CODE (decl
) == FIELD_DECL
)
246 cp_error ("cannot declare field `%D' to be of signature type `%T'",
248 else if (TREE_CODE (decl
) == FUNCTION_DECL
249 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
)
250 cp_error ("invalid return type for method `%#D'", decl
);
251 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
252 cp_error ("invalid return type for function `%#D'", decl
);
255 cp_error ("cannot allocate an object of signature type `%T'", type
);
258 /* Print an error message for invalid use of an incomplete type.
259 VALUE is the expression that was used (or 0 if that isn't known)
260 and TYPE is the type that was invalid. */
263 incomplete_type_error (value
, type
)
269 /* Avoid duplicate error message. */
270 if (TREE_CODE (type
) == ERROR_MARK
)
273 if (value
!= 0 && (TREE_CODE (value
) == VAR_DECL
274 || TREE_CODE (value
) == PARM_DECL
))
275 cp_error ("`%D' has incomplete type", value
);
279 /* We must print an error message. Be clever about what it says. */
281 switch (TREE_CODE (type
))
286 errmsg
= "invalid use of undefined type `%#T'";
290 error ("invalid use of void expression");
294 if (TYPE_DOMAIN (type
))
296 type
= TREE_TYPE (type
);
299 error ("invalid use of array with unspecified bounds");
303 error ("invalid use of member type (did you forget the `&' ?)");
306 case TEMPLATE_TYPE_PARM
:
307 error ("invalid use of template type parameter");
311 my_friendly_abort (108);
314 cp_error (errmsg
, type
);
318 /* Like error(), but don't call report_error_function(). */
326 extern char * progname
;
329 fprintf (stderr
, "%s:%d: ", input_filename
, lineno
);
331 fprintf (stderr
, "%s: ", progname
);
333 fprintf (stderr
, s
, v
, v2
);
334 fprintf (stderr
, "\n");
337 /* There are times when the compiler can get very confused, confused
338 to the point of giving up by aborting, simply because of previous
339 input errors. It is much better to have the user go back and
340 correct those errors first, and see if it makes us happier, than it
341 is to abort on him. This is because when one has a 10,000 line
342 program, and the compiler comes back with ``core dump'', the user
343 is left not knowing even where to begin to fix things and no place
344 to even try and work around things.
346 The parameter is to uniquely identify the problem to the user, so
347 that they can say, I am having problem 59, and know that fix 7 will
348 probably solve their problem. Or, we can document what problem
349 59 is, so they can understand how to work around it, should they
352 Note, there will be no more calls in the C++ front end to abort,
353 because the C++ front end is so unreliable still. The C front end
354 can get away with calling abort, because for most of the calls to
355 abort on most machines, it, I suspect, can be proven that it is
356 impossible to ever call abort. The same is not yet true for C++,
357 one day, maybe it will be.
359 We used to tell people to "fix the above error[s] and try recompiling
360 the program" via a call to fatal, but that message tended to look
361 silly. So instead, we just do the equivalent of a call to fatal in the
362 same situation (call exit). */
364 /* First used: 0 (reserved), Last used: 369. Free: */
366 static int abortcount
= 0;
369 my_friendly_abort (i
)
372 /* if the previous error came through here, i.e. report_error_function
373 ended up calling us again, don't just exit; we want a diagnostic of
376 current_function_decl
= NULL_TREE
;
377 else if (errorcount
> 0 || sorrycount
> 0)
382 ack ("Internal compiler error.");
384 ack ("Internal compiler error %d.", i
);
385 ack ("Please submit a full bug report to `egcs-bugs@cygnus.com'.");
388 error ("confused by earlier errors, bailing out");
395 error ("Internal compiler error.");
397 error ("Internal compiler error %d.", i
);
399 fatal ("Please submit a full bug report to `egcs-bugs@cygnus.com'.");
403 my_friendly_assert (cond
, where
)
407 my_friendly_abort (where
);
410 /* Return nonzero if VALUE is a valid constant-valued expression
411 for use in initializing a static variable; one that can be an
412 element of a "constant" initializer.
414 Return null_pointer_node if the value is absolute;
415 if it is relocatable, return the variable that determines the relocation.
416 We assume that VALUE has been folded as much as possible;
417 therefore, we do not need to check for such things as
418 arithmetic-combinations of integers. */
421 initializer_constant_valid_p (value
, endtype
)
425 switch (TREE_CODE (value
))
428 if (TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
429 && TREE_CONSTANT (value
))
431 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value
)),
434 return TREE_STATIC (value
) ? null_pointer_node
: 0;
440 return null_pointer_node
;
443 return TREE_OPERAND (value
, 0);
445 case NON_LVALUE_EXPR
:
446 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
450 /* Allow conversions between pointer types. */
451 if (POINTER_TYPE_P (TREE_TYPE (value
))
452 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
453 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
455 /* Allow conversions between real types. */
456 if (TREE_CODE (TREE_TYPE (value
)) == REAL_TYPE
457 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == REAL_TYPE
)
458 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
460 /* Allow length-preserving conversions between integer types. */
461 if (TREE_CODE (TREE_TYPE (value
)) == INTEGER_TYPE
462 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == INTEGER_TYPE
463 && (TYPE_PRECISION (TREE_TYPE (value
))
464 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
465 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
467 /* Allow conversions between other integer types only if
469 if (TREE_CODE (TREE_TYPE (value
)) == INTEGER_TYPE
470 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == INTEGER_TYPE
)
472 tree inner
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
474 if (inner
== null_pointer_node
)
475 return null_pointer_node
;
479 /* Allow (int) &foo provided int is as wide as a pointer. */
480 if (TREE_CODE (TREE_TYPE (value
)) == INTEGER_TYPE
481 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == POINTER_TYPE
482 && (TYPE_PRECISION (TREE_TYPE (value
))
483 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
484 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
487 /* Likewise conversions from int to pointers. */
488 if (TREE_CODE (TREE_TYPE (value
)) == POINTER_TYPE
489 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == INTEGER_TYPE
490 && (TYPE_PRECISION (TREE_TYPE (value
))
491 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
492 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
495 /* Allow conversions to union types if the value inside is okay. */
496 if (TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
)
497 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
502 if ((TREE_CODE (endtype
) == INTEGER_TYPE
)
503 && (TYPE_PRECISION (endtype
) < POINTER_SIZE
))
506 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
508 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
510 /* If either term is absolute, use the other terms relocation. */
511 if (valid0
== null_pointer_node
)
513 if (valid1
== null_pointer_node
)
519 if ((TREE_CODE (endtype
) == INTEGER_TYPE
)
520 && (TYPE_PRECISION (endtype
) < POINTER_SIZE
))
523 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
525 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
527 /* Win if second argument is absolute. */
528 if (valid1
== null_pointer_node
)
530 /* Win if both arguments have the same relocation.
531 Then the value is absolute. */
532 if (valid0
== valid1
)
533 return null_pointer_node
;
544 /* Perform appropriate conversions on the initial value of a variable,
545 store it in the declaration DECL,
546 and print any error messages that are appropriate.
547 If the init is invalid, store an ERROR_MARK.
549 C++: Note that INIT might be a TREE_LIST, which would mean that it is
550 a base class initializer for some aggregate type, hopefully compatible
551 with DECL. If INIT is a single element, and DECL is an aggregate
552 type, we silently convert INIT into a TREE_LIST, allowing a constructor
555 If INIT is a TREE_LIST and there is no constructor, turn INIT
556 into a CONSTRUCTOR and use standard initialization techniques.
557 Perhaps a warning should be generated?
559 Returns value of initializer if initialization could not be
560 performed for static variable. In that case, caller must do
564 store_init_value (decl
, init
)
567 register tree value
, type
;
569 /* If variable's type was invalidly declared, just ignore it. */
571 type
= TREE_TYPE (decl
);
572 if (TREE_CODE (type
) == ERROR_MARK
)
576 /* This breaks arrays, and should not have any effect for other decls. */
577 /* Take care of C++ business up here. */
578 type
= TYPE_MAIN_VARIANT (type
);
581 if (IS_AGGR_TYPE (type
))
583 if (! TYPE_HAS_TRIVIAL_INIT_REF (type
)
584 && TREE_CODE (init
) != CONSTRUCTOR
)
585 my_friendly_abort (109);
587 /* Although we are not allowed to declare variables of signature
588 type, we complain about a possible constructor call in such a
589 declaration as well. */
590 if (TREE_CODE (init
) == TREE_LIST
591 && IS_SIGNATURE (type
))
593 cp_error ("constructor syntax cannot be used with signature type `%T'",
595 init
= error_mark_node
;
597 else if (TREE_CODE (init
) == TREE_LIST
)
599 cp_error ("constructor syntax used, but no constructor declared for type `%T'", type
);
600 init
= build_nt (CONSTRUCTOR
, NULL_TREE
, nreverse (init
));
603 if (TREE_CODE (init
) == CONSTRUCTOR
)
607 /* Check that we're really an aggregate as ARM 8.4.1 defines it. */
608 if (CLASSTYPE_N_BASECLASSES (type
))
609 cp_error_at ("initializer list construction invalid for derived class object `%D'", decl
);
610 if (CLASSTYPE_VTBL_PTR (type
))
611 cp_error_at ("initializer list construction invalid for polymorphic class object `%D'", decl
);
612 if (TYPE_NEEDS_CONSTRUCTING (type
))
614 cp_error_at ("initializer list construction invalid for `%D'", decl
);
615 error ("due to the presence of a constructor");
617 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
618 if (TREE_PRIVATE (field
) || TREE_PROTECTED (field
))
620 cp_error_at ("initializer list construction invalid for `%D'", decl
);
621 cp_error_at ("due to non-public access of member `%D'", field
);
623 for (field
= TYPE_METHODS (type
); field
; field
= TREE_CHAIN (field
))
624 if (TREE_PRIVATE (field
) || TREE_PROTECTED (field
))
626 cp_error_at ("initializer list construction invalid for `%D'", decl
);
627 cp_error_at ("due to non-public access of member `%D'", field
);
632 else if (TREE_CODE (init
) == TREE_LIST
633 && TREE_TYPE (init
) != unknown_type_node
)
635 if (TREE_CODE (decl
) == RESULT_DECL
)
637 if (TREE_CHAIN (init
))
639 warning ("comma expression used to initialize return value");
640 init
= build_compound_expr (init
);
643 init
= TREE_VALUE (init
);
645 else if (TREE_TYPE (init
) != 0
646 && TREE_CODE (TREE_TYPE (init
)) == OFFSET_TYPE
)
648 /* Use the type of our variable to instantiate
649 the type of our initializer. */
650 init
= instantiate_type (type
, init
, 1);
652 else if (TREE_CODE (init
) == TREE_LIST
653 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
655 error ("cannot initialize arrays using this syntax");
660 /* We get here with code like `int a (2);' */
662 if (TREE_CHAIN (init
) != NULL_TREE
)
664 pedwarn ("initializer list being treated as compound expression");
665 init
= build_compound_expr (init
);
668 init
= TREE_VALUE (init
);
672 if (TYPE_PTRMEMFUNC_P (type
) && TREE_CODE (init
) == CONSTRUCTOR
673 && TREE_TYPE (init
) == NULL_TREE
)
674 cp_pedwarn ("initializer list for `%T'", type
);
676 /* End of special C++ code. */
678 /* Digest the specified initializer into an expression. */
680 value
= digest_init (type
, init
, (tree
*) 0);
682 /* Store the expression if valid; else report error. */
684 if (TREE_CODE (value
) == ERROR_MARK
)
686 /* Other code expects that initializers for objects of types that need
687 constructing never make it into DECL_INITIAL, and passes 'init' to
688 expand_aggr_init without checking DECL_INITIAL. So just return. */
689 else if (TYPE_NEEDS_CONSTRUCTING (type
))
691 else if (TREE_STATIC (decl
)
692 && (! TREE_CONSTANT (value
)
693 || ! initializer_constant_valid_p (value
, TREE_TYPE (value
))
695 /* A STATIC PUBLIC int variable doesn't have to be
696 run time inited when doing pic. (mrs) */
697 /* Since ctors and dtors are the only things that can
698 reference vtables, and they are always written down
699 the the vtable definition, we can leave the
700 vtables in initialized data space.
701 However, other initialized data cannot be initialized
702 this way. Instead a global file-level initializer
704 || (flag_pic
&& !DECL_VIRTUAL_P (decl
) && TREE_PUBLIC (decl
))
709 #if 0 /* No, that's C. jason 9/19/94 */
712 if (pedantic
&& TREE_CODE (value
) == CONSTRUCTOR
713 /* Don't complain about non-constant initializers of
714 signature tables and signature pointers/references. */
715 && ! (TYPE_LANG_SPECIFIC (type
)
716 && (IS_SIGNATURE (type
)
717 || IS_SIGNATURE_POINTER (type
)
718 || IS_SIGNATURE_REFERENCE (type
))))
720 if (! TREE_CONSTANT (value
) || ! TREE_STATIC (value
))
721 pedwarn ("ANSI C++ forbids non-constant aggregate initializer expressions");
725 DECL_INITIAL (decl
) = value
;
729 /* Digest the parser output INIT as an initializer for type TYPE.
730 Return a C expression of type TYPE to represent the initial value.
732 If TAIL is nonzero, it points to a variable holding a list of elements
733 of which INIT is the first. We update the list stored there by
734 removing from the head all the elements that we use.
735 Normally this is only one; we use more than one element only if
736 TYPE is an aggregate and INIT is not a constructor. */
739 digest_init (type
, init
, tail
)
740 tree type
, init
, *tail
;
742 enum tree_code code
= TREE_CODE (type
);
743 tree element
= NULL_TREE
;
744 tree old_tail_contents
= NULL_TREE
;
745 /* Nonzero if INIT is a braced grouping, which comes in as a CONSTRUCTOR
746 tree node which has no TREE_TYPE. */
749 /* By default, assume we use one element from a list.
750 We correct this later in the sole case where it is not true. */
754 old_tail_contents
= *tail
;
755 *tail
= TREE_CHAIN (*tail
);
758 if (init
== error_mark_node
|| (TREE_CODE (init
) == TREE_LIST
759 && TREE_VALUE (init
) == error_mark_node
))
760 return error_mark_node
;
762 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
763 if (TREE_CODE (init
) == NON_LVALUE_EXPR
)
764 init
= TREE_OPERAND (init
, 0);
766 if (init
&& TREE_TYPE (init
) && TYPE_PTRMEMFUNC_P (type
))
767 init
= default_conversion (init
);
769 if (init
&& TYPE_PTRMEMFUNC_P (type
)
770 && ((TREE_CODE (init
) == ADDR_EXPR
771 && ((TREE_CODE (TREE_TYPE (init
)) == POINTER_TYPE
772 && TREE_CODE (TREE_TYPE (TREE_TYPE (init
))) == METHOD_TYPE
)
773 || TREE_CODE (TREE_OPERAND (init
, 0)) == TREE_LIST
))
774 || TREE_CODE (init
) == TREE_LIST
775 || integer_zerop (init
)
776 || (TREE_TYPE (init
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (init
)))))
778 return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type
), init
, 0);
781 raw_constructor
= TREE_CODE (init
) == CONSTRUCTOR
&& TREE_TYPE (init
) == 0;
783 if (init
&& raw_constructor
784 && CONSTRUCTOR_ELTS (init
) != 0
785 && TREE_CHAIN (CONSTRUCTOR_ELTS (init
)) == 0)
787 element
= TREE_VALUE (CONSTRUCTOR_ELTS (init
));
788 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
789 if (element
&& TREE_CODE (element
) == NON_LVALUE_EXPR
)
790 element
= TREE_OPERAND (element
, 0);
791 if (element
== error_mark_node
)
795 /* Any type can be initialized from an expression of the same type,
796 optionally with braces. */
798 if (init
&& TREE_TYPE (init
)
799 && (TYPE_MAIN_VARIANT (TREE_TYPE (init
)) == type
800 || (code
== ARRAY_TYPE
&& comptypes (TREE_TYPE (init
), type
, 1))))
802 if (pedantic
&& code
== ARRAY_TYPE
803 && TREE_CODE (init
) != STRING_CST
)
804 pedwarn ("ANSI C++ forbids initializing array from array expression");
805 if (TREE_CODE (init
) == CONST_DECL
)
806 init
= DECL_INITIAL (init
);
807 else if (TREE_READONLY_DECL_P (init
))
808 init
= decl_constant_value (init
);
809 else if (IS_AGGR_TYPE (type
) && TYPE_NEEDS_CONSTRUCTING (type
))
810 init
= ocp_convert (type
, init
, CONV_IMPLICIT
|CONV_FORCE_TEMP
,
815 if (element
&& (TREE_TYPE (element
) == type
816 || (code
== ARRAY_TYPE
&& TREE_TYPE (element
)
817 && comptypes (TREE_TYPE (element
), type
, 1))))
819 if (pedantic
&& code
== ARRAY_TYPE
)
820 pedwarn ("ANSI C++ forbids initializing array from array expression");
821 if (pedantic
&& (code
== RECORD_TYPE
|| code
== UNION_TYPE
))
822 pedwarn ("ANSI C++ forbids single nonscalar initializer with braces");
823 if (TREE_CODE (element
) == CONST_DECL
)
824 element
= DECL_INITIAL (element
);
825 else if (TREE_READONLY_DECL_P (element
))
826 element
= decl_constant_value (element
);
830 /* Initialization of an array of chars from a string constant
831 optionally enclosed in braces. */
833 if (code
== ARRAY_TYPE
)
835 tree typ1
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
836 if ((typ1
== char_type_node
837 || typ1
== signed_char_type_node
838 || typ1
== unsigned_char_type_node
839 || typ1
== unsigned_wchar_type_node
840 || typ1
== signed_wchar_type_node
)
841 && ((init
&& TREE_CODE (init
) == STRING_CST
)
842 || (element
&& TREE_CODE (element
) == STRING_CST
)))
844 tree string
= element
? element
: init
;
846 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string
)))
848 && TYPE_PRECISION (typ1
) == BITS_PER_UNIT
)
850 error ("char-array initialized from wide string");
851 return error_mark_node
;
853 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string
)))
855 && TYPE_PRECISION (typ1
) != BITS_PER_UNIT
)
857 error ("int-array initialized from non-wide string");
858 return error_mark_node
;
862 && typ1
!= char_type_node
863 && typ1
!= signed_char_type_node
864 && typ1
!= unsigned_char_type_node
)
865 pedwarn ("ANSI C++ forbids string initializer except for `char' elements");
866 TREE_TYPE (string
) = type
;
867 if (TYPE_DOMAIN (type
) != 0
868 && TREE_CONSTANT (TYPE_SIZE (type
)))
871 = TREE_INT_CST_LOW (TYPE_SIZE (type
));
872 size
= (size
+ BITS_PER_UNIT
- 1) / BITS_PER_UNIT
;
873 /* In C it is ok to subtract 1 from the length of the string
874 because it's ok to ignore the terminating null char that is
875 counted in the length of the constant, but in C++ this would
877 if (size
< TREE_STRING_LENGTH (string
))
878 pedwarn ("initializer-string for array of chars is too long");
884 /* Handle scalar types, including conversions,
885 and signature pointers and references. */
887 if (code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== POINTER_TYPE
888 || code
== ENUMERAL_TYPE
|| code
== REFERENCE_TYPE
889 || code
== BOOLEAN_TYPE
|| code
== COMPLEX_TYPE
890 || (code
== RECORD_TYPE
&& ! raw_constructor
891 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
))))
897 error ("initializer for scalar variable requires one element");
898 return error_mark_node
;
902 while (TREE_CODE (init
) == CONSTRUCTOR
903 && ! (TREE_TYPE (init
)
904 && TYPE_PTRMEMFUNC_P (TREE_TYPE (init
))))
906 cp_pedwarn ("braces around scalar initializer for `%T'", type
);
907 init
= CONSTRUCTOR_ELTS (init
);
908 if (TREE_CHAIN (init
))
909 cp_pedwarn ("ignoring extra initializers for `%T'", type
);
910 init
= TREE_VALUE (init
);
913 return convert_for_initialization (0, type
, init
, LOOKUP_NORMAL
,
914 "initialization", NULL_TREE
, 0);
917 /* Come here only for records and arrays (and unions with constructors). */
919 if (TYPE_SIZE (type
) && ! TREE_CONSTANT (TYPE_SIZE (type
)))
921 cp_error ("variable-sized object of type `%T' may not be initialized",
923 return error_mark_node
;
926 if (code
== ARRAY_TYPE
|| code
== RECORD_TYPE
|| code
== UNION_TYPE
)
928 if (raw_constructor
&& TYPE_NON_AGGREGATE_CLASS (type
))
930 cp_error ("subobject of type `%T' must be initialized by constructor, not by `%E'",
932 return error_mark_node
;
934 else if (raw_constructor
)
935 return process_init_constructor (type
, init
, (tree
*)0);
936 else if (TYPE_NON_AGGREGATE_CLASS (type
))
938 int flags
= LOOKUP_NORMAL
;
939 /* Initialization from { } is copy-initialization. */
941 flags
|= LOOKUP_ONLYCONVERTING
;
942 return convert_for_initialization (0, type
, init
, flags
,
943 "initialization", NULL_TREE
, 0);
947 *tail
= old_tail_contents
;
948 return process_init_constructor (type
, 0, tail
);
951 if (code
!= ARRAY_TYPE
)
952 return convert_for_initialization (NULL_TREE
, type
, init
, LOOKUP_NORMAL
,
953 "initialization", NULL_TREE
, 0);
956 error ("invalid initializer");
957 return error_mark_node
;
960 /* Process a constructor for a variable of type TYPE.
961 The constructor elements may be specified either with INIT or with ELTS,
962 only one of which should be non-null.
964 If INIT is specified, it is a CONSTRUCTOR node which is specifically
965 and solely for initializing this datum.
967 If ELTS is specified, it is the address of a variable containing
968 a list of expressions. We take as many elements as we need
969 from the head of the list and update the list.
971 In the resulting constructor, TREE_CONSTANT is set if all elts are
972 constant, and TREE_STATIC is set if, in addition, all elts are simple enough
973 constants that the assembler and linker can compute them. */
976 process_init_constructor (type
, init
, elts
)
977 tree type
, init
, *elts
;
980 /* List of the elements of the result constructor,
982 register tree members
= NULL
;
988 /* Make TAIL be the list of elements to use for the initialization,
989 no matter how the data was given to us. */
993 if (warn_missing_braces
)
994 warning ("aggregate has a partly bracketed initializer");
998 tail
= CONSTRUCTOR_ELTS (init
);
1000 /* Gobble as many elements as needed, and make a constructor or initial value
1001 for each element of this aggregate. Chain them together in result.
1002 If there are too few, use 0 for each scalar ultimate component. */
1004 if (TREE_CODE (type
) == ARRAY_TYPE
)
1006 tree domain
= TYPE_DOMAIN (type
);
1011 len
= (TREE_INT_CST_LOW (TYPE_MAX_VALUE (domain
))
1012 - TREE_INT_CST_LOW (TYPE_MIN_VALUE (domain
))
1015 len
= -1; /* Take as many as there are */
1017 for (i
= 0; (len
< 0 || i
< len
) && tail
!= 0; i
++)
1019 register tree next1
;
1021 if (TREE_PURPOSE (tail
)
1022 && (TREE_CODE (TREE_PURPOSE (tail
)) != INTEGER_CST
1023 || TREE_INT_CST_LOW (TREE_PURPOSE (tail
)) != i
))
1024 sorry ("non-trivial labeled initializers");
1026 if (TREE_VALUE (tail
) != 0)
1029 next1
= digest_init (TYPE_MAIN_VARIANT (TREE_TYPE (type
)),
1030 TREE_VALUE (tail
), &tail1
);
1031 if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (type
))
1032 && TYPE_MAIN_VARIANT (TREE_TYPE (type
)) != TYPE_MAIN_VARIANT (TREE_TYPE (next1
)))
1034 /* The fact this needs to be done suggests this code needs
1035 to be totally rewritten. */
1036 next1
= convert_for_initialization (NULL_TREE
, TREE_TYPE (type
), next1
, LOOKUP_NORMAL
, "initialization", NULL_TREE
, 0);
1038 my_friendly_assert (tail1
== 0
1039 || TREE_CODE (tail1
) == TREE_LIST
, 319);
1040 if (tail
== tail1
&& len
< 0)
1042 error ("non-empty initializer for array of empty elements");
1043 /* Just ignore what we were supposed to use. */
1050 next1
= error_mark_node
;
1051 tail
= TREE_CHAIN (tail
);
1054 if (next1
== error_mark_node
)
1056 else if (!TREE_CONSTANT (next1
))
1058 else if (! initializer_constant_valid_p (next1
, TREE_TYPE (next1
)))
1060 members
= expr_tree_cons (NULL_TREE
, next1
, members
);
1063 if (TREE_CODE (type
) == RECORD_TYPE
)
1065 register tree field
;
1069 if (TYPE_USES_VIRTUAL_BASECLASSES (type
))
1071 sorry ("initializer list for object of class with virtual baseclasses");
1072 return error_mark_node
;
1075 if (TYPE_BINFO_BASETYPES (type
))
1077 sorry ("initializer list for object of class with baseclasses");
1078 return error_mark_node
;
1081 if (TYPE_VIRTUAL_P (type
))
1083 sorry ("initializer list for object using virtual functions");
1084 return error_mark_node
;
1088 for (field
= TYPE_FIELDS (type
); field
&& tail
;
1089 field
= TREE_CHAIN (field
))
1091 register tree next1
;
1093 if (! DECL_NAME (field
))
1095 members
= expr_tree_cons (field
, integer_zero_node
, members
);
1099 if (TREE_CODE (field
) != FIELD_DECL
)
1102 if (TREE_PURPOSE (tail
)
1103 && TREE_PURPOSE (tail
) != field
1104 && TREE_PURPOSE (tail
) != DECL_NAME (field
))
1105 sorry ("non-trivial labeled initializers");
1107 if (TREE_VALUE (tail
) != 0)
1111 next1
= digest_init (TREE_TYPE (field
),
1112 TREE_VALUE (tail
), &tail1
);
1113 my_friendly_assert (tail1
== 0
1114 || TREE_CODE (tail1
) == TREE_LIST
, 320);
1119 next1
= error_mark_node
;
1120 tail
= TREE_CHAIN (tail
);
1123 if (next1
== error_mark_node
)
1125 else if (!TREE_CONSTANT (next1
))
1127 else if (! initializer_constant_valid_p (next1
, TREE_TYPE (next1
)))
1129 members
= expr_tree_cons (field
, next1
, members
);
1131 for (; field
; field
= TREE_CHAIN (field
))
1133 if (TREE_CODE (field
) != FIELD_DECL
)
1136 /* Does this field have a default initialization? */
1137 if (DECL_INITIAL (field
))
1139 register tree next1
= DECL_INITIAL (field
);
1140 if (TREE_CODE (next1
) == ERROR_MARK
)
1142 else if (!TREE_CONSTANT (next1
))
1144 else if (! initializer_constant_valid_p (next1
, TREE_TYPE (next1
)))
1146 members
= expr_tree_cons (field
, next1
, members
);
1148 else if (TREE_READONLY (field
))
1149 error ("uninitialized const member `%s'",
1150 IDENTIFIER_POINTER (DECL_NAME (field
)));
1151 else if (TYPE_LANG_SPECIFIC (TREE_TYPE (field
))
1152 && CLASSTYPE_READONLY_FIELDS_NEED_INIT (TREE_TYPE (field
)))
1153 error ("member `%s' with uninitialized const fields",
1154 IDENTIFIER_POINTER (DECL_NAME (field
)));
1155 else if (TREE_CODE (TREE_TYPE (field
)) == REFERENCE_TYPE
)
1156 error ("member `%s' is uninitialized reference",
1157 IDENTIFIER_POINTER (DECL_NAME (field
)));
1161 if (TREE_CODE (type
) == UNION_TYPE
)
1163 register tree field
= TYPE_FIELDS (type
);
1164 register tree next1
;
1166 /* Find the first named field. ANSI decided in September 1990
1167 that only named fields count here. */
1168 while (field
&& (DECL_NAME (field
) == 0
1169 || TREE_CODE (field
) != FIELD_DECL
))
1170 field
= TREE_CHAIN (field
);
1172 /* If this element specifies a field, initialize via that field. */
1173 if (TREE_PURPOSE (tail
) != NULL_TREE
)
1177 if (TREE_CODE (TREE_PURPOSE (tail
)) == FIELD_DECL
)
1178 /* Handle the case of a call by build_c_cast. */
1179 field
= TREE_PURPOSE (tail
), win
= 1;
1180 else if (TREE_CODE (TREE_PURPOSE (tail
)) != IDENTIFIER_NODE
)
1181 error ("index value instead of field name in union initializer");
1185 for (temp
= TYPE_FIELDS (type
);
1187 temp
= TREE_CHAIN (temp
))
1188 if (DECL_NAME (temp
) == TREE_PURPOSE (tail
))
1191 field
= temp
, win
= 1;
1193 error ("no field `%s' in union being initialized",
1194 IDENTIFIER_POINTER (TREE_PURPOSE (tail
)));
1197 TREE_VALUE (tail
) = error_mark_node
;
1199 else if (field
== 0)
1201 cp_error ("union `%T' with no named members cannot be initialized",
1203 TREE_VALUE (tail
) = error_mark_node
;
1206 if (TREE_VALUE (tail
) != 0)
1210 next1
= digest_init (TREE_TYPE (field
),
1211 TREE_VALUE (tail
), &tail1
);
1212 if (tail1
!= 0 && TREE_CODE (tail1
) != TREE_LIST
)
1213 my_friendly_abort (357);
1218 next1
= error_mark_node
;
1219 tail
= TREE_CHAIN (tail
);
1222 if (next1
== error_mark_node
)
1224 else if (!TREE_CONSTANT (next1
))
1226 else if (initializer_constant_valid_p (next1
, TREE_TYPE (next1
)) == 0)
1228 members
= expr_tree_cons (field
, next1
, members
);
1231 /* If arguments were specified as a list, just remove the ones we used. */
1234 /* If arguments were specified as a constructor,
1235 complain unless we used all the elements of the constructor. */
1237 pedwarn ("excess elements in aggregate initializer");
1240 return error_mark_node
;
1242 result
= build (CONSTRUCTOR
, type
, NULL_TREE
, nreverse (members
));
1244 TREE_HAS_CONSTRUCTOR (result
) = TREE_HAS_CONSTRUCTOR (init
);
1245 if (allconstant
) TREE_CONSTANT (result
) = 1;
1246 if (allconstant
&& allsimple
) TREE_STATIC (result
) = 1;
1250 /* Given a structure or union value DATUM, construct and return
1251 the structure or union component which results from narrowing
1252 that value by the type specified in BASETYPE. For example, given the
1255 class L { int ii; };
1256 class A : L { ... };
1257 class B : L { ... };
1258 class C : A, B { ... };
1266 x.A::ii refers to the ii member of the L part of
1267 of A part of the C object named by X. In this case,
1268 DATUM would be x, and BASETYPE would be A. */
1271 build_scoped_ref (datum
, basetype
)
1276 tree type
= TREE_TYPE (datum
);
1278 if (datum
== error_mark_node
)
1279 return error_mark_node
;
1281 if (TREE_CODE (type
) == REFERENCE_TYPE
)
1282 type
= TREE_TYPE (type
);
1284 type
= TYPE_MAIN_VARIANT (type
);
1286 /* This is an easy conversion. */
1287 if (is_aggr_type (basetype
, 1))
1289 tree binfo
= TYPE_BINFO (basetype
);
1290 if (binfo
!= TYPE_BINFO (type
))
1292 binfo
= get_binfo (binfo
, type
, 1);
1293 if (binfo
== error_mark_node
)
1294 return error_mark_node
;
1296 return error_not_base_type (basetype
, type
);
1299 switch (TREE_CODE (datum
))
1304 case FIX_TRUNC_EXPR
:
1305 case FIX_FLOOR_EXPR
:
1306 case FIX_ROUND_EXPR
:
1308 ref
= convert_pointer_to (binfo
,
1309 build_unary_op (ADDR_EXPR
, TREE_OPERAND (datum
, 0), 0));
1312 ref
= convert_pointer_to (binfo
,
1313 build_unary_op (ADDR_EXPR
, datum
, 0));
1315 return build_indirect_ref (ref
, "(compiler error in build_scoped_ref)");
1317 return error_mark_node
;
1320 /* Build a reference to an object specified by the C++ `->' operator.
1321 Usually this just involves dereferencing the object, but if the
1322 `->' operator is overloaded, then such overloads must be
1323 performed until an object which does not have the `->' operator
1324 overloaded is found. An error is reported when circular pointer
1325 delegation is detected. */
1328 build_x_arrow (datum
)
1331 tree types_memoized
= NULL_TREE
;
1332 register tree rval
= datum
;
1333 tree type
= TREE_TYPE (rval
);
1334 tree last_rval
= NULL_TREE
;
1336 if (type
== error_mark_node
)
1337 return error_mark_node
;
1339 if (processing_template_decl
)
1340 return build_min_nt (ARROW_EXPR
, rval
);
1342 if (TREE_CODE (rval
) == OFFSET_REF
)
1344 rval
= resolve_offset_ref (datum
);
1345 type
= TREE_TYPE (rval
);
1348 if (TREE_CODE (type
) == REFERENCE_TYPE
)
1350 rval
= convert_from_reference (rval
);
1351 type
= TREE_TYPE (rval
);
1354 if (IS_AGGR_TYPE (type
))
1356 while ((rval
= build_opfncall (COMPONENT_REF
, LOOKUP_NORMAL
, rval
,
1357 NULL_TREE
, NULL_TREE
)))
1359 if (rval
== error_mark_node
)
1360 return error_mark_node
;
1362 if (value_member (TREE_TYPE (rval
), types_memoized
))
1364 error ("circular pointer delegation detected");
1365 return error_mark_node
;
1369 types_memoized
= tree_cons (NULL_TREE
, TREE_TYPE (rval
),
1375 if (last_rval
== NULL_TREE
)
1377 cp_error ("base operand of `->' has non-pointer type `%T'", type
);
1378 return error_mark_node
;
1381 if (TREE_CODE (TREE_TYPE (last_rval
)) == REFERENCE_TYPE
)
1382 last_rval
= convert_from_reference (last_rval
);
1385 last_rval
= default_conversion (rval
);
1387 /* Signature pointers are not dereferenced. */
1388 if (TYPE_LANG_SPECIFIC (TREE_TYPE (last_rval
))
1389 && IS_SIGNATURE_POINTER (TREE_TYPE (last_rval
)))
1392 if (TREE_CODE (TREE_TYPE (last_rval
)) == POINTER_TYPE
)
1393 return build_indirect_ref (last_rval
, NULL_PTR
);
1396 error ("result of `operator->()' yields non-pointer result");
1398 error ("base operand of `->' is not a pointer");
1399 return error_mark_node
;
1402 /* Make an expression to refer to the COMPONENT field of
1403 structure or union value DATUM. COMPONENT is an arbitrary
1404 expression. DATUM has not already been checked out to be of
1407 For C++, COMPONENT may be a TREE_LIST. This happens when we must
1408 return an object of member type to a method of the current class,
1409 but there is not yet enough typing information to know which one.
1410 As a special case, if there is only one method by that name,
1411 it is returned. Otherwise we return an expression which other
1412 routines will have to know how to deal with later. */
1415 build_m_component_ref (datum
, component
)
1416 tree datum
, component
;
1419 tree objtype
= TREE_TYPE (datum
);
1423 if (processing_template_decl
)
1424 return build_min_nt (DOTSTAR_EXPR
, datum
, component
);
1426 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (component
)))
1428 type
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (component
)));
1433 component
= build_indirect_ref (component
, NULL_PTR
);
1434 type
= TREE_TYPE (component
);
1435 rettype
= TREE_TYPE (type
);
1438 if (datum
== error_mark_node
|| component
== error_mark_node
)
1439 return error_mark_node
;
1441 if (TREE_CODE (type
) != OFFSET_TYPE
&& TREE_CODE (type
) != METHOD_TYPE
)
1443 cp_error ("`%E' cannot be used as a member pointer, since it is of type `%T'", component
, type
);
1444 return error_mark_node
;
1447 if (TREE_CODE (objtype
) == REFERENCE_TYPE
)
1448 objtype
= TREE_TYPE (objtype
);
1449 objtype
= TYPE_MAIN_VARIANT (objtype
);
1451 if (! IS_AGGR_TYPE (objtype
))
1453 cp_error ("cannot apply member pointer `%E' to `%E'", component
, datum
);
1454 cp_error ("which is of non-aggregate type `%T'", objtype
);
1455 return error_mark_node
;
1458 binfo
= get_binfo (TYPE_METHOD_BASETYPE (type
), objtype
, 1);
1459 if (binfo
== NULL_TREE
)
1461 cp_error ("member type `%T::' incompatible with object type `%T'",
1462 TYPE_METHOD_BASETYPE (type
), objtype
);
1463 return error_mark_node
;
1465 else if (binfo
== error_mark_node
)
1466 return error_mark_node
;
1468 component
= build (OFFSET_REF
, rettype
, datum
, component
);
1469 if (TREE_CODE (type
) == OFFSET_TYPE
)
1470 component
= resolve_offset_ref (component
);
1474 /* Return a tree node for the expression TYPENAME '(' PARMS ')'. */
1477 build_functional_cast (exp
, parms
)
1481 /* This is either a call to a constructor,
1482 or a C cast in C++'s `functional' notation. */
1485 if (exp
== error_mark_node
|| parms
== error_mark_node
)
1486 return error_mark_node
;
1488 if (TREE_CODE (exp
) == IDENTIFIER_NODE
)
1490 if (IDENTIFIER_HAS_TYPE_VALUE (exp
))
1491 /* Either an enum or an aggregate type. */
1492 type
= IDENTIFIER_TYPE_VALUE (exp
);
1495 type
= lookup_name (exp
, 1);
1496 if (!type
|| TREE_CODE (type
) != TYPE_DECL
)
1498 cp_error ("`%T' fails to be a typedef or built-in type", exp
);
1499 return error_mark_node
;
1501 type
= TREE_TYPE (type
);
1504 else if (TREE_CODE (exp
) == TYPE_DECL
)
1505 type
= TREE_TYPE (exp
);
1509 if (processing_template_decl
)
1510 return build_min (CAST_EXPR
, type
, parms
);
1512 if (IS_SIGNATURE (type
))
1514 error ("signature type not allowed in cast or constructor expression");
1515 return error_mark_node
;
1518 if (! IS_AGGR_TYPE (type
))
1520 /* this must build a C cast */
1521 if (parms
== NULL_TREE
)
1522 parms
= integer_zero_node
;
1525 if (TREE_CHAIN (parms
) != NULL_TREE
)
1526 pedwarn ("initializer list being treated as compound expression");
1527 parms
= build_compound_expr (parms
);
1530 return build_c_cast (type
, parms
);
1533 /* Prepare to evaluate as a call to a constructor. If this expression
1534 is actually used, for example,
1536 return X (arg1, arg2, ...);
1538 then the slot being initialized will be filled in. */
1540 if (TYPE_SIZE (complete_type (type
)) == NULL_TREE
)
1542 cp_error ("type `%T' is not yet defined", type
);
1543 return error_mark_node
;
1546 if (parms
&& TREE_CHAIN (parms
) == NULL_TREE
)
1547 return build_c_cast (type
, TREE_VALUE (parms
));
1549 exp
= build_method_call (NULL_TREE
, ctor_identifier
, parms
,
1550 TYPE_BINFO (type
), LOOKUP_NORMAL
);
1552 if (exp
== error_mark_node
)
1553 return error_mark_node
;
1555 return build_cplus_new (type
, exp
);
1558 /* Return the character string for the name that encodes the
1559 enumeral value VALUE in the domain TYPE. */
1562 enum_name_string (value
, type
)
1566 register tree values
= TYPE_VALUES (type
);
1567 register HOST_WIDE_INT intval
= TREE_INT_CST_LOW (value
);
1569 my_friendly_assert (TREE_CODE (type
) == ENUMERAL_TYPE
, 324);
1571 && TREE_INT_CST_LOW (TREE_VALUE (values
)) != intval
)
1572 values
= TREE_CHAIN (values
);
1573 if (values
== NULL_TREE
)
1575 char *buf
= (char *)oballoc (16 + TYPE_NAME_LENGTH (type
));
1577 /* Value must have been cast. */
1578 sprintf (buf
, "(enum %s)%d",
1579 TYPE_NAME_STRING (type
), intval
);
1582 return IDENTIFIER_POINTER (TREE_PURPOSE (values
));
1586 /* Print out a language-specific error message for
1587 (Pascal) case or (C) switch statements.
1588 CODE tells what sort of message to print.
1589 TYPE is the type of the switch index expression.
1590 NEW is the new value that we were trying to add.
1591 OLD is the old value that stopped us from adding it. */
1594 report_case_error (code
, type
, new_value
, old_value
)
1597 tree new_value
, old_value
;
1602 error ("case label not within a switch statement");
1604 error ("default label not within a switch statement");
1610 error ("multiple default labels in one switch");
1613 if (TREE_CODE (new_value
) == RANGE_EXPR
)
1614 if (TREE_CODE (old_value
) == RANGE_EXPR
)
1616 char *buf
= (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type
)));
1617 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1618 sprintf (buf
, "overlapping ranges [%s..%s], [%s..%s] in case expression",
1619 enum_name_string (TREE_OPERAND (new_value
, 0), type
),
1620 enum_name_string (TREE_OPERAND (new_value
, 1), type
),
1621 enum_name_string (TREE_OPERAND (old_value
, 0), type
),
1622 enum_name_string (TREE_OPERAND (old_value
, 1), type
));
1624 sprintf (buf
, "overlapping ranges [%d..%d], [%d..%d] in case expression",
1625 TREE_INT_CST_LOW (TREE_OPERAND (new_value
, 0)),
1626 TREE_INT_CST_LOW (TREE_OPERAND (new_value
, 1)),
1627 TREE_INT_CST_LOW (TREE_OPERAND (old_value
, 0)),
1628 TREE_INT_CST_LOW (TREE_OPERAND (old_value
, 1)));
1633 char *buf
= (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type
)));
1634 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1635 sprintf (buf
, "range [%s..%s] includes element `%s' in case expression",
1636 enum_name_string (TREE_OPERAND (new_value
, 0), type
),
1637 enum_name_string (TREE_OPERAND (new_value
, 1), type
),
1638 enum_name_string (old_value
, type
));
1640 sprintf (buf
, "range [%d..%d] includes (%d) in case expression",
1641 TREE_INT_CST_LOW (TREE_OPERAND (new_value
, 0)),
1642 TREE_INT_CST_LOW (TREE_OPERAND (new_value
, 1)),
1643 TREE_INT_CST_LOW (old_value
));
1646 else if (TREE_CODE (old_value
) == RANGE_EXPR
)
1648 char *buf
= (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type
)));
1649 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1650 sprintf (buf
, "range [%s..%s] includes element `%s' in case expression",
1651 enum_name_string (TREE_OPERAND (old_value
, 0), type
),
1652 enum_name_string (TREE_OPERAND (old_value
, 1), type
),
1653 enum_name_string (new_value
, type
));
1655 sprintf (buf
, "range [%d..%d] includes (%d) in case expression",
1656 TREE_INT_CST_LOW (TREE_OPERAND (old_value
, 0)),
1657 TREE_INT_CST_LOW (TREE_OPERAND (old_value
, 1)),
1658 TREE_INT_CST_LOW (new_value
));
1663 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1664 error ("duplicate label `%s' in switch statement",
1665 enum_name_string (new_value
, type
));
1667 error ("duplicate label (%d) in switch statement",
1668 TREE_INT_CST_LOW (new_value
));
1673 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1674 warning ("case value out of range for enum %s",
1675 TYPE_NAME_STRING (type
));
1677 warning ("case value out of range");
1681 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1682 error ("range values `%s' and `%s' reversed",
1683 enum_name_string (new_value
, type
),
1684 enum_name_string (old_value
, type
));
1686 error ("range values reversed");
1692 check_for_new_type (string
, inptree
)
1694 flagged_type_tree inptree
;
1696 if (pedantic
&& inptree
.new_type_flag
)
1697 pedwarn ("ANSI C++ forbids defining types within %s",string
);