Allow object reference in C++ trailing return type

Fixes #231
This commit is contained in:
Olly Betts 2022-02-02 11:31:45 +13:00
parent aee380ce82
commit 27a3d16ac6
3 changed files with 14 additions and 0 deletions

View File

@ -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_<module>_Init() as a C module init function.

View File

@ -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; }
%}

View File

@ -3383,6 +3383,10 @@ cpp_alternate_rettype : primitive_type { $$ = $1; }
*/
| TYPE_RAW { $$ = $1; }
| idcolon { $$ = $1; }
| idcolon AND {
$$ = $1;
SwigType_add_reference($$);
}
| decltype { $$ = $1; }
;