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 640b6414b1a..847e5a65970 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 @@ -195,13 +195,26 @@ public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase { // f(0); // f(nullptr); // } - public void testFunctionCall() throws Exception { + public void testFunctionCallWithPointerParameter_1() throws Exception { IPreferenceStore preferenceStore = getPreferenceStore(); preferenceStore.setValue(PreferenceConstants.FORWARD_DECLARE_FUNCTIONS, true); assertDefined(); assertDeclared("f", "A"); } + // typedef int A; + // void f(const A* p); + + // void test() { + // f(nullptr); + // } + public void testFunctionCallWithPointerParameter_2() throws Exception { + IPreferenceStore preferenceStore = getPreferenceStore(); + preferenceStore.setValue(PreferenceConstants.FORWARD_DECLARE_FUNCTIONS, true); + assertDefined(); + assertDeclared("f"); + } + // 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 d3c26a57bd6..fc1e4fed014 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 @@ -201,7 +201,7 @@ public class BindingClassifier { if (canBeDeclared) { // The declared parameter type must be declared. We must explicitly do this here // because this type doesn't appear within the AST. - declareType(parameterType); + declareTypeExceptTypedefOrNonFixedEnum(parameterType); } else { assert argument != null; if (argument instanceof IASTExpression) { @@ -422,6 +422,22 @@ public class BindingClassifier { } } + /** + * Adds the given type to the list of bindings which have to be declared. Typedefs and + * enumerations without fixed underlying type are skipped since they must be defined in the file + * that references them by name. If the type is explicitly referenced in this translation unit, + * it will be defined independently from this method. + * + * @param type The type to add. + */ + private void declareTypeExceptTypedefOrNonFixedEnum(IType type) { + IBinding typeBinding = getTypeBinding(type); + if (typeBinding != null && !(typeBinding instanceof ITypedef) + && !isEnumerationWithoutFixedUnderlyingType(typeBinding)) { + declareBinding(typeBinding); + } + } + /** * Adds the given binding to the list of bindings which have to be defined. *