13

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?

Barry
  • 286,269
  • 29
  • 621
  • 977
Rumburak
  • 3,416
  • 16
  • 27

1 Answers1

5

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.

Atul Mehra
  • 106
  • 1
  • 4
  • @AfulMehra looks like the first request link is broken. – Sonic78 Feb 25 '21 at 22:15
  • Thanks for pointing out..Corrected link by removing the fullstop at end. Here's the link again anyway - https://github.com/compiler-explorer/compiler-explorer/issues/2166. – Atul Mehra Feb 27 '21 at 09:35
  • For today problem [is not multiple sources](https://godbolt.org/z/1KzMesx93), but more [like missing per-compiled modules](https://godbolt.org/z/s1erjzKeb). – Marek R Jul 04 '22 at 16:02