From 55621d1af55be7bf9a2c8e5dcef4368d9a6d4e51 Mon Sep 17 00:00:00 2001 From: Dmitri Gribenko Date: Mon, 11 Dec 2023 09:07:07 -0800 Subject: Add nullability annotations PiperOrigin-RevId: 589842893 Change-Id: I9657761d1f71c665582406f278c6605f6d382f6d --- absl/strings/str_format.h | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'absl/strings/str_format.h') diff --git a/absl/strings/str_format.h b/absl/strings/str_format.h index c9b350fd..66b6af58 100644 --- a/absl/strings/str_format.h +++ b/absl/strings/str_format.h @@ -79,6 +79,7 @@ #include "absl/base/attributes.h" #include "absl/base/config.h" +#include "absl/base/nullability.h" #include "absl/strings/internal/str_format/arg.h" // IWYU pragma: export #include "absl/strings/internal/str_format/bind.h" // IWYU pragma: export #include "absl/strings/internal/str_format/checker.h" // IWYU pragma: export @@ -110,7 +111,8 @@ class UntypedFormatSpec { explicit UntypedFormatSpec(string_view s) : spec_(s) {} protected: - explicit UntypedFormatSpec(const str_format_internal::ParsedFormatBase* pc) + explicit UntypedFormatSpec( + absl::Nonnull pc) : spec_(pc) {} private: @@ -150,7 +152,7 @@ str_format_internal::StreamedWrapper FormatStreamed(const T& v) { // EXPECT_EQ(8, n); class FormatCountCapture { public: - explicit FormatCountCapture(int* p) : p_(p) {} + explicit FormatCountCapture(absl::Nonnull p) : p_(p) {} private: // FormatCountCaptureHelper is used to define FormatConvertImpl() for this @@ -159,8 +161,8 @@ class FormatCountCapture { // Unused() is here because of the false positive from -Wunused-private-field // p_ is used in the templated function of the friend FormatCountCaptureHelper // class. - int* Unused() { return p_; } - int* p_; + absl::Nonnull Unused() { return p_; } + absl::Nonnull p_; }; // FormatSpec @@ -375,7 +377,7 @@ ABSL_MUST_USE_RESULT std::string StrFormat(const FormatSpec& format, // std::string orig("For example PI is approximately "); // std::cout << StrAppendFormat(&orig, "%12.6f", 3.14); template -std::string& StrAppendFormat(std::string* dst, +std::string& StrAppendFormat(absl::Nonnull dst, const FormatSpec& format, const Args&... args) { return str_format_internal::AppendPack( @@ -435,7 +437,7 @@ int PrintF(const FormatSpec& format, const Args&... args) { // Outputs: "The capital of Mongolia is Ulaanbaatar" // template -int FPrintF(std::FILE* output, const FormatSpec& format, +int FPrintF(absl::Nonnull output, const FormatSpec& format, const Args&... args) { return str_format_internal::FprintF( output, str_format_internal::UntypedFormatSpecImpl::Extract(format), @@ -464,8 +466,8 @@ int FPrintF(std::FILE* output, const FormatSpec& format, // Post-condition: output == "The capital of Mongolia is Ulaanbaatar" // template -int SNPrintF(char* output, std::size_t size, const FormatSpec& format, - const Args&... args) { +int SNPrintF(absl::Nonnull output, std::size_t size, + const FormatSpec& format, const Args&... args) { return str_format_internal::SnprintF( output, size, str_format_internal::UntypedFormatSpecImpl::Extract(format), {str_format_internal::FormatArgImpl(args)...}); @@ -498,7 +500,7 @@ class FormatRawSink { template ::value>::type> - FormatRawSink(T* raw) // NOLINT + FormatRawSink(absl::Nonnull raw) // NOLINT : sink_(raw) {} private: @@ -855,14 +857,16 @@ class FormatSink { } // Support `absl::Format(&sink, format, args...)`. - friend void AbslFormatFlush(FormatSink* sink, absl::string_view v) { + friend void AbslFormatFlush(absl::Nonnull sink, + absl::string_view v) { sink->Append(v); } private: friend str_format_internal::FormatSinkImpl; - explicit FormatSink(str_format_internal::FormatSinkImpl* s) : sink_(s) {} - str_format_internal::FormatSinkImpl* sink_; + explicit FormatSink(absl::Nonnull s) + : sink_(s) {} + absl::Nonnull sink_; }; // FormatConvertResult -- cgit v1.2.3