[v3 PATCH] Implement LWG 2221, No formatted output operator for nullptr

Ville Voutilainen ville.voutilainen@gmail.com
Sun Dec 3 21:08:00 GMT 2017


Tested on Linux-x64.

2017-11-14  Ville Voutilainen  <ville.voutilainen@gmail.com>

    Implement LWG 2221
    * include/std/ostream (operator<<(nullptr_t)): New.
    * testsuite/27_io/basic_ostream/inserters_other/char/lwg2221.cc: New.
-------------- next part --------------
diff --git a/libstdc++-v3/include/std/ostream b/libstdc++-v3/include/std/ostream
index f7cab03..18011bc 100644
--- a/libstdc++-v3/include/std/ostream
+++ b/libstdc++-v3/include/std/ostream
@@ -245,6 +245,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       operator<<(const void* __p)
       { return _M_insert(__p); }
 
+#if __cplusplus > 201402L
+      __ostream_type&
+      operator<<(nullptr_t)
+      { return *this << "nullptr"; }
+#endif
+
       /**
        *  @brief  Extracting from another streambuf.
        *  @param  __sb  A pointer to a streambuf
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/lwg2221.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/lwg2221.cc
new file mode 100644
index 0000000..1ffacb3
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/lwg2221.cc
@@ -0,0 +1,9 @@
+// { dg-options "-std=gnu++17" }
+// { dg-do compile }
+
+#include <iostream>
+
+int main()
+{
+  std::cout << nullptr << std::endl;
+}


More information about the Libstdc++ mailing list