Skip to content

Commit de31f6b

Browse files
committed
Add test case for compound literals dacay
Add two regression tests to ensure correct handling of compound array literals in initializer context and when passed as pointer arguments. The tests cover: - decay of an int[] compound literal to int* during initialization - passing an int[] compound literal to a function expecting int*
1 parent 9322389 commit de31f6b

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
@@ -733,6 +733,28 @@ int main() {
733733
}
734734
EOF
735735

736+
# Test: Array compound literal decay to pointer in initializer
737+
try_ 0 << EOF
738+
int main(void) {
739+
int *arr = (int[]){1, 2, 3, 4, 5};
740+
return arr[0] != 1 || arr[4] != 5;
741+
}
742+
EOF
743+
744+
# Test: Passing array compound literal as pointer argument
745+
try_ 0 << EOF
746+
int sum(int *p, int n) {
747+
int s = 0;
748+
for (int i = 0; i < n; i++)
749+
s += p[i];
750+
return s;
751+
}
752+
int main(void) {
753+
int s = sum((int[]){1, 2, 3, 0, 0}, 3);
754+
return s != 6;
755+
}
756+
EOF
757+
736758
# Test: Complex expression with compound literals
737759
try_ 77 << EOF
738760
int main() {

0 commit comments

Comments
 (0)