ValueType: handle new nothrow

This commit is contained in:
Robert Reif 2017-03-05 02:13:00 +01:00 committed by Daniel Marjamäki
parent 115ea08544
commit e02b2c4483
2 changed files with 7 additions and 2 deletions

View File

@ -4861,10 +4861,13 @@ void SymbolDatabase::setValueTypeInTokenList(Token *tokens, bool cpp, const Sett
} else if (tok->enumerator()) { } else if (tok->enumerator()) {
setValueType(tok, *tok->enumerator(), cpp, defsign, settings); setValueType(tok, *tok->enumerator(), cpp, defsign, settings);
} else if (cpp && tok->str() == "new") { } else if (cpp && tok->str() == "new") {
if (Token::Match(tok, "new %type% ;|[")) { if (Token::Match(tok, "new %type% ;|[") ||
Token::Match(tok, "new ( std| ::| nothrow ) %type% ;|[")) {
ValueType vt; ValueType vt;
vt.pointer = 1; vt.pointer = 1;
const Token * const typeTok = tok->next(); const Token * typeTok = tok->next();
if (typeTok->str() == "(")
typeTok = typeTok->link()->next();
vt.type = ValueType::typeFromString(typeTok->str(), typeTok->isLong()); vt.type = ValueType::typeFromString(typeTok->str(), typeTok->isLong());
if (vt.type == ValueType::Type::UNKNOWN_TYPE) if (vt.type == ValueType::Type::UNKNOWN_TYPE)
vt.fromLibraryType(typeTok->str(), settings); vt.fromLibraryType(typeTok->str(), settings);

View File

@ -4313,6 +4313,8 @@ private:
ASSERT_EQUALS("signed int", typeOf("; auto x = 3;", "x")); ASSERT_EQUALS("signed int", typeOf("; auto x = 3;", "x"));
ASSERT_EQUALS("signed int *", typeOf("; auto *p = (int *)0;", "p")); ASSERT_EQUALS("signed int *", typeOf("; auto *p = (int *)0;", "p"));
ASSERT_EQUALS("signed int *", typeOf("; auto data = new int[100];", "data")); ASSERT_EQUALS("signed int *", typeOf("; auto data = new int[100];", "data"));
ASSERT_EQUALS("signed int *", typeOf("; auto data = new (nothrow) int[100];", "data"));
ASSERT_EQUALS("signed int *", typeOf("; auto data = new (std::nothrow) int[100];", "data"));
ASSERT_EQUALS("const signed short", typeOf("short values[10]; void f() { for (const auto *x : values); }", "x")); ASSERT_EQUALS("const signed short", typeOf("short values[10]; void f() { for (const auto *x : values); }", "x"));
ASSERT_EQUALS("signed int *", typeOf("MACRO(test) void test() { auto x = (int*)y; }", "x")); // #7931 (garbage?) ASSERT_EQUALS("signed int *", typeOf("MACRO(test) void test() { auto x = (int*)y; }", "x")); // #7931 (garbage?)
} }