Skip to content

Commit

Permalink
[clang-tidy] misc-string-integer-assignment: fix false positive
Browse files Browse the repository at this point in the history
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
  • Loading branch information
legrosbuffle committed Feb 28, 2019
1 parent c6846b8 commit ff5e4bc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Expand Up @@ -26,15 +26,20 @@ 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(
expr(hasType(isInteger()), unless(hasType(isAnyCharacter())),
// 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);
Expand Down
Expand Up @@ -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);
Expand Down

0 comments on commit ff5e4bc

Please sign in to comment.