ValueType: refactor and improve handling of 'new ...'
This commit is contained in:
parent
6a718baae5
commit
e0dd0a82ed
|
@ -4861,25 +4861,30 @@ void SymbolDatabase::setValueTypeInTokenList(Token *tokens, bool cpp, const Sett
|
|||
} else if (tok->enumerator()) {
|
||||
setValueType(tok, *tok->enumerator(), cpp, defsign, settings);
|
||||
} else if (cpp && tok->str() == "new") {
|
||||
if (Token::Match(tok, "new %type% ;|[") ||
|
||||
Token::Match(tok, "new ( std| ::| nothrow ) %type% ;|[")) {
|
||||
ValueType vt;
|
||||
vt.pointer = 1;
|
||||
const Token * typeTok = tok->next();
|
||||
if (typeTok->str() == "(")
|
||||
typeTok = typeTok->link()->next();
|
||||
const Token *typeTok = tok->next();
|
||||
if (Token::Match(typeTok, "( std| ::| nothrow )"))
|
||||
typeTok = typeTok->link()->next();
|
||||
if (!Token::Match(typeTok, "%type% ;|[|("))
|
||||
return;
|
||||
ValueType vt;
|
||||
vt.pointer = 1;
|
||||
if (typeTok->type() && typeTok->type()->classScope) {
|
||||
vt.type = ValueType::Type::NONSTD;
|
||||
vt.typeScope = typeTok->type()->classScope;
|
||||
} else {
|
||||
vt.type = ValueType::typeFromString(typeTok->str(), typeTok->isLong());
|
||||
if (vt.type == ValueType::Type::UNKNOWN_TYPE)
|
||||
vt.fromLibraryType(typeTok->str(), settings);
|
||||
if (vt.type == ValueType::Type::UNKNOWN_TYPE)
|
||||
return;
|
||||
if (typeTok->isUnsigned())
|
||||
vt.sign = ValueType::Sign::UNSIGNED;
|
||||
else if (typeTok->isSigned())
|
||||
vt.sign = ValueType::Sign::SIGNED;
|
||||
if (vt.sign == ValueType::Sign::UNKNOWN_SIGN && vt.isIntegral())
|
||||
vt.sign = (vt.type == ValueType::Type::CHAR) ? defsign : ValueType::Sign::SIGNED;
|
||||
if (vt.type != ValueType::Type::UNKNOWN_TYPE)
|
||||
setValueType(tok, vt, cpp, defsign, settings);
|
||||
}
|
||||
setValueType(tok, vt, cpp, defsign, settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4309,6 +4309,9 @@ private:
|
|||
ASSERT_EQUALS(ValueType::Type::INT, vt.type);
|
||||
}
|
||||
|
||||
// new
|
||||
ASSERT_EQUALS("C *", typeOf("class C {}; x = new C();", "new"));
|
||||
|
||||
// auto variables
|
||||
ASSERT_EQUALS("signed int", typeOf("; auto x = 3;", "x"));
|
||||
ASSERT_EQUALS("signed int *", typeOf("; auto *p = (int *)0;", "p"));
|
||||
|
|
Loading…
Reference in New Issue