Skip to content

Commit

Permalink
fixes 'std::ptrdiff_t' to 'std::size_t' casting error
Browse files Browse the repository at this point in the history
addresses this compiler warning:

```text
[..]/magic_enum_utility.hpp:101:31: warning: conversion to ‘std::size_t’ {aka ‘long unsigned int’} from ‘std::ptrdiff_t’ {aka ‘long int’} may change the sign of the result [-Wsign-conversion]
  101 |       return enum_value<D, S>(index);
      |                               ^~~~~
```
  • Loading branch information
RalphSteinhagen committed Nov 9, 2023
1 parent 49bb72d commit a7f9047
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions include/magic_enum_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ template <typename E, detail::enum_subtype S = detail::subtype_v<E>>
if (const auto i = enum_index<D, S>(value)) {
const std::ptrdiff_t index = (static_cast<std::ptrdiff_t>(*i) + n);
if (index >= 0 && index < count) {
return enum_value<D, S>(index);
return enum_value<D, S>(static_cast<std::size_t>(index));
}
}
return {};
Expand All @@ -98,7 +98,7 @@ template <typename E, detail::enum_subtype S = detail::subtype_v<E>>
if (const auto i = enum_index<D, S>(value)) {
const std::ptrdiff_t index = ((((static_cast<std::ptrdiff_t>(*i) + n) % count) + count) % count);
if (index >= 0 && index < count) {
return enum_value<D, S>(index);
return enum_value<D, S>(static_cast<std::size_t>(index));
}
}
return MAGIC_ENUM_ASSERT(false), value;
Expand All @@ -112,7 +112,7 @@ template <typename E, detail::enum_subtype S = detail::subtype_v<E>>
if (const auto i = enum_index<D, S>(value)) {
const std::ptrdiff_t index = (static_cast<std::ptrdiff_t>(*i) - n);
if (index >= 0 && index < count) {
return enum_value<D, S>(index);
return enum_value<D, S>(static_cast<std::size_t>(index));
}
}
return {};
Expand All @@ -126,7 +126,7 @@ template <typename E, detail::enum_subtype S = detail::subtype_v<E>>
if (const auto i = enum_index<D, S>(value)) {
const std::ptrdiff_t index = ((((static_cast<std::ptrdiff_t>(*i) - n) % count) + count) % count);
if (index >= 0 && index < count) {
return enum_value<D, S>(index);
return enum_value<D, S>(static_cast<std::size_t>(index));
}
}
return MAGIC_ENUM_ASSERT(false), value;
Expand Down

0 comments on commit a7f9047

Please sign in to comment.