[Bug libstdc++/111685] Segfault while sorting on array element address

2023-10-06 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111685 --- Comment #12 from Fedor Chelnokov --- Related discussion: https://stackoverflow.com/q/77224270/7325599

[Bug libstdc++/111685] Segfault while sorting on array element address

2023-10-05 Thread knoepfel at fnal dot gov via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111685 Kyle Knoepfel changed: What|Removed |Added Resolution|--- |INVALID Status|UNCONFIRMED

[Bug libstdc++/111685] Segfault while sorting on array element address

2023-10-04 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111685 --- Comment #10 from Fedor Chelnokov --- It seems that both libc++ and MS STL implement std::sort without a temporary object passed to cmp, because they are fine with compiling the following code in constant expression (where unrelated pointers

[Bug libstdc++/111685] Segfault while sorting on array element address

2023-10-04 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111685 --- Comment #9 from Jonathan Wakely --- The sketches above are completely untested (and incorrect) but just demonstrating the ideas.

[Bug libstdc++/111685] Segfault while sorting on array element address

2023-10-04 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111685 --- Comment #8 from Jonathan Wakely --- The standard only defines sorting in terms of comparisons on "every iterator i pointing to the sequence", which seems to preclude using a temporary object on the stack that is outside the sequence. That

[Bug libstdc++/111685] Segfault while sorting on array element address

2023-10-03 Thread xry111 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111685 Xi Ruoyao changed: What|Removed |Added CC||xry111 at gcc dot gnu.org --- Comment #7

[Bug libstdc++/111685] Segfault while sorting on array element address

2023-10-03 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111685 --- Comment #6 from Andrew Pinski --- https://github.com/gcc-mirror/gcc/blob/d9375e490072d1aae73a93949aa158fcd2a27018/libstdc%2B%2B-v3/include/bits/stl_algo.h#L1814 is exactly where a temp copy is created. Is that valid for std::sort, I am

[Bug libstdc++/111685] Segfault while sorting on array element address

2023-10-03 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111685 --- Comment #5 from Andrew Pinski --- With -fsanitize=address we get this at runtime: ``` = ==1==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fc69190003c at pc

[Bug libstdc++/111685] Segfault while sorting on array element address

2023-10-03 Thread knoepfel at fnal dot gov via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111685 Kyle Knoepfel changed: What|Removed |Added Status|RESOLVED|UNCONFIRMED Resolution|INVALID

[Bug libstdc++/111685] Segfault while sorting on array element address

2023-10-03 Thread knoepfel at fnal dot gov via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111685 --- Comment #3 from Kyle Knoepfel --- @Andrew Pinski, yes I surmised as much. My difficulty, though, is in understanding if this is the correct behavior according to the standard's specification of std::sort, which presumably is reasonably

[Bug libstdc++/111685] Segfault while sorting on array element address

2023-10-03 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111685 Andrew Pinski changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution|---

[Bug libstdc++/111685] Segfault while sorting on array element address

2023-10-03 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111685 --- Comment #1 from Andrew Pinski --- IIRC this happens if the cmp is defined incorrectly.