Skip to content

Commit

Permalink
Fix compiler warnings from unncessary abs (#162)
Browse files Browse the repository at this point in the history
* Enhance AbsFunc specialization for signed and unsigned types

Refined the AbsFunc template struct to handle both signed and unsigned types using enable_if conditions. This change introduces specialized behavior, ensuring proper functioning and type safety depending on the numerical type.

* Add RPY_MAYBE_UNUSED to unused member variables

Marked unused member variables with RPY_MAYBE_UNUSED in comparison_trait.h and lie_key.cpp to avoid compiler warnings. This helps in maintaining cleaner code and ensures that warnings are handled properly.
  • Loading branch information
inakleinbottle authored Nov 20, 2024
1 parent efc6961 commit eadda95
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion platform/include/roughpy/generics/comparison_trait.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ConstRef;
*/
class ROUGHPY_PLATFORM_EXPORT ComparisonTrait : public BuiltinTrait
{
const Type* p_type;
RPY_MAYBE_UNUSED const Type* p_type;

protected:
constexpr explicit ComparisonTrait(const Type* type)
Expand Down
14 changes: 13 additions & 1 deletion platform/include/roughpy/generics/number_trait.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ struct AbsFunc : NoSuchFunction {
};

template <typename T>
struct AbsFunc<T, void_t<decltype(abs(declval<T>()))>> {
struct AbsFunc<T, void_t<decltype(abs(declval<T>())), enable_if_t<is_signed_v<T>>>> {
using result_t = decltype(abs(declval<T>()));

static constexpr bool has_function = true;
Expand All @@ -263,6 +263,18 @@ struct AbsFunc<T, void_t<decltype(abs(declval<T>()))>> {
}
};

template <typename T>
struct AbsFunc<T, enable_if_t<is_unsigned_v<T>>>
{
using result_t = T;
static constexpr bool has_function = true;
constexpr result_t operator()(const T& val) const
{
return val;
}
};


template <typename T, typename = void>
struct SqrtFunc : NoSuchFunction {
};
Expand Down
4 changes: 2 additions & 2 deletions roughpy/src/algebra/lie_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ namespace {
class ToLieKeyHelper
{
using container_type = typename python::PyLieKey::container_type;
dimn_t size;
dimn_t current;
RPY_MAYBE_UNUSED dimn_t size;
RPY_MAYBE_UNUSED dimn_t current;
algebra::LieBasis basis;
deg_t width;
let_t max_letter = 0;
Expand Down

0 comments on commit eadda95

Please sign in to comment.