diff --git a/lib/checkother.cpp b/lib/checkother.cpp index b5fd0dda361..5f056aa5ef0 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1943,13 +1943,16 @@ void CheckOtherImpl::checkConstPointer() if (deref == MEMBER) { if (!gparent) continue; - if (parent->astOperand2()) { - if (parent->astOperand2()->function() && parent->astOperand2()->function()->isConst()) + const Token* funcParent = parent; + while (Token::simpleMatch(funcParent->astParent(), ".")) + funcParent = funcParent->astParent(); + if (funcParent->astOperand2()) { + if (funcParent->astOperand2()->function() && funcParent->astOperand2()->function()->isConst()) continue; - if (mSettings.library.isFunctionConst(parent->astOperand2())) + if (mSettings.library.isFunctionConst(funcParent->astOperand2())) continue; - if (parent->astOperand2()->varId()) { - if (gparent->str() == "?" && astIsLHS(parent)) + if (funcParent->astOperand2()->varId()) { + if (gparent->str() == "?" && astIsLHS(funcParent)) continue; } } diff --git a/test/testother.cpp b/test/testother.cpp index 93e67229f43..7011e7edd8b 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4864,6 +4864,18 @@ class TestOther : public TestFixture { ASSERT_EQUALS("[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n" "[test.cpp:1:20]: (style) Parameter 'q' can be declared as pointer to const [constParameterPointer]\n", errout_str()); + + check("struct S { std::string a; };\n" // #13678 + "struct T { S s; };\n" + "bool f(S* s) {\n" + " return s->a.empty();\n" + "}\n" + "bool g(T* t) {\n" + " return t->s.a.empty();\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3:11]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\n" + "[test.cpp:6:11]: (style) Parameter 't' can be declared as pointer to const [constParameterPointer]\n", + errout_str()); } void constArray() {