From c3f743a7631fcf8e76ea648de9ec9362f8643a19 Mon Sep 17 00:00:00 2001 From: Chris Kitching Date: Thu, 19 Oct 2017 13:34:02 +0100 Subject: [PATCH] Add [[nodiscard]] attribute to hipError_t in C++17 mode This will yield a compiler warning any time you discard an error return value from an API call. [ROCm/clr commit: 939fa02ade27cbde15bd6fe4f999952afd00b9ac] --- projects/clr/hipamd/include/hip/hip_runtime_api.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/projects/clr/hipamd/include/hip/hip_runtime_api.h b/projects/clr/hipamd/include/hip/hip_runtime_api.h index 97733964bf..a2ebcd27a5 100644 --- a/projects/clr/hipamd/include/hip/hip_runtime_api.h +++ b/projects/clr/hipamd/include/hip/hip_runtime_api.h @@ -143,6 +143,13 @@ typedef struct hipPointerAttribute_t { * */ +// Ignoring error-code return values from hip APIs is discouraged. On C++17, +// we can make that yield a warning +#if __cplusplus >= 201703L +#define __HIP_NODISCARD [[nodiscard]] +#else +#define __HIP_NODISCARD +#endif /* * @brief hipError_t @@ -152,7 +159,7 @@ typedef struct hipPointerAttribute_t { // Developer note - when updating these, update the hipErrorName and hipErrorString functions in NVCC and HCC paths // Also update the hipCUDAErrorTohipError function in NVCC path. -typedef enum hipError_t { +typedef enum __HIP_NODISCARD hipError_t { hipSuccess = 0, ///< Successful completion. hipErrorOutOfMemory = 2, hipErrorNotInitialized = 3, @@ -219,6 +226,8 @@ typedef enum hipError_t { hipErrorTbd ///< Marker that more error codes are needed. } hipError_t; +#undef __HIP_NODISCARD + /* * @brief hipDeviceAttribute_t * @enum