This commit is contained in:
ringabout
2026-05-20 20:19:23 +08:00
parent 4d77a1d9fc
commit 8fb0023f46
3 changed files with 11 additions and 19 deletions

7
tests/ccgbugs2/m25800.h Normal file
View File

@@ -0,0 +1,7 @@
/*TYPESECTION*/
struct CppRef {
int* data;
CppRef() : data(new int(42)) {}
~CppRef() { delete data; data = nullptr; }
void reset() { delete data; data = nullptr; }
};

View File

@@ -4,16 +4,9 @@ discard """
"""
# Bug Report 1: {.importcpp.} on =wasMoved generates invalid preprocessor directive #.
{.emit: """/*TYPESECTION*/
struct CppRef {
int* data;
CppRef() : data(new int(42)) {}
~CppRef() { delete data; data = nullptr; }
void reset() { delete data; data = nullptr; }
};
""".}
type CppRef* {.importcpp, bycopy, noInit.} = object
type CppRef* {.importcpp, bycopy, noInit, header: "m25800.h".} = object
proc `=destroy`(x: var CppRef) {.importcpp: "#.~CppRef()".}
proc `=wasMoved`(x: var CppRef) {.importcpp: "#.reset()".}