summaryrefslogtreecommitdiffstats
path: root/include/assert.h
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2011-12-29 14:41:17 +0000
committered <ed@FreeBSD.org>2011-12-29 14:41:17 +0000
commit6b1695514efa6e705884f7d15166aecea36a7109 (patch)
tree50309d6357daf075303c5d87a8558a92b3f59fe4 /include/assert.h
parentf9bb345c0851c34aa1058639a5701a0e86cf63f6 (diff)
downloadFreeBSD-src-6b1695514efa6e705884f7d15166aecea36a7109.zip
FreeBSD-src-6b1695514efa6e705884f7d15166aecea36a7109.tar.gz
Don't define static_assert for C++.
Even though _Static_assert() is pretty robust for C code, it cannot work correctly with C++ code. This is due to the fact that C++ template parameters may contain commas that are not enclosed in parentheses. For example: static_assert(foo<int, int>::bar == baz, "..."); This causes _Static_assert to be called with an excessive number of parameters. If you want to use static_assert in C++, just use a C++11 compiler. Reported on: current@, ports@
Diffstat (limited to 'include/assert.h')
-rw-r--r--include/assert.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/include/assert.h b/include/assert.h
index 6633d8f..c880a78 100644
--- a/include/assert.h
+++ b/include/assert.h
@@ -58,7 +58,16 @@
#ifndef _ASSERT_H_
#define _ASSERT_H_
-#if __ISO_C_VISIBLE >= 2011 && (!defined(__cplusplus) || __cplusplus < 201103L)
+/*
+ * Static assertions. In principle we could define static_assert for
+ * C++ older than C++11, but this breaks if _Static_assert is
+ * implemented as a macro.
+ *
+ * C++ template parameters may contain commas, even if not enclosed in
+ * parentheses, causing the _Static_assert macro to be invoked with more
+ * than two parameters.
+ */
+#if __ISO_C_VISIBLE >= 2011 && !defined(__cplusplus)
#define static_assert _Static_assert
#endif
OpenPOWER on IntegriCloud