courbet updated this revision to Diff 188318.
courbet added a comment.

- add more tests
- Traverse using decls.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D58606

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
@@ -53,8 +53,8 @@
 
   std::basic_string<MyArcaneChar> as;
   as = 6;
-// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: an integer is interpreted as a 
chara
-// CHECK-FIXES: {{^}}  as = 6;{{$}}
+  as = static_cast<MyArcaneChar>(6);
+  as = 'a';
 
   s += toupper(x);
   s += tolower(x);
Index: clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
===================================================================
--- clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
+++ clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
@@ -26,7 +26,8 @@
                 hasOverloadedOperatorName("+=")),
           callee(cxxMethodDecl(ofClass(classTemplateSpecializationDecl(
               hasName("::std::basic_string"),
-              hasTemplateArgument(0, 
refersToType(qualType().bind("type"))))))),
+              hasTemplateArgument(0, refersToType(hasCanonicalType(
+                                         qualType().bind("type")))))))),
           hasArgument(
               1,
               ignoringImpCasts(
@@ -34,7 +35,11 @@
                        // Ignore calls to tolower/toupper (see PR27723).
                        unless(callExpr(callee(functionDecl(
                            hasAnyName("tolower", "std::tolower", "toupper",
-                                      "std::toupper"))))))
+                                      "std::toupper"))))),
+                       // Do not warn if assigning e.g. `CodePoint` to
+                       // `basic_string<CodePoint>`
+                       unless(hasType(qualType(
+                           hasCanonicalType(equalsBoundNode("type"))))))
                       .bind("expr"))),
           unless(isInTemplateInstantiation())),
       this);


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
@@ -53,8 +53,8 @@
 
   std::basic_string<MyArcaneChar> as;
   as = 6;
-// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: an integer is interpreted as a chara
-// CHECK-FIXES: {{^}}  as = 6;{{$}}
+  as = static_cast<MyArcaneChar>(6);
+  as = 'a';
 
   s += toupper(x);
   s += tolower(x);
Index: clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
===================================================================
--- clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
+++ clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
@@ -26,7 +26,8 @@
                 hasOverloadedOperatorName("+=")),
           callee(cxxMethodDecl(ofClass(classTemplateSpecializationDecl(
               hasName("::std::basic_string"),
-              hasTemplateArgument(0, refersToType(qualType().bind("type"))))))),
+              hasTemplateArgument(0, refersToType(hasCanonicalType(
+                                         qualType().bind("type")))))))),
           hasArgument(
               1,
               ignoringImpCasts(
@@ -34,7 +35,11 @@
                        // Ignore calls to tolower/toupper (see PR27723).
                        unless(callExpr(callee(functionDecl(
                            hasAnyName("tolower", "std::tolower", "toupper",
-                                      "std::toupper"))))))
+                                      "std::toupper"))))),
+                       // Do not warn if assigning e.g. `CodePoint` to
+                       // `basic_string<CodePoint>`
+                       unless(hasType(qualType(
+                           hasCanonicalType(equalsBoundNode("type"))))))
                       .bind("expr"))),
           unless(isInTemplateInstantiation())),
       this);
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to