Skip to content

Work around C++14 assert problem #12906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions platform/mbed_chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifndef __MBED_CHRONO_H__
#define __MBED_CHRONO_H__

#include "mbed_toolchain.h"
#include <cstdint>
#include <cassert>
#include <ratio>
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
9 changes: 9 additions & 0 deletions platform/mbed_toolchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */ \
Expand Down