12.6.7.12 CPP0011 - 승격된 스택 전용 값 타입(Promoted Stack Only Value Type)

12.6.7.12 CPP0011 - 승격된 스택 전용 값 타입(Promoted Stack Only Value Type)

설명(Description)

cpp.ValueType으로 주석 처리되고 StackOnly 플래그를 포함하는 extern 클래스나 enum은 힙으로 승격되는 것이 금지됩니다. 타입이 조용히 힙으로 승격되는 방법은 여러 가지가 있으며, 다음 예제들은 몇 가지 경우를 보여줍니다.

예제(Examples)

다음 예제들은 CPP0011을 생성합니다.

@:semantics(value)
@:cpp.ValueType({ flags : [ StackOnly ] })
extern class Foo {
    function new():Void;
}

function main() {
    final f : Null<Foo> = new Foo(); // CPP0011, nullable value types are required to go on the heap.
}
@:semantics(value)
@:cpp.ValueType({ flags : [ StackOnly ] })
extern class Foo {
    function new():Void;
}

function main() {
    final f = new Foo(); // CPP0011, variables captured in a closure are required to go on the heap.
    final c = () -> {
        trace(f);
    }

    c();
}
@:semantics(value)
@:cpp.ValueType({ flags : [ StackOnly ] })
extern class Foo {
    function new():Void;
}

function bar(o:Dynamic) {
    trace(o);
}

function main() {
    final f = new Foo(); // CPP0011, converting a value type to Dynamic requires boxing it onto the heap.

    bar(f);
}
@:semantics(value)
@:cpp.ValueType({ flags : [ StackOnly ] })
extern class Foo {
    function new():Void;
}

class Bar {
    var f : Foo; // CPP0011, class fields of value types are required to be on the heap.

    public function new() {
        f = new Foo();
    }
}

function main() {
    final f = new Bar();
}

출처: CPP0011 - Promoted Stack Only Value Type

더 알아보기