Skip to content

Commit 5137e7f

Browse files
committed
[clang] Improve -Wsign-compare diagnostic
The cv-qualifiers are not relevant to the comparison result so one should not print them.
1 parent 63af271 commit 5137e7f

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

clang/lib/Sema/SemaChecking.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10593,7 +10593,8 @@ static void AnalyzeComparison(Sema &S, BinaryOperator *E) {
1059310593

1059410594
S.DiagRuntimeBehavior(E->getOperatorLoc(), E,
1059510595
S.PDiag(diag::warn_mixed_sign_comparison)
10596-
<< LHS->getType() << RHS->getType()
10596+
<< LHS->getType().getUnqualifiedType()
10597+
<< RHS->getType().getUnqualifiedType()
1059710598
<< LHS->getSourceRange() << RHS->getSourceRange());
1059810599
}
1059910600

clang/test/SemaCXX/compare.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,10 @@ void test4(short s) {
233233
// All negative shorts are cast towards the max unsigned range. Relation
234234
// comparisons are possible, but equality comparisons are tautological.
235235
const unsigned A = 32768;
236-
void (s < A); // expected-warning{{comparison of integers of different signs: 'short' and 'const unsigned int'}}
237-
void (s > A); // expected-warning{{comparison of integers of different signs: 'short' and 'const unsigned int'}}
238-
void (s <= A); // expected-warning{{comparison of integers of different signs: 'short' and 'const unsigned int'}}
239-
void (s >= A); // expected-warning{{comparison of integers of different signs: 'short' and 'const unsigned int'}}
236+
void (s < A); // expected-warning{{comparison of integers of different signs: 'short' and 'unsigned int'}}
237+
void (s > A); // expected-warning{{comparison of integers of different signs: 'short' and 'unsigned int'}}
238+
void (s <= A); // expected-warning{{comparison of integers of different signs: 'short' and 'unsigned int'}}
239+
void (s >= A); // expected-warning{{comparison of integers of different signs: 'short' and 'unsigned int'}}
240240

241241
void (s == A); // expected-warning{{comparison of constant 32768 with expression of type 'short' is always false}}
242242
void (s != A); // expected-warning{{comparison of constant 32768 with expression of type 'short' is always true}}
@@ -245,12 +245,12 @@ void test4(short s) {
245245
// unsigned. Likewise, a negative one short can also be converted to max
246246
// unsigned.
247247
const unsigned B = -1;
248-
void (s < B); // expected-warning{{comparison of integers of different signs: 'short' and 'const unsigned int'}}
248+
void (s < B); // expected-warning{{comparison of integers of different signs: 'short' and 'unsigned int'}}
249249
void (s > B); // expected-warning{{comparison 'short' > 4294967295 is always false}}
250250
void (s <= B); // expected-warning{{comparison 'short' <= 4294967295 is always true}}
251-
void (s >= B); // expected-warning{{comparison of integers of different signs: 'short' and 'const unsigned int'}}
252-
void (s == B); // expected-warning{{comparison of integers of different signs: 'short' and 'const unsigned int'}}
253-
void (s != B); // expected-warning{{comparison of integers of different signs: 'short' and 'const unsigned int'}}
251+
void (s >= B); // expected-warning{{comparison of integers of different signs: 'short' and 'unsigned int'}}
252+
void (s == B); // expected-warning{{comparison of integers of different signs: 'short' and 'unsigned int'}}
253+
void (s != B); // expected-warning{{comparison of integers of different signs: 'short' and 'unsigned int'}}
254254

255255
}
256256

0 commit comments

Comments
 (0)