DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wconsumed -std=c++11 %s |
| 2 | |
DeLesley Hutchins | 0e8534e | 2013-09-03 20:11:38 +0000 | [diff] [blame^] | 3 | #define CALLABLE_WHEN_UNCONSUMED __attribute__ ((callable_when_unconsumed)) |
| 4 | #define CONSUMABLE __attribute__ ((consumable)) |
| 5 | #define CONSUMES __attribute__ ((consumes)) |
| 6 | #define RETURN_TYPESTATE(State) __attribute__ ((return_typestate(State))) |
| 7 | #define TESTS_UNCONSUMED __attribute__ ((tests_unconsumed)) |
| 8 | |
| 9 | // FIXME: This warning is not generated if it appears bellow the AttrTester0 |
| 10 | // class declaration. Why? |
| 11 | int returnTypestateForUnconsumable() RETURN_TYPESTATE(consumed); // expected-warning {{return state set for an unconsumable type 'int'}} |
| 12 | int returnTypestateForUnconsumable() { |
| 13 | return 0; |
| 14 | } |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 15 | |
| 16 | class AttrTester0 { |
DeLesley Hutchins | 0e8534e | 2013-09-03 20:11:38 +0000 | [diff] [blame^] | 17 | void consumes() __attribute__ ((consumes(42))); // expected-error {{attribute takes no arguments}} |
| 18 | bool testsUnconsumed() __attribute__ ((tests_unconsumed(42))); // expected-error {{attribute takes no arguments}} |
| 19 | void callableWhenUnconsumed() __attribute__ ((callable_when_unconsumed(42))); // expected-error {{attribute takes no arguments}} |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 20 | }; |
| 21 | |
| 22 | int var0 CONSUMES; // expected-warning {{'consumes' attribute only applies to methods}} |
| 23 | int var1 TESTS_UNCONSUMED; // expected-warning {{'tests_unconsumed' attribute only applies to methods}} |
| 24 | int var2 CALLABLE_WHEN_UNCONSUMED; // expected-warning {{'callable_when_unconsumed' attribute only applies to methods}} |
DeLesley Hutchins | c55bee6 | 2013-08-30 22:56:34 +0000 | [diff] [blame] | 25 | int var3 CONSUMABLE; // expected-warning {{'consumable' attribute only applies to classes}} |
DeLesley Hutchins | 0e8534e | 2013-09-03 20:11:38 +0000 | [diff] [blame^] | 26 | int var4 RETURN_TYPESTATE(consumed); // expected-warning {{'return_typestate' attribute only applies to functions}} |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 27 | |
DeLesley Hutchins | c55bee6 | 2013-08-30 22:56:34 +0000 | [diff] [blame] | 28 | void function0() CONSUMES; // expected-warning {{'consumes' attribute only applies to methods}} |
| 29 | void function1() TESTS_UNCONSUMED; // expected-warning {{'tests_unconsumed' attribute only applies to methods}} |
| 30 | void function2() CALLABLE_WHEN_UNCONSUMED; // expected-warning {{'callable_when_unconsumed' attribute only applies to methods}} |
| 31 | void function3() CONSUMABLE; // expected-warning {{'consumable' attribute only applies to classes}} |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 32 | |
DeLesley Hutchins | c55bee6 | 2013-08-30 22:56:34 +0000 | [diff] [blame] | 33 | class CONSUMABLE AttrTester1 { |
| 34 | void callableWhenUnconsumed() CALLABLE_WHEN_UNCONSUMED; |
| 35 | void consumes() CONSUMES; |
| 36 | bool testsUnconsumed() TESTS_UNCONSUMED; |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
DeLesley Hutchins | 0e8534e | 2013-09-03 20:11:38 +0000 | [diff] [blame^] | 39 | AttrTester1 returnTypestateTester0() RETURN_TYPESTATE(not_a_state); // expected-warning {{unknown consumed analysis state 'not_a_state'}} |
| 40 | AttrTester1 returnTypestateTester1() RETURN_TYPESTATE(42); // expected-error {{'return_typestate' attribute requires an identifier}} |
| 41 | |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 42 | class AttrTester2 { |
DeLesley Hutchins | 0e8534e | 2013-09-03 20:11:38 +0000 | [diff] [blame^] | 43 | void callableWhenUnconsumed() CALLABLE_WHEN_UNCONSUMED; // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}} |
| 44 | void consumes() CONSUMES; // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}} |
| 45 | bool testsUnconsumed() TESTS_UNCONSUMED; // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}} |
DeLesley Hutchins | df7bef0 | 2013-08-12 21:20:55 +0000 | [diff] [blame] | 46 | }; |