<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/149404>149404</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Spurious compilation error using <format> and import std
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kamrann
</td>
</tr>
</table>
<pre>
This issue has been plaguing me for a while, I've finally managed to reduce it somewhat - not minimal, but the only dependency now is libcxx.
This is perhaps related to the known limitation of #include/import ordering with std, but it's a bit different; it requires both `import std` and `#include <format>` to repro, but it shows up even with the #include encapsulated into a module, and regardless of the import order in the consuming translation unit.
[Compiler Explorer](https://godbolt.org/z/r8To7WY1s) link.
Reproducing for me on both latest trunk and latest release.
```
// mod_a.cppm
export module mod_a;
import std;
auto something() -> void
{
auto const buf = "a";
auto x = std::format("{}", buf[0]);
}
```
```
// mod_b.cppm
module;
#include <format>
export module mod_b;
```
```
// source.cpp
import std;
// note: import order not relevant
import mod_a;
import mod_b;
auto func() -> void
{
auto const buf = "a";
auto x = std::format("{}", buf[0]);
}
auto dies() -> void
{
std::string_view weird;
auto x = std::format("{}", weird);
}
```
Output:
```
In module 'std' imported from /app/source.cpp:2:
/opt/compiler-explorer/clang-trunk-20250717/bin/../include/c++/v1/__format/format_functions.h:99:30: error: call to implicitly-deleted default constructor of 'formatter<std::__1::basic_string_view<char, std::__1::char_traits<char>>, wchar_t>'
99 | formatter<_Tp, _CharT> __f;
| ^
/opt/compiler-explorer/clang-trunk-20250717/bin/../include/c++/v1/__format/format_functions.h:98:62: note: while substituting into a lambda expression here
98 | __parse_ = [](basic_format_parse_context<_CharT>& __ctx) {
| ^
/opt/compiler-explorer/clang-trunk-20250717/bin/../include/c++/v1/__format/format_functions.h:393:25: note: in instantiation of function template specialization 'std::__format::__compile_time_handle<wchar_t>::__enable<std::__1::basic_string_view<char>>' requested here
393 | __handle.template __enable<_Tp>();
| ^
/opt/compiler-explorer/clang-trunk-20250717/bin/../include/c++/v1/__format/format_functions.h:389:99: note: while substituting into a lambda expression here
389 | static constexpr array<__format::__compile_time_handle<_CharT>, sizeof...(_Args)> __handles_{[] {
| ^
source.cpp:16:26: note: in instantiation of template class 'std::__1::basic_format_string<wchar_t, std::__1::basic_string_view<char> &>' requested here
16 | auto x = std::format("{}", weird);
| ^
/opt/compiler-explorer/clang-trunk-20250717/bin/../include/c++/v1/__format/formatter_string.h:141:63: note: default constructor of 'formatter<std::__1::basic_string_view<char>, wchar_t>' is implicitly deleted because base class '__disabled_formatter' has a deleted default constructor
141 | struct formatter<basic_string_view<char, _Traits>, wchar_t> : __disabled_formatter {};
| ^
/opt/compiler-explorer/clang-trunk-20250717/bin/../include/c++/v1/__format/formatter.h:25:3: note: '__disabled_formatter' has been explicitly marked deleted here
25 | __disabled_formatter() = delete;
| ^
```
Note the bizarre reference to `wchar_t`.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMWEFv47oR_jX0ZRBDpmzJPvjgOBHwLi3QBih6EihpbLGhSJWk4mR_fTEUZSv7kuxrX4HdwEBkkRzOfN83M6SFc_KsEfdsc882Dwsx-NbY_bPorNB6UZnmbf_USgfSuQGhFQ4qRA29EudB6jN0CCdjQcCllQoZP8JvjOcvCCephVJv0AktztiAN2CxGWoE6cGZDi-t8HAH2njopJadULS6Gjz4FsFo9QYN9qgb1PUbaHMB6UDJqn59XbLkwJJDdAx6tK3oHVhUwo9bkYlnbS4alOykF14aDeYEjKdS12pokPFCdr2xHoxt0FIsF-lbcL6Z_JCe8dyBgEp6aOTphBa1Z-k9hWDx34O06KAyvgWWJdEarc8SELqhl7f9gKXHk7Gd8Cx9pBkBkN6a227gWnNxMPSAL6hHdyiQmRHUtejdMMYptTcgoDPNMEJPm1o8C9sodI7ipeXzMEHq8K422g0dBe2t0E6NAA1a-ogt29wfTddLhRYeX3tlLFq2eWB823rfO5YeGC8YL86mqYzyS2PPjBffGC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