diff options
author | Hannes Vogt | 2019-01-29 20:36:42 +0000 |
---|---|---|
committer | Hannes Vogt | 2019-02-01 06:18:02 +0000 |
commit | e5466b8204c8c903c36e43e0c9d5c4ea9d83a942 (patch) | |
tree | 1f7c757561654b02515fa16ca81e1d5a93d6f86f | |
parent | 740496c20ff25c43e53d5e3629721b761b2fcb8b (diff) | |
download | org.eclipse.cdt-e5466b8204c8c903c36e43e0c9d5c4ea9d83a942.tar.gz org.eclipse.cdt-e5466b8204c8c903c36e43e0c9d5c4ea9d83a942.tar.xz org.eclipse.cdt-e5466b8204c8c903c36e43e0c9d5c4ea9d83a942.zip |
Bug 543913 - False negative in ctor with wrong arguments
Change-Id: I3a9c692383c5c9d8c465d9ecbc66463b39d5199d
Signed-off-by: Hannes Vogt <hannes@havogt.de>
4 files changed, 71 insertions, 1 deletions
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 3134508e077..b32453e95e7 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 @@ public class AST2CPPTests extends AST2CPPTestBase { // 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 3917785ac1f..fa084f408f8 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.IASTInitializerClause; 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 @@ public class CPPASTFunctionCallExpression extends ASTNode 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 @@ public class CPPASTFunctionCallExpression extends ASTNode 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 b4fe2f7b25a..bc9cd9b9ac8 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.Linkage; 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 @@ import org.eclipse.core.runtime.PlatformObject; * 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 dfad90333ee..e899187cc0d 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 @@ public class CPPSemantics { 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); |