From d9d69d49a295a2f5c2807dd7d11a24dd09c3ddf0 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Tue, 6 Aug 2013 13:10:55 -0700 Subject: [PATCH] Bug 45203. Don't forward declare types of function parameters since the header containing the function declaration must declare them. --- .../includes/BindingClassifierTest.java | 7 +- .../includes/BindingClassifier.java | 76 +++++++------------ 2 files changed, 33 insertions(+), 50 deletions(-) diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/includes/BindingClassifierTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/includes/BindingClassifierTest.java index 847e5a65970..f3ddc3d9759 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/includes/BindingClassifierTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/includes/BindingClassifierTest.java @@ -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; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/BindingClassifier.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/BindingClassifier.java index fc1e4fed014..51c4e47ab5f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/BindingClassifier.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/BindingClassifier.java @@ -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); - - 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; - } - } + 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)) { + 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); } } }