SymbolDatabase: Fix Variable pointer property for 'std::string x(*p)'

This commit is contained in:
Daniel Marjamäki 2021-11-17 08:22:49 +01:00
parent 2998382c86
commit 8b5865055a
2 changed files with 14 additions and 1 deletions

View File

@ -6242,7 +6242,7 @@ static const Token * parsedecl(const Token *type, ValueType * const valuetype, V
} else if (const Library::Container *container = settings->library.detectContainer(type)) {
valuetype->type = ValueType::Type::CONTAINER;
valuetype->container = container;
while (Token::Match(type, "%name%|::|<")) {
while (Token::Match(type, "%type%|::|<")) {
if (type->str() == "<" && type->link()) {
if (container->type_templateArgNo >= 0) {
const Token *templateType = type->next();

View File

@ -137,6 +137,7 @@ private:
TEST_CASE(test_isVariableDeclarationIdentifiesScopedStdDeclaration);
TEST_CASE(test_isVariableDeclarationIdentifiesManyScopes);
TEST_CASE(test_isVariableDeclarationIdentifiesPointers);
TEST_CASE(test_isVariableDeclarationIdentifiesPointers2);
TEST_CASE(test_isVariableDeclarationDoesNotIdentifyConstness);
TEST_CASE(test_isVariableDeclarationIdentifiesFirstOfManyVariables);
TEST_CASE(test_isVariableDeclarationIdentifiesScopedPointerDeclaration);
@ -655,6 +656,18 @@ private:
ASSERT(false == v3.isReference());
}
void test_isVariableDeclarationIdentifiesPointers2() {
GET_SYMBOL_DB("void slurpInManifest() {\n"
" std::string tmpiostring(*tI);\n"
" if(tmpiostring==\"infoonly\"){}\n"
"}");
const Token *tok = Token::findsimplematch(tokenizer.tokens(), "tmpiostring ==");
ASSERT(tok->variable());
ASSERT(!tok->variable()->isPointer());
}
void test_isVariableDeclarationDoesNotIdentifyConstness() {
reset();
givenACodeSampleToTokenize constness("const int* cp;");