Skip to content

[clang][request] Warn when bitfield is too small to hold all enum values #171783

@chrchr-github

Description

@chrchr-github
struct S {
    enum E : unsigned char { E0, E1, E2, E3 };
    E e : 1; // warn here
};

S::E f(S::E e) {
    S s{};
    s.e = e;
    //s.e = S::E3; // [clang-diagnostic-bitfield-constant-conversion]
    return s.e;
}

int main() {
    return f(S::E3);
}

Not sure if this is appropriate for clang-tidy or diagnostics.
GCC shows a warning.
https://godbolt.org/z/WTnPYTrz7

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions