<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3251: Are std::format alignment specifiers applied to string arguments?</title>
<meta property="og:title" content="Issue 3251: Are std::format alignment specifiers applied to string arguments?">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3251.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++20">C++20</a> status.</em></p>
<h3 id="3251"><a href="lwg-defects.html#3251">3251</a>. Are <code>std::format</code> alignment specifiers applied to string arguments?</h3>
<p><b>Section:</b> 28.5.2 <a href="https://wg21.link/format.string">[format.string]</a> <b>Status:</b> <a href="lwg-active.html#C++20">C++20</a>
 <b>Submitter:</b> Richard Smith <b>Opened:</b> 2019-08-02 <b>Last modified:</b> 2021-02-25</p>
<p><b>Priority: </b>2
</p>
<p><b>View all other</b> <a href="lwg-index.html#format.string">issues</a> in [format.string].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++20">C++20</a> status.</p>
<p><b>Discussion:</b></p>
<p>
We are told:
</p>
<blockquote><p>
Formatting of objects of arithmetic types and <code>const void*</code> is done as if by 
calling <code>to_chars</code> (unless otherwise specified) and copying the output through 
the output iterator of the format context with additional padding and adjustments 
as specified by the format specifiers.
</p></blockquote>
<p>
&hellip; but there is no corresponding rule for strings. Is an alignment specifier 
intended to be applied to strings or not? The wording as-is is ambiguous.
<p/>
(The above also doesn't cover formatting <code>void*</code> or <code>std::nullptr_t</code>. 
Presumably at least those two should have the relevant adjustments applied to them!)
<p/>
The wording never actually anywhere says that the <code>basic_format_args</code> are in 
any way involved in the formatting process, or how formatting actually happens. 
(The wording doesn't say that <code>basic_format_arg::handle::format</code> is ever 
called, for example.)
<p/>
<b>Victor Zverovich:</b>
<p/>
An alignment specifier is intended to be applied to strings as well, <code>void*</code> and 
<code>std::nullptr_t</code> are converted into <code>const void*</code> when constructing 
<code>basic_format_arg</code>.
<p/>
The wording for <code>vformat</code> and similar functions says that <code>basic_format_args</code> is involved:
</p>
<blockquote><p>
<i>Returns:</i> A string object holding the character representation of formatting arguments
 provided by <code>args</code> formatted according to specifications given in <code>fmt</code>.
</p></blockquote>
<p>
but I admit that it is hand-wavy. Perhaps we could add something along the lines of
</p>
<blockquote><p>
For each replacement field referring to the argument with index <code>(arg-id) i</code>, the 
<code>basic_format_arg</code> object referring to the argument is obtained via <code>args.get(i)</code> 
and the <code>parse</code> and <code>format</code> functions of the <code>formatter</code> specialization 
for the underlying argument type are called to parse the format specification and format the value.
</p></blockquote>
<p>
to clarify how we format <code>args</code> (<code>basic_format_args</code>).
</p>

<p><i>[2019-08-21 Priority set to 2 based on reflector discussion]</i></p>


<p><i>[2019-08-21; Victor Zverovich suggests wording]</i></p>

<p><i>[2020-02 Status to Immediate on Thursday night in Prague.]</i></p>



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

<ol>
<li><p>Modify 28.5.2.2 <a href="https://wg21.link/format.string.std">[format.string.std]</a> as indicated:</p>

<blockquote>
<p>
-3- <ins>The <i>align</i> specifier applies to all argument types.</ins> The meaning of the 
various alignment options is as specified in Table [tab:format.align]. 
[<i>Example:</i> [&hellip;
</p>
</blockquote>
</li>
</ol>




</body>
</html>
