[gjs: 3/10] maint: Avoid bogus cppcheck warning about missing return with enable_if_t




commit 77aab924370a292815b47b835c23bb0bed107ed8
Author: Philip Chimento <philip chimento gmail com>
Date:   Sun Jan 16 16:37:35 2022 -0800

    maint: Avoid bogus cppcheck warning about missing return with enable_if_t
    
    This is reported at https://trac.cppcheck.net/ticket/10732 however, the
    workaround seems like it's somewhat more readable than the original, so
    let's keep this.

 gi/function.cpp | 27 +++++++++------------------
 1 file changed, 9 insertions(+), 18 deletions(-)
---
diff --git a/gi/function.cpp b/gi/function.cpp
index 5c4fa4a28..ef8857294 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -9,7 +9,6 @@
 
 #include <memory>  // for unique_ptr
 #include <string>
-#include <type_traits>
 #include <vector>
 
 #include <ffi.h>
@@ -178,23 +177,15 @@ class Function : public CWrapper<Function> {
 }  // namespace Gjs
 
 template <typename T, GITypeTag TAG = GI_TYPE_TAG_VOID>
-static inline std::enable_if_t<std::is_integral_v<T> && std::is_signed_v<T>>
-set_ffi_arg(void* result, GIArgument* value) {
-    *static_cast<ffi_sarg*>(result) = gjs_arg_get<T, TAG>(value);
-}
-
-template <typename T, GITypeTag TAG = GI_TYPE_TAG_VOID>
-static inline std::enable_if_t<std::is_floating_point_v<T> ||
-                               std::is_unsigned_v<T>>
-set_ffi_arg(void* result, GIArgument* value) {
-    *static_cast<ffi_arg*>(result) = gjs_arg_get<T, TAG>(value);
-}
-
-template <typename T, GITypeTag TAG = GI_TYPE_TAG_VOID>
-static inline std::enable_if_t<std::is_pointer_v<T>> set_ffi_arg(
-    void* result, GIArgument* value) {
-    *static_cast<ffi_arg*>(result) =
-        gjs_pointer_to_int<ffi_arg>(gjs_arg_get<T, TAG>(value));
+static inline void set_ffi_arg(void* result, GIArgument* value) {
+    if constexpr (std::is_integral_v<T> && std::is_signed_v<T>) {
+        *static_cast<ffi_sarg*>(result) = gjs_arg_get<T, TAG>(value);
+    } else if constexpr (std::is_floating_point_v<T> && std::is_unsigned_v<T>) {
+        *static_cast<ffi_arg*>(result) = gjs_arg_get<T, TAG>(value);
+    } else if constexpr (std::is_pointer_v<T>) {
+        *static_cast<ffi_arg*>(result) =
+            gjs_pointer_to_int<ffi_arg>(gjs_arg_get<T, TAG>(value));
+    }
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]