-
Notifications
You must be signed in to change notification settings - Fork 810
Fix enum-enum math for compatibility with C++20 #1671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
r-barnes
wants to merge
1
commit into
linux-rdma:master
Choose a base branch
from
r-barnes:richard/constants
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Signed-off-by: Richard Barnes <[email protected]>
8f8d321 to
9847215
Compare
r-barnes
added a commit
to r-barnes/monarch
that referenced
this pull request
Dec 15, 2025
Summary:
Generated by running
```
hg backout D88882181
hg backout D89083275
hg backout D88911049
```
and then adding explicit casts.
`infiniband/verbs.h` caused C++20 compilation failures due to enum-enum math which could not simply be suppressed because it's a header file.
D88882181 converted `enum` to constants to allow the math to work and because the enums themselves seemed suspect. This caused compilation to succeed with C++20 and unblock a number of broken tests.
But it broke Rust! D89083275 and D88911049 fix Rust by artificially restoring the `enum` values. But that's a mess.
Here we back out both D88882181 and D89083275 and D88911049. Doing so brings us back to a state where the following compilation error would arise:
```
buck-out/v2/gen/fbsource/third-party/rdma-core/stablev60/__ibverbs__/c01e142197f8fe04/buck-headers/infiniband/verbs.h:573:59: error: bitwise operation between different enumeration types ('(unnamed enum at buck-out/v2/gen/fbsource/third-party/rdma-core/stablev60/__ibverbs__/c01e142197f8fe04/buck-headers/infiniband/verbs.h:562:1)' and 'ibv_create_cq_wc_flags') is deprecated [-Werror,-Wdeprecated-anon-enum-enum-conversion]
573 | IBV_CREATE_CQ_SUP_WC_FLAGS = ((((((IBV_WC_STANDARD_FLAGS) | (IBV_WC_EX_WITH_COMPLETION_TIMESTAMP)) | (IBV_WC_EX_WITH_CVLAN)) | (IBV_WC_EX_WITH_FLOW_TAG)) | (IBV_WC_EX_WITH_TM_INFO)) | (IBV_WC_EX_WITH_COMPLETION_TIMESTAMP_WALLCLOCK))
| ~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
This time we fix the error by adding explicit `(int)` casts to the affected Line 573.
The result is code that:
* Compiles with C++20 by explicitly suppressing the issue causing the compilation failure
* Retains the enums so that builds with Rust work.
Upstream PR: linux-rdma/rdma-core#1671
See discussion [here](https://fb.workplace.com/groups/rust.language/permalink/30268407786114448/).
Reviewed By: peterdelevoryas
Differential Revision: D89088011
Member
|
I think since these are intended to be used by an application that will | them together the only answer is to change them to #define's. Otherwise the app will hit these warnings too. |
Member
|
And if we are going to do this we should do it for all the enum's being used for defining bit fields. |
meta-codesync bot
pushed a commit
to meta-pytorch/monarch
that referenced
this pull request
Dec 16, 2025
…sts (#2147) Summary: Pull Request resolved: #2147 Generated by running ``` hg backout D88882181 hg backout D89083275 hg backout D88911049 ``` and then adding explicit casts. `infiniband/verbs.h` caused C++20 compilation failures due to enum-enum math which could not simply be suppressed because it's a header file. D88882181 converted `enum` to constants to allow the math to work and because the enums themselves seemed suspect. This caused compilation to succeed with C++20 and unblock a number of broken tests. But it broke Rust! D89083275 and D88911049 fix Rust by artificially restoring the `enum` values. But that's a mess. Here we back out both D88882181 and D89083275 and D88911049. Doing so brings us back to a state where the following compilation error would arise: ``` buck-out/v2/gen/fbsource/third-party/rdma-core/stablev60/__ibverbs__/c01e142197f8fe04/buck-headers/infiniband/verbs.h:573:59: error: bitwise operation between different enumeration types ('(unnamed enum at buck-out/v2/gen/fbsource/third-party/rdma-core/stablev60/__ibverbs__/c01e142197f8fe04/buck-headers/infiniband/verbs.h:562:1)' and 'ibv_create_cq_wc_flags') is deprecated [-Werror,-Wdeprecated-anon-enum-enum-conversion] 573 | IBV_CREATE_CQ_SUP_WC_FLAGS = ((((((IBV_WC_STANDARD_FLAGS) | (IBV_WC_EX_WITH_COMPLETION_TIMESTAMP)) | (IBV_WC_EX_WITH_CVLAN)) | (IBV_WC_EX_WITH_FLOW_TAG)) | (IBV_WC_EX_WITH_TM_INFO)) | (IBV_WC_EX_WITH_COMPLETION_TIMESTAMP_WALLCLOCK)) | ~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` This time we fix the error by adding explicit `(int)` casts to the affected Line 573. The result is code that: * Compiles with C++20 by explicitly suppressing the issue causing the compilation failure * Retains the enums so that builds with Rust work. Upstream PR: linux-rdma/rdma-core#1671 See discussion [here](https://fb.workplace.com/groups/rust.language/permalink/30268407786114448/). Reviewed By: peterdelevoryas Differential Revision: D89088011 fbshipit-source-id: 9a0164b34e02e0f06781b5cd64a0b6163a71663c
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When compiling code that includes the header
infiniband/verbs.hwith CUDA using C++20 we observe:This use of enums seems to be a pre-C++11 way of generating compile-time constants. This PR uses explicit casts to suppress the compile-time warning.
This code, is of course C, but the enum-enum conversion issues leak out into C++ because they're in a header. There are a few options:
constexpr(heavyweight solution).#pragma clang diagnostic pushand#pragma clang diagnostic pop(it's more complicated than this, but folly has a macro that could be copied to cover all scenarios)The current code's use of enums seems as though it could cause increasing compilation issues over time, so fixing it seems like a good idea.
Let me know what you'd like to do - I'm happy to help.