[clang-tools-extra] r355076 - [clang-tidy] misc-string-integer-assignment: fix false positive
Clement Courbet via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 28 02:33:32 PST 2019
Author: courbet
Date: Thu Feb 28 02:33:32 2019
New Revision: 355076
URL: http://llvm.org/viewvc/llvm-project?rev=355076&view=rev
Log:
[clang-tidy] misc-string-integer-assignment: fix false positive
Summary:
using CodePoint = uint32_t;
CodePoint cp;
basic_string<CodePoint> s;
s += cp;
See PR27723.
Reviewers: xazax.hun, alexfh
Subscribers: rnkovacs, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D58606
Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/bugprone-string-integer-assignment.cpp
Modified: clang-tools-extra/trunk/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp?rev=355076&r1=355075&r2=355076&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp Thu Feb 28 02:33:32 2019
@@ -26,7 +26,8 @@ void StringIntegerAssignmentCheck::regis
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 @@ void StringIntegerAssignmentCheck::regis
// 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);
Modified: clang-tools-extra/trunk/test/clang-tidy/bugprone-string-integer-assignment.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-string-integer-assignment.cpp?rev=355076&r1=355075&r2=355076&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-string-integer-assignment.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-string-integer-assignment.cpp Thu Feb 28 02:33:32 2019
@@ -53,8 +53,8 @@ int main() {
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);
More information about the cfe-commits
mailing list