Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang-tidy]: Add cert-str34-c alias for bugprone-signed-char-misuse.
Summary: Added `DiagnoseSignedUnsignedCharComparisons` option to filter out unrelated use cases. The SEI cert catches explicit integer casts (two use cases), while in the case of `signed char` \ `unsigned char` comparison, we have implicit conversions. Reviewers: aaron.ballman Reviewed By: aaron.ballman Subscribers: xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D79334
- Loading branch information
Showing
8 changed files
with
65 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.. title:: clang-tidy - cert-str34-c | ||
.. meta:: | ||
:http-equiv=refresh: 5;URL=bugprone-signed-char-misuse.html | ||
|
||
cert-str34-c | ||
============ | ||
|
||
The cert-str34-c check is an alias, please see | ||
`bugprone-signed-char-misuse <bugprone-signed-char-misuse.html>`_ | ||
for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
clang-tools-extra/test/clang-tidy/checkers/cert-str34-c.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// RUN: %check_clang_tidy %s cert-str34-c %t | ||
|
||
// Check whether alias is actually working. | ||
int SimpleVarDeclaration() { | ||
signed char CCharacter = -5; | ||
int NCharacter = CCharacter; | ||
// CHECK-MESSAGES: [[@LINE-1]]:20: warning: 'signed char' to 'int' conversion; consider casting to 'unsigned char' first. [cert-str34-c] | ||
|
||
return NCharacter; | ||
} | ||
|
||
// Check whether bugprone-signed-char-misuse.DiagnoseSignedUnsignedCharComparisons option is set correctly. | ||
int SignedUnsignedCharEquality(signed char SCharacter) { | ||
unsigned char USCharacter = 'a'; | ||
if (SCharacter == USCharacter) // no warning | ||
return 1; | ||
return 0; | ||
} |