Skip to content

Commit 47fbb70

Browse files
authored
Add support for generic lambda with explicit type list (#349)
Currently cppfront process the following code: ```cpp main: () = { g := :<T> () = { v := 0; }; } ``` And generates: ```cpp auto main() -> int{ auto g {template <typename T> []() -> void{auto v {0}; }}; } ``` After this change cppfront will generate: ```cpp auto main() -> int{ auto g {[]<typename T>() -> void{auto v {0}; }}; } ``` Closes: #346. All regression tests pass.
1 parent 0bac3bc commit 47fbb70

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

source/cppfront.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,6 +2370,12 @@ class cppfront
23702370
// Handle an anonymous function
23712371
if (decl->is_function()) {
23722372
auto lambda_intro = build_capture_lambda_intro_for(decl->captures, n.position());
2373+
2374+
// Handle an anonymous generic function with explicit type list
2375+
if (decl->template_parameters) {
2376+
print_to_string(&lambda_intro, *decl->template_parameters, false, true);
2377+
}
2378+
23732379
emit(*decl, lambda_intro);
23742380
}
23752381
// Else an anonymous object as 'typeid { initializer }'
@@ -4851,6 +4857,7 @@ class cppfront
48514857
printer.get_phase() < printer.phase2_func_defs
48524858
|| (
48534859
n.is_function()
4860+
&& n.has_name() // only if it is not unnambed function aka lambda
48544861
&& n.initializer // only if the function has a definition (is not abstract)
48554862
&& printer.get_phase() == printer.phase2_func_defs
48564863
)

0 commit comments

Comments
 (0)