mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-14 01:23:53 +00:00
Add -Wdeprecated to test suite and fix associated warnings (#1191)
This commit turns on `-Wdeprecated` in the test suite and fixes several associated deprecation warnings that show up as a result: - in C++17 `static constexpr` members are implicitly inline; our redeclaration (needed for C++11/14) is deprecated in C++17. - various test suite classes have destructors and rely on implicit copy constructors, but implicit copy constructor definitions when a user-declared destructor is present was deprecated in C++11. - Eigen also has various implicit copy constructors, so just disable `-Wdeprecated` in `eigen.h`.
This commit is contained in:
parent
15e0e44549
commit
ba33b2fc79
@ -25,9 +25,13 @@ template <typename T> struct format_descriptor<std::complex<T>, detail::enable_i
|
|||||||
static std::string format() { return std::string(value); }
|
static std::string format() { return std::string(value); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifndef PYBIND11_CPP17
|
||||||
|
|
||||||
template <typename T> constexpr const char format_descriptor<
|
template <typename T> constexpr const char format_descriptor<
|
||||||
std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>>::value[3];
|
std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>>::value[3];
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
NAMESPACE_BEGIN(detail)
|
NAMESPACE_BEGIN(detail)
|
||||||
|
|
||||||
template <typename T> struct is_fmt_numeric<std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>> {
|
template <typename T> struct is_fmt_numeric<std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>> {
|
||||||
|
@ -704,9 +704,13 @@ template <typename T> struct format_descriptor<T, detail::enable_if_t<std::is_ar
|
|||||||
static std::string format() { return std::string(1, c); }
|
static std::string format() { return std::string(1, c); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if !defined(PYBIND11_CPP17)
|
||||||
|
|
||||||
template <typename T> constexpr const char format_descriptor<
|
template <typename T> constexpr const char format_descriptor<
|
||||||
T, detail::enable_if_t<std::is_arithmetic<T>::value>>::value[2];
|
T, detail::enable_if_t<std::is_arithmetic<T>::value>>::value[2];
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/// RAII wrapper that temporarily clears any Python error state
|
/// RAII wrapper that temporarily clears any Python error state
|
||||||
struct error_scope {
|
struct error_scope {
|
||||||
PyObject *type, *value, *trace;
|
PyObject *type, *value, *trace;
|
||||||
|
@ -17,6 +17,11 @@
|
|||||||
# pragma GCC diagnostic push
|
# pragma GCC diagnostic push
|
||||||
# pragma GCC diagnostic ignored "-Wconversion"
|
# pragma GCC diagnostic ignored "-Wconversion"
|
||||||
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||||
|
# ifdef __clang__
|
||||||
|
// Eigen generates a bunch of implicit-copy-constructor-is-deprecated warnings with -Wdeprecated
|
||||||
|
// under Clang, so disable that warning here:
|
||||||
|
# pragma GCC diagnostic ignored "-Wdeprecated"
|
||||||
|
# endif
|
||||||
# if __GNUC__ >= 7
|
# if __GNUC__ >= 7
|
||||||
# pragma GCC diagnostic ignored "-Wint-in-bool-context"
|
# pragma GCC diagnostic ignored "-Wint-in-bool-context"
|
||||||
# endif
|
# endif
|
||||||
|
@ -295,6 +295,9 @@ public:
|
|||||||
PyErr_Fetch(&type.ptr(), &value.ptr(), &trace.ptr());
|
PyErr_Fetch(&type.ptr(), &value.ptr(), &trace.ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error_already_set(const error_already_set &) = default;
|
||||||
|
error_already_set(error_already_set &&) = default;
|
||||||
|
|
||||||
inline ~error_already_set();
|
inline ~error_already_set();
|
||||||
|
|
||||||
/// Give the currently-held error back to Python, if any. If there is currently a Python error
|
/// Give the currently-held error back to Python, if any. If there is currently a Python error
|
||||||
|
@ -124,7 +124,7 @@ function(pybind11_enable_warnings target_name)
|
|||||||
if(MSVC)
|
if(MSVC)
|
||||||
target_compile_options(${target_name} PRIVATE /W4)
|
target_compile_options(${target_name} PRIVATE /W4)
|
||||||
else()
|
else()
|
||||||
target_compile_options(${target_name} PRIVATE -Wall -Wextra -Wconversion -Wcast-qual)
|
target_compile_options(${target_name} PRIVATE -Wall -Wextra -Wconversion -Wcast-qual -Wdeprecated)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(PYBIND11_WERROR)
|
if(PYBIND11_WERROR)
|
||||||
|
@ -36,6 +36,8 @@ TEST_SUBMODULE(call_policies, m) {
|
|||||||
class Child {
|
class Child {
|
||||||
public:
|
public:
|
||||||
Child() { py::print("Allocating child."); }
|
Child() { py::print("Allocating child."); }
|
||||||
|
Child(const Child &) = default;
|
||||||
|
Child(Child &&) = default;
|
||||||
~Child() { py::print("Releasing child."); }
|
~Child() { py::print("Releasing child."); }
|
||||||
};
|
};
|
||||||
py::class_<Child>(m, "Child")
|
py::class_<Child>(m, "Child")
|
||||||
|
@ -14,6 +14,9 @@
|
|||||||
TEST_SUBMODULE(class_, m) {
|
TEST_SUBMODULE(class_, m) {
|
||||||
// test_instance
|
// test_instance
|
||||||
struct NoConstructor {
|
struct NoConstructor {
|
||||||
|
NoConstructor() = default;
|
||||||
|
NoConstructor(const NoConstructor &) = default;
|
||||||
|
NoConstructor(NoConstructor &&) = default;
|
||||||
static NoConstructor *new_instance() {
|
static NoConstructor *new_instance() {
|
||||||
auto *ptr = new NoConstructor();
|
auto *ptr = new NoConstructor();
|
||||||
print_created(ptr, "via new_instance");
|
print_created(ptr, "via new_instance");
|
||||||
@ -82,7 +85,12 @@ TEST_SUBMODULE(class_, m) {
|
|||||||
m.def("dog_bark", [](const Dog &dog) { return dog.bark(); });
|
m.def("dog_bark", [](const Dog &dog) { return dog.bark(); });
|
||||||
|
|
||||||
// test_automatic_upcasting
|
// test_automatic_upcasting
|
||||||
struct BaseClass { virtual ~BaseClass() {} };
|
struct BaseClass {
|
||||||
|
BaseClass() = default;
|
||||||
|
BaseClass(const BaseClass &) = default;
|
||||||
|
BaseClass(BaseClass &&) = default;
|
||||||
|
virtual ~BaseClass() {}
|
||||||
|
};
|
||||||
struct DerivedClass1 : BaseClass { };
|
struct DerivedClass1 : BaseClass { };
|
||||||
struct DerivedClass2 : BaseClass { };
|
struct DerivedClass2 : BaseClass { };
|
||||||
|
|
||||||
|
@ -49,7 +49,14 @@ namespace test_exc_sp {
|
|||||||
int f1(int x) noexcept { return x+1; }
|
int f1(int x) noexcept { return x+1; }
|
||||||
int f2(int x) noexcept(true) { return x+2; }
|
int f2(int x) noexcept(true) { return x+2; }
|
||||||
int f3(int x) noexcept(false) { return x+3; }
|
int f3(int x) noexcept(false) { return x+3; }
|
||||||
|
#if defined(__GNUG__)
|
||||||
|
# pragma GCC diagnostic push
|
||||||
|
# pragma GCC diagnostic ignored "-Wdeprecated"
|
||||||
|
#endif
|
||||||
int f4(int x) throw() { return x+4; } // Deprecated equivalent to noexcept(true)
|
int f4(int x) throw() { return x+4; } // Deprecated equivalent to noexcept(true)
|
||||||
|
#if defined(__GNUG__)
|
||||||
|
# pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
struct C {
|
struct C {
|
||||||
int m1(int x) noexcept { return x-1; }
|
int m1(int x) noexcept { return x-1; }
|
||||||
int m2(int x) const noexcept { return x-2; }
|
int m2(int x) const noexcept { return x-2; }
|
||||||
@ -57,8 +64,15 @@ struct C {
|
|||||||
int m4(int x) const noexcept(true) { return x-4; }
|
int m4(int x) const noexcept(true) { return x-4; }
|
||||||
int m5(int x) noexcept(false) { return x-5; }
|
int m5(int x) noexcept(false) { return x-5; }
|
||||||
int m6(int x) const noexcept(false) { return x-6; }
|
int m6(int x) const noexcept(false) { return x-6; }
|
||||||
|
#if defined(__GNUG__)
|
||||||
|
# pragma GCC diagnostic push
|
||||||
|
# pragma GCC diagnostic ignored "-Wdeprecated"
|
||||||
|
#endif
|
||||||
int m7(int x) throw() { return x-7; }
|
int m7(int x) throw() { return x-7; }
|
||||||
int m8(int x) const throw() { return x-8; }
|
int m8(int x) const throw() { return x-8; }
|
||||||
|
#if defined(__GNUG__)
|
||||||
|
# pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,6 +285,7 @@ TEST_SUBMODULE(factory_constructors, m) {
|
|||||||
// test_reallocations
|
// test_reallocations
|
||||||
// Class that has verbose operator_new/operator_delete calls
|
// Class that has verbose operator_new/operator_delete calls
|
||||||
struct NoisyAlloc {
|
struct NoisyAlloc {
|
||||||
|
NoisyAlloc(const NoisyAlloc &) = default;
|
||||||
NoisyAlloc(int i) { py::print(py::str("NoisyAlloc(int {})").format(i)); }
|
NoisyAlloc(int i) { py::print(py::str("NoisyAlloc(int {})").format(i)); }
|
||||||
NoisyAlloc(double d) { py::print(py::str("NoisyAlloc(double {})").format(d)); }
|
NoisyAlloc(double d) { py::print(py::str("NoisyAlloc(double {})").format(d)); }
|
||||||
~NoisyAlloc() { py::print("~NoisyAlloc()"); }
|
~NoisyAlloc() { py::print("~NoisyAlloc()"); }
|
||||||
|
@ -130,8 +130,8 @@ TEST_SUBMODULE(multiple_inheritance, m) {
|
|||||||
// test_mi_unaligned_base
|
// test_mi_unaligned_base
|
||||||
// test_mi_base_return
|
// test_mi_base_return
|
||||||
// Issue #801: invalid casting to derived type with MI bases
|
// Issue #801: invalid casting to derived type with MI bases
|
||||||
struct I801B1 { int a = 1; virtual ~I801B1() = default; };
|
struct I801B1 { int a = 1; I801B1() = default; I801B1(const I801B1 &) = default; virtual ~I801B1() = default; };
|
||||||
struct I801B2 { int b = 2; virtual ~I801B2() = default; };
|
struct I801B2 { int b = 2; I801B2() = default; I801B2(const I801B2 &) = default; virtual ~I801B2() = default; };
|
||||||
struct I801C : I801B1, I801B2 {};
|
struct I801C : I801B1, I801B2 {};
|
||||||
struct I801D : I801C {}; // Indirect MI
|
struct I801D : I801C {}; // Indirect MI
|
||||||
// Unregistered classes:
|
// Unregistered classes:
|
||||||
@ -205,7 +205,7 @@ TEST_SUBMODULE(multiple_inheritance, m) {
|
|||||||
// test_diamond_inheritance
|
// test_diamond_inheritance
|
||||||
// Issue #959: segfault when constructing diamond inheritance instance
|
// Issue #959: segfault when constructing diamond inheritance instance
|
||||||
// All of these have int members so that there will be various unequal pointers involved.
|
// All of these have int members so that there will be various unequal pointers involved.
|
||||||
struct B { int b; virtual ~B() = default; };
|
struct B { int b; B() = default; B(const B&) = default; virtual ~B() = default; };
|
||||||
struct C0 : public virtual B { int c0; };
|
struct C0 : public virtual B { int c0; };
|
||||||
struct C1 : public virtual B { int c1; };
|
struct C1 : public virtual B { int c1; };
|
||||||
struct D : public C0, public C1 { int d; };
|
struct D : public C0, public C1 { int d; };
|
||||||
|
@ -98,6 +98,7 @@ TEST_SUBMODULE(smart_ptr, m) {
|
|||||||
// Object managed by a std::shared_ptr<>
|
// Object managed by a std::shared_ptr<>
|
||||||
class MyObject2 {
|
class MyObject2 {
|
||||||
public:
|
public:
|
||||||
|
MyObject2(const MyObject2 &) = default;
|
||||||
MyObject2(int value) : value(value) { print_created(this, toString()); }
|
MyObject2(int value) : value(value) { print_created(this, toString()); }
|
||||||
std::string toString() const { return "MyObject2[" + std::to_string(value) + "]"; }
|
std::string toString() const { return "MyObject2[" + std::to_string(value) + "]"; }
|
||||||
virtual ~MyObject2() { print_destroyed(this); }
|
virtual ~MyObject2() { print_destroyed(this); }
|
||||||
@ -116,6 +117,7 @@ TEST_SUBMODULE(smart_ptr, m) {
|
|||||||
// Object managed by a std::shared_ptr<>, additionally derives from std::enable_shared_from_this<>
|
// Object managed by a std::shared_ptr<>, additionally derives from std::enable_shared_from_this<>
|
||||||
class MyObject3 : public std::enable_shared_from_this<MyObject3> {
|
class MyObject3 : public std::enable_shared_from_this<MyObject3> {
|
||||||
public:
|
public:
|
||||||
|
MyObject3(const MyObject3 &) = default;
|
||||||
MyObject3(int value) : value(value) { print_created(this, toString()); }
|
MyObject3(int value) : value(value) { print_created(this, toString()); }
|
||||||
std::string toString() const { return "MyObject3[" + std::to_string(value) + "]"; }
|
std::string toString() const { return "MyObject3[" + std::to_string(value) + "]"; }
|
||||||
virtual ~MyObject3() { print_destroyed(this); }
|
virtual ~MyObject3() { print_destroyed(this); }
|
||||||
@ -219,6 +221,8 @@ TEST_SUBMODULE(smart_ptr, m) {
|
|||||||
|
|
||||||
// Issue #865: shared_from_this doesn't work with virtual inheritance
|
// Issue #865: shared_from_this doesn't work with virtual inheritance
|
||||||
struct SharedFromThisVBase : std::enable_shared_from_this<SharedFromThisVBase> {
|
struct SharedFromThisVBase : std::enable_shared_from_this<SharedFromThisVBase> {
|
||||||
|
SharedFromThisVBase() = default;
|
||||||
|
SharedFromThisVBase(const SharedFromThisVBase &) = default;
|
||||||
virtual ~SharedFromThisVBase() = default;
|
virtual ~SharedFromThisVBase() = default;
|
||||||
};
|
};
|
||||||
struct SharedFromThisVirt : virtual SharedFromThisVBase {};
|
struct SharedFromThisVirt : virtual SharedFromThisVBase {};
|
||||||
|
Loading…
Reference in New Issue
Block a user