gcc-9 testcase warning fix
warning: ‘new’ of initializer_list does not extend the lifetime of the underlying array [-Winit-list-lifetime]
This commit is contained in:
parent
b55ce0cf84
commit
75c5cb7458
2 changed files with 40 additions and 3 deletions
|
|
@ -6,12 +6,21 @@
|
||||||
%ignore A::A(std::initializer_list<int>);
|
%ignore A::A(std::initializer_list<int>);
|
||||||
%ignore B::method;
|
%ignore B::method;
|
||||||
|
|
||||||
%typemap(in) std::initializer_list<const char *> {
|
%typemap(in) std::initializer_list<const char *> %{
|
||||||
$1 = {"Ab", "Fab"};
|
$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 %{
|
%inline %{
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
public:
|
public:
|
||||||
|
|
@ -26,9 +35,16 @@ public:
|
||||||
void method(std::initializer_list<int> init) {}
|
void method(std::initializer_list<int> init) {}
|
||||||
};
|
};
|
||||||
class C {
|
class C {
|
||||||
|
std::string joined;
|
||||||
public:
|
public:
|
||||||
C(std::initializer_list<const char *>) {}
|
C(std::initializer_list<const char *> init) {
|
||||||
|
for (auto& val : init)
|
||||||
|
joined += val;
|
||||||
|
}
|
||||||
C() {}
|
C() {}
|
||||||
|
const char * get_joined_string() {
|
||||||
|
return joined.c_str();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
|
||||||
21
Examples/test-suite/java/cpp11_initializer_list_runme.java
Normal file
21
Examples/test-suite/java/cpp11_initializer_list_runme.java
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue