diff --git a/stl/inc/xlocnum b/stl/inc/xlocnum index 43b8532518f..36682328eb6 100644 --- a/stl/inc/xlocnum +++ b/stl/inc/xlocnum @@ -1435,7 +1435,7 @@ private: ios_base::fmtflags _Ffl = _Flags & ios_base::floatfield; if (_Flags & ios_base::uppercase) { if (_Ffl == ios_base::fixed) { - _Ch = 'f'; + _Ch = 'F'; } else if (_Ffl == (ios_base::scientific | ios_base::fixed)) { _Ch = 'A'; } else if (_Ffl == ios_base::scientific) { diff --git a/tests/std/test.lst b/tests/std/test.lst index 42163db9973..1f98f24c490 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -265,6 +265,7 @@ tests\LWG3528_make_from_tuple_impl tests\LWG3545_pointer_traits_sfinae tests\LWG3561_discard_block_engine_counter tests\LWG3610_iota_view_size_and_integer_class +tests\LWG4084_iostream_uppercase_inf_nan tests\LWG4105_ranges_ends_with_and_integer_class tests\P0009R18_mdspan_default_accessor tests\P0009R18_mdspan_extents diff --git a/tests/std/tests/LWG4084_iostream_uppercase_inf_nan/env.lst b/tests/std/tests/LWG4084_iostream_uppercase_inf_nan/env.lst new file mode 100644 index 00000000000..19f025bd0e6 --- /dev/null +++ b/tests/std/tests/LWG4084_iostream_uppercase_inf_nan/env.lst @@ -0,0 +1,4 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +RUNALL_INCLUDE ..\usual_matrix.lst diff --git a/tests/std/tests/LWG4084_iostream_uppercase_inf_nan/test.cpp b/tests/std/tests/LWG4084_iostream_uppercase_inf_nan/test.cpp new file mode 100644 index 00000000000..4f9acdc6213 --- /dev/null +++ b/tests/std/tests/LWG4084_iostream_uppercase_inf_nan/test.cpp @@ -0,0 +1,104 @@ +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include +#include +#include +#include +#include + +using namespace std; + +template , int> = 0> +constexpr const auto& choose_literal(const char (&s)[N], const wchar_t (&)[N]) noexcept { + return s; +} +template , int> = 0> +constexpr const auto& choose_literal(const char (&)[N], const wchar_t (&ws)[N]) noexcept { + return ws; +} + +#define STATICALLY_WIDEN(CharT, S) ::choose_literal(S, L##S) + +template +void test() { + // LWG-4084 "std::fixed ignores std::uppercase" + { + auto s = (basic_ostringstream{} << fixed << uppercase << numeric_limits::infinity()).str(); + assert(s == STATICALLY_WIDEN(CharT, "INF")); + } + { + auto s = (basic_ostringstream{} << fixed << uppercase << numeric_limits::quiet_NaN()).str(); + assert(s == STATICALLY_WIDEN(CharT, "NAN")); + } + // also test other combinations + { + auto s = (basic_ostringstream{} << fixed << numeric_limits::infinity()).str(); + assert(s == STATICALLY_WIDEN(CharT, "inf")); + } + { + auto s = (basic_ostringstream{} << fixed << numeric_limits::quiet_NaN()).str(); + assert(s == STATICALLY_WIDEN(CharT, "nan")); + } + + { + auto s = (basic_ostringstream{} << uppercase << numeric_limits::infinity()).str(); + assert(s == STATICALLY_WIDEN(CharT, "INF")); + } + { + auto s = (basic_ostringstream{} << uppercase << numeric_limits::quiet_NaN()).str(); + assert(s == STATICALLY_WIDEN(CharT, "NAN")); + } + { + auto s = (basic_ostringstream{} << numeric_limits::infinity()).str(); + assert(s == STATICALLY_WIDEN(CharT, "inf")); + } + { + auto s = (basic_ostringstream{} << numeric_limits::quiet_NaN()).str(); + assert(s == STATICALLY_WIDEN(CharT, "nan")); + } + + { + auto s = (basic_ostringstream{} << scientific << uppercase << numeric_limits::infinity()).str(); + assert(s == STATICALLY_WIDEN(CharT, "INF")); + } + { + auto s = (basic_ostringstream{} << scientific << uppercase << numeric_limits::quiet_NaN()).str(); + assert(s == STATICALLY_WIDEN(CharT, "NAN")); + } + { + auto s = (basic_ostringstream{} << scientific << numeric_limits::infinity()).str(); + assert(s == STATICALLY_WIDEN(CharT, "inf")); + } + { + auto s = (basic_ostringstream{} << scientific << numeric_limits::quiet_NaN()).str(); + assert(s == STATICALLY_WIDEN(CharT, "nan")); + } + + { + auto s = (basic_ostringstream{} << hexfloat << uppercase << numeric_limits::infinity()).str(); + assert(s == STATICALLY_WIDEN(CharT, "INF")); + } + { + auto s = (basic_ostringstream{} << hexfloat << uppercase << numeric_limits::quiet_NaN()).str(); + assert(s == STATICALLY_WIDEN(CharT, "NAN")); + } + { + auto s = (basic_ostringstream{} << hexfloat << numeric_limits::infinity()).str(); + assert(s == STATICALLY_WIDEN(CharT, "inf")); + } + { + auto s = (basic_ostringstream{} << hexfloat << numeric_limits::quiet_NaN()).str(); + assert(s == STATICALLY_WIDEN(CharT, "nan")); + } +} + +int main() { + test(); + test(); + test(); + + test(); + test(); + test(); +}