The `ostream` `nullptr` inserter implemented in
3c125fe is missing a C++ version
guard. Normally, `libc++` takes the stance of backporting LWG issues to older
standards modes as was done in
3c125fe. However, backporting to older standards
modes breaks existing code in popular libraries such as `Boost.Test` and
`Google Test` who define their own overload for `nullptr_t`.
Instead, only apply this `operator<<` overload in C++17 or later.
Fixes https://github.com/llvm/llvm-project/issues/55861.
Differential Revision: https://reviews.llvm.org/
D127033
basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
+#if _LIBCPP_STD_VER > 14
+// LWG 2221 - nullptr. This is not backported to older standards modes.
+// See https://reviews.llvm.org/D127033 for more info on the rationale.
_LIBCPP_INLINE_VISIBILITY
basic_ostream& operator<<(nullptr_t)
{ return *this << "nullptr"; }
+#endif
// 27.7.2.7 Unformatted output:
basic_ostream& put(char_type __c);
os << &sb2;
assert(sb.str() == "testing...");
}
- { // LWG 2221 - nullptr
+#if TEST_STD_VER > 14
+// LWG 2221 - nullptr. This is not backported to older standards modes.
+// See https://reviews.llvm.org/D127033 for more info on the rationale.
+ {
testbuf<char> sb;
std::ostream os(&sb);
os << nullptr;
assert(sb.str().size() != 0);
LIBCPP_ASSERT(sb.str() == "nullptr");
}
+#endif
return 0;
}