Bug 1729598 - Replace MOZ_MUST_USE_TYPE with [[nodiscard]]. r=static-analysis-reviewers,andi

Differential Revision: https://phabricator.services.mozilla.com/D125504
This commit is contained in:
Chris Peterson 2021-09-15 05:10:51 +00:00
parent 196daa1700
commit c9530ebe28
10 changed files with 20 additions and 23 deletions

View file

@ -25,7 +25,7 @@ namespace mozilla {
// Allow QMResult errors to use existing stack id and to increase the frame id
// during error propagation.
template <>
class MOZ_MUST_USE_TYPE GenericErrorResult<QMResult> {
class [[nodiscard]] GenericErrorResult<QMResult> {
QMResult mErrorValue;
template <typename V, typename E2>

View file

@ -1161,7 +1161,7 @@ auto CollectWhile(const Cond& aCond, const Body& aBody)
}
template <>
class MOZ_MUST_USE_TYPE GenericErrorResult<mozilla::ipc::IPCResult> {
class [[nodiscard]] GenericErrorResult<mozilla::ipc::IPCResult> {
mozilla::ipc::IPCResult mErrorValue;
template <typename V, typename E2>

View file

@ -55,17 +55,10 @@ namespace image {
* NOT_SUPPORTED: The requested operation is not supported, but the image is
* otherwise valid.
*/
enum class MOZ_MUST_USE_TYPE ImgDrawResult : uint8_t {
SUCCESS,
SUCCESS_NOT_COMPLETE,
INCOMPLETE,
WRONG_SIZE,
NOT_READY,
TEMPORARY_ERROR,
BAD_IMAGE,
BAD_ARGS,
NOT_SUPPORTED
};
enum class [[nodiscard]] ImgDrawResult : uint8_t{
SUCCESS, SUCCESS_NOT_COMPLETE, INCOMPLETE, WRONG_SIZE,
NOT_READY, TEMPORARY_ERROR, BAD_IMAGE, BAD_ARGS,
NOT_SUPPORTED};
/**
* You can combine ImgDrawResults with &. By analogy to bitwise-&, the result is

View file

@ -58,7 +58,7 @@
//
// TODO(heycam): We should perhaps have a similar struct for Owned types with a
// Consume() method to convert them into a UniquePtr. The struct for Strong
// types at least have MOZ_MUST_USE_TYPE on them.
// types at least have [[nodiscard]] on them.
//
//
// Using these types in Rust =========================

View file

@ -38,7 +38,11 @@ struct unused_t;
* Otherwise, use std::move(RefPtr/nsCOMPtr/etc).
*/
template <class T>
struct MOZ_MUST_USE_TYPE MOZ_NON_AUTOABLE already_AddRefed {
struct
#if !defined(MOZ_CLANG_PLUGIN) && !defined(XGILL_PLUGIN)
[[nodiscard]]
#endif
MOZ_NON_AUTOABLE already_AddRefed {
already_AddRefed() : mRawPtr(nullptr) {}
// For simplicity, allow returning nullptr from functions returning

View file

@ -439,7 +439,7 @@ constexpr auto ToResult(Result<V, E>&& aValue)
* V* const, E> is not possible.)
*/
template <typename V, typename E>
class MOZ_MUST_USE_TYPE Result final {
class [[nodiscard]] Result final {
// See class comment on Result<const V, E> and Result<V, const E>.
static_assert(!std::is_const_v<V>);
static_assert(!std::is_const_v<E>);
@ -745,7 +745,7 @@ class MOZ_MUST_USE_TYPE Result final {
* useful in error-handling macros; see MOZ_TRY for an example.
*/
template <typename E>
class MOZ_MUST_USE_TYPE GenericErrorResult {
class [[nodiscard]] GenericErrorResult {
E mErrorValue;
template <typename V, typename E2>

View file

@ -21,7 +21,7 @@ struct ErrorPropagationTag;
// Allow nsresult errors to automatically convert to nsresult values, so MOZ_TRY
// can be used in XPCOM methods with Result<T, nserror> results.
template <>
class MOZ_MUST_USE_TYPE GenericErrorResult<nsresult> {
class [[nodiscard]] GenericErrorResult<nsresult> {
nsresult mErrorValue;
template <typename V, typename E2>

View file

@ -473,8 +473,8 @@ renaming_overrides_prefixing = true
inline bool IsRight() const;
"""
# TODO(emilio): Add hooks to cbindgen to be able to generate MOZ_MUST_USE_TYPE
# or [[nodiscard]] on the functions.
# TODO(emilio): Add hooks to cbindgen to be able to generate [[nodiscard]]
# on the functions.
"Owned" = """
UniquePtr<GeckoType> Consume() {
UniquePtr<GeckoType> ret(ptr);

View file

@ -234,9 +234,9 @@ struct UnusedZero<nsresult> {
} // namespace detail
template <typename T>
class MOZ_MUST_USE_TYPE GenericErrorResult;
class GenericErrorResult;
template <>
class MOZ_MUST_USE_TYPE GenericErrorResult<nsresult>;
class GenericErrorResult<nsresult>;
struct Ok;
template <typename V, typename E>

View file

@ -290,7 +290,7 @@ to OOM).
The ``must_use`` property is useful if the result of a method call or an
attribute get/set should always (or usually) be checked, which is frequently
the case. (e.g. a method that opens a file should almost certainly have its
result checked.) This property will cause ``MOZ_MUST_USE`` to be added to the
result checked.) This property will cause ``[[nodiscard]]`` to be added to the
generated function declarations, which means certain compilers (e.g. clang and
GCC) will reports errors if these results are not used.