Debian Codegraph @

gcc/cp/lambda.cc

raw
1 /* Perform the semantic phase of lambda parsing, i.e., the process of
2 building tree structure, checking semantic consistency, and
3 building RTL. These routines are used both during actual parsing
4 and during the instantiation of template functions.
5
6 Copyright (C) 1998-2025 Free Software Foundation, Inc.
7
8 This file is part of GCC.
9
10 GCC is free software; you can redistribute it and/or modify it
11 under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3, or (at your option)
13 any later version.
14
15 GCC is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
23
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "cp-tree.h"
28 #include "stringpool.h"
29 #include "cgraph.h"
30 #include "tree-iterator.h"
31 #include "toplev.h"
32 #include "gimplify.h"
33 #include "target.h"
34 #include "decl.h"
35 #include "flags.h"
36
37 /* Constructor for a lambda expression. */
38
39 tree
40 build_lambda_expr (void)
41 {
42 tree lambda = make_node (LAMBDA_EXPR);
43 LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda) = CPLD_NONE;
44 LAMBDA_EXPR_CAPTURE_LIST (lambda) = NULL_TREE;
45 LAMBDA_EXPR_THIS_CAPTURE (lambda) = NULL_TREE;
46 LAMBDA_EXPR_REGEN_INFO (lambda) = NULL_TREE;
47 LAMBDA_EXPR_PENDING_PROXIES (lambda) = NULL;
48 return lambda;
49 }
50
51 /* Create the closure object for a LAMBDA_EXPR. */
52
53 tree
54 build_lambda_object (tree lambda_expr)
55 {
56 /* Build aggregate constructor call.
57 - cp_parser_braced_list
58 - cp_parser_functional_cast */
59 vec<constructor_elt, va_gc> *elts = NULL;
60 tree node, expr, type;
61
62 if (processing_template_decl && !in_template_context
63 && current_binding_level->requires_expression)
64 /* As in cp_parser_lambda_expression, don't get confused by
65 cp_parser_requires_expression setting processing_template_decl. In that
66 case we want to return the result of finish_compound_literal, to avoid
67 tsubst_lambda_expr. */;
68 else if (processing_template_decl || lambda_expr == error_mark_node)
69 return lambda_expr;
70
71 /* Make sure any error messages refer to the lambda-introducer. */
72 location_t loc = LAMBDA_EXPR_LOCATION (lambda_expr);
73 iloc_sentinel il (loc);
74
75 for (node = LAMBDA_EXPR_CAPTURE_LIST (lambda_expr);
76 node;
77 node = TREE_CHAIN (node))
78 {
79 tree field = TREE_PURPOSE (node);
80 tree val = TREE_VALUE (node);
81
82 if (field == error_mark_node)
83 {
84 expr = error_mark_node;
85 goto out;
86 }
87
88 if (TREE_CODE (val) == TREE_LIST)
89 val = build_x_compound_expr_from_list (val, ELK_INIT,
90 tf_warning_or_error);
91
92 if (DECL_P (val))
93 mark_used (val);
94
95 /* Mere mortals can't copy arrays with aggregate initialization, so
96 do some magic to make it work here. */
97 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE)
98 val = build_array_copy (val);
99 else if (DECL_NORMAL_CAPTURE_P (field)
100 && !DECL_VLA_CAPTURE_P (field)
101 && !TYPE_REF_P (TREE_TYPE (field)))
102 {
103 /* "the entities that are captured by copy are used to
104 direct-initialize each corresponding non-static data
105 member of the resulting closure object."
106
107 There's normally no way to express direct-initialization
108 from an element of a CONSTRUCTOR, so we build up a special
109 TARGET_EXPR to bypass the usual copy-initialization. */
110 val = force_rvalue (val, tf_warning_or_error);
111 if (TREE_CODE (val) == TARGET_EXPR)
112 TARGET_EXPR_DIRECT_INIT_P (val) = true;
113 }
114
115 CONSTRUCTOR_APPEND_ELT (elts, DECL_NAME (field), val);
116 }
117
118 expr = build_constructor (init_list_type_node, elts);
119 CONSTRUCTOR_IS_DIRECT_INIT (expr) = 1;
120
121 /* N2927: "[The closure] class type is not an aggregate."
122 But we briefly treat it as an aggregate to make this simpler. */
123 type = LAMBDA_EXPR_CLOSURE (lambda_expr);
124 CLASSTYPE_NON_AGGREGATE (type) = 0;
125 expr = finish_compound_literal (type, expr, tf_warning_or_error);
126 protected_set_expr_location (expr, loc);
127 CLASSTYPE_NON_AGGREGATE (type) = 1;
128
129 out:
130 return expr;
131 }
132
133 /* Return an initialized RECORD_TYPE for LAMBDA.
134 LAMBDA must have its explicit captures already. */
135
136 tree
137 begin_lambda_type (tree lambda)
138 {
139 /* Lambda names are nearly but not quite anonymous. */
140 tree name = make_anon_name ();
141 IDENTIFIER_LAMBDA_P (name) = true;
142
143 /* Create the new RECORD_TYPE for this lambda. */
144 tree type = xref_tag (/*tag_code=*/record_type, name);
145 if (type == error_mark_node)
146 return error_mark_node;
147
148 /* Designate it as a struct so that we can use aggregate initialization. */
149 CLASSTYPE_DECLARED_CLASS (type) = false;
150
151 /* Cross-reference the expression and the type. */
152 LAMBDA_EXPR_CLOSURE (lambda) = type;
153 CLASSTYPE_LAMBDA_EXPR (type) = lambda;
154
155 /* In C++17, assume the closure is literal; we'll clear the flag later if
156 necessary. */
157 if (cxx_dialect >= cxx17)
158 CLASSTYPE_LITERAL_P (type) = true;
159
160 /* Clear base types. */
161 xref_basetypes (type, /*bases=*/NULL_TREE);
162
163 /* Start the class. */
164 type = begin_class_definition (type);
165
166 return type;
167 }
168
169 /* Given a LAMBDA_EXPR or closure type LAMBDA, return the op() of the
170 closure type. */
171
172 tree
173 lambda_function (tree lambda)
174 {
175 tree type;
176 if (TREE_CODE (lambda) == LAMBDA_EXPR)
177 type = LAMBDA_EXPR_CLOSURE (lambda);
178 else
179 type = lambda;
180 gcc_assert (LAMBDA_TYPE_P (type));
181 /* Don't let debug_tree cause instantiation. */
182 if (CLASSTYPE_TEMPLATE_INSTANTIATION (type)
183 && !COMPLETE_OR_OPEN_TYPE_P (type))
184 return NULL_TREE;
185 lambda = get_class_binding_direct (type, call_op_identifier);
186 if (lambda)
187 lambda = STRIP_TEMPLATE (get_first_fn (lambda));
188 return lambda;
189 }
190
191 /* True if EXPR is an expression whose type can be used directly in lambda
192 capture. Not to be used for 'auto'. */
193
194 static bool
195 type_deducible_expression_p (tree expr)
196 {
197 if (!type_dependent_expression_p (expr))
198 return true;
199 if (BRACE_ENCLOSED_INITIALIZER_P (expr)
200 || TREE_CODE (expr) == EXPR_PACK_EXPANSION)
201 return false;
202 tree t = non_reference (TREE_TYPE (expr));
203 return (t && TREE_CODE (t) != TYPE_PACK_EXPANSION
204 && !WILDCARD_TYPE_P (t) && !LAMBDA_TYPE_P (t)
205 && !array_of_unknown_bound_p (t)
206 && !type_uses_auto (t));
207 }
208
209 /* Returns the type to use for the FIELD_DECL corresponding to the
210 capture of EXPR. EXPLICIT_INIT_P indicates whether this is a
211 C++14 init capture, and BY_REFERENCE_P indicates whether we're
212 capturing by reference. */
213
214 tree
215 lambda_capture_field_type (tree expr, bool explicit_init_p,
216 bool by_reference_p)
217 {
218 tree type;
219 bool is_this = is_this_parameter (tree_strip_nop_conversions (expr));
220
221 if (is_this)
222 type = TREE_TYPE (expr);
223 else if (explicit_init_p)
224 {
225 if (uses_parameter_packs (expr))
226 {
227 /* Stick with 'auto...' even if the type could be deduced. */
228 type = make_auto_pack ();
229 if (by_reference_p)
230 type = build_reference_type (type);
231 }
232 else
233 {
234 tree auto_node = make_auto ();
235 type = auto_node;
236 if (by_reference_p)
237 /* Add the reference now, so deduction doesn't lose
238 outermost CV qualifiers of EXPR. */
239 type = build_reference_type (type);
240 type = do_auto_deduction (type, expr, auto_node);
241 }
242 }
243 else if (!type_deducible_expression_p (expr))
244 {
245 type = cxx_make_type (DECLTYPE_TYPE);
246 DECLTYPE_TYPE_EXPR (type) = expr;
247 DECLTYPE_FOR_LAMBDA_CAPTURE (type) = true;
248 DECLTYPE_FOR_REF_CAPTURE (type) = by_reference_p;
249 SET_TYPE_STRUCTURAL_EQUALITY (type);
250 }
251 else
252 {
253 STRIP_ANY_LOCATION_WRAPPER (expr);
254
255 if (!by_reference_p && is_capture_proxy (expr))
256 {
257 /* When capturing by-value another capture proxy from an enclosing
258 lambda, consider the type of the corresponding field instead,
259 as the proxy may be additionally const-qualifed if the enclosing
260 lambda is non-mutable (PR94376). */
261 gcc_assert (TREE_CODE (DECL_VALUE_EXPR (expr)) == COMPONENT_REF);
262 expr = TREE_OPERAND (DECL_VALUE_EXPR (expr), 1);
263 }
264
265 type = non_reference (unlowered_expr_type (expr));
266
267 if (by_reference_p || TREE_CODE (type) == FUNCTION_TYPE)
268 type = build_reference_type (type);
269 }
270
271 return type;
272 }
273
274 /* Returns true iff DECL is a lambda capture proxy variable created by
275 build_capture_proxy. */
276
277 bool
278 is_capture_proxy (tree decl)
279 {
280 /* Location wrappers should be stripped or otherwise handled by the
281 caller before using this predicate. */
282 gcc_checking_assert (!location_wrapper_p (decl));
283
284 return (VAR_P (decl)
285 && DECL_HAS_VALUE_EXPR_P (decl)
286 && !DECL_ANON_UNION_VAR_P (decl)
287 && !DECL_DECOMPOSITION_P (decl)
288 && !DECL_FNAME_P (decl)
289 && !(DECL_ARTIFICIAL (decl)
290 && DECL_LANG_SPECIFIC (decl)
291 && DECL_OMP_PRIVATIZED_MEMBER (decl))
292 && LAMBDA_FUNCTION_P (DECL_CONTEXT (decl)));
293 }
294
295 /* Returns true iff DECL is a capture proxy for a normal capture
296 (i.e. without explicit initializer). */
297
298 bool
299 is_normal_capture_proxy (tree decl)
300 {
301 if (!is_capture_proxy (decl))
302 /* It's not a capture proxy. */
303 return false;
304
305 return (DECL_LANG_SPECIFIC (decl)
306 && DECL_CAPTURED_VARIABLE (decl));
307 }
308
309 /* If DECL is a normal capture proxy, return the variable it captures.
310 Otherwise, just return DECL. */
311
312 tree
313 strip_normal_capture_proxy (tree decl)
314 {
315 while (is_normal_capture_proxy (decl))
316 decl = DECL_CAPTURED_VARIABLE (decl);
317 return decl;
318 }
319
320 /* Returns true iff DECL is a capture proxy for a normal capture
321 of a constant variable. */
322
323 bool
324 is_constant_capture_proxy (tree decl)
325 {
326 if (is_normal_capture_proxy (decl))
327 return decl_constant_var_p (DECL_CAPTURED_VARIABLE (decl));
328 return false;
329 }
330
331 /* VAR is a capture proxy created by build_capture_proxy; add it to the
332 current function, which is the operator() for the appropriate lambda. */
333
334 void
335 insert_capture_proxy (tree var)
336 {
337 if (is_normal_capture_proxy (var))
338 {
339 tree cap = DECL_CAPTURED_VARIABLE (var);
340 if (CHECKING_P)
341 {
342 gcc_assert (!is_normal_capture_proxy (cap));
343 tree old = retrieve_local_specialization (cap);
344 if (old)
345 gcc_assert (DECL_CONTEXT (old) != DECL_CONTEXT (var));
346 }
347 register_local_specialization (var, cap);
348 }
349
350 /* Put the capture proxy in the extra body block so that it won't clash
351 with a later local variable. */
352 pushdecl_outermost_localscope (var);
353
354 /* And put a DECL_EXPR in the STATEMENT_LIST for the same block. */
355 var = build_stmt (DECL_SOURCE_LOCATION (var), DECL_EXPR, var);
356 tree stmt_list = (*stmt_list_stack)[1];
357 gcc_assert (stmt_list);
358 append_to_statement_list_force (var, &stmt_list);
359 }
360
361 /* We've just finished processing a lambda; if the containing scope is also
362 a lambda, insert any capture proxies that were created while processing
363 the nested lambda. */
364
365 void
366 insert_pending_capture_proxies (void)
367 {
368 tree lam;
369 vec<tree, va_gc> *proxies;
370 unsigned i;
371
372 if (!current_function_decl || !LAMBDA_FUNCTION_P (current_function_decl))
373 return;
374
375 lam = CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (current_function_decl));
376 proxies = LAMBDA_EXPR_PENDING_PROXIES (lam);
377 for (i = 0; i < vec_safe_length (proxies); ++i)
378 {
379 tree var = (*proxies)[i];
380 insert_capture_proxy (var);
381 }
382 release_tree_vector (LAMBDA_EXPR_PENDING_PROXIES (lam));
383 LAMBDA_EXPR_PENDING_PROXIES (lam) = NULL;
384 }
385
386 /* Given REF, a COMPONENT_REF designating a field in the lambda closure,
387 return the type we want the proxy to have: the type of the field itself,
388 with added const-qualification if the lambda isn't mutable and the
389 capture is by value. */
390
391 tree
392 lambda_proxy_type (tree ref)
393 {
394 tree type;
395 if (ref == error_mark_node)
396 return error_mark_node;
397 if (REFERENCE_REF_P (ref))
398 ref = TREE_OPERAND (ref, 0);
399 gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
400 type = TREE_TYPE (ref);
401 if (!type || WILDCARD_TYPE_P (non_reference (type)))
402 {
403 type = cxx_make_type (DECLTYPE_TYPE);
404 DECLTYPE_TYPE_EXPR (type) = ref;
405 DECLTYPE_FOR_LAMBDA_PROXY (type) = true;
406 SET_TYPE_STRUCTURAL_EQUALITY (type);
407 }
408 if (DECL_PACK_P (TREE_OPERAND (ref, 1)))
409 type = make_pack_expansion (type);
410 return type;
411 }
412
413 /* MEMBER is a capture field in a lambda closure class. Now that we're
414 inside the operator(), build a placeholder var for future lookups and
415 debugging. */
416
417 static tree
418 build_capture_proxy (tree member, tree init)
419 {
420 tree var, object, fn, closure, name, lam, type;
421
422 if (PACK_EXPANSION_P (member))
423 member = PACK_EXPANSION_PATTERN (member);
424
425 closure = DECL_CONTEXT (member);
426 fn = lambda_function (closure);
427 lam = CLASSTYPE_LAMBDA_EXPR (closure);
428
429 object = DECL_ARGUMENTS (fn);
430 /* The proxy variable forwards to the capture field. */
431 if (INDIRECT_TYPE_P (TREE_TYPE (object)))
432 object = build_fold_indirect_ref (object);
433 object = finish_non_static_data_member (member, object, NULL_TREE);
434 if (REFERENCE_REF_P (object))
435 object = TREE_OPERAND (object, 0);
436
437 /* Remove the __ inserted by add_capture. */
438 if (IDENTIFIER_POINTER (DECL_NAME (member))[2] == '_'
439 && IDENTIFIER_POINTER (DECL_NAME (member))[3] == '.')
440 name = get_identifier ("_");
441 else
442 name = get_identifier (IDENTIFIER_POINTER (DECL_NAME (member)) + 2);
443
444 type = lambda_proxy_type (object);
445
446 if (name == this_identifier && !INDIRECT_TYPE_P (type))
447 {
448 type = build_pointer_type (type);
449 type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
450 object = build_fold_addr_expr_with_type (object, type);
451 }
452
453 if (DECL_VLA_CAPTURE_P (member))
454 {
455 /* Rebuild the VLA type from the pointer and maxindex. */
456 tree field = next_aggregate_field (TYPE_FIELDS (type));
457 tree ptr = build_simple_component_ref (object, field);
458 field = next_aggregate_field (DECL_CHAIN (field));
459 tree max = build_simple_component_ref (object, field);
460 type = build_cplus_array_type (TREE_TYPE (TREE_TYPE (ptr)),
461 build_index_type (max));
462 type = build_reference_type (type);
463 object = convert (type, ptr);
464 }
465
466 complete_type (type);
467
468 var = build_decl (input_location, VAR_DECL, name, type);
469 SET_DECL_VALUE_EXPR (var, object);
470 DECL_HAS_VALUE_EXPR_P (var) = 1;
471 DECL_ARTIFICIAL (var) = 1;
472 TREE_USED (var) = 1;
473 DECL_CONTEXT (var) = fn;
474
475 if (DECL_NORMAL_CAPTURE_P (member))
476 {
477 if (DECL_VLA_CAPTURE_P (member))
478 {
479 init = CONSTRUCTOR_ELT (init, 0)->value;
480 init = TREE_OPERAND (init, 0); // Strip ADDR_EXPR.
481 init = TREE_OPERAND (init, 0); // Strip ARRAY_REF.
482 }
483 else
484 {
485 if (PACK_EXPANSION_P (init))
486 init = PACK_EXPANSION_PATTERN (init);
487 }
488
489 if (INDIRECT_REF_P (init))
490 init = TREE_OPERAND (init, 0);
491 STRIP_NOPS (init);
492
493 gcc_assert (VAR_P (init) || TREE_CODE (init) == PARM_DECL);
494 init = strip_normal_capture_proxy (init);
495 retrofit_lang_decl (var);
496 DECL_CAPTURED_VARIABLE (var) = init;
497 }
498
499 if (name == this_identifier)
500 {
501 gcc_assert (LAMBDA_EXPR_THIS_CAPTURE (lam) == member);
502 LAMBDA_EXPR_THIS_CAPTURE (lam) = var;
503 }
504
505 if (fn == current_function_decl)
506 insert_capture_proxy (var);
507 else
508 vec_safe_push (LAMBDA_EXPR_PENDING_PROXIES (lam), var);
509
510 return var;
511 }
512
513 static GTY(()) tree ptr_id;
514 static GTY(()) tree max_id;
515
516 /* Return a struct containing a pointer and a length for lambda capture of
517 an array of runtime length. */
518
519 static tree
520 vla_capture_type (tree array_type)
521 {
522 tree type = xref_tag (record_type, make_anon_name ());
523 xref_basetypes (type, NULL_TREE);
524 type = begin_class_definition (type);
525 if (!ptr_id)
526 {
527 ptr_id = get_identifier ("ptr");
528 max_id = get_identifier ("max");
529 }
530 tree ptrtype = build_pointer_type (TREE_TYPE (array_type));
531 tree field = build_decl (input_location, FIELD_DECL, ptr_id, ptrtype);
532 finish_member_declaration (field);
533 field = build_decl (input_location, FIELD_DECL, max_id, sizetype);
534 finish_member_declaration (field);
535 return finish_struct (type, NULL_TREE);
536 }
537
538 /* From an ID and INITIALIZER, create a capture (by reference if
539 BY_REFERENCE_P is true), add it to the capture-list for LAMBDA,
540 and return it. If ID is `this', BY_REFERENCE_P says whether
541 `*this' is captured by reference. */
542
543 tree
544 add_capture (tree lambda, tree id, tree orig_init, bool by_reference_p,
545 bool explicit_init_p, unsigned *name_independent_cnt)
546 {
547 char *buf;
548 tree type, member, name;
549 bool vla = false;
550 bool variadic = false;
551 tree initializer = orig_init;
552
553 if (PACK_EXPANSION_P (initializer))
554 {
555 initializer = PACK_EXPANSION_PATTERN (initializer);
556 variadic = true;
557 }
558
559 if (TREE_CODE (initializer) == TREE_LIST
560 /* A pack expansion might end up with multiple elements. */
561 && !PACK_EXPANSION_P (TREE_VALUE (initializer)))
562 initializer = build_x_compound_expr_from_list (initializer, ELK_INIT,
563 tf_warning_or_error);
564 type = TREE_TYPE (initializer);
565 if (type == error_mark_node)
566 return error_mark_node;
567
568 if (!dependent_type_p (type) && array_of_runtime_bound_p (type))
569 {
570 vla = true;
571 if (!by_reference_p)
572 error ("array of runtime bound cannot be captured by copy, "
573 "only by reference");
574
575 /* For a VLA, we capture the address of the first element and the
576 maximum index, and then reconstruct the VLA for the proxy. */
577 tree elt = cp_build_array_ref (input_location, initializer,
578 integer_zero_node, tf_warning_or_error);
579 initializer = build_constructor_va (init_list_type_node, 2,
580 NULL_TREE, build_address (elt),
581 NULL_TREE,
582 array_type_nelts_minus_one (type));
583 type = vla_capture_type (type);
584 }
585 else if (!dependent_type_p (type)
586 && variably_modified_type_p (type, NULL_TREE))
587 {
588 auto_diagnostic_group d;
589 sorry ("capture of variably-modified type %qT that is not an N3639 array "
590 "of runtime bound", type);
591 if (TREE_CODE (type) == ARRAY_TYPE
592 && variably_modified_type_p (TREE_TYPE (type), NULL_TREE))
593 inform (input_location, "because the array element type %qT has "
594 "variable size", TREE_TYPE (type));
595 return error_mark_node;
596 }
597 else
598 {
599 type = lambda_capture_field_type (initializer, explicit_init_p,
600 by_reference_p);
601 if (type == error_mark_node)
602 return error_mark_node;
603
604 if (id == this_identifier && !by_reference_p)
605 {
606 gcc_assert (INDIRECT_TYPE_P (type));
607 type = TREE_TYPE (type);
608 initializer = cp_build_fold_indirect_ref (initializer);
609 }
610
611 if (dependent_type_p (type))
612 ;
613 else if (id != this_identifier && by_reference_p)
614 {
615 if (!lvalue_p (initializer))
616 {
617 error ("cannot capture %qE by reference", initializer);
618 return error_mark_node;
619 }
620 }
621 else
622 {
623 /* Capture by copy requires a complete type. */
624 type = complete_type (type);
625 if (!COMPLETE_TYPE_P (type))
626 {
627 auto_diagnostic_group d;
628 error ("capture by copy of incomplete type %qT", type);
629 cxx_incomplete_type_inform (type);
630 return error_mark_node;
631 }
632 else if (!verify_type_context (input_location,
633 TCTX_CAPTURE_BY_COPY, type))
634 return error_mark_node;
635 }
636
637 if (cxx_dialect < cxx20 && !explicit_init_p)
638 {
639 auto_diagnostic_group d;
640 tree stripped_init = tree_strip_any_location_wrapper (initializer);
641 if (DECL_DECOMPOSITION_P (stripped_init)
642 && pedwarn (input_location, OPT_Wc__20_extensions,
643 "captured structured bindings are a C++20 extension"))
644 inform (DECL_SOURCE_LOCATION (stripped_init), "declared here");
645 }
646 }
647
648 /* Add __ to the beginning of the field name so that user code
649 won't find the field with name lookup. We can't just leave the name
650 unset because template instantiation uses the name to find
651 instantiated fields. */
652 if (id_equal (id, "_") && name_independent_cnt)
653 {
654 if (*name_independent_cnt == 0)
655 name = get_identifier ("___");
656 else
657 {
658 /* For 2nd and later name-independent capture use
659 unique names. */
660 char buf2[5 + (HOST_BITS_PER_INT + 2) / 3];
661 sprintf (buf2, "___.%u", *name_independent_cnt);
662 name = get_identifier (buf2);
663 }
664 name_independent_cnt[0]++;
665 }
666 else
667 {
668 buf = XALLOCAVEC (char, IDENTIFIER_LENGTH (id) + 3);
669 buf[1] = buf[0] = '_';
670 memcpy (buf + 2, IDENTIFIER_POINTER (id),
671 IDENTIFIER_LENGTH (id) + 1);
672 name = get_identifier (buf);
673 }
674
675 if (variadic)
676 {
677 type = make_pack_expansion (type);
678 if (explicit_init_p)
679 /* With an explicit initializer 'type' is auto, which isn't really a
680 parameter pack in this context. We will want as many fields as we
681 have elements in the expansion of the initializer, so use its packs
682 instead. */
683 {
684 PACK_EXPANSION_PARAMETER_PACKS (type)
685 = uses_parameter_packs (initializer);
686 PACK_EXPANSION_AUTO_P (type) = true;
687 }
688 }
689
690 /* Make member variable. */
691 member = build_decl (input_location, FIELD_DECL, name, type);
692 DECL_VLA_CAPTURE_P (member) = vla;
693
694 if (!explicit_init_p)
695 /* Normal captures are invisible to name lookup but uses are replaced
696 with references to the capture field; we implement this by only
697 really making them invisible in unevaluated context; see
698 qualify_lookup. For now, let's make explicitly initialized captures
699 always visible. */
700 DECL_NORMAL_CAPTURE_P (member) = true;
701
702 if (id == this_identifier)
703 LAMBDA_EXPR_THIS_CAPTURE (lambda) = member;
704
705 /* Add it to the appropriate closure class if we've started it. */
706 if (current_class_type
707 && current_class_type == LAMBDA_EXPR_CLOSURE (lambda))
708 {
709 if (COMPLETE_TYPE_P (current_class_type))
710 internal_error ("trying to capture %qD in instantiation of "
711 "generic lambda", id);
712 finish_member_declaration (member);
713 }
714
715 tree listmem = member;
716 if (variadic)
717 {
718 listmem = make_pack_expansion (member);
719 initializer = orig_init;
720 }
721 LAMBDA_EXPR_CAPTURE_LIST (lambda)
722 = tree_cons (listmem, initializer, LAMBDA_EXPR_CAPTURE_LIST (lambda));
723
724 if (LAMBDA_EXPR_CLOSURE (lambda))
725 return build_capture_proxy (member, initializer);
726 /* For explicit captures we haven't started the function yet, so we wait
727 and build the proxy from cp_parser_lambda_body. */
728 LAMBDA_CAPTURE_EXPLICIT_P (LAMBDA_EXPR_CAPTURE_LIST (lambda)) = true;
729 return NULL_TREE;
730 }
731
732 /* Register all the capture members on the list CAPTURES, which is the
733 LAMBDA_EXPR_CAPTURE_LIST for the lambda after the introducer. */
734
735 void
736 register_capture_members (tree captures)
737 {
738 if (captures == NULL_TREE)
739 return;
740
741 register_capture_members (TREE_CHAIN (captures));
742
743 tree field = TREE_PURPOSE (captures);
744 if (PACK_EXPANSION_P (field))
745 field = PACK_EXPANSION_PATTERN (field);
746
747 finish_member_declaration (field);
748 }
749
750 /* Similar to add_capture, except this works on a stack of nested lambdas.
751 BY_REFERENCE_P in this case is derived from the default capture mode.
752 Returns the capture for the lambda at the bottom of the stack. */
753
754 tree
755 add_default_capture (tree lambda_stack, tree id, tree initializer)
756 {
757 bool this_capture_p = (id == this_identifier);
758 tree var = NULL_TREE;
759 tree saved_class_type = current_class_type;
760
761 for (tree node = lambda_stack;
762 node;
763 node = TREE_CHAIN (node))
764 {
765 tree lambda = TREE_VALUE (node);
766
767 current_class_type = LAMBDA_EXPR_CLOSURE (lambda);
768 if (DECL_PACK_P (initializer))
769 initializer = make_pack_expansion (initializer);
770 var = add_capture (lambda,
771 id,
772 initializer,
773 /*by_reference_p=*/
774 (this_capture_p
775 || (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda)
776 == CPLD_REFERENCE)),
777 /*explicit_init_p=*/false, NULL);
778 initializer = convert_from_reference (var);
779
780 /* Warn about deprecated implicit capture of this via [=]. */
781 if (cxx_dialect >= cxx20
782 && this_capture_p
783 && LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda) == CPLD_COPY)
784 {
785 auto_diagnostic_group d;
786 if (warning_at (LAMBDA_EXPR_LOCATION (lambda), OPT_Wdeprecated,
787 "implicit capture of %qE via %<[=]%> is deprecated "
788 "in C++20", this_identifier))
789 inform (LAMBDA_EXPR_LOCATION (lambda), "add explicit %<this%> or "
790 "%<*this%> capture");
791 }
792 }
793
794 current_class_type = saved_class_type;
795
796 return var;
797 }
798
799 /* Return the capture pertaining to a use of 'this' in LAMBDA, in the
800 form of an INDIRECT_REF, possibly adding it through default
801 capturing, if ADD_CAPTURE_P is nonzero. If ADD_CAPTURE_P is negative,
802 try to capture but don't complain if we can't. */
803
804 tree
805 lambda_expr_this_capture (tree lambda, int add_capture_p)
806 {
807 tree result;
808
809 tree this_capture = LAMBDA_EXPR_THIS_CAPTURE (lambda);
810 if (this_capture)
811 if (tree spec = retrieve_local_specialization (this_capture))
812 {
813 gcc_checking_assert (generic_lambda_fn_p (lambda_function (lambda)));
814 this_capture = spec;
815 }
816
817 /* In unevaluated context this isn't an odr-use, so don't capture. */
818 if (cp_unevaluated_operand)
819 add_capture_p = false;
820
821 /* Try to default capture 'this' if we can. */
822 if (!this_capture)
823 {
824 tree lambda_stack = NULL_TREE;
825 tree init = NULL_TREE;
826 bool saw_complete = false;
827
828 /* If we are in a lambda function, we can move out until we hit:
829 1. a non-lambda function or NSDMI,
830 2. a lambda function capturing 'this', or
831 3. a non-default capturing lambda function. */
832 for (tree tlambda = lambda; ;)
833 {
834 if (add_capture_p
835 && LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (tlambda) == CPLD_NONE)
836 /* tlambda won't let us capture 'this'. */
837 break;
838
839 if (add_capture_p)
840 lambda_stack = tree_cons (NULL_TREE,
841 tlambda,
842 lambda_stack);
843
844 tree closure = LAMBDA_EXPR_CLOSURE (tlambda);
845 if (COMPLETE_TYPE_P (closure))
846 /* We're instantiating a generic lambda op(), the containing
847 scope may be gone. */
848 saw_complete = true;
849
850 tree containing_function
851 = decl_function_context (TYPE_NAME (closure));
852
853 tree ex = LAMBDA_EXPR_EXTRA_SCOPE (tlambda);
854 if (ex && TREE_CODE (ex) == FIELD_DECL)
855 {
856 /* Lambda in an NSDMI. We don't have a function to look up
857 'this' in, but we can find (or rebuild) the fake one from
858 inject_this_parameter. */
859 if (!containing_function && !saw_complete)
860 /* If we're parsing a lambda in a non-local class,
861 we can find the fake 'this' in scope_chain. */
862 init = scope_chain->x_current_class_ptr;
863 else
864 /* Otherwise it's either gone or buried in
865 function_context_stack, so make another. */
866 init = build_this_parm (NULL_TREE, DECL_CONTEXT (ex),
867 TYPE_UNQUALIFIED);
868 gcc_checking_assert
869 (init && (TREE_TYPE (TREE_TYPE (init))
870 == current_nonlambda_class_type ()));
871 break;
872 }
873
874 if (containing_function == NULL_TREE)
875 /* We ran out of scopes; there's no 'this' to capture. */
876 break;
877
878 if (!LAMBDA_FUNCTION_P (containing_function))
879 {
880 /* We found a non-lambda function.
881 There is no this pointer in xobj member functions. */
882 if (DECL_IOBJ_MEMBER_FUNCTION_P (containing_function))
883 /* First parameter is 'this'. */
884 init = DECL_ARGUMENTS (containing_function);
885 break;
886 }
887
888 tlambda
889 = CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (containing_function));
890
891 if (LAMBDA_EXPR_THIS_CAPTURE (tlambda))
892 {
893 /* An outer lambda has already captured 'this'. */
894 init = LAMBDA_EXPR_THIS_CAPTURE (tlambda);
895 break;
896 }
897 }
898
899 if (init)
900 {
901 if (add_capture_p)
902 this_capture = add_default_capture (lambda_stack,
903 /*id=*/this_identifier,
904 init);
905 else
906 this_capture = init;
907 }
908 }
909
910 if (cp_unevaluated_operand)
911 result = this_capture;
912 else if (!this_capture)
913 {
914 if (add_capture_p == 1)
915 {
916 error ("%<this%> was not captured for this lambda function");
917 result = error_mark_node;
918 }
919 else
920 result = NULL_TREE;
921 }
922 else
923 {
924 /* To make sure that current_class_ref is for the lambda. */
925 gcc_assert (!current_class_ref
926 || (TYPE_MAIN_VARIANT (TREE_TYPE (current_class_ref))
927 == LAMBDA_EXPR_CLOSURE (lambda)));
928
929 result = this_capture;
930
931 /* If 'this' is captured, each use of 'this' is transformed into an
932 access to the corresponding unnamed data member of the closure
933 type cast (_expr.cast_ 5.4) to the type of 'this'. [ The cast
934 ensures that the transformed expression is an rvalue. ] */
935 result = rvalue (result);
936 }
937
938 return result;
939 }
940
941 /* Return the innermost LAMBDA_EXPR we're currently in, if any. */
942
943 tree
944 current_lambda_expr (void)
945 {
946 tree type = current_class_type;
947 while (type && !LAMBDA_TYPE_P (type))
948 type = decl_type_context (TYPE_NAME (type));
949 if (type)
950 return CLASSTYPE_LAMBDA_EXPR (type);
951 else
952 return NULL_TREE;
953 }
954
955 /* Return the current LAMBDA_EXPR, if this is a resolvable dummy
956 object. NULL otherwise.. */
957
958 static tree
959 resolvable_dummy_lambda (tree object)
960 {
961 if (!is_dummy_object (object))
962 return NULL_TREE;
963
964 tree type = TYPE_MAIN_VARIANT (TREE_TYPE (object));
965 gcc_assert (!TYPE_PTR_P (type));
966
967 if (type != current_class_type
968 && current_class_type
969 && LAMBDA_TYPE_P (current_class_type)
970 && lambda_function (current_class_type)
971 && DERIVED_FROM_P (type, nonlambda_method_basetype()))
972 return CLASSTYPE_LAMBDA_EXPR (current_class_type);
973
974 return NULL_TREE;
975 }
976
977 /* We don't want to capture 'this' until we know we need it, i.e. after
978 overload resolution has chosen a non-static member function. At that
979 point we call this function to turn a dummy object into a use of the
980 'this' capture. */
981
982 tree
983 maybe_resolve_dummy (tree object, bool add_capture_p)
984 {
985 if (tree lam = resolvable_dummy_lambda (object))
986 if (tree cap = lambda_expr_this_capture (lam, add_capture_p))
987 if (cap != error_mark_node)
988 object = build_fold_indirect_ref (cap);
989
990 return object;
991 }
992
993 /* When parsing a generic lambda containing an argument-dependent
994 member function call we defer overload resolution to instantiation
995 time. But we have to know now whether to capture this or not.
996 Do that if FNS contains any non-static fns as per
997 [expr.prim.lambda.capture]/7.1. */
998
999 void
1000 maybe_generic_this_capture (tree object, tree fns)
1001 {
1002 if (tree lam = resolvable_dummy_lambda (object))
1003 if (!LAMBDA_EXPR_THIS_CAPTURE (lam))
1004 {
1005 /* We've not yet captured, so look at the function set of
1006 interest. */
1007 if (BASELINK_P (fns))
1008 fns = BASELINK_FUNCTIONS (fns);
1009 bool id_expr = TREE_CODE (fns) == TEMPLATE_ID_EXPR;
1010 if (id_expr)
1011 fns = TREE_OPERAND (fns, 0);
1012
1013 for (lkp_iterator iter (fns); iter; ++iter)
1014 if (((!id_expr && TREE_CODE (*iter) != USING_DECL)
1015 || TREE_CODE (*iter) == TEMPLATE_DECL)
1016 && DECL_OBJECT_MEMBER_FUNCTION_P (*iter))
1017 {
1018 /* Found a non-static member. Capture this. */
1019 lambda_expr_this_capture (lam, /*maybe*/-1);
1020 break;
1021 }
1022 }
1023 }
1024
1025 /* Returns the innermost non-lambda function. */
1026
1027 tree
1028 current_nonlambda_function (void)
1029 {
1030 tree fn = current_function_decl;
1031 while (fn && LAMBDA_FUNCTION_P (fn))
1032 fn = decl_function_context (fn);
1033 return fn;
1034 }
1035
1036 /* Returns the method basetype of the innermost non-lambda function, including
1037 a hypothetical constructor if inside an NSDMI, or NULL_TREE if none. */
1038
1039 tree
1040 nonlambda_method_basetype (void)
1041 {
1042 tree type = current_class_type;
1043 if (!type || !LAMBDA_TYPE_P (type))
1044 return current_class_ref ? type : NULL_TREE;
1045
1046 while (true)
1047 {
1048 tree lam = CLASSTYPE_LAMBDA_EXPR (type);
1049 tree ex = LAMBDA_EXPR_EXTRA_SCOPE (lam);
1050 if (ex && TREE_CODE (ex) == FIELD_DECL)
1051 /* Lambda in an NSDMI. */
1052 return DECL_CONTEXT (ex);
1053
1054 tree fn = TYPE_CONTEXT (type);
1055 if (!fn || TREE_CODE (fn) != FUNCTION_DECL
1056 || !DECL_IOBJ_MEMBER_FUNCTION_P (fn))
1057 /* No enclosing non-lambda method. */
1058 return NULL_TREE;
1059 if (!LAMBDA_FUNCTION_P (fn))
1060 /* Found an enclosing non-lambda method. */
1061 return TYPE_METHOD_BASETYPE (TREE_TYPE (fn));
1062 type = DECL_CONTEXT (fn);
1063 }
1064 }
1065
1066 /* Like current_scope, but looking through lambdas. If ONLY_SKIP_CLOSURES_P,
1067 only look through closure types. */
1068
1069 tree
1070 current_nonlambda_scope (bool only_skip_closures_p/*=false*/)
1071 {
1072 tree scope = current_scope ();
1073 for (;;)
1074 {
1075 if (!only_skip_closures_p
1076 && TREE_CODE (scope) == FUNCTION_DECL
1077 && LAMBDA_FUNCTION_P (scope))
1078 {
1079 scope = CP_TYPE_CONTEXT (DECL_CONTEXT (scope));
1080 continue;
1081 }
1082 else if (LAMBDA_TYPE_P (scope))
1083 {
1084 scope = CP_TYPE_CONTEXT (scope);
1085 continue;
1086 }
1087 break;
1088 }
1089 return scope;
1090 }
1091
1092 /* Helper function for maybe_add_lambda_conv_op; build a CALL_EXPR with
1093 indicated FN and NARGS, but do not initialize the return type or any of the
1094 argument slots. */
1095
1096 static tree
1097 prepare_op_call (tree fn, int nargs)
1098 {
1099 tree t;
1100
1101 t = build_vl_exp (CALL_EXPR, nargs + 3);
1102 CALL_EXPR_FN (t) = fn;
1103 CALL_EXPR_STATIC_CHAIN (t) = NULL;
1104
1105 return t;
1106 }
1107
1108 /* Return true iff CALLOP is the op() for a generic lambda. */
1109
1110 bool
1111 generic_lambda_fn_p (tree callop)
1112 {
1113 return (LAMBDA_FUNCTION_P (callop)
1114 && DECL_TEMPLATE_INFO (callop)
1115 && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (callop)));
1116 }
1117
1118 /* If the closure TYPE has a static op(), also add a conversion to function
1119 pointer. */
1120
1121 void
1122 maybe_add_lambda_conv_op (tree type)
1123 {
1124 bool nested = (cfun != NULL);
1125 bool nested_def = decl_function_context (TYPE_MAIN_DECL (type));
1126 tree callop = lambda_function (type);
1127 tree lam = CLASSTYPE_LAMBDA_EXPR (type);
1128
1129 if (LAMBDA_EXPR_CAPTURE_LIST (lam) != NULL_TREE
1130 || LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam) != CPLD_NONE)
1131 return;
1132
1133 if (processing_template_decl)
1134 return;
1135
1136 bool const generic_lambda_p = generic_lambda_fn_p (callop);
1137
1138 if (!generic_lambda_p && undeduced_auto_decl (callop))
1139 {
1140 /* If the op() wasn't deduced due to errors, give up. */
1141 gcc_assert (errorcount || sorrycount);
1142 return;
1143 }
1144
1145 /* Non-generic non-capturing lambdas only have a conversion function to
1146 pointer to function when the trailing requires-clause's constraints are
1147 satisfied. */
1148 if (!generic_lambda_p && !constraints_satisfied_p (callop))
1149 return;
1150
1151 /* Non-template conversion operators are defined directly with build_call_a
1152 and using DIRECT_ARGVEC for arguments (including 'this'). Templates are
1153 deferred and the CALL is built in-place. In the case of a deduced return
1154 call op, the decltype expression, DECLTYPE_CALL, used as a substitute for
1155 the return type is also built in-place. The arguments of DECLTYPE_CALL in
1156 the return expression may differ in flags from those in the body CALL. In
1157 particular, parameter pack expansions are marked PACK_EXPANSION_LOCAL_P in
1158 the body CALL, but not in DECLTYPE_CALL. */
1159
1160 vec<tree, va_gc> *direct_argvec = 0;
1161 tree decltype_call = 0, call = 0;
1162 tree optype = TREE_TYPE (callop);
1163 tree fn_result = TREE_TYPE (optype);
1164
1165 tree thisarg = NULL_TREE;
1166 if (TREE_CODE (optype) == METHOD_TYPE)
1167 thisarg = build_int_cst (TREE_TYPE (DECL_ARGUMENTS (callop)), 0);
1168 if (generic_lambda_p)
1169 {
1170 ++processing_template_decl;
1171
1172 /* Prepare the dependent member call for the static member function
1173 '_FUN' and, potentially, prepare another call to be used in a decltype
1174 return expression for a deduced return call op to allow for simple
1175 implementation of the conversion operator. */
1176
1177 tree objfn;
1178 int nargs = list_length (DECL_ARGUMENTS (callop));
1179 if (thisarg)
1180 {
1181 tree instance = cp_build_fold_indirect_ref (thisarg);
1182 objfn = lookup_template_function (DECL_NAME (callop),
1183 DECL_TI_ARGS (callop));
1184 objfn = build_min (COMPONENT_REF, NULL_TREE,
1185 instance, objfn, NULL_TREE);
1186 --nargs;
1187 call = prepare_op_call (objfn, nargs);
1188 }
1189 else
1190 objfn = callop;
1191
1192 if (type_uses_auto (fn_result))
1193 decltype_call = prepare_op_call (objfn, nargs);
1194 }
1195 else if (thisarg)
1196 {
1197 direct_argvec = make_tree_vector ();
1198 direct_argvec->quick_push (thisarg);
1199 }
1200
1201 /* Copy CALLOP's argument list (as per 'copy_list') as FN_ARGS in order to
1202 declare the static member function "_FUN" below. For each arg append to
1203 DIRECT_ARGVEC (for the non-template case) or populate the pre-allocated
1204 call args (for the template case). If a parameter pack is found, expand
1205 it, flagging it as PACK_EXPANSION_LOCAL_P for the body call. */
1206
1207 tree fn_args = NULL_TREE;
1208 {
1209 int ix = 0;
1210 tree src = FUNCTION_FIRST_USER_PARM (callop);
1211 tree tgt = NULL;
1212
1213 if (!thisarg && !decltype_call)
1214 src = NULL_TREE;
1215 while (src)
1216 {
1217 tree new_node = copy_node (src);
1218 /* We set DECL_CONTEXT of NEW_NODE to the statfn below.
1219 Notice this is creating a recursive type! */
1220
1221 /* Clear TREE_ADDRESSABLE on thunk arguments. */
1222 TREE_ADDRESSABLE (new_node) = 0;
1223
1224 if (!fn_args)
1225 fn_args = tgt = new_node;
1226 else
1227 {
1228 TREE_CHAIN (tgt) = new_node;
1229 tgt = new_node;
1230 }
1231
1232 mark_exp_read (tgt);
1233
1234 if (generic_lambda_p)
1235 {
1236 tree a = tgt;
1237 if (thisarg)
1238 {
1239 if (DECL_PACK_P (tgt))
1240 {
1241 a = make_pack_expansion (a);
1242 PACK_EXPANSION_LOCAL_P (a) = true;
1243 }
1244 CALL_EXPR_ARG (call, ix) = a;
1245 }
1246
1247 if (decltype_call)
1248 {
1249 /* Avoid capturing variables in this context. */
1250 ++cp_unevaluated_operand;
1251 CALL_EXPR_ARG (decltype_call, ix) = forward_parm (tgt);
1252 --cp_unevaluated_operand;
1253 }
1254
1255 ++ix;
1256 }
1257 else
1258 vec_safe_push (direct_argvec, tgt);
1259
1260 src = TREE_CHAIN (src);
1261 }
1262 }
1263
1264 if (generic_lambda_p)
1265 {
1266 if (decltype_call)
1267 {
1268 fn_result = finish_decltype_type
1269 (decltype_call, /*id_expression_or_member_access_p=*/false,
1270 tf_warning_or_error);
1271 }
1272 }
1273 else if (thisarg)
1274 {
1275 /* Don't warn on deprecated or unavailable lambda declarations, unless
1276 the lambda is actually called. */
1277 auto du = make_temp_override (deprecated_state,
1278 UNAVAILABLE_DEPRECATED_SUPPRESS);
1279 call = build_call_a (callop, direct_argvec->length (),
1280 direct_argvec->address ());
1281 }
1282
1283 if (thisarg)
1284 {
1285 CALL_FROM_THUNK_P (call) = 1;
1286 SET_EXPR_LOCATION (call, UNKNOWN_LOCATION);
1287 }
1288
1289 tree stattype
1290 = build_function_type (fn_result, FUNCTION_FIRST_USER_PARMTYPE (callop));
1291 stattype = (cp_build_type_attribute_variant
1292 (stattype, TYPE_ATTRIBUTES (optype)));
1293 if (flag_noexcept_type
1294 && TYPE_NOTHROW_P (TREE_TYPE (callop)))
1295 stattype = build_exception_variant (stattype, noexcept_true_spec);
1296
1297 if (generic_lambda_p)
1298 --processing_template_decl;
1299
1300 /* First build up the conversion op. */
1301
1302 tree rettype = build_pointer_type (stattype);
1303 tree name = make_conv_op_name (rettype);
1304 tree thistype = cp_build_qualified_type (type, TYPE_QUAL_CONST);
1305 tree fntype = build_method_type_directly (thistype, rettype, void_list_node);
1306 /* DR 1722: The conversion function should be noexcept. */
1307 fntype = build_exception_variant (fntype, noexcept_true_spec);
1308 tree convfn = build_lang_decl (FUNCTION_DECL, name, fntype);
1309 SET_DECL_LANGUAGE (convfn, lang_cplusplus);
1310 tree fn = convfn;
1311 DECL_SOURCE_LOCATION (fn) = DECL_SOURCE_LOCATION (callop);
1312 SET_DECL_ALIGN (fn, MINIMUM_METHOD_BOUNDARY);
1313 grokclassfn (type, fn, NO_SPECIAL);
1314 set_linkage_according_to_type (type, fn);
1315 rest_of_decl_compilation (fn, namespace_bindings_p (), at_eof);
1316 DECL_IN_AGGR_P (fn) = 1;
1317 DECL_ARTIFICIAL (fn) = 1;
1318 DECL_NOT_REALLY_EXTERN (fn) = 1;
1319 DECL_DECLARED_INLINE_P (fn) = 1;
1320 DECL_DECLARED_CONSTEXPR_P (fn) = DECL_DECLARED_CONSTEXPR_P (callop);
1321 if (DECL_IMMEDIATE_FUNCTION_P (callop))
1322 SET_DECL_IMMEDIATE_FUNCTION_P (fn);
1323 DECL_ARGUMENTS (fn) = build_this_parm (fn, fntype, TYPE_QUAL_CONST);
1324
1325 if (nested_def)
1326 DECL_INTERFACE_KNOWN (fn) = 1;
1327
1328 if (generic_lambda_p)
1329 fn = add_inherited_template_parms (fn, DECL_TI_TEMPLATE (callop));
1330
1331 add_method (type, fn, false);
1332
1333 if (thisarg == NULL_TREE)
1334 {
1335 /* For static lambda, just return operator(). */
1336 if (nested)
1337 push_function_context ();
1338 else
1339 /* Still increment function_depth so that we don't GC in the
1340 middle of an expression. */
1341 ++function_depth;
1342
1343 /* Generate the body of the conversion op. */
1344
1345 start_preparsed_function (convfn, NULL_TREE,
1346 SF_PRE_PARSED | SF_INCLASS_INLINE);
1347 tree body = begin_function_body ();
1348 tree compound_stmt = begin_compound_stmt (0);
1349
1350 /* decl_needed_p needs to see that it's used. */
1351 TREE_USED (callop) = 1;
1352 finish_return_stmt (decay_conversion (callop, tf_warning_or_error));
1353
1354 finish_compound_stmt (compound_stmt);
1355 finish_function_body (body);
1356
1357 fn = finish_function (/*inline_p=*/true);
1358 if (!generic_lambda_p)
1359 expand_or_defer_fn (fn);
1360
1361 if (nested)
1362 pop_function_context ();
1363 else
1364 --function_depth;
1365 return;
1366 }
1367
1368 /* Generic thunk code fails for varargs; we'll complain in mark_used if
1369 the conversion op is used. */
1370 if (varargs_function_p (callop))
1371 {
1372 DECL_DELETED_FN (fn) = 1;
1373 return;
1374 }
1375
1376 /* Now build up the thunk to be returned. */
1377
1378 tree statfn = build_lang_decl (FUNCTION_DECL, fun_identifier, stattype);
1379 SET_DECL_LANGUAGE (statfn, lang_cplusplus);
1380 fn = statfn;
1381 DECL_SOURCE_LOCATION (fn) = DECL_SOURCE_LOCATION (callop);
1382 grokclassfn (type, fn, NO_SPECIAL);
1383 set_linkage_according_to_type (type, fn);
1384 rest_of_decl_compilation (fn, namespace_bindings_p (), at_eof);
1385 DECL_IN_AGGR_P (fn) = 1;
1386 DECL_ARTIFICIAL (fn) = 1;
1387 DECL_NOT_REALLY_EXTERN (fn) = 1;
1388 DECL_DECLARED_INLINE_P (fn) = 1;
1389 DECL_STATIC_FUNCTION_P (fn) = 1;
1390 DECL_DECLARED_CONSTEXPR_P (fn) = DECL_DECLARED_CONSTEXPR_P (callop);
1391 if (DECL_IMMEDIATE_FUNCTION_P (callop))
1392 SET_DECL_IMMEDIATE_FUNCTION_P (fn);
1393 DECL_ARGUMENTS (fn) = fn_args;
1394 for (tree arg = fn_args; arg; arg = DECL_CHAIN (arg))
1395 {
1396 /* Avoid duplicate -Wshadow warnings. */
1397 DECL_NAME (arg) = NULL_TREE;
1398 DECL_CONTEXT (arg) = fn;
1399 }
1400 if (nested_def)
1401 DECL_INTERFACE_KNOWN (fn) = 1;
1402
1403 if (generic_lambda_p)
1404 fn = add_inherited_template_parms (fn, DECL_TI_TEMPLATE (callop));
1405
1406 if (flag_sanitize & SANITIZE_NULL)
1407 /* Don't UBsan this function; we're deliberately calling op() with a null
1408 object argument. */
1409 add_no_sanitize_value (fn, SANITIZE_UNDEFINED);
1410
1411 add_method (type, fn, false);
1412
1413 if (nested)
1414 push_function_context ();
1415 else
1416 /* Still increment function_depth so that we don't GC in the
1417 middle of an expression. */
1418 ++function_depth;
1419
1420 /* Generate the body of the thunk. */
1421
1422 start_preparsed_function (statfn, NULL_TREE,
1423 SF_PRE_PARSED | SF_INCLASS_INLINE);
1424 tree body = begin_function_body ();
1425 tree compound_stmt = begin_compound_stmt (0);
1426 if (!generic_lambda_p)
1427 {
1428 set_flags_from_callee (call);
1429 if (MAYBE_CLASS_TYPE_P (TREE_TYPE (call)))
1430 call = build_cplus_new (TREE_TYPE (call), call, tf_warning_or_error);
1431 }
1432 call = convert_from_reference (call);
1433 finish_return_stmt (call);
1434
1435 finish_compound_stmt (compound_stmt);
1436 finish_function_body (body);
1437
1438 fn = finish_function (/*inline_p=*/true);
1439 if (!generic_lambda_p)
1440 expand_or_defer_fn (fn);
1441
1442 /* Generate the body of the conversion op. */
1443
1444 start_preparsed_function (convfn, NULL_TREE,
1445 SF_PRE_PARSED | SF_INCLASS_INLINE);
1446 body = begin_function_body ();
1447 compound_stmt = begin_compound_stmt (0);
1448
1449 /* decl_needed_p needs to see that it's used. */
1450 TREE_USED (statfn) = 1;
1451 finish_return_stmt (decay_conversion (statfn, tf_warning_or_error));
1452
1453 finish_compound_stmt (compound_stmt);
1454 finish_function_body (body);
1455
1456 fn = finish_function (/*inline_p=*/true);
1457 if (!generic_lambda_p)
1458 expand_or_defer_fn (fn);
1459
1460 if (nested)
1461 pop_function_context ();
1462 else
1463 --function_depth;
1464 }
1465
1466 /* True if FN is the static function "_FUN" that gets returned from the lambda
1467 conversion operator. */
1468
1469 bool
1470 lambda_static_thunk_p (tree fn)
1471 {
1472 return (fn && TREE_CODE (fn) == FUNCTION_DECL
1473 && DECL_ARTIFICIAL (fn)
1474 && DECL_STATIC_FUNCTION_P (fn)
1475 && LAMBDA_TYPE_P (CP_DECL_CONTEXT (fn)));
1476 }
1477
1478 bool
1479 call_from_lambda_thunk_p (tree call)
1480 {
1481 return (CALL_FROM_THUNK_P (call)
1482 && lambda_static_thunk_p (current_function_decl));
1483 }
1484
1485 /* Returns true iff VAL is a lambda-related declaration which should
1486 be ignored by unqualified lookup. */
1487
1488 bool
1489 is_lambda_ignored_entity (tree val)
1490 {
1491 /* Look past normal, non-VLA capture proxies. */
1492 if (is_normal_capture_proxy (val)
1493 && !variably_modified_type_p (TREE_TYPE (val), NULL_TREE))
1494 return true;
1495
1496 /* Always ignore lambda fields, their names are only for debugging. */
1497 if (TREE_CODE (val) == FIELD_DECL
1498 && CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (val)))
1499 return true;
1500
1501 /* None of the lookups that use qualify_lookup want the op() from the
1502 lambda; they want the one from the enclosing class. */
1503 if (tree fns = maybe_get_fns (val))
1504 if (LAMBDA_FUNCTION_P (OVL_FIRST (fns)))
1505 return true;
1506
1507 return false;
1508 }
1509
1510 /* Lambdas that appear in variable initializer or default argument
1511 scope get that in their mangling, so we need to record it. Also,
1512 multiple lambdas in the same scope may need a mangling
1513 discriminator. In ABI <= 17, there is a single per-scope sequence
1514 number. In ABI >= 18, there are per-scope per-signature sequence
1515 numbers. */
1516 struct GTY(()) lambda_sig_count
1517 {
1518 tree fn; // The lambda fn whose sig this is.
1519 unsigned count;
1520 };
1521 struct GTY(()) lambda_discriminator
1522 {
1523 tree scope;
1524 unsigned nesting; // Inside a function, VAR_DECLs get the function
1525 // as scope. This counts that nesting.
1526 unsigned count; // The per-scope counter.
1527 vec<lambda_sig_count, va_gc> *discriminators; // Per-signature counters
1528 };
1529 // The current scope.
1530 static GTY(()) lambda_discriminator lambda_scope;
1531 // Stack of previous scopes.
1532 static GTY(()) vec<lambda_discriminator, va_gc> *lambda_scope_stack;
1533
1534 // Push DECL as lambda extra scope, also new discriminator counters.
1535
1536 void
1537 start_lambda_scope (tree decl)
1538 {
1539 gcc_checking_assert (decl);
1540 if (current_function_decl && VAR_P (decl))
1541 // If we're inside a function, we ignore variable scope. Don't push.
1542 lambda_scope.nesting++;
1543 else
1544 {
1545 vec_safe_push (lambda_scope_stack, lambda_scope);
1546 lambda_scope.scope = decl;
1547 lambda_scope.nesting = 0;
1548 lambda_scope.count = 0;
1549 lambda_scope.discriminators = nullptr;
1550 }
1551 }
1552
1553 // Pop from the current lambda extra scope.
1554
1555 void
1556 finish_lambda_scope (void)
1557 {
1558 if (!lambda_scope.nesting--)
1559 {
1560 lambda_scope = lambda_scope_stack->last ();
1561 lambda_scope_stack->pop ();
1562 }
1563 }
1564
1565 // Record the current lambda scope into LAMBDA
1566
1567 void
1568 record_lambda_scope (tree lambda)
1569 {
1570 tree closure = LAMBDA_EXPR_CLOSURE (lambda);
1571 gcc_checking_assert (closure);
1572
1573 /* Before ABI v20, lambdas in static data member initializers did not
1574 get a dedicated lambda scope. */
1575 tree scope = lambda_scope.scope;
1576 if (is_static_data_member_initialized_in_class (scope))
1577 {
1578 if (!abi_version_at_least (20))
1579 scope = NULL_TREE;
1580 if (warn_abi && abi_version_crosses (20) && !processing_template_decl)
1581 {
1582 if (abi_version_at_least (20))
1583 warning_at (location_of (closure), OPT_Wabi,
1584 "the mangled name of %qT changed in "
1585 "%<-fabi-version=20%> (GCC 15.1)", closure);
1586 else
1587 warning_at (location_of (closure), OPT_Wabi,
1588 "the mangled name of %qT changes in "
1589 "%<-fabi-version=20%> (GCC 15.1)", closure);
1590 }
1591 }
1592
1593 /* An otherwise unattached class-scope lambda in a member template
1594 should not have a mangling scope, as the mangling scope will not
1595 correctly inherit on instantiation. */
1596 tree ctx = TYPE_CONTEXT (closure);
1597 if (scope
1598 && ctx
1599 && CLASS_TYPE_P (ctx)
1600 && ctx == TREE_TYPE (scope)
1601 && current_template_depth > template_class_depth (ctx))
1602 scope = NULL_TREE;
1603
1604 LAMBDA_EXPR_EXTRA_SCOPE (lambda) = scope;
1605 if (scope)
1606 maybe_key_decl (scope, TYPE_NAME (closure));
1607 }
1608
1609 // Compare lambda template heads TMPL_A and TMPL_B, used for both
1610 // templated lambdas, and template template parameters of said lambda.
1611
1612 static bool
1613 compare_lambda_template_head (tree tmpl_a, tree tmpl_b)
1614 {
1615 // We only need one level of template parms
1616 tree inner_a = INNERMOST_TEMPLATE_PARMS (DECL_TEMPLATE_PARMS (tmpl_a));
1617 tree inner_b = INNERMOST_TEMPLATE_PARMS (DECL_TEMPLATE_PARMS (tmpl_b));
1618
1619 // We only compare explicit template parms, ignoring trailing
1620 // synthetic ones.
1621 int len_a = TREE_VEC_LENGTH (inner_a);
1622 int len_b = TREE_VEC_LENGTH (inner_b);
1623
1624 for (int ix = 0, len = MAX (len_a, len_b); ix != len; ix++)
1625 {
1626 tree parm_a = NULL_TREE;
1627 if (ix < len_a)
1628 {
1629 parm_a = TREE_VEC_ELT (inner_a, ix);
1630 if (parm_a == error_mark_node)
1631 return false;
1632 parm_a = TREE_VALUE (parm_a);
1633 if (parm_a == error_mark_node)
1634 return false;
1635 if (DECL_VIRTUAL_P (parm_a))
1636 parm_a = NULL_TREE;
1637 }
1638
1639 tree parm_b = NULL_TREE;
1640 if (ix < len_b)
1641 {
1642 parm_b = TREE_VEC_ELT (inner_b, ix);
1643 if (parm_b == error_mark_node)
1644 return false;
1645 parm_b = TREE_VALUE (parm_b);
1646 if (parm_b == error_mark_node)
1647 return false;
1648 if (DECL_VIRTUAL_P (parm_b))
1649 parm_b = NULL_TREE;
1650 }
1651
1652 if (!parm_a && !parm_b)
1653 // we're done
1654 break;
1655
1656 if (!(parm_a && parm_b))
1657 return false;
1658
1659 if (TREE_CODE (parm_a) != TREE_CODE (parm_b))
1660 return false;
1661
1662 if (TREE_CODE (parm_a) == PARM_DECL)
1663 {
1664 if (TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (parm_a))
1665 != TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (parm_b)))
1666 return false;
1667
1668 if (!same_type_p (TREE_TYPE (parm_a), TREE_TYPE (parm_b)))
1669 return false;
1670 }
1671 else
1672 {
1673 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (parm_a))
1674 != TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (parm_b)))
1675 return false;
1676
1677 if (TREE_CODE (parm_a) != TEMPLATE_DECL)
1678 gcc_checking_assert (TREE_CODE (parm_a) == TYPE_DECL);
1679 else if (!compare_lambda_template_head (parm_a, parm_b))
1680 return false;
1681 }
1682 }
1683
1684 return true;
1685 }
1686
1687 // Compare lambda signatures FN_A and FN_B, they may be TEMPLATE_DECLs too.
1688
1689 static bool
1690 compare_lambda_sig (tree fn_a, tree fn_b)
1691 {
1692 if (TREE_CODE (fn_a) == TEMPLATE_DECL
1693 && TREE_CODE (fn_b) == TEMPLATE_DECL)
1694 {
1695 if (!compare_lambda_template_head (fn_a, fn_b))
1696 return false;
1697 fn_a = DECL_TEMPLATE_RESULT (fn_a);
1698 fn_b = DECL_TEMPLATE_RESULT (fn_b);
1699 }
1700 else if (TREE_CODE (fn_a) == TEMPLATE_DECL
1701 || TREE_CODE (fn_b) == TEMPLATE_DECL)
1702 return false;
1703
1704 if (fn_a == error_mark_node
1705 || fn_b == error_mark_node)
1706 return false;
1707
1708 for (tree args_a = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (fn_a))),
1709 args_b = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (fn_b)));
1710 args_a || args_b;
1711 args_a = TREE_CHAIN (args_a), args_b = TREE_CHAIN (args_b))
1712 {
1713 if (!args_a || !args_b)
1714 return false;
1715 // This check also deals with differing variadicness
1716 if (!same_type_p (TREE_VALUE (args_a), TREE_VALUE (args_b)))
1717 return false;
1718 }
1719
1720 return true;
1721 }
1722
1723 // Record the per-scope discriminator of LAMBDA. If the extra scope
1724 // is empty, we must use the empty scope counter, which might not be
1725 // the live one.
1726
1727 void
1728 record_lambda_scope_discriminator (tree lambda)
1729 {
1730 auto *slot = (vec_safe_is_empty (lambda_scope_stack)
1731 || LAMBDA_EXPR_EXTRA_SCOPE (lambda)
1732 ? &lambda_scope : lambda_scope_stack->begin ());
1733 LAMBDA_EXPR_SCOPE_ONLY_DISCRIMINATOR (lambda) = slot->count++;
1734 }
1735
1736 // Record the per-scope per-signature discriminator of LAMBDA. If the
1737 // extra scope is empty, we must use the empty scope counter, which
1738 // might not be the live one.
1739
1740 void
1741 record_lambda_scope_sig_discriminator (tree lambda, tree fn)
1742 {
1743 auto *slot = (vec_safe_is_empty (lambda_scope_stack)
1744 || LAMBDA_EXPR_EXTRA_SCOPE (lambda)
1745 ? &lambda_scope : lambda_scope_stack->begin ());
1746 gcc_checking_assert (LAMBDA_EXPR_EXTRA_SCOPE (lambda) == slot->scope);
1747
1748 // A linear search, we're not expecting this to be a big list, and
1749 // this avoids needing a signature hash function.
1750 lambda_sig_count *sig;
1751 if (unsigned ix = vec_safe_length (slot->discriminators))
1752 for (sig = slot->discriminators->begin (); ix--; sig++)
1753 if (compare_lambda_sig (fn, sig->fn))
1754 goto found;
1755 {
1756 lambda_sig_count init = {fn, 0};
1757 sig = vec_safe_push (slot->discriminators, init);
1758 }
1759 found:
1760 LAMBDA_EXPR_SCOPE_SIG_DISCRIMINATOR (lambda) = sig->count++;
1761 }
1762
1763 tree
1764 start_lambda_function (tree fco, tree lambda_expr)
1765 {
1766 /* Let the front end know that we are going to be defining this
1767 function. */
1768 start_preparsed_function (fco,
1769 NULL_TREE,
1770 SF_PRE_PARSED | SF_INCLASS_INLINE);
1771
1772 tree body = begin_function_body ();
1773
1774 /* Push the proxies for any explicit captures. */
1775 for (tree cap = LAMBDA_EXPR_CAPTURE_LIST (lambda_expr); cap;
1776 cap = TREE_CHAIN (cap))
1777 build_capture_proxy (TREE_PURPOSE (cap), TREE_VALUE (cap));
1778
1779 return body;
1780 }
1781
1782 /* Subroutine of prune_lambda_captures: CAP is a node in
1783 LAMBDA_EXPR_CAPTURE_LIST. Return the variable it captures for which we
1784 might optimize away the capture, or NULL_TREE if there is no such
1785 variable. */
1786
1787 static tree
1788 var_to_maybe_prune (tree cap)
1789 {
1790 if (LAMBDA_CAPTURE_EXPLICIT_P (cap))
1791 /* Don't prune explicit captures. */
1792 return NULL_TREE;
1793
1794 tree mem = TREE_PURPOSE (cap);
1795 if (!DECL_P (mem) || !DECL_NORMAL_CAPTURE_P (mem))
1796 /* Packs and init-captures aren't captures of constant vars. */
1797 return NULL_TREE;
1798
1799 tree init = TREE_VALUE (cap);
1800 if (is_normal_capture_proxy (init))
1801 init = DECL_CAPTURED_VARIABLE (init);
1802 if (decl_constant_var_p (init))
1803 return init;
1804
1805 return NULL_TREE;
1806 }
1807
1808 /* walk_tree helper for prune_lambda_captures: Remember which capture proxies
1809 for constant variables are actually used in the lambda body.
1810
1811 There will always be a DECL_EXPR for the capture proxy; remember it when we
1812 see it, but replace it with any other use. */
1813
1814 static tree
1815 mark_const_cap_r (tree *t, int *walk_subtrees, void *data)
1816 {
1817 hash_map<tree,tree*> &const_vars = *(hash_map<tree,tree*>*)data;
1818
1819 tree var = NULL_TREE;
1820 if (TREE_CODE (*t) == DECL_EXPR)
1821 {
1822 tree decl = DECL_EXPR_DECL (*t);
1823 if (is_constant_capture_proxy (decl))
1824 {
1825 var = DECL_CAPTURED_VARIABLE (decl);
1826 *walk_subtrees = 0;
1827 }
1828 }
1829 else if (!location_wrapper_p (*t) /* is_capture_proxy dislikes them. */
1830 && is_constant_capture_proxy (*t))
1831 var = DECL_CAPTURED_VARIABLE (*t);
1832
1833 if (var)
1834 {
1835 tree *&slot = const_vars.get_or_insert (var);
1836 if (!slot || VAR_P (*t))
1837 slot = t;
1838 }
1839
1840 return NULL_TREE;
1841 }
1842
1843 /* We're at the end of processing a lambda; go back and remove any captures of
1844 constant variables for which we've folded away all uses. */
1845
1846 static void
1847 prune_lambda_captures (tree body)
1848 {
1849 tree lam = current_lambda_expr ();
1850 if (!LAMBDA_EXPR_CAPTURE_OPTIMIZED (lam))
1851 /* No uses were optimized away. */
1852 return;
1853 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam) == CPLD_NONE)
1854 /* No default captures, and we don't prune explicit captures. */
1855 return;
1856 /* Don't bother pruning in a template, we'll prune at instantiation time. */
1857 if (dependent_type_p (TREE_TYPE (lam)))
1858 return;
1859
1860 hash_map<tree,tree*> const_vars;
1861
1862 cp_walk_tree_without_duplicates (&body, mark_const_cap_r, &const_vars);
1863
1864 tree bind_expr = expr_single (DECL_SAVED_TREE (lambda_function (lam)));
1865 if (bind_expr && TREE_CODE (bind_expr) == MUST_NOT_THROW_EXPR)
1866 bind_expr = expr_single (TREE_OPERAND (bind_expr, 0));
1867 /* FIXME: We don't currently handle noexcept lambda captures correctly,
1868 so bind_expr may not be set; see PR c++/119764. */
1869 gcc_assert (!bind_expr || TREE_CODE (bind_expr) == BIND_EXPR);
1870
1871 tree *fieldp = &TYPE_FIELDS (LAMBDA_EXPR_CLOSURE (lam));
1872 for (tree *capp = &LAMBDA_EXPR_CAPTURE_LIST (lam); *capp; )
1873 {
1874 tree cap = *capp;
1875 if (tree var = var_to_maybe_prune (cap))
1876 {
1877 tree **use = const_vars.get (var);
1878 if (use && TREE_CODE (**use) == DECL_EXPR)
1879 {
1880 /* All uses of this capture were folded away, leaving only the
1881 proxy declaration. */
1882
1883 /* Splice the capture out of LAMBDA_EXPR_CAPTURE_LIST. */
1884 *capp = TREE_CHAIN (cap);
1885
1886 /* And out of TYPE_FIELDS. */
1887 tree field = TREE_PURPOSE (cap);
1888 while (*fieldp != field)
1889 fieldp = &DECL_CHAIN (*fieldp);
1890 *fieldp = DECL_CHAIN (*fieldp);
1891
1892 /* And out of the bindings for the function. */
1893 tree *blockp = &BLOCK_VARS (current_binding_level->blocks);
1894 while (*blockp != DECL_EXPR_DECL (**use))
1895 blockp = &DECL_CHAIN (*blockp);
1896 *blockp = DECL_CHAIN (*blockp);
1897
1898 /* And maybe out of the vars declared in the containing
1899 BIND_EXPR, if it's listed there. */
1900 if (bind_expr)
1901 {
1902 tree *bindp = &BIND_EXPR_VARS (bind_expr);
1903 while (*bindp && *bindp != DECL_EXPR_DECL (**use))
1904 bindp = &DECL_CHAIN (*bindp);
1905 if (*bindp)
1906 *bindp = DECL_CHAIN (*bindp);
1907 }
1908
1909 /* And remove the capture proxy declaration. */
1910 **use = void_node;
1911 continue;
1912 }
1913 }
1914
1915 capp = &TREE_CHAIN (cap);
1916 }
1917 }
1918
1919 // Record the per-scope per-signature discriminator of LAMBDA. If the
1920 // extra scope is empty, we must use the empty scope counter, which
1921 // might not be the live one.
1922
1923 void
1924 finish_lambda_function (tree body)
1925 {
1926 finish_function_body (body);
1927
1928 prune_lambda_captures (body);
1929
1930 /* Finish the function and generate code for it if necessary. */
1931 tree fn = finish_function (/*inline_p=*/true);
1932
1933 /* Only expand if the call op is not a template. */
1934 if (!DECL_TEMPLATE_INFO (fn))
1935 expand_or_defer_fn (fn);
1936 }
1937
1938 #include "gt-cp-lambda.h"