fmt::ostream - aggregate buffer instead of inheriting it (#3139)

Some MSVC-specific behavior:
When class fmt::ostream inherits detail::buffer - the last gets implicitly exported when fmt is built as a shared library.
Unless os.h is included, the compiler assumes detail::buffer is not externally exported and instantiates a local copy of it, which causes ODR violation.
With aggregation - there is no extra exporting of detail::buffer symbols.
This commit is contained in:
Ihor Dutchak
2022-10-23 17:21:36 +03:00
committed by GitHub
parent 64965bdc96
commit 80f8d34427
2 changed files with 57 additions and 28 deletions

View File

@@ -366,8 +366,32 @@ long getpagesize() {
# endif
}
FMT_API void ostream::grow(size_t) {
FMT_BEGIN_DETAIL_NAMESPACE
void file_buffer::grow(size_t) {
if (this->size() == this->capacity()) flush();
}
file_buffer::file_buffer(cstring_view path,
const detail::ostream_params& params)
: file_(path, params.oflag) {
set(new char[params.buffer_size], params.buffer_size);
}
file_buffer::file_buffer(file_buffer&& other)
: detail::buffer<char>(other.data(), other.size(), other.capacity()),
file_(std::move(other.file_)) {
other.clear();
other.set(nullptr, 0);
}
file_buffer::~file_buffer() {
flush();
delete[] data();
}
FMT_END_DETAIL_NAMESPACE
ostream::~ostream() = default;
#endif // FMT_USE_FCNTL
FMT_END_NAMESPACE