Skip to content

Commit b34565e

Browse files
committed
[clangd] Simplify logging wrapper after r336888
llvm-svn: 336890
1 parent 73c7dce commit b34565e

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

clang-tools-extra/clangd/Logger.h

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "llvm/ADT/Twine.h"
1414
#include "llvm/Support/Debug.h"
1515
#include "llvm/Support/Error.h"
16+
#include "llvm/Support/FormatAdapters.h"
1617
#include "llvm/Support/FormatVariadic.h"
1718

1819
namespace clang {
@@ -35,21 +36,11 @@ const char *debugType(const char *Filename);
3536
void log(Logger::Level, const llvm::formatv_object_base &);
3637

3738
// We often want to consume llvm::Errors by value when passing them to log().
38-
// This is tricky because the logging infrastructure must mark them as handled.
39-
// When forwarding argument to formatv, we wrap Errors-by-value in this type
40-
// whose destructor handles the cleanup.
41-
// FIXME: simplify after D49170 lands.
42-
struct WrappedError {
43-
llvm::Error E;
44-
WrappedError(WrappedError &&) = default;
45-
~WrappedError() { consumeError(std::move(E)); }
46-
};
47-
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
48-
const WrappedError &Err) {
49-
return OS << Err.E;
50-
}
39+
// We automatically wrap them in llvm::fmt_consume() as formatv requires.
5140
template <typename T> T &&wrap(T &&V) { return std::forward<T>(V); }
52-
inline WrappedError wrap(llvm::Error &&V) { return WrappedError{std::move(V)}; }
41+
inline decltype(fmt_consume(llvm::Error::success())) wrap(llvm::Error &&V) {
42+
return fmt_consume(std::move(V));
43+
}
5344
template <typename... Ts>
5445
void log(Logger::Level L, const char *Fmt, Ts &&... Vals) {
5546
detail::log(L, llvm::formatv(Fmt, detail::wrap(std::forward<Ts>(Vals))...));

0 commit comments

Comments
 (0)