Skip to content

Commit 0579c69

Browse files
committed
Extend docs
1 parent 172bb12 commit 0579c69

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,21 @@ Attribute Changes in Clang
201201
and each must be a positive integer when provided. The parameter ``x`` is required, while ``y`` and
202202
``z`` are optional with default value of 1.
203203

204+
- The ``_Nullable`` and ``_Nonnull`` family of type attributes can now apply
205+
to certain C++ class types, such as smart pointers:
206+
``void useObject(std::unique_ptr<Object> _Nonnull obj);``.
207+
208+
This works for standard library types including ``unique_ptr``, ``shared_ptr``
209+
and ``function``. See `the attribute reference
210+
documentation <https://llvm.org/docs/AttributeReference.html#nullability-attributes>`_
211+
for the full list.
212+
213+
- The ``_Nullable`` attribute can be applied to C++ class declarations:
214+
``template <class T> class _Nullable MySmartPointer {};``.
215+
216+
This allows the ``_Nullable`` and ``_Nonnull` family of type attributes to
217+
apply to this class.
218+
204219
Improvements to Clang's diagnostics
205220
-----------------------------------
206221
- Clang now applies syntax highlighting to the code snippets it

clang/include/clang/Basic/AttrDocs.td

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4153,10 +4153,16 @@ non-underscored keywords. For example:
41534153
@end
41544154

41554155
As well as built-in pointer types, the nullability attributes can be attached
4156-
to C++ classes marked with the ``_Nullable`` attribute, as well as the C++
4157-
standard library types ``unique_ptr``, ``shared_ptr``, ``auto_ptr``,
4158-
``exception_ptr``, ``function``, ``move_only_function`` and
4159-
``coroutine_handle``.
4156+
to C++ classes marked with the ``_Nullable`` attribute.
4157+
4158+
The following C++ standard library types are considered nullable:
4159+
``unique_ptr``, ``shared_ptr``, ``auto_ptr``, ``exception_ptr``, ``function``,
4160+
``move_only_function`` and ``coroutine_handle``.
4161+
4162+
Types should be marked nullable only where the type itself leaves nullability
4163+
ambiguous. For example, ``std::optional`` is not marked ``_Nullable``, because
4164+
``optional<int> _Nullable`` is redundant and ``optional<int> _Nonnull`` is
4165+
not a useful type.
41604166
}];
41614167
}
41624168

0 commit comments

Comments
 (0)