Skip to content

Commit

Permalink
Implement LWG-4084 std::fixed ignores std::uppercase (#5151)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephan T. Lavavej <stl@nuwen.net>
  • Loading branch information
frederick-vs-ja and StephanTLavavej authored Dec 5, 2024
1 parent 649a4f2 commit e0b8a11
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stl/inc/xlocnum
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/std/tests/LWG4084_iostream_uppercase_inf_nan/env.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\usual_matrix.lst
104 changes: 104 additions & 0 deletions tests/std/tests/LWG4084_iostream_uppercase_inf_nan/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <cassert>
#include <cstddef>
#include <limits>
#include <sstream>
#include <type_traits>

using namespace std;

template <class CharT, size_t N, enable_if_t<is_same_v<CharT, char>, int> = 0>
constexpr const auto& choose_literal(const char (&s)[N], const wchar_t (&)[N]) noexcept {
return s;
}
template <class CharT, size_t N, enable_if_t<is_same_v<CharT, wchar_t>, 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<CharT>(S, L##S)

template <class CharT, class F>
void test() {
// LWG-4084 "std::fixed ignores std::uppercase"
{
auto s = (basic_ostringstream<CharT>{} << fixed << uppercase << numeric_limits<F>::infinity()).str();
assert(s == STATICALLY_WIDEN(CharT, "INF"));
}
{
auto s = (basic_ostringstream<CharT>{} << fixed << uppercase << numeric_limits<F>::quiet_NaN()).str();
assert(s == STATICALLY_WIDEN(CharT, "NAN"));
}
// also test other combinations
{
auto s = (basic_ostringstream<CharT>{} << fixed << numeric_limits<F>::infinity()).str();
assert(s == STATICALLY_WIDEN(CharT, "inf"));
}
{
auto s = (basic_ostringstream<CharT>{} << fixed << numeric_limits<F>::quiet_NaN()).str();
assert(s == STATICALLY_WIDEN(CharT, "nan"));
}

{
auto s = (basic_ostringstream<CharT>{} << uppercase << numeric_limits<F>::infinity()).str();
assert(s == STATICALLY_WIDEN(CharT, "INF"));
}
{
auto s = (basic_ostringstream<CharT>{} << uppercase << numeric_limits<F>::quiet_NaN()).str();
assert(s == STATICALLY_WIDEN(CharT, "NAN"));
}
{
auto s = (basic_ostringstream<CharT>{} << numeric_limits<F>::infinity()).str();
assert(s == STATICALLY_WIDEN(CharT, "inf"));
}
{
auto s = (basic_ostringstream<CharT>{} << numeric_limits<F>::quiet_NaN()).str();
assert(s == STATICALLY_WIDEN(CharT, "nan"));
}

{
auto s = (basic_ostringstream<CharT>{} << scientific << uppercase << numeric_limits<F>::infinity()).str();
assert(s == STATICALLY_WIDEN(CharT, "INF"));
}
{
auto s = (basic_ostringstream<CharT>{} << scientific << uppercase << numeric_limits<F>::quiet_NaN()).str();
assert(s == STATICALLY_WIDEN(CharT, "NAN"));
}
{
auto s = (basic_ostringstream<CharT>{} << scientific << numeric_limits<F>::infinity()).str();
assert(s == STATICALLY_WIDEN(CharT, "inf"));
}
{
auto s = (basic_ostringstream<CharT>{} << scientific << numeric_limits<F>::quiet_NaN()).str();
assert(s == STATICALLY_WIDEN(CharT, "nan"));
}

{
auto s = (basic_ostringstream<CharT>{} << hexfloat << uppercase << numeric_limits<F>::infinity()).str();
assert(s == STATICALLY_WIDEN(CharT, "INF"));
}
{
auto s = (basic_ostringstream<CharT>{} << hexfloat << uppercase << numeric_limits<F>::quiet_NaN()).str();
assert(s == STATICALLY_WIDEN(CharT, "NAN"));
}
{
auto s = (basic_ostringstream<CharT>{} << hexfloat << numeric_limits<F>::infinity()).str();
assert(s == STATICALLY_WIDEN(CharT, "inf"));
}
{
auto s = (basic_ostringstream<CharT>{} << hexfloat << numeric_limits<F>::quiet_NaN()).str();
assert(s == STATICALLY_WIDEN(CharT, "nan"));
}
}

int main() {
test<char, float>();
test<char, double>();
test<char, long double>();

test<wchar_t, float>();
test<wchar_t, double>();
test<wchar_t, long double>();
}

0 comments on commit e0b8a11

Please sign in to comment.