Skip to content

Commit 623e5db

Browse files
committed
cppcheck-opensource#5702 crash: clang: test/Parser/cxx0x-member-initializers.cpp (bailout withn an internal error)
1 parent 6f3e3f5 commit 623e5db

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

‎lib/checkclass.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,8 @@ bool CheckClass::isBaseClassFunc(const Token *tok, const Scope *scope)
432432

433433
void CheckClass::initializeVarList(const Function &func, std::list<const Function *> &callstack, const Scope *scope, std::vector<Usage> &usage)
434434
{
435+
if (!func.functionScope)
436+
throw InternalError(0, "Internal Error: Invalid syntax"); // #5702
435437
bool initList = func.isConstructor();
436438
const Token *ftok = func.arg->link()->next();
437439
int level = 0;

‎test/testclass.cpp‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ class TestClass : public TestFixture {
183183
TEST_CASE(pureVirtualFunctionCallPrevented);
184184

185185
TEST_CASE(duplInheritedMembers);
186+
TEST_CASE(invalidInitializerList);
186187
}
187188

188189
void checkDuplInheritedMembers(const char code[]) {
@@ -1970,12 +1971,12 @@ class TestClass : public TestFixture {
19701971
ASSERT_EQUALS("[test.cpp:9]: (error) Class 'AA<double>' which is inherited by class 'B' does not have a virtual destructor.\n", errout.str());
19711972
}
19721973

1973-
void checkNoConstructor(const char code[]) {
1974+
void checkNoConstructor(const char code[], const char* level="style") {
19741975
// Clear the error log
19751976
errout.str("");
19761977

19771978
Settings settings;
1978-
settings.addEnabled("style");
1979+
settings.addEnabled(level);
19791980

19801981
// Tokenize..
19811982
Tokenizer tokenizer(&settings, this);
@@ -5974,6 +5975,12 @@ class TestClass : public TestFixture {
59745975
ASSERT_EQUALS("", errout.str());
59755976
}
59765977

5978+
void invalidInitializerList() {
5979+
ASSERT_THROW(checkNoConstructor("struct R1 {\n"
5980+
" int a;\n"
5981+
" R1 () : a { }\n"
5982+
"};\n", "warning"), InternalError);
5983+
}
59775984
};
59785985

59795986
REGISTER_TEST(TestClass)

0 commit comments

Comments
 (0)