Dear Maintainer,
* What led up to the situation?
When defining a simple module in which a std::string is exported the program
compiles correctly but segfaults when it's run. When (instead of a
std::string) objects like std::vector<double> or std::ifstream are exported
the segfault isn't observed.
* What exactly did you do (or not do) that was effective (or
ineffective)?
I defined the following module (mod.cc):
module;
#include <string>
export module mod;
export std::string modstr{ "hello" };
and the source file (main.cc) defining main():
#include <iostream>
import mod;
int main()
{
std::cout << modstr << '\n';
}
These files were compiled and linked calling:
g++ --std=c++20 -Wall -O2 -fmodules-ts -c -o mod.o mod.cc
g++ --std=c++20 -Wall -O2 -fmodules-ts -c -o main.o main.cc
g++ main.o mod.o
* What was the outcome of this action?
Compilation and linking succeeded, but when calling ./a.out the output was:
Segmentation fault
* What outcome did you expect instead?
Output to the std output stream of the line
hello
Additional information:
When defining and exporting (and using in main()), e.g.,
std:vector<double> array{ 1, 2, 3 } or std::ifstream str{ "mod.cc } no
segfault was observed.
I found GCC Bugzilla – Bug 99569, where a module exports a function
returning a std::string, which program also segfaults, but apparently the
segfault is already encountered when defining a plain std::string module
object, and doesn't require an exported function