We have a fairly common anti-pattern where a CheckedNumeric is correctly used for all the necessary math operations, but then the value is extracted into a destination type that cannot represent the full range of source values. It looks like this:
base CheckedNumeric<size_t> buffer_size;
// ... various math operations on buffer_size ...
int len = buffer_size.ValueOrDie(); // silent truncation from size_t to int.
The easiest way to detect these is just change the return type on the value returning functions from Dst to StrictNumeric<Dst> and then look at the list of compile failures.
The only solution I have in mind right now is to support overloaded return types on the value extraction functions and have them all return StrictNumeric<Dst> as a proxy class. The downside is that this breaks auto, but I can add some operator overloads to mitigate that, and a value extraction method to handle the remaining corner cases.
Comment 1 by bugdroid1@chromium.org
, Nov 25 2016