diff options
author | swarmer <[email protected]> | 2024-09-26 22:16:03 +0300 |
---|---|---|
committer | swarmer <[email protected]> | 2024-09-26 22:36:37 +0300 |
commit | 69ce19dae9cc421f3d3a3b650e01b2f9bece79b5 (patch) | |
tree | b73fa8fbd2b795a54301e37aaaa6259811040823 | |
parent | 9598e6ce746a6ae937ccc291c9c5e64db14ce62e (diff) |
check lifetime bound of output streams
commit_hash:17de7afe0f415c511e587b2f2607cbbc2348742e
-rw-r--r-- | util/generic/flags.h | 2 | ||||
-rw-r--r-- | util/generic/maybe.h | 2 | ||||
-rw-r--r-- | util/stream/format.h | 14 | ||||
-rw-r--r-- | util/stream/input.h | 2 | ||||
-rw-r--r-- | util/stream/output.h | 19 | ||||
-rw-r--r-- | util/string/join.h | 2 |
6 files changed, 21 insertions, 20 deletions
diff --git a/util/generic/flags.h b/util/generic/flags.h index de56e8b5999..b263230479c 100644 --- a/util/generic/flags.h +++ b/util/generic/flags.h @@ -190,7 +190,7 @@ public: return *this; } - friend IOutputStream& operator<<(IOutputStream& stream, const TFlags& flags) { + friend IOutputStream& operator<<(IOutputStream& stream Y_LIFETIME_BOUND, const TFlags& flags) { ::NPrivate::PrintFlags(stream, static_cast<ui64>(flags.Value_), sizeof(TInt)); return stream; } diff --git a/util/generic/maybe.h b/util/generic/maybe.h index ceaf4d66f0c..1de6bf38945 100644 --- a/util/generic/maybe.h +++ b/util/generic/maybe.h @@ -858,7 +858,7 @@ constexpr bool operator>=(const U& value, const TMaybe<T, TPolicy>& maybe) { class IOutputStream; template <class T, class TPolicy> -inline IOutputStream& operator<<(IOutputStream& out, const TMaybe<T, TPolicy>& maybe) { +inline IOutputStream& operator<<(IOutputStream& out Y_LIFETIME_BOUND, const TMaybe<T, TPolicy>& maybe) { if (maybe.Defined()) { out << *maybe; } else { diff --git a/util/stream/format.h b/util/stream/format.h index 56c3083bbca..c6ee9c720fc 100644 --- a/util/stream/format.h +++ b/util/stream/format.h @@ -67,7 +67,7 @@ namespace NFormatPrivate { }; template <typename T> - IOutputStream& operator<<(IOutputStream& o, const TLeftPad<T>& lp) { + IOutputStream& operator<<(IOutputStream& o Y_LIFETIME_BOUND, const TLeftPad<T>& lp) { TTempBuf buf; TMemoryOutput ss(buf.Data(), buf.Size()); ss << lp.Value; @@ -94,7 +94,7 @@ namespace NFormatPrivate { }; template <typename T> - IOutputStream& operator<<(IOutputStream& o, const TRightPad<T>& lp) { + IOutputStream& operator<<(IOutputStream& o Y_LIFETIME_BOUND, const TRightPad<T>& lp) { TTempBuf buf; TMemoryOutput ss(buf.Data(), buf.Size()); ss << lp.Value; @@ -123,7 +123,7 @@ namespace NFormatPrivate { using TUnsignedBaseNumber = TBaseNumber<std::make_unsigned_t<std::remove_cv_t<T>>, Base>; template <typename TStream, typename T, size_t Base> - TStream& ToStreamImpl(TStream& stream, const TBaseNumber<T, Base>& value) { + TStream& ToStreamImpl(TStream& stream Y_LIFETIME_BOUND, const TBaseNumber<T, Base>& value) { char buf[8 * sizeof(T) + 1]; /* Add 1 for sign. */ TStringBuf str(buf, IntToString<Base>(value.Value, buf, sizeof(buf))); @@ -149,12 +149,12 @@ namespace NFormatPrivate { } template <typename T, size_t Base> - IOutputStream& operator<<(IOutputStream& stream, const TBaseNumber<T, Base>& value) { + IOutputStream& operator<<(IOutputStream& stream Y_LIFETIME_BOUND, const TBaseNumber<T, Base>& value) { return ToStreamImpl(stream, value); } template <typename T, size_t Base> - std::ostream& operator<<(std::ostream& stream, const TBaseNumber<T, Base>& value) { + std::ostream& operator<<(std::ostream& stream Y_LIFETIME_BOUND, const TBaseNumber<T, Base>& value) { return ToStreamImpl(stream, value); } @@ -169,7 +169,7 @@ namespace NFormatPrivate { }; template <typename Char, size_t Base> - IOutputStream& operator<<(IOutputStream& os, const TBaseText<Char, Base>& text) { + IOutputStream& operator<<(IOutputStream& os Y_LIFETIME_BOUND, const TBaseText<Char, Base>& text) { for (size_t i = 0; i < text.Text.size(); ++i) { if (i != 0) { os << ' '; @@ -190,7 +190,7 @@ namespace NFormatPrivate { }; template <typename T> - IOutputStream& operator<<(IOutputStream& o, const TFloatPrecision<T>& prec) { + IOutputStream& operator<<(IOutputStream& o Y_LIFETIME_BOUND, const TFloatPrecision<T>& prec) { char buf[512]; size_t count = FloatToString(prec.Value, buf, sizeof(buf), prec.Mode, prec.NDigits); o << TStringBuf(buf, count); diff --git a/util/stream/input.h b/util/stream/input.h index b1facec2545..c64159b28c4 100644 --- a/util/stream/input.h +++ b/util/stream/input.h @@ -256,7 +256,7 @@ void In(IInputStream& in, T& value); * @see operator<<(IOutputStream&, T&) */ template <typename T> -inline IInputStream& operator>>(IInputStream& in, T& value) { +inline IInputStream& operator>>(IInputStream& in Y_LIFETIME_BOUND, T& value) { In<T>(in, value); return in; } diff --git a/util/stream/output.h b/util/stream/output.h index 1f903a655af..8acd66a4ba8 100644 --- a/util/stream/output.h +++ b/util/stream/output.h @@ -7,6 +7,7 @@ #include <util/generic/string.h> #include <util/generic/strbuf.h> #include <util/generic/typetraits.h> +#include <util/system/compiler.h> #include <type_traits> @@ -207,54 +208,54 @@ void Out<const wchar16*>(IOutputStream& o, const wchar16* w); template <> void Out<const wchar32*>(IOutputStream& o, const wchar32* w); -static inline IOutputStream& operator<<(IOutputStream& o, TStreamManipulator m) { +static inline IOutputStream& operator<<(IOutputStream& o Y_LIFETIME_BOUND, TStreamManipulator m) { m(o); return o; } -static inline IOutputStream& operator<<(IOutputStream& o, const char* t) { +static inline IOutputStream& operator<<(IOutputStream& o Y_LIFETIME_BOUND, const char* t) { Out<const char*>(o, t); return o; } -static inline IOutputStream& operator<<(IOutputStream& o, char* t) { +static inline IOutputStream& operator<<(IOutputStream& o Y_LIFETIME_BOUND, char* t) { Out<const char*>(o, t); return o; } template <class T> -static inline std::enable_if_t<std::is_scalar<T>::value, IOutputStream&> operator<<(IOutputStream& o, T t) { +static inline std::enable_if_t<std::is_scalar<T>::value, IOutputStream&> operator<<(IOutputStream& o Y_LIFETIME_BOUND, T t) { Out<T>(o, t); return o; } template <class T> -static inline std::enable_if_t<!std::is_scalar<T>::value, IOutputStream&> operator<<(IOutputStream& o, const T& t) { +static inline std::enable_if_t<!std::is_scalar<T>::value, IOutputStream&> operator<<(IOutputStream& o Y_LIFETIME_BOUND, const T& t) { Out<T>(o, t); return o; } -static inline IOutputStream& operator<<(IOutputStream& o, const wchar16* t) { +static inline IOutputStream& operator<<(IOutputStream& o Y_LIFETIME_BOUND, const wchar16* t) { Out<const wchar16*>(o, t); return o; } -static inline IOutputStream& operator<<(IOutputStream& o, wchar16* t) { +static inline IOutputStream& operator<<(IOutputStream& o Y_LIFETIME_BOUND, wchar16* t) { Out<const wchar16*>(o, t); return o; } -static inline IOutputStream& operator<<(IOutputStream& o, const wchar32* t) { +static inline IOutputStream& operator<<(IOutputStream& o Y_LIFETIME_BOUND, const wchar32* t) { Out<const wchar32*>(o, t); return o; } -static inline IOutputStream& operator<<(IOutputStream& o, wchar32* t) { +static inline IOutputStream& operator<<(IOutputStream& o Y_LIFETIME_BOUND, wchar32* t) { Out<const wchar32*>(o, t); return o; } diff --git a/util/string/join.h b/util/string/join.h index 720951abc53..f0d28df2919 100644 --- a/util/string/join.h +++ b/util/string/join.h @@ -203,7 +203,7 @@ JoinSeq(TCharType delim, const TContainer& data) { */ template <class TIterB, class TIterE> struct TRangeJoiner { - friend constexpr IOutputStream& operator<<(IOutputStream& stream, const TRangeJoiner<TIterB, TIterE>& rangeJoiner) { + friend constexpr IOutputStream& operator<<(IOutputStream& stream Y_LIFETIME_BOUND, const TRangeJoiner<TIterB, TIterE>& rangeJoiner) { if (rangeJoiner.b != rangeJoiner.e) { stream << *rangeJoiner.b; |