1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Bug 446225 - Captured variables not recognized as usages

This commit is contained in:
Sergey Prigogin 2014-10-07 15:54:08 -07:00
parent 936b844596
commit 20feb58da0
3 changed files with 8 additions and 5 deletions

View file

@ -8336,6 +8336,7 @@ public class AST2CPPTests extends AST2TestBase {
ICPPVariable foo1= bh.assertNonProblemOnFirstIdentifier("foo =", ICPPVariable.class); ICPPVariable foo1= bh.assertNonProblemOnFirstIdentifier("foo =", ICPPVariable.class);
ICPPVariable foo2= bh.assertNonProblemOnFirstIdentifier("[foo]", ICPPVariable.class); ICPPVariable foo2= bh.assertNonProblemOnFirstIdentifier("[foo]", ICPPVariable.class);
assertTrue(foo1 == foo2); assertTrue(foo1 == foo2);
assertEquals(2, bh.getTranslationUnit().getReferences(foo1).length);
} }
// typedef int TInt; // typedef int TInt;

View file

@ -1443,7 +1443,7 @@ public class CPPVisitor extends ASTQueries {
private void addProblem(IASTProblem problem) { private void addProblem(IASTProblem problem) {
if (fProblems == null) { if (fProblems == null) {
fProblems= new ArrayList<IASTProblem>(); fProblems= new ArrayList<>();
} }
fProblems.add(problem); fProblems.add(problem);
} }
@ -1610,7 +1610,7 @@ public class CPPVisitor extends ASTQueries {
if (areEquivalentBindings(nameBinding, binding, index)) { if (areEquivalentBindings(nameBinding, binding, index)) {
return true; return true;
} }
// A using declaration is a declaration for the references of its delegates // A using declaration is a declaration for the references of its delegates.
if (nameBinding instanceof ICPPUsingDeclaration) { if (nameBinding instanceof ICPPUsingDeclaration) {
if (ArrayUtil.contains(((ICPPUsingDeclaration) nameBinding).getDelegates(), binding)) { if (ArrayUtil.contains(((ICPPUsingDeclaration) nameBinding).getDelegates(), binding)) {
return true; return true;
@ -1634,8 +1634,9 @@ public class CPPVisitor extends ASTQueries {
return true; return true;
} }
if ((binding1 instanceof IIndexBinding) != (binding2 instanceof IIndexBinding) && index != null) { if ((binding1 instanceof IIndexBinding) != (binding2 instanceof IIndexBinding) && index != null) {
// Even though we know one of them is an index binding, we need to adapt both because they might not come from an // Even though we know one of them is an index binding, we need to adapt both because
// index with the same number of fragments. So one of them could be a composite binding and the other one not. // they might not come from an index with the same number of fragments. So one of them
// could be a composite binding and the other one not.
binding1 = index.adaptBinding(binding1); binding1 = index.adaptBinding(binding1);
binding2 = index.adaptBinding(binding2); binding2 = index.adaptBinding(binding2);
@ -1753,6 +1754,7 @@ public class CPPVisitor extends ASTQueries {
prop == IASTNamedTypeSpecifier.NAME || prop == IASTNamedTypeSpecifier.NAME ||
prop == ICPPASTConstructorChainInitializer.MEMBER_ID || prop == ICPPASTConstructorChainInitializer.MEMBER_ID ||
prop == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT || prop == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT ||
prop == ICPPASTCapture.IDENTIFIER ||
prop == IASTImplicitNameOwner.IMPLICIT_NAME) { prop == IASTImplicitNameOwner.IMPLICIT_NAME) {
break; break;
} }

View file

@ -57,7 +57,7 @@ public class OccurrencesFinder implements IOccurrencesFinder {
if (!(node instanceof IASTName)) if (!(node instanceof IASTName))
return CSearchMessages.OccurrencesFinder_no_element; return CSearchMessages.OccurrencesFinder_no_element;
fRoot= root; fRoot= root;
fSelectedNode= (IASTName)node; fSelectedNode= (IASTName) node;
fTarget= fSelectedNode.resolveBinding(); fTarget= fSelectedNode.resolveBinding();
if (fTarget == null) if (fTarget == null)
return CSearchMessages.OccurrencesFinder_no_binding; return CSearchMessages.OccurrencesFinder_no_binding;