diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 3bae7290c..aef09625e 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -462,9 +462,9 @@ static bool checkExceptionHandling(const Token* tok) { const Variable* var = tok->variable(); const Scope* upperScope = tok->scope(); - if (upperScope == var->scope()) + if (var && upperScope == var->scope()) return true; - while (upperScope && upperScope->type != Scope::eTry && upperScope->type != Scope::eLambda && upperScope->nestedIn != var->scope() && upperScope->isExecutable()) { + while (upperScope && upperScope->type != Scope::eTry && upperScope->type != Scope::eLambda && (!var || upperScope->nestedIn != var->scope()) && upperScope->isExecutable()) { upperScope = upperScope->nestedIn; } if (upperScope && upperScope->type == Scope::eTry) { diff --git a/test/testother.cpp b/test/testother.cpp index c7a8d3fa5..e2949df83 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -5608,6 +5608,16 @@ private: " }\n" "}"); ASSERT_EQUALS("", errout.str()); + + // Member variable pointers + check("void podMemPtrs() {\n" + " int POD::*memptr;\n" + " memptr = &POD::a;\n" + " memptr = &POD::b;\n" + " if (memptr)\n" + " memptr = 0;\n" + "}"); + ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (performance, inconclusive) Variable 'memptr' is reassigned a value before the old one has been used if variable is no semaphore variable.\n", errout.str()); } void redundantMemWrite() {