Skip to content

Commit

Permalink
Reimplement LAZY_STREAM with a switch
Browse files Browse the repository at this point in the history
This trades warnings with C4715 (not all control paths return a value)
and C4127 (conditional expression is constant). We explicitly disable
C4127 so fingers crossed that no other problem pops up when rolling this
into crashpad.

This also gets rid of logging::LogMessageVoidify which is nice.

Bug: chromium:40254046
Change-Id: I52274f3e66d84507c48f019a66ebabebe80ca912
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/mini_chromium/+/5907040
Reviewed-by: Mark Mentovai <mark@chromium.org>
  • Loading branch information
pbos committed Oct 4, 2024
1 parent d288241 commit c081fd0
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions base/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,6 @@ class LogMessageFatal final : public LogMessage {
[[noreturn]] ~LogMessageFatal() override;
};

class LogMessageVoidify {
public:
LogMessageVoidify() {}

void operator&(const std::ostream&) const {}
};

#if BUILDFLAG(IS_WIN)
class Win32ErrorLogMessage : public LogMessage {
public:
Expand Down Expand Up @@ -256,7 +249,13 @@ const LogSeverity LOG_0 = LOG_ERROR;
#endif // BUILDFLAG(IS_WIN)

#define LAZY_STREAM(stream, condition) \
!(condition) ? (void) 0 : ::logging::LogMessageVoidify() & (stream)
switch (0) \
case 0: \
default: \
if (!(condition)) \
; \
else \
(stream)

// FATAL is always enabled and required to be resolved in compile time for
// LOG(FATAL) to be properly understood as [[noreturn]].
Expand Down

0 comments on commit c081fd0

Please sign in to comment.