From b8665b9c4943c93e584db2c30b2d54c4bf3326ba Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Wed, 27 Nov 2024 02:47:32 +0800 Subject: [PATCH 1/2] Implement LWG-4084 --- stl/inc/xlocnum | 2 +- tests/std/test.lst | 1 + .../env.lst | 4 + .../test.cpp | 104 ++++++++++++++++++ 4 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 tests/std/tests/LWG4084_iostream_uppercase_inf_nan/env.lst create mode 100644 tests/std/tests/LWG4084_iostream_uppercase_inf_nan/test.cpp 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..e3c17319970 --- /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)[NChar], const wchar_t (&)[NWChar]) noexcept { + return s; +} +template , int> = 0> +constexpr const auto& choose_literal(const char (&)[NChar], const wchar_t (&ws)[NWChar]) 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(); +} From 622242ba864530977835bbe3612850a6b0c8f648 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Mon, 2 Dec 2024 08:45:08 -0800 Subject: [PATCH 2/2] `choose_literal` always chooses between equal-size strings. --- .../std/tests/LWG4084_iostream_uppercase_inf_nan/test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/std/tests/LWG4084_iostream_uppercase_inf_nan/test.cpp b/tests/std/tests/LWG4084_iostream_uppercase_inf_nan/test.cpp index e3c17319970..4f9acdc6213 100644 --- a/tests/std/tests/LWG4084_iostream_uppercase_inf_nan/test.cpp +++ b/tests/std/tests/LWG4084_iostream_uppercase_inf_nan/test.cpp @@ -9,12 +9,12 @@ using namespace std; -template , int> = 0> -constexpr const auto& choose_literal(const char (&s)[NChar], const wchar_t (&)[NWChar]) noexcept { +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 (&)[NChar], const wchar_t (&ws)[NWChar]) noexcept { +template , int> = 0> +constexpr const auto& choose_literal(const char (&)[N], const wchar_t (&ws)[N]) noexcept { return ws; }