Skip to content

Commit

Permalink
cleanup: Use _Static_assert in gcc/clang.
Browse files Browse the repository at this point in the history
Hopefully they don't throw warnings at us.
  • Loading branch information
iphydf committed Mar 27, 2022
1 parent bc006be commit 96ab891
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .github/scripts/cmake-osx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ add_ld_flag -undefined error
# Make compilation error on a warning
add_flag -Werror

# Allow _Static_assert. Supported C11 extensions are fine, since we have several
# C99-only compilers we test against anyway. Anything that passes all the
# compilers we use is fine.
add_c_flag -Wno-c11-extensions

cmake -B_build -H. \
-DCMAKE_C_FLAGS="$C_FLAGS" \
-DCMAKE_CXX_FLAGS="$CXX_FLAGS" \
Expand Down
7 changes: 4 additions & 3 deletions toxcore/ccompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@
#if !defined(__cplusplus) || __cplusplus < 201103L
#define nullptr NULL
#ifndef static_assert
#define STATIC_ASSERT_(cond, msg, line) typedef int static_assert_##line[(cond) ? 1 : -1]
#define STATIC_ASSERT(cond, msg, line) STATIC_ASSERT_(cond, msg, line)
#ifdef __GNUC__
#define static_assert(cond, msg) __attribute__((__unused__)) STATIC_ASSERT(cond, msg, __LINE__)
// We'll just assume gcc and clang support C11 _Static_assert.
#define static_assert _Static_assert
#else // !__GNUC__
#define STATIC_ASSERT_(cond, msg, line) typedef int static_assert_##line[(cond) ? 1 : -1]
#define STATIC_ASSERT(cond, msg, line) STATIC_ASSERT_(cond, msg, line)
#define static_assert(cond, msg) STATIC_ASSERT(cond, msg, __LINE__)
#endif // !__GNUC__
#endif // !static_assert
Expand Down

0 comments on commit 96ab891

Please sign in to comment.