error: use of bitwise '|' with boolean operands

1.5k views Asked by At

Little update... The error code come from notcurses.h so can't change that and also since 3 months I compile without problem but now

when #include <notcurses/notcurses.h> I obtain this error !

/opt/homebrew/Cellar/notcurses/3.0.9_1/include/notcurses/notcurses.h:205:12: error: use of bitwise '|' with boolean operands [-Werror,-Wbitwise-instead-of-logical]
  return !(ncchannel_default_p(channel) | ncchannel_palindex_p(channel));
          ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                        ||
/opt/homebrew/Cellar/notcurses/3.0.9_1/include/notcurses/notcurses.h:205:12: note: cast one or both operands to int to silence this warning
1 error generated.

I don't think it's related to notcurses itself... but last week, everything was ok. I came back from a trip with my laptop and when trying to compile, I now have this error.

In notcurses.h the function in error is :

201 // Is this channel using RGB color?
202 static inline bool
203 ncchannel_rgb_p(uint32_t channel){
# 204   ***// bitwise or is intentional (allows compiler more freedom)***
205   return !(ncchannel_default_p(channel) | ncchannel_palindex_p(channel));
206 }

I tried to update brew, gcc, and notcurses I use $(pkg-config --cflags --libs notcurses) in compilation

Is there a way to resolve that without

  • modifying notcurses.h
  • removing -Werror -Wall -Wextra on compile line

Should I reinstall MacOs ?

3

There are 3 answers

0
Motomotes On

One could replace the

205   return !(ncchannel_default_p(channel) | ncchannel_palindex_p(channel));

with

205   return !(!(channel & NC_BGDEFAULT_MASK) | (channel & (NC_BGDEFAULT_MASK | NC_BG_PALETTE)) 

to resolve the warning and to allow the compiler to prevent branching with ||.

0
chqrlie On

The simplest fix, without investigating into bitmask optimisation is to convert the boolean predicate function return value to int as suggested by the compiler:

// Is this channel using RGB color?
static inline bool ncchannel_rgb_p(uint32_t channel) {
   // bitwise or is intentional (allows compiler more freedom)
   return !(+ncchannel_default_p(channel) | +ncchannel_palindex_p(channel));
}
2
nick black On

notcurses author here. i wish you would have brought this to our bugtracker; it would have been addressed months ago! we're handling it right now as part of https://github.com/dankamongmen/notcurses/pull/2746