diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h --- a/llvm/include/llvm/Support/raw_ostream.h +++ b/llvm/include/llvm/Support/raw_ostream.h @@ -622,6 +622,9 @@ /// A raw_ostream that writes to an std::string. This is a simple adaptor /// class. This class does not encounter output errors. +/// raw_string_ostream operates without a buffer, delegating all memory +/// management to the std::string. Thus the std::string is always up-to-date, +/// may be used directly and there is no need to call flush(). class raw_string_ostream : public raw_ostream { std::string &OS; @@ -636,14 +639,10 @@ explicit raw_string_ostream(std::string &O) : OS(O) { SetUnbuffered(); } - ~raw_string_ostream() override; + ~raw_string_ostream() override = default; - /// Flushes the stream contents to the target string and returns the string's - /// reference. - std::string& str() { - flush(); - return OS; - } + /// Returns the string's reference. + std::string& str() { return OS; } void reserveExtraSpace(uint64_t ExtraSize) override { OS.reserve(tell() + ExtraSize); diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp @@ -937,10 +937,6 @@ // raw_string_ostream //===----------------------------------------------------------------------===// -raw_string_ostream::~raw_string_ostream() { - flush(); -} - void raw_string_ostream::write_impl(const char *Ptr, size_t Size) { OS.append(Ptr, Size); }