Fix crash in constPointer() (#4932)
* Fix crash in constPointer() * Format
This commit is contained in:
parent
b2b0962067
commit
86efca28a3
|
@ -1479,7 +1479,7 @@ void CheckOther::checkConstVariable()
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (Token::Match(tok, "& %varid%", var->declarationId())) {
|
||||
if (tok->isUnaryOp("&") && Token::Match(tok, "& %varid%", var->declarationId())) {
|
||||
const Token* opTok = tok->astParent();
|
||||
if (opTok->isComparisonOp() || opTok->isAssignmentOp() || opTok->isCalculation()) {
|
||||
if (opTok->isComparisonOp() || opTok->isCalculation()) {
|
||||
|
|
|
@ -3453,6 +3453,17 @@ private:
|
|||
"[test.cpp:11]: (style) Parameter 's' can be declared as pointer to const\n"
|
||||
"[test.cpp:14]: (style) Parameter 's' can be declared as pointer to const\n",
|
||||
errout.str());
|
||||
|
||||
check("struct S { int a; };\n"
|
||||
"void f(std::vector<S>& v, int b) {\n"
|
||||
" size_t n = v.size();\n"
|
||||
" for (size_t i = 0; i < n; i++) {\n"
|
||||
" S& s = v[i];\n"
|
||||
" if (!(b & s.a))\n"
|
||||
" continue;\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:5]: (style) Variable 's' can be declared as reference to const\n", errout.str()); // don't crash
|
||||
}
|
||||
|
||||
void switchRedundantAssignmentTest() {
|
||||
|
|
Loading…
Reference in New Issue