Sam Panzer | e1715b6 | 2012-08-21 00:52:01 +0000 | [diff] [blame^] | 1 | // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s |
| 2 | struct Data { }; |
| 3 | struct T { |
| 4 | Data *begin(); |
| 5 | Data *end(); |
| 6 | }; |
| 7 | |
| 8 | struct NoBegin { |
| 9 | Data *end(); |
| 10 | }; |
| 11 | |
| 12 | struct DeletedEnd : public T { |
| 13 | Data *begin(); |
| 14 | Data *end() = delete; //expected-note {{function has been explicitly marked deleted here}} |
| 15 | }; |
| 16 | |
| 17 | struct DeletedADLBegin { }; |
| 18 | |
| 19 | int* begin(DeletedADLBegin) = delete; //expected-note {{candidate function has been explicitly deleted}} \ |
| 20 | expected-note 6 {{candidate function not viable: no known conversion}} |
| 21 | |
| 22 | struct PrivateEnd { |
| 23 | Data *begin(); |
| 24 | |
| 25 | private: |
| 26 | Data *end(); // expected-note 1 {{declared private here}} |
| 27 | }; |
| 28 | |
| 29 | struct ADLNoEnd { }; |
| 30 | Data * begin(ADLNoEnd); // expected-note 7 {{candidate function not viable: no known conversion}} |
| 31 | |
| 32 | struct OverloadedStar { |
| 33 | T operator*(); |
| 34 | }; |
| 35 | |
| 36 | void f() { |
| 37 | T t; |
| 38 | for (auto i : t) { } |
| 39 | T *pt; |
| 40 | for (auto i : pt) { } // expected-error{{invalid range expression of type 'T *'; did you mean to dereference it with '*'?}} |
| 41 | |
| 42 | int arr[10]; |
| 43 | for (auto i : arr) { } |
| 44 | int (*parr)[10]; |
| 45 | for (auto i : parr) { }// expected-error{{invalid range expression of type 'int (*)[10]'; did you mean to dereference it with '*'?}} |
| 46 | |
| 47 | NoBegin NB; |
| 48 | for (auto i : NB) { }// expected-error{{range type 'NoBegin' has 'end' member but no 'begin' member}} |
| 49 | NoBegin *pNB; |
| 50 | for (auto i : pNB) { }// expected-error{{invalid range expression of type 'NoBegin *'; no viable 'begin' function available}} |
| 51 | NoBegin **ppNB; |
| 52 | for (auto i : ppNB) { }// expected-error{{invalid range expression of type 'NoBegin **'; no viable 'begin' function available}} |
| 53 | NoBegin *****pppppNB; |
| 54 | for (auto i : pppppNB) { }// expected-error{{invalid range expression of type 'NoBegin *****'; no viable 'begin' function available}} |
| 55 | |
| 56 | ADLNoEnd ANE; |
| 57 | for (auto i : ANE) { } // expected-error{{invalid range expression of type 'ADLNoEnd'; no viable 'end' function available}} |
| 58 | ADLNoEnd *pANE; |
| 59 | for (auto i : pANE) { } // expected-error{{invalid range expression of type 'ADLNoEnd *'; no viable 'begin' function available}} |
| 60 | |
| 61 | DeletedEnd DE; |
| 62 | for (auto i : DE) { } // expected-error{{attempt to use a deleted function}} \ |
| 63 | expected-note {{when looking up 'end' function for range expression of type 'DeletedEnd'}} |
| 64 | DeletedEnd *pDE; |
| 65 | |
| 66 | for (auto i : pDE) { } // expected-error {{invalid range expression of type 'DeletedEnd *'; no viable 'begin' function available}} |
| 67 | |
| 68 | PrivateEnd PE; |
| 69 | // FIXME: This diagnostic should be improved, as it does not specify that |
| 70 | // the range is invalid. |
| 71 | for (auto i : PE) { } // expected-error{{'end' is a private member of 'PrivateEnd'}} |
| 72 | |
| 73 | // FIXME: This diagnostic should be improved as well. It should not mention a |
| 74 | // deleted function, and we should not issue a FixIt suggesting a dereference. |
| 75 | PrivateEnd *pPE; |
| 76 | for (auto i : pPE) { }// expected-error {{invalid range expression of type 'PrivateEnd *'}} |
| 77 | |
| 78 | DeletedADLBegin DAB; |
| 79 | for (auto i : DAB) { } // expected-error {{call to deleted function 'begin'}}\ |
| 80 | expected-note {{when looking up 'begin' function for range expression of type 'DeletedADLBegin'}} |
| 81 | |
| 82 | OverloadedStar OS; |
| 83 | for (auto i : *OS) { } |
| 84 | |
| 85 | for (auto i : OS) { } // expected-error {{invalid range expression of type 'OverloadedStar'; did you mean to dereference it with '*'?}} |
| 86 | } |