aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2016-08-30 12:00:00 -0400
committerPeter Eisentraut <peter_e@gmx.net>2017-12-26 10:45:07 -0500
commita2c8e5cfdb9d82ae6d4bb8f37a4dc7cbeca63ec1 (patch)
tree881ab6b921979a3f5782324973eff4eda77f36fd
parent0689dc3a235a12c58910fba325f0150979d0c81f (diff)
downloadpostgresql-a2c8e5cfdb9d82ae6d4bb8f37a4dc7cbeca63ec1.tar.gz
postgresql-a2c8e5cfdb9d82ae6d4bb8f37a4dc7cbeca63ec1.zip
Add support for static assertions in C++
This allows modules written in C++ to use or include header files that use StaticAssertStmt() etc. Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
-rw-r--r--src/include/c.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/include/c.h b/src/include/c.h
index 11fcffbae39..22535a7debb 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -754,6 +754,7 @@ typedef NameData *Name;
* about a negative width for a struct bit-field. This will not include a
* helpful error message, but it beats not getting an error at all.
*/
+#ifndef __cplusplus
#ifdef HAVE__STATIC_ASSERT
#define StaticAssertStmt(condition, errmessage) \
do { _Static_assert(condition, errmessage); } while(0)
@@ -765,6 +766,19 @@ typedef NameData *Name;
#define StaticAssertExpr(condition, errmessage) \
StaticAssertStmt(condition, errmessage)
#endif /* HAVE__STATIC_ASSERT */
+#else /* C++ */
+#if defined(__cpp_static_assert) && __cpp_static_assert >= 200410
+#define StaticAssertStmt(condition, errmessage) \
+ static_assert(condition, errmessage)
+#define StaticAssertExpr(condition, errmessage) \
+ StaticAssertStmt(condition, errmessage)
+#else
+#define StaticAssertStmt(condition, errmessage) \
+ do { struct static_assert_struct { int static_assert_failure : (condition) ? 1 : -1; }; } while(0)
+#define StaticAssertExpr(condition, errmessage) \
+ ({ StaticAssertStmt(condition, errmessage); })
+#endif
+#endif /* C++ */
/*