diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 04746676b..f172a9d3d 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -435,7 +435,7 @@ void CheckClass::initializeVarList(const Function &func, std::listlink()->next(); int level = 0; - for (; ftok != func.functionScope->classEnd; ftok = ftok->next()) { + for (; ftok && ftok != func.functionScope->classEnd; ftok = ftok->next()) { // Class constructor.. initializing variables like this // clKalle::clKalle() : var(value) { } if (initList) { diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index 044e5d655..5ef19fa02 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -162,6 +162,7 @@ private: TEST_CASE(uninitVarOperatorEqual); // ticket #2415 TEST_CASE(uninitVarPointer); // ticket #3801 TEST_CASE(uninitConstVar); + TEST_CASE(constructors_crash1); // ticket #5641 } @@ -2901,6 +2902,16 @@ private: "};"); ASSERT_EQUALS("", errout.str()); } + + // Ticket #5641 "Regression. Crash for 'C() _STLP_NOTHROW {}'" + void constructors_crash1() { + check("class C {\n" + "public:\n" + " C() _STLP_NOTHROW {}\n" + " C(const C&) _STLP_NOTHROW {}\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestConstructors)