Skip to content

Clang misses left shift count warning found by gcc #59863

Open
@jstengleingithub

Description

@jstengleingithub

Clang misses a shift count warning found by GCC.

cat shift.c
#include <stdio.h>
typedef enum shiftof {
    OFA_FM_POL_ERROR = (1<<32)
} shiftof_t;

int main()
{
    printf ("%u %lu %lu\n", OFA_FM_POL_ERROR, sizeof(OFA_FM_POL_ERROR), sizeof(shiftof_t));
}
$ ./bin/clang -Wall shift.c
(no warning)
$ gcc -Wall shift.c
shift.c:3:26: warning: left shift count >= width of type [-Wshift-count-overflow]
     OFA_FM_POL_ERROR = (1<<32)
                          ^~
$ gcc --version
gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-10)
$ ./bin/clang --version
clang version 16.0.0 (https://github.com/llvm/llvm-project 6daa983c9dde7608bcaa20b11e4a7d28fab4e003)

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