llvm-project/clang/test/Sema/tautological-unsigned-char-zero-compare.cc
Anton Bikineev 69545154cc [Sema] Move 'char-expression-as-unsigned < 0' into a separate diagnostic
This change splits '-Wtautological-unsigned-zero-compare' by reporting
char-expressions-interpreted-as-unsigned under a separate diagnostic
'-Wtautological-unsigned-char-zero-compare'. This is beneficial for
projects that want to enable '-Wtautological-unsigned-zero-compare' but at
the same time want to keep code portable for platforms with char being
signed or unsigned, such as Chromium.

Differential Revision: https://reviews.llvm.org/D99808
2021-04-14 01:01:40 +02:00

40 lines
1.4 KiB
C++

// RUN: %clang_cc1 -fsyntax-only \
// RUN: -fno-signed-char \
// RUN: -Wtautological-unsigned-zero-compare \
// RUN: -Wtautological-unsigned-char-zero-compare \
// RUN: -verify=unsigned %s
// RUN: %clang_cc1 -fsyntax-only \
// RUN: -Wtautological-unsigned-zero-compare \
// RUN: -Wtautological-unsigned-char-zero-compare \
// RUN: -verify=signed %s
void f(char c, unsigned char uc, signed char cc) {
if (c < 0)
return;
// unsigned-warning@-2 {{comparison of char expression < 0 is always false, since char is interpreted as unsigned}}
if (uc < 0)
return;
// unsigned-warning@-2 {{comparison of unsigned expression < 0 is always false}}
// signed-warning@-3 {{comparison of unsigned expression < 0 is always false}}
if (cc < 0)
return;
// Promoted to integer expressions should not warn.
if (c - 4 < 0)
return;
}
void ref(char &c, unsigned char &uc, signed char &cc) {
if (c < 0)
return;
// unsigned-warning@-2 {{comparison of char expression < 0 is always false, since char is interpreted as unsigned}}
if (uc < 0)
return;
// unsigned-warning@-2 {{comparison of unsigned expression < 0 is always false}}
// signed-warning@-3 {{comparison of unsigned expression < 0 is always false}}
if (cc < 0)
return;
// Promoted to integer expressions should not warn.
if (c - 4 < 0)
return;
}