diff --git a/CHANGES.current b/CHANGES.current index b68fa55d2..230ff333b 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.1.0 (in progress) =========================== +2022-02-01: olly + #231 Handle returning an object by reference in a C++ trailing + return type. + 2022-02-01: davidcl [Scilab] #745 use SWIG__Init() as a C module init function. diff --git a/Examples/test-suite/cpp11_alternate_function_syntax.i b/Examples/test-suite/cpp11_alternate_function_syntax.i index b3ecabc8c..2f5aaa41a 100644 --- a/Examples/test-suite/cpp11_alternate_function_syntax.i +++ b/Examples/test-suite/cpp11_alternate_function_syntax.i @@ -3,6 +3,8 @@ %module cpp11_alternate_function_syntax %inline %{ +struct Hello {}; + struct SomeStruct { int addNormal(int x, int y); auto addAlternate(int x, int y) -> int; @@ -12,6 +14,9 @@ struct SomeStruct { auto addAlternateMemberPtrParm(int x, int (SomeStruct::*mp)(int, int)) -> int; auto addAlternateMemberPtrConstParm(int x, int (SomeStruct::*mp)(int, int) const) const -> int; + // Returning a reference didn't parse in SWIG < 4.1.0 (#231) + auto output() -> Hello&; + virtual auto addFinal(int x, int y) const noexcept -> int final { return x + y; } virtual ~SomeStruct() = default; }; @@ -27,5 +32,6 @@ auto SomeStruct::addAlternateMemberPtrParm(int x, int (SomeStruct::*mp)(int, int auto SomeStruct::addAlternateMemberPtrConstParm(int x, int (SomeStruct::*mp)(int, int) const) const -> int { return 1000*x + (this->*mp)(x, x); } +auto SomeStruct::output() -> Hello& { static Hello h; return h; } %} diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index aafec5cbb..c9d24cef0 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -3383,6 +3383,10 @@ cpp_alternate_rettype : primitive_type { $$ = $1; } */ | TYPE_RAW { $$ = $1; } | idcolon { $$ = $1; } + | idcolon AND { + $$ = $1; + SwigType_add_reference($$); + } | decltype { $$ = $1; } ;