Sort function behaving incorrectly.
| Bugzilla Link | 52192 |
| Resolution | INVALID |
| Resolved on | Oct 15, 2021 19:40 |
| Version | 11.0 |
| OS | All |
| Attachments | This is the test program. |
| CC | @dwblaikie,@mclow |
Extended Description
There seems to be an issue with the libc++ sort function. The attached program runs correctly with the default library, but fails with libc++. The expected output is 0.
Here is a cut/paste from a cygwin session:
$ clang++ -std=c++11 -o a.out -w t.cpp
VogelEd@XLB3502Q4E ~ $ ./a.out got back 0
VogelEd@XLB3502Q4E ~ $ clang++ -std=c++11 -o a.out -stdlib=libc++ -w t.cpp
VogelEd@XLB3502Q4E ~ $ ./a.out got back 260
Other environments (such as Visual Studio 2019) also emit 0.
Oh, no worries - appreciate the bug, but yeah - generally it'll be a matter of whether C++ requires the consistency/a particular answer or not. In this case I don't think it does require that.
I only point this out because the output is different from g++ and Visual Studio. If you are happy with that difference, please close this.
I'm sorry, I should have noted that in my post.
Thank you very much for the quick response.
Could you explain further why you believe the behavior of this program is required to produce '0'?
Seems to me it'd be acceptable for an implementation to decrement the end iterator in its implementation, and then maybe increment it later, which could produce the result you're seeing.
It's not obvious to me that this program must produce 0.