llvm-project/clang/test/Sema/attr-capabilities.cpp
Yi Kong 2d58d19c48 [ThreadSafetyAnalysis] Fix isCapabilityExpr
There are many more expr types that can be a capability expr, like
CXXThisExpr, CallExpr, MemberExpr. Instead of enumerating all of them,
just check typeHasCapability for any type given.

Also add & and * operators to allowed unary operators.

Differential Revision: https://reviews.llvm.org/D41224

llvm-svn: 320753
2017-12-14 22:24:45 +00:00

18 lines
816 B
C++

// RUN: %clang_cc1 -fsyntax-only -Wthread-safety -verify %s
class __attribute__((shared_capability("mutex"))) Mutex {
public:
void func1() __attribute__((assert_capability(this)));
void func2() __attribute__((assert_capability(!this)));
const Mutex& operator!() const { return *this; }
};
class NotACapability {
public:
void func1() __attribute__((assert_capability(this))); // expected-warning {{'assert_capability' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'NotACapability *'}}
void func2() __attribute__((assert_capability(!this))); // expected-warning {{'assert_capability' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'bool'}}
const NotACapability& operator!() const { return *this; }
};