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 ();
40 extern void pedwarn (), error ();
42 extern int errorcount;
43 extern int sorrycount;
45 /* Print an error message stemming from an attempt to use
46 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 /* Print an error message stemming from an invalid use of an
77 TYPE is the type or binfo which draws the error.
78 MSG is the message to print.
79 ARG is an optional argument which may provide more information. */
81 error_with_aggr_type (type, msg, arg)
88 if (TREE_CODE (type) == TREE_VEC)
89 type = BINFO_TYPE (type);
91 name = TYPE_NAME (type);
92 if (TREE_CODE (name) == TYPE_DECL)
93 name = DECL_NAME (name);
94 error (msg, IDENTIFIER_POINTER (name), arg);
97 /* According to ARM $7.1.6, "A `const' object may be initialized, but its
98 value may not be changed thereafter. Thus, we emit hard errors for these,
99 rather than just pedwarns. If `SOFT' is 1, then we just pedwarn. (For
100 example, conversions to references.) */
102 readonly_error (arg, string, soft)
115 if (TREE_CODE (arg) == COMPONENT_REF)
117 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0))))
118 fmt = "%s of member `%s' in read-only structure";
120 fmt = "%s of read-only member `%s'";
121 (*fn) (fmt, string, lang_printable_name (TREE_OPERAND (arg, 1)));
123 else if (TREE_CODE (arg) == VAR_DECL)
125 if (DECL_LANG_SPECIFIC (arg)
126 && DECL_IN_AGGR_P (arg)
127 && !TREE_STATIC (arg))
128 fmt = "%s of constant field `%s'";
130 fmt = "%s of read-only variable `%s'";
131 (*fn) (fmt, string, lang_printable_name (arg));
133 else if (TREE_CODE (arg) == PARM_DECL)
134 (*fn) ("%s of read-only parameter `%s'", string,
135 lang_printable_name (arg));
136 else if (TREE_CODE (arg) == INDIRECT_REF
137 && TREE_CODE (TREE_TYPE (TREE_OPERAND (arg, 0))) == REFERENCE_TYPE
138 && (TREE_CODE (TREE_OPERAND (arg, 0)) == VAR_DECL
139 || TREE_CODE (TREE_OPERAND (arg, 0)) == PARM_DECL))
140 (*fn) ("%s of read-only reference `%s'",
141 string, lang_printable_name (TREE_OPERAND (arg, 0)));
142 else if (TREE_CODE (arg) == RESULT_DECL)
143 (*fn) ("%s of read-only named return value `%s'",
144 string, lang_printable_name (arg));
146 (*fn) ("%s of read-only location", string);
149 /* Print an error message for invalid use of a type which declares
150 virtual functions which are not inheritable. */
152 abstract_virtuals_error (decl, type)
156 tree u = CLASSTYPE_ABSTRACT_VIRTUALS (type);
160 if (TREE_CODE (decl) == RESULT_DECL)
163 if (TREE_CODE (decl) == VAR_DECL)
164 cp_error ("cannot declare variable `%D' to be of type `%T'",
166 else if (TREE_CODE (decl) == PARM_DECL)
167 cp_error ("cannot declare parameter `%D' to be of type `%T'",
169 else if (TREE_CODE (decl) == FIELD_DECL)
170 cp_error ("cannot declare field `%D' to be of type `%T'",
172 else if (TREE_CODE (decl) == FUNCTION_DECL
173 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
174 cp_error ("invalid return type for method `%#D'", decl);
175 else if (TREE_CODE (decl) == FUNCTION_DECL)
176 cp_error ("invalid return type for function `%#D'", decl);
178 else cp_error ("cannot allocate an object of type `%T'", type);
179 /* Only go through this once. */
180 if (TREE_PURPOSE (u) == NULL_TREE)
182 error (" since the following virtual functions are abstract:");
183 TREE_PURPOSE (u) = error_mark_node;
186 cp_error ("\t%#D", TREE_VALUE (u));
190 else cp_error (" since type `%T' has abstract virtual functions", type);
193 /* Print an error message for invalid use of a signature type.
194 Signatures are treated similar to abstract classes here, they
195 cannot be instantiated. */
197 signature_error (decl, type)
203 if (TREE_CODE (decl) == RESULT_DECL)
206 if (TREE_CODE (decl) == VAR_DECL)
207 cp_error ("cannot declare variable `%D' to be of signature type `%T'",
209 else if (TREE_CODE (decl) == PARM_DECL)
210 cp_error ("cannot declare parameter `%D' to be of signature type `%T'",
212 else if (TREE_CODE (decl) == FIELD_DECL)
213 cp_error ("cannot declare field `%D' to be of signature type `%T'",
215 else if (TREE_CODE (decl) == FUNCTION_DECL
216 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
217 cp_error ("invalid return type for method `%#D'", decl);
218 else if (TREE_CODE (decl) == FUNCTION_DECL)
219 cp_error ("invalid return type for function `%#D'", decl);
222 cp_error ("cannot allocate an object of signature type `%T'", type);
225 /* Print an error message for invalid use of an incomplete type.
226 VALUE is the expression that was used (or 0 if that isn't known)
227 and TYPE is the type that was invalid. */
230 incomplete_type_error (value, type)
236 /* Avoid duplicate error message. */
237 if (TREE_CODE (type) == ERROR_MARK)
240 if (value != 0 && (TREE_CODE (value) == VAR_DECL
241 || TREE_CODE (value) == PARM_DECL))
242 error ("`%s' has an incomplete type",
243 IDENTIFIER_POINTER (DECL_NAME (value)));
247 /* We must print an error message. Be clever about what it says. */
249 switch (TREE_CODE (type))
252 errmsg = "invalid use of undefined type `struct %s'";
256 errmsg = "invalid use of undefined type `union %s'";
260 errmsg = "invalid use of undefined type `enum %s'";
264 error ("invalid use of void expression");
268 if (TYPE_DOMAIN (type))
270 type = TREE_TYPE (type);
273 error ("invalid use of array with unspecified bounds");
277 error ("invalid use of member type (did you forget the `&' ?)");
281 my_friendly_abort (108);
284 error_with_aggr_type (type, errmsg);
288 /* Like error(), but don't call report_error_function(). */
295 extern char * progname;
298 fprintf (stderr, "%s:%d: ", input_filename, lineno);
300 fprintf (stderr, "%s: ", progname);
302 fprintf (stderr, s, v, v2);
303 fprintf (stderr, "\n");
306 /* There are times when the compiler can get very confused, confused
307 to the point of giving up by aborting, simply because of previous
308 input errors. It is much better to have the user go back and
309 correct those errors first, and see if it makes us happier, than it
310 is to abort on him. This is because when one has a 10,000 line
311 program, and the compiler comes back with ``core dump'', the user
312 is left not knowing even where to begin to fix things and no place
313 to even try and work around things.
315 The parameter is to uniquely identify the problem to the user, so
316 that they can say, I am having problem 59, and know that fix 7 will
317 probably solve their problem. Or, we can document what problem
318 59 is, so they can understand how to work around it, should they
321 Note, there will be no more calls in the C++ front end to abort,
322 because the C++ front end is so unreliable still. The C front end
323 can get away with calling abort, because for most of the calls to
324 abort on most machines, it, I suspect, can be proven that it is
325 impossible to ever call abort. The same is not yet true for C++,
326 one day, maybe it will be.
328 We used to tell people to "fix the above error[s] and try recompiling
329 the program" via a call to fatal, but that message tended to look
330 silly. So instead, we just do the equivalent of a call to fatal in the
331 same situation (call exit). */
333 /* First used: 0 (reserved), Last used: 366. Free: */
335 static int abortcount = 0;
338 my_friendly_abort (i)
341 /* if the previous error came through here, i.e. report_error_function
342 ended up calling us again, don't just exit; we want a diagnostic of
345 current_function_decl = NULL_TREE;
346 else if (errorcount > 0 || sorrycount > 0)
351 ack ("Internal compiler error.");
353 ack ("Internal compiler error %d.", i);
354 ack ("Please submit a full bug report to `bug-g++@prep.ai.mit.edu'.");
357 error ("confused by earlier errors, bailing out");
364 error ("Internal compiler error.");
366 error ("Internal compiler error %d.", i);
368 fatal ("Please submit a full bug report to `bug-g++@prep.ai.mit.edu'.");
372 my_friendly_assert (cond, where)
376 my_friendly_abort (where);
379 /* Return nonzero if VALUE is a valid constant-valued expression
380 for use in initializing a static variable; one that can be an
381 element of a "constant" initializer.
383 Return null_pointer_node if the value is absolute;
384 if it is relocatable, return the variable that determines the relocation.
385 We assume that VALUE has been folded as much as possible;
386 therefore, we do not need to check for such things as
387 arithmetic-combinations of integers. */
390 initializer_constant_valid_p (value, endtype)
394 switch (TREE_CODE (value))
397 if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
398 && TREE_CONSTANT (value))
400 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)),
403 return TREE_STATIC (value) ? null_pointer_node : 0;
409 return null_pointer_node;
412 return TREE_OPERAND (value, 0);
414 case NON_LVALUE_EXPR:
415 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
419 /* Allow conversions between pointer types. */
420 if (TREE_CODE (TREE_TYPE (value)) == POINTER_TYPE
421 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == POINTER_TYPE)
422 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
424 /* Allow conversions between real types. */
425 if (TREE_CODE (TREE_TYPE (value)) == REAL_TYPE
426 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == REAL_TYPE)
427 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
429 /* Allow length-preserving conversions between integer types. */
430 if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
431 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE
432 && (TYPE_PRECISION (TREE_TYPE (value))
433 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
434 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
436 /* Allow conversions between other integer types only if
438 if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
439 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE)
441 tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0),
443 if (inner == null_pointer_node)
444 return null_pointer_node;
448 /* Allow (int) &foo provided int is as wide as a pointer. */
449 if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
450 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == POINTER_TYPE
451 && (TYPE_PRECISION (TREE_TYPE (value))
452 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
453 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
456 /* Likewise conversions from int to pointers. */
457 if (TREE_CODE (TREE_TYPE (value)) == POINTER_TYPE
458 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE
459 && (TYPE_PRECISION (TREE_TYPE (value))
460 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
461 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
464 /* Allow conversions to union types if the value inside is okay. */
465 if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
466 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
471 if ((TREE_CODE (endtype) == INTEGER_TYPE)
472 && (TYPE_PRECISION (endtype) < POINTER_SIZE))
475 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
477 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
479 /* If either term is absolute, use the other terms relocation. */
480 if (valid0 == null_pointer_node)
482 if (valid1 == null_pointer_node)
488 if ((TREE_CODE (endtype) == INTEGER_TYPE)
489 && (TYPE_PRECISION (endtype) < POINTER_SIZE))
492 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
494 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
496 /* Win if second argument is absolute. */
497 if (valid1 == null_pointer_node)
499 /* Win if both arguments have the same relocation.
500 Then the value is absolute. */
501 if (valid0 == valid1)
502 return null_pointer_node;
510 /* Perform appropriate conversions on the initial value of a variable,
511 store it in the declaration DECL,
512 and print any error messages that are appropriate.
513 If the init is invalid, store an ERROR_MARK.
515 C++: Note that INIT might be a TREE_LIST, which would mean that it is
516 a base class initializer for some aggregate type, hopefully compatible
517 with DECL. If INIT is a single element, and DECL is an aggregate
518 type, we silently convert INIT into a TREE_LIST, allowing a constructor
521 If INIT is a TREE_LIST and there is no constructor, turn INIT
522 into a CONSTRUCTOR and use standard initialization techniques.
523 Perhaps a warning should be generated?
525 Returns value of initializer if initialization could not be
526 performed for static variable. In that case, caller must do
530 store_init_value (decl, init)
533 register tree value, type;
535 /* If variable's type was invalidly declared, just ignore it. */
537 type = TREE_TYPE (decl);
538 if (TREE_CODE (type) == ERROR_MARK)
542 /* This breaks arrays, and should not have any effect for other decls. */
543 /* Take care of C++ business up here. */
544 type = TYPE_MAIN_VARIANT (type);
547 if (IS_AGGR_TYPE (type))
549 if (! TYPE_HAS_TRIVIAL_INIT_REF (type)
550 && TREE_CODE (init) != CONSTRUCTOR)
551 my_friendly_abort (109);
553 /* Although we are not allowed to declare variables of signature
554 type, we complain about a possible constructor call in such a
555 declaration as well. */
556 if (TREE_CODE (init) == TREE_LIST
557 && IS_SIGNATURE (type))
559 cp_error ("constructor syntax cannot be used with signature type `%T'",
561 init = error_mark_node;
563 else if (TREE_CODE (init) == TREE_LIST)
565 cp_error ("constructor syntax used, but no constructor declared for type `%T'", type);
566 init = build_nt (CONSTRUCTOR, NULL_TREE, nreverse (init));
569 if (TREE_CODE (init) == CONSTRUCTOR)
573 /* Check that we're really an aggregate as ARM 8.4.1 defines it. */
574 if (CLASSTYPE_N_BASECLASSES (type))
575 cp_error_at ("initializer list construction invalid for derived class object `%D'", decl);
576 if (CLASSTYPE_VTBL_PTR (type))
577 cp_error_at ("initializer list construction invalid for polymorphic class object `%D'", decl);
578 if (TYPE_NEEDS_CONSTRUCTING (type))
580 cp_error_at ("initializer list construction invalid for `%D'", decl);
581 error ("due to the presence of a constructor");
583 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
584 if (TREE_PRIVATE (field) || TREE_PROTECTED (field))
586 cp_error_at ("initializer list construction invalid for `%D'", decl);
587 cp_error_at ("due to non-public access of member `%D'", field);
589 for (field = TYPE_METHODS (type); field; field = TREE_CHAIN (field))
590 if (TREE_PRIVATE (field) || TREE_PROTECTED (field))
592 cp_error_at ("initializer list construction invalid for `%D'", decl);
593 cp_error_at ("due to non-public access of member `%D'", field);
598 else if (TREE_CODE (init) == TREE_LIST
599 && TREE_TYPE (init) != unknown_type_node)
601 if (TREE_CODE (decl) == RESULT_DECL)
603 if (TREE_CHAIN (init))
605 warning ("comma expression used to initialize return value");
606 init = build_compound_expr (init);
609 init = TREE_VALUE (init);
611 else if (TREE_TYPE (init) != 0
612 && TREE_CODE (TREE_TYPE (init)) == OFFSET_TYPE)
614 /* Use the type of our variable to instantiate
615 the type of our initializer. */
616 init = instantiate_type (type, init, 1);
618 else if (TREE_CODE (init) == TREE_LIST
619 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
621 error ("cannot initialize arrays using this syntax");
626 /* We get here with code like `int a (2);' */
628 if (TREE_CHAIN (init) != NULL_TREE)
630 pedwarn ("initializer list being treated as compound expression");
631 init = build_compound_expr (init);
634 init = TREE_VALUE (init);
638 /* End of special C++ code. */
640 /* Digest the specified initializer into an expression. */
642 value = digest_init (type, init, (tree *) 0);
644 /* Store the expression if valid; else report error. */
646 if (TREE_CODE (value) == ERROR_MARK)
648 else if (TREE_STATIC (decl)
649 && (! TREE_CONSTANT (value)
650 || ! initializer_constant_valid_p (value, TREE_TYPE (value))
652 /* A STATIC PUBLIC int variable doesn't have to be
653 run time inited when doing pic. (mrs) */
654 /* Since ctors and dtors are the only things that can
655 reference vtables, and they are always written down
656 the the vtable definition, we can leave the
657 vtables in initialized data space.
658 However, other initialized data cannot be initialized
659 this way. Instead a global file-level initializer
661 || (flag_pic && !DECL_VIRTUAL_P (decl) && TREE_PUBLIC (decl))
666 #if 0 /* No, that's C. jason 9/19/94 */
669 if (pedantic && TREE_CODE (value) == CONSTRUCTOR
670 /* Don't complain about non-constant initializers of
671 signature tables and signature pointers/references. */
672 && ! (TYPE_LANG_SPECIFIC (type)
673 && (IS_SIGNATURE (type)
674 || IS_SIGNATURE_POINTER (type)
675 || IS_SIGNATURE_REFERENCE (type))))
677 if (! TREE_CONSTANT (value) || ! TREE_STATIC (value))
678 pedwarn ("ANSI C++ forbids non-constant aggregate initializer expressions");
682 DECL_INITIAL (decl) = value;
686 /* Digest the parser output INIT as an initializer for type TYPE.
687 Return a C expression of type TYPE to represent the initial value.
689 If TAIL is nonzero, it points to a variable holding a list of elements
690 of which INIT is the first. We update the list stored there by
691 removing from the head all the elements that we use.
692 Normally this is only one; we use more than one element only if
693 TYPE is an aggregate and INIT is not a constructor. */
696 digest_init (type, init, tail)
697 tree type, init, *tail;
699 enum tree_code code = TREE_CODE (type);
700 tree element = NULL_TREE;
701 tree old_tail_contents;
702 /* Nonzero if INIT is a braced grouping, which comes in as a CONSTRUCTOR
703 tree node which has no TREE_TYPE. */
706 /* By default, assume we use one element from a list.
707 We correct this later in the sole case where it is not true. */
711 old_tail_contents = *tail;
712 *tail = TREE_CHAIN (*tail);
715 if (init == error_mark_node || (TREE_CODE (init) == TREE_LIST
716 && TREE_VALUE (init) == error_mark_node))
717 return error_mark_node;
719 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
720 if (TREE_CODE (init) == NON_LVALUE_EXPR)
721 init = TREE_OPERAND (init, 0);
723 if (init && TREE_TYPE (init) && TYPE_PTRMEMFUNC_P (type))
724 init = default_conversion (init);
726 if (init && TYPE_PTRMEMFUNC_P (type)
727 && ((TREE_CODE (init) == ADDR_EXPR
728 && ((TREE_CODE (TREE_TYPE (init)) == POINTER_TYPE
729 && TREE_CODE (TREE_TYPE (TREE_TYPE (init))) == METHOD_TYPE)
730 || TREE_CODE (TREE_OPERAND (init, 0)) == TREE_LIST))
731 || TREE_CODE (init) == TREE_LIST
732 || integer_zerop (init)
733 || (TREE_TYPE (init) && TYPE_PTRMEMFUNC_P (TREE_TYPE (init)))))
735 return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), init, 0);
738 raw_constructor = TREE_CODE (init) == CONSTRUCTOR && TREE_TYPE (init) == 0;
740 if (init && raw_constructor
741 && CONSTRUCTOR_ELTS (init) != 0
742 && TREE_CHAIN (CONSTRUCTOR_ELTS (init)) == 0)
744 element = TREE_VALUE (CONSTRUCTOR_ELTS (init));
745 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
746 if (element && TREE_CODE (element) == NON_LVALUE_EXPR)
747 element = TREE_OPERAND (element, 0);
748 if (element == error_mark_node)
752 /* Any type can be initialized from an expression of the same type,
753 optionally with braces. */
755 if (init && TREE_TYPE (init)
756 && (TYPE_MAIN_VARIANT (TREE_TYPE (init)) == type
757 || (code == ARRAY_TYPE && comptypes (TREE_TYPE (init), type, 1))))
759 if (pedantic && code == ARRAY_TYPE
760 && TREE_CODE (init) != STRING_CST)
761 pedwarn ("ANSI C++ forbids initializing array from array expression");
762 if (TREE_CODE (init) == CONST_DECL)
763 init = DECL_INITIAL (init);
764 else if (TREE_READONLY_DECL_P (init))
765 init = decl_constant_value (init);
769 if (element && (TREE_TYPE (element) == type
770 || (code == ARRAY_TYPE && TREE_TYPE (element)
771 && comptypes (TREE_TYPE (element), type, 1))))
773 if (pedantic && code == ARRAY_TYPE)
774 pedwarn ("ANSI C++ forbids initializing array from array expression");
775 if (pedantic && (code == RECORD_TYPE || code == UNION_TYPE))
776 pedwarn ("ANSI C++ forbids single nonscalar initializer with braces");
777 if (TREE_CODE (element) == CONST_DECL)
778 element = DECL_INITIAL (element);
779 else if (TREE_READONLY_DECL_P (element))
780 element = decl_constant_value (element);
784 /* Initialization of an array of chars from a string constant
785 optionally enclosed in braces. */
787 if (code == ARRAY_TYPE)
789 tree typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type));
790 if ((typ1 == char_type_node
791 || typ1 == signed_char_type_node
792 || typ1 == unsigned_char_type_node
793 || typ1 == unsigned_wchar_type_node
794 || typ1 == signed_wchar_type_node)
795 && ((init && TREE_CODE (init) == STRING_CST)
796 || (element && TREE_CODE (element) == STRING_CST)))
798 tree string = element ? element : init;
800 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string)))
802 && TYPE_PRECISION (typ1) == BITS_PER_UNIT)
804 error ("char-array initialized from wide string");
805 return error_mark_node;
807 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string)))
809 && TYPE_PRECISION (typ1) != BITS_PER_UNIT)
811 error ("int-array initialized from non-wide string");
812 return error_mark_node;
816 && typ1 != char_type_node
817 && typ1 != signed_char_type_node
818 && typ1 != unsigned_char_type_node)
819 pedwarn ("ANSI C++ forbids string initializer except for `char' elements");
820 TREE_TYPE (string) = type;
821 if (TYPE_DOMAIN (type) != 0
822 && TREE_CONSTANT (TYPE_SIZE (type)))
825 = TREE_INT_CST_LOW (TYPE_SIZE (type));
826 size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
827 /* In C it is ok to subtract 1 from the length of the string
828 because it's ok to ignore the terminating null char that is
829 counted in the length of the constant, but in C++ this would
831 if (size < TREE_STRING_LENGTH (string))
832 pedwarn ("initializer-string for array of chars is too long");
838 /* Handle scalar types, including conversions,
839 and signature pointers and references. */
841 if (code == INTEGER_TYPE || code == REAL_TYPE || code == POINTER_TYPE
842 || code == ENUMERAL_TYPE || code == REFERENCE_TYPE
843 || code == BOOLEAN_TYPE
844 || (code == RECORD_TYPE && ! raw_constructor
845 && (IS_SIGNATURE_POINTER (type) || IS_SIGNATURE_REFERENCE (type))))
851 error ("initializer for scalar variable requires one element");
852 return error_mark_node;
856 while (TREE_CODE (init) == CONSTRUCTOR)
858 cp_pedwarn ("braces around scalar initializer for `%T'", type);
859 init = CONSTRUCTOR_ELTS (init);
860 if (TREE_CHAIN (init))
861 cp_pedwarn ("ignoring extra initializers for `%T'", type);
862 init = TREE_VALUE (init);
865 return convert_for_initialization (0, type, init, LOOKUP_NORMAL,
866 "initialization", NULL_TREE, 0);
869 /* Come here only for records and arrays (and unions with constructors). */
871 if (TYPE_SIZE (type) && ! TREE_CONSTANT (TYPE_SIZE (type)))
873 cp_error ("variable-sized object of type `%T' may not be initialized",
875 return error_mark_node;
878 if (code == ARRAY_TYPE || code == RECORD_TYPE || code == UNION_TYPE)
880 if (raw_constructor && TYPE_NON_AGGREGATE_CLASS (type))
882 cp_error ("subobject of type `%T' must be initialized by constructor, not by `%E'",
884 return error_mark_node;
886 else if (raw_constructor)
887 return process_init_constructor (type, init, (tree *)0);
888 else if (TYPE_NON_AGGREGATE_CLASS (type))
891 /* This isn't true. */
892 /* This can only be reached when caller is initializing
893 ARRAY_TYPE. In that case, we don't want to convert
894 INIT to TYPE. We will let `expand_vec_init' do it. */
897 return convert_for_initialization (0, type, init, LOOKUP_NORMAL,
898 "initialization", NULL_TREE, 0);
903 *tail = old_tail_contents;
904 return process_init_constructor (type, 0, tail);
906 else if (flag_traditional)
907 /* Traditionally one can say `char x[100] = 0;'. */
908 return process_init_constructor (type,
909 build_nt (CONSTRUCTOR, 0,
910 tree_cons (0, init, 0)),
912 if (code != ARRAY_TYPE)
913 return convert_for_initialization (0, type, init, LOOKUP_NORMAL,
914 "initialization", NULL_TREE, 0);
917 error ("invalid initializer");
918 return error_mark_node;
921 /* Process a constructor for a variable of type TYPE.
922 The constructor elements may be specified either with INIT or with ELTS,
923 only one of which should be non-null.
925 If INIT is specified, it is a CONSTRUCTOR node which is specifically
926 and solely for initializing this datum.
928 If ELTS is specified, it is the address of a variable containing
929 a list of expressions. We take as many elements as we need
930 from the head of the list and update the list.
932 In the resulting constructor, TREE_CONSTANT is set if all elts are
933 constant, and TREE_STATIC is set if, in addition, all elts are simple enough
934 constants that the assembler and linker can compute them. */
937 process_init_constructor (type, init, elts)
938 tree type, init, *elts;
941 /* List of the elements of the result constructor,
943 register tree members = NULL;
949 /* Make TAIL be the list of elements to use for the initialization,
950 no matter how the data was given to us. */
954 if (warn_missing_braces)
955 warning ("aggregate has a partly bracketed initializer");
959 tail = CONSTRUCTOR_ELTS (init);
961 /* Gobble as many elements as needed, and make a constructor or initial value
962 for each element of this aggregate. Chain them together in result.
963 If there are too few, use 0 for each scalar ultimate component. */
965 if (TREE_CODE (type) == ARRAY_TYPE)
967 tree domain = TYPE_DOMAIN (type);
972 len = (TREE_INT_CST_LOW (TYPE_MAX_VALUE (domain))
973 - TREE_INT_CST_LOW (TYPE_MIN_VALUE (domain))
976 len = -1; /* Take as many as there are */
978 for (i = 0; (len < 0 || i < len) && tail != 0; i++)
982 if (TREE_VALUE (tail) != 0)
985 next1 = digest_init (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
986 TREE_VALUE (tail), &tail1);
987 if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (type))
988 && TYPE_MAIN_VARIANT (TREE_TYPE (type)) != TYPE_MAIN_VARIANT (TREE_TYPE (next1)))
990 /* The fact this needs to be done suggests this code needs
991 to be totally rewritten. */
992 next1 = convert_for_initialization (NULL_TREE, TREE_TYPE (type), next1, LOOKUP_NORMAL, "initialization", NULL_TREE, 0);
994 my_friendly_assert (tail1 == 0
995 || TREE_CODE (tail1) == TREE_LIST, 319);
996 if (tail == tail1 && len < 0)
998 error ("non-empty initializer for array of empty elements");
999 /* Just ignore what we were supposed to use. */
1006 next1 = error_mark_node;
1007 tail = TREE_CHAIN (tail);
1010 if (next1 == error_mark_node)
1012 else if (!TREE_CONSTANT (next1))
1014 else if (! initializer_constant_valid_p (next1, TREE_TYPE (next1)))
1016 members = tree_cons (NULL_TREE, next1, members);
1019 if (TREE_CODE (type) == RECORD_TYPE)
1021 register tree field;
1025 if (TYPE_USES_VIRTUAL_BASECLASSES (type))
1027 sorry ("initializer list for object of class with virtual baseclasses");
1028 return error_mark_node;
1031 if (TYPE_BINFO_BASETYPES (type))
1033 sorry ("initializer list for object of class with baseclasses");
1034 return error_mark_node;
1037 if (TYPE_VIRTUAL_P (type))
1039 sorry ("initializer list for object using virtual functions");
1040 return error_mark_node;
1044 for (field = TYPE_FIELDS (type); field && tail;
1045 field = TREE_CHAIN (field))
1047 register tree next1;
1049 if (! DECL_NAME (field))
1051 members = tree_cons (field, integer_zero_node, members);
1055 if (TREE_CODE (field) != FIELD_DECL)
1058 if (TREE_VALUE (tail) != 0)
1062 next1 = digest_init (TREE_TYPE (field),
1063 TREE_VALUE (tail), &tail1);
1064 my_friendly_assert (tail1 == 0
1065 || TREE_CODE (tail1) == TREE_LIST, 320);
1070 next1 = error_mark_node;
1071 tail = TREE_CHAIN (tail);
1074 if (next1 == error_mark_node)
1076 else if (!TREE_CONSTANT (next1))
1078 else if (! initializer_constant_valid_p (next1, TREE_TYPE (next1)))
1080 members = tree_cons (field, next1, members);
1082 for (; field; field = TREE_CHAIN (field))
1084 if (TREE_CODE (field) != FIELD_DECL)
1087 /* Does this field have a default initialization? */
1088 if (DECL_INITIAL (field))
1090 register tree next1 = DECL_INITIAL (field);
1091 if (TREE_CODE (next1) == ERROR_MARK)
1093 else if (!TREE_CONSTANT (next1))
1095 else if (! initializer_constant_valid_p (next1, TREE_TYPE (next1)))
1097 members = tree_cons (field, next1, members);
1099 else if (TREE_READONLY (field))
1100 error ("uninitialized const member `%s'",
1101 IDENTIFIER_POINTER (DECL_NAME (field)));
1102 else if (TYPE_LANG_SPECIFIC (TREE_TYPE (field))
1103 && CLASSTYPE_READONLY_FIELDS_NEED_INIT (TREE_TYPE (field)))
1104 error ("member `%s' with uninitialized const fields",
1105 IDENTIFIER_POINTER (DECL_NAME (field)));
1106 else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
1107 error ("member `%s' is uninitialized reference",
1108 IDENTIFIER_POINTER (DECL_NAME (field)));
1112 if (TREE_CODE (type) == UNION_TYPE)
1114 register tree field = TYPE_FIELDS (type);
1115 register tree next1;
1117 /* Find the first named field. ANSI decided in September 1990
1118 that only named fields count here. */
1119 while (field && DECL_NAME (field) == 0)
1120 field = TREE_CHAIN (field);
1122 /* If this element specifies a field, initialize via that field. */
1123 if (TREE_PURPOSE (tail) != NULL_TREE)
1127 if (TREE_CODE (TREE_PURPOSE (tail)) == FIELD_DECL)
1128 /* Handle the case of a call by build_c_cast. */
1129 field = TREE_PURPOSE (tail), win = 1;
1130 else if (TREE_CODE (TREE_PURPOSE (tail)) != IDENTIFIER_NODE)
1131 error ("index value instead of field name in union initializer");
1135 for (temp = TYPE_FIELDS (type);
1137 temp = TREE_CHAIN (temp))
1138 if (DECL_NAME (temp) == TREE_PURPOSE (tail))
1141 field = temp, win = 1;
1143 error ("no field `%s' in union being initialized",
1144 IDENTIFIER_POINTER (TREE_PURPOSE (tail)));
1147 TREE_VALUE (tail) = error_mark_node;
1149 else if (field == 0)
1151 cp_error ("union `%T' with no named members cannot be initialized",
1153 TREE_VALUE (tail) = error_mark_node;
1156 if (TREE_VALUE (tail) != 0)
1160 next1 = digest_init (TREE_TYPE (field),
1161 TREE_VALUE (tail), &tail1);
1162 if (tail1 != 0 && TREE_CODE (tail1) != TREE_LIST)
1163 my_friendly_abort (357);
1168 next1 = error_mark_node;
1169 tail = TREE_CHAIN (tail);
1172 if (next1 == error_mark_node)
1174 else if (!TREE_CONSTANT (next1))
1176 else if (initializer_constant_valid_p (next1, TREE_TYPE (next1)) == 0)
1178 members = tree_cons (field, next1, members);
1181 /* If arguments were specified as a list, just remove the ones we used. */
1184 /* If arguments were specified as a constructor,
1185 complain unless we used all the elements of the constructor. */
1187 pedwarn ("excess elements in aggregate initializer");
1190 return error_mark_node;
1192 result = build (CONSTRUCTOR, type, NULL_TREE, nreverse (members));
1194 TREE_HAS_CONSTRUCTOR (result) = TREE_HAS_CONSTRUCTOR (init);
1195 if (allconstant) TREE_CONSTANT (result) = 1;
1196 if (allconstant && allsimple) TREE_STATIC (result) = 1;
1200 /* Given a structure or union value DATUM, construct and return
1201 the structure or union component which results from narrowing
1202 that value by the type specified in BASETYPE. For example, given the
1205 class L { int ii; };
1206 class A : L { ... };
1207 class B : L { ... };
1208 class C : A, B { ... };
1216 x.A::ii refers to the ii member of the L part of
1217 of A part of the C object named by X. In this case,
1218 DATUM would be x, and BASETYPE would be A.
1223 build_scoped_ref (datum, basetype)
1228 tree type = TREE_TYPE (datum);
1230 if (datum == error_mark_node)
1231 return error_mark_node;
1233 if (TREE_CODE (type) == REFERENCE_TYPE)
1234 type = TREE_TYPE (type);
1236 type = TYPE_MAIN_VARIANT (type);
1238 /* This is an easy conversion. */
1239 if (is_aggr_type (basetype, 1))
1241 tree binfo = TYPE_BINFO (basetype);
1242 if (binfo != TYPE_BINFO (type))
1244 binfo = get_binfo (binfo, type, 1);
1245 if (binfo == error_mark_node)
1246 return error_mark_node;
1248 return error_not_base_type (basetype, type);
1251 switch (TREE_CODE (datum))
1256 case FIX_TRUNC_EXPR:
1257 case FIX_FLOOR_EXPR:
1258 case FIX_ROUND_EXPR:
1260 ref = convert_pointer_to (binfo,
1261 build_unary_op (ADDR_EXPR, TREE_OPERAND (datum, 0), 0));
1264 ref = convert_pointer_to (binfo,
1265 build_unary_op (ADDR_EXPR, datum, 0));
1267 return build_indirect_ref (ref, "(compiler error in build_scoped_ref)");
1269 return error_mark_node;
1272 /* Build a reference to an object specified by the C++ `->' operator.
1273 Usually this just involves dereferencing the object, but if the
1274 `->' operator is overloaded, then such overloads must be
1275 performed until an object which does not have the `->' operator
1276 overloaded is found. An error is reported when circular pointer
1277 delegation is detected. */
1279 build_x_arrow (datum)
1282 tree types_memoized = NULL_TREE;
1283 register tree rval = datum;
1284 tree type = TREE_TYPE (rval);
1287 if (type == error_mark_node)
1288 return error_mark_node;
1290 if (current_template_parms)
1291 return build_min_nt (ARROW_EXPR, rval);
1293 if (TREE_CODE (rval) == OFFSET_REF)
1295 rval = resolve_offset_ref (datum);
1296 type = TREE_TYPE (rval);
1299 if (TREE_CODE (type) == REFERENCE_TYPE)
1301 rval = convert_from_reference (rval);
1302 type = TREE_TYPE (rval);
1305 if (IS_AGGR_TYPE (type) && TYPE_OVERLOADS_ARROW (complete_type (type)))
1307 while ((rval = build_opfncall (COMPONENT_REF, LOOKUP_NORMAL, rval, NULL_TREE, NULL_TREE)))
1309 if (rval == error_mark_node)
1310 return error_mark_node;
1312 if (value_member (TREE_TYPE (rval), types_memoized))
1314 error ("circular pointer delegation detected");
1315 return error_mark_node;
1319 types_memoized = tree_cons (NULL_TREE, TREE_TYPE (rval),
1324 if (TREE_CODE (TREE_TYPE (last_rval)) == REFERENCE_TYPE)
1325 last_rval = convert_from_reference (last_rval);
1328 last_rval = default_conversion (rval);
1330 /* Signature pointers are not dereferenced. */
1331 if (TYPE_LANG_SPECIFIC (TREE_TYPE (last_rval))
1332 && IS_SIGNATURE_POINTER (TREE_TYPE (last_rval)))
1335 if (TREE_CODE (TREE_TYPE (last_rval)) == POINTER_TYPE)
1336 return build_indirect_ref (last_rval, NULL_PTR);
1339 error ("result of `operator->()' yields non-pointer result");
1341 error ("base operand of `->' is not a pointer");
1342 return error_mark_node;
1345 /* Make an expression to refer to the COMPONENT field of
1346 structure or union value DATUM. COMPONENT is an arbitrary
1347 expression. DATUM has not already been checked out to be of
1350 For C++, COMPONENT may be a TREE_LIST. This happens when we must
1351 return an object of member type to a method of the current class,
1352 but there is not yet enough typing information to know which one.
1353 As a special case, if there is only one method by that name,
1354 it is returned. Otherwise we return an expression which other
1355 routines will have to know how to deal with later. */
1357 build_m_component_ref (datum, component)
1358 tree datum, component;
1361 tree objtype = TREE_TYPE (datum);
1365 if (current_template_parms)
1366 return build_min_nt (DOTSTAR_EXPR, datum, component);
1368 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (component)))
1370 type = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (component)));
1375 component = build_indirect_ref (component, NULL_PTR);
1376 type = TREE_TYPE (component);
1377 rettype = TREE_TYPE (TREE_TYPE (component));
1380 if (datum == error_mark_node || component == error_mark_node)
1381 return error_mark_node;
1383 if (TREE_CODE (type) != OFFSET_TYPE && TREE_CODE (type) != METHOD_TYPE)
1385 cp_error ("`%E' cannot be used as a member pointer, since it is of type `%T'", component, type);
1386 return error_mark_node;
1389 if (TREE_CODE (objtype) == REFERENCE_TYPE)
1390 objtype = TREE_TYPE (objtype);
1391 objtype = TYPE_MAIN_VARIANT (objtype);
1393 if (! IS_AGGR_TYPE (objtype))
1395 cp_error ("cannot apply member pointer `%E' to `%E'", component, datum);
1396 cp_error ("which is of non-aggregate type `%T'", objtype);
1397 return error_mark_node;
1400 binfo = get_binfo (TYPE_METHOD_BASETYPE (type), objtype, 1);
1401 if (binfo == NULL_TREE)
1403 cp_error ("member type `%T::' incompatible with object type `%T'",
1404 TYPE_METHOD_BASETYPE (type), objtype);
1405 return error_mark_node;
1407 else if (binfo == error_mark_node)
1408 return error_mark_node;
1410 return build (OFFSET_REF, rettype, datum, component);
1413 /* Return a tree node for the expression TYPENAME '(' PARMS ')'.
1415 Because we cannot tell whether this construct is really a call to a
1416 constructor or a request for a type conversion, we try both, and
1417 report any ambiguities we find. */
1419 build_functional_cast (exp, parms)
1423 /* This is either a call to a constructor,
1424 or a C cast in C++'s `functional' notation. */
1425 tree type, name = NULL_TREE;
1426 tree expr_as_ctor = NULL_TREE;
1428 if (exp == error_mark_node || parms == error_mark_node)
1429 return error_mark_node;
1431 if (TREE_CODE (exp) == IDENTIFIER_NODE)
1435 if (IDENTIFIER_HAS_TYPE_VALUE (exp))
1436 /* Either an enum or an aggregate type. */
1437 type = IDENTIFIER_TYPE_VALUE (exp);
1440 type = lookup_name (exp, 1);
1441 if (!type || TREE_CODE (type) != TYPE_DECL)
1443 cp_error ("`%T' fails to be a typedef or built-in type", name);
1444 return error_mark_node;
1446 type = TREE_TYPE (type);
1449 else if (TREE_CODE (exp) == TYPE_DECL)
1450 type = TREE_TYPE (exp);
1454 if (current_template_parms)
1455 return build_min (CAST_EXPR, type, parms);
1457 if (IS_SIGNATURE (type))
1459 error ("signature type not allowed in cast or constructor expression");
1460 return error_mark_node;
1463 if (! IS_AGGR_TYPE (type))
1465 /* this must build a C cast */
1466 if (parms == NULL_TREE)
1467 parms = integer_zero_node;
1470 if (TREE_CHAIN (parms) != NULL_TREE)
1471 pedwarn ("initializer list being treated as compound expression");
1472 parms = build_compound_expr (parms);
1475 return build_c_cast (type, parms, 1);
1478 /* Prepare to evaluate as a call to a constructor. If this expression
1479 is actually used, for example,
1481 return X (arg1, arg2, ...);
1483 then the slot being initialized will be filled in. */
1485 if (name == NULL_TREE)
1487 name = TYPE_NAME (type);
1488 if (TREE_CODE (name) == TYPE_DECL)
1489 name = DECL_NESTED_TYPENAME (name);
1492 if (TYPE_SIZE (complete_type (type)) == NULL_TREE)
1494 cp_error ("type `%T' is not yet defined", type);
1495 return error_mark_node;
1498 if (parms && TREE_CHAIN (parms) == NULL_TREE)
1499 return build_c_cast (type, parms, 1);
1501 expr_as_ctor = build_method_call (NULL_TREE, name, parms,
1502 NULL_TREE, LOOKUP_NORMAL);
1504 if (expr_as_ctor == error_mark_node)
1505 return error_mark_node;
1507 return build_cplus_new (type, expr_as_ctor);
1510 /* Return the character string for the name that encodes the
1511 enumeral value VALUE in the domain TYPE. */
1513 enum_name_string (value, type)
1517 register tree values = TYPE_VALUES (type);
1518 register HOST_WIDE_INT intval = TREE_INT_CST_LOW (value);
1520 my_friendly_assert (TREE_CODE (type) == ENUMERAL_TYPE, 324);
1522 && TREE_INT_CST_LOW (TREE_VALUE (values)) != intval)
1523 values = TREE_CHAIN (values);
1524 if (values == NULL_TREE)
1526 char *buf = (char *)oballoc (16 + TYPE_NAME_LENGTH (type));
1528 /* Value must have been cast. */
1529 sprintf (buf, "(enum %s)%d",
1530 TYPE_NAME_STRING (type), intval);
1533 return IDENTIFIER_POINTER (TREE_PURPOSE (values));
1537 /* Print out a language-specific error message for
1538 (Pascal) case or (C) switch statements.
1539 CODE tells what sort of message to print.
1540 TYPE is the type of the switch index expression.
1541 NEW is the new value that we were trying to add.
1542 OLD is the old value that stopped us from adding it. */
1544 report_case_error (code, type, new_value, old_value)
1547 tree new_value, old_value;
1552 error ("case label not within a switch statement");
1554 error ("default label not within a switch statement");
1560 error ("multiple default labels in one switch");
1563 if (TREE_CODE (new_value) == RANGE_EXPR)
1564 if (TREE_CODE (old_value) == RANGE_EXPR)
1566 char *buf = (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type)));
1567 if (TREE_CODE (type) == ENUMERAL_TYPE)
1568 sprintf (buf, "overlapping ranges [%s..%s], [%s..%s] in case expression",
1569 enum_name_string (TREE_OPERAND (new_value, 0), type),
1570 enum_name_string (TREE_OPERAND (new_value, 1), type),
1571 enum_name_string (TREE_OPERAND (old_value, 0), type),
1572 enum_name_string (TREE_OPERAND (old_value, 1), type));
1574 sprintf (buf, "overlapping ranges [%d..%d], [%d..%d] in case expression",
1575 TREE_INT_CST_LOW (TREE_OPERAND (new_value, 0)),
1576 TREE_INT_CST_LOW (TREE_OPERAND (new_value, 1)),
1577 TREE_INT_CST_LOW (TREE_OPERAND (old_value, 0)),
1578 TREE_INT_CST_LOW (TREE_OPERAND (old_value, 1)));
1583 char *buf = (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type)));
1584 if (TREE_CODE (type) == ENUMERAL_TYPE)
1585 sprintf (buf, "range [%s..%s] includes element `%s' in case expression",
1586 enum_name_string (TREE_OPERAND (new_value, 0), type),
1587 enum_name_string (TREE_OPERAND (new_value, 1), type),
1588 enum_name_string (old_value, type));
1590 sprintf (buf, "range [%d..%d] includes (%d) in case expression",
1591 TREE_INT_CST_LOW (TREE_OPERAND (new_value, 0)),
1592 TREE_INT_CST_LOW (TREE_OPERAND (new_value, 1)),
1593 TREE_INT_CST_LOW (old_value));
1596 else if (TREE_CODE (old_value) == RANGE_EXPR)
1598 char *buf = (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type)));
1599 if (TREE_CODE (type) == ENUMERAL_TYPE)
1600 sprintf (buf, "range [%s..%s] includes element `%s' in case expression",
1601 enum_name_string (TREE_OPERAND (old_value, 0), type),
1602 enum_name_string (TREE_OPERAND (old_value, 1), type),
1603 enum_name_string (new_value, type));
1605 sprintf (buf, "range [%d..%d] includes (%d) in case expression",
1606 TREE_INT_CST_LOW (TREE_OPERAND (old_value, 0)),
1607 TREE_INT_CST_LOW (TREE_OPERAND (old_value, 1)),
1608 TREE_INT_CST_LOW (new_value));
1613 if (TREE_CODE (type) == ENUMERAL_TYPE)
1614 error ("duplicate label `%s' in switch statement",
1615 enum_name_string (new_value, type));
1617 error ("duplicate label (%d) in switch statement",
1618 TREE_INT_CST_LOW (new_value));
1623 if (TREE_CODE (type) == ENUMERAL_TYPE)
1624 warning ("case value out of range for enum %s",
1625 TYPE_NAME_STRING (type));
1627 warning ("case value out of range");
1631 if (TREE_CODE (type) == ENUMERAL_TYPE)
1632 error ("range values `%s' and `%s' reversed",
1633 enum_name_string (new_value, type),
1634 enum_name_string (old_value, type));
1636 error ("range values reversed");