| 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 | |
| 5 | namespace std { |
| 6 | |
| 7 | template <class _CharT, class _Traits = void> class basic_ostream { |
| 8 | public: |
| 9 | basic_ostream &operator<<(int); |
| 10 | basic_ostream &operator<<(unsigned int); |
| 11 | }; |
| 12 | |
| 13 | template <class CharT, class Traits> |
| 14 | basic_ostream<CharT, Traits> &operator<<(basic_ostream<CharT, Traits> &, CharT); |
| 15 | template <class CharT, class Traits> |
| 16 | basic_ostream<CharT, Traits> &operator<<(basic_ostream<CharT, Traits> &, char); |
| 17 | template <class _Traits> |
| 18 | basic_ostream<char, _Traits> &operator<<(basic_ostream<char, _Traits> &, char); |
| 19 | template <class _Traits> |
| 20 | basic_ostream<char, _Traits> &operator<<(basic_ostream<char, _Traits> &, |
| 21 | signed char); |
| 22 | template <class _Traits> |
| 23 | basic_ostream<char, _Traits> &operator<<(basic_ostream<char, _Traits> &, |
| 24 | unsigned char); |
| 25 | |
| 26 | using ostream = basic_ostream<char>; |
| 27 | |
| 28 | } // namespace std |
| 29 | |
| 30 | using uint8_t = unsigned char; |
| 31 | using int8_t = signed char; |
| 32 | |
| 33 | void 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 | |