Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/include Add static_assert macro definition in <assert.h>



details:   https://anonhg.NetBSD.org/src/rev/ef97a32e22d7
branches:  trunk
changeset: 818207:ef97a32e22d7
user:      kamil <kamil%NetBSD.org@localhost>
date:      Mon Oct 03 12:08:39 2016 +0000

description:
Add static_assert macro definition in <assert.h>

This declaration conforms to the C11 standard
Reference: ISO/IEC 9899:201x 7.2 Diagnostics <assert.h>

_Static_assert performs compile-time assertion checking.

According to ISO/IEC 9899:201x (draft) 7.2 Diagnostics <assert.h> defines
the static_assert macro which expands to _Static_assert. It's not
conditionalized by NDEBUG like the assert macro.

According to ISO/IEC N3242=11-0012 (C++1x) the <cassert> header shall
define only the assert macro, but not static_assert as it's already part
of the C++11 language.

Allow to define static_assert in C++ prior the C++11 standard. It might be
broken but a nonstandard C++ compiler might support C11-like _Static_assert
feature. Note that it's fatal for g++ 5.4, but it works for clang++ 3.8.1.

Approved by <joerg>.

diffstat:

 include/assert.h |  8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diffs (19 lines):

diff -r 91931830ae1e -r ef97a32e22d7 include/assert.h
--- a/include/assert.h  Mon Oct 03 11:06:06 2016 +0000
+++ b/include/assert.h  Mon Oct 03 12:08:39 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: assert.h,v 1.21 2011/08/26 01:10:49 joerg Exp $        */
+/*     $NetBSD: assert.h,v 1.22 2016/10/03 12:08:39 kamil Exp $        */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -104,3 +104,9 @@
 void __diagassert13(const char *, int, const char *, const char *);
 __END_DECLS
 #endif /* __ASSERT_DECLARED */
+
+#if ((__cplusplus - 0) < 201103L)
+#ifndef static_assert
+#define static_assert _Static_assert
+#endif /* static_assert */
+#endif



Home | Main Index | Thread Index | Old Index