diff --git a/CHANGES.current b/CHANGES.current index 8e77d5bc0..1e4a24488 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -11,6 +11,29 @@ Version 4.0.0 (in progress) [Python] Patch #1083. Define_DEBUG to 1 to do exactly like Visual Studio /LDd, /MDd or /MTd compiler options. +2017-08-25: wsfulton + Issue #1059. Add support for C++11 ref-qualifiers on non-static member functions. + Members with lvalue ref-qualifiers such as: + + struct RQ { + void m1(int x) &; + void m2(int x) const &; + }; + + are wrapped like any other member function. Member functions with rvalue ref-qualifiers + are ignored by default, such as: + + struct RQ { + void m3(int x) &&; + void m4(int x) const &&; + }; + + example.i:7: Warning 405: Method with rvalue ref-qualifier m3(int) && ignored. + example.i:8: Warning 405: Method with rvalue ref-qualifier m4(int) const && ignored. + + These can be unignored and exposed to the target language, see further documentation in + CPlusPlus11.html. + 2017-08-16: wsfulton Fix #1063. Add using declarations to templates into typedef table. diff --git a/Doc/Manual/CPlusPlus11.html b/Doc/Manual/CPlusPlus11.html index e4dff6543..f9281bd56 100644 --- a/Doc/Manual/CPlusPlus11.html +++ b/Doc/Manual/CPlusPlus11.html @@ -42,6 +42,7 @@
+C++11 non-static member functions can be declared with ref-qualifiers. +Member functions declared with a & lvalue ref-qualifiers are wrapped like any other function without ref-qualifiers. +Member functions declared with a && rvalue ref-qualifiers are ignored by default +as they are unlikely to be required from non-C++ languages where the concept of rvalue-ness +for the implied *this pointer does not apply. +The warning is hidden by default, but can be displayed as described in the section on Enabling extra warnings. +
+ ++Consider: +
+ +
+struct RQ {
+ void m1(int x) &;
+ void m2(int x) &&;
+};
++The only wrapped method will be the lvalue ref-qualified method m1 +and if SWIG is run with the -Wextra command-line option, the following warning will be issued indicating m2 is not wrapped: +
+ ++example.i:7: Warning 405: Method with rvalue ref-qualifier m2(int) && ignored. ++
+If you unignore the method as follows, wrappers for m2 will be generated: +
+ +
+%feature("ignore", "0") RQ::m2(int x) &&;
+struct RQ {
+ void m1(int x) &;
+ void m2(int x) &&;
+};
++Inspection of the generated C++ code, will show that std::move is used on the instance +of the RQ * class: +
+ ++ RQ *arg1 = (RQ *) 0 ; + int arg2 ; + + arg1 = ...marshalled from target language... + arg2 = ...marshalled from target language... + + std::move(*arg1).m2(arg2); +
+This will compile but when run, the move effects may not be what you want. +As stated earlier, rvalue ref-qualifiers aren't really applicable outside the world of C++. +However, if you really know what you are doing, full control over the call to the method is +possible via the low-level "action" feature. +This feature completely replaces the call to the underlying function, that is, the last line in the snippet of code above. +
+ +
+%feature("ignore", "0") RQ::m2(int x) &&;
+%feature("action") RQ::m2(int x) && %{
+ RQ().m2(arg2);
+%}
+struct RQ {
+ void m1(int x) &;
+ void m2(int x) &&;
+};
++resulting in: +
+ ++ RQ *arg1 = (RQ *) 0 ; + int arg2 ; + + arg1 = ...marshalled from target language... + arg2 = ...marshalled from target language... + + RQ().m2(arg2); +
+Compatibility note: SWIG-4.0.0 was the first version to support ref-qualifiers. +