Skip to content
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

Clangd cannot find function implementation in C++20 module implementation unit #57674

Closed
vagran opened this issue Sep 10, 2022 · 4 comments
Closed
Labels
clang:modules C++20 modules and Clang Header Modules clangd

Comments

@vagran
Copy link

vagran commented Sep 10, 2022

File a.cppm:

export module A;

export void
TestFunc(); // <<< Finding implementation from here

File a.cpp:

module A;

void
TestFunc()
{
}

Placing cursor on TestFunc() declaration in cppm and trying to find its implementation in VSCode with clangd connected gives no result.

compile_commands.json:

[
{
"directory":"/home/artyom/projects/asio-awaitable-module-problem-demo/build",
"file":"../a.cppm",
"output":"a.pcm",
"command":"/opt/clang-latest/bin/clang++ -c -std=c++20 -stdlib=libc++ -Wall -Werror -g -O0 -fmodules -fimplicit-modules -fmodules-cache-path=modules-cache -DMODULES -fretain-comments-from-system-headers --precompile -x c++-module ../a.cppm -o a.pcm -Xclang -emit-module-interface"
}
,
{
"directory":"/home/artyom/projects/asio-awaitable-module-problem-demo/build",
"file":"../a.cpp",
"output":"a.o",
"command":"/opt/clang-latest/bin/clang++ -c -std=c++20 -stdlib=libc++ -Wall -Werror -g -O0 -fmodules -fimplicit-modules -fmodules-cache-path=modules-cache -DMODULES -fretain-comments-from-system-headers -fmodule-file=a.pcm ../a.cpp -o a.o"
}
]

Clangd log:

V[22:45:33.175] <<< {"id":8,"jsonrpc":"2.0","method":"textDocument/implementation","params":{"position":{"character":4,"line":3},"textDocument":{"uri":"file:///home/artyom/projects/asio-awaitable-module-problem-demo/a.cppm"}}}

I[22:45:33.175] <-- textDocument/implementation(8)
V[22:45:33.175] ASTWorker running Implementations on version 1 of /home/artyom/projects/asio-awaitable-module-problem-demo/a.cppm
I[22:45:33.175] --> reply:textDocument/implementation(8) 0 ms
V[22:45:33.175] >>> {"id":8,"jsonrpc":"2.0","result":[]}

Full log attached.

Repository with sample project available here.

$ /opt/clang-latest/bin/clangd --version
clangd version 16.0.0 (https://github.com/llvm/llvm-project.git ee761374f797a47919ec8f9f49f9b8b1b20573e8)
Features: linux
Platform: x86_64-unknown-linux-gnu
@vagran
Copy link
Author

vagran commented Sep 10, 2022

Just noticed this line in the log:

E[22:45:27.705] Failed to scan baseline of /home/artyom/projects/asio-awaitable-module-problem-demo/a.cpp: failed BeginSourceFile

I already reported half-year ago about that.

Also noticed that finding declaration from implementation works fine. Placing cursor in .cpp file and jumping to declaration in .cppm. So some index for this file is built.

@EugeneZelenko EugeneZelenko added clangd clang:modules C++20 modules and Clang Header Modules and removed new issue labels Sep 10, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 10, 2022

@llvm/issue-subscribers-clang-modules

@sam-mccall
Copy link
Collaborator

Sorry, clangd doesn't have any modules support.
Clang does, and clangd allows flags to be passed through to clang so some things may work or appear to work. But it would need significant design/implementation effort to get it into a usable state.

clangd/clangd#1293 is the tracking bug for this, but nobody is currently working on it :-(

@ChuanqiXu9
Copy link
Member

@vagran BTW, your implementation asio_impl module is not good. Since C++20 Modules doesn't use the clang's module map now. You can the related things https://clang.llvm.org/docs/StandardCPlusPlusModules.html.

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

5 participants