Skip to content

Commit

Permalink
Adds CHECK support for nullptr. (fixes google#341)
Browse files Browse the repository at this point in the history
This allows CHECK_NE(foo, nullptr) to compile and produces "nullptr" for the
string representation of nullptr.
  • Loading branch information
bretmckee committed May 24, 2019
1 parent 96a2f23 commit f2cf2e1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Abhishek Dasgupta <abhi2743@gmail.com>
Abhishek Parmar <abhishek@orng.net>
Andrew Schwartzmeyer <andrew@schwartzmeyer.com>
Andy Ying <andy@trailofbits.com>
Bret McKee <bretmckee@google.com>
Brian Silverman <bsilver16384@gmail.com>
Fumitoshi Ukai <ukai@google.com>
Guillaume Dumont <dumont.guillaume@gmail.com>
Expand Down
4 changes: 4 additions & 0 deletions src/glog/logging.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,10 @@ void MakeCheckOpValueString(std::ostream* os, const signed char& v);
template <> GOOGLE_GLOG_DLL_DECL
void MakeCheckOpValueString(std::ostream* os, const unsigned char& v);

// Provide printable value for nullptr_t
template <> GOOGLE_GLOG_DLL_DECL
void MakeCheckOpValueString(std::ostream* os, const std::nullptr_t& v);

// Build the error message string. Specify no inlining for code size.
template <typename T1, typename T2>
std::string* MakeCheckOpString(const T1& v1, const T2& v2, const char* exprtext)
Expand Down
5 changes: 5 additions & 0 deletions src/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2163,6 +2163,11 @@ void MakeCheckOpValueString(std::ostream* os, const unsigned char& v) {
}
}

template <>
void MakeCheckOpValueString(std::ostream* os, const std::nullptr_t& v) {
(*os) << "nullptr";
}

void InitGoogleLogging(const char* argv0) {
glog_internal_namespace_::InitGoogleLoggingUtilities(argv0);
}
Expand Down

0 comments on commit f2cf2e1

Please sign in to comment.