HaxeFoundation / HaxeFoundation/haxe
[cpp] Invalid code generated from `Int` to `cpp.Star<Int>` cast
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
```haxe
function main() {
final a:Int = 10;
final b:cpp.Star = 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:
```haxe
function main() {
final a:cpp.Star = 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 = hl.Ref.make(10);
| ^^
| Ref should be a local variable
```
Contributor guide
Assessment
This issue has not been assessed yet.