Skip to content

Commit c1ac443

Browse files
committed
move tests; update docs
1 parent 1036946 commit c1ac443

File tree

4 files changed

+388
-343
lines changed

4 files changed

+388
-343
lines changed

clang/include/clang/Basic/AttrDocs.td

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3925,13 +3925,20 @@ def LifetimeCaptureByDocs : Documentation {
39253925
parameter or implicit object parameter indicates that that objects that are referred to
39263926
by that parameter may also be referred to by the capturing entity ``X``.
39273927

3928-
By default, a reference is considered to refer to its referenced object, a
3929-
pointer is considered to refer to its pointee, a ``std::initializer_list<T>``
3930-
is considered to refer to its underlying array, and aggregates (arrays and
3931-
simple ``struct``\s) are considered to refer to all objects that their
3932-
transitive subobjects refer to.
3928+
By default:
3929+
3930+
- A reference is considered to refer to its referenced object.
3931+
- A pointer is considered to refer to its pointee.
3932+
- A ``std::initializer_list<T>`` is considered to refer to its underlying array.
3933+
- Aggregates (arrays and simple ``struct``\s) are considered to refer to all
3934+
objects that their transitive subobjects refer to.
3935+
- View types (types annotated with [[``gsl::Pointer()``]]) are considered to refer
3936+
to its pointee. This holds true even if the view type appears as a reference.
3937+
For example, both ``std::string_view`` and ``const std::string_view &`` are
3938+
considered to refer to a ``std::string``.
39333939

39343940
The capturing entity ``X`` can be one of the following:
3941+
39353942
- Another (named) function parameter.
39363943

39373944
.. code-block:: c++
@@ -3951,7 +3958,7 @@ The capturing entity ``X`` can be one of the following:
39513958
std::set<std::string_view> s;
39523959
};
39533960

3954-
- 'global', 'unknown' (without quotes).
3961+
- `global`, `unknown`.
39553962

39563963
.. code-block:: c++
39573964

@@ -3983,6 +3990,21 @@ The attribute supports specifying more than one capturing entities:
39833990
s2.insert(a);
39843991
}
39853992

3993+
Currently clang would diagnose when a temporary is used as an argument to a
3994+
parameter whose reference is captured.
3995+
3996+
.. code-block:: c++
3997+
3998+
void addToSet(std::string_view a [[clang::lifetime_capture_by(s)]], std::set<std::string_view>& s) {
3999+
s.insert(a);
4000+
}
4001+
void use() {
4002+
std::set<std::string_view> s;
4003+
addToSet(std::string(), s); // Warning: object whose reference is captured by 's' will be destroyed at the end of the full-expression.
4004+
std::string local;
4005+
addToSet(local, s); // Ok.
4006+
}
4007+
39864008
.. _`lifetimebound`: https://clang.llvm.org/docs/AttributeReference.html#lifetimebound
39874009
}];
39884010
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
2+
namespace __gnu_cxx {
3+
template <typename T>
4+
struct basic_iterator {
5+
basic_iterator operator++();
6+
T& operator*() const;
7+
T* operator->() const;
8+
};
9+
10+
template<typename T>
11+
bool operator!=(basic_iterator<T>, basic_iterator<T>);
12+
}
13+
14+
namespace std {
15+
template<typename T> struct remove_reference { typedef T type; };
16+
template<typename T> struct remove_reference<T &> { typedef T type; };
17+
template<typename T> struct remove_reference<T &&> { typedef T type; };
18+
19+
template<typename T>
20+
typename remove_reference<T>::type &&move(T &&t) noexcept;
21+
22+
template <typename C>
23+
auto data(const C &c) -> decltype(c.data());
24+
25+
template <typename C>
26+
auto begin(C &c) -> decltype(c.begin());
27+
28+
template<typename T, int N>
29+
T *begin(T (&array)[N]);
30+
31+
using size_t = decltype(sizeof(0));
32+
33+
template<typename T>
34+
struct initializer_list {
35+
const T* ptr; size_t sz;
36+
};
37+
template<typename T> class allocator {};
38+
template <typename T, typename Alloc = allocator<T>>
39+
struct vector {
40+
typedef __gnu_cxx::basic_iterator<T> iterator;
41+
iterator begin();
42+
iterator end();
43+
const T *data() const;
44+
vector();
45+
vector(initializer_list<T> __l,
46+
const Alloc& alloc = Alloc());
47+
48+
template<typename InputIterator>
49+
vector(InputIterator first, InputIterator __last);
50+
51+
T &at(int n);
52+
};
53+
54+
template<typename T>
55+
struct basic_string_view {
56+
basic_string_view();
57+
basic_string_view(const T *);
58+
const T *begin() const;
59+
};
60+
using string_view = basic_string_view<char>;
61+
62+
template<class _Mystr> struct iter {
63+
iter& operator-=(int);
64+
65+
iter operator-(int _Off) const {
66+
iter _Tmp = *this;
67+
return _Tmp -= _Off;
68+
}
69+
};
70+
71+
template<typename T>
72+
struct basic_string {
73+
basic_string();
74+
basic_string(const T *);
75+
const T *c_str() const;
76+
operator basic_string_view<T> () const;
77+
using const_iterator = iter<T>;
78+
};
79+
using string = basic_string<char>;
80+
81+
template<typename T>
82+
struct unique_ptr {
83+
T &operator*();
84+
T *get() const;
85+
};
86+
87+
template<typename T>
88+
struct optional {
89+
optional();
90+
optional(const T&);
91+
92+
template<typename U = T>
93+
optional(U&& t);
94+
95+
template<typename U>
96+
optional(optional<U>&& __t);
97+
98+
T &operator*() &;
99+
T &&operator*() &&;
100+
T &value() &;
101+
T &&value() &&;
102+
};
103+
template<typename T>
104+
optional<__decay(T)> make_optional(T&&);
105+
106+
107+
template<typename T>
108+
struct stack {
109+
T &top();
110+
};
111+
112+
struct any {};
113+
114+
template<typename T>
115+
T any_cast(const any& operand);
116+
117+
template<typename T>
118+
struct reference_wrapper {
119+
template<typename U>
120+
reference_wrapper(U &&);
121+
};
122+
123+
template<typename T>
124+
reference_wrapper<T> ref(T& t) noexcept;
125+
126+
struct false_type {
127+
static constexpr bool value = false;
128+
constexpr operator bool() const noexcept { return value; }
129+
};
130+
struct true_type {
131+
static constexpr bool value = true;
132+
constexpr operator bool() const noexcept { return value; }
133+
};
134+
135+
template<class T> struct is_pointer : false_type {};
136+
template<class T> struct is_pointer<T*> : true_type {};
137+
template<class T> struct is_pointer<T* const> : true_type {};
138+
}

0 commit comments

Comments
 (0)