1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 01:15:29 +02:00

Bug 543913 - False negative in ctor with wrong arguments

Change-Id: I3a9c692383c5c9d8c465d9ecbc66463b39d5199d
Signed-off-by: Hannes Vogt <hannes@havogt.de>
This commit is contained in:
Hannes Vogt 2019-01-29 21:36:42 +01:00
parent 740496c20f
commit e5466b8204
4 changed files with 71 additions and 1 deletions

View file

@ -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);
}
}

View file

@ -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) {

View file

@ -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() {

View file

@ -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);