Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfaa650a

Browse files
committed
Revert "Refactor compile-time assertion checks in c.h"
This reverts commitb7f64c6, which broke the fallback implementation forC++. We have discussed a couple of alternatives to reduce the number ofimplementations for those asserts, but nothing allowing to reduce thenumber of implementations down to three instead of four, so there is nobenefit in keeping this patch.Thanks to Tom Lane for the discussion.Discussion:https://postgr.es/m/20200313115033.GA183471@paquier.xyz
1 parent33753ac commitfaa650a

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

‎src/include/c.h

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -836,37 +836,43 @@ extern void ExceptionalCondition(const char *conditionName,
836836
* The macro StaticAssertDecl() is suitable for use at file scope (outside of
837837
* any function).
838838
*
839-
* On recent C++ compilers, we can use standard static_assert().
840-
*
841839
* Otherwise we fall back on a kluge that assumes the compiler will complain
842840
* about a negative width for a struct bit-field. This will not include a
843841
* helpful error message, but it beats not getting an error at all.
844842
*/
845-
#if !defined(__cplusplus)&& defined(HAVE__STATIC_ASSERT)
846-
/* Default C implementation */
843+
#ifndef__cplusplus
844+
#ifdefHAVE__STATIC_ASSERT
847845
#defineStaticAssertStmt(condition,errmessage) \
848846
do { _Static_assert(condition, errmessage); } while(0)
849847
#defineStaticAssertExpr(condition,errmessage) \
850848
((void) ({ StaticAssertStmt(condition, errmessage); true; }))
851849
#defineStaticAssertDecl(condition,errmessage) \
852850
_Static_assert(condition, errmessage)
853-
#elif defined(__cplusplus)&&__cpp_static_assert >=200410
854-
/* Default C++ implementation */
851+
#else/* !HAVE__STATIC_ASSERT */
852+
#defineStaticAssertStmt(condition,errmessage) \
853+
((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; }))
854+
#defineStaticAssertExpr(condition,errmessage) \
855+
StaticAssertStmt(condition, errmessage)
856+
#defineStaticAssertDecl(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
855861
#defineStaticAssertStmt(condition,errmessage) \
856862
static_assert(condition, errmessage)
857863
#defineStaticAssertExpr(condition,errmessage) \
858864
({ static_assert(condition, errmessage); })
859865
#defineStaticAssertDecl(condition,errmessage) \
860866
static_assert(condition, errmessage)
861-
#else
862-
/* Fallback implementation for C and C++ */
867+
#else/* !__cpp_static_assert */
863868
#defineStaticAssertStmt(condition,errmessage) \
864-
((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; }))
869+
do {structstatic_assert_struct{ int static_assert_failure : (condition) ? 1 : -1; }; } while(0)
865870
#defineStaticAssertExpr(condition,errmessage) \
866-
StaticAssertStmt(condition, errmessage)
871+
((void) ({StaticAssertStmt(condition, errmessage); }))
867872
#defineStaticAssertDecl(condition,errmessage) \
868873
extern void static_assert_func(int static_assert_failure[(condition) ? 1 : -1])
869-
#endif
874+
#endif/* __cpp_static_assert */
875+
#endif/* C++ */
870876

871877

872878
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp