Skip to content

Spurious -Wbitfield-enum-conversion warning when using signed enum in a bit-field #138738

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

Closed
brevzin opened this issue May 6, 2025 · 1 comment
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer

Comments

@brevzin
Copy link
Contributor

brevzin commented May 6, 2025

Short reproduction:

#include <cstdint>

enum class E : int8_t {
    sell = -1,
    buy = +1,
    other = 0
};

struct Data {
    E e : 8;
    int padding : 24 = 0;
};

struct Aux {
    E e;
};

auto make_data(Aux const& aux) -> Data {
    return Data{.e=aux.e};
}

The warning I get from clang (under -Wconversion) is:

<source>:19:20: warning: assigning value of signed enum type 'E' to unsigned bit-field 'e'; negative enumerators of enum 'E' will be converted to positive values [-Wbitfield-enum-conversion]
   19 |     return Data{.e=aux.e};
      |                    ^
<source>:10:5: note: consider making the bit-field type signed
   10 |     E e : 8;
      |     ^

But the bit-field type is signed. And I can't write signed E either.

@EugeneZelenko EugeneZelenko added clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer and removed new issue labels May 6, 2025
@AaronBallman
Copy link
Collaborator

Closing as this is fixed on trunk already: https://godbolt.org/z/MWofc1xv8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer
Projects
None yet
Development

No branches or pull requests

4 participants