From 8932b28b8a128318a1308bb5bb028d2cba690bd0 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Mon, 26 Dec 2022 09:17:22 -0500 Subject: [PATCH] AK: Mark Error::from_ functions as [[nodiscard]] Prevents mistakes like the one fixed in #16672. --- AK/Error.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/AK/Error.h b/AK/Error.h index b963532a52..50185897f5 100644 --- a/AK/Error.h +++ b/AK/Error.h @@ -21,9 +21,9 @@ namespace AK { class Error { public: - static Error from_errno(int code) { return Error(code); } - static Error from_syscall(StringView syscall_name, int rc) { return Error(syscall_name, rc); } - static Error from_string_view(StringView string_literal) { return Error(string_literal); } + [[nodiscard]] static Error from_errno(int code) { return Error(code); } + [[nodiscard]] static Error from_syscall(StringView syscall_name, int rc) { return Error(syscall_name, rc); } + [[nodiscard]] static Error from_string_view(StringView string_literal) { return Error(string_literal); } // NOTE: Prefer `from_string_literal` when directly typing out an error message: // @@ -32,7 +32,7 @@ public: // If you need to return a static string based on a dynamic condition (like // picking an error from an array), then prefer `from_string_view` instead. template - ALWAYS_INLINE static Error from_string_literal(char const (&string_literal)[N]) + [[nodiscard]] ALWAYS_INLINE static Error from_string_literal(char const (&string_literal)[N]) { return from_string_view(StringView { string_literal, N - 1 }); }