diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index e3d9885f8..5b44554d7 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3799,6 +3799,8 @@ static const Token * parsedecl(const Token *type, ValueType * const valuetype) valuetype->sign = ValueType::Sign::UNSIGNED; if (type->str() == "const") valuetype->constness |= (1 << (valuetype->pointer - pointer0)); + else if (type->str() == "void") + valuetype->type = ValueType::Type::VOID; else if (type->str() == "bool") valuetype->type = ValueType::Type::BOOL; else if (type->str() == "char") @@ -3901,7 +3903,9 @@ std::string ValueType::str() const std::string ret; if (constness & 1) ret = " const"; - if (isIntegral()) { + if (type == VOID) + ret += " void"; + else if (isIntegral()) { if (sign == SIGNED) ret += " signed"; else if (sign == UNSIGNED) diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index 330a2e8b7..4e53d192b 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -1051,7 +1051,7 @@ private: class CPPCHECKLIB ValueType { public: enum Sign {UNKNOWN_SIGN, SIGNED, UNSIGNED} sign; - enum Type {UNKNOWN_TYPE, NONSTD, BOOL, CHAR, SHORT, INT, LONG, LONGLONG, FLOAT, DOUBLE, LONGDOUBLE} type; + enum Type {UNKNOWN_TYPE, NONSTD, VOID, BOOL, CHAR, SHORT, INT, LONG, LONGLONG, FLOAT, DOUBLE, LONGDOUBLE} type; unsigned int pointer; // 0=>not pointer, 1=>*, 2=>**, 3=>***, etc unsigned int constness; // bit 0=data, bit 1=*, bit 2=** const Scope *typeScope; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 6efaf3d1b..b4d87cd57 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -3044,6 +3044,7 @@ private: ASSERT_EQUALS("const short *", typeOf("L\"hello\" + 1", "+")); // Variable calculations + ASSERT_EQUALS("void *", typeOf("void *p; a = p + 1;", "+")); ASSERT_EQUALS("int", typeOf("int x; a = x + 1;", "+")); ASSERT_EQUALS("int", typeOf("int x; a = x | 1;", "|")); ASSERT_EQUALS("float", typeOf("float x; a = x + 1;", "+")); @@ -3061,10 +3062,12 @@ private: ASSERT_EQUALS("int", typeOf("struct X {int i;}; void f(struct X x) { x.i }", ".")); // array.. + ASSERT_EQUALS("void * *", typeOf("void * x[10]; a = x + 0;", "+")); ASSERT_EQUALS("int *", typeOf("int x[10]; a = x + 1;", "+")); ASSERT_EQUALS("int", typeOf("int x[10]; a = x[0] + 1;", "+")); // cast.. + ASSERT_EQUALS("void *", typeOf("a = (void *)0;", "(")); ASSERT_EQUALS("char", typeOf("a = (char)32;", "(")); ASSERT_EQUALS("long", typeOf("a = (long)32;", "(")); ASSERT_EQUALS("long", typeOf("a = (long int)32;", "("));