Skip to content

Commit a6ca3cf

Browse files
committed
Throw syntaxError when encounter one in symboldatabase (fixes cppcheck-opensource#5572)
1 parent efe3f83 commit a6ca3cf

2 files changed

Lines changed: 8 additions & 13 deletions

File tree

‎lib/symboldatabase.cpp‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
147147

148148
// make sure we have valid code
149149
if (!tok2) {
150-
scopeList.pop_back();
151-
break;
150+
_tokenizer->syntaxError(tok);
152151
}
153152
}
154153

@@ -157,8 +156,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
157156

158157
// make sure we have valid code
159158
if (!new_scope->classEnd) {
160-
scopeList.pop_back();
161-
break;
159+
_tokenizer->syntaxError(tok);
162160
}
163161

164162
// make the new scope the current scope

‎test/testsymboldatabase.cpp‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,16 +1402,12 @@ class TestSymbolDatabase: public TestFixture {
14021402

14031403
void symboldatabase14() {
14041404
// ticket #2589 - segmentation fault
1405-
check("struct B : A\n");
1406-
1407-
ASSERT_EQUALS("", errout.str());
1405+
ASSERT_THROW(check("struct B : A\n"), InternalError);
14081406
}
14091407

14101408
void symboldatabase15() {
14111409
// ticket #2591 - segmentation fault
1412-
check("struct A :\n");
1413-
1414-
ASSERT_EQUALS("", errout.str());
1410+
ASSERT_THROW(check("struct A :\n"), InternalError);
14151411
}
14161412

14171413
void symboldatabase16() {
@@ -1444,9 +1440,7 @@ class TestSymbolDatabase: public TestFixture {
14441440

14451441
void symboldatabase20() {
14461442
// ticket #3013 - segmentation fault
1447-
check("struct x : virtual y\n");
1448-
1449-
ASSERT_EQUALS("", errout.str());
1443+
ASSERT_THROW(check("struct x : virtual y\n"), InternalError);
14501444
}
14511445

14521446
void symboldatabase21() {
@@ -1851,6 +1845,9 @@ class TestSymbolDatabase: public TestFixture {
18511845
GET_SYMBOL_DB("{ }; void namespace A::f; { g() { int } }");
18521846
(void)db;
18531847
}
1848+
{
1849+
ASSERT_THROW(GET_SYMBOL_DB("class Foo {}; class Bar : public Foo"), InternalError);
1850+
}
18541851
}
18551852

18561853
void findFunction1() {

0 commit comments

Comments
 (0)