From 8c20a93bac4f9631d180ff9ec5b562ed2673d78c Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Tue, 19 Aug 2014 16:36:21 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215986 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/ArrayRef.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/llvm/ADT/ArrayRef.h b/include/llvm/ADT/ArrayRef.h index 44400d591da..0351cf5bb4c 100644 --- a/include/llvm/ADT/ArrayRef.h +++ b/include/llvm/ADT/ArrayRef.h @@ -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.