Fixed travis failure

This commit is contained in:
Daniel Marjamäki 2015-05-25 18:19:40 +02:00
parent a9db06c641
commit a8d7897471
2 changed files with 18 additions and 2 deletions

View File

@ -315,7 +315,9 @@ void CheckType::checkLongCast()
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
if (!Token::Match(tok, "%var% ="))
continue;
if (!tok->variable() || !tok->variable()->isConst() || tok->variable()->typeStartToken()->originalName() != "long")
if (!tok->variable() || !tok->variable()->isConst() || tok->variable()->typeStartToken()->str() != "long")
continue;
if (!tok->variable()->typeStartToken()->originalName().empty())
continue;
if (Token::Match(tok->next()->astOperand2(), "*|<<") && astIsIntResult(tok->next()->astOperand2()))
longCastAssignError(tok);
@ -331,7 +333,7 @@ void CheckType::checkLongCast()
const Token * def = scope->classDef;
bool islong = false;
while (Token::Match(def, "%type%|::")) {
if (def->originalName() == "long") {
if (def->str() == "long" && def->originalName().empty()) {
islong = true;
break;
}

View File

@ -140,6 +140,7 @@ private:
void longCastAssign() {
Settings settings;
settings.addEnabled("style");
settings.platform(Settings::PlatformType::Unix64);
check("long f(int x, int y) {\n"
" const long ret = x * y;\n"
@ -147,6 +148,13 @@ private:
"}\n", &settings);
ASSERT_EQUALS("[test.cpp:2]: (style) possible loss of information, int result is assigned to long variable\n", errout.str());
// typedef
check("long f(int x, int y) {\n"
" const size_t ret = x * y;\n"
" return ret;\n"
"}\n", &settings);
ASSERT_EQUALS("", errout.str());
// astIsIntResult
check("long f(int x, int y) {\n"
" const long ret = (long)x * y;\n"
@ -163,6 +171,12 @@ private:
" return x * y;\n"
"}\n", &settings);
ASSERT_EQUALS("[test.cpp:2]: (style) possible loss of information, int result is returned as long value\n", errout.str());
// typedef
check("size_t f(int x, int y) {\n"
" return x * y;\n"
"}\n", &settings);
ASSERT_EQUALS("", errout.str());
}
};