I used g++ -fmodules-ts -std=c++23
to compile a formatted "Hello Module!" but got SIGSEGV fault by calling std::format
. If I didn't import <iostream>
and then replace std::cout << format;
with printf(format.data());
everything works well.
import <iostream>;
import <format>;
int main()
{
std::string format = std::format("Hello {}!\n", "Module");
std::cout << format;
return 0;
}
GDB backtrace:
Thread 1 received signal SIGSEGV, Segmentation fault.
0x00007ff6039f8d60 in std::basic_string_view<char, std::char_traits<char> >::begin (this=0x5ff800) at D:/msys64/mingw64/include/c++/13.2.0/string_view:190
190 { return this->_M_str; }
(gdb) bt
#0 0x00007ff6039f8d60 in std::basic_string_view<char, std::char_traits<char> >::begin (this=0x5ff800) at D:/msys64/mingw64/include/c++/13.2.0/string_view:190
#1 0x00007ff6039f1a31 in std::basic_format_parse_context<char>::basic_format_parse_context (this=0x5ff958, __fmt="Hello {}!", __num_args=18446744073709551615)
at D:/msys64/mingw64/include/c++/13.2.0/format:206
#2 0x00007ff6039f1b20 in std::__format::_Scanner<char>::_Scanner (this=0x5ff950, __str="Hello {}!", __nargs=18446744073709551615)
at D:/msys64/mingw64/include/c++/13.2.0/format:3434
#3 0x00007ff6039f1b74 in std::__format::_Formatting_scanner<std::__format::_Sink_iter<char>, char>::_Formatting_scanner (this=0x5ff950, __fc=..., __str="Hello {}!")
at D:/msys64/mingw64/include/c++/13.2.0/format:3548
#4 0x00007ff603a04686 in std::__format::__do_vformat_to<std::__format::_Sink_iter<char>, char, std::basic_format_context<std::__format::_Sink_iter<char>, char> > (
__out=..., __fmt="Hello {}!", __args=std::format_args with 1 argument, __loc=0x0) at D:/msys64/mingw64/include/c++/13.2.0/format:3650
#5 0x00007ff603a077f9 in std::vformat_to<std::__format::_Sink_iter<char> > (__args=std::format_args with 1 argument, __fmt="Hello {}!", __out=...)
at D:/msys64/mingw64/include/c++/13.2.0/format:3681
#6 std::vformat (__fmt="Hello {}!", __args=std::format_args with 1 argument) at D:/msys64/mingw64/include/c++/13.2.0/format:3708
#7 0x00007ff603a075b3 in std::format<char const (&) [7]> (__fmt=...) at D:/msys64/mingw64/include/c++/13.2.0/format:3743
#8 0x00007ff6039f1bd3 in main () at .\module.cpp:6
__nargs
being UINT64_MAX seems to be weird.
I wonder if it's a bug of module feature, or, how to fixed this.