Fix 11682: False positive: constParameterReference with overloaded method (#5038)

* Fix 11682: False positive: constParameterReference with overloaded method

* Format
This commit is contained in:
Paul Fultz II 2023-05-05 04:27:15 -05:00 committed by GitHub
parent 1db510b9fd
commit 543b4adc8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -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()) {

View File

@ -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() {