summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/pr46921.c
blob: 17dfedd7e0a272dcc81666986310efdb0b9bde79 (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
/* PR c/46921  lost side effect when struct initializer expr uses comma
      operator  */

/* { dg-do run } */
/* { dg-options "" } */

extern int printf(const char *, ...);
extern void abort (void);

typedef struct __uws_0 { } uw_unit;
uw_unit uw_unit_v = {};

struct __uws_1 
{
  struct __uws_0 __uwf_1;
  struct __uws_1* __uwf_2;
};

static int left_hand_eval = 0;

static void
foo (const char *s)
{
  ++left_hand_eval;
  printf("%s", s);
}

int
main ()
{
  struct __uws_1 tmp = {(foo("Inner\n"), uw_unit_v)};
  
  printf("Outer\n");
  /* left hand expression in comma operator initializer must always be
     evaluated if there are side effects.  */
  if (!left_hand_eval)
    abort ();
  
  return 0;
}