Fix FP missingOverride with unnamed parameters (#3887)
This commit is contained in:
parent
e208fc67c1
commit
ffd9f9a93f
|
@ -2610,6 +2610,15 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se
|
||||||
} else if (second->next()->str() == "[" && first->next()->str() != "[")
|
} else if (second->next()->str() == "[" && first->next()->str() != "[")
|
||||||
first = first->next();
|
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
|
// argument list has different number of arguments
|
||||||
else if (openParen == 1 && second->str() == ")" && first->str() != ")")
|
else if (openParen == 1 && second->str() == ")" && first->str() != ")")
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -7539,6 +7539,78 @@ private:
|
||||||
" };\n"
|
" };\n"
|
||||||
"}\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());
|
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() {
|
void overrideCVRefQualifiers() {
|
||||||
|
|
Loading…
Reference in New Issue