blob: 0a91636ea9492cf27ca074dcc1c38369a2ebac43 [file] [log] [blame]
DeLesley Hutchins48a31762013-08-12 21:20:55 +00001// RUN: %clang_cc1 -fsyntax-only -verify -Wconsumed -std=c++11 %s
2
DeLesley Hutchins210791a2013-10-04 21:28:06 +00003#define CALLABLE_WHEN(...) __attribute__ ((callable_when(__VA_ARGS__)))
DeLesley Hutchins33a29342013-10-11 23:03:26 +00004#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 Wailes9385f9f2013-10-29 20:28:41 +00007#define TEST_TYPESTATE(state) __attribute__ ((test_typestate(state)))
DeLesley Hutchinsfc368252013-09-03 20:11:38 +00008
DeLesley Hutchinse13ce182013-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 Hutchinsfc368252013-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 Hutchins48a31762013-08-12 21:20:55 +000018
19class AttrTester0 {
Chris Wailes9385f9f2013-10-29 20:28:41 +000020 void consumes() __attribute__ ((set_typestate())); // expected-error {{attribute takes one argument}}
21 bool testUnconsumed() __attribute__ ((test_typestate())); // expected-error {{attribute takes one argument}}
22 void callableWhen() __attribute__ ((callable_when())); // expected-error {{attribute takes at least 1 argument}}
DeLesley Hutchins48a31762013-08-12 21:20:55 +000023};
24
DeLesley Hutchins33a29342013-10-11 23:03:26 +000025int var0 SET_TYPESTATE(consumed); // expected-warning {{'set_typestate' attribute only applies to methods}}
Chris Wailes9385f9f2013-10-29 20:28:41 +000026int var1 TEST_TYPESTATE(consumed); // expected-warning {{'test_typestate' attribute only applies to methods}}
DeLesley Hutchins33a29342013-10-11 23:03:26 +000027int var2 CALLABLE_WHEN("consumed"); // expected-warning {{'callable_when' attribute only applies to methods}}
David Blaikie16f76d22013-09-06 01:28:43 +000028int var3 CONSUMABLE(consumed); // expected-warning {{'consumable' attribute only applies to classes}}
DeLesley Hutchinsfc368252013-09-03 20:11:38 +000029int var4 RETURN_TYPESTATE(consumed); // expected-warning {{'return_typestate' attribute only applies to functions}}
DeLesley Hutchins48a31762013-08-12 21:20:55 +000030
DeLesley Hutchins33a29342013-10-11 23:03:26 +000031void function0() SET_TYPESTATE(consumed); // expected-warning {{'set_typestate' attribute only applies to methods}}
Chris Wailes9385f9f2013-10-29 20:28:41 +000032void function1() TEST_TYPESTATE(consumed); // expected-warning {{'test_typestate' attribute only applies to methods}}
DeLesley Hutchins33a29342013-10-11 23:03:26 +000033void function2() CALLABLE_WHEN("consumed"); // expected-warning {{'callable_when' attribute only applies to methods}}
David Blaikie16f76d22013-09-06 01:28:43 +000034void function3() CONSUMABLE(consumed); // expected-warning {{'consumable' attribute only applies to classes}}
DeLesley Hutchins48a31762013-08-12 21:20:55 +000035
David Blaikie16f76d22013-09-06 01:28:43 +000036class CONSUMABLE(unknown) AttrTester1 {
Chris Wailes9385f9f2013-10-29 20:28:41 +000037 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}}
40 void consumes() SET_TYPESTATE(consumed);
41 bool testUnconsumed() TEST_TYPESTATE(consumed);
DeLesley Hutchins48a31762013-08-12 21:20:55 +000042};
43
Aaron Ballman682ee422013-09-11 19:47:58 +000044AttrTester1 returnTypestateTester0() RETURN_TYPESTATE(not_a_state); // expected-warning {{'return_typestate' attribute argument not supported: 'not_a_state'}}
DeLesley Hutchinsfc368252013-09-03 20:11:38 +000045AttrTester1 returnTypestateTester1() RETURN_TYPESTATE(42); // expected-error {{'return_typestate' attribute requires an identifier}}
46
DeLesley Hutchins36ea1dd2013-10-17 22:53:04 +000047void returnTypestateTester2(AttrTester1 &Param RETURN_TYPESTATE(unconsumed));
48
DeLesley Hutchins48a31762013-08-12 21:20:55 +000049class AttrTester2 {
Chris Wailes9385f9f2013-10-29 20:28:41 +000050 void callableWhen() CALLABLE_WHEN("unconsumed"); // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}}
51 void consumes() SET_TYPESTATE(consumed); // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}}
52 bool testUnconsumed() TEST_TYPESTATE(consumed); // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}}
DeLesley Hutchins48a31762013-08-12 21:20:55 +000053};
David Blaikie16f76d22013-09-06 01:28:43 +000054
55class CONSUMABLE(42) AttrTester3; // expected-error {{'consumable' attribute requires an identifier}}