diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index d8aa3f58d..a0cce20cf 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -5355,7 +5355,8 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const const Scope * scope = tok->scope(); // check if this function is a member function - if (scope && scope->functionOf && scope->functionOf->isClassOrStruct() && scope->function) { + if (scope && scope->functionOf && scope->functionOf->isClassOrStruct() && scope->function && + func->nestedIn == scope->functionOf) { // check if isConst mismatches if (scope->function->isConst() != func->isConst()) { if (scope->function->isConst()) { diff --git a/test/testother.cpp b/test/testother.cpp index f82825b04..38a3a9bd6 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3158,6 +3158,21 @@ private: " a.fill(0);\n" "}\n"); ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'a' can be declared as const array\n", errout.str()); + + // #11682 + check("struct b {\n" + " void mutate();\n" + "};\n" + "struct c {\n" + " const b& get() const;\n" + " b get();\n" + "};\n" + "struct d {\n" + " void f(c& e) const {\n" + " e.get().mutate();\n" + " }\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); } void constParameterCallback() {