MikeLankamp / fpm

C++ header-only fixed-point math library
https://mikelankamp.github.io/fpm
MIT License
673 stars 85 forks source link

Cannot result in a constant expression errors #52

Open vladipus opened 1 year ago

vladipus commented 1 year ago

Binary operators like:

template <typename B, typename I, unsigned int F, bool R> constexpr inline fixed<B, I, F, R> operator+(const fixed<B, I, F, R>& x, const fixed<B, I, F, R>& y) noexcept { return fixed<B, I, F, R>(x) += y; }

are defined as constexpr but the += operator is never constexpr which results in a "cannot result in a constant expression" error.

serjzimmerman commented 1 year ago

I too encountered this issue. However, it seems intentional to me because this library aims to support C++11 which does not allow operator overloads to be constexpr. I did not look very closely into the code, but I think constexpr could be conditionally enabled for C++14 using version specific macros