Skip to content

-Wsign-compare fails to warn about mismatches involving const types #13018

@llvmbot

Description

@llvmbot
Bugzilla Link 12646
Version trunk
OS All
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@zygoloid

Extended Description

Compiling the following with [clang++ -Wsign-compare -c] (trunk 155352) results in warnings for the first i==u comparison and then for all the comparisons in g(). I believe the other comparisons in f() should also trigger the warning, for consistency (but they appear not too, presumably because of the "const"s).

int f() {
int i = 1;
const int ci = 2;
unsigned u = 3;
const unsigned cu = 4;
if (i == u) return 1; // Only this triggers a warning!
if (ci == cu) return 2;
if (i == cu) return 3;
if (ci == u) return 4;
return 0;
}

int bar();
int g() {
int i = bar();
const int ci = bar();
unsigned u = bar();
const unsigned cu = bar();
if (i == u) return 1;
if (ci == cu) return 2;
if (i == cu) return 3;
if (ci == u) return 4;
return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++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