Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
SidneyCogdill opened this issue May 9, 2025 · 3 comments
Open
Labels
clang:modules C++20 modules and Clang Header Modules clangd

Comments

@SidneyCogdill
Copy link

SidneyCogdill commented May 9, 2025

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
@EugeneZelenko EugeneZelenko added clangd clang:modules C++20 modules and Clang Header Modules and removed new issue labels May 9, 2025
@llvmbot
Copy link
Member

llvmbot commented May 9, 2025

@llvm/issue-subscribers-clangd

Author: Sidney Cogdill (SidneyCogdill)

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 &lt;print&gt;

export module unique_fd;

import unique_wrapper;

export struct UniqueFd { ... };
// unique_wrapper.cpp
module;

#include &lt;functional&gt;
#include &lt;stdexcept&gt;
#include &lt;type_traits&gt;

export module unique_wrapper;

export template &lt;typename Handle&gt; 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 &lt;print&gt;

export module my_app;

import unique_wrapper; // &lt;- 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:

~&gt; 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=&lt;relative path to build folder&gt; \
    --experimental-modules-support \
    --header-insertion=never \
    --background-index \
    -j=6 \
    --pch-storage=disk

@llvmbot
Copy link
Member

llvmbot commented May 9, 2025

@llvm/issue-subscribers-clang-modules

Author: Sidney Cogdill (SidneyCogdill)

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 &lt;print&gt;

export module unique_fd;

import unique_wrapper;

export struct UniqueFd { ... };
// unique_wrapper.cpp
module;

#include &lt;functional&gt;
#include &lt;stdexcept&gt;
#include &lt;type_traits&gt;

export module unique_wrapper;

export template &lt;typename Handle&gt; 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 &lt;print&gt;

export module my_app;

import unique_wrapper; // &lt;- 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:

~&gt; 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=&lt;relative path to build folder&gt; \
    --experimental-modules-support \
    --header-insertion=never \
    --background-index \
    -j=6 \
    --pch-storage=disk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:modules C++20 modules and Clang Header Modules clangd
Projects
None yet
Development

No branches or pull requests

4 participants
@EugeneZelenko @llvmbot @SidneyCogdill and others