Created attachment 13993 [details] Minimal example of the code causing the problem The attached code is miscompiled at optimization levels -Os and above and the checks in checked_add function are apparently ignored. Reproduced on FreeBSD and Windows with clang 3.5.0 (release=r217039) and 3.6.0(tags/RELEASE_360/final).
Looks like undefined behavior to me. signed integer overflow (as happens at the beginning of the call to checked_add when passed max_int) is undefined. Since your program unconditionally executes that addition, the behavior of the entire program is undefined - nothing it does, even before the point of the addition, is guaranteed by the C++ standard.