Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Stornelli2019-05-12 06:20:34 -0400
committerMarco Stornelli2019-05-18 02:13:30 -0400
commit6452688c183614a4bc1f4163a253f08d2dc507d9 (patch)
tree1c9a29a9412fdb7aa2d1575348ea671b604441a6
parentec6f9d204dc2ba6359276467cc82bfba480e07f8 (diff)
downloadorg.eclipse.cdt-6452688c183614a4bc1f4163a253f08d2dc507d9.tar.gz
org.eclipse.cdt-6452688c183614a4bc1f4163a253f08d2dc507d9.tar.xz
org.eclipse.cdt-6452688c183614a4bc1f4163a253f08d2dc507d9.zip
Bug 468742 - Fix false positive no-virtual destructor
Change-Id: Id8d2efaf3f7a5ca74d160e4a726c08a71c6d7067 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/NonVirtualDestructorChecker.java9
-rw-r--r--codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java30
2 files changed, 39 insertions, 0 deletions
diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructorChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructorChecker.java
index bb9df540d7..9895b75b2e 100644
--- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructorChecker.java
+++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructorChecker.java
@@ -30,10 +30,12 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel;
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.core.dom.ast.cpp.ICPPTemplateTypeParameter;
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;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
/**
* Checker to find that class has virtual method and non virtual destructor
@@ -73,6 +75,10 @@ public class NonVirtualDestructorChecker extends AbstractIndexAstChecker {
if (destructor != null && destructor.isVirtual()) {
return true;
}
+ //We can't say anything in this case, so return true to avoid false positive
+ if (destructor == null && CPPTemplates.isDependentType(classType)) {
+ return true;
+ }
ICPPBase[] bases = classType.getBases();
for (ICPPBase base : bases) {
IBinding baseClass = base.getBaseClass();
@@ -81,6 +87,9 @@ public class NonVirtualDestructorChecker extends AbstractIndexAstChecker {
if (!checkedClassTypes.contains(cppClassType) && hasVirtualDestructor(cppClassType)) {
return true;
}
+ } else if (baseClass instanceof ICPPTemplateTypeParameter) {
+ //We can't say anything in this case, so return true to avoid false positive
+ return true;
}
}
return false;
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 d4001cce2b..c24bf9f704 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
@@ -248,4 +248,34 @@ public class NonVirtualDestructorCheckerTest extends CheckerTestCase {
loadCodeAndRun(getAboveComment());
checkNoErrors();
}
+
+ //template<typename T>
+ //class Base;
+ //template <typename T>
+ //class A {
+ // using type = Base<T>;
+ //};
+ //template<typename T>
+ //class B: public A<T>::type {
+ // virtual void f() {}
+ //};
+ public void testDeferredClasses1_Bug468742() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkNoErrors();
+ }
+
+ //struct Root {
+ //};
+ //template<typename T>
+ //class A: public T {
+ //public:
+ // virtual int f() const = 0;
+ //};
+ //typedef A<Root> B;
+ //class C: public A<Root> {
+ //};
+ public void testDeferredClasses2_Bug468742() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(9);
+ }
}

Back to the top