00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "config.h"
00035 #include "system.h"
00036 #include "tree.h"
00037 #include "cp-tree.h"
00038 #include "flags.h"
00039 #include "toplev.h"
00040 #include "output.h"
00041 #include "diagnostic.h"
00042
00043 static tree process_init_constructor PARAMS ((tree, tree, tree *));
00044
00045
00046
00047
00048 tree
00049 error_not_base_type (basetype, type)
00050 tree basetype, type;
00051 {
00052 if (TREE_CODE (basetype) == FUNCTION_DECL)
00053 basetype = DECL_CONTEXT (basetype);
00054 error ("type `%T' is not a base type for type `%T'", basetype, type);
00055 return error_mark_node;
00056 }
00057
00058 tree
00059 binfo_or_else (base, type)
00060 tree base, type;
00061 {
00062 tree binfo = lookup_base (type, base, ba_ignore, NULL);
00063
00064 if (binfo == error_mark_node)
00065 return NULL_TREE;
00066 else if (!binfo)
00067 error_not_base_type (base, type);
00068 return binfo;
00069 }
00070
00071
00072
00073
00074
00075
00076 void
00077 readonly_error (arg, string, soft)
00078 tree arg;
00079 const char *string;
00080 int soft;
00081 {
00082 const char *fmt;
00083 void (*fn) PARAMS ((const char *, ...));
00084
00085 if (soft)
00086 fn = pedwarn;
00087 else
00088 fn = error;
00089
00090 if (TREE_CODE (arg) == COMPONENT_REF)
00091 {
00092 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0))))
00093 fmt = "%s of data-member `%D' in read-only structure";
00094 else
00095 fmt = "%s of read-only data-member `%D'";
00096 (*fn) (fmt, string, TREE_OPERAND (arg, 1));
00097 }
00098 else if (TREE_CODE (arg) == VAR_DECL)
00099 {
00100 if (DECL_LANG_SPECIFIC (arg)
00101 && DECL_IN_AGGR_P (arg)
00102 && !TREE_STATIC (arg))
00103 fmt = "%s of constant field `%D'";
00104 else
00105 fmt = "%s of read-only variable `%D'";
00106 (*fn) (fmt, string, arg);
00107 }
00108 else if (TREE_CODE (arg) == PARM_DECL)
00109 (*fn) ("%s of read-only parameter `%D'", string, arg);
00110 else if (TREE_CODE (arg) == INDIRECT_REF
00111 && TREE_CODE (TREE_TYPE (TREE_OPERAND (arg, 0))) == REFERENCE_TYPE
00112 && (TREE_CODE (TREE_OPERAND (arg, 0)) == VAR_DECL
00113 || TREE_CODE (TREE_OPERAND (arg, 0)) == PARM_DECL))
00114 (*fn) ("%s of read-only reference `%D'", string, TREE_OPERAND (arg, 0));
00115 else if (TREE_CODE (arg) == RESULT_DECL)
00116 (*fn) ("%s of read-only named return value `%D'", string, arg);
00117 else if (TREE_CODE (arg) == FUNCTION_DECL)
00118 (*fn) ("%s of function `%D'", string, arg);
00119 else
00120 (*fn) ("%s of read-only location", string);
00121 }
00122
00123
00124
00125
00126
00127
00128 int
00129 abstract_virtuals_error (decl, type)
00130 tree decl;
00131 tree type;
00132 {
00133 tree u;
00134 tree tu;
00135
00136 if (processing_template_decl)
00137
00138
00139
00140 return 0;
00141
00142 if (!CLASS_TYPE_P (type) || !CLASSTYPE_PURE_VIRTUALS (type))
00143 return 0;
00144
00145 if (!TYPE_SIZE (type))
00146
00147
00148 return 0;
00149
00150 u = CLASSTYPE_PURE_VIRTUALS (type);
00151 if (decl)
00152 {
00153 if (TREE_CODE (decl) == RESULT_DECL)
00154 return 0;
00155
00156 if (TREE_CODE (decl) == VAR_DECL)
00157 error ("cannot declare variable `%D' to be of type `%T'",
00158 decl, type);
00159 else if (TREE_CODE (decl) == PARM_DECL)
00160 error ("cannot declare parameter `%D' to be of type `%T'",
00161 decl, type);
00162 else if (TREE_CODE (decl) == FIELD_DECL)
00163 error ("cannot declare field `%D' to be of type `%T'",
00164 decl, type);
00165 else if (TREE_CODE (decl) == FUNCTION_DECL
00166 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
00167 error ("invalid return type for member function `%#D'", decl);
00168 else if (TREE_CODE (decl) == FUNCTION_DECL)
00169 error ("invalid return type for function `%#D'", decl);
00170 }
00171 else
00172 error ("cannot allocate an object of type `%T'", type);
00173
00174
00175 if (TREE_PURPOSE (u) == NULL_TREE)
00176 {
00177 TREE_PURPOSE (u) = error_mark_node;
00178
00179 error (" because the following virtual functions are abstract:");
00180 for (tu = u; tu; tu = TREE_CHAIN (tu))
00181 cp_error_at ("\t%#D", TREE_VALUE (tu));
00182 }
00183 else
00184 error (" since type `%T' has abstract virtual functions", type);
00185
00186 return 1;
00187 }
00188
00189
00190
00191
00192
00193
00194
00195 void
00196 cxx_incomplete_type_diagnostic (value, type, diag_type)
00197 tree value;
00198 tree type;
00199 int diag_type;
00200 {
00201 int decl = 0;
00202 void (*p_msg) PARAMS ((const char *, ...));
00203 void (*p_msg_at) PARAMS ((const char *, ...));
00204
00205 if (diag_type == 1)
00206 {
00207 p_msg = warning;
00208 p_msg_at = cp_warning_at;
00209 }
00210 else if (diag_type == 2)
00211 {
00212 p_msg = pedwarn;
00213 p_msg_at = cp_pedwarn_at;
00214 }
00215 else
00216 {
00217 p_msg = error;
00218 p_msg_at = cp_error_at;
00219 }
00220
00221
00222 if (TREE_CODE (type) == ERROR_MARK)
00223 return;
00224
00225 if (value != 0 && (TREE_CODE (value) == VAR_DECL
00226 || TREE_CODE (value) == PARM_DECL
00227 || TREE_CODE (value) == FIELD_DECL))
00228 {
00229 (*p_msg_at) ("`%D' has incomplete type", value);
00230 decl = 1;
00231 }
00232 retry:
00233
00234
00235 switch (TREE_CODE (type))
00236 {
00237 case RECORD_TYPE:
00238 case UNION_TYPE:
00239 case ENUMERAL_TYPE:
00240 if (!decl)
00241 (*p_msg) ("invalid use of undefined type `%#T'", type);
00242 if (!TYPE_TEMPLATE_INFO (type))
00243 (*p_msg_at) ("forward declaration of `%#T'", type);
00244 else
00245 (*p_msg_at) ("declaration of `%#T'", type);
00246 break;
00247
00248 case VOID_TYPE:
00249 (*p_msg) ("invalid use of `%T'", type);
00250 break;
00251
00252 case ARRAY_TYPE:
00253 if (TYPE_DOMAIN (type))
00254 {
00255 type = TREE_TYPE (type);
00256 goto retry;
00257 }
00258 (*p_msg) ("invalid use of array with unspecified bounds");
00259 break;
00260
00261 case OFFSET_TYPE:
00262 bad_member:
00263 (*p_msg) ("invalid use of member (did you forget the `&' ?)");
00264 break;
00265
00266 case TEMPLATE_TYPE_PARM:
00267 (*p_msg) ("invalid use of template type parameter");
00268 break;
00269
00270 case UNKNOWN_TYPE:
00271 if (value && TREE_CODE (value) == COMPONENT_REF)
00272 goto bad_member;
00273 else if (value && TREE_CODE (value) == ADDR_EXPR)
00274 (*p_msg) ("address of overloaded function with no contextual type information");
00275 else if (value && TREE_CODE (value) == OVERLOAD)
00276 (*p_msg) ("overloaded function with no contextual type information");
00277 else
00278 (*p_msg) ("insufficient contextual information to determine type");
00279 break;
00280
00281 default:
00282 abort ();
00283 }
00284 }
00285
00286
00287
00288 #undef cxx_incomplete_type_error
00289 void
00290 cxx_incomplete_type_error (value, type)
00291 tree value;
00292 tree type;
00293 {
00294 cxx_incomplete_type_diagnostic (value, type, 0);
00295 }
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317 tree
00318 store_init_value (decl, init)
00319 tree decl, init;
00320 {
00321 register tree value, type;
00322
00323
00324
00325 type = TREE_TYPE (decl);
00326 if (TREE_CODE (type) == ERROR_MARK)
00327 return NULL_TREE;
00328
00329 if (IS_AGGR_TYPE (type))
00330 {
00331 if (! TYPE_HAS_TRIVIAL_INIT_REF (type)
00332 && TREE_CODE (init) != CONSTRUCTOR)
00333 abort ();
00334
00335 if (TREE_CODE (init) == TREE_LIST)
00336 {
00337 error ("constructor syntax used, but no constructor declared for type `%T'", type);
00338 init = build_nt (CONSTRUCTOR, NULL_TREE, nreverse (init));
00339 }
00340 }
00341 else if (TREE_CODE (init) == TREE_LIST
00342 && TREE_TYPE (init) != unknown_type_node)
00343 {
00344 if (TREE_CODE (decl) == RESULT_DECL)
00345 {
00346 if (TREE_CHAIN (init))
00347 {
00348 warning ("comma expression used to initialize return value");
00349 init = build_compound_expr (init);
00350 }
00351 else
00352 init = TREE_VALUE (init);
00353 }
00354 else if (TREE_CODE (init) == TREE_LIST
00355 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
00356 {
00357 error ("cannot initialize arrays using this syntax");
00358 return NULL_TREE;
00359 }
00360 else
00361 {
00362
00363
00364 if (TREE_CHAIN (init) != NULL_TREE)
00365 {
00366 pedwarn ("initializer list being treated as compound expression");
00367 init = build_compound_expr (init);
00368 }
00369 else
00370 init = TREE_VALUE (init);
00371 }
00372 }
00373
00374
00375
00376
00377 value = digest_init (type, init, (tree *) 0);
00378
00379
00380
00381 if (TREE_CODE (value) == ERROR_MARK)
00382 ;
00383
00384
00385
00386 else if (TYPE_NEEDS_CONSTRUCTING (type))
00387 return value;
00388 else if (TREE_STATIC (decl)
00389 && (! TREE_CONSTANT (value)
00390 || ! initializer_constant_valid_p (value, TREE_TYPE (value))))
00391 return value;
00392
00393
00394
00395
00396 DECL_INITIAL (decl) = value;
00397 return NULL_TREE;
00398 }
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410 tree
00411 digest_init (type, init, tail)
00412 tree type, init, *tail;
00413 {
00414 enum tree_code code = TREE_CODE (type);
00415 tree element = NULL_TREE;
00416 tree old_tail_contents = NULL_TREE;
00417
00418 int raw_constructor;
00419
00420
00421
00422
00423 if (tail)
00424 {
00425 old_tail_contents = *tail;
00426 *tail = TREE_CHAIN (*tail);
00427 }
00428
00429 if (init == error_mark_node || (TREE_CODE (init) == TREE_LIST
00430 && TREE_VALUE (init) == error_mark_node))
00431 return error_mark_node;
00432
00433 if (TREE_CODE (init) == ERROR_MARK)
00434
00435
00436 return init;
00437
00438
00439
00440 if (!complete_type_or_else (TREE_CODE (type) == ARRAY_TYPE
00441 ? TREE_TYPE (type) : type, NULL_TREE))
00442 return error_mark_node;
00443
00444
00445 if (TREE_CODE (init) == NON_LVALUE_EXPR)
00446 init = TREE_OPERAND (init, 0);
00447
00448 raw_constructor = (TREE_CODE (init) == CONSTRUCTOR
00449 && TREE_HAS_CONSTRUCTOR (init));
00450
00451 if (raw_constructor
00452 && CONSTRUCTOR_ELTS (init) != 0
00453 && TREE_CHAIN (CONSTRUCTOR_ELTS (init)) == 0)
00454 {
00455 element = TREE_VALUE (CONSTRUCTOR_ELTS (init));
00456
00457 if (element && TREE_CODE (element) == NON_LVALUE_EXPR)
00458 element = TREE_OPERAND (element, 0);
00459 if (element == error_mark_node)
00460 return element;
00461 }
00462
00463
00464
00465
00466 if (code == ARRAY_TYPE)
00467 {
00468 tree typ1;
00469
00470 if (TREE_CODE (init) == TREE_LIST)
00471 {
00472 error ("initializing array with parameter list");
00473 return error_mark_node;
00474 }
00475
00476 typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type));
00477 if (char_type_p (typ1)
00478 && ((init && TREE_CODE (init) == STRING_CST)
00479 || (element && TREE_CODE (element) == STRING_CST)))
00480 {
00481 tree string = element ? element : init;
00482
00483 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string)))
00484 != char_type_node)
00485 && TYPE_PRECISION (typ1) == BITS_PER_UNIT)
00486 {
00487 error ("char-array initialized from wide string");
00488 return error_mark_node;
00489 }
00490 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string)))
00491 == char_type_node)
00492 && TYPE_PRECISION (typ1) != BITS_PER_UNIT)
00493 {
00494 error ("int-array initialized from non-wide string");
00495 return error_mark_node;
00496 }
00497
00498 TREE_TYPE (string) = type;
00499 if (TYPE_DOMAIN (type) != 0
00500 && TREE_CONSTANT (TYPE_SIZE (type)))
00501 {
00502 register int size
00503 = TREE_INT_CST_LOW (TYPE_SIZE (type));
00504 size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
00505
00506
00507
00508
00509 if (size < TREE_STRING_LENGTH (string))
00510 pedwarn ("initializer-string for array of chars is too long");
00511 }
00512 return string;
00513 }
00514 }
00515
00516
00517
00518
00519 if (code == INTEGER_TYPE || code == REAL_TYPE || code == POINTER_TYPE
00520 || code == ENUMERAL_TYPE || code == REFERENCE_TYPE
00521 || code == BOOLEAN_TYPE || code == COMPLEX_TYPE
00522 || TYPE_PTRMEMFUNC_P (type))
00523 {
00524 if (raw_constructor)
00525 {
00526 if (element == 0)
00527 {
00528 error ("initializer for scalar variable requires one element");
00529 return error_mark_node;
00530 }
00531 init = element;
00532 }
00533 while (TREE_CODE (init) == CONSTRUCTOR && TREE_HAS_CONSTRUCTOR (init))
00534 {
00535 pedwarn ("braces around scalar initializer for `%T'", type);
00536 init = CONSTRUCTOR_ELTS (init);
00537 if (TREE_CHAIN (init))
00538 pedwarn ("ignoring extra initializers for `%T'", type);
00539 init = TREE_VALUE (init);
00540 }
00541
00542 return convert_for_initialization (0, type, init, LOOKUP_NORMAL,
00543 "initialization", NULL_TREE, 0);
00544 }
00545
00546
00547
00548 if (COMPLETE_TYPE_P (type) && ! TREE_CONSTANT (TYPE_SIZE (type)))
00549 {
00550 error ("variable-sized object of type `%T' may not be initialized",
00551 type);
00552 return error_mark_node;
00553 }
00554
00555 if (code == ARRAY_TYPE || code == VECTOR_TYPE || IS_AGGR_TYPE_CODE (code))
00556 {
00557 if (raw_constructor && TYPE_NON_AGGREGATE_CLASS (type)
00558 && TREE_HAS_CONSTRUCTOR (init))
00559 {
00560 error ("subobject of type `%T' must be initialized by constructor, not by `%E'",
00561 type, init);
00562 return error_mark_node;
00563 }
00564 else if (raw_constructor)
00565 return process_init_constructor (type, init, (tree *)0);
00566 else if (can_convert_arg (type, TREE_TYPE (init), init)
00567 || TYPE_NON_AGGREGATE_CLASS (type))
00568 ;
00569 else if (tail != 0)
00570 {
00571 *tail = old_tail_contents;
00572 return process_init_constructor (type, 0, tail);
00573 }
00574
00575 if (code != ARRAY_TYPE)
00576 {
00577 int flags = LOOKUP_NORMAL;
00578
00579 if (tail)
00580 flags |= LOOKUP_ONLYCONVERTING;
00581
00582 return convert_for_initialization (NULL_TREE, type, init, flags,
00583 "initialization", NULL_TREE, 0);
00584 }
00585 }
00586
00587 error ("invalid initializer");
00588 return error_mark_node;
00589 }
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606 static tree
00607 process_init_constructor (type, init, elts)
00608 tree type, init, *elts;
00609 {
00610 register tree tail;
00611
00612
00613 register tree members = NULL;
00614 register tree next1;
00615 tree result;
00616 int allconstant = 1;
00617 int allsimple = 1;
00618 int erroneous = 0;
00619
00620
00621
00622
00623 if (elts)
00624 {
00625 if (warn_missing_braces)
00626 warning ("aggregate has a partly bracketed initializer");
00627 tail = *elts;
00628 }
00629 else
00630 tail = CONSTRUCTOR_ELTS (init);
00631
00632
00633
00634
00635
00636 if (TREE_CODE (type) == ARRAY_TYPE || TREE_CODE (type) == VECTOR_TYPE)
00637 {
00638 register long len;
00639 register int i;
00640
00641 if (TREE_CODE (type) == ARRAY_TYPE)
00642 {
00643 tree domain = TYPE_DOMAIN (type);
00644 if (domain)
00645 len = (TREE_INT_CST_LOW (TYPE_MAX_VALUE (domain))
00646 - TREE_INT_CST_LOW (TYPE_MIN_VALUE (domain))
00647 + 1);
00648 else
00649 len = -1;
00650 }
00651 else
00652 {
00653
00654 len = TYPE_VECTOR_SUBPARTS (type);
00655 }
00656
00657 for (i = 0; len < 0 || i < len; i++)
00658 {
00659 if (tail)
00660 {
00661 if (TREE_PURPOSE (tail)
00662 && (TREE_CODE (TREE_PURPOSE (tail)) != INTEGER_CST
00663 || compare_tree_int (TREE_PURPOSE (tail), i) != 0))
00664 sorry ("non-trivial labeled initializers");
00665
00666 if (TREE_VALUE (tail) != 0)
00667 {
00668 tree tail1 = tail;
00669 next1 = digest_init (TREE_TYPE (type),
00670 TREE_VALUE (tail), &tail1);
00671 if (next1 == error_mark_node)
00672 return next1;
00673 my_friendly_assert
00674 (same_type_ignoring_top_level_qualifiers_p
00675 (TREE_TYPE (type), TREE_TYPE (next1)),
00676 981123);
00677 my_friendly_assert (tail1 == 0
00678 || TREE_CODE (tail1) == TREE_LIST, 319);
00679 if (tail == tail1 && len < 0)
00680 {
00681 error ("non-empty initializer for array of empty elements");
00682
00683 tail1 = NULL_TREE;
00684 }
00685 tail = tail1;
00686 }
00687 else
00688 {
00689 next1 = error_mark_node;
00690 tail = TREE_CHAIN (tail);
00691 }
00692 }
00693 else if (len < 0)
00694
00695 break;
00696 else if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (type)))
00697 {
00698
00699
00700
00701
00702
00703 if (IS_AGGR_TYPE (TREE_TYPE (type)))
00704 next1 = build_functional_cast (TREE_TYPE (type), NULL_TREE);
00705 else
00706 next1 = build (CONSTRUCTOR, NULL_TREE, NULL_TREE, NULL_TREE);
00707 next1 = digest_init (TREE_TYPE (type), next1, 0);
00708 }
00709 else if (! zero_init_p (TREE_TYPE (type)))
00710 next1 = build_zero_init (TREE_TYPE (type),
00711 NULL_TREE,
00712 false);
00713 else
00714
00715
00716 break;
00717
00718 if (next1 == error_mark_node)
00719 erroneous = 1;
00720 else if (!TREE_CONSTANT (next1))
00721 allconstant = 0;
00722 else if (! initializer_constant_valid_p (next1, TREE_TYPE (next1)))
00723 allsimple = 0;
00724 members = tree_cons (size_int (i), next1, members);
00725 }
00726 }
00727 else if (TREE_CODE (type) == RECORD_TYPE)
00728 {
00729 register tree field;
00730
00731 if (tail)
00732 {
00733 if (TYPE_USES_VIRTUAL_BASECLASSES (type))
00734 {
00735 sorry ("initializer list for object of class with virtual base classes");
00736 return error_mark_node;
00737 }
00738
00739 if (TYPE_BINFO_BASETYPES (type))
00740 {
00741 sorry ("initializer list for object of class with base classes");
00742 return error_mark_node;
00743 }
00744
00745 if (TYPE_POLYMORPHIC_P (type))
00746 {
00747 sorry ("initializer list for object using virtual functions");
00748 return error_mark_node;
00749 }
00750 }
00751
00752 for (field = TYPE_FIELDS (type); field;
00753 field = TREE_CHAIN (field))
00754 {
00755 if (! DECL_NAME (field) && DECL_C_BIT_FIELD (field))
00756 {
00757 members = tree_cons (field, integer_zero_node, members);
00758 continue;
00759 }
00760
00761 if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field))
00762 continue;
00763
00764 if (tail)
00765 {
00766 if (TREE_PURPOSE (tail)
00767 && TREE_PURPOSE (tail) != field
00768 && TREE_PURPOSE (tail) != DECL_NAME (field))
00769 sorry ("non-trivial labeled initializers");
00770
00771 if (TREE_VALUE (tail) != 0)
00772 {
00773 tree tail1 = tail;
00774
00775 next1 = digest_init (TREE_TYPE (field),
00776 TREE_VALUE (tail), &tail1);
00777 my_friendly_assert (tail1 == 0
00778 || TREE_CODE (tail1) == TREE_LIST, 320);
00779 tail = tail1;
00780 }
00781 else
00782 {
00783 next1 = error_mark_node;
00784 tail = TREE_CHAIN (tail);
00785 }
00786 }
00787 else if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (field)))
00788 {
00789
00790
00791
00792
00793
00794 if (IS_AGGR_TYPE (TREE_TYPE (field)))
00795 next1 = build_functional_cast (TREE_TYPE (field),
00796 NULL_TREE);
00797 else
00798 {
00799 next1 = build (CONSTRUCTOR, NULL_TREE, NULL_TREE,
00800 NULL_TREE);
00801 if (init)
00802 TREE_HAS_CONSTRUCTOR (next1)
00803 = TREE_HAS_CONSTRUCTOR (init);
00804 }
00805 next1 = digest_init (TREE_TYPE (field), next1, 0);
00806
00807
00808 if (extra_warnings
00809 && (!init || TREE_HAS_CONSTRUCTOR (init)))
00810 warning ("missing initializer for member `%D'", field);
00811 }
00812 else
00813 {
00814 if (TREE_READONLY (field))
00815 error ("uninitialized const member `%D'", field);
00816 else if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (TREE_TYPE (field)))
00817 error ("member `%D' with uninitialized const fields",
00818 field);
00819 else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
00820 error ("member `%D' is uninitialized reference", field);
00821
00822
00823
00824 if (extra_warnings
00825 && (!init || TREE_HAS_CONSTRUCTOR (init)))
00826 warning ("missing initializer for member `%D'", field);
00827
00828 if (! zero_init_p (TREE_TYPE (field)))
00829 next1 = build_zero_init (TREE_TYPE (field),
00830 NULL_TREE,
00831 false);
00832 else
00833
00834
00835 continue;
00836 }
00837
00838 if (next1 == error_mark_node)
00839 erroneous = 1;
00840 else if (!TREE_CONSTANT (next1))
00841 allconstant = 0;
00842 else if (! initializer_constant_valid_p (next1, TREE_TYPE (next1)))
00843 allsimple = 0;
00844 members = tree_cons (field, next1, members);
00845 }
00846 }
00847 else if (TREE_CODE (type) == UNION_TYPE
00848
00849 && tail)
00850 {
00851 register tree field = TYPE_FIELDS (type);
00852
00853
00854
00855 while (field && (!DECL_NAME (field) || TREE_CODE (field) != FIELD_DECL))
00856 field = TREE_CHAIN (field);
00857
00858
00859 if (TREE_PURPOSE (tail) != NULL_TREE)
00860 {
00861 int win = 0;
00862
00863 if (TREE_CODE (TREE_PURPOSE (tail)) == FIELD_DECL)
00864
00865 field = TREE_PURPOSE (tail), win = 1;
00866 else if (TREE_CODE (TREE_PURPOSE (tail)) != IDENTIFIER_NODE)
00867 error ("index value instead of field name in union initializer");
00868 else
00869 {
00870 tree temp;
00871 for (temp = TYPE_FIELDS (type);
00872 temp;
00873 temp = TREE_CHAIN (temp))
00874 if (DECL_NAME (temp) == TREE_PURPOSE (tail))
00875 break;
00876 if (temp)
00877 field = temp, win = 1;
00878 else
00879 error ("no field `%D' in union being initialized",
00880 TREE_PURPOSE (tail));
00881 }
00882 if (!win)
00883 TREE_VALUE (tail) = error_mark_node;
00884 }
00885 else if (field == 0)
00886 {
00887 error ("union `%T' with no named members cannot be initialized",
00888 type);
00889 TREE_VALUE (tail) = error_mark_node;
00890 }
00891
00892 if (TREE_VALUE (tail) != 0)
00893 {
00894 tree tail1 = tail;
00895
00896 next1 = digest_init (TREE_TYPE (field),
00897 TREE_VALUE (tail), &tail1);
00898 if (tail1 != 0 && TREE_CODE (tail1) != TREE_LIST)
00899 abort ();
00900 tail = tail1;
00901 }
00902 else
00903 {
00904 next1 = error_mark_node;
00905 tail = TREE_CHAIN (tail);
00906 }
00907
00908 if (next1 == error_mark_node)
00909 erroneous = 1;
00910 else if (!TREE_CONSTANT (next1))
00911 allconstant = 0;
00912 else if (initializer_constant_valid_p (next1, TREE_TYPE (next1)) == 0)
00913 allsimple = 0;
00914 members = tree_cons (field, next1, members);
00915 }
00916
00917
00918 if (elts)
00919 *elts = tail;
00920
00921
00922 else if (tail)
00923 pedwarn ("excess elements in aggregate initializer");
00924
00925 if (erroneous)
00926 return error_mark_node;
00927
00928 result = build (CONSTRUCTOR, type, NULL_TREE, nreverse (members));
00929 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == NULL_TREE)
00930 complete_array_type (type, result, 0);
00931 if (init)
00932 TREE_HAS_CONSTRUCTOR (result) = TREE_HAS_CONSTRUCTOR (init);
00933 if (allconstant) TREE_CONSTANT (result) = 1;
00934 if (allconstant && allsimple) TREE_STATIC (result) = 1;
00935 return result;
00936 }
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966 tree
00967 build_scoped_ref (datum, basetype, binfo_p)
00968 tree datum;
00969 tree basetype;
00970 tree *binfo_p;
00971 {
00972 tree binfo;
00973
00974 if (datum == error_mark_node)
00975 return error_mark_node;
00976 if (*binfo_p)
00977 binfo = *binfo_p;
00978 else
00979 binfo = lookup_base (TREE_TYPE (datum), basetype, ba_check, NULL);
00980
00981 if (!binfo || binfo == error_mark_node)
00982 {
00983 *binfo_p = NULL_TREE;
00984 if (!binfo)
00985 error_not_base_type (basetype, TREE_TYPE (datum));
00986 return error_mark_node;
00987 }
00988
00989 *binfo_p = binfo;
00990 return build_base_path (PLUS_EXPR, datum, binfo, 1);
00991 }
00992
00993
00994
00995
00996
00997
00998
00999
01000 tree
01001 build_x_arrow (datum)
01002 tree datum;
01003 {
01004 tree types_memoized = NULL_TREE;
01005 register tree rval = datum;
01006 tree type = TREE_TYPE (rval);
01007 tree last_rval = NULL_TREE;
01008
01009 if (type == error_mark_node)
01010 return error_mark_node;
01011
01012 if (processing_template_decl)
01013 return build_min_nt (ARROW_EXPR, rval);
01014
01015 if (TREE_CODE (rval) == OFFSET_REF)
01016 {
01017 rval = resolve_offset_ref (datum);
01018 type = TREE_TYPE (rval);
01019 }
01020
01021 if (TREE_CODE (type) == REFERENCE_TYPE)
01022 {
01023 rval = convert_from_reference (rval);
01024 type = TREE_TYPE (rval);
01025 }
01026
01027 if (IS_AGGR_TYPE (type))
01028 {
01029 while ((rval = build_opfncall (COMPONENT_REF, LOOKUP_NORMAL, rval,
01030 NULL_TREE, NULL_TREE)))
01031 {
01032 if (rval == error_mark_node)
01033 return error_mark_node;
01034
01035 if (value_member (TREE_TYPE (rval), types_memoized))
01036 {
01037 error ("circular pointer delegation detected");
01038 return error_mark_node;
01039 }
01040 else
01041 {
01042 types_memoized = tree_cons (NULL_TREE, TREE_TYPE (rval),
01043 types_memoized);
01044 }
01045 last_rval = rval;
01046 }
01047
01048 if (last_rval == NULL_TREE)
01049 {
01050 error ("base operand of `->' has non-pointer type `%T'", type);
01051 return error_mark_node;
01052 }
01053
01054 if (TREE_CODE (TREE_TYPE (last_rval)) == REFERENCE_TYPE)
01055 last_rval = convert_from_reference (last_rval);
01056 }
01057 else
01058 last_rval = default_conversion (rval);
01059
01060 if (TREE_CODE (TREE_TYPE (last_rval)) == POINTER_TYPE)
01061 return build_indirect_ref (last_rval, NULL);
01062
01063 if (types_memoized)
01064 error ("result of `operator->()' yields non-pointer result");
01065 else
01066 error ("base operand of `->' is not a pointer");
01067 return error_mark_node;
01068 }
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082 tree
01083 build_m_component_ref (datum, component)
01084 tree datum, component;
01085 {
01086 tree type;
01087 tree objtype;
01088 tree field_type;
01089 int type_quals;
01090 tree binfo;
01091
01092 if (processing_template_decl)
01093 return build_min_nt (DOTSTAR_EXPR, datum, component);
01094
01095 datum = decay_conversion (datum);
01096
01097 if (datum == error_mark_node || component == error_mark_node)
01098 return error_mark_node;
01099
01100 objtype = TYPE_MAIN_VARIANT (TREE_TYPE (datum));
01101
01102 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (component)))
01103 {
01104 type = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (component)));
01105 field_type = type;
01106 }
01107 else if (TYPE_PTRMEM_P (TREE_TYPE (component)))
01108 {
01109 type = TREE_TYPE (TREE_TYPE (component));
01110 field_type = TREE_TYPE (type);
01111
01112
01113 type_quals = TYPE_UNQUALIFIED;
01114 if (TREE_CODE (field_type) == REFERENCE_TYPE)
01115
01116
01117
01118 ;
01119 else
01120 {
01121 type_quals = (cp_type_quals (field_type)
01122 | cp_type_quals (TREE_TYPE (datum)));
01123
01124
01125
01126
01127 field_type = cp_build_qualified_type (field_type, type_quals);
01128 }
01129 }
01130 else
01131 {
01132 error ("`%E' cannot be used as a member pointer, since it is of type `%T'",
01133 component, TREE_TYPE (component));
01134 return error_mark_node;
01135 }
01136
01137 if (! IS_AGGR_TYPE (objtype))
01138 {
01139 error ("cannot apply member pointer `%E' to `%E', which is of non-aggregate type `%T'",
01140 component, datum, objtype);
01141 return error_mark_node;
01142 }
01143
01144 binfo = lookup_base (objtype, TYPE_METHOD_BASETYPE (type),
01145 ba_check, NULL);
01146 if (!binfo)
01147 {
01148 error ("member type `%T::' incompatible with object type `%T'",
01149 TYPE_METHOD_BASETYPE (type), objtype);
01150 return error_mark_node;
01151 }
01152 else if (binfo == error_mark_node)
01153 return error_mark_node;
01154
01155 component = build (OFFSET_REF, field_type, datum, component);
01156 if (TREE_CODE (type) == OFFSET_TYPE)
01157 component = resolve_offset_ref (component);
01158 return component;
01159 }
01160
01161
01162
01163 tree
01164 build_functional_cast (exp, parms)
01165 tree exp;
01166 tree parms;
01167 {
01168
01169
01170 tree type;
01171
01172 if (exp == error_mark_node || parms == error_mark_node)
01173 return error_mark_node;
01174
01175 if (TREE_CODE (exp) == IDENTIFIER_NODE)
01176 {
01177 if (IDENTIFIER_HAS_TYPE_VALUE (exp))
01178
01179 type = IDENTIFIER_TYPE_VALUE (exp);
01180 else
01181 {
01182 type = lookup_name (exp, 1);
01183 if (!type || TREE_CODE (type) != TYPE_DECL)
01184 {
01185 error ("`%T' fails to be a typedef or built-in type", exp);
01186 return error_mark_node;
01187 }
01188 type = TREE_TYPE (type);
01189 }
01190 }
01191 else if (TREE_CODE (exp) == TYPE_DECL)
01192 type = TREE_TYPE (exp);
01193 else
01194 type = exp;
01195
01196 if (processing_template_decl)
01197 return build_min (CAST_EXPR, type, parms);
01198
01199 if (! IS_AGGR_TYPE (type))
01200 {
01201
01202 if (parms == NULL_TREE)
01203 parms = integer_zero_node;
01204 else
01205 {
01206 if (TREE_CHAIN (parms) != NULL_TREE)
01207 pedwarn ("initializer list being treated as compound expression");
01208 parms = build_compound_expr (parms);
01209 }
01210
01211 return build_c_cast (type, parms);
01212 }
01213
01214
01215
01216
01217
01218
01219
01220
01221 if (!complete_type_or_else (type, NULL_TREE))
01222 return error_mark_node;
01223 if (abstract_virtuals_error (NULL_TREE, type))
01224 return error_mark_node;
01225
01226 if (parms && TREE_CHAIN (parms) == NULL_TREE)
01227 return build_c_cast (type, TREE_VALUE (parms));
01228
01229
01230
01231 if (parms == NULL_TREE && !TYPE_NEEDS_CONSTRUCTING (type)
01232 && TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
01233 {
01234 exp = build (CONSTRUCTOR, type, NULL_TREE, NULL_TREE);
01235 return get_target_expr (exp);
01236 }
01237
01238 exp = build_special_member_call (NULL_TREE, complete_ctor_identifier, parms,
01239 TYPE_BINFO (type), LOOKUP_NORMAL);
01240
01241 if (exp == error_mark_node)
01242 return error_mark_node;
01243
01244 return build_cplus_new (type, exp);
01245 }
01246
01247
01248
01249
01250
01251 void
01252 check_for_new_type (string, inptree)
01253 const char *string;
01254 flagged_type_tree inptree;
01255 {
01256 if (inptree.new_type_flag
01257 && (pedantic || strcmp (string, "cast") != 0))
01258 pedwarn ("ISO C++ forbids defining types within %s", string);
01259 }
01260
01261
01262
01263
01264
01265
01266 tree
01267 add_exception_specifier (list, spec, complain)
01268 tree list, spec;
01269 int complain;
01270 {
01271 int ok;
01272 tree core = spec;
01273 int is_ptr;
01274 int diag_type = -1;
01275
01276 if (spec == error_mark_node)
01277 return list;
01278
01279 my_friendly_assert (spec && (!list || TREE_VALUE (list)), 19990317);
01280
01281
01282
01283
01284 is_ptr = TREE_CODE (core) == POINTER_TYPE;
01285 if (is_ptr || TREE_CODE (core) == REFERENCE_TYPE)
01286 core = TREE_TYPE (core);
01287 if (complain < 0)
01288 ok = 1;
01289 else if (VOID_TYPE_P (core))
01290 ok = is_ptr;
01291 else if (TREE_CODE (core) == TEMPLATE_TYPE_PARM)
01292 ok = 1;
01293 else if (processing_template_decl)
01294 ok = 1;
01295 else
01296 {
01297 ok = 1;
01298
01299
01300
01301
01302 if (!COMPLETE_TYPE_P (complete_type (core)))
01303 diag_type = 2;
01304 }
01305
01306 if (ok)
01307 {
01308 tree probe;
01309
01310 for (probe = list; probe; probe = TREE_CHAIN (probe))
01311 if (same_type_p (TREE_VALUE (probe), spec))
01312 break;
01313 if (!probe)
01314 list = tree_cons (NULL_TREE, spec, list);
01315 }
01316 else
01317 diag_type = 0;
01318
01319 if (diag_type >= 0 && complain)
01320 cxx_incomplete_type_diagnostic (NULL_TREE, core, diag_type);
01321
01322 return list;
01323 }
01324
01325
01326
01327
01328 tree
01329 merge_exception_specifiers (list, add)
01330 tree list, add;
01331 {
01332 if (!list || !add)
01333 return NULL_TREE;
01334 else if (!TREE_VALUE (list))
01335 return add;
01336 else if (!TREE_VALUE (add))
01337 return list;
01338 else
01339 {
01340 tree orig_list = list;
01341
01342 for (; add; add = TREE_CHAIN (add))
01343 {
01344 tree spec = TREE_VALUE (add);
01345 tree probe;
01346
01347 for (probe = orig_list; probe; probe = TREE_CHAIN (probe))
01348 if (same_type_p (TREE_VALUE (probe), spec))
01349 break;
01350 if (!probe)
01351 {
01352 spec = build_tree_list (NULL_TREE, spec);
01353 TREE_CHAIN (spec) = list;
01354 list = spec;
01355 }
01356 }
01357 }
01358 return list;
01359 }
01360
01361
01362
01363
01364
01365
01366
01367 void
01368 require_complete_eh_spec_types (fntype, decl)
01369 tree fntype, decl;
01370 {
01371 tree raises;
01372
01373 if (decl && DECL_ARTIFICIAL (decl))
01374 return;
01375 for (raises = TYPE_RAISES_EXCEPTIONS (fntype); raises;
01376 raises = TREE_CHAIN (raises))
01377 {
01378 tree type = TREE_VALUE (raises);
01379 if (type && !COMPLETE_TYPE_P (type))
01380 {
01381 if (decl)
01382 error
01383 ("call to function `%D' which throws incomplete type `%#T'",
01384 decl, type);
01385 else
01386 error ("call to function which throws incomplete type `%#T'",
01387 decl);
01388 }
01389 }
01390 }