[clang-tools-extra] r336890 - [clangd] Simplify logging wrapper after r336888

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 12 01:00:22 PDT 2018


Author: sammccall
Date: Thu Jul 12 01:00:21 2018
New Revision: 336890

URL: http://llvm.org/viewvc/llvm-project?rev=336890&view=rev
Log:
[clangd] Simplify logging wrapper after r336888

Modified:
    clang-tools-extra/trunk/clangd/Logger.h

Modified: clang-tools-extra/trunk/clangd/Logger.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Logger.h?rev=336890&r1=336889&r2=336890&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/Logger.h (original)
+++ clang-tools-extra/trunk/clangd/Logger.h Thu Jul 12 01:00:21 2018
@@ -13,6 +13,7 @@
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/FormatAdapters.h"
 #include "llvm/Support/FormatVariadic.h"
 
 namespace clang {
@@ -35,21 +36,11 @@ const char *debugType(const char *Filena
 void log(Logger::Level, const llvm::formatv_object_base &);
 
 // We often want to consume llvm::Errors by value when passing them to log().
-// This is tricky because the logging infrastructure must mark them as handled.
-// When forwarding argument to formatv, we wrap Errors-by-value in this type
-// whose destructor handles the cleanup.
-// FIXME: simplify after D49170 lands.
-struct WrappedError {
-  llvm::Error E;
-  WrappedError(WrappedError &&) = default;
-  ~WrappedError() { consumeError(std::move(E)); }
-};
-inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
-                                     const WrappedError &Err) {
-  return OS << Err.E;
-}
+// We automatically wrap them in llvm::fmt_consume() as formatv requires.
 template <typename T> T &&wrap(T &&V) { return std::forward<T>(V); }
-inline WrappedError wrap(llvm::Error &&V) { return WrappedError{std::move(V)}; }
+inline decltype(fmt_consume(llvm::Error::success())) wrap(llvm::Error &&V) {
+  return fmt_consume(std::move(V));
+}
 template <typename... Ts>
 void log(Logger::Level L, const char *Fmt, Ts &&... Vals) {
   detail::log(L, llvm::formatv(Fmt, detail::wrap(std::forward<Ts>(Vals))...));




More information about the cfe-commits mailing list