Skip to content

Commit

Permalink
Use std::bit_not instead of ~
Browse files Browse the repository at this point in the history
This removes a GCC warning about excessive casting that MSVC actually requires
  • Loading branch information
Blake-Madden committed Jun 6, 2024
1 parent 0014950 commit 544b446
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ AlwaysBreakTemplateDeclarations: Yes
SpaceAfterTemplateKeyword: false
AlignAfterOpenBracket: Align
InsertBraces: true
IndentPPDirectives: BeforeHash
12 changes: 6 additions & 6 deletions tinyexpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ namespace te_builtins

// force the bit manipulation to stay unsigned, like what Excel does
const uint8_t intVal{ static_cast<uint8_t>(val) };
const decltype(intVal) result{ static_cast<decltype(intVal)>(~intVal) };
const decltype(intVal) result{ std::bit_not<decltype(intVal)>{}(intVal) };
return static_cast<te_type>(result);
}

Expand All @@ -769,7 +769,7 @@ namespace te_builtins
}

const uint16_t intVal{ static_cast<uint16_t>(val) };
const decltype(intVal) result{ static_cast<decltype(intVal)>(~intVal) };
const decltype(intVal) result{ std::bit_not<decltype(intVal)>{}(intVal) };
return static_cast<te_type>(result);
}

Expand All @@ -795,7 +795,7 @@ namespace te_builtins
}

const uint32_t intVal{ static_cast<uint32_t>(val) };
const decltype(intVal) result{ ~intVal };
const decltype(intVal) result{ std::bit_not<decltype(intVal)>{}(intVal) };
return static_cast<te_type>(result);
}

Expand All @@ -821,7 +821,7 @@ namespace te_builtins
}

const uint64_t intVal{ static_cast<uint64_t>(val) };
const decltype(intVal) result{ ~intVal };
const decltype(intVal) result{ std::bit_not<decltype(intVal)>{}(intVal) };
return static_cast<te_type>(result);
}

Expand Down Expand Up @@ -1210,7 +1210,7 @@ const std::set<te_variable> te_parser::m_functions = { // NOLINT
#ifndef TE_FLOAT
{ "bitand", static_cast<te_fun2>(te_builtins::te_bitwise_and), TE_PURE },
{ "bitor", static_cast<te_fun2>(te_builtins::te_bitwise_or), TE_PURE },
#if __cplusplus >= 202002L
#if __cplusplus >= 202002L
{ "bitlrotate8", static_cast<te_fun2>(te_builtins::te_left_rotate8), TE_PURE },
{ "bitrrotate8", static_cast<te_fun2>(te_builtins::te_right_rotate8), TE_PURE },
{ "bitlrotate16", static_cast<te_fun2>(te_builtins::te_left_rotate16), TE_PURE },
Expand All @@ -1221,7 +1221,7 @@ const std::set<te_variable> te_parser::m_functions = { // NOLINT
{ "bitrrotate64", static_cast<te_fun2>(te_builtins::te_right_rotate64), TE_PURE },
{ "bitlrotate", static_cast<te_fun2>(te_builtins::te_left_rotate), TE_PURE },
{ "bitrrotate", static_cast<te_fun2>(te_builtins::te_right_rotate), TE_PURE },
#endif
#endif
{ "bitnot8", static_cast<te_fun1>(te_builtins::te_bitwise_not8), TE_PURE },
{ "bitnot16", static_cast<te_fun1>(te_builtins::te_bitwise_not16), TE_PURE },
{ "bitnot32", static_cast<te_fun1>(te_builtins::te_bitwise_not32), TE_PURE },
Expand Down
8 changes: 5 additions & 3 deletions tinyexpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@
#include <variant>
#include <vector>
#if __has_include(<bit>)
#include <bit>
#include <bit>
#endif

class te_parser;

#if defined(TE_FLOAT) && defined(TE_LONG_DOUBLE)
#error TE_FLOAT and TE_LONG_DOUBLE compile options cannot be combined. Only one data type can be specified.
#error TE_FLOAT and TE_LONG_DOUBLE compile options cannot be combined. Only one data type can be specified.
#endif

/// @brief Define this to use @c float instead of @c double for the parser's data type.
Expand All @@ -92,7 +92,7 @@ using te_type = double;
#endif

#if defined(TE_FLOAT) && defined(TE_BITWISE_OPERATORS)
#error TE_FLOAT and TE_BITWISE_OPERATORS compile options cannot be combined. TE_FLOAT will not support bitwise operations.
#error TE_FLOAT and TE_BITWISE_OPERATORS compile options cannot be combined. TE_FLOAT will not support bitwise operations.
#endif

class te_expr;
Expand Down Expand Up @@ -245,6 +245,7 @@ class te_parser
public:
/// @private
te_parser() = default;

/// @private
// cppcheck-suppress uninitMemberVar
te_parser(const te_parser& that)
Expand All @@ -254,6 +255,7 @@ class te_parser
m_decimalSeparator(that.m_decimalSeparator), m_listSeparator(that.m_listSeparator)
{
}

/// @private
te_parser& operator=(const te_parser& that)
{
Expand Down

0 comments on commit 544b446

Please sign in to comment.