Skip to content

Address -Wsign-conversion warnings with Clang #1399

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

Merged
merged 1 commit into from
May 5, 2025

Conversation

eramongodb
Copy link
Contributor

@eramongodb eramongodb commented May 5, 2025

Followup to #1356, where a -Wsign-conversion Clang warning due to the following expression was overlooked:

0xFFu << (-element_end.bit & 7u)

element_end.bit is a std::uint8_t. The unary negation operator implicitly promotes the result to an int, whose signedness is inconsistent with 7u (warning: signed & unsigned). The literal is made a signed int for consistency. This should not impact the behavior of the overall expression (tested exhaustively). (Updated link: static assert unsigned << signed -> unsigned (after promotion) + test UINT8_MAX as well.)

@eramongodb eramongodb requested a review from kevinAlbs May 5, 2025 16:14
@eramongodb eramongodb self-assigned this May 5, 2025
@eramongodb eramongodb requested a review from a team as a code owner May 5, 2025 16:14
Copy link
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The exhaustive test to double check is appreciated.

@eramongodb eramongodb merged commit dbc9469 into mongodb:master May 5, 2025
14 of 16 checks passed
@eramongodb eramongodb deleted the cxx-warnings branch May 5, 2025 17:26
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