From 258581ce2ef41bc32075331304d1f347c8cdc1e0 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 13 Jul 2023 12:18:29 +0200 Subject: [PATCH] Fix FP uselessOverride with macro (#5238) --- lib/checkclass.cpp | 2 ++ test/testclass.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index c5981cb53..abf831924 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -3151,6 +3151,8 @@ static bool compareTokenRanges(const Token* start1, const Token* end1, const Tok break; if (tok1->str() == "this") break; + if (tok1->isExpandedMacro() || tok2->isExpandedMacro()) + break; if (tok1 == end1 && tok2 == end2) { isEqual = true; break; diff --git a/test/testclass.cpp b/test/testclass.cpp index add011fe4..53371d545 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -8565,6 +8565,13 @@ private: " int f() const override { return g(); }\n" "};\n"); ASSERT_EQUALS("", errout.str()); + + checkUselessOverride("#define MACRO 1\n" + "struct B { virtual int f() { return 1; } };\n" + "struct D : B {\n" + " int f() override { return MACRO; }\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); } #define checkUnsafeClassRefMember(code) checkUnsafeClassRefMember_(code, __FILE__, __LINE__)