1// RUN: %check_clang_tidy %s bugprone-unintended-char-ostream-output %t -- \
2// RUN: -config="{CheckOptions: \
3// RUN: {bugprone-unintended-char-ostream-output.CastTypeName: \"unsigned char\"}}"
4
5namespace std {
6
7template <class _CharT, class _Traits = void> class basic_ostream {
8public:
9 basic_ostream &operator<<(int);
10 basic_ostream &operator<<(unsigned int);
11};
12
13template <class CharT, class Traits>
14basic_ostream<CharT, Traits> &operator<<(basic_ostream<CharT, Traits> &, CharT);
15template <class CharT, class Traits>
16basic_ostream<CharT, Traits> &operator<<(basic_ostream<CharT, Traits> &, char);
17template <class _Traits>
18basic_ostream<char, _Traits> &operator<<(basic_ostream<char, _Traits> &, char);
19template <class _Traits>
20basic_ostream<char, _Traits> &operator<<(basic_ostream<char, _Traits> &,
21 signed char);
22template <class _Traits>
23basic_ostream<char, _Traits> &operator<<(basic_ostream<char, _Traits> &,
24 unsigned char);
25
26using ostream = basic_ostream<char>;
27
28} // namespace std
29
30using uint8_t = unsigned char;
31using int8_t = signed char;
32
33void origin_ostream(std::ostream &os) {
34 uint8_t unsigned_value = 9;
35 os << unsigned_value;
36 // CHECK-MESSAGES: [[@LINE-1]]:6: warning: 'uint8_t' (aka 'unsigned char') passed to 'operator<<' outputs as character instead of integer
37 // CHECK-FIXES: os << static_cast<unsigned char>(unsigned_value);
38
39 int8_t signed_value = 9;
40 os << signed_value;
41 // CHECK-MESSAGES: [[@LINE-1]]:6: warning: 'int8_t' (aka 'signed char') passed to 'operator<<' outputs as character instead of integer
42 // CHECK-FIXES: os << static_cast<unsigned char>(signed_value);
43
44 char char_value = 9;
45 os << char_value;
46}
47

source code of clang-tools-extra/test/clang-tidy/checkers/bugprone/unintended-char-ostream-output-cast-type.cpp