Skip to content

Commit

Permalink
Fix #11819 FP stlcstrConstructor for string_view constructed with siz…
Browse files Browse the repository at this point in the history
…e argument
  • Loading branch information
chrchr-github committed Jul 7, 2023
1 parent 7d4b491 commit 607c090
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/checkstl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1992,7 +1992,7 @@ void CheckStl::string_c_str()
}
}
}
} else if (printPerformance && Token::Match(tok, "%var% (|{ %var% . c_str|data ( )") &&
} else if (printPerformance && Token::Match(tok, "%var% (|{ %var% . c_str|data ( ) !!,") &&
tok->variable() && (tok->variable()->isStlStringType() || tok->variable()->isStlStringViewType()) &&
tok->tokAt(2)->variable() && tok->tokAt(2)->variable()->isStlStringType()) {
string_c_strConstructor(tok, tok->variable()->getTypeName());
Expand Down
5 changes: 5 additions & 0 deletions test/teststl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4256,6 +4256,11 @@ class TestStl : public TestFixture {
ASSERT_EQUALS("[test.cpp:2]: (performance) Assigning the result of c_str() to a std::string_view is slow and redundant.\n"
"[test.cpp:6]: (performance) Constructing a std::string_view from the result of c_str() is slow and redundant.\n",
errout.str());

check("void f(const std::string& s) {\n" // #11819
" std::string_view sv(s.data(), 13);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}

void uselessCalls() {
Expand Down

0 comments on commit 607c090

Please sign in to comment.