Search code examples
c++c++20c++-modulescompiler-explorer

How to test C++ modules with godbolt (compiler explorer)?


In order to ask questions about or demonstrate bugs/features with self-written modules in C++20, it would be great to be able to use Matt Godbolt's compiler explorer.

Example:

test.cpp (module test):

export module test;

export template<typename T>
void do_something(const T&)
{
}

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

main.cpp:

import test;

int main() {
    do_something(7);
}

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

Q: Is there a way to do this with compiler explorer?


Solution

  • Currently you cannot. A typical modules example needs multiple source files. Eg. in your case, main.cpp & test.cpp. This is not currently supported in GodBolt. I tried building using the raw github content on Godbolt. But it does not work. I have opened this request. Also see this ongoing request which seemingly is under process.