diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 03c617a02..4cc1f2f2a 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1567,6 +1567,8 @@ void CheckOther::checkConstPointer() deref = true; else if (Token::simpleMatch(parent, "[") && parent->astOperand1() == tok && tok != nameTok) deref = true; + else if (Token::Match(parent, "%op%") && Token::simpleMatch(parent->astParent(), ".")) + deref = true; if (deref) { const Token* const gparent = parent->astParent(); if (Token::Match(gparent, "%cop%") && !gparent->isUnaryOp("&") && !gparent->isUnaryOp("*")) diff --git a/test/testother.cpp b/test/testother.cpp index 7f81727ec..5f0b47ae6 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3105,6 +3105,12 @@ private: " if (x == nullptr) {}\n" "}\n"); ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'x' can be declared as pointer to const\n", errout.str()); + + check("struct S { void v(); };\n" // #11095 + "void f(S* s) {\n" + " (s - 1)->v();\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void switchRedundantAssignmentTest() {