Skip to content

Commit

Permalink
Merge pull request #5 from arkadiuszwojcik/static_assert
Browse files Browse the repository at this point in the history
Implement static assert
  • Loading branch information
ikskuh authored Jan 11, 2025
2 parents 5281055 + e21e92f commit 62de5f4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ extern FOUNDATION_LIBC_NORETURN void foundation_libc_assert(char const * asserti
#error "bad definition of FOUNDATION_LIBC_ASSERT_DEFAULT!"
#endif

#if !defined(__cplusplus)
#undef static_assert
#define static_assert FOUNDATION_LIBC_STATIC_ASSERT
#endif

#endif
2 changes: 2 additions & 0 deletions include/foundation/builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__))
Expand Down
4 changes: 4 additions & 0 deletions test/src/assert-validator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

0 comments on commit 62de5f4

Please sign in to comment.