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

[libc++][format] Should operator<<(thread::id) care about fmtflags in C++23? #62073

Closed
JMazurkiewicz opened this issue Apr 11, 2023 · 4 comments
Assignees
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@JMazurkiewicz
Copy link
Contributor

Repro:

#include <cassert>
#include <format>
#include <sstream>
#include <thread>

using namespace std;

int main() {
  auto id = this_thread::get_id();
  const auto s1 = format("{}", id);
  ostringstream stream;
  stream << id;
  const auto s2 = stream.str(); // This is "text representation".
  assert(s2 == s1);             // Ok.

  stream.str("");
  stream << hex << id;
  const auto s3 =
      stream.str(); // Should this be the same "text representation"?
  assert(s3 == s1); // Currently, it is not.
}

Build:

PS D:\libcxx-playground> clang -std=c++2b -fexperimental-library -Iinclude\c++\v1 -llib\c++ "-llib\windows\clang_rt.builtins-x86_64" .\test.cpp
PS D:\libcxx-playground> .\a.exe
Assertion failed: s3 == s1, file .\test.cpp, line 20

The question is: should operator<<(thread::id) even care about fmtflags? It seems to me that since P2693R1 (partially implemented in 88622aa) the text representation is not longer "unspecified" and should always be the same, no matter what the fmtflags/locale/precision are.

CC: @mordante

@EugeneZelenko EugeneZelenko added libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. and removed new issue labels Apr 11, 2023
@JMazurkiewicz JMazurkiewicz changed the title [libc++][format] Should operator<<(thead::id) care about fmtflags in C++23? [libc++][format] Should operator<<(thread::id) care about fmtflags in C++23? Apr 11, 2023
@mordante mordante self-assigned this Apr 12, 2023
@mordante
Copy link
Member

This is an interesting question since in this example the output of operator<< is not identical either. I haven't checked, but I'm quite sure that was a requirement before this change. I will look into this.

@mordante
Copy link
Member

mordante commented May 7, 2023

Based on the wording prior to P2693R1 this requirement was true for operator<< too. I had a quick look at all major implementations and I expect them all the have the same issue. I will test further at another time.

@mordante
Copy link
Member

@mordante
Copy link
Member

This has been merged 1c1edd1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

No branches or pull requests

3 participants