[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

llvm-svn: 355076
This commit is contained in:
Clement Courbet 2019-02-28 10:33:32 +00:00
parent c6846b8800
commit ff5e4bcad0
2 changed files with 9 additions and 4 deletions

View File

@ -26,7 +26,8 @@ void StringIntegerAssignmentCheck::registerMatchers(MatchFinder *Finder) {
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::registerMatchers(MatchFinder *Finder) {
// 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);

View File

@ -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);