Fixed #8146 (false positive: enum initialized using class member initializer syntax in struct in struct) (#1270)

This commit is contained in:
IOBYTE 2018-05-30 09:40:16 -04:00 committed by Daniel Marjamäki
parent 4c9bde277a
commit 7681bbf227
2 changed files with 15 additions and 3 deletions

View File

@ -1668,7 +1668,7 @@ void Variable::evaluate(const Library* lib)
std::string strtype = _start->str();
for (const Token *typeToken = _start; Token::Match(typeToken, "%type% :: %type%"); typeToken = typeToken->tokAt(2))
strtype += "::" + typeToken->strAt(2);
setFlag(fIsClass, !lib->podtype(strtype) && !_start->isStandardType() && !isPointer() && !isReference());
setFlag(fIsClass, !lib->podtype(strtype) && !_start->isStandardType() && !isEnumType() && !isPointer() && !isReference());
setFlag(fIsStlType, Token::simpleMatch(_start, "std ::"));
setFlag(fIsStlString, isStlType() && (Token::Match(_start->tokAt(2), "string|wstring|u16string|u32string !!::") || (Token::simpleMatch(_start->tokAt(2), "basic_string <") && !Token::simpleMatch(_start->linkAt(3), "> ::"))));
}

View File

@ -144,7 +144,8 @@ private:
TEST_CASE(uninitVar29);
TEST_CASE(uninitVar30); // ticket #6417
TEST_CASE(uninitVar31); // ticket #8271
TEST_CASE(uninitVarEnum);
TEST_CASE(uninitVarEnum1);
TEST_CASE(uninitVarEnum2); // ticket #8146
TEST_CASE(uninitVarStream);
TEST_CASE(uninitVarTypedef);
TEST_CASE(uninitVarMemset);
@ -2821,7 +2822,7 @@ private:
}
void uninitVarEnum() {
void uninitVarEnum1() {
check("class Fred\n"
"{\n"
"public:\n"
@ -2834,6 +2835,17 @@ private:
ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'Fred::i' is not initialized in the constructor.\n", errout.str());
}
void uninitVarEnum2() { // ticket #8146
check("enum E { E1 };\n"
"struct X { E e = E1; };\n"
"struct Y {\n"
" Y() {}\n"
" X x;\n"
"};");
ASSERT_EQUALS("", errout.str());
}
void uninitVarStream() {
check("class Foo\n"
"{\n"