<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/137031>137031</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Strange compile error with std::print, std::filesystem::path and libremidi.hpp in a header unit
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
RoqueDeicide
</td>
</tr>
</table>
<pre>
## Versions
OS: Windows 10 22H2
LLVM: 20.1.0
## Setup
Inside the project folder I've cloned [libremidi](https://github.com/celtera/libremidi.git) into "libremidi" sub-folder and checked out tag `v5.2.0`
I've created the following files:
`lrm.h++`
```cpp
#include <libremidi/libremidi.hpp>
```
`main.c++`
```cpp
import "lrm.h++"; // (1)
import std;
int main(int,char*[])
{
std::filesystem::path p{}; // (2)
std::print("Test"); // (3)
return 0;
}
```
## Compilation
I use the following commands to compile `lrm.pcm`, `std.pcm` and `main.exe` respectively:
```console
clang++ -std=c++26 -O3 "-cxx-isystemC:\\Program Files\\LLVM\\include\\c++\\v1" -isystem libremidi\include -fmodule-header=user -xc++-header lrm.h++ -o lrm.pcm
```
```console
clang++ -c -std=c++26 -O3 -isystem "C:\\Program Files\\LLVM\\include\\c++\\v1" -isystem libremidi\include "C:\\Program Files\\LLVM\\share\\libc++\\v1\\std.cppm" -fmodule-output=std.pcm -Wno-include-angled-in-module-purview -Wno-reserved-module-identifier -o std.o
```
```console
clang++ -std=c++26 -O3 main.c++ -isystem "C:\\Program Files\\LLVM\\include\\c++\\v1" -isystem libremidi\include -L "C:\\Program Files\\LLVM\\lib" -fprebuilt-module-path=. std.pcm -fmodule-file=lrm.pcm -o main.exe
```
## Error
The following is printed out when executing the last command:
```console
main.c++:2:1: warning: the implementation of header units is in an experimental phase [-Wexperimental-header-units]
2 | import "lrm.h++";
| ^
In module 'std' imported from main.c++:4:
C:\Program Files\LLVM\include\c++\v1\__format\format_functions.h:425:10: error: no matching function for call to
'__vformat_to'
425 | return std::__vformat_to(std::move(__out_it), __fmt, __args);
| ^~~~~~~~~~~~~~~~~
C:\Program Files\LLVM\include\c++\v1\__format\format_functions.h:455:8: note: in instantiation of function template
specialization 'std::__1::vformat_to<std::__1::back_insert_iterator<std::__format::__output_buffer<char>>>'
requested here
455 | std::vformat_to(__buffer.__make_output_iterator(), __fmt, __args);
| ^
C:\Program Files\LLVM\include\c++\v1\print:259:23: note: in instantiation of function template specialization
'std::__1::vformat<void>' requested here
259 | string __str = std::vformat(__fmt, __args);
| ^
C:\Program Files\LLVM\include\c++\v1\print:321:12: note: in instantiation of function template specialization
'std::__print::__vprint_unicode_windows<void>' requested here
321 | __print::__vprint_unicode_windows(__stream, __fmt, __args, __write_nl, __print::__is_terminal(__stream));
| ^
C:\Program Files\LLVM\include\c++\v1\print:335:14: note: in instantiation of function template specialization
'std::__print::__vprint_unicode<void>' requested here
335 | __print::__vprint_unicode(__stream, __fmt.get(), std::make_format_args(__args...), false);
| ^
C:\Program Files\LLVM\include\c++\v1\print:345:8: note: in instantiation of function template specialization
'std::__1::print<>' requested here
345 | std::print(stdout, __fmt, std::forward<_Args>(__args)...);
| ^
main.c++:9:7: note: in instantiation of function template specialization 'std::__1::print<>' requested here
9 | std::print("Test");
| ^
C:\Program Files\LLVM\include\c++\v1\__format\format_functions.h:406:30: note: candidate template ignored: deduced type
'basic_string_view<...>' of 2nd parameter does not match adjusted type 'basic_string_view<...>' of argument [with
_OutIt = __libcpp_remove_reference_t<back_insert_iterator<__output_buffer<char>> &>, _CharT = char, _FormatOutIt =
std::__1::back_insert_iterator<std::__format::__output_buffer<char>>]
406 | _LIBCPP_HIDE_FROM_ABI _OutIt __vformat_to(_OutIt __out_it,
| ^
1 warning and 1 error generated.
```
## Other details
If any one of the lines in `main.c++`, that are marked with a comment, is removed, compilation succeeds. Same happens, if import of a header unit is replaced `#include`, or if a normal module is used instead.
I've read in #130057, that `-fmodules-reduced-bmi` could address the issue, so I've adjusted the first 2 commands to be:
```console
clang++ -std=c++26 -O3 "-cxx-isystemC:\\Program Files\\LLVM\\include\\c++\\v1" -isystem libremidi\include -fmodule-header=user -xc++-header lrm.h++ -fmodules-reduced-bmi -o lrm.pcm
```
```console
clang++ -c -std=c++26 -O3 -isystem "C:\\Program Files\\LLVM\\include\\c++\\v1" -isystem libremidi\include "C:\\Program Files\\LLVM\\share\\libc++\\v1\\std.cppm" -fmodule-output=std.pcm -Wno-include-angled-in-module-purview -Wno-reserved-module-identifier -fmodules-reduced-bmi -o std.o
```
However, trying to compile `main.c++` leads to a different error:
```console
fatal error: file 'lrm.pcm' is not a valid precompiled module file: file doesn't start with AST file magic
1 error generated.
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsWdtu27rSfhrmZmBBpiwfLnzh2A0aoAstVovVS4EWRxZXJVKLpJzmv_iffYMHyY7rJm132w1sbMNIdCCHw-8bzsnMGHGQiGuS35J8d8N6Wyu9_lP90-MORSk43uwVf1wTmhGawV-ojVDSkHTz9j3JNvBRSK4eDExToPQ1JenmzZu__nBvaJpMk5SkG_cNs9-j7TuSbu6lERzB1gidVn9jaaFSDUcN94QujghloyRyIPltI_YaW8EFyXeELmtrO0OyDaF3hN4dhK37fVKqltC7EhuLmhF6N85JDsISugIhrQJC6UkYpWD6_SSuyiSHssbyE3JQvQXLDkDm6TFPaJKSudvEoJhGZpF71SvVNOpByANUokGvVboh87TRbVITeuu-fq77679l1wUwhCybniOQbHum05niddeR7NX53HDdMiGT8hnhou2Utn6zZ2pQSrJbCKABocspoavATBxvLCfZbXwkLbh1CF0KaQndljXThG6CicSZizB45SduSLbxGDwai22475itoXPjFju3-NnqdFj9NLvTfqklofQDGusUpis_LX5Os7Nxtkbbawlp1Hyxu8QrWN1WtZ1omBVKOiKhN3jBX6nalkluwCp33YkGIRLZla0TRrfugbE8PvAmM_CBn9E90mg6LK04YvM4GkPkRkmjGiTppmyYPARWYOK3v4t00jlM3maOuUn5-fNEBDC3TlK-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