Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using std::format with float or double based std::chrono::time_point causes error: invalid operands to binary expression #78555

Closed
HirthammerAllTerra opened this issue Jan 18, 2024 · 4 comments
Assignees
Labels
format C++20 std::format or std::print, and anything related to them invalid Resolved as invalid, i.e. not a bug libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@HirthammerAllTerra
Copy link

Consider the following code snippet:

using Representation = double;
using Duration       = std::chrono::duration<Representation>;
using Clock          = std::chrono::system_clock;
using TimePoint      = std::chrono::time_point<Clock, Duration>;

TimePoint tp = {};

std::string time_string = std::format("{:%d.%m.%Y %H:%M:%S}", tp);

This results in the compile error:

error: invalid operands to binary expression ('basic_ostringstream<char>' and 'const std::chrono::time_point<std::chrono::system_clock, std::chrono::duration<double>>')
                  __os << __t;
                  ~~~~ ^  ~~~

If you change the type def Representation to an integer or unsigned integer type, the code compiles.

System Info:

OS: Ubuntu 22.04 LTS
Clang-Version: 15.0.7

Here is a link with the code that produces the error at Compiler Explorer. The error is still present in the newest available Clang version (17.0.1) at Compiler explorer.

@cor3ntin cor3ntin added libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. and removed new issue labels Jan 18, 2024
@EugeneZelenko EugeneZelenko added the format C++20 std::format or std::print, and anything related to them label Jan 18, 2024
@mordante mordante self-assigned this Jan 18, 2024
@jwakely
Copy link
Contributor

jwakely commented Jan 19, 2024

This is a bug in libstdc++ headers, not Clang. This should be closed.

You need to be aware that Clang on Compiler Explorer uses libstdc++ unless you use -stdlib=libc++

@HirthammerAllTerra
Copy link
Author

HirthammerAllTerra commented Jan 19, 2024

This is a bug in libstdc++ headers, not Clang. This should be closed.

You need to be aware that Clang on Compiler Explorer uses libstdc++ unless you use -stdlib=libc++

Thanks for clarifying this. I wasn't aware of it. For reference, here is the related bug report for libstdc++.

@jwakely
Copy link
Contributor

jwakely commented Jan 19, 2024

compiler-explorer/compiler-explorer#3682 has a good explanation.

@mordante
Copy link
Member

Thanks @jwakely

@EugeneZelenko EugeneZelenko added the invalid Resolved as invalid, i.e. not a bug label Jan 19, 2024
@EugeneZelenko EugeneZelenko closed this as not planned Won't fix, can't repro, duplicate, stale Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
format C++20 std::format or std::print, and anything related to them invalid Resolved as invalid, i.e. not a bug libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

No branches or pull requests

5 participants