DeLesley Hutchins | 9cd5d40 | 2013-10-17 22:21:03 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wconsumed -fcxx-exceptions -std=c++11 %s |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 2 | |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 3 | // TODO: Switch to using macros for the expected warnings. |
| 4 | |
| 5 | #define CALLABLE_WHEN(...) __attribute__ ((callable_when(__VA_ARGS__))) |
| 6 | #define CONSUMABLE(state) __attribute__ ((consumable(state))) |
DeLesley Hutchins | d4f0e19 | 2013-10-17 23:23:53 +0000 | [diff] [blame] | 7 | #define PARAM_TYPESTATE(state) __attribute__ ((param_typestate(state))) |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 8 | #define RETURN_TYPESTATE(state) __attribute__ ((return_typestate(state))) |
DeLesley Hutchins | d4f0e19 | 2013-10-17 23:23:53 +0000 | [diff] [blame] | 9 | #define SET_TYPESTATE(state) __attribute__ ((set_typestate(state))) |
DeLesley Hutchins | 1bf6343 | 2013-10-11 22:30:48 +0000 | [diff] [blame] | 10 | #define TESTS_TYPESTATE(state) __attribute__ ((tests_typestate(state))) |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 11 | |
| 12 | typedef decltype(nullptr) nullptr_t; |
| 13 | |
| 14 | template <typename T> |
David Blaikie | a33ab60 | 2013-09-06 01:28:43 +0000 | [diff] [blame] | 15 | class CONSUMABLE(unconsumed) ConsumableClass { |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 16 | T var; |
| 17 | |
DeLesley Hutchins | 627c7f9 | 2013-10-11 21:55:33 +0000 | [diff] [blame] | 18 | public: |
DeLesley Hutchins | b7dc1f5 | 2013-08-29 17:26:57 +0000 | [diff] [blame] | 19 | ConsumableClass(); |
DeLesley Hutchins | 0e8534e | 2013-09-03 20:11:38 +0000 | [diff] [blame] | 20 | ConsumableClass(nullptr_t p) RETURN_TYPESTATE(consumed); |
| 21 | ConsumableClass(T val) RETURN_TYPESTATE(unconsumed); |
David Blaikie | a33ab60 | 2013-09-06 01:28:43 +0000 | [diff] [blame] | 22 | ConsumableClass(ConsumableClass<T> &other); |
| 23 | ConsumableClass(ConsumableClass<T> &&other); |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 24 | |
DeLesley Hutchins | 9e8bd1d | 2013-08-23 18:40:39 +0000 | [diff] [blame] | 25 | ConsumableClass<T>& operator=(ConsumableClass<T> &other); |
| 26 | ConsumableClass<T>& operator=(ConsumableClass<T> &&other); |
DeLesley Hutchins | f30e194 | 2013-10-11 23:03:26 +0000 | [diff] [blame] | 27 | ConsumableClass<T>& operator=(nullptr_t) SET_TYPESTATE(consumed); |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 28 | |
| 29 | template <typename U> |
DeLesley Hutchins | 9e8bd1d | 2013-08-23 18:40:39 +0000 | [diff] [blame] | 30 | ConsumableClass<T>& operator=(ConsumableClass<U> &other); |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 31 | |
| 32 | template <typename U> |
DeLesley Hutchins | 9e8bd1d | 2013-08-23 18:40:39 +0000 | [diff] [blame] | 33 | ConsumableClass<T>& operator=(ConsumableClass<U> &&other); |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 34 | |
DeLesley Hutchins | f30e194 | 2013-10-11 23:03:26 +0000 | [diff] [blame] | 35 | void operator()(int a) SET_TYPESTATE(consumed); |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 36 | void operator*() const CALLABLE_WHEN("unconsumed"); |
| 37 | void unconsumedCall() const CALLABLE_WHEN("unconsumed"); |
| 38 | void callableWhenUnknown() const CALLABLE_WHEN("unconsumed", "unknown"); |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 39 | |
DeLesley Hutchins | 1bf6343 | 2013-10-11 22:30:48 +0000 | [diff] [blame] | 40 | bool isValid() const TESTS_TYPESTATE(unconsumed); |
| 41 | operator bool() const TESTS_TYPESTATE(unconsumed); |
| 42 | bool operator!=(nullptr_t) const TESTS_TYPESTATE(unconsumed); |
| 43 | bool operator==(nullptr_t) const TESTS_TYPESTATE(consumed); |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 44 | |
DeLesley Hutchins | b7dc1f5 | 2013-08-29 17:26:57 +0000 | [diff] [blame] | 45 | void constCall() const; |
| 46 | void nonconstCall(); |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 47 | |
DeLesley Hutchins | f30e194 | 2013-10-11 23:03:26 +0000 | [diff] [blame] | 48 | void consume() SET_TYPESTATE(consumed); |
| 49 | void unconsume() SET_TYPESTATE(unconsumed); |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
DeLesley Hutchins | 627c7f9 | 2013-10-11 21:55:33 +0000 | [diff] [blame] | 52 | class CONSUMABLE(unconsumed) DestructorTester { |
| 53 | public: |
DeLesley Hutchins | c5cdafc | 2013-10-18 18:36:21 +0000 | [diff] [blame] | 54 | DestructorTester() RETURN_TYPESTATE(unconsumed); |
DeLesley Hutchins | 627c7f9 | 2013-10-11 21:55:33 +0000 | [diff] [blame] | 55 | DestructorTester(int); |
| 56 | |
DeLesley Hutchins | c5cdafc | 2013-10-18 18:36:21 +0000 | [diff] [blame] | 57 | void operator*() CALLABLE_WHEN("unconsumed"); |
DeLesley Hutchins | 627c7f9 | 2013-10-11 21:55:33 +0000 | [diff] [blame] | 58 | |
| 59 | ~DestructorTester() CALLABLE_WHEN("consumed"); |
| 60 | }; |
| 61 | |
DeLesley Hutchins | 9e8bd1d | 2013-08-23 18:40:39 +0000 | [diff] [blame] | 62 | void baf0(const ConsumableClass<int> var); |
| 63 | void baf1(const ConsumableClass<int> &var); |
| 64 | void baf2(const ConsumableClass<int> *var); |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 65 | |
DeLesley Hutchins | be63ab6 | 2013-10-18 19:25:18 +0000 | [diff] [blame^] | 66 | void baf3(ConsumableClass<int> var); |
| 67 | void baf4(ConsumableClass<int> &var); |
| 68 | void baf5(ConsumableClass<int> *var); |
| 69 | void baf6(ConsumableClass<int> &&var); |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 70 | |
DeLesley Hutchins | 0e8534e | 2013-09-03 20:11:38 +0000 | [diff] [blame] | 71 | ConsumableClass<int> returnsUnconsumed() { |
| 72 | return ConsumableClass<int>(); // expected-warning {{return value not in expected state; expected 'unconsumed', observed 'consumed'}} |
| 73 | } |
| 74 | |
| 75 | ConsumableClass<int> returnsConsumed() RETURN_TYPESTATE(consumed); |
| 76 | ConsumableClass<int> returnsConsumed() { |
| 77 | return ConsumableClass<int>(); |
| 78 | } |
| 79 | |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 80 | ConsumableClass<int> returnsUnknown() RETURN_TYPESTATE(unknown); |
| 81 | |
DeLesley Hutchins | b7dc1f5 | 2013-08-29 17:26:57 +0000 | [diff] [blame] | 82 | void testInitialization() { |
DeLesley Hutchins | 9e8bd1d | 2013-08-23 18:40:39 +0000 | [diff] [blame] | 83 | ConsumableClass<int> var0; |
| 84 | ConsumableClass<int> var1 = ConsumableClass<int>(); |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 85 | |
DeLesley Hutchins | 9e8bd1d | 2013-08-23 18:40:39 +0000 | [diff] [blame] | 86 | var0 = ConsumableClass<int>(); |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 87 | |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 88 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}} |
| 89 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}} |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 90 | |
| 91 | if (var0.isValid()) { |
| 92 | *var0; |
DeLesley Hutchins | b7dc1f5 | 2013-08-29 17:26:57 +0000 | [diff] [blame] | 93 | *var1; |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 94 | |
| 95 | } else { |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 96 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}} |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | |
DeLesley Hutchins | 627c7f9 | 2013-10-11 21:55:33 +0000 | [diff] [blame] | 100 | void testDestruction() { |
| 101 | DestructorTester D0(42), D1(42); |
| 102 | |
| 103 | *D0; |
| 104 | *D1; |
| 105 | |
DeLesley Hutchins | c5cdafc | 2013-10-18 18:36:21 +0000 | [diff] [blame] | 106 | DestructorTester D2; |
| 107 | *D2; |
| 108 | |
DeLesley Hutchins | 627c7f9 | 2013-10-11 21:55:33 +0000 | [diff] [blame] | 109 | D0.~DestructorTester(); // expected-warning {{invalid invocation of method '~DestructorTester' on object 'D0' while it is in the 'unconsumed' state}} |
| 110 | |
DeLesley Hutchins | c5cdafc | 2013-10-18 18:36:21 +0000 | [diff] [blame] | 111 | return; // expected-warning {{invalid invocation of method '~DestructorTester' on object 'D0' while it is in the 'unconsumed' state}} \ |
| 112 | expected-warning {{invalid invocation of method '~DestructorTester' on object 'D1' while it is in the 'unconsumed' state}} \ |
| 113 | expected-warning {{invalid invocation of method '~DestructorTester' on object 'D2' while it is in the 'unconsumed' state}} |
DeLesley Hutchins | 627c7f9 | 2013-10-11 21:55:33 +0000 | [diff] [blame] | 114 | } |
| 115 | |
DeLesley Hutchins | 9e8bd1d | 2013-08-23 18:40:39 +0000 | [diff] [blame] | 116 | void testTempValue() { |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 117 | *ConsumableClass<int>(); // expected-warning {{invalid invocation of method 'operator*' on a temporary object while it is in the 'consumed' state}} |
DeLesley Hutchins | 5fdd207 | 2013-08-22 20:44:47 +0000 | [diff] [blame] | 118 | } |
| 119 | |
DeLesley Hutchins | b7dc1f5 | 2013-08-29 17:26:57 +0000 | [diff] [blame] | 120 | void testSimpleRValueRefs() { |
DeLesley Hutchins | 9e8bd1d | 2013-08-23 18:40:39 +0000 | [diff] [blame] | 121 | ConsumableClass<int> var0; |
| 122 | ConsumableClass<int> var1(42); |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 123 | |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 124 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}} |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 125 | *var1; |
| 126 | |
DeLesley Hutchins | 9e8bd1d | 2013-08-23 18:40:39 +0000 | [diff] [blame] | 127 | var0 = static_cast<ConsumableClass<int>&&>(var1); |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 128 | |
| 129 | *var0; |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 130 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}} |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 131 | } |
| 132 | |
DeLesley Hutchins | b7dc1f5 | 2013-08-29 17:26:57 +0000 | [diff] [blame] | 133 | void testIfStmt() { |
DeLesley Hutchins | 9e8bd1d | 2013-08-23 18:40:39 +0000 | [diff] [blame] | 134 | ConsumableClass<int> var; |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 135 | |
| 136 | if (var.isValid()) { |
DeLesley Hutchins | b7dc1f5 | 2013-08-29 17:26:57 +0000 | [diff] [blame] | 137 | *var; |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 138 | } else { |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 139 | *var; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}} |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | if (!var.isValid()) { |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 143 | *var; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}} |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 144 | } else { |
| 145 | *var; |
| 146 | } |
| 147 | |
| 148 | if (var) { |
| 149 | // Empty |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 150 | } else { |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 151 | *var; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}} |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 152 | } |
DeLesley Hutchins | 5fdd207 | 2013-08-22 20:44:47 +0000 | [diff] [blame] | 153 | |
| 154 | if (var != nullptr) { |
| 155 | // Empty |
DeLesley Hutchins | 5fdd207 | 2013-08-22 20:44:47 +0000 | [diff] [blame] | 156 | } else { |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 157 | *var; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}} |
DeLesley Hutchins | 5fdd207 | 2013-08-22 20:44:47 +0000 | [diff] [blame] | 158 | } |
DeLesley Hutchins | 1bf6343 | 2013-10-11 22:30:48 +0000 | [diff] [blame] | 159 | |
| 160 | if (var == nullptr) { |
| 161 | *var; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}} |
| 162 | } else { |
| 163 | // Empty |
| 164 | } |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 165 | } |
| 166 | |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 167 | void testComplexConditionals0() { |
DeLesley Hutchins | b7dc1f5 | 2013-08-29 17:26:57 +0000 | [diff] [blame] | 168 | ConsumableClass<int> var0, var1, var2; |
| 169 | |
| 170 | if (var0 && var1) { |
| 171 | *var0; |
| 172 | *var1; |
| 173 | |
| 174 | } else { |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 175 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}} |
| 176 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}} |
DeLesley Hutchins | b7dc1f5 | 2013-08-29 17:26:57 +0000 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | if (var0 || var1) { |
| 180 | *var0; |
| 181 | *var1; |
| 182 | |
| 183 | } else { |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 184 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}} |
| 185 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}} |
DeLesley Hutchins | b7dc1f5 | 2013-08-29 17:26:57 +0000 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | if (var0 && !var1) { |
| 189 | *var0; |
| 190 | *var1; |
| 191 | |
| 192 | } else { |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 193 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}} |
| 194 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}} |
DeLesley Hutchins | b7dc1f5 | 2013-08-29 17:26:57 +0000 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | if (var0 || !var1) { |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 198 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}} |
| 199 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}} |
DeLesley Hutchins | b7dc1f5 | 2013-08-29 17:26:57 +0000 | [diff] [blame] | 200 | |
| 201 | } else { |
| 202 | *var0; |
| 203 | *var1; |
| 204 | } |
| 205 | |
| 206 | if (!var0 && !var1) { |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 207 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}} |
| 208 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}} |
DeLesley Hutchins | b7dc1f5 | 2013-08-29 17:26:57 +0000 | [diff] [blame] | 209 | |
| 210 | } else { |
| 211 | *var0; |
| 212 | *var1; |
| 213 | } |
| 214 | |
| 215 | if (!var0 || !var1) { |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 216 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}} |
| 217 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}} |
DeLesley Hutchins | b7dc1f5 | 2013-08-29 17:26:57 +0000 | [diff] [blame] | 218 | |
| 219 | } else { |
| 220 | *var0; |
| 221 | *var1; |
| 222 | } |
| 223 | |
| 224 | if (!(var0 && var1)) { |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 225 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}} |
| 226 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}} |
DeLesley Hutchins | b7dc1f5 | 2013-08-29 17:26:57 +0000 | [diff] [blame] | 227 | |
| 228 | } else { |
| 229 | *var0; |
| 230 | *var1; |
| 231 | } |
| 232 | |
| 233 | if (!(var0 || var1)) { |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 234 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}} |
| 235 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}} |
DeLesley Hutchins | b7dc1f5 | 2013-08-29 17:26:57 +0000 | [diff] [blame] | 236 | |
| 237 | } else { |
| 238 | *var0; |
| 239 | *var1; |
| 240 | } |
| 241 | |
| 242 | if (var0 && var1 && var2) { |
| 243 | *var0; |
| 244 | *var1; |
| 245 | *var2; |
| 246 | |
| 247 | } else { |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 248 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}} |
| 249 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}} |
| 250 | *var2; // expected-warning {{invalid invocation of method 'operator*' on object 'var2' while it is in the 'consumed' state}} |
DeLesley Hutchins | b7dc1f5 | 2013-08-29 17:26:57 +0000 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | #if 0 |
| 254 | // FIXME: Get this test to pass. |
| 255 | if (var0 || var1 || var2) { |
| 256 | *var0; |
| 257 | *var1; |
| 258 | *var2; |
| 259 | |
| 260 | } else { |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 261 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}} |
| 262 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}} |
| 263 | *var2; // expected-warning {{invalid invocation of method 'operator*' on object 'var2' while it is in the 'consumed' state}} |
| 264 | } |
| 265 | #endif |
| 266 | } |
| 267 | |
| 268 | void testComplexConditionals1() { |
| 269 | ConsumableClass<int> var0, var1, var2; |
| 270 | |
| 271 | // Coerce all variables into the unknown state. |
DeLesley Hutchins | be63ab6 | 2013-10-18 19:25:18 +0000 | [diff] [blame^] | 272 | baf4(var0); |
| 273 | baf4(var1); |
| 274 | baf4(var2); |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 275 | |
| 276 | if (var0 && var1) { |
| 277 | *var0; |
| 278 | *var1; |
| 279 | |
| 280 | } else { |
| 281 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'unknown' state}} |
| 282 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'unknown' state}} |
| 283 | } |
| 284 | |
| 285 | if (var0 || var1) { |
| 286 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'unknown' state}} |
| 287 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'unknown' state}} |
| 288 | |
| 289 | } else { |
| 290 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}} |
| 291 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}} |
| 292 | } |
| 293 | |
| 294 | if (var0 && !var1) { |
| 295 | *var0; |
| 296 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}} |
| 297 | |
| 298 | } else { |
| 299 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'unknown' state}} |
| 300 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'unknown' state}} |
| 301 | } |
| 302 | |
| 303 | if (var0 || !var1) { |
| 304 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'unknown' state}} |
| 305 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'unknown' state}} |
| 306 | |
| 307 | } else { |
| 308 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}} |
| 309 | *var1; |
| 310 | } |
| 311 | |
| 312 | if (!var0 && !var1) { |
| 313 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}} |
| 314 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}} |
| 315 | |
| 316 | } else { |
| 317 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'unknown' state}} |
| 318 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'unknown' state}} |
| 319 | } |
| 320 | |
| 321 | if (!(var0 || var1)) { |
| 322 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}} |
| 323 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}} |
| 324 | |
| 325 | } else { |
| 326 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'unknown' state}} |
| 327 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'unknown' state}} |
| 328 | } |
| 329 | |
| 330 | if (!var0 || !var1) { |
| 331 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'unknown' state}} |
| 332 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'unknown' state}} |
| 333 | |
| 334 | } else { |
| 335 | *var0; |
| 336 | *var1; |
| 337 | } |
| 338 | |
| 339 | if (!(var0 && var1)) { |
| 340 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'unknown' state}} |
| 341 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'unknown' state}} |
| 342 | |
| 343 | } else { |
| 344 | *var0; |
| 345 | *var1; |
| 346 | } |
| 347 | |
| 348 | if (var0 && var1 && var2) { |
| 349 | *var0; |
| 350 | *var1; |
| 351 | *var2; |
| 352 | |
| 353 | } else { |
| 354 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'unknown' state}} |
| 355 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'unknown' state}} |
| 356 | *var2; // expected-warning {{invalid invocation of method 'operator*' on object 'var2' while it is in the 'unknown' state}} |
| 357 | } |
| 358 | |
| 359 | #if 0 |
| 360 | // FIXME: Get this test to pass. |
| 361 | if (var0 || var1 || var2) { |
| 362 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'unknown' state}} |
| 363 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'unknown' state}} |
| 364 | *var2; // expected-warning {{invalid invocation of method 'operator*' on object 'var2' while it is in the 'unknown' state}} |
| 365 | |
| 366 | } else { |
| 367 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}} |
| 368 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}} |
| 369 | *var2; // expected-warning {{invalid invocation of method 'operator*' on object 'var2' while it is in the 'consumed' state}} |
DeLesley Hutchins | b7dc1f5 | 2013-08-29 17:26:57 +0000 | [diff] [blame] | 370 | } |
| 371 | #endif |
| 372 | } |
| 373 | |
| 374 | void testStateChangeInBranch() { |
| 375 | ConsumableClass<int> var; |
| 376 | |
| 377 | // Make var enter the 'unknown' state. |
DeLesley Hutchins | be63ab6 | 2013-10-18 19:25:18 +0000 | [diff] [blame^] | 378 | baf4(var); |
DeLesley Hutchins | b7dc1f5 | 2013-08-29 17:26:57 +0000 | [diff] [blame] | 379 | |
| 380 | if (!var) { |
| 381 | var = ConsumableClass<int>(42); |
| 382 | } |
| 383 | |
| 384 | *var; |
| 385 | } |
| 386 | |
DeLesley Hutchins | 4252598 | 2013-08-29 22:36:05 +0000 | [diff] [blame] | 387 | void testFunctionParam(ConsumableClass<int> param) { |
| 388 | |
| 389 | if (param.isValid()) { |
| 390 | *param; |
| 391 | } else { |
David Blaikie | a33ab60 | 2013-09-06 01:28:43 +0000 | [diff] [blame] | 392 | *param; |
DeLesley Hutchins | 4252598 | 2013-08-29 22:36:05 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | param = nullptr; |
| 396 | *param; // expected-warning {{invocation of method 'operator*' on object 'param' while it is in the 'consumed' state}} |
| 397 | } |
| 398 | |
DeLesley Hutchins | cd0f6d7 | 2013-10-17 22:53:04 +0000 | [diff] [blame] | 399 | void testParamReturnTypestateCallee(bool cond, ConsumableClass<int> &Param RETURN_TYPESTATE(unconsumed)) { // expected-warning {{parameter 'Param' not in expected state when the function returns: expected 'unconsumed', observed 'consumed'}} |
| 400 | |
| 401 | if (cond) { |
| 402 | Param.consume(); |
| 403 | return; // expected-warning {{parameter 'Param' not in expected state when the function returns: expected 'unconsumed', observed 'consumed'}} |
| 404 | } |
| 405 | |
| 406 | Param.consume(); |
| 407 | } |
| 408 | |
| 409 | void testParamReturnTypestateCaller() { |
| 410 | ConsumableClass<int> var; |
| 411 | |
| 412 | testParamReturnTypestateCallee(true, var); |
| 413 | |
| 414 | *var; |
| 415 | } |
| 416 | |
DeLesley Hutchins | d4f0e19 | 2013-10-17 23:23:53 +0000 | [diff] [blame] | 417 | void testParamTypestateCallee(ConsumableClass<int> Param0 PARAM_TYPESTATE(consumed), |
| 418 | ConsumableClass<int> &Param1 PARAM_TYPESTATE(consumed)) { |
| 419 | |
| 420 | *Param0; // expected-warning {{invalid invocation of method 'operator*' on object 'Param0' while it is in the 'consumed' state}} |
| 421 | *Param1; // expected-warning {{invalid invocation of method 'operator*' on object 'Param1' while it is in the 'consumed' state}} |
| 422 | } |
| 423 | |
| 424 | void testParamTypestateCaller() { |
| 425 | ConsumableClass<int> Var0, Var1(42); |
| 426 | |
| 427 | testParamTypestateCallee(Var0, Var1); // expected-warning {{argument not in expected state; expected 'consumed', observed 'unconsumed'}} |
| 428 | } |
| 429 | |
DeLesley Hutchins | be63ab6 | 2013-10-18 19:25:18 +0000 | [diff] [blame^] | 430 | void baf3(ConsumableClass<int> var) { |
| 431 | *var; |
| 432 | } |
| 433 | |
| 434 | void baf4(ConsumableClass<int> &var) { |
| 435 | *var; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'unknown' state}} |
| 436 | } |
| 437 | |
| 438 | void baf6(ConsumableClass<int> &&var) { |
| 439 | *var; |
| 440 | } |
| 441 | |
DeLesley Hutchins | b7dc1f5 | 2013-08-29 17:26:57 +0000 | [diff] [blame] | 442 | void testCallingConventions() { |
DeLesley Hutchins | 9e8bd1d | 2013-08-23 18:40:39 +0000 | [diff] [blame] | 443 | ConsumableClass<int> var(42); |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 444 | |
| 445 | baf0(var); |
| 446 | *var; |
| 447 | |
| 448 | baf1(var); |
| 449 | *var; |
| 450 | |
| 451 | baf2(&var); |
| 452 | *var; |
| 453 | |
DeLesley Hutchins | be63ab6 | 2013-10-18 19:25:18 +0000 | [diff] [blame^] | 454 | baf4(var); |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 455 | *var; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'unknown' state}} |
| 456 | |
| 457 | var = ConsumableClass<int>(42); |
DeLesley Hutchins | be63ab6 | 2013-10-18 19:25:18 +0000 | [diff] [blame^] | 458 | baf5(&var); |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 459 | *var; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'unknown' state}} |
| 460 | |
| 461 | var = ConsumableClass<int>(42); |
DeLesley Hutchins | be63ab6 | 2013-10-18 19:25:18 +0000 | [diff] [blame^] | 462 | baf6(static_cast<ConsumableClass<int>&&>(var)); |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 463 | *var; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}} |
| 464 | } |
| 465 | |
| 466 | void testConstAndNonConstMemberFunctions() { |
| 467 | ConsumableClass<int> var(42); |
| 468 | |
| 469 | var.constCall(); |
| 470 | *var; |
| 471 | |
| 472 | var.nonconstCall(); |
| 473 | *var; |
| 474 | } |
| 475 | |
| 476 | void testFunctionParam0(ConsumableClass<int> param) { |
| 477 | *param; |
| 478 | } |
| 479 | |
| 480 | void testFunctionParam1(ConsumableClass<int> ¶m) { |
| 481 | *param; // expected-warning {{invalid invocation of method 'operator*' on object 'param' while it is in the 'unknown' state}} |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 482 | } |
| 483 | |
DeLesley Hutchins | 0e8534e | 2013-09-03 20:11:38 +0000 | [diff] [blame] | 484 | void testReturnStates() { |
| 485 | ConsumableClass<int> var; |
| 486 | |
| 487 | var = returnsUnconsumed(); |
| 488 | *var; |
| 489 | |
| 490 | var = returnsConsumed(); |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 491 | *var; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}} |
| 492 | } |
| 493 | |
| 494 | void testCallableWhen() { |
| 495 | ConsumableClass<int> var(42); |
| 496 | |
| 497 | *var; |
| 498 | |
DeLesley Hutchins | be63ab6 | 2013-10-18 19:25:18 +0000 | [diff] [blame^] | 499 | baf4(var); |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 500 | |
| 501 | var.callableWhenUnknown(); |
DeLesley Hutchins | 0e8534e | 2013-09-03 20:11:38 +0000 | [diff] [blame] | 502 | } |
| 503 | |
DeLesley Hutchins | b7dc1f5 | 2013-08-29 17:26:57 +0000 | [diff] [blame] | 504 | void testMoveAsignmentish() { |
DeLesley Hutchins | 9e8bd1d | 2013-08-23 18:40:39 +0000 | [diff] [blame] | 505 | ConsumableClass<int> var0; |
| 506 | ConsumableClass<long> var1(42); |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 507 | |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 508 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}} |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 509 | *var1; |
| 510 | |
DeLesley Hutchins | 9e8bd1d | 2013-08-23 18:40:39 +0000 | [diff] [blame] | 511 | var0 = static_cast<ConsumableClass<long>&&>(var1); |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 512 | |
| 513 | *var0; |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 514 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}} |
DeLesley Hutchins | d324a0b | 2013-08-29 21:17:25 +0000 | [diff] [blame] | 515 | |
| 516 | var1 = ConsumableClass<long>(42); |
| 517 | var1 = nullptr; |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 518 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}} |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 519 | } |
| 520 | |
DeLesley Hutchins | b7dc1f5 | 2013-08-29 17:26:57 +0000 | [diff] [blame] | 521 | void testConditionalMerge() { |
DeLesley Hutchins | 9e8bd1d | 2013-08-23 18:40:39 +0000 | [diff] [blame] | 522 | ConsumableClass<int> var; |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 523 | |
| 524 | if (var.isValid()) { |
| 525 | // Empty |
| 526 | } |
| 527 | |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 528 | *var; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}} |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 529 | |
| 530 | if (var.isValid()) { |
| 531 | // Empty |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 532 | } else { |
| 533 | // Empty |
| 534 | } |
| 535 | |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 536 | *var; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}} |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 537 | } |
| 538 | |
DeLesley Hutchins | f30e194 | 2013-10-11 23:03:26 +0000 | [diff] [blame] | 539 | void testSetTypestate() { |
DeLesley Hutchins | 9e8bd1d | 2013-08-23 18:40:39 +0000 | [diff] [blame] | 540 | ConsumableClass<int> var(42); |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 541 | |
| 542 | *var; |
| 543 | |
| 544 | var.consume(); |
| 545 | |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 546 | *var; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}} |
DeLesley Hutchins | f30e194 | 2013-10-11 23:03:26 +0000 | [diff] [blame] | 547 | |
| 548 | var.unconsume(); |
| 549 | |
| 550 | *var; |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 551 | } |
| 552 | |
DeLesley Hutchins | f30e194 | 2013-10-11 23:03:26 +0000 | [diff] [blame] | 553 | void testConsumes0() { |
DeLesley Hutchins | 9e8bd1d | 2013-08-23 18:40:39 +0000 | [diff] [blame] | 554 | ConsumableClass<int> var(nullptr); |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 555 | |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 556 | *var; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}} |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 557 | } |
| 558 | |
DeLesley Hutchins | f30e194 | 2013-10-11 23:03:26 +0000 | [diff] [blame] | 559 | void testConsumes1() { |
DeLesley Hutchins | 9e8bd1d | 2013-08-23 18:40:39 +0000 | [diff] [blame] | 560 | ConsumableClass<int> var(42); |
DeLesley Hutchins | 5fdd207 | 2013-08-22 20:44:47 +0000 | [diff] [blame] | 561 | |
| 562 | var.unconsumedCall(); |
| 563 | var(6); |
| 564 | |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 565 | var.unconsumedCall(); // expected-warning {{invalid invocation of method 'unconsumedCall' on object 'var' while it is in the 'consumed' state}} |
DeLesley Hutchins | 5fdd207 | 2013-08-22 20:44:47 +0000 | [diff] [blame] | 566 | } |
| 567 | |
DeLesley Hutchins | 6654085 | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 568 | void testUnreachableBlock() { |
DeLesley Hutchins | b7dc1f5 | 2013-08-29 17:26:57 +0000 | [diff] [blame] | 569 | ConsumableClass<int> var(42); |
| 570 | |
| 571 | if (var) { |
| 572 | *var; |
| 573 | } else { |
| 574 | *var; |
| 575 | } |
| 576 | |
| 577 | *var; |
| 578 | } |
| 579 | |
DeLesley Hutchins | 7385840 | 2013-10-09 18:30:24 +0000 | [diff] [blame] | 580 | |
| 581 | void testForLoop1() { |
| 582 | ConsumableClass<int> var0, var1(42); |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 583 | |
DeLesley Hutchins | 7385840 | 2013-10-09 18:30:24 +0000 | [diff] [blame] | 584 | for (int i = 0; i < 10; ++i) { // expected-warning {{state of variable 'var1' must match at the entry and exit of loop}} |
| 585 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}} |
| 586 | |
| 587 | *var1; |
| 588 | var1.consume(); |
| 589 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}} |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 590 | } |
| 591 | |
DeLesley Hutchins | 7385840 | 2013-10-09 18:30:24 +0000 | [diff] [blame] | 592 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}} |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 593 | } |
| 594 | |
DeLesley Hutchins | 7385840 | 2013-10-09 18:30:24 +0000 | [diff] [blame] | 595 | void testWhileLoop1() { |
| 596 | int i = 10; |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 597 | |
DeLesley Hutchins | 7385840 | 2013-10-09 18:30:24 +0000 | [diff] [blame] | 598 | ConsumableClass<int> var0, var1(42); |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 599 | |
DeLesley Hutchins | 52f717e | 2013-10-17 18:19:31 +0000 | [diff] [blame] | 600 | while (i-- > 0) { // expected-warning {{state of variable 'var1' must match at the entry and exit of loop}} |
DeLesley Hutchins | 7385840 | 2013-10-09 18:30:24 +0000 | [diff] [blame] | 601 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}} |
| 602 | |
| 603 | *var1; |
| 604 | var1.consume(); |
DeLesley Hutchins | 52f717e | 2013-10-17 18:19:31 +0000 | [diff] [blame] | 605 | *var1; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}} |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 606 | } |
| 607 | |
DeLesley Hutchins | 7385840 | 2013-10-09 18:30:24 +0000 | [diff] [blame] | 608 | *var0; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}} |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 609 | } |
DeLesley Hutchins | 52f717e | 2013-10-17 18:19:31 +0000 | [diff] [blame] | 610 | |
| 611 | |
| 612 | namespace ContinueICETest { |
| 613 | |
| 614 | bool cond1(); |
| 615 | bool cond2(); |
| 616 | |
| 617 | static void foo1() { |
| 618 | while (cond1()) { |
| 619 | if (cond2()) |
| 620 | continue; |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | static void foo2() { |
| 625 | while (true) { |
| 626 | if (false) |
| 627 | continue; |
| 628 | } |
| 629 | } |
| 630 | |
DeLesley Hutchins | 9cd5d40 | 2013-10-17 22:21:03 +0000 | [diff] [blame] | 631 | class runtime_error |
| 632 | { |
| 633 | public: |
| 634 | virtual ~runtime_error(); |
| 635 | }; |
| 636 | |
| 637 | void read(bool sf) { |
| 638 | while (sf) { |
| 639 | if(sf) throw runtime_error(); |
| 640 | } |
| 641 | } |
| 642 | |
DeLesley Hutchins | 52f717e | 2013-10-17 18:19:31 +0000 | [diff] [blame] | 643 | } // end namespace ContinueICETest |
| 644 | |