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

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

Section: 22.14.6.7 [format.context] Status: New Submitter: Jiang An Opened: 2024-03-24 Last modified: 2024-03-26

Priority: Not Prioritized

View all other issues in [format.context].

View all issues with New status.

Discussion:

Per 22.14.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.

Proposed resolution:

This wording is relative to N4971.

  1. Modify 22.14.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);
      };
    }