On Mon, Apr 11, 2016 at 11:15 PM, Martin Probst <mar...@probst.io> wrote:
>> > Was/is the 2 correct then? (if it was next(rbegin, 2) that'd be
>> > equivalent
>> > to prev(end, 3), yes?)
>>
>> I think it is from looking at the test case, looping in martin to see
>> whether I'm right :)
>
>
> At that point in the code, we have [..., PrePrev = '@', Prev = 'SomeToken']
> and CurrentToken = 'Whatever', CurrentToken has not been appended to the
> list yet. So moving two from the end should be correct.
>
> I don't quite understand why rend() actually works in my code with the unit
> tests. Is that some unintentional side effect of its implementation leaking?
> I think I explicitly confirmed that my test does test what it's trying to
> test.

The implementation of std::list in common standard libraries is
actually cyclic. So ++end() brings you back to the beginning of the
list. This made the test work magically :)

Dropping off the end of the list is of course undefined behavior and
there may be non-cyclic implementations where this doesn't work. Debug
STL also threw assertion failures, which made me aware of this issue
in the first place.

It's also interesting that due to the cyclic nature of std::list, asan
(or valgrind) cannot detect this kind of bug.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to