Bug 1571631 - Replace MOZ_MUST_USE with [[nodiscard]] in mfbt. r=sg

Also move MOZ_MUST_USE before function declarations' specifiers and return type. While clang and gcc's __attribute__((warn_unused_result)) can appear before, between, or after function specifiers and return types, the [[nodiscard]] attribute must precede the function specifiers.

Depends on D108344

Differential Revision: https://phabricator.services.mozilla.com/D108345
This commit is contained in:
Chris Peterson 2021-03-17 03:01:21 +00:00
Родитель 0ea5ad6742
Коммит 7bc752e42b
17 изменённых файлов: 111 добавлений и 111 удалений

Просмотреть файл

@ -118,7 +118,7 @@ class MallocAllocPolicy {
void reportAllocOverflow() const {}
MOZ_MUST_USE bool checkSimulatedOOM() const { return true; }
[[nodiscard]] bool checkSimulatedOOM() const { return true; }
};
/*
@ -167,7 +167,7 @@ class NeverAllocPolicy {
void reportAllocOverflow() const {}
MOZ_MUST_USE bool checkSimulatedOOM() const { return true; }
[[nodiscard]] bool checkSimulatedOOM() const { return true; }
};
} // namespace mozilla

Просмотреть файл

@ -142,7 +142,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;
return rawPtr;

Просмотреть файл

@ -594,7 +594,7 @@ struct AssertionConditionType {
#define MOZ_ALWAYS_TRUE(expr) \
do { \
if (MOZ_LIKELY(expr)) { \
/* Silence MOZ_MUST_USE. */ \
/* Silence [[nodiscard]]. */ \
} else { \
MOZ_DIAGNOSTIC_ASSERT(false, #expr); \
} \

Просмотреть файл

@ -306,7 +306,7 @@ class BufferList : private AllocPolicy {
// Copies aSize bytes from aData into the BufferList. The storage for these
// bytes may be split across multiple buffers. Size() is increased by aSize.
inline MOZ_MUST_USE bool WriteBytes(const char* aData, size_t aSize);
[[nodiscard]] inline bool WriteBytes(const char* aData, size_t aSize);
// Allocates a buffer of at most |aMaxBytes| bytes and, if successful, returns
// that buffer, and places its size in |aSize|. If unsuccessful, returns null
@ -398,8 +398,8 @@ class BufferList : private AllocPolicy {
};
template <typename AllocPolicy>
MOZ_MUST_USE bool BufferList<AllocPolicy>::WriteBytes(const char* aData,
size_t aSize) {
[[nodiscard]] bool BufferList<AllocPolicy>::WriteBytes(const char* aData,
size_t aSize) {
MOZ_RELEASE_ASSERT(mOwning);
MOZ_RELEASE_ASSERT(mStandardCapacity);

Просмотреть файл

@ -81,10 +81,10 @@ class LZ4 {
* buffer (necessarily <= aMaxOutputSize)
* @return true on success, false on failure
*/
static MFBT_API MOZ_MUST_USE bool decompress(const char* aSource,
size_t aInputSize, char* aDest,
size_t aMaxOutputSize,
size_t* aOutputSize);
[[nodiscard]] static MFBT_API bool decompress(const char* aSource,
size_t aInputSize, char* aDest,
size_t aMaxOutputSize,
size_t* aOutputSize);
/**
* If the source stream is malformed, the function will stop decoding
@ -105,11 +105,11 @@ class LZ4 {
* buffer (necessarily <= aMaxOutputSize)
* @return true on success, false on failure
*/
static MFBT_API MOZ_MUST_USE bool decompressPartial(const char* aSource,
size_t aInputSize,
char* aDest,
size_t aMaxOutputSize,
size_t* aOutputSize);
[[nodiscard]] static MFBT_API bool decompressPartial(const char* aSource,
size_t aInputSize,
char* aDest,
size_t aMaxOutputSize,
size_t* aOutputSize);
/*
* Provides the maximum size that LZ4 may output in a "worst case"

Просмотреть файл

@ -280,42 +280,42 @@ template <Endianness ThisEndian>
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 a uintptr_t in ThisEndian endianness from |aPtr| and return it. */
static MOZ_MUST_USE uintptr_t readUintptr(const void* aPtr) {
[[nodiscard]] static uintptr_t readUintptr(const void* aPtr) {
return read<uintptr_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);
}
/** Read an intptr_t in ThisEndian endianness from |aPtr| and return it. */
static MOZ_MUST_USE intptr_t readIntptr(const void* aPtr) {
[[nodiscard]] static intptr_t readIntptr(const void* aPtr) {
return read<intptr_t>(aPtr);
}
@ -353,7 +353,7 @@ class Endian : private EndianUtils {
* 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);
}
@ -382,7 +382,7 @@ class Endian : private EndianUtils {
* 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);
}
@ -413,7 +413,7 @@ class Endian : private EndianUtils {
*/
template <typename T>
MOZ_MUST_USE static T swapToNetworkOrder(T aValue) {
[[nodiscard]] static T swapToNetworkOrder(T aValue) {
return swapToBigEndian(aValue);
}
@ -432,7 +432,7 @@ class Endian : private EndianUtils {
* 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);
}
@ -461,7 +461,7 @@ class Endian : private EndianUtils {
* 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);
}
@ -491,7 +491,7 @@ class Endian : private EndianUtils {
* in network code.
*/
template <typename T>
MOZ_MUST_USE static T swapFromNetworkOrder(T aValue) {
[[nodiscard]] static T swapFromNetworkOrder(T aValue) {
return swapFromBigEndian(aValue);
}

Просмотреть файл

@ -633,8 +633,7 @@ static MOZ_ALWAYS_INLINE bool FuzzyEqualsMultiplicative(
* representable (even though the bit patterns of double precision NaNs can't
* all be exactly represented in single precision).
*/
MOZ_MUST_USE
extern MFBT_API bool IsFloat32Representable(double aValue);
[[nodiscard]] extern MFBT_API bool IsFloat32Representable(double aValue);
} /* namespace mozilla */

Просмотреть файл

@ -181,7 +181,7 @@ inline HashNumber AddUintptrToHash<8>(HashNumber aHash, uintptr_t aValue) {
template <typename T, bool TypeIsNotIntegral = !std::is_integral_v<T>,
bool TypeIsNotEnum = !std::is_enum_v<T>,
std::enable_if_t<TypeIsNotIntegral && TypeIsNotEnum, int> = 0>
MOZ_MUST_USE inline HashNumber AddToHash(HashNumber aHash, T aA) {
[[nodiscard]] inline HashNumber AddToHash(HashNumber aHash, T aA) {
/*
* Try to convert |A| to uint32_t implicitly. If this works, great. If not,
* we'll error out.
@ -190,7 +190,7 @@ MOZ_MUST_USE inline HashNumber AddToHash(HashNumber aHash, T aA) {
}
template <typename A>
MOZ_MUST_USE inline HashNumber AddToHash(HashNumber aHash, A* aA) {
[[nodiscard]] inline HashNumber AddToHash(HashNumber aHash, A* aA) {
/*
* You might think this function should just take a void*. But then we'd only
* catch data pointers and couldn't handle function pointers.
@ -206,12 +206,12 @@ MOZ_MUST_USE inline HashNumber AddToHash(HashNumber aHash, A* aA) {
// first implicitly converted to 32 bits and then passed to AddUintptrToHash()
// to be hashed.
template <typename T, std::enable_if_t<std::is_integral_v<T>, int> = 0>
MOZ_MUST_USE constexpr HashNumber AddToHash(HashNumber aHash, T aA) {
[[nodiscard]] constexpr HashNumber AddToHash(HashNumber aHash, T aA) {
return detail::AddUintptrToHash<sizeof(T)>(aHash, aA);
}
template <typename T, std::enable_if_t<std::is_enum_v<T>, int> = 0>
MOZ_MUST_USE constexpr HashNumber AddToHash(HashNumber aHash, T aA) {
[[nodiscard]] constexpr HashNumber AddToHash(HashNumber aHash, T aA) {
// Hash using AddUintptrToHash with the underlying type of the enum type
using UnderlyingType = typename std::underlying_type<T>::type;
return detail::AddUintptrToHash<sizeof(UnderlyingType)>(
@ -219,7 +219,7 @@ MOZ_MUST_USE constexpr HashNumber AddToHash(HashNumber aHash, T aA) {
}
template <typename A, typename... Args>
MOZ_MUST_USE HashNumber AddToHash(HashNumber aHash, A aArg, Args... aArgs) {
[[nodiscard]] HashNumber AddToHash(HashNumber aHash, A aArg, Args... aArgs) {
return AddToHash(AddToHash(aHash, aArg), aArgs...);
}
@ -231,7 +231,7 @@ MOZ_MUST_USE HashNumber AddToHash(HashNumber aHash, A aArg, Args... aArgs) {
* that x has already been hashed.
*/
template <typename... Args>
MOZ_MUST_USE inline HashNumber HashGeneric(Args... aArgs) {
[[nodiscard]] inline HashNumber HashGeneric(Args... aArgs) {
return AddToHash(0, aArgs...);
}
@ -248,7 +248,7 @@ MOZ_MUST_USE inline HashNumber HashGeneric(Args... aArgs) {
* marginally faster.
*/
template <typename Iterator>
MOZ_MUST_USE constexpr HashNumber HashStringUntilZero(Iterator aIter) {
[[nodiscard]] constexpr HashNumber HashStringUntilZero(Iterator aIter) {
HashNumber hash = 0;
for (; auto c = *aIter; ++aIter) {
hash = AddToHash(hash, c);
@ -260,8 +260,8 @@ MOZ_MUST_USE constexpr HashNumber HashStringUntilZero(Iterator aIter) {
* Hash successive |aIter[i]| up to |i == aLength|.
*/
template <typename Iterator>
MOZ_MUST_USE constexpr HashNumber HashStringKnownLength(Iterator aIter,
size_t aLength) {
[[nodiscard]] constexpr HashNumber HashStringKnownLength(Iterator aIter,
size_t aLength) {
HashNumber hash = 0;
for (size_t i = 0; i < aLength; i++) {
hash = AddToHash(hash, aIter[i]);
@ -275,30 +275,30 @@ MOZ_MUST_USE constexpr HashNumber HashStringKnownLength(Iterator aIter,
* These functions are non-template functions so that users can 1) overload them
* with their own types 2) in a way that allows implicit conversions to happen.
*/
MOZ_MUST_USE inline HashNumber HashString(const char* aStr) {
[[nodiscard]] inline HashNumber HashString(const char* aStr) {
// Use the |const unsigned char*| version of the above so that all ordinary
// character data hashes identically.
return HashStringUntilZero(reinterpret_cast<const unsigned char*>(aStr));
}
MOZ_MUST_USE inline HashNumber HashString(const char* aStr, size_t aLength) {
[[nodiscard]] inline HashNumber HashString(const char* aStr, size_t aLength) {
// Delegate to the |const unsigned char*| version of the above to share
// template instantiations.
return HashStringKnownLength(reinterpret_cast<const unsigned char*>(aStr),
aLength);
}
MOZ_MUST_USE
inline HashNumber HashString(const unsigned char* aStr, size_t aLength) {
[[nodiscard]] inline HashNumber HashString(const unsigned char* aStr,
size_t aLength) {
return HashStringKnownLength(aStr, aLength);
}
MOZ_MUST_USE constexpr HashNumber HashString(const char16_t* aStr) {
[[nodiscard]] constexpr HashNumber HashString(const char16_t* aStr) {
return HashStringUntilZero(aStr);
}
MOZ_MUST_USE inline HashNumber HashString(const char16_t* aStr,
size_t aLength) {
[[nodiscard]] inline HashNumber HashString(const char16_t* aStr,
size_t aLength) {
return HashStringKnownLength(aStr, aLength);
}
@ -308,14 +308,14 @@ MOZ_MUST_USE inline HashNumber HashString(const char16_t* aStr,
template <typename WCharT, typename = typename std::enable_if<
std::is_same<WCharT, wchar_t>::value &&
!std::is_same<wchar_t, char16_t>::value>::type>
MOZ_MUST_USE inline HashNumber HashString(const WCharT* aStr) {
[[nodiscard]] inline HashNumber HashString(const WCharT* aStr) {
return HashStringUntilZero(aStr);
}
template <typename WCharT, typename = typename std::enable_if<
std::is_same<WCharT, wchar_t>::value &&
!std::is_same<wchar_t, char16_t>::value>::type>
MOZ_MUST_USE inline HashNumber HashString(const WCharT* aStr, size_t aLength) {
[[nodiscard]] inline HashNumber HashString(const WCharT* aStr, size_t aLength) {
return HashStringKnownLength(aStr, aLength);
}
@ -325,8 +325,8 @@ MOZ_MUST_USE inline HashNumber HashString(const WCharT* 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 HashNumber HashBytes(const void* bytes,
size_t aLength);
[[nodiscard]] extern MFBT_API HashNumber HashBytes(const void* bytes,
size_t aLength);
/**
* A pseudorandom function mapping 32-bit integers to 32-bit integers.

Просмотреть файл

@ -32,7 +32,7 @@
// - |MallocAllocPolicy| is the default and is usually appropriate; note that
// operations (such as insertions) that might cause allocations are
// fallible and must be checked for OOM. These checks are enforced by the
// use of MOZ_MUST_USE.
// use of [[nodiscard]].
//
// - |InfallibleAllocPolicy| is another possibility; it allows the
// abovementioned OOM checks to be done with MOZ_ALWAYS_TRUE().
@ -212,7 +212,7 @@ class HashMap {
// Attempt to reserve enough space to fit at least |aLen| elements. Does
// nothing if the map already has sufficient capacity.
MOZ_MUST_USE bool reserve(uint32_t aLen) { return mImpl.reserve(aLen); }
[[nodiscard]] bool reserve(uint32_t aLen) { return mImpl.reserve(aLen); }
// -- Lookups --------------------------------------------------------------
@ -247,7 +247,7 @@ class HashMap {
// Overwrite existing value with |aValue|, or add it if not present. Returns
// false on OOM.
template <typename KeyInput, typename ValueInput>
MOZ_MUST_USE bool put(KeyInput&& aKey, ValueInput&& aValue) {
[[nodiscard]] bool put(KeyInput&& aKey, ValueInput&& aValue) {
AddPtr p = lookupForAdd(aKey);
if (p) {
p->value() = std::forward<ValueInput>(aValue);
@ -260,14 +260,14 @@ class HashMap {
// Like put(), but slightly faster. Must only be used when the given key is
// not already present. (In debug builds, assertions check this.)
template <typename KeyInput, typename ValueInput>
MOZ_MUST_USE bool putNew(KeyInput&& aKey, ValueInput&& aValue) {
[[nodiscard]] bool putNew(KeyInput&& aKey, ValueInput&& aValue) {
return mImpl.putNew(aKey, std::forward<KeyInput>(aKey),
std::forward<ValueInput>(aValue));
}
template <typename KeyInput, typename ValueInput>
MOZ_MUST_USE bool putNew(const Lookup& aLookup, KeyInput&& aKey,
ValueInput&& aValue) {
[[nodiscard]] bool putNew(const Lookup& aLookup, KeyInput&& aKey,
ValueInput&& aValue) {
return mImpl.putNew(aLookup, std::forward<KeyInput>(aKey),
std::forward<ValueInput>(aValue));
}
@ -331,15 +331,15 @@ class HashMap {
// Add a key/value. Returns false on OOM.
template <typename KeyInput, typename ValueInput>
MOZ_MUST_USE bool add(AddPtr& aPtr, KeyInput&& aKey, ValueInput&& aValue) {
[[nodiscard]] bool add(AddPtr& aPtr, KeyInput&& aKey, ValueInput&& aValue) {
return mImpl.add(aPtr, std::forward<KeyInput>(aKey),
std::forward<ValueInput>(aValue));
}
// See the comment above lookupForAdd() for details.
template <typename KeyInput, typename ValueInput>
MOZ_MUST_USE bool relookupOrAdd(AddPtr& aPtr, KeyInput&& aKey,
ValueInput&& aValue) {
[[nodiscard]] bool relookupOrAdd(AddPtr& aPtr, KeyInput&& aKey,
ValueInput&& aValue) {
return mImpl.relookupOrAdd(aPtr, aKey, std::forward<KeyInput>(aKey),
std::forward<ValueInput>(aValue));
}
@ -501,7 +501,7 @@ class HashSet {
// Attempt to reserve enough space to fit at least |aLen| elements. Does
// nothing if the map already has sufficient capacity.
MOZ_MUST_USE bool reserve(uint32_t aLen) { return mImpl.reserve(aLen); }
[[nodiscard]] bool reserve(uint32_t aLen) { return mImpl.reserve(aLen); }
// -- Lookups --------------------------------------------------------------
@ -534,7 +534,7 @@ class HashSet {
// Add |aU| if it is not present already. Returns false on OOM.
template <typename U>
MOZ_MUST_USE bool put(U&& aU) {
[[nodiscard]] bool put(U&& aU) {
AddPtr p = lookupForAdd(aU);
return p ? true : add(p, std::forward<U>(aU));
}
@ -542,13 +542,13 @@ class HashSet {
// Like put(), but slightly faster. Must only be used when the given element
// is not already present. (In debug builds, assertions check this.)
template <typename U>
MOZ_MUST_USE bool putNew(U&& aU) {
[[nodiscard]] bool putNew(U&& aU) {
return mImpl.putNew(aU, std::forward<U>(aU));
}
// Like the other putNew(), but for when |Lookup| is different to |T|.
template <typename U>
MOZ_MUST_USE bool putNew(const Lookup& aLookup, U&& aU) {
[[nodiscard]] bool putNew(const Lookup& aLookup, U&& aU) {
return mImpl.putNew(aLookup, std::forward<U>(aU));
}
@ -610,13 +610,14 @@ class HashSet {
// Add an element. Returns false on OOM.
template <typename U>
MOZ_MUST_USE bool add(AddPtr& aPtr, U&& aU) {
[[nodiscard]] bool add(AddPtr& aPtr, U&& aU) {
return mImpl.add(aPtr, std::forward<U>(aU));
}
// See the comment above lookupForAdd() for details.
template <typename U>
MOZ_MUST_USE bool relookupOrAdd(AddPtr& aPtr, const Lookup& aLookup, U&& aU) {
[[nodiscard]] bool relookupOrAdd(AddPtr& aPtr, const Lookup& aLookup,
U&& aU) {
return mImpl.relookupOrAdd(aPtr, aLookup, std::forward<U>(aU));
}
@ -2018,7 +2019,7 @@ class HashTable : private AllocPolicy {
compact();
}
MOZ_MUST_USE bool reserve(uint32_t aLen) {
[[nodiscard]] bool reserve(uint32_t aLen) {
if (aLen == 0) {
return true;
}
@ -2093,7 +2094,7 @@ class HashTable : private AllocPolicy {
}
template <typename... Args>
MOZ_MUST_USE bool add(AddPtr& aPtr, Args&&... aArgs) {
[[nodiscard]] bool add(AddPtr& aPtr, Args&&... aArgs) {
ReentrancyGuard g(*this);
MOZ_ASSERT_IF(aPtr.isValid(), mTable);
MOZ_ASSERT_IF(aPtr.isValid(), aPtr.mTable == this);
@ -2165,7 +2166,7 @@ class HashTable : private AllocPolicy {
// Note: |aLookup| may be alias arguments in |aArgs|, so this function must
// take care not to use |aLookup| after moving |aArgs|.
template <typename... Args>
MOZ_MUST_USE bool putNew(const Lookup& aLookup, Args&&... aArgs) {
[[nodiscard]] bool putNew(const Lookup& aLookup, Args&&... aArgs) {
if (!this->checkSimulatedOOM()) {
return false;
}
@ -2182,8 +2183,8 @@ class HashTable : private AllocPolicy {
// Note: |aLookup| may be a reference to a piece of |u|, so this function
// must take care not to use |aLookup| after moving |u|.
template <typename... Args>
MOZ_MUST_USE bool relookupOrAdd(AddPtr& aPtr, const Lookup& aLookup,
Args&&... aArgs) {
[[nodiscard]] bool relookupOrAdd(AddPtr& aPtr, const Lookup& aLookup,
Args&&... aArgs) {
// Check for error from ensureHash() here.
if (!aPtr.isLive()) {
return false;

Просмотреть файл

@ -23,13 +23,13 @@ namespace mozilla {
* where type T and U both support AddToHash.
*/
template <typename U, typename V>
MOZ_MUST_USE inline HashNumber HashPair(const std::pair<U, V>& pair) {
[[nodiscard]] inline HashNumber HashPair(const std::pair<U, V>& pair) {
// Pair hash combines the hash of each member
return HashGeneric(pair.first, pair.second);
}
template <typename U, typename V>
MOZ_MUST_USE inline HashNumber HashCompactPair(const CompactPair<U, V>& pair) {
[[nodiscard]] inline HashNumber HashCompactPair(const CompactPair<U, V>& pair) {
// Pair hash combines the hash of each member
return HashGeneric(pair.first(), pair.second());
}

Просмотреть файл

@ -123,8 +123,9 @@ class SPSCRingBufferBase {
* @param count The number of elements to enqueue.
* @return The number of element enqueued.
*/
MOZ_MUST_USE
int EnqueueDefault(int aCount) { return Enqueue(nullptr, aCount); }
[[nodiscard]] int EnqueueDefault(int aCount) {
return Enqueue(nullptr, aCount);
}
/**
* @brief Put an element in the queue.
*
@ -134,8 +135,7 @@ class SPSCRingBufferBase {
*
* @return 1 if the element was inserted, 0 otherwise.
*/
MOZ_MUST_USE
int Enqueue(T& aElement) { return Enqueue(&aElement, 1); }
[[nodiscard]] int Enqueue(T& aElement) { return Enqueue(&aElement, 1); }
/**
* Push `aCount` elements in the ring buffer.
*
@ -147,8 +147,7 @@ class SPSCRingBufferBase {
* @return The number of elements successfully coped from `elements` and
* inserted into the ring buffer.
*/
MOZ_MUST_USE
int Enqueue(T* aElements, int aCount) {
[[nodiscard]] int Enqueue(T* aElements, int aCount) {
#ifdef DEBUG
AssertCorrectThread(mProducerId);
#endif
@ -194,8 +193,7 @@ class SPSCRingBufferBase {
* @param count The maximum number of elements to Dequeue.
* @return The number of elements written to `elements`.
*/
MOZ_MUST_USE
int Dequeue(T* elements, int count) {
[[nodiscard]] int Dequeue(T* elements, int count) {
#ifdef DEBUG
AssertCorrectThread(mConsumerId);
#endif

Просмотреть файл

@ -116,7 +116,7 @@ class MOZ_STACK_CLASS ScopeExit {
};
template <typename ExitFunction>
MOZ_MUST_USE ScopeExit<ExitFunction> MakeScopeExit(
[[nodiscard]] ScopeExit<ExitFunction> MakeScopeExit(
ExitFunction&& exitFunction) {
return ScopeExit<ExitFunction>(std::move(exitFunction));
}

Просмотреть файл

@ -156,7 +156,7 @@ class SegmentedVector : private AllocPolicy {
// 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) {
last = this->template pod_malloc<Segment>(1);

Просмотреть файл

@ -170,7 +170,7 @@ class ThreadLocalNativeStorage {
template <typename T, template <typename U> class Storage>
class ThreadLocal : public Storage<T> {
public:
MOZ_MUST_USE inline bool init();
[[nodiscard]] inline bool init();
void infallibleInit() {
MOZ_RELEASE_ASSERT(init(), "Infallible TLS initialization failed");

Просмотреть файл

@ -292,7 +292,7 @@ class UniquePtr {
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;
return p;
@ -403,7 +403,7 @@ class UniquePtr<T[], D> {
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;
return p;

Просмотреть файл

@ -116,7 +116,8 @@ struct VectorImpl {
* aNewCap has not overflowed, and (2) multiplying aNewCap by sizeof(T) will
* not overflow.
*/
static inline MOZ_MUST_USE bool growTo(Vector<T, N, AP>& aV, size_t aNewCap) {
[[nodiscard]] static inline bool growTo(Vector<T, N, AP>& aV,
size_t aNewCap) {
MOZ_ASSERT(!aV.usingInlineStorage());
MOZ_ASSERT(!CapacityHasExcessSpace<T>(aNewCap));
T* newbuf = aV.template pod_malloc<T>(aNewCap);
@ -200,7 +201,8 @@ struct VectorImpl<T, N, AP, true> {
}
}
static inline MOZ_MUST_USE bool growTo(Vector<T, N, AP>& aV, size_t aNewCap) {
[[nodiscard]] static inline bool growTo(Vector<T, N, AP>& aV,
size_t aNewCap) {
MOZ_ASSERT(!aV.usingInlineStorage());
MOZ_ASSERT(!CapacityHasExcessSpace<T>(aNewCap));
T* newbuf =
@ -252,9 +254,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 */
@ -576,7 +578,7 @@ class MOZ_NON_PARAM Vector final : private AllocPolicy {
* 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
@ -585,7 +587,7 @@ class MOZ_NON_PARAM Vector final : private AllocPolicy {
* 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
@ -595,7 +597,7 @@ class MOZ_NON_PARAM Vector final : private AllocPolicy {
* 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
@ -610,18 +612,18 @@ class MOZ_NON_PARAM Vector final : private AllocPolicy {
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();
@ -657,29 +659,29 @@ class MOZ_NON_PARAM Vector final : private AllocPolicy {
* not amused.")
*/
template <typename U>
MOZ_MUST_USE bool append(U&& aU);
[[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;
Impl::new_(&back(), std::forward<Args>(aArgs)...);
return true;
}
template <typename U, size_t O, class BP>
MOZ_MUST_USE bool appendAll(const Vector<U, O, BP>& aU);
[[nodiscard]] bool appendAll(const Vector<U, O, BP>& aU);
template <typename U, size_t O, class BP>
MOZ_MUST_USE bool appendAll(Vector<U, O, BP>&& aU);
MOZ_MUST_USE bool appendN(const T& aT, size_t aN);
[[nodiscard]] bool appendAll(Vector<U, O, BP>&& aU);
[[nodiscard]] bool appendN(const T& aT, size_t aN);
template <typename U>
MOZ_MUST_USE bool append(const U* aBegin, const U* aEnd);
[[nodiscard]] bool append(const U* aBegin, const U* aEnd);
template <typename U>
MOZ_MUST_USE bool append(const U* aBegin, size_t aLength);
[[nodiscard]] bool append(const U* aBegin, size_t aLength);
template <typename U>
MOZ_MUST_USE bool moveAppend(U* aBegin, U* aEnd);
[[nodiscard]] bool moveAppend(U* aBegin, U* aEnd);
/*
* Guaranteed-infallible append operations for use upon vectors whose
@ -719,7 +721,7 @@ class MOZ_NON_PARAM Vector final : private AllocPolicy {
*
* 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
@ -737,7 +739,7 @@ class MOZ_NON_PARAM Vector final : private AllocPolicy {
* 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
@ -776,7 +778,7 @@ class MOZ_NON_PARAM Vector final : private AllocPolicy {
* 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),

Просмотреть файл

@ -36,7 +36,7 @@ class InfallibleAllocPolicy {
};
// 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.