diff --git a/CHANGES.current b/CHANGES.current
index 38c0b7011..fbf85ba3e 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -7,6 +7,9 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.1.0 (in progress)
===========================
+2022-07-27: ZackerySpytz, olly
+ #1678 Support parsing C++20 templated lambdas.
+
2022-07-27: ZackerySpytz, olly
#1622 Add support for the C++20 spaceship operator (<=>).
diff --git a/Doc/Manual/CPlusPlus20.html b/Doc/Manual/CPlusPlus20.html
index 8db84bfd5..0f29a03b8 100644
--- a/Doc/Manual/CPlusPlus20.html
+++ b/Doc/Manual/CPlusPlus20.html
@@ -50,6 +50,14 @@ or attempts to automatically map it to a three-way comparison operator
in any target languages that have one.
+
+
+
+SWIG should parse lambda templates, but
+like
+ non-templated lambdas they aren't currently wrapped.
+
+
diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk
index 838ea5d2a..6ca3aef22 100644
--- a/Examples/test-suite/common.mk
+++ b/Examples/test-suite/common.mk
@@ -649,6 +649,7 @@ CPP17_TEST_BROKEN = \
# C++20 test cases.
CPP20_TEST_CASES += \
+ cpp20_lambda_template \
cpp20_spaceship_operator \
# Broken C++20 test cases.
diff --git a/Examples/test-suite/cpp20_lambda_template.i b/Examples/test-suite/cpp20_lambda_template.i
new file mode 100644
index 000000000..948364f42
--- /dev/null
+++ b/Examples/test-suite/cpp20_lambda_template.i
@@ -0,0 +1,12 @@
+%module cpp20_lambda_template
+
+// We just want to test that SWIG doesn't choke parsing this so suppress:
+// Warning 340: Lambda expressions and closures are not fully supported yet.
+%warnfilter(WARN_CPP11_LAMBDA);
+
+%include
+
+%inline %{
+#include
+auto templated_lambda = [](std::vector t){};
+%}
diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y
index be5159a62..816264de6 100644
--- a/Source/CParse/parser.y
+++ b/Source/CParse/parser.y
@@ -1713,7 +1713,7 @@ static String *add_qualifier_to_declarator(SwigType *type, SwigType *qualifier)
%type type_specifier primitive_type_list ;
%type fname stringtype;
%type featattr;
-%type lambda_introducer lambda_body;
+%type lambda_introducer lambda_body lambda_template;
%type lambda_tail;
%type virt_specifier_seq virt_specifier_seq_opt;
@@ -3420,17 +3420,17 @@ cpp_alternate_rettype : primitive_type { $$ = $1; }
auto myFunc = [](int x, int y) throw() -> int { return x+y; };
auto six = [](int x, int y) { return x+y; }(4, 2);
------------------------------------------------------------ */
-cpp_lambda_decl : storage_class AUTO idcolon EQUAL lambda_introducer LPAREN parms RPAREN cpp_const lambda_body lambda_tail {
+cpp_lambda_decl : storage_class AUTO idcolon EQUAL lambda_introducer lambda_template LPAREN parms RPAREN cpp_const lambda_body lambda_tail {
$$ = new_node("lambda");
Setattr($$,"name",$3);
add_symbols($$);
}
- | storage_class AUTO idcolon EQUAL lambda_introducer LPAREN parms RPAREN cpp_const ARROW type lambda_body lambda_tail {
+ | storage_class AUTO idcolon EQUAL lambda_introducer lambda_template LPAREN parms RPAREN cpp_const ARROW type lambda_body lambda_tail {
$$ = new_node("lambda");
Setattr($$,"name",$3);
add_symbols($$);
}
- | storage_class AUTO idcolon EQUAL lambda_introducer lambda_body lambda_tail {
+ | storage_class AUTO idcolon EQUAL lambda_introducer lambda_template lambda_body lambda_tail {
$$ = new_node("lambda");
Setattr($$,"name",$3);
add_symbols($$);
@@ -3443,6 +3443,13 @@ lambda_introducer : LBRACKET {
}
;
+lambda_template : LESSTHAN {
+ skip_balanced('<','>');
+ $$ = 0;
+ }
+ | empty { $$ = 0; }
+ ;
+
lambda_body : LBRACE {
skip_balanced('{','}');
$$ = 0;