On 4/6/22 01:24, arn...@skeeve.com wrote:
Most people
would wonder "Why is there a bitwise and here?" and not think of it
as a logical and.
I'm not sure I agree about the "most", as I expect most people won't
notice or care about this level of detail. However, for people who
wonder like that, about adding an explanatory comment? That will help
people who are unaccustomed to this valid and useful (albeit
less-common) programming style. Something like the attached (untested)
patch, perhaps?
& for a logical test can be dangerous since any non-zero
value can be true.
Sure, but that's an issue only when using & on types like 'int'. It's
not an issue when using & on 'bool'. Similarly, + has rounding issues on
'float' but that doesn't mean we need to worry about +'s rounding issues
on 'int'.diff --git a/lib/dfa.c b/lib/dfa.c
index a27d096f73..391c2ffbf2 100644
--- a/lib/dfa.c
+++ b/lib/dfa.c
@@ -43,6 +43,11 @@
MMU will check anyway. */
#define assume_nonnull(x) assume ((x) != NULL)
+/* Pacify Clang. */
+#ifdef clang
+ #pragma clang diagnostic ignored "-Wbitwise-instead-of-logical"
+#endif
+
static bool
streq (char const *a, char const *b)
{
@@ -1089,6 +1094,8 @@ parse_bracket_exp (struct dfa *dfa)
/* Treat [x-y] as a range if x != y. */
if (wc != wc2 || wc == WEOF)
{
+ /* Use "&" instead of "&&", as short-circuit evaluation is
+ not needed and might even slow things down. */
if (dfa->localeinfo.simple
|| (isasciidigit (c) & isasciidigit (c2)))
{