Skip to content

Commit ffd9f9a

Browse files
Fix FP missingOverride with unnamed parameters (#3887)
1 parent e208fc6 commit ffd9f9a

2 files changed

Lines changed: 81 additions & 0 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,6 +2610,15 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se
26102610
} else if (second->next()->str() == "[" && first->next()->str() != "[")
26112611
first = first->next();
26122612

2613+
// unnamed parameters
2614+
else if (Token::Match(first, "(|, %type% ,|)") && Token::Match(second, "(|, %type% ,|)")) {
2615+
if (first->next()->expressionString() != second->next()->expressionString())
2616+
break;
2617+
first = first->next();
2618+
second = second->next();
2619+
continue;
2620+
}
2621+
26132622
// argument list has different number of arguments
26142623
else if (openParen == 1 && second->str() == ")" && first->str() != ")")
26152624
break;

test/testclass.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7539,6 +7539,78 @@ class TestClass : public TestFixture {
75397539
" };\n"
75407540
"}\n");
75417541
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:6]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier.\n", errout.str());
7542+
7543+
checkOverride("struct A {\n"
7544+
" virtual void f(int);\n"
7545+
"};\n"
7546+
"struct D : A {\n"
7547+
" void f(double);\n"
7548+
"};\n");
7549+
ASSERT_EQUALS("", errout.str());
7550+
7551+
checkOverride("struct A {\n"
7552+
" virtual void f(int);\n"
7553+
"};\n"
7554+
"struct D : A {\n"
7555+
" void f(int);\n"
7556+
"};\n");
7557+
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier.\n", errout.str());
7558+
7559+
checkOverride("struct A {\n"
7560+
" virtual void f(char, int);\n"
7561+
"};\n"
7562+
"struct D : A {\n"
7563+
" void f(char, int);\n"
7564+
"};\n");
7565+
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier.\n", errout.str());
7566+
7567+
checkOverride("struct A {\n"
7568+
" virtual void f(char, int);\n"
7569+
"};\n"
7570+
"struct D : A {\n"
7571+
" void f(char, double);\n"
7572+
"};\n");
7573+
ASSERT_EQUALS("", errout.str());
7574+
7575+
checkOverride("struct A {\n"
7576+
" virtual void f(char, int);\n"
7577+
"};\n"
7578+
"struct D : A {\n"
7579+
" void f(char c = '\\0', double);\n"
7580+
"};\n");
7581+
ASSERT_EQUALS("", errout.str());
7582+
7583+
checkOverride("struct A {\n"
7584+
" virtual void f(char, int);\n"
7585+
"};\n"
7586+
"struct D : A {\n"
7587+
" void f(char c = '\\0', int);\n"
7588+
"};\n");
7589+
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier.\n", errout.str());
7590+
7591+
checkOverride("struct A {\n"
7592+
" virtual void f(char c, std::vector<int>);\n"
7593+
"};\n"
7594+
"struct D : A {\n"
7595+
" void f(char c, std::vector<double>);\n"
7596+
"};\n");
7597+
ASSERT_EQUALS("", errout.str());
7598+
7599+
checkOverride("struct A {\n"
7600+
" virtual void f(char c, std::vector<int>);\n"
7601+
"};\n"
7602+
"struct D : A {\n"
7603+
" void f(char c, std::set<int>);\n"
7604+
"};\n");
7605+
ASSERT_EQUALS("", errout.str());
7606+
7607+
checkOverride("struct A {\n"
7608+
" virtual void f(char c, std::vector<int> v);\n"
7609+
"};\n"
7610+
"struct D : A {\n"
7611+
" void f(char c, std::vector<int> w = {});\n"
7612+
"};\n");
7613+
TODO_ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier.\n", "", errout.str());
75427614
}
75437615

75447616
void overrideCVRefQualifiers() {

0 commit comments

Comments
 (0)