@@ -836,43 +836,37 @@ extern void ExceptionalCondition(const char *conditionName,
836
836
* The macro StaticAssertDecl() is suitable for use at file scope (outside of
837
837
* any function).
838
838
*
839
+ * On recent C++ compilers, we can use standard static_assert().
840
+ *
839
841
* Otherwise we fall back on a kluge that assumes the compiler will complain
840
842
* about a negative width for a struct bit-field. This will not include a
841
843
* helpful error message, but it beats not getting an error at all.
842
844
*/
843
- #ifndef __cplusplus
844
- #ifdef HAVE__STATIC_ASSERT
845
+ #if !defined( __cplusplus ) && defined( HAVE__STATIC_ASSERT )
846
+ /* Default C implementation */
845
847
#define StaticAssertStmt (condition , errmessage ) \
846
848
do { _Static_assert(condition, errmessage); } while(0)
847
849
#define StaticAssertExpr (condition , errmessage ) \
848
850
((void) ({ StaticAssertStmt(condition, errmessage); true; }))
849
851
#define StaticAssertDecl (condition , errmessage ) \
850
852
_Static_assert(condition, errmessage)
851
- #else /* !HAVE__STATIC_ASSERT */
852
- #define StaticAssertStmt (condition , errmessage ) \
853
- ((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; }))
854
- #define StaticAssertExpr (condition , errmessage ) \
855
- StaticAssertStmt(condition, errmessage)
856
- #define StaticAssertDecl (condition , errmessage ) \
857
- extern void static_assert_func(int static_assert_failure[(condition) ? 1 : -1])
858
- #endif /* HAVE__STATIC_ASSERT */
859
- #else /* C++ */
860
- #if defined(__cpp_static_assert ) && __cpp_static_assert >= 200410
853
+ #elif defined(__cplusplus ) && __cpp_static_assert >= 200410
854
+ /* Default C++ implementation */
861
855
#define StaticAssertStmt (condition , errmessage ) \
862
856
static_assert(condition, errmessage)
863
857
#define StaticAssertExpr (condition , errmessage ) \
864
858
({ static_assert(condition, errmessage); })
865
859
#define StaticAssertDecl (condition , errmessage ) \
866
860
static_assert(condition, errmessage)
867
- #else /* !__cpp_static_assert */
861
+ #else
862
+ /* Fallback implementation for C and C++ */
868
863
#define StaticAssertStmt (condition , errmessage ) \
869
- do { struct static_assert_struct { int static_assert_failure : (condition) ? 1 : -1; }; } while(0 )
864
+ ((void) sizeof( struct { int static_assert_failure : (condition) ? 1 : -1; }) )
870
865
#define StaticAssertExpr (condition , errmessage ) \
871
- ((void) ({ StaticAssertStmt(condition, errmessage); }) )
866
+ StaticAssertStmt(condition, errmessage)
872
867
#define StaticAssertDecl (condition , errmessage ) \
873
868
extern void static_assert_func(int static_assert_failure[(condition) ? 1 : -1])
874
- #endif /* __cpp_static_assert */
875
- #endif /* C++ */
869
+ #endif
876
870
877
871
878
872
/*
0 commit comments