1 /* Handle the hair of processing (but not expanding) inline functions.
2 Also manage function and variable name overloading.
3 Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 1999, 2000 Free Software Foundation, Inc.
5 Contributed by Michael Tiemann (tiemann@cygnus.com)
7 This file is part of GNU CC.
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
25 /* Handle method declarations. */
38 /* Various flags to control the mangling process. */
44 /* The thing we are presently mangling is part of a template type,
45 rather than a fully instantiated type. Therefore, we may see
46 complex expressions where we would normally expect to see a
47 simple integer constant. */
48 mf_maybe_uninstantiated = 1,
49 /* When mangling a numeric value, use the form `_XX_' (instead of
50 just `XX') if the value has more than one digit. */
51 mf_use_underscores_around_value = 2,
54 typedef enum mangling_flags mangling_flags;
56 static void do_build_assign_ref PARAMS ((tree));
57 static void do_build_copy_constructor PARAMS ((tree));
58 static tree synthesize_exception_spec PARAMS ((tree, tree (*) (tree, void *), void *));
59 static tree locate_dtor PARAMS ((tree, void *));
60 static tree locate_ctor PARAMS ((tree, void *));
61 static tree locate_copy PARAMS ((tree, void *));
63 /* Called once to initialize method.c. */
72 /* Set the mangled name (DECL_ASSEMBLER_NAME) for DECL. */
75 set_mangled_name_for_decl (decl)
78 if (processing_template_decl)
79 /* There's no need to mangle the name of a template function. */
86 /* Given a tree_code CODE, and some arguments (at least one),
87 attempt to use an overloaded operator on the arguments.
89 For unary operators, only the first argument need be checked.
90 For binary operators, both arguments may need to be checked.
92 Member functions can convert class references to class pointers,
93 for one-level deep indirection. More than that is not supported.
94 Operators [](), ()(), and ->() must be member functions.
96 We call function call building calls with LOOKUP_COMPLAIN if they
97 are our only hope. This is true when we see a vanilla operator
98 applied to something of aggregate type. If this fails, we are free
99 to return `error_mark_node', because we will have reported the
102 Operators NEW and DELETE overload in funny ways: operator new takes
103 a single `size' parameter, and operator delete takes a pointer to the
104 storage being deleted. When overloading these operators, success is
105 assumed. If there is a failure, report an error message and return
106 `error_mark_node'. */
110 build_opfncall (code, flags, xarg1, xarg2, arg3)
113 tree xarg1, xarg2, arg3;
115 return build_new_op (code, flags, xarg1, xarg2, arg3);
118 /* This function takes an identifier, ID, and attempts to figure out what
119 it means. There are a number of possible scenarios, presented in increasing
122 1) not in a class's scope
123 2) in class's scope, member name of the class's method
124 3) in class's scope, but not a member name of the class
125 4) in class's scope, member name of a class's variable
127 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
128 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
130 As a last ditch, try to look up the name as a label and return that
133 Values which are declared as being of REFERENCE_TYPE are
134 automatically dereferenced here (as a hack to make the
138 hack_identifier (value, name)
143 if (value == error_mark_node)
144 return error_mark_node;
146 type = TREE_TYPE (value);
147 if (TREE_CODE (value) == FIELD_DECL)
149 if (current_class_ptr == NULL_TREE)
151 if (current_function_decl
152 && DECL_STATIC_FUNCTION_P (current_function_decl))
153 error ("invalid use of member `%D' in static member function",
156 /* We can get here when processing a bad default
158 struct S { int a; void f(int i = a); } */
159 error ("invalid use of member `%D'", value);
161 return error_mark_node;
163 TREE_USED (current_class_ptr) = 1;
165 /* Mark so that if we are in a constructor, and then find that
166 this field was initialized by a base initializer,
167 we can emit an error message. */
168 TREE_USED (value) = 1;
169 value = build_component_ref (current_class_ref, name, NULL_TREE, 1);
171 else if ((TREE_CODE (value) == FUNCTION_DECL
172 && DECL_FUNCTION_MEMBER_P (value))
173 || (TREE_CODE (value) == OVERLOAD
174 && DECL_FUNCTION_MEMBER_P (OVL_CURRENT (value))))
178 if (TREE_CODE (value) == OVERLOAD)
179 value = OVL_CURRENT (value);
181 decl = maybe_dummy_object (DECL_CONTEXT (value), 0);
182 value = build_component_ref (decl, name, NULL_TREE, 1);
184 else if (really_overloaded_fn (value))
186 else if (TREE_CODE (value) == OVERLOAD)
187 /* not really overloaded function */
188 mark_used (OVL_FUNCTION (value));
189 else if (TREE_CODE (value) == TREE_LIST)
191 /* Ambiguous reference to base members, possibly other cases?. */
193 while (t && TREE_CODE (t) == TREE_LIST)
195 mark_used (TREE_VALUE (t));
199 else if (TREE_CODE (value) == NAMESPACE_DECL)
201 error ("use of namespace `%D' as expression", value);
202 return error_mark_node;
204 else if (DECL_CLASS_TEMPLATE_P (value))
206 error ("use of class template `%T' as expression", value);
207 return error_mark_node;
212 if (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == PARM_DECL
213 || TREE_CODE (value) == RESULT_DECL)
215 tree context = decl_function_context (value);
216 if (context != NULL_TREE && context != current_function_decl
217 && ! TREE_STATIC (value))
219 error ("use of %s from containing function",
220 (TREE_CODE (value) == VAR_DECL
221 ? "`auto' variable" : "parameter"));
222 cp_error_at (" `%#D' declared here", value);
223 value = error_mark_node;
227 if (DECL_P (value) && DECL_NONLOCAL (value))
229 if (DECL_CLASS_SCOPE_P (value)
230 && DECL_CONTEXT (value) != current_class_type)
233 path = currently_open_derived_class (DECL_CONTEXT (value));
234 enforce_access (path, value);
237 else if (TREE_CODE (value) == TREE_LIST
238 && TREE_TYPE (value) == error_mark_node)
241 request for member `%D' is ambiguous in multiple inheritance lattice",
243 print_candidates (value);
244 return error_mark_node;
247 if (! processing_template_decl)
248 value = convert_from_reference (value);
253 /* Return a thunk to FUNCTION. For a virtual thunk, DELTA is the
254 offset to this used to locate the vptr, and VCALL_INDEX is used to
255 look up the eventual subobject location. For a non-virtual thunk,
256 DELTA is the offset to this and VCALL_INDEX is NULL. */
259 make_thunk (function, delta, vcall_index)
270 /* Scale the VCALL_INDEX to be in terms of bytes. */
273 = size_binop (MULT_EXPR,
276 TYPE_SIZE_UNIT (vtable_entry_type)));
278 vcall_offset = NULL_TREE;
280 d = tree_low_cst (delta, 0);
282 if (TREE_CODE (function) != ADDR_EXPR)
284 func_decl = TREE_OPERAND (function, 0);
285 if (TREE_CODE (func_decl) != FUNCTION_DECL)
288 thunk_id = mangle_thunk (TREE_OPERAND (function, 0),
289 delta, vcall_offset);
290 thunk = IDENTIFIER_GLOBAL_VALUE (thunk_id);
291 if (thunk && !DECL_THUNK_P (thunk))
293 error ("implementation-reserved name `%D' used", thunk_id);
295 SET_IDENTIFIER_GLOBAL_VALUE (thunk_id, thunk);
297 if (thunk == NULL_TREE)
299 thunk = build_decl (FUNCTION_DECL, thunk_id, TREE_TYPE (func_decl));
300 DECL_LANG_SPECIFIC (thunk) = DECL_LANG_SPECIFIC (func_decl);
301 cxx_dup_lang_specific_decl (func_decl);
302 SET_DECL_ASSEMBLER_NAME (thunk, thunk_id);
303 DECL_CONTEXT (thunk) = DECL_CONTEXT (func_decl);
304 TREE_READONLY (thunk) = TREE_READONLY (func_decl);
305 TREE_THIS_VOLATILE (thunk) = TREE_THIS_VOLATILE (func_decl);
306 TREE_PUBLIC (thunk) = TREE_PUBLIC (func_decl);
308 comdat_linkage (thunk);
309 SET_DECL_THUNK_P (thunk);
310 DECL_INITIAL (thunk) = function;
311 THUNK_DELTA (thunk) = d;
312 THUNK_VCALL_OFFSET (thunk) = vcall_offset;
313 /* The thunk itself is not a constructor or destructor, even if
314 the thing it is thunking to is. */
315 DECL_INTERFACE_KNOWN (thunk) = 1;
316 DECL_NOT_REALLY_EXTERN (thunk) = 1;
317 DECL_SAVED_FUNCTION_DATA (thunk) = NULL;
318 DECL_DESTRUCTOR_P (thunk) = 0;
319 DECL_CONSTRUCTOR_P (thunk) = 0;
320 /* And neither is it a clone. */
321 DECL_CLONED_FUNCTION (thunk) = NULL_TREE;
322 DECL_EXTERNAL (thunk) = 1;
323 DECL_ARTIFICIAL (thunk) = 1;
324 /* Even if this thunk is a member of a local class, we don't
325 need a static chain. */
326 DECL_NO_STATIC_CHAIN (thunk) = 1;
327 /* The THUNK is not a pending inline, even if the FUNC_DECL is. */
328 DECL_PENDING_INLINE_P (thunk) = 0;
329 /* Nor has it been deferred. */
330 DECL_DEFERRED_FN (thunk) = 0;
331 /* So that finish_file can write out any thunks that need to be: */
332 pushdecl_top_level (thunk);
333 SET_IDENTIFIER_GLOBAL_VALUE (thunk_id, thunk);
338 /* Emit the definition of a C++ multiple inheritance vtable thunk. If
339 EMIT_P is non-zero, the thunk is emitted immediately. */
342 use_thunk (thunk_fndecl, emit_p)
351 if (TREE_ASM_WRITTEN (thunk_fndecl))
354 fnaddr = DECL_INITIAL (thunk_fndecl);
355 if (TREE_CODE (DECL_INITIAL (thunk_fndecl)) != ADDR_EXPR)
356 /* We already turned this thunk into an ordinary function.
357 There's no need to process this thunk again. */
360 /* Thunks are always addressable; they only appear in vtables. */
361 TREE_ADDRESSABLE (thunk_fndecl) = 1;
363 /* Figure out what function is being thunked to. It's referenced in
364 this translation unit. */
365 function = TREE_OPERAND (fnaddr, 0);
366 TREE_ADDRESSABLE (function) = 1;
367 mark_used (function);
368 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (function)) = 1;
372 delta = THUNK_DELTA (thunk_fndecl);
373 vcall_offset = THUNK_VCALL_OFFSET (thunk_fndecl);
375 /* And, if we need to emit the thunk, it's used. */
376 mark_used (thunk_fndecl);
377 /* This thunk is actually defined. */
378 DECL_EXTERNAL (thunk_fndecl) = 0;
379 /* The linkage of the function may have changed. FIXME in linkage
381 TREE_PUBLIC (thunk_fndecl) = TREE_PUBLIC (function);
383 if (flag_syntax_only)
385 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
389 push_to_top_level ();
391 /* The back-end expects DECL_INITIAL to contain a BLOCK, so we
393 DECL_INITIAL (thunk_fndecl) = make_node (BLOCK);
394 BLOCK_VARS (DECL_INITIAL (thunk_fndecl))
395 = DECL_ARGUMENTS (thunk_fndecl);
397 #ifdef ASM_OUTPUT_MI_THUNK
401 current_function_decl = thunk_fndecl;
402 DECL_RESULT (thunk_fndecl)
403 = build_decl (RESULT_DECL, 0, integer_type_node);
404 fnname = XSTR (XEXP (DECL_RTL (thunk_fndecl), 0), 0);
405 init_function_start (thunk_fndecl, input_filename, lineno);
406 current_function_is_thunk = 1;
407 assemble_start_function (thunk_fndecl, fnname);
408 ASM_OUTPUT_MI_THUNK (asm_out_file, thunk_fndecl, delta, function);
409 assemble_end_function (thunk_fndecl, fnname);
410 current_function_decl = 0;
412 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
415 #endif /* ASM_OUTPUT_MI_THUNK */
417 /* If we don't have the necessary macro for efficient thunks, generate
418 a thunk function that just makes a call to the real function.
419 Unfortunately, this doesn't work for varargs. */
423 if (varargs_function_p (function))
424 error ("generic thunk code fails for method `%#D' which uses `...'",
427 /* Set up clone argument trees for the thunk. */
429 for (a = DECL_ARGUMENTS (function); a; a = TREE_CHAIN (a))
431 tree x = copy_node (a);
433 DECL_CONTEXT (x) = thunk_fndecl;
437 DECL_ARGUMENTS (thunk_fndecl) = a;
438 DECL_RESULT (thunk_fndecl) = NULL_TREE;
440 start_function (NULL_TREE, thunk_fndecl, NULL_TREE, SF_PRE_PARSED);
441 /* We don't bother with a body block for thunks. */
443 /* Adjust the this pointer by the constant. */
444 t = ssize_int (delta);
445 t = fold (build (PLUS_EXPR, TREE_TYPE (a), a, t));
447 /* If there's a vcall offset, look up that value in the vtable and
448 adjust the `this' pointer again. */
449 if (vcall_offset && !integer_zerop (vcall_offset))
455 /* The vptr is always at offset zero in the object. */
456 t = build1 (NOP_EXPR,
457 build_pointer_type (build_pointer_type
458 (vtable_entry_type)),
460 /* Form the vtable address. */
461 t = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (t)), t);
462 /* Find the entry with the vcall offset. */
463 t = build (PLUS_EXPR, TREE_TYPE (t), t, vcall_offset);
464 /* Calculate the offset itself. */
465 t = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (t)), t);
466 /* Adjust the `this' pointer. */
467 t = fold (build (PLUS_EXPR,
468 TREE_TYPE (orig_this),
473 /* Build up the call to the real function. */
474 t = tree_cons (NULL_TREE, t, NULL_TREE);
475 for (a = TREE_CHAIN (a); a; a = TREE_CHAIN (a))
476 t = tree_cons (NULL_TREE, a, t);
478 t = build_call (function, t);
479 if (VOID_TYPE_P (TREE_TYPE (t)))
480 finish_expr_stmt (t);
482 finish_return_stmt (t);
484 /* Since we want to emit the thunk, we explicitly mark its name as
486 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (thunk_fndecl)) = 1;
488 /* But we don't want debugging information about it. */
489 DECL_IGNORED_P (thunk_fndecl) = 1;
491 expand_body (finish_function (0));
494 pop_from_top_level ();
497 /* Code for synthesizing methods which have default semantics defined. */
499 /* Generate code for default X(X&) constructor. */
502 do_build_copy_constructor (fndecl)
505 tree parm = FUNCTION_FIRST_USER_PARM (fndecl);
508 parm = convert_from_reference (parm);
510 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type)
511 && is_empty_class (current_class_type))
512 /* Don't copy the padding byte; it might not have been allocated
513 if *this is a base subobject. */;
514 else if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type))
516 t = build (INIT_EXPR, void_type_node, current_class_ref, parm);
517 finish_expr_stmt (t);
521 tree fields = TYPE_FIELDS (current_class_type);
522 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
523 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
524 tree member_init_list = NULL_TREE;
525 tree base_init_list = NULL_TREE;
526 int cvquals = cp_type_quals (TREE_TYPE (parm));
529 /* Initialize all the base-classes with the parameter converted
530 to their type so that we get their copy constructor and not
531 another constructor that takes current_class_type. We must
532 deal with the binfo's directly as a direct base might be
533 inaccessible due to ambiguity. */
534 for (t = CLASSTYPE_VBASECLASSES (current_class_type); t;
537 tree binfo = TREE_VALUE (t);
539 base_init_list = tree_cons (binfo,
540 build_base_path (PLUS_EXPR, parm,
545 for (i = 0; i < n_bases; ++i)
547 tree binfo = TREE_VEC_ELT (binfos, i);
548 if (TREE_VIA_VIRTUAL (binfo))
551 base_init_list = tree_cons (binfo,
552 build_base_path (PLUS_EXPR, parm,
557 for (; fields; fields = TREE_CHAIN (fields))
563 if (TREE_CODE (field) != FIELD_DECL)
567 if (DECL_NAME (field))
569 if (VFIELD_NAME_P (DECL_NAME (field)))
572 /* True for duplicate members. */
573 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
576 else if ((t = TREE_TYPE (field)) != NULL_TREE
577 && ANON_AGGR_TYPE_P (t)
578 && TYPE_FIELDS (t) != NULL_TREE)
579 /* Just use the field; anonymous types can't have
580 nontrivial copy ctors or assignment ops. */;
584 /* Compute the type of "init->field". If the copy-constructor
585 parameter is, for example, "const S&", and the type of
586 the field is "T", then the type will usually be "const
587 T". (There are no cv-qualified variants of reference
589 expr_type = TREE_TYPE (field);
590 if (TREE_CODE (expr_type) != REFERENCE_TYPE)
591 expr_type = cp_build_qualified_type (expr_type, cvquals);
592 init = build (COMPONENT_REF, expr_type, init, field);
593 init = build_tree_list (NULL_TREE, init);
596 = tree_cons (field, init, member_init_list);
598 member_init_list = nreverse (member_init_list);
599 base_init_list = nreverse (base_init_list);
600 emit_base_init (member_init_list, base_init_list);
605 do_build_assign_ref (fndecl)
608 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
611 compound_stmt = begin_compound_stmt (/*has_no_scope=*/0);
612 parm = convert_from_reference (parm);
614 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type)
615 && is_empty_class (current_class_type))
616 /* Don't copy the padding byte; it might not have been allocated
617 if *this is a base subobject. */;
618 else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type))
620 tree t = build (MODIFY_EXPR, void_type_node, current_class_ref, parm);
621 finish_expr_stmt (t);
626 int cvquals = cp_type_quals (TREE_TYPE (parm));
629 /* Assign to each of thedirect base classes. */
630 for (i = 0; i < CLASSTYPE_N_BASECLASSES (current_class_type); ++i)
635 binfo = BINFO_BASETYPE (TYPE_BINFO (current_class_type), i);
636 /* We must convert PARM directly to the base class
637 explicitly since the base class may be ambiguous. */
638 converted_parm = build_base_path (PLUS_EXPR, parm, binfo, 1);
639 /* Call the base class assignment operator. */
641 (build_special_member_call (current_class_ref,
642 ansi_assopname (NOP_EXPR),
643 build_tree_list (NULL_TREE,
646 LOOKUP_NORMAL | LOOKUP_NONVIRTUAL));
649 /* Assign to each of the non-static data members. */
650 for (fields = TYPE_FIELDS (current_class_type);
652 fields = TREE_CHAIN (fields))
657 if (TREE_CODE (field) != FIELD_DECL)
660 if (CP_TYPE_CONST_P (TREE_TYPE (field)))
662 error ("non-static const member `%#D', can't use default assignment operator", field);
665 else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
667 error ("non-static reference member `%#D', can't use default assignment operator", field);
671 comp = current_class_ref;
674 if (DECL_NAME (field))
676 if (VFIELD_NAME_P (DECL_NAME (field)))
679 /* True for duplicate members. */
680 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
683 else if ((t = TREE_TYPE (field)) != NULL_TREE
684 && ANON_AGGR_TYPE_P (t)
685 && TYPE_FIELDS (t) != NULL_TREE)
686 /* Just use the field; anonymous types can't have
687 nontrivial copy ctors or assignment ops. */;
691 comp = build (COMPONENT_REF, TREE_TYPE (field), comp, field);
692 init = build (COMPONENT_REF,
693 build_qualified_type (TREE_TYPE (field), cvquals),
696 if (DECL_NAME (field))
697 finish_expr_stmt (build_modify_expr (comp, NOP_EXPR, init));
699 finish_expr_stmt (build (MODIFY_EXPR, TREE_TYPE (comp), comp,
703 finish_return_stmt (current_class_ref);
704 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt);
708 synthesize_method (fndecl)
711 int nested = (current_function_decl != NULL_TREE);
712 tree context = decl_function_context (fndecl);
717 import_export_decl (fndecl);
719 /* If we've been asked to synthesize a clone, just synthesize the
720 cloned function instead. Doing so will automatically fill in the
721 body for the clone. */
722 if (DECL_CLONED_FUNCTION_P (fndecl))
724 synthesize_method (DECL_CLONED_FUNCTION (fndecl));
729 push_to_top_level ();
731 push_function_context_to (context);
733 /* Put the function definition at the position where it is needed,
734 rather than within the body of the class. That way, an error
735 during the generation of the implicit body points at the place
736 where the attempt to generate the function occurs, giving the
737 user a hint as to why we are attempting to generate the
739 DECL_SOURCE_LINE (fndecl) = lineno;
740 DECL_SOURCE_FILE (fndecl) = input_filename;
742 interface_unknown = 1;
743 start_function (NULL_TREE, fndecl, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED);
745 stmt = begin_function_body ();
747 if (DECL_OVERLOADED_OPERATOR_P (fndecl) == NOP_EXPR)
749 do_build_assign_ref (fndecl);
752 else if (DECL_CONSTRUCTOR_P (fndecl))
754 tree arg_chain = FUNCTION_FIRST_USER_PARMTYPE (fndecl);
755 if (arg_chain != void_list_node)
756 do_build_copy_constructor (fndecl);
757 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type))
758 finish_mem_initializers (NULL_TREE);
761 /* If we haven't yet generated the body of the function, just
762 generate an empty compound statement. */
766 compound_stmt = begin_compound_stmt (/*has_no_scope=*/0);
767 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt);
770 finish_function_body (stmt);
771 expand_body (finish_function (0));
773 extract_interface_info ();
775 pop_from_top_level ();
777 pop_function_context_from (context);
780 /* Use EXTRACTOR to locate the relevant function called for each base &
781 class field of TYPE. CLIENT allows additional information to be passed
782 to EXTRACTOR. Generates the union of all exceptions generated by those
783 functions. Note that we haven't updated TYPE_FIELDS and such of any
784 variants yet, so we need to look at the main one. */
787 synthesize_exception_spec (type, extractor, client)
789 tree (*extractor) (tree, void *);
792 tree raises = empty_except_spec;
793 tree fields = TYPE_FIELDS (type);
794 int i, n_bases = CLASSTYPE_N_BASECLASSES (type);
795 tree binfos = TYPE_BINFO_BASETYPES (type);
797 for (i = 0; i != n_bases; i++)
799 tree base = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
800 tree fn = (*extractor) (base, client);
803 tree fn_raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn));
805 raises = merge_exception_specifiers (raises, fn_raises);
808 for (; fields; fields = TREE_CHAIN (fields))
810 tree type = TREE_TYPE (fields);
813 if (TREE_CODE (fields) != FIELD_DECL)
815 while (TREE_CODE (type) == ARRAY_TYPE)
816 type = TREE_TYPE (type);
817 if (TREE_CODE (type) != RECORD_TYPE)
820 fn = (*extractor) (type, client);
823 tree fn_raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn));
825 raises = merge_exception_specifiers (raises, fn_raises);
831 /* Locate the dtor of TYPE. */
834 locate_dtor (type, client)
836 void *client ATTRIBUTE_UNUSED;
840 if (!TYPE_HAS_DESTRUCTOR (type))
842 fns = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type),
843 CLASSTYPE_DESTRUCTOR_SLOT);
847 /* Locate the default ctor of TYPE. */
850 locate_ctor (type, client)
852 void *client ATTRIBUTE_UNUSED;
856 if (!TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
859 fns = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type),
860 CLASSTYPE_CONSTRUCTOR_SLOT);
861 for (; fns; fns = OVL_NEXT (fns))
863 tree fn = OVL_CURRENT (fns);
864 tree parms = TYPE_ARG_TYPES (TREE_TYPE (fn));
866 if (sufficient_parms_p (TREE_CHAIN (parms)))
878 /* Locate the copy ctor or copy assignment of TYPE. CLIENT_
879 points to a COPY_DATA holding the name (NULL for the ctor)
880 and desired qualifiers of the source operand. */
883 locate_copy (type, client_)
887 struct copy_data *client = (struct copy_data *)client_;
890 tree best = NULL_TREE;
895 if (TYPE_HAS_ASSIGN_REF (type))
896 ix = lookup_fnfields_1 (type, client->name);
898 else if (TYPE_HAS_INIT_REF (type))
899 ix = CLASSTYPE_CONSTRUCTOR_SLOT;
902 fns = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), ix);
904 for (; fns; fns = OVL_NEXT (fns))
906 tree fn = OVL_CURRENT (fns);
907 tree parms = TYPE_ARG_TYPES (TREE_TYPE (fn));
912 parms = TREE_CHAIN (parms);
915 src_type = TREE_VALUE (parms);
916 if (TREE_CODE (src_type) == REFERENCE_TYPE)
917 src_type = TREE_TYPE (src_type);
918 if (!same_type_ignoring_top_level_qualifiers_p (src_type, type))
920 if (!sufficient_parms_p (TREE_CHAIN (parms)))
922 quals = cp_type_quals (src_type);
923 if (client->quals & ~quals)
925 excess = quals & ~client->quals;
926 if (!best || (excess_p && !excess))
938 /* Implicitly declare the special function indicated by KIND, as a
939 member of TYPE. For copy constructors and assignment operators,
940 CONST_P indicates whether these functions should take a const
941 reference argument or a non-const reference. */
944 implicitly_declare_fn (kind, type, const_p)
945 special_function_kind kind;
949 tree declspecs = NULL_TREE;
950 tree fn, args = NULL_TREE;
951 tree raises = empty_except_spec;
954 tree name = constructor_name (TYPE_IDENTIFIER (type));
960 name = build_nt (BIT_NOT_EXPR, name);
961 args = void_list_node;
962 raises = synthesize_exception_spec (type, &locate_dtor, 0);
965 case sfk_constructor:
966 /* Default constructor. */
967 args = void_list_node;
968 raises = synthesize_exception_spec (type, &locate_ctor, 0);
971 case sfk_copy_constructor:
972 case sfk_assignment_operator:
974 struct copy_data data;
980 if (kind == sfk_assignment_operator)
983 declspecs = build_tree_list (NULL_TREE, type);
985 name = ansi_assopname (NOP_EXPR);
990 data.quals = TYPE_QUAL_CONST;
991 argtype = build_qualified_type (argtype, TYPE_QUAL_CONST);
994 argtype = build_reference_type (argtype);
995 args = build_tree_list (hash_tree_chain (argtype, NULL_TREE),
996 get_identifier ("_ctor_arg"));
997 args = tree_cons (NULL_TREE, args, void_list_node);
999 raises = synthesize_exception_spec (type, &locate_copy, &data);
1006 TREE_PARMLIST (args) = 1;
1009 tree declarator = make_call_declarator (name, args, NULL_TREE, raises);
1012 declarator = build_nt (ADDR_EXPR, declarator);
1014 fn = grokfield (declarator, declspecs, NULL_TREE, NULL_TREE, NULL_TREE);
1016 TREE_USED (FUNCTION_FIRST_USER_PARM (fn)) = 1;
1019 my_friendly_assert (TREE_CODE (fn) == FUNCTION_DECL, 20000408);
1021 DECL_ARTIFICIAL (fn) = 1;
1022 DECL_NOT_REALLY_EXTERN (fn) = 1;
1023 DECL_DECLARED_INLINE_P (fn) = 1;
1024 DECL_INLINE (fn) = 1;
1030 /* Given a FUNCTION_DECL FN and a chain LIST, skip as many elements of LIST
1031 as there are artificial parms in FN. */
1034 skip_artificial_parms_for (fn, list)
1037 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
1038 list = TREE_CHAIN (list);
1042 if (DECL_HAS_IN_CHARGE_PARM_P (fn))
1043 list = TREE_CHAIN (list);
1044 if (DECL_HAS_VTT_PARM_P (fn))
1045 list = TREE_CHAIN (list);