1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Removed an invalid exemption for abstract classes.

This commit is contained in:
Sergey Prigogin 2011-07-17 19:02:26 -07:00
parent 1feac1a80a
commit 822ae5e4a9
2 changed files with 7 additions and 23 deletions

View file

@ -8,6 +8,7 @@
* Contributors: * Contributors:
* Alena Laskavaia - initial API and implementation * Alena Laskavaia - initial API and implementation
* Patrick Hofer [bug 315528] * Patrick Hofer [bug 315528]
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.codan.internal.checkers; package org.eclipse.cdt.codan.internal.checkers;
@ -83,11 +84,7 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
} }
ICPPMethod virtualMethod = null; ICPPMethod virtualMethod = null;
for (ICPPMethod method : classType.getAllDeclaredMethods()) { for (ICPPMethod method : classType.getAllDeclaredMethods()) {
if (method.isPureVirtual()) { if (!method.isDestructor() && method.isVirtual()) {
// Class has at least one pure virtual method, it is abstract
// and cannot be instantiated.
return PROCESS_SKIP;
} else if (method.isVirtual() && !method.isDestructor()) {
virtualMethod = method; virtualMethod = method;
} }
} }

View file

@ -7,6 +7,8 @@
* *
* Contributors: * Contributors:
* Patrick Hofer - Initial API and implementation * Patrick Hofer - Initial API and implementation
* Tomasz Wesolowski
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.codan.core.internal.checkers; package org.eclipse.cdt.codan.core.internal.checkers;
@ -143,9 +145,7 @@ public class NonVirtualDestructorCheckerTest extends CheckerTestCase {
checkErrorLines(3, 7, 11, 13); checkErrorLines(3, 7, 11, 13);
} }
// class A { // OK. Do _not_ warn here. // class A {
// // A is an abstract class because it has one pure virtual method.
// // A cannot be instantiated.
// virtual void f1() { }; // virtual void f1() { };
// virtual void f2() = 0; // virtual void f2() = 0;
// }; // };
@ -157,7 +157,8 @@ public class NonVirtualDestructorCheckerTest extends CheckerTestCase {
// }; // };
public void testAbstractBaseClass() { public void testAbstractBaseClass() {
loadCodeAndRun(getAboveComment()); loadCodeAndRun(getAboveComment());
checkNoErrors(); // It doesn't matter if the class is abstract or not - dtor can be called polymorphically.
checkErrorLines(1);
} }
// struct Base { // struct Base {
@ -180,18 +181,4 @@ public class NonVirtualDestructorCheckerTest extends CheckerTestCase {
loadCodeAndRun(getAboveComment()); loadCodeAndRun(getAboveComment());
checkErrorLines(4); 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();
}
} }