1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002 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. */
33 #include "coretypes.h"
50 extern cpp_reader
*parse_in
;
52 /* This structure contains information about the initializations
53 and/or destructions required for a particular priority level. */
54 typedef struct priority_info_s
{
55 /* Nonzero if there have been any initializations at this priority
56 throughout the translation unit. */
57 int initializations_p
;
58 /* Nonzero if there have been any destructions at this priority
59 throughout the translation unit. */
63 static void mark_vtable_entries
PARAMS ((tree
));
64 static void grok_function_init
PARAMS ((tree
, tree
));
65 static int maybe_emit_vtables (tree
);
66 static int is_namespace_ancestor
PARAMS ((tree
, tree
));
67 static void add_using_namespace
PARAMS ((tree
, tree
, int));
68 static tree ambiguous_decl
PARAMS ((tree
, tree
, tree
,int));
69 static tree build_anon_union_vars
PARAMS ((tree
));
70 static int acceptable_java_type
PARAMS ((tree
));
71 static void output_vtable_inherit
PARAMS ((tree
));
72 static tree start_objects
PARAMS ((int, int));
73 static void finish_objects
PARAMS ((int, int, tree
));
74 static tree merge_functions
PARAMS ((tree
, tree
));
75 static tree decl_namespace
PARAMS ((tree
));
76 static tree validate_nonmember_using_decl
PARAMS ((tree
, tree
*, tree
*));
77 static void do_nonmember_using_decl
PARAMS ((tree
, tree
, tree
, tree
,
79 static tree start_static_storage_duration_function
PARAMS ((void));
80 static void finish_static_storage_duration_function
PARAMS ((tree
));
81 static priority_info get_priority_info
PARAMS ((int));
82 static void do_static_initialization
PARAMS ((tree
, tree
));
83 static void do_static_destruction
PARAMS ((tree
));
84 static tree start_static_initialization_or_destruction
PARAMS ((tree
, int));
85 static void finish_static_initialization_or_destruction
PARAMS ((tree
));
86 static void generate_ctor_or_dtor_function
PARAMS ((int, int));
87 static int generate_ctor_and_dtor_functions_for_priority
88 PARAMS ((splay_tree_node
, void *));
89 static tree prune_vars_needing_no_initialization
PARAMS ((tree
));
90 static void write_out_vars
PARAMS ((tree
));
91 static void import_export_class
PARAMS ((tree
));
92 static tree key_method
PARAMS ((tree
));
93 static tree get_guard_bits
PARAMS ((tree
));
95 /* A list of static class variables. This is needed, because a
96 static class variable can be declared inside the class without
97 an initializer, and then initialized, statically, outside the class. */
98 static GTY(()) varray_type pending_statics
;
99 #define pending_statics_used \
100 (pending_statics ? pending_statics->elements_used : 0)
102 /* A list of functions which were declared inline, but which we
103 may need to emit outline anyway. */
104 static GTY(()) varray_type deferred_fns
;
105 #define deferred_fns_used \
106 (deferred_fns ? deferred_fns->elements_used : 0)
108 /* Flag used when debugging spew.c */
110 extern int spew_debug
;
112 /* Nonzero if we're done parsing and into end-of-file activities. */
116 /* Functions called along with real static constructors and destructors. */
121 /* The :: namespace. */
123 tree global_namespace
;
125 /* Incorporate `const' and `volatile' qualifiers for member functions.
126 FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
127 QUALS is a list of qualifiers. Returns any explicit
128 top-level qualifiers of the method's this pointer, anything other than
129 TYPE_UNQUALIFIED will be an extension. */
132 grok_method_quals (ctype
, function
, quals
)
133 tree ctype
, function
, quals
;
135 tree fntype
= TREE_TYPE (function
);
136 tree raises
= TYPE_RAISES_EXCEPTIONS (fntype
);
137 int type_quals
= TYPE_UNQUALIFIED
;
138 int dup_quals
= TYPE_UNQUALIFIED
;
139 int this_quals
= TYPE_UNQUALIFIED
;
143 int tq
= cp_type_qual_from_rid (TREE_VALUE (quals
));
145 if ((type_quals
| this_quals
) & tq
)
147 else if (tq
& TYPE_QUAL_RESTRICT
)
151 quals
= TREE_CHAIN (quals
);
155 if (dup_quals
!= TYPE_UNQUALIFIED
)
156 error ("duplicate type qualifiers in %s declaration",
157 TREE_CODE (function
) == FUNCTION_DECL
158 ? "member function" : "type");
160 ctype
= cp_build_qualified_type (ctype
, type_quals
);
161 fntype
= build_cplus_method_type (ctype
, TREE_TYPE (fntype
),
162 (TREE_CODE (fntype
) == METHOD_TYPE
163 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype
))
164 : TYPE_ARG_TYPES (fntype
)));
166 fntype
= build_exception_variant (fntype
, raises
);
168 TREE_TYPE (function
) = fntype
;
172 /* Warn when -fexternal-templates is used and #pragma
173 interface/implementation is not used all the times it should be,
177 warn_if_unknown_interface (decl
)
180 static int already_warned
= 0;
181 if (already_warned
++)
184 if (flag_alt_external_templates
)
186 tree til
= tinst_for_decl ();
188 const char *sf
= input_filename
;
192 lineno
= TINST_LINE (til
);
193 input_filename
= TINST_FILE (til
);
195 warning ("template `%#D' instantiated in file without #pragma interface",
201 cp_warning_at ("template `%#D' defined in file without #pragma interface",
205 /* A subroutine of the parser, to handle a component list. */
208 grok_x_components (specs
)
213 specs
= strip_attrs (specs
);
215 check_tag_decl (specs
);
216 t
= groktypename (build_tree_list (specs
, NULL_TREE
));
218 /* The only case where we need to do anything additional here is an
219 anonymous union field, e.g.: `struct S { union { int i; }; };'. */
220 if (t
== NULL_TREE
|| !ANON_AGGR_TYPE_P (t
))
223 fixup_anonymous_aggr (t
);
224 finish_member_declaration (build_decl (FIELD_DECL
, NULL_TREE
, t
));
227 /* Build a PARM_DECL with NAME and TYPE, and set DECL_ARG_TYPE
231 cp_build_parm_decl (name
, type
)
235 tree parm
= build_decl (PARM_DECL
, name
, type
);
236 DECL_ARG_TYPE (parm
) = type_passed_as (type
);
240 /* Returns a PARM_DECL for a parameter of the indicated TYPE, with the
244 build_artificial_parm (name
, type
)
248 tree parm
= cp_build_parm_decl (name
, type
);
249 DECL_ARTIFICIAL (parm
) = 1;
250 /* All our artificial parms are implicitly `const'; they cannot be
252 TREE_READONLY (parm
) = 1;
256 /* Constructors for types with virtual baseclasses need an "in-charge" flag
257 saying whether this constructor is responsible for initialization of
258 virtual baseclasses or not. All destructors also need this "in-charge"
259 flag, which additionally determines whether or not the destructor should
260 free the memory for the object.
262 This function adds the "in-charge" flag to member function FN if
263 appropriate. It is called from grokclassfn and tsubst.
264 FN must be either a constructor or destructor.
266 The in-charge flag follows the 'this' parameter, and is followed by the
267 VTT parm (if any), then the user-written parms. */
270 maybe_retrofit_in_chrg (fn
)
273 tree basetype
, arg_types
, parms
, parm
, fntype
;
275 /* If we've already add the in-charge parameter don't do it again. */
276 if (DECL_HAS_IN_CHARGE_PARM_P (fn
))
279 /* When processing templates we can't know, in general, whether or
280 not we're going to have virtual baseclasses. */
281 if (uses_template_parms (fn
))
284 /* We don't need an in-charge parameter for constructors that don't
285 have virtual bases. */
286 if (DECL_CONSTRUCTOR_P (fn
)
287 && !TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn
)))
290 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
291 basetype
= TREE_TYPE (TREE_VALUE (arg_types
));
292 arg_types
= TREE_CHAIN (arg_types
);
294 parms
= TREE_CHAIN (DECL_ARGUMENTS (fn
));
296 /* If this is a subobject constructor or destructor, our caller will
297 pass us a pointer to our VTT. */
298 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn
)))
300 parm
= build_artificial_parm (vtt_parm_identifier
, vtt_parm_type
);
302 /* First add it to DECL_ARGUMENTS between 'this' and the real args... */
303 TREE_CHAIN (parm
) = parms
;
306 /* ...and then to TYPE_ARG_TYPES. */
307 arg_types
= hash_tree_chain (vtt_parm_type
, arg_types
);
309 DECL_HAS_VTT_PARM_P (fn
) = 1;
312 /* Then add the in-charge parm (before the VTT parm). */
313 parm
= build_artificial_parm (in_charge_identifier
, integer_type_node
);
314 TREE_CHAIN (parm
) = parms
;
316 arg_types
= hash_tree_chain (integer_type_node
, arg_types
);
318 /* Insert our new parameter(s) into the list. */
319 TREE_CHAIN (DECL_ARGUMENTS (fn
)) = parms
;
321 /* And rebuild the function type. */
322 fntype
= build_cplus_method_type (basetype
, TREE_TYPE (TREE_TYPE (fn
)),
324 if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn
)))
325 fntype
= build_exception_variant (fntype
,
326 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn
)));
327 TREE_TYPE (fn
) = fntype
;
329 /* Now we've got the in-charge parameter. */
330 DECL_HAS_IN_CHARGE_PARM_P (fn
) = 1;
333 /* Classes overload their constituent function names automatically.
334 When a function name is declared in a record structure,
335 its name is changed to it overloaded name. Since names for
336 constructors and destructors can conflict, we place a leading
339 CNAME is the name of the class we are grokking for.
341 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
343 FLAGS contains bits saying what's special about today's
344 arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
346 If FUNCTION is a destructor, then we must add the `auto-delete' field
347 as a second parameter. There is some hair associated with the fact
348 that we must "declare" this variable in the manner consistent with the
349 way the rest of the arguments were declared.
351 QUALS are the qualifiers for the this pointer. */
354 grokclassfn (ctype
, function
, flags
, quals
)
355 tree ctype
, function
;
356 enum overload_flags flags
;
359 tree fn_name
= DECL_NAME (function
);
360 int this_quals
= TYPE_UNQUALIFIED
;
362 /* Even within an `extern "C"' block, members get C++ linkage. See
363 [dcl.link] for details. */
364 SET_DECL_LANGUAGE (function
, lang_cplusplus
);
366 if (fn_name
== NULL_TREE
)
368 error ("name missing for member function");
369 fn_name
= get_identifier ("<anonymous>");
370 DECL_NAME (function
) = fn_name
;
374 this_quals
= grok_method_quals (ctype
, function
, quals
);
376 if (TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
378 /* Must add the class instance variable up front. */
379 /* Right now we just make this a pointer. But later
380 we may wish to make it special. */
381 tree type
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (function
)));
385 /* The `this' parameter is implicitly `const'; it cannot be
387 this_quals
|= TYPE_QUAL_CONST
;
388 qual_type
= cp_build_qualified_type (type
, this_quals
);
389 parm
= build_artificial_parm (this_identifier
, qual_type
);
390 c_apply_type_quals_to_decl (this_quals
, parm
);
391 TREE_CHAIN (parm
) = last_function_parms
;
392 last_function_parms
= parm
;
395 DECL_ARGUMENTS (function
) = last_function_parms
;
396 DECL_CONTEXT (function
) = ctype
;
398 if (flags
== DTOR_FLAG
)
399 DECL_DESTRUCTOR_P (function
) = 1;
401 if (flags
== DTOR_FLAG
|| DECL_CONSTRUCTOR_P (function
))
402 maybe_retrofit_in_chrg (function
);
404 if (flags
== DTOR_FLAG
)
406 DECL_DESTRUCTOR_P (function
) = 1;
407 TYPE_HAS_DESTRUCTOR (ctype
) = 1;
411 /* Create an ARRAY_REF, checking for the user doing things backwards
415 grok_array_decl (array_expr
, index_exp
)
416 tree array_expr
, index_exp
;
418 tree type
= TREE_TYPE (array_expr
);
421 if (type
== error_mark_node
|| index_exp
== error_mark_node
)
422 return error_mark_node
;
423 if (processing_template_decl
)
424 return build_min (ARRAY_REF
, type
? TREE_TYPE (type
) : NULL_TREE
,
425 array_expr
, index_exp
);
427 if (type
== NULL_TREE
)
429 /* Something has gone very wrong. Assume we are mistakenly reducing
430 an expression instead of a declaration. */
431 error ("parser may be lost: is there a '{' missing somewhere?");
435 if (TREE_CODE (type
) == OFFSET_TYPE
436 || TREE_CODE (type
) == REFERENCE_TYPE
)
437 type
= TREE_TYPE (type
);
439 /* If they have an `operator[]', use that. */
440 if (IS_AGGR_TYPE (type
) || IS_AGGR_TYPE (TREE_TYPE (index_exp
)))
441 return build_opfncall (ARRAY_REF
, LOOKUP_NORMAL
,
442 array_expr
, index_exp
, NULL_TREE
);
444 /* Otherwise, create an ARRAY_REF for a pointer or array type. It
445 is a little-known fact that, if `a' is an array and `i' is an
446 int, you can write `i[a]', which means the same thing as `a[i]'. */
448 if (TREE_CODE (type
) == ARRAY_TYPE
)
451 p1
= build_expr_type_conversion (WANT_POINTER
, array_expr
, 0);
453 if (TREE_CODE (TREE_TYPE (index_exp
)) == ARRAY_TYPE
)
456 p2
= build_expr_type_conversion (WANT_POINTER
, index_exp
, 0);
458 i1
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, array_expr
, 0);
459 i2
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, index_exp
, 0);
461 if ((p1
&& i2
) && (i1
&& p2
))
462 error ("ambiguous conversion for array subscript");
465 array_expr
= p1
, index_exp
= i2
;
467 array_expr
= p2
, index_exp
= i1
;
470 error ("invalid types `%T[%T]' for array subscript",
471 type
, TREE_TYPE (index_exp
));
472 return error_mark_node
;
475 if (array_expr
== error_mark_node
|| index_exp
== error_mark_node
)
476 error ("ambiguous conversion for array subscript");
478 return build_array_ref (array_expr
, index_exp
);
481 /* Given the cast expression EXP, checking out its validity. Either return
482 an error_mark_node if there was an unavoidable error, return a cast to
483 void for trying to delete a pointer w/ the value 0, or return the
484 call to delete. If DOING_VEC is 1, we handle things differently
485 for doing an array delete. If DOING_VEC is 2, they gave us the
486 array size as an argument to delete.
487 Implements ARM $5.3.4. This is called from the parser. */
490 delete_sanity (exp
, size
, doing_vec
, use_global_delete
)
492 int doing_vec
, use_global_delete
;
495 /* For a regular vector delete (aka, no size argument) we will pass
496 this down as a NULL_TREE into build_vec_delete. */
497 tree maxindex
= NULL_TREE
;
499 if (exp
== error_mark_node
)
502 if (processing_template_decl
)
504 t
= build_min (DELETE_EXPR
, void_type_node
, exp
, size
);
505 DELETE_EXPR_USE_GLOBAL (t
) = use_global_delete
;
506 DELETE_EXPR_USE_VEC (t
) = doing_vec
;
510 if (TREE_CODE (exp
) == OFFSET_REF
)
511 exp
= resolve_offset_ref (exp
);
512 exp
= convert_from_reference (exp
);
513 t
= stabilize_reference (exp
);
514 t
= build_expr_type_conversion (WANT_POINTER
, t
, 1);
516 if (t
== NULL_TREE
|| t
== error_mark_node
)
518 error ("type `%#T' argument given to `delete', expected pointer",
520 return error_mark_node
;
525 maxindex
= cp_build_binary_op (MINUS_EXPR
, size
, integer_one_node
);
526 pedwarn ("anachronistic use of array size in vector delete");
529 type
= TREE_TYPE (t
);
531 /* As of Valley Forge, you can delete a pointer to const. */
533 /* You can't delete functions. */
534 if (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
536 error ("cannot delete a function. Only pointer-to-objects are valid arguments to `delete'");
537 return error_mark_node
;
540 /* Deleting ptr to void is undefined behavior [expr.delete/3]. */
541 if (TREE_CODE (TREE_TYPE (type
)) == VOID_TYPE
)
543 warning ("deleting `%T' is undefined", type
);
547 /* An array can't have been allocated by new, so complain. */
548 if (TREE_CODE (t
) == ADDR_EXPR
549 && TREE_CODE (TREE_OPERAND (t
, 0)) == VAR_DECL
550 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == ARRAY_TYPE
)
551 warning ("deleting array `%#D'", TREE_OPERAND (t
, 0));
553 /* Deleting a pointer with the value zero is valid and has no effect. */
554 if (integer_zerop (t
))
555 return build1 (NOP_EXPR
, void_type_node
, t
);
558 return build_vec_delete (t
, maxindex
, sfk_deleting_destructor
,
561 return build_delete (type
, t
, sfk_deleting_destructor
,
562 LOOKUP_NORMAL
, use_global_delete
);
565 /* Report an error if the indicated template declaration is not the
566 sort of thing that should be a member template. */
569 check_member_template (tmpl
)
574 my_friendly_assert (TREE_CODE (tmpl
) == TEMPLATE_DECL
, 0);
575 decl
= DECL_TEMPLATE_RESULT (tmpl
);
577 if (TREE_CODE (decl
) == FUNCTION_DECL
578 || (TREE_CODE (decl
) == TYPE_DECL
579 && IS_AGGR_TYPE (TREE_TYPE (decl
))))
581 if (current_function_decl
)
582 /* 14.5.2.2 [temp.mem]
584 A local class shall not have member templates. */
585 error ("invalid declaration of member template `%#D' in local class",
588 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (decl
))
590 /* 14.5.2.3 [temp.mem]
592 A member function template shall not be virtual. */
594 ("invalid use of `virtual' in template declaration of `%#D'",
596 DECL_VIRTUAL_P (decl
) = 0;
599 /* The debug-information generating code doesn't know what to do
600 with member templates. */
601 DECL_IGNORED_P (tmpl
) = 1;
604 error ("template declaration of `%#D'", decl
);
607 /* Return true iff TYPE is a valid Java parameter or return type. */
610 acceptable_java_type (type
)
613 if (TREE_CODE (type
) == VOID_TYPE
|| TYPE_FOR_JAVA (type
))
615 if (TREE_CODE (type
) == POINTER_TYPE
|| TREE_CODE (type
) == REFERENCE_TYPE
)
617 type
= TREE_TYPE (type
);
618 if (TREE_CODE (type
) == RECORD_TYPE
)
621 if (! TYPE_FOR_JAVA (type
))
623 if (! CLASSTYPE_TEMPLATE_INFO (type
))
625 args
= CLASSTYPE_TI_ARGS (type
);
626 i
= TREE_VEC_LENGTH (args
);
629 type
= TREE_VEC_ELT (args
, i
);
630 if (TREE_CODE (type
) == POINTER_TYPE
)
631 type
= TREE_TYPE (type
);
632 if (! TYPE_FOR_JAVA (type
))
641 /* For a METHOD in a Java class CTYPE, return 1 if
642 the parameter and return types are valid Java types.
643 Otherwise, print appropriate error messages, and return 0. */
646 check_java_method (method
)
650 tree arg_types
= TYPE_ARG_TYPES (TREE_TYPE (method
));
651 tree ret_type
= TREE_TYPE (TREE_TYPE (method
));
652 if (! acceptable_java_type (ret_type
))
654 error ("Java method '%D' has non-Java return type `%T'",
658 for (; arg_types
!= NULL_TREE
; arg_types
= TREE_CHAIN (arg_types
))
660 tree type
= TREE_VALUE (arg_types
);
661 if (! acceptable_java_type (type
))
663 error ("Java method '%D' has non-Java parameter type `%T'",
671 /* Sanity check: report error if this function FUNCTION is not
672 really a member of the class (CTYPE) it is supposed to belong to.
673 CNAME is the same here as it is for grokclassfn above. */
676 check_classfn (ctype
, function
)
677 tree ctype
, function
;
681 if (DECL_USE_TEMPLATE (function
)
682 && !(TREE_CODE (function
) == TEMPLATE_DECL
683 && DECL_TEMPLATE_SPECIALIZATION (function
))
684 && is_member_template (DECL_TI_TEMPLATE (function
)))
685 /* Since this is a specialization of a member template,
686 we're not going to find the declaration in the class.
689 struct S { template <typename T> void f(T); };
690 template <> void S::f(int);
692 we're not going to find `S::f(int)', but there's no
693 reason we should, either. We let our callers know we didn't
694 find the method, but we don't complain. */
697 ix
= lookup_fnfields_1 (complete_type (ctype
),
698 DECL_CONSTRUCTOR_P (function
) ? ctor_identifier
:
699 DECL_DESTRUCTOR_P (function
) ? dtor_identifier
:
700 DECL_NAME (function
));
704 tree methods
= CLASSTYPE_METHOD_VEC (ctype
);
705 tree fndecls
, fndecl
;
707 const char *format
= NULL
;
709 for (fndecls
= TREE_VEC_ELT (methods
, ix
);
710 fndecls
; fndecls
= OVL_NEXT (fndecls
))
714 fndecl
= OVL_CURRENT (fndecls
);
715 p1
= TYPE_ARG_TYPES (TREE_TYPE (function
));
716 p2
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
718 /* We cannot simply call decls_match because this doesn't
719 work for static member functions that are pretending to
720 be methods, and because the name may have been changed by
723 /* Get rid of the this parameter on functions that become
725 if (DECL_STATIC_FUNCTION_P (fndecl
)
726 && TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
727 p1
= TREE_CHAIN (p1
);
729 if (same_type_p (TREE_TYPE (TREE_TYPE (function
)),
730 TREE_TYPE (TREE_TYPE (fndecl
)))
731 && compparms (p1
, p2
)
732 && (DECL_TEMPLATE_SPECIALIZATION (function
)
733 == DECL_TEMPLATE_SPECIALIZATION (fndecl
))
734 && (!DECL_TEMPLATE_SPECIALIZATION (function
)
735 || (DECL_TI_TEMPLATE (function
)
736 == DECL_TI_TEMPLATE (fndecl
))))
739 error ("prototype for `%#D' does not match any in class `%T'",
741 is_conv_op
= DECL_CONV_FN_P (fndecl
);
744 ix
= CLASSTYPE_FIRST_CONVERSION_SLOT
;
745 fndecls
= TREE_VEC_ELT (methods
, ix
);
748 fndecl
= OVL_CURRENT (fndecls
);
749 fndecls
= OVL_NEXT (fndecls
);
751 if (!fndecls
&& is_conv_op
)
753 if (TREE_VEC_LENGTH (methods
) > ix
)
756 fndecls
= TREE_VEC_ELT (methods
, ix
);
757 if (!DECL_CONV_FN_P (OVL_CURRENT (fndecls
)))
769 format
= "candidates are: %#D";
771 format
= "candidate is: %#D";
772 cp_error_at (format
, fndecl
);
775 else if (!COMPLETE_TYPE_P (ctype
))
776 cxx_incomplete_type_error (function
, ctype
);
778 error ("no `%#D' member function declared in class `%T'",
781 /* If we did not find the method in the class, add it to avoid
782 spurious errors (unless the CTYPE is not yet defined, in which
783 case we'll only confuse ourselves when the function is declared
784 properly within the class. */
785 if (COMPLETE_TYPE_P (ctype
))
786 add_method (ctype
, function
, /*error_p=*/1);
790 /* We have just processed the DECL, which is a static data member.
791 Its initializer, if present, is INIT. The ASMSPEC_TREE, if
792 present, is the assembly-language name for the data member.
793 FLAGS is as for cp_finish_decl. */
796 finish_static_data_member_decl (decl
, init
, asmspec_tree
, flags
)
802 my_friendly_assert (TREE_PUBLIC (decl
), 0);
804 DECL_CONTEXT (decl
) = current_class_type
;
806 /* We cannot call pushdecl here, because that would fill in the
807 TREE_CHAIN of our decl. Instead, we modify cp_finish_decl to do
808 the right thing, namely, to put this decl out straight away. */
809 /* current_class_type can be NULL_TREE in case of error. */
810 if (!asmspec_tree
&& current_class_type
)
811 DECL_INITIAL (decl
) = error_mark_node
;
813 if (! processing_template_decl
)
815 if (!pending_statics
)
816 VARRAY_TREE_INIT (pending_statics
, 32, "pending_statics");
817 VARRAY_PUSH_TREE (pending_statics
, decl
);
820 if (LOCAL_CLASS_P (current_class_type
))
821 pedwarn ("local class `%#T' shall not have static data member `%#D'",
822 current_class_type
, decl
);
824 /* Static consts need not be initialized in the class definition. */
825 if (init
!= NULL_TREE
&& TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl
)))
827 static int explained
= 0;
829 error ("initializer invalid for static member with constructor");
832 error ("(an out of class initialization is required)");
837 /* Force the compiler to know when an uninitialized static const
838 member is being used. */
839 if (CP_TYPE_CONST_P (TREE_TYPE (decl
)) && init
== 0)
840 TREE_USED (decl
) = 1;
841 DECL_INITIAL (decl
) = init
;
842 DECL_IN_AGGR_P (decl
) = 1;
844 cp_finish_decl (decl
, init
, asmspec_tree
, flags
);
847 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
848 of a structure component, returning a _DECL node.
849 QUALS is a list of type qualifiers for this decl (such as for declaring
850 const member functions).
852 This is done during the parsing of the struct declaration.
853 The _DECL nodes are chained together and the lot of them
854 are ultimately passed to `build_struct' to make the RECORD_TYPE node.
856 If class A defines that certain functions in class B are friends, then
857 the way I have set things up, it is B who is interested in permission
858 granted by A. However, it is in A's context that these declarations
859 are parsed. By returning a void_type_node, class A does not attempt
860 to incorporate the declarations of the friends within its structure.
862 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
863 CHANGES TO CODE IN `start_method'. */
866 grokfield (declarator
, declspecs
, init
, asmspec_tree
, attrlist
)
867 tree declarator
, declspecs
, init
, asmspec_tree
, attrlist
;
870 const char *asmspec
= 0;
871 int flags
= LOOKUP_ONLYCONVERTING
;
873 /* Convert () initializers to = initializers. */
874 if (init
== NULL_TREE
&& declarator
!= NULL_TREE
875 && TREE_CODE (declarator
) == CALL_EXPR
876 && TREE_OPERAND (declarator
, 0)
877 && (TREE_CODE (TREE_OPERAND (declarator
, 0)) == IDENTIFIER_NODE
878 || TREE_CODE (TREE_OPERAND (declarator
, 0)) == SCOPE_REF
)
879 && parmlist_is_exprlist (CALL_DECLARATOR_PARMS (declarator
)))
881 /* It's invalid to try to initialize a data member using a
882 functional notation, e.g.:
888 Explain that to the user. */
889 static int explained
;
891 error ("invalid data member initialization");
894 error ("(use `=' to initialize static data members)");
898 declarator
= TREE_OPERAND (declarator
, 0);
902 if (declspecs
== NULL_TREE
903 && TREE_CODE (declarator
) == SCOPE_REF
904 && TREE_CODE (TREE_OPERAND (declarator
, 1)) == IDENTIFIER_NODE
)
906 /* Access declaration */
907 if (! IS_AGGR_TYPE_CODE (TREE_CODE (TREE_OPERAND (declarator
, 0))))
909 else if (TREE_COMPLEXITY (declarator
) == current_class_depth
)
911 return do_class_using_decl (declarator
);
915 && TREE_CODE (init
) == TREE_LIST
916 && TREE_VALUE (init
) == error_mark_node
917 && TREE_CHAIN (init
) == NULL_TREE
)
920 value
= grokdeclarator (declarator
, declspecs
, FIELD
, init
!= 0, &attrlist
);
921 if (! value
|| value
== error_mark_node
)
922 /* friend or constructor went bad. */
924 if (TREE_TYPE (value
) == error_mark_node
)
925 return error_mark_node
;
927 if (TREE_CODE (value
) == TYPE_DECL
&& init
)
929 error ("typedef `%D' is initialized (use __typeof__ instead)", value
);
933 /* Pass friendly classes back. */
934 if (TREE_CODE (value
) == VOID_TYPE
)
935 return void_type_node
;
937 if (DECL_NAME (value
) != NULL_TREE
938 && IDENTIFIER_POINTER (DECL_NAME (value
))[0] == '_'
939 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value
)), "_vptr"))
940 error ("member `%D' conflicts with virtual function table field name",
943 /* Stash away type declarations. */
944 if (TREE_CODE (value
) == TYPE_DECL
)
946 DECL_NONLOCAL (value
) = 1;
947 DECL_CONTEXT (value
) = current_class_type
;
949 if (CLASS_TYPE_P (TREE_TYPE (value
)))
950 CLASSTYPE_GOT_SEMICOLON (TREE_TYPE (value
)) = 1;
952 if (processing_template_decl
)
953 value
= push_template_decl (value
);
958 if (DECL_IN_AGGR_P (value
))
960 error ("`%D' is already defined in `%T'", value
,
961 DECL_CONTEXT (value
));
962 return void_type_node
;
966 asmspec
= TREE_STRING_POINTER (asmspec_tree
);
970 if (TREE_CODE (value
) == FUNCTION_DECL
)
972 grok_function_init (value
, init
);
975 else if (pedantic
&& TREE_CODE (value
) != VAR_DECL
)
976 /* Already complained in grokdeclarator. */
980 /* We allow initializers to become parameters to base
982 if (TREE_CODE (init
) == TREE_LIST
)
984 if (TREE_CHAIN (init
) == NULL_TREE
)
985 init
= TREE_VALUE (init
);
987 init
= digest_init (TREE_TYPE (value
), init
, (tree
*)0);
990 if (!processing_template_decl
)
992 if (TREE_CODE (init
) == CONST_DECL
)
993 init
= DECL_INITIAL (init
);
994 else if (TREE_READONLY_DECL_P (init
))
995 init
= decl_constant_value (init
);
996 else if (TREE_CODE (init
) == CONSTRUCTOR
)
997 init
= digest_init (TREE_TYPE (value
), init
, (tree
*)0);
998 if (init
== error_mark_node
)
999 /* We must make this look different than `error_mark_node'
1000 because `decl_const_value' would mis-interpret it
1001 as only meaning that this VAR_DECL is defined. */
1002 init
= build1 (NOP_EXPR
, TREE_TYPE (value
), init
);
1003 else if (! TREE_CONSTANT (init
))
1005 /* We can allow references to things that are effectively
1006 static, since references are initialized with the
1008 if (TREE_CODE (TREE_TYPE (value
)) != REFERENCE_TYPE
1009 || (TREE_STATIC (init
) == 0
1010 && (!DECL_P (init
) || DECL_EXTERNAL (init
) == 0)))
1012 error ("field initializer is not constant");
1013 init
= error_mark_node
;
1020 if (processing_template_decl
&& ! current_function_decl
1021 && (TREE_CODE (value
) == VAR_DECL
|| TREE_CODE (value
) == FUNCTION_DECL
))
1022 value
= push_template_decl (value
);
1025 cplus_decl_attributes (&value
, attrlist
, 0);
1027 if (TREE_CODE (value
) == VAR_DECL
)
1029 finish_static_data_member_decl (value
, init
, asmspec_tree
,
1033 if (TREE_CODE (value
) == FIELD_DECL
)
1036 error ("`asm' specifiers are not permitted on non-static data members");
1037 if (DECL_INITIAL (value
) == error_mark_node
)
1038 init
= error_mark_node
;
1039 cp_finish_decl (value
, init
, NULL_TREE
, flags
);
1040 DECL_INITIAL (value
) = init
;
1041 DECL_IN_AGGR_P (value
) = 1;
1044 if (TREE_CODE (value
) == FUNCTION_DECL
)
1048 /* This must override the asm specifier which was placed
1049 by grokclassfn. Lay this out fresh. */
1050 SET_DECL_RTL (value
, NULL_RTX
);
1051 SET_DECL_ASSEMBLER_NAME (value
, get_identifier (asmspec
));
1053 if (!DECL_FRIEND_P (value
))
1054 grok_special_member_properties (value
);
1056 cp_finish_decl (value
, init
, asmspec_tree
, flags
);
1058 /* Pass friends back this way. */
1059 if (DECL_FRIEND_P (value
))
1060 return void_type_node
;
1062 DECL_IN_AGGR_P (value
) = 1;
1070 /* Like `grokfield', but for bitfields.
1071 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1074 grokbitfield (declarator
, declspecs
, width
)
1075 tree declarator
, declspecs
, width
;
1077 register tree value
= grokdeclarator (declarator
, declspecs
, BITFIELD
,
1080 if (! value
) return NULL_TREE
; /* friends went bad. */
1082 /* Pass friendly classes back. */
1083 if (TREE_CODE (value
) == VOID_TYPE
)
1084 return void_type_node
;
1086 if (TREE_CODE (value
) == TYPE_DECL
)
1088 error ("cannot declare `%D' to be a bit-field type", value
);
1092 /* Usually, finish_struct_1 catches bitfields with invalid types.
1093 But, in the case of bitfields with function type, we confuse
1094 ourselves into thinking they are member functions, so we must
1096 if (TREE_CODE (value
) == FUNCTION_DECL
)
1098 error ("cannot declare bit-field `%D' with function type",
1103 if (DECL_IN_AGGR_P (value
))
1105 error ("`%D' is already defined in the class %T", value
,
1106 DECL_CONTEXT (value
));
1107 return void_type_node
;
1110 if (TREE_STATIC (value
))
1112 error ("static member `%D' cannot be a bit-field", value
);
1115 cp_finish_decl (value
, NULL_TREE
, NULL_TREE
, 0);
1117 if (width
!= error_mark_node
)
1119 constant_expression_warning (width
);
1120 DECL_INITIAL (value
) = width
;
1121 SET_DECL_C_BIT_FIELD (value
);
1124 DECL_IN_AGGR_P (value
) = 1;
1128 /* Convert a conversion operator name to an identifier. SCOPE is the
1129 scope of the conversion operator, if explicit. */
1132 grokoptypename (declspecs
, declarator
, scope
)
1133 tree declspecs
, declarator
;
1136 tree t
= grokdeclarator (declarator
, declspecs
, TYPENAME
, 0, NULL
);
1138 /* Resolve any TYPENAME_TYPEs that refer to SCOPE, before mangling
1139 the name, so that we mangle the right thing. */
1140 if (scope
&& current_template_parms
1141 && uses_template_parms (t
)
1142 && uses_template_parms (scope
))
1144 tree args
= current_template_args ();
1147 t
= tsubst (t
, args
, tf_error
| tf_warning
, NULL_TREE
);
1151 return mangle_conv_op_name_for_type (t
);
1154 /* When a function is declared with an initializer,
1155 do the right thing. Currently, there are two possibilities:
1160 // initialization possibility #1.
1161 virtual void f () = 0;
1183 // initialization possibility #2
1190 grok_function_init (decl
, init
)
1194 /* An initializer for a function tells how this function should
1196 tree type
= TREE_TYPE (decl
);
1198 if (TREE_CODE (type
) == FUNCTION_TYPE
)
1199 error ("initializer specified for non-member function `%D'", decl
);
1200 else if (integer_zerop (init
))
1201 DECL_PURE_VIRTUAL_P (decl
) = 1;
1203 error ("invalid initializer for virtual method `%D'", decl
);
1207 cplus_decl_attributes (decl
, attributes
, flags
)
1208 tree
*decl
, attributes
;
1211 if (*decl
== NULL_TREE
|| *decl
== void_type_node
)
1214 if (TREE_CODE (*decl
) == TEMPLATE_DECL
)
1215 decl
= &DECL_TEMPLATE_RESULT (*decl
);
1217 decl_attributes (decl
, attributes
, flags
);
1219 if (TREE_CODE (*decl
) == TYPE_DECL
)
1220 SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (*decl
), TREE_TYPE (*decl
));
1223 /* Return the name for the constructor (or destructor) for the
1224 specified class TYPE. When given a template, this routine doesn't
1225 lose the specialization. */
1228 constructor_name_full (tree type
)
1230 type
= TYPE_MAIN_VARIANT (type
);
1231 if (CLASS_TYPE_P (type
) && TYPE_WAS_ANONYMOUS (type
)
1232 && TYPE_HAS_CONSTRUCTOR (type
))
1233 return DECL_NAME (OVL_CURRENT (CLASSTYPE_CONSTRUCTORS (type
)));
1235 return TYPE_IDENTIFIER (type
);
1238 /* Return the name for the constructor (or destructor) for the
1239 specified class. When given a template, return the plain
1240 unspecialized name. */
1243 constructor_name (type
)
1247 name
= constructor_name_full (type
);
1248 if (IDENTIFIER_TEMPLATE (name
))
1249 name
= IDENTIFIER_TEMPLATE (name
);
1253 /* Returns TRUE if NAME is the name for the constructor for TYPE. */
1256 constructor_name_p (tree name
, tree type
)
1258 return (name
== constructor_name (type
)
1259 || name
== constructor_name_full (type
));
1263 /* Defer the compilation of the FN until the end of compilation. */
1269 if (DECL_DEFERRED_FN (fn
))
1271 DECL_DEFERRED_FN (fn
) = 1;
1273 VARRAY_TREE_INIT (deferred_fns
, 32, "deferred_fns");
1275 VARRAY_PUSH_TREE (deferred_fns
, fn
);
1278 /* Walks through the namespace- or function-scope anonymous union OBJECT,
1279 building appropriate ALIAS_DECLs. Returns one of the fields for use in
1280 the mangled name. */
1283 build_anon_union_vars (object
)
1286 tree type
= TREE_TYPE (object
);
1287 tree main_decl
= NULL_TREE
;
1290 /* Rather than write the code to handle the non-union case,
1291 just give an error. */
1292 if (TREE_CODE (type
) != UNION_TYPE
)
1293 error ("anonymous struct not inside named type");
1295 for (field
= TYPE_FIELDS (type
);
1297 field
= TREE_CHAIN (field
))
1302 if (DECL_ARTIFICIAL (field
))
1304 if (TREE_CODE (field
) != FIELD_DECL
)
1307 `%#D' invalid; an anonymous union can only have non-static data members",
1312 if (TREE_PRIVATE (field
))
1313 cp_pedwarn_at ("private member `%#D' in anonymous union", field
);
1314 else if (TREE_PROTECTED (field
))
1315 cp_pedwarn_at ("protected member `%#D' in anonymous union", field
);
1317 ref
= build_class_member_access_expr (object
, field
, NULL_TREE
,
1320 if (DECL_NAME (field
))
1322 decl
= build_decl (ALIAS_DECL
, DECL_NAME (field
), TREE_TYPE (field
));
1323 DECL_INITIAL (decl
) = ref
;
1324 TREE_PUBLIC (decl
) = 0;
1325 TREE_STATIC (decl
) = 0;
1326 DECL_EXTERNAL (decl
) = 1;
1327 decl
= pushdecl (decl
);
1329 else if (ANON_AGGR_TYPE_P (TREE_TYPE (field
)))
1330 decl
= build_anon_union_vars (ref
);
1332 if (main_decl
== NULL_TREE
)
1339 /* Finish off the processing of a UNION_TYPE structure. If the union is an
1340 anonymous union, then all members must be laid out together. PUBLIC_P
1341 is nonzero if this union is not declared static. */
1344 finish_anon_union (anon_union_decl
)
1345 tree anon_union_decl
;
1347 tree type
= TREE_TYPE (anon_union_decl
);
1349 int public_p
= TREE_PUBLIC (anon_union_decl
);
1351 /* The VAR_DECL's context is the same as the TYPE's context. */
1352 DECL_CONTEXT (anon_union_decl
) = DECL_CONTEXT (TYPE_NAME (type
));
1354 if (TYPE_FIELDS (type
) == NULL_TREE
)
1359 error ("namespace-scope anonymous aggregates must be static");
1363 if (!processing_template_decl
)
1365 main_decl
= build_anon_union_vars (anon_union_decl
);
1367 if (main_decl
== NULL_TREE
)
1369 warning ("anonymous union with no members");
1373 /* Use main_decl to set the mangled name. */
1374 DECL_NAME (anon_union_decl
) = DECL_NAME (main_decl
);
1375 mangle_decl (anon_union_decl
);
1376 DECL_NAME (anon_union_decl
) = NULL_TREE
;
1379 pushdecl (anon_union_decl
);
1380 if (building_stmt_tree ()
1381 && at_function_scope_p ())
1382 add_decl_stmt (anon_union_decl
);
1383 else if (!processing_template_decl
)
1384 rest_of_decl_compilation (anon_union_decl
, NULL
,
1385 toplevel_bindings_p (), at_eof
);
1388 /* Auxiliary functions to make type signatures for
1389 `operator new' and `operator delete' correspond to
1390 what compiler will be expecting. */
1393 coerce_new_type (type
)
1397 tree args
= TYPE_ARG_TYPES (type
);
1399 my_friendly_assert (TREE_CODE (type
) == FUNCTION_TYPE
, 20001107);
1401 if (!same_type_p (TREE_TYPE (type
), ptr_type_node
))
1402 e
= 1, error ("`operator new' must return type `%T'", ptr_type_node
);
1404 if (!args
|| args
== void_list_node
1405 || !same_type_p (TREE_VALUE (args
), size_type_node
))
1408 if (args
&& args
!= void_list_node
)
1409 args
= TREE_CHAIN (args
);
1410 pedwarn ("`operator new' takes type `size_t' (`%T') as first parameter", size_type_node
);
1415 args
= tree_cons (NULL_TREE
, size_type_node
, args
);
1418 type
= build_exception_variant
1419 (build_function_type (ptr_type_node
, args
),
1420 TYPE_RAISES_EXCEPTIONS (type
));
1428 coerce_delete_type (type
)
1432 tree args
= TYPE_ARG_TYPES (type
);
1434 my_friendly_assert (TREE_CODE (type
) == FUNCTION_TYPE
, 20001107);
1436 if (!same_type_p (TREE_TYPE (type
), void_type_node
))
1437 e
= 1, error ("`operator delete' must return type `%T'", void_type_node
);
1439 if (!args
|| args
== void_list_node
1440 || !same_type_p (TREE_VALUE (args
), ptr_type_node
))
1443 if (args
&& args
!= void_list_node
)
1444 args
= TREE_CHAIN (args
);
1445 error ("`operator delete' takes type `%T' as first parameter", ptr_type_node
);
1450 args
= tree_cons (NULL_TREE
, ptr_type_node
, args
);
1453 type
= build_exception_variant
1454 (build_function_type (void_type_node
, args
),
1455 TYPE_RAISES_EXCEPTIONS (type
));
1464 mark_vtable_entries (decl
)
1467 tree entries
= CONSTRUCTOR_ELTS (DECL_INITIAL (decl
));
1469 for (; entries
; entries
= TREE_CHAIN (entries
))
1471 tree fnaddr
= TREE_VALUE (entries
);
1474 if (TREE_CODE (fnaddr
) != ADDR_EXPR
1475 && TREE_CODE (fnaddr
) != FDESC_EXPR
)
1476 /* This entry is an offset: a virtual base class offset, a
1477 virtual call offset, an RTTI offset, etc. */
1480 fn
= TREE_OPERAND (fnaddr
, 0);
1481 TREE_ADDRESSABLE (fn
) = 1;
1482 /* When we don't have vcall offsets, we output thunks whenever
1483 we output the vtables that contain them. With vcall offsets,
1484 we know all the thunks we'll need when we emit a virtual
1485 function, so we emit the thunks there instead. */
1486 if (DECL_THUNK_P (fn
))
1487 use_thunk (fn
, /*emit_p=*/0);
1492 /* Set DECL up to have the closest approximation of "initialized common"
1493 linkage available. */
1496 comdat_linkage (decl
)
1500 make_decl_one_only (decl
);
1501 else if (TREE_CODE (decl
) == FUNCTION_DECL
1502 || (TREE_CODE (decl
) == VAR_DECL
&& DECL_ARTIFICIAL (decl
)))
1503 /* We can just emit function and compiler-generated variables
1504 statically; having multiple copies is (for the most part) only
1507 There are two correctness issues, however: the address of a
1508 template instantiation with external linkage should be the
1509 same, independent of what translation unit asks for the
1510 address, and this will not hold when we emit multiple copies of
1511 the function. However, there's little else we can do.
1513 Also, by default, the typeinfo implementation assumes that
1514 there will be only one copy of the string used as the name for
1515 each type. Therefore, if weak symbols are unavailable, the
1516 run-time library should perform a more conservative check; it
1517 should perform a string comparison, rather than an address
1519 TREE_PUBLIC (decl
) = 0;
1522 /* Static data member template instantiations, however, cannot
1523 have multiple copies. */
1524 if (DECL_INITIAL (decl
) == 0
1525 || DECL_INITIAL (decl
) == error_mark_node
)
1526 DECL_COMMON (decl
) = 1;
1527 else if (EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl
)))
1529 DECL_COMMON (decl
) = 1;
1530 DECL_INITIAL (decl
) = error_mark_node
;
1534 /* We can't do anything useful; leave vars for explicit
1536 DECL_EXTERNAL (decl
) = 1;
1537 DECL_NOT_REALLY_EXTERN (decl
) = 0;
1541 if (DECL_LANG_SPECIFIC (decl
))
1542 DECL_COMDAT (decl
) = 1;
1545 /* For win32 we also want to put explicit instantiations in
1546 linkonce sections, so that they will be merged with implicit
1547 instantiations; otherwise we get duplicate symbol errors. */
1550 maybe_make_one_only (decl
)
1553 /* We used to say that this was not necessary on targets that support weak
1554 symbols, because the implicit instantiations will defer to the explicit
1555 one. However, that's not actually the case in SVR4; a strong definition
1556 after a weak one is an error. Also, not making explicit
1557 instantiations one_only means that we can end up with two copies of
1558 some template instantiations. */
1562 /* We can't set DECL_COMDAT on functions, or finish_file will think
1563 we can get away with not emitting them if they aren't used. We need
1564 to for variables so that cp_finish_decl will update their linkage,
1565 because their DECL_INITIAL may not have been set properly yet. */
1567 make_decl_one_only (decl
);
1569 if (TREE_CODE (decl
) == VAR_DECL
)
1571 DECL_COMDAT (decl
) = 1;
1572 /* Mark it needed so we don't forget to emit it. */
1573 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
)) = 1;
1577 /* Returns the virtual function with which the vtable for TYPE is
1578 emitted, or NULL_TREE if that heuristic is not applicable to TYPE. */
1586 if (TYPE_FOR_JAVA (type
)
1587 || CLASSTYPE_TEMPLATE_INSTANTIATION (type
)
1588 || CLASSTYPE_INTERFACE_KNOWN (type
))
1591 for (method
= TYPE_METHODS (type
); method
!= NULL_TREE
;
1592 method
= TREE_CHAIN (method
))
1593 if (DECL_VINDEX (method
) != NULL_TREE
1594 && ! DECL_DECLARED_INLINE_P (method
)
1595 && ! DECL_PURE_VIRTUAL_P (method
))
1601 /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL,
1602 based on TYPE and other static flags.
1604 Note that anything public is tagged TREE_PUBLIC, whether
1605 it's public in this file or in another one. */
1608 import_export_vtable (decl
, type
, final
)
1612 if (DECL_INTERFACE_KNOWN (decl
))
1615 if (TYPE_FOR_JAVA (type
))
1617 TREE_PUBLIC (decl
) = 1;
1618 DECL_EXTERNAL (decl
) = 1;
1619 DECL_INTERFACE_KNOWN (decl
) = 1;
1621 else if (CLASSTYPE_INTERFACE_KNOWN (type
))
1623 TREE_PUBLIC (decl
) = 1;
1624 DECL_EXTERNAL (decl
) = CLASSTYPE_INTERFACE_ONLY (type
);
1625 DECL_INTERFACE_KNOWN (decl
) = 1;
1629 /* We can only wait to decide if we have real non-inline virtual
1630 functions in our class, or if we come from a template. */
1632 int found
= (CLASSTYPE_TEMPLATE_INSTANTIATION (type
)
1633 || key_method (type
));
1635 if (final
|| ! found
)
1637 comdat_linkage (decl
);
1638 DECL_EXTERNAL (decl
) = 0;
1642 TREE_PUBLIC (decl
) = 1;
1643 DECL_EXTERNAL (decl
) = 1;
1648 /* Determine whether or not we want to specifically import or export CTYPE,
1649 using various heuristics. */
1652 import_export_class (ctype
)
1655 /* -1 for imported, 1 for exported. */
1656 int import_export
= 0;
1658 /* It only makes sense to call this function at EOF. The reason is
1659 that this function looks at whether or not the first non-inline
1660 non-abstract virtual member function has been defined in this
1661 translation unit. But, we can't possibly know that until we've
1662 seen the entire translation unit. */
1663 my_friendly_assert (at_eof
, 20000226);
1665 if (CLASSTYPE_INTERFACE_KNOWN (ctype
))
1668 /* If MULTIPLE_SYMBOL_SPACES is defined and we saw a #pragma interface,
1669 we will have CLASSTYPE_INTERFACE_ONLY set but not
1670 CLASSTYPE_INTERFACE_KNOWN. In that case, we don't want to use this
1671 heuristic because someone will supply a #pragma implementation
1672 elsewhere, and deducing it here would produce a conflict. */
1673 if (CLASSTYPE_INTERFACE_ONLY (ctype
))
1676 if (lookup_attribute ("dllimport", TYPE_ATTRIBUTES (ctype
)))
1678 else if (lookup_attribute ("dllexport", TYPE_ATTRIBUTES (ctype
)))
1681 /* If we got -fno-implicit-templates, we import template classes that
1682 weren't explicitly instantiated. */
1683 if (import_export
== 0
1684 && CLASSTYPE_IMPLICIT_INSTANTIATION (ctype
)
1685 && ! flag_implicit_templates
)
1688 /* Base our import/export status on that of the first non-inline,
1689 non-pure virtual function, if any. */
1690 if (import_export
== 0
1691 && TYPE_POLYMORPHIC_P (ctype
))
1693 tree method
= key_method (ctype
);
1695 import_export
= (DECL_REALLY_EXTERN (method
) ? -1 : 1);
1698 #ifdef MULTIPLE_SYMBOL_SPACES
1699 if (import_export
== -1)
1705 SET_CLASSTYPE_INTERFACE_KNOWN (ctype
);
1706 CLASSTYPE_INTERFACE_ONLY (ctype
) = (import_export
< 0);
1710 /* We need to describe to the assembler the relationship between
1711 a vtable and the vtable of the parent class. */
1714 output_vtable_inherit (vars
)
1718 rtx child_rtx
, parent_rtx
;
1720 child_rtx
= XEXP (DECL_RTL (vars
), 0); /* strip the mem ref */
1722 parent
= binfo_for_vtable (vars
);
1724 if (parent
== TYPE_BINFO (DECL_CONTEXT (vars
)))
1725 parent_rtx
= const0_rtx
;
1728 parent
= get_vtbl_decl_for_binfo (TYPE_BINFO (BINFO_TYPE (parent
)));
1729 parent_rtx
= XEXP (DECL_RTL (parent
), 0); /* strip the mem ref */
1734 assemble_vtable_inherit (child_rtx
, parent_rtx
);
1737 /* If necessary, write out the vtables for the dynamic class CTYPE.
1738 Returns nonzero if any vtables were emitted. */
1741 maybe_emit_vtables (tree ctype
)
1746 /* If the vtables for this class have already been emitted there is
1747 nothing more to do. */
1748 primary_vtbl
= CLASSTYPE_VTABLES (ctype
);
1749 if (TREE_ASM_WRITTEN (primary_vtbl
))
1751 /* Ignore dummy vtables made by get_vtable_decl. */
1752 if (TREE_TYPE (primary_vtbl
) == void_type_node
)
1755 import_export_class (ctype
);
1756 import_export_vtable (primary_vtbl
, ctype
, 1);
1758 /* See if any of the vtables are needed. */
1759 for (vtbl
= CLASSTYPE_VTABLES (ctype
); vtbl
; vtbl
= TREE_CHAIN (vtbl
))
1760 if (!DECL_EXTERNAL (vtbl
) && DECL_NEEDED_P (vtbl
))
1765 /* If the references to this class' vtables are optimized away,
1766 still emit the appropriate debugging information. See
1768 if (DECL_COMDAT (primary_vtbl
)
1769 && CLASSTYPE_DEBUG_REQUESTED (ctype
))
1770 note_debug_info_needed (ctype
);
1774 /* The ABI requires that we emit all of the vtables if we emit any
1776 for (vtbl
= CLASSTYPE_VTABLES (ctype
); vtbl
; vtbl
= TREE_CHAIN (vtbl
))
1779 import_export_vtable (vtbl
, ctype
, 1);
1780 mark_vtable_entries (vtbl
);
1781 if (TREE_TYPE (DECL_INITIAL (vtbl
)) == 0)
1782 store_init_value (vtbl
, DECL_INITIAL (vtbl
));
1784 if (write_symbols
== DWARF_DEBUG
|| write_symbols
== DWARF2_DEBUG
)
1786 /* Mark the VAR_DECL node representing the vtable itself as a
1787 "gratuitous" one, thereby forcing dwarfout.c to ignore it.
1788 It is rather important that such things be ignored because
1789 any effort to actually generate DWARF for them will run
1790 into trouble when/if we encounter code like:
1793 struct S { virtual void member (); };
1795 because the artificial declaration of the vtable itself (as
1796 manufactured by the g++ front end) will say that the vtable
1797 is a static member of `S' but only *after* the debug output
1798 for the definition of `S' has already been output. This causes
1799 grief because the DWARF entry for the definition of the vtable
1800 will try to refer back to an earlier *declaration* of the
1801 vtable as a static member of `S' and there won't be one.
1802 We might be able to arrange to have the "vtable static member"
1803 attached to the member list for `S' before the debug info for
1804 `S' get written (which would solve the problem) but that would
1805 require more intrusive changes to the g++ front end. */
1807 DECL_IGNORED_P (vtbl
) = 1;
1810 /* Always make vtables weak. */
1812 comdat_linkage (vtbl
);
1814 rest_of_decl_compilation (vtbl
, NULL
, 1, 1);
1817 output_vtable_inherit (vtbl
);
1819 /* Because we're only doing syntax-checking, we'll never end up
1820 actually marking the variable as written. */
1821 if (flag_syntax_only
)
1822 TREE_ASM_WRITTEN (vtbl
) = 1;
1825 /* Since we're writing out the vtable here, also write the debug
1827 note_debug_info_needed (ctype
);
1832 /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an
1833 inline function or template instantiation at end-of-file. */
1836 import_export_decl (decl
)
1839 if (DECL_INTERFACE_KNOWN (decl
))
1842 if (DECL_TEMPLATE_INSTANTIATION (decl
)
1843 || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl
))
1845 DECL_NOT_REALLY_EXTERN (decl
) = 1;
1846 if ((DECL_IMPLICIT_INSTANTIATION (decl
)
1847 || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl
))
1848 && (flag_implicit_templates
1849 || (flag_implicit_inline_templates
1850 && DECL_DECLARED_INLINE_P (decl
))))
1852 if (!TREE_PUBLIC (decl
))
1853 /* Templates are allowed to have internal linkage. See
1857 comdat_linkage (decl
);
1861 DECL_EXTERNAL (decl
) = 1;
1862 DECL_NOT_REALLY_EXTERN (decl
) = 0;
1865 else if (DECL_FUNCTION_MEMBER_P (decl
))
1867 if (!DECL_DECLARED_INLINE_P (decl
))
1869 tree ctype
= DECL_CONTEXT (decl
);
1870 import_export_class (ctype
);
1871 if (CLASSTYPE_INTERFACE_KNOWN (ctype
))
1873 DECL_NOT_REALLY_EXTERN (decl
)
1874 = ! (CLASSTYPE_INTERFACE_ONLY (ctype
)
1875 || (DECL_DECLARED_INLINE_P (decl
)
1876 && ! flag_implement_inlines
1877 && !DECL_VINDEX (decl
)));
1879 if (!DECL_NOT_REALLY_EXTERN (decl
))
1880 DECL_EXTERNAL (decl
) = 1;
1882 /* Always make artificials weak. */
1883 if (DECL_ARTIFICIAL (decl
) && flag_weak
)
1884 comdat_linkage (decl
);
1886 maybe_make_one_only (decl
);
1890 comdat_linkage (decl
);
1893 comdat_linkage (decl
);
1895 DECL_INTERFACE_KNOWN (decl
) = 1;
1898 /* Here, we only decide whether or not the tinfo node should be
1899 emitted with the vtable. IS_IN_LIBRARY is nonzero iff the
1900 typeinfo for TYPE should be in the runtime library. */
1903 import_export_tinfo (decl
, type
, is_in_library
)
1908 if (DECL_INTERFACE_KNOWN (decl
))
1911 if (IS_AGGR_TYPE (type
))
1912 import_export_class (type
);
1914 if (IS_AGGR_TYPE (type
) && CLASSTYPE_INTERFACE_KNOWN (type
)
1915 && TYPE_POLYMORPHIC_P (type
)
1916 /* If -fno-rtti, we're not necessarily emitting this stuff with
1917 the class, so go ahead and emit it now. This can happen when
1918 a class is used in exception handling. */
1921 DECL_NOT_REALLY_EXTERN (decl
) = !CLASSTYPE_INTERFACE_ONLY (type
);
1922 DECL_COMDAT (decl
) = 0;
1926 DECL_NOT_REALLY_EXTERN (decl
) = 1;
1927 DECL_COMDAT (decl
) = 1;
1930 /* Now override some cases. */
1932 DECL_COMDAT (decl
) = 1;
1933 else if (is_in_library
)
1934 DECL_COMDAT (decl
) = 0;
1936 DECL_INTERFACE_KNOWN (decl
) = 1;
1940 build_cleanup (decl
)
1944 tree type
= TREE_TYPE (decl
);
1946 if (TREE_CODE (type
) == ARRAY_TYPE
)
1950 cxx_mark_addressable (decl
);
1951 temp
= build1 (ADDR_EXPR
, build_pointer_type (type
), decl
);
1953 temp
= build_delete (TREE_TYPE (temp
), temp
,
1954 sfk_complete_destructor
,
1955 LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
|LOOKUP_DESTRUCTOR
, 0);
1959 /* Returns the initialization guard variable for the variable DECL,
1960 which has static storage duration. */
1969 sname
= mangle_guard_variable (decl
);
1970 guard
= IDENTIFIER_GLOBAL_VALUE (sname
);
1975 /* We use a type that is big enough to contain a mutex as well
1976 as an integer counter. */
1977 guard_type
= long_long_integer_type_node
;
1978 guard
= build_decl (VAR_DECL
, sname
, guard_type
);
1980 /* The guard should have the same linkage as what it guards. */
1981 TREE_PUBLIC (guard
) = TREE_PUBLIC (decl
);
1982 TREE_STATIC (guard
) = TREE_STATIC (decl
);
1983 DECL_COMMON (guard
) = DECL_COMMON (decl
);
1984 DECL_ONE_ONLY (guard
) = DECL_ONE_ONLY (decl
);
1985 if (TREE_PUBLIC (decl
))
1986 DECL_WEAK (guard
) = DECL_WEAK (decl
);
1988 DECL_ARTIFICIAL (guard
) = 1;
1989 TREE_USED (guard
) = 1;
1990 pushdecl_top_level (guard
);
1991 cp_finish_decl (guard
, NULL_TREE
, NULL_TREE
, 0);
1996 /* Return those bits of the GUARD variable that should be set when the
1997 guarded entity is actually initialized. */
2000 get_guard_bits (guard
)
2003 /* We only set the first byte of the guard, in order to leave room
2004 for a mutex in the high-order bits. */
2005 guard
= build1 (ADDR_EXPR
,
2006 build_pointer_type (TREE_TYPE (guard
)),
2008 guard
= build1 (NOP_EXPR
,
2009 build_pointer_type (char_type_node
),
2011 guard
= build1 (INDIRECT_REF
, char_type_node
, guard
);
2016 /* Return an expression which determines whether or not the GUARD
2017 variable has already been initialized. */
2020 get_guard_cond (guard
)
2025 /* Check to see if the GUARD is zero. */
2026 guard
= get_guard_bits (guard
);
2027 guard_value
= integer_zero_node
;
2028 if (!same_type_p (TREE_TYPE (guard_value
), TREE_TYPE (guard
)))
2029 guard_value
= convert (TREE_TYPE (guard
), guard_value
);
2030 return cp_build_binary_op (EQ_EXPR
, guard
, guard_value
);
2033 /* Return an expression which sets the GUARD variable, indicating that
2034 the variable being guarded has been initialized. */
2042 /* Set the GUARD to one. */
2043 guard
= get_guard_bits (guard
);
2044 guard_init
= integer_one_node
;
2045 if (!same_type_p (TREE_TYPE (guard_init
), TREE_TYPE (guard
)))
2046 guard_init
= convert (TREE_TYPE (guard
), guard_init
);
2047 return build_modify_expr (guard
, NOP_EXPR
, guard_init
);
2050 /* Start the process of running a particular set of global constructors
2051 or destructors. Subroutine of do_[cd]tors. */
2054 start_objects (method_type
, initp
)
2055 int method_type
, initp
;
2061 /* Make ctor or dtor function. METHOD_TYPE may be 'I' or 'D'. */
2063 if (initp
!= DEFAULT_INIT_PRIORITY
)
2073 sprintf (type
, "%c%c%.5u", method_type
, joiner
, initp
);
2076 sprintf (type
, "%c", method_type
);
2078 fnname
= get_file_function_name_long (type
);
2080 start_function (void_list_node
,
2081 make_call_declarator (fnname
, void_list_node
, NULL_TREE
,
2083 NULL_TREE
, SF_DEFAULT
);
2085 /* It can be a static function as long as collect2 does not have
2086 to scan the object file to find its ctor/dtor routine. */
2087 TREE_PUBLIC (current_function_decl
) = ! targetm
.have_ctors_dtors
;
2089 /* Mark this declaration as used to avoid spurious warnings. */
2090 TREE_USED (current_function_decl
) = 1;
2092 /* Mark this function as a global constructor or destructor. */
2093 if (method_type
== 'I')
2094 DECL_GLOBAL_CTOR_P (current_function_decl
) = 1;
2096 DECL_GLOBAL_DTOR_P (current_function_decl
) = 1;
2097 DECL_LANG_SPECIFIC (current_function_decl
)->decl_flags
.u2sel
= 1;
2099 body
= begin_compound_stmt (/*has_no_scope=*/0);
2101 /* We cannot allow these functions to be elided, even if they do not
2102 have external linkage. And, there's no point in deferring
2103 copmilation of thes functions; they're all going to have to be
2105 current_function_cannot_inline
2106 = "static constructors and destructors cannot be inlined";
2111 /* Finish the process of running a particular set of global constructors
2112 or destructors. Subroutine of do_[cd]tors. */
2115 finish_objects (method_type
, initp
, body
)
2116 int method_type
, initp
;
2122 finish_compound_stmt (/*has_no_scope=*/0, body
);
2123 fn
= finish_function (0);
2126 /* When only doing semantic analysis, and no RTL generation, we
2127 can't call functions that directly emit assembly code; there is
2128 no assembly file in which to put the code. */
2129 if (flag_syntax_only
)
2132 if (targetm
.have_ctors_dtors
)
2134 rtx fnsym
= XEXP (DECL_RTL (fn
), 0);
2135 if (method_type
== 'I')
2136 (* targetm
.asm_out
.constructor
) (fnsym
, initp
);
2138 (* targetm
.asm_out
.destructor
) (fnsym
, initp
);
2142 /* The names of the parameters to the function created to handle
2143 initializations and destructions for objects with static storage
2145 #define INITIALIZE_P_IDENTIFIER "__initialize_p"
2146 #define PRIORITY_IDENTIFIER "__priority"
2148 /* The name of the function we create to handle initializations and
2149 destructions for objects with static storage duration. */
2150 #define SSDF_IDENTIFIER "__static_initialization_and_destruction"
2152 /* The declaration for the __INITIALIZE_P argument. */
2153 static GTY(()) tree initialize_p_decl
;
2155 /* The declaration for the __PRIORITY argument. */
2156 static GTY(()) tree priority_decl
;
2158 /* The declaration for the static storage duration function. */
2159 static GTY(()) tree ssdf_decl
;
2161 /* All the static storage duration functions created in this
2162 translation unit. */
2163 static GTY(()) varray_type ssdf_decls
;
2165 /* A map from priority levels to information about that priority
2166 level. There may be many such levels, so efficient lookup is
2168 static splay_tree priority_info_map
;
2170 /* Begins the generation of the function that will handle all
2171 initialization and destruction of objects with static storage
2172 duration. The function generated takes two parameters of type
2173 `int': __INITIALIZE_P and __PRIORITY. If __INITIALIZE_P is
2174 nonzero, it performs initializations. Otherwise, it performs
2175 destructions. It only performs those initializations or
2176 destructions with the indicated __PRIORITY. The generated function
2179 It is assumed that this function will only be called once per
2180 translation unit. */
2183 start_static_storage_duration_function ()
2185 static unsigned ssdf_number
;
2190 char id
[sizeof (SSDF_IDENTIFIER
) + 1 /* '\0' */ + 32];
2192 /* Create the identifier for this function. It will be of the form
2193 SSDF_IDENTIFIER_<number>. */
2194 sprintf (id
, "%s_%u", SSDF_IDENTIFIER
, ssdf_number
++);
2195 if (ssdf_number
== 0)
2197 /* Overflow occurred. That means there are at least 4 billion
2198 initialization functions. */
2199 sorry ("too many initialization functions required");
2203 /* Create the parameters. */
2204 parm_types
= void_list_node
;
2205 parm_types
= tree_cons (NULL_TREE
, integer_type_node
, parm_types
);
2206 parm_types
= tree_cons (NULL_TREE
, integer_type_node
, parm_types
);
2207 type
= build_function_type (void_type_node
, parm_types
);
2209 /* Create the FUNCTION_DECL itself. */
2210 ssdf_decl
= build_lang_decl (FUNCTION_DECL
,
2211 get_identifier (id
),
2213 TREE_PUBLIC (ssdf_decl
) = 0;
2214 DECL_ARTIFICIAL (ssdf_decl
) = 1;
2216 /* Put this function in the list of functions to be called from the
2217 static constructors and destructors. */
2220 VARRAY_TREE_INIT (ssdf_decls
, 32, "ssdf_decls");
2222 /* Take this opportunity to initialize the map from priority
2223 numbers to information about that priority level. */
2224 priority_info_map
= splay_tree_new (splay_tree_compare_ints
,
2225 /*delete_key_fn=*/0,
2226 /*delete_value_fn=*/
2227 (splay_tree_delete_value_fn
) &free
);
2229 /* We always need to generate functions for the
2230 DEFAULT_INIT_PRIORITY so enter it now. That way when we walk
2231 priorities later, we'll be sure to find the
2232 DEFAULT_INIT_PRIORITY. */
2233 get_priority_info (DEFAULT_INIT_PRIORITY
);
2236 VARRAY_PUSH_TREE (ssdf_decls
, ssdf_decl
);
2238 /* Create the argument list. */
2239 initialize_p_decl
= cp_build_parm_decl
2240 (get_identifier (INITIALIZE_P_IDENTIFIER
), integer_type_node
);
2241 DECL_CONTEXT (initialize_p_decl
) = ssdf_decl
;
2242 TREE_USED (initialize_p_decl
) = 1;
2243 priority_decl
= cp_build_parm_decl
2244 (get_identifier (PRIORITY_IDENTIFIER
), integer_type_node
);
2245 DECL_CONTEXT (priority_decl
) = ssdf_decl
;
2246 TREE_USED (priority_decl
) = 1;
2248 TREE_CHAIN (initialize_p_decl
) = priority_decl
;
2249 DECL_ARGUMENTS (ssdf_decl
) = initialize_p_decl
;
2251 /* Put the function in the global scope. */
2252 pushdecl (ssdf_decl
);
2254 /* Start the function itself. This is equivalent to declarating the
2257 static void __ssdf (int __initialize_p, init __priority_p);
2259 It is static because we only need to call this function from the
2260 various constructor and destructor functions for this module. */
2261 start_function (/*specs=*/NULL_TREE
,
2263 /*attrs=*/NULL_TREE
,
2266 /* Set up the scope of the outermost block in the function. */
2267 body
= begin_compound_stmt (/*has_no_scope=*/0);
2269 /* This function must not be deferred because we are depending on
2270 its compilation to tell us what is TREE_SYMBOL_REFERENCED. */
2271 current_function_cannot_inline
2272 = "static storage duration functions cannot be inlined";
2277 /* Finish the generation of the function which performs initialization
2278 and destruction of objects with static storage duration. After
2279 this point, no more such objects can be created. */
2282 finish_static_storage_duration_function (body
)
2285 /* Close out the function. */
2286 finish_compound_stmt (/*has_no_scope=*/0, body
);
2287 expand_body (finish_function (0));
2290 /* Return the information about the indicated PRIORITY level. If no
2291 code to handle this level has yet been generated, generate the
2292 appropriate prologue. */
2294 static priority_info
2295 get_priority_info (priority
)
2301 n
= splay_tree_lookup (priority_info_map
,
2302 (splay_tree_key
) priority
);
2305 /* Create a new priority information structure, and insert it
2307 pi
= (priority_info
) xmalloc (sizeof (struct priority_info_s
));
2308 pi
->initializations_p
= 0;
2309 pi
->destructions_p
= 0;
2310 splay_tree_insert (priority_info_map
,
2311 (splay_tree_key
) priority
,
2312 (splay_tree_value
) pi
);
2315 pi
= (priority_info
) n
->value
;
2320 /* Set up to handle the initialization or destruction of DECL. If
2321 INITP is nonzero, we are initializing the variable. Otherwise, we
2322 are destroying it. */
2325 start_static_initialization_or_destruction (decl
, initp
)
2329 tree guard_if_stmt
= NULL_TREE
;
2336 /* Figure out the priority for this declaration. */
2337 priority
= DECL_INIT_PRIORITY (decl
);
2339 priority
= DEFAULT_INIT_PRIORITY
;
2341 /* Remember that we had an initialization or finalization at this
2343 pi
= get_priority_info (priority
);
2345 pi
->initializations_p
= 1;
2347 pi
->destructions_p
= 1;
2349 /* Trick the compiler into thinking we are at the file and line
2350 where DECL was declared so that error-messages make sense, and so
2351 that the debugger will show somewhat sensible file and line
2353 input_filename
= DECL_SOURCE_FILE (decl
);
2354 lineno
= DECL_SOURCE_LINE (decl
);
2360 Access control for implicit calls to the constructors,
2361 the conversion functions, or the destructor called to
2362 create and destroy a static data member is performed as
2363 if these calls appeared in the scope of the member's
2366 we pretend we are in a static member function of the class of
2367 which the DECL is a member. */
2368 if (member_p (decl
))
2370 DECL_CONTEXT (current_function_decl
) = DECL_CONTEXT (decl
);
2371 DECL_STATIC_FUNCTION_P (current_function_decl
) = 1;
2374 /* Conditionalize this initialization on being in the right priority
2375 and being initializing/finalizing appropriately. */
2376 guard_if_stmt
= begin_if_stmt ();
2377 cond
= cp_build_binary_op (EQ_EXPR
,
2379 build_int_2 (priority
, 0));
2380 init_cond
= initp
? integer_one_node
: integer_zero_node
;
2381 init_cond
= cp_build_binary_op (EQ_EXPR
,
2384 cond
= cp_build_binary_op (TRUTH_ANDIF_EXPR
, cond
, init_cond
);
2386 /* Assume we don't need a guard. */
2388 /* We need a guard if this is an object with external linkage that
2389 might be initialized in more than one place. (For example, a
2390 static data member of a template, when the data member requires
2392 if (TREE_PUBLIC (decl
) && (DECL_COMMON (decl
)
2393 || DECL_ONE_ONLY (decl
)
2394 || DECL_WEAK (decl
)))
2398 guard
= get_guard (decl
);
2400 /* When using __cxa_atexit, we just check the GUARD as we would
2401 for a local static. */
2402 if (flag_use_cxa_atexit
)
2404 /* When using __cxa_atexit, we never try to destroy
2405 anything from a static destructor. */
2406 my_friendly_assert (initp
, 20000629);
2407 guard_cond
= get_guard_cond (guard
);
2409 /* If we don't have __cxa_atexit, then we will be running
2410 destructors from .fini sections, or their equivalents. So,
2411 we need to know how many times we've tried to initialize this
2412 object. We do initializations only if the GUARD is zero,
2413 i.e., if we are the first to initialize the variable. We do
2414 destructions only if the GUARD is one, i.e., if we are the
2415 last to destroy the variable. */
2418 = cp_build_binary_op (EQ_EXPR
,
2419 build_unary_op (PREINCREMENT_EXPR
,
2425 = cp_build_binary_op (EQ_EXPR
,
2426 build_unary_op (PREDECREMENT_EXPR
,
2431 cond
= cp_build_binary_op (TRUTH_ANDIF_EXPR
, cond
, guard_cond
);
2434 finish_if_stmt_cond (cond
, guard_if_stmt
);
2436 /* If we're using __cxa_atexit, we have not already set the GUARD,
2437 so we must do so now. */
2438 if (guard
&& initp
&& flag_use_cxa_atexit
)
2439 finish_expr_stmt (set_guard (guard
));
2441 return guard_if_stmt
;
2444 /* We've just finished generating code to do an initialization or
2445 finalization. GUARD_IF_STMT is the if-statement we used to guard
2446 the initialization. */
2449 finish_static_initialization_or_destruction (guard_if_stmt
)
2452 finish_then_clause (guard_if_stmt
);
2455 /* Now that we're done with DECL we don't need to pretend to be a
2456 member of its class any longer. */
2457 DECL_CONTEXT (current_function_decl
) = NULL_TREE
;
2458 DECL_STATIC_FUNCTION_P (current_function_decl
) = 0;
2461 /* Generate code to do the initialization of DECL, a VAR_DECL with
2462 static storage duration. The initialization is INIT. */
2465 do_static_initialization (decl
, init
)
2471 /* Set up for the initialization. */
2473 = start_static_initialization_or_destruction (decl
,
2476 /* Perform the initialization. */
2478 finish_expr_stmt (init
);
2480 /* If we're using __cxa_atexit, register a a function that calls the
2481 destructor for the object. */
2482 if (flag_use_cxa_atexit
)
2483 register_dtor_fn (decl
);
2486 finish_static_initialization_or_destruction (guard_if_stmt
);
2489 /* Generate code to do the static destruction of DECL. If DECL may be
2490 initialized more than once in different object files, GUARD is the
2491 guard variable to check. PRIORITY is the priority for the
2495 do_static_destruction (decl
)
2500 /* If we're using __cxa_atexit, then destructors are registered
2501 immediately after objects are initialized. */
2502 my_friendly_assert (!flag_use_cxa_atexit
, 20000121);
2504 /* If we don't need a destructor, there's nothing to do. */
2505 if (TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl
)))
2508 /* Actually do the destruction. */
2509 guard_if_stmt
= start_static_initialization_or_destruction (decl
,
2511 finish_expr_stmt (build_cleanup (decl
));
2512 finish_static_initialization_or_destruction (guard_if_stmt
);
2515 /* VARS is a list of variables with static storage duration which may
2516 need initialization and/or finalization. Remove those variables
2517 that don't really need to be initialized or finalized, and return
2518 the resulting list. The order in which the variables appear in
2519 VARS is in reverse order of the order in which they should actually
2520 be initialized. The list we return is in the unreversed order;
2521 i.e., the first variable should be initialized first. */
2524 prune_vars_needing_no_initialization (vars
)
2530 for (var
= vars
, result
= NULL_TREE
;
2532 var
= TREE_CHAIN (var
))
2534 tree decl
= TREE_VALUE (var
);
2535 tree init
= TREE_PURPOSE (var
);
2537 /* Deal gracefully with error. */
2538 if (decl
== error_mark_node
)
2541 /* The only things that can be initialized are variables. */
2542 my_friendly_assert (TREE_CODE (decl
) == VAR_DECL
, 19990420);
2544 /* If this object is not defined, we don't need to do anything
2546 if (DECL_EXTERNAL (decl
))
2549 /* Also, if the initializer already contains errors, we can bail
2551 if (init
&& TREE_CODE (init
) == TREE_LIST
2552 && value_member (error_mark_node
, init
))
2555 /* This variable is going to need initialization and/or
2556 finalization, so we add it to the list. */
2557 result
= tree_cons (init
, decl
, result
);
2563 /* Make sure we have told the back end about all the variables in
2567 write_out_vars (vars
)
2572 for (v
= vars
; v
; v
= TREE_CHAIN (v
))
2573 if (! TREE_ASM_WRITTEN (TREE_VALUE (v
)))
2574 rest_of_decl_compilation (TREE_VALUE (v
), 0, 1, 1);
2577 /* Generate a static constructor (if CONSTRUCTOR_P) or destructor
2578 (otherwise) that will initialize all gobal objects with static
2579 storage duration having the indicated PRIORITY. */
2582 generate_ctor_or_dtor_function (constructor_p
, priority
)
2591 /* We use `I' to indicate initialization and `D' to indicate
2598 /* Begin the function. */
2599 body
= start_objects (function_key
, priority
);
2601 /* Call the static storage duration function with appropriate
2603 for (i
= 0; i
< ssdf_decls
->elements_used
; ++i
)
2605 arguments
= tree_cons (NULL_TREE
, build_int_2 (priority
, 0),
2607 arguments
= tree_cons (NULL_TREE
, build_int_2 (constructor_p
, 0),
2609 finish_expr_stmt (build_function_call (VARRAY_TREE (ssdf_decls
, i
),
2613 /* If we're generating code for the DEFAULT_INIT_PRIORITY, throw in
2614 calls to any functions marked with attributes indicating that
2615 they should be called at initialization- or destruction-time. */
2616 if (priority
== DEFAULT_INIT_PRIORITY
)
2620 for (fns
= constructor_p
? static_ctors
: static_dtors
;
2622 fns
= TREE_CHAIN (fns
))
2623 finish_expr_stmt (build_function_call (TREE_VALUE (fns
), NULL_TREE
));
2626 /* Close out the function. */
2627 finish_objects (function_key
, priority
, body
);
2630 /* Generate constructor and destructor functions for the priority
2634 generate_ctor_and_dtor_functions_for_priority (n
, data
)
2636 void *data ATTRIBUTE_UNUSED
;
2638 int priority
= (int) n
->key
;
2639 priority_info pi
= (priority_info
) n
->value
;
2641 /* Generate the functions themselves, but only if they are really
2643 if (pi
->initializations_p
2644 || (priority
== DEFAULT_INIT_PRIORITY
&& static_ctors
))
2645 generate_ctor_or_dtor_function (/*constructor_p=*/1,
2647 if (pi
->destructions_p
2648 || (priority
== DEFAULT_INIT_PRIORITY
&& static_dtors
))
2649 generate_ctor_or_dtor_function (/*constructor_p=*/0,
2652 /* Keep iterating. */
2656 /* This routine is called from the last rule in yyparse ().
2657 Its job is to create all the code needed to initialize and
2658 destroy the global aggregates. We do the destruction
2659 first, since that way we only need to reverse the decls once. */
2670 /* Bad parse errors. Just forget about it. */
2671 if (! global_bindings_p () || current_class_type
|| decl_namespace_list
)
2674 /* Otherwise, GDB can get confused, because in only knows
2675 about source for LINENO-1 lines. */
2678 interface_unknown
= 1;
2681 /* We now have to write out all the stuff we put off writing out.
2684 o Template specializations that we have not yet instantiated,
2685 but which are needed.
2686 o Initialization and destruction for non-local objects with
2687 static storage duration. (Local objects with static storage
2688 duration are initialized when their scope is first entered,
2689 and are cleaned up via atexit.)
2690 o Virtual function tables.
2692 All of these may cause others to be needed. For example,
2693 instantiating one function may cause another to be needed, and
2694 generating the initializer for an object may cause templates to be
2695 instantiated, etc., etc. */
2697 timevar_push (TV_VARCONST
);
2699 emit_support_tinfos ();
2707 /* If there are templates that we've put off instantiating, do
2709 instantiate_pending_templates ();
2711 /* Write out virtual tables as required. Note that writing out
2712 the virtual table for a template class may cause the
2713 instantiation of members of that class. */
2714 for (t
= dynamic_classes
; t
; t
= TREE_CHAIN (t
))
2715 if (maybe_emit_vtables (TREE_VALUE (t
)))
2718 /* Write out needed type info variables. Writing out one variable
2719 might cause others to be needed. */
2720 if (walk_globals (unemitted_tinfo_decl_p
, emit_tinfo_decl
, /*data=*/0))
2723 /* The list of objects with static storage duration is built up
2724 in reverse order. We clear STATIC_AGGREGATES so that any new
2725 aggregates added during the initialization of these will be
2726 initialized in the correct order when we next come around the
2728 vars
= prune_vars_needing_no_initialization (static_aggregates
);
2729 static_aggregates
= NULL_TREE
;
2735 /* We need to start a new initialization function each time
2736 through the loop. That's because we need to know which
2737 vtables have been referenced, and TREE_SYMBOL_REFERENCED
2738 isn't computed until a function is finished, and written
2739 out. That's a deficiency in the back-end. When this is
2740 fixed, these initialization functions could all become
2741 inline, with resulting performance improvements. */
2742 tree ssdf_body
= start_static_storage_duration_function ();
2744 /* Make sure the back end knows about all the variables. */
2745 write_out_vars (vars
);
2747 /* First generate code to do all the initializations. */
2748 for (v
= vars
; v
; v
= TREE_CHAIN (v
))
2749 do_static_initialization (TREE_VALUE (v
),
2752 /* Then, generate code to do all the destructions. Do these
2753 in reverse order so that the most recently constructed
2754 variable is the first destroyed. If we're using
2755 __cxa_atexit, then we don't need to do this; functions
2756 were registered at initialization time to destroy the
2758 if (!flag_use_cxa_atexit
)
2760 vars
= nreverse (vars
);
2761 for (v
= vars
; v
; v
= TREE_CHAIN (v
))
2762 do_static_destruction (TREE_VALUE (v
));
2767 /* Finish up the static storage duration function for this
2769 finish_static_storage_duration_function (ssdf_body
);
2771 /* All those initializations and finalizations might cause
2772 us to need more inline functions, more template
2773 instantiations, etc. */
2777 for (i
= 0; i
< deferred_fns_used
; ++i
)
2779 tree decl
= VARRAY_TREE (deferred_fns
, i
);
2781 import_export_decl (decl
);
2783 /* Does it need synthesizing? */
2784 if (DECL_ARTIFICIAL (decl
) && ! DECL_INITIAL (decl
)
2786 && (! DECL_REALLY_EXTERN (decl
) || DECL_INLINE (decl
)))
2788 /* Even though we're already at the top-level, we push
2789 there again. That way, when we pop back a few lines
2790 hence, all of our state is restored. Otherwise,
2791 finish_function doesn't clean things up, and we end
2792 up with CURRENT_FUNCTION_DECL set. */
2793 push_to_top_level ();
2794 synthesize_method (decl
);
2795 pop_from_top_level ();
2799 /* We lie to the back-end, pretending that some functions
2800 are not defined when they really are. This keeps these
2801 functions from being put out unnecessarily. But, we must
2802 stop lying when the functions are referenced, or if they
2803 are not comdat since they need to be put out now. This
2804 is done in a separate for cycle, because if some deferred
2805 function is contained in another deferred function later
2806 in deferred_fns varray, rest_of_compilation would skip
2807 this function and we really cannot expand the same
2809 if (DECL_NOT_REALLY_EXTERN (decl
)
2810 && DECL_INITIAL (decl
)
2811 && DECL_NEEDED_P (decl
))
2812 DECL_EXTERNAL (decl
) = 0;
2814 /* If we're going to need to write this function out, and
2815 there's already a body for it, create RTL for it now.
2816 (There might be no body if this is a method we haven't
2817 gotten around to synthesizing yet.) */
2818 if (!DECL_EXTERNAL (decl
)
2819 && DECL_NEEDED_P (decl
)
2820 && DECL_SAVED_TREE (decl
)
2821 && !TREE_ASM_WRITTEN (decl
))
2823 int saved_not_really_extern
;
2825 /* When we call finish_function in expand_body, it will
2826 try to reset DECL_NOT_REALLY_EXTERN so we save and
2828 saved_not_really_extern
= DECL_NOT_REALLY_EXTERN (decl
);
2829 /* Generate RTL for this function now that we know we
2832 /* Undo the damage done by finish_function. */
2833 DECL_EXTERNAL (decl
) = 0;
2834 DECL_NOT_REALLY_EXTERN (decl
) = saved_not_really_extern
;
2835 /* If we're compiling -fsyntax-only pretend that this
2836 function has been written out so that we don't try to
2838 if (flag_syntax_only
)
2839 TREE_ASM_WRITTEN (decl
) = 1;
2844 if (deferred_fns_used
2845 && wrapup_global_declarations (&VARRAY_TREE (deferred_fns
, 0),
2848 if (walk_namespaces (wrapup_globals_for_namespace
, /*data=*/0))
2851 /* Static data members are just like namespace-scope globals. */
2852 for (i
= 0; i
< pending_statics_used
; ++i
)
2854 tree decl
= VARRAY_TREE (pending_statics
, i
);
2855 if (TREE_ASM_WRITTEN (decl
))
2857 import_export_decl (decl
);
2858 if (DECL_NOT_REALLY_EXTERN (decl
) && ! DECL_IN_AGGR_P (decl
))
2859 DECL_EXTERNAL (decl
) = 0;
2862 && wrapup_global_declarations (&VARRAY_TREE (pending_statics
, 0),
2863 pending_statics_used
))
2868 /* All used inline functions must have a definition at this point. */
2869 for (i
= 0; i
< deferred_fns_used
; ++i
)
2871 tree decl
= VARRAY_TREE (deferred_fns
, i
);
2873 if (TREE_USED (decl
) && DECL_DECLARED_INLINE_P (decl
)
2874 && !(TREE_ASM_WRITTEN (decl
) || DECL_SAVED_TREE (decl
)))
2875 cp_warning_at ("inline function `%D' used but never defined", decl
);
2878 /* We give C linkage to static constructors and destructors. */
2879 push_lang_context (lang_name_c
);
2881 /* Generate initialization and destruction functions for all
2882 priorities for which they are required. */
2883 if (priority_info_map
)
2884 splay_tree_foreach (priority_info_map
,
2885 generate_ctor_and_dtor_functions_for_priority
,
2888 /* We're done with the splay-tree now. */
2889 if (priority_info_map
)
2890 splay_tree_delete (priority_info_map
);
2892 /* We're done with static constructors, so we can go back to "C++"
2894 pop_lang_context ();
2896 /* Now, issue warnings about static, but not defined, functions,
2897 etc., and emit debugging information. */
2898 walk_namespaces (wrapup_globals_for_namespace
, /*data=*/&reconsider
);
2899 if (pending_statics
)
2900 check_global_declarations (&VARRAY_TREE (pending_statics
, 0),
2901 pending_statics_used
);
2905 /* The entire file is now complete. If requested, dump everything
2909 FILE *stream
= dump_begin (TDI_all
, &flags
);
2913 dump_node (global_namespace
, flags
& ~TDF_SLIM
, stream
);
2914 dump_end (TDI_all
, stream
);
2918 timevar_pop (TV_VARCONST
);
2920 if (flag_detailed_statistics
)
2922 dump_tree_statistics ();
2923 dump_time_statistics ();
2927 /* This is something of the form 'A()()()()()+1' that has turned out to be an
2928 expr. Since it was parsed like a type, we need to wade through and fix
2929 that. Unfortunately, since operator() is left-associative, we can't use
2930 tail recursion. In the above example, TYPE is `A', and DECL is
2933 Maybe this shouldn't be recursive, but how often will it actually be
2937 reparse_absdcl_as_expr (type
, decl
)
2940 /* do build_functional_cast (type, NULL_TREE) at bottom */
2941 if (TREE_OPERAND (decl
, 0) == NULL_TREE
)
2942 return build_functional_cast (type
, NULL_TREE
);
2945 decl
= reparse_absdcl_as_expr (type
, TREE_OPERAND (decl
, 0));
2947 return finish_call_expr (decl
, NULL_TREE
, /*disallow_virtual=*/false);
2950 /* This is something of the form `int ((int)(int)(int)1)' that has turned
2951 out to be an expr. Since it was parsed like a type, we need to wade
2952 through and fix that. Since casts are right-associative, we are
2953 reversing the order, so we don't have to recurse.
2955 In the above example, DECL is the `(int)(int)(int)', and EXPR is the
2959 reparse_absdcl_as_casts (decl
, expr
)
2965 if (TREE_CODE (expr
) == CONSTRUCTOR
2966 && TREE_TYPE (expr
) == 0)
2968 type
= groktypename (TREE_VALUE (CALL_DECLARATOR_PARMS (decl
)));
2969 decl
= TREE_OPERAND (decl
, 0);
2971 if (processing_template_decl
)
2972 TREE_TYPE (expr
) = type
;
2975 expr
= digest_init (type
, expr
, (tree
*) 0);
2976 if (TREE_CODE (type
) == ARRAY_TYPE
&& !COMPLETE_TYPE_P (type
))
2978 int failure
= complete_array_type (type
, expr
, 1);
2979 my_friendly_assert (!failure
, 78);
2986 type
= groktypename (TREE_VALUE (CALL_DECLARATOR_PARMS (decl
)));
2987 decl
= TREE_OPERAND (decl
, 0);
2988 if (!VOID_TYPE_P (type
))
2990 expr
= build_c_cast (type
, expr
);
2993 if (warn_old_style_cast
&& ! in_system_header
2994 && non_void_p
&& current_lang_name
!= lang_name_c
)
2995 warning ("use of old-style cast");
3000 /* T is the parse tree for an expression. Return the expression after
3001 performing semantic analysis. */
3004 build_expr_from_tree (t
)
3007 if (t
== NULL_TREE
|| t
== error_mark_node
)
3010 switch (TREE_CODE (t
))
3012 case IDENTIFIER_NODE
:
3013 return do_identifier (t
, 0, NULL_TREE
);
3016 if (LOOKUP_EXPR_GLOBAL (t
))
3018 tree token
= TREE_OPERAND (t
, 0);
3019 return do_scoped_id (token
, IDENTIFIER_GLOBAL_VALUE (token
));
3023 t
= do_identifier (TREE_OPERAND (t
, 0), 0, NULL_TREE
);
3024 if (TREE_CODE (t
) == ALIAS_DECL
)
3025 t
= DECL_INITIAL (t
);
3029 case TEMPLATE_ID_EXPR
:
3035 template = build_expr_from_tree (TREE_OPERAND (t
, 0));
3036 args
= build_expr_from_tree (TREE_OPERAND (t
, 1));
3038 if (TREE_CODE (template) == COMPONENT_REF
)
3040 object
= TREE_OPERAND (template, 0);
3041 template = TREE_OPERAND (template, 1);
3046 template = lookup_template_function (template, args
);
3048 return build (COMPONENT_REF
, TREE_TYPE (template),
3055 return build_x_indirect_ref
3056 (build_expr_from_tree (TREE_OPERAND (t
, 0)), "unary *");
3059 return build_functional_cast
3060 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3062 case REINTERPRET_CAST_EXPR
:
3063 return build_reinterpret_cast
3064 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3066 case CONST_CAST_EXPR
:
3067 return build_const_cast
3068 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3070 case DYNAMIC_CAST_EXPR
:
3071 return build_dynamic_cast
3072 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3074 case STATIC_CAST_EXPR
:
3075 return build_static_cast
3076 (TREE_TYPE (t
), build_expr_from_tree (TREE_OPERAND (t
, 0)));
3078 case PREDECREMENT_EXPR
:
3079 case PREINCREMENT_EXPR
:
3080 case POSTDECREMENT_EXPR
:
3081 case POSTINCREMENT_EXPR
:
3085 case TRUTH_NOT_EXPR
:
3087 case CONVERT_EXPR
: /* Unary + */
3092 return build_x_unary_op (TREE_CODE (t
),
3093 build_expr_from_tree (TREE_OPERAND (t
, 0)));
3098 case TRUNC_DIV_EXPR
:
3100 case FLOOR_DIV_EXPR
:
3101 case ROUND_DIV_EXPR
:
3102 case EXACT_DIV_EXPR
:
3104 case BIT_ANDTC_EXPR
:
3107 case TRUNC_MOD_EXPR
:
3108 case FLOOR_MOD_EXPR
:
3109 case TRUTH_ANDIF_EXPR
:
3110 case TRUTH_ORIF_EXPR
:
3111 case TRUTH_AND_EXPR
:
3126 return build_x_binary_op
3128 build_expr_from_tree (TREE_OPERAND (t
, 0)),
3129 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3132 return build_m_component_ref
3133 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3134 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3137 return build_offset_ref (TREE_OPERAND (t
, 0), TREE_OPERAND (t
, 1));
3140 if (TREE_OPERAND (t
, 0) == NULL_TREE
)
3142 return build_nt (ARRAY_REF
, NULL_TREE
,
3143 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3144 return grok_array_decl (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3145 build_expr_from_tree (TREE_OPERAND (t
, 1)));
3150 tree r
= build_expr_from_tree (TREE_OPERAND (t
, 0));
3152 return TREE_CODE (t
) == SIZEOF_EXPR
? expr_sizeof (r
) : c_alignof_expr (r
);
3154 return cxx_sizeof_or_alignof_type (r
, TREE_CODE (t
), true);
3158 return build_x_modify_expr
3159 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3160 TREE_CODE (TREE_OPERAND (t
, 1)),
3161 build_expr_from_tree (TREE_OPERAND (t
, 2)));
3164 return build_x_arrow
3165 (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3169 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3170 build_expr_from_tree (TREE_OPERAND (t
, 1)),
3171 build_expr_from_tree (TREE_OPERAND (t
, 2)),
3172 NEW_EXPR_USE_GLOBAL (t
));
3175 return delete_sanity
3176 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3177 build_expr_from_tree (TREE_OPERAND (t
, 1)),
3178 DELETE_EXPR_USE_VEC (t
), DELETE_EXPR_USE_GLOBAL (t
));
3181 if (TREE_OPERAND (t
, 1) == NULL_TREE
)
3182 return build_x_compound_expr
3183 (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3187 case METHOD_CALL_EXPR
:
3188 if (TREE_CODE (TREE_OPERAND (t
, 0)) == SCOPE_REF
)
3190 tree ref
= TREE_OPERAND (t
, 0);
3191 tree name
= TREE_OPERAND (ref
, 1);
3193 if (TREE_CODE (name
) == TEMPLATE_ID_EXPR
)
3194 name
= build_nt (TEMPLATE_ID_EXPR
,
3195 TREE_OPERAND (name
, 0),
3196 build_expr_from_tree (TREE_OPERAND (name
, 1)));
3198 return build_scoped_method_call
3199 (build_expr_from_tree (TREE_OPERAND (t
, 1)),
3200 build_expr_from_tree (TREE_OPERAND (ref
, 0)),
3202 build_expr_from_tree (TREE_OPERAND (t
, 2)));
3206 tree fn
= TREE_OPERAND (t
, 0);
3208 /* We can get a TEMPLATE_ID_EXPR here on code like:
3212 so we must resolve that. However, we can also get things
3213 like a BIT_NOT_EXPR here, when referring to a destructor,
3214 and things like that are not correctly resolved by
3215 build_expr_from_tree. So, just use build_expr_from_tree
3216 when we really need it. */
3217 if (TREE_CODE (fn
) == TEMPLATE_ID_EXPR
)
3218 fn
= lookup_template_function
3219 (TREE_OPERAND (fn
, 0),
3220 build_expr_from_tree (TREE_OPERAND (fn
, 1)));
3222 return build_method_call
3223 (build_expr_from_tree (TREE_OPERAND (t
, 1)),
3225 build_expr_from_tree (TREE_OPERAND (t
, 2)),
3226 NULL_TREE
, LOOKUP_NORMAL
);
3230 if (TREE_CODE (TREE_OPERAND (t
, 0)) == SCOPE_REF
)
3232 tree ref
= TREE_OPERAND (t
, 0);
3233 tree name
= TREE_OPERAND (ref
, 1);
3234 tree fn
, scope
, args
;
3236 if (TREE_CODE (name
) == TEMPLATE_ID_EXPR
)
3237 name
= build_nt (TEMPLATE_ID_EXPR
,
3238 TREE_OPERAND (name
, 0),
3239 build_expr_from_tree (TREE_OPERAND (name
, 1)));
3241 scope
= build_expr_from_tree (TREE_OPERAND (ref
, 0));
3242 args
= build_expr_from_tree (TREE_OPERAND (t
, 1));
3243 fn
= resolve_scoped_fn_name (scope
, name
);
3245 return build_call_from_tree (fn
, args
, 1);
3249 tree name
= TREE_OPERAND (t
, 0);
3251 tree args
= build_expr_from_tree (TREE_OPERAND (t
, 1));
3252 if (args
!= NULL_TREE
&& TREE_CODE (name
) == LOOKUP_EXPR
3253 && !LOOKUP_EXPR_GLOBAL (name
)
3254 && TREE_CODE ((id
= TREE_OPERAND (name
, 0))) == IDENTIFIER_NODE
3255 && (!current_class_type
3256 || !lookup_member (current_class_type
, id
, 0, 0)))
3258 /* Do Koenig lookup if there are no class members. */
3259 name
= do_identifier (id
, 0, args
);
3261 else if (TREE_CODE (name
) == TEMPLATE_ID_EXPR
3262 || ! really_overloaded_fn (name
))
3263 name
= build_expr_from_tree (name
);
3265 if (TREE_CODE (name
) == OFFSET_REF
)
3266 return build_offset_ref_call_from_tree (name
, args
);
3267 if (TREE_CODE (name
) == COMPONENT_REF
)
3268 return finish_object_call_expr (TREE_OPERAND (name
, 1),
3269 TREE_OPERAND (name
, 0),
3271 name
= convert_from_reference (name
);
3272 return build_call_from_tree (name
, args
,
3273 /*disallow_virtual=*/false);
3277 return build_x_conditional_expr
3278 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3279 build_expr_from_tree (TREE_OPERAND (t
, 1)),
3280 build_expr_from_tree (TREE_OPERAND (t
, 2)));
3282 case PSEUDO_DTOR_EXPR
:
3283 return (finish_pseudo_destructor_expr
3284 (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3285 build_expr_from_tree (TREE_OPERAND (t
, 1)),
3286 build_expr_from_tree (TREE_OPERAND (t
, 2))));
3290 tree purpose
, value
, chain
;
3292 if (t
== void_list_node
)
3295 purpose
= TREE_PURPOSE (t
);
3297 purpose
= build_expr_from_tree (purpose
);
3298 value
= TREE_VALUE (t
);
3300 value
= build_expr_from_tree (value
);
3301 chain
= TREE_CHAIN (t
);
3302 if (chain
&& chain
!= void_type_node
)
3303 chain
= build_expr_from_tree (chain
);
3304 return tree_cons (purpose
, value
, chain
);
3309 tree object
= build_expr_from_tree (TREE_OPERAND (t
, 0));
3310 tree member
= TREE_OPERAND (t
, 1);
3312 if (!CLASS_TYPE_P (TREE_TYPE (object
)))
3314 if (TREE_CODE (member
) == BIT_NOT_EXPR
)
3315 return finish_pseudo_destructor_expr (object
,
3317 TREE_TYPE (object
));
3318 else if (TREE_CODE (member
) == SCOPE_REF
3319 && (TREE_CODE (TREE_OPERAND (member
, 1)) == BIT_NOT_EXPR
))
3320 return finish_pseudo_destructor_expr (object
,
3321 TREE_OPERAND (t
, 0),
3322 TREE_TYPE (object
));
3324 else if (TREE_CODE (member
) == SCOPE_REF
3325 && TREE_CODE (TREE_OPERAND (member
, 1)) == TEMPLATE_ID_EXPR
)
3330 /* Lookup the template functions now that we know what the
3332 tmpl
= TREE_OPERAND (TREE_OPERAND (member
, 1), 0);
3333 args
= TREE_OPERAND (TREE_OPERAND (member
, 1), 1);
3334 member
= lookup_qualified_name (TREE_OPERAND (member
, 0),
3338 if (BASELINK_P (member
))
3339 BASELINK_FUNCTIONS (member
)
3340 = build_nt (TEMPLATE_ID_EXPR
, BASELINK_FUNCTIONS (member
),
3344 error ("`%D' is not a member of `%T'",
3345 tmpl
, TREE_TYPE (object
));
3346 return error_mark_node
;
3351 return finish_class_member_access_expr (object
, member
);
3355 return build_throw (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3361 tree type
= TREE_TYPE (t
);
3364 /* digest_init will do the wrong thing if we let it. */
3365 if (type
&& TYPE_PTRMEMFUNC_P (type
))
3369 /* We do not want to process the purpose of aggregate
3370 initializers as they are identifier nodes which will be
3371 looked up by digest_init. */
3372 purpose_p
= !(type
&& IS_AGGR_TYPE (type
));
3373 for (elts
= CONSTRUCTOR_ELTS (t
); elts
; elts
= TREE_CHAIN (elts
))
3375 tree purpose
= TREE_PURPOSE (elts
);
3376 tree value
= TREE_VALUE (elts
);
3378 if (purpose
&& purpose_p
)
3379 purpose
= build_expr_from_tree (purpose
);
3380 value
= build_expr_from_tree (value
);
3381 r
= tree_cons (purpose
, value
, r
);
3384 r
= build_nt (CONSTRUCTOR
, NULL_TREE
, nreverse (r
));
3385 TREE_HAS_CONSTRUCTOR (r
) = TREE_HAS_CONSTRUCTOR (t
);
3388 return digest_init (type
, r
, 0);
3393 if (TYPE_P (TREE_OPERAND (t
, 0)))
3394 return get_typeid (TREE_OPERAND (t
, 0));
3395 return build_typeid (build_expr_from_tree (TREE_OPERAND (t
, 0)));
3399 return convert_from_reference (t
);
3402 return build_va_arg (build_expr_from_tree (TREE_OPERAND (t
, 0)),
3410 /* FN is an OFFSET_REF indicating the function to call in parse-tree
3411 form; it has not yet been semantically analyzed. ARGS are the
3412 arguments to the function. They have already been semantically
3416 build_offset_ref_call_from_tree (tree fn
, tree args
)
3420 my_friendly_assert (TREE_CODE (fn
) == OFFSET_REF
, 20020725);
3422 /* A qualified name corresponding to a non-static member
3423 function or a pointer-to-member is represented as an
3426 For both of these function calls, FN will be an OFFSET_REF.
3428 struct A { void f(); };
3429 void A::f() { (A::f) (); }
3431 struct B { void g(); };
3433 void B::g() { (this->*p)(); } */
3435 /* This code is not really correct (for example, it does not
3436 handle the case that `A::f' is overloaded), but it is
3437 historically how we have handled this situation. */
3438 object_addr
= build_unary_op (ADDR_EXPR
, TREE_OPERAND (fn
, 0), 0);
3439 if (TREE_CODE (TREE_OPERAND (fn
, 1)) == FIELD_DECL
)
3440 fn
= resolve_offset_ref (fn
);
3443 fn
= TREE_OPERAND (fn
, 1);
3444 fn
= get_member_function_from_ptrfunc (&object_addr
, fn
);
3446 args
= tree_cons (NULL_TREE
, object_addr
, args
);
3447 return build_function_call (fn
, args
);
3450 /* FN indicates the function to call. Name resolution has been
3451 performed on FN. ARGS are the arguments to the function. They
3452 have already been semantically analyzed. DISALLOW_VIRTUAL is true
3453 if the function call should be determined at compile time, even if
3457 build_call_from_tree (tree fn
, tree args
, bool disallow_virtual
)
3463 /* Check to see that name lookup has already been performed. */
3464 my_friendly_assert (TREE_CODE (fn
) != OFFSET_REF
, 20020725);
3465 my_friendly_assert (TREE_CODE (fn
) != SCOPE_REF
, 20020725);
3467 /* In the future all of this should be eliminated. Instead,
3468 name-lookup for a member function should simply return a
3469 baselink, instead of a FUNCTION_DECL, TEMPLATE_DECL, or
3470 TEMPLATE_ID_EXPR. */
3472 if (TREE_CODE (fn
) == TEMPLATE_ID_EXPR
)
3475 template_args
= TREE_OPERAND (fn
, 1);
3476 fn
= TREE_OPERAND (fn
, 0);
3480 template_id
= NULL_TREE
;
3481 template_args
= NULL_TREE
;
3484 f
= (TREE_CODE (fn
) == OVERLOAD
) ? get_first_fn (fn
) : fn
;
3485 /* Make sure we have a baselink (rather than simply a
3486 FUNCTION_DECL) for a member function. */
3487 if (current_class_type
3488 && ((TREE_CODE (f
) == FUNCTION_DECL
3489 && DECL_FUNCTION_MEMBER_P (f
))
3490 || (DECL_FUNCTION_TEMPLATE_P (f
)
3491 && DECL_FUNCTION_MEMBER_P (f
))))
3493 f
= lookup_member (current_class_type
, DECL_NAME (f
),
3494 /*protect=*/1, /*want_type=*/0);
3501 if (BASELINK_P (fn
))
3502 BASELINK_FUNCTIONS (fn
) = build_nt (TEMPLATE_ID_EXPR
,
3503 BASELINK_FUNCTIONS (fn
),
3509 return finish_call_expr (fn
, args
, disallow_virtual
);
3512 /* This is something of the form `int (*a)++' that has turned out to be an
3513 expr. It was only converted into parse nodes, so we need to go through
3514 and build up the semantics. Most of the work is done by
3515 build_expr_from_tree, above.
3517 In the above example, TYPE is `int' and DECL is `*a'. */
3520 reparse_decl_as_expr (type
, decl
)
3523 decl
= build_expr_from_tree (decl
);
3525 return build_functional_cast (type
, build_tree_list (NULL_TREE
, decl
));
3530 /* This is something of the form `int (*a)' that has turned out to be a
3531 decl. It was only converted into parse nodes, so we need to do the
3532 checking that make_{pointer,reference}_declarator do. */
3535 finish_decl_parsing (decl
)
3538 switch (TREE_CODE (decl
))
3540 case IDENTIFIER_NODE
:
3543 return make_pointer_declarator
3544 (NULL_TREE
, finish_decl_parsing (TREE_OPERAND (decl
, 0)));
3546 return make_reference_declarator
3547 (NULL_TREE
, finish_decl_parsing (TREE_OPERAND (decl
, 0)));
3549 TREE_OPERAND (decl
, 0) = finish_decl_parsing (TREE_OPERAND (decl
, 0));
3552 push_nested_class (TREE_TYPE (TREE_OPERAND (decl
, 0)), 3);
3553 TREE_COMPLEXITY (decl
) = current_class_depth
;
3556 TREE_OPERAND (decl
, 0) = finish_decl_parsing (TREE_OPERAND (decl
, 0));
3559 /* For attribute handling. */
3560 TREE_VALUE (decl
) = finish_decl_parsing (TREE_VALUE (decl
));
3562 case TEMPLATE_ID_EXPR
:
3570 /* Return 1 if root encloses child. */
3573 is_namespace_ancestor (root
, child
)
3578 if (root
== global_namespace
)
3580 if (child
== global_namespace
)
3582 return is_namespace_ancestor (root
, CP_DECL_CONTEXT (child
));
3586 /* Return the namespace that is the common ancestor
3587 of two given namespaces. */
3590 namespace_ancestor (ns1
, ns2
)
3593 if (is_namespace_ancestor (ns1
, ns2
))
3595 return namespace_ancestor (CP_DECL_CONTEXT (ns1
), ns2
);
3598 /* Insert used into the using list of user. Set indirect_flag if this
3599 directive is not directly from the source. Also find the common
3600 ancestor and let our users know about the new namespace */
3602 add_using_namespace (user
, used
, indirect
)
3608 /* Using oneself is a no-op. */
3611 my_friendly_assert (TREE_CODE (user
) == NAMESPACE_DECL
, 380);
3612 my_friendly_assert (TREE_CODE (used
) == NAMESPACE_DECL
, 380);
3613 /* Check if we already have this. */
3614 t
= purpose_member (used
, DECL_NAMESPACE_USING (user
));
3618 /* Promote to direct usage. */
3619 TREE_INDIRECT_USING (t
) = 0;
3623 /* Add used to the user's using list. */
3624 DECL_NAMESPACE_USING (user
)
3625 = tree_cons (used
, namespace_ancestor (user
, used
),
3626 DECL_NAMESPACE_USING (user
));
3628 TREE_INDIRECT_USING (DECL_NAMESPACE_USING (user
)) = indirect
;
3630 /* Add user to the used's users list. */
3631 DECL_NAMESPACE_USERS (used
)
3632 = tree_cons (user
, 0, DECL_NAMESPACE_USERS (used
));
3634 /* Recursively add all namespaces used. */
3635 for (t
= DECL_NAMESPACE_USING (used
); t
; t
= TREE_CHAIN (t
))
3636 /* indirect usage */
3637 add_using_namespace (user
, TREE_PURPOSE (t
), 1);
3639 /* Tell everyone using us about the new used namespaces. */
3640 for (t
= DECL_NAMESPACE_USERS (user
); t
; t
= TREE_CHAIN (t
))
3641 add_using_namespace (TREE_PURPOSE (t
), used
, 1);
3644 /* Combines two sets of overloaded functions into an OVERLOAD chain, removing
3645 duplicates. The first list becomes the tail of the result.
3647 The algorithm is O(n^2). We could get this down to O(n log n) by
3648 doing a sort on the addresses of the functions, if that becomes
3652 merge_functions (s1
, s2
)
3656 for (; s2
; s2
= OVL_NEXT (s2
))
3658 tree fn2
= OVL_CURRENT (s2
);
3661 for (fns1
= s1
; fns1
; fns1
= OVL_NEXT (fns1
))
3663 tree fn1
= OVL_CURRENT (fns1
);
3665 /* If the function from S2 is already in S1, there is no
3666 need to add it again. For `extern "C"' functions, we
3667 might have two FUNCTION_DECLs for the same function, in
3668 different namespaces; again, we only need one of them. */
3670 || (DECL_EXTERN_C_P (fn1
) && DECL_EXTERN_C_P (fn2
)
3671 && DECL_NAME (fn1
) == DECL_NAME (fn2
)))
3675 /* If we exhausted all of the functions in S1, FN2 is new. */
3677 s1
= build_overload (fn2
, s1
);
3682 /* This should return an error not all definitions define functions.
3683 It is not an error if we find two functions with exactly the
3684 same signature, only if these are selected in overload resolution.
3685 old is the current set of bindings, new the freshly-found binding.
3686 XXX Do we want to give *all* candidates in case of ambiguity?
3687 XXX In what way should I treat extern declarations?
3688 XXX I don't want to repeat the entire duplicate_decls here */
3691 ambiguous_decl (name
, old
, new, flags
)
3698 my_friendly_assert (old
!= NULL_TREE
, 393);
3699 /* Copy the value. */
3700 val
= BINDING_VALUE (new);
3702 switch (TREE_CODE (val
))
3705 /* If we expect types or namespaces, and not templates,
3706 or this is not a template class. */
3707 if (LOOKUP_QUALIFIERS_ONLY (flags
)
3708 && !DECL_CLASS_TEMPLATE_P (val
))
3712 if (LOOKUP_NAMESPACES_ONLY (flags
))
3715 case NAMESPACE_DECL
:
3716 if (LOOKUP_TYPES_ONLY (flags
))
3720 /* Ignore built-in functions that are still anticipated. */
3721 if (LOOKUP_QUALIFIERS_ONLY (flags
) || DECL_ANTICIPATED (val
))
3725 if (LOOKUP_QUALIFIERS_ONLY (flags
))
3729 if (!BINDING_VALUE (old
))
3730 BINDING_VALUE (old
) = val
;
3731 else if (val
&& val
!= BINDING_VALUE (old
))
3733 if (is_overloaded_fn (BINDING_VALUE (old
))
3734 && is_overloaded_fn (val
))
3736 BINDING_VALUE (old
) = merge_functions (BINDING_VALUE (old
),
3741 /* Some declarations are functions, some are not. */
3742 if (flags
& LOOKUP_COMPLAIN
)
3744 /* If we've already given this error for this lookup,
3745 BINDING_VALUE (old) is error_mark_node, so let's not
3746 repeat ourselves. */
3747 if (BINDING_VALUE (old
) != error_mark_node
)
3749 error ("use of `%D' is ambiguous", name
);
3750 cp_error_at (" first declared as `%#D' here",
3751 BINDING_VALUE (old
));
3753 cp_error_at (" also declared as `%#D' here", val
);
3755 BINDING_VALUE (old
) = error_mark_node
;
3758 /* ... and copy the type. */
3759 type
= BINDING_TYPE (new);
3760 if (LOOKUP_NAMESPACES_ONLY (flags
))
3762 if (!BINDING_TYPE (old
))
3763 BINDING_TYPE (old
) = type
;
3764 else if (type
&& BINDING_TYPE (old
) != type
)
3766 if (flags
& LOOKUP_COMPLAIN
)
3768 error ("`%D' denotes an ambiguous type",name
);
3769 cp_error_at (" first type here", BINDING_TYPE (old
));
3770 cp_error_at (" other type here", type
);
3776 /* Subroutine of unualified_namespace_lookup:
3777 Add the bindings of NAME in used namespaces to VAL.
3778 We are currently looking for names in namespace SCOPE, so we
3779 look through USINGS for using-directives of namespaces
3780 which have SCOPE as a common ancestor with the current scope.
3781 Returns zero on errors. */
3784 lookup_using_namespace (name
, val
, usings
, scope
, flags
, spacesp
)
3785 tree name
, val
, usings
, scope
;
3791 /* Iterate over all used namespaces in current, searching for using
3792 directives of scope. */
3793 for (iter
= usings
; iter
; iter
= TREE_CHAIN (iter
))
3794 if (TREE_VALUE (iter
) == scope
)
3797 *spacesp
= tree_cons (TREE_PURPOSE (iter
), NULL_TREE
,
3799 val1
= binding_for_name (name
, TREE_PURPOSE (iter
));
3800 /* Resolve ambiguities. */
3801 val
= ambiguous_decl (name
, val
, val1
, flags
);
3803 return BINDING_VALUE (val
) != error_mark_node
;
3807 Accepts the NAME to lookup and its qualifying SCOPE.
3808 Returns the name/type pair found into the CPLUS_BINDING RESULT,
3812 qualified_lookup_using_namespace (name
, scope
, result
, flags
)
3818 /* Maintain a list of namespaces visited... */
3819 tree seen
= NULL_TREE
;
3820 /* ... and a list of namespace yet to see. */
3821 tree todo
= NULL_TREE
;
3823 /* Look through namespace aliases. */
3824 scope
= ORIGINAL_NAMESPACE (scope
);
3825 while (scope
&& (result
!= error_mark_node
))
3827 seen
= tree_cons (scope
, NULL_TREE
, seen
);
3828 result
= ambiguous_decl (name
, result
,
3829 binding_for_name (name
, scope
), flags
);
3830 if (!BINDING_VALUE (result
) && !BINDING_TYPE (result
))
3831 /* Consider using directives. */
3832 for (usings
= DECL_NAMESPACE_USING (scope
); usings
;
3833 usings
= TREE_CHAIN (usings
))
3834 /* If this was a real directive, and we have not seen it. */
3835 if (!TREE_INDIRECT_USING (usings
)
3836 && !purpose_member (TREE_PURPOSE (usings
), seen
))
3837 todo
= tree_cons (TREE_PURPOSE (usings
), NULL_TREE
, todo
);
3840 scope
= TREE_PURPOSE (todo
);
3841 todo
= TREE_CHAIN (todo
);
3844 scope
= NULL_TREE
; /* If there never was a todo list. */
3846 return result
!= error_mark_node
;
3849 /* [namespace.memdef]/2 */
3851 /* Set the context of a declaration to scope. Complain if we are not
3855 set_decl_namespace (decl
, scope
, friendp
)
3862 /* Get rid of namespace aliases. */
3863 scope
= ORIGINAL_NAMESPACE (scope
);
3865 /* It is ok for friends to be qualified in parallel space. */
3866 if (!friendp
&& !is_namespace_ancestor (current_namespace
, scope
))
3867 error ("declaration of `%D' not in a namespace surrounding `%D'",
3869 DECL_CONTEXT (decl
) = FROB_CONTEXT (scope
);
3870 if (scope
!= current_namespace
)
3872 /* See whether this has been declared in the namespace. */
3873 old
= namespace_binding (DECL_NAME (decl
), scope
);
3875 /* No old declaration at all. */
3877 /* A template can be explicitly specialized in any namespace. */
3878 if (processing_explicit_instantiation
)
3880 if (!is_overloaded_fn (decl
))
3881 /* Don't compare non-function decls with decls_match here,
3882 since it can't check for the correct constness at this
3883 point. pushdecl will find those errors later. */
3885 /* Since decl is a function, old should contain a function decl. */
3886 if (!is_overloaded_fn (old
))
3888 if (processing_template_decl
|| processing_specialization
)
3889 /* We have not yet called push_template_decl to turn a
3890 FUNCTION_DECL into a TEMPLATE_DECL, so the declarations
3891 won't match. But, we'll check later, when we construct the
3894 if (is_overloaded_fn (old
))
3896 for (; old
; old
= OVL_NEXT (old
))
3897 if (decls_match (decl
, OVL_CURRENT (old
)))
3901 if (decls_match (decl
, old
))
3907 error ("`%D' should have been declared inside `%D'",
3911 /* Compute the namespace where a declaration is defined. */
3914 decl_namespace (decl
)
3918 decl
= TYPE_STUB_DECL (decl
);
3919 while (DECL_CONTEXT (decl
))
3921 decl
= DECL_CONTEXT (decl
);
3922 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
3925 decl
= TYPE_STUB_DECL (decl
);
3926 my_friendly_assert (DECL_P (decl
), 390);
3929 return global_namespace
;
3932 /* Return the namespace where the current declaration is declared. */
3935 current_decl_namespace ()
3938 /* If we have been pushed into a different namespace, use it. */
3939 if (decl_namespace_list
)
3940 return TREE_PURPOSE (decl_namespace_list
);
3942 if (current_class_type
)
3943 result
= decl_namespace (TYPE_STUB_DECL (current_class_type
));
3944 else if (current_function_decl
)
3945 result
= decl_namespace (current_function_decl
);
3947 result
= current_namespace
;
3951 /* Temporarily set the namespace for the current declaration. */
3954 push_decl_namespace (decl
)
3957 if (TREE_CODE (decl
) != NAMESPACE_DECL
)
3958 decl
= decl_namespace (decl
);
3959 decl_namespace_list
= tree_cons (ORIGINAL_NAMESPACE (decl
),
3960 NULL_TREE
, decl_namespace_list
);
3964 pop_decl_namespace ()
3966 decl_namespace_list
= TREE_CHAIN (decl_namespace_list
);
3969 /* Enter a class or namespace scope. */
3975 if (TREE_CODE (t
) == NAMESPACE_DECL
)
3976 push_decl_namespace (t
);
3977 else if CLASS_TYPE_P (t
)
3978 push_nested_class (t
, 2);
3981 /* Leave scope pushed by push_scope. */
3987 if (TREE_CODE (t
) == NAMESPACE_DECL
)
3988 pop_decl_namespace ();
3989 else if CLASS_TYPE_P (t
)
3990 pop_nested_class ();
3993 /* [basic.lookup.koenig] */
3994 /* A nonzero return value in the functions below indicates an error. */
4004 static int arg_assoc
PARAMS ((struct arg_lookup
*, tree
));
4005 static int arg_assoc_args
PARAMS ((struct arg_lookup
*, tree
));
4006 static int arg_assoc_type
PARAMS ((struct arg_lookup
*, tree
));
4007 static int add_function
PARAMS ((struct arg_lookup
*, tree
));
4008 static int arg_assoc_namespace
PARAMS ((struct arg_lookup
*, tree
));
4009 static int arg_assoc_class
PARAMS ((struct arg_lookup
*, tree
));
4010 static int arg_assoc_template_arg
PARAMS ((struct arg_lookup
*, tree
));
4012 /* Add a function to the lookup structure.
4013 Returns 1 on error. */
4016 add_function (k
, fn
)
4017 struct arg_lookup
*k
;
4020 /* We used to check here to see if the function was already in the list,
4021 but that's O(n^2), which is just too expensive for function lookup.
4022 Now we deal with the occasional duplicate in joust. In doing this, we
4023 assume that the number of duplicates will be small compared to the
4024 total number of functions being compared, which should usually be the
4027 /* We must find only functions, or exactly one non-function. */
4030 else if (is_overloaded_fn (k
->functions
) && is_overloaded_fn (fn
))
4031 k
->functions
= build_overload (fn
, k
->functions
);
4034 tree f1
= OVL_CURRENT (k
->functions
);
4036 if (is_overloaded_fn (f1
))
4038 fn
= f1
; f1
= f2
; f2
= fn
;
4040 cp_error_at ("`%D' is not a function,", f1
);
4041 cp_error_at (" conflict with `%D'", f2
);
4042 error (" in call to `%D'", k
->name
);
4049 /* Add functions of a namespace to the lookup structure.
4050 Returns 1 on error. */
4053 arg_assoc_namespace (k
, scope
)
4054 struct arg_lookup
*k
;
4059 if (purpose_member (scope
, k
->namespaces
))
4061 k
->namespaces
= tree_cons (scope
, NULL_TREE
, k
->namespaces
);
4063 value
= namespace_binding (k
->name
, scope
);
4067 for (; value
; value
= OVL_NEXT (value
))
4068 if (add_function (k
, OVL_CURRENT (value
)))
4074 /* Adds everything associated with a template argument to the lookup
4075 structure. Returns 1 on error. */
4078 arg_assoc_template_arg (k
, arg
)
4079 struct arg_lookup
* k
;
4082 /* [basic.lookup.koenig]
4084 If T is a template-id, its associated namespaces and classes are
4085 ... the namespaces and classes associated with the types of the
4086 template arguments provided for template type parameters
4087 (excluding template template parameters); the namespaces in which
4088 any template template arguments are defined; and the classes in
4089 which any member templates used as template template arguments
4090 are defined. [Note: non-type template arguments do not
4091 contribute to the set of associated namespaces. ] */
4093 /* Consider first template template arguments. */
4094 if (TREE_CODE (arg
) == TEMPLATE_TEMPLATE_PARM
4095 || TREE_CODE (arg
) == UNBOUND_CLASS_TEMPLATE
)
4097 else if (TREE_CODE (arg
) == TEMPLATE_DECL
)
4099 tree ctx
= CP_DECL_CONTEXT (arg
);
4101 /* It's not a member template. */
4102 if (TREE_CODE (ctx
) == NAMESPACE_DECL
)
4103 return arg_assoc_namespace (k
, ctx
);
4104 /* Otherwise, it must be member template. */
4106 return arg_assoc_class (k
, ctx
);
4108 /* It's not a template template argument, but it is a type template
4110 else if (TYPE_P (arg
))
4111 return arg_assoc_type (k
, arg
);
4112 /* It's a non-type template argument. */
4117 /* Adds everything associated with class to the lookup structure.
4118 Returns 1 on error. */
4121 arg_assoc_class (k
, type
)
4122 struct arg_lookup
* k
;
4125 tree list
, friends
, context
;
4128 /* Backend build structures, such as __builtin_va_list, aren't
4129 affected by all this. */
4130 if (!CLASS_TYPE_P (type
))
4133 if (purpose_member (type
, k
->classes
))
4135 k
->classes
= tree_cons (type
, NULL_TREE
, k
->classes
);
4137 context
= decl_namespace (TYPE_MAIN_DECL (type
));
4138 if (arg_assoc_namespace (k
, context
))
4141 /* Process baseclasses. */
4142 for (i
= 0; i
< CLASSTYPE_N_BASECLASSES (type
); i
++)
4143 if (arg_assoc_class (k
, TYPE_BINFO_BASETYPE (type
, i
)))
4146 /* Process friends. */
4147 for (list
= DECL_FRIENDLIST (TYPE_MAIN_DECL (type
)); list
;
4148 list
= TREE_CHAIN (list
))
4149 if (k
->name
== TREE_PURPOSE (list
))
4150 for (friends
= TREE_VALUE (list
); friends
;
4151 friends
= TREE_CHAIN (friends
))
4152 /* Only interested in global functions with potentially hidden
4153 (i.e. unqualified) declarations. */
4154 if (TREE_PURPOSE (friends
) == error_mark_node
&& TREE_VALUE (friends
)
4155 && decl_namespace (TREE_VALUE (friends
)) == context
)
4156 if (add_function (k
, TREE_VALUE (friends
)))
4159 /* Process template arguments. */
4160 if (CLASSTYPE_TEMPLATE_INFO (type
))
4162 list
= INNERMOST_TEMPLATE_ARGS (CLASSTYPE_TI_ARGS (type
));
4163 for (i
= 0; i
< TREE_VEC_LENGTH (list
); ++i
)
4164 arg_assoc_template_arg (k
, TREE_VEC_ELT (list
, i
));
4170 /* Adds everything associated with a given type.
4171 Returns 1 on error. */
4174 arg_assoc_type (k
, type
)
4175 struct arg_lookup
*k
;
4178 switch (TREE_CODE (type
))
4189 if (TYPE_PTRMEMFUNC_P (type
))
4190 return arg_assoc_type (k
, TYPE_PTRMEMFUNC_FN_TYPE (type
));
4191 return arg_assoc_class (k
, type
);
4193 case REFERENCE_TYPE
:
4195 return arg_assoc_type (k
, TREE_TYPE (type
));
4198 return arg_assoc_namespace (k
, decl_namespace (TYPE_MAIN_DECL (type
)));
4200 /* Pointer to member: associate class type and value type. */
4201 if (arg_assoc_type (k
, TYPE_OFFSET_BASETYPE (type
)))
4203 return arg_assoc_type (k
, TREE_TYPE (type
));
4205 /* The basetype is referenced in the first arg type, so just
4208 /* Associate the parameter types. */
4209 if (arg_assoc_args (k
, TYPE_ARG_TYPES (type
)))
4211 /* Associate the return type. */
4212 return arg_assoc_type (k
, TREE_TYPE (type
));
4213 case TEMPLATE_TYPE_PARM
:
4214 case BOUND_TEMPLATE_TEMPLATE_PARM
:
4219 if (type
== unknown_type_node
)
4221 /* else fall through */
4228 /* Adds everything associated with arguments. Returns 1 on error. */
4231 arg_assoc_args (k
, args
)
4232 struct arg_lookup
* k
;
4235 for (; args
; args
= TREE_CHAIN (args
))
4236 if (arg_assoc (k
, TREE_VALUE (args
)))
4241 /* Adds everything associated with a given tree_node. Returns 1 on error. */
4245 struct arg_lookup
* k
;
4248 if (n
== error_mark_node
)
4252 return arg_assoc_type (k
, n
);
4254 if (! type_unknown_p (n
))
4255 return arg_assoc_type (k
, TREE_TYPE (n
));
4257 if (TREE_CODE (n
) == ADDR_EXPR
)
4258 n
= TREE_OPERAND (n
, 0);
4259 if (TREE_CODE (n
) == COMPONENT_REF
)
4260 n
= TREE_OPERAND (n
, 1);
4261 if (TREE_CODE (n
) == OFFSET_REF
)
4262 n
= TREE_OPERAND (n
, 1);
4263 while (TREE_CODE (n
) == TREE_LIST
)
4265 if (TREE_CODE (n
) == BASELINK
)
4266 n
= BASELINK_FUNCTIONS (n
);
4268 if (TREE_CODE (n
) == FUNCTION_DECL
)
4269 return arg_assoc_type (k
, TREE_TYPE (n
));
4270 if (TREE_CODE (n
) == TEMPLATE_ID_EXPR
)
4272 /* [basic.lookup.koenig]
4274 If T is a template-id, its associated namespaces and classes
4275 are the namespace in which the template is defined; for
4276 member templates, the member template's class... */
4277 tree
template = TREE_OPERAND (n
, 0);
4278 tree args
= TREE_OPERAND (n
, 1);
4282 if (TREE_CODE (template) == COMPONENT_REF
)
4283 template = TREE_OPERAND (template, 1);
4285 /* First, the template. There may actually be more than one if
4286 this is an overloaded function template. But, in that case,
4287 we only need the first; all the functions will be in the same
4289 template = OVL_CURRENT (template);
4291 ctx
= CP_DECL_CONTEXT (template);
4293 if (TREE_CODE (ctx
) == NAMESPACE_DECL
)
4295 if (arg_assoc_namespace (k
, ctx
) == 1)
4298 /* It must be a member template. */
4299 else if (arg_assoc_class (k
, ctx
) == 1)
4302 /* Now the arguments. */
4303 for (arg
= args
; arg
!= NULL_TREE
; arg
= TREE_CHAIN (arg
))
4304 if (arg_assoc_template_arg (k
, TREE_VALUE (arg
)) == 1)
4309 my_friendly_assert (TREE_CODE (n
) == OVERLOAD
, 980715);
4311 for (; n
; n
= OVL_CHAIN (n
))
4312 if (arg_assoc_type (k
, TREE_TYPE (OVL_FUNCTION (n
))))
4319 /* Performs Koenig lookup depending on arguments, where fns
4320 are the functions found in normal lookup. */
4323 lookup_arg_dependent (name
, fns
, args
)
4328 struct arg_lookup k
;
4329 tree fn
= NULL_TREE
;
4333 k
.classes
= NULL_TREE
;
4335 /* Note that we've already looked at some namespaces during normal
4336 unqualified lookup, unless we found a decl in function scope. */
4338 fn
= OVL_CURRENT (fns
);
4339 if (fn
&& TREE_CODE (fn
) == FUNCTION_DECL
&& DECL_LOCAL_FUNCTION_P (fn
))
4340 k
.namespaces
= NULL_TREE
;
4342 unqualified_namespace_lookup (name
, 0, &k
.namespaces
);
4344 arg_assoc_args (&k
, args
);
4348 /* Process a namespace-alias declaration. */
4351 do_namespace_alias (alias
, namespace)
4352 tree alias
, namespace;
4354 if (TREE_CODE (namespace) != NAMESPACE_DECL
)
4356 /* The parser did not find it, so it's not there. */
4357 error ("unknown namespace `%D'", namespace);
4361 namespace = ORIGINAL_NAMESPACE (namespace);
4363 /* Build the alias. */
4364 alias
= build_lang_decl (NAMESPACE_DECL
, alias
, void_type_node
);
4365 DECL_NAMESPACE_ALIAS (alias
) = namespace;
4369 /* Check a non-member using-declaration. Return the name and scope
4370 being used, and the USING_DECL, or NULL_TREE on failure. */
4373 validate_nonmember_using_decl (decl
, scope
, name
)
4378 *scope
= global_namespace
;
4381 if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
)
4383 *name
= TREE_OPERAND (decl
, 0);
4385 A using-declaration shall not name a template-id. */
4386 error ("a using-declaration cannot specify a template-id. Try `using %D'", *name
);
4390 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
4392 error ("namespace `%D' not allowed in using-declaration", decl
);
4396 if (is_overloaded_fn (decl
))
4397 decl
= get_first_fn (decl
);
4399 my_friendly_assert (DECL_P (decl
), 20020908);
4401 if (TREE_CODE (decl
) == CONST_DECL
)
4402 /* Enumeration constants to not have DECL_CONTEXT set. */
4403 *scope
= TYPE_CONTEXT (TREE_TYPE (decl
));
4405 *scope
= DECL_CONTEXT (decl
);
4407 *scope
= global_namespace
;
4409 /* [namespace.udecl]
4410 A using-declaration for a class member shall be a
4411 member-declaration. */
4412 if (TYPE_P (*scope
))
4414 error ("`%T' is not a namespace", *scope
);
4417 *name
= DECL_NAME (decl
);
4418 /* Make a USING_DECL. */
4419 return push_using_decl (*scope
, *name
);
4422 /* Process local and global using-declarations. */
4425 do_nonmember_using_decl (scope
, name
, oldval
, oldtype
, newval
, newtype
)
4427 tree oldval
, oldtype
;
4428 tree
*newval
, *newtype
;
4432 *newval
= *newtype
= NULL_TREE
;
4433 decls
= make_node (CPLUS_BINDING
);
4434 if (!qualified_lookup_using_namespace (name
, scope
, decls
, 0))
4438 if (!BINDING_VALUE (decls
) && !BINDING_TYPE (decls
))
4440 error ("`%D' not declared", name
);
4444 /* Check for using functions. */
4445 if (BINDING_VALUE (decls
) && is_overloaded_fn (BINDING_VALUE (decls
)))
4449 if (oldval
&& !is_overloaded_fn (oldval
))
4451 duplicate_decls (OVL_CURRENT (BINDING_VALUE (decls
)), oldval
);
4456 for (tmp
= BINDING_VALUE (decls
); tmp
; tmp
= OVL_NEXT (tmp
))
4458 tree new_fn
= OVL_CURRENT (tmp
);
4460 /* [namespace.udecl]
4462 If a function declaration in namespace scope or block
4463 scope has the same name and the same parameter types as a
4464 function introduced by a using declaration the program is
4466 for (tmp1
= oldval
; tmp1
; tmp1
= OVL_NEXT (tmp1
))
4468 tree old_fn
= OVL_CURRENT (tmp1
);
4470 if (new_fn
== old_fn
)
4471 /* The function already exists in the current namespace. */
4473 else if (OVL_USED (tmp1
))
4474 continue; /* this is a using decl */
4475 else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (new_fn
)),
4476 TYPE_ARG_TYPES (TREE_TYPE (old_fn
))))
4478 /* If this using declaration introduces a function
4479 recognized as a built-in, no longer mark it as
4480 anticipated in this scope. */
4481 if (DECL_ANTICIPATED (old_fn
))
4483 DECL_ANTICIPATED (old_fn
) = 0;
4487 /* There was already a non-using declaration in
4488 this scope with the same parameter types. If both
4489 are the same extern "C" functions, that's ok. */
4490 if (!decls_match (new_fn
, old_fn
))
4491 error ("`%D' is already declared in this scope", name
);
4496 /* If we broke out of the loop, there's no reason to add
4497 this function to the using declarations for this
4502 *newval
= build_overload (OVL_CURRENT (tmp
), *newval
);
4503 if (TREE_CODE (*newval
) != OVERLOAD
)
4504 *newval
= ovl_cons (*newval
, NULL_TREE
);
4505 OVL_USED (*newval
) = 1;
4510 *newval
= BINDING_VALUE (decls
);
4512 duplicate_decls (*newval
, oldval
);
4515 *newtype
= BINDING_TYPE (decls
);
4516 if (oldtype
&& *newtype
&& oldtype
!= *newtype
)
4518 error ("using declaration `%D' introduced ambiguous type `%T'",
4524 /* Process a using-declaration not appearing in class or local scope. */
4527 do_toplevel_using_decl (decl
)
4530 tree scope
, name
, binding
;
4531 tree oldval
, oldtype
, newval
, newtype
;
4533 decl
= validate_nonmember_using_decl (decl
, &scope
, &name
);
4534 if (decl
== NULL_TREE
)
4537 binding
= binding_for_name (name
, current_namespace
);
4539 oldval
= BINDING_VALUE (binding
);
4540 oldtype
= BINDING_TYPE (binding
);
4542 do_nonmember_using_decl (scope
, name
, oldval
, oldtype
, &newval
, &newtype
);
4544 /* Copy declarations found. */
4546 BINDING_VALUE (binding
) = newval
;
4548 BINDING_TYPE (binding
) = newtype
;
4552 /* Process a using-declaration at function scope. */
4555 do_local_using_decl (decl
)
4559 tree oldval
, oldtype
, newval
, newtype
;
4561 decl
= validate_nonmember_using_decl (decl
, &scope
, &name
);
4562 if (decl
== NULL_TREE
)
4565 if (building_stmt_tree ()
4566 && at_function_scope_p ())
4567 add_decl_stmt (decl
);
4569 oldval
= lookup_name_current_level (name
);
4570 oldtype
= lookup_type_current_level (name
);
4572 do_nonmember_using_decl (scope
, name
, oldval
, oldtype
, &newval
, &newtype
);
4576 if (is_overloaded_fn (newval
))
4580 /* We only need to push declarations for those functions
4581 that were not already bound in the current level.
4582 The old value might be NULL_TREE, it might be a single
4583 function, or an OVERLOAD. */
4584 if (oldval
&& TREE_CODE (oldval
) == OVERLOAD
)
4585 term
= OVL_FUNCTION (oldval
);
4588 for (fn
= newval
; fn
&& OVL_CURRENT (fn
) != term
;
4590 push_overloaded_decl (OVL_CURRENT (fn
),
4591 PUSH_LOCAL
| PUSH_USING
);
4594 push_local_binding (name
, newval
, PUSH_USING
);
4597 set_identifier_type_value (name
, newtype
);
4601 do_class_using_decl (decl
)
4606 if (TREE_CODE (decl
) != SCOPE_REF
4607 || !TYPE_P (TREE_OPERAND (decl
, 0)))
4609 error ("using-declaration for non-member at class scope");
4612 name
= TREE_OPERAND (decl
, 1);
4613 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
4615 error ("using-declaration for destructor");
4618 else if (TREE_CODE (name
) == TEMPLATE_ID_EXPR
)
4620 name
= TREE_OPERAND (name
, 0);
4621 error ("a using-declaration cannot specify a template-id. Try `using %T::%D'", TREE_OPERAND (decl
, 0), name
);
4624 if (TREE_CODE (name
) == TYPE_DECL
)
4626 tree type
= TREE_TYPE (name
);
4627 if (CLASSTYPE_USE_TEMPLATE (TREE_TYPE (name
)))
4629 name
= DECL_NAME (CLASSTYPE_TI_TEMPLATE (type
));
4630 error ("a using-declaration cannot specify a template-id.");
4633 name
= DECL_NAME (name
);
4635 else if (TREE_CODE (name
) == TEMPLATE_DECL
)
4636 name
= DECL_NAME (name
);
4637 else if (BASELINK_P (name
))
4641 fns
= BASELINK_FUNCTIONS (name
);
4642 if (TREE_CODE (fns
) == TEMPLATE_ID_EXPR
)
4644 fns
= TREE_OPERAND (fns
, 0);
4645 error ("a using-declaration cannot specify a template-id. Try `using %T::%D'",
4646 BASELINK_ACCESS_BINFO (name
),
4647 DECL_NAME (get_first_fn (fns
)));
4649 name
= DECL_NAME (get_first_fn (fns
));
4652 my_friendly_assert (TREE_CODE (name
) == IDENTIFIER_NODE
, 980716);
4654 value
= build_lang_decl (USING_DECL
, name
, void_type_node
);
4655 DECL_INITIAL (value
) = TREE_OPERAND (decl
, 0);
4659 /* Process a using-directive. */
4662 do_using_directive (namespace)
4665 if (building_stmt_tree ())
4666 add_stmt (build_stmt (USING_STMT
, namespace));
4668 /* using namespace A::B::C; */
4669 if (TREE_CODE (namespace) == SCOPE_REF
)
4670 namespace = TREE_OPERAND (namespace, 1);
4671 if (TREE_CODE (namespace) == IDENTIFIER_NODE
)
4673 /* Lookup in lexer did not find a namespace. */
4674 if (!processing_template_decl
)
4675 error ("namespace `%T' undeclared", namespace);
4678 if (TREE_CODE (namespace) != NAMESPACE_DECL
)
4680 if (!processing_template_decl
)
4681 error ("`%T' is not a namespace", namespace);
4684 namespace = ORIGINAL_NAMESPACE (namespace);
4685 if (!toplevel_bindings_p ())
4686 push_using_directive (namespace);
4689 add_using_namespace (current_namespace
, namespace, 0);
4693 check_default_args (x
)
4696 tree arg
= TYPE_ARG_TYPES (TREE_TYPE (x
));
4697 int saw_def
= 0, i
= 0 - (TREE_CODE (TREE_TYPE (x
)) == METHOD_TYPE
);
4698 for (; arg
&& arg
!= void_list_node
; arg
= TREE_CHAIN (arg
), ++i
)
4700 if (TREE_PURPOSE (arg
))
4704 cp_error_at ("default argument missing for parameter %P of `%+#D'",
4715 TREE_USED (decl
) = 1;
4716 if (processing_template_decl
)
4719 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (decl
)
4720 && !TREE_ASM_WRITTEN (decl
))
4721 /* Remember it, so we can check it was defined. */
4724 if (!skip_evaluation
)
4725 assemble_external (decl
);
4727 /* Is it a synthesized method that needs to be synthesized? */
4728 if (TREE_CODE (decl
) == FUNCTION_DECL
4729 && DECL_NONSTATIC_MEMBER_FUNCTION_P (decl
)
4730 && DECL_ARTIFICIAL (decl
)
4731 && ! DECL_INITIAL (decl
)
4732 /* Kludge: don't synthesize for default args. */
4733 && current_function_decl
)
4735 synthesize_method (decl
);
4736 /* If we've already synthesized the method we don't need to
4737 instantiate it, so we can return right away. */
4741 /* If this is a function or variable that is an instance of some
4742 template, we now know that we will need to actually do the
4743 instantiation. We check that DECL is not an explicit
4744 instantiation because that is not checked in instantiate_decl. */
4745 if ((DECL_NON_THUNK_FUNCTION_P (decl
) || TREE_CODE (decl
) == VAR_DECL
)
4746 && DECL_LANG_SPECIFIC (decl
) && DECL_TEMPLATE_INFO (decl
)
4747 && (!DECL_EXPLICIT_INSTANTIATION (decl
)
4748 || (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INLINE (decl
))))
4749 instantiate_decl (decl
, /*defer_ok=*/1);
4752 /* Helper function for class_head_decl and class_head_defn
4753 nonterminals. AGGR is the class, union or struct tag. SCOPE is the
4754 explicit scope used (NULL for no scope resolution). ID is the
4755 name. DEFN_P is true, if this is a definition of the class and
4756 NEW_TYPE_P is set to nonzero, if we push into the scope containing
4757 the to be defined aggregate.
4759 Return a TYPE_DECL for the type declared by ID in SCOPE. */
4762 handle_class_head (tag_kind
, scope
, id
, attributes
, defn_p
, new_type_p
)
4763 enum tag_types tag_kind
;
4764 tree scope
, id
, attributes
;
4768 tree decl
= NULL_TREE
;
4769 tree current
= current_scope ();
4770 bool xrefd_p
= false;
4772 if (current
== NULL_TREE
)
4773 current
= current_namespace
;
4779 if (TREE_CODE (id
) == TYPE_DECL
)
4780 /* We must bash typedefs back to the main decl of the
4781 type. Otherwise we become confused about scopes. */
4782 decl
= TYPE_MAIN_DECL (TREE_TYPE (id
));
4783 else if (DECL_CLASS_TEMPLATE_P (id
))
4784 decl
= DECL_TEMPLATE_RESULT (id
);
4789 /* According to the suggested resolution of core issue
4790 180, 'typename' is assumed after a class-key. */
4791 decl
= make_typename_type (scope
, id
, tf_error
);
4792 if (decl
!= error_mark_node
)
4793 decl
= TYPE_MAIN_DECL (decl
);
4797 else if (scope
== current
)
4799 /* We've been given AGGR SCOPE::ID, when we're already
4800 inside SCOPE. Be nice about it. */
4802 pedwarn ("extra qualification `%T::' on member `%D' ignored",
4806 error ("`%T' does not have a class or union named `%D'",
4813 decl
= TYPE_MAIN_DECL (xref_tag (tag_kind
, id
, attributes
, !defn_p
));
4817 if (!TYPE_BINFO (TREE_TYPE (decl
)))
4819 error ("`%T' is not a class or union type", decl
);
4820 return error_mark_node
;
4825 /* For a definition, we want to enter the containing scope
4826 before looking up any base classes etc. Only do so, if this
4827 is different to the current scope. */
4828 tree context
= CP_DECL_CONTEXT (decl
);
4830 *new_type_p
= (current
!= context
4831 && TREE_CODE (context
) != TEMPLATE_TYPE_PARM
4832 && TREE_CODE (context
) != BOUND_TEMPLATE_TEMPLATE_PARM
);
4834 push_scope (context
);
4837 && PROCESSING_REAL_TEMPLATE_DECL_P ()
4838 && !CLASSTYPE_TEMPLATE_SPECIALIZATION (TREE_TYPE (decl
)))
4839 decl
= push_template_decl (decl
);
4845 #include "gt-cp-decl2.h"