Skip to content

Don't use enum for flags#5242

Merged
pks-t merged 1 commit intolibgit2:masterfrom
csware:no-enum-for-flags
Sep 26, 2019
Merged

Don't use enum for flags#5242
pks-t merged 1 commit intolibgit2:masterfrom
csware:no-enum-for-flags

Conversation

@csware
Copy link
Copy Markdown
Contributor

@csware csware commented Sep 25, 2019

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).

I'm unsure whether uint32_t is a good way, because then I get "signed/unsigned" warnings in the case above - no warnigns would be generated with a plain int (cf. the following is needed with uint32_t: opts.flags &= ~static_cast<uint32_t>(GIT_BLOB_FILTER_CHECK_FOR_BINARY);).

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>
@pks-t
Copy link
Copy Markdown
Member

pks-t commented Sep 26, 2019

Fully agreed. I already highlighted such issues in other PRs in the past, using enums for bitfields is the wrong thing to do.
We already use unsigned types to represent such bitfields, and I think we should just continue doing so. So uint32_t looks perfectly fine to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants