diff --git a/platform/mbed_chrono.h b/platform/mbed_chrono.h index a051588c71e..210d64b3fe2 100644 --- a/platform/mbed_chrono.h +++ b/platform/mbed_chrono.h @@ -19,6 +19,7 @@ #ifndef __MBED_CHRONO_H__ #define __MBED_CHRONO_H__ +#include "mbed_toolchain.h" #include #include #include @@ -85,10 +86,7 @@ inline namespace chrono_literals { constexpr chrono::deciseconds operator "" _ds(unsigned long long x) { chrono::deciseconds::rep val = static_cast(x); - if (val < 0) { - assert(false); - } - assert(static_cast(val) == x); + assert(val >= 0 && static_cast(val) == x); return chrono::deciseconds(val); } @@ -106,10 +104,7 @@ constexpr chrono::deciseconds operator "" _ds(unsigned long long x) constexpr chrono::centiseconds operator "" _cs(unsigned long long x) { chrono::centiseconds::rep val = static_cast(x); - if (val < 0) { - assert(false); - } - assert(static_cast(val) == x); + assert(val >= 0 && static_cast(val) == x); return chrono::centiseconds(val); } diff --git a/platform/mbed_toolchain.h b/platform/mbed_toolchain.h index a0fc28cf05e..2fa91d69e26 100644 --- a/platform/mbed_toolchain.h +++ b/platform/mbed_toolchain.h @@ -24,6 +24,15 @@ #define __error_t_defined 1 #endif +/* Work around ARM Compiler 6 bug - assert does not work in constexpr + * functions unless you stop it from using its __promise built-in. + */ +#ifdef __ARMCC_VERSION +#ifndef __DO_NOT_LINK_PROMISE_WITH_ASSERT +#define __DO_NOT_LINK_PROMISE_WITH_ASSERT +#endif +#endif + // Warning for unsupported compilers #if !defined(__GNUC__) /* GCC */ \ && !defined(__clang__) /* LLVM/Clang */ \