[llvm] r215986 - ADT: Avoid using std::equal in ArrayRef::equals
Duncan P. N. Exon Smith
dexonsmith at apple.com
Tue Aug 19 12:30:35 PDT 2014
> On 2014-Aug-19, at 11:04, David Blaikie <dblaikie at gmail.com> wrote:
>
> On Tue, Aug 19, 2014 at 11:04 AM, David Blaikie <dblaikie at gmail.com> wrote:
>> On Tue, Aug 19, 2014 at 9:36 AM, Duncan P. N. Exon Smith
>> <dexonsmith at apple.com> wrote:
>>> Author: dexonsmith
>>> Date: Tue Aug 19 11:36:21 2014
>>> New Revision: 215986
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=215986&view=rev
>>> Log:
>>> ADT: Avoid using std::equal in ArrayRef::equals
>>>
>>> MSVC's STL has a bug in `std::equal()`: it asserts on nullptr iterators,
>>> causing a block revert in r215981. This works around that by re-writing
>>> `ArrayRef::equals()` to do the work itself.
>>
>> Adding a comment might be nice, describing what we're working around,
>> so we can switch it back later?
Was the comment in this commit not clear enough? What do you think
would be better?
> Oh, and you could add a unit test, if you like.
r216008. Thanks!
>
>>
>>>
>>> Modified:
>>> llvm/trunk/include/llvm/ADT/ArrayRef.h
>>>
>>> Modified: llvm/trunk/include/llvm/ADT/ArrayRef.h
>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/ArrayRef.h?rev=215986&r1=215985&r2=215986&view=diff
>>> ==============================================================================
>>> --- llvm/trunk/include/llvm/ADT/ArrayRef.h (original)
>>> +++ llvm/trunk/include/llvm/ADT/ArrayRef.h Tue Aug 19 11:36:21 2014
>>> @@ -145,7 +145,13 @@ namespace llvm {
>>> bool equals(ArrayRef RHS) const {
>>> if (Length != RHS.Length)
>>> return false;
>>> - return std::equal(begin(), end(), RHS.begin());
>>> + // Don't use std::equal(), since it asserts in MSVC on nullptr iterators.
>>> + for (auto L = begin(), LE = end(), R = RHS.begin(); L != LE; ++L, ++R)
>>> + // Match std::equal() in using == (instead of !=) to minimize API
>>> + // requirements of ArrayRef'ed types.
>>> + if (!(*L == *R))
>>> + return false;
>>> + return true;
>>> }
>>>
>>> /// slice(n) - Chop off the first N elements of the array.
>>>
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list