diff options
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/SemaCXX/warn-consumed-analysis.cpp | 19 | ||||
-rw-r--r-- | clang/test/SemaCXX/warn-consumed-parsing.cpp | 22 |
2 files changed, 23 insertions, 18 deletions
diff --git a/clang/test/SemaCXX/warn-consumed-analysis.cpp b/clang/test/SemaCXX/warn-consumed-analysis.cpp index b11a74f95e5..8a55c8820a2 100644 --- a/clang/test/SemaCXX/warn-consumed-analysis.cpp +++ b/clang/test/SemaCXX/warn-consumed-analysis.cpp @@ -4,7 +4,7 @@ #define CALLABLE_WHEN(...) __attribute__ ((callable_when(__VA_ARGS__))) #define CONSUMABLE(state) __attribute__ ((consumable(state))) -#define CONSUMES __attribute__ ((consumes)) +#define SET_TYPESTATE(state) __attribute__ ((set_typestate(state))) #define RETURN_TYPESTATE(state) __attribute__ ((return_typestate(state))) #define TESTS_TYPESTATE(state) __attribute__ ((tests_typestate(state))) @@ -23,7 +23,7 @@ public: ConsumableClass<T>& operator=(ConsumableClass<T> &other); ConsumableClass<T>& operator=(ConsumableClass<T> &&other); - ConsumableClass<T>& operator=(nullptr_t) CONSUMES; + ConsumableClass<T>& operator=(nullptr_t) SET_TYPESTATE(consumed); template <typename U> ConsumableClass<T>& operator=(ConsumableClass<U> &other); @@ -31,7 +31,7 @@ public: template <typename U> ConsumableClass<T>& operator=(ConsumableClass<U> &&other); - void operator()(int a) CONSUMES; + void operator()(int a) SET_TYPESTATE(consumed); void operator*() const CALLABLE_WHEN("unconsumed"); void unconsumedCall() const CALLABLE_WHEN("unconsumed"); void callableWhenUnknown() const CALLABLE_WHEN("unconsumed", "unknown"); @@ -44,7 +44,8 @@ public: void constCall() const; void nonconstCall(); - void consume() CONSUMES; + void consume() SET_TYPESTATE(consumed); + void unconsume() SET_TYPESTATE(unconsumed); }; class CONSUMABLE(unconsumed) DestructorTester { @@ -484,7 +485,7 @@ void testConditionalMerge() { *var; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}} } -void testConsumes0() { +void testSetTypestate() { ConsumableClass<int> var(42); *var; @@ -492,15 +493,19 @@ void testConsumes0() { var.consume(); *var; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}} + + var.unconsume(); + + *var; } -void testConsumes1() { +void testConsumes0() { ConsumableClass<int> var(nullptr); *var; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}} } -void testConsumes2() { +void testConsumes1() { ConsumableClass<int> var(42); var.unconsumedCall(); diff --git a/clang/test/SemaCXX/warn-consumed-parsing.cpp b/clang/test/SemaCXX/warn-consumed-parsing.cpp index 0cc8579c940..80021020ca6 100644 --- a/clang/test/SemaCXX/warn-consumed-parsing.cpp +++ b/clang/test/SemaCXX/warn-consumed-parsing.cpp @@ -1,10 +1,10 @@ // RUN: %clang_cc1 -fsyntax-only -verify -Wconsumed -std=c++11 %s #define CALLABLE_WHEN(...) __attribute__ ((callable_when(__VA_ARGS__))) -#define CONSUMABLE(state) __attribute__ ((consumable(state))) -#define CONSUMES __attribute__ ((consumes)) -#define RETURN_TYPESTATE(state) __attribute__ ((return_typestate(state))) -#define TESTS_TYPESTATE(state) __attribute__ ((tests_typestate(state))) +#define CONSUMABLE(state) __attribute__ ((consumable(state))) +#define SET_TYPESTATE(state) __attribute__ ((set_typestate(state))) +#define RETURN_TYPESTATE(state) __attribute__ ((return_typestate(state))) +#define TESTS_TYPESTATE(state) __attribute__ ((tests_typestate(state))) // FIXME: This test is here because the warning is issued by the Consumed // analysis, not SemaDeclAttr. The analysis won't run after an error @@ -17,27 +17,27 @@ int returnTypestateForUnconsumable() { } class AttrTester0 { - void consumes() __attribute__ ((consumes(42))); // expected-error {{attribute takes no arguments}} + void consumes() __attribute__ ((set_typestate())); // expected-error {{attribute takes one argument}} bool testsUnconsumed() __attribute__ ((tests_typestate())); // expected-error {{attribute takes one argument}} void callableWhen() __attribute__ ((callable_when())); // expected-error {{attribute takes at least 1 argument}} }; -int var0 CONSUMES; // expected-warning {{'consumes' attribute only applies to methods}} +int var0 SET_TYPESTATE(consumed); // expected-warning {{'set_typestate' attribute only applies to methods}} int var1 TESTS_TYPESTATE(consumed); // expected-warning {{'tests_typestate' attribute only applies to methods}} -int var2 CALLABLE_WHEN(42); // expected-warning {{'callable_when' attribute only applies to methods}} +int var2 CALLABLE_WHEN("consumed"); // expected-warning {{'callable_when' attribute only applies to methods}} int var3 CONSUMABLE(consumed); // expected-warning {{'consumable' attribute only applies to classes}} int var4 RETURN_TYPESTATE(consumed); // expected-warning {{'return_typestate' attribute only applies to functions}} -void function0() CONSUMES; // expected-warning {{'consumes' attribute only applies to methods}} +void function0() SET_TYPESTATE(consumed); // expected-warning {{'set_typestate' attribute only applies to methods}} void function1() TESTS_TYPESTATE(consumed); // expected-warning {{'tests_typestate' attribute only applies to methods}} -void function2() CALLABLE_WHEN(42); // expected-warning {{'callable_when' attribute only applies to methods}} +void function2() CALLABLE_WHEN("consumed"); // expected-warning {{'callable_when' attribute only applies to methods}} void function3() CONSUMABLE(consumed); // expected-warning {{'consumable' attribute only applies to classes}} class CONSUMABLE(unknown) AttrTester1 { void callableWhen0() CALLABLE_WHEN("unconsumed"); void callableWhen1() CALLABLE_WHEN(42); // expected-error {{'callable_when' attribute requires a string}} void callableWhen2() CALLABLE_WHEN("foo"); // expected-warning {{'callable_when' attribute argument not supported: foo}} - void consumes() CONSUMES; + void consumes() SET_TYPESTATE(consumed); bool testsUnconsumed() TESTS_TYPESTATE(consumed); }; @@ -46,7 +46,7 @@ AttrTester1 returnTypestateTester1() RETURN_TYPESTATE(42); // expected-error {{' class AttrTester2 { void callableWhen() CALLABLE_WHEN("unconsumed"); // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}} - void consumes() CONSUMES; // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}} + void consumes() SET_TYPESTATE(consumed); // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}} bool testsUnconsumed() TESTS_TYPESTATE(consumed); // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}} }; |