Skip to content

clang -Wconstant-conversion conditional operator false positive #64741

Closed as not planned
@osandov

Description

@osandov

The following C source code:

int x = 0 ? 9223372036854775807L : 2147483648;

Produces the following warning when compiled with Clang:

$ clang --version
clang version 16.0.6 (Fedora 16.0.6-2.fc38)
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ clang -Wconstant-conversion -fsyntax-only test.c
test.c:1:13: warning: implicit conversion from 'long' to 'int' changes value from 9223372036854775807 to -1 [-Wconstant-conversion]
int x = 0 ? 9223372036854775807L : 2147483647;
    ~       ^~~~~~~~~~~~~~~~~~~~
1 warning generated.

0 ? 9223372036854775807L : 2147483647 evaluates to 2147483647L, so this warning is incorrect. GCC's similar -Woverflow doesn't trigger for this test case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerduplicateResolved as duplicatefalse-positiveWarning fires when it should not

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions