diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java index b79fccf9806..08f46740fb1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java @@ -1121,7 +1121,7 @@ public class Conversions { return false; } - private static boolean isNullPointerConstant(IType s) { + public static boolean isNullPointerConstant(IType s) { if (s instanceof CPPBasicType) { final CPPBasicType basicType = (CPPBasicType) s; if (basicType.getKind() == Kind.eNullPtr) 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 6c61420b4e0..640b6414b1a 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 @@ -192,6 +192,8 @@ public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase { // void test(A* a) { // f(a); + // f(0); + // f(nullptr); // } public void testFunctionCall() throws Exception { IPreferenceStore preferenceStore = getPreferenceStore(); 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 11c1f1f75fc..8d3003fc04f 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 @@ -100,6 +100,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.LookupData; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; @@ -178,14 +179,18 @@ public class BindingClassifier { // sufficient if it matches the actual parameter type. if (argument instanceof IASTExpression) { IType argumentType = ((IASTExpression) argument).getExpressionType(); - 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)) { + 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; + } } } } @@ -636,7 +641,7 @@ public class BindingClassifier { } // Get the arguments of the initializer. - IASTInitializerClause[] arguments = new IASTInitializerClause[] { }; + IASTInitializerClause[] arguments = IASTExpression.EMPTY_EXPRESSION_ARRAY; if (initializer instanceof ICPPASTConstructorInitializer) { ICPPASTConstructorInitializer constructorInitializer = (ICPPASTConstructorInitializer) initializer; arguments = constructorInitializer.getArguments(); @@ -659,13 +664,13 @@ public class BindingClassifier { // We're constructing a pointer type. No constructor is called. We however have // to check whether the argument type matches the declared type. memberType = getNestedType(memberType, REF); - for (IASTInitializerClause actualParameter : arguments) { - if (actualParameter instanceof IASTExpression) { - IType parameterType = ((IASTExpression) actualParameter).getExpressionType(); - if (!isSameType(memberType, parameterType)) { + for (IASTInitializerClause argument : arguments) { + if (argument instanceof IASTExpression) { + IType argumentType = ((IASTExpression) argument).getExpressionType(); + if (!Conversions.isNullPointerConstant(argumentType) && !isSameType(memberType, argumentType)) { // Types don't match. Define both types. defineTypeExceptTypedefOrNonFixedEnum(memberType); - defineTypeExceptTypedefOrNonFixedEnum(parameterType); + defineTypeExceptTypedefOrNonFixedEnum(argumentType); } } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/GCCHeaderSubstitutionMaps.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/GCCHeaderSubstitutionMaps.java index b77a66a990f..2bca62efddd 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/GCCHeaderSubstitutionMaps.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/GCCHeaderSubstitutionMaps.java @@ -17,26 +17,28 @@ public class GCCHeaderSubstitutionMaps { @SuppressWarnings("nls") private static final String[] symbolExportMap = new String[] { "EOF", "", + "EOF", "", "EOF", "", "NULL", "", "NULL", "", - "NULL", "", - "NULL", "", - "NULL", "", - "NULL", "", - "NULL", "", - "NULL", "", - "NULL", "", - "NULL", "", "NULL", "", + "NULL", "", + "NULL", "", + "NULL", "", "NULL", "", - "NULL", "", + "NULL", "", + "NULL", "", "NULL", "", + "NULL", "", + "NULL", "", + "NULL", "", + "NULL", "", "blkcnt_t", "", "blkcnt_t", "", "blksize_t", "", "blksize_t", "", "calloc", "", + "calloc", "", "daddr_t", "", "daddr_t", "", "dev_t", "", @@ -45,6 +47,7 @@ public class GCCHeaderSubstitutionMaps { "error_t", "", "error_t", "", "free", "", + "free", "", "fsblkcnt_t", "", "fsblkcnt_t", "", "fsfilcnt_t", "", @@ -70,6 +73,7 @@ public class GCCHeaderSubstitutionMaps { "key_t", "", "key_t", "", "malloc", "", + "malloc", "", "mode_t", "", "mode_t", "", "mode_t", "", @@ -89,12 +93,15 @@ public class GCCHeaderSubstitutionMaps { "pid_t", "", "pid_t", "", "pid_t", "", + "pid_t", "", "pid_t", "", "realloc", "", + "realloc", "", "sigset_t", "", "sigset_t", "", "sigset_t", "", "size_t", "", + "size_t", "", "socklen_t", "", "socklen_t", "", "socklen_t", "", @@ -125,6 +132,7 @@ public class GCCHeaderSubstitutionMaps { "useconds_t", "", "useconds_t", "", "va_list", "", + "va_list", "", }; @SuppressWarnings("nls")