Skip to content

Commit 2c046c4

Browse files
committed
Add the gsl::Pointer/gsl::Owner combo to ArrayRef and SmallVector so it can diagnose this common combo.
1 parent 262108e commit 2c046c4

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

llvm/include/llvm/ADT/ArrayRef.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace llvm {
3838
/// This is intended to be trivially copyable, so it should be passed by
3939
/// value.
4040
template<typename T>
41-
class LLVM_NODISCARD ArrayRef {
41+
class LLVM_GSL_POINTER LLVM_NODISCARD ArrayRef {
4242
public:
4343
using iterator = const T *;
4444
using const_iterator = const T *;

llvm/include/llvm/ADT/SmallVector.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,8 @@ template <typename T> struct alignas(alignof(T)) SmallVectorStorage<T, 0> {};
841841
/// Note that this does not attempt to be exception safe.
842842
///
843843
template <typename T, unsigned N>
844-
class SmallVector : public SmallVectorImpl<T>, SmallVectorStorage<T, N> {
844+
class LLVM_GSL_OWNER SmallVector : public SmallVectorImpl<T>,
845+
SmallVectorStorage<T, N> {
845846
public:
846847
SmallVector() : SmallVectorImpl<T>(N) {}
847848

llvm/include/llvm/Support/Compiler.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,14 @@
289289
#define LLVM_REQUIRE_CONSTANT_INITIALIZATION
290290
#endif
291291

292+
/// LLVM_GSL_OWNER - Apply this to owning classes like SmallVector to enable
293+
/// lifetime warnings.
294+
#if LLVM_HAS_CPP_ATTRIBUTE(gsl::Owner)
295+
#define LLVM_GSL_OWNER [[gsl::Owner]]
296+
#else
297+
#define LLVM_GSL_OWNER
298+
#endif
299+
292300
/// LLVM_GSL_POINTER - Apply this to non-owning classes like
293301
/// StringRef to enable lifetime warnings.
294302
#if LLVM_HAS_CPP_ATTRIBUTE(gsl::Pointer)

0 commit comments

Comments
 (0)