Merge branch 'cpp20-template-lambdas'

Fixes #1678
This commit is contained in:
Olly Betts 2022-07-27 09:36:42 +12:00
commit 24ec116742
5 changed files with 35 additions and 4 deletions

View file

@ -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 (<=>).

View file

@ -50,6 +50,14 @@ or attempts to automatically map it to a three-way comparison operator
in any target languages that have one.
</p>
<H3><a name="CPlusPlus20_lambda_templates">10.2.2 Lambda templates</a></H3>
<p>
SWIG should parse lambda templates, but
<a href="CPlusPlus11.html#CPlusPlus11_lambda_functions_and_expressions">like
non-templated lambdas they aren't currently wrapped</a>.
</p>
<H2><a name="CPlusPlus20_standard_library_changes">10.3 Standard library changes</a></H2>

View file

@ -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.

View file

@ -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 <std_vector.i>
%inline %{
#include <vector>
auto templated_lambda = []<typename T>(std::vector<T> t){};
%}

View file

@ -1713,7 +1713,7 @@ static String *add_qualifier_to_declarator(SwigType *type, SwigType *qualifier)
%type <ptype> type_specifier primitive_type_list ;
%type <node> fname stringtype;
%type <node> featattr;
%type <node> lambda_introducer lambda_body;
%type <node> lambda_introducer lambda_body lambda_template;
%type <pl> lambda_tail;
%type <str> 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;