Skip to content

Commit 7681bbf

Browse files
IOBYTEdanmar
authored andcommitted
Fixed #8146 (false positive: enum initialized using class member initializer syntax in struct in struct) (#1270)
1 parent 4c9bde2 commit 7681bbf

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,7 @@ void Variable::evaluate(const Library* lib)
16681668
std::string strtype = _start->str();
16691669
for (const Token *typeToken = _start; Token::Match(typeToken, "%type% :: %type%"); typeToken = typeToken->tokAt(2))
16701670
strtype += "::" + typeToken->strAt(2);
1671-
setFlag(fIsClass, !lib->podtype(strtype) && !_start->isStandardType() && !isPointer() && !isReference());
1671+
setFlag(fIsClass, !lib->podtype(strtype) && !_start->isStandardType() && !isEnumType() && !isPointer() && !isReference());
16721672
setFlag(fIsStlType, Token::simpleMatch(_start, "std ::"));
16731673
setFlag(fIsStlString, isStlType() && (Token::Match(_start->tokAt(2), "string|wstring|u16string|u32string !!::") || (Token::simpleMatch(_start->tokAt(2), "basic_string <") && !Token::simpleMatch(_start->linkAt(3), "> ::"))));
16741674
}

test/testconstructors.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ class TestConstructors : public TestFixture {
144144
TEST_CASE(uninitVar29);
145145
TEST_CASE(uninitVar30); // ticket #6417
146146
TEST_CASE(uninitVar31); // ticket #8271
147-
TEST_CASE(uninitVarEnum);
147+
TEST_CASE(uninitVarEnum1);
148+
TEST_CASE(uninitVarEnum2); // ticket #8146
148149
TEST_CASE(uninitVarStream);
149150
TEST_CASE(uninitVarTypedef);
150151
TEST_CASE(uninitVarMemset);
@@ -2821,7 +2822,7 @@ class TestConstructors : public TestFixture {
28212822

28222823
}
28232824

2824-
void uninitVarEnum() {
2825+
void uninitVarEnum1() {
28252826
check("class Fred\n"
28262827
"{\n"
28272828
"public:\n"
@@ -2834,6 +2835,17 @@ class TestConstructors : public TestFixture {
28342835
ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'Fred::i' is not initialized in the constructor.\n", errout.str());
28352836
}
28362837

2838+
void uninitVarEnum2() { // ticket #8146
2839+
check("enum E { E1 };\n"
2840+
"struct X { E e = E1; };\n"
2841+
"struct Y {\n"
2842+
" Y() {}\n"
2843+
" X x;\n"
2844+
"};");
2845+
2846+
ASSERT_EQUALS("", errout.str());
2847+
}
2848+
28372849
void uninitVarStream() {
28382850
check("class Foo\n"
28392851
"{\n"

0 commit comments

Comments
 (0)