From 12ad44a18d9a08c3d44a8e17c13cbc7aaee6f55a Mon Sep 17 00:00:00 2001 From: Marcin Kowalczyk Date: Thu, 26 Sep 2024 14:50:30 +0200 Subject: [PATCH] Add `ABSL_ATTRIBUTE_LIFETIME_BOUND` for remaining pointers and file descriptors passed as function and constructor parameters, where the pointed to object must outlive the function result or the constructed object. PiperOrigin-RevId: 679114168 --- riegeli/base/chain_details.h | 7 ++++--- riegeli/base/intrusive_shared_ptr.h | 6 ++++-- riegeli/bytes/absl_stringify_writer.h | 5 +++-- riegeli/bytes/array_backward_writer.h | 6 ++++-- riegeli/bytes/array_writer.h | 5 +++-- riegeli/bytes/cfile_handle.h | 9 ++++++--- riegeli/bytes/cfile_reader.h | 6 ++++-- riegeli/bytes/cfile_writer.h | 6 ++++-- riegeli/bytes/fd_handle.h | 7 ++++--- riegeli/bytes/fd_mmap_reader.h | 6 ++++-- riegeli/bytes/fd_reader.h | 6 ++++-- riegeli/bytes/fd_writer.h | 6 ++++-- riegeli/bytes/limiting_reader.h | 7 +++++-- riegeli/bytes/pullable_reader.h | 6 ++++-- riegeli/bytes/pushable_backward_writer.h | 6 ++++-- riegeli/bytes/pushable_writer.h | 6 ++++-- riegeli/bytes/string_reader.h | 6 ++++-- riegeli/bytes/writer.h | 2 +- riegeli/csv/csv_record.h | 10 +++++++--- riegeli/digests/digester_handle.h | 4 ++-- riegeli/messages/message_parse.h | 3 ++- riegeli/messages/message_serialize.h | 2 +- riegeli/records/tools/tfrecord_recognizer.h | 7 +++++-- 23 files changed, 87 insertions(+), 47 deletions(-) diff --git a/riegeli/base/chain_details.h b/riegeli/base/chain_details.h index c1921df8..0becdc9b 100644 --- a/riegeli/base/chain_details.h +++ b/riegeli/base/chain_details.h @@ -195,7 +195,8 @@ class Chain::BlockIterator : public WithCompare { BlockIterator() = default; - explicit BlockIterator(const Chain* chain, size_t block_index); + explicit BlockIterator(const Chain* chain ABSL_ATTRIBUTE_LIFETIME_BOUND, + size_t block_index); BlockIterator(const BlockIterator& that) = default; BlockIterator& operator=(const BlockIterator& that) = default; @@ -768,8 +769,8 @@ inline const T* Chain::BlockRef::external_object() const { } } -inline Chain::BlockIterator::BlockIterator(const Chain* chain, - size_t block_index) +inline Chain::BlockIterator::BlockIterator( + const Chain* chain ABSL_ATTRIBUTE_LIFETIME_BOUND, size_t block_index) : chain_(chain), ptr_((ABSL_PREDICT_FALSE(chain_ == nullptr) ? kBeginShortData : chain_->begin_ == chain_->end_ diff --git a/riegeli/base/intrusive_shared_ptr.h b/riegeli/base/intrusive_shared_ptr.h index 14e1a354..c3c6d69e 100644 --- a/riegeli/base/intrusive_shared_ptr.h +++ b/riegeli/base/intrusive_shared_ptr.h @@ -113,9 +113,11 @@ class // Creates an `IntrusiveSharedPtr` holding `ptr`. // // Takes ownership of `ptr` unless the second parameter is `kShareOwnership`. - explicit IntrusiveSharedPtr(T* ptr, PassOwnership = kPassOwnership) noexcept + explicit IntrusiveSharedPtr(T* ptr ABSL_ATTRIBUTE_LIFETIME_BOUND, + PassOwnership = kPassOwnership) noexcept : ptr_(ptr) {} - explicit IntrusiveSharedPtr(T* ptr, ShareOwnership) noexcept + explicit IntrusiveSharedPtr(T* ptr ABSL_ATTRIBUTE_LIFETIME_BOUND, + ShareOwnership) noexcept : ptr_(Ref(ptr)) {} // Creates an `IntrusiveSharedPtr` holding a constructed value. diff --git a/riegeli/bytes/absl_stringify_writer.h b/riegeli/bytes/absl_stringify_writer.h index 4ccd22cb..dab37ad9 100644 --- a/riegeli/bytes/absl_stringify_writer.h +++ b/riegeli/bytes/absl_stringify_writer.h @@ -47,7 +47,7 @@ class AbslStringifyWriter : public BufferedWriter { explicit AbslStringifyWriter(Closed) noexcept : BufferedWriter(kClosed) {} // Will write to `*dest`. - explicit AbslStringifyWriter(Dest dest) + explicit AbslStringifyWriter(Dest dest ABSL_ATTRIBUTE_LIFETIME_BOUND) : dest_(std::move(RIEGELI_ASSERT_NOTNULL(dest))) {} AbslStringifyWriter(AbslStringifyWriter&& that) = default; @@ -81,7 +81,8 @@ class AbslStringifyWriter : PrefixLimitingWriter(kClosed) {} // Will write to `*dest`. - explicit AbslStringifyWriter(WriterAbslStringifySink* dest) + explicit AbslStringifyWriter( + WriterAbslStringifySink* dest ABSL_ATTRIBUTE_LIFETIME_BOUND) : PrefixLimitingWriter(RIEGELI_ASSERT_NOTNULL(dest)->dest()), dest_(dest) {} diff --git a/riegeli/bytes/array_backward_writer.h b/riegeli/bytes/array_backward_writer.h index cefc6490..46f6d929 100644 --- a/riegeli/bytes/array_backward_writer.h +++ b/riegeli/bytes/array_backward_writer.h @@ -109,7 +109,8 @@ class ArrayBackwardWriter : public ArrayBackwardWriterBase { template >::value, int> = 0> - explicit ArrayBackwardWriter(char* dest, size_t size); + explicit ArrayBackwardWriter(char* dest ABSL_ATTRIBUTE_LIFETIME_BOUND, + size_t size); ArrayBackwardWriter(ArrayBackwardWriter&& that) = default; ArrayBackwardWriter& operator=(ArrayBackwardWriter&& that) = default; @@ -153,7 +154,8 @@ explicit ArrayBackwardWriter(Dest&& dest) absl::negation>>>:: value, DeleteCtad, InitializerTargetT>>; -explicit ArrayBackwardWriter(char* dest, size_t size) +explicit ArrayBackwardWriter(char* dest ABSL_ATTRIBUTE_LIFETIME_BOUND, + size_t size) -> ArrayBackwardWriter>; #endif diff --git a/riegeli/bytes/array_writer.h b/riegeli/bytes/array_writer.h index 5f4bdf36..57c770c4 100644 --- a/riegeli/bytes/array_writer.h +++ b/riegeli/bytes/array_writer.h @@ -128,7 +128,7 @@ class ArrayWriter : public ArrayWriterBase { template >::value, int> = 0> - explicit ArrayWriter(char* dest, size_t size); + explicit ArrayWriter(char* dest ABSL_ATTRIBUTE_LIFETIME_BOUND, size_t size); ArrayWriter(ArrayWriter&& that) = default; ArrayWriter& operator=(ArrayWriter&& that) = default; @@ -258,7 +258,8 @@ template template < typename DependentDest, std::enable_if_t>::value, int>> -inline ArrayWriter::ArrayWriter(char* dest, size_t size) +inline ArrayWriter::ArrayWriter(char* dest ABSL_ATTRIBUTE_LIFETIME_BOUND, + size_t size) : ArrayWriter(absl::MakeSpan(dest, size)) {} template diff --git a/riegeli/bytes/cfile_handle.h b/riegeli/bytes/cfile_handle.h index 49f4cfc0..337f8387 100644 --- a/riegeli/bytes/cfile_handle.h +++ b/riegeli/bytes/cfile_handle.h @@ -46,7 +46,8 @@ class OwnedCFile() = default; // Creates an `OwnedCFile` which owns `file`. - explicit OwnedCFile(FILE* file) noexcept : file_(file) {} + explicit OwnedCFile(FILE* file ABSL_ATTRIBUTE_LIFETIME_BOUND) noexcept + : file_(file) {} // The moved-from `FILE*` is left absent. OwnedCFile(OwnedCFile&& that) = default; @@ -139,7 +140,8 @@ class UnownedCFile() = default; // Creates an `UnownedCFile` which stores `file`. - explicit UnownedCFile(FILE* file) noexcept : file_(file) {} + explicit UnownedCFile(FILE* file ABSL_ATTRIBUTE_LIFETIME_BOUND) noexcept + : file_(file) {} UnownedCFile(const UnownedCFile& that) = default; UnownedCFile& operator=(const UnownedCFile& that) = default; @@ -233,7 +235,8 @@ class // Creates a `CFileHandle` which points to `target`. template ::value, int> = 0> - explicit CFileHandle(T* target) : methods_(&kMethods), target_(target) {} + explicit CFileHandle(T* target ABSL_ATTRIBUTE_LIFETIME_BOUND) + : methods_(&kMethods), target_(target) {} CFileHandle(const CFileHandle& that) = default; CFileHandle& operator=(const CFileHandle& that) = default; diff --git a/riegeli/bytes/cfile_reader.h b/riegeli/bytes/cfile_reader.h index a1e17c15..cd618292 100644 --- a/riegeli/bytes/cfile_reader.h +++ b/riegeli/bytes/cfile_reader.h @@ -263,7 +263,8 @@ class CFileReader : public CFileReaderBase { template ::value, int> = 0> - explicit CFileReader(FILE* src, Options options = Options()); + explicit CFileReader(FILE* src ABSL_ATTRIBUTE_LIFETIME_BOUND, + Options options = Options()); // Opens a file for reading. // @@ -400,7 +401,8 @@ template template < typename DependentSrc, std::enable_if_t::value, int>> -inline CFileReader::CFileReader(FILE* src, Options options) +inline CFileReader::CFileReader(FILE* src ABSL_ATTRIBUTE_LIFETIME_BOUND, + Options options) : CFileReader(riegeli::Maker(src), std::move(options)) {} template diff --git a/riegeli/bytes/cfile_writer.h b/riegeli/bytes/cfile_writer.h index c5e17cfe..90e5f79e 100644 --- a/riegeli/bytes/cfile_writer.h +++ b/riegeli/bytes/cfile_writer.h @@ -365,7 +365,8 @@ class CFileWriter : public CFileWriterBase { template ::value, int> = 0> - explicit CFileWriter(FILE* dest, Options options = Options()); + explicit CFileWriter(FILE* dest ABSL_ATTRIBUTE_LIFETIME_BOUND, + Options options = Options()); // Opens a file for writing. // @@ -515,7 +516,8 @@ template template < typename DependentDest, std::enable_if_t::value, int>> -inline CFileWriter::CFileWriter(FILE* dest, Options options) +inline CFileWriter::CFileWriter(FILE* dest ABSL_ATTRIBUTE_LIFETIME_BOUND, + Options options) : CFileWriter(riegeli::Maker(dest), std::move(options)) {} template diff --git a/riegeli/bytes/fd_handle.h b/riegeli/bytes/fd_handle.h index 8250540e..7357477c 100644 --- a/riegeli/bytes/fd_handle.h +++ b/riegeli/bytes/fd_handle.h @@ -57,7 +57,7 @@ class OwnedFd() = default; // Creates an `OwnedFd` which owns `fd`. - explicit OwnedFd(int fd) noexcept : fd_(fd) {} + explicit OwnedFd(int fd ABSL_ATTRIBUTE_LIFETIME_BOUND) noexcept : fd_(fd) {} // The moved-from fd is left absent. OwnedFd(OwnedFd&& that) noexcept : fd_(that.Release()) {} @@ -144,7 +144,7 @@ class UnownedFd : public WithEqual { UnownedFd() = default; // Creates an `UnownedFd` which stores `fd`. - explicit UnownedFd(int fd) noexcept : fd_(fd) {} + explicit UnownedFd(int fd ABSL_ATTRIBUTE_LIFETIME_BOUND) noexcept : fd_(fd) {} UnownedFd(const UnownedFd& that) = default; UnownedFd& operator=(const UnownedFd& that) = default; @@ -249,7 +249,8 @@ class // Creates an `FdHandle` which points to `target`. template ::value, int> = 0> - explicit FdHandle(T* target) : methods_(&kMethods), target_(target) {} + explicit FdHandle(T* target ABSL_ATTRIBUTE_LIFETIME_BOUND) + : methods_(&kMethods), target_(target) {} FdHandle(const FdHandle& that) = default; FdHandle& operator=(const FdHandle& that) = default; diff --git a/riegeli/bytes/fd_mmap_reader.h b/riegeli/bytes/fd_mmap_reader.h index 3a9081b0..d48637fa 100644 --- a/riegeli/bytes/fd_mmap_reader.h +++ b/riegeli/bytes/fd_mmap_reader.h @@ -246,7 +246,8 @@ class FdMMapReader : public FdMMapReaderBase { template ::value, int> = 0> - explicit FdMMapReader(int src, Options options = Options()); + explicit FdMMapReader(int src ABSL_ATTRIBUTE_LIFETIME_BOUND, + Options options = Options()); // Opens a file for reading. // @@ -386,7 +387,8 @@ template template < typename DependentSrc, std::enable_if_t::value, int>> -inline FdMMapReader::FdMMapReader(int src, Options options) +inline FdMMapReader::FdMMapReader(int src ABSL_ATTRIBUTE_LIFETIME_BOUND, + Options options) : FdMMapReader(riegeli::Maker(src), std::move(options)) {} template diff --git a/riegeli/bytes/fd_reader.h b/riegeli/bytes/fd_reader.h index 39d9a54e..9ed66e84 100644 --- a/riegeli/bytes/fd_reader.h +++ b/riegeli/bytes/fd_reader.h @@ -341,7 +341,8 @@ class FdReader : public FdReaderBase { template ::value, int> = 0> - explicit FdReader(int src, Options options = Options()); + explicit FdReader(int src ABSL_ATTRIBUTE_LIFETIME_BOUND, + Options options = Options()); // Opens a file for reading. // @@ -501,7 +502,8 @@ template template < typename DependentSrc, std::enable_if_t::value, int>> -inline FdReader::FdReader(int src, Options options) +inline FdReader::FdReader(int src ABSL_ATTRIBUTE_LIFETIME_BOUND, + Options options) : FdReader(riegeli::Maker(src), std::move(options)) {} template diff --git a/riegeli/bytes/fd_writer.h b/riegeli/bytes/fd_writer.h index dd40b5ee..2d050706 100644 --- a/riegeli/bytes/fd_writer.h +++ b/riegeli/bytes/fd_writer.h @@ -516,7 +516,8 @@ class FdWriter : public FdWriterBase { template ::value, int> = 0> - explicit FdWriter(int dest, Options options = Options()); + explicit FdWriter(int dest ABSL_ATTRIBUTE_LIFETIME_BOUND, + Options options = Options()); // Opens a file for writing. // @@ -687,7 +688,8 @@ template template < typename DependentDest, std::enable_if_t::value, int>> -inline FdWriter::FdWriter(int dest, Options options) +inline FdWriter::FdWriter(int dest ABSL_ATTRIBUTE_LIFETIME_BOUND, + Options options) : FdWriter(riegeli::Maker(dest), std::move(options)) {} template diff --git a/riegeli/bytes/limiting_reader.h b/riegeli/bytes/limiting_reader.h index 94d23838..d45f3e37 100644 --- a/riegeli/bytes/limiting_reader.h +++ b/riegeli/bytes/limiting_reader.h @@ -384,7 +384,9 @@ class ScopedLimiter { // would require an unusual behavior of failing when the limit is exceeded. // That behavior would not be useful in practice because reading would never // end cleanly. - explicit ScopedLimiter(LimitingReaderBase* reader, Options options); + explicit ScopedLimiter(LimitingReaderBase* reader + ABSL_ATTRIBUTE_LIFETIME_BOUND, + Options options); ScopedLimiter(const ScopedLimiter&) = delete; ScopedLimiter& operator=(const ScopedLimiter&) = delete; @@ -584,7 +586,8 @@ bool LimitingReader::SyncImpl(SyncType sync_type) { return sync_ok; } -inline ScopedLimiter::ScopedLimiter(LimitingReaderBase* reader, Options options) +inline ScopedLimiter::ScopedLimiter( + LimitingReaderBase* reader ABSL_ATTRIBUTE_LIFETIME_BOUND, Options options) : reader_(RIEGELI_ASSERT_NOTNULL(reader)), old_max_pos_(reader_->max_pos()), old_exact_(reader_->exact()), diff --git a/riegeli/bytes/pullable_reader.h b/riegeli/bytes/pullable_reader.h index 2bdb0322..18d4686f 100644 --- a/riegeli/bytes/pullable_reader.h +++ b/riegeli/bytes/pullable_reader.h @@ -20,6 +20,7 @@ #include #include +#include "absl/base/attributes.h" #include "absl/base/optimization.h" #include "absl/functional/function_ref.h" #include "absl/strings/cord.h" @@ -167,7 +168,7 @@ class PullableReader : public Reader { // position reflects what has been read from the source and must not be changed. class PullableReader::BehindScratch { public: - explicit BehindScratch(PullableReader* context); + explicit BehindScratch(PullableReader* context ABSL_ATTRIBUTE_LIFETIME_BOUND); BehindScratch(BehindScratch&& that) = default; BehindScratch& operator=(BehindScratch&&) = delete; @@ -209,7 +210,8 @@ inline bool PullableReader::scratch_used() const { return scratch_ != nullptr && !scratch_->buffer.empty(); } -inline PullableReader::BehindScratch::BehindScratch(PullableReader* context) +inline PullableReader::BehindScratch::BehindScratch( + PullableReader* context ABSL_ATTRIBUTE_LIFETIME_BOUND) : context_(context) { if (ABSL_PREDICT_FALSE(context_->scratch_used())) Enter(); } diff --git a/riegeli/bytes/pushable_backward_writer.h b/riegeli/bytes/pushable_backward_writer.h index a7c5dedf..5b40bdd1 100644 --- a/riegeli/bytes/pushable_backward_writer.h +++ b/riegeli/bytes/pushable_backward_writer.h @@ -20,6 +20,7 @@ #include #include +#include "absl/base/attributes.h" #include "absl/base/optimization.h" #include "absl/strings/cord.h" #include "absl/strings/string_view.h" @@ -177,7 +178,8 @@ class PushableBackwardWriter : public BackwardWriter { // destination and must not be changed. class PushableBackwardWriter::BehindScratch { public: - explicit BehindScratch(PushableBackwardWriter* context); + explicit BehindScratch( + PushableBackwardWriter* context ABSL_ATTRIBUTE_LIFETIME_BOUND); BehindScratch(BehindScratch&& that) = default; BehindScratch& operator=(BehindScratch&&) = delete; @@ -222,7 +224,7 @@ inline bool PushableBackwardWriter::scratch_used() const { } inline PushableBackwardWriter::BehindScratch::BehindScratch( - PushableBackwardWriter* context) + PushableBackwardWriter* context ABSL_ATTRIBUTE_LIFETIME_BOUND) : context_(context) { if (ABSL_PREDICT_FALSE(context_->scratch_used())) Enter(); } diff --git a/riegeli/bytes/pushable_writer.h b/riegeli/bytes/pushable_writer.h index 55ab2640..f4a26874 100644 --- a/riegeli/bytes/pushable_writer.h +++ b/riegeli/bytes/pushable_writer.h @@ -20,6 +20,7 @@ #include #include +#include "absl/base/attributes.h" #include "absl/base/optimization.h" #include "absl/strings/cord.h" #include "absl/strings/string_view.h" @@ -183,7 +184,7 @@ class PushableWriter : public Writer { // destination and must not be changed. class PushableWriter::BehindScratch { public: - explicit BehindScratch(PushableWriter* context); + explicit BehindScratch(PushableWriter* context ABSL_ATTRIBUTE_LIFETIME_BOUND); BehindScratch(BehindScratch&& that) = default; BehindScratch& operator=(BehindScratch&&) = delete; @@ -225,7 +226,8 @@ inline bool PushableWriter::scratch_used() const { return scratch_ != nullptr && !scratch_->buffer.empty(); } -inline PushableWriter::BehindScratch::BehindScratch(PushableWriter* context) +inline PushableWriter::BehindScratch::BehindScratch( + PushableWriter* context ABSL_ATTRIBUTE_LIFETIME_BOUND) : context_(context) { if (ABSL_PREDICT_FALSE(context_->scratch_used())) Enter(); } diff --git a/riegeli/bytes/string_reader.h b/riegeli/bytes/string_reader.h index b1cbf4f3..fc22ff0c 100644 --- a/riegeli/bytes/string_reader.h +++ b/riegeli/bytes/string_reader.h @@ -109,7 +109,8 @@ class StringReader : public StringReaderBase { template ::value, int> = 0> - explicit StringReader(const char* src, size_t size); + explicit StringReader(const char* src ABSL_ATTRIBUTE_LIFETIME_BOUND, + size_t size); StringReader(StringReader&& that) = default; StringReader& operator=(StringReader&& that) = default; @@ -221,7 +222,8 @@ template template < typename DependentSrc, std::enable_if_t::value, int>> -inline StringReader::StringReader(const char* src, size_t size) +inline StringReader::StringReader( + const char* src ABSL_ATTRIBUTE_LIFETIME_BOUND, size_t size) : StringReader(absl::string_view(src, size)) {} template diff --git a/riegeli/bytes/writer.h b/riegeli/bytes/writer.h index 3c0aa0a4..1b195879 100644 --- a/riegeli/bytes/writer.h +++ b/riegeli/bytes/writer.h @@ -59,7 +59,7 @@ class WriterAbslStringifySink { WriterAbslStringifySink() = default; // Will write to `*dest`. - explicit WriterAbslStringifySink(Writer* dest) + explicit WriterAbslStringifySink(Writer* dest ABSL_ATTRIBUTE_LIFETIME_BOUND) : dest_(RIEGELI_ASSERT_NOTNULL(dest)) {} WriterAbslStringifySink(WriterAbslStringifySink&& that) = default; diff --git a/riegeli/csv/csv_record.h b/riegeli/csv/csv_record.h index 566c9365..a53a1e5c 100644 --- a/riegeli/csv/csv_record.h +++ b/riegeli/csv/csv_record.h @@ -522,7 +522,8 @@ class CsvHeaderConstant { std::integral_constant, std::is_convertible...>::value, int> = 0> - /*implicit*/ constexpr CsvHeaderConstant(Fields&&... fields) + /*implicit*/ constexpr CsvHeaderConstant( + Fields&&... fields ABSL_ATTRIBUTE_LIFETIME_BOUND) : fields_{std::forward(fields)...} {} // Will create a `CsvHeader` consisting of the given sequence of field names. @@ -540,7 +541,8 @@ class CsvHeaderConstant { std::is_convertible...>::value, int> = 0> explicit constexpr CsvHeaderConstant( - std::string (*normalizer)(absl::string_view), Fields&&... fields) + std::string (*normalizer)(absl::string_view), + Fields&&... fields ABSL_ATTRIBUTE_LIFETIME_BOUND) : normalizer_(normalizer), fields_{std::forward(fields)...} {} // Will create a `CsvHeader` consisting of field names from `base_header` @@ -560,7 +562,9 @@ class CsvHeaderConstant { std::is_convertible...>::value, int> = 0> explicit constexpr CsvHeaderConstant( - const CsvHeaderConstant& base_header, Fields&&... fields) + const CsvHeaderConstant& base_header + ABSL_ATTRIBUTE_LIFETIME_BOUND, + Fields&&... fields ABSL_ATTRIBUTE_LIFETIME_BOUND) : CsvHeaderConstant(base_header, std::make_index_sequence(), std::forward(fields)...) {} diff --git a/riegeli/digests/digester_handle.h b/riegeli/digests/digester_handle.h index 9d8e1859..650af7f6 100644 --- a/riegeli/digests/digester_handle.h +++ b/riegeli/digests/digester_handle.h @@ -138,7 +138,7 @@ class // Creates a `DigesterBaseHandle` which points to `target`. template ::value, int> = 0> - explicit DigesterBaseHandle(T* target) + explicit DigesterBaseHandle(T* target ABSL_ATTRIBUTE_LIFETIME_BOUND) : methods_(&kMethods), target_(target) {} DigesterBaseHandle(const DigesterBaseHandle& that) = default; @@ -493,7 +493,7 @@ class DigesterHandle : public DigesterBaseHandle { template < typename T, std::enable_if_t::value, int> = 0> - explicit DigesterHandle(T* target) + explicit DigesterHandle(T* target ABSL_ATTRIBUTE_LIFETIME_BOUND) : DigesterBaseHandle(&kMethods, target) {} DigesterHandle(const DigesterHandle& that) = default; diff --git a/riegeli/messages/message_parse.h b/riegeli/messages/message_parse.h index d381b6f1..af324ce7 100644 --- a/riegeli/messages/message_parse.h +++ b/riegeli/messages/message_parse.h @@ -178,7 +178,8 @@ class ReaderInputStream : public google::protobuf::io::ZeroCopyInputStream { ReaderInputStream() = default; // Will read from `*src`. - explicit ReaderInputStream(Reader* src) : src_(RIEGELI_ASSERT_NOTNULL(src)) {} + explicit ReaderInputStream(Reader* src ABSL_ATTRIBUTE_LIFETIME_BOUND) + : src_(RIEGELI_ASSERT_NOTNULL(src)) {} ABSL_ATTRIBUTE_REINITIALIZES void Reset() { src_ = nullptr; } ABSL_ATTRIBUTE_REINITIALIZES void Reset(Reader* src) { diff --git a/riegeli/messages/message_serialize.h b/riegeli/messages/message_serialize.h index c5d96c67..05c0cb5c 100644 --- a/riegeli/messages/message_serialize.h +++ b/riegeli/messages/message_serialize.h @@ -192,7 +192,7 @@ class WriterOutputStream : public google::protobuf::io::ZeroCopyOutputStream { WriterOutputStream() = default; // Will write to `*dest`. - explicit WriterOutputStream(Writer* dest) + explicit WriterOutputStream(Writer* dest ABSL_ATTRIBUTE_LIFETIME_BOUND) : dest_(RIEGELI_ASSERT_NOTNULL(dest)) {} ABSL_ATTRIBUTE_REINITIALIZES void Reset() { dest_ = nullptr; } diff --git a/riegeli/records/tools/tfrecord_recognizer.h b/riegeli/records/tools/tfrecord_recognizer.h index 8c164eb5..d15ccb00 100644 --- a/riegeli/records/tools/tfrecord_recognizer.h +++ b/riegeli/records/tools/tfrecord_recognizer.h @@ -1,3 +1,4 @@ +#include "absl/base/attributes.h" // Copyright 2018 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,7 +25,8 @@ namespace riegeli { class TFRecordRecognizer : public Object { public: - explicit TFRecordRecognizer(Reader* byte_reader); + explicit TFRecordRecognizer( + Reader* byte_reader ABSL_ATTRIBUTE_LIFETIME_BOUND); // Ensures that the file looks like a valid TFRecord file. // @@ -43,7 +45,8 @@ class TFRecordRecognizer : public Object { // Implementation details follow. -inline TFRecordRecognizer::TFRecordRecognizer(Reader* byte_reader) +inline TFRecordRecognizer::TFRecordRecognizer( + Reader* byte_reader ABSL_ATTRIBUTE_LIFETIME_BOUND) : byte_reader_(RIEGELI_ASSERT_NOTNULL(byte_reader)) {} } // namespace riegeli