问题描述
双重编辑:仅在使用 libstdc++ 时,同一代码上可能存在的错误和 Clang 段错误导致 GCC 段错误。起初我不知道这是因为编译器段错误并不是特别有用,但是使用标志 -stdlib=libc++,您可以使用 clang 来很好地编译此代码。使用 libstdc++ 时的 Clang 段错误是一个单独的问题,这个问题特别关注 GCC。
可以在相关的错误报告 #101184 中找到进一步简化的 GCC 示例。如果您对解决方案感兴趣,我建议您查看错误报告。
在下面的代码墙中,有几个小的 c++20 模块在使用包含的命令构建时会导致 GCC-11 编译器段错误。
我试着在下面的文字中解释这个问题,但这个问题有点挑剔,我发现理解它的最好方法是稍微玩一下。
其中两个模块,“filler1”和“filler2”不导出任何东西,只在导出模块指令之前包含几个标准库。因为实际上没有从这两者中导出任何内容,所以我希望它不会对程序行为产生任何影响,但出于某种原因,如果两者都包含在内,则会出现 GCC 段错误。如果以任何顺序删除任何一个,程序都可以正常编译。此外,这些填充模块中包含的标准库是特殊的,如果删除“功能”或“内存”,即使它们没有在整个程序中的任何地方使用,它也可以很好地编译。
还有 testmod1 模块,它只包含“向量”。但与填充模块不同的是,要发生段错误,必须在导出模块指令之后定义任意类型的向量,可以导出也可以不导出。
拼图的最后一个可能也是最奇怪的部分是 testmodp 模块。除了之前存在的所有微粒之外,还有一个模板结构:template
注意:因为这个错误非常特殊,一个 5 文件示例是我可以在不改变行为的情况下将其提取到的最小文件,我也不允许包含链接,所以如果你想测试它,复制带有相应名称的所有内容。如果这里有什么不对的地方,请随时在评论中联系 (:
感谢阅读!
文件“filler1.cc”
module;
#include <memory>
export module filler1;
文件“filler2.cc”
module;
#include <memory>
#include <functional>
export module filler2;
文件“testmodp.cc”
module;
#include <functional>
#include <vector>
#include <variant>
export module testmodp;
export template<typename... Ts> // must be a template with args used in Meta_variant for error to occur
struct testmodp{
typedef std::variant<Ts...> Meta_variant;
std::vector<Meta_variant> Meta_gs;
};
文件“testmod1.cc”
module;
#include <vector>
export module testmod1;
export struct testasdf{
std::vector<int> testvec;
};
文件“test_impl.cc”
module;
#include <memory>
import filler1;
import filler2;
import testmodp;
import testmod1;
export module test_impl;
export namespace test_impl {
void test_init(){
new testmodp<int,float>();
}
};
GCC 要运行的命令
mkdir build
g++ -std=c++2a -fmodules-ts -c testmod1.cc -o build/testmod1.pcm
g++ -std=c++2a -fmodules-ts -c filler1.cc -o build/filler1.pcm
g++ -std=c++2a -fmodules-ts -c filler2.cc -o build/filler2.pcm
g++ -std=c++2a -fmodules-ts -c testmodp.cc -o build/testmodp.pcm
g++ -std=c++2a -fmodules-ts -c test_impl.cc -o build/test_impl.pcm
GCC 内部编译器错误:
module_test/test3/test_impl.cc:11:8: internal compiler error: in write_location,at cp/module.cc:15605
11 | export module test_impl;
| ^~~~~~
0x1797368 internal_error(char const*,...)
???:0
0x67f8f9 fancy_abort(char const*,int,char const*)
???:0
0x7652d9 trees_out::core_vals(tree_node*)
???:0
0x768e78 trees_out::tree_value(tree_node*)
???:0
0x761e9c trees_out::tree_node(tree_node*)
???:0
0x763cd6 trees_out::write_var_def(tree_node*)
???:0
0x764fd5 module_state::write_cluster(elf_out*,depset**,unsigned int,depset::hash&,unsigned int*,unsigned int*)
???:0
0x767ec9 module_state::write(elf_out*,cpp_reader*)
???:0
0x768d86 finish_module_processing(cpp_reader*)
???:0
0x713d1b c_parse_final_cleanups()
???:0
Please submit a full bug report,Please include the complete backtrace with any bug report.
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)