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

Commita2c8e5c

Browse files
committed
Add support for static assertions in C++
This allows modules written in C++ to use or include header files thatuse StaticAssertStmt() etc.Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
1 parent0689dc3 commita2c8e5c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

‎src/include/c.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@ typedef NameData *Name;
754754
* about a negative width for a struct bit-field. This will not include a
755755
* helpful error message, but it beats not getting an error at all.
756756
*/
757+
#ifndef__cplusplus
757758
#ifdefHAVE__STATIC_ASSERT
758759
#defineStaticAssertStmt(condition,errmessage) \
759760
do { _Static_assert(condition, errmessage); } while(0)
@@ -765,6 +766,19 @@ typedef NameData *Name;
765766
#defineStaticAssertExpr(condition,errmessage) \
766767
StaticAssertStmt(condition, errmessage)
767768
#endif/* HAVE__STATIC_ASSERT */
769+
#else/* C++ */
770+
#if defined(__cpp_static_assert)&&__cpp_static_assert >=200410
771+
#defineStaticAssertStmt(condition,errmessage) \
772+
static_assert(condition, errmessage)
773+
#defineStaticAssertExpr(condition,errmessage) \
774+
StaticAssertStmt(condition, errmessage)
775+
#else
776+
#defineStaticAssertStmt(condition,errmessage) \
777+
do { struct static_assert_struct { int static_assert_failure : (condition) ? 1 : -1; }; } while(0)
778+
#defineStaticAssertExpr(condition,errmessage) \
779+
({ StaticAssertStmt(condition, errmessage); })
780+
#endif
781+
#endif/* C++ */
768782

769783

770784
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp