summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNing Ren <ningr@google.com>2017-04-20 22:30:42 (GMT)
committerNing Ren <ningr@google.com>2017-04-20 22:32:24 (GMT)
commit0d8c6340f8c5276e0a67df6712f4249582cd79b3 (patch)
tree9fd468c3f39eb82ee14933c6f2bf7fda7e48308f /src
parentda816ea70645e463aa04f9564544939fa327d5a7 (diff)
downloadglog-0d8c6340f8c5276e0a67df6712f4249582cd79b3.zip
glog-0d8c6340f8c5276e0a67df6712f4249582cd79b3.tar.gz
glog-0d8c6340f8c5276e0a67df6712f4249582cd79b3.tar.bz2
CHECK_NOTNULL works with smart pointers when compiled in C++11.
Diffstat (limited to 'src')
-rw-r--r--src/glog/logging.h.in30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/glog/logging.h.in b/src/glog/logging.h.in
index 271346f..d6cc865 100644
--- a/src/glog/logging.h.in
+++ b/src/glog/logging.h.in
@@ -1309,6 +1309,35 @@ inline void LogAtLevel(int const severity, std::string const &msg) {
// LOG macros, 2. this macro can be used as C++ stream.
#define LOG_AT_LEVEL(severity) @ac_google_namespace@::LogMessage(__FILE__, __LINE__, severity).stream()
+// Check if it's compiled in C++11 mode.
+//
+// GXX_EXPERIMENTAL_CXX0X is defined by gcc and clang up to at least
+// gcc-4.7 and clang-3.1 (2011-12-13). __cplusplus was defined to 1
+// in gcc before 4.7 (Crosstool 16) and clang before 3.1, but is
+// defined according to the language version in effect thereafter.
+// Microsoft Visual Studio 14 (2015) sets __cplusplus==199711 despite
+// reasonably good C++11 support, so we set LANG_CXX for it and
+// newer versions (_MSC_VER >= 1900).
+#if (defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L || \
+ (defined(_MSC_VER) && _MSC_VER >= 1900))
+// Helper for CHECK_NOTNULL().
+//
+// In C++11, all cases can be handled by a single function. Since the value
+// category of the argument is preserved (also for rvalue references),
+// member initializer lists like the one below will compile correctly:
+//
+// Foo()
+// : x_(CHECK_NOTNULL(MethodReturningUniquePtr())) {}
+template <typename T>
+T CheckNotNull(const char* file, int line, const char* names, T&& t) {
+ if (t == nullptr) {
+ LogMessageFatal(file, line, new std::string(names));
+ }
+ return std::forward<T>(t);
+}
+
+#else
+
// A small helper for CHECK_NOTNULL().
template <typename T>
T* CheckNotNull(const char *file, int line, const char *names, T* t) {
@@ -1317,6 +1346,7 @@ T* CheckNotNull(const char *file, int line, const char *names, T* t) {
}
return t;
}
+#endif
// Allow folks to put a counter in the LOG_EVERY_X()'ed messages. This
// only works if ostream is a LogStream. If the ostream is not a