diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/AbstractClassInstantiationCheckerTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/AbstractClassInstantiationCheckerTest.java index a5f9fef290b..d9fda5899cd 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/AbstractClassInstantiationCheckerTest.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/AbstractClassInstantiationCheckerTest.java @@ -228,4 +228,20 @@ public class AbstractClassInstantiationCheckerTest extends CheckerTestCase { loadCodeAndRun(getAboveComment()); checkErrorLines(4); } + + // class A { + // public: + // virtual ~A() = 0; + // }; + // + // class B : public A { + // public: + // virtual ~B() {} + // }; + // + // B b; + public void testPureVirtualDestructorOverride() { + loadCodeAndRun(getAboveComment()); + checkNoErrors(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java index 37968bb0638..49a790d715b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java @@ -822,6 +822,15 @@ public class ClassTypeHelper { return resultArray; } + private static String getMethodNameForOverrideKey(ICPPMethod method) { + if (method.isDestructor()) { + // Destructor's names may differ but they will override each other. + return "~"; //$NON-NLS-1$ + } else { + return method.getName(); + } + } + /** * Returns pure virtual methods of the given class grouped by their names. * @@ -849,7 +858,7 @@ public class ClassTypeHelper { } // Remove overridden methods (even if they are pure virtual) for (ICPPMethod declaredMethod : classTarget.getDeclaredMethods()) { - Set methodsSet = pureVirtualMethods.get(declaredMethod.getName()); + Set methodsSet = pureVirtualMethods.get(getMethodNameForOverrideKey(declaredMethod)); if (methodsSet != null) { for (Iterator methodIt = methodsSet.iterator(); methodIt.hasNext();) { ICPPMethod method = methodIt.next(); @@ -858,17 +867,17 @@ public class ClassTypeHelper { } } if (methodsSet.isEmpty()) { - pureVirtualMethods.remove(declaredMethod.getName()); + pureVirtualMethods.remove(getMethodNameForOverrideKey(declaredMethod)); } } } // Add pure virtual methods of current class for (ICPPMethod method : classTarget.getDeclaredMethods()) { if (method.isPureVirtual()) { - Set methodsSet = pureVirtualMethods.get(method.getName()); + Set methodsSet = pureVirtualMethods.get(getMethodNameForOverrideKey(method)); if (methodsSet == null) { methodsSet = new HashSet(); - pureVirtualMethods.put(method.getName(), methodsSet); + pureVirtualMethods.put(getMethodNameForOverrideKey(method), methodsSet); } methodsSet.add(method); }