From c26c687912d46401098f3e6f1256f0f937494ddf Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 28 Jul 2016 16:12:16 +1000 Subject: [PATCH] format: set ostream precision as if for strings ostream conversions are converted to strings anyway, so we should treat them as such earlier in the process. --- format.ipp | 2 +- test/format.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/format.ipp b/format.ipp index 42ac2461..d375282b 100644 --- a/format.ipp +++ b/format.ipp @@ -225,12 +225,12 @@ namespace util { namespace format { namespace detail { return -1; case specifier::kind::STRING: + case specifier::kind::OSTREAM: return std::numeric_limits::max (); case specifier::kind::POINTER: case specifier::kind::CHARACTER: case specifier::kind::ESCAPE: - case specifier::kind::OSTREAM: return 0; } diff --git a/test/format.cpp b/test/format.cpp index 0628ea58..4ecf9697 100644 --- a/test/format.cpp +++ b/test/format.cpp @@ -2,6 +2,18 @@ #include "tap.hpp" + +/////////////////////////////////////////////////////////////////////////////// +struct userobj { }; + +static std::ostream& +operator<< (std::ostream &os, const userobj&) +{ + return os << "userobj"; +} + + +/////////////////////////////////////////////////////////////////////////////// int main (void) { @@ -121,6 +133,7 @@ main (void) CHECK_RENDER ("%.64s", "foo", "foo"); CHECK_RENDER ("%3.1s", " f", "foo"); CHECK_RENDER ("%-3.1s", "f ", "foo"); + CHECK_RENDER ("%!", "userobj", userobj {}); CHECK_RENDER ("%p", "0x1234567", (void*)0x01234567); CHECK_RENDER ("%p", "0x1234567", (int*)0x01234567);