mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-03 03:01:44 +00:00
Update for C++17 and fix MSVC warnings (#1694)
* Update MSVC arguments * Fix json allocator * Fix simulation diamond * Bump gtest * Remove empty varargs in unit tests * Replace test case with test suite * Remove deprecation warning in optional * Remove need for NOMIXMAX to be defined in wpilib headers
This commit is contained in:
committed by
Peter Johnson
parent
fb1239a2ad
commit
221011494d
@@ -117,6 +117,11 @@
|
||||
#ifndef LLVM_NODISCARD
|
||||
#if __cplusplus > 201402L && __has_cpp_attribute(nodiscard)
|
||||
#define LLVM_NODISCARD [[nodiscard]]
|
||||
// Detect MSVC directly, since __cplusplus still defaults to old version
|
||||
#elif _MSVC_LANG >= 201703L
|
||||
#define LLVM_NODISCARD [[nodiscard]]
|
||||
#elif _MSC_VER
|
||||
#define LLVM_NODISCARD
|
||||
#elif !__cplusplus
|
||||
// Workaround for llvm.org/PR23435, since clang 3.6 and below emit a spurious
|
||||
// error when __has_cpp_attribute is given a scoped attribute in C mode.
|
||||
@@ -236,6 +241,11 @@
|
||||
#ifndef LLVM_FALLTHROUGH
|
||||
#if __cplusplus > 201402L && __has_cpp_attribute(fallthrough)
|
||||
#define LLVM_FALLTHROUGH [[fallthrough]]
|
||||
// Detect MSVC directly, since __cplusplus still defaults to old version
|
||||
#elif _MSVC_LANG >= 201703L
|
||||
#define LLVM_FALLTHROUGH [[fallthrough]]
|
||||
#elif _MSC_VER
|
||||
#define LLVM_FALLTHROUGH
|
||||
#elif __has_cpp_attribute(gnu::fallthrough)
|
||||
#define LLVM_FALLTHROUGH [[gnu::fallthrough]]
|
||||
#elif !__cplusplus
|
||||
|
||||
@@ -352,7 +352,7 @@ protected:
|
||||
return 0;
|
||||
// +1 is required because of the strict equality.
|
||||
// For example if NumEntries is 48, we need to return 401.
|
||||
return NextPowerOf2(NumEntries * 4 / 3 + 1);
|
||||
return static_cast<unsigned>(NextPowerOf2(NumEntries * 4 / 3 + 1));
|
||||
}
|
||||
|
||||
void moveFromOldBuckets(BucketT *OldBucketsBegin, BucketT *OldBucketsEnd) {
|
||||
@@ -777,7 +777,7 @@ public:
|
||||
// Reduce the number of buckets.
|
||||
unsigned NewNumBuckets = 0;
|
||||
if (OldNumEntries)
|
||||
NewNumBuckets = std::max(64, 1 << (Log2_32_Ceil(OldNumEntries) + 1));
|
||||
NewNumBuckets = (std::max)(64, 1 << (Log2_32_Ceil(OldNumEntries) + 1));
|
||||
if (NewNumBuckets == NumBuckets) {
|
||||
this->BaseT::initEmpty();
|
||||
return;
|
||||
|
||||
@@ -265,7 +265,7 @@ template <typename T> struct DenseMapInfo<ArrayRef<T>> {
|
||||
template <> struct DenseMapInfo<hash_code> {
|
||||
static inline hash_code getEmptyKey() { return hash_code(-1); }
|
||||
static inline hash_code getTombstoneKey() { return hash_code(-2); }
|
||||
static unsigned getHashValue(hash_code val) { return val; }
|
||||
static unsigned getHashValue(hash_code val) { return static_cast<unsigned>(val); }
|
||||
static bool isEqual(hash_code LHS, hash_code RHS) { return LHS == RHS; }
|
||||
};
|
||||
|
||||
|
||||
@@ -183,7 +183,7 @@ public:
|
||||
/// Move-construct an error value. The newly constructed error is considered
|
||||
/// unchecked, even if the source error had been checked. The original error
|
||||
/// becomes a checked Success value, regardless of its original state.
|
||||
Error(Error &&Other) {
|
||||
Error(Error &&Other) noexcept {
|
||||
setChecked(true);
|
||||
*this = std::move(Other);
|
||||
}
|
||||
@@ -202,7 +202,7 @@ public:
|
||||
/// you cannot overwrite an unhandled error. The current error is then
|
||||
/// considered unchecked. The source error becomes a checked success value,
|
||||
/// regardless of its original state.
|
||||
Error &operator=(Error &&Other) {
|
||||
Error &operator=(Error &&Other) noexcept {
|
||||
// Don't allow overwriting of unchecked values.
|
||||
assertIsChecked();
|
||||
setPtr(Other.getPtr());
|
||||
|
||||
@@ -94,7 +94,7 @@ class format_object final : public format_object_base {
|
||||
int snprint_tuple(char *Buffer, unsigned BufferSize,
|
||||
index_sequence<Is...>) const {
|
||||
#ifdef _MSC_VER
|
||||
return _snprintf(Buffer, BufferSize, Fmt, std::get<Is>(Vals)...);
|
||||
return _snprintf_s(Buffer, BufferSize, BufferSize, Fmt, std::get<Is>(Vals)...);
|
||||
#else
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
|
||||
@@ -55,6 +55,11 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 26495)
|
||||
#endif
|
||||
|
||||
namespace wpi {
|
||||
|
||||
/// An opaque object representing a hash code.
|
||||
@@ -192,7 +197,7 @@ inline uint64_t hash_1to3_bytes(const char *s, size_t len, uint64_t seed) {
|
||||
uint8_t b = s[len >> 1];
|
||||
uint8_t c = s[len - 1];
|
||||
uint32_t y = static_cast<uint32_t>(a) + (static_cast<uint32_t>(b) << 8);
|
||||
uint32_t z = len + (static_cast<uint32_t>(c) << 2);
|
||||
uint32_t z = static_cast<uint32_t>(len + (static_cast<uint64_t>(c) << 2));
|
||||
return shift_mix(y * k2 ^ z * k3 ^ seed) * k2;
|
||||
}
|
||||
|
||||
@@ -568,7 +573,7 @@ public:
|
||||
// Check whether the entire set of values fit in the buffer. If so, we'll
|
||||
// use the optimized short hashing routine and skip state entirely.
|
||||
if (length == 0)
|
||||
return hash_short(buffer, buffer_ptr - buffer, seed);
|
||||
return static_cast<size_t>(hash_short(buffer, buffer_ptr - buffer, seed));
|
||||
|
||||
// Mix the final buffer, rotating it if we did a partial fill in order to
|
||||
// simulate doing a mix of the last 64-bytes. That is how the algorithm
|
||||
@@ -580,7 +585,7 @@ public:
|
||||
state.mix(buffer);
|
||||
length += buffer_ptr - buffer;
|
||||
|
||||
return state.finalize(length);
|
||||
return static_cast<size_t>(state.finalize(length));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -619,7 +624,7 @@ inline hash_code hash_integer_value(uint64_t value) {
|
||||
const uint64_t seed = get_execution_seed();
|
||||
const char *s = reinterpret_cast<const char *>(&value);
|
||||
const uint64_t a = fetch32(s);
|
||||
return hash_16_bytes(seed + (a << 3), fetch32(s + 4));
|
||||
return static_cast<size_t>(hash_16_bytes(seed + (a << 3), fetch32(s + 4)));
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
@@ -657,4 +662,8 @@ hash_code hash_value(const std::basic_string<T> &arg) {
|
||||
|
||||
} // namespace wpi
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -58,7 +58,7 @@ template <typename T, std::size_t SizeOfT> struct TrailingZerosCounter {
|
||||
// Bisection method.
|
||||
std::size_t ZeroBits = 0;
|
||||
T Shift = std::numeric_limits<T>::digits >> 1;
|
||||
T Mask = std::numeric_limits<T>::max() >> Shift;
|
||||
T Mask = (std::numeric_limits<T>::max)() >> Shift;
|
||||
while (Shift) {
|
||||
if ((Val & Mask) == 0) {
|
||||
Val >>= Shift;
|
||||
@@ -199,7 +199,7 @@ std::size_t countLeadingZeros(T Val, ZeroBehavior ZB = ZB_Width) {
|
||||
/// valid arguments.
|
||||
template <typename T> T findFirstSet(T Val, ZeroBehavior ZB = ZB_Max) {
|
||||
if (ZB == ZB_Max && Val == 0)
|
||||
return std::numeric_limits<T>::max();
|
||||
return (std::numeric_limits<T>::max)();
|
||||
|
||||
return countTrailingZeros(Val, ZB_Undefined);
|
||||
}
|
||||
@@ -240,7 +240,7 @@ template <typename T> T maskLeadingZeros(unsigned N) {
|
||||
/// valid arguments.
|
||||
template <typename T> T findLastSet(T Val, ZeroBehavior ZB = ZB_Max) {
|
||||
if (ZB == ZB_Max && Val == 0)
|
||||
return std::numeric_limits<T>::max();
|
||||
return (std::numeric_limits<T>::max)();
|
||||
|
||||
// Use ^ instead of - because both gcc and llvm can remove the associated ^
|
||||
// in the __builtin_clz intrinsic on x86.
|
||||
@@ -370,6 +370,11 @@ inline uint64_t maxUIntN(uint64_t N) {
|
||||
return UINT64_MAX >> (64 - N);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4146)
|
||||
#endif
|
||||
|
||||
/// Gets the minimum value for a N-bit signed integer.
|
||||
inline int64_t minIntN(int64_t N) {
|
||||
assert(N > 0 && N <= 64 && "integer width out of range");
|
||||
@@ -377,6 +382,10 @@ inline int64_t minIntN(int64_t N) {
|
||||
return -(UINT64_C(1)<<(N-1));
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
/// Gets the maximum value for a N-bit signed integer.
|
||||
inline int64_t maxIntN(int64_t N) {
|
||||
assert(N > 0 && N <= 64 && "integer width out of range");
|
||||
@@ -519,26 +528,26 @@ inline double Log2(double Value) {
|
||||
/// (32 bit edition.)
|
||||
/// Ex. Log2_32(32) == 5, Log2_32(1) == 0, Log2_32(0) == -1, Log2_32(6) == 2
|
||||
inline unsigned Log2_32(uint32_t Value) {
|
||||
return 31 - countLeadingZeros(Value);
|
||||
return static_cast<unsigned>(31 - countLeadingZeros(Value));
|
||||
}
|
||||
|
||||
/// Return the floor log base 2 of the specified value, -1 if the value is zero.
|
||||
/// (64 bit edition.)
|
||||
inline unsigned Log2_64(uint64_t Value) {
|
||||
return 63 - countLeadingZeros(Value);
|
||||
return static_cast<unsigned>(63 - countLeadingZeros(Value));
|
||||
}
|
||||
|
||||
/// Return the ceil log base 2 of the specified value, 32 if the value is zero.
|
||||
/// (32 bit edition).
|
||||
/// Ex. Log2_32_Ceil(32) == 5, Log2_32_Ceil(1) == 0, Log2_32_Ceil(6) == 3
|
||||
inline unsigned Log2_32_Ceil(uint32_t Value) {
|
||||
return 32 - countLeadingZeros(Value - 1);
|
||||
return static_cast<unsigned>(32 - countLeadingZeros(Value - 1));
|
||||
}
|
||||
|
||||
/// Return the ceil log base 2 of the specified value, 64 if the value is zero.
|
||||
/// (64 bit edition.)
|
||||
inline unsigned Log2_64_Ceil(uint64_t Value) {
|
||||
return 64 - countLeadingZeros(Value - 1);
|
||||
return static_cast<unsigned>(64 - countLeadingZeros(Value - 1));
|
||||
}
|
||||
|
||||
/// Return the greatest common divisor of the values using Euclid's algorithm.
|
||||
@@ -747,7 +756,7 @@ inline int64_t SignExtend64(uint64_t X, unsigned B) {
|
||||
template <typename T>
|
||||
typename std::enable_if<std::is_unsigned<T>::value, T>::type
|
||||
AbsoluteDifference(T X, T Y) {
|
||||
return std::max(X, Y) - std::min(X, Y);
|
||||
return (std::max)(X, Y) - (std::min)(X, Y);
|
||||
}
|
||||
|
||||
/// Add two unsigned integers, X and Y, of type T. Clamp the result to the
|
||||
@@ -762,7 +771,7 @@ SaturatingAdd(T X, T Y, bool *ResultOverflowed = nullptr) {
|
||||
T Z = X + Y;
|
||||
Overflowed = (Z < X || Z < Y);
|
||||
if (Overflowed)
|
||||
return std::numeric_limits<T>::max();
|
||||
return (std::numeric_limits<T>::max)();
|
||||
else
|
||||
return Z;
|
||||
}
|
||||
@@ -787,7 +796,7 @@ SaturatingMultiply(T X, T Y, bool *ResultOverflowed = nullptr) {
|
||||
// Special case: if X or Y is 0, Log2_64 gives -1, and Log2Z
|
||||
// will necessarily be less than Log2Max as desired.
|
||||
int Log2Z = Log2_64(X) + Log2_64(Y);
|
||||
const T Max = std::numeric_limits<T>::max();
|
||||
const T Max = (std::numeric_limits<T>::max)();
|
||||
int Log2Max = Log2_64(Max);
|
||||
if (Log2Z < Log2Max) {
|
||||
return X * Y;
|
||||
|
||||
@@ -23,6 +23,14 @@
|
||||
|
||||
namespace wpi {
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma warning(push)
|
||||
// Warning on NONNULL, report is not known to abort
|
||||
#pragma warning(disable : 6387)
|
||||
#pragma warning(disable : 28196)
|
||||
#pragma warning(disable : 28183)
|
||||
#endif
|
||||
|
||||
LLVM_ATTRIBUTE_RETURNS_NONNULL inline void *safe_malloc(size_t Sz) {
|
||||
void *Result = std::malloc(Sz);
|
||||
if (Result == nullptr)
|
||||
@@ -45,5 +53,9 @@ LLVM_ATTRIBUTE_RETURNS_NONNULL inline void *safe_realloc(void *Ptr, size_t Sz) {
|
||||
return Result;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -22,6 +22,12 @@
|
||||
#include <iterator>
|
||||
#include <system_error>
|
||||
|
||||
#ifdef _WIN32
|
||||
// Disable iterator deprecation warning
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4996)
|
||||
#endif
|
||||
|
||||
namespace wpi {
|
||||
namespace sys {
|
||||
namespace path {
|
||||
@@ -460,4 +466,8 @@ std::error_code widenPath(const Twine &Path8, SmallVectorImpl<wchar_t> &Path16);
|
||||
} // end namespace sys
|
||||
} // end namespace wpi
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1310,7 +1310,7 @@ template <typename R> struct result_pair {
|
||||
ValueOfRange<R> &value() { return *Iter; }
|
||||
|
||||
private:
|
||||
std::size_t Index = std::numeric_limits<std::size_t>::max();
|
||||
std::size_t Index = (std::numeric_limits<std::size_t>::max)();
|
||||
IterOfRange<R> Iter;
|
||||
};
|
||||
|
||||
@@ -1325,7 +1325,7 @@ class enumerator_iter
|
||||
|
||||
public:
|
||||
explicit enumerator_iter(IterOfRange<R> EndIter)
|
||||
: Result(std::numeric_limits<size_t>::max(), EndIter) {}
|
||||
: Result((std::numeric_limits<size_t>::max)(), EndIter) {}
|
||||
|
||||
enumerator_iter(std::size_t Index, IterOfRange<R> Iter)
|
||||
: Result(Index, Iter) {}
|
||||
@@ -1334,7 +1334,7 @@ public:
|
||||
const result_type &operator*() const { return Result; }
|
||||
|
||||
enumerator_iter<R> &operator++() {
|
||||
assert(Result.Index != std::numeric_limits<size_t>::max());
|
||||
assert(Result.Index != (std::numeric_limits<size_t>::max)());
|
||||
++Result.Iter;
|
||||
++Result.Index;
|
||||
return *this;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2015-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -67,7 +67,7 @@ class SafeThreadOwnerBase {
|
||||
: SafeThreadOwnerBase() {
|
||||
swap(*this, other);
|
||||
}
|
||||
SafeThreadOwnerBase& operator=(SafeThreadOwnerBase other) noexcept {
|
||||
SafeThreadOwnerBase& operator=(SafeThreadOwnerBase&& other) noexcept {
|
||||
swap(*this, other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ protected:
|
||||
|
||||
SmallVectorBase() = delete;
|
||||
SmallVectorBase(void *FirstEl, size_t Capacity)
|
||||
: BeginX(FirstEl), Capacity(Capacity) {}
|
||||
: BeginX(FirstEl), Capacity(static_cast<unsigned>(Capacity)) {}
|
||||
|
||||
/// This is an implementation of the grow() method which only works
|
||||
/// on POD-like data types and is out of line to reduce code duplication.
|
||||
@@ -75,7 +75,7 @@ public:
|
||||
/// which will only be overwritten.
|
||||
void set_size(size_t Size) {
|
||||
assert(Size <= capacity());
|
||||
this->Size = Size;
|
||||
this->Size = static_cast<unsigned>(Size);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -252,7 +252,7 @@ void SmallVectorTemplateBase<T, isPodLike>::grow(size_t MinSize) {
|
||||
|
||||
// Always grow, even from zero.
|
||||
size_t NewCapacity = size_t(NextPowerOf2(this->capacity() + 2));
|
||||
NewCapacity = std::min(std::max(NewCapacity, MinSize), size_t(UINT32_MAX));
|
||||
NewCapacity = (std::min)((std::max)(NewCapacity, MinSize), size_t(UINT32_MAX));
|
||||
T *NewElts = static_cast<T*>(wpi::safe_malloc(NewCapacity*sizeof(T)));
|
||||
|
||||
// Move the elements over.
|
||||
@@ -266,7 +266,7 @@ void SmallVectorTemplateBase<T, isPodLike>::grow(size_t MinSize) {
|
||||
free(this->begin());
|
||||
|
||||
this->BeginX = NewElts;
|
||||
this->Capacity = NewCapacity;
|
||||
this->Capacity = static_cast<unsigned>(NewCapacity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -60,14 +60,14 @@ inline unsigned hexDigitValue(char C) {
|
||||
if (C >= '0' && C <= '9') return C-'0';
|
||||
if (C >= 'a' && C <= 'f') return C-'a'+10U;
|
||||
if (C >= 'A' && C <= 'F') return C-'A'+10U;
|
||||
return -1U;
|
||||
return (std::numeric_limits<unsigned>::max)();
|
||||
}
|
||||
|
||||
/// Checks if character \p C is one of the 10 decimal digits.
|
||||
inline bool isDigit(char C) { return C >= '0' && C <= '9'; }
|
||||
|
||||
/// Checks if character \p C is a hexadecimal numeric character.
|
||||
inline bool isHexDigit(char C) { return hexDigitValue(C) != -1U; }
|
||||
inline bool isHexDigit(char C) { return hexDigitValue(C) != (std::numeric_limits<unsigned>::max)(); }
|
||||
|
||||
/// Checks if character \p C is a valid letter as classified by "C" locale.
|
||||
inline bool isAlpha(char C) {
|
||||
@@ -151,7 +151,7 @@ inline std::string toHex(ArrayRef<uint8_t> Input, bool LowerCase = false) {
|
||||
inline uint8_t hexFromNibbles(char MSB, char LSB) {
|
||||
unsigned U1 = hexDigitValue(MSB);
|
||||
unsigned U2 = hexDigitValue(LSB);
|
||||
assert(U1 != -1U && U2 != -1U);
|
||||
assert(U1 != (std::numeric_limits<unsigned>::max)() && U2 != (std::numeric_limits<unsigned>::max)());
|
||||
|
||||
return static_cast<uint8_t>((U1 << 4) | U2);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ protected:
|
||||
protected:
|
||||
explicit StringMapImpl(unsigned itemSize)
|
||||
: ItemSize(itemSize) {}
|
||||
StringMapImpl(StringMapImpl &&RHS)
|
||||
StringMapImpl(StringMapImpl &&RHS) noexcept
|
||||
: TheTable(RHS.TheTable), NumBuckets(RHS.NumBuckets),
|
||||
NumItems(RHS.NumItems), NumTombstones(RHS.NumTombstones),
|
||||
ItemSize(RHS.ItemSize) {
|
||||
|
||||
@@ -183,7 +183,7 @@ namespace wpi {
|
||||
LLVM_ATTRIBUTE_ALWAYS_INLINE
|
||||
int compare(StringRef RHS) const noexcept {
|
||||
// Check the prefix for a mismatch.
|
||||
if (int Res = compareMemory(Data, RHS.Data, std::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.
|
||||
@@ -274,7 +274,7 @@ namespace wpi {
|
||||
LLVM_NODISCARD
|
||||
LLVM_ATTRIBUTE_ALWAYS_INLINE
|
||||
size_t find(char C, size_t From = 0) const noexcept {
|
||||
size_t FindBegin = std::min(From, Length);
|
||||
size_t FindBegin = (std::min)(From, Length);
|
||||
if (FindBegin < Length) { // Avoid calling memchr with nullptr.
|
||||
// Just forward to memchr, which is faster than a hand-rolled loop.
|
||||
if (const void *P = ::memchr(Data + FindBegin, C, Length - FindBegin))
|
||||
@@ -336,7 +336,7 @@ namespace wpi {
|
||||
/// found.
|
||||
LLVM_NODISCARD
|
||||
size_t rfind(char C, size_t From = npos) const noexcept {
|
||||
From = std::min(From, Length);
|
||||
From = (std::min)(From, Length);
|
||||
size_t i = From;
|
||||
while (i != 0) {
|
||||
--i;
|
||||
@@ -554,8 +554,8 @@ namespace wpi {
|
||||
LLVM_NODISCARD
|
||||
LLVM_ATTRIBUTE_ALWAYS_INLINE
|
||||
StringRef substr(size_t Start, size_t N = npos) const noexcept {
|
||||
Start = std::min(Start, Length);
|
||||
return StringRef(Data + Start, std::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 only the first \p N
|
||||
@@ -666,8 +666,8 @@ namespace wpi {
|
||||
LLVM_NODISCARD
|
||||
LLVM_ATTRIBUTE_ALWAYS_INLINE
|
||||
StringRef slice(size_t Start, size_t End) const noexcept {
|
||||
Start = std::min(Start, Length);
|
||||
End = std::min(std::max(Start, End), Length);
|
||||
Start = (std::min)(Start, Length);
|
||||
End = (std::min)((std::max)(Start, End), Length);
|
||||
return StringRef(Data + Start, End - Start);
|
||||
}
|
||||
|
||||
@@ -776,28 +776,28 @@ namespace wpi {
|
||||
/// the left removed.
|
||||
LLVM_NODISCARD
|
||||
StringRef ltrim(char Char) const noexcept {
|
||||
return drop_front(std::min(Length, find_first_not_of(Char)));
|
||||
return drop_front((std::min)(Length, find_first_not_of(Char)));
|
||||
}
|
||||
|
||||
/// Return string with consecutive characters in \p Chars starting from
|
||||
/// the left removed.
|
||||
LLVM_NODISCARD
|
||||
StringRef ltrim(StringRef Chars = " \t\n\v\f\r") const noexcept {
|
||||
return drop_front(std::min(Length, find_first_not_of(Chars)));
|
||||
return drop_front((std::min)(Length, find_first_not_of(Chars)));
|
||||
}
|
||||
|
||||
/// Return string with consecutive \p Char characters starting from the
|
||||
/// right removed.
|
||||
LLVM_NODISCARD
|
||||
StringRef rtrim(char Char) const noexcept {
|
||||
return drop_back(size() - std::min(Length, find_last_not_of(Char) + 1));
|
||||
return drop_back(size() - (std::min)(Length, find_last_not_of(Char) + 1));
|
||||
}
|
||||
|
||||
/// Return string with consecutive characters in \p Chars starting from
|
||||
/// the right removed.
|
||||
LLVM_NODISCARD
|
||||
StringRef rtrim(StringRef Chars = " \t\n\v\f\r") const noexcept {
|
||||
return drop_back(size() - std::min(Length, find_last_not_of(Chars) + 1));
|
||||
return drop_back(size() - (std::min)(Length, find_last_not_of(Chars) + 1));
|
||||
}
|
||||
|
||||
/// Return string with consecutive \p Char characters starting from the
|
||||
|
||||
@@ -17,6 +17,11 @@
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 26495)
|
||||
#endif
|
||||
|
||||
namespace wpi {
|
||||
|
||||
class raw_ostream;
|
||||
@@ -531,4 +536,8 @@ namespace wpi {
|
||||
|
||||
} // end namespace wpi
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif // LLVM_ADT_TWINE_H
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -75,7 +75,7 @@ class WebSocket : public std::enable_shared_from_this<WebSocket> {
|
||||
* Client connection options.
|
||||
*/
|
||||
struct ClientOptions {
|
||||
ClientOptions() : handshakeTimeout{uv::Timer::Time::max()} {}
|
||||
ClientOptions() : handshakeTimeout{(uv::Timer::Time::max)()} {}
|
||||
|
||||
/** Timeout for the handshake request. */
|
||||
uv::Timer::Time handshakeTimeout;
|
||||
|
||||
@@ -2962,12 +2962,14 @@ class json
|
||||
{
|
||||
std::allocator<T> alloc;
|
||||
|
||||
auto deleter = [&](T * object)
|
||||
{
|
||||
alloc.deallocate(object, 1);
|
||||
};
|
||||
std::unique_ptr<T, decltype(deleter)> object(alloc.allocate(1), deleter);
|
||||
alloc.construct(object.get(), std::forward<Args>(args)...);
|
||||
using AllocatorTraits = std::allocator_traits<std::allocator<T>>;
|
||||
|
||||
auto deleter = [&](T * object)
|
||||
{
|
||||
AllocatorTraits::deallocate(alloc, object, 1);
|
||||
};
|
||||
std::unique_ptr<T, decltype(deleter)> object(AllocatorTraits::allocate(alloc, 1), deleter);
|
||||
AllocatorTraits::construct(alloc, object.get(), std::forward<Args>(args)...);
|
||||
assert(object != nullptr);
|
||||
return object.release();
|
||||
}
|
||||
@@ -5318,8 +5320,8 @@ class json
|
||||
if (is_string())
|
||||
{
|
||||
std::allocator<std::string> alloc;
|
||||
alloc.destroy(m_value.string);
|
||||
alloc.deallocate(m_value.string, 1);
|
||||
std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.string);
|
||||
std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.string, 1);
|
||||
m_value.string = nullptr;
|
||||
}
|
||||
|
||||
@@ -5422,8 +5424,8 @@ class json
|
||||
if (is_string())
|
||||
{
|
||||
std::allocator<std::string> alloc;
|
||||
alloc.destroy(m_value.string);
|
||||
alloc.deallocate(m_value.string, 1);
|
||||
std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.string);
|
||||
std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.string, 1);
|
||||
m_value.string = nullptr;
|
||||
}
|
||||
|
||||
@@ -8077,7 +8079,7 @@ namespace std
|
||||
@since version 1.0.0
|
||||
*/
|
||||
template<>
|
||||
inline void swap(wpi::json& j1,
|
||||
inline void swap<wpi::json>(wpi::json& j1,
|
||||
wpi::json& j2) noexcept(
|
||||
is_nothrow_move_constructible<wpi::json>::value and
|
||||
is_nothrow_move_assignable<wpi::json>::value
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
# ifndef WPIUTIL_WPI_OPTIONAL_H
|
||||
# define WPIUTIL_WPI_OPTIONAL_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#define _SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING
|
||||
#endif
|
||||
|
||||
# include <utility>
|
||||
# include <type_traits>
|
||||
# include <initializer_list>
|
||||
@@ -77,7 +81,7 @@ struct has_overloaded_addressof
|
||||
{
|
||||
template <class X>
|
||||
constexpr static bool has_overload(...) { return false; }
|
||||
|
||||
|
||||
template <class X, size_t S = sizeof(std::declval<X&>().operator&()) >
|
||||
constexpr static bool has_overload(bool) { return true; }
|
||||
|
||||
@@ -97,15 +101,15 @@ T* static_addressof(T& ref)
|
||||
}
|
||||
|
||||
|
||||
// the call to convert<A>(b) has return type A and converts b to type A iff b decltype(b) is implicitly convertible to A
|
||||
// the call to convert<A>(b) has return type A and converts b to type A iff b decltype(b) is implicitly convertible to A
|
||||
template <class U>
|
||||
constexpr U convert(U v) { return v; }
|
||||
|
||||
|
||||
|
||||
namespace swap_ns
|
||||
{
|
||||
using std::swap;
|
||||
|
||||
|
||||
template <class T>
|
||||
void adl_swap(T& t, T& u) noexcept(noexcept(swap(t, u)))
|
||||
{
|
||||
@@ -230,12 +234,12 @@ class optional : private OptionalBase<T>
|
||||
{
|
||||
static_assert( !std::is_same<typename std::decay<T>::type, nullopt_t>::value, "bad T" );
|
||||
static_assert( !std::is_same<typename std::decay<T>::type, in_place_t>::value, "bad T" );
|
||||
|
||||
|
||||
|
||||
constexpr bool initialized() const noexcept { return OptionalBase<T>::init_; }
|
||||
typename std::remove_const<T>::type* dataptr() { return std::addressof(OptionalBase<T>::storage_.value_); }
|
||||
constexpr const T* dataptr() const { return detail_::static_addressof(OptionalBase<T>::storage_.value_); }
|
||||
|
||||
|
||||
constexpr const T& contained_val() const& { return OptionalBase<T>::storage_.value_; }
|
||||
# if OPTIONAL_HAS_MOVE_ACCESSORS == 1
|
||||
constexpr T&& contained_val() && { return std::move(OptionalBase<T>::storage_.value_); }
|
||||
@@ -249,7 +253,7 @@ class optional : private OptionalBase<T>
|
||||
if (initialized()) dataptr()->T::~T();
|
||||
OptionalBase<T>::init_ = false;
|
||||
}
|
||||
|
||||
|
||||
template <class... Args>
|
||||
void initialize(Args&&... args) noexcept(noexcept(T(std::forward<Args>(args)...)))
|
||||
{
|
||||
@@ -312,7 +316,7 @@ public:
|
||||
clear();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
optional& operator=(const optional& rhs)
|
||||
{
|
||||
if (initialized() == true && rhs.initialized() == false) clear();
|
||||
@@ -320,7 +324,7 @@ public:
|
||||
else if (initialized() == true && rhs.initialized() == true) contained_val() = *rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
optional& operator=(optional&& rhs)
|
||||
noexcept(std::is_nothrow_move_assignable<T>::value && std::is_nothrow_move_constructible<T>::value)
|
||||
{
|
||||
@@ -342,22 +346,22 @@ public:
|
||||
else { initialize(std::forward<U>(v)); }
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template <class... Args>
|
||||
void emplace(Args&&... args)
|
||||
{
|
||||
clear();
|
||||
initialize(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
|
||||
template <class U, class... Args>
|
||||
void emplace(std::initializer_list<U> il, Args&&... args)
|
||||
{
|
||||
clear();
|
||||
initialize<U, Args...>(il, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
|
||||
// 20.5.4.4, Swap
|
||||
void swap(optional<T>& rhs) noexcept(std::is_nothrow_move_constructible<T>::value
|
||||
&& noexcept(detail_::swap_ns::adl_swap(std::declval<T&>(), std::declval<T&>())))
|
||||
@@ -368,30 +372,30 @@ public:
|
||||
}
|
||||
|
||||
// 20.5.4.5, Observers
|
||||
|
||||
|
||||
explicit constexpr operator bool() const noexcept { return initialized(); }
|
||||
constexpr bool has_value() const noexcept { return initialized(); }
|
||||
|
||||
|
||||
constexpr T const* operator ->() const {
|
||||
return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), dataptr());
|
||||
}
|
||||
|
||||
|
||||
# if OPTIONAL_HAS_MOVE_ACCESSORS == 1
|
||||
|
||||
constexpr T* operator ->() {
|
||||
assert (initialized());
|
||||
return dataptr();
|
||||
}
|
||||
|
||||
|
||||
constexpr T const& operator *() const& {
|
||||
return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), contained_val());
|
||||
}
|
||||
|
||||
|
||||
constexpr T& operator *() & {
|
||||
assert (initialized());
|
||||
return contained_val();
|
||||
}
|
||||
|
||||
|
||||
constexpr T&& operator *() && {
|
||||
assert (initialized());
|
||||
return constexpr_move(contained_val());
|
||||
@@ -400,48 +404,48 @@ public:
|
||||
constexpr T const& value() const& {
|
||||
return initialized() ? contained_val() : (throw bad_optional_access("bad optional access"), contained_val());
|
||||
}
|
||||
|
||||
|
||||
constexpr T& value() & {
|
||||
return initialized() ? contained_val() : (throw bad_optional_access("bad optional access"), contained_val());
|
||||
}
|
||||
|
||||
|
||||
constexpr T&& value() && {
|
||||
if (!initialized()) throw bad_optional_access("bad optional access");
|
||||
return std::move(contained_val());
|
||||
}
|
||||
|
||||
|
||||
# else
|
||||
|
||||
T* operator ->() {
|
||||
assert (initialized());
|
||||
return dataptr();
|
||||
}
|
||||
|
||||
|
||||
constexpr T const& operator *() const {
|
||||
return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), contained_val());
|
||||
}
|
||||
|
||||
|
||||
T& operator *() {
|
||||
assert (initialized());
|
||||
return contained_val();
|
||||
}
|
||||
|
||||
|
||||
constexpr T const& value() const {
|
||||
return initialized() ? contained_val() : (throw bad_optional_access("bad optional access"), contained_val());
|
||||
}
|
||||
|
||||
|
||||
T& value() {
|
||||
return initialized() ? contained_val() : (throw bad_optional_access("bad optional access"), contained_val());
|
||||
}
|
||||
|
||||
|
||||
# endif
|
||||
|
||||
|
||||
template <class V>
|
||||
constexpr T value_or(V&& v) const&
|
||||
{
|
||||
return *this ? **this : detail_::convert<T>(constexpr_forward<V>(v));
|
||||
}
|
||||
|
||||
|
||||
# if OPTIONAL_HAS_MOVE_ACCESSORS == 1
|
||||
|
||||
template <class V>
|
||||
@@ -451,15 +455,15 @@ public:
|
||||
}
|
||||
|
||||
# else
|
||||
|
||||
|
||||
template <class V>
|
||||
T value_or(V&& v) &&
|
||||
{
|
||||
return *this ? constexpr_move(const_cast<optional<T>&>(*this).contained_val()) : detail_::convert<T>(constexpr_forward<V>(v));
|
||||
}
|
||||
|
||||
|
||||
# endif
|
||||
|
||||
|
||||
// 20.6.3.6, modifiers
|
||||
void reset() noexcept { clear(); }
|
||||
};
|
||||
@@ -471,42 +475,42 @@ class optional<T&>
|
||||
static_assert( !std::is_same<T, nullopt_t>::value, "bad T" );
|
||||
static_assert( !std::is_same<T, in_place_t>::value, "bad T" );
|
||||
T* ref;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// 20.5.5.1, construction/destruction
|
||||
constexpr optional() noexcept : ref(nullptr) {}
|
||||
|
||||
|
||||
constexpr optional(nullopt_t) noexcept : ref(nullptr) {}
|
||||
|
||||
|
||||
constexpr optional(T& v) noexcept : ref(detail_::static_addressof(v)) {}
|
||||
|
||||
|
||||
optional(T&&) = delete;
|
||||
|
||||
|
||||
constexpr optional(const optional& rhs) noexcept : ref(rhs.ref) {}
|
||||
|
||||
|
||||
explicit constexpr optional(in_place_t, T& v) noexcept : ref(detail_::static_addressof(v)) {}
|
||||
|
||||
|
||||
explicit optional(in_place_t, T&&) = delete;
|
||||
|
||||
|
||||
~optional() = default;
|
||||
|
||||
|
||||
// 20.5.5.2, mutation
|
||||
optional& operator=(nullopt_t) noexcept {
|
||||
ref = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// optional& operator=(const optional& rhs) noexcept {
|
||||
// ref = rhs.ref;
|
||||
// return *this;
|
||||
// }
|
||||
|
||||
|
||||
// optional& operator=(optional&& rhs) noexcept {
|
||||
// ref = rhs.ref;
|
||||
// return *this;
|
||||
// }
|
||||
|
||||
|
||||
template <typename U>
|
||||
auto operator=(U&& rhs) noexcept
|
||||
-> typename std::enable_if
|
||||
@@ -518,7 +522,7 @@ public:
|
||||
ref = rhs.ref;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template <typename U>
|
||||
auto operator=(U&& rhs) noexcept
|
||||
-> typename std::enable_if
|
||||
@@ -527,40 +531,40 @@ public:
|
||||
optional&
|
||||
>::type
|
||||
= delete;
|
||||
|
||||
|
||||
void emplace(T& v) noexcept {
|
||||
ref = detail_::static_addressof(v);
|
||||
}
|
||||
|
||||
|
||||
void emplace(T&&) = delete;
|
||||
|
||||
|
||||
|
||||
|
||||
void swap(optional<T&>& rhs) noexcept
|
||||
{
|
||||
std::swap(ref, rhs.ref);
|
||||
}
|
||||
|
||||
|
||||
// 20.5.5.3, observers
|
||||
constexpr T* operator->() const {
|
||||
return TR2_OPTIONAL_ASSERTED_EXPRESSION(ref, ref);
|
||||
}
|
||||
|
||||
|
||||
constexpr T& operator*() const {
|
||||
return TR2_OPTIONAL_ASSERTED_EXPRESSION(ref, *ref);
|
||||
}
|
||||
|
||||
|
||||
constexpr T& value() const {
|
||||
return ref ? *ref : (throw bad_optional_access("bad optional access"), *ref);
|
||||
}
|
||||
|
||||
|
||||
explicit constexpr operator bool() const noexcept {
|
||||
return ref != nullptr;
|
||||
}
|
||||
|
||||
|
||||
constexpr bool has_value() const noexcept {
|
||||
return ref != nullptr;
|
||||
}
|
||||
|
||||
|
||||
template <class V>
|
||||
constexpr typename std::decay<T>::type value_or(V&& v) const
|
||||
{
|
||||
@@ -889,18 +893,18 @@ namespace std
|
||||
{
|
||||
typedef typename hash<T>::result_type result_type;
|
||||
typedef wpi::optional<T> argument_type;
|
||||
|
||||
|
||||
constexpr result_type operator()(argument_type const& arg) const {
|
||||
return arg ? std::hash<T>{}(*arg) : result_type{};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct hash<wpi::optional<T&>>
|
||||
{
|
||||
typedef typename hash<T>::result_type result_type;
|
||||
typedef wpi::optional<T&> argument_type;
|
||||
|
||||
|
||||
constexpr result_type operator()(argument_type const& arg) const {
|
||||
return arg ? std::hash<T>{}(*arg) : result_type{};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2015-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -49,7 +49,7 @@ class raw_istream {
|
||||
}
|
||||
|
||||
size_t readsome(void* data, size_t len) {
|
||||
size_t readlen = std::min(in_avail(), len);
|
||||
size_t readlen = (std::min)(in_avail(), len);
|
||||
if (readlen == 0) return 0;
|
||||
read_impl(data, readlen);
|
||||
return m_read_count;
|
||||
|
||||
@@ -40,11 +40,11 @@ class Buffer : public uv_buf_t {
|
||||
: Buffer{reinterpret_cast<const char*>(arr.data()), arr.size()} {}
|
||||
Buffer(char* base_, size_t len_) {
|
||||
base = base_;
|
||||
len = len_;
|
||||
len = static_cast<decltype(len)>(len_);
|
||||
}
|
||||
Buffer(const char* base_, size_t len_) {
|
||||
base = const_cast<char*>(base_);
|
||||
len = len_;
|
||||
len = static_cast<decltype(len)>(len_);
|
||||
}
|
||||
|
||||
ArrayRef<char> data() const { return ArrayRef<char>{base, len}; }
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -130,7 +130,8 @@ class Tcp final : public NetworkStreamImpl<Tcp, uv_tcp_t> {
|
||||
* @return True in case of success, false otherwise.
|
||||
*/
|
||||
bool SetKeepAlive(bool enable, Time time = Time{0}) {
|
||||
return uv_tcp_keepalive(GetRaw(), enable, time.count()) == 0;
|
||||
return uv_tcp_keepalive(GetRaw(), enable,
|
||||
static_cast<unsigned>(time.count())) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -244,7 +244,8 @@ class Udp final : public HandleImpl<Udp, uv_udp_t> {
|
||||
* @return Number of bytes sent.
|
||||
*/
|
||||
int TrySend(const sockaddr& addr, ArrayRef<Buffer> bufs) {
|
||||
int val = uv_udp_try_send(GetRaw(), bufs.data(), bufs.size(), &addr);
|
||||
int val = uv_udp_try_send(GetRaw(), bufs.data(),
|
||||
static_cast<unsigned>(bufs.size()), &addr);
|
||||
if (val < 0) {
|
||||
this->ReportError(val);
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user