Uninitialized member variables: Checking enum variables
This commit is contained in:
parent
b9460ca6f8
commit
22583269c1
|
@ -87,6 +87,8 @@ struct CheckClass::VAR *CheckClass::ClassChecking_GetVarList(const Token *tok1)
|
||||||
{
|
{
|
||||||
if (next->isStandardType())
|
if (next->isStandardType())
|
||||||
varname = next->strAt(1);
|
varname = next->strAt(1);
|
||||||
|
else if (Token::findmatch(_tokenizer->tokens(), ("enum " + next->str()).c_str()))
|
||||||
|
varname = next->strAt(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pointer?
|
// Pointer?
|
||||||
|
|
|
@ -41,6 +41,8 @@ private:
|
||||||
TEST_CASE(virtualDestructor3); // Base class has a destructor, but it's not virtual
|
TEST_CASE(virtualDestructor3); // Base class has a destructor, but it's not virtual
|
||||||
TEST_CASE(virtualDestructor4); // Derived class doesn't have a destructor => no error
|
TEST_CASE(virtualDestructor4); // Derived class doesn't have a destructor => no error
|
||||||
TEST_CASE(virtualDestructor5); // Derived class has empty destructor => no error
|
TEST_CASE(virtualDestructor5); // Derived class has empty destructor => no error
|
||||||
|
|
||||||
|
TEST_CASE(uninitVar1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that base classes have virtual destructors
|
// Check that base classes have virtual destructors
|
||||||
|
@ -124,6 +126,45 @@ private:
|
||||||
"class Derived : public Base { public: ~Derived(); }; Derived::~Derived() {}");
|
"class Derived : public Base { public: ~Derived(); }; Derived::~Derived() {}");
|
||||||
ASSERT_EQUALS(std::string(""), errout.str());
|
ASSERT_EQUALS(std::string(""), errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void checkUninitVar(const char code[])
|
||||||
|
{
|
||||||
|
// Tokenize..
|
||||||
|
Tokenizer tokenizer;
|
||||||
|
std::istringstream istr(code);
|
||||||
|
tokenizer.tokenize(istr, "test.cpp");
|
||||||
|
tokenizer.simplifyTokenList();
|
||||||
|
|
||||||
|
// Clear the error log
|
||||||
|
errout.str("");
|
||||||
|
|
||||||
|
// Check..
|
||||||
|
Settings settings;
|
||||||
|
CheckClass checkClass(&tokenizer, settings, this);
|
||||||
|
checkClass.constructors();
|
||||||
|
}
|
||||||
|
|
||||||
|
void uninitVar1()
|
||||||
|
{
|
||||||
|
checkUninitVar("enum ECODES\n"
|
||||||
|
"{\n"
|
||||||
|
" CODE_1 = 0,\n"
|
||||||
|
" CODE_2 = 1\n"
|
||||||
|
"};\n"
|
||||||
|
"\n"
|
||||||
|
"class Fred\n"
|
||||||
|
"{\n"
|
||||||
|
"public:\n"
|
||||||
|
" Fred() {}\n"
|
||||||
|
"\n"
|
||||||
|
"private:\n"
|
||||||
|
" ECODES _code;\n"
|
||||||
|
"};\n" );
|
||||||
|
|
||||||
|
ASSERT_EQUALS("[test.cpp:10]: Uninitialized member variable 'Fred::_code'\n", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_TEST(TestClass)
|
REGISTER_TEST(TestClass)
|
||||||
|
|
Loading…
Reference in New Issue