Skip to content

Commit 272c912

Browse files
committed
add: test case for array compound literals
1 parent d6b9fbf commit 272c912

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/driver.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,28 @@ int main() {
724724
}
725725
EOF
726726

727+
# Test: Array compound literal decay to pointer in initializer
728+
try_ 0 << EOF
729+
int main(void) {
730+
int *arr = (int[]){1, 2, 3, 4, 5};
731+
return arr[0] != 1 || arr[4] != 5;
732+
}
733+
EOF
734+
735+
# Test: Passing array compound literal as pointer argument
736+
try_ 0 << EOF
737+
int sum(int *p, int n) {
738+
int s = 0;
739+
for (int i = 0; i < n; i++)
740+
s += p[i];
741+
return s;
742+
}
743+
int main(void) {
744+
int s = sum((int[]){1, 2, 3, 0, 0}, 3);
745+
return s != 6;
746+
}
747+
EOF
748+
727749
# Test: Complex expression with compound literals
728750
try_ 77 << EOF
729751
int main() {

0 commit comments

Comments
 (0)