Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[clangd] fails to compile the module with transitive module dependency #139189

Copy link
Copy link
Open
@SidneyCogdill

Description

@SidneyCogdill
Issue body actions

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 requires unique_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 in my_app, unique_wrapper has to be explicitly imported before unique_fd, otherwise clangd will fail to compile unique_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

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:modulesC++20 modules and Clang Header ModulesC++20 modules and Clang Header Modulesclangd

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.