Don't use enum for flags#5242
Merged
pks-t merged 1 commit intolibgit2:masterfrom Sep 26, 2019
csware:no-enum-for-flags
Merged
Conversation
csware
referenced
this pull request
Sep 25, 2019
Provide a function to filter blobs that allows for more functionality than the existing `git_blob_filtered_content` function.
Using an `enum` causes trouble when used with C++ as bitwise operations are not possible w/o casting (e.g., `opts.flags &= ~GIT_BLOB_FILTER_CHECK_FOR_BINARY;` is invalid as there is no `&=` operator for `enum`). Signed-off-by: Sven Strickroth <email@cs-ware.de>
Member
|
Fully agreed. I already highlighted such issues in other PRs in the past, using enums for bitfields is the wrong thing to do. |
pks-t
approved these changes
Sep 26, 2019
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
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.
Using an
enumcauses trouble when used with C++ as bitwise operations are not possible w/o casting (e.g.,opts.flags &= ~GIT_BLOB_FILTER_CHECK_FOR_BINARY;is invalid as there is no&=operator forenum).I'm unsure whether
uint32_tis a good way, because then I get "signed/unsigned" warnings in the case above - no warnigns would be generated with a plainint(cf. the following is needed withuint32_t:opts.flags &= ~static_cast<uint32_t>(GIT_BLOB_FILTER_CHECK_FOR_BINARY);).