mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
Bug 326269 - Checker for instantiation of an abstract class. Patch by Anton Gorenkov.
This commit is contained in:
parent
af28c6569c
commit
2ba3a82120
2 changed files with 29 additions and 4 deletions
|
@ -228,4 +228,20 @@ public class AbstractClassInstantiationCheckerTest extends CheckerTestCase {
|
||||||
loadCodeAndRun(getAboveComment());
|
loadCodeAndRun(getAboveComment());
|
||||||
checkErrorLines(4);
|
checkErrorLines(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// class A {
|
||||||
|
// public:
|
||||||
|
// virtual ~A() = 0;
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// class B : public A {
|
||||||
|
// public:
|
||||||
|
// virtual ~B() {}
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// B b;
|
||||||
|
public void testPureVirtualDestructorOverride() {
|
||||||
|
loadCodeAndRun(getAboveComment());
|
||||||
|
checkNoErrors();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -822,6 +822,15 @@ public class ClassTypeHelper {
|
||||||
return resultArray;
|
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.
|
* 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)
|
// Remove overridden methods (even if they are pure virtual)
|
||||||
for (ICPPMethod declaredMethod : classTarget.getDeclaredMethods()) {
|
for (ICPPMethod declaredMethod : classTarget.getDeclaredMethods()) {
|
||||||
Set<ICPPMethod> methodsSet = pureVirtualMethods.get(declaredMethod.getName());
|
Set<ICPPMethod> methodsSet = pureVirtualMethods.get(getMethodNameForOverrideKey(declaredMethod));
|
||||||
if (methodsSet != null) {
|
if (methodsSet != null) {
|
||||||
for (Iterator<ICPPMethod> methodIt = methodsSet.iterator(); methodIt.hasNext();) {
|
for (Iterator<ICPPMethod> methodIt = methodsSet.iterator(); methodIt.hasNext();) {
|
||||||
ICPPMethod method = methodIt.next();
|
ICPPMethod method = methodIt.next();
|
||||||
|
@ -858,17 +867,17 @@ public class ClassTypeHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (methodsSet.isEmpty()) {
|
if (methodsSet.isEmpty()) {
|
||||||
pureVirtualMethods.remove(declaredMethod.getName());
|
pureVirtualMethods.remove(getMethodNameForOverrideKey(declaredMethod));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Add pure virtual methods of current class
|
// Add pure virtual methods of current class
|
||||||
for (ICPPMethod method : classTarget.getDeclaredMethods()) {
|
for (ICPPMethod method : classTarget.getDeclaredMethods()) {
|
||||||
if (method.isPureVirtual()) {
|
if (method.isPureVirtual()) {
|
||||||
Set<ICPPMethod> methodsSet = pureVirtualMethods.get(method.getName());
|
Set<ICPPMethod> methodsSet = pureVirtualMethods.get(getMethodNameForOverrideKey(method));
|
||||||
if (methodsSet == null) {
|
if (methodsSet == null) {
|
||||||
methodsSet = new HashSet<ICPPMethod>();
|
methodsSet = new HashSet<ICPPMethod>();
|
||||||
pureVirtualMethods.put(method.getName(), methodsSet);
|
pureVirtualMethods.put(getMethodNameForOverrideKey(method), methodsSet);
|
||||||
}
|
}
|
||||||
methodsSet.add(method);
|
methodsSet.add(method);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue