Commit c1bb68fe authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

isVirtualFunction: Fix false positive for constructor

When class has a virtual destructor

Change-Id: Ifcc9a05ee1eb1144ed7e035b9f077846fcb96cf3
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 1fd14c4c
......@@ -227,9 +227,12 @@ static bool isVirtualFunction_helper(const Function *function,
LookupContext context(document, snapshot);
QList<LookupItem> results = context.lookup(function->name(), function->enclosingScope());
if (!results.isEmpty()) {
const bool isDestructor = function->name()->isDestructorNameId();
foreach (const LookupItem &item, results) {
if (Symbol *symbol = item.declaration()) {
if (Function *functionType = symbol->type()->asFunctionType()) {
if (functionType->name()->isDestructorNameId() != isDestructor)
continue;
if (functionType == function) // already tested
continue;
if (functionType->isFinal())
......@@ -409,6 +412,10 @@ void CppEditorPlugin::test_functionhelper_virtualFunctions_data()
"struct Derived : Base { virtual void foo() final {} };\n"
"struct Derived2 : Derived { void foo() {} };")
<< (VirtualityList() << Virtual << Virtual << NotVirtual);
QTest::newRow("ctor-virtual-dtor")
<< _("struct Base { Base() {} virtual ~Base() {} };\n")
<< (VirtualityList() << NotVirtual << Virtual);
}
} // namespace Internal
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment