Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Stornelli2019-04-27 11:49:46 -0400
committerMarco Stornelli2019-05-08 02:23:47 -0400
commitdb0cc1f9a46f32a821347b49edccc7e560da8ee5 (patch)
treeebc4fe7b564d561e5c26b394dc5f5972cdf9dfe0
parentbf0b7a76edd9cf4f3ea7b4a4adaff277fe03295a (diff)
downloadorg.eclipse.cdt-db0cc1f9a46f32a821347b49edccc7e560da8ee5.tar.gz
org.eclipse.cdt-db0cc1f9a46f32a821347b49edccc7e560da8ee5.tar.xz
org.eclipse.cdt-db0cc1f9a46f32a821347b49edccc7e560da8ee5.zip
Bug 468749 - Fix false negative no virtual destructor
The checkers simply skipped nested classes. Change-Id: If464b229e586267d845768f9d96d3223328a8298 Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java7
-rw-r--r--codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java12
2 files changed, 15 insertions, 4 deletions
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 68f44b1513..1425e730c4 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
@@ -99,7 +99,7 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
boolean hasVirtualDestructor = hasVirtualDestructor(classType);
checkedClassTypes.clear();
if (hasVirtualDestructor) {
- return PROCESS_SKIP;
+ return PROCESS_CONTINUE;
}
ICPPMethod virtualMethod = null;
for (ICPPMethod method : ClassTypeHelper.getAllDeclaredMethods(classType)) {
@@ -108,13 +108,13 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
}
}
if (virtualMethod == null) {
- return PROCESS_SKIP;
+ return PROCESS_CONTINUE;
}
ICPPMethod destructor = getDestructor(classType);
if (destructor != null && destructor.getVisibility() != ICPPASTVisibilityLabel.v_public
&& classType.getFriends().length == 0) {
// No error if the destructor is protected or private and there are no friends.
- return PROCESS_SKIP;
+ return PROCESS_CONTINUE;
}
IASTNode node = decl;
@@ -125,7 +125,6 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
}
}
reportProblem(PROBLEM_ID, node, new String(className.getSimpleID()), virtualMethod.getName());
- return PROCESS_SKIP;
} finally {
CPPSemantics.popLookupPoint();
}
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 7f11b65bbc..7012c38c50 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
@@ -221,4 +221,16 @@ public class NonVirtualDestructorCheckerTest extends CheckerTestCase {
assertTrue((start == -1 && end == -1) || // ok, not multi-line
!code.substring(start, end).contains("\n"));
}
+
+ //class A {
+ //public:
+ // class B {
+ // public:
+ // virtual void test();
+ // };
+ //}
+ public void testNestedClasses_Bug468749() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(3, NonVirtualDestructor.PROBLEM_ID);
+ }
}

Back to the top