Merge pull request #12906 from kjbracey-arm/chrono_asserts

Work around C++14 assert problem
pull/12959/head
Martin Kojtal 2020-05-12 14:27:04 +02:00 committed by GitHub
commit f13db5fa76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View File

@ -19,6 +19,7 @@
#ifndef __MBED_CHRONO_H__
#define __MBED_CHRONO_H__
#include "mbed_toolchain.h"
#include <cstdint>
#include <cassert>
#include <ratio>
@ -85,10 +86,7 @@ inline namespace chrono_literals {
constexpr chrono::deciseconds operator "" _ds(unsigned long long x)
{
chrono::deciseconds::rep val = static_cast<chrono::deciseconds::rep>(x);
if (val < 0) {
assert(false);
}
assert(static_cast<unsigned long long>(val) == x);
assert(val >= 0 && static_cast<unsigned long long>(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<chrono::centiseconds::rep>(x);
if (val < 0) {
assert(false);
}
assert(static_cast<unsigned long long>(val) == x);
assert(val >= 0 && static_cast<unsigned long long>(val) == x);
return chrono::centiseconds(val);
}

View File

@ -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 */ \