<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3544: format-arg-store::args is unintentionally not exposition-only</title>
<meta property="og:title" content="Issue 3544: format-arg-store::args is unintentionally not exposition-only">
<meta property="og:description" content="C++ library issue. Status: C++23">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3544.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#C++23">C++23</a> status.</em></p>
<h3 id="3544"><a href="lwg-defects.html#3544">3544</a>. <code><i>format-arg-store</i>::args</code> is unintentionally not exposition-only</h3>
<p><b>Section:</b> 28.5.8.2 <a href="https://wg21.link/format.arg.store">[format.arg.store]</a> <b>Status:</b> <a href="lwg-active.html#C++23">C++23</a>
 <b>Submitter:</b> Casey Carter <b>Opened:</b> 2021-04-22 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>3
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++23">C++23</a> status.</p>
<p><b>Discussion:</b></p>
<p>
Despite the statement in 28.5.8.3 <a href="https://wg21.link/format.args">[format.args]</a>/1:
</p>
<blockquote><p>
An instance of <code>basic_format_args</code> provides access to formatting arguments. Implementations should
optimize the representation of <code>basic_format_args</code> for a small number of formatting arguments.
[<i>Note 1:</i> For example, by storing indices of type alternatives separately from values and packing
the former. &mdash; <i>end note</i>]
</p></blockquote>
<p>
<code>make_format_args</code> and <code>make_wformat_args</code> are specified to return an object whose type is
a specialization of the exposition-only class template <code><i>format-arg-store</i></code> which has a public
non-static data member that is an <code>array</code> of <code>basic_format_arg</code>. In order to actually
"optimize the representation of <code>basic_format_args</code>" an implementation must internally avoid using
<code>make_format_args</code> (and <code>make_wformat_args</code>) and instead use a different mechanism to type-erase
arguments. <code>basic_format_args</code> must still be convertible from <code><i>format-arg-store</i></code> as
specified, however, so internally <code>basic_format_args</code> must support both the bad/slow standard mechanism
and a good/fast internal-only mechanism for argument storage.
<p/>
While this complicated state of affairs is technically implementable, it greatly complicates the implementation
of <code>&lt;format&gt;</code> with no commensurate benefit. Indeed, naive users may make the mistake of thinking
that e.g. <code>vformat(fmt, make_format_args(args...))</code> is as efficient as <code>format(fmt, args...)</code> &mdash;
that's what the "<i>Effects:</i> Equivalent to" in 28.5.5 <a href="https://wg21.link/format.functions">[format.functions]</a>/2 implies &mdash; and
inadvertently introduce performance regressions. It would be better for both implementers and users if
<code><i>format-arg-store</i></code> had no public data members and its member <code>args</code> were made exposition-only.
</p>

<p><i>[2021-05-10; Reflector poll]</i></p>

<p>
Priority set to 3.
Tim: "The current specification of <code>make_format_args</code> depends on
<code><i>format-arg-store</i></code> being an aggregate,
which is no longer true with this PR."
</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>
This wording is relative to <a href="https://wg21.link/n4885">N4885</a>.
</p>

<ol>
<li><p>Modify 28.5.1 <a href="https://wg21.link/format.syn">[format.syn]</a>, header <code>&lt;format&gt;</code> synopsis, as indicated:</p>

<blockquote>
<pre>
[&hellip;]
<i>// 28.5.8.2 <a href="https://wg21.link/format.arg.store">[format.arg.store]</a>, class template format-arg-store</i>
template&lt;class Context, class... Args&gt; <del>struct</del><ins>class</ins> <i>format-arg-store</i>; <i>// exposition only</i>
[&hellip;]
</pre>
</blockquote>
</li>

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

<blockquote>
<pre>
namespace std {
  template&lt;class Context, class... Args&gt;
  <del>struct</del><ins>class</ins> <i>format-arg-store</i> { <i>// exposition only</i>
    array&lt;basic_format_arg&lt;Context&gt;, sizeof...(Args)&gt; args; <ins><i>// exposition only</i></ins>
  };
}
</pre>
</blockquote>
</li>
</ol>
</blockquote>
<p><i>[2021-05-18; Tim updates wording.]</i></p>


<p><i>[2021-05-20; Reflector poll]</i></p>

<p>
Set status to Tentatively Ready after six votes in favour during reflector poll.
</p>

<p><i>[2021-06-07 Approved at June 2021 virtual plenary. Status changed: Voting &rarr; WP.]</i></p>



<p id="res-3544"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/n4885">N4885</a>.
</p>

<ol>
<li><p>Modify 28.5.1 <a href="https://wg21.link/format.syn">[format.syn]</a>, header <code>&lt;format&gt;</code> synopsis, as indicated:</p>

<blockquote>
<pre>
[&hellip;]
<i>// 28.5.8.2 <a href="https://wg21.link/format.arg.store">[format.arg.store]</a>, class template format-arg-store</i>
template&lt;class Context, class... Args&gt; <del>struct</del><ins>class</ins> <i>format-arg-store</i>; <i>// exposition only</i>

template&lt;class Context = format_context, class... Args&gt;
  <i>format-arg-store</i>&lt;Context, Args...&gt;
    make_format_args(const Args&amp;... <ins>fmt_</ins>args);
[&hellip;]
</pre>
</blockquote>
</li>

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

<blockquote>
<pre>
namespace std {
  template&lt;class Context, class... Args&gt;
  <del>struct</del><ins>class</ins> <i>format-arg-store</i> { <i>// exposition only</i>
    array&lt;basic_format_arg&lt;Context&gt;, sizeof...(Args)&gt; args; <ins><i>// exposition only</i></ins>
  };
}
</pre>
<p>-1- An instance of <code><i>format-arg-store</i></code> stores formatting arguments.</p>
<pre>
template&lt;class Context = format_context, class... Args&gt;
  <i>format-arg-store</i>&lt;Context, Args...&gt; make_format_args(const Args&amp;... <ins>fmt_</ins>args);
</pre>
<blockquote>
<p>
-2- <i>Preconditions</i>: The type <code>typename Context::template formatter_type&lt;T<sub>i</sub>&gt;</code>
meets the <i>Formatter</i> requirements (28.5.6.1 <a href="https://wg21.link/formatter.requirements">[formatter.requirements]</a>)
for each <code>T<sub>i</sub></code> in <code>Args</code>.
<p/>
-3- <i>Returns</i>: <del></del>
<ins>An object of type <code><i>format-arg-store</i>&lt;Context, Args...&gt;</code>
whose <code>args</code> data member is initialized with</ins>
<code>{basic_format_arg&lt;Context&gt;(<ins>fmt_</ins>args)...}</code>.
</p>
</blockquote>
</blockquote>
</li>
</ol>





</body>
</html>
