From d27cdd90ca1220412cabff55935fe428e1b63e5e Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Tue, 6 Aug 2013 15:26:49 -0700 Subject: [PATCH] Bug 45203. Fixed a bug and added test for function calls with reference parameters. --- .../includes/BindingClassifierTest.java | 14 ++++++++++++++ .../ui/refactoring/includes/BindingClassifier.java | 9 ++++++--- 2 files changed, 20 insertions(+), 3 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 f3ddc3d9759..41151dd4335 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 @@ -216,6 +216,20 @@ public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase { assertDeclared("f"); } + // class A {}; + // void f(const A& p); + // A& g(); + + // void test() { + // f(g()); + // } + public void testFunctionCallWithReferenceParameter() throws Exception { + IPreferenceStore preferenceStore = getPreferenceStore(); + preferenceStore.setValue(PreferenceConstants.FORWARD_DECLARE_FUNCTIONS, true); + assertDefined(); + assertDeclared("f", "g"); + } + // struct A { // A(const char* s); // }; 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 51c4e47ab5f..0ad0fa3223e 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 @@ -165,16 +165,18 @@ public class BindingClassifier { IParameter[] parameters = function.getParameters(); for (int i = 0; i < parameters.length && i < arguments.length; i++) { IType parameterType = parameters[i].getType(); - parameterType = getNestedType(parameterType, 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. + // sufficient if it matches the actual parameter type. We don't need to provide + // a parameter declaration since it is a responsibility of the header declaring + // the function. if (argument instanceof IASTExpression) { IType argumentType = ((IASTExpression) argument).getExpressionType(); if (parameterType instanceof IPointerType && Conversions.isNullPointerConstant(argumentType)) { continue; } + parameterType = getNestedType(parameterType, REF | ALLCVQ); argumentType = getNestedType(argumentType, REF | ALLCVQ); if (parameterType instanceof IPointerType && argumentType instanceof IPointerType) { @@ -194,6 +196,7 @@ public class BindingClassifier { } // As a matter of policy, a header declaring the function is responsible for // defining parameter types that allow implicit conversion. + parameterType = getNestedType(parameterType, REF | ALLCVQ); if (!(parameterType instanceof ICPPClassType) || fAst.getDeclarationsInAST(function).length != 0 || !hasConvertingConstructor((ICPPClassType) parameterType, argument)) { @@ -430,7 +433,7 @@ public class BindingClassifier { return; if (fAst.getDefinitionsInAST(binding).length != 0) - return; // Defined locally + return; // Defined locally. List requiredBindings = getRequiredBindings(binding); for (IBinding requiredBinding : requiredBindings) {