Open
Description
The reproduction step doesn't fit into an issue description. I've created a tiny project to showcase the bug: https://github.com/SidneyCogdill/clangd_modules_bug_showcase
git clone https://github.com/SidneyCogdill/clangd_modules_bug_showcase.git
Audit the code before opening it in your editor because it's good security practice, it's a tiny project and shouldn't be hard.
Basically:
- module
unique_fd
requiresunique_wrapper
as an dependency:
// unique_fd.cpp
module;
#include <print>
export module unique_fd;
import unique_wrapper;
export struct UniqueFd { ... };
// unique_wrapper.cpp
module;
#include <functional>
#include <stdexcept>
#include <type_traits>
export module unique_wrapper;
export template <typename Handle> requires(...)
struct UniqueWrapper { ... };
- When
unique_fd
is used inmy_app
,unique_wrapper
has to be explicitly imported beforeunique_fd
, otherwise clangd will fail to compileunique_fd
:
module;
#include <print>
export module my_app;
import unique_wrapper; // <- This is required to make clangd successfully compile `unique_fd`.
import unique_fd;
clang can compile the program successfully, but clangd will complain "Module XXX not found`. more importantly it will point at whatever the first import statement is at rather than the problematic module. One can only obtain useful information from the log output.
clangd version:
~> clangd-21 --version
Ubuntu clangd version 21.0.0 (++20250501084208+9b1051281e43-1~exp1~20250501084221.26)
Features: linux+grpc
Platform: x86_64-pc-linux-gnu
arguments:
clangd \
--compile-commands-dir=<relative path to build folder> \
--experimental-modules-support \
--header-insertion=never \
--background-index \
-j=6 \
--pch-storage=disk