Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: mbed-os/TESTS/mbedmicro-mbed/static_assert/test_cpp.cpp
- Revision:
- 0:8fdf9a60065b
diff -r 000000000000 -r 8fdf9a60065b mbed-os/TESTS/mbedmicro-mbed/static_assert/test_cpp.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os/TESTS/mbedmicro-mbed/static_assert/test_cpp.cpp Wed Oct 10 00:33:53 2018 +0000
@@ -0,0 +1,47 @@
+#include "mbed_assert.h"
+#define THE_ANSWER 42
+
+// Tests for static asserts in different contexts
+// multiple asserts are used to guarantee no conflicts occur in generated labels
+
+// Test for static asserts in global context
+MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
+ "An int must be larger than char");
+MBED_STATIC_ASSERT(2 + 2 == 4,
+ "Hopefully the universe is mathematically consistent");
+MBED_STATIC_ASSERT(THE_ANSWER == 42,
+ "Said Deep Thought, with infinite majesty and calm");
+
+struct test {
+ int dummy;
+
+ // Test for static asserts in struct context
+ MBED_STRUCT_STATIC_ASSERT(sizeof(int) >= sizeof(char),
+ "An int must be larger than char");
+ MBED_STRUCT_STATIC_ASSERT(2 + 2 == 4,
+ "Hopefully the universe is mathematically consistent");
+ MBED_STRUCT_STATIC_ASSERT(THE_ANSWER == 42,
+ "Said Deep Thought, with infinite majesty and calm");
+
+ MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
+ "An int must be larger than char");
+ MBED_STATIC_ASSERT(2 + 2 == 4,
+ "Hopefully the universe is mathematically consistent");
+ MBED_STATIC_ASSERT(THE_ANSWER == 42,
+ "Said Deep Thought, with infinite majesty and calm");
+};
+
+MBED_STATIC_ASSERT(sizeof(struct test) == sizeof(int),
+ "Static assertions should not change the size of a struct");
+
+void doit_c(void)
+{
+ // Test for static asserts in function context
+ MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
+ "An int must be larger than char");
+ MBED_STATIC_ASSERT(2 + 2 == 4,
+ "Hopefully the universe is mathematically consistent");
+ MBED_STATIC_ASSERT(THE_ANSWER == 42,
+ "Said Deep Thought, with infinite majesty and calm");
+}
+