从 gcc/g++ 8.1更新到9.1并重新编译我的代码后,它的大部分测试都失败了。因此,进行了一些挖掘,我发现这std::stable_sort就是问题所在。
事实证明,我调用的大多数调用std::stable_sort都是不必要的,也就是说,调用std::sort就足够了。因此,我在可能的情况下进行了替换,并且关于这些代码段的测试再次成功。
现在,我只有一个电话 std::stable_sort
void MshReader::determinePhysicalEntitiesRange() {
// conns is not empty
std::stable_sort(this->conns.begin(), this->conns.end(),
[=](const auto& a, const auto& b){
return a[this->index] < b[this->index];
}
);
// acess some values of conns
}
Run Code Online (Sandbox Code Playgroud)
其中conns是std::vector<std::vector<int>>存储元素连接性的。排序是基于列index完成的,它的值在类头中分配,并且所有std::vector<int>在conns 中都有该条目。
另一个值得一提的事实是,在调试版本中(使用编译器标志“-g”,不使用“-O3”)所有测试都成功。
此外,在发布版本(使用标志“-O3”,不使用“-g”)时,通过在调用 之前和之后打印conns的值std::stable_sort,我发现conns被破坏了。
前
row:
0: 0 2 0 1
1: 0 …Run Code Online (Sandbox Code Playgroud)