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

Bug 435075 - Avoid an infinite recursion during name resolution

Change-Id: Ie9ac34b184f7b7f6b5196aad716d0fc3696c1e6e
Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
Reviewed-on: https://git.eclipse.org/r/32193
Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
Nathan Ridge 2014-08-20 01:42:03 -04:00 committed by Sergey Prigogin
parent b18a544841
commit 767ceb4a42
6 changed files with 22 additions and 10 deletions

View file

@ -405,4 +405,11 @@ public class IndexCBindingResolutionTest extends IndexBindingResolutionTestBase
assertNotNull(numericalValue); assertNotNull(numericalValue);
assertEquals(i, numericalValue.intValue()); assertEquals(i, numericalValue.intValue());
} }
// extern char TableValue[10];
// char TableValue[sizeof TableValue];
public void testNameLookupFromArrayModifier_435075() throws Exception {
checkBindings();
}
} }

View file

@ -829,7 +829,8 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas
IType type= fn.getType().getParameterTypes()[0]; IType type= fn.getType().getParameterTypes()[0];
assertInstance(type, IPointerType.class); assertInstance(type, IPointerType.class);
type= ((IPointerType) type).getType(); type= ((IPointerType) type).getType();
assertSame(type, cl); assertInstance(cl, IType.class);
assertSameType(type, (IType) cl);
} }
// class A { // class A {

View file

@ -1862,4 +1862,11 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
public void testLambdaOwnedByClass() throws Exception { public void testLambdaOwnedByClass() throws Exception {
checkBindings(); checkBindings();
} }
// extern char TableValue[10];
// char TableValue[sizeof TableValue];
public void testNameLookupFromArrayModifier_435075() throws Exception {
checkBindings();
}
} }

View file

@ -291,7 +291,7 @@ public class CScope implements ICScope, IASTInternalScope {
} }
private IBinding extractBinding(final IASTName candidate, boolean resolve, IASTName forName) { private IBinding extractBinding(final IASTName candidate, boolean resolve, IASTName forName) {
if (!resolve || acceptDeclaredAfter(forName) || CVisitor.declaredBefore(candidate, forName)) { if (!resolve || acceptDeclaredAfter(forName, candidate) || CVisitor.declaredBefore(candidate, forName)) {
if (resolve && candidate != forName) { if (resolve && candidate != forName) {
return candidate.resolveBinding(); return candidate.resolveBinding();
} }
@ -300,7 +300,10 @@ public class CScope implements ICScope, IASTInternalScope {
return null; return null;
} }
private boolean acceptDeclaredAfter(IASTName name) { private boolean acceptDeclaredAfter(IASTName name, IASTName candidate) {
// Functions may be declared after the point of use.
if (!(candidate.getParent() instanceof IASTFunctionDeclarator))
return false;
if (getKind() != EScopeKind.eGlobal) if (getKind() != EScopeKind.eGlobal)
return false; return false;
final ASTNodeProperty propertyInParent = name.getPropertyInParent(); final ASTNodeProperty propertyInParent = name.getPropertyInParent();

View file

@ -1665,6 +1665,7 @@ public class CVisitor extends ASTQueries {
static public boolean declaredBefore(IASTNode nodeA, IASTNode nodeB) { static public boolean declaredBefore(IASTNode nodeA, IASTNode nodeB) {
if (nodeB == null) return true; if (nodeB == null) return true;
if (nodeB.getPropertyInParent() == STRING_LOOKUP_PROPERTY) return true; if (nodeB.getPropertyInParent() == STRING_LOOKUP_PROPERTY) return true;
if (nodeB.getPropertyInParent() == STRING_LOOKUP_TAGS_PROPERTY) return true;
if (nodeA instanceof ASTNode) { if (nodeA instanceof ASTNode) {
ASTNode nd= (ASTNode) nodeA; ASTNode nd= (ASTNode) nodeA;

View file

@ -1871,13 +1871,6 @@ public class CPPSemantics {
int pointOfDecl= -1; int pointOfDecl= -1;
if (obj instanceof ICPPInternalBinding) { if (obj instanceof ICPPInternalBinding) {
ICPPInternalBinding cpp = (ICPPInternalBinding) obj; ICPPInternalBinding cpp = (ICPPInternalBinding) obj;
// For bindings in global or namespace scope we don't know whether there is a
// previous declaration in one of the skipped header files. For bindings that
// are likely to be redeclared we need to assume that there is a declaration
// in one of the headers.
if (indexBased && acceptDeclaredAfter(cpp)) {
return true;
}
IASTNode[] n = cpp.getDeclarations(); IASTNode[] n = cpp.getDeclarations();
if (n != null && n.length > 0) { if (n != null && n.length > 0) {
nd = (ASTNode) n[0]; nd = (ASTNode) n[0];