Index: include/locale =================================================================== --- include/locale +++ include/locale @@ -1402,6 +1402,7 @@ this->__format_int(__fmt+1, __len, true, __iob.flags()); const unsigned __nbuf = (numeric_limits::digits / 3) + ((numeric_limits::digits % 3) != 0) + + ((__iob.flags() & ios_base::showbase) != 0) + 2; char __nar[__nbuf]; int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); @@ -1428,6 +1429,7 @@ this->__format_int(__fmt+1, __len, true, __iob.flags()); const unsigned __nbuf = (numeric_limits::digits / 3) + ((numeric_limits::digits % 3) != 0) + + ((__iob.flags() & ios_base::showbase) != 0) + 2; char __nar[__nbuf]; int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); @@ -1454,6 +1456,7 @@ this->__format_int(__fmt+1, __len, false, __iob.flags()); const unsigned __nbuf = (numeric_limits::digits / 3) + ((numeric_limits::digits % 3) != 0) + + ((__iob.flags() & ios_base::showbase) != 0) + 1; char __nar[__nbuf]; int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); @@ -1480,6 +1483,7 @@ this->__format_int(__fmt+1, __len, false, __iob.flags()); const unsigned __nbuf = (numeric_limits::digits / 3) + ((numeric_limits::digits % 3) != 0) + + ((__iob.flags() & ios_base::showbase) != 0) + 1; char __nar[__nbuf]; int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); Index: test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/minmax_showbase.pass.cpp =================================================================== --- /dev/null +++ test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/minmax_showbase.pass.cpp @@ -0,0 +1,97 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template > +// class basic_ostream; + +// operator<<(short n); +// operator<<(unsigned short n); +// operator<<(int n); +// operator<<(unsigned int n); +// operator<<(long n); +// operator<<(unsigned long n); +// operator<<(long long n); +// operator<<(unsigned long long n); + +// Testing to make sure that the max length values are correctly inserted when +// using std::showbase + +#include +#include +#include +#include +#include +#include + +template +static void test(std::ios_base::fmtflags fmt, const char *expected) +{ + std::stringstream ss; + ss.setf(fmt, std::ios_base::basefield); + ss << std::showbase << (std::is_signed::value ? std::numeric_limits::min() : std::numeric_limits::max()); + assert(ss.str() == expected); +} + +int main(void) +{ + const std::ios_base::fmtflags o = std::ios_base::oct; + const std::ios_base::fmtflags d = std::ios_base::dec; + const std::ios_base::fmtflags x = std::ios_base::hex; + + test(o, "0100000"); + test(d, "-32768"); + test(x, "0x8000"); + + test(o, "0177777"); + test(d, "65535"); + test(x, "0xffff"); + + test(o, "020000000000"); + test(d, "-2147483648"); + test(x, "0x80000000"); + + test(o, "037777777777"); + test(d, "4294967295"); + test(x, "0xffffffff"); + + const bool long_is_32 = std::integral_constant::value; // avoid compiler warnings + const bool long_is_64 = std::integral_constant::value; // avoid compiler warnings + const bool long_long_is_64 = std::integral_constant::value; // avoid compiler warnings + + if (long_is_32) { + test(o, "020000000000"); + test(d, "-2147483648"); + test(x, "0x80000000"); + + test(o, "037777777777"); + test(d, "4294967295"); + test(x, "0xffffffff"); + } else if (long_is_64) { + test(o, "01000000000000000000000"); + test(d, "-9223372036854775808"); + test(x, "0x8000000000000000"); + + test(o, "01777777777777777777777"); + test(d, "18446744073709551615"); + test(x, "0xffffffffffffffff"); + } + if (long_long_is_64) { + test(o, "01000000000000000000000"); + test(d, "-9223372036854775808"); + test(x, "0x8000000000000000"); + + test(o, "01777777777777777777777"); + test(d, "18446744073709551615"); + test(x, "0xffffffffffffffff"); + } + + return 0; +}