diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 04365271c6e..7542e7d7b3a 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1723,7 +1723,7 @@ void CheckOther::checkConstVariable() if (retTok->varId() == var->declarationId()) return true; while (retTok && retTok->isCast()) - retTok = retTok->astOperand2(); + retTok = retTok->astOperand2() ? retTok->astOperand2() : retTok->astOperand1(); while (Token::simpleMatch(retTok, ".")) retTok = retTok->astOperand2(); if (Token::simpleMatch(retTok, "&")) diff --git a/test/testother.cpp b/test/testother.cpp index 28c812325d7..d1fc966d6ff 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3967,6 +3967,13 @@ class TestOther : public TestFixture { check("size_t* f(std::array& a) { return reinterpret_cast(a.data()); }\n"); // #14074 ASSERT_EQUALS("", errout_str()); + + check("struct S { int i; };\n" // #14231 + "void* f(S& s, int& v) {\n" + " v = s.i;\n" + " return (void*)&s;\n" + "}\n"); // don't crash + ASSERT_EQUALS("", errout_str()); } void constParameterCallback() {