Skip to content

Commit 27a3d16

Browse files
committed
Allow object reference in C++ trailing return type
Fixes swig#231
1 parent aee380c commit 27a3d16

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

CHANGES.current

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
77
Version 4.1.0 (in progress)
88
===========================
99

10+
2022-02-01: olly
11+
#231 Handle returning an object by reference in a C++ trailing
12+
return type.
13+
1014
2022-02-01: davidcl
1115
[Scilab] #745 use SWIG_<module>_Init() as a C module init function.
1216

Examples/test-suite/cpp11_alternate_function_syntax.i

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
%module cpp11_alternate_function_syntax
44

55
%inline %{
6+
struct Hello {};
7+
68
struct SomeStruct {
79
int addNormal(int x, int y);
810
auto addAlternate(int x, int y) -> int;
@@ -12,6 +14,9 @@ struct SomeStruct {
1214
auto addAlternateMemberPtrParm(int x, int (SomeStruct::*mp)(int, int)) -> int;
1315
auto addAlternateMemberPtrConstParm(int x, int (SomeStruct::*mp)(int, int) const) const -> int;
1416

17+
// Returning a reference didn't parse in SWIG < 4.1.0 (#231)
18+
auto output() -> Hello&;
19+
1520
virtual auto addFinal(int x, int y) const noexcept -> int final { return x + y; }
1621
virtual ~SomeStruct() = default;
1722
};
@@ -27,5 +32,6 @@ auto SomeStruct::addAlternateMemberPtrParm(int x, int (SomeStruct::*mp)(int, int
2732
auto SomeStruct::addAlternateMemberPtrConstParm(int x, int (SomeStruct::*mp)(int, int) const) const -> int {
2833
return 1000*x + (this->*mp)(x, x);
2934
}
35+
auto SomeStruct::output() -> Hello& { static Hello h; return h; }
3036

3137
%}

Source/CParse/parser.y

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3383,6 +3383,10 @@ cpp_alternate_rettype : primitive_type { $$ = $1; }
33833383
*/
33843384
| TYPE_RAW { $$ = $1; }
33853385
| idcolon { $$ = $1; }
3386+
| idcolon AND {
3387+
$$ = $1;
3388+
SwigType_add_reference($$);
3389+
}
33863390
| decltype { $$ = $1; }
33873391
;
33883392

0 commit comments

Comments
 (0)