From 81bcbfa7fef156ad0c3928c287f26fd3bbd97289 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 28 Mar 2022 22:44:04 +0200 Subject: [PATCH] Fix #10920 FP missingOverride with friend (#3955) --- lib/symboldatabase.cpp | 3 ++- test/testclass.cpp | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 84299abde..ef0737d38 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1754,7 +1754,8 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const if (Token::Match(tok1, "%name%")) { if (tok1->str() == "return") return false; - tok1 = tok1->previous(); + if (tok1->str() != "friend") + tok1 = tok1->previous(); } // skip over qualification diff --git a/test/testclass.cpp b/test/testclass.cpp index b1b63f790..3c9adee8a 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -7678,6 +7678,15 @@ private: " 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()); + + checkOverride("struct T {};\n" // #10920 + "struct B {\n" + " virtual T f() = 0;\n" + "};\n" + "struct D : B {\n" + " friend T f();\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); } void overrideCVRefQualifiers() {