145
|
1 // PR c++/81676 - bogus -Wunused warnings in constexpr if.
|
|
2 // { dg-do compile { target c++17 } }
|
|
3 // { dg-options "-Wall -Wextra" }
|
|
4
|
|
5 template <typename T> int
|
|
6 f1 (T v)
|
|
7 {
|
|
8 T x = 0;
|
|
9 if constexpr(sizeof(T) == sizeof(int))
|
|
10 return v + x;
|
|
11 else
|
|
12 return 0;
|
|
13 }
|
|
14
|
|
15 template <typename T> int
|
|
16 f2 (T v) // { dg-warning "unused parameter .v." }
|
|
17 {
|
|
18 T x = 0;
|
|
19 if constexpr(sizeof(T) == sizeof(int))
|
|
20 return x;
|
|
21 else
|
|
22 return 0;
|
|
23 }
|
|
24
|
|
25 template <typename T> int
|
|
26 f3 (T v)
|
|
27 {
|
|
28 T x = 0; // { dg-warning "unused variable .x." }
|
|
29 if constexpr(sizeof(T) == sizeof(int))
|
|
30 return v;
|
|
31 else
|
|
32 return 0;
|
|
33 }
|
|
34
|
|
35 template <typename T> int
|
|
36 f4 (T v)
|
|
37 {
|
|
38 T x = 0;
|
|
39 if constexpr(sizeof(T) == sizeof(int))
|
|
40 return 0;
|
|
41 else
|
|
42 return v + x;
|
|
43 }
|
|
44
|
|
45 template <typename T> int
|
|
46 f5 (T v) // { dg-warning "unused parameter .v." }
|
|
47 {
|
|
48 T x = 0;
|
|
49 if constexpr(sizeof(T) == sizeof(int))
|
|
50 return 0;
|
|
51 else
|
|
52 return x;
|
|
53 }
|
|
54
|
|
55 template <typename T> int
|
|
56 f6 (T v)
|
|
57 {
|
|
58 T x = 0; // { dg-warning "unused variable .x." }
|
|
59 if constexpr(sizeof(T) == sizeof(int))
|
|
60 return 0;
|
|
61 else
|
|
62 return v;
|
|
63 }
|
|
64
|
|
65 int main()
|
|
66 {
|
|
67 f1(0);
|
|
68 f1('a');
|
|
69 f2(0);
|
|
70 f2('a');
|
|
71 f3(0);
|
|
72 f3('a');
|
|
73 f4(0);
|
|
74 f4('a');
|
|
75 f5(0);
|
|
76 f5('a');
|
|
77 f6(0);
|
|
78 f6('a');
|
|
79 }
|