Skip to content

Commit 0f42d81

Browse files
Fix #12706 FP uselessOverride with virtual function in derived class (#6382)
1 parent 84cf512 commit 0f42d81

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/checkclass.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3230,6 +3230,8 @@ static bool compareTokenRanges(const Token* start1, const Token* end1, const Tok
32303230
const Token* tok2 = start2;
32313231
bool isEqual = false;
32323232
while (tok1 && tok2) {
3233+
if (tok1->function() != tok2->function())
3234+
break;
32333235
if (tok1->str() != tok2->str())
32343236
break;
32353237
if (tok1->str() == "this")

test/testclass.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8678,6 +8678,16 @@ class TestClass : public TestFixture {
86788678
" int f() override { return MACRO; }\n"
86798679
"};\n");
86808680
ASSERT_EQUALS("", errout_str());
8681+
8682+
checkUselessOverride("struct B {\n" // #12706
8683+
" virtual void f() { g(); }\n"
8684+
" void g() { std::cout << \"Base\\n\"; }\n"
8685+
"};\n"
8686+
"struct D : B {\n"
8687+
" void f() override { g(); }\n"
8688+
" virtual void g() { std::cout << \"Derived\\n\"; }\n"
8689+
"};\n");
8690+
ASSERT_EQUALS("", errout_str());
86818691
}
86828692

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

0 commit comments

Comments
 (0)