| 1 |
// RUN: %clang_cc1 %s -ast-dump | FileCheck %s |
| 2 |
|
| 3 |
// Verify that we print the [[clang::lifetime_capture_by(X)]] attribute. |
| 4 |
|
| 5 |
struct S { |
| 6 |
void foo(int &a, int &b) [[clang::lifetime_capture_by(a, b, global)]]; |
| 7 |
}; |
| 8 |
|
| 9 |
// CHECK: CXXMethodDecl {{.*}}clang::lifetime_capture_by(a, b, global) |
| 10 |
|
| 11 |
// **************************************************************************** |
| 12 |
// Infer annotation for STL container methods. |
| 13 |
// **************************************************************************** |
| 14 |
namespace __gnu_cxx { |
| 15 |
template <typename T> |
| 16 |
struct basic_iterator {}; |
| 17 |
} |
| 18 |
|
| 19 |
namespace std { |
| 20 |
template<typename T> class allocator {}; |
| 21 |
template <typename T, typename Alloc = allocator<T>> |
| 22 |
struct vector { |
| 23 |
typedef __gnu_cxx::basic_iterator<T> iterator; |
| 24 |
iterator begin(); |
| 25 |
|
| 26 |
vector(); |
| 27 |
|
| 28 |
void push_back(const T&); |
| 29 |
void push_back(T&&); |
| 30 |
|
| 31 |
void insert(iterator, T&&); |
| 32 |
}; |
| 33 |
|
| 34 |
template <typename Key, typename Value> |
| 35 |
struct map { |
| 36 |
Value& operator[](Key&& p); |
| 37 |
Value& operator[](const Key& p); |
| 38 |
}; |
| 39 |
} // namespace std |
| 40 |
|
| 41 |
// CHECK-NOT: LifetimeCaptureByAttr |
| 42 |
|
| 43 |
struct [[gsl::Pointer()]] View {}; |
| 44 |
std::vector<View> views; |
| 45 |
// CHECK: ClassTemplateSpecializationDecl {{.*}} struct vector definition instantiated_from 0x{{.+}} implicit_instantiation |
| 46 |
|
| 47 |
// CHECK: CXXMethodDecl {{.*}} push_back 'void (const View &)' |
| 48 |
// CHECK-NEXT: ParmVarDecl {{.*}} 'const View &' |
| 49 |
// CHECK-NEXT: LifetimeCaptureByAttr {{.*}} Implicit |
| 50 |
|
| 51 |
// CHECK: CXXMethodDecl {{.*}} push_back 'void (View &&)' |
| 52 |
// CHECK-NEXT: ParmVarDecl {{.*}} 'View &&' |
| 53 |
// CHECK-NEXT: LifetimeCaptureByAttr {{.*}} Implicit |
| 54 |
|
| 55 |
// CHECK: CXXMethodDecl {{.*}} insert 'void (iterator, View &&)' |
| 56 |
// CHECK-NEXT: ParmVarDecl {{.*}} 'iterator' |
| 57 |
// CHECK-NEXT: ParmVarDecl {{.*}} 'View &&' |
| 58 |
// CHECK-NEXT: LifetimeCaptureByAttr {{.*}} Implicit |
| 59 |
|
| 60 |
template <class T> struct [[gsl::Pointer()]] ViewTemplate {}; |
| 61 |
std::vector<ViewTemplate<int>> templated_views; |
| 62 |
// CHECK: ClassTemplateSpecializationDecl {{.*}} struct vector definition instantiated_from 0x{{.+}} implicit_instantiation |
| 63 |
|
| 64 |
// CHECK: CXXMethodDecl {{.*}} push_back 'void (const ViewTemplate<int> &)' |
| 65 |
// CHECK-NEXT: ParmVarDecl {{.*}} 'const ViewTemplate<int> &' |
| 66 |
// CHECK-NEXT: LifetimeCaptureByAttr {{.*}} Implicit |
| 67 |
// CHECK-NOT: LifetimeCaptureByAttr |
| 68 |
|
| 69 |
// CHECK: CXXMethodDecl {{.*}} push_back 'void (ViewTemplate<int> &&)' |
| 70 |
// CHECK-NEXT: ParmVarDecl {{.*}} 'ViewTemplate<int> &&' |
| 71 |
// CHECK-NEXT: LifetimeCaptureByAttr {{.*}} Implicit |
| 72 |
|
| 73 |
// CHECK: CXXMethodDecl {{.*}} insert 'void (iterator, ViewTemplate<int> &&)' |
| 74 |
// CHECK-NEXT: ParmVarDecl {{.*}} 'iterator' |
| 75 |
// CHECK-NEXT: ParmVarDecl {{.*}} 'ViewTemplate<int> &&' |
| 76 |
// CHECK-NEXT: LifetimeCaptureByAttr {{.*}} Implicit |
| 77 |
|
| 78 |
std::vector<int*> pointers; |
| 79 |
// CHECK: ClassTemplateSpecializationDecl {{.*}} struct vector definition instantiated_from 0x{{.+}} implicit_instantiation |
| 80 |
|
| 81 |
// CHECK: CXXMethodDecl {{.*}} push_back 'void (int *const &)' |
| 82 |
// CHECK-NEXT: ParmVarDecl {{.*}} 'int *const &' |
| 83 |
// CHECK-NOT: LifetimeCaptureByAttr |
| 84 |
|
| 85 |
// CHECK: CXXMethodDecl {{.*}} push_back 'void (int *&&)' |
| 86 |
// CHECK-NEXT: ParmVarDecl {{.*}} 'int *&&' |
| 87 |
// CHECK-NOT: LifetimeCaptureByAttr |
| 88 |
|
| 89 |
// CHECK: CXXMethodDecl {{.*}} insert 'void (iterator, int *&&)' |
| 90 |
// CHECK-NEXT: ParmVarDecl {{.*}} 'iterator' |
| 91 |
// CHECK-NEXT: ParmVarDecl {{.*}} 'int *&&' |
| 92 |
// CHECK-NOT: LifetimeCaptureByAttr |
| 93 |
|
| 94 |
std::vector<int> ints; |
| 95 |
// CHECK: ClassTemplateSpecializationDecl {{.*}} struct vector definition instantiated_from 0x{{.+}} implicit_instantiation |
| 96 |
// CHECK: TemplateArgument type 'int' |
| 97 |
|
| 98 |
// CHECK: CXXMethodDecl {{.*}} push_back 'void (const int &)' |
| 99 |
// CHECK-NOT: LifetimeCaptureByAttr |
| 100 |
|
| 101 |
// CHECK: CXXMethodDecl {{.*}} push_back 'void (int &&)' |
| 102 |
// CHECK-NOT: LifetimeCaptureByAttr |
| 103 |
|
| 104 |
// CHECK: CXXMethodDecl {{.*}} insert 'void (iterator, int &&)' |
| 105 |
// CHECK-NEXT: ParmVarDecl {{.*}} 'iterator' |
| 106 |
// CHECK-NEXT: ParmVarDecl {{.*}} 'int &&' |
| 107 |
// CHECK-NOT: LifetimeCaptureByAttr |
| 108 |
|
| 109 |
std::map<View, int> map; |
| 110 |
// CHECK: ClassTemplateSpecializationDecl {{.*}} struct map definition instantiated_from 0x{{.+}} implicit_instantiation |
| 111 |
|
| 112 |
// CHECK: CXXMethodDecl {{.*}} operator[] 'int &(View &&)' implicit_instantiation |
| 113 |
// CHECK-NEXT: ParmVarDecl {{.*}} p 'View &&' |
| 114 |
// CHECK-NEXT: LifetimeCaptureByAttr {{.*}} Implicit |
| 115 |
// CHECK: CXXMethodDecl {{.*}} operator[] 'int &(const View &)' implicit_instantiation |
| 116 |
// CHECK-NEXT: ParmVarDecl {{.*}} p 'const View &' |
| 117 |
// CHECK-NEXT: LifetimeCaptureByAttr {{.*}} Implicit |