From 65299c9c652f3ce4958011ffe28119d0eff0f38d Mon Sep 17 00:00:00 2001 From: Dmitri Gribenko Date: Sat, 11 Jun 2022 01:41:10 +0200 Subject: [PATCH] [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). --- .../bugprone-unchecked-optional-access.rst | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) 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 opt) { + void f(std::optional 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 opt) { + void f(std::optional 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 opt) { + void g(std::optional opt) { use(*opt); // unsafe: it is unclear whether `opt` has a value. } - void f(absl::optional opt) { + void f(std::optional opt) { if (opt.has_value()) { g(opt); } @@ -121,7 +121,7 @@ example: .. code-block:: c++ - void f(absl::optional opt) { + void f(std::optional opt) { if (opt.has_value()) { use(*opt); } @@ -137,9 +137,9 @@ have a value. For example: .. code-block:: c++ - void f(absl::optional opt1) { + void f(std::optional opt1) { if (opt1.has_value()) { - absl::optional opt2 = opt1; + std::optional opt2 = opt1; use(*opt2); } } @@ -154,7 +154,7 @@ a value. For example: .. code-block:: c++ - void f(absl::optional opt) { + void f(std::optional 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 opt) { + void f(std::optional 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 opt) { + void f(std::optional opt) { if (opt.has_value()) { g(*opt); } @@ -234,7 +234,7 @@ and .. code-block:: c++ struct S { - absl::optional opt; + std::optional 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; + using OptionalInt = std::optional; void f(OptionalInt opt) { use(opt.value()); // unsafe: it is unclear whether `opt` has a value.