brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.9 KiB · 63f4135 Raw
67 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify -Wconsumed -std=c++11 %s2 3#define CALLABLE_WHEN(...)      __attribute__ ((callable_when(__VA_ARGS__)))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)))7#define TEST_TYPESTATE(state)   __attribute__ ((test_typestate(state)))8 9// FIXME: This test is here because the warning is issued by the Consumed10//        analysis, not SemaDeclAttr.  The analysis won't run after an error11//        has been issued.  Once the attribute propagation for template12//        instantiation has been fixed, this can be moved somewhere else and the13//        definition can be removed.14int returnTypestateForUnconsumable() RETURN_TYPESTATE(consumed); // expected-warning {{return state set for an unconsumable type 'int'}}15int returnTypestateForUnconsumable() {16  return 0;17}18 19class AttrTester0 {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}}23};24 25int var0 SET_TYPESTATE(consumed); // expected-warning {{'set_typestate' attribute only applies to functions}}26int var1 TEST_TYPESTATE(consumed); // expected-warning {{'test_typestate' attribute only applies to}}27int var2 CALLABLE_WHEN("consumed"); // expected-warning {{'callable_when' attribute only applies to}}28int var3 CONSUMABLE(consumed); // expected-warning {{'consumable' attribute only applies to classes}}29int var4 RETURN_TYPESTATE(consumed); // expected-warning {{'return_typestate' attribute only applies to functions}}30 31void function0() SET_TYPESTATE(consumed); // expected-warning {{'set_typestate' attribute only applies to}}32void function1() TEST_TYPESTATE(consumed); // expected-warning {{'test_typestate' attribute only applies to}}33void function2() CALLABLE_WHEN("consumed"); // expected-warning {{'callable_when' attribute only applies to}}34void function3() CONSUMABLE(consumed); // expected-warning {{'consumable' attribute only applies to classes}}35 36class CONSUMABLE(unknown) AttrTester1 {37  void callableWhen0()  CALLABLE_WHEN("unconsumed");38  void callableWhen1()  CALLABLE_WHEN(42); // expected-error {{expected string literal as argument of 'callable_when' attribute}}39  void callableWhen2()  CALLABLE_WHEN("foo"); // expected-warning {{'callable_when' attribute argument not supported: foo}}40  void callableWhen3()  CALLABLE_WHEN(unconsumed);41  void consumes()       SET_TYPESTATE(consumed);42  bool testUnconsumed() TEST_TYPESTATE(consumed);43};44 45AttrTester1 returnTypestateTester0() RETURN_TYPESTATE(not_a_state); // expected-warning {{'return_typestate' attribute argument not supported: 'not_a_state'}}46AttrTester1 returnTypestateTester1() RETURN_TYPESTATE(42); // expected-error {{'return_typestate' attribute requires an identifier}}47 48void returnTypestateTester2(AttrTester1 &Param RETURN_TYPESTATE(unconsumed));49 50class AttrTester2 {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}}54};55 56class CONSUMABLE(42) AttrTester3; // expected-error {{'consumable' attribute requires an identifier}}57 58 59class CONSUMABLE(unconsumed)60      __attribute__((consumable_auto_cast_state))61      __attribute__((consumable_set_state_on_read))62      Status {63};64 65 66 67