diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java index f4e365cd037..24fb21b8a42 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java @@ -8,6 +8,7 @@ * Contributors: * Alena Laskavaia - initial API and implementation * Patrick Hofer [bug 315528] + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.codan.internal.checkers; @@ -83,11 +84,7 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker { } ICPPMethod virtualMethod = null; for (ICPPMethod method : classType.getAllDeclaredMethods()) { - if (method.isPureVirtual()) { - // Class has at least one pure virtual method, it is abstract - // and cannot be instantiated. - return PROCESS_SKIP; - } else if (method.isVirtual() && !method.isDestructor()) { + if (!method.isDestructor() && method.isVirtual()) { virtualMethod = method; } } diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java index 4a587027b88..2e5c88d8993 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java @@ -7,6 +7,8 @@ * * Contributors: * Patrick Hofer - Initial API and implementation + * Tomasz Wesolowski + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.codan.core.internal.checkers; @@ -143,9 +145,7 @@ public class NonVirtualDestructorCheckerTest extends CheckerTestCase { checkErrorLines(3, 7, 11, 13); } - // class A { // OK. Do _not_ warn here. - // // A is an abstract class because it has one pure virtual method. - // // A cannot be instantiated. + // class A { // virtual void f1() { }; // virtual void f2() = 0; // }; @@ -157,7 +157,8 @@ public class NonVirtualDestructorCheckerTest extends CheckerTestCase { // }; public void testAbstractBaseClass() { loadCodeAndRun(getAboveComment()); - checkNoErrors(); + // It doesn't matter if the class is abstract or not - dtor can be called polymorphically. + checkErrorLines(1); } // struct Base { @@ -180,18 +181,4 @@ public class NonVirtualDestructorCheckerTest extends CheckerTestCase { loadCodeAndRun(getAboveComment()); checkErrorLines(4); } - - // struct IBase { - // virtual void foo() = 0; - // }; - // struct IDerived : IBase { - // }; - // struct ADerived : IDerived { - // void foo(); - // virtual void bar() = 0; - // }; - public void testInheritedAbstractClasses() { - loadCodeAndRun(getAboveComment()); - checkNoErrors(); - } }