From 7729f6cf4edd7c8eda935b1c7c8b4276d73b6e69 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 29 Nov 2017 21:50:38 -0500 Subject: [PATCH] translate-c: support static incomplete array inside function --- src/translate_c.cpp | 16 ++++++++++++++-- test/translate_c.zig | 10 ++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/translate_c.cpp b/src/translate_c.cpp index f5c1ef5810..f89444a5ee 100644 --- a/src/translate_c.cpp +++ b/src/translate_c.cpp @@ -976,11 +976,23 @@ static AstNode *trans_type(Context *c, const Type *ty, const SourceLocation &sou const AttributedType *attributed_ty = static_cast(ty); return trans_qual_type(c, attributed_ty->getEquivalentType(), source_loc); } + case Type::IncompleteArray: + { + const IncompleteArrayType *incomplete_array_ty = static_cast(ty); + QualType child_qt = incomplete_array_ty->getElementType(); + AstNode *child_type_node = trans_qual_type(c, child_qt, source_loc); + if (child_type_node == nullptr) { + emit_warning(c, source_loc, "unresolved array element type"); + return nullptr; + } + AstNode *pointer_node = trans_create_node_addr_of(c, child_qt.isConstQualified(), + child_qt.isVolatileQualified(), child_type_node); + return pointer_node; + } case Type::BlockPointer: case Type::LValueReference: case Type::RValueReference: case Type::MemberPointer: - case Type::IncompleteArray: case Type::VariableArray: case Type::DependentSizedArray: case Type::DependentSizedExtVector: @@ -4301,7 +4313,7 @@ int parse_h_file(ImportTableEntry *import, ZigList *errors, const ch } } - return 0; + return ErrorUnexpected; } c->ctx = &ast_unit->getASTContext(); diff --git a/test/translate_c.zig b/test/translate_c.zig index 90b99b5faf..d4974109da 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -1178,4 +1178,14 @@ pub fn addCases(cases: &tests.TranslateCContext) { , \\pub var v0: ?&const u8 = c"0.0.0"; ); + + cases.add("static incomplete array inside function", + \\void foo(void) { + \\ static const char v2[] = "2.2.2"; + \\} + , + \\pub fn foo() { + \\ const v2: &const u8 = c"2.2.2"; + \\} + ); }