Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Stornelli2019-04-27 11:55:37 -0400
committerMarco Stornelli2019-05-12 03:59:22 -0400
commit695de049db539bb34b4c4e0a3a394e7d9757db8c (patch)
tree06ebfaa45d709cd768e3c6002a678f3019ad16f0
parent125721a48525f77fb229ce04bedcf954990fde83 (diff)
downloadorg.eclipse.cdt-695de049db539bb34b4c4e0a3a394e7d9757db8c.tar.gz
org.eclipse.cdt-695de049db539bb34b4c4e0a3a394e7d9757db8c.tar.xz
org.eclipse.cdt-695de049db539bb34b4c4e0a3a394e7d9757db8c.zip
Bug 458850 - Fix false positive for deferred classes
Change-Id: I46335a94d69ae8d4e5ae1c68857344d1dc513328 Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/plugin.xml2
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructorChecker.java (renamed from codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java)11
-rw-r--r--codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java23
3 files changed, 29 insertions, 7 deletions
diff --git a/codan/org.eclipse.cdt.codan.checkers/plugin.xml b/codan/org.eclipse.cdt.codan.checkers/plugin.xml
index dc150898d6..d1d46d6eef 100644
--- a/codan/org.eclipse.cdt.codan.checkers/plugin.xml
+++ b/codan/org.eclipse.cdt.codan.checkers/plugin.xml
@@ -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
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/NonVirtualDestructorChecker.java
index 1425e730c4..bb9df540d7 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/NonVirtualDestructorChecker.java
@@ -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;
}
diff --git a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java
index 7012c38c50..d4001cce2b 100644
--- a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java
+++ b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java
@@ -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();
}
}

Back to the top