Skip to content

feature request - allow disabling floating point implicit conversion #528

@ghorn

Description

@ghorn

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions