diff --git a/stl/inc/chrono b/stl/inc/chrono index 34f10386d0..982be0a92d 100644 --- a/stl/inc/chrono +++ b/stl/inc/chrono @@ -5477,7 +5477,14 @@ namespace chrono { int _Estimated_width = -1; (void) _Measure_string_prefix(_Stream.view(), _Estimated_width); - return _Write_aligned(_STD move(_FormatCtx.out()), _Estimated_width, _Specs, _Fmt_align::_Left, + + auto _Format_specs = _Specs; + if (_Specs._Dynamic_width_index >= 0) { + _Format_specs._Width = _Get_dynamic_specs<_Width_checker>( + _FormatCtx.arg(static_cast(_Specs._Dynamic_width_index))); + } + + return _Write_aligned(_STD move(_FormatCtx.out()), _Estimated_width, _Format_specs, _Fmt_align::_Left, [&](auto _Out) { return _Fmt_write(_STD move(_Out), _Stream.view()); }); } diff --git a/tests/std/test.lst b/tests/std/test.lst index edced59a40..1cb0e33f91 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -234,6 +234,7 @@ tests\GH_003840_tellg_when_reading_lf_file_in_text_mode tests\GH_003867_output_nan tests\GH_004023_mdspan_fwd_prod_overflow tests\GH_004040_container_nonmember_functions +tests\GH_004201_chrono_formatter tests\GH_004275_seeking_fancy_iterators tests\LWG2381_num_get_floating_point tests\LWG2597_complex_branch_cut diff --git a/tests/std/tests/GH_004201_chrono_formatter/env.lst b/tests/std/tests/GH_004201_chrono_formatter/env.lst new file mode 100644 index 0000000000..d6d824b587 --- /dev/null +++ b/tests/std/tests/GH_004201_chrono_formatter/env.lst @@ -0,0 +1,4 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +RUNALL_INCLUDE ..\concepts_20_matrix.lst diff --git a/tests/std/tests/GH_004201_chrono_formatter/test.cpp b/tests/std/tests/GH_004201_chrono_formatter/test.cpp new file mode 100644 index 0000000000..2b3e109621 --- /dev/null +++ b/tests/std/tests/GH_004201_chrono_formatter/test.cpp @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include +#include +#include +#include + +using namespace std::literals::chrono_literals; + +int main() { + assert(std::format("[{:20%T}]", 314159s) == "[87:15:59 ]"); + + // std::formatter specializations for types used to ignore dynamically provided width + assert(std::format("[{:{}%T}]", 314159s, 20) == "[87:15:59 ]"); +}