mirror of
https://github.com/RYDE-WORK/pybind11.git
synced 2026-02-03 05:53:21 +08:00
style: clang-tidy: default checks and fix bug in iostream deconstruction
```
/pybind11/include/pybind11/iostream.h:71:9: warning: Call to virtual method 'pythonbuf::sync' during destruction bypasses virtual dispatch [clang-analyzer-optin.cplusplus.VirtualCall]
sync();
^
/pybind11/tests/test_iostream.cpp:72:5: note: Calling '~scoped_ostream_redirect'
});
```
This commit is contained in:
parent
4d78640830
commit
e7bafc8ec1
@ -1,7 +1,6 @@
|
|||||||
FormatStyle: file
|
FormatStyle: file
|
||||||
|
|
||||||
Checks: '
|
Checks: '
|
||||||
-*,
|
|
||||||
llvm-namespace-comment,
|
llvm-namespace-comment,
|
||||||
modernize-use-override,
|
modernize-use-override,
|
||||||
readability-container-size-empty,
|
readability-container-size-empty,
|
||||||
|
|||||||
@ -38,7 +38,10 @@ private:
|
|||||||
return sync() == 0 ? traits_type::not_eof(c) : traits_type::eof();
|
return sync() == 0 ? traits_type::not_eof(c) : traits_type::eof();
|
||||||
}
|
}
|
||||||
|
|
||||||
int sync() override {
|
// This function must be non-virtual to be called in a destructor. If the
|
||||||
|
// rare MSVC test failure shows up with this version, then this should be
|
||||||
|
// simplified to a fully qualified call.
|
||||||
|
int _sync() {
|
||||||
if (pbase() != pptr()) {
|
if (pbase() != pptr()) {
|
||||||
// This subtraction cannot be negative, so dropping the sign
|
// This subtraction cannot be negative, so dropping the sign
|
||||||
str line(pbase(), static_cast<size_t>(pptr() - pbase()));
|
str line(pbase(), static_cast<size_t>(pptr() - pbase()));
|
||||||
@ -54,6 +57,10 @@ private:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sync() override {
|
||||||
|
return _sync();
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
pythonbuf(object pyostream, size_t buffer_size = 1024)
|
pythonbuf(object pyostream, size_t buffer_size = 1024)
|
||||||
@ -68,7 +75,7 @@ public:
|
|||||||
|
|
||||||
/// Sync before destroy
|
/// Sync before destroy
|
||||||
~pythonbuf() override {
|
~pythonbuf() override {
|
||||||
sync();
|
_sync();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user