[clang-tools-extra] 65299c9 - [clang-tidy][docs] Use std::optional instead of absl::optional in examples

Dmitri Gribenko via cfe-commits cfe-commits at lists.llvm.org
Sat Jun 11 12:08:44 PDT 2022


Author: Dmitri Gribenko
Date: 2022-06-11T21:03:43+02:00
New Revision: 65299c9c652f3ce4958011ffe28119d0eff0f38d

URL: https://github.com/llvm/llvm-project/commit/65299c9c652f3ce4958011ffe28119d0eff0f38d
DIFF: https://github.com/llvm/llvm-project/commit/65299c9c652f3ce4958011ffe28119d0eff0f38d.diff

LOG: [clang-tidy][docs] Use std::optional instead of absl::optional in examples

The standard type is vastly more popular than the Abseil polyfill, so it
makes more sense to use it in documentation, even though the checker
actually understands both (and that fact is documented already).

Added: 
    

Modified: 
    clang-tools-extra/docs/clang-tidy/checks/bugprone-unchecked-optional-access.rst

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone-unchecked-optional-access.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone-unchecked-optional-access.rst
index 9c53c8a6d175f..5d8b76aec771d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone-unchecked-optional-access.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone-unchecked-optional-access.rst
@@ -42,7 +42,7 @@ existence check:
 
 .. code-block:: c++
 
-   void f(absl::optional<int> opt) {
+   void f(std::optional<int> opt) {
      use(*opt); // unsafe: it is unclear whether `opt` has a value.
    }
 
@@ -54,7 +54,7 @@ branches of the code. For example:
 
 .. code-block:: c++
 
-   void f(absl::optional<int> opt) {
+   void f(std::optional<int> opt) {
      if (opt.has_value()) {
      } else {
        use(opt.value()); // unsafe: it is clear that `opt` does *not* have a value.
@@ -99,11 +99,11 @@ optional has a value. For example:
 
 .. code-block:: c++
 
-   void g(absl::optional<int> opt) {
+   void g(std::optional<int> opt) {
      use(*opt); // unsafe: it is unclear whether `opt` has a value.
    }
 
-   void f(absl::optional<int> opt) {
+   void f(std::optional<int> opt) {
      if (opt.has_value()) {
        g(opt);
      }
@@ -121,7 +121,7 @@ example:
 
 .. code-block:: c++
 
-   void f(absl::optional<int> opt) {
+   void f(std::optional<int> opt) {
      if (opt.has_value()) {
        use(*opt);
      }
@@ -137,9 +137,9 @@ have a value. For example:
 
 .. code-block:: c++
 
-   void f(absl::optional<int> opt1) {
+   void f(std::optional<int> opt1) {
      if (opt1.has_value()) {
-       absl::optional<int> opt2 = opt1;
+       std::optional<int> opt2 = opt1;
        use(*opt2);
      }
    }
@@ -154,7 +154,7 @@ a value. For example:
 
 .. code-block:: c++
 
-   void f(absl::optional<int> opt) {
+   void f(std::optional<int> opt) {
      DCHECK(opt.has_value());
      use(*opt);
    }
@@ -168,7 +168,7 @@ paths that lead to an access. For example:
 
 .. code-block:: c++
 
-   void f(absl::optional<int> opt) {
+   void f(std::optional<int> opt) {
      bool safe = false;
      if (opt.has_value() && SomeOtherCondition()) {
        safe = true;
@@ -223,7 +223,7 @@ check the optional again in the local scope of the callee. For example:
      use(val);
    }
 
-   void f(absl::optional<int> opt) {
+   void f(std::optional<int> opt) {
      if (opt.has_value()) {
        g(*opt);
      }
@@ -234,7 +234,7 @@ and
 .. code-block:: c++
 
    struct S {
-     absl::optional<int> opt;
+     std::optional<int> opt;
      int x;
    };
 
@@ -260,7 +260,7 @@ The check is aware of aliases of optional types that are created via
 
 .. code-block:: c++
 
-   using OptionalInt = absl::optional<int>;
+   using OptionalInt = std::optional<int>;
 
    void f(OptionalInt opt) {
      use(opt.value()); // unsafe: it is unclear whether `opt` has a value.


        


More information about the cfe-commits mailing list