diff options
Diffstat (limited to 'gcc/testsuite/g++.dg/cpp0x/range-for5.C')
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/range-for5.C | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/cpp0x/range-for5.C b/gcc/testsuite/g++.dg/cpp0x/range-for5.C new file mode 100644 index 000000000..9c97ad5fa --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/range-for5.C @@ -0,0 +1,54 @@ +// Test for errors in range-based for loops + +// { dg-do compile } +// { dg-options "-std=c++0x" } + +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) + { + int i; + } +} |