1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Bug 45203. Don't forward declare types of function parameters since

the header containing the function declaration must declare them.
This commit is contained in:
Sergey Prigogin 2013-08-06 13:10:55 -07:00
parent 9d234dcfce
commit d9d69d49a2
2 changed files with 33 additions and 50 deletions

View file

@ -189,9 +189,10 @@ public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase {
// class A {};
// void f(const A* p);
// A* g();
// void test(A* a) {
// f(a);
// void test() {
// f(g());
// f(0);
// f(nullptr);
// }
@ -199,7 +200,7 @@ public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase {
IPreferenceStore preferenceStore = getPreferenceStore();
preferenceStore.setValue(PreferenceConstants.FORWARD_DECLARE_FUNCTIONS, true);
assertDefined();
assertDeclared("f", "A");
assertDeclared("f", "g");
}
// typedef int A;

View file

@ -163,59 +163,41 @@ public class BindingClassifier {
*/
private void processFunctionParameters(IFunction function, IASTInitializerClause[] arguments) {
IParameter[] parameters = function.getParameters();
for (int i = 0; i < parameters.length; i++) {
for (int i = 0; i < parameters.length && i < arguments.length; i++) {
IType parameterType = parameters[i].getType();
parameterType = getNestedType(parameterType, REF | ALLCVQ);
IASTInitializerClause argument = null;
boolean canBeDeclared = false;
if (i >= arguments.length) {
// This is a default value parameter. The function call itself doesn't need
// a definition of this parameter type.
canBeDeclared = true;
} else {
// This argument is present within the function call expression.
// It's therefore not a default parameter.
argument = arguments[i];
if (parameterType instanceof IPointerType || parameterType instanceof ICPPReferenceType) {
// The declared parameter type is a pointer or reference type. A declaration is
// sufficient if it matches the actual parameter type.
if (argument instanceof IASTExpression) {
IType argumentType = ((IASTExpression) argument).getExpressionType();
if (parameterType instanceof IPointerType && Conversions.isNullPointerConstant(argumentType)) {
canBeDeclared = true;
} else {
argumentType = getNestedType(argumentType, REF | ALLCVQ);
IASTInitializerClause argument = arguments[i];
if (parameterType instanceof IPointerType || parameterType instanceof ICPPReferenceType) {
// The declared parameter type is a pointer or reference type. A declaration is
// sufficient if it matches the actual parameter type.
if (argument instanceof IASTExpression) {
IType argumentType = ((IASTExpression) argument).getExpressionType();
if (parameterType instanceof IPointerType && Conversions.isNullPointerConstant(argumentType)) {
continue;
}
argumentType = getNestedType(argumentType, REF | ALLCVQ);
if (parameterType instanceof IPointerType && argumentType instanceof IPointerType) {
parameterType = getNestedType(((IPointerType) parameterType).getType(), ALLCVQ);
argumentType = getNestedType(((IPointerType) argumentType).getType(), ALLCVQ);
}
if (isSameType(parameterType, argumentType)) {
canBeDeclared = true;
}
}
if (parameterType instanceof IPointerType && argumentType instanceof IPointerType) {
parameterType = getNestedType(((IPointerType) parameterType).getType(), ALLCVQ);
argumentType = getNestedType(((IPointerType) argumentType).getType(), ALLCVQ);
}
if (isSameType(parameterType, argumentType)) {
continue;
}
}
}
if (canBeDeclared) {
// The declared parameter type must be declared. We must explicitly do this here
// because this type doesn't appear within the AST.
declareTypeExceptTypedefOrNonFixedEnum(parameterType);
} else {
assert argument != null;
if (argument instanceof IASTExpression) {
IType argumentType = ((IASTExpression) argument).getExpressionType();
// The type of the argument requires a full definition.
defineTypeExceptTypedefOrNonFixedEnum(argumentType);
}
// As a matter of policy, a header declaring the function is responsible for
// defining parameter types that allow implicit conversion.
if (!(parameterType instanceof ICPPClassType) ||
fAst.getDeclarationsInAST(function).length != 0 ||
!hasConvertingConstructor((ICPPClassType) parameterType, argument)) {
defineTypeExceptTypedefOrNonFixedEnum(parameterType);
}
if (argument instanceof IASTExpression) {
IType argumentType = ((IASTExpression) argument).getExpressionType();
// The type of the argument requires a full definition.
defineTypeExceptTypedefOrNonFixedEnum(argumentType);
}
// As a matter of policy, a header declaring the function is responsible for
// defining parameter types that allow implicit conversion.
if (!(parameterType instanceof ICPPClassType) ||
fAst.getDeclarationsInAST(function).length != 0 ||
!hasConvertingConstructor((ICPPClassType) parameterType, argument)) {
defineTypeExceptTypedefOrNonFixedEnum(parameterType);
}
}
}