From e68d8024f5d02532f3519a9651d5eec3db653c59 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 1 Oct 2012 18:53:12 +0000 Subject: [PATCH] Lambda expressions: parse exception specification in lambda functions. Fix lambda testcase for gcc-4.7. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13854 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/cpp0x_lambda_functions.i | 29 ++++++++++++++++++++ Source/CParse/parser.y | 5 ++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/cpp0x_lambda_functions.i b/Examples/test-suite/cpp0x_lambda_functions.i index 56235e9a6..0f10af471 100644 --- a/Examples/test-suite/cpp0x_lambda_functions.i +++ b/Examples/test-suite/cpp0x_lambda_functions.i @@ -19,7 +19,23 @@ auto lambda2 = [](int x, int y) { return x+y; }; auto lambda3 = [&](int x, int y) { return x+y; }; auto lambda4 = [=](int x, int y) { return x+y; }; int thing = 0; +#ifdef SWIG +// Not strictly correct as captured variables should have non-automatic storage duration, ie shouldn't capture globals. gcc-4.7 warns about this, but we check that SWIG can parse this anyway. auto lambda5 = [=,&thing]() { return thing;}; +#else +auto lambda5 = [=]() { return thing;}; +#endif + +void fn() { + int stuff = 0; + auto lambdaxxxx = [=,&stuff]() { return thing;}; +} +auto lambda6 = [] (int a, int b) mutable { return a + b; }; +auto lambda7 = [] (int x, int y) -> int { return x+y; }; +auto lambda8 = [] (int x, int y) throw() -> int { return x+y; }; +auto lambda9 = [] (int x, int y) mutable throw() -> int { return x+y; }; +auto lambda10 = [] (int x, int y) throw(int) { return x+y; }; +auto lambda11 = [] (int x, int y) mutable throw(int) { return x+y; }; int runLambda1() { return lambda1(5,6); @@ -49,3 +65,16 @@ int runLambdaInline() { } %} +%{ +// TODO +struct LambdaStruct { + static constexpr auto lambda_struct1 = [=]() { return thing;}; +}; +auto lambda100 = [] { return thing;}; +int lambda101 = [] (int a, int b) { return a + b; }(1, 2); +int lambda102 = [] (int a, int b) mutable { return a + b; }(1, 2); +auto lambda103 = [] () throw () { /* does not throw */ }; +auto lambda104 = [] () mutable throw () { /* does not throw */ }; +void lambda_init(int = ([=]{ return 0; })()); +%} + diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index f601aab9f..04b69fbc6 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -3295,8 +3295,9 @@ cpp_alternate_rettype : primitive_type { $$ = $1; } OR auto myFunc = [](int x, int y) { return x+y; } */ -c_lambda_decl : c_lambda_decl_front LPAREN parms RPAREN LBRACE { skip_balanced('{','}'); } SEMI { $$ = 0; } - | c_lambda_decl_front LPAREN parms RPAREN ARROW type LBRACE { skip_balanced('{','}'); } SEMI { $$ = 0; } +c_lambda_decl : c_lambda_decl_front LPAREN parms RPAREN cpp_const LBRACE { skip_balanced('{','}'); } SEMI { $$ = 0; } + | c_lambda_decl_front LPAREN parms RPAREN cpp_const ARROW type LBRACE { skip_balanced('{','}'); } SEMI { $$ = 0; } + ; c_lambda_decl_front : storage_class AUTO idcolon EQUAL LBRACKET { skip_balanced('[',']'); $$ = 0; }