Skip to content

[Modules][libc++] Using <filesystem> with -fmodules -fcxx-modules triggers missing‑import errors #138683

@devajithvs

Description

@devajithvs

When compiling a minimal program using <filesystem> with -fmodules -fcxx-modules using libc++ built from upstream, the compiler fails with module import errors for time_point and _FilesystemClock.

Compiling the below code:

#include <filesystem>

int main() {
    std::filesystem::file_time_type::clock::now();
    return 0;
}

with

$LLVM_INSTALL/bin/clang++ \
-stdlib=libc++ -nostdinc++ \
-isystem $LLVM_INSTALL/include/x86_64-unknown-linux-gnu/c++/v1 \
-isystem $LLVM_INSTALL/include/c++/v1 \
-fmodules -fcxx-modules \
reproducer.cpp

Raises:

reproducer.cpp:4:22: error: missing '#include <__chrono/time_point.h>'; 'time_point' must be defined before it is used
    4 |     std::filesystem::file_time_type::clock::now();
      |                      ^
.../include/c++/v1/__chrono/time_point.h:34:28: note: definition here is not reachable
   34 | class _LIBCPP_TEMPLATE_VIS time_point {
      |                            ^
reproducer.cpp:4:38: error: missing '#include <__chrono/file_clock.h>'; '_FilesystemClock' must be defined before it is used
    4 |     std::filesystem::file_time_type::clock::now();
      |                                      ^
.../include/c++/v1/__chrono/file_clock.h:49:8: note: definition here is not reachable
   49 | struct _FilesystemClock {
      |        ^
2 errors generated.

Similar failures/warnings were first observed with Apple’s libc++ module map on MacOS with Sonoma 14.6.1 and XCode 15.4 and clang-1500.3.9.4 - See a similar reproducer with AppleClang: root-project/root#16494 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions