Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2610,6 +2610,15 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se
} else if (second->next()->str() == "[" && first->next()->str() != "[")
first = first->next();

// unnamed parameters
else if (Token::Match(first, "(|, %type% ,|)") && Token::Match(second, "(|, %type% ,|)")) {
if (first->next()->expressionString() != second->next()->expressionString())
break;
first = first->next();
second = second->next();
continue;
}

// argument list has different number of arguments
else if (openParen == 1 && second->str() == ")" && first->str() != ")")
break;
Expand Down
72 changes: 72 additions & 0 deletions test/testclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7539,6 +7539,78 @@ class TestClass : public TestFixture {
" };\n"
"}\n");
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());

checkOverride("struct A {\n"
" virtual void f(int);\n"
"};\n"
"struct D : A {\n"
" void f(double);\n"
"};\n");
ASSERT_EQUALS("", errout.str());

checkOverride("struct A {\n"
" virtual void f(int);\n"
"};\n"
"struct D : A {\n"
" void f(int);\n"
"};\n");
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());

checkOverride("struct A {\n"
" virtual void f(char, int);\n"
"};\n"
"struct D : A {\n"
" void f(char, int);\n"
"};\n");
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());

checkOverride("struct A {\n"
" virtual void f(char, int);\n"
"};\n"
"struct D : A {\n"
" void f(char, double);\n"
"};\n");
ASSERT_EQUALS("", errout.str());

checkOverride("struct A {\n"
" virtual void f(char, int);\n"
"};\n"
"struct D : A {\n"
" void f(char c = '\\0', double);\n"
"};\n");
ASSERT_EQUALS("", errout.str());

checkOverride("struct A {\n"
" virtual void f(char, int);\n"
"};\n"
"struct D : A {\n"
" void f(char c = '\\0', int);\n"
"};\n");
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());

checkOverride("struct A {\n"
" virtual void f(char c, std::vector<int>);\n"
"};\n"
"struct D : A {\n"
" void f(char c, std::vector<double>);\n"
"};\n");
ASSERT_EQUALS("", errout.str());

checkOverride("struct A {\n"
" virtual void f(char c, std::vector<int>);\n"
"};\n"
"struct D : A {\n"
" void f(char c, std::set<int>);\n"
"};\n");
ASSERT_EQUALS("", errout.str());

checkOverride("struct A {\n"
" virtual void f(char c, std::vector<int> v);\n"
"};\n"
"struct D : A {\n"
" void f(char c, std::vector<int> w = {});\n"
"};\n");
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());
}

void overrideCVRefQualifiers() {
Expand Down