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)
575 /* Check that we're really an aggregate as ARM 8.4.1 defines it. */
576 if (CLASSTYPE_N_BASECLASSES (type))
577 cp_error_at ("initializer list construction invalid for derived class object `%D'", decl);
578 if (CLASSTYPE_VTBL_PTR (type))
579 cp_error_at ("initializer list construction invalid for polymorphic class object `%D'", decl);
580 if (TYPE_NEEDS_CONSTRUCTING (type))
582 cp_error_at ("initializer list construction invalid for `%D'", decl);
583 error ("due to the presence of a constructor");
585 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
586 if (TREE_PRIVATE (field) || TREE_PROTECTED (field))
588 cp_error_at ("initializer list construction invalid for `%D'", decl);
589 cp_error_at ("due to non-public access of member `%D'", field);
591 funcs = TYPE_METHODS (type);
593 for (func = 0; func < TREE_VEC_LENGTH (funcs); func++)
595 field = TREE_VEC_ELT (funcs, func);
596 if (field && (TREE_PRIVATE (field) || TREE_PROTECTED (field)))
598 cp_error_at ("initializer list construction invalid for `%D'", decl);
599 cp_error_at ("due to non-public access of member `%D'", field);
605 else if (TREE_CODE (init) == TREE_LIST
606 && TREE_TYPE (init) != unknown_type_node)
608 if (TREE_CODE (decl) == RESULT_DECL)
610 if (TREE_CHAIN (init))
612 warning ("comma expression used to initialize return value");
613 init = build_compound_expr (init);
616 init = TREE_VALUE (init);
618 else if (TREE_TYPE (init) != 0
619 && TREE_CODE (TREE_TYPE (init)) == OFFSET_TYPE)
621 /* Use the type of our variable to instantiate
622 the type of our initializer. */
623 init = instantiate_type (type, init, 1);
625 else if (TREE_CODE (init) == TREE_LIST
626 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
628 error ("cannot initialize arrays using this syntax");
633 /* We get here with code like `int a (2);' */
635 if (TREE_CHAIN (init) != NULL_TREE)
637 pedwarn ("initializer list being treated as compound expression");
638 init = build_compound_expr (init);
641 init = TREE_VALUE (init);
645 /* End of special C++ code. */
647 /* Digest the specified initializer into an expression. */
649 value = digest_init (type, init, (tree *) 0);
651 /* Store the expression if valid; else report error. */
653 if (TREE_CODE (value) == ERROR_MARK)
655 else if (TREE_STATIC (decl)
656 && (! TREE_CONSTANT (value)
657 || ! initializer_constant_valid_p (value, TREE_TYPE (value))
659 /* A STATIC PUBLIC int variable doesn't have to be
660 run time inited when doing pic. (mrs) */
661 /* Since ctors and dtors are the only things that can
662 reference vtables, and they are always written down
663 the the vtable definition, we can leave the
664 vtables in initialized data space.
665 However, other initialized data cannot be initialized
666 this way. Instead a global file-level initializer
668 || (flag_pic && !DECL_VIRTUAL_P (decl) && TREE_PUBLIC (decl))
673 #if 0 /* No, that's C. jason 9/19/94 */
676 if (pedantic && TREE_CODE (value) == CONSTRUCTOR
677 /* Don't complain about non-constant initializers of
678 signature tables and signature pointers/references. */
679 && ! (TYPE_LANG_SPECIFIC (type)
680 && (IS_SIGNATURE (type)
681 || IS_SIGNATURE_POINTER (type)
682 || IS_SIGNATURE_REFERENCE (type))))
684 if (! TREE_CONSTANT (value) || ! TREE_STATIC (value))
685 pedwarn ("ANSI C++ forbids non-constant aggregate initializer expressions");
689 DECL_INITIAL (decl) = value;
693 /* Digest the parser output INIT as an initializer for type TYPE.
694 Return a C expression of type TYPE to represent the initial value.
696 If TAIL is nonzero, it points to a variable holding a list of elements
697 of which INIT is the first. We update the list stored there by
698 removing from the head all the elements that we use.
699 Normally this is only one; we use more than one element only if
700 TYPE is an aggregate and INIT is not a constructor. */
703 digest_init (type, init, tail)
704 tree type, init, *tail;
706 enum tree_code code = TREE_CODE (type);
707 tree element = NULL_TREE;
708 tree old_tail_contents;
709 /* Nonzero if INIT is a braced grouping, which comes in as a CONSTRUCTOR
710 tree node which has no TREE_TYPE. */
713 /* By default, assume we use one element from a list.
714 We correct this later in the sole case where it is not true. */
718 old_tail_contents = *tail;
719 *tail = TREE_CHAIN (*tail);
722 if (init == error_mark_node || (TREE_CODE (init) == TREE_LIST
723 && TREE_VALUE (init) == error_mark_node))
724 return error_mark_node;
726 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
727 if (TREE_CODE (init) == NON_LVALUE_EXPR)
728 init = TREE_OPERAND (init, 0);
730 if (init && TREE_TYPE (init) && TYPE_PTRMEMFUNC_P (type))
731 init = default_conversion (init);
733 if (init && TYPE_PTRMEMFUNC_P (type)
734 && ((TREE_CODE (init) == ADDR_EXPR
735 && ((TREE_CODE (TREE_TYPE (init)) == POINTER_TYPE
736 && TREE_CODE (TREE_TYPE (TREE_TYPE (init))) == METHOD_TYPE)
737 || TREE_CODE (TREE_OPERAND (init, 0)) == TREE_LIST))
738 || TREE_CODE (init) == TREE_LIST
739 || integer_zerop (init)
740 || (TREE_TYPE (init) && TYPE_PTRMEMFUNC_P (TREE_TYPE (init)))))
742 return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), init, 0);
745 raw_constructor = TREE_CODE (init) == CONSTRUCTOR && TREE_TYPE (init) == 0;
747 if (init && raw_constructor
748 && CONSTRUCTOR_ELTS (init) != 0
749 && TREE_CHAIN (CONSTRUCTOR_ELTS (init)) == 0)
751 element = TREE_VALUE (CONSTRUCTOR_ELTS (init));
752 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
753 if (element && TREE_CODE (element) == NON_LVALUE_EXPR)
754 element = TREE_OPERAND (element, 0);
755 if (element == error_mark_node)
759 /* Any type can be initialized from an expression of the same type,
760 optionally with braces. */
762 if (init && TREE_TYPE (init)
763 && (TYPE_MAIN_VARIANT (TREE_TYPE (init)) == type
764 || (code == ARRAY_TYPE && comptypes (TREE_TYPE (init), type, 1))))
766 if (pedantic && code == ARRAY_TYPE
767 && TREE_CODE (init) != STRING_CST)
768 pedwarn ("ANSI C++ forbids initializing array from array expression");
769 if (TREE_CODE (init) == CONST_DECL)
770 init = DECL_INITIAL (init);
771 else if (TREE_READONLY_DECL_P (init))
772 init = decl_constant_value (init);
776 if (element && (TREE_TYPE (element) == type
777 || (code == ARRAY_TYPE && TREE_TYPE (element)
778 && comptypes (TREE_TYPE (element), type, 1))))
780 if (pedantic && code == ARRAY_TYPE)
781 pedwarn ("ANSI C++ forbids initializing array from array expression");
782 if (pedantic && (code == RECORD_TYPE || code == UNION_TYPE))
783 pedwarn ("ANSI C++ forbids single nonscalar initializer with braces");
784 if (TREE_CODE (element) == CONST_DECL)
785 element = DECL_INITIAL (element);
786 else if (TREE_READONLY_DECL_P (element))
787 element = decl_constant_value (element);
791 /* Initialization of an array of chars from a string constant
792 optionally enclosed in braces. */
794 if (code == ARRAY_TYPE)
796 tree typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type));
797 if ((typ1 == char_type_node
798 || typ1 == signed_char_type_node
799 || typ1 == unsigned_char_type_node
800 || typ1 == unsigned_wchar_type_node
801 || typ1 == signed_wchar_type_node)
802 && ((init && TREE_CODE (init) == STRING_CST)
803 || (element && TREE_CODE (element) == STRING_CST)))
805 tree string = element ? element : init;
807 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string)))
809 && TYPE_PRECISION (typ1) == BITS_PER_UNIT)
811 error ("char-array initialized from wide string");
812 return error_mark_node;
814 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string)))
816 && TYPE_PRECISION (typ1) != BITS_PER_UNIT)
818 error ("int-array initialized from non-wide string");
819 return error_mark_node;
823 && typ1 != char_type_node
824 && typ1 != signed_char_type_node
825 && typ1 != unsigned_char_type_node)
826 pedwarn ("ANSI C++ forbids string initializer except for `char' elements");
827 TREE_TYPE (string) = type;
828 if (TYPE_DOMAIN (type) != 0
829 && TREE_CONSTANT (TYPE_SIZE (type)))
832 = TREE_INT_CST_LOW (TYPE_SIZE (type));
833 size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
834 /* In C it is ok to subtract 1 from the length of the string
835 because it's ok to ignore the terminating null char that is
836 counted in the length of the constant, but in C++ this would
838 if (size < TREE_STRING_LENGTH (string))
839 pedwarn ("initializer-string for array of chars is too long");
845 /* Handle scalar types, including conversions,
846 and signature pointers and references. */
848 if (code == INTEGER_TYPE || code == REAL_TYPE || code == POINTER_TYPE
849 || code == ENUMERAL_TYPE || code == REFERENCE_TYPE
850 || code == BOOLEAN_TYPE
851 || (code == RECORD_TYPE && ! raw_constructor
852 && (IS_SIGNATURE_POINTER (type) || IS_SIGNATURE_REFERENCE (type))))
858 error ("initializer for scalar variable requires one element");
859 return error_mark_node;
863 while (TREE_CODE (init) == CONSTRUCTOR)
865 cp_pedwarn ("braces around scalar initializer for `%T'", type);
866 init = CONSTRUCTOR_ELTS (init);
867 if (TREE_CHAIN (init))
868 cp_pedwarn ("ignoring extra initializers for `%T'", type);
869 init = TREE_VALUE (init);
872 return convert_for_initialization (0, type, init, LOOKUP_NORMAL,
873 "initialization", NULL_TREE, 0);
876 /* Come here only for records and arrays (and unions with constructors). */
878 if (TYPE_SIZE (type) && ! TREE_CONSTANT (TYPE_SIZE (type)))
880 cp_error ("variable-sized object of type `%T' may not be initialized",
882 return error_mark_node;
885 if (code == ARRAY_TYPE || code == RECORD_TYPE || code == UNION_TYPE)
887 if (raw_constructor && TYPE_NON_AGGREGATE_CLASS (type))
889 cp_error ("subobject of type `%T' must be initialized by constructor, not by `%E'",
891 return error_mark_node;
893 else if (raw_constructor)
894 return process_init_constructor (type, init, (tree *)0);
895 else if (TYPE_NON_AGGREGATE_CLASS (type))
897 /* This can only be reached when caller is initializing
898 ARRAY_TYPE. In that case, we don't want to convert
899 INIT to TYPE. We will let `expand_vec_init' do it. */
904 *tail = old_tail_contents;
905 return process_init_constructor (type, 0, tail);
907 else if (flag_traditional)
908 /* Traditionally one can say `char x[100] = 0;'. */
909 return process_init_constructor (type,
910 build_nt (CONSTRUCTOR, 0,
911 tree_cons (0, init, 0)),
913 if (code != ARRAY_TYPE)
914 return convert_for_initialization (0, type, init, LOOKUP_NORMAL,
915 "initialization", NULL_TREE, 0);
918 error ("invalid initializer");
919 return error_mark_node;
922 /* Process a constructor for a variable of type TYPE.
923 The constructor elements may be specified either with INIT or with ELTS,
924 only one of which should be non-null.
926 If INIT is specified, it is a CONSTRUCTOR node which is specifically
927 and solely for initializing this datum.
929 If ELTS is specified, it is the address of a variable containing
930 a list of expressions. We take as many elements as we need
931 from the head of the list and update the list.
933 In the resulting constructor, TREE_CONSTANT is set if all elts are
934 constant, and TREE_STATIC is set if, in addition, all elts are simple enough
935 constants that the assembler and linker can compute them. */
938 process_init_constructor (type, init, elts)
939 tree type, init, *elts;
942 /* List of the elements of the result constructor,
944 register tree members = NULL;
950 /* Make TAIL be the list of elements to use for the initialization,
951 no matter how the data was given to us. */
955 if (warn_missing_braces)
956 warning ("aggregate has a partly bracketed initializer");
960 tail = CONSTRUCTOR_ELTS (init);
962 /* Gobble as many elements as needed, and make a constructor or initial value
963 for each element of this aggregate. Chain them together in result.
964 If there are too few, use 0 for each scalar ultimate component. */
966 if (TREE_CODE (type) == ARRAY_TYPE)
968 tree domain = TYPE_DOMAIN (type);
973 len = (TREE_INT_CST_LOW (TYPE_MAX_VALUE (domain))
974 - TREE_INT_CST_LOW (TYPE_MIN_VALUE (domain))
977 len = -1; /* Take as many as there are */
979 for (i = 0; (len < 0 || i < len) && tail != 0; i++)
983 if (TREE_VALUE (tail) != 0)
986 next1 = digest_init (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
987 TREE_VALUE (tail), &tail1);
988 if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (type))
989 && TYPE_MAIN_VARIANT (TREE_TYPE (type)) != TYPE_MAIN_VARIANT (TREE_TYPE (next1)))
991 /* The fact this needs to be done suggests this code needs
992 to be totally rewritten. */
993 next1 = convert_for_initialization (NULL_TREE, TREE_TYPE (type), next1, LOOKUP_NORMAL, "initialization", NULL_TREE, 0);
995 my_friendly_assert (tail1 == 0
996 || TREE_CODE (tail1) == TREE_LIST, 319);
997 if (tail == tail1 && len < 0)
999 error ("non-empty initializer for array of empty elements");
1000 /* Just ignore what we were supposed to use. */
1007 next1 = error_mark_node;
1008 tail = TREE_CHAIN (tail);
1011 if (next1 == error_mark_node)
1013 else if (!TREE_CONSTANT (next1))
1015 else if (! initializer_constant_valid_p (next1, TREE_TYPE (next1)))
1017 members = tree_cons (NULL_TREE, next1, members);
1020 if (TREE_CODE (type) == RECORD_TYPE)
1022 register tree field;
1026 if (TYPE_USES_VIRTUAL_BASECLASSES (type))
1028 sorry ("initializer list for object of class with virtual baseclasses");
1029 return error_mark_node;
1032 if (TYPE_BINFO_BASETYPES (type))
1034 sorry ("initializer list for object of class with baseclasses");
1035 return error_mark_node;
1038 if (TYPE_VIRTUAL_P (type))
1040 sorry ("initializer list for object using virtual functions");
1041 return error_mark_node;
1045 for (field = TYPE_FIELDS (type); field && tail;
1046 field = TREE_CHAIN (field))
1048 register tree next1;
1050 if (! DECL_NAME (field))
1052 members = tree_cons (field, integer_zero_node, members);
1056 if (TREE_CODE (field) != FIELD_DECL)
1059 if (TREE_VALUE (tail) != 0)
1063 next1 = digest_init (TREE_TYPE (field),
1064 TREE_VALUE (tail), &tail1);
1065 my_friendly_assert (tail1 == 0
1066 || TREE_CODE (tail1) == TREE_LIST, 320);
1071 next1 = error_mark_node;
1072 tail = TREE_CHAIN (tail);
1075 if (next1 == error_mark_node)
1077 else if (!TREE_CONSTANT (next1))
1079 else if (! initializer_constant_valid_p (next1, TREE_TYPE (next1)))
1081 members = tree_cons (field, next1, members);
1083 for (; field; field = TREE_CHAIN (field))
1085 if (TREE_CODE (field) != FIELD_DECL)
1088 /* Does this field have a default initialization? */
1089 if (DECL_INITIAL (field))
1091 register tree next1 = DECL_INITIAL (field);
1092 if (TREE_CODE (next1) == ERROR_MARK)
1094 else if (!TREE_CONSTANT (next1))
1096 else if (! initializer_constant_valid_p (next1, TREE_TYPE (next1)))
1098 members = tree_cons (field, next1, members);
1100 else if (TREE_READONLY (field))
1101 error ("uninitialized const member `%s'",
1102 IDENTIFIER_POINTER (DECL_NAME (field)));
1103 else if (TYPE_LANG_SPECIFIC (TREE_TYPE (field))
1104 && CLASSTYPE_READONLY_FIELDS_NEED_INIT (TREE_TYPE (field)))
1105 error ("member `%s' with uninitialized const fields",
1106 IDENTIFIER_POINTER (DECL_NAME (field)));
1107 else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
1108 error ("member `%s' is uninitialized reference",
1109 IDENTIFIER_POINTER (DECL_NAME (field)));
1113 if (TREE_CODE (type) == UNION_TYPE)
1115 register tree field = TYPE_FIELDS (type);
1116 register tree next1;
1118 /* Find the first named field. ANSI decided in September 1990
1119 that only named fields count here. */
1120 while (field && DECL_NAME (field) == 0)
1121 field = TREE_CHAIN (field);
1123 /* If this element specifies a field, initialize via that field. */
1124 if (TREE_PURPOSE (tail) != NULL_TREE)
1128 if (TREE_CODE (TREE_PURPOSE (tail)) == FIELD_DECL)
1129 /* Handle the case of a call by build_c_cast. */
1130 field = TREE_PURPOSE (tail), win = 1;
1131 else if (TREE_CODE (TREE_PURPOSE (tail)) != IDENTIFIER_NODE)
1132 error ("index value instead of field name in union initializer");
1136 for (temp = TYPE_FIELDS (type);
1138 temp = TREE_CHAIN (temp))
1139 if (DECL_NAME (temp) == TREE_PURPOSE (tail))
1142 field = temp, win = 1;
1144 error ("no field `%s' in union being initialized",
1145 IDENTIFIER_POINTER (TREE_PURPOSE (tail)));
1148 TREE_VALUE (tail) = error_mark_node;
1150 else if (field == 0)
1152 cp_error ("union `%T' with no named members cannot be initialized",
1154 TREE_VALUE (tail) = error_mark_node;
1157 if (TREE_VALUE (tail) != 0)
1161 next1 = digest_init (TREE_TYPE (field),
1162 TREE_VALUE (tail), &tail1);
1163 if (tail1 != 0 && TREE_CODE (tail1) != TREE_LIST)
1164 my_friendly_abort (357);
1169 next1 = error_mark_node;
1170 tail = TREE_CHAIN (tail);
1173 if (next1 == error_mark_node)
1175 else if (!TREE_CONSTANT (next1))
1177 else if (initializer_constant_valid_p (next1, TREE_TYPE (next1)) == 0)
1179 members = tree_cons (field, next1, members);
1182 /* If arguments were specified as a list, just remove the ones we used. */
1185 /* If arguments were specified as a constructor,
1186 complain unless we used all the elements of the constructor. */
1188 pedwarn ("excess elements in aggregate initializer");
1191 return error_mark_node;
1193 result = build (CONSTRUCTOR, type, NULL_TREE, nreverse (members));
1195 TREE_HAS_CONSTRUCTOR (result) = TREE_HAS_CONSTRUCTOR (init);
1196 if (allconstant) TREE_CONSTANT (result) = 1;
1197 if (allconstant && allsimple) TREE_STATIC (result) = 1;
1201 /* Given a structure or union value DATUM, construct and return
1202 the structure or union component which results from narrowing
1203 that value by the types specified in TYPES. For example, given the
1206 class L { int ii; };
1207 class A : L { ... };
1208 class B : L { ... };
1209 class C : A, B { ... };
1217 x::C::A::L::ii refers to the ii member of the L part of
1218 of A part of the C object named by X. In this case,
1219 DATUM would be x, and TYPES would be a SCOPE_REF consisting of
1226 The last entry in the SCOPE_REF is always an IDENTIFIER_NODE.
1231 build_scoped_ref (datum, types)
1236 tree type = TREE_TYPE (datum);
1238 if (datum == error_mark_node)
1239 return error_mark_node;
1241 if (TREE_CODE (type) == REFERENCE_TYPE)
1242 type = TREE_TYPE (type);
1244 type = TYPE_MAIN_VARIANT (type);
1246 if (TREE_CODE (types) == SCOPE_REF)
1248 /* We have some work to do. */
1250 { tree type; struct type_chain *next; }
1251 *chain = NULL, *head = NULL, scratch;
1252 ref = build_unary_op (ADDR_EXPR, datum, 0);
1253 while (TREE_CODE (types) == SCOPE_REF)
1255 tree t = TREE_OPERAND (types, 1);
1256 if (is_aggr_typedef (t, 1))
1258 head = (struct type_chain *)alloca (sizeof (struct type_chain));
1259 head->type = IDENTIFIER_TYPE_VALUE (t);
1262 types = TREE_OPERAND (types, 0);
1264 else return error_mark_node;
1266 if (! is_aggr_typedef (types, 1))
1267 return error_mark_node;
1270 head->type = IDENTIFIER_TYPE_VALUE (types);
1275 tree binfo = chain->type;
1276 type = TREE_TYPE (TREE_TYPE (ref));
1277 if (binfo != TYPE_BINFO (type))
1279 binfo = get_binfo (binfo, type, 1);
1280 if (binfo == error_mark_node)
1281 return error_mark_node;
1283 return error_not_base_type (chain->type, type);
1284 ref = convert_pointer_to (binfo, ref);
1286 chain = chain->next;
1288 return build_indirect_ref (ref, "(compiler error in build_scoped_ref)");
1291 /* This is an easy conversion. */
1292 if (is_aggr_typedef (types, 1))
1294 tree binfo = TYPE_BINFO (IDENTIFIER_TYPE_VALUE (types));
1295 if (binfo != TYPE_BINFO (type))
1297 binfo = get_binfo (binfo, type, 1);
1298 if (binfo == error_mark_node)
1299 return error_mark_node;
1301 return error_not_base_type (IDENTIFIER_TYPE_VALUE (types), type);
1304 switch (TREE_CODE (datum))
1309 case FIX_TRUNC_EXPR:
1310 case FIX_FLOOR_EXPR:
1311 case FIX_ROUND_EXPR:
1313 ref = convert_pointer_to (binfo,
1314 build_unary_op (ADDR_EXPR, TREE_OPERAND (datum, 0), 0));
1317 ref = convert_pointer_to (binfo,
1318 build_unary_op (ADDR_EXPR, datum, 0));
1320 return build_indirect_ref (ref, "(compiler error in build_scoped_ref)");
1322 return error_mark_node;
1325 /* Build a reference to an object specified by the C++ `->' operator.
1326 Usually this just involves dereferencing the object, but if the
1327 `->' operator is overloaded, then such overloads must be
1328 performed until an object which does not have the `->' operator
1329 overloaded is found. An error is reported when circular pointer
1330 delegation is detected. */
1332 build_x_arrow (datum)
1335 tree types_memoized = NULL_TREE;
1336 register tree rval = datum;
1337 tree type = TREE_TYPE (rval);
1340 if (type == error_mark_node)
1341 return error_mark_node;
1343 if (TREE_CODE (rval) == OFFSET_REF)
1345 rval = resolve_offset_ref (datum);
1346 type = TREE_TYPE (rval);
1349 if (TREE_CODE (type) == REFERENCE_TYPE)
1351 rval = convert_from_reference (rval);
1352 type = TREE_TYPE (rval);
1355 if (IS_AGGR_TYPE (type) && TYPE_OVERLOADS_ARROW (type))
1357 while ((rval = build_opfncall (COMPONENT_REF, LOOKUP_NORMAL, rval, 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),
1374 if (TREE_CODE (TREE_TYPE (last_rval)) == REFERENCE_TYPE)
1375 last_rval = convert_from_reference (last_rval);
1378 last_rval = default_conversion (rval);
1380 /* Signature pointers are not dereferenced. */
1381 if (TYPE_LANG_SPECIFIC (TREE_TYPE (last_rval))
1382 && IS_SIGNATURE_POINTER (TREE_TYPE (last_rval)))
1385 if (TREE_CODE (TREE_TYPE (last_rval)) == POINTER_TYPE)
1386 return build_indirect_ref (last_rval, NULL_PTR);
1389 error ("result of `operator->()' yields non-pointer result");
1391 error ("base operand of `->' is not a pointer");
1392 return error_mark_node;
1395 /* Make an expression to refer to the COMPONENT field of
1396 structure or union value DATUM. COMPONENT is an arbitrary
1397 expression. DATUM has not already been checked out to be of
1400 For C++, COMPONENT may be a TREE_LIST. This happens when we must
1401 return an object of member type to a method of the current class,
1402 but there is not yet enough typing information to know which one.
1403 As a special case, if there is only one method by that name,
1404 it is returned. Otherwise we return an expression which other
1405 routines will have to know how to deal with later. */
1407 build_m_component_ref (datum, component)
1408 tree datum, component;
1411 tree objtype = TREE_TYPE (datum);
1415 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (component)))
1417 type = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (component)));
1422 component = build_indirect_ref (component, NULL_PTR);
1423 type = TREE_TYPE (component);
1424 rettype = TREE_TYPE (TREE_TYPE (component));
1427 if (datum == error_mark_node || component == error_mark_node)
1428 return error_mark_node;
1430 if (TREE_CODE (type) != OFFSET_TYPE && TREE_CODE (type) != METHOD_TYPE)
1432 cp_error ("`%E' cannot be used as a member pointer, since it is of type `%T'", component, type);
1433 return error_mark_node;
1436 if (TREE_CODE (objtype) == REFERENCE_TYPE)
1437 objtype = TREE_TYPE (objtype);
1438 objtype = TYPE_MAIN_VARIANT (objtype);
1440 if (! IS_AGGR_TYPE (objtype))
1442 cp_error ("cannot apply member pointer `%E' to `%E'", component, datum);
1443 cp_error ("which is of non-aggregate type `%T'", objtype);
1444 return error_mark_node;
1447 binfo = get_binfo (TYPE_METHOD_BASETYPE (type), objtype, 1);
1448 if (binfo == NULL_TREE)
1450 cp_error ("member type `%T::' incompatible with object type `%T'",
1451 TYPE_METHOD_BASETYPE (type), objtype);
1452 return error_mark_node;
1454 else if (binfo == error_mark_node)
1455 return error_mark_node;
1457 return build (OFFSET_REF, rettype, datum, component);
1460 /* Return a tree node for the expression TYPENAME '(' PARMS ')'.
1462 Because we cannot tell whether this construct is really a call to a
1463 constructor or a request for a type conversion, we try both, and
1464 report any ambiguities we find. */
1466 build_functional_cast (exp, parms)
1470 /* This is either a call to a constructor,
1471 or a C cast in C++'s `functional' notation. */
1472 tree type, name = NULL_TREE;
1473 tree expr_as_ctor = NULL_TREE;
1475 if (exp == error_mark_node || parms == error_mark_node)
1476 return error_mark_node;
1478 if (TREE_CODE (exp) == IDENTIFIER_NODE)
1482 if (IDENTIFIER_HAS_TYPE_VALUE (exp))
1483 /* Either an enum or an aggregate type. */
1484 type = IDENTIFIER_TYPE_VALUE (exp);
1487 type = lookup_name (exp, 1);
1488 if (!type || TREE_CODE (type) != TYPE_DECL)
1490 cp_error ("`%T' fails to be a typedef or built-in type", name);
1491 return error_mark_node;
1493 type = TREE_TYPE (type);
1499 if (IS_SIGNATURE (type))
1501 error ("signature type not allowed in cast or constructor expression");
1502 return error_mark_node;
1505 /* Prepare to evaluate as a call to a constructor. If this expression
1506 is actually used, for example,
1508 return X (arg1, arg2, ...);
1510 then the slot being initialized will be filled in. */
1512 if (name == NULL_TREE)
1514 name = TYPE_NAME (type);
1515 if (TREE_CODE (name) == TYPE_DECL)
1516 name = DECL_NESTED_TYPENAME (name);
1519 if (! IS_AGGR_TYPE (type))
1521 /* this must build a C cast */
1522 if (parms == NULL_TREE)
1523 parms = integer_zero_node;
1526 if (TREE_CHAIN (parms) != NULL_TREE)
1527 pedwarn ("initializer list being treated as compound expression");
1528 parms = build_compound_expr (parms);
1531 return build_c_cast (type, parms, 1);
1534 if (TYPE_SIZE (type) == NULL_TREE)
1536 cp_error ("type `%T' is not yet defined", type);
1537 return error_mark_node;
1540 if (parms && TREE_CHAIN (parms) == NULL_TREE)
1541 return build_c_cast (type, parms, 1);
1543 expr_as_ctor = build_method_call (NULL_TREE, name, parms,
1544 NULL_TREE, LOOKUP_NORMAL);
1546 if (expr_as_ctor == error_mark_node)
1547 return error_mark_node;
1549 return build_cplus_new (type, expr_as_ctor, 1);
1552 /* Return the character string for the name that encodes the
1553 enumeral value VALUE in the domain TYPE. */
1555 enum_name_string (value, type)
1559 register tree values = TYPE_VALUES (type);
1560 register HOST_WIDE_INT intval = TREE_INT_CST_LOW (value);
1562 my_friendly_assert (TREE_CODE (type) == ENUMERAL_TYPE, 324);
1564 && TREE_INT_CST_LOW (TREE_VALUE (values)) != intval)
1565 values = TREE_CHAIN (values);
1566 if (values == NULL_TREE)
1568 char *buf = (char *)oballoc (16 + TYPE_NAME_LENGTH (type));
1570 /* Value must have been cast. */
1571 sprintf (buf, "(enum %s)%d",
1572 TYPE_NAME_STRING (type), intval);
1575 return IDENTIFIER_POINTER (TREE_PURPOSE (values));
1579 /* Print out a language-specific error message for
1580 (Pascal) case or (C) switch statements.
1581 CODE tells what sort of message to print.
1582 TYPE is the type of the switch index expression.
1583 NEW is the new value that we were trying to add.
1584 OLD is the old value that stopped us from adding it. */
1586 report_case_error (code, type, new_value, old_value)
1589 tree new_value, old_value;
1594 error ("case label not within a switch statement");
1596 error ("default label not within a switch statement");
1602 error ("multiple default labels in one switch");
1605 if (TREE_CODE (new_value) == RANGE_EXPR)
1606 if (TREE_CODE (old_value) == RANGE_EXPR)
1608 char *buf = (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type)));
1609 if (TREE_CODE (type) == ENUMERAL_TYPE)
1610 sprintf (buf, "overlapping ranges [%s..%s], [%s..%s] in case expression",
1611 enum_name_string (TREE_OPERAND (new_value, 0), type),
1612 enum_name_string (TREE_OPERAND (new_value, 1), type),
1613 enum_name_string (TREE_OPERAND (old_value, 0), type),
1614 enum_name_string (TREE_OPERAND (old_value, 1), type));
1616 sprintf (buf, "overlapping ranges [%d..%d], [%d..%d] in case expression",
1617 TREE_INT_CST_LOW (TREE_OPERAND (new_value, 0)),
1618 TREE_INT_CST_LOW (TREE_OPERAND (new_value, 1)),
1619 TREE_INT_CST_LOW (TREE_OPERAND (old_value, 0)),
1620 TREE_INT_CST_LOW (TREE_OPERAND (old_value, 1)));
1625 char *buf = (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type)));
1626 if (TREE_CODE (type) == ENUMERAL_TYPE)
1627 sprintf (buf, "range [%s..%s] includes element `%s' in case expression",
1628 enum_name_string (TREE_OPERAND (new_value, 0), type),
1629 enum_name_string (TREE_OPERAND (new_value, 1), type),
1630 enum_name_string (old_value, type));
1632 sprintf (buf, "range [%d..%d] includes (%d) in case expression",
1633 TREE_INT_CST_LOW (TREE_OPERAND (new_value, 0)),
1634 TREE_INT_CST_LOW (TREE_OPERAND (new_value, 1)),
1635 TREE_INT_CST_LOW (old_value));
1638 else if (TREE_CODE (old_value) == RANGE_EXPR)
1640 char *buf = (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type)));
1641 if (TREE_CODE (type) == ENUMERAL_TYPE)
1642 sprintf (buf, "range [%s..%s] includes element `%s' in case expression",
1643 enum_name_string (TREE_OPERAND (old_value, 0), type),
1644 enum_name_string (TREE_OPERAND (old_value, 1), type),
1645 enum_name_string (new_value, type));
1647 sprintf (buf, "range [%d..%d] includes (%d) in case expression",
1648 TREE_INT_CST_LOW (TREE_OPERAND (old_value, 0)),
1649 TREE_INT_CST_LOW (TREE_OPERAND (old_value, 1)),
1650 TREE_INT_CST_LOW (new_value));
1655 if (TREE_CODE (type) == ENUMERAL_TYPE)
1656 error ("duplicate label `%s' in switch statement",
1657 enum_name_string (new_value, type));
1659 error ("duplicate label (%d) in switch statement",
1660 TREE_INT_CST_LOW (new_value));
1665 if (TREE_CODE (type) == ENUMERAL_TYPE)
1666 warning ("case value out of range for enum %s",
1667 TYPE_NAME_STRING (type));
1669 warning ("case value out of range");
1673 if (TREE_CODE (type) == ENUMERAL_TYPE)
1674 error ("range values `%s' and `%s' reversed",
1675 enum_name_string (new_value, type),
1676 enum_name_string (old_value, type));
1678 error ("range values reversed");