Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Opaque cpp.PointerType can't be stored in a class field

Đang mở
#1,447 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@Aidan63 đang làm issue này rồi.

Từ ngày 31/10/2026.

  • #1449 của @Aidan63 — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
52/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cpp
Lĩnh vực
backend

Hướng nghiên cứu

Start with the Main.hx reproducer and build it using haxe --main Main --cpp bin -D HXCPP_CPP17; compare the generated Holder.cpp field and constructor assignment shown in the issue. Trace the conversion that instantiates Boxed_obj<Opaque>; done means the forward-declared pointer can be stored in Holder and the build succeeds.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

A @:cpp.PointerType extern for a struct that is only forward-declared, such as SDL_Window, can be held in a local variable, but storing it in a class field fails to compile.

opaque.h:

#pragma once
struct Opaque;
Opaque* opaque_create();

Main.hx:

@:semantics(value)
@:include("opaque.h")
@:cpp.PointerType({ type : "Opaque" })
extern class Opaque {}

@:include("opaque.h")
extern class OpaqueApi {
	@:native("opaque_create")
	static function create():Opaque;
}

class Holder {
	public final opaque:Opaque;

	public function new(opaque) {
		this.opaque = opaque;
	}
}

@:buildXml("<files id='haxe'><compilerflag value='-I${this_dir}/..'/></files>")
@:cppFileCode("Opaque* opaque_create() { return nullptr; }")
class Main {
	static function main() {
		new Holder(OpaqueApi.create());
	}
}

Building with haxe --main Main --cpp bin -D HXCPP_CPP17 fails in Holder.cpp:

include\cpp\marshal\Definitions.inc(22): error C2079: 'cpp::marshal::Boxed_obj<T>::value' uses undefined struct 'Opaque'

Without Holder, keeping the value in a local variable in main, it compiles and runs.

The generated field looks right:

::cpp::marshal::Boxed< ::Opaque* > opaque;

The constructor assigns it like this:

this->opaque = ( (::cpp::marshal::PointerReference< ::Opaque >)(opaque) );

Somewhere in that conversion, Boxed_obj<Opaque> gets instantiated, which boxes the struct itself rather than the pointer. That can't work for a struct without a definition.

Tested on Windows with MSVC, Haxe 5.0.0-preview.1+8e58a1d10d and hxcpp master (0f1615ff).

🤖 Generated with Claude Code

Ngôn ngữ chính
C++
Star
330
Fork
233
Merge trung bình
8 giờ 57 phút
Pull request đã merge (30 ngày)
12

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của HaxeFoundation/hxcpp

Tất cả issue của HaxeFoundation/hxcpp

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.