1762bb9d0ad20320b9f97a841dce57ba5e8e48b07Richard Smith// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s 2ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 34872e1014844632083690cc1d021b95218a5023bDavid Blaikiestruct pr12960 { 44872e1014844632083690cc1d021b95218a5023bDavid Blaikie int begin; 54872e1014844632083690cc1d021b95218a5023bDavid Blaikie void foo(int x) { 6e1715b66a878bcab315513351e5df68bfc010d2eSam Panzer for (int& it : x) { // expected-error {{invalid range expression of type 'int'; no viable 'begin' function available}} 74872e1014844632083690cc1d021b95218a5023bDavid Blaikie } 84872e1014844632083690cc1d021b95218a5023bDavid Blaikie } 94872e1014844632083690cc1d021b95218a5023bDavid Blaikie}; 104872e1014844632083690cc1d021b95218a5023bDavid Blaikie 11b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smithstruct null_t { 12b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith operator int*(); 13b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith}; 14b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith 15b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smithnamespace X { 16ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith template<typename T> 17b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith auto begin(T &&t) -> decltype(t.begin()) { return t.begin(); } // expected-note 2{{ignored: substitution failure}} 18ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith template<typename T> 19ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith auto end(T &&t) -> decltype(t.end()) { return t.end(); } // expected-note {{candidate template ignored: substitution failure [with T = }} 20ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 21ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith template<typename T> 22ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith auto begin(T &&t) -> decltype(t.alt_begin()) { return t.alt_begin(); } // expected-note {{selected 'begin' template [with T = }} \ 23b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith expected-note 2{{candidate template ignored: substitution failure [with T = }} 24ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith template<typename T> 25ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith auto end(T &&t) -> decltype(t.alt_end()) { return t.alt_end(); } // expected-note {{candidate template ignored: substitution failure [with T = }} 26ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 27ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith namespace inner { 28ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith // These should never be considered. 29ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith int begin(int); 30ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith int end(int); 31ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 32ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 33ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith using namespace inner; 34ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 35b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith struct A { // expected-note 2 {{candidate constructor}} 36b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith A(); 37b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith int *begin(); // expected-note 3{{selected 'begin' function with iterator type 'int *'}} expected-note {{'begin' declared here}} 38b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith int *end(); 39b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith }; 40ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 41b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith struct B { 42b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith B(); 43b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith int *alt_begin(); 44b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith int *alt_end(); 45b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith }; 46b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith 47b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith struct NoBeginADL { 48b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith null_t alt_end(); 49b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith }; 50b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith struct NoEndADL { 51b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith null_t alt_begin(); 52b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith }; 53b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith} 54b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith 55b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smithusing X::A; 56ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 579625e44c0252485277a340746ed8ac950686156fDouglas Gregorvoid f(); 589625e44c0252485277a340746ed8ac950686156fDouglas Gregorvoid f(int); 59ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 60ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithvoid g() { 61ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith for (int a : A()) 62ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith A __begin; 63ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith for (char *a : A()) { // expected-error {{cannot initialize a variable of type 'char *' with an lvalue of type 'int'}} 64ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 65b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith for (char *a : X::B()) { // expected-error {{cannot initialize a variable of type 'char *' with an lvalue of type 'int'}} 66ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 67ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith // FIXME: Terrible diagnostic here. auto deduction should fail, but does not! 689625e44c0252485277a340746ed8ac950686156fDouglas Gregor for (double a : f) { // expected-error {{cannot use type '<overloaded function type>' as a range}} 69ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 70ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith for (auto a : A()) { 71ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 72b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith for (auto a : X::B()) { 73ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 74ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith for (auto *a : A()) { // expected-error {{variable 'a' with type 'auto *' has incompatible initializer of type 'int'}} 75ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 76ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith // : is not a typo for :: here. 77b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith for (A NS:A()) { // expected-error {{no viable conversion from 'int' to 'X::A'}} 78ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 79ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith for (auto not_in_scope : not_in_scope) { // expected-error {{use of undeclared identifier 'not_in_scope'}} 80ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 81ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 82ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith for (auto a : A()) 83ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith for (auto b : A()) { 84ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith __range.begin(); // expected-error {{use of undeclared identifier '__range'}} 85ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ++__begin; // expected-error {{use of undeclared identifier '__begin'}} 86ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith --__end; // expected-error {{use of undeclared identifier '__end'}} 87ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 88ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 89ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith for (char c : "test") 90ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ; 91ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith for (auto a : f()) // expected-error {{cannot use type 'void' as a range}} 92ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ; 93ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 94ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith extern int incomplete[]; 95ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith for (auto a : incomplete) // expected-error {{cannot use incomplete type 'int []' as a range}} 96ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ; 97ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith extern struct Incomplete also_incomplete[2]; // expected-note {{forward declaration}} 98ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith for (auto &a : also_incomplete) // expected-error {{cannot use incomplete type 'struct Incomplete [2]' as a range}} 99ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ; 100ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 101ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith struct VoidBegin { 102ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith void begin(); // expected-note {{selected 'begin' function with iterator type 'void'}} 103ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith void end(); 104ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith }; 105ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith for (auto a : VoidBegin()) // expected-error {{cannot use type 'void' as an iterator}} 106ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ; 107ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 108ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith struct Differ { 109ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith int *begin(); // expected-note {{selected 'begin' function with iterator type 'int *'}} 110ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith null_t end(); // expected-note {{selected 'end' function with iterator type 'null_t'}} 111ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith }; 112ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith for (auto a : Differ()) // expected-error {{'begin' and 'end' must return the same type (got 'int *' and 'null_t')}} 113ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ; 114ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 115ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith for (void f() : "error") // expected-error {{for range declaration must declare a variable}} 116ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ; 117ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 118ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith for (extern int a : A()) {} // expected-error {{loop variable 'a' may not be declared 'extern'}} 119ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith for (static int a : A()) {} // expected-error {{loop variable 'a' may not be declared 'static'}} 12079f4bb7aad1b7c53f8a3bc43d89de0efdef8286dRichard Smith for (register int a : A()) {} // expected-error {{loop variable 'a' may not be declared 'register'}} expected-warning {{deprecated}} 121c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smith for (constexpr int a : A()) {} // expected-error {{loop variable 'a' may not be declared 'constexpr'}} 122ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 123b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith for (auto u : X::NoBeginADL()) { // expected-error {{invalid range expression of type 'X::NoBeginADL'; no viable 'begin' function available}} 124ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 125b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith for (auto u : X::NoEndADL()) { // expected-error {{invalid range expression of type 'X::NoEndADL'; no viable 'end' function available}} 126ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 127ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 128ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith struct NoBegin { 129ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith null_t end(); 130ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith }; 131ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith struct NoEnd { 132ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith null_t begin(); 133ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith }; 134ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith for (auto u : NoBegin()) { // expected-error {{range type 'NoBegin' has 'end' member but no 'begin' member}} 135ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 1368123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer for (auto u : NoEnd()) { // expected-error {{range type 'NoEnd' has 'begin' member but no 'end' member}} 137ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 138ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 139ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith struct NoIncr { 140ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith void *begin(); // expected-note {{selected 'begin' function with iterator type 'void *'}} 141ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith void *end(); 142ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith }; 1438123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer for (auto u : NoIncr()) { // expected-error {{arithmetic on a pointer to void}}\ 1448123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer expected-note {{in implicit call to 'operator++' for iterator of type 'NoIncr'}} 145ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 146ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 147ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith struct NoNotEq { 148ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith NoNotEq begin(); // expected-note {{selected 'begin' function with iterator type 'NoNotEq'}} 149ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith NoNotEq end(); 150ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith void operator++(); 151ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith }; 1528123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer for (auto u : NoNotEq()) { // expected-error {{invalid operands to binary expression}}\ 1538123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer expected-note {{in implicit call to 'operator!=' for iterator of type 'NoNotEq'}} 1548123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer } 1558123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer 1568123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer struct NoDeref { 1578123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer NoDeref begin(); // expected-note {{selected 'begin' function}} 1588123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer NoDeref end(); 1598123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer void operator++(); 1608123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer bool operator!=(NoDeref &); 1618123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer }; 1628123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer 1638123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer for (auto u : NoDeref()) { // expected-error {{indirection requires pointer operand}} \ 1648123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer expected-note {{in implicit call to 'operator*' for iterator of type 'NoDeref'}} 165ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 166ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 167ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith struct NoCopy { 168ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith NoCopy(); 169ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith NoCopy(const NoCopy &) = delete; 170ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith int *begin(); 171ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith int *end(); 172ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith }; 173ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith for (int n : NoCopy()) { // ok 174ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 175ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 176e1715b66a878bcab315513351e5df68bfc010d2eSam Panzer for (int n : 42) { // expected-error {{invalid range expression of type 'int'; no viable 'begin' function available}} 177ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 178ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 179ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith for (auto a : *also_incomplete) { // expected-error {{cannot use incomplete type 'struct Incomplete' as a range}} 180ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 181ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith} 182ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 183ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate<typename T, typename U> 184ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithvoid h(T t) { 185b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith for (U u : t) { // expected-error {{no viable conversion from 'X::A' to 'int'}} 186ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 187ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith for (auto u : t) { 188ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 189ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith} 190ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 191ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate void h<A, int>(A); 192ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate void h<A(&)[4], A &>(A(&)[4]); 193ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate void h<A(&)[13], A>(A(&)[13]); 194ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate void h<A(&)[13], int>(A(&)[13]); // expected-note {{requested here}} 195ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 196ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate<typename T> 197ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithvoid i(T t) { 198b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith for (auto u : t) { // expected-error {{invalid range expression of type 'X::A *'; no viable 'begin' function available}} \ 199ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith expected-error {{member function 'begin' not viable}} \ 200e1715b66a878bcab315513351e5df68bfc010d2eSam Panzer expected-note {{when looking up 'begin' function}} 201e1715b66a878bcab315513351e5df68bfc010d2eSam Panzer 202ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 203ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith} 204ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate void i<A[13]>(A*); // expected-note {{requested here}} 205ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate void i<const A>(const A); // expected-note {{requested here}} 206ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 207b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smithstruct StdBeginEnd {}; 208b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smithnamespace std { 209b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith int *begin(StdBeginEnd); 210b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith int *end(StdBeginEnd); 211b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith} 212b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smithvoid DR1442() { 213b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith for (auto a : StdBeginEnd()) {} // expected-error {{invalid range expression of type 'StdBeginEnd'; no viable 'begin'}} 214b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith} 215b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith 216ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithnamespace NS { 217ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith class ADL {}; 218ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith int *begin(ADL); // expected-note {{no known conversion from 'NS::NoADL' to 'NS::ADL'}} 219ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith int *end(ADL); 220ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 221ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith class NoADL {}; 222ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith} 223ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithint *begin(NS::NoADL); 224ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithint *end(NS::NoADL); 225ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 226ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithstruct VoidBeginADL {}; 227ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithvoid begin(VoidBeginADL); // expected-note {{selected 'begin' function with iterator type 'void'}} 228ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithvoid end(VoidBeginADL); 229ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 230ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithvoid j() { 231ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith for (auto u : NS::ADL()) { 232ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 233e1715b66a878bcab315513351e5df68bfc010d2eSam Panzer for (auto u : NS::NoADL()) { // expected-error {{invalid range expression of type 'NS::NoADL'; no viable 'begin' function available}} 234ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 235ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith for (auto a : VoidBeginADL()) { // expected-error {{cannot use type 'void' as an iterator}} 236e1715b66a878bcab315513351e5df68bfc010d2eSam Panzer 237ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 238ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith} 239ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 240ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithvoid example() { 241ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith int array[5] = { 1, 2, 3, 4, 5 }; 242ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith for (int &x : array) 243ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith x *= 2; 244ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith} 24539b60dc786950e553f5e12fa0e692a33f650a568Douglas Gregor 24639b60dc786950e553f5e12fa0e692a33f650a568Douglas Gregornamespace rdar13712739 { 24739b60dc786950e553f5e12fa0e692a33f650a568Douglas Gregor template<typename T> 24839b60dc786950e553f5e12fa0e692a33f650a568Douglas Gregor void foo(const T& t) { 24939b60dc786950e553f5e12fa0e692a33f650a568Douglas Gregor auto &x = t.get(); // expected-error{{member reference base type 'const int' is not a structure or union}} 25039b60dc786950e553f5e12fa0e692a33f650a568Douglas Gregor for (auto &blah : x) { } 25139b60dc786950e553f5e12fa0e692a33f650a568Douglas Gregor } 25239b60dc786950e553f5e12fa0e692a33f650a568Douglas Gregor 25339b60dc786950e553f5e12fa0e692a33f650a568Douglas Gregor template void foo(const int&); // expected-note{{in instantiation of function template specialization}} 25439b60dc786950e553f5e12fa0e692a33f650a568Douglas Gregor} 255