[PATCH] D58604: [clang-tidy] misc-string-integer-assignment: ignore toupper/tolower
Clement Courbet via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 25 03:58:54 PST 2019
courbet created this revision.
courbet added reviewers: xazax.hun, alexfh.
Herald added subscribers: cfe-commits, rnkovacs.
Herald added a project: clang.
Tis represents ~20% of false positives. See PR27723.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D58604
Files:
clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
test/clang-tidy/bugprone-string-integer-assignment.cpp
Index: test/clang-tidy/bugprone-string-integer-assignment.cpp
===================================================================
--- test/clang-tidy/bugprone-string-integer-assignment.cpp
+++ test/clang-tidy/bugprone-string-integer-assignment.cpp
@@ -11,8 +11,14 @@
typedef basic_string<char> string;
typedef basic_string<wchar_t> wstring;
+
+int tolower(int i);
+int toupper(int i);
}
+int tolower(int i);
+int toupper(int i);
+
typedef int MyArcaneChar;
int main() {
@@ -50,4 +56,7 @@
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: an integer is interpreted as a chara
// CHECK-FIXES: {{^}} as = 6;{{$}}
+ s += toupper(x);
+ s += tolower(x);
+ s += std::tolower(x);
}
Index: clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
===================================================================
--- clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
+++ clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
@@ -27,10 +27,15 @@
callee(cxxMethodDecl(ofClass(classTemplateSpecializationDecl(
hasName("::std::basic_string"),
hasTemplateArgument(0, refersToType(qualType().bind("type"))))))),
- hasArgument(1,
- ignoringImpCasts(expr(hasType(isInteger()),
- unless(hasType(isAnyCharacter())))
- .bind("expr"))),
+ hasArgument(
+ 1,
+ ignoringImpCasts(
+ expr(hasType(isInteger()), unless(hasType(isAnyCharacter())),
+ // Ignore calls to tolower/toupper (see PR27723).
+ unless(callExpr(callee(functionDecl(
+ hasAnyName("tolower", "std::tolower", "toupper",
+ "std::toupper"))))))
+ .bind("expr"))),
unless(isInTemplateInstantiation())),
this);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58604.188127.patch
Type: text/x-patch
Size: 1920 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190225/a1ccad77/attachment.bin>
More information about the cfe-commits
mailing list