style: clang-tidy: modernize-use-override
diff --git a/.clang-tidy b/.clang-tidy
index 798e676..93e4a7c 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -3,6 +3,7 @@
Checks: '
-*,
llvm-namespace-comment,
+modernize-use-override,
'
HeaderFilterRegex: 'pybind11/.*h'
diff --git a/include/pybind11/iostream.h b/include/pybind11/iostream.h
index eaf92df..4b4042b 100644
--- a/include/pybind11/iostream.h
+++ b/include/pybind11/iostream.h
@@ -30,7 +30,7 @@
object pywrite;
object pyflush;
- int overflow(int c) {
+ int overflow(int c) override {
if (!traits_type::eq_int_type(c, traits_type::eof())) {
*pptr() = traits_type::to_char_type(c);
pbump(1);
@@ -38,7 +38,7 @@
return sync() == 0 ? traits_type::not_eof(c) : traits_type::eof();
}
- int sync() {
+ int sync() override {
if (pbase() != pptr()) {
// This subtraction cannot be negative, so dropping the sign
str line(pbase(), static_cast<size_t>(pptr() - pbase()));
@@ -67,7 +67,7 @@
pythonbuf(pythonbuf&&) = default;
/// Sync before destroy
- ~pythonbuf() {
+ ~pythonbuf() override {
sync();
}
};
diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h
index 8e05261..3164764 100644
--- a/include/pybind11/pytypes.h
+++ b/include/pybind11/pytypes.h
@@ -331,7 +331,7 @@
error_already_set(const error_already_set &) = default;
error_already_set(error_already_set &&) = default;
- inline ~error_already_set();
+ inline ~error_already_set() override;
/// Give the currently-held error back to Python, if any. If there is currently a Python error
/// already set it is cleared first. After this call, the current object no longer stores the
diff --git a/tests/test_exceptions.cpp b/tests/test_exceptions.cpp
index 537819d..6187f2e 100644
--- a/tests/test_exceptions.cpp
+++ b/tests/test_exceptions.cpp
@@ -13,7 +13,7 @@
class MyException : public std::exception {
public:
explicit MyException(const char * m) : message{m} {}
- virtual const char * what() const noexcept override {return message.c_str();}
+ const char * what() const noexcept override {return message.c_str();}
private:
std::string message = "";
};
@@ -22,7 +22,7 @@
class MyException2 : public std::exception {
public:
explicit MyException2(const char * m) : message{m} {}
- virtual const char * what() const noexcept override {return message.c_str();}
+ const char * what() const noexcept override {return message.c_str();}
private:
std::string message = "";
};
@@ -41,7 +41,7 @@
class MyException4 : public std::exception {
public:
explicit MyException4(const char * m) : message{m} {}
- virtual const char * what() const noexcept override {return message.c_str();}
+ const char * what() const noexcept override {return message.c_str();}
private:
std::string message = "";
};
diff --git a/tests/test_factory_constructors.cpp b/tests/test_factory_constructors.cpp
index f70ed33..dcfabac 100644
--- a/tests/test_factory_constructors.cpp
+++ b/tests/test_factory_constructors.cpp
@@ -58,13 +58,13 @@
public:
TestFactory4() : TestFactory3() { print_default_created(this); }
TestFactory4(int v) : TestFactory3(v) { print_created(this, v); }
- virtual ~TestFactory4() { print_destroyed(this); }
+ ~TestFactory4() override { print_destroyed(this); }
};
// Another class for an invalid downcast test
class TestFactory5 : public TestFactory3 {
public:
TestFactory5(int i) : TestFactory3(i) { print_created(this, i); }
- virtual ~TestFactory5() { print_destroyed(this); }
+ ~TestFactory5() override { print_destroyed(this); }
};
class TestFactory6 {
@@ -88,8 +88,8 @@
PyTF6(PyTF6 &&f) : TestFactory6(std::move(f)) { print_move_created(this); }
PyTF6(const PyTF6 &f) : TestFactory6(f) { print_copy_created(this); }
PyTF6(std::string s) : TestFactory6((int) s.size()) { alias = true; print_created(this, s); }
- virtual ~PyTF6() { print_destroyed(this); }
- int get() override { PYBIND11_OVERRIDE(int, TestFactory6, get, /*no args*/); }
+ ~PyTF6() override { print_destroyed(this); }
+ int get() override { PYBIND11_OVERLOAD(int, TestFactory6, get, /*no args*/); }
};
class TestFactory7 {
@@ -109,8 +109,7 @@
PyTF7(int i) : TestFactory7(i) { alias = true; print_created(this, i); }
PyTF7(PyTF7 &&f) : TestFactory7(std::move(f)) { print_move_created(this); }
PyTF7(const PyTF7 &f) : TestFactory7(f) { print_copy_created(this); }
- virtual ~PyTF7() { print_destroyed(this); }
- int get() override { PYBIND11_OVERRIDE(int, TestFactory7, get, /*no args*/); }
+ ~PyTF7() override { print_destroyed(this); }
};
diff --git a/tests/test_smart_ptr.cpp b/tests/test_smart_ptr.cpp
index af7b86e..512175e 100644
--- a/tests/test_smart_ptr.cpp
+++ b/tests/test_smart_ptr.cpp
@@ -98,9 +98,9 @@
class MyObject1 : public Object {
public:
MyObject1(int value) : value(value) { print_created(this, toString()); }
- std::string toString() const { return "MyObject1[" + std::to_string(value) + "]"; }
+ std::string toString() const override { return "MyObject1[" + std::to_string(value) + "]"; }
protected:
- virtual ~MyObject1() { print_destroyed(this); }
+ ~MyObject1() override { print_destroyed(this); }
private:
int value;
};
@@ -208,7 +208,7 @@
class MyObject4b : public MyObject4a {
public:
MyObject4b(int i) : MyObject4a(i) { print_created(this); }
- ~MyObject4b() { print_destroyed(this); }
+ ~MyObject4b() override { print_destroyed(this); }
};
py::class_<MyObject4b, MyObject4a>(m, "MyObject4b")
.def(py::init<int>());
diff --git a/tests/test_virtual_functions.cpp b/tests/test_virtual_functions.cpp
index 0210695..7a41756 100644
--- a/tests/test_virtual_functions.cpp
+++ b/tests/test_virtual_functions.cpp
@@ -158,8 +158,8 @@
};
struct DispatchIssue : Base {
- virtual std::string dispatch() const {
- PYBIND11_OVERRIDE_PURE(std::string, Base, dispatch, /* no arguments */);
+ std::string dispatch() const override {
+ PYBIND11_OVERLOAD_PURE(std::string, Base, dispatch, /* no arguments */);
}
};
@@ -234,7 +234,7 @@
struct PyA : A {
PyA() { py::print("PyA.PyA()"); }
PyA(const PyA&) = delete;
- ~PyA() { py::print("PyA.~PyA()"); }
+ ~PyA() override { py::print("PyA.~PyA()"); }
void f() override {
py::print("PyA.f()");
@@ -262,7 +262,7 @@
struct PyA2 : A2 {
PyA2() { py::print("PyA2.PyA2()"); }
PyA2(const PyA2&) = delete;
- ~PyA2() { py::print("PyA2.~PyA2()"); }
+ ~PyA2() override { py::print("PyA2.~PyA2()"); }
void f() override {
py::print("PyA2.f()");
PYBIND11_OVERRIDE(void, A2, f);