aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/c23-static-assert-7.c
blob: 9c35353be82e0d18fd14890c008f49f53c71ba80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* Test C2y static assertions in expressions: -Wc23-c2y-compat warnings for
   C23.  */
/* { dg-do compile } */
/* { dg-options "-std=c23 -Wc23-c2y-compat" } */

/* Old forms of static assertion still valid.  */
static_assert (1);
static_assert (2, "message" );
struct s { int a; static_assert (3); };

void
f ()
{
  static_assert (4);
 label:
  static_assert (5);
  for (static_assert (6);;)
    ;
}

/* Test new forms of static assertion.  */
void
g ()
{
  (void) 0, static_assert (7), (void) 0; /* { dg-warning "ISO C does not support static assertions in expressions before C2Y" } */
  extern typeof (static_assert (8)) f (); /* { dg-warning "ISO C does not support static assertions in expressions before C2Y" } */
  1
    ? static_assert (9) /* { dg-warning "ISO C does not support static assertions in expressions before C2Y" } */
    : static_assert (10); /* { dg-warning "ISO C does not support static assertions in expressions before C2Y" } */
  if (1)
    static_assert (11); /* { dg-warning "ISO C does not support static assertions in expressions before C2Y" } */
  else
    static_assert (12); /* { dg-warning "ISO C does not support static assertions in expressions before C2Y" } */
  for (;;)
    static_assert (13); /* { dg-warning "ISO C does not support static assertions in expressions before C2Y" } */
  while (true)
    static_assert (14); /* { dg-warning "ISO C does not support static assertions in expressions before C2Y" } */
  do
    static_assert (15); /* { dg-warning "ISO C does not support static assertions in expressions before C2Y" } */
  while (false);
  switch (16)
    static_assert (17); /* { dg-warning "ISO C does not support static assertions in expressions before C2Y" } */
  (void) static_assert (18); /* { dg-warning "ISO C does not support static assertions in expressions before C2Y" } */
  (static_assert (19)); /* { dg-warning "ISO C does not support static assertions in expressions before C2Y" } */
}

void
g2 ()
{
  (void) 0, static_assert (7, "message"), (void) 0; /* { dg-warning "ISO C does not support static assertions in expressions before C2Y" } */
  extern typeof (static_assert (8, "message")) f (); /* { dg-warning "ISO C does not support static assertions in expressions before C2Y" } */
  1
    ? static_assert (9, "message") /* { dg-warning "ISO C does not support static assertions in expressions before C2Y" } */
    : static_assert (10, "message"); /* { dg-warning "ISO C does not support static assertions in expressions before C2Y" } */
  if (1)
    static_assert (11, "message"); /* { dg-warning "ISO C does not support static assertions in expressions before C2Y" } */
  else
    static_assert (12, "message"); /* { dg-warning "ISO C does not support static assertions in expressions before C2Y" } */
  for (;;)
    static_assert (13, "message"); /* { dg-warning "ISO C does not support static assertions in expressions before C2Y" } */
  while (true)
    static_assert (14, "message"); /* { dg-warning "ISO C does not support static assertions in expressions before C2Y" } */
  do
    static_assert (15, "message"); /* { dg-warning "ISO C does not support static assertions in expressions before C2Y" } */
  while (false);
  switch (16)
    static_assert (17, "message"); /* { dg-warning "ISO C does not support static assertions in expressions before C2Y" } */
  (void) static_assert (18, "message"); /* { dg-warning "ISO C does not support static assertions in expressions before C2Y" } */
  (static_assert (19, "message")); /* { dg-warning "ISO C does not support static assertions in expressions before C2Y" } */
}