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

Checking for compatible arrays in plain C, follow up to bug 269926.

This commit is contained in:
Markus Schorn 2009-08-21 13:29:04 +00:00
parent 65ab982bac
commit 537f9ed45a
4 changed files with 29 additions and 19 deletions

View file

@ -6407,4 +6407,12 @@ public class AST2Tests extends AST2BaseTest {
assertTrue(((IFunction)n.resolveBinding()).getType().getParameterTypes()[0] instanceof IPointerType);
}
}
// extern int a[];
// int a[1];
public void testIncompleteArrays_269926() throws Exception {
final String code = getAboveComment();
parseAndCheckBindings(code, ParserLanguage.C);
parseAndCheckBindings(code, ParserLanguage.CPP);
}
}

View file

@ -19,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
@ -145,4 +146,22 @@ public class ASTQueries {
return false;
return type1.isSameType(type2);
}
protected static IType isCompatibleArray(IType t1, IType t2) {
if (t1 instanceof IArrayType && t2 instanceof IArrayType) {
IArrayType a1 = (IArrayType) t1;
IArrayType a2 = (IArrayType) t2;
if (!isSameType(a1.getType(), a2.getType())) {
return null;
}
if (a1.getSize() == null) {
if (a2.getSize() != null) {
return a2;
}
} else if (a2.getSize() == null) {
return a1;
}
}
return null;
}
}

View file

@ -780,7 +780,8 @@ public class CVisitor extends ASTQueries {
t2 = ((IVariable)binding).getType();
} catch (DOMException e1) {
}
if (t1 != null && t2 != null && t1.isSameType(t2)) {
if (t1 != null && t2 != null && (
t1.isSameType(t2) || isCompatibleArray(t1, t2) != null)) {
if (binding instanceof CVariable)
((CVariable)binding).addDeclaration(name);
} else {

View file

@ -686,24 +686,6 @@ public class CPPVisitor extends ASTQueries {
return binding;
}
private static IType isCompatibleArray(IType t1, IType t2) {
if (t1 instanceof IArrayType && t2 instanceof IArrayType) {
IArrayType a1 = (IArrayType) t1;
IArrayType a2 = (IArrayType) t2;
if (!isSameType(a1.getType(), a2.getType())) {
return null;
}
if (a1.getSize() == null) {
if (a2.getSize() != null) {
return a2;
}
} else if (a2.getSize() == null) {
return a1;
}
}
return null;
}
public static boolean isConstructor(IScope containingScope, IASTDeclarator declarator) {
if (containingScope == null || !(containingScope instanceof ICPPClassScope))
return false;