Thread overview
CTFE and RTFE results differ (aliasing)
12 hours ago
kdevel
11 hours ago
monkyyy
12 hours ago
//
// 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)

11 hours ago

On Monday, 5 May 2025 at 17:15:57 UTC, kdevel wrote:

>

even worse:

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

4 hours ago

On Monday, 5 May 2025 at 17:15:57 UTC, kdevel wrote:

>
//
// 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