Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: move LogMessageVoidify into internal namespace #1053

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 36 additions & 19 deletions src/glog/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,14 @@ class LogSink; // defined below

#define LOG_IF(severity, condition) \
static_cast<void>(0), \
!(condition) ? (void)0 : google::LogMessageVoidify() & LOG(severity)
!(condition) \
? (void)0 \
: google::logging::internal::LogMessageVoidify() & LOG(severity)
#define SYSLOG_IF(severity, condition) \
static_cast<void>(0), \
!(condition) ? (void)0 : google::LogMessageVoidify() & SYSLOG(severity)
!(condition) \
? (void)0 \
: google::logging::internal::LogMessageVoidify() & SYSLOG(severity)

#define LOG_ASSERT(condition) \
LOG_IF(FATAL, !(condition)) << "Assert failed: " #condition
Expand Down Expand Up @@ -853,7 +857,9 @@ DECLARE_CHECK_STROP_IMPL(strcasecmp, false)

#define PLOG_IF(severity, condition) \
static_cast<void>(0), \
!(condition) ? (void)0 : google::LogMessageVoidify() & PLOG(severity)
!(condition) \
? (void)0 \
: google::logging::internal::LogMessageVoidify() & PLOG(severity)

// A CHECK() macro that postpends errno if the condition is false. E.g.
//
Expand Down Expand Up @@ -1052,34 +1058,41 @@ constexpr LogSeverity GLOG_0 = GLOG_ERROR;

# define DLOG(severity) \
static_cast<void>(0), \
true ? (void)0 : google::LogMessageVoidify() & LOG(severity)
true ? (void)0 \
: google::logging::internal::LogMessageVoidify() & LOG(severity)

# define DVLOG(verboselevel) \
static_cast<void>(0), (true || !VLOG_IS_ON(verboselevel)) \
? (void)0 \
: google::LogMessageVoidify() & LOG(INFO)
# define DVLOG(verboselevel) \
static_cast<void>(0), \
(true || !VLOG_IS_ON(verboselevel)) \
? (void)0 \
: google::logging::internal::LogMessageVoidify() & LOG(INFO)

# define DLOG_IF(severity, condition) \
static_cast<void>(0), (true || !(condition)) \
? (void)0 \
: google::LogMessageVoidify() & LOG(severity)
# define DLOG_IF(severity, condition) \
static_cast<void>(0), \
(true || !(condition)) \
? (void)0 \
: google::logging::internal::LogMessageVoidify() & LOG(severity)

# define DLOG_EVERY_N(severity, n) \
static_cast<void>(0), \
true ? (void)0 : google::LogMessageVoidify() & LOG(severity)
true ? (void)0 \
: google::logging::internal::LogMessageVoidify() & LOG(severity)

# define DLOG_IF_EVERY_N(severity, condition, n) \
static_cast<void>(0), (true || !(condition)) \
? (void)0 \
: google::LogMessageVoidify() & LOG(severity)
static_cast<void>(0), \
(true || !(condition)) \
? (void)0 \
: google::logging::internal::LogMessageVoidify() & LOG(severity)

# define DLOG_FIRST_N(severity, n) \
static_cast<void>(0), \
true ? (void)0 : google::LogMessageVoidify() & LOG(severity)
true ? (void)0 \
: google::logging::internal::LogMessageVoidify() & LOG(severity)

# define DLOG_EVERY_T(severity, T) \
static_cast<void>(0), \
true ? (void)0 : google::LogMessageVoidify() & LOG(severity)
true ? (void)0 \
: google::logging::internal::LogMessageVoidify() & LOG(severity)

# define DLOG_ASSERT(condition) \
static_cast<void>(0), true ? (void)0 : (LOG_ASSERT(condition))
Expand Down Expand Up @@ -1414,13 +1427,17 @@ class GLOG_EXPORT ErrnoLogMessage : public LogMessage {
// logging macros. This avoids compiler warnings like "value computed
// is not used" and "statement has no effect".

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

// Flushes all log files that contains messages that are at least of
// the specified severity level. Thread-safe.
Expand Down