CheckIO: Handle AST pointer type better
This commit is contained in:
parent
b9036c2ca8
commit
b77203a277
|
@ -1368,9 +1368,17 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings,
|
||||||
// TODO: This is a bailout so that old code is used in simple cases. Remove the old code and always use the AST type.
|
// TODO: This is a bailout so that old code is used in simple cases. Remove the old code and always use the AST type.
|
||||||
if (!Token::Match(tok, "&| %str%|%num%|%name% ,|)") && !Token::Match(tok, "%name% [|(|.|<|::|?")) {
|
if (!Token::Match(tok, "&| %str%|%num%|%name% ,|)") && !Token::Match(tok, "%name% [|(|.|<|::|?")) {
|
||||||
const ValueType *valuetype = tok->argumentType();
|
const ValueType *valuetype = tok->argumentType();
|
||||||
if (valuetype && valuetype->type >= ValueType::Type::BOOL && !valuetype->pointer) {
|
if (valuetype && valuetype->type >= ValueType::Type::BOOL) {
|
||||||
tempToken = new Token(0);
|
tempToken = new Token(0);
|
||||||
if (valuetype->type <= ValueType::INT)
|
if (valuetype->pointer == 0U && valuetype->type <= ValueType::INT)
|
||||||
|
tempToken->str("int");
|
||||||
|
else if (valuetype->type == ValueType::BOOL)
|
||||||
|
tempToken->str("bool");
|
||||||
|
else if (valuetype->type == ValueType::CHAR)
|
||||||
|
tempToken->str("char");
|
||||||
|
else if (valuetype->type == ValueType::SHORT)
|
||||||
|
tempToken->str("short");
|
||||||
|
else if (valuetype->type == ValueType::INT)
|
||||||
tempToken->str("int");
|
tempToken->str("int");
|
||||||
else if (valuetype->type == ValueType::LONG)
|
else if (valuetype->type == ValueType::LONG)
|
||||||
tempToken->str("long");
|
tempToken->str("long");
|
||||||
|
@ -1387,6 +1395,8 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings,
|
||||||
else if (valuetype->sign == ValueType::Sign::SIGNED)
|
else if (valuetype->sign == ValueType::Sign::SIGNED)
|
||||||
tempToken->isSigned(true);
|
tempToken->isSigned(true);
|
||||||
}
|
}
|
||||||
|
for (unsigned int p = 0; p < valuetype->pointer; p++)
|
||||||
|
tempToken->insertToken("*");
|
||||||
typeToken = tempToken;
|
typeToken = tempToken;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3736,6 +3736,10 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void test() {\n"
|
||||||
|
" printf(\"%i\", (short *)x);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:2]: (warning) %i in format string (no. 1) requires 'int' but the argument type is 'short *'.\n", errout.str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue