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 `&' ?)");
250 case TEMPLATE_TYPE_PARM
:
251 error ("invalid use of template type parameter");
255 my_friendly_abort (108);
258 cp_error (errmsg
, type
);
262 /* Like error(), but don't call report_error_function(). */
270 extern char * progname
;
273 fprintf (stderr
, "%s:%d: ", input_filename
, lineno
);
275 fprintf (stderr
, "%s: ", progname
);
277 fprintf (stderr
, s
, v
, v2
);
278 fprintf (stderr
, "\n");
281 /* There are times when the compiler can get very confused, confused
282 to the point of giving up by aborting, simply because of previous
283 input errors. It is much better to have the user go back and
284 correct those errors first, and see if it makes us happier, than it
285 is to abort on him. This is because when one has a 10,000 line
286 program, and the compiler comes back with ``core dump'', the user
287 is left not knowing even where to begin to fix things and no place
288 to even try and work around things.
290 The parameter is to uniquely identify the problem to the user, so
291 that they can say, I am having problem 59, and know that fix 7 will
292 probably solve their problem. Or, we can document what problem
293 59 is, so they can understand how to work around it, should they
296 Note, there will be no more calls in the C++ front end to abort,
297 because the C++ front end is so unreliable still. The C front end
298 can get away with calling abort, because for most of the calls to
299 abort on most machines, it, I suspect, can be proven that it is
300 impossible to ever call abort. The same is not yet true for C++,
301 one day, maybe it will be.
303 We used to tell people to "fix the above error[s] and try recompiling
304 the program" via a call to fatal, but that message tended to look
305 silly. So instead, we just do the equivalent of a call to fatal in the
306 same situation (call exit). */
308 /* First used: 0 (reserved), Last used: 369. Free: */
310 static int abortcount
= 0;
313 my_friendly_abort (i
)
316 /* if the previous error came through here, i.e. report_error_function
317 ended up calling us again, don't just exit; we want a diagnostic of
320 current_function_decl
= NULL_TREE
;
321 else if (errorcount
> 0 || sorrycount
> 0)
326 ack ("Internal compiler error.");
328 ack ("Internal compiler error %d.", i
);
329 ack ("Please submit a full bug report to `egcs-bugs@cygnus.com'.");
332 error ("confused by earlier errors, bailing out");
339 error ("Internal compiler error.");
341 error ("Internal compiler error %d.", i
);
343 fatal ("Please submit a full bug report to `egcs-bugs@cygnus.com'.");
347 my_friendly_assert (cond
, where
)
351 my_friendly_abort (where
);
354 /* Return nonzero if VALUE is a valid constant-valued expression
355 for use in initializing a static variable; one that can be an
356 element of a "constant" initializer.
358 Return null_pointer_node if the value is absolute;
359 if it is relocatable, return the variable that determines the relocation.
360 We assume that VALUE has been folded as much as possible;
361 therefore, we do not need to check for such things as
362 arithmetic-combinations of integers. */
365 initializer_constant_valid_p (value
, endtype
)
369 switch (TREE_CODE (value
))
372 if (TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
373 && TREE_CONSTANT (value
))
375 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value
)),
378 return TREE_STATIC (value
) ? null_pointer_node
: 0;
384 return null_pointer_node
;
387 return TREE_OPERAND (value
, 0);
389 case NON_LVALUE_EXPR
:
390 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
394 /* Allow conversions between pointer types. */
395 if (TREE_CODE (TREE_TYPE (value
)) == POINTER_TYPE
396 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == POINTER_TYPE
)
397 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
399 /* Allow conversions between real types. */
400 if (TREE_CODE (TREE_TYPE (value
)) == REAL_TYPE
401 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == REAL_TYPE
)
402 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
404 /* Allow length-preserving conversions between integer types. */
405 if (TREE_CODE (TREE_TYPE (value
)) == INTEGER_TYPE
406 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == INTEGER_TYPE
407 && (TYPE_PRECISION (TREE_TYPE (value
))
408 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
409 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
411 /* Allow conversions between other integer types only if
413 if (TREE_CODE (TREE_TYPE (value
)) == INTEGER_TYPE
414 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == INTEGER_TYPE
)
416 tree inner
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
418 if (inner
== null_pointer_node
)
419 return null_pointer_node
;
423 /* Allow (int) &foo provided int is as wide as a pointer. */
424 if (TREE_CODE (TREE_TYPE (value
)) == INTEGER_TYPE
425 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == POINTER_TYPE
426 && (TYPE_PRECISION (TREE_TYPE (value
))
427 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
428 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
431 /* Likewise conversions from int to pointers. */
432 if (TREE_CODE (TREE_TYPE (value
)) == POINTER_TYPE
433 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == INTEGER_TYPE
434 && (TYPE_PRECISION (TREE_TYPE (value
))
435 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
436 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
439 /* Allow conversions to union types if the value inside is okay. */
440 if (TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
)
441 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
446 if ((TREE_CODE (endtype
) == INTEGER_TYPE
)
447 && (TYPE_PRECISION (endtype
) < POINTER_SIZE
))
450 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
452 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
454 /* If either term is absolute, use the other terms relocation. */
455 if (valid0
== null_pointer_node
)
457 if (valid1
== null_pointer_node
)
463 if ((TREE_CODE (endtype
) == INTEGER_TYPE
)
464 && (TYPE_PRECISION (endtype
) < POINTER_SIZE
))
467 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
469 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
471 /* Win if second argument is absolute. */
472 if (valid1
== null_pointer_node
)
474 /* Win if both arguments have the same relocation.
475 Then the value is absolute. */
476 if (valid0
== valid1
)
477 return null_pointer_node
;
488 /* Perform appropriate conversions on the initial value of a variable,
489 store it in the declaration DECL,
490 and print any error messages that are appropriate.
491 If the init is invalid, store an ERROR_MARK.
493 C++: Note that INIT might be a TREE_LIST, which would mean that it is
494 a base class initializer for some aggregate type, hopefully compatible
495 with DECL. If INIT is a single element, and DECL is an aggregate
496 type, we silently convert INIT into a TREE_LIST, allowing a constructor
499 If INIT is a TREE_LIST and there is no constructor, turn INIT
500 into a CONSTRUCTOR and use standard initialization techniques.
501 Perhaps a warning should be generated?
503 Returns value of initializer if initialization could not be
504 performed for static variable. In that case, caller must do
508 store_init_value (decl
, init
)
511 register tree value
, type
;
513 /* If variable's type was invalidly declared, just ignore it. */
515 type
= TREE_TYPE (decl
);
516 if (TREE_CODE (type
) == ERROR_MARK
)
520 /* This breaks arrays, and should not have any effect for other decls. */
521 /* Take care of C++ business up here. */
522 type
= TYPE_MAIN_VARIANT (type
);
525 if (IS_AGGR_TYPE (type
))
527 if (! TYPE_HAS_TRIVIAL_INIT_REF (type
)
528 && TREE_CODE (init
) != CONSTRUCTOR
)
529 my_friendly_abort (109);
531 /* Although we are not allowed to declare variables of signature
532 type, we complain about a possible constructor call in such a
533 declaration as well. */
534 if (TREE_CODE (init
) == TREE_LIST
535 && IS_SIGNATURE (type
))
537 cp_error ("constructor syntax cannot be used with signature type `%T'",
539 init
= error_mark_node
;
541 else if (TREE_CODE (init
) == TREE_LIST
)
543 cp_error ("constructor syntax used, but no constructor declared for type `%T'", type
);
544 init
= build_nt (CONSTRUCTOR
, NULL_TREE
, nreverse (init
));
547 if (TREE_CODE (init
) == CONSTRUCTOR
)
551 /* Check that we're really an aggregate as ARM 8.4.1 defines it. */
552 if (CLASSTYPE_N_BASECLASSES (type
))
553 cp_error_at ("initializer list construction invalid for derived class object `%D'", decl
);
554 if (CLASSTYPE_VTBL_PTR (type
))
555 cp_error_at ("initializer list construction invalid for polymorphic class object `%D'", decl
);
556 if (TYPE_NEEDS_CONSTRUCTING (type
))
558 cp_error_at ("initializer list construction invalid for `%D'", decl
);
559 error ("due to the presence of a constructor");
561 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
562 if (TREE_PRIVATE (field
) || TREE_PROTECTED (field
))
564 cp_error_at ("initializer list construction invalid for `%D'", decl
);
565 cp_error_at ("due to non-public access of member `%D'", field
);
567 for (field
= TYPE_METHODS (type
); field
; field
= TREE_CHAIN (field
))
568 if (TREE_PRIVATE (field
) || TREE_PROTECTED (field
))
570 cp_error_at ("initializer list construction invalid for `%D'", decl
);
571 cp_error_at ("due to non-public access of member `%D'", field
);
576 else if (TREE_CODE (init
) == TREE_LIST
577 && TREE_TYPE (init
) != unknown_type_node
)
579 if (TREE_CODE (decl
) == RESULT_DECL
)
581 if (TREE_CHAIN (init
))
583 warning ("comma expression used to initialize return value");
584 init
= build_compound_expr (init
);
587 init
= TREE_VALUE (init
);
589 else if (TREE_TYPE (init
) != 0
590 && TREE_CODE (TREE_TYPE (init
)) == OFFSET_TYPE
)
592 /* Use the type of our variable to instantiate
593 the type of our initializer. */
594 init
= instantiate_type (type
, init
, 1);
596 else if (TREE_CODE (init
) == TREE_LIST
597 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
599 error ("cannot initialize arrays using this syntax");
604 /* We get here with code like `int a (2);' */
606 if (TREE_CHAIN (init
) != NULL_TREE
)
608 pedwarn ("initializer list being treated as compound expression");
609 init
= build_compound_expr (init
);
612 init
= TREE_VALUE (init
);
616 if (TYPE_PTRMEMFUNC_P (type
) && TREE_CODE (init
) == CONSTRUCTOR
617 && TREE_TYPE (init
) == NULL_TREE
)
618 cp_pedwarn ("initializer list for `%T'", type
);
620 /* End of special C++ code. */
622 /* Digest the specified initializer into an expression. */
624 value
= digest_init (type
, init
, (tree
*) 0);
626 /* Store the expression if valid; else report error. */
628 if (TREE_CODE (value
) == ERROR_MARK
)
630 /* Other code expects that initializers for objects of types that need
631 constructing never make it into DECL_INITIAL, and passes 'init' to
632 expand_aggr_init without checking DECL_INITIAL. So just return. */
633 else if (TYPE_NEEDS_CONSTRUCTING (type
))
635 else if (TREE_STATIC (decl
)
636 && (! TREE_CONSTANT (value
)
637 || ! initializer_constant_valid_p (value
, TREE_TYPE (value
))
639 /* A STATIC PUBLIC int variable doesn't have to be
640 run time inited when doing pic. (mrs) */
641 /* Since ctors and dtors are the only things that can
642 reference vtables, and they are always written down
643 the the vtable definition, we can leave the
644 vtables in initialized data space.
645 However, other initialized data cannot be initialized
646 this way. Instead a global file-level initializer
648 || (flag_pic
&& !DECL_VIRTUAL_P (decl
) && TREE_PUBLIC (decl
))
653 #if 0 /* No, that's C. jason 9/19/94 */
656 if (pedantic
&& TREE_CODE (value
) == CONSTRUCTOR
657 /* Don't complain about non-constant initializers of
658 signature tables and signature pointers/references. */
659 && ! (TYPE_LANG_SPECIFIC (type
)
660 && (IS_SIGNATURE (type
)
661 || IS_SIGNATURE_POINTER (type
)
662 || IS_SIGNATURE_REFERENCE (type
))))
664 if (! TREE_CONSTANT (value
) || ! TREE_STATIC (value
))
665 pedwarn ("ANSI C++ forbids non-constant aggregate initializer expressions");
669 DECL_INITIAL (decl
) = value
;
673 /* Digest the parser output INIT as an initializer for type TYPE.
674 Return a C expression of type TYPE to represent the initial value.
676 If TAIL is nonzero, it points to a variable holding a list of elements
677 of which INIT is the first. We update the list stored there by
678 removing from the head all the elements that we use.
679 Normally this is only one; we use more than one element only if
680 TYPE is an aggregate and INIT is not a constructor. */
683 digest_init (type
, init
, tail
)
684 tree type
, init
, *tail
;
686 enum tree_code code
= TREE_CODE (type
);
687 tree element
= NULL_TREE
;
688 tree old_tail_contents
;
689 /* Nonzero if INIT is a braced grouping, which comes in as a CONSTRUCTOR
690 tree node which has no TREE_TYPE. */
693 /* By default, assume we use one element from a list.
694 We correct this later in the sole case where it is not true. */
698 old_tail_contents
= *tail
;
699 *tail
= TREE_CHAIN (*tail
);
702 if (init
== error_mark_node
|| (TREE_CODE (init
) == TREE_LIST
703 && TREE_VALUE (init
) == error_mark_node
))
704 return error_mark_node
;
706 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
707 if (TREE_CODE (init
) == NON_LVALUE_EXPR
)
708 init
= TREE_OPERAND (init
, 0);
710 if (init
&& TREE_TYPE (init
) && TYPE_PTRMEMFUNC_P (type
))
711 init
= default_conversion (init
);
713 if (init
&& TYPE_PTRMEMFUNC_P (type
)
714 && ((TREE_CODE (init
) == ADDR_EXPR
715 && ((TREE_CODE (TREE_TYPE (init
)) == POINTER_TYPE
716 && TREE_CODE (TREE_TYPE (TREE_TYPE (init
))) == METHOD_TYPE
)
717 || TREE_CODE (TREE_OPERAND (init
, 0)) == TREE_LIST
))
718 || TREE_CODE (init
) == TREE_LIST
719 || integer_zerop (init
)
720 || (TREE_TYPE (init
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (init
)))))
722 return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type
), init
, 0);
725 raw_constructor
= TREE_CODE (init
) == CONSTRUCTOR
&& TREE_TYPE (init
) == 0;
727 if (init
&& raw_constructor
728 && CONSTRUCTOR_ELTS (init
) != 0
729 && TREE_CHAIN (CONSTRUCTOR_ELTS (init
)) == 0)
731 element
= TREE_VALUE (CONSTRUCTOR_ELTS (init
));
732 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
733 if (element
&& TREE_CODE (element
) == NON_LVALUE_EXPR
)
734 element
= TREE_OPERAND (element
, 0);
735 if (element
== error_mark_node
)
739 /* Any type can be initialized from an expression of the same type,
740 optionally with braces. */
742 if (init
&& TREE_TYPE (init
)
743 && (TYPE_MAIN_VARIANT (TREE_TYPE (init
)) == type
744 || (code
== ARRAY_TYPE
&& comptypes (TREE_TYPE (init
), type
, 1))))
746 if (pedantic
&& code
== ARRAY_TYPE
747 && TREE_CODE (init
) != STRING_CST
)
748 pedwarn ("ANSI C++ forbids initializing array from array expression");
749 if (TREE_CODE (init
) == CONST_DECL
)
750 init
= DECL_INITIAL (init
);
751 else if (TREE_READONLY_DECL_P (init
))
752 init
= decl_constant_value (init
);
753 else if (IS_AGGR_TYPE (type
) && TYPE_NEEDS_CONSTRUCTING (type
))
754 init
= ocp_convert (type
, init
, CONV_IMPLICIT
|CONV_FORCE_TEMP
,
759 if (element
&& (TREE_TYPE (element
) == type
760 || (code
== ARRAY_TYPE
&& TREE_TYPE (element
)
761 && comptypes (TREE_TYPE (element
), type
, 1))))
763 if (pedantic
&& code
== ARRAY_TYPE
)
764 pedwarn ("ANSI C++ forbids initializing array from array expression");
765 if (pedantic
&& (code
== RECORD_TYPE
|| code
== UNION_TYPE
))
766 pedwarn ("ANSI C++ forbids single nonscalar initializer with braces");
767 if (TREE_CODE (element
) == CONST_DECL
)
768 element
= DECL_INITIAL (element
);
769 else if (TREE_READONLY_DECL_P (element
))
770 element
= decl_constant_value (element
);
774 /* Initialization of an array of chars from a string constant
775 optionally enclosed in braces. */
777 if (code
== ARRAY_TYPE
)
779 tree typ1
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
780 if ((typ1
== char_type_node
781 || typ1
== signed_char_type_node
782 || typ1
== unsigned_char_type_node
783 || typ1
== unsigned_wchar_type_node
784 || typ1
== signed_wchar_type_node
)
785 && ((init
&& TREE_CODE (init
) == STRING_CST
)
786 || (element
&& TREE_CODE (element
) == STRING_CST
)))
788 tree string
= element
? element
: init
;
790 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string
)))
792 && TYPE_PRECISION (typ1
) == BITS_PER_UNIT
)
794 error ("char-array initialized from wide string");
795 return error_mark_node
;
797 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string
)))
799 && TYPE_PRECISION (typ1
) != BITS_PER_UNIT
)
801 error ("int-array initialized from non-wide string");
802 return error_mark_node
;
806 && typ1
!= char_type_node
807 && typ1
!= signed_char_type_node
808 && typ1
!= unsigned_char_type_node
)
809 pedwarn ("ANSI C++ forbids string initializer except for `char' elements");
810 TREE_TYPE (string
) = type
;
811 if (TYPE_DOMAIN (type
) != 0
812 && TREE_CONSTANT (TYPE_SIZE (type
)))
815 = TREE_INT_CST_LOW (TYPE_SIZE (type
));
816 size
= (size
+ BITS_PER_UNIT
- 1) / BITS_PER_UNIT
;
817 /* In C it is ok to subtract 1 from the length of the string
818 because it's ok to ignore the terminating null char that is
819 counted in the length of the constant, but in C++ this would
821 if (size
< TREE_STRING_LENGTH (string
))
822 pedwarn ("initializer-string for array of chars is too long");
828 /* Handle scalar types, including conversions,
829 and signature pointers and references. */
831 if (code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== POINTER_TYPE
832 || code
== ENUMERAL_TYPE
|| code
== REFERENCE_TYPE
833 || code
== BOOLEAN_TYPE
|| code
== COMPLEX_TYPE
834 || (code
== RECORD_TYPE
&& ! raw_constructor
835 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
))))
841 error ("initializer for scalar variable requires one element");
842 return error_mark_node
;
846 while (TREE_CODE (init
) == CONSTRUCTOR
847 && ! (TREE_TYPE (init
)
848 && TYPE_PTRMEMFUNC_P (TREE_TYPE (init
))))
850 cp_pedwarn ("braces around scalar initializer for `%T'", type
);
851 init
= CONSTRUCTOR_ELTS (init
);
852 if (TREE_CHAIN (init
))
853 cp_pedwarn ("ignoring extra initializers for `%T'", type
);
854 init
= TREE_VALUE (init
);
857 return convert_for_initialization (0, type
, init
, LOOKUP_NORMAL
,
858 "initialization", NULL_TREE
, 0);
861 /* Come here only for records and arrays (and unions with constructors). */
863 if (TYPE_SIZE (type
) && ! TREE_CONSTANT (TYPE_SIZE (type
)))
865 cp_error ("variable-sized object of type `%T' may not be initialized",
867 return error_mark_node
;
870 if (code
== ARRAY_TYPE
|| code
== RECORD_TYPE
|| code
== UNION_TYPE
)
872 if (raw_constructor
&& TYPE_NON_AGGREGATE_CLASS (type
))
874 cp_error ("subobject of type `%T' must be initialized by constructor, not by `%E'",
876 return error_mark_node
;
878 else if (raw_constructor
)
879 return process_init_constructor (type
, init
, (tree
*)0);
880 else if (TYPE_NON_AGGREGATE_CLASS (type
))
882 int flags
= LOOKUP_NORMAL
;
883 /* Initialization from { } is copy-initialization. */
885 flags
|= LOOKUP_ONLYCONVERTING
;
886 return convert_for_initialization (0, type
, init
, flags
,
887 "initialization", NULL_TREE
, 0);
891 *tail
= old_tail_contents
;
892 return process_init_constructor (type
, 0, tail
);
895 if (code
!= ARRAY_TYPE
)
896 return convert_for_initialization (NULL_TREE
, type
, init
, LOOKUP_NORMAL
,
897 "initialization", NULL_TREE
, 0);
900 error ("invalid initializer");
901 return error_mark_node
;
904 /* Process a constructor for a variable of type TYPE.
905 The constructor elements may be specified either with INIT or with ELTS,
906 only one of which should be non-null.
908 If INIT is specified, it is a CONSTRUCTOR node which is specifically
909 and solely for initializing this datum.
911 If ELTS is specified, it is the address of a variable containing
912 a list of expressions. We take as many elements as we need
913 from the head of the list and update the list.
915 In the resulting constructor, TREE_CONSTANT is set if all elts are
916 constant, and TREE_STATIC is set if, in addition, all elts are simple enough
917 constants that the assembler and linker can compute them. */
920 process_init_constructor (type
, init
, elts
)
921 tree type
, init
, *elts
;
924 /* List of the elements of the result constructor,
926 register tree members
= NULL
;
932 /* Make TAIL be the list of elements to use for the initialization,
933 no matter how the data was given to us. */
937 if (warn_missing_braces
)
938 warning ("aggregate has a partly bracketed initializer");
942 tail
= CONSTRUCTOR_ELTS (init
);
944 /* Gobble as many elements as needed, and make a constructor or initial value
945 for each element of this aggregate. Chain them together in result.
946 If there are too few, use 0 for each scalar ultimate component. */
948 if (TREE_CODE (type
) == ARRAY_TYPE
)
950 tree domain
= TYPE_DOMAIN (type
);
955 len
= (TREE_INT_CST_LOW (TYPE_MAX_VALUE (domain
))
956 - TREE_INT_CST_LOW (TYPE_MIN_VALUE (domain
))
959 len
= -1; /* Take as many as there are */
961 for (i
= 0; (len
< 0 || i
< len
) && tail
!= 0; i
++)
965 if (TREE_VALUE (tail
) != 0)
968 next1
= digest_init (TYPE_MAIN_VARIANT (TREE_TYPE (type
)),
969 TREE_VALUE (tail
), &tail1
);
970 if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (type
))
971 && TYPE_MAIN_VARIANT (TREE_TYPE (type
)) != TYPE_MAIN_VARIANT (TREE_TYPE (next1
)))
973 /* The fact this needs to be done suggests this code needs
974 to be totally rewritten. */
975 next1
= convert_for_initialization (NULL_TREE
, TREE_TYPE (type
), next1
, LOOKUP_NORMAL
, "initialization", NULL_TREE
, 0);
977 my_friendly_assert (tail1
== 0
978 || TREE_CODE (tail1
) == TREE_LIST
, 319);
979 if (tail
== tail1
&& len
< 0)
981 error ("non-empty initializer for array of empty elements");
982 /* Just ignore what we were supposed to use. */
989 next1
= error_mark_node
;
990 tail
= TREE_CHAIN (tail
);
993 if (next1
== error_mark_node
)
995 else if (!TREE_CONSTANT (next1
))
997 else if (! initializer_constant_valid_p (next1
, TREE_TYPE (next1
)))
999 members
= expr_tree_cons (NULL_TREE
, next1
, members
);
1002 if (TREE_CODE (type
) == RECORD_TYPE
)
1004 register tree field
;
1008 if (TYPE_USES_VIRTUAL_BASECLASSES (type
))
1010 sorry ("initializer list for object of class with virtual baseclasses");
1011 return error_mark_node
;
1014 if (TYPE_BINFO_BASETYPES (type
))
1016 sorry ("initializer list for object of class with baseclasses");
1017 return error_mark_node
;
1020 if (TYPE_VIRTUAL_P (type
))
1022 sorry ("initializer list for object using virtual functions");
1023 return error_mark_node
;
1027 for (field
= TYPE_FIELDS (type
); field
&& tail
;
1028 field
= TREE_CHAIN (field
))
1030 register tree next1
;
1032 if (! DECL_NAME (field
))
1034 members
= expr_tree_cons (field
, integer_zero_node
, members
);
1038 if (TREE_CODE (field
) != FIELD_DECL
)
1041 if (TREE_VALUE (tail
) != 0)
1045 next1
= digest_init (TREE_TYPE (field
),
1046 TREE_VALUE (tail
), &tail1
);
1047 my_friendly_assert (tail1
== 0
1048 || TREE_CODE (tail1
) == TREE_LIST
, 320);
1053 next1
= error_mark_node
;
1054 tail
= TREE_CHAIN (tail
);
1057 if (next1
== error_mark_node
)
1059 else if (!TREE_CONSTANT (next1
))
1061 else if (! initializer_constant_valid_p (next1
, TREE_TYPE (next1
)))
1063 members
= expr_tree_cons (field
, next1
, members
);
1065 for (; field
; field
= TREE_CHAIN (field
))
1067 if (TREE_CODE (field
) != FIELD_DECL
)
1070 /* Does this field have a default initialization? */
1071 if (DECL_INITIAL (field
))
1073 register tree next1
= DECL_INITIAL (field
);
1074 if (TREE_CODE (next1
) == ERROR_MARK
)
1076 else if (!TREE_CONSTANT (next1
))
1078 else if (! initializer_constant_valid_p (next1
, TREE_TYPE (next1
)))
1080 members
= expr_tree_cons (field
, next1
, members
);
1082 else if (TREE_READONLY (field
))
1083 error ("uninitialized const member `%s'",
1084 IDENTIFIER_POINTER (DECL_NAME (field
)));
1085 else if (TYPE_LANG_SPECIFIC (TREE_TYPE (field
))
1086 && CLASSTYPE_READONLY_FIELDS_NEED_INIT (TREE_TYPE (field
)))
1087 error ("member `%s' with uninitialized const fields",
1088 IDENTIFIER_POINTER (DECL_NAME (field
)));
1089 else if (TREE_CODE (TREE_TYPE (field
)) == REFERENCE_TYPE
)
1090 error ("member `%s' is uninitialized reference",
1091 IDENTIFIER_POINTER (DECL_NAME (field
)));
1095 if (TREE_CODE (type
) == UNION_TYPE
)
1097 register tree field
= TYPE_FIELDS (type
);
1098 register tree next1
;
1100 /* Find the first named field. ANSI decided in September 1990
1101 that only named fields count here. */
1102 while (field
&& (DECL_NAME (field
) == 0
1103 || TREE_CODE (field
) != FIELD_DECL
))
1104 field
= TREE_CHAIN (field
);
1106 /* If this element specifies a field, initialize via that field. */
1107 if (TREE_PURPOSE (tail
) != NULL_TREE
)
1111 if (TREE_CODE (TREE_PURPOSE (tail
)) == FIELD_DECL
)
1112 /* Handle the case of a call by build_c_cast. */
1113 field
= TREE_PURPOSE (tail
), win
= 1;
1114 else if (TREE_CODE (TREE_PURPOSE (tail
)) != IDENTIFIER_NODE
)
1115 error ("index value instead of field name in union initializer");
1119 for (temp
= TYPE_FIELDS (type
);
1121 temp
= TREE_CHAIN (temp
))
1122 if (DECL_NAME (temp
) == TREE_PURPOSE (tail
))
1125 field
= temp
, win
= 1;
1127 error ("no field `%s' in union being initialized",
1128 IDENTIFIER_POINTER (TREE_PURPOSE (tail
)));
1131 TREE_VALUE (tail
) = error_mark_node
;
1133 else if (field
== 0)
1135 cp_error ("union `%T' with no named members cannot be initialized",
1137 TREE_VALUE (tail
) = error_mark_node
;
1140 if (TREE_VALUE (tail
) != 0)
1144 next1
= digest_init (TREE_TYPE (field
),
1145 TREE_VALUE (tail
), &tail1
);
1146 if (tail1
!= 0 && TREE_CODE (tail1
) != TREE_LIST
)
1147 my_friendly_abort (357);
1152 next1
= error_mark_node
;
1153 tail
= TREE_CHAIN (tail
);
1156 if (next1
== error_mark_node
)
1158 else if (!TREE_CONSTANT (next1
))
1160 else if (initializer_constant_valid_p (next1
, TREE_TYPE (next1
)) == 0)
1162 members
= expr_tree_cons (field
, next1
, members
);
1165 /* If arguments were specified as a list, just remove the ones we used. */
1168 /* If arguments were specified as a constructor,
1169 complain unless we used all the elements of the constructor. */
1171 pedwarn ("excess elements in aggregate initializer");
1174 return error_mark_node
;
1176 result
= build (CONSTRUCTOR
, type
, NULL_TREE
, nreverse (members
));
1178 TREE_HAS_CONSTRUCTOR (result
) = TREE_HAS_CONSTRUCTOR (init
);
1179 if (allconstant
) TREE_CONSTANT (result
) = 1;
1180 if (allconstant
&& allsimple
) TREE_STATIC (result
) = 1;
1184 /* Given a structure or union value DATUM, construct and return
1185 the structure or union component which results from narrowing
1186 that value by the type specified in BASETYPE. For example, given the
1189 class L { int ii; };
1190 class A : L { ... };
1191 class B : L { ... };
1192 class C : A, B { ... };
1200 x.A::ii refers to the ii member of the L part of
1201 of A part of the C object named by X. In this case,
1202 DATUM would be x, and BASETYPE would be A. */
1205 build_scoped_ref (datum
, basetype
)
1210 tree type
= TREE_TYPE (datum
);
1212 if (datum
== error_mark_node
)
1213 return error_mark_node
;
1215 if (TREE_CODE (type
) == REFERENCE_TYPE
)
1216 type
= TREE_TYPE (type
);
1218 type
= TYPE_MAIN_VARIANT (type
);
1220 /* This is an easy conversion. */
1221 if (is_aggr_type (basetype
, 1))
1223 tree binfo
= TYPE_BINFO (basetype
);
1224 if (binfo
!= TYPE_BINFO (type
))
1226 binfo
= get_binfo (binfo
, type
, 1);
1227 if (binfo
== error_mark_node
)
1228 return error_mark_node
;
1230 return error_not_base_type (basetype
, type
);
1233 switch (TREE_CODE (datum
))
1238 case FIX_TRUNC_EXPR
:
1239 case FIX_FLOOR_EXPR
:
1240 case FIX_ROUND_EXPR
:
1242 ref
= convert_pointer_to (binfo
,
1243 build_unary_op (ADDR_EXPR
, TREE_OPERAND (datum
, 0), 0));
1246 ref
= convert_pointer_to (binfo
,
1247 build_unary_op (ADDR_EXPR
, datum
, 0));
1249 return build_indirect_ref (ref
, "(compiler error in build_scoped_ref)");
1251 return error_mark_node
;
1254 /* Build a reference to an object specified by the C++ `->' operator.
1255 Usually this just involves dereferencing the object, but if the
1256 `->' operator is overloaded, then such overloads must be
1257 performed until an object which does not have the `->' operator
1258 overloaded is found. An error is reported when circular pointer
1259 delegation is detected. */
1262 build_x_arrow (datum
)
1265 tree types_memoized
= NULL_TREE
;
1266 register tree rval
= datum
;
1267 tree type
= TREE_TYPE (rval
);
1270 if (type
== error_mark_node
)
1271 return error_mark_node
;
1273 if (processing_template_decl
)
1274 return build_min_nt (ARROW_EXPR
, rval
);
1276 if (TREE_CODE (rval
) == OFFSET_REF
)
1278 rval
= resolve_offset_ref (datum
);
1279 type
= TREE_TYPE (rval
);
1282 if (TREE_CODE (type
) == REFERENCE_TYPE
)
1284 rval
= convert_from_reference (rval
);
1285 type
= TREE_TYPE (rval
);
1288 if (IS_AGGR_TYPE (type
) && TYPE_OVERLOADS_ARROW (complete_type (type
)))
1290 while ((rval
= build_opfncall (COMPONENT_REF
, LOOKUP_NORMAL
, rval
, NULL_TREE
, NULL_TREE
)))
1292 if (rval
== error_mark_node
)
1293 return error_mark_node
;
1295 if (value_member (TREE_TYPE (rval
), types_memoized
))
1297 error ("circular pointer delegation detected");
1298 return error_mark_node
;
1302 types_memoized
= tree_cons (NULL_TREE
, TREE_TYPE (rval
),
1307 if (TREE_CODE (TREE_TYPE (last_rval
)) == REFERENCE_TYPE
)
1308 last_rval
= convert_from_reference (last_rval
);
1311 last_rval
= default_conversion (rval
);
1313 /* Signature pointers are not dereferenced. */
1314 if (TYPE_LANG_SPECIFIC (TREE_TYPE (last_rval
))
1315 && IS_SIGNATURE_POINTER (TREE_TYPE (last_rval
)))
1318 if (TREE_CODE (TREE_TYPE (last_rval
)) == POINTER_TYPE
)
1319 return build_indirect_ref (last_rval
, NULL_PTR
);
1322 error ("result of `operator->()' yields non-pointer result");
1324 error ("base operand of `->' is not a pointer");
1325 return error_mark_node
;
1328 /* Make an expression to refer to the COMPONENT field of
1329 structure or union value DATUM. COMPONENT is an arbitrary
1330 expression. DATUM has not already been checked out to be of
1333 For C++, COMPONENT may be a TREE_LIST. This happens when we must
1334 return an object of member type to a method of the current class,
1335 but there is not yet enough typing information to know which one.
1336 As a special case, if there is only one method by that name,
1337 it is returned. Otherwise we return an expression which other
1338 routines will have to know how to deal with later. */
1341 build_m_component_ref (datum
, component
)
1342 tree datum
, component
;
1345 tree objtype
= TREE_TYPE (datum
);
1349 if (processing_template_decl
)
1350 return build_min_nt (DOTSTAR_EXPR
, datum
, component
);
1352 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (component
)))
1354 type
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (component
)));
1359 component
= build_indirect_ref (component
, NULL_PTR
);
1360 type
= TREE_TYPE (component
);
1361 rettype
= TREE_TYPE (type
);
1364 if (datum
== error_mark_node
|| component
== error_mark_node
)
1365 return error_mark_node
;
1367 if (TREE_CODE (type
) != OFFSET_TYPE
&& TREE_CODE (type
) != METHOD_TYPE
)
1369 cp_error ("`%E' cannot be used as a member pointer, since it is of type `%T'", component
, type
);
1370 return error_mark_node
;
1373 if (TREE_CODE (objtype
) == REFERENCE_TYPE
)
1374 objtype
= TREE_TYPE (objtype
);
1375 objtype
= TYPE_MAIN_VARIANT (objtype
);
1377 if (! IS_AGGR_TYPE (objtype
))
1379 cp_error ("cannot apply member pointer `%E' to `%E'", component
, datum
);
1380 cp_error ("which is of non-aggregate type `%T'", objtype
);
1381 return error_mark_node
;
1384 binfo
= get_binfo (TYPE_METHOD_BASETYPE (type
), objtype
, 1);
1385 if (binfo
== NULL_TREE
)
1387 cp_error ("member type `%T::' incompatible with object type `%T'",
1388 TYPE_METHOD_BASETYPE (type
), objtype
);
1389 return error_mark_node
;
1391 else if (binfo
== error_mark_node
)
1392 return error_mark_node
;
1394 component
= build (OFFSET_REF
, rettype
, datum
, component
);
1395 if (TREE_CODE (type
) == OFFSET_TYPE
)
1396 component
= resolve_offset_ref (component
);
1400 /* Return a tree node for the expression TYPENAME '(' PARMS ')'. */
1403 build_functional_cast (exp
, parms
)
1407 /* This is either a call to a constructor,
1408 or a C cast in C++'s `functional' notation. */
1411 if (exp
== error_mark_node
|| parms
== error_mark_node
)
1412 return error_mark_node
;
1414 if (TREE_CODE (exp
) == IDENTIFIER_NODE
)
1416 if (IDENTIFIER_HAS_TYPE_VALUE (exp
))
1417 /* Either an enum or an aggregate type. */
1418 type
= IDENTIFIER_TYPE_VALUE (exp
);
1421 type
= lookup_name (exp
, 1);
1422 if (!type
|| TREE_CODE (type
) != TYPE_DECL
)
1424 cp_error ("`%T' fails to be a typedef or built-in type", exp
);
1425 return error_mark_node
;
1427 type
= TREE_TYPE (type
);
1430 else if (TREE_CODE (exp
) == TYPE_DECL
)
1431 type
= TREE_TYPE (exp
);
1435 if (processing_template_decl
)
1436 return build_min (CAST_EXPR
, type
, parms
);
1438 if (IS_SIGNATURE (type
))
1440 error ("signature type not allowed in cast or constructor expression");
1441 return error_mark_node
;
1444 if (! IS_AGGR_TYPE (type
))
1446 /* this must build a C cast */
1447 if (parms
== NULL_TREE
)
1448 parms
= integer_zero_node
;
1451 if (TREE_CHAIN (parms
) != NULL_TREE
)
1452 pedwarn ("initializer list being treated as compound expression");
1453 parms
= build_compound_expr (parms
);
1456 return build_c_cast (type
, parms
);
1459 /* Prepare to evaluate as a call to a constructor. If this expression
1460 is actually used, for example,
1462 return X (arg1, arg2, ...);
1464 then the slot being initialized will be filled in. */
1466 if (TYPE_SIZE (complete_type (type
)) == NULL_TREE
)
1468 cp_error ("type `%T' is not yet defined", type
);
1469 return error_mark_node
;
1472 if (parms
&& TREE_CHAIN (parms
) == NULL_TREE
)
1473 return build_c_cast (type
, TREE_VALUE (parms
));
1475 exp
= build_method_call (NULL_TREE
, ctor_identifier
, parms
,
1476 TYPE_BINFO (type
), LOOKUP_NORMAL
);
1478 if (exp
== error_mark_node
)
1479 return error_mark_node
;
1481 return build_cplus_new (type
, exp
);
1484 /* Return the character string for the name that encodes the
1485 enumeral value VALUE in the domain TYPE. */
1488 enum_name_string (value
, type
)
1492 register tree values
= TYPE_VALUES (type
);
1493 register HOST_WIDE_INT intval
= TREE_INT_CST_LOW (value
);
1495 my_friendly_assert (TREE_CODE (type
) == ENUMERAL_TYPE
, 324);
1497 && TREE_INT_CST_LOW (TREE_VALUE (values
)) != intval
)
1498 values
= TREE_CHAIN (values
);
1499 if (values
== NULL_TREE
)
1501 char *buf
= (char *)oballoc (16 + TYPE_NAME_LENGTH (type
));
1503 /* Value must have been cast. */
1504 sprintf (buf
, "(enum %s)%d",
1505 TYPE_NAME_STRING (type
), intval
);
1508 return IDENTIFIER_POINTER (TREE_PURPOSE (values
));
1512 /* Print out a language-specific error message for
1513 (Pascal) case or (C) switch statements.
1514 CODE tells what sort of message to print.
1515 TYPE is the type of the switch index expression.
1516 NEW is the new value that we were trying to add.
1517 OLD is the old value that stopped us from adding it. */
1520 report_case_error (code
, type
, new_value
, old_value
)
1523 tree new_value
, old_value
;
1528 error ("case label not within a switch statement");
1530 error ("default label not within a switch statement");
1536 error ("multiple default labels in one switch");
1539 if (TREE_CODE (new_value
) == RANGE_EXPR
)
1540 if (TREE_CODE (old_value
) == RANGE_EXPR
)
1542 char *buf
= (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type
)));
1543 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1544 sprintf (buf
, "overlapping ranges [%s..%s], [%s..%s] in case expression",
1545 enum_name_string (TREE_OPERAND (new_value
, 0), type
),
1546 enum_name_string (TREE_OPERAND (new_value
, 1), type
),
1547 enum_name_string (TREE_OPERAND (old_value
, 0), type
),
1548 enum_name_string (TREE_OPERAND (old_value
, 1), type
));
1550 sprintf (buf
, "overlapping ranges [%d..%d], [%d..%d] in case expression",
1551 TREE_INT_CST_LOW (TREE_OPERAND (new_value
, 0)),
1552 TREE_INT_CST_LOW (TREE_OPERAND (new_value
, 1)),
1553 TREE_INT_CST_LOW (TREE_OPERAND (old_value
, 0)),
1554 TREE_INT_CST_LOW (TREE_OPERAND (old_value
, 1)));
1559 char *buf
= (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type
)));
1560 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1561 sprintf (buf
, "range [%s..%s] includes element `%s' in case expression",
1562 enum_name_string (TREE_OPERAND (new_value
, 0), type
),
1563 enum_name_string (TREE_OPERAND (new_value
, 1), type
),
1564 enum_name_string (old_value
, type
));
1566 sprintf (buf
, "range [%d..%d] includes (%d) in case expression",
1567 TREE_INT_CST_LOW (TREE_OPERAND (new_value
, 0)),
1568 TREE_INT_CST_LOW (TREE_OPERAND (new_value
, 1)),
1569 TREE_INT_CST_LOW (old_value
));
1572 else if (TREE_CODE (old_value
) == RANGE_EXPR
)
1574 char *buf
= (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type
)));
1575 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1576 sprintf (buf
, "range [%s..%s] includes element `%s' in case expression",
1577 enum_name_string (TREE_OPERAND (old_value
, 0), type
),
1578 enum_name_string (TREE_OPERAND (old_value
, 1), type
),
1579 enum_name_string (new_value
, type
));
1581 sprintf (buf
, "range [%d..%d] includes (%d) in case expression",
1582 TREE_INT_CST_LOW (TREE_OPERAND (old_value
, 0)),
1583 TREE_INT_CST_LOW (TREE_OPERAND (old_value
, 1)),
1584 TREE_INT_CST_LOW (new_value
));
1589 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1590 error ("duplicate label `%s' in switch statement",
1591 enum_name_string (new_value
, type
));
1593 error ("duplicate label (%d) in switch statement",
1594 TREE_INT_CST_LOW (new_value
));
1599 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1600 warning ("case value out of range for enum %s",
1601 TYPE_NAME_STRING (type
));
1603 warning ("case value out of range");
1607 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1608 error ("range values `%s' and `%s' reversed",
1609 enum_name_string (new_value
, type
),
1610 enum_name_string (old_value
, type
));
1612 error ("range values reversed");
1618 check_for_new_type (string
, inptree
)
1620 flagged_type_tree inptree
;
1622 if (pedantic
&& inptree
.new_type_flag
)
1623 pedwarn ("ANSI C++ forbids defining types within %s",string
);