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 "coretypes.h"
00037 #include "tm.h"
00038 #include "tree.h"
00039 #include "rtl.h"
00040 #include "expr.h"
00041 #include "flags.h"
00042 #include "cp-tree.h"
00043 #include "tree-inline.h"
00044 #include "decl.h"
00045 #include "output.h"
00046 #include "except.h"
00047 #include "toplev.h"
00048 #include "hashtab.h"
00049 #include "tm_p.h"
00050 #include "target.h"
00051 #include "c-common.h"
00052 #include "c-pragma.h"
00053 #include "diagnostic.h"
00054 #include "debug.h"
00055 #include "timevar.h"
00056 #include "tree-flow.h"
00057
00058 static tree grokparms (cp_parameter_declarator *, tree *);
00059 static const char *redeclaration_error_message (tree, tree);
00060
00061 static int decl_jump_unsafe (tree);
00062 static void require_complete_types_for_parms (tree);
00063 static int ambi_op_p (enum tree_code);
00064 static int unary_op_p (enum tree_code);
00065 static void push_local_name (tree);
00066 static tree grok_reference_init (tree, tree, tree, tree *);
00067 static tree grokvardecl (tree, tree, const cp_decl_specifier_seq *,
00068 int, int, tree);
00069 static void record_unknown_type (tree, const char *);
00070 static tree builtin_function_1 (const char *, tree, tree,
00071 enum built_in_function code,
00072 enum built_in_class cl, const char *,
00073 tree);
00074 static tree build_library_fn_1 (tree, enum tree_code, tree);
00075 static int member_function_or_else (tree, tree, enum overload_flags);
00076 static void bad_specifiers (tree, const char *, int, int, int, int,
00077 int);
00078 static void check_for_uninitialized_const_var (tree);
00079 static hashval_t typename_hash (const void *);
00080 static int typename_compare (const void *, const void *);
00081 static tree local_variable_p_walkfn (tree *, int *, void *);
00082 static tree record_builtin_java_type (const char *, int);
00083 static const char *tag_name (enum tag_types);
00084 static tree lookup_and_check_tag (enum tag_types, tree, tag_scope, bool);
00085 static int walk_namespaces_r (tree, walk_namespaces_fn, void *);
00086 static void maybe_deduce_size_from_array_init (tree, tree);
00087 static void layout_var_decl (tree);
00088 static void maybe_commonize_var (tree);
00089 static tree check_initializer (tree, tree, int, tree *);
00090 static void make_rtl_for_nonlocal_decl (tree, tree, const char *);
00091 static void save_function_data (tree);
00092 static void check_function_type (tree, tree);
00093 static void finish_constructor_body (void);
00094 static void begin_destructor_body (void);
00095 static void finish_destructor_body (void);
00096 static tree create_array_type_for_decl (tree, tree, tree);
00097 static tree get_atexit_node (void);
00098 static tree get_dso_handle_node (void);
00099 static tree start_cleanup_fn (void);
00100 static void end_cleanup_fn (void);
00101 static tree cp_make_fname_decl (tree, int);
00102 static void initialize_predefined_identifiers (void);
00103 static tree check_special_function_return_type
00104 (special_function_kind, tree, tree);
00105 static tree push_cp_library_fn (enum tree_code, tree);
00106 static tree build_cp_library_fn (tree, enum tree_code, tree);
00107 static void store_parm_decls (tree);
00108 static void initialize_local_var (tree, tree);
00109 static void expand_static_init (tree, tree);
00110 static tree next_initializable_field (tree);
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 tree cp_global_trees[CPTI_MAX];
00150
00151
00152
00153
00154 tree global_type_node;
00155
00156
00157 tree global_scope_name;
00158
00159 #define local_names cp_function_chain->x_local_names
00160
00161
00162
00163
00164
00165 tree static_aggregates;
00166
00167
00168
00169
00170
00171 tree integer_two_node, integer_three_node;
00172
00173
00174
00175
00176 struct named_label_use_entry GTY(())
00177 {
00178 struct named_label_use_entry *next;
00179
00180
00181
00182 struct cp_binding_level *binding_level;
00183
00184
00185
00186 tree names_in_scope;
00187
00188 location_t o_goto_locus;
00189
00190
00191
00192 bool in_omp_scope;
00193 };
00194
00195
00196
00197
00198
00199 struct named_label_entry GTY(())
00200 {
00201
00202 tree label_decl;
00203
00204
00205
00206
00207 struct cp_binding_level *binding_level;
00208
00209
00210
00211 tree names_in_scope;
00212
00213
00214 tree bad_decls;
00215
00216
00217 struct named_label_use_entry *uses;
00218
00219
00220
00221
00222 bool in_try_scope;
00223 bool in_catch_scope;
00224 bool in_omp_scope;
00225 };
00226
00227 #define named_labels cp_function_chain->x_named_labels
00228
00229
00230
00231
00232 int function_depth;
00233
00234
00235
00236
00237
00238
00239 enum deprecated_states {
00240 DEPRECATED_NORMAL,
00241 DEPRECATED_SUPPRESS
00242 };
00243
00244 static enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
00245
00246
00247
00248
00249
00250
00251 static GTY(()) tree incomplete_vars;
00252
00253
00254
00255
00256
00257 tmpl_spec_kind
00258 current_tmpl_spec_kind (int n_class_scopes)
00259 {
00260 int n_template_parm_scopes = 0;
00261 int seen_specialization_p = 0;
00262 int innermost_specialization_p = 0;
00263 struct cp_binding_level *b;
00264
00265
00266 for (b = current_binding_level;
00267 b->kind == sk_template_parms;
00268 b = b->level_chain)
00269 {
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279 if (b->explicit_spec_p)
00280 {
00281 if (n_template_parm_scopes == 0)
00282 innermost_specialization_p = 1;
00283 else
00284 seen_specialization_p = 1;
00285 }
00286 else if (seen_specialization_p == 1)
00287 return tsk_invalid_member_spec;
00288
00289 ++n_template_parm_scopes;
00290 }
00291
00292
00293 if (processing_explicit_instantiation)
00294 {
00295 if (n_template_parm_scopes != 0)
00296
00297
00298
00299
00300
00301
00302 return tsk_invalid_expl_inst;
00303 else
00304 return tsk_expl_inst;
00305 }
00306
00307 if (n_template_parm_scopes < n_class_scopes)
00308
00309
00310
00311
00312
00313
00314
00315 return tsk_insufficient_parms;
00316 else if (n_template_parm_scopes == n_class_scopes)
00317
00318
00319
00320
00321
00322
00323
00324 return tsk_none;
00325 else if (n_template_parm_scopes > n_class_scopes + 1)
00326
00327
00328
00329
00330
00331 return tsk_excessive_parms;
00332 else
00333
00334
00335
00336
00337
00338
00339
00340 return innermost_specialization_p ? tsk_expl_spec : tsk_template;
00341 }
00342
00343
00344
00345 void
00346 finish_scope (void)
00347 {
00348 poplevel (0, 0, 0);
00349 }
00350
00351
00352
00353
00354 static void
00355 pop_label (tree label, tree old_value)
00356 {
00357 if (!processing_template_decl)
00358 {
00359 if (DECL_INITIAL (label) == NULL_TREE)
00360 {
00361 location_t location;
00362
00363 error ("label %q+D used but not defined", label);
00364 #ifdef USE_MAPPED_LOCATION
00365 location = input_location;
00366 #else
00367 location.file = input_filename;
00368 location.line = 0;
00369 #endif
00370
00371 define_label (location, DECL_NAME (label));
00372 }
00373 else if (!TREE_USED (label))
00374 warning (OPT_Wunused_label, "label %q+D defined but not used", label);
00375 }
00376
00377 SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), old_value);
00378 }
00379
00380
00381
00382
00383
00384 static int
00385 pop_labels_1 (void **slot, void *data)
00386 {
00387 struct named_label_entry *ent = (struct named_label_entry *) *slot;
00388 tree block = (tree) data;
00389
00390 pop_label (ent->label_decl, NULL_TREE);
00391
00392
00393
00394 TREE_CHAIN (ent->label_decl) = BLOCK_VARS (block);
00395 BLOCK_VARS (block) = ent->label_decl;
00396
00397 htab_clear_slot (named_labels, slot);
00398
00399 return 1;
00400 }
00401
00402 static void
00403 pop_labels (tree block)
00404 {
00405 if (named_labels)
00406 {
00407 htab_traverse (named_labels, pop_labels_1, block);
00408 named_labels = NULL;
00409 }
00410 }
00411
00412
00413
00414 static void
00415 pop_local_label (tree label, tree old_value)
00416 {
00417 struct named_label_entry dummy;
00418 void **slot;
00419
00420 pop_label (label, old_value);
00421
00422 dummy.label_decl = label;
00423 slot = htab_find_slot (named_labels, &dummy, NO_INSERT);
00424 htab_clear_slot (named_labels, slot);
00425 }
00426
00427
00428
00429
00430 void *
00431 objc_get_current_scope (void)
00432 {
00433 return current_binding_level;
00434 }
00435
00436
00437
00438
00439
00440
00441
00442 void
00443 objc_mark_locals_volatile (void *enclosing_blk)
00444 {
00445 struct cp_binding_level *scope;
00446
00447 for (scope = current_binding_level;
00448 scope && scope != enclosing_blk;
00449 scope = scope->level_chain)
00450 {
00451 tree decl;
00452
00453 for (decl = scope->names; decl; decl = TREE_CHAIN (decl))
00454 objc_volatilize_decl (decl);
00455
00456
00457 if (scope->kind == sk_function_parms)
00458 break;
00459 }
00460 }
00461
00462
00463
00464 static int
00465 poplevel_named_label_1 (void **slot, void *data)
00466 {
00467 struct named_label_entry *ent = (struct named_label_entry *) *slot;
00468 struct cp_binding_level *bl = (struct cp_binding_level *) data;
00469 struct cp_binding_level *obl = bl->level_chain;
00470
00471 if (ent->binding_level == bl)
00472 {
00473 tree decl;
00474
00475 for (decl = ent->names_in_scope; decl; decl = TREE_CHAIN (decl))
00476 if (decl_jump_unsafe (decl))
00477 ent->bad_decls = tree_cons (NULL, decl, ent->bad_decls);
00478
00479 ent->binding_level = obl;
00480 ent->names_in_scope = obl->names;
00481 switch (bl->kind)
00482 {
00483 case sk_try:
00484 ent->in_try_scope = true;
00485 break;
00486 case sk_catch:
00487 ent->in_catch_scope = true;
00488 break;
00489 case sk_omp:
00490 ent->in_omp_scope = true;
00491 break;
00492 default:
00493 break;
00494 }
00495 }
00496 else if (ent->uses)
00497 {
00498 struct named_label_use_entry *use;
00499
00500 for (use = ent->uses; use ; use = use->next)
00501 if (use->binding_level == bl)
00502 {
00503 use->binding_level = obl;
00504 use->names_in_scope = obl->names;
00505 if (bl->kind == sk_omp)
00506 use->in_omp_scope = true;
00507 }
00508 }
00509
00510 return 1;
00511 }
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528 tree
00529 poplevel (int keep, int reverse, int functionbody)
00530 {
00531 tree link;
00532
00533
00534 tree decls;
00535 int tmp = functionbody;
00536 int real_functionbody;
00537 tree subblocks;
00538 tree block;
00539 tree decl;
00540 int leaving_for_scope;
00541 scope_kind kind;
00542
00543 timevar_push (TV_NAME_LOOKUP);
00544 restart:
00545
00546 block = NULL_TREE;
00547
00548 gcc_assert (current_binding_level->kind != sk_class);
00549
00550 real_functionbody = (current_binding_level->kind == sk_cleanup
00551 ? ((functionbody = 0), tmp) : functionbody);
00552 subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
00553
00554 gcc_assert (!VEC_length(cp_class_binding,
00555 current_binding_level->class_shadowed));
00556
00557
00558
00559
00560 gcc_assert (keep == 0 || keep == 1);
00561
00562 if (current_binding_level->keep)
00563 keep = 1;
00564
00565
00566
00567 if (cfun && !functionbody && named_labels)
00568 htab_traverse (named_labels, poplevel_named_label_1,
00569 current_binding_level);
00570
00571
00572
00573
00574
00575 if (reverse)
00576 current_binding_level->names
00577 = decls = nreverse (current_binding_level->names);
00578 else
00579 decls = current_binding_level->names;
00580
00581
00582
00583
00584 block = NULL_TREE;
00585 if (keep == 1 || functionbody)
00586 block = make_node (BLOCK);
00587 if (block != NULL_TREE)
00588 {
00589 BLOCK_VARS (block) = decls;
00590 BLOCK_SUBBLOCKS (block) = subblocks;
00591 }
00592
00593
00594 if (keep >= 0)
00595 for (link = subblocks; link; link = TREE_CHAIN (link))
00596 BLOCK_SUPERCONTEXT (link) = block;
00597
00598
00599
00600
00601
00602 leaving_for_scope
00603 = current_binding_level->kind == sk_for && flag_new_for_scope == 1;
00604
00605
00606 if (warn_unused_variable
00607 && !processing_template_decl)
00608 for (decl = getdecls (); decl; decl = TREE_CHAIN (decl))
00609 if (TREE_CODE (decl) == VAR_DECL
00610 && ! TREE_USED (decl)
00611 && ! DECL_IN_SYSTEM_HEADER (decl)
00612 && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
00613 warning (OPT_Wunused_variable, "unused variable %q+D", decl);
00614
00615
00616 for (link = decls; link; link = TREE_CHAIN (link))
00617 {
00618 if (leaving_for_scope && TREE_CODE (link) == VAR_DECL
00619 && DECL_NAME (link))
00620 {
00621 tree name = DECL_NAME (link);
00622 cxx_binding *ob;
00623 tree ns_binding;
00624
00625 ob = outer_binding (name,
00626 IDENTIFIER_BINDING (name),
00627 true);
00628 if (!ob)
00629 ns_binding = IDENTIFIER_NAMESPACE_VALUE (name);
00630 else
00631 ns_binding = NULL_TREE;
00632
00633 if (ob && ob->scope == current_binding_level->level_chain)
00634
00635
00636
00637
00638
00639
00640
00641 pop_binding (name, link);
00642 else if ((ob && (TREE_CODE (ob->value) == TYPE_DECL))
00643 || (ns_binding && TREE_CODE (ns_binding) == TYPE_DECL))
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654 pop_binding (name, link);
00655 else
00656 {
00657
00658
00659 DECL_DEAD_FOR_LOCAL (link) = 1;
00660
00661
00662
00663 if (ob && ob->value)
00664 {
00665 SET_DECL_SHADOWED_FOR_VAR (link, ob->value);
00666 DECL_HAS_SHADOWED_FOR_VAR_P (link) = 1;
00667 }
00668
00669
00670
00671
00672 current_binding_level->level_chain->dead_vars_from_for
00673 = tree_cons (NULL_TREE, link,
00674 current_binding_level->level_chain->
00675 dead_vars_from_for);
00676
00677
00678
00679 IDENTIFIER_BINDING (name)->scope
00680 = current_binding_level->level_chain;
00681 }
00682 }
00683 else
00684 {
00685 tree name;
00686
00687
00688 decl = link;
00689
00690 if (TREE_CODE (decl) == TREE_LIST)
00691 decl = TREE_VALUE (decl);
00692 name = decl;
00693
00694 if (TREE_CODE (name) == OVERLOAD)
00695 name = OVL_FUNCTION (name);
00696
00697 gcc_assert (DECL_P (name));
00698 pop_binding (DECL_NAME (name), decl);
00699 }
00700 }
00701
00702
00703
00704 for (link = current_binding_level->dead_vars_from_for;
00705 link; link = TREE_CHAIN (link))
00706 pop_binding (DECL_NAME (TREE_VALUE (link)), TREE_VALUE (link));
00707
00708
00709 for (link = current_binding_level->type_shadowed;
00710 link; link = TREE_CHAIN (link))
00711 SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link), TREE_VALUE (link));
00712
00713
00714 for (link = current_binding_level->shadowed_labels;
00715 link;
00716 link = TREE_CHAIN (link))
00717 pop_local_label (TREE_VALUE (link), TREE_PURPOSE (link));
00718
00719
00720
00721
00722
00723
00724
00725 if (block)
00726 {
00727 tree* d;
00728
00729 for (d = &BLOCK_VARS (block); *d; )
00730 {
00731 if (TREE_CODE (*d) == TREE_LIST)
00732 *d = TREE_CHAIN (*d);
00733 else
00734 d = &TREE_CHAIN (*d);
00735 }
00736 }
00737
00738
00739
00740 if (functionbody)
00741 {
00742
00743
00744
00745 BLOCK_VARS (block) = 0;
00746 pop_labels (block);
00747 }
00748
00749 kind = current_binding_level->kind;
00750 if (kind == sk_cleanup)
00751 {
00752 tree stmt;
00753
00754
00755
00756
00757 stmt = pop_stmt_list (current_binding_level->statement_list);
00758 stmt = c_build_bind_expr (block, stmt);
00759 add_stmt (stmt);
00760 }
00761
00762 leave_scope ();
00763 if (functionbody)
00764 DECL_INITIAL (current_function_decl) = block;
00765 else if (block)
00766 current_binding_level->blocks
00767 = chainon (current_binding_level->blocks, block);
00768
00769
00770
00771
00772
00773
00774 else if (subblocks)
00775 current_binding_level->blocks
00776 = chainon (current_binding_level->blocks, subblocks);
00777
00778
00779
00780
00781 if (block)
00782 TREE_USED (block) = 1;
00783
00784
00785 if (kind == sk_cleanup)
00786 goto restart;
00787
00788 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, block);
00789 }
00790
00791
00792
00793
00794
00795 void
00796 insert_block (tree block)
00797 {
00798 TREE_USED (block) = 1;
00799 current_binding_level->blocks
00800 = chainon (current_binding_level->blocks, block);
00801 }
00802
00803
00804
00805
00806 static int
00807 walk_namespaces_r (tree namespace, walk_namespaces_fn f, void* data)
00808 {
00809 int result = 0;
00810 tree current = NAMESPACE_LEVEL (namespace)->namespaces;
00811
00812 result |= (*f) (namespace, data);
00813
00814 for (; current; current = TREE_CHAIN (current))
00815 result |= walk_namespaces_r (current, f, data);
00816
00817 return result;
00818 }
00819
00820
00821
00822
00823 int
00824 walk_namespaces (walk_namespaces_fn f, void* data)
00825 {
00826 return walk_namespaces_r (global_namespace, f, data);
00827 }
00828
00829
00830
00831
00832
00833 int
00834 wrapup_globals_for_namespace (tree namespace, void* data)
00835 {
00836 struct cp_binding_level *level = NAMESPACE_LEVEL (namespace);
00837 VEC(tree,gc) *statics = level->static_decls;
00838 tree *vec = VEC_address (tree, statics);
00839 int len = VEC_length (tree, statics);
00840 int last_time = (data != 0);
00841
00842 if (last_time)
00843 {
00844 check_global_declarations (vec, len);
00845 emit_debug_global_declarations (vec, len);
00846 return 0;
00847 }
00848
00849
00850 return wrapup_global_declarations (vec, len);
00851 }
00852
00853
00854
00855
00856
00857
00858
00859 tree
00860 create_implicit_typedef (tree name, tree type)
00861 {
00862 tree decl;
00863
00864 decl = build_decl (TYPE_DECL, name, type);
00865 DECL_ARTIFICIAL (decl) = 1;
00866
00867
00868
00869 SET_DECL_IMPLICIT_TYPEDEF_P (decl);
00870 TYPE_NAME (type) = decl;
00871
00872 return decl;
00873 }
00874
00875
00876
00877 static void
00878 push_local_name (tree decl)
00879 {
00880 size_t i, nelts;
00881 tree t, name;
00882
00883 timevar_push (TV_NAME_LOOKUP);
00884
00885 name = DECL_NAME (decl);
00886
00887 nelts = VEC_length (tree, local_names);
00888 for (i = 0; i < nelts; i++)
00889 {
00890 t = VEC_index (tree, local_names, i);
00891 if (DECL_NAME (t) == name)
00892 {
00893 if (!DECL_LANG_SPECIFIC (decl))
00894 retrofit_lang_decl (decl);
00895 DECL_LANG_SPECIFIC (decl)->decl_flags.u2sel = 1;
00896 if (DECL_LANG_SPECIFIC (t))
00897 DECL_DISCRIMINATOR (decl) = DECL_DISCRIMINATOR (t) + 1;
00898 else
00899 DECL_DISCRIMINATOR (decl) = 1;
00900
00901 VEC_replace (tree, local_names, i, decl);
00902 timevar_pop (TV_NAME_LOOKUP);
00903 return;
00904 }
00905 }
00906
00907 VEC_safe_push (tree, gc, local_names, decl);
00908 timevar_pop (TV_NAME_LOOKUP);
00909 }
00910
00911
00912
00913
00914
00915
00916
00917
00918 int
00919 decls_match (tree newdecl, tree olddecl)
00920 {
00921 int types_match;
00922
00923 if (newdecl == olddecl)
00924 return 1;
00925
00926 if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
00927
00928
00929 return 0;
00930
00931 if (TREE_CODE (newdecl) == FUNCTION_DECL)
00932 {
00933 tree f1 = TREE_TYPE (newdecl);
00934 tree f2 = TREE_TYPE (olddecl);
00935 tree p1 = TYPE_ARG_TYPES (f1);
00936 tree p2 = TYPE_ARG_TYPES (f2);
00937
00938 if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
00939 && ! (DECL_EXTERN_C_P (newdecl)
00940 && DECL_EXTERN_C_P (olddecl)))
00941 return 0;
00942
00943 if (TREE_CODE (f1) != TREE_CODE (f2))
00944 return 0;
00945
00946 if (same_type_p (TREE_TYPE (f1), TREE_TYPE (f2)))
00947 {
00948 if (p2 == NULL_TREE && DECL_EXTERN_C_P (olddecl)
00949 && (DECL_BUILT_IN (olddecl)
00950 #ifndef NO_IMPLICIT_EXTERN_C
00951 || (DECL_IN_SYSTEM_HEADER (newdecl) && !DECL_CLASS_SCOPE_P (newdecl))
00952 || (DECL_IN_SYSTEM_HEADER (olddecl) && !DECL_CLASS_SCOPE_P (olddecl))
00953 #endif
00954 ))
00955 {
00956 types_match = self_promoting_args_p (p1);
00957 if (p1 == void_list_node)
00958 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
00959 }
00960 #ifndef NO_IMPLICIT_EXTERN_C
00961 else if (p1 == NULL_TREE
00962 && (DECL_EXTERN_C_P (olddecl)
00963 && DECL_IN_SYSTEM_HEADER (olddecl)
00964 && !DECL_CLASS_SCOPE_P (olddecl))
00965 && (DECL_EXTERN_C_P (newdecl)
00966 && DECL_IN_SYSTEM_HEADER (newdecl)
00967 && !DECL_CLASS_SCOPE_P (newdecl)))
00968 {
00969 types_match = self_promoting_args_p (p2);
00970 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
00971 }
00972 #endif
00973 else
00974 types_match = compparms (p1, p2);
00975 }
00976 else
00977 types_match = 0;
00978 }
00979 else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
00980 {
00981 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl))
00982 != TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)))
00983 return 0;
00984
00985 if (!comp_template_parms (DECL_TEMPLATE_PARMS (newdecl),
00986 DECL_TEMPLATE_PARMS (olddecl)))
00987 return 0;
00988
00989 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
00990 types_match = same_type_p (TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl)),
00991 TREE_TYPE (DECL_TEMPLATE_RESULT (newdecl)));
00992 else
00993 types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl),
00994 DECL_TEMPLATE_RESULT (newdecl));
00995 }
00996 else
00997 {
00998
00999
01000 if (TREE_CODE (newdecl) == VAR_DECL
01001 && CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
01002
01003
01004
01005
01006
01007 && !(DECL_EXTERN_C_P (olddecl) && DECL_EXTERN_C_P (newdecl)))
01008 return 0;
01009
01010 if (TREE_TYPE (newdecl) == error_mark_node)
01011 types_match = TREE_TYPE (olddecl) == error_mark_node;
01012 else if (TREE_TYPE (olddecl) == NULL_TREE)
01013 types_match = TREE_TYPE (newdecl) == NULL_TREE;
01014 else if (TREE_TYPE (newdecl) == NULL_TREE)
01015 types_match = 0;
01016 else
01017 types_match = comptypes (TREE_TYPE (newdecl),
01018 TREE_TYPE (olddecl),
01019 COMPARE_REDECLARATION);
01020 }
01021
01022 return types_match;
01023 }
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034 void
01035 warn_extern_redeclared_static (tree newdecl, tree olddecl)
01036 {
01037 tree name;
01038
01039 if (TREE_CODE (newdecl) == TYPE_DECL
01040 || TREE_CODE (newdecl) == TEMPLATE_DECL
01041 || TREE_CODE (newdecl) == CONST_DECL
01042 || TREE_CODE (newdecl) == NAMESPACE_DECL)
01043 return;
01044
01045
01046
01047 if (TREE_CODE (newdecl) == FUNCTION_DECL
01048 && DECL_STATIC_FUNCTION_P (newdecl))
01049 return;
01050
01051
01052
01053 if (DECL_THIS_STATIC (olddecl) || !DECL_THIS_STATIC (newdecl))
01054 return;
01055
01056
01057 if (TREE_CODE (olddecl) == FUNCTION_DECL
01058 && DECL_ARTIFICIAL (olddecl))
01059 return;
01060
01061 name = DECL_ASSEMBLER_NAME (newdecl);
01062 pedwarn ("%qD was declared %<extern%> and later %<static%>", newdecl);
01063 pedwarn ("previous declaration of %q+D", olddecl);
01064 }
01065
01066
01067
01068
01069
01070 static void
01071 check_redeclaration_exception_specification (tree new_decl,
01072 tree old_decl)
01073 {
01074 tree new_type;
01075 tree old_type;
01076 tree new_exceptions;
01077 tree old_exceptions;
01078
01079 new_type = TREE_TYPE (new_decl);
01080 new_exceptions = TYPE_RAISES_EXCEPTIONS (new_type);
01081 old_type = TREE_TYPE (old_decl);
01082 old_exceptions = TYPE_RAISES_EXCEPTIONS (old_type);
01083
01084
01085
01086
01087
01088
01089
01090 if ((pedantic || ! DECL_IN_SYSTEM_HEADER (old_decl))
01091 && ! DECL_IS_BUILTIN (old_decl)
01092 && flag_exceptions
01093 && !comp_except_specs (new_exceptions, old_exceptions,
01094 true))
01095 {
01096 error ("declaration of %qF throws different exceptions", new_decl);
01097 error ("from previous declaration %q+F", old_decl);
01098 }
01099 }
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110 tree
01111 duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend)
01112 {
01113 unsigned olddecl_uid = DECL_UID (olddecl);
01114 int olddecl_friend = 0, types_match = 0, hidden_friend = 0;
01115 int new_defines_function = 0;
01116 tree new_template;
01117
01118 if (newdecl == olddecl)
01119 return olddecl;
01120
01121 types_match = decls_match (newdecl, olddecl);
01122
01123
01124
01125
01126
01127
01128 if (TREE_TYPE (newdecl) == error_mark_node
01129 || TREE_TYPE (olddecl) == error_mark_node)
01130 return error_mark_node;
01131
01132 if (DECL_P (olddecl)
01133 && TREE_CODE (newdecl) == FUNCTION_DECL
01134 && TREE_CODE (olddecl) == FUNCTION_DECL
01135 && (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl)))
01136 {
01137 if (DECL_DECLARED_INLINE_P (newdecl)
01138 && DECL_UNINLINABLE (newdecl)
01139 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
01140 ;
01141 else if (DECL_DECLARED_INLINE_P (olddecl)
01142 && DECL_UNINLINABLE (olddecl)
01143 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
01144 ;
01145 else if (DECL_DECLARED_INLINE_P (newdecl)
01146 && DECL_UNINLINABLE (olddecl)
01147 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
01148 {
01149 warning (OPT_Wattributes, "function %q+D redeclared as inline",
01150 newdecl);
01151 warning (OPT_Wattributes, "previous declaration of %q+D "
01152 "with attribute noinline", olddecl);
01153 }
01154 else if (DECL_DECLARED_INLINE_P (olddecl)
01155 && DECL_UNINLINABLE (newdecl)
01156 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
01157 {
01158 warning (OPT_Wattributes, "function %q+D redeclared with "
01159 "attribute noinline", newdecl);
01160 warning (OPT_Wattributes, "previous declaration of %q+D was inline",
01161 olddecl);
01162 }
01163 }
01164
01165
01166 if (TREE_CODE (olddecl) == FUNCTION_DECL
01167 && DECL_ARTIFICIAL (olddecl))
01168 {
01169 gcc_assert (!DECL_HIDDEN_FRIEND_P (olddecl));
01170 if (TREE_CODE (newdecl) != FUNCTION_DECL)
01171 {
01172
01173
01174 if (DECL_ANTICIPATED (olddecl))
01175 return NULL_TREE;
01176
01177
01178
01179
01180 if (! TREE_PUBLIC (newdecl))
01181 {
01182 warning (OPT_Wshadow, "shadowing %s function %q#D",
01183 DECL_BUILT_IN (olddecl) ? "built-in" : "library",
01184 olddecl);
01185
01186 return NULL_TREE;
01187 }
01188
01189
01190 else if (! DECL_BUILT_IN (olddecl))
01191 warning (0, "library function %q#D redeclared as non-function %q#D",
01192 olddecl, newdecl);
01193 else
01194 {
01195 error ("declaration of %q#D", newdecl);
01196 error ("conflicts with built-in declaration %q#D",
01197 olddecl);
01198 }
01199 return NULL_TREE;
01200 }
01201 else if (!types_match)
01202 {
01203
01204
01205 if (DECL_ANTICIPATED (olddecl))
01206 {
01207
01208
01209 tree t1, t2;
01210
01211 for (t1 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
01212 t2 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
01213 t1 || t2;
01214 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
01215 if (!t1 || !t2)
01216 break;
01217 else if (TREE_VALUE (t2) == fileptr_type_node)
01218 {
01219 tree t = TREE_VALUE (t1);
01220
01221 if (TREE_CODE (t) == POINTER_TYPE
01222 && TYPE_NAME (TREE_TYPE (t))
01223 && DECL_NAME (TYPE_NAME (TREE_TYPE (t)))
01224 == get_identifier ("FILE")
01225 && compparms (TREE_CHAIN (t1), TREE_CHAIN (t2)))
01226 {
01227 tree oldargs = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
01228
01229 TYPE_ARG_TYPES (TREE_TYPE (olddecl))
01230 = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
01231 types_match = decls_match (newdecl, olddecl);
01232 if (types_match)
01233 return duplicate_decls (newdecl, olddecl,
01234 newdecl_is_friend);
01235 TYPE_ARG_TYPES (TREE_TYPE (olddecl)) = oldargs;
01236 }
01237 }
01238 else if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
01239 break;
01240 }
01241 else if ((DECL_EXTERN_C_P (newdecl)
01242 && DECL_EXTERN_C_P (olddecl))
01243 || compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
01244 TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
01245 {
01246
01247
01248 if (TREE_PUBLIC (newdecl))
01249 {
01250 warning (0, "new declaration %q#D", newdecl);
01251 warning (0, "ambiguates built-in declaration %q#D",
01252 olddecl);
01253 }
01254 else
01255 warning (OPT_Wshadow, "shadowing %s function %q#D",
01256 DECL_BUILT_IN (olddecl) ? "built-in" : "library",
01257 olddecl);
01258 }
01259 else
01260
01261 return NULL_TREE;
01262
01263
01264 COPY_DECL_RTL (newdecl, olddecl);
01265 }
01266
01267
01268
01269 else if (DECL_ANTICIPATED (olddecl))
01270 {
01271 tree type = TREE_TYPE (newdecl);
01272 tree attribs = (*targetm.merge_type_attributes)
01273 (TREE_TYPE (olddecl), type);
01274
01275 type = cp_build_type_attribute_variant (type, attribs);
01276 TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = type;
01277 }
01278
01279
01280
01281 TREE_NOTHROW (olddecl) = 0;
01282
01283 if (DECL_THIS_STATIC (newdecl) && !DECL_THIS_STATIC (olddecl))
01284 {
01285
01286
01287 DECL_THIS_STATIC (olddecl) = 1;
01288 TREE_PUBLIC (olddecl) = 0;
01289
01290
01291
01292
01293 SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
01294 COPY_DECL_RTL (newdecl, olddecl);
01295 }
01296 }
01297 else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
01298 {
01299 if ((TREE_CODE (olddecl) == TYPE_DECL && DECL_ARTIFICIAL (olddecl)
01300 && TREE_CODE (newdecl) != TYPE_DECL
01301 && ! (TREE_CODE (newdecl) == TEMPLATE_DECL
01302 && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL))
01303 || (TREE_CODE (newdecl) == TYPE_DECL && DECL_ARTIFICIAL (newdecl)
01304 && TREE_CODE (olddecl) != TYPE_DECL
01305 && ! (TREE_CODE (olddecl) == TEMPLATE_DECL
01306 && (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl))
01307 == TYPE_DECL))))
01308 {
01309
01310
01311
01312
01313
01314 return NULL_TREE;
01315 }
01316
01317 if ((TREE_CODE (newdecl) == FUNCTION_DECL
01318 && DECL_FUNCTION_TEMPLATE_P (olddecl))
01319 || (TREE_CODE (olddecl) == FUNCTION_DECL
01320 && DECL_FUNCTION_TEMPLATE_P (newdecl)))
01321 return NULL_TREE;
01322
01323 error ("%q#D redeclared as different kind of symbol", newdecl);
01324 if (TREE_CODE (olddecl) == TREE_LIST)
01325 olddecl = TREE_VALUE (olddecl);
01326 error ("previous declaration of %q+#D", olddecl);
01327
01328 return error_mark_node;
01329 }
01330 else if (!types_match)
01331 {
01332 if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl))
01333
01334
01335 return NULL_TREE;
01336
01337 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
01338 {
01339
01340
01341
01342 if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == TYPE_DECL
01343 || TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
01344 {
01345 error ("declaration of template %q#D", newdecl);
01346 error ("conflicts with previous declaration %q+#D", olddecl);
01347 }
01348 else if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == FUNCTION_DECL
01349 && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL
01350 && compparms (TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl))),
01351 TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (newdecl))))
01352 && comp_template_parms (DECL_TEMPLATE_PARMS (newdecl),
01353 DECL_TEMPLATE_PARMS (olddecl))
01354
01355
01356 && same_type_p (TREE_TYPE (TREE_TYPE (newdecl)),
01357 TREE_TYPE (TREE_TYPE (olddecl))))
01358 {
01359 error ("new declaration %q#D", newdecl);
01360 error ("ambiguates old declaration %q+#D", olddecl);
01361 }
01362 return NULL_TREE;
01363 }
01364 if (TREE_CODE (newdecl) == FUNCTION_DECL)
01365 {
01366 if (DECL_EXTERN_C_P (newdecl) && DECL_EXTERN_C_P (olddecl))
01367 {
01368 error ("declaration of C function %q#D conflicts with",
01369 newdecl);
01370 error ("previous declaration %q+#D here", olddecl);
01371 }
01372 else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
01373 TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
01374 {
01375 error ("new declaration %q#D", newdecl);
01376 error ("ambiguates old declaration %q+#D", olddecl);
01377 return error_mark_node;
01378 }
01379 else
01380 return NULL_TREE;
01381 }
01382 else
01383 {
01384 error ("conflicting declaration %q#D", newdecl);
01385 error ("%q+D has a previous declaration as %q#D", olddecl, olddecl);
01386 return error_mark_node;
01387 }
01388 }
01389 else if (TREE_CODE (newdecl) == FUNCTION_DECL
01390 && ((DECL_TEMPLATE_SPECIALIZATION (olddecl)
01391 && (!DECL_TEMPLATE_INFO (newdecl)
01392 || (DECL_TI_TEMPLATE (newdecl)
01393 != DECL_TI_TEMPLATE (olddecl))))
01394 || (DECL_TEMPLATE_SPECIALIZATION (newdecl)
01395 && (!DECL_TEMPLATE_INFO (olddecl)
01396 || (DECL_TI_TEMPLATE (olddecl)
01397 != DECL_TI_TEMPLATE (newdecl))))))
01398
01399
01400
01401
01402
01403
01404
01405
01406 return NULL_TREE;
01407 else if (TREE_CODE (newdecl) == FUNCTION_DECL
01408 && ((DECL_TEMPLATE_INSTANTIATION (olddecl)
01409 && !DECL_USE_TEMPLATE (newdecl))
01410 || (DECL_TEMPLATE_INSTANTIATION (newdecl)
01411 && !DECL_USE_TEMPLATE (olddecl))))
01412
01413
01414 return NULL_TREE;
01415 else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
01416 {
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426 if (DECL_NAMESPACE_ALIAS (newdecl)
01427 && (DECL_NAMESPACE_ALIAS (newdecl)
01428 == DECL_NAMESPACE_ALIAS (olddecl)))
01429 return olddecl;
01430
01431
01432
01433
01434
01435
01436
01437 error ("declaration of namespace %qD conflicts with", newdecl);
01438 error ("previous declaration of namespace %q+D here", olddecl);
01439 return error_mark_node;
01440 }
01441 else
01442 {
01443 const char *errmsg = redeclaration_error_message (newdecl, olddecl);
01444 if (errmsg)
01445 {
01446 error (errmsg, newdecl);
01447 if (DECL_NAME (olddecl) != NULL_TREE)
01448 error ((DECL_INITIAL (olddecl) && namespace_bindings_p ())
01449 ? "%q+#D previously defined here"
01450 : "%q+#D previously declared here", olddecl);
01451 return error_mark_node;
01452 }
01453 else if (TREE_CODE (olddecl) == FUNCTION_DECL
01454 && DECL_INITIAL (olddecl) != NULL_TREE
01455 && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE
01456 && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE)
01457 {
01458
01459 warning (0, "prototype for %q+#D", newdecl);
01460 warning (0, "%Jfollows non-prototype definition here", olddecl);
01461 }
01462 else if ((TREE_CODE (olddecl) == FUNCTION_DECL
01463 || TREE_CODE (olddecl) == VAR_DECL)
01464 && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
01465 {
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487
01488
01489
01490 if (current_lang_depth () == 0)
01491 {
01492
01493
01494 if (!DECL_LANG_SPECIFIC (newdecl))
01495 retrofit_lang_decl (newdecl);
01496 SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
01497 }
01498 else
01499 {
01500 error ("previous declaration of %q+#D with %qL linkage",
01501 olddecl, DECL_LANGUAGE (olddecl));
01502 error ("conflicts with new declaration with %qL linkage",
01503 DECL_LANGUAGE (newdecl));
01504 }
01505 }
01506
01507 if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl))
01508 ;
01509 else if (TREE_CODE (olddecl) == FUNCTION_DECL)
01510 {
01511 tree t1 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
01512 tree t2 = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
01513 int i = 1;
01514
01515 if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE)
01516 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2);
01517
01518 for (; t1 && t1 != void_list_node;
01519 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
01520 if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
01521 {
01522 if (1 == simple_cst_equal (TREE_PURPOSE (t1),
01523 TREE_PURPOSE (t2)))
01524 {
01525 pedwarn ("default argument given for parameter %d of %q#D",
01526 i, newdecl);
01527 pedwarn ("after previous specification in %q+#D", olddecl);
01528 }
01529 else
01530 {
01531 error ("default argument given for parameter %d of %q#D",
01532 i, newdecl);
01533 error ("after previous specification in %q+#D",
01534 olddecl);
01535 }
01536 }
01537
01538 if (DECL_DECLARED_INLINE_P (newdecl)
01539 && ! DECL_DECLARED_INLINE_P (olddecl)
01540 && TREE_ADDRESSABLE (olddecl) && warn_inline)
01541 {
01542 warning (0, "%q#D was used before it was declared inline", newdecl);
01543 warning (0, "%Jprevious non-inline declaration here", olddecl);
01544 }
01545 }
01546 }
01547
01548
01549
01550
01551
01552
01553
01554
01555 if (TREE_CODE (olddecl) == TYPE_DECL
01556 && (DECL_IMPLICIT_TYPEDEF_P (olddecl)
01557 || DECL_IMPLICIT_TYPEDEF_P (newdecl)))
01558 return NULL_TREE;
01559
01560
01561
01562 warn_extern_redeclared_static (newdecl, olddecl);
01563
01564
01565 if (TREE_CODE (newdecl) == FUNCTION_DECL)
01566 {
01567
01568
01569
01570
01571 if (DECL_VINDEX (olddecl))
01572 DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
01573 if (DECL_CONTEXT (olddecl))
01574 DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
01575 DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
01576 DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
01577 DECL_PURE_VIRTUAL_P (newdecl) |= DECL_PURE_VIRTUAL_P (olddecl);
01578 DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl);
01579 DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl);
01580 if (DECL_OVERLOADED_OPERATOR_P (olddecl) != ERROR_MARK)
01581 SET_OVERLOADED_OPERATOR_CODE
01582 (newdecl, DECL_OVERLOADED_OPERATOR_P (olddecl));
01583 new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE;
01584
01585
01586
01587
01588 if (warn_redundant_decls && ! DECL_ARTIFICIAL (olddecl)
01589 && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
01590
01591 && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))
01592
01593 && ! (newdecl_is_friend || DECL_FRIEND_P (olddecl)))
01594 {
01595 warning (OPT_Wredundant_decls, "redundant redeclaration of %qD in same scope", newdecl);
01596 warning (OPT_Wredundant_decls, "previous declaration of %q+D", olddecl);
01597 }
01598 }
01599
01600
01601 if (TREE_CODE (olddecl) == TYPE_DECL)
01602 {
01603 tree newtype = TREE_TYPE (newdecl);
01604 tree oldtype = TREE_TYPE (olddecl);
01605
01606 if (newtype != error_mark_node && oldtype != error_mark_node
01607 && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
01608 CLASSTYPE_FRIEND_CLASSES (newtype)
01609 = CLASSTYPE_FRIEND_CLASSES (oldtype);
01610
01611 DECL_ORIGINAL_TYPE (newdecl) = DECL_ORIGINAL_TYPE (olddecl);
01612 }
01613
01614
01615
01616 DECL_ATTRIBUTES (newdecl)
01617 = (*targetm.merge_decl_attributes) (olddecl, newdecl);
01618
01619 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
01620 {
01621 tree old_result;
01622 tree new_result;
01623 old_result = DECL_TEMPLATE_RESULT (olddecl);
01624 new_result = DECL_TEMPLATE_RESULT (newdecl);
01625 TREE_TYPE (olddecl) = TREE_TYPE (old_result);
01626 DECL_TEMPLATE_SPECIALIZATIONS (olddecl)
01627 = chainon (DECL_TEMPLATE_SPECIALIZATIONS (olddecl),
01628 DECL_TEMPLATE_SPECIALIZATIONS (newdecl));
01629
01630 if (DECL_FUNCTION_TEMPLATE_P (newdecl))
01631 {
01632 DECL_INLINE (old_result)
01633 |= DECL_INLINE (new_result);
01634 DECL_DECLARED_INLINE_P (old_result)
01635 |= DECL_DECLARED_INLINE_P (new_result);
01636 check_redeclaration_exception_specification (newdecl, olddecl);
01637 }
01638
01639
01640
01641 if (DECL_INITIAL (old_result) == NULL_TREE
01642 && DECL_INITIAL (new_result) != NULL_TREE)
01643 {
01644 DECL_SOURCE_LOCATION (olddecl)
01645 = DECL_SOURCE_LOCATION (old_result)
01646 = DECL_SOURCE_LOCATION (newdecl);
01647 if (DECL_FUNCTION_TEMPLATE_P (newdecl))
01648 DECL_ARGUMENTS (old_result)
01649 = DECL_ARGUMENTS (new_result);
01650 }
01651
01652 return olddecl;
01653 }
01654
01655 if (types_match)
01656 {
01657
01658 tree oldtype = TREE_TYPE (olddecl);
01659 tree newtype;
01660
01661
01662 newtype = merge_types (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
01663
01664
01665 if (TREE_CODE (newdecl) == TYPE_DECL
01666 && newtype == DECL_ORIGINAL_TYPE (newdecl))
01667 newtype = oldtype;
01668
01669 if (TREE_CODE (newdecl) == VAR_DECL)
01670 {
01671 DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
01672 DECL_INITIALIZED_P (newdecl) |= DECL_INITIALIZED_P (olddecl);
01673 DECL_NONTRIVIALLY_INITIALIZED_P (newdecl)
01674 |= DECL_NONTRIVIALLY_INITIALIZED_P (olddecl);
01675 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (newdecl)
01676 |= DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (olddecl);
01677
01678
01679 if (DECL_LANG_SPECIFIC (olddecl)
01680 && CP_DECL_THREADPRIVATE_P (olddecl))
01681 {
01682
01683 if (!DECL_LANG_SPECIFIC (newdecl))
01684 retrofit_lang_decl (newdecl);
01685
01686 DECL_TLS_MODEL (newdecl) = DECL_TLS_MODEL (olddecl);
01687 CP_DECL_THREADPRIVATE_P (newdecl) = 1;
01688 }
01689 }
01690
01691
01692
01693 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
01694 check_redeclaration_exception_specification (newdecl, olddecl);
01695 TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
01696
01697 if (TREE_CODE (newdecl) == FUNCTION_DECL)
01698 check_default_args (newdecl);
01699
01700
01701 if (! same_type_p (newtype, oldtype)
01702 && TREE_TYPE (newdecl) != error_mark_node
01703 && !(processing_template_decl && uses_template_parms (newdecl)))
01704 layout_type (TREE_TYPE (newdecl));
01705
01706 if ((TREE_CODE (newdecl) == VAR_DECL
01707 || TREE_CODE (newdecl) == PARM_DECL
01708 || TREE_CODE (newdecl) == RESULT_DECL
01709 || TREE_CODE (newdecl) == FIELD_DECL
01710 || TREE_CODE (newdecl) == TYPE_DECL)
01711 && !(processing_template_decl && uses_template_parms (newdecl)))
01712 layout_decl (newdecl, 0);
01713
01714
01715 if (TREE_READONLY (newdecl))
01716 TREE_READONLY (olddecl) = 1;
01717 if (TREE_THIS_VOLATILE (newdecl))
01718 TREE_THIS_VOLATILE (olddecl) = 1;
01719 if (TREE_NOTHROW (newdecl))
01720 TREE_NOTHROW (olddecl) = 1;
01721
01722
01723 if (TREE_DEPRECATED (newdecl))
01724 TREE_DEPRECATED (olddecl) = 1;
01725
01726
01727 if (DECL_INITIAL (newdecl) == NULL_TREE
01728 && DECL_INITIAL (olddecl) != NULL_TREE)
01729 {
01730 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
01731 DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
01732 if (CAN_HAVE_FULL_LANG_DECL_P (newdecl)
01733 && DECL_LANG_SPECIFIC (newdecl)
01734 && DECL_LANG_SPECIFIC (olddecl))
01735 {
01736 DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
01737 DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
01738 }
01739 }
01740
01741
01742
01743
01744
01745 if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
01746 DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
01747
01748 if (TREE_CODE (newdecl) == FUNCTION_DECL)
01749 {
01750 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
01751 |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
01752 DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
01753 TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
01754 TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
01755 TREE_NOTHROW (newdecl) |= TREE_NOTHROW (olddecl);
01756 DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
01757 DECL_IS_PURE (newdecl) |= DECL_IS_PURE (olddecl);
01758
01759 COPY_DECL_RTL (olddecl, newdecl);
01760 }
01761 else if (TREE_CODE (newdecl) == VAR_DECL
01762 && (DECL_SIZE (olddecl) || !DECL_SIZE (newdecl)))
01763 {
01764
01765
01766
01767
01768 COPY_DECL_RTL (olddecl, newdecl);
01769 }
01770 }
01771
01772
01773 else
01774 {
01775
01776 tree oldstatic = value_member (olddecl, static_aggregates);
01777 if (oldstatic)
01778 TREE_VALUE (oldstatic) = error_mark_node;
01779
01780 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
01781 TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
01782 TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
01783 TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
01784 }
01785
01786
01787 merge_weak (newdecl, olddecl);
01788
01789 DECL_ONE_ONLY (newdecl) |= DECL_ONE_ONLY (olddecl);
01790 DECL_DEFER_OUTPUT (newdecl) |= DECL_DEFER_OUTPUT (olddecl);
01791 TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
01792 TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
01793 if (! DECL_EXTERNAL (olddecl))
01794 DECL_EXTERNAL (newdecl) = 0;
01795
01796 new_template = NULL_TREE;
01797 if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl))
01798 {
01799 DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
01800 DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
01801 DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl);
01802 DECL_TEMPLATE_INSTANTIATED (newdecl)
01803 |= DECL_TEMPLATE_INSTANTIATED (olddecl);
01804
01805
01806
01807
01808
01809 if (!DECL_USE_TEMPLATE (newdecl))
01810 DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl);
01811
01812
01813
01814 DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
01815 DECL_LANG_SPECIFIC (newdecl)->decl_flags.u2 =
01816 DECL_LANG_SPECIFIC (olddecl)->decl_flags.u2;
01817 DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
01818 DECL_REPO_AVAILABLE_P (newdecl) = DECL_REPO_AVAILABLE_P (olddecl);
01819 if (DECL_TEMPLATE_INFO (newdecl))
01820 new_template = DECL_TI_TEMPLATE (newdecl);
01821 DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
01822 DECL_INITIALIZED_IN_CLASS_P (newdecl)
01823 |= DECL_INITIALIZED_IN_CLASS_P (olddecl);
01824 olddecl_friend = DECL_FRIEND_P (olddecl);
01825 hidden_friend = (DECL_ANTICIPATED (olddecl)
01826 && DECL_HIDDEN_FRIEND_P (olddecl)
01827 && newdecl_is_friend);
01828
01829
01830 if (TREE_CODE (newdecl) == FUNCTION_DECL
01831 || DECL_FUNCTION_TEMPLATE_P (newdecl))
01832 {
01833 DECL_BEFRIENDING_CLASSES (newdecl)
01834 = chainon (DECL_BEFRIENDING_CLASSES (newdecl),
01835 DECL_BEFRIENDING_CLASSES (olddecl));
01836
01837
01838 if (DECL_VIRTUAL_P (newdecl))
01839 DECL_THUNKS (newdecl) = DECL_THUNKS (olddecl);
01840 }
01841 }
01842
01843 if (TREE_CODE (newdecl) == FUNCTION_DECL)
01844 {
01845 if (DECL_TEMPLATE_INSTANTIATION (olddecl)
01846 && !DECL_TEMPLATE_INSTANTIATION (newdecl))
01847 {
01848
01849
01850
01851 gcc_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl));
01852
01853 if (TREE_USED (olddecl))
01854
01855
01856
01857
01858
01859
01860
01861
01862 error ("explicit specialization of %qD after first use",
01863 olddecl);
01864
01865 SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
01866
01867
01868
01869
01870 DECL_VISIBILITY_SPECIFIED (olddecl) = 0;
01871
01872
01873
01874 }
01875 else
01876 {
01877 if (DECL_PENDING_INLINE_INFO (newdecl) == 0)
01878 DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl);
01879
01880 DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl);
01881
01882
01883
01884 if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == NULL_TREE)
01885 DECL_INLINE (olddecl) = 1;
01886 DECL_INLINE (newdecl) = DECL_INLINE (olddecl);
01887
01888 DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
01889 = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
01890 }
01891
01892
01893 DECL_ABSTRACT (newdecl) = DECL_ABSTRACT (olddecl);
01894
01895 if (! types_match)
01896 {
01897 SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
01898 COPY_DECL_ASSEMBLER_NAME (newdecl, olddecl);
01899 COPY_DECL_RTL (newdecl, olddecl);
01900 }
01901 if (! types_match || new_defines_function)
01902 {
01903
01904
01905
01906 DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
01907 DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
01908 }
01909 if (new_defines_function)
01910
01911
01912 SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
01913 else if (types_match)
01914 {
01915
01916
01917 if (DECL_BUILT_IN (olddecl))
01918 {
01919 DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl);
01920 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
01921
01922
01923 COPY_DECL_RTL (olddecl, newdecl);
01924 }
01925
01926 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
01927
01928 if (DECL_ARGUMENTS (olddecl))
01929 DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
01930 }
01931 }
01932 else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
01933 NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
01934
01935
01936 TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
01937 TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
01938 DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
01939 COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
01940
01941
01942 if (DECL_VISIBILITY_SPECIFIED (olddecl)
01943 && DECL_VISIBILITY_SPECIFIED (newdecl)
01944 && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
01945 {
01946 warning (OPT_Wattributes, "%q+D: visibility attribute ignored "
01947 "because it", newdecl);
01948 warning (OPT_Wattributes, "%Jconflicts with previous "
01949 "declaration here", olddecl);
01950 }
01951
01952 if (DECL_VISIBILITY_SPECIFIED (olddecl))
01953 {
01954 DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
01955 DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
01956 }
01957
01958
01959 if (TREE_CODE (newdecl) == VAR_DECL && DECL_HAS_INIT_PRIORITY_P (newdecl))
01960 {
01961 SET_DECL_INIT_PRIORITY (olddecl, DECL_INIT_PRIORITY (newdecl));
01962 DECL_HAS_INIT_PRIORITY_P (olddecl) = 1;
01963 }
01964
01965
01966
01967 if (DECL_LANG_SPECIFIC (olddecl))
01968 {
01969 gcc_assert (DECL_LANG_SPECIFIC (olddecl)
01970 != DECL_LANG_SPECIFIC (newdecl));
01971 ggc_free (DECL_LANG_SPECIFIC (olddecl));
01972 }
01973
01974 if (TREE_CODE (newdecl) == FUNCTION_DECL)
01975 {
01976 int function_size;
01977
01978 function_size = sizeof (struct tree_decl_common);
01979
01980 memcpy ((char *) olddecl + sizeof (struct tree_common),
01981 (char *) newdecl + sizeof (struct tree_common),
01982 function_size - sizeof (struct tree_common));
01983
01984 memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
01985 (char *) newdecl + sizeof (struct tree_decl_common),
01986 sizeof (struct tree_function_decl) - sizeof (struct tree_decl_common));
01987 if (new_template)
01988
01989
01990
01991
01992
01993
01994
01995
01996
01997
01998
01999
02000
02001
02002
02003
02004
02005
02006
02007
02008
02009 reregister_specialization (newdecl,
02010 new_template,
02011 olddecl);
02012 }
02013 else
02014 {
02015 size_t size = tree_code_size (TREE_CODE (olddecl));
02016 memcpy ((char *) olddecl + sizeof (struct tree_common),
02017 (char *) newdecl + sizeof (struct tree_common),
02018 sizeof (struct tree_decl_common) - sizeof (struct tree_common));
02019 switch (TREE_CODE (olddecl))
02020 {
02021 case LABEL_DECL:
02022 case VAR_DECL:
02023 case RESULT_DECL:
02024 case PARM_DECL:
02025 case FIELD_DECL:
02026 case TYPE_DECL:
02027 case CONST_DECL:
02028 {
02029 memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
02030 (char *) newdecl + sizeof (struct tree_decl_common),
02031 size - sizeof (struct tree_decl_common)
02032 + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
02033 }
02034 break;
02035 default:
02036 memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
02037 (char *) newdecl + sizeof (struct tree_decl_common),
02038 sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common)
02039 + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
02040 break;
02041 }
02042 }
02043 DECL_UID (olddecl) = olddecl_uid;
02044 if (olddecl_friend)
02045 DECL_FRIEND_P (olddecl) = 1;
02046 if (hidden_friend)
02047 {
02048 DECL_ANTICIPATED (olddecl) = 1;
02049 DECL_HIDDEN_FRIEND_P (olddecl) = 1;
02050 }
02051
02052
02053
02054 DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
02055
02056
02057
02058
02059 if (DECL_RTL_SET_P (olddecl)
02060 && (TREE_CODE (olddecl) == FUNCTION_DECL
02061 || (TREE_CODE (olddecl) == VAR_DECL
02062 && TREE_STATIC (olddecl))))
02063 make_decl_rtl (olddecl);
02064
02065
02066
02067
02068 ggc_free (newdecl);
02069
02070 return olddecl;
02071 }
02072
02073
02074
02075
02076
02077
02078
02079 static const char *
02080 redeclaration_error_message (tree newdecl, tree olddecl)
02081 {
02082 if (TREE_CODE (newdecl) == TYPE_DECL)
02083 {
02084
02085
02086
02087 if (same_type_p (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
02088 return NULL;
02089 else
02090 return "redefinition of %q#D";
02091 }
02092 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
02093 {
02094
02095
02096
02097 if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl)
02098 && DECL_INITIAL (olddecl) == NULL_TREE)
02099 return NULL;
02100
02101
02102
02103 if (DECL_NAMESPACE_SCOPE_P (olddecl)
02104 && DECL_CONTEXT (olddecl) != DECL_CONTEXT (newdecl)
02105 && ! decls_match (olddecl, newdecl))
02106 return "%qD conflicts with used function";
02107
02108
02109
02110
02111
02112 if (DECL_INITIAL (olddecl) != NULL_TREE
02113 && DECL_INITIAL (newdecl) != NULL_TREE)
02114 {
02115 if (DECL_NAME (olddecl) == NULL_TREE)
02116 return "%q#D not declared in class";
02117 else
02118 return "redefinition of %q#D";
02119 }
02120 return NULL;
02121 }
02122 else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
02123 {
02124 tree nt, ot;
02125
02126 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
02127 {
02128 if (COMPLETE_TYPE_P (TREE_TYPE (newdecl))
02129 && COMPLETE_TYPE_P (TREE_TYPE (olddecl)))
02130 return "redefinition of %q#D";
02131 return NULL;
02132 }
02133
02134 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != FUNCTION_DECL
02135 || (DECL_TEMPLATE_RESULT (newdecl)
02136 == DECL_TEMPLATE_RESULT (olddecl)))
02137 return NULL;
02138
02139 nt = DECL_TEMPLATE_RESULT (newdecl);
02140 if (DECL_TEMPLATE_INFO (nt))
02141 nt = DECL_TEMPLATE_RESULT (template_for_substitution (nt));
02142 ot = DECL_TEMPLATE_RESULT (olddecl);
02143 if (DECL_TEMPLATE_INFO (ot))
02144 ot = DECL_TEMPLATE_RESULT (template_for_substitution (ot));
02145 if (DECL_INITIAL (nt) && DECL_INITIAL (ot))
02146 return "redefinition of %q#D";
02147
02148 return NULL;
02149 }
02150 else if (TREE_CODE (newdecl) == VAR_DECL
02151 && DECL_THREAD_LOCAL_P (newdecl) != DECL_THREAD_LOCAL_P (olddecl)
02152 && (! DECL_LANG_SPECIFIC (olddecl)
02153 || ! CP_DECL_THREADPRIVATE_P (olddecl)
02154 || DECL_THREAD_LOCAL_P (newdecl)))
02155 {
02156
02157
02158 if (DECL_THREAD_LOCAL_P (newdecl))
02159 return "thread-local declaration of %q#D follows "
02160 "non-thread-local declaration";
02161 else
02162 return "non-thread-local declaration of %q#D follows "
02163 "thread-local declaration";
02164 }
02165 else if (toplevel_bindings_p () || DECL_NAMESPACE_SCOPE_P (newdecl))
02166 {
02167
02168
02169 if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
02170 return NULL;
02171
02172 return "redefinition of %q#D";
02173 }
02174 else
02175 {
02176
02177
02178
02179 if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
02180 return "redeclaration of %q#D";
02181 return NULL;
02182 }
02183 }
02184
02185
02186
02187 static hashval_t
02188 named_label_entry_hash (const void *data)
02189 {
02190 const struct named_label_entry *ent = (const struct named_label_entry *) data;
02191 return DECL_UID (ent->label_decl);
02192 }
02193
02194 static int
02195 named_label_entry_eq (const void *a, const void *b)
02196 {
02197 const struct named_label_entry *ent_a = (const struct named_label_entry *) a;
02198 const struct named_label_entry *ent_b = (const struct named_label_entry *) b;
02199 return ent_a->label_decl == ent_b->label_decl;
02200 }
02201
02202
02203
02204 static tree
02205 make_label_decl (tree id, int local_p)
02206 {
02207 struct named_label_entry *ent;
02208 void **slot;
02209 tree decl;
02210
02211 decl = build_decl (LABEL_DECL, id, void_type_node);
02212
02213 DECL_CONTEXT (decl) = current_function_decl;
02214 DECL_MODE (decl) = VOIDmode;
02215 C_DECLARED_LABEL_FLAG (decl) = local_p;
02216
02217
02218
02219 DECL_SOURCE_LOCATION (decl) = input_location;
02220
02221
02222 SET_IDENTIFIER_LABEL_VALUE (id, decl);
02223
02224
02225 if (!named_labels)
02226 named_labels = htab_create_ggc (13, named_label_entry_hash,
02227 named_label_entry_eq, NULL);
02228
02229
02230
02231
02232 ent = GGC_CNEW (struct named_label_entry);
02233 ent->label_decl = decl;
02234
02235 slot = htab_find_slot (named_labels, ent, INSERT);
02236 gcc_assert (*slot == NULL);
02237 *slot = ent;
02238
02239 return decl;
02240 }
02241
02242
02243
02244
02245
02246 tree
02247 lookup_label (tree id)
02248 {
02249 tree decl;
02250
02251 timevar_push (TV_NAME_LOOKUP);
02252
02253 if (current_function_decl == NULL_TREE)
02254 {
02255 error ("label %qE referenced outside of any function", id);
02256 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
02257 }
02258
02259
02260 decl = IDENTIFIER_LABEL_VALUE (id);
02261 if (decl != NULL_TREE && DECL_CONTEXT (decl) == current_function_decl)
02262 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
02263
02264 decl = make_label_decl (id, 0);
02265 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
02266 }
02267
02268
02269
02270 tree
02271 declare_local_label (tree id)
02272 {
02273 tree decl, shadow;
02274
02275
02276
02277 shadow = tree_cons (IDENTIFIER_LABEL_VALUE (id), NULL_TREE,
02278 current_binding_level->shadowed_labels);
02279 current_binding_level->shadowed_labels = shadow;
02280
02281 decl = make_label_decl (id, 1);
02282 TREE_VALUE (shadow) = decl;
02283
02284 return decl;
02285 }
02286
02287
02288
02289
02290 static int
02291 decl_jump_unsafe (tree decl)
02292 {
02293 if (TREE_CODE (decl) != VAR_DECL || TREE_STATIC (decl)
02294 || TREE_TYPE (decl) == error_mark_node)
02295 return 0;
02296
02297 if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))
02298 || DECL_NONTRIVIALLY_INITIALIZED_P (decl))
02299 return 2;
02300
02301 if (pod_type_p (TREE_TYPE (decl)))
02302 return 0;
02303
02304
02305
02306 return 1;
02307 }
02308
02309
02310
02311 static void
02312 identify_goto (tree decl, const location_t *locus)
02313 {
02314 if (decl)
02315 pedwarn ("jump to label %qD", decl);
02316 else
02317 pedwarn ("jump to case label");
02318 if (locus)
02319 pedwarn ("%H from here", locus);
02320 }
02321
02322
02323
02324
02325
02326
02327
02328 static bool
02329 check_previous_goto_1 (tree decl, struct cp_binding_level* level, tree names,
02330 bool exited_omp, const location_t *locus)
02331 {
02332 struct cp_binding_level *b;
02333 bool identified = false, saw_eh = false, saw_omp = false;
02334
02335 if (exited_omp)
02336 {
02337 identify_goto (decl, locus);
02338 error (" exits OpenMP structured block");
02339 identified = saw_omp = true;
02340 }
02341
02342 for (b = current_binding_level; b ; b = b->level_chain)
02343 {
02344 tree new_decls, old_decls = (b == level ? names : NULL_TREE);
02345
02346 for (new_decls = b->names; new_decls != old_decls;
02347 new_decls = TREE_CHAIN (new_decls))
02348 {
02349 int problem = decl_jump_unsafe (new_decls);
02350 if (! problem)
02351 continue;
02352
02353 if (!identified)
02354 {
02355 identify_goto (decl, locus);
02356 identified = true;
02357 }
02358 if (problem > 1)
02359 error (" crosses initialization of %q+#D", new_decls);
02360 else
02361 pedwarn (" enters scope of non-POD %q+#D", new_decls);
02362 }
02363
02364 if (b == level)
02365 break;
02366 if ((b->kind == sk_try || b->kind == sk_catch) && !saw_eh)
02367 {
02368 if (!identified)
02369 {
02370 identify_goto (decl, locus);
02371 identified = true;
02372 }
02373 if (b->kind == sk_try)
02374 error (" enters try block");
02375 else
02376 error (" enters catch block");
02377 saw_eh = true;
02378 }
02379 if (b->kind == sk_omp && !saw_omp)
02380 {
02381 if (!identified)
02382 {
02383 identify_goto (decl, locus);
02384 identified = true;
02385 }
02386 error (" enters OpenMP structured block");
02387 saw_omp = true;
02388 }
02389 }
02390
02391 return !identified;
02392 }
02393
02394 static void
02395 check_previous_goto (tree decl, struct named_label_use_entry *use)
02396 {
02397 check_previous_goto_1 (decl, use->binding_level,
02398 use->names_in_scope, use->in_omp_scope,
02399 &use->o_goto_locus);
02400 }
02401
02402 static bool
02403 check_switch_goto (struct cp_binding_level* level)
02404 {
02405 return check_previous_goto_1 (NULL_TREE, level, level->names, false, NULL);
02406 }
02407
02408
02409
02410
02411 void
02412 check_goto (tree decl)
02413 {
02414 struct named_label_entry *ent, dummy;
02415 bool saw_catch = false, identified = false;
02416 tree bad;
02417
02418
02419
02420 if (TREE_CODE (decl) != LABEL_DECL)
02421 return;
02422
02423
02424
02425 if (decl == cdtor_label)
02426 return;
02427
02428 dummy.label_decl = decl;
02429 ent = (struct named_label_entry *) htab_find (named_labels, &dummy);
02430 gcc_assert (ent != NULL);
02431
02432
02433 if (! DECL_INITIAL (decl))
02434 {
02435 struct named_label_use_entry *new_use;
02436
02437
02438
02439 if (ent->uses
02440 && ent->uses->names_in_scope == current_binding_level->names)
02441 return;
02442
02443 new_use = GGC_NEW (struct named_label_use_entry);
02444 new_use->binding_level = current_binding_level;
02445 new_use->names_in_scope = current_binding_level->names;
02446 new_use->o_goto_locus = input_location;
02447 new_use->in_omp_scope = false;
02448
02449 new_use->next = ent->uses;
02450 ent->uses = new_use;
02451 return;
02452 }
02453
02454 if (ent->in_try_scope || ent->in_catch_scope
02455 || ent->in_omp_scope || ent->bad_decls)
02456 {
02457 pedwarn ("jump to label %q+D", decl);
02458 pedwarn (" from here");
02459 identified = true;
02460 }
02461
02462 for (bad = ent->bad_decls; bad; bad = TREE_CHAIN (bad))
02463 {
02464 tree b = TREE_VALUE (bad);
02465 int u = decl_jump_unsafe (b);
02466
02467 if (u > 1 && DECL_ARTIFICIAL (b))
02468 {
02469
02470 error ("%J enters catch block", b);
02471 saw_catch = true;
02472 }
02473 else if (u > 1)
02474 error (" skips initialization of %q+#D", b);
02475 else
02476 pedwarn (" enters scope of non-POD %q+#D", b);
02477 }
02478
02479 if (ent->in_try_scope)
02480 error (" enters try block");
02481 else if (ent->in_catch_scope && !saw_catch)
02482 error (" enters catch block");
02483
02484 if (ent->in_omp_scope)
02485 error (" enters OpenMP structured block");
02486 else if (flag_openmp)
02487 {
02488 struct cp_binding_level *b;
02489 for (b = current_binding_level; b ; b = b->level_chain)
02490 {
02491 if (b == ent->binding_level)
02492 break;
02493 if (b->kind == sk_omp)
02494 {
02495 if (!identified)
02496 {
02497 pedwarn ("jump to label %q+D", decl);
02498 pedwarn (" from here");
02499 identified = true;
02500 }
02501 error (" exits OpenMP structured block");
02502 break;
02503 }
02504 }
02505 }
02506 }
02507
02508
02509
02510
02511 bool
02512 check_omp_return (void)
02513 {
02514 struct cp_binding_level *b;
02515 for (b = current_binding_level; b ; b = b->level_chain)
02516 if (b->kind == sk_omp)
02517 {
02518 error ("invalid exit from OpenMP structured block");
02519 return false;
02520 }
02521 return true;
02522 }
02523
02524
02525
02526
02527 tree
02528 define_label (location_t location, tree name)
02529 {
02530 struct named_label_entry *ent, dummy;
02531 struct cp_binding_level *p;
02532 tree decl;
02533
02534 timevar_push (TV_NAME_LOOKUP);
02535
02536 decl = lookup_label (name);
02537
02538 dummy.label_decl = decl;
02539 ent = (struct named_label_entry *) htab_find (named_labels, &dummy);
02540 gcc_assert (ent != NULL);
02541
02542
02543
02544 for (p = current_binding_level;
02545 p->kind != sk_function_parms;
02546 p = p->level_chain)
02547 p->more_cleanups_ok = 0;
02548
02549 if (name == get_identifier ("wchar_t"))
02550 pedwarn ("label named wchar_t");
02551
02552 if (DECL_INITIAL (decl) != NULL_TREE)
02553 {
02554 error ("duplicate label %qD", decl);
02555 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
02556 }
02557 else
02558 {
02559 struct named_label_use_entry *use;
02560
02561
02562 DECL_INITIAL (decl) = error_mark_node;
02563
02564 DECL_SOURCE_LOCATION (decl) = location;
02565
02566 ent->binding_level = current_binding_level;
02567 ent->names_in_scope = current_binding_level->names;
02568
02569 for (use = ent->uses; use ; use = use->next)
02570 check_previous_goto (decl, use);
02571 ent->uses = NULL;
02572 }
02573
02574 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
02575 }
02576
02577 struct cp_switch
02578 {
02579 struct cp_binding_level *level;
02580 struct cp_switch *next;
02581
02582 tree switch_stmt;
02583
02584
02585
02586
02587
02588 splay_tree cases;
02589 };
02590
02591
02592
02593
02594
02595
02596
02597 static struct cp_switch *switch_stack;
02598
02599
02600
02601
02602 void
02603 push_switch (tree switch_stmt)
02604 {
02605 struct cp_switch *p = XNEW (struct cp_switch);
02606 p->level = current_binding_level;
02607 p->next = switch_stack;
02608 p->switch_stmt = switch_stmt;
02609 p->cases = splay_tree_new (case_compare, NULL, NULL);
02610 switch_stack = p;
02611 }
02612
02613 void
02614 pop_switch (void)
02615 {
02616 struct cp_switch *cs = switch_stack;
02617 location_t switch_location;
02618
02619
02620 if (EXPR_HAS_LOCATION (cs->switch_stmt))
02621 switch_location = EXPR_LOCATION (cs->switch_stmt);
02622 else
02623 switch_location = input_location;
02624 if (!processing_template_decl)
02625 c_do_switch_warnings (cs->cases, switch_location,
02626 SWITCH_STMT_TYPE (cs->switch_stmt),
02627 SWITCH_STMT_COND (cs->switch_stmt));
02628
02629 splay_tree_delete (cs->cases);
02630 switch_stack = switch_stack->next;
02631 free (cs);
02632 }
02633
02634
02635
02636
02637 tree
02638 finish_case_label (tree low_value, tree high_value)
02639 {
02640 tree cond, r;
02641 struct cp_binding_level *p;
02642
02643 if (processing_template_decl)
02644 {
02645 tree label;
02646
02647
02648
02649 label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
02650 return add_stmt (build_case_label (low_value, high_value, label));
02651 }
02652
02653
02654 cond = SWITCH_STMT_COND (switch_stack->switch_stmt);
02655 if (cond && TREE_CODE (cond) == TREE_LIST)
02656 cond = TREE_VALUE (cond);
02657
02658 if (!check_switch_goto (switch_stack->level))
02659 return error_mark_node;
02660
02661 r = c_add_case_label (switch_stack->cases, cond, TREE_TYPE (cond),
02662 low_value, high_value);
02663
02664
02665
02666 for (p = current_binding_level;
02667 p->kind != sk_function_parms;
02668 p = p->level_chain)
02669 p->more_cleanups_ok = 0;
02670
02671 return r;
02672 }
02673
02674
02675
02676 static hashval_t
02677 typename_hash (const void* k)
02678 {
02679 hashval_t hash;
02680 tree t = (tree) k;
02681
02682 hash = (htab_hash_pointer (TYPE_CONTEXT (t))
02683 ^ htab_hash_pointer (DECL_NAME (TYPE_NAME (t))));
02684
02685 return hash;
02686 }
02687
02688 typedef struct typename_info {
02689 tree scope;
02690 tree name;
02691 tree template_id;
02692 bool enum_p;
02693 bool class_p;
02694 } typename_info;
02695
02696
02697
02698 static int
02699 typename_compare (const void * k1, const void * k2)
02700 {
02701 tree t1;
02702 const typename_info *t2;
02703
02704 t1 = (tree) k1;
02705 t2 = (const typename_info *) k2;
02706
02707 return (DECL_NAME (TYPE_NAME (t1)) == t2->name
02708 && TYPE_CONTEXT (t1) == t2->scope
02709 && TYPENAME_TYPE_FULLNAME (t1) == t2->template_id
02710 && TYPENAME_IS_ENUM_P (t1) == t2->enum_p
02711 && TYPENAME_IS_CLASS_P (t1) == t2->class_p);
02712 }
02713
02714
02715
02716
02717
02718
02719 static GTY ((param_is (union tree_node))) htab_t typename_htab;
02720
02721 static tree
02722 build_typename_type (tree context, tree name, tree fullname,
02723 enum tag_types tag_type)
02724 {
02725 tree t;
02726 tree d;
02727 typename_info ti;
02728 void **e;
02729 hashval_t hash;
02730
02731 if (typename_htab == NULL)
02732 typename_htab = htab_create_ggc (61, &typename_hash,
02733 &typename_compare, NULL);
02734
02735 ti.scope = FROB_CONTEXT (context);
02736 ti.name = name;
02737 ti.template_id = fullname;
02738 ti.enum_p = tag_type == enum_type;
02739 ti.class_p = (tag_type == class_type
02740 || tag_type == record_type
02741 || tag_type == union_type);
02742 hash = (htab_hash_pointer (ti.scope)
02743 ^ htab_hash_pointer (ti.name));
02744
02745
02746 e = htab_find_slot_with_hash (typename_htab, &ti, hash, INSERT);
02747 if (*e)
02748 t = (tree) *e;
02749 else
02750 {
02751
02752 t = make_aggr_type (TYPENAME_TYPE);
02753 TYPE_CONTEXT (t) = ti.scope;
02754 TYPENAME_TYPE_FULLNAME (t) = ti.template_id;
02755 TYPENAME_IS_ENUM_P (t) = ti.enum_p;
02756 TYPENAME_IS_CLASS_P (t) = ti.class_p;
02757
02758
02759 d = build_decl (TYPE_DECL, name, t);
02760 TYPE_NAME (TREE_TYPE (d)) = d;
02761 TYPE_STUB_DECL (TREE_TYPE (d)) = d;
02762 DECL_CONTEXT (d) = FROB_CONTEXT (context);
02763 DECL_ARTIFICIAL (d) = 1;
02764
02765
02766 *e = t;
02767 }
02768
02769 return t;
02770 }
02771
02772
02773
02774
02775
02776
02777
02778
02779
02780 tree
02781 make_typename_type (tree context, tree name, enum tag_types tag_type,
02782 tsubst_flags_t complain)
02783 {
02784 tree fullname;
02785 tree t;
02786 bool want_template;
02787
02788 if (name == error_mark_node
02789 || context == NULL_TREE
02790 || context == error_mark_node)
02791 return error_mark_node;
02792
02793 if (TYPE_P (name))
02794 {
02795 if (!(TYPE_LANG_SPECIFIC (name)
02796 && (CLASSTYPE_IS_TEMPLATE (name)
02797 || CLASSTYPE_USE_TEMPLATE (name))))
02798 name = TYPE_IDENTIFIER (name);
02799 else
02800
02801 name = build_nt (TEMPLATE_ID_EXPR,
02802 CLASSTYPE_TI_TEMPLATE (name),
02803 CLASSTYPE_TI_ARGS (name));
02804 }
02805 else if (TREE_CODE (name) == TYPE_DECL)
02806 name = DECL_NAME (name);
02807
02808 fullname = name;
02809
02810 if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
02811 {
02812 name = TREE_OPERAND (name, 0);
02813 if (TREE_CODE (name) == TEMPLATE_DECL)
02814 name = TREE_OPERAND (fullname, 0) = DECL_NAME (name);
02815 else if (TREE_CODE (name) == OVERLOAD)
02816 {
02817 error ("%qD is not a type", name);
02818 return error_mark_node;
02819 }
02820 }
02821 if (TREE_CODE (name) == TEMPLATE_DECL)
02822 {
02823 error ("%qD used without template parameters", name);
02824 return error_mark_node;
02825 }
02826 gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
02827 gcc_assert (TYPE_P (context));
02828
02829
02830
02831
02832 if (dependent_type_p (context))
02833 return build_typename_type (context, name, fullname, tag_type);
02834
02835 if (!IS_AGGR_TYPE (context))
02836 {
02837 if (complain & tf_error)
02838 error ("%q#T is not a class", context);
02839 return error_mark_node;
02840 }
02841
02842 want_template = TREE_CODE (fullname) == TEMPLATE_ID_EXPR;
02843
02844
02845
02846 t = lookup_field (context, name, 0, true);
02847 if (!t)
02848 {
02849 if (complain & tf_error)
02850 error (want_template ? "no class template named %q#T in %q#T"
02851 : "no type named %q#T in %q#T", name, context);
02852 return error_mark_node;
02853 }
02854
02855 if (want_template && !DECL_CLASS_TEMPLATE_P (t))
02856 {
02857 if (complain & tf_error)
02858 error ("%<typename %T::%D%> names %q#T, which is not a class template",
02859 context, name, t);
02860 return error_mark_node;
02861 }
02862 if (!want_template && TREE_CODE (t) != TYPE_DECL)
02863 {
02864 if (complain & tf_error)
02865 error ("%<typename %T::%D%> names %q#T, which is not a type",
02866 context, name, t);
02867 return error_mark_node;
02868 }
02869
02870 if (complain & tf_error)
02871 perform_or_defer_access_check (TYPE_BINFO (context), t, t);
02872
02873 if (want_template)
02874 return lookup_template_class (t, TREE_OPERAND (fullname, 1),
02875 NULL_TREE, context,
02876 0,
02877 tf_warning_or_error | tf_user);
02878
02879 if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
02880 t = TREE_TYPE (t);
02881
02882 return t;
02883 }
02884
02885
02886
02887
02888
02889
02890
02891
02892
02893
02894 tree
02895 make_unbound_class_template (tree context, tree name, tree parm_list,
02896 tsubst_flags_t complain)
02897 {
02898 tree t;
02899 tree d;
02900
02901 if (TYPE_P (name))
02902 name = TYPE_IDENTIFIER (name);
02903 else if (DECL_P (name))
02904 name = DECL_NAME (name);
02905 gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
02906
02907 if (!dependent_type_p (context)
02908 || currently_open_class (context))
02909 {
02910 tree tmpl = NULL_TREE;
02911
02912 if (IS_AGGR_TYPE (context))
02913 tmpl = lookup_field (context, name, 0, false);
02914
02915 if (!tmpl || !DECL_CLASS_TEMPLATE_P (tmpl))
02916 {
02917 if (complain & tf_error)
02918 error ("no class template named %q#T in %q#T", name, context);
02919 return error_mark_node;
02920 }
02921
02922 if (parm_list
02923 && !comp_template_parms (DECL_TEMPLATE_PARMS (tmpl), parm_list))
02924 {
02925 if (complain & tf_error)
02926 {
02927 error ("template parameters do not match template");
02928 error ("%q+D declared here", tmpl);
02929 }
02930 return error_mark_node;
02931 }
02932
02933 if (complain & tf_error)
02934 perform_or_defer_access_check (TYPE_BINFO (context), tmpl, tmpl);
02935
02936 return tmpl;
02937 }
02938
02939
02940 t = make_aggr_type (UNBOUND_CLASS_TEMPLATE);
02941 TYPE_CONTEXT (t) = FROB_CONTEXT (context);
02942 TREE_TYPE (t) = NULL_TREE;
02943
02944
02945 d = build_decl (TEMPLATE_DECL, name, t);
02946 TYPE_NAME (TREE_TYPE (d)) = d;
02947 TYPE_STUB_DECL (TREE_TYPE (d)) = d;
02948 DECL_CONTEXT (d) = FROB_CONTEXT (context);
02949 DECL_ARTIFICIAL (d) = 1;
02950 DECL_TEMPLATE_PARMS (d) = parm_list;
02951
02952 return t;
02953 }
02954
02955
02956
02957
02958
02959
02960
02961
02962 void
02963 record_builtin_type (enum rid rid_index,
02964 const char* name,
02965 tree type)
02966 {
02967 tree rname = NULL_TREE, tname = NULL_TREE;
02968 tree tdecl = NULL_TREE;
02969
02970 if ((int) rid_index < (int) RID_MAX)
02971 rname = ridpointers[(int) rid_index];
02972 if (name)
02973 tname = get_identifier (name);
02974
02975
02976
02977
02978
02979
02980 if (tname)
02981 {
02982 tdecl = build_decl (TYPE_DECL, tname, type);
02983 DECL_ARTIFICIAL (tdecl) = 1;
02984 SET_IDENTIFIER_GLOBAL_VALUE (tname, tdecl);
02985 }
02986 if (rname)
02987 {
02988 if (!tdecl)
02989 {
02990 tdecl = build_decl (TYPE_DECL, rname, type);
02991 DECL_ARTIFICIAL (tdecl) = 1;
02992 }
02993 SET_IDENTIFIER_GLOBAL_VALUE (rname, tdecl);
02994 }
02995
02996 if (!TYPE_NAME (type))
02997 TYPE_NAME (type) = tdecl;
02998
02999 if (tdecl)
03000 debug_hooks->type_decl (tdecl, 0);
03001 }
03002
03003
03004
03005
03006
03007
03008 static tree
03009 record_builtin_java_type (const char* name, int size)
03010 {
03011 tree type, decl;
03012 if (size > 0)
03013 type = make_signed_type (size);
03014 else if (size > -32)
03015 {
03016 type = make_unsigned_type (-size);
03017
03018 }
03019 else
03020 {
03021 type = make_node (REAL_TYPE);
03022 TYPE_PRECISION (type) = - size;
03023 layout_type (type);
03024 }
03025 record_builtin_type (RID_MAX, name, type);
03026 decl = TYPE_NAME (type);
03027
03028
03029
03030
03031 DECL_IGNORED_P (decl) = 1;
03032
03033 TYPE_FOR_JAVA (type) = 1;
03034 return type;
03035 }
03036
03037
03038
03039 static void
03040 record_unknown_type (tree type, const char* name)
03041 {
03042 tree decl = pushdecl (build_decl (TYPE_DECL, get_identifier (name), type));
03043
03044 DECL_IGNORED_P (decl) = 1;
03045 TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
03046 TYPE_SIZE (type) = TYPE_SIZE (void_type_node);
03047 TYPE_ALIGN (type) = 1;
03048 TYPE_USER_ALIGN (type) = 0;
03049 TYPE_MODE (type) = TYPE_MODE (void_type_node);
03050 }
03051
03052
03053
03054
03055 typedef struct predefined_identifier
03056 {
03057
03058 const char *const name;
03059
03060 tree *const node;
03061
03062 const int ctor_or_dtor_p;
03063 } predefined_identifier;
03064
03065
03066
03067 static void
03068 initialize_predefined_identifiers (void)
03069 {
03070 const predefined_identifier *pid;
03071
03072
03073 static const predefined_identifier predefined_identifiers[] = {
03074 { "C++", &lang_name_cplusplus, 0 },
03075 { "C", &lang_name_c, 0 },
03076 { "Java", &lang_name_java, 0 },
03077
03078
03079 { "__ct ", &ctor_identifier, 1 },
03080 { "__base_ctor ", &base_ctor_identifier, 1 },
03081 { "__comp_ctor ", &complete_ctor_identifier, 1 },
03082 { "__dt ", &dtor_identifier, 1 },
03083 { "__comp_dtor ", &complete_dtor_identifier, 1 },
03084 { "__base_dtor ", &base_dtor_identifier, 1 },
03085 { "__deleting_dtor ", &deleting_dtor_identifier, 1 },
03086 { IN_CHARGE_NAME, &in_charge_identifier, 0 },
03087 { "nelts", &nelts_identifier, 0 },
03088 { THIS_NAME, &this_identifier, 0 },
03089 { VTABLE_DELTA_NAME, &delta_identifier, 0 },
03090 { VTABLE_PFN_NAME, &pfn_identifier, 0 },
03091 { "_vptr", &vptr_identifier, 0 },
03092 { "__vtt_parm", &vtt_parm_identifier, 0 },
03093 { "::", &global_scope_name, 0 },
03094 { "std", &std_identifier, 0 },
03095 { NULL, NULL, 0 }
03096 };
03097
03098 for (pid = predefined_identifiers; pid->name; ++pid)
03099 {
03100 *pid->node = get_identifier (pid->name);
03101 if (pid->ctor_or_dtor_p)
03102 IDENTIFIER_CTOR_OR_DTOR_P (*pid->node) = 1;
03103 }
03104 }
03105
03106
03107
03108
03109
03110
03111 void
03112 cxx_init_decl_processing (void)
03113 {
03114 tree void_ftype;
03115 tree void_ftype_ptr;
03116
03117 build_common_tree_nodes (flag_signed_char, false);
03118
03119
03120 initialize_predefined_identifiers ();
03121
03122
03123 push_to_top_level ();
03124
03125 current_function_decl = NULL_TREE;
03126 current_binding_level = NULL;
03127
03128 gcc_assert (global_namespace == NULL_TREE);
03129 global_namespace = build_lang_decl (NAMESPACE_DECL, global_scope_name,
03130 void_type_node);
03131 TREE_PUBLIC (global_namespace) = 1;
03132 begin_scope (sk_namespace, global_namespace);
03133
03134 current_lang_name = NULL_TREE;
03135
03136
03137 if (!flag_permissive)
03138 flag_pedantic_errors = 1;
03139 if (!flag_no_inline)
03140 {
03141 flag_inline_trees = 1;
03142 flag_no_inline = 1;
03143 }
03144 if (flag_inline_functions)
03145 flag_inline_trees = 2;
03146
03147
03148
03149 if (TARGET_PTRMEMFUNC_VBIT_LOCATION == ptrmemfunc_vbit_in_pfn
03150 && force_align_functions_log < 1)
03151 force_align_functions_log = 1;
03152
03153
03154 current_lang_name = lang_name_c;
03155
03156
03157 push_namespace (std_identifier);
03158 std_node = current_namespace;
03159 pop_namespace ();
03160
03161 c_common_nodes_and_builtins ();
03162
03163 java_byte_type_node = record_builtin_java_type ("__java_byte", 8);
03164 java_short_type_node = record_builtin_java_type ("__java_short", 16);
03165 java_int_type_node = record_builtin_java_type ("__java_int", 32);
03166 java_long_type_node = record_builtin_java_type ("__java_long", 64);
03167 java_float_type_node = record_builtin_java_type ("__java_float", -32);
03168 java_double_type_node = record_builtin_java_type ("__java_double", -64);
03169 java_char_type_node = record_builtin_java_type ("__java_char", -16);
03170 java_boolean_type_node = record_builtin_java_type ("__java_boolean", -1);
03171
03172 integer_two_node = build_int_cst (NULL_TREE, 2);
03173 integer_three_node = build_int_cst (NULL_TREE, 3);
03174
03175 record_builtin_type (RID_BOOL, "bool", boolean_type_node);
03176 truthvalue_type_node = boolean_type_node;
03177 truthvalue_false_node = boolean_false_node;
03178 truthvalue_true_node = boolean_true_node;
03179
03180 empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE);
03181
03182 #if 0
03183 record_builtin_type (RID_MAX, NULL, string_type_node);
03184 #endif
03185
03186 delta_type_node = ptrdiff_type_node;
03187 vtable_index_type = ptrdiff_type_node;
03188
03189 vtt_parm_type = build_pointer_type (const_ptr_type_node);
03190 void_ftype = build_function_type (void_type_node, void_list_node);
03191 void_ftype_ptr = build_function_type (void_type_node,
03192 tree_cons (NULL_TREE,
03193 ptr_type_node,
03194 void_list_node));
03195 void_ftype_ptr
03196 = build_exception_variant (void_ftype_ptr, empty_except_spec);
03197
03198
03199
03200 unknown_type_node = make_node (UNKNOWN_TYPE);
03201 record_unknown_type (unknown_type_node, "unknown type");
03202
03203
03204 TREE_TYPE (unknown_type_node) = unknown_type_node;
03205
03206
03207
03208 TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
03209 TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
03210
03211 {
03212
03213
03214 tree vfunc_type = make_node (FUNCTION_TYPE);
03215 TREE_TYPE (vfunc_type) = integer_type_node;
03216 TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
03217 layout_type (vfunc_type);
03218
03219 vtable_entry_type = build_pointer_type (vfunc_type);
03220 }
03221 record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type);
03222
03223 vtbl_type_node
03224 = build_cplus_array_type (vtable_entry_type, NULL_TREE);
03225 layout_type (vtbl_type_node);
03226 vtbl_type_node = build_qualified_type (vtbl_type_node, TYPE_QUAL_CONST);
03227 record_builtin_type (RID_MAX, NULL, vtbl_type_node);
03228 vtbl_ptr_type_node = build_pointer_type (vtable_entry_type);
03229 layout_type (vtbl_ptr_type_node);
03230 record_builtin_type (RID_MAX, NULL, vtbl_ptr_type_node);
03231
03232 push_namespace (get_identifier ("__cxxabiv1"));
03233 abi_node = current_namespace;
03234 pop_namespace ();
03235
03236 global_type_node = make_node (LANG_TYPE);
03237 record_unknown_type (global_type_node, "global type");
03238
03239
03240 current_lang_name = lang_name_cplusplus;
03241
03242 {
03243 tree bad_alloc_id;
03244 tree bad_alloc_type_node;
03245 tree bad_alloc_decl;
03246 tree newtype, deltype;
03247 tree ptr_ftype_sizetype;
03248
03249 push_namespace (std_identifier);
03250 bad_alloc_id = get_identifier ("bad_alloc");
03251 bad_alloc_type_node = make_aggr_type (RECORD_TYPE);
03252 TYPE_CONTEXT (bad_alloc_type_node) = current_namespace;
03253 bad_alloc_decl
03254 = create_implicit_typedef (bad_alloc_id, bad_alloc_type_node);
03255 DECL_CONTEXT (bad_alloc_decl) = current_namespace;
03256 TYPE_STUB_DECL (bad_alloc_type_node) = bad_alloc_decl;
03257 pop_namespace ();
03258
03259 ptr_ftype_sizetype
03260 = build_function_type (ptr_type_node,
03261 tree_cons (NULL_TREE,
03262 size_type_node,
03263 void_list_node));
03264 newtype = build_exception_variant
03265 (ptr_ftype_sizetype, add_exception_specifier
03266 (NULL_TREE, bad_alloc_type_node, -1));
03267 deltype = build_exception_variant (void_ftype_ptr, empty_except_spec);
03268 push_cp_library_fn (NEW_EXPR, newtype);
03269 push_cp_library_fn (VEC_NEW_EXPR, newtype);
03270 global_delete_fndecl = push_cp_library_fn (DELETE_EXPR, deltype);
03271 push_cp_library_fn (VEC_DELETE_EXPR, deltype);
03272 }
03273
03274 abort_fndecl
03275 = build_library_fn_ptr ("__cxa_pure_virtual", void_ftype);
03276
03277
03278 init_class_processing ();
03279 init_rtti_processing ();
03280
03281 if (flag_exceptions)
03282 init_exception_processing ();
03283
03284 if (! supports_one_only ())
03285 flag_weak = 0;
03286
03287 make_fname_decl = cp_make_fname_decl;
03288 start_fname_decls ();
03289
03290
03291 if (flag_exceptions)
03292 using_eh_for_cleanups ();
03293 }
03294
03295
03296
03297
03298
03299 tree
03300 cp_fname_init (const char* name, tree *type_p)
03301 {
03302 tree domain = NULL_TREE;
03303 tree type;
03304 tree init = NULL_TREE;
03305 size_t length = 0;
03306
03307 if (name)
03308 {
03309 length = strlen (name);
03310 domain = build_index_type (size_int (length));
03311 init = build_string (length + 1, name);
03312 }
03313
03314 type = build_qualified_type (char_type_node, TYPE_QUAL_CONST);
03315 type = build_cplus_array_type (type, domain);
03316
03317 *type_p = type;
03318
03319 if (init)
03320 TREE_TYPE (init) = type;
03321 else
03322 init = error_mark_node;
03323
03324 return init;
03325 }
03326
03327
03328
03329
03330
03331
03332
03333 static tree
03334 cp_make_fname_decl (tree id, int type_dep)
03335 {
03336 const char *const name = (type_dep && processing_template_decl
03337 ? NULL : fname_as_string (type_dep));
03338 tree type;
03339 tree init = cp_fname_init (name, &type);
03340 tree decl = build_decl (VAR_DECL, id, type);
03341
03342 if (name)
03343 free ((char *) name);
03344
03345
03346 DECL_CONTEXT (decl) = current_function_decl;
03347 DECL_PRETTY_FUNCTION_P (decl) = type_dep;
03348
03349 TREE_STATIC (decl) = 1;
03350 TREE_READONLY (decl) = 1;
03351 DECL_ARTIFICIAL (decl) = 1;
03352
03353 TREE_USED (decl) = 1;
03354
03355 if (current_function_decl)
03356 {
03357 struct cp_binding_level *b = current_binding_level;
03358 while (b->level_chain->kind != sk_function_parms)
03359 b = b->level_chain;
03360 pushdecl_with_scope (decl, b, false);
03361 cp_finish_decl (decl, init, false, NULL_TREE,
03362 LOOKUP_ONLYCONVERTING);
03363 }
03364 else
03365 pushdecl_top_level_and_finish (decl, init);
03366
03367 return decl;
03368 }
03369
03370
03371
03372
03373
03374
03375
03376
03377
03378
03379
03380
03381
03382 static tree
03383 builtin_function_1 (const char* name,
03384 tree type,
03385 tree context,
03386 enum built_in_function code,
03387 enum built_in_class class,
03388 const char* libname,
03389 tree attrs)
03390 {
03391 tree decl = build_library_fn_1 (get_identifier (name), ERROR_MARK, type);
03392 DECL_BUILT_IN_CLASS (decl) = class;
03393 DECL_FUNCTION_CODE (decl) = code;
03394 DECL_CONTEXT (decl) = context;
03395
03396 pushdecl (decl);
03397
03398
03399
03400
03401 if (libname)
03402 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (libname));
03403
03404
03405
03406
03407 if (name[0] != '_' || name[1] != '_')
03408 DECL_ANTICIPATED (decl) = 1;
03409
03410
03411 if (attrs)
03412 decl_attributes (&decl, attrs, ATTR_FLAG_BUILT_IN);
03413 else
03414 decl_attributes (&decl, NULL_TREE, 0);
03415
03416 return decl;
03417 }
03418
03419
03420
03421
03422
03423
03424
03425
03426
03427
03428
03429
03430
03431
03432
03433
03434
03435 tree
03436 builtin_function (const char* name,
03437 tree type,
03438 int code,
03439 enum built_in_class cl,
03440 const char* libname,
03441 tree attrs)
03442 {
03443
03444
03445 if (name[0] != '_')
03446 {
03447 push_namespace (std_identifier);
03448 builtin_function_1 (name, type, std_node, code, cl, libname, attrs);
03449 pop_namespace ();
03450 }
03451
03452 return builtin_function_1 (name, type, NULL_TREE, code,
03453 cl, libname, attrs);
03454 }
03455
03456
03457
03458
03459 static tree
03460 build_library_fn_1 (tree name, enum tree_code operator_code, tree type)
03461 {
03462 tree fn = build_lang_decl (FUNCTION_DECL, name, type);
03463 DECL_EXTERNAL (fn) = 1;
03464 TREE_PUBLIC (fn) = 1;
03465 DECL_ARTIFICIAL (fn) = 1;
03466 SET_OVERLOADED_OPERATOR_CODE (fn, operator_code);
03467 SET_DECL_LANGUAGE (fn, lang_c);
03468
03469
03470 DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
03471 DECL_VISIBILITY_SPECIFIED (fn) = 1;
03472 return fn;
03473 }
03474
03475
03476
03477
03478
03479 tree
03480 build_library_fn (tree name, tree type)
03481 {
03482 tree fn = build_library_fn_1 (name, ERROR_MARK, type);
03483 TREE_NOTHROW (fn) = 1;
03484 return fn;
03485 }
03486
03487
03488
03489 static tree
03490 build_cp_library_fn (tree name, enum tree_code operator_code, tree type)
03491 {
03492 tree fn = build_library_fn_1 (name, operator_code, type);
03493 TREE_NOTHROW (fn) = TYPE_NOTHROW_P (type);
03494 DECL_CONTEXT (fn) = FROB_CONTEXT (current_namespace);
03495 SET_DECL_LANGUAGE (fn, lang_cplusplus);
03496 return fn;
03497 }
03498
03499
03500
03501
03502 tree
03503 build_library_fn_ptr (const char* name, tree type)
03504 {
03505 return build_library_fn (get_identifier (name), type);
03506 }
03507
03508
03509
03510
03511 tree
03512 build_cp_library_fn_ptr (const char* name, tree type)
03513 {
03514 return build_cp_library_fn (get_identifier (name), ERROR_MARK, type);
03515 }
03516
03517
03518
03519
03520 tree
03521 push_library_fn (tree name, tree type)
03522 {
03523 tree fn = build_library_fn (name, type);
03524 pushdecl_top_level (fn);
03525 return fn;
03526 }
03527
03528
03529
03530
03531 static tree
03532 push_cp_library_fn (enum tree_code operator_code, tree type)
03533 {
03534 tree fn = build_cp_library_fn (ansi_opname (operator_code),
03535 operator_code,
03536 type);
03537 pushdecl (fn);
03538 return fn;
03539 }
03540
03541
03542
03543
03544 tree
03545 push_void_library_fn (tree name, tree parmtypes)
03546 {
03547 tree type = build_function_type (void_type_node, parmtypes);
03548 return push_library_fn (name, type);
03549 }
03550
03551
03552
03553
03554 tree
03555 push_throw_library_fn (tree name, tree type)
03556 {
03557 tree fn = push_library_fn (name, type);
03558 TREE_THIS_VOLATILE (fn) = 1;
03559 TREE_NOTHROW (fn) = 0;
03560 return fn;
03561 }
03562
03563
03564
03565
03566
03567
03568
03569
03570
03571
03572
03573 void
03574 fixup_anonymous_aggr (tree t)
03575 {
03576 tree *q;
03577
03578
03579 TYPE_HAS_CONSTRUCTOR (t) = 0;
03580 TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
03581 TYPE_HAS_INIT_REF (t) = 0;
03582 TYPE_HAS_CONST_INIT_REF (t) = 0;
03583 TYPE_HAS_ASSIGN_REF (t) = 0;
03584 TYPE_HAS_CONST_ASSIGN_REF (t) = 0;
03585
03586
03587
03588 q = &TYPE_METHODS (t);
03589 while (*q)
03590 {
03591 if (DECL_ARTIFICIAL (*q))
03592 *q = TREE_CHAIN (*q);
03593 else
03594 q = &TREE_CHAIN (*q);
03595 }
03596
03597
03598 if (TYPE_METHODS (t))
03599 error ("%Jan anonymous union cannot have function members",
03600 TYPE_MAIN_DECL (t));
03601
03602
03603
03604
03605
03606 if (TREE_CODE (t) != UNION_TYPE)
03607 {
03608 tree field, type;
03609
03610 for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
03611 if (TREE_CODE (field) == FIELD_DECL)
03612 {
03613 type = TREE_TYPE (field);
03614 if (CLASS_TYPE_P (type))
03615 {
03616 if (TYPE_NEEDS_CONSTRUCTING (type))
03617 error ("member %q+#D with constructor not allowed "
03618 "in anonymous aggregate", field);
03619 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
03620 error ("member %q+#D with destructor not allowed "
03621 "in anonymous aggregate", field);
03622 if (TYPE_HAS_COMPLEX_ASSIGN_REF (type))
03623 error ("member %q+#D with copy assignment operator "
03624 "not allowed in anonymous aggregate", field);
03625 }
03626 }
03627 }
03628 }
03629
03630
03631
03632
03633
03634
03635 tree
03636 check_tag_decl (cp_decl_specifier_seq *declspecs)
03637 {
03638 int saw_friend = declspecs->specs[(int)ds_friend] != 0;
03639 int saw_typedef = declspecs->specs[(int)ds_typedef] != 0;
03640
03641
03642
03643
03644 tree declared_type = NULL_TREE;
03645 bool error_p = false;
03646
03647 if (declspecs->multiple_types_p)
03648 error ("multiple types in one declaration");
03649 else if (declspecs->redefined_builtin_type)
03650 {
03651 if (!in_system_header)
03652 pedwarn ("redeclaration of C++ built-in type %qT",
03653 declspecs->redefined_builtin_type);
03654 return NULL_TREE;
03655 }
03656
03657 if (declspecs->type
03658 && TYPE_P (declspecs->type)
03659 && ((TREE_CODE (declspecs->type) != TYPENAME_TYPE
03660 && IS_AGGR_TYPE (declspecs->type))
03661 || TREE_CODE (declspecs->type) == ENUMERAL_TYPE))
03662 declared_type = declspecs->type;
03663 else if (declspecs->type == error_mark_node)
03664 error_p = true;
03665 if (declared_type == NULL_TREE && ! saw_friend && !error_p)
03666 pedwarn ("declaration does not declare anything");
03667
03668 else if (declared_type && IS_AGGR_TYPE_CODE (TREE_CODE (declared_type))
03669 && TYPE_ANONYMOUS_P (declared_type))
03670 {
03671
03672
03673
03674
03675
03676
03677
03678
03679
03680
03681
03682
03683
03684
03685
03686
03687 if (saw_typedef)
03688 {
03689 error ("missing type-name in typedef-declaration");
03690 return NULL_TREE;
03691 }
03692 ;
03693 SET_ANON_AGGR_TYPE_P (declared_type);
03694
03695 if (TREE_CODE (declared_type) != UNION_TYPE && pedantic
03696 && !in_system_header)
03697 pedwarn ("ISO C++ prohibits anonymous structs");
03698 }
03699
03700 else
03701 {
03702 if (declspecs->specs[(int)ds_inline]
03703 || declspecs->specs[(int)ds_virtual])
03704 error ("%qs can only be specified for functions",
03705 declspecs->specs[(int)ds_inline]
03706 ? "inline" : "virtual");
03707 else if (saw_friend
03708 && (!current_class_type
03709 || current_scope () != current_class_type))
03710 error ("%<friend%> can only be specified inside a class");
03711 else if (declspecs->specs[(int)ds_explicit])
03712 error ("%<explicit%> can only be specified for constructors");
03713 else if (declspecs->storage_class)
03714 error ("a storage class can only be specified for objects "
03715 "and functions");
03716 else if (declspecs->specs[(int)ds_const]
03717 || declspecs->specs[(int)ds_volatile]
03718 || declspecs->specs[(int)ds_restrict]
03719 || declspecs->specs[(int)ds_thread])
03720 error ("qualifiers can only be specified for objects "
03721 "and functions");
03722 }
03723
03724 return declared_type;
03725 }
03726
03727
03728
03729
03730
03731
03732
03733
03734
03735
03736
03737
03738
03739
03740 tree
03741 shadow_tag (cp_decl_specifier_seq *declspecs)
03742 {
03743 tree t = check_tag_decl (declspecs);
03744
03745 if (!t)
03746 return NULL_TREE;
03747
03748 if (declspecs->attributes)
03749 {
03750 warning (0, "attribute ignored in declaration of %q+#T", t);
03751 warning (0, "attribute for %q+#T must follow the %qs keyword",
03752 t, class_key_or_enum_as_string (t));
03753
03754 }
03755
03756 if (maybe_process_partial_specialization (t) == error_mark_node)
03757 return NULL_TREE;
03758
03759
03760
03761
03762
03763
03764 if (ANON_AGGR_TYPE_P (t))
03765 {
03766 fixup_anonymous_aggr (t);
03767
03768 if (TYPE_FIELDS (t))
03769 {
03770 tree decl = grokdeclarator (NULL,
03771 declspecs, NORMAL, 0, NULL);
03772 finish_anon_union (decl);
03773 }
03774 }
03775
03776 return t;
03777 }
03778
03779
03780
03781 tree
03782 groktypename (cp_decl_specifier_seq *type_specifiers,
03783 const cp_declarator *declarator)
03784 {
03785 tree attrs;
03786 tree type;
03787 attrs = type_specifiers->attributes;
03788 type_specifiers->attributes = NULL_TREE;
03789 type = grokdeclarator (declarator, type_specifiers, TYPENAME, 0, &attrs);
03790 if (attrs)
03791 cplus_decl_attributes (&type, attrs, 0);
03792 return type;
03793 }
03794
03795
03796
03797
03798
03799
03800
03801
03802
03803
03804
03805
03806
03807
03808
03809
03810 tree
03811 start_decl (const cp_declarator *declarator,
03812 cp_decl_specifier_seq *declspecs,
03813 int initialized,
03814 tree attributes,
03815 tree prefix_attributes,
03816 tree *pushed_scope_p)
03817 {
03818 tree decl;
03819 tree type, tem;
03820 tree context;
03821 bool was_public;
03822
03823 *pushed_scope_p = NULL_TREE;
03824
03825
03826
03827 if (lookup_attribute ("deprecated", attributes))
03828 deprecated_state = DEPRECATED_SUPPRESS;
03829
03830 attributes = chainon (attributes, prefix_attributes);
03831
03832 decl = grokdeclarator (declarator, declspecs, NORMAL, initialized,
03833 &attributes);
03834
03835 deprecated_state = DEPRECATED_NORMAL;
03836
03837 if (decl == NULL_TREE || TREE_CODE (decl) == VOID_TYPE
03838 || decl == error_mark_node)
03839 return error_mark_node;
03840
03841 type = TREE_TYPE (decl);
03842
03843 context = DECL_CONTEXT (decl);
03844
03845 if (context)
03846 {
03847 *pushed_scope_p = push_scope (context);
03848
03849
03850 if (TREE_CODE (context) == NAMESPACE_DECL)
03851 context = NULL_TREE;
03852 }
03853
03854 if (initialized)
03855
03856
03857
03858 switch (TREE_CODE (decl))
03859 {
03860 case TYPE_DECL:
03861 error ("typedef %qD is initialized (use __typeof__ instead)", decl);
03862 return error_mark_node;
03863
03864 case FUNCTION_DECL:
03865 error ("function %q#D is initialized like a variable", decl);
03866 return error_mark_node;
03867
03868 default:
03869 break;
03870 }
03871
03872 if (initialized)
03873 {
03874 if (! toplevel_bindings_p ()
03875 && DECL_EXTERNAL (decl))
03876 warning (0, "declaration of %q#D has %<extern%> and is initialized",
03877 decl);
03878 DECL_EXTERNAL (decl) = 0;
03879 if (toplevel_bindings_p ())
03880 TREE_STATIC (decl) = 1;
03881 }
03882
03883
03884 cplus_decl_attributes (&decl, attributes, 0);
03885
03886
03887
03888
03889
03890 if (initialized && DECL_DLLIMPORT_P (decl))
03891 {
03892 error ("definition of %q#D is marked %<dllimport%>", decl);
03893 DECL_DLLIMPORT_P (decl) = 0;
03894 }
03895
03896
03897 maybe_apply_pragma_weak (decl);
03898
03899 if (TREE_CODE (decl) == FUNCTION_DECL
03900 && DECL_DECLARED_INLINE_P (decl)
03901 && DECL_UNINLINABLE (decl)
03902 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
03903 warning (0, "inline function %q+D given attribute noinline", decl);
03904
03905 if (context && COMPLETE_TYPE_P (complete_type (context)))
03906 {
03907 if (TREE_CODE (decl) == VAR_DECL)
03908 {
03909 tree field = lookup_field (context, DECL_NAME (decl), 0, false);
03910 if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL)
03911 error ("%q#D is not a static member of %q#T", decl, context);
03912 else
03913 {
03914 if (DECL_CONTEXT (field) != context)
03915 {
03916 if (!same_type_p (DECL_CONTEXT (field), context))
03917 pedwarn ("ISO C++ does not permit %<%T::%D%> "
03918 "to be defined as %<%T::%D%>",
03919 DECL_CONTEXT (field), DECL_NAME (decl),
03920 context, DECL_NAME (decl));
03921 DECL_CONTEXT (decl) = DECL_CONTEXT (field);
03922 }
03923 if (processing_specialization
03924 && template_class_depth (context) == 0
03925 && CLASSTYPE_TEMPLATE_SPECIALIZATION (context))
03926 error ("template header not allowed in member definition "
03927 "of explicitly specialized class");
03928
03929
03930
03931
03932
03933 if (initialized && DECL_INITIALIZED_IN_CLASS_P (field))
03934 error ("duplicate initialization of %qD", decl);
03935 if (duplicate_decls (decl, field, false))
03936 decl = field;
03937 }
03938 }
03939 else
03940 {
03941 tree field = check_classfn (context, decl,
03942 (processing_template_decl
03943 > template_class_depth (context))
03944 ? current_template_parms
03945 : NULL_TREE);
03946 if (field && duplicate_decls (decl, field,
03947 false))
03948 decl = field;
03949 }
03950
03951
03952 DECL_IN_AGGR_P (decl) = 0;
03953
03954
03955
03956
03957 if (DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
03958 {
03959 SET_DECL_TEMPLATE_SPECIALIZATION (decl);
03960
03961
03962
03963
03964
03965
03966
03967 if (!initialized && processing_specialization)
03968 DECL_EXTERNAL (decl) = 1;
03969 }
03970
03971 if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl))
03972 pedwarn ("declaration of %q#D outside of class is not definition",
03973 decl);
03974 }
03975
03976 was_public = TREE_PUBLIC (decl);
03977
03978
03979 tem = maybe_push_decl (decl);
03980
03981 if (processing_template_decl)
03982 tem = push_template_decl (tem);
03983 if (tem == error_mark_node)
03984 return error_mark_node;
03985
03986
03987
03988
03989
03990
03991 if (flag_conserve_space
03992 && TREE_CODE (tem) == VAR_DECL
03993 && TREE_PUBLIC (tem)
03994 && !DECL_THREAD_LOCAL_P (tem)
03995 && !have_global_bss_p ())
03996 DECL_COMMON (tem) = 1;
03997
03998 if (TREE_CODE (tem) == VAR_DECL
03999 && DECL_NAMESPACE_SCOPE_P (tem) && !TREE_PUBLIC (tem) && !was_public
04000 && !DECL_THIS_STATIC (tem) && !DECL_ARTIFICIAL (tem))
04001 {
04002
04003
04004
04005 gcc_assert (cp_type_readonly (TREE_TYPE (tem)));
04006 DECL_THIS_STATIC (tem) = 1;
04007 }
04008
04009 if (!processing_template_decl && TREE_CODE (tem) == VAR_DECL)
04010 start_decl_1 (tem, initialized);
04011
04012 return tem;
04013 }
04014
04015 void
04016 start_decl_1 (tree decl, bool initialized)
04017 {
04018 tree type;
04019
04020 gcc_assert (!processing_template_decl);
04021
04022 if (error_operand_p (decl))
04023 return;
04024
04025 gcc_assert (TREE_CODE (decl) == VAR_DECL);
04026 type = TREE_TYPE (decl);
04027
04028 if (initialized)
04029
04030
04031
04032 {
04033
04034
04035 if (COMPLETE_TYPE_P (complete_type (type)))
04036 ;
04037 else if (TREE_CODE (type) != ARRAY_TYPE)
04038 {
04039 error ("variable %q#D has initializer but incomplete type", decl);
04040 initialized = 0;
04041 type = TREE_TYPE (decl) = error_mark_node;
04042 }
04043 else if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (type))))
04044 {
04045 if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
04046 error ("elements of array %q#D have incomplete type", decl);
04047
04048 initialized = 0;
04049 }
04050 }
04051 else if (IS_AGGR_TYPE (type)
04052 && ! DECL_EXTERNAL (decl))
04053 {
04054 if (!COMPLETE_TYPE_P (complete_type (type)))
04055 {
04056 error ("aggregate %q#D has incomplete type and cannot be defined",
04057 decl);
04058
04059
04060 type = TREE_TYPE (decl) = error_mark_node;
04061 }
04062 else
04063 {
04064
04065
04066
04067
04068
04069
04070 initialized = TYPE_NEEDS_CONSTRUCTING (type);
04071 }
04072 }
04073
04074
04075
04076
04077
04078
04079
04080 maybe_push_cleanup_level (type);
04081 }
04082
04083
04084
04085
04086
04087
04088
04089
04090
04091
04092
04093 static tree
04094 grok_reference_init (tree decl, tree type, tree init, tree *cleanup)
04095 {
04096 tree tmp;
04097
04098 if (init == NULL_TREE)
04099 {
04100 if ((DECL_LANG_SPECIFIC (decl) == 0
04101 || DECL_IN_AGGR_P (decl) == 0)
04102 && ! DECL_THIS_EXTERN (decl))
04103 error ("%qD declared as reference but not initialized", decl);
04104 return NULL_TREE;
04105 }
04106
04107 if (TREE_CODE (init) == CONSTRUCTOR)
04108 {
04109 error ("ISO C++ forbids use of initializer list to "
04110 "initialize reference %qD", decl);
04111 return NULL_TREE;
04112 }
04113
04114 if (TREE_CODE (init) == TREE_LIST)
04115 init = build_x_compound_expr_from_list (init, "initializer");
04116
04117 if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE
04118 && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
04119
04120 init = decay_conversion (init);
04121
04122
04123
04124
04125
04126
04127
04128
04129 tmp = initialize_reference (type, init, decl, cleanup);
04130
04131 if (tmp == error_mark_node)
04132 return NULL_TREE;
04133 else if (tmp == NULL_TREE)
04134 {
04135 error ("cannot initialize %qT from %qT", type, TREE_TYPE (init));
04136 return NULL_TREE;
04137 }
04138
04139 if (TREE_STATIC (decl) && !TREE_CONSTANT (tmp))
04140 return tmp;
04141
04142 DECL_INITIAL (decl) = tmp;
04143
04144 return NULL_TREE;
04145 }
04146
04147
04148
04149
04150
04151
04152
04153
04154 static bool
04155 check_array_designated_initializer (const constructor_elt *ce)
04156 {
04157
04158 if (ce->index)
04159 {
04160
04161
04162 gcc_assert (TREE_CODE (ce->index) == IDENTIFIER_NODE);
04163 error ("name %qD used in a GNU-style designated "
04164 "initializer for an array", ce->index);
04165 return false;
04166 }
04167
04168 return true;
04169 }
04170
04171
04172
04173
04174
04175 static void
04176 maybe_deduce_size_from_array_init (tree decl, tree init)
04177 {
04178 tree type = TREE_TYPE (decl);
04179
04180 if (TREE_CODE (type) == ARRAY_TYPE
04181 && TYPE_DOMAIN (type) == NULL_TREE
04182 && TREE_CODE (decl) != TYPE_DECL)
04183 {
04184
04185
04186 int do_default = !DECL_EXTERNAL (decl);
04187 tree initializer = init ? init : DECL_INITIAL (decl);
04188 int failure = 0;
04189
04190
04191
04192
04193
04194 if (initializer && TREE_CODE (initializer) == CONSTRUCTOR)
04195 {
04196 VEC(constructor_elt,gc) *v = CONSTRUCTOR_ELTS (initializer);
04197 constructor_elt *ce;
04198 HOST_WIDE_INT i;
04199 for (i = 0;
04200 VEC_iterate (constructor_elt, v, i, ce);
04201 ++i)
04202 if (!check_array_designated_initializer (ce))
04203 failure = 1;
04204 }
04205
04206 if (!failure)
04207 {
04208 failure = cp_complete_array_type (&TREE_TYPE (decl), initializer,
04209 do_default);
04210 if (failure == 1)
04211 {
04212 error ("initializer fails to determine size of %qD", decl);
04213 TREE_TYPE (decl) = error_mark_node;
04214 }
04215 else if (failure == 2)
04216 {
04217 if (do_default)
04218 {
04219 error ("array size missing in %qD", decl);
04220 TREE_TYPE (decl) = error_mark_node;
04221 }
04222
04223
04224
04225
04226 else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
04227 DECL_EXTERNAL (decl) = 1;
04228 }
04229 else if (failure == 3)
04230 {
04231 error ("zero-size array %qD", decl);
04232 TREE_TYPE (decl) = error_mark_node;
04233 }
04234 }
04235
04236 cp_apply_type_quals_to_decl (cp_type_quals (TREE_TYPE (decl)), decl);
04237
04238 layout_decl (decl, 0);
04239 }
04240 }
04241
04242
04243
04244
04245 static void
04246 layout_var_decl (tree decl)
04247 {
04248 tree type;
04249
04250 type = TREE_TYPE (decl);
04251 if (type == error_mark_node)
04252 return;
04253
04254
04255
04256
04257
04258
04259 if (!DECL_EXTERNAL (decl))
04260 complete_type (type);
04261 if (!DECL_SIZE (decl)
04262 && TREE_TYPE (decl) != error_mark_node
04263 && (COMPLETE_TYPE_P (type)
04264 || (TREE_CODE (type) == ARRAY_TYPE
04265 && !TYPE_DOMAIN (type)
04266 && COMPLETE_TYPE_P (TREE_TYPE (type)))))
04267 layout_decl (decl, 0);
04268
04269 if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
04270 {
04271
04272
04273
04274 error ("storage size of %qD isn't known", decl);
04275 TREE_TYPE (decl) = error_mark_node;
04276 }
04277 #if 0
04278
04279
04280
04281 else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype))
04282
04283 note_debug_info_needed (ttype);
04284
04285 if (TREE_STATIC (decl) && DECL_CLASS_SCOPE_P (decl))
04286 note_debug_info_needed (DECL_CONTEXT (decl));
04287 #endif
04288
04289 if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
04290 && DECL_SIZE (decl) != NULL_TREE
04291 && ! TREE_CONSTANT (DECL_SIZE (decl)))
04292 {
04293 if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
04294 constant_expression_warning (DECL_SIZE (decl));
04295 else
04296 error ("storage size of %qD isn't constant", decl);
04297 }
04298 }
04299
04300
04301
04302
04303
04304 static void
04305 maybe_commonize_var (tree decl)
04306 {
04307
04308
04309 if (TREE_STATIC (decl)
04310
04311 && ! DECL_ARTIFICIAL (decl)
04312 && DECL_FUNCTION_SCOPE_P (decl)
04313
04314
04315
04316 && (DECL_COMDAT (DECL_CONTEXT (decl))
04317 || ((DECL_DECLARED_INLINE_P (DECL_CONTEXT (decl))
04318 || DECL_TEMPLATE_INSTANTIATION (DECL_CONTEXT (decl)))
04319 && TREE_PUBLIC (DECL_CONTEXT (decl)))))
04320 {
04321 if (flag_weak)
04322 {
04323
04324
04325
04326 comdat_linkage (decl);
04327 }
04328 else
04329 {
04330 if (DECL_INITIAL (decl) == NULL_TREE
04331 || DECL_INITIAL (decl) == error_mark_node)
04332 {
04333
04334
04335 TREE_PUBLIC (decl) = 1;
04336 DECL_COMMON (decl) = 1;
04337 }
04338 else
04339 {
04340
04341
04342
04343 TREE_PUBLIC (decl) = 0;
04344 DECL_COMMON (decl) = 0;
04345 warning (0, "sorry: semantics of inline function static "
04346 "data %q+#D are wrong (you'll wind up "
04347 "with multiple copies)", decl);
04348 warning (0, "%J you can work around this by removing "
04349 "the initializer",
04350 decl);
04351 }
04352 }
04353 }
04354 else if (DECL_LANG_SPECIFIC (decl) && DECL_COMDAT (decl))
04355
04356
04357 comdat_linkage (decl);
04358 }
04359
04360
04361
04362 static void
04363 check_for_uninitialized_const_var (tree decl)
04364 {
04365 tree type = TREE_TYPE (decl);
04366
04367
04368
04369
04370 if (TREE_CODE (decl) == VAR_DECL
04371 && TREE_CODE (type) != REFERENCE_TYPE
04372 && CP_TYPE_CONST_P (type)
04373 && !TYPE_NEEDS_CONSTRUCTING (type)
04374 && !DECL_INITIAL (decl))
04375 error ("uninitialized const %qD", decl);
04376 }
04377
04378
04379
04380
04381
04382 typedef struct reshape_iterator_t
04383 {
04384 constructor_elt *cur;
04385 constructor_elt *end;
04386 } reshape_iter;
04387
04388 static tree reshape_init_r (tree, reshape_iter *, bool);
04389
04390
04391
04392
04393
04394
04395 static tree
04396 next_initializable_field (tree field)
04397 {
04398 while (field
04399 && (TREE_CODE (field) != FIELD_DECL
04400 || (DECL_C_BIT_FIELD (field) && !DECL_NAME (field))
04401 || DECL_ARTIFICIAL (field)))
04402 field = TREE_CHAIN (field);
04403
04404 return field;
04405 }
04406
04407
04408
04409
04410
04411
04412
04413 static tree
04414 reshape_init_array_1 (tree elt_type, tree max_index, reshape_iter *d)
04415 {
04416 tree new_init;
04417 bool sized_array_p = (max_index != NULL_TREE);
04418 unsigned HOST_WIDE_INT max_index_cst = 0;
04419 unsigned HOST_WIDE_INT index;
04420
04421
04422 new_init = build_constructor (NULL_TREE, NULL);
04423
04424 if (sized_array_p)
04425 {
04426
04427 if (integer_all_onesp (max_index))
04428 return new_init;
04429
04430 if (host_integerp (max_index, 1))
04431 max_index_cst = tree_low_cst (max_index, 1);
04432
04433 else
04434 max_index_cst = tree_low_cst (fold_convert (size_type_node, max_index),
04435 1);
04436 }
04437
04438
04439 for (index = 0;
04440 d->cur != d->end && (!sized_array_p || index <= max_index_cst);
04441 ++index)
04442 {
04443 tree elt_init;
04444
04445 check_array_designated_initializer (d->cur);
04446 elt_init = reshape_init_r (elt_type, d, false);
04447 if (elt_init == error_mark_node)
04448 return error_mark_node;
04449 CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init), NULL_TREE, elt_init);
04450 }
04451
04452 return new_init;
04453 }
04454
04455
04456
04457
04458 static tree
04459 reshape_init_array (tree type, reshape_iter *d)
04460 {
04461 tree max_index = NULL_TREE;
04462
04463 gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
04464
04465 if (TYPE_DOMAIN (type))
04466 max_index = array_type_nelts (type);
04467
04468 return reshape_init_array_1 (TREE_TYPE (type), max_index, d);
04469 }
04470
04471
04472
04473
04474 static tree
04475 reshape_init_vector (tree type, reshape_iter *d)
04476 {
04477 tree max_index = NULL_TREE;
04478 tree rtype;
04479
04480 gcc_assert (TREE_CODE (type) == VECTOR_TYPE);
04481
04482 if (COMPOUND_LITERAL_P (d->cur->value))
04483 {
04484 tree value = d->cur->value;
04485 if (!same_type_p (TREE_TYPE (value), type))
04486 {
04487 error ("invalid type %qT as initializer for a vector of type %qT",
04488 TREE_TYPE (d->cur->value), type);
04489 value = error_mark_node;
04490 }
04491 ++d->cur;
04492 return value;
04493 }
04494
04495
04496
04497
04498 rtype = TYPE_DEBUG_REPRESENTATION_TYPE (type);
04499 if (rtype && TYPE_DOMAIN (TREE_TYPE (TYPE_FIELDS (rtype))))
04500 max_index = array_type_nelts (TREE_TYPE (TYPE_FIELDS (rtype)));
04501
04502 return reshape_init_array_1 (TREE_TYPE (type), max_index, d);
04503 }
04504
04505
04506
04507
04508 static tree
04509 reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p)
04510 {
04511 tree field;
04512 tree new_init;
04513
04514 gcc_assert (CLASS_TYPE_P (type));
04515
04516
04517 new_init = build_constructor (NULL_TREE, NULL);
04518 field = next_initializable_field (TYPE_FIELDS (type));
04519
04520 if (!field)
04521 {
04522
04523
04524
04525
04526
04527 if (!first_initializer_p)
04528 {
04529 error ("initializer for %qT must be brace-enclosed", type);
04530 return error_mark_node;
04531 }
04532 return new_init;
04533 }
04534
04535
04536 while (d->cur != d->end)
04537 {
04538 tree field_init;
04539
04540
04541 if (d->cur->index)
04542 {
04543 field = lookup_field_1 (type, d->cur->index, false);
04544
04545 if (!field || TREE_CODE (field) != FIELD_DECL)
04546 {
04547 error ("%qT has no non-static data member named %qD", type,
04548 d->cur->index);
04549 return error_mark_node;
04550 }
04551 }
04552
04553
04554 if (!field)
04555 break;
04556
04557 field_init = reshape_init_r (TREE_TYPE (field), d,
04558 false);
04559 CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init), field, field_init);
04560
04561
04562
04563
04564
04565
04566 if (TREE_CODE (type) == UNION_TYPE)
04567 break;
04568
04569 field = next_initializable_field (TREE_CHAIN (field));
04570 }
04571
04572 return new_init;
04573 }
04574
04575
04576
04577
04578
04579
04580
04581 static tree
04582 reshape_init_r (tree type, reshape_iter *d, bool first_initializer_p)
04583 {
04584 tree init = d->cur->value;
04585
04586
04587
04588 if (!CP_AGGREGATE_TYPE_P (type))
04589 {
04590
04591
04592
04593
04594
04595 if (TREE_CODE (init) == CONSTRUCTOR
04596 && BRACE_ENCLOSED_INITIALIZER_P (init))
04597 {
04598 error ("braces around scalar initializer for type %qT", type);
04599 init = error_mark_node;
04600 }
04601
04602 d->cur++;
04603 return init;
04604 }
04605
04606
04607
04608
04609
04610
04611
04612
04613
04614
04615 if (TREE_CODE (init) != CONSTRUCTOR
04616 && can_convert_arg (type, TREE_TYPE (init), init, LOOKUP_NORMAL))
04617 {
04618 d->cur++;
04619 return init;
04620 }
04621
04622
04623
04624
04625
04626
04627
04628 if (TREE_CODE (type) == ARRAY_TYPE
04629 && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type))))
04630 {
04631 tree str_init = init;
04632
04633
04634
04635 if (!first_initializer_p
04636 && TREE_CODE (str_init) == CONSTRUCTOR
04637 && VEC_length (constructor_elt, CONSTRUCTOR_ELTS (str_init)) == 1)
04638 {
04639 str_init = VEC_index (constructor_elt,
04640 CONSTRUCTOR_ELTS (str_init), 0)->value;
04641 }
04642
04643
04644
04645
04646 if (TREE_CODE (str_init) == STRING_CST)
04647 {
04648 d->cur++;
04649 return str_init;
04650 }
04651 }
04652
04653
04654
04655
04656
04657 if (!first_initializer_p)
04658 {
04659 if (TREE_CODE (init) == CONSTRUCTOR)
04660 {
04661 if (TREE_TYPE (init) && TYPE_PTRMEMFUNC_P (TREE_TYPE (init)))
04662
04663
04664
04665 ;
04666 else if (COMPOUND_LITERAL_P (init))
04667
04668
04669
04670
04671
04672 gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (init));
04673 else
04674 {
04675 ++d->cur;
04676 gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (init));
04677 return reshape_init (type, init);
04678 }
04679 }
04680
04681 warning (OPT_Wmissing_braces, "missing braces around initializer for %qT",
04682 type);
04683 }
04684
04685
04686 if (CLASS_TYPE_P (type))
04687 return reshape_init_class (type, d, first_initializer_p);
04688 else if (TREE_CODE (type) == ARRAY_TYPE)
04689 return reshape_init_array (type, d);
04690 else if (TREE_CODE (type) == VECTOR_TYPE)
04691 return reshape_init_vector (type, d);
04692 else
04693 gcc_unreachable();
04694 }
04695
04696
04697
04698
04699
04700
04701
04702
04703
04704
04705
04706
04707
04708
04709
04710
04711 tree
04712 reshape_init (tree type, tree init)
04713 {
04714 VEC(constructor_elt, gc) *v;
04715 reshape_iter d;
04716 tree new_init;
04717
04718 gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (init));
04719
04720 v = CONSTRUCTOR_ELTS (init);
04721
04722
04723
04724 if (VEC_empty (constructor_elt, v))
04725 return init;
04726
04727
04728 d.cur = VEC_index (constructor_elt, v, 0);
04729 d.end = d.cur + VEC_length (constructor_elt, v);
04730
04731 new_init = reshape_init_r (type, &d, true);
04732 if (new_init == error_mark_node)
04733 return error_mark_node;
04734
04735
04736
04737 if (d.cur != d.end)
04738 error ("too many initializers for %qT", type);
04739
04740 return new_init;
04741 }
04742
04743
04744
04745
04746
04747
04748
04749
04750 static tree
04751 check_initializer (tree decl, tree init, int flags, tree *cleanup)
04752 {
04753 tree type = TREE_TYPE (decl);
04754 tree init_code = NULL;
04755
04756
04757
04758 TREE_TYPE (decl) = type = complete_type (TREE_TYPE (decl));
04759
04760 if (type == error_mark_node)
04761
04762 return NULL_TREE;
04763
04764 if (TREE_CODE (type) == ARRAY_TYPE)
04765 {
04766 tree element_type = TREE_TYPE (type);
04767
04768
04769
04770
04771 if (!COMPLETE_TYPE_P (complete_type (element_type)))
04772 {
04773 error ("elements of array %q#D have incomplete type", decl);
04774 return NULL_TREE;
04775 }
04776
04777 if (init
04778 && ((COMPLETE_TYPE_P (type) && !TREE_CONSTANT (TYPE_SIZE (type)))
04779 || !TREE_CONSTANT (TYPE_SIZE (element_type))))
04780 {
04781 error ("variable-sized object %qD may not be initialized", decl);
04782 return NULL_TREE;
04783 }
04784 }
04785 else if (!COMPLETE_TYPE_P (type))
04786 {
04787 error ("%qD has incomplete type", decl);
04788 TREE_TYPE (decl) = error_mark_node;
04789 return NULL_TREE;
04790 }
04791 else
04792
04793 gcc_assert (TREE_CONSTANT (TYPE_SIZE (type)));
04794
04795 if (!CP_AGGREGATE_TYPE_P (type)
04796 && init && BRACE_ENCLOSED_INITIALIZER_P (init)
04797 && VEC_length (constructor_elt, CONSTRUCTOR_ELTS (init)) != 1)
04798 {
04799 error ("scalar object %qD requires one element in initializer", decl);
04800 TREE_TYPE (decl) = error_mark_node;
04801 return NULL_TREE;
04802 }
04803
04804 if (TREE_CODE (decl) == CONST_DECL)
04805 {
04806 gcc_assert (TREE_CODE (type) != REFERENCE_TYPE);
04807
04808 DECL_INITIAL (decl) = init;
04809
04810 gcc_assert (init != NULL_TREE);
04811 init = NULL_TREE;
04812 }
04813 else if (!DECL_EXTERNAL (decl) && TREE_CODE (type) == REFERENCE_TYPE)
04814 init = grok_reference_init (decl, type, init, cleanup);
04815 else if (init)
04816 {
04817
04818
04819 if (TREE_CODE (init) == CONSTRUCTOR
04820 && !COMPOUND_LITERAL_P (init)
04821 && !TREE_TYPE (init))
04822 {
04823 init = reshape_init (type, init);
04824
04825 if ((*targetm.vector_opaque_p) (type))
04826 {
04827 error ("opaque vector types cannot be initialized");
04828 init = error_mark_node;
04829 }
04830 }
04831
04832
04833
04834 maybe_deduce_size_from_array_init (decl, init);
04835 type = TREE_TYPE (decl);
04836 if (type == error_mark_node)
04837 return NULL_TREE;
04838
04839 if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type))
04840 {
04841 if (TREE_CODE (type) == ARRAY_TYPE)
04842 goto initialize_aggr;
04843 else if (TREE_CODE (init) == CONSTRUCTOR)
04844 {
04845 if (TYPE_NON_AGGREGATE_CLASS (type))
04846 {
04847 error ("%qD must be initialized by constructor, "
04848 "not by %<{...}%>",
04849 decl);
04850 init = error_mark_node;
04851 }
04852 else
04853 goto dont_use_constructor;
04854 }
04855 else
04856 {
04857 int saved_stmts_are_full_exprs_p;
04858
04859 initialize_aggr:
04860 saved_stmts_are_full_exprs_p = 0;
04861 if (building_stmt_tree ())
04862 {
04863 saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
04864 current_stmt_tree ()->stmts_are_full_exprs_p = 1;
04865 }
04866 init = build_aggr_init (decl, init, flags);
04867 if (building_stmt_tree ())
04868 current_stmt_tree ()->stmts_are_full_exprs_p =
04869 saved_stmts_are_full_exprs_p;
04870 return init;
04871 }
04872 }
04873 else
04874 {
04875 dont_use_constructor:
04876 if (TREE_CODE (init) != TREE_VEC)
04877 {
04878 init_code = store_init_value (decl, init);
04879 if (pedantic && TREE_CODE (type) == ARRAY_TYPE
04880 && DECL_INITIAL (decl)
04881 && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
04882 && PAREN_STRING_LITERAL_P (DECL_INITIAL (decl)))
04883 warning (0, "array %qD initialized by parenthesized string literal %qE",
04884 decl, DECL_INITIAL (decl));
04885 init = NULL;
04886 }
04887 }
04888 }
04889 else if (DECL_EXTERNAL (decl))
04890 ;
04891 else if (TYPE_P (type) && TYPE_NEEDS_CONSTRUCTING (type))
04892 goto initialize_aggr;
04893 else if (IS_AGGR_TYPE (type))
04894 {
04895 tree core_type = strip_array_types (type);
04896
04897 if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type))
04898 error ("structure %qD with uninitialized const members", decl);
04899 if (CLASSTYPE_REF_FIELDS_NEED_INIT (core_type))
04900 error ("structure %qD with uninitialized reference members", decl);
04901
04902 check_for_uninitialized_const_var (decl);
04903 }
04904 else
04905 check_for_uninitialized_const_var (decl);
04906
04907 if (init && init != error_mark_node)
04908 init_code = build2 (INIT_EXPR, type, decl, init);
04909
04910 return init_code;
04911 }
04912
04913
04914
04915 static void
04916 make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec)
04917 {
04918 int toplev = toplevel_bindings_p ();
04919 int defer_p;
04920 const char *filename;
04921
04922
04923 if (asmspec)
04924 {
04925
04926
04927
04928 if (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
04929 {
04930 set_user_assembler_name (decl, asmspec);
04931 DECL_HARD_REGISTER (decl) = 1;
04932 }
04933 else
04934 {
04935 if (TREE_CODE (decl) == FUNCTION_DECL
04936 && DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL)
04937 set_builtin_user_assembler_name (decl, asmspec);
04938 set_user_assembler_name (decl, asmspec);
04939 }
04940 }
04941
04942
04943 if (TREE_CODE (decl) != VAR_DECL)
04944 {
04945 rest_of_decl_compilation (decl, toplev, at_eof);
04946 return;
04947 }
04948
04949
04950
04951 if (DECL_LANG_SPECIFIC (decl) && DECL_IN_AGGR_P (decl))
04952 {
04953 gcc_assert (TREE_STATIC (decl));
04954
04955
04956 if (init == NULL_TREE)
04957 gcc_assert (DECL_EXTERNAL (decl));
04958 }
04959
04960
04961 if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
04962 return;
04963
04964
04965
04966 defer_p = DECL_FUNCTION_SCOPE_P (decl) || DECL_VIRTUAL_P (decl);
04967
04968
04969
04970 filename = input_filename;
04971 if (!DECL_VIRTUAL_P (decl)
04972 && TREE_READONLY (decl)
04973 && DECL_INITIAL (decl) != NULL_TREE
04974 && DECL_INITIAL (decl) != error_mark_node
04975 && filename != NULL
04976 && ! EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl))
04977 && toplev
04978 && !TREE_PUBLIC (decl))
04979 {
04980
04981
04982 struct c_fileinfo *finfo = get_fileinfo (filename);
04983 if (!finfo->interface_unknown && !TREE_PUBLIC (decl))
04984 {
04985 TREE_PUBLIC (decl) = 1;
04986 DECL_EXTERNAL (decl) = finfo->interface_only;
04987 }
04988
04989 defer_p = 1;
04990 }
04991
04992 else if (DECL_LANG_SPECIFIC (decl)
04993 && DECL_IMPLICIT_INSTANTIATION (decl))
04994 defer_p = 1;
04995
04996
04997 if (!defer_p)
04998 rest_of_decl_compilation (decl, toplev, at_eof);
04999 }
05000
05001
05002
05003 static void
05004 initialize_local_var (tree decl, tree init)
05005 {
05006 tree type = TREE_TYPE (decl);
05007 tree cleanup;
05008
05009 gcc_assert (TREE_CODE (decl) == VAR_DECL
05010 || TREE_CODE (decl) == RESULT_DECL);
05011 gcc_assert (!TREE_STATIC (decl));
05012
05013 if (DECL_SIZE (decl) == NULL_TREE)
05014 {
05015
05016 DECL_INITIAL (decl) = NULL_TREE;
05017 TREE_ADDRESSABLE (decl) = TREE_USED (decl);
05018 }
05019
05020 if (DECL_SIZE (decl) && type != error_mark_node)
05021 {
05022 int already_used;
05023
05024
05025 already_used = TREE_USED (decl) || TREE_USED (type);
05026
05027
05028 if (init)
05029 {
05030 int saved_stmts_are_full_exprs_p;
05031
05032 gcc_assert (building_stmt_tree ());
05033 saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
05034 current_stmt_tree ()->stmts_are_full_exprs_p = 1;
05035 finish_expr_stmt (init);
05036 current_stmt_tree ()->stmts_are_full_exprs_p =
05037 saved_stmts_are_full_exprs_p;
05038 }
05039
05040
05041
05042
05043
05044
05045
05046 if (TYPE_NEEDS_CONSTRUCTING (type)
05047 && ! already_used
05048 && TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
05049 && DECL_NAME (decl))
05050 TREE_USED (decl) = 0;
05051 else if (already_used)
05052 TREE_USED (decl) = 1;
05053 }
05054
05055
05056 cleanup = cxx_maybe_build_cleanup (decl);
05057 if (DECL_SIZE (decl) && cleanup)
05058 finish_decl_cleanup (decl, cleanup);
05059 }
05060
05061
05062
05063
05064
05065
05066
05067 void
05068 initialize_artificial_var (tree decl, tree init)
05069 {
05070 gcc_assert (DECL_ARTIFICIAL (decl));
05071 if (TREE_CODE (init) == TREE_LIST)
05072 init = build_constructor_from_list (NULL_TREE, init);
05073 gcc_assert (TREE_CODE (init) == CONSTRUCTOR);
05074 DECL_INITIAL (decl) = init;
05075 DECL_INITIALIZED_P (decl) = 1;
05076 determine_visibility (decl);
05077 layout_var_decl (decl);
05078 maybe_commonize_var (decl);
05079 make_rtl_for_nonlocal_decl (decl, init, NULL);
05080 }
05081
05082
05083
05084
05085
05086
05087
05088
05089
05090
05091
05092
05093 void
05094 cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
05095 tree asmspec_tree, int flags)
05096 {
05097 tree type;
05098 tree cleanup;
05099 const char *asmspec = NULL;
05100 int was_readonly = 0;
05101 bool var_definition_p = false;
05102 int saved_processing_template_decl;
05103
05104 if (decl == error_mark_node)
05105 return;
05106 else if (! decl)
05107 {
05108 if (init)
05109 error ("assignment (not initialization) in declaration");
05110 return;
05111 }
05112
05113 gcc_assert (TREE_CODE (decl) != RESULT_DECL);
05114
05115 gcc_assert (TREE_CODE (decl) != PARM_DECL);
05116
05117 type = TREE_TYPE (decl);
05118 if (type == error_mark_node)
05119 return;
05120
05121
05122 cleanup = NULL_TREE;
05123 saved_processing_template_decl = processing_template_decl;
05124
05125
05126 if (global_scope_p (current_binding_level))
05127 asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
05128 if (asmspec_tree && asmspec_tree != error_mark_node)
05129 asmspec = TREE_STRING_POINTER (asmspec_tree);
05130
05131 if (current_class_type
05132 && CP_DECL_CONTEXT (decl) == current_class_type
05133 && TYPE_BEING_DEFINED (current_class_type)
05134 && (DECL_INITIAL (decl) || init))
05135 DECL_INITIALIZED_IN_CLASS_P (decl) = 1;
05136
05137 if (processing_template_decl)
05138 {
05139 bool type_dependent_p;
05140
05141
05142 if (at_function_scope_p ())
05143 add_decl_expr (decl);
05144
05145 type_dependent_p = dependent_type_p (type);
05146
05147 if (init && init_const_expr_p)
05148 {
05149 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
05150 if (DECL_INTEGRAL_CONSTANT_VAR_P (decl))
05151 TREE_CONSTANT (decl) = 1;
05152 }
05153
05154 if (!init
05155 || !DECL_CLASS_SCOPE_P (decl)
05156 || !DECL_INTEGRAL_CONSTANT_VAR_P (decl)
05157 || type_dependent_p
05158 || value_dependent_expression_p (init)
05159
05160
05161 || (TREE_CODE (init) == CONSTRUCTOR
05162 && VEC_length (constructor_elt, CONSTRUCTOR_ELTS (init)) == 1
05163 && value_dependent_expression_p
05164 (VEC_index (constructor_elt,
05165 CONSTRUCTOR_ELTS (init), 0)->value)))
05166 {
05167 if (init)
05168 DECL_INITIAL (decl) = init;
05169 if (TREE_CODE (decl) == VAR_DECL
05170 && !DECL_PRETTY_FUNCTION_P (decl)
05171 && !type_dependent_p)
05172 maybe_deduce_size_from_array_init (decl, init);
05173 goto finish_end;
05174 }
05175
05176 init = fold_non_dependent_expr (init);
05177 processing_template_decl = 0;
05178 }
05179
05180
05181 if (TREE_CODE (decl) == TYPE_DECL)
05182 {
05183 if (type != error_mark_node
05184 && IS_AGGR_TYPE (type) && DECL_NAME (decl))
05185 {
05186 if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
05187 warning (0, "shadowing previous type declaration of %q#D", decl);
05188 set_identifier_type_value (DECL_NAME (decl), decl);
05189 }
05190
05191
05192
05193
05194 if (TYPE_MAIN_DECL (TREE_TYPE (decl)) == decl
05195 && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
05196 TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
05197
05198 rest_of_decl_compilation (decl, DECL_CONTEXT (decl) == NULL_TREE,
05199 at_eof);
05200 goto finish_end;
05201 }
05202
05203
05204 if (! DECL_EXTERNAL (decl)
05205 && TREE_READONLY (decl)
05206 && TREE_CODE (type) == REFERENCE_TYPE)
05207 {
05208 was_readonly = 1;
05209 TREE_READONLY (decl) = 0;
05210 }
05211
05212 if (TREE_CODE (decl) == VAR_DECL)
05213 {
05214
05215
05216 if (DECL_THREAD_LOCAL_P (decl) && !pod_type_p (TREE_TYPE (decl)))
05217 error ("%qD cannot be thread-local because it has non-POD type %qT",
05218 decl, TREE_TYPE (decl));
05219
05220
05221
05222
05223
05224
05225 if (!processing_template_decl
05226 && DECL_FUNCTION_SCOPE_P (decl)
05227 && TREE_STATIC (decl)
05228 && !DECL_ARTIFICIAL (decl))
05229 push_local_name (decl);
05230
05231
05232 if (!DECL_INITIALIZED_P (decl)
05233
05234
05235
05236
05237 && (!DECL_EXTERNAL (decl) || init))
05238 {
05239 if (init)
05240 {
05241 DECL_NONTRIVIALLY_INITIALIZED_P (decl) = 1;
05242 if (init_const_expr_p)
05243 {
05244 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
05245 if (DECL_INTEGRAL_CONSTANT_VAR_P (decl))
05246 TREE_CONSTANT (decl) = 1;
05247 }
05248 }
05249 init = check_initializer (decl, init, flags, &cleanup);
05250
05251 if (DECL_THREAD_LOCAL_P (decl) && init)
05252 {
05253 error ("%qD is thread-local and so cannot be dynamically "
05254 "initialized", decl);
05255 init = NULL_TREE;
05256 }
05257
05258
05259
05260
05261
05262
05263
05264
05265
05266
05267
05268
05269 if (DECL_EXTERNAL (decl) && init)
05270 {
05271 error ("%qD cannot be initialized by a non-constant expression"
05272 " when being declared", decl);
05273 DECL_INITIALIZED_IN_CLASS_P (decl) = 0;
05274 init = NULL_TREE;
05275 }
05276
05277
05278
05279
05280
05281
05282
05283
05284
05285
05286
05287
05288
05289 if (TREE_STATIC (decl) && !DECL_INITIAL (decl))
05290 DECL_INITIAL (decl) = build_zero_init (TREE_TYPE (decl),
05291 NULL_TREE,
05292 true);
05293
05294
05295 DECL_INITIALIZED_P (decl) = 1;
05296
05297
05298
05299 if (!DECL_EXTERNAL (decl))
05300 var_definition_p = true;
05301 }
05302
05303
05304
05305
05306 else if (TREE_CODE (type) == ARRAY_TYPE)
05307 layout_type (type);
05308 }
05309
05310
05311
05312
05313 if (at_function_scope_p ())
05314 add_decl_expr (decl);
05315
05316
05317
05318 if (!saved_processing_template_decl
05319 && (TREE_CODE (decl) == VAR_DECL
05320 || TREE_CODE (decl) == FUNCTION_DECL))
05321 {
05322 if (TREE_CODE (decl) == VAR_DECL)
05323 {
05324 layout_var_decl (decl);
05325 maybe_commonize_var (decl);
05326 }
05327
05328 make_rtl_for_nonlocal_decl (decl, init, asmspec);
05329
05330
05331
05332
05333 if (TREE_CODE (type) == FUNCTION_TYPE
05334 || TREE_CODE (type) == METHOD_TYPE)
05335 abstract_virtuals_error (decl, TREE_TYPE (type));
05336 else
05337 abstract_virtuals_error (decl, type);
05338
05339
05340 determine_visibility (decl);
05341
05342 if (TREE_CODE (decl) == FUNCTION_DECL
05343 || TREE_TYPE (decl) == error_mark_node)
05344
05345 ;
05346 else if (DECL_EXTERNAL (decl)
05347 && ! (DECL_LANG_SPECIFIC (decl)
05348 && DECL_NOT_REALLY_EXTERN (decl)))
05349 {
05350 if (init)
05351 DECL_INITIAL (decl) = init;
05352 }
05353 else
05354 {
05355
05356 if (DECL_FUNCTION_SCOPE_P (decl))
05357 {
05358
05359 if (processing_template_decl)
05360 DECL_INITIAL (decl) = init;
05361 else if (!TREE_STATIC (decl))
05362 initialize_local_var (decl, init);
05363 }
05364
05365
05366
05367
05368
05369
05370
05371
05372
05373 if (var_definition_p && TREE_STATIC (decl))
05374 expand_static_init (decl, init);
05375 }
05376 }
05377
05378
05379
05380 if (cleanup)
05381 push_cleanup (decl, cleanup, false);
05382
05383 finish_end:
05384 processing_template_decl = saved_processing_template_decl;
05385
05386 if (was_readonly)
05387 TREE_READONLY (decl) = 1;
05388
05389
05390 if (lookup_attribute ("used", DECL_ATTRIBUTES (decl)))
05391 mark_decl_referenced (decl);
05392 }
05393
05394
05395
05396 void
05397 finish_decl (tree decl, tree init, tree asmspec_tree)
05398 {
05399 cp_finish_decl (decl, init, false, asmspec_tree, 0);
05400 }
05401
05402
05403
05404
05405
05406
05407
05408
05409 static tree
05410 declare_global_var (tree name, tree type)
05411 {
05412 tree decl;
05413
05414 push_to_top_level ();
05415 decl = build_decl (VAR_DECL, name, type);
05416 TREE_PUBLIC (decl) = 1;
05417 DECL_EXTERNAL (decl) = 1;
05418 DECL_ARTIFICIAL (decl) = 1;
05419
05420
05421
05422
05423 decl = pushdecl (decl);
05424 finish_decl (decl, NULL_TREE, NULL_TREE);
05425 pop_from_top_level ();
05426
05427 return decl;
05428 }
05429
05430
05431
05432
05433
05434 static tree
05435 get_atexit_node (void)
05436 {
05437 tree atexit_fndecl;
05438 tree arg_types;
05439 tree fn_type;
05440 tree fn_ptr_type;
05441 const char *name;
05442 bool use_aeabi_atexit;
05443
05444 if (atexit_node)
05445 return atexit_node;
05446
05447 if (flag_use_cxa_atexit)
05448 {
05449
05450
05451
05452
05453
05454
05455
05456 use_aeabi_atexit = targetm.cxx.use_aeabi_atexit ();
05457
05458
05459 arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
05460 fn_type = build_function_type (void_type_node, arg_types);
05461 fn_ptr_type = build_pointer_type (fn_type);
05462
05463 arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
05464 if (use_aeabi_atexit)
05465 {
05466 arg_types = tree_cons (NULL_TREE, fn_ptr_type, arg_types);
05467 arg_types = tree_cons (NULL_TREE, ptr_type_node, arg_types);
05468 }
05469 else
05470 {
05471 arg_types = tree_cons (NULL_TREE, ptr_type_node, arg_types);
05472 arg_types = tree_cons (NULL_TREE, fn_ptr_type, arg_types);
05473 }
05474
05475 fn_type = build_function_type (integer_type_node, arg_types);
05476 fn_ptr_type = build_pointer_type (fn_type);
05477 if (use_aeabi_atexit)
05478 name = "__aeabi_atexit";
05479 else
05480 name = "__cxa_atexit";
05481 }
05482 else
05483 {
05484
05485
05486
05487
05488
05489
05490 fn_type = build_function_type (void_type_node, void_list_node);
05491 fn_ptr_type = build_pointer_type (fn_type);
05492 arg_types = tree_cons (NULL_TREE, fn_ptr_type, void_list_node);
05493
05494 fn_type = build_function_type (integer_type_node, arg_types);
05495 name = "atexit";
05496 }
05497
05498
05499 push_lang_context (lang_name_c);
05500 atexit_fndecl = build_library_fn_ptr (name, fn_type);
05501 mark_used (atexit_fndecl);
05502 pop_lang_context ();
05503 atexit_node = decay_conversion (atexit_fndecl);
05504
05505 return atexit_node;
05506 }
05507
05508
05509
05510 static tree
05511 get_dso_handle_node (void)
05512 {
05513 if (dso_handle_node)
05514 return dso_handle_node;
05515
05516
05517 dso_handle_node = declare_global_var (get_identifier ("__dso_handle"),
05518 ptr_type_node);
05519
05520 return dso_handle_node;
05521 }
05522
05523
05524
05525
05526 static GTY(()) int start_cleanup_cnt;
05527
05528 static tree
05529 start_cleanup_fn (void)
05530 {
05531 char name[32];
05532 tree parmtypes;
05533 tree fntype;
05534 tree fndecl;
05535
05536 push_to_top_level ();
05537
05538
05539 push_lang_context (lang_name_c);
05540
05541
05542 parmtypes = void_list_node;
05543
05544
05545
05546
05547 if (flag_use_cxa_atexit)
05548 parmtypes = tree_cons (NULL_TREE, ptr_type_node, parmtypes);
05549
05550 fntype = build_function_type (void_type_node, parmtypes);
05551
05552 sprintf (name, "__tcf_%d", start_cleanup_cnt++);
05553
05554 fndecl = build_lang_decl (FUNCTION_DECL, get_identifier (name), fntype);
05555
05556
05557 TREE_PUBLIC (fndecl) = 0;
05558 DECL_ARTIFICIAL (fndecl) = 1;
05559
05560
05561
05562
05563 DECL_INLINE (fndecl) = 1;
05564 DECL_DECLARED_INLINE_P (fndecl) = 1;
05565 DECL_INTERFACE_KNOWN (fndecl) = 1;
05566
05567 if (flag_use_cxa_atexit)
05568 {
05569 tree parmdecl;
05570
05571 parmdecl = cp_build_parm_decl (NULL_TREE, ptr_type_node);
05572 DECL_CONTEXT (parmdecl) = fndecl;
05573 TREE_USED (parmdecl) = 1;
05574 DECL_ARGUMENTS (fndecl) = parmdecl;
05575 }
05576
05577 pushdecl (fndecl);
05578 start_preparsed_function (fndecl, NULL_TREE, SF_PRE_PARSED);
05579
05580 pop_lang_context ();
05581
05582 return current_function_decl;
05583 }
05584
05585
05586
05587 static void
05588 end_cleanup_fn (void)
05589 {
05590 expand_or_defer_fn (finish_function (0));
05591
05592 pop_from_top_level ();
05593 }
05594
05595
05596
05597
05598 tree
05599 register_dtor_fn (tree decl)
05600 {
05601 tree cleanup;
05602 tree compound_stmt;
05603 tree args;
05604 tree fcall;
05605
05606 if (TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
05607 return void_zero_node;
05608
05609
05610
05611
05612 build_cleanup (decl);
05613
05614
05615 cleanup = start_cleanup_fn ();
05616
05617
05618
05619
05620
05621
05622 push_deferring_access_checks (dk_no_check);
05623 fcall = build_cleanup (decl);
05624 pop_deferring_access_checks ();
05625
05626
05627 compound_stmt = begin_compound_stmt (BCS_FN_BODY);
05628 finish_expr_stmt (fcall);
05629 finish_compound_stmt (compound_stmt);
05630 end_cleanup_fn ();
05631
05632
05633 cxx_mark_addressable (cleanup);
05634 mark_used (cleanup);
05635 cleanup = build_unary_op (ADDR_EXPR, cleanup, 0);
05636 if (flag_use_cxa_atexit)
05637 {
05638 args = tree_cons (NULL_TREE,
05639 build_unary_op (ADDR_EXPR, get_dso_handle_node (), 0),
05640 NULL_TREE);
05641 if (targetm.cxx.use_aeabi_atexit ())
05642 {
05643 args = tree_cons (NULL_TREE, cleanup, args);
05644 args = tree_cons (NULL_TREE, null_pointer_node, args);
05645 }
05646 else
05647 {
05648 args = tree_cons (NULL_TREE, null_pointer_node, args);
05649 args = tree_cons (NULL_TREE, cleanup, args);
05650 }
05651 }
05652 else
05653 args = tree_cons (NULL_TREE, cleanup, NULL_TREE);
05654 return build_function_call (get_atexit_node (), args);
05655 }
05656
05657
05658
05659
05660
05661 static void
05662 expand_static_init (tree decl, tree init)
05663 {
05664 gcc_assert (TREE_CODE (decl) == VAR_DECL);
05665 gcc_assert (TREE_STATIC (decl));
05666
05667
05668 if (!init
05669 && !TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))
05670 && TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
05671 return;
05672
05673 if (DECL_FUNCTION_SCOPE_P (decl))
05674 {
05675
05676 tree if_stmt = NULL_TREE, inner_if_stmt = NULL_TREE;
05677 tree then_clause = NULL_TREE, inner_then_clause = NULL_TREE;
05678 tree guard, guard_addr, guard_addr_list;
05679 tree acquire_fn, release_fn, abort_fn;
05680 tree flag, begin;
05681
05682
05683
05684
05685
05686
05687
05688
05689
05690
05691
05692
05693
05694
05695
05696
05697
05698
05699
05700
05701
05702
05703
05704
05705
05706
05707
05708
05709
05710
05711
05712
05713
05714 guard = get_guard (decl);
05715
05716
05717
05718
05719 if (!targetm.relaxed_ordering || !flag_threadsafe_statics)
05720 {
05721
05722 if_stmt = begin_if_stmt ();
05723 finish_if_stmt_cond (get_guard_cond (guard), if_stmt);
05724 then_clause = begin_compound_stmt (BCS_NO_SCOPE);
05725 }
05726
05727 if (flag_threadsafe_statics)
05728 {
05729 guard_addr = build_address (guard);
05730 guard_addr_list = build_tree_list (NULL_TREE, guard_addr);
05731
05732 acquire_fn = get_identifier ("__cxa_guard_acquire");
05733 release_fn = get_identifier ("__cxa_guard_release");
05734 abort_fn = get_identifier ("__cxa_guard_abort");
05735 if (!get_global_value_if_present (acquire_fn, &acquire_fn))
05736 {
05737 tree argtypes = tree_cons (NULL_TREE, TREE_TYPE (guard_addr),
05738 void_list_node);
05739 tree vfntype = build_function_type (void_type_node, argtypes);
05740 acquire_fn = push_library_fn
05741 (acquire_fn, build_function_type (integer_type_node, argtypes));
05742 release_fn = push_library_fn (release_fn, vfntype);
05743 abort_fn = push_library_fn (abort_fn, vfntype);
05744 }
05745 else
05746 {
05747 release_fn = identifier_global_value (release_fn);
05748 abort_fn = identifier_global_value (abort_fn);
05749 }
05750
05751 inner_if_stmt = begin_if_stmt ();
05752 finish_if_stmt_cond (build_call (acquire_fn, guard_addr_list),
05753 inner_if_stmt);
05754
05755 inner_then_clause = begin_compound_stmt (BCS_NO_SCOPE);
05756 begin = get_target_expr (boolean_false_node);
05757 flag = TARGET_EXPR_SLOT (begin);
05758
05759 TARGET_EXPR_CLEANUP (begin)
05760 = build3 (COND_EXPR, void_type_node, flag,
05761 void_zero_node,
05762 build_call (abort_fn, guard_addr_list));
05763 CLEANUP_EH_ONLY (begin) = 1;
05764
05765
05766 init = add_stmt_to_compound (begin, init);
05767 init = add_stmt_to_compound
05768 (init, build2 (MODIFY_EXPR, void_type_node, flag, boolean_true_node));
05769 init = add_stmt_to_compound
05770 (init, build_call (release_fn, guard_addr_list));
05771 }
05772 else
05773 init = add_stmt_to_compound (init, set_guard (guard));
05774
05775
05776
05777 init = add_stmt_to_compound (init, register_dtor_fn (decl));
05778
05779 finish_expr_stmt (init);
05780
05781 if (flag_threadsafe_statics)
05782 {
05783 finish_compound_stmt (inner_then_clause);
05784 finish_then_clause (inner_if_stmt);
05785 finish_if_stmt (inner_if_stmt);
05786 }
05787
05788 if (!targetm.relaxed_ordering || !flag_threadsafe_statics)
05789 {
05790 finish_compound_stmt (then_clause);
05791 finish_then_clause (if_stmt);
05792 finish_if_stmt (if_stmt);
05793 }
05794 }
05795 else
05796 static_aggregates = tree_cons (init, decl, static_aggregates);
05797 }
05798
05799
05800
05801
05802
05803
05804
05805 int
05806 cp_complete_array_type (tree *ptype, tree initial_value, bool do_default)
05807 {
05808 int failure;
05809 tree type, elt_type;
05810
05811 if (initial_value)
05812 {
05813
05814
05815
05816
05817
05818 if (char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (*ptype)))
05819 && TREE_CODE (initial_value) == CONSTRUCTOR
05820 && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (initial_value)))
05821 {
05822 VEC(constructor_elt,gc) *v = CONSTRUCTOR_ELTS (initial_value);
05823 tree value = VEC_index (constructor_elt, v, 0)->value;
05824
05825 if (TREE_CODE (value) == STRING_CST
05826 && VEC_length (constructor_elt, v) == 1)
05827 initial_value = value;
05828 }
05829 }
05830
05831 failure = complete_array_type (ptype, initial_value, do_default);
05832
05833
05834
05835
05836
05837
05838 type = *ptype;
05839 if (TYPE_DOMAIN (type))
05840 {
05841 elt_type = TREE_TYPE (type);
05842 TYPE_NEEDS_CONSTRUCTING (type) = TYPE_NEEDS_CONSTRUCTING (elt_type);
05843 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
05844 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type);
05845 }
05846
05847 return failure;
05848 }
05849
05850
05851
05852
05853
05854 static int
05855 member_function_or_else (tree ctype, tree cur_type, enum overload_flags flags)
05856 {
05857 if (ctype && ctype != cur_type)
05858 {
05859 if (flags == DTOR_FLAG)
05860 error ("destructor for alien class %qT cannot be a member", ctype);
05861 else
05862 error ("constructor for alien class %qT cannot be a member", ctype);
05863 return 0;
05864 }
05865 return 1;
05866 }
05867
05868
05869
05870
05871
05872
05873 static void
05874 bad_specifiers (tree object,
05875 const char* type,
05876 int virtualp,
05877 int quals,
05878 int inlinep,
05879 int friendp,
05880 int raises)
05881 {
05882 if (virtualp)
05883 error ("%qD declared as a %<virtual%> %s", object, type);
05884 if (inlinep)
05885 error ("%qD declared as an %<inline%> %s", object, type);
05886 if (quals)
05887 error ("%<const%> and %<volatile%> function specifiers on "
05888 "%qD invalid in %s declaration",
05889 object, type);
05890 if (friendp)
05891 error ("%q+D declared as a friend", object);
05892 if (raises
05893 && (TREE_CODE (object) == TYPE_DECL
05894 || (!TYPE_PTRFN_P (TREE_TYPE (object))
05895 && !TYPE_REFFN_P (TREE_TYPE (object))
05896 && !TYPE_PTRMEMFUNC_P (TREE_TYPE (object)))))
05897 error ("%q+D declared with an exception specification", object);
05898 }
05899
05900
05901
05902
05903
05904 static void
05905 check_class_member_definition_namespace (tree decl)
05906 {
05907
05908
05909 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL
05910 || TREE_CODE (decl) == VAR_DECL);
05911
05912
05913
05914 if (processing_specialization)
05915 return;
05916
05917
05918 if (processing_explicit_instantiation)
05919 return;
05920
05921
05922
05923
05924
05925
05926
05927
05928
05929
05930 if (!is_ancestor (current_namespace, DECL_CONTEXT (decl)))
05931 pedwarn ("definition of %qD is not in namespace enclosing %qT",
05932 decl, DECL_CONTEXT (decl));
05933 }
05934
05935
05936
05937
05938
05939 tree
05940 build_this_parm (tree type, cp_cv_quals quals)
05941 {
05942 tree this_type;
05943 tree qual_type;
05944 tree parm;
05945 cp_cv_quals this_quals;
05946
05947 this_type = TREE_VALUE (TYPE_ARG_TYPES (type));
05948
05949
05950 this_quals = (quals & TYPE_QUAL_RESTRICT) | TYPE_QUAL_CONST;
05951 qual_type = cp_build_qualified_type (this_type, this_quals);
05952 parm = build_artificial_parm (this_identifier, qual_type);
05953 cp_apply_type_quals_to_decl (this_quals, parm);
05954 return parm;
05955 }
05956
05957
05958
05959
05960
05961
05962
05963
05964
05965
05966
05967
05968
05969
05970
05971
05972
05973
05974
05975 static tree
05976 grokfndecl (tree ctype,
05977 tree type,
05978 tree declarator,
05979 tree parms,
05980 tree orig_declarator,
05981 int virtualp,
05982 enum overload_flags flags,
05983 cp_cv_quals quals,
05984 tree raises,
05985 int check,
05986 int friendp,
05987 int publicp,
05988 int inlinep,
05989 special_function_kind sfk,
05990 bool funcdef_flag,
05991 int template_count,
05992 tree in_namespace,
05993 tree* attrlist)
05994 {
05995 tree decl;
05996 int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE;
05997 tree t;
05998
05999 if (raises)
06000 type = build_exception_variant (type, raises);
06001
06002 decl = build_lang_decl (FUNCTION_DECL, declarator, type);
06003 if (TREE_CODE (type) == METHOD_TYPE)
06004 {
06005 tree parm;
06006 parm = build_this_parm (type, quals);
06007 TREE_CHAIN (parm) = parms;
06008 parms = parm;
06009 }
06010 DECL_ARGUMENTS (decl) = parms;
06011
06012 if (TYPE_VOLATILE (type))
06013 TREE_THIS_VOLATILE (decl) = 1;
06014
06015 if (friendp
06016 && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)
06017 {
06018 if (funcdef_flag)
06019 error
06020 ("defining explicit specialization %qD in friend declaration",
06021 orig_declarator);
06022 else
06023 {
06024 tree fns = TREE_OPERAND (orig_declarator, 0);
06025 tree args = TREE_OPERAND (orig_declarator, 1);
06026
06027 if (PROCESSING_REAL_TEMPLATE_DECL_P ())
06028 {
06029
06030 error ("invalid use of template-id %qD in declaration "
06031 "of primary template",
06032 orig_declarator);
06033 return NULL_TREE;
06034 }
06035
06036
06037
06038
06039 SET_DECL_IMPLICIT_INSTANTIATION (decl);
06040
06041 if (TREE_CODE (fns) == COMPONENT_REF)
06042 {
06043
06044
06045
06046
06047
06048 gcc_assert (TREE_TYPE (TREE_OPERAND (fns, 0))
06049 == current_class_type);
06050 fns = TREE_OPERAND (fns, 1);
06051 }
06052 gcc_assert (TREE_CODE (fns) == IDENTIFIER_NODE
06053 || TREE_CODE (fns) == OVERLOAD);
06054 DECL_TEMPLATE_INFO (decl) = tree_cons (fns, args, NULL_TREE);
06055
06056 for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t))
06057 if (TREE_PURPOSE (t)
06058 && TREE_CODE (TREE_PURPOSE (t)) == DEFAULT_ARG)
06059 {
06060 error ("default arguments are not allowed in declaration "
06061 "of friend template specialization %qD",
06062 decl);
06063 return NULL_TREE;
06064 }
06065
06066 if (inlinep)
06067 {
06068 error ("%<inline%> is not allowed in declaration of friend "
06069 "template specialization %qD",
06070 decl);
06071 return NULL_TREE;
06072 }
06073 }
06074 }
06075
06076
06077 if (in_namespace)
06078 set_decl_namespace (decl, in_namespace, friendp);
06079 else if (!ctype)
06080 DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
06081
06082
06083 if ((MAIN_NAME_P (declarator)
06084 || (IDENTIFIER_LENGTH (declarator) > 10
06085 && IDENTIFIER_POINTER (declarator)[0] == '_'
06086 && IDENTIFIER_POINTER (declarator)[1] == '_'
06087 && strncmp (IDENTIFIER_POINTER (declarator)+2, "builtin_", 8) == 0))
06088 && current_lang_name == lang_name_cplusplus
06089 && ctype == NULL_TREE
06090
06091 && DECL_CONTEXT (decl) == NULL_TREE)
06092 SET_DECL_LANGUAGE (decl, lang_c);
06093
06094
06095 if (staticp)
06096 {
06097 DECL_STATIC_FUNCTION_P (decl) = 1;
06098 DECL_CONTEXT (decl) = ctype;
06099 }
06100
06101 if (ctype)
06102 {
06103 DECL_CONTEXT (decl) = ctype;
06104 if (funcdef_flag)
06105 check_class_member_definition_namespace (decl);
06106 }
06107
06108 if (ctype == NULL_TREE && DECL_MAIN_P (decl))
06109 {
06110 if (processing_template_decl)
06111 error ("cannot declare %<::main%> to be a template");
06112 if (inlinep)
06113 error ("cannot declare %<::main%> to be inline");
06114 if (!publicp)
06115 error ("cannot declare %<::main%> to be static");
06116 inlinep = 0;
06117 publicp = 1;
06118 }
06119
06120
06121
06122 if (ctype && (TYPE_ANONYMOUS_P (ctype)
06123 || decl_function_context (TYPE_MAIN_DECL (ctype))))
06124 publicp = 0;
06125
06126 if (publicp)
06127 {
06128
06129
06130
06131
06132
06133 t = no_linkage_check (TREE_TYPE (decl),
06134 false);
06135 if (t)
06136 {
06137 if (TYPE_ANONYMOUS_P (t))
06138 {
06139 if (DECL_EXTERN_C_P (decl))
06140 ;
06141 else
06142 {
06143 pedwarn ("non-local function %q#D uses anonymous type",
06144 decl);
06145 if (DECL_ORIGINAL_TYPE (TYPE_NAME (t)))
06146 pedwarn ("%q+#D does not refer to the unqualified "
06147 "type, so it is not used for linkage",
06148 TYPE_NAME (t));
06149 }
06150 }
06151 else
06152 pedwarn ("non-local function %q#D uses local type %qT", decl, t);
06153 }
06154 }
06155
06156 TREE_PUBLIC (decl) = publicp;
06157 if (! publicp)
06158 {
06159 DECL_INTERFACE_KNOWN (decl) = 1;
06160 DECL_NOT_REALLY_EXTERN (decl) = 1;
06161 }
06162
06163
06164 if (inlinep)
06165 DECL_DECLARED_INLINE_P (decl) = 1;
06166
06167
06168 if (DECL_DECLARED_INLINE_P (decl)
06169 || (flag_inline_trees == 2 && !DECL_INLINE (decl) && funcdef_flag))
06170 DECL_INLINE (decl) = 1;
06171
06172 DECL_EXTERNAL (decl) = 1;
06173 if (quals && TREE_CODE (type) == FUNCTION_TYPE)
06174 {
06175 error ("%smember function %qD cannot have cv-qualifier",
06176 (ctype ? "static " : "non-"), decl);
06177 quals = TYPE_UNQUALIFIED;
06178 }
06179
06180 if (IDENTIFIER_OPNAME_P (DECL_NAME (decl))
06181 && !grok_op_properties (decl, true))
06182 return NULL_TREE;
06183
06184 if (ctype && decl_function_context (decl))
06185 DECL_NO_STATIC_CHAIN (decl) = 1;
06186
06187 if (funcdef_flag)
06188
06189
06190 DECL_INITIAL (decl) = error_mark_node;
06191
06192 if (TYPE_NOTHROW_P (type) || nothrow_libfn_p (decl))
06193 TREE_NOTHROW (decl) = 1;
06194
06195
06196 if (check < 0)
06197 return decl;
06198
06199 if (ctype != NULL_TREE)
06200 {
06201 if (sfk == sfk_constructor)
06202 DECL_CONSTRUCTOR_P (decl) = 1;
06203
06204 grokclassfn (ctype, decl, flags);
06205 }
06206
06207 decl = check_explicit_specialization (orig_declarator, decl,
06208 template_count,
06209 2 * funcdef_flag +
06210 4 * (friendp != 0));
06211 if (decl == error_mark_node)
06212 return NULL_TREE;
06213
06214 if (attrlist)
06215 {
06216 cplus_decl_attributes (&decl, *attrlist, 0);
06217 *attrlist = NULL_TREE;
06218 }
06219
06220
06221 if (ctype == NULL_TREE && DECL_MAIN_P (decl)
06222 && !same_type_p (TREE_TYPE (TREE_TYPE (decl)),
06223 integer_type_node))
06224 {
06225 tree oldtypeargs = TYPE_ARG_TYPES (TREE_TYPE (decl));
06226 tree newtype;
06227 error ("%<::main%> must return %<int%>");
06228 newtype = build_function_type (integer_type_node, oldtypeargs);
06229 TREE_TYPE (decl) = newtype;
06230 }
06231
06232 if (ctype != NULL_TREE
06233 && (! TYPE_FOR_JAVA (ctype) || check_java_method (decl))
06234 && check)
06235 {
06236 tree old_decl;
06237
06238 old_decl = check_classfn (ctype, decl,
06239 (processing_template_decl
06240 > template_class_depth (ctype))
06241 ? current_template_parms
06242 : NULL_TREE);
06243 if (old_decl)
06244 {
06245 tree ok;
06246 tree pushed_scope;
06247
06248 if (TREE_CODE (old_decl) == TEMPLATE_DECL)
06249
06250
06251
06252
06253 old_decl = DECL_TEMPLATE_RESULT (old_decl);
06254
06255 if (DECL_STATIC_FUNCTION_P (old_decl)
06256 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
06257
06258
06259 revert_static_member_fn (decl);
06260 if (DECL_ARTIFICIAL (old_decl))
06261 error ("definition of implicitly-declared %qD", old_decl);
06262
06263
06264
06265 if (TREE_CODE (decl) == TEMPLATE_DECL)
06266 decl = DECL_TEMPLATE_RESULT (decl);
06267
06268
06269
06270 pushed_scope = push_scope (ctype);
06271 ok = duplicate_decls (decl, old_decl, friendp);
06272 if (pushed_scope)
06273 pop_scope (pushed_scope);
06274 if (!ok)
06275 {
06276 error ("no %q#D member function declared in class %qT",
06277 decl, ctype);
06278 return NULL_TREE;
06279 }
06280 return old_decl;
06281 }
06282 }
06283
06284 if (DECL_CONSTRUCTOR_P (decl) && !grok_ctor_properties (ctype, decl))
06285 return NULL_TREE;
06286
06287 if (ctype == NULL_TREE || check)
06288 return decl;
06289
06290 if (virtualp)
06291 DECL_VIRTUAL_P (decl) = 1;
06292
06293 return decl;
06294 }
06295
06296
06297
06298
06299 static void
06300 set_linkage_for_static_data_member (tree decl)
06301 {
06302
06303
06304
06305
06306 TREE_PUBLIC (decl) = 1;
06307 TREE_STATIC (decl) = 1;
06308
06309
06310
06311 if (!processing_template_decl)
06312 DECL_INTERFACE_KNOWN (decl) = 1;
06313 }
06314
06315
06316
06317
06318
06319
06320
06321 static tree
06322 grokvardecl (tree type,
06323 tree name,
06324 const cp_decl_specifier_seq *declspecs,
06325 int initialized,
06326 int constp,
06327 tree scope)
06328 {
06329 tree decl;
06330 tree explicit_scope;
06331
06332 gcc_assert (!name || TREE_CODE (name) == IDENTIFIER_NODE);
06333
06334
06335
06336 explicit_scope = scope;
06337 if (!scope)
06338 {
06339
06340
06341 if (declspecs->storage_class == sc_extern)
06342 scope = current_namespace;
06343 else if (!at_function_scope_p ())
06344 scope = current_scope ();
06345 }
06346
06347 if (scope
06348 && (
06349
06350 (TREE_CODE (scope) == NAMESPACE_DECL && processing_template_decl)
06351
06352
06353 || (TREE_CODE (scope) == NAMESPACE_DECL
06354 && current_lang_name != lang_name_cplusplus)
06355
06356 || TYPE_P (scope)))
06357 decl = build_lang_decl (VAR_DECL, name, type);
06358 else
06359 decl = build_decl (VAR_DECL, name, type);
06360
06361 if (explicit_scope && TREE_CODE (explicit_scope) == NAMESPACE_DECL)
06362 set_decl_namespace (decl, explicit_scope, 0);
06363 else
06364 DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
06365
06366 if (declspecs->storage_class == sc_extern)
06367 {
06368 DECL_THIS_EXTERN (decl) = 1;
06369 DECL_EXTERNAL (decl) = !initialized;
06370 }
06371
06372 if (DECL_CLASS_SCOPE_P (decl))
06373 {
06374 set_linkage_for_static_data_member (decl);
06375
06376 DECL_EXTERNAL (decl) = 0;
06377 check_class_member_definition_namespace (decl);
06378 }
06379
06380
06381 else if (toplevel_bindings_p ())
06382 {
06383 TREE_PUBLIC (decl) = (declspecs->storage_class != sc_static
06384 && (DECL_THIS_EXTERN (decl) || ! constp));
06385 TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
06386 }
06387
06388 else
06389 {
06390 TREE_STATIC (decl) = declspecs->storage_class == sc_static;
06391 TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
06392 }
06393
06394 if (declspecs->specs[(int)ds_thread])
06395 {
06396 if (targetm.have_tls)
06397 DECL_TLS_MODEL (decl) = decl_default_tls_model (decl);
06398 else
06399
06400
06401 error ("thread-local storage not supported for this target");
06402 }
06403
06404 if (TREE_PUBLIC (decl))
06405 {
06406
06407
06408
06409
06410
06411 tree t = no_linkage_check (TREE_TYPE (decl), false);
06412 if (t)
06413 {
06414 if (TYPE_ANONYMOUS_P (t))
06415 {
06416 if (DECL_EXTERN_C_P (decl))
06417
06418 ;
06419 else
06420 {
06421
06422
06423
06424
06425 warning (0, "non-local variable %q#D uses anonymous type",
06426 decl);
06427 if (DECL_ORIGINAL_TYPE (TYPE_NAME (t)))
06428 warning (0, "%q+#D does not refer to the unqualified "
06429 "type, so it is not used for linkage",
06430 TYPE_NAME (t));
06431 }
06432 }
06433 else
06434 warning (0, "non-local variable %q#D uses local type %qT", decl, t);
06435 }
06436 }
06437 else
06438 DECL_INTERFACE_KNOWN (decl) = 1;
06439
06440 return decl;
06441 }
06442
06443
06444
06445
06446 tree
06447 build_ptrmemfunc_type (tree type)
06448 {
06449 tree field, fields;
06450 tree t;
06451 tree unqualified_variant = NULL_TREE;
06452
06453 if (type == error_mark_node)
06454 return type;
06455
06456
06457
06458
06459
06460 if ((t = TYPE_GET_PTRMEMFUNC_TYPE (type)))
06461 return t;
06462
06463
06464
06465 if (cp_type_quals (type) != TYPE_UNQUALIFIED)
06466 unqualified_variant
06467 = build_ptrmemfunc_type (TYPE_MAIN_VARIANT (type));
06468
06469 t = make_aggr_type (RECORD_TYPE);
06470 xref_basetypes (t, NULL_TREE);
06471
06472
06473 TYPE_PTRMEMFUNC_FLAG (t) = 1;
06474
06475 SET_IS_AGGR_TYPE (t, 0);
06476
06477 field = build_decl (FIELD_DECL, pfn_identifier, type);
06478 fields = field;
06479
06480 field = build_decl (FIELD_DECL, delta_identifier, delta_type_node);
06481 TREE_CHAIN (field) = fields;
06482 fields = field;
06483
06484 finish_builtin_struct (t, "__ptrmemfunc_type", fields, ptr_type_node);
06485
06486
06487
06488 TYPE_NAME (t) = NULL_TREE;
06489
06490
06491
06492
06493
06494 if (cp_type_quals (type) != TYPE_UNQUALIFIED)
06495 {
06496 t = build_qualified_type (t, cp_type_quals (type));
06497 TYPE_MAIN_VARIANT (t) = unqualified_variant;
06498 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (unqualified_variant);
06499 TYPE_NEXT_VARIANT (unqualified_variant) = t;
06500 }
06501
06502
06503
06504 TYPE_SET_PTRMEMFUNC_TYPE (type, t);
06505
06506 return t;
06507 }
06508
06509
06510
06511 tree
06512 build_ptrmem_type (tree class_type, tree member_type)
06513 {
06514 if (TREE_CODE (member_type) == METHOD_TYPE)
06515 {
06516 tree arg_types;
06517
06518 arg_types = TYPE_ARG_TYPES (member_type);
06519 class_type = (cp_build_qualified_type
06520 (class_type,
06521 cp_type_quals (TREE_TYPE (TREE_VALUE (arg_types)))));
06522 member_type
06523 = build_method_type_directly (class_type,
06524 TREE_TYPE (member_type),
06525 TREE_CHAIN (arg_types));
06526 return build_ptrmemfunc_type (build_pointer_type (member_type));
06527 }
06528 else
06529 {
06530 gcc_assert (TREE_CODE (member_type) != FUNCTION_TYPE);
06531 return build_offset_type (class_type, member_type);
06532 }
06533 }
06534
06535
06536
06537
06538
06539
06540 int
06541 check_static_variable_definition (tree decl, tree type)
06542 {
06543
06544
06545
06546
06547
06548
06549 if (!ARITHMETIC_TYPE_P (type) && TREE_CODE (type) != ENUMERAL_TYPE)
06550 {
06551 error ("invalid in-class initialization of static data member "
06552 "of non-integral type %qT",
06553 type);
06554
06555
06556
06557
06558 return 1;
06559 }
06560 else if (!CP_TYPE_CONST_P (type))
06561 error ("ISO C++ forbids in-class initialization of non-const "
06562 "static member %qD",
06563 decl);
06564 else if (pedantic && !INTEGRAL_TYPE_P (type))
06565 pedwarn ("ISO C++ forbids initialization of member constant "
06566 "%qD of non-integral type %qT", decl, type);
06567
06568 return 0;
06569 }
06570
06571
06572
06573
06574
06575 tree
06576 compute_array_index_type (tree name, tree size)
06577 {
06578 tree type;
06579 tree itype;
06580
06581 if (error_operand_p (size))
06582 return error_mark_node;
06583
06584 type = TREE_TYPE (size);
06585
06586 if (!dependent_type_p (type) && !INTEGRAL_TYPE_P (type))
06587 {
06588 if (name)
06589 error ("size of array %qD has non-integral type %qT", name, type);
06590 else
06591 error ("size of array has non-integral type %qT", type);
06592 size = integer_one_node;
06593 type = TREE_TYPE (size);
06594 }
06595
06596 if (abi_version_at_least (2)
06597
06598 ? value_dependent_expression_p (size)
06599
06600
06601 : processing_template_decl)
06602 return build_index_type (build_min (MINUS_EXPR, sizetype,
06603 size, integer_one_node));
06604
06605
06606 STRIP_TYPE_NOPS (size);
06607
06608
06609 size = integral_constant_value (size);
06610
06611
06612 if (TREE_CODE (size) == INTEGER_CST)
06613 {
06614
06615
06616 int old_flag_pedantic_errors = flag_pedantic_errors;
06617 int old_pedantic = pedantic;
06618 pedantic = flag_pedantic_errors = 1;
06619 constant_expression_warning (size);
06620 pedantic = old_pedantic;
06621 flag_pedantic_errors = old_flag_pedantic_errors;
06622
06623
06624 if (INT_CST_LT (size, integer_zero_node))
06625 {
06626 if (name)
06627 error ("size of array %qD is negative", name);
06628 else
06629 error ("size of array is negative");
06630 size = integer_one_node;
06631 }
06632
06633
06634 else if (integer_zerop (size) && pedantic && !in_system_header)
06635 {
06636 if (name)
06637 pedwarn ("ISO C++ forbids zero-size array %qD", name);
06638 else
06639 pedwarn ("ISO C++ forbids zero-size array");
06640 }
06641 }
06642 else if (TREE_CONSTANT (size))
06643 {
06644
06645 if (name)
06646 error ("size of array %qD is not an integral constant-expression",
06647 name);
06648 else
06649 error ("size of array is not an integral constant-expression");
06650 size = integer_one_node;
06651 }
06652 else if (pedantic)
06653 {
06654 if (name)
06655 pedwarn ("ISO C++ forbids variable-size array %qD", name);
06656 else
06657 pedwarn ("ISO C++ forbids variable-size array");
06658 }
06659
06660 if (processing_template_decl && !TREE_CONSTANT (size))
06661
06662 itype = build_min (MINUS_EXPR, sizetype, size, integer_one_node);
06663 else
06664 {
06665 HOST_WIDE_INT saved_processing_template_decl;
06666
06667
06668
06669
06670
06671 saved_processing_template_decl = processing_template_decl;
06672 processing_template_decl = 0;
06673 itype = cp_build_binary_op (MINUS_EXPR,
06674 cp_convert (ssizetype, size),
06675 cp_convert (ssizetype, integer_one_node));
06676 itype = fold (itype);
06677 processing_template_decl = saved_processing_template_decl;
06678
06679 if (!TREE_CONSTANT (itype))
06680
06681 itype = variable_size (itype);
06682
06683
06684
06685 else if (TREE_CODE (itype) == INTEGER_CST
06686 && TREE_OVERFLOW (itype))
06687 {
06688 error ("overflow in array dimension");
06689 TREE_OVERFLOW (itype) = 0;
06690 }
06691 }
06692
06693
06694 return build_index_type (itype);
06695 }
06696
06697
06698
06699
06700
06701 tree
06702 get_scope_of_declarator (const cp_declarator *declarator)
06703 {
06704 while (declarator && declarator->kind != cdk_id)
06705 declarator = declarator->declarator;
06706
06707
06708
06709 if (declarator
06710 && declarator->u.id.qualifying_scope)
06711 return declarator->u.id.qualifying_scope;
06712
06713
06714
06715 return NULL_TREE;
06716 }
06717
06718
06719
06720
06721
06722 static tree
06723 create_array_type_for_decl (tree name, tree type, tree size)
06724 {
06725 tree itype = NULL_TREE;
06726 const char* error_msg;
06727
06728
06729 if (type == error_mark_node || size == error_mark_node)
06730 return error_mark_node;
06731
06732
06733 error_msg = NULL;
06734
06735
06736 switch (TREE_CODE (type))
06737 {
06738 case VOID_TYPE:
06739 error_msg = "array of void";
06740 break;
06741
06742 case FUNCTION_TYPE:
06743 error_msg = "array of functions";
06744 break;
06745
06746 case REFERENCE_TYPE:
06747 error_msg = "array of references";
06748 break;
06749
06750 case METHOD_TYPE:
06751 error_msg = "array of function members";
06752 break;
06753
06754 default:
06755 break;
06756 }
06757
06758
06759 if (error_msg)
06760 {
06761 if (name)
06762 error ("declaration of %qD as %s", name, error_msg);
06763 else
06764 error ("creating %s", error_msg);
06765
06766 return error_mark_node;
06767 }
06768
06769
06770
06771
06772
06773 if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
06774 {
06775 if (name)
06776 error ("declaration of %qD as multidimensional array must "
06777 "have bounds for all dimensions except the first",
06778 name);
06779 else
06780 error ("multidimensional array must have bounds for all "
06781 "dimensions except the first");
06782
06783 return error_mark_node;
06784 }
06785
06786
06787 if (size)
06788 itype = compute_array_index_type (name, size);
06789
06790
06791
06792
06793 abstract_virtuals_error (name, type);
06794
06795 return build_cplus_array_type (type, itype);
06796 }
06797
06798
06799
06800
06801
06802
06803
06804
06805
06806 static tree
06807 check_special_function_return_type (special_function_kind sfk,
06808 tree type,
06809 tree optype)
06810 {
06811 switch (sfk)
06812 {
06813 case sfk_constructor:
06814 if (type)
06815 error ("return type specification for constructor invalid");
06816
06817 if (targetm.cxx.cdtor_returns_this () && !TYPE_FOR_JAVA (optype))
06818 type = build_pointer_type (optype);
06819 else
06820 type = void_type_node;
06821 break;
06822
06823 case sfk_destructor:
06824 if (type)
06825 error ("return type specification for destructor invalid");
06826
06827
06828
06829
06830 if (targetm.cxx.cdtor_returns_this () && !TYPE_FOR_JAVA (optype))
06831 type = build_pointer_type (void_type_node);
06832 else
06833 type = void_type_node;
06834 break;
06835
06836 case sfk_conversion:
06837 if (type && !same_type_p (type, optype))
06838 error ("operator %qT declared to return %qT", optype, type);
06839 else if (type)
06840 pedwarn ("return type specified for %<operator %T%>", optype);
06841 type = optype;
06842 break;
06843
06844 default:
06845 gcc_unreachable ();
06846 }
06847
06848 return type;
06849 }
06850
06851
06852
06853
06854
06855
06856 tree
06857 check_var_type (tree identifier, tree type)
06858 {
06859 if (VOID_TYPE_P (type))
06860 {
06861 if (!identifier)
06862 error ("unnamed variable or field declared void");
06863 else if (TREE_CODE (identifier) == IDENTIFIER_NODE)
06864 {
06865 gcc_assert (!IDENTIFIER_OPNAME_P (identifier));
06866 error ("variable or field %qE declared void", identifier);
06867 }
06868 else
06869 error ("variable or field declared void");
06870 type = error_mark_node;
06871 }
06872
06873 return type;
06874 }
06875
06876
06877
06878
06879
06880
06881
06882
06883
06884
06885
06886
06887
06888
06889
06890
06891
06892
06893
06894
06895
06896
06897
06898
06899
06900
06901
06902
06903
06904
06905
06906
06907
06908
06909
06910
06911
06912
06913
06914
06915
06916
06917
06918
06919 tree
06920 grokdeclarator (const cp_declarator *declarator,
06921 const cp_decl_specifier_seq *declspecs,
06922 enum decl_context decl_context,
06923 int initialized,
06924 tree* attrlist)
06925 {
06926 tree type = NULL_TREE;
06927 int longlong = 0;
06928 int virtualp, explicitp, friendp, inlinep, staticp;
06929 int explicit_int = 0;
06930 int explicit_char = 0;
06931 int defaulted_int = 0;
06932 tree dependent_name = NULL_TREE;
06933
06934 tree typedef_decl = NULL_TREE;
06935 const char *name = NULL;
06936 tree typedef_type = NULL_TREE;
06937
06938 bool funcdef_flag = false;
06939 cp_declarator_kind innermost_code = cdk_error;
06940 int bitfield = 0;
06941 #if 0
06942
06943 tree decl_attr = NULL_TREE;
06944 #endif
06945
06946
06947
06948
06949 special_function_kind sfk = sfk_none;
06950
06951 tree dname = NULL_TREE;
06952 tree ctor_return_type = NULL_TREE;
06953 enum overload_flags flags = NO_SPECIAL;
06954
06955
06956 cp_cv_quals memfn_quals = TYPE_UNQUALIFIED;
06957
06958 int type_quals;
06959 tree raises = NULL_TREE;
06960 int template_count = 0;
06961 tree returned_attrs = NULL_TREE;
06962 tree parms = NULL_TREE;
06963 const cp_declarator *id_declarator;
06964
06965
06966 tree unqualified_id;
06967
06968
06969
06970
06971 tree ctype = current_class_type;
06972
06973
06974
06975
06976 tree in_namespace = NULL_TREE;
06977 cp_storage_class storage_class;
06978 bool unsigned_p, signed_p, short_p, long_p, thread_p;
06979 bool type_was_error_mark_node = false;
06980
06981 signed_p = declspecs->specs[(int)ds_signed];
06982 unsigned_p = declspecs->specs[(int)ds_unsigned];
06983 short_p = declspecs->specs[(int)ds_short];
06984 long_p = declspecs->specs[(int)ds_long];
06985 longlong = declspecs->specs[(int)ds_long] >= 2;
06986 thread_p = declspecs->specs[(int)ds_thread];
06987
06988 if (decl_context == FUNCDEF)
06989 funcdef_flag = true, decl_context = NORMAL;
06990 else if (decl_context == MEMFUNCDEF)
06991 funcdef_flag = true, decl_context = FIELD;
06992 else if (decl_context == BITFIELD)
06993 bitfield = 1, decl_context = FIELD;
06994
06995
06996
06997 for (id_declarator = declarator;
06998 id_declarator;
06999 id_declarator = id_declarator->declarator)
07000 {
07001 if (id_declarator->kind != cdk_id)
07002 innermost_code = id_declarator->kind;
07003
07004 switch (id_declarator->kind)
07005 {
07006 case cdk_function:
07007 if (id_declarator->declarator
07008 && id_declarator->declarator->kind == cdk_id)
07009 {
07010 sfk = id_declarator->declarator->u.id.sfk;
07011 if (sfk == sfk_destructor)
07012 flags = DTOR_FLAG;
07013 }
07014 break;
07015
07016 case cdk_id:
07017 {
07018 tree qualifying_scope = id_declarator->u.id.qualifying_scope;
07019 tree decl = id_declarator->u.id.unqualified_name;
07020 if (!decl)
07021 break;
07022 if (qualifying_scope)
07023 {
07024 if (at_function_scope_p ())
07025 {
07026
07027
07028
07029
07030
07031
07032
07033 if (qualifying_scope == global_namespace)
07034 error ("invalid use of qualified-name %<::%D%>",
07035 decl);
07036 else if (TYPE_P (qualifying_scope))
07037 error ("invalid use of qualified-name %<%T::%D%>",
07038 qualifying_scope, decl);
07039 else
07040 error ("invalid use of qualified-name %<%D::%D%>",
07041 qualifying_scope, decl);
07042 return error_mark_node;
07043 }
07044 else if (TYPE_P (qualifying_scope))
07045 {
07046 ctype = qualifying_scope;
07047 if (innermost_code != cdk_function
07048 && current_class_type
07049 && !UNIQUELY_DERIVED_FROM_P (ctype,
07050 current_class_type))
07051 {
07052 error ("type %qT is not derived from type %qT",
07053 ctype, current_class_type);
07054 return error_mark_node;
07055 }
07056 }
07057 else if (TREE_CODE (qualifying_scope) == NAMESPACE_DECL)
07058 in_namespace = qualifying_scope;
07059 }
07060 switch (TREE_CODE (decl))
07061 {
07062 case BIT_NOT_EXPR:
07063 {
07064 tree type;
07065
07066 if (innermost_code != cdk_function)
07067 {
07068 error ("declaration of %qD as non-function", decl);
07069 return error_mark_node;
07070 }
07071 else if (!qualifying_scope
07072 && !(current_class_type && at_class_scope_p ()))
07073 {
07074 error ("declaration of %qD as non-member", decl);
07075 return error_mark_node;
07076 }
07077
07078 type = TREE_OPERAND (decl, 0);
07079 name = IDENTIFIER_POINTER (constructor_name (type));
07080 dname = decl;
07081 }
07082 break;
07083
07084 case TEMPLATE_ID_EXPR:
07085 {
07086 tree fns = TREE_OPERAND (decl, 0);
07087
07088 dname = fns;
07089 if (TREE_CODE (dname) != IDENTIFIER_NODE)
07090 {
07091 gcc_assert (is_overloaded_fn (dname));
07092 dname = DECL_NAME (get_first_fn (dname));
07093 }
07094 }
07095
07096
07097 case IDENTIFIER_NODE:
07098 if (TREE_CODE (decl) == IDENTIFIER_NODE)
07099 dname = decl;
07100
07101 if (C_IS_RESERVED_WORD (dname))
07102 {
07103 error ("declarator-id missing; using reserved word %qD",
07104 dname);
07105 name = IDENTIFIER_POINTER (dname);
07106 }
07107 else if (!IDENTIFIER_TYPENAME_P (dname))
07108 name = IDENTIFIER_POINTER (dname);
07109 else
07110 {
07111 gcc_assert (flags == NO_SPECIAL);
07112 flags = TYPENAME_FLAG;
07113 ctor_return_type = TREE_TYPE (dname);
07114 sfk = sfk_conversion;
07115 if (is_typename_at_global_scope (dname))
07116 name = IDENTIFIER_POINTER (dname);
07117 else
07118 name = "<invalid operator>";
07119 }
07120 break;
07121
07122 default:
07123 gcc_unreachable ();
07124 }
07125 break;
07126
07127 case cdk_array:
07128 case cdk_pointer:
07129 case cdk_reference:
07130 case cdk_ptrmem:
07131 break;
07132
07133 case cdk_error:
07134 return error_mark_node;
07135
07136 default:
07137 gcc_unreachable ();
07138 }
07139 }
07140 if (id_declarator->kind == cdk_id)
07141 break;
07142 }
07143
07144
07145
07146
07147
07148 if (funcdef_flag && innermost_code != cdk_function)
07149 {
07150 error ("function definition does not declare parameters");
07151 return error_mark_node;
07152 }
07153
07154 if (((dname && IDENTIFIER_OPNAME_P (dname)) || flags == TYPENAME_FLAG)
07155 && innermost_code != cdk_function
07156 && ! (ctype && !declspecs->any_specifiers_p))
07157 {
07158 error ("declaration of %qD as non-function", dname);
07159 return error_mark_node;
07160 }
07161
07162
07163
07164
07165
07166
07167
07168
07169
07170
07171
07172
07173
07174
07175
07176 if (decl_context == NORMAL && !toplevel_bindings_p ())
07177 {
07178 struct cp_binding_level *b = current_binding_level;
07179 current_binding_level = b->level_chain;
07180 if (current_binding_level != 0 && toplevel_bindings_p ())
07181 decl_context = PARM;
07182 current_binding_level = b;
07183 }
07184
07185 if (name == NULL)
07186 name = decl_context == PARM ? "parameter" : "type name";
07187
07188
07189
07190 if (declspecs->multiple_types_p)
07191 {
07192 error ("two or more data types in declaration of %qs", name);
07193 return error_mark_node;
07194 }
07195
07196
07197 type = declspecs->type;
07198 if (type == error_mark_node)
07199 {
07200 type = NULL_TREE;
07201 type_was_error_mark_node = true;
07202 }
07203
07204
07205 if (type && TREE_DEPRECATED (type)
07206 && deprecated_state != DEPRECATED_SUPPRESS)
07207 warn_deprecated_use (type);
07208 if (type && TREE_CODE (type) == TYPE_DECL)
07209 {
07210 typedef_decl = type;
07211 type = TREE_TYPE (typedef_decl);
07212 }
07213
07214
07215 if (type == NULL_TREE && (signed_p || unsigned_p || long_p || short_p))
07216 {
07217
07218 type = integer_type_node;
07219 defaulted_int = 1;
07220 }
07221
07222 explicit_int = declspecs->explicit_int_p;
07223 explicit_char = declspecs->explicit_char_p;
07224
07225 #if 0
07226
07227 if (typedef_decl)
07228 decl_attr = DECL_ATTRIBUTES (typedef_decl);
07229 #endif
07230 typedef_type = type;
07231
07232
07233 if (sfk != sfk_conversion)
07234 ctor_return_type = ctype;
07235
07236 if (sfk != sfk_none)
07237 type = check_special_function_return_type (sfk, type,
07238 ctor_return_type);
07239 else if (type == NULL_TREE)
07240 {
07241 int is_main;
07242
07243 explicit_int = -1;
07244
07245
07246
07247
07248 is_main = (funcdef_flag
07249 && dname && MAIN_NAME_P (dname)
07250 && ctype == NULL_TREE
07251 && in_namespace == NULL_TREE
07252 && current_namespace == global_namespace);
07253
07254 if (type_was_error_mark_node)
07255 ;
07256 else if (in_system_header || flag_ms_extensions)
07257 ;
07258 else if (pedantic || ! is_main)
07259 pedwarn ("ISO C++ forbids declaration of %qs with no type", name);
07260 else if (warn_return_type)
07261 warning (0, "ISO C++ forbids declaration of %qs with no type", name);
07262
07263 type = integer_type_node;
07264 }
07265
07266 ctype = NULL_TREE;
07267
07268
07269
07270
07271
07272 if (long_p && !longlong && TYPE_MAIN_VARIANT (type) == double_type_node)
07273 {
07274 long_p = false;
07275 type = build_qualified_type (long_double_type_node,
07276 cp_type_quals (type));
07277 }
07278
07279
07280
07281 if (unsigned_p || signed_p || long_p || short_p)
07282 {
07283 int ok = 0;
07284
07285 if ((signed_p || unsigned_p) && TREE_CODE (type) != INTEGER_TYPE)
07286 error ("%<signed%> or %<unsigned%> invalid for %qs", name);
07287 else if (signed_p && unsigned_p)
07288 error ("%<signed%> and %<unsigned%> specified together for %qs", name);
07289 else if (longlong && TREE_CODE (type) != INTEGER_TYPE)
07290 error ("%<long long%> invalid for %qs", name);
07291 else if (long_p && TREE_CODE (type) == REAL_TYPE)
07292 error ("%<long%> invalid for %qs", name);
07293 else if (short_p && TREE_CODE (type) == REAL_TYPE)
07294 error ("%<short%> invalid for %qs", name);
07295 else if ((long_p || short_p) && TREE_CODE (type) != INTEGER_TYPE)
07296 error ("%<long%> or %<short%> invalid for %qs", name);
07297 else if ((long_p || short_p) && explicit_char)
07298 error ("%<long%> or %<short%> specified with char for %qs", name);
07299 else if (long_p && short_p)
07300 error ("%<long%> and %<short%> specified together for %qs", name);
07301 else
07302 {
07303 ok = 1;
07304 if (!explicit_int && !defaulted_int && !explicit_char && pedantic)
07305 {
07306 pedwarn ("long, short, signed or unsigned used invalidly for %qs",
07307 name);
07308 if (flag_pedantic_errors)
07309 ok = 0;
07310 }
07311 }
07312
07313
07314 if (! ok)
07315 {
07316 unsigned_p = false;
07317 signed_p = false;
07318 long_p = false;
07319 short_p = false;
07320 longlong = 0;
07321 }
07322 }
07323
07324
07325
07326 if (unsigned_p
07327
07328
07329
07330
07331
07332
07333
07334
07335 || (bitfield && !flag_signed_bitfields
07336 && !signed_p
07337
07338
07339
07340 && !(typedef_decl
07341 && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))
07342 && TREE_CODE (type) == INTEGER_TYPE
07343 && !same_type_p (TYPE_MAIN_VARIANT (type), wchar_type_node)))
07344 {
07345 if (longlong)
07346 {
07347 #ifdef TARG_SL
07348 if (Long_Long_Support == TRUE)
07349 {
07350 type = long_long_unsigned_type_node;
07351 }
07352 else
07353 {
07354 warning("\"unsigned long long\" is mapped to \"unsinged long\" in declaration %s, "
07355 "Please use \"-mlong-long\" option to enbale long long type supporting", name);
07356 type = long_unsigned_type_node;
07357 }
07358 #else
07359 type = long_long_unsigned_type_node;
07360 #endif
07361 }
07362 else if (long_p)
07363 type = long_unsigned_type_node;
07364 else if (short_p)
07365 type = short_unsigned_type_node;
07366 else if (type == char_type_node)
07367 type = unsigned_char_type_node;
07368 else if (typedef_decl)
07369 type = c_common_unsigned_type (type);
07370 else
07371 type = unsigned_type_node;
07372 }
07373 else if (signed_p && type == char_type_node)
07374 type = signed_char_type_node;
07375 else if (longlong)
07376 {
07377 #ifdef TARG_SL
07378 if (Long_Long_Support == TRUE)
07379 {
07380 type = long_long_integer_type_node;
07381 }
07382 else
07383 {
07384 warning("\"long long\" is mapped to \"long\" in declaration %s, "
07385 "Please use \"-mlong-long\" option to enbale long long type supporting", name);
07386 type = long_integer_type_node;
07387 }
07388 #else
07389 type = long_long_integer_type_node;
07390 #endif
07391 }
07392 else if (long_p)
07393 type = long_integer_type_node;
07394 else if (short_p)
07395 type = short_integer_type_node;
07396
07397 if (declspecs->specs[(int)ds_complex])
07398 {
07399 #ifdef TARG_SL
07400 error("Unsupported type: \"complex\"");
07401 #endif
07402 if (TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
07403 error ("complex invalid for %qs", name);
07404
07405
07406
07407
07408
07409 else if (defaulted_int && ! longlong
07410 && ! (long_p || short_p || signed_p || unsigned_p))
07411 type = complex_double_type_node;
07412 else if (type == integer_type_node)
07413 type = complex_integer_type_node;
07414 else if (type == float_type_node)
07415 type = complex_float_type_node;
07416 else if (type == double_type_node)
07417 type = complex_double_type_node;
07418 else if (type == long_double_type_node)
07419 type = complex_long_double_type_node;
07420 else
07421 type = build_complex_type (type);
07422 }
07423
07424 #ifdef TARG_SL
07425 if (TREE_CODE(type) == REAL_TYPE)
07426 {
07427 if (TYPE_MAIN_VARIANT(type) == double_type_node || TYPE_MAIN_VARIANT(type) == float_type_node)
07428 {
07429 if (Float_Point_Support == FALSE)
07430 {
07431 error("\"float/double\" type is not supported in default mode, "
07432 "Please use \"-msoft-float\" option to enable float point emulation");
07433 }
07434 }
07435 else
07436 {
07437 warning(0, "Unsupported real type");
07438 }
07439 }
07440 #endif
07441
07442 type_quals = TYPE_UNQUALIFIED;
07443 if (declspecs->specs[(int)ds_const])
07444 type_quals |= TYPE_QUAL_CONST;
07445 if (declspecs->specs[(int)ds_volatile])
07446 type_quals |= TYPE_QUAL_VOLATILE;
07447 if (declspecs->specs[(int)ds_restrict])
07448 type_quals |= TYPE_QUAL_RESTRICT;
07449 if (sfk == sfk_conversion && type_quals != TYPE_UNQUALIFIED)
07450 error ("qualifiers are not allowed on declaration of %<operator %T%>",
07451 ctor_return_type);
07452
07453 if (TREE_CODE (type) == FUNCTION_TYPE
07454 && type_quals != TYPE_UNQUALIFIED)
07455 {
07456
07457
07458
07459 if (pedantic)
07460 {
07461 tree bad_type = build_qualified_type (type, type_quals);
07462 pedwarn ("ignoring %qV qualifiers added to function type %qT",
07463 bad_type, type);
07464 }
07465 type_quals = TYPE_UNQUALIFIED;
07466 }
07467 type_quals |= cp_type_quals (type);
07468 type = cp_build_qualified_type_real
07469 (type, type_quals, ((typedef_decl && !DECL_ARTIFICIAL (typedef_decl)
07470 ? tf_ignore_bad_quals : 0) | tf_warning_or_error));
07471
07472 type_quals = cp_type_quals (type);
07473
07474 staticp = 0;
07475 inlinep = !! declspecs->specs[(int)ds_inline];
07476 virtualp = !! declspecs->specs[(int)ds_virtual];
07477 explicitp = !! declspecs->specs[(int)ds_explicit];
07478
07479 storage_class = declspecs->storage_class;
07480 if (storage_class == sc_static)
07481 staticp = 1 + (decl_context == FIELD);
07482
07483 if (virtualp && staticp == 2)
07484 {
07485 error ("member %qD cannot be declared both virtual and static", dname);
07486 storage_class = sc_none;
07487 staticp = 0;
07488 }
07489 friendp = !! declspecs->specs[(int)ds_friend];
07490
07491 if (dependent_name && !friendp)
07492 {
07493 error ("%<%T::%D%> is not a valid declarator", ctype, dependent_name);
07494 return error_mark_node;
07495 }
07496
07497
07498 if (decl_context == PARM)
07499 {
07500 if (declspecs->specs[(int)ds_typedef])
07501 {
07502 error ("typedef declaration invalid in parameter declaration");
07503 return error_mark_node;
07504 }
07505 else if (storage_class == sc_static
07506 || storage_class == sc_extern
07507 || thread_p)
07508 error ("storage class specifiers invalid in parameter declarations");
07509 }
07510
07511
07512 if (virtualp
07513 && (current_class_name == NULL_TREE || decl_context != FIELD))
07514 {
07515 error ("virtual outside class declaration");
07516 virtualp = 0;
07517 }
07518
07519
07520 if (staticp && decl_context == TYPENAME
07521 && declspecs->type
07522 && ANON_AGGR_TYPE_P (declspecs->type))
07523 decl_context = FIELD;
07524
07525
07526
07527 if (thread_p
07528 && ((storage_class
07529 && storage_class != sc_extern
07530 && storage_class != sc_static)
07531 || declspecs->specs[(int)ds_typedef]))
07532 {
07533 error ("multiple storage classes in declaration of %qs", name);
07534 thread_p = false;
07535 }
07536 if (declspecs->conflicting_specifiers_p)
07537 {
07538 error ("conflicting specifiers in declaration of %qs", name);
07539 storage_class = sc_none;
07540 }
07541 else if (decl_context != NORMAL
07542 && ((storage_class != sc_none
07543 && storage_class != sc_mutable)
07544 || thread_p))
07545 {
07546 if ((decl_context == PARM || decl_context == CATCHPARM)
07547 && (storage_class == sc_register
07548 || storage_class == sc_auto))
07549 ;
07550 else if (declspecs->specs[(int)ds_typedef])
07551 ;
07552 else if (decl_context == FIELD
07553
07554 && storage_class == sc_static)
07555
07556
07557 ;
07558 else
07559 {
07560 if (decl_context == FIELD)
07561 error ("storage class specified for %qs", name);
07562 else
07563 {
07564 if (decl_context == PARM || decl_context == CATCHPARM)
07565 error ("storage class specified for parameter %qs", name);
07566 else
07567 error ("storage class specified for typename");
07568 }
07569 if (storage_class == sc_register
07570 || storage_class == sc_auto
07571 || storage_class == sc_extern
07572 || thread_p)
07573 storage_class = sc_none;
07574 }
07575 }
07576 else if (storage_class == sc_extern && initialized
07577 && !funcdef_flag)
07578 {
07579 if (toplevel_bindings_p ())
07580 {
07581
07582
07583 if (!(type_quals & TYPE_QUAL_CONST))
07584 warning (0, "%qs initialized and declared %<extern%>", name);
07585 }
07586 else
07587 error ("%qs has both %<extern%> and initializer", name);
07588 }
07589 else if (storage_class == sc_extern && funcdef_flag
07590 && ! toplevel_bindings_p ())
07591 error ("nested function %qs declared %<extern%>", name);
07592 else if (toplevel_bindings_p ())
07593 {
07594 if (storage_class == sc_auto)
07595 error ("top-level declaration of %qs specifies %<auto%>", name);
07596 }
07597 else if (thread_p
07598 && storage_class != sc_extern
07599 && storage_class != sc_static)
07600 {
07601 error ("function-scope %qs implicitly auto and declared %<__thread%>",
07602 name);
07603 thread_p = false;
07604 }
07605
07606 if (storage_class && friendp)
07607 error ("storage class specifiers invalid in friend function declarations");
07608
07609 if (!id_declarator)
07610 unqualified_id = NULL_TREE;
07611 else
07612 {
07613 unqualified_id = id_declarator->u.id.unqualified_name;
07614 switch (TREE_CODE (unqualified_id))
07615 {
07616 case BIT_NOT_EXPR:
07617 unqualified_id
07618 = constructor_name (TREE_OPERAND (unqualified_id, 0));
07619 break;
07620
07621 case IDENTIFIER_NODE:
07622 case TEMPLATE_ID_EXPR:
07623 break;
07624
07625 default:
07626 gcc_unreachable ();
07627 }
07628 }
07629
07630
07631
07632 for (; declarator; declarator = declarator->declarator)
07633 {
07634 const cp_declarator *inner_declarator;
07635 tree attrs;
07636
07637 if (type == error_mark_node)
07638 return error_mark_node;
07639
07640 attrs = declarator->attributes;
07641 if (attrs)
07642 {
07643 int attr_flags;
07644
07645 attr_flags = 0;
07646 if (declarator == NULL || declarator->kind == cdk_id)
07647 attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
07648 if (declarator->kind == cdk_function)
07649 attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
07650 if (declarator->kind == cdk_array)
07651 attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
07652 returned_attrs = decl_attributes (&type,
07653 chainon (returned_attrs, attrs),
07654 attr_flags);
07655 }
07656
07657 if (declarator->kind == cdk_id)
07658 break;
07659
07660 inner_declarator = declarator->declarator;
07661
07662 switch (declarator->kind)
07663 {
07664 case cdk_array:
07665 type = create_array_type_for_decl (dname, type,
07666 declarator->u.array.bounds);
07667 break;
07668
07669 case cdk_function:
07670 {
07671 tree arg_types;
07672 int funcdecl_p;
07673
07674
07675
07676
07677
07678
07679 type_quals = TYPE_UNQUALIFIED;
07680
07681
07682
07683 if (TREE_CODE (type) == FUNCTION_TYPE)
07684 {
07685 error ("%qs declared as function returning a function", name);
07686 type = integer_type_node;
07687 }
07688 if (TREE_CODE (type) == ARRAY_TYPE)
07689 {
07690 error ("%qs declared as function returning an array", name);
07691 type = integer_type_node;
07692 }
07693
07694
07695 memfn_quals = declarator->u.function.qualifiers;
07696
07697
07698 raises = declarator->u.function.exception_specification;
07699
07700
07701
07702 funcdecl_p = inner_declarator && inner_declarator->kind == cdk_id;
07703
07704 if (ctype == NULL_TREE
07705 && decl_context == FIELD
07706 && funcdecl_p
07707 && (friendp == 0 || dname == current_class_name))
07708 ctype = current_class_type;
07709
07710 if (ctype && (sfk == sfk_constructor
07711 || sfk == sfk_destructor))
07712 {
07713
07714
07715
07716
07717
07718
07719
07720
07721
07722
07723
07724
07725 if (staticp == 2)
07726 error ((flags == DTOR_FLAG)
07727 ? "destructor cannot be static member function"
07728 : "constructor cannot be static member function");
07729 if (memfn_quals)
07730 {
07731 error ((flags == DTOR_FLAG)
07732 ? "destructors may not be cv-qualified"
07733 : "constructors may not be cv-qualified");
07734 memfn_quals = TYPE_UNQUALIFIED;
07735 }
07736
07737 if (decl_context == FIELD
07738 && !member_function_or_else (ctype,
07739 current_class_type,
07740 flags))
07741 return error_mark_node;
07742
07743 if (flags != DTOR_FLAG)
07744 {
07745
07746 if (explicitp == 1)
07747 explicitp = 2;
07748 if (virtualp)
07749 {
07750 pedwarn ("constructors cannot be declared virtual");
07751 virtualp = 0;
07752 }
07753 if (decl_context == FIELD
07754 && sfk != sfk_constructor)
07755 return error_mark_node;
07756 }
07757 if (decl_context == FIELD)
07758 staticp = 0;
07759 }
07760 else if (friendp)
07761 {
07762 if (initialized)
07763 error ("can't initialize friend function %qs", name);
07764 if (virtualp)
07765 {
07766
07767 error ("virtual functions cannot be friends");
07768 friendp = 0;
07769 }
07770 if (decl_context == NORMAL)
07771 error ("friend declaration not in class definition");
07772 if (current_function_decl && funcdef_flag)
07773 error ("can't define friend function %qs in a local "
07774 "class definition",
07775 name);
07776 }
07777
07778 arg_types = grokparms (declarator->u.function.parameters,
07779 &parms);
07780
07781 if (inner_declarator
07782 && inner_declarator->kind == cdk_id
07783 && inner_declarator->u.id.sfk == sfk_destructor
07784 && arg_types != void_list_node)
07785 {
07786 error ("destructors may not have parameters");
07787 arg_types = void_list_node;
07788 parms = NULL_TREE;
07789 }
07790
07791 type = build_function_type (type, arg_types);
07792 }
07793 break;
07794
07795 case cdk_pointer:
07796 case cdk_reference:
07797 case cdk_ptrmem:
07798
07799
07800
07801 if (TREE_CODE (type) == REFERENCE_TYPE)
07802 {
07803 error (declarator->kind == cdk_reference
07804 ? "cannot declare reference to %q#T"
07805 : "cannot declare pointer to %q#T", type);
07806 type = TREE_TYPE (type);
07807 }
07808 else if (VOID_TYPE_P (type))
07809 {
07810 if (declarator->kind == cdk_reference)
07811 error ("cannot declare reference to %q#T", type);
07812 else if (declarator->kind == cdk_ptrmem)
07813 error ("cannot declare pointer to %q#T member", type);
07814 }
07815
07816
07817
07818 type_quals = TYPE_UNQUALIFIED;
07819
07820 if (declarator->kind == cdk_ptrmem
07821 && (TREE_CODE (type) == FUNCTION_TYPE || memfn_quals))
07822 {
07823 memfn_quals |= cp_type_quals (type);
07824 type = build_memfn_type (type,
07825 declarator->u.pointer.class_type,
07826 memfn_quals);
07827 memfn_quals = TYPE_UNQUALIFIED;
07828 }
07829
07830 if (declarator->kind == cdk_reference)
07831 {
07832 if (!VOID_TYPE_P (type))
07833 type = build_reference_type (type);
07834 }
07835 else if (TREE_CODE (type) == METHOD_TYPE)
07836 type = build_ptrmemfunc_type (build_pointer_type (type));
07837 else if (declarator->kind == cdk_ptrmem)
07838 {
07839 gcc_assert (TREE_CODE (declarator->u.pointer.class_type)
07840 != NAMESPACE_DECL);
07841 if (declarator->u.pointer.class_type == error_mark_node)
07842
07843 type = error_mark_node;
07844 else
07845 type = build_ptrmem_type (declarator->u.pointer.class_type,
07846 type);
07847 }
07848 else
07849 type = build_pointer_type (type);
07850
07851
07852
07853
07854 if (declarator->u.pointer.qualifiers)
07855 {
07856 type
07857 = cp_build_qualified_type (type,
07858 declarator->u.pointer.qualifiers);
07859 type_quals = cp_type_quals (type);
07860 }
07861 ctype = NULL_TREE;
07862 break;
07863
07864 case cdk_error:
07865 break;
07866
07867 default:
07868 gcc_unreachable ();
07869 }
07870 }
07871
07872 if (unqualified_id && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR
07873 && TREE_CODE (type) != FUNCTION_TYPE
07874 && TREE_CODE (type) != METHOD_TYPE)
07875 {
07876 error ("template-id %qD used as a declarator",
07877 unqualified_id);
07878 unqualified_id = dname;
07879 }
07880
07881
07882
07883
07884
07885
07886
07887
07888 if (declarator
07889 && declarator->u.id.qualifying_scope
07890 && TYPE_P (declarator->u.id.qualifying_scope))
07891 {
07892 tree t;
07893
07894 ctype = declarator->u.id.qualifying_scope;
07895 ctype = TYPE_MAIN_VARIANT (ctype);
07896 t = ctype;
07897 while (t != NULL_TREE && CLASS_TYPE_P (t))
07898 {
07899
07900
07901
07902
07903
07904
07905
07906
07907
07908
07909 if (CLASSTYPE_TEMPLATE_SPECIALIZATION (t)
07910 && !any_dependent_template_arguments_p (CLASSTYPE_TI_ARGS (t)))
07911
07912
07913
07914 break;
07915 if ((CLASSTYPE_USE_TEMPLATE (t) || CLASSTYPE_IS_TEMPLATE (t))
07916 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)))
07917 template_count += 1;
07918
07919 t = TYPE_MAIN_DECL (t);
07920 t = DECL_CONTEXT (t);
07921 }
07922
07923 if (ctype == current_class_type)
07924 {
07925 if (friendp)
07926 pedwarn ("member functions are implicitly friends of their class");
07927 else
07928 pedwarn ("extra qualification %<%T::%> on member %qs",
07929 ctype, name);
07930 }
07931 else if (
07932
07933 !COMPLETE_TYPE_P (ctype)
07934 && (
07935
07936 funcdef_flag
07937
07938
07939
07940
07941 || (!friendp && !CLASS_TYPE_P (ctype))
07942
07943
07944
07945
07946
07947 || !(dependent_type_p (ctype)
07948 || currently_open_class (ctype)))
07949
07950 && !complete_type_or_else (ctype, NULL_TREE))
07951 return error_mark_node;
07952 else if (TREE_CODE (type) == FUNCTION_TYPE)
07953 {
07954 tree sname = declarator->u.id.unqualified_name;
07955
07956 if (current_class_type
07957 && (!friendp || funcdef_flag))
07958 {
07959 error (funcdef_flag
07960 ? "cannot define member function %<%T::%s%> within %<%T%>"
07961 : "cannot declare member function %<%T::%s%> within %<%T%>",
07962 ctype, name, current_class_type);
07963 return error_mark_node;
07964 }
07965
07966 if (TREE_CODE (sname) == IDENTIFIER_NODE
07967 && NEW_DELETE_OPNAME_P (sname))
07968
07969
07970 ;
07971 else
07972 type = build_memfn_type (type, ctype, memfn_quals);
07973 }
07974 else if (declspecs->specs[(int)ds_typedef]
07975 && current_class_type)
07976 {
07977 error ("cannot declare member %<%T::%s%> within %qT",
07978 ctype, name, current_class_type);
07979 return error_mark_node;
07980 }
07981 }
07982
07983
07984
07985 if (returned_attrs)
07986 {
07987 if (attrlist)
07988 *attrlist = chainon (returned_attrs, *attrlist);
07989 else
07990 attrlist = &returned_attrs;
07991 }
07992
07993
07994
07995 if (TREE_CODE (type) == ARRAY_TYPE
07996 && COMPLETE_TYPE_P (type)
07997 && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST
07998 && TREE_OVERFLOW (TYPE_SIZE_UNIT (type)))
07999 {
08000 error ("size of array %qs is too large", name);
08001
08002
08003 type = error_mark_node;
08004 }
08005
08006 if ((decl_context == FIELD || decl_context == PARM)
08007 && !processing_template_decl
08008 && variably_modified_type_p (type, NULL_TREE))
08009 {
08010 if (decl_context == FIELD)
08011 error ("data member may not have variably modified type %qT", type);
08012 else
08013 error ("parameter may not have variably modified type %qT", type);
08014 type = error_mark_node;
08015 }
08016
08017 if (explicitp == 1 || (explicitp && friendp))
08018 {
08019
08020
08021 error ("only declarations of constructors can be %<explicit%>");
08022 explicitp = 0;
08023 }
08024
08025 if (storage_class == sc_mutable)
08026 {
08027 if (decl_context != FIELD || friendp)
08028 {
08029 error ("non-member %qs cannot be declared %<mutable%>", name);
08030 storage_class = sc_none;
08031 }
08032 else if (decl_context == TYPENAME || declspecs->specs[(int)ds_typedef])
08033 {
08034 error ("non-object member %qs cannot be declared %<mutable%>", name);
08035 storage_class = sc_none;
08036 }
08037 else if (TREE_CODE (type) == FUNCTION_TYPE
08038 || TREE_CODE (type) == METHOD_TYPE)
08039 {
08040 error ("function %qs cannot be declared %<mutable%>", name);
08041 storage_class = sc_none;
08042 }
08043 else if (staticp)
08044 {
08045 error ("static %qs cannot be declared %<mutable%>", name);
08046 storage_class = sc_none;
08047 }
08048 else if (type_quals & TYPE_QUAL_CONST)
08049 {
08050 error ("const %qs cannot be declared %<mutable%>", name);
08051 storage_class = sc_none;
08052 }
08053 }
08054
08055
08056 if (declspecs->specs[(int)ds_typedef] && decl_context != TYPENAME)
08057 {
08058 tree decl;
08059
08060
08061
08062 if (current_lang_name == lang_name_java)
08063 TYPE_FOR_JAVA (type) = 1;
08064
08065
08066
08067
08068
08069
08070
08071
08072
08073
08074 if (memfn_quals && TREE_CODE (type) == FUNCTION_TYPE)
08075 type = cp_build_qualified_type (type, memfn_quals);
08076
08077 if (decl_context == FIELD)
08078 decl = build_lang_decl (TYPE_DECL, unqualified_id, type);
08079 else
08080 decl = build_decl (TYPE_DECL, unqualified_id, type);
08081 if (id_declarator && declarator->u.id.qualifying_scope)
08082 error ("%Jtypedef name may not be a nested-name-specifier", decl);
08083
08084 if (decl_context != FIELD)
08085 {
08086 if (!current_function_decl)
08087 DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
08088 else if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (current_function_decl)
08089 || (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P
08090 (current_function_decl)))
08091
08092
08093
08094
08095 DECL_ABSTRACT (decl) = 1;
08096 }
08097 else if (constructor_name_p (unqualified_id, current_class_type))
08098 pedwarn ("ISO C++ forbids nested type %qD with same name "
08099 "as enclosing class",
08100 unqualified_id);
08101
08102
08103
08104
08105
08106 if (type != error_mark_node
08107 && unqualified_id
08108 && TYPE_NAME (type)
08109 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
08110 && TYPE_ANONYMOUS_P (type)
08111
08112 && (!attrlist || !*attrlist)
08113 && cp_type_quals (type) == TYPE_UNQUALIFIED)
08114 {
08115 tree oldname = TYPE_NAME (type);
08116 tree t;
08117
08118
08119 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
08120 if (TYPE_NAME (t) == oldname)
08121 TYPE_NAME (t) = decl;
08122
08123 if (TYPE_LANG_SPECIFIC (type))
08124 TYPE_WAS_ANONYMOUS (type) = 1;
08125
08126
08127
08128
08129 if (TYPE_LANG_SPECIFIC (type) && CLASSTYPE_TEMPLATE_INFO (type))
08130 DECL_NAME (CLASSTYPE_TI_TEMPLATE (type))
08131 = TYPE_IDENTIFIER (type);
08132
08133
08134
08135 }
08136
08137
08138
08139 if (memfn_quals && !ctype && TREE_CODE (type) == FUNCTION_TYPE)
08140 memfn_quals = TYPE_UNQUALIFIED;
08141
08142 if (signed_p
08143 || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
08144 C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
08145
08146 bad_specifiers (decl, "type", virtualp,
08147 memfn_quals != TYPE_UNQUALIFIED,
08148 inlinep, friendp, raises != NULL_TREE);
08149
08150 return decl;
08151 }
08152
08153
08154
08155
08156
08157
08158 if (type && typedef_type
08159 && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type)
08160 && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type))
08161 type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
08162
08163
08164
08165
08166 if (type == typedef_type && TREE_CODE (type) == FUNCTION_TYPE)
08167 {
08168 tree decls = NULL_TREE;
08169 tree args;
08170
08171 for (args = TYPE_ARG_TYPES (type); args; args = TREE_CHAIN (args))
08172 {
08173 tree decl = cp_build_parm_decl (NULL_TREE, TREE_VALUE (args));
08174
08175 TREE_CHAIN (decl) = decls;
08176 decls = decl;
08177 }
08178
08179 parms = nreverse (decls);
08180
08181 if (decl_context != TYPENAME)
08182 {
08183
08184
08185 if (cp_type_quals (type) != TYPE_UNQUALIFIED
08186 && (current_class_type == NULL_TREE || staticp) )
08187 {
08188 error ("qualified function types cannot be used to declare %s functions",
08189 (staticp? "static member" : "free"));
08190 type = TYPE_MAIN_VARIANT (type);
08191 }
08192
08193
08194
08195 memfn_quals |= cp_type_quals (type);
08196 }
08197 }
08198
08199
08200
08201
08202 if (decl_context == TYPENAME)
08203 {
08204
08205
08206 if (type_quals != TYPE_UNQUALIFIED)
08207 type_quals = TYPE_UNQUALIFIED;
08208
08209
08210 if (friendp)
08211 {
08212 if (type_quals != TYPE_UNQUALIFIED)
08213 {
08214 error ("type qualifiers specified for friend class declaration");
08215 type_quals = TYPE_UNQUALIFIED;
08216 }
08217 if (inlinep)
08218 {
08219 error ("%<inline%> specified for friend class declaration");
08220 inlinep = 0;
08221 }
08222
08223 if (!current_aggr)
08224 {
08225
08226 if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
08227 pedwarn ("template parameters cannot be friends");
08228 else if (TREE_CODE (type) == TYPENAME_TYPE)
08229 pedwarn ("friend declaration requires class-key, "
08230 "i.e. %<friend class %T::%D%>",
08231 TYPE_CONTEXT (type), TYPENAME_TYPE_FULLNAME (type));
08232 else
08233 pedwarn ("friend declaration requires class-key, "
08234 "i.e. %<friend %#T%>",
08235 type);
08236 }
08237
08238
08239 if (type != integer_type_node)
08240 {
08241
08242 if (current_class_type)
08243 make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type),
08244 true);
08245 else
08246 error ("trying to make class %qT a friend of global scope",
08247 type);
08248
08249 type = void_type_node;
08250 }
08251 }
08252 else if (memfn_quals)
08253 {
08254 if (ctype == NULL_TREE)
08255 {
08256 if (TREE_CODE (type) != METHOD_TYPE)
08257 error ("invalid qualifiers on non-member function type");
08258 else
08259 ctype = TYPE_METHOD_BASETYPE (type);
08260 }
08261 if (ctype)
08262 type = build_memfn_type (type, ctype, memfn_quals);
08263 }
08264
08265 return type;
08266 }
08267 else if (unqualified_id == NULL_TREE && decl_context != PARM
08268 && decl_context != CATCHPARM
08269 && TREE_CODE (type) != UNION_TYPE
08270 && ! bitfield)
08271 {
08272 error ("abstract declarator %qT used as declaration", type);
08273 return error_mark_node;
08274 }
08275
08276
08277 if (unqualified_id
08278 && IDENTIFIER_OPNAME_P (unqualified_id)
08279 && TREE_CODE (type) != FUNCTION_TYPE
08280 && TREE_CODE (type) != METHOD_TYPE)
08281 {
08282 error ("declaration of %qD as non-function", unqualified_id);
08283 return error_mark_node;
08284 }
08285
08286
08287
08288 if (decl_context != PARM)
08289 {
08290 type = check_var_type (unqualified_id, type);
08291 if (type == error_mark_node)
08292 return error_mark_node;
08293 }
08294
08295
08296
08297
08298 if (decl_context == PARM || decl_context == CATCHPARM)
08299 {
08300 if (ctype || in_namespace)
08301 error ("cannot use %<::%> in parameter declaration");
08302
08303
08304
08305
08306
08307 if (TREE_CODE (type) == ARRAY_TYPE)
08308 {
08309
08310 type = build_pointer_type (TREE_TYPE (type));
08311 type_quals = TYPE_UNQUALIFIED;
08312 }
08313 else if (TREE_CODE (type) == FUNCTION_TYPE)
08314 type = build_pointer_type (type);
08315 }
08316
08317 {
08318 tree decl;
08319
08320 if (decl_context == PARM)
08321 {
08322 decl = cp_build_parm_decl (unqualified_id, type);
08323
08324 bad_specifiers (decl, "parameter", virtualp,
08325 memfn_quals != TYPE_UNQUALIFIED,
08326 inlinep, friendp, raises != NULL_TREE);
08327 }
08328 else if (decl_context == FIELD)
08329 {
08330
08331 if (!staticp && TREE_CODE (type) == ARRAY_TYPE
08332 && TYPE_DOMAIN (type) == NULL_TREE)
08333 {
08334 tree itype = compute_array_index_type (dname, integer_zero_node);
08335 type = build_cplus_array_type (TREE_TYPE (type), itype);
08336 }
08337
08338 if (type == error_mark_node)
08339 {
08340
08341
08342 decl = NULL_TREE;
08343 }
08344 else if (in_namespace && !friendp)
08345 {
08346
08347 error ("invalid use of %<::%>");
08348 return error_mark_node;
08349 }
08350 else if (TREE_CODE (type) == FUNCTION_TYPE)
08351 {
08352 int publicp = 0;
08353 tree function_context;
08354
08355 if (friendp == 0)
08356 {
08357 if (ctype == NULL_TREE)
08358 ctype = current_class_type;
08359
08360 if (ctype == NULL_TREE)
08361 {
08362 error ("can't make %qD into a method -- not in a class",
08363 unqualified_id);
08364 return error_mark_node;
08365 }
08366
08367
08368
08369 if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
08370 {
08371 error ("function %qD declared virtual inside a union",
08372 unqualified_id);
08373 return error_mark_node;
08374 }
08375
08376 if (NEW_DELETE_OPNAME_P (unqualified_id))
08377 {
08378 if (virtualp)
08379 {
08380 error ("%qD cannot be declared virtual, since it "
08381 "is always static",
08382 unqualified_id);
08383 virtualp = 0;
08384 }
08385 }
08386 else if (staticp < 2)
08387 type = build_memfn_type (type, ctype, memfn_quals);
08388 }
08389
08390
08391 if (sfk == sfk_destructor)
08392 {
08393 if (!ctype)
08394 {
08395 gcc_assert (friendp);
08396 error ("expected qualified name in friend declaration "
08397 "for destructor %qD",
08398 id_declarator->u.id.unqualified_name);
08399 return error_mark_node;
08400 }
08401
08402 if (!same_type_p (TREE_OPERAND
08403 (id_declarator->u.id.unqualified_name, 0),
08404 ctype))
08405 {
08406 error ("declaration of %qD as member of %qT",
08407 id_declarator->u.id.unqualified_name, ctype);
08408 return error_mark_node;
08409 }
08410 }
08411
08412
08413 function_context = (ctype != NULL_TREE) ?
08414 decl_function_context (TYPE_MAIN_DECL (ctype)) : NULL_TREE;
08415 publicp = (! friendp || ! staticp)
08416 && function_context == NULL_TREE;
08417 decl = grokfndecl (ctype, type,
08418 TREE_CODE (unqualified_id) != TEMPLATE_ID_EXPR
08419 ? unqualified_id : dname,
08420 parms,
08421 unqualified_id,
08422 virtualp, flags, memfn_quals, raises,
08423 friendp ? -1 : 0, friendp, publicp, inlinep,
08424 sfk,
08425 funcdef_flag, template_count, in_namespace, attrlist);
08426 if (decl == NULL_TREE)
08427 return error_mark_node;
08428 #if 0
08429
08430
08431 decl = build_decl_attribute_variant (decl, decl_attr);
08432 #endif
08433
08434
08435
08436
08437
08438
08439
08440
08441 if (explicitp == 2)
08442 DECL_NONCONVERTING_P (decl) = 1;
08443 else if (DECL_CONSTRUCTOR_P (decl))
08444 {
08445
08446
08447
08448
08449 tree arg_types = FUNCTION_FIRST_USER_PARMTYPE (decl);
08450
08451 if (arg_types == void_list_node
08452 || (arg_types
08453 && TREE_CHAIN (arg_types)
08454 && TREE_CHAIN (arg_types) != void_list_node
08455 && !TREE_PURPOSE (TREE_CHAIN (arg_types))))
08456 DECL_NONCONVERTING_P (decl) = 1;
08457 }
08458 }
08459 else if (TREE_CODE (type) == METHOD_TYPE)
08460 {
08461
08462
08463
08464
08465 decl = grokfndecl (ctype, type,
08466 TREE_CODE (unqualified_id) != TEMPLATE_ID_EXPR
08467 ? unqualified_id : dname,
08468 parms,
08469 unqualified_id,
08470 virtualp, flags, memfn_quals, raises,
08471 friendp ? -1 : 0, friendp, 1, 0, sfk,
08472 funcdef_flag, template_count, in_namespace,
08473 attrlist);
08474 if (decl == NULL_TREE)
08475 return error_mark_node;
08476 }
08477 else if (!staticp && !dependent_type_p (type)
08478 && !COMPLETE_TYPE_P (complete_type (type))
08479 && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0))
08480 {
08481 if (unqualified_id)
08482 error ("field %qD has incomplete type", unqualified_id);
08483 else
08484 error ("name %qT has incomplete type", type);
08485
08486
08487
08488 if (current_class_type
08489 && TYPE_NAME (current_class_type)
08490 && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (current_class_type))
08491 && declspecs->type
08492 && declspecs->type == type)
08493 error (" in instantiation of template %qT",
08494 current_class_type);
08495
08496 return error_mark_node;
08497 }
08498 else
08499 {
08500 if (friendp)
08501 {
08502 error ("%qE is neither function nor member function; "
08503 "cannot be declared friend", unqualified_id);
08504 friendp = 0;
08505 }
08506 decl = NULL_TREE;
08507 }
08508
08509 if (friendp)
08510 {
08511
08512 if (ctype == current_class_type)
08513 ;
08514 else if (decl && DECL_NAME (decl))
08515 {
08516 if (template_class_depth (current_class_type) == 0)
08517 {
08518 decl = check_explicit_specialization
08519 (unqualified_id, decl, template_count,
08520 2 * funcdef_flag + 4);
08521 if (decl == error_mark_node)
08522 return error_mark_node;
08523 }
08524
08525 decl = do_friend (ctype, unqualified_id, decl,
08526 *attrlist, flags,
08527 funcdef_flag);
08528 return decl;
08529 }
08530 else
08531 return error_mark_node;
08532 }
08533
08534
08535
08536 if (decl == NULL_TREE)
08537 {
08538 if (initialized)
08539 {
08540 if (!staticp)
08541 {
08542
08543
08544
08545
08546
08547
08548
08549
08550
08551
08552
08553
08554 pedwarn ("ISO C++ forbids initialization of member %qD",
08555 unqualified_id);
08556 pedwarn ("making %qD static", unqualified_id);
08557 staticp = 1;
08558 }
08559
08560 if (uses_template_parms (type))
08561
08562 ;
08563 else if (check_static_variable_definition (unqualified_id,
08564 type))
08565
08566
08567
08568
08569
08570 return error_mark_node;
08571 }
08572
08573 if (staticp)
08574 {
08575
08576
08577 decl = build_lang_decl (VAR_DECL, unqualified_id, type);
08578 set_linkage_for_static_data_member (decl);
08579
08580
08581
08582 DECL_EXTERNAL (decl) = 1;
08583
08584 if (thread_p)
08585 {
08586 if (targetm.have_tls)
08587 DECL_TLS_MODEL (decl) = decl_default_tls_model (decl);
08588 else
08589
08590
08591
08592 error ("thread-local storage not supported for this target");
08593 }
08594 }
08595 else
08596 {
08597 decl = build_decl (FIELD_DECL, unqualified_id, type);
08598 DECL_NONADDRESSABLE_P (decl) = bitfield;
08599 if (storage_class == sc_mutable)
08600 {
08601 DECL_MUTABLE_P (decl) = 1;
08602 storage_class = sc_none;
08603 }
08604 }
08605
08606 bad_specifiers (decl, "field", virtualp,
08607 memfn_quals != TYPE_UNQUALIFIED,
08608 inlinep, friendp, raises != NULL_TREE);
08609 }
08610 }
08611 else if (TREE_CODE (type) == FUNCTION_TYPE
08612 || TREE_CODE (type) == METHOD_TYPE)
08613 {
08614 tree original_name;
08615 int publicp = 0;
08616
08617 if (!unqualified_id)
08618 return error_mark_node;
08619
08620 if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
08621 original_name = dname;
08622 else
08623 original_name = unqualified_id;
08624
08625 if (storage_class == sc_auto)
08626 error ("storage class %<auto%> invalid for function %qs", name);
08627 else if (storage_class == sc_register)
08628 error ("storage class %<register%> invalid for function %qs", name);
08629 else if (thread_p)
08630 error ("storage class %<__thread%> invalid for function %qs", name);
08631
08632
08633
08634
08635 if (! toplevel_bindings_p ()
08636 && (storage_class == sc_static
08637 || declspecs->specs[(int)ds_inline])
08638 && pedantic)
08639 {
08640 if (storage_class == sc_static)
08641 pedwarn ("%<static%> specified invalid for function %qs "
08642 "declared out of global scope", name);
08643 else
08644 pedwarn ("%<inline%> specifier invalid for function %qs "
08645 "declared out of global scope", name);
08646 }
08647
08648 if (ctype == NULL_TREE)
08649 {
08650 if (virtualp)
08651 {
08652 error ("virtual non-class function %qs", name);
08653 virtualp = 0;
08654 }
08655 }
08656 else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2
08657 && !NEW_DELETE_OPNAME_P (original_name))
08658 type = build_method_type_directly (ctype,
08659 TREE_TYPE (type),
08660 TYPE_ARG_TYPES (type));
08661
08662
08663 publicp = (ctype != NULL_TREE
08664 || storage_class == sc_extern
08665 || storage_class != sc_static);
08666
08667 decl = grokfndecl (ctype, type, original_name, parms, unqualified_id,
08668 virtualp, flags, memfn_quals, raises,
08669 1, friendp,
08670 publicp, inlinep, sfk, funcdef_flag,
08671 template_count, in_namespace, attrlist);
08672 if (decl == NULL_TREE)
08673 return error_mark_node;
08674
08675 if (staticp == 1)
08676 {
08677 int invalid_static = 0;
08678
08679
08680
08681 if (TREE_CODE (type) == METHOD_TYPE)
08682 {
08683 pedwarn ("cannot declare member function %qD to have "
08684 "static linkage", decl);
08685 invalid_static = 1;
08686 }
08687 else if (current_function_decl)
08688 {
08689
08690 error ("cannot declare static function inside another function");
08691 invalid_static = 1;
08692 }
08693
08694 if (invalid_static)
08695 {
08696 staticp = 0;
08697 storage_class = sc_none;
08698 }
08699 }
08700 }
08701 else
08702 {
08703
08704
08705
08706 decl = grokvardecl (type, unqualified_id,
08707 declspecs,
08708 initialized,
08709 (type_quals & TYPE_QUAL_CONST) != 0,
08710 ctype ? ctype : in_namespace);
08711 bad_specifiers (decl, "variable", virtualp,
08712 memfn_quals != TYPE_UNQUALIFIED,
08713 inlinep, friendp, raises != NULL_TREE);
08714
08715 if (ctype)
08716 {
08717 DECL_CONTEXT (decl) = ctype;
08718 if (staticp == 1)
08719 {
08720 pedwarn ("%<static%> may not be used when defining "
08721 "(as opposed to declaring) a static data member");
08722 staticp = 0;
08723 storage_class = sc_none;
08724 }
08725 if (storage_class == sc_register && TREE_STATIC (decl))
08726 {
08727 error ("static member %qD declared %<register%>", decl);
08728 storage_class = sc_none;
08729 }
08730 if (storage_class == sc_extern && pedantic)
08731 {
08732 pedwarn ("cannot explicitly declare member %q#D to have "
08733 "extern linkage",
08734 decl);
08735 storage_class = sc_none;
08736 }
08737 }
08738 }
08739
08740
08741
08742
08743 if (storage_class == sc_register)
08744 DECL_REGISTER (decl) = 1;
08745 else if (storage_class == sc_extern)
08746 DECL_THIS_EXTERN (decl) = 1;
08747 else if (storage_class == sc_static)
08748 DECL_THIS_STATIC (decl) = 1;
08749
08750
08751
08752
08753 if (!processing_template_decl)
08754 cp_apply_type_quals_to_decl (type_quals, decl);
08755
08756 return decl;
08757 }
08758 }
08759
08760
08761
08762
08763
08764 static void
08765 require_complete_types_for_parms (tree parms)
08766 {
08767 for (; parms; parms = TREE_CHAIN (parms))
08768 {
08769 if (dependent_type_p (TREE_TYPE (parms)))
08770 continue;
08771 if (!VOID_TYPE_P (TREE_TYPE (parms))
08772 && complete_type_or_else (TREE_TYPE (parms), parms))
08773 {
08774 relayout_decl (parms);
08775 DECL_ARG_TYPE (parms) = type_passed_as (TREE_TYPE (parms));
08776 }
08777 else
08778
08779
08780 TREE_TYPE (parms) = error_mark_node;
08781 }
08782 }
08783
08784
08785
08786 int
08787 local_variable_p (tree t)
08788 {
08789 if ((TREE_CODE (t) == VAR_DECL
08790
08791
08792 && !TYPE_P (CP_DECL_CONTEXT (t))
08793
08794 && !DECL_NAMESPACE_SCOPE_P (t))
08795 || (TREE_CODE (t) == PARM_DECL))
08796 return 1;
08797
08798 return 0;
08799 }
08800
08801
08802
08803
08804
08805 int
08806 nonstatic_local_decl_p (tree t)
08807 {
08808 return ((local_variable_p (t) && !TREE_STATIC (t))
08809 || TREE_CODE (t) == LABEL_DECL
08810 || TREE_CODE (t) == RESULT_DECL);
08811 }
08812
08813
08814
08815
08816 static tree
08817 local_variable_p_walkfn (tree *tp, int *walk_subtrees,
08818 void *data ATTRIBUTE_UNUSED)
08819 {
08820 if (local_variable_p (*tp) && !DECL_ARTIFICIAL (*tp))
08821 return *tp;
08822 else if (TYPE_P (*tp))
08823 *walk_subtrees = 0;
08824
08825 return NULL_TREE;
08826 }
08827
08828
08829
08830
08831
08832
08833
08834 tree
08835 check_default_argument (tree decl, tree arg)
08836 {
08837 tree var;
08838 tree decl_type;
08839
08840 if (TREE_CODE (arg) == DEFAULT_ARG)
08841
08842
08843
08844 return arg;
08845
08846 if (TYPE_P (decl))
08847 {
08848 decl_type = decl;
08849 decl = NULL_TREE;
08850 }
08851 else
08852 decl_type = TREE_TYPE (decl);
08853
08854 if (arg == error_mark_node
08855 || decl == error_mark_node
08856 || TREE_TYPE (arg) == error_mark_node
08857 || decl_type == error_mark_node)
08858
08859
08860 return error_mark_node;
08861
08862
08863
08864
08865
08866 if (!TREE_TYPE (arg)
08867 || !can_convert_arg (decl_type, TREE_TYPE (arg), arg, LOOKUP_NORMAL))
08868 {
08869 if (decl)
08870 error ("default argument for %q#D has type %qT",
08871 decl, TREE_TYPE (arg));
08872 else
08873 error ("default argument for parameter of type %qT has type %qT",
08874 decl_type, TREE_TYPE (arg));
08875
08876 return error_mark_node;
08877 }
08878
08879
08880
08881
08882
08883
08884
08885
08886 var = walk_tree_without_duplicates (&arg, local_variable_p_walkfn,
08887 NULL);
08888 if (var)
08889 {
08890 error ("default argument %qE uses local variable %qD", arg, var);
08891 return error_mark_node;
08892 }
08893
08894
08895 return arg;
08896 }
08897
08898
08899
08900
08901
08902
08903
08904
08905
08906
08907 static tree
08908 grokparms (cp_parameter_declarator *first_parm, tree *parms)
08909 {
08910 tree result = NULL_TREE;
08911 tree decls = NULL_TREE;
08912 int ellipsis = !first_parm || first_parm->ellipsis_p;
08913 cp_parameter_declarator *parm;
08914 int any_error = 0;
08915
08916 for (parm = first_parm; parm != NULL; parm = parm->next)
08917 {
08918 tree type = NULL_TREE;
08919 tree init = parm->default_argument;
08920 tree attrs;
08921 tree decl;
08922
08923 if (parm == no_parameters)
08924 break;
08925
08926 attrs = parm->decl_specifiers.attributes;
08927 parm->decl_specifiers.attributes = NULL_TREE;
08928 decl = grokdeclarator (parm->declarator, &parm->decl_specifiers,
08929 PARM, init != NULL_TREE, &attrs);
08930 if (! decl || TREE_TYPE (decl) == error_mark_node)
08931 continue;
08932
08933 if (attrs)
08934 cplus_decl_attributes (&decl, attrs, 0);
08935
08936 type = TREE_TYPE (decl);
08937 if (VOID_TYPE_P (type))
08938 {
08939 if (same_type_p (type, void_type_node)
08940 && DECL_SELF_REFERENCE_P (type)
08941 && !DECL_NAME (decl) && !result && !parm->next && !ellipsis)
08942
08943 break;
08944 cxx_incomplete_type_error (decl, type);
08945
08946
08947
08948 type = error_mark_node;
08949 TREE_TYPE (decl) = error_mark_node;
08950 }
08951
08952 if (type != error_mark_node)
08953 {
08954
08955
08956 type = cp_build_qualified_type (type, 0);
08957 if (TREE_CODE (type) == METHOD_TYPE)
08958 {
08959 error ("parameter %qD invalidly declared method type", decl);
08960 type = build_pointer_type (type);
08961 TREE_TYPE (decl) = type;
08962 }
08963 else if (abstract_virtuals_error (decl, type))
08964 any_error = 1;
08965 else if (POINTER_TYPE_P (type))
08966 {
08967
08968
08969 tree t = TREE_TYPE (type);
08970 int ptr = TYPE_PTR_P (type);
08971
08972 while (1)
08973 {
08974 if (TYPE_PTR_P (t))
08975 ptr = 1;
08976 else if (TREE_CODE (t) != ARRAY_TYPE)
08977 break;
08978 else if (!TYPE_DOMAIN (t))
08979 break;
08980 t = TREE_TYPE (t);
08981 }
08982 if (TREE_CODE (t) == ARRAY_TYPE)
08983 error ("parameter %qD includes %s to array of unknown "
08984 "bound %qT",
08985 decl, ptr ? "pointer" : "reference", t);
08986 }
08987
08988 if (any_error)
08989 init = NULL_TREE;
08990 else if (init && !processing_template_decl)
08991 init = check_default_argument (decl, init);
08992 }
08993
08994 TREE_CHAIN (decl) = decls;
08995 decls = decl;
08996 result = tree_cons (init, type, result);
08997 }
08998 decls = nreverse (decls);
08999 result = nreverse (result);
09000 if (!ellipsis)
09001 result = chainon (result, void_list_node);
09002 *parms = decls;
09003
09004 return result;
09005 }
09006
09007
09008
09009 #ifdef KEY
09010
09011 int (*p_copy_fn_p) (tree) = copy_fn_p;
09012 #endif
09013
09014
09015
09016
09017
09018
09019
09020
09021
09022
09023
09024
09025
09026
09027
09028
09029
09030
09031
09032 int
09033 copy_fn_p (tree d)
09034 {
09035 tree args;
09036 tree arg_type;
09037 int result = 1;
09038
09039 gcc_assert (DECL_FUNCTION_MEMBER_P (d));
09040
09041 if (TREE_CODE (d) == TEMPLATE_DECL
09042 || (DECL_TEMPLATE_INFO (d)
09043 && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (d))))
09044
09045
09046
09047
09048 return 0;
09049
09050 args = FUNCTION_FIRST_USER_PARMTYPE (d);
09051 if (!args)
09052 return 0;
09053
09054 arg_type = TREE_VALUE (args);
09055 if (arg_type == error_mark_node)
09056 return 0;
09057
09058 if (TYPE_MAIN_VARIANT (arg_type) == DECL_CONTEXT (d))
09059 {
09060
09061 result = -1;
09062 }
09063 else if (TREE_CODE (arg_type) == REFERENCE_TYPE
09064 && TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)) == DECL_CONTEXT (d))
09065 {
09066 if (CP_TYPE_CONST_P (TREE_TYPE (arg_type)))
09067 result = 2;
09068 }
09069 else
09070 return 0;
09071
09072 args = TREE_CHAIN (args);
09073
09074 if (args && args != void_list_node && !TREE_PURPOSE (args))
09075
09076 return 0;
09077
09078 return result;
09079 }
09080
09081
09082
09083 void grok_special_member_properties (tree decl)
09084 {
09085 tree class_type;
09086
09087 if (!DECL_NONSTATIC_MEMBER_FUNCTION_P (decl))
09088 return;
09089
09090 class_type = DECL_CONTEXT (decl);
09091 if (DECL_CONSTRUCTOR_P (decl))
09092 {
09093 int ctor = copy_fn_p (decl);
09094
09095 TYPE_HAS_CONSTRUCTOR (class_type) = 1;
09096
09097 if (ctor > 0)
09098 {
09099
09100
09101
09102
09103
09104
09105
09106 TYPE_HAS_INIT_REF (class_type) = 1;
09107 if (ctor > 1)
09108 TYPE_HAS_CONST_INIT_REF (class_type) = 1;
09109 }
09110 else if (sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (decl)))
09111 TYPE_HAS_DEFAULT_CONSTRUCTOR (class_type) = 1;
09112 }
09113 else if (DECL_OVERLOADED_OPERATOR_P (decl) == NOP_EXPR)
09114 {
09115
09116
09117
09118
09119
09120
09121 int assop = copy_fn_p (decl);
09122
09123 if (assop)
09124 {
09125 TYPE_HAS_ASSIGN_REF (class_type) = 1;
09126 if (assop != 1)
09127 TYPE_HAS_CONST_ASSIGN_REF (class_type) = 1;
09128 }
09129 }
09130 }
09131
09132
09133
09134
09135 int
09136 grok_ctor_properties (tree ctype, tree decl)
09137 {
09138 int ctor_parm = copy_fn_p (decl);
09139
09140 if (ctor_parm < 0)
09141 {
09142
09143
09144
09145
09146
09147
09148
09149
09150
09151
09152
09153
09154
09155
09156
09157 error ("invalid constructor; you probably meant %<%T (const %T&)%>",
09158 ctype, ctype);
09159 return 0;
09160 }
09161
09162 return 1;
09163 }
09164
09165
09166
09167 static int
09168 ambi_op_p (enum tree_code code)
09169 {
09170 return (code == INDIRECT_REF
09171 || code == ADDR_EXPR
09172 || code == UNARY_PLUS_EXPR
09173 || code == NEGATE_EXPR
09174 || code == PREINCREMENT_EXPR
09175 || code == PREDECREMENT_EXPR);
09176 }
09177
09178
09179
09180 static int
09181 unary_op_p (enum tree_code code)
09182 {
09183 return (code == TRUTH_NOT_EXPR
09184 || code == BIT_NOT_EXPR
09185 || code == COMPONENT_REF
09186 || code == TYPE_EXPR);
09187 }
09188
09189
09190
09191
09192 bool
09193 grok_op_properties (tree decl, bool complain)
09194 {
09195 tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
09196 tree argtype;
09197 int methodp = (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE);
09198 tree name = DECL_NAME (decl);
09199 enum tree_code operator_code;
09200 int arity;
09201 bool ellipsis_p;
09202 tree class_type;
09203
09204
09205 for (argtype = argtypes, arity = 0;
09206 argtype && argtype != void_list_node;
09207 argtype = TREE_CHAIN (argtype))
09208 ++arity;
09209 ellipsis_p = !argtype;
09210
09211 class_type = DECL_CONTEXT (decl);
09212 if (class_type && !CLASS_TYPE_P (class_type))
09213 class_type = NULL_TREE;
09214
09215 if (DECL_CONV_FN_P (decl))
09216 operator_code = TYPE_EXPR;
09217 else
09218 do
09219 {
09220 #define DEF_OPERATOR(NAME, CODE, MANGLING, ARITY, ASSN_P) \
09221 if (ansi_opname (CODE) == name) \
09222 { \
09223 operator_code = (CODE); \
09224 break; \
09225 } \
09226 else if (ansi_assopname (CODE) == name) \
09227 { \
09228 operator_code = (CODE); \
09229 DECL_ASSIGNMENT_OPERATOR_P (decl) = 1; \
09230 break; \
09231 }
09232
09233 #include "operators.def"
09234 #undef DEF_OPERATOR
09235
09236 gcc_unreachable ();
09237 }
09238 while (0);
09239 gcc_assert (operator_code != LAST_CPLUS_TREE_CODE);
09240 SET_OVERLOADED_OPERATOR_CODE (decl, operator_code);
09241
09242 if (class_type)
09243 switch (operator_code)
09244 {
09245 case NEW_EXPR:
09246 TYPE_HAS_NEW_OPERATOR (class_type) = 1;
09247 break;
09248
09249 case DELETE_EXPR:
09250 TYPE_GETS_DELETE (class_type) |= 1;
09251 break;
09252
09253 case VEC_NEW_EXPR:
09254 TYPE_HAS_ARRAY_NEW_OPERATOR (class_type) = 1;
09255 break;
09256
09257 case VEC_DELETE_EXPR:
09258 TYPE_GETS_DELETE (class_type) |= 2;
09259 break;
09260
09261 default:
09262 break;
09263 }
09264
09265
09266
09267
09268
09269
09270
09271
09272 if (operator_code == NEW_EXPR || operator_code == VEC_NEW_EXPR
09273 || operator_code == DELETE_EXPR || operator_code == VEC_DELETE_EXPR)
09274 {
09275 if (DECL_NAMESPACE_SCOPE_P (decl))
09276 {
09277 if (CP_DECL_CONTEXT (decl) != global_namespace)
09278 {
09279 error ("%qD may not be declared within a namespace", decl);
09280 return false;
09281 }
09282 else if (!TREE_PUBLIC (decl))
09283 {
09284 error ("%qD may not be declared as static", decl);
09285 return false;
09286 }
09287 }
09288 }
09289
09290 if (operator_code == NEW_EXPR || operator_code == VEC_NEW_EXPR)
09291 TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl));
09292 else if (operator_code == DELETE_EXPR || operator_code == VEC_DELETE_EXPR)
09293 TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl));
09294 else
09295 {
09296
09297
09298
09299 if (! methodp || DECL_STATIC_FUNCTION_P (decl))
09300 {
09301 if (operator_code == TYPE_EXPR
09302 || operator_code == CALL_EXPR
09303 || operator_code == COMPONENT_REF
09304 || operator_code == ARRAY_REF
09305 || operator_code == NOP_EXPR)
09306 {
09307 error ("%qD must be a nonstatic member function", decl);
09308 return false;
09309 }
09310 else
09311 {
09312 tree p;
09313
09314 if (DECL_STATIC_FUNCTION_P (decl))
09315 {
09316 error ("%qD must be either a non-static member "
09317 "function or a non-member function", decl);
09318 return false;
09319 }
09320
09321 for (p = argtypes; p && p != void_list_node; p = TREE_CHAIN (p))
09322 {
09323 tree arg = non_reference (TREE_VALUE (p));
09324 if (arg == error_mark_node)
09325 return false;
09326
09327
09328
09329
09330 if (IS_AGGR_TYPE (arg) || TREE_CODE (arg) == ENUMERAL_TYPE)
09331 break;
09332 }
09333
09334 if (!p || p == void_list_node)
09335 {
09336 if (complain)
09337 error ("%qD must have an argument of class or "
09338 "enumerated type", decl);
09339 return false;
09340 }
09341 }
09342 }
09343
09344
09345
09346 if (operator_code == CALL_EXPR)
09347 return true;
09348
09349
09350 if (IDENTIFIER_TYPENAME_P (name)
09351 && ! DECL_TEMPLATE_INFO (decl)
09352 && warn_conversion
09353
09354
09355 && class_type == current_class_type)
09356 {
09357 tree t = TREE_TYPE (name);
09358 int ref = (TREE_CODE (t) == REFERENCE_TYPE);
09359 const char *what = 0;
09360
09361 if (ref)
09362 t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
09363
09364 if (TREE_CODE (t) == VOID_TYPE)
09365 what = "void";
09366 else if (class_type)
09367 {
09368 if (t == class_type)
09369 what = "the same type";
09370
09371 else if (IS_AGGR_TYPE (t)
09372 && COMPLETE_TYPE_P (t)
09373 && DERIVED_FROM_P (t, class_type))
09374 what = "a base class";
09375 }
09376
09377 if (what)
09378 warning (OPT_Wconversion, "conversion to %s%s will never use a type "
09379 "conversion operator",
09380 ref ? "a reference to " : "", what);
09381 }
09382
09383 if (operator_code == COND_EXPR)
09384 {
09385
09386 error ("ISO C++ prohibits overloading operator ?:");
09387 return false;
09388 }
09389 else if (ellipsis_p)
09390 {
09391 error ("%qD must not have variable number of arguments", decl);
09392 return false;
09393 }
09394 else if (ambi_op_p (operator_code))
09395 {
09396 if (arity == 1)
09397
09398
09399 ;
09400 else if (arity == 2)
09401 {
09402
09403
09404 switch (operator_code)
09405 {
09406 case INDIRECT_REF:
09407 operator_code = MULT_EXPR;
09408 break;
09409
09410 case ADDR_EXPR:
09411 operator_code = BIT_AND_EXPR;
09412 break;
09413
09414 case UNARY_PLUS_EXPR:
09415 operator_code = PLUS_EXPR;
09416 break;
09417
09418 case NEGATE_EXPR:
09419 operator_code = MINUS_EXPR;
09420 break;
09421
09422 case PREINCREMENT_EXPR:
09423 operator_code = POSTINCREMENT_EXPR;
09424 break;
09425
09426 case PREDECREMENT_EXPR:
09427 operator_code = POSTDECREMENT_EXPR;
09428 break;
09429
09430 default:
09431 gcc_unreachable ();
09432 }
09433
09434 SET_OVERLOADED_OPERATOR_CODE (decl, operator_code);
09435
09436 if ((operator_code == POSTINCREMENT_EXPR
09437 || operator_code == POSTDECREMENT_EXPR)
09438 && ! processing_template_decl
09439 && ! same_type_p (TREE_VALUE (TREE_CHAIN (argtypes)), integer_type_node))
09440 {
09441 if (methodp)
09442 error ("postfix %qD must take %<int%> as its argument",
09443 decl);
09444 else
09445 error ("postfix %qD must take %<int%> as its second "
09446 "argument", decl);
09447 return false;
09448 }
09449 }
09450 else
09451 {
09452 if (methodp)
09453 error ("%qD must take either zero or one argument", decl);
09454 else
09455 error ("%qD must take either one or two arguments", decl);
09456 return false;
09457 }
09458
09459
09460 if (warn_ecpp
09461 && (operator_code == POSTINCREMENT_EXPR
09462 || operator_code == POSTDECREMENT_EXPR
09463 || operator_code == PREINCREMENT_EXPR
09464 || operator_code == PREDECREMENT_EXPR))
09465 {
09466 tree arg = TREE_VALUE (argtypes);
09467 tree ret = TREE_TYPE (TREE_TYPE (decl));
09468 if (methodp || TREE_CODE (arg) == REFERENCE_TYPE)
09469 arg = TREE_TYPE (arg);
09470 arg = TYPE_MAIN_VARIANT (arg);
09471 if (operator_code == PREINCREMENT_EXPR
09472 || operator_code == PREDECREMENT_EXPR)
09473 {
09474 if (TREE_CODE (ret) != REFERENCE_TYPE
09475 || !same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (ret)),
09476 arg))
09477 warning (OPT_Weffc__, "prefix %qD should return %qT", decl,
09478 build_reference_type (arg));
09479 }
09480 else
09481 {
09482 if (!same_type_p (TYPE_MAIN_VARIANT (ret), arg))
09483 warning (OPT_Weffc__, "postfix %qD should return %qT", decl, arg);
09484 }
09485 }
09486 }
09487 else if (unary_op_p (operator_code))
09488 {
09489 if (arity != 1)
09490 {
09491 if (methodp)
09492 error ("%qD must take %<void%>", decl);
09493 else
09494 error ("%qD must take exactly one argument", decl);
09495 return false;
09496 }
09497 }
09498 else
09499 {
09500 if (arity != 2)
09501 {
09502 if (methodp)
09503 error ("%qD must take exactly one argument", decl);
09504 else
09505 error ("%qD must take exactly two arguments", decl);
09506 return false;
09507 }
09508
09509
09510 if (warn_ecpp
09511 && (operator_code == TRUTH_ANDIF_EXPR
09512 || operator_code == TRUTH_ORIF_EXPR
09513 || operator_code == COMPOUND_EXPR))
09514 warning (OPT_Weffc__, "user-defined %qD always evaluates both arguments",
09515 decl);
09516 }
09517
09518
09519 if (warn_ecpp
09520 && arity == 2
09521 && !DECL_ASSIGNMENT_OPERATOR_P (decl)
09522 && (operator_code == PLUS_EXPR
09523 || operator_code == MINUS_EXPR
09524 || operator_code == TRUNC_DIV_EXPR
09525 || operator_code == MULT_EXPR
09526 || operator_code == TRUNC_MOD_EXPR)
09527 && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) == REFERENCE_TYPE)
09528 warning (OPT_Weffc__, "%qD should return by value", decl);
09529
09530
09531 for (; argtypes && argtypes != void_list_node;
09532 argtypes = TREE_CHAIN (argtypes))
09533 if (TREE_PURPOSE (argtypes))
09534 {
09535 TREE_PURPOSE (argtypes) = NULL_TREE;
09536 if (operator_code == POSTINCREMENT_EXPR
09537 || operator_code == POSTDECREMENT_EXPR)
09538 {
09539 if (pedantic)
09540 pedwarn ("%qD cannot have default arguments", decl);
09541 }
09542 else
09543 {
09544 error ("%qD cannot have default arguments", decl);
09545 return false;
09546 }
09547 }
09548 }
09549 return true;
09550 }
09551
09552
09553
09554 static const char *
09555 tag_name (enum tag_types code)
09556 {
09557 switch (code)
09558 {
09559 case record_type:
09560 return "struct";
09561 case class_type:
09562 return "class";
09563 case union_type:
09564 return "union";
09565 case enum_type:
09566 return "enum";
09567 case typename_type:
09568 return "typename";
09569 default:
09570 gcc_unreachable ();
09571 }
09572 }
09573
09574
09575
09576
09577
09578
09579
09580 tree
09581 check_elaborated_type_specifier (enum tag_types tag_code,
09582 tree decl,
09583 bool allow_template_p)
09584 {
09585 tree type;
09586
09587
09588
09589
09590
09591
09592
09593 if (DECL_SELF_REFERENCE_P (decl))
09594 decl = TYPE_NAME (TREE_TYPE (decl));
09595
09596 type = TREE_TYPE (decl);
09597
09598
09599
09600 if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
09601 {
09602 error ("using template type parameter %qT after %qs",
09603 type, tag_name (tag_code));
09604 return error_mark_node;
09605 }
09606
09607
09608
09609
09610
09611
09612
09613
09614 else if (!DECL_IMPLICIT_TYPEDEF_P (decl)
09615 && tag_code != typename_type)
09616 {
09617 error ("using typedef-name %qD after %qs", decl, tag_name (tag_code));
09618 error ("%q+D has a previous declaration here", decl);
09619 return error_mark_node;
09620 }
09621 else if (TREE_CODE (type) != RECORD_TYPE
09622 && TREE_CODE (type) != UNION_TYPE
09623 && tag_code != enum_type
09624 && tag_code != typename_type)
09625 {
09626 error ("%qT referred to as %qs", type, tag_name (tag_code));
09627 error ("%q+T has a previous declaration here", type);
09628 return error_mark_node;
09629 }
09630 else if (TREE_CODE (type) != ENUMERAL_TYPE
09631 && tag_code == enum_type)
09632 {
09633 error ("%qT referred to as enum", type);
09634 error ("%q+T has a previous declaration here", type);
09635 return error_mark_node;
09636 }
09637 else if (!allow_template_p
09638 && TREE_CODE (type) == RECORD_TYPE
09639 && CLASSTYPE_IS_TEMPLATE (type))
09640 {
09641
09642
09643
09644
09645
09646
09647
09648 error ("template argument required for %<%s %T%>",
09649 tag_name (tag_code),
09650 DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)));
09651 return error_mark_node;
09652 }
09653
09654 return type;
09655 }
09656
09657
09658
09659
09660
09661
09662 static tree
09663 lookup_and_check_tag (enum tag_types tag_code, tree name,
09664 tag_scope scope, bool template_header_p)
09665 {
09666 tree t;
09667 tree decl;
09668 if (scope == ts_global)
09669 {
09670
09671
09672 decl = lookup_name_prefer_type (name, 2);
09673
09674
09675
09676
09677
09678
09679 if (!decl)
09680 decl = lookup_type_scope (name, ts_within_enclosing_non_class);
09681 }
09682 else
09683 decl = lookup_type_scope (name, scope);
09684
09685 if (decl && DECL_CLASS_TEMPLATE_P (decl))
09686 decl = DECL_TEMPLATE_RESULT (decl);
09687
09688 if (decl && TREE_CODE (decl) == TYPE_DECL)
09689 {
09690
09691
09692
09693
09694 if (scope == ts_current && DECL_SELF_REFERENCE_P (decl))
09695 {
09696 error ("%qD has the same name as the class in which it is "
09697 "declared",
09698 decl);
09699 return error_mark_node;
09700 }
09701
09702
09703
09704
09705
09706
09707
09708
09709
09710
09711
09712
09713
09714
09715
09716
09717
09718 t = check_elaborated_type_specifier (tag_code,
09719 decl,
09720 template_header_p
09721 | DECL_SELF_REFERENCE_P (decl));
09722 return t;
09723 }
09724 else
09725 return NULL_TREE;
09726 }
09727
09728
09729
09730
09731
09732
09733
09734
09735
09736
09737
09738
09739
09740
09741
09742
09743 tree
09744 xref_tag (enum tag_types tag_code, tree name,
09745 tag_scope scope, bool template_header_p)
09746 {
09747 enum tree_code code;
09748 tree t;
09749 tree context = NULL_TREE;
09750
09751 timevar_push (TV_NAME_LOOKUP);
09752
09753 gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
09754
09755 switch (tag_code)
09756 {
09757 case record_type:
09758 case class_type:
09759 code = RECORD_TYPE;
09760 break;
09761 case union_type:
09762 code = UNION_TYPE;
09763 break;
09764 case enum_type:
09765 code = ENUMERAL_TYPE;
09766 break;
09767 default:
09768 gcc_unreachable ();
09769 }
09770
09771
09772
09773 if (ANON_AGGRNAME_P (name))
09774 t = NULL_TREE;
09775 else
09776 t = lookup_and_check_tag (tag_code, name,
09777 scope, template_header_p);
09778
09779 if (t == error_mark_node)
09780 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
09781
09782 if (scope != ts_current && t && current_class_type
09783 && template_class_depth (current_class_type)
09784 && template_header_p)
09785 {
09786
09787
09788
09789
09790
09791
09792
09793
09794
09795
09796
09797
09798
09799
09800
09801
09802
09803
09804
09805
09806
09807
09808
09809
09810
09811
09812
09813
09814
09815
09816
09817
09818
09819
09820
09821
09822 context = TYPE_CONTEXT (t);
09823 t = NULL_TREE;
09824 }
09825
09826 if (! t)
09827 {
09828
09829
09830
09831
09832 if (code == ENUMERAL_TYPE)
09833 {
09834 error ("use of enum %q#D without previous declaration", name);
09835 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
09836 }
09837 else
09838 {
09839 t = make_aggr_type (code);
09840 TYPE_CONTEXT (t) = context;
09841 t = pushtag (name, t, scope);
09842 }
09843 }
09844 else
09845 {
09846 if (template_header_p && IS_AGGR_TYPE (t))
09847 {
09848 if (!redeclare_class_template (t, current_template_parms))
09849 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
09850 }
09851 else if (!processing_template_decl
09852 && CLASS_TYPE_P (t)
09853 && CLASSTYPE_IS_TEMPLATE (t))
09854 {
09855 error ("redeclaration of %qT as a non-template", t);
09856 error ("previous declaration %q+D", t);
09857 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
09858 }
09859
09860
09861 if (scope != ts_within_enclosing_non_class
09862 && hidden_name_p (TYPE_NAME (t)))
09863 {
09864 DECL_ANTICIPATED (TYPE_NAME (t)) = 0;
09865 DECL_FRIEND_P (TYPE_NAME (t)) = 0;
09866
09867 if (TYPE_TEMPLATE_INFO (t))
09868 {
09869 DECL_ANTICIPATED (TYPE_TI_TEMPLATE (t)) = 0;
09870 DECL_FRIEND_P (TYPE_TI_TEMPLATE (t)) = 0;
09871 }
09872 }
09873 }
09874
09875 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
09876 }
09877
09878 tree
09879 xref_tag_from_type (tree old, tree id, tag_scope scope)
09880 {
09881 enum tag_types tag_kind;
09882
09883 if (TREE_CODE (old) == RECORD_TYPE)
09884 tag_kind = (CLASSTYPE_DECLARED_CLASS (old) ? class_type : record_type);
09885 else
09886 tag_kind = union_type;
09887
09888 if (id == NULL_TREE)
09889 id = TYPE_IDENTIFIER (old);
09890
09891 return xref_tag (tag_kind, id, scope, false);
09892 }
09893
09894
09895
09896
09897
09898
09899
09900
09901
09902 bool
09903 xref_basetypes (tree ref, tree base_list)
09904 {
09905 tree *basep;
09906 tree binfo, base_binfo;
09907 unsigned max_vbases = 0;
09908 unsigned max_bases = 0;
09909 int i;
09910 tree default_access;
09911 tree igo_prev;
09912
09913 if (ref == error_mark_node)
09914 return false;
09915
09916
09917
09918 default_access = (TREE_CODE (ref) == RECORD_TYPE
09919 && CLASSTYPE_DECLARED_CLASS (ref)
09920 ? access_private_node : access_public_node);
09921
09922
09923
09924
09925
09926 basep = &base_list;
09927 while (*basep)
09928 {
09929 tree basetype = TREE_VALUE (*basep);
09930
09931 if (!(processing_template_decl && uses_template_parms (basetype))
09932 && !complete_type_or_else (basetype, NULL))
09933
09934 *basep = TREE_CHAIN (*basep);
09935 else
09936 {
09937 max_bases++;
09938 if (TREE_TYPE (*basep))
09939 max_vbases++;
09940 if (CLASS_TYPE_P (basetype))
09941 max_vbases += VEC_length (tree, CLASSTYPE_VBASECLASSES (basetype));
09942 basep = &TREE_CHAIN (*basep);
09943 }
09944 }
09945
09946 TYPE_MARKED_P (ref) = 1;
09947
09948
09949
09950 gcc_assert (!TYPE_BINFO (ref) || TYPE_SIZE (ref));
09951 gcc_assert (TYPE_MAIN_VARIANT (ref) == ref);
09952
09953 binfo = make_tree_binfo (max_bases);
09954
09955 TYPE_BINFO (ref) = binfo;
09956 BINFO_OFFSET (binfo) = size_zero_node;
09957 BINFO_TYPE (binfo) = ref;
09958
09959 if (max_bases)
09960 {
09961 BINFO_BASE_ACCESSES (binfo) = VEC_alloc (tree, gc, max_bases);
09962
09963 CLASSTYPE_NON_AGGREGATE (ref) = 1;
09964
09965 if (TREE_CODE (ref) == UNION_TYPE)
09966 {
09967 error ("derived union %qT invalid", ref);
09968 return false;
09969 }
09970 }
09971
09972 if (max_bases > 1)
09973 {
09974 if (TYPE_FOR_JAVA (ref))
09975 {
09976 error ("Java class %qT cannot have multiple bases", ref);
09977 return false;
09978 }
09979 }
09980
09981 if (max_vbases)
09982 {
09983 CLASSTYPE_VBASECLASSES (ref) = VEC_alloc (tree, gc, max_vbases);
09984
09985 if (TYPE_FOR_JAVA (ref))
09986 {
09987 error ("Java class %qT cannot have virtual bases", ref);
09988 return false;
09989 }
09990 }
09991
09992 for (igo_prev = binfo; base_list; base_list = TREE_CHAIN (base_list))
09993 {
09994 tree access = TREE_PURPOSE (base_list);
09995 int via_virtual = TREE_TYPE (base_list) != NULL_TREE;
09996 tree basetype = TREE_VALUE (base_list);
09997
09998 if (access == access_default_node)
09999 access = default_access;
10000
10001 if (TREE_CODE (basetype) == TYPE_DECL)
10002 basetype = TREE_TYPE (basetype);
10003 if (TREE_CODE (basetype) != RECORD_TYPE
10004 && TREE_CODE (basetype) != TYPENAME_TYPE
10005 && TREE_CODE (basetype) != TEMPLATE_TYPE_PARM
10006 && TREE_CODE (basetype) != BOUND_TEMPLATE_TEMPLATE_PARM)
10007 {
10008 error ("base type %qT fails to be a struct or class type",
10009 basetype);
10010 return false;
10011 }
10012
10013 if (TYPE_FOR_JAVA (basetype) && (current_lang_depth () == 0))
10014 TYPE_FOR_JAVA (ref) = 1;
10015
10016 base_binfo = NULL_TREE;
10017 if (CLASS_TYPE_P (basetype) && !dependent_type_p (basetype))
10018 {
10019 base_binfo = TYPE_BINFO (basetype);
10020
10021 basetype = BINFO_TYPE (base_binfo);
10022
10023
10024 TYPE_HAS_NEW_OPERATOR (ref)
10025 |= TYPE_HAS_NEW_OPERATOR (basetype);
10026 TYPE_HAS_ARRAY_NEW_OPERATOR (ref)
10027 |= TYPE_HAS_ARRAY_NEW_OPERATOR (basetype);
10028 TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype);
10029 TYPE_HAS_CONVERSION (ref) |= TYPE_HAS_CONVERSION (basetype);
10030 CLASSTYPE_DIAMOND_SHAPED_P (ref)
10031 |= CLASSTYPE_DIAMOND_SHAPED_P (basetype);
10032 CLASSTYPE_REPEATED_BASE_P (ref)
10033 |= CLASSTYPE_REPEATED_BASE_P (basetype);
10034 }
10035
10036
10037
10038 if (TYPE_MARKED_P (basetype))
10039 {
10040 if (basetype == ref)
10041 error ("recursive type %qT undefined", basetype);
10042 else
10043 error ("duplicate base type %qT invalid", basetype);
10044 return false;
10045 }
10046 TYPE_MARKED_P (basetype) = 1;
10047
10048 base_binfo = copy_binfo (base_binfo, basetype, ref,
10049 &igo_prev, via_virtual);
10050 if (!BINFO_INHERITANCE_CHAIN (base_binfo))
10051 BINFO_INHERITANCE_CHAIN (base_binfo) = binfo;
10052
10053 BINFO_BASE_APPEND (binfo, base_binfo);
10054 BINFO_BASE_ACCESS_APPEND (binfo, access);
10055 }
10056
10057 if (VEC_space (tree, CLASSTYPE_VBASECLASSES (ref), 1))
10058
10059
10060 CLASSTYPE_DIAMOND_SHAPED_P (ref) = 1;
10061
10062
10063 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
10064 TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 0;
10065 TYPE_MARKED_P (ref) = 0;
10066
10067
10068 if (!CLASSTYPE_REPEATED_BASE_P (ref))
10069 {
10070 for (base_binfo = binfo; base_binfo;
10071 base_binfo = TREE_CHAIN (base_binfo))
10072 {
10073 if (TYPE_MARKED_P (BINFO_TYPE (base_binfo)))
10074 {
10075 CLASSTYPE_REPEATED_BASE_P (ref) = 1;
10076 break;
10077 }
10078 TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 1;
10079 }
10080 for (base_binfo = binfo; base_binfo;
10081 base_binfo = TREE_CHAIN (base_binfo))
10082 if (TYPE_MARKED_P (BINFO_TYPE (base_binfo)))
10083 TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 0;
10084 else
10085 break;
10086 }
10087
10088 return true;
10089 }
10090
10091
10092
10093
10094
10095
10096
10097
10098 tree
10099 start_enum (tree name)
10100 {
10101 tree enumtype;
10102
10103 gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
10104
10105
10106
10107
10108
10109 enumtype = lookup_and_check_tag (enum_type, name,
10110 ts_current,
10111 false);
10112
10113 if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE)
10114 {
10115 error ("multiple definition of %q#T", enumtype);
10116 error ("%Jprevious definition here", TYPE_MAIN_DECL (enumtype));
10117
10118 TYPE_VALUES (enumtype) = NULL_TREE;
10119 }
10120 else
10121 {
10122
10123
10124 if (enumtype == error_mark_node)
10125 name = make_anon_name ();
10126
10127 enumtype = make_node (ENUMERAL_TYPE);
10128 enumtype = pushtag (name, enumtype, ts_current);
10129 }
10130
10131 return enumtype;
10132 }
10133
10134
10135
10136
10137
10138 void
10139 finish_enum (tree enumtype)
10140 {
10141 tree values;
10142 tree decl;
10143 tree value;
10144 tree minnode;
10145 tree maxnode;
10146 tree t;
10147 bool unsignedp;
10148 bool use_short_enum;
10149 int lowprec;
10150 int highprec;
10151 int precision;
10152 integer_type_kind itk;
10153 tree underlying_type = NULL_TREE;
10154
10155
10156 TYPE_VALUES (enumtype) = nreverse (TYPE_VALUES (enumtype));
10157
10158
10159
10160
10161
10162 if (processing_template_decl)
10163 {
10164 for (values = TYPE_VALUES (enumtype);
10165 values;
10166 values = TREE_CHAIN (values))
10167 TREE_TYPE (TREE_VALUE (values)) = enumtype;
10168 if (at_function_scope_p ())
10169 add_stmt (build_min (TAG_DEFN, enumtype));
10170 return;
10171 }
10172
10173
10174 if (TYPE_VALUES (enumtype))
10175 {
10176 minnode = maxnode = NULL_TREE;
10177
10178 for (values = TYPE_VALUES (enumtype);
10179 values;
10180 values = TREE_CHAIN (values))
10181 {
10182 decl = TREE_VALUE (values);
10183
10184
10185
10186
10187
10188 TREE_TYPE (decl) = enumtype;
10189
10190
10191 value = DECL_INITIAL (decl);
10192 if (value == error_mark_node)
10193 value = integer_zero_node;
10194
10195
10196 if (!minnode)
10197 minnode = maxnode = value;
10198 else if (tree_int_cst_lt (maxnode, value))
10199 maxnode = value;
10200 else if (tree_int_cst_lt (value, minnode))
10201 minnode = value;
10202 }
10203 }
10204 else
10205
10206
10207
10208
10209 minnode = maxnode = integer_zero_node;
10210
10211
10212
10213
10214
10215 unsignedp = tree_int_cst_sgn (minnode) >= 0;
10216 lowprec = min_precision (minnode, unsignedp);
10217 highprec = min_precision (maxnode, unsignedp);
10218 precision = MAX (lowprec, highprec);
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237 use_short_enum = flag_short_enums
10238 || lookup_attribute ("packed", TYPE_ATTRIBUTES (enumtype));
10239
10240 for (itk = (use_short_enum ? itk_char : itk_int);
10241 itk != itk_none;
10242 itk++)
10243 {
10244 underlying_type = integer_types[itk];
10245 if (TYPE_PRECISION (underlying_type) >= precision
10246 && TYPE_UNSIGNED (underlying_type) == unsignedp)
10247 break;
10248 }
10249 if (itk == itk_none)
10250 {
10251
10252
10253
10254
10255 error ("no integral type can represent all of the enumerator values "
10256 "for %qT", enumtype);
10257 precision = TYPE_PRECISION (long_long_integer_type_node);
10258 underlying_type = integer_types[itk_unsigned_long_long];
10259 }
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276 TYPE_PRECISION (enumtype) = TYPE_PRECISION (underlying_type);
10277
10278 set_min_and_max_values_for_integral_type (enumtype, precision, unsignedp);
10279
10280
10281
10282
10283
10284
10285 TYPE_SIZE (enumtype) = TYPE_SIZE (underlying_type);
10286 TYPE_SIZE_UNIT (enumtype) = TYPE_SIZE_UNIT (underlying_type);
10287 TYPE_MODE (enumtype) = TYPE_MODE (underlying_type);
10288 TYPE_ALIGN (enumtype) = TYPE_ALIGN (underlying_type);
10289 TYPE_USER_ALIGN (enumtype) = TYPE_USER_ALIGN (underlying_type);
10290 TYPE_UNSIGNED (enumtype) = TYPE_UNSIGNED (underlying_type);
10291
10292
10293
10294 for (values = TYPE_VALUES (enumtype); values; values = TREE_CHAIN (values))
10295 {
10296 location_t saved_location;
10297
10298 decl = TREE_VALUE (values);
10299 saved_location = input_location;
10300 input_location = DECL_SOURCE_LOCATION (decl);
10301 value = perform_implicit_conversion (underlying_type,
10302 DECL_INITIAL (decl));
10303 input_location = saved_location;
10304
10305
10306 value = copy_node (value);
10307
10308 TREE_TYPE (value) = enumtype;
10309 DECL_INITIAL (decl) = value;
10310 TREE_VALUE (values) = value;
10311 }
10312
10313
10314 for (t = TYPE_MAIN_VARIANT (enumtype); t; t = TYPE_NEXT_VARIANT (t))
10315 {
10316 TYPE_VALUES (t) = TYPE_VALUES (enumtype);
10317 TYPE_MIN_VALUE (t) = TYPE_MIN_VALUE (enumtype);
10318 TYPE_MAX_VALUE (t) = TYPE_MAX_VALUE (enumtype);
10319 TYPE_SIZE (t) = TYPE_SIZE (enumtype);
10320 TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (enumtype);
10321 TYPE_MODE (t) = TYPE_MODE (enumtype);
10322 TYPE_PRECISION (t) = TYPE_PRECISION (enumtype);
10323 TYPE_ALIGN (t) = TYPE_ALIGN (enumtype);
10324 TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (enumtype);
10325 TYPE_UNSIGNED (t) = TYPE_UNSIGNED (enumtype);
10326 }
10327
10328
10329 rest_of_type_compilation (enumtype, namespace_bindings_p ());
10330 }
10331
10332
10333
10334
10335
10336 void
10337 build_enumerator (tree name, tree value, tree enumtype)
10338 {
10339 tree decl;
10340 tree context;
10341 tree type;
10342
10343
10344
10345 if (value == error_mark_node)
10346 value = NULL_TREE;
10347
10348
10349 if (value)
10350 STRIP_TYPE_NOPS (value);
10351
10352 if (! processing_template_decl)
10353 {
10354
10355 if (value != NULL_TREE)
10356 {
10357 value = integral_constant_value (value);
10358
10359 if (TREE_CODE (value) == INTEGER_CST)
10360 {
10361 value = perform_integral_promotions (value);
10362 constant_expression_warning (value);
10363 }
10364 else
10365 {
10366 error ("enumerator value for %qD not integer constant", name);
10367 value = NULL_TREE;
10368 }
10369 }
10370
10371
10372 if (value == NULL_TREE)
10373 {
10374 if (TYPE_VALUES (enumtype))
10375 {
10376 HOST_WIDE_INT hi;
10377 unsigned HOST_WIDE_INT lo;
10378 tree prev_value;
10379 bool overflowed;
10380
10381
10382
10383
10384
10385 prev_value = DECL_INITIAL (TREE_VALUE (TYPE_VALUES (enumtype)));
10386 overflowed = add_double (TREE_INT_CST_LOW (prev_value),
10387 TREE_INT_CST_HIGH (prev_value),
10388 1, 0, &lo, &hi);
10389 value = build_int_cst_wide (TREE_TYPE (prev_value), lo, hi);
10390 overflowed |= !int_fits_type_p (value, TREE_TYPE (prev_value));
10391
10392 if (overflowed)
10393 {
10394 error ("overflow in enumeration values at %qD", name);
10395 value = error_mark_node;
10396 }
10397 }
10398 else
10399 value = integer_zero_node;
10400 }
10401
10402
10403 STRIP_TYPE_NOPS (value);
10404 }
10405
10406
10407 context = current_scope ();
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422 type = value ? TREE_TYPE (value) : NULL_TREE;
10423
10424 if (context && context == current_class_type)
10425
10426
10427 decl = build_lang_decl (CONST_DECL, name, type);
10428 else
10429
10430
10431 decl = build_decl (CONST_DECL, name, type);
10432
10433 DECL_CONTEXT (decl) = FROB_CONTEXT (context);
10434 TREE_CONSTANT (decl) = 1;
10435 TREE_INVARIANT (decl) = 1;
10436 TREE_READONLY (decl) = 1;
10437 DECL_INITIAL (decl) = value;
10438
10439 if (context && context == current_class_type)
10440
10441
10442
10443 finish_member_declaration (decl);
10444 else
10445 pushdecl (decl);
10446
10447
10448 TYPE_VALUES (enumtype) = tree_cons (name, decl, TYPE_VALUES (enumtype));
10449 }
10450
10451
10452
10453
10454 static void
10455 check_function_type (tree decl, tree current_function_parms)
10456 {
10457 tree fntype = TREE_TYPE (decl);
10458 tree return_type = complete_type (TREE_TYPE (fntype));
10459
10460
10461 require_complete_types_for_parms (current_function_parms);
10462
10463 if (dependent_type_p (return_type))
10464 return;
10465 if (!COMPLETE_OR_VOID_TYPE_P (return_type))
10466 {
10467 tree args = TYPE_ARG_TYPES (fntype);
10468
10469 error ("return type %q#T is incomplete", return_type);
10470
10471
10472 if (TREE_CODE (fntype) == METHOD_TYPE)
10473 fntype = build_method_type_directly (TREE_TYPE (TREE_VALUE (args)),
10474 void_type_node,
10475 TREE_CHAIN (args));
10476 else
10477 fntype = build_function_type (void_type_node, args);
10478 TREE_TYPE (decl)
10479 = build_exception_variant (fntype,
10480 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl)));
10481 }
10482 else
10483 abstract_virtuals_error (decl, TREE_TYPE (fntype));
10484 }
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504 void
10505 start_preparsed_function (tree decl1, tree attrs, int flags)
10506 {
10507 tree ctype = NULL_TREE;
10508 tree fntype;
10509 tree restype;
10510 int doing_friend = 0;
10511 struct cp_binding_level *bl;
10512 tree current_function_parms;
10513 struct c_fileinfo *finfo
10514 = get_fileinfo (LOCATION_FILE (DECL_SOURCE_LOCATION (decl1)));
10515 bool honor_interface;
10516
10517
10518 gcc_assert (TREE_CODE (TREE_VALUE (void_list_node)) == VOID_TYPE);
10519 gcc_assert (TREE_CHAIN (void_list_node) == NULL_TREE);
10520
10521 fntype = TREE_TYPE (decl1);
10522 if (TREE_CODE (fntype) == METHOD_TYPE)
10523 ctype = TYPE_METHOD_BASETYPE (fntype);
10524
10525
10526
10527 if (!ctype && DECL_FRIEND_P (decl1))
10528 {
10529 ctype = DECL_FRIEND_CONTEXT (decl1);
10530
10531
10532
10533
10534 if (ctype && TREE_CODE (ctype) != RECORD_TYPE)
10535 ctype = NULL_TREE;
10536 else
10537 doing_friend = 1;
10538 }
10539
10540 if (DECL_DECLARED_INLINE_P (decl1)
10541 && lookup_attribute ("noinline", attrs))
10542 warning (0, "inline function %q+D given attribute noinline", decl1);
10543
10544 if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl1))
10545
10546
10547
10548 adjust_clone_args (decl1);
10549
10550
10551
10552 if (ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1)
10553 && TREE_CODE (TREE_TYPE (decl1)) == METHOD_TYPE)
10554 {
10555 revert_static_member_fn (decl1);
10556 ctype = NULL_TREE;
10557 }
10558
10559
10560
10561 if (ctype)
10562 push_nested_class (ctype);
10563 else if (DECL_STATIC_FUNCTION_P (decl1))
10564 push_nested_class (DECL_CONTEXT (decl1));
10565
10566
10567
10568
10569
10570
10571
10572 if (flags & SF_INCLASS_INLINE)
10573 maybe_begin_member_template_processing (decl1);
10574
10575
10576 if (warn_ecpp
10577 && DECL_OVERLOADED_OPERATOR_P (decl1) == NOP_EXPR
10578 && TREE_CODE (TREE_TYPE (fntype)) == VOID_TYPE)
10579 warning (OPT_Weffc__, "%<operator=%> should return a reference to %<*this%>");
10580
10581
10582
10583 if (!DECL_INITIAL (decl1))
10584 DECL_INITIAL (decl1) = error_mark_node;
10585
10586
10587
10588 TREE_STATIC (decl1) = 1;
10589
10590
10591
10592
10593
10594 if (processing_template_decl)
10595 {
10596
10597 tree newdecl1 = push_template_decl (decl1);
10598 if (newdecl1 != error_mark_node)
10599 decl1 = newdecl1;
10600 }
10601
10602
10603 current_function_decl = decl1;
10604
10605
10606
10607 current_function_parms = DECL_ARGUMENTS (decl1);
10608
10609
10610
10611
10612 check_function_type (decl1, current_function_parms);
10613
10614
10615 restype = TREE_TYPE (fntype);
10616
10617 if (c_promoting_integer_type_p (restype))
10618 restype = type_promotes_to (restype);
10619 if (DECL_RESULT (decl1) == NULL_TREE)
10620 {
10621 tree resdecl;
10622
10623 resdecl = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (restype));
10624 DECL_ARTIFICIAL (resdecl) = 1;
10625 DECL_IGNORED_P (resdecl) = 1;
10626 DECL_RESULT (decl1) = resdecl;
10627
10628 cp_apply_type_quals_to_decl (cp_type_quals (restype), resdecl);
10629 }
10630
10631
10632
10633
10634
10635
10636 bl = current_binding_level;
10637 allocate_struct_function (decl1);
10638 current_binding_level = bl;
10639
10640
10641
10642
10643
10644 cfun->x_dont_save_pending_sizes_p = 1;
10645
10646
10647 DECL_SAVED_TREE (decl1) = push_stmt_list ();
10648
10649
10650 announce_function (decl1);
10651
10652
10653
10654
10655 if (!processing_template_decl && !(flags & SF_PRE_PARSED))
10656 {
10657
10658 if (!DECL_FUNCTION_MEMBER_P (decl1)
10659 && !(DECL_USE_TEMPLATE (decl1) &&
10660 PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl1))))
10661 {
10662 tree olddecl = pushdecl (decl1);
10663
10664 if (olddecl == error_mark_node)
10665
10666
10667
10668 ;
10669 else
10670
10671
10672 decl1 = olddecl;
10673 }
10674 else
10675 {
10676
10677 if (!DECL_CONTEXT (decl1) && DECL_TEMPLATE_INFO (decl1))
10678 DECL_CONTEXT (decl1) = DECL_CONTEXT (DECL_TI_TEMPLATE (decl1));
10679 }
10680 fntype = TREE_TYPE (decl1);
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690 if (!DECL_CONTEXT (decl1))
10691 maybe_apply_pragma_weak (decl1);
10692 }
10693
10694
10695 current_function_decl = decl1;
10696 cfun->decl = decl1;
10697
10698
10699
10700 if (!DECL_PENDING_INLINE_P (decl1))
10701 DECL_SAVED_FUNCTION_DATA (decl1) = NULL;
10702
10703 if (ctype && !doing_friend && !DECL_STATIC_FUNCTION_P (decl1))
10704 {
10705
10706
10707
10708
10709 tree t = DECL_ARGUMENTS (decl1);
10710
10711 gcc_assert (t != NULL_TREE && TREE_CODE (t) == PARM_DECL);
10712 gcc_assert (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE);
10713
10714 cp_function_chain->x_current_class_ref
10715 = build_indirect_ref (t, NULL);
10716 cp_function_chain->x_current_class_ptr = t;
10717
10718
10719
10720 t = TREE_CHAIN (t);
10721 if (DECL_HAS_IN_CHARGE_PARM_P (decl1))
10722 {
10723 current_in_charge_parm = t;
10724 t = TREE_CHAIN (t);
10725 }
10726 if (DECL_HAS_VTT_PARM_P (decl1))
10727 {
10728 gcc_assert (DECL_NAME (t) == vtt_parm_identifier);
10729 current_vtt_parm = t;
10730 }
10731 }
10732
10733 honor_interface = (!DECL_TEMPLATE_INSTANTIATION (decl1)
10734
10735
10736
10737
10738
10739
10740 && !DECL_ARTIFICIAL (decl1));
10741
10742 if (DECL_INTERFACE_KNOWN (decl1))
10743 {
10744 tree ctx = decl_function_context (decl1);
10745
10746 if (DECL_NOT_REALLY_EXTERN (decl1))
10747 DECL_EXTERNAL (decl1) = 0;
10748
10749 if (ctx != NULL_TREE && DECL_DECLARED_INLINE_P (ctx)
10750 && TREE_PUBLIC (ctx))
10751
10752
10753 comdat_linkage (decl1);
10754 }
10755
10756
10757
10758 else if (!finfo->interface_unknown && honor_interface)
10759 {
10760 if (DECL_DECLARED_INLINE_P (decl1)
10761 || DECL_TEMPLATE_INSTANTIATION (decl1)
10762 || processing_template_decl)
10763 {
10764 DECL_EXTERNAL (decl1)
10765 = (finfo->interface_only
10766 || (DECL_DECLARED_INLINE_P (decl1)
10767 && ! flag_implement_inlines
10768 && !DECL_VINDEX (decl1)));
10769
10770
10771 maybe_make_one_only (decl1);
10772 }
10773 else
10774 DECL_EXTERNAL (decl1) = 0;
10775 DECL_INTERFACE_KNOWN (decl1) = 1;
10776
10777
10778
10779 if (!DECL_EXTERNAL (decl1))
10780 mark_needed (decl1);
10781 }
10782 else if (finfo->interface_unknown && finfo->interface_only
10783 && honor_interface)
10784 {
10785
10786
10787
10788
10789
10790
10791 comdat_linkage (decl1);
10792 DECL_EXTERNAL (decl1) = 0;
10793 DECL_INTERFACE_KNOWN (decl1) = 1;
10794 DECL_DEFER_OUTPUT (decl1) = 1;
10795 }
10796 else
10797 {
10798
10799
10800 DECL_EXTERNAL (decl1) = 0;
10801
10802 if ((DECL_DECLARED_INLINE_P (decl1)
10803 || DECL_TEMPLATE_INSTANTIATION (decl1))
10804 && ! DECL_INTERFACE_KNOWN (decl1)
10805
10806 && ! decl_function_context (decl1))
10807 DECL_DEFER_OUTPUT (decl1) = 1;
10808 else
10809 DECL_INTERFACE_KNOWN (decl1) = 1;
10810 }
10811
10812
10813
10814
10815
10816 if (!DECL_CLONED_FUNCTION_P (decl1))
10817 determine_visibility (decl1);
10818
10819 begin_scope (sk_function_parms, decl1);
10820
10821 ++function_depth;
10822
10823 if (DECL_DESTRUCTOR_P (decl1)
10824 || (DECL_CONSTRUCTOR_P (decl1)
10825 && targetm.cxx.cdtor_returns_this ()))
10826 {
10827 cdtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
10828 DECL_CONTEXT (cdtor_label) = current_function_decl;
10829 }
10830
10831 start_fname_decls ();
10832
10833 store_parm_decls (current_function_parms);
10834 }
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844 int
10845 start_function (cp_decl_specifier_seq *declspecs,
10846 const cp_declarator *declarator,
10847 tree attrs)
10848 {
10849 tree decl1;
10850
10851 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, &attrs);
10852
10853
10854 if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL)
10855 return 0;
10856
10857 if (DECL_MAIN_P (decl1))
10858
10859
10860 gcc_assert (same_type_p (TREE_TYPE (TREE_TYPE (decl1)),
10861 integer_type_node));
10862
10863 start_preparsed_function (decl1, attrs, SF_DEFAULT);
10864
10865 return 1;
10866 }
10867
10868
10869
10870
10871 static bool
10872 use_eh_spec_block (tree fn)
10873 {
10874 return (flag_exceptions && flag_enforce_eh_specs
10875 && !processing_template_decl
10876 && TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn))
10877
10878
10879
10880 && !DECL_CLONED_FUNCTION_P (fn)
10881
10882
10883
10884
10885
10886
10887
10888
10889 && !DECL_ARTIFICIAL (fn));
10890 }
10891
10892
10893
10894
10895
10896
10897
10898 static void
10899 store_parm_decls (tree current_function_parms)
10900 {
10901 tree fndecl = current_function_decl;
10902 tree parm;
10903
10904
10905
10906
10907 tree nonparms = NULL_TREE;
10908
10909 if (current_function_parms)
10910 {
10911
10912
10913
10914
10915
10916 tree specparms = current_function_parms;
10917 tree next;
10918
10919
10920
10921 current_binding_level->names = NULL;
10922
10923
10924
10925
10926 specparms = nreverse (specparms);
10927
10928 for (parm = specparms; parm; parm = next)
10929 {
10930 next = TREE_CHAIN (parm);
10931 if (TREE_CODE (parm) == PARM_DECL)
10932 {
10933 if (DECL_NAME (parm) == NULL_TREE
10934 || TREE_CODE (parm) != VOID_TYPE)
10935 pushdecl (parm);
10936 else
10937 error ("parameter %qD declared void", parm);
10938 }
10939 else
10940 {
10941
10942
10943 TREE_CHAIN (parm) = NULL_TREE;
10944 nonparms = chainon (nonparms, parm);
10945 }
10946 }
10947
10948
10949
10950
10951 DECL_ARGUMENTS (fndecl) = getdecls ();
10952 }
10953 else
10954 DECL_ARGUMENTS (fndecl) = NULL_TREE;
10955
10956
10957
10958
10959
10960 current_binding_level->names = chainon (nonparms, DECL_ARGUMENTS (fndecl));
10961
10962 if (use_eh_spec_block (current_function_decl))
10963 current_eh_spec_block = begin_eh_spec_block ();
10964 }
10965
10966
10967
10968
10969
10970
10971 static void
10972 save_function_data (tree decl)
10973 {
10974 struct language_function *f;
10975
10976
10977
10978 gcc_assert (!DECL_PENDING_INLINE_P (decl));
10979
10980
10981 f = GGC_NEW (struct language_function);
10982 memcpy (f, cp_function_chain, sizeof (struct language_function));
10983 DECL_SAVED_FUNCTION_DATA (decl) = f;
10984
10985
10986 f->base.x_stmt_tree.x_cur_stmt_list = NULL_TREE;
10987 f->bindings = NULL;
10988 f->x_local_names = NULL;
10989 }
10990
10991
10992
10993
10994 static void
10995 finish_constructor_body (void)
10996 {
10997 tree val;
10998 tree exprstmt;
10999
11000 if (targetm.cxx.cdtor_returns_this ())
11001 {
11002
11003 add_stmt (build_stmt (LABEL_EXPR, cdtor_label));
11004
11005 val = DECL_ARGUMENTS (current_function_decl);
11006 val = build2 (MODIFY_EXPR, TREE_TYPE (val),
11007 DECL_RESULT (current_function_decl), val);
11008
11009 exprstmt = build_stmt (RETURN_EXPR, val);
11010 add_stmt (exprstmt);
11011 }
11012 }
11013
11014
11015
11016
11017 static void
11018 begin_destructor_body (void)
11019 {
11020 tree compound_stmt;
11021
11022
11023
11024
11025
11026 if (COMPLETE_TYPE_P (current_class_type))
11027 {
11028 compound_stmt = begin_compound_stmt (0);
11029
11030
11031
11032 initialize_vtbl_ptrs (current_class_ptr);
11033 finish_compound_stmt (compound_stmt);
11034
11035
11036
11037 push_base_cleanups ();
11038 }
11039 }
11040
11041
11042
11043
11044 static void
11045 finish_destructor_body (void)
11046 {
11047 tree exprstmt;
11048
11049
11050
11051 add_stmt (build_stmt (LABEL_EXPR, cdtor_label));
11052
11053
11054 if (DECL_VIRTUAL_P (current_function_decl))
11055 {
11056 tree if_stmt;
11057 tree virtual_size = cxx_sizeof (current_class_type);
11058
11059
11060
11061
11062
11063
11064
11065 exprstmt = build_op_delete_call(DELETE_EXPR, current_class_ptr,
11066 virtual_size,
11067 false,
11068 NULL_TREE,
11069 NULL_TREE);
11070
11071 if_stmt = begin_if_stmt ();
11072 finish_if_stmt_cond (build2 (BIT_AND_EXPR, integer_type_node,
11073 current_in_charge_parm,
11074 integer_one_node),
11075 if_stmt);
11076 finish_expr_stmt (exprstmt);
11077 finish_then_clause (if_stmt);
11078 finish_if_stmt (if_stmt);
11079 }
11080
11081 if (targetm.cxx.cdtor_returns_this ())
11082 {
11083 tree val;
11084
11085 val = DECL_ARGUMENTS (current_function_decl);
11086 val = build2 (MODIFY_EXPR, TREE_TYPE (val),
11087 DECL_RESULT (current_function_decl), val);
11088
11089 exprstmt = build_stmt (RETURN_EXPR, val);
11090 add_stmt (exprstmt);
11091 }
11092 }
11093
11094
11095
11096
11097
11098
11099 tree
11100 begin_function_body (void)
11101 {
11102 tree stmt;
11103
11104 if (! FUNCTION_NEEDS_BODY_BLOCK (current_function_decl))
11105 return NULL_TREE;
11106
11107 if (processing_template_decl)
11108 ;
11109 else
11110
11111
11112
11113 keep_next_level (true);
11114
11115 stmt = begin_compound_stmt (BCS_FN_BODY);
11116
11117 if (processing_template_decl)
11118 ;
11119 else if (DECL_DESTRUCTOR_P (current_function_decl))
11120 begin_destructor_body ();
11121
11122 return stmt;
11123 }
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134 void
11135 finish_function_body (tree compstmt)
11136 {
11137 if (compstmt == NULL_TREE)
11138 return;
11139
11140
11141 finish_compound_stmt (compstmt);
11142
11143 if (processing_template_decl)
11144 ;
11145 else if (DECL_CONSTRUCTOR_P (current_function_decl))
11146 finish_constructor_body ();
11147 else if (DECL_DESTRUCTOR_P (current_function_decl))
11148 finish_destructor_body ();
11149 }
11150
11151
11152
11153
11154
11155 static tree
11156 outer_curly_brace_block (tree fndecl)
11157 {
11158 tree block = BLOCK_SUBBLOCKS (DECL_INITIAL (fndecl));
11159 if (FUNCTION_NEEDS_BODY_BLOCK (current_function_decl))
11160
11161 block = BLOCK_SUBBLOCKS (block);
11162 return block;
11163 }
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175 tree
11176 finish_function (int flags)
11177 {
11178 tree fndecl = current_function_decl;
11179 tree fntype, ctype = NULL_TREE;
11180 int inclass_inline = (flags & 2) != 0;
11181 int nested;
11182
11183
11184
11185 if (fndecl == NULL_TREE)
11186 return error_mark_node;
11187
11188 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fndecl)
11189 && DECL_VIRTUAL_P (fndecl)
11190 && !processing_template_decl)
11191 {
11192 tree fnclass = DECL_CONTEXT (fndecl);
11193 if (fndecl == CLASSTYPE_KEY_METHOD (fnclass))
11194 keyed_classes = tree_cons (NULL_TREE, fnclass, keyed_classes);
11195 }
11196
11197 nested = function_depth > 1;
11198 fntype = TREE_TYPE (fndecl);
11199
11200
11201
11202
11203
11204 gcc_assert (building_stmt_tree ());
11205
11206
11207
11208 if (!DECL_CLONED_FUNCTION_P (fndecl))
11209 {
11210 if (DECL_MAIN_P (current_function_decl))
11211 {
11212 tree stmt;
11213
11214
11215
11216 #if VMS_TARGET
11217 stmt = finish_return_stmt (integer_one_node);
11218 #else
11219 stmt = finish_return_stmt (integer_zero_node);
11220 #endif
11221
11222
11223
11224 #ifdef USE_MAPPED_LOCATION
11225 SET_EXPR_LOCATION (stmt, UNKNOWN_LOCATION);
11226 #else
11227 annotate_with_file_line (stmt, input_filename, 0);
11228 #endif
11229 }
11230
11231 if (use_eh_spec_block (current_function_decl))
11232 finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
11233 (TREE_TYPE (current_function_decl)),
11234 current_eh_spec_block);
11235 }
11236
11237
11238 DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
11239
11240 finish_fname_decls ();
11241
11242
11243 if (!processing_template_decl
11244 && !cp_function_chain->can_throw
11245 && !flag_non_call_exceptions
11246 && !DECL_REPLACEABLE_P (fndecl))
11247 TREE_NOTHROW (fndecl) = 1;
11248
11249
11250
11251
11252
11253
11254
11255
11256 if (current_binding_level->kind != sk_function_parms)
11257 {
11258
11259 gcc_assert (errorcount);
11260
11261
11262
11263 DECL_SAVED_TREE (fndecl) = alloc_stmt_list ();
11264
11265 while (current_binding_level->kind != sk_function_parms)
11266 {
11267 if (current_binding_level->kind == sk_class)
11268 pop_nested_class ();
11269 else
11270 poplevel (0, 0, 0);
11271 }
11272 }
11273 poplevel (1, 0, 1);
11274
11275
11276
11277 gcc_assert (stmts_are_full_exprs_p ());
11278
11279
11280
11281 if (current_function_return_value)
11282 {
11283 tree r = current_function_return_value;
11284 tree outer;
11285
11286 if (r != error_mark_node
11287
11288
11289 && aggregate_value_p (TREE_TYPE (TREE_TYPE (fndecl)), fndecl)
11290
11291
11292
11293
11294 && (outer = outer_curly_brace_block (fndecl))
11295 #if defined(KEY) && defined(TARG_X8664)
11296 && (TREE_CODE(TREE_TYPE(TREE_TYPE(fndecl))) != VECTOR_TYPE)
11297 #endif
11298 && chain_member (r, BLOCK_VARS (outer)))
11299 finalize_nrv (&DECL_SAVED_TREE (fndecl), r, DECL_RESULT (fndecl));
11300
11301 current_function_return_value = NULL_TREE;
11302 }
11303
11304
11305 if (current_class_name)
11306 ctype = current_class_type;
11307
11308
11309 DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
11310
11311
11312
11313 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
11314
11315
11316 if (!processing_template_decl)
11317 save_function_data (fndecl);
11318
11319
11320 if (warn_return_type
11321 && TREE_CODE (TREE_TYPE (fntype)) != VOID_TYPE
11322 && !dependent_type_p (TREE_TYPE (fntype))
11323 && !current_function_returns_value && !current_function_returns_null
11324
11325 && !current_function_returns_abnormally
11326 && !DECL_NAME (DECL_RESULT (fndecl))
11327
11328
11329 && (DECL_INLINE (fndecl) || processing_template_decl)
11330
11331 && !DECL_CONSTRUCTOR_P (fndecl)
11332 && !DECL_DESTRUCTOR_P (fndecl))
11333 warning (OPT_Wreturn_type, "no return statement in function returning non-void");
11334
11335
11336
11337 cfun->function_end_locus = input_location;
11338
11339
11340 if (!processing_template_decl)
11341 {
11342 struct language_function *f = DECL_SAVED_FUNCTION_DATA (fndecl);
11343
11344 #ifdef KEY
11345
11346
11347 if (!flag_spin_file)
11348 #endif
11349 cp_genericize (fndecl);
11350
11351 f->x_current_class_ptr = NULL;
11352 f->x_current_class_ref = NULL;
11353 f->x_eh_spec_block = NULL;
11354 f->x_in_charge_parm = NULL;
11355 f->x_vtt_parm = NULL;
11356 f->x_return_value = NULL;
11357 f->bindings = NULL;
11358 f->extern_decl_map = NULL;
11359
11360
11361 c_warn_unused_result (&DECL_SAVED_TREE (fndecl));
11362 }
11363
11364 local_names = NULL;
11365
11366
11367
11368 cfun = NULL;
11369 current_function_decl = NULL;
11370
11371
11372
11373
11374
11375 if (inclass_inline)
11376 maybe_end_member_template_processing ();
11377
11378
11379 if (ctype)
11380 pop_nested_class ();
11381
11382 --function_depth;
11383
11384
11385 if (! nested)
11386
11387
11388
11389 current_function_decl = NULL_TREE;
11390
11391 return fndecl;
11392 }
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415 tree
11416 start_method (cp_decl_specifier_seq *declspecs,
11417 const cp_declarator *declarator, tree attrlist)
11418 {
11419 tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0,
11420 &attrlist);
11421
11422 if (fndecl == error_mark_node)
11423 return error_mark_node;
11424
11425 if (fndecl == NULL || TREE_CODE (fndecl) != FUNCTION_DECL)
11426 {
11427 error ("invalid member function declaration");
11428 return error_mark_node;
11429 }
11430
11431 if (attrlist)
11432 cplus_decl_attributes (&fndecl, attrlist, 0);
11433
11434
11435 if (fndecl == void_type_node)
11436 return fndecl;
11437
11438 if (DECL_IN_AGGR_P (fndecl))
11439 {
11440 if (DECL_CONTEXT (fndecl)
11441 && TREE_CODE (DECL_CONTEXT (fndecl)) != NAMESPACE_DECL)
11442 error ("%qD is already defined in class %qT", fndecl,
11443 DECL_CONTEXT (fndecl));
11444 return error_mark_node;
11445 }
11446
11447 check_template_shadow (fndecl);
11448
11449 DECL_DECLARED_INLINE_P (fndecl) = 1;
11450 if (flag_default_inline)
11451 DECL_INLINE (fndecl) = 1;
11452
11453
11454 if (processing_template_decl && !DECL_TEMPLATE_SPECIALIZATION (fndecl))
11455 {
11456 fndecl = push_template_decl (fndecl);
11457 if (fndecl == error_mark_node)
11458 return fndecl;
11459 }
11460
11461 if (! DECL_FRIEND_P (fndecl))
11462 {
11463 if (TREE_CHAIN (fndecl))
11464 {
11465 fndecl = copy_node (fndecl);
11466 TREE_CHAIN (fndecl) = NULL_TREE;
11467 }
11468 }
11469
11470 finish_decl (fndecl, NULL_TREE, NULL_TREE);
11471
11472
11473 begin_scope (sk_function_parms, fndecl);
11474
11475 DECL_IN_AGGR_P (fndecl) = 1;
11476 return fndecl;
11477 }
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491 tree
11492 finish_method (tree decl)
11493 {
11494 tree fndecl = decl;
11495 tree old_initial;
11496
11497 tree link;
11498
11499 if (decl == void_type_node)
11500 return decl;
11501
11502 old_initial = DECL_INITIAL (fndecl);
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514 for (link = current_binding_level->names; link; link = TREE_CHAIN (link))
11515 {
11516 if (DECL_NAME (link) != NULL_TREE)
11517 pop_binding (DECL_NAME (link), link);
11518 gcc_assert (TREE_CODE (link) != FUNCTION_DECL);
11519 DECL_CONTEXT (link) = NULL_TREE;
11520 }
11521
11522 poplevel (0, 0, 0);
11523
11524 DECL_INITIAL (fndecl) = old_initial;
11525
11526
11527
11528
11529 if (DECL_FRIEND_P (fndecl))
11530 {
11531 VEC_safe_push (tree, gc, CLASSTYPE_INLINE_FRIENDS (current_class_type),
11532 fndecl);
11533 decl = void_type_node;
11534 }
11535
11536 return decl;
11537 }
11538
11539
11540
11541
11542
11543 void
11544 maybe_register_incomplete_var (tree var)
11545 {
11546 gcc_assert (TREE_CODE (var) == VAR_DECL);
11547
11548
11549 if (!processing_template_decl && TREE_TYPE (var) != error_mark_node
11550 && DECL_EXTERNAL (var))
11551 {
11552 tree inner_type = TREE_TYPE (var);
11553
11554 while (TREE_CODE (inner_type) == ARRAY_TYPE)
11555 inner_type = TREE_TYPE (inner_type);
11556 inner_type = TYPE_MAIN_VARIANT (inner_type);
11557
11558 if ((!COMPLETE_TYPE_P (inner_type) && CLASS_TYPE_P (inner_type))
11559
11560 || (TYPE_LANG_SPECIFIC (inner_type)
11561 && TYPE_BEING_DEFINED (inner_type)))
11562 incomplete_vars = tree_cons (inner_type, var, incomplete_vars);
11563 }
11564 }
11565
11566
11567
11568
11569
11570 void
11571 complete_vars (tree type)
11572 {
11573 tree *list = &incomplete_vars;
11574
11575 gcc_assert (CLASS_TYPE_P (type));
11576 while (*list)
11577 {
11578 if (same_type_p (type, TREE_PURPOSE (*list)))
11579 {
11580 tree var = TREE_VALUE (*list);
11581 tree type = TREE_TYPE (var);
11582
11583
11584 complete_type (type);
11585 cp_apply_type_quals_to_decl (cp_type_quals (type), var);
11586
11587 *list = TREE_CHAIN (*list);
11588 }
11589 else
11590 list = &TREE_CHAIN (*list);
11591 }
11592
11593
11594 complete_type_check_abstract (type);
11595 }
11596
11597
11598
11599
11600 tree
11601 cxx_maybe_build_cleanup (tree decl)
11602 {
11603 tree type = TREE_TYPE (decl);
11604
11605 if (type != error_mark_node && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
11606 {
11607 int flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR;
11608 tree rval;
11609 bool has_vbases = (TREE_CODE (type) == RECORD_TYPE
11610 && CLASSTYPE_VBASECLASSES (type));
11611
11612 if (TREE_CODE (type) == ARRAY_TYPE)
11613 rval = decl;
11614 else
11615 {
11616 cxx_mark_addressable (decl);
11617 rval = build_unary_op (ADDR_EXPR, decl, 0);
11618 }
11619
11620
11621 if (!has_vbases || flag_expensive_optimizations)
11622 flags |= LOOKUP_NONVIRTUAL;
11623
11624 rval = build_delete (TREE_TYPE (rval), rval,
11625 sfk_complete_destructor, flags, 0);
11626
11627 return rval;
11628 }
11629 return NULL_TREE;
11630 }
11631
11632
11633
11634 void
11635 finish_stmt (void)
11636 {
11637 }
11638
11639
11640
11641
11642 void
11643 revert_static_member_fn (tree decl)
11644 {
11645 tree tmp;
11646 tree function = TREE_TYPE (decl);
11647 tree args = TYPE_ARG_TYPES (function);
11648
11649 if (cp_type_quals (TREE_TYPE (TREE_VALUE (args)))
11650 != TYPE_UNQUALIFIED)
11651 error ("static member function %q#D declared with type qualifiers", decl);
11652
11653 args = TREE_CHAIN (args);
11654 tmp = build_function_type (TREE_TYPE (function), args);
11655 tmp = build_qualified_type (tmp, cp_type_quals (function));
11656 tmp = build_exception_variant (tmp,
11657 TYPE_RAISES_EXCEPTIONS (function));
11658 TREE_TYPE (decl) = tmp;
11659 if (DECL_ARGUMENTS (decl))
11660 DECL_ARGUMENTS (decl) = TREE_CHAIN (DECL_ARGUMENTS (decl));
11661 DECL_STATIC_FUNCTION_P (decl) = 1;
11662 }
11663
11664
11665
11666
11667 void
11668 cxx_push_function_context (struct function * f)
11669 {
11670 struct language_function *p = GGC_CNEW (struct language_function);
11671 f->language = p;
11672
11673
11674
11675 current_stmt_tree ()->stmts_are_full_exprs_p = 1;
11676
11677 if (f->decl)
11678 {
11679 tree fn = f->decl;
11680
11681 if (DECL_SAVED_FUNCTION_DATA (fn))
11682 {
11683
11684
11685 *cp_function_chain = *DECL_SAVED_FUNCTION_DATA (fn);
11686
11687
11688
11689
11690 if (! DECL_INLINE (fn))
11691 DECL_SAVED_FUNCTION_DATA (fn) = NULL;
11692 }
11693 }
11694 }
11695
11696
11697
11698
11699 void
11700 cxx_pop_function_context (struct function * f)
11701 {
11702 f->language = 0;
11703 }
11704
11705
11706
11707
11708 enum cp_tree_node_structure_enum
11709 cp_tree_node_structure (union lang_tree_node * t)
11710 {
11711 switch (TREE_CODE (&t->generic))
11712 {
11713 case DEFAULT_ARG: return TS_CP_DEFAULT_ARG;
11714 case IDENTIFIER_NODE: return TS_CP_IDENTIFIER;
11715 case OVERLOAD: return TS_CP_OVERLOAD;
11716 case TEMPLATE_PARM_INDEX: return TS_CP_TPI;
11717 case TINST_LEVEL: return TS_CP_TINST_LEVEL;
11718 case PTRMEM_CST: return TS_CP_PTRMEM;
11719 case BASELINK: return TS_CP_BASELINK;
11720 default: return TS_CP_GENERIC;
11721 }
11722 }
11723
11724
11725 tree
11726 build_void_list_node (void)
11727 {
11728 tree t = build_tree_list (NULL_TREE, void_type_node);
11729 return t;
11730 }
11731
11732 bool
11733 cp_missing_noreturn_ok_p (tree decl)
11734 {
11735
11736 return DECL_MAIN_P (decl);
11737 }
11738
11739
11740
11741 const char *
11742 cxx_comdat_group (tree decl)
11743 {
11744 tree name;
11745
11746
11747
11748
11749 if (TREE_CODE (decl) == VAR_DECL && DECL_VTABLE_OR_VTT_P (decl))
11750 name = DECL_ASSEMBLER_NAME (CLASSTYPE_VTABLES (DECL_CONTEXT (decl)));
11751
11752
11753 else
11754 {
11755 while (DECL_THUNK_P (decl))
11756 {
11757
11758
11759
11760 tree target = THUNK_TARGET (decl);
11761 if (TARGET_USE_LOCAL_THUNK_ALIAS_P (target)
11762 && DECL_SECTION_NAME (target) != NULL
11763 && DECL_ONE_ONLY (target))
11764 decl = target;
11765 else
11766 break;
11767 }
11768 name = DECL_ASSEMBLER_NAME (decl);
11769 }
11770
11771 return IDENTIFIER_POINTER (name);
11772 }
11773
11774 #include "gt-cp-decl.h"