[cfe-dev] Make command line support for C++20 module uniform with GCC

chuanqi.xcq via cfe-dev cfe-dev at lists.llvm.org
Mon Oct 25 01:57:08 PDT 2021


Hi all,

   Recently I am playing with C++20 modules and I found that the command line support of GCC
is much better than Clang. Here is an example:

```C++
// say_hello.cpp
module;
#include <iostream>
#include <string_view>
export module Hello;
export void SayHello
  (std::string_view const &name)
{
  std::cout << "Hello " << name << "!\n";
}
// main.cpp
#include <string_view>
import Hello;
int main() {
  SayHello("world");
  return 0;
}
```

To compile the example, in gcc we need:
```
g++ -std=c++20 -fmodules-ts say_hello.cpp main.cpp 
```

And in clang, we need:
```
clang++ -std=c++20 -fmodules-ts -Xclang -emit-module-interface -c say_hello.cpp -o Hello.pcm
clang++ -std=c++20 -fmodules-ts -fprebuilt-module-path=. main.cpp say_hello.cpp
```

Yeah, in clang we need to another line to emit module interface explicitly and another option
to tell the prebuilt-module-path. And in GCC, this happens by default, when GCC find it is compiling
a c++20 module, it would generate the module interface automatically to the path:
```
gcm.cache/filename.gcm
```
It would create `gcm.cache` in case it doesn't exist. 

And GCC would search prebuilt module interface in `gcm.cache` automatically.

It looks much more friendly to me. The intention of this mail is to ask if you think it is the right direction
to make the clang's command line support for c++20 module more like GCC. The different I see now includes:
- Generate prebuilt module interface automatically. (And generate it to a specific directory automatically)
- Have a default value for prebuilt module path.

I am wondering if any one more familiar with the clang's command line and file system would love to 
support this (I am not so familiar with it). Although It may take more time, I would love to support if others are busy.

Thanks,
Chuanqi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20211025/13bc7938/attachment.html>


More information about the cfe-dev mailing list