comparison gcc/testsuite/g++.dg/cpp0x/range-for13.C @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
1 // Test for errors in range-based for loops 1 // Test for errors in range-based for loops
2 // with member begin/end 2 // with member begin/end
3 3
4 // { dg-do compile { target c++11 } } 4 // { dg-do compile { target c++11 } }
5
6 //These should not be used
7 template<typename T> int *begin(T &t)
8 {
9 T::fail;
10 }
11 template<typename T> int *end(T &t)
12 {
13 T::fail;
14 }
15 5
16 struct container1 6 struct container1
17 { 7 {
18 int *begin(); 8 int *begin();
19 //no end 9 //no end
85 75
86 function begin; 76 function begin;
87 static function end; 77 static function end;
88 }; 78 };
89 79
80 namespace N
81 {
82 template<typename T> int *begin(T &t)
83 {
84 return 0;
85 }
86 template<typename T> int *end(T &t)
87 {
88 return 0;
89 }
90 struct container11
91 {
92 int *begin();
93 //no end
94 };
95
96 struct container12
97 {
98 int *end();
99 //no begin
100 };
101
102 struct container13
103 {
104 };
105 }
106
90 void test1() 107 void test1()
91 { 108 {
92 for (int x : container1()); // { dg-error "member but not" } 109 for (int x : container1()); // { dg-error "'begin' was not declared|'end' was not declared" }
93 for (int x : container2()); // { dg-error "member but not" } 110 for (int x : container2()); // { dg-error "'begin' was not declared|'end' was not declared" }
94 for (int x : container3()); // { dg-error "within this context" } 111 for (int x : container3()); // { dg-error "within this context" }
95 for (int x : container4()); // { dg-error "cannot be used as a function" } 112 for (int x : container4()); // { dg-error "cannot be used as a function" }
96 for (int x : container5()); // { dg-error "invalid use of" } 113 for (int x : container5()); // { dg-error "invalid use of" }
97 for (int x : container6()); 114 for (int x : container6());
98 for (int x : container7()); 115 for (int x : container7());
99 for (int x : container8()); 116 for (int x : container8());
100 for (int x : container9()); // { dg-error "within this context" } 117 for (int x : container9()); // { dg-error "within this context" }
101 for (int x : container10()); 118 for (int x : container10());
119 for (int x : N::container11());
120 for (int x : N::container12());
121 for (int x : N::container13());
102 } 122 }