diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index b2aee23f6..dcc0bfcfa 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -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()) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 88a427ca7..f750ee772 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -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)