diff options
Diffstat (limited to 'core')
2 files changed, 38 insertions, 9 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 637cc029c5f..f02b4d91c82 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 @@ -6392,4 +6392,19 @@ public class AST2Tests extends AST2BaseTest { } } + + // /* Check that a parameter declared as a typedef'd array + // * is treated as a pointer + // */ + //typedef int my_buf[16]; + //void goo(my_buf in); + // + public void testBug284248() throws Exception { + for(ParserLanguage lang : ParserLanguage.values()) { + IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), lang); + assertTrue(tu.isFrozen()); + IASTName n = ((IASTSimpleDeclaration)tu.getDeclarations()[1]).getDeclarators()[0].getName(); + assertTrue(((IFunction)n.resolveBinding()).getType().getParameterTypes()[0] instanceof IPointerType); + } + } } 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 9d69b3178c6..1d74d813561 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 @@ -51,6 +51,7 @@ import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.IArrayType; import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; @@ -1281,22 +1282,35 @@ public class CVisitor extends ASTQueries { if (isParameter) { + IType paramType = type; + // Remove typedefs ready for subsequent processing. + while (paramType instanceof ITypedef) { + try { + paramType = ((ITypedef)paramType).getType(); + } catch (DOMException e) { + paramType= null; + } + } + //C99: 6.7.5.3-7 a declaration of a parameter as "array of type" shall be adjusted to "qualified pointer to type", where the //type qualifiers (if any) are those specified within the[and] of the array type derivation - if (type instanceof ICArrayType) { - ICArrayType at = (ICArrayType) type; - try { + if (paramType instanceof IArrayType) { // the index does not yet return ICArrayTypes + IArrayType at = (IArrayType) paramType; + try { int q= 0; - if (at.isConst()) q |= CPointerType.IS_CONST; - if (at.isVolatile()) q |= CPointerType.IS_VOLATILE; - if (at.isRestrict()) q |= CPointerType.IS_RESTRICT; + if (at instanceof ICArrayType) { + ICArrayType cat= (ICArrayType) at; + if (cat.isConst()) q |= CPointerType.IS_CONST; + if (cat.isVolatile()) q |= CPointerType.IS_VOLATILE; + if (cat.isRestrict()) q |= CPointerType.IS_RESTRICT; + } type = new CPointerType(at.getType(), q); } catch (DOMException e) { - // stick to the array + // ignore the qualifiers } - } else if (type instanceof IFunctionType) { + } else if (paramType instanceof IFunctionType) { //-8 A declaration of a parameter as "function returning type" shall be adjusted to "pointer to function returning type" - type = new CPointerType(type, 0); + type = new CPointerType(paramType, 0); } } |