Re:Catching integer overflows with template metaprogramming ...
by jbapple on Monday March 27, 2017 @12:26AM
(#13965172)
While I agree with your essential point about #1, I think we agree for different reasons.
UBSan is a set of run-time checks and has low compile-time cost. The example function you give, f, would be complained about if you passed it INT_MAX, but that complaint would come at run-time and it would never be triggered if you never passed it INT_MAX.
I also agree that it is not possible to enforce non-INT_MAX limits, like x < 10.
Re:Catching integer overflows with template metaprogramming ...
by kentonv on Monday March 27, 2017 @01:27AM
(#13965380)
Oh, for some reason I thought Clang's sanitizers were strictly compile-time, but looking closer I see that's not correct. Hmm, will have to look closer at that.
UBSan is a set of run-time checks and has low compile-time cost. The example function you give, f, would be complained about if you passed it INT_MAX, but that complaint would come at run-time and it would never be triggered if you never passed it INT_MAX.
I also agree that it is not possible to enforce non-INT_MAX limits, like x < 10.