1
0
Fork 0
forked from suyu/suyu

fixed_point: Mark default constructor as constexpr

Ensures that a fixed-point value is always initialized

This likely also fixes several cases of uninitialized values being
operated on, since we have multiple areas in the codebase where the
default constructor is being used like:

Common::FixedPoint<50, 14> current_sample{};

and is then followed up with an arithmetic operation like += or
something else, which operates directly on FixedPoint's internal data
member, which would previously be uninitialized.
This commit is contained in:
Lioncash 2022-10-18 15:37:37 -04:00
parent b6119a55f9
commit 6e1c6297a3

View file

@ -267,7 +267,7 @@ public:
static constexpr base_type one = base_type(1) << fractional_bits; static constexpr base_type one = base_type(1) << fractional_bits;
public: // constructors public: // constructors
FixedPoint() = default; constexpr FixedPoint() = default;
constexpr FixedPoint(const FixedPoint&) = default; constexpr FixedPoint(const FixedPoint&) = default;
constexpr FixedPoint& operator=(const FixedPoint&) = default; constexpr FixedPoint& operator=(const FixedPoint&) = default;
@ -463,7 +463,7 @@ public:
} }
public: public:
base_type data_; base_type data_{};
}; };
// if we have the same fractional portion, but differing integer portions, we trivially upgrade the // if we have the same fractional portion, but differing integer portions, we trivially upgrade the