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
00035 #include "config.h"
00036 #include "system.h"
00037 #include "coretypes.h"
00038 #include "tm.h"
00039 #include "tree.h"
00040 #include "rtl.h"
00041 #include "expr.h"
00042 #include "flags.h"
00043 #include "cp-tree.h"
00044 #include "tree-inline.h"
00045 #include "decl.h"
00046 #include "output.h"
00047 #include "except.h"
00048 #include "toplev.h"
00049 #include "hashtab.h"
00050 #include "tm_p.h"
00051 #include "target.h"
00052 #include "c-common.h"
00053 #include "c-pragma.h"
00054 #include "diagnostic.h"
00055 #include "debug.h"
00056 #include "timevar.h"
00057 #include "tree-flow.h"
00058
00059 static tree grokparms (cp_parameter_declarator *, tree *);
00060 static const char *redeclaration_error_message (tree, tree);
00061
00062 static int decl_jump_unsafe (tree);
00063 static void require_complete_types_for_parms (tree);
00064 static int ambi_op_p (enum tree_code);
00065 static int unary_op_p (enum tree_code);
00066 static void push_local_name (tree);
00067 static tree grok_reference_init (tree, tree, tree, tree *);
00068 static tree grokvardecl (tree, tree, const cp_decl_specifier_seq *,
00069 int, int, tree);
00070 static void record_unknown_type (tree, const char *);
00071 static tree builtin_function_1 (const char *, tree, tree,
00072 enum built_in_function code,
00073 enum built_in_class cl, const char *,
00074 tree);
00075 static tree build_library_fn_1 (tree, enum tree_code, tree);
00076 static int member_function_or_else (tree, tree, enum overload_flags);
00077 static void bad_specifiers (tree, const char *, int, int, int, int,
00078 int);
00079 static void check_for_uninitialized_const_var (tree);
00080 static hashval_t typename_hash (const void *);
00081 static int typename_compare (const void *, const void *);
00082 static tree local_variable_p_walkfn (tree *, int *, void *);
00083 static tree record_builtin_java_type (const char *, int);
00084 static const char *tag_name (enum tag_types);
00085 static tree lookup_and_check_tag (enum tag_types, tree, tag_scope, bool);
00086 static int walk_namespaces_r (tree, walk_namespaces_fn, void *);
00087 static tree make_label_decl (tree, int);
00088 static void use_label (tree);
00089 static void check_previous_goto_1 (tree, struct cp_binding_level *, tree,
00090 const location_t *);
00091 static void check_previous_goto (struct named_label_use_list *);
00092 static void check_switch_goto (struct cp_binding_level *);
00093 static void check_previous_gotos (tree);
00094 static void pop_label (tree, tree);
00095 static void pop_labels (tree);
00096 static void maybe_deduce_size_from_array_init (tree, tree);
00097 static void layout_var_decl (tree);
00098 static void maybe_commonize_var (tree);
00099 static tree check_initializer (tree, tree, int, tree *);
00100 static void make_rtl_for_nonlocal_decl (tree, tree, const char *);
00101 static void save_function_data (tree);
00102 static void check_function_type (tree, tree);
00103 static void finish_constructor_body (void);
00104 static void begin_destructor_body (void);
00105 static void finish_destructor_body (void);
00106 static tree create_array_type_for_decl (tree, tree, tree);
00107 static tree get_atexit_node (void);
00108 static tree get_dso_handle_node (void);
00109 static tree start_cleanup_fn (void);
00110 static void end_cleanup_fn (void);
00111 static tree cp_make_fname_decl (tree, int);
00112 static void initialize_predefined_identifiers (void);
00113 static tree check_special_function_return_type
00114 (special_function_kind, tree, tree);
00115 static tree push_cp_library_fn (enum tree_code, tree);
00116 static tree build_cp_library_fn (tree, enum tree_code, tree);
00117 static void store_parm_decls (tree);
00118 static void initialize_local_var (tree, tree);
00119 static void expand_static_init (tree, tree);
00120 static tree next_initializable_field (tree);
00121 static tree reshape_init (tree, tree *);
00122
00123
00124 tree error_mark_list;
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
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 tree cp_global_trees[CPTI_MAX];
00172
00173
00174
00175
00176 tree global_type_node;
00177
00178
00179 tree global_scope_name;
00180
00181
00182
00183
00184 struct named_label_use_list GTY(())
00185 {
00186 struct cp_binding_level *binding_level;
00187 tree names_in_scope;
00188 tree label_decl;
00189 location_t o_goto_locus;
00190 struct named_label_use_list *next;
00191 };
00192
00193 #define named_label_uses cp_function_chain->x_named_label_uses
00194
00195 #define local_names cp_function_chain->x_local_names
00196
00197
00198
00199
00200
00201 tree static_aggregates;
00202
00203
00204
00205
00206
00207 tree integer_two_node, integer_three_node;
00208
00209
00210
00211
00212
00213 struct named_label_list GTY(())
00214 {
00215 struct cp_binding_level *binding_level;
00216 tree names_in_scope;
00217 tree old_value;
00218 tree label_decl;
00219 tree bad_decls;
00220 struct named_label_list *next;
00221 unsigned int in_try_scope : 1;
00222 unsigned int in_catch_scope : 1;
00223 };
00224
00225 #define named_labels cp_function_chain->x_named_labels
00226
00227
00228
00229
00230 int function_depth;
00231
00232
00233
00234
00235
00236
00237 enum deprecated_states {
00238 DEPRECATED_NORMAL,
00239 DEPRECATED_SUPPRESS
00240 };
00241
00242 static enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
00243
00244
00245
00246 bool have_extern_spec;
00247
00248
00249
00250
00251
00252
00253 static GTY(()) tree incomplete_vars;
00254
00255
00256
00257
00258
00259 tmpl_spec_kind
00260 current_tmpl_spec_kind (int n_class_scopes)
00261 {
00262 int n_template_parm_scopes = 0;
00263 int seen_specialization_p = 0;
00264 int innermost_specialization_p = 0;
00265 struct cp_binding_level *b;
00266
00267
00268 for (b = current_binding_level;
00269 b->kind == sk_template_parms;
00270 b = b->level_chain)
00271 {
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281 if (b->explicit_spec_p)
00282 {
00283 if (n_template_parm_scopes == 0)
00284 innermost_specialization_p = 1;
00285 else
00286 seen_specialization_p = 1;
00287 }
00288 else if (seen_specialization_p == 1)
00289 return tsk_invalid_member_spec;
00290
00291 ++n_template_parm_scopes;
00292 }
00293
00294
00295 if (processing_explicit_instantiation)
00296 {
00297 if (n_template_parm_scopes != 0)
00298
00299
00300
00301
00302
00303
00304 return tsk_invalid_expl_inst;
00305 else
00306 return tsk_expl_inst;
00307 }
00308
00309 if (n_template_parm_scopes < n_class_scopes)
00310
00311
00312
00313
00314
00315
00316
00317 return tsk_insufficient_parms;
00318 else if (n_template_parm_scopes == n_class_scopes)
00319
00320
00321
00322
00323
00324
00325
00326 return tsk_none;
00327 else if (n_template_parm_scopes > n_class_scopes + 1)
00328
00329
00330
00331
00332
00333 return tsk_excessive_parms;
00334 else
00335
00336
00337
00338
00339
00340
00341
00342 return innermost_specialization_p ? tsk_expl_spec : tsk_template;
00343 }
00344
00345
00346
00347 void
00348 finish_scope (void)
00349 {
00350 poplevel (0, 0, 0);
00351 }
00352
00353
00354
00355
00356 static void
00357 pop_label (tree label, tree old_value)
00358 {
00359 if (!processing_template_decl)
00360 {
00361 if (DECL_INITIAL (label) == NULL_TREE)
00362 {
00363 location_t location;
00364
00365 cp_error_at ("label %qD used but not defined", label);
00366 #ifdef USE_MAPPED_LOCATION
00367 location = input_location;
00368 #else
00369 location.file = input_filename;
00370 location.line = 0;
00371 #endif
00372
00373 define_label (location, DECL_NAME (label));
00374 }
00375 else if (warn_unused_label && !TREE_USED (label))
00376 cp_warning_at ("label %qD defined but not used", label);
00377 }
00378
00379 SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), old_value);
00380 }
00381
00382
00383
00384
00385
00386 static void
00387 pop_labels (tree block)
00388 {
00389 struct named_label_list *link;
00390
00391
00392
00393 for (link = named_labels; link; link = link->next)
00394 {
00395 pop_label (link->label_decl, link->old_value);
00396
00397
00398 TREE_CHAIN (link->label_decl) = BLOCK_VARS (block);
00399 BLOCK_VARS (block) = link->label_decl;
00400 }
00401
00402 named_labels = NULL;
00403 }
00404
00405
00406
00407
00408 void *
00409 objc_get_current_scope (void)
00410 {
00411 return current_binding_level;
00412 }
00413
00414
00415
00416
00417
00418
00419
00420 void
00421 objc_mark_locals_volatile (void *enclosing_blk)
00422 {
00423 struct cp_binding_level *scope;
00424
00425 for (scope = current_binding_level;
00426 scope && scope != enclosing_blk && scope->kind == sk_block;
00427 scope = scope->level_chain)
00428 {
00429 tree decl;
00430
00431 for (decl = scope->names; decl; decl = TREE_CHAIN (decl))
00432 {
00433 if (TREE_CODE (decl) == VAR_DECL)
00434 {
00435 DECL_REGISTER (decl) = 0;
00436 TREE_THIS_VOLATILE (decl) = 1;
00437 }
00438 }
00439 }
00440 }
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457 tree
00458 poplevel (int keep, int reverse, int functionbody)
00459 {
00460 tree link;
00461
00462
00463 tree decls;
00464 int tmp = functionbody;
00465 int real_functionbody;
00466 tree subblocks;
00467 tree block;
00468 tree decl;
00469 int leaving_for_scope;
00470 scope_kind kind;
00471
00472 timevar_push (TV_NAME_LOOKUP);
00473 restart:
00474
00475 block = NULL_TREE;
00476
00477 gcc_assert (current_binding_level->kind != sk_class);
00478
00479 real_functionbody = (current_binding_level->kind == sk_cleanup
00480 ? ((functionbody = 0), tmp) : functionbody);
00481 subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
00482
00483 gcc_assert (!VEC_length(cp_class_binding,
00484 current_binding_level->class_shadowed));
00485
00486
00487
00488
00489 gcc_assert (keep == 0 || keep == 1);
00490
00491 if (current_binding_level->keep)
00492 keep = 1;
00493
00494
00495
00496 if (cfun && !functionbody)
00497 {
00498 struct cp_binding_level *level_chain;
00499 level_chain = current_binding_level->level_chain;
00500 if (level_chain)
00501 {
00502 struct named_label_use_list *uses;
00503 struct named_label_list *labels;
00504 for (labels = named_labels; labels; labels = labels->next)
00505 if (labels->binding_level == current_binding_level)
00506 {
00507 tree decl;
00508 if (current_binding_level->kind == sk_try)
00509 labels->in_try_scope = 1;
00510 if (current_binding_level->kind == sk_catch)
00511 labels->in_catch_scope = 1;
00512 for (decl = labels->names_in_scope; decl;
00513 decl = TREE_CHAIN (decl))
00514 if (decl_jump_unsafe (decl))
00515 labels->bad_decls = tree_cons (NULL_TREE, decl,
00516 labels->bad_decls);
00517 labels->binding_level = level_chain;
00518 labels->names_in_scope = level_chain->names;
00519 }
00520
00521 for (uses = named_label_uses; uses; uses = uses->next)
00522 if (uses->binding_level == current_binding_level)
00523 {
00524 uses->binding_level = level_chain;
00525 uses->names_in_scope = level_chain->names;
00526 }
00527 }
00528 }
00529
00530
00531
00532
00533
00534 if (reverse)
00535 current_binding_level->names
00536 = decls = nreverse (current_binding_level->names);
00537 else
00538 decls = current_binding_level->names;
00539
00540
00541
00542
00543 block = NULL_TREE;
00544 if (keep == 1 || functionbody)
00545 block = make_node (BLOCK);
00546 if (block != NULL_TREE)
00547 {
00548 BLOCK_VARS (block) = decls;
00549 BLOCK_SUBBLOCKS (block) = subblocks;
00550 }
00551
00552
00553 if (keep >= 0)
00554 for (link = subblocks; link; link = TREE_CHAIN (link))
00555 BLOCK_SUPERCONTEXT (link) = block;
00556
00557
00558
00559
00560
00561 leaving_for_scope
00562 = current_binding_level->kind == sk_for && flag_new_for_scope == 1;
00563
00564
00565 if (warn_unused_variable
00566 && !processing_template_decl)
00567 for (decl = getdecls (); decl; decl = TREE_CHAIN (decl))
00568 if (TREE_CODE (decl) == VAR_DECL
00569 && ! TREE_USED (decl)
00570 && ! DECL_IN_SYSTEM_HEADER (decl)
00571 && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
00572 warning ("%Junused variable %qD", decl, decl);
00573
00574
00575 for (link = decls; link; link = TREE_CHAIN (link))
00576 {
00577 if (leaving_for_scope && TREE_CODE (link) == VAR_DECL
00578 && DECL_NAME (link))
00579 {
00580 tree name = DECL_NAME (link);
00581 cxx_binding *ob;
00582 tree ns_binding;
00583
00584 ob = outer_binding (name,
00585 IDENTIFIER_BINDING (name),
00586 true);
00587 if (!ob)
00588 ns_binding = IDENTIFIER_NAMESPACE_VALUE (name);
00589 else
00590 ns_binding = NULL_TREE;
00591
00592 if (ob && ob->scope == current_binding_level->level_chain)
00593
00594
00595
00596
00597
00598
00599
00600 pop_binding (name, link);
00601 else if ((ob && (TREE_CODE (ob->value) == TYPE_DECL))
00602 || (ns_binding && TREE_CODE (ns_binding) == TYPE_DECL))
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613 pop_binding (name, link);
00614 else
00615 {
00616
00617
00618 DECL_DEAD_FOR_LOCAL (link) = 1;
00619
00620
00621
00622 if (ob && ob->value)
00623 DECL_SHADOWED_FOR_VAR (link) = ob->value;
00624
00625
00626
00627
00628 current_binding_level->level_chain->dead_vars_from_for
00629 = tree_cons (NULL_TREE, link,
00630 current_binding_level->level_chain->
00631 dead_vars_from_for);
00632
00633
00634
00635 IDENTIFIER_BINDING (name)->scope
00636 = current_binding_level->level_chain;
00637 }
00638 }
00639 else
00640 {
00641 tree name;
00642
00643
00644 decl = link;
00645
00646 if (TREE_CODE (decl) == TREE_LIST)
00647 decl = TREE_VALUE (decl);
00648 name = decl;
00649
00650 if (TREE_CODE (name) == OVERLOAD)
00651 name = OVL_FUNCTION (name);
00652
00653 gcc_assert (DECL_P (name));
00654 pop_binding (DECL_NAME (name), decl);
00655 }
00656 }
00657
00658
00659
00660 for (link = current_binding_level->dead_vars_from_for;
00661 link; link = TREE_CHAIN (link))
00662 pop_binding (DECL_NAME (TREE_VALUE (link)), TREE_VALUE (link));
00663
00664
00665 for (link = current_binding_level->type_shadowed;
00666 link; link = TREE_CHAIN (link))
00667 SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link), TREE_VALUE (link));
00668
00669
00670 for (link = current_binding_level->shadowed_labels;
00671 link;
00672 link = TREE_CHAIN (link))
00673 pop_label (TREE_VALUE (link), TREE_PURPOSE (link));
00674
00675
00676
00677
00678
00679
00680
00681 if (block)
00682 {
00683 tree* d;
00684
00685 for (d = &BLOCK_VARS (block); *d; )
00686 {
00687 if (TREE_CODE (*d) == TREE_LIST)
00688 *d = TREE_CHAIN (*d);
00689 else
00690 d = &TREE_CHAIN (*d);
00691 }
00692 }
00693
00694
00695
00696 if (functionbody)
00697 {
00698
00699
00700
00701 BLOCK_VARS (block) = 0;
00702 pop_labels (block);
00703 }
00704
00705 kind = current_binding_level->kind;
00706 if (kind == sk_cleanup)
00707 {
00708 tree stmt;
00709
00710
00711
00712
00713 stmt = pop_stmt_list (current_binding_level->statement_list);
00714 stmt = c_build_bind_expr (block, stmt);
00715 add_stmt (stmt);
00716 }
00717
00718 leave_scope ();
00719 if (functionbody)
00720 DECL_INITIAL (current_function_decl) = block;
00721 else if (block)
00722 current_binding_level->blocks
00723 = chainon (current_binding_level->blocks, block);
00724
00725
00726
00727
00728
00729
00730 else if (subblocks)
00731 current_binding_level->blocks
00732 = chainon (current_binding_level->blocks, subblocks);
00733
00734
00735
00736
00737 if (block)
00738 TREE_USED (block) = 1;
00739
00740
00741 if (kind == sk_cleanup)
00742 goto restart;
00743
00744 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, block);
00745 }
00746
00747
00748
00749
00750
00751 void
00752 insert_block (tree block)
00753 {
00754 TREE_USED (block) = 1;
00755 current_binding_level->blocks
00756 = chainon (current_binding_level->blocks, block);
00757 }
00758
00759
00760
00761
00762 static int
00763 walk_namespaces_r (tree namespace, walk_namespaces_fn f, void* data)
00764 {
00765 int result = 0;
00766 tree current = NAMESPACE_LEVEL (namespace)->namespaces;
00767
00768 result |= (*f) (namespace, data);
00769
00770 for (; current; current = TREE_CHAIN (current))
00771 result |= walk_namespaces_r (current, f, data);
00772
00773 return result;
00774 }
00775
00776
00777
00778
00779 int
00780 walk_namespaces (walk_namespaces_fn f, void* data)
00781 {
00782 return walk_namespaces_r (global_namespace, f, data);
00783 }
00784
00785
00786
00787
00788
00789 int
00790 wrapup_globals_for_namespace (tree namespace, void* data)
00791 {
00792 struct cp_binding_level *level = NAMESPACE_LEVEL (namespace);
00793 varray_type statics = level->static_decls;
00794 tree *vec = &VARRAY_TREE (statics, 0);
00795 int len = VARRAY_ACTIVE_SIZE (statics);
00796 int last_time = (data != 0);
00797
00798 if (last_time)
00799 {
00800 check_global_declarations (vec, len);
00801 emit_debug_global_declarations (vec, len);
00802 return 0;
00803 }
00804
00805
00806 return wrapup_global_declarations (vec, len);
00807 }
00808
00809
00810
00811
00812
00813
00814
00815 tree
00816 create_implicit_typedef (tree name, tree type)
00817 {
00818 tree decl;
00819
00820 decl = build_decl (TYPE_DECL, name, type);
00821 DECL_ARTIFICIAL (decl) = 1;
00822
00823
00824
00825 SET_DECL_IMPLICIT_TYPEDEF_P (decl);
00826 TYPE_NAME (type) = decl;
00827
00828 return decl;
00829 }
00830
00831
00832
00833 static void
00834 push_local_name (tree decl)
00835 {
00836 size_t i, nelts;
00837 tree t, name;
00838
00839 timevar_push (TV_NAME_LOOKUP);
00840 if (!local_names)
00841 VARRAY_TREE_INIT (local_names, 8, "local_names");
00842
00843 name = DECL_NAME (decl);
00844
00845 nelts = VARRAY_ACTIVE_SIZE (local_names);
00846 for (i = 0; i < nelts; i++)
00847 {
00848 t = VARRAY_TREE (local_names, i);
00849 if (DECL_NAME (t) == name)
00850 {
00851 if (!DECL_LANG_SPECIFIC (decl))
00852 retrofit_lang_decl (decl);
00853 DECL_LANG_SPECIFIC (decl)->decl_flags.u2sel = 1;
00854 if (DECL_LANG_SPECIFIC (t))
00855 DECL_DISCRIMINATOR (decl) = DECL_DISCRIMINATOR (t) + 1;
00856 else
00857 DECL_DISCRIMINATOR (decl) = 1;
00858
00859 VARRAY_TREE (local_names, i) = decl;
00860 timevar_pop (TV_NAME_LOOKUP);
00861 return;
00862 }
00863 }
00864
00865 VARRAY_PUSH_TREE (local_names, decl);
00866 timevar_pop (TV_NAME_LOOKUP);
00867 }
00868
00869
00870
00871
00872
00873
00874
00875
00876 int
00877 decls_match (tree newdecl, tree olddecl)
00878 {
00879 int types_match;
00880
00881 if (newdecl == olddecl)
00882 return 1;
00883
00884 if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
00885
00886
00887 return 0;
00888
00889 if (TREE_CODE (newdecl) == FUNCTION_DECL)
00890 {
00891 tree f1 = TREE_TYPE (newdecl);
00892 tree f2 = TREE_TYPE (olddecl);
00893 tree p1 = TYPE_ARG_TYPES (f1);
00894 tree p2 = TYPE_ARG_TYPES (f2);
00895
00896 if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
00897 && ! (DECL_EXTERN_C_P (newdecl)
00898 && DECL_EXTERN_C_P (olddecl)))
00899 return 0;
00900
00901 if (TREE_CODE (f1) != TREE_CODE (f2))
00902 return 0;
00903
00904 if (same_type_p (TREE_TYPE (f1), TREE_TYPE (f2)))
00905 {
00906 if (p2 == NULL_TREE && DECL_EXTERN_C_P (olddecl)
00907 && (DECL_BUILT_IN (olddecl)
00908 #ifndef NO_IMPLICIT_EXTERN_C
00909 || (DECL_IN_SYSTEM_HEADER (newdecl) && !DECL_CLASS_SCOPE_P (newdecl))
00910 || (DECL_IN_SYSTEM_HEADER (olddecl) && !DECL_CLASS_SCOPE_P (olddecl))
00911 #endif
00912 ))
00913 {
00914 types_match = self_promoting_args_p (p1);
00915 if (p1 == void_list_node)
00916 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
00917 }
00918 #ifndef NO_IMPLICIT_EXTERN_C
00919 else if (p1 == NULL_TREE
00920 && (DECL_EXTERN_C_P (olddecl)
00921 && DECL_IN_SYSTEM_HEADER (olddecl)
00922 && !DECL_CLASS_SCOPE_P (olddecl))
00923 && (DECL_EXTERN_C_P (newdecl)
00924 && DECL_IN_SYSTEM_HEADER (newdecl)
00925 && !DECL_CLASS_SCOPE_P (newdecl)))
00926 {
00927 types_match = self_promoting_args_p (p2);
00928 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
00929 }
00930 #endif
00931 else
00932 types_match = compparms (p1, p2);
00933 }
00934 else
00935 types_match = 0;
00936 }
00937 else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
00938 {
00939 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl))
00940 != TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)))
00941 return 0;
00942
00943 if (!comp_template_parms (DECL_TEMPLATE_PARMS (newdecl),
00944 DECL_TEMPLATE_PARMS (olddecl)))
00945 return 0;
00946
00947 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
00948 types_match = same_type_p (TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl)),
00949 TREE_TYPE (DECL_TEMPLATE_RESULT (newdecl)));
00950 else
00951 types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl),
00952 DECL_TEMPLATE_RESULT (newdecl));
00953 }
00954 else
00955 {
00956
00957
00958 if (TREE_CODE (newdecl) == VAR_DECL
00959 && CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl))
00960 return 0;
00961
00962 if (TREE_TYPE (newdecl) == error_mark_node)
00963 types_match = TREE_TYPE (olddecl) == error_mark_node;
00964 else if (TREE_TYPE (olddecl) == NULL_TREE)
00965 types_match = TREE_TYPE (newdecl) == NULL_TREE;
00966 else if (TREE_TYPE (newdecl) == NULL_TREE)
00967 types_match = 0;
00968 else
00969 types_match = comptypes (TREE_TYPE (newdecl),
00970 TREE_TYPE (olddecl),
00971 COMPARE_REDECLARATION);
00972 }
00973
00974 return types_match;
00975 }
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986 void
00987 warn_extern_redeclared_static (tree newdecl, tree olddecl)
00988 {
00989 tree name;
00990
00991 if (TREE_CODE (newdecl) == TYPE_DECL
00992 || TREE_CODE (newdecl) == TEMPLATE_DECL
00993 || TREE_CODE (newdecl) == CONST_DECL
00994 || TREE_CODE (newdecl) == NAMESPACE_DECL)
00995 return;
00996
00997
00998
00999 if (TREE_CODE (newdecl) == FUNCTION_DECL
01000 && DECL_STATIC_FUNCTION_P (newdecl))
01001 return;
01002
01003
01004
01005 if (DECL_THIS_STATIC (olddecl) || !DECL_THIS_STATIC (newdecl))
01006 return;
01007
01008
01009 if (TREE_CODE (olddecl) == FUNCTION_DECL
01010 && DECL_ARTIFICIAL (olddecl))
01011 return;
01012
01013 name = DECL_ASSEMBLER_NAME (newdecl);
01014 pedwarn ("%qD was declared %<extern%> and later %<static%>", newdecl);
01015 cp_pedwarn_at ("previous declaration of %qD", olddecl);
01016 }
01017
01018
01019
01020
01021
01022
01023
01024
01025 tree
01026 duplicate_decls (tree newdecl, tree olddecl)
01027 {
01028 unsigned olddecl_uid = DECL_UID (olddecl);
01029 int olddecl_friend = 0, types_match = 0;
01030 int new_defines_function = 0;
01031
01032 if (newdecl == olddecl)
01033 return olddecl;
01034
01035 types_match = decls_match (newdecl, olddecl);
01036
01037
01038
01039
01040
01041
01042 if (TREE_TYPE (newdecl) == error_mark_node
01043 || TREE_TYPE (olddecl) == error_mark_node)
01044 types_match = 1;
01045
01046 if (DECL_P (olddecl)
01047 && TREE_CODE (newdecl) == FUNCTION_DECL
01048 && TREE_CODE (olddecl) == FUNCTION_DECL
01049 && (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl)))
01050 {
01051 if (DECL_DECLARED_INLINE_P (newdecl)
01052 && DECL_UNINLINABLE (newdecl)
01053 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
01054 ;
01055 else if (DECL_DECLARED_INLINE_P (olddecl)
01056 && DECL_UNINLINABLE (olddecl)
01057 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
01058 ;
01059 else if (DECL_DECLARED_INLINE_P (newdecl)
01060 && DECL_UNINLINABLE (olddecl)
01061 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
01062 {
01063 warning ("%Jfunction %qD redeclared as inline", newdecl, newdecl);
01064 warning ("%Jprevious declaration of %qD with attribute noinline",
01065 olddecl, olddecl);
01066 }
01067 else if (DECL_DECLARED_INLINE_P (olddecl)
01068 && DECL_UNINLINABLE (newdecl)
01069 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
01070 {
01071 warning ("%Jfunction %qD redeclared with attribute noinline",
01072 newdecl, newdecl);
01073 warning ("%Jprevious declaration of %qD was inline",
01074 olddecl, olddecl);
01075 }
01076 }
01077
01078
01079 if (TREE_CODE (olddecl) == FUNCTION_DECL
01080 && DECL_ARTIFICIAL (olddecl))
01081 {
01082 if (TREE_CODE (newdecl) != FUNCTION_DECL)
01083 {
01084
01085 if (DECL_ANTICIPATED (olddecl))
01086 return NULL_TREE;
01087
01088
01089
01090
01091 if (! TREE_PUBLIC (newdecl))
01092 {
01093 if (warn_shadow)
01094 warning ("shadowing %s function %q#D",
01095 DECL_BUILT_IN (olddecl) ? "built-in" : "library",
01096 olddecl);
01097
01098 return NULL_TREE;
01099 }
01100
01101
01102 else if (! DECL_BUILT_IN (olddecl))
01103 warning ("library function %q#D redeclared as non-function %q#D",
01104 olddecl, newdecl);
01105 else
01106 {
01107 error ("declaration of %q#D", newdecl);
01108 error ("conflicts with built-in declaration %q#D",
01109 olddecl);
01110 }
01111 return NULL_TREE;
01112 }
01113 else if (!types_match)
01114 {
01115
01116 if (DECL_ANTICIPATED (olddecl))
01117 {
01118
01119
01120 tree t1, t2;
01121
01122 for (t1 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
01123 t2 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
01124 t1 || t2;
01125 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
01126 if (!t1 || !t2)
01127 break;
01128 else if (TREE_VALUE (t2) == fileptr_type_node)
01129 {
01130 tree t = TREE_VALUE (t1);
01131
01132 if (TREE_CODE (t) == POINTER_TYPE
01133 && TYPE_NAME (TREE_TYPE (t))
01134 && DECL_NAME (TYPE_NAME (TREE_TYPE (t)))
01135 == get_identifier ("FILE")
01136 && compparms (TREE_CHAIN (t1), TREE_CHAIN (t2)))
01137 {
01138 tree oldargs = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
01139
01140 TYPE_ARG_TYPES (TREE_TYPE (olddecl))
01141 = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
01142 types_match = decls_match (newdecl, olddecl);
01143 if (types_match)
01144 return duplicate_decls (newdecl, olddecl);
01145 TYPE_ARG_TYPES (TREE_TYPE (olddecl)) = oldargs;
01146 }
01147 }
01148 else if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
01149 break;
01150 }
01151 else if ((DECL_EXTERN_C_P (newdecl)
01152 && DECL_EXTERN_C_P (olddecl))
01153 || compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
01154 TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
01155 {
01156
01157
01158 if (TREE_PUBLIC (newdecl))
01159 {
01160 warning ("new declaration %q#D", newdecl);
01161 warning ("ambiguates built-in declaration %q#D",
01162 olddecl);
01163 }
01164 else if (warn_shadow)
01165 warning ("shadowing %s function %q#D",
01166 DECL_BUILT_IN (olddecl) ? "built-in" : "library",
01167 olddecl);
01168 }
01169 else
01170
01171 return NULL_TREE;
01172
01173
01174 COPY_DECL_RTL (newdecl, olddecl);
01175 }
01176
01177
01178 else if (DECL_ANTICIPATED (olddecl))
01179 {
01180 tree type = TREE_TYPE (newdecl);
01181 tree attribs = (*targetm.merge_type_attributes)
01182 (TREE_TYPE (olddecl), type);
01183
01184 type = cp_build_type_attribute_variant (type, attribs);
01185 TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = type;
01186 }
01187
01188
01189
01190 TREE_NOTHROW (olddecl) = 0;
01191
01192 if (DECL_THIS_STATIC (newdecl) && !DECL_THIS_STATIC (olddecl))
01193 {
01194
01195
01196 DECL_THIS_STATIC (olddecl) = 1;
01197 TREE_PUBLIC (olddecl) = 0;
01198
01199
01200
01201
01202 SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
01203 COPY_DECL_RTL (newdecl, olddecl);
01204 }
01205 }
01206 else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
01207 {
01208 if ((TREE_CODE (olddecl) == TYPE_DECL && DECL_ARTIFICIAL (olddecl)
01209 && TREE_CODE (newdecl) != TYPE_DECL
01210 && ! (TREE_CODE (newdecl) == TEMPLATE_DECL
01211 && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL))
01212 || (TREE_CODE (newdecl) == TYPE_DECL && DECL_ARTIFICIAL (newdecl)
01213 && TREE_CODE (olddecl) != TYPE_DECL
01214 && ! (TREE_CODE (olddecl) == TEMPLATE_DECL
01215 && (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl))
01216 == TYPE_DECL))))
01217 {
01218
01219
01220
01221
01222
01223 return NULL_TREE;
01224 }
01225
01226 if ((TREE_CODE (newdecl) == FUNCTION_DECL
01227 && DECL_FUNCTION_TEMPLATE_P (olddecl))
01228 || (TREE_CODE (olddecl) == FUNCTION_DECL
01229 && DECL_FUNCTION_TEMPLATE_P (newdecl)))
01230 return NULL_TREE;
01231
01232 error ("%q#D redeclared as different kind of symbol", newdecl);
01233 if (TREE_CODE (olddecl) == TREE_LIST)
01234 olddecl = TREE_VALUE (olddecl);
01235 cp_error_at ("previous declaration of %q#D", olddecl);
01236
01237 return error_mark_node;
01238 }
01239 else if (!types_match)
01240 {
01241 if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl))
01242
01243
01244 return NULL_TREE;
01245
01246 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
01247 {
01248
01249
01250
01251 if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == TYPE_DECL
01252 || TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
01253 {
01254 error ("declaration of template %q#D", newdecl);
01255 cp_error_at ("conflicts with previous declaration %q#D",
01256 olddecl);
01257 }
01258 else if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == FUNCTION_DECL
01259 && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL
01260 && compparms (TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl))),
01261 TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (newdecl))))
01262 && comp_template_parms (DECL_TEMPLATE_PARMS (newdecl),
01263 DECL_TEMPLATE_PARMS (olddecl))
01264
01265
01266 && same_type_p (TREE_TYPE (TREE_TYPE (newdecl)),
01267 TREE_TYPE (TREE_TYPE (olddecl))))
01268 {
01269 error ("new declaration %q#D", newdecl);
01270 cp_error_at ("ambiguates old declaration %q#D", olddecl);
01271 }
01272 return NULL_TREE;
01273 }
01274 if (TREE_CODE (newdecl) == FUNCTION_DECL)
01275 {
01276 if (DECL_EXTERN_C_P (newdecl) && DECL_EXTERN_C_P (olddecl))
01277 {
01278 error ("declaration of C function %q#D conflicts with",
01279 newdecl);
01280 cp_error_at ("previous declaration %q#D here", olddecl);
01281 }
01282 else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
01283 TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
01284 {
01285 error ("new declaration %q#D", newdecl);
01286 cp_error_at ("ambiguates old declaration %q#D", olddecl);
01287 }
01288 else
01289 return NULL_TREE;
01290 }
01291 else
01292 {
01293 error ("conflicting declaration %q#D", newdecl);
01294 cp_error_at ("%qD has a previous declaration as %q#D",
01295 olddecl, olddecl);
01296 return error_mark_node;
01297 }
01298 }
01299 else if (TREE_CODE (newdecl) == FUNCTION_DECL
01300 && ((DECL_TEMPLATE_SPECIALIZATION (olddecl)
01301 && (!DECL_TEMPLATE_INFO (newdecl)
01302 || (DECL_TI_TEMPLATE (newdecl)
01303 != DECL_TI_TEMPLATE (olddecl))))
01304 || (DECL_TEMPLATE_SPECIALIZATION (newdecl)
01305 && (!DECL_TEMPLATE_INFO (olddecl)
01306 || (DECL_TI_TEMPLATE (olddecl)
01307 != DECL_TI_TEMPLATE (newdecl))))))
01308
01309
01310
01311
01312
01313
01314
01315
01316 return NULL_TREE;
01317 else if (TREE_CODE (newdecl) == FUNCTION_DECL
01318 && ((DECL_TEMPLATE_INSTANTIATION (olddecl)
01319 && !DECL_USE_TEMPLATE (newdecl))
01320 || (DECL_TEMPLATE_INSTANTIATION (newdecl)
01321 && !DECL_USE_TEMPLATE (olddecl))))
01322
01323
01324 return NULL_TREE;
01325 else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
01326 {
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336 if (DECL_NAMESPACE_ALIAS (newdecl)
01337 && (DECL_NAMESPACE_ALIAS (newdecl)
01338 == DECL_NAMESPACE_ALIAS (olddecl)))
01339 return olddecl;
01340
01341
01342
01343
01344
01345
01346
01347 error ("declaration of namespace %qD conflicts with", newdecl);
01348 cp_error_at ("previous declaration of namespace %qD here", olddecl);
01349 return error_mark_node;
01350 }
01351 else
01352 {
01353 const char *errmsg = redeclaration_error_message (newdecl, olddecl);
01354 if (errmsg)
01355 {
01356 error (errmsg, newdecl);
01357 if (DECL_NAME (olddecl) != NULL_TREE)
01358 cp_error_at ((DECL_INITIAL (olddecl)
01359 && namespace_bindings_p ())
01360 ? "%q#D previously defined here"
01361 : "%q#D previously declared here", olddecl);
01362 return error_mark_node;
01363 }
01364 else if (TREE_CODE (olddecl) == FUNCTION_DECL
01365 && DECL_INITIAL (olddecl) != NULL_TREE
01366 && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE
01367 && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE)
01368 {
01369
01370 cp_warning_at ("prototype for %q#D", newdecl);
01371 warning ("%Jfollows non-prototype definition here", olddecl);
01372 }
01373 else if (TREE_CODE (olddecl) == FUNCTION_DECL
01374 && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
01375 {
01376
01377
01378
01379 if (current_lang_depth () == 0)
01380 SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
01381 else
01382 {
01383 cp_error_at ("previous declaration of %q#D with %qL linkage",
01384 olddecl, DECL_LANGUAGE (olddecl));
01385 error ("conflicts with new declaration with %qL linkage",
01386 DECL_LANGUAGE (newdecl));
01387 }
01388 }
01389
01390 if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl))
01391 ;
01392 else if (TREE_CODE (olddecl) == FUNCTION_DECL)
01393 {
01394 tree t1 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
01395 tree t2 = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
01396 int i = 1;
01397
01398 if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE)
01399 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2);
01400
01401 for (; t1 && t1 != void_list_node;
01402 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
01403 if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
01404 {
01405 if (1 == simple_cst_equal (TREE_PURPOSE (t1),
01406 TREE_PURPOSE (t2)))
01407 {
01408 pedwarn ("default argument given for parameter %d of %q#D",
01409 i, newdecl);
01410 cp_pedwarn_at ("after previous specification in %q#D",
01411 olddecl);
01412 }
01413 else
01414 {
01415 error ("default argument given for parameter %d of %q#D",
01416 i, newdecl);
01417 cp_error_at ("after previous specification in %q#D",
01418 olddecl);
01419 }
01420 }
01421
01422 if (DECL_DECLARED_INLINE_P (newdecl)
01423 && ! DECL_DECLARED_INLINE_P (olddecl)
01424 && TREE_ADDRESSABLE (olddecl) && warn_inline)
01425 {
01426 warning ("%q#D was used before it was declared inline", newdecl);
01427 warning ("%Jprevious non-inline declaration here", olddecl);
01428 }
01429 }
01430 }
01431
01432
01433
01434
01435
01436
01437
01438
01439 if (TREE_CODE (olddecl) == TYPE_DECL
01440 && (DECL_IMPLICIT_TYPEDEF_P (olddecl)
01441 || DECL_IMPLICIT_TYPEDEF_P (newdecl)))
01442 return NULL_TREE;
01443
01444
01445
01446 warn_extern_redeclared_static (newdecl, olddecl);
01447
01448
01449 if (TREE_CODE (newdecl) == FUNCTION_DECL)
01450 {
01451
01452
01453
01454
01455 if (DECL_VINDEX (olddecl))
01456 DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
01457 if (DECL_CONTEXT (olddecl))
01458 DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
01459 DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
01460 DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
01461 DECL_PURE_VIRTUAL_P (newdecl) |= DECL_PURE_VIRTUAL_P (olddecl);
01462 DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl);
01463 DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl);
01464 if (DECL_OVERLOADED_OPERATOR_P (olddecl) != ERROR_MARK)
01465 SET_OVERLOADED_OPERATOR_CODE
01466 (newdecl, DECL_OVERLOADED_OPERATOR_P (olddecl));
01467 new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE;
01468
01469
01470
01471
01472 if (warn_redundant_decls && ! DECL_ARTIFICIAL (olddecl)
01473 && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
01474
01475 && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))
01476
01477 && ! (DECL_FRIEND_P (newdecl) || DECL_FRIEND_P (olddecl)))
01478 {
01479 warning ("redundant redeclaration of %qD in same scope", newdecl);
01480 cp_warning_at ("previous declaration of %qD", olddecl);
01481 }
01482 }
01483
01484
01485 if (TREE_CODE (olddecl) == TYPE_DECL)
01486 {
01487 tree newtype = TREE_TYPE (newdecl);
01488 tree oldtype = TREE_TYPE (olddecl);
01489
01490 if (newtype != error_mark_node && oldtype != error_mark_node
01491 && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
01492 CLASSTYPE_FRIEND_CLASSES (newtype)
01493 = CLASSTYPE_FRIEND_CLASSES (oldtype);
01494
01495 DECL_ORIGINAL_TYPE (newdecl) = DECL_ORIGINAL_TYPE (olddecl);
01496 }
01497
01498
01499
01500 DECL_ATTRIBUTES (newdecl)
01501 = (*targetm.merge_decl_attributes) (olddecl, newdecl);
01502
01503 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
01504 {
01505 TREE_TYPE (olddecl) = TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl));
01506 DECL_TEMPLATE_SPECIALIZATIONS (olddecl)
01507 = chainon (DECL_TEMPLATE_SPECIALIZATIONS (olddecl),
01508 DECL_TEMPLATE_SPECIALIZATIONS (newdecl));
01509
01510
01511
01512 if (DECL_INITIAL (DECL_TEMPLATE_RESULT (olddecl)) == NULL_TREE
01513 && DECL_INITIAL (DECL_TEMPLATE_RESULT (newdecl)) != NULL_TREE)
01514 {
01515 DECL_SOURCE_LOCATION (olddecl)
01516 = DECL_SOURCE_LOCATION (DECL_TEMPLATE_RESULT (olddecl))
01517 = DECL_SOURCE_LOCATION (newdecl);
01518 if (DECL_FUNCTION_TEMPLATE_P (newdecl))
01519 DECL_ARGUMENTS (DECL_TEMPLATE_RESULT (olddecl))
01520 = DECL_ARGUMENTS (DECL_TEMPLATE_RESULT (newdecl));
01521 }
01522
01523 if (DECL_FUNCTION_TEMPLATE_P (newdecl))
01524 {
01525 DECL_INLINE (DECL_TEMPLATE_RESULT (olddecl))
01526 |= DECL_INLINE (DECL_TEMPLATE_RESULT (newdecl));
01527 DECL_DECLARED_INLINE_P (DECL_TEMPLATE_RESULT (olddecl))
01528 |= DECL_DECLARED_INLINE_P (DECL_TEMPLATE_RESULT (newdecl));
01529 }
01530
01531 return olddecl;
01532 }
01533
01534 if (types_match)
01535 {
01536
01537 tree oldtype = TREE_TYPE (olddecl);
01538 tree newtype;
01539
01540
01541 newtype = merge_types (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
01542
01543
01544 if (TREE_CODE (newdecl) == TYPE_DECL
01545 && newtype == DECL_ORIGINAL_TYPE (newdecl))
01546 newtype = oldtype;
01547
01548 if (TREE_CODE (newdecl) == VAR_DECL)
01549 {
01550 DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
01551 DECL_INITIALIZED_P (newdecl) |= DECL_INITIALIZED_P (olddecl);
01552 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (newdecl)
01553 |= DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (olddecl);
01554 }
01555
01556
01557
01558 else if (TREE_CODE (newdecl) == FUNCTION_DECL
01559 && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))
01560 != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl))))
01561 {
01562 TREE_TYPE (newdecl) = build_exception_variant (newtype,
01563 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)));
01564 TREE_TYPE (olddecl) = build_exception_variant (newtype,
01565 TYPE_RAISES_EXCEPTIONS (oldtype));
01566
01567 if ((pedantic || ! DECL_IN_SYSTEM_HEADER (olddecl))
01568 && ! DECL_IS_BUILTIN (olddecl)
01569 && flag_exceptions
01570 && !comp_except_specs (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)),
01571 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl)), 1))
01572 {
01573 error ("declaration of %qF throws different exceptions",
01574 newdecl);
01575 cp_error_at ("than previous declaration %qF", olddecl);
01576 }
01577 }
01578 TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
01579
01580
01581 if (! same_type_p (newtype, oldtype)
01582 && TREE_TYPE (newdecl) != error_mark_node
01583 && !(processing_template_decl && uses_template_parms (newdecl)))
01584 layout_type (TREE_TYPE (newdecl));
01585
01586 if ((TREE_CODE (newdecl) == VAR_DECL
01587 || TREE_CODE (newdecl) == PARM_DECL
01588 || TREE_CODE (newdecl) == RESULT_DECL
01589 || TREE_CODE (newdecl) == FIELD_DECL
01590 || TREE_CODE (newdecl) == TYPE_DECL)
01591 && !(processing_template_decl && uses_template_parms (newdecl)))
01592 layout_decl (newdecl, 0);
01593
01594
01595 if (TREE_READONLY (newdecl))
01596 TREE_READONLY (olddecl) = 1;
01597 if (TREE_THIS_VOLATILE (newdecl))
01598 TREE_THIS_VOLATILE (olddecl) = 1;
01599 if (TREE_NOTHROW (newdecl))
01600 TREE_NOTHROW (olddecl) = 1;
01601
01602
01603 if (TREE_DEPRECATED (newdecl))
01604 TREE_DEPRECATED (olddecl) = 1;
01605
01606
01607 if (DECL_INITIAL (newdecl) == NULL_TREE
01608 && DECL_INITIAL (olddecl) != NULL_TREE)
01609 {
01610 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
01611 DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
01612 if (CAN_HAVE_FULL_LANG_DECL_P (newdecl)
01613 && DECL_LANG_SPECIFIC (newdecl)
01614 && DECL_LANG_SPECIFIC (olddecl))
01615 {
01616 DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
01617 DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
01618 }
01619 }
01620
01621
01622
01623
01624
01625 if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
01626 DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
01627
01628 if (TREE_CODE (newdecl) == FUNCTION_DECL)
01629 {
01630 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
01631 |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
01632 DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
01633 TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
01634 TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
01635 TREE_NOTHROW (newdecl) |= TREE_NOTHROW (olddecl);
01636 DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
01637 DECL_IS_PURE (newdecl) |= DECL_IS_PURE (olddecl);
01638
01639 COPY_DECL_RTL (olddecl, newdecl);
01640 }
01641 else if (TREE_CODE (newdecl) == VAR_DECL
01642 && (DECL_SIZE (olddecl) || !DECL_SIZE (newdecl)))
01643 {
01644
01645
01646
01647
01648 COPY_DECL_RTL (olddecl, newdecl);
01649 }
01650 }
01651
01652
01653 else
01654 {
01655
01656 tree oldstatic = value_member (olddecl, static_aggregates);
01657 if (oldstatic)
01658 TREE_VALUE (oldstatic) = error_mark_node;
01659
01660 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
01661 TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
01662 TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
01663 TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
01664 }
01665
01666
01667 merge_weak (newdecl, olddecl);
01668
01669 DECL_ONE_ONLY (newdecl) |= DECL_ONE_ONLY (olddecl);
01670 DECL_DEFER_OUTPUT (newdecl) |= DECL_DEFER_OUTPUT (olddecl);
01671 TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
01672 TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
01673 if (! DECL_EXTERNAL (olddecl))
01674 DECL_EXTERNAL (newdecl) = 0;
01675
01676 if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl))
01677 {
01678 DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
01679 DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
01680 DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl);
01681 DECL_TEMPLATE_INSTANTIATED (newdecl)
01682 |= DECL_TEMPLATE_INSTANTIATED (olddecl);
01683
01684
01685
01686
01687
01688 if (!DECL_USE_TEMPLATE (newdecl))
01689 DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl);
01690
01691
01692
01693 DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
01694 DECL_LANG_SPECIFIC (newdecl)->decl_flags.u2 =
01695 DECL_LANG_SPECIFIC (olddecl)->decl_flags.u2;
01696 DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
01697 DECL_REPO_AVAILABLE_P (newdecl) = DECL_REPO_AVAILABLE_P (olddecl);
01698 DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
01699 DECL_INITIALIZED_IN_CLASS_P (newdecl)
01700 |= DECL_INITIALIZED_IN_CLASS_P (olddecl);
01701 olddecl_friend = DECL_FRIEND_P (olddecl);
01702
01703
01704 if (TREE_CODE (newdecl) == FUNCTION_DECL
01705 || DECL_FUNCTION_TEMPLATE_P (newdecl))
01706 {
01707 DECL_BEFRIENDING_CLASSES (newdecl)
01708 = chainon (DECL_BEFRIENDING_CLASSES (newdecl),
01709 DECL_BEFRIENDING_CLASSES (olddecl));
01710
01711
01712 if (DECL_VIRTUAL_P (newdecl))
01713 DECL_THUNKS (newdecl) = DECL_THUNKS (olddecl);
01714 }
01715 }
01716
01717 if (TREE_CODE (newdecl) == FUNCTION_DECL)
01718 {
01719 if (DECL_TEMPLATE_INSTANTIATION (olddecl)
01720 && !DECL_TEMPLATE_INSTANTIATION (newdecl))
01721 {
01722
01723
01724
01725 gcc_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl));
01726
01727 if (TREE_USED (olddecl))
01728
01729
01730
01731
01732
01733
01734
01735
01736 error ("explicit specialization of %qD after first use",
01737 olddecl);
01738
01739 SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
01740
01741
01742
01743 }
01744 else
01745 {
01746 if (DECL_PENDING_INLINE_INFO (newdecl) == 0)
01747 DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl);
01748
01749 DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl);
01750
01751
01752
01753 if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == NULL_TREE)
01754 DECL_INLINE (olddecl) = 1;
01755 DECL_INLINE (newdecl) = DECL_INLINE (olddecl);
01756
01757 DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
01758 = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
01759 }
01760
01761
01762 DECL_ABSTRACT (newdecl) = DECL_ABSTRACT (olddecl);
01763
01764 if (! types_match)
01765 {
01766 SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
01767 COPY_DECL_ASSEMBLER_NAME (newdecl, olddecl);
01768 COPY_DECL_RTL (newdecl, olddecl);
01769 }
01770 if (! types_match || new_defines_function)
01771 {
01772
01773
01774
01775 DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
01776 DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
01777 }
01778 if (new_defines_function)
01779
01780
01781 SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
01782 else if (types_match)
01783 {
01784
01785
01786 if (DECL_BUILT_IN (olddecl))
01787 {
01788 DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl);
01789 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
01790
01791
01792 COPY_DECL_RTL (olddecl, newdecl);
01793 }
01794
01795 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
01796
01797 if (DECL_ARGUMENTS (olddecl))
01798 DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
01799 }
01800 }
01801 else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
01802 NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
01803
01804
01805 TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
01806 TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
01807 DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
01808 COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
01809
01810
01811 if (DECL_VISIBILITY_SPECIFIED (olddecl)
01812 && DECL_VISIBILITY_SPECIFIED (newdecl)
01813 && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
01814 {
01815 warning ("%J%qD: visibility attribute ignored because it",
01816 newdecl, newdecl);
01817 warning ("%Jconflicts with previous declaration here", olddecl);
01818 }
01819
01820 if (DECL_VISIBILITY_SPECIFIED (olddecl))
01821 {
01822 DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
01823 DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
01824 }
01825
01826
01827
01828 if (DECL_LANG_SPECIFIC (olddecl))
01829 {
01830 gcc_assert (DECL_LANG_SPECIFIC (olddecl)
01831 != DECL_LANG_SPECIFIC (newdecl));
01832 ggc_free (DECL_LANG_SPECIFIC (olddecl));
01833 }
01834
01835 if (TREE_CODE (newdecl) == FUNCTION_DECL)
01836 {
01837 int function_size;
01838
01839 function_size = sizeof (struct tree_decl);
01840
01841 memcpy ((char *) olddecl + sizeof (struct tree_common),
01842 (char *) newdecl + sizeof (struct tree_common),
01843 function_size - sizeof (struct tree_common));
01844
01845 if (DECL_TEMPLATE_INFO (newdecl))
01846
01847
01848
01849
01850
01851
01852
01853
01854
01855
01856
01857
01858
01859
01860
01861
01862
01863
01864
01865
01866
01867 reregister_specialization (newdecl,
01868 DECL_TI_TEMPLATE (newdecl),
01869 olddecl);
01870 }
01871 else
01872 {
01873 memcpy ((char *) olddecl + sizeof (struct tree_common),
01874 (char *) newdecl + sizeof (struct tree_common),
01875 sizeof (struct tree_decl) - sizeof (struct tree_common)
01876 + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
01877 }
01878
01879 DECL_UID (olddecl) = olddecl_uid;
01880 if (olddecl_friend)
01881 DECL_FRIEND_P (olddecl) = 1;
01882
01883
01884
01885 DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
01886
01887
01888
01889
01890 if (DECL_RTL_SET_P (olddecl)
01891 && (TREE_CODE (olddecl) == FUNCTION_DECL
01892 || (TREE_CODE (olddecl) == VAR_DECL
01893 && TREE_STATIC (olddecl))))
01894 make_decl_rtl (olddecl);
01895
01896
01897
01898
01899 ggc_free (newdecl);
01900
01901 return olddecl;
01902 }
01903
01904
01905
01906
01907
01908
01909
01910 static const char *
01911 redeclaration_error_message (tree newdecl, tree olddecl)
01912 {
01913 if (TREE_CODE (newdecl) == TYPE_DECL)
01914 {
01915
01916
01917
01918 if (same_type_p (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
01919 return 0;
01920 else
01921 return "redefinition of %q#D";
01922 }
01923 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
01924 {
01925
01926
01927
01928 if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl)
01929 && DECL_INITIAL (olddecl) == NULL_TREE)
01930 return 0;
01931
01932
01933
01934 if (DECL_NAMESPACE_SCOPE_P (olddecl)
01935 && DECL_CONTEXT (olddecl) != DECL_CONTEXT (newdecl)
01936 && ! decls_match (olddecl, newdecl))
01937 return "%qD conflicts with used function";
01938
01939
01940
01941
01942
01943 if (DECL_INITIAL (olddecl) != NULL_TREE
01944 && DECL_INITIAL (newdecl) != NULL_TREE)
01945 {
01946 if (DECL_NAME (olddecl) == NULL_TREE)
01947 return "%q#D not declared in class";
01948 else
01949 return "redefinition of %q#D";
01950 }
01951 return 0;
01952 }
01953 else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
01954 {
01955 tree nt, ot;
01956
01957 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
01958 {
01959 if (COMPLETE_TYPE_P (TREE_TYPE (newdecl))
01960 && COMPLETE_TYPE_P (TREE_TYPE (olddecl)))
01961 return "redefinition of %q#D";
01962 return NULL;
01963 }
01964
01965 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != FUNCTION_DECL
01966 || (DECL_TEMPLATE_RESULT (newdecl)
01967 == DECL_TEMPLATE_RESULT (olddecl)))
01968 return NULL;
01969
01970 nt = DECL_TEMPLATE_RESULT (newdecl);
01971 if (DECL_TEMPLATE_INFO (nt))
01972 nt = DECL_TEMPLATE_RESULT (template_for_substitution (nt));
01973 ot = DECL_TEMPLATE_RESULT (olddecl);
01974 if (DECL_TEMPLATE_INFO (ot))
01975 ot = DECL_TEMPLATE_RESULT (template_for_substitution (ot));
01976 if (DECL_INITIAL (nt) && DECL_INITIAL (ot))
01977 return "redefinition of %q#D";
01978
01979 return NULL;
01980 }
01981 else if (toplevel_bindings_p () || DECL_NAMESPACE_SCOPE_P (newdecl))
01982 {
01983
01984
01985 if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
01986 return 0;
01987
01988 return "redefinition of %q#D";
01989 }
01990 else
01991 {
01992
01993
01994
01995 if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
01996 return "redeclaration of %q#D";
01997 return 0;
01998 }
01999 }
02000
02001
02002
02003 static tree
02004 make_label_decl (tree id, int local_p)
02005 {
02006 tree decl;
02007
02008 decl = build_decl (LABEL_DECL, id, void_type_node);
02009
02010 DECL_CONTEXT (decl) = current_function_decl;
02011 DECL_MODE (decl) = VOIDmode;
02012 C_DECLARED_LABEL_FLAG (decl) = local_p;
02013
02014
02015
02016 DECL_SOURCE_LOCATION (decl) = input_location;
02017
02018
02019 SET_IDENTIFIER_LABEL_VALUE (id, decl);
02020
02021 return decl;
02022 }
02023
02024
02025
02026
02027
02028
02029 static void
02030 use_label (tree decl)
02031 {
02032 if (named_label_uses == NULL
02033 || named_label_uses->names_in_scope != current_binding_level->names
02034 || named_label_uses->label_decl != decl)
02035 {
02036 struct named_label_use_list *new_ent;
02037 new_ent = GGC_NEW (struct named_label_use_list);
02038 new_ent->label_decl = decl;
02039 new_ent->names_in_scope = current_binding_level->names;
02040 new_ent->binding_level = current_binding_level;
02041 new_ent->o_goto_locus = input_location;
02042 new_ent->next = named_label_uses;
02043 named_label_uses = new_ent;
02044 }
02045 }
02046
02047
02048
02049
02050
02051 tree
02052 lookup_label (tree id)
02053 {
02054 tree decl;
02055 struct named_label_list *ent;
02056
02057 timevar_push (TV_NAME_LOOKUP);
02058
02059 if (current_function_decl == NULL_TREE)
02060 {
02061 error ("label %qE referenced outside of any function", id);
02062 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
02063 }
02064
02065
02066 decl = IDENTIFIER_LABEL_VALUE (id);
02067 if (decl != NULL_TREE && DECL_CONTEXT (decl) == current_function_decl)
02068 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
02069
02070
02071
02072
02073 ent = GGC_CNEW (struct named_label_list);
02074 ent->old_value = IDENTIFIER_LABEL_VALUE (id);
02075 ent->next = named_labels;
02076 named_labels = ent;
02077
02078
02079 decl = make_label_decl (id, 0);
02080
02081
02082 ent->label_decl = decl;
02083
02084 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
02085 }
02086
02087
02088
02089 tree
02090 declare_local_label (tree id)
02091 {
02092 tree decl;
02093
02094
02095
02096
02097 current_binding_level->shadowed_labels
02098 = tree_cons (IDENTIFIER_LABEL_VALUE (id), NULL_TREE,
02099 current_binding_level->shadowed_labels);
02100
02101 decl = make_label_decl (id, 1);
02102
02103 TREE_VALUE (current_binding_level->shadowed_labels) = decl;
02104
02105 return decl;
02106 }
02107
02108
02109
02110
02111 static int
02112 decl_jump_unsafe (tree decl)
02113 {
02114 if (TREE_CODE (decl) != VAR_DECL || TREE_STATIC (decl))
02115 return 0;
02116
02117 if (DECL_INITIAL (decl) == NULL_TREE
02118 && pod_type_p (TREE_TYPE (decl)))
02119 return 0;
02120
02121
02122
02123
02124 if (DECL_INITIAL (decl)
02125 || (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))))
02126 return 2;
02127 return 1;
02128 }
02129
02130
02131
02132
02133
02134
02135 static void
02136 check_previous_goto_1 (tree decl,
02137 struct cp_binding_level* level,
02138 tree names, const location_t *locus)
02139 {
02140 int identified = 0;
02141 int saw_eh = 0;
02142 struct cp_binding_level *b = current_binding_level;
02143 for (; b; b = b->level_chain)
02144 {
02145 tree new_decls = b->names;
02146 tree old_decls = (b == level ? names : NULL_TREE);
02147 for (; new_decls != old_decls;
02148 new_decls = TREE_CHAIN (new_decls))
02149 {
02150 int problem = decl_jump_unsafe (new_decls);
02151 if (! problem)
02152 continue;
02153
02154 if (! identified)
02155 {
02156 if (decl)
02157 pedwarn ("jump to label %qD", decl);
02158 else
02159 pedwarn ("jump to case label");
02160
02161 if (locus)
02162 pedwarn ("%H from here", locus);
02163 identified = 1;
02164 }
02165
02166 if (problem > 1)
02167 cp_error_at (" crosses initialization of %q#D",
02168 new_decls);
02169 else
02170 cp_pedwarn_at (" enters scope of non-POD %q#D",
02171 new_decls);
02172 }
02173
02174 if (b == level)
02175 break;
02176 if ((b->kind == sk_try || b->kind == sk_catch) && ! saw_eh)
02177 {
02178 if (! identified)
02179 {
02180 if (decl)
02181 pedwarn ("jump to label %qD", decl);
02182 else
02183 pedwarn ("jump to case label");
02184
02185 if (locus)
02186 pedwarn ("%H from here", locus);
02187 identified = 1;
02188 }
02189 if (b->kind == sk_try)
02190 error (" enters try block");
02191 else
02192 error (" enters catch block");
02193 saw_eh = 1;
02194 }
02195 }
02196 }
02197
02198 static void
02199 check_previous_goto (struct named_label_use_list* use)
02200 {
02201 check_previous_goto_1 (use->label_decl, use->binding_level,
02202 use->names_in_scope, &use->o_goto_locus);
02203 }
02204
02205 static void
02206 check_switch_goto (struct cp_binding_level* level)
02207 {
02208 check_previous_goto_1 (NULL_TREE, level, level->names, NULL);
02209 }
02210
02211
02212
02213
02214 static void
02215 check_previous_gotos (tree decl)
02216 {
02217 struct named_label_use_list **usep;
02218
02219 if (! TREE_USED (decl))
02220 return;
02221
02222 for (usep = &named_label_uses; *usep; )
02223 {
02224 struct named_label_use_list *use = *usep;
02225 if (use->label_decl == decl)
02226 {
02227 check_previous_goto (use);
02228 *usep = use->next;
02229 }
02230 else
02231 usep = &(use->next);
02232 }
02233 }
02234
02235
02236
02237
02238 void
02239 check_goto (tree decl)
02240 {
02241 int identified = 0;
02242 tree bad;
02243 struct named_label_list *lab;
02244
02245
02246
02247 if (! DECL_P (decl))
02248 return;
02249
02250
02251 if (! DECL_INITIAL (decl))
02252 {
02253 use_label (decl);
02254 return;
02255 }
02256
02257 for (lab = named_labels; lab; lab = lab->next)
02258 if (decl == lab->label_decl)
02259 break;
02260
02261
02262
02263 if (lab == 0)
02264 return;
02265
02266 if ((lab->in_try_scope || lab->in_catch_scope || lab->bad_decls)
02267 && !identified)
02268 {
02269 cp_pedwarn_at ("jump to label %qD", decl);
02270 pedwarn (" from here");
02271 identified = 1;
02272 }
02273
02274 for (bad = lab->bad_decls; bad; bad = TREE_CHAIN (bad))
02275 {
02276 tree b = TREE_VALUE (bad);
02277 int u = decl_jump_unsafe (b);
02278
02279 if (u > 1 && DECL_ARTIFICIAL (b))
02280
02281 error ("%J enters catch block", b);
02282 else if (u > 1)
02283 cp_error_at (" skips initialization of %q#D", b);
02284 else
02285 cp_pedwarn_at (" enters scope of non-POD %q#D", b);
02286 }
02287
02288 if (lab->in_try_scope)
02289 error (" enters try block");
02290 else if (lab->in_catch_scope)
02291 error (" enters catch block");
02292 }
02293
02294
02295
02296
02297 tree
02298 define_label (location_t location, tree name)
02299 {
02300 tree decl = lookup_label (name);
02301 struct named_label_list *ent;
02302 struct cp_binding_level *p;
02303
02304 timevar_push (TV_NAME_LOOKUP);
02305 for (ent = named_labels; ent; ent = ent->next)
02306 if (ent->label_decl == decl)
02307 break;
02308
02309
02310
02311 for (p = current_binding_level;
02312 p->kind != sk_function_parms;
02313 p = p->level_chain)
02314 p->more_cleanups_ok = 0;
02315
02316 if (name == get_identifier ("wchar_t"))
02317 pedwarn ("label named wchar_t");
02318
02319 if (DECL_INITIAL (decl) != NULL_TREE)
02320 error ("duplicate label %qD", decl);
02321 else
02322 {
02323
02324 DECL_INITIAL (decl) = error_mark_node;
02325
02326 DECL_SOURCE_LOCATION (decl) = location;
02327 if (ent)
02328 {
02329 ent->names_in_scope = current_binding_level->names;
02330 ent->binding_level = current_binding_level;
02331 }
02332 check_previous_gotos (decl);
02333 }
02334
02335 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
02336 }
02337
02338 struct cp_switch
02339 {
02340 struct cp_binding_level *level;
02341 struct cp_switch *next;
02342
02343 tree switch_stmt;
02344
02345
02346
02347
02348
02349 splay_tree cases;
02350 };
02351
02352
02353
02354
02355
02356
02357
02358 static struct cp_switch *switch_stack;
02359
02360
02361
02362
02363 void
02364 push_switch (tree switch_stmt)
02365 {
02366 struct cp_switch *p = xmalloc (sizeof (struct cp_switch));
02367 p->level = current_binding_level;
02368 p->next = switch_stack;
02369 p->switch_stmt = switch_stmt;
02370 p->cases = splay_tree_new (case_compare, NULL, NULL);
02371 switch_stack = p;
02372 }
02373
02374 void
02375 pop_switch (void)
02376 {
02377 struct cp_switch *cs = switch_stack;
02378
02379
02380 c_do_switch_warnings (cs->cases, cs->switch_stmt);
02381
02382 splay_tree_delete (cs->cases);
02383 switch_stack = switch_stack->next;
02384 free (cs);
02385 }
02386
02387
02388
02389
02390 tree
02391 finish_case_label (tree low_value, tree high_value)
02392 {
02393 tree cond, r;
02394 struct cp_binding_level *p;
02395
02396 if (processing_template_decl)
02397 {
02398 tree label;
02399
02400
02401
02402 label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
02403 return add_stmt (build_case_label (low_value, high_value, label));
02404 }
02405
02406
02407 cond = SWITCH_STMT_COND (switch_stack->switch_stmt);
02408 if (cond && TREE_CODE (cond) == TREE_LIST)
02409 cond = TREE_VALUE (cond);
02410
02411 r = c_add_case_label (switch_stack->cases, cond, TREE_TYPE (cond),
02412 low_value, high_value);
02413
02414 check_switch_goto (switch_stack->level);
02415
02416
02417
02418 for (p = current_binding_level;
02419 p->kind != sk_function_parms;
02420 p = p->level_chain)
02421 p->more_cleanups_ok = 0;
02422
02423 return r;
02424 }
02425
02426
02427
02428 static hashval_t
02429 typename_hash (const void* k)
02430 {
02431 hashval_t hash;
02432 tree t = (tree) k;
02433
02434 hash = (htab_hash_pointer (TYPE_CONTEXT (t))
02435 ^ htab_hash_pointer (DECL_NAME (TYPE_NAME (t))));
02436
02437 return hash;
02438 }
02439
02440 typedef struct typename_info {
02441 tree scope;
02442 tree name;
02443 tree template_id;
02444 bool enum_p;
02445 bool class_p;
02446 } typename_info;
02447
02448
02449
02450 static int
02451 typename_compare (const void * k1, const void * k2)
02452 {
02453 tree t1;
02454 const typename_info *t2;
02455
02456 t1 = (tree) k1;
02457 t2 = (const typename_info *) k2;
02458
02459 return (DECL_NAME (TYPE_NAME (t1)) == t2->name
02460 && TYPE_CONTEXT (t1) == t2->scope
02461 && TYPENAME_TYPE_FULLNAME (t1) == t2->template_id
02462 && TYPENAME_IS_ENUM_P (t1) == t2->enum_p
02463 && TYPENAME_IS_CLASS_P (t1) == t2->class_p);
02464 }
02465
02466
02467
02468
02469
02470
02471 static GTY ((param_is (union tree_node))) htab_t typename_htab;
02472
02473 static tree
02474 build_typename_type (tree context, tree name, tree fullname,
02475 enum tag_types tag_type)
02476 {
02477 tree t;
02478 tree d;
02479 typename_info ti;
02480 void **e;
02481 hashval_t hash;
02482
02483 if (typename_htab == NULL)
02484 typename_htab = htab_create_ggc (61, &typename_hash,
02485 &typename_compare, NULL);
02486
02487 ti.scope = FROB_CONTEXT (context);
02488 ti.name = name;
02489 ti.template_id = fullname;
02490 ti.enum_p = tag_type == enum_type;
02491 ti.class_p = (tag_type == class_type
02492 || tag_type == record_type
02493 || tag_type == union_type);
02494 hash = (htab_hash_pointer (ti.scope)
02495 ^ htab_hash_pointer (ti.name));
02496
02497
02498 e = htab_find_slot_with_hash (typename_htab, &ti, hash, INSERT);
02499 if (*e)
02500 t = (tree) *e;
02501 else
02502 {
02503
02504 t = make_aggr_type (TYPENAME_TYPE);
02505 TYPE_CONTEXT (t) = ti.scope;
02506 TYPENAME_TYPE_FULLNAME (t) = ti.template_id;
02507 TYPENAME_IS_ENUM_P (t) = ti.enum_p;
02508 TYPENAME_IS_CLASS_P (t) = ti.class_p;
02509
02510
02511 d = build_decl (TYPE_DECL, name, t);
02512 TYPE_NAME (TREE_TYPE (d)) = d;
02513 TYPE_STUB_DECL (TREE_TYPE (d)) = d;
02514 DECL_CONTEXT (d) = FROB_CONTEXT (context);
02515 DECL_ARTIFICIAL (d) = 1;
02516
02517
02518 *e = t;
02519 }
02520
02521 return t;
02522 }
02523
02524
02525
02526
02527
02528
02529
02530
02531
02532 tree
02533 make_typename_type (tree context, tree name, enum tag_types tag_type,
02534 tsubst_flags_t complain)
02535 {
02536 tree fullname;
02537
02538 if (name == error_mark_node
02539 || context == NULL_TREE
02540 || context == error_mark_node)
02541 return error_mark_node;
02542
02543 if (TYPE_P (name))
02544 {
02545 if (!(TYPE_LANG_SPECIFIC (name)
02546 && (CLASSTYPE_IS_TEMPLATE (name)
02547 || CLASSTYPE_USE_TEMPLATE (name))))
02548 name = TYPE_IDENTIFIER (name);
02549 else
02550
02551 name = build_nt (TEMPLATE_ID_EXPR,
02552 CLASSTYPE_TI_TEMPLATE (name),
02553 CLASSTYPE_TI_ARGS (name));
02554 }
02555 else if (TREE_CODE (name) == TYPE_DECL)
02556 name = DECL_NAME (name);
02557
02558 fullname = name;
02559
02560 if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
02561 {
02562 name = TREE_OPERAND (name, 0);
02563 if (TREE_CODE (name) == TEMPLATE_DECL)
02564 name = TREE_OPERAND (fullname, 0) = DECL_NAME (name);
02565 }
02566 if (TREE_CODE (name) == TEMPLATE_DECL)
02567 {
02568 error ("%qD used without template parameters", name);
02569 return error_mark_node;
02570 }
02571 gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
02572 gcc_assert (TYPE_P (context));
02573
02574 if (!dependent_type_p (context)
02575 || currently_open_class (context))
02576 {
02577 if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR)
02578 {
02579 tree tmpl = NULL_TREE;
02580 if (IS_AGGR_TYPE (context))
02581 tmpl = lookup_field (context, name, 0, false);
02582 if (!tmpl || !DECL_CLASS_TEMPLATE_P (tmpl))
02583 {
02584 if (complain & tf_error)
02585 error ("no class template named %q#T in %q#T",
02586 name, context);
02587 return error_mark_node;
02588 }
02589
02590 if (complain & tf_error)
02591 perform_or_defer_access_check (TYPE_BINFO (context), tmpl);
02592
02593 return lookup_template_class (tmpl,
02594 TREE_OPERAND (fullname, 1),
02595 NULL_TREE, context,
02596 0,
02597 tf_error | tf_warning | tf_user);
02598 }
02599 else
02600 {
02601 tree t;
02602
02603 if (!IS_AGGR_TYPE (context))
02604 {
02605 if (complain & tf_error)
02606 error ("no type named %q#T in %q#T", name, context);
02607 return error_mark_node;
02608 }
02609
02610 t = lookup_field (context, name, 0, true);
02611 if (t)
02612 {
02613 if (TREE_CODE (t) != TYPE_DECL)
02614 {
02615 if (complain & tf_error)
02616 error ("no type named %q#T in %q#T", name, context);
02617 return error_mark_node;
02618 }
02619
02620 if (complain & tf_error)
02621 perform_or_defer_access_check (TYPE_BINFO (context), t);
02622
02623 if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
02624 t = TREE_TYPE (t);
02625
02626 return t;
02627 }
02628 }
02629 }
02630
02631
02632
02633 if (!dependent_type_p (context))
02634 {
02635 if (complain & tf_error)
02636 error ("no type named %q#T in %q#T", name, context);
02637 return error_mark_node;
02638 }
02639
02640 return build_typename_type (context, name, fullname, tag_type);
02641 }
02642
02643
02644
02645
02646
02647
02648
02649
02650
02651
02652 tree
02653 make_unbound_class_template (tree context, tree name, tree parm_list,
02654 tsubst_flags_t complain)
02655 {
02656 tree t;
02657 tree d;
02658
02659 if (TYPE_P (name))
02660 name = TYPE_IDENTIFIER (name);
02661 else if (DECL_P (name))
02662 name = DECL_NAME (name);
02663 gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
02664
02665 if (!dependent_type_p (context)
02666 || currently_open_class (context))
02667 {
02668 tree tmpl = NULL_TREE;
02669
02670 if (IS_AGGR_TYPE (context))
02671 tmpl = lookup_field (context, name, 0, false);
02672
02673 if (!tmpl || !DECL_CLASS_TEMPLATE_P (tmpl))
02674 {
02675 if (complain & tf_error)
02676 error ("no class template named %q#T in %q#T", name, context);
02677 return error_mark_node;
02678 }
02679
02680 if (parm_list
02681 && !comp_template_parms (DECL_TEMPLATE_PARMS (tmpl), parm_list))
02682 {
02683 if (complain & tf_error)
02684 {
02685 error ("template parameters do not match template");
02686 cp_error_at ("%qD declared here", tmpl);
02687 }
02688 return error_mark_node;
02689 }
02690
02691 if (complain & tf_error)
02692 perform_or_defer_access_check (TYPE_BINFO (context), tmpl);
02693
02694 return tmpl;
02695 }
02696
02697
02698 t = make_aggr_type (UNBOUND_CLASS_TEMPLATE);
02699 TYPE_CONTEXT (t) = FROB_CONTEXT (context);
02700 TREE_TYPE (t) = NULL_TREE;
02701
02702
02703 d = build_decl (TEMPLATE_DECL, name, t);
02704 TYPE_NAME (TREE_TYPE (d)) = d;
02705 TYPE_STUB_DECL (TREE_TYPE (d)) = d;
02706 DECL_CONTEXT (d) = FROB_CONTEXT (context);
02707 DECL_ARTIFICIAL (d) = 1;
02708 DECL_TEMPLATE_PARMS (d) = parm_list;
02709
02710 return t;
02711 }
02712
02713
02714
02715
02716
02717
02718
02719
02720 void
02721 record_builtin_type (enum rid rid_index,
02722 const char* name,
02723 tree type)
02724 {
02725 tree rname = NULL_TREE, tname = NULL_TREE;
02726 tree tdecl = NULL_TREE;
02727
02728 if ((int) rid_index < (int) RID_MAX)
02729 rname = ridpointers[(int) rid_index];
02730 if (name)
02731 tname = get_identifier (name);
02732
02733
02734
02735
02736
02737
02738 if (tname)
02739 {
02740 tdecl = build_decl (TYPE_DECL, tname, type);
02741 DECL_ARTIFICIAL (tdecl) = 1;
02742 SET_IDENTIFIER_GLOBAL_VALUE (tname, tdecl);
02743 }
02744 if (rname)
02745 {
02746 if (!tdecl)
02747 {
02748 tdecl = build_decl (TYPE_DECL, rname, type);
02749 DECL_ARTIFICIAL (tdecl) = 1;
02750 }
02751 SET_IDENTIFIER_GLOBAL_VALUE (rname, tdecl);
02752 }
02753
02754 if (!TYPE_NAME (type))
02755 TYPE_NAME (type) = tdecl;
02756
02757 if (tdecl)
02758 debug_hooks->type_decl (tdecl, 0);
02759 }
02760
02761
02762
02763
02764
02765
02766 static tree
02767 record_builtin_java_type (const char* name, int size)
02768 {
02769 tree type, decl;
02770 if (size > 0)
02771 type = make_signed_type (size);
02772 else if (size > -32)
02773 {
02774 type = make_unsigned_type (-size);
02775
02776 }
02777 else
02778 {
02779 type = make_node (REAL_TYPE);
02780 TYPE_PRECISION (type) = - size;
02781 layout_type (type);
02782 }
02783 record_builtin_type (RID_MAX, name, type);
02784 decl = TYPE_NAME (type);
02785
02786
02787
02788
02789 DECL_IGNORED_P (decl) = 1;
02790
02791 TYPE_FOR_JAVA (type) = 1;
02792 return type;
02793 }
02794
02795
02796
02797 static void
02798 record_unknown_type (tree type, const char* name)
02799 {
02800 tree decl = pushdecl (build_decl (TYPE_DECL, get_identifier (name), type));
02801
02802 DECL_IGNORED_P (decl) = 1;
02803 TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
02804 TYPE_SIZE (type) = TYPE_SIZE (void_type_node);
02805 TYPE_ALIGN (type) = 1;
02806 TYPE_USER_ALIGN (type) = 0;
02807 TYPE_MODE (type) = TYPE_MODE (void_type_node);
02808 }
02809
02810
02811
02812
02813 typedef struct predefined_identifier
02814 {
02815
02816 const char *const name;
02817
02818 tree *const node;
02819
02820 const int ctor_or_dtor_p;
02821 } predefined_identifier;
02822
02823
02824
02825 static void
02826 initialize_predefined_identifiers (void)
02827 {
02828 const predefined_identifier *pid;
02829
02830
02831 static const predefined_identifier predefined_identifiers[] = {
02832 { "C++", &lang_name_cplusplus, 0 },
02833 { "C", &lang_name_c, 0 },
02834 { "Java", &lang_name_java, 0 },
02835
02836
02837 { "__ct ", &ctor_identifier, 1 },
02838 { "__base_ctor ", &base_ctor_identifier, 1 },
02839 { "__comp_ctor ", &complete_ctor_identifier, 1 },
02840 { "__dt ", &dtor_identifier, 1 },
02841 { "__comp_dtor ", &complete_dtor_identifier, 1 },
02842 { "__base_dtor ", &base_dtor_identifier, 1 },
02843 { "__deleting_dtor ", &deleting_dtor_identifier, 1 },
02844 { IN_CHARGE_NAME, &in_charge_identifier, 0 },
02845 { "nelts", &nelts_identifier, 0 },
02846 { THIS_NAME, &this_identifier, 0 },
02847 { VTABLE_DELTA_NAME, &delta_identifier, 0 },
02848 { VTABLE_PFN_NAME, &pfn_identifier, 0 },
02849 { "_vptr", &vptr_identifier, 0 },
02850 { "__vtt_parm", &vtt_parm_identifier, 0 },
02851 { "::", &global_scope_name, 0 },
02852 { "std", &std_identifier, 0 },
02853 { NULL, NULL, 0 }
02854 };
02855
02856 for (pid = predefined_identifiers; pid->name; ++pid)
02857 {
02858 *pid->node = get_identifier (pid->name);
02859 if (pid->ctor_or_dtor_p)
02860 IDENTIFIER_CTOR_OR_DTOR_P (*pid->node) = 1;
02861 }
02862 }
02863
02864
02865
02866
02867
02868
02869 void
02870 cxx_init_decl_processing (void)
02871 {
02872 tree void_ftype;
02873 tree void_ftype_ptr;
02874
02875 build_common_tree_nodes (flag_signed_char, false);
02876
02877
02878 initialize_predefined_identifiers ();
02879
02880
02881 push_to_top_level ();
02882
02883 current_function_decl = NULL_TREE;
02884 current_binding_level = NULL;
02885
02886 gcc_assert (global_namespace == NULL_TREE);
02887 global_namespace = build_lang_decl (NAMESPACE_DECL, global_scope_name,
02888 void_type_node);
02889 begin_scope (sk_namespace, global_namespace);
02890
02891 current_lang_name = NULL_TREE;
02892
02893
02894 if (!flag_permissive)
02895 flag_pedantic_errors = 1;
02896 if (!flag_no_inline)
02897 {
02898 flag_inline_trees = 1;
02899 flag_no_inline = 1;
02900 }
02901 if (flag_inline_functions)
02902 flag_inline_trees = 2;
02903
02904
02905
02906 if (TARGET_PTRMEMFUNC_VBIT_LOCATION == ptrmemfunc_vbit_in_pfn
02907 && force_align_functions_log < 1)
02908 force_align_functions_log = 1;
02909
02910
02911 current_lang_name = lang_name_c;
02912
02913 error_mark_list = build_tree_list (error_mark_node, error_mark_node);
02914 TREE_TYPE (error_mark_list) = error_mark_node;
02915
02916
02917 push_namespace (std_identifier);
02918 std_node = current_namespace;
02919 pop_namespace ();
02920
02921 c_common_nodes_and_builtins ();
02922
02923 java_byte_type_node = record_builtin_java_type ("__java_byte", 8);
02924 java_short_type_node = record_builtin_java_type ("__java_short", 16);
02925 java_int_type_node = record_builtin_java_type ("__java_int", 32);
02926 java_long_type_node = record_builtin_java_type ("__java_long", 64);
02927 java_float_type_node = record_builtin_java_type ("__java_float", -32);
02928 java_double_type_node = record_builtin_java_type ("__java_double", -64);
02929 java_char_type_node = record_builtin_java_type ("__java_char", -16);
02930 java_boolean_type_node = record_builtin_java_type ("__java_boolean", -1);
02931
02932 integer_two_node = build_int_cst (NULL_TREE, 2);
02933 integer_three_node = build_int_cst (NULL_TREE, 3);
02934
02935 record_builtin_type (RID_BOOL, "bool", boolean_type_node);
02936 truthvalue_type_node = boolean_type_node;
02937 truthvalue_false_node = boolean_false_node;
02938 truthvalue_true_node = boolean_true_node;
02939
02940 empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE);
02941
02942 #if 0
02943 record_builtin_type (RID_MAX, NULL, string_type_node);
02944 #endif
02945
02946 delta_type_node = ptrdiff_type_node;
02947 vtable_index_type = ptrdiff_type_node;
02948
02949 vtt_parm_type = build_pointer_type (const_ptr_type_node);
02950 void_ftype = build_function_type (void_type_node, void_list_node);
02951 void_ftype_ptr = build_function_type (void_type_node,
02952 tree_cons (NULL_TREE,
02953 ptr_type_node,
02954 void_list_node));
02955 void_ftype_ptr
02956 = build_exception_variant (void_ftype_ptr, empty_except_spec);
02957
02958
02959
02960 unknown_type_node = make_node (UNKNOWN_TYPE);
02961 record_unknown_type (unknown_type_node, "unknown type");
02962
02963
02964 TREE_TYPE (unknown_type_node) = unknown_type_node;
02965
02966
02967
02968 TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
02969 TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
02970
02971 {
02972
02973
02974 tree vfunc_type = make_node (FUNCTION_TYPE);
02975 TREE_TYPE (vfunc_type) = integer_type_node;
02976 TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
02977 layout_type (vfunc_type);
02978
02979 vtable_entry_type = build_pointer_type (vfunc_type);
02980 }
02981 record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type);
02982
02983 vtbl_type_node
02984 = build_cplus_array_type (vtable_entry_type, NULL_TREE);
02985 layout_type (vtbl_type_node);
02986 vtbl_type_node = build_qualified_type (vtbl_type_node, TYPE_QUAL_CONST);
02987 record_builtin_type (RID_MAX, NULL, vtbl_type_node);
02988 vtbl_ptr_type_node = build_pointer_type (vtable_entry_type);
02989 layout_type (vtbl_ptr_type_node);
02990 record_builtin_type (RID_MAX, NULL, vtbl_ptr_type_node);
02991
02992 push_namespace (get_identifier ("__cxxabiv1"));
02993 abi_node = current_namespace;
02994 pop_namespace ();
02995
02996 global_type_node = make_node (LANG_TYPE);
02997 record_unknown_type (global_type_node, "global type");
02998
02999
03000 current_lang_name = lang_name_cplusplus;
03001
03002 {
03003 tree bad_alloc_id;
03004 tree bad_alloc_type_node;
03005 tree bad_alloc_decl;
03006 tree newtype, deltype;
03007 tree ptr_ftype_sizetype;
03008
03009 push_namespace (std_identifier);
03010 bad_alloc_id = get_identifier ("bad_alloc");
03011 bad_alloc_type_node = make_aggr_type (RECORD_TYPE);
03012 TYPE_CONTEXT (bad_alloc_type_node) = current_namespace;
03013 bad_alloc_decl
03014 = create_implicit_typedef (bad_alloc_id, bad_alloc_type_node);
03015 DECL_CONTEXT (bad_alloc_decl) = current_namespace;
03016 TYPE_STUB_DECL (bad_alloc_type_node) = bad_alloc_decl;
03017 pop_namespace ();
03018
03019 ptr_ftype_sizetype
03020 = build_function_type (ptr_type_node,
03021 tree_cons (NULL_TREE,
03022 size_type_node,
03023 void_list_node));
03024 newtype = build_exception_variant
03025 (ptr_ftype_sizetype, add_exception_specifier
03026 (NULL_TREE, bad_alloc_type_node, -1));
03027 deltype = build_exception_variant (void_ftype_ptr, empty_except_spec);
03028 push_cp_library_fn (NEW_EXPR, newtype);
03029 push_cp_library_fn (VEC_NEW_EXPR, newtype);
03030 global_delete_fndecl = push_cp_library_fn (DELETE_EXPR, deltype);
03031 push_cp_library_fn (VEC_DELETE_EXPR, deltype);
03032 }
03033
03034 abort_fndecl
03035 = build_library_fn_ptr ("__cxa_pure_virtual", void_ftype);
03036
03037
03038 init_class_processing ();
03039 init_rtti_processing ();
03040
03041 if (flag_exceptions)
03042 init_exception_processing ();
03043
03044 if (! supports_one_only ())
03045 flag_weak = 0;
03046
03047 make_fname_decl = cp_make_fname_decl;
03048 start_fname_decls ();
03049
03050
03051 if (flag_exceptions)
03052 using_eh_for_cleanups ();
03053 }
03054
03055
03056
03057
03058
03059 tree
03060 cp_fname_init (const char* name, tree *type_p)
03061 {
03062 tree domain = NULL_TREE;
03063 tree type;
03064 tree init = NULL_TREE;
03065 size_t length = 0;
03066
03067 if (name)
03068 {
03069 length = strlen (name);
03070 domain = build_index_type (size_int (length));
03071 init = build_string (length + 1, name);
03072 }
03073
03074 type = build_qualified_type (char_type_node, TYPE_QUAL_CONST);
03075 type = build_cplus_array_type (type, domain);
03076
03077 *type_p = type;
03078
03079 if (init)
03080 TREE_TYPE (init) = type;
03081 else
03082 init = error_mark_node;
03083
03084 return init;
03085 }
03086
03087
03088
03089
03090
03091
03092
03093 static tree
03094 cp_make_fname_decl (tree id, int type_dep)
03095 {
03096 const char *const name = (type_dep && processing_template_decl
03097 ? NULL : fname_as_string (type_dep));
03098 tree type;
03099 tree init = cp_fname_init (name, &type);
03100 tree decl = build_decl (VAR_DECL, id, type);
03101
03102 if (name)
03103 free ((char *) name);
03104
03105
03106 DECL_CONTEXT (decl) = current_function_decl;
03107 DECL_PRETTY_FUNCTION_P (decl) = type_dep;
03108
03109 TREE_STATIC (decl) = 1;
03110 TREE_READONLY (decl) = 1;
03111 DECL_ARTIFICIAL (decl) = 1;
03112 DECL_INITIAL (decl) = init;
03113
03114 TREE_USED (decl) = 1;
03115
03116 if (current_function_decl)
03117 {
03118 struct cp_binding_level *b = current_binding_level;
03119 while (b->level_chain->kind != sk_function_parms)
03120 b = b->level_chain;
03121 pushdecl_with_scope (decl, b);
03122 cp_finish_decl (decl, init, NULL_TREE, LOOKUP_ONLYCONVERTING);
03123 }
03124 else
03125 pushdecl_top_level_and_finish (decl, init);
03126
03127 return decl;
03128 }
03129
03130
03131
03132
03133
03134
03135
03136
03137
03138
03139
03140
03141
03142 static tree
03143 builtin_function_1 (const char* name,
03144 tree type,
03145 tree context,
03146 enum built_in_function code,
03147 enum built_in_class class,
03148 const char* libname,
03149 tree attrs)
03150 {
03151 tree decl = build_library_fn_1 (get_identifier (name), ERROR_MARK, type);
03152 DECL_BUILT_IN_CLASS (decl) = class;
03153 DECL_FUNCTION_CODE (decl) = code;
03154 DECL_CONTEXT (decl) = context;
03155
03156 pushdecl (decl);
03157
03158
03159
03160
03161 if (libname)
03162 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (libname));
03163
03164
03165
03166 if (name[0] != '_' || name[1] != '_')
03167 DECL_ANTICIPATED (decl) = 1;
03168
03169
03170 if (attrs)
03171 decl_attributes (&decl, attrs, ATTR_FLAG_BUILT_IN);
03172 else
03173 decl_attributes (&decl, NULL_TREE, 0);
03174
03175 return decl;
03176 }
03177
03178
03179
03180
03181
03182
03183
03184
03185
03186
03187
03188
03189
03190
03191
03192
03193
03194 tree
03195 builtin_function (const char* name,
03196 tree type,
03197 int code,
03198 enum built_in_class cl,
03199 const char* libname,
03200 tree attrs)
03201 {
03202
03203
03204 if (name[0] != '_')
03205 {
03206 push_namespace (std_identifier);
03207 builtin_function_1 (name, type, std_node, code, cl, libname, attrs);
03208 pop_namespace ();
03209 }
03210
03211 return builtin_function_1 (name, type, NULL_TREE, code,
03212 cl, libname, attrs);
03213 }
03214
03215
03216
03217
03218 static tree
03219 build_library_fn_1 (tree name, enum tree_code operator_code, tree type)
03220 {
03221 tree fn = build_lang_decl (FUNCTION_DECL, name, type);
03222 DECL_EXTERNAL (fn) = 1;
03223 TREE_PUBLIC (fn) = 1;
03224 DECL_ARTIFICIAL (fn) = 1;
03225 TREE_NOTHROW (fn) = 1;
03226 SET_OVERLOADED_OPERATOR_CODE (fn, operator_code);
03227 SET_DECL_LANGUAGE (fn, lang_c);
03228
03229
03230 DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
03231 DECL_VISIBILITY_SPECIFIED (fn) = 1;
03232 return fn;
03233 }
03234
03235
03236
03237
03238
03239 tree
03240 build_library_fn (tree name, tree type)
03241 {
03242 return build_library_fn_1 (name, ERROR_MARK, type);
03243 }
03244
03245
03246
03247 static tree
03248 build_cp_library_fn (tree name, enum tree_code operator_code, tree type)
03249 {
03250 tree fn = build_library_fn_1 (name, operator_code, type);
03251 TREE_NOTHROW (fn) = TYPE_NOTHROW_P (type);
03252 DECL_CONTEXT (fn) = FROB_CONTEXT (current_namespace);
03253 SET_DECL_LANGUAGE (fn, lang_cplusplus);
03254 return fn;
03255 }
03256
03257
03258
03259
03260 tree
03261 build_library_fn_ptr (const char* name, tree type)
03262 {
03263 return build_library_fn (get_identifier (name), type);
03264 }
03265
03266
03267
03268
03269 tree
03270 build_cp_library_fn_ptr (const char* name, tree type)
03271 {
03272 return build_cp_library_fn (get_identifier (name), ERROR_MARK, type);
03273 }
03274
03275
03276
03277
03278 tree
03279 push_library_fn (tree name, tree type)
03280 {
03281 tree fn = build_library_fn (name, type);
03282 pushdecl_top_level (fn);
03283 return fn;
03284 }
03285
03286
03287
03288
03289 static tree
03290 push_cp_library_fn (enum tree_code operator_code, tree type)
03291 {
03292 tree fn = build_cp_library_fn (ansi_opname (operator_code),
03293 operator_code,
03294 type);
03295 pushdecl (fn);
03296 return fn;
03297 }
03298
03299
03300
03301
03302 tree
03303 push_void_library_fn (tree name, tree parmtypes)
03304 {
03305 tree type = build_function_type (void_type_node, parmtypes);
03306 return push_library_fn (name, type);
03307 }
03308
03309
03310
03311
03312 tree
03313 push_throw_library_fn (tree name, tree type)
03314 {
03315 tree fn = push_library_fn (name, type);
03316 TREE_THIS_VOLATILE (fn) = 1;
03317 TREE_NOTHROW (fn) = 0;
03318 return fn;
03319 }
03320
03321
03322
03323
03324
03325
03326
03327
03328
03329
03330
03331 void
03332 fixup_anonymous_aggr (tree t)
03333 {
03334 tree *q;
03335
03336
03337 TYPE_HAS_CONSTRUCTOR (t) = 0;
03338 TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
03339 TYPE_HAS_INIT_REF (t) = 0;
03340 TYPE_HAS_CONST_INIT_REF (t) = 0;
03341 TYPE_HAS_ASSIGN_REF (t) = 0;
03342 TYPE_HAS_CONST_ASSIGN_REF (t) = 0;
03343
03344
03345
03346 q = &TYPE_METHODS (t);
03347 while (*q)
03348 {
03349 if (DECL_ARTIFICIAL (*q))
03350 *q = TREE_CHAIN (*q);
03351 else
03352 q = &TREE_CHAIN (*q);
03353 }
03354
03355
03356 if (TYPE_METHODS (t))
03357 error ("%Jan anonymous union cannot have function members",
03358 TYPE_MAIN_DECL (t));
03359
03360
03361
03362
03363
03364 if (TREE_CODE (t) != UNION_TYPE)
03365 {
03366 tree field, type;
03367
03368 for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
03369 if (TREE_CODE (field) == FIELD_DECL)
03370 {
03371 type = TREE_TYPE (field);
03372 if (CLASS_TYPE_P (type))
03373 {
03374 if (TYPE_NEEDS_CONSTRUCTING (type))
03375 cp_error_at ("member %q#D with constructor not allowed "
03376 "in anonymous aggregate",
03377 field);
03378 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
03379 cp_error_at ("member %q#D with destructor not allowed "
03380 "in anonymous aggregate",
03381 field);
03382 if (TYPE_HAS_COMPLEX_ASSIGN_REF (type))
03383 cp_error_at ("member %q#D with copy assignment operator "
03384 "not allowed in anonymous aggregate",
03385 field);
03386 }
03387 }
03388 }
03389 }
03390
03391
03392
03393
03394
03395
03396 tree
03397 check_tag_decl (cp_decl_specifier_seq *declspecs)
03398 {
03399 int saw_friend = declspecs->specs[(int)ds_friend] != 0;
03400 int saw_typedef = declspecs->specs[(int)ds_typedef] != 0;
03401
03402
03403
03404
03405 tree declared_type = NULL_TREE;
03406 bool error_p = false;
03407
03408 if (declspecs->multiple_types_p)
03409 error ("multiple types in one declaration");
03410 else if (declspecs->redefined_builtin_type)
03411 {
03412 if (!in_system_header)
03413 pedwarn ("redeclaration of C++ built-in type %qT",
03414 declspecs->redefined_builtin_type);
03415 return NULL_TREE;
03416 }
03417
03418 if (declspecs->type
03419 && TYPE_P (declspecs->type)
03420 && ((TREE_CODE (declspecs->type) != TYPENAME_TYPE
03421 && IS_AGGR_TYPE (declspecs->type))
03422 || TREE_CODE (declspecs->type) == ENUMERAL_TYPE))
03423 declared_type = declspecs->type;
03424 else if (declspecs->type == error_mark_node)
03425 error_p = true;
03426 if (declared_type == NULL_TREE && ! saw_friend && !error_p)
03427 pedwarn ("declaration does not declare anything");
03428
03429 else if (declared_type && IS_AGGR_TYPE_CODE (TREE_CODE (declared_type))
03430 && TYPE_ANONYMOUS_P (declared_type))
03431 {
03432
03433
03434
03435
03436
03437
03438
03439
03440
03441
03442
03443
03444
03445
03446
03447
03448 if (saw_typedef)
03449 {
03450 error ("missing type-name in typedef-declaration");
03451 return NULL_TREE;
03452 }
03453 ;
03454 SET_ANON_AGGR_TYPE_P (declared_type);
03455
03456 if (TREE_CODE (declared_type) != UNION_TYPE && pedantic
03457 && !in_system_header)
03458 pedwarn ("ISO C++ prohibits anonymous structs");
03459 }
03460
03461 else
03462 {
03463 if (declspecs->specs[(int)ds_inline]
03464 || declspecs->specs[(int)ds_virtual])
03465 error ("%qs can only be specified for functions",
03466 declspecs->specs[(int)ds_inline]
03467 ? "inline" : "virtual");
03468 else if (saw_friend
03469 && (!current_class_type
03470 || current_scope () != current_class_type))
03471 error ("%<friend%> can only be specified inside a class");
03472 else if (declspecs->specs[(int)ds_explicit])
03473 error ("%<explicit%> can only be specified for constructors");
03474 else if (declspecs->storage_class)
03475 error ("a storage class can only be specified for objects "
03476 "and functions");
03477 else if (declspecs->specs[(int)ds_const]
03478 || declspecs->specs[(int)ds_volatile]
03479 || declspecs->specs[(int)ds_restrict]
03480 || declspecs->specs[(int)ds_thread])
03481 error ("qualifiers can only be specified for objects "
03482 "and functions");
03483 }
03484
03485 return declared_type;
03486 }
03487
03488
03489
03490
03491
03492
03493
03494
03495
03496
03497
03498
03499
03500
03501 tree
03502 shadow_tag (cp_decl_specifier_seq *declspecs)
03503 {
03504 tree t = check_tag_decl (declspecs);
03505
03506 if (!t)
03507 return NULL_TREE;
03508
03509 if (declspecs->attributes)
03510 {
03511 cp_warning_at ("attribute ignored in declaration of %q#T", t);
03512 cp_warning_at ("attribute for %q#T must follow the %qs keyword",
03513 t,
03514 class_key_or_enum_as_string (t));
03515
03516 }
03517
03518 maybe_process_partial_specialization (t);
03519
03520
03521
03522
03523
03524
03525 if (ANON_AGGR_TYPE_P (t))
03526 {
03527 fixup_anonymous_aggr (t);
03528
03529 if (TYPE_FIELDS (t))
03530 {
03531 tree decl = grokdeclarator (NULL,
03532 declspecs, NORMAL, 0, NULL);
03533 finish_anon_union (decl);
03534 }
03535 }
03536
03537 return t;
03538 }
03539
03540
03541
03542 tree
03543 groktypename (cp_decl_specifier_seq *type_specifiers,
03544 const cp_declarator *declarator)
03545 {
03546 tree attrs;
03547 tree type;
03548 attrs = type_specifiers->attributes;
03549 type_specifiers->attributes = NULL_TREE;
03550 type = grokdeclarator (declarator, type_specifiers, TYPENAME, 0, &attrs);
03551 if (attrs)
03552 cplus_decl_attributes (&type, attrs, 0);
03553 return type;
03554 }
03555
03556
03557
03558
03559
03560
03561
03562
03563
03564
03565
03566
03567
03568
03569
03570
03571 tree
03572 start_decl (const cp_declarator *declarator,
03573 cp_decl_specifier_seq *declspecs,
03574 int initialized,
03575 tree attributes,
03576 tree prefix_attributes,
03577 tree *pushed_scope_p)
03578 {
03579 tree decl;
03580 tree type, tem;
03581 tree context;
03582
03583 *pushed_scope_p = NULL_TREE;
03584
03585
03586 if (have_extern_spec)
03587 {
03588 declspecs->storage_class = sc_extern;
03589 have_extern_spec = false;
03590 }
03591
03592
03593
03594 if (lookup_attribute ("deprecated", attributes))
03595 deprecated_state = DEPRECATED_SUPPRESS;
03596
03597 attributes = chainon (attributes, prefix_attributes);
03598
03599 decl = grokdeclarator (declarator, declspecs, NORMAL, initialized,
03600 &attributes);
03601
03602 deprecated_state = DEPRECATED_NORMAL;
03603
03604 if (decl == NULL_TREE || TREE_CODE (decl) == VOID_TYPE)
03605 return error_mark_node;
03606
03607 type = TREE_TYPE (decl);
03608
03609 if (type == error_mark_node)
03610 return error_mark_node;
03611
03612 context = DECL_CONTEXT (decl);
03613
03614 if (context)
03615 {
03616 *pushed_scope_p = push_scope (context);
03617
03618
03619 if (TREE_CODE (context) == NAMESPACE_DECL)
03620 context = NULL_TREE;
03621 }
03622
03623 if (initialized)
03624
03625
03626
03627 switch (TREE_CODE (decl))
03628 {
03629 case TYPE_DECL:
03630 error ("typedef %qD is initialized (use __typeof__ instead)", decl);
03631 initialized = 0;
03632 break;
03633
03634 case FUNCTION_DECL:
03635 error ("function %q#D is initialized like a variable", decl);
03636 initialized = 0;
03637 break;
03638
03639 default:
03640 break;
03641 }
03642
03643 if (initialized)
03644 {
03645 if (! toplevel_bindings_p ()
03646 && DECL_EXTERNAL (decl))
03647 warning ("declaration of %q#D has %<extern%> and is initialized",
03648 decl);
03649 DECL_EXTERNAL (decl) = 0;
03650 if (toplevel_bindings_p ())
03651 TREE_STATIC (decl) = 1;
03652
03653
03654
03655
03656 DECL_INITIAL (decl) = error_mark_node;
03657 }
03658
03659
03660 cplus_decl_attributes (&decl, attributes, 0);
03661
03662
03663 maybe_apply_pragma_weak (decl);
03664
03665 if (TREE_CODE (decl) == FUNCTION_DECL
03666 && DECL_DECLARED_INLINE_P (decl)
03667 && DECL_UNINLINABLE (decl)
03668 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
03669 warning ("%Jinline function %qD given attribute noinline", decl, decl);
03670
03671 if (context && COMPLETE_TYPE_P (complete_type (context)))
03672 {
03673 if (TREE_CODE (decl) == VAR_DECL)
03674 {
03675 tree field = lookup_field (context, DECL_NAME (decl), 0, false);
03676 if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL)
03677 error ("%q#D is not a static member of %q#T", decl, context);
03678 else
03679 {
03680 if (DECL_CONTEXT (field) != context)
03681 {
03682 if (!same_type_p (DECL_CONTEXT (field), context))
03683 pedwarn ("ISO C++ does not permit %<%T::%D%> "
03684 "to be defined as %<%T::%D%>",
03685 DECL_CONTEXT (field), DECL_NAME (decl),
03686 context, DECL_NAME (decl));
03687 DECL_CONTEXT (decl) = DECL_CONTEXT (field);
03688 }
03689 if (processing_specialization
03690 && template_class_depth (context) == 0
03691 && CLASSTYPE_TEMPLATE_SPECIALIZATION (context))
03692 error ("template header not allowed in member definition "
03693 "of explicitly specialized class");
03694
03695
03696
03697
03698
03699 if (DECL_INITIAL (decl)
03700 && DECL_INITIALIZED_IN_CLASS_P (field))
03701 error ("duplicate initialization of %qD", decl);
03702 if (duplicate_decls (decl, field))
03703 decl = field;
03704 }
03705 }
03706 else
03707 {
03708 tree field = check_classfn (context, decl,
03709 (processing_template_decl
03710 > template_class_depth (context))
03711 ? current_template_parms
03712 : NULL_TREE);
03713 if (field && duplicate_decls (decl, field))
03714 decl = field;
03715 }
03716
03717
03718 DECL_IN_AGGR_P (decl) = 0;
03719 if ((DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
03720 || CLASSTYPE_TEMPLATE_INSTANTIATION (context))
03721 {
03722
03723
03724
03725
03726 if (DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
03727 SET_DECL_TEMPLATE_SPECIALIZATION (decl);
03728
03729
03730
03731
03732
03733
03734 if (DECL_INITIAL (decl) == NULL_TREE && processing_specialization)
03735 DECL_EXTERNAL (decl) = 1;
03736 }
03737
03738 if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl))
03739 pedwarn ("declaration of %q#D outside of class is not definition",
03740 decl);
03741 }
03742
03743
03744 tem = maybe_push_decl (decl);
03745
03746 if (processing_template_decl)
03747 tem = push_template_decl (tem);
03748 if (tem == error_mark_node)
03749 return error_mark_node;
03750
03751 #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS)
03752
03753
03754
03755
03756
03757 DECL_COMMON (tem) = ((TREE_CODE (tem) != VAR_DECL
03758 || !DECL_THREAD_LOCAL (tem))
03759 && (flag_conserve_space || ! TREE_PUBLIC (tem)));
03760 #endif
03761
03762 if (! processing_template_decl)
03763 start_decl_1 (tem);
03764
03765 return tem;
03766 }
03767
03768 void
03769 start_decl_1 (tree decl)
03770 {
03771 tree type = TREE_TYPE (decl);
03772 int initialized = (DECL_INITIAL (decl) != NULL_TREE);
03773
03774 if (type == error_mark_node)
03775 return;
03776
03777 if (initialized)
03778
03779
03780
03781 {
03782
03783
03784 if (COMPLETE_TYPE_P (complete_type (type)))
03785 ;
03786 else if (TREE_CODE (type) != ARRAY_TYPE)
03787 {
03788 error ("variable %q#D has initializer but incomplete type", decl);
03789 initialized = 0;
03790 type = TREE_TYPE (decl) = error_mark_node;
03791 }
03792 else if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (type))))
03793 {
03794 if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
03795 error ("elements of array %q#D have incomplete type", decl);
03796
03797 initialized = 0;
03798 }
03799 }
03800
03801 if (!initialized
03802 && TREE_CODE (decl) != TYPE_DECL
03803 && TREE_CODE (decl) != TEMPLATE_DECL
03804 && type != error_mark_node
03805 && IS_AGGR_TYPE (type)
03806 && ! DECL_EXTERNAL (decl))
03807 {
03808 if ((! processing_template_decl || ! uses_template_parms (type))
03809 && !COMPLETE_TYPE_P (complete_type (type)))
03810 {
03811 error ("aggregate %q#D has incomplete type and cannot be defined",
03812 decl);
03813
03814
03815 type = TREE_TYPE (decl) = error_mark_node;
03816 }
03817 else
03818 {
03819
03820
03821
03822
03823
03824
03825 initialized = TYPE_NEEDS_CONSTRUCTING (type);
03826 }
03827 }
03828
03829 if (! initialized)
03830 DECL_INITIAL (decl) = NULL_TREE;
03831
03832
03833
03834
03835
03836
03837
03838 maybe_push_cleanup_level (type);
03839 }
03840
03841
03842
03843
03844
03845
03846
03847
03848
03849
03850
03851 static tree
03852 grok_reference_init (tree decl, tree type, tree init, tree *cleanup)
03853 {
03854 tree tmp;
03855
03856 if (init == NULL_TREE)
03857 {
03858 if ((DECL_LANG_SPECIFIC (decl) == 0
03859 || DECL_IN_AGGR_P (decl) == 0)
03860 && ! DECL_THIS_EXTERN (decl))
03861 error ("%qD declared as reference but not initialized", decl);
03862 return NULL_TREE;
03863 }
03864
03865 if (TREE_CODE (init) == CONSTRUCTOR)
03866 {
03867 error ("ISO C++ forbids use of initializer list to "
03868 "initialize reference %qD", decl);
03869 return NULL_TREE;
03870 }
03871
03872 if (TREE_CODE (init) == TREE_LIST)
03873 init = build_x_compound_expr_from_list (init, "initializer");
03874
03875 if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE
03876 && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
03877
03878 init = decay_conversion (init);
03879
03880
03881
03882
03883
03884
03885
03886
03887 tmp = initialize_reference (type, init, decl, cleanup);
03888
03889 if (tmp == error_mark_node)
03890 return NULL_TREE;
03891 else if (tmp == NULL_TREE)
03892 {
03893 error ("cannot initialize %qT from %qT", type, TREE_TYPE (init));
03894 return NULL_TREE;
03895 }
03896
03897 if (TREE_STATIC (decl) && !TREE_CONSTANT (tmp))
03898 return tmp;
03899
03900 DECL_INITIAL (decl) = tmp;
03901
03902 return NULL_TREE;
03903 }
03904
03905
03906
03907
03908
03909 static void
03910 maybe_deduce_size_from_array_init (tree decl, tree init)
03911 {
03912 tree type = TREE_TYPE (decl);
03913
03914 if (TREE_CODE (type) == ARRAY_TYPE
03915 && TYPE_DOMAIN (type) == NULL_TREE
03916 && TREE_CODE (decl) != TYPE_DECL)
03917 {
03918
03919
03920 int do_default = !DECL_EXTERNAL (decl);
03921 tree initializer = init ? init : DECL_INITIAL (decl);
03922 int failure = cp_complete_array_type (&TREE_TYPE (decl), initializer,
03923 do_default);
03924
03925 if (failure == 1)
03926 error ("initializer fails to determine size of %qD", decl);
03927
03928 if (failure == 2)
03929 {
03930 if (do_default)
03931 error ("array size missing in %qD", decl);
03932
03933
03934
03935
03936 else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
03937 DECL_EXTERNAL (decl) = 1;
03938 }
03939
03940 if (failure == 3)
03941 error ("zero-size array %qD", decl);
03942
03943 cp_apply_type_quals_to_decl (cp_type_quals (TREE_TYPE (decl)), decl);
03944
03945 layout_decl (decl, 0);
03946 }
03947 }
03948
03949
03950
03951
03952 static void
03953 layout_var_decl (tree decl)
03954 {
03955 tree type = TREE_TYPE (decl);
03956 #if 0
03957 tree ttype = target_type (type);
03958 #endif
03959
03960
03961
03962
03963
03964
03965 if (!DECL_EXTERNAL (decl))
03966 complete_type (type);
03967 if (!DECL_SIZE (decl)
03968 && TREE_TYPE (decl) != error_mark_node
03969 && (COMPLETE_TYPE_P (type)
03970 || (TREE_CODE (type) == ARRAY_TYPE
03971 && !TYPE_DOMAIN (type)
03972 && COMPLETE_TYPE_P (TREE_TYPE (type)))))
03973 layout_decl (decl, 0);
03974
03975 if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
03976 {
03977
03978
03979
03980 error ("storage size of %qD isn't known", decl);
03981 TREE_TYPE (decl) = error_mark_node;
03982 }
03983 #if 0
03984
03985
03986
03987 else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype))
03988
03989 note_debug_info_needed (ttype);
03990
03991 if (TREE_STATIC (decl) && DECL_CLASS_SCOPE_P (decl))
03992 note_debug_info_needed (DECL_CONTEXT (decl));
03993 #endif
03994
03995 if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
03996 && DECL_SIZE (decl) != NULL_TREE
03997 && ! TREE_CONSTANT (DECL_SIZE (decl)))
03998 {
03999 if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
04000 constant_expression_warning (DECL_SIZE (decl));
04001 else
04002 error ("storage size of %qD isn't constant", decl);
04003 }
04004
04005 if (TREE_STATIC (decl)
04006 && !DECL_ARTIFICIAL (decl)
04007 && current_function_decl
04008 && DECL_CONTEXT (decl) == current_function_decl)
04009 push_local_name (decl);
04010 }
04011
04012
04013
04014
04015
04016 static void
04017 maybe_commonize_var (tree decl)
04018 {
04019
04020
04021 if (TREE_STATIC (decl)
04022
04023 && ! DECL_ARTIFICIAL (decl)
04024 && DECL_FUNCTION_SCOPE_P (decl)
04025
04026
04027
04028 && (DECL_COMDAT (DECL_CONTEXT (decl))
04029 || ((DECL_DECLARED_INLINE_P (DECL_CONTEXT (decl))
04030 || DECL_TEMPLATE_INSTANTIATION (DECL_CONTEXT (decl)))
04031 && TREE_PUBLIC (DECL_CONTEXT (decl)))))
04032 {
04033 if (flag_weak)
04034 {
04035
04036
04037
04038 comdat_linkage (decl);
04039 }
04040 else
04041 {
04042 if (DECL_INITIAL (decl) == NULL_TREE
04043 || DECL_INITIAL (decl) == error_mark_node)
04044 {
04045
04046
04047 TREE_PUBLIC (decl) = 1;
04048 DECL_COMMON (decl) = 1;
04049 }
04050 else
04051 {
04052
04053
04054
04055 TREE_PUBLIC (decl) = 0;
04056 DECL_COMMON (decl) = 0;
04057 cp_warning_at ("sorry: semantics of inline function static "
04058 "data %q#D are wrong (you'll wind up "
04059 "with multiple copies)", decl);
04060 warning ("%J you can work around this by removing "
04061 "the initializer",
04062 decl);
04063 }
04064 }
04065 }
04066 else if (DECL_LANG_SPECIFIC (decl) && DECL_COMDAT (decl))
04067
04068
04069 comdat_linkage (decl);
04070 }
04071
04072
04073
04074 static void
04075 check_for_uninitialized_const_var (tree decl)
04076 {
04077 tree type = TREE_TYPE (decl);
04078
04079
04080
04081
04082 if (TREE_CODE (decl) == VAR_DECL
04083 && TREE_CODE (type) != REFERENCE_TYPE
04084 && CP_TYPE_CONST_P (type)
04085 && !TYPE_NEEDS_CONSTRUCTING (type)
04086 && !DECL_INITIAL (decl))
04087 error ("uninitialized const %qD", decl);
04088 }
04089
04090
04091
04092
04093
04094
04095 static tree
04096 next_initializable_field (tree field)
04097 {
04098 while (field
04099 && (TREE_CODE (field) != FIELD_DECL
04100 || (DECL_C_BIT_FIELD (field) && !DECL_NAME (field))
04101 || DECL_ARTIFICIAL (field)))
04102 field = TREE_CHAIN (field);
04103
04104 return field;
04105 }
04106
04107
04108
04109
04110
04111
04112
04113
04114
04115 static bool
04116 reshape_init_array (tree elt_type, tree max_index,
04117 tree *initp, tree new_init)
04118 {
04119 bool sized_array_p = (max_index != NULL_TREE);
04120 unsigned HOST_WIDE_INT max_index_cst = 0;
04121 unsigned HOST_WIDE_INT index;
04122
04123 if (sized_array_p)
04124 {
04125 if (host_integerp (max_index, 1))
04126 max_index_cst = tree_low_cst (max_index, 1);
04127
04128 else
04129 max_index_cst = tree_low_cst (fold_convert (size_type_node, max_index),
04130 1);
04131 }
04132
04133
04134 for (index = 0;
04135 *initp && (!sized_array_p || index <= max_index_cst);
04136 ++index)
04137 {
04138 tree element_init;
04139 tree designated_index;
04140
04141 element_init = reshape_init (elt_type, initp);
04142 if (element_init == error_mark_node)
04143 return false;
04144 TREE_CHAIN (element_init) = CONSTRUCTOR_ELTS (new_init);
04145 CONSTRUCTOR_ELTS (new_init) = element_init;
04146 designated_index = TREE_PURPOSE (element_init);
04147 if (designated_index)
04148 {
04149
04150 if (TREE_CODE (designated_index) == IDENTIFIER_NODE)
04151 {
04152 error ("name %qD used in a GNU-style designated "
04153 "initializer for an array", designated_index);
04154 TREE_PURPOSE (element_init) = NULL_TREE;
04155 }
04156 else
04157 gcc_unreachable ();
04158 }
04159 }
04160
04161 return true;
04162 }
04163
04164
04165
04166
04167
04168
04169
04170
04171
04172
04173
04174
04175
04176
04177
04178
04179 static tree
04180 reshape_init (tree type, tree *initp)
04181 {
04182 tree inits;
04183 tree old_init;
04184 tree old_init_value;
04185 tree new_init;
04186 bool brace_enclosed_p;
04187 bool string_init_p;
04188
04189 old_init = *initp;
04190 old_init_value = (TREE_CODE (*initp) == TREE_LIST
04191 ? TREE_VALUE (*initp) : old_init);
04192
04193 gcc_assert (old_init_value);
04194
04195
04196
04197
04198 if (TREE_CODE (old_init_value) == CONSTRUCTOR
04199 && BRACE_ENCLOSED_INITIALIZER_P (old_init_value))
04200 {
04201 *initp = TREE_CHAIN (old_init);
04202 TREE_CHAIN (old_init) = NULL_TREE;
04203 inits = CONSTRUCTOR_ELTS (old_init_value);
04204 initp = &inits;
04205 brace_enclosed_p = true;
04206 }
04207 else
04208 {
04209 inits = NULL_TREE;
04210 brace_enclosed_p = false;
04211 }
04212
04213
04214
04215 if (!CP_AGGREGATE_TYPE_P (type))
04216 {
04217 *initp = TREE_CHAIN (old_init);
04218 TREE_CHAIN (old_init) = NULL_TREE;
04219
04220
04221 if (brace_enclosed_p)
04222 {
04223 error ("brace-enclosed initializer used to initialize %qT",
04224 type);
04225 if (TREE_CODE (old_init) == TREE_LIST)
04226 TREE_VALUE (old_init) = error_mark_node;
04227 else
04228 old_init = error_mark_node;
04229 }
04230
04231 return old_init;
04232 }
04233
04234
04235
04236
04237
04238
04239
04240
04241
04242
04243 if (!brace_enclosed_p
04244 && can_convert_arg (type, TREE_TYPE (old_init_value), old_init_value))
04245 {
04246 *initp = TREE_CHAIN (old_init);
04247 TREE_CHAIN (old_init) = NULL_TREE;
04248 return old_init;
04249 }
04250
04251 string_init_p = false;
04252 if (TREE_CODE (old_init_value) == STRING_CST
04253 && TREE_CODE (type) == ARRAY_TYPE
04254 && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type))))
04255 {
04256
04257
04258
04259
04260
04261
04262 new_init = old_init;
04263
04264 *initp = TREE_CHAIN (old_init);
04265 TREE_CHAIN (old_init) = NULL_TREE;
04266 string_init_p = true;
04267 }
04268 else
04269 {
04270
04271 new_init = build_constructor (NULL_TREE, NULL_TREE);
04272
04273 if (CLASS_TYPE_P (type))
04274 {
04275 tree field;
04276
04277 field = next_initializable_field (TYPE_FIELDS (type));
04278
04279 if (!field)
04280 {
04281
04282
04283
04284
04285
04286 if (!brace_enclosed_p)
04287 {
04288 error ("initializer for %qT must be brace-enclosed", type);
04289 return error_mark_node;
04290 }
04291 }
04292 else
04293 {
04294
04295
04296 while (*initp)
04297 {
04298 tree field_init;
04299
04300
04301 if (TREE_PURPOSE (*initp))
04302 {
04303 if (pedantic)
04304 pedwarn ("ISO C++ does not allow designated initializers");
04305 field = lookup_field_1 (type, TREE_PURPOSE (*initp),
04306 false);
04307 if (!field || TREE_CODE (field) != FIELD_DECL)
04308 error ("%qT has no non-static data member named %qD",
04309 type, TREE_PURPOSE (*initp));
04310 }
04311 if (!field)
04312 break;
04313
04314 field_init = reshape_init (TREE_TYPE (field), initp);
04315 if (field_init == error_mark_node)
04316 return error_mark_node;
04317 TREE_CHAIN (field_init) = CONSTRUCTOR_ELTS (new_init);
04318 CONSTRUCTOR_ELTS (new_init) = field_init;
04319
04320
04321
04322
04323
04324 if (TREE_CODE (type) == UNION_TYPE)
04325 break;
04326 field = next_initializable_field (TREE_CHAIN (field));
04327 }
04328 }
04329 }
04330 else if (TREE_CODE (type) == ARRAY_TYPE
04331 || TREE_CODE (type) == VECTOR_TYPE)
04332 {
04333
04334
04335 tree max_index = NULL_TREE;
04336 if (TREE_CODE (type) == ARRAY_TYPE)
04337 {
04338 if (TYPE_DOMAIN (type))
04339 max_index = array_type_nelts (type);
04340 }
04341 else
04342 {
04343
04344
04345
04346 tree rtype = TYPE_DEBUG_REPRESENTATION_TYPE (type);
04347 if (rtype && TYPE_DOMAIN (TREE_TYPE (TYPE_FIELDS (rtype))))
04348 max_index = array_type_nelts (TREE_TYPE (TYPE_FIELDS
04349 (rtype)));
04350 }
04351
04352 if (!reshape_init_array (TREE_TYPE (type), max_index,
04353 initp, new_init))
04354 return error_mark_node;
04355 }
04356 else
04357 gcc_unreachable ();
04358
04359
04360
04361 CONSTRUCTOR_ELTS (new_init) = nreverse (CONSTRUCTOR_ELTS (new_init));
04362
04363 if (TREE_CODE (old_init) == TREE_LIST)
04364 new_init = build_tree_list (TREE_PURPOSE (old_init), new_init);
04365 }
04366
04367
04368
04369 if (*initp)
04370 {
04371 if (brace_enclosed_p)
04372 error ("too many initializers for %qT", type);
04373 else if (warn_missing_braces && !string_init_p)
04374 warning ("missing braces around initializer");
04375 }
04376
04377 return new_init;
04378 }
04379
04380
04381
04382
04383
04384
04385
04386
04387 static tree
04388 check_initializer (tree decl, tree init, int flags, tree *cleanup)
04389 {
04390 tree type = TREE_TYPE (decl);
04391 tree init_code = NULL;
04392
04393
04394 if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE)
04395 init = NULL_TREE;
04396
04397
04398
04399
04400
04401 DECL_INITIAL (decl) = NULL_TREE;
04402
04403
04404
04405 TREE_TYPE (decl) = type = complete_type (TREE_TYPE (decl));
04406
04407 if (type == error_mark_node)
04408
04409 init = NULL_TREE;
04410 else if (init && COMPLETE_TYPE_P (type)
04411 && !TREE_CONSTANT (TYPE_SIZE (type)))
04412 {
04413 error ("variable-sized object %qD may not be initialized", decl);
04414 init = NULL_TREE;
04415 }
04416 else if (TREE_CODE (type) == ARRAY_TYPE
04417 && !COMPLETE_TYPE_P (complete_type (TREE_TYPE (type))))
04418 {
04419 error ("elements of array %q#D have incomplete type", decl);
04420 init = NULL_TREE;
04421 }
04422 else if (TREE_CODE (type) != ARRAY_TYPE && !COMPLETE_TYPE_P (type))
04423 {
04424 error ("%qD has incomplete type", decl);
04425 TREE_TYPE (decl) = error_mark_node;
04426 init = NULL_TREE;
04427 }
04428
04429 if (TREE_CODE (decl) == CONST_DECL)
04430 {
04431 gcc_assert (TREE_CODE (decl) != REFERENCE_TYPE);
04432
04433 DECL_INITIAL (decl) = init;
04434
04435 gcc_assert (init != NULL_TREE);
04436 init = NULL_TREE;
04437 }
04438 else if (!DECL_EXTERNAL (decl) && TREE_CODE (type) == REFERENCE_TYPE)
04439 init = grok_reference_init (decl, type, init, cleanup);
04440 else if (init)
04441 {
04442 if (TREE_CODE (init) == CONSTRUCTOR
04443 && BRACE_ENCLOSED_INITIALIZER_P (init))
04444 {
04445
04446
04447
04448
04449
04450
04451
04452
04453
04454 if (CP_AGGREGATE_TYPE_P (type))
04455 init = reshape_init (type, &init);
04456
04457 if ((*targetm.vector_opaque_p) (type))
04458 {
04459 error ("opaque vector types cannot be initialized");
04460 init = error_mark_node;
04461 }
04462 }
04463
04464
04465
04466 maybe_deduce_size_from_array_init (decl, init);
04467 type = TREE_TYPE (decl);
04468
04469 if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type))
04470 {
04471 if (TREE_CODE (type) == ARRAY_TYPE)
04472 goto initialize_aggr;
04473 else if (TREE_CODE (init) == CONSTRUCTOR
04474 && BRACE_ENCLOSED_INITIALIZER_P (init))
04475 {
04476 if (TYPE_NON_AGGREGATE_CLASS (type))
04477 {
04478 error ("%qD must be initialized by constructor, "
04479 "not by %<{...}%>",
04480 decl);
04481 init = error_mark_node;
04482 }
04483 else
04484 goto dont_use_constructor;
04485 }
04486 else
04487 {
04488 int saved_stmts_are_full_exprs_p;
04489
04490 initialize_aggr:
04491 saved_stmts_are_full_exprs_p = 0;
04492 if (building_stmt_tree ())
04493 {
04494 saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
04495 current_stmt_tree ()->stmts_are_full_exprs_p = 1;
04496 }
04497 init = build_aggr_init (decl, init, flags);
04498 if (building_stmt_tree ())
04499 current_stmt_tree ()->stmts_are_full_exprs_p =
04500 saved_stmts_are_full_exprs_p;
04501 return init;
04502 }
04503 }
04504 else
04505 {
04506 dont_use_constructor:
04507 if (TREE_CODE (init) != TREE_VEC)
04508 {
04509 init_code = store_init_value (decl, init);
04510 if (pedantic && TREE_CODE (type) == ARRAY_TYPE
04511 && DECL_INITIAL (decl)
04512 && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
04513 && PAREN_STRING_LITERAL_P (DECL_INITIAL (decl)))
04514 warning ("array %qD initialized by parenthesized string literal %qE",
04515 decl, DECL_INITIAL (decl));
04516 init = NULL;
04517 }
04518 }
04519 }
04520 else if (DECL_EXTERNAL (decl))
04521 ;
04522 else if (TYPE_P (type) && TYPE_NEEDS_CONSTRUCTING (type))
04523 goto initialize_aggr;
04524 else if (IS_AGGR_TYPE (type))
04525 {
04526 tree core_type = strip_array_types (type);
04527
04528 if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type))
04529 error ("structure %qD with uninitialized const members", decl);
04530 if (CLASSTYPE_REF_FIELDS_NEED_INIT (core_type))
04531 error ("structure %qD with uninitialized reference members", decl);
04532
04533 check_for_uninitialized_const_var (decl);
04534 }
04535 else
04536 check_for_uninitialized_const_var (decl);
04537
04538 if (init && init != error_mark_node)
04539 init_code = build2 (INIT_EXPR, type, decl, init);
04540
04541 return init_code;
04542 }
04543
04544
04545
04546 static void
04547 make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec)
04548 {
04549 int toplev = toplevel_bindings_p ();
04550 int defer_p;
04551
04552
04553 if (asmspec)
04554 {
04555
04556
04557
04558 if (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
04559 {
04560 change_decl_assembler_name (decl, get_identifier (asmspec));
04561 DECL_HARD_REGISTER (decl) = 1;
04562 }
04563 else
04564 {
04565 if (TREE_CODE (decl) == FUNCTION_DECL
04566 && DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL)
04567 set_builtin_user_assembler_name (decl, asmspec);
04568 set_user_assembler_name (decl, asmspec);
04569 }
04570 }
04571
04572
04573 if (TREE_CODE (decl) != VAR_DECL)
04574 {
04575 rest_of_decl_compilation (decl, toplev, at_eof);
04576 return;
04577 }
04578
04579
04580
04581 if (DECL_LANG_SPECIFIC (decl) && DECL_IN_AGGR_P (decl))
04582 {
04583 gcc_assert (TREE_STATIC (decl));
04584
04585
04586 if (init == NULL_TREE)
04587 gcc_assert (DECL_EXTERNAL (decl));
04588 }
04589
04590
04591 if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
04592 return;
04593
04594
04595
04596 defer_p = DECL_FUNCTION_SCOPE_P (decl) || DECL_VIRTUAL_P (decl);
04597
04598
04599
04600 if (!DECL_VIRTUAL_P (decl)
04601 && TREE_READONLY (decl)
04602 && DECL_INITIAL (decl) != NULL_TREE
04603 && DECL_INITIAL (decl) != error_mark_node
04604 && ! EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl))
04605 && toplev
04606 && !TREE_PUBLIC (decl))
04607 {
04608
04609
04610 struct c_fileinfo *finfo = get_fileinfo (lbasename (input_filename));
04611 if (!finfo->interface_unknown && !TREE_PUBLIC (decl))
04612 {
04613 TREE_PUBLIC (decl) = 1;
04614 DECL_EXTERNAL (decl) = finfo->interface_only;
04615 }
04616
04617 defer_p = 1;
04618 }
04619
04620 else if (DECL_LANG_SPECIFIC (decl)
04621 && DECL_IMPLICIT_INSTANTIATION (decl))
04622 defer_p = 1;
04623
04624
04625 if (!defer_p)
04626 rest_of_decl_compilation (decl, toplev, at_eof);
04627 }
04628
04629
04630
04631 static void
04632 initialize_local_var (tree decl, tree init)
04633 {
04634 tree type = TREE_TYPE (decl);
04635 tree cleanup;
04636
04637 gcc_assert (TREE_CODE (decl) == VAR_DECL
04638 || TREE_CODE (decl) == RESULT_DECL);
04639 gcc_assert (!TREE_STATIC (decl));
04640
04641 if (DECL_SIZE (decl) == NULL_TREE)
04642 {
04643
04644 DECL_INITIAL (decl) = NULL_TREE;
04645 TREE_ADDRESSABLE (decl) = TREE_USED (decl);
04646 }
04647
04648 if (DECL_SIZE (decl) && type != error_mark_node)
04649 {
04650 int already_used;
04651
04652
04653 already_used = TREE_USED (decl) || TREE_USED (type);
04654
04655
04656 if (init)
04657 {
04658 int saved_stmts_are_full_exprs_p;
04659
04660 gcc_assert (building_stmt_tree ());
04661 saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
04662 current_stmt_tree ()->stmts_are_full_exprs_p = 1;
04663 finish_expr_stmt (init);
04664 current_stmt_tree ()->stmts_are_full_exprs_p =
04665 saved_stmts_are_full_exprs_p;
04666 }
04667
04668
04669
04670
04671
04672
04673
04674 if (TYPE_NEEDS_CONSTRUCTING (type)
04675 && ! already_used
04676 && TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
04677 && DECL_NAME (decl))
04678 TREE_USED (decl) = 0;
04679 else if (already_used)
04680 TREE_USED (decl) = 1;
04681 }
04682
04683
04684 cleanup = cxx_maybe_build_cleanup (decl);
04685 if (DECL_SIZE (decl) && cleanup)
04686 finish_decl_cleanup (decl, cleanup);
04687 }
04688
04689
04690
04691
04692
04693
04694 void
04695 initialize_artificial_var (tree decl, tree init)
04696 {
04697 DECL_INITIAL (decl) = build_constructor (NULL_TREE, init);
04698 DECL_INITIALIZED_P (decl) = 1;
04699 determine_visibility (decl);
04700 layout_var_decl (decl);
04701 maybe_commonize_var (decl);
04702 make_rtl_for_nonlocal_decl (decl, init, NULL);
04703 }
04704
04705
04706
04707
04708
04709
04710
04711
04712
04713
04714
04715
04716 void
04717 cp_finish_decl (tree decl, tree init, tree asmspec_tree, int flags)
04718 {
04719 tree type;
04720 tree ttype = NULL_TREE;
04721 tree cleanup;
04722 const char *asmspec = NULL;
04723 int was_readonly = 0;
04724 bool var_definition_p = false;
04725
04726 if (decl == error_mark_node)
04727 return;
04728 else if (! decl)
04729 {
04730 if (init)
04731 error ("assignment (not initialization) in declaration");
04732 return;
04733 }
04734
04735 gcc_assert (TREE_CODE (decl) != RESULT_DECL);
04736
04737
04738 cleanup = NULL_TREE;
04739
04740
04741 if (global_scope_p (current_binding_level))
04742 asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
04743 if (asmspec_tree)
04744 asmspec = TREE_STRING_POINTER (asmspec_tree);
04745
04746 if (init && TREE_CODE (init) == NAMESPACE_DECL)
04747 {
04748 error ("cannot initialize %qD to namespace %qD", decl, init);
04749 init = NULL_TREE;
04750 }
04751
04752 if (current_class_type
04753 && CP_DECL_CONTEXT (decl) == current_class_type
04754 && TYPE_BEING_DEFINED (current_class_type)
04755 && (DECL_INITIAL (decl) || init))
04756 DECL_INITIALIZED_IN_CLASS_P (decl) = 1;
04757
04758 type = TREE_TYPE (decl);
04759
04760 if (type == error_mark_node)
04761 goto finish_end;
04762
04763 if (processing_template_decl)
04764 {
04765
04766 if (at_function_scope_p ())
04767 add_decl_expr (decl);
04768
04769 if (init && DECL_INITIAL (decl))
04770 DECL_INITIAL (decl) = init;
04771 if (TREE_CODE (decl) == VAR_DECL
04772 && !DECL_PRETTY_FUNCTION_P (decl)
04773 && !dependent_type_p (TREE_TYPE (decl)))
04774 maybe_deduce_size_from_array_init (decl, init);
04775
04776 goto finish_end;
04777 }
04778
04779
04780 gcc_assert (TREE_CODE (decl) != PARM_DECL);
04781
04782
04783 if (TREE_CODE (decl) == TYPE_DECL)
04784 {
04785 if (type != error_mark_node
04786 && IS_AGGR_TYPE (type) && DECL_NAME (decl))
04787 {
04788 if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
04789 warning ("shadowing previous type declaration of %q#D", decl);
04790 set_identifier_type_value (DECL_NAME (decl), decl);
04791 }
04792
04793
04794
04795
04796 if (TYPE_MAIN_DECL (TREE_TYPE (decl)) == decl
04797 && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
04798 TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
04799
04800 rest_of_decl_compilation (decl, DECL_CONTEXT (decl) == NULL_TREE,
04801 at_eof);
04802 goto finish_end;
04803 }
04804
04805 if (TREE_CODE (decl) != FUNCTION_DECL)
04806 ttype = target_type (type);
04807
04808
04809
04810 if (! DECL_EXTERNAL (decl)
04811 && TREE_READONLY (decl)
04812 && TREE_CODE (type) == REFERENCE_TYPE)
04813 {
04814 was_readonly = 1;
04815 TREE_READONLY (decl) = 0;
04816 }
04817
04818 if (TREE_CODE (decl) == VAR_DECL)
04819 {
04820
04821
04822 if (DECL_THREAD_LOCAL (decl) && !pod_type_p (TREE_TYPE (decl)))
04823 error ("%qD cannot be thread-local because it has non-POD type %qT",
04824 decl, TREE_TYPE (decl));
04825
04826
04827 if (!DECL_INITIALIZED_P (decl)
04828
04829
04830
04831
04832 && (!DECL_EXTERNAL (decl) || init))
04833 {
04834 init = check_initializer (decl, init, flags, &cleanup);
04835
04836 if (DECL_THREAD_LOCAL (decl) && init)
04837 {
04838 error ("%qD is thread-local and so cannot be dynamically "
04839 "initialized", decl);
04840 init = NULL_TREE;
04841 }
04842
04843
04844
04845
04846
04847
04848
04849
04850
04851
04852
04853
04854 if (DECL_EXTERNAL (decl) && init)
04855 {
04856 error ("%qD cannot be initialized by a non-constant expression"
04857 " when being declared", decl);
04858 DECL_INITIALIZED_IN_CLASS_P (decl) = 0;
04859 init = NULL_TREE;
04860 }
04861
04862
04863
04864
04865
04866
04867
04868
04869
04870
04871
04872
04873
04874 if (TREE_STATIC (decl) && !DECL_INITIAL (decl))
04875 DECL_INITIAL (decl) = build_zero_init (TREE_TYPE (decl),
04876 NULL_TREE,
04877 true);
04878
04879
04880 DECL_INITIALIZED_P (decl) = 1;
04881
04882
04883
04884 if (!DECL_EXTERNAL (decl))
04885 var_definition_p = true;
04886
04887
04888 determine_visibility (decl);
04889 }
04890
04891
04892
04893
04894 else if (TREE_CODE (type) == ARRAY_TYPE)
04895 layout_type (type);
04896 }
04897
04898
04899
04900
04901 if (at_function_scope_p ())
04902 add_decl_expr (decl);
04903
04904 if (TREE_CODE (decl) == VAR_DECL)
04905 layout_var_decl (decl);
04906
04907
04908
04909
04910 if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
04911 {
04912 if (TREE_CODE (decl) == VAR_DECL)
04913 maybe_commonize_var (decl);
04914
04915 make_rtl_for_nonlocal_decl (decl, init, asmspec);
04916
04917
04918
04919
04920 if (TREE_CODE (type) == FUNCTION_TYPE
04921 || TREE_CODE (type) == METHOD_TYPE)
04922 abstract_virtuals_error (decl, TREE_TYPE (type));
04923 else
04924 abstract_virtuals_error (decl, type);
04925
04926 if (TREE_CODE (decl) == FUNCTION_DECL
04927 || TREE_TYPE (decl) == error_mark_node)
04928
04929 ;
04930 else if (DECL_EXTERNAL (decl)
04931 && ! (DECL_LANG_SPECIFIC (decl)
04932 && DECL_NOT_REALLY_EXTERN (decl)))
04933 {
04934 if (init)
04935 DECL_INITIAL (decl) = init;
04936 }
04937 else
04938 {
04939
04940 if (DECL_FUNCTION_SCOPE_P (decl))
04941 {
04942
04943 if (processing_template_decl)
04944 {
04945 if (init || DECL_INITIAL (decl) == error_mark_node)
04946 DECL_INITIAL (decl) = init;
04947 }
04948 else if (!TREE_STATIC (decl))
04949 initialize_local_var (decl, init);
04950 }
04951
04952
04953
04954
04955
04956
04957
04958
04959
04960 if (var_definition_p && TREE_STATIC (decl))
04961 expand_static_init (decl, init);
04962 }
04963 }
04964
04965
04966
04967 if (cleanup)
04968 push_cleanup (decl, cleanup, false);
04969
04970 finish_end:
04971
04972 if (was_readonly)
04973 TREE_READONLY (decl) = 1;
04974
04975
04976 if (lookup_attribute ("used", DECL_ATTRIBUTES (decl)))
04977 mark_decl_referenced (decl);
04978 }
04979
04980
04981
04982 void
04983 finish_decl (tree decl, tree init, tree asmspec_tree)
04984 {
04985 cp_finish_decl (decl, init, asmspec_tree, 0);
04986 }
04987
04988
04989
04990
04991
04992
04993
04994
04995 tree
04996 declare_global_var (tree name, tree type)
04997 {
04998 tree decl;
04999
05000 push_to_top_level ();
05001 decl = build_decl (VAR_DECL, name, type);
05002 TREE_PUBLIC (decl) = 1;
05003 DECL_EXTERNAL (decl) = 1;
05004 DECL_ARTIFICIAL (decl) = 1;
05005
05006
05007
05008
05009 decl = pushdecl (decl);
05010 cp_finish_decl (decl, NULL_TREE, NULL_TREE, 0);
05011 pop_from_top_level ();
05012
05013 return decl;
05014 }
05015
05016
05017
05018
05019
05020 static tree
05021 get_atexit_node (void)
05022 {
05023 tree atexit_fndecl;
05024 tree arg_types;
05025 tree fn_type;
05026 tree fn_ptr_type;
05027 const char *name;
05028
05029 if (atexit_node)
05030 return atexit_node;
05031
05032 if (flag_use_cxa_atexit)
05033 {
05034
05035
05036
05037
05038
05039
05040
05041
05042
05043 arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
05044 fn_type = build_function_type (void_type_node, arg_types);
05045 fn_ptr_type = build_pointer_type (fn_type);
05046
05047 arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
05048 arg_types = tree_cons (NULL_TREE, ptr_type_node, arg_types);
05049 arg_types = tree_cons (NULL_TREE, fn_ptr_type, arg_types);
05050
05051 fn_type = build_function_type (integer_type_node, arg_types);
05052 fn_ptr_type = build_pointer_type (fn_type);
05053 name = "__cxa_atexit";
05054 }
05055 else
05056 {
05057
05058
05059
05060
05061
05062
05063 fn_type = build_function_type (void_type_node, void_list_node);
05064 fn_ptr_type = build_pointer_type (fn_type);
05065 arg_types = tree_cons (NULL_TREE, fn_ptr_type, void_list_node);
05066
05067 fn_type = build_function_type (integer_type_node, arg_types);
05068 name = "atexit";
05069 }
05070
05071
05072 push_lang_context (lang_name_c);
05073 atexit_fndecl = build_library_fn_ptr (name, fn_type);
05074 mark_used (atexit_fndecl);
05075 pop_lang_context ();
05076 atexit_node = decay_conversion (atexit_fndecl);
05077
05078 return atexit_node;
05079 }
05080
05081
05082
05083 static tree
05084 get_dso_handle_node (void)
05085 {
05086 if (dso_handle_node)
05087 return dso_handle_node;
05088
05089
05090 dso_handle_node = declare_global_var (get_identifier ("__dso_handle"),
05091 ptr_type_node);
05092
05093 return dso_handle_node;
05094 }
05095
05096
05097
05098
05099 static GTY(()) int start_cleanup_cnt;
05100
05101 static tree
05102 start_cleanup_fn (void)
05103 {
05104 char name[32];
05105 tree parmtypes;
05106 tree fntype;
05107 tree fndecl;
05108
05109 push_to_top_level ();
05110
05111
05112 push_lang_context (lang_name_c);
05113
05114
05115 parmtypes = void_list_node;
05116
05117
05118
05119
05120 if (flag_use_cxa_atexit)
05121 parmtypes = tree_cons (NULL_TREE, ptr_type_node, parmtypes);
05122
05123 fntype = build_function_type (void_type_node, parmtypes);
05124
05125 sprintf (name, "__tcf_%d", start_cleanup_cnt++);
05126
05127 fndecl = build_lang_decl (FUNCTION_DECL, get_identifier (name), fntype);
05128
05129
05130 TREE_PUBLIC (fndecl) = 0;
05131 DECL_ARTIFICIAL (fndecl) = 1;
05132
05133
05134
05135
05136 DECL_INLINE (fndecl) = 1;
05137 DECL_DECLARED_INLINE_P (fndecl) = 1;
05138 DECL_INTERFACE_KNOWN (fndecl) = 1;
05139
05140 if (flag_use_cxa_atexit)
05141 {
05142 tree parmdecl;
05143
05144 parmdecl = cp_build_parm_decl (NULL_TREE, ptr_type_node);
05145 DECL_CONTEXT (parmdecl) = fndecl;
05146 TREE_USED (parmdecl) = 1;
05147 DECL_ARGUMENTS (fndecl) = parmdecl;
05148 }
05149
05150 pushdecl (fndecl);
05151 start_preparsed_function (fndecl, NULL_TREE, SF_PRE_PARSED);
05152
05153 pop_lang_context ();
05154
05155 return current_function_decl;
05156 }
05157
05158
05159
05160 static void
05161 end_cleanup_fn (void)
05162 {
05163 expand_or_defer_fn (finish_function (0));
05164
05165 pop_from_top_level ();
05166 }
05167
05168
05169
05170
05171 tree
05172 register_dtor_fn (tree decl)
05173 {
05174 tree cleanup;
05175 tree compound_stmt;
05176 tree args;
05177 tree fcall;
05178
05179 if (TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
05180 return void_zero_node;
05181
05182
05183
05184
05185 build_cleanup (decl);
05186
05187
05188 cleanup = start_cleanup_fn ();
05189
05190
05191
05192
05193
05194
05195 push_deferring_access_checks (dk_no_check);
05196 fcall = build_cleanup (decl);
05197 pop_deferring_access_checks ();
05198
05199
05200 compound_stmt = begin_compound_stmt (BCS_FN_BODY);
05201 finish_expr_stmt (fcall);
05202 finish_compound_stmt (compound_stmt);
05203 end_cleanup_fn ();
05204
05205
05206 cxx_mark_addressable (cleanup);
05207 mark_used (cleanup);
05208 cleanup = build_unary_op (ADDR_EXPR, cleanup, 0);
05209 if (flag_use_cxa_atexit)
05210 {
05211 args = tree_cons (NULL_TREE,
05212 build_unary_op (ADDR_EXPR, get_dso_handle_node (), 0),
05213 NULL_TREE);
05214 args = tree_cons (NULL_TREE, null_pointer_node, args);
05215 args = tree_cons (NULL_TREE, cleanup, args);
05216 }
05217 else
05218 args = tree_cons (NULL_TREE, cleanup, NULL_TREE);
05219 return build_function_call (get_atexit_node (), args);
05220 }
05221
05222
05223
05224
05225
05226 static void
05227 expand_static_init (tree decl, tree init)
05228 {
05229 gcc_assert (TREE_CODE (decl) == VAR_DECL);
05230 gcc_assert (TREE_STATIC (decl));
05231
05232
05233 if (!init
05234 && !TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))
05235 && TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
05236 return;
05237
05238 if (DECL_FUNCTION_SCOPE_P (decl))
05239 {
05240
05241 tree if_stmt = NULL_TREE, inner_if_stmt = NULL_TREE;
05242 tree then_clause = NULL_TREE, inner_then_clause = NULL_TREE;
05243 tree guard, guard_addr, guard_addr_list;
05244 tree acquire_fn, release_fn, abort_fn;
05245 tree flag, begin;
05246
05247
05248
05249
05250
05251
05252
05253
05254
05255
05256
05257
05258
05259
05260
05261
05262
05263
05264
05265
05266
05267
05268
05269
05270
05271
05272
05273
05274
05275
05276
05277
05278
05279 guard = get_guard (decl);
05280
05281
05282
05283
05284 if (!targetm.relaxed_ordering || !flag_threadsafe_statics)
05285 {
05286
05287 if_stmt = begin_if_stmt ();
05288 finish_if_stmt_cond (get_guard_cond (guard), if_stmt);
05289 then_clause = begin_compound_stmt (BCS_NO_SCOPE);
05290 }
05291
05292 if (flag_threadsafe_statics)
05293 {
05294 guard_addr = build_address (guard);
05295 guard_addr_list = build_tree_list (NULL_TREE, guard_addr);
05296
05297 acquire_fn = get_identifier ("__cxa_guard_acquire");
05298 release_fn = get_identifier ("__cxa_guard_release");
05299 abort_fn = get_identifier ("__cxa_guard_abort");
05300 if (!get_global_value_if_present (acquire_fn, &acquire_fn))
05301 {
05302 tree argtypes = tree_cons (NULL_TREE, TREE_TYPE (guard_addr),
05303 void_list_node);
05304 tree vfntype = build_function_type (void_type_node, argtypes);
05305 acquire_fn = push_library_fn
05306 (acquire_fn, build_function_type (integer_type_node, argtypes));
05307 release_fn = push_library_fn (release_fn, vfntype);
05308 abort_fn = push_library_fn (abort_fn, vfntype);
05309 }
05310 else
05311 {
05312 release_fn = identifier_global_value (release_fn);
05313 abort_fn = identifier_global_value (abort_fn);
05314 }
05315
05316 inner_if_stmt = begin_if_stmt ();
05317 finish_if_stmt_cond (build_call (acquire_fn, guard_addr_list),
05318 inner_if_stmt);
05319
05320 inner_then_clause = begin_compound_stmt (BCS_NO_SCOPE);
05321 begin = get_target_expr (boolean_false_node);
05322 flag = TARGET_EXPR_SLOT (begin);
05323
05324 TARGET_EXPR_CLEANUP (begin)
05325 = build (COND_EXPR, void_type_node, flag,
05326 void_zero_node,
05327 build_call (abort_fn, guard_addr_list));
05328 CLEANUP_EH_ONLY (begin) = 1;
05329
05330
05331 init = add_stmt_to_compound (begin, init);
05332 init = add_stmt_to_compound
05333 (init, build (MODIFY_EXPR, void_type_node, flag, boolean_true_node));
05334 init = add_stmt_to_compound
05335 (init, build_call (release_fn, guard_addr_list));
05336 }
05337 else
05338 init = add_stmt_to_compound (init, set_guard (guard));
05339
05340
05341
05342 init = add_stmt_to_compound (init, register_dtor_fn (decl));
05343
05344 finish_expr_stmt (init);
05345
05346 if (flag_threadsafe_statics)
05347 {
05348 finish_compound_stmt (inner_then_clause);
05349 finish_then_clause (inner_if_stmt);
05350 finish_if_stmt (inner_if_stmt);
05351 }
05352
05353 if (!targetm.relaxed_ordering || !flag_threadsafe_statics)
05354 {
05355 finish_compound_stmt (then_clause);
05356 finish_then_clause (if_stmt);
05357 finish_if_stmt (if_stmt);
05358 }
05359 }
05360 else
05361 static_aggregates = tree_cons (init, decl, static_aggregates);
05362 }
05363
05364
05365
05366
05367
05368
05369 int
05370 cp_complete_array_type (tree *ptype, tree initial_value, bool do_default)
05371 {
05372 int failure;
05373 tree type, elt_type;
05374
05375 if (initial_value)
05376 {
05377
05378
05379 if (char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (*ptype)))
05380 && TREE_CODE (initial_value) == CONSTRUCTOR
05381 && CONSTRUCTOR_ELTS (initial_value)
05382 && (TREE_CODE (TREE_VALUE (CONSTRUCTOR_ELTS (initial_value)))
05383 == STRING_CST)
05384 && TREE_CHAIN (CONSTRUCTOR_ELTS (initial_value)) == NULL_TREE)
05385 initial_value = TREE_VALUE (CONSTRUCTOR_ELTS (initial_value));
05386 }
05387
05388 failure = complete_array_type (ptype, initial_value, do_default);
05389
05390
05391
05392
05393
05394
05395 type = *ptype;
05396 if (TYPE_DOMAIN (type))
05397 {
05398 elt_type = TREE_TYPE (type);
05399 TYPE_NEEDS_CONSTRUCTING (type) = TYPE_NEEDS_CONSTRUCTING (elt_type);
05400 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
05401 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type);
05402 }
05403
05404 return failure;
05405 }
05406
05407
05408
05409
05410
05411 static int
05412 member_function_or_else (tree ctype, tree cur_type, enum overload_flags flags)
05413 {
05414 if (ctype && ctype != cur_type)
05415 {
05416 if (flags == DTOR_FLAG)
05417 error ("destructor for alien class %qT cannot be a member", ctype);
05418 else
05419 error ("constructor for alien class %qT cannot be a member", ctype);
05420 return 0;
05421 }
05422 return 1;
05423 }
05424
05425
05426
05427
05428
05429
05430 static void
05431 bad_specifiers (tree object,
05432 const char* type,
05433 int virtualp,
05434 int quals,
05435 int inlinep,
05436 int friendp,
05437 int raises)
05438 {
05439 if (virtualp)
05440 error ("%qD declared as a %<virtual%> %s", object, type);
05441 if (inlinep)
05442 error ("%qD declared as an %<inline%> %s", object, type);
05443 if (quals)
05444 error ("%<const%> and %<volatile%> function specifiers on "
05445 "%qD invalid in %s declaration",
05446 object, type);
05447 if (friendp)
05448 cp_error_at ("%qD declared as a friend", object);
05449 if (raises
05450 && (TREE_CODE (object) == TYPE_DECL
05451 || (!TYPE_PTRFN_P (TREE_TYPE (object))
05452 && !TYPE_REFFN_P (TREE_TYPE (object))
05453 && !TYPE_PTRMEMFUNC_P (TREE_TYPE (object)))))
05454 cp_error_at ("%qD declared with an exception specification", object);
05455 }
05456
05457
05458
05459
05460
05461
05462
05463
05464
05465
05466
05467
05468
05469
05470
05471
05472
05473
05474
05475 static tree
05476 grokfndecl (tree ctype,
05477 tree type,
05478 tree declarator,
05479 tree parms,
05480 tree orig_declarator,
05481 int virtualp,
05482 enum overload_flags flags,
05483 cp_cv_quals quals,
05484 tree raises,
05485 int check,
05486 int friendp,
05487 int publicp,
05488 int inlinep,
05489 special_function_kind sfk,
05490 int funcdef_flag,
05491 int template_count,
05492 tree in_namespace,
05493 tree* attrlist)
05494 {
05495 tree decl;
05496 int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE;
05497 int has_default_arg = 0;
05498 tree t;
05499
05500 if (raises)
05501 type = build_exception_variant (type, raises);
05502
05503 decl = build_lang_decl (FUNCTION_DECL, declarator, type);
05504 DECL_ARGUMENTS (decl) = parms;
05505
05506 if (TYPE_VOLATILE (type))
05507 TREE_THIS_VOLATILE (decl) = 1;
05508
05509
05510 if (in_namespace)
05511 set_decl_namespace (decl, in_namespace, friendp);
05512 else if (!ctype)
05513 DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
05514
05515
05516 if ((MAIN_NAME_P (declarator)
05517 || (IDENTIFIER_LENGTH (declarator) > 10
05518 && IDENTIFIER_POINTER (declarator)[0] == '_'
05519 && IDENTIFIER_POINTER (declarator)[1] == '_'
05520 && strncmp (IDENTIFIER_POINTER (declarator)+2, "builtin_", 8) == 0))
05521 && current_lang_name == lang_name_cplusplus
05522 && ctype == NULL_TREE
05523
05524 && DECL_CONTEXT (decl) == NULL_TREE)
05525 SET_DECL_LANGUAGE (decl, lang_c);
05526
05527
05528 if (staticp)
05529 {
05530 DECL_STATIC_FUNCTION_P (decl) = 1;
05531 DECL_CONTEXT (decl) = ctype;
05532 }
05533
05534 if (ctype)
05535 DECL_CONTEXT (decl) = ctype;
05536
05537 if (ctype == NULL_TREE && DECL_MAIN_P (decl))
05538 {
05539 if (processing_template_decl)
05540 error ("cannot declare %<::main%> to be a template");
05541 if (inlinep)
05542 error ("cannot declare %<::main%> to be inline");
05543 if (!publicp)
05544 error ("cannot declare %<::main%> to be static");
05545 if (!same_type_p (TREE_TYPE (TREE_TYPE (decl)),
05546 integer_type_node))
05547 {
05548 error ("%<::main%> must return %<int%>");
05549 TREE_TYPE (TREE_TYPE (decl)) = integer_type_node;
05550 }
05551 inlinep = 0;
05552 publicp = 1;
05553 }
05554
05555
05556
05557 if (ctype && (TYPE_ANONYMOUS_P (ctype)
05558 || decl_function_context (TYPE_MAIN_DECL (ctype))))
05559 publicp = 0;
05560
05561 if (publicp)
05562 {
05563
05564
05565
05566
05567
05568 t = no_linkage_check (TREE_TYPE (decl),
05569 false);
05570 if (t)
05571 {
05572 if (TYPE_ANONYMOUS_P (t))
05573 {
05574 if (DECL_EXTERN_C_P (decl))
05575 ;
05576 else
05577 {
05578 pedwarn ("non-local function %q#D uses anonymous type",
05579 decl);
05580 if (DECL_ORIGINAL_TYPE (TYPE_NAME (t)))
05581 cp_pedwarn_at ("%q#D does not refer to the unqualified "
05582 "type, so it is not used for linkage",
05583 TYPE_NAME (t));
05584 }
05585 }
05586 else
05587 pedwarn ("non-local function %q#D uses local type %qT", decl, t);
05588 }
05589 }
05590
05591 TREE_PUBLIC (decl) = publicp;
05592 if (! publicp)
05593 {
05594 DECL_INTERFACE_KNOWN (decl) = 1;
05595 DECL_NOT_REALLY_EXTERN (decl) = 1;
05596 }
05597
05598
05599 if (inlinep)
05600 DECL_DECLARED_INLINE_P (decl) = 1;
05601
05602
05603 if (DECL_DECLARED_INLINE_P (decl)
05604 || (flag_inline_trees == 2 && !DECL_INLINE (decl) && funcdef_flag))
05605 DECL_INLINE (decl) = 1;
05606
05607 DECL_EXTERNAL (decl) = 1;
05608 if (quals && TREE_CODE (type) == FUNCTION_TYPE)
05609 {
05610 error ("%smember function %qD cannot have cv-qualifier",
05611 (ctype ? "static " : "non-"), decl);
05612 quals = TYPE_UNQUALIFIED;
05613 }
05614
05615 if (IDENTIFIER_OPNAME_P (DECL_NAME (decl)))
05616 grok_op_properties (decl, true);
05617
05618 if (ctype && decl_function_context (decl))
05619 DECL_NO_STATIC_CHAIN (decl) = 1;
05620
05621 for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t))
05622 if (TREE_PURPOSE (t)
05623 && TREE_CODE (TREE_PURPOSE (t)) == DEFAULT_ARG)
05624 {
05625 has_default_arg = 1;
05626 break;
05627 }
05628
05629 if (friendp
05630 && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)
05631 {
05632 if (funcdef_flag)
05633 error
05634 ("defining explicit specialization %qD in friend declaration",
05635 orig_declarator);
05636 else
05637 {
05638 tree fns = TREE_OPERAND (orig_declarator, 0);
05639 tree args = TREE_OPERAND (orig_declarator, 1);
05640
05641 if (PROCESSING_REAL_TEMPLATE_DECL_P ())
05642 {
05643
05644 error ("invalid use of template-id %qD in declaration "
05645 "of primary template",
05646 orig_declarator);
05647 return NULL_TREE;
05648 }
05649
05650
05651
05652
05653 SET_DECL_IMPLICIT_INSTANTIATION (decl);
05654
05655 if (TREE_CODE (fns) == COMPONENT_REF)
05656 {
05657
05658
05659
05660
05661
05662 gcc_assert (TREE_TYPE (TREE_OPERAND (fns, 0))
05663 == current_class_type);
05664 fns = TREE_OPERAND (fns, 1);
05665 }
05666 gcc_assert (TREE_CODE (fns) == IDENTIFIER_NODE
05667 || TREE_CODE (fns) == OVERLOAD);
05668 DECL_TEMPLATE_INFO (decl) = tree_cons (fns, args, NULL_TREE);
05669
05670 if (has_default_arg)
05671 {
05672 error ("default arguments are not allowed in declaration "
05673 "of friend template specialization %qD",
05674 decl);
05675 return NULL_TREE;
05676 }
05677
05678 if (inlinep)
05679 {
05680 error ("%<inline%> is not allowed in declaration of friend "
05681 "template specialization %qD",
05682 decl);
05683 return NULL_TREE;
05684 }
05685 }
05686 }
05687
05688 if (funcdef_flag)
05689
05690
05691 DECL_INITIAL (decl) = error_mark_node;
05692
05693 if (TYPE_NOTHROW_P (type) || nothrow_libfn_p (decl))
05694 TREE_NOTHROW (decl) = 1;
05695
05696
05697 if (check < 0)
05698 return decl;
05699
05700 if (ctype != NULL_TREE)
05701 {
05702 if (sfk == sfk_constructor)
05703 DECL_CONSTRUCTOR_P (decl) = 1;
05704
05705 grokclassfn (ctype, decl, flags, quals);
05706 }
05707
05708 decl = check_explicit_specialization (orig_declarator, decl,
05709 template_count,
05710 2 * (funcdef_flag != 0) +
05711 4 * (friendp != 0));
05712 if (decl == error_mark_node)
05713 return NULL_TREE;
05714
05715 if (attrlist)
05716 {
05717 cplus_decl_attributes (&decl, *attrlist, 0);
05718 *attrlist = NULL_TREE;
05719 }
05720
05721 if (ctype != NULL_TREE
05722 && (! TYPE_FOR_JAVA (ctype) || check_java_method (decl))
05723 && check)
05724 {
05725 tree old_decl;
05726
05727 old_decl = check_classfn (ctype, decl,
05728 (processing_template_decl
05729 > template_class_depth (ctype))
05730 ? current_template_parms
05731 : NULL_TREE);
05732
05733 if (old_decl && TREE_CODE (old_decl) == TEMPLATE_DECL)
05734
05735
05736
05737
05738 old_decl = DECL_TEMPLATE_RESULT (old_decl);
05739
05740 if (old_decl && DECL_STATIC_FUNCTION_P (old_decl)
05741 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
05742
05743
05744 revert_static_member_fn (decl);
05745 if (old_decl && DECL_ARTIFICIAL (old_decl))
05746 error ("definition of implicitly-declared %qD", old_decl);
05747
05748 if (old_decl)
05749 {
05750 tree ok;
05751 tree pushed_scope;
05752
05753
05754
05755 if (TREE_CODE (decl) == TEMPLATE_DECL)
05756 decl = DECL_TEMPLATE_RESULT (decl);
05757
05758
05759
05760 pushed_scope = push_scope (ctype);
05761 ok = duplicate_decls (decl, old_decl);
05762 if (pushed_scope)
05763 pop_scope (pushed_scope);
05764 if (!ok)
05765 {
05766 error ("no %q#D member function declared in class %qT",
05767 decl, ctype);
05768 return NULL_TREE;
05769 }
05770 return old_decl;
05771 }
05772 }
05773
05774 if (DECL_CONSTRUCTOR_P (decl) && !grok_ctor_properties (ctype, decl))
05775 return NULL_TREE;
05776
05777 if (ctype == NULL_TREE || check)
05778 return decl;
05779
05780 if (virtualp)
05781 DECL_VIRTUAL_P (decl) = 1;
05782
05783 return decl;
05784 }
05785
05786
05787
05788
05789 static void
05790 set_linkage_for_static_data_member (tree decl)
05791 {
05792
05793
05794
05795
05796 TREE_PUBLIC (decl) = 1;
05797 TREE_STATIC (decl) = 1;
05798
05799
05800
05801 if (!processing_template_decl)
05802 DECL_INTERFACE_KNOWN (decl) = 1;
05803 }
05804
05805
05806
05807
05808
05809
05810
05811 static tree
05812 grokvardecl (tree type,
05813 tree name,
05814 const cp_decl_specifier_seq *declspecs,
05815 int initialized,
05816 int constp,
05817 tree scope)
05818 {
05819 tree decl;
05820 tree explicit_scope;
05821
05822 gcc_assert (!name || TREE_CODE (name) == IDENTIFIER_NODE);
05823
05824
05825
05826 explicit_scope = scope;
05827 if (!scope)
05828 {
05829
05830
05831 if (declspecs->storage_class == sc_extern)
05832 scope = current_namespace;
05833 else if (!at_function_scope_p ())
05834 scope = current_scope ();
05835 }
05836
05837 if (scope
05838 && (
05839
05840 (TREE_CODE (scope) == NAMESPACE_DECL && processing_template_decl)
05841
05842
05843 || (TREE_CODE (scope) == NAMESPACE_DECL
05844 && current_lang_name != lang_name_cplusplus)
05845
05846 || TYPE_P (scope)))
05847 decl = build_lang_decl (VAR_DECL, name, type);
05848 else
05849 decl = build_decl (VAR_DECL, name, type);
05850
05851 if (explicit_scope && TREE_CODE (explicit_scope) == NAMESPACE_DECL)
05852 set_decl_namespace (decl, explicit_scope, 0);
05853 else
05854 DECL_CONTEXT (decl) = scope;
05855
05856 if (declspecs->storage_class == sc_extern)
05857 {
05858 DECL_THIS_EXTERN (decl) = 1;
05859 DECL_EXTERNAL (decl) = !initialized;
05860 }
05861
05862 if (DECL_CLASS_SCOPE_P (decl))
05863 {
05864 set_linkage_for_static_data_member (decl);
05865
05866 DECL_EXTERNAL (decl) = 0;
05867 }
05868
05869
05870 else if (toplevel_bindings_p ())
05871 {
05872 TREE_PUBLIC (decl) = (declspecs->storage_class != sc_static
05873 && (DECL_THIS_EXTERN (decl) || ! constp));
05874 TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
05875 }
05876
05877 else
05878 {
05879 TREE_STATIC (decl) = declspecs->storage_class == sc_static;
05880 TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
05881 }
05882
05883 if (declspecs->specs[(int)ds_thread])
05884 {
05885 if (targetm.have_tls)
05886 DECL_THREAD_LOCAL (decl) = 1;
05887 else
05888
05889
05890 error ("thread-local storage not supported for this target");
05891 }
05892
05893 if (TREE_PUBLIC (decl))
05894 {
05895
05896
05897
05898
05899
05900 tree t = no_linkage_check (TREE_TYPE (decl), false);
05901 if (t)
05902 {
05903 if (TYPE_ANONYMOUS_P (t))
05904 {
05905 if (DECL_EXTERN_C_P (decl))
05906
05907 ;
05908 else
05909 {
05910
05911
05912
05913
05914 warning ("non-local variable %q#D uses anonymous type",
05915 decl);
05916 if (DECL_ORIGINAL_TYPE (TYPE_NAME (t)))
05917 cp_warning_at ("%q#D does not refer to the unqualified "
05918 "type, so it is not used for linkage",
05919 TYPE_NAME (t));
05920 }
05921 }
05922 else
05923 warning ("non-local variable %q#D uses local type %qT", decl, t);
05924 }
05925 }
05926 else
05927 DECL_INTERFACE_KNOWN (decl) = 1;
05928
05929 return decl;
05930 }
05931
05932
05933
05934
05935 tree
05936 build_ptrmemfunc_type (tree type)
05937 {
05938 tree field, fields;
05939 tree t;
05940 tree unqualified_variant = NULL_TREE;
05941
05942 if (type == error_mark_node)
05943 return type;
05944
05945
05946
05947
05948
05949 if ((t = TYPE_GET_PTRMEMFUNC_TYPE (type)))
05950 return t;
05951
05952
05953
05954 if (cp_type_quals (type) != TYPE_UNQUALIFIED)
05955 unqualified_variant
05956 = build_ptrmemfunc_type (TYPE_MAIN_VARIANT (type));
05957
05958 t = make_aggr_type (RECORD_TYPE);
05959 xref_basetypes (t, NULL_TREE);
05960
05961
05962 TYPE_PTRMEMFUNC_FLAG (t) = 1;
05963
05964 SET_IS_AGGR_TYPE (t, 0);
05965
05966 field = build_decl (FIELD_DECL, pfn_identifier, type);
05967 fields = field;
05968
05969 field = build_decl (FIELD_DECL, delta_identifier, delta_type_node);
05970 TREE_CHAIN (field) = fields;
05971 fields = field;
05972
05973 finish_builtin_struct (t, "__ptrmemfunc_type", fields, ptr_type_node);
05974
05975
05976
05977 TYPE_NAME (t) = NULL_TREE;
05978
05979
05980
05981
05982
05983 if (cp_type_quals (type) != TYPE_UNQUALIFIED)
05984 {
05985 t = build_qualified_type (t, cp_type_quals (type));
05986 TYPE_MAIN_VARIANT (t) = unqualified_variant;
05987 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (unqualified_variant);
05988 TYPE_NEXT_VARIANT (unqualified_variant) = t;
05989 }
05990
05991
05992
05993 TYPE_SET_PTRMEMFUNC_TYPE (type, t);
05994
05995 return t;
05996 }
05997
05998
05999
06000 tree
06001 build_ptrmem_type (tree class_type, tree member_type)
06002 {
06003 if (TREE_CODE (member_type) == METHOD_TYPE)
06004 {
06005 tree arg_types;
06006
06007 arg_types = TYPE_ARG_TYPES (member_type);
06008 class_type = (cp_build_qualified_type
06009 (class_type,
06010 cp_type_quals (TREE_TYPE (TREE_VALUE (arg_types)))));
06011 member_type
06012 = build_method_type_directly (class_type,
06013 TREE_TYPE (member_type),
06014 TREE_CHAIN (arg_types));
06015 return build_ptrmemfunc_type (build_pointer_type (member_type));
06016 }
06017 else
06018 {
06019 gcc_assert (TREE_CODE (member_type) != FUNCTION_TYPE);
06020 return build_offset_type (class_type, member_type);
06021 }
06022 }
06023
06024
06025
06026
06027
06028
06029 int
06030 check_static_variable_definition (tree decl, tree type)
06031 {
06032
06033
06034
06035
06036
06037
06038 if (!ARITHMETIC_TYPE_P (type) && TREE_CODE (type) != ENUMERAL_TYPE)
06039 {
06040 error ("invalid in-class initialization of static data member "
06041 "of non-integral type %qT",
06042 type);
06043
06044
06045
06046
06047 return 1;
06048 }
06049 else if (!CP_TYPE_CONST_P (type))
06050 error ("ISO C++ forbids in-class initialization of non-const "
06051 "static member %qD",
06052 decl);
06053 else if (pedantic && !INTEGRAL_TYPE_P (type))
06054 pedwarn ("ISO C++ forbids initialization of member constant "
06055 "%qD of non-integral type %qT", decl, type);
06056
06057 return 0;
06058 }
06059
06060
06061
06062
06063
06064 tree
06065 compute_array_index_type (tree name, tree size)
06066 {
06067 tree type = TREE_TYPE (size);
06068 tree itype;
06069
06070
06071 if (!dependent_type_p (type) && !INTEGRAL_TYPE_P (type))
06072 {
06073 if (name)
06074 error ("size of array %qD has non-integral type %qT", name, type);
06075 else
06076 error ("size of array has non-integral type %qT", type);
06077 size = integer_one_node;
06078 type = TREE_TYPE (size);
06079 }
06080
06081 if (abi_version_at_least (2)
06082
06083 ? value_dependent_expression_p (size)
06084
06085
06086 : processing_template_decl)
06087 return build_index_type (build_min (MINUS_EXPR, sizetype,
06088 size, integer_one_node));
06089
06090
06091 STRIP_TYPE_NOPS (size);
06092
06093
06094 size = integral_constant_value (size);
06095
06096
06097 if (TREE_CODE (size) == INTEGER_CST)
06098 {
06099
06100
06101 int old_flag_pedantic_errors = flag_pedantic_errors;
06102 int old_pedantic = pedantic;
06103 pedantic = flag_pedantic_errors = 1;
06104 constant_expression_warning (size);
06105 pedantic = old_pedantic;
06106 flag_pedantic_errors = old_flag_pedantic_errors;
06107
06108
06109 if (INT_CST_LT (size, integer_zero_node))
06110 {
06111 if (name)
06112 error ("size of array %qD is negative", name);
06113 else
06114 error ("size of array is negative");
06115 size = integer_one_node;
06116 }
06117
06118
06119 else if (integer_zerop (size) && pedantic && !in_system_header)
06120 {
06121 if (name)
06122 pedwarn ("ISO C++ forbids zero-size array %qD", name);
06123 else
06124 pedwarn ("ISO C++ forbids zero-size array");
06125 }
06126 }
06127 else if (TREE_CONSTANT (size))
06128 {
06129
06130 if (name)
06131 error ("size of array %qD is not an integral constant-expression",
06132 name);
06133 else
06134 error ("size of array is not an integral constant-expression");
06135 }
06136 else if (pedantic)
06137 {
06138 if (name)
06139 pedwarn ("ISO C++ forbids variable-size array %qD", name);
06140 else
06141 pedwarn ("ISO C++ forbids variable-size array");
06142 }
06143
06144 if (processing_template_decl && !TREE_CONSTANT (size))
06145
06146 itype = build_min (MINUS_EXPR, sizetype, size, integer_one_node);
06147 else
06148 {
06149 HOST_WIDE_INT saved_processing_template_decl;
06150
06151
06152
06153
06154
06155 saved_processing_template_decl = processing_template_decl;
06156 processing_template_decl = 0;
06157 itype = cp_build_binary_op (MINUS_EXPR,
06158 cp_convert (ssizetype, size),
06159 cp_convert (ssizetype, integer_one_node));
06160 itype = fold (itype);
06161 processing_template_decl = saved_processing_template_decl;
06162
06163 if (!TREE_CONSTANT (itype))
06164
06165 itype = variable_size (itype);
06166
06167
06168
06169 else if (TREE_OVERFLOW (itype))
06170 {
06171 error ("overflow in array dimension");
06172 TREE_OVERFLOW (itype) = 0;
06173 }
06174 }
06175
06176
06177 return build_index_type (itype);
06178 }
06179
06180
06181
06182
06183
06184 tree
06185 get_scope_of_declarator (const cp_declarator *declarator)
06186 {
06187 while (declarator && declarator->kind != cdk_id)
06188 declarator = declarator->declarator;
06189
06190
06191
06192 if (declarator
06193 && declarator->u.id.qualifying_scope)
06194 return declarator->u.id.qualifying_scope;
06195
06196
06197
06198 return NULL_TREE;
06199 }
06200
06201
06202
06203
06204
06205 static tree
06206 create_array_type_for_decl (tree name, tree type, tree size)
06207 {
06208 tree itype = NULL_TREE;
06209 const char* error_msg;
06210
06211
06212 if (type == error_mark_node || size == error_mark_node)
06213 return error_mark_node;
06214
06215
06216 error_msg = NULL;
06217
06218
06219 switch (TREE_CODE (type))
06220 {
06221 case VOID_TYPE:
06222 error_msg = "array of void";
06223 break;
06224
06225 case FUNCTION_TYPE:
06226 error_msg = "array of functions";
06227 break;
06228
06229 case REFERENCE_TYPE:
06230 error_msg = "array of references";
06231 break;
06232
06233 case METHOD_TYPE:
06234 error_msg = "array of function members";
06235 break;
06236
06237 default:
06238 break;
06239 }
06240
06241
06242 if (error_msg)
06243 {
06244 if (name)
06245 error ("declaration of %qD as %s", name, error_msg);
06246 else
06247 error ("creating %s", error_msg);
06248
06249 return error_mark_node;
06250 }
06251
06252
06253
06254
06255
06256 if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
06257 {
06258 if (name)
06259 error ("declaration of %qD as multidimensional array must "
06260 "have bounds for all dimensions except the first",
06261 name);
06262 else
06263 error ("multidimensional array must have bounds for all "
06264 "dimensions except the first");
06265
06266 return error_mark_node;
06267 }
06268
06269
06270 if (size)
06271 itype = compute_array_index_type (name, size);
06272
06273
06274
06275
06276 abstract_virtuals_error (name, type);
06277
06278 return build_cplus_array_type (type, itype);
06279 }
06280
06281
06282
06283
06284
06285
06286
06287
06288
06289 static tree
06290 check_special_function_return_type (special_function_kind sfk,
06291 tree type,
06292 tree optype)
06293 {
06294 switch (sfk)
06295 {
06296 case sfk_constructor:
06297 if (type)
06298 error ("return type specification for constructor invalid");
06299
06300 if (targetm.cxx.cdtor_returns_this () && !TYPE_FOR_JAVA (optype))
06301 type = build_pointer_type (optype);
06302 else
06303 type = void_type_node;
06304 break;
06305
06306 case sfk_destructor:
06307 if (type)
06308 error ("return type specification for destructor invalid");
06309
06310
06311
06312
06313 if (targetm.cxx.cdtor_returns_this () && !TYPE_FOR_JAVA (optype))
06314 type = build_pointer_type (void_type_node);
06315 else
06316 type = void_type_node;
06317 break;
06318
06319 case sfk_conversion:
06320 if (type && !same_type_p (type, optype))
06321 error ("operator %qT declared to return %qT", optype, type);
06322 else if (type)
06323 pedwarn ("return type specified for %<operator %T%>", optype);
06324 type = optype;
06325 break;
06326
06327 default:
06328 gcc_unreachable ();
06329 }
06330
06331 return type;
06332 }
06333
06334
06335
06336
06337
06338
06339 tree
06340 check_var_type (tree identifier, tree type)
06341 {
06342 if (VOID_TYPE_P (type))
06343 {
06344 if (!identifier)
06345 error ("unnamed variable or field declared void");
06346 else if (TREE_CODE (identifier) == IDENTIFIER_NODE)
06347 {
06348 gcc_assert (!IDENTIFIER_OPNAME_P (identifier));
06349 error ("variable or field %qE declared void", identifier);
06350 }
06351 else
06352 error ("variable or field declared void");
06353 type = integer_type_node;
06354 }
06355
06356 return type;
06357 }
06358
06359
06360
06361
06362
06363
06364
06365
06366
06367
06368
06369
06370
06371
06372
06373
06374
06375
06376
06377
06378
06379
06380
06381
06382
06383
06384
06385
06386
06387
06388
06389
06390
06391
06392
06393
06394
06395
06396
06397
06398 tree
06399 grokdeclarator (const cp_declarator *declarator,
06400 const cp_decl_specifier_seq *declspecs,
06401 enum decl_context decl_context,
06402 int initialized,
06403 tree* attrlist)
06404 {
06405 tree type = NULL_TREE;
06406 int longlong = 0;
06407 int type_quals;
06408 int virtualp, explicitp, friendp, inlinep, staticp;
06409 int explicit_int = 0;
06410 int explicit_char = 0;
06411 int defaulted_int = 0;
06412 tree dependant_name = NULL_TREE;
06413
06414 tree typedef_decl = NULL_TREE;
06415 const char *name = NULL;
06416 tree typedef_type = NULL_TREE;
06417 int funcdef_flag = 0;
06418 cp_declarator_kind innermost_code = cdk_error;
06419 int bitfield = 0;
06420 #if 0
06421
06422 tree decl_attr = NULL_TREE;
06423 #endif
06424
06425
06426
06427
06428 special_function_kind sfk = sfk_none;
06429
06430 tree dname = NULL_TREE;
06431 tree ctor_return_type = NULL_TREE;
06432 enum overload_flags flags = NO_SPECIAL;
06433 cp_cv_quals quals = TYPE_UNQUALIFIED;
06434 tree raises = NULL_TREE;
06435 int template_count = 0;
06436 tree returned_attrs = NULL_TREE;
06437 tree parms = NULL_TREE;
06438 const cp_declarator *id_declarator;
06439
06440
06441 tree unqualified_id;
06442
06443
06444
06445
06446 tree ctype = current_class_type;
06447
06448
06449
06450
06451 tree in_namespace = NULL_TREE;
06452 cp_decl_spec ds;
06453 cp_storage_class storage_class;
06454 bool unsigned_p, signed_p, short_p, long_p, thread_p;
06455 bool type_was_error_mark_node = false;
06456
06457 signed_p = declspecs->specs[(int)ds_signed];
06458 unsigned_p = declspecs->specs[(int)ds_unsigned];
06459 short_p = declspecs->specs[(int)ds_short];
06460 long_p = declspecs->specs[(int)ds_long];
06461 thread_p = declspecs->specs[(int)ds_thread];
06462
06463 if (decl_context == FUNCDEF)
06464 funcdef_flag = 1, decl_context = NORMAL;
06465 else if (decl_context == MEMFUNCDEF)
06466 funcdef_flag = -1, decl_context = FIELD;
06467 else if (decl_context == BITFIELD)
06468 bitfield = 1, decl_context = FIELD;
06469
06470
06471
06472 for (id_declarator = declarator;
06473 id_declarator;
06474 id_declarator = id_declarator->declarator)
06475 {
06476 if (id_declarator->kind != cdk_id)
06477 innermost_code = id_declarator->kind;
06478
06479 switch (id_declarator->kind)
06480 {
06481 case cdk_function:
06482 if (id_declarator->declarator
06483 && id_declarator->declarator->kind == cdk_id)
06484 {
06485 sfk = id_declarator->declarator->u.id.sfk;
06486 if (sfk == sfk_destructor)
06487 flags = DTOR_FLAG;
06488 }
06489 break;
06490
06491 case cdk_id:
06492 {
06493 tree qualifying_scope = id_declarator->u.id.qualifying_scope;
06494 tree decl = id_declarator->u.id.unqualified_name;
06495 if (!decl)
06496 break;
06497 if (qualifying_scope)
06498 {
06499 if (TYPE_P (qualifying_scope))
06500 {
06501 ctype = qualifying_scope;
06502 if (innermost_code != cdk_function
06503 && current_class_type
06504 && !UNIQUELY_DERIVED_FROM_P (ctype,
06505 current_class_type))
06506 {
06507 error ("type %qT is not derived from type %qT",
06508 ctype, current_class_type);
06509 return error_mark_node;
06510 }
06511 }
06512 else if (TREE_CODE (qualifying_scope) == NAMESPACE_DECL)
06513 in_namespace = qualifying_scope;
06514 }
06515 if (TREE_CODE (decl) == BASELINK)
06516 decl = BASELINK_FUNCTIONS (decl);
06517 if (decl == error_mark_node)
06518 return error_mark_node;
06519 switch (TREE_CODE (decl))
06520 {
06521 case BIT_NOT_EXPR:
06522 {
06523 tree type;
06524
06525 if (innermost_code != cdk_function)
06526 {
06527 error ("declaration of %qD as non-function", decl);
06528 return error_mark_node;
06529 }
06530 else if (!qualifying_scope
06531 && !(current_class_type && at_class_scope_p ()))
06532 {
06533 error ("declaration of %qD as non-member", decl);
06534 return error_mark_node;
06535 }
06536
06537 type = TREE_OPERAND (decl, 0);
06538 name = IDENTIFIER_POINTER (constructor_name (type));
06539 }
06540 break;
06541
06542 case TEMPLATE_ID_EXPR:
06543 {
06544 tree fns = TREE_OPERAND (decl, 0);
06545
06546 dname = fns;
06547 if (TREE_CODE (dname) == COMPONENT_REF)
06548 dname = TREE_OPERAND (dname, 1);
06549 if (TREE_CODE (dname) != IDENTIFIER_NODE)
06550 {
06551 gcc_assert (is_overloaded_fn (dname));
06552 dname = DECL_NAME (get_first_fn (dname));
06553 }
06554 }
06555
06556
06557 case IDENTIFIER_NODE:
06558 if (TREE_CODE (decl) == IDENTIFIER_NODE)
06559 dname = decl;
06560
06561 if (C_IS_RESERVED_WORD (dname))
06562 {
06563 error ("declarator-id missing; using reserved word %qD",
06564 dname);
06565 name = IDENTIFIER_POINTER (dname);
06566 }
06567 else if (!IDENTIFIER_TYPENAME_P (dname))
06568 name = IDENTIFIER_POINTER (dname);
06569 else
06570 {
06571 gcc_assert (flags == NO_SPECIAL);
06572 flags = TYPENAME_FLAG;
06573 ctor_return_type = TREE_TYPE (dname);
06574 sfk = sfk_conversion;
06575 if (is_typename_at_global_scope (dname))
06576 name = IDENTIFIER_POINTER (dname);
06577 else
06578 name = "<invalid operator>";
06579 }
06580 break;
06581
06582 case TYPE_DECL:
06583 dname = constructor_name (TREE_TYPE (decl));
06584 name = IDENTIFIER_POINTER (dname);
06585 break;
06586
06587 default:
06588 gcc_unreachable ();
06589 }
06590 break;
06591
06592 case cdk_array:
06593 case cdk_pointer:
06594 case cdk_reference:
06595 case cdk_ptrmem:
06596 break;
06597
06598 case cdk_error:
06599 break;
06600
06601 default:
06602 gcc_unreachable ();
06603 }
06604 }
06605 if (id_declarator->kind == cdk_id)
06606 break;
06607 }
06608
06609
06610
06611
06612 if (funcdef_flag && innermost_code != cdk_function)
06613 return 0;
06614
06615 if (((dname && IDENTIFIER_OPNAME_P (dname)) || flags == TYPENAME_FLAG)
06616 && innermost_code != cdk_function
06617 && ! (ctype && !declspecs->any_specifiers_p))
06618 {
06619 error ("declaration of %qD as non-function", dname);
06620 return error_mark_node;
06621 }
06622
06623
06624
06625
06626
06627
06628
06629
06630
06631
06632
06633
06634
06635
06636
06637 if (decl_context == NORMAL && !toplevel_bindings_p ())
06638 {
06639 struct cp_binding_level *b = current_binding_level;
06640 current_binding_level = b->level_chain;
06641 if (current_binding_level != 0 && toplevel_bindings_p ())
06642 decl_context = PARM;
06643 current_binding_level = b;
06644 }
06645
06646 if (name == NULL)
06647 name = decl_context == PARM ? "parameter" : "type name";
06648
06649
06650
06651 if (declspecs->multiple_types_p)
06652 error ("two or more data types in declaration of %qs", name);
06653
06654 type = declspecs->type;
06655 if (type == error_mark_node)
06656 {
06657 type = NULL_TREE;
06658 type_was_error_mark_node = true;
06659 }
06660
06661
06662 if (type && TREE_DEPRECATED (type)
06663 && deprecated_state != DEPRECATED_SUPPRESS)
06664 warn_deprecated_use (type);
06665 if (type && TREE_CODE (type) == TYPE_DECL)
06666 {
06667 typedef_decl = type;
06668 type = TREE_TYPE (typedef_decl);
06669 }
06670
06671
06672 if (type == NULL_TREE && (signed_p || unsigned_p || long_p || short_p))
06673 {
06674
06675 type = integer_type_node;
06676 defaulted_int = 1;
06677 }
06678
06679 explicit_int = declspecs->explicit_int_p;
06680 explicit_char = declspecs->explicit_char_p;
06681
06682
06683 for (ds = ds_first; ds != ds_last; ++ds)
06684 {
06685 unsigned count = declspecs->specs[(int)ds];
06686 if (count < 2)
06687 continue;
06688
06689
06690 if (ds == ds_long)
06691 {
06692 if (count > 2)
06693 error ("%<long long long%> is too long for GCC");
06694 else if (pedantic && !in_system_header && warn_long_long)
06695 pedwarn ("ISO C++ does not support %<long long%>");
06696 else
06697 longlong = 1;
06698 }
06699 else if (declspecs->specs[(int)ds] > 1)
06700 {
06701 static const char *const decl_spec_names[] = {
06702 "signed",
06703 "unsigned",
06704 "short",
06705 "long",
06706 "const",
06707 "volatile",
06708 "restrict",
06709 "inline",
06710 "virtual",
06711 "explicit",
06712 "friend",
06713 "typedef",
06714 "__complex",
06715 "__thread"
06716 };
06717 error ("duplicate %qs", decl_spec_names[(int)ds]);
06718 }
06719 }
06720
06721 #if 0
06722
06723 if (typedef_decl)
06724 decl_attr = DECL_ATTRIBUTES (typedef_decl);
06725 #endif
06726 typedef_type = type;
06727
06728
06729 if (sfk != sfk_conversion)
06730 ctor_return_type = ctype;
06731
06732 if (sfk != sfk_none)
06733 type = check_special_function_return_type (sfk, type,
06734 ctor_return_type);
06735 else if (type == NULL_TREE)
06736 {
06737 int is_main;
06738
06739 explicit_int = -1;
06740
06741
06742
06743
06744 is_main = (funcdef_flag
06745 && dname && MAIN_NAME_P (dname)
06746 && ctype == NULL_TREE
06747 && in_namespace == NULL_TREE
06748 && current_namespace == global_namespace);
06749
06750 if (type_was_error_mark_node)
06751 ;
06752 else if (in_system_header || flag_ms_extensions)
06753 ;
06754 else if (pedantic || ! is_main)
06755 pedwarn ("ISO C++ forbids declaration of %qs with no type", name);
06756 else if (warn_return_type)
06757 warning ("ISO C++ forbids declaration of %qs with no type", name);
06758
06759 type = integer_type_node;
06760 }
06761
06762 ctype = NULL_TREE;
06763
06764
06765
06766
06767
06768 if (long_p && TYPE_MAIN_VARIANT (type) == double_type_node)
06769 {
06770 long_p = false;
06771 type = build_qualified_type (long_double_type_node,
06772 cp_type_quals (type));
06773 }
06774
06775
06776
06777 if (unsigned_p || signed_p || long_p || short_p)
06778 {
06779 int ok = 0;
06780
06781 if (TREE_CODE (type) == REAL_TYPE)
06782 error ("short, signed or unsigned invalid for %qs", name);
06783 else if (TREE_CODE (type) != INTEGER_TYPE)
06784 error ("long, short, signed or unsigned invalid for %qs", name);
06785 else if (long_p && short_p)
06786 error ("long and short specified together for %qs", name);
06787 else if ((long_p || short_p) && explicit_char)
06788 error ("long or short specified with char for %qs", name);
06789 else if ((long_p|| short_p) && TREE_CODE (type) == REAL_TYPE)
06790 error ("long or short specified with floating type for %qs", name);
06791 else if (signed_p && unsigned_p)
06792 error ("signed and unsigned given together for %qs", name);
06793 else
06794 {
06795 ok = 1;
06796 if (!explicit_int && !defaulted_int && !explicit_char && pedantic)
06797 {
06798 pedwarn ("long, short, signed or unsigned used invalidly for %qs",
06799 name);
06800 if (flag_pedantic_errors)
06801 ok = 0;
06802 }
06803 }
06804
06805
06806 if (! ok)
06807 {
06808 unsigned_p = false;
06809 signed_p = false;
06810 long_p = false;
06811 short_p = false;
06812 longlong = 0;
06813 }
06814 }
06815
06816
06817
06818 if (unsigned_p
06819
06820
06821
06822
06823
06824
06825
06826
06827 || (bitfield && !flag_signed_bitfields
06828 && !signed_p
06829
06830
06831
06832 && !(typedef_decl
06833 && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))
06834 && (TREE_CODE (type) == INTEGER_TYPE
06835 || TREE_CODE (type) == CHAR_TYPE)
06836 && !same_type_p (TYPE_MAIN_VARIANT (type), wchar_type_node)))
06837 {
06838 if (longlong)
06839 {
06840 #ifdef TARG_SL
06841 if (Long_Long_Support == TRUE)
06842 {
06843 type = long_long_unsigned_type_node;
06844 }
06845 else
06846 {
06847 warning("\"unsigned long long\" is mapped to \"unsinged long\" in declaration %s, "
06848 "Please use \"-mlong-long\" option to enbale long long type supporting", name);
06849 type = long_unsigned_type_node;
06850 }
06851 #else
06852 type = long_long_unsigned_type_node;
06853 #endif
06854 }
06855 else if (long_p)
06856 type = long_unsigned_type_node;
06857 else if (short_p)
06858 type = short_unsigned_type_node;
06859 else if (type == char_type_node)
06860 type = unsigned_char_type_node;
06861 else if (typedef_decl)
06862 type = c_common_unsigned_type (type);
06863 else
06864 type = unsigned_type_node;
06865 }
06866 else if (signed_p && type == char_type_node)
06867 type = signed_char_type_node;
06868 else if (longlong)
06869 {
06870 #ifdef TARG_SL
06871 if (Long_Long_Support == TRUE)
06872 {
06873 type = long_long_integer_type_node;
06874 }
06875 else
06876 {
06877 warning("\"long long\" is mapped to \"long\" in declaration %s, "
06878 "Please use \"-mlong-long\" option to enbale long long type supporting", name);
06879 type = long_integer_type_node;
06880 }
06881 #else
06882 type = long_long_integer_type_node;
06883 #endif
06884 }
06885 else if (long_p)
06886 type = long_integer_type_node;
06887 else if (short_p)
06888 type = short_integer_type_node;
06889
06890 if (declspecs->specs[(int)ds_complex])
06891 {
06892 #ifdef TARG_SL
06893 error("Unsupported type: \"complex\"");
06894 #endif
06895 if (TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
06896 error ("complex invalid for %qs", name);
06897
06898
06899
06900
06901
06902 else if (defaulted_int && ! longlong
06903 && ! (long_p || short_p || signed_p || unsigned_p))
06904 type = complex_double_type_node;
06905 else if (type == integer_type_node)
06906 type = complex_integer_type_node;
06907 else if (type == float_type_node)
06908 type = complex_float_type_node;
06909 else if (type == double_type_node)
06910 type = complex_double_type_node;
06911 else if (type == long_double_type_node)
06912 type = complex_long_double_type_node;
06913 else
06914 type = build_complex_type (type);
06915 }
06916
06917 #ifdef TARG_SL
06918 if (TREE_CODE(type) == REAL_TYPE)
06919 {
06920 if (TYPE_MAIN_VARIANT(type) == double_type_node || TYPE_MAIN_VARIANT(type) == float_type_node)
06921 {
06922 if (Float_Point_Support == FALSE)
06923 {
06924 error("\"float/double\" type is not supported in default mode, "
06925 "Please use \"-msoft-float\" option to enable float point emulation");
06926 }
06927 }
06928 else
06929 {
06930 warning("Unsupported real type");
06931 }
06932 }
06933 #endif
06934
06935
06936 type_quals = TYPE_UNQUALIFIED;
06937 if (declspecs->specs[(int)ds_const])
06938 type_quals |= TYPE_QUAL_CONST;
06939 if (declspecs->specs[(int)ds_volatile])
06940 type_quals |= TYPE_QUAL_VOLATILE;
06941 if (declspecs->specs[(int)ds_restrict])
06942 type_quals |= TYPE_QUAL_RESTRICT;
06943 if (sfk == sfk_conversion && type_quals != TYPE_UNQUALIFIED)
06944 error ("qualifiers are not allowed on declaration of %<operator %T%>",
06945 ctor_return_type);
06946
06947 if (TREE_CODE (type) == FUNCTION_TYPE
06948 && type_quals != TYPE_UNQUALIFIED)
06949 {
06950
06951
06952
06953 if (pedantic)
06954 {
06955 tree bad_type = build_qualified_type (type, type_quals);
06956 pedwarn ("ignoring %qV qualifiers added to function type %qT",
06957 bad_type, type);
06958 }
06959 type_quals = TYPE_UNQUALIFIED;
06960 }
06961 type_quals |= cp_type_quals (type);
06962 type = cp_build_qualified_type_real
06963 (type, type_quals, ((typedef_decl && !DECL_ARTIFICIAL (typedef_decl)
06964 ? tf_ignore_bad_quals : 0) | tf_error | tf_warning));
06965
06966 type_quals = cp_type_quals (type);
06967
06968 staticp = 0;
06969 inlinep = !! declspecs->specs[(int)ds_inline];
06970 virtualp = !! declspecs->specs[(int)ds_virtual];
06971 explicitp = !! declspecs->specs[(int)ds_explicit];
06972
06973 storage_class = declspecs->storage_class;
06974 if (storage_class == sc_static)
06975 staticp = 1 + (decl_context == FIELD);
06976
06977 if (virtualp && staticp == 2)
06978 {
06979 error ("member %qD cannot be declared both virtual and static", dname);
06980 staticp = 0;
06981 }
06982 friendp = !! declspecs->specs[(int)ds_friend];
06983
06984 if (dependant_name && !friendp)
06985 {
06986 error ("%<%T::%D%> is not a valid declarator", ctype, dependant_name);
06987 return void_type_node;
06988 }
06989
06990
06991 if (decl_context == PARM)
06992 {
06993 if (declspecs->specs[(int)ds_typedef])
06994 error ("typedef declaration invalid in parameter declaration");
06995 else if (storage_class == sc_static
06996 || storage_class == sc_extern
06997 || thread_p)
06998 error ("storage class specifiers invalid in parameter declarations");
06999 }
07000
07001
07002 if (virtualp
07003 && (current_class_name == NULL_TREE || decl_context != FIELD))
07004 {
07005 error ("virtual outside class declaration");
07006 virtualp = 0;
07007 }
07008
07009
07010 if (staticp && decl_context == TYPENAME
07011 && declspecs->type
07012 && ANON_AGGR_TYPE_P (declspecs->type))
07013 decl_context = FIELD;
07014
07015
07016
07017 if (declspecs->multiple_storage_classes_p)
07018 {
07019 error ("multiple storage classes in declaration of %qs", name);
07020 storage_class = sc_none;
07021 }
07022 else if (thread_p
07023 && ((storage_class
07024 && storage_class != sc_extern
07025 && storage_class != sc_static)
07026 || declspecs->specs[(int)ds_typedef]))
07027 {
07028 error ("multiple storage classes in declaration of %qs", name);
07029 thread_p = false;
07030 }
07031 else if (decl_context != NORMAL
07032 && ((storage_class != sc_none
07033 && storage_class != sc_mutable)
07034 || thread_p))
07035 {
07036 if ((decl_context == PARM || decl_context == CATCHPARM)
07037 && (storage_class == sc_register
07038 || storage_class == sc_auto))
07039 ;
07040 else if (declspecs->specs[(int)ds_typedef])
07041 ;
07042 else if (decl_context == FIELD
07043
07044 && storage_class == sc_static)
07045
07046
07047 ;
07048 else
07049 {
07050 if (decl_context == FIELD)
07051 error ("storage class specified for %qs", name);
07052 else
07053 {
07054 if (decl_context == PARM || decl_context == CATCHPARM)
07055 error ("storage class specified for parameter %qs", name);
07056 else
07057 error ("storage class specified for typename");
07058 }
07059 if (storage_class == sc_register
07060 || storage_class == sc_auto
07061 || storage_class == sc_extern
07062 || thread_p)
07063 storage_class = sc_none;
07064 }
07065 }
07066 else if (storage_class == sc_extern && initialized
07067 && !funcdef_flag)
07068 {
07069 if (toplevel_bindings_p ())
07070 {
07071
07072
07073 if (!(type_quals & TYPE_QUAL_CONST))
07074 warning ("%qs initialized and declared %<extern%>", name);
07075 }
07076 else
07077 error ("%qs has both %<extern%> and initializer", name);
07078 }
07079 else if (storage_class == sc_extern && funcdef_flag
07080 && ! toplevel_bindings_p ())
07081 error ("nested function %qs declared %<extern%>", name);
07082 else if (toplevel_bindings_p ())
07083 {
07084 if (storage_class == sc_auto)
07085 error ("top-level declaration of %qs specifies %<auto%>", name);
07086 }
07087 else if (thread_p
07088 && storage_class != sc_extern
07089 && storage_class != sc_static)
07090 {
07091 error ("function-scope %qs implicitly auto and declared %<__thread%>",
07092 name);
07093 thread_p = false;
07094 }
07095
07096 if (storage_class && friendp)
07097 error ("storage class specifiers invalid in friend function declarations");
07098
07099 if (!id_declarator)
07100 unqualified_id = NULL_TREE;
07101 else
07102 {
07103 unqualified_id = id_declarator->u.id.unqualified_name;
07104 if (TREE_CODE (unqualified_id) == BASELINK)
07105 unqualified_id = BASELINK_FUNCTIONS (unqualified_id);
07106 switch (TREE_CODE (unqualified_id))
07107 {
07108 case BIT_NOT_EXPR:
07109 unqualified_id
07110 = constructor_name (TREE_OPERAND (unqualified_id, 0));
07111 break;
07112
07113 case TYPE_DECL:
07114 unqualified_id
07115 = constructor_name (TREE_TYPE (unqualified_id));
07116 break;
07117
07118 case IDENTIFIER_NODE:
07119 case TEMPLATE_ID_EXPR:
07120 break;
07121
07122 default:
07123 gcc_unreachable ();
07124 }
07125 }
07126
07127
07128
07129 for (; declarator; declarator = declarator->declarator)
07130 {
07131 const cp_declarator *inner_declarator;
07132 tree attrs;
07133
07134 if (type == error_mark_node)
07135 return error_mark_node;
07136
07137 attrs = declarator->attributes;
07138 if (attrs)
07139 {
07140 int attr_flags;
07141
07142 attr_flags = 0;
07143 if (declarator == NULL || declarator->kind == cdk_id)
07144 attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
07145 if (declarator->kind == cdk_function)
07146 attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
07147 if (declarator->kind == cdk_array)
07148 attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
07149 returned_attrs = decl_attributes (&type,
07150 chainon (returned_attrs, attrs),
07151 attr_flags);
07152 }
07153
07154 if (declarator->kind == cdk_id)
07155 break;
07156
07157 inner_declarator = declarator->declarator;
07158
07159 switch (declarator->kind)
07160 {
07161 case cdk_array:
07162 type = create_array_type_for_decl (dname, type,
07163 declarator->u.array.bounds);
07164 break;
07165
07166 case cdk_function:
07167 {
07168 tree arg_types;
07169 int funcdecl_p;
07170
07171
07172
07173
07174
07175
07176 type_quals = TYPE_UNQUALIFIED;
07177
07178
07179
07180 if (TREE_CODE (type) == FUNCTION_TYPE)
07181 {
07182 error ("%qs declared as function returning a function", name);
07183 type = integer_type_node;
07184 }
07185 if (TREE_CODE (type) == ARRAY_TYPE)
07186 {
07187 error ("%qs declared as function returning an array", name);
07188 type = integer_type_node;
07189 }
07190
07191
07192 quals = declarator->u.function.qualifiers;
07193
07194
07195 raises = declarator->u.function.exception_specification;
07196
07197
07198
07199 funcdecl_p = inner_declarator && inner_declarator->kind == cdk_id;
07200
07201 if (ctype == NULL_TREE
07202 && decl_context == FIELD
07203 && funcdecl_p
07204 && (friendp == 0 || dname == current_class_name))
07205 ctype = current_class_type;
07206
07207 if (ctype && sfk == sfk_conversion)
07208 TYPE_HAS_CONVERSION (ctype) = 1;
07209 if (ctype && (sfk == sfk_constructor
07210 || sfk == sfk_destructor))
07211 {
07212
07213
07214
07215
07216
07217 if (flags == DTOR_FLAG)
07218 {
07219
07220
07221
07222 if (staticp == 2)
07223 error ("destructor cannot be static member function");
07224 if (quals)
07225 {
07226 error ("destructors may not be cv-qualified");
07227 quals = TYPE_UNQUALIFIED;
07228 }
07229 if (decl_context == FIELD)
07230 {
07231 if (! member_function_or_else (ctype,
07232 current_class_type,
07233 flags))
07234 return void_type_node;
07235 }
07236 }
07237 else
07238 {
07239 if (explicitp == 1)
07240 explicitp = 2;
07241
07242
07243
07244
07245 if (staticp == 2)
07246 error ("constructor cannot be static member function");
07247 if (virtualp)
07248 {
07249 pedwarn ("constructors cannot be declared virtual");
07250 virtualp = 0;
07251 }
07252 if (quals)
07253 {
07254 error ("constructors may not be cv-qualified");
07255 quals = TYPE_UNQUALIFIED;
07256 }
07257 if (decl_context == FIELD)
07258 {
07259 if (! member_function_or_else (ctype,
07260 current_class_type,
07261 flags))
07262 return void_type_node;
07263 TYPE_HAS_CONSTRUCTOR (ctype) = 1;
07264 if (sfk != sfk_constructor)
07265 return NULL_TREE;
07266 }
07267 }
07268 if (decl_context == FIELD)
07269 staticp = 0;
07270 }
07271 else if (friendp)
07272 {
07273 if (initialized)
07274 error ("can't initialize friend function %qs", name);
07275 if (virtualp)
07276 {
07277
07278 error ("virtual functions cannot be friends");
07279 friendp = 0;
07280 }
07281 if (decl_context == NORMAL)
07282 error ("friend declaration not in class definition");
07283 if (current_function_decl && funcdef_flag)
07284 error ("can't define friend function %qs in a local "
07285 "class definition",
07286 name);
07287 }
07288
07289 arg_types = grokparms (declarator->u.function.parameters,
07290 &parms);
07291
07292 if (inner_declarator
07293 && inner_declarator->kind == cdk_id
07294 && inner_declarator->u.id.sfk == sfk_destructor
07295 && arg_types != void_list_node)
07296 {
07297 error ("destructors may not have parameters");
07298 arg_types = void_list_node;
07299 parms = NULL_TREE;
07300 }
07301
07302 type = build_function_type (type, arg_types);
07303 type = cp_build_qualified_type (type, quals);
07304 }
07305 break;
07306
07307 case cdk_pointer:
07308 case cdk_reference:
07309 case cdk_ptrmem:
07310
07311
07312
07313 if (TREE_CODE (type) == REFERENCE_TYPE)
07314 {
07315 error (declarator->kind == cdk_reference
07316 ? "cannot declare reference to %q#T"
07317 : "cannot declare pointer to %q#T", type);
07318 type = TREE_TYPE (type);
07319 }
07320 else if (VOID_TYPE_P (type))
07321 {
07322 if (declarator->kind == cdk_reference)
07323 error ("cannot declare reference to %q#T", type);
07324 else if (declarator->kind == cdk_ptrmem)
07325 error ("cannot declare pointer to %q#T member", type);
07326 }
07327
07328
07329
07330 type_quals = TYPE_UNQUALIFIED;
07331
07332 if (declarator->kind == cdk_ptrmem
07333 && (TREE_CODE (type) == FUNCTION_TYPE
07334 || (quals && TREE_CODE (type) == METHOD_TYPE)))
07335 {
07336 tree dummy;
07337
07338
07339
07340
07341 if (TREE_CODE (type) == FUNCTION_TYPE)
07342 quals = cp_type_quals (type);
07343
07344 dummy = build_decl (TYPE_DECL, NULL_TREE, type);
07345 grok_method_quals (declarator->u.pointer.class_type,
07346 dummy, quals);
07347 type = TREE_TYPE (dummy);
07348 quals = TYPE_UNQUALIFIED;
07349 }
07350
07351 if (declarator->kind == cdk_reference)
07352 {
07353 if (!VOID_TYPE_P (type))
07354 type = build_reference_type (type);
07355 }
07356 else if (TREE_CODE (type) == METHOD_TYPE)
07357 type = build_ptrmemfunc_type (build_pointer_type (type));
07358 else if (declarator->kind == cdk_ptrmem)
07359 {
07360
07361 if (TREE_CODE (declarator->u.pointer.class_type)
07362 == NAMESPACE_DECL)
07363 {
07364 error ("%qD is a namespace",
07365 declarator->u.pointer.class_type);
07366 type = build_pointer_type (type);
07367 }
07368 else if (declarator->u.pointer.class_type == error_mark_node)
07369
07370 type = error_mark_node;
07371 else
07372 type = build_ptrmem_type (declarator->u.pointer.class_type,
07373 type);
07374 }
07375 else
07376 type = build_pointer_type (type);
07377
07378
07379
07380
07381 if (declarator->u.pointer.qualifiers)
07382 {
07383 type
07384 = cp_build_qualified_type (type,
07385 declarator->u.pointer.qualifiers);
07386 type_quals = cp_type_quals (type);
07387 }
07388 ctype = NULL_TREE;
07389 break;
07390
07391 case cdk_error:
07392 break;
07393
07394 default:
07395 gcc_unreachable ();
07396 }
07397 }
07398
07399 if (unqualified_id && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR
07400 && TREE_CODE (type) != FUNCTION_TYPE
07401 && TREE_CODE (type) != METHOD_TYPE)
07402 {
07403 error ("template-id %qD used as a declarator",
07404 unqualified_id);
07405 unqualified_id = dname;
07406 }
07407
07408
07409
07410 if (declarator
07411 && declarator->u.id.qualifying_scope
07412 && TYPE_P (declarator->u.id.qualifying_scope))
07413 {
07414 tree t;
07415
07416 ctype = declarator->u.id.qualifying_scope;
07417 ctype = TYPE_MAIN_VARIANT (ctype);
07418 t = ctype;
07419 while (t != NULL_TREE && CLASS_TYPE_P (t))
07420 {
07421
07422
07423
07424
07425
07426
07427
07428
07429
07430
07431 if (CLASSTYPE_TEMPLATE_INFO (t)
07432 && (CLASSTYPE_TEMPLATE_INSTANTIATION (t)
07433 || uses_template_parms (CLASSTYPE_TI_ARGS (t)))
07434 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)))
07435 template_count += 1;
07436
07437 t = TYPE_MAIN_DECL (t);
07438 t = DECL_CONTEXT (t);
07439 }
07440
07441 if (ctype == current_class_type)
07442 {
07443
07444
07445
07446
07447
07448
07449 if (pedantic)
07450 pedwarn ("extra qualification %<%T::%> on member %qs ignored",
07451 ctype, name);
07452 }
07453 else if (TREE_CODE (type) == FUNCTION_TYPE)
07454 {
07455 tree sname = declarator->u.id.unqualified_name;
07456
07457 if (TREE_CODE (sname) == IDENTIFIER_NODE
07458 && NEW_DELETE_OPNAME_P (sname))
07459
07460
07461 ;
07462 else if (current_class_type == NULL_TREE || friendp)
07463 type
07464 = build_method_type_directly (ctype,
07465 TREE_TYPE (type),
07466 TYPE_ARG_TYPES (type));
07467 else
07468 {
07469 error ("cannot declare member function %<%T::%s%> within %<%T%>",
07470 ctype, name, current_class_type);
07471 return error_mark_node;
07472 }
07473 }
07474 else if (declspecs->specs[(int)ds_typedef]
07475 || COMPLETE_TYPE_P (complete_type (ctype)))
07476 {
07477
07478
07479
07480
07481
07482 if (current_class_type)
07483 {
07484 error ("cannot declare member %<%T::%s%> within %qT",
07485 ctype, name, current_class_type);
07486 return void_type_node;
07487 }
07488 }
07489 else
07490 {
07491 cxx_incomplete_type_error (NULL_TREE, ctype);
07492 return error_mark_node;
07493 }
07494 }
07495
07496 if (returned_attrs)
07497 {
07498 if (attrlist)
07499 *attrlist = chainon (returned_attrs, *attrlist);
07500 else
07501 attrlist = &returned_attrs;
07502 }
07503
07504
07505
07506
07507
07508 if (TREE_CODE (type) == ARRAY_TYPE
07509 && COMPLETE_TYPE_P (type)