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
);
136 if (TREE_CODE (decl
) == RESULT_DECL
)
139 if (TREE_CODE (decl
) == VAR_DECL
)
140 cp_error ("cannot declare variable `%D' to be of type `%T'",
142 else if (TREE_CODE (decl
) == PARM_DECL
)
143 cp_error ("cannot declare parameter `%D' to be of type `%T'",
145 else if (TREE_CODE (decl
) == FIELD_DECL
)
146 cp_error ("cannot declare field `%D' to be of type `%T'",
148 else if (TREE_CODE (decl
) == FUNCTION_DECL
149 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
)
150 cp_error ("invalid return type for method `%#D'", decl
);
151 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
152 cp_error ("invalid return type for function `%#D'", decl
);
154 else cp_error ("cannot allocate an object of type `%T'", type
);
155 /* Only go through this once. */
156 if (TREE_PURPOSE (u
) == NULL_TREE
)
158 error (" since the following virtual functions are abstract:");
159 TREE_PURPOSE (u
) = error_mark_node
;
162 cp_error ("\t%#D", TREE_VALUE (u
));
166 else cp_error (" since type `%T' has abstract virtual functions", type
);
169 /* Print an error message for invalid use of a signature type.
170 Signatures are treated similar to abstract classes here, they
171 cannot be instantiated. */
174 signature_error (decl
, type
)
180 if (TREE_CODE (decl
) == RESULT_DECL
)
183 if (TREE_CODE (decl
) == VAR_DECL
)
184 cp_error ("cannot declare variable `%D' to be of signature type `%T'",
186 else if (TREE_CODE (decl
) == PARM_DECL
)
187 cp_error ("cannot declare parameter `%D' to be of signature type `%T'",
189 else if (TREE_CODE (decl
) == FIELD_DECL
)
190 cp_error ("cannot declare field `%D' to be of signature type `%T'",
192 else if (TREE_CODE (decl
) == FUNCTION_DECL
193 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
)
194 cp_error ("invalid return type for method `%#D'", decl
);
195 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
196 cp_error ("invalid return type for function `%#D'", decl
);
199 cp_error ("cannot allocate an object of signature type `%T'", type
);
202 /* Print an error message for invalid use of an incomplete type.
203 VALUE is the expression that was used (or 0 if that isn't known)
204 and TYPE is the type that was invalid. */
207 incomplete_type_error (value
, type
)
213 /* Avoid duplicate error message. */
214 if (TREE_CODE (type
) == ERROR_MARK
)
217 if (value
!= 0 && (TREE_CODE (value
) == VAR_DECL
218 || TREE_CODE (value
) == PARM_DECL
))
219 cp_error ("`%D' has incomplete type", value
);
223 /* We must print an error message. Be clever about what it says. */
225 switch (TREE_CODE (type
))
230 errmsg
= "invalid use of undefined type `%#T'";
234 error ("invalid use of void expression");
238 if (TYPE_DOMAIN (type
))
240 type
= TREE_TYPE (type
);
243 error ("invalid use of array with unspecified bounds");
247 error ("invalid use of member type (did you forget the `&' ?)");
251 my_friendly_abort (108);
254 cp_error (errmsg
, type
);
258 /* Like error(), but don't call report_error_function(). */
266 extern char * progname
;
269 fprintf (stderr
, "%s:%d: ", input_filename
, lineno
);
271 fprintf (stderr
, "%s: ", progname
);
273 fprintf (stderr
, s
, v
, v2
);
274 fprintf (stderr
, "\n");
277 /* There are times when the compiler can get very confused, confused
278 to the point of giving up by aborting, simply because of previous
279 input errors. It is much better to have the user go back and
280 correct those errors first, and see if it makes us happier, than it
281 is to abort on him. This is because when one has a 10,000 line
282 program, and the compiler comes back with ``core dump'', the user
283 is left not knowing even where to begin to fix things and no place
284 to even try and work around things.
286 The parameter is to uniquely identify the problem to the user, so
287 that they can say, I am having problem 59, and know that fix 7 will
288 probably solve their problem. Or, we can document what problem
289 59 is, so they can understand how to work around it, should they
292 Note, there will be no more calls in the C++ front end to abort,
293 because the C++ front end is so unreliable still. The C front end
294 can get away with calling abort, because for most of the calls to
295 abort on most machines, it, I suspect, can be proven that it is
296 impossible to ever call abort. The same is not yet true for C++,
297 one day, maybe it will be.
299 We used to tell people to "fix the above error[s] and try recompiling
300 the program" via a call to fatal, but that message tended to look
301 silly. So instead, we just do the equivalent of a call to fatal in the
302 same situation (call exit). */
304 /* First used: 0 (reserved), Last used: 369. Free: */
306 static int abortcount
= 0;
309 my_friendly_abort (i
)
312 /* if the previous error came through here, i.e. report_error_function
313 ended up calling us again, don't just exit; we want a diagnostic of
316 current_function_decl
= NULL_TREE
;
317 else if (errorcount
> 0 || sorrycount
> 0)
322 ack ("Internal compiler error.");
324 ack ("Internal compiler error %d.", i
);
325 ack ("Please submit a full bug report to `egcs-bugs@cygnus.com'.");
328 error ("confused by earlier errors, bailing out");
335 error ("Internal compiler error.");
337 error ("Internal compiler error %d.", i
);
339 fatal ("Please submit a full bug report to `egcs-bugs@cygnus.com'.");
343 my_friendly_assert (cond
, where
)
347 my_friendly_abort (where
);
350 /* Return nonzero if VALUE is a valid constant-valued expression
351 for use in initializing a static variable; one that can be an
352 element of a "constant" initializer.
354 Return null_pointer_node if the value is absolute;
355 if it is relocatable, return the variable that determines the relocation.
356 We assume that VALUE has been folded as much as possible;
357 therefore, we do not need to check for such things as
358 arithmetic-combinations of integers. */
361 initializer_constant_valid_p (value
, endtype
)
365 switch (TREE_CODE (value
))
368 if (TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
369 && TREE_CONSTANT (value
))
371 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value
)),
374 return TREE_STATIC (value
) ? null_pointer_node
: 0;
380 return null_pointer_node
;
383 return TREE_OPERAND (value
, 0);
385 case NON_LVALUE_EXPR
:
386 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
390 /* Allow conversions between pointer types. */
391 if (TREE_CODE (TREE_TYPE (value
)) == POINTER_TYPE
392 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == POINTER_TYPE
)
393 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
395 /* Allow conversions between real types. */
396 if (TREE_CODE (TREE_TYPE (value
)) == REAL_TYPE
397 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == REAL_TYPE
)
398 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
400 /* Allow length-preserving conversions between integer types. */
401 if (TREE_CODE (TREE_TYPE (value
)) == INTEGER_TYPE
402 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == INTEGER_TYPE
403 && (TYPE_PRECISION (TREE_TYPE (value
))
404 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
405 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
407 /* Allow conversions between other integer types only if
409 if (TREE_CODE (TREE_TYPE (value
)) == INTEGER_TYPE
410 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == INTEGER_TYPE
)
412 tree inner
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
414 if (inner
== null_pointer_node
)
415 return null_pointer_node
;
419 /* Allow (int) &foo provided int is as wide as a pointer. */
420 if (TREE_CODE (TREE_TYPE (value
)) == INTEGER_TYPE
421 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == POINTER_TYPE
422 && (TYPE_PRECISION (TREE_TYPE (value
))
423 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
424 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
427 /* Likewise conversions from int to pointers. */
428 if (TREE_CODE (TREE_TYPE (value
)) == POINTER_TYPE
429 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == INTEGER_TYPE
430 && (TYPE_PRECISION (TREE_TYPE (value
))
431 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
432 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
435 /* Allow conversions to union types if the value inside is okay. */
436 if (TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
)
437 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
442 if ((TREE_CODE (endtype
) == INTEGER_TYPE
)
443 && (TYPE_PRECISION (endtype
) < POINTER_SIZE
))
446 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
448 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
450 /* If either term is absolute, use the other terms relocation. */
451 if (valid0
== null_pointer_node
)
453 if (valid1
== null_pointer_node
)
459 if ((TREE_CODE (endtype
) == INTEGER_TYPE
)
460 && (TYPE_PRECISION (endtype
) < POINTER_SIZE
))
463 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
465 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
467 /* Win if second argument is absolute. */
468 if (valid1
== null_pointer_node
)
470 /* Win if both arguments have the same relocation.
471 Then the value is absolute. */
472 if (valid0
== valid1
)
473 return null_pointer_node
;
484 /* Perform appropriate conversions on the initial value of a variable,
485 store it in the declaration DECL,
486 and print any error messages that are appropriate.
487 If the init is invalid, store an ERROR_MARK.
489 C++: Note that INIT might be a TREE_LIST, which would mean that it is
490 a base class initializer for some aggregate type, hopefully compatible
491 with DECL. If INIT is a single element, and DECL is an aggregate
492 type, we silently convert INIT into a TREE_LIST, allowing a constructor
495 If INIT is a TREE_LIST and there is no constructor, turn INIT
496 into a CONSTRUCTOR and use standard initialization techniques.
497 Perhaps a warning should be generated?
499 Returns value of initializer if initialization could not be
500 performed for static variable. In that case, caller must do
504 store_init_value (decl
, init
)
507 register tree value
, type
;
509 /* If variable's type was invalidly declared, just ignore it. */
511 type
= TREE_TYPE (decl
);
512 if (TREE_CODE (type
) == ERROR_MARK
)
516 /* This breaks arrays, and should not have any effect for other decls. */
517 /* Take care of C++ business up here. */
518 type
= TYPE_MAIN_VARIANT (type
);
521 if (IS_AGGR_TYPE (type
))
523 if (! TYPE_HAS_TRIVIAL_INIT_REF (type
)
524 && TREE_CODE (init
) != CONSTRUCTOR
)
525 my_friendly_abort (109);
527 /* Although we are not allowed to declare variables of signature
528 type, we complain about a possible constructor call in such a
529 declaration as well. */
530 if (TREE_CODE (init
) == TREE_LIST
531 && IS_SIGNATURE (type
))
533 cp_error ("constructor syntax cannot be used with signature type `%T'",
535 init
= error_mark_node
;
537 else if (TREE_CODE (init
) == TREE_LIST
)
539 cp_error ("constructor syntax used, but no constructor declared for type `%T'", type
);
540 init
= build_nt (CONSTRUCTOR
, NULL_TREE
, nreverse (init
));
543 if (TREE_CODE (init
) == CONSTRUCTOR
)
547 /* Check that we're really an aggregate as ARM 8.4.1 defines it. */
548 if (CLASSTYPE_N_BASECLASSES (type
))
549 cp_error_at ("initializer list construction invalid for derived class object `%D'", decl
);
550 if (CLASSTYPE_VTBL_PTR (type
))
551 cp_error_at ("initializer list construction invalid for polymorphic class object `%D'", decl
);
552 if (TYPE_NEEDS_CONSTRUCTING (type
))
554 cp_error_at ("initializer list construction invalid for `%D'", decl
);
555 error ("due to the presence of a constructor");
557 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
558 if (TREE_PRIVATE (field
) || TREE_PROTECTED (field
))
560 cp_error_at ("initializer list construction invalid for `%D'", decl
);
561 cp_error_at ("due to non-public access of member `%D'", field
);
563 for (field
= TYPE_METHODS (type
); field
; field
= TREE_CHAIN (field
))
564 if (TREE_PRIVATE (field
) || TREE_PROTECTED (field
))
566 cp_error_at ("initializer list construction invalid for `%D'", decl
);
567 cp_error_at ("due to non-public access of member `%D'", field
);
572 else if (TREE_CODE (init
) == TREE_LIST
573 && TREE_TYPE (init
) != unknown_type_node
)
575 if (TREE_CODE (decl
) == RESULT_DECL
)
577 if (TREE_CHAIN (init
))
579 warning ("comma expression used to initialize return value");
580 init
= build_compound_expr (init
);
583 init
= TREE_VALUE (init
);
585 else if (TREE_TYPE (init
) != 0
586 && TREE_CODE (TREE_TYPE (init
)) == OFFSET_TYPE
)
588 /* Use the type of our variable to instantiate
589 the type of our initializer. */
590 init
= instantiate_type (type
, init
, 1);
592 else if (TREE_CODE (init
) == TREE_LIST
593 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
595 error ("cannot initialize arrays using this syntax");
600 /* We get here with code like `int a (2);' */
602 if (TREE_CHAIN (init
) != NULL_TREE
)
604 pedwarn ("initializer list being treated as compound expression");
605 init
= build_compound_expr (init
);
608 init
= TREE_VALUE (init
);
612 if (TYPE_PTRMEMFUNC_P (type
) && TREE_CODE (init
) == CONSTRUCTOR
613 && TREE_TYPE (init
) == NULL_TREE
)
614 cp_pedwarn ("initializer list for `%T'", type
);
616 /* End of special C++ code. */
618 /* Digest the specified initializer into an expression. */
620 value
= digest_init (type
, init
, (tree
*) 0);
622 /* Store the expression if valid; else report error. */
624 if (TREE_CODE (value
) == ERROR_MARK
)
626 /* Other code expects that initializers for objects of types that need
627 constructing never make it into DECL_INITIAL, and passes 'init' to
628 expand_aggr_init without checking DECL_INITIAL. So just return. */
629 else if (TYPE_NEEDS_CONSTRUCTING (type
))
631 else if (TREE_STATIC (decl
)
632 && (! TREE_CONSTANT (value
)
633 || ! initializer_constant_valid_p (value
, TREE_TYPE (value
))
635 /* A STATIC PUBLIC int variable doesn't have to be
636 run time inited when doing pic. (mrs) */
637 /* Since ctors and dtors are the only things that can
638 reference vtables, and they are always written down
639 the the vtable definition, we can leave the
640 vtables in initialized data space.
641 However, other initialized data cannot be initialized
642 this way. Instead a global file-level initializer
644 || (flag_pic
&& !DECL_VIRTUAL_P (decl
) && TREE_PUBLIC (decl
))
649 #if 0 /* No, that's C. jason 9/19/94 */
652 if (pedantic
&& TREE_CODE (value
) == CONSTRUCTOR
653 /* Don't complain about non-constant initializers of
654 signature tables and signature pointers/references. */
655 && ! (TYPE_LANG_SPECIFIC (type
)
656 && (IS_SIGNATURE (type
)
657 || IS_SIGNATURE_POINTER (type
)
658 || IS_SIGNATURE_REFERENCE (type
))))
660 if (! TREE_CONSTANT (value
) || ! TREE_STATIC (value
))
661 pedwarn ("ANSI C++ forbids non-constant aggregate initializer expressions");
665 DECL_INITIAL (decl
) = value
;
669 /* Digest the parser output INIT as an initializer for type TYPE.
670 Return a C expression of type TYPE to represent the initial value.
672 If TAIL is nonzero, it points to a variable holding a list of elements
673 of which INIT is the first. We update the list stored there by
674 removing from the head all the elements that we use.
675 Normally this is only one; we use more than one element only if
676 TYPE is an aggregate and INIT is not a constructor. */
679 digest_init (type
, init
, tail
)
680 tree type
, init
, *tail
;
682 enum tree_code code
= TREE_CODE (type
);
683 tree element
= NULL_TREE
;
684 tree old_tail_contents
;
685 /* Nonzero if INIT is a braced grouping, which comes in as a CONSTRUCTOR
686 tree node which has no TREE_TYPE. */
689 /* By default, assume we use one element from a list.
690 We correct this later in the sole case where it is not true. */
694 old_tail_contents
= *tail
;
695 *tail
= TREE_CHAIN (*tail
);
698 if (init
== error_mark_node
|| (TREE_CODE (init
) == TREE_LIST
699 && TREE_VALUE (init
) == error_mark_node
))
700 return error_mark_node
;
702 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
703 if (TREE_CODE (init
) == NON_LVALUE_EXPR
)
704 init
= TREE_OPERAND (init
, 0);
706 if (init
&& TREE_TYPE (init
) && TYPE_PTRMEMFUNC_P (type
))
707 init
= default_conversion (init
);
709 if (init
&& TYPE_PTRMEMFUNC_P (type
)
710 && ((TREE_CODE (init
) == ADDR_EXPR
711 && ((TREE_CODE (TREE_TYPE (init
)) == POINTER_TYPE
712 && TREE_CODE (TREE_TYPE (TREE_TYPE (init
))) == METHOD_TYPE
)
713 || TREE_CODE (TREE_OPERAND (init
, 0)) == TREE_LIST
))
714 || TREE_CODE (init
) == TREE_LIST
715 || integer_zerop (init
)
716 || (TREE_TYPE (init
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (init
)))))
718 return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type
), init
, 0);
721 raw_constructor
= TREE_CODE (init
) == CONSTRUCTOR
&& TREE_TYPE (init
) == 0;
723 if (init
&& raw_constructor
724 && CONSTRUCTOR_ELTS (init
) != 0
725 && TREE_CHAIN (CONSTRUCTOR_ELTS (init
)) == 0)
727 element
= TREE_VALUE (CONSTRUCTOR_ELTS (init
));
728 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
729 if (element
&& TREE_CODE (element
) == NON_LVALUE_EXPR
)
730 element
= TREE_OPERAND (element
, 0);
731 if (element
== error_mark_node
)
735 /* Any type can be initialized from an expression of the same type,
736 optionally with braces. */
738 if (init
&& TREE_TYPE (init
)
739 && (TYPE_MAIN_VARIANT (TREE_TYPE (init
)) == type
740 || (code
== ARRAY_TYPE
&& comptypes (TREE_TYPE (init
), type
, 1))))
742 if (pedantic
&& code
== ARRAY_TYPE
743 && TREE_CODE (init
) != STRING_CST
)
744 pedwarn ("ANSI C++ forbids initializing array from array expression");
745 if (TREE_CODE (init
) == CONST_DECL
)
746 init
= DECL_INITIAL (init
);
747 else if (TREE_READONLY_DECL_P (init
))
748 init
= decl_constant_value (init
);
749 else if (IS_AGGR_TYPE (type
) && TYPE_NEEDS_CONSTRUCTING (type
))
750 init
= ocp_convert (type
, init
, CONV_IMPLICIT
|CONV_FORCE_TEMP
,
755 if (element
&& (TREE_TYPE (element
) == type
756 || (code
== ARRAY_TYPE
&& TREE_TYPE (element
)
757 && comptypes (TREE_TYPE (element
), type
, 1))))
759 if (pedantic
&& code
== ARRAY_TYPE
)
760 pedwarn ("ANSI C++ forbids initializing array from array expression");
761 if (pedantic
&& (code
== RECORD_TYPE
|| code
== UNION_TYPE
))
762 pedwarn ("ANSI C++ forbids single nonscalar initializer with braces");
763 if (TREE_CODE (element
) == CONST_DECL
)
764 element
= DECL_INITIAL (element
);
765 else if (TREE_READONLY_DECL_P (element
))
766 element
= decl_constant_value (element
);
770 /* Initialization of an array of chars from a string constant
771 optionally enclosed in braces. */
773 if (code
== ARRAY_TYPE
)
775 tree typ1
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
776 if ((typ1
== char_type_node
777 || typ1
== signed_char_type_node
778 || typ1
== unsigned_char_type_node
779 || typ1
== unsigned_wchar_type_node
780 || typ1
== signed_wchar_type_node
)
781 && ((init
&& TREE_CODE (init
) == STRING_CST
)
782 || (element
&& TREE_CODE (element
) == STRING_CST
)))
784 tree string
= element
? element
: init
;
786 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string
)))
788 && TYPE_PRECISION (typ1
) == BITS_PER_UNIT
)
790 error ("char-array initialized from wide string");
791 return error_mark_node
;
793 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string
)))
795 && TYPE_PRECISION (typ1
) != BITS_PER_UNIT
)
797 error ("int-array initialized from non-wide string");
798 return error_mark_node
;
802 && typ1
!= char_type_node
803 && typ1
!= signed_char_type_node
804 && typ1
!= unsigned_char_type_node
)
805 pedwarn ("ANSI C++ forbids string initializer except for `char' elements");
806 TREE_TYPE (string
) = type
;
807 if (TYPE_DOMAIN (type
) != 0
808 && TREE_CONSTANT (TYPE_SIZE (type
)))
811 = TREE_INT_CST_LOW (TYPE_SIZE (type
));
812 size
= (size
+ BITS_PER_UNIT
- 1) / BITS_PER_UNIT
;
813 /* In C it is ok to subtract 1 from the length of the string
814 because it's ok to ignore the terminating null char that is
815 counted in the length of the constant, but in C++ this would
817 if (size
< TREE_STRING_LENGTH (string
))
818 pedwarn ("initializer-string for array of chars is too long");
824 /* Handle scalar types, including conversions,
825 and signature pointers and references. */
827 if (code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== POINTER_TYPE
828 || code
== ENUMERAL_TYPE
|| code
== REFERENCE_TYPE
829 || code
== BOOLEAN_TYPE
|| code
== COMPLEX_TYPE
830 || (code
== RECORD_TYPE
&& ! raw_constructor
831 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
))))
837 error ("initializer for scalar variable requires one element");
838 return error_mark_node
;
842 while (TREE_CODE (init
) == CONSTRUCTOR
843 && ! (TREE_TYPE (init
)
844 && TYPE_PTRMEMFUNC_P (TREE_TYPE (init
))))
846 cp_pedwarn ("braces around scalar initializer for `%T'", type
);
847 init
= CONSTRUCTOR_ELTS (init
);
848 if (TREE_CHAIN (init
))
849 cp_pedwarn ("ignoring extra initializers for `%T'", type
);
850 init
= TREE_VALUE (init
);
853 return convert_for_initialization (0, type
, init
, LOOKUP_NORMAL
,
854 "initialization", NULL_TREE
, 0);
857 /* Come here only for records and arrays (and unions with constructors). */
859 if (TYPE_SIZE (type
) && ! TREE_CONSTANT (TYPE_SIZE (type
)))
861 cp_error ("variable-sized object of type `%T' may not be initialized",
863 return error_mark_node
;
866 if (code
== ARRAY_TYPE
|| code
== RECORD_TYPE
|| code
== UNION_TYPE
)
868 if (raw_constructor
&& TYPE_NON_AGGREGATE_CLASS (type
))
870 cp_error ("subobject of type `%T' must be initialized by constructor, not by `%E'",
872 return error_mark_node
;
874 else if (raw_constructor
)
875 return process_init_constructor (type
, init
, (tree
*)0);
876 else if (TYPE_NON_AGGREGATE_CLASS (type
))
878 int flags
= LOOKUP_NORMAL
;
879 /* Initialization from { } is copy-initialization. */
881 flags
|= LOOKUP_ONLYCONVERTING
;
882 return convert_for_initialization (0, type
, init
, flags
,
883 "initialization", NULL_TREE
, 0);
887 *tail
= old_tail_contents
;
888 return process_init_constructor (type
, 0, tail
);
891 if (code
!= ARRAY_TYPE
)
892 return convert_for_initialization (NULL_TREE
, type
, init
, LOOKUP_NORMAL
,
893 "initialization", NULL_TREE
, 0);
896 error ("invalid initializer");
897 return error_mark_node
;
900 /* Process a constructor for a variable of type TYPE.
901 The constructor elements may be specified either with INIT or with ELTS,
902 only one of which should be non-null.
904 If INIT is specified, it is a CONSTRUCTOR node which is specifically
905 and solely for initializing this datum.
907 If ELTS is specified, it is the address of a variable containing
908 a list of expressions. We take as many elements as we need
909 from the head of the list and update the list.
911 In the resulting constructor, TREE_CONSTANT is set if all elts are
912 constant, and TREE_STATIC is set if, in addition, all elts are simple enough
913 constants that the assembler and linker can compute them. */
916 process_init_constructor (type
, init
, elts
)
917 tree type
, init
, *elts
;
920 /* List of the elements of the result constructor,
922 register tree members
= NULL
;
928 /* Make TAIL be the list of elements to use for the initialization,
929 no matter how the data was given to us. */
933 if (warn_missing_braces
)
934 warning ("aggregate has a partly bracketed initializer");
938 tail
= CONSTRUCTOR_ELTS (init
);
940 /* Gobble as many elements as needed, and make a constructor or initial value
941 for each element of this aggregate. Chain them together in result.
942 If there are too few, use 0 for each scalar ultimate component. */
944 if (TREE_CODE (type
) == ARRAY_TYPE
)
946 tree domain
= TYPE_DOMAIN (type
);
951 len
= (TREE_INT_CST_LOW (TYPE_MAX_VALUE (domain
))
952 - TREE_INT_CST_LOW (TYPE_MIN_VALUE (domain
))
955 len
= -1; /* Take as many as there are */
957 for (i
= 0; (len
< 0 || i
< len
) && tail
!= 0; i
++)
961 if (TREE_VALUE (tail
) != 0)
964 next1
= digest_init (TYPE_MAIN_VARIANT (TREE_TYPE (type
)),
965 TREE_VALUE (tail
), &tail1
);
966 if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (type
))
967 && TYPE_MAIN_VARIANT (TREE_TYPE (type
)) != TYPE_MAIN_VARIANT (TREE_TYPE (next1
)))
969 /* The fact this needs to be done suggests this code needs
970 to be totally rewritten. */
971 next1
= convert_for_initialization (NULL_TREE
, TREE_TYPE (type
), next1
, LOOKUP_NORMAL
, "initialization", NULL_TREE
, 0);
973 my_friendly_assert (tail1
== 0
974 || TREE_CODE (tail1
) == TREE_LIST
, 319);
975 if (tail
== tail1
&& len
< 0)
977 error ("non-empty initializer for array of empty elements");
978 /* Just ignore what we were supposed to use. */
985 next1
= error_mark_node
;
986 tail
= TREE_CHAIN (tail
);
989 if (next1
== error_mark_node
)
991 else if (!TREE_CONSTANT (next1
))
993 else if (! initializer_constant_valid_p (next1
, TREE_TYPE (next1
)))
995 members
= expr_tree_cons (NULL_TREE
, next1
, members
);
998 if (TREE_CODE (type
) == RECORD_TYPE
)
1000 register tree field
;
1004 if (TYPE_USES_VIRTUAL_BASECLASSES (type
))
1006 sorry ("initializer list for object of class with virtual baseclasses");
1007 return error_mark_node
;
1010 if (TYPE_BINFO_BASETYPES (type
))
1012 sorry ("initializer list for object of class with baseclasses");
1013 return error_mark_node
;
1016 if (TYPE_VIRTUAL_P (type
))
1018 sorry ("initializer list for object using virtual functions");
1019 return error_mark_node
;
1023 for (field
= TYPE_FIELDS (type
); field
&& tail
;
1024 field
= TREE_CHAIN (field
))
1026 register tree next1
;
1028 if (! DECL_NAME (field
))
1030 members
= expr_tree_cons (field
, integer_zero_node
, members
);
1034 if (TREE_CODE (field
) != FIELD_DECL
)
1037 if (TREE_VALUE (tail
) != 0)
1041 next1
= digest_init (TREE_TYPE (field
),
1042 TREE_VALUE (tail
), &tail1
);
1043 my_friendly_assert (tail1
== 0
1044 || TREE_CODE (tail1
) == TREE_LIST
, 320);
1049 next1
= error_mark_node
;
1050 tail
= TREE_CHAIN (tail
);
1053 if (next1
== error_mark_node
)
1055 else if (!TREE_CONSTANT (next1
))
1057 else if (! initializer_constant_valid_p (next1
, TREE_TYPE (next1
)))
1059 members
= expr_tree_cons (field
, next1
, members
);
1061 for (; field
; field
= TREE_CHAIN (field
))
1063 if (TREE_CODE (field
) != FIELD_DECL
)
1066 /* Does this field have a default initialization? */
1067 if (DECL_INITIAL (field
))
1069 register tree next1
= DECL_INITIAL (field
);
1070 if (TREE_CODE (next1
) == ERROR_MARK
)
1072 else if (!TREE_CONSTANT (next1
))
1074 else if (! initializer_constant_valid_p (next1
, TREE_TYPE (next1
)))
1076 members
= expr_tree_cons (field
, next1
, members
);
1078 else if (TREE_READONLY (field
))
1079 error ("uninitialized const member `%s'",
1080 IDENTIFIER_POINTER (DECL_NAME (field
)));
1081 else if (TYPE_LANG_SPECIFIC (TREE_TYPE (field
))
1082 && CLASSTYPE_READONLY_FIELDS_NEED_INIT (TREE_TYPE (field
)))
1083 error ("member `%s' with uninitialized const fields",
1084 IDENTIFIER_POINTER (DECL_NAME (field
)));
1085 else if (TREE_CODE (TREE_TYPE (field
)) == REFERENCE_TYPE
)
1086 error ("member `%s' is uninitialized reference",
1087 IDENTIFIER_POINTER (DECL_NAME (field
)));
1091 if (TREE_CODE (type
) == UNION_TYPE
)
1093 register tree field
= TYPE_FIELDS (type
);
1094 register tree next1
;
1096 /* Find the first named field. ANSI decided in September 1990
1097 that only named fields count here. */
1098 while (field
&& (DECL_NAME (field
) == 0
1099 || TREE_CODE (field
) != FIELD_DECL
))
1100 field
= TREE_CHAIN (field
);
1102 /* If this element specifies a field, initialize via that field. */
1103 if (TREE_PURPOSE (tail
) != NULL_TREE
)
1107 if (TREE_CODE (TREE_PURPOSE (tail
)) == FIELD_DECL
)
1108 /* Handle the case of a call by build_c_cast. */
1109 field
= TREE_PURPOSE (tail
), win
= 1;
1110 else if (TREE_CODE (TREE_PURPOSE (tail
)) != IDENTIFIER_NODE
)
1111 error ("index value instead of field name in union initializer");
1115 for (temp
= TYPE_FIELDS (type
);
1117 temp
= TREE_CHAIN (temp
))
1118 if (DECL_NAME (temp
) == TREE_PURPOSE (tail
))
1121 field
= temp
, win
= 1;
1123 error ("no field `%s' in union being initialized",
1124 IDENTIFIER_POINTER (TREE_PURPOSE (tail
)));
1127 TREE_VALUE (tail
) = error_mark_node
;
1129 else if (field
== 0)
1131 cp_error ("union `%T' with no named members cannot be initialized",
1133 TREE_VALUE (tail
) = error_mark_node
;
1136 if (TREE_VALUE (tail
) != 0)
1140 next1
= digest_init (TREE_TYPE (field
),
1141 TREE_VALUE (tail
), &tail1
);
1142 if (tail1
!= 0 && TREE_CODE (tail1
) != TREE_LIST
)
1143 my_friendly_abort (357);
1148 next1
= error_mark_node
;
1149 tail
= TREE_CHAIN (tail
);
1152 if (next1
== error_mark_node
)
1154 else if (!TREE_CONSTANT (next1
))
1156 else if (initializer_constant_valid_p (next1
, TREE_TYPE (next1
)) == 0)
1158 members
= expr_tree_cons (field
, next1
, members
);
1161 /* If arguments were specified as a list, just remove the ones we used. */
1164 /* If arguments were specified as a constructor,
1165 complain unless we used all the elements of the constructor. */
1167 pedwarn ("excess elements in aggregate initializer");
1170 return error_mark_node
;
1172 result
= build (CONSTRUCTOR
, type
, NULL_TREE
, nreverse (members
));
1174 TREE_HAS_CONSTRUCTOR (result
) = TREE_HAS_CONSTRUCTOR (init
);
1175 if (allconstant
) TREE_CONSTANT (result
) = 1;
1176 if (allconstant
&& allsimple
) TREE_STATIC (result
) = 1;
1180 /* Given a structure or union value DATUM, construct and return
1181 the structure or union component which results from narrowing
1182 that value by the type specified in BASETYPE. For example, given the
1185 class L { int ii; };
1186 class A : L { ... };
1187 class B : L { ... };
1188 class C : A, B { ... };
1196 x.A::ii refers to the ii member of the L part of
1197 of A part of the C object named by X. In this case,
1198 DATUM would be x, and BASETYPE would be A. */
1201 build_scoped_ref (datum
, basetype
)
1206 tree type
= TREE_TYPE (datum
);
1208 if (datum
== error_mark_node
)
1209 return error_mark_node
;
1211 if (TREE_CODE (type
) == REFERENCE_TYPE
)
1212 type
= TREE_TYPE (type
);
1214 type
= TYPE_MAIN_VARIANT (type
);
1216 /* This is an easy conversion. */
1217 if (is_aggr_type (basetype
, 1))
1219 tree binfo
= TYPE_BINFO (basetype
);
1220 if (binfo
!= TYPE_BINFO (type
))
1222 binfo
= get_binfo (binfo
, type
, 1);
1223 if (binfo
== error_mark_node
)
1224 return error_mark_node
;
1226 return error_not_base_type (basetype
, type
);
1229 switch (TREE_CODE (datum
))
1234 case FIX_TRUNC_EXPR
:
1235 case FIX_FLOOR_EXPR
:
1236 case FIX_ROUND_EXPR
:
1238 ref
= convert_pointer_to (binfo
,
1239 build_unary_op (ADDR_EXPR
, TREE_OPERAND (datum
, 0), 0));
1242 ref
= convert_pointer_to (binfo
,
1243 build_unary_op (ADDR_EXPR
, datum
, 0));
1245 return build_indirect_ref (ref
, "(compiler error in build_scoped_ref)");
1247 return error_mark_node
;
1250 /* Build a reference to an object specified by the C++ `->' operator.
1251 Usually this just involves dereferencing the object, but if the
1252 `->' operator is overloaded, then such overloads must be
1253 performed until an object which does not have the `->' operator
1254 overloaded is found. An error is reported when circular pointer
1255 delegation is detected. */
1258 build_x_arrow (datum
)
1261 tree types_memoized
= NULL_TREE
;
1262 register tree rval
= datum
;
1263 tree type
= TREE_TYPE (rval
);
1266 if (type
== error_mark_node
)
1267 return error_mark_node
;
1269 if (processing_template_decl
)
1270 return build_min_nt (ARROW_EXPR
, rval
);
1272 if (TREE_CODE (rval
) == OFFSET_REF
)
1274 rval
= resolve_offset_ref (datum
);
1275 type
= TREE_TYPE (rval
);
1278 if (TREE_CODE (type
) == REFERENCE_TYPE
)
1280 rval
= convert_from_reference (rval
);
1281 type
= TREE_TYPE (rval
);
1284 if (IS_AGGR_TYPE (type
) && TYPE_OVERLOADS_ARROW (complete_type (type
)))
1286 while ((rval
= build_opfncall (COMPONENT_REF
, LOOKUP_NORMAL
, rval
, NULL_TREE
, NULL_TREE
)))
1288 if (rval
== error_mark_node
)
1289 return error_mark_node
;
1291 if (value_member (TREE_TYPE (rval
), types_memoized
))
1293 error ("circular pointer delegation detected");
1294 return error_mark_node
;
1298 types_memoized
= tree_cons (NULL_TREE
, TREE_TYPE (rval
),
1303 if (TREE_CODE (TREE_TYPE (last_rval
)) == REFERENCE_TYPE
)
1304 last_rval
= convert_from_reference (last_rval
);
1307 last_rval
= default_conversion (rval
);
1309 /* Signature pointers are not dereferenced. */
1310 if (TYPE_LANG_SPECIFIC (TREE_TYPE (last_rval
))
1311 && IS_SIGNATURE_POINTER (TREE_TYPE (last_rval
)))
1314 if (TREE_CODE (TREE_TYPE (last_rval
)) == POINTER_TYPE
)
1315 return build_indirect_ref (last_rval
, NULL_PTR
);
1318 error ("result of `operator->()' yields non-pointer result");
1320 error ("base operand of `->' is not a pointer");
1321 return error_mark_node
;
1324 /* Make an expression to refer to the COMPONENT field of
1325 structure or union value DATUM. COMPONENT is an arbitrary
1326 expression. DATUM has not already been checked out to be of
1329 For C++, COMPONENT may be a TREE_LIST. This happens when we must
1330 return an object of member type to a method of the current class,
1331 but there is not yet enough typing information to know which one.
1332 As a special case, if there is only one method by that name,
1333 it is returned. Otherwise we return an expression which other
1334 routines will have to know how to deal with later. */
1337 build_m_component_ref (datum
, component
)
1338 tree datum
, component
;
1341 tree objtype
= TREE_TYPE (datum
);
1345 if (processing_template_decl
)
1346 return build_min_nt (DOTSTAR_EXPR
, datum
, component
);
1348 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (component
)))
1350 type
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (component
)));
1355 component
= build_indirect_ref (component
, NULL_PTR
);
1356 type
= TREE_TYPE (component
);
1357 rettype
= TREE_TYPE (type
);
1360 if (datum
== error_mark_node
|| component
== error_mark_node
)
1361 return error_mark_node
;
1363 if (TREE_CODE (type
) != OFFSET_TYPE
&& TREE_CODE (type
) != METHOD_TYPE
)
1365 cp_error ("`%E' cannot be used as a member pointer, since it is of type `%T'", component
, type
);
1366 return error_mark_node
;
1369 if (TREE_CODE (objtype
) == REFERENCE_TYPE
)
1370 objtype
= TREE_TYPE (objtype
);
1371 objtype
= TYPE_MAIN_VARIANT (objtype
);
1373 if (! IS_AGGR_TYPE (objtype
))
1375 cp_error ("cannot apply member pointer `%E' to `%E'", component
, datum
);
1376 cp_error ("which is of non-aggregate type `%T'", objtype
);
1377 return error_mark_node
;
1380 binfo
= get_binfo (TYPE_METHOD_BASETYPE (type
), objtype
, 1);
1381 if (binfo
== NULL_TREE
)
1383 cp_error ("member type `%T::' incompatible with object type `%T'",
1384 TYPE_METHOD_BASETYPE (type
), objtype
);
1385 return error_mark_node
;
1387 else if (binfo
== error_mark_node
)
1388 return error_mark_node
;
1390 component
= build (OFFSET_REF
, rettype
, datum
, component
);
1391 if (TREE_CODE (type
) == OFFSET_TYPE
)
1392 component
= resolve_offset_ref (component
);
1396 /* Return a tree node for the expression TYPENAME '(' PARMS ')'. */
1399 build_functional_cast (exp
, parms
)
1403 /* This is either a call to a constructor,
1404 or a C cast in C++'s `functional' notation. */
1407 if (exp
== error_mark_node
|| parms
== error_mark_node
)
1408 return error_mark_node
;
1410 if (TREE_CODE (exp
) == IDENTIFIER_NODE
)
1412 if (IDENTIFIER_HAS_TYPE_VALUE (exp
))
1413 /* Either an enum or an aggregate type. */
1414 type
= IDENTIFIER_TYPE_VALUE (exp
);
1417 type
= lookup_name (exp
, 1);
1418 if (!type
|| TREE_CODE (type
) != TYPE_DECL
)
1420 cp_error ("`%T' fails to be a typedef or built-in type", exp
);
1421 return error_mark_node
;
1423 type
= TREE_TYPE (type
);
1426 else if (TREE_CODE (exp
) == TYPE_DECL
)
1427 type
= TREE_TYPE (exp
);
1431 if (processing_template_decl
)
1432 return build_min (CAST_EXPR
, type
, parms
);
1434 if (IS_SIGNATURE (type
))
1436 error ("signature type not allowed in cast or constructor expression");
1437 return error_mark_node
;
1440 if (! IS_AGGR_TYPE (type
))
1442 /* this must build a C cast */
1443 if (parms
== NULL_TREE
)
1444 parms
= integer_zero_node
;
1447 if (TREE_CHAIN (parms
) != NULL_TREE
)
1448 pedwarn ("initializer list being treated as compound expression");
1449 parms
= build_compound_expr (parms
);
1452 return build_c_cast (type
, parms
);
1455 /* Prepare to evaluate as a call to a constructor. If this expression
1456 is actually used, for example,
1458 return X (arg1, arg2, ...);
1460 then the slot being initialized will be filled in. */
1462 if (TYPE_SIZE (complete_type (type
)) == NULL_TREE
)
1464 cp_error ("type `%T' is not yet defined", type
);
1465 return error_mark_node
;
1468 if (parms
&& TREE_CHAIN (parms
) == NULL_TREE
)
1469 return build_c_cast (type
, TREE_VALUE (parms
));
1471 exp
= build_method_call (NULL_TREE
, ctor_identifier
, parms
,
1472 TYPE_BINFO (type
), LOOKUP_NORMAL
);
1474 if (exp
== error_mark_node
)
1475 return error_mark_node
;
1477 return build_cplus_new (type
, exp
);
1480 /* Return the character string for the name that encodes the
1481 enumeral value VALUE in the domain TYPE. */
1484 enum_name_string (value
, type
)
1488 register tree values
= TYPE_VALUES (type
);
1489 register HOST_WIDE_INT intval
= TREE_INT_CST_LOW (value
);
1491 my_friendly_assert (TREE_CODE (type
) == ENUMERAL_TYPE
, 324);
1493 && TREE_INT_CST_LOW (TREE_VALUE (values
)) != intval
)
1494 values
= TREE_CHAIN (values
);
1495 if (values
== NULL_TREE
)
1497 char *buf
= (char *)oballoc (16 + TYPE_NAME_LENGTH (type
));
1499 /* Value must have been cast. */
1500 sprintf (buf
, "(enum %s)%d",
1501 TYPE_NAME_STRING (type
), intval
);
1504 return IDENTIFIER_POINTER (TREE_PURPOSE (values
));
1508 /* Print out a language-specific error message for
1509 (Pascal) case or (C) switch statements.
1510 CODE tells what sort of message to print.
1511 TYPE is the type of the switch index expression.
1512 NEW is the new value that we were trying to add.
1513 OLD is the old value that stopped us from adding it. */
1516 report_case_error (code
, type
, new_value
, old_value
)
1519 tree new_value
, old_value
;
1524 error ("case label not within a switch statement");
1526 error ("default label not within a switch statement");
1532 error ("multiple default labels in one switch");
1535 if (TREE_CODE (new_value
) == RANGE_EXPR
)
1536 if (TREE_CODE (old_value
) == RANGE_EXPR
)
1538 char *buf
= (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type
)));
1539 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1540 sprintf (buf
, "overlapping ranges [%s..%s], [%s..%s] in case expression",
1541 enum_name_string (TREE_OPERAND (new_value
, 0), type
),
1542 enum_name_string (TREE_OPERAND (new_value
, 1), type
),
1543 enum_name_string (TREE_OPERAND (old_value
, 0), type
),
1544 enum_name_string (TREE_OPERAND (old_value
, 1), type
));
1546 sprintf (buf
, "overlapping ranges [%d..%d], [%d..%d] in case expression",
1547 TREE_INT_CST_LOW (TREE_OPERAND (new_value
, 0)),
1548 TREE_INT_CST_LOW (TREE_OPERAND (new_value
, 1)),
1549 TREE_INT_CST_LOW (TREE_OPERAND (old_value
, 0)),
1550 TREE_INT_CST_LOW (TREE_OPERAND (old_value
, 1)));
1555 char *buf
= (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type
)));
1556 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1557 sprintf (buf
, "range [%s..%s] includes element `%s' in case expression",
1558 enum_name_string (TREE_OPERAND (new_value
, 0), type
),
1559 enum_name_string (TREE_OPERAND (new_value
, 1), type
),
1560 enum_name_string (old_value
, type
));
1562 sprintf (buf
, "range [%d..%d] includes (%d) in case expression",
1563 TREE_INT_CST_LOW (TREE_OPERAND (new_value
, 0)),
1564 TREE_INT_CST_LOW (TREE_OPERAND (new_value
, 1)),
1565 TREE_INT_CST_LOW (old_value
));
1568 else if (TREE_CODE (old_value
) == RANGE_EXPR
)
1570 char *buf
= (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type
)));
1571 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1572 sprintf (buf
, "range [%s..%s] includes element `%s' in case expression",
1573 enum_name_string (TREE_OPERAND (old_value
, 0), type
),
1574 enum_name_string (TREE_OPERAND (old_value
, 1), type
),
1575 enum_name_string (new_value
, type
));
1577 sprintf (buf
, "range [%d..%d] includes (%d) in case expression",
1578 TREE_INT_CST_LOW (TREE_OPERAND (old_value
, 0)),
1579 TREE_INT_CST_LOW (TREE_OPERAND (old_value
, 1)),
1580 TREE_INT_CST_LOW (new_value
));
1585 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1586 error ("duplicate label `%s' in switch statement",
1587 enum_name_string (new_value
, type
));
1589 error ("duplicate label (%d) in switch statement",
1590 TREE_INT_CST_LOW (new_value
));
1595 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1596 warning ("case value out of range for enum %s",
1597 TYPE_NAME_STRING (type
));
1599 warning ("case value out of range");
1603 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1604 error ("range values `%s' and `%s' reversed",
1605 enum_name_string (new_value
, type
),
1606 enum_name_string (old_value
, type
));
1608 error ("range values reversed");
1614 check_for_new_type (string
, inptree
)
1616 flagged_type_tree inptree
;
1618 if (pedantic
&& inptree
.new_type_flag
)
1619 pedwarn ("ANSI C++ forbids defining types within %s",string
);