mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
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>
This commit is contained in:
parent
bf0b7a76ed
commit
db0cc1f9a4
2 changed files with 15 additions and 4 deletions
|
@ -99,7 +99,7 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
|
||||||
boolean hasVirtualDestructor = hasVirtualDestructor(classType);
|
boolean hasVirtualDestructor = hasVirtualDestructor(classType);
|
||||||
checkedClassTypes.clear();
|
checkedClassTypes.clear();
|
||||||
if (hasVirtualDestructor) {
|
if (hasVirtualDestructor) {
|
||||||
return PROCESS_SKIP;
|
return PROCESS_CONTINUE;
|
||||||
}
|
}
|
||||||
ICPPMethod virtualMethod = null;
|
ICPPMethod virtualMethod = null;
|
||||||
for (ICPPMethod method : ClassTypeHelper.getAllDeclaredMethods(classType)) {
|
for (ICPPMethod method : ClassTypeHelper.getAllDeclaredMethods(classType)) {
|
||||||
|
@ -108,13 +108,13 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (virtualMethod == null) {
|
if (virtualMethod == null) {
|
||||||
return PROCESS_SKIP;
|
return PROCESS_CONTINUE;
|
||||||
}
|
}
|
||||||
ICPPMethod destructor = getDestructor(classType);
|
ICPPMethod destructor = getDestructor(classType);
|
||||||
if (destructor != null && destructor.getVisibility() != ICPPASTVisibilityLabel.v_public
|
if (destructor != null && destructor.getVisibility() != ICPPASTVisibilityLabel.v_public
|
||||||
&& classType.getFriends().length == 0) {
|
&& classType.getFriends().length == 0) {
|
||||||
// No error if the destructor is protected or private and there are no friends.
|
// No error if the destructor is protected or private and there are no friends.
|
||||||
return PROCESS_SKIP;
|
return PROCESS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
IASTNode node = decl;
|
IASTNode node = decl;
|
||||||
|
@ -125,7 +125,6 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reportProblem(PROBLEM_ID, node, new String(className.getSimpleID()), virtualMethod.getName());
|
reportProblem(PROBLEM_ID, node, new String(className.getSimpleID()), virtualMethod.getName());
|
||||||
return PROCESS_SKIP;
|
|
||||||
} finally {
|
} finally {
|
||||||
CPPSemantics.popLookupPoint();
|
CPPSemantics.popLookupPoint();
|
||||||
}
|
}
|
||||||
|
|
|
@ -221,4 +221,16 @@ public class NonVirtualDestructorCheckerTest extends CheckerTestCase {
|
||||||
assertTrue((start == -1 && end == -1) || // ok, not multi-line
|
assertTrue((start == -1 && end == -1) || // ok, not multi-line
|
||||||
!code.substring(start, end).contains("\n"));
|
!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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue