Skip to content

Commit d0cd4bb

Browse files
authored
Add variably modified typeof regression tests [EDGcpfe/28891]
1 parent 296fd2a commit d0cd4bb

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//type:rp
2+
//options_all:--c --c11 --no_strict_gnu --gnu_version=130300
3+
int main(void) {
4+
int k = 1, a[8], fails = 0;
5+
typeof (++k, (int (*)[k])a) p;
6+
(void)sizeof(p);
7+
fails += k != 2;
8+
// Each declarator evaluates the type specifier once.
9+
typeof (++k, (int (*)[k])a) q, r;
10+
(void)sizeof(q); (void)sizeof(r);
11+
fails += k != 4;
12+
typedef typeof (++k, (int (*)[k])a) T;
13+
fails += k != 5;
14+
T t;
15+
(void)sizeof(t);
16+
fails += k != 5; // A typedef use must not repeat its defining expression.
17+
typeof (++k, (int*)a) ordinary;
18+
(void)sizeof(ordinary);
19+
fails += k != 5; // A non-variably-modified operand is unevaluated.
20+
(void)(typeof (++k, (int (*)[k])a))a;
21+
fails += k != 6;
22+
(void)sizeof(typeof (++k, (int (*)[k])a));
23+
// sizeof a pointer does not require evaluating its variably modified type.
24+
// GNU C is permitted to omit that evaluation, so do not constrain k here.
25+
return fails;
26+
}

0 commit comments

Comments
 (0)