diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 426345149..e8f033ad4 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3752,6 +3752,9 @@ static void setValueType(Token *tok, const ValueType &valuetype) static const Token * parsedecl(const Token *type, ValueType * const valuetype) { + const unsigned int pointer0 = valuetype->pointer; + while (Token::Match(type->previous(), "%name%")) + type = type->previous(); valuetype->sign = ValueType::Sign::UNKNOWN_SIGN; valuetype->type = ValueType::Type::UNKNOWN_TYPE; while (Token::Match(type, "%name%|*|&") && !type->variable()) { @@ -3759,7 +3762,9 @@ static const Token * parsedecl(const Token *type, ValueType * const valuetype) valuetype->sign = ValueType::Sign::SIGNED; else if (type->isUnsigned()) valuetype->sign = ValueType::Sign::UNSIGNED; - if (type->str() == "bool") + if (type->str() == "const") + valuetype->constness |= (1 << (valuetype->pointer - pointer0)); + else if (type->str() == "bool") valuetype->type = ValueType::Type::BOOL; else if (type->str() == "char") valuetype->type = ValueType::Type::CHAR; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index d95accf68..89dee0deb 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -3005,6 +3005,9 @@ private: // const.. ASSERT_EQUALS("const char *", typeOf("a = \"123\";", "\"123\"")); + ASSERT_EQUALS("const int *", typeOf("const int *a; x = a + 1;", "a +")); + ASSERT_EQUALS("int * const", typeOf("int * const a; x = a + 1;", "+")); + ASSERT_EQUALS("const int *", typeOf("const int a[20]; x = a + 1;", "+")); } };