]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/cp/method.c
trans.c (check_inlining_for_nested_subprog): Quote reserved names.
[thirdparty/gcc.git] / gcc / cp / method.c
1 /* Handle the hair of processing (but not expanding) inline functions.
2 Also manage function and variable name overloading.
3 Copyright (C) 1987-2019 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
5
6 This file is part of GCC.
7
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.
12
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.
17
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/>. */
21
22
23 /* Handle method declarations. */
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "target.h"
28 #include "cp-tree.h"
29 #include "stringpool.h"
30 #include "cgraph.h"
31 #include "varasm.h"
32 #include "toplev.h"
33 #include "common/common-target.h"
34
35 static void do_build_copy_assign (tree);
36 static void do_build_copy_constructor (tree);
37 static tree make_alias_for_thunk (tree);
38
39 /* Called once to initialize method.c. */
40
41 void
42 init_method (void)
43 {
44 init_mangle ();
45 }
46 \f
47 /* Return a this or result adjusting thunk to FUNCTION. THIS_ADJUSTING
48 indicates whether it is a this or result adjusting thunk.
49 FIXED_OFFSET and VIRTUAL_OFFSET indicate how to do the adjustment
50 (see thunk_adjust). VIRTUAL_OFFSET can be NULL, but FIXED_OFFSET
51 never is. VIRTUAL_OFFSET is the /index/ into the vtable for this
52 adjusting thunks, we scale it to a byte offset. For covariant
53 thunks VIRTUAL_OFFSET is the virtual binfo. You must post process
54 the returned thunk with finish_thunk. */
55
56 tree
57 make_thunk (tree function, bool this_adjusting,
58 tree fixed_offset, tree virtual_offset)
59 {
60 HOST_WIDE_INT d;
61 tree thunk;
62
63 gcc_assert (TREE_CODE (function) == FUNCTION_DECL);
64 /* We can have this thunks to covariant thunks, but not vice versa. */
65 gcc_assert (!DECL_THIS_THUNK_P (function));
66 gcc_assert (!DECL_RESULT_THUNK_P (function) || this_adjusting);
67
68 /* Scale the VIRTUAL_OFFSET to be in terms of bytes. */
69 if (this_adjusting && virtual_offset)
70 virtual_offset
71 = size_binop (MULT_EXPR,
72 virtual_offset,
73 convert (ssizetype,
74 TYPE_SIZE_UNIT (vtable_entry_type)));
75
76 d = tree_to_shwi (fixed_offset);
77
78 /* See if we already have the thunk in question. For this_adjusting
79 thunks VIRTUAL_OFFSET will be an INTEGER_CST, for covariant thunks it
80 will be a BINFO. */
81 for (thunk = DECL_THUNKS (function); thunk; thunk = DECL_CHAIN (thunk))
82 if (DECL_THIS_THUNK_P (thunk) == this_adjusting
83 && THUNK_FIXED_OFFSET (thunk) == d
84 && !virtual_offset == !THUNK_VIRTUAL_OFFSET (thunk)
85 && (!virtual_offset
86 || (this_adjusting
87 ? tree_int_cst_equal (THUNK_VIRTUAL_OFFSET (thunk),
88 virtual_offset)
89 : THUNK_VIRTUAL_OFFSET (thunk) == virtual_offset)))
90 return thunk;
91
92 /* All thunks must be created before FUNCTION is actually emitted;
93 the ABI requires that all thunks be emitted together with the
94 function to which they transfer control. */
95 gcc_assert (!TREE_ASM_WRITTEN (function));
96 /* Likewise, we can only be adding thunks to a function declared in
97 the class currently being laid out. */
98 gcc_assert (TYPE_SIZE (DECL_CONTEXT (function))
99 && TYPE_BEING_DEFINED (DECL_CONTEXT (function)));
100
101 thunk = build_decl (DECL_SOURCE_LOCATION (function),
102 FUNCTION_DECL, NULL_TREE, TREE_TYPE (function));
103 DECL_LANG_SPECIFIC (thunk) = DECL_LANG_SPECIFIC (function);
104 cxx_dup_lang_specific_decl (thunk);
105 DECL_VIRTUAL_P (thunk) = true;
106 SET_DECL_THUNKS (thunk, NULL_TREE);
107
108 DECL_CONTEXT (thunk) = DECL_CONTEXT (function);
109 TREE_READONLY (thunk) = TREE_READONLY (function);
110 TREE_THIS_VOLATILE (thunk) = TREE_THIS_VOLATILE (function);
111 TREE_PUBLIC (thunk) = TREE_PUBLIC (function);
112 SET_DECL_THUNK_P (thunk, this_adjusting);
113 THUNK_TARGET (thunk) = function;
114 THUNK_FIXED_OFFSET (thunk) = d;
115 THUNK_VIRTUAL_OFFSET (thunk) = virtual_offset;
116 THUNK_ALIAS (thunk) = NULL_TREE;
117
118 DECL_INTERFACE_KNOWN (thunk) = 1;
119 DECL_NOT_REALLY_EXTERN (thunk) = 1;
120 DECL_COMDAT (thunk) = DECL_COMDAT (function);
121 DECL_SAVED_AUTO_RETURN_TYPE (thunk) = NULL;
122 /* The thunk itself is not a constructor or destructor, even if
123 the thing it is thunking to is. */
124 DECL_CXX_DESTRUCTOR_P (thunk) = 0;
125 DECL_CXX_CONSTRUCTOR_P (thunk) = 0;
126 DECL_EXTERNAL (thunk) = 1;
127 DECL_ARTIFICIAL (thunk) = 1;
128 /* The THUNK is not a pending inline, even if the FUNCTION is. */
129 DECL_PENDING_INLINE_P (thunk) = 0;
130 DECL_DECLARED_INLINE_P (thunk) = 0;
131 /* Nor is it a template instantiation. */
132 DECL_USE_TEMPLATE (thunk) = 0;
133 DECL_TEMPLATE_INFO (thunk) = NULL;
134
135 /* Add it to the list of thunks associated with FUNCTION. */
136 DECL_CHAIN (thunk) = DECL_THUNKS (function);
137 SET_DECL_THUNKS (function, thunk);
138
139 return thunk;
140 }
141
142 /* Finish THUNK, a thunk decl. */
143
144 void
145 finish_thunk (tree thunk)
146 {
147 tree function, name;
148 tree fixed_offset = ssize_int (THUNK_FIXED_OFFSET (thunk));
149 tree virtual_offset = THUNK_VIRTUAL_OFFSET (thunk);
150
151 gcc_assert (!DECL_NAME (thunk) && DECL_THUNK_P (thunk));
152 if (virtual_offset && DECL_RESULT_THUNK_P (thunk))
153 virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
154 function = THUNK_TARGET (thunk);
155 name = mangle_thunk (function, DECL_THIS_THUNK_P (thunk),
156 fixed_offset, virtual_offset, thunk);
157
158 /* We can end up with declarations of (logically) different
159 covariant thunks, that do identical adjustments. The two thunks
160 will be adjusting between within different hierarchies, which
161 happen to have the same layout. We must nullify one of them to
162 refer to the other. */
163 if (DECL_RESULT_THUNK_P (thunk))
164 {
165 tree cov_probe;
166
167 for (cov_probe = DECL_THUNKS (function);
168 cov_probe; cov_probe = DECL_CHAIN (cov_probe))
169 if (DECL_NAME (cov_probe) == name)
170 {
171 gcc_assert (!DECL_THUNKS (thunk));
172 THUNK_ALIAS (thunk) = (THUNK_ALIAS (cov_probe)
173 ? THUNK_ALIAS (cov_probe) : cov_probe);
174 break;
175 }
176 }
177
178 DECL_NAME (thunk) = name;
179 SET_DECL_ASSEMBLER_NAME (thunk, name);
180 }
181
182 static GTY (()) int thunk_labelno;
183
184 /* Create a static alias to target. */
185
186 tree
187 make_alias_for (tree target, tree newid)
188 {
189 tree alias = build_decl (DECL_SOURCE_LOCATION (target),
190 TREE_CODE (target), newid, TREE_TYPE (target));
191 DECL_LANG_SPECIFIC (alias) = DECL_LANG_SPECIFIC (target);
192 cxx_dup_lang_specific_decl (alias);
193 DECL_CONTEXT (alias) = DECL_CONTEXT (target);
194 TREE_READONLY (alias) = TREE_READONLY (target);
195 TREE_THIS_VOLATILE (alias) = TREE_THIS_VOLATILE (target);
196 TREE_PUBLIC (alias) = 0;
197 DECL_INTERFACE_KNOWN (alias) = 1;
198 if (DECL_LANG_SPECIFIC (alias))
199 {
200 DECL_NOT_REALLY_EXTERN (alias) = 1;
201 DECL_USE_TEMPLATE (alias) = 0;
202 DECL_TEMPLATE_INFO (alias) = NULL;
203 }
204 DECL_EXTERNAL (alias) = 0;
205 DECL_ARTIFICIAL (alias) = 1;
206 DECL_TEMPLATE_INSTANTIATED (alias) = 0;
207 if (TREE_CODE (alias) == FUNCTION_DECL)
208 {
209 DECL_SAVED_AUTO_RETURN_TYPE (alias) = NULL;
210 DECL_CXX_DESTRUCTOR_P (alias) = 0;
211 DECL_CXX_CONSTRUCTOR_P (alias) = 0;
212 DECL_PENDING_INLINE_P (alias) = 0;
213 DECL_DECLARED_INLINE_P (alias) = 0;
214 DECL_INITIAL (alias) = error_mark_node;
215 DECL_ARGUMENTS (alias) = copy_list (DECL_ARGUMENTS (target));
216 }
217 else
218 TREE_STATIC (alias) = 1;
219 TREE_ADDRESSABLE (alias) = 1;
220 TREE_USED (alias) = 1;
221 SET_DECL_ASSEMBLER_NAME (alias, DECL_NAME (alias));
222 return alias;
223 }
224
225 static tree
226 make_alias_for_thunk (tree function)
227 {
228 tree alias;
229 char buf[256];
230
231 targetm.asm_out.generate_internal_label (buf, "LTHUNK", thunk_labelno);
232 thunk_labelno++;
233
234 alias = make_alias_for (function, get_identifier (buf));
235
236 if (!flag_syntax_only)
237 {
238 struct cgraph_node *funcn, *aliasn;
239 funcn = cgraph_node::get (function);
240 gcc_checking_assert (funcn);
241 aliasn = cgraph_node::create_same_body_alias (alias, function);
242 DECL_ASSEMBLER_NAME (function);
243 gcc_assert (aliasn != NULL);
244 }
245
246 return alias;
247 }
248
249 /* Emit the definition of a C++ multiple inheritance or covariant
250 return vtable thunk. If EMIT_P is nonzero, the thunk is emitted
251 immediately. */
252
253 void
254 use_thunk (tree thunk_fndecl, bool emit_p)
255 {
256 tree a, t, function, alias;
257 tree virtual_offset;
258 HOST_WIDE_INT fixed_offset, virtual_value;
259 bool this_adjusting = DECL_THIS_THUNK_P (thunk_fndecl);
260 struct cgraph_node *funcn, *thunk_node;
261
262 /* We should have called finish_thunk to give it a name. */
263 gcc_assert (DECL_NAME (thunk_fndecl));
264
265 /* We should never be using an alias, always refer to the
266 aliased thunk. */
267 gcc_assert (!THUNK_ALIAS (thunk_fndecl));
268
269 if (TREE_ASM_WRITTEN (thunk_fndecl))
270 return;
271
272 function = THUNK_TARGET (thunk_fndecl);
273 if (DECL_RESULT (thunk_fndecl))
274 /* We already turned this thunk into an ordinary function.
275 There's no need to process this thunk again. */
276 return;
277
278 if (DECL_THUNK_P (function))
279 /* The target is itself a thunk, process it now. */
280 use_thunk (function, emit_p);
281
282 /* Thunks are always addressable; they only appear in vtables. */
283 TREE_ADDRESSABLE (thunk_fndecl) = 1;
284
285 /* Figure out what function is being thunked to. It's referenced in
286 this translation unit. */
287 TREE_ADDRESSABLE (function) = 1;
288 mark_used (function);
289 if (!emit_p)
290 return;
291
292 if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function))
293 alias = make_alias_for_thunk (function);
294 else
295 alias = function;
296
297 fixed_offset = THUNK_FIXED_OFFSET (thunk_fndecl);
298 virtual_offset = THUNK_VIRTUAL_OFFSET (thunk_fndecl);
299
300 if (virtual_offset)
301 {
302 if (!this_adjusting)
303 virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
304 virtual_value = tree_to_shwi (virtual_offset);
305 gcc_assert (virtual_value);
306 }
307 else
308 virtual_value = 0;
309
310 /* And, if we need to emit the thunk, it's used. */
311 mark_used (thunk_fndecl);
312 /* This thunk is actually defined. */
313 DECL_EXTERNAL (thunk_fndecl) = 0;
314 /* The linkage of the function may have changed. FIXME in linkage
315 rewrite. */
316 gcc_assert (DECL_INTERFACE_KNOWN (function));
317 TREE_PUBLIC (thunk_fndecl) = TREE_PUBLIC (function);
318 DECL_VISIBILITY (thunk_fndecl) = DECL_VISIBILITY (function);
319 DECL_VISIBILITY_SPECIFIED (thunk_fndecl)
320 = DECL_VISIBILITY_SPECIFIED (function);
321 DECL_COMDAT (thunk_fndecl) = DECL_COMDAT (function);
322 DECL_WEAK (thunk_fndecl) = DECL_WEAK (function);
323
324 if (flag_syntax_only)
325 {
326 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
327 return;
328 }
329
330 push_to_top_level ();
331
332 if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function)
333 && targetm_common.have_named_sections)
334 {
335 tree fn = function;
336 struct symtab_node *symbol;
337
338 if ((symbol = symtab_node::get (function))
339 && symbol->alias)
340 {
341 if (symbol->analyzed)
342 fn = symtab_node::get (function)->ultimate_alias_target ()->decl;
343 else
344 fn = symtab_node::get (function)->alias_target;
345 }
346 resolve_unique_section (fn, 0, flag_function_sections);
347
348 if (DECL_SECTION_NAME (fn) != NULL && DECL_ONE_ONLY (fn))
349 {
350 resolve_unique_section (thunk_fndecl, 0, flag_function_sections);
351
352 /* Output the thunk into the same section as function. */
353 set_decl_section_name (thunk_fndecl, DECL_SECTION_NAME (fn));
354 symtab_node::get (thunk_fndecl)->implicit_section
355 = symtab_node::get (fn)->implicit_section;
356 }
357 }
358
359 /* Set up cloned argument trees for the thunk. */
360 t = NULL_TREE;
361 for (a = DECL_ARGUMENTS (function); a; a = DECL_CHAIN (a))
362 {
363 tree x = copy_node (a);
364 DECL_CHAIN (x) = t;
365 DECL_CONTEXT (x) = thunk_fndecl;
366 SET_DECL_RTL (x, NULL);
367 DECL_HAS_VALUE_EXPR_P (x) = 0;
368 TREE_ADDRESSABLE (x) = 0;
369 t = x;
370 }
371 a = nreverse (t);
372 DECL_ARGUMENTS (thunk_fndecl) = a;
373 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
374 funcn = cgraph_node::get (function);
375 gcc_checking_assert (funcn);
376 thunk_node = funcn->create_thunk (thunk_fndecl, function,
377 this_adjusting, fixed_offset, virtual_value,
378 0, virtual_offset, alias);
379 if (DECL_ONE_ONLY (function))
380 thunk_node->add_to_same_comdat_group (funcn);
381
382 pop_from_top_level ();
383 }
384 \f
385 /* Code for synthesizing methods which have default semantics defined. */
386
387 /* True iff CTYPE has a trivial SFK. */
388
389 static bool
390 type_has_trivial_fn (tree ctype, special_function_kind sfk)
391 {
392 switch (sfk)
393 {
394 case sfk_constructor:
395 return !TYPE_HAS_COMPLEX_DFLT (ctype);
396 case sfk_copy_constructor:
397 return !TYPE_HAS_COMPLEX_COPY_CTOR (ctype);
398 case sfk_move_constructor:
399 return !TYPE_HAS_COMPLEX_MOVE_CTOR (ctype);
400 case sfk_copy_assignment:
401 return !TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype);
402 case sfk_move_assignment:
403 return !TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype);
404 case sfk_destructor:
405 case sfk_virtual_destructor:
406 return !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype);
407 case sfk_inheriting_constructor:
408 return false;
409 default:
410 gcc_unreachable ();
411 }
412 }
413
414 /* Note that CTYPE has a non-trivial SFK even though we previously thought
415 it was trivial. */
416
417 static void
418 type_set_nontrivial_flag (tree ctype, special_function_kind sfk)
419 {
420 switch (sfk)
421 {
422 case sfk_constructor:
423 TYPE_HAS_COMPLEX_DFLT (ctype) = true;
424 return;
425 case sfk_copy_constructor:
426 TYPE_HAS_COMPLEX_COPY_CTOR (ctype) = true;
427 return;
428 case sfk_move_constructor:
429 TYPE_HAS_COMPLEX_MOVE_CTOR (ctype) = true;
430 return;
431 case sfk_copy_assignment:
432 TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype) = true;
433 return;
434 case sfk_move_assignment:
435 TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype) = true;
436 return;
437 case sfk_destructor:
438 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype) = true;
439 return;
440 case sfk_inheriting_constructor:
441 default:
442 gcc_unreachable ();
443 }
444 }
445
446 /* True iff FN is a trivial defaulted member function ([cd]tor, op=). */
447
448 bool
449 trivial_fn_p (tree fn)
450 {
451 if (TREE_CODE (fn) == TEMPLATE_DECL)
452 return false;
453 if (!DECL_DEFAULTED_FN (fn))
454 return false;
455
456 /* If fn is a clone, get the primary variant. */
457 if (tree prim = DECL_CLONED_FUNCTION (fn))
458 fn = prim;
459 return type_has_trivial_fn (DECL_CONTEXT (fn), special_function_p (fn));
460 }
461
462 /* PARM is a PARM_DECL for a function which we want to forward to another
463 function without changing its value category, a la std::forward. */
464
465 tree
466 forward_parm (tree parm)
467 {
468 tree exp = convert_from_reference (parm);
469 tree type = TREE_TYPE (parm);
470 if (DECL_PACK_P (parm))
471 type = PACK_EXPANSION_PATTERN (type);
472 if (!TYPE_REF_P (type))
473 type = cp_build_reference_type (type, /*rval=*/true);
474 warning_sentinel w (warn_useless_cast);
475 exp = build_static_cast (type, exp, tf_warning_or_error);
476 if (DECL_PACK_P (parm))
477 exp = make_pack_expansion (exp);
478 return exp;
479 }
480
481 /* Strip all inheriting constructors, if any, to return the original
482 constructor from a (possibly indirect) base class. */
483
484 tree
485 strip_inheriting_ctors (tree dfn)
486 {
487 if (!flag_new_inheriting_ctors)
488 return dfn;
489 tree fn = dfn;
490 while (tree inh = DECL_INHERITED_CTOR (fn))
491 fn = OVL_FIRST (inh);
492
493 if (TREE_CODE (fn) == TEMPLATE_DECL
494 && TREE_CODE (dfn) == FUNCTION_DECL)
495 fn = DECL_TEMPLATE_RESULT (fn);
496 return fn;
497 }
498
499 /* Find the binfo for the base subobject of BINFO being initialized by
500 inherited constructor FNDECL (a member of a direct base of BINFO). */
501
502 static tree inherited_ctor_binfo (tree, tree);
503 static tree
504 inherited_ctor_binfo_1 (tree binfo, tree fndecl)
505 {
506 tree base = DECL_CONTEXT (fndecl);
507 tree base_binfo;
508 for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
509 if (BINFO_TYPE (base_binfo) == base)
510 return inherited_ctor_binfo (base_binfo, fndecl);
511
512 gcc_unreachable();
513 }
514
515 /* Find the binfo for the base subobject of BINFO being initialized by
516 inheriting constructor FNDECL (a member of BINFO), or BINFO if FNDECL is not
517 an inheriting constructor. */
518
519 static tree
520 inherited_ctor_binfo (tree binfo, tree fndecl)
521 {
522 tree inh = DECL_INHERITED_CTOR (fndecl);
523 if (!inh)
524 return binfo;
525
526 tree results = NULL_TREE;
527 for (ovl_iterator iter (inh); iter; ++iter)
528 {
529 tree one = inherited_ctor_binfo_1 (binfo, *iter);
530 if (!results)
531 results = one;
532 else if (one != results)
533 results = tree_cons (NULL_TREE, one, results);
534 }
535 return results;
536 }
537
538 /* Find the binfo for the base subobject being initialized by inheriting
539 constructor FNDECL, or NULL_TREE if FNDECL is not an inheriting
540 constructor. */
541
542 tree
543 inherited_ctor_binfo (tree fndecl)
544 {
545 if (!DECL_INHERITED_CTOR (fndecl))
546 return NULL_TREE;
547 tree binfo = TYPE_BINFO (DECL_CONTEXT (fndecl));
548 return inherited_ctor_binfo (binfo, fndecl);
549 }
550
551 /* True if we should omit all user-declared parameters from constructor FN,
552 because it is a base clone of a ctor inherited from a virtual base. */
553
554 bool
555 ctor_omit_inherited_parms (tree fn)
556 {
557 if (!flag_new_inheriting_ctors)
558 /* We only optimize away the parameters in the new model. */
559 return false;
560 if (!DECL_BASE_CONSTRUCTOR_P (fn)
561 || !CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn)))
562 return false;
563 if (FUNCTION_FIRST_USER_PARMTYPE (DECL_ORIGIN (fn)) == void_list_node)
564 /* No user-declared parameters to omit. */
565 return false;
566 tree binfo = inherited_ctor_binfo (fn);
567 for (; binfo; binfo = BINFO_INHERITANCE_CHAIN (binfo))
568 if (BINFO_VIRTUAL_P (binfo))
569 return true;
570 return false;
571 }
572
573 /* True iff constructor(s) INH inherited into BINFO initializes INIT_BINFO.
574 This can be true for multiple virtual bases as well as one direct
575 non-virtual base. */
576
577 static bool
578 binfo_inherited_from (tree binfo, tree init_binfo, tree inh)
579 {
580 /* inh is an OVERLOAD if we inherited the same constructor along
581 multiple paths, check all of them. */
582 for (ovl_iterator iter (inh); iter; ++iter)
583 {
584 tree fn = *iter;
585 tree base = DECL_CONTEXT (fn);
586 tree base_binfo = NULL_TREE;
587 for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
588 if (BINFO_TYPE (base_binfo) == base)
589 break;
590 if (base_binfo == init_binfo
591 || (flag_new_inheriting_ctors
592 && binfo_inherited_from (base_binfo, init_binfo,
593 DECL_INHERITED_CTOR (fn))))
594 return true;
595 }
596 return false;
597 }
598
599 /* Subroutine of do_build_copy_constructor: Add a mem-initializer for BINFO
600 given the parameter or parameters PARM, possibly inherited constructor
601 base INH, or move flag MOVE_P. */
602
603 static tree
604 add_one_base_init (tree binfo, tree parm, bool move_p, tree inh,
605 tree member_init_list)
606 {
607 tree init;
608 if (inh)
609 {
610 /* An inheriting constructor only has a mem-initializer for
611 the base it inherits from. */
612 if (!binfo_inherited_from (TYPE_BINFO (current_class_type), binfo, inh))
613 return member_init_list;
614
615 tree *p = &init;
616 init = NULL_TREE;
617 for (; parm; parm = DECL_CHAIN (parm))
618 {
619 tree exp = forward_parm (parm);
620 *p = build_tree_list (NULL_TREE, exp);
621 p = &TREE_CHAIN (*p);
622 }
623 }
624 else
625 {
626 init = build_base_path (PLUS_EXPR, parm, binfo, 1,
627 tf_warning_or_error);
628 if (move_p)
629 init = move (init);
630 init = build_tree_list (NULL_TREE, init);
631 }
632 return tree_cons (binfo, init, member_init_list);
633 }
634
635 /* Generate code for default X(X&) or X(X&&) constructor or an inheriting
636 constructor. */
637
638 static void
639 do_build_copy_constructor (tree fndecl)
640 {
641 tree parm = FUNCTION_FIRST_USER_PARM (fndecl);
642 bool move_p = DECL_MOVE_CONSTRUCTOR_P (fndecl);
643 bool trivial = trivial_fn_p (fndecl);
644 tree inh = DECL_INHERITED_CTOR (fndecl);
645
646 if (!inh)
647 parm = convert_from_reference (parm);
648
649 if (trivial)
650 {
651 if (is_empty_class (current_class_type))
652 /* Don't copy the padding byte; it might not have been allocated
653 if *this is a base subobject. */;
654 else if (tree_int_cst_equal (TYPE_SIZE (current_class_type),
655 CLASSTYPE_SIZE (current_class_type)))
656 {
657 tree t = build2 (INIT_EXPR, void_type_node, current_class_ref, parm);
658 finish_expr_stmt (t);
659 }
660 else
661 {
662 /* We must only copy the non-tail padding parts. */
663 tree base_size = CLASSTYPE_SIZE_UNIT (current_class_type);
664 base_size = size_binop (MINUS_EXPR, base_size, size_int (1));
665 tree array_type = build_array_type (unsigned_char_type_node,
666 build_index_type (base_size));
667 tree alias_set = build_int_cst (TREE_TYPE (current_class_ptr), 0);
668 tree lhs = build2 (MEM_REF, array_type,
669 current_class_ptr, alias_set);
670 tree rhs = build2 (MEM_REF, array_type,
671 TREE_OPERAND (parm, 0), alias_set);
672 tree t = build2 (INIT_EXPR, void_type_node, lhs, rhs);
673 finish_expr_stmt (t);
674 }
675 }
676 else
677 {
678 tree member_init_list = NULL_TREE;
679 int i;
680 tree binfo, base_binfo;
681 vec<tree, va_gc> *vbases;
682
683 /* Initialize all the base-classes with the parameter converted
684 to their type so that we get their copy constructor and not
685 another constructor that takes current_class_type. We must
686 deal with the binfo's directly as a direct base might be
687 inaccessible due to ambiguity. */
688 for (vbases = CLASSTYPE_VBASECLASSES (current_class_type), i = 0;
689 vec_safe_iterate (vbases, i, &binfo); i++)
690 {
691 member_init_list = add_one_base_init (binfo, parm, move_p, inh,
692 member_init_list);
693 }
694
695 for (binfo = TYPE_BINFO (current_class_type), i = 0;
696 BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
697 {
698 if (BINFO_VIRTUAL_P (base_binfo))
699 continue;
700 member_init_list = add_one_base_init (base_binfo, parm, move_p,
701 inh, member_init_list);
702 }
703
704 if (!inh)
705 {
706 int cvquals = cp_type_quals (TREE_TYPE (parm));
707
708 for (tree fields = TYPE_FIELDS (current_class_type);
709 fields; fields = DECL_CHAIN (fields))
710 {
711 tree field = fields;
712 tree expr_type;
713
714 if (TREE_CODE (field) != FIELD_DECL)
715 continue;
716
717 expr_type = TREE_TYPE (field);
718 if (DECL_NAME (field))
719 {
720 if (VFIELD_NAME_P (DECL_NAME (field)))
721 continue;
722 }
723 else if (ANON_AGGR_TYPE_P (expr_type) && TYPE_FIELDS (expr_type))
724 /* Just use the field; anonymous types can't have
725 nontrivial copy ctors or assignment ops or this
726 function would be deleted. */;
727 else
728 continue;
729
730 /* Compute the type of "init->field". If the copy-constructor
731 parameter is, for example, "const S&", and the type of
732 the field is "T", then the type will usually be "const
733 T". (There are no cv-qualified variants of reference
734 types.) */
735 if (!TYPE_REF_P (expr_type))
736 {
737 int quals = cvquals;
738
739 if (DECL_MUTABLE_P (field))
740 quals &= ~TYPE_QUAL_CONST;
741 quals |= cp_type_quals (expr_type);
742 expr_type = cp_build_qualified_type (expr_type, quals);
743 }
744
745 tree init = build3 (COMPONENT_REF, expr_type, parm, field, NULL_TREE);
746 if (move_p && !TYPE_REF_P (expr_type)
747 /* 'move' breaks bit-fields, and has no effect for scalars. */
748 && !scalarish_type_p (expr_type))
749 init = move (init);
750 init = build_tree_list (NULL_TREE, init);
751
752 member_init_list = tree_cons (field, init, member_init_list);
753 }
754 }
755
756 finish_mem_initializers (member_init_list);
757 }
758 }
759
760 static void
761 do_build_copy_assign (tree fndecl)
762 {
763 tree parm = DECL_CHAIN (DECL_ARGUMENTS (fndecl));
764 tree compound_stmt;
765 bool move_p = move_fn_p (fndecl);
766 bool trivial = trivial_fn_p (fndecl);
767 int flags = LOOKUP_NORMAL | LOOKUP_NONVIRTUAL | LOOKUP_DEFAULTED;
768
769 compound_stmt = begin_compound_stmt (0);
770 parm = convert_from_reference (parm);
771
772 if (trivial
773 && is_empty_class (current_class_type))
774 /* Don't copy the padding byte; it might not have been allocated
775 if *this is a base subobject. */;
776 else if (trivial)
777 {
778 tree t = build2 (MODIFY_EXPR, void_type_node, current_class_ref, parm);
779 finish_expr_stmt (t);
780 }
781 else
782 {
783 tree fields;
784 int cvquals = cp_type_quals (TREE_TYPE (parm));
785 int i;
786 tree binfo, base_binfo;
787
788 /* Assign to each of the direct base classes. */
789 for (binfo = TYPE_BINFO (current_class_type), i = 0;
790 BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
791 {
792 tree converted_parm;
793
794 /* We must convert PARM directly to the base class
795 explicitly since the base class may be ambiguous. */
796 converted_parm = build_base_path (PLUS_EXPR, parm, base_binfo, 1,
797 tf_warning_or_error);
798 if (move_p)
799 converted_parm = move (converted_parm);
800 /* Call the base class assignment operator. */
801 releasing_vec parmvec (make_tree_vector_single (converted_parm));
802 finish_expr_stmt
803 (build_special_member_call (current_class_ref,
804 assign_op_identifier,
805 &parmvec,
806 base_binfo,
807 flags,
808 tf_warning_or_error));
809 }
810
811 /* Assign to each of the non-static data members. */
812 for (fields = TYPE_FIELDS (current_class_type);
813 fields;
814 fields = DECL_CHAIN (fields))
815 {
816 tree comp = current_class_ref;
817 tree init = parm;
818 tree field = fields;
819 tree expr_type;
820 int quals;
821
822 if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field))
823 continue;
824
825 expr_type = TREE_TYPE (field);
826
827 if (CP_TYPE_CONST_P (expr_type))
828 {
829 error ("non-static const member %q#D, cannot use default "
830 "assignment operator", field);
831 continue;
832 }
833 else if (TYPE_REF_P (expr_type))
834 {
835 error ("non-static reference member %q#D, cannot use "
836 "default assignment operator", field);
837 continue;
838 }
839
840 if (DECL_NAME (field))
841 {
842 if (VFIELD_NAME_P (DECL_NAME (field)))
843 continue;
844 }
845 else if (ANON_AGGR_TYPE_P (expr_type)
846 && TYPE_FIELDS (expr_type) != NULL_TREE)
847 /* Just use the field; anonymous types can't have
848 nontrivial copy ctors or assignment ops or this
849 function would be deleted. */;
850 else
851 continue;
852
853 comp = build3 (COMPONENT_REF, expr_type, comp, field, NULL_TREE);
854
855 /* Compute the type of init->field */
856 quals = cvquals;
857 if (DECL_MUTABLE_P (field))
858 quals &= ~TYPE_QUAL_CONST;
859 expr_type = cp_build_qualified_type (expr_type, quals);
860
861 init = build3 (COMPONENT_REF, expr_type, init, field, NULL_TREE);
862 if (move_p && !TYPE_REF_P (expr_type)
863 /* 'move' breaks bit-fields, and has no effect for scalars. */
864 && !scalarish_type_p (expr_type))
865 init = move (init);
866
867 if (DECL_NAME (field))
868 init = cp_build_modify_expr (input_location, comp, NOP_EXPR, init,
869 tf_warning_or_error);
870 else
871 init = build2 (MODIFY_EXPR, TREE_TYPE (comp), comp, init);
872 finish_expr_stmt (init);
873 }
874 }
875 finish_return_stmt (current_class_ref);
876 finish_compound_stmt (compound_stmt);
877 }
878
879 /* Synthesize FNDECL, a non-static member function. */
880
881 void
882 synthesize_method (tree fndecl)
883 {
884 bool nested = (current_function_decl != NULL_TREE);
885 tree context = decl_function_context (fndecl);
886 bool need_body = true;
887 tree stmt;
888 location_t save_input_location = input_location;
889 int error_count = errorcount;
890 int warning_count = warningcount + werrorcount;
891
892 /* Reset the source location, we might have been previously
893 deferred, and thus have saved where we were first needed. */
894 if (!DECL_INHERITED_CTOR (fndecl))
895 DECL_SOURCE_LOCATION (fndecl)
896 = DECL_SOURCE_LOCATION (TYPE_NAME (DECL_CONTEXT (fndecl)));
897
898 /* If we've been asked to synthesize a clone, just synthesize the
899 cloned function instead. Doing so will automatically fill in the
900 body for the clone. */
901 if (DECL_CLONED_FUNCTION_P (fndecl))
902 fndecl = DECL_CLONED_FUNCTION (fndecl);
903
904 /* We may be in the middle of deferred access check. Disable
905 it now. */
906 push_deferring_access_checks (dk_no_deferred);
907
908 if (! context)
909 push_to_top_level ();
910 else if (nested)
911 push_function_context ();
912
913 input_location = DECL_SOURCE_LOCATION (fndecl);
914
915 start_preparsed_function (fndecl, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED);
916 stmt = begin_function_body ();
917
918 if (DECL_ASSIGNMENT_OPERATOR_P (fndecl)
919 && DECL_OVERLOADED_OPERATOR_IS (fndecl, NOP_EXPR))
920 {
921 do_build_copy_assign (fndecl);
922 need_body = false;
923 }
924 else if (DECL_CONSTRUCTOR_P (fndecl))
925 {
926 tree arg_chain = FUNCTION_FIRST_USER_PARMTYPE (fndecl);
927 if (arg_chain != void_list_node)
928 do_build_copy_constructor (fndecl);
929 else
930 finish_mem_initializers (NULL_TREE);
931 }
932
933 /* If we haven't yet generated the body of the function, just
934 generate an empty compound statement. */
935 if (need_body)
936 {
937 tree compound_stmt;
938 compound_stmt = begin_compound_stmt (BCS_FN_BODY);
939 finish_compound_stmt (compound_stmt);
940 }
941
942 finish_function_body (stmt);
943 expand_or_defer_fn (finish_function (/*inline_p=*/false));
944
945 input_location = save_input_location;
946
947 if (! context)
948 pop_from_top_level ();
949 else if (nested)
950 pop_function_context ();
951
952 pop_deferring_access_checks ();
953
954 if (error_count != errorcount || warning_count != warningcount + werrorcount)
955 inform (input_location, "synthesized method %qD first required here",
956 fndecl);
957 }
958
959 /* Build a reference to type TYPE with cv-quals QUALS, which is an
960 rvalue if RVALUE is true. */
961
962 static tree
963 build_stub_type (tree type, int quals, bool rvalue)
964 {
965 tree argtype = cp_build_qualified_type (type, quals);
966 return cp_build_reference_type (argtype, rvalue);
967 }
968
969 /* Build a dummy glvalue from dereferencing a dummy reference of type
970 REFTYPE. */
971
972 static tree
973 build_stub_object (tree reftype)
974 {
975 if (!TYPE_REF_P (reftype))
976 reftype = cp_build_reference_type (reftype, /*rval*/true);
977 tree stub = build1 (CONVERT_EXPR, reftype, integer_one_node);
978 return convert_from_reference (stub);
979 }
980
981 /* Determine which function will be called when looking up NAME in TYPE,
982 called with a single ARGTYPE argument, or no argument if ARGTYPE is
983 null. FLAGS and COMPLAIN are as for build_new_method_call.
984
985 Returns a FUNCTION_DECL if all is well.
986 Returns NULL_TREE if overload resolution failed.
987 Returns error_mark_node if the chosen function cannot be called. */
988
989 static tree
990 locate_fn_flags (tree type, tree name, tree argtype, int flags,
991 tsubst_flags_t complain)
992 {
993 tree ob, fn, fns, binfo, rval;
994
995 if (TYPE_P (type))
996 binfo = TYPE_BINFO (type);
997 else
998 {
999 binfo = type;
1000 type = BINFO_TYPE (binfo);
1001 }
1002
1003 ob = build_stub_object (cp_build_reference_type (type, false));
1004 releasing_vec args;
1005 if (argtype)
1006 {
1007 if (TREE_CODE (argtype) == TREE_LIST)
1008 {
1009 for (tree elt = argtype; elt && elt != void_list_node;
1010 elt = TREE_CHAIN (elt))
1011 {
1012 tree type = TREE_VALUE (elt);
1013 tree arg = build_stub_object (type);
1014 vec_safe_push (args, arg);
1015 }
1016 }
1017 else
1018 {
1019 tree arg = build_stub_object (argtype);
1020 args->quick_push (arg);
1021 }
1022 }
1023
1024 fns = lookup_fnfields (binfo, name, 0);
1025 rval = build_new_method_call (ob, fns, &args, binfo, flags, &fn, complain);
1026
1027 if (fn && rval == error_mark_node)
1028 return rval;
1029 else
1030 return fn;
1031 }
1032
1033 /* Locate the dtor of TYPE. */
1034
1035 tree
1036 get_dtor (tree type, tsubst_flags_t complain)
1037 {
1038 tree fn = locate_fn_flags (type, complete_dtor_identifier, NULL_TREE,
1039 LOOKUP_NORMAL, complain);
1040 if (fn == error_mark_node)
1041 return NULL_TREE;
1042 return fn;
1043 }
1044
1045 /* Locate the default ctor of TYPE. */
1046
1047 tree
1048 locate_ctor (tree type)
1049 {
1050 tree fn;
1051
1052 push_deferring_access_checks (dk_no_check);
1053 fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
1054 LOOKUP_SPECULATIVE, tf_none);
1055 pop_deferring_access_checks ();
1056 if (fn == error_mark_node)
1057 return NULL_TREE;
1058 return fn;
1059 }
1060
1061 /* Likewise, but give any appropriate errors. */
1062
1063 tree
1064 get_default_ctor (tree type)
1065 {
1066 tree fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
1067 LOOKUP_NORMAL, tf_warning_or_error);
1068 if (fn == error_mark_node)
1069 return NULL_TREE;
1070 return fn;
1071 }
1072
1073 /* Locate the copy ctor of TYPE. */
1074
1075 tree
1076 get_copy_ctor (tree type, tsubst_flags_t complain)
1077 {
1078 int quals = (TYPE_HAS_CONST_COPY_CTOR (type)
1079 ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
1080 tree argtype = build_stub_type (type, quals, false);
1081 tree fn = locate_fn_flags (type, complete_ctor_identifier, argtype,
1082 LOOKUP_NORMAL, complain);
1083 if (fn == error_mark_node)
1084 return NULL_TREE;
1085 return fn;
1086 }
1087
1088 /* Locate the copy assignment operator of TYPE. */
1089
1090 tree
1091 get_copy_assign (tree type)
1092 {
1093 int quals = (TYPE_HAS_CONST_COPY_ASSIGN (type)
1094 ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
1095 tree argtype = build_stub_type (type, quals, false);
1096 tree fn = locate_fn_flags (type, assign_op_identifier, argtype,
1097 LOOKUP_NORMAL, tf_warning_or_error);
1098 if (fn == error_mark_node)
1099 return NULL_TREE;
1100 return fn;
1101 }
1102
1103 /* walk_tree helper function for is_trivially_xible. If *TP is a call,
1104 return it if it calls something other than a trivial special member
1105 function. */
1106
1107 static tree
1108 check_nontriv (tree *tp, int *, void *)
1109 {
1110 tree fn = cp_get_callee (*tp);
1111 if (fn == NULL_TREE)
1112 return NULL_TREE;
1113
1114 if (TREE_CODE (fn) == ADDR_EXPR)
1115 fn = TREE_OPERAND (fn, 0);
1116
1117 if (TREE_CODE (fn) != FUNCTION_DECL
1118 || !trivial_fn_p (fn))
1119 return fn;
1120 return NULL_TREE;
1121 }
1122
1123 /* Return declval<T>() = declval<U>() treated as an unevaluated operand. */
1124
1125 static tree
1126 assignable_expr (tree to, tree from)
1127 {
1128 ++cp_unevaluated_operand;
1129 to = build_stub_object (to);
1130 from = build_stub_object (from);
1131 tree r = cp_build_modify_expr (input_location, to, NOP_EXPR, from, tf_none);
1132 --cp_unevaluated_operand;
1133 return r;
1134 }
1135
1136 /* The predicate condition for a template specialization
1137 is_constructible<T, Args...> shall be satisfied if and only if the
1138 following variable definition would be well-formed for some invented
1139 variable t: T t(create<Args>()...);
1140
1141 Return something equivalent in well-formedness and triviality. */
1142
1143 static tree
1144 constructible_expr (tree to, tree from)
1145 {
1146 tree expr;
1147 cp_unevaluated cp_uneval_guard;
1148 if (CLASS_TYPE_P (to))
1149 {
1150 tree ctype = to;
1151 vec<tree, va_gc> *args = NULL;
1152 if (!TYPE_REF_P (to))
1153 to = cp_build_reference_type (to, /*rval*/false);
1154 tree ob = build_stub_object (to);
1155 for (; from; from = TREE_CHAIN (from))
1156 vec_safe_push (args, build_stub_object (TREE_VALUE (from)));
1157 expr = build_special_member_call (ob, complete_ctor_identifier, &args,
1158 ctype, LOOKUP_NORMAL, tf_none);
1159 if (expr == error_mark_node)
1160 return error_mark_node;
1161 /* The current state of the standard vis-a-vis LWG 2116 is that
1162 is_*constructible involves destruction as well. */
1163 if (type_build_dtor_call (ctype))
1164 {
1165 tree dtor = build_special_member_call (ob, complete_dtor_identifier,
1166 NULL, ctype, LOOKUP_NORMAL,
1167 tf_none);
1168 if (dtor == error_mark_node)
1169 return error_mark_node;
1170 if (!TYPE_HAS_TRIVIAL_DESTRUCTOR (ctype))
1171 expr = build2 (COMPOUND_EXPR, void_type_node, expr, dtor);
1172 }
1173 }
1174 else
1175 {
1176 if (from == NULL_TREE)
1177 return build_value_init (strip_array_types (to), tf_none);
1178 else if (TREE_CHAIN (from))
1179 return error_mark_node; // too many initializers
1180 from = build_stub_object (TREE_VALUE (from));
1181 expr = perform_direct_initialization_if_possible (to, from,
1182 /*cast*/false,
1183 tf_none);
1184 }
1185 return expr;
1186 }
1187
1188 /* Returns a tree iff TO is assignable (if CODE is MODIFY_EXPR) or
1189 constructible (otherwise) from FROM, which is a single type for
1190 assignment or a list of types for construction. */
1191
1192 static tree
1193 is_xible_helper (enum tree_code code, tree to, tree from, bool trivial)
1194 {
1195 if (VOID_TYPE_P (to) || ABSTRACT_CLASS_TYPE_P (to)
1196 || (from && FUNC_OR_METHOD_TYPE_P (from)
1197 && (TYPE_READONLY (from) || FUNCTION_REF_QUALIFIED (from))))
1198 return error_mark_node;
1199 tree expr;
1200 if (code == MODIFY_EXPR)
1201 expr = assignable_expr (to, from);
1202 else if (trivial && from && TREE_CHAIN (from))
1203 return error_mark_node; // only 0- and 1-argument ctors can be trivial
1204 else
1205 expr = constructible_expr (to, from);
1206 return expr;
1207 }
1208
1209 /* Returns true iff TO is trivially assignable (if CODE is MODIFY_EXPR) or
1210 constructible (otherwise) from FROM, which is a single type for
1211 assignment or a list of types for construction. */
1212
1213 bool
1214 is_trivially_xible (enum tree_code code, tree to, tree from)
1215 {
1216 tree expr;
1217 expr = is_xible_helper (code, to, from, /*trivial*/true);
1218
1219 if (expr == NULL_TREE || expr == error_mark_node)
1220 return false;
1221 tree nt = cp_walk_tree_without_duplicates (&expr, check_nontriv, NULL);
1222 return !nt;
1223 }
1224
1225 /* Returns true iff TO is assignable (if CODE is MODIFY_EXPR) or
1226 constructible (otherwise) from FROM, which is a single type for
1227 assignment or a list of types for construction. */
1228
1229 bool
1230 is_xible (enum tree_code code, tree to, tree from)
1231 {
1232 tree expr = is_xible_helper (code, to, from, /*trivial*/false);
1233 if (expr == error_mark_node)
1234 return false;
1235 return !!expr;
1236 }
1237
1238 /* Subroutine of synthesized_method_walk. Update SPEC_P, TRIVIAL_P and
1239 DELETED_P or give an error message MSG with argument ARG. */
1240
1241 static void
1242 process_subob_fn (tree fn, tree *spec_p, bool *trivial_p,
1243 bool *deleted_p, bool *constexpr_p,
1244 bool diag, tree arg, bool dtor_from_ctor = false)
1245 {
1246 if (!fn || fn == error_mark_node)
1247 {
1248 if (deleted_p)
1249 *deleted_p = true;
1250 return;
1251 }
1252
1253 if (spec_p)
1254 {
1255 if (!maybe_instantiate_noexcept (fn))
1256 *spec_p = error_mark_node;
1257 else
1258 {
1259 tree raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn));
1260 *spec_p = merge_exception_specifiers (*spec_p, raises);
1261 }
1262 }
1263
1264 if (!trivial_fn_p (fn) && !dtor_from_ctor)
1265 {
1266 if (trivial_p)
1267 *trivial_p = false;
1268 if (TREE_CODE (arg) == FIELD_DECL
1269 && TREE_CODE (DECL_CONTEXT (arg)) == UNION_TYPE)
1270 {
1271 if (deleted_p)
1272 *deleted_p = true;
1273 if (diag)
1274 error ("union member %q+D with non-trivial %qD", arg, fn);
1275 }
1276 }
1277
1278 if (constexpr_p && !DECL_DECLARED_CONSTEXPR_P (fn))
1279 {
1280 *constexpr_p = false;
1281 if (diag)
1282 {
1283 inform (DECL_SOURCE_LOCATION (fn),
1284 "defaulted constructor calls non-%<constexpr%> %qD", fn);
1285 explain_invalid_constexpr_fn (fn);
1286 }
1287 }
1288 }
1289
1290 /* Categorize various special_function_kinds. */
1291 #define SFK_CTOR_P(sfk) \
1292 ((sfk) >= sfk_constructor && (sfk) <= sfk_move_constructor)
1293 #define SFK_DTOR_P(sfk) \
1294 ((sfk) == sfk_destructor || (sfk) == sfk_virtual_destructor)
1295 #define SFK_ASSIGN_P(sfk) \
1296 ((sfk) == sfk_copy_assignment || (sfk) == sfk_move_assignment)
1297 #define SFK_COPY_P(sfk) \
1298 ((sfk) == sfk_copy_constructor || (sfk) == sfk_copy_assignment)
1299 #define SFK_MOVE_P(sfk) \
1300 ((sfk) == sfk_move_constructor || (sfk) == sfk_move_assignment)
1301
1302 /* Subroutine of synthesized_method_walk to allow recursion into anonymous
1303 aggregates. If DTOR_FROM_CTOR is true, we're walking subobject destructors
1304 called from a synthesized constructor, in which case we don't consider
1305 the triviality of the subobject destructor. */
1306
1307 static void
1308 walk_field_subobs (tree fields, special_function_kind sfk, tree fnname,
1309 int quals, tree *spec_p, bool *trivial_p,
1310 bool *deleted_p, bool *constexpr_p,
1311 bool diag, int flags, tsubst_flags_t complain,
1312 bool dtor_from_ctor)
1313 {
1314 tree field;
1315 for (field = fields; field; field = DECL_CHAIN (field))
1316 {
1317 tree mem_type, argtype, rval;
1318
1319 if (TREE_CODE (field) != FIELD_DECL
1320 || DECL_ARTIFICIAL (field))
1321 continue;
1322
1323 /* Variant members only affect deletedness. In particular, they don't
1324 affect the exception-specification of a user-provided destructor,
1325 which we're figuring out via get_defaulted_eh_spec. So if we aren't
1326 asking if this is deleted, don't even look up the function; we don't
1327 want an error about a deleted function we aren't actually calling. */
1328 if (sfk == sfk_destructor && deleted_p == NULL
1329 && TREE_CODE (DECL_CONTEXT (field)) == UNION_TYPE)
1330 break;
1331
1332 mem_type = strip_array_types (TREE_TYPE (field));
1333 if (SFK_ASSIGN_P (sfk))
1334 {
1335 bool bad = true;
1336 if (CP_TYPE_CONST_P (mem_type) && !CLASS_TYPE_P (mem_type))
1337 {
1338 if (diag)
1339 error ("non-static const member %q#D, cannot use default "
1340 "assignment operator", field);
1341 }
1342 else if (TYPE_REF_P (mem_type))
1343 {
1344 if (diag)
1345 error ("non-static reference member %q#D, cannot use "
1346 "default assignment operator", field);
1347 }
1348 else
1349 bad = false;
1350
1351 if (bad && deleted_p)
1352 *deleted_p = true;
1353 }
1354 else if (sfk == sfk_constructor || sfk == sfk_inheriting_constructor)
1355 {
1356 bool bad;
1357
1358 if (DECL_INITIAL (field))
1359 {
1360 if (diag && DECL_INITIAL (field) == error_mark_node)
1361 inform (DECL_SOURCE_LOCATION (field),
1362 "initializer for %q#D is invalid", field);
1363 if (trivial_p)
1364 *trivial_p = false;
1365 /* Core 1351: If the field has an NSDMI that could throw, the
1366 default constructor is noexcept(false). */
1367 if (spec_p)
1368 {
1369 tree nsdmi = get_nsdmi (field, /*ctor*/false, complain);
1370 if (nsdmi == error_mark_node)
1371 *spec_p = error_mark_node;
1372 else if (*spec_p != error_mark_node
1373 && !expr_noexcept_p (nsdmi, complain))
1374 *spec_p = noexcept_false_spec;
1375 }
1376 /* Don't do the normal processing. */
1377 continue;
1378 }
1379
1380 bad = false;
1381 if (CP_TYPE_CONST_P (mem_type)
1382 && default_init_uninitialized_part (mem_type))
1383 {
1384 if (diag)
1385 {
1386 error ("uninitialized const member in %q#T",
1387 current_class_type);
1388 inform (DECL_SOURCE_LOCATION (field),
1389 "%q#D should be initialized", field);
1390 }
1391 bad = true;
1392 }
1393 else if (TYPE_REF_P (mem_type))
1394 {
1395 if (diag)
1396 {
1397 error ("uninitialized reference member in %q#T",
1398 current_class_type);
1399 inform (DECL_SOURCE_LOCATION (field),
1400 "%q#D should be initialized", field);
1401 }
1402 bad = true;
1403 }
1404
1405 if (bad && deleted_p)
1406 *deleted_p = true;
1407
1408 /* For an implicitly-defined default constructor to be constexpr,
1409 every member must have a user-provided default constructor or
1410 an explicit initializer. */
1411 if (constexpr_p && !CLASS_TYPE_P (mem_type)
1412 && TREE_CODE (DECL_CONTEXT (field)) != UNION_TYPE)
1413 {
1414 *constexpr_p = false;
1415 if (diag)
1416 inform (DECL_SOURCE_LOCATION (field),
1417 "defaulted default constructor does not "
1418 "initialize %q#D", field);
1419 }
1420 }
1421 else if (sfk == sfk_copy_constructor)
1422 {
1423 /* 12.8p11b5 */
1424 if (TYPE_REF_P (mem_type)
1425 && TYPE_REF_IS_RVALUE (mem_type))
1426 {
1427 if (diag)
1428 error ("copying non-static data member %q#D of rvalue "
1429 "reference type", field);
1430 if (deleted_p)
1431 *deleted_p = true;
1432 }
1433 }
1434
1435 if (!CLASS_TYPE_P (mem_type))
1436 continue;
1437
1438 if (ANON_AGGR_TYPE_P (mem_type))
1439 {
1440 walk_field_subobs (TYPE_FIELDS (mem_type), sfk, fnname, quals,
1441 spec_p, trivial_p, deleted_p, constexpr_p,
1442 diag, flags, complain, dtor_from_ctor);
1443 continue;
1444 }
1445
1446 if (SFK_COPY_P (sfk) || SFK_MOVE_P (sfk))
1447 {
1448 int mem_quals = cp_type_quals (mem_type) | quals;
1449 if (DECL_MUTABLE_P (field))
1450 mem_quals &= ~TYPE_QUAL_CONST;
1451 argtype = build_stub_type (mem_type, mem_quals, SFK_MOVE_P (sfk));
1452 }
1453 else
1454 argtype = NULL_TREE;
1455
1456 rval = locate_fn_flags (mem_type, fnname, argtype, flags, complain);
1457
1458 process_subob_fn (rval, spec_p, trivial_p, deleted_p,
1459 constexpr_p, diag, field, dtor_from_ctor);
1460 }
1461 }
1462
1463 /* Base walker helper for synthesized_method_walk. Inspect a direct
1464 or virtual base. BINFO is the parent type's binfo. BASE_BINFO is
1465 the base binfo of interests. All other parms are as for
1466 synthesized_method_walk, or its local vars. */
1467
1468 static tree
1469 synthesized_method_base_walk (tree binfo, tree base_binfo,
1470 special_function_kind sfk, tree fnname, int quals,
1471 tree *inheriting_ctor, tree inherited_parms,
1472 int flags, bool diag,
1473 tree *spec_p, bool *trivial_p,
1474 bool *deleted_p, bool *constexpr_p)
1475 {
1476 bool inherited_binfo = false;
1477 tree argtype = NULL_TREE;
1478 deferring_kind defer = dk_no_deferred;
1479
1480 if (SFK_COPY_P (sfk) || SFK_MOVE_P (sfk))
1481 argtype = build_stub_type (BINFO_TYPE (base_binfo), quals, SFK_MOVE_P (sfk));
1482 else if (inheriting_ctor
1483 && (inherited_binfo
1484 = binfo_inherited_from (binfo, base_binfo, *inheriting_ctor)))
1485 {
1486 argtype = inherited_parms;
1487 /* Don't check access on the inherited constructor. */
1488 if (flag_new_inheriting_ctors)
1489 defer = dk_deferred;
1490 }
1491 else if (cxx_dialect >= cxx14 && sfk == sfk_virtual_destructor
1492 && BINFO_VIRTUAL_P (base_binfo)
1493 && ABSTRACT_CLASS_TYPE_P (BINFO_TYPE (binfo)))
1494 /* Don't check access when looking at vbases of abstract class's
1495 virtual destructor. */
1496 defer = dk_no_check;
1497
1498 if (defer != dk_no_deferred)
1499 push_deferring_access_checks (defer);
1500 tree rval = locate_fn_flags (base_binfo, fnname, argtype, flags,
1501 diag ? tf_warning_or_error : tf_none);
1502 if (defer != dk_no_deferred)
1503 pop_deferring_access_checks ();
1504
1505 /* Replace an inherited template with the appropriate specialization. */
1506 if (inherited_binfo && rval
1507 && DECL_P (*inheriting_ctor) && DECL_P (rval)
1508 && DECL_CONTEXT (*inheriting_ctor) == DECL_CONTEXT (rval))
1509 *inheriting_ctor = DECL_CLONED_FUNCTION (rval);
1510
1511 process_subob_fn (rval, spec_p, trivial_p, deleted_p,
1512 constexpr_p, diag, BINFO_TYPE (base_binfo));
1513 if (SFK_CTOR_P (sfk) &&
1514 (!BINFO_VIRTUAL_P (base_binfo)
1515 || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (BINFO_TYPE (base_binfo))))
1516 {
1517 /* In a constructor we also need to check the subobject
1518 destructors for cleanup of partially constructed objects. */
1519 tree dtor = locate_fn_flags (base_binfo, complete_dtor_identifier,
1520 NULL_TREE, flags,
1521 diag ? tf_warning_or_error : tf_none);
1522 /* Note that we don't pass down trivial_p; the subobject
1523 destructors don't affect triviality of the constructor. Nor
1524 do they affect constexpr-ness (a constant expression doesn't
1525 throw) or exception-specification (a throw from one of the
1526 dtors would be a double-fault). */
1527 process_subob_fn (dtor, NULL, NULL, deleted_p, NULL, false,
1528 BINFO_TYPE (base_binfo), /*dtor_from_ctor*/true);
1529 }
1530
1531 return rval;
1532 }
1533
1534 /* The caller wants to generate an implicit declaration of SFK for
1535 CTYPE which is const if relevant and CONST_P is set. If SPEC_P,
1536 TRIVIAL_P, DELETED_P or CONSTEXPR_P are non-null, set their
1537 referent appropriately. If DIAG is true, we're either being called
1538 from maybe_explain_implicit_delete to give errors, or if
1539 CONSTEXPR_P is non-null, from explain_invalid_constexpr_fn. */
1540
1541 static void
1542 synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p,
1543 tree *spec_p, bool *trivial_p, bool *deleted_p,
1544 bool *constexpr_p, bool diag,
1545 tree *inheriting_ctor, tree inherited_parms)
1546 {
1547 tree binfo, base_binfo;
1548 int i;
1549
1550 /* SFK must be exactly one category. */
1551 gcc_checking_assert (SFK_DTOR_P(sfk) + SFK_CTOR_P(sfk)
1552 + SFK_ASSIGN_P(sfk) == 1);
1553
1554 if (spec_p)
1555 *spec_p = (cxx_dialect >= cxx11 ? noexcept_true_spec : empty_except_spec);
1556
1557 if (deleted_p)
1558 {
1559 /* "The closure type associated with a lambda-expression has a deleted
1560 default constructor and a deleted copy assignment operator."
1561 This is diagnosed in maybe_explain_implicit_delete.
1562 In C++2a, only lambda-expressions with lambda-captures have those
1563 deleted. */
1564 if (LAMBDA_TYPE_P (ctype)
1565 && (sfk == sfk_constructor || sfk == sfk_copy_assignment)
1566 && (cxx_dialect < cxx2a
1567 || LAMBDA_EXPR_CAPTURE_LIST (CLASSTYPE_LAMBDA_EXPR (ctype))
1568 || LAMBDA_EXPR_DEFAULT_CAPTURE_MODE
1569 (CLASSTYPE_LAMBDA_EXPR (ctype)) != CPLD_NONE))
1570 {
1571 *deleted_p = true;
1572 return;
1573 }
1574
1575 *deleted_p = false;
1576 }
1577
1578 bool check_vdtor = false;
1579 tree fnname;
1580
1581 if (SFK_DTOR_P (sfk))
1582 {
1583 check_vdtor = true;
1584 /* The synthesized method will call base dtors, but check complete
1585 here to avoid having to deal with VTT. */
1586 fnname = complete_dtor_identifier;
1587 }
1588 else if (SFK_ASSIGN_P (sfk))
1589 fnname = assign_op_identifier;
1590 else
1591 fnname = complete_ctor_identifier;
1592
1593 gcc_assert ((sfk == sfk_inheriting_constructor)
1594 == (inheriting_ctor && *inheriting_ctor != NULL_TREE));
1595
1596 /* If that user-written default constructor would satisfy the
1597 requirements of a constexpr constructor (7.1.5), the
1598 implicitly-defined default constructor is constexpr.
1599
1600 The implicitly-defined copy/move assignment operator is constexpr if
1601 - X is a literal type, and
1602 - the assignment operator selected to copy/move each direct base class
1603 subobject is a constexpr function, and
1604 - for each non-static data member of X that is of class type (or array
1605 thereof), the assignment operator selected to copy/move that
1606 member is a constexpr function. */
1607 if (constexpr_p)
1608 *constexpr_p = (SFK_CTOR_P (sfk)
1609 || (SFK_ASSIGN_P (sfk) && cxx_dialect >= cxx14));
1610
1611 bool expected_trivial = type_has_trivial_fn (ctype, sfk);
1612 if (trivial_p)
1613 *trivial_p = expected_trivial;
1614
1615 /* The TYPE_HAS_COMPLEX_* flags tell us about constraints from base
1616 class versions and other properties of the type. But a subobject
1617 class can be trivially copyable and yet have overload resolution
1618 choose a template constructor for initialization, depending on
1619 rvalueness and cv-quals. And furthermore, a member in a base might
1620 be trivial but deleted or otherwise not callable. So we can't exit
1621 early in C++0x. The same considerations apply in C++98/03, but
1622 there the definition of triviality does not consider overload
1623 resolution, so a constructor can be trivial even if it would otherwise
1624 call a non-trivial constructor. */
1625 if (expected_trivial
1626 && (!(SFK_COPY_P (sfk) || SFK_MOVE_P (sfk)) || cxx_dialect < cxx11))
1627 {
1628 if (constexpr_p && sfk == sfk_constructor)
1629 {
1630 bool cx = trivial_default_constructor_is_constexpr (ctype);
1631 *constexpr_p = cx;
1632 if (diag && !cx && TREE_CODE (ctype) == UNION_TYPE)
1633 /* A trivial constructor doesn't have any NSDMI. */
1634 inform (input_location, "defaulted default constructor does "
1635 "not initialize any non-static data member");
1636 }
1637 if (!diag && cxx_dialect < cxx11)
1638 return;
1639 }
1640
1641 ++cp_unevaluated_operand;
1642 ++c_inhibit_evaluation_warnings;
1643 push_deferring_access_checks (dk_no_deferred);
1644
1645 tree scope = push_scope (ctype);
1646
1647 int flags = LOOKUP_NORMAL | LOOKUP_SPECULATIVE;
1648 if (sfk != sfk_inheriting_constructor)
1649 flags |= LOOKUP_DEFAULTED;
1650
1651 tsubst_flags_t complain = diag ? tf_warning_or_error : tf_none;
1652 if (diag && spec_p)
1653 /* We're in get_defaulted_eh_spec; we don't actually want any walking
1654 diagnostics, we just want complain set. */
1655 diag = false;
1656 int quals = const_p ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED;
1657
1658 for (binfo = TYPE_BINFO (ctype), i = 0;
1659 BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
1660 {
1661 if (!SFK_ASSIGN_P (sfk) && BINFO_VIRTUAL_P (base_binfo))
1662 /* We'll handle virtual bases below. */
1663 continue;
1664
1665 tree fn = synthesized_method_base_walk (binfo, base_binfo,
1666 sfk, fnname, quals,
1667 inheriting_ctor, inherited_parms,
1668 flags, diag, spec_p, trivial_p,
1669 deleted_p, constexpr_p);
1670
1671 if (diag && SFK_ASSIGN_P (sfk) && SFK_MOVE_P (sfk)
1672 && BINFO_VIRTUAL_P (base_binfo)
1673 && fn && TREE_CODE (fn) == FUNCTION_DECL
1674 && move_fn_p (fn) && !trivial_fn_p (fn)
1675 && vbase_has_user_provided_move_assign (BINFO_TYPE (base_binfo)))
1676 warning (OPT_Wvirtual_move_assign,
1677 "defaulted move assignment for %qT calls a non-trivial "
1678 "move assignment operator for virtual base %qT",
1679 ctype, BINFO_TYPE (base_binfo));
1680
1681 if (check_vdtor && type_has_virtual_destructor (BINFO_TYPE (base_binfo)))
1682 {
1683 /* Unlike for base ctor/op=/dtor, for operator delete it's fine
1684 to have a null fn (no class-specific op delete). */
1685 fn = locate_fn_flags (ctype, ovl_op_identifier (false, DELETE_EXPR),
1686 ptr_type_node, flags, tf_none);
1687 if (fn && fn == error_mark_node)
1688 {
1689 if (complain & tf_error)
1690 locate_fn_flags (ctype, ovl_op_identifier (false, DELETE_EXPR),
1691 ptr_type_node, flags, complain);
1692 if (deleted_p)
1693 *deleted_p = true;
1694 }
1695 check_vdtor = false;
1696 }
1697 }
1698
1699 vec<tree, va_gc> *vbases = CLASSTYPE_VBASECLASSES (ctype);
1700 if (SFK_ASSIGN_P (sfk))
1701 /* Already examined vbases above. */;
1702 else if (vec_safe_is_empty (vbases))
1703 /* No virtual bases to worry about. */;
1704 else if (ABSTRACT_CLASS_TYPE_P (ctype) && cxx_dialect >= cxx14
1705 /* DR 1658 specifis that vbases of abstract classes are
1706 ignored for both ctors and dtors. Except DR 2338
1707 overrides that skipping when determing the eh-spec of a
1708 virtual destructor. */
1709 && sfk != sfk_virtual_destructor)
1710 /* Vbase cdtors are not relevant. */;
1711 else
1712 {
1713 if (constexpr_p)
1714 *constexpr_p = false;
1715
1716 FOR_EACH_VEC_ELT (*vbases, i, base_binfo)
1717 synthesized_method_base_walk (binfo, base_binfo, sfk, fnname, quals,
1718 inheriting_ctor, inherited_parms,
1719 flags, diag,
1720 spec_p, trivial_p, deleted_p, constexpr_p);
1721 }
1722
1723 /* Now handle the non-static data members. */
1724 walk_field_subobs (TYPE_FIELDS (ctype), sfk, fnname, quals,
1725 spec_p, trivial_p, deleted_p, constexpr_p,
1726 diag, flags, complain, /*dtor_from_ctor*/false);
1727 if (SFK_CTOR_P (sfk))
1728 walk_field_subobs (TYPE_FIELDS (ctype), sfk_destructor,
1729 complete_dtor_identifier, TYPE_UNQUALIFIED,
1730 NULL, NULL, deleted_p, NULL,
1731 false, flags, complain, /*dtor_from_ctor*/true);
1732
1733 pop_scope (scope);
1734
1735 pop_deferring_access_checks ();
1736 --cp_unevaluated_operand;
1737 --c_inhibit_evaluation_warnings;
1738 }
1739
1740 /* DECL is a defaulted function whose exception specification is now
1741 needed. Return what it should be. */
1742
1743 tree
1744 get_defaulted_eh_spec (tree decl, tsubst_flags_t complain)
1745 {
1746 if (DECL_CLONED_FUNCTION_P (decl))
1747 decl = DECL_CLONED_FUNCTION (decl);
1748 special_function_kind sfk = special_function_p (decl);
1749 tree ctype = DECL_CONTEXT (decl);
1750 tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
1751 tree parm_type = TREE_VALUE (parms);
1752 bool const_p = CP_TYPE_CONST_P (non_reference (parm_type));
1753 tree spec = empty_except_spec;
1754 bool diag = !DECL_DELETED_FN (decl) && (complain & tf_error);
1755 tree inh = DECL_INHERITED_CTOR (decl);
1756 if (SFK_DTOR_P (sfk) && DECL_VIRTUAL_P (decl))
1757 /* We have to examine virtual bases even if abstract. */
1758 sfk = sfk_virtual_destructor;
1759 bool pushed = false;
1760 if (CLASSTYPE_TEMPLATE_INSTANTIATION (ctype))
1761 pushed = push_tinst_level (decl);
1762 synthesized_method_walk (ctype, sfk, const_p, &spec, NULL, NULL,
1763 NULL, diag, &inh, parms);
1764 if (pushed)
1765 pop_tinst_level ();
1766 return spec;
1767 }
1768
1769 /* DECL is a deleted function. If it's implicitly deleted, explain why and
1770 return true; else return false. */
1771
1772 bool
1773 maybe_explain_implicit_delete (tree decl)
1774 {
1775 /* If decl is a clone, get the primary variant. */
1776 decl = DECL_ORIGIN (decl);
1777 gcc_assert (DECL_DELETED_FN (decl));
1778 if (DECL_DEFAULTED_FN (decl))
1779 {
1780 /* Not marked GTY; it doesn't need to be GC'd or written to PCH. */
1781 static hash_set<tree> *explained;
1782
1783 special_function_kind sfk;
1784 location_t loc;
1785 bool informed;
1786 tree ctype;
1787
1788 if (!explained)
1789 explained = new hash_set<tree>;
1790 if (explained->add (decl))
1791 return true;
1792
1793 sfk = special_function_p (decl);
1794 ctype = DECL_CONTEXT (decl);
1795 loc = input_location;
1796 input_location = DECL_SOURCE_LOCATION (decl);
1797
1798 informed = false;
1799 if (LAMBDA_TYPE_P (ctype))
1800 {
1801 informed = true;
1802 if (sfk == sfk_constructor)
1803 inform (DECL_SOURCE_LOCATION (decl),
1804 "a lambda closure type has a deleted default constructor");
1805 else if (sfk == sfk_copy_assignment)
1806 inform (DECL_SOURCE_LOCATION (decl),
1807 "a lambda closure type has a deleted copy assignment operator");
1808 else
1809 informed = false;
1810 }
1811 else if (DECL_ARTIFICIAL (decl)
1812 && (sfk == sfk_copy_assignment || sfk == sfk_copy_constructor)
1813 && classtype_has_move_assign_or_move_ctor_p (ctype, true))
1814 {
1815 inform (DECL_SOURCE_LOCATION (decl),
1816 "%q#D is implicitly declared as deleted because %qT "
1817 "declares a move constructor or move assignment operator",
1818 decl, ctype);
1819 informed = true;
1820 }
1821 else if (sfk == sfk_inheriting_constructor)
1822 {
1823 tree binfo = inherited_ctor_binfo (decl);
1824 if (TREE_CODE (binfo) != TREE_BINFO)
1825 {
1826 inform (DECL_SOURCE_LOCATION (decl),
1827 "%q#D inherits from multiple base subobjects",
1828 decl);
1829 informed = true;
1830 }
1831 }
1832 if (!informed)
1833 {
1834 tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
1835 bool const_p = false;
1836 if (parms)
1837 {
1838 tree parm_type = TREE_VALUE (parms);
1839 const_p = CP_TYPE_CONST_P (non_reference (parm_type));
1840 }
1841 tree raises = NULL_TREE;
1842 bool deleted_p = false;
1843 tree scope = push_scope (ctype);
1844 tree inh = DECL_INHERITED_CTOR (decl);
1845
1846 synthesized_method_walk (ctype, sfk, const_p,
1847 &raises, NULL, &deleted_p, NULL, false,
1848 &inh, parms);
1849 if (deleted_p)
1850 {
1851 inform (DECL_SOURCE_LOCATION (decl),
1852 "%q#D is implicitly deleted because the default "
1853 "definition would be ill-formed:", decl);
1854 synthesized_method_walk (ctype, sfk, const_p,
1855 NULL, NULL, &deleted_p, NULL, true,
1856 &inh, parms);
1857 }
1858 else if (!comp_except_specs
1859 (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl)),
1860 raises, ce_normal))
1861 inform (DECL_SOURCE_LOCATION (decl), "%q#F is implicitly "
1862 "deleted because its exception-specification does not "
1863 "match the implicit exception-specification %qX",
1864 decl, raises);
1865 else if (flag_checking)
1866 gcc_unreachable ();
1867
1868 pop_scope (scope);
1869 }
1870
1871 input_location = loc;
1872 return true;
1873 }
1874 return false;
1875 }
1876
1877 /* DECL is a defaulted function which was declared constexpr. Explain why
1878 it can't be constexpr. */
1879
1880 void
1881 explain_implicit_non_constexpr (tree decl)
1882 {
1883 tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
1884 bool const_p = CP_TYPE_CONST_P (non_reference (TREE_VALUE (parms)));
1885 tree inh = DECL_INHERITED_CTOR (decl);
1886 bool dummy;
1887 synthesized_method_walk (DECL_CLASS_CONTEXT (decl),
1888 special_function_p (decl), const_p,
1889 NULL, NULL, NULL, &dummy, true,
1890 &inh, parms);
1891 }
1892
1893 /* DECL is an instantiation of an inheriting constructor template. Deduce
1894 the correct exception-specification and deletedness for this particular
1895 specialization. */
1896
1897 void
1898 deduce_inheriting_ctor (tree decl)
1899 {
1900 decl = DECL_ORIGIN (decl);
1901 gcc_assert (DECL_INHERITED_CTOR (decl));
1902 tree spec;
1903 bool trivial, constexpr_, deleted;
1904 tree inh = DECL_INHERITED_CTOR (decl);
1905 synthesized_method_walk (DECL_CONTEXT (decl), sfk_inheriting_constructor,
1906 false, &spec, &trivial, &deleted, &constexpr_,
1907 /*diag*/false,
1908 &inh,
1909 FUNCTION_FIRST_USER_PARMTYPE (decl));
1910 if (TREE_CODE (inherited_ctor_binfo (decl)) != TREE_BINFO)
1911 /* Inherited the same constructor from different base subobjects. */
1912 deleted = true;
1913 DECL_DELETED_FN (decl) = deleted;
1914 TREE_TYPE (decl) = build_exception_variant (TREE_TYPE (decl), spec);
1915 SET_DECL_INHERITED_CTOR (decl, inh);
1916
1917 tree clone;
1918 FOR_EACH_CLONE (clone, decl)
1919 {
1920 DECL_DELETED_FN (clone) = deleted;
1921 TREE_TYPE (clone) = build_exception_variant (TREE_TYPE (clone), spec);
1922 SET_DECL_INHERITED_CTOR (clone, inh);
1923 }
1924 }
1925
1926 /* Implicitly declare the special function indicated by KIND, as a
1927 member of TYPE. For copy constructors and assignment operators,
1928 CONST_P indicates whether these functions should take a const
1929 reference argument or a non-const reference. Returns the
1930 FUNCTION_DECL for the implicitly declared function. */
1931
1932 tree
1933 implicitly_declare_fn (special_function_kind kind, tree type,
1934 bool const_p, tree inherited_ctor,
1935 tree inherited_parms)
1936 {
1937 tree fn;
1938 tree parameter_types = void_list_node;
1939 tree return_type;
1940 tree fn_type;
1941 tree raises = empty_except_spec;
1942 tree rhs_parm_type = NULL_TREE;
1943 tree this_parm;
1944 tree name;
1945 HOST_WIDE_INT saved_processing_template_decl;
1946 bool deleted_p;
1947 bool constexpr_p;
1948
1949 /* Because we create declarations for implicitly declared functions
1950 lazily, we may be creating the declaration for a member of TYPE
1951 while in some completely different context. However, TYPE will
1952 never be a dependent class (because we never want to do lookups
1953 for implicitly defined functions in a dependent class).
1954 Furthermore, we must set PROCESSING_TEMPLATE_DECL to zero here
1955 because we only create clones for constructors and destructors
1956 when not in a template. */
1957 gcc_assert (!dependent_type_p (type));
1958 saved_processing_template_decl = processing_template_decl;
1959 processing_template_decl = 0;
1960
1961 type = TYPE_MAIN_VARIANT (type);
1962
1963 if (targetm.cxx.cdtor_returns_this ())
1964 {
1965 if (kind == sfk_destructor)
1966 /* See comment in check_special_function_return_type. */
1967 return_type = build_pointer_type (void_type_node);
1968 else
1969 return_type = build_pointer_type (type);
1970 }
1971 else
1972 return_type = void_type_node;
1973
1974 switch (kind)
1975 {
1976 case sfk_destructor:
1977 /* Destructor. */
1978 name = dtor_identifier;
1979 break;
1980
1981 case sfk_constructor:
1982 /* Default constructor. */
1983 name = ctor_identifier;
1984 break;
1985
1986 case sfk_copy_constructor:
1987 case sfk_copy_assignment:
1988 case sfk_move_constructor:
1989 case sfk_move_assignment:
1990 case sfk_inheriting_constructor:
1991 {
1992 if (kind == sfk_copy_assignment
1993 || kind == sfk_move_assignment)
1994 {
1995 return_type = build_reference_type (type);
1996 name = assign_op_identifier;
1997 }
1998 else
1999 name = ctor_identifier;
2000
2001 if (kind == sfk_inheriting_constructor)
2002 parameter_types = inherited_parms;
2003 else
2004 {
2005 if (const_p)
2006 rhs_parm_type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
2007 else
2008 rhs_parm_type = type;
2009 bool move_p = (kind == sfk_move_assignment
2010 || kind == sfk_move_constructor);
2011 rhs_parm_type = cp_build_reference_type (rhs_parm_type, move_p);
2012
2013 parameter_types = tree_cons (NULL_TREE, rhs_parm_type, parameter_types);
2014 }
2015 break;
2016 }
2017 default:
2018 gcc_unreachable ();
2019 }
2020
2021 bool trivial_p = false;
2022
2023 if (inherited_ctor)
2024 {
2025 /* For an inheriting constructor, just copy these flags from the
2026 inherited constructor until deduce_inheriting_ctor. */
2027 raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (inherited_ctor));
2028 deleted_p = DECL_DELETED_FN (inherited_ctor);
2029 constexpr_p = DECL_DECLARED_CONSTEXPR_P (inherited_ctor);
2030 }
2031 else if (cxx_dialect >= cxx11)
2032 {
2033 raises = noexcept_deferred_spec;
2034 synthesized_method_walk (type, kind, const_p, NULL, &trivial_p,
2035 &deleted_p, &constexpr_p, false,
2036 &inherited_ctor, inherited_parms);
2037 }
2038 else
2039 synthesized_method_walk (type, kind, const_p, &raises, &trivial_p,
2040 &deleted_p, &constexpr_p, false,
2041 &inherited_ctor, inherited_parms);
2042 /* Don't bother marking a deleted constructor as constexpr. */
2043 if (deleted_p)
2044 constexpr_p = false;
2045 /* A trivial copy/move constructor is also a constexpr constructor,
2046 unless the class has virtual bases (7.1.5p4). */
2047 else if (trivial_p && cxx_dialect >= cxx11
2048 && (kind == sfk_copy_constructor
2049 || kind == sfk_move_constructor)
2050 && !CLASSTYPE_VBASECLASSES (type))
2051 gcc_assert (constexpr_p);
2052
2053 if (!trivial_p && type_has_trivial_fn (type, kind))
2054 type_set_nontrivial_flag (type, kind);
2055
2056 /* Create the function. */
2057 fn_type = build_method_type_directly (type, return_type, parameter_types);
2058 if (raises)
2059 {
2060 if (raises != error_mark_node)
2061 fn_type = build_exception_variant (fn_type, raises);
2062 else
2063 /* Can happen, eg, in C++98 mode for an ill-formed non-static data
2064 member initializer (c++/89914). */
2065 gcc_assert (seen_error ());
2066 }
2067 fn = build_lang_decl (FUNCTION_DECL, name, fn_type);
2068 if (kind != sfk_inheriting_constructor)
2069 DECL_SOURCE_LOCATION (fn) = DECL_SOURCE_LOCATION (TYPE_NAME (type));
2070
2071 if (!IDENTIFIER_CDTOR_P (name))
2072 /* Assignment operator. */
2073 DECL_OVERLOADED_OPERATOR_CODE_RAW (fn) = OVL_OP_NOP_EXPR;
2074 else if (IDENTIFIER_CTOR_P (name))
2075 DECL_CXX_CONSTRUCTOR_P (fn) = true;
2076 else
2077 DECL_CXX_DESTRUCTOR_P (fn) = true;
2078
2079 SET_DECL_ALIGN (fn, MINIMUM_METHOD_BOUNDARY);
2080
2081 /* Create the explicit arguments. */
2082 if (rhs_parm_type)
2083 {
2084 /* Note that this parameter is *not* marked DECL_ARTIFICIAL; we
2085 want its type to be included in the mangled function
2086 name. */
2087 tree decl = cp_build_parm_decl (fn, NULL_TREE, rhs_parm_type);
2088 TREE_READONLY (decl) = 1;
2089 retrofit_lang_decl (decl);
2090 DECL_PARM_INDEX (decl) = DECL_PARM_LEVEL (decl) = 1;
2091 DECL_ARGUMENTS (fn) = decl;
2092 }
2093 else if (kind == sfk_inheriting_constructor)
2094 {
2095 tree *p = &DECL_ARGUMENTS (fn);
2096 int index = 1;
2097 for (tree parm = inherited_parms; parm && parm != void_list_node;
2098 parm = TREE_CHAIN (parm))
2099 {
2100 *p = cp_build_parm_decl (fn, NULL_TREE, TREE_VALUE (parm));
2101 retrofit_lang_decl (*p);
2102 DECL_PARM_LEVEL (*p) = 1;
2103 DECL_PARM_INDEX (*p) = index++;
2104 p = &DECL_CHAIN (*p);
2105 }
2106 SET_DECL_INHERITED_CTOR (fn, inherited_ctor);
2107 DECL_NONCONVERTING_P (fn) = DECL_NONCONVERTING_P (inherited_ctor);
2108 /* A constructor so declared has the same access as the corresponding
2109 constructor in X. */
2110 TREE_PRIVATE (fn) = TREE_PRIVATE (inherited_ctor);
2111 TREE_PROTECTED (fn) = TREE_PROTECTED (inherited_ctor);
2112 /* Copy constexpr from the inherited constructor even if the
2113 inheriting constructor doesn't satisfy the requirements. */
2114 constexpr_p = DECL_DECLARED_CONSTEXPR_P (inherited_ctor);
2115 }
2116 /* Add the "this" parameter. */
2117 this_parm = build_this_parm (fn, fn_type, TYPE_UNQUALIFIED);
2118 DECL_CHAIN (this_parm) = DECL_ARGUMENTS (fn);
2119 DECL_ARGUMENTS (fn) = this_parm;
2120
2121 grokclassfn (type, fn, kind == sfk_destructor ? DTOR_FLAG : NO_SPECIAL);
2122 DECL_IN_AGGR_P (fn) = 1;
2123 DECL_ARTIFICIAL (fn) = 1;
2124 DECL_DEFAULTED_FN (fn) = 1;
2125 if (cxx_dialect >= cxx11)
2126 {
2127 DECL_DELETED_FN (fn) = deleted_p;
2128 DECL_DECLARED_CONSTEXPR_P (fn) = constexpr_p;
2129 }
2130 DECL_EXTERNAL (fn) = true;
2131 DECL_NOT_REALLY_EXTERN (fn) = 1;
2132 DECL_DECLARED_INLINE_P (fn) = 1;
2133 set_linkage_according_to_type (type, fn);
2134 if (TREE_PUBLIC (fn))
2135 DECL_COMDAT (fn) = 1;
2136 rest_of_decl_compilation (fn, namespace_bindings_p (), at_eof);
2137 gcc_assert (!TREE_USED (fn));
2138
2139 /* Propagate constraints from the inherited constructor. */
2140 if (flag_concepts && inherited_ctor)
2141 if (tree orig_ci = get_constraints (inherited_ctor))
2142 {
2143 tree new_ci = copy_node (orig_ci);
2144 set_constraints (fn, new_ci);
2145 }
2146
2147 /* Restore PROCESSING_TEMPLATE_DECL. */
2148 processing_template_decl = saved_processing_template_decl;
2149
2150 if (inherited_ctor && TREE_CODE (inherited_ctor) == TEMPLATE_DECL)
2151 fn = add_inherited_template_parms (fn, inherited_ctor);
2152
2153 /* Warn about calling a non-trivial move assignment in a virtual base. */
2154 if (kind == sfk_move_assignment && !deleted_p && !trivial_p
2155 && CLASSTYPE_VBASECLASSES (type))
2156 {
2157 location_t loc = input_location;
2158 input_location = DECL_SOURCE_LOCATION (fn);
2159 synthesized_method_walk (type, kind, const_p,
2160 NULL, NULL, NULL, NULL, true,
2161 NULL, NULL_TREE);
2162 input_location = loc;
2163 }
2164
2165 return fn;
2166 }
2167
2168 /* Gives any errors about defaulted functions which need to be deferred
2169 until the containing class is complete. */
2170
2171 void
2172 defaulted_late_check (tree fn)
2173 {
2174 /* Complain about invalid signature for defaulted fn. */
2175 tree ctx = DECL_CONTEXT (fn);
2176 special_function_kind kind = special_function_p (fn);
2177 bool fn_const_p = (copy_fn_p (fn) == 2);
2178 tree implicit_fn = implicitly_declare_fn (kind, ctx, fn_const_p,
2179 NULL, NULL);
2180 tree eh_spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (implicit_fn));
2181
2182 if (!same_type_p (TREE_TYPE (TREE_TYPE (fn)),
2183 TREE_TYPE (TREE_TYPE (implicit_fn)))
2184 || !compparms (TYPE_ARG_TYPES (TREE_TYPE (fn)),
2185 TYPE_ARG_TYPES (TREE_TYPE (implicit_fn))))
2186 {
2187 error ("defaulted declaration %q+D does not match the "
2188 "expected signature", fn);
2189 inform (DECL_SOURCE_LOCATION (fn),
2190 "expected signature: %qD", implicit_fn);
2191 }
2192
2193 if (DECL_DELETED_FN (implicit_fn))
2194 {
2195 DECL_DELETED_FN (fn) = 1;
2196 return;
2197 }
2198
2199 /* 8.4.2/2: An explicitly-defaulted function (...) may have an explicit
2200 exception-specification only if it is compatible (15.4) with the
2201 exception-specification on the implicit declaration. If a function
2202 is explicitly defaulted on its first declaration, (...) it is
2203 implicitly considered to have the same exception-specification as if
2204 it had been implicitly declared. */
2205 maybe_instantiate_noexcept (fn);
2206 tree fn_spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn));
2207 if (!fn_spec)
2208 {
2209 if (DECL_DEFAULTED_IN_CLASS_P (fn))
2210 TREE_TYPE (fn) = build_exception_variant (TREE_TYPE (fn), eh_spec);
2211 }
2212 else if (UNEVALUATED_NOEXCEPT_SPEC_P (fn_spec))
2213 /* Equivalent to the implicit spec. */;
2214 else if (DECL_DEFAULTED_IN_CLASS_P (fn)
2215 && !CLASSTYPE_TEMPLATE_INSTANTIATION (ctx))
2216 /* We can't compare an explicit exception-specification on a
2217 constructor defaulted in the class body to the implicit
2218 exception-specification until after we've parsed any NSDMI; see
2219 after_nsdmi_defaulted_late_checks. */;
2220 else
2221 {
2222 tree eh_spec = get_defaulted_eh_spec (fn);
2223 if (!comp_except_specs (fn_spec, eh_spec, ce_normal))
2224 {
2225 if (DECL_DEFAULTED_IN_CLASS_P (fn))
2226 DECL_DELETED_FN (fn) = true;
2227 else
2228 error ("function %q+D defaulted on its redeclaration "
2229 "with an exception-specification that differs from "
2230 "the implicit exception-specification %qX", fn, eh_spec);
2231 }
2232 }
2233
2234 if (DECL_DEFAULTED_IN_CLASS_P (fn)
2235 && DECL_DECLARED_CONSTEXPR_P (implicit_fn))
2236 {
2237 /* Hmm...should we do this for out-of-class too? Should it be OK to
2238 add constexpr later like inline, rather than requiring
2239 declarations to match? */
2240 DECL_DECLARED_CONSTEXPR_P (fn) = true;
2241 if (kind == sfk_constructor)
2242 TYPE_HAS_CONSTEXPR_CTOR (ctx) = true;
2243 }
2244
2245 if (!DECL_DECLARED_CONSTEXPR_P (implicit_fn)
2246 && DECL_DECLARED_CONSTEXPR_P (fn))
2247 {
2248 if (!CLASSTYPE_TEMPLATE_INSTANTIATION (ctx))
2249 {
2250 error ("explicitly defaulted function %q+D cannot be declared "
2251 "%qs because the implicit declaration is not %qs:",
2252 fn, "constexpr", "constexpr");
2253 explain_implicit_non_constexpr (fn);
2254 }
2255 DECL_DECLARED_CONSTEXPR_P (fn) = false;
2256 }
2257 }
2258
2259 /* OK, we've parsed the NSDMI for class T, now we can check any explicit
2260 exception-specifications on functions defaulted in the class body. */
2261
2262 void
2263 after_nsdmi_defaulted_late_checks (tree t)
2264 {
2265 if (uses_template_parms (t))
2266 return;
2267 if (t == error_mark_node)
2268 return;
2269 for (tree fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn))
2270 if (!DECL_ARTIFICIAL (fn)
2271 && DECL_DECLARES_FUNCTION_P (fn)
2272 && DECL_DEFAULTED_IN_CLASS_P (fn))
2273 {
2274 tree fn_spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn));
2275 if (UNEVALUATED_NOEXCEPT_SPEC_P (fn_spec))
2276 continue;
2277
2278 tree eh_spec = get_defaulted_eh_spec (fn);
2279 if (eh_spec == error_mark_node)
2280 continue;
2281
2282 if (!comp_except_specs (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)),
2283 eh_spec, ce_normal))
2284 DECL_DELETED_FN (fn) = true;
2285 }
2286 }
2287
2288 /* Returns true iff FN can be explicitly defaulted, and gives any
2289 errors if defaulting FN is ill-formed. */
2290
2291 bool
2292 defaultable_fn_check (tree fn)
2293 {
2294 special_function_kind kind = sfk_none;
2295
2296 if (template_parm_scope_p ())
2297 {
2298 error ("a template cannot be defaulted");
2299 return false;
2300 }
2301
2302 if (DECL_CONSTRUCTOR_P (fn))
2303 {
2304 if (FUNCTION_FIRST_USER_PARMTYPE (fn) == void_list_node)
2305 kind = sfk_constructor;
2306 else if (copy_fn_p (fn) > 0
2307 && (TREE_CHAIN (FUNCTION_FIRST_USER_PARMTYPE (fn))
2308 == void_list_node))
2309 kind = sfk_copy_constructor;
2310 else if (move_fn_p (fn))
2311 kind = sfk_move_constructor;
2312 }
2313 else if (DECL_DESTRUCTOR_P (fn))
2314 kind = sfk_destructor;
2315 else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
2316 && DECL_OVERLOADED_OPERATOR_IS (fn, NOP_EXPR))
2317 {
2318 if (copy_fn_p (fn))
2319 kind = sfk_copy_assignment;
2320 else if (move_fn_p (fn))
2321 kind = sfk_move_assignment;
2322 }
2323
2324 if (kind == sfk_none)
2325 {
2326 error ("%qD cannot be defaulted", fn);
2327 return false;
2328 }
2329 else
2330 {
2331 for (tree t = FUNCTION_FIRST_USER_PARMTYPE (fn);
2332 t && t != void_list_node; t = TREE_CHAIN (t))
2333 if (TREE_PURPOSE (t))
2334 {
2335 error ("defaulted function %q+D with default argument", fn);
2336 break;
2337 }
2338
2339 /* Avoid do_warn_unused_parameter warnings. */
2340 for (tree p = FUNCTION_FIRST_USER_PARM (fn); p; p = DECL_CHAIN (p))
2341 if (DECL_NAME (p))
2342 TREE_NO_WARNING (p) = 1;
2343
2344 if (TYPE_BEING_DEFINED (DECL_CONTEXT (fn)))
2345 /* Defer checking. */;
2346 else if (!processing_template_decl)
2347 defaulted_late_check (fn);
2348
2349 return true;
2350 }
2351 }
2352
2353 /* Add an implicit declaration to TYPE for the kind of function
2354 indicated by SFK. Return the FUNCTION_DECL for the new implicit
2355 declaration. */
2356
2357 tree
2358 lazily_declare_fn (special_function_kind sfk, tree type)
2359 {
2360 tree fn;
2361 /* Whether or not the argument has a const reference type. */
2362 bool const_p = false;
2363
2364 type = TYPE_MAIN_VARIANT (type);
2365
2366 switch (sfk)
2367 {
2368 case sfk_constructor:
2369 CLASSTYPE_LAZY_DEFAULT_CTOR (type) = 0;
2370 break;
2371 case sfk_copy_constructor:
2372 const_p = TYPE_HAS_CONST_COPY_CTOR (type);
2373 CLASSTYPE_LAZY_COPY_CTOR (type) = 0;
2374 break;
2375 case sfk_move_constructor:
2376 CLASSTYPE_LAZY_MOVE_CTOR (type) = 0;
2377 break;
2378 case sfk_copy_assignment:
2379 const_p = TYPE_HAS_CONST_COPY_ASSIGN (type);
2380 CLASSTYPE_LAZY_COPY_ASSIGN (type) = 0;
2381 break;
2382 case sfk_move_assignment:
2383 CLASSTYPE_LAZY_MOVE_ASSIGN (type) = 0;
2384 break;
2385 case sfk_destructor:
2386 CLASSTYPE_LAZY_DESTRUCTOR (type) = 0;
2387 break;
2388 default:
2389 gcc_unreachable ();
2390 }
2391
2392 /* Declare the function. */
2393 fn = implicitly_declare_fn (sfk, type, const_p, NULL, NULL);
2394
2395 /* [class.copy]/8 If the class definition declares a move constructor or
2396 move assignment operator, the implicitly declared copy constructor is
2397 defined as deleted.... */
2398 if ((sfk == sfk_copy_assignment || sfk == sfk_copy_constructor)
2399 && cxx_dialect >= cxx11)
2400 {
2401 if (classtype_has_move_assign_or_move_ctor_p (type, true))
2402 DECL_DELETED_FN (fn) = true;
2403 else if (classtype_has_depr_implicit_copy (type))
2404 /* The implicit definition of a copy constructor as defaulted is
2405 deprecated if the class has a user-declared copy assignment operator
2406 or a user-declared destructor. The implicit definition of a copy
2407 assignment operator as defaulted is deprecated if the class has a
2408 user-declared copy constructor or a user-declared destructor (15.4,
2409 15.8). */
2410 TREE_DEPRECATED (fn) = true;
2411 }
2412
2413 /* Destructors and assignment operators may be virtual. */
2414 if (sfk == sfk_destructor
2415 || sfk == sfk_move_assignment
2416 || sfk == sfk_copy_assignment)
2417 check_for_override (fn, type);
2418
2419 /* Add it to the class */
2420 bool added = add_method (type, fn, false);
2421 gcc_assert (added || errorcount);
2422
2423 /* Add it to TYPE_FIELDS. */
2424 if (sfk == sfk_destructor
2425 && DECL_VIRTUAL_P (fn))
2426 /* The ABI requires that a virtual destructor go at the end of the
2427 vtable. */
2428 TYPE_FIELDS (type) = chainon (TYPE_FIELDS (type), fn);
2429 else
2430 {
2431 DECL_CHAIN (fn) = TYPE_FIELDS (type);
2432 TYPE_FIELDS (type) = fn;
2433 }
2434 /* Propagate TYPE_FIELDS. */
2435 fixup_type_variants (type);
2436
2437 maybe_add_class_template_decl_list (type, fn, /*friend_p=*/0);
2438 if (DECL_MAYBE_IN_CHARGE_CDTOR_P (fn))
2439 /* Create appropriate clones. */
2440 clone_function_decl (fn, /*update_methods=*/true);
2441
2442 return fn;
2443 }
2444
2445 /* Given a FUNCTION_DECL FN and a chain LIST, skip as many elements of LIST
2446 as there are artificial parms in FN. */
2447
2448 tree
2449 skip_artificial_parms_for (const_tree fn, tree list)
2450 {
2451 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
2452 list = TREE_CHAIN (list);
2453 else
2454 return list;
2455
2456 if (DECL_HAS_IN_CHARGE_PARM_P (fn))
2457 list = TREE_CHAIN (list);
2458 if (DECL_HAS_VTT_PARM_P (fn))
2459 list = TREE_CHAIN (list);
2460 return list;
2461 }
2462
2463 /* Given a FUNCTION_DECL FN and a chain LIST, return the number of
2464 artificial parms in FN. */
2465
2466 int
2467 num_artificial_parms_for (const_tree fn)
2468 {
2469 int count = 0;
2470
2471 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
2472 count++;
2473 else
2474 return 0;
2475
2476 if (DECL_HAS_IN_CHARGE_PARM_P (fn))
2477 count++;
2478 if (DECL_HAS_VTT_PARM_P (fn))
2479 count++;
2480 return count;
2481 }
2482
2483
2484 #include "gt-cp-method.h"