c-common.c (c_common_nodes_and_builtins): Use cxx11 in lieu of cxx0x.
[official-gcc.git] / gcc / cp / method.c
blob4ac533eacf7237fae7b912884d579fc6c65219d6
1 /* Handle the hair of processing (but not expanding) inline functions.
2 Also manage function and variable name overloading.
3 Copyright (C) 1987-2013 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 "cp-tree.h"
30 #include "flags.h"
31 #include "toplev.h"
32 #include "tm_p.h"
33 #include "target.h"
34 #include "common/common-target.h"
35 #include "diagnostic.h"
36 #include "cgraph.h"
37 #include "gimple.h"
39 /* Various flags to control the mangling process. */
41 enum mangling_flags
43 /* No flags. */
44 mf_none = 0,
45 /* The thing we are presently mangling is part of a template type,
46 rather than a fully instantiated type. Therefore, we may see
47 complex expressions where we would normally expect to see a
48 simple integer constant. */
49 mf_maybe_uninstantiated = 1,
50 /* When mangling a numeric value, use the form `_XX_' (instead of
51 just `XX') if the value has more than one digit. */
52 mf_use_underscores_around_value = 2
55 typedef enum mangling_flags mangling_flags;
57 static void do_build_copy_assign (tree);
58 static void do_build_copy_constructor (tree);
59 static tree make_alias_for_thunk (tree);
61 /* Called once to initialize method.c. */
63 void
64 init_method (void)
66 init_mangle ();
69 /* Return a this or result adjusting thunk to FUNCTION. THIS_ADJUSTING
70 indicates whether it is a this or result adjusting thunk.
71 FIXED_OFFSET and VIRTUAL_OFFSET indicate how to do the adjustment
72 (see thunk_adjust). VIRTUAL_OFFSET can be NULL, but FIXED_OFFSET
73 never is. VIRTUAL_OFFSET is the /index/ into the vtable for this
74 adjusting thunks, we scale it to a byte offset. For covariant
75 thunks VIRTUAL_OFFSET is the virtual binfo. You must post process
76 the returned thunk with finish_thunk. */
78 tree
79 make_thunk (tree function, bool this_adjusting,
80 tree fixed_offset, tree virtual_offset)
82 HOST_WIDE_INT d;
83 tree thunk;
85 gcc_assert (TREE_CODE (function) == FUNCTION_DECL);
86 /* We can have this thunks to covariant thunks, but not vice versa. */
87 gcc_assert (!DECL_THIS_THUNK_P (function));
88 gcc_assert (!DECL_RESULT_THUNK_P (function) || this_adjusting);
90 /* Scale the VIRTUAL_OFFSET to be in terms of bytes. */
91 if (this_adjusting && virtual_offset)
92 virtual_offset
93 = size_binop (MULT_EXPR,
94 virtual_offset,
95 convert (ssizetype,
96 TYPE_SIZE_UNIT (vtable_entry_type)));
98 d = tree_low_cst (fixed_offset, 0);
100 /* See if we already have the thunk in question. For this_adjusting
101 thunks VIRTUAL_OFFSET will be an INTEGER_CST, for covariant thunks it
102 will be a BINFO. */
103 for (thunk = DECL_THUNKS (function); thunk; thunk = DECL_CHAIN (thunk))
104 if (DECL_THIS_THUNK_P (thunk) == this_adjusting
105 && THUNK_FIXED_OFFSET (thunk) == d
106 && !virtual_offset == !THUNK_VIRTUAL_OFFSET (thunk)
107 && (!virtual_offset
108 || (this_adjusting
109 ? tree_int_cst_equal (THUNK_VIRTUAL_OFFSET (thunk),
110 virtual_offset)
111 : THUNK_VIRTUAL_OFFSET (thunk) == virtual_offset)))
112 return thunk;
114 /* All thunks must be created before FUNCTION is actually emitted;
115 the ABI requires that all thunks be emitted together with the
116 function to which they transfer control. */
117 gcc_assert (!TREE_ASM_WRITTEN (function));
118 /* Likewise, we can only be adding thunks to a function declared in
119 the class currently being laid out. */
120 gcc_assert (TYPE_SIZE (DECL_CONTEXT (function))
121 && TYPE_BEING_DEFINED (DECL_CONTEXT (function)));
123 thunk = build_decl (DECL_SOURCE_LOCATION (function),
124 FUNCTION_DECL, NULL_TREE, TREE_TYPE (function));
125 DECL_LANG_SPECIFIC (thunk) = DECL_LANG_SPECIFIC (function);
126 cxx_dup_lang_specific_decl (thunk);
127 DECL_VIRTUAL_P (thunk) = true;
128 SET_DECL_THUNKS (thunk, NULL_TREE);
130 DECL_CONTEXT (thunk) = DECL_CONTEXT (function);
131 TREE_READONLY (thunk) = TREE_READONLY (function);
132 TREE_THIS_VOLATILE (thunk) = TREE_THIS_VOLATILE (function);
133 TREE_PUBLIC (thunk) = TREE_PUBLIC (function);
134 SET_DECL_THUNK_P (thunk, this_adjusting);
135 THUNK_TARGET (thunk) = function;
136 THUNK_FIXED_OFFSET (thunk) = d;
137 THUNK_VIRTUAL_OFFSET (thunk) = virtual_offset;
138 THUNK_ALIAS (thunk) = NULL_TREE;
140 DECL_INTERFACE_KNOWN (thunk) = 1;
141 DECL_NOT_REALLY_EXTERN (thunk) = 1;
142 DECL_COMDAT (thunk) = DECL_COMDAT (function);
143 DECL_SAVED_FUNCTION_DATA (thunk) = NULL;
144 /* The thunk itself is not a constructor or destructor, even if
145 the thing it is thunking to is. */
146 DECL_DESTRUCTOR_P (thunk) = 0;
147 DECL_CONSTRUCTOR_P (thunk) = 0;
148 DECL_EXTERNAL (thunk) = 1;
149 DECL_ARTIFICIAL (thunk) = 1;
150 /* The THUNK is not a pending inline, even if the FUNCTION is. */
151 DECL_PENDING_INLINE_P (thunk) = 0;
152 DECL_DECLARED_INLINE_P (thunk) = 0;
153 /* Nor is it a template instantiation. */
154 DECL_USE_TEMPLATE (thunk) = 0;
155 DECL_TEMPLATE_INFO (thunk) = NULL;
157 /* Add it to the list of thunks associated with FUNCTION. */
158 DECL_CHAIN (thunk) = DECL_THUNKS (function);
159 SET_DECL_THUNKS (function, thunk);
161 return thunk;
164 /* Finish THUNK, a thunk decl. */
166 void
167 finish_thunk (tree thunk)
169 tree function, name;
170 tree fixed_offset = ssize_int (THUNK_FIXED_OFFSET (thunk));
171 tree virtual_offset = THUNK_VIRTUAL_OFFSET (thunk);
173 gcc_assert (!DECL_NAME (thunk) && DECL_THUNK_P (thunk));
174 if (virtual_offset && DECL_RESULT_THUNK_P (thunk))
175 virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
176 function = THUNK_TARGET (thunk);
177 name = mangle_thunk (function, DECL_THIS_THUNK_P (thunk),
178 fixed_offset, virtual_offset);
180 /* We can end up with declarations of (logically) different
181 covariant thunks, that do identical adjustments. The two thunks
182 will be adjusting between within different hierarchies, which
183 happen to have the same layout. We must nullify one of them to
184 refer to the other. */
185 if (DECL_RESULT_THUNK_P (thunk))
187 tree cov_probe;
189 for (cov_probe = DECL_THUNKS (function);
190 cov_probe; cov_probe = DECL_CHAIN (cov_probe))
191 if (DECL_NAME (cov_probe) == name)
193 gcc_assert (!DECL_THUNKS (thunk));
194 THUNK_ALIAS (thunk) = (THUNK_ALIAS (cov_probe)
195 ? THUNK_ALIAS (cov_probe) : cov_probe);
196 break;
200 DECL_NAME (thunk) = name;
201 SET_DECL_ASSEMBLER_NAME (thunk, name);
204 static GTY (()) int thunk_labelno;
206 /* Create a static alias to target. */
208 tree
209 make_alias_for (tree target, tree newid)
211 tree alias = build_decl (DECL_SOURCE_LOCATION (target),
212 TREE_CODE (target), newid, TREE_TYPE (target));
213 DECL_LANG_SPECIFIC (alias) = DECL_LANG_SPECIFIC (target);
214 cxx_dup_lang_specific_decl (alias);
215 DECL_CONTEXT (alias) = NULL;
216 TREE_READONLY (alias) = TREE_READONLY (target);
217 TREE_THIS_VOLATILE (alias) = TREE_THIS_VOLATILE (target);
218 TREE_PUBLIC (alias) = 0;
219 DECL_INTERFACE_KNOWN (alias) = 1;
220 if (DECL_LANG_SPECIFIC (alias))
222 DECL_NOT_REALLY_EXTERN (alias) = 1;
223 DECL_USE_TEMPLATE (alias) = 0;
224 DECL_TEMPLATE_INFO (alias) = NULL;
226 DECL_EXTERNAL (alias) = 0;
227 DECL_ARTIFICIAL (alias) = 1;
228 DECL_TEMPLATE_INSTANTIATED (alias) = 0;
229 if (TREE_CODE (alias) == FUNCTION_DECL)
231 DECL_SAVED_FUNCTION_DATA (alias) = NULL;
232 DECL_DESTRUCTOR_P (alias) = 0;
233 DECL_CONSTRUCTOR_P (alias) = 0;
234 DECL_PENDING_INLINE_P (alias) = 0;
235 DECL_DECLARED_INLINE_P (alias) = 0;
236 DECL_INITIAL (alias) = error_mark_node;
237 DECL_ARGUMENTS (alias) = copy_list (DECL_ARGUMENTS (target));
239 else
240 TREE_STATIC (alias) = 1;
241 TREE_ADDRESSABLE (alias) = 1;
242 TREE_USED (alias) = 1;
243 SET_DECL_ASSEMBLER_NAME (alias, DECL_NAME (alias));
244 return alias;
247 static tree
248 make_alias_for_thunk (tree function)
250 tree alias;
251 char buf[256];
253 targetm.asm_out.generate_internal_label (buf, "LTHUNK", thunk_labelno);
254 thunk_labelno++;
256 alias = make_alias_for (function, get_identifier (buf));
258 if (!flag_syntax_only)
260 struct cgraph_node *funcn, *aliasn;
261 funcn = cgraph_get_node (function);
262 gcc_checking_assert (funcn);
263 aliasn = cgraph_same_body_alias (funcn, alias, function);
264 DECL_ASSEMBLER_NAME (function);
265 gcc_assert (aliasn != NULL);
268 return alias;
271 /* Emit the definition of a C++ multiple inheritance or covariant
272 return vtable thunk. If EMIT_P is nonzero, the thunk is emitted
273 immediately. */
275 void
276 use_thunk (tree thunk_fndecl, bool emit_p)
278 tree a, t, function, alias;
279 tree virtual_offset;
280 HOST_WIDE_INT fixed_offset, virtual_value;
281 bool this_adjusting = DECL_THIS_THUNK_P (thunk_fndecl);
282 struct cgraph_node *funcn, *thunk_node;
284 /* We should have called finish_thunk to give it a name. */
285 gcc_assert (DECL_NAME (thunk_fndecl));
287 /* We should never be using an alias, always refer to the
288 aliased thunk. */
289 gcc_assert (!THUNK_ALIAS (thunk_fndecl));
291 if (TREE_ASM_WRITTEN (thunk_fndecl))
292 return;
294 function = THUNK_TARGET (thunk_fndecl);
295 if (DECL_RESULT (thunk_fndecl))
296 /* We already turned this thunk into an ordinary function.
297 There's no need to process this thunk again. */
298 return;
300 if (DECL_THUNK_P (function))
301 /* The target is itself a thunk, process it now. */
302 use_thunk (function, emit_p);
304 /* Thunks are always addressable; they only appear in vtables. */
305 TREE_ADDRESSABLE (thunk_fndecl) = 1;
307 /* Figure out what function is being thunked to. It's referenced in
308 this translation unit. */
309 TREE_ADDRESSABLE (function) = 1;
310 mark_used (function);
311 if (!emit_p)
312 return;
314 if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function))
315 alias = make_alias_for_thunk (function);
316 else
317 alias = function;
319 fixed_offset = THUNK_FIXED_OFFSET (thunk_fndecl);
320 virtual_offset = THUNK_VIRTUAL_OFFSET (thunk_fndecl);
322 if (virtual_offset)
324 if (!this_adjusting)
325 virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
326 virtual_value = tree_low_cst (virtual_offset, /*pos=*/0);
327 gcc_assert (virtual_value);
329 else
330 virtual_value = 0;
332 /* And, if we need to emit the thunk, it's used. */
333 mark_used (thunk_fndecl);
334 /* This thunk is actually defined. */
335 DECL_EXTERNAL (thunk_fndecl) = 0;
336 /* The linkage of the function may have changed. FIXME in linkage
337 rewrite. */
338 gcc_assert (DECL_INTERFACE_KNOWN (function));
339 TREE_PUBLIC (thunk_fndecl) = TREE_PUBLIC (function);
340 DECL_VISIBILITY (thunk_fndecl) = DECL_VISIBILITY (function);
341 DECL_VISIBILITY_SPECIFIED (thunk_fndecl)
342 = DECL_VISIBILITY_SPECIFIED (function);
343 DECL_COMDAT (thunk_fndecl) = DECL_COMDAT (function);
344 DECL_WEAK (thunk_fndecl) = DECL_WEAK (function);
346 if (flag_syntax_only)
348 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
349 return;
352 push_to_top_level ();
354 if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function)
355 && targetm_common.have_named_sections)
357 resolve_unique_section (function, 0, flag_function_sections);
359 if (DECL_SECTION_NAME (function) != NULL && DECL_ONE_ONLY (function))
361 resolve_unique_section (thunk_fndecl, 0, flag_function_sections);
363 /* Output the thunk into the same section as function. */
364 DECL_SECTION_NAME (thunk_fndecl) = DECL_SECTION_NAME (function);
368 /* Set up cloned argument trees for the thunk. */
369 t = NULL_TREE;
370 for (a = DECL_ARGUMENTS (function); a; a = DECL_CHAIN (a))
372 tree x = copy_node (a);
373 DECL_CHAIN (x) = t;
374 DECL_CONTEXT (x) = thunk_fndecl;
375 SET_DECL_RTL (x, NULL);
376 DECL_HAS_VALUE_EXPR_P (x) = 0;
377 TREE_ADDRESSABLE (x) = 0;
378 t = x;
380 a = nreverse (t);
381 DECL_ARGUMENTS (thunk_fndecl) = a;
382 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
383 funcn = cgraph_get_node (function);
384 gcc_checking_assert (funcn);
385 thunk_node = cgraph_add_thunk (funcn, thunk_fndecl, function,
386 this_adjusting, fixed_offset, virtual_value,
387 virtual_offset, alias);
388 if (DECL_ONE_ONLY (function))
389 symtab_add_to_same_comdat_group ((symtab_node) thunk_node,
390 (symtab_node) funcn);
392 if (!this_adjusting
393 || !targetm.asm_out.can_output_mi_thunk (thunk_fndecl, fixed_offset,
394 virtual_value, alias))
396 /* If this is a covariant thunk, or we don't have the necessary
397 code for efficient thunks, generate a thunk function that
398 just makes a call to the real function. Unfortunately, this
399 doesn't work for varargs. */
401 if (varargs_function_p (function))
402 error ("generic thunk code fails for method %q#D which uses %<...%>",
403 function);
406 pop_from_top_level ();
409 /* Code for synthesizing methods which have default semantics defined. */
411 /* True iff CTYPE has a trivial SFK. */
413 static bool
414 type_has_trivial_fn (tree ctype, special_function_kind sfk)
416 switch (sfk)
418 case sfk_constructor:
419 return !TYPE_HAS_COMPLEX_DFLT (ctype);
420 case sfk_copy_constructor:
421 return !TYPE_HAS_COMPLEX_COPY_CTOR (ctype);
422 case sfk_move_constructor:
423 return !TYPE_HAS_COMPLEX_MOVE_CTOR (ctype);
424 case sfk_copy_assignment:
425 return !TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype);
426 case sfk_move_assignment:
427 return !TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype);
428 case sfk_destructor:
429 return !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype);
430 case sfk_inheriting_constructor:
431 return false;
432 default:
433 gcc_unreachable ();
437 /* Note that CTYPE has a non-trivial SFK even though we previously thought
438 it was trivial. */
440 static void
441 type_set_nontrivial_flag (tree ctype, special_function_kind sfk)
443 switch (sfk)
445 case sfk_constructor:
446 TYPE_HAS_COMPLEX_DFLT (ctype) = true;
447 return;
448 case sfk_copy_constructor:
449 TYPE_HAS_COMPLEX_COPY_CTOR (ctype) = true;
450 return;
451 case sfk_move_constructor:
452 TYPE_HAS_COMPLEX_MOVE_CTOR (ctype) = true;
453 return;
454 case sfk_copy_assignment:
455 TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype) = true;
456 return;
457 case sfk_move_assignment:
458 TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype) = true;
459 return;
460 case sfk_destructor:
461 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype) = true;
462 return;
463 case sfk_inheriting_constructor:
464 default:
465 gcc_unreachable ();
469 /* True iff FN is a trivial defaulted member function ([cd]tor, op=). */
471 bool
472 trivial_fn_p (tree fn)
474 if (!DECL_DEFAULTED_FN (fn))
475 return false;
477 /* If fn is a clone, get the primary variant. */
478 fn = DECL_ORIGIN (fn);
479 return type_has_trivial_fn (DECL_CONTEXT (fn), special_function_p (fn));
482 /* Subroutine of do_build_copy_constructor: Add a mem-initializer for BINFO
483 given the parameter or parameters PARM, possibly inherited constructor
484 base INH, or move flag MOVE_P. */
486 static tree
487 add_one_base_init (tree binfo, tree parm, bool move_p, tree inh,
488 tree member_init_list)
490 tree init;
491 if (inh)
493 /* An inheriting constructor only has a mem-initializer for
494 the base it inherits from. */
495 if (BINFO_TYPE (binfo) != inh)
496 return member_init_list;
498 tree *p = &init;
499 init = NULL_TREE;
500 for (; parm; parm = DECL_CHAIN (parm))
502 tree exp = convert_from_reference (parm);
503 if (TREE_CODE (TREE_TYPE (parm)) != REFERENCE_TYPE
504 || TYPE_REF_IS_RVALUE (TREE_TYPE (parm)))
505 exp = move (exp);
506 *p = build_tree_list (NULL_TREE, exp);
507 p = &TREE_CHAIN (*p);
510 else
512 init = build_base_path (PLUS_EXPR, parm, binfo, 1,
513 tf_warning_or_error);
514 if (move_p)
515 init = move (init);
516 init = build_tree_list (NULL_TREE, init);
518 return tree_cons (binfo, init, member_init_list);
521 /* Generate code for default X(X&) or X(X&&) constructor or an inheriting
522 constructor. */
524 static void
525 do_build_copy_constructor (tree fndecl)
527 tree parm = FUNCTION_FIRST_USER_PARM (fndecl);
528 bool move_p = DECL_MOVE_CONSTRUCTOR_P (fndecl);
529 bool trivial = trivial_fn_p (fndecl);
530 tree inh = DECL_INHERITED_CTOR_BASE (fndecl);
532 if (!inh)
533 parm = convert_from_reference (parm);
535 if (trivial
536 && is_empty_class (current_class_type))
537 /* Don't copy the padding byte; it might not have been allocated
538 if *this is a base subobject. */;
539 else if (trivial)
541 tree t = build2 (INIT_EXPR, void_type_node, current_class_ref, parm);
542 finish_expr_stmt (t);
544 else
546 tree fields = TYPE_FIELDS (current_class_type);
547 tree member_init_list = NULL_TREE;
548 int cvquals = cp_type_quals (TREE_TYPE (parm));
549 int i;
550 tree binfo, base_binfo;
551 tree init;
552 vec<tree, va_gc> *vbases;
554 /* Initialize all the base-classes with the parameter converted
555 to their type so that we get their copy constructor and not
556 another constructor that takes current_class_type. We must
557 deal with the binfo's directly as a direct base might be
558 inaccessible due to ambiguity. */
559 for (vbases = CLASSTYPE_VBASECLASSES (current_class_type), i = 0;
560 vec_safe_iterate (vbases, i, &binfo); i++)
562 member_init_list = add_one_base_init (binfo, parm, move_p, inh,
563 member_init_list);
566 for (binfo = TYPE_BINFO (current_class_type), i = 0;
567 BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
569 if (BINFO_VIRTUAL_P (base_binfo))
570 continue;
571 member_init_list = add_one_base_init (base_binfo, parm, move_p,
572 inh, member_init_list);
575 for (; fields; fields = DECL_CHAIN (fields))
577 tree field = fields;
578 tree expr_type;
580 if (TREE_CODE (field) != FIELD_DECL)
581 continue;
582 if (inh)
583 continue;
585 expr_type = TREE_TYPE (field);
586 if (DECL_NAME (field))
588 if (VFIELD_NAME_P (DECL_NAME (field)))
589 continue;
591 else if (ANON_AGGR_TYPE_P (expr_type) && TYPE_FIELDS (expr_type))
592 /* Just use the field; anonymous types can't have
593 nontrivial copy ctors or assignment ops or this
594 function would be deleted. */;
595 else
596 continue;
598 /* Compute the type of "init->field". If the copy-constructor
599 parameter is, for example, "const S&", and the type of
600 the field is "T", then the type will usually be "const
601 T". (There are no cv-qualified variants of reference
602 types.) */
603 if (TREE_CODE (expr_type) != REFERENCE_TYPE)
605 int quals = cvquals;
607 if (DECL_MUTABLE_P (field))
608 quals &= ~TYPE_QUAL_CONST;
609 quals |= cp_type_quals (expr_type);
610 expr_type = cp_build_qualified_type (expr_type, quals);
613 init = build3 (COMPONENT_REF, expr_type, parm, field, NULL_TREE);
614 if (move_p && TREE_CODE (expr_type) != REFERENCE_TYPE
615 /* 'move' breaks bit-fields, and has no effect for scalars. */
616 && !scalarish_type_p (expr_type))
617 init = move (init);
618 init = build_tree_list (NULL_TREE, init);
620 member_init_list = tree_cons (field, init, member_init_list);
622 finish_mem_initializers (member_init_list);
626 static void
627 do_build_copy_assign (tree fndecl)
629 tree parm = DECL_CHAIN (DECL_ARGUMENTS (fndecl));
630 tree compound_stmt;
631 bool move_p = move_fn_p (fndecl);
632 bool trivial = trivial_fn_p (fndecl);
633 int flags = LOOKUP_NORMAL | LOOKUP_NONVIRTUAL | LOOKUP_DEFAULTED;
635 compound_stmt = begin_compound_stmt (0);
636 parm = convert_from_reference (parm);
638 if (trivial
639 && is_empty_class (current_class_type))
640 /* Don't copy the padding byte; it might not have been allocated
641 if *this is a base subobject. */;
642 else if (trivial)
644 tree t = build2 (MODIFY_EXPR, void_type_node, current_class_ref, parm);
645 finish_expr_stmt (t);
647 else
649 tree fields;
650 int cvquals = cp_type_quals (TREE_TYPE (parm));
651 int i;
652 tree binfo, base_binfo;
654 /* Assign to each of the direct base classes. */
655 for (binfo = TYPE_BINFO (current_class_type), i = 0;
656 BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
658 tree converted_parm;
659 vec<tree, va_gc> *parmvec;
661 /* We must convert PARM directly to the base class
662 explicitly since the base class may be ambiguous. */
663 converted_parm = build_base_path (PLUS_EXPR, parm, base_binfo, 1,
664 tf_warning_or_error);
665 if (move_p)
666 converted_parm = move (converted_parm);
667 /* Call the base class assignment operator. */
668 parmvec = make_tree_vector_single (converted_parm);
669 finish_expr_stmt
670 (build_special_member_call (current_class_ref,
671 ansi_assopname (NOP_EXPR),
672 &parmvec,
673 base_binfo,
674 flags,
675 tf_warning_or_error));
676 release_tree_vector (parmvec);
679 /* Assign to each of the non-static data members. */
680 for (fields = TYPE_FIELDS (current_class_type);
681 fields;
682 fields = DECL_CHAIN (fields))
684 tree comp = current_class_ref;
685 tree init = parm;
686 tree field = fields;
687 tree expr_type;
688 int quals;
690 if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field))
691 continue;
693 expr_type = TREE_TYPE (field);
695 if (CP_TYPE_CONST_P (expr_type))
697 error ("non-static const member %q#D, can%'t use default "
698 "assignment operator", field);
699 continue;
701 else if (TREE_CODE (expr_type) == REFERENCE_TYPE)
703 error ("non-static reference member %q#D, can%'t use "
704 "default assignment operator", field);
705 continue;
708 if (DECL_NAME (field))
710 if (VFIELD_NAME_P (DECL_NAME (field)))
711 continue;
713 else if (ANON_AGGR_TYPE_P (expr_type)
714 && TYPE_FIELDS (expr_type) != NULL_TREE)
715 /* Just use the field; anonymous types can't have
716 nontrivial copy ctors or assignment ops or this
717 function would be deleted. */;
718 else
719 continue;
721 comp = build3 (COMPONENT_REF, expr_type, comp, field, NULL_TREE);
723 /* Compute the type of init->field */
724 quals = cvquals;
725 if (DECL_MUTABLE_P (field))
726 quals &= ~TYPE_QUAL_CONST;
727 expr_type = cp_build_qualified_type (expr_type, quals);
729 init = build3 (COMPONENT_REF, expr_type, init, field, NULL_TREE);
730 if (move_p && TREE_CODE (expr_type) != REFERENCE_TYPE
731 /* 'move' breaks bit-fields, and has no effect for scalars. */
732 && !scalarish_type_p (expr_type))
733 init = move (init);
735 if (DECL_NAME (field))
736 init = cp_build_modify_expr (comp, NOP_EXPR, init,
737 tf_warning_or_error);
738 else
739 init = build2 (MODIFY_EXPR, TREE_TYPE (comp), comp, init);
740 finish_expr_stmt (init);
743 finish_return_stmt (current_class_ref);
744 finish_compound_stmt (compound_stmt);
747 /* Synthesize FNDECL, a non-static member function. */
749 void
750 synthesize_method (tree fndecl)
752 bool nested = (current_function_decl != NULL_TREE);
753 tree context = decl_function_context (fndecl);
754 bool need_body = true;
755 tree stmt;
756 location_t save_input_location = input_location;
757 int error_count = errorcount;
758 int warning_count = warningcount + werrorcount;
760 /* Reset the source location, we might have been previously
761 deferred, and thus have saved where we were first needed. */
762 DECL_SOURCE_LOCATION (fndecl)
763 = DECL_SOURCE_LOCATION (TYPE_NAME (DECL_CONTEXT (fndecl)));
765 /* If we've been asked to synthesize a clone, just synthesize the
766 cloned function instead. Doing so will automatically fill in the
767 body for the clone. */
768 if (DECL_CLONED_FUNCTION_P (fndecl))
769 fndecl = DECL_CLONED_FUNCTION (fndecl);
771 /* We may be in the middle of deferred access check. Disable
772 it now. */
773 push_deferring_access_checks (dk_no_deferred);
775 if (! context)
776 push_to_top_level ();
777 else if (nested)
778 push_function_context ();
780 input_location = DECL_SOURCE_LOCATION (fndecl);
782 start_preparsed_function (fndecl, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED);
783 stmt = begin_function_body ();
785 if (DECL_OVERLOADED_OPERATOR_P (fndecl) == NOP_EXPR)
787 do_build_copy_assign (fndecl);
788 need_body = false;
790 else if (DECL_CONSTRUCTOR_P (fndecl))
792 tree arg_chain = FUNCTION_FIRST_USER_PARMTYPE (fndecl);
793 if (arg_chain != void_list_node)
794 do_build_copy_constructor (fndecl);
795 else
796 finish_mem_initializers (NULL_TREE);
799 /* If we haven't yet generated the body of the function, just
800 generate an empty compound statement. */
801 if (need_body)
803 tree compound_stmt;
804 compound_stmt = begin_compound_stmt (BCS_FN_BODY);
805 finish_compound_stmt (compound_stmt);
808 finish_function_body (stmt);
809 expand_or_defer_fn (finish_function (0));
811 input_location = save_input_location;
813 if (! context)
814 pop_from_top_level ();
815 else if (nested)
816 pop_function_context ();
818 pop_deferring_access_checks ();
820 if (error_count != errorcount || warning_count != warningcount + werrorcount)
821 inform (input_location, "synthesized method %qD first required here ",
822 fndecl);
825 /* Build a reference to type TYPE with cv-quals QUALS, which is an
826 rvalue if RVALUE is true. */
828 static tree
829 build_stub_type (tree type, int quals, bool rvalue)
831 tree argtype = cp_build_qualified_type (type, quals);
832 return cp_build_reference_type (argtype, rvalue);
835 /* Build a dummy glvalue from dereferencing a dummy reference of type
836 REFTYPE. */
838 static tree
839 build_stub_object (tree reftype)
841 tree stub = build1 (NOP_EXPR, reftype, integer_one_node);
842 return convert_from_reference (stub);
845 /* Determine which function will be called when looking up NAME in TYPE,
846 called with a single ARGTYPE argument, or no argument if ARGTYPE is
847 null. FLAGS and COMPLAIN are as for build_new_method_call.
849 Returns a FUNCTION_DECL if all is well.
850 Returns NULL_TREE if overload resolution failed.
851 Returns error_mark_node if the chosen function cannot be called. */
853 static tree
854 locate_fn_flags (tree type, tree name, tree argtype, int flags,
855 tsubst_flags_t complain)
857 tree ob, fn, fns, binfo, rval;
858 vec<tree, va_gc> *args;
860 if (TYPE_P (type))
861 binfo = TYPE_BINFO (type);
862 else
864 binfo = type;
865 type = BINFO_TYPE (binfo);
868 ob = build_stub_object (cp_build_reference_type (type, false));
869 args = make_tree_vector ();
870 if (argtype)
872 if (TREE_CODE (argtype) == TREE_LIST)
874 for (tree elt = argtype; elt != void_list_node;
875 elt = TREE_CHAIN (elt))
877 tree type = TREE_VALUE (elt);
878 if (TREE_CODE (type) != REFERENCE_TYPE)
879 type = cp_build_reference_type (type, /*rval*/true);
880 tree arg = build_stub_object (type);
881 vec_safe_push (args, arg);
884 else
886 tree arg = build_stub_object (argtype);
887 args->quick_push (arg);
891 fns = lookup_fnfields (binfo, name, 0);
892 rval = build_new_method_call (ob, fns, &args, binfo, flags, &fn, complain);
894 release_tree_vector (args);
895 if (fn && rval == error_mark_node)
896 return rval;
897 else
898 return fn;
901 /* Locate the dtor of TYPE. */
903 tree
904 get_dtor (tree type, tsubst_flags_t complain)
906 tree fn = locate_fn_flags (type, complete_dtor_identifier, NULL_TREE,
907 LOOKUP_NORMAL, complain);
908 if (fn == error_mark_node)
909 return NULL_TREE;
910 return fn;
913 /* Locate the default ctor of TYPE. */
915 tree
916 locate_ctor (tree type)
918 tree fn;
920 push_deferring_access_checks (dk_no_check);
921 fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
922 LOOKUP_SPECULATIVE, tf_none);
923 pop_deferring_access_checks ();
924 if (fn == error_mark_node)
925 return NULL_TREE;
926 return fn;
929 /* Likewise, but give any appropriate errors. */
931 tree
932 get_default_ctor (tree type)
934 tree fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
935 LOOKUP_NORMAL, tf_warning_or_error);
936 if (fn == error_mark_node)
937 return NULL_TREE;
938 return fn;
941 /* Locate the copy ctor of TYPE. */
943 tree
944 get_copy_ctor (tree type, tsubst_flags_t complain)
946 int quals = (TYPE_HAS_CONST_COPY_CTOR (type)
947 ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
948 tree argtype = build_stub_type (type, quals, false);
949 tree fn = locate_fn_flags (type, complete_ctor_identifier, argtype,
950 LOOKUP_NORMAL, complain);
951 if (fn == error_mark_node)
952 return NULL_TREE;
953 return fn;
956 /* Locate the copy assignment operator of TYPE. */
958 tree
959 get_copy_assign (tree type)
961 int quals = (TYPE_HAS_CONST_COPY_ASSIGN (type)
962 ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
963 tree argtype = build_stub_type (type, quals, false);
964 tree fn = locate_fn_flags (type, ansi_assopname (NOP_EXPR), argtype,
965 LOOKUP_NORMAL, tf_warning_or_error);
966 if (fn == error_mark_node)
967 return NULL_TREE;
968 return fn;
971 /* Subroutine of synthesized_method_walk. Update SPEC_P, TRIVIAL_P and
972 DELETED_P or give an error message MSG with argument ARG. */
974 static void
975 process_subob_fn (tree fn, tree *spec_p, bool *trivial_p,
976 bool *deleted_p, bool *constexpr_p,
977 bool diag, tree arg)
979 if (!fn || fn == error_mark_node)
980 goto bad;
982 if (spec_p)
984 tree raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn));
985 *spec_p = merge_exception_specifiers (*spec_p, raises, fn);
988 if (!trivial_fn_p (fn))
990 if (trivial_p)
991 *trivial_p = false;
992 if (TREE_CODE (arg) == FIELD_DECL
993 && TREE_CODE (DECL_CONTEXT (arg)) == UNION_TYPE)
995 if (deleted_p)
996 *deleted_p = true;
997 if (diag)
998 error ("union member %q+D with non-trivial %qD", arg, fn);
1002 if (constexpr_p && !DECL_DECLARED_CONSTEXPR_P (fn))
1004 *constexpr_p = false;
1005 if (diag)
1007 inform (0, "defaulted constructor calls non-constexpr "
1008 "%q+D", fn);
1009 explain_invalid_constexpr_fn (fn);
1013 return;
1015 bad:
1016 if (deleted_p)
1017 *deleted_p = true;
1020 /* Subroutine of synthesized_method_walk to allow recursion into anonymous
1021 aggregates. */
1023 static void
1024 walk_field_subobs (tree fields, tree fnname, special_function_kind sfk,
1025 int quals, bool copy_arg_p, bool move_p,
1026 bool assign_p, tree *spec_p, bool *trivial_p,
1027 bool *deleted_p, bool *constexpr_p,
1028 bool diag, int flags, tsubst_flags_t complain)
1030 tree field;
1031 for (field = fields; field; field = DECL_CHAIN (field))
1033 tree mem_type, argtype, rval;
1035 if (TREE_CODE (field) != FIELD_DECL
1036 || DECL_ARTIFICIAL (field))
1037 continue;
1039 mem_type = strip_array_types (TREE_TYPE (field));
1040 if (assign_p)
1042 bool bad = true;
1043 if (CP_TYPE_CONST_P (mem_type) && !CLASS_TYPE_P (mem_type))
1045 if (diag)
1046 error ("non-static const member %q#D, can%'t use default "
1047 "assignment operator", field);
1049 else if (TREE_CODE (mem_type) == REFERENCE_TYPE)
1051 if (diag)
1052 error ("non-static reference member %q#D, can%'t use "
1053 "default assignment operator", field);
1055 else
1056 bad = false;
1058 if (bad && deleted_p)
1059 *deleted_p = true;
1061 else if (sfk == sfk_constructor)
1063 bool bad;
1065 if (DECL_INITIAL (field))
1067 if (diag && DECL_INITIAL (field) == error_mark_node)
1068 inform (0, "initializer for %q+#D is invalid", field);
1069 if (trivial_p)
1070 *trivial_p = false;
1071 #if 0
1072 /* Core 1351: If the field has an NSDMI that could throw, the
1073 default constructor is noexcept(false). FIXME this is
1074 broken by deferred parsing and 1360 saying we can't lazily
1075 declare a non-trivial default constructor. Also this
1076 needs to do deferred instantiation. Disable until the
1077 conflict between 1351 and 1360 is resolved. */
1078 if (spec_p && !expr_noexcept_p (DECL_INITIAL (field), complain))
1079 *spec_p = noexcept_false_spec;
1080 #endif
1082 /* Don't do the normal processing. */
1083 continue;
1086 bad = false;
1087 if (CP_TYPE_CONST_P (mem_type)
1088 && default_init_uninitialized_part (mem_type))
1090 if (diag)
1091 error ("uninitialized non-static const member %q#D",
1092 field);
1093 bad = true;
1095 else if (TREE_CODE (mem_type) == REFERENCE_TYPE)
1097 if (diag)
1098 error ("uninitialized non-static reference member %q#D",
1099 field);
1100 bad = true;
1103 if (bad && deleted_p)
1104 *deleted_p = true;
1106 /* For an implicitly-defined default constructor to be constexpr,
1107 every member must have a user-provided default constructor or
1108 an explicit initializer. */
1109 if (constexpr_p && !CLASS_TYPE_P (mem_type)
1110 && TREE_CODE (DECL_CONTEXT (field)) != UNION_TYPE)
1112 *constexpr_p = false;
1113 if (diag)
1114 inform (0, "defaulted default constructor does not "
1115 "initialize %q+#D", field);
1118 else if (sfk == sfk_copy_constructor)
1120 /* 12.8p11b5 */
1121 if (TREE_CODE (mem_type) == REFERENCE_TYPE
1122 && TYPE_REF_IS_RVALUE (mem_type))
1124 if (diag)
1125 error ("copying non-static data member %q#D of rvalue "
1126 "reference type", field);
1127 if (deleted_p)
1128 *deleted_p = true;
1132 if (!CLASS_TYPE_P (mem_type))
1133 continue;
1135 if (ANON_AGGR_TYPE_P (mem_type))
1137 walk_field_subobs (TYPE_FIELDS (mem_type), fnname, sfk, quals,
1138 copy_arg_p, move_p, assign_p, spec_p, trivial_p,
1139 deleted_p, constexpr_p,
1140 diag, flags, complain);
1141 continue;
1144 if (copy_arg_p)
1146 int mem_quals = cp_type_quals (mem_type) | quals;
1147 if (DECL_MUTABLE_P (field))
1148 mem_quals &= ~TYPE_QUAL_CONST;
1149 argtype = build_stub_type (mem_type, mem_quals, move_p);
1151 else
1152 argtype = NULL_TREE;
1154 rval = locate_fn_flags (mem_type, fnname, argtype, flags, complain);
1156 process_subob_fn (rval, spec_p, trivial_p, deleted_p,
1157 constexpr_p, diag, field);
1161 /* The caller wants to generate an implicit declaration of SFK for CTYPE
1162 which is const if relevant and CONST_P is set. If spec_p, trivial_p and
1163 deleted_p are non-null, set their referent appropriately. If diag is
1164 true, we're either being called from maybe_explain_implicit_delete to
1165 give errors, or if constexpr_p is non-null, from
1166 explain_invalid_constexpr_fn. */
1168 static void
1169 synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p,
1170 tree *spec_p, bool *trivial_p, bool *deleted_p,
1171 bool *constexpr_p, bool diag,
1172 tree inherited_base, tree inherited_parms)
1174 tree binfo, base_binfo, scope, fnname, rval, argtype;
1175 bool move_p, copy_arg_p, assign_p, expected_trivial, check_vdtor;
1176 vec<tree, va_gc> *vbases;
1177 int i, quals, flags;
1178 tsubst_flags_t complain;
1179 bool ctor_p;
1181 if (spec_p)
1182 *spec_p = (cxx_dialect >= cxx11 ? noexcept_true_spec : empty_except_spec);
1184 if (deleted_p)
1186 /* "The closure type associated with a lambda-expression has a deleted
1187 default constructor and a deleted copy assignment operator."
1188 This is diagnosed in maybe_explain_implicit_delete. */
1189 if (LAMBDA_TYPE_P (ctype)
1190 && (sfk == sfk_constructor
1191 || sfk == sfk_copy_assignment))
1193 *deleted_p = true;
1194 return;
1197 *deleted_p = false;
1200 ctor_p = false;
1201 assign_p = false;
1202 check_vdtor = false;
1203 switch (sfk)
1205 case sfk_move_assignment:
1206 case sfk_copy_assignment:
1207 assign_p = true;
1208 fnname = ansi_assopname (NOP_EXPR);
1209 break;
1211 case sfk_destructor:
1212 check_vdtor = true;
1213 /* The synthesized method will call base dtors, but check complete
1214 here to avoid having to deal with VTT. */
1215 fnname = complete_dtor_identifier;
1216 break;
1218 case sfk_constructor:
1219 case sfk_move_constructor:
1220 case sfk_copy_constructor:
1221 case sfk_inheriting_constructor:
1222 ctor_p = true;
1223 fnname = complete_ctor_identifier;
1224 break;
1226 default:
1227 gcc_unreachable ();
1230 gcc_assert ((sfk == sfk_inheriting_constructor)
1231 == (inherited_base != NULL_TREE));
1233 /* If that user-written default constructor would satisfy the
1234 requirements of a constexpr constructor (7.1.5), the
1235 implicitly-defined default constructor is constexpr. */
1236 if (constexpr_p)
1237 *constexpr_p = ctor_p;
1239 move_p = false;
1240 switch (sfk)
1242 case sfk_constructor:
1243 case sfk_destructor:
1244 case sfk_inheriting_constructor:
1245 copy_arg_p = false;
1246 break;
1248 case sfk_move_constructor:
1249 case sfk_move_assignment:
1250 move_p = true;
1251 case sfk_copy_constructor:
1252 case sfk_copy_assignment:
1253 copy_arg_p = true;
1254 break;
1256 default:
1257 gcc_unreachable ();
1260 expected_trivial = type_has_trivial_fn (ctype, sfk);
1261 if (trivial_p)
1262 *trivial_p = expected_trivial;
1264 /* The TYPE_HAS_COMPLEX_* flags tell us about constraints from base
1265 class versions and other properties of the type. But a subobject
1266 class can be trivially copyable and yet have overload resolution
1267 choose a template constructor for initialization, depending on
1268 rvalueness and cv-quals. So we can't exit early for copy/move
1269 methods in C++0x. The same considerations apply in C++98/03, but
1270 there the definition of triviality does not consider overload
1271 resolution, so a constructor can be trivial even if it would otherwise
1272 call a non-trivial constructor. */
1273 if (expected_trivial
1274 && (!copy_arg_p || cxx_dialect < cxx11))
1276 if (constexpr_p && sfk == sfk_constructor)
1278 bool cx = trivial_default_constructor_is_constexpr (ctype);
1279 *constexpr_p = cx;
1280 if (diag && !cx && TREE_CODE (ctype) == UNION_TYPE)
1281 /* A trivial constructor doesn't have any NSDMI. */
1282 inform (input_location, "defaulted default constructor does "
1283 "not initialize any non-static data member");
1285 if (!diag)
1286 return;
1289 ++cp_unevaluated_operand;
1290 ++c_inhibit_evaluation_warnings;
1291 push_deferring_access_checks (dk_no_deferred);
1293 scope = push_scope (ctype);
1295 flags = LOOKUP_NORMAL|LOOKUP_SPECULATIVE;
1296 if (!inherited_base)
1297 flags |= LOOKUP_DEFAULTED;
1299 complain = diag ? tf_warning_or_error : tf_none;
1301 if (const_p)
1302 quals = TYPE_QUAL_CONST;
1303 else
1304 quals = TYPE_UNQUALIFIED;
1305 argtype = NULL_TREE;
1307 for (binfo = TYPE_BINFO (ctype), i = 0;
1308 BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
1310 tree basetype = BINFO_TYPE (base_binfo);
1312 if (!assign_p && BINFO_VIRTUAL_P (base_binfo))
1313 /* We'll handle virtual bases below. */
1314 continue;
1316 if (copy_arg_p)
1317 argtype = build_stub_type (basetype, quals, move_p);
1318 else if (basetype == inherited_base)
1319 argtype = inherited_parms;
1320 rval = locate_fn_flags (base_binfo, fnname, argtype, flags, complain);
1321 if (inherited_base)
1322 argtype = NULL_TREE;
1324 process_subob_fn (rval, spec_p, trivial_p, deleted_p,
1325 constexpr_p, diag, basetype);
1326 if (ctor_p && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (basetype))
1328 /* In a constructor we also need to check the subobject
1329 destructors for cleanup of partially constructed objects. */
1330 rval = locate_fn_flags (base_binfo, complete_dtor_identifier,
1331 NULL_TREE, flags, complain);
1332 /* Note that we don't pass down trivial_p; the subobject
1333 destructors don't affect triviality of the constructor. Nor
1334 do they affect constexpr-ness (a constant expression doesn't
1335 throw) or exception-specification (a throw from one of the
1336 dtors would be a double-fault). */
1337 process_subob_fn (rval, NULL, NULL,
1338 deleted_p, NULL, false,
1339 basetype);
1342 if (check_vdtor && type_has_virtual_destructor (basetype))
1344 rval = locate_fn_flags (ctype, ansi_opname (DELETE_EXPR),
1345 ptr_type_node, flags, complain);
1346 /* Unlike for base ctor/op=/dtor, for operator delete it's fine
1347 to have a null rval (no class-specific op delete). */
1348 if (rval && rval == error_mark_node && deleted_p)
1349 *deleted_p = true;
1350 check_vdtor = false;
1353 if (diag && assign_p && move_p
1354 && BINFO_VIRTUAL_P (base_binfo)
1355 && rval && TREE_CODE (rval) == FUNCTION_DECL
1356 && move_fn_p (rval) && !trivial_fn_p (rval)
1357 && vbase_has_user_provided_move_assign (basetype))
1358 warning (OPT_Wvirtual_move_assign,
1359 "defaulted move assignment for %qT calls a non-trivial "
1360 "move assignment operator for virtual base %qT",
1361 ctype, basetype);
1364 vbases = CLASSTYPE_VBASECLASSES (ctype);
1365 if (vbases == NULL)
1366 /* No virtual bases to worry about. */;
1367 else if (!assign_p)
1369 if (constexpr_p)
1370 *constexpr_p = false;
1371 FOR_EACH_VEC_ELT (*vbases, i, base_binfo)
1373 tree basetype = BINFO_TYPE (base_binfo);
1374 if (copy_arg_p)
1375 argtype = build_stub_type (basetype, quals, move_p);
1376 rval = locate_fn_flags (base_binfo, fnname, argtype, flags, complain);
1378 process_subob_fn (rval, spec_p, trivial_p, deleted_p,
1379 constexpr_p, diag, basetype);
1380 if (ctor_p && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (basetype))
1382 rval = locate_fn_flags (base_binfo, complete_dtor_identifier,
1383 NULL_TREE, flags, complain);
1384 process_subob_fn (rval, NULL, NULL,
1385 deleted_p, NULL, false,
1386 basetype);
1391 /* Now handle the non-static data members. */
1392 walk_field_subobs (TYPE_FIELDS (ctype), fnname, sfk, quals,
1393 copy_arg_p, move_p, assign_p, spec_p, trivial_p,
1394 deleted_p, constexpr_p,
1395 diag, flags, complain);
1396 if (ctor_p)
1397 walk_field_subobs (TYPE_FIELDS (ctype), complete_dtor_identifier,
1398 sfk_destructor, TYPE_UNQUALIFIED, false,
1399 false, false, NULL, NULL,
1400 deleted_p, NULL,
1401 false, flags, complain);
1403 pop_scope (scope);
1405 pop_deferring_access_checks ();
1406 --cp_unevaluated_operand;
1407 --c_inhibit_evaluation_warnings;
1410 /* DECL is a deleted function. If it's implicitly deleted, explain why and
1411 return true; else return false. */
1413 bool
1414 maybe_explain_implicit_delete (tree decl)
1416 /* If decl is a clone, get the primary variant. */
1417 decl = DECL_ORIGIN (decl);
1418 gcc_assert (DECL_DELETED_FN (decl));
1419 if (DECL_DEFAULTED_FN (decl))
1421 /* Not marked GTY; it doesn't need to be GC'd or written to PCH. */
1422 static struct pointer_set_t *explained;
1424 special_function_kind sfk;
1425 location_t loc;
1426 bool informed;
1427 tree ctype;
1429 if (!explained)
1430 explained = pointer_set_create ();
1431 if (pointer_set_insert (explained, decl))
1432 return true;
1434 sfk = special_function_p (decl);
1435 ctype = DECL_CONTEXT (decl);
1436 loc = input_location;
1437 input_location = DECL_SOURCE_LOCATION (decl);
1439 informed = false;
1440 if (LAMBDA_TYPE_P (ctype))
1442 informed = true;
1443 if (sfk == sfk_constructor)
1444 inform (DECL_SOURCE_LOCATION (decl),
1445 "a lambda closure type has a deleted default constructor");
1446 else if (sfk == sfk_copy_assignment)
1447 inform (DECL_SOURCE_LOCATION (decl),
1448 "a lambda closure type has a deleted copy assignment operator");
1449 else
1450 informed = false;
1452 else if (DECL_ARTIFICIAL (decl)
1453 && (sfk == sfk_copy_assignment
1454 || sfk == sfk_copy_constructor)
1455 && (type_has_user_declared_move_constructor (ctype)
1456 || type_has_user_declared_move_assign (ctype)))
1458 inform (0, "%q+#D is implicitly declared as deleted because %qT "
1459 "declares a move constructor or move assignment operator",
1460 decl, ctype);
1461 informed = true;
1463 if (!informed)
1465 tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
1466 tree parm_type = TREE_VALUE (parms);
1467 bool const_p = CP_TYPE_CONST_P (non_reference (parm_type));
1468 tree scope = push_scope (ctype);
1469 inform (0, "%q+#D is implicitly deleted because the default "
1470 "definition would be ill-formed:", decl);
1471 pop_scope (scope);
1472 synthesized_method_walk (ctype, sfk, const_p,
1473 NULL, NULL, NULL, NULL, true,
1474 DECL_INHERITED_CTOR_BASE (decl), parms);
1477 input_location = loc;
1478 return true;
1480 return false;
1483 /* DECL is a defaulted function which was declared constexpr. Explain why
1484 it can't be constexpr. */
1486 void
1487 explain_implicit_non_constexpr (tree decl)
1489 tree parm_type = TREE_VALUE (FUNCTION_FIRST_USER_PARMTYPE (decl));
1490 bool const_p = CP_TYPE_CONST_P (non_reference (parm_type));
1491 bool dummy;
1492 synthesized_method_walk (DECL_CLASS_CONTEXT (decl),
1493 special_function_p (decl), const_p,
1494 NULL, NULL, NULL, &dummy, true,
1495 NULL_TREE, NULL_TREE);
1498 /* DECL is an instantiation of an inheriting constructor template. Deduce
1499 the correct exception-specification and deletedness for this particular
1500 specialization. */
1502 void
1503 deduce_inheriting_ctor (tree decl)
1505 gcc_assert (DECL_INHERITED_CTOR_BASE (decl));
1506 tree spec;
1507 bool trivial, constexpr_, deleted;
1508 synthesized_method_walk (DECL_CONTEXT (decl), sfk_inheriting_constructor,
1509 false, &spec, &trivial, &deleted, &constexpr_,
1510 /*diag*/false,
1511 DECL_INHERITED_CTOR_BASE (decl),
1512 FUNCTION_FIRST_USER_PARMTYPE (decl));
1513 DECL_DELETED_FN (decl) = deleted;
1514 TREE_TYPE (decl) = build_exception_variant (TREE_TYPE (decl), spec);
1517 /* Implicitly declare the special function indicated by KIND, as a
1518 member of TYPE. For copy constructors and assignment operators,
1519 CONST_P indicates whether these functions should take a const
1520 reference argument or a non-const reference. Returns the
1521 FUNCTION_DECL for the implicitly declared function. */
1523 tree
1524 implicitly_declare_fn (special_function_kind kind, tree type,
1525 bool const_p, tree inherited_ctor,
1526 tree inherited_parms)
1528 tree fn;
1529 tree parameter_types = void_list_node;
1530 tree return_type;
1531 tree fn_type;
1532 tree raises = empty_except_spec;
1533 tree rhs_parm_type = NULL_TREE;
1534 tree this_parm;
1535 tree name;
1536 HOST_WIDE_INT saved_processing_template_decl;
1537 bool deleted_p;
1538 bool constexpr_p;
1540 /* Because we create declarations for implicitly declared functions
1541 lazily, we may be creating the declaration for a member of TYPE
1542 while in some completely different context. However, TYPE will
1543 never be a dependent class (because we never want to do lookups
1544 for implicitly defined functions in a dependent class).
1545 Furthermore, we must set PROCESSING_TEMPLATE_DECL to zero here
1546 because we only create clones for constructors and destructors
1547 when not in a template. */
1548 gcc_assert (!dependent_type_p (type));
1549 saved_processing_template_decl = processing_template_decl;
1550 processing_template_decl = 0;
1552 type = TYPE_MAIN_VARIANT (type);
1554 if (targetm.cxx.cdtor_returns_this () && !TYPE_FOR_JAVA (type))
1556 if (kind == sfk_destructor)
1557 /* See comment in check_special_function_return_type. */
1558 return_type = build_pointer_type (void_type_node);
1559 else
1560 return_type = build_pointer_type (type);
1562 else
1563 return_type = void_type_node;
1565 switch (kind)
1567 case sfk_destructor:
1568 /* Destructor. */
1569 name = constructor_name (type);
1570 break;
1572 case sfk_constructor:
1573 /* Default constructor. */
1574 name = constructor_name (type);
1575 break;
1577 case sfk_copy_constructor:
1578 case sfk_copy_assignment:
1579 case sfk_move_constructor:
1580 case sfk_move_assignment:
1581 case sfk_inheriting_constructor:
1583 bool move_p;
1584 if (kind == sfk_copy_assignment
1585 || kind == sfk_move_assignment)
1587 return_type = build_reference_type (type);
1588 name = ansi_assopname (NOP_EXPR);
1590 else
1591 name = constructor_name (type);
1593 if (kind == sfk_inheriting_constructor)
1594 parameter_types = inherited_parms;
1595 else
1597 if (const_p)
1598 rhs_parm_type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
1599 else
1600 rhs_parm_type = type;
1601 move_p = (kind == sfk_move_assignment
1602 || kind == sfk_move_constructor);
1603 rhs_parm_type = cp_build_reference_type (rhs_parm_type, move_p);
1605 parameter_types = tree_cons (NULL_TREE, rhs_parm_type, parameter_types);
1607 break;
1609 default:
1610 gcc_unreachable ();
1613 tree inherited_base = (inherited_ctor
1614 ? DECL_CONTEXT (inherited_ctor)
1615 : NULL_TREE);
1616 bool trivial_p = false;
1618 if (inherited_ctor && TREE_CODE (inherited_ctor) == TEMPLATE_DECL)
1620 /* For an inheriting constructor template, just copy these flags from
1621 the inherited constructor template for now. */
1622 raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (inherited_ctor));
1623 deleted_p = DECL_DELETED_FN (DECL_TEMPLATE_RESULT (inherited_ctor));
1624 constexpr_p
1625 = DECL_DECLARED_CONSTEXPR_P (DECL_TEMPLATE_RESULT (inherited_ctor));
1627 else
1628 synthesized_method_walk (type, kind, const_p, &raises, &trivial_p,
1629 &deleted_p, &constexpr_p, false,
1630 inherited_base, inherited_parms);
1631 /* Don't bother marking a deleted constructor as constexpr. */
1632 if (deleted_p)
1633 constexpr_p = false;
1634 /* A trivial copy/move constructor is also a constexpr constructor. */
1635 else if (trivial_p && cxx_dialect >= cxx11
1636 && (kind == sfk_copy_constructor
1637 || kind == sfk_move_constructor))
1638 gcc_assert (constexpr_p);
1640 if (!trivial_p && type_has_trivial_fn (type, kind))
1641 type_set_nontrivial_flag (type, kind);
1643 /* Create the function. */
1644 fn_type = build_method_type_directly (type, return_type, parameter_types);
1645 if (raises)
1646 fn_type = build_exception_variant (fn_type, raises);
1647 fn = build_lang_decl (FUNCTION_DECL, name, fn_type);
1648 if (kind != sfk_inheriting_constructor)
1649 DECL_SOURCE_LOCATION (fn) = DECL_SOURCE_LOCATION (TYPE_NAME (type));
1650 if (kind == sfk_constructor || kind == sfk_copy_constructor
1651 || kind == sfk_move_constructor || kind == sfk_inheriting_constructor)
1652 DECL_CONSTRUCTOR_P (fn) = 1;
1653 else if (kind == sfk_destructor)
1654 DECL_DESTRUCTOR_P (fn) = 1;
1655 else
1657 DECL_ASSIGNMENT_OPERATOR_P (fn) = 1;
1658 SET_OVERLOADED_OPERATOR_CODE (fn, NOP_EXPR);
1661 /* If pointers to member functions use the least significant bit to
1662 indicate whether a function is virtual, ensure a pointer
1663 to this function will have that bit clear. */
1664 if (TARGET_PTRMEMFUNC_VBIT_LOCATION == ptrmemfunc_vbit_in_pfn
1665 && DECL_ALIGN (fn) < 2 * BITS_PER_UNIT)
1666 DECL_ALIGN (fn) = 2 * BITS_PER_UNIT;
1668 /* Create the explicit arguments. */
1669 if (rhs_parm_type)
1671 /* Note that this parameter is *not* marked DECL_ARTIFICIAL; we
1672 want its type to be included in the mangled function
1673 name. */
1674 tree decl = cp_build_parm_decl (NULL_TREE, rhs_parm_type);
1675 TREE_READONLY (decl) = 1;
1676 retrofit_lang_decl (decl);
1677 DECL_PARM_INDEX (decl) = DECL_PARM_LEVEL (decl) = 1;
1678 DECL_ARGUMENTS (fn) = decl;
1680 else if (kind == sfk_inheriting_constructor)
1682 tree *p = &DECL_ARGUMENTS (fn);
1683 int index = 1;
1684 for (tree parm = inherited_parms; parm != void_list_node;
1685 parm = TREE_CHAIN (parm))
1687 *p = cp_build_parm_decl (NULL_TREE, TREE_VALUE (parm));
1688 retrofit_lang_decl (*p);
1689 DECL_PARM_LEVEL (*p) = 1;
1690 DECL_PARM_INDEX (*p) = index++;
1691 DECL_CONTEXT (*p) = fn;
1692 p = &DECL_CHAIN (*p);
1694 SET_DECL_INHERITED_CTOR_BASE (fn, inherited_base);
1695 DECL_NONCONVERTING_P (fn) = DECL_NONCONVERTING_P (inherited_ctor);
1696 /* A constructor so declared has the same access as the corresponding
1697 constructor in X. */
1698 TREE_PRIVATE (fn) = TREE_PRIVATE (inherited_ctor);
1699 TREE_PROTECTED (fn) = TREE_PROTECTED (inherited_ctor);
1700 /* Copy constexpr from the inherited constructor even if the
1701 inheriting constructor doesn't satisfy the requirements. */
1702 constexpr_p
1703 = DECL_DECLARED_CONSTEXPR_P (STRIP_TEMPLATE (inherited_ctor));
1705 /* Add the "this" parameter. */
1706 this_parm = build_this_parm (fn_type, TYPE_UNQUALIFIED);
1707 DECL_CHAIN (this_parm) = DECL_ARGUMENTS (fn);
1708 DECL_ARGUMENTS (fn) = this_parm;
1710 grokclassfn (type, fn, kind == sfk_destructor ? DTOR_FLAG : NO_SPECIAL);
1711 set_linkage_according_to_type (type, fn);
1712 rest_of_decl_compilation (fn, toplevel_bindings_p (), at_eof);
1713 DECL_IN_AGGR_P (fn) = 1;
1714 DECL_ARTIFICIAL (fn) = 1;
1715 DECL_DEFAULTED_FN (fn) = 1;
1716 if (cxx_dialect >= cxx11)
1718 DECL_DELETED_FN (fn) = deleted_p;
1719 DECL_DECLARED_CONSTEXPR_P (fn) = constexpr_p;
1721 DECL_EXTERNAL (fn) = true;
1722 DECL_NOT_REALLY_EXTERN (fn) = 1;
1723 DECL_DECLARED_INLINE_P (fn) = 1;
1724 gcc_assert (!TREE_USED (fn));
1726 /* Restore PROCESSING_TEMPLATE_DECL. */
1727 processing_template_decl = saved_processing_template_decl;
1729 if (inherited_ctor && TREE_CODE (inherited_ctor) == TEMPLATE_DECL)
1730 fn = add_inherited_template_parms (fn, inherited_ctor);
1732 /* Warn about calling a non-trivial move assignment in a virtual base. */
1733 if (kind == sfk_move_assignment && !deleted_p && !trivial_p
1734 && CLASSTYPE_VBASECLASSES (type))
1736 location_t loc = input_location;
1737 input_location = DECL_SOURCE_LOCATION (fn);
1738 synthesized_method_walk (type, kind, const_p,
1739 NULL, NULL, NULL, NULL, true,
1740 NULL_TREE, NULL_TREE);
1741 input_location = loc;
1744 return fn;
1747 /* Gives any errors about defaulted functions which need to be deferred
1748 until the containing class is complete. */
1750 void
1751 defaulted_late_check (tree fn)
1753 /* Complain about invalid signature for defaulted fn. */
1754 tree ctx = DECL_CONTEXT (fn);
1755 special_function_kind kind = special_function_p (fn);
1756 bool fn_const_p = (copy_fn_p (fn) == 2);
1757 tree implicit_fn = implicitly_declare_fn (kind, ctx, fn_const_p,
1758 NULL, NULL);
1759 tree eh_spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (implicit_fn));
1761 if (!same_type_p (TREE_TYPE (TREE_TYPE (fn)),
1762 TREE_TYPE (TREE_TYPE (implicit_fn)))
1763 || !compparms (TYPE_ARG_TYPES (TREE_TYPE (fn)),
1764 TYPE_ARG_TYPES (TREE_TYPE (implicit_fn))))
1766 error ("defaulted declaration %q+D", fn);
1767 error_at (DECL_SOURCE_LOCATION (fn),
1768 "does not match expected signature %qD", implicit_fn);
1771 /* 8.4.2/2: An explicitly-defaulted function (...) may have an explicit
1772 exception-specification only if it is compatible (15.4) with the
1773 exception-specification on the implicit declaration. If a function
1774 is explicitly defaulted on its first declaration, (...) it is
1775 implicitly considered to have the same exception-specification as if
1776 it had been implicitly declared. */
1777 if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)))
1779 maybe_instantiate_noexcept (fn);
1780 if (!comp_except_specs (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)),
1781 eh_spec, ce_normal))
1783 if (DECL_DEFAULTED_IN_CLASS_P (fn))
1784 error ("function %q+D defaulted on its first declaration "
1785 "with an exception-specification that differs from "
1786 "the implicit declaration %q#D", fn, implicit_fn);
1787 else
1788 error ("function %q+D defaulted on its redeclaration "
1789 "with an exception-specification that differs from "
1790 "the implicit declaration %q#D", fn, implicit_fn);
1793 if (DECL_DEFAULTED_IN_CLASS_P (fn))
1794 TREE_TYPE (fn) = build_exception_variant (TREE_TYPE (fn), eh_spec);
1796 if (DECL_DEFAULTED_IN_CLASS_P (fn)
1797 && DECL_DECLARED_CONSTEXPR_P (implicit_fn))
1799 /* Hmm...should we do this for out-of-class too? Should it be OK to
1800 add constexpr later like inline, rather than requiring
1801 declarations to match? */
1802 DECL_DECLARED_CONSTEXPR_P (fn) = true;
1803 if (kind == sfk_constructor)
1804 TYPE_HAS_CONSTEXPR_CTOR (ctx) = true;
1807 if (!DECL_DECLARED_CONSTEXPR_P (implicit_fn)
1808 && DECL_DECLARED_CONSTEXPR_P (fn))
1810 if (!CLASSTYPE_TEMPLATE_INSTANTIATION (ctx))
1812 error ("explicitly defaulted function %q+D cannot be declared "
1813 "as constexpr because the implicit declaration is not "
1814 "constexpr:", fn);
1815 explain_implicit_non_constexpr (fn);
1817 DECL_DECLARED_CONSTEXPR_P (fn) = false;
1820 if (DECL_DELETED_FN (implicit_fn))
1821 DECL_DELETED_FN (fn) = 1;
1824 /* Returns true iff FN can be explicitly defaulted, and gives any
1825 errors if defaulting FN is ill-formed. */
1827 bool
1828 defaultable_fn_check (tree fn)
1830 special_function_kind kind = sfk_none;
1832 if (template_parm_scope_p ())
1834 error ("a template cannot be defaulted");
1835 return false;
1838 if (DECL_CONSTRUCTOR_P (fn))
1840 if (FUNCTION_FIRST_USER_PARMTYPE (fn) == void_list_node)
1841 kind = sfk_constructor;
1842 else if (copy_fn_p (fn) > 0
1843 && (TREE_CHAIN (FUNCTION_FIRST_USER_PARMTYPE (fn))
1844 == void_list_node))
1845 kind = sfk_copy_constructor;
1846 else if (move_fn_p (fn))
1847 kind = sfk_move_constructor;
1849 else if (DECL_DESTRUCTOR_P (fn))
1850 kind = sfk_destructor;
1851 else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
1852 && DECL_OVERLOADED_OPERATOR_P (fn) == NOP_EXPR)
1854 if (copy_fn_p (fn))
1855 kind = sfk_copy_assignment;
1856 else if (move_fn_p (fn))
1857 kind = sfk_move_assignment;
1860 if (kind == sfk_none)
1862 error ("%qD cannot be defaulted", fn);
1863 return false;
1865 else
1867 for (tree t = FUNCTION_FIRST_USER_PARMTYPE (fn);
1868 t && t != void_list_node; t = TREE_CHAIN (t))
1869 if (TREE_PURPOSE (t))
1871 error ("defaulted function %q+D with default argument", fn);
1872 break;
1875 /* Avoid do_warn_unused_parameter warnings. */
1876 for (tree p = FUNCTION_FIRST_USER_PARM (fn); p; p = DECL_CHAIN (p))
1877 if (DECL_NAME (p))
1878 TREE_NO_WARNING (p) = 1;
1880 if (TYPE_BEING_DEFINED (DECL_CONTEXT (fn)))
1881 /* Defer checking. */;
1882 else if (!processing_template_decl)
1883 defaulted_late_check (fn);
1885 return true;
1889 /* Add an implicit declaration to TYPE for the kind of function
1890 indicated by SFK. Return the FUNCTION_DECL for the new implicit
1891 declaration. */
1893 tree
1894 lazily_declare_fn (special_function_kind sfk, tree type)
1896 tree fn;
1897 /* Whether or not the argument has a const reference type. */
1898 bool const_p = false;
1900 switch (sfk)
1902 case sfk_constructor:
1903 CLASSTYPE_LAZY_DEFAULT_CTOR (type) = 0;
1904 break;
1905 case sfk_copy_constructor:
1906 const_p = TYPE_HAS_CONST_COPY_CTOR (type);
1907 CLASSTYPE_LAZY_COPY_CTOR (type) = 0;
1908 break;
1909 case sfk_move_constructor:
1910 CLASSTYPE_LAZY_MOVE_CTOR (type) = 0;
1911 break;
1912 case sfk_copy_assignment:
1913 const_p = TYPE_HAS_CONST_COPY_ASSIGN (type);
1914 CLASSTYPE_LAZY_COPY_ASSIGN (type) = 0;
1915 break;
1916 case sfk_move_assignment:
1917 CLASSTYPE_LAZY_MOVE_ASSIGN (type) = 0;
1918 break;
1919 case sfk_destructor:
1920 CLASSTYPE_LAZY_DESTRUCTOR (type) = 0;
1921 break;
1922 default:
1923 gcc_unreachable ();
1926 /* Declare the function. */
1927 fn = implicitly_declare_fn (sfk, type, const_p, NULL, NULL);
1929 /* [class.copy]/8 If the class definition declares a move constructor or
1930 move assignment operator, the implicitly declared copy constructor is
1931 defined as deleted.... */
1932 if ((sfk == sfk_copy_assignment
1933 || sfk == sfk_copy_constructor)
1934 && (type_has_user_declared_move_constructor (type)
1935 || type_has_user_declared_move_assign (type)))
1936 DECL_DELETED_FN (fn) = true;
1938 /* A destructor may be virtual. */
1939 if (sfk == sfk_destructor
1940 || sfk == sfk_move_assignment
1941 || sfk == sfk_copy_assignment)
1942 check_for_override (fn, type);
1943 /* Add it to CLASSTYPE_METHOD_VEC. */
1944 add_method (type, fn, NULL_TREE);
1945 /* Add it to TYPE_METHODS. */
1946 if (sfk == sfk_destructor
1947 && DECL_VIRTUAL_P (fn)
1948 && abi_version_at_least (2))
1949 /* The ABI requires that a virtual destructor go at the end of the
1950 vtable. */
1951 TYPE_METHODS (type) = chainon (TYPE_METHODS (type), fn);
1952 else
1954 /* G++ 3.2 put the implicit destructor at the *beginning* of the
1955 TYPE_METHODS list, which cause the destructor to be emitted
1956 in an incorrect location in the vtable. */
1957 if (warn_abi && sfk == sfk_destructor && DECL_VIRTUAL_P (fn))
1958 warning (OPT_Wabi, "vtable layout for class %qT may not be ABI-compliant"
1959 "and may change in a future version of GCC due to "
1960 "implicit virtual destructor",
1961 type);
1962 DECL_CHAIN (fn) = TYPE_METHODS (type);
1963 TYPE_METHODS (type) = fn;
1965 maybe_add_class_template_decl_list (type, fn, /*friend_p=*/0);
1966 if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn)
1967 || DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn))
1968 /* Create appropriate clones. */
1969 clone_function_decl (fn, /*update_method_vec=*/true);
1971 return fn;
1974 /* Given a FUNCTION_DECL FN and a chain LIST, skip as many elements of LIST
1975 as there are artificial parms in FN. */
1977 tree
1978 skip_artificial_parms_for (const_tree fn, tree list)
1980 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
1981 list = TREE_CHAIN (list);
1982 else
1983 return list;
1985 if (DECL_HAS_IN_CHARGE_PARM_P (fn))
1986 list = TREE_CHAIN (list);
1987 if (DECL_HAS_VTT_PARM_P (fn))
1988 list = TREE_CHAIN (list);
1989 return list;
1992 /* Given a FUNCTION_DECL FN and a chain LIST, return the number of
1993 artificial parms in FN. */
1996 num_artificial_parms_for (const_tree fn)
1998 int count = 0;
2000 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
2001 count++;
2002 else
2003 return 0;
2005 if (DECL_HAS_IN_CHARGE_PARM_P (fn))
2006 count++;
2007 if (DECL_HAS_VTT_PARM_P (fn))
2008 count++;
2009 return count;
2013 #include "gt-cp-method.h"