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