Fixed #5602 (false positive on std::vector - after unknown macro around the function header)
This commit is contained in:
parent
547803f581
commit
79942df842
|
@ -640,11 +640,12 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
|||
tok = funcStart;
|
||||
|
||||
// class function
|
||||
if (tok->previous()->str() == "::")
|
||||
if (tok->previous() && tok->previous()->str() == "::")
|
||||
addClassFunction(&scope, &tok, argStart);
|
||||
|
||||
// class destructor
|
||||
else if (tok->previous()->str() == "~" &&
|
||||
else if (tok->previous() &&
|
||||
tok->previous()->str() == "~" &&
|
||||
tok->strAt(-2) == "::")
|
||||
addClassFunction(&scope, &tok, argStart);
|
||||
|
||||
|
@ -1100,6 +1101,17 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
|
|||
}
|
||||
}
|
||||
|
||||
// UNKNOWN_MACRO(a,b) { ... }
|
||||
else if (outerScope->type == Scope::eGlobal &&
|
||||
Token::Match(tok, "%var% (") &&
|
||||
tok->isUpperCaseName() &&
|
||||
Token::Match(tok->linkAt(1), ") {") &&
|
||||
(!tok->previous() || Token::Match(tok->previous(), "[;{}]"))) {
|
||||
*funcStart = tok;
|
||||
*argStart = tok->next();
|
||||
return true;
|
||||
}
|
||||
|
||||
// template constructor?
|
||||
else if (Token::Match(tok, "%var% <") && Token::simpleMatch(tok->next()->link(), "> (")) {
|
||||
const Token* tok2 = tok->next()->link()->next()->link();
|
||||
|
|
|
@ -225,6 +225,8 @@ private:
|
|||
|
||||
TEST_CASE(garbage);
|
||||
|
||||
TEST_CASE(isFunction); // UNKNOWN_MACRO(a,b) { .. }
|
||||
|
||||
TEST_CASE(findFunction1);
|
||||
TEST_CASE(findFunction2); // mismatch: parameter passed by address => reference argument
|
||||
|
||||
|
@ -1986,6 +1988,19 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
void isFunction() { // #5602 - UNKNOWN_MACRO(a,b) { .. }
|
||||
GET_SYMBOL_DB("TEST(a,b) {\n"
|
||||
" std::vector<int> messages;\n"
|
||||
" foo(messages[2].size());\n"
|
||||
"}");
|
||||
const Variable * const var = db ? db->getVariableFromVarId(1U) : nullptr;
|
||||
ASSERT(db &&
|
||||
db->findScopeByName("TEST") &&
|
||||
var &&
|
||||
var->typeStartToken() &&
|
||||
var->typeStartToken()->str() == "std");
|
||||
}
|
||||
|
||||
void findFunction1() {
|
||||
GET_SYMBOL_DB("int foo(int x);\n" /* 1 */
|
||||
"void foo();\n" /* 2 */
|
||||
|
|
Loading…
Reference in New Issue