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 @@ -295,7 +295,7 @@ /// This function determines if this stream is displayed and supports colors. /// The result is unaffected by calls to enable_color(). - virtual bool has_colors() const { return is_displayed(); } + virtual bool has_colors() { return is_displayed(); } // Enable or disable colors. Once enable_colors(false) is called, // changeColor() has no effect until enable_colors(true) is called. @@ -412,6 +412,7 @@ int FD; bool ShouldClose; bool SupportsSeeking = false; + Optional HasColors; #ifdef _WIN32 /// True if this fd refers to a Windows console device. Mintty and other @@ -479,7 +480,7 @@ bool is_displayed() const override; - bool has_colors() const override; + bool has_colors() override; std::error_code error() const { return EC; } 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 @@ -857,8 +857,10 @@ return sys::Process::FileDescriptorIsDisplayed(FD); } -bool raw_fd_ostream::has_colors() const { - return sys::Process::FileDescriptorHasColors(FD); +bool raw_fd_ostream::has_colors() { + if (!HasColors) + HasColors = sys::Process::FileDescriptorHasColors(FD); + return *HasColors; } Expected raw_fd_ostream::lock() {