Skip to content

Commit

Permalink
Add support for enum forward declarations
Browse files Browse the repository at this point in the history
These will otherwise create duplicate bindings.
  • Loading branch information
JamesWrigley committed Jun 9, 2024
1 parent b1c62fa commit 3d8244d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/CodeTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2121,7 +2121,7 @@ bool CodeTree::add_type_specialization(TypeRcd* pTypeRcd, const CXType& type){
bool CodeTree::isAForwardDeclaration(CXCursor cursor) const{
const auto& kind = clang_getCursorKind(cursor);

auto rc = (kind == CXCursor_ClassDecl || kind == CXCursor_StructDecl)
auto rc = (kind == CXCursor_ClassDecl || kind == CXCursor_StructDecl || kind == CXCursor_EnumDecl)
&& !clang_equalCursors(clang_getCursorDefinition(cursor), cursor);

const auto& special = clang_getSpecializedCursorTemplate(cursor);
Expand Down Expand Up @@ -2234,7 +2234,7 @@ CXChildVisitResult CodeTree::visit(CXCursor cursor, CXCursor parent,
tree.visit_class(cursor);
} else if(kind == CXCursor_FunctionDecl){
tree.visit_global_function(cursor);
} else if(kind == CXCursor_EnumDecl){
} else if(kind == CXCursor_EnumDecl && !tree.isAForwardDeclaration(cursor)){
tree.visit_enum(cursor);
} else if(kind == CXCursor_TypedefDecl){
// tree.visit_typedef(cursor);
Expand Down
9 changes: 9 additions & 0 deletions test/TestEnum/A.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,12 @@ enum E {
E1 = 5,
E2 = 6
};

// Only the definition should create a binding, otherwise a duplicate will be
// created for the forward declaration which will cause an error during
// precompilation.
enum ForwardDecl : int;
enum ForwardDecl : int {
X = 1,
Y = 2
};

0 comments on commit 3d8244d

Please sign in to comment.