diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2013-01-24 08:02:34 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2013-01-24 08:02:34 +0000 |
commit | 07c35d61e30d371a65b134ca62c44701230cfbd0 (patch) | |
tree | ed4da60a440e5f7e7c1e160269d7548784fc2771 | |
parent | d357bec829d08ee96afe8ca8bf6d8631f6b983c9 (diff) | |
download | swig-07c35d61e30d371a65b134ca62c44701230cfbd0.tar.gz |
Fix generated code for rvalue references by converting functions returning an rvalue reference into something that can be taken the address of - via a const ref cast. Now the rvalue_reference tests compile under g++-4.7 (C# only atm)
-rw-r--r-- | Examples/test-suite/common.mk | 1 | ||||
-rw-r--r-- | Examples/test-suite/cpp0x_rvalue_reference3.i | 65 | ||||
-rw-r--r-- | Source/Swig/cwrap.c | 11 |
3 files changed, 76 insertions, 1 deletions
diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index c19755018..1b50ed895 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -443,6 +443,7 @@ CPP0X_TEST_CASES = \ cpp0x_raw_string_literals \ cpp0x_rvalue_reference \ cpp0x_rvalue_reference2 \ + cpp0x_rvalue_reference3 \ cpp0x_sizeof_object \ cpp0x_static_assert \ cpp0x_strongly_typed_enumerations \ diff --git a/Examples/test-suite/cpp0x_rvalue_reference3.i b/Examples/test-suite/cpp0x_rvalue_reference3.i new file mode 100644 index 000000000..c6fe60068 --- /dev/null +++ b/Examples/test-suite/cpp0x_rvalue_reference3.i @@ -0,0 +1,65 @@ +%module cpp0x_rvalue_reference3 + +%inline %{ +#include <utility> +struct Thing {}; + +Thing && global_rvalue_ref = Thing(); +Thing *&& global_rvalue_ref_ptr1 = 0; +Thing const*&& global_rvalue_ref_ptr2 = 0; +Thing *const&& global_rvalue_ref_ptr3 = 0; +Thing const*const &&global_rvalue_ref_ptr4 = 0; + +Thing && returnit1() { return std::move(global_rvalue_ref); } +Thing *&& returnit2() { return std::move(global_rvalue_ref_ptr1); } +Thing const*&& returnit3() { return std::move(global_rvalue_ref_ptr2); } +Thing *const&& returnit4() { return std::move(global_rvalue_ref_ptr3); } +Thing const*const&& returnit5() { return std::move(global_rvalue_ref_ptr4); } + +void takeit1(Thing && t) {} +void takeit2(Thing *&& t) {} +void takeit3(Thing const*&& t) {} +void takeit4(Thing *const&& t) {} +void takeit5(Thing const*const&& t) {} + +struct Containing { + Thing && member_rvalue_ref; + Thing *&& member_rvalue_ref_ptr1 = 0; + Thing const*&& member_rvalue_ref_ptr2 = 0; + Thing *const&& member_rvalue_ref_ptr3 = 0; + Thing const*const &&member_rvalue_ref_ptr4 = 0; + + Containing() : member_rvalue_ref(Thing()) {} +}; +%} + + +%inline %{ +int && int_global_rvalue_ref = 5; +int *&& int_global_rvalue_ref_ptr1 = 0; +int const*&& int_global_rvalue_ref_ptr2 = 0; +int *const&& int_global_rvalue_ref_ptr3 = 0; +int const*const &&int_global_rvalue_ref_ptr4 = 0; + +int && int_returnit1() { return std::move(int_global_rvalue_ref); } +int *&& int_returnit2() { return std::move(int_global_rvalue_ref_ptr1); } +int const*&& int_returnit3() { return std::move(int_global_rvalue_ref_ptr2); } +int *const&& int_returnit4() { return std::move(int_global_rvalue_ref_ptr3); } +int const*const&& int_returnit5() { return std::move(int_global_rvalue_ref_ptr4); } + +void int_takeit1(int && t) {} +void int_takeit2(int *&& t) {} +void int_takeit3(int const*&& t) {} +void int_takeit4(int *const&& t) {} +void int_takeit5(int const*const&& t) {} + +struct IntContaining { + int && member_rvalue_ref; + int *&& member_rvalue_ref_ptr1 = 0; + int const*&& member_rvalue_ref_ptr2 = 0; + int *const&& member_rvalue_ref_ptr3 = 0; + int const*const &&member_rvalue_ref_ptr4 = 0; + + IntContaining() : member_rvalue_ref(55) {} +}; +%} diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index d335bb0e9..1ec790167 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -317,7 +317,16 @@ String *Swig_cresult(SwigType *t, const_String_or_char_ptr name, const_String_or case T_RVALUE_REFERENCE: { String *lstr = SwigType_lstr(t, 0); - Printf(fcall, "%s = (%s) &", name, lstr); + SwigType *tt = Copy(t); + SwigType_del_rvalue_reference(tt); + SwigType_add_qualifier(tt, "const"); + SwigType_add_reference(tt); + String *const_lvalue_str = SwigType_rcaststr(tt, 0); + + Printf(fcall, "%s = (%s) &%s", name, lstr, const_lvalue_str); + + Delete(const_lvalue_str); + Delete(tt); Delete(lstr); } break; |