[libcxx-commits] [PATCH] D127033: [libc++] Define ostream nullptr inserter for >= C++17 only

Joe Loser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jun 3 16:10:26 PDT 2022


jloser created this revision.
jloser added reviewers: ldionne, Mordante, philnik, var-const, zoecarver, mclow.lists, EricWF.
Herald added a project: All.
jloser requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

The `ostream` `nullptr` inserter implemented in 3c125fe is missing a C++ version
guard. As adopted with LWG 2221, this should only apply to C++17 or later. Add a
version guard as such.

Fixes https://github.com/llvm/llvm-project/issues/55861.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127033

Files:
  libcxx/include/ostream
  libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/streambuf.pass.cpp


Index: libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/streambuf.pass.cpp
===================================================================
--- libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/streambuf.pass.cpp
+++ libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/streambuf.pass.cpp
@@ -67,6 +67,7 @@
         os << &sb2;
         assert(sb.str() == "testing...");
     }
+#if TEST_STD_VER > 14
     { // LWG 2221 - nullptr
         testbuf<char> sb;
         std::ostream os(&sb);
@@ -74,6 +75,7 @@
         assert(sb.str().size() != 0);
         LIBCPP_ASSERT(sb.str() == "nullptr");
     }
+#endif
 
   return 0;
 }
Index: libcxx/include/ostream
===================================================================
--- libcxx/include/ostream
+++ libcxx/include/ostream
@@ -222,9 +222,11 @@
 
     basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
 
+#if _LIBCPP_STD_VER > 14
     _LIBCPP_INLINE_VISIBILITY
     basic_ostream& operator<<(nullptr_t)
     { return *this << "nullptr"; }
+#endif
 
     // 27.7.2.7 Unformatted output:
     basic_ostream& put(char_type __c);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127033.434193.patch
Type: text/x-patch
Size: 1242 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220603/a8777bfa/attachment.bin>


More information about the libcxx-commits mailing list