mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +02:00
Fix codan return value check with typedef return and template function
This commit is contained in:
parent
58ab28dfd1
commit
590906a005
2 changed files with 37 additions and 4 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<typename T>
|
||||
// void g(T t) {}
|
||||
//
|
||||
// template<typename T>
|
||||
// void f(T t) {
|
||||
// return g(t);
|
||||
// }
|
||||
public void testTemplateFunctionReturningVoidType() throws Exception {
|
||||
checkSampleAbove();
|
||||
}
|
||||
|
||||
// class c {
|
||||
// c() {
|
||||
// return;
|
||||
|
|
Loading…
Add table
Reference in a new issue