1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
5 auto begin(T &&t) -> decltype(t.begin()) { return t.begin(); } // expected-note 4{{ignored: substitution failure}}
7 auto end(T &&t) -> decltype(t.end()) { return t.end(); } // expected-note {{candidate template ignored: substitution failure [with T = }}
10 auto begin(T &&t) -> decltype(t.alt_begin()) { return t.alt_begin(); } // expected-note {{selected 'begin' template [with T = }} \
11 expected-note 4{{candidate template ignored: substitution failure [with T = }}
13 auto end(T &&t) -> decltype(t.alt_end()) { return t.alt_end(); } // expected-note {{candidate template ignored: substitution failure [with T = }}
16 // These should never be considered.
21 using namespace inner;
24 struct A { // expected-note 2 {{candidate constructor}}
26 int *begin(); // expected-note 3{{selected 'begin' function with iterator type 'int *'}} expected-note {{'begin' declared here}}
42 for (char *a : A()) { // expected-error {{cannot initialize a variable of type 'char *' with an lvalue of type 'int'}}
44 for (char *a : B()) { // expected-error {{cannot initialize a variable of type 'char *' with an lvalue of type 'int'}}
46 // FIXME: Terrible diagnostic here. auto deduction should fail, but does not!
47 for (double a : f) { // expected-error {{cannot use type '<overloaded function type>' as a range}}
53 for (auto *a : A()) { // expected-error {{variable 'a' with type 'auto *' has incompatible initializer of type 'int'}}
55 // : is not a typo for :: here.
56 for (A NS:A()) { // expected-error {{no viable conversion from 'int' to 'A'}}
58 for (auto not_in_scope : not_in_scope) { // expected-error {{use of undeclared identifier 'not_in_scope'}}
63 __range.begin(); // expected-error {{use of undeclared identifier '__range'}}
64 ++__begin; // expected-error {{use of undeclared identifier '__begin'}}
65 --__end; // expected-error {{use of undeclared identifier '__end'}}
70 for (auto a : f()) // expected-error {{cannot use type 'void' as a range}}
73 extern int incomplete[];
74 for (auto a : incomplete) // expected-error {{cannot use incomplete type 'int []' as a range}}
76 extern struct Incomplete also_incomplete[2]; // expected-note {{forward declaration}}
77 for (auto &a : also_incomplete) // expected-error {{cannot use incomplete type 'struct Incomplete [2]' as a range}}
81 void begin(); // expected-note {{selected 'begin' function with iterator type 'void'}}
84 for (auto a : VoidBegin()) // expected-error {{cannot use type 'void' as an iterator}}
91 int *begin(); // expected-note {{selected 'begin' function with iterator type 'int *'}}
92 null_t end(); // expected-note {{selected 'end' function with iterator type 'null_t'}}
94 for (auto a : Differ()) // expected-error {{'begin' and 'end' must return the same type (got 'int *' and 'null_t')}}
97 for (void f() : "error") // expected-error {{for range declaration must declare a variable}}
100 for (extern int a : A()) {} // expected-error {{loop variable 'a' may not be declared 'extern'}}
101 for (static int a : A()) {} // expected-error {{loop variable 'a' may not be declared 'static'}}
102 for (register int a : A()) {} // expected-error {{loop variable 'a' may not be declared 'register'}}
103 for (constexpr int a : A()) {} // expected-error {{loop variable 'a' may not be declared 'constexpr'}}
111 for (auto u : NoBeginADL()) { // expected-error {{no matching function for call to 'begin'}} expected-note {{range has type 'NoBeginADL'}}
113 for (auto u : NoEndADL()) { // expected-error {{no matching function for call to 'end'}} expected-note {{range has type 'NoEndADL'}}
122 for (auto u : NoBegin()) { // expected-error {{range type 'NoBegin' has 'end' member but no 'begin' member}}
124 for (auto u : NoEnd()) { // expected-error {{range type 'NoEnd' has 'begin' member but no 'end' member}}
128 void *begin(); // expected-note {{selected 'begin' function with iterator type 'void *'}}
131 for (auto u : NoIncr()) { // expected-error {{arithmetic on a pointer to void}}
135 NoNotEq begin(); // expected-note {{selected 'begin' function with iterator type 'NoNotEq'}}
139 for (auto u : NoNotEq()) { // expected-error {{invalid operands to binary expression}}
144 NoCopy(const NoCopy &) = delete;
148 for (int n : NoCopy()) { // ok
151 for (int n : 42) { // expected-error {{no matching function for call to 'begin'}} \
152 expected-note {{range has type 'int'}}
155 for (auto a : *also_incomplete) { // expected-error {{cannot use incomplete type 'struct Incomplete' as a range}}
159 template<typename T, typename U>
161 for (U u : t) { // expected-error {{no viable conversion from 'A' to 'int'}}
167 template void h<A, int>(A);
168 template void h<A(&)[4], A &>(A(&)[4]);
169 template void h<A(&)[13], A>(A(&)[13]);
170 template void h<A(&)[13], int>(A(&)[13]); // expected-note {{requested here}}
174 for (auto u : t) { // expected-error {{no matching function for call to 'begin'}} \
175 expected-error {{member function 'begin' not viable}} \
176 expected-note {{range has type}}
179 template void i<A[13]>(A*); // expected-note {{requested here}}
180 template void i<const A>(const A); // expected-note {{requested here}}
184 int *begin(ADL); // expected-note {{no known conversion from 'NS::NoADL' to 'NS::ADL'}}
189 int *begin(NS::NoADL);
192 struct VoidBeginADL {};
193 void begin(VoidBeginADL); // expected-note {{selected 'begin' function with iterator type 'void'}}
194 void end(VoidBeginADL);
197 for (auto u : NS::ADL()) {
199 for (auto u : NS::NoADL()) { // expected-error {{no matching function for call to 'begin'}} expected-note {{range has type}}
201 for (auto a : VoidBeginADL()) { // expected-error {{cannot use type 'void' as an iterator}}
206 int array[5] = { 1, 2, 3, 4, 5 };