summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2023-11-05 12:37:04 +0100
committerMoonchild <moonchild@palemoon.org>2023-11-08 13:50:33 +0100
commit190e7bd30a8df5bfa8e1aba0210f2b67a3b0120d (patch)
tree8135f52584980fc3ce9827daa3e27a08af2c6913
parent292ece5fde96a67a44830cb2c05463a06de0b373 (diff)
downloaduxp-190e7bd30a8df5bfa8e1aba0210f2b67a3b0120d.tar.gz
Issue #2342: Use [[nodiscard]] in /mfbt
-rw-r--r--mfbt/AllocPolicy.h2
-rw-r--r--mfbt/AlreadyAddRefed.h2
-rw-r--r--mfbt/Assertions.h8
-rw-r--r--mfbt/Compression.h6
-rw-r--r--mfbt/EndianUtils.h24
-rw-r--r--mfbt/FloatingPoint.h2
-rw-r--r--mfbt/HashFunctions.h26
-rw-r--r--mfbt/SegmentedVector.h2
-rw-r--r--mfbt/ThreadLocal.h2
-rw-r--r--mfbt/UniquePtr.h4
-rw-r--r--mfbt/Vector.h42
-rw-r--r--mfbt/tests/TestSegmentedVector.cpp2
12 files changed, 61 insertions, 61 deletions
diff --git a/mfbt/AllocPolicy.h b/mfbt/AllocPolicy.h
index add1a1a34a..56f7ea0d7f 100644
--- a/mfbt/AllocPolicy.h
+++ b/mfbt/AllocPolicy.h
@@ -121,7 +121,7 @@ public:
{
}
- MOZ_MUST_USE bool checkSimulatedOOM() const
+ [[nodiscard]] bool checkSimulatedOOM() const
{
return true;
}
diff --git a/mfbt/AlreadyAddRefed.h b/mfbt/AlreadyAddRefed.h
index 1478ce9e8a..6d356da438 100644
--- a/mfbt/AlreadyAddRefed.h
+++ b/mfbt/AlreadyAddRefed.h
@@ -110,7 +110,7 @@ struct MOZ_MUST_USE_TYPE MOZ_NON_AUTOABLE already_AddRefed
aUnused << mutableAlreadyAddRefed->take();
}
- MOZ_MUST_USE T* take()
+ [[nodiscard]] T* take()
{
T* rawPtr = mRawPtr;
mRawPtr = nullptr;
diff --git a/mfbt/Assertions.h b/mfbt/Assertions.h
index df41795c12..09a1b8eaa6 100644
--- a/mfbt/Assertions.h
+++ b/mfbt/Assertions.h
@@ -603,25 +603,25 @@ struct AssertionConditionType
# define MOZ_ALWAYS_TRUE(expr) \
do { \
if ((expr)) { \
- /* Silence MOZ_MUST_USE. */ \
+ /* Silence [[nodiscard]]. */ \
} \
} while (0)
# define MOZ_ALWAYS_FALSE(expr) \
do { \
if ((expr)) { \
- /* Silence MOZ_MUST_USE. */ \
+ /* Silence [[nodiscard]]. */ \
} \
} while (0)
# define MOZ_ALWAYS_OK(expr) \
do { \
if ((expr).isOk()) { \
- /* Silence MOZ_MUST_USE. */ \
+ /* Silence [[nodiscard]]. */ \
} \
} while (0)
# define MOZ_ALWAYS_ERR(expr) \
do { \
if ((expr).isErr()) { \
- /* Silence MOZ_MUST_USE. */ \
+ /* Silence [[nodiscard]]. */ \
} \
} while (0)
#endif
diff --git a/mfbt/Compression.h b/mfbt/Compression.h
index 37e4307c0d..cf207c6fa0 100644
--- a/mfbt/Compression.h
+++ b/mfbt/Compression.h
@@ -71,7 +71,7 @@ public:
* @param aOutputSize is the output size, therefore the original size
* @return true on success, false on failure
*/
- static MFBT_API MOZ_MUST_USE bool
+ [[nodiscard]] static MFBT_API bool
decompress(const char* aSource, char* aDest, size_t aOutputSize);
/**
@@ -91,7 +91,7 @@ public:
* buffer (necessarily <= aMaxOutputSize)
* @return true on success, false on failure
*/
- static MFBT_API MOZ_MUST_USE bool
+ [[nodiscard]] static MFBT_API bool
decompress(const char* aSource, size_t aInputSize, char* aDest,
size_t aMaxOutputSize, size_t* aOutputSize);
@@ -114,7 +114,7 @@ public:
* buffer (necessarily <= aMaxOutputSize)
* @return true on success, false on failure
*/
- static MFBT_API MOZ_MUST_USE bool
+ [[nodiscard]] static MFBT_API bool
decompressPartial(const char* aSource, size_t aInputSize, char* aDest,
size_t aMaxOutputSize, size_t* aOutputSize);
diff --git a/mfbt/EndianUtils.h b/mfbt/EndianUtils.h
index 719e048c12..1dce2bdc29 100644
--- a/mfbt/EndianUtils.h
+++ b/mfbt/EndianUtils.h
@@ -343,37 +343,37 @@ class Endian : private EndianUtils
{
protected:
/** Read a uint16_t in ThisEndian endianness from |aPtr| and return it. */
- static MOZ_MUST_USE uint16_t readUint16(const void* aPtr)
+ [[nodiscard]] static uint16_t readUint16(const void* aPtr)
{
return read<uint16_t>(aPtr);
}
/** Read a uint32_t in ThisEndian endianness from |aPtr| and return it. */
- static MOZ_MUST_USE uint32_t readUint32(const void* aPtr)
+ [[nodiscard]] static uint32_t readUint32(const void* aPtr)
{
return read<uint32_t>(aPtr);
}
/** Read a uint64_t in ThisEndian endianness from |aPtr| and return it. */
- static MOZ_MUST_USE uint64_t readUint64(const void* aPtr)
+ [[nodiscard]] static uint64_t readUint64(const void* aPtr)
{
return read<uint64_t>(aPtr);
}
/** Read an int16_t in ThisEndian endianness from |aPtr| and return it. */
- static MOZ_MUST_USE int16_t readInt16(const void* aPtr)
+ [[nodiscard]] static int16_t readInt16(const void* aPtr)
{
return read<int16_t>(aPtr);
}
/** Read an int32_t in ThisEndian endianness from |aPtr| and return it. */
- static MOZ_MUST_USE int32_t readInt32(const void* aPtr)
+ [[nodiscard]] static int32_t readInt32(const void* aPtr)
{
return read<uint32_t>(aPtr);
}
/** Read an int64_t in ThisEndian endianness from |aPtr| and return it. */
- static MOZ_MUST_USE int64_t readInt64(const void* aPtr)
+ [[nodiscard]] static int64_t readInt64(const void* aPtr)
{
return read<int64_t>(aPtr);
}
@@ -422,7 +422,7 @@ protected:
* format for transmission.
*/
template<typename T>
- MOZ_MUST_USE static T swapToLittleEndian(T aValue)
+ [[nodiscard]] static T swapToLittleEndian(T aValue)
{
return maybeSwap<ThisEndian, Little>(aValue);
}
@@ -452,7 +452,7 @@ protected:
* Converts a value of type T to big-endian format.
*/
template<typename T>
- MOZ_MUST_USE static T swapToBigEndian(T aValue)
+ [[nodiscard]] static T swapToBigEndian(T aValue)
{
return maybeSwap<ThisEndian, Big>(aValue);
}
@@ -484,7 +484,7 @@ protected:
*/
template<typename T>
- MOZ_MUST_USE static T swapToNetworkOrder(T aValue)
+ [[nodiscard]] static T swapToNetworkOrder(T aValue)
{
return swapToBigEndian(aValue);
}
@@ -507,7 +507,7 @@ protected:
* Converts a value of type T from little-endian format.
*/
template<typename T>
- MOZ_MUST_USE static T swapFromLittleEndian(T aValue)
+ [[nodiscard]] static T swapFromLittleEndian(T aValue)
{
return maybeSwap<Little, ThisEndian>(aValue);
}
@@ -537,7 +537,7 @@ protected:
* Converts a value of type T from big-endian format.
*/
template<typename T>
- MOZ_MUST_USE static T swapFromBigEndian(T aValue)
+ [[nodiscard]] static T swapFromBigEndian(T aValue)
{
return maybeSwap<Big, ThisEndian>(aValue);
}
@@ -568,7 +568,7 @@ protected:
* in network code.
*/
template<typename T>
- MOZ_MUST_USE static T swapFromNetworkOrder(T aValue)
+ [[nodiscard]] static T swapFromNetworkOrder(T aValue)
{
return swapFromBigEndian(aValue);
}
diff --git a/mfbt/FloatingPoint.h b/mfbt/FloatingPoint.h
index a2846ce298..2ee1d1299b 100644
--- a/mfbt/FloatingPoint.h
+++ b/mfbt/FloatingPoint.h
@@ -523,7 +523,7 @@ FuzzyEqualsMultiplicative(T aValue1, T aValue2,
*
* This function isn't inlined to avoid buggy optimizations by MSVC.
*/
-MOZ_MUST_USE
+[[nodiscard]]
extern MFBT_API bool
IsFloat32Representable(double aFloat32);
diff --git a/mfbt/HashFunctions.h b/mfbt/HashFunctions.h
index d287081174..8a3bacd966 100644
--- a/mfbt/HashFunctions.h
+++ b/mfbt/HashFunctions.h
@@ -160,7 +160,7 @@ AddUintptrToHash<8>(uint32_t aHash, uintptr_t aValue)
* convert to uint32_t, data pointers, and function pointers.
*/
template<typename A>
-MOZ_MUST_USE inline uint32_t
+[[nodiscard]] inline uint32_t
AddToHash(uint32_t aHash, A aA)
{
/*
@@ -171,7 +171,7 @@ AddToHash(uint32_t aHash, A aA)
}
template<typename A>
-MOZ_MUST_USE inline uint32_t
+[[nodiscard]] inline uint32_t
AddToHash(uint32_t aHash, A* aA)
{
/*
@@ -185,14 +185,14 @@ AddToHash(uint32_t aHash, A* aA)
}
template<>
-MOZ_MUST_USE inline uint32_t
+[[nodiscard]] inline uint32_t
AddToHash(uint32_t aHash, uintptr_t aA)
{
return detail::AddUintptrToHash<sizeof(uintptr_t)>(aHash, aA);
}
template<typename A, typename... Args>
-MOZ_MUST_USE uint32_t
+[[nodiscard]] uint32_t
AddToHash(uint32_t aHash, A aArg, Args... aArgs)
{
return AddToHash(AddToHash(aHash, aArg), aArgs...);
@@ -206,7 +206,7 @@ AddToHash(uint32_t aHash, A aArg, Args... aArgs)
* that x has already been hashed.
*/
template<typename... Args>
-MOZ_MUST_USE inline uint32_t
+[[nodiscard]] inline uint32_t
HashGeneric(Args... aArgs)
{
return AddToHash(0, aArgs...);
@@ -244,32 +244,32 @@ HashKnownLength(const T* aStr, size_t aLength)
* If you have the string's length, you might as well call the overload which
* includes the length. It may be marginally faster.
*/
-MOZ_MUST_USE inline uint32_t
+[[nodiscard]] inline uint32_t
HashString(const char* aStr)
{
return detail::HashUntilZero(reinterpret_cast<const unsigned char*>(aStr));
}
-MOZ_MUST_USE inline uint32_t
+[[nodiscard]] inline uint32_t
HashString(const char* aStr, size_t aLength)
{
return detail::HashKnownLength(reinterpret_cast<const unsigned char*>(aStr), aLength);
}
-MOZ_MUST_USE
+[[nodiscard]]
inline uint32_t
HashString(const unsigned char* aStr, size_t aLength)
{
return detail::HashKnownLength(aStr, aLength);
}
-MOZ_MUST_USE inline uint32_t
+[[nodiscard]] inline uint32_t
HashString(const char16_t* aStr)
{
return detail::HashUntilZero(aStr);
}
-MOZ_MUST_USE inline uint32_t
+[[nodiscard]] inline uint32_t
HashString(const char16_t* aStr, size_t aLength)
{
return detail::HashKnownLength(aStr, aLength);
@@ -280,13 +280,13 @@ HashString(const char16_t* aStr, size_t aLength)
* the same width!
*/
#ifdef WIN32
-MOZ_MUST_USE inline uint32_t
+[[nodiscard]] inline uint32_t
HashString(const wchar_t* aStr)
{
return detail::HashUntilZero(aStr);
}
-MOZ_MUST_USE inline uint32_t
+[[nodiscard]] inline uint32_t
HashString(const wchar_t* aStr, size_t aLength)
{
return detail::HashKnownLength(aStr, aLength);
@@ -299,7 +299,7 @@ HashString(const wchar_t* aStr, size_t aLength)
* This hash walks word-by-word, rather than byte-by-byte, so you won't get the
* same result out of HashBytes as you would out of HashString.
*/
-MOZ_MUST_USE extern MFBT_API uint32_t
+[[nodiscard]] extern MFBT_API uint32_t
HashBytes(const void* bytes, size_t aLength);
/**
diff --git a/mfbt/SegmentedVector.h b/mfbt/SegmentedVector.h
index 6e4dc2a452..54590a934d 100644
--- a/mfbt/SegmentedVector.h
+++ b/mfbt/SegmentedVector.h
@@ -158,7 +158,7 @@ public:
// Returns false if the allocation failed. (If you are using an infallible
// allocation policy, use InfallibleAppend() instead.)
template<typename U>
- MOZ_MUST_USE bool Append(U&& aU)
+ [[nodiscard]] bool Append(U&& aU)
{
Segment* last = mSegments.getLast();
if (!last || last->Length() == kSegmentCapacity) {
diff --git a/mfbt/ThreadLocal.h b/mfbt/ThreadLocal.h
index 7acfa46548..cf8a97cba2 100644
--- a/mfbt/ThreadLocal.h
+++ b/mfbt/ThreadLocal.h
@@ -113,7 +113,7 @@ public:
{}
#endif
- MOZ_MUST_USE inline bool init();
+ [[nodiscard]] inline bool init();
inline T get() const;
diff --git a/mfbt/UniquePtr.h b/mfbt/UniquePtr.h
index 97fb8d27ae..035adc2a52 100644
--- a/mfbt/UniquePtr.h
+++ b/mfbt/UniquePtr.h
@@ -327,7 +327,7 @@ public:
DeleterType& get_deleter() { return del(); }
const DeleterType& get_deleter() const { return del(); }
- MOZ_MUST_USE Pointer release()
+ [[nodiscard]] Pointer release()
{
Pointer p = ptr();
ptr() = nullptr;
@@ -462,7 +462,7 @@ public:
DeleterType& get_deleter() { return mTuple.second(); }
const DeleterType& get_deleter() const { return mTuple.second(); }
- MOZ_MUST_USE Pointer release()
+ [[nodiscard]] Pointer release()
{
Pointer p = mTuple.first();
mTuple.first() = nullptr;
diff --git a/mfbt/Vector.h b/mfbt/Vector.h
index 6d5c769e9d..b75a5d8a04 100644
--- a/mfbt/Vector.h
+++ b/mfbt/Vector.h
@@ -129,7 +129,7 @@ struct VectorImpl
* aNewCap has not overflowed, and (2) multiplying aNewCap by sizeof(T) will
* not overflow.
*/
- static inline MOZ_MUST_USE bool
+ [[nodiscard]] static inline bool
growTo(Vector<T, N, AP>& aV, size_t aNewCap)
{
MOZ_ASSERT(!aV.usingInlineStorage());
@@ -221,7 +221,7 @@ struct VectorImpl<T, N, AP, true>
}
}
- static inline MOZ_MUST_USE bool
+ [[nodiscard]] static inline bool
growTo(Vector<T, N, AP>& aV, size_t aNewCap)
{
MOZ_ASSERT(!aV.usingInlineStorage());
@@ -290,9 +290,9 @@ class MOZ_NON_PARAM Vector final : private AllocPolicy
friend struct detail::VectorTesting;
- MOZ_MUST_USE bool growStorageBy(size_t aIncr);
- MOZ_MUST_USE bool convertToHeapStorage(size_t aNewCap);
- MOZ_MUST_USE bool maybeCheckSimulatedOOM(size_t aRequestedSize);
+ [[nodiscard]] bool growStorageBy(size_t aIncr);
+ [[nodiscard]] bool convertToHeapStorage(size_t aNewCap);
+ [[nodiscard]] bool maybeCheckSimulatedOOM(size_t aRequestedSize);
/* magic constants */
@@ -618,7 +618,7 @@ public:
* Given that the vector is empty, grow the internal capacity to |aRequest|,
* keeping the length 0.
*/
- MOZ_MUST_USE bool initCapacity(size_t aRequest);
+ [[nodiscard]] bool initCapacity(size_t aRequest);
/**
* Given that the vector is empty, grow the internal capacity and length to
@@ -627,7 +627,7 @@ public:
* rounding that happens in resize and overhead of initialization for elements
* that are about to be overwritten.
*/
- MOZ_MUST_USE bool initLengthUninitialized(size_t aRequest);
+ [[nodiscard]] bool initLengthUninitialized(size_t aRequest);
/**
* If reserve(aRequest) succeeds and |aRequest >= length()|, then appending
@@ -637,7 +637,7 @@ public:
* A request to reserve an amount less than the current length does not affect
* reserved space.
*/
- MOZ_MUST_USE bool reserve(size_t aRequest);
+ [[nodiscard]] bool reserve(size_t aRequest);
/**
* Destroy elements in the range [end() - aIncr, end()). Does not deallocate
@@ -652,18 +652,18 @@ public:
void shrinkTo(size_t aNewLength);
/** Grow the vector by aIncr elements. */
- MOZ_MUST_USE bool growBy(size_t aIncr);
+ [[nodiscard]] bool growBy(size_t aIncr);
/** Call shrinkBy or growBy based on whether newSize > length(). */
- MOZ_MUST_USE bool resize(size_t aNewLength);
+ [[nodiscard]] bool resize(size_t aNewLength);
/**
* Increase the length of the vector, but don't initialize the new elements
* -- leave them as uninitialized memory.
*/
- MOZ_MUST_USE bool growByUninitialized(size_t aIncr);
+ [[nodiscard]] bool growByUninitialized(size_t aIncr);
void infallibleGrowByUninitialized(size_t aIncr);
- MOZ_MUST_USE bool resizeUninitialized(size_t aNewLength);
+ [[nodiscard]] bool resizeUninitialized(size_t aNewLength);
/** Shorthand for shrinkBy(length()). */
void clear();
@@ -693,13 +693,13 @@ public:
* vector, instead of copying it. If it fails, |aU| is left unmoved. ("We are
* not amused.")
*/
- template<typename U> MOZ_MUST_USE bool append(U&& aU);
+ template<typename U> [[nodiscard]] bool append(U&& aU);
/**
* Construct a T in-place as a new entry at the end of this vector.
*/
template<typename... Args>
- MOZ_MUST_USE bool emplaceBack(Args&&... aArgs)
+ [[nodiscard]] bool emplaceBack(Args&&... aArgs)
{
if (!growByUninitialized(1))
return false;
@@ -708,10 +708,10 @@ public:
}
template<typename U, size_t O, class BP>
- MOZ_MUST_USE bool appendAll(const Vector<U, O, BP>& aU);
- MOZ_MUST_USE bool appendN(const T& aT, size_t aN);
- template<typename U> MOZ_MUST_USE bool append(const U* aBegin, const U* aEnd);
- template<typename U> MOZ_MUST_USE bool append(const U* aBegin, size_t aLength);
+ [[nodiscard]] bool appendAll(const Vector<U, O, BP>& aU);
+ [[nodiscard]] bool appendN(const T& aT, size_t aN);
+ template<typename U> [[nodiscard]] bool append(const U* aBegin, const U* aEnd);
+ template<typename U> [[nodiscard]] bool append(const U* aBegin, size_t aLength);
/*
* Guaranteed-infallible append operations for use upon vectors whose
@@ -755,7 +755,7 @@ public:
*
* N.B. Although a T*, only the range [0, length()) is constructed.
*/
- MOZ_MUST_USE T* extractRawBuffer();
+ [[nodiscard]] T* extractRawBuffer();
/**
* If elements are stored in-place, allocate a new buffer, move this vector's
@@ -773,7 +773,7 @@ public:
* If any of these elements are uninitialized (as growByUninitialized
* enables), behavior is undefined.
*/
- MOZ_MUST_USE T* extractOrCopyRawBuffer();
+ [[nodiscard]] T* extractOrCopyRawBuffer();
/**
* Transfer ownership of an array of objects into the vector. The caller
@@ -801,7 +801,7 @@ public:
* This is inherently a linear-time operation. Be careful!
*/
template<typename U>
- MOZ_MUST_USE T* insert(T* aP, U&& aVal);
+ [[nodiscard]] T* insert(T* aP, U&& aVal);
/**
* Removes the element |aT|, which must fall in the bounds [begin, end),
diff --git a/mfbt/tests/TestSegmentedVector.cpp b/mfbt/tests/TestSegmentedVector.cpp
index 31f9f47432..0e45c64bcf 100644
--- a/mfbt/tests/TestSegmentedVector.cpp
+++ b/mfbt/tests/TestSegmentedVector.cpp
@@ -34,7 +34,7 @@ public:
};
// We want to test Append(), which is fallible and marked with
-// MOZ_MUST_USE. But we're using an infallible alloc policy, and so
+// [[nodiscard]]. But we're using an infallible alloc policy, and so
// don't really need to check the result. Casting to |void| works with clang
// but not GCC, so we instead use this dummy variable which works with both
// compilers.