summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/pragma-diag-3.c
blob: b6ee60f16770924a1e882f10b0c9376ff040c568 (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
/* { dg-do compile } */
/* { dg-options "-Wswitch-enum -Wsign-compare -fstrict-overflow -Wstrict-overflow -Werror -Wno-error=switch-enum" } */
/* PR c/66098 - #pragma diagnostic 'ignored' not fully undone by pop for strict-overflow 
   PR c/66711 - GCC does not correctly restore diagnostic state after pragma GCC diagnostic pop with -Werror 
*/
/* { dg-message "warnings being treated as errors" "" {target "*-*-*"} 0 } */

void testing2() {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-overflow"
  int j = 4;
  j + 4 < j;
#pragma GCC diagnostic pop
}

void testing3() {
  int k = 4;
  k + 4 < k; /* { dg-error "overflow" "" { xfail *-*-* } } */
}

int bar()
{
  unsigned x = 0;
  int y = 1;

  /* generates an error - ok */
  x += x < y ? 1 : 0; /* { dg-error "comparison" } */

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-compare"
  /* generates no diagnostic - ok */
  x += x < y ? 1 : 0;
#pragma GCC diagnostic pop

  x += x < y ? 1 : 0; /* { dg-error "comparison" } */

  return x;
}

enum EE { ONE, TWO };

int f (enum EE e)
{
  int r = 0;

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch-enum"

  switch (e)
    {
    case ONE:
      r = 1;
      break;
    }
#pragma GCC diagnostic pop

  switch (e) /* { dg-warning "switch" } */
    {
    case ONE:
      r = 1;
      break;
    }
  return r;
}