llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Sort function behaving incorrectly.

Open edfvogel opened this issue 5 years ago • 3 comments

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.

edfvogel avatar Oct 16 '21 00:10 edfvogel

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.

dwblaikie avatar Oct 16 '21 02:10 dwblaikie

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.

edfvogel avatar Oct 16 '21 01:10 edfvogel

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.

dwblaikie avatar Oct 16 '21 01:10 dwblaikie