Skip to content

Commit 7d852c4

Browse files
committed
Director virtual methods and std::move
Add missing std::move calls in director methods
1 parent c45658f commit 7d852c4

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

CHANGES.current

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ Version 4.5.0 (in progress)
99

1010
2025-10-27: wsfulton
1111
#3276 Add missing std::move when wrapping move constructors for directors.
12+
Also add missing std::move for wrapped director (virtual) methods with
13+
rvalue references.

Examples/test-suite/cpp11_directors.i

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ struct MoveOnlyNode {
2424
MoveOnlyNode(int a, double d) {}
2525
MoveOnlyNode() = default;
2626
virtual ~MoveOnlyNode() = default;
27+
virtual void rvalues_int(int &&) {}
28+
virtual void rvalues_mo(MoveOnlyNode &&) {}
29+
virtual void rvalues_mo_overload(MoveOnlyNode &&) {}
30+
virtual void rvalues_mo_overload(int, double, MoveOnlyNode &&) {}
31+
32+
using DoubleRVR = double&&;
33+
using MoveOnlyNodeRVR = MoveOnlyNode&&;
34+
virtual void rvalues_using(DoubleRVR, MoveOnlyNodeRVR p2) {}
2735
};
2836
}
2937
%}

Source/Modules/directors.cxx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,27 +101,29 @@ String *Swig_director_declaration(Node *n) {
101101
* ----------------------------------------------------------------------------- */
102102

103103
String *Swig_method_call(const_String_or_char_ptr name, ParmList *parms) {
104-
String *func;
104+
String *func = NewString("");
105105
int comma = 0;
106106
Parm *p = parms;
107-
SwigType *pt;
108-
String *nname;
109-
110-
func = NewString("");
111-
nname = SwigType_namestr(name);
107+
String *nname = SwigType_namestr(name);
112108
Printf(func, "%s(", nname);
109+
113110
while (p) {
114-
String *pname;
115-
pt = Getattr(p, "type");
111+
SwigType *pt = Getattr(p, "type");
116112
if ((SwigType_type(pt) != T_VOID)) {
113+
SwigType *rpt = SwigType_typedef_resolve_all(pt);
114+
String *pname = Getattr(p, "name");
117115
if (comma)
118-
Printf(func, ",");
119-
pname = Getattr(p, "name");
120-
Printf(func, "%s", pname);
116+
Append(func, ",");
117+
if (SwigType_isrvalue_reference(rpt))
118+
Printv(func, "std::move(", pname, ")", NIL);
119+
else
120+
Printv(func, pname, NIL);
121+
Delete(rpt);
121122
comma = 1;
122123
}
123124
p = nextSibling(p);
124125
}
126+
125127
Printf(func, ")");
126128
return func;
127129
}

Source/Swig/cwrap.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,16 +397,12 @@ String *Swig_cfunction_call(const_String_or_char_ptr name, ParmList *parms) {
397397
SwigType *rpt = SwigType_typedef_resolve_all(pt);
398398
String *pname = Swig_cparm_name(p, i);
399399
String *rcaststr = SwigType_rcaststr(rpt, pname);
400-
401-
if (comma) {
400+
if (comma)
402401
Append(func, ",");
403-
}
404-
405402
if (cparse_cplusplus && SwigType_type(rpt) == T_USER)
406403
Printv(func, "SWIG_STD_MOVE(", rcaststr, ")", NIL);
407404
else
408405
Printv(func, rcaststr, NIL);
409-
410406
Delete(rpt);
411407
Delete(pname);
412408
Delete(rcaststr);

0 commit comments

Comments
 (0)