From c47c24bbd214e5c0e69f256847ffe470ef8476b3 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 7 Mar 2019 16:32:10 -0500 Subject: [PATCH] common/bit_field: Make BitField trivially copyable This makes the class much more flexible and doesn't make performing copies with classes that contain a bitfield member a pain. Given BitField instances are only intended to be used within unions, the fact the full storage value would be copied isn't a big concern (only sizeof(union_type) would be copied anyways). While we're at it, provide defaulted move constructors for consistency. --- src/common/bit_field.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/common/bit_field.h b/src/common/bit_field.h index 99859d0b13..8131d1f958 100644 --- a/src/common/bit_field.h +++ b/src/common/bit_field.h @@ -125,8 +125,6 @@ private: using StorageTypeWithEndian = typename AddEndian::type; public: - constexpr BitField& operator=(const BitField&) = default; - /// Constants to allow limited introspection of fields if needed static constexpr std::size_t position = Position; static constexpr std::size_t bits = Bits; @@ -162,9 +160,13 @@ public: BitField(T val) = delete; BitField& operator=(T val) = delete; - // Force default constructor to be created - // so that we can use this within unions - constexpr BitField() = default; + constexpr BitField() noexcept = default; + + constexpr BitField(const BitField&) noexcept = default; + constexpr BitField& operator=(const BitField&) noexcept = default; + + constexpr BitField(BitField&&) noexcept = default; + constexpr BitField& operator=(BitField&&) noexcept = default; constexpr operator T() const { return Value();