Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 355938
Collapse All | Expand All

(-)a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java (-1 / +3 lines)
Lines 47-52 import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition; Link Here
47
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLambdaExpression;
47
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLambdaExpression;
48
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
48
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
49
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
49
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
50
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTryBlockStatement;
50
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
51
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
51
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
52
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
52
53
Lines 206-212 public class ReturnChecker extends AbstractAstFunctionChecker { Link Here
206
	private boolean isCompoundStatement(IASTStatement last) {
207
	private boolean isCompoundStatement(IASTStatement last) {
207
		return last instanceof IASTIfStatement || last instanceof IASTWhileStatement ||
208
		return last instanceof IASTIfStatement || last instanceof IASTWhileStatement ||
208
				last instanceof IASTDoStatement	|| last instanceof IASTForStatement ||
209
				last instanceof IASTDoStatement	|| last instanceof IASTForStatement ||
209
				last instanceof IASTSwitchStatement || last instanceof IASTCompoundStatement;
210
				last instanceof IASTSwitchStatement || last instanceof IASTCompoundStatement ||
211
				last instanceof ICPPASTTryBlockStatement;
210
	}
212
	}
211
213
212
	protected boolean isFuncExitStatement(IASTStatement statement) {
214
	protected boolean isFuncExitStatement(IASTStatement statement) {
(-)a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/cfg/ControlFlowGraphBuilder.java (-1 / +8 lines)
Lines 32-37 import org.eclipse.cdt.core.dom.ast.IASTBreakStatement; Link Here
32
import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
32
import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
33
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
33
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
34
import org.eclipse.cdt.core.dom.ast.IASTContinueStatement;
34
import org.eclipse.cdt.core.dom.ast.IASTContinueStatement;
35
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
35
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
36
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
36
import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement;
37
import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement;
37
import org.eclipse.cdt.core.dom.ast.IASTDoStatement;
38
import org.eclipse.cdt.core.dom.ast.IASTDoStatement;
Lines 238-244 public class ControlFlowGraphBuilder { Link Here
238
		ICPPASTCatchHandler[] catchHandlers = body.getCatchHandlers();
239
		ICPPASTCatchHandler[] catchHandlers = body.getCatchHandlers();
239
		for (int i = 0; i < catchHandlers.length; i++) {
240
		for (int i = 0; i < catchHandlers.length; i++) {
240
			ICPPASTCatchHandler handler = catchHandlers[i];
241
			ICPPASTCatchHandler handler = catchHandlers[i];
241
			IBranchNode handlerNode = factory.createBranchNode(handler.getDeclaration());
242
			IASTDeclaration handlerDecl = handler.getDeclaration();
243
			// handlerDecl might be null if the handler is of the form 'catch (...)'
244
			IBranchNode handlerNode;
245
			if (handlerDecl == null)
246
				handlerNode = factory.createBranchNode("..."); //$NON-NLS-1$
247
			else
248
				handlerNode = factory.createBranchNode(handler.getDeclaration());
242
			addOutgoing(ifNode, handlerNode);
249
			addOutgoing(ifNode, handlerNode);
243
			IBasicBlock els = createSubGraph(handlerNode, handler.getCatchBody());
250
			IBasicBlock els = createSubGraph(handlerNode, handler.getCatchBody());
244
			addJump(els, mergeNode);
251
			addJump(els, mergeNode);
(-)a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java (+23 lines)
Lines 310-313 public class ReturnCheckerTest extends CheckerTestCase { Link Here
310
		loadCodeAndRun(getAboveComment());
310
		loadCodeAndRun(getAboveComment());
311
		checkNoErrors();
311
		checkNoErrors();
312
	}
312
	}
313
314
	// int foo() {
315
	//     try {
316
	//         return 1;
317
	//     } catch (...) {
318
	//         return 0;
319
	//     }
320
	// }
321
	public void testTryCatch1_Bug355938() {
322
		loadCodeAndRunCpp(getAboveComment());
323
		checkNoErrors();
324
	}
325
326
	// int foo() {
327
	//     try {
328
	//         return 1;
329
	//     } catch (...) {
330
	//     }
331
	// }
332
	public void testTryCatch2_Bug355938() {
333
		loadCodeAndRunCpp(getAboveComment());
334
		checkErrorLine(1);
335
	}
313
}
336
}

Return to bug 355938