75 lines · cpp
1// RUN: %check_clang_tidy %s bugprone-signed-char-misuse %t \2// RUN: -config='{CheckOptions: \3// RUN: {bugprone-signed-char-misuse.CharTypedefsToIgnore: "sal_Int8;int8_t"}}' \4// RUN: --5 6///////////////////////////////////////////////////////////////////7/// Test cases correctly caught by the check.8 9// Check that a simple test case is still caught.10int SimpleAssignment() {11 signed char CCharacter = -5;12 int NCharacter;13 NCharacter = CCharacter;14 // CHECK-MESSAGES: [[@LINE-1]]:16: warning: 'signed char' to 'int' conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse]15 16 return NCharacter;17}18 19typedef signed char sal_Char;20 21int TypedefNotInIgnorableList() {22 sal_Char CCharacter = 'a';23 int NCharacter = CCharacter;24 // CHECK-MESSAGES: [[@LINE-1]]:20: warning: 'signed char' to 'int' conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse]25 26 return NCharacter;27}28 29///////////////////////////////////////////////////////////////////30/// Test cases correctly ignored by the check.31 32typedef signed char sal_Int8;33 34int OneIgnorableTypedef() {35 sal_Int8 CCharacter = 'a';36 int NCharacter = CCharacter;37 38 return NCharacter;39}40 41typedef signed char int8_t;42 43int OtherIgnorableTypedef() {44 int8_t CCharacter = 'a';45 int NCharacter = CCharacter;46 47 return NCharacter;48}49 50///////////////////////////////////////////////////////////////////51/// Test cases which should be caught by the check.52 53namespace boost {54 55template <class T>56class optional {57 T *member;58 59public:60 optional(T value) {61 member = new T(value);62 }63 64 T operator*() { return *member; }65};66 67} // namespace boost68 69int DereferenceWithTypdef(boost::optional<sal_Int8> param) {70 int NCharacter = *param;71 // CHECK-MESSAGES: [[@LINE-1]]:20: warning: 'signed char' to 'int' conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse]72 73 return NCharacter;74}75