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,132 @@ +//===----------------------------------------------------------------------===// +// +// 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 +void test_min_oct(const char *expected) +{ + std::stringstream ss; + ss << std::oct << std::showbase << std::numeric_limits::min(); + assert(ss.str() == expected); +} + +template +void test_max_oct(const char *expected) +{ + std::stringstream ss; + ss << std::oct << std::showbase << std::numeric_limits::max(); + assert(ss.str() == expected); +} + +template +void test_min_dec(const char *expected) +{ + std::stringstream ss; + ss << std::dec << std::showbase << std::numeric_limits::min(); + assert(ss.str() == expected); +} + +template +void test_max_dec(const char *expected) +{ + std::stringstream ss; + ss << std::dec << std::showbase << std::numeric_limits::max(); + assert(ss.str() == expected); +} + +template +void test_min_hex(const char *expected) +{ + std::stringstream ss; + ss << std::hex << std::showbase << std::numeric_limits::min(); + assert(ss.str() == expected); +} + +template +void test_max_hex(const char *expected) +{ + std::stringstream ss; + ss << std::hex << std::showbase << std::numeric_limits::max(); + assert(ss.str() == expected); +} + +int main(void) +{ + test_min_oct("0100000"); + test_min_dec("-32768"); + test_min_hex("0x8000"); + + test_max_oct("0177777"); + test_max_dec("65535"); + test_max_hex("0xffff"); + + test_min_oct("020000000000"); + test_min_dec("-2147483648"); + test_min_hex("0x80000000"); + + test_max_oct("037777777777"); + test_max_dec("4294967295"); + test_max_hex("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_min_oct("020000000000"); + test_min_dec("-2147483648"); + test_min_hex("0x80000000"); + + test_max_oct("037777777777"); + test_max_dec("4294967295"); + test_max_hex("0xffffffff"); + } else if (long_is_64) { + test_min_oct("01000000000000000000000"); + test_min_dec("-9223372036854775808"); + test_min_hex("0x8000000000000000"); + + test_max_oct("01777777777777777777777"); + test_max_dec("18446744073709551615"); + test_max_hex("0xffffffffffffffff"); + } + if (long_long_is_64) { + test_min_oct("01000000000000000000000"); + test_min_dec("-9223372036854775808"); + test_min_hex("0x8000000000000000"); + + test_max_oct("01777777777777777777777"); + test_max_dec("18446744073709551615"); + test_max_hex("0xffffffffffffffff"); + } + + return 0; +}