Код: Выделить всё
#include
import animal;
int main() {
auto s = makeSound();
printf("%s", s.c_str());
return 0;
}
< /code>
и интерфейс модуля: < /p>
module;
#include
export module animal;
import :sound;
export std::string makeSound() {
return makeSound_Impl();
}
< /code>
и модуль реализации модуля: < /p>
module;
#include
module animal:sound;
std::string makeSound_Impl() {
return "Wroooarrh";
}
< /code>
Программа составлена с: < /p>
g++ -fmodules-ts -g -std=c++20 animal_sound.cpp -c -o animal_sound.o
g++ -fmodules-ts -g -std=c++20 animal.cpp -c -o animal.o
g++ -fmodules-ts -g -std=c++20 animal.o animal_sound.o main.cpp -o main.exe
< /code>
версия компилятора: < /p>
g++ --version
g++ (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1
< /code>
Программа сбои на basic_string: < /p>
Program received signal SIGSEGV, Segmentation fault.
0x00005555555566c2 in std::__cxx11::basic_string::_M_data (this=0xd00aa32b9e55bf00) at /usr/include/c++/13/bits/basic_string.h:223
223 { return _M_dataplus._M_p; }
(gdb) bt
#0 0x00005555555566c2 in std::__cxx11::basic_string::_M_data (this=0x0) at /usr/include/c++/13/bits/basic_string.h:223
#1 0x0000555555556f3a in std::__cxx11::basic_string::c_str (this=0x7fffffffda50) at /usr/include/c++/13/bits/basic_string.h:2584
#2 0x0000555555556ea6 in main () at main.cpp:7
Код: Выделить всё
module;
#include
export module animal;
export std::string makeSound() {
return "Sound!";
}
< /code>
Все работает нормально (программа не сбоя). Я делаю что -то не так, или это проблема компилятора? Если нет включения Код: Выделить всё
module;
#include
export module animal:sound;
export std::string makeSound() {
return "Wroooarrh";
}
< /code>
module;
// #include // Adding include makes program crash
export module animal;
export import :sound;
сообщил об ошибке на GCC Bugzilla: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111447
Подробнее здесь: https://stackoverflow.com/questions/771 ... tion-units