Skip to content

Commit

Permalink
Revert "simplify DLOG macro definition in NDEBUG mode (#830)"
Browse files Browse the repository at this point in the history
This reverts commit 278ed96.
  • Loading branch information
sergiud committed Aug 18, 2022
1 parent bfee415 commit 0511d80
Showing 1 changed file with 41 additions and 9 deletions.
50 changes: 41 additions & 9 deletions src/glog/logging.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,12 @@ class LogSink; // defined below
#define LOG_STRING(severity, outvec) \
LOG_TO_STRING_##severity(static_cast<std::vector<std::string>*>(outvec)).stream()

#define LOG_IF(severity, condition) if(condition) LOG(severity)
#define SYSLOG_IF(severity, condition) if(condition) SYSLOG(severity)
#define LOG_IF(severity, condition) \
static_cast<void>(0), \
!(condition) ? (void) 0 : @ac_google_namespace@::LogMessageVoidify() & LOG(severity)
#define SYSLOG_IF(severity, condition) \
static_cast<void>(0), \
!(condition) ? (void) 0 : @ac_google_namespace@::LogMessageVoidify() & SYSLOG(severity)

#define LOG_ASSERT(condition) \
LOG_IF(FATAL, !(condition)) << "Assert failed: " #condition
Expand Down Expand Up @@ -1001,7 +1005,9 @@ DECLARE_CHECK_STROP_IMPL(strcasecmp, false)
__FILE__, __LINE__, @ac_google_namespace@::GLOG_ ## severity, counter, \
&@ac_google_namespace@::LogMessage::SendToLog)

#define PLOG_IF(severity, condition) if(condition) PLOG(severity)
#define PLOG_IF(severity, condition) \
static_cast<void>(0), \
!(condition) ? (void) 0 : @ac_google_namespace@::LogMessageVoidify() & PLOG(severity)

// A CHECK() macro that postpends errno if the condition is false. E.g.
//
Expand Down Expand Up @@ -1333,17 +1339,30 @@ const LogSeverity GLOG_0 = GLOG_ERROR;

#else // !DCHECK_IS_ON()

#define DLOG(severity) if((false)) LOG(severity)
#define DLOG(severity) \
static_cast<void>(0), \
true ? (void) 0 : @ac_google_namespace@::LogMessageVoidify() & LOG(severity)

#define DVLOG(verboselevel) if((false) && VLOG_IS_ON(verboselevel)) LOG(INFO)
#define DVLOG(verboselevel) \
static_cast<void>(0), \
(true || !VLOG_IS_ON(verboselevel)) ? \
(void) 0 : @ac_google_namespace@::LogMessageVoidify() & LOG(INFO)

#define DLOG_IF(severity, condition) if((false) && (condition)) LOG(severity)
#define DLOG_IF(severity, condition) \
static_cast<void>(0), \
(true || !(condition)) ? (void) 0 : @ac_google_namespace@::LogMessageVoidify() & LOG(severity)

#define DLOG_EVERY_N(severity, n) if((false)) LOG(severity)
#define DLOG_EVERY_N(severity, n) \
static_cast<void>(0), \
true ? (void) 0 : @ac_google_namespace@::LogMessageVoidify() & LOG(severity)

#define DLOG_IF_EVERY_N(severity, condition, n) if((false) && (condition)) LOG(severity)
#define DLOG_IF_EVERY_N(severity, condition, n) \
static_cast<void>(0), \
(true || !(condition))? (void) 0 : @ac_google_namespace@::LogMessageVoidify() & LOG(severity)

#define DLOG_ASSERT(condition) if((false)) LOG_ASSERT(condition)
#define DLOG_ASSERT(condition) \
static_cast<void>(0), \
true ? (void) 0 : LOG_ASSERT(condition)

// MSVC warning C4127: conditional expression is constant
#define DCHECK(condition) \
Expand Down Expand Up @@ -1688,6 +1707,19 @@ class GLOG_EXPORT ErrnoLogMessage : public LogMessage {
};


// This class is used to explicitly ignore values in the conditional
// logging macros. This avoids compiler warnings like "value computed
// is not used" and "statement has no effect".

class GLOG_EXPORT LogMessageVoidify {
public:
LogMessageVoidify() { }
// This has to be an operator with a precedence lower than << but
// higher than ?:
void operator&(std::ostream&) { }
};


// Flushes all log files that contains messages that are at least of
// the specified severity level. Thread-safe.
GLOG_EXPORT void FlushLogFiles(LogSeverity min_severity);
Expand Down

0 comments on commit 0511d80

Please sign in to comment.