Fix #11818 FP constParameterReference / #11819 FP stlcstrConstructor / #11814 FP unknownMacro (#5224)
This commit is contained in:
parent
c738627d15
commit
cc38ef4168
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -3270,6 +3270,12 @@ private:
|
|||
" 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() {
|
||||
|
|
|
@ -4256,6 +4256,11 @@ private:
|
|||
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() {
|
||||
|
|
|
@ -6876,6 +6876,10 @@ private:
|
|||
|
||||
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()
|
||||
|
|
Loading…
Reference in New Issue