Skip to content

clang-tidy bugprone-signed-char-misuse triggers on int8_t to int castΒ #108943

@davidrohr

Description

@davidrohr

When running the following code through clang-tidy with bugprone-signed-char-misuse

    int8_t y = 0;
    int32_t x = y;

it prints

[warning: 'signed char' to 'int32_t' (aka 'int') conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse]](javascript:;)
    7 |     int32_t x = y;

I think we should not print this warning when int8_t is used. The warning is to catch character to int conversions, but when int8_t is used, the user normally wants explicitly a signed integer.

In addition, I wonder actually why the check triggers on

    signed char y = 0;
    int32_t x = y;

Since here already I indicate that I want a signed char. AFAIK, char, signed char, unsigned char are 3 different types, and whether char becomes signed char or unsigned char is implementation-defined.
IMHO, the check should only trigger on char, i.e. only for

    char y = 0;
    int32_t x = y;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions