diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2019-07-09 08:06:18 +0100 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2019-07-09 08:06:18 +0100 |
commit | 75c5cb74581227c0261e3451dd67828af5b2c125 (patch) | |
tree | ad60367bbd336a00fb82de469d5e4e69fb342996 /Examples | |
parent | b55ce0cf847e363f9300be5372e705954c9e3a15 (diff) | |
download | swig-75c5cb74581227c0261e3451dd67828af5b2c125.tar.gz |
gcc-9 testcase warning fix
warning: ‘new’ of initializer_list does not extend the lifetime of the
underlying array [-Winit-list-lifetime]
Diffstat (limited to 'Examples')
-rw-r--r-- | Examples/test-suite/cpp11_initializer_list.i | 22 | ||||
-rw-r--r-- | Examples/test-suite/java/cpp11_initializer_list_runme.java | 21 |
2 files changed, 40 insertions, 3 deletions
diff --git a/Examples/test-suite/cpp11_initializer_list.i b/Examples/test-suite/cpp11_initializer_list.i index 58d2ecc50..b309576c1 100644 --- a/Examples/test-suite/cpp11_initializer_list.i +++ b/Examples/test-suite/cpp11_initializer_list.i @@ -6,12 +6,21 @@ %ignore A::A(std::initializer_list<int>); %ignore B::method; -%typemap(in) std::initializer_list<const char *> { +%typemap(in) std::initializer_list<const char *> %{ $1 = {"Ab", "Fab"}; -} +%} + +%begin %{ +#if __GNUC__ >= 9 +/* warning: ‘new’ of initializer_list does not extend the lifetime of the underlying array [-Winit-list-lifetime] */ +/* incorrect warning for C::C(std::initializer_list<const char *>) */ +#pragma GCC diagnostic ignored "-Winit-list-lifetime" +#endif +%} %inline %{ #include <initializer_list> +#include <string> class A { public: @@ -26,9 +35,16 @@ public: void method(std::initializer_list<int> init) {} }; class C { + std::string joined; public: - C(std::initializer_list<const char *>) {} + C(std::initializer_list<const char *> init) { + for (auto& val : init) + joined += val; + } C() {} + const char * get_joined_string() { + return joined.c_str(); + } }; %} diff --git a/Examples/test-suite/java/cpp11_initializer_list_runme.java b/Examples/test-suite/java/cpp11_initializer_list_runme.java new file mode 100644 index 000000000..0318c9e90 --- /dev/null +++ b/Examples/test-suite/java/cpp11_initializer_list_runme.java @@ -0,0 +1,21 @@ + +import cpp11_initializer_list.*; + +public class cpp11_initializer_list_runme { + + static { + try { + System.loadLibrary("cpp11_initializer_list"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) { + C c = new C(null); + String joined = c.get_joined_string(); + if (!joined.equals("AbFab")) + throw new RuntimeException("Wrong joined string " + joined); + } +} |