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, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
5 Free Software Foundation, Inc.
6 Contributed by Michael Tiemann (tiemann@cygnus.com)
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3, or (at your option)
15 GCC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
25 /* Handle method declarations. */
28 #include "coretypes.h"
37 #include "tree-pass.h"
38 #include "diagnostic.h"
42 /* Various flags to control the mangling process. */
48 /* The thing we are presently mangling is part of a template type,
49 rather than a fully instantiated type. Therefore, we may see
50 complex expressions where we would normally expect to see a
51 simple integer constant. */
52 mf_maybe_uninstantiated = 1,
53 /* When mangling a numeric value, use the form `_XX_' (instead of
54 just `XX') if the value has more than one digit. */
55 mf_use_underscores_around_value = 2
58 typedef enum mangling_flags mangling_flags;
60 static void do_build_copy_assign (tree);
61 static void do_build_copy_constructor (tree);
62 static tree make_alias_for_thunk (tree);
64 /* Called once to initialize method.c. */
72 /* Return a this or result adjusting thunk to FUNCTION. THIS_ADJUSTING
73 indicates whether it is a this or result adjusting thunk.
74 FIXED_OFFSET and VIRTUAL_OFFSET indicate how to do the adjustment
75 (see thunk_adjust). VIRTUAL_OFFSET can be NULL, but FIXED_OFFSET
76 never is. VIRTUAL_OFFSET is the /index/ into the vtable for this
77 adjusting thunks, we scale it to a byte offset. For covariant
78 thunks VIRTUAL_OFFSET is the virtual binfo. You must post process
79 the returned thunk with finish_thunk. */
82 make_thunk (tree function, bool this_adjusting,
83 tree fixed_offset, tree virtual_offset)
88 gcc_assert (TREE_CODE (function) == FUNCTION_DECL);
89 /* We can have this thunks to covariant thunks, but not vice versa. */
90 gcc_assert (!DECL_THIS_THUNK_P (function));
91 gcc_assert (!DECL_RESULT_THUNK_P (function) || this_adjusting);
93 /* Scale the VIRTUAL_OFFSET to be in terms of bytes. */
94 if (this_adjusting && virtual_offset)
96 = size_binop (MULT_EXPR,
99 TYPE_SIZE_UNIT (vtable_entry_type)));
101 d = tree_low_cst (fixed_offset, 0);
103 /* See if we already have the thunk in question. For this_adjusting
104 thunks VIRTUAL_OFFSET will be an INTEGER_CST, for covariant thunks it
106 for (thunk = DECL_THUNKS (function); thunk; thunk = TREE_CHAIN (thunk))
107 if (DECL_THIS_THUNK_P (thunk) == this_adjusting
108 && THUNK_FIXED_OFFSET (thunk) == d
109 && !virtual_offset == !THUNK_VIRTUAL_OFFSET (thunk)
112 ? tree_int_cst_equal (THUNK_VIRTUAL_OFFSET (thunk),
114 : THUNK_VIRTUAL_OFFSET (thunk) == virtual_offset)))
117 /* All thunks must be created before FUNCTION is actually emitted;
118 the ABI requires that all thunks be emitted together with the
119 function to which they transfer control. */
120 gcc_assert (!TREE_ASM_WRITTEN (function));
121 /* Likewise, we can only be adding thunks to a function declared in
122 the class currently being laid out. */
123 gcc_assert (TYPE_SIZE (DECL_CONTEXT (function))
124 && TYPE_BEING_DEFINED (DECL_CONTEXT (function)));
126 thunk = build_decl (DECL_SOURCE_LOCATION (function),
127 FUNCTION_DECL, NULL_TREE, TREE_TYPE (function));
128 DECL_LANG_SPECIFIC (thunk) = DECL_LANG_SPECIFIC (function);
129 cxx_dup_lang_specific_decl (thunk);
130 DECL_THUNKS (thunk) = NULL_TREE;
132 DECL_CONTEXT (thunk) = DECL_CONTEXT (function);
133 TREE_READONLY (thunk) = TREE_READONLY (function);
134 TREE_THIS_VOLATILE (thunk) = TREE_THIS_VOLATILE (function);
135 TREE_PUBLIC (thunk) = TREE_PUBLIC (function);
136 SET_DECL_THUNK_P (thunk, this_adjusting);
137 THUNK_TARGET (thunk) = function;
138 THUNK_FIXED_OFFSET (thunk) = d;
139 THUNK_VIRTUAL_OFFSET (thunk) = virtual_offset;
140 THUNK_ALIAS (thunk) = NULL_TREE;
142 /* The thunk itself is not a constructor or destructor, even if
143 the thing it is thunking to is. */
144 DECL_INTERFACE_KNOWN (thunk) = 1;
145 DECL_NOT_REALLY_EXTERN (thunk) = 1;
146 DECL_SAVED_FUNCTION_DATA (thunk) = NULL;
147 DECL_DESTRUCTOR_P (thunk) = 0;
148 DECL_CONSTRUCTOR_P (thunk) = 0;
149 DECL_EXTERNAL (thunk) = 1;
150 DECL_ARTIFICIAL (thunk) = 1;
151 /* The THUNK is not a pending inline, even if the FUNCTION is. */
152 DECL_PENDING_INLINE_P (thunk) = 0;
153 DECL_DECLARED_INLINE_P (thunk) = 0;
154 /* Nor is it a template instantiation. */
155 DECL_USE_TEMPLATE (thunk) = 0;
156 DECL_TEMPLATE_INFO (thunk) = NULL;
158 /* Add it to the list of thunks associated with FUNCTION. */
159 TREE_CHAIN (thunk) = DECL_THUNKS (function);
160 DECL_THUNKS (function) = thunk;
165 /* Finish THUNK, a thunk decl. */
168 finish_thunk (tree thunk)
171 tree fixed_offset = ssize_int (THUNK_FIXED_OFFSET (thunk));
172 tree virtual_offset = THUNK_VIRTUAL_OFFSET (thunk);
174 gcc_assert (!DECL_NAME (thunk) && DECL_THUNK_P (thunk));
175 if (virtual_offset && DECL_RESULT_THUNK_P (thunk))
176 virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
177 function = THUNK_TARGET (thunk);
178 name = mangle_thunk (function, DECL_THIS_THUNK_P (thunk),
179 fixed_offset, virtual_offset);
181 /* We can end up with declarations of (logically) different
182 covariant thunks, that do identical adjustments. The two thunks
183 will be adjusting between within different hierarchies, which
184 happen to have the same layout. We must nullify one of them to
185 refer to the other. */
186 if (DECL_RESULT_THUNK_P (thunk))
190 for (cov_probe = DECL_THUNKS (function);
191 cov_probe; cov_probe = TREE_CHAIN (cov_probe))
192 if (DECL_NAME (cov_probe) == name)
194 gcc_assert (!DECL_THUNKS (thunk));
195 THUNK_ALIAS (thunk) = (THUNK_ALIAS (cov_probe)
196 ? THUNK_ALIAS (cov_probe) : cov_probe);
201 DECL_NAME (thunk) = name;
202 SET_DECL_ASSEMBLER_NAME (thunk, name);
205 static GTY (()) int thunk_labelno;
207 /* Create a static alias to target. */
210 make_alias_for (tree target, tree newid)
212 tree alias = build_decl (DECL_SOURCE_LOCATION (target),
213 TREE_CODE (target), newid, TREE_TYPE (target));
214 DECL_LANG_SPECIFIC (alias) = DECL_LANG_SPECIFIC (target);
215 cxx_dup_lang_specific_decl (alias);
216 DECL_CONTEXT (alias) = NULL;
217 TREE_READONLY (alias) = TREE_READONLY (target);
218 TREE_THIS_VOLATILE (alias) = TREE_THIS_VOLATILE (target);
219 TREE_PUBLIC (alias) = 0;
220 DECL_INTERFACE_KNOWN (alias) = 1;
221 if (DECL_LANG_SPECIFIC (alias))
223 DECL_NOT_REALLY_EXTERN (alias) = 1;
224 DECL_USE_TEMPLATE (alias) = 0;
225 DECL_TEMPLATE_INFO (alias) = NULL;
227 DECL_EXTERNAL (alias) = 0;
228 DECL_ARTIFICIAL (alias) = 1;
229 DECL_TEMPLATE_INSTANTIATED (alias) = 0;
230 if (TREE_CODE (alias) == FUNCTION_DECL)
232 DECL_SAVED_FUNCTION_DATA (alias) = NULL;
233 DECL_DESTRUCTOR_P (alias) = 0;
234 DECL_CONSTRUCTOR_P (alias) = 0;
235 DECL_PENDING_INLINE_P (alias) = 0;
236 DECL_DECLARED_INLINE_P (alias) = 0;
237 DECL_INITIAL (alias) = error_mark_node;
238 DECL_ARGUMENTS (alias) = copy_list (DECL_ARGUMENTS (target));
241 TREE_STATIC (alias) = 1;
242 TREE_ADDRESSABLE (alias) = 1;
243 TREE_USED (alias) = 1;
244 SET_DECL_ASSEMBLER_NAME (alias, DECL_NAME (alias));
245 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias)) = 1;
250 make_alias_for_thunk (tree function)
255 ASM_GENERATE_INTERNAL_LABEL (buf, "LTHUNK", thunk_labelno);
258 alias = make_alias_for (function, get_identifier (buf));
260 if (!flag_syntax_only)
262 bool ok = cgraph_same_body_alias (alias, function);
263 DECL_ASSEMBLER_NAME (function);
270 /* Emit the definition of a C++ multiple inheritance or covariant
271 return vtable thunk. If EMIT_P is nonzero, the thunk is emitted
275 use_thunk (tree thunk_fndecl, bool emit_p)
277 tree a, t, function, alias;
279 HOST_WIDE_INT fixed_offset, virtual_value;
280 bool this_adjusting = DECL_THIS_THUNK_P (thunk_fndecl);
282 /* We should have called finish_thunk to give it a name. */
283 gcc_assert (DECL_NAME (thunk_fndecl));
285 /* We should never be using an alias, always refer to the
287 gcc_assert (!THUNK_ALIAS (thunk_fndecl));
289 if (TREE_ASM_WRITTEN (thunk_fndecl))
292 function = THUNK_TARGET (thunk_fndecl);
293 if (DECL_RESULT (thunk_fndecl))
294 /* We already turned this thunk into an ordinary function.
295 There's no need to process this thunk again. */
298 if (DECL_THUNK_P (function))
299 /* The target is itself a thunk, process it now. */
300 use_thunk (function, emit_p);
302 /* Thunks are always addressable; they only appear in vtables. */
303 TREE_ADDRESSABLE (thunk_fndecl) = 1;
305 /* Figure out what function is being thunked to. It's referenced in
306 this translation unit. */
307 TREE_ADDRESSABLE (function) = 1;
308 mark_used (function);
312 if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function))
313 alias = make_alias_for_thunk (function);
317 fixed_offset = THUNK_FIXED_OFFSET (thunk_fndecl);
318 virtual_offset = THUNK_VIRTUAL_OFFSET (thunk_fndecl);
323 virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
324 virtual_value = tree_low_cst (virtual_offset, /*pos=*/0);
325 gcc_assert (virtual_value);
330 /* And, if we need to emit the thunk, it's used. */
331 mark_used (thunk_fndecl);
332 /* This thunk is actually defined. */
333 DECL_EXTERNAL (thunk_fndecl) = 0;
334 /* The linkage of the function may have changed. FIXME in linkage
336 TREE_PUBLIC (thunk_fndecl) = TREE_PUBLIC (function);
337 DECL_VISIBILITY (thunk_fndecl) = DECL_VISIBILITY (function);
338 DECL_VISIBILITY_SPECIFIED (thunk_fndecl)
339 = DECL_VISIBILITY_SPECIFIED (function);
340 if (DECL_ONE_ONLY (function) || DECL_WEAK (function))
341 make_decl_one_only (thunk_fndecl, cxx_comdat_group (thunk_fndecl));
343 if (flag_syntax_only)
345 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
349 push_to_top_level ();
351 if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function)
352 && targetm.have_named_sections)
354 resolve_unique_section (function, 0, flag_function_sections);
356 if (DECL_SECTION_NAME (function) != NULL && DECL_ONE_ONLY (function))
358 resolve_unique_section (thunk_fndecl, 0, flag_function_sections);
360 /* Output the thunk into the same section as function. */
361 DECL_SECTION_NAME (thunk_fndecl) = DECL_SECTION_NAME (function);
365 /* Set up cloned argument trees for the thunk. */
367 for (a = DECL_ARGUMENTS (function); a; a = TREE_CHAIN (a))
369 tree x = copy_node (a);
371 DECL_CONTEXT (x) = thunk_fndecl;
372 SET_DECL_RTL (x, NULL);
373 DECL_HAS_VALUE_EXPR_P (x) = 0;
377 DECL_ARGUMENTS (thunk_fndecl) = a;
378 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
379 cgraph_add_thunk (thunk_fndecl, function,
380 this_adjusting, fixed_offset, virtual_value,
381 virtual_offset, alias);
384 || !targetm.asm_out.can_output_mi_thunk (thunk_fndecl, fixed_offset,
385 virtual_value, alias))
387 /* If this is a covariant thunk, or we don't have the necessary
388 code for efficient thunks, generate a thunk function that
389 just makes a call to the real function. Unfortunately, this
390 doesn't work for varargs. */
392 if (varargs_function_p (function))
393 error ("generic thunk code fails for method %q#D which uses %<...%>",
397 pop_from_top_level ();
400 /* Code for synthesizing methods which have default semantics defined. */
402 /* True iff CTYPE has a trivial SFK. */
405 type_has_trivial_fn (tree ctype, special_function_kind sfk)
409 case sfk_constructor:
410 return !TYPE_HAS_COMPLEX_DFLT (ctype);
411 case sfk_copy_constructor:
412 return !TYPE_HAS_COMPLEX_COPY_CTOR (ctype);
413 case sfk_move_constructor:
414 return !TYPE_HAS_COMPLEX_MOVE_CTOR (ctype);
415 case sfk_copy_assignment:
416 return !TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype);
417 case sfk_move_assignment:
418 return !TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype);
420 return !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype);
426 /* Note that CTYPE has a non-trivial SFK even though we previously thought
430 type_set_nontrivial_flag (tree ctype, special_function_kind sfk)
434 case sfk_constructor:
435 TYPE_HAS_COMPLEX_DFLT (ctype) = true;
437 case sfk_copy_constructor:
438 TYPE_HAS_COMPLEX_COPY_CTOR (ctype) = true;
440 case sfk_move_constructor:
441 TYPE_HAS_COMPLEX_MOVE_CTOR (ctype) = true;
443 case sfk_copy_assignment:
444 TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype) = true;
446 case sfk_move_assignment:
447 TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype) = true;
450 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype) = true;
457 /* True iff FN is a trivial defaulted member function ([cd]tor, op=). */
460 trivial_fn_p (tree fn)
462 if (!DECL_DEFAULTED_FN (fn))
465 /* If fn is a clone, get the primary variant. */
466 fn = DECL_ORIGIN (fn);
467 return type_has_trivial_fn (DECL_CONTEXT (fn), special_function_p (fn));
470 /* Generate code for default X(X&) or X(X&&) constructor. */
473 do_build_copy_constructor (tree fndecl)
475 tree parm = FUNCTION_FIRST_USER_PARM (fndecl);
476 bool move_p = DECL_MOVE_CONSTRUCTOR_P (fndecl);
477 bool trivial = trivial_fn_p (fndecl);
479 parm = convert_from_reference (parm);
482 && is_empty_class (current_class_type))
483 /* Don't copy the padding byte; it might not have been allocated
484 if *this is a base subobject. */;
487 tree t = build2 (INIT_EXPR, void_type_node, current_class_ref, parm);
488 finish_expr_stmt (t);
492 tree fields = TYPE_FIELDS (current_class_type);
493 tree member_init_list = NULL_TREE;
494 int cvquals = cp_type_quals (TREE_TYPE (parm));
496 tree binfo, base_binfo;
498 VEC(tree,gc) *vbases;
500 /* Initialize all the base-classes with the parameter converted
501 to their type so that we get their copy constructor and not
502 another constructor that takes current_class_type. We must
503 deal with the binfo's directly as a direct base might be
504 inaccessible due to ambiguity. */
505 for (vbases = CLASSTYPE_VBASECLASSES (current_class_type), i = 0;
506 VEC_iterate (tree, vbases, i, binfo); i++)
508 init = build_base_path (PLUS_EXPR, parm, binfo, 1);
513 build_tree_list (NULL_TREE, init),
517 for (binfo = TYPE_BINFO (current_class_type), i = 0;
518 BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
520 if (BINFO_VIRTUAL_P (base_binfo))
523 init = build_base_path (PLUS_EXPR, parm, base_binfo, 1);
527 = tree_cons (base_binfo,
528 build_tree_list (NULL_TREE, init),
532 for (; fields; fields = TREE_CHAIN (fields))
537 if (TREE_CODE (field) != FIELD_DECL)
540 expr_type = TREE_TYPE (field);
541 if (DECL_NAME (field))
543 if (VFIELD_NAME_P (DECL_NAME (field)))
546 else if (ANON_AGGR_TYPE_P (expr_type) && TYPE_FIELDS (expr_type))
547 /* Just use the field; anonymous types can't have
548 nontrivial copy ctors or assignment ops. */;
552 /* Compute the type of "init->field". If the copy-constructor
553 parameter is, for example, "const S&", and the type of
554 the field is "T", then the type will usually be "const
555 T". (There are no cv-qualified variants of reference
557 if (TREE_CODE (expr_type) != REFERENCE_TYPE)
561 if (DECL_MUTABLE_P (field))
562 quals &= ~TYPE_QUAL_CONST;
563 quals |= cp_type_quals (expr_type);
564 expr_type = cp_build_qualified_type (expr_type, quals);
567 init = build3 (COMPONENT_REF, expr_type, parm, field, NULL_TREE);
568 if (move_p && TREE_CODE (expr_type) != REFERENCE_TYPE)
570 init = build_tree_list (NULL_TREE, init);
572 member_init_list = tree_cons (field, init, member_init_list);
574 finish_mem_initializers (member_init_list);
579 do_build_copy_assign (tree fndecl)
581 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
583 bool move_p = move_fn_p (fndecl);
584 bool trivial = trivial_fn_p (fndecl);
586 compound_stmt = begin_compound_stmt (0);
587 parm = convert_from_reference (parm);
590 && is_empty_class (current_class_type))
591 /* Don't copy the padding byte; it might not have been allocated
592 if *this is a base subobject. */;
595 tree t = build2 (MODIFY_EXPR, void_type_node, current_class_ref, parm);
596 finish_expr_stmt (t);
601 int cvquals = cp_type_quals (TREE_TYPE (parm));
603 tree binfo, base_binfo;
605 /* Assign to each of the direct base classes. */
606 for (binfo = TYPE_BINFO (current_class_type), i = 0;
607 BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
610 VEC(tree,gc) *parmvec;
612 /* We must convert PARM directly to the base class
613 explicitly since the base class may be ambiguous. */
614 converted_parm = build_base_path (PLUS_EXPR, parm, base_binfo, 1);
616 converted_parm = move (converted_parm);
617 /* Call the base class assignment operator. */
618 parmvec = make_tree_vector_single (converted_parm);
620 (build_special_member_call (current_class_ref,
621 ansi_assopname (NOP_EXPR),
624 LOOKUP_NORMAL | LOOKUP_NONVIRTUAL,
625 tf_warning_or_error));
626 release_tree_vector (parmvec);
629 /* Assign to each of the non-static data members. */
630 for (fields = TYPE_FIELDS (current_class_type);
632 fields = TREE_CHAIN (fields))
634 tree comp = current_class_ref;
640 if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field))
643 expr_type = TREE_TYPE (field);
645 if (CP_TYPE_CONST_P (expr_type))
647 error ("non-static const member %q#D, can't use default "
648 "assignment operator", field);
651 else if (TREE_CODE (expr_type) == REFERENCE_TYPE)
653 error ("non-static reference member %q#D, can't use "
654 "default assignment operator", field);
658 if (DECL_NAME (field))
660 if (VFIELD_NAME_P (DECL_NAME (field)))
663 else if (ANON_AGGR_TYPE_P (expr_type)
664 && TYPE_FIELDS (expr_type) != NULL_TREE)
665 /* Just use the field; anonymous types can't have
666 nontrivial copy ctors or assignment ops. */;
670 comp = build3 (COMPONENT_REF, expr_type, comp, field, NULL_TREE);
672 /* Compute the type of init->field */
674 if (DECL_MUTABLE_P (field))
675 quals &= ~TYPE_QUAL_CONST;
676 expr_type = cp_build_qualified_type (expr_type, quals);
678 init = build3 (COMPONENT_REF, expr_type, init, field, NULL_TREE);
679 if (move_p && TREE_CODE (expr_type) != REFERENCE_TYPE)
682 if (DECL_NAME (field))
683 init = cp_build_modify_expr (comp, NOP_EXPR, init,
684 tf_warning_or_error);
686 init = build2 (MODIFY_EXPR, TREE_TYPE (comp), comp, init);
687 finish_expr_stmt (init);
690 finish_return_stmt (current_class_ref);
691 finish_compound_stmt (compound_stmt);
694 /* Synthesize FNDECL, a non-static member function. */
697 synthesize_method (tree fndecl)
699 bool nested = (current_function_decl != NULL_TREE);
700 tree context = decl_function_context (fndecl);
701 bool need_body = true;
703 location_t save_input_location = input_location;
704 int error_count = errorcount;
705 int warning_count = warningcount;
707 /* Reset the source location, we might have been previously
708 deferred, and thus have saved where we were first needed. */
709 DECL_SOURCE_LOCATION (fndecl)
710 = DECL_SOURCE_LOCATION (TYPE_NAME (DECL_CONTEXT (fndecl)));
712 /* If we've been asked to synthesize a clone, just synthesize the
713 cloned function instead. Doing so will automatically fill in the
714 body for the clone. */
715 if (DECL_CLONED_FUNCTION_P (fndecl))
716 fndecl = DECL_CLONED_FUNCTION (fndecl);
718 /* We may be in the middle of deferred access check. Disable
720 push_deferring_access_checks (dk_no_deferred);
723 push_to_top_level ();
725 push_function_context ();
727 input_location = DECL_SOURCE_LOCATION (fndecl);
729 start_preparsed_function (fndecl, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED);
730 stmt = begin_function_body ();
732 if (DECL_OVERLOADED_OPERATOR_P (fndecl) == NOP_EXPR)
734 do_build_copy_assign (fndecl);
737 else if (DECL_CONSTRUCTOR_P (fndecl))
739 tree arg_chain = FUNCTION_FIRST_USER_PARMTYPE (fndecl);
740 if (arg_chain != void_list_node)
741 do_build_copy_constructor (fndecl);
743 finish_mem_initializers (NULL_TREE);
746 /* If we haven't yet generated the body of the function, just
747 generate an empty compound statement. */
751 compound_stmt = begin_compound_stmt (BCS_FN_BODY);
752 finish_compound_stmt (compound_stmt);
755 finish_function_body (stmt);
756 expand_or_defer_fn (finish_function (0));
758 input_location = save_input_location;
761 pop_from_top_level ();
763 pop_function_context ();
765 pop_deferring_access_checks ();
767 if (error_count != errorcount || warning_count != warningcount)
768 inform (input_location, "synthesized method %qD first required here ",
772 /* Build a reference to type TYPE with cv-quals QUALS, which is an
773 rvalue if RVALUE is true. */
776 build_stub_type (tree type, int quals, bool rvalue)
778 tree argtype = cp_build_qualified_type (type, quals);
779 return cp_build_reference_type (argtype, rvalue);
782 /* Build a dummy glvalue from dereferencing a dummy reference of type
786 build_stub_object (tree reftype)
788 tree stub = build1 (NOP_EXPR, reftype, integer_one_node);
789 return convert_from_reference (stub);
792 /* Determine which function will be called when looking up NAME in TYPE,
793 called with a single ARGTYPE argument, or no argument if ARGTYPE is
794 null. FLAGS and COMPLAIN are as for build_new_method_call.
796 Returns a FUNCTION_DECL if all is well.
797 Returns NULL_TREE if overload resolution failed.
798 Returns error_mark_node if the chosen function cannot be called. */
801 locate_fn_flags (tree type, tree name, tree argtype, int flags,
802 tsubst_flags_t complain)
804 tree ob, fn, fns, binfo, rval;
808 binfo = TYPE_BINFO (type);
812 type = BINFO_TYPE (binfo);
815 ob = build_stub_object (cp_build_reference_type (type, false));
816 args = make_tree_vector ();
819 tree arg = build_stub_object (argtype);
820 VEC_quick_push (tree, args, arg);
823 fns = lookup_fnfields (binfo, name, 0);
824 rval = build_new_method_call (ob, fns, &args, binfo, flags, &fn, complain);
826 release_tree_vector (args);
827 if (fn && rval == error_mark_node)
833 /* Locate the dtor of TYPE. */
838 tree fn = locate_fn_flags (type, complete_dtor_identifier, NULL_TREE,
839 LOOKUP_NORMAL, tf_warning_or_error);
840 if (fn == error_mark_node)
845 /* Locate the default ctor of TYPE. */
848 locate_ctor (tree type)
850 tree fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
851 LOOKUP_SPECULATIVE, tf_none);
852 if (fn == error_mark_node)
857 /* Likewise, but give any appropriate errors. */
860 get_default_ctor (tree type)
862 tree fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
863 LOOKUP_NORMAL, tf_warning_or_error);
864 if (fn == error_mark_node)
869 /* Locate the copy ctor of TYPE. */
872 get_copy_ctor (tree type)
874 int quals = (TYPE_HAS_CONST_COPY_CTOR (type)
875 ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
876 tree argtype = build_stub_type (type, quals, false);
877 tree fn = locate_fn_flags (type, complete_ctor_identifier, argtype,
878 LOOKUP_NORMAL, tf_warning_or_error);
879 if (fn == error_mark_node)
884 /* Locate the copy assignment operator of TYPE. */
887 get_copy_assign (tree type)
889 int quals = (TYPE_HAS_CONST_COPY_ASSIGN (type)
890 ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
891 tree argtype = build_stub_type (type, quals, false);
892 tree fn = locate_fn_flags (type, ansi_assopname (NOP_EXPR), argtype,
893 LOOKUP_NORMAL, tf_warning_or_error);
894 if (fn == error_mark_node)
899 /* Subroutine of synthesized_method_walk. Update SPEC_P, TRIVIAL_P and
900 DELETED_P or give an error message MSG with argument ARG. */
903 process_subob_fn (tree fn, bool move_p, tree *spec_p, bool *trivial_p,
904 bool *deleted_p, const char *msg, tree arg)
906 if (!fn || fn == error_mark_node)
911 tree raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn));
912 *spec_p = merge_exception_specifiers (*spec_p, raises);
915 if (trivial_p && !trivial_fn_p (fn))
918 if (move_p && !move_fn_p (fn) && !trivial_fn_p (fn))
932 /* The caller wants to generate an implicit declaration of SFK for CTYPE
933 which is const if relevant and CONST_P is set. If spec_p, trivial_p and
934 deleted_p are non-null, set their referent appropriately. If diag is
935 true, we're being called from maybe_explain_implicit_delete to give
939 synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p,
940 tree *spec_p, bool *trivial_p, bool *deleted_p,
943 tree binfo, base_binfo, field, scope, fnname, rval, argtype;
944 bool move_p, copy_arg_p, assign_p, expected_trivial, check_vdtor;
945 VEC(tree,gc) *vbases;
947 tsubst_flags_t complain;
951 *spec_p = (cxx_dialect >= cxx0x
952 ? noexcept_true_spec : empty_except_spec);
956 /* "The closure type associated with a lambda-expression has a deleted
957 default constructor and a deleted copy assignment operator."
958 This is diagnosed in maybe_explain_implicit_delete. */
959 if (LAMBDA_TYPE_P (ctype)
960 && (sfk == sfk_constructor
961 || sfk == sfk_copy_assignment))
973 case sfk_constructor:
978 case sfk_move_constructor:
979 case sfk_move_assignment:
981 case sfk_copy_constructor:
982 case sfk_copy_assignment:
990 expected_trivial = type_has_trivial_fn (ctype, sfk);
992 *trivial_p = expected_trivial;
994 #ifndef ENABLE_CHECKING
995 /* The TYPE_HAS_COMPLEX_* flags tell us about constraints from base
996 class versions and other properties of the type. But a subobject
997 class can be trivially copyable and yet have overload resolution
998 choose a template constructor for initialization, depending on
999 rvalueness and cv-quals. So we can't exit early for copy/move
1000 methods in C++0x. */
1001 if (expected_trivial
1002 && (!copy_arg_p || cxx_dialect < cxx0x))
1007 check_vdtor = false;
1010 case sfk_move_assignment:
1011 case sfk_copy_assignment:
1013 fnname = ansi_assopname (NOP_EXPR);
1016 case sfk_destructor:
1018 /* The synthesized method will call base dtors, but check complete
1019 here to avoid having to deal with VTT. */
1020 fnname = complete_dtor_identifier;
1023 case sfk_constructor:
1024 case sfk_move_constructor:
1025 case sfk_copy_constructor:
1026 fnname = complete_ctor_identifier;
1033 ++cp_unevaluated_operand;
1034 ++c_inhibit_evaluation_warnings;
1036 scope = push_scope (ctype);
1040 flags = LOOKUP_NORMAL|LOOKUP_SPECULATIVE;
1041 complain = tf_warning_or_error;
1045 flags = LOOKUP_PROTECT|LOOKUP_SPECULATIVE;
1050 quals = TYPE_QUAL_CONST;
1052 quals = TYPE_UNQUALIFIED;
1053 argtype = NULL_TREE;
1055 for (binfo = TYPE_BINFO (ctype), i = 0;
1056 BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
1058 tree basetype = BINFO_TYPE (base_binfo);
1060 argtype = build_stub_type (basetype, quals, move_p);
1061 rval = locate_fn_flags (base_binfo, fnname, argtype, flags, complain);
1066 msg = ("base %qT does not have a move assignment operator or trivial "
1067 "copy assignment operator");
1069 msg = ("base %qT does not have a move constructor or trivial "
1070 "copy constructor");
1072 process_subob_fn (rval, move_p, spec_p, trivial_p, deleted_p,
1073 msg, BINFO_TYPE (base_binfo));
1075 if (check_vdtor && type_has_virtual_destructor (basetype))
1077 rval = locate_fn_flags (ctype, ansi_opname (DELETE_EXPR),
1078 ptr_type_node, flags, complain);
1079 /* Unlike for base ctor/op=/dtor, for operator delete it's fine
1080 to have a null rval (no class-specific op delete). */
1081 if (rval && rval == error_mark_node && deleted_p)
1086 vbases = CLASSTYPE_VBASECLASSES (ctype);
1087 if (vbases && assign_p && move_p)
1089 /* Should the spec be changed to allow vbases that only occur once? */
1091 error ("%qT has virtual bases, default move assignment operator "
1092 "cannot be generated", ctype);
1097 for (i = 0; VEC_iterate (tree, vbases, i, base_binfo); ++i)
1100 argtype = build_stub_type (BINFO_TYPE (base_binfo), quals, move_p);
1101 rval = locate_fn_flags (base_binfo, fnname, argtype, flags, complain);
1106 msg = ("virtual base %qT does not have a move assignment "
1107 "operator or trivial copy assignment operator");
1109 msg = ("virtual base %qT does not have a move constructor "
1110 "or trivial copy constructor");
1112 process_subob_fn (rval, move_p, spec_p, trivial_p, deleted_p,
1113 msg, BINFO_TYPE (base_binfo));
1116 for (field = TYPE_FIELDS (ctype); field; field = TREE_CHAIN (field))
1120 if (TREE_CODE (field) != FIELD_DECL
1121 || DECL_ARTIFICIAL (field))
1124 mem_type = strip_array_types (TREE_TYPE (field));
1128 if (CP_TYPE_CONST_P (mem_type) && !CLASS_TYPE_P (mem_type))
1131 error ("non-static const member %q#D, can't use default "
1132 "assignment operator", field);
1134 else if (TREE_CODE (mem_type) == REFERENCE_TYPE)
1137 error ("non-static reference member %q#D, can't use "
1138 "default assignment operator", field);
1143 if (bad && deleted_p)
1146 else if (sfk == sfk_constructor)
1149 if (CP_TYPE_CONST_P (mem_type)
1150 && (!CLASS_TYPE_P (mem_type)
1151 || !type_has_user_provided_default_constructor (mem_type)))
1154 error ("uninitialized non-static const member %q#D",
1157 else if (TREE_CODE (mem_type) == REFERENCE_TYPE)
1160 error ("uninitialized non-static reference member %q#D",
1166 if (bad && deleted_p)
1170 if (!CLASS_TYPE_P (mem_type)
1171 || ANON_AGGR_TYPE_P (mem_type))
1176 int mem_quals = cp_type_quals (mem_type) | quals;
1177 if (DECL_MUTABLE_P (field))
1178 mem_quals &= ~TYPE_QUAL_CONST;
1179 argtype = build_stub_type (mem_type, mem_quals, move_p);
1182 rval = locate_fn_flags (mem_type, fnname, argtype, flags, complain);
1187 msg = ("non-static data member %qD does not have a move "
1188 "assignment operator or trivial copy assignment operator");
1190 msg = ("non-static data member %qD does not have a move "
1191 "constructor or trivial copy constructor");
1193 process_subob_fn (rval, move_p, spec_p, trivial_p, deleted_p,
1199 --cp_unevaluated_operand;
1200 --c_inhibit_evaluation_warnings;
1202 #ifdef ENABLE_CHECKING
1203 /* If we expected this to be trivial but it isn't, then either we're in
1204 C++0x mode and this is a copy/move ctor/op= or there's an error. */
1205 gcc_assert (!(trivial_p && expected_trivial && !*trivial_p)
1206 || (copy_arg_p && cxx_dialect >= cxx0x)
1211 /* DECL is a deleted function. If it's implicitly deleted, explain why and
1212 return true; else return false. */
1215 maybe_explain_implicit_delete (tree decl)
1217 /* If decl is a clone, get the primary variant. */
1218 decl = DECL_ORIGIN (decl);
1219 gcc_assert (DECL_DELETED_FN (decl));
1220 if (DECL_DEFAULTED_FN (decl)
1221 && DECL_INITIAL (decl) == NULL_TREE)
1223 /* Not marked GTY; it doesn't need to be GC'd or written to PCH. */
1224 static htab_t explained_htab;
1227 special_function_kind sfk;
1232 if (!explained_htab)
1233 explained_htab = htab_create (37, htab_hash_pointer,
1234 htab_eq_pointer, NULL);
1235 slot = htab_find_slot (explained_htab, decl, INSERT);
1240 sfk = special_function_p (decl);
1241 ctype = DECL_CONTEXT (decl);
1242 loc = input_location;
1243 input_location = DECL_SOURCE_LOCATION (decl);
1246 if (LAMBDA_TYPE_P (ctype))
1249 if (sfk == sfk_constructor)
1250 error ("a lambda closure type has a deleted default constructor");
1251 else if (sfk == sfk_copy_assignment)
1252 error ("a lambda closure type has a deleted copy assignment operator");
1258 tree parm_type = TREE_VALUE (FUNCTION_FIRST_USER_PARMTYPE (decl));
1259 bool const_p = CP_TYPE_CONST_P (non_reference (parm_type));
1260 tree scope = push_scope (ctype);
1261 error ("%qD is implicitly deleted because the default "
1262 "definition would be ill-formed:", decl);
1264 synthesized_method_walk (ctype, sfk, const_p,
1265 NULL, NULL, NULL, true);
1268 input_location = loc;
1274 /* Implicitly declare the special function indicated by KIND, as a
1275 member of TYPE. For copy constructors and assignment operators,
1276 CONST_P indicates whether these functions should take a const
1277 reference argument or a non-const reference. Returns the
1278 FUNCTION_DECL for the implicitly declared function. */
1281 implicitly_declare_fn (special_function_kind kind, tree type, bool const_p)
1284 tree parameter_types = void_list_node;
1287 tree raises = empty_except_spec;
1288 tree rhs_parm_type = NULL_TREE;
1291 HOST_WIDE_INT saved_processing_template_decl;
1295 /* Because we create declarations for implicitly declared functions
1296 lazily, we may be creating the declaration for a member of TYPE
1297 while in some completely different context. However, TYPE will
1298 never be a dependent class (because we never want to do lookups
1299 for implicitly defined functions in a dependent class).
1300 Furthermore, we must set PROCESSING_TEMPLATE_DECL to zero here
1301 because we only create clones for constructors and destructors
1302 when not in a template. */
1303 gcc_assert (!dependent_type_p (type));
1304 saved_processing_template_decl = processing_template_decl;
1305 processing_template_decl = 0;
1307 type = TYPE_MAIN_VARIANT (type);
1309 if (targetm.cxx.cdtor_returns_this () && !TYPE_FOR_JAVA (type))
1311 if (kind == sfk_destructor)
1312 /* See comment in check_special_function_return_type. */
1313 return_type = build_pointer_type (void_type_node);
1315 return_type = build_pointer_type (type);
1318 return_type = void_type_node;
1322 case sfk_destructor:
1324 name = constructor_name (type);
1327 case sfk_constructor:
1328 /* Default constructor. */
1329 name = constructor_name (type);
1332 case sfk_copy_constructor:
1333 case sfk_copy_assignment:
1334 case sfk_move_constructor:
1335 case sfk_move_assignment:
1338 if (kind == sfk_copy_assignment
1339 || kind == sfk_move_assignment)
1341 return_type = build_reference_type (type);
1342 name = ansi_assopname (NOP_EXPR);
1345 name = constructor_name (type);
1348 rhs_parm_type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
1350 rhs_parm_type = type;
1351 move_p = (kind == sfk_move_assignment
1352 || kind == sfk_move_constructor);
1353 rhs_parm_type = cp_build_reference_type (rhs_parm_type, move_p);
1355 parameter_types = tree_cons (NULL_TREE, rhs_parm_type, parameter_types);
1362 synthesized_method_walk (type, kind, const_p, &raises, &trivial_p,
1365 if (!trivial_p && type_has_trivial_fn (type, kind))
1366 type_set_nontrivial_flag (type, kind);
1368 /* Create the function. */
1369 fn_type = build_method_type_directly (type, return_type, parameter_types);
1371 fn_type = build_exception_variant (fn_type, raises);
1372 fn = build_lang_decl (FUNCTION_DECL, name, fn_type);
1373 DECL_SOURCE_LOCATION (fn) = DECL_SOURCE_LOCATION (TYPE_NAME (type));
1374 if (kind == sfk_constructor || kind == sfk_copy_constructor
1375 || kind == sfk_move_constructor)
1376 DECL_CONSTRUCTOR_P (fn) = 1;
1377 else if (kind == sfk_destructor)
1378 DECL_DESTRUCTOR_P (fn) = 1;
1381 DECL_ASSIGNMENT_OPERATOR_P (fn) = 1;
1382 SET_OVERLOADED_OPERATOR_CODE (fn, NOP_EXPR);
1385 /* If pointers to member functions use the least significant bit to
1386 indicate whether a function is virtual, ensure a pointer
1387 to this function will have that bit clear. */
1388 if (TARGET_PTRMEMFUNC_VBIT_LOCATION == ptrmemfunc_vbit_in_pfn
1389 && DECL_ALIGN (fn) < 2 * BITS_PER_UNIT)
1390 DECL_ALIGN (fn) = 2 * BITS_PER_UNIT;
1392 /* Create the explicit arguments. */
1395 /* Note that this parameter is *not* marked DECL_ARTIFICIAL; we
1396 want its type to be included in the mangled function
1398 DECL_ARGUMENTS (fn) = cp_build_parm_decl (NULL_TREE, rhs_parm_type);
1399 TREE_READONLY (DECL_ARGUMENTS (fn)) = 1;
1401 /* Add the "this" parameter. */
1402 this_parm = build_this_parm (fn_type, TYPE_UNQUALIFIED);
1403 TREE_CHAIN (this_parm) = DECL_ARGUMENTS (fn);
1404 DECL_ARGUMENTS (fn) = this_parm;
1406 grokclassfn (type, fn, kind == sfk_destructor ? DTOR_FLAG : NO_SPECIAL);
1407 set_linkage_according_to_type (type, fn);
1408 rest_of_decl_compilation (fn, toplevel_bindings_p (), at_eof);
1409 DECL_IN_AGGR_P (fn) = 1;
1410 DECL_ARTIFICIAL (fn) = 1;
1411 DECL_DEFAULTED_FN (fn) = 1;
1412 if (cxx_dialect >= cxx0x)
1413 DECL_DELETED_FN (fn) = deleted_p;
1414 DECL_NOT_REALLY_EXTERN (fn) = 1;
1415 DECL_DECLARED_INLINE_P (fn) = 1;
1416 gcc_assert (!TREE_USED (fn));
1418 /* Restore PROCESSING_TEMPLATE_DECL. */
1419 processing_template_decl = saved_processing_template_decl;
1424 /* Gives any errors about defaulted functions which need to be deferred
1425 until the containing class is complete. */
1428 defaulted_late_check (tree fn)
1430 /* Complain about invalid signature for defaulted fn. */
1431 tree ctx = DECL_CONTEXT (fn);
1432 special_function_kind kind = special_function_p (fn);
1433 bool fn_const_p = (copy_fn_p (fn) == 2);
1434 tree implicit_fn = implicitly_declare_fn (kind, ctx, fn_const_p);
1436 if (!same_type_p (TREE_TYPE (TREE_TYPE (fn)),
1437 TREE_TYPE (TREE_TYPE (implicit_fn)))
1438 || !compparms (TYPE_ARG_TYPES (TREE_TYPE (fn)),
1439 TYPE_ARG_TYPES (TREE_TYPE (implicit_fn))))
1441 error ("defaulted declaration %q+D", fn);
1442 error_at (DECL_SOURCE_LOCATION (fn),
1443 "does not match expected signature %qD", implicit_fn);
1446 /* 8.4.2/2: If it is explicitly defaulted on its first declaration, it is
1447 implicitly considered to have the same exception-specification as if
1448 it had been implicitly declared. */
1449 if (DECL_DEFAULTED_IN_CLASS_P (fn))
1451 tree eh_spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (implicit_fn));
1452 TREE_TYPE (fn) = build_exception_variant (TREE_TYPE (fn), eh_spec);
1455 if (DECL_DELETED_FN (implicit_fn))
1456 DECL_DELETED_FN (fn) = 1;
1459 /* Returns true iff FN can be explicitly defaulted, and gives any
1460 errors if defaulting FN is ill-formed. */
1463 defaultable_fn_check (tree fn)
1465 special_function_kind kind = sfk_none;
1467 if (DECL_CONSTRUCTOR_P (fn))
1469 if (FUNCTION_FIRST_USER_PARMTYPE (fn) == void_list_node)
1470 kind = sfk_constructor;
1471 else if (copy_fn_p (fn) > 0
1472 && (TREE_CHAIN (FUNCTION_FIRST_USER_PARMTYPE (fn))
1474 kind = sfk_copy_constructor;
1475 else if (move_fn_p (fn))
1476 kind = sfk_move_constructor;
1478 else if (DECL_DESTRUCTOR_P (fn))
1479 kind = sfk_destructor;
1480 else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
1481 && DECL_OVERLOADED_OPERATOR_P (fn) == NOP_EXPR)
1484 kind = sfk_copy_assignment;
1485 else if (move_fn_p (fn))
1486 kind = sfk_move_assignment;
1489 if (kind == sfk_none)
1491 error ("%qD cannot be defaulted", fn);
1496 tree t = FUNCTION_FIRST_USER_PARMTYPE (fn);
1497 for (; t && t != void_list_node; t = TREE_CHAIN (t))
1498 if (TREE_PURPOSE (t))
1500 error ("defaulted function %q+D with default argument", fn);
1503 if (TYPE_BEING_DEFINED (DECL_CONTEXT (fn)))
1505 if (DECL_NONCONVERTING_P (fn))
1506 error ("%qD declared explicit cannot be defaulted in the class "
1508 if (current_access_specifier != access_public_node)
1509 error ("%qD declared with non-public access cannot be defaulted "
1510 "in the class body", fn);
1511 if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)))
1512 error ("function %q+D defaulted on its first declaration "
1513 "must not have an exception-specification", fn);
1514 if (DECL_VIRTUAL_P (fn))
1515 error ("%qD declared virtual cannot be defaulted in the class "
1518 else if (!processing_template_decl)
1519 defaulted_late_check (fn);
1525 /* Add an implicit declaration to TYPE for the kind of function
1526 indicated by SFK. Return the FUNCTION_DECL for the new implicit
1530 lazily_declare_fn (special_function_kind sfk, tree type)
1533 /* Whether or not the argument has a const reference type. */
1534 bool const_p = false;
1538 case sfk_constructor:
1539 CLASSTYPE_LAZY_DEFAULT_CTOR (type) = 0;
1541 case sfk_copy_constructor:
1542 const_p = TYPE_HAS_CONST_COPY_CTOR (type);
1543 CLASSTYPE_LAZY_COPY_CTOR (type) = 0;
1545 case sfk_move_constructor:
1546 CLASSTYPE_LAZY_MOVE_CTOR (type) = 0;
1548 case sfk_copy_assignment:
1549 const_p = TYPE_HAS_CONST_COPY_ASSIGN (type);
1550 CLASSTYPE_LAZY_COPY_ASSIGN (type) = 0;
1552 case sfk_move_assignment:
1553 CLASSTYPE_LAZY_MOVE_ASSIGN (type) = 0;
1555 case sfk_destructor:
1556 CLASSTYPE_LAZY_DESTRUCTOR (type) = 0;
1562 /* Declare the function. */
1563 fn = implicitly_declare_fn (sfk, type, const_p);
1565 /* For move variants, rather than declare them as deleted we just
1566 don't declare them at all. */
1567 if (DECL_DELETED_FN (fn)
1568 && (sfk == sfk_move_constructor
1569 || sfk == sfk_move_assignment))
1572 /* A destructor may be virtual. */
1573 if (sfk == sfk_destructor
1574 || sfk == sfk_move_assignment
1575 || sfk == sfk_copy_assignment)
1576 check_for_override (fn, type);
1577 /* Add it to CLASSTYPE_METHOD_VEC. */
1578 add_method (type, fn, NULL_TREE);
1579 /* Add it to TYPE_METHODS. */
1580 if (sfk == sfk_destructor
1581 && DECL_VIRTUAL_P (fn)
1582 && abi_version_at_least (2))
1583 /* The ABI requires that a virtual destructor go at the end of the
1585 TYPE_METHODS (type) = chainon (TYPE_METHODS (type), fn);
1588 /* G++ 3.2 put the implicit destructor at the *beginning* of the
1589 TYPE_METHODS list, which cause the destructor to be emitted
1590 in an incorrect location in the vtable. */
1591 if (warn_abi && sfk == sfk_destructor && DECL_VIRTUAL_P (fn))
1592 warning (OPT_Wabi, "vtable layout for class %qT may not be ABI-compliant"
1593 "and may change in a future version of GCC due to "
1594 "implicit virtual destructor",
1596 TREE_CHAIN (fn) = TYPE_METHODS (type);
1597 TYPE_METHODS (type) = fn;
1599 maybe_add_class_template_decl_list (type, fn, /*friend_p=*/0);
1600 if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn)
1601 || DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn))
1602 /* Create appropriate clones. */
1603 clone_function_decl (fn, /*update_method_vec=*/true);
1608 /* Given a FUNCTION_DECL FN and a chain LIST, skip as many elements of LIST
1609 as there are artificial parms in FN. */
1612 skip_artificial_parms_for (const_tree fn, tree list)
1614 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
1615 list = TREE_CHAIN (list);
1619 if (DECL_HAS_IN_CHARGE_PARM_P (fn))
1620 list = TREE_CHAIN (list);
1621 if (DECL_HAS_VTT_PARM_P (fn))
1622 list = TREE_CHAIN (list);
1626 /* Given a FUNCTION_DECL FN and a chain LIST, return the number of
1627 artificial parms in FN. */
1630 num_artificial_parms_for (const_tree fn)
1634 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
1639 if (DECL_HAS_IN_CHARGE_PARM_P (fn))
1641 if (DECL_HAS_VTT_PARM_P (fn))
1647 #include "gt-cp-method.h"