diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java index cc4715284cc..0e8fded9b54 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java @@ -2161,4 +2161,18 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa assertEquals("bool", ASTTypeUtil.getType(td.getType())); getProblemFromASTName("type y", 4); } + + // template + // void sort(const RandomAccessRange& rng, BinaryPredicate pred); + // + // struct S {}; + // const S* s[5]; + + // template + // void test(BinaryPredicate bp) { + // sort(s, [&bp](const S* a, const S* b){ return bp(*a, *b); }); + // } + public void testLambdaExpression_395884() throws Exception { + checkBindings(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBinding.java index 99ccc8589c1..66d16bf1192 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBinding.java @@ -48,28 +48,32 @@ public interface IBinding extends IAdaptable { * Returns the binding that owns this binding, or null if there is no owner. *

* The owner is determined as follows: - *
{@link ICPPUsingDeclaration}: The owner depends on where the declaration is found, within a - * function or method, a class-type, a namespace or on global scope. + *
{@link ICPPUsingDeclaration}: The owner depends on where the declaration is found, + * within a function or method, a class-type, a namespace or on global scope. *
{@link ICPPTemplateParameter}: The owner is the {@link ICPPTemplateDefinition}. - *
{@link IEnumerator}: The owner is the {@link IEnumeration}, independent of whether they are scoped or not. - *
For all other bindings: The owner depends on where the binding can be defined (it could be - * declared else where). + *
{@link IEnumerator}: The owner is the {@link IEnumeration}, independent of whether they + * are scoped or not. + *
For all other bindings: The owner depends on where the binding can be defined (it could + * be declared elsewhere). *

Possible owners are: - *
{@link IFunction}: for parameters, local types, variables, enumerators, labels and using declarations; - *
{@link ICPPClassType}: for class-, struct- and union-members, even if the composite type is anonymous; - * also for enumerators and using declarations; - *
{@link ICompositeType}: for struct- and union-members, even if the composite type is anonymous; - * also for anonymous structs or unions found within another struct; - *
{@link ICPPNamespace}: for global types, functions, variables, enumerators, namespaces and using declarations; + *
{@link IFunction}: for parameters, local types, variables, enumerators, labels and using + * declarations; + *
Closure represented by {@link ICPPClassType}: for lambda expression parameters; + *
{@link ICPPClassType}: for class-, struct- and union-members, even if the composite type + * is anonymous; also for enumerators and using declarations; + *
{@link ICompositeType}: for struct- and union-members, even if the composite type is + * anonymous; also for anonymous structs or unions found within another struct; + *
{@link ICPPNamespace}: for global types, functions, variables, enumerators, namespaces + * and using declarations; *
{@link IEnumeration}: for enumerators. - *
null: for types, functions, variables, namespaces and using declarations; + *
{@code null}: for types, functions, variables, namespaces and using declarations; * @since 5.1 */ public IBinding getOwner(); /** - * Returns the parent scope for this binding. A binding may have declarations in multiple scopes, - * this method returns the scope where the binding would potentially be defined. + * Returns the parent scope for this binding. A binding may have declarations in multiple + * scopes, this method returns the scope where the binding would potentially be defined. */ public IScope getScope() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java index 30a8f9a62f3..14e1902fd42 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java @@ -107,7 +107,7 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP ICPPParameter[] params = new ICPPParameter[parameterTypes.length]; 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) { @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java index 47a59ec9236..8f4ba43e7c7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java @@ -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.ProblemType; 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.ICPPUnknownBinding; import org.eclipse.core.runtime.CoreException; @@ -96,12 +97,8 @@ public class EvalBinding extends CPPEvaluation { * otherwise returns -1 */ public int getFunctionParameterPosition() { - if (fParameterPosition < 0) { - ICPPFunction parameterOwner = getParameterOwner(); - if (parameterOwner != null) { - ICPPParameter[] parameters = fParameterOwner.getParameters(); - fParameterPosition = findInArray(parameters, fBinding); - } + if (fParameterPosition < 0 && fBinding instanceof CPPParameter) { + fParameterPosition = ((CPPParameter) fBinding).getParameterPosition(); } return fParameterPosition; } @@ -111,27 +108,14 @@ public class EvalBinding extends CPPEvaluation { * otherwise {@code null}. */ public ICPPFunction getParameterOwner() { - if (fParameterOwner == null && fBinding instanceof ICPPParameter) { - fParameterOwner = (ICPPFunction) ((ICPPParameter) fBinding).getOwner(); + if (fParameterOwner == null && fBinding instanceof CPPParameter) { + IBinding owner = ((CPPParameter) fBinding).getOwner(); + if (owner instanceof ICPPFunction) + fParameterOwner = (ICPPFunction) owner; } 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 */