https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91007
Bug ID: 91007 Summary: stable_sort segfaults on -O3 Product: gcc Version: 9.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: barry.revzin at gmail dot com Target Milestone: --- Reduced from StackOverflow (https://stackoverflow.com/q/56779605/2069064): #include <vector> #include <algorithm> int main() { using V = std::vector<int>; std::vector<V> conns{ V{0,2}, V{0,2}, V{0,2}, }; std::stable_sort(conns.begin(), conns.end(), [](const V& a, const V& b){ return a[0] < b[0]; } ); } On gcc 9.1, compiled with -O3, this segfaults. With -O2 and under, it's fine. On gcc 8.3, it's fine.