Bug 543913 - False negative in ctor with wrong arguments

Change-Id: I3a9c692383c5c9d8c465d9ecbc66463b39d5199d
Signed-off-by: Hannes Vogt <hannes@havogt.de>
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
index 3134508..b32453e 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
@@ -12834,4 +12834,20 @@
 		// which is explicit
 		bh.assertImplicitName("a0", 2, IProblemBinding.class);
 	}
+
+	//	struct type {
+	//	  type(int a) {}
+	//	};
+	//
+	//	struct other_type {};
+	//
+	//	int main() {
+	//	  type(1, 2);
+	//	  type(other_type());
+	//	}
+	public void testCtorWithWrongArguments_543913() throws Exception {
+		BindingAssertionHelper bh = getAssertionHelper();
+		bh.assertImplicitName("type(1, 2)", 4, IProblemBinding.class);
+		bh.assertImplicitName("type(other_type())", 4, IProblemBinding.class);
+	}
 }
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java
index 3917785..fa084f4 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java
@@ -33,6 +33,7 @@
 import org.eclipse.cdt.core.dom.ast.IASTName;
 import org.eclipse.cdt.core.dom.ast.IASTNode;
 import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.IProblemBinding;
 import org.eclipse.cdt.core.dom.ast.IType;
 import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpression;
 import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference;
@@ -132,6 +133,14 @@
 			if (overload == null)
 				return fImplicitNames = IASTImplicitName.EMPTY_NAME_ARRAY;
 
+			if (overload instanceof IProblemBinding) {
+				CPPASTImplicitName overloadName = null;
+				overloadName = new CPPASTImplicitName(overload.getNameCharArray(), this);
+				overloadName.setBinding(overload);
+				overloadName.setOffsetAndLength((ASTNode) getFunctionNameExpression());
+				return fImplicitNames = new IASTImplicitName[] { overloadName };
+			}
+
 			if (getEvaluation() instanceof EvalTypeId) {
 				CPPASTImplicitName n1 = new CPPASTImplicitName(overload.getNameCharArray(), this);
 				n1.setOffsetAndLength((ASTNode) fFunctionName);
@@ -264,6 +273,9 @@
 						try {
 							ICPPConstructor[] constructors = cls.getConstructors();
 							IBinding b = CPPSemantics.resolveFunction(data, constructors, true, false);
+							if (b instanceof IProblemBinding && !(b instanceof ICPPFunction))
+								b = new CPPFunction.CPPFunctionProblem(data.getLookupName(),
+										((IProblemBinding) b).getID());
 							if (b instanceof ICPPFunction)
 								return (ICPPFunction) b;
 						} catch (DOMException e) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java
index b4fe2f7..bc9cd9b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java
@@ -53,6 +53,7 @@
 import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
 import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
 import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
+import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
 import org.eclipse.cdt.internal.core.dom.parser.ProblemFunctionType;
 import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
 import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
@@ -63,6 +64,47 @@
  * Binding for C++ function
  */
 public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInternalFunction {
+
+	public static class CPPFunctionProblem extends ProblemBinding implements ICPPFunction {
+		public CPPFunctionProblem(IASTNode node, int id, char[] arg) {
+			super(node, id, arg);
+		}
+
+		public CPPFunctionProblem(IASTName name, int id) {
+			super(name, id);
+		}
+
+		@Override
+		public IScope getFunctionScope() {
+			return null;
+		}
+
+		@Override
+		public boolean isNoReturn() {
+			return false;
+		}
+
+		@Override
+		public ICPPFunctionType getType() {
+			return null;
+		}
+
+		@Override
+		public ICPPFunctionType getDeclaredType() {
+			return null;
+		}
+
+		@Override
+		public ICPPParameter[] getParameters() {
+			return ICPPParameter.EMPTY_CPPPARAMETER_ARRAY;
+		}
+
+		@Override
+		public int getRequiredArgumentCount() {
+			return 0;
+		}
+	}
+
 	public static final ICPPFunction UNINITIALIZED_FUNCTION = new CPPFunction(null) {
 		@Override
 		public String toString() {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java
index dfad903..e899187 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java
@@ -2759,7 +2759,7 @@
 
 		if (bestFnCost == null) {
 			if (unknownFunction == null)
-				return null;
+				return new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, fns);
 
 			setTargetedFunctionsToUnknown(argTypes);
 			return CPPDeferredFunction.createForCandidates(fns);