Adds CHECK support for nullptr. (fixes #341)#342
Adds CHECK support for nullptr. (fixes #341)#342bretmckee wants to merge 2 commits intogoogle:masterfrom
Conversation
This allows CHECK_NE(foo, nullptr) to compile and produces "nullptr" for the string representation of nullptr.
This is required because nullptr was added for c++11.
| void MakeCheckOpValueString(std::ostream* os, const unsigned char& v); | ||
|
|
||
| // This is required because nullptr is only present in c++ 11 and later. | ||
| #if __cplusplus >= 201103L |
There was a problem hiding this comment.
Unfortunately, this check is unreliable (e.g., under MSVC). Instead, you should test for std::nullptr_t using CMake and CheckCXXSymbolExists and provide a define (e.g., HAVE_NULLPTR_T) that is eventually used here. The __cplusplus check can be left as a backup.
There was a problem hiding this comment.
What about doing like in tensorflow ?
https://github.com/tensorflow/tensorflow/blob/590d6eef7e91a6a7392c8ffffb7b58f2e0c8bc6b/tensorflow/core/platform/macros.h#L108
https://github.com/tensorflow/tensorflow/blob/590d6eef7e91a6a7392c8ffffb7b58f2e0c8bc6b/tensorflow/core/platform/default/logging.h#L171
There was a problem hiding this comment.
This can be used as fallback. The actual check should be performed by the build system as previously explained.
|
Any plan on merging this? I'm seeing compile errors like below when using glog in AppleClang 11.0.3.11030032 for glog 0.4 /usr/local/include/glog/logging.h:640:9: error: use of overloaded operator '<<' is ambiguous (with operand types 'std::ostream' (aka 'basic_ostream') and 'const nullptr_t') |
|
seems to be the same error in #562 |
|
The finished changes are now in #641. @bretmckee I hope you are fine with this. |
This allows CHECK_NE(foo, nullptr) to compile and produces "nullptr" for the
string representation of nullptr.