verity: Fix unit test issue with libc++
class Message in logging inherits from ostream which libc++
dislikes since ostream class has a private constructor. Inspection
showed no reason to inherit ostream. Message class only needs
to overload the "<<" operator for logging. So move the already
defined "<<" operator function inside the class.
Remove stream() function and update the macros.
BUG=chromium:724628
TEST=verity unit tests pass with/without libc++.
Change-Id: Ia854f11287fdf3789844540da49ea6eb969a7b40
Reviewed-on: https://chromium-review.googlesource.com/614871
Commit-Ready: Manoj Gupta <manojgupta@chromium.org>
Tested-by: Manoj Gupta <manojgupta@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/logging/logging.h b/logging/logging.h
index 86b8820..7656a8b 100644
--- a/logging/logging.h
+++ b/logging/logging.h
@@ -23,7 +23,7 @@
static MessageLevel min_level = LEVEL_INFO;
-class Message : public std::ostream {
+class Message {
public:
Message(MessageLevel level,
MessageType type,
@@ -72,6 +72,20 @@
exit(1);
}
+ template<typename T>
+ const Message& operator<<(const T& t) const {
+#ifdef NDEBUG
+ if (type() == TYPE_DEBUG)
+ return *this;
+#endif
+
+ if (type() == TYPE_NULL || level() < min_level)
+ return *this;
+
+ std::cerr << t;
+ return *this;
+ }
+
MessageLevel level() const { return level_; }
MessageType type() const { return type_; }
int log_errno() const { return log_errno_; }
@@ -80,9 +94,6 @@
void set_level(MessageLevel l) { level_ = l; }
- // Returns 'this' to simplify the macros.
- virtual Message *stream() { return this; }
-
private:
MessageLevel level_;
MessageType type_;
@@ -90,48 +101,33 @@
const char *file_;
unsigned long line_;
};
-
-template <typename T>
-Message &operator<<(Message &s, T t) {
-#ifdef NDEBUG
- if (s.type() == TYPE_DEBUG)
- return s;
-#endif
-
- if (s.type() == TYPE_NULL || s.level() < min_level)
- return s;
-
- std::cerr << t;
- return s;
-}
-
} // namespace logging
// Interface macros
#define LOG(_level) \
- *logging::Message(logging::LEVEL_##_level, \
+ logging::Message(logging::LEVEL_##_level, \
logging::TYPE_NORMAL, \
0, \
__FILE__, \
- __LINE__).stream()
+ __LINE__)
#define PLOG(_level) \
- *logging::Message(logging::LEVEL_##_level, \
+ logging::Message(logging::LEVEL_##_level, \
logging::TYPE_ERRNO,\
errno, \
__FILE__, \
- __LINE__).stream()
+ __LINE__)
#define DLOG(_level) \
- *logging::Message(logging::LEVEL_##_level,\
+ logging::Message(logging::LEVEL_##_level,\
logging::TYPE_DEBUG, \
0, \
__FILE__, \
- __LINE__).stream()
+ __LINE__)
#define LOG_NULL \
- *logging::Message(logging::LEVEL_INFO, \
+ logging::Message(logging::LEVEL_INFO, \
logging::TYPE_NULL, \
0, \
__FILE__, \
- __LINE__).stream()
+ __LINE__)
#define LOG_IF(_level, cond) ((cond) ? LOG(_level) : LOG_NULL)
#define PLOG_IF(_level, cond) ((cond) ? PLOG(_level) : LOG_NULL)