1 /* { dg-options "-Wunused-variable" } */
2 
3 /* Verify that ignoring -Wunused-variable works, for various placements
4    of the variable and the _Pragma.  */
5 
6 /* Test 1: the _Pragma is in a macro, but the affected code isn't.  */
7 
8 #pragma GCC diagnostic push
9 
10 #define MACRO_1 \
11     _Pragma("GCC diagnostic ignored \"-Wunused-variable\"")
12 
test_1()13 int test_1()
14 {
15     _Pragma("GCC diagnostic ignored \"-Wunused-variable\"")
16     int x;
17     return 0;
18 }
19 #pragma GCC diagnostic pop
20 
21 
22 /* Test 2: neither the _Pragma nor the affected code are in a macro.  */
23 
24 #pragma GCC diagnostic push
test_2()25 int test_2()
26 {
27     _Pragma("GCC diagnostic ignored \"-Wunused-variable\"")
28     int x;
29     return 0;
30 }
31 #pragma GCC diagnostic pop
32 
33 
34 /* Test 3: the _Pragma isn't in a macro, but the affected code is.  */
35 
36 #define MACRO_3 \
37     int x;
38 
39 #pragma GCC diagnostic push
test_3()40 int test_3()
41 {
42     _Pragma("GCC diagnostic ignored \"-Wunused-variable\"")
43     MACRO_3
44     return 0;
45 }
46 #pragma GCC diagnostic pop
47 
48 
49 /* Test 4: the _Pragma and the affected code are in different macros.  */
50 
51 #pragma GCC diagnostic push
52 #define MACRO_4A \
53     _Pragma("GCC diagnostic ignored \"-Wunused-variable\"")
54 
55 #define MACRO_4B \
56     int x;
57 
test_4()58 int test_4()
59 {
60     MACRO_4A;
61     MACRO_4B
62     return 0;
63 }
64 #pragma GCC diagnostic pop
65 
66 
67 /* Test 5: both the _Pragma and the affected code are in the same macro.  */
68 
69 #pragma GCC diagnostic push
70 #define MACRO_5 \
71     _Pragma("GCC diagnostic ignored \"-Wunused-variable\"") \
72     int x;
73 
test_5()74 int test_5()
75 {
76     MACRO_5;
77     return 0;
78 }
79 #pragma GCC diagnostic pop
80