-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
bugSomething isn't workingSomething isn't workingchronoC++20 chronoC++20 chronofixedSomething works now, yay!Something works now, yay!formatC++20/23 formatC++20/23 format
Description
C:\Temp>type meow.cpp
#include <chrono>
#include <format>
#include <iostream>
#include <string>
#include <thread>
using namespace std;
int main() {
#ifdef __GLIBCXX__
cout << "libstdc++\n";
#elif defined(_LIBCPP_VERSION)
cout << "libc++\n";
#elif defined(_MSVC_STL_UPDATE)
cout << "microsoft/STL\n";
#endif
const auto id = this_thread::get_id();
cout << format(" int {{:20}}: [{:20}]\n", 1729);
cout << format(" int {{:{{}}}}: [{:{}}]\n", 1729, 20);
cout << format("thread::id {{:20}}: [{:20}]\n", id);
cout << format("thread::id {{:{{}}}}: [{:{}}]\n", id, 20);
cout << format(" seconds {{:20%T}}: [{:20%T}]\n", 314159s);
cout << format(" seconds {{:{{}}%T}}: [{:{}%T}]\n", 314159s, 20);
}C:\Temp>cl /EHsc /nologo /W4 /std:c++latest /MTd /Od meow.cpp && meow
meow.cpp
microsoft/STL
int {:20}: [ 1729]
int {:{}}: [ 1729]
thread::id {:20}: [ 34680]
thread::id {:{}}: [ 34680]
seconds {:20%T}: [87:15:59 ]
seconds {:{}%T}: [87:15:59]
https://godbolt.org/z/YbM9qnocf
When formatting a duration, the fact that {:20%T} respects the statically provided width but {:{}%T} ignores the dynamically provided width is super buggy, and neither libstdc++ nor libc++ exhibit that behavior.
(There's a separate question of whether duration should default to being left-aligned or right-aligned. MSVC and libstdc++ chose left, libc++ chose right.)
(libc++ is also printing the hours mod 24, unlike MSVC and libstdc++.)
frederick-vs-ja
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingchronoC++20 chronoC++20 chronofixedSomething works now, yay!Something works now, yay!formatC++20/23 formatC++20/23 format