p1.cpp revision 8123b6e7838216a53ba050f07e36fee28e1bbdaf
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
11ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithnamespace std {
12ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  template<typename T>
13ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    auto begin(T &&t) -> decltype(t.begin()) { return t.begin(); } // expected-note 4{{ignored: substitution failure}}
14ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  template<typename T>
15ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    auto end(T &&t) -> decltype(t.end()) { return t.end(); } // expected-note {{candidate template ignored: substitution failure [with T = }}
16ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
17ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  template<typename T>
18ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    auto begin(T &&t) -> decltype(t.alt_begin()) { return t.alt_begin(); } // expected-note {{selected 'begin' template [with T = }} \
19ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                                              expected-note 4{{candidate template ignored: substitution failure [with T = }}
20ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  template<typename T>
21ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    auto end(T &&t) -> decltype(t.alt_end()) { return t.alt_end(); } // expected-note {{candidate template ignored: substitution failure [with T = }}
22ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
23ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  namespace inner {
24ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    // These should never be considered.
25ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    int begin(int);
26ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    int end(int);
27ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
28ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
29ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  using namespace inner;
30ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith}
31ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
3285ea7aa961deac1d754f610af8062ae3f8b4e2a5Sebastian Redlstruct A { // expected-note 2 {{candidate constructor}}
33ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  A();
34ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  int *begin(); // expected-note 3{{selected 'begin' function with iterator type 'int *'}} expected-note {{'begin' declared here}}
35ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  int *end();
36ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith};
37ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
38ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithstruct B {
39ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  B();
40ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  int *alt_begin();
41ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  int *alt_end();
42ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith};
43ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
449625e44c0252485277a340746ed8ac950686156fDouglas Gregorvoid f();
459625e44c0252485277a340746ed8ac950686156fDouglas Gregorvoid f(int);
46ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
47ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithvoid g() {
48ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (int a : A())
49ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    A __begin;
50ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (char *a : A()) { // expected-error {{cannot initialize a variable of type 'char *' with an lvalue of type 'int'}}
51ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
52ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (char *a : B()) { // expected-error {{cannot initialize a variable of type 'char *' with an lvalue of type 'int'}}
53ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
54ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  // FIXME: Terrible diagnostic here. auto deduction should fail, but does not!
559625e44c0252485277a340746ed8ac950686156fDouglas Gregor  for (double a : f) { // expected-error {{cannot use type '<overloaded function type>' as a range}}
56ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
57ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (auto a : A()) {
58ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
59ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (auto a : B()) {
60ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
61ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (auto *a : A()) { // expected-error {{variable 'a' with type 'auto *' has incompatible initializer of type 'int'}}
62ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
63ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  // : is not a typo for :: here.
64ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (A NS:A()) { // expected-error {{no viable conversion from 'int' to 'A'}}
65ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
66ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (auto not_in_scope : not_in_scope) { // expected-error {{use of undeclared identifier 'not_in_scope'}}
67ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
68ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
69ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (auto a : A())
70ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    for (auto b : A()) {
71ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      __range.begin(); // expected-error {{use of undeclared identifier '__range'}}
72ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      ++__begin; // expected-error {{use of undeclared identifier '__begin'}}
73ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      --__end; // expected-error {{use of undeclared identifier '__end'}}
74ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    }
75ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
76ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (char c : "test")
77ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    ;
78ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (auto a : f()) // expected-error {{cannot use type 'void' as a range}}
79ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    ;
80ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
81ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  extern int incomplete[];
82ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (auto a : incomplete) // expected-error {{cannot use incomplete type 'int []' as a range}}
83ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    ;
84ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  extern struct Incomplete also_incomplete[2]; // expected-note {{forward declaration}}
85ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (auto &a : also_incomplete) // expected-error {{cannot use incomplete type 'struct Incomplete [2]' as a range}}
86ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    ;
87ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
88ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  struct VoidBegin {
89ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    void begin(); // expected-note {{selected 'begin' function with iterator type 'void'}}
90ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    void end();
91ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  };
92ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (auto a : VoidBegin()) // expected-error {{cannot use type 'void' as an iterator}}
93ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    ;
94ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
95ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  struct null_t {
96ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    operator int*();
97ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  };
98ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  struct Differ {
99ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    int *begin(); // expected-note {{selected 'begin' function with iterator type 'int *'}}
100ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    null_t end(); // expected-note {{selected 'end' function with iterator type 'null_t'}}
101ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  };
102ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (auto a : Differ()) // expected-error {{'begin' and 'end' must return the same type (got 'int *' and 'null_t')}}
103ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    ;
104ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
105ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (void f() : "error") // expected-error {{for range declaration must declare a variable}}
106ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    ;
107ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
108ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (extern int a : A()) {} // expected-error {{loop variable 'a' may not be declared 'extern'}}
109ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (static int a : A()) {} // expected-error {{loop variable 'a' may not be declared 'static'}}
110ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (register int a : A()) {} // expected-error {{loop variable 'a' may not be declared 'register'}}
111c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smith  for (constexpr int a : A()) {} // expected-error {{loop variable 'a' may not be declared 'constexpr'}}
112ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
113ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  struct NoBeginADL {
114ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    null_t alt_end();
115ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  };
116ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  struct NoEndADL {
117ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    null_t alt_begin();
118ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  };
119e1715b66a878bcab315513351e5df68bfc010d2eSam Panzer  for (auto u : NoBeginADL()) { // expected-error {{invalid range expression of type 'NoBeginADL'; no viable 'begin' function available}}
120ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
121e1715b66a878bcab315513351e5df68bfc010d2eSam Panzer  for (auto u : NoEndADL()) { // expected-error {{invalid range expression of type 'NoEndADL'; no viable 'end' function available}}
122ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
123ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
124ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  struct NoBegin {
125ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    null_t end();
126ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  };
127ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  struct NoEnd {
128ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    null_t begin();
129ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  };
130ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (auto u : NoBegin()) { // expected-error {{range type 'NoBegin' has 'end' member but no 'begin' member}}
131ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
1328123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer  for (auto u : NoEnd()) { // expected-error {{range type 'NoEnd' has 'begin' member but no 'end' member}}
133ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
134ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
135ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  struct NoIncr {
136ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    void *begin(); // expected-note {{selected 'begin' function with iterator type 'void *'}}
137ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    void *end();
138ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  };
1398123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer  for (auto u : NoIncr()) { // expected-error {{arithmetic on a pointer to void}}\
1408123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer    expected-note {{in implicit call to 'operator++' for iterator of type 'NoIncr'}}
141ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
142ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
143ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  struct NoNotEq {
144ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    NoNotEq begin(); // expected-note {{selected 'begin' function with iterator type 'NoNotEq'}}
145ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    NoNotEq end();
146ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    void operator++();
147ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  };
1488123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer  for (auto u : NoNotEq()) { // expected-error {{invalid operands to binary expression}}\
1498123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer    expected-note {{in implicit call to 'operator!=' for iterator of type 'NoNotEq'}}
1508123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer  }
1518123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer
1528123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer  struct NoDeref {
1538123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer    NoDeref begin(); // expected-note {{selected 'begin' function}}
1548123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer    NoDeref end();
1558123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer    void operator++();
1568123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer    bool operator!=(NoDeref &);
1578123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer  };
1588123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer
1598123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer  for (auto u : NoDeref()) { // expected-error {{indirection requires pointer operand}} \
1608123b6e7838216a53ba050f07e36fee28e1bbdafSam Panzer    expected-note {{in implicit call to 'operator*' for iterator of type 'NoDeref'}}
161ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
162ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
163ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  struct NoCopy {
164ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    NoCopy();
165ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    NoCopy(const NoCopy &) = delete;
166ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    int *begin();
167ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    int *end();
168ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  };
169ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (int n : NoCopy()) { // ok
170ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
171ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
172e1715b66a878bcab315513351e5df68bfc010d2eSam Panzer  for (int n : 42) { // expected-error {{invalid range expression of type 'int'; no viable 'begin' function available}}
173ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
174ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
175ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (auto a : *also_incomplete) { // expected-error {{cannot use incomplete type 'struct Incomplete' as a range}}
176ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
177ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith}
178ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
179ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate<typename T, typename U>
180ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithvoid h(T t) {
181ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (U u : t) { // expected-error {{no viable conversion from 'A' to 'int'}}
182ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
183ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (auto u : t) {
184ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
185ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith}
186ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
187ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate void h<A, int>(A);
188ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate void h<A(&)[4], A &>(A(&)[4]);
189ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate void h<A(&)[13], A>(A(&)[13]);
190ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate void h<A(&)[13], int>(A(&)[13]); // expected-note {{requested here}}
191ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
192ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate<typename T>
193ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithvoid i(T t) {
194e1715b66a878bcab315513351e5df68bfc010d2eSam Panzer  for (auto u : t) { // expected-error {{invalid range expression of type 'A *'; no viable 'begin' function available}} \
195ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                        expected-error {{member function 'begin' not viable}} \
196e1715b66a878bcab315513351e5df68bfc010d2eSam Panzer                        expected-note {{when looking up 'begin' function}}
197e1715b66a878bcab315513351e5df68bfc010d2eSam Panzer
198ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
199ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith}
200ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate void i<A[13]>(A*); // expected-note {{requested here}}
201ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate void i<const A>(const A); // expected-note {{requested here}}
202ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
203ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithnamespace NS {
204ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  class ADL {};
205ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  int *begin(ADL); // expected-note {{no known conversion from 'NS::NoADL' to 'NS::ADL'}}
206ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  int *end(ADL);
207ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
208ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  class NoADL {};
209ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith}
210ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithint *begin(NS::NoADL);
211ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithint *end(NS::NoADL);
212ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
213ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithstruct VoidBeginADL {};
214ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithvoid begin(VoidBeginADL); // expected-note {{selected 'begin' function with iterator type 'void'}}
215ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithvoid end(VoidBeginADL);
216ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
217ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithvoid j() {
218ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (auto u : NS::ADL()) {
219ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
220e1715b66a878bcab315513351e5df68bfc010d2eSam Panzer  for (auto u : NS::NoADL()) { // expected-error {{invalid range expression of type 'NS::NoADL'; no viable 'begin' function available}}
221ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
222ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (auto a : VoidBeginADL()) { // expected-error {{cannot use type 'void' as an iterator}}
223e1715b66a878bcab315513351e5df68bfc010d2eSam Panzer
224ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
225ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith}
226ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
227ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithvoid example() {
228ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  int array[5] = { 1, 2, 3, 4, 5 };
229ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  for (int &x : array)
230ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    x *= 2;
231ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith}
232