如何使用 Godbolt(编译器资源管理器)测试 C++ 模块?

Rum*_*rak 11 c++ c++20 c++-modules compiler-explorer

为了在 C++20 中使用自编模块提出问题或演示错误/功能,能够使用Matt Godbolt 的编译器资源管理器会很棒。

例子:

test.cpp(模块测试):

export module test;

export template<typename T>
void do_something(const T&)
{
}
Run Code Online (Sandbox Code Playgroud)

编译 clang++ -std=c++20 -stdlib=libc++ -fmodules -c -Xclang -emit-module-interface -o test.pcm test.cpp

主.cpp:

import test;

int main() {
    do_something(7);
}
Run Code Online (Sandbox Code Playgroud)

编译 clang++ -std=c++20 -stdlib=libc++ -fmodules -fimplicit-modules -fimplicit-module-maps -fprebuilt-module-path=. main.cpp

问:有没有办法用编译器资源管理器来做到这一点?

Atu*_*hra 6

目前你不能。典型的模块示例需要多个源文件。例如。在你的例子中,main.cpp 和 test.cpp。目前 GodBolt 不支持此功能。我尝试使用 Godbolt 上的原始 github 内容进行构建。但这不起作用。我已经打开了这个请求。另请参阅这个似乎正在处理中的持续请求。