llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

unsuppressable error about invalid bitwise operation between different enumeration types

Open jackua22 opened this issue 2 years ago • 4 comments

We use Infiniband API installed on hundreds of servers in our farm. It is in /usr/include/infiniband/verbs.h. For R&D, it is third-party software. This program #include <infiniband/verbs.h> Then compilation fails like this

/grid/common/test/llvm-v18.1.1d1rh74_lnx86/bin/clang++ -c -std=c++26 -Wno-error -Wno-enum-conversion -Wno-deprecated-anon-enum-enum-conversion enum.cpp
In file included from enum.cpp:1:
/usr/include/infiniband/verbs.h:550:53: error: invalid bitwise operation between different enumeration types ('(unnamed enum at /usr/include/infiniband/verbs.h:539:1)' and 'ibv_create_cq_wc_flags')
  550 |         IBV_CREATE_CQ_SUP_WC_FLAGS = IBV_WC_STANDARD_FLAGS |
      |                                      ~~~~~~~~~~~~~~~~~~~~~ ^
  551 |                                 IBV_WC_EX_WITH_COMPLETION_TIMESTAMP |
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

With -std=++2b, it does not. The error is correct. What is incorrect is that the error has no ID and cannot be suppressed in any known way. According to this page https://clang.llvm.org/docs/DiagnosticsReference.html#wanon-enum-enum-conversion I can make the second enum anon, too, by adding -Dibv_create_cq_wc_flags= to the command line. The error changes but stays an error:

/usr/include/infiniband/verbs.h:550:53: error: invalid bitwise operation between different enumeration types ('(unnamed enum at /usr/include/infiniband/verbs.h:539:1)' and
      '(unnamed enum at /usr/include/infiniband/verbs.h:524:1)')

This is a wrong general situation, every message must have an ID and be suppressable. This is some info about the header: -rw-r--r-- 1 root root 92862 Mar 22 2021 /usr/include/infiniband/verbs.h a07809625d1024f1dfdf3db62a66ce88 /usr/include/infiniband/verbs.h I am unsure if copying a couple of lines from that header to this ticket is a good idea.

jackua22 avatar May 16 '24 03:05 jackua22

CC @cor3ntin I think this is 1cbd52f791d3f

shafik avatar May 16 '24 23:05 shafik

We ran into the same problem with the same header when turning on C++26. For obvious reasons, I can't "change [our] previously correct, working code because of this" as @AaronBallman suggested in the PR.

I would suggest suppressing this error or downgrading to a warning in system headers, or perhaps if at least one of the operands is an unnamed enum.

timsong-cpp avatar Mar 18 '25 00:03 timsong-cpp

Given that this has come up twice now, we may want to consider https://github.com/llvm/llvm-project/pull/73105#pullrequestreview-1755467464 -- CC @cor3ntin

AaronBallman avatar Mar 18 '25 11:03 AaronBallman

Thanks for the fix!

It looks like this also affects Cocoa.h, and AppleClang doesn't have the fix yet. I filed https://feedbackassistant.apple.com/feedback/21478051 for that (https://openradar.appspot.com/21478051).

(Edit: Full error, in case it case something searches for it: error: invalid bitwise operation between different enumeration types ('CGImageAlphaInfo' and 'CGImageComponentInfo'))

nico avatar Dec 30 '25 20:12 nico