DeLesley Hutchins | 48a3176 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wconsumed -std=c++11 %s |
| 2 | |
DeLesley Hutchins | 210791a | 2013-10-04 21:28:06 +0000 | [diff] [blame] | 3 | #define CALLABLE_WHEN(...) __attribute__ ((callable_when(__VA_ARGS__))) |
DeLesley Hutchins | 33a2934 | 2013-10-11 23:03:26 +0000 | [diff] [blame] | 4 | #define CONSUMABLE(state) __attribute__ ((consumable(state))) |
| 5 | #define SET_TYPESTATE(state) __attribute__ ((set_typestate(state))) |
| 6 | #define RETURN_TYPESTATE(state) __attribute__ ((return_typestate(state))) |
Chris Wailes | 9385f9f | 2013-10-29 20:28:41 +0000 | [diff] [blame] | 7 | #define TEST_TYPESTATE(state) __attribute__ ((test_typestate(state))) |
DeLesley Hutchins | fc36825 | 2013-09-03 20:11:38 +0000 | [diff] [blame] | 8 | |
DeLesley Hutchins | e13ce18 | 2013-09-03 22:35:53 +0000 | [diff] [blame] | 9 | // FIXME: This test is here because the warning is issued by the Consumed |
| 10 | // analysis, not SemaDeclAttr. The analysis won't run after an error |
| 11 | // has been issued. Once the attribute propagation for template |
| 12 | // instantiation has been fixed, this can be moved somewhere else and the |
| 13 | // definition can be removed. |
DeLesley Hutchins | fc36825 | 2013-09-03 20:11:38 +0000 | [diff] [blame] | 14 | int returnTypestateForUnconsumable() RETURN_TYPESTATE(consumed); // expected-warning {{return state set for an unconsumable type 'int'}} |
| 15 | int returnTypestateForUnconsumable() { |
| 16 | return 0; |
| 17 | } |
DeLesley Hutchins | 48a3176 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 18 | |
| 19 | class AttrTester0 { |
Aaron Ballman | 05e420a | 2014-01-02 21:26:14 +0000 | [diff] [blame] | 20 | void consumes() __attribute__ ((set_typestate())); // expected-error {{'set_typestate' attribute takes one argument}} |
| 21 | bool testUnconsumed() __attribute__ ((test_typestate())); // expected-error {{'test_typestate' attribute takes one argument}} |
| 22 | void callableWhen() __attribute__ ((callable_when())); // expected-error {{'callable_when' attribute takes at least 1 argument}} |
DeLesley Hutchins | 48a3176 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 23 | }; |
| 24 | |
DeLesley Hutchins | 33a2934 | 2013-10-11 23:03:26 +0000 | [diff] [blame] | 25 | int var0 SET_TYPESTATE(consumed); // expected-warning {{'set_typestate' attribute only applies to methods}} |
Chris Wailes | 9385f9f | 2013-10-29 20:28:41 +0000 | [diff] [blame] | 26 | int var1 TEST_TYPESTATE(consumed); // expected-warning {{'test_typestate' attribute only applies to methods}} |
DeLesley Hutchins | 33a2934 | 2013-10-11 23:03:26 +0000 | [diff] [blame] | 27 | int var2 CALLABLE_WHEN("consumed"); // expected-warning {{'callable_when' attribute only applies to methods}} |
David Blaikie | 16f76d2 | 2013-09-06 01:28:43 +0000 | [diff] [blame] | 28 | int var3 CONSUMABLE(consumed); // expected-warning {{'consumable' attribute only applies to classes}} |
DeLesley Hutchins | fc36825 | 2013-09-03 20:11:38 +0000 | [diff] [blame] | 29 | int var4 RETURN_TYPESTATE(consumed); // expected-warning {{'return_typestate' attribute only applies to functions}} |
DeLesley Hutchins | 48a3176 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 30 | |
DeLesley Hutchins | 33a2934 | 2013-10-11 23:03:26 +0000 | [diff] [blame] | 31 | void function0() SET_TYPESTATE(consumed); // expected-warning {{'set_typestate' attribute only applies to methods}} |
Chris Wailes | 9385f9f | 2013-10-29 20:28:41 +0000 | [diff] [blame] | 32 | void function1() TEST_TYPESTATE(consumed); // expected-warning {{'test_typestate' attribute only applies to methods}} |
DeLesley Hutchins | 33a2934 | 2013-10-11 23:03:26 +0000 | [diff] [blame] | 33 | void function2() CALLABLE_WHEN("consumed"); // expected-warning {{'callable_when' attribute only applies to methods}} |
David Blaikie | 16f76d2 | 2013-09-06 01:28:43 +0000 | [diff] [blame] | 34 | void function3() CONSUMABLE(consumed); // expected-warning {{'consumable' attribute only applies to classes}} |
DeLesley Hutchins | 48a3176 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 35 | |
David Blaikie | 16f76d2 | 2013-09-06 01:28:43 +0000 | [diff] [blame] | 36 | class CONSUMABLE(unknown) AttrTester1 { |
Chris Wailes | 9385f9f | 2013-10-29 20:28:41 +0000 | [diff] [blame] | 37 | void callableWhen0() CALLABLE_WHEN("unconsumed"); |
| 38 | void callableWhen1() CALLABLE_WHEN(42); // expected-error {{'callable_when' attribute requires a string}} |
| 39 | void callableWhen2() CALLABLE_WHEN("foo"); // expected-warning {{'callable_when' attribute argument not supported: foo}} |
Aaron Ballman | 55ef151 | 2014-12-19 16:42:04 +0000 | [diff] [blame] | 40 | void callableWhen3() CALLABLE_WHEN(unconsumed); |
Chris Wailes | 9385f9f | 2013-10-29 20:28:41 +0000 | [diff] [blame] | 41 | void consumes() SET_TYPESTATE(consumed); |
| 42 | bool testUnconsumed() TEST_TYPESTATE(consumed); |
DeLesley Hutchins | 48a3176 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
Aaron Ballman | 682ee42 | 2013-09-11 19:47:58 +0000 | [diff] [blame] | 45 | AttrTester1 returnTypestateTester0() RETURN_TYPESTATE(not_a_state); // expected-warning {{'return_typestate' attribute argument not supported: 'not_a_state'}} |
DeLesley Hutchins | fc36825 | 2013-09-03 20:11:38 +0000 | [diff] [blame] | 46 | AttrTester1 returnTypestateTester1() RETURN_TYPESTATE(42); // expected-error {{'return_typestate' attribute requires an identifier}} |
| 47 | |
DeLesley Hutchins | 36ea1dd | 2013-10-17 22:53:04 +0000 | [diff] [blame] | 48 | void returnTypestateTester2(AttrTester1 &Param RETURN_TYPESTATE(unconsumed)); |
| 49 | |
DeLesley Hutchins | 48a3176 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 50 | class AttrTester2 { |
Chris Wailes | 9385f9f | 2013-10-29 20:28:41 +0000 | [diff] [blame] | 51 | void callableWhen() CALLABLE_WHEN("unconsumed"); // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}} |
| 52 | void consumes() SET_TYPESTATE(consumed); // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}} |
| 53 | bool testUnconsumed() TEST_TYPESTATE(consumed); // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}} |
DeLesley Hutchins | 48a3176 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 54 | }; |
David Blaikie | 16f76d2 | 2013-09-06 01:28:43 +0000 | [diff] [blame] | 55 | |
| 56 | class CONSUMABLE(42) AttrTester3; // expected-error {{'consumable' attribute requires an identifier}} |
DeLesley Hutchins | f28bbec | 2014-01-14 00:36:53 +0000 | [diff] [blame] | 57 | |
| 58 | |
| 59 | class CONSUMABLE(unconsumed) |
| 60 | __attribute__((consumable_auto_cast_state)) |
| 61 | __attribute__((consumable_set_state_on_read)) |
| 62 | Status { |
| 63 | }; |
| 64 | |
| 65 | |
| 66 | |