ValueType: Handle void pointers

This commit is contained in:
Daniel Marjamäki 2015-12-29 19:58:51 +01:00
parent bd1037e95b
commit c5c386ceb8
3 changed files with 9 additions and 2 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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;", "("));