From 537f9ed45ac9f1a3f99c22dc58be8c0785ee81d3 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Fri, 21 Aug 2009 13:29:04 +0000 Subject: [PATCH] Checking for compatible arrays in plain C, follow up to bug 269926. --- .../cdt/core/parser/tests/ast2/AST2Tests.java | 8 ++++++++ .../internal/core/dom/parser/ASTQueries.java | 19 +++++++++++++++++++ .../internal/core/dom/parser/c/CVisitor.java | 3 ++- .../dom/parser/cpp/semantics/CPPVisitor.java | 18 ------------------ 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index 042883d917a..e0446f12fb1 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -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); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTQueries.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTQueries.java index c0f4b88d6d6..74f602a2cfe 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTQueries.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTQueries.java @@ -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; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java index 99a4118ebd4..79fbe0414a1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java @@ -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 { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java index 14e3910fca9..1aef4b0ef26 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java @@ -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;