[PATCH] D58606: [clang-tidy] misc-string-integer-assignment: fix false positive
Clement Courbet via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 28 02:34:16 PST 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL355076: [clang-tidy] misc-string-integer-assignment: fix false positive (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/D58606/new/
https://reviews.llvm.org/D58606
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/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
+++ clang-tools-extra/trunk/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: 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
@@ -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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58606.188689.patch
Type: text/x-patch
Size: 2107 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190228/741dd1c0/attachment-0001.bin>
More information about the cfe-commits
mailing list