Skip to content
Open
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
9 changes: 8 additions & 1 deletion c2rust-ast-exporter/src/AstExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2625,11 +2625,18 @@ 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;`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth elaborating a bit on what's going on here: we're seeing a forward declaration of an enum which the C standard theoretically forbids, but both our test code and its upstream source at https://github.com/Enlightenment/efl/blob/master/src/lib/evas/include/evas_private.h#L77 do it anyway.

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