diff options
author | DeLesley Hutchins <delesley@google.com> | 2013-10-17 23:23:53 +0000 |
---|---|---|
committer | DeLesley Hutchins <delesley@google.com> | 2013-10-17 23:23:53 +0000 |
commit | 6939177ceab8b9df367bbaeccb16a74d85447644 (patch) | |
tree | bb51351642d736f4bb09e8b6a5b5e9dc05f8e4fa /clang/test | |
parent | 403425bba8939ecbf217f3f9e6b1ceb6ad45f16b (diff) | |
download | bcm5719-llvm-6939177ceab8b9df367bbaeccb16a74d85447644.tar.gz bcm5719-llvm-6939177ceab8b9df367bbaeccb16a74d85447644.zip |
Consumed analysis: Add param_typestate attribute, which specifies that
function parameters must be in a particular state. Patch by
chris.wailes@gmail.com. Reviewed by delesley@google.com.
llvm-svn: 192934
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/SemaCXX/warn-consumed-analysis.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/clang/test/SemaCXX/warn-consumed-analysis.cpp b/clang/test/SemaCXX/warn-consumed-analysis.cpp index dd1bb2312d8..2e45216cfe9 100644 --- a/clang/test/SemaCXX/warn-consumed-analysis.cpp +++ b/clang/test/SemaCXX/warn-consumed-analysis.cpp @@ -4,8 +4,9 @@ #define CALLABLE_WHEN(...) __attribute__ ((callable_when(__VA_ARGS__))) #define CONSUMABLE(state) __attribute__ ((consumable(state))) -#define SET_TYPESTATE(state) __attribute__ ((set_typestate(state))) +#define PARAM_TYPESTATE(state) __attribute__ ((param_typestate(state))) #define RETURN_TYPESTATE(state) __attribute__ ((return_typestate(state))) +#define SET_TYPESTATE(state) __attribute__ ((set_typestate(state))) #define TESTS_TYPESTATE(state) __attribute__ ((tests_typestate(state))) typedef decltype(nullptr) nullptr_t; @@ -406,6 +407,19 @@ void testParamReturnTypestateCaller() { *var; } +void testParamTypestateCallee(ConsumableClass<int> Param0 PARAM_TYPESTATE(consumed), + ConsumableClass<int> &Param1 PARAM_TYPESTATE(consumed)) { + + *Param0; // expected-warning {{invalid invocation of method 'operator*' on object 'Param0' while it is in the 'consumed' state}} + *Param1; // expected-warning {{invalid invocation of method 'operator*' on object 'Param1' while it is in the 'consumed' state}} +} + +void testParamTypestateCaller() { + ConsumableClass<int> Var0, Var1(42); + + testParamTypestateCallee(Var0, Var1); // expected-warning {{argument not in expected state; expected 'consumed', observed 'unconsumed'}} +} + void testCallingConventions() { ConsumableClass<int> var(42); |