-
Notifications
You must be signed in to change notification settings - Fork 29
Description
au permits implicit floating point conversions by design, including conversions which reduce precision.
GCC and Clang have a -Wfloat-conversion flag (implied by -Wconversion) which prevents implicit conversions from double to float. Clang-tidy has the cppcoreguidelines-narrowing-conversions check (aliased by bugprone-narrowing-conversions) which also enforces this.
In a codebase with these warnings/checks enable, it was surprising to me when a au::Quantity<Unit, double> was implicitly cast to au::Quantity<Unit, float>. It led to a subtle bug.
I'm guessing that there is no desire to remove the implicit conversions feature. On the other hand, in a codebase with -Wfloat-conversion / cppcoreguidelines-narrowing-conversions, the au::Quantity implicit conversions are essentially a "leak". What are your thoughts on this situation? How could it be possible for a codebase to disallow these implicit conversions? What would you think of something like a -DAU_NO_IMPLICIT_FLOAT_CONVERSIONS flag?