blob: 001fb866b89c0ee19d11113c7430b4fdb7b8d2bd [file] [log] [blame]
DeLesley Hutchinsdf7bef02013-08-12 21:20:55 +00001// RUN: %clang_cc1 -fsyntax-only -verify -Wconsumed -std=c++11 %s
2
DeLesley Hutchins0e8534e2013-09-03 20:11:38 +00003#define CALLABLE_WHEN_UNCONSUMED __attribute__ ((callable_when_unconsumed))
David Blaikiea33ab602013-09-06 01:28:43 +00004#define CONSUMABLE(state) __attribute__ ((consumable(state)))
DeLesley Hutchins0e8534e2013-09-03 20:11:38 +00005#define CONSUMES __attribute__ ((consumes))
David Blaikiea33ab602013-09-06 01:28:43 +00006#define RETURN_TYPESTATE(state) __attribute__ ((return_typestate(state)))
DeLesley Hutchins0e8534e2013-09-03 20:11:38 +00007#define TESTS_UNCONSUMED __attribute__ ((tests_unconsumed))
8
DeLesley Hutchins50949202013-09-03 22:35:53 +00009// 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 Hutchins0e8534e2013-09-03 20:11:38 +000014int returnTypestateForUnconsumable() RETURN_TYPESTATE(consumed); // expected-warning {{return state set for an unconsumable type 'int'}}
15int returnTypestateForUnconsumable() {
16 return 0;
17}
DeLesley Hutchinsdf7bef02013-08-12 21:20:55 +000018
19class AttrTester0 {
DeLesley Hutchins0e8534e2013-09-03 20:11:38 +000020 void consumes() __attribute__ ((consumes(42))); // expected-error {{attribute takes no arguments}}
21 bool testsUnconsumed() __attribute__ ((tests_unconsumed(42))); // expected-error {{attribute takes no arguments}}
22 void callableWhenUnconsumed() __attribute__ ((callable_when_unconsumed(42))); // expected-error {{attribute takes no arguments}}
DeLesley Hutchinsdf7bef02013-08-12 21:20:55 +000023};
24
25int var0 CONSUMES; // expected-warning {{'consumes' attribute only applies to methods}}
26int var1 TESTS_UNCONSUMED; // expected-warning {{'tests_unconsumed' attribute only applies to methods}}
27int var2 CALLABLE_WHEN_UNCONSUMED; // expected-warning {{'callable_when_unconsumed' attribute only applies to methods}}
David Blaikiea33ab602013-09-06 01:28:43 +000028int var3 CONSUMABLE(consumed); // expected-warning {{'consumable' attribute only applies to classes}}
DeLesley Hutchins0e8534e2013-09-03 20:11:38 +000029int var4 RETURN_TYPESTATE(consumed); // expected-warning {{'return_typestate' attribute only applies to functions}}
DeLesley Hutchinsdf7bef02013-08-12 21:20:55 +000030
DeLesley Hutchinsc55bee62013-08-30 22:56:34 +000031void function0() CONSUMES; // expected-warning {{'consumes' attribute only applies to methods}}
32void function1() TESTS_UNCONSUMED; // expected-warning {{'tests_unconsumed' attribute only applies to methods}}
33void function2() CALLABLE_WHEN_UNCONSUMED; // expected-warning {{'callable_when_unconsumed' attribute only applies to methods}}
David Blaikiea33ab602013-09-06 01:28:43 +000034void function3() CONSUMABLE(consumed); // expected-warning {{'consumable' attribute only applies to classes}}
DeLesley Hutchinsdf7bef02013-08-12 21:20:55 +000035
David Blaikiea33ab602013-09-06 01:28:43 +000036class CONSUMABLE(unknown) AttrTester1 {
DeLesley Hutchinsc55bee62013-08-30 22:56:34 +000037 void callableWhenUnconsumed() CALLABLE_WHEN_UNCONSUMED;
38 void consumes() CONSUMES;
39 bool testsUnconsumed() TESTS_UNCONSUMED;
DeLesley Hutchinsdf7bef02013-08-12 21:20:55 +000040};
41
DeLesley Hutchins0e8534e2013-09-03 20:11:38 +000042AttrTester1 returnTypestateTester0() RETURN_TYPESTATE(not_a_state); // expected-warning {{unknown consumed analysis state 'not_a_state'}}
43AttrTester1 returnTypestateTester1() RETURN_TYPESTATE(42); // expected-error {{'return_typestate' attribute requires an identifier}}
44
DeLesley Hutchinsdf7bef02013-08-12 21:20:55 +000045class AttrTester2 {
DeLesley Hutchins0e8534e2013-09-03 20:11:38 +000046 void callableWhenUnconsumed() CALLABLE_WHEN_UNCONSUMED; // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}}
47 void consumes() CONSUMES; // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}}
48 bool testsUnconsumed() TESTS_UNCONSUMED; // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}}
DeLesley Hutchinsdf7bef02013-08-12 21:20:55 +000049};
David Blaikiea33ab602013-09-06 01:28:43 +000050
51class CONSUMABLE(42) AttrTester3; // expected-error {{'consumable' attribute requires an identifier}}