1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-17 05:55:22 +02:00

Bug 315528 - Non-virtual destructor diagnostics doesn't take superclass into account. Tests by Patrick Hofer.

This commit is contained in:
Sergey Prigogin 2011-05-23 23:55:41 +00:00
parent 8fc40a2884
commit c3b5435595
3 changed files with 131 additions and 1 deletions

View file

@ -33,7 +33,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
* @author Alena Laskavaia
*/
public class NonVirtualDestructor extends AbstractIndexAstChecker {
private static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem"; //$NON-NLS-1$
public static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem"; //$NON-NLS-1$
public void processAst(IASTTranslationUnit ast) {
// Traverse the ast using the visitor pattern.

View file

@ -0,0 +1,128 @@
/*******************************************************************************
* Copyright (c) 2011 Patrick Hofer and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Patrick Hofer - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.codan.core.internal.checkers;
import org.eclipse.cdt.codan.core.test.CheckerTestCase;
import org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructor;
/**
* Test for {@see NonVirtualDestructor} class.
*/
public class NonVirtualDestructorCheckerTest extends CheckerTestCase {
@Override
public boolean isCpp() {
return true;
}
@Override
public void setUp() throws Exception {
super.setUp();
enableProblems(NonVirtualDestructor.ER_ID);
}
// struct A {
// virtual void f() = 0;
// virtual ~A(); // ok.
// };
public void testVirtualDtorInClass() {
loadCodeAndRun(getAboveComment());
checkNoErrors();
}
// struct A {
// virtual void f() = 0;
// protected:
// ~A(); // ok.
// };
public void testNonPublicVirtualDtorInClass() {
loadCodeAndRun(getAboveComment());
checkNoErrors();
}
// struct A {
// virtual void f() = 0;
// ~A(); // warn! public non-virtual dtor.
// };
public void _testPublicVirtualDtorInClass() {
loadCodeAndRun(getAboveComment());
checkErrorLines(3);
}
// struct A {
// virtual void f() = 0;
// // warn! implicit public non-virtual dtor.
// };
public void _testImplicitPublicNonVirtualDtorInClass() {
loadCodeAndRun(getAboveComment());
checkErrorLines(1);
}
// struct F { };
//
// struct A {
// virtual void f() = 0;
// private:
// friend class F;
// ~A(); // warn! can be called from class F.
// };
public void _testPublicNonVirtualDtorCanBeCalledFromFriendClass() {
loadCodeAndRun(getAboveComment());
checkErrorLines(7);
}
// struct A {
// virtual void f() = 0;
// virtual ~A();
// };
//
// struct B {
// ~B(); // ok.
// };
public void testVirtualDtorInBaseClass() {
loadCodeAndRun(getAboveComment());
checkNoErrors();
}
// struct A {
// virtual void f() = 0;
// virtual ~A(); // ok.
// };
//
// struct B : public A { };
//
// struct C { };
//
// struct D : public B, C { };
//
// struct E : public D { };
public void testVirtualDtorInBaseClass2() {
loadCodeAndRun(getAboveComment());
checkNoErrors();
}
// struct A {
// virtual void f() = 0;
// ~A(); // warn! public non-virtual dtor.
// // this affects B, D and E further down in the hierarchy as well
// };
//
// struct B : public A { };
//
// struct C { };
//
// struct D : public B, C { };
//
// struct E : public D {
// };
public void _testNonVirtualDtorInBaseClass2() {
checkErrorLines(3, 7, 11, 13);
}
}

View file

@ -21,6 +21,7 @@ import org.eclipse.cdt.codan.core.internal.checkers.AssignmentToItselfCheckerTes
import org.eclipse.cdt.codan.core.internal.checkers.CaseBreakCheckerTest;
import org.eclipse.cdt.codan.core.internal.checkers.CatchByReferenceTest;
import org.eclipse.cdt.codan.core.internal.checkers.FormatStringCheckerTest;
import org.eclipse.cdt.codan.core.internal.checkers.NonVirtualDestructorCheckerTest;
import org.eclipse.cdt.codan.core.internal.checkers.ProblemBindingCheckerTest;
import org.eclipse.cdt.codan.core.internal.checkers.ReturnCheckerTest;
import org.eclipse.cdt.codan.core.internal.checkers.ReturnStyleCheckerTest;
@ -56,6 +57,7 @@ public class AutomatedIntegrationSuite extends TestSuite {
suite.addTestSuite(CaseBreakCheckerTest.class);
suite.addTestSuite(CatchByReferenceTest.class);
suite.addTestSuite(FormatStringCheckerTest.class);
suite.addTestSuite(NonVirtualDestructorCheckerTest.class);
suite.addTestSuite(ProblemBindingCheckerTest.class);
suite.addTestSuite(ReturnCheckerTest.class);
suite.addTestSuite(ReturnStyleCheckerTest.class);