[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 05:08:29 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL354780: [clang-tidy] misc-string-integer-assignment: ignore toupper/tolower (authored by courbet, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58604/new/

https://reviews.llvm.org/D58604

Files:
  clang-tools-extra/trunk/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/bugprone-string-integer-assignment.cpp


Index: clang-tools-extra/trunk/test/clang-tidy/bugprone-string-integer-assignment.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-string-integer-assignment.cpp
+++ clang-tools-extra/trunk/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-tools-extra/trunk/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
+++ clang-tools-extra/trunk/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.188140.patch
Type: text/x-patch
Size: 2064 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190225/45a193c9/attachment.bin>


More information about the cfe-commits mailing list