diff options
Diffstat (limited to 'src/support')
-rw-r--r-- | src/support/file.cpp | 11 | ||||
-rw-r--r-- | src/support/file.h | 2 |
2 files changed, 6 insertions, 7 deletions
diff --git a/src/support/file.cpp b/src/support/file.cpp index 2a8426461..d17e3a338 100644 --- a/src/support/file.cpp +++ b/src/support/file.cpp @@ -88,11 +88,12 @@ template std::vector<char> wasm::read_file<>(const std::string&, wasm::Output::Output(const std::string& filename, Flags::BinaryOption binary) : outfile(), out([this, filename, binary]() { - if (filename == "-") { - return std::cout.rdbuf(); - } + // Ensure a single return at the very end, to avoid clang-tidy warnings + // about the types of different returns here. std::streambuf* buffer; - if (filename.size()) { + if (filename == "-" || filename.empty()) { + buffer = std::cout.rdbuf(); + } else { BYN_TRACE("Opening '" << filename << "'\n"); auto flags = std::ofstream::out | std::ofstream::trunc; if (binary == Flags::Binary) { @@ -104,8 +105,6 @@ wasm::Output::Output(const std::string& filename, Flags::BinaryOption binary) exit(EXIT_FAILURE); } buffer = outfile.rdbuf(); - } else { - buffer = std::cout.rdbuf(); } return buffer; }()) {} diff --git a/src/support/file.h b/src/support/file.h index 3dc766b2d..ae91831c9 100644 --- a/src/support/file.h +++ b/src/support/file.h @@ -50,7 +50,7 @@ std::string read_possible_response_file(const std::string&); class Output { public: - // An empty filename will open stdout instead. + // An empty filename or "-" will open stdout instead. Output(const std::string& filename, Flags::BinaryOption binary); ~Output() = default; template<typename T> std::ostream& operator<<(const T& v) { return out << v; } |