summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Lioncash2021-06-05 06:05:39 -0400
committerGravatar Lioncash2021-06-05 06:09:07 -0400
commit25b73e135fc37d6b7792d27f28496523a28200af (patch)
treee6e2c3b93000b1cae97285d53bf1a86c3f8b91e6 /src
parentMerge pull request #6362 from lat9nq/reset-to-defaults (diff)
downloadyuzu-25b73e135fc37d6b7792d27f28496523a28200af.tar.gz
yuzu-25b73e135fc37d6b7792d27f28496523a28200af.tar.xz
yuzu-25b73e135fc37d6b7792d27f28496523a28200af.zip
result: Add [[nodiscard]] specifiers where applicable
The result code classes are used quite extensively throughout both the kernel and service HLE code. We can mark these member functions as [[nodiscard]] to prevent a few logic bugs from slipping through.
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/result.h40
1 files changed, 20 insertions, 20 deletions
diff --git a/src/core/hle/result.h b/src/core/hle/result.h
index 605236552..a755008d5 100644
--- a/src/core/hle/result.h
+++ b/src/core/hle/result.h
@@ -124,21 +124,21 @@ union ResultCode {
124 constexpr ResultCode(ErrorModule module_, u32 description_) 124 constexpr ResultCode(ErrorModule module_, u32 description_)
125 : raw(module.FormatValue(module_) | description.FormatValue(description_)) {} 125 : raw(module.FormatValue(module_) | description.FormatValue(description_)) {}
126 126
127 constexpr bool IsSuccess() const { 127 [[nodiscard]] constexpr bool IsSuccess() const {
128 return raw == 0; 128 return raw == 0;
129 } 129 }
130 130
131 constexpr bool IsError() const { 131 [[nodiscard]] constexpr bool IsError() const {
132 return raw != 0; 132 return !IsSuccess();
133 } 133 }
134}; 134};
135 135
136constexpr bool operator==(const ResultCode& a, const ResultCode& b) { 136[[nodiscard]] constexpr bool operator==(const ResultCode& a, const ResultCode& b) {
137 return a.raw == b.raw; 137 return a.raw == b.raw;
138} 138}
139 139
140constexpr bool operator!=(const ResultCode& a, const ResultCode& b) { 140[[nodiscard]] constexpr bool operator!=(const ResultCode& a, const ResultCode& b) {
141 return a.raw != b.raw; 141 return !operator==(a, b);
142} 142}
143 143
144// Convenience functions for creating some common kinds of errors: 144// Convenience functions for creating some common kinds of errors:
@@ -200,7 +200,7 @@ public:
200 * specify the success code. `success_code` must not be an error code. 200 * specify the success code. `success_code` must not be an error code.
201 */ 201 */
202 template <typename... Args> 202 template <typename... Args>
203 static ResultVal WithCode(ResultCode success_code, Args&&... args) { 203 [[nodiscard]] static ResultVal WithCode(ResultCode success_code, Args&&... args) {
204 ResultVal<T> result; 204 ResultVal<T> result;
205 result.emplace(success_code, std::forward<Args>(args)...); 205 result.emplace(success_code, std::forward<Args>(args)...);
206 return result; 206 return result;
@@ -259,49 +259,49 @@ public:
259 } 259 }
260 260
261 /// Returns true if the `ResultVal` contains an error code and no value. 261 /// Returns true if the `ResultVal` contains an error code and no value.
262 bool empty() const { 262 [[nodiscard]] bool empty() const {
263 return result_code.IsError(); 263 return result_code.IsError();
264 } 264 }
265 265
266 /// Returns true if the `ResultVal` contains a return value. 266 /// Returns true if the `ResultVal` contains a return value.
267 bool Succeeded() const { 267 [[nodiscard]] bool Succeeded() const {
268 return result_code.IsSuccess(); 268 return result_code.IsSuccess();
269 } 269 }
270 /// Returns true if the `ResultVal` contains an error code and no value. 270 /// Returns true if the `ResultVal` contains an error code and no value.
271 bool Failed() const { 271 [[nodiscard]] bool Failed() const {
272 return empty(); 272 return empty();
273 } 273 }
274 274
275 ResultCode Code() const { 275 [[nodiscard]] ResultCode Code() const {
276 return result_code; 276 return result_code;
277 } 277 }
278 278
279 const T& operator*() const { 279 [[nodiscard]] const T& operator*() const {
280 return object; 280 return object;
281 } 281 }
282 T& operator*() { 282 [[nodiscard]] T& operator*() {
283 return object; 283 return object;
284 } 284 }
285 const T* operator->() const { 285 [[nodiscard]] const T* operator->() const {
286 return &object; 286 return &object;
287 } 287 }
288 T* operator->() { 288 [[nodiscard]] T* operator->() {
289 return &object; 289 return &object;
290 } 290 }
291 291
292 /// Returns the value contained in this `ResultVal`, or the supplied default if it is missing. 292 /// Returns the value contained in this `ResultVal`, or the supplied default if it is missing.
293 template <typename U> 293 template <typename U>
294 T ValueOr(U&& value) const { 294 [[nodiscard]] T ValueOr(U&& value) const {
295 return !empty() ? object : std::move(value); 295 return !empty() ? object : std::move(value);
296 } 296 }
297 297
298 /// Asserts that the result succeeded and returns a reference to it. 298 /// Asserts that the result succeeded and returns a reference to it.
299 T& Unwrap() & { 299 [[nodiscard]] T& Unwrap() & {
300 ASSERT_MSG(Succeeded(), "Tried to Unwrap empty ResultVal"); 300 ASSERT_MSG(Succeeded(), "Tried to Unwrap empty ResultVal");
301 return **this; 301 return **this;
302 } 302 }
303 303
304 T&& Unwrap() && { 304 [[nodiscard]] T&& Unwrap() && {
305 ASSERT_MSG(Succeeded(), "Tried to Unwrap empty ResultVal"); 305 ASSERT_MSG(Succeeded(), "Tried to Unwrap empty ResultVal");
306 return std::move(**this); 306 return std::move(**this);
307 } 307 }
@@ -320,7 +320,7 @@ private:
320 * `T` with and creates a success `ResultVal` contained the constructed value. 320 * `T` with and creates a success `ResultVal` contained the constructed value.
321 */ 321 */
322template <typename T, typename... Args> 322template <typename T, typename... Args>
323ResultVal<T> MakeResult(Args&&... args) { 323[[nodiscard]] ResultVal<T> MakeResult(Args&&... args) {
324 return ResultVal<T>::WithCode(ResultSuccess, std::forward<Args>(args)...); 324 return ResultVal<T>::WithCode(ResultSuccess, std::forward<Args>(args)...);
325} 325}
326 326
@@ -329,7 +329,7 @@ ResultVal<T> MakeResult(Args&&... args) {
329 * copy or move constructing. 329 * copy or move constructing.
330 */ 330 */
331template <typename Arg> 331template <typename Arg>
332ResultVal<std::remove_reference_t<Arg>> MakeResult(Arg&& arg) { 332[[nodiscard]] ResultVal<std::remove_reference_t<Arg>> MakeResult(Arg&& arg) {
333 return ResultVal<std::remove_reference_t<Arg>>::WithCode(ResultSuccess, std::forward<Arg>(arg)); 333 return ResultVal<std::remove_reference_t<Arg>>::WithCode(ResultSuccess, std::forward<Arg>(arg));
334} 334}
335 335