digitalmars.D.learn - CTFE and RTFE results differ (aliasing)
- kdevel (33/33) May 05 ```d
- monkyyy (44/45) May 05 even worse:
- Steven Schveighoffer (3/11) May 05 This is a bug, please report it.
- kdevel (3/13) May 06 I would like to yield to someone with a GH account.
- kdevel (5/19) May 12 When I put `shared` in front of that definition the unittest
```d // // bs3.d // 2025-05-05 stvo // // $ dmd -g -checkaction=context -unittest -main -run bs3.d // bs3.d(25): [unittest] [4, 3, 3, 4] != [4, 3, 2, 1] // 1/1 modules FAILED unittests // auto foo (ubyte [4] s) { auto u = s; ubyte [4] tmp = u; u[0] = tmp [3]; u[1] = tmp [2]; u[2] = tmp [1]; u[3] = tmp [0]; return u; } unittest { enum ubyte [4] u = [1,2,3,4]; enum r = foo (u); auto s = foo (u); assert (r == s); } ``` According to the spec [1] the above code conforms to the CTFE restrictions and contains no pointers. It also does not contain "implementation defined behavior". Thus the result of CTFE and RTFE should be identical but they differ. Suggestions appreciated! [1] https://dlang.org/spec/function.html#interpretation 20.22 Compile Time Function Execution (CTFE)
May 05
On Monday, 5 May 2025 at 17:15:57 UTC, kdevel wrote:even worse: ```d auto foo(ubyte[4] s){ ubyte[] u = s; ubyte[4] tmp = u; u[0] = tmp[3]; u[3] = tmp[0]; return u; } unittest{ import std; enum ubyte[4] u = [1, 2, 3, 4]; enum r = foo(u); auto s = foo(u); r.writeln; s.writeln; assert(r!=s); } ``` ``` 2.105.3: Success with output: ----- 1 modules passed unittests [1, 2, 3, 4] [4, 2, 3, 1] [216, 88, 171, 59] ----- 2.106.1: Success with output: ----- 1 modules passed unittests [1, 2, 3, 4] [4, 2, 3, 1] [136, 48, 143, 115] ----- Since 2.107.0: Success with output: ----- 1 modules passed unittests [1, 2, 3, 4] [4, 2, 3, 1] [56, 227, 42, 198] ----- ``` what fun
May 05
On Monday, 5 May 2025 at 17:15:57 UTC, kdevel wrote:```d // // bs3.d // 2025-05-05 stvo // // $ dmd -g -checkaction=context -unittest -main -run bs3.d // bs3.d(25): [unittest] [4, 3, 3, 4] != [4, 3, 2, 1] ```This is a bug, please report it. -Steve
May 05
On Tuesday, 6 May 2025 at 01:29:35 UTC, Steven Schveighoffer wrote:On Monday, 5 May 2025 at 17:15:57 UTC, kdevel wrote:I would like to yield to someone with a GH account.```d // // bs3.d // 2025-05-05 stvo // // $ dmd -g -checkaction=context -unittest -main -run bs3.d // bs3.d(25): [unittest] [4, 3, 3, 4] != [4, 3, 2, 1] ```This is a bug, please report it.
May 06
On Monday, 5 May 2025 at 17:15:57 UTC, kdevel wrote:``` auto foo (ubyte [4] s) { auto u = s; ubyte [4] tmp = u; ```When I put `shared` in front of that definition the unittest passes.``` u[0] = tmp [3]; u[1] = tmp [2]; u[2] = tmp [1]; u[3] = tmp [0]; return u; } ```I appreciate if sb. with a GH account could file the issue with the original code as bug.
May 12