小编Fel*_*lli的帖子

g++ 9.1 更新后 std::stable_sort 出现问题

从 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)

其中connsstd::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)

c++ g++ std c++17

5
推荐指数
1
解决办法
147
查看次数

标签 统计

c++ ×1

c++17 ×1

g++ ×1

std ×1