comparison gcc/testsuite/c-c++-common/Wduplicated-cond-3.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
1 /* PR c/64249 */
2 /* { dg-do compile } */
3 /* { dg-options "-Wall -Wno-duplicated-cond" } */
4
5 #ifndef __cplusplus
6 # define bool _Bool
7 # define true 1
8 # define false 0
9 #endif
10
11 extern int foo (void);
12
13 int
14 fn1 (int n)
15 {
16 if (n == 1)
17 return -1;
18 else if (n == 2)
19 return 0;
20 else if (n == 1)
21 return 1;
22 return 0;
23 }
24
25 int
26 fn2 (void)
27 {
28 if (4)
29 return 1;
30 else if (4)
31 return 2;
32
33 #define N 10
34 if (N)
35 return 3;
36 else if (N)
37 return 4;
38 }
39
40 int
41 fn3 (int n)
42 {
43 if (n == 42)
44 return 1;
45 if (n == 42)
46 return 2;
47
48 if (n)
49 if (n)
50 if (n)
51 if (n)
52 return 42;
53
54 if (!n)
55 return 10;
56 else
57 return 11;
58 }
59
60 int
61 fn4 (int n)
62 {
63 if (n > 0)
64 {
65 if (n == 1)
66 return 1;
67 else if (n == 1)
68 return 2;
69 }
70 else if (n < 0)
71 {
72 if (n < -1)
73 return 6;
74 else if (n < -2)
75 {
76 if (n == -10)
77 return 3;
78 else if (n == -10)
79 return 4;
80 }
81 }
82 else
83 return 7;
84 return 0;
85 }
86
87 struct S { long p, q; };
88
89 int
90 fn5 (struct S *s)
91 {
92 if (!s->p)
93 return 12345;
94 else if (!s->p)
95 return 1234;
96 return 0;
97 }
98
99 int
100 fn6 (int n)
101 {
102 if (n)
103 return n;
104 else if (n)
105 return n;
106 else if (n)
107 return n;
108 else if (n)
109 return n;
110 else if (n)
111 return n;
112 else if (n)
113 return n;
114 else if (n)
115 return n;
116 else if (n)
117 return n;
118 return 0;
119 }
120
121 int
122 fn7 (int n)
123 {
124 if (n == 0)
125 return 10;
126 else if (n == 1)
127 return 11;
128 else if (n == 2)
129 return 12;
130 else if (n == 3)
131 return 13;
132 else if (n == 4)
133 return 14;
134 else if (n == 5)
135 return 15;
136 else if (n == 6)
137 return 16;
138 else if (n == 7)
139 return 17;
140 else if (n == 0)
141 return 100;
142 else if (n == 1)
143 return 101;
144 else if (n == 2)
145 return 102;
146 else if (n == 3)
147 return 103;
148 else if (n == 4)
149 return 104;
150 else if (n == 5)
151 return 105;
152 else if (n == 6)
153 return 106;
154 else if (n == 7)
155 return 107;
156 return 0;
157 }
158
159 int
160 fn8 (bool b)
161 {
162 if (!b)
163 return 16;
164 else if (!b)
165 return 27;
166 else
167 return 64;
168 }
169
170 int
171 fn9 (int i, int j, int k)
172 {
173 if ((i > 0 && j > 0 && k > 0)
174 && ((i > 11 && j == 76 && k < 10)
175 || (i < 0 && j == 99 && k > 103)))
176 return -999;
177 else
178 if ((i > 0 && j > 0 && k > 0)
179 && ((i > 11 && j == 76 && k < 10)
180 || (i < 0 && j == 99 && k > 103)))
181 return 999;
182 else
183 return 0;
184 }
185
186 int
187 fn10 (void)
188 {
189 if (foo ())
190 return 17329;
191 else if (foo ())
192 return 18409;
193 return 0;
194 }
195
196 int
197 fn11 (int n)
198 {
199 if (++n == 10)
200 return 666;
201 else if (++n == 10)
202 return 9;
203 return 0;
204 }