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
9 changes: 9 additions & 0 deletions cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/goplus/gogen"
"github.com/goplus/llcppg/clang"
lc "github.com/llarhub/clang-c"
)

const (
Expand Down Expand Up @@ -286,6 +287,14 @@ func loadFiles(ctx *pkgCtx, files []Source, myPkgPath string, goFileOf func(head
clang.VisitChildren(f.Cursor(), func(decl, parent clang.Cursor) clang.ChildVisitResult {
if pkgOf != nil {
at := clang.PresumedFile(decl.Location())
switch decl.Kind {
case lc.Cursor_ClassDecl, lc.Cursor_StructDecl:
Comment on lines +290 to +291

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.

[P2] Same forward-decl misattribution likely applies to enum/union

This switch only special-cases Cursor_ClassDecl/Cursor_StructDecl. Enum and union declarations short-circuit on the exact same condition elsewhere (enum.go:65 and union.go:67 both do if decl.IsCursorDefinition() == 0 { return }), so an enum/union forward-declared in file A and defined in file B can be attributed to the wrong file by the same mechanism this PR fixes for class/struct. Enum forward declarations with a fixed underlying type (enum E : int;) are legal and common C++11.

If the broader fix is intended, consider also handling lc.Cursor_EnumDecl (and lc.Cursor_UnionDecl). If class/struct is the deliberate scope, a short comment explaining why would prevent a future reader from assuming it was an oversight. (Typedefs are correctly excluded — they are not a forward/definition pair.)

if decl.IsCursorDefinition() == 0 {
if definition := decl.Definition(); definition.IsNull() == 0 {
Comment thread
xushiwei marked this conversation as resolved.
at = clang.PresumedFile(definition.Location())
}
}
}
if _, ok := lastSeen[at]; ok {
return clang.Continue // already loaded
}
Expand Down
9 changes: 7 additions & 2 deletions tool/_testc/python-3.14.8/cpython-pythread.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions tool/_testc/python-3.14.8/pythread.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading