diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java index 77ec28aa489..01a51d7dcb9 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java @@ -251,10 +251,12 @@ public class ReturnChecker extends AbstractAstFunctionChecker { analyzer.visit(returnValue); } } else if (returnKind == ReturnTypeKind.Void) { - if (returnValue instanceof IASTExpression) { - IType type = ((IASTExpression) returnValue).getExpressionType(); - if (isVoid(type)) + if (returnValue instanceof IASTExpression expr) { + IType type = SemanticUtil.getNestedType(expr.getExpressionType(), SemanticUtil.TDEF); + if (isVoid(type) || CPPTemplates.isDependentType(type)) { + // For case of TypeOfDependentExpression see comment in getReturnTypeKind() return PROCESS_SKIP; + } reportProblem(RET_ERR_VALUE_ID, returnValue); } } @@ -417,7 +419,8 @@ public class ReturnChecker extends AbstractAstFunctionChecker { private IType getReturnType(IASTFunctionDefinition func) { if (cachedReturnType == null) { - cachedReturnType = CxxAstUtils.getReturnType(func); + IType type = SemanticUtil.getNestedType(CxxAstUtils.getReturnType(func), SemanticUtil.TDEF); + cachedReturnType = type; } return cachedReturnType; } diff --git a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java index 7487bcce5bb..b06df15dd2a 100644 --- a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java +++ b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java @@ -130,6 +130,36 @@ public class ReturnCheckerTest extends CheckerTestCase { checkErrorLine(3, ReturnChecker.RET_ERR_VALUE_ID); } + // typedef void typedef_type; + // typedef_type f() + // { + // return; + // } + public void testTypedefVoidReturnType() throws Exception { + checkSampleAbove(); + } + + // typedef void typedef_type; + // typedef_type g(); + // void f() + // { + // return g(); + // } + public void testReturningTypedefVoidReturnType() throws Exception { + checkSampleAbove(); + } + + // template + // void g(T t) {} + // + // template + // void f(T t) { + // return g(t); + // } + public void testTemplateFunctionReturningVoidType() throws Exception { + checkSampleAbove(); + } + // class c { // c() { // return;