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). */
40 static tree process_init_constructor
PROTO((tree
, tree
, tree
*));
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. */
49 error_not_base_type (basetype
, type
)
52 if (TREE_CODE (basetype
) == FUNCTION_DECL
)
53 basetype
= DECL_CLASS_CONTEXT (basetype
);
54 cp_error ("type `%T' is not a base type for type `%T'", basetype
, type
);
55 return error_mark_node
;
59 binfo_or_else (parent_or_type
, type
)
60 tree parent_or_type
, type
;
63 if (TYPE_MAIN_VARIANT (parent_or_type
) == TYPE_MAIN_VARIANT (type
))
64 return TYPE_BINFO (parent_or_type
);
65 if ((binfo
= get_binfo (parent_or_type
, TYPE_MAIN_VARIANT (type
), 0)))
67 if (binfo
== error_mark_node
)
71 error_not_base_type (parent_or_type
, type
);
75 /* According to ARM $7.1.6, "A `const' object may be initialized, but its
76 value may not be changed thereafter. Thus, we emit hard errors for these,
77 rather than just pedwarns. If `SOFT' is 1, then we just pedwarn. (For
78 example, conversions to references.) */
81 readonly_error (arg
, string
, soft
)
94 if (TREE_CODE (arg
) == COMPONENT_REF
)
96 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg
, 0))))
97 fmt
= "%s of member `%D' in read-only structure";
99 fmt
= "%s of read-only member `%D'";
100 (*fn
) (fmt
, string
, TREE_OPERAND (arg
, 1));
102 else if (TREE_CODE (arg
) == VAR_DECL
)
104 if (DECL_LANG_SPECIFIC (arg
)
105 && DECL_IN_AGGR_P (arg
)
106 && !TREE_STATIC (arg
))
107 fmt
= "%s of constant field `%D'";
109 fmt
= "%s of read-only variable `%D'";
110 (*fn
) (fmt
, string
, arg
);
112 else if (TREE_CODE (arg
) == PARM_DECL
)
113 (*fn
) ("%s of read-only parameter `%D'", string
, arg
);
114 else if (TREE_CODE (arg
) == INDIRECT_REF
115 && TREE_CODE (TREE_TYPE (TREE_OPERAND (arg
, 0))) == REFERENCE_TYPE
116 && (TREE_CODE (TREE_OPERAND (arg
, 0)) == VAR_DECL
117 || TREE_CODE (TREE_OPERAND (arg
, 0)) == PARM_DECL
))
118 (*fn
) ("%s of read-only reference `%D'", string
, TREE_OPERAND (arg
, 0));
119 else if (TREE_CODE (arg
) == RESULT_DECL
)
120 (*fn
) ("%s of read-only named return value `%D'", string
, arg
);
122 (*fn
) ("%s of read-only location", string
);
125 /* Print an error message for invalid use of a type which declares
126 virtual functions which are not inheritable. */
129 abstract_virtuals_error (decl
, type
)
133 tree u
= CLASSTYPE_ABSTRACT_VIRTUALS (type
);
134 int has_abstract_virtuals
, needs_final_overriders
;
137 /* Count how many abstract methods need to be defined. */
138 for (has_abstract_virtuals
= 0, tu
= u
; tu
; tu
= TREE_CHAIN (tu
))
140 if (DECL_ABSTRACT_VIRTUAL_P (TREE_VALUE (tu
))
141 && ! DECL_NEEDS_FINAL_OVERRIDER_P (TREE_VALUE (tu
)))
143 has_abstract_virtuals
= 1;
148 /* Count how many virtual methods need a final overrider. */
149 for (needs_final_overriders
= 0, tu
= u
; tu
; tu
= TREE_CHAIN (tu
))
151 if (DECL_NEEDS_FINAL_OVERRIDER_P (TREE_VALUE (tu
)))
153 needs_final_overriders
= 1;
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
);
179 cp_error ("cannot allocate an object of type `%T'", type
);
181 /* Only go through this once. */
182 if (TREE_PURPOSE (u
) == NULL_TREE
)
184 TREE_PURPOSE (u
) = error_mark_node
;
186 if (has_abstract_virtuals
)
187 error (" since the following virtual functions are abstract:");
191 if (DECL_ABSTRACT_VIRTUAL_P (TREE_VALUE (tu
))
192 && ! DECL_NEEDS_FINAL_OVERRIDER_P (TREE_VALUE (tu
)))
193 cp_error ("\t%#D", TREE_VALUE (tu
));
194 tu
= TREE_CHAIN (tu
);
197 if (needs_final_overriders
)
199 if (has_abstract_virtuals
)
200 error (" and the following virtual functions need a final overrider:");
202 error (" since the following virtual functions need a final overrider:");
207 if (DECL_NEEDS_FINAL_OVERRIDER_P (TREE_VALUE (tu
)))
208 cp_error ("\t%#D", TREE_VALUE (tu
));
209 tu
= TREE_CHAIN (tu
);
214 if (has_abstract_virtuals
)
216 if (needs_final_overriders
)
217 cp_error (" since type `%T' has abstract virtual functions and must override virtual functions", type
);
219 cp_error (" since type `%T' has abstract virtual functions", type
);
222 cp_error (" since type `%T' must override virtual functions", type
);
226 /* Print an error message for invalid use of a signature type.
227 Signatures are treated similar to abstract classes here, they
228 cannot be instantiated. */
231 signature_error (decl
, type
)
237 if (TREE_CODE (decl
) == RESULT_DECL
)
240 if (TREE_CODE (decl
) == VAR_DECL
)
241 cp_error ("cannot declare variable `%D' to be of signature type `%T'",
243 else if (TREE_CODE (decl
) == PARM_DECL
)
244 cp_error ("cannot declare parameter `%D' to be of signature type `%T'",
246 else if (TREE_CODE (decl
) == FIELD_DECL
)
247 cp_error ("cannot declare field `%D' to be of signature type `%T'",
249 else if (TREE_CODE (decl
) == FUNCTION_DECL
250 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
)
251 cp_error ("invalid return type for method `%#D'", decl
);
252 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
253 cp_error ("invalid return type for function `%#D'", decl
);
256 cp_error ("cannot allocate an object of signature type `%T'", type
);
259 /* Print an error message for invalid use of an incomplete type.
260 VALUE is the expression that was used (or 0 if that isn't known)
261 and TYPE is the type that was invalid. */
264 incomplete_type_error (value
, type
)
270 /* Avoid duplicate error message. */
271 if (TREE_CODE (type
) == ERROR_MARK
)
274 if (value
!= 0 && (TREE_CODE (value
) == VAR_DECL
275 || TREE_CODE (value
) == PARM_DECL
))
276 cp_error ("`%D' has incomplete type", value
);
280 /* We must print an error message. Be clever about what it says. */
282 switch (TREE_CODE (type
))
287 errmsg
= "invalid use of undefined type `%#T'";
291 error ("invalid use of void expression");
295 if (TYPE_DOMAIN (type
))
297 type
= TREE_TYPE (type
);
300 error ("invalid use of array with unspecified bounds");
304 error ("invalid use of member type (did you forget the `&' ?)");
307 case TEMPLATE_TYPE_PARM
:
308 error ("invalid use of template type parameter");
312 my_friendly_abort (108);
315 cp_error (errmsg
, type
);
319 /* Like error(), but don't call report_error_function(). */
327 extern char * progname
;
330 fprintf (stderr
, "%s:%d: ", input_filename
, lineno
);
332 fprintf (stderr
, "%s: ", progname
);
334 fprintf (stderr
, s
, v
, v2
);
335 fprintf (stderr
, "\n");
338 /* There are times when the compiler can get very confused, confused
339 to the point of giving up by aborting, simply because of previous
340 input errors. It is much better to have the user go back and
341 correct those errors first, and see if it makes us happier, than it
342 is to abort on him. This is because when one has a 10,000 line
343 program, and the compiler comes back with ``core dump'', the user
344 is left not knowing even where to begin to fix things and no place
345 to even try and work around things.
347 The parameter is to uniquely identify the problem to the user, so
348 that they can say, I am having problem 59, and know that fix 7 will
349 probably solve their problem. Or, we can document what problem
350 59 is, so they can understand how to work around it, should they
353 Note, there will be no more calls in the C++ front end to abort,
354 because the C++ front end is so unreliable still. The C front end
355 can get away with calling abort, because for most of the calls to
356 abort on most machines, it, I suspect, can be proven that it is
357 impossible to ever call abort. The same is not yet true for C++,
358 one day, maybe it will be.
360 We used to tell people to "fix the above error[s] and try recompiling
361 the program" via a call to fatal, but that message tended to look
362 silly. So instead, we just do the equivalent of a call to fatal in the
363 same situation (call exit). */
365 /* First used: 0 (reserved), Last used: 369. Free: */
367 static int abortcount
= 0;
370 my_friendly_abort (i
)
373 /* if the previous error came through here, i.e. report_error_function
374 ended up calling us again, don't just exit; we want a diagnostic of
377 current_function_decl
= NULL_TREE
;
378 else if (errorcount
> 0 || sorrycount
> 0)
383 ack ("Internal compiler error.");
385 ack ("Internal compiler error %d.", i
);
386 ack ("Please submit a full bug report to `egcs-bugs@cygnus.com'.");
389 error ("confused by earlier errors, bailing out");
396 error ("Internal compiler error.");
398 error ("Internal compiler error %d.", i
);
400 fatal ("Please submit a full bug report to `egcs-bugs@cygnus.com'.");
404 my_friendly_assert (cond
, where
)
408 my_friendly_abort (where
);
411 /* Return nonzero if VALUE is a valid constant-valued expression
412 for use in initializing a static variable; one that can be an
413 element of a "constant" initializer.
415 Return null_pointer_node if the value is absolute;
416 if it is relocatable, return the variable that determines the relocation.
417 We assume that VALUE has been folded as much as possible;
418 therefore, we do not need to check for such things as
419 arithmetic-combinations of integers. */
422 initializer_constant_valid_p (value
, endtype
)
426 switch (TREE_CODE (value
))
429 if (TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
430 && TREE_CONSTANT (value
))
432 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value
)),
435 return TREE_STATIC (value
) ? null_pointer_node
: 0;
441 return null_pointer_node
;
444 return TREE_OPERAND (value
, 0);
446 case NON_LVALUE_EXPR
:
447 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
451 /* Allow conversions between pointer types. */
452 if (POINTER_TYPE_P (TREE_TYPE (value
))
453 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
454 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
456 /* Allow conversions between real types. */
457 if (TREE_CODE (TREE_TYPE (value
)) == REAL_TYPE
458 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == REAL_TYPE
)
459 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
461 /* Allow length-preserving conversions between integer types. */
462 if (TREE_CODE (TREE_TYPE (value
)) == INTEGER_TYPE
463 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == INTEGER_TYPE
464 && (TYPE_PRECISION (TREE_TYPE (value
))
465 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
466 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
468 /* Allow conversions between other integer types only if
470 if (TREE_CODE (TREE_TYPE (value
)) == INTEGER_TYPE
471 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == INTEGER_TYPE
)
473 tree inner
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
475 if (inner
== null_pointer_node
)
476 return null_pointer_node
;
480 /* Allow (int) &foo provided int is as wide as a pointer. */
481 if (TREE_CODE (TREE_TYPE (value
)) == INTEGER_TYPE
482 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == POINTER_TYPE
483 && (TYPE_PRECISION (TREE_TYPE (value
))
484 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
485 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
488 /* Likewise conversions from int to pointers. */
489 if (TREE_CODE (TREE_TYPE (value
)) == POINTER_TYPE
490 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == INTEGER_TYPE
491 && (TYPE_PRECISION (TREE_TYPE (value
))
492 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
493 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
496 /* Allow conversions to union types if the value inside is okay. */
497 if (TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
)
498 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
503 if ((TREE_CODE (endtype
) == INTEGER_TYPE
)
504 && (TYPE_PRECISION (endtype
) < POINTER_SIZE
))
507 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
509 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
511 /* If either term is absolute, use the other terms relocation. */
512 if (valid0
== null_pointer_node
)
514 if (valid1
== null_pointer_node
)
520 if ((TREE_CODE (endtype
) == INTEGER_TYPE
)
521 && (TYPE_PRECISION (endtype
) < POINTER_SIZE
))
524 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
526 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
528 /* Win if second argument is absolute. */
529 if (valid1
== null_pointer_node
)
531 /* Win if both arguments have the same relocation.
532 Then the value is absolute. */
533 if (valid0
== valid1
)
534 return null_pointer_node
;
545 /* Perform appropriate conversions on the initial value of a variable,
546 store it in the declaration DECL,
547 and print any error messages that are appropriate.
548 If the init is invalid, store an ERROR_MARK.
550 C++: Note that INIT might be a TREE_LIST, which would mean that it is
551 a base class initializer for some aggregate type, hopefully compatible
552 with DECL. If INIT is a single element, and DECL is an aggregate
553 type, we silently convert INIT into a TREE_LIST, allowing a constructor
556 If INIT is a TREE_LIST and there is no constructor, turn INIT
557 into a CONSTRUCTOR and use standard initialization techniques.
558 Perhaps a warning should be generated?
560 Returns value of initializer if initialization could not be
561 performed for static variable. In that case, caller must do
565 store_init_value (decl
, init
)
568 register tree value
, type
;
570 /* If variable's type was invalidly declared, just ignore it. */
572 type
= TREE_TYPE (decl
);
573 if (TREE_CODE (type
) == ERROR_MARK
)
577 /* This breaks arrays, and should not have any effect for other decls. */
578 /* Take care of C++ business up here. */
579 type
= TYPE_MAIN_VARIANT (type
);
582 if (IS_AGGR_TYPE (type
))
584 if (! TYPE_HAS_TRIVIAL_INIT_REF (type
)
585 && TREE_CODE (init
) != CONSTRUCTOR
)
586 my_friendly_abort (109);
588 /* Although we are not allowed to declare variables of signature
589 type, we complain about a possible constructor call in such a
590 declaration as well. */
591 if (TREE_CODE (init
) == TREE_LIST
592 && IS_SIGNATURE (type
))
594 cp_error ("constructor syntax cannot be used with signature type `%T'",
596 init
= error_mark_node
;
598 else if (TREE_CODE (init
) == TREE_LIST
)
600 cp_error ("constructor syntax used, but no constructor declared for type `%T'", type
);
601 init
= build_nt (CONSTRUCTOR
, NULL_TREE
, nreverse (init
));
604 if (TREE_CODE (init
) == CONSTRUCTOR
)
608 /* Check that we're really an aggregate as ARM 8.4.1 defines it. */
609 if (CLASSTYPE_N_BASECLASSES (type
))
610 cp_error_at ("initializer list construction invalid for derived class object `%D'", decl
);
611 if (CLASSTYPE_VTBL_PTR (type
))
612 cp_error_at ("initializer list construction invalid for polymorphic class object `%D'", decl
);
613 if (TYPE_NEEDS_CONSTRUCTING (type
))
615 cp_error_at ("initializer list construction invalid for `%D'", decl
);
616 error ("due to the presence of a constructor");
618 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
619 if (TREE_PRIVATE (field
) || TREE_PROTECTED (field
))
621 cp_error_at ("initializer list construction invalid for `%D'", decl
);
622 cp_error_at ("due to non-public access of member `%D'", field
);
624 for (field
= TYPE_METHODS (type
); field
; field
= TREE_CHAIN (field
))
625 if (TREE_PRIVATE (field
) || TREE_PROTECTED (field
))
627 cp_error_at ("initializer list construction invalid for `%D'", decl
);
628 cp_error_at ("due to non-public access of member `%D'", field
);
633 else if (TREE_CODE (init
) == TREE_LIST
634 && TREE_TYPE (init
) != unknown_type_node
)
636 if (TREE_CODE (decl
) == RESULT_DECL
)
638 if (TREE_CHAIN (init
))
640 warning ("comma expression used to initialize return value");
641 init
= build_compound_expr (init
);
644 init
= TREE_VALUE (init
);
646 else if (TREE_TYPE (init
) != 0
647 && TREE_CODE (TREE_TYPE (init
)) == OFFSET_TYPE
)
649 /* Use the type of our variable to instantiate
650 the type of our initializer. */
651 init
= instantiate_type (type
, init
, 1);
653 else if (TREE_CODE (init
) == TREE_LIST
654 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
656 error ("cannot initialize arrays using this syntax");
661 /* We get here with code like `int a (2);' */
663 if (TREE_CHAIN (init
) != NULL_TREE
)
665 pedwarn ("initializer list being treated as compound expression");
666 init
= build_compound_expr (init
);
669 init
= TREE_VALUE (init
);
673 /* End of special C++ code. */
675 /* Digest the specified initializer into an expression. */
677 value
= digest_init (type
, init
, (tree
*) 0);
679 /* Store the expression if valid; else report error. */
681 if (TREE_CODE (value
) == ERROR_MARK
)
683 /* Other code expects that initializers for objects of types that need
684 constructing never make it into DECL_INITIAL, and passes 'init' to
685 expand_aggr_init without checking DECL_INITIAL. So just return. */
686 else if (TYPE_NEEDS_CONSTRUCTING (type
))
688 else if (TREE_STATIC (decl
)
689 && (! TREE_CONSTANT (value
)
690 || ! initializer_constant_valid_p (value
, TREE_TYPE (value
))
692 /* A STATIC PUBLIC int variable doesn't have to be
693 run time inited when doing pic. (mrs) */
694 /* Since ctors and dtors are the only things that can
695 reference vtables, and they are always written down
696 the vtable definition, we can leave the
697 vtables in initialized data space.
698 However, other initialized data cannot be initialized
699 this way. Instead a global file-level initializer
701 || (flag_pic
&& !DECL_VIRTUAL_P (decl
) && TREE_PUBLIC (decl
))
706 #if 0 /* No, that's C. jason 9/19/94 */
709 if (pedantic
&& TREE_CODE (value
) == CONSTRUCTOR
710 /* Don't complain about non-constant initializers of
711 signature tables and signature pointers/references. */
712 && ! (TYPE_LANG_SPECIFIC (type
)
713 && (IS_SIGNATURE (type
)
714 || IS_SIGNATURE_POINTER (type
)
715 || IS_SIGNATURE_REFERENCE (type
))))
717 if (! TREE_CONSTANT (value
) || ! TREE_STATIC (value
))
718 pedwarn ("ANSI C++ forbids non-constant aggregate initializer expressions");
722 DECL_INITIAL (decl
) = value
;
726 /* Digest the parser output INIT as an initializer for type TYPE.
727 Return a C expression of type TYPE to represent the initial value.
729 If TAIL is nonzero, it points to a variable holding a list of elements
730 of which INIT is the first. We update the list stored there by
731 removing from the head all the elements that we use.
732 Normally this is only one; we use more than one element only if
733 TYPE is an aggregate and INIT is not a constructor. */
736 digest_init (type
, init
, tail
)
737 tree type
, init
, *tail
;
739 enum tree_code code
= TREE_CODE (type
);
740 tree element
= NULL_TREE
;
741 tree old_tail_contents
= NULL_TREE
;
742 /* Nonzero if INIT is a braced grouping, which comes in as a CONSTRUCTOR
743 tree node which has no TREE_TYPE. */
746 /* By default, assume we use one element from a list.
747 We correct this later in the sole case where it is not true. */
751 old_tail_contents
= *tail
;
752 *tail
= TREE_CHAIN (*tail
);
755 if (init
== error_mark_node
|| (TREE_CODE (init
) == TREE_LIST
756 && TREE_VALUE (init
) == error_mark_node
))
757 return error_mark_node
;
759 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
760 if (TREE_CODE (init
) == NON_LVALUE_EXPR
)
761 init
= TREE_OPERAND (init
, 0);
763 raw_constructor
= TREE_CODE (init
) == CONSTRUCTOR
&& TREE_TYPE (init
) == 0;
766 && CONSTRUCTOR_ELTS (init
) != 0
767 && TREE_CHAIN (CONSTRUCTOR_ELTS (init
)) == 0)
769 element
= TREE_VALUE (CONSTRUCTOR_ELTS (init
));
770 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
771 if (element
&& TREE_CODE (element
) == NON_LVALUE_EXPR
)
772 element
= TREE_OPERAND (element
, 0);
773 if (element
== error_mark_node
)
777 /* Initialization of an array of chars from a string constant
778 optionally enclosed in braces. */
780 if (code
== ARRAY_TYPE
)
784 if (TREE_CODE (init
) == TREE_LIST
)
786 error ("initializing array with parameter list");
787 return error_mark_node
;
790 typ1
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
791 if ((typ1
== char_type_node
792 || typ1
== signed_char_type_node
793 || typ1
== unsigned_char_type_node
794 || typ1
== unsigned_wchar_type_node
795 || typ1
== signed_wchar_type_node
)
796 && ((init
&& TREE_CODE (init
) == STRING_CST
)
797 || (element
&& TREE_CODE (element
) == STRING_CST
)))
799 tree string
= element
? element
: init
;
801 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string
)))
803 && TYPE_PRECISION (typ1
) == BITS_PER_UNIT
)
805 error ("char-array initialized from wide string");
806 return error_mark_node
;
808 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string
)))
810 && TYPE_PRECISION (typ1
) != BITS_PER_UNIT
)
812 error ("int-array initialized from non-wide string");
813 return error_mark_node
;
816 TREE_TYPE (string
) = type
;
817 if (TYPE_DOMAIN (type
) != 0
818 && TREE_CONSTANT (TYPE_SIZE (type
)))
821 = TREE_INT_CST_LOW (TYPE_SIZE (type
));
822 size
= (size
+ BITS_PER_UNIT
- 1) / BITS_PER_UNIT
;
823 /* In C it is ok to subtract 1 from the length of the string
824 because it's ok to ignore the terminating null char that is
825 counted in the length of the constant, but in C++ this would
827 if (size
< TREE_STRING_LENGTH (string
))
828 pedwarn ("initializer-string for array of chars is too long");
834 /* Handle scalar types, including conversions,
835 and signature pointers and references. */
837 if (code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== POINTER_TYPE
838 || code
== ENUMERAL_TYPE
|| code
== REFERENCE_TYPE
839 || code
== BOOLEAN_TYPE
|| code
== COMPLEX_TYPE
840 || TYPE_PTRMEMFUNC_P (type
)
841 || (code
== RECORD_TYPE
&& ! raw_constructor
842 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
))))
848 error ("initializer for scalar variable requires one element");
849 return error_mark_node
;
853 while (TREE_CODE (init
) == CONSTRUCTOR
&& TREE_HAS_CONSTRUCTOR (init
))
855 cp_pedwarn ("braces around scalar initializer for `%T'", type
);
856 init
= CONSTRUCTOR_ELTS (init
);
857 if (TREE_CHAIN (init
))
858 cp_pedwarn ("ignoring extra initializers for `%T'", type
);
859 init
= TREE_VALUE (init
);
862 return convert_for_initialization (0, type
, init
, LOOKUP_NORMAL
,
863 "initialization", NULL_TREE
, 0);
866 /* Come here only for records and arrays (and unions with constructors). */
868 if (TYPE_SIZE (type
) && ! TREE_CONSTANT (TYPE_SIZE (type
)))
870 cp_error ("variable-sized object of type `%T' may not be initialized",
872 return error_mark_node
;
875 if (code
== ARRAY_TYPE
|| code
== RECORD_TYPE
|| code
== UNION_TYPE
)
877 if (raw_constructor
&& TYPE_NON_AGGREGATE_CLASS (type
))
879 cp_error ("subobject of type `%T' must be initialized by constructor, not by `%E'",
881 return error_mark_node
;
883 else if (raw_constructor
)
884 return process_init_constructor (type
, init
, (tree
*)0);
885 else if (can_convert_arg (type
, TREE_TYPE (init
), init
)
886 || TYPE_NON_AGGREGATE_CLASS (type
))
887 /* These are never initialized from multiple constructor elements. */;
890 *tail
= old_tail_contents
;
891 return process_init_constructor (type
, 0, tail
);
894 if (code
!= ARRAY_TYPE
)
896 int flags
= LOOKUP_NORMAL
;
897 /* Initialization from { } is copy-initialization. */
899 flags
|= LOOKUP_ONLYCONVERTING
;
901 return convert_for_initialization (NULL_TREE
, type
, init
, flags
,
902 "initialization", NULL_TREE
, 0);
906 error ("invalid initializer");
907 return error_mark_node
;
910 /* Process a constructor for a variable of type TYPE.
911 The constructor elements may be specified either with INIT or with ELTS,
912 only one of which should be non-null.
914 If INIT is specified, it is a CONSTRUCTOR node which is specifically
915 and solely for initializing this datum.
917 If ELTS is specified, it is the address of a variable containing
918 a list of expressions. We take as many elements as we need
919 from the head of the list and update the list.
921 In the resulting constructor, TREE_CONSTANT is set if all elts are
922 constant, and TREE_STATIC is set if, in addition, all elts are simple enough
923 constants that the assembler and linker can compute them. */
926 process_init_constructor (type
, init
, elts
)
927 tree type
, init
, *elts
;
930 /* List of the elements of the result constructor,
932 register tree members
= NULL
;
938 /* Make TAIL be the list of elements to use for the initialization,
939 no matter how the data was given to us. */
943 if (warn_missing_braces
)
944 warning ("aggregate has a partly bracketed initializer");
948 tail
= CONSTRUCTOR_ELTS (init
);
950 /* Gobble as many elements as needed, and make a constructor or initial value
951 for each element of this aggregate. Chain them together in result.
952 If there are too few, use 0 for each scalar ultimate component. */
954 if (TREE_CODE (type
) == ARRAY_TYPE
)
956 tree domain
= TYPE_DOMAIN (type
);
961 len
= (TREE_INT_CST_LOW (TYPE_MAX_VALUE (domain
))
962 - TREE_INT_CST_LOW (TYPE_MIN_VALUE (domain
))
965 len
= -1; /* Take as many as there are */
967 for (i
= 0; (len
< 0 || i
< len
) && tail
!= 0; i
++)
971 if (TREE_PURPOSE (tail
)
972 && (TREE_CODE (TREE_PURPOSE (tail
)) != INTEGER_CST
973 || TREE_INT_CST_LOW (TREE_PURPOSE (tail
)) != i
))
974 sorry ("non-trivial labeled initializers");
976 if (TREE_VALUE (tail
) != 0)
979 next1
= digest_init (TREE_TYPE (type
),
980 TREE_VALUE (tail
), &tail1
);
981 if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (type
))
982 && TYPE_MAIN_VARIANT (TREE_TYPE (type
)) != TYPE_MAIN_VARIANT (TREE_TYPE (next1
)))
984 /* The fact this needs to be done suggests this code needs
985 to be totally rewritten. */
986 next1
= convert_for_initialization (NULL_TREE
, TREE_TYPE (type
), next1
, LOOKUP_NORMAL
, "initialization", NULL_TREE
, 0);
988 my_friendly_assert (tail1
== 0
989 || TREE_CODE (tail1
) == TREE_LIST
, 319);
990 if (tail
== tail1
&& len
< 0)
992 error ("non-empty initializer for array of empty elements");
993 /* Just ignore what we were supposed to use. */
1000 next1
= error_mark_node
;
1001 tail
= TREE_CHAIN (tail
);
1004 if (next1
== error_mark_node
)
1006 else if (!TREE_CONSTANT (next1
))
1008 else if (! initializer_constant_valid_p (next1
, TREE_TYPE (next1
)))
1010 members
= expr_tree_cons (NULL_TREE
, next1
, members
);
1013 if (TREE_CODE (type
) == RECORD_TYPE
)
1015 register tree field
;
1019 if (TYPE_USES_VIRTUAL_BASECLASSES (type
))
1021 sorry ("initializer list for object of class with virtual baseclasses");
1022 return error_mark_node
;
1025 if (TYPE_BINFO_BASETYPES (type
))
1027 sorry ("initializer list for object of class with baseclasses");
1028 return error_mark_node
;
1031 if (TYPE_VIRTUAL_P (type
))
1033 sorry ("initializer list for object using virtual functions");
1034 return error_mark_node
;
1038 for (field
= TYPE_FIELDS (type
); field
&& tail
;
1039 field
= TREE_CHAIN (field
))
1041 register tree next1
;
1043 if (! DECL_NAME (field
))
1045 members
= expr_tree_cons (field
, integer_zero_node
, members
);
1049 if (TREE_CODE (field
) != FIELD_DECL
)
1052 if (TREE_PURPOSE (tail
)
1053 && TREE_PURPOSE (tail
) != field
1054 && TREE_PURPOSE (tail
) != DECL_NAME (field
))
1055 sorry ("non-trivial labeled initializers");
1057 if (TREE_VALUE (tail
) != 0)
1061 next1
= digest_init (TREE_TYPE (field
),
1062 TREE_VALUE (tail
), &tail1
);
1063 my_friendly_assert (tail1
== 0
1064 || TREE_CODE (tail1
) == TREE_LIST
, 320);
1069 next1
= error_mark_node
;
1070 tail
= TREE_CHAIN (tail
);
1073 if (next1
== error_mark_node
)
1075 else if (!TREE_CONSTANT (next1
))
1077 else if (! initializer_constant_valid_p (next1
, TREE_TYPE (next1
)))
1079 members
= expr_tree_cons (field
, next1
, members
);
1081 for (; field
; field
= TREE_CHAIN (field
))
1083 if (TREE_CODE (field
) != FIELD_DECL
)
1086 /* Does this field have a default initialization? */
1087 if (DECL_INITIAL (field
))
1089 register tree next1
= DECL_INITIAL (field
);
1090 if (TREE_CODE (next1
) == ERROR_MARK
)
1092 else if (!TREE_CONSTANT (next1
))
1094 else if (! initializer_constant_valid_p (next1
, TREE_TYPE (next1
)))
1096 members
= expr_tree_cons (field
, next1
, members
);
1098 else if (TREE_READONLY (field
))
1099 error ("uninitialized const member `%s'",
1100 IDENTIFIER_POINTER (DECL_NAME (field
)));
1101 else if (TYPE_LANG_SPECIFIC (TREE_TYPE (field
))
1102 && CLASSTYPE_READONLY_FIELDS_NEED_INIT (TREE_TYPE (field
)))
1103 error ("member `%s' with uninitialized const fields",
1104 IDENTIFIER_POINTER (DECL_NAME (field
)));
1105 else if (TREE_CODE (TREE_TYPE (field
)) == REFERENCE_TYPE
)
1106 error ("member `%s' is uninitialized reference",
1107 IDENTIFIER_POINTER (DECL_NAME (field
)));
1108 /* Warn when some struct elements are implicitly initialized
1110 else if (extra_warnings
)
1111 warning ("missing initializer for member `%s'",
1112 IDENTIFIER_POINTER (DECL_NAME (field
)));
1116 if (TREE_CODE (type
) == UNION_TYPE
)
1118 register tree field
= TYPE_FIELDS (type
);
1119 register tree next1
;
1121 /* Find the first named field. ANSI decided in September 1990
1122 that only named fields count here. */
1123 while (field
&& (DECL_NAME (field
) == 0
1124 || TREE_CODE (field
) != FIELD_DECL
))
1125 field
= TREE_CHAIN (field
);
1127 /* If this element specifies a field, initialize via that field. */
1128 if (TREE_PURPOSE (tail
) != NULL_TREE
)
1132 if (TREE_CODE (TREE_PURPOSE (tail
)) == FIELD_DECL
)
1133 /* Handle the case of a call by build_c_cast. */
1134 field
= TREE_PURPOSE (tail
), win
= 1;
1135 else if (TREE_CODE (TREE_PURPOSE (tail
)) != IDENTIFIER_NODE
)
1136 error ("index value instead of field name in union initializer");
1140 for (temp
= TYPE_FIELDS (type
);
1142 temp
= TREE_CHAIN (temp
))
1143 if (DECL_NAME (temp
) == TREE_PURPOSE (tail
))
1146 field
= temp
, win
= 1;
1148 error ("no field `%s' in union being initialized",
1149 IDENTIFIER_POINTER (TREE_PURPOSE (tail
)));
1152 TREE_VALUE (tail
) = error_mark_node
;
1154 else if (field
== 0)
1156 cp_error ("union `%T' with no named members cannot be initialized",
1158 TREE_VALUE (tail
) = error_mark_node
;
1161 if (TREE_VALUE (tail
) != 0)
1165 next1
= digest_init (TREE_TYPE (field
),
1166 TREE_VALUE (tail
), &tail1
);
1167 if (tail1
!= 0 && TREE_CODE (tail1
) != TREE_LIST
)
1168 my_friendly_abort (357);
1173 next1
= error_mark_node
;
1174 tail
= TREE_CHAIN (tail
);
1177 if (next1
== error_mark_node
)
1179 else if (!TREE_CONSTANT (next1
))
1181 else if (initializer_constant_valid_p (next1
, TREE_TYPE (next1
)) == 0)
1183 members
= expr_tree_cons (field
, next1
, members
);
1186 /* If arguments were specified as a list, just remove the ones we used. */
1189 /* If arguments were specified as a constructor,
1190 complain unless we used all the elements of the constructor. */
1192 pedwarn ("excess elements in aggregate initializer");
1195 return error_mark_node
;
1197 result
= build (CONSTRUCTOR
, type
, NULL_TREE
, nreverse (members
));
1199 TREE_HAS_CONSTRUCTOR (result
) = TREE_HAS_CONSTRUCTOR (init
);
1200 if (allconstant
) TREE_CONSTANT (result
) = 1;
1201 if (allconstant
&& allsimple
) TREE_STATIC (result
) = 1;
1205 /* Given a structure or union value DATUM, construct and return
1206 the structure or union component which results from narrowing
1207 that value by the type specified in BASETYPE. For example, given the
1210 class L { int ii; };
1211 class A : L { ... };
1212 class B : L { ... };
1213 class C : A, B { ... };
1221 x.A::ii refers to the ii member of the L part of
1222 the A part of the C object named by X. In this case,
1223 DATUM would be x, and BASETYPE would be A. */
1226 build_scoped_ref (datum
, basetype
)
1231 tree type
= TREE_TYPE (datum
);
1233 if (datum
== error_mark_node
)
1234 return error_mark_node
;
1236 if (TREE_CODE (type
) == REFERENCE_TYPE
)
1237 type
= TREE_TYPE (type
);
1239 type
= TYPE_MAIN_VARIANT (type
);
1241 /* This is an easy conversion. */
1242 if (is_aggr_type (basetype
, 1))
1244 tree binfo
= TYPE_BINFO (basetype
);
1245 if (binfo
!= TYPE_BINFO (type
))
1247 binfo
= get_binfo (binfo
, type
, 1);
1248 if (binfo
== error_mark_node
)
1249 return error_mark_node
;
1251 return error_not_base_type (basetype
, type
);
1254 switch (TREE_CODE (datum
))
1259 case FIX_TRUNC_EXPR
:
1260 case FIX_FLOOR_EXPR
:
1261 case FIX_ROUND_EXPR
:
1263 ref
= convert_pointer_to (binfo
,
1264 build_unary_op (ADDR_EXPR
, TREE_OPERAND (datum
, 0), 0));
1267 ref
= convert_pointer_to (binfo
,
1268 build_unary_op (ADDR_EXPR
, datum
, 0));
1270 return build_indirect_ref (ref
, "(compiler error in build_scoped_ref)");
1272 return error_mark_node
;
1275 /* Build a reference to an object specified by the C++ `->' operator.
1276 Usually this just involves dereferencing the object, but if the
1277 `->' operator is overloaded, then such overloads must be
1278 performed until an object which does not have the `->' operator
1279 overloaded is found. An error is reported when circular pointer
1280 delegation is detected. */
1283 build_x_arrow (datum
)
1286 tree types_memoized
= NULL_TREE
;
1287 register tree rval
= datum
;
1288 tree type
= TREE_TYPE (rval
);
1289 tree last_rval
= NULL_TREE
;
1291 if (type
== error_mark_node
)
1292 return error_mark_node
;
1294 if (processing_template_decl
)
1295 return build_min_nt (ARROW_EXPR
, rval
);
1297 if (TREE_CODE (rval
) == OFFSET_REF
)
1299 rval
= resolve_offset_ref (datum
);
1300 type
= TREE_TYPE (rval
);
1303 if (TREE_CODE (type
) == REFERENCE_TYPE
)
1305 rval
= convert_from_reference (rval
);
1306 type
= TREE_TYPE (rval
);
1309 if (IS_AGGR_TYPE (type
))
1311 while ((rval
= build_opfncall (COMPONENT_REF
, LOOKUP_NORMAL
, rval
,
1312 NULL_TREE
, NULL_TREE
)))
1314 if (rval
== error_mark_node
)
1315 return error_mark_node
;
1317 if (value_member (TREE_TYPE (rval
), types_memoized
))
1319 error ("circular pointer delegation detected");
1320 return error_mark_node
;
1324 types_memoized
= tree_cons (NULL_TREE
, TREE_TYPE (rval
),
1330 if (last_rval
== NULL_TREE
)
1332 cp_error ("base operand of `->' has non-pointer type `%T'", type
);
1333 return error_mark_node
;
1336 if (TREE_CODE (TREE_TYPE (last_rval
)) == REFERENCE_TYPE
)
1337 last_rval
= convert_from_reference (last_rval
);
1340 last_rval
= default_conversion (rval
);
1342 /* Signature pointers are not dereferenced. */
1343 if (TYPE_LANG_SPECIFIC (TREE_TYPE (last_rval
))
1344 && IS_SIGNATURE_POINTER (TREE_TYPE (last_rval
)))
1347 if (TREE_CODE (TREE_TYPE (last_rval
)) == POINTER_TYPE
)
1348 return build_indirect_ref (last_rval
, NULL_PTR
);
1351 error ("result of `operator->()' yields non-pointer result");
1353 error ("base operand of `->' is not a pointer");
1354 return error_mark_node
;
1357 /* Make an expression to refer to the COMPONENT field of
1358 structure or union value DATUM. COMPONENT is an arbitrary
1359 expression. DATUM has not already been checked out to be of
1362 For C++, COMPONENT may be a TREE_LIST. This happens when we must
1363 return an object of member type to a method of the current class,
1364 but there is not yet enough typing information to know which one.
1365 As a special case, if there is only one method by that name,
1366 it is returned. Otherwise we return an expression which other
1367 routines will have to know how to deal with later. */
1370 build_m_component_ref (datum
, component
)
1371 tree datum
, component
;
1374 tree objtype
= TREE_TYPE (datum
);
1378 if (processing_template_decl
)
1379 return build_min_nt (DOTSTAR_EXPR
, datum
, component
);
1381 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (component
)))
1383 type
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (component
)));
1388 component
= build_indirect_ref (component
, NULL_PTR
);
1389 type
= TREE_TYPE (component
);
1390 rettype
= TREE_TYPE (type
);
1393 if (datum
== error_mark_node
|| component
== error_mark_node
)
1394 return error_mark_node
;
1396 if (TREE_CODE (type
) != OFFSET_TYPE
&& TREE_CODE (type
) != METHOD_TYPE
)
1398 cp_error ("`%E' cannot be used as a member pointer, since it is of type `%T'", component
, type
);
1399 return error_mark_node
;
1402 if (TREE_CODE (objtype
) == REFERENCE_TYPE
)
1403 objtype
= TREE_TYPE (objtype
);
1404 objtype
= TYPE_MAIN_VARIANT (objtype
);
1406 if (! IS_AGGR_TYPE (objtype
))
1408 cp_error ("cannot apply member pointer `%E' to `%E'", component
, datum
);
1409 cp_error ("which is of non-aggregate type `%T'", objtype
);
1410 return error_mark_node
;
1413 binfo
= get_binfo (TYPE_METHOD_BASETYPE (type
), objtype
, 1);
1414 if (binfo
== NULL_TREE
)
1416 cp_error ("member type `%T::' incompatible with object type `%T'",
1417 TYPE_METHOD_BASETYPE (type
), objtype
);
1418 return error_mark_node
;
1420 else if (binfo
== error_mark_node
)
1421 return error_mark_node
;
1423 component
= build (OFFSET_REF
, rettype
, datum
, component
);
1424 if (TREE_CODE (type
) == OFFSET_TYPE
)
1425 component
= resolve_offset_ref (component
);
1429 /* Return a tree node for the expression TYPENAME '(' PARMS ')'. */
1432 build_functional_cast (exp
, parms
)
1436 /* This is either a call to a constructor,
1437 or a C cast in C++'s `functional' notation. */
1440 if (exp
== error_mark_node
|| parms
== error_mark_node
)
1441 return error_mark_node
;
1443 if (TREE_CODE (exp
) == IDENTIFIER_NODE
)
1445 if (IDENTIFIER_HAS_TYPE_VALUE (exp
))
1446 /* Either an enum or an aggregate type. */
1447 type
= IDENTIFIER_TYPE_VALUE (exp
);
1450 type
= lookup_name (exp
, 1);
1451 if (!type
|| TREE_CODE (type
) != TYPE_DECL
)
1453 cp_error ("`%T' fails to be a typedef or built-in type", exp
);
1454 return error_mark_node
;
1456 type
= TREE_TYPE (type
);
1459 else if (TREE_CODE (exp
) == TYPE_DECL
)
1460 type
= TREE_TYPE (exp
);
1464 if (processing_template_decl
)
1465 return build_min (CAST_EXPR
, type
, parms
);
1467 if (IS_SIGNATURE (type
))
1469 error ("signature type not allowed in cast or constructor expression");
1470 return error_mark_node
;
1473 if (! IS_AGGR_TYPE (type
))
1475 /* this must build a C cast */
1476 if (parms
== NULL_TREE
)
1477 parms
= integer_zero_node
;
1480 if (TREE_CHAIN (parms
) != NULL_TREE
)
1481 pedwarn ("initializer list being treated as compound expression");
1482 parms
= build_compound_expr (parms
);
1485 return build_c_cast (type
, parms
);
1488 /* Prepare to evaluate as a call to a constructor. If this expression
1489 is actually used, for example,
1491 return X (arg1, arg2, ...);
1493 then the slot being initialized will be filled in. */
1495 if (TYPE_SIZE (complete_type (type
)) == NULL_TREE
)
1497 cp_error ("type `%T' is not yet defined", type
);
1498 return error_mark_node
;
1501 if (parms
&& TREE_CHAIN (parms
) == NULL_TREE
)
1502 return build_c_cast (type
, TREE_VALUE (parms
));
1504 /* We need to zero-initialize POD types. Let's do that for everything
1505 that doesn't need a constructor. */
1506 if (parms
== NULL_TREE
&& !TYPE_NEEDS_CONSTRUCTING (type
)
1507 && TYPE_HAS_DEFAULT_CONSTRUCTOR (type
))
1509 exp
= build (CONSTRUCTOR
, type
, NULL_TREE
, NULL_TREE
);
1510 return get_target_expr (exp
);
1513 exp
= build_method_call (NULL_TREE
, ctor_identifier
, parms
,
1514 TYPE_BINFO (type
), LOOKUP_NORMAL
);
1516 if (exp
== error_mark_node
)
1517 return error_mark_node
;
1519 return build_cplus_new (type
, exp
);
1522 /* Return the character string for the name that encodes the
1523 enumeral value VALUE in the domain TYPE. */
1526 enum_name_string (value
, type
)
1530 register tree values
= TYPE_VALUES (type
);
1531 register HOST_WIDE_INT intval
= TREE_INT_CST_LOW (value
);
1533 my_friendly_assert (TREE_CODE (type
) == ENUMERAL_TYPE
, 324);
1535 && TREE_INT_CST_LOW (TREE_VALUE (values
)) != intval
)
1536 values
= TREE_CHAIN (values
);
1537 if (values
== NULL_TREE
)
1539 char *buf
= (char *)oballoc (16 + TYPE_NAME_LENGTH (type
));
1541 /* Value must have been cast. */
1542 sprintf (buf
, "(enum %s)%ld",
1543 TYPE_NAME_STRING (type
), (long) intval
);
1546 return IDENTIFIER_POINTER (TREE_PURPOSE (values
));
1550 /* Print out a language-specific error message for
1551 (Pascal) case or (C) switch statements.
1552 CODE tells what sort of message to print.
1553 TYPE is the type of the switch index expression.
1554 NEW is the new value that we were trying to add.
1555 OLD is the old value that stopped us from adding it. */
1558 report_case_error (code
, type
, new_value
, old_value
)
1561 tree new_value
, old_value
;
1566 error ("case label not within a switch statement");
1568 error ("default label not within a switch statement");
1574 error ("multiple default labels in one switch");
1577 if (TREE_CODE (new_value
) == RANGE_EXPR
)
1578 if (TREE_CODE (old_value
) == RANGE_EXPR
)
1580 char *buf
= (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type
)));
1581 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1582 sprintf (buf
, "overlapping ranges [%s..%s], [%s..%s] in case expression",
1583 enum_name_string (TREE_OPERAND (new_value
, 0), type
),
1584 enum_name_string (TREE_OPERAND (new_value
, 1), type
),
1585 enum_name_string (TREE_OPERAND (old_value
, 0), type
),
1586 enum_name_string (TREE_OPERAND (old_value
, 1), type
));
1588 sprintf (buf
, "overlapping ranges [%d..%d], [%d..%d] in case expression",
1589 TREE_INT_CST_LOW (TREE_OPERAND (new_value
, 0)),
1590 TREE_INT_CST_LOW (TREE_OPERAND (new_value
, 1)),
1591 TREE_INT_CST_LOW (TREE_OPERAND (old_value
, 0)),
1592 TREE_INT_CST_LOW (TREE_OPERAND (old_value
, 1)));
1597 char *buf
= (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type
)));
1598 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1599 sprintf (buf
, "range [%s..%s] includes element `%s' in case expression",
1600 enum_name_string (TREE_OPERAND (new_value
, 0), type
),
1601 enum_name_string (TREE_OPERAND (new_value
, 1), type
),
1602 enum_name_string (old_value
, type
));
1604 sprintf (buf
, "range [%d..%d] includes (%d) in case expression",
1605 TREE_INT_CST_LOW (TREE_OPERAND (new_value
, 0)),
1606 TREE_INT_CST_LOW (TREE_OPERAND (new_value
, 1)),
1607 TREE_INT_CST_LOW (old_value
));
1610 else if (TREE_CODE (old_value
) == RANGE_EXPR
)
1612 char *buf
= (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type
)));
1613 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1614 sprintf (buf
, "range [%s..%s] includes element `%s' in case expression",
1615 enum_name_string (TREE_OPERAND (old_value
, 0), type
),
1616 enum_name_string (TREE_OPERAND (old_value
, 1), type
),
1617 enum_name_string (new_value
, type
));
1619 sprintf (buf
, "range [%d..%d] includes (%d) in case expression",
1620 TREE_INT_CST_LOW (TREE_OPERAND (old_value
, 0)),
1621 TREE_INT_CST_LOW (TREE_OPERAND (old_value
, 1)),
1622 TREE_INT_CST_LOW (new_value
));
1627 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1628 error ("duplicate label `%s' in switch statement",
1629 enum_name_string (new_value
, type
));
1631 error ("duplicate label (%d) in switch statement",
1632 TREE_INT_CST_LOW (new_value
));
1637 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1638 warning ("case value out of range for enum %s",
1639 TYPE_NAME_STRING (type
));
1641 warning ("case value out of range");
1645 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1646 error ("range values `%s' and `%s' reversed",
1647 enum_name_string (new_value
, type
),
1648 enum_name_string (old_value
, type
));
1650 error ("range values reversed");
1656 check_for_new_type (string
, inptree
)
1658 flagged_type_tree inptree
;
1660 if (pedantic
&& inptree
.new_type_flag
)
1661 pedwarn ("ANSI C++ forbids defining types within %s",string
);