Merged revisions 208012,208018-208019,208021,208023-208030,208033,208037,208040-20804...
[official-gcc.git] / main / gcc / cp / method.c
blob11bff7f45878ece660410341cc9fdc71ce8b24f0
1 /* Handle the hair of processing (but not expanding) inline functions.
2 Also manage function and variable name overloading.
3 Copyright (C) 1987-2014 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
6 This file is part of GCC.
8 GCC 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 3, or (at your option)
11 any later version.
13 GCC 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 GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* Handle method declarations. */
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "tm.h"
28 #include "tree.h"
29 #include "stringpool.h"
30 #include "varasm.h"
31 #include "cp-tree.h"
32 #include "flags.h"
33 #include "toplev.h"
34 #include "tm_p.h"
35 #include "target.h"
36 #include "common/common-target.h"
37 #include "diagnostic.h"
38 #include "cgraph.h"
39 #include "pointer-set.h"
41 /* Various flags to control the mangling process. */
43 enum mangling_flags
45 /* No flags. */
46 mf_none = 0,
47 /* The thing we are presently mangling is part of a template type,
48 rather than a fully instantiated type. Therefore, we may see
49 complex expressions where we would normally expect to see a
50 simple integer constant. */
51 mf_maybe_uninstantiated = 1,
52 /* When mangling a numeric value, use the form `_XX_' (instead of
53 just `XX') if the value has more than one digit. */
54 mf_use_underscores_around_value = 2
57 typedef enum mangling_flags mangling_flags;
59 static void do_build_copy_assign (tree);
60 static void do_build_copy_constructor (tree);
61 static tree make_alias_for_thunk (tree);
63 /* Called once to initialize method.c. */
65 void
66 init_method (void)
68 init_mangle ();
71 /* Return a this or result adjusting thunk to FUNCTION. THIS_ADJUSTING
72 indicates whether it is a this or result adjusting thunk.
73 FIXED_OFFSET and VIRTUAL_OFFSET indicate how to do the adjustment
74 (see thunk_adjust). VIRTUAL_OFFSET can be NULL, but FIXED_OFFSET
75 never is. VIRTUAL_OFFSET is the /index/ into the vtable for this
76 adjusting thunks, we scale it to a byte offset. For covariant
77 thunks VIRTUAL_OFFSET is the virtual binfo. You must post process
78 the returned thunk with finish_thunk. */
80 tree
81 make_thunk (tree function, bool this_adjusting,
82 tree fixed_offset, tree virtual_offset)
84 HOST_WIDE_INT d;
85 tree thunk;
87 gcc_assert (TREE_CODE (function) == FUNCTION_DECL);
88 /* We can have this thunks to covariant thunks, but not vice versa. */
89 gcc_assert (!DECL_THIS_THUNK_P (function));
90 gcc_assert (!DECL_RESULT_THUNK_P (function) || this_adjusting);
92 /* Scale the VIRTUAL_OFFSET to be in terms of bytes. */
93 if (this_adjusting && virtual_offset)
94 virtual_offset
95 = size_binop (MULT_EXPR,
96 virtual_offset,
97 convert (ssizetype,
98 TYPE_SIZE_UNIT (vtable_entry_type)));
100 d = tree_to_shwi (fixed_offset);
102 /* See if we already have the thunk in question. For this_adjusting
103 thunks VIRTUAL_OFFSET will be an INTEGER_CST, for covariant thunks it
104 will be a BINFO. */
105 for (thunk = DECL_THUNKS (function); thunk; thunk = DECL_CHAIN (thunk))
106 if (DECL_THIS_THUNK_P (thunk) == this_adjusting
107 && THUNK_FIXED_OFFSET (thunk) == d
108 && !virtual_offset == !THUNK_VIRTUAL_OFFSET (thunk)
109 && (!virtual_offset
110 || (this_adjusting
111 ? tree_int_cst_equal (THUNK_VIRTUAL_OFFSET (thunk),
112 virtual_offset)
113 : THUNK_VIRTUAL_OFFSET (thunk) == virtual_offset)))
114 return thunk;
116 /* All thunks must be created before FUNCTION is actually emitted;
117 the ABI requires that all thunks be emitted together with the
118 function to which they transfer control. */
119 gcc_assert (!TREE_ASM_WRITTEN (function));
120 /* Likewise, we can only be adding thunks to a function declared in
121 the class currently being laid out. */
122 gcc_assert (TYPE_SIZE (DECL_CONTEXT (function))
123 && TYPE_BEING_DEFINED (DECL_CONTEXT (function)));
125 thunk = build_decl (DECL_SOURCE_LOCATION (function),
126 FUNCTION_DECL, NULL_TREE, TREE_TYPE (function));
127 DECL_LANG_SPECIFIC (thunk) = DECL_LANG_SPECIFIC (function);
128 cxx_dup_lang_specific_decl (thunk);
129 DECL_VIRTUAL_P (thunk) = true;
130 SET_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 DECL_INTERFACE_KNOWN (thunk) = 1;
143 DECL_NOT_REALLY_EXTERN (thunk) = 1;
144 DECL_COMDAT (thunk) = DECL_COMDAT (function);
145 DECL_SAVED_FUNCTION_DATA (thunk) = NULL;
146 /* The thunk itself is not a constructor or destructor, even if
147 the thing it is thunking to is. */
148 DECL_DESTRUCTOR_P (thunk) = 0;
149 DECL_CONSTRUCTOR_P (thunk) = 0;
150 DECL_EXTERNAL (thunk) = 1;
151 DECL_ARTIFICIAL (thunk) = 1;
152 /* The THUNK is not a pending inline, even if the FUNCTION is. */
153 DECL_PENDING_INLINE_P (thunk) = 0;
154 DECL_DECLARED_INLINE_P (thunk) = 0;
155 /* Nor is it a template instantiation. */
156 DECL_USE_TEMPLATE (thunk) = 0;
157 DECL_TEMPLATE_INFO (thunk) = NULL;
159 /* Add it to the list of thunks associated with FUNCTION. */
160 DECL_CHAIN (thunk) = DECL_THUNKS (function);
161 SET_DECL_THUNKS (function, thunk);
163 return thunk;
166 /* Finish THUNK, a thunk decl. */
168 void
169 finish_thunk (tree thunk)
171 tree function, name;
172 tree fixed_offset = ssize_int (THUNK_FIXED_OFFSET (thunk));
173 tree virtual_offset = THUNK_VIRTUAL_OFFSET (thunk);
175 gcc_assert (!DECL_NAME (thunk) && DECL_THUNK_P (thunk));
176 if (virtual_offset && DECL_RESULT_THUNK_P (thunk))
177 virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
178 function = THUNK_TARGET (thunk);
179 name = mangle_thunk (function, DECL_THIS_THUNK_P (thunk),
180 fixed_offset, virtual_offset);
182 /* We can end up with declarations of (logically) different
183 covariant thunks, that do identical adjustments. The two thunks
184 will be adjusting between within different hierarchies, which
185 happen to have the same layout. We must nullify one of them to
186 refer to the other. */
187 if (DECL_RESULT_THUNK_P (thunk))
189 tree cov_probe;
191 for (cov_probe = DECL_THUNKS (function);
192 cov_probe; cov_probe = DECL_CHAIN (cov_probe))
193 if (DECL_NAME (cov_probe) == name)
195 gcc_assert (!DECL_THUNKS (thunk));
196 THUNK_ALIAS (thunk) = (THUNK_ALIAS (cov_probe)
197 ? THUNK_ALIAS (cov_probe) : cov_probe);
198 break;
202 DECL_NAME (thunk) = name;
203 SET_DECL_ASSEMBLER_NAME (thunk, name);
206 static GTY (()) int thunk_labelno;
208 /* Create a static alias to target. */
210 tree
211 make_alias_for (tree target, tree newid)
213 tree alias = build_decl (DECL_SOURCE_LOCATION (target),
214 TREE_CODE (target), newid, TREE_TYPE (target));
215 DECL_LANG_SPECIFIC (alias) = DECL_LANG_SPECIFIC (target);
216 cxx_dup_lang_specific_decl (alias);
217 DECL_CONTEXT (alias) = NULL;
218 TREE_READONLY (alias) = TREE_READONLY (target);
219 TREE_THIS_VOLATILE (alias) = TREE_THIS_VOLATILE (target);
220 TREE_PUBLIC (alias) = 0;
221 DECL_INTERFACE_KNOWN (alias) = 1;
222 if (DECL_LANG_SPECIFIC (alias))
224 DECL_NOT_REALLY_EXTERN (alias) = 1;
225 DECL_USE_TEMPLATE (alias) = 0;
226 DECL_TEMPLATE_INFO (alias) = NULL;
228 DECL_EXTERNAL (alias) = 0;
229 DECL_ARTIFICIAL (alias) = 1;
230 DECL_TEMPLATE_INSTANTIATED (alias) = 0;
231 if (TREE_CODE (alias) == FUNCTION_DECL)
233 DECL_SAVED_FUNCTION_DATA (alias) = NULL;
234 DECL_DESTRUCTOR_P (alias) = 0;
235 DECL_CONSTRUCTOR_P (alias) = 0;
236 DECL_PENDING_INLINE_P (alias) = 0;
237 DECL_DECLARED_INLINE_P (alias) = 0;
238 DECL_INITIAL (alias) = error_mark_node;
239 DECL_ARGUMENTS (alias) = copy_list (DECL_ARGUMENTS (target));
241 else
242 TREE_STATIC (alias) = 1;
243 TREE_ADDRESSABLE (alias) = 1;
244 TREE_USED (alias) = 1;
245 SET_DECL_ASSEMBLER_NAME (alias, DECL_NAME (alias));
246 return alias;
249 static tree
250 make_alias_for_thunk (tree function)
252 tree alias;
253 char buf[256];
255 targetm.asm_out.generate_internal_label (buf, "LTHUNK", thunk_labelno);
256 thunk_labelno++;
258 alias = make_alias_for (function, get_identifier (buf));
260 if (!flag_syntax_only)
262 struct cgraph_node *funcn, *aliasn;
263 funcn = cgraph_get_node (function);
264 gcc_checking_assert (funcn);
265 aliasn = cgraph_same_body_alias (funcn, alias, function);
266 DECL_ASSEMBLER_NAME (function);
267 gcc_assert (aliasn != NULL);
270 return alias;
273 /* Emit the definition of a C++ multiple inheritance or covariant
274 return vtable thunk. If EMIT_P is nonzero, the thunk is emitted
275 immediately. */
277 void
278 use_thunk (tree thunk_fndecl, bool emit_p)
280 tree a, t, function, alias;
281 tree virtual_offset;
282 HOST_WIDE_INT fixed_offset, virtual_value;
283 bool this_adjusting = DECL_THIS_THUNK_P (thunk_fndecl);
284 struct cgraph_node *funcn, *thunk_node;
286 /* We should have called finish_thunk to give it a name. */
287 gcc_assert (DECL_NAME (thunk_fndecl));
289 /* We should never be using an alias, always refer to the
290 aliased thunk. */
291 gcc_assert (!THUNK_ALIAS (thunk_fndecl));
293 if (TREE_ASM_WRITTEN (thunk_fndecl))
294 return;
296 function = THUNK_TARGET (thunk_fndecl);
297 if (DECL_RESULT (thunk_fndecl))
298 /* We already turned this thunk into an ordinary function.
299 There's no need to process this thunk again. */
300 return;
302 if (DECL_THUNK_P (function))
303 /* The target is itself a thunk, process it now. */
304 use_thunk (function, emit_p);
306 /* Thunks are always addressable; they only appear in vtables. */
307 TREE_ADDRESSABLE (thunk_fndecl) = 1;
309 /* Figure out what function is being thunked to. It's referenced in
310 this translation unit. */
311 TREE_ADDRESSABLE (function) = 1;
312 mark_used (function);
313 if (!emit_p)
314 return;
316 if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function))
317 alias = make_alias_for_thunk (function);
318 else
319 alias = function;
321 fixed_offset = THUNK_FIXED_OFFSET (thunk_fndecl);
322 virtual_offset = THUNK_VIRTUAL_OFFSET (thunk_fndecl);
324 if (virtual_offset)
326 if (!this_adjusting)
327 virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
328 virtual_value = tree_to_shwi (virtual_offset);
329 gcc_assert (virtual_value);
331 else
332 virtual_value = 0;
334 /* And, if we need to emit the thunk, it's used. */
335 mark_used (thunk_fndecl);
336 /* This thunk is actually defined. */
337 DECL_EXTERNAL (thunk_fndecl) = 0;
338 /* The linkage of the function may have changed. FIXME in linkage
339 rewrite. */
340 gcc_assert (DECL_INTERFACE_KNOWN (function));
341 TREE_PUBLIC (thunk_fndecl) = TREE_PUBLIC (function);
342 DECL_VISIBILITY (thunk_fndecl) = DECL_VISIBILITY (function);
343 DECL_VISIBILITY_SPECIFIED (thunk_fndecl)
344 = DECL_VISIBILITY_SPECIFIED (function);
345 DECL_COMDAT (thunk_fndecl) = DECL_COMDAT (function);
346 DECL_WEAK (thunk_fndecl) = DECL_WEAK (function);
348 if (flag_syntax_only)
350 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
351 return;
354 push_to_top_level ();
356 if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function)
357 && targetm_common.have_named_sections)
359 resolve_unique_section (function, 0, flag_function_sections);
361 if (DECL_SECTION_NAME (function) != NULL && DECL_ONE_ONLY (function))
363 resolve_unique_section (thunk_fndecl, 0, flag_function_sections);
365 /* Output the thunk into the same section as function. */
366 DECL_SECTION_NAME (thunk_fndecl) = DECL_SECTION_NAME (function);
370 /* Set up cloned argument trees for the thunk. */
371 t = NULL_TREE;
372 for (a = DECL_ARGUMENTS (function); a; a = DECL_CHAIN (a))
374 tree x = copy_node (a);
375 DECL_CHAIN (x) = t;
376 DECL_CONTEXT (x) = thunk_fndecl;
377 SET_DECL_RTL (x, NULL);
378 DECL_HAS_VALUE_EXPR_P (x) = 0;
379 TREE_ADDRESSABLE (x) = 0;
380 t = x;
382 a = nreverse (t);
383 DECL_ARGUMENTS (thunk_fndecl) = a;
384 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
385 funcn = cgraph_get_node (function);
386 gcc_checking_assert (funcn);
387 thunk_node = cgraph_add_thunk (funcn, thunk_fndecl, function,
388 this_adjusting, fixed_offset, virtual_value,
389 virtual_offset, alias);
390 if (DECL_ONE_ONLY (function))
391 symtab_add_to_same_comdat_group (thunk_node,
392 funcn);
394 if (!this_adjusting
395 || !targetm.asm_out.can_output_mi_thunk (thunk_fndecl, fixed_offset,
396 virtual_value, alias))
398 /* If this is a covariant thunk, or we don't have the necessary
399 code for efficient thunks, generate a thunk function that
400 just makes a call to the real function. Unfortunately, this
401 doesn't work for varargs. */
403 if (varargs_function_p (function))
404 error ("generic thunk code fails for method %q#D which uses %<...%>",
405 function);
408 pop_from_top_level ();
411 /* Code for synthesizing methods which have default semantics defined. */
413 /* True iff CTYPE has a trivial SFK. */
415 static bool
416 type_has_trivial_fn (tree ctype, special_function_kind sfk)
418 switch (sfk)
420 case sfk_constructor:
421 return !TYPE_HAS_COMPLEX_DFLT (ctype);
422 case sfk_copy_constructor:
423 return !TYPE_HAS_COMPLEX_COPY_CTOR (ctype);
424 case sfk_move_constructor:
425 return !TYPE_HAS_COMPLEX_MOVE_CTOR (ctype);
426 case sfk_copy_assignment:
427 return !TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype);
428 case sfk_move_assignment:
429 return !TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype);
430 case sfk_destructor:
431 return !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype);
432 case sfk_inheriting_constructor:
433 return false;
434 default:
435 gcc_unreachable ();
439 /* Note that CTYPE has a non-trivial SFK even though we previously thought
440 it was trivial. */
442 static void
443 type_set_nontrivial_flag (tree ctype, special_function_kind sfk)
445 switch (sfk)
447 case sfk_constructor:
448 TYPE_HAS_COMPLEX_DFLT (ctype) = true;
449 return;
450 case sfk_copy_constructor:
451 TYPE_HAS_COMPLEX_COPY_CTOR (ctype) = true;
452 return;
453 case sfk_move_constructor:
454 TYPE_HAS_COMPLEX_MOVE_CTOR (ctype) = true;
455 return;
456 case sfk_copy_assignment:
457 TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype) = true;
458 return;
459 case sfk_move_assignment:
460 TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype) = true;
461 return;
462 case sfk_destructor:
463 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype) = true;
464 return;
465 case sfk_inheriting_constructor:
466 default:
467 gcc_unreachable ();
471 /* True iff FN is a trivial defaulted member function ([cd]tor, op=). */
473 bool
474 trivial_fn_p (tree fn)
476 if (!DECL_DEFAULTED_FN (fn))
477 return false;
479 /* If fn is a clone, get the primary variant. */
480 if (tree prim = DECL_CLONED_FUNCTION (fn))
481 fn = prim;
482 return type_has_trivial_fn (DECL_CONTEXT (fn), special_function_p (fn));
485 /* Subroutine of do_build_copy_constructor: Add a mem-initializer for BINFO
486 given the parameter or parameters PARM, possibly inherited constructor
487 base INH, or move flag MOVE_P. */
489 static tree
490 add_one_base_init (tree binfo, tree parm, bool move_p, tree inh,
491 tree member_init_list)
493 tree init;
494 if (inh)
496 /* An inheriting constructor only has a mem-initializer for
497 the base it inherits from. */
498 if (BINFO_TYPE (binfo) != inh)
499 return member_init_list;
501 tree *p = &init;
502 init = NULL_TREE;
503 for (; parm; parm = DECL_CHAIN (parm))
505 tree exp = convert_from_reference (parm);
506 if (TREE_CODE (TREE_TYPE (parm)) != REFERENCE_TYPE
507 || TYPE_REF_IS_RVALUE (TREE_TYPE (parm)))
508 exp = move (exp);
509 *p = build_tree_list (NULL_TREE, exp);
510 p = &TREE_CHAIN (*p);
513 else
515 init = build_base_path (PLUS_EXPR, parm, binfo, 1,
516 tf_warning_or_error);
517 if (move_p)
518 init = move (init);
519 init = build_tree_list (NULL_TREE, init);
521 return tree_cons (binfo, init, member_init_list);
524 /* Generate code for default X(X&) or X(X&&) constructor or an inheriting
525 constructor. */
527 static void
528 do_build_copy_constructor (tree fndecl)
530 tree parm = FUNCTION_FIRST_USER_PARM (fndecl);
531 bool move_p = DECL_MOVE_CONSTRUCTOR_P (fndecl);
532 bool trivial = trivial_fn_p (fndecl);
533 tree inh = DECL_INHERITED_CTOR_BASE (fndecl);
535 if (!inh)
536 parm = convert_from_reference (parm);
538 if (trivial
539 && is_empty_class (current_class_type))
540 /* Don't copy the padding byte; it might not have been allocated
541 if *this is a base subobject. */;
542 else if (trivial)
544 tree t = build2 (INIT_EXPR, void_type_node, current_class_ref, parm);
545 finish_expr_stmt (t);
547 else
549 tree fields = TYPE_FIELDS (current_class_type);
550 tree member_init_list = NULL_TREE;
551 int cvquals = cp_type_quals (TREE_TYPE (parm));
552 int i;
553 tree binfo, base_binfo;
554 tree init;
555 vec<tree, va_gc> *vbases;
557 /* Initialize all the base-classes with the parameter converted
558 to their type so that we get their copy constructor and not
559 another constructor that takes current_class_type. We must
560 deal with the binfo's directly as a direct base might be
561 inaccessible due to ambiguity. */
562 for (vbases = CLASSTYPE_VBASECLASSES (current_class_type), i = 0;
563 vec_safe_iterate (vbases, i, &binfo); i++)
565 member_init_list = add_one_base_init (binfo, parm, move_p, inh,
566 member_init_list);
569 for (binfo = TYPE_BINFO (current_class_type), i = 0;
570 BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
572 if (BINFO_VIRTUAL_P (base_binfo))
573 continue;
574 member_init_list = add_one_base_init (base_binfo, parm, move_p,
575 inh, member_init_list);
578 for (; fields; fields = DECL_CHAIN (fields))
580 tree field = fields;
581 tree expr_type;
583 if (TREE_CODE (field) != FIELD_DECL)
584 continue;
585 if (inh)
586 continue;
588 expr_type = TREE_TYPE (field);
589 if (DECL_NAME (field))
591 if (VFIELD_NAME_P (DECL_NAME (field)))
592 continue;
594 else if (ANON_AGGR_TYPE_P (expr_type) && TYPE_FIELDS (expr_type))
595 /* Just use the field; anonymous types can't have
596 nontrivial copy ctors or assignment ops or this
597 function would be deleted. */;
598 else
599 continue;
601 /* Compute the type of "init->field". If the copy-constructor
602 parameter is, for example, "const S&", and the type of
603 the field is "T", then the type will usually be "const
604 T". (There are no cv-qualified variants of reference
605 types.) */
606 if (TREE_CODE (expr_type) != REFERENCE_TYPE)
608 int quals = cvquals;
610 if (DECL_MUTABLE_P (field))
611 quals &= ~TYPE_QUAL_CONST;
612 quals |= cp_type_quals (expr_type);
613 expr_type = cp_build_qualified_type (expr_type, quals);
616 init = build3 (COMPONENT_REF, expr_type, parm, field, NULL_TREE);
617 if (move_p && TREE_CODE (expr_type) != REFERENCE_TYPE
618 /* 'move' breaks bit-fields, and has no effect for scalars. */
619 && !scalarish_type_p (expr_type))
620 init = move (init);
621 init = build_tree_list (NULL_TREE, init);
623 member_init_list = tree_cons (field, init, member_init_list);
625 finish_mem_initializers (member_init_list);
629 static void
630 do_build_copy_assign (tree fndecl)
632 tree parm = DECL_CHAIN (DECL_ARGUMENTS (fndecl));
633 tree compound_stmt;
634 bool move_p = move_fn_p (fndecl);
635 bool trivial = trivial_fn_p (fndecl);
636 int flags = LOOKUP_NORMAL | LOOKUP_NONVIRTUAL | LOOKUP_DEFAULTED;
638 compound_stmt = begin_compound_stmt (0);
639 parm = convert_from_reference (parm);
641 if (trivial
642 && is_empty_class (current_class_type))
643 /* Don't copy the padding byte; it might not have been allocated
644 if *this is a base subobject. */;
645 else if (trivial)
647 tree t = build2 (MODIFY_EXPR, void_type_node, current_class_ref, parm);
648 finish_expr_stmt (t);
650 else
652 tree fields;
653 int cvquals = cp_type_quals (TREE_TYPE (parm));
654 int i;
655 tree binfo, base_binfo;
657 /* Assign to each of the direct base classes. */
658 for (binfo = TYPE_BINFO (current_class_type), i = 0;
659 BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
661 tree converted_parm;
662 vec<tree, va_gc> *parmvec;
664 /* We must convert PARM directly to the base class
665 explicitly since the base class may be ambiguous. */
666 converted_parm = build_base_path (PLUS_EXPR, parm, base_binfo, 1,
667 tf_warning_or_error);
668 if (move_p)
669 converted_parm = move (converted_parm);
670 /* Call the base class assignment operator. */
671 parmvec = make_tree_vector_single (converted_parm);
672 finish_expr_stmt
673 (build_special_member_call (current_class_ref,
674 ansi_assopname (NOP_EXPR),
675 &parmvec,
676 base_binfo,
677 flags,
678 tf_warning_or_error));
679 release_tree_vector (parmvec);
682 /* Assign to each of the non-static data members. */
683 for (fields = TYPE_FIELDS (current_class_type);
684 fields;
685 fields = DECL_CHAIN (fields))
687 tree comp = current_class_ref;
688 tree init = parm;
689 tree field = fields;
690 tree expr_type;
691 int quals;
693 if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field))
694 continue;
696 expr_type = TREE_TYPE (field);
698 if (CP_TYPE_CONST_P (expr_type))
700 error ("non-static const member %q#D, can%'t use default "
701 "assignment operator", field);
702 continue;
704 else if (TREE_CODE (expr_type) == REFERENCE_TYPE)
706 error ("non-static reference member %q#D, can%'t use "
707 "default assignment operator", field);
708 continue;
711 if (DECL_NAME (field))
713 if (VFIELD_NAME_P (DECL_NAME (field)))
714 continue;
716 else if (ANON_AGGR_TYPE_P (expr_type)
717 && TYPE_FIELDS (expr_type) != NULL_TREE)
718 /* Just use the field; anonymous types can't have
719 nontrivial copy ctors or assignment ops or this
720 function would be deleted. */;
721 else
722 continue;
724 comp = build3 (COMPONENT_REF, expr_type, comp, field, NULL_TREE);
726 /* Compute the type of init->field */
727 quals = cvquals;
728 if (DECL_MUTABLE_P (field))
729 quals &= ~TYPE_QUAL_CONST;
730 expr_type = cp_build_qualified_type (expr_type, quals);
732 init = build3 (COMPONENT_REF, expr_type, init, field, NULL_TREE);
733 if (move_p && TREE_CODE (expr_type) != REFERENCE_TYPE
734 /* 'move' breaks bit-fields, and has no effect for scalars. */
735 && !scalarish_type_p (expr_type))
736 init = move (init);
738 if (DECL_NAME (field))
739 init = cp_build_modify_expr (comp, NOP_EXPR, init,
740 tf_warning_or_error);
741 else
742 init = build2 (MODIFY_EXPR, TREE_TYPE (comp), comp, init);
743 finish_expr_stmt (init);
746 finish_return_stmt (current_class_ref);
747 finish_compound_stmt (compound_stmt);
750 /* Synthesize FNDECL, a non-static member function. */
752 void
753 synthesize_method (tree fndecl)
755 bool nested = (current_function_decl != NULL_TREE);
756 tree context = decl_function_context (fndecl);
757 bool need_body = true;
758 tree stmt;
759 location_t save_input_location = input_location;
760 int error_count = errorcount;
761 int warning_count = warningcount + werrorcount;
763 /* Reset the source location, we might have been previously
764 deferred, and thus have saved where we were first needed. */
765 DECL_SOURCE_LOCATION (fndecl)
766 = DECL_SOURCE_LOCATION (TYPE_NAME (DECL_CONTEXT (fndecl)));
768 /* If we've been asked to synthesize a clone, just synthesize the
769 cloned function instead. Doing so will automatically fill in the
770 body for the clone. */
771 if (DECL_CLONED_FUNCTION_P (fndecl))
772 fndecl = DECL_CLONED_FUNCTION (fndecl);
774 /* We may be in the middle of deferred access check. Disable
775 it now. */
776 push_deferring_access_checks (dk_no_deferred);
778 if (! context)
779 push_to_top_level ();
780 else if (nested)
781 push_function_context ();
783 input_location = DECL_SOURCE_LOCATION (fndecl);
785 start_preparsed_function (fndecl, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED);
786 stmt = begin_function_body ();
788 if (DECL_OVERLOADED_OPERATOR_P (fndecl) == NOP_EXPR)
790 do_build_copy_assign (fndecl);
791 need_body = false;
793 else if (DECL_CONSTRUCTOR_P (fndecl))
795 tree arg_chain = FUNCTION_FIRST_USER_PARMTYPE (fndecl);
796 if (arg_chain != void_list_node)
797 do_build_copy_constructor (fndecl);
798 else
799 finish_mem_initializers (NULL_TREE);
802 /* If we haven't yet generated the body of the function, just
803 generate an empty compound statement. */
804 if (need_body)
806 tree compound_stmt;
807 compound_stmt = begin_compound_stmt (BCS_FN_BODY);
808 finish_compound_stmt (compound_stmt);
811 finish_function_body (stmt);
812 expand_or_defer_fn (finish_function (0));
814 input_location = save_input_location;
816 if (! context)
817 pop_from_top_level ();
818 else if (nested)
819 pop_function_context ();
821 pop_deferring_access_checks ();
823 if (error_count != errorcount || warning_count != warningcount + werrorcount)
824 inform (input_location, "synthesized method %qD first required here ",
825 fndecl);
828 /* Build a reference to type TYPE with cv-quals QUALS, which is an
829 rvalue if RVALUE is true. */
831 static tree
832 build_stub_type (tree type, int quals, bool rvalue)
834 tree argtype = cp_build_qualified_type (type, quals);
835 return cp_build_reference_type (argtype, rvalue);
838 /* Build a dummy glvalue from dereferencing a dummy reference of type
839 REFTYPE. */
841 static tree
842 build_stub_object (tree reftype)
844 tree stub = build1 (NOP_EXPR, reftype, integer_one_node);
845 return convert_from_reference (stub);
848 /* Determine which function will be called when looking up NAME in TYPE,
849 called with a single ARGTYPE argument, or no argument if ARGTYPE is
850 null. FLAGS and COMPLAIN are as for build_new_method_call.
852 Returns a FUNCTION_DECL if all is well.
853 Returns NULL_TREE if overload resolution failed.
854 Returns error_mark_node if the chosen function cannot be called. */
856 static tree
857 locate_fn_flags (tree type, tree name, tree argtype, int flags,
858 tsubst_flags_t complain)
860 tree ob, fn, fns, binfo, rval;
861 vec<tree, va_gc> *args;
863 if (TYPE_P (type))
864 binfo = TYPE_BINFO (type);
865 else
867 binfo = type;
868 type = BINFO_TYPE (binfo);
871 ob = build_stub_object (cp_build_reference_type (type, false));
872 args = make_tree_vector ();
873 if (argtype)
875 if (TREE_CODE (argtype) == TREE_LIST)
877 for (tree elt = argtype; elt != void_list_node;
878 elt = TREE_CHAIN (elt))
880 tree type = TREE_VALUE (elt);
881 if (TREE_CODE (type) != REFERENCE_TYPE)
882 type = cp_build_reference_type (type, /*rval*/true);
883 tree arg = build_stub_object (type);
884 vec_safe_push (args, arg);
887 else
889 tree arg = build_stub_object (argtype);
890 args->quick_push (arg);
894 fns = lookup_fnfields (binfo, name, 0);
895 rval = build_new_method_call (ob, fns, &args, binfo, flags, &fn, complain);
897 release_tree_vector (args);
898 if (fn && rval == error_mark_node)
899 return rval;
900 else
901 return fn;
904 /* Locate the dtor of TYPE. */
906 tree
907 get_dtor (tree type, tsubst_flags_t complain)
909 tree fn = locate_fn_flags (type, complete_dtor_identifier, NULL_TREE,
910 LOOKUP_NORMAL, complain);
911 if (fn == error_mark_node)
912 return NULL_TREE;
913 return fn;
916 /* Locate the default ctor of TYPE. */
918 tree
919 locate_ctor (tree type)
921 tree fn;
923 push_deferring_access_checks (dk_no_check);
924 fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
925 LOOKUP_SPECULATIVE, tf_none);
926 pop_deferring_access_checks ();
927 if (fn == error_mark_node)
928 return NULL_TREE;
929 return fn;
932 /* Likewise, but give any appropriate errors. */
934 tree
935 get_default_ctor (tree type)
937 tree fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
938 LOOKUP_NORMAL, tf_warning_or_error);
939 if (fn == error_mark_node)
940 return NULL_TREE;
941 return fn;
944 /* Locate the copy ctor of TYPE. */
946 tree
947 get_copy_ctor (tree type, tsubst_flags_t complain)
949 int quals = (TYPE_HAS_CONST_COPY_CTOR (type)
950 ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
951 tree argtype = build_stub_type (type, quals, false);
952 tree fn = locate_fn_flags (type, complete_ctor_identifier, argtype,
953 LOOKUP_NORMAL, complain);
954 if (fn == error_mark_node)
955 return NULL_TREE;
956 return fn;
959 /* Locate the copy assignment operator of TYPE. */
961 tree
962 get_copy_assign (tree type)
964 int quals = (TYPE_HAS_CONST_COPY_ASSIGN (type)
965 ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
966 tree argtype = build_stub_type (type, quals, false);
967 tree fn = locate_fn_flags (type, ansi_assopname (NOP_EXPR), argtype,
968 LOOKUP_NORMAL, tf_warning_or_error);
969 if (fn == error_mark_node)
970 return NULL_TREE;
971 return fn;
974 /* Locate the inherited constructor of constructor CTOR. */
976 tree
977 get_inherited_ctor (tree ctor)
979 gcc_assert (DECL_INHERITED_CTOR_BASE (ctor));
981 push_deferring_access_checks (dk_no_check);
982 tree fn = locate_fn_flags (DECL_INHERITED_CTOR_BASE (ctor),
983 complete_ctor_identifier,
984 FUNCTION_FIRST_USER_PARMTYPE (ctor),
985 LOOKUP_NORMAL|LOOKUP_SPECULATIVE,
986 tf_none);
987 pop_deferring_access_checks ();
988 if (fn == error_mark_node)
989 return NULL_TREE;
990 return fn;
993 /* Subroutine of synthesized_method_walk. Update SPEC_P, TRIVIAL_P and
994 DELETED_P or give an error message MSG with argument ARG. */
996 static void
997 process_subob_fn (tree fn, tree *spec_p, bool *trivial_p,
998 bool *deleted_p, bool *constexpr_p,
999 bool diag, tree arg)
1001 if (!fn || fn == error_mark_node)
1002 goto bad;
1004 if (spec_p)
1006 tree raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn));
1007 *spec_p = merge_exception_specifiers (*spec_p, raises, fn);
1010 if (!trivial_fn_p (fn))
1012 if (trivial_p)
1013 *trivial_p = false;
1014 if (TREE_CODE (arg) == FIELD_DECL
1015 && TREE_CODE (DECL_CONTEXT (arg)) == UNION_TYPE)
1017 if (deleted_p)
1018 *deleted_p = true;
1019 if (diag)
1020 error ("union member %q+D with non-trivial %qD", arg, fn);
1024 if (constexpr_p && !DECL_DECLARED_CONSTEXPR_P (fn))
1026 *constexpr_p = false;
1027 if (diag)
1029 inform (0, "defaulted constructor calls non-constexpr "
1030 "%q+D", fn);
1031 explain_invalid_constexpr_fn (fn);
1035 return;
1037 bad:
1038 if (deleted_p)
1039 *deleted_p = true;
1042 /* Subroutine of synthesized_method_walk to allow recursion into anonymous
1043 aggregates. */
1045 static void
1046 walk_field_subobs (tree fields, tree fnname, special_function_kind sfk,
1047 int quals, bool copy_arg_p, bool move_p,
1048 bool assign_p, tree *spec_p, bool *trivial_p,
1049 bool *deleted_p, bool *constexpr_p,
1050 bool diag, int flags, tsubst_flags_t complain)
1052 tree field;
1053 for (field = fields; field; field = DECL_CHAIN (field))
1055 tree mem_type, argtype, rval;
1057 if (TREE_CODE (field) != FIELD_DECL
1058 || DECL_ARTIFICIAL (field))
1059 continue;
1061 mem_type = strip_array_types (TREE_TYPE (field));
1062 if (assign_p)
1064 bool bad = true;
1065 if (CP_TYPE_CONST_P (mem_type) && !CLASS_TYPE_P (mem_type))
1067 if (diag)
1068 error ("non-static const member %q#D, can%'t use default "
1069 "assignment operator", field);
1071 else if (TREE_CODE (mem_type) == REFERENCE_TYPE)
1073 if (diag)
1074 error ("non-static reference member %q#D, can%'t use "
1075 "default assignment operator", field);
1077 else
1078 bad = false;
1080 if (bad && deleted_p)
1081 *deleted_p = true;
1083 else if (sfk == sfk_constructor)
1085 bool bad;
1087 if (DECL_INITIAL (field))
1089 if (diag && DECL_INITIAL (field) == error_mark_node)
1090 inform (0, "initializer for %q+#D is invalid", field);
1091 if (trivial_p)
1092 *trivial_p = false;
1093 #if 0
1094 /* Core 1351: If the field has an NSDMI that could throw, the
1095 default constructor is noexcept(false). FIXME this is
1096 broken by deferred parsing and 1360 saying we can't lazily
1097 declare a non-trivial default constructor. Also this
1098 needs to do deferred instantiation. Disable until the
1099 conflict between 1351 and 1360 is resolved. */
1100 if (spec_p && !expr_noexcept_p (DECL_INITIAL (field), complain))
1101 *spec_p = noexcept_false_spec;
1102 #endif
1104 /* Don't do the normal processing. */
1105 continue;
1108 bad = false;
1109 if (CP_TYPE_CONST_P (mem_type)
1110 && default_init_uninitialized_part (mem_type))
1112 if (diag)
1114 error ("uninitialized const member in %q#T",
1115 current_class_type);
1116 inform (DECL_SOURCE_LOCATION (field),
1117 "%q#D should be initialized", field);
1119 bad = true;
1121 else if (TREE_CODE (mem_type) == REFERENCE_TYPE)
1123 if (diag)
1125 error ("uninitialized reference member in %q#T",
1126 current_class_type);
1127 inform (DECL_SOURCE_LOCATION (field),
1128 "%q#D should be initialized", field);
1130 bad = true;
1133 if (bad && deleted_p)
1134 *deleted_p = true;
1136 /* For an implicitly-defined default constructor to be constexpr,
1137 every member must have a user-provided default constructor or
1138 an explicit initializer. */
1139 if (constexpr_p && !CLASS_TYPE_P (mem_type)
1140 && TREE_CODE (DECL_CONTEXT (field)) != UNION_TYPE)
1142 *constexpr_p = false;
1143 if (diag)
1144 inform (0, "defaulted default constructor does not "
1145 "initialize %q+#D", field);
1148 else if (sfk == sfk_copy_constructor)
1150 /* 12.8p11b5 */
1151 if (TREE_CODE (mem_type) == REFERENCE_TYPE
1152 && TYPE_REF_IS_RVALUE (mem_type))
1154 if (diag)
1155 error ("copying non-static data member %q#D of rvalue "
1156 "reference type", field);
1157 if (deleted_p)
1158 *deleted_p = true;
1162 if (!CLASS_TYPE_P (mem_type))
1163 continue;
1165 if (ANON_AGGR_TYPE_P (mem_type))
1167 walk_field_subobs (TYPE_FIELDS (mem_type), fnname, sfk, quals,
1168 copy_arg_p, move_p, assign_p, spec_p, trivial_p,
1169 deleted_p, constexpr_p,
1170 diag, flags, complain);
1171 continue;
1174 if (copy_arg_p)
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);
1181 else
1182 argtype = NULL_TREE;
1184 rval = locate_fn_flags (mem_type, fnname, argtype, flags, complain);
1186 process_subob_fn (rval, spec_p, trivial_p, deleted_p,
1187 constexpr_p, diag, field);
1191 /* The caller wants to generate an implicit declaration of SFK for CTYPE
1192 which is const if relevant and CONST_P is set. If spec_p, trivial_p and
1193 deleted_p are non-null, set their referent appropriately. If diag is
1194 true, we're either being called from maybe_explain_implicit_delete to
1195 give errors, or if constexpr_p is non-null, from
1196 explain_invalid_constexpr_fn. */
1198 static void
1199 synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p,
1200 tree *spec_p, bool *trivial_p, bool *deleted_p,
1201 bool *constexpr_p, bool diag,
1202 tree inherited_base, tree inherited_parms)
1204 tree binfo, base_binfo, scope, fnname, rval, argtype;
1205 bool move_p, copy_arg_p, assign_p, expected_trivial, check_vdtor;
1206 vec<tree, va_gc> *vbases;
1207 int i, quals, flags;
1208 tsubst_flags_t complain;
1209 bool ctor_p;
1211 if (spec_p)
1212 *spec_p = (cxx_dialect >= cxx11 ? noexcept_true_spec : empty_except_spec);
1214 if (deleted_p)
1216 /* "The closure type associated with a lambda-expression has a deleted
1217 default constructor and a deleted copy assignment operator."
1218 This is diagnosed in maybe_explain_implicit_delete. */
1219 if (LAMBDA_TYPE_P (ctype)
1220 && (sfk == sfk_constructor
1221 || sfk == sfk_copy_assignment))
1223 *deleted_p = true;
1224 return;
1227 *deleted_p = false;
1230 ctor_p = false;
1231 assign_p = false;
1232 check_vdtor = false;
1233 switch (sfk)
1235 case sfk_move_assignment:
1236 case sfk_copy_assignment:
1237 assign_p = true;
1238 fnname = ansi_assopname (NOP_EXPR);
1239 break;
1241 case sfk_destructor:
1242 check_vdtor = true;
1243 /* The synthesized method will call base dtors, but check complete
1244 here to avoid having to deal with VTT. */
1245 fnname = complete_dtor_identifier;
1246 break;
1248 case sfk_constructor:
1249 case sfk_move_constructor:
1250 case sfk_copy_constructor:
1251 case sfk_inheriting_constructor:
1252 ctor_p = true;
1253 fnname = complete_ctor_identifier;
1254 break;
1256 default:
1257 gcc_unreachable ();
1260 gcc_assert ((sfk == sfk_inheriting_constructor)
1261 == (inherited_base != NULL_TREE));
1263 /* If that user-written default constructor would satisfy the
1264 requirements of a constexpr constructor (7.1.5), the
1265 implicitly-defined default constructor is constexpr. */
1266 if (constexpr_p)
1267 *constexpr_p = ctor_p;
1269 move_p = false;
1270 switch (sfk)
1272 case sfk_constructor:
1273 case sfk_destructor:
1274 case sfk_inheriting_constructor:
1275 copy_arg_p = false;
1276 break;
1278 case sfk_move_constructor:
1279 case sfk_move_assignment:
1280 move_p = true;
1281 case sfk_copy_constructor:
1282 case sfk_copy_assignment:
1283 copy_arg_p = true;
1284 break;
1286 default:
1287 gcc_unreachable ();
1290 expected_trivial = type_has_trivial_fn (ctype, sfk);
1291 if (trivial_p)
1292 *trivial_p = expected_trivial;
1294 /* The TYPE_HAS_COMPLEX_* flags tell us about constraints from base
1295 class versions and other properties of the type. But a subobject
1296 class can be trivially copyable and yet have overload resolution
1297 choose a template constructor for initialization, depending on
1298 rvalueness and cv-quals. And furthermore, a member in a base might
1299 be trivial but deleted or otherwise not callable. So we can't exit
1300 early in C++0x. The same considerations apply in C++98/03, but
1301 there the definition of triviality does not consider overload
1302 resolution, so a constructor can be trivial even if it would otherwise
1303 call a non-trivial constructor. */
1304 if (expected_trivial
1305 && (!copy_arg_p || cxx_dialect < cxx11))
1307 if (constexpr_p && sfk == sfk_constructor)
1309 bool cx = trivial_default_constructor_is_constexpr (ctype);
1310 *constexpr_p = cx;
1311 if (diag && !cx && TREE_CODE (ctype) == UNION_TYPE)
1312 /* A trivial constructor doesn't have any NSDMI. */
1313 inform (input_location, "defaulted default constructor does "
1314 "not initialize any non-static data member");
1316 if (!diag && cxx_dialect < cxx11)
1317 return;
1320 ++cp_unevaluated_operand;
1321 ++c_inhibit_evaluation_warnings;
1322 push_deferring_access_checks (dk_no_deferred);
1324 scope = push_scope (ctype);
1326 flags = LOOKUP_NORMAL|LOOKUP_SPECULATIVE;
1327 if (!inherited_base)
1328 flags |= LOOKUP_DEFAULTED;
1330 complain = diag ? tf_warning_or_error : tf_none;
1332 if (const_p)
1333 quals = TYPE_QUAL_CONST;
1334 else
1335 quals = TYPE_UNQUALIFIED;
1336 argtype = NULL_TREE;
1338 for (binfo = TYPE_BINFO (ctype), i = 0;
1339 BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
1341 tree basetype = BINFO_TYPE (base_binfo);
1343 if (!assign_p && BINFO_VIRTUAL_P (base_binfo))
1344 /* We'll handle virtual bases below. */
1345 continue;
1347 if (copy_arg_p)
1348 argtype = build_stub_type (basetype, quals, move_p);
1349 else if (basetype == inherited_base)
1350 argtype = inherited_parms;
1351 rval = locate_fn_flags (base_binfo, fnname, argtype, flags, complain);
1352 if (inherited_base)
1353 argtype = NULL_TREE;
1355 process_subob_fn (rval, spec_p, trivial_p, deleted_p,
1356 constexpr_p, diag, basetype);
1357 if (ctor_p)
1359 /* In a constructor we also need to check the subobject
1360 destructors for cleanup of partially constructed objects. */
1361 rval = locate_fn_flags (base_binfo, complete_dtor_identifier,
1362 NULL_TREE, flags, complain);
1363 /* Note that we don't pass down trivial_p; the subobject
1364 destructors don't affect triviality of the constructor. Nor
1365 do they affect constexpr-ness (a constant expression doesn't
1366 throw) or exception-specification (a throw from one of the
1367 dtors would be a double-fault). */
1368 process_subob_fn (rval, NULL, NULL,
1369 deleted_p, NULL, false,
1370 basetype);
1373 if (check_vdtor && type_has_virtual_destructor (basetype))
1375 rval = locate_fn_flags (ctype, ansi_opname (DELETE_EXPR),
1376 ptr_type_node, flags, complain);
1377 /* Unlike for base ctor/op=/dtor, for operator delete it's fine
1378 to have a null rval (no class-specific op delete). */
1379 if (rval && rval == error_mark_node && deleted_p)
1380 *deleted_p = true;
1381 check_vdtor = false;
1384 if (diag && assign_p && move_p
1385 && BINFO_VIRTUAL_P (base_binfo)
1386 && rval && TREE_CODE (rval) == FUNCTION_DECL
1387 && move_fn_p (rval) && !trivial_fn_p (rval)
1388 && vbase_has_user_provided_move_assign (basetype))
1389 warning (OPT_Wvirtual_move_assign,
1390 "defaulted move assignment for %qT calls a non-trivial "
1391 "move assignment operator for virtual base %qT",
1392 ctype, basetype);
1395 vbases = CLASSTYPE_VBASECLASSES (ctype);
1396 if (vec_safe_is_empty (vbases))
1397 /* No virtual bases to worry about. */;
1398 else if (!assign_p)
1400 if (constexpr_p)
1401 *constexpr_p = false;
1402 FOR_EACH_VEC_ELT (*vbases, i, base_binfo)
1404 tree basetype = BINFO_TYPE (base_binfo);
1405 if (copy_arg_p)
1406 argtype = build_stub_type (basetype, quals, move_p);
1407 rval = locate_fn_flags (base_binfo, fnname, argtype, flags, complain);
1409 process_subob_fn (rval, spec_p, trivial_p, deleted_p,
1410 constexpr_p, diag, basetype);
1411 if (ctor_p && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (basetype))
1413 rval = locate_fn_flags (base_binfo, complete_dtor_identifier,
1414 NULL_TREE, flags, complain);
1415 process_subob_fn (rval, NULL, NULL,
1416 deleted_p, NULL, false,
1417 basetype);
1422 /* Now handle the non-static data members. */
1423 walk_field_subobs (TYPE_FIELDS (ctype), fnname, sfk, quals,
1424 copy_arg_p, move_p, assign_p, spec_p, trivial_p,
1425 deleted_p, constexpr_p,
1426 diag, flags, complain);
1427 if (ctor_p)
1428 walk_field_subobs (TYPE_FIELDS (ctype), complete_dtor_identifier,
1429 sfk_destructor, TYPE_UNQUALIFIED, false,
1430 false, false, NULL, NULL,
1431 deleted_p, NULL,
1432 false, flags, complain);
1434 pop_scope (scope);
1436 pop_deferring_access_checks ();
1437 --cp_unevaluated_operand;
1438 --c_inhibit_evaluation_warnings;
1441 /* DECL is a deleted function. If it's implicitly deleted, explain why and
1442 return true; else return false. */
1444 bool
1445 maybe_explain_implicit_delete (tree decl)
1447 /* If decl is a clone, get the primary variant. */
1448 decl = DECL_ORIGIN (decl);
1449 gcc_assert (DECL_DELETED_FN (decl));
1450 if (DECL_DEFAULTED_FN (decl))
1452 /* Not marked GTY; it doesn't need to be GC'd or written to PCH. */
1453 static struct pointer_set_t *explained;
1455 special_function_kind sfk;
1456 location_t loc;
1457 bool informed;
1458 tree ctype;
1460 if (!explained)
1461 explained = pointer_set_create ();
1462 if (pointer_set_insert (explained, decl))
1463 return true;
1465 sfk = special_function_p (decl);
1466 ctype = DECL_CONTEXT (decl);
1467 loc = input_location;
1468 input_location = DECL_SOURCE_LOCATION (decl);
1470 informed = false;
1471 if (LAMBDA_TYPE_P (ctype))
1473 informed = true;
1474 if (sfk == sfk_constructor)
1475 inform (DECL_SOURCE_LOCATION (decl),
1476 "a lambda closure type has a deleted default constructor");
1477 else if (sfk == sfk_copy_assignment)
1478 inform (DECL_SOURCE_LOCATION (decl),
1479 "a lambda closure type has a deleted copy assignment operator");
1480 else
1481 informed = false;
1483 else if (DECL_ARTIFICIAL (decl)
1484 && (sfk == sfk_copy_assignment
1485 || sfk == sfk_copy_constructor)
1486 && (type_has_user_declared_move_constructor (ctype)
1487 || type_has_user_declared_move_assign (ctype)))
1489 inform (0, "%q+#D is implicitly declared as deleted because %qT "
1490 "declares a move constructor or move assignment operator",
1491 decl, ctype);
1492 informed = true;
1494 if (!informed)
1496 tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
1497 tree parm_type = TREE_VALUE (parms);
1498 bool const_p = CP_TYPE_CONST_P (non_reference (parm_type));
1499 tree raises = NULL_TREE;
1500 bool deleted_p = false;
1501 tree scope = push_scope (ctype);
1503 synthesized_method_walk (ctype, sfk, const_p,
1504 &raises, NULL, &deleted_p, NULL, false,
1505 DECL_INHERITED_CTOR_BASE (decl), parms);
1506 if (deleted_p)
1508 inform (0, "%q+#D is implicitly deleted because the default "
1509 "definition would be ill-formed:", decl);
1510 synthesized_method_walk (ctype, sfk, const_p,
1511 NULL, NULL, NULL, NULL, true,
1512 DECL_INHERITED_CTOR_BASE (decl), parms);
1514 else if (!comp_except_specs
1515 (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl)),
1516 raises, ce_normal))
1517 inform (DECL_SOURCE_LOCATION (decl), "%q#F is implicitly "
1518 "deleted because its exception-specification does not "
1519 "match the implicit exception-specification %qX",
1520 decl, raises);
1521 #ifdef ENABLE_CHECKING
1522 else
1523 gcc_unreachable ();
1524 #endif
1526 pop_scope (scope);
1529 input_location = loc;
1530 return true;
1532 return false;
1535 /* DECL is a defaulted function which was declared constexpr. Explain why
1536 it can't be constexpr. */
1538 void
1539 explain_implicit_non_constexpr (tree decl)
1541 tree parm_type = TREE_VALUE (FUNCTION_FIRST_USER_PARMTYPE (decl));
1542 bool const_p = CP_TYPE_CONST_P (non_reference (parm_type));
1543 bool dummy;
1544 synthesized_method_walk (DECL_CLASS_CONTEXT (decl),
1545 special_function_p (decl), const_p,
1546 NULL, NULL, NULL, &dummy, true,
1547 NULL_TREE, NULL_TREE);
1550 /* DECL is an instantiation of an inheriting constructor template. Deduce
1551 the correct exception-specification and deletedness for this particular
1552 specialization. */
1554 void
1555 deduce_inheriting_ctor (tree decl)
1557 gcc_assert (DECL_INHERITED_CTOR_BASE (decl));
1558 tree spec;
1559 bool trivial, constexpr_, deleted;
1560 synthesized_method_walk (DECL_CONTEXT (decl), sfk_inheriting_constructor,
1561 false, &spec, &trivial, &deleted, &constexpr_,
1562 /*diag*/false,
1563 DECL_INHERITED_CTOR_BASE (decl),
1564 FUNCTION_FIRST_USER_PARMTYPE (decl));
1565 DECL_DELETED_FN (decl) = deleted;
1566 TREE_TYPE (decl) = build_exception_variant (TREE_TYPE (decl), spec);
1569 /* Implicitly declare the special function indicated by KIND, as a
1570 member of TYPE. For copy constructors and assignment operators,
1571 CONST_P indicates whether these functions should take a const
1572 reference argument or a non-const reference. Returns the
1573 FUNCTION_DECL for the implicitly declared function. */
1575 tree
1576 implicitly_declare_fn (special_function_kind kind, tree type,
1577 bool const_p, tree inherited_ctor,
1578 tree inherited_parms)
1580 tree fn;
1581 tree parameter_types = void_list_node;
1582 tree return_type;
1583 tree fn_type;
1584 tree raises = empty_except_spec;
1585 tree rhs_parm_type = NULL_TREE;
1586 tree this_parm;
1587 tree name;
1588 HOST_WIDE_INT saved_processing_template_decl;
1589 bool deleted_p;
1590 bool constexpr_p;
1592 /* Because we create declarations for implicitly declared functions
1593 lazily, we may be creating the declaration for a member of TYPE
1594 while in some completely different context. However, TYPE will
1595 never be a dependent class (because we never want to do lookups
1596 for implicitly defined functions in a dependent class).
1597 Furthermore, we must set PROCESSING_TEMPLATE_DECL to zero here
1598 because we only create clones for constructors and destructors
1599 when not in a template. */
1600 gcc_assert (!dependent_type_p (type));
1601 saved_processing_template_decl = processing_template_decl;
1602 processing_template_decl = 0;
1604 type = TYPE_MAIN_VARIANT (type);
1606 if (targetm.cxx.cdtor_returns_this () && !TYPE_FOR_JAVA (type))
1608 if (kind == sfk_destructor)
1609 /* See comment in check_special_function_return_type. */
1610 return_type = build_pointer_type (void_type_node);
1611 else
1612 return_type = build_pointer_type (type);
1614 else
1615 return_type = void_type_node;
1617 switch (kind)
1619 case sfk_destructor:
1620 /* Destructor. */
1621 name = constructor_name (type);
1622 break;
1624 case sfk_constructor:
1625 /* Default constructor. */
1626 name = constructor_name (type);
1627 break;
1629 case sfk_copy_constructor:
1630 case sfk_copy_assignment:
1631 case sfk_move_constructor:
1632 case sfk_move_assignment:
1633 case sfk_inheriting_constructor:
1635 bool move_p;
1636 if (kind == sfk_copy_assignment
1637 || kind == sfk_move_assignment)
1639 return_type = build_reference_type (type);
1640 name = ansi_assopname (NOP_EXPR);
1642 else
1643 name = constructor_name (type);
1645 if (kind == sfk_inheriting_constructor)
1646 parameter_types = inherited_parms;
1647 else
1649 if (const_p)
1650 rhs_parm_type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
1651 else
1652 rhs_parm_type = type;
1653 move_p = (kind == sfk_move_assignment
1654 || kind == sfk_move_constructor);
1655 rhs_parm_type = cp_build_reference_type (rhs_parm_type, move_p);
1657 parameter_types = tree_cons (NULL_TREE, rhs_parm_type, parameter_types);
1659 break;
1661 default:
1662 gcc_unreachable ();
1665 tree inherited_base = (inherited_ctor
1666 ? DECL_CONTEXT (inherited_ctor)
1667 : NULL_TREE);
1668 bool trivial_p = false;
1670 if (inherited_ctor && TREE_CODE (inherited_ctor) == TEMPLATE_DECL)
1672 /* For an inheriting constructor template, just copy these flags from
1673 the inherited constructor template for now. */
1674 raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (inherited_ctor));
1675 deleted_p = DECL_DELETED_FN (inherited_ctor);
1676 constexpr_p = DECL_DECLARED_CONSTEXPR_P (inherited_ctor);
1678 else
1679 synthesized_method_walk (type, kind, const_p, &raises, &trivial_p,
1680 &deleted_p, &constexpr_p, false,
1681 inherited_base, inherited_parms);
1682 /* Don't bother marking a deleted constructor as constexpr. */
1683 if (deleted_p)
1684 constexpr_p = false;
1685 /* A trivial copy/move constructor is also a constexpr constructor,
1686 unless the class has virtual bases (7.1.5p4). */
1687 else if (trivial_p && cxx_dialect >= cxx11
1688 && (kind == sfk_copy_constructor
1689 || kind == sfk_move_constructor)
1690 && !CLASSTYPE_VBASECLASSES (type))
1691 gcc_assert (constexpr_p);
1693 if (!trivial_p && type_has_trivial_fn (type, kind))
1694 type_set_nontrivial_flag (type, kind);
1696 /* Create the function. */
1697 fn_type = build_method_type_directly (type, return_type, parameter_types);
1698 if (raises)
1699 fn_type = build_exception_variant (fn_type, raises);
1700 fn = build_lang_decl (FUNCTION_DECL, name, fn_type);
1701 if (kind != sfk_inheriting_constructor)
1702 DECL_SOURCE_LOCATION (fn) = DECL_SOURCE_LOCATION (TYPE_NAME (type));
1703 if (kind == sfk_constructor || kind == sfk_copy_constructor
1704 || kind == sfk_move_constructor || kind == sfk_inheriting_constructor)
1705 DECL_CONSTRUCTOR_P (fn) = 1;
1706 else if (kind == sfk_destructor)
1707 DECL_DESTRUCTOR_P (fn) = 1;
1708 else
1710 DECL_ASSIGNMENT_OPERATOR_P (fn) = 1;
1711 SET_OVERLOADED_OPERATOR_CODE (fn, NOP_EXPR);
1714 /* If pointers to member functions use the least significant bit to
1715 indicate whether a function is virtual, ensure a pointer
1716 to this function will have that bit clear. */
1717 if (TARGET_PTRMEMFUNC_VBIT_LOCATION == ptrmemfunc_vbit_in_pfn
1718 && DECL_ALIGN (fn) < 2 * BITS_PER_UNIT)
1719 DECL_ALIGN (fn) = 2 * BITS_PER_UNIT;
1721 /* Create the explicit arguments. */
1722 if (rhs_parm_type)
1724 /* Note that this parameter is *not* marked DECL_ARTIFICIAL; we
1725 want its type to be included in the mangled function
1726 name. */
1727 tree decl = cp_build_parm_decl (NULL_TREE, rhs_parm_type);
1728 TREE_READONLY (decl) = 1;
1729 retrofit_lang_decl (decl);
1730 DECL_PARM_INDEX (decl) = DECL_PARM_LEVEL (decl) = 1;
1731 DECL_ARGUMENTS (fn) = decl;
1733 else if (kind == sfk_inheriting_constructor)
1735 tree *p = &DECL_ARGUMENTS (fn);
1736 int index = 1;
1737 for (tree parm = inherited_parms; parm != void_list_node;
1738 parm = TREE_CHAIN (parm))
1740 *p = cp_build_parm_decl (NULL_TREE, TREE_VALUE (parm));
1741 retrofit_lang_decl (*p);
1742 DECL_PARM_LEVEL (*p) = 1;
1743 DECL_PARM_INDEX (*p) = index++;
1744 DECL_CONTEXT (*p) = fn;
1745 p = &DECL_CHAIN (*p);
1747 SET_DECL_INHERITED_CTOR_BASE (fn, inherited_base);
1748 DECL_NONCONVERTING_P (fn) = DECL_NONCONVERTING_P (inherited_ctor);
1749 /* A constructor so declared has the same access as the corresponding
1750 constructor in X. */
1751 TREE_PRIVATE (fn) = TREE_PRIVATE (inherited_ctor);
1752 TREE_PROTECTED (fn) = TREE_PROTECTED (inherited_ctor);
1753 /* Copy constexpr from the inherited constructor even if the
1754 inheriting constructor doesn't satisfy the requirements. */
1755 constexpr_p = DECL_DECLARED_CONSTEXPR_P (inherited_ctor);
1757 /* Add the "this" parameter. */
1758 this_parm = build_this_parm (fn_type, TYPE_UNQUALIFIED);
1759 DECL_CHAIN (this_parm) = DECL_ARGUMENTS (fn);
1760 DECL_ARGUMENTS (fn) = this_parm;
1762 grokclassfn (type, fn, kind == sfk_destructor ? DTOR_FLAG : NO_SPECIAL);
1763 set_linkage_according_to_type (type, fn);
1764 rest_of_decl_compilation (fn, toplevel_bindings_p (), at_eof);
1765 DECL_IN_AGGR_P (fn) = 1;
1766 DECL_ARTIFICIAL (fn) = 1;
1767 DECL_DEFAULTED_FN (fn) = 1;
1768 if (cxx_dialect >= cxx11)
1770 DECL_DELETED_FN (fn) = deleted_p;
1771 DECL_DECLARED_CONSTEXPR_P (fn) = constexpr_p;
1773 DECL_EXTERNAL (fn) = true;
1774 DECL_NOT_REALLY_EXTERN (fn) = 1;
1775 DECL_DECLARED_INLINE_P (fn) = 1;
1776 gcc_assert (!TREE_USED (fn));
1778 /* Restore PROCESSING_TEMPLATE_DECL. */
1779 processing_template_decl = saved_processing_template_decl;
1781 if (inherited_ctor && TREE_CODE (inherited_ctor) == TEMPLATE_DECL)
1782 fn = add_inherited_template_parms (fn, inherited_ctor);
1784 /* Warn about calling a non-trivial move assignment in a virtual base. */
1785 if (kind == sfk_move_assignment && !deleted_p && !trivial_p
1786 && CLASSTYPE_VBASECLASSES (type))
1788 location_t loc = input_location;
1789 input_location = DECL_SOURCE_LOCATION (fn);
1790 synthesized_method_walk (type, kind, const_p,
1791 NULL, NULL, NULL, NULL, true,
1792 NULL_TREE, NULL_TREE);
1793 input_location = loc;
1796 return fn;
1799 /* Gives any errors about defaulted functions which need to be deferred
1800 until the containing class is complete. */
1802 void
1803 defaulted_late_check (tree fn)
1805 /* Complain about invalid signature for defaulted fn. */
1806 tree ctx = DECL_CONTEXT (fn);
1807 special_function_kind kind = special_function_p (fn);
1808 bool fn_const_p = (copy_fn_p (fn) == 2);
1809 tree implicit_fn = implicitly_declare_fn (kind, ctx, fn_const_p,
1810 NULL, NULL);
1811 tree eh_spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (implicit_fn));
1813 if (!same_type_p (TREE_TYPE (TREE_TYPE (fn)),
1814 TREE_TYPE (TREE_TYPE (implicit_fn)))
1815 || !compparms (TYPE_ARG_TYPES (TREE_TYPE (fn)),
1816 TYPE_ARG_TYPES (TREE_TYPE (implicit_fn))))
1818 error ("defaulted declaration %q+D", fn);
1819 error_at (DECL_SOURCE_LOCATION (fn),
1820 "does not match expected signature %qD", implicit_fn);
1823 /* 8.4.2/2: An explicitly-defaulted function (...) may have an explicit
1824 exception-specification only if it is compatible (15.4) with the
1825 exception-specification on the implicit declaration. If a function
1826 is explicitly defaulted on its first declaration, (...) it is
1827 implicitly considered to have the same exception-specification as if
1828 it had been implicitly declared. */
1829 if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)))
1831 maybe_instantiate_noexcept (fn);
1832 if (!comp_except_specs (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)),
1833 eh_spec, ce_normal))
1835 if (DECL_DEFAULTED_IN_CLASS_P (fn))
1837 DECL_DELETED_FN (fn) = true;
1838 eh_spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn));
1840 else
1841 error ("function %q+D defaulted on its redeclaration "
1842 "with an exception-specification that differs from "
1843 "the implicit declaration %q#D", fn, implicit_fn);
1846 if (DECL_DEFAULTED_IN_CLASS_P (fn))
1847 TREE_TYPE (fn) = build_exception_variant (TREE_TYPE (fn), eh_spec);
1849 if (DECL_DEFAULTED_IN_CLASS_P (fn)
1850 && DECL_DECLARED_CONSTEXPR_P (implicit_fn))
1852 /* Hmm...should we do this for out-of-class too? Should it be OK to
1853 add constexpr later like inline, rather than requiring
1854 declarations to match? */
1855 DECL_DECLARED_CONSTEXPR_P (fn) = true;
1856 if (kind == sfk_constructor)
1857 TYPE_HAS_CONSTEXPR_CTOR (ctx) = true;
1860 if (!DECL_DECLARED_CONSTEXPR_P (implicit_fn)
1861 && DECL_DECLARED_CONSTEXPR_P (fn))
1863 if (!CLASSTYPE_TEMPLATE_INSTANTIATION (ctx))
1865 error ("explicitly defaulted function %q+D cannot be declared "
1866 "as constexpr because the implicit declaration is not "
1867 "constexpr:", fn);
1868 explain_implicit_non_constexpr (fn);
1870 DECL_DECLARED_CONSTEXPR_P (fn) = false;
1873 if (DECL_DELETED_FN (implicit_fn))
1874 DECL_DELETED_FN (fn) = 1;
1877 /* Returns true iff FN can be explicitly defaulted, and gives any
1878 errors if defaulting FN is ill-formed. */
1880 bool
1881 defaultable_fn_check (tree fn)
1883 special_function_kind kind = sfk_none;
1885 if (template_parm_scope_p ())
1887 error ("a template cannot be defaulted");
1888 return false;
1891 if (DECL_CONSTRUCTOR_P (fn))
1893 if (FUNCTION_FIRST_USER_PARMTYPE (fn) == void_list_node)
1894 kind = sfk_constructor;
1895 else if (copy_fn_p (fn) > 0
1896 && (TREE_CHAIN (FUNCTION_FIRST_USER_PARMTYPE (fn))
1897 == void_list_node))
1898 kind = sfk_copy_constructor;
1899 else if (move_fn_p (fn))
1900 kind = sfk_move_constructor;
1902 else if (DECL_DESTRUCTOR_P (fn))
1903 kind = sfk_destructor;
1904 else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
1905 && DECL_OVERLOADED_OPERATOR_P (fn) == NOP_EXPR)
1907 if (copy_fn_p (fn))
1908 kind = sfk_copy_assignment;
1909 else if (move_fn_p (fn))
1910 kind = sfk_move_assignment;
1913 if (kind == sfk_none)
1915 error ("%qD cannot be defaulted", fn);
1916 return false;
1918 else
1920 for (tree t = FUNCTION_FIRST_USER_PARMTYPE (fn);
1921 t && t != void_list_node; t = TREE_CHAIN (t))
1922 if (TREE_PURPOSE (t))
1924 error ("defaulted function %q+D with default argument", fn);
1925 break;
1928 /* Avoid do_warn_unused_parameter warnings. */
1929 for (tree p = FUNCTION_FIRST_USER_PARM (fn); p; p = DECL_CHAIN (p))
1930 if (DECL_NAME (p))
1931 TREE_NO_WARNING (p) = 1;
1933 if (TYPE_BEING_DEFINED (DECL_CONTEXT (fn)))
1934 /* Defer checking. */;
1935 else if (!processing_template_decl)
1936 defaulted_late_check (fn);
1938 return true;
1942 /* Add an implicit declaration to TYPE for the kind of function
1943 indicated by SFK. Return the FUNCTION_DECL for the new implicit
1944 declaration. */
1946 tree
1947 lazily_declare_fn (special_function_kind sfk, tree type)
1949 tree fn;
1950 /* Whether or not the argument has a const reference type. */
1951 bool const_p = false;
1953 switch (sfk)
1955 case sfk_constructor:
1956 CLASSTYPE_LAZY_DEFAULT_CTOR (type) = 0;
1957 break;
1958 case sfk_copy_constructor:
1959 const_p = TYPE_HAS_CONST_COPY_CTOR (type);
1960 CLASSTYPE_LAZY_COPY_CTOR (type) = 0;
1961 break;
1962 case sfk_move_constructor:
1963 CLASSTYPE_LAZY_MOVE_CTOR (type) = 0;
1964 break;
1965 case sfk_copy_assignment:
1966 const_p = TYPE_HAS_CONST_COPY_ASSIGN (type);
1967 CLASSTYPE_LAZY_COPY_ASSIGN (type) = 0;
1968 break;
1969 case sfk_move_assignment:
1970 CLASSTYPE_LAZY_MOVE_ASSIGN (type) = 0;
1971 break;
1972 case sfk_destructor:
1973 CLASSTYPE_LAZY_DESTRUCTOR (type) = 0;
1974 break;
1975 default:
1976 gcc_unreachable ();
1979 /* Declare the function. */
1980 fn = implicitly_declare_fn (sfk, type, const_p, NULL, NULL);
1982 /* [class.copy]/8 If the class definition declares a move constructor or
1983 move assignment operator, the implicitly declared copy constructor is
1984 defined as deleted.... */
1985 if ((sfk == sfk_copy_assignment
1986 || sfk == sfk_copy_constructor)
1987 && (type_has_user_declared_move_constructor (type)
1988 || type_has_user_declared_move_assign (type)))
1989 DECL_DELETED_FN (fn) = true;
1991 /* A destructor may be virtual. */
1992 if (sfk == sfk_destructor
1993 || sfk == sfk_move_assignment
1994 || sfk == sfk_copy_assignment)
1995 check_for_override (fn, type);
1996 /* Add it to CLASSTYPE_METHOD_VEC. */
1997 add_method (type, fn, NULL_TREE);
1998 /* Add it to TYPE_METHODS. */
1999 if (sfk == sfk_destructor
2000 && DECL_VIRTUAL_P (fn)
2001 && abi_version_at_least (2))
2002 /* The ABI requires that a virtual destructor go at the end of the
2003 vtable. */
2004 TYPE_METHODS (type) = chainon (TYPE_METHODS (type), fn);
2005 else
2007 /* G++ 3.2 put the implicit destructor at the *beginning* of the
2008 TYPE_METHODS list, which cause the destructor to be emitted
2009 in an incorrect location in the vtable. */
2010 if (warn_abi && sfk == sfk_destructor && DECL_VIRTUAL_P (fn))
2011 warning (OPT_Wabi, "vtable layout for class %qT may not be ABI-compliant"
2012 "and may change in a future version of GCC due to "
2013 "implicit virtual destructor",
2014 type);
2015 DECL_CHAIN (fn) = TYPE_METHODS (type);
2016 TYPE_METHODS (type) = fn;
2018 maybe_add_class_template_decl_list (type, fn, /*friend_p=*/0);
2019 if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn)
2020 || DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn))
2021 /* Create appropriate clones. */
2022 clone_function_decl (fn, /*update_method_vec=*/true);
2024 return fn;
2027 /* Given a FUNCTION_DECL FN and a chain LIST, skip as many elements of LIST
2028 as there are artificial parms in FN. */
2030 tree
2031 skip_artificial_parms_for (const_tree fn, tree list)
2033 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
2034 list = TREE_CHAIN (list);
2035 else
2036 return list;
2038 if (DECL_HAS_IN_CHARGE_PARM_P (fn))
2039 list = TREE_CHAIN (list);
2040 if (DECL_HAS_VTT_PARM_P (fn))
2041 list = TREE_CHAIN (list);
2042 return list;
2045 /* Given a FUNCTION_DECL FN and a chain LIST, return the number of
2046 artificial parms in FN. */
2049 num_artificial_parms_for (const_tree fn)
2051 int count = 0;
2053 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
2054 count++;
2055 else
2056 return 0;
2058 if (DECL_HAS_IN_CHARGE_PARM_P (fn))
2059 count++;
2060 if (DECL_HAS_VTT_PARM_P (fn))
2061 count++;
2062 return count;
2066 #include "gt-cp-method.h"