Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion c2rust-ast-exporter/src/AstExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2625,11 +2625,20 @@ class TranslateASTVisitor final

void TypeEncoder::VisitEnumType(const EnumType *T) {
auto ed = T->getDecl()->getDefinition();

// getDefinition can return NULL if there is only a forward declaration like `enum Foo;`
// Forward declarations of enums are not actually allowed by the C standard,
// but are supported by LLVM and are used in real code, see
// https://github.com/immunant/c2rust/pull/1743#discussion_r3120875668
if (!ed) {
ed = T->getDecl()->getCanonicalDecl();
Comment thread
ahomescu marked this conversation as resolved.
}

encodeType(T, TagEnumType, [T, ed](CborEncoder *local) {
cbor_encode_uint(local, uintptr_t(ed));
});

if (ed != nullptr) astEncoder->TraverseDecl(ed);
astEncoder->TraverseDecl(ed);
}

void TypeEncoder::VisitRecordType(const RecordType *T) {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/enums/src/enum_fwd_decl.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ struct _Evas_Func
};

// dummy item imported by `test_enums.rs`
int foo(int i) { return i;}
struct _Evas_Func foo(struct _Evas_Func i) { return i;}
Comment thread
ahomescu marked this conversation as resolved.
Loading