Fixed crash in clang test suite with member variable pointers

This commit is contained in:
PKEuS 2015-11-11 18:24:00 +01:00
parent 36c5815ddb
commit 1589841cb6
2 changed files with 12 additions and 2 deletions

View File

@ -462,9 +462,9 @@ static bool checkExceptionHandling(const Token* tok)
{ {
const Variable* var = tok->variable(); const Variable* var = tok->variable();
const Scope* upperScope = tok->scope(); const Scope* upperScope = tok->scope();
if (upperScope == var->scope()) if (var && upperScope == var->scope())
return true; 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; upperScope = upperScope->nestedIn;
} }
if (upperScope && upperScope->type == Scope::eTry) { if (upperScope && upperScope->type == Scope::eTry) {

View File

@ -5608,6 +5608,16 @@ private:
" }\n" " }\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); 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() { void redundantMemWrite() {