1 // RUN: %clang_cc1 -fsyntax-only -verify -Wconsumed -fcxx-exceptions -std=c++11 %s
3 // TODO: Switch to using macros for the expected warnings.
5 #define CALLABLE_WHEN(...) __attribute__ ((callable_when(__VA_ARGS__)))
6 #define CONSUMABLE(state) __attribute__ ((consumable(state)))
7 #define PARAM_TYPESTATE(state) __attribute__ ((param_typestate(state)))
8 #define RETURN_TYPESTATE(state) __attribute__ ((return_typestate(state)))
9 #define SET_TYPESTATE(state) __attribute__ ((set_typestate(state)))
10 #define TEST_TYPESTATE(state) __attribute__ ((test_typestate(state)))
12 typedef decltype(nullptr) nullptr_t
;
15 class CONSUMABLE(unconsumed
) ConsumableClass
{
20 ConsumableClass(nullptr_t p
) RETURN_TYPESTATE(consumed
);
21 ConsumableClass(T val
) RETURN_TYPESTATE(unconsumed
);
22 ConsumableClass(ConsumableClass
<T
> &other
);
23 ConsumableClass(ConsumableClass
<T
> &&other
);
25 ConsumableClass
<T
>& operator=(ConsumableClass
<T
> &other
);
26 ConsumableClass
<T
>& operator=(ConsumableClass
<T
> &&other
);
27 ConsumableClass
<T
>& operator=(nullptr_t
) SET_TYPESTATE(consumed
);
30 ConsumableClass
<T
>& operator=(ConsumableClass
<U
> &other
);
33 ConsumableClass
<T
>& operator=(ConsumableClass
<U
> &&other
);
35 void operator()(int a
) SET_TYPESTATE(consumed
);
36 void operator*() const CALLABLE_WHEN("unconsumed");
37 void unconsumedCall() const CALLABLE_WHEN("unconsumed");
38 void callableWhenUnknown() const CALLABLE_WHEN("unconsumed", "unknown");
40 bool isValid() const TEST_TYPESTATE(unconsumed
);
41 operator bool() const TEST_TYPESTATE(unconsumed
);
42 bool operator!=(nullptr_t
) const TEST_TYPESTATE(unconsumed
);
43 bool operator==(nullptr_t
) const TEST_TYPESTATE(consumed
);
45 void constCall() const;
48 void consume() SET_TYPESTATE(consumed
);
49 void unconsume() SET_TYPESTATE(unconsumed
);
52 class CONSUMABLE(unconsumed
) DestructorTester
{
55 DestructorTester(int);
56 DestructorTester(nullptr_t
) RETURN_TYPESTATE(unconsumed
);
57 DestructorTester(DestructorTester
&&);
59 void operator*() CALLABLE_WHEN("unconsumed");
61 ~DestructorTester() CALLABLE_WHEN("consumed");
65 void dtByVal(DestructorTester
);
66 void dtByValMarkUnconsumed(DestructorTester
RETURN_TYPESTATE(unconsumed
));
68 void baf0(const ConsumableClass
<int> var
);
69 void baf1(const ConsumableClass
<int> &var
);
70 void baf2(const ConsumableClass
<int> *var
);
72 void baf3(ConsumableClass
<int> var
);
73 void baf4(ConsumableClass
<int> &var
);
74 void baf5(ConsumableClass
<int> *var
);
75 void baf6(ConsumableClass
<int> &&var
);
77 ConsumableClass
<int> returnsUnconsumed() {
78 return ConsumableClass
<int>(); // expected-warning {{return value not in expected state; expected 'unconsumed', observed 'consumed'}}
81 ConsumableClass
<int> returnsConsumed() RETURN_TYPESTATE(consumed
);
82 ConsumableClass
<int> returnsConsumed() {
83 return ConsumableClass
<int>();
86 ConsumableClass
<int> returnsUnknown() RETURN_TYPESTATE(unknown
);
88 void testInitialization() {
89 ConsumableClass
<int> var0
;
90 ConsumableClass
<int> var1
= ConsumableClass
<int>();
91 ConsumableClass
<int> var2(42);
92 ConsumableClass
<int> var3(var2
); // copy constructor
93 ConsumableClass
<int> var4(var0
); // copy consumed value
95 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}}
96 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}}
99 *var4
; // expected-warning {{invalid invocation of method 'operator*' on object 'var4' while it is in the 'consumed' state}}
101 var0
= ConsumableClass
<int>(42);
105 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}}
107 if (var0
.isValid()) {
112 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}}
116 void testDestruction() {
117 DestructorTester
D0(42), D1(42), D2
;
121 *D2
; // expected-warning {{invalid invocation of method 'operator*' on object 'D2' while it is in the 'consumed' state}}
123 D0
.~DestructorTester(); // expected-warning {{invalid invocation of method '~DestructorTester' on object 'D0' while it is in the 'unconsumed' state}}
125 return; // expected-warning {{invalid invocation of method '~DestructorTester' on object 'D0' while it is in the 'unconsumed' state}} \
126 expected
-warning
{{invalid invocation of method
'~DestructorTester' on object
'D1' while it is in the
'unconsumed' state
}}
129 void testDestructionByVal() {
131 // both the var and the temporary are consumed:
132 DestructorTester
D0(nullptr);
133 dtByVal((DestructorTester
&&)D0
);
136 // the var is consumed but the temporary isn't:
137 DestructorTester
D1(nullptr);
138 dtByValMarkUnconsumed((DestructorTester
&&)D1
); // expected-warning {{invalid invocation of method '~DestructorTester' on a temporary object while it is in the 'unconsumed' state}}
142 void testTempValue() {
143 *ConsumableClass
<int>(); // expected-warning {{invalid invocation of method 'operator*' on a temporary object while it is in the 'consumed' state}}
146 void testSimpleRValueRefs() {
147 ConsumableClass
<int> var0
;
148 ConsumableClass
<int> var1(42);
150 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}}
153 var0
= static_cast<ConsumableClass
<int>&&>(var1
);
156 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}}
160 ConsumableClass
<int> var
;
165 *var
; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}}
168 if (!var
.isValid()) {
169 *var
; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}}
177 *var
; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}}
180 if (var
!= nullptr) {
183 *var
; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}}
186 if (var
== nullptr) {
187 *var
; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}}
193 void testComplexConditionals0() {
194 ConsumableClass
<int> var0
, var1
, var2
;
201 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}}
202 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}}
210 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}}
211 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}}
219 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}}
220 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}}
224 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}}
225 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}}
232 if (!var0
&& !var1
) {
233 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}}
234 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}}
241 if (!var0
|| !var1
) {
242 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}}
243 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}}
250 if (!(var0
&& var1
)) {
251 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}}
252 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}}
259 if (!(var0
|| var1
)) {
260 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}}
261 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}}
268 if (var0
&& var1
&& var2
) {
274 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}}
275 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}}
276 *var2
; // expected-warning {{invalid invocation of method 'operator*' on object 'var2' while it is in the 'consumed' state}}
280 // FIXME: Get this test to pass.
281 if (var0
|| var1
|| var2
) {
287 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}}
288 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}}
289 *var2
; // expected-warning {{invalid invocation of method 'operator*' on object 'var2' while it is in the 'consumed' state}}
294 void testComplexConditionals1() {
295 ConsumableClass
<int> var0
, var1
, var2
;
297 // Coerce all variables into the unknown state.
307 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'unknown' state}}
308 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'unknown' state}}
312 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'unknown' state}}
313 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'unknown' state}}
316 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}}
317 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}}
322 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}}
325 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'unknown' state}}
326 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'unknown' state}}
330 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'unknown' state}}
331 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'unknown' state}}
334 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}}
338 if (!var0
&& !var1
) {
339 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}}
340 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}}
343 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'unknown' state}}
344 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'unknown' state}}
347 if (!(var0
|| var1
)) {
348 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}}
349 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}}
352 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'unknown' state}}
353 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'unknown' state}}
356 if (!var0
|| !var1
) {
357 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'unknown' state}}
358 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'unknown' state}}
365 if (!(var0
&& var1
)) {
366 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'unknown' state}}
367 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'unknown' state}}
374 if (var0
&& var1
&& var2
) {
380 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'unknown' state}}
381 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'unknown' state}}
382 *var2
; // expected-warning {{invalid invocation of method 'operator*' on object 'var2' while it is in the 'unknown' state}}
386 // FIXME: Get this test to pass.
387 if (var0
|| var1
|| var2
) {
388 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'unknown' state}}
389 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'unknown' state}}
390 *var2
; // expected-warning {{invalid invocation of method 'operator*' on object 'var2' while it is in the 'unknown' state}}
393 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}}
394 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}}
395 *var2
; // expected-warning {{invalid invocation of method 'operator*' on object 'var2' while it is in the 'consumed' state}}
400 void testStateChangeInBranch() {
401 ConsumableClass
<int> var
;
403 // Make var enter the 'unknown' state.
407 var
= ConsumableClass
<int>(42);
413 void testFunctionParam(ConsumableClass
<int> param
) {
415 if (param
.isValid()) {
422 *param
; // expected-warning {{invocation of method 'operator*' on object 'param' while it is in the 'consumed' state}}
425 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'}}
429 return; // expected-warning {{parameter 'Param' not in expected state when the function returns: expected 'unconsumed', observed 'consumed'}}
435 void testRvalueRefParamReturnTypestateCallee(ConsumableClass
<int> &&Param
RETURN_TYPESTATE(unconsumed
)) {
439 void testParamReturnTypestateCaller() {
440 ConsumableClass
<int> var
;
442 testParamReturnTypestateCallee(true, var
);
443 testRvalueRefParamReturnTypestateCallee((ConsumableClass
<int> &&)var
);
448 void testParamTypestateCallee(ConsumableClass
<int> Param0
PARAM_TYPESTATE(consumed
),
449 ConsumableClass
<int> &Param1
PARAM_TYPESTATE(consumed
)) {
451 *Param0
; // expected-warning {{invalid invocation of method 'operator*' on object 'Param0' while it is in the 'consumed' state}}
452 *Param1
; // expected-warning {{invalid invocation of method 'operator*' on object 'Param1' while it is in the 'consumed' state}}
455 void testParamTypestateCaller() {
456 ConsumableClass
<int> Var0
, Var1(42);
458 testParamTypestateCallee(Var0
, Var1
); // expected-warning {{argument not in expected state; expected 'consumed', observed 'unconsumed'}}
462 void consumeFunc(ConsumableClass
<int> P
PARAM_TYPESTATE(unconsumed
));
464 static void consumeFuncStatic(ConsumableClass
<int> P
PARAM_TYPESTATE(unconsumed
));
465 void consumeFuncMeth(ConsumableClass
<int> P
PARAM_TYPESTATE(unconsumed
));
466 void operator<<(ConsumableClass
<int> P
PARAM_TYPESTATE(unconsumed
));
469 void operator>>(ParamTest
& pt
, ConsumableClass
<int> P
PARAM_TYPESTATE(unconsumed
));
472 void testFunctionParams() {
473 // Make sure we handle the different kinds of functions.
474 ConsumableClass
<int> P
;
476 consumeFunc(P
); // expected-warning {{argument not in expected state; expected 'unconsumed', observed 'consumed'}}
477 ParamTest::consumeFuncStatic(P
); // expected-warning {{argument not in expected state; expected 'unconsumed', observed 'consumed'}}
479 pt
.consumeFuncMeth(P
); // expected-warning {{argument not in expected state; expected 'unconsumed', observed 'consumed'}}
480 pt
<< P
; // expected-warning {{argument not in expected state; expected 'unconsumed', observed 'consumed'}}
481 pt
>> P
; // expected-warning {{argument not in expected state; expected 'unconsumed', observed 'consumed'}}
484 void baf3(ConsumableClass
<int> var
) {
488 void baf4(ConsumableClass
<int> &var
) {
489 *var
; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'unknown' state}}
492 void baf6(ConsumableClass
<int> &&var
) {
496 void testCallingConventions() {
497 ConsumableClass
<int> var(42);
512 *var
; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'unknown' state}}
514 var
= ConsumableClass
<int>(42);
516 *var
; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'unknown' state}}
518 var
= ConsumableClass
<int>(42);
519 baf6(static_cast<ConsumableClass
<int>&&>(var
));
520 *var
; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}}
523 void testConstAndNonConstMemberFunctions() {
524 ConsumableClass
<int> var(42);
533 void testFunctionParam0(ConsumableClass
<int> param
) {
537 void testFunctionParam1(ConsumableClass
<int> ¶m
) {
538 *param
; // expected-warning {{invalid invocation of method 'operator*' on object 'param' while it is in the 'unknown' state}}
541 void testReturnStates() {
542 ConsumableClass
<int> var
;
544 var
= returnsUnconsumed();
547 var
= returnsConsumed();
548 *var
; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}}
551 void testCallableWhen() {
552 ConsumableClass
<int> var(42);
558 var
.callableWhenUnknown();
561 void testMoveAsignmentish() {
562 ConsumableClass
<int> var0
;
563 ConsumableClass
<long> var1(42);
565 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}}
568 var0
= static_cast<ConsumableClass
<long>&&>(var1
);
571 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}}
573 var1
= ConsumableClass
<long>(42);
575 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}}
578 void testConditionalMerge() {
579 ConsumableClass
<int> var
;
585 *var
; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}}
593 *var
; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}}
596 void testSetTypestate() {
597 ConsumableClass
<int> var(42);
603 *var
; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}}
610 void testConsumes0() {
611 ConsumableClass
<int> var(nullptr);
613 *var
; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}}
616 void testConsumes1() {
617 ConsumableClass
<int> var(42);
619 var
.unconsumedCall();
622 var
.unconsumedCall(); // expected-warning {{invalid invocation of method 'unconsumedCall' on object 'var' while it is in the 'consumed' state}}
625 void testUnreachableBlock() {
626 ConsumableClass
<int> var(42);
638 void testForLoop1() {
639 ConsumableClass
<int> var0
, var1(42);
641 for (int i
= 0; i
< 10; ++i
) { // expected-warning {{state of variable 'var1' must match at the entry and exit of loop}}
642 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}}
646 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}}
649 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}}
652 void testWhileLoop1() {
655 ConsumableClass
<int> var0
, var1(42);
657 while (i
-- > 0) { // expected-warning {{state of variable 'var1' must match at the entry and exit of loop}}
658 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}}
662 *var1
; // expected-warning {{invalid invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}}
665 *var0
; // expected-warning {{invalid invocation of method 'operator*' on object 'var0' while it is in the 'consumed' state}}
668 // Tests if state information is correctly discarded for certain shapes of CFGs.
669 void testSwitchGOTO(void) {
680 typedef const int*& IntegerPointerReference
;
681 void testIsRValueRefishAndCanonicalType(IntegerPointerReference a
) {}
683 namespace ContinueICETest
{
705 virtual ~runtime_error();
710 if(sf
) throw runtime_error();
714 } // end namespace ContinueICETest
717 namespace StatusUseCaseTests
{
719 class CONSUMABLE(unconsumed
)
720 __attribute__((consumable_auto_cast_state
))
721 __attribute__((consumable_set_state_on_read
))
728 Status() RETURN_TYPESTATE(consumed
);
729 Status(int c
) RETURN_TYPESTATE(unconsumed
);
731 Status(const Status
&other
);
732 Status(Status
&&other
);
734 Status
& operator=(const Status
&other
) CALLABLE_WHEN("unknown", "consumed");
735 Status
& operator=(Status
&&other
) CALLABLE_WHEN("unknown", "consumed");
737 bool operator==(const Status
&other
) const SET_TYPESTATE(consumed
);
739 bool check() const SET_TYPESTATE(consumed
);
740 void ignore() const SET_TYPESTATE(consumed
);
741 // Status& markAsChecked() { return *this; }
743 void clear() CALLABLE_WHEN("unknown", "consumed") SET_TYPESTATE(consumed
);
745 ~Status() CALLABLE_WHEN("unknown", "consumed");
747 operator bool() const; // Will not consume the object.
752 Status
doSomething();
753 void handleStatus(const Status
& s
RETURN_TYPESTATE(consumed
));
754 void handleStatusRef(Status
& s
);
755 void handleStatusPtr(Status
* s
);
756 void handleStatusUnmarked(const Status
& s
);
758 void log(const char* msg
);
759 void fail() __attribute__((noreturn
));
760 void checkStat(const Status
& s
);
763 void testSimpleTemporaries0() {
764 doSomething(); // expected-warning {{invalid invocation of method '~Status' on a temporary object while it is in the 'unconsumed' state}}
767 void testSimpleTemporaries1() {
768 doSomething().ignore();
771 void testSimpleTemporaries2() {
772 handleStatus(doSomething());
775 void testSimpleTemporaries3() {
776 Status s
= doSomething();
777 } // expected-warning {{invalid invocation of method '~Status' on object 's' while it is in the 'unconsumed' state}}
779 void testTemporariesWithControlFlow(bool a
) {
780 bool b
= false || doSomething(); // expected-warning {{invalid invocation of method '~Status' on a temporary object while it is in the 'unconsumed' state}}
783 Status
testSimpleTemporariesReturn0() {
784 return doSomething();
787 Status
testSimpleTemporariesReturn1() {
788 Status s
= doSomething();
792 void testSimpleTemporaries4() {
793 Status s
= doSomething();
797 void testSimpleTemporaries5() {
798 Status s
= doSomething();
799 s
.clear(); // expected-warning {{invalid invocation of method 'clear' on object 's' while it is in the 'unconsumed' state}}
802 void testSimpleTemporaries6() {
803 Status s1
= doSomething();
806 Status s2
= doSomething();
809 Status s3
= doSomething();
810 handleStatusPtr(&s3
);
812 Status s4
= doSomething();
813 handleStatusUnmarked(s4
);
816 void testSimpleTemporaries7() {
819 } // expected-warning {{invalid invocation of method '~Status' on object 's' while it is in the 'unconsumed' state}}
821 void testTemporariesWithConditionals0() {
824 Status s
= doSomething();
827 } // expected-warning {{invalid invocation of method '~Status' on object 's' while it is in the 'unconsumed' state}}
829 void testTemporariesWithConditionals1() {
832 Status s
= doSomething();
838 void testTemporariesWithConditionals2() {
841 Status s
= doSomething();
847 void testTemporariesWithConditionals3() {
848 Status s
= doSomething();
854 void testTemporariesAndConstructors0() {
855 Status
s(doSomething()); // Test the copy constructor.
859 void testTemporariesAndConstructors1F() {
860 Status s1
= doSomething(); // Test the copy constructor.
862 } // expected-warning {{invalid invocation of method '~Status' on object 's2' while it is in the 'unconsumed' state}}
864 void testTemporariesAndConstructors1S() {
865 Status s1
= doSomething(); // Test the copy constructor.
870 void testTemporariesAndConstructors2F() {
871 // Test the move constructor.
872 Status s1
= doSomething();
873 Status s2
= static_cast<Status
&&>(s1
);
874 } // expected-warning {{invalid invocation of method '~Status' on object 's2' while it is in the 'unconsumed' state}}
876 void testTemporariesAndConstructors2S() {
877 // Test the move constructor.
878 Status s1
= doSomething();
879 Status s2
= static_cast<Status
&&>(s1
);
883 void testTemporariesAndOperators0F() {
884 // Test the assignment operator.
885 Status s1
= doSomething();
888 } // expected-warning {{invalid invocation of method '~Status' on object 's2' while it is in the 'unconsumed' state}}
890 void testTemporariesAndOperators0S() {
891 // Test the assignment operator.
892 Status s1
= doSomething();
898 void testTemporariesAndOperators1F() {
899 // Test the move assignment operator.
900 Status s1
= doSomething();
902 s2
= static_cast<Status
&&>(s1
);
903 } // expected-warning {{invalid invocation of method '~Status' on object 's2' while it is in the 'unconsumed' state}}
905 void testTemporariesAndOperators1S() {
906 // Test the move assignment operator.
907 Status s1
= doSomething();
909 s2
= static_cast<Status
&&>(s1
);
913 void testTemporariesAndOperators2() {
914 Status s1
= doSomething();
915 Status s2
= doSomething();
916 s1
= s2
; // expected-warning {{invalid invocation of method 'operator=' on object 's1' while it is in the 'unconsumed' state}}
921 Status
testReturnAutocast() {
922 Status s
= doSomething();
923 s
.check(); // consume s
924 return s
; // should autocast back to unconsumed
928 namespace TestParens
{
931 checkStat((doSomething()));
935 Status s
= (doSomething());
940 (doSomething()).check();
944 if ((doSomething()) == Status::OK
)
948 } // end namespace TestParens
950 } // end namespace InitializerAssertionFailTest
974 std::move(x
); // expected-warning {{ignoring return value}}
978 } // end namespace PR18260