summaryrefslogtreecommitdiff
path: root/lib/verify.h
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2006-01-10 17:47:56 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2006-01-10 17:47:56 +0000
commitd11af4159eb8836696ef29f1e1ac9ad4db348d47 (patch)
tree87dc9cf5d37eebdd601ef33b9925bfb955ff87ff /lib/verify.h
parent71520b31c09c843d37c84abd12694e06428cdd47 (diff)
downloadcoreutils-d11af4159eb8836696ef29f1e1ac9ad4db348d47.tar.xz
Sync from gnulib.
Diffstat (limited to 'lib/verify.h')
-rw-r--r--lib/verify.h47
1 files changed, 28 insertions, 19 deletions
diff --git a/lib/verify.h b/lib/verify.h
index fbabd82c0..328980fa3 100644
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -23,24 +23,33 @@
/* Each of these macros verifies that its argument R is a nonzero
constant expression. To be portable, R's type must be integer (or
- boolean). Unlike assert, there is no run-time overhead. */
-
-/* A type that is valid if and only if R is a nonzero constant expression.
- The symbols verify_type__ and verify_error_if_negative_size__ are
- private to this header file. */
-
-# define verify_type__(R) \
- struct { unsigned int verify_error_if_negative_size__ : (R) ? 1 : -1; }
-
-/* Verify requirement R at compile-time, as a declaration. */
-
-# define verify(R) \
- extern int (* verify_function__ (void)) [sizeof (verify_type__ (R))]
-
-/* Verify requirement R at compile-time, as an expression.
- This macro can be used in some contexts where verify cannot, and vice versa.
- Return void. */
-
-# define verify_expr(R) ((void) ((verify_type__ (R) *) 0))
+ boolean). Unlike assert, there is no run-time overhead.
+
+ There are two macros, since no single macro can be used in all
+ contexts in C. verify_true (R) is for scalar contexts, where it
+ may be cast to void if need be. verify (R) is for declaration
+ contexts, e.g., the top level.
+
+ The symbols verify_error_if_negative_size__ and verify_function__
+ are private to this header. */
+
+/* Verify requirement R at compile-time, as an integer constant expression.
+ Return true. */
+
+# ifdef __cplusplus
+template <int w>
+ struct verify_type__ { unsigned int verify_error_if_negative_size__: w; };
+# define verify_true(R) \
+ (!!sizeof (verify_type__<(R) ? 1 : -1>))
+# else
+# define verify_true(R) \
+ (!!sizeof \
+ (struct { unsigned int verify_error_if_negative_size__: (R) ? 1 : -1; }))
+# endif
+
+/* Verify requirement R at compile-time, as a declaration without a
+ trailing ';'. */
+
+# define verify(R) extern int (* verify_function__ (void)) [verify_true (R)]
#endif