[PATCH] D81525: [Support] Ensure errs() is constructed after outs() and don't rerun tie when errs() is called

Antonio Maiorano via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 11 12:41:23 PDT 2020


amaiorano added a comment.

I posted this on the GitHub PR, but was told the main discussion about this bug is here:
https://github.com/llvm/llvm-project/commit/1ce831912c797df1cb6d313d8e576a3f86175b6d#r39838454

Not sure a separate InitializeAndTie struct is needed when you can use an immediately-invoked lambda:

  raw_fd_ostream &llvm::errs() {
    // Set standard error to be unbuffered and tied to outs() by default.
    static auto S = [] { 
      raw_fd_ostream s(STDERR_FILENO, false, true);
      s.tie(&outs());
      return s;
    }();
    return S;
  }

I'm assuming 's' can be returned by value here, of course, otherwise we could make it static and return by reference from the lambda.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81525/new/

https://reviews.llvm.org/D81525





More information about the llvm-commits mailing list