Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3033,7 +3033,7 @@ bool isLikelyStreamRead(bool cpp, const Token *op)
const Token *parent = op;
while (parent->astParent() && parent->astParent()->str() == op->str())
parent = parent->astParent();
if (parent->astParent() && !Token::Match(parent->astParent(), "%oror%|&&|(|,|.|!|;"))
if (parent->astParent() && !Token::Match(parent->astParent(), "%oror%|&&|(|,|.|!|;|return"))
return false;
if (op->str() == "&" && parent->astParent())
return false;
Expand Down
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
2 changes: 1 addition & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8058,7 +8058,7 @@ void Tokenizer::reportUnknownMacros() const

// Report unknown macros before } "{ .. if (x) MACRO }"
for (const Token *tok = tokens(); tok; tok = tok->next()) {
if (Token::Match(tok, ")|; %name% }")) {
if (Token::Match(tok, ")|; %name% } !!)")) {
const Token* prev = tok->linkAt(2);
while (Token::simpleMatch(prev, "{"))
prev = prev->previous();
Expand Down
6 changes: 6 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3270,6 +3270,12 @@ class TestOther : public TestFixture {
" const int* p = s.g<int>();\n"
"}\n");
ASSERT_EQUALS("", errout.str());

check("struct S { int x; };\n" // #11818
"std::istream& f(std::istream& is, S& s) {\n"
" return is >> s.x;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}

void constParameterCallback() {
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
4 changes: 4 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6876,6 +6876,10 @@ class TestTokenizer : public TestFixture {

ASSERT_THROW(tokenizeAndStringify("void foo() { if(x) SYSTEM_ERROR }"), InternalError);
ASSERT_THROW(tokenizeAndStringify("void foo() { dostuff(); SYSTEM_ERROR }"), InternalError);

ASSERT_NO_THROW(tokenizeAndStringify("void f(void* q) {\n"
" g(&(S) { .p = (int*)q });\n"
"}\n", /*expand*/ true, cppcheck::Platform::Type::Native, "test.c"));
}

void findGarbageCode() { // Test Tokenizer::findGarbageCode()
Expand Down