Skip to content

Commit 4e35173

Browse files
Fix #12946 Calling base class on different object is ignored (#6606)
1 parent c7bc7a8 commit 4e35173

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

lib/checkclass.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3296,6 +3296,8 @@ void CheckClass::checkUselessOverride()
32963296
if (const Token* const call = getSingleFunctionCall(func.functionScope)) {
32973297
if (call->function() != baseFunc)
32983298
continue;
3299+
if (Token::simpleMatch(call->astParent(), "."))
3300+
continue;
32993301
std::vector<const Token*> funcArgs = getArguments(func.tokenDef);
33003302
std::vector<const Token*> callArgs = getArguments(call);
33013303
if (funcArgs.size() != callArgs.size() ||

test/testclass.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8732,6 +8732,16 @@ class TestClass : public TestFixture {
87328732
" virtual void g() { std::cout << \"Derived\\n\"; }\n"
87338733
"};\n");
87348734
ASSERT_EQUALS("", errout_str());
8735+
8736+
checkUselessOverride("struct B {\n" // #12946
8737+
" virtual int f() { return i; }\n"
8738+
" int i;\n"
8739+
"};\n"
8740+
"struct D : B {\n"
8741+
" int f() override { return b.f(); }\n"
8742+
" B b;\n"
8743+
"};\n");
8744+
ASSERT_EQUALS("", errout_str());
87358745
}
87368746

87378747
#define checkUnsafeClassRefMember(code) checkUnsafeClassRefMember_(code, __FILE__, __LINE__)

0 commit comments

Comments
 (0)