OSDN Git Service

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