File tree Expand file tree Collapse file tree 3 files changed +10
-2
lines changed Expand file tree Collapse file tree 3 files changed +10
-2
lines changed Original file line number Diff line number Diff line change 9
9
#include " SignedBitwiseCheck.h"
10
10
#include " clang/AST/ASTContext.h"
11
11
#include " clang/ASTMatchers/ASTMatchFinder.h"
12
+ #include " clang/ASTMatchers/ASTMatchers.h"
12
13
13
14
using namespace clang ::ast_matchers;
14
15
using namespace clang ::ast_matchers::internal;
@@ -29,8 +30,8 @@ void SignedBitwiseCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
29
30
void SignedBitwiseCheck::registerMatchers (MatchFinder *Finder) {
30
31
const auto SignedIntegerOperand =
31
32
(IgnorePositiveIntegerLiterals
32
- ? expr (ignoringImpCasts (hasType ( isSignedInteger ())),
33
- unless (integerLiteral ()))
33
+ ? expr (ignoringImpCasts (
34
+ allOf ( hasType ( isSignedInteger ()), unless (integerLiteral ()) )))
34
35
: expr (ignoringImpCasts (hasType (isSignedInteger ()))))
35
36
.bind (" signed-operand" );
36
37
Original file line number Diff line number Diff line change @@ -259,6 +259,10 @@ Changes in existing checks
259
259
- Improved :doc: `google-runtime-int <clang-tidy/checks/google/runtime-int >`
260
260
check performance through optimizations.
261
261
262
+ - Improved :doc: `hicpp-signed-bitwise <clang-tidy/checks/hicpp/signed-bitwise >`
263
+ check by ignoring false positives involving positive integer literals behind
264
+ implicit casts when `IgnorePositiveIntegerLiterals ` is enabled.
265
+
262
266
- Improved :doc: `hicpp-ignored-remove-result <clang-tidy/checks/hicpp/ignored-remove-result >`
263
267
check by ignoring other functions with same prefixes as the target specific
264
268
functions.
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ void examples() {
11
11
// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use of a signed integer operand with a binary bitwise operator
12
12
13
13
unsigned URes2 = URes << 1 ; // Ok
14
+ unsigned URes3 = URes & 1 ; // Ok
14
15
15
16
int IResult;
16
17
IResult = 10 & 2 ; // Ok
@@ -21,6 +22,8 @@ void examples() {
21
22
IResult = Int << 1 ;
22
23
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
23
24
IResult = ~0 ; // Ok
25
+ IResult = -1 & 1 ;
26
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator [hicpp-signed-bitwise]
24
27
}
25
28
26
29
enum EnumConstruction {
You can’t perform that action at this time.
0 commit comments