This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of WP status.

4061. Should std::basic_format_context be default-constructible/copyable/movable?

Section: 28.5.6.7 [format.context] Status: WP Submitter: Jiang An Opened: 2024-03-24 Last modified: 2024-07-08

Priority: Not Prioritized

View all other issues in [format.context].

View all issues with WP status.

Discussion:

Per 28.5.6.7 [format.context], it seems that std::basic_format_context has a default constructor that is effectively defaulted, which means that it is default constructible if and only if OutIt is default constructible. Currently only libstdc++ makes it conditionally default constructible, while libc++ and MSVC STL (together with fmtlib) make it never default constructible.

It seems that basic_format_context objects are supposed to be created by the implementation in some internal way, and user codes are only supposed to modify existing basic_format_context objects during formatting.

[2024-05-08; Reflector poll]

Set status to Tentatively Ready after six votes in favour during reflector poll.

[St. Louis 2024-06-29; Status changed: Voting → WP.]

Proposed resolution:

This wording is relative to N4971.

  1. Modify 28.5.6.7 [format.context] as indicated:

    namespace std {
      template<class Out, class charT>
      class basic_format_context {
        basic_format_args<basic_format_context> args_; // exposition only
        Out out_;                                      // exposition only
    
        basic_format_context(const basic_format_context&) = delete;
        basic_format_context& operator=(const basic_format_context&) = delete;
      public:
        using iterator = Out;
        using char_type = charT;
        template<class T> using formatter_type = formatter<T, charT>;
        
        basic_format_arg<basic_format_context> arg(size_t id) const noexcept;
        std::locale locale();
        
        iterator out();
        void advance_to(iterator it);
      };
    }