Skip to content

Improve error messages when a constructed Quantity truncates #391

@hoffbrinkle

Description

@hoffbrinkle

Given some units defined as such1:

struct PerMille : decltype(Percent{} / mag<10>());
struct PerMyriad : decltype(PerMille{} / mag<10>());
struct PerCentMille : decltype(PerMyriad{} / mag<10>());
struct PartsPerMillion : decltype(PerCentMille{} / mag<10>());
struct PartsPerBillion : decltype(PartsPerMillion{} / mag<1'000>());
struct PartsPerTrillion : decltype(PartsPerBillion{} / mag<1'000>());
struct PartsPerQuadrillion : decltype(PartsPerTrillion{} / mag<1'000>());
struct PartsPerQuintillion : decltype(PartsPerQuadrillion{} / mag<1'000>());

Trying to assign from a QuantityI64<PartsPerQuintillion> to a QuantityI64<PartsPerBillion> results in an error message that says there isn't a constructor available:

note: candidate function (the implicit move assignment operator) not viable: no known conversion from 'Quantity<av::embedded::firmware::protocol::ptp::PartsPerQuintillion, [...]>' to 'Quantity<av::embedded::firmware::protocol::ptp::PartsPerBillion, [...]>' for 1st argument

Manually requesting the conversion using .as(PartsPerBillion{}) yields a more useful error:

error: static assertion failed due to requirement 'IMPLICIT_OK': Dangerous conversion for integer Rep!  See: https://aurora-opensource.github.io/au/main/troubleshooting/#dangerous-conversion

Which can then be resolved with a .coerce_as. It would be useful to get the conversion error in the first instance.

Footnotes

  1. https://godbolt.org/z/GjG38c7Yc

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions