aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/ADT/StringRef.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/ADT/StringRef.h')
-rw-r--r--include/llvm/ADT/StringRef.h27
1 files changed, 12 insertions, 15 deletions
diff --git a/include/llvm/ADT/StringRef.h b/include/llvm/ADT/StringRef.h
index 1f413e8..778fa10 100644
--- a/include/llvm/ADT/StringRef.h
+++ b/include/llvm/ADT/StringRef.h
@@ -51,12 +51,6 @@ namespace llvm {
/// The length of the string.
size_t Length;
- // Workaround PR5482: nearly all gcc 4.x miscompile StringRef and std::min()
- // Changing the arg of min to be an integer, instead of a reference to an
- // integer works around this bug.
- static size_t min(size_t a, size_t b) { return a < b ? a : b; }
- static size_t max(size_t a, size_t b) { return a > b ? a : b; }
-
// Workaround memcmp issue with null pointers (undefined behavior)
// by providing a specialized version
static int compareMemory(const char *Lhs, const char *Rhs, size_t Length) {
@@ -124,7 +118,7 @@ namespace llvm {
}
// copy - Allocate copy in Allocator and return StringRef to it.
- template <typename Allocator> StringRef copy(Allocator &A) {
+ template <typename Allocator> StringRef copy(Allocator &A) const {
char *S = A.template Allocate<char>(Length);
std::copy(begin(), end(), S);
return StringRef(S, Length);
@@ -146,7 +140,7 @@ namespace llvm {
/// is lexicographically less than, equal to, or greater than the \p RHS.
int compare(StringRef RHS) const {
// Check the prefix for a mismatch.
- if (int Res = compareMemory(Data, RHS.Data, min(Length, RHS.Length)))
+ if (int Res = compareMemory(Data, RHS.Data, std::min(Length, RHS.Length)))
return Res < 0 ? -1 : 1;
// Otherwise the prefixes match, so we only need to check the lengths.
@@ -237,7 +231,7 @@ namespace llvm {
/// \returns The index of the first occurrence of \p C, or npos if not
/// found.
size_t find(char C, size_t From = 0) const {
- for (size_t i = min(From, Length), e = Length; i != e; ++i)
+ for (size_t i = std::min(From, Length), e = Length; i != e; ++i)
if (Data[i] == C)
return i;
return npos;
@@ -254,7 +248,7 @@ namespace llvm {
/// \returns The index of the last occurrence of \p C, or npos if not
/// found.
size_t rfind(char C, size_t From = npos) const {
- From = min(From, Length);
+ From = std::min(From, Length);
size_t i = From;
while (i != 0) {
--i;
@@ -353,8 +347,11 @@ namespace llvm {
typename std::enable_if<!std::numeric_limits<T>::is_signed, bool>::type
getAsInteger(unsigned Radix, T &Result) const {
unsigned long long ULLVal;
+ // The additional cast to unsigned long long is required to avoid the
+ // Visual C++ warning C4805: '!=' : unsafe mix of type 'bool' and type
+ // 'unsigned __int64' when instantiating getAsInteger with T = bool.
if (getAsUnsignedInteger(*this, Radix, ULLVal) ||
- static_cast<T>(ULLVal) != ULLVal)
+ static_cast<unsigned long long>(static_cast<T>(ULLVal)) != ULLVal)
return true;
Result = ULLVal;
return false;
@@ -396,8 +393,8 @@ namespace llvm {
/// exceeds the number of characters remaining in the string, the string
/// suffix (starting with \p Start) will be returned.
StringRef substr(size_t Start, size_t N = npos) const {
- Start = min(Start, Length);
- return StringRef(Data + Start, min(N, Length - Start));
+ Start = std::min(Start, Length);
+ return StringRef(Data + Start, std::min(N, Length - Start));
}
/// Return a StringRef equal to 'this' but with the first \p N elements
@@ -425,8 +422,8 @@ namespace llvm {
/// number of characters remaining in the string, the string suffix
/// (starting with \p Start) will be returned.
StringRef slice(size_t Start, size_t End) const {
- Start = min(Start, Length);
- End = min(max(Start, End), Length);
+ Start = std::min(Start, Length);
+ End = std::min(std::max(Start, End), Length);
return StringRef(Data + Start, End - Start);
}