<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3975: Specializations of basic_format_context should not be permitted</title>
<meta property="og:title" content="Issue 3975: Specializations of basic_format_context should not be permitted">
<meta property="og:description" content="C++ library issue. Status: WP">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3975.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#WP">WP</a> status.</em></p>
<h3 id="3975"><a href="lwg-defects.html#3975">3975</a>. Specializations of <code>basic_format_context</code> should not be permitted</h3>
<p><b>Section:</b> 28.5.6.7 <a href="https://wg21.link/format.context">[format.context]</a> <b>Status:</b> <a href="lwg-active.html#WP">WP</a>
 <b>Submitter:</b> Brian Bi <b>Opened:</b> 2023-08-13 <b>Last modified:</b> 2024-04-02</p>
<p><b>Priority: </b>3
</p>
<p><b>View all other</b> <a href="lwg-index.html#format.context">issues</a> in [format.context].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#WP">WP</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The current wording allows users to specialize <code>std::basic_format_context</code>. However, an implementation is not 
likely to accept a program that uses the library in a way that would instantiate such a specialization, because 
28.5.6.7 <a href="https://wg21.link/format.context">[format.context]</a> does not provide a complete description of the interface that such a specialization 
would need to have (e.g., it does not provide a means to initialize the exposition-only <code>args_</code> member). Since the 
library was not designed to be able to work with user specializations of <code>std::basic_format_context</code>, declaring 
such specializations should be explicitly disallowed.
</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">

<p>
This wording is relative to <a href="https://wg21.link/N4958" title=" Working Draft, Programming Languages — C++">N4958</a>.
</p>

<ol>

<li><p>Modify the 28.5.6.7 <a href="https://wg21.link/format.context">[format.context]</a> as indicated:</p>

<blockquote>
<p>
-1- An instance of <code>basic_format_context</code> holds formatting state consisting of the formatting arguments and
the output iterator.
<p/>
<ins>-?- The behavior of a program that adds specializations of <code>basic_format_context</code> is undefined.</ins>
<p/>
-2- <code>Out</code> shall model <code>output_iterator&lt;const charT&amp;&gt;</code>.
</p>
</blockquote>

</li>
</ol>
</blockquote>

<p><i>[2023-09-23; Daniel comments and provides improved wording]</i></p>

<p>
During the reflector discussion, Dietmar pointed out that the constraint can in principle be checked statically (e.g. when the 
Library creates or refers to an instantiation of <code>basic_format_context</code>), so we can reduce the rather draconian consequence of
"undefined behaviour" to "ill-formed, no diagnostics required". Furthermore, the new wording also adds the same constraint to
<code>basic_format_parse_context</code> as suggested by Tim. This is needed, since only one public constructor is specified, but
that specification does not allow to construct an object a non-zero <code>num_args_</code> or with the type information necessary 
for the <code>check_dynamic_spec*</code> functions, so the library has an unspecified way to realize this.
</p>

<p><i>[2023-10-30; Reflector poll]</i></p>

<p>
Set priority to 3 after reflector poll.
</p>

<p><i>[Kona 2023-11-07; move to Ready]</i></p>


<p><i>[Tokyo 2024-03-23; Status changed: Voting &rarr; WP.]</i></p>



<p id="res-3975"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/N4958" title=" Working Draft, Programming Languages — C++">N4958</a>.
</p>

<blockquote class="note">
<p>
[<i>Drafting note:</i> The suggested wording form is borrowed from exactly the same wording form used for <code>allocator_traits</code>.]
</p>
</blockquote>

<ol>

<li><p>Modify 28.5.6.7 <a href="https://wg21.link/format.context">[format.context]</a> as indicated:</p>

<blockquote>
<p>
-1- An instance of <code>basic_format_context</code> holds formatting state consisting of the formatting arguments and
the output iterator.
<p/>
<ins>-?- If a program declares an explicit or partial specialization of <code>basic_format_context</code>, the program is ill-formed,
no diagnostic required.</ins>
<p/>
-2- <code>Out</code> shall model <code>output_iterator&lt;const charT&amp;&gt;</code>.
</p>
</blockquote>

</li>

<li><p>Modify 28.5.6.6 <a href="https://wg21.link/format.parse.ctx">[format.parse.ctx]</a> as indicated:</p>

<blockquote>
<p>
-1- An instance of <code>basic_format_parse_context</code> holds the format string parsing state consisting of the format
string range being parsed and the argument counter for automatic indexing.
<p/>
<ins>-?- If a program declares an explicit or partial specialization of <code>basic_format_parse_context</code>, the program is ill-formed,
no diagnostic required.</ins>
</p>
</blockquote>

</li>
</ol>





</body>
</html>
