Skip to content

Commit

Permalink
Add test case for taking the address of array literal elements (#16785)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorpel authored Aug 19, 2024
1 parent 0cd8dcf commit 2ac9a69
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions compiler/test/runnable/nogc.d
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,37 @@ void test12936() @nogc

/***********************/

version(none) // Pending future enhancements:
void testIndexedArrayLiteral() @nogc
{
int i = 2;
int x = [10, 20, 30, 40][i];
assert(x == 30);

enum arr = [100, 200, 300, 400][1 .. $];
assert(arr[i] == 400);
}

void testArrayLiteralLvalue()
{
// https://github.com/dlang/dmd/pull/16784
// Test that this array literal is *not* put on the stack because
// it gets its address taken
static int* getPtr(int i) => &[1, 2, 3][i];
int* x = getPtr(1);
int* y = getPtr(1);
assert(x != y);
}

/***********************/

int main()
{
test1();
test3032();
test12642();
test12936();
testArrayLiteralLvalue();

printf("Success\n");
return 0;
Expand Down

0 comments on commit 2ac9a69

Please sign in to comment.