Files
2026-10-17 21:57:03 +08:00

27 lines
818 B
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from stdint import *
import win32.win32console
import stdlib
# =============================================================================
# 负向工程(**应当编译失败**,对照工程:NewLifetimeTest)
#
# §4.3 判据 5:`slife` 对象由编译器独占释放 —— 禁止手动 free。
# 理由:出口已经会自动 free 一次,再手动 free 就是 double-free。
# 期望报错:LifetimeError。
# =============================================================================
novirtual class Point:
x: int
y: int
export def main() -> int:
win32.win32console.SetConsoleCP(65001)
win32.win32console.SetConsoleOutputCP(65001)
p: Point* = new heap slife Point(1, 2)
stdlib.free(p) # ← 必须被拒:slife 由编译器在函数出口释放
return 0