Skip to content

Commit

Permalink
Fix #12706 FP uselessOverride with virtual function in derived class (d…
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored May 4, 2024
1 parent 84cf512 commit 0f42d81
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3230,6 +3230,8 @@ static bool compareTokenRanges(const Token* start1, const Token* end1, const Tok
const Token* tok2 = start2;
bool isEqual = false;
while (tok1 && tok2) {
if (tok1->function() != tok2->function())
break;
if (tok1->str() != tok2->str())
break;
if (tok1->str() == "this")
Expand Down
10 changes: 10 additions & 0 deletions test/testclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8678,6 +8678,16 @@ class TestClass : public TestFixture {
" int f() override { return MACRO; }\n"
"};\n");
ASSERT_EQUALS("", errout_str());

checkUselessOverride("struct B {\n" // #12706
" virtual void f() { g(); }\n"
" void g() { std::cout << \"Base\\n\"; }\n"
"};\n"
"struct D : B {\n"
" void f() override { g(); }\n"
" virtual void g() { std::cout << \"Derived\\n\"; }\n"
"};\n");
ASSERT_EQUALS("", errout_str());
}

#define checkUnsafeClassRefMember(code) checkUnsafeClassRefMember_(code, __FILE__, __LINE__)
Expand Down

0 comments on commit 0f42d81

Please sign in to comment.