Skip to content

Commit 4df46fb

Browse files
authored
Merge pull request #478 from theamirocohen/static_assert
Implement a STATIC_ASSERT macro
2 parents a2b8ff5 + 4fee899 commit 4df46fb

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

api/inc/uvisor_exports.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,19 @@
7777
/** Static Assertion Macro
7878
*
7979
* This macro works from both inside and outside function scope.
80-
*
81-
* FIXME This is currently not implemented. This issue is tracked at
82-
* https://github.com/ARMmbed/uvisor/issues/288
83-
*/
84-
#define UVISOR_STATIC_ASSERT(cond, msg)
80+
* The implementations differ due to compilation differences, C++ static_assert
81+
* is known from C++11 (__cplusplus > 199711L) while mbed-os compiles with c++98,
82+
* and C _Static_assert is known from GCC version 4.6.0. */
83+
#define GCC_VERSION (__GNUC__ * 10000 \
84+
+ __GNUC_MINOR__ * 100 \
85+
+ __GNUC_PATCHLEVEL__)
86+
#if (__cplusplus > 199711L)
87+
#define UVISOR_STATIC_ASSERT(cond, msg) static_assert(cond, #msg)
88+
#elif (!__cplusplus && GCC_VERSION > 40600)
89+
#define UVISOR_STATIC_ASSERT(cond, msg) _Static_assert(cond, #msg)
90+
#else
91+
#define UVISOR_STATIC_ASSERT(cond, msg) typedef char STATIC_ASSERT_##msg[(cond)?1:-1]
92+
#endif
8593

8694
/* convert macro argument to string */
8795
/* note: this needs one level of indirection, accomplished with the helper macro

tools/uvisor-tests.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0ac4c38729d2602bff96d68983a7790143210912
1+
0fc7c7f55507421463ba46a9692008e87a1ac5f2

0 commit comments

Comments
 (0)