diff --git a/format.ipp b/format.ipp index 33d53e65..6efc8da1 100644 --- a/format.ipp +++ b/format.ipp @@ -603,6 +603,12 @@ namespace util { namespace format { namespace detail { OutputT write (OutputT os, const specifier spec, const char *t) { + // we need to forward to the pointer write function rather than the + // other way around to reduce ambiguity and the potential for + // recursion. + if (spec.k == specifier::kind::POINTER) + return write (os, spec, reinterpret_cast (t)); + if (spec.k != specifier::kind::STRING) throw conversion_error ("invalid specifier kind for string argumetn"); @@ -672,7 +678,7 @@ namespace util { namespace format { namespace detail { //------------------------------------------------------------------------- template std::enable_if_t< - std::is_pointer::value, + std::is_pointer::value && !std::is_same, char>::value, OutputT > write (OutputT &os, const specifier &spec, const T t) diff --git a/test/format.cpp b/test/format.cpp index b343e33e..119d84c0 100644 --- a/test/format.cpp +++ b/test/format.cpp @@ -112,6 +112,8 @@ main (void) CHECK_RENDER ("%c", "A", 'A'); CHECK_RENDER ("%s", "foo", "foo"); + CHECK_RENDER ("%s", "foo", std::string ("foo")); + CHECK_RENDER ("%s", "foo", const_cast ("foo")); CHECK_RENDER ("%.s", "", "foo"); CHECK_RENDER ("%.0s", "", "foo"); CHECK_RENDER ("%.2s", "fo", "foo"); @@ -122,6 +124,7 @@ main (void) CHECK_RENDER ("%p", "0x1234567", (void*)0x01234567); CHECK_RENDER ("%p", "0x1234567", (int*)0x01234567); + CHECK_RENDER ("%p", "0x1234567", (char*)0x01234567); CHECK_RENDER ("%p", "(nil)", nullptr); CHECK_RENDER ("%p", "(nil)", NULL);