mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Bug 504004 - ReturnChecker should treat constructors and destructors as
void functions Change-Id: I8d957abcade86224af1e7ae1b1456f6a8e5b3813
This commit is contained in:
parent
2a3a9d6b4b
commit
ed0b384e9d
1 changed files with 16 additions and 12 deletions
|
@ -106,7 +106,7 @@ public class ReturnChecker extends AbstractAstFunctionChecker {
|
||||||
if (returnValue != null) {
|
if (returnValue != null) {
|
||||||
hasret = true;
|
hasret = true;
|
||||||
}
|
}
|
||||||
if (!isVoid(func) && !isConstructorDestructor(func)) {
|
if (isNonVoid(func) && !isConstructorDestructor(func)) {
|
||||||
if (checkImplicitReturn(RET_NO_VALUE_ID) || isExplicitReturn(func)) {
|
if (checkImplicitReturn(RET_NO_VALUE_ID) || isExplicitReturn(func)) {
|
||||||
if (returnValue == null)
|
if (returnValue == null)
|
||||||
reportProblem(RET_NO_VALUE_ID, ret);
|
reportProblem(RET_NO_VALUE_ID, ret);
|
||||||
|
@ -153,7 +153,7 @@ public class ReturnChecker extends AbstractAstFunctionChecker {
|
||||||
return; // If it is template get out of here.
|
return; // If it is template get out of here.
|
||||||
ReturnStmpVisitor visitor = new ReturnStmpVisitor(func);
|
ReturnStmpVisitor visitor = new ReturnStmpVisitor(func);
|
||||||
func.accept(visitor);
|
func.accept(visitor);
|
||||||
boolean nonVoid = !isVoid(func);
|
boolean nonVoid = isNonVoid(func);
|
||||||
if (nonVoid && !isMain(func)) {
|
if (nonVoid && !isMain(func)) {
|
||||||
// There a return but maybe it is only on one branch.
|
// There a return but maybe it is only on one branch.
|
||||||
IASTStatement body = func.getBody();
|
IASTStatement body = func.getBody();
|
||||||
|
@ -201,9 +201,6 @@ public class ReturnChecker extends AbstractAstFunctionChecker {
|
||||||
if (!checkImplicitReturn(RET_NORET_ID) && !isExplicitReturn(func)) {
|
if (!checkImplicitReturn(RET_NORET_ID) && !isExplicitReturn(func)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isConstructorDestructor(func)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reportProblem(RET_NORET_ID, func.getDeclSpecifier());
|
reportProblem(RET_NORET_ID, func.getDeclSpecifier());
|
||||||
|
@ -251,18 +248,25 @@ public class ReturnChecker extends AbstractAstFunctionChecker {
|
||||||
return getDeclSpecType(func) != IASTSimpleDeclSpecifier.t_unspecified;
|
return getDeclSpecType(func) != IASTSimpleDeclSpecifier.t_unspecified;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isVoid(IASTFunctionDefinition func) {
|
/**
|
||||||
|
* Checks if the function has a return type other than void. Constructors and destructors
|
||||||
|
* don't have return type.
|
||||||
|
*
|
||||||
|
* @param func the function to check
|
||||||
|
* @return {@code true} if the function has a non void return type
|
||||||
|
*/
|
||||||
|
private boolean isNonVoid(IASTFunctionDefinition func) {
|
||||||
|
if (isConstructorDestructor(func))
|
||||||
|
return false;
|
||||||
int type = getDeclSpecType(func);
|
int type = getDeclSpecType(func);
|
||||||
if (type == IASTSimpleDeclSpecifier.t_void) {
|
if (type == IASTSimpleDeclSpecifier.t_void) {
|
||||||
IASTFunctionDeclarator declarator = func.getDeclarator();
|
IASTFunctionDeclarator declarator = func.getDeclarator();
|
||||||
if (declarator.getPointerOperators().length == 0)
|
if (declarator.getPointerOperators().length == 0)
|
||||||
return true;
|
return false;
|
||||||
} else if (type == IASTSimpleDeclSpecifier.t_auto) {
|
} else if (type == IASTSimpleDeclSpecifier.t_auto && isAutoVoid(func)) {
|
||||||
if (isAutoVoid(func)) {
|
return false;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue