summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp0x/range-for6.C
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/g++.dg/cpp0x/range-for6.C')
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/range-for6.C29
1 files changed, 29 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/cpp0x/range-for6.C b/gcc/testsuite/g++.dg/cpp0x/range-for6.C
new file mode 100644
index 000000000..775507f8d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/range-for6.C
@@ -0,0 +1,29 @@
+// Test for range-based for loop
+// Test the loop with an initializer_list
+
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+#include <initializer_list>
+
+extern "C" void abort();
+
+template<typename T> T foo()
+{
+ T sum = 0;
+ for (T x : {T(1),T(2),T(3),T(4)})
+ sum += x;
+ if (sum != T(10))
+ abort();
+}
+
+int main()
+{
+ int sum = 0;
+ for (int x : {1,2,3,4})
+ sum += x;
+ if (sum != 10)
+ abort();
+
+ foo<int>();
+}