Skip to content

<chrono>: incorrect estimated string width when formatting year_month_day into fullwidth character #2002

@lone-wolf-akela

Description

@lone-wolf-akela

Command-line test case

Active code page: 65001

D:\cpptest>type repro.cpp
#include <format>
#include <iostream>
#include <chrono>
#include <locale>
int main()
{
        using namespace std::chrono;
        std::locale loc{ "chinese.UTF-8" };
        std::locale::global(loc);
        const year_month_day date = 2021y / June / 1d;
        std::cout << std::format("+{:-^60}+\n", "");
        std::cout << std::format("|{:^60}|\n", "English & 中文");
        std::cout << std::format("|{:^60%Y %B %d %A}|\n", date);
        std::cout << std::format("|{:^60}|\n", std::format("{:%Y %B %d %A}", date));
        std::cout << std::format("+{:-^60}+\n", "");
        return 0;
}

D:\cpptest>cl /std:c++20 /utf-8 .\repro.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30129.3 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

repro.cpp
D:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.29.30129\include\chrono(2879): warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
Microsoft (R) Incremental Linker Version 14.29.30129.3
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:repro.exe
repro.obj

D:\cpptest>repro.exe
+------------------------------------------------------------+
|                       English & 中文                       |
|                  2021 六月 01 星期二                  |
|                    2021 六月 01 星期二                     |
+------------------------------------------------------------+

Expected behavior
I expect the output to be like:

+------------------------------------------------------------+
|                       English & 中文                       |
|                    2021 六月 01 星期二                     |
|                    2021 六月 01 星期二                     |
+------------------------------------------------------------+

i.e. the two lines of "2021 六月 01 星期二" should have the same width.
STL version

Microsoft Visual Studio Enterprise 2019 Preview
版本 16.11.0 Preview 1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingchronoC++20 chronofixedSomething works now, yay!formatC++20/23 format

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions