diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 8fbd0c007..f8c18a6f6 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2135,6 +2135,8 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool& return false; const Token* lhs = tok1->previous(); + if (lhs->str() == "(" && tok1->astParent() && tok1->astParent()->astParent()) + lhs = tok1->astParent()->astParent(); if (lhs->str() == "&") { lhs = lhs->previous(); if (lhs->isAssignmentOp() && lhs->previous()->variable()) { diff --git a/test/testclass.cpp b/test/testclass.cpp index d4b37eaf9..b81c9a444 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -445,7 +445,7 @@ private: "};"); ASSERT_EQUALS("[test.cpp:1]: (style) Struct 'A' has a constructor with 1 argument that is not explicit.\n", errout.str()); - checkExplicitConstructors("struct Foo {\n" + checkExplicitConstructors("struct Foo {\n" // #10515 " template \n" " explicit constexpr Foo(T) {}\n" "};\n" @@ -5797,6 +5797,14 @@ private: " void g() { bar.f(k); }\n" "};\n"); ASSERT_EQUALS("", errout.str()); + + checkConst("struct S {\n" + " A a;\n" + " void f(int j, int*& p) {\n" + " p = &(((a[j])));\n" + " }\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); } void const_handleDefaultParameters() {