Fixed #9875 (Crash)

This commit is contained in:
Daniel Marjamäki 2020-09-04 19:15:48 +02:00
parent 30d3643bb8
commit 1daf1ec108
2 changed files with 14 additions and 1 deletions

View File

@ -1412,9 +1412,15 @@ void CheckOther::checkConstVariable()
bool castToNonConst = false;
for (const Token* tok = var->nameToken(); tok != scope->bodyEnd && tok != nullptr; tok = tok->next()) {
if (tok->isCast()) {
if (!tok->valueType()) {
castToNonConst = true; // safe guess
break;
}
bool isConst = 0 != (tok->valueType()->constness & (1 << tok->valueType()->pointer));
if (!isConst)
if (!isConst) {
castToNonConst = true;
break;
}
}
}
if (castToNonConst)

View File

@ -2232,6 +2232,13 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
check("struct C { void f() const; };\n" // #9875 - crash
"\n"
"void foo(C& x) {\n"
" x.f();\n"
" foo( static_cast<U2>(0) );\n"
"}");
ASSERT_EQUALS("", errout.str());
check("class a {\n"
" void foo(const int& i) const;\n"