mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 22:22:11 +02:00
Bug 458850 - Fix false positive for deferred classes
Change-Id: I46335a94d69ae8d4e5ae1c68857344d1dc513328 Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
This commit is contained in:
parent
125721a485
commit
695de049db
3 changed files with 29 additions and 7 deletions
|
@ -33,7 +33,7 @@
|
|||
</checker>
|
||||
|
||||
<checker
|
||||
class="org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructor"
|
||||
class="org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorChecker"
|
||||
id="org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructor"
|
||||
name="%checker.name.NonVirtualDestructor">
|
||||
<problem
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
|
||||
|
||||
|
@ -39,7 +40,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
|
|||
*
|
||||
* @author Alena Laskavaia
|
||||
*/
|
||||
public class NonVirtualDestructor extends AbstractIndexAstChecker {
|
||||
@SuppressWarnings("restriction")
|
||||
public class NonVirtualDestructorChecker extends AbstractIndexAstChecker {
|
||||
public static final String PROBLEM_ID = "org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem"; //$NON-NLS-1$
|
||||
|
||||
// Prevent stack overflow in case: class A: public A {};
|
||||
|
@ -52,7 +54,12 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
|
|||
}
|
||||
|
||||
private static ICPPMethod getDestructor(ICPPClassType classType) {
|
||||
for (ICPPMethod method : classType.getDeclaredMethods()) {
|
||||
ICPPMethod[] methods = null;
|
||||
if (classType instanceof ICPPDeferredClassInstance)
|
||||
methods = ((ICPPDeferredClassInstance) classType).getClassTemplate().getDeclaredMethods();
|
||||
else
|
||||
methods = classType.getDeclaredMethods();
|
||||
for (ICPPMethod method : methods) {
|
||||
if (method.isDestructor()) {
|
||||
return method;
|
||||
}
|
|
@ -16,11 +16,11 @@
|
|||
package org.eclipse.cdt.codan.core.internal.checkers;
|
||||
|
||||
import org.eclipse.cdt.codan.core.tests.CheckerTestCase;
|
||||
import org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructor;
|
||||
import org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorChecker;
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
|
||||
/**
|
||||
* Test for {@link NonVirtualDestructor} class.
|
||||
* Test for {@link NonVirtualDestructorChecker} class.
|
||||
*/
|
||||
public class NonVirtualDestructorCheckerTest extends CheckerTestCase {
|
||||
@Override
|
||||
|
@ -31,7 +31,7 @@ public class NonVirtualDestructorCheckerTest extends CheckerTestCase {
|
|||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
enableProblems(NonVirtualDestructor.PROBLEM_ID);
|
||||
enableProblems(NonVirtualDestructorChecker.PROBLEM_ID);
|
||||
}
|
||||
|
||||
// struct A {
|
||||
|
@ -231,6 +231,21 @@ public class NonVirtualDestructorCheckerTest extends CheckerTestCase {
|
|||
//}
|
||||
public void testNestedClasses_Bug468749() throws Exception {
|
||||
loadCodeAndRun(getAboveComment());
|
||||
checkErrorLine(3, NonVirtualDestructor.PROBLEM_ID);
|
||||
checkErrorLine(3, NonVirtualDestructorChecker.PROBLEM_ID);
|
||||
}
|
||||
|
||||
//template <typename T>
|
||||
//class A {
|
||||
// virtual void f() {}
|
||||
//public:
|
||||
// virtual ~A() {}
|
||||
//};
|
||||
//template <typename T>
|
||||
//class B : public A<T> {
|
||||
// virtual void f() {}
|
||||
//};
|
||||
public void testDeferredClasses_Bug458850() throws Exception {
|
||||
loadCodeAndRun(getAboveComment());
|
||||
checkNoErrors();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue