Reviewed handling of unknown types in CheckUninitVar

This commit is contained in:
Daniel Marjamäki 2012-06-22 16:39:39 +02:00
parent 354406441a
commit abaa044e03
2 changed files with 18 additions and 1 deletions

View File

@ -1052,7 +1052,7 @@ void CheckUninitVar::checkScope(const Scope* scope)
if (forHead)
continue;
bool stdtype = false;
bool stdtype = _tokenizer->isC();
const Token* tok = i->typeStartToken();
for (; tok->str() != ";" && tok->str() != "<"; tok = tok->next()) {
if (tok->isStandardType())

View File

@ -55,6 +55,7 @@ private:
TEST_CASE(uninitvar3); // #3844
TEST_CASE(uninitvar4); // #3869 (reference)
TEST_CASE(uninitvar5); // #3861
TEST_CASE(uninitvar6); // handling unknown types in C and C++ files
}
void checkUninitVar(const char code[]) {
@ -2193,6 +2194,22 @@ private:
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: c\n", errout.str());
}
// Handling of unknown types. Assume they are POD in C.
void uninitvar6() {
const char code[] = "void f() {\n"
" dfs a;\n"
" return a;\n"
"}";
// Assume dfs is a non POD type if file is C++
checkUninitVar2(code, "test.cpp");
ASSERT_EQUALS("", errout.str());
// Assume dfs is a POD type if file is C
checkUninitVar2(code, "test.c");
ASSERT_EQUALS("[test.c:3]: (error) Uninitialized variable: a\n", errout.str());
}
};
REGISTER_TEST(TestUninitVar)