mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 395884 - ClassCastException in EvalBinding.getParameterOwner
This commit is contained in:
parent
823e0d0984
commit
9db71c4ba6
4 changed files with 40 additions and 38 deletions
|
@ -2161,4 +2161,18 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
||||||
assertEquals("bool", ASTTypeUtil.getType(td.getType()));
|
assertEquals("bool", ASTTypeUtil.getType(td.getType()));
|
||||||
getProblemFromASTName("type y", 4);
|
getProblemFromASTName("type y", 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// template <class RandomAccessRange, class BinaryPredicate>
|
||||||
|
// void sort(const RandomAccessRange& rng, BinaryPredicate pred);
|
||||||
|
//
|
||||||
|
// struct S {};
|
||||||
|
// const S* s[5];
|
||||||
|
|
||||||
|
// template <typename BinaryPredicate>
|
||||||
|
// void test(BinaryPredicate bp) {
|
||||||
|
// sort(s, [&bp](const S* a, const S* b){ return bp(*a, *b); });
|
||||||
|
// }
|
||||||
|
public void testLambdaExpression_395884() throws Exception {
|
||||||
|
checkBindings();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,28 +48,32 @@ public interface IBinding extends IAdaptable {
|
||||||
* Returns the binding that owns this binding, or <code>null</code> if there is no owner.
|
* Returns the binding that owns this binding, or <code>null</code> if there is no owner.
|
||||||
* <p>
|
* <p>
|
||||||
* The owner is determined as follows:
|
* The owner is determined as follows:
|
||||||
* <br> {@link ICPPUsingDeclaration}: The owner depends on where the declaration is found, within a
|
* <br> {@link ICPPUsingDeclaration}: The owner depends on where the declaration is found,
|
||||||
* function or method, a class-type, a namespace or on global scope.
|
* within a function or method, a class-type, a namespace or on global scope.
|
||||||
* <br> {@link ICPPTemplateParameter}: The owner is the {@link ICPPTemplateDefinition}.
|
* <br> {@link ICPPTemplateParameter}: The owner is the {@link ICPPTemplateDefinition}.
|
||||||
* <br> {@link IEnumerator}: The owner is the {@link IEnumeration}, independent of whether they are scoped or not.
|
* <br> {@link IEnumerator}: The owner is the {@link IEnumeration}, independent of whether they
|
||||||
* <br> For all other bindings: The owner depends on where the binding can be defined (it could be
|
* are scoped or not.
|
||||||
* declared else where).
|
* <br> For all other bindings: The owner depends on where the binding can be defined (it could
|
||||||
|
* be declared elsewhere).
|
||||||
* <p> Possible owners are:
|
* <p> Possible owners are:
|
||||||
* <br> {@link IFunction}: for parameters, local types, variables, enumerators, labels and using declarations;
|
* <br> {@link IFunction}: for parameters, local types, variables, enumerators, labels and using
|
||||||
* <br> {@link ICPPClassType}: for class-, struct- and union-members, even if the composite type is anonymous;
|
* declarations;
|
||||||
* also for enumerators and using declarations;
|
* <br> Closure represented by {@link ICPPClassType}: for lambda expression parameters;
|
||||||
* <br> {@link ICompositeType}: for struct- and union-members, even if the composite type is anonymous;
|
* <br> {@link ICPPClassType}: for class-, struct- and union-members, even if the composite type
|
||||||
* also for anonymous structs or unions found within another struct;
|
* is anonymous; also for enumerators and using declarations;
|
||||||
* <br> {@link ICPPNamespace}: for global types, functions, variables, enumerators, namespaces and using declarations;
|
* <br> {@link ICompositeType}: for struct- and union-members, even if the composite type is
|
||||||
|
* anonymous; also for anonymous structs or unions found within another struct;
|
||||||
|
* <br> {@link ICPPNamespace}: for global types, functions, variables, enumerators, namespaces
|
||||||
|
* and using declarations;
|
||||||
* <br> {@link IEnumeration}: for enumerators.
|
* <br> {@link IEnumeration}: for enumerators.
|
||||||
* <br> <code>null</code>: for types, functions, variables, namespaces and using declarations;
|
* <br> {@code null}: for types, functions, variables, namespaces and using declarations;
|
||||||
* @since 5.1
|
* @since 5.1
|
||||||
*/
|
*/
|
||||||
public IBinding getOwner();
|
public IBinding getOwner();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the parent scope for this binding. A binding may have declarations in multiple scopes,
|
* Returns the parent scope for this binding. A binding may have declarations in multiple
|
||||||
* this method returns the scope where the binding would potentially be defined.
|
* scopes, this method returns the scope where the binding would potentially be defined.
|
||||||
*/
|
*/
|
||||||
public IScope getScope() throws DOMException;
|
public IScope getScope() throws DOMException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP
|
||||||
|
|
||||||
ICPPParameter[] params = new ICPPParameter[parameterTypes.length];
|
ICPPParameter[] params = new ICPPParameter[parameterTypes.length];
|
||||||
for (int i = 0; i < params.length; i++) {
|
for (int i = 0; i < params.length; i++) {
|
||||||
params[i]= new CPPParameter(parameterTypes[i], 0);
|
params[i]= new CPPParameter(parameterTypes[i], i);
|
||||||
}
|
}
|
||||||
m= new CPPImplicitMethod(scope, OverloadableOperator.PAREN.toCharArray(), ft, params) {
|
m= new CPPImplicitMethod(scope, OverloadableOperator.PAREN.toCharArray(), ft, params) {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -39,6 +39,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
|
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
|
import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.Value;
|
import org.eclipse.cdt.internal.core.dom.parser.Value;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPParameter;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
@ -96,12 +97,8 @@ public class EvalBinding extends CPPEvaluation {
|
||||||
* otherwise returns -1
|
* otherwise returns -1
|
||||||
*/
|
*/
|
||||||
public int getFunctionParameterPosition() {
|
public int getFunctionParameterPosition() {
|
||||||
if (fParameterPosition < 0) {
|
if (fParameterPosition < 0 && fBinding instanceof CPPParameter) {
|
||||||
ICPPFunction parameterOwner = getParameterOwner();
|
fParameterPosition = ((CPPParameter) fBinding).getParameterPosition();
|
||||||
if (parameterOwner != null) {
|
|
||||||
ICPPParameter[] parameters = fParameterOwner.getParameters();
|
|
||||||
fParameterPosition = findInArray(parameters, fBinding);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return fParameterPosition;
|
return fParameterPosition;
|
||||||
}
|
}
|
||||||
|
@ -111,27 +108,14 @@ public class EvalBinding extends CPPEvaluation {
|
||||||
* otherwise {@code null}.
|
* otherwise {@code null}.
|
||||||
*/
|
*/
|
||||||
public ICPPFunction getParameterOwner() {
|
public ICPPFunction getParameterOwner() {
|
||||||
if (fParameterOwner == null && fBinding instanceof ICPPParameter) {
|
if (fParameterOwner == null && fBinding instanceof CPPParameter) {
|
||||||
fParameterOwner = (ICPPFunction) ((ICPPParameter) fBinding).getOwner();
|
IBinding owner = ((CPPParameter) fBinding).getOwner();
|
||||||
|
if (owner instanceof ICPPFunction)
|
||||||
|
fParameterOwner = (ICPPFunction) owner;
|
||||||
}
|
}
|
||||||
return fParameterOwner;
|
return fParameterOwner;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds a given object in an array.
|
|
||||||
*
|
|
||||||
* @param array the array to find the object in
|
|
||||||
* @param obj the object to find
|
|
||||||
* @return the index of the object in the array, or -1 if the object is not in the array
|
|
||||||
*/
|
|
||||||
private static int findInArray(Object[] array, Object obj) {
|
|
||||||
for (int i = 0; i < array.length; i++) {
|
|
||||||
if (obj == array[i])
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return if the binding is a template parameter, returns its ID, otherwise returns -1
|
* @return if the binding is a template parameter, returns its ID, otherwise returns -1
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue