Skip to content

[clang-tidy] bugprone-signed-char-misuse gives false positives in C23 for enum with signed char type #145651

Open
@bjosv

Description

@bjosv

When running bugprone-signed-char-misuse on C23 code that uses enums with a fixed underlying type of signed char we get warnings.

enum e : signed char {
    E_M128 = -128,
};

enum e state = E_M128;
---
<source>:8:16: warning: 'signed char' to 'enum e' conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse]
    8 | enum e state = E_M128;
      |                ^
1 warning generated.

A full example:
https://godbolt.org/z/vGTj966TY

The checker gets that the RHS EnumConstant is a signed char but don't use the fact that LHS is of type signed char, giving a warning.

The RHS seems to give the AST
ImplicitCastExpr <col:13> 'e_t':'enum e' <IntegralCast>
but we have not found anything in the standard that motivates the warning and we believe the warning is a false positive.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions