Commit f0d2747df165dca20b815615fafc03bba315d23b

Ozkan Sezer 2022-03-17T14:56:04

use _Static_assert for SDL_COMPILE_TIME_ASSERT(), when available

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h
index c0d194c..4554f9e 100644
--- a/include/SDL_stdinc.h
+++ b/include/SDL_stdinc.h
@@ -354,8 +354,14 @@ typedef uint64_t Uint64;
 #endif
 #endif /* SDL_DISABLE_ANALYZE_MACROS */
 
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
+#define SDL_COMPILE_TIME_ASSERT(name, x) _Static_assert(x, #x);
+#elif defined(__cplusplus) && (__cplusplus >= 201103L)
+#define SDL_COMPILE_TIME_ASSERT(name, x)  static_assert(x, #x);
+#else /* universal, but may trigger -Wunused-local-typedefs */
 #define SDL_COMPILE_TIME_ASSERT(name, x)               \
        typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1]
+#endif
 /** \cond */
 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
 SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);