<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63421>63421</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[libc++] <format> has uninitialized variables when formatting a string with zero arguments.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
BlamKiwi
</td>
</tr>
</table>
<pre>
When formatting a string with 0 arguments, `std::format("Hello World!");` , GCC 13.1 complains there are maybe uninitialized variables. This causes spurious warnings/errors with appropriate build flags enabled.
```
[build] /workspaces/include/c++/v1/__format/format_functions.h:71:65: error: '<anonymous>' may be used uninitialized [-Werror=maybe-uninitialized]
[build] 71 | return _VSTD::__format_arg_store<_Context, _Args...>(__args...);
```
The culprit is in the constructor of `__format_arg_store`. When constructing an argument store of 0 size, it never writes a value to `__packed_format_arg_store::__types_`. A quick fix is to give `__packed_format_arg_store::__types_` a default value of 0.
```
template <class _Context, size_t N>
struct __packed_format_arg_store {
__basic_format_arg_value<_Context> __values_[N];
uint64_t __types_ = 0;
};
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVMtu6zYQ_ZrxZhBBIvWwF1r4EbdAgbtp0CwFShpLbGhS5cO-ydcXlJxHe3MDXECQSWtmeGbO4RHOyUET1VDsoDisRPCjsfVOifMf8ipXremf68eRNJ6MPQvvpR5QoPM2Lq7Sj5iisEM4k_YO2B6hTJ3vgW-Bb5ccYGtg7HdSyuCjsaoHlgFjwDbAd1CmGNN-2-8x40mGnTlPSkjt0I9kCYUlPIvnljBoqaWXQskX6vEirBStIpfgwygddiI4cuimYKUJDq_CaqkHB-xI1hrrFrRimqyZrBSesA1S9XhSYnBIOhbrE4T0AOn29i7T27Nsi92cAsUBgR2vxj65SXQUz5C6U6EnYMcO2G5-jpcM2LFpXqdwXBbNKejOS6NdMgLfVhnwbVkA3-KMMy6AVcD3Qhv9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