From 741fb0936e5c6db74f3808cad580bc447226d4c0 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 6 Dec 2024 20:09:35 +0100 Subject: [PATCH] Fix #13382 FP functionStatic with forward-declared base class (#7078) --- lib/checkclass.cpp | 2 +- test/testclass.cpp | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index d8556108bcd..78a7d029560 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2282,7 +2282,7 @@ bool CheckClass::isMemberVar(const Scope *scope, const Token *tok) const for (const Type::BaseInfo & i : scope->definedType->derivedFrom) { // find the base class const Type *derivedFrom = i.type; - if (!derivedFrom) + if (!derivedFrom || !derivedFrom->classScope) foundAllBaseClasses = false; // find the function in the base class diff --git a/test/testclass.cpp b/test/testclass.cpp index d0b0cb4172f..93d900e1e27 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -6715,13 +6715,22 @@ class TestClass : public TestFixture { ASSERT_EQUALS("", errout_str()); } - void const96() { // #13282 - checkConst("struct S : B {\n" + void const96() { + checkConst("struct S : B {\n" // #13282 " bool f() { return b; }\n" " bool g() override { return b; }\n" " bool b;\n" "};\n"); ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Either there is a missing 'override', or the member function 'S::f' can be const.\n", errout_str()); + + checkConst("struct B;\n" // #13382 + "struct S : B {\n" + " void f();\n" + "};\n" + "void S::f() {\n" + " B::g(0);\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void const97() { // #13301