Skip to content

Commit e0b8a11

Browse files
Implement LWG-4084 std::fixed ignores std::uppercase (#5151)
Co-authored-by: Stephan T. Lavavej <[email protected]>
1 parent 649a4f2 commit e0b8a11

File tree

4 files changed

+110
-1
lines changed

4 files changed

+110
-1
lines changed

stl/inc/xlocnum

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,7 @@ private:
14351435
ios_base::fmtflags _Ffl = _Flags & ios_base::floatfield;
14361436
if (_Flags & ios_base::uppercase) {
14371437
if (_Ffl == ios_base::fixed) {
1438-
_Ch = 'f';
1438+
_Ch = 'F';
14391439
} else if (_Ffl == (ios_base::scientific | ios_base::fixed)) {
14401440
_Ch = 'A';
14411441
} else if (_Ffl == ios_base::scientific) {

tests/std/test.lst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ tests\LWG3528_make_from_tuple_impl
265265
tests\LWG3545_pointer_traits_sfinae
266266
tests\LWG3561_discard_block_engine_counter
267267
tests\LWG3610_iota_view_size_and_integer_class
268+
tests\LWG4084_iostream_uppercase_inf_nan
268269
tests\LWG4105_ranges_ends_with_and_integer_class
269270
tests\P0009R18_mdspan_default_accessor
270271
tests\P0009R18_mdspan_extents
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
RUNALL_INCLUDE ..\usual_matrix.lst
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#include <cassert>
5+
#include <cstddef>
6+
#include <limits>
7+
#include <sstream>
8+
#include <type_traits>
9+
10+
using namespace std;
11+
12+
template <class CharT, size_t N, enable_if_t<is_same_v<CharT, char>, int> = 0>
13+
constexpr const auto& choose_literal(const char (&s)[N], const wchar_t (&)[N]) noexcept {
14+
return s;
15+
}
16+
template <class CharT, size_t N, enable_if_t<is_same_v<CharT, wchar_t>, int> = 0>
17+
constexpr const auto& choose_literal(const char (&)[N], const wchar_t (&ws)[N]) noexcept {
18+
return ws;
19+
}
20+
21+
#define STATICALLY_WIDEN(CharT, S) ::choose_literal<CharT>(S, L##S)
22+
23+
template <class CharT, class F>
24+
void test() {
25+
// LWG-4084 "std::fixed ignores std::uppercase"
26+
{
27+
auto s = (basic_ostringstream<CharT>{} << fixed << uppercase << numeric_limits<F>::infinity()).str();
28+
assert(s == STATICALLY_WIDEN(CharT, "INF"));
29+
}
30+
{
31+
auto s = (basic_ostringstream<CharT>{} << fixed << uppercase << numeric_limits<F>::quiet_NaN()).str();
32+
assert(s == STATICALLY_WIDEN(CharT, "NAN"));
33+
}
34+
// also test other combinations
35+
{
36+
auto s = (basic_ostringstream<CharT>{} << fixed << numeric_limits<F>::infinity()).str();
37+
assert(s == STATICALLY_WIDEN(CharT, "inf"));
38+
}
39+
{
40+
auto s = (basic_ostringstream<CharT>{} << fixed << numeric_limits<F>::quiet_NaN()).str();
41+
assert(s == STATICALLY_WIDEN(CharT, "nan"));
42+
}
43+
44+
{
45+
auto s = (basic_ostringstream<CharT>{} << uppercase << numeric_limits<F>::infinity()).str();
46+
assert(s == STATICALLY_WIDEN(CharT, "INF"));
47+
}
48+
{
49+
auto s = (basic_ostringstream<CharT>{} << uppercase << numeric_limits<F>::quiet_NaN()).str();
50+
assert(s == STATICALLY_WIDEN(CharT, "NAN"));
51+
}
52+
{
53+
auto s = (basic_ostringstream<CharT>{} << numeric_limits<F>::infinity()).str();
54+
assert(s == STATICALLY_WIDEN(CharT, "inf"));
55+
}
56+
{
57+
auto s = (basic_ostringstream<CharT>{} << numeric_limits<F>::quiet_NaN()).str();
58+
assert(s == STATICALLY_WIDEN(CharT, "nan"));
59+
}
60+
61+
{
62+
auto s = (basic_ostringstream<CharT>{} << scientific << uppercase << numeric_limits<F>::infinity()).str();
63+
assert(s == STATICALLY_WIDEN(CharT, "INF"));
64+
}
65+
{
66+
auto s = (basic_ostringstream<CharT>{} << scientific << uppercase << numeric_limits<F>::quiet_NaN()).str();
67+
assert(s == STATICALLY_WIDEN(CharT, "NAN"));
68+
}
69+
{
70+
auto s = (basic_ostringstream<CharT>{} << scientific << numeric_limits<F>::infinity()).str();
71+
assert(s == STATICALLY_WIDEN(CharT, "inf"));
72+
}
73+
{
74+
auto s = (basic_ostringstream<CharT>{} << scientific << numeric_limits<F>::quiet_NaN()).str();
75+
assert(s == STATICALLY_WIDEN(CharT, "nan"));
76+
}
77+
78+
{
79+
auto s = (basic_ostringstream<CharT>{} << hexfloat << uppercase << numeric_limits<F>::infinity()).str();
80+
assert(s == STATICALLY_WIDEN(CharT, "INF"));
81+
}
82+
{
83+
auto s = (basic_ostringstream<CharT>{} << hexfloat << uppercase << numeric_limits<F>::quiet_NaN()).str();
84+
assert(s == STATICALLY_WIDEN(CharT, "NAN"));
85+
}
86+
{
87+
auto s = (basic_ostringstream<CharT>{} << hexfloat << numeric_limits<F>::infinity()).str();
88+
assert(s == STATICALLY_WIDEN(CharT, "inf"));
89+
}
90+
{
91+
auto s = (basic_ostringstream<CharT>{} << hexfloat << numeric_limits<F>::quiet_NaN()).str();
92+
assert(s == STATICALLY_WIDEN(CharT, "nan"));
93+
}
94+
}
95+
96+
int main() {
97+
test<char, float>();
98+
test<char, double>();
99+
test<char, long double>();
100+
101+
test<wchar_t, float>();
102+
test<wchar_t, double>();
103+
test<wchar_t, long double>();
104+
}

0 commit comments

Comments
 (0)