HaxeFoundation / HaxeFoundation/haxe

`cpp.Pointer` does not work when called from an expression with side-effects

Open
#6,154 4 comments 0 reactions 1 assignee Claimed by @Simn View on GitHub
bug haxe-foundation-partner platform-cpp
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

The code located at https://gist.github.com/waneck/3422d5c34bfd5985d3b4238654728cd3 now fails on 3.4.2 .

I think the culprit is https://github.com/HaxeFoundation/haxe/issues/5082#issuecomment-210392412 , since as you can see in the code, the following works without issues:

```rgb.ptr.setValues(2,3,4);```

while the following fails:
```rgb.ptr.setValues(getInt(), getInt(), getInt());```

It fails because Haxe tries to create a temporary variable of `cpp.Pointer#ptr` type, which doesn't work. This makes it generate the following bad code:

```HXLINE( 5) RGB * rgb1 = rgb->ptr;
HXDLIN( 5) int _hx_tmp = ::Main_obj::getInt();
HXDLIN( 5) int _hx_tmp1 = ::Main_obj::getInt();
HXDLIN( 5) (*(rgb1))->setValues(_hx_tmp,_hx_tmp1,::Main_obj::getInt());
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.