Skip to content

Commit 4788e86

Browse files
committed
Add regression tests for compound literal pointers
Four regression tests were added under the “Compound Literals” section in `tests/driver.sh` The tests cover: - char[] compound literal assigned to char* (sum = 200) - short[] compound literal assigned to short* (sum = 6) - ternary returning int* with literal in the false branch (true case) - ternary returning int* selecting the literal branch (false case)
1 parent fc3ded6 commit 4788e86

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/driver.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4743,6 +4743,36 @@ int main() {
47434743
}
47444744
EOF
47454745

4746+
try_ 200 << EOF
4747+
int main(void) {
4748+
char *s = (char[]){'A', 'B', 'C', 'D', 'E'};
4749+
return s[0] + s[1] + s[4]; /* 65 + 66 + 69 */
4750+
}
4751+
EOF
4752+
4753+
try_ 6 << EOF
4754+
int main(void) {
4755+
short *s = (short[]){1, 2, 3, 4, 5};
4756+
return s[0] + s[4];
4757+
}
4758+
EOF
4759+
4760+
try_ 60 << EOF
4761+
int main(void) {
4762+
int arr[] = {10, 20, 30, 40, 50};
4763+
int *selected = 1 ? arr : (int[]){1, 2, 3, 4, 5};
4764+
return selected[0] + selected[4];
4765+
}
4766+
EOF
4767+
4768+
try_ 6 << EOF
4769+
int main(void) {
4770+
int arr[] = {10, 20, 30, 40, 50};
4771+
int *selected = 0 ? arr : (int[]){1, 2, 3, 4, 5};
4772+
return selected[0] + selected[4];
4773+
}
4774+
EOF
4775+
47464776
try_ 120 << EOF
47474777
int main() {
47484778
/* Complex expression with mixed compound literals */

0 commit comments

Comments
 (0)