[PATCH] D33776: [libcxx] LWG2221: No formatted output operator for nullptr

Arthur O'Dwyer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 13 10:57:58 PST 2017

Quuxplusone added inline comments.

Comment at: include/ostream:225
+    basic_ostream& operator<<(nullptr_t)
+    { return *this << (const void*)0; }
mclow.lists wrote:
> lichray wrote:
> > Oh, common, I persuaded the committee to allow you to print a `(null)`  and you don't do it...
> I think that `(null)` is a better thing to output here than `0x0`.
Are you two implying that

    *this << (const void *)0;

does *not* print `(null)`? It certainly should, IMO. (I mean, it'll call `num_put` for `void*` in the current locale, but I would naturally expect that to print `(null)`.)
Anyway, whether the current locale prints null as `(null)` or not, there is great potential utility in using the same format for all pointers, as K-ballo is doing here. I'd really like to be able to

    std::ostringstream oss;
    oss << nullptr;  // equivalently: oss << (void*)0;
    void *p;
    std::istringstream(oss.str()) >> p;  // should read in a null pointer, not derp out

FWIW, it looks like libc++ currently *does* print null pointers as `(nil)`, which is not quite the same thing as `(null)`. libstdc++ prints them as `0`.


More information about the cfe-commits mailing list