From 3a212f17d82483ff0997848c34ab581fea189f3d Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 17 Apr 2024 11:43:08 +0200 Subject: [PATCH] Fix #12620 Crash in checkReturnByReference() (#6300) --- lib/checkclass.cpp | 2 +- test/testclass.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 7dc6c3f1468..018b700104b 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -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); diff --git a/test/testclass.cpp b/test/testclass.cpp index c9dde77fae5..6f37f0c3c92 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -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 } };