Add nullability annotations to Abseil Flags reflection APIs.

Annotates FindCommandLineFlag with absl_nullable and the values in the map returned by GetAllFlags with absl_nonnull.

PiperOrigin-RevId: 987595681
Change-Id: I13c35707dab408c445a7631998ec7b70d70cfd43
diff --git a/absl/flags/BUILD.bazel b/absl/flags/BUILD.bazel
index 59cae99..59771c7 100644
--- a/absl/flags/BUILD.bazel
+++ b/absl/flags/BUILD.bazel
@@ -208,6 +208,7 @@
         "//absl/base:core_headers",
         "//absl/base:fast_type_id",
         "//absl/base:no_destructor",
+        "//absl/base:nullability",
         "//absl/container:flat_hash_map",
         "//absl/strings",
         "//absl/strings:string_view",
diff --git a/absl/flags/CMakeLists.txt b/absl/flags/CMakeLists.txt
index a96e294..0e40085 100644
--- a/absl/flags/CMakeLists.txt
+++ b/absl/flags/CMakeLists.txt
@@ -174,6 +174,7 @@
     absl::flags_private_handle_accessor
     absl::flat_hash_map
     absl::no_destructor
+    absl::nullability
     absl::string_view
     absl::strings
     absl::synchronization
diff --git a/absl/flags/reflection.cc b/absl/flags/reflection.cc
index 89625b1..e7eeaa3 100644
--- a/absl/flags/reflection.cc
+++ b/absl/flags/reflection.cc
@@ -28,6 +28,7 @@
 
 #include "absl/base/config.h"
 #include "absl/base/no_destructor.h"
+#include "absl/base/nullability.h"
 #include "absl/base/thread_annotations.h"
 #include "absl/container/flat_hash_map.h"
 #include "absl/flags/commandlineflag.h"
@@ -352,7 +353,7 @@
 
 // --------------------------------------------------------------------
 
-CommandLineFlag* FindCommandLineFlag(absl::string_view name) {
+CommandLineFlag* absl_nullable FindCommandLineFlag(absl::string_view name) {
   if (name.empty()) return nullptr;
   flags_internal::FlagRegistry& registry =
       flags_internal::FlagRegistry::GlobalRegistry();
@@ -361,7 +362,8 @@
 
 // --------------------------------------------------------------------
 
-absl::flat_hash_map<absl::string_view, absl::CommandLineFlag*> GetAllFlags() {
+absl::flat_hash_map<absl::string_view, absl::CommandLineFlag* absl_nonnull>
+GetAllFlags() {
   absl::flat_hash_map<absl::string_view, absl::CommandLineFlag*> res;
   flags_internal::ForEachFlag([&](CommandLineFlag& flag) {
     if (!flag.IsRetired()) res.insert({flag.Name(), &flag});
diff --git a/absl/flags/reflection.h b/absl/flags/reflection.h
index 7236965..aeaf728 100644
--- a/absl/flags/reflection.h
+++ b/absl/flags/reflection.h
@@ -27,6 +27,7 @@
 #include <string>
 
 #include "absl/base/config.h"
+#include "absl/base/nullability.h"
 #include "absl/container/flat_hash_map.h"
 #include "absl/flags/commandlineflag.h"
 #include "absl/flags/internal/commandlineflag.h"
@@ -43,11 +44,13 @@
 // Returns the reflection handle of an Abseil flag of the specified name, or
 // `nullptr` if not found. This function will emit a warning if the name of a
 // 'retired' flag is specified.
-absl::CommandLineFlag* FindCommandLineFlag(absl::string_view name);
+absl::CommandLineFlag* absl_nullable FindCommandLineFlag(
+    absl::string_view name);
 
 // Returns current state of the Flags registry in a form of mapping from flag
 // name to a flag reflection handle.
-absl::flat_hash_map<absl::string_view, absl::CommandLineFlag*> GetAllFlags();
+absl::flat_hash_map<absl::string_view, absl::CommandLineFlag* absl_nonnull>
+GetAllFlags();
 
 //------------------------------------------------------------------------------
 // FlagSaver
@@ -81,7 +84,8 @@
   FlagSaver& operator=(const FlagSaver&) = delete;
 
  private:
-  std::unique_ptr<flags_internal::FlagSaverImpl> impl_;
+  // Null if no flags restoration is needed.
+  absl_nullable std::unique_ptr<flags_internal::FlagSaverImpl> impl_;
 };
 
 //-----------------------------------------------------------------------------