Skip to content

Commit

Permalink
style: clang-tidy: default checks and fix bug in iostream deconstruction
Browse files Browse the repository at this point in the history
```
/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'
    });
```
  • Loading branch information
henryiii committed Sep 15, 2020
1 parent 4d78640 commit e7bafc8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FormatStyle: file

Checks: '
-*,
llvm-namespace-comment,
modernize-use-override,
readability-container-size-empty,
Expand Down
11 changes: 9 additions & 2 deletions include/pybind11/iostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ class pythonbuf : public std::streambuf {
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()) {
// This subtraction cannot be negative, so dropping the sign
str line(pbase(), static_cast<size_t>(pptr() - pbase()));
Expand All @@ -54,6 +57,10 @@ class pythonbuf : public std::streambuf {
return 0;
}

int sync() override {
return _sync();
}

public:

pythonbuf(object pyostream, size_t buffer_size = 1024)
Expand All @@ -68,7 +75,7 @@ class pythonbuf : public std::streambuf {

/// Sync before destroy
~pythonbuf() override {
sync();
_sync();
}
};

Expand Down

0 comments on commit e7bafc8

Please sign in to comment.