aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.dg/cpp0x/range-for5.C
diff options
context:
space:
mode:
Diffstat (limited to 'gcc-4.9/gcc/testsuite/g++.dg/cpp0x/range-for5.C')
-rw-r--r--gcc-4.9/gcc/testsuite/g++.dg/cpp0x/range-for5.C53
1 files changed, 53 insertions, 0 deletions
diff --git a/gcc-4.9/gcc/testsuite/g++.dg/cpp0x/range-for5.C b/gcc-4.9/gcc/testsuite/g++.dg/cpp0x/range-for5.C
new file mode 100644
index 0000000..bf04406
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/g++.dg/cpp0x/range-for5.C
@@ -0,0 +1,53 @@
+// Test for errors in range-based for loops
+
+// { dg-do compile { target c++11 } }
+
+struct container
+{
+};
+
+int *begin(const container &c)
+{
+ return 0;
+}
+
+int end(const container &c) //Ops! wrong type
+{
+ return 0;
+}
+
+
+struct Implicit
+{
+ Implicit(int x)
+ {}
+};
+struct Explicit
+{
+ explicit Explicit(int x)
+ {}
+};
+
+void test1()
+{
+ container c;
+ for (int x : c) // { dg-error "inconsistent|conversion" }
+ ;
+
+ int a[2] = {1,2};
+ for (Implicit x : a)
+ ;
+ for (Explicit x : a) // { dg-error "conversion" }
+ ;
+ for (const Implicit &x : a)
+ ;
+ for (Implicit &&x : a)
+ ;
+
+ //Check the correct scopes
+ int i;
+ for (int i : a) // { dg-message "previously declared" }
+ {
+ int i; // { dg-error "redeclaration" }
+ }
+}