Skip to content

Commit

Permalink
Fix #12620 Crash in checkReturnByReference() (#6300)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Apr 17, 2024
1 parent 8b518bf commit 3a212f1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3306,7 +3306,7 @@ void CheckClass::checkUselessOverride()
}

static const Variable* getSingleReturnVar(const Scope* scope) {
if (!scope)
if (!scope || !scope->bodyStart)
return nullptr;
const Token* const start = scope->bodyStart->next();
const Token* const end = Token::findsimplematch(start, ";", 1, scope->bodyEnd);
Expand Down
4 changes: 4 additions & 0 deletions test/testclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8951,6 +8951,10 @@ class TestClass : public TestFixture {
" std::string f(std::string s) { return s; }\n"
"};\n");
ASSERT_EQUALS("", errout_str());

checkReturnByReference("struct S { S(); };\n" // #12620
"S::S() = delete;\n");
ASSERT_EQUALS("", errout_str()); // don't crash
}
};

Expand Down

0 comments on commit 3a212f1

Please sign in to comment.