From 8310198cd572df0590eff2bce1926d0ace84bb86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 24 Apr 2018 13:53:58 +0200 Subject: [PATCH] SymbolDatabase: Refactoring and testing isImplicitlyVirtual --- lib/symboldatabase.cpp | 19 +++++++++---------- test/testsymboldatabase.cpp | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 21a70d8aa..831b0d9b2 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3196,17 +3196,16 @@ bool Function::isImplicitlyVirtual(bool defaultVal) const { if (isVirtual()) return true; - else if (access == Private || access == Public || access == Protected) { - bool safe = true; - bool hasVirt = isImplicitlyVirtual_rec(nestedIn->definedType, safe); - if (hasVirt) - return true; - else if (safe) - return false; - else - return defaultVal; - } else + if (!nestedIn->isClassOrStruct()) return false; + bool safe = true; + bool hasVirt = isImplicitlyVirtual_rec(nestedIn->definedType, safe); + if (hasVirt) + return true; + else if (safe) + return false; + else + return defaultVal; } bool Function::isImplicitlyVirtual_rec(const ::Type* baseType, bool& safe) const diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index c05d43e88..d0ca27de1 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -212,6 +212,8 @@ private: TEST_CASE(functionArgs12); // #7661 TEST_CASE(functionArgs13); // #7697 + TEST_CASE(functionImplicitlyVirtual); + TEST_CASE(namespaces1); TEST_CASE(namespaces2); TEST_CASE(namespaces3); // #3854 - unknown macro @@ -2065,6 +2067,18 @@ private: } } + void functionImplicitlyVirtual() { + GET_SYMBOL_DB("class base { virtual void f(); };\n" + "class derived : base { void f(); };\n" + "void derived::f() {}"); + ASSERT(db != nullptr); + if (!db) + return; + ASSERT_EQUALS(4, db->scopeList.size()); + const Function *function = db->scopeList.back().function; + ASSERT_EQUALS(true, function && function->isImplicitlyVirtual(false)); + } + void namespaces1() { GET_SYMBOL_DB("namespace fred {\n" " namespace barney {\n"