Skip to content

Strange compile error with std::print, std::filesystem::path and libremidi.hpp in a header unit #137031

Open
@RoqueDeicide

Description

@RoqueDeicide

Versions

OS: Windows 10 22H2
LLVM: 20.1.0

Setup

Inside the project folder I've cloned libremidi into "libremidi" sub-folder and checked out tag v5.2.0
I've created the following files:
lrm.h++

#include <libremidi/libremidi.hpp>

main.c++

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:

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
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
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:

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:

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
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:

fatal error: file 'lrm.pcm' is not a valid precompiled module file: file doesn't start with AST file magic
1 error generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:modulesC++20 modules and Clang Header Modules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions