Fix the class-memaccess warning

This commit is contained in:
Jean Pierre Cimalando 2020-10-10 03:07:07 +02:00
parent f333013dff
commit 80ee358523
2 changed files with 34 additions and 21 deletions

View file

@ -15,18 +15,26 @@ ModKey::Parameters::Parameters() noexcept
// zero-fill the structure // zero-fill the structure
// 1. this ensures that non-used values will be always 0 // 1. this ensures that non-used values will be always 0
// 2. this makes the object memcmp-comparable // 2. this makes the object memcmp-comparable
std::memset(this, 0, sizeof(*this)); std::memset(
static_cast<RawParameters*>(this),
0, sizeof(RawParameters));
} }
ModKey::Parameters::Parameters(const Parameters& other) noexcept ModKey::Parameters::Parameters(const Parameters& other) noexcept
{ {
std::memcpy(this, &other, sizeof(*this)); std::memcpy(
static_cast<RawParameters*>(this),
static_cast<const RawParameters*>(&other),
sizeof(RawParameters));
} }
ModKey::Parameters& ModKey::Parameters::operator=(const Parameters& other) noexcept ModKey::Parameters& ModKey::Parameters::operator=(const Parameters& other) noexcept
{ {
if (this != &other) if (this != &other)
std::memcpy(this, &other, sizeof(*this)); std::memcpy(
static_cast<RawParameters*>(this),
static_cast<const RawParameters*>(&other),
sizeof(RawParameters));
return *this; return *this;
} }

View file

@ -42,24 +42,7 @@ public:
bool isTarget() const noexcept; bool isTarget() const noexcept;
std::string toString() const; std::string toString() const;
struct Parameters { struct RawParameters {
Parameters() noexcept;
Parameters(const Parameters& other) noexcept;
Parameters& operator=(const Parameters& other) noexcept;
Parameters(Parameters&&) = delete;
Parameters &operator=(Parameters&&) = delete;
bool operator==(const Parameters& other) const noexcept
{
return std::memcmp(this, &other, sizeof(*this)) == 0;
}
bool operator!=(const Parameters& other) const noexcept
{
return std::memcmp(this, &other, sizeof(*this)) != 0;
}
union { union {
//! Parameters if this key identifies a CC source //! Parameters if this key identifies a CC source
struct { uint16_t cc; uint8_t curve, smooth; float step; }; struct { uint16_t cc; uint8_t curve, smooth; float step; };
@ -71,6 +54,28 @@ public:
}; };
}; };
struct Parameters : RawParameters {
Parameters() noexcept;
Parameters(const Parameters& other) noexcept;
Parameters& operator=(const Parameters& other) noexcept;
Parameters(Parameters&&) = delete;
Parameters &operator=(Parameters&&) = delete;
bool operator==(const Parameters& other) const noexcept
{
return std::memcmp(
static_cast<const RawParameters*>(this),
static_cast<const RawParameters*>(&other),
sizeof(RawParameters)) == 0;
}
bool operator!=(const Parameters& other) const noexcept
{
return !operator==(other);
}
};
public: public:
bool operator==(const ModKey &other) const noexcept bool operator==(const ModKey &other) const noexcept
{ {