1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52: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 {}; // class A {};
// void f(const A* p); // void f(const A* p);
// A* g();
// void test(A* a) { // void test() {
// f(a); // f(g());
// f(0); // f(0);
// f(nullptr); // f(nullptr);
// } // }
@ -199,7 +200,7 @@ public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase {
IPreferenceStore preferenceStore = getPreferenceStore(); IPreferenceStore preferenceStore = getPreferenceStore();
preferenceStore.setValue(PreferenceConstants.FORWARD_DECLARE_FUNCTIONS, true); preferenceStore.setValue(PreferenceConstants.FORWARD_DECLARE_FUNCTIONS, true);
assertDefined(); assertDefined();
assertDeclared("f", "A"); assertDeclared("f", "g");
} }
// typedef int A; // typedef int A;

View file

@ -163,27 +163,18 @@ public class BindingClassifier {
*/ */
private void processFunctionParameters(IFunction function, IASTInitializerClause[] arguments) { private void processFunctionParameters(IFunction function, IASTInitializerClause[] arguments) {
IParameter[] parameters = function.getParameters(); 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(); IType parameterType = parameters[i].getType();
parameterType = getNestedType(parameterType, REF | ALLCVQ); parameterType = getNestedType(parameterType, REF | ALLCVQ);
IASTInitializerClause argument = null; IASTInitializerClause argument = arguments[i];
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) { if (parameterType instanceof IPointerType || parameterType instanceof ICPPReferenceType) {
// The declared parameter type is a pointer or reference type. A declaration is // The declared parameter type is a pointer or reference type. A declaration is
// sufficient if it matches the actual parameter type. // sufficient if it matches the actual parameter type.
if (argument instanceof IASTExpression) { if (argument instanceof IASTExpression) {
IType argumentType = ((IASTExpression) argument).getExpressionType(); IType argumentType = ((IASTExpression) argument).getExpressionType();
if (parameterType instanceof IPointerType && Conversions.isNullPointerConstant(argumentType)) { if (parameterType instanceof IPointerType && Conversions.isNullPointerConstant(argumentType)) {
canBeDeclared = true; continue;
} else { }
argumentType = getNestedType(argumentType, REF | ALLCVQ); argumentType = getNestedType(argumentType, REF | ALLCVQ);
if (parameterType instanceof IPointerType && argumentType instanceof IPointerType) { if (parameterType instanceof IPointerType && argumentType instanceof IPointerType) {
@ -191,19 +182,11 @@ public class BindingClassifier {
argumentType = getNestedType(((IPointerType) argumentType).getType(), ALLCVQ); argumentType = getNestedType(((IPointerType) argumentType).getType(), ALLCVQ);
} }
if (isSameType(parameterType, argumentType)) { if (isSameType(parameterType, argumentType)) {
canBeDeclared = true; 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) { if (argument instanceof IASTExpression) {
IType argumentType = ((IASTExpression) argument).getExpressionType(); IType argumentType = ((IASTExpression) argument).getExpressionType();
// The type of the argument requires a full definition. // The type of the argument requires a full definition.
@ -218,7 +201,6 @@ public class BindingClassifier {
} }
} }
} }
}
/** /**
* Returns {@code true} if {@code targetType} has a constructor that can be used for * Returns {@code true} if {@code targetType} has a constructor that can be used for