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);
|
analyzer.visit(returnValue);
|
||||||
}
|
}
|
||||||
} else if (returnKind == ReturnTypeKind.Void) {
|
} else if (returnKind == ReturnTypeKind.Void) {
|
||||||
if (returnValue instanceof IASTExpression) {
|
if (returnValue instanceof IASTExpression expr) {
|
||||||
IType type = ((IASTExpression) returnValue).getExpressionType();
|
IType type = SemanticUtil.getNestedType(expr.getExpressionType(), SemanticUtil.TDEF);
|
||||||
if (isVoid(type))
|
if (isVoid(type) || CPPTemplates.isDependentType(type)) {
|
||||||
|
// For case of TypeOfDependentExpression see comment in getReturnTypeKind()
|
||||||
return PROCESS_SKIP;
|
return PROCESS_SKIP;
|
||||||
|
}
|
||||||
reportProblem(RET_ERR_VALUE_ID, returnValue);
|
reportProblem(RET_ERR_VALUE_ID, returnValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -417,7 +419,8 @@ public class ReturnChecker extends AbstractAstFunctionChecker {
|
||||||
|
|
||||||
private IType getReturnType(IASTFunctionDefinition func) {
|
private IType getReturnType(IASTFunctionDefinition func) {
|
||||||
if (cachedReturnType == null) {
|
if (cachedReturnType == null) {
|
||||||
cachedReturnType = CxxAstUtils.getReturnType(func);
|
IType type = SemanticUtil.getNestedType(CxxAstUtils.getReturnType(func), SemanticUtil.TDEF);
|
||||||
|
cachedReturnType = type;
|
||||||
}
|
}
|
||||||
return cachedReturnType;
|
return cachedReturnType;
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,6 +130,36 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
checkErrorLine(3, ReturnChecker.RET_ERR_VALUE_ID);
|
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 {
|
// class c {
|
||||||
// c() {
|
// c() {
|
||||||
// return;
|
// return;
|
||||||
|
|
Loading…
Add table
Reference in a new issue