Skip to content

fmt/chrono.h: use of deprecated std::codecvt class template which is deprecated as of C++20 #2408

Description

@JoeLoser

As of C++20, the class template speciailization std::codecvt<char32_t, char, std::mbstate_t> is deprecated in favor of using char8_t: std::codecvt<char32_t, char8_t, std::mbstate_t>.

The line causing this warning is chrono.h. This warning was noticed when using llvm12 with libc++ in C++20 mode (c++2a) as libc++ marks the class template as deprecated per the C++20 spec.

Some notes regarding a potential patch for this:

  • The do_write function currently returns a std::string. One approach to solving this problem is to change this do_write function to work with char or char8_t consistently based on compiler support for char8_t. This would mean that the return type is now std::string or std::basic_string<char8_t>. Consider the following snippet:
#if defined(__cpp_char8_t)
  using char_t = char8_t;
#else
  using char_t = char;
#endif
  auto&& os = std::basic_ostringstream<char_t>();

// Other code as-is

auto& f =
      std::use_facet<std::codecvt<code_unit, char_t, std::mbstate_t>>(loc);
  • The call to std::time_put notably should use char still rather than char_t. There is no overload for std::time_put<char8_t> which is an oversight I think when char8_t got proposed. It can be added in a future paper which I may propose.

Note: I recommend working with char_t as described above throughout to avoid UB. While char and char8_t are the same size, alignment, etc, it is UB to reinterpret_cast different types (e.g. a std::string to a std::basic_string<char8_t>) for example as returned from the stringstream.str() call.

With the return type of do_write being a std::string or std::basic_string<char8_t> now, I don't yet know how this affects the calling code copies the string to the output iterator.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions