Fortran: Fix PR 47485.
[gcc.git] / gcc / testsuite / g++.dg / warn / Wrange-loop-construct2.C
blob5bb08cc5a1dcd703ddc006fd31b26f86517154e4
1 // PR c++/94695
2 // { dg-do compile { target c++11 } }
3 // { dg-options "-Wrange-loop-construct" }
5 struct Foo { };
6 struct Bar {
7   char arr[100];
8   Bar(Foo);
9   Bar(int);
10   operator int();
13 template<typename T>
14 struct It {
15   T operator*();
16   It operator++();
17   bool operator!=(const It);
20 template<typename T>
21 struct Cont {
22   using I = It<T>;
23   I begin();
24   I end();
27 void
28 fn1 ()
30   int arr[10];
31   Cont<int> cont_int;
33   for (const double &x : arr) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
34   for (const double x : arr) { (void) x; }
35   for (const int &x : arr) { (void) x; }
36   for (double &&x : arr) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
37   for (double x : arr) { (void) x; }
39   for (const int &&x : cont_int) { (void) x; }
40   for (const int &x : cont_int) { (void) x; }
41   for (const int x : cont_int) { (void) x; }
42   for (int&& x : cont_int) { (void) x; }
43   for (int x : cont_int) { (void) x; }
45   for (const double &&x : cont_int) { (void) x; }
46   for (const double &x : cont_int) { (void) x; }
47   for (const double x : cont_int) { (void) x; }
49   for (double &&x : cont_int) { (void) x; }
50   for (double x : cont_int) { (void) x; }
52   for (const Bar &&x : cont_int) { (void) x; }
53   for (const Bar x : cont_int) { (void) x; }
56 void
57 fn2 ()
59   Cont<int &> cont_int_ref;
61   for (const int &x : cont_int_ref) { (void) x; }
62   for (const int x : cont_int_ref) { (void) x; }
63   for (int &x : cont_int_ref) { (void) x; }
64   for (int x : cont_int_ref) { (void) x; }
66   for (const double &&x : cont_int_ref) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
67   for (const double &x : cont_int_ref) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
68   for (const double x : cont_int_ref) { (void) x; }
69   for (double &&x : cont_int_ref) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
70   for (double x : cont_int_ref) { (void) x; }
72   for (const Bar &&x : cont_int_ref) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
73   for (const Bar &x : cont_int_ref) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
74   for (const Bar x : cont_int_ref) { (void) x; }
75   for (Bar &&x : cont_int_ref) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
76   for (Bar x : cont_int_ref) { (void) x; }
79 void
80 fn3 ()
82   Cont<Bar> cont_bar;
84   for (const Bar &&x : cont_bar) { (void) x; }
85   for (const Bar &x : cont_bar) { (void) x; }
86   for (const Bar x : cont_bar) { (void) x; }
87   for (Bar &&x : cont_bar) { (void) x; }
88   for (Bar x : cont_bar) { (void) x; }
90   for (const int &&x : cont_bar) { (void) x; }
91   for (const int &x : cont_bar) { (void) x; }
92   for (const int x : cont_bar) { (void) x; }
93   for (int &&x : cont_bar) { (void) x; }
94   for (int x : cont_bar) { (void) x; }
97 void
98 fn4 ()
100   Cont<Bar &> cont_bar_ref;
102   for (const Bar &x : cont_bar_ref) { (void) x; }
103   for (Bar &x : cont_bar_ref) { (void) x; }
104   for (Bar x : cont_bar_ref) { (void) x; }
106   for (const int &&x : cont_bar_ref) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
107   for (const int &x : cont_bar_ref) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
108   for (const int x : cont_bar_ref) { (void) x; }
109   for (int &&x : cont_bar_ref) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
110   for (int x : cont_bar_ref) { (void) x; }
113 void
114 fn5 ()
116   Cont<Foo> cont_foo;
118   for (const Bar &&x : cont_foo) { (void) x; }
119   for (const Bar &x : cont_foo) { (void) x; }
120   for (const Bar x : cont_foo) { (void) x; }
121   for (Bar &&x : cont_foo) { (void) x; }
122   for (Bar x : cont_foo) { (void) x; }
125 void
126 fn6 ()
128   Cont<Foo &> cont_foo_ref;
130   for (const Bar &&x : cont_foo_ref) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
131   for (const Bar &x : cont_foo_ref) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
132   for (const Bar x : cont_foo_ref) { (void) x; }
133   for (Bar &&x : cont_foo_ref) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
134   for (Bar x : cont_foo_ref) { (void) x; }
137 void
138 fn7 ()
140   double arr[2];
142   for (const double &x : arr) { (void) x; }
143   for (const double x : arr) { (void) x; }
144   for (double &x : arr) { (void) x; }
145   for (double x : arr) { (void) x; }
147   for (const int &&x : arr) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
148   for (const int &x : arr) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
149   for (const int x : arr) { (void) x; }
150   for (int &&x : arr) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
151   for (int x : arr) { (void) x; }
153   for (const Bar &&x : arr) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
154   for (const Bar &x : arr) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
155   for (const Bar x : arr) { (void) x; }
156   for (Bar &&x : arr) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
157   for (Bar x : arr) { (void) x; }
160 void
161 fn8 ()
163   Foo arr[2];
165   for (const Foo &x : arr) { (void) x; }
166   for (const Foo x : arr) { (void) x; }
167   for (Foo &x : arr) { (void) x; }
168   for (Foo x : arr) { (void) x; }
170   for (const Bar &&x : arr) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
171   for (const Bar &x : arr) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
172   for (const Bar x : arr) { (void) x; }
173   for (Bar &&x : arr) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
174   for (Bar x : arr) { (void) x; }
177 void
178 fn9 ()
180   Bar arr[2] = { 1, 2 };
182   for (const Bar &x : arr) { (void) x; }
183   for (Bar &x : arr) { (void) x; }
184   for (Bar x : arr) { (void) x; }
186   for (const int &&x : arr) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
187   for (const int &x : arr) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
188   for (const int x : arr) { (void) x; }
189   for (int &&x : arr) { (void) x; } // { dg-warning "binds to a temporary constructed from type" }
190   for (int x : arr) { (void) x; }
193 template<typename T>
194 void
195 fn10 ()
197   Cont<Bar> cont_bar;
199   for (const Bar &x : cont_bar) { (void) x; }
201   Cont<T> cont_dep;
202   for (const T &x : cont_dep) { (void) x; }
204 template void fn10<Bar>();
206 struct S {
207   void fn()
208   {
209     Cont<Bar> cont_bar;
210     for (const Bar &x : cont_bar) { (void) x; }
211   }