diff --git a/lib/library.cpp b/lib/library.cpp index 2bd2e61cc..c3ebbfe2c 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -1601,7 +1601,7 @@ const Library::SmartPointer* Library::detectSmartPointer(const Token* tok) const return &it->second; } -CPPCHECKLIB const Library::Container * getLibraryContainer(const Token * tok) +const Library::Container * getLibraryContainer(const Token * tok) { if (!tok) return nullptr; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 118feab0a..593ff3b3e 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -465,7 +465,8 @@ private: TEST_CASE(executableScopeWithUnknownFunction); - TEST_CASE(valuetype); + TEST_CASE(valueType1); + TEST_CASE(valueType2); TEST_CASE(variadic1); // #7453 TEST_CASE(variadic2); // #7649 @@ -7331,7 +7332,7 @@ private: return tok->valueType() ? tok->valueType()->str() : std::string(); } - void valuetype() { + void valueType1() { // stringification ASSERT_EQUALS("", ValueType().str()); @@ -7784,6 +7785,49 @@ private: } } + void valueType2() { + GET_SYMBOL_DB("int i;\n" + "bool b;\n" + "Unknown u;\n" + "std::string s;\n" + "std::vector v;\n" + "std::map::const_iterator it;\n" + "void* p;\n" + "\n" + "void f() {\n" + " func(i, b, u, s, v, it, p);\n" + "}"); + + const Token* tok = tokenizer.tokens(); + + for (int i = 0; i < 2; i++) { + tok = Token::findsimplematch(tok, "i"); + ASSERT(tok && tok->valueType()); + ASSERT_EQUALS("signed int", tok->valueType()->str()); + + tok = Token::findsimplematch(tok, "b"); + ASSERT(tok && tok->valueType()); + ASSERT_EQUALS("bool", tok->valueType()->str()); + + tok = Token::findsimplematch(tok, "u"); + ASSERT(tok && !tok->valueType()); + + tok = Token::findsimplematch(tok, "s"); + ASSERT(tok && tok->valueType()); + ASSERT_EQUALS("container(std :: string|wstring|u16string|u32string)", tok->valueType()->str()); + ASSERT(tok->valueType()->container && tok->valueType()->container->stdStringLike); + + tok = Token::findsimplematch(tok, "v"); + ASSERT(tok && tok->valueType()); + ASSERT_EQUALS("container(std :: vector <)", tok->valueType()->str()); + ASSERT(tok->valueType()->container && !tok->valueType()->container->stdStringLike); + + tok = Token::findsimplematch(tok, "it"); + ASSERT(tok && tok->valueType()); + ASSERT_EQUALS("iterator(std :: map|unordered_map <)", tok->valueType()->str()); + } + } + void variadic1() { // #7453 { GET_SYMBOL_DB("CBase* create(const char *c1, ...);\n"