I have a strange issue when I'm trying to use std::list with modules.
Here is my simple code:
module_b.cpp:
module;
import <list>;
import <iostream>;
export module module_b;
export void test_b()
{
std::cout << "Hello!\n";
std::list<int> b; // <- this cause the issue
}
main.cpp:
import module_b;
int main()
{
test_b();
}
And here is how I try to build it with g++ 11.2.0 on cygwin:
$ g++.exe -std=c++20 -fmodules-ts -c -x c++-system-header list
$ g++.exe -std=c++20 -fmodules-ts -c -x c++-system-header iostream
$ g++ -std=c++20 -fmodules-ts module_b.cpp main.cpp
In module imported at main.cpp:1:1:
module_b: error: failed to read compiled module: Bad file data
module_b: note: compiled module file is ‘gcm.cache/module_b.gcm’
module_b: fatal error: returning to the gate for a mechanical issue
compilation terminated.
And it works when I comment-out std::list<int> b; in module_b:
$ g++ -std=c++20 -fmodules-ts module_b.cpp main.cpp
$ ./a.exe
Hello!
So what is the reason? How can I use list when using modules?