From ffd9f9a93f6c6da103a2b4e8bc556e77a587377e Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 11 Mar 2022 21:44:13 +0100 Subject: [PATCH] Fix FP missingOverride with unnamed parameters (#3887) --- lib/symboldatabase.cpp | 9 ++++++ test/testclass.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index c328bad2b..479069e64 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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; diff --git a/test/testclass.cpp b/test/testclass.cpp index 5adff2c96..64d13ec3f 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -7539,6 +7539,78 @@ private: " };\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);\n" + "};\n" + "struct D : A {\n" + " void f(char c, std::vector);\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + + checkOverride("struct A {\n" + " virtual void f(char c, std::vector);\n" + "};\n" + "struct D : A {\n" + " void f(char c, std::set);\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + + checkOverride("struct A {\n" + " virtual void f(char c, std::vector v);\n" + "};\n" + "struct D : A {\n" + " void f(char c, std::vector 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() {