Skip to content

[cpp] Invalid code generated from Int to cpp.Star<Int> cast #12458

@tobil4sk

Description

@tobil4sk
function main() {
	final a:Int = 10;
	final b:cpp.Star<Int> = a;
}
Error: ./src/_Main/Main_Fields_.cpp: In static member function ‘static void _Main::Main_Fields__obj::main()’:
./src/_Main/Main_Fields_.cpp:29:19: error: invalid conversion from ‘int’ to ‘int*’ [-fpermissive]
   29 |         int * b = a;
      |                   ^
      |                   |
      |                   int
./src/_Main/Main_Fields_.cpp:29:19: note: possible fix: take the address with ‘&’
   29 |         int * b = a;
      |                   ^
      |                   &

Also, code like this should not be permitted as you cannot get a pointer to temporary rvalue:

function main() {
	final a:cpp.Star<Int> = 10;
}

This should be handled similarly to #12457.

Also compare with a similar error on the hashlink target:

[ERROR] Test.hx:3: characters 41-43

 3 |     final ref:hl.Ref<Int> = hl.Ref.make(10);
   |                                         ^^
   | Ref should be a local variable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions