1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001 Free Software Foundation, Inc.
4 Hacked by Michael Tiemann (tiemann@cygnus.com)
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 /* Process declarations and symbol lookup for C front end.
25 Also constructs types; the standard scalar types at initialization,
26 and structure, union, array and enum types when they are declared. */
28 /* ??? not all decl nodes are given the most useful possible
29 line numbers. For example, the CONST_DECLs for enum values. */
44 #include "dwarf2out.h"
49 extern cpp_reader
*parse_in
;
51 /* This structure contains information about the initializations
52 and/or destructions required for a particular priority level. */
53 typedef struct priority_info_s
{
54 /* Non-zero if there have been any initializations at this priority
55 throughout the translation unit. */
56 int initializations_p
;
57 /* Non-zero if there have been any destructions at this priority
58 throughout the translation unit. */
62 static void cxx_post_options
PARAMS ((void));
63 static void mark_vtable_entries
PARAMS ((tree
));
64 static void grok_function_init
PARAMS ((tree
, tree
));
65 static int finish_vtable_vardecl
PARAMS ((tree
*, void *));
66 static int prune_vtable_vardecl
PARAMS ((tree
*, void *));
67 static int is_namespace_ancestor
PARAMS ((tree
, tree
));
68 static void add_using_namespace
PARAMS ((tree
, tree
, int));
69 static tree ambiguous_decl
PARAMS ((tree
, tree
, tree
,int));
70 static tree build_anon_union_vars
PARAMS ((tree
, tree
*, int, int));
71 static int acceptable_java_type
PARAMS ((tree
));
72 static void output_vtable_inherit
PARAMS ((tree
));
73 static tree start_objects
PARAMS ((int, int));
74 static void finish_objects
PARAMS ((int, int, tree
));
75 static tree merge_functions
PARAMS ((tree
, tree
));
76 static tree decl_namespace
PARAMS ((tree
));
77 static tree validate_nonmember_using_decl
PARAMS ((tree
, tree
*, tree
*));
78 static void do_nonmember_using_decl
PARAMS ((tree
, tree
, tree
, tree
,
80 static tree start_static_storage_duration_function
PARAMS ((void));
81 static void finish_static_storage_duration_function
PARAMS ((tree
));
82 static priority_info get_priority_info
PARAMS ((int));
83 static void do_static_initialization
PARAMS ((tree
, tree
));
84 static void do_static_destruction
PARAMS ((tree
));
85 static tree start_static_initialization_or_destruction
PARAMS ((tree
, int));
86 static void finish_static_initialization_or_destruction
PARAMS ((tree
));
87 static void generate_ctor_or_dtor_function
PARAMS ((int, int));
88 static int generate_ctor_and_dtor_functions_for_priority
89 PARAMS ((splay_tree_node
, void *));
90 static tree prune_vars_needing_no_initialization
PARAMS ((tree
));
91 static void write_out_vars
PARAMS ((tree
));
92 static void import_export_class
PARAMS ((tree
));
93 static tree key_method
PARAMS ((tree
));
94 static int compare_options
PARAMS ((const PTR
, const PTR
));
95 static tree get_guard_bits
PARAMS ((tree
));
97 extern int current_class_depth
;
99 /* A list of virtual function tables we must make sure to write out. */
100 tree pending_vtables
;
102 /* A list of static class variables. This is needed, because a
103 static class variable can be declared inside the class without
104 an initializer, and then initialized, staticly, outside the class. */
105 static varray_type pending_statics
;
106 #define pending_statics_used \
107 (pending_statics ? pending_statics->elements_used : 0)
109 /* A list of functions which were declared inline, but which we
110 may need to emit outline anyway. */
111 static varray_type deferred_fns
;
112 #define deferred_fns_used \
113 (deferred_fns ? deferred_fns->elements_used : 0)
115 /* Same, but not reset. Local temp variables and global temp variables
116 can have the same name. */
117 static int global_temp_name_counter
;
119 /* Flag used when debugging spew.c */
121 extern int spew_debug
;
123 /* Nonzero if we're done parsing and into end-of-file activities. */
127 /* Functions called along with real static constructors and destructors. */
132 /* The :: namespace. */
134 tree global_namespace
;
136 /* The stack for namespaces of current declarations. */
138 static tree decl_namespace_list
;
141 /* C (and C++) language-specific option variables. */
143 /* Nonzero means allow type mismatches in conditional expressions;
144 just make their values `void'. */
146 int flag_cond_mismatch
;
148 /* Nonzero means don't recognize the keyword `asm'. */
152 /* Nonzero means don't recognize any extension keywords. */
154 int flag_no_gnu_keywords
;
156 /* Nonzero means do some things the same way PCC does. Only provided so
157 the compiler will link. */
159 int flag_traditional
;
161 /* Nonzero means to treat bitfields as unsigned unless they say `signed'. */
163 int flag_signed_bitfields
= 1;
165 /* Nonzero means enable obscure standard features and disable GNU
166 extensions that might cause standard-compliant code to be
171 /* Nonzero means do emit exported implementations of functions even if
172 they can be inlined. */
174 int flag_implement_inlines
= 1;
176 /* Nonzero means do emit exported implementations of templates, instead of
177 multiple static copies in each file that needs a definition. */
179 int flag_external_templates
;
181 /* Nonzero means that the decision to emit or not emit the implementation of a
182 template depends on where the template is instantiated, rather than where
185 int flag_alt_external_templates
;
187 /* Nonzero means that implicit instantiations will be emitted if needed. */
189 int flag_implicit_templates
= 1;
191 /* Nonzero means that implicit instantiations of inline templates will be
192 emitted if needed, even if instantiations of non-inline templates
195 int flag_implicit_inline_templates
= 1;
197 /* Nonzero means warn about implicit declarations. */
199 int warn_implicit
= 1;
201 /* Nonzero means warn about usage of long long when `-pedantic'. */
203 int warn_long_long
= 1;
205 /* Nonzero means warn when all ctors or dtors are private, and the class
208 int warn_ctor_dtor_privacy
= 1;
210 /* True if we want to implement vtables using "thunks".
211 The default is off. */
213 #ifndef DEFAULT_VTABLE_THUNKS
214 #define DEFAULT_VTABLE_THUNKS 0
216 int flag_vtable_thunks
= DEFAULT_VTABLE_THUNKS
;
218 /* Nonzero means generate separate instantiation control files and juggle
219 them at link time. */
221 int flag_use_repository
;
223 /* Nonzero if we want to issue diagnostics that the standard says are not
226 int flag_optional_diags
= 1;
228 /* Nonzero means give string constants the type `const char *', as mandated
231 int flag_const_strings
= 1;
233 /* Nonzero means warn about deprecated conversion from string constant to
236 int warn_write_strings
;
238 /* Nonzero means warn about pointer casts that can drop a type qualifier
239 from the pointer target type. */
243 /* Nonzero means warn about sizeof(function) or addition/subtraction
244 of function pointers. */
246 int warn_pointer_arith
= 1;
248 /* Nonzero means warn for any function def without prototype decl. */
250 int warn_missing_prototypes
;
252 /* Nonzero means warn about multiple (redundant) decls for the same single
253 variable or function. */
255 int warn_redundant_decls
;
257 /* Warn if initializer is not completely bracketed. */
259 int warn_missing_braces
;
261 /* Warn about comparison of signed and unsigned values. */
263 int warn_sign_compare
;
265 /* Warn about testing equality of floating point numbers. */
267 int warn_float_equal
= 0;
269 /* Warn about functions which might be candidates for format attributes. */
271 int warn_missing_format_attribute
;
273 /* Warn about a subscript that has type char. */
275 int warn_char_subscripts
;
277 /* Warn if a type conversion is done that might have confusing results. */
281 /* Warn if adding () is suggested. */
283 int warn_parentheses
;
285 /* Non-zero means warn in function declared in derived class has the
286 same name as a virtual in the base class, but fails to match the
287 type signature of any virtual function in the base class. */
289 int warn_overloaded_virtual
;
291 /* Non-zero means warn when declaring a class that has a non virtual
292 destructor, when it really ought to have a virtual one. */
296 /* Non-zero means warn when a function is declared extern and later inline. */
298 int warn_extern_inline
;
300 /* Non-zero means warn when the compiler will reorder code. */
304 /* Non-zero means warn when synthesis behavior differs from Cfront's. */
308 /* Non-zero means warn when we convert a pointer to member function
309 into a pointer to (void or function). */
311 int warn_pmf2ptr
= 1;
313 /* Nonzero means warn about violation of some Effective C++ style rules. */
317 /* Nonzero means warn where overload resolution chooses a promotion from
318 unsigned to signed over a conversion to an unsigned of the same size. */
322 /* Nonzero means warn when an old-style cast is used. */
324 int warn_old_style_cast
;
326 /* Warn about #pragma directives that are not recognised. */
328 int warn_unknown_pragmas
; /* Tri state variable. */
330 /* Nonzero means warn about use of multicharacter literals. */
332 int warn_multichar
= 1;
334 /* Nonzero means warn when non-templatized friend functions are
335 declared within a template */
337 int warn_nontemplate_friend
= 1;
339 /* Nonzero means complain about deprecated features. */
341 int warn_deprecated
= 1;
343 /* Nonzero means `$' can be in an identifier. */
345 #ifndef DOLLARS_IN_IDENTIFIERS
346 #define DOLLARS_IN_IDENTIFIERS 1
348 int dollars_in_ident
= DOLLARS_IN_IDENTIFIERS
;
350 /* Nonzero means that labels can be used as first-class objects */
354 /* Nonzero means allow Microsoft extensions without a pedwarn. */
356 int flag_ms_extensions
;
358 /* C++ specific flags. */
359 /* Zero means that `this' is a *const. This gives nice behavior in the
360 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior.
361 -2 means we're constructing an object and it has fixed type. */
363 int flag_this_is_variable
;
365 /* Nonzero means we should attempt to elide constructors when possible. */
367 int flag_elide_constructors
= 1;
369 /* Nonzero means that member functions defined in class scope are
370 inline by default. */
372 int flag_default_inline
= 1;
374 /* Controls whether compiler generates 'type descriptor' that give
375 run-time type information. */
379 /* Nonzero if we wish to output cross-referencing information
380 for the GNU class browser. */
382 extern int flag_gnu_xref
;
384 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
387 int flag_huge_objects
;
389 /* Nonzero if we want to conserve space in the .o files. We do this
390 by putting uninitialized data and runtime initialized data into
391 .common instead of .data at the expense of not flagging multiple
394 int flag_conserve_space
;
396 /* Nonzero if we want to obey access control semantics. */
398 int flag_access_control
= 1;
400 /* Nonzero if we want to understand the operator names, i.e. 'bitand'. */
402 int flag_operator_names
= 1;
404 /* Nonzero if we want to check the return value of new and avoid calling
405 constructors if it is a null pointer. */
409 /* Nonzero if we want the new ISO rules for pushing a new scope for `for'
410 initialization variables.
411 0: Old rules, set by -fno-for-scope.
412 2: New ISO rules, set by -ffor-scope.
413 1: Try to implement new ISO rules, but with backup compatibility
414 (and warnings). This is the default, for now. */
416 int flag_new_for_scope
= 1;
418 /* Nonzero if we want to emit defined symbols with common-like linkage as
419 weak symbols where possible, in order to conform to C++ semantics.
420 Otherwise, emit them as local symbols. */
424 /* Nonzero to enable experimental ABI changes. */
428 /* Nonzero to use __cxa_atexit, rather than atexit, to register
429 destructors for local statics and global objects. */
431 int flag_use_cxa_atexit
;
433 /* Nonzero to not ignore namespace std. */
435 int flag_honor_std
= ENABLE_STD_NAMESPACE
;
437 /* Nonzero if we should expand functions calls inline at the tree
438 level, rather than at the RTL level. */
440 int flag_inline_trees
= 0;
442 /* Maximum template instantiation depth. This limit is rather
443 arbitrary, but it exists to limit the time it takes to notice
444 infinite template instantiations. */
446 int max_tinst_depth
= 50;
448 /* The name-mangling scheme to use. Must be 1 or greater to support
449 template functions with identical types, but different template
451 int name_mangling_version
= 2;
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. */
457 int flag_do_squangling
;
459 /* Nonzero means output .vtable_{entry,inherit} for use in doing vtable gc. */
463 /* Nonzero means make the default pedwarns warnings instead of errors.
464 The value of this flag is ignored if -pedantic is specified. */
468 /* Nonzero means to implement standard semantics for exception
469 specifications, calling unexpected if an exception is thrown that
470 doesn't match the specification. Zero means to treat them as
471 assertions and optimize accordingly, but not check them. */
473 int flag_enforce_eh_specs
= 1;
475 /* The variant of the C language being processed. */
477 c_language_kind c_language
= clk_cplusplus
;
479 /* Table of language-dependent -f options.
480 STRING is the option name. VARIABLE is the address of the variable.
481 ON_VALUE is the value to store in VARIABLE
482 if `-fSTRING' is seen as an option.
483 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
485 static struct { const char *string
; int *variable
; int on_value
;}
489 {"signed-char", &flag_signed_char
, 1},
490 {"unsigned-char", &flag_signed_char
, 0},
491 {"signed-bitfields", &flag_signed_bitfields
, 1},
492 {"unsigned-bitfields", &flag_signed_bitfields
, 0},
493 {"short-enums", &flag_short_enums
, 1},
494 {"short-double", &flag_short_double
, 1},
495 {"short-wchar", &flag_short_wchar
, 1},
496 {"cond-mismatch", &flag_cond_mismatch
, 1},
497 {"asm", &flag_no_asm
, 0},
498 {"builtin", &flag_no_builtin
, 0},
500 /* C++-only options. */
501 {"access-control", &flag_access_control
, 1},
502 {"check-new", &flag_check_new
, 1},
503 {"conserve-space", &flag_conserve_space
, 1},
504 {"const-strings", &flag_const_strings
, 1},
505 {"default-inline", &flag_default_inline
, 1},
506 {"dollars-in-identifiers", &dollars_in_ident
, 1},
507 {"elide-constructors", &flag_elide_constructors
, 1},
508 {"enforce-eh-specs", &flag_enforce_eh_specs
, 1},
509 {"external-templates", &flag_external_templates
, 1},
510 {"for-scope", &flag_new_for_scope
, 2},
511 {"gnu-keywords", &flag_no_gnu_keywords
, 0},
512 {"handle-exceptions", &flag_exceptions
, 1},
513 {"honor-std", &flag_honor_std
, 1},
514 {"huge-objects", &flag_huge_objects
, 1},
515 {"implement-inlines", &flag_implement_inlines
, 1},
516 {"implicit-inline-templates", &flag_implicit_inline_templates
, 1},
517 {"implicit-templates", &flag_implicit_templates
, 1},
518 {"labels-ok", &flag_labels_ok
, 1},
519 {"ms-extensions", &flag_ms_extensions
, 1},
520 {"nonansi-builtins", &flag_no_nonansi_builtin
, 0},
521 {"operator-names", &flag_operator_names
, 1},
522 {"optional-diags", &flag_optional_diags
, 1},
523 {"permissive", &flag_permissive
, 1},
524 {"repo", &flag_use_repository
, 1},
525 {"rtti", &flag_rtti
, 1},
526 {"squangle", &flag_do_squangling
, 1},
527 {"stats", &flag_detailed_statistics
, 1},
528 {"use-cxa-atexit", &flag_use_cxa_atexit
, 1},
529 {"vtable-gc", &flag_vtable_gc
, 1},
530 {"vtable-thunks", &flag_vtable_thunks
, 1},
531 {"weak", &flag_weak
, 1},
532 {"xref", &flag_gnu_xref
, 1}
535 /* The list of `-f' options that we no longer support. The `-f'
536 prefix is not given in this table. The `-fno-' variants are not
537 listed here. This table must be kept in alphabetical order. */
538 static const char * const unsupported_options
[] = {
547 /* Each front end provides its own. */
548 struct lang_hooks lang_hooks
= {cxx_post_options
};
550 /* Post-switch processing. */
554 cpp_post_options (parse_in
);
557 /* Compare two option strings, pointed two by P1 and P2, for use with
561 compare_options (p1
, p2
)
565 return strcmp (*((const char *const *) p1
), *((const char *const *) p2
));
568 /* Decode the string P as a language-specific option.
569 Return the number of strings consumed for a valid option.
570 Otherwise return 0. Should not complain if it does not
571 recognise the option. */
574 lang_decode_option (argc
, argv
)
578 int strings_processed
;
579 const char *p
= argv
[0];
581 strings_processed
= cpp_handle_option (parse_in
, argc
, argv
);
583 if (!strcmp (p
, "-ftraditional") || !strcmp (p
, "-traditional"))
585 else if (p
[0] == '-' && p
[1] == 'f')
587 /* Some kind of -f option.
588 P's value is the option sans `-f'.
589 Search for it in the table of options. */
590 const char *option_value
= NULL
;
591 const char *positive_option
;
595 /* Try special -f options. */
597 /* See if this is one of the options no longer supported. We
598 used to support these options, so we continue to accept them,
600 if (strncmp (p
, "no-", strlen ("no-")) == 0)
601 positive_option
= p
+ strlen ("no-");
605 /* If the option is present, issue a warning. Indicate to our
606 caller that the option was processed successfully. */
607 if (bsearch (&positive_option
,
609 (sizeof (unsupported_options
)
610 / sizeof (unsupported_options
[0])),
611 sizeof (unsupported_options
[0]),
614 warning ("-f%s is no longer supported", p
);
618 if (!strcmp (p
, "handle-exceptions")
619 || !strcmp (p
, "no-handle-exceptions"))
620 warning ("-fhandle-exceptions has been renamed to -fexceptions (and is now on by default)");
621 else if (! strcmp (p
, "alt-external-templates"))
623 flag_external_templates
= 1;
624 flag_alt_external_templates
= 1;
625 cp_deprecated ("-falt-external-templates");
627 else if (! strcmp (p
, "no-alt-external-templates"))
628 flag_alt_external_templates
= 0;
629 else if (!strcmp (p
, "repo"))
631 flag_use_repository
= 1;
632 flag_implicit_templates
= 0;
634 else if (!strcmp (p
, "external-templates"))
636 flag_external_templates
= 1;
637 cp_deprecated ("-fexternal-templates");
639 else if (!strcmp (p
, "new-abi"))
642 flag_do_squangling
= 1;
643 flag_vtable_thunks
= 1;
645 else if (!strcmp (p
, "no-new-abi"))
648 flag_do_squangling
= 0;
650 else if ((option_value
651 = skip_leading_substring (p
, "template-depth-")))
653 = read_integral_parameter (option_value
, p
- 2, max_tinst_depth
);
654 else if ((option_value
655 = skip_leading_substring (p
, "name-mangling-version-")))
656 name_mangling_version
657 = read_integral_parameter (option_value
, p
- 2, name_mangling_version
);
658 else if ((option_value
659 = skip_leading_substring (p
, "dump-translation-unit-")))
662 error ("no file specified with -fdump-translation-unit");
664 flag_dump_translation_unit
= option_value
;
671 !found
&& j
< (sizeof (lang_f_options
)
672 / sizeof (lang_f_options
[0]));
675 if (!strcmp (p
, lang_f_options
[j
].string
))
677 *lang_f_options
[j
].variable
= lang_f_options
[j
].on_value
;
678 /* A goto here would be cleaner,
679 but breaks the vax pcc. */
682 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-'
683 && ! strcmp (p
+3, lang_f_options
[j
].string
))
685 *lang_f_options
[j
].variable
= ! lang_f_options
[j
].on_value
;
693 else if (p
[0] == '-' && p
[1] == 'W')
697 /* The -W options control the warning behavior of the compiler. */
700 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-')
703 if (!strcmp (p
, "implicit"))
704 warn_implicit
= setting
;
705 else if (!strcmp (p
, "long-long"))
706 warn_long_long
= setting
;
707 else if (!strcmp (p
, "return-type"))
708 warn_return_type
= setting
;
709 else if (!strcmp (p
, "ctor-dtor-privacy"))
710 warn_ctor_dtor_privacy
= setting
;
711 else if (!strcmp (p
, "write-strings"))
712 warn_write_strings
= setting
;
713 else if (!strcmp (p
, "cast-qual"))
714 warn_cast_qual
= setting
;
715 else if (!strcmp (p
, "char-subscripts"))
716 warn_char_subscripts
= setting
;
717 else if (!strcmp (p
, "pointer-arith"))
718 warn_pointer_arith
= setting
;
719 else if (!strcmp (p
, "missing-prototypes"))
720 warn_missing_prototypes
= setting
;
721 else if (!strcmp (p
, "strict-prototypes"))
724 warning ("-Wno-strict-prototypes is not supported in C++");
726 else if (!strcmp (p
, "redundant-decls"))
727 warn_redundant_decls
= setting
;
728 else if (!strcmp (p
, "missing-braces"))
729 warn_missing_braces
= setting
;
730 else if (!strcmp (p
, "sign-compare"))
731 warn_sign_compare
= setting
;
732 else if (!strcmp (p
, "float-equal"))
733 warn_float_equal
= setting
;
734 else if (!strcmp (p
, "format"))
735 set_Wformat (setting
);
736 else if (!strcmp (p
, "format-y2k"))
737 warn_format_y2k
= setting
;
738 else if (!strcmp (p
, "format-extra-args"))
739 warn_format_extra_args
= setting
;
740 else if (!strcmp (p
, "format-nonliteral"))
741 warn_format_nonliteral
= setting
;
742 else if (!strcmp (p
, "format-security"))
743 warn_format_security
= setting
;
744 else if (!strcmp (p
, "missing-format-attribute"))
745 warn_missing_format_attribute
= setting
;
746 else if (!strcmp (p
, "conversion"))
747 warn_conversion
= setting
;
748 else if (!strcmp (p
, "parentheses"))
749 warn_parentheses
= setting
;
750 else if (!strcmp (p
, "non-virtual-dtor"))
751 warn_nonvdtor
= setting
;
752 else if (!strcmp (p
, "extern-inline"))
753 warn_extern_inline
= setting
;
754 else if (!strcmp (p
, "reorder"))
755 warn_reorder
= setting
;
756 else if (!strcmp (p
, "synth"))
757 warn_synth
= setting
;
758 else if (!strcmp (p
, "pmf-conversions"))
759 warn_pmf2ptr
= setting
;
760 else if (!strcmp (p
, "effc++"))
762 else if (!strcmp (p
, "sign-promo"))
763 warn_sign_promo
= setting
;
764 else if (!strcmp (p
, "old-style-cast"))
765 warn_old_style_cast
= setting
;
766 else if (!strcmp (p
, "overloaded-virtual"))
767 warn_overloaded_virtual
= setting
;
768 else if (!strcmp (p
, "multichar"))
769 warn_multichar
= setting
;
770 else if (!strcmp (p
, "unknown-pragmas"))
771 /* Set to greater than 1, so that even unknown pragmas in
772 system headers will be warned about. */
773 warn_unknown_pragmas
= setting
* 2;
774 else if (!strcmp (p
, "non-template-friend"))
775 warn_nontemplate_friend
= setting
;
776 else if (!strcmp (p
, "deprecated"))
777 warn_deprecated
= setting
;
778 else if (!strcmp (p
, "comment"))
779 ; /* cpp handles this one. */
780 else if (!strcmp (p
, "comments"))
781 ; /* cpp handles this one. */
782 else if (!strcmp (p
, "trigraphs"))
783 ; /* cpp handles this one. */
784 else if (!strcmp (p
, "import"))
785 ; /* cpp handles this one. */
786 else if (!strcmp (p
, "all"))
788 warn_return_type
= setting
;
789 set_Wunused (setting
);
790 warn_implicit
= setting
;
791 warn_switch
= setting
;
792 set_Wformat (setting
);
793 warn_parentheses
= setting
;
794 warn_missing_braces
= setting
;
795 warn_sign_compare
= setting
;
796 warn_multichar
= setting
;
797 /* We save the value of warn_uninitialized, since if they put
798 -Wuninitialized on the command line, we need to generate a
799 warning about not using it without also specifying -O. */
800 if (warn_uninitialized
!= 1)
801 warn_uninitialized
= (setting
? 2 : 0);
802 /* Only warn about unknown pragmas that are not in system
804 warn_unknown_pragmas
= 1;
806 /* C++-specific warnings. */
807 warn_ctor_dtor_privacy
= setting
;
808 warn_nonvdtor
= setting
;
809 warn_reorder
= setting
;
810 warn_nontemplate_friend
= setting
;
812 else return strings_processed
;
814 else if (!strcmp (p
, "-ansi"))
815 flag_no_nonansi_builtin
= 1, flag_ansi
= 1,
816 flag_noniso_default_format_attributes
= 0, flag_no_gnu_keywords
= 1;
818 /* Undocumented, only ever used when you're invoking cc1plus by hand, since
819 it's probably safe to assume no sane person would ever want to use this
820 under normal circumstances. */
821 else if (!strcmp (p
, "-spew-debug"))
825 return strings_processed
;
830 /* Incorporate `const' and `volatile' qualifiers for member functions.
831 FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
832 QUALS is a list of qualifiers. Returns any explicit
833 top-level qualifiers of the method's this pointer, anything other than
834 TYPE_UNQUALIFIED will be an extension. */
837 grok_method_quals (ctype
, function
, quals
)
838 tree ctype
, function
, quals
;
840 tree fntype
= TREE_TYPE (function
);
841 tree raises
= TYPE_RAISES_EXCEPTIONS (fntype
);
842 int type_quals
= TYPE_UNQUALIFIED
;
843 int dup_quals
= TYPE_UNQUALIFIED
;
844 int this_quals
= TYPE_UNQUALIFIED
;
848 int tq
= cp_type_qual_from_rid (TREE_VALUE (quals
));
850 if ((type_quals
| this_quals
) & tq
)
852 else if (tq
& TYPE_QUAL_RESTRICT
)
856 quals
= TREE_CHAIN (quals
);
860 if (dup_quals
!= TYPE_UNQUALIFIED
)
861 cp_error ("duplicate type qualifiers in %s declaration",
862 TREE_CODE (function
) == FUNCTION_DECL
863 ? "member function" : "type");
865 ctype
= cp_build_qualified_type (ctype
, type_quals
);
866 fntype
= build_cplus_method_type (ctype
, TREE_TYPE (fntype
),
867 (TREE_CODE (fntype
) == METHOD_TYPE
868 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype
))
869 : TYPE_ARG_TYPES (fntype
)));
871 fntype
= build_exception_variant (fntype
, raises
);
873 TREE_TYPE (function
) = fntype
;
877 /* Warn when -fexternal-templates is used and #pragma
878 interface/implementation is not used all the times it should be,
882 warn_if_unknown_interface (decl
)
885 static int already_warned
= 0;
886 if (already_warned
++)
889 if (flag_alt_external_templates
)
891 tree til
= tinst_for_decl ();
893 const char *sf
= input_filename
;
897 lineno
= TINST_LINE (til
);
898 input_filename
= TINST_FILE (til
);
900 cp_warning ("template `%#D' instantiated in file without #pragma interface",
906 cp_warning_at ("template `%#D' defined in file without #pragma interface",
910 /* A subroutine of the parser, to handle a component list. */
913 grok_x_components (specs
)
918 specs
= strip_attrs (specs
);
920 check_tag_decl (specs
);
921 t
= groktypename (build_tree_list (specs
, NULL_TREE
));
923 /* The only case where we need to do anything additional here is an
924 anonymous union field, e.g.: `struct S { union { int i; }; };'. */
925 if (t
== NULL_TREE
|| !ANON_AGGR_TYPE_P (t
))
928 fixup_anonymous_aggr (t
);
929 finish_member_declaration (build_decl (FIELD_DECL
, NULL_TREE
, t
));
932 /* Returns a PARM_DECL for a parameter of the indicated TYPE, with the
936 build_artificial_parm (name
, type
)
942 parm
= build_decl (PARM_DECL
, name
, type
);
943 DECL_ARTIFICIAL (parm
) = 1;
944 DECL_ARG_TYPE (parm
) = type
;
948 /* Constructors for types with virtual baseclasses need an "in-charge" flag
949 saying whether this constructor is responsible for initialization of
950 virtual baseclasses or not. All destructors also need this "in-charge"
951 flag, which additionally determines whether or not the destructor should
952 free the memory for the object.
954 This function adds the "in-charge" flag to member function FN if
955 appropriate. It is called from grokclassfn and tsubst.
956 FN must be either a constructor or destructor. */
959 maybe_retrofit_in_chrg (fn
)
962 tree basetype
, arg_types
, parms
, parm
, fntype
;
964 /* If we've already add the in-charge parameter don't do it again. */
965 if (DECL_HAS_IN_CHARGE_PARM_P (fn
))
968 /* When processing templates we can't know, in general, whether or
969 not we're going to have virtual baseclasses. */
970 if (uses_template_parms (fn
))
973 /* We don't need an in-charge parameter for constructors that don't
974 have virtual bases. */
975 if (DECL_CONSTRUCTOR_P (fn
)
976 && !TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn
)))
979 /* First add it to DECL_ARGUMENTS... */
980 parm
= build_artificial_parm (in_charge_identifier
, integer_type_node
);
981 TREE_READONLY (parm
) = 1;
982 parms
= DECL_ARGUMENTS (fn
);
983 TREE_CHAIN (parm
) = TREE_CHAIN (parms
);
984 TREE_CHAIN (parms
) = parm
;
986 /* ...and then to TYPE_ARG_TYPES. */
987 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
988 basetype
= TREE_TYPE (TREE_VALUE (arg_types
));
989 arg_types
= hash_tree_chain (integer_type_node
, TREE_CHAIN (arg_types
));
990 fntype
= build_cplus_method_type (basetype
, TREE_TYPE (TREE_TYPE (fn
)),
992 if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn
)))
993 fntype
= build_exception_variant (fntype
,
994 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn
)));
995 TREE_TYPE (fn
) = fntype
;
997 /* Now we've got the in-charge parameter. */
998 DECL_HAS_IN_CHARGE_PARM_P (fn
) = 1;
1000 /* If this is a subobject constructor or destructor, our caller will
1001 pass us a pointer to our VTT. */
1002 if (flag_new_abi
&& TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn
)))
1004 DECL_VTT_PARM (fn
) = build_artificial_parm (vtt_parm_identifier
,
1006 DECL_CONTEXT (DECL_VTT_PARM (fn
)) = fn
;
1007 DECL_USE_VTT_PARM (fn
) = build_artificial_parm (NULL_TREE
,
1009 DECL_CONTEXT (DECL_USE_VTT_PARM (fn
)) = fn
;
1013 /* Classes overload their constituent function names automatically.
1014 When a function name is declared in a record structure,
1015 its name is changed to it overloaded name. Since names for
1016 constructors and destructors can conflict, we place a leading
1017 '$' for destructors.
1019 CNAME is the name of the class we are grokking for.
1021 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
1023 FLAGS contains bits saying what's special about today's
1024 arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
1026 If FUNCTION is a destructor, then we must add the `auto-delete' field
1027 as a second parameter. There is some hair associated with the fact
1028 that we must "declare" this variable in the manner consistent with the
1029 way the rest of the arguments were declared.
1031 QUALS are the qualifiers for the this pointer. */
1034 grokclassfn (ctype
, function
, flags
, quals
)
1035 tree ctype
, function
;
1036 enum overload_flags flags
;
1039 tree fn_name
= DECL_NAME (function
);
1040 int this_quals
= TYPE_UNQUALIFIED
;
1042 /* Even within an `extern "C"' block, members get C++ linkage. See
1043 [dcl.link] for details. */
1044 DECL_LANGUAGE (function
) = lang_cplusplus
;
1046 if (fn_name
== NULL_TREE
)
1048 error ("name missing for member function");
1049 fn_name
= get_identifier ("<anonymous>");
1050 DECL_NAME (function
) = fn_name
;
1054 this_quals
= grok_method_quals (ctype
, function
, quals
);
1056 if (TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
1058 /* Must add the class instance variable up front. */
1059 /* Right now we just make this a pointer. But later
1060 we may wish to make it special. */
1061 tree type
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (function
)));
1065 /* The `this' parameter is implicitly `const'; it cannot be
1067 this_quals
|= TYPE_QUAL_CONST
;
1068 qual_type
= cp_build_qualified_type (type
, this_quals
);
1069 parm
= build_artificial_parm (this_identifier
, qual_type
);
1070 c_apply_type_quals_to_decl (this_quals
, parm
);
1072 /* We can make this a register, so long as we don't
1073 accidentally complain if someone tries to take its address. */
1074 DECL_REGISTER (parm
) = 1;
1075 TREE_CHAIN (parm
) = last_function_parms
;
1076 last_function_parms
= parm
;
1079 DECL_ARGUMENTS (function
) = last_function_parms
;
1080 DECL_CONTEXT (function
) = ctype
;
1082 if (flags
== DTOR_FLAG
|| DECL_CONSTRUCTOR_P (function
))
1083 maybe_retrofit_in_chrg (function
);
1085 if (flags
== DTOR_FLAG
)
1087 DECL_DESTRUCTOR_P (function
) = 1;
1090 set_mangled_name_for_decl (function
);
1092 DECL_ASSEMBLER_NAME (function
) = build_destructor_name (ctype
);
1094 TYPE_HAS_DESTRUCTOR (ctype
) = 1;
1097 set_mangled_name_for_decl (function
);
1100 /* Work on the expr used by alignof (this is only called by the parser). */
1109 if (processing_template_decl
)
1110 return build_min (ALIGNOF_EXPR
, sizetype
, expr
);
1112 if (TREE_CODE (expr
) == COMPONENT_REF
1113 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
, 1)))
1114 error ("`__alignof__' applied to a bit-field");
1116 if (TREE_CODE (expr
) == INDIRECT_REF
)
1118 best
= t
= TREE_OPERAND (expr
, 0);
1119 bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
1121 while (TREE_CODE (t
) == NOP_EXPR
1122 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
1125 t
= TREE_OPERAND (t
, 0);
1126 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
1127 if (thisalign
> bestalign
)
1128 best
= t
, bestalign
= thisalign
;
1130 return c_alignof (TREE_TYPE (TREE_TYPE (best
)));
1133 return c_alignof (TREE_TYPE (expr
));
1136 /* Create an ARRAY_REF, checking for the user doing things backwards
1140 grok_array_decl (array_expr
, index_exp
)
1141 tree array_expr
, index_exp
;
1143 tree type
= TREE_TYPE (array_expr
);
1144 tree p1
, p2
, i1
, i2
;
1146 if (type
== error_mark_node
|| index_exp
== error_mark_node
)
1147 return error_mark_node
;
1148 if (processing_template_decl
)
1149 return build_min (ARRAY_REF
, type
? TREE_TYPE (type
) : NULL_TREE
,
1150 array_expr
, index_exp
);
1152 if (type
== NULL_TREE
)
1154 /* Something has gone very wrong. Assume we are mistakenly reducing
1155 an expression instead of a declaration. */
1156 error ("parser may be lost: is there a '{' missing somewhere?");
1160 if (TREE_CODE (type
) == OFFSET_TYPE
1161 || TREE_CODE (type
) == REFERENCE_TYPE
)
1162 type
= TREE_TYPE (type
);
1164 /* If they have an `operator[]', use that. */
1165 if (IS_AGGR_TYPE (type
) || IS_AGGR_TYPE (TREE_TYPE (index_exp
)))
1166 return build_opfncall (ARRAY_REF
, LOOKUP_NORMAL
,
1167 array_expr
, index_exp
, NULL_TREE
);
1169 /* Otherwise, create an ARRAY_REF for a pointer or array type. It
1170 is a little-known fact that, if `a' is an array and `i' is an
1171 int, you can write `i[a]', which means the same thing as `a[i]'. */
1173 if (TREE_CODE (type
) == ARRAY_TYPE
)
1176 p1
= build_expr_type_conversion (WANT_POINTER
, array_expr
, 0);
1178 if (TREE_CODE (TREE_TYPE (index_exp
)) == ARRAY_TYPE
)
1181 p2
= build_expr_type_conversion (WANT_POINTER
, index_exp
, 0);
1183 i1
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, array_expr
, 0);
1184 i2
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, index_exp
, 0);
1186 if ((p1
&& i2
) && (i1
&& p2
))
1187 error ("ambiguous conversion for array subscript");
1190 array_expr
= p1
, index_exp
= i2
;
1192 array_expr
= p2
, index_exp
= i1
;
1195 cp_error ("invalid types `%T[%T]' for array subscript",
1196 type
, TREE_TYPE (index_exp
));
1197 return error_mark_node
;
1200 if (array_expr
== error_mark_node
|| index_exp
== error_mark_node
)
1201 error ("ambiguous conversion for array subscript");
1203 return build_array_ref (array_expr
, index_exp
);
1206 /* Given the cast expression EXP, checking out its validity. Either return
1207 an error_mark_node if there was an unavoidable error, return a cast to
1208 void for trying to delete a pointer w/ the value 0, or return the
1209 call to delete. If DOING_VEC is 1, we handle things differently
1210 for doing an array delete. If DOING_VEC is 2, they gave us the
1211 array size as an argument to delete.
1212 Implements ARM $5.3.4. This is called from the parser. */
1215 delete_sanity (exp
, size
, doing_vec
, use_global_delete
)
1217 int doing_vec
, use_global_delete
;
1220 /* For a regular vector delete (aka, no size argument) we will pass
1221 this down as a NULL_TREE into build_vec_delete. */
1222 tree maxindex
= NULL_TREE
;
1224 if (exp
== error_mark_node
)
1227 if (processing_template_decl
)
1229 t
= build_min (DELETE_EXPR
, void_type_node
, exp
, size
);
1230 DELETE_EXPR_USE_GLOBAL (t
) = use_global_delete
;
1231 DELETE_EXPR_USE_VEC (t
) = doing_vec
;
1235 if (TREE_CODE (exp
) == OFFSET_REF
)
1236 exp
= resolve_offset_ref (exp
);
1237 exp
= convert_from_reference (exp
);
1238 t
= stabilize_reference (exp
);
1239 t
= build_expr_type_conversion (WANT_POINTER
, t
, 1);
1241 if (t
== NULL_TREE
|| t
== error_mark_node
)
1243 cp_error ("type `%#T' argument given to `delete', expected pointer",
1245 return error_mark_node
;
1250 maxindex
= cp_build_binary_op (MINUS_EXPR
, size
, integer_one_node
);
1251 pedwarn ("anachronistic use of array size in vector delete");
1254 type
= TREE_TYPE (t
);
1256 /* As of Valley Forge, you can delete a pointer to const. */
1258 /* You can't delete functions. */
1259 if (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
1261 error ("cannot delete a function. Only pointer-to-objects are valid arguments to `delete'");
1262 return error_mark_node
;
1265 /* Deleting ptr to void is undefined behaviour [expr.delete/3]. */
1266 if (TREE_CODE (TREE_TYPE (type
)) == VOID_TYPE
)
1268 cp_warning ("deleting `%T' is undefined", type
);
1272 /* An array can't have been allocated by new, so complain. */
1273 if (TREE_CODE (t
) == ADDR_EXPR
1274 && TREE_CODE (TREE_OPERAND (t
, 0)) == VAR_DECL
1275 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == ARRAY_TYPE
)
1276 cp_warning ("deleting array `%#D'", TREE_OPERAND (t
, 0));
1278 /* Deleting a pointer with the value zero is valid and has no effect. */
1279 if (integer_zerop (t
))
1280 return build1 (NOP_EXPR
, void_type_node
, t
);
1283 return build_vec_delete (t
, maxindex
, sfk_deleting_destructor
,
1287 if (IS_AGGR_TYPE (TREE_TYPE (type
))
1288 && TYPE_GETS_REG_DELETE (TREE_TYPE (type
)))
1290 /* Only do access checking here; we'll be calling op delete
1291 from the destructor. */
1292 tree tmp
= build_op_delete_call (DELETE_EXPR
, t
, size_zero_node
,
1293 LOOKUP_NORMAL
, NULL_TREE
);
1294 if (tmp
== error_mark_node
)
1295 return error_mark_node
;
1298 return build_delete (type
, t
, sfk_deleting_destructor
,
1299 LOOKUP_NORMAL
, use_global_delete
);
1303 /* Report an error if the indicated template declaration is not the
1304 sort of thing that should be a member template. */
1307 check_member_template (tmpl
)
1312 my_friendly_assert (TREE_CODE (tmpl
) == TEMPLATE_DECL
, 0);
1313 decl
= DECL_TEMPLATE_RESULT (tmpl
);
1315 if (TREE_CODE (decl
) == FUNCTION_DECL
1316 || (TREE_CODE (decl
) == TYPE_DECL
1317 && IS_AGGR_TYPE (TREE_TYPE (decl
))))
1319 if (current_function_decl
)
1320 /* 14.5.2.2 [temp.mem]
1322 A local class shall not have member templates. */
1323 cp_error ("invalid declaration of member template `%#D' in local class",
1326 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (decl
))
1328 /* 14.5.2.3 [temp.mem]
1330 A member function template shall not be virtual. */
1332 ("invalid use of `virtual' in template declaration of `%#D'",
1334 DECL_VIRTUAL_P (decl
) = 0;
1337 /* The debug-information generating code doesn't know what to do
1338 with member templates. */
1339 DECL_IGNORED_P (tmpl
) = 1;
1342 cp_error ("template declaration of `%#D'", decl
);
1345 /* Return true iff TYPE is a valid Java parameter or return type. */
1348 acceptable_java_type (type
)
1351 if (TREE_CODE (type
) == VOID_TYPE
|| TYPE_FOR_JAVA (type
))
1353 if (TREE_CODE (type
) == POINTER_TYPE
)
1355 type
= TREE_TYPE (type
);
1356 if (TREE_CODE (type
) == RECORD_TYPE
)
1359 if (! TYPE_FOR_JAVA (type
))
1361 if (! CLASSTYPE_TEMPLATE_INFO (type
))
1363 args
= CLASSTYPE_TI_ARGS (type
);
1364 i
= TREE_VEC_LENGTH (args
);
1367 type
= TREE_VEC_ELT (args
, i
);
1368 if (TREE_CODE (type
) == POINTER_TYPE
)
1369 type
= TREE_TYPE (type
);
1370 if (! TYPE_FOR_JAVA (type
))
1379 /* For a METHOD in a Java class CTYPE, return 1 if
1380 the parameter and return types are valid Java types.
1381 Otherwise, print appropriate error messages, and return 0. */
1384 check_java_method (method
)
1388 tree arg_types
= TYPE_ARG_TYPES (TREE_TYPE (method
));
1389 tree ret_type
= TREE_TYPE (TREE_TYPE (method
));
1390 if (! acceptable_java_type (ret_type
))
1392 cp_error ("Java method '%D' has non-Java return type `%T'",
1396 for (; arg_types
!= NULL_TREE
; arg_types
= TREE_CHAIN (arg_types
))
1398 tree type
= TREE_VALUE (arg_types
);
1399 if (! acceptable_java_type (type
))
1401 cp_error ("Java method '%D' has non-Java parameter type `%T'",
1406 return jerr
? 0 : 1;
1409 /* Sanity check: report error if this function FUNCTION is not
1410 really a member of the class (CTYPE) it is supposed to belong to.
1411 CNAME is the same here as it is for grokclassfn above. */
1414 check_classfn (ctype
, function
)
1415 tree ctype
, function
;
1417 tree fn_name
= DECL_NAME (function
);
1418 tree fndecl
, fndecls
;
1419 tree method_vec
= CLASSTYPE_METHOD_VEC (complete_type (ctype
));
1423 if (DECL_USE_TEMPLATE (function
)
1424 && !(TREE_CODE (function
) == TEMPLATE_DECL
1425 && DECL_TEMPLATE_SPECIALIZATION (function
))
1426 && is_member_template (DECL_TI_TEMPLATE (function
)))
1427 /* Since this is a specialization of a member template,
1428 we're not going to find the declaration in the class.
1431 struct S { template <typename T> void f(T); };
1432 template <> void S::f(int);
1434 we're not going to find `S::f(int)', but there's no
1435 reason we should, either. We let our callers know we didn't
1436 find the method, but we don't complain. */
1439 if (method_vec
!= 0)
1441 methods
= &TREE_VEC_ELT (method_vec
, 0);
1442 end
= TREE_VEC_END (method_vec
);
1444 /* First suss out ctors and dtors. */
1445 if (*methods
&& fn_name
== DECL_NAME (OVL_CURRENT (*methods
))
1446 && DECL_CONSTRUCTOR_P (function
))
1448 if (*++methods
&& fn_name
== DECL_NAME (OVL_CURRENT (*methods
))
1449 && DECL_DESTRUCTOR_P (function
))
1452 while (++methods
!= end
&& *methods
)
1455 if (fn_name
== DECL_NAME (OVL_CURRENT (*methods
)))
1458 for (fndecls
= *methods
; fndecls
!= NULL_TREE
;
1459 fndecls
= OVL_NEXT (fndecls
))
1461 fndecl
= OVL_CURRENT (fndecls
);
1462 /* The DECL_ASSEMBLER_NAME for a TEMPLATE_DECL, or
1463 for a for member function of a template class, is
1464 not mangled, so the check below does not work
1465 correctly in that case. Since mangled destructor
1466 names do not include the type of the arguments,
1467 we can't use this short-cut for them, either.
1468 (It's not legal to declare arguments for a
1469 destructor, but some people try.) */
1470 if (!DECL_DESTRUCTOR_P (function
)
1471 && (DECL_ASSEMBLER_NAME (function
)
1472 != DECL_NAME (function
))
1473 && (DECL_ASSEMBLER_NAME (fndecl
)
1474 != DECL_NAME (fndecl
))
1475 && (DECL_ASSEMBLER_NAME (function
)
1476 == DECL_ASSEMBLER_NAME (fndecl
)))
1479 /* We cannot simply call decls_match because this
1480 doesn't work for static member functions that are
1481 pretending to be methods, and because the name
1482 may have been changed by asm("new_name"). */
1483 if (DECL_NAME (function
) == DECL_NAME (fndecl
))
1485 tree p1
= TYPE_ARG_TYPES (TREE_TYPE (function
));
1486 tree p2
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
1488 /* Get rid of the this parameter on functions that become
1490 if (DECL_STATIC_FUNCTION_P (fndecl
)
1491 && TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
1492 p1
= TREE_CHAIN (p1
);
1494 if (same_type_p (TREE_TYPE (TREE_TYPE (function
)),
1495 TREE_TYPE (TREE_TYPE (fndecl
)))
1496 && compparms (p1
, p2
)
1497 && (DECL_TEMPLATE_SPECIALIZATION (function
)
1498 == DECL_TEMPLATE_SPECIALIZATION (fndecl
))
1499 && (!DECL_TEMPLATE_SPECIALIZATION (function
)
1500 || (DECL_TI_TEMPLATE (function
)
1501 == DECL_TI_TEMPLATE (fndecl
))))
1510 if (methods
!= end
&& *methods
)
1512 tree fndecl
= *methods
;
1513 cp_error ("prototype for `%#D' does not match any in class `%T'",
1515 cp_error_at ("candidate%s: %+#D", OVL_NEXT (fndecl
) ? "s are" : " is",
1516 OVL_CURRENT (fndecl
));
1517 while (fndecl
= OVL_NEXT (fndecl
), fndecl
)
1518 cp_error_at (" %#D", OVL_CURRENT(fndecl
));
1523 if (!COMPLETE_TYPE_P (ctype
))
1524 incomplete_type_error (function
, ctype
);
1526 cp_error ("no `%#D' member function declared in class `%T'",
1530 /* If we did not find the method in the class, add it to avoid
1531 spurious errors (unless the CTYPE is not yet defined, in which
1532 case we'll only confuse ourselves when the function is declared
1533 properly within the class. */
1534 if (COMPLETE_TYPE_P (ctype
))
1535 add_method (ctype
, function
, /*error_p=*/1);
1539 /* We have just processed the DECL, which is a static data member.
1540 Its initializer, if present, is INIT. The ASMSPEC_TREE, if
1541 present, is the assembly-language name for the data member.
1542 FLAGS is as for cp_finish_decl. */
1545 finish_static_data_member_decl (decl
, init
, asmspec_tree
, flags
)
1551 const char *asmspec
= 0;
1554 asmspec
= TREE_STRING_POINTER (asmspec_tree
);
1556 my_friendly_assert (TREE_PUBLIC (decl
), 0);
1558 DECL_CONTEXT (decl
) = current_class_type
;
1560 /* We cannot call pushdecl here, because that would fill in the
1561 decl of our TREE_CHAIN. Instead, we modify cp_finish_decl to do
1562 the right thing, namely, to put this decl out straight away. */
1563 /* current_class_type can be NULL_TREE in case of error. */
1564 if (!asmspec
&& current_class_type
)
1566 DECL_INITIAL (decl
) = error_mark_node
;
1568 DECL_ASSEMBLER_NAME (decl
) = mangle_decl (decl
);
1570 DECL_ASSEMBLER_NAME (decl
)
1571 = build_static_name (current_class_type
, DECL_NAME (decl
));
1573 if (! processing_template_decl
)
1575 if (!pending_statics
)
1576 VARRAY_TREE_INIT (pending_statics
, 32, "pending_statics");
1577 VARRAY_PUSH_TREE (pending_statics
, decl
);
1580 /* Static consts need not be initialized in the class definition. */
1581 if (init
!= NULL_TREE
&& TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl
)))
1583 static int explained
= 0;
1585 error ("initializer invalid for static member with constructor");
1588 error ("(an out of class initialization is required)");
1593 /* Force the compiler to know when an uninitialized static const
1594 member is being used. */
1595 if (CP_TYPE_CONST_P (TREE_TYPE (decl
)) && init
== 0)
1596 TREE_USED (decl
) = 1;
1597 DECL_INITIAL (decl
) = init
;
1598 DECL_IN_AGGR_P (decl
) = 1;
1600 cp_finish_decl (decl
, init
, asmspec_tree
, flags
);
1603 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
1604 of a structure component, returning a _DECL node.
1605 QUALS is a list of type qualifiers for this decl (such as for declaring
1606 const member functions).
1608 This is done during the parsing of the struct declaration.
1609 The _DECL nodes are chained together and the lot of them
1610 are ultimately passed to `build_struct' to make the RECORD_TYPE node.
1612 If class A defines that certain functions in class B are friends, then
1613 the way I have set things up, it is B who is interested in permission
1614 granted by A. However, it is in A's context that these declarations
1615 are parsed. By returning a void_type_node, class A does not attempt
1616 to incorporate the declarations of the friends within its structure.
1618 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
1619 CHANGES TO CODE IN `start_method'. */
1622 grokfield (declarator
, declspecs
, init
, asmspec_tree
, attrlist
)
1623 tree declarator
, declspecs
, init
, asmspec_tree
, attrlist
;
1625 register tree value
;
1626 const char *asmspec
= 0;
1627 int flags
= LOOKUP_ONLYCONVERTING
;
1629 /* Convert () initializers to = initializers. */
1630 if (init
== NULL_TREE
&& declarator
!= NULL_TREE
1631 && TREE_CODE (declarator
) == CALL_EXPR
1632 && TREE_OPERAND (declarator
, 0)
1633 && (TREE_CODE (TREE_OPERAND (declarator
, 0)) == IDENTIFIER_NODE
1634 || TREE_CODE (TREE_OPERAND (declarator
, 0)) == SCOPE_REF
)
1635 && parmlist_is_exprlist (CALL_DECLARATOR_PARMS (declarator
)))
1637 /* It's invalid to try to initialize a data member using a
1638 functional notation, e.g.:
1644 Explain that to the user. */
1645 static int explained
;
1647 cp_error ("invalid data member initialization");
1650 cp_error ("(use `=' to initialize static data members)");
1654 declarator
= TREE_OPERAND (declarator
, 0);
1658 if (declspecs
== NULL_TREE
1659 && TREE_CODE (declarator
) == SCOPE_REF
1660 && TREE_CODE (TREE_OPERAND (declarator
, 1)) == IDENTIFIER_NODE
)
1662 /* Access declaration */
1663 if (! IS_AGGR_TYPE_CODE (TREE_CODE (TREE_OPERAND (declarator
, 0))))
1665 else if (TREE_COMPLEXITY (declarator
) == current_class_depth
)
1666 pop_nested_class ();
1667 return do_class_using_decl (declarator
);
1671 && TREE_CODE (init
) == TREE_LIST
1672 && TREE_VALUE (init
) == error_mark_node
1673 && TREE_CHAIN (init
) == NULL_TREE
)
1676 value
= grokdeclarator (declarator
, declspecs
, FIELD
, init
!= 0, attrlist
);
1677 if (! value
|| value
== error_mark_node
)
1678 /* friend or constructor went bad. */
1680 if (TREE_TYPE (value
) == error_mark_node
)
1681 return error_mark_node
;
1683 /* Pass friendly classes back. */
1684 if (TREE_CODE (value
) == VOID_TYPE
)
1685 return void_type_node
;
1687 if (DECL_NAME (value
) != NULL_TREE
1688 && IDENTIFIER_POINTER (DECL_NAME (value
))[0] == '_'
1689 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value
)), "_vptr"))
1690 cp_error ("member `%D' conflicts with virtual function table field name",
1693 /* Stash away type declarations. */
1694 if (TREE_CODE (value
) == TYPE_DECL
)
1696 DECL_NONLOCAL (value
) = 1;
1697 DECL_CONTEXT (value
) = current_class_type
;
1699 if (CLASS_TYPE_P (TREE_TYPE (value
)))
1700 CLASSTYPE_GOT_SEMICOLON (TREE_TYPE (value
)) = 1;
1702 /* Now that we've updated the context, we need to remangle the
1703 name for this TYPE_DECL. */
1704 DECL_ASSEMBLER_NAME (value
) = DECL_NAME (value
);
1705 if (!uses_template_parms (value
))
1708 DECL_ASSEMBLER_NAME (value
) = mangle_type (TREE_TYPE (value
));
1710 DECL_ASSEMBLER_NAME (value
) =
1711 get_identifier (build_overload_name (TREE_TYPE (value
), 1, 1));
1714 if (processing_template_decl
)
1715 value
= push_template_decl (value
);
1720 if (DECL_IN_AGGR_P (value
))
1722 cp_error ("`%D' is already defined in `%T'", value
,
1723 DECL_CONTEXT (value
));
1724 return void_type_node
;
1728 asmspec
= TREE_STRING_POINTER (asmspec_tree
);
1732 if (TREE_CODE (value
) == FUNCTION_DECL
)
1734 grok_function_init (value
, init
);
1737 else if (pedantic
&& TREE_CODE (value
) != VAR_DECL
)
1738 /* Already complained in grokdeclarator. */
1742 /* We allow initializers to become parameters to base
1744 if (TREE_CODE (init
) == TREE_LIST
)
1746 if (TREE_CHAIN (init
) == NULL_TREE
)
1747 init
= TREE_VALUE (init
);
1749 init
= digest_init (TREE_TYPE (value
), init
, (tree
*)0);
1752 if (TREE_CODE (init
) == CONST_DECL
)
1753 init
= DECL_INITIAL (init
);
1754 else if (TREE_READONLY_DECL_P (init
))
1755 init
= decl_constant_value (init
);
1756 else if (TREE_CODE (init
) == CONSTRUCTOR
)
1757 init
= digest_init (TREE_TYPE (value
), init
, (tree
*)0);
1758 if (init
== error_mark_node
)
1759 /* We must make this look different than `error_mark_node'
1760 because `decl_const_value' would mis-interpret it
1761 as only meaning that this VAR_DECL is defined. */
1762 init
= build1 (NOP_EXPR
, TREE_TYPE (value
), init
);
1763 else if (processing_template_decl
)
1765 else if (! TREE_CONSTANT (init
))
1767 /* We can allow references to things that are effectively
1768 static, since references are initialized with the address. */
1769 if (TREE_CODE (TREE_TYPE (value
)) != REFERENCE_TYPE
1770 || (TREE_STATIC (init
) == 0
1771 && (!DECL_P (init
) || DECL_EXTERNAL (init
) == 0)))
1773 error ("field initializer is not constant");
1774 init
= error_mark_node
;
1780 if (processing_template_decl
&& ! current_function_decl
1781 && (TREE_CODE (value
) == VAR_DECL
|| TREE_CODE (value
) == FUNCTION_DECL
))
1782 value
= push_template_decl (value
);
1785 cplus_decl_attributes (value
, TREE_PURPOSE (attrlist
),
1786 TREE_VALUE (attrlist
));
1788 if (TREE_CODE (value
) == VAR_DECL
)
1790 finish_static_data_member_decl (value
, init
, asmspec_tree
,
1794 if (TREE_CODE (value
) == FIELD_DECL
)
1798 /* This must override the asm specifier which was placed
1799 by grokclassfn. Lay this out fresh. */
1800 DECL_RTL (value
) = NULL_RTX
;
1801 DECL_ASSEMBLER_NAME (value
) = get_identifier (asmspec
);
1803 if (DECL_INITIAL (value
) == error_mark_node
)
1804 init
= error_mark_node
;
1805 cp_finish_decl (value
, init
, asmspec_tree
, flags
);
1806 DECL_INITIAL (value
) = init
;
1807 DECL_IN_AGGR_P (value
) = 1;
1810 if (TREE_CODE (value
) == FUNCTION_DECL
)
1814 /* This must override the asm specifier which was placed
1815 by grokclassfn. Lay this out fresh. */
1816 DECL_RTL (value
) = NULL_RTX
;
1817 DECL_ASSEMBLER_NAME (value
) = get_identifier (asmspec
);
1819 cp_finish_decl (value
, init
, asmspec_tree
, flags
);
1821 /* Pass friends back this way. */
1822 if (DECL_FRIEND_P (value
))
1823 return void_type_node
;
1825 DECL_IN_AGGR_P (value
) = 1;
1828 my_friendly_abort (21);
1833 /* Like `grokfield', but for bitfields.
1834 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1837 grokbitfield (declarator
, declspecs
, width
)
1838 tree declarator
, declspecs
, width
;
1840 register tree value
= grokdeclarator (declarator
, declspecs
, BITFIELD
,
1843 if (! value
) return NULL_TREE
; /* friends went bad. */
1845 /* Pass friendly classes back. */
1846 if (TREE_CODE (value
) == VOID_TYPE
)
1847 return void_type_node
;
1849 if (TREE_CODE (value
) == TYPE_DECL
)
1851 cp_error ("cannot declare `%D' to be a bitfield type", value
);
1855 /* Usually, finish_struct_1 catches bitifields with invalid types.
1856 But, in the case of bitfields with function type, we confuse
1857 ourselves into thinking they are member functions, so we must
1859 if (TREE_CODE (value
) == FUNCTION_DECL
)
1861 cp_error ("cannot declare bitfield `%D' with funcion type",
1866 if (DECL_IN_AGGR_P (value
))
1868 cp_error ("`%D' is already defined in the class %T", value
,
1869 DECL_CONTEXT (value
));
1870 return void_type_node
;
1873 GNU_xref_member (current_class_name
, value
);
1875 if (TREE_STATIC (value
))
1877 cp_error ("static member `%D' cannot be a bitfield", value
);
1880 cp_finish_decl (value
, NULL_TREE
, NULL_TREE
, 0);
1882 if (width
!= error_mark_node
)
1884 constant_expression_warning (width
);
1885 DECL_INITIAL (value
) = width
;
1886 SET_DECL_C_BIT_FIELD (value
);
1889 DECL_IN_AGGR_P (value
) = 1;
1894 grokoptypename (declspecs
, declarator
)
1895 tree declspecs
, declarator
;
1897 tree t
= grokdeclarator (declarator
, declspecs
, TYPENAME
, 0, NULL_TREE
);
1899 return mangle_conv_op_name_for_type (t
);
1901 return build_typename_overload (t
);
1904 /* When a function is declared with an initializer,
1905 do the right thing. Currently, there are two possibilities:
1910 // initialization possibility #1.
1911 virtual void f () = 0;
1933 // initialization possibility #2
1940 copy_assignment_arg_p (parmtype
, virtualp
)
1942 int virtualp ATTRIBUTE_UNUSED
;
1944 if (current_class_type
== NULL_TREE
)
1947 if (TREE_CODE (parmtype
) == REFERENCE_TYPE
)
1948 parmtype
= TREE_TYPE (parmtype
);
1950 if ((TYPE_MAIN_VARIANT (parmtype
) == current_class_type
)
1952 /* Non-standard hack to support old Booch components. */
1953 || (! virtualp
&& DERIVED_FROM_P (parmtype
, current_class_type
))
1962 grok_function_init (decl
, init
)
1966 /* An initializer for a function tells how this function should
1968 tree type
= TREE_TYPE (decl
);
1970 if (TREE_CODE (type
) == FUNCTION_TYPE
)
1971 cp_error ("initializer specified for non-member function `%D'", decl
);
1973 /* We'll check for this in finish_struct_1. */
1974 else if (DECL_VINDEX (decl
) == NULL_TREE
)
1975 cp_error ("initializer specified for non-virtual member function `%D'", decl
);
1977 else if (integer_zerop (init
))
1980 /* Mark this function as being "defined". */
1981 DECL_INITIAL (decl
) = error_mark_node
;
1982 /* pure virtual destructors must be defined. */
1983 /* pure virtual needs to be defined (as abort) only when put in
1984 vtbl. For wellformed call, it should be itself. pr4737 */
1985 if (!DECL_DESTRUCTOR_P (decl
)))
1987 /* Give this node rtl from `abort'. */
1988 DECL_RTL (decl
) = DECL_RTL (abort_fndecl
);
1991 DECL_PURE_VIRTUAL_P (decl
) = 1;
1992 if (DECL_OVERLOADED_OPERATOR_P (decl
) == NOP_EXPR
)
1995 = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl
))));
1997 if (copy_assignment_arg_p (parmtype
, 1))
1998 TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type
) = 1;
2002 cp_error ("invalid initializer for virtual method `%D'", decl
);
2006 cplus_decl_attributes (decl
, attributes
, prefix_attributes
)
2007 tree decl
, attributes
, prefix_attributes
;
2009 if (decl
== NULL_TREE
|| decl
== void_type_node
)
2012 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
2013 decl
= DECL_TEMPLATE_RESULT (decl
);
2015 decl_attributes (decl
, attributes
, prefix_attributes
);
2017 if (TREE_CODE (decl
) == TYPE_DECL
)
2018 SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl
), TREE_TYPE (decl
));
2021 /* CONSTRUCTOR_NAME:
2022 Return the name for the constructor (or destructor) for the
2023 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
2024 IDENTIFIER_NODE. When given a template, this routine doesn't
2025 lose the specialization. */
2028 constructor_name_full (thing
)
2031 if (TREE_CODE (thing
) == TEMPLATE_TYPE_PARM
2032 || TREE_CODE (thing
) == BOUND_TEMPLATE_TEMPLATE_PARM
2033 || TREE_CODE (thing
) == TYPENAME_TYPE
)
2034 thing
= TYPE_NAME (thing
);
2035 else if (IS_AGGR_TYPE_CODE (TREE_CODE (thing
)))
2037 if (TYPE_WAS_ANONYMOUS (thing
) && TYPE_HAS_CONSTRUCTOR (thing
))
2038 thing
= DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (thing
), 0)));
2040 thing
= TYPE_NAME (thing
);
2042 if (TREE_CODE (thing
) == TYPE_DECL
2043 || (TREE_CODE (thing
) == TEMPLATE_DECL
2044 && TREE_CODE (DECL_TEMPLATE_RESULT (thing
)) == TYPE_DECL
))
2045 thing
= DECL_NAME (thing
);
2046 my_friendly_assert (TREE_CODE (thing
) == IDENTIFIER_NODE
, 197);
2050 /* CONSTRUCTOR_NAME:
2051 Return the name for the constructor (or destructor) for the
2052 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
2053 IDENTIFIER_NODE. When given a template, return the plain
2054 unspecialized name. */
2057 constructor_name (thing
)
2061 thing
= constructor_name_full (thing
);
2062 t
= IDENTIFIER_TEMPLATE (thing
);
2068 /* Defer the compilation of the FN until the end of compilation. */
2074 if (DECL_DEFERRED_FN (fn
))
2076 DECL_DEFERRED_FN (fn
) = 1;
2078 VARRAY_TREE_INIT (deferred_fns
, 32, "deferred_fns");
2080 VARRAY_PUSH_TREE (deferred_fns
, fn
);
2083 /* Hand off a unique name which can be used for variable we don't really
2084 want to know about anyway, for example, the anonymous variables which
2085 are needed to make references work. Declare this thing so we can use it.
2086 The variable created will be of type TYPE, and will have internal
2090 get_temp_name (type
)
2093 char buf
[sizeof (AUTO_TEMP_FORMAT
) + 20];
2095 int toplev
= toplevel_bindings_p ();
2097 sprintf (buf
, AUTO_TEMP_FORMAT
, global_temp_name_counter
++);
2098 decl
= build_decl (VAR_DECL
, get_identifier (buf
), type
);
2099 DECL_ARTIFICIAL (decl
) = 1;
2100 TREE_USED (decl
) = 1;
2101 TREE_STATIC (decl
) = 1;
2103 decl
= pushdecl_top_level (decl
);
2105 /* If this is a local variable, then lay out its rtl now.
2106 Otherwise, callers of this function are responsible for dealing
2107 with this variable's rtl. */
2111 my_friendly_assert (DECL_INITIAL (decl
) == NULL_TREE
,
2118 /* Hunts through the global anonymous union ANON_DECL, building
2119 appropriate VAR_DECLs. Stores cleanups on the list of ELEMS, and
2120 returns a VAR_DECL whose size is the same as the size of the
2121 ANON_DECL, if one is available. */
2124 build_anon_union_vars (anon_decl
, elems
, static_p
, external_p
)
2130 tree type
= TREE_TYPE (anon_decl
);
2131 tree main_decl
= NULL_TREE
;
2134 /* Rather than write the code to handle the non-union case,
2135 just give an error. */
2136 if (TREE_CODE (type
) != UNION_TYPE
)
2137 error ("anonymous struct not inside named type");
2139 for (field
= TYPE_FIELDS (type
);
2141 field
= TREE_CHAIN (field
))
2145 if (DECL_ARTIFICIAL (field
))
2147 if (TREE_CODE (field
) != FIELD_DECL
)
2149 cp_pedwarn_at ("`%#D' invalid; an anonymous union can only have non-static data members",
2154 if (TREE_PRIVATE (field
))
2155 cp_pedwarn_at ("private member `%#D' in anonymous union", field
);
2156 else if (TREE_PROTECTED (field
))
2157 cp_pedwarn_at ("protected member `%#D' in anonymous union", field
);
2159 if (DECL_NAME (field
) == NULL_TREE
2160 && ANON_AGGR_TYPE_P (TREE_TYPE (field
)))
2162 decl
= build_anon_union_vars (field
, elems
, static_p
, external_p
);
2166 else if (DECL_NAME (field
) == NULL_TREE
)
2170 decl
= build_decl (VAR_DECL
, DECL_NAME (field
), TREE_TYPE (field
));
2171 /* tell `pushdecl' that this is not tentative. */
2172 DECL_INITIAL (decl
) = error_mark_node
;
2173 TREE_PUBLIC (decl
) = 0;
2174 TREE_STATIC (decl
) = static_p
;
2175 DECL_EXTERNAL (decl
) = external_p
;
2176 decl
= pushdecl (decl
);
2177 DECL_INITIAL (decl
) = NULL_TREE
;
2180 /* Only write out one anon union element--choose the largest
2181 one. We used to try to find one the same size as the union,
2182 but that fails if the ABI forces us to align the union more
2184 if (main_decl
== NULL_TREE
2185 || tree_int_cst_lt (DECL_SIZE (main_decl
), DECL_SIZE (decl
)))
2188 TREE_ASM_WRITTEN (main_decl
) = 1;
2192 /* ??? This causes there to be no debug info written out
2194 TREE_ASM_WRITTEN (decl
) = 1;
2196 if (DECL_NAME (field
) == NULL_TREE
2197 && ANON_AGGR_TYPE_P (TREE_TYPE (field
)))
2198 /* The remainder of the processing was already done in the
2202 /* If there's a cleanup to do, it belongs in the
2203 TREE_PURPOSE of the following TREE_LIST. */
2204 *elems
= tree_cons (NULL_TREE
, decl
, *elems
);
2205 TREE_TYPE (*elems
) = type
;
2211 /* Finish off the processing of a UNION_TYPE structure.
2212 If there are static members, then all members are
2213 static, and must be laid out together. If the
2214 union is an anonymous union, we arrange for that
2215 as well. PUBLIC_P is nonzero if this union is
2216 not declared static. */
2219 finish_anon_union (anon_union_decl
)
2220 tree anon_union_decl
;
2222 tree type
= TREE_TYPE (anon_union_decl
);
2224 int public_p
= TREE_PUBLIC (anon_union_decl
);
2225 int static_p
= TREE_STATIC (anon_union_decl
);
2226 int external_p
= DECL_EXTERNAL (anon_union_decl
);
2228 if (TYPE_FIELDS (type
) == NULL_TREE
)
2233 error ("namespace-scope anonymous aggregates must be static");
2237 main_decl
= build_anon_union_vars (anon_union_decl
,
2238 &DECL_ANON_UNION_ELEMS (anon_union_decl
),
2239 static_p
, external_p
);
2241 if (main_decl
== NULL_TREE
)
2243 warning ("anonymous aggregate with no members");
2249 make_decl_rtl (main_decl
, 0, toplevel_bindings_p ());
2250 DECL_RTL (anon_union_decl
) = DECL_RTL (main_decl
);
2251 expand_anon_union_decl (anon_union_decl
,
2253 DECL_ANON_UNION_ELEMS (anon_union_decl
));
2256 add_decl_stmt (anon_union_decl
);
2259 /* Finish processing a builtin type TYPE. It's name is NAME,
2260 its fields are in the array FIELDS. LEN is the number of elements
2261 in FIELDS minus one, or put another way, it is the maximum subscript
2264 It is given the same alignment as ALIGN_TYPE. */
2267 finish_builtin_type (type
, name
, fields
, len
, align_type
)
2276 TYPE_FIELDS (type
) = fields
[0];
2277 for (i
= 0; i
< len
; i
++)
2279 layout_type (TREE_TYPE (fields
[i
]));
2280 DECL_FIELD_CONTEXT (fields
[i
]) = type
;
2281 TREE_CHAIN (fields
[i
]) = fields
[i
+1];
2283 DECL_FIELD_CONTEXT (fields
[i
]) = type
;
2284 TYPE_ALIGN (type
) = TYPE_ALIGN (align_type
);
2285 TYPE_USER_ALIGN (type
) = TYPE_USER_ALIGN (align_type
);
2287 #if 0 /* not yet, should get fixed properly later */
2288 TYPE_NAME (type
) = make_type_decl (get_identifier (name
), type
);
2290 TYPE_NAME (type
) = build_decl (TYPE_DECL
, get_identifier (name
), type
);
2292 TYPE_STUB_DECL (type
) = TYPE_NAME (type
);
2293 layout_decl (TYPE_NAME (type
), 0);
2296 /* Auxiliary functions to make type signatures for
2297 `operator new' and `operator delete' correspond to
2298 what compiler will be expecting. */
2301 coerce_new_type (type
)
2305 tree args
= TYPE_ARG_TYPES (type
);
2307 my_friendly_assert (TREE_CODE (type
) == FUNCTION_TYPE
, 20001107);
2309 if (!same_type_p (TREE_TYPE (type
), ptr_type_node
))
2310 e
= 1, cp_error ("`operator new' must return type `%T'", ptr_type_node
);
2312 if (!args
|| args
== void_list_node
2313 || !same_type_p (TREE_VALUE (args
), c_size_type_node
))
2316 if (args
&& args
!= void_list_node
)
2317 args
= TREE_CHAIN (args
);
2318 cp_error ("`operator new' takes type `size_t' (`%T') as first parameter", c_size_type_node
);
2323 args
= tree_cons (NULL_TREE
, c_size_type_node
, args
);
2326 type
= build_exception_variant
2327 (build_function_type (ptr_type_node
, args
),
2328 TYPE_RAISES_EXCEPTIONS (type
));
2336 coerce_delete_type (type
)
2340 tree args
= TYPE_ARG_TYPES (type
);
2342 my_friendly_assert (TREE_CODE (type
) == FUNCTION_TYPE
, 20001107);
2344 if (!same_type_p (TREE_TYPE (type
), void_type_node
))
2345 e
= 1, cp_error ("`operator delete' must return type `%T'", void_type_node
);
2347 if (!args
|| args
== void_list_node
2348 || !same_type_p (TREE_VALUE (args
), ptr_type_node
))
2351 if (args
&& args
!= void_list_node
)
2352 args
= TREE_CHAIN (args
);
2353 cp_error ("`operator delete' takes type `%T' as first parameter", ptr_type_node
);
2358 args
= tree_cons (NULL_TREE
, ptr_type_node
, args
);
2361 type
= build_exception_variant
2362 (build_function_type (void_type_node
, args
),
2363 TYPE_RAISES_EXCEPTIONS (type
));
2372 mark_vtable_entries (decl
)
2375 tree entries
= CONSTRUCTOR_ELTS (DECL_INITIAL (decl
));
2377 for (; entries
; entries
= TREE_CHAIN (entries
))
2382 fnaddr
= (flag_vtable_thunks
? TREE_VALUE (entries
)
2383 : FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries
)));
2385 if (TREE_CODE (fnaddr
) != ADDR_EXPR
)
2386 /* This entry is an offset: a virtual base class offset, a
2387 virtual call offset, and RTTI offset, etc. */
2390 fn
= TREE_OPERAND (fnaddr
, 0);
2391 TREE_ADDRESSABLE (fn
) = 1;
2392 /* When we don't have vcall offsets, we output thunks whenever
2393 we output the vtables that contain them. With vcall offsets,
2394 we know all the thunks we'll need when we emit a virtual
2395 function, so we emit the thunks there instead. */
2396 if (DECL_THUNK_P (fn
))
2397 use_thunk (fn
, THUNK_GENERATE_WITH_VTABLE_P (fn
));
2402 /* Set DECL up to have the closest approximation of "initialized common"
2403 linkage available. */
2406 comdat_linkage (decl
)
2410 make_decl_one_only (decl
);
2411 else if (TREE_CODE (decl
) == FUNCTION_DECL
|| DECL_VIRTUAL_P (decl
))
2412 /* We can just emit functions and vtables statically; having
2413 multiple copies is (for the most part) only a waste of space.
2414 There is at least one correctness issue, however: the address
2415 of a template instantiation with external linkage should be the
2416 same, independent of what translation unit asks for the
2417 address, and this will not hold when we emit multiple copies of
2418 the function. However, there's little else we can do. */
2419 TREE_PUBLIC (decl
) = 0;
2422 /* Static data member template instantiations, however, cannot
2423 have multiple copies. */
2424 if (DECL_INITIAL (decl
) == 0
2425 || DECL_INITIAL (decl
) == error_mark_node
)
2426 DECL_COMMON (decl
) = 1;
2427 else if (EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl
)))
2429 DECL_COMMON (decl
) = 1;
2430 DECL_INITIAL (decl
) = error_mark_node
;
2434 /* We can't do anything useful; leave vars for explicit
2436 DECL_EXTERNAL (decl
) = 1;
2437 DECL_NOT_REALLY_EXTERN (decl
) = 0;
2441 if (DECL_LANG_SPECIFIC (decl
))
2442 DECL_COMDAT (decl
) = 1;
2445 /* For win32 we also want to put explicit instantiations in
2446 linkonce sections, so that they will be merged with implicit
2447 instantiations; otherwise we get duplicate symbol errors. */
2450 maybe_make_one_only (decl
)
2453 /* We used to say that this was not necessary on targets that support weak
2454 symbols, because the implicit instantiations will defer to the explicit
2455 one. However, that's not actually the case in SVR4; a strong definition
2456 after a weak one is an error. Also, not making explicit
2457 instantiations one_only means that we can end up with two copies of
2458 some template instantiations. */
2459 if (! supports_one_only ())
2462 /* We can't set DECL_COMDAT on functions, or finish_file will think
2463 we can get away with not emitting them if they aren't used. We need
2464 to for variables so that cp_finish_decl will update their linkage,
2465 because their DECL_INITIAL may not have been set properly yet. */
2467 make_decl_one_only (decl
);
2469 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_LANG_SPECIFIC (decl
))
2470 DECL_COMDAT (decl
) = 1;
2473 /* Returns the virtual function with which the vtable for TYPE is
2474 emitted, or NULL_TREE if that heuristic is not applicable to TYPE. */
2482 if (TYPE_FOR_JAVA (type
)
2483 || CLASSTYPE_TEMPLATE_INSTANTIATION (type
)
2484 || CLASSTYPE_INTERFACE_KNOWN (type
))
2487 for (method
= TYPE_METHODS (type
); method
!= NULL_TREE
;
2488 method
= TREE_CHAIN (method
))
2489 if (DECL_VINDEX (method
) != NULL_TREE
2490 && ! DECL_THIS_INLINE (method
)
2491 && ! DECL_PURE_VIRTUAL_P (method
))
2497 /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL,
2498 based on TYPE and other static flags.
2500 Note that anything public is tagged TREE_PUBLIC, whether
2501 it's public in this file or in another one. */
2504 import_export_vtable (decl
, type
, final
)
2508 if (DECL_INTERFACE_KNOWN (decl
))
2511 if (TYPE_FOR_JAVA (type
))
2513 TREE_PUBLIC (decl
) = 1;
2514 DECL_EXTERNAL (decl
) = 1;
2515 DECL_INTERFACE_KNOWN (decl
) = 1;
2517 else if (CLASSTYPE_INTERFACE_KNOWN (type
))
2519 TREE_PUBLIC (decl
) = 1;
2520 DECL_EXTERNAL (decl
) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type
);
2521 DECL_INTERFACE_KNOWN (decl
) = 1;
2525 /* We can only wait to decide if we have real non-inline virtual
2526 functions in our class, or if we come from a template. */
2528 int found
= (CLASSTYPE_TEMPLATE_INSTANTIATION (type
)
2529 || key_method (type
));
2531 if (final
|| ! found
)
2533 comdat_linkage (decl
);
2534 DECL_EXTERNAL (decl
) = 0;
2538 TREE_PUBLIC (decl
) = 1;
2539 DECL_EXTERNAL (decl
) = 1;
2544 /* Determine whether or not we want to specifically import or export CTYPE,
2545 using various heuristics. */
2548 import_export_class (ctype
)
2551 /* -1 for imported, 1 for exported. */
2552 int import_export
= 0;
2554 /* It only makes sense to call this function at EOF. The reason is
2555 that this function looks at whether or not the first non-inline
2556 non-abstract virtual member function has been defined in this
2557 translation unit. But, we can't possibly know that until we've
2558 seen the entire translation unit. */
2559 my_friendly_assert (at_eof
, 20000226);
2561 if (CLASSTYPE_INTERFACE_KNOWN (ctype
))
2564 /* If MULTIPLE_SYMBOL_SPACES is defined and we saw a #pragma interface,
2565 we will have CLASSTYPE_INTERFACE_ONLY set but not
2566 CLASSTYPE_INTERFACE_KNOWN. In that case, we don't want to use this
2567 heuristic because someone will supply a #pragma implementation
2568 elsewhere, and deducing it here would produce a conflict. */
2569 if (CLASSTYPE_INTERFACE_ONLY (ctype
))
2572 #ifdef VALID_MACHINE_TYPE_ATTRIBUTE
2573 /* FIXME this should really use some sort of target-independent macro. */
2574 if (lookup_attribute ("dllimport", TYPE_ATTRIBUTES (ctype
)))
2576 else if (lookup_attribute ("dllexport", TYPE_ATTRIBUTES (ctype
)))
2580 /* If we got -fno-implicit-templates, we import template classes that
2581 weren't explicitly instantiated. */
2582 if (import_export
== 0
2583 && CLASSTYPE_IMPLICIT_INSTANTIATION (ctype
)
2584 && ! flag_implicit_templates
)
2587 /* Base our import/export status on that of the first non-inline,
2588 non-pure virtual function, if any. */
2589 if (import_export
== 0
2590 && TYPE_POLYMORPHIC_P (ctype
))
2592 tree method
= key_method (ctype
);
2594 import_export
= (DECL_REALLY_EXTERN (method
) ? -1 : 1);
2597 #ifdef MULTIPLE_SYMBOL_SPACES
2598 if (import_export
== -1)
2604 SET_CLASSTYPE_INTERFACE_KNOWN (ctype
);
2605 CLASSTYPE_VTABLE_NEEDS_WRITING (ctype
) = (import_export
> 0);
2606 CLASSTYPE_INTERFACE_ONLY (ctype
) = (import_export
< 0);
2610 /* We need to describe to the assembler the relationship between
2611 a vtable and the vtable of the parent class. */
2614 output_vtable_inherit (vars
)
2620 op
[0] = XEXP (DECL_RTL (vars
), 0); /* strip the mem ref */
2622 parent
= binfo_for_vtable (vars
);
2624 if (parent
== TYPE_BINFO (DECL_CONTEXT (vars
)))
2628 parent
= get_vtbl_decl_for_binfo (TYPE_BINFO (BINFO_TYPE (parent
)));
2629 op
[1] = XEXP (DECL_RTL (parent
), 0); /* strip the mem ref */
2632 my_friendly_abort (980826);
2634 output_asm_insn (".vtable_inherit %c0, %c1", op
);
2638 finish_vtable_vardecl (t
, data
)
2640 void *data ATTRIBUTE_UNUSED
;
2643 tree ctype
= DECL_CONTEXT (vars
);
2644 import_export_class (ctype
);
2645 import_export_vtable (vars
, ctype
, 1);
2647 if (! DECL_EXTERNAL (vars
)
2648 && DECL_NEEDED_P (vars
)
2649 && ! TREE_ASM_WRITTEN (vars
))
2651 if (TREE_TYPE (vars
) == void_type_node
)
2652 /* It is a dummy vtable made by get_vtable_decl. Ignore it. */
2656 mark_vtable_entries (vars
);
2657 if (TREE_TYPE (DECL_INITIAL (vars
)) == 0)
2658 store_init_value (vars
, DECL_INITIAL (vars
));
2660 if (write_symbols
== DWARF_DEBUG
|| write_symbols
== DWARF2_DEBUG
)
2662 /* Mark the VAR_DECL node representing the vtable itself as a
2663 "gratuitous" one, thereby forcing dwarfout.c to ignore it.
2664 It is rather important that such things be ignored because
2665 any effort to actually generate DWARF for them will run
2666 into trouble when/if we encounter code like:
2669 struct S { virtual void member (); };
2671 because the artificial declaration of the vtable itself (as
2672 manufactured by the g++ front end) will say that the vtable
2673 is a static member of `S' but only *after* the debug output
2674 for the definition of `S' has already been output. This causes
2675 grief because the DWARF entry for the definition of the vtable
2676 will try to refer back to an earlier *declaration* of the
2677 vtable as a static member of `S' and there won't be one.
2678 We might be able to arrange to have the "vtable static member"
2679 attached to the member list for `S' before the debug info for
2680 `S' get written (which would solve the problem) but that would
2681 require more intrusive changes to the g++ front end. */
2683 DECL_IGNORED_P (vars
) = 1;
2686 /* Always make vtables weak. */
2688 comdat_linkage (vars
);
2690 rest_of_decl_compilation (vars
, NULL_PTR
, 1, 1);
2693 output_vtable_inherit (vars
);
2695 /* Because we're only doing syntax-checking, we'll never end up
2696 actually marking the variable as written. */
2697 if (flag_syntax_only
)
2698 TREE_ASM_WRITTEN (vars
) = 1;
2700 /* Since we're writing out the vtable here, also write the debug
2702 note_debug_info_needed (ctype
);
2707 /* If the references to this class' vtables were optimized away, still
2708 emit the appropriate debugging information. See dfs_debug_mark. */
2709 if (DECL_COMDAT (vars
)
2710 && CLASSTYPE_DEBUG_REQUESTED (ctype
))
2711 note_debug_info_needed (ctype
);
2717 prune_vtable_vardecl (t
, data
)
2719 void *data ATTRIBUTE_UNUSED
;
2721 *t
= TREE_CHAIN (*t
);
2725 /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an
2726 inline function or template instantiation at end-of-file. */
2729 import_export_decl (decl
)
2732 if (DECL_INTERFACE_KNOWN (decl
))
2735 if (DECL_TEMPLATE_INSTANTIATION (decl
)
2736 || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl
))
2738 DECL_NOT_REALLY_EXTERN (decl
) = 1;
2739 if ((DECL_IMPLICIT_INSTANTIATION (decl
)
2740 || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl
))
2741 && (flag_implicit_templates
2742 || (flag_implicit_inline_templates
&& DECL_THIS_INLINE (decl
))))
2744 if (!TREE_PUBLIC (decl
))
2745 /* Templates are allowed to have internal linkage. See
2749 comdat_linkage (decl
);
2752 DECL_NOT_REALLY_EXTERN (decl
) = 0;
2754 else if (DECL_FUNCTION_MEMBER_P (decl
))
2756 tree ctype
= DECL_CONTEXT (decl
);
2757 import_export_class (ctype
);
2758 if (CLASSTYPE_INTERFACE_KNOWN (ctype
)
2760 ? (! DECL_THIS_INLINE (decl
))
2761 : (! DECL_ARTIFICIAL (decl
) || DECL_VINDEX (decl
))))
2763 DECL_NOT_REALLY_EXTERN (decl
)
2764 = ! (CLASSTYPE_INTERFACE_ONLY (ctype
)
2765 || (DECL_THIS_INLINE (decl
) && ! flag_implement_inlines
2766 && !DECL_VINDEX (decl
)));
2768 /* Always make artificials weak. */
2769 if (DECL_ARTIFICIAL (decl
) && flag_weak
)
2770 comdat_linkage (decl
);
2772 maybe_make_one_only (decl
);
2775 comdat_linkage (decl
);
2777 else if (DECL_TINFO_FN_P (decl
))
2779 tree ctype
= TREE_TYPE (DECL_NAME (decl
));
2781 if (IS_AGGR_TYPE (ctype
))
2782 import_export_class (ctype
);
2784 if (IS_AGGR_TYPE (ctype
) && CLASSTYPE_INTERFACE_KNOWN (ctype
)
2785 && TYPE_POLYMORPHIC_P (ctype
)
2786 /* If -fno-rtti, we're not necessarily emitting this stuff with
2787 the class, so go ahead and emit it now. This can happen
2788 when a class is used in exception handling. */
2790 /* If the type is a cv-qualified variant of a type, then we
2791 must emit the tinfo function in this translation unit
2792 since it will not be emitted when the vtable for the type
2793 is output (which is when the unqualified version is
2795 && same_type_p (ctype
, TYPE_MAIN_VARIANT (ctype
)))
2797 DECL_NOT_REALLY_EXTERN (decl
)
2798 = ! (CLASSTYPE_INTERFACE_ONLY (ctype
)
2799 || (DECL_THIS_INLINE (decl
) && ! flag_implement_inlines
2800 && !DECL_VINDEX (decl
)));
2802 /* Always make artificials weak. */
2804 comdat_linkage (decl
);
2806 else if (TYPE_BUILT_IN (ctype
)
2807 && same_type_p (ctype
, TYPE_MAIN_VARIANT (ctype
)))
2808 DECL_NOT_REALLY_EXTERN (decl
) = 0;
2810 comdat_linkage (decl
);
2813 comdat_linkage (decl
);
2815 DECL_INTERFACE_KNOWN (decl
) = 1;
2819 build_cleanup (decl
)
2823 tree type
= TREE_TYPE (decl
);
2825 if (TREE_CODE (type
) == ARRAY_TYPE
)
2829 mark_addressable (decl
);
2830 temp
= build1 (ADDR_EXPR
, build_pointer_type (type
), decl
);
2832 temp
= build_delete (TREE_TYPE (temp
), temp
,
2833 sfk_complete_destructor
,
2834 LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
|LOOKUP_DESTRUCTOR
, 0);
2838 /* Returns the initialization guard variable for the variable DECL,
2839 which has static storage duration. */
2848 /* For a local variable, under the old ABI, we do not try to get a
2849 unique mangled name for the DECL. */
2850 if (!flag_new_abi
&& DECL_FUNCTION_SCOPE_P (decl
))
2852 guard
= get_temp_name (integer_type_node
);
2853 cp_finish_decl (guard
, NULL_TREE
, NULL_TREE
, 0);
2858 /* For struct X foo __attribute__((weak)), there is a counter
2859 __snfoo. Since base is already an assembler name, sname should
2860 be globally unique */
2861 sname
= get_id_2 ("__sn", DECL_ASSEMBLER_NAME (decl
));
2863 sname
= mangle_guard_variable (decl
);
2865 guard
= IDENTIFIER_GLOBAL_VALUE (sname
);
2870 /* Under the new ABI, we use a type that is big enough to
2871 contain a mutex as well as an integer counter. */
2873 guard_type
= long_long_integer_type_node
;
2875 guard_type
= integer_type_node
;
2877 guard
= build_decl (VAR_DECL
, sname
, guard_type
);
2878 TREE_PUBLIC (guard
) = 1;
2879 DECL_ARTIFICIAL (guard
) = 1;
2880 TREE_STATIC (guard
) = 1;
2881 TREE_USED (guard
) = 1;
2882 DECL_COMMON (guard
) = 1;
2883 pushdecl_top_level (guard
);
2884 cp_finish_decl (guard
, NULL_TREE
, NULL_TREE
, 0);
2889 /* Return those bits of the GUARD variable that should be set when the
2890 guarded entity is actually initialized. */
2893 get_guard_bits (guard
)
2899 /* Under the new ABI, we only set the first byte of the guard,
2900 in order to leave room for a mutex in the high-order bits. */
2901 guard
= build1 (ADDR_EXPR
,
2902 build_pointer_type (TREE_TYPE (guard
)),
2904 guard
= build1 (NOP_EXPR
,
2905 build_pointer_type (char_type_node
),
2907 guard
= build1 (INDIRECT_REF
, char_type_node
, guard
);
2912 /* Return an expression which determines whether or not the GUARD
2913 variable has already been initialized. */
2916 get_guard_cond (guard
)
2921 /* Check to see if the GUARD is zero. */
2922 guard
= get_guard_bits (guard
);
2923 guard_value
= integer_zero_node
;
2924 if (!same_type_p (TREE_TYPE (guard_value
), TREE_TYPE (guard
)))
2925 guard_value
= convert (TREE_TYPE (guard
), guard_value
);
2926 return cp_build_binary_op (EQ_EXPR
, guard
, guard_value
);
2929 /* Return an expression which sets the GUARD variable, indicating that
2930 the variable being guarded has been initialized. */
2938 /* Set the GUARD to one. */
2939 guard
= get_guard_bits (guard
);
2940 guard_init
= integer_one_node
;
2941 if (!same_type_p (TREE_TYPE (guard_init
), TREE_TYPE (guard
)))
2942 guard_init
= convert (TREE_TYPE (guard
), guard_init
);
2943 return build_modify_expr (guard
, NOP_EXPR
, guard_init
);
2946 /* Start the process of running a particular set of global constructors
2947 or destructors. Subroutine of do_[cd]tors. */
2950 start_objects (method_type
, initp
)
2951 int method_type
, initp
;
2957 /* Make ctor or dtor function. METHOD_TYPE may be 'I' or 'D'. */
2959 if (initp
!= DEFAULT_INIT_PRIORITY
)
2969 sprintf (type
, "%c%c%.5u", method_type
, joiner
, initp
);
2972 sprintf (type
, "%c", method_type
);
2974 fnname
= get_file_function_name_long (type
);
2976 start_function (void_list_node
,
2977 make_call_declarator (fnname
, void_list_node
, NULL_TREE
,
2979 NULL_TREE
, SF_DEFAULT
);
2981 #if defined(ASM_OUTPUT_CONSTRUCTOR) && defined(ASM_OUTPUT_DESTRUCTOR)
2982 /* It can be a static function as long as collect2 does not have
2983 to scan the object file to find its ctor/dtor routine. */
2984 TREE_PUBLIC (current_function_decl
) = 0;
2987 /* Mark this declaration as used to avoid spurious warnings. */
2988 TREE_USED (current_function_decl
) = 1;
2990 /* Mark this function as a global constructor or destructor. */
2991 if (method_type
== 'I')
2992 DECL_GLOBAL_CTOR_P (current_function_decl
) = 1;
2994 DECL_GLOBAL_DTOR_P (current_function_decl
) = 1;
2995 GLOBAL_INIT_PRIORITY (current_function_decl
) = initp
;
2997 body
= begin_compound_stmt (/*has_no_scope=*/0);
2999 /* We cannot allow these functions to be elided, even if they do not
3000 have external linkage. And, there's no point in deferring
3001 copmilation of thes functions; they're all going to have to be
3003 current_function_cannot_inline
3004 = "static constructors and destructors cannot be inlined";
3009 /* Finish the process of running a particular set of global constructors
3010 or destructors. Subroutine of do_[cd]tors. */
3013 finish_objects (method_type
, initp
, body
)
3014 int method_type
, initp
;
3021 finish_compound_stmt (/*has_no_scope=*/0, body
);
3022 fn
= finish_function (0);
3025 /* When only doing semantic analysis, and no RTL generation, we
3026 can't call functions that directly emit assembly code; there is
3027 no assembly file in which to put the code. */
3028 if (flag_syntax_only
)
3031 fnname
= XSTR (XEXP (DECL_RTL (fn
), 0), 0);
3032 if (initp
== DEFAULT_INIT_PRIORITY
)
3034 if (method_type
== 'I')
3035 assemble_constructor (fnname
);
3037 assemble_destructor (fnname
);
3039 #if defined (ASM_OUTPUT_SECTION_NAME) && defined (ASM_OUTPUT_CONSTRUCTOR)
3040 /* If we're using init priority we can't use assemble_*tor, but on ELF
3041 targets we can stick the references into named sections for GNU ld
3046 sprintf (buf
, ".%ctors.%.5u", method_type
== 'I' ? 'c' : 'd',
3047 /* invert the numbering so the linker puts us in the proper
3048 order; constructors are run from right to left, and the
3049 linker sorts in increasing order. */
3050 MAX_INIT_PRIORITY
- initp
);
3051 named_section (NULL_TREE
, buf
, 0);
3052 assemble_integer (gen_rtx_SYMBOL_REF (Pmode
, fnname
),
3053 POINTER_SIZE
/ BITS_PER_UNIT
, 1);
3058 /* The names of the parameters to the function created to handle
3059 initializations and destructions for objects with static storage
3061 #define INITIALIZE_P_IDENTIFIER "__initialize_p"
3062 #define PRIORITY_IDENTIFIER "__priority"
3064 /* The name of the function we create to handle initializations and
3065 destructions for objects with static storage duration. */
3066 #define SSDF_IDENTIFIER "__static_initialization_and_destruction"
3068 /* The declaration for the __INITIALIZE_P argument. */
3069 static tree initialize_p_decl
;
3071 /* The declaration for the __PRIORITY argument. */
3072 static tree priority_decl
;
3074 /* The declaration for the static storage duration function. */
3075 static tree ssdf_decl
;
3077 /* All the static storage duration functions created in this
3078 translation unit. */
3079 static varray_type ssdf_decls
;
3081 /* A map from priority levels to information about that priority
3082 level. There may be many such levels, so efficient lookup is
3084 static splay_tree priority_info_map
;
3086 /* Begins the generation of the function that will handle all
3087 initialization and destruction of objects with static storage
3088 duration. The function generated takes two parameters of type
3089 `int': __INITIALIZE_P and __PRIORITY. If __INITIALIZE_P is
3090 non-zero, it performs initializations. Otherwise, it performs
3091 destructions. It only performs those initializations or
3092 destructions with the indicated __PRIORITY. The generated function
3095 It is assumed that this function will only be called once per
3096 translation unit. */
3099 start_static_storage_duration_function ()
3101 static unsigned ssdf_number
;
3106 char id
[sizeof (SSDF_IDENTIFIER
) + 1 /* '\0' */ + 32];
3108 /* Create the identifier for this function. It will be of the form
3109 SSDF_IDENTIFIER_<number>. */
3110 sprintf (id
, "%s_%u", SSDF_IDENTIFIER
, ssdf_number
++);
3111 if (ssdf_number
== 0)
3113 /* Overflow occurred. That means there are at least 4 billion
3114 initialization functions. */
3115 sorry ("too many initialization functions required");
3116 my_friendly_abort (19990430);
3119 /* Create the parameters. */
3120 parm_types
= void_list_node
;
3121 parm_types
= tree_cons (NULL_TREE
, integer_type_node
, parm_types
);
3122 parm_types
= tree_cons (NULL_TREE
, integer_type_node
, parm_types
);
3123 type
= build_function_type (void_type_node
, parm_types
);
3125 /* Create the FUNCTION_DECL itself. */
3126 ssdf_decl
= build_lang_decl (FUNCTION_DECL
,
3127 get_identifier (id
),
3129 TREE_PUBLIC (ssdf_decl
) = 0;
3130 DECL_ARTIFICIAL (ssdf_decl
) = 1;
3132 /* Put this function in the list of functions to be called from the
3133 static constructors and destructors. */
3136 VARRAY_TREE_INIT (ssdf_decls
, 32, "ssdf_decls");
3138 /* Take this opportunity to initialize the map from priority
3139 numbers to information about that priority level. */
3140 priority_info_map
= splay_tree_new (splay_tree_compare_ints
,
3141 /*delete_key_fn=*/0,
3142 /*delete_value_fn=*/
3143 (splay_tree_delete_value_fn
) &free
);
3145 /* We always need to generate functions for the
3146 DEFAULT_INIT_PRIORITY so enter it now. That way when we walk
3147 priorities later, we'll be sure to find the
3148 DEFAULT_INIT_PRIORITY. */
3149 get_priority_info (DEFAULT_INIT_PRIORITY
);
3152 VARRAY_PUSH_TREE (ssdf_decls
, ssdf_decl
);
3154 /* Create the argument list. */
3155 initialize_p_decl
= build_decl (PARM_DECL
,
3156 get_identifier (INITIALIZE_P_IDENTIFIER
),
3158 DECL_CONTEXT (initialize_p_decl
) = ssdf_decl
;
3159 DECL_ARG_TYPE (initialize_p_decl
) = integer_type_node
;
3160 TREE_USED (initialize_p_decl
) = 1;
3161 priority_decl
= build_decl (PARM_DECL
, get_identifier (PRIORITY_IDENTIFIER
),
3163 DECL_CONTEXT (priority_decl
) = ssdf_decl
;
3164 DECL_ARG_TYPE (priority_decl
) = integer_type_node
;
3165 TREE_USED (priority_decl
) = 1;
3167 TREE_CHAIN (initialize_p_decl
) = priority_decl
;
3168 DECL_ARGUMENTS (ssdf_decl
) = initialize_p_decl
;
3170 /* Put the function in the global scope. */
3171 pushdecl (ssdf_decl
);
3173 /* Start the function itself. This is equivalent to declarating the
3176 static void __ssdf (int __initialize_p, init __priority_p);
3178 It is static because we only need to call this function from the
3179 various constructor and destructor functions for this module. */
3180 start_function (/*specs=*/NULL_TREE
,
3182 /*attrs=*/NULL_TREE
,
3185 /* Set up the scope of the outermost block in the function. */
3186 body
= begin_compound_stmt (/*has_no_scope=*/0);
3188 /* This function must not be deferred because we are depending on
3189 its compilation to tell us what is TREE_SYMBOL_REFERENCED. */
3190 current_function_cannot_inline
3191 = "static storage duration functions cannot be inlined";
3196 /* Finish the generation of the function which performs initialization
3197 and destruction of objects with static storage duration. After
3198 this point, no more such objects can be created. */
3201 finish_static_storage_duration_function (body
)
3204 /* Close out the function. */
3205 finish_compound_stmt (/*has_no_scope=*/0, body
);
3206 expand_body (finish_function (0));
3209 /* Return the information about the indicated PRIORITY level. If no
3210 code to handle this level has yet been generated, generate the
3211 appropriate prologue. */
3213 static priority_info
3214 get_priority_info (priority
)
3220 n
= splay_tree_lookup (priority_info_map
,
3221 (splay_tree_key
) priority
);
3224 /* Create a new priority information structure, and insert it
3226 pi
= (priority_info
) xmalloc (sizeof (struct priority_info_s
));
3227 pi
->initializations_p
= 0;
3228 pi
->destructions_p
= 0;
3229 splay_tree_insert (priority_info_map
,
3230 (splay_tree_key
) priority
,
3231 (splay_tree_value
) pi
);
3234 pi
= (priority_info
) n
->value
;
3239 /* Set up to handle the initialization or destruction of DECL. If
3240 INITP is non-zero, we are initializing the variable. Otherwise, we
3241 are destroying it. */
3244 start_static_initialization_or_destruction (decl
, initp
)
3248 tree guard_if_stmt
= NULL_TREE
;
3255 /* Figure out the priority for this declaration. */
3256 priority
= DECL_INIT_PRIORITY (decl
);
3258 priority
= DEFAULT_INIT_PRIORITY
;
3260 /* Remember that we had an initialization or finalization at this
3262 pi
= get_priority_info (priority
);
3264 pi
->initializations_p
= 1;
3266 pi
->destructions_p
= 1;
3268 /* Trick the compiler into thinking we are at the file and line
3269 where DECL was declared so that error-messages make sense, and so
3270 that the debugger will show somewhat sensible file and line
3272 input_filename
= DECL_SOURCE_FILE (decl
);
3273 lineno
= DECL_SOURCE_LINE (decl
);
3279 Access control for implicit calls to the constructors,
3280 the conversion functions, or the destructor called to
3281 create and destroy a static data member is performed as
3282 if these calls appeared in the scope of the member's
3285 we pretend we are in a static member function of the class of
3286 which the DECL is a member. */
3287 if (member_p (decl
))
3289 DECL_CONTEXT (current_function_decl
) = DECL_CONTEXT (decl
);
3290 DECL_STATIC_FUNCTION_P (current_function_decl
) = 1;
3293 /* Conditionalize this initialization on being in the right priority
3294 and being initializing/finalizing appropriately. */
3295 guard_if_stmt
= begin_if_stmt ();
3296 cond
= cp_build_binary_op (EQ_EXPR
,
3298 build_int_2 (priority
, 0));
3299 init_cond
= initp
? integer_one_node
: integer_zero_node
;
3300 init_cond
= cp_build_binary_op (EQ_EXPR
,
3303 cond
= cp_build_binary_op (TRUTH_ANDIF_EXPR
, cond
, init_cond
);
3305 /* Assume we don't need a guard. */
3307 /* We need a guard if this is an object with external linkage that
3308 might be initialized in more than one place. (For example, a
3309 static data member of a template, when the data member requires
3311 if (TREE_PUBLIC (decl
) && (DECL_COMMON (decl
)
3312 || DECL_ONE_ONLY (decl
)
3313 || DECL_WEAK (decl
)))
3317 guard
= get_guard (decl
);
3319 /* When using __cxa_atexit, we just check the GUARD as we would
3320 for a local static. */
3321 if (flag_use_cxa_atexit
)
3323 /* When using __cxa_atexit, we never try to destroy
3324 anything from a static destructor. */
3325 my_friendly_assert (initp
, 20000629);
3326 guard_cond
= get_guard_cond (guard
);
3328 /* Under the old ABI, e do initializations only if the GUARD is
3329 zero, i.e., if we are the first to initialize the variable.
3330 We do destructions only if the GUARD is one, i.e., if we are
3331 the last to destroy the variable. */
3334 = cp_build_binary_op (EQ_EXPR
,
3335 build_unary_op (PREINCREMENT_EXPR
,
3341 = cp_build_binary_op (EQ_EXPR
,
3342 build_unary_op (PREDECREMENT_EXPR
,
3347 cond
= cp_build_binary_op (TRUTH_ANDIF_EXPR
, cond
, guard_cond
);
3350 finish_if_stmt_cond (cond
, guard_if_stmt
);
3352 /* Under the new ABI, we have not already set the GUARD, so we must
3354 if (guard
&& initp
&& flag_new_abi
)
3355 finish_expr_stmt (set_guard (guard
));
3357 return guard_if_stmt
;
3360 /* We've just finished generating code to do an initialization or
3361 finalization. GUARD_IF_STMT is the if-statement we used to guard
3362 the initialization. */
3365 finish_static_initialization_or_destruction (guard_if_stmt
)
3368 finish_then_clause (guard_if_stmt
);
3371 /* Now that we're done with DECL we don't need to pretend to be a
3372 member of its class any longer. */
3373 DECL_CONTEXT (current_function_decl
) = NULL_TREE
;
3374 DECL_STATIC_FUNCTION_P (current_function_decl
) = 0;
3377 /* Generate code to do the static initialization of DECL. The
3378 initialization is INIT. If DECL may be initialized more than once
3379 in different object files, GUARD is the guard variable to
3380 check. PRIORITY is the priority for the initialization. */
3383 do_static_initialization (decl
, init
)
3390 /* Set up for the initialization. */
3392 = start_static_initialization_or_destruction (decl
,
3395 /* Do the initialization itself. */
3396 if (IS_AGGR_TYPE (TREE_TYPE (decl
))
3397 || TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
3398 expr
= build_aggr_init (decl
, init
, 0);
3401 expr
= build (INIT_EXPR
, TREE_TYPE (decl
), decl
, init
);
3402 TREE_SIDE_EFFECTS (expr
) = 1;
3404 finish_expr_stmt (expr
);
3406 /* If we're using __cxa_atexit, register a a function that calls the
3407 destructor for the object. */
3408 if (flag_use_cxa_atexit
)
3409 register_dtor_fn (decl
);
3412 finish_static_initialization_or_destruction (guard_if_stmt
);
3415 /* Generate code to do the static destruction of DECL. If DECL may be
3416 initialized more than once in different object files, GUARD is the
3417 guard variable to check. PRIORITY is the priority for the
3421 do_static_destruction (decl
)
3426 /* If we're using __cxa_atexit, then destructors are registered
3427 immediately after objects are initialized. */
3428 my_friendly_assert (!flag_use_cxa_atexit
, 20000121);
3430 /* If we don't need a destructor, there's nothing to do. */
3431 if (TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl
)))
3434 /* Actually do the destruction. */
3435 guard_if_stmt
= start_static_initialization_or_destruction (decl
,
3437 finish_expr_stmt (build_cleanup (decl
));
3438 finish_static_initialization_or_destruction (guard_if_stmt
);
3441 /* VARS is a list of variables with static storage duration which may
3442 need initialization and/or finalization. Remove those variables
3443 that don't really need to be initialized or finalized, and return
3444 the resulting list. The order in which the variables appear in
3445 VARS is in reverse order of the order in which they should actually
3446 be initialized. The list we return is in the unreversed order;
3447 i.e., the first variable should be initialized first. */
3450 prune_vars_needing_no_initialization (vars
)
3456 for (var
= vars
, result
= NULL_TREE
;
3458 var
= TREE_CHAIN (var
))
3460 tree decl
= TREE_VALUE (var
);
3461 tree init
= TREE_PURPOSE (var
);
3463 /* Deal gracefully with error. */
3464 if (decl
== error_mark_node
)
3467 /* The only things that can be initialized are variables. */
3468 my_friendly_assert (TREE_CODE (decl
) == VAR_DECL
, 19990420);
3470 /* If this object is not defined, we don't need to do anything
3472 if (DECL_EXTERNAL (decl
))
3475 /* Also, if the initializer already contains errors, we can bail
3477 if (init
&& TREE_CODE (init
) == TREE_LIST
3478 && value_member (error_mark_node
, init
))
3481 /* This variable is going to need initialization and/or
3482 finalization, so we add it to the list. */
3483 result
= tree_cons (init
, decl
, result
);
3489 /* Make sure we have told the back end about all the variables in
3493 write_out_vars (vars
)
3498 for (v
= vars
; v
; v
= TREE_CHAIN (v
))
3499 if (! TREE_ASM_WRITTEN (TREE_VALUE (v
)))
3500 rest_of_decl_compilation (TREE_VALUE (v
), 0, 1, 1);
3503 /* Generate a static constructor (if CONSTRUCTOR_P) or destructor
3504 (otherwise) that will initialize all gobal objects with static
3505 storage duration having the indicated PRIORITY. */
3508 generate_ctor_or_dtor_function (constructor_p
, priority
)
3517 /* We use `I' to indicate initialization and `D' to indicate
3524 /* Begin the function. */
3525 body
= start_objects (function_key
, priority
);
3527 /* Call the static storage duration function with appropriate
3529 for (i
= 0; i
< ssdf_decls
->elements_used
; ++i
)
3531 arguments
= tree_cons (NULL_TREE
, build_int_2 (priority
, 0),
3533 arguments
= tree_cons (NULL_TREE
, build_int_2 (constructor_p
, 0),
3535 finish_expr_stmt (build_function_call (VARRAY_TREE (ssdf_decls
, i
),
3539 /* If we're generating code for the DEFAULT_INIT_PRIORITY, throw in
3540 calls to any functions marked with attributes indicating that
3541 they should be called at initialization- or destruction-time. */
3542 if (priority
== DEFAULT_INIT_PRIORITY
)
3546 for (fns
= constructor_p
? static_ctors
: static_dtors
;
3548 fns
= TREE_CHAIN (fns
))
3549 finish_expr_stmt (build_function_call (TREE_VALUE (fns
), NULL_TREE
));
3552 /* Close out the function. */
3553 finish_objects (function_key
, priority
, body
);
3556 /* Generate constructor and destructor functions for the priority
3560 generate_ctor_and_dtor_functions_for_priority (n
, data
)
3562 void *data ATTRIBUTE_UNUSED
;
3564 int priority
= (int) n
->key
;
3565 priority_info pi
= (priority_info
) n
->value
;
3567 /* Generate the functions themselves, but only if they are really
3569 if (pi
->initializations_p
3570 || (priority
== DEFAULT_INIT_PRIORITY
&& static_ctors
))
3571 generate_ctor_or_dtor_function (/*constructor_p=*/1,
3573 if (pi
->destructions_p
3574 || (priority
== DEFAULT_INIT_PRIORITY
&& static_dtors
))
3575 generate_ctor_or_dtor_function (/*constructor_p=*/0,
3578 /* Keep iterating. */
3582 /* This routine is called from the last rule in yyparse ().
3583 Its job is to create all the code needed to initialize and
3584 destroy the global aggregates. We do the destruction
3585 first, since that way we only need to reverse the decls once. */
3596 /* Bad parse errors. Just forget about it. */
3597 if (! global_bindings_p () || current_class_type
|| decl_namespace_list
)
3600 /* Otherwise, GDB can get confused, because in only knows
3601 about source for LINENO-1 lines. */
3604 interface_unknown
= 1;
3607 /* We now have to write out all the stuff we put off writing out.
3610 o Template specializations that we have not yet instantiated,
3611 but which are needed.
3612 o Initialization and destruction for non-local objects with
3613 static storage duration. (Local objects with static storage
3614 duration are initialized when their scope is first entered,
3615 and are cleaned up via atexit.)
3616 o Virtual function tables.
3618 All of these may cause others to be needed. For example,
3619 instantiating one function may cause another to be needed, and
3620 generating the intiailzer for an object may cause templates to be
3621 instantiated, etc., etc. */
3623 timevar_push (TV_VARCONST
);
3625 if (new_abi_rtti_p ())
3626 emit_support_tinfos ();
3632 /* If there are templates that we've put off instantiating, do
3634 instantiate_pending_templates ();
3636 /* Write out virtual tables as required. Note that writing out
3637 the virtual table for a template class may cause the
3638 instantiation of members of that class. */
3639 if (walk_globals (vtable_decl_p
,
3640 finish_vtable_vardecl
,
3644 /* Write out needed type info variables. Writing out one variable
3645 might cause others to be needed. */
3646 if (new_abi_rtti_p ()
3647 && walk_globals (tinfo_decl_p
, emit_tinfo_decl
, /*data=*/0))
3650 /* The list of objects with static storage duration is built up
3651 in reverse order. We clear STATIC_AGGREGATES so that any new
3652 aggregates added during the initialization of these will be
3653 initialized in the correct order when we next come around the
3655 vars
= prune_vars_needing_no_initialization (static_aggregates
);
3656 static_aggregates
= NULL_TREE
;
3662 /* We need to start a new initialization function each time
3663 through the loop. That's because we need to know which
3664 vtables have been referenced, and TREE_SYMBOL_REFERENCED
3665 isn't computed until a function is finished, and written
3666 out. That's a deficiency in the back-end. When this is
3667 fixed, these initialization functions could all become
3668 inline, with resulting performance improvements. */
3669 tree ssdf_body
= start_static_storage_duration_function ();
3671 /* Make sure the back end knows about all the variables. */
3672 write_out_vars (vars
);
3674 /* First generate code to do all the initializations. */
3675 for (v
= vars
; v
; v
= TREE_CHAIN (v
))
3676 do_static_initialization (TREE_VALUE (v
),
3679 /* Then, generate code to do all the destructions. Do these
3680 in reverse order so that the most recently constructed
3681 variable is the first destroyed. If we're using
3682 __cxa_atexit, then we don't need to do this; functions
3683 were registered at initialization time to destroy the
3685 if (!flag_use_cxa_atexit
)
3687 vars
= nreverse (vars
);
3688 for (v
= vars
; v
; v
= TREE_CHAIN (v
))
3689 do_static_destruction (TREE_VALUE (v
));
3694 /* Finish up the static storage duration function for this
3696 finish_static_storage_duration_function (ssdf_body
);
3698 /* All those initializations and finalizations might cause
3699 us to need more inline functions, more template
3700 instantiations, etc. */
3704 /* Go through the various inline functions, and see if any need
3706 for (i
= 0; i
< deferred_fns_used
; ++i
)
3708 tree decl
= VARRAY_TREE (deferred_fns
, i
);
3709 import_export_decl (decl
);
3710 if (DECL_ARTIFICIAL (decl
) && ! DECL_INITIAL (decl
)
3712 && (! DECL_REALLY_EXTERN (decl
) || DECL_INLINE (decl
)))
3714 /* Even though we're already at the top-level, we push
3715 there again. That way, when we pop back a few lines
3716 hence, all of our state is restored. Otherwise,
3717 finish_function doesn't clean things up, and we end
3718 up with CURRENT_FUNCTION_DECL set. */
3719 push_to_top_level ();
3720 if (DECL_TINFO_FN_P (decl
))
3721 synthesize_tinfo_fn (decl
);
3723 synthesize_method (decl
);
3724 pop_from_top_level ();
3729 /* Mark all functions that might deal with exception-handling as
3731 mark_all_runtime_matches ();
3733 /* We lie to the back-end, pretending that some functions are
3734 not defined when they really are. This keeps these functions
3735 from being put out unnecessarily. But, we must stop lying
3736 when the functions are referenced, or if they are not comdat
3737 since they need to be put out now. */
3738 for (i
= 0; i
< deferred_fns_used
; ++i
)
3740 tree decl
= VARRAY_TREE (deferred_fns
, i
);
3742 if (DECL_NOT_REALLY_EXTERN (decl
)
3743 && DECL_INITIAL (decl
)
3744 && DECL_NEEDED_P (decl
))
3745 DECL_EXTERNAL (decl
) = 0;
3747 /* If we're going to need to write this function out, and
3748 there's already a body for it, create RTL for it now.
3749 (There might be no body if this is a method we haven't
3750 gotten around to synthesizing yet.) */
3751 if (!DECL_EXTERNAL (decl
)
3752 && DECL_NEEDED_P (decl
)
3753 && DECL_SAVED_TREE (decl
)
3754 && !DECL_SAVED_INSNS (decl
)
3755 && !TREE_ASM_WRITTEN (decl
))
3757 int saved_not_really_extern
;
3759 /* When we call finish_function in expand_body, it will
3760 try to reset DECL_NOT_REALLY_EXTERN so we save and
3762 saved_not_really_extern
= DECL_NOT_REALLY_EXTERN (decl
);
3763 /* Generate RTL for this function now that we know we
3766 /* Undo the damage done by finish_function. */
3767 DECL_EXTERNAL (decl
) = 0;
3768 DECL_NOT_REALLY_EXTERN (decl
) = saved_not_really_extern
;
3769 /* If we're compiling -fsyntax-only pretend that this
3770 function has been written out so that we don't try to
3772 if (flag_syntax_only
)
3773 TREE_ASM_WRITTEN (decl
) = 1;
3778 if (deferred_fns_used
3779 && wrapup_global_declarations (&VARRAY_TREE (deferred_fns
, 0),
3782 if (walk_namespaces (wrapup_globals_for_namespace
, /*data=*/0))
3785 /* Static data members are just like namespace-scope globals. */
3786 for (i
= 0; i
< pending_statics_used
; ++i
)
3788 tree decl
= VARRAY_TREE (pending_statics
, i
);
3789 if (TREE_ASM_WRITTEN (decl
))
3791 import_export_decl (decl
);
3792 if (DECL_NOT_REALLY_EXTERN (decl
) && ! DECL_IN_AGGR_P (decl
))
3793 DECL_EXTERNAL (decl
) = 0;
3796 && wrapup_global_declarations (&VARRAY_TREE (pending_statics
, 0),
3797 pending_statics_used
))
3802 /* We give C linkage to static constructors and destructors. */
3803 push_lang_context (lang_name_c
);
3805 /* Generate initialization and destruction functions for all
3806 priorities for which they are required. */
3807 if (priority_info_map
)
3808 splay_tree_foreach (priority_info_map
,
3809 generate_ctor_and_dtor_functions_for_priority
,
3812 /* We're done with the splay-tree now. */
3813 if (priority_info_map
)
3814 splay_tree_delete (priority_info_map
);
3816 /* We're done with static constructors, so we can go back to "C++"
3818 pop_lang_context ();
3820 /* Now delete from the chain of variables all virtual function tables.
3821 We output them all ourselves, because each will be treated
3822 specially. We don't do this if we're just doing semantic
3823 analysis, and not code-generation. */
3824 if (!flag_syntax_only
)
3825 walk_globals (vtable_decl_p
, prune_vtable_vardecl
, /*data=*/0);
3827 /* Now, issue warnings about static, but not defined, functions,
3828 etc., and emit debugging information. */
3829 walk_namespaces (wrapup_globals_for_namespace
, /*data=*/&reconsider
);
3830 if (pending_statics
)
3831 check_global_declarations (&VARRAY_TREE (pending_statics
, 0),
3832 pending_statics_used
);
3836 /* The entire file is now complete. If requested, dump everything
3838 if (flag_dump_translation_unit
)
3839 dump_node_to_file (global_namespace
, flag_dump_translation_unit
);
3841 /* If there's some tool that wants to examine the entire translation
3842 unit, let it do so now. */
3844 (*back_end_hook
) (global_namespace
);
3846 timevar_pop (TV_VARCONST
);
3848 if (flag_detailed_statistics
)
3850 dump_tree_statistics ();
3851 dump_time_statistics ();
3855 /* This is something of the form 'A()()()()()+1' that has turned out to be an
3856 expr. Since it was parsed like a type, we need to wade through and fix
3857 that. Unfortunately, since operator() is left-associative, we can't use
3858 tail recursion. In the above example, TYPE is `A', and DECL is
3861 Maybe this shouldn't be recursive, but how often will it actually be
3865 reparse_absdcl_as_expr (type
, decl
)
3868 /* do build_functional_cast (type, NULL_TREE) at bottom */
3869 if (TREE_OPERAND (decl
, 0) == NULL_TREE
)
3870 return build_functional_cast (type
, NULL_TREE
);
3873 decl
= reparse_absdcl_as_expr (type
, TREE_OPERAND (decl
, 0));
3875 decl
= build_x_function_call (decl
, NULL_TREE
, current_class_ref
);
3877 if (TREE_CODE (decl
) == CALL_EXPR
3878 && (! TREE_TYPE (decl
)
3879 || TREE_CODE (TREE_TYPE (decl
)) != VOID_TYPE
))
3880 decl
= require_complete_type (decl
);
3885 /* This is something of the form `int ((int)(int)(int)1)' that has turned
3886 out to be an expr. Since it was parsed like a type, we need to wade
3887 through and fix that. Since casts are right-associative, we are
3888 reversing the order, so we don't have to recurse.
3890 In the above example, DECL is the `(int)(int)(int)', and EXPR is the
3894 reparse_absdcl_as_casts (decl
, expr
)
3899 if (TREE_CODE (expr
) == CONSTRUCTOR
3900 && TREE_TYPE (expr
) == 0)
3902 type
= groktypename (TREE_VALUE (CALL_DECLARATOR_PARMS (decl
)));
3903 decl
= TREE_OPERAND (decl
, 0);
3905 expr
= digest_init (type
, expr
, (tree
*) 0);
3906 if (TREE_CODE (type
) == ARRAY_TYPE
&& !COMPLETE_TYPE_P (type
))
3908 int failure
= complete_array_type (type
, expr
, 1);
3910 my_friendly_abort (78);
3916 type
= groktypename (TREE_VALUE (CALL_DECLARATOR_PARMS (decl
)));
3917 decl
= TREE_OPERAND (decl
, 0);
3918 expr
= build_c_cast (type
, expr
);
3921 if (warn_old_style_cast
&& ! in_system_header
3922 && current_lang_name
!= lang_name_c
)
3923 warning ("use of old-style cast");
3928 /* Given plain tree nodes for an expression, build up the full semantics. */
3931 build_expr_from_tree (t
)
3934 if (t
== NULL_TREE
|| t
== error_mark_node
)
3937 switch (TREE_CODE (t
))
3939 case IDENTIFIER_NODE
:
3940 return do_identifier (t
, 0, NULL_TREE
);
3943 if (LOOKUP_EXPR_GLOBAL (t
))
3944 return do_scoped_id (TREE_OPERAND (t
, 0), 0);
3946 return do_identifier (TREE_OPERAND (t
, 0), 0, NULL_TREE
);
3948 case TEMPLATE_ID_EXPR
:
3949 return (lookup_template_function
3950 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3951 build_expr_from_tree (TREE_OPERAND (t
, 1))));
3954 return build_x_indirect_ref
3955 (build_expr_from_tree (TREE_OPERAND (t
, 0)), "unary *");
3958 return build_functional_cast
3959 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3961 case REINTERPRET_CAST_EXPR
:
3962 return build_reinterpret_cast
3963 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3965 case CONST_CAST_EXPR
:
3966 return build_const_cast
3967 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3969 case DYNAMIC_CAST_EXPR
:
3970 return build_dynamic_cast
3971 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3973 case STATIC_CAST_EXPR
:
3974 return build_static_cast
3975 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3977 case PREDECREMENT_EXPR
:
3978 case PREINCREMENT_EXPR
:
3979 case POSTDECREMENT_EXPR
:
3980 case POSTINCREMENT_EXPR
:
3984 case TRUTH_NOT_EXPR
:
3986 case CONVERT_EXPR
: /* Unary + */
3991 return build_x_unary_op (TREE_CODE (t
),
3992 build_expr_from_tree (TREE_OPERAND (t
, 0)));
3997 case TRUNC_DIV_EXPR
:
3999 case FLOOR_DIV_EXPR
:
4000 case ROUND_DIV_EXPR
:
4001 case EXACT_DIV_EXPR
:
4003 case BIT_ANDTC_EXPR
:
4006 case TRUNC_MOD_EXPR
:
4007 case FLOOR_MOD_EXPR
:
4008 case TRUTH_ANDIF_EXPR
:
4009 case TRUTH_ORIF_EXPR
:
4010 case TRUTH_AND_EXPR
:
4025 return build_x_binary_op
4027 build_expr_from_tree (TREE_OPERAND (t
, 0)),
4028 build_expr_from_tree (TREE_OPERAND (t
, 1)));
4031 return build_m_component_ref
4032 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
4033 build_expr_from_tree (TREE_OPERAND (t
, 1)));
4036 return build_offset_ref (TREE_OPERAND (t
, 0), TREE_OPERAND (t
, 1));
4039 if (TREE_OPERAND (t
, 0) == NULL_TREE
)
4041 return build_parse_node (ARRAY_REF
, NULL_TREE
,
4042 build_expr_from_tree (TREE_OPERAND (t
, 1)));
4043 return grok_array_decl (build_expr_from_tree (TREE_OPERAND (t
, 0)),
4044 build_expr_from_tree (TREE_OPERAND (t
, 1)));
4049 tree r
= build_expr_from_tree (TREE_OPERAND (t
, 0));
4052 return TREE_CODE (t
) == SIZEOF_EXPR
? c_sizeof (r
) : c_alignof (r
);
4056 return build_x_modify_expr
4057 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
4058 TREE_CODE (TREE_OPERAND (t
, 1)),
4059 build_expr_from_tree (TREE_OPERAND (t
, 2)));
4062 return build_x_arrow
4063 (build_expr_from_tree (TREE_OPERAND (t
, 0)));
4067 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
4068 build_expr_from_tree (TREE_OPERAND (t
, 1)),
4069 build_expr_from_tree (TREE_OPERAND (t
, 2)),
4070 NEW_EXPR_USE_GLOBAL (t
));
4073 return delete_sanity
4074 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
4075 build_expr_from_tree (TREE_OPERAND (t
, 1)),
4076 DELETE_EXPR_USE_VEC (t
), DELETE_EXPR_USE_GLOBAL (t
));
4079 if (TREE_OPERAND (t
, 1) == NULL_TREE
)
4080 return build_x_compound_expr
4081 (build_expr_from_tree (TREE_OPERAND (t
, 0)));
4083 my_friendly_abort (42);
4085 case METHOD_CALL_EXPR
:
4086 if (TREE_CODE (TREE_OPERAND (t
, 0)) == SCOPE_REF
)
4088 tree ref
= TREE_OPERAND (t
, 0);
4089 tree name
= TREE_OPERAND (ref
, 1);
4091 if (TREE_CODE (name
) == TEMPLATE_ID_EXPR
)
4092 name
= build_nt (TEMPLATE_ID_EXPR
,
4093 TREE_OPERAND (name
, 0),
4094 build_expr_from_tree (TREE_OPERAND (name
, 1)));
4096 return build_scoped_method_call
4097 (build_expr_from_tree (TREE_OPERAND (t
, 1)),
4098 build_expr_from_tree (TREE_OPERAND (ref
, 0)),
4100 build_expr_from_tree (TREE_OPERAND (t
, 2)));
4104 tree fn
= TREE_OPERAND (t
, 0);
4106 /* We can get a TEMPLATE_ID_EXPR here on code like:
4110 so we must resolve that. However, we can also get things
4111 like a BIT_NOT_EXPR here, when referring to a destructor,
4112 and things like that are not correctly resolved by
4113 build_expr_from_tree. So, just use build_expr_from_tree
4114 when we really need it. */
4115 if (TREE_CODE (fn
) == TEMPLATE_ID_EXPR
)
4116 fn
= lookup_template_function
4117 (TREE_OPERAND (fn
, 0),
4118 build_expr_from_tree (TREE_OPERAND (fn
, 1)));
4120 return build_method_call
4121 (build_expr_from_tree (TREE_OPERAND (t
, 1)),
4123 build_expr_from_tree (TREE_OPERAND (t
, 2)),
4124 NULL_TREE
, LOOKUP_NORMAL
);
4128 if (TREE_CODE (TREE_OPERAND (t
, 0)) == SCOPE_REF
)
4130 tree ref
= TREE_OPERAND (t
, 0);
4131 tree name
= TREE_OPERAND (ref
, 1);
4133 if (TREE_CODE (name
) == TEMPLATE_ID_EXPR
)
4134 name
= build_nt (TEMPLATE_ID_EXPR
,
4135 TREE_OPERAND (name
, 0),
4136 build_expr_from_tree (TREE_OPERAND (name
, 1)));
4138 return build_member_call
4139 (build_expr_from_tree (TREE_OPERAND (ref
, 0)),
4141 build_expr_from_tree (TREE_OPERAND (t
, 1)));
4145 tree name
= TREE_OPERAND (t
, 0);
4147 tree args
= build_expr_from_tree (TREE_OPERAND (t
, 1));
4148 if (args
!= NULL_TREE
&& TREE_CODE (name
) == LOOKUP_EXPR
4149 && !LOOKUP_EXPR_GLOBAL (name
)
4150 && TREE_CODE ((id
= TREE_OPERAND (name
, 0))) == IDENTIFIER_NODE
4151 && (!current_class_type
4152 || !lookup_member (current_class_type
, id
, 0, 0)))
4154 /* Do Koenig lookup if there are no class members. */
4155 name
= do_identifier (id
, 0, args
);
4157 else if (TREE_CODE (name
) == TEMPLATE_ID_EXPR
4158 || ! really_overloaded_fn (name
))
4159 name
= build_expr_from_tree (name
);
4160 return build_x_function_call (name
, args
, current_class_ref
);
4164 return build_x_conditional_expr
4165 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
4166 build_expr_from_tree (TREE_OPERAND (t
, 1)),
4167 build_expr_from_tree (TREE_OPERAND (t
, 2)));
4169 case PSEUDO_DTOR_EXPR
:
4170 return (finish_pseudo_destructor_call_expr
4171 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
4172 build_expr_from_tree (TREE_OPERAND (t
, 1)),
4173 build_expr_from_tree (TREE_OPERAND (t
, 2))));
4177 tree purpose
, value
, chain
;
4179 if (t
== void_list_node
)
4182 purpose
= TREE_PURPOSE (t
);
4184 purpose
= build_expr_from_tree (purpose
);
4185 value
= TREE_VALUE (t
);
4187 value
= build_expr_from_tree (value
);
4188 chain
= TREE_CHAIN (t
);
4189 if (chain
&& chain
!= void_type_node
)
4190 chain
= build_expr_from_tree (chain
);
4191 return tree_cons (purpose
, value
, chain
);
4196 tree object
= build_expr_from_tree (TREE_OPERAND (t
, 0));
4197 tree field
= TREE_OPERAND (t
, 1);
4199 /* We use a COMPONENT_REF to indicate things of the form `x.b'
4200 and `x.A::b'. We must distinguish between those cases
4202 if (TREE_CODE (field
) == SCOPE_REF
)
4203 return build_object_ref (object
,
4204 TREE_OPERAND (field
, 0),
4205 TREE_OPERAND (field
, 1));
4207 return build_x_component_ref (object
, field
,
4212 return build_throw (build_expr_from_tree (TREE_OPERAND (t
, 0)));
4218 /* digest_init will do the wrong thing if we let it. */
4219 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
4222 r
= build_nt (CONSTRUCTOR
, NULL_TREE
,
4223 build_expr_from_tree (CONSTRUCTOR_ELTS (t
)));
4224 TREE_HAS_CONSTRUCTOR (r
) = TREE_HAS_CONSTRUCTOR (t
);
4227 return digest_init (TREE_TYPE (t
), r
, 0);
4232 if (TYPE_P (TREE_OPERAND (t
, 0)))
4233 return get_typeid (TREE_OPERAND (t
, 0));
4234 return build_typeid (build_expr_from_tree (TREE_OPERAND (t
, 0)));
4237 return convert_from_reference (t
);
4240 return build_va_arg (build_expr_from_tree (TREE_OPERAND (t
, 0)),
4248 /* This is something of the form `int (*a)++' that has turned out to be an
4249 expr. It was only converted into parse nodes, so we need to go through
4250 and build up the semantics. Most of the work is done by
4251 build_expr_from_tree, above.
4253 In the above example, TYPE is `int' and DECL is `*a'. */
4256 reparse_decl_as_expr (type
, decl
)
4259 decl
= build_expr_from_tree (decl
);
4261 return build_functional_cast (type
, build_tree_list (NULL_TREE
, decl
));
4266 /* This is something of the form `int (*a)' that has turned out to be a
4267 decl. It was only converted into parse nodes, so we need to do the
4268 checking that make_{pointer,reference}_declarator do. */
4271 finish_decl_parsing (decl
)
4274 extern int current_class_depth
;
4276 switch (TREE_CODE (decl
))
4278 case IDENTIFIER_NODE
:
4281 return make_pointer_declarator
4282 (NULL_TREE
, finish_decl_parsing (TREE_OPERAND (decl
, 0)));
4284 return make_reference_declarator
4285 (NULL_TREE
, finish_decl_parsing (TREE_OPERAND (decl
, 0)));
4287 TREE_OPERAND (decl
, 0) = finish_decl_parsing (TREE_OPERAND (decl
, 0));
4290 push_nested_class (TREE_TYPE (TREE_OPERAND (decl
, 0)), 3);
4291 TREE_COMPLEXITY (decl
) = current_class_depth
;
4294 TREE_OPERAND (decl
, 0) = finish_decl_parsing (TREE_OPERAND (decl
, 0));
4297 /* For attribute handling. */
4298 TREE_VALUE (decl
) = finish_decl_parsing (TREE_VALUE (decl
));
4300 case TEMPLATE_ID_EXPR
:
4303 my_friendly_abort (5);
4308 /* Return 1 if root encloses child. */
4311 is_namespace_ancestor (root
, child
)
4316 if (root
== global_namespace
)
4318 if (child
== global_namespace
)
4320 return is_namespace_ancestor (root
, CP_DECL_CONTEXT (child
));
4324 /* Return the namespace that is the common ancestor
4325 of two given namespaces. */
4328 namespace_ancestor (ns1
, ns2
)
4331 if (is_namespace_ancestor (ns1
, ns2
))
4333 return namespace_ancestor (CP_DECL_CONTEXT (ns1
), ns2
);
4336 /* Insert used into the using list of user. Set indirect_flag if this
4337 directive is not directly from the source. Also find the common
4338 ancestor and let our users know about the new namespace */
4340 add_using_namespace (user
, used
, indirect
)
4346 /* Using oneself is a no-op. */
4349 my_friendly_assert (TREE_CODE (user
) == NAMESPACE_DECL
, 380);
4350 my_friendly_assert (TREE_CODE (used
) == NAMESPACE_DECL
, 380);
4351 /* Check if we already have this. */
4352 t
= purpose_member (used
, DECL_NAMESPACE_USING (user
));
4356 /* Promote to direct usage. */
4357 TREE_INDIRECT_USING (t
) = 0;
4361 /* Add used to the user's using list. */
4362 DECL_NAMESPACE_USING (user
)
4363 = tree_cons (used
, namespace_ancestor (user
, used
),
4364 DECL_NAMESPACE_USING (user
));
4366 TREE_INDIRECT_USING (DECL_NAMESPACE_USING (user
)) = indirect
;
4368 /* Add user to the used's users list. */
4369 DECL_NAMESPACE_USERS (used
)
4370 = tree_cons (user
, 0, DECL_NAMESPACE_USERS (used
));
4372 /* Recursively add all namespaces used. */
4373 for (t
= DECL_NAMESPACE_USING (used
); t
; t
= TREE_CHAIN (t
))
4374 /* indirect usage */
4375 add_using_namespace (user
, TREE_PURPOSE (t
), 1);
4377 /* Tell everyone using us about the new used namespaces. */
4378 for (t
= DECL_NAMESPACE_USERS (user
); t
; t
= TREE_CHAIN (t
))
4379 add_using_namespace (TREE_PURPOSE (t
), used
, 1);
4382 /* Combines two sets of overloaded functions into an OVERLOAD chain, removing
4383 duplicates. The first list becomes the tail of the result.
4385 The algorithm is O(n^2). We could get this down to O(n log n) by
4386 doing a sort on the addresses of the functions, if that becomes
4390 merge_functions (s1
, s2
)
4394 for (; s2
; s2
= OVL_NEXT (s2
))
4396 tree fn
= OVL_CURRENT (s2
);
4397 if (! ovl_member (fn
, s1
))
4398 s1
= build_overload (fn
, s1
);
4403 /* This should return an error not all definitions define functions.
4404 It is not an error if we find two functions with exactly the
4405 same signature, only if these are selected in overload resolution.
4406 old is the current set of bindings, new the freshly-found binding.
4407 XXX Do we want to give *all* candidates in case of ambiguity?
4408 XXX In what way should I treat extern declarations?
4409 XXX I don't want to repeat the entire duplicate_decls here */
4412 ambiguous_decl (name
, old
, new, flags
)
4419 my_friendly_assert (old
!= NULL_TREE
, 393);
4420 /* Copy the value. */
4421 val
= BINDING_VALUE (new);
4423 switch (TREE_CODE (val
))
4426 /* If we expect types or namespaces, and not templates,
4427 or this is not a template class. */
4428 if (LOOKUP_QUALIFIERS_ONLY (flags
)
4429 && !DECL_CLASS_TEMPLATE_P (val
))
4433 if (LOOKUP_NAMESPACES_ONLY (flags
))
4436 case NAMESPACE_DECL
:
4437 if (LOOKUP_TYPES_ONLY (flags
))
4441 if (LOOKUP_QUALIFIERS_ONLY (flags
))
4445 if (!BINDING_VALUE (old
))
4446 BINDING_VALUE (old
) = val
;
4447 else if (val
&& val
!= BINDING_VALUE (old
))
4449 if (is_overloaded_fn (BINDING_VALUE (old
))
4450 && is_overloaded_fn (val
))
4452 BINDING_VALUE (old
) = merge_functions (BINDING_VALUE (old
),
4457 /* Some declarations are functions, some are not. */
4458 if (flags
& LOOKUP_COMPLAIN
)
4460 /* If we've already given this error for this lookup,
4461 BINDING_VALUE (old) is error_mark_node, so let's not
4462 repeat ourselves. */
4463 if (BINDING_VALUE (old
) != error_mark_node
)
4465 cp_error ("use of `%D' is ambiguous", name
);
4466 cp_error_at (" first declared as `%#D' here",
4467 BINDING_VALUE (old
));
4469 cp_error_at (" also declared as `%#D' here", val
);
4471 BINDING_VALUE (old
) = error_mark_node
;
4474 /* ... and copy the type. */
4475 type
= BINDING_TYPE (new);
4476 if (LOOKUP_NAMESPACES_ONLY (flags
))
4478 if (!BINDING_TYPE (old
))
4479 BINDING_TYPE (old
) = type
;
4480 else if (type
&& BINDING_TYPE (old
) != type
)
4482 if (flags
& LOOKUP_COMPLAIN
)
4484 cp_error ("`%D' denotes an ambiguous type",name
);
4485 cp_error_at (" first type here", BINDING_TYPE (old
));
4486 cp_error_at (" other type here", type
);
4492 /* Subroutine of unualified_namespace_lookup:
4493 Add the bindings of NAME in used namespaces to VAL.
4494 We are currently looking for names in namespace SCOPE, so we
4495 look through USINGS for using-directives of namespaces
4496 which have SCOPE as a common ancestor with the current scope.
4497 Returns zero on errors. */
4500 lookup_using_namespace (name
, val
, usings
, scope
, flags
, spacesp
)
4501 tree name
, val
, usings
, scope
;
4507 /* Iterate over all used namespaces in current, searching for using
4508 directives of scope. */
4509 for (iter
= usings
; iter
; iter
= TREE_CHAIN (iter
))
4510 if (TREE_VALUE (iter
) == scope
)
4513 *spacesp
= tree_cons (TREE_PURPOSE (iter
), NULL_TREE
,
4515 val1
= binding_for_name (name
, TREE_PURPOSE (iter
));
4516 /* Resolve ambiguities. */
4517 val
= ambiguous_decl (name
, val
, val1
, flags
);
4519 return BINDING_VALUE (val
) != error_mark_node
;
4523 Accepts the NAME to lookup and its qualifying SCOPE.
4524 Returns the name/type pair found into the CPLUS_BINDING RESULT,
4528 qualified_lookup_using_namespace (name
, scope
, result
, flags
)
4534 /* Maintain a list of namespaces visited... */
4535 tree seen
= NULL_TREE
;
4536 /* ... and a list of namespace yet to see. */
4537 tree todo
= NULL_TREE
;
4539 /* Look through namespace aliases. */
4540 scope
= ORIGINAL_NAMESPACE (scope
);
4541 while (scope
&& (result
!= error_mark_node
))
4543 seen
= tree_cons (scope
, NULL_TREE
, seen
);
4544 result
= ambiguous_decl (name
, result
,
4545 binding_for_name (name
, scope
), flags
);
4546 if (!BINDING_VALUE (result
) && !BINDING_TYPE (result
))
4547 /* Consider using directives. */
4548 for (usings
= DECL_NAMESPACE_USING (scope
); usings
;
4549 usings
= TREE_CHAIN (usings
))
4550 /* If this was a real directive, and we have not seen it. */
4551 if (!TREE_INDIRECT_USING (usings
)
4552 && !purpose_member (TREE_PURPOSE (usings
), seen
))
4553 todo
= tree_cons (TREE_PURPOSE (usings
), NULL_TREE
, todo
);
4556 scope
= TREE_PURPOSE (todo
);
4557 todo
= TREE_CHAIN (todo
);
4560 scope
= NULL_TREE
; /* If there never was a todo list. */
4562 return result
!= error_mark_node
;
4565 /* [namespace.memdef]/2 */
4567 /* Set the context of a declaration to scope. Complain if we are not
4571 set_decl_namespace (decl
, scope
, friendp
)
4577 if (scope
== fake_std_node
)
4578 scope
= global_namespace
;
4579 /* Get rid of namespace aliases. */
4580 scope
= ORIGINAL_NAMESPACE (scope
);
4582 /* It is ok for friends to be qualified in parallel space. */
4583 if (!friendp
&& !is_namespace_ancestor (current_namespace
, scope
))
4584 cp_error ("declaration of `%D' not in a namespace surrounding `%D'",
4586 DECL_CONTEXT (decl
) = FROB_CONTEXT (scope
);
4587 if (scope
!= current_namespace
)
4589 /* See whether this has been declared in the namespace. */
4590 old
= namespace_binding (DECL_NAME (decl
), scope
);
4592 /* No old declaration at all. */
4594 if (!is_overloaded_fn (decl
))
4595 /* Don't compare non-function decls with decls_match here,
4596 since it can't check for the correct constness at this
4597 point. pushdecl will find those errors later. */
4599 /* Since decl is a function, old should contain a function decl. */
4600 if (!is_overloaded_fn (old
))
4602 if (processing_template_decl
|| processing_specialization
)
4603 /* We have not yet called push_template_decl to turn the
4604 FUNCTION_DECL into a TEMPLATE_DECL, so the declarations
4605 won't match. But, we'll check later, when we construct the
4608 for (; old
; old
= OVL_NEXT (old
))
4609 if (decls_match (decl
, OVL_CURRENT (old
)))
4615 cp_error ("`%D' should have been declared inside `%D'",
4619 /* Compute the namespace where a declaration is defined. */
4622 decl_namespace (decl
)
4626 decl
= TYPE_STUB_DECL (decl
);
4627 while (DECL_CONTEXT (decl
))
4629 decl
= DECL_CONTEXT (decl
);
4630 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
4633 decl
= TYPE_STUB_DECL (decl
);
4634 my_friendly_assert (DECL_P (decl
), 390);
4637 return global_namespace
;
4640 /* Return the namespace where the current declaration is declared. */
4643 current_decl_namespace ()
4646 /* If we have been pushed into a different namespace, use it. */
4647 if (decl_namespace_list
)
4648 return TREE_PURPOSE (decl_namespace_list
);
4650 if (current_class_type
)
4651 result
= decl_namespace (TYPE_STUB_DECL (current_class_type
));
4652 else if (current_function_decl
)
4653 result
= decl_namespace (current_function_decl
);
4655 result
= current_namespace
;
4659 /* Temporarily set the namespace for the current declaration. */
4662 push_decl_namespace (decl
)
4665 if (TREE_CODE (decl
) != NAMESPACE_DECL
)
4666 decl
= decl_namespace (decl
);
4667 decl_namespace_list
= tree_cons (ORIGINAL_NAMESPACE (decl
),
4668 NULL_TREE
, decl_namespace_list
);
4672 pop_decl_namespace ()
4674 decl_namespace_list
= TREE_CHAIN (decl_namespace_list
);
4677 /* Enter a class or namespace scope. */
4683 if (TREE_CODE (t
) == NAMESPACE_DECL
)
4684 push_decl_namespace (t
);
4689 /* Leave scope pushed by push_scope. */
4695 if (TREE_CODE (t
) == NAMESPACE_DECL
)
4696 pop_decl_namespace ();
4701 /* [basic.lookup.koenig] */
4702 /* A non-zero return value in the functions below indicates an error.
4703 All nodes allocated in the procedure are on the scratch obstack. */
4713 static int arg_assoc
PARAMS ((struct arg_lookup
*, tree
));
4714 static int arg_assoc_args
PARAMS ((struct arg_lookup
*, tree
));
4715 static int arg_assoc_type
PARAMS ((struct arg_lookup
*, tree
));
4716 static int add_function
PARAMS ((struct arg_lookup
*, tree
));
4717 static int arg_assoc_namespace
PARAMS ((struct arg_lookup
*, tree
));
4718 static int arg_assoc_class
PARAMS ((struct arg_lookup
*, tree
));
4719 static int arg_assoc_template_arg
PARAMS ((struct arg_lookup
*, tree
));
4721 /* Add a function to the lookup structure.
4722 Returns 1 on error. */
4725 add_function (k
, fn
)
4726 struct arg_lookup
*k
;
4729 /* We used to check here to see if the function was already in the list,
4730 but that's O(n^2), which is just too expensive for function lookup.
4731 Now we deal with the occasional duplicate in joust. In doing this, we
4732 assume that the number of duplicates will be small compared to the
4733 total number of functions being compared, which should usually be the
4736 /* We must find only functions, or exactly one non-function. */
4739 else if (is_overloaded_fn (k
->functions
) && is_overloaded_fn (fn
))
4740 k
->functions
= build_overload (fn
, k
->functions
);
4743 tree f1
= OVL_CURRENT (k
->functions
);
4745 if (is_overloaded_fn (f1
))
4747 fn
= f1
; f1
= f2
; f2
= fn
;
4749 cp_error_at ("`%D' is not a function,", f1
);
4750 cp_error_at (" conflict with `%D'", f2
);
4751 cp_error (" in call to `%D'", k
->name
);
4758 /* Add functions of a namespace to the lookup structure.
4759 Returns 1 on error. */
4762 arg_assoc_namespace (k
, scope
)
4763 struct arg_lookup
*k
;
4768 if (purpose_member (scope
, k
->namespaces
))
4770 k
->namespaces
= tree_cons (scope
, NULL_TREE
, k
->namespaces
);
4772 value
= namespace_binding (k
->name
, scope
);
4776 for (; value
; value
= OVL_NEXT (value
))
4777 if (add_function (k
, OVL_CURRENT (value
)))
4783 /* Adds everything associated with a template argument to the lookup
4784 structure. Returns 1 on error. */
4787 arg_assoc_template_arg (k
, arg
)
4788 struct arg_lookup
* k
;
4791 /* [basic.lookup.koenig]
4793 If T is a template-id, its associated namespaces and classes are
4794 ... the namespaces and classes associated with the types of the
4795 template arguments provided for template type parameters
4796 (excluding template template parameters); the namespaces in which
4797 any template template arguments are defined; and the classes in
4798 which any member templates used as template template arguments
4799 are defined. [Note: non-type template arguments do not
4800 contribute to the set of associated namespaces. ] */
4802 /* Consider first template template arguments. */
4803 if (TREE_CODE (arg
) == TEMPLATE_TEMPLATE_PARM
)
4805 else if (TREE_CODE (arg
) == TEMPLATE_DECL
)
4807 tree ctx
= CP_DECL_CONTEXT (arg
);
4809 /* It's not a member template. */
4810 if (TREE_CODE (ctx
) == NAMESPACE_DECL
)
4811 return arg_assoc_namespace (k
, ctx
);
4812 /* Otherwise, it must be member template. */
4814 return arg_assoc_class (k
, ctx
);
4816 /* It's not a template template argument, but it is a type template
4818 else if (TYPE_P (arg
))
4819 return arg_assoc_type (k
, arg
);
4820 /* It's a non-type template argument. */
4825 /* Adds everything associated with class to the lookup structure.
4826 Returns 1 on error. */
4829 arg_assoc_class (k
, type
)
4830 struct arg_lookup
* k
;
4833 tree list
, friends
, context
;
4836 /* Backend build structures, such as __builtin_va_list, aren't
4837 affected by all this. */
4838 if (!CLASS_TYPE_P (type
))
4841 if (purpose_member (type
, k
->classes
))
4843 k
->classes
= tree_cons (type
, NULL_TREE
, k
->classes
);
4845 context
= decl_namespace (TYPE_MAIN_DECL (type
));
4846 if (arg_assoc_namespace (k
, context
))
4849 /* Process baseclasses. */
4850 for (i
= 0; i
< CLASSTYPE_N_BASECLASSES (type
); i
++)
4851 if (arg_assoc_class (k
, TYPE_BINFO_BASETYPE (type
, i
)))
4854 /* Process friends. */
4855 for (list
= DECL_FRIENDLIST (TYPE_MAIN_DECL (type
)); list
;
4856 list
= TREE_CHAIN (list
))
4857 if (k
->name
== TREE_PURPOSE (list
))
4858 for (friends
= TREE_VALUE (list
); friends
;
4859 friends
= TREE_CHAIN (friends
))
4860 /* Only interested in global functions with potentially hidden
4861 (i.e. unqualified) declarations. */
4862 if (TREE_PURPOSE (list
) == error_mark_node
&& TREE_VALUE (list
)
4863 && decl_namespace (TREE_VALUE (list
)) == context
)
4864 if (add_function (k
, TREE_VALUE (list
)))
4867 /* Process template arguments. */
4868 if (CLASSTYPE_TEMPLATE_INFO (type
))
4870 list
= INNERMOST_TEMPLATE_ARGS (CLASSTYPE_TI_ARGS (type
));
4871 for (i
= 0; i
< TREE_VEC_LENGTH (list
); ++i
)
4872 arg_assoc_template_arg (k
, TREE_VEC_ELT (list
, i
));
4878 /* Adds everything associated with a given type.
4879 Returns 1 on error. */
4882 arg_assoc_type (k
, type
)
4883 struct arg_lookup
*k
;
4886 switch (TREE_CODE (type
))
4897 if (TYPE_PTRMEMFUNC_P (type
))
4898 return arg_assoc_type (k
, TYPE_PTRMEMFUNC_FN_TYPE (type
));
4899 return arg_assoc_class (k
, type
);
4901 case REFERENCE_TYPE
:
4903 return arg_assoc_type (k
, TREE_TYPE (type
));
4906 return arg_assoc_namespace (k
, decl_namespace (TYPE_MAIN_DECL (type
)));
4908 /* Pointer to member: associate class type and value type. */
4909 if (arg_assoc_type (k
, TYPE_OFFSET_BASETYPE (type
)))
4911 return arg_assoc_type (k
, TREE_TYPE (type
));
4913 /* The basetype is referenced in the first arg type, so just
4916 /* Associate the parameter types. */
4917 if (arg_assoc_args (k
, TYPE_ARG_TYPES (type
)))
4919 /* Associate the return type. */
4920 return arg_assoc_type (k
, TREE_TYPE (type
));
4921 case TEMPLATE_TYPE_PARM
:
4922 case BOUND_TEMPLATE_TEMPLATE_PARM
:
4927 if (type
== unknown_type_node
)
4929 /* else fall through */
4931 my_friendly_abort (390);
4936 /* Adds everything associated with arguments. Returns 1 on error. */
4939 arg_assoc_args (k
, args
)
4940 struct arg_lookup
* k
;
4943 for (; args
; args
= TREE_CHAIN (args
))
4944 if (arg_assoc (k
, TREE_VALUE (args
)))
4949 /* Adds everything associated with a given tree_node. Returns 1 on error. */
4953 struct arg_lookup
* k
;
4956 if (n
== error_mark_node
)
4960 return arg_assoc_type (k
, n
);
4962 if (! type_unknown_p (n
))
4963 return arg_assoc_type (k
, TREE_TYPE (n
));
4965 if (TREE_CODE (n
) == ADDR_EXPR
)
4966 n
= TREE_OPERAND (n
, 0);
4967 if (TREE_CODE (n
) == COMPONENT_REF
)
4968 n
= TREE_OPERAND (n
, 1);
4969 if (TREE_CODE (n
) == OFFSET_REF
)
4970 n
= TREE_OPERAND (n
, 1);
4971 while (TREE_CODE (n
) == TREE_LIST
)
4974 if (TREE_CODE (n
) == FUNCTION_DECL
)
4975 return arg_assoc_type (k
, TREE_TYPE (n
));
4976 if (TREE_CODE (n
) == TEMPLATE_ID_EXPR
)
4978 /* [basic.lookup.koenig]
4980 If T is a template-id, its associated namespaces and classes
4981 are the namespace in which the template is defined; for
4982 member templates, the member template's class... */
4983 tree
template = TREE_OPERAND (n
, 0);
4984 tree args
= TREE_OPERAND (n
, 1);
4988 if (TREE_CODE (template) == COMPONENT_REF
)
4989 template = TREE_OPERAND (template, 1);
4991 /* First, the template. There may actually be more than one if
4992 this is an overloaded function template. But, in that case,
4993 we only need the first; all the functions will be in the same
4995 template = OVL_CURRENT (template);
4997 ctx
= CP_DECL_CONTEXT (template);
4999 if (TREE_CODE (ctx
) == NAMESPACE_DECL
)
5001 if (arg_assoc_namespace (k
, ctx
) == 1)
5004 /* It must be a member template. */
5005 else if (arg_assoc_class (k
, ctx
) == 1)
5008 /* Now the arguments. */
5009 for (arg
= args
; arg
!= NULL_TREE
; arg
= TREE_CHAIN (arg
))
5010 if (arg_assoc_template_arg (k
, TREE_VALUE (arg
)) == 1)
5015 my_friendly_assert (TREE_CODE (n
) == OVERLOAD
, 980715);
5017 for (; n
; n
= OVL_CHAIN (n
))
5018 if (arg_assoc_type (k
, TREE_TYPE (OVL_FUNCTION (n
))))
5025 /* Performs Koenig lookup depending on arguments, where fns
5026 are the functions found in normal lookup. */
5029 lookup_arg_dependent (name
, fns
, args
)
5034 struct arg_lookup k
;
5035 tree fn
= NULL_TREE
;
5039 k
.classes
= NULL_TREE
;
5041 /* Note that we've already looked at some namespaces during normal
5042 unqualified lookup, unless we found a decl in function scope. */
5044 fn
= OVL_CURRENT (fns
);
5045 if (fn
&& TREE_CODE (fn
) == FUNCTION_DECL
&& DECL_LOCAL_FUNCTION_P (fn
))
5046 k
.namespaces
= NULL_TREE
;
5048 unqualified_namespace_lookup (name
, 0, &k
.namespaces
);
5050 arg_assoc_args (&k
, args
);
5054 /* Process a namespace-alias declaration. */
5057 do_namespace_alias (alias
, namespace)
5058 tree alias
, namespace;
5060 if (TREE_CODE (namespace) != NAMESPACE_DECL
)
5062 /* The parser did not find it, so it's not there. */
5063 cp_error ("unknown namespace `%D'", namespace);
5067 namespace = ORIGINAL_NAMESPACE (namespace);
5069 /* Build the alias. */
5070 alias
= build_lang_decl (NAMESPACE_DECL
, alias
, void_type_node
);
5071 DECL_NAMESPACE_ALIAS (alias
) = namespace;
5075 /* Check a non-member using-declaration. Return the name and scope
5076 being used, and the USING_DECL, or NULL_TREE on failure. */
5079 validate_nonmember_using_decl (decl
, scope
, name
)
5084 if (TREE_CODE (decl
) == SCOPE_REF
5085 && TREE_OPERAND (decl
, 0) == fake_std_node
)
5087 if (namespace_bindings_p ()
5088 && current_namespace
== global_namespace
)
5089 /* There's no need for a using declaration at all, here,
5090 since `std' is the same as `::'. We can't just pass this
5091 on because we'll complain later about declaring something
5092 in the same scope as a using declaration with the same
5093 name. We return NULL_TREE which indicates to the caller
5094 that there's no need to do any further processing. */
5097 *scope
= global_namespace
;
5098 *name
= TREE_OPERAND (decl
, 1);
5100 else if (TREE_CODE (decl
) == SCOPE_REF
)
5102 *scope
= TREE_OPERAND (decl
, 0);
5103 *name
= TREE_OPERAND (decl
, 1);
5105 /* [namespace.udecl]
5107 A using-declaration for a class member shall be a
5108 member-declaration. */
5109 if (TREE_CODE (*scope
) != NAMESPACE_DECL
)
5111 if (TYPE_P (*scope
))
5112 cp_error ("`%T' is not a namespace", *scope
);
5114 cp_error ("`%D' is not a namespace", *scope
);
5118 else if (TREE_CODE (decl
) == IDENTIFIER_NODE
5119 || TREE_CODE (decl
) == TYPE_DECL
5120 || TREE_CODE (decl
) == TEMPLATE_DECL
)
5122 *scope
= global_namespace
;
5126 my_friendly_abort (382);
5128 *name
= DECL_NAME (*name
);
5129 /* Make a USING_DECL. */
5130 return push_using_decl (*scope
, *name
);
5133 /* Process local and global using-declarations. */
5136 do_nonmember_using_decl (scope
, name
, oldval
, oldtype
, newval
, newtype
)
5138 tree oldval
, oldtype
;
5139 tree
*newval
, *newtype
;
5143 *newval
= *newtype
= NULL_TREE
;
5144 decls
= make_node (CPLUS_BINDING
);
5145 if (!qualified_lookup_using_namespace (name
, scope
, decls
, 0))
5149 if (!BINDING_VALUE (decls
) && !BINDING_TYPE (decls
))
5151 cp_error ("`%D' not declared", name
);
5155 /* Check for using functions. */
5156 if (BINDING_VALUE (decls
) && is_overloaded_fn (BINDING_VALUE (decls
)))
5160 if (oldval
&& !is_overloaded_fn (oldval
))
5162 duplicate_decls (OVL_CURRENT (BINDING_VALUE (decls
)), oldval
);
5167 for (tmp
= BINDING_VALUE (decls
); tmp
; tmp
= OVL_NEXT (tmp
))
5169 tree new_fn
= OVL_CURRENT (tmp
);
5171 /* [namespace.udecl]
5173 If a function declaration in namespace scope or block
5174 scope has the same name and the same parameter types as a
5175 function introduced by a using declaration the program is
5177 for (tmp1
= oldval
; tmp1
; tmp1
= OVL_NEXT (tmp1
))
5179 tree old_fn
= OVL_CURRENT (tmp1
);
5181 if (!OVL_USED (tmp1
)
5182 && compparms (TYPE_ARG_TYPES (TREE_TYPE (new_fn
)),
5183 TYPE_ARG_TYPES (TREE_TYPE (old_fn
))))
5185 if (!(DECL_EXTERN_C_P (new_fn
)
5186 && DECL_EXTERN_C_P (old_fn
)))
5187 /* There was already a non-using declaration in
5188 this scope with the same parameter types. */
5189 cp_error ("`%D' is already declared in this scope",
5193 else if (duplicate_decls (new_fn
, old_fn
))
5194 /* We're re-using something we already used
5195 before. We don't need to add it again. */
5199 /* If we broke out of the loop, there's no reason to add
5200 this function to the using declarations for this
5205 *newval
= build_overload (OVL_CURRENT (tmp
), *newval
);
5206 if (TREE_CODE (*newval
) != OVERLOAD
)
5207 *newval
= ovl_cons (*newval
, NULL_TREE
);
5208 OVL_USED (*newval
) = 1;
5213 *newval
= BINDING_VALUE (decls
);
5215 duplicate_decls (*newval
, oldval
);
5218 *newtype
= BINDING_TYPE (decls
);
5219 if (oldtype
&& *newtype
&& oldtype
!= *newtype
)
5221 cp_error ("using directive `%D' introduced ambiguous type `%T'",
5227 /* Process a using-declaration not appearing in class or local scope. */
5230 do_toplevel_using_decl (decl
)
5233 tree scope
, name
, binding
;
5234 tree oldval
, oldtype
, newval
, newtype
;
5236 decl
= validate_nonmember_using_decl (decl
, &scope
, &name
);
5237 if (decl
== NULL_TREE
)
5240 binding
= binding_for_name (name
, current_namespace
);
5242 oldval
= BINDING_VALUE (binding
);
5243 oldtype
= BINDING_TYPE (binding
);
5245 do_nonmember_using_decl (scope
, name
, oldval
, oldtype
, &newval
, &newtype
);
5247 /* Copy declarations found. */
5249 BINDING_VALUE (binding
) = newval
;
5251 BINDING_TYPE (binding
) = newtype
;
5255 /* Process a using-declaration at function scope. */
5258 do_local_using_decl (decl
)
5262 tree oldval
, oldtype
, newval
, newtype
;
5264 decl
= validate_nonmember_using_decl (decl
, &scope
, &name
);
5265 if (decl
== NULL_TREE
)
5268 oldval
= lookup_name_current_level (name
);
5269 oldtype
= lookup_type_current_level (name
);
5271 do_nonmember_using_decl (scope
, name
, oldval
, oldtype
, &newval
, &newtype
);
5275 if (is_overloaded_fn (newval
))
5279 /* We only need to push declarations for those functions
5280 that were not already bound in the current level.
5281 The old value might be NULL_TREE, it might be a single
5282 function, or an OVERLOAD. */
5283 if (oldval
&& TREE_CODE (oldval
) == OVERLOAD
)
5284 term
= OVL_FUNCTION (oldval
);
5287 for (fn
= newval
; fn
&& OVL_CURRENT (fn
) != term
;
5289 push_overloaded_decl (OVL_CURRENT (fn
),
5290 PUSH_LOCAL
| PUSH_USING
);
5293 push_local_binding (name
, newval
, PUSH_USING
);
5296 set_identifier_type_value (name
, newtype
);
5300 do_class_using_decl (decl
)
5305 if (TREE_CODE (decl
) != SCOPE_REF
5306 || !TYPE_P (TREE_OPERAND (decl
, 0)))
5308 cp_error ("using-declaration for non-member at class scope");
5311 name
= TREE_OPERAND (decl
, 1);
5312 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
5314 cp_error ("using-declaration for destructor");
5317 if (TREE_CODE (name
) == TYPE_DECL
)
5318 name
= DECL_NAME (name
);
5320 my_friendly_assert (TREE_CODE (name
) == IDENTIFIER_NODE
, 980716);
5322 value
= build_lang_decl (USING_DECL
, name
, void_type_node
);
5323 DECL_INITIAL (value
) = TREE_OPERAND (decl
, 0);
5327 /* Process a using-directive. */
5330 do_using_directive (namespace)
5333 if (namespace == fake_std_node
)
5335 /* using namespace A::B::C; */
5336 if (TREE_CODE (namespace) == SCOPE_REF
)
5337 namespace = TREE_OPERAND (namespace, 1);
5338 if (TREE_CODE (namespace) == IDENTIFIER_NODE
)
5340 /* Lookup in lexer did not find a namespace. */
5341 cp_error ("namespace `%T' undeclared", namespace);
5344 if (TREE_CODE (namespace) != NAMESPACE_DECL
)
5346 cp_error ("`%T' is not a namespace", namespace);
5349 namespace = ORIGINAL_NAMESPACE (namespace);
5350 if (!toplevel_bindings_p ())
5351 push_using_directive (namespace);
5354 add_using_namespace (current_namespace
, namespace, 0);
5358 check_default_args (x
)
5361 tree arg
= TYPE_ARG_TYPES (TREE_TYPE (x
));
5362 int saw_def
= 0, i
= 0 - (TREE_CODE (TREE_TYPE (x
)) == METHOD_TYPE
);
5363 for (; arg
&& arg
!= void_list_node
; arg
= TREE_CHAIN (arg
), ++i
)
5365 if (TREE_PURPOSE (arg
))
5369 cp_error_at ("default argument missing for parameter %P of `%+#D'",
5380 TREE_USED (decl
) = 1;
5381 if (processing_template_decl
)
5383 assemble_external (decl
);
5385 /* Is it a synthesized method that needs to be synthesized? */
5386 if (TREE_CODE (decl
) == FUNCTION_DECL
5387 && DECL_NONSTATIC_MEMBER_FUNCTION_P (decl
)
5388 && DECL_ARTIFICIAL (decl
)
5389 && ! DECL_INITIAL (decl
)
5390 /* Kludge: don't synthesize for default args. */
5391 && current_function_decl
)
5393 synthesize_method (decl
);
5394 /* If we've already synthesized the method we don't need to
5395 instantiate it, so we can return right away. */
5399 /* If this is a function or variable that is an instance of some
5400 template, we now know that we will need to actually do the
5401 instantiation. We check that DECL is not an explicit
5402 instantiation because that is not checked in instantiate_decl. */
5403 if ((DECL_NON_THUNK_FUNCTION_P (decl
) || TREE_CODE (decl
) == VAR_DECL
)
5404 && DECL_LANG_SPECIFIC (decl
) && DECL_TEMPLATE_INFO (decl
)
5405 && (!DECL_EXPLICIT_INSTANTIATION (decl
)
5406 || (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INLINE (decl
))))
5407 instantiate_decl (decl
, /*defer_ok=*/1);
5410 /* Helper function for named_class_head_sans_basetype nonterminal. We
5411 have just seen something of the form `AGGR SCOPE::ID'. Return a
5412 TYPE_DECL for the type declared by ID in SCOPE. */
5415 handle_class_head (aggr
, scope
, id
)
5416 tree aggr
, scope
, id
;
5418 tree decl
= NULL_TREE
;
5420 if (TREE_CODE (id
) == TYPE_DECL
)
5421 /* We must bash typedefs back to the main decl of the type. Otherwise
5422 we become confused about scopes. */
5423 decl
= TYPE_MAIN_DECL (TREE_TYPE (id
));
5424 else if (DECL_CLASS_TEMPLATE_P (id
))
5425 decl
= DECL_TEMPLATE_RESULT (id
);
5428 tree current
= current_scope ();
5430 if (current
== NULL_TREE
)
5431 current
= current_namespace
;
5432 if (scope
== fake_std_node
)
5433 scope
= global_namespace
;
5434 if (scope
== NULL_TREE
)
5435 scope
= global_namespace
;
5439 /* According to the suggested resolution of core issue 180,
5440 'typename' is assumed after a class-key. */
5441 decl
= make_typename_type (scope
, id
, 1);
5442 if (decl
!= error_mark_node
)
5443 decl
= TYPE_MAIN_DECL (decl
);
5447 else if (scope
== current
)
5449 /* We've been given AGGR SCOPE::ID, when we're already inside SCOPE.
5450 Be nice about it. */
5452 cp_pedwarn ("extra qualification `%T::' on member `%D' ignored",
5453 FROB_CONTEXT (scope
), id
);
5455 else if (scope
!= global_namespace
)
5456 cp_error ("`%T' does not have a nested type named `%D'", scope
, id
);
5458 cp_error ("no file-scope type named `%D'", id
);
5460 /* Inject it at the current scope. */
5462 decl
= TYPE_MAIN_DECL (xref_tag (aggr
, id
, 1));
5465 /* Enter the SCOPE. If this turns out not to be a definition, the
5466 parser must leave the scope. */
5467 push_scope (CP_DECL_CONTEXT (decl
));
5469 /* If we see something like:
5471 template <typename T> struct S::I ....
5473 we must create a TEMPLATE_DECL for the nested type. */
5474 if (PROCESSING_REAL_TEMPLATE_DECL_P ())
5475 decl
= push_template_decl (decl
);
5480 /* Initialize decl2.c. */
5485 ggc_add_tree_root (&decl_namespace_list
, 1);
5486 ggc_add_tree_varray_root (&deferred_fns
, 1);
5487 ggc_add_tree_varray_root (&pending_statics
, 1);
5488 ggc_add_tree_varray_root (&ssdf_decls
, 1);
5489 ggc_add_tree_root (&ssdf_decl
, 1);
5490 ggc_add_tree_root (&priority_decl
, 1);
5491 ggc_add_tree_root (&initialize_p_decl
, 1);
5492 ggc_add_tree_root (&pending_vtables
, 1);