On 06/13/2011 08:10 PM, Paul Eggert wrote: > It's relatively common to want to verify a property at compile-time > inside an expression, when using a macro. For example, in Emacs, > I might want to do something like this: > > #define ENCODE_CHAR(charset, c) \ > (verify_true (sizeof (c) <= sizeof (int)), \ > [some expression that assumes sizeof (c) <= sizeof (int)]) > > Unfortunately this elicits the following diagnostic with GCC 4.6.0: > > charset.c:1767:14: error: left-hand operand of comma expression has no > effect [-Werror=unused-value]
And I agree that adding a cast to void to silence that gcc warning is undesirable. > > So I am thinking of a new macro verify_expr (R, E), which verifies R > at compile-time and then yields the value of E. Then the Emacs macro > can be written this way: > > #define ENCODE_CHAR(charset, c) \ > verify_expr (sizeof (c) <= sizeof (int), \ > [some expression that assumes sizeof (c) <= sizeof (int)]) Looks good to me. > +++ b/tests/test-verify.c > @@ -39,7 +39,7 @@ verify (1 == 1); verify (1 == 1); /* should be ok */ > > enum > { > - item = verify_true (1 == 1) * 0 + 17 /* should be ok */ > + item = verify_expr (1 == 1, 1) * 0 + 17 /* should be ok */ > }; > > static int > @@ -55,9 +55,9 @@ function (int n) > verify (1 == 1); verify (1 == 1); /* should be ok */ > > if (n) > - return ((void) verify_true (1 == 1), verify_true (1 == 1) + 7); /* > should be ok */ > + return ((void) verify_expr (1 == 1, 1), verify_expr (1 == 1, 8)); /* > should be ok */ Even though verify_true is deprecated by your patch, should we still be testing that it compiles? Particularly since in your patch, you did not #define verify_true in terms of verify_expr, but instead defined both in terms of _GL_VERIFY_EXPR. -- Eric Blake ebl...@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature