OSDN Git Service

632e4f975a9d312022a4dab0917ec779703d844d
[pf3gnuchains/gcc-fork.git] / gcc / cp / decl2.c
1 /* Process declarations and variables for C compiler.
2    Copyright (C) 1988, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
3    Hacked by Michael Tiemann (tiemann@cygnus.com)
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22
23 /* Process declarations and symbol lookup for C front end.
24    Also constructs types; the standard scalar types at initialization,
25    and structure, union, array and enum types when they are declared.  */
26
27 /* ??? not all decl nodes are given the most useful possible
28    line numbers.  For example, the CONST_DECLs for enum values.  */
29
30 #include "config.h"
31 #include "system.h"
32 #include "tree.h"
33 #include "rtl.h"
34 #include "flags.h"
35 #include "cp-tree.h"
36 #include "decl.h"
37 #include "lex.h"
38 #include "output.h"
39 #include "except.h"
40 #include "expr.h"
41 #include "defaults.h"
42 #include "toplev.h"
43 #include "dwarf2out.h"
44 #include "dwarfout.h"
45
46 #if USE_CPPLIB
47 #include "cpplib.h"
48 extern cpp_reader  parse_in;
49 extern cpp_options parse_options;
50 static int cpp_initialized;
51 #endif
52
53 static tree get_sentry PROTO((tree));
54 static void mark_vtable_entries PROTO((tree));
55 static void import_export_template PROTO((tree));
56 static void grok_function_init PROTO((tree, tree));
57 static int finish_vtable_vardecl PROTO((tree, tree));
58 static int prune_vtable_vardecl PROTO((tree, tree));
59 static void finish_sigtable_vardecl PROTO((tree, tree));
60 static int is_namespace_ancestor PROTO((tree, tree));
61 static tree namespace_ancestor PROTO((tree, tree));
62 static void add_using_namespace PROTO((tree, tree, int));
63 static tree ambiguous_decl PROTO((tree, tree, tree));
64 static tree build_anon_union_vars PROTO((tree, tree*, int, int));
65
66 extern int current_class_depth;
67
68 /* A list of virtual function tables we must make sure to write out.  */
69 tree pending_vtables;
70
71 /* A list of static class variables.  This is needed, because a
72    static class variable can be declared inside the class without
73    an initializer, and then initialized, staticly, outside the class.  */
74 tree pending_statics;
75
76 /* A list of functions which were declared inline, but which we
77    may need to emit outline anyway.  */
78 static tree saved_inlines;
79
80 /* Used to help generate temporary names which are unique within
81    a function.  Reset to 0 by start_function.  */
82
83 int temp_name_counter;
84
85 /* Same, but not reset.  Local temp variables and global temp variables
86    can have the same name.  */
87 static int global_temp_name_counter;
88
89 /* Flag used when debugging spew.c */
90
91 extern int spew_debug;
92
93 /* Nonzero if we're done parsing and into end-of-file activities.  */
94
95 int at_eof;
96
97 /* Functions called along with real static constructors and destructors.  */
98
99 tree static_ctors, static_dtors;
100
101 /* The current open namespace, and ::. */
102
103 tree current_namespace;
104 tree global_namespace;
105
106 /* The stack for namespaces of current declarations. */
107
108 static tree decl_namespace_list;
109
110 \f
111 /* C (and C++) language-specific option variables.  */
112
113 /* Nonzero means allow type mismatches in conditional expressions;
114    just make their values `void'.   */
115
116 int flag_cond_mismatch;
117
118 /* Nonzero means give `double' the same size as `float'.  */
119
120 int flag_short_double;
121
122 /* Nonzero means don't recognize the keyword `asm'.  */
123
124 int flag_no_asm;
125
126 /* Nonzero means don't recognize any extension keywords.  */
127
128 int flag_no_gnu_keywords;
129
130 /* Nonzero means don't recognize the non-ANSI builtin functions.  */
131
132 int flag_no_builtin;
133
134 /* Nonzero means don't recognize the non-ANSI builtin functions.
135    -ansi sets this.  */
136
137 int flag_no_nonansi_builtin;
138
139 /* Nonzero means do some things the same way PCC does.  Only provided so
140    the compiler will link.  */
141
142 int flag_traditional;
143
144 /* Nonzero means to treat bitfields as unsigned unless they say `signed'.  */
145
146 int flag_signed_bitfields = 1;
147
148 /* Nonzero means handle `#ident' directives.  0 means ignore them.  */
149
150 int flag_no_ident;
151
152 /* Nonzero means enable obscure ANSI features and disable GNU extensions
153    that might cause ANSI-compliant code to be miscompiled.  */
154
155 int flag_ansi;
156
157 /* Nonzero means do emit exported implementations of functions even if
158    they can be inlined.  */
159
160 int flag_implement_inlines = 1;
161
162 /* Nonzero means do emit exported implementations of templates, instead of
163    multiple static copies in each file that needs a definition.  */
164
165 int flag_external_templates;
166
167 /* Nonzero means that the decision to emit or not emit the implementation of a
168    template depends on where the template is instantiated, rather than where
169    it is defined.  */
170
171 int flag_alt_external_templates;
172
173 /* Nonzero means that implicit instantiations will be emitted if needed.  */
174
175 int flag_implicit_templates = 1;
176
177 /* Nonzero means warn about implicit declarations.  */
178
179 int warn_implicit = 1;
180
181 /* Nonzero means warn about usage of long long when `-pedantic'.  */
182
183 int warn_long_long = 1;
184
185 /* Nonzero means warn when all ctors or dtors are private, and the class
186    has no friends.  */
187
188 int warn_ctor_dtor_privacy = 1;
189
190 /* True if we want to implement vtables using "thunks".
191    The default is off.  */
192
193 #ifndef DEFAULT_VTABLE_THUNKS
194 #define DEFAULT_VTABLE_THUNKS 0
195 #endif
196 int flag_vtable_thunks = DEFAULT_VTABLE_THUNKS;
197
198 /* True if we want to deal with repository information.  */
199
200 int flag_use_repository;
201
202 /* Nonzero if we want to issue diagnostics that the standard says are not
203    required.  */
204
205 int flag_optional_diags = 1;
206
207 /* Nonzero means give string constants the type `const char *'
208    to get extra warnings from them.  These warnings will be too numerous
209    to be useful, except in thoroughly ANSIfied programs.  */
210
211 int warn_write_strings;
212
213 /* Nonzero means warn about pointer casts that can drop a type qualifier
214    from the pointer target type.  */
215
216 int warn_cast_qual;
217
218 /* Nonzero means warn about sizeof(function) or addition/subtraction
219    of function pointers.  */
220
221 int warn_pointer_arith = 1;
222
223 /* Nonzero means warn for any function def without prototype decl.  */
224
225 int warn_missing_prototypes;
226
227 /* Nonzero means warn about multiple (redundant) decls for the same single
228    variable or function.  */
229
230 int warn_redundant_decls;
231
232 /* Warn if initializer is not completely bracketed.  */
233
234 int warn_missing_braces;
235
236 /* Warn about comparison of signed and unsigned values.  */
237
238 int warn_sign_compare;
239
240 /* Warn about *printf or *scanf format/argument anomalies.  */
241
242 int warn_format;
243
244 /* Warn about a subscript that has type char.  */
245
246 int warn_char_subscripts;
247
248 /* Warn if a type conversion is done that might have confusing results.  */
249
250 int warn_conversion;
251
252 /* Warn if adding () is suggested.  */
253
254 int warn_parentheses;
255
256 /* Non-zero means warn in function declared in derived class has the
257    same name as a virtual in the base class, but fails to match the
258    type signature of any virtual function in the base class.  */
259 int warn_overloaded_virtual;
260
261 /* Non-zero means warn when declaring a class that has a non virtual
262    destructor, when it really ought to have a virtual one.  */
263 int warn_nonvdtor;
264
265 /* Non-zero means warn when a function is declared extern and later inline.  */
266 int warn_extern_inline;
267
268 /* Non-zero means warn when the compiler will reorder code.  */
269 int warn_reorder;
270
271 /* Non-zero means warn when synthesis behavior differs from Cfront's.  */
272 int warn_synth;
273
274 /* Non-zero means warn when we convert a pointer to member function
275    into a pointer to (void or function).  */
276 int warn_pmf2ptr = 1;
277
278 /* Nonzero means warn about violation of some Effective C++ style rules.  */
279
280 int warn_ecpp;
281
282 /* Nonzero means warn where overload resolution chooses a promotion from
283    unsigned to signed over a conversion to an unsigned of the same size.  */
284
285 int warn_sign_promo;
286
287 /* Nonzero means warn when an old-style cast is used.  */
288
289 int warn_old_style_cast;
290
291 /* Warn about #pragma directives that are not recognised.  */      
292
293 int warn_unknown_pragmas; /* Tri state variable.  */  
294
295 /* Nonzero means warn about use of multicharacter literals.  */
296
297 int warn_multichar = 1;
298
299 /* Nonzero means `$' can be in an identifier.  */
300
301 #ifndef DOLLARS_IN_IDENTIFIERS
302 #define DOLLARS_IN_IDENTIFIERS 1
303 #endif
304 int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
305
306 /* Nonzero for -fno-strict-prototype switch: do not consider empty
307    argument prototype to mean function takes no arguments.  */
308
309 int flag_strict_prototype = 2;
310 int strict_prototype = 1;
311 int strict_prototypes_lang_c, strict_prototypes_lang_cplusplus = 1;
312
313 /* Nonzero means that labels can be used as first-class objects */
314
315 int flag_labels_ok;
316
317 /* Non-zero means to collect statistics which might be expensive
318    and to print them when we are done.  */
319 int flag_detailed_statistics;
320
321 /* C++ specific flags.  */   
322 /* Nonzero for -fall-virtual: make every member function (except
323    constructors) lay down in the virtual function table.  Calls
324    can then either go through the virtual function table or not,
325    depending.  */
326
327 int flag_all_virtual;
328
329 /* Zero means that `this' is a *const.  This gives nice behavior in the
330    2.0 world.  1 gives 1.2-compatible behavior.  2 gives Spring behavior.
331    -2 means we're constructing an object and it has fixed type.  */
332
333 int flag_this_is_variable;
334
335 /* Nonzero means memoize our member lookups.  */
336
337 int flag_memoize_lookups; int flag_save_memoized_contexts;
338
339 /* 3 means write out only virtuals function tables `defined'
340    in this implementation file.
341    2 means write out only specific virtual function tables
342    and give them (C) public access.
343    1 means write out virtual function tables and give them
344    (C) public access.
345    0 means write out virtual function tables and give them
346    (C) static access (default).
347    -1 means declare virtual function tables extern.  */
348
349 int write_virtuals;
350
351 /* Nonzero means we should attempt to elide constructors when possible.
352    FIXME: This flag is obsolete, and should be torn out along with the
353    old overloading code.  */
354
355 int flag_elide_constructors;
356
357 /* Nonzero means recognize and handle signature language constructs.  */
358
359 int flag_handle_signatures;
360
361 /* Nonzero means that member functions defined in class scope are
362    inline by default.  */
363
364 int flag_default_inline = 1;
365
366 /* Controls whether enums and ints freely convert.
367    1 means with complete freedom.
368    0 means enums can convert to ints, but not vice-versa.  */
369 int flag_int_enum_equivalence;
370
371 /* Controls whether compiler generates 'type descriptor' that give
372    run-time type information.  */
373 int flag_rtti = 1;
374
375 /* Nonzero if we wish to output cross-referencing information
376    for the GNU class browser.  */
377 extern int flag_gnu_xref;
378
379 /* Nonzero if compiler can make `reasonable' assumptions about
380    references and objects.  For example, the compiler must be
381    conservative about the following and not assume that `a' is nonnull:
382
383    obj &a = g ();
384    a.f (2);
385
386    In general, it is `reasonable' to assume that for many programs,
387    and better code can be generated in that case.  */
388
389 int flag_assume_nonnull_objects = 1;
390
391 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
392    objects.  */
393
394 int flag_huge_objects;
395
396 /* Nonzero if we want to conserve space in the .o files.  We do this
397    by putting uninitialized data and runtime initialized data into
398    .common instead of .data at the expense of not flagging multiple
399    definitions.  */
400
401 int flag_conserve_space;
402
403 /* Nonzero if we want to obey access control semantics.  */
404
405 int flag_access_control = 1;
406
407 /* Nonzero if we want to understand the operator names, i.e. 'bitand'.  */
408
409 int flag_operator_names;
410
411 /* Nonzero if we want to check the return value of new and avoid calling
412    constructors if it is a null pointer.  */
413
414 int flag_check_new;
415
416 /* Nonzero if we want the new ANSI rules for pushing a new scope for `for'
417    initialization variables.
418    0: Old rules, set by -fno-for-scope.
419    2: New ANSI rules, set by -ffor-scope.
420    1: Try to implement new ANSI rules, but with backup compatibility
421    (and warnings).  This is the default, for now.  */
422
423 int flag_new_for_scope = 1;
424
425 /* Nonzero if we want to emit defined symbols with common-like linkage as
426    weak symbols where possible, in order to conform to C++ semantics.
427    Otherwise, emit them as local symbols.  */
428
429 int flag_weak = 1;
430
431 /* Nonzero to enable experimental ABI changes.  */
432
433 int flag_new_abi;
434
435 /* Nonzero to not ignore namespace std. */
436
437 int flag_honor_std;
438
439 /* Maximum template instantiation depth. Must be at least 17 for ANSI
440    compliance. */
441
442 int max_tinst_depth = 17;
443
444 /* The name-mangling scheme to use.  Must be 1 or greater to support
445    template functions with identical types, but different template
446    arguments.  */
447 int name_mangling_version = 2;
448
449 /* Nonzero means that guiding declarations are allowed.  */
450 int flag_guiding_decls;
451
452 /* Nonzero if squashed mangling is to be performed. 
453    This uses the B and K codes to reference previously seen class types 
454    and class qualifiers.       */
455 int flag_do_squangling;
456
457
458 /* Table of language-dependent -f options.
459    STRING is the option name.  VARIABLE is the address of the variable.
460    ON_VALUE is the value to store in VARIABLE
461     if `-fSTRING' is seen as an option.
462    (If `-fno-STRING' is seen as an option, the opposite value is stored.)  */
463
464 static struct { char *string; int *variable; int on_value;} lang_f_options[] =
465 {
466   {"signed-char", &flag_signed_char, 1},
467   {"unsigned-char", &flag_signed_char, 0},
468   {"signed-bitfields", &flag_signed_bitfields, 1},
469   {"unsigned-bitfields", &flag_signed_bitfields, 0},
470   {"short-enums", &flag_short_enums, 1},
471   {"short-double", &flag_short_double, 1},
472   {"cond-mismatch", &flag_cond_mismatch, 1},
473   {"squangle", &flag_do_squangling, 1},
474   {"asm", &flag_no_asm, 0},
475   {"builtin", &flag_no_builtin, 0},
476   {"ident", &flag_no_ident, 0},
477   {"labels-ok", &flag_labels_ok, 1},
478   {"stats", &flag_detailed_statistics, 1},
479   {"this-is-variable", &flag_this_is_variable, 1},
480   {"strict-prototype", &flag_strict_prototype, 1},
481   {"all-virtual", &flag_all_virtual, 1},
482   {"memoize-lookups", &flag_memoize_lookups, 1},
483   {"elide-constructors", &flag_elide_constructors, 1},
484   {"handle-exceptions", &flag_exceptions, 1},
485   {"handle-signatures", &flag_handle_signatures, 1},
486   {"default-inline", &flag_default_inline, 1},
487   {"dollars-in-identifiers", &dollars_in_ident, 1},
488   {"enum-int-equiv", &flag_int_enum_equivalence, 1},
489   {"honor-std", &flag_honor_std, 1},
490   {"rtti", &flag_rtti, 1},
491   {"xref", &flag_gnu_xref, 1},
492   {"nonnull-objects", &flag_assume_nonnull_objects, 1},
493   {"implement-inlines", &flag_implement_inlines, 1},
494   {"external-templates", &flag_external_templates, 1},
495   {"implicit-templates", &flag_implicit_templates, 1},
496   {"huge-objects", &flag_huge_objects, 1},
497   {"conserve-space", &flag_conserve_space, 1},
498   {"vtable-thunks", &flag_vtable_thunks, 1},
499   {"access-control", &flag_access_control, 1},
500   {"nonansi-builtins", &flag_no_nonansi_builtin, 0},
501   {"gnu-keywords", &flag_no_gnu_keywords, 0},
502   {"operator-names", &flag_operator_names, 1},
503   {"optional-diags", &flag_optional_diags, 1},
504   {"check-new", &flag_check_new, 1},
505   {"repo", &flag_use_repository, 1},
506   {"for-scope", &flag_new_for_scope, 2},
507   {"weak", &flag_weak, 1}
508 };
509
510 /* Decode the string P as a language-specific option.
511    Return the number of strings consumed for a valid option.
512    Otherwise return 0.  */
513
514 int   
515 lang_decode_option (argc, argv)
516      int argc;
517      char **argv;
518
519 {
520   int strings_processed;
521   char *p = argv[0];
522 #if USE_CPPLIB
523   if (! cpp_initialized)
524     {
525       cpp_reader_init (&parse_in);
526       parse_in.data = &parse_options;
527       cpp_options_init (&parse_options);
528       cpp_initialized = 1;
529     }
530   strings_processed = cpp_handle_option (&parse_in, argc, argv);
531 #else
532   strings_processed = 0;
533 #endif /* ! USE_CPPLIB */
534
535   if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))
536     flag_writable_strings = 1,
537     flag_this_is_variable = 1, flag_new_for_scope = 0;
538   /* The +e options are for cfront compatibility.  They come in as
539      `-+eN', to kludge around gcc.c's argument handling.  */
540   else if (p[0] == '-' && p[1] == '+' && p[2] == 'e')
541     {
542       int old_write_virtuals = write_virtuals;
543       if (p[3] == '1')
544         write_virtuals = 1;
545       else if (p[3] == '0')
546         write_virtuals = -1;
547       else if (p[3] == '2')
548         write_virtuals = 2;
549       else error ("invalid +e option");
550       if (old_write_virtuals != 0
551           && write_virtuals != old_write_virtuals)
552         error ("conflicting +e options given");
553     }
554   else if (p[0] == '-' && p[1] == 'f')
555     {
556       /* Some kind of -f option.
557          P's value is the option sans `-f'.
558          Search for it in the table of options.  */
559       int found = 0;
560       size_t j;
561
562       p += 2;
563       /* Try special -f options.  */
564
565       if (!strcmp (p, "handle-exceptions")
566           || !strcmp (p, "no-handle-exceptions"))
567         warning ("-fhandle-exceptions has been renamed to -fexceptions (and is now on by default)");
568
569       if (!strcmp (p, "save-memoized"))
570         {
571           flag_memoize_lookups = 1;
572           flag_save_memoized_contexts = 1;
573           found = 1;
574         }
575       else if (!strcmp (p, "no-save-memoized"))
576         {
577           flag_memoize_lookups = 0;
578           flag_save_memoized_contexts = 0;
579           found = 1;
580         }
581       else if (! strcmp (p, "alt-external-templates"))
582         {
583           flag_external_templates = 1;
584           flag_alt_external_templates = 1;
585           found = 1;
586         }
587       else if (! strcmp (p, "no-alt-external-templates"))
588         {
589           flag_alt_external_templates = 0;
590           found = 1;
591         }
592       else if (!strcmp (p, "repo"))
593         {
594           flag_use_repository = 1;
595           flag_implicit_templates = 0;
596           found = 1;
597         }
598       else if (!strcmp (p, "guiding-decls"))
599         {
600           flag_guiding_decls = 1;
601           name_mangling_version = 0;
602           found = 1;
603         }
604       else if (!strcmp (p, "no-guiding-decls"))
605         {
606           flag_guiding_decls = 0;
607           found = 1;
608         }
609       else if (!strcmp (p, "ansi-overloading"))
610         found = 1;
611       else if (!strcmp (p, "no-ansi-overloading"))
612         {
613           error ("-fno-ansi-overloading is no longer supported");
614           found = 1;
615         }
616       else if (!strcmp (p, "new-abi"))
617         {
618           flag_new_abi = 1;
619           flag_do_squangling = 1;
620           flag_honor_std = 1;
621           flag_vtable_thunks = 1;
622         }
623       else if (!strcmp (p, "no-new-abi"))
624         {
625           flag_new_abi = 0;
626           flag_do_squangling = 0;
627           flag_honor_std = 0;
628         }
629       else if (!strncmp (p, "template-depth-", 15))
630         {
631           char *endp = p + 15;
632           while (*endp)
633             {
634               if (*endp >= '0' && *endp <= '9')
635                 endp++;
636               else
637                 {
638                   error ("Invalid option `%s'", p - 2);
639                   goto template_depth_lose;
640                 }
641             }
642           max_tinst_depth = atoi (p + 15);
643         template_depth_lose: ;
644         }
645       else if (!strncmp (p, "name-mangling-version-", 22))
646         {
647           char *endp = p + 22;
648           while (*endp)
649             {
650               if (*endp >= '0' && *endp <= '9')
651                 endp++;
652               else
653                 {
654                   error ("Invalid option `%s'", p - 2);
655                   goto mangling_version_lose;
656                 }
657             }
658           name_mangling_version = atoi (p + 22);
659         mangling_version_lose: ;
660         }
661       else for (j = 0;
662                 !found && j < sizeof (lang_f_options) / sizeof (lang_f_options[0]);
663                 j++)
664         {
665           if (!strcmp (p, lang_f_options[j].string))
666             {
667               *lang_f_options[j].variable = lang_f_options[j].on_value;
668               /* A goto here would be cleaner,
669                  but breaks the vax pcc.  */
670               found = 1;
671             }
672           if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
673               && ! strcmp (p+3, lang_f_options[j].string))
674             {
675               *lang_f_options[j].variable = ! lang_f_options[j].on_value;
676               found = 1;
677             }
678         }
679       return found;
680     }
681   else if (p[0] == '-' && p[1] == 'W')
682     {
683       int setting = 1;
684
685       /* The -W options control the warning behavior of the compiler.  */
686       p += 2;
687
688       if (p[0] == 'n' && p[1] == 'o' && p[2] == '-')
689         setting = 0, p += 3;
690
691       if (!strcmp (p, "implicit"))
692         warn_implicit = setting;
693       else if (!strcmp (p, "long-long"))
694         warn_long_long = setting;
695       else if (!strcmp (p, "return-type"))
696         warn_return_type = setting;
697       else if (!strcmp (p, "ctor-dtor-privacy"))
698         warn_ctor_dtor_privacy = setting;
699       else if (!strcmp (p, "write-strings"))
700         warn_write_strings = setting;
701       else if (!strcmp (p, "cast-qual"))
702         warn_cast_qual = setting;
703       else if (!strcmp (p, "char-subscripts"))
704         warn_char_subscripts = setting;
705       else if (!strcmp (p, "pointer-arith"))
706         warn_pointer_arith = setting;
707       else if (!strcmp (p, "missing-prototypes"))
708         warn_missing_prototypes = setting;
709       else if (!strcmp (p, "redundant-decls"))
710         warn_redundant_decls = setting;
711       else if (!strcmp (p, "missing-braces"))
712         warn_missing_braces = setting;
713       else if (!strcmp (p, "sign-compare"))
714         warn_sign_compare = setting;
715       else if (!strcmp (p, "format"))
716         warn_format = setting;
717       else if (!strcmp (p, "conversion"))
718         warn_conversion = setting;
719       else if (!strcmp (p, "parentheses"))
720         warn_parentheses = setting;
721       else if (!strcmp (p, "non-virtual-dtor"))
722         warn_nonvdtor = setting;
723       else if (!strcmp (p, "extern-inline"))
724         warn_extern_inline = setting;
725       else if (!strcmp (p, "reorder"))
726         warn_reorder = setting;
727       else if (!strcmp (p, "synth"))
728         warn_synth = setting;
729       else if (!strcmp (p, "pmf-conversions"))
730         warn_pmf2ptr = setting;
731       else if (!strcmp (p, "effc++"))
732         warn_ecpp = setting;
733       else if (!strcmp (p, "sign-promo"))
734         warn_sign_promo = setting;
735       else if (!strcmp (p, "old-style-cast"))
736         warn_old_style_cast = setting;
737       else if (!strcmp (p, "overloaded-virtual"))
738         warn_overloaded_virtual = setting;
739       else if (!strcmp (p, "multichar"))
740         warn_multichar = setting;
741       else if (!strcmp (p, "unknown-pragmas"))
742         /* Set to greater than 1, so that even unknown pragmas in
743            system headers will be warned about.  */  
744         warn_unknown_pragmas = setting * 2;
745       else if (!strcmp (p, "comment"))
746         ;                       /* cpp handles this one.  */
747       else if (!strcmp (p, "comments"))
748         ;                       /* cpp handles this one.  */
749       else if (!strcmp (p, "trigraphs"))
750         ;                       /* cpp handles this one.  */
751       else if (!strcmp (p, "import"))
752         ;                       /* cpp handles this one.  */
753       else if (!strcmp (p, "all"))
754         {
755           warn_return_type = setting;
756           warn_unused = setting;
757           warn_implicit = setting;
758           warn_ctor_dtor_privacy = setting;
759           warn_switch = setting;
760           warn_format = setting;
761           warn_parentheses = setting;
762           warn_missing_braces = setting;
763           warn_sign_compare = setting;
764           warn_extern_inline = setting;
765           warn_nonvdtor = setting;
766           warn_multichar = setting;
767           /* We save the value of warn_uninitialized, since if they put
768              -Wuninitialized on the command line, we need to generate a
769              warning about not using it without also specifying -O.  */
770           if (warn_uninitialized != 1)
771             warn_uninitialized = (setting ? 2 : 0);
772           warn_reorder = setting;
773           warn_sign_promo = setting;
774           /* Only warn about unknown pragmas that are not in system
775              headers.  */                                        
776           warn_unknown_pragmas = 1;                  
777         }
778       else return strings_processed;
779     }
780   else if (!strcmp (p, "-ansi"))
781     flag_no_nonansi_builtin = 1, flag_ansi = 1,
782     flag_no_gnu_keywords = 1, flag_operator_names = 1;
783 #ifdef SPEW_DEBUG
784   /* Undocumented, only ever used when you're invoking cc1plus by hand, since
785      it's probably safe to assume no sane person would ever want to use this
786      under normal circumstances.  */
787   else if (!strcmp (p, "-spew-debug"))
788     spew_debug = 1;
789 #endif
790   else
791     return strings_processed;
792
793   return 1;
794 }
795 \f
796 /* Incorporate `const' and `volatile' qualifiers for member functions.
797    FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
798    QUALS is a list of qualifiers.  */
799
800 tree
801 grok_method_quals (ctype, function, quals)
802      tree ctype, function, quals;
803 {
804   tree fntype = TREE_TYPE (function);
805   tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
806
807   do
808     {
809       extern tree ridpointers[];
810
811       if (TREE_VALUE (quals) == ridpointers[(int)RID_CONST])
812         {
813           if (TYPE_READONLY (ctype))
814             error ("duplicate `%s' %s",
815                    IDENTIFIER_POINTER (TREE_VALUE (quals)),
816                    (TREE_CODE (function) == FUNCTION_DECL
817                     ? "for member function" : "in type declaration"));
818           ctype = build_type_variant (ctype, 1, TYPE_VOLATILE (ctype));
819           build_pointer_type (ctype);
820         }
821       else if (TREE_VALUE (quals) == ridpointers[(int)RID_VOLATILE])
822         {
823           if (TYPE_VOLATILE (ctype))
824             error ("duplicate `%s' %s",
825                    IDENTIFIER_POINTER (TREE_VALUE (quals)),
826                    (TREE_CODE (function) == FUNCTION_DECL
827                     ? "for member function" : "in type declaration"));
828           ctype = build_type_variant (ctype, TYPE_READONLY (ctype), 1);
829           build_pointer_type (ctype);
830         }
831       else
832         my_friendly_abort (20);
833       quals = TREE_CHAIN (quals);
834     }
835   while (quals);
836   fntype = build_cplus_method_type (ctype, TREE_TYPE (fntype),
837                                     (TREE_CODE (fntype) == METHOD_TYPE
838                                      ? TREE_CHAIN (TYPE_ARG_TYPES (fntype))
839                                      : TYPE_ARG_TYPES (fntype)));
840   if (raises)
841     fntype = build_exception_variant (fntype, raises);
842
843   TREE_TYPE (function) = fntype;
844   return ctype;
845 }
846
847 /* Warn when -fexternal-templates is used and #pragma
848    interface/implementation is not used all the times it should be,
849    inform the user.  */
850
851 void
852 warn_if_unknown_interface (decl)
853      tree decl;
854 {
855   static int already_warned = 0;
856   if (already_warned++)
857     return;
858
859   if (flag_alt_external_templates)
860     {
861       struct tinst_level *til = tinst_for_decl ();
862       int sl = lineno;
863       char *sf = input_filename;
864
865       if (til)
866         {
867           lineno = til->line;
868           input_filename = til->file;
869         }
870       cp_warning ("template `%#D' instantiated in file without #pragma interface",
871                   decl);
872       lineno = sl;
873       input_filename = sf;
874     }
875   else
876     cp_warning_at ("template `%#D' defined in file without #pragma interface",
877                    decl);
878 }
879
880 /* A subroutine of the parser, to handle a component list.  */
881
882 tree
883 grok_x_components (specs, components)
884      tree specs, components;
885 {
886   register tree t, x, tcode;
887
888   /* We just got some friends.  They have been recorded elsewhere.  */
889   if (components == void_type_node)
890     return NULL_TREE;
891
892   if (components == NULL_TREE)
893     {
894       t = groktypename (build_decl_list (specs, NULL_TREE));
895
896       if (t == NULL_TREE)
897         {
898           error ("error in component specification");
899           return NULL_TREE;
900         }
901
902       switch (TREE_CODE (t))
903         {
904         case VAR_DECL:
905           /* Static anonymous unions come out as VAR_DECLs.  */
906           if (ANON_UNION_TYPE_P (TREE_TYPE (t)))
907             return t;
908
909           /* We return SPECS here, because in the parser it was ending
910              up with not doing anything to $$, which is what SPECS
911              represents.  */
912           return specs;
913           break;
914
915         case RECORD_TYPE:
916           /* This code may be needed for UNION_TYPEs as
917              well.  */
918           tcode = record_type_node;
919           if (CLASSTYPE_DECLARED_CLASS (t))
920             tcode = class_type_node;
921           else if (IS_SIGNATURE (t))
922             tcode = signature_type_node;
923
924           if (CLASSTYPE_IS_TEMPLATE (t))
925             /* In this case, the TYPE_IDENTIFIER will be something
926                like S<T>, rather than S, so to get the correct name we
927                look at the template.  */
928             x = DECL_NAME (CLASSTYPE_TI_TEMPLATE (t));
929           else
930             x = TYPE_IDENTIFIER (t);
931
932           t = xref_tag (tcode, x, NULL_TREE, 0);
933           return NULL_TREE;
934           break;
935
936         case UNION_TYPE:
937         case ENUMERAL_TYPE:
938           if (TREE_CODE (t) == UNION_TYPE)
939             tcode = union_type_node;
940           else
941             tcode = enum_type_node;
942
943           t = xref_tag (tcode, TYPE_IDENTIFIER (t), NULL_TREE, 0);
944           if (ANON_UNION_TYPE_P (t))
945             {
946               /* See also shadow_tag.  */
947
948               struct pending_inline **p;
949               tree *q;
950               x = build_lang_field_decl (FIELD_DECL, NULL_TREE, t);
951
952               /* Wipe out memory of synthesized methods */
953               TYPE_HAS_CONSTRUCTOR (t) = 0;
954               TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
955               TYPE_HAS_INIT_REF (t) = 0;
956               TYPE_HAS_CONST_INIT_REF (t) = 0;
957               TYPE_HAS_ASSIGN_REF (t) = 0;
958               TYPE_HAS_ASSIGNMENT (t) = 0;
959               TYPE_HAS_CONST_ASSIGN_REF (t) = 0;
960
961               q = &TYPE_METHODS (t);
962               while (*q)
963                 {
964                   if (DECL_ARTIFICIAL (*q))
965                     *q = TREE_CHAIN (*q);
966                   else
967                     q = &TREE_CHAIN (*q);
968                 }
969               if (TYPE_METHODS (t))
970                 error ("an anonymous union cannot have function members");
971
972               p = &pending_inlines;
973               for (; *p; *p = (*p)->next)
974                 if (DECL_CONTEXT ((*p)->fndecl) != t)
975                   break;
976             }
977           else if (TREE_CODE (t) == ENUMERAL_TYPE)
978             x = grok_enum_decls (NULL_TREE);
979           else
980             x = NULL_TREE;
981           return x;
982           break;
983
984         default:
985           if (t != void_type_node)
986             error ("empty component declaration");
987           return NULL_TREE;
988         }
989     }
990   else
991     /* There may or may not be any enum decls to grok, but
992        grok_enum_decls will just return components, if there aren't
993        any.  We used to try to figure out whether or not there were
994        any enum decls based on the type of components, but that's too
995        hard; it might be something like `enum { a } *p;'.  */
996     return grok_enum_decls (components);
997 }
998
999 /* Constructors for types with virtual baseclasses need an "in-charge" flag
1000    saying whether this constructor is responsible for initialization of
1001    virtual baseclasses or not.  All destructors also need this "in-charge"
1002    flag, which additionally determines whether or not the destructor should
1003    free the memory for the object.
1004
1005    This function adds the "in-charge" flag to member function FN if
1006    appropriate.  It is called from grokclassfn and tsubst.
1007    FN must be either a constructor or destructor.  */
1008
1009 void
1010 maybe_retrofit_in_chrg (fn)
1011      tree fn;
1012 {
1013   tree basetype, arg_types, parms, parm, fntype;
1014
1015   if (DECL_CONSTRUCTOR_P (fn)
1016       && TYPE_USES_VIRTUAL_BASECLASSES (DECL_CLASS_CONTEXT (fn))
1017       && ! DECL_CONSTRUCTOR_FOR_VBASE_P (fn))
1018     /* OK */;
1019   else if (! DECL_CONSTRUCTOR_P (fn)
1020            && TREE_CHAIN (DECL_ARGUMENTS (fn)) == NULL_TREE)
1021     /* OK */;
1022   else
1023     return;
1024
1025   if (DECL_CONSTRUCTOR_P (fn))
1026     DECL_CONSTRUCTOR_FOR_VBASE_P (fn) = 1;
1027
1028   /* First add it to DECL_ARGUMENTS...  */
1029   parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node);
1030   /* Mark the artificial `__in_chrg' parameter as "artificial".  */
1031   SET_DECL_ARTIFICIAL (parm);
1032   DECL_ARG_TYPE (parm) = integer_type_node;
1033   TREE_READONLY (parm) = 1;
1034   parms = DECL_ARGUMENTS (fn);
1035   TREE_CHAIN (parm) = TREE_CHAIN (parms);
1036   TREE_CHAIN (parms) = parm;
1037
1038   /* ...and then to TYPE_ARG_TYPES.  */
1039   arg_types = TYPE_ARG_TYPES (TREE_TYPE (fn));
1040   basetype = TREE_TYPE (TREE_VALUE (arg_types));
1041   arg_types = hash_tree_chain (integer_type_node, TREE_CHAIN (arg_types));
1042   fntype = build_cplus_method_type (basetype, TREE_TYPE (TREE_TYPE (fn)),
1043                                     arg_types);
1044   if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)))
1045     fntype = build_exception_variant (fntype,
1046                                       TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)));
1047   TREE_TYPE (fn) = fntype;
1048 }
1049
1050 /* Classes overload their constituent function names automatically.
1051    When a function name is declared in a record structure,
1052    its name is changed to it overloaded name.  Since names for
1053    constructors and destructors can conflict, we place a leading
1054    '$' for destructors.
1055
1056    CNAME is the name of the class we are grokking for.
1057
1058    FUNCTION is a FUNCTION_DECL.  It was created by `grokdeclarator'.
1059
1060    FLAGS contains bits saying what's special about today's
1061    arguments.  1 == DESTRUCTOR.  2 == OPERATOR.
1062
1063    If FUNCTION is a destructor, then we must add the `auto-delete' field
1064    as a second parameter.  There is some hair associated with the fact
1065    that we must "declare" this variable in the manner consistent with the
1066    way the rest of the arguments were declared.
1067
1068    QUALS are the qualifiers for the this pointer.  */
1069
1070 void
1071 grokclassfn (ctype, cname, function, flags, quals)
1072      tree ctype, cname, function;
1073      enum overload_flags flags;
1074      tree quals;
1075 {
1076   tree fn_name = DECL_NAME (function);
1077   tree arg_types;
1078   tree parm;
1079   tree qualtype;
1080
1081   if (fn_name == NULL_TREE)
1082     {
1083       error ("name missing for member function");
1084       fn_name = get_identifier ("<anonymous>");
1085       DECL_NAME (function) = fn_name;
1086     }
1087
1088   if (quals)
1089     qualtype = grok_method_quals (ctype, function, quals);
1090   else
1091     qualtype = ctype;
1092
1093   arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
1094   if (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
1095     {
1096       /* Must add the class instance variable up front.  */
1097       /* Right now we just make this a pointer.  But later
1098          we may wish to make it special.  */
1099       tree type = TREE_VALUE (arg_types);
1100       int constp = 1;
1101
1102       if ((flag_this_is_variable > 0)
1103           && (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function)))
1104         constp = 0;
1105
1106       parm = build_decl (PARM_DECL, this_identifier, type);
1107       /* Mark the artificial `this' parameter as "artificial".  */
1108       SET_DECL_ARTIFICIAL (parm);
1109       DECL_ARG_TYPE (parm) = type;
1110       /* We can make this a register, so long as we don't
1111          accidentally complain if someone tries to take its address.  */
1112       DECL_REGISTER (parm) = 1;
1113       if (constp)
1114         TREE_READONLY (parm) = 1;
1115       TREE_CHAIN (parm) = last_function_parms;
1116       last_function_parms = parm;
1117     }
1118
1119   DECL_ARGUMENTS (function) = last_function_parms;
1120   /* First approximations.  */
1121   DECL_CONTEXT (function) = ctype;
1122   DECL_CLASS_CONTEXT (function) = ctype;
1123
1124   if (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function))
1125     {
1126       maybe_retrofit_in_chrg (function);
1127       arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
1128     }
1129
1130   if (flags == DTOR_FLAG)
1131     {
1132       DECL_ASSEMBLER_NAME (function) = build_destructor_name (ctype);
1133       TYPE_HAS_DESTRUCTOR (ctype) = 1;
1134     }
1135   else
1136     {
1137       if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
1138         /* Only true for static member functions.  */
1139         arg_types = hash_tree_chain (build_pointer_type (qualtype),
1140                                      arg_types);
1141
1142       DECL_ASSEMBLER_NAME (function)
1143         = build_decl_overload (fn_name, arg_types,
1144                                1 + DECL_CONSTRUCTOR_P (function));
1145     }
1146 }
1147
1148 /* Work on the expr used by alignof (this is only called by the parser).  */
1149
1150 tree
1151 grok_alignof (expr)
1152      tree expr;
1153 {
1154   tree best, t;
1155   int bestalign;
1156
1157   if (processing_template_decl)
1158     return build_min (ALIGNOF_EXPR, sizetype, expr);
1159
1160   if (TREE_CODE (expr) == COMPONENT_REF
1161       && DECL_BIT_FIELD (TREE_OPERAND (expr, 1)))
1162     error ("`__alignof__' applied to a bit-field");
1163
1164   if (TREE_CODE (expr) == INDIRECT_REF)
1165     {
1166       best = t = TREE_OPERAND (expr, 0);
1167       bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
1168
1169       while (TREE_CODE (t) == NOP_EXPR
1170              && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
1171         {
1172           int thisalign;
1173           t = TREE_OPERAND (t, 0);
1174           thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
1175           if (thisalign > bestalign)
1176             best = t, bestalign = thisalign;
1177         }
1178       return c_alignof (TREE_TYPE (TREE_TYPE (best)));
1179     }
1180   else
1181     {
1182       /* ANSI says arrays and fns are converted inside comma.
1183          But we can't convert them in build_compound_expr
1184          because that would break commas in lvalues.
1185          So do the conversion here if operand was a comma.  */
1186       if (TREE_CODE (expr) == COMPOUND_EXPR
1187           && (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
1188               || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
1189         expr = default_conversion (expr);
1190       return c_alignof (TREE_TYPE (expr));
1191     }
1192 }
1193
1194 /* Create an ARRAY_REF, checking for the user doing things backwards
1195    along the way.  */
1196
1197 tree
1198 grok_array_decl (array_expr, index_exp)
1199      tree array_expr, index_exp;
1200 {
1201   tree type = TREE_TYPE (array_expr);
1202   tree p1, p2, i1, i2;
1203
1204   if (type == error_mark_node || index_exp == error_mark_node)
1205     return error_mark_node;
1206   if (processing_template_decl)
1207     return build_min (ARRAY_REF, type ? TREE_TYPE (type) : NULL_TREE,
1208                       array_expr, index_exp);
1209
1210   if (type == NULL_TREE)
1211     {
1212       /* Something has gone very wrong.  Assume we are mistakenly reducing
1213          an expression instead of a declaration.  */
1214       error ("parser may be lost: is there a '{' missing somewhere?");
1215       return NULL_TREE;
1216     }
1217
1218   if (TREE_CODE (type) == OFFSET_TYPE
1219       || TREE_CODE (type) == REFERENCE_TYPE)
1220     type = TREE_TYPE (type);
1221
1222   /* If they have an `operator[]', use that.  */
1223   if (IS_AGGR_TYPE (type) || IS_AGGR_TYPE (TREE_TYPE (index_exp)))
1224     return build_opfncall (ARRAY_REF, LOOKUP_NORMAL,
1225                            array_expr, index_exp, NULL_TREE);
1226
1227   /* Otherwise, create an ARRAY_REF for a pointer or array type.  */
1228
1229   if (TREE_CODE (type) == ARRAY_TYPE)
1230     p1 = array_expr;
1231   else
1232     p1 = build_expr_type_conversion (WANT_POINTER, array_expr, 0);
1233
1234   if (TREE_CODE (TREE_TYPE (index_exp)) == ARRAY_TYPE)
1235     p2 = index_exp;
1236   else
1237     p2 = build_expr_type_conversion (WANT_POINTER, index_exp, 0);
1238
1239   i1 = build_expr_type_conversion (WANT_INT | WANT_ENUM, array_expr, 0);
1240   i2 = build_expr_type_conversion (WANT_INT | WANT_ENUM, index_exp, 0);
1241
1242   if ((p1 && i2) && (i1 && p2))
1243     error ("ambiguous conversion for array subscript");
1244
1245   if (p1 && i2)
1246     array_expr = p1, index_exp = i2;
1247   else if (i1 && p2)
1248     array_expr = p2, index_exp = i1;
1249   else
1250     {
1251       cp_error ("invalid types `%T[%T]' for array subscript",
1252                 type, TREE_TYPE (index_exp));
1253       return error_mark_node;
1254     }
1255
1256   if (array_expr == error_mark_node || index_exp == error_mark_node)
1257     error ("ambiguous conversion for array subscript");
1258
1259   return build_array_ref (array_expr, index_exp);
1260 }
1261
1262 /* Given the cast expression EXP, checking out its validity.   Either return
1263    an error_mark_node if there was an unavoidable error, return a cast to
1264    void for trying to delete a pointer w/ the value 0, or return the
1265    call to delete.  If DOING_VEC is 1, we handle things differently
1266    for doing an array delete.  If DOING_VEC is 2, they gave us the
1267    array size as an argument to delete.
1268    Implements ARM $5.3.4.  This is called from the parser.  */
1269
1270 tree
1271 delete_sanity (exp, size, doing_vec, use_global_delete)
1272      tree exp, size;
1273      int doing_vec, use_global_delete;
1274 {
1275   tree t, type;
1276   /* For a regular vector delete (aka, no size argument) we will pass
1277      this down as a NULL_TREE into build_vec_delete.  */
1278   tree maxindex = NULL_TREE;
1279
1280   if (exp == error_mark_node)
1281     return exp;
1282
1283   if (processing_template_decl)
1284     {
1285       t = build_min (DELETE_EXPR, void_type_node, exp, size);
1286       DELETE_EXPR_USE_GLOBAL (t) = use_global_delete;
1287       DELETE_EXPR_USE_VEC (t) = doing_vec;
1288       return t;
1289     }
1290
1291   if (TREE_CODE (exp) == OFFSET_REF)
1292     exp = resolve_offset_ref (exp);
1293   exp = convert_from_reference (exp);
1294   t = stabilize_reference (exp);
1295   t = build_expr_type_conversion (WANT_POINTER, t, 1);
1296
1297   if (t == NULL_TREE || t == error_mark_node)
1298     {
1299       cp_error ("type `%#T' argument given to `delete', expected pointer",
1300                 TREE_TYPE (exp));
1301       return error_mark_node;
1302     }
1303
1304   if (doing_vec == 2)
1305     {
1306       maxindex = build_binary_op (MINUS_EXPR, size, integer_one_node, 1);
1307       pedwarn ("anachronistic use of array size in vector delete");
1308     }
1309
1310   type = TREE_TYPE (t);
1311
1312   /* As of Valley Forge, you can delete a pointer to const.  */
1313
1314   /* You can't delete functions.  */
1315   if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
1316     {
1317       error ("cannot delete a function");
1318       return error_mark_node;
1319     }
1320
1321   /* An array can't have been allocated by new, so complain.  */
1322   if (TREE_CODE (t) == ADDR_EXPR
1323       && TREE_CODE (TREE_OPERAND (t, 0)) == VAR_DECL
1324       && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == ARRAY_TYPE)
1325     cp_warning ("deleting array `%#D'", TREE_OPERAND (t, 0));
1326
1327   /* Deleting a pointer with the value zero is valid and has no effect.  */
1328   if (integer_zerop (t))
1329     return build1 (NOP_EXPR, void_type_node, t);
1330
1331   if (doing_vec)
1332     return build_vec_delete (t, maxindex, integer_one_node,
1333                              integer_two_node, use_global_delete);
1334   else
1335     {
1336       if (IS_AGGR_TYPE (TREE_TYPE (type))
1337           && TYPE_GETS_REG_DELETE (TREE_TYPE (type)))
1338         {
1339           /* Only do access checking here; we'll be calling op delete
1340              from the destructor.  */
1341           tree tmp = build_op_delete_call (DELETE_EXPR, t, size_zero_node,
1342                                            LOOKUP_NORMAL, NULL_TREE);
1343           if (tmp == error_mark_node)
1344             return error_mark_node;
1345         }
1346
1347       return build_delete (type, t, integer_three_node,
1348                            LOOKUP_NORMAL, use_global_delete);
1349     }
1350 }
1351
1352 /* Report an error if the indicated template declaration is not the
1353    sort of thing that should be a member template.  */
1354
1355 void
1356 check_member_template (tmpl)
1357      tree tmpl;
1358 {
1359   tree decl;
1360
1361   my_friendly_assert (TREE_CODE (tmpl) == TEMPLATE_DECL, 0);
1362   decl = DECL_TEMPLATE_RESULT (tmpl);
1363
1364   if (TREE_CODE (decl) == FUNCTION_DECL
1365       || (TREE_CODE (decl) == TYPE_DECL
1366           && IS_AGGR_TYPE (TREE_TYPE (decl))))
1367     {
1368       if (current_function_decl)
1369         /* 14.5.2.2 [temp.mem]
1370            
1371            A local class shall not have member templates. */
1372         cp_error ("declaration of member template `%#D' in local class",
1373                   decl);
1374       
1375       if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
1376         {
1377           /* 14.5.2.3 [temp.mem]
1378
1379              A member function template shall not be virtual.  */
1380           cp_error 
1381             ("invalid use of `virtual' in template declaration of `%#D'",
1382              decl);
1383           DECL_VIRTUAL_P (decl) = 0;
1384         }
1385
1386       /* The debug-information generating code doesn't know what to do
1387          with member templates.  */ 
1388       DECL_IGNORED_P (tmpl) = 1;
1389     } 
1390   else
1391     cp_error ("template declaration of `%#D'", decl);
1392 }
1393
1394 /* Return true iff TYPE is a valid Java parameter or return type. */
1395
1396 int
1397 acceptable_java_type (type)
1398      tree type;
1399 {
1400   if (TREE_CODE (type) == VOID_TYPE || TYPE_FOR_JAVA (type))
1401     return 1;
1402   if (TREE_CODE (type) == POINTER_TYPE)
1403     {
1404       type = TREE_TYPE (type);
1405       if (TREE_CODE (type) == RECORD_TYPE)
1406         {
1407           complete_type (type);
1408           return TYPE_FOR_JAVA (type);
1409         }
1410     }
1411   return 0;
1412 }
1413
1414 /* For a METHOD in a Java class CTYPE, return 1 if
1415    the parameter and return types are valid Java types.
1416    Otherwise, print appropriate error messages, and return 0.  */
1417
1418 int
1419 check_java_method (ctype, method)
1420      tree ctype, method;
1421 {
1422   int jerr = 0;
1423   tree arg_types = TYPE_ARG_TYPES (TREE_TYPE (method));
1424   tree ret_type = TREE_TYPE (TREE_TYPE (method));
1425   if (! acceptable_java_type (ret_type))
1426     {
1427       cp_error ("Java method '%D' has non-Java return type `%T'",
1428                 method, ret_type);
1429       jerr++;
1430     }
1431   for (; arg_types != NULL_TREE; arg_types = TREE_CHAIN (arg_types))
1432     {
1433       tree type = TREE_VALUE (arg_types);
1434       if (! acceptable_java_type (type))
1435         {
1436           cp_error ("Java method '%D' has non-Java parameter type `%T'",
1437                     method, type);
1438           jerr++;
1439         }
1440     }
1441   return jerr ? 0 : 1;
1442 }
1443
1444 /* Sanity check: report error if this function FUNCTION is not
1445    really a member of the class (CTYPE) it is supposed to belong to.
1446    CNAME is the same here as it is for grokclassfn above.  */
1447
1448 tree
1449 check_classfn (ctype, function)
1450      tree ctype, function;
1451 {
1452   tree fn_name = DECL_NAME (function);
1453   tree fndecl, fndecls;
1454   tree method_vec = CLASSTYPE_METHOD_VEC (complete_type (ctype));
1455   tree *methods = 0;
1456   tree *end = 0;
1457   tree templates = NULL_TREE;
1458
1459   if (method_vec != 0)
1460     {
1461       methods = &TREE_VEC_ELT (method_vec, 0);
1462       end = TREE_VEC_END (method_vec);
1463
1464       /* First suss out ctors and dtors.  */
1465       if (*methods && fn_name == DECL_NAME (OVL_CURRENT (*methods))
1466           && DECL_CONSTRUCTOR_P (function))
1467         goto got_it;
1468       if (*++methods && fn_name == DECL_NAME (OVL_CURRENT (*methods))
1469           && DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (function)))
1470         goto got_it;
1471
1472       while (++methods != end)
1473         {
1474           fndecl = *methods;
1475           if (fn_name == DECL_NAME (OVL_CURRENT (*methods)))
1476             {
1477             got_it:
1478               for (fndecls = *methods; fndecls != NULL_TREE;
1479                    fndecls = OVL_NEXT (fndecls))
1480                 {
1481                   fndecl = OVL_CURRENT (fndecls);
1482                   /* The DECL_ASSEMBLER_NAME for a TEMPLATE_DECL is
1483                      not mangled, so the check below does not work
1484                      correctly in that case.  */
1485                   if (TREE_CODE (function) != TEMPLATE_DECL
1486                       && TREE_CODE (fndecl) != TEMPLATE_DECL
1487                       && (DECL_ASSEMBLER_NAME (function) 
1488                           == DECL_ASSEMBLER_NAME (fndecl)))
1489                     return fndecl;
1490
1491                   /* We cannot simply call decls_match because this
1492                      doesn't work for static member functions that are 
1493                      pretending to be methods, and because the name
1494                      may have been changed by asm("new_name").  */ 
1495                   if (DECL_NAME (function) == DECL_NAME (fndecl))
1496                     {
1497                       tree p1 = TYPE_ARG_TYPES (TREE_TYPE (function));
1498                       tree p2 = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
1499
1500                       /* Get rid of the this parameter on functions that become
1501                          static.  */
1502                       if (DECL_STATIC_FUNCTION_P (fndecl)
1503                           && TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
1504                         p1 = TREE_CHAIN (p1);
1505
1506                       if (comptypes (TREE_TYPE (TREE_TYPE (function)),
1507                                      TREE_TYPE (TREE_TYPE (fndecl)), 1)
1508                           && compparms (p1, p2, 3)
1509                           && (DECL_TEMPLATE_SPECIALIZATION (function)
1510                               == DECL_TEMPLATE_SPECIALIZATION (fndecl))
1511                           && (!DECL_TEMPLATE_SPECIALIZATION (function)
1512                               || (DECL_TI_TEMPLATE (function) 
1513                                   == DECL_TI_TEMPLATE (fndecl))))
1514                         return fndecl;
1515
1516                       if (is_member_template (fndecl))
1517                         /* This function might be an instantiation
1518                            or specialization of fndecl.  */
1519                         templates = 
1520                           scratch_tree_cons (NULL_TREE, fndecl, templates);
1521                     }
1522                 }
1523               break;            /* loser */
1524             }
1525           else if (TREE_CODE (fndecl) == TEMPLATE_DECL 
1526                    && IDENTIFIER_TYPENAME_P (DECL_NAME (fndecl))
1527                    && IDENTIFIER_TYPENAME_P (fn_name))
1528             /* The method in the class is a member template
1529                conversion operator.  We are declaring another
1530                conversion operator.  It is possible that even though
1531                the names don't match, there is some specialization
1532                occurring.  */
1533             templates = 
1534               scratch_tree_cons (NULL_TREE, fndecl, templates);
1535         }
1536     }
1537
1538   if (templates)
1539     /* This function might be an instantiation or a specialization.
1540        We should verify that this is possible.  If it is, we must
1541        somehow add the new declaration to the method vector for the
1542        class.  Perhaps we should use add_method?  For now, we simply
1543        return NULL_TREE, which lets the caller know that this
1544        function is new, but we don't print an error message.  */
1545     return NULL_TREE;
1546
1547   if (methods != end)
1548     {
1549       tree fndecl = *methods;
1550       cp_error ("prototype for `%#D' does not match any in class `%T'",
1551                 function, ctype);
1552       cp_error_at ("candidate%s: %+#D", OVL_NEXT (fndecl) ? "s are" : " is",
1553                    OVL_CURRENT (fndecl));
1554       while (fndecl = OVL_NEXT (fndecl), fndecl)
1555         cp_error_at ("                %#D", OVL_CURRENT(fndecl));
1556     }
1557   else
1558     {
1559       methods = 0;
1560       cp_error ("no `%#D' member function declared in class `%T'",
1561                 function, ctype);
1562     }
1563
1564   /* If we did not find the method in the class, add it to avoid
1565      spurious errors.  */
1566   add_method (ctype, methods, function);
1567   return NULL_TREE;
1568 }
1569
1570 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
1571    of a structure component, returning a FIELD_DECL node.
1572    QUALS is a list of type qualifiers for this decl (such as for declaring
1573    const member functions).
1574
1575    This is done during the parsing of the struct declaration.
1576    The FIELD_DECL nodes are chained together and the lot of them
1577    are ultimately passed to `build_struct' to make the RECORD_TYPE node.
1578
1579    C++:
1580
1581    If class A defines that certain functions in class B are friends, then
1582    the way I have set things up, it is B who is interested in permission
1583    granted by A.  However, it is in A's context that these declarations
1584    are parsed.  By returning a void_type_node, class A does not attempt
1585    to incorporate the declarations of the friends within its structure.
1586
1587    DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
1588    CHANGES TO CODE IN `start_method'.  */
1589
1590 tree
1591 grokfield (declarator, declspecs, init, asmspec_tree, attrlist)
1592      tree declarator, declspecs, init, asmspec_tree, attrlist;
1593 {
1594   register tree value;
1595   char *asmspec = 0;
1596   int flags = LOOKUP_ONLYCONVERTING;
1597
1598   /* Convert () initializers to = initializers.  */
1599   if (init == NULL_TREE && declarator != NULL_TREE
1600       && TREE_CODE (declarator) == CALL_EXPR
1601       && TREE_OPERAND (declarator, 0)
1602       && (TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE
1603           || TREE_CODE (TREE_OPERAND (declarator, 0)) == SCOPE_REF)
1604       && parmlist_is_exprlist (TREE_OPERAND (declarator, 1)))
1605     {
1606       init = TREE_OPERAND (declarator, 1);
1607       declarator = TREE_OPERAND (declarator, 0);
1608       flags = 0;
1609     }
1610
1611   if (declspecs == NULL_TREE
1612       && TREE_CODE (declarator) == SCOPE_REF
1613       && TREE_CODE (TREE_OPERAND (declarator, 1)) == IDENTIFIER_NODE)
1614     {
1615       /* Access declaration */
1616       if (! IS_AGGR_TYPE_CODE (TREE_CODE (TREE_OPERAND (declarator, 0))))
1617         ;
1618       else if (TREE_COMPLEXITY (declarator) == current_class_depth)
1619         pop_nested_class (1);
1620       return do_class_using_decl (declarator);
1621     }
1622
1623   if (init
1624       && TREE_CODE (init) == TREE_LIST
1625       && TREE_VALUE (init) == error_mark_node
1626       && TREE_CHAIN (init) == NULL_TREE)
1627     init = NULL_TREE;
1628
1629   value = grokdeclarator (declarator, declspecs, FIELD, init != 0, NULL_TREE);
1630   if (! value)
1631     return value; /* friend or constructor went bad.  */
1632
1633   /* Pass friendly classes back.  */
1634   if (TREE_CODE (value) == VOID_TYPE)
1635     return void_type_node;
1636
1637   if (DECL_NAME (value) != NULL_TREE
1638       && IDENTIFIER_POINTER (DECL_NAME (value))[0] == '_'
1639       && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value)), "_vptr"))
1640     cp_error ("member `%D' conflicts with virtual function table field name",
1641               value);
1642
1643   /* Stash away type declarations.  */
1644   if (TREE_CODE (value) == TYPE_DECL)
1645     {
1646       DECL_NONLOCAL (value) = 1;
1647       DECL_CONTEXT (value) = current_class_type;
1648       DECL_CLASS_CONTEXT (value) = current_class_type;
1649       CLASSTYPE_LOCAL_TYPEDECLS (current_class_type) = 1;
1650
1651       /* Now that we've updated the context, we need to remangle the
1652          name for this TYPE_DECL.  */
1653       DECL_ASSEMBLER_NAME (value) = DECL_NAME (value);
1654       DECL_ASSEMBLER_NAME (value) =
1655         get_identifier (build_overload_name (TREE_TYPE (value), 1, 1));
1656
1657       pushdecl_class_level (value);
1658       return value;
1659     }
1660
1661   if (IS_SIGNATURE (current_class_type)
1662       && TREE_CODE (value) != FUNCTION_DECL)
1663     {
1664       error ("field declaration not allowed in signature");
1665       return void_type_node;
1666     }
1667
1668   if (DECL_IN_AGGR_P (value))
1669     {
1670       cp_error ("`%D' is already defined in the class %T", value,
1671                   DECL_CONTEXT (value));
1672       return void_type_node;
1673     }
1674
1675   if (asmspec_tree)
1676     asmspec = TREE_STRING_POINTER (asmspec_tree);
1677
1678   if (init)
1679     {
1680       if (IS_SIGNATURE (current_class_type)
1681           && TREE_CODE (value) == FUNCTION_DECL)
1682         {
1683           error ("function declarations cannot have initializers in signature");
1684           init = NULL_TREE;
1685         }
1686       else if (TREE_CODE (value) == FUNCTION_DECL)
1687         {
1688           grok_function_init (value, init);
1689           init = NULL_TREE;
1690         }
1691       else if (pedantic && TREE_CODE (value) != VAR_DECL)
1692         /* Already complained in grokdeclarator.  */
1693         init = NULL_TREE;
1694       else
1695         {
1696           /* We allow initializers to become parameters to base
1697              initializers.  */
1698           if (TREE_CODE (init) == TREE_LIST)
1699             {
1700               if (TREE_CHAIN (init) == NULL_TREE)
1701                 init = TREE_VALUE (init);
1702               else
1703                 init = digest_init (TREE_TYPE (value), init, (tree *)0);
1704             }
1705           
1706           if (TREE_CODE (init) == CONST_DECL)
1707             init = DECL_INITIAL (init);
1708           else if (TREE_READONLY_DECL_P (init))
1709             init = decl_constant_value (init);
1710           else if (TREE_CODE (init) == CONSTRUCTOR)
1711             init = digest_init (TREE_TYPE (value), init, (tree *)0);
1712           my_friendly_assert (TREE_PERMANENT (init), 192);
1713           if (init == error_mark_node)
1714             /* We must make this look different than `error_mark_node'
1715                because `decl_const_value' would mis-interpret it
1716                as only meaning that this VAR_DECL is defined.  */
1717             init = build1 (NOP_EXPR, TREE_TYPE (value), init);
1718           else if (processing_template_decl)
1719             ;
1720           else if (! TREE_CONSTANT (init))
1721             {
1722               /* We can allow references to things that are effectively
1723                  static, since references are initialized with the address.  */
1724               if (TREE_CODE (TREE_TYPE (value)) != REFERENCE_TYPE
1725                   || (TREE_STATIC (init) == 0
1726                       && (TREE_CODE_CLASS (TREE_CODE (init)) != 'd'
1727                           || DECL_EXTERNAL (init) == 0)))
1728                 {
1729                   error ("field initializer is not constant");
1730                   init = error_mark_node;
1731                 }
1732             }
1733         }
1734     }
1735
1736   /* The corresponding pop_obstacks is in cp_finish_decl.  */
1737   push_obstacks_nochange ();
1738
1739   if (processing_template_decl && ! current_function_decl
1740       && (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == FUNCTION_DECL))
1741     value = push_template_decl (value);
1742
1743   if (attrlist)
1744     cplus_decl_attributes (value, TREE_PURPOSE (attrlist),
1745                            TREE_VALUE (attrlist));
1746
1747   if (TREE_CODE (value) == VAR_DECL)
1748     {
1749       my_friendly_assert (TREE_PUBLIC (value), 0);
1750
1751       /* We cannot call pushdecl here, because that would
1752          fill in the value of our TREE_CHAIN.  Instead, we
1753          modify cp_finish_decl to do the right thing, namely, to
1754          put this decl out straight away.  */
1755       /* current_class_type can be NULL_TREE in case of error.  */
1756       if (asmspec == 0 && current_class_type)
1757         {
1758           TREE_PUBLIC (value) = 1;
1759           DECL_INITIAL (value) = error_mark_node;
1760           DECL_ASSEMBLER_NAME (value)
1761             = build_static_name (current_class_type, DECL_NAME (value));
1762         }
1763       if (! processing_template_decl)
1764         pending_statics = perm_tree_cons (NULL_TREE, value, pending_statics);
1765       
1766       /* Static consts need not be initialized in the class definition.  */
1767       if (init != NULL_TREE && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value)))
1768         {
1769           static int explanation = 0;
1770           
1771           error ("initializer invalid for static member with constructor");
1772           if (explanation++ == 0)
1773             error ("(you really want to initialize it separately)");
1774           init = 0;
1775         }
1776       /* Force the compiler to know when an uninitialized static
1777          const member is being used.  */
1778       if (TYPE_READONLY (value) && init == 0)
1779         TREE_USED (value) = 1;
1780       DECL_INITIAL (value) = init;
1781       DECL_IN_AGGR_P (value) = 1;
1782       DECL_CONTEXT (value) = current_class_type;
1783       DECL_CLASS_CONTEXT (value) = current_class_type;
1784
1785       cp_finish_decl (value, init, asmspec_tree, 1, flags);
1786       pushdecl_class_level (value);
1787       return value;
1788     }
1789   if (TREE_CODE (value) == FIELD_DECL)
1790     {
1791       if (asmspec)
1792         {
1793           /* This must override the asm specifier which was placed
1794              by grokclassfn.  Lay this out fresh.  */
1795           DECL_RTL (value) = NULL_RTX;
1796           DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
1797         }
1798       if (DECL_INITIAL (value) == error_mark_node)
1799         init = error_mark_node;
1800       cp_finish_decl (value, init, asmspec_tree, 1, flags);
1801       DECL_INITIAL (value) = init;
1802       DECL_IN_AGGR_P (value) = 1;
1803       return value;
1804     }
1805   if (TREE_CODE (value) == FUNCTION_DECL)
1806     {
1807       if (asmspec)
1808         {
1809           /* This must override the asm specifier which was placed
1810              by grokclassfn.  Lay this out fresh.  */
1811           DECL_RTL (value) = NULL_RTX;
1812           DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
1813         }
1814       cp_finish_decl (value, init, asmspec_tree, 1, flags);
1815
1816       /* Pass friends back this way.  */
1817       if (DECL_FRIEND_P (value))
1818         return void_type_node;
1819
1820 #if 0 /* Just because a fn is declared doesn't mean we'll try to define it.  */
1821       if (current_function_decl && ! IS_SIGNATURE (current_class_type))
1822         cp_error ("method `%#D' of local class must be defined in class body",
1823                   value);
1824 #endif
1825
1826       DECL_IN_AGGR_P (value) = 1;
1827       return value;
1828     }
1829   my_friendly_abort (21);
1830   /* NOTREACHED */
1831   return NULL_TREE;
1832 }
1833
1834 /* Like `grokfield', but for bitfields.
1835    WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node.  */
1836
1837 tree
1838 grokbitfield (declarator, declspecs, width)
1839      tree declarator, declspecs, width;
1840 {
1841   register tree value = grokdeclarator (declarator, declspecs, BITFIELD,
1842                                         0, NULL_TREE);
1843
1844   if (! value) return NULL_TREE; /* friends went bad.  */
1845
1846   /* Pass friendly classes back.  */
1847   if (TREE_CODE (value) == VOID_TYPE)
1848     return void_type_node;
1849
1850   if (TREE_CODE (value) == TYPE_DECL)
1851     {
1852       cp_error ("cannot declare `%D' to be a bitfield type", value);
1853       return NULL_TREE;
1854     }
1855
1856   if (IS_SIGNATURE (current_class_type))
1857     {
1858       error ("field declaration not allowed in signature");
1859       return void_type_node;
1860     }
1861
1862   if (DECL_IN_AGGR_P (value))
1863     {
1864       cp_error ("`%D' is already defined in the class %T", value,
1865                   DECL_CONTEXT (value));
1866       return void_type_node;
1867     }
1868
1869   GNU_xref_member (current_class_name, value);
1870
1871   if (TREE_STATIC (value))
1872     {
1873       cp_error ("static member `%D' cannot be a bitfield", value);
1874       return NULL_TREE;
1875     }
1876   cp_finish_decl (value, NULL_TREE, NULL_TREE, 0, 0);
1877
1878   if (width != error_mark_node)
1879     {
1880       constant_expression_warning (width);
1881       DECL_INITIAL (value) = width;
1882       DECL_BIT_FIELD (value) = 1;
1883     }
1884
1885   DECL_IN_AGGR_P (value) = 1;
1886   return value;
1887 }
1888
1889 tree
1890 grokoptypename (declspecs, declarator)
1891      tree declspecs, declarator;
1892 {
1893   tree t = grokdeclarator (declarator, declspecs, TYPENAME, 0, NULL_TREE);
1894   return build_typename_overload (t);
1895 }
1896
1897 /* When a function is declared with an initializer,
1898    do the right thing.  Currently, there are two possibilities:
1899
1900    class B
1901    {
1902     public:
1903      // initialization possibility #1.
1904      virtual void f () = 0;
1905      int g ();
1906    };
1907    
1908    class D1 : B
1909    {
1910     public:
1911      int d1;
1912      // error, no f ();
1913    };
1914    
1915    class D2 : B
1916    {
1917     public:
1918      int d2;
1919      void f ();
1920    };
1921    
1922    class D3 : B
1923    {
1924     public:
1925      int d3;
1926      // initialization possibility #2
1927      void f () = B::f;
1928    };
1929
1930 */
1931
1932 int
1933 copy_assignment_arg_p (parmtype, virtualp)
1934      tree parmtype;
1935      int virtualp;
1936 {
1937   if (current_class_type == NULL_TREE)
1938     return 0;
1939
1940   if (TREE_CODE (parmtype) == REFERENCE_TYPE)
1941     parmtype = TREE_TYPE (parmtype);
1942
1943   if ((TYPE_MAIN_VARIANT (parmtype) == current_class_type)
1944 #if 0
1945       /* Non-standard hack to support old Booch components.  */
1946       || (! virtualp && DERIVED_FROM_P (parmtype, current_class_type))
1947 #endif
1948       )
1949     return 1;
1950
1951   return 0;
1952 }
1953
1954 static void
1955 grok_function_init (decl, init)
1956      tree decl;
1957      tree init;
1958 {
1959   /* An initializer for a function tells how this function should
1960      be inherited.  */
1961   tree type = TREE_TYPE (decl);
1962
1963   if (TREE_CODE (type) == FUNCTION_TYPE)
1964     cp_error ("initializer specified for non-member function `%D'", decl);
1965 #if 0
1966   /* We'll check for this in finish_struct_1.  */
1967   else if (DECL_VINDEX (decl) == NULL_TREE)
1968     cp_error ("initializer specified for non-virtual method `%D'", decl);
1969 #endif
1970   else if (integer_zerop (init))
1971     {
1972 #if 0
1973       /* Mark this function as being "defined".  */
1974       DECL_INITIAL (decl) = error_mark_node;
1975       /* pure virtual destructors must be defined.  */
1976       /* pure virtual needs to be defined (as abort) only when put in 
1977          vtbl. For wellformed call, it should be itself. pr4737 */
1978       if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl)))
1979         {
1980           extern tree abort_fndecl;
1981           /* Give this node rtl from `abort'.  */
1982           DECL_RTL (decl) = DECL_RTL (abort_fndecl);
1983         }
1984 #endif
1985       DECL_ABSTRACT_VIRTUAL_P (decl) = 1;
1986       if (DECL_NAME (decl) == ansi_opname [(int) MODIFY_EXPR])
1987         {
1988           tree parmtype
1989             = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl))));
1990
1991           if (copy_assignment_arg_p (parmtype, 1))
1992             TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type) = 1;
1993         }
1994     }
1995   else
1996     cp_error ("invalid initializer for virtual method `%D'", decl);
1997 }
1998 \f
1999 void
2000 cplus_decl_attributes (decl, attributes, prefix_attributes)
2001      tree decl, attributes, prefix_attributes;
2002 {
2003   if (decl == NULL_TREE || decl == void_type_node)
2004     return;
2005
2006   if (TREE_CODE (decl) == TEMPLATE_DECL)
2007     decl = DECL_TEMPLATE_RESULT (decl);
2008
2009   decl_attributes (decl, attributes, prefix_attributes);
2010
2011   if (TREE_CODE (decl) == TYPE_DECL)
2012     SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl), TREE_TYPE (decl));
2013 }
2014 \f
2015 /* CONSTRUCTOR_NAME:
2016    Return the name for the constructor (or destructor) for the
2017    specified class.  Argument can be RECORD_TYPE, TYPE_DECL, or
2018    IDENTIFIER_NODE.  When given a template, this routine doesn't
2019    lose the specialization.  */
2020
2021 tree
2022 constructor_name_full (thing)
2023      tree thing;
2024 {
2025   if (TREE_CODE (thing) == TEMPLATE_TYPE_PARM
2026       || TREE_CODE (thing) == TEMPLATE_TEMPLATE_PARM
2027       || TREE_CODE (thing) == TYPENAME_TYPE)
2028     thing = TYPE_NAME (thing);
2029   else if (IS_AGGR_TYPE_CODE (TREE_CODE (thing)))
2030     {
2031       if (TYPE_WAS_ANONYMOUS (thing) && TYPE_HAS_CONSTRUCTOR (thing))
2032         thing = DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (thing), 0)));
2033       else
2034         thing = TYPE_NAME (thing);
2035     }
2036   if (TREE_CODE (thing) == TYPE_DECL
2037       || (TREE_CODE (thing) == TEMPLATE_DECL
2038           && TREE_CODE (DECL_TEMPLATE_RESULT (thing)) == TYPE_DECL))
2039     thing = DECL_NAME (thing);
2040   my_friendly_assert (TREE_CODE (thing) == IDENTIFIER_NODE, 197);
2041   return thing;
2042 }
2043
2044 /* CONSTRUCTOR_NAME:
2045    Return the name for the constructor (or destructor) for the
2046    specified class.  Argument can be RECORD_TYPE, TYPE_DECL, or
2047    IDENTIFIER_NODE.  When given a template, return the plain
2048    unspecialized name.  */
2049
2050 tree
2051 constructor_name (thing)
2052      tree thing;
2053 {
2054   tree t;
2055   thing = constructor_name_full (thing);
2056   t = IDENTIFIER_TEMPLATE (thing);
2057   if (!t)
2058     return thing;
2059   return t;
2060 }
2061 \f
2062 /* Cache the value of this class's main virtual function table pointer
2063    in a register variable.  This will save one indirection if a
2064    more than one virtual function call is made this function.  */
2065
2066 void
2067 setup_vtbl_ptr ()
2068 {
2069   extern tree base_init_expr;
2070
2071   if (base_init_expr == 0
2072       && DECL_CONSTRUCTOR_P (current_function_decl))
2073     {
2074       if (processing_template_decl)
2075         add_tree (build_min_nt
2076                   (CTOR_INITIALIZER,
2077                    current_member_init_list, current_base_init_list));
2078       else
2079         emit_base_init (current_class_type, 0);
2080     }
2081 }
2082
2083 /* Record the existence of an addressable inline function.  */
2084
2085 void
2086 mark_inline_for_output (decl)
2087      tree decl;
2088 {
2089   decl = DECL_MAIN_VARIANT (decl);
2090   if (DECL_SAVED_INLINE (decl))
2091     return;
2092   my_friendly_assert (TREE_PERMANENT (decl), 363);
2093   DECL_SAVED_INLINE (decl) = 1;
2094 #if 0
2095   if (DECL_PENDING_INLINE_INFO (decl) != 0
2096       && ! DECL_PENDING_INLINE_INFO (decl)->deja_vu)
2097     {
2098       struct pending_inline *t = pending_inlines;
2099       my_friendly_assert (DECL_SAVED_INSNS (decl) == 0, 198);
2100       while (t)
2101         {
2102           if (t == DECL_PENDING_INLINE_INFO (decl))
2103             break;
2104           t = t->next;
2105         }
2106       if (t == 0)
2107         {
2108           t = DECL_PENDING_INLINE_INFO (decl);
2109           t->next = pending_inlines;
2110           pending_inlines = t;
2111         }
2112       DECL_PENDING_INLINE_INFO (decl) = 0;
2113     }
2114 #endif
2115   saved_inlines = perm_tree_cons (NULL_TREE, decl, saved_inlines);
2116 }
2117
2118 void
2119 clear_temp_name ()
2120 {
2121   temp_name_counter = 0;
2122 }
2123
2124 /* Hand off a unique name which can be used for variable we don't really
2125    want to know about anyway, for example, the anonymous variables which
2126    are needed to make references work.  Declare this thing so we can use it.
2127    The variable created will be of type TYPE.
2128
2129    STATICP is nonzero if this variable should be static.  */
2130
2131 tree
2132 get_temp_name (type, staticp)
2133      tree type;
2134      int staticp;
2135 {
2136   char buf[sizeof (AUTO_TEMP_FORMAT) + 20];
2137   tree decl;
2138   int toplev = toplevel_bindings_p ();
2139
2140   push_obstacks_nochange ();
2141   if (toplev || staticp)
2142     {
2143       end_temporary_allocation ();
2144       sprintf (buf, AUTO_TEMP_FORMAT, global_temp_name_counter++);
2145       decl = pushdecl_top_level (build_decl (VAR_DECL, get_identifier (buf), type));
2146     }
2147   else
2148     {
2149       sprintf (buf, AUTO_TEMP_FORMAT, temp_name_counter++);
2150       decl = pushdecl (build_decl (VAR_DECL, get_identifier (buf), type));
2151     }
2152   TREE_USED (decl) = 1;
2153   TREE_STATIC (decl) = staticp;
2154   DECL_ARTIFICIAL (decl) = 1;
2155
2156   /* If this is a local variable, then lay out its rtl now.
2157      Otherwise, callers of this function are responsible for dealing
2158      with this variable's rtl.  */
2159   if (! toplev)
2160     {
2161       expand_decl (decl);
2162       expand_decl_init (decl);
2163     }
2164   pop_obstacks ();
2165
2166   return decl;
2167 }
2168
2169 /* Get a variable which we can use for multiple assignments.
2170    It is not entered into current_binding_level, because
2171    that breaks things when it comes time to do final cleanups
2172    (which take place "outside" the binding contour of the function).  */
2173
2174 tree
2175 get_temp_regvar (type, init)
2176      tree type, init;
2177 {
2178   tree decl;
2179
2180   decl = build_decl (VAR_DECL, NULL_TREE, type);
2181   TREE_USED (decl) = 1;
2182   DECL_REGISTER (decl) = 1;
2183   DECL_ARTIFICIAL (decl) = 1;
2184
2185   DECL_RTL (decl) = assign_temp (type, 2, 0, 1);
2186   /* We can expand these without fear, since they cannot need
2187      constructors or destructors.  */
2188   expand_expr (build_modify_expr (decl, INIT_EXPR, init),
2189                NULL_RTX, VOIDmode, 0);
2190
2191   return decl;
2192 }
2193
2194 /* Hunts through the global anonymous union ANON_DECL, building
2195    appropriate VAR_DECLs.  Stores cleanups on the list of ELEMS, and
2196    returns a VAR_DECL whose size is the same as the size of the
2197    ANON_DECL, if one is available.  */
2198
2199 tree 
2200 build_anon_union_vars (anon_decl, elems, static_p, external_p)
2201      tree anon_decl;
2202      tree* elems;
2203      int static_p;
2204      int external_p;
2205 {
2206   tree type = TREE_TYPE (anon_decl);
2207   tree main_decl = NULL_TREE;
2208   tree field;
2209
2210   for (field = TYPE_FIELDS (type); 
2211        field != NULL_TREE; 
2212        field = TREE_CHAIN (field))
2213     {
2214       tree decl;
2215       if (TREE_CODE (field) != FIELD_DECL)
2216         continue;
2217
2218       if (TREE_PRIVATE (field))
2219         cp_pedwarn_at ("private member `%#D' in anonymous union", field);
2220       else if (TREE_PROTECTED (field))
2221         cp_pedwarn_at ("protected member `%#D' in anonymous union", field);
2222
2223       if (DECL_NAME (field) == NULL_TREE
2224           && TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
2225         {
2226           decl = build_anon_union_vars (field, elems, static_p, external_p);
2227           if (!decl)
2228             continue;
2229         }
2230       else
2231         {
2232           decl = build_decl (VAR_DECL, DECL_NAME (field), TREE_TYPE (field));
2233           /* tell `pushdecl' that this is not tentative.  */
2234           DECL_INITIAL (decl) = error_mark_node;
2235           TREE_PUBLIC (decl) = 0;
2236           TREE_STATIC (decl) = static_p;
2237           DECL_EXTERNAL (decl) = external_p;
2238           decl = pushdecl (decl);
2239           DECL_INITIAL (decl) = NULL_TREE;
2240         }
2241
2242       /* Only write out one anon union element--choose the one that
2243          can hold them all.  */
2244       if (main_decl == NULL_TREE
2245           && simple_cst_equal (DECL_SIZE (decl),
2246                                DECL_SIZE (anon_decl)) == 1)
2247         main_decl = decl;
2248       else 
2249         /* ??? This causes there to be no debug info written out
2250            about this decl.  */
2251         TREE_ASM_WRITTEN (decl) = 1;
2252       
2253       if (DECL_NAME (field) == NULL_TREE
2254           && TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
2255         /* The remainder of the processing was already done in the
2256            recursive call.  */
2257         continue;
2258
2259       /* If there's a cleanup to do, it belongs in the
2260          TREE_PURPOSE of the following TREE_LIST.  */
2261       *elems = scratch_tree_cons (NULL_TREE, decl, *elems);
2262       TREE_TYPE (*elems) = type;
2263     }
2264   
2265   return main_decl;
2266 }
2267
2268 /* Finish off the processing of a UNION_TYPE structure.
2269    If there are static members, then all members are
2270    static, and must be laid out together.  If the
2271    union is an anonymous union, we arrange for that
2272    as well.  PUBLIC_P is nonzero if this union is
2273    not declared static.  */
2274
2275 void
2276 finish_anon_union (anon_union_decl)
2277      tree anon_union_decl;
2278 {
2279   tree type = TREE_TYPE (anon_union_decl);
2280   tree elems = NULL_TREE;
2281   tree main_decl;
2282   int public_p = TREE_PUBLIC (anon_union_decl);
2283   int static_p = TREE_STATIC (anon_union_decl);
2284   int external_p = DECL_EXTERNAL (anon_union_decl);
2285
2286   if (TYPE_FIELDS (type) == NULL_TREE)
2287     return;
2288
2289   if (public_p)
2290     {
2291       error ("global anonymous unions must be declared static");
2292       return;
2293     }
2294
2295   main_decl = build_anon_union_vars (anon_union_decl, &elems, 
2296                                      static_p, external_p);
2297
2298   if (static_p)
2299     {
2300       if (main_decl)
2301         {
2302           make_decl_rtl (main_decl, 0, toplevel_bindings_p ());
2303           DECL_RTL (anon_union_decl) = DECL_RTL (main_decl);
2304         }
2305       else
2306         {
2307           warning ("anonymous union with no members");
2308           return;
2309         }
2310     }
2311
2312   /* The following call assumes that there are never any cleanups
2313      for anonymous unions--a reasonable assumption.  */
2314   expand_anon_union_decl (anon_union_decl, NULL_TREE, elems);
2315 }
2316
2317 /* Finish processing a builtin type TYPE.  It's name is NAME,
2318    its fields are in the array FIELDS.  LEN is the number of elements
2319    in FIELDS minus one, or put another way, it is the maximum subscript
2320    used in FIELDS.
2321
2322    It is given the same alignment as ALIGN_TYPE.  */
2323
2324 void
2325 finish_builtin_type (type, name, fields, len, align_type)
2326      tree type;
2327      char *name;
2328      tree fields[];
2329      int len;
2330      tree align_type;
2331 {
2332   register int i;
2333
2334   TYPE_FIELDS (type) = fields[0];
2335   for (i = 0; i < len; i++)
2336     {
2337       layout_type (TREE_TYPE (fields[i]));
2338       DECL_FIELD_CONTEXT (fields[i]) = type;
2339       TREE_CHAIN (fields[i]) = fields[i+1];
2340     }
2341   DECL_FIELD_CONTEXT (fields[i]) = type;
2342   DECL_CLASS_CONTEXT (fields[i]) = type;
2343   TYPE_ALIGN (type) = TYPE_ALIGN (align_type);
2344   layout_type (type);
2345 #if 0 /* not yet, should get fixed properly later */
2346   TYPE_NAME (type) = make_type_decl (get_identifier (name), type);
2347 #else
2348   TYPE_NAME (type) = build_decl (TYPE_DECL, get_identifier (name), type);
2349 #endif
2350   TYPE_STUB_DECL (type) = TYPE_NAME (type);
2351   layout_decl (TYPE_NAME (type), 0);
2352 }
2353 \f
2354 /* Auxiliary functions to make type signatures for
2355    `operator new' and `operator delete' correspond to
2356    what compiler will be expecting.  */
2357
2358 tree
2359 coerce_new_type (type)
2360      tree type;
2361 {
2362   int e1 = 0, e2 = 0;
2363
2364   if (TREE_CODE (type) == METHOD_TYPE)
2365     type = build_function_type (TREE_TYPE (type), TREE_CHAIN (TYPE_ARG_TYPES (type)));
2366   if (TREE_TYPE (type) != ptr_type_node)
2367     e1 = 1, error ("`operator new' must return type `void *'");
2368
2369   /* Technically the type must be `size_t', but we may not know
2370      what that is.  */
2371   if (TYPE_ARG_TYPES (type) == NULL_TREE)
2372     e1 = 1, error ("`operator new' takes type `size_t' parameter");
2373   else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type))) != INTEGER_TYPE
2374            || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type))) != TYPE_PRECISION (sizetype))
2375     e2 = 1, error ("`operator new' takes type `size_t' as first parameter");
2376   if (e2)
2377     type = build_function_type (ptr_type_node, tree_cons (NULL_TREE, sizetype, TREE_CHAIN (TYPE_ARG_TYPES (type))));
2378   else if (e1)
2379     type = build_function_type (ptr_type_node, TYPE_ARG_TYPES (type));
2380   return type;
2381 }
2382
2383 tree
2384 coerce_delete_type (type)
2385      tree type;
2386 {
2387   int e1 = 0, e2 = 0;
2388 #if 0
2389   e3 = 0;
2390 #endif
2391   tree arg_types = TYPE_ARG_TYPES (type);
2392
2393   if (TREE_CODE (type) == METHOD_TYPE)
2394     {
2395       type = build_function_type (TREE_TYPE (type), TREE_CHAIN (arg_types));
2396       arg_types = TREE_CHAIN (arg_types);
2397     }
2398
2399   if (TREE_TYPE (type) != void_type_node)
2400     e1 = 1, error ("`operator delete' must return type `void'");
2401
2402   if (arg_types == NULL_TREE
2403       || TREE_VALUE (arg_types) != ptr_type_node)
2404     e2 = 1, error ("`operator delete' takes type `void *' as first parameter");
2405
2406 #if 0
2407   if (arg_types
2408       && TREE_CHAIN (arg_types)
2409       && TREE_CHAIN (arg_types) != void_list_node)
2410     {
2411       /* Again, technically this argument must be `size_t', but again
2412          we may not know what that is.  */
2413       tree t2 = TREE_VALUE (TREE_CHAIN (arg_types));
2414       if (TREE_CODE (t2) != INTEGER_TYPE
2415           || TYPE_PRECISION (t2) != TYPE_PRECISION (sizetype))
2416         e3 = 1, error ("second argument to `operator delete' must be of type `size_t'");
2417       else if (TREE_CHAIN (TREE_CHAIN (arg_types)) != void_list_node)
2418         {
2419           e3 = 1;
2420           if (TREE_CHAIN (TREE_CHAIN (arg_types)))
2421             error ("too many arguments in declaration of `operator delete'");
2422           else
2423             error ("`...' invalid in specification of `operator delete'");
2424         }
2425     }
2426
2427   if (e3)
2428     arg_types = tree_cons (NULL_TREE, ptr_type_node,
2429                            build_tree_list (NULL_TREE, sizetype));
2430   else if (e3 |= e2)
2431     {
2432       if (arg_types == NULL_TREE)
2433         arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
2434       else
2435         arg_types = tree_cons (NULL_TREE, ptr_type_node, TREE_CHAIN (arg_types));
2436     }
2437   else e3 |= e1;
2438 #endif
2439
2440   if (e2)
2441     arg_types = tree_cons (NULL_TREE, ptr_type_node,
2442                            arg_types ? TREE_CHAIN (arg_types): NULL_TREE);
2443   if (e2 || e1)
2444     type = build_function_type (void_type_node, arg_types);
2445
2446   return type;
2447 }
2448 \f
2449 extern tree abort_fndecl;
2450
2451 static void
2452 mark_vtable_entries (decl)
2453      tree decl;
2454 {
2455   tree entries = CONSTRUCTOR_ELTS (DECL_INITIAL (decl));
2456
2457   if (flag_rtti)
2458     {
2459       tree fnaddr = (flag_vtable_thunks ? TREE_VALUE (TREE_CHAIN (entries))
2460                      : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries)));
2461       tree fn = TREE_OPERAND (fnaddr, 0);
2462       TREE_ADDRESSABLE (fn) = 1;
2463       mark_used (fn);
2464     }
2465   skip_rtti_stuff (&entries);
2466
2467   for (; entries; entries = TREE_CHAIN (entries))
2468     {
2469       tree fnaddr = (flag_vtable_thunks ? TREE_VALUE (entries) 
2470                      : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries)));
2471       tree fn = TREE_OPERAND (fnaddr, 0);
2472       TREE_ADDRESSABLE (fn) = 1;
2473       if (DECL_LANG_SPECIFIC (fn) && DECL_ABSTRACT_VIRTUAL_P (fn))
2474         {
2475           TREE_OPERAND (fnaddr, 0) = fn = copy_node (fn);
2476           DECL_RTL (fn) = DECL_RTL (abort_fndecl);
2477           mark_used (abort_fndecl);
2478         }
2479       if (TREE_CODE (fn) == THUNK_DECL && DECL_EXTERNAL (fn))
2480         {
2481           DECL_EXTERNAL (fn) = 0;
2482           emit_thunk (fn);
2483         }
2484       mark_used (fn);
2485     }
2486 }
2487
2488 /* Set DECL up to have the closest approximation of "initialized common"
2489    linkage available.  */
2490
2491 void
2492 comdat_linkage (decl)
2493      tree decl;
2494 {
2495   if (flag_weak)
2496     make_decl_one_only (decl);
2497   else
2498     TREE_PUBLIC (decl) = 0;
2499
2500   if (DECL_LANG_SPECIFIC (decl))
2501     DECL_COMDAT (decl) = 1;
2502 }
2503
2504 /* For win32 we also want to put explicit instantiations in
2505    linkonce sections, so that they will be merged with implicit
2506    instantiations; otherwise we get duplicate symbol errors.  */
2507
2508 void
2509 maybe_make_one_only (decl)
2510      tree decl;
2511 {
2512   /* This is not necessary on targets that support weak symbols, because
2513      the implicit instantiations will defer to the explicit one.  */     
2514   if (! supports_one_only () || SUPPORTS_WEAK)
2515     return;
2516
2517   /* We can't set DECL_COMDAT on functions, or finish_file will think
2518      we can get away with not emitting them if they aren't used.
2519      We can't use make_decl_one_only for variables, because their
2520      DECL_INITIAL may not have been set properly yet.  */
2521
2522   if (TREE_CODE (decl) == FUNCTION_DECL)
2523     make_decl_one_only (decl);
2524   else
2525     comdat_linkage (decl);
2526 }
2527
2528 /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL,
2529    based on TYPE and other static flags.
2530
2531    Note that anything public is tagged TREE_PUBLIC, whether
2532    it's public in this file or in another one.  */
2533
2534 void
2535 import_export_vtable (decl, type, final)
2536      tree decl, type;
2537      int final;
2538 {
2539   if (DECL_INTERFACE_KNOWN (decl))
2540     return;
2541
2542   /* +e0 or +e1 */
2543   if (write_virtuals < 2 && write_virtuals != 0)
2544     {
2545       TREE_PUBLIC (decl) = 1;
2546       if (write_virtuals < 0)
2547         DECL_EXTERNAL (decl) = 1;
2548       DECL_INTERFACE_KNOWN (decl) = 1;
2549     }
2550   else if (CLASSTYPE_INTERFACE_KNOWN (type))
2551     {
2552       TREE_PUBLIC (decl) = 1;
2553       DECL_EXTERNAL (decl) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type);
2554       DECL_INTERFACE_KNOWN (decl) = 1;
2555
2556       /* For WIN32 we also want to put explicit instantiations in
2557          linkonce sections.  */
2558       if (CLASSTYPE_EXPLICIT_INSTANTIATION (type))
2559         maybe_make_one_only (decl);
2560     }
2561   else
2562     {
2563       /* We can only wait to decide if we have real non-inline virtual
2564          functions in our class, or if we come from a template.  */
2565
2566       int found = CLASSTYPE_TEMPLATE_INSTANTIATION (type);
2567
2568 #ifndef MULTIPLE_SYMBOL_SPACES
2569       if (! found && ! final)
2570         {
2571           tree method;
2572           for (method = TYPE_METHODS (type); method != NULL_TREE;
2573                method = TREE_CHAIN (method))
2574             if (DECL_VINDEX (method) != NULL_TREE
2575                 && ! DECL_THIS_INLINE (method)
2576                 && ! DECL_ABSTRACT_VIRTUAL_P (method))
2577               {
2578                 found = 1;
2579                 break;
2580               }
2581         }
2582 #endif
2583
2584       if (final || ! found)
2585         {
2586           comdat_linkage (decl);
2587           DECL_EXTERNAL (decl) = 0;
2588         }
2589       else
2590         {
2591           TREE_PUBLIC (decl) = 1;
2592           DECL_EXTERNAL (decl) = 1;
2593         }
2594     }
2595 }
2596
2597 static void
2598 import_export_template (type)
2599      tree type;
2600 {
2601   if (CLASSTYPE_IMPLICIT_INSTANTIATION (type)
2602       && ! flag_implicit_templates
2603       && CLASSTYPE_INTERFACE_UNKNOWN (type))
2604     {
2605       SET_CLASSTYPE_INTERFACE_KNOWN (type);
2606       CLASSTYPE_INTERFACE_ONLY (type) = 1;
2607       CLASSTYPE_VTABLE_NEEDS_WRITING (type) = 0;
2608     }
2609 }
2610     
2611 int
2612 finish_prevtable_vardecl (prev, vars)
2613      tree prev, vars;
2614 {
2615   tree ctype = DECL_CONTEXT (vars);
2616   import_export_template (ctype);
2617
2618 #ifndef MULTIPLE_SYMBOL_SPACES
2619   if (CLASSTYPE_INTERFACE_UNKNOWN (ctype) && TYPE_VIRTUAL_P (ctype)
2620       && ! CLASSTYPE_TEMPLATE_INSTANTIATION (ctype))
2621     {
2622       tree method;
2623       for (method = TYPE_METHODS (ctype); method != NULL_TREE;
2624            method = TREE_CHAIN (method))
2625         {
2626           if (DECL_VINDEX (method) != NULL_TREE
2627               && !DECL_THIS_INLINE (method)
2628               && !DECL_ABSTRACT_VIRTUAL_P (method))
2629             {
2630               SET_CLASSTYPE_INTERFACE_KNOWN (ctype);
2631               CLASSTYPE_VTABLE_NEEDS_WRITING (ctype)
2632                 = ! DECL_REALLY_EXTERN (method);
2633               CLASSTYPE_INTERFACE_ONLY (ctype) = DECL_REALLY_EXTERN (method);
2634               break;
2635             }
2636         }
2637     }
2638 #endif
2639
2640   import_export_vtable (vars, ctype, 1);
2641   return 1;
2642 }
2643     
2644 static int
2645 finish_vtable_vardecl (prev, vars)
2646      tree prev, vars;
2647 {
2648   if (write_virtuals >= 0
2649       && ! DECL_EXTERNAL (vars)
2650       && ((TREE_PUBLIC (vars) && ! DECL_WEAK (vars) && ! DECL_ONE_ONLY (vars))
2651           || CLASSTYPE_EXPLICIT_INSTANTIATION (DECL_CONTEXT (vars))
2652           || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars))
2653           || (hack_decl_function_context (vars) && TREE_USED (vars)))
2654       && ! TREE_ASM_WRITTEN (vars))
2655     {
2656       /* Write it out.  */
2657       mark_vtable_entries (vars);
2658       if (TREE_TYPE (DECL_INITIAL (vars)) == 0)
2659         store_init_value (vars, DECL_INITIAL (vars));
2660
2661       if (write_symbols == DWARF_DEBUG || write_symbols == DWARF2_DEBUG)
2662         {
2663           /* Mark the VAR_DECL node representing the vtable itself as a
2664              "gratuitous" one, thereby forcing dwarfout.c to ignore it.
2665              It is rather important that such things be ignored because
2666              any effort to actually generate DWARF for them will run
2667              into trouble when/if we encounter code like:
2668
2669                 #pragma interface
2670                 struct S { virtual void member (); };
2671
2672               because the artificial declaration of the vtable itself (as
2673               manufactured by the g++ front end) will say that the vtable
2674               is a static member of `S' but only *after* the debug output
2675               for the definition of `S' has already been output.  This causes
2676               grief because the DWARF entry for the definition of the vtable
2677               will try to refer back to an earlier *declaration* of the
2678               vtable as a static member of `S' and there won't be one.
2679               We might be able to arrange to have the "vtable static member"
2680               attached to the member list for `S' before the debug info for
2681               `S' get written (which would solve the problem) but that would
2682               require more intrusive changes to the g++ front end.  */
2683
2684           DECL_IGNORED_P (vars) = 1;
2685         }
2686
2687       rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2688       return 1;
2689     }
2690   else if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars)))
2691     /* We don't know what to do with this one yet.  */
2692     return 0;
2693
2694   /* We know that PREV must be non-zero here.  */
2695   TREE_CHAIN (prev) = TREE_CHAIN (vars);
2696   return 0;
2697 }
2698
2699 static int
2700 prune_vtable_vardecl (prev, vars)
2701      tree prev, vars;
2702 {
2703   /* We know that PREV must be non-zero here.  */
2704   TREE_CHAIN (prev) = TREE_CHAIN (vars);
2705   return 1;
2706 }
2707
2708 int
2709 walk_vtables (typedecl_fn, vardecl_fn)
2710      register void (*typedecl_fn) PROTO ((tree, tree));
2711      register int (*vardecl_fn) PROTO ((tree, tree));
2712 {
2713   tree prev, vars;
2714   int flag = 0;
2715
2716   for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2717     {
2718       register tree type = TREE_TYPE (vars);
2719
2720       if (TREE_CODE (vars) == VAR_DECL && DECL_VIRTUAL_P (vars))
2721         {
2722           if (vardecl_fn)
2723             flag |= (*vardecl_fn) (prev, vars);
2724
2725           if (prev && TREE_CHAIN (prev) != vars)
2726             continue;
2727         }
2728       else if (TREE_CODE (vars) == TYPE_DECL
2729                && type != error_mark_node
2730                && TYPE_LANG_SPECIFIC (type)
2731                && CLASSTYPE_VSIZE (type))
2732         {
2733           if (typedecl_fn) (*typedecl_fn) (prev, vars);
2734         }
2735
2736       prev = vars;
2737     }
2738
2739   return flag;
2740 }
2741
2742 static void
2743 finish_sigtable_vardecl (prev, vars)
2744      tree prev, vars;
2745 {
2746   /* We don't need to mark sigtable entries as addressable here as is done
2747      for vtables.  Since sigtables, unlike vtables, are always written out,
2748      that was already done in build_signature_table_constructor.  */
2749
2750   rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2751
2752   /* We know that PREV must be non-zero here.  */
2753   TREE_CHAIN (prev) = TREE_CHAIN (vars);
2754 }
2755
2756 void
2757 walk_sigtables (typedecl_fn, vardecl_fn)
2758      register void (*typedecl_fn) PROTO((tree, tree));
2759      register void (*vardecl_fn) PROTO((tree, tree));
2760 {
2761   tree prev, vars;
2762
2763   for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2764     {
2765       register tree type = TREE_TYPE (vars);
2766
2767       if (TREE_CODE (vars) == TYPE_DECL
2768           && type != error_mark_node
2769           && IS_SIGNATURE (type))
2770         {
2771           if (typedecl_fn) (*typedecl_fn) (prev, vars);
2772         }
2773       else if (TREE_CODE (vars) == VAR_DECL
2774                && TREE_TYPE (vars) != error_mark_node
2775                && IS_SIGNATURE (TREE_TYPE (vars)))
2776         {
2777           if (vardecl_fn) (*vardecl_fn) (prev, vars);
2778         }
2779       else
2780         prev = vars;
2781     }
2782 }
2783
2784 /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an
2785    inline function or template instantiation at end-of-file.  */
2786
2787 void
2788 import_export_decl (decl)
2789      tree decl;
2790 {
2791   if (DECL_INTERFACE_KNOWN (decl))
2792     return;
2793
2794   if (DECL_TEMPLATE_INSTANTIATION (decl))
2795     {
2796       DECL_NOT_REALLY_EXTERN (decl) = 1;
2797       if (DECL_IMPLICIT_INSTANTIATION (decl)
2798           && (flag_implicit_templates || DECL_THIS_INLINE (decl)))
2799         {
2800           if (!TREE_PUBLIC (decl))
2801             /* Templates are allowed to have internal linkage.  See 
2802                [basic.link].  */
2803             ;
2804           else if (TREE_CODE (decl) == FUNCTION_DECL)
2805             comdat_linkage (decl);
2806           else
2807             DECL_COMDAT (decl) = 1;
2808         }
2809       else
2810         DECL_NOT_REALLY_EXTERN (decl) = 0;
2811     }
2812   else if (DECL_FUNCTION_MEMBER_P (decl))
2813     {
2814       tree ctype = DECL_CLASS_CONTEXT (decl);
2815       if (CLASSTYPE_INTERFACE_KNOWN (ctype)
2816           && (! DECL_ARTIFICIAL (decl) || DECL_VINDEX (decl)))
2817         {
2818           DECL_NOT_REALLY_EXTERN (decl)
2819             = ! (CLASSTYPE_INTERFACE_ONLY (ctype)
2820                  || (DECL_THIS_INLINE (decl) && ! flag_implement_inlines));
2821         }
2822       else
2823         comdat_linkage (decl);
2824     }
2825   /* tinfo function */
2826   else if (DECL_ARTIFICIAL (decl) && DECL_MUTABLE_P (decl))
2827     {
2828       tree ctype = TREE_TYPE (DECL_NAME (decl));
2829       if (IS_AGGR_TYPE (ctype) && CLASSTYPE_INTERFACE_KNOWN (ctype)
2830           && TYPE_VIRTUAL_P (ctype))
2831         {
2832           /* If the type is a cv-qualified variant of a type, then we
2833              must emit the tinfo function in this translation unit
2834              since it will not be emitted when the vtable for the type
2835              is output (which is when the unqualified version is
2836              generated).  */
2837           DECL_NOT_REALLY_EXTERN (decl)
2838             = TYPE_READONLY (ctype) 
2839             || TYPE_VOLATILE (ctype)
2840             || ! (CLASSTYPE_INTERFACE_ONLY (ctype)
2841                   || (DECL_THIS_INLINE (decl) && ! flag_implement_inlines));
2842
2843           /* For WIN32 we also want to put explicit instantiations in
2844              linkonce sections.  */
2845           if (CLASSTYPE_EXPLICIT_INSTANTIATION (ctype))
2846             maybe_make_one_only (decl);
2847         }
2848       else if (TYPE_BUILT_IN (ctype) && ctype == TYPE_MAIN_VARIANT (ctype))
2849         DECL_NOT_REALLY_EXTERN (decl) = 0;
2850       else
2851         comdat_linkage (decl);
2852     } 
2853   else
2854     comdat_linkage (decl);
2855
2856   DECL_INTERFACE_KNOWN (decl) = 1;
2857 }
2858
2859 tree
2860 build_cleanup (decl)
2861      tree decl;
2862 {
2863   tree temp;
2864   tree type = TREE_TYPE (decl);
2865
2866   if (TREE_CODE (type) == ARRAY_TYPE)
2867     temp = decl;
2868   else
2869     {
2870       mark_addressable (decl);
2871       temp = build1 (ADDR_EXPR, build_pointer_type (type), decl);
2872     }
2873   temp = build_delete (TREE_TYPE (temp), temp,
2874                        integer_two_node,
2875                        LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
2876   return temp;
2877 }
2878
2879 extern int parse_time, varconst_time;
2880 extern tree pending_templates;
2881 extern tree maybe_templates;
2882
2883 static tree
2884 get_sentry (base)
2885      tree base;
2886 {
2887   tree sname = get_id_2 ("__sn", base);
2888   /* For struct X foo __attribute__((weak)), there is a counter
2889      __snfoo. Since base is already an assembler name, sname should
2890      be globally unique */
2891   tree sentry = IDENTIFIER_GLOBAL_VALUE (sname);
2892   if (! sentry)
2893     {
2894       push_obstacks_nochange ();
2895       end_temporary_allocation ();
2896       sentry = build_decl (VAR_DECL, sname, integer_type_node);
2897       TREE_PUBLIC (sentry) = 1;
2898       DECL_ARTIFICIAL (sentry) = 1;
2899       TREE_STATIC (sentry) = 1;
2900       TREE_USED (sentry) = 1;
2901       DECL_COMMON (sentry) = 1;
2902       pushdecl_top_level (sentry);
2903       cp_finish_decl (sentry, NULL_TREE, NULL_TREE, 0, 0);
2904       pop_obstacks ();
2905     }
2906   return sentry;
2907 }
2908
2909 /* Start the process of running a particular set of global constructors
2910    or destructors.  Subroutine of do_[cd]tors.  */
2911
2912 static void
2913 start_objects (method_type)
2914      int method_type;
2915 {
2916   tree fnname;
2917
2918   /* Make ctor or dtor function.  METHOD_TYPE may be 'I' or 'D'.  */
2919
2920   fnname = get_file_function_name (method_type);
2921
2922   start_function (void_list_node,
2923                   make_call_declarator (fnname, void_list_node, NULL_TREE,
2924                                         NULL_TREE),
2925                   NULL_TREE, 0);
2926
2927   store_parm_decls ();
2928   pushlevel (0);
2929   clear_last_expr ();
2930   push_momentary ();
2931   expand_start_bindings (0);
2932 }
2933
2934 /* Finish the process of running a particular set of global constructors
2935    or destructors.  Subroutine of do_[cd]tors.  */
2936
2937 static void
2938 finish_objects (method_type)
2939      int method_type;
2940 {
2941   char *fnname;
2942
2943   tree list = (method_type == 'I' ? static_ctors : static_dtors);
2944
2945   if (! current_function_decl && list)
2946     start_objects (method_type);
2947
2948   for (; list; list = TREE_CHAIN (list))
2949     expand_expr_stmt (build_function_call (TREE_VALUE (list), NULL_TREE));
2950
2951   if (! current_function_decl)
2952     return;
2953
2954   fnname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
2955
2956   /* Finish up. */
2957   expand_end_bindings (getdecls (), 1, 0);
2958   poplevel (1, 0, 0);
2959   pop_momentary ();
2960   finish_function (lineno, 0, 0);
2961
2962   if (method_type == 'I')
2963     assemble_constructor (fnname);
2964   else
2965     assemble_destructor (fnname);
2966 }
2967
2968 /* Generate a function to run a set of global destructors.  Subroutine of
2969    finish_file.  */
2970
2971 static void
2972 do_dtors ()
2973 {
2974   tree vars = static_aggregates;
2975
2976   for (; vars; vars = TREE_CHAIN (vars))
2977     {
2978       tree decl = TREE_VALUE (vars);
2979       tree type = TREE_TYPE (decl);
2980       tree temp;
2981
2982       if (TYPE_NEEDS_DESTRUCTOR (type) && ! TREE_STATIC (vars)
2983           && ! DECL_EXTERNAL (decl))
2984         {
2985           int protect = (TREE_PUBLIC (decl) && (DECL_COMMON (decl)
2986                                                 || DECL_ONE_ONLY (decl)
2987                                                 || DECL_WEAK (decl)));
2988
2989           if (! current_function_decl)
2990             start_objects ('D');
2991
2992           temp = build_cleanup (decl);
2993
2994           if (protect)
2995             {
2996               tree sentry = get_sentry (DECL_ASSEMBLER_NAME (decl));
2997               sentry = build_unary_op (PREDECREMENT_EXPR, sentry, 0);
2998               sentry = build_binary_op (EQ_EXPR, sentry, integer_zero_node, 1);
2999               expand_start_cond (sentry, 0);
3000             }
3001
3002           expand_expr_stmt (temp);
3003
3004           if (protect)
3005             expand_end_cond ();
3006         }
3007     }
3008
3009   finish_objects ('D');
3010 }
3011
3012 /* Generate a function to run a set of global constructors.  Subroutine of
3013    finish_file.  */
3014
3015 static void
3016 do_ctors ()
3017 {
3018   tree vars = static_aggregates;
3019
3020   /* Reverse the list so it's in the right order for ctors.  */
3021   vars = nreverse (vars);
3022
3023   for (; vars; vars = TREE_CHAIN (vars))
3024     {
3025       tree decl = TREE_VALUE (vars);
3026       tree init = TREE_PURPOSE (vars);
3027
3028       /* If this was a static attribute within some function's scope,
3029          then don't initialize it here.  Also, don't bother
3030          with initializers that contain errors.  */
3031       if (TREE_STATIC (vars)
3032           || DECL_EXTERNAL (decl)
3033           || (init && TREE_CODE (init) == TREE_LIST
3034               && value_member (error_mark_node, init)))
3035         continue;
3036
3037       if (TREE_CODE (decl) == VAR_DECL)
3038         {
3039           int protect = (TREE_PUBLIC (decl) && (DECL_COMMON (decl)
3040                                                 || DECL_ONE_ONLY (decl)
3041                                                 || DECL_WEAK (decl)));
3042
3043           if (! current_function_decl)
3044             start_objects ('I');
3045
3046           /* Set these global variables so that GDB at least puts
3047              us near the declaration which required the initialization.  */
3048           input_filename = DECL_SOURCE_FILE (decl);
3049           lineno = DECL_SOURCE_LINE (decl);
3050           emit_note (input_filename, lineno);
3051
3052           /* 9.5p5: The initializer of a static member of a class has
3053              the same access rights as a member function.  */
3054           if (member_p (decl))
3055             {
3056               DECL_CLASS_CONTEXT (current_function_decl)
3057                 = DECL_CONTEXT (decl);
3058               DECL_STATIC_FUNCTION_P (current_function_decl) = 1;
3059             }
3060
3061           if (protect)
3062             {
3063               tree sentry = get_sentry (DECL_ASSEMBLER_NAME (decl));
3064               sentry = build_unary_op (PREINCREMENT_EXPR, sentry, 0);
3065               sentry = build_binary_op
3066                 (EQ_EXPR, sentry, integer_one_node, 1);
3067               expand_start_cond (sentry, 0);
3068             }
3069
3070           expand_start_target_temps ();
3071
3072           if (IS_AGGR_TYPE (TREE_TYPE (decl))
3073               || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
3074             expand_aggr_init (decl, init, 0, 0);
3075           else if (TREE_CODE (init) == TREE_VEC)
3076             {
3077               expand_expr (expand_vec_init (decl, TREE_VEC_ELT (init, 0),
3078                                             TREE_VEC_ELT (init, 1),
3079                                             TREE_VEC_ELT (init, 2), 0),
3080                            const0_rtx, VOIDmode, EXPAND_NORMAL);
3081             }
3082           else
3083             expand_assignment (decl, init, 0, 0);
3084               
3085           /* The expression might have involved increments and
3086              decrements.  */
3087           emit_queue ();
3088
3089           /* Cleanup any temporaries needed for the initial value.  */
3090           expand_end_target_temps ();
3091
3092           if (protect)
3093             expand_end_cond ();
3094
3095           DECL_CLASS_CONTEXT (current_function_decl) = NULL_TREE;
3096           DECL_STATIC_FUNCTION_P (current_function_decl) = 0;
3097         }
3098       else if (decl == error_mark_node)
3099         /* OK */;
3100       else
3101         my_friendly_abort (22);
3102     }
3103
3104   finish_objects ('I');
3105 }
3106
3107 /* This routine is called from the last rule in yyparse ().
3108    Its job is to create all the code needed to initialize and
3109    destroy the global aggregates.  We do the destruction
3110    first, since that way we only need to reverse the decls once.  */
3111
3112 void
3113 finish_file ()
3114 {
3115   extern int lineno;
3116   int start_time, this_time;
3117
3118   tree fnname;
3119   tree vars;
3120   int needs_cleaning = 0, needs_messing_up = 0;
3121
3122   at_eof = 1;
3123
3124   /* Bad parse errors.  Just forget about it.  */
3125   if (! global_bindings_p () || current_class_type)
3126     return;
3127
3128   start_time = get_run_time ();
3129
3130   /* Otherwise, GDB can get confused, because in only knows
3131      about source for LINENO-1 lines.  */
3132   lineno -= 1;
3133
3134   interface_unknown = 1;
3135   interface_only = 0;
3136
3137   for (fnname = pending_templates; fnname; fnname = TREE_CHAIN (fnname))
3138     {
3139       tree srcloc = TREE_PURPOSE (fnname);
3140       tree decl = TREE_VALUE (fnname);
3141
3142       input_filename = SRCLOC_FILE (srcloc);
3143       lineno = SRCLOC_LINE (srcloc);
3144
3145       if (TREE_CODE_CLASS (TREE_CODE (decl)) == 't')
3146         {
3147           instantiate_class_template (decl);
3148           if (CLASSTYPE_TEMPLATE_INSTANTIATION (decl))
3149             for (vars = TYPE_METHODS (decl); vars; vars = TREE_CHAIN (vars))
3150               if (! DECL_ARTIFICIAL (vars))
3151                 instantiate_decl (vars);
3152         }
3153       else
3154         instantiate_decl (decl);
3155     }
3156
3157   for (fnname = maybe_templates; fnname; fnname = TREE_CHAIN (fnname))
3158     {
3159       tree args, fn, decl = TREE_VALUE (fnname);
3160
3161       if (DECL_INITIAL (decl))
3162         continue;
3163
3164       fn = TREE_PURPOSE (fnname);
3165       args = get_bindings (fn, decl, NULL_TREE);
3166       fn = instantiate_template (fn, args);
3167       instantiate_decl (fn);
3168     }
3169
3170   cat_namespace_levels();
3171
3172   /* Push into C language context, because that's all
3173      we'll need here.  */
3174   push_lang_context (lang_name_c);
3175
3176 #if 1
3177   /* The reason for pushing garbage onto the global_binding_level is to
3178      ensure that we can slice out _DECLs which pertain to virtual function
3179      tables.  If the last thing pushed onto the global_binding_level was a
3180      virtual function table, then slicing it out would slice away all the
3181      decls (i.e., we lose the head of the chain).
3182
3183      There are several ways of getting the same effect, from changing the
3184      way that iterators over the chain treat the elements that pertain to
3185      virtual function tables, moving the implementation of this code to
3186      decl.c (where we can manipulate global_binding_level directly),
3187      popping the garbage after pushing it and slicing away the vtable
3188      stuff, or just leaving it alone.  */
3189
3190   /* Make last thing in global scope not be a virtual function table.  */
3191 #if 0 /* not yet, should get fixed properly later */
3192   vars = make_type_decl (get_identifier (" @%$#@!"), integer_type_node);
3193 #else
3194   vars = build_decl (TYPE_DECL, get_identifier (" @%$#@!"), integer_type_node);
3195 #endif
3196   DECL_IGNORED_P (vars) = 1;
3197   SET_DECL_ARTIFICIAL (vars);
3198   pushdecl (vars);
3199 #endif
3200
3201   /* Walk to mark the inline functions we need, then output them so
3202      that we can pick up any other tdecls that those routines need.  */
3203   walk_vtables ((void (*) PROTO ((tree, tree))) 0,
3204                 finish_prevtable_vardecl);
3205
3206   for (vars = static_aggregates; vars; vars = TREE_CHAIN (vars))
3207     if (! TREE_ASM_WRITTEN (TREE_VALUE (vars)))
3208       rest_of_decl_compilation (TREE_VALUE (vars), 0, 1, 1);
3209   vars = static_aggregates;
3210
3211   if (static_ctors || vars)
3212     needs_messing_up = 1;
3213   if (static_dtors || vars)
3214     needs_cleaning = 1;
3215
3216   /* The aggregates are listed in reverse declaration order, for cleaning.  */
3217   if (needs_cleaning)
3218     {
3219       do_dtors ();
3220     }
3221
3222   /* do_ctors will reverse the lists for messing up.  */
3223   if (needs_messing_up)
3224     {
3225       do_ctors ();
3226     }
3227
3228   permanent_allocation (1);
3229
3230   /* Done with C language context needs.  */
3231   pop_lang_context ();
3232
3233   /* Now write out any static class variables (which may have since
3234      learned how to be initialized).  */
3235   while (pending_statics)
3236     {
3237       tree decl = TREE_VALUE (pending_statics);
3238
3239       /* Output DWARF debug information.  */
3240 #ifdef DWARF_DEBUGGING_INFO
3241       if (write_symbols == DWARF_DEBUG)
3242         dwarfout_file_scope_decl (decl, 1);
3243 #endif
3244 #ifdef DWARF2_DEBUGGING_INFO
3245       if (write_symbols == DWARF2_DEBUG)
3246         dwarf2out_decl (decl);
3247 #endif
3248
3249       DECL_DEFER_OUTPUT (decl) = 0;
3250       rest_of_decl_compilation
3251         (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), 1, 1);
3252
3253       pending_statics = TREE_CHAIN (pending_statics);
3254     }
3255
3256   this_time = get_run_time ();
3257   parse_time -= this_time - start_time;
3258   varconst_time += this_time - start_time;
3259
3260   start_time = get_run_time ();
3261
3262   if (flag_handle_signatures)
3263     walk_sigtables ((void (*) PROTO ((tree, tree))) 0,
3264                     finish_sigtable_vardecl);
3265
3266   for (fnname = saved_inlines; fnname; fnname = TREE_CHAIN (fnname))
3267     {
3268       tree decl = TREE_VALUE (fnname);
3269       import_export_decl (decl);
3270     }
3271
3272   mark_all_runtime_matches ();
3273
3274   /* Now write out inline functions which had their addresses taken and
3275      which were not declared virtual and which were not declared `extern
3276      inline'.  */
3277   {
3278     int reconsider = 1;         /* More may be referenced; check again */
3279
3280     while (reconsider)
3281       {
3282         tree *p = &saved_inlines;
3283         reconsider = 0;
3284
3285         /* We need to do this each time so that newly completed template
3286            types don't wind up at the front of the list.  Sigh.  */
3287         vars = build_decl (TYPE_DECL, make_anon_name (), integer_type_node);
3288         DECL_IGNORED_P (vars) = 1;
3289         SET_DECL_ARTIFICIAL (vars);
3290         pushdecl (vars);
3291
3292         reconsider |= walk_vtables ((void (*) PROTO((tree, tree))) 0, 
3293                                     finish_vtable_vardecl);
3294
3295         while (*p)
3296           {
3297             tree decl = TREE_VALUE (*p);
3298
3299             if (DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl)
3300                 && TREE_USED (decl)
3301                 && (! DECL_REALLY_EXTERN (decl) || DECL_INLINE (decl)))
3302               {
3303                 if (DECL_MUTABLE_P (decl))
3304                   synthesize_tinfo_fn (decl);
3305                 else
3306                   synthesize_method (decl);
3307                 reconsider = 1;
3308               }
3309
3310             /* Catch new template instantiations.  */
3311             if (decl != TREE_VALUE (*p))
3312               continue;
3313
3314             if (TREE_ASM_WRITTEN (decl)
3315                 || (DECL_SAVED_INSNS (decl) == 0 && ! DECL_ARTIFICIAL (decl)))
3316               *p = TREE_CHAIN (*p);
3317             else if (DECL_INITIAL (decl) == 0)
3318               p = &TREE_CHAIN (*p);
3319             else if ((TREE_PUBLIC (decl) && ! DECL_COMDAT (decl))
3320                      || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
3321                      || flag_keep_inline_functions)
3322               {
3323                 if (DECL_NOT_REALLY_EXTERN (decl))
3324                   {
3325                     DECL_EXTERNAL (decl) = 0;
3326                     reconsider = 1;
3327                     /* We can't inline this function after it's been
3328                        emitted.  We want a variant of
3329                        output_inline_function that doesn't prevent
3330                        subsequent integration...  */
3331                     DECL_INLINE (decl) = 0;
3332                     output_inline_function (decl);
3333                     permanent_allocation (1);
3334                   }
3335
3336                 *p = TREE_CHAIN (*p);
3337               }
3338             else
3339               p = &TREE_CHAIN (*p);
3340           }
3341       }
3342
3343     /* It's possible that some of the remaining inlines will still be
3344        needed.  For example, a static inline whose address is used in
3345        the initializer for a file-scope static variable will be
3346        needed.  Code in compile_file will handle this, but we mustn't
3347        pretend that there are no definitions for the inlines, or it
3348        won't be able to.
3349
3350        FIXME: This won't catch member functions.  We should really
3351        unify this stuff with the compile_file stuff.  */
3352     for (vars = saved_inlines; vars != NULL_TREE; vars = TREE_CHAIN (vars))
3353       {
3354         tree decl = TREE_VALUE (vars);
3355
3356         if (DECL_NOT_REALLY_EXTERN (decl)
3357             && !DECL_COMDAT (decl)
3358             && DECL_INITIAL (decl) != NULL_TREE)
3359           DECL_EXTERNAL (decl) = 0;
3360       }
3361   }
3362
3363   /* Now delete from the chain of variables all virtual function tables.
3364      We output them all ourselves, because each will be treated specially.  */
3365
3366   walk_vtables ((void (*) PROTO((tree, tree))) 0,
3367                 prune_vtable_vardecl);
3368
3369   if (write_virtuals == 2)
3370     {
3371       /* Now complain about an virtual function tables promised
3372          but not delivered.  */
3373       while (pending_vtables)
3374         {
3375           if (TREE_PURPOSE (pending_vtables) == NULL_TREE)
3376             error ("virtual function table for `%s' not defined",
3377                    IDENTIFIER_POINTER (TREE_VALUE (pending_vtables)));
3378           pending_vtables = TREE_CHAIN (pending_vtables);
3379         }
3380     }
3381
3382   finish_repo ();
3383
3384   this_time = get_run_time ();
3385   parse_time -= this_time - start_time;
3386   varconst_time += this_time - start_time;
3387
3388   if (flag_detailed_statistics)
3389     {
3390       dump_tree_statistics ();
3391       dump_time_statistics ();
3392     }
3393 }
3394
3395 /* This is something of the form 'A()()()()()+1' that has turned out to be an
3396    expr.  Since it was parsed like a type, we need to wade through and fix
3397    that.  Unfortunately, since operator() is left-associative, we can't use
3398    tail recursion.  In the above example, TYPE is `A', and DECL is
3399    `()()()()()'.
3400
3401    Maybe this shouldn't be recursive, but how often will it actually be
3402    used?  (jason) */
3403
3404 tree
3405 reparse_absdcl_as_expr (type, decl)
3406      tree type, decl;
3407 {
3408   /* do build_functional_cast (type, NULL_TREE) at bottom */
3409   if (TREE_OPERAND (decl, 0) == NULL_TREE)
3410     return build_functional_cast (type, NULL_TREE);
3411
3412   /* recurse */
3413   decl = reparse_decl_as_expr (type, TREE_OPERAND (decl, 0));
3414
3415   decl = build_x_function_call (decl, NULL_TREE, current_class_ref);
3416
3417   if (TREE_CODE (decl) == CALL_EXPR && TREE_TYPE (decl) != void_type_node)
3418     decl = require_complete_type (decl);
3419
3420   return decl;
3421 }
3422
3423 /* This is something of the form `int ((int)(int)(int)1)' that has turned
3424    out to be an expr.  Since it was parsed like a type, we need to wade
3425    through and fix that.  Since casts are right-associative, we are
3426    reversing the order, so we don't have to recurse.
3427
3428    In the above example, DECL is the `(int)(int)(int)', and EXPR is the
3429    `1'.  */
3430
3431 tree
3432 reparse_absdcl_as_casts (decl, expr)
3433      tree decl, expr;
3434 {
3435   tree type;
3436   
3437   if (TREE_CODE (expr) == CONSTRUCTOR
3438       && TREE_TYPE (expr) == 0)
3439     {
3440       type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3441       decl = TREE_OPERAND (decl, 0);
3442
3443       if (IS_SIGNATURE (type))
3444         {
3445           error ("cast specifies signature type");
3446           return error_mark_node;
3447         }
3448
3449       expr = digest_init (type, expr, (tree *) 0);
3450       if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
3451         {
3452           int failure = complete_array_type (type, expr, 1);
3453           if (failure)
3454             my_friendly_abort (78);
3455         }
3456     }
3457
3458   while (decl)
3459     {
3460       type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3461       decl = TREE_OPERAND (decl, 0);
3462       expr = build_c_cast (type, expr);
3463     }
3464
3465   if (warn_old_style_cast)
3466     warning ("use of old-style cast");
3467
3468   return expr;
3469 }
3470
3471 /* Given plain tree nodes for an expression, build up the full semantics.  */
3472
3473 tree
3474 build_expr_from_tree (t)
3475      tree t;
3476 {
3477   if (t == NULL_TREE || t == error_mark_node)
3478     return t;
3479
3480   switch (TREE_CODE (t))
3481     {
3482     case IDENTIFIER_NODE:
3483       return do_identifier (t, 0, NULL_TREE);
3484
3485     case LOOKUP_EXPR:
3486       if (LOOKUP_EXPR_GLOBAL (t))
3487         return do_scoped_id (TREE_OPERAND (t, 0), 0);
3488       else
3489         return do_identifier (TREE_OPERAND (t, 0), 0, NULL_TREE);
3490
3491     case TEMPLATE_ID_EXPR:
3492       return (lookup_template_function
3493               (build_expr_from_tree (TREE_OPERAND (t, 0)),
3494                build_expr_from_tree (TREE_OPERAND (t, 1))));
3495
3496     case INDIRECT_REF:
3497       return build_x_indirect_ref
3498         (build_expr_from_tree (TREE_OPERAND (t, 0)), "unary *");
3499
3500     case CAST_EXPR:
3501       return build_functional_cast
3502         (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3503
3504     case REINTERPRET_CAST_EXPR:
3505       return build_reinterpret_cast
3506         (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3507
3508     case CONST_CAST_EXPR:
3509       return build_const_cast
3510         (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3511
3512     case DYNAMIC_CAST_EXPR:
3513       return build_dynamic_cast
3514         (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3515
3516     case STATIC_CAST_EXPR:
3517       return build_static_cast
3518         (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3519
3520     case PREDECREMENT_EXPR:
3521     case PREINCREMENT_EXPR:
3522     case POSTDECREMENT_EXPR:
3523     case POSTINCREMENT_EXPR:
3524     case NEGATE_EXPR:
3525     case BIT_NOT_EXPR:
3526     case ABS_EXPR:
3527     case TRUTH_NOT_EXPR:
3528     case ADDR_EXPR:
3529     case CONVERT_EXPR:      /* Unary + */
3530       if (TREE_TYPE (t))
3531         return t;
3532       return build_x_unary_op (TREE_CODE (t),
3533                                build_expr_from_tree (TREE_OPERAND (t, 0)));
3534
3535     case PLUS_EXPR:
3536     case MINUS_EXPR:
3537     case MULT_EXPR:
3538     case TRUNC_DIV_EXPR:
3539     case CEIL_DIV_EXPR:
3540     case FLOOR_DIV_EXPR:
3541     case ROUND_DIV_EXPR:
3542     case EXACT_DIV_EXPR:
3543     case BIT_AND_EXPR:
3544     case BIT_ANDTC_EXPR:
3545     case BIT_IOR_EXPR:
3546     case BIT_XOR_EXPR:
3547     case TRUNC_MOD_EXPR:
3548     case FLOOR_MOD_EXPR:
3549     case TRUTH_ANDIF_EXPR:
3550     case TRUTH_ORIF_EXPR:
3551     case TRUTH_AND_EXPR:
3552     case TRUTH_OR_EXPR:
3553     case RSHIFT_EXPR:
3554     case LSHIFT_EXPR:
3555     case RROTATE_EXPR:
3556     case LROTATE_EXPR:
3557     case EQ_EXPR:
3558     case NE_EXPR:
3559     case MAX_EXPR:
3560     case MIN_EXPR:
3561     case LE_EXPR:
3562     case GE_EXPR:
3563     case LT_EXPR:
3564     case GT_EXPR:
3565     case MEMBER_REF:
3566       return build_x_binary_op
3567         (TREE_CODE (t), 
3568          build_expr_from_tree (TREE_OPERAND (t, 0)),
3569          build_expr_from_tree (TREE_OPERAND (t, 1)));
3570
3571     case DOTSTAR_EXPR:
3572       return build_m_component_ref
3573         (build_expr_from_tree (TREE_OPERAND (t, 0)),
3574          build_expr_from_tree (TREE_OPERAND (t, 1)));
3575
3576     case SCOPE_REF:
3577       return build_offset_ref (TREE_OPERAND (t, 0), TREE_OPERAND (t, 1));
3578
3579     case ARRAY_REF:
3580       if (TREE_OPERAND (t, 0) == NULL_TREE)
3581         /* new-type-id */
3582         return build_parse_node (ARRAY_REF, NULL_TREE,
3583                                  build_expr_from_tree (TREE_OPERAND (t, 1)));
3584       return grok_array_decl (build_expr_from_tree (TREE_OPERAND (t, 0)),
3585                               build_expr_from_tree (TREE_OPERAND (t, 1)));
3586
3587     case SIZEOF_EXPR:
3588     case ALIGNOF_EXPR:
3589       {
3590         tree r = build_expr_from_tree (TREE_OPERAND (t, 0));
3591         if (TREE_CODE_CLASS (TREE_CODE (r)) != 't')
3592           r = TREE_TYPE (r);
3593         return TREE_CODE (t) == SIZEOF_EXPR ? c_sizeof (r) : c_alignof (r);
3594       }
3595
3596     case MODOP_EXPR:
3597       return build_x_modify_expr
3598         (build_expr_from_tree (TREE_OPERAND (t, 0)),
3599          TREE_CODE (TREE_OPERAND (t, 1)),
3600          build_expr_from_tree (TREE_OPERAND (t, 2)));
3601
3602     case ARROW_EXPR:
3603       return build_x_arrow
3604         (build_expr_from_tree (TREE_OPERAND (t, 0)));
3605
3606     case NEW_EXPR:
3607       return build_new
3608         (build_expr_from_tree (TREE_OPERAND (t, 0)),
3609          build_expr_from_tree (TREE_OPERAND (t, 1)),
3610          build_expr_from_tree (TREE_OPERAND (t, 2)),
3611          NEW_EXPR_USE_GLOBAL (t));
3612
3613     case DELETE_EXPR:
3614       return delete_sanity
3615         (build_expr_from_tree (TREE_OPERAND (t, 0)),
3616          build_expr_from_tree (TREE_OPERAND (t, 1)),
3617          DELETE_EXPR_USE_VEC (t), DELETE_EXPR_USE_GLOBAL (t));
3618
3619     case COMPOUND_EXPR:
3620       if (TREE_OPERAND (t, 1) == NULL_TREE)
3621         return build_x_compound_expr
3622           (build_expr_from_tree (TREE_OPERAND (t, 0)));
3623       else
3624         my_friendly_abort (42);
3625
3626     case METHOD_CALL_EXPR:
3627       if (TREE_CODE (TREE_OPERAND (t, 0)) == SCOPE_REF)
3628         {
3629           tree ref = TREE_OPERAND (t, 0);
3630           return build_scoped_method_call
3631             (build_expr_from_tree (TREE_OPERAND (t, 1)),
3632              build_expr_from_tree (TREE_OPERAND (ref, 0)),
3633              TREE_OPERAND (ref, 1),
3634              build_expr_from_tree (TREE_OPERAND (t, 2)));
3635         }
3636       return build_method_call
3637         (build_expr_from_tree (TREE_OPERAND (t, 1)),
3638          TREE_OPERAND (t, 0),
3639          build_expr_from_tree (TREE_OPERAND (t, 2)),
3640          NULL_TREE, LOOKUP_NORMAL);
3641
3642     case CALL_EXPR:
3643       if (TREE_CODE (TREE_OPERAND (t, 0)) == SCOPE_REF)
3644         {
3645           tree ref = TREE_OPERAND (t, 0);
3646           return build_member_call
3647             (build_expr_from_tree (TREE_OPERAND (ref, 0)),
3648              TREE_OPERAND (ref, 1),
3649              build_expr_from_tree (TREE_OPERAND (t, 1)));
3650         }
3651       else
3652         {
3653           tree name = TREE_OPERAND (t, 0);
3654           tree id;
3655           tree args = build_expr_from_tree (TREE_OPERAND (t, 1));
3656           if (args != NULL_TREE && TREE_CODE (name) == LOOKUP_EXPR
3657               && !LOOKUP_EXPR_GLOBAL (name)
3658               && TREE_CODE ((id = TREE_OPERAND (name, 0))) == IDENTIFIER_NODE
3659               && (!current_class_type
3660                   || !lookup_member (current_class_type, id, 0, 0)))
3661             {
3662               /* Do Koenig lookup if there are no class members. */
3663               name = do_identifier (id, 0, args);
3664             }
3665           else if (TREE_CODE (name) == TEMPLATE_ID_EXPR
3666               || ! really_overloaded_fn (name))
3667             name = build_expr_from_tree (name);
3668           return build_x_function_call (name, args, current_class_ref);
3669         }
3670
3671     case COND_EXPR:
3672       return build_x_conditional_expr
3673         (build_expr_from_tree (TREE_OPERAND (t, 0)),
3674          build_expr_from_tree (TREE_OPERAND (t, 1)),
3675          build_expr_from_tree (TREE_OPERAND (t, 2)));
3676
3677     case TREE_LIST:
3678       {
3679         tree purpose, value, chain;
3680
3681         if (t == void_list_node)
3682           return t;
3683
3684         purpose = TREE_PURPOSE (t);
3685         if (purpose)
3686           purpose = build_expr_from_tree (purpose);
3687         value = TREE_VALUE (t);
3688         if (value)
3689           value = build_expr_from_tree (value);
3690         chain = TREE_CHAIN (t);
3691         if (chain && chain != void_type_node)
3692           chain = build_expr_from_tree (chain);
3693         return expr_tree_cons (purpose, value, chain);
3694       }
3695
3696     case COMPONENT_REF:
3697       return build_x_component_ref
3698         (build_expr_from_tree (TREE_OPERAND (t, 0)),
3699          TREE_OPERAND (t, 1), NULL_TREE, 1);
3700       
3701     case THROW_EXPR:
3702       return build_throw (build_expr_from_tree (TREE_OPERAND (t, 0)));
3703
3704     case CONSTRUCTOR:
3705       {
3706         tree r;
3707
3708         /* digest_init will do the wrong thing if we let it.  */
3709         if (TREE_TYPE (t) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t)))
3710           return t;
3711
3712         r = build_nt (CONSTRUCTOR, NULL_TREE,
3713                       build_expr_from_tree (CONSTRUCTOR_ELTS (t)));
3714
3715         if (TREE_TYPE (t))
3716           return digest_init (TREE_TYPE (t), r, 0);
3717         return r;
3718       }
3719
3720     case TYPEID_EXPR:
3721       if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t, 0))) == 't')
3722         return get_typeid (TREE_OPERAND (t, 0));
3723       return build_x_typeid (build_expr_from_tree (TREE_OPERAND (t, 0)));
3724
3725     case VAR_DECL:
3726       return convert_from_reference (t);
3727
3728     default:
3729       return t;
3730     }
3731 }
3732
3733 /* This is something of the form `int (*a)++' that has turned out to be an
3734    expr.  It was only converted into parse nodes, so we need to go through
3735    and build up the semantics.  Most of the work is done by
3736    build_expr_from_tree, above.
3737
3738    In the above example, TYPE is `int' and DECL is `*a'.  */
3739
3740 tree
3741 reparse_decl_as_expr (type, decl)
3742      tree type, decl;
3743 {
3744   decl = build_expr_from_tree (decl);
3745   if (type)
3746     return build_functional_cast (type, build_expr_list (NULL_TREE, decl));
3747   else
3748     return decl;
3749 }
3750
3751 /* This is something of the form `int (*a)' that has turned out to be a
3752    decl.  It was only converted into parse nodes, so we need to do the
3753    checking that make_{pointer,reference}_declarator do.  */
3754
3755 tree
3756 finish_decl_parsing (decl)
3757      tree decl;
3758 {
3759   extern int current_class_depth;
3760   
3761   switch (TREE_CODE (decl))
3762     {
3763     case IDENTIFIER_NODE:
3764       return decl;
3765     case INDIRECT_REF:
3766       return make_pointer_declarator
3767         (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3768     case ADDR_EXPR:
3769       return make_reference_declarator
3770         (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3771     case BIT_NOT_EXPR:
3772       TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3773       return decl;
3774     case SCOPE_REF:
3775       push_nested_class (TREE_TYPE (TREE_OPERAND (decl, 0)), 3);
3776       TREE_COMPLEXITY (decl) = current_class_depth;
3777       return decl;
3778     case ARRAY_REF:
3779       TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3780       return decl;
3781     default:
3782       my_friendly_abort (5);
3783       return NULL_TREE;
3784     }
3785 }
3786
3787 tree
3788 check_cp_case_value (value)
3789      tree value;
3790 {
3791   if (value == NULL_TREE)
3792     return value;
3793
3794   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
3795   STRIP_TYPE_NOPS (value);
3796
3797   if (TREE_READONLY_DECL_P (value))
3798     {
3799       value = decl_constant_value (value);
3800       STRIP_TYPE_NOPS (value);
3801     }
3802   value = fold (value);
3803
3804   if (TREE_CODE (value) != INTEGER_CST
3805       && value != error_mark_node)
3806     {
3807       cp_error ("case label `%E' does not reduce to an integer constant",
3808                 value);
3809       value = error_mark_node;
3810     }
3811   else
3812     /* Promote char or short to int.  */
3813     value = default_conversion (value);
3814
3815   constant_expression_warning (value);
3816
3817   return value;
3818 }
3819
3820 /* Return 1 if root encloses child. */
3821
3822 static int
3823 is_namespace_ancestor (root, child)
3824      tree root, child;
3825 {
3826   if (root == child)
3827     return 1;
3828   if (root == global_namespace)
3829     return 1;
3830   if (child == global_namespace)
3831     return 0;
3832   return is_namespace_ancestor (root, CP_DECL_CONTEXT (child));
3833 }
3834   
3835
3836 /* Return the namespace that is the common ancestor 
3837    of two given namespaces. */
3838
3839 static tree
3840 namespace_ancestor (ns1, ns2)
3841      tree ns1, ns2;
3842 {
3843   if (is_namespace_ancestor (ns1, ns2))
3844     return ns1;
3845   return namespace_ancestor (DECL_CONTEXT (ns1), ns2);
3846 }
3847
3848 /* Insert used into the using list of user. Set indirect_flag if this
3849    directive is not directly from the source. Also find the common
3850    ancestor and let our users know about the new namespace */
3851 static void 
3852 add_using_namespace (user, used, indirect)
3853      tree user;
3854      tree used;
3855      int indirect;
3856 {
3857   tree iter;
3858   /* Using oneself is a no-op. */
3859   if (user == used)
3860     return;
3861   my_friendly_assert (TREE_CODE (user) == NAMESPACE_DECL, 380);
3862   my_friendly_assert (TREE_CODE (used) == NAMESPACE_DECL, 380);
3863   /* Check if we already have this. */
3864   if (purpose_member (used, DECL_NAMESPACE_USING (user)) != NULL_TREE)
3865     return;
3866
3867   /* Add used to the user's using list. */
3868   DECL_NAMESPACE_USING (user) 
3869     = perm_tree_cons (used, namespace_ancestor (user, used), 
3870                       DECL_NAMESPACE_USING (user));
3871
3872   TREE_INDIRECT_USING (DECL_NAMESPACE_USING (user)) = indirect;
3873
3874   /* Add user to the used's users list. */
3875   DECL_NAMESPACE_USERS (used)
3876     = perm_tree_cons (user, 0, DECL_NAMESPACE_USERS (used));
3877                       
3878   for (iter = DECL_NAMESPACE_USERS (user); iter; iter = TREE_CHAIN (iter))
3879     /* indirect usage */
3880     add_using_namespace (TREE_PURPOSE (iter), used, 1);
3881 }
3882
3883 /* Combines two sets of overloaded functions into an OVERLOAD chain.
3884    The first list becomes the tail of the result. */
3885
3886 static tree
3887 merge_functions (s1, s2)
3888      tree s1;
3889      tree s2;
3890 {
3891   if (TREE_CODE (s2) == OVERLOAD)
3892     while (s2)
3893       {
3894         s1 = build_overload (OVL_FUNCTION (s2), s1);
3895         s2 = OVL_CHAIN (s2);
3896       }
3897   else
3898     s1 = build_overload (s2, s1);
3899   return s1;
3900 }
3901
3902 /* This should return an error not all definitions define functions.
3903    It is not an error if we find two functions with exactly the
3904    same signature, only if these are selected in overload resolution.
3905    old is the current set of bindings, new the freshly-found binding.
3906    XXX Do we want to give *all* candidates in case of ambiguity?
3907    XXX In what way should I treat extern declarations?
3908    XXX I don't want to repeat the entire duplicate_decls here */
3909
3910 static tree
3911 ambiguous_decl (name, old, new)
3912      tree name;
3913      tree old;
3914      tree new;
3915 {
3916   my_friendly_assert (old != NULL_TREE, 393);
3917   /* Copy the value. */
3918   if (!BINDING_VALUE (old))
3919     BINDING_VALUE (old) = BINDING_VALUE (new);
3920   else if (BINDING_VALUE (new) 
3921            && BINDING_VALUE (new) != BINDING_VALUE (old))
3922     {
3923       if (is_overloaded_fn (BINDING_VALUE (old)) 
3924           && is_overloaded_fn (BINDING_VALUE (new)))
3925         {
3926           BINDING_VALUE (old) = merge_functions (BINDING_VALUE (old),
3927                                                  BINDING_VALUE (new));
3928         }
3929       else
3930         {
3931           /* Some declarations are functions, some are not. */
3932           cp_error ("ambiguous definition `%D' used", name);
3933           cp_error_at ("first definition here", BINDING_VALUE (old));
3934           cp_error_at ("other definition here", BINDING_VALUE (new));
3935           return error_mark_node;
3936         }
3937     }
3938   /* ... and copy the type. */
3939   if (!BINDING_TYPE (old))
3940     BINDING_TYPE (old) = BINDING_TYPE (new);
3941   else if(BINDING_TYPE (new)
3942           && BINDING_TYPE (old) != BINDING_TYPE (new))
3943     {
3944       cp_error ("`%D' denotes an ambiguous type",name);
3945       cp_error_at ("first type here", BINDING_TYPE (old));
3946       cp_error_at ("other type here", BINDING_TYPE (new));
3947     }
3948   return old;
3949 }
3950
3951 /* Add the bindings of name in used namespaces to val.
3952    The using list is defined by usings, and the lookup goes to scope.
3953    Returns zero on errors. */
3954
3955 int
3956 lookup_using_namespace (name, val, usings, scope)
3957      tree name, val, usings, scope;
3958 {
3959   tree iter;
3960   tree val1;
3961   /* Iterate over all used namespaces in current, searching for using
3962      directives of scope. */
3963   for (iter = usings; iter; iter = TREE_CHAIN (iter))
3964     if (TREE_VALUE (iter) == scope)
3965       {
3966         val1 = binding_for_name (name, TREE_PURPOSE (iter));
3967         /* Resolve ambiguities. */
3968         val = ambiguous_decl (name, val, val1);
3969       }
3970   return val != error_mark_node;
3971 }
3972
3973 /* [namespace.qual]
3974    Excepts the name to lookup and its qualifying scope.
3975    Returns the name/type pair found into the CPLUS_BINDING result,
3976    or 0 on error. */
3977
3978 int
3979 qualified_lookup_using_namespace (name, scope, result)
3980      tree name;
3981      tree scope;
3982      tree result;
3983 {
3984   /* Maintain a list of namespaces visited... */
3985   tree seen = NULL_TREE;
3986   /* ... and a list of namespace yet to see. */
3987   tree todo = NULL_TREE;
3988   tree usings;
3989   while (scope && (result != error_mark_node))
3990     {
3991       seen = temp_tree_cons (scope, NULL_TREE, seen);
3992       result = ambiguous_decl (name, result, binding_for_name (name, scope));
3993       if (!BINDING_VALUE (result) && !BINDING_TYPE (result))
3994         /* Consider using directives. */
3995         for (usings = DECL_NAMESPACE_USING (scope); usings;
3996              usings = TREE_CHAIN (usings))
3997           /* If this was a real directive, and we have not seen it. */
3998           if (!TREE_INDIRECT_USING (usings)
3999               && !purpose_member (TREE_PURPOSE (usings), seen))
4000             todo = temp_tree_cons (TREE_PURPOSE (usings), NULL_TREE, todo);
4001       if (todo)
4002         {
4003           scope = TREE_PURPOSE (todo);
4004           todo = TREE_CHAIN (todo);
4005         }
4006       else
4007         scope = NULL_TREE; /* If there never was a todo list. */
4008     }
4009   return result != error_mark_node;
4010 }
4011
4012 /* [namespace.memdef]/2 */
4013
4014 /* Set the context of a declaration to scope. Complain if we are not
4015    outside scope. */
4016
4017 void
4018 set_decl_namespace (decl, scope)
4019      tree decl;
4020      tree scope;
4021 {
4022   tree old;
4023   if (scope == std_node)
4024     scope = global_namespace;
4025   /* Get rid of namespace aliases. */
4026   scope = ORIGINAL_NAMESPACE (scope);
4027   
4028   if (!is_namespace_ancestor (current_namespace, scope))
4029     cp_error ("declaration of `%D' not in a namespace surrounding `%D'",
4030               decl, scope);
4031   DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
4032   if (scope != current_namespace)
4033     {
4034       /* See whether this has been declared in the namespace. */
4035       old = namespace_binding (DECL_NAME (decl), scope);
4036       if (!old)
4037         /* No old declaration at all. */
4038         goto complain;
4039       if (!is_overloaded_fn (decl))
4040         /* Don't compare non-function decls with decls_match here,
4041            since it can't check for the correct constness at this
4042            point. pushdecl will find those errors later.  */
4043         return;
4044       /* Since decl is a function, old should contain a function decl. */
4045       if (!is_overloaded_fn (old))
4046         goto complain;
4047       for (; old; old = OVL_NEXT (old))
4048         if (decls_match (decl, OVL_CURRENT (old)))
4049           return;
4050     }
4051   else
4052     return;
4053  complain:
4054   cp_error ("`%D' should have been declared inside `%D'",
4055             decl, scope);
4056
4057
4058 /* Compute the namespace where a declaration is defined. */
4059
4060 tree
4061 decl_namespace (decl)
4062      tree decl;
4063 {
4064   while (DECL_CONTEXT (decl))
4065     {
4066       decl = DECL_CONTEXT (decl);
4067       if (TREE_CODE (decl) == NAMESPACE_DECL)
4068         return decl;
4069       if (TREE_CODE_CLASS (TREE_CODE (decl)) == 't')
4070         decl = TYPE_STUB_DECL (decl);
4071       my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd', 390);
4072     }
4073
4074   return global_namespace;
4075 }
4076
4077 /* Return the namespace where the current declaration is declared. */
4078
4079 tree
4080 current_decl_namespace ()
4081 {
4082   tree result;
4083   /* If we have been pushed into a different namespace, use it. */
4084   if (decl_namespace_list)
4085     return TREE_PURPOSE (decl_namespace_list);
4086
4087   if (current_class_type)
4088     if (CLASSTYPE_USE_TEMPLATE (current_class_type))
4089       result = decl_namespace (CLASSTYPE_TI_TEMPLATE (current_class_type));
4090     else
4091       result = decl_namespace (TYPE_STUB_DECL (current_class_type));
4092   else if (current_function_decl)
4093     if (DECL_USE_TEMPLATE (current_function_decl))
4094       result = decl_namespace (DECL_TI_TEMPLATE (current_function_decl));
4095     else
4096       result = decl_namespace (current_function_decl);
4097   else 
4098     result = current_namespace;
4099   return result;
4100 }
4101
4102 /* Temporarily set the namespace for the current declaration. */
4103
4104 void
4105 push_decl_namespace (decl)
4106      tree decl;
4107 {
4108   if (TREE_CODE (decl) != NAMESPACE_DECL)
4109     decl = decl_namespace (decl);
4110   decl_namespace_list = tree_cons (decl, NULL_TREE, decl_namespace_list);
4111 }
4112
4113 void
4114 pop_decl_namespace ()
4115 {
4116   decl_namespace_list = TREE_CHAIN (decl_namespace_list);
4117 }
4118
4119 /* [basic.lookup.koenig] */
4120 /* A non-zero return value in the functions below indicates an error.
4121    All nodes allocated in the procedure are on the scratch obstack. */
4122
4123 struct arg_lookup
4124 {
4125   tree name;
4126   tree namespaces;
4127   tree classes;
4128   tree functions;
4129 };
4130
4131 static int arg_assoc         PROTO((struct arg_lookup*, tree));
4132 static int arg_assoc_args    PROTO((struct arg_lookup*, tree));
4133
4134 /* Add a function to the lookup structure. */
4135
4136 static int
4137 add_function (k, fn)
4138      struct arg_lookup *k;
4139      tree fn;
4140 {
4141   if (ovl_member (fn, k->functions))
4142     return 0;
4143   k->functions = build_overload (fn, k->functions);
4144   return 0;
4145 }
4146
4147 /* Add functions of a namespace to the lookup structure. */
4148
4149 static int
4150 arg_assoc_namespace (k, scope)
4151      struct arg_lookup *k;
4152      tree scope;
4153 {
4154   tree value;
4155
4156   if (purpose_member (scope, k->namespaces))
4157     return 0;
4158   k->namespaces = tree_cons (scope, NULL_TREE, k->namespaces);
4159   
4160   value = namespace_binding (k->name, scope);
4161   if (!value)
4162     return 0;
4163   
4164   if (!is_overloaded_fn (value))
4165     {
4166       cp_error_at ("`%D' is not a function", value);
4167       cp_error ("in call to `%D'", k->name);
4168       return 1;
4169     }
4170   
4171   for (; value; value = OVL_NEXT (value))
4172     if (add_function (k, OVL_CURRENT (value)))
4173       return 1;
4174   
4175   return 0;
4176 }
4177
4178 /* Adds everything associated with class to the lookup structure. */
4179
4180 static int
4181 arg_assoc_class (k, type)
4182      struct arg_lookup* k;
4183      tree type;
4184 {
4185   tree list, friends, context;
4186   int i;
4187   
4188   if (purpose_member (type, k->classes))
4189     return 0;
4190   k->classes = tree_cons (type, NULL_TREE, k->classes);
4191   
4192   context = decl_namespace (TYPE_MAIN_DECL (type));
4193   if (arg_assoc_namespace (k, context))
4194     return 1;
4195   
4196   /* Process baseclasses. */
4197   for (i = 0; i < CLASSTYPE_N_BASECLASSES (type); i++)
4198     if (arg_assoc_class (k, TYPE_BINFO_BASETYPE (type, i)))
4199       return 1;
4200   
4201   /* Process friends. */
4202   for (list = DECL_FRIENDLIST (TYPE_MAIN_DECL (type)); list; 
4203        list = TREE_CHAIN (list))
4204     if (k->name == TREE_PURPOSE (list))
4205       for (friends = TREE_VALUE (list); friends; 
4206            friends = TREE_CHAIN (friends))
4207         /* Only interested in global functions with potentially hidden
4208            (i.e. unqualified) declarations. */
4209         if (TREE_PURPOSE (list) == error_mark_node && TREE_VALUE (list)
4210             && decl_namespace (TREE_VALUE (list)) == context)
4211           if (add_function (k, TREE_VALUE (list)))
4212             return 1;
4213   return 0;
4214 }
4215
4216 /* Adds everything associated with a given type. */
4217
4218 static int
4219 arg_assoc_type (k, type)
4220      struct arg_lookup *k;
4221      tree type;
4222 {
4223   switch (TREE_CODE (type))
4224     {
4225     case VOID_TYPE:
4226     case INTEGER_TYPE:
4227     case REAL_TYPE:
4228     case COMPLEX_TYPE:
4229     case CHAR_TYPE:
4230     case BOOLEAN_TYPE:
4231       return 0;
4232     case RECORD_TYPE:
4233       if (TYPE_PTRMEMFUNC_P (type))
4234         return arg_assoc_type (k, TYPE_PTRMEMFUNC_FN_TYPE (type));
4235       return arg_assoc_class (k, type);
4236     case POINTER_TYPE:
4237     case REFERENCE_TYPE:
4238     case ARRAY_TYPE:
4239       return arg_assoc_type (k, TREE_TYPE (type));
4240     case UNION_TYPE:
4241     case ENUMERAL_TYPE:
4242       return arg_assoc_namespace (k, decl_namespace (TYPE_MAIN_DECL (type)));
4243     case OFFSET_TYPE:
4244       /* Pointer to member: associate class type and value type. */
4245       if (arg_assoc_type (k, TYPE_OFFSET_BASETYPE (type)))
4246         return 1;
4247       return arg_assoc_type (k, TREE_TYPE (type));
4248     case METHOD_TYPE:
4249       /* Associate the class of the method. */
4250       if (arg_assoc_type (k, TYPE_METHOD_BASETYPE (type)))
4251         return 1;
4252       /* Fall through. */
4253     case FUNCTION_TYPE:
4254       /* Associate the parameter types. */
4255       if (arg_assoc_args (k, TYPE_ARG_TYPES (type)))
4256         return 1;
4257       /* Associate the return type. */
4258       return arg_assoc_type (k, TREE_TYPE (type));
4259     case LANG_TYPE:
4260       if (type == unknown_type_node)
4261         return 0;
4262       /* else fall through */
4263     default:
4264       my_friendly_abort (390);
4265     }
4266   return 0;
4267 }
4268
4269 /* Adds everything associated with arguments. */
4270
4271 static int
4272 arg_assoc_args (k, args)
4273      struct arg_lookup* k;
4274      tree args;
4275 {
4276   for (; args; args = TREE_CHAIN (args))
4277     if (arg_assoc (k, TREE_VALUE (args)))
4278       return 1;
4279   return 0;
4280 }
4281
4282 /* Adds everything associated with a given tree_node. */
4283
4284 static int
4285 arg_assoc (k, n)
4286      struct arg_lookup* k;
4287      tree n;
4288 {
4289   switch (TREE_CODE_CLASS (TREE_CODE (n)))
4290     {
4291     case 't':
4292       return arg_assoc_type (k, n);
4293     case 'c':
4294     case '1':
4295     case '2':
4296     case '<':
4297     case 'r':
4298       return arg_assoc_type (k, TREE_TYPE (n));
4299     case 'e':
4300       switch (TREE_CODE (n))
4301         {
4302         case ADDR_EXPR:
4303           /* special processing */
4304           break;
4305         default:
4306           return arg_assoc_type (k, TREE_TYPE (n));
4307         }
4308     default:
4309       break;
4310     }
4311
4312   while (n)
4313     switch (TREE_CODE (n))
4314       {
4315       case CONST_DECL: /* 'd' */
4316       case VAR_DECL:
4317       case PARM_DECL:
4318       case RESULT_DECL:
4319         return arg_assoc_type (k, TREE_TYPE (n));
4320       case ADDR_EXPR: /* 'e' */
4321         /* We can't use the TREE_TYPE, as the type of an overloaded function
4322            will be useless here. */
4323         n = TREE_OPERAND (n, 0);
4324         continue;
4325       case OVERLOAD:  /* 'x' */
4326         if (arg_assoc (k, OVL_CURRENT (n)))
4327           return 1;
4328         n = OVL_NEXT (n);
4329         continue;
4330       case TREE_LIST: /* 'x' */
4331         /* XXX Overloaded member, should get an OVERLOAD directly, here. */
4332         n = TREE_VALUE (n);
4333         continue;
4334       case FUNCTION_DECL: /* 'd' */
4335         if (arg_assoc_args (k, FUNCTION_ARG_CHAIN (n)))
4336           return 1;     
4337         if (DECL_FUNCTION_MEMBER_P (n))
4338           if (arg_assoc_type (k, DECL_CLASS_CONTEXT (n)))
4339             return 1;
4340         return 0;
4341       case TEMPLATE_DECL:
4342         /* XXX Type of a function template in the context of Koenig lookup?
4343            Assume that template parameters are non-deduced for the moment. */
4344         n = DECL_RESULT (n);
4345         continue;
4346       case ERROR_MARK:
4347         return 0;
4348       default:
4349         cp_error ("sorry, Koenig lookup for `%s' of type `%T' failed",
4350                   tree_code_name [(int)TREE_CODE (n)], TREE_TYPE (n));
4351         my_friendly_abort (391);
4352       }
4353   return 0;
4354 }
4355
4356 /* Performs Koenig lookup depending on arguments, where fns
4357    are the functions found in normal lookup. */
4358
4359 tree
4360 lookup_arg_dependent (name, fns, args)
4361      tree name;
4362      tree fns;
4363      tree args;
4364 {
4365   struct arg_lookup k;
4366   k.name = name;
4367   k.functions = fns;
4368   k.namespaces = NULL_TREE;
4369   k.classes = NULL_TREE;
4370   
4371   push_scratch_obstack ();
4372   arg_assoc_args (&k, args);
4373   pop_obstacks ();
4374   return k.functions;
4375 }
4376
4377 /* Process a namespace-alias declaration. */
4378
4379 void
4380 do_namespace_alias (alias, namespace)
4381      tree alias, namespace;
4382 {
4383   tree binding;
4384   tree old;
4385
4386   if (TREE_CODE (namespace) != NAMESPACE_DECL)
4387     {
4388       /* The parser did not find it, so it's not there. */
4389       cp_error ("unknown namespace `%D'", namespace);
4390       return;
4391     }
4392
4393   namespace = ORIGINAL_NAMESPACE (namespace);
4394
4395   binding = binding_for_name (alias, current_namespace);
4396   old = BINDING_VALUE (binding);
4397   if (old)
4398     {
4399       if (TREE_CODE (old) == NAMESPACE_DECL
4400           && DECL_NAMESPACE_ALIAS (old) == namespace)
4401         /* Ok: redeclaration. */
4402         return;
4403       cp_error ("invalid namespace alias `%D'", alias);
4404       cp_error_at ("`%D' previously declared here", old);
4405     }
4406   else
4407     {
4408       /* Build the alias. */
4409       alias = build_lang_decl (NAMESPACE_DECL, alias, void_type_node);     
4410       DECL_NAMESPACE_ALIAS (alias) = namespace;
4411       DECL_CONTEXT (alias) = FROB_CONTEXT (current_namespace);
4412       BINDING_VALUE (binding) = alias;
4413     }
4414 }
4415
4416 /* Check a non-member using-declaration. Return the name and scope
4417    being used, and the USING_DECL, or NULL_TREE on failure. */
4418
4419 static tree
4420 validate_nonmember_using_decl (decl, scope, name)
4421      tree decl;
4422      tree *scope;
4423      tree *name;
4424 {
4425   if (TREE_CODE (decl) == SCOPE_REF
4426       && TREE_OPERAND (decl, 0) == std_node)
4427     return NULL_TREE;
4428   if (TREE_CODE (decl) == SCOPE_REF)
4429     {
4430       *scope = TREE_OPERAND (decl, 0);
4431       *name = TREE_OPERAND (decl, 1);
4432     }
4433   else if (TREE_CODE (decl) == IDENTIFIER_NODE
4434            || TREE_CODE (decl) == TYPE_DECL)
4435     {
4436       *scope = global_namespace;
4437       *name = decl;
4438     }
4439   else
4440     my_friendly_abort (382);
4441   if (TREE_CODE_CLASS (TREE_CODE (*name)) == 'd')
4442     *name = DECL_NAME (*name);
4443   /* Make a USING_DECL. */
4444   return push_using_decl (*scope, *name);
4445 }
4446
4447 /* Process local and global using-declarations. */
4448
4449 static void
4450 do_nonmember_using_decl (scope, name, oldval, oldtype, newval, newtype)
4451      tree scope, name;
4452      tree oldval, oldtype;
4453      tree *newval, *newtype;
4454 {
4455   tree decls;
4456   struct tree_binding _decls;
4457
4458   *newval = *newtype = NULL_TREE;
4459   decls = binding_init (&_decls);
4460   if (!qualified_lookup_using_namespace (name, scope, decls))
4461     /* Lookup error */
4462     return;
4463
4464   if (!BINDING_VALUE (decls) && !BINDING_TYPE (decls))
4465     {
4466       cp_error ("`%D' not declared", name);
4467       return;
4468     }
4469
4470   /* Check for using functions. */
4471   if (BINDING_VALUE (decls) && is_overloaded_fn (BINDING_VALUE (decls)))
4472     {
4473       tree tmp, tmp1;
4474       *newval = oldval;
4475       for (tmp = BINDING_VALUE (decls); tmp; tmp = OVL_NEXT (tmp))
4476         {
4477
4478           /* Compare each new function with each old one.
4479              If the old function was also used, there is no conflict. */
4480           for (tmp1 = oldval; tmp1; tmp1 = OVL_NEXT (tmp1))
4481             if (OVL_CURRENT (tmp) == OVL_CURRENT (tmp1))
4482               break;
4483             else if (OVL_USED (tmp1))
4484               continue;
4485             else if (duplicate_decls (OVL_CURRENT (tmp), OVL_CURRENT (tmp1)))
4486               return;
4487
4488           /* Duplicate use, ignore */
4489           if (tmp1)
4490             continue;
4491             
4492           *newval = build_overload (OVL_CURRENT (tmp), *newval);
4493           if (TREE_CODE (*newval) != OVERLOAD)
4494             *newval = ovl_cons (*newval, NULL_TREE);
4495           OVL_USED (*newval) = 1;
4496         }
4497     }
4498   else 
4499     {
4500       *newval = BINDING_VALUE (decls);
4501       if (oldval && oldval != *newval && !duplicate_decls (*newval, oldval))
4502         *newval = oldval;
4503     } 
4504
4505   *newtype = BINDING_TYPE (decls);
4506   if (oldtype && *newtype && oldtype != *newtype)
4507     {
4508       cp_error ("using directive `%D' introduced ambiguous type `%T'",
4509                 name, oldtype);
4510       return;
4511     }
4512 }
4513
4514 /* Process a using-declaration not appearing in class or local scope. */
4515
4516 void
4517 do_toplevel_using_decl (decl)
4518      tree decl;
4519 {
4520   tree scope, name, binding;
4521   tree oldval, oldtype, newval, newtype;
4522
4523   decl = validate_nonmember_using_decl (decl, &scope, &name);
4524   if (decl == NULL_TREE)
4525     return;
4526   
4527   binding = binding_for_name (name, current_namespace);
4528
4529   oldval = BINDING_VALUE (binding);
4530   oldtype = BINDING_TYPE (binding);
4531
4532   do_nonmember_using_decl (scope, name, oldval, oldtype, &newval, &newtype);
4533
4534   /* Copy declarations found. */
4535   if (newval)
4536     BINDING_VALUE (binding) = newval;
4537   if (newtype)
4538     BINDING_TYPE (binding) = newtype;
4539   return;
4540 }
4541
4542 void
4543 do_local_using_decl (decl)
4544      tree decl;
4545 {
4546   tree scope, name;
4547   tree oldval, oldtype, newval, newtype;
4548   decl = validate_nonmember_using_decl (decl, &scope, &name);
4549   if (decl == NULL_TREE)
4550     return;
4551
4552   /* XXX nested values */
4553   oldval = IDENTIFIER_LOCAL_VALUE (name);
4554   /* XXX get local type */
4555   oldtype = NULL_TREE;
4556
4557   do_nonmember_using_decl (scope, name, oldval, oldtype, &newval, &newtype);
4558
4559   if (newval)
4560     /* XXX update bindings */
4561     IDENTIFIER_LOCAL_VALUE (name) = newval;
4562   /* XXX type */
4563 }
4564
4565 tree
4566 do_class_using_decl (decl)
4567      tree decl;
4568 {
4569   tree name, value;
4570
4571   if (TREE_CODE (decl) != SCOPE_REF
4572       || TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (decl, 0))) != 't')
4573     {
4574       cp_error ("using-declaration for non-member at class scope");
4575       return NULL_TREE;
4576     }
4577   name = TREE_OPERAND (decl, 1);
4578   if (TREE_CODE (name) == BIT_NOT_EXPR)
4579     {
4580       cp_error ("using-declaration for destructor");
4581       return NULL_TREE;
4582     }
4583
4584   value = build_lang_field_decl (USING_DECL, name, void_type_node);
4585   DECL_INITIAL (value) = TREE_OPERAND (decl, 0);
4586   return value;
4587 }
4588
4589 /* Process a using-directive. */
4590
4591 void
4592 do_using_directive (namespace)
4593      tree namespace;
4594 {
4595   if (namespace == std_node)
4596     return;
4597   /* using namespace A::B::C; */
4598   if (TREE_CODE (namespace) == SCOPE_REF)
4599       namespace = TREE_OPERAND (namespace, 1);
4600   if (TREE_CODE (namespace) == IDENTIFIER_NODE)
4601     {
4602       /* Lookup in lexer did not find a namespace. */
4603       cp_error ("namespace `%T' undeclared", namespace);
4604       return;
4605     }
4606   if (TREE_CODE (namespace) != NAMESPACE_DECL)
4607     {
4608       cp_error ("`%T' is not a namespace", namespace);
4609       return;
4610     }
4611   namespace = ORIGINAL_NAMESPACE (namespace);
4612   if (!toplevel_bindings_p ())
4613     push_using_directive
4614       (namespace, namespace_ancestor (current_decl_namespace(), 
4615                                       current_namespace));
4616   else
4617     /* direct usage */
4618     add_using_namespace (current_namespace, namespace, 0);
4619 }
4620
4621 void
4622 check_default_args (x)
4623      tree x;
4624 {
4625   tree arg = TYPE_ARG_TYPES (TREE_TYPE (x));
4626   int saw_def = 0, i = 0 - (TREE_CODE (TREE_TYPE (x)) == METHOD_TYPE);
4627   for (; arg && arg != void_list_node; arg = TREE_CHAIN (arg), ++i)
4628     {
4629       if (TREE_PURPOSE (arg))
4630         saw_def = 1;
4631       else if (saw_def)
4632         {
4633           cp_error_at ("default argument missing for parameter %P of `%+#D'",
4634                        i, x);
4635           break;
4636         }
4637     }
4638 }
4639
4640 void
4641 mark_used (decl)
4642      tree decl;
4643 {
4644   TREE_USED (decl) = 1;
4645   if (processing_template_decl)
4646     return;
4647   assemble_external (decl);
4648   /* Is it a synthesized method that needs to be synthesized?  */
4649   if (TREE_CODE (decl) == FUNCTION_DECL && DECL_CLASS_CONTEXT (decl)
4650       && DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl)
4651       /* Kludge: don't synthesize for default args.  */
4652       && current_function_decl)
4653     synthesize_method (decl);
4654   if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
4655     instantiate_decl (decl);
4656 }
4657
4658 /* Helper function for named_class_head_sans_basetype nonterminal.  */
4659
4660 tree
4661 handle_class_head (aggr, scope, id)
4662      tree aggr, scope, id;
4663 {
4664   if (TREE_CODE (id) == TYPE_DECL)
4665     return id;
4666
4667   if (scope)
4668     cp_error ("`%T' does not have a nested type named `%D'", scope, id);
4669   else
4670     cp_error ("no file-scope type named `%D'", id);
4671
4672   id = xref_tag
4673     (aggr, make_anon_name (), NULL_TREE, 1);
4674   return TYPE_MAIN_DECL (id);
4675 }