https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104202
Bug ID: 104202 Summary: when defining a std::string in a module implementation file using -O2 g++ segfaults Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: f.b.brokken at rug dot nl Target Milestone: --- Created attachment 52274 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52274&action=edit Output of the compiler (segfaults) when compiling 'mod.cc' Using the following main file (main.cc): --------------------------------- #include <iostream> import mod; int main() { std::cout << modstr << '\n'; } --------------------------------- defining the module mod interface in a separate file (zfirst.cc): --------------------------------- module; #include <string> export module mod; export extern std::string modstr; --------------------------------- and initializing modstr in a separate module implementation file (mod.cc): ------------------------------- module; #include <string> module mod; std::string modstr{ "hello" }; ------------------------------- compiles OK when using the following compiler options: --std=c++20 -Wall -Wextra -fno-strict-aliasing -fwrapv -fmodules-ts but when adding the option -O2 the compiler segfaults (compiler output is attached). Omitting the -Wextra -fno-strict-aliasing -fwrapv options makes no difference. The compilation was performed on a (yesterday) updated Debian testing distribution using g++ (Debian 12-20211217-1) 12.0.0 20211217 (experimental) [master r12-6027-g774269aa4b9] Copyright (C) 2021 Free Software Foundation, Inc. If you need any additional information, please let me know. Kind regards, Frank.