From 95a14e77fc82bd49ac667b6ce993da5ad8d12e52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arkadiusz=20W=C3=B3jcik?= Date: Fri, 10 Jan 2025 23:30:55 +0100 Subject: [PATCH 1/3] Implement static assert --- include/assert.h | 2 ++ include/foundation/builtins.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/include/assert.h b/include/assert.h index 16c4979..624363e 100644 --- a/include/assert.h +++ b/include/assert.h @@ -40,4 +40,6 @@ extern FOUNDATION_LIBC_NORETURN void foundation_libc_assert(char const * asserti #error "bad definition of FOUNDATION_LIBC_ASSERT_DEFAULT!" #endif +#define static_assert FOUNDATION_LIBC_STATIC_ASSERT + #endif diff --git a/include/foundation/builtins.h b/include/foundation/builtins.h index e95803e..a5b57b9 100644 --- a/include/foundation/builtins.h +++ b/include/foundation/builtins.h @@ -12,6 +12,8 @@ #define FOUNDATION_LIBC_ASSERT FOUNDATION_LIBC_ASSERT_DEFAULT #endif +#define FOUNDATION_LIBC_STATIC_ASSERT _Static_assert + #if defined(__clang__) #define FOUNDATION_LIBC_NORETURN __attribute__((__noreturn__)) From 098891de6b9c2c0dd8f94985bc227cbac27c8973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arkadiusz=20W=C3=B3jcik?= Date: Fri, 10 Jan 2025 23:38:39 +0100 Subject: [PATCH 2/3] Exclude from C++ builds --- include/assert.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/assert.h b/include/assert.h index 624363e..b7eaf75 100644 --- a/include/assert.h +++ b/include/assert.h @@ -40,6 +40,8 @@ extern FOUNDATION_LIBC_NORETURN void foundation_libc_assert(char const * asserti #error "bad definition of FOUNDATION_LIBC_ASSERT_DEFAULT!" #endif +#if !defined(__cplusplus) #define static_assert FOUNDATION_LIBC_STATIC_ASSERT +#endif #endif From e21e92ffa863128c06f488cab5006d568181d13b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arkadiusz=20W=C3=B3jcik?= Date: Sat, 11 Jan 2025 10:21:03 +0100 Subject: [PATCH 3/3] Fix build error, add test --- include/assert.h | 1 + test/src/assert-validator.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/include/assert.h b/include/assert.h index b7eaf75..74ab2cd 100644 --- a/include/assert.h +++ b/include/assert.h @@ -41,6 +41,7 @@ extern FOUNDATION_LIBC_NORETURN void foundation_libc_assert(char const * asserti #endif #if !defined(__cplusplus) +#undef static_assert #define static_assert FOUNDATION_LIBC_STATIC_ASSERT #endif diff --git a/test/src/assert-validator.c b/test/src/assert-validator.c index b75ca55..db1f492 100644 --- a/test/src/assert-validator.c +++ b/test/src/assert-validator.c @@ -23,3 +23,7 @@ void assert_ok(void) { void assert_bad(void) { assert(0); } + +void assert_static(void) { + static_assert(sizeof(int) == sizeof(int), "int size check"); +}