1 /* { dg-do compile } */
2 /* { dg-options "-Wswitch-enum -Wsign-compare -fstrict-overflow -Wstrict-overflow -Werror -Wno-error=switch-enum" } */
3 /* PR c/66098 - #pragma diagnostic 'ignored' not fully undone by pop for strict-overflow
4    PR c/66711 - GCC does not correctly restore diagnostic state after pragma GCC diagnostic pop with -Werror
5 */
6 /* { dg-message "warnings being treated as errors" "" {target "*-*-*"} 0 } */
7 
testing2()8 void testing2() {
9 #pragma GCC diagnostic push
10 #pragma GCC diagnostic ignored "-Wstrict-overflow"
11   int j = 4;
12   j + 4 < j;
13 #pragma GCC diagnostic pop
14 }
15 
testing3()16 void testing3() {
17   int k = 4;
18   k + 4 < k; /* { dg-error "overflow" } */
19 }
20 
bar()21 int bar()
22 {
23   unsigned x = 0;
24   int y = 1;
25 
26   /* generates an error - ok */
27   x += x < y ? 1 : 0; /* { dg-error "comparison" } */
28 
29 #pragma GCC diagnostic push
30 #pragma GCC diagnostic ignored "-Wsign-compare"
31   /* generates no diagnostic - ok */
32   x += x < y ? 1 : 0;
33 #pragma GCC diagnostic pop
34 
35   x += x < y ? 1 : 0; /* { dg-error "comparison" } */
36 
37   return x;
38 }
39 
40 enum EE { ONE, TWO };
41 
f(enum EE e)42 int f (enum EE e)
43 {
44   int r = 0;
45 
46 #pragma GCC diagnostic push
47 #pragma GCC diagnostic ignored "-Wswitch-enum"
48 
49   switch (e)
50     {
51     case ONE:
52       r = 1;
53       break;
54     }
55 #pragma GCC diagnostic pop
56 
57   switch (e) /* { dg-warning "switch" } */
58     {
59     case ONE:
60       r = 1;
61       break;
62     }
63   return r;
64 }
65