[llvm-branch-commits] [clang-tools-extra] [clang-tidy][docs] Rewrite readability check docs to Markdown [4/5] (PR #221641)

Zeyi Xu via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Sep 6 22:51:20 PDT 2026


https://github.com/zeyi2 created https://github.com/llvm/llvm-project/pull/221641

<sub>Stack created with <a href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>

>From 71504ce4ac46cf778850b50d90b6e4be9c171e3f Mon Sep 17 00:00:00 2001
From: Zeyi Xu <mitchell.xu2 at gmail.com>
Date: Mon, 7 Sep 2026 13:38:45 +0800
Subject: [PATCH] [clang-tidy][docs] Rewrite readability check docs to Markdown
 [4/5]

---
 .../redundant-lambda-parameter-list.md        |  56 ++---
 .../readability/redundant-member-init.md      |  90 ++++---
 .../checks/readability/redundant-nested-if.md |  75 +++---
 .../readability/redundant-parentheses.md      |  47 ++--
 .../readability/redundant-preprocessor.md     | 103 ++++----
 .../readability/redundant-qualified-alias.md  |  33 ++-
 .../readability/redundant-string-init.md      |  57 +++--
 .../checks/readability/redundant-typename.md  |  46 ++--
 .../reference-to-constructed-temporary.md     |  26 +-
 .../readability/simplify-boolean-expr.md      | 224 +++++++++---------
 10 files changed, 371 insertions(+), 386 deletions(-)

diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-lambda-parameter-list.md b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-lambda-parameter-list.md
index 5233be86ceb77..a2a68b9c97ce7 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-lambda-parameter-list.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-lambda-parameter-list.md
@@ -1,35 +1,35 @@
-.. title:: clang-tidy - readability-redundant-lambda-parameter-list
+```{title} clang-tidy - readability-redundant-lambda-parameter-list
+```
 
-readability-redundant-lambda-parameter-list
-===========================================
+# readability-redundant-lambda-parameter-list
 
 Finds lambda expressions with a redundant empty parameter list and removes it.
 
 In C++11 and later, a lambda with no parameters does not require an explicit
-``()`` unless it has a specifier such as ``mutable``, ``noexcept``, or a
-trailing return type. In C++23 and later, ``()`` is redundant even when such
+`()` unless it has a specifier such as `mutable`, `noexcept`, or a
+trailing return type. In C++23 and later, `()` is redundant even when such
 specifiers are present.
 
-.. code-block:: c++
-
-  // C++11 and later - the following lambdas will be rewritten:
-  auto a = []() { return 42; };
-  // becomes:
-  auto a = [] { return 42; };
-
-  auto b = [x = 1]() { return x; };
-  // becomes:
-  auto b = [x = 1] { return x; };
-
-  // C++23 and later - the following lambdas will also be rewritten:
-  auto c = []() mutable {};
-  // becomes:
-  auto c = [] mutable {};
-
-  auto d = []() noexcept {};
-  // becomes:
-  auto d = [] noexcept {};
-
-  auto e = []() -> int { return 0; };
-  // becomes:
-  auto e = [] -> int { return 0; };
+```c++
+// C++11 and later - the following lambdas will be rewritten:
+auto a = []() { return 42; };
+// becomes:
+auto a = [] { return 42; };
+
+auto b = [x = 1]() { return x; };
+// becomes:
+auto b = [x = 1] { return x; };
+
+// C++23 and later - the following lambdas will also be rewritten:
+auto c = []() mutable {};
+// becomes:
+auto c = [] mutable {};
+
+auto d = []() noexcept {};
+// becomes:
+auto d = [] noexcept {};
+
+auto e = []() -> int { return 0; };
+// becomes:
+auto e = [] -> int { return 0; };
+```
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-member-init.md b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-member-init.md
index aab2431db6aba..5e2d4dda90c12 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-member-init.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-member-init.md
@@ -1,51 +1,49 @@
-.. title:: clang-tidy - readability-redundant-member-init
+```{title} clang-tidy - readability-redundant-member-init
+```
 
-readability-redundant-member-init
-=================================
+# readability-redundant-member-init
 
 Finds member initializations that are unnecessary because the same default
 constructor would be called if they were not present.
 
-Example
--------
-
-.. code-block:: c++
-
-  // Explicitly initializing the member s and v is unnecessary.
-  class Foo {
-  public:
-    Foo() : s() {}
-
-  private:
-    std::string s;
-    std::vector<int> v {};
-  };
-
-Options
--------
-
-.. option:: IgnoreMacros
-
-    When `true`, the check will ignore member initializations where the
-    initializer involves a macro expansion. Default is `false`.
-
-.. option:: IgnoreBaseInCopyConstructors
-
-    Default is `false`.
-
-    When `true`, the check will ignore unnecessary base class initializations
-    within copy constructors, since some compilers issue warnings/errors when
-    base classes are not explicitly initialized in copy constructors. For example,
-    ``gcc`` with ``-Wextra`` or ``-Werror=extra`` issues warning or error
-    ``base class 'Bar' should be explicitly initialized in the copy constructor``
-    if ``Bar()`` were removed in the following example:
-
-.. code-block:: c++
-
-  // Explicitly initializing member s and base class Bar is unnecessary.
-  struct Foo : public Bar {
-    // Remove s() below. If IgnoreBaseInCopyConstructors!=0, keep Bar().
-    Foo(const Foo& foo) : Bar(), s() {}
-    std::string s;
-  };
-
+## Example
+
+```c++
+// Explicitly initializing the member s and v is unnecessary.
+class Foo {
+public:
+  Foo() : s() {}
+
+private:
+  std::string s;
+  std::vector<int> v {};
+};
+```
+
+## Options
+
+```{option} IgnoreMacros
+When `true`, the check will ignore member initializations where the
+initializer involves a macro expansion. Default is `false`.
+```
+
+```{option} IgnoreBaseInCopyConstructors
+When `true`, the check will ignore unnecessary base class initializations
+within copy constructors, since some compilers issue warnings/errors when
+base classes are not explicitly initialized in copy constructors.
+Default is `false`.
+
+For example,
+`gcc` with `-Wextra` or `-Werror=extra` issues warning or error
+`base class 'Bar' should be explicitly initialized in the copy constructor`
+if `Bar()` were removed in the following example:
+```
+
+```c++
+// Explicitly initializing member s and base class Bar is unnecessary.
+struct Foo : public Bar {
+  // Remove s() below. If IgnoreBaseInCopyConstructors!=0, keep Bar().
+  Foo(const Foo& foo) : Bar(), s() {}
+  std::string s;
+};
+```
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-nested-if.md b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-nested-if.md
index d307f4f963988..92d9bc1a63ac6 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-nested-if.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-nested-if.md
@@ -1,59 +1,58 @@
-.. title:: clang-tidy - readability-redundant-nested-if
+```{title} clang-tidy - readability-redundant-nested-if
+```
 
-readability-redundant-nested-if
-===============================
+# readability-redundant-nested-if
 
-Finds nested ``if`` statements that can be merged by combining their
-conditions with ``&&``.
+Finds nested `if` statements that can be merged by combining their
+conditions with `&&`.
 
 Example:
 
-.. code-block:: c++
-
-  if (a) {
-    if (b) {
-      work();
-    }
+```c++
+if (a) {
+  if (b) {
+    work();
   }
+}
+```
 
 becomes
 
-.. code-block:: c++
-
-  if ((a) && (b)) {
-    work();
-  }
+```c++
+if ((a) && (b)) {
+  work();
+}
+```
 
 The check also supports outer declaration conditions in C++17 and later:
 
-.. code-block:: c++
-
-  if (bool X = ready()) {
-    if (can_run()) {
-      work();
-    }
+```c++
+if (bool X = ready()) {
+  if (can_run()) {
+    work();
   }
+}
+```
 
 becomes
 
-.. code-block:: c++
+```c++
+if (bool X = ready(); X && (can_run())) {
+  work();
+}
+```
 
-  if (bool X = ready(); X && (can_run())) {
-    work();
-  }
-
-For ``if constexpr``, dependent nested conditions are merged only when they can
+For `if constexpr`, dependent nested conditions are merged only when they can
 be formed outside the discarded branch. This includes conditions such as
-non-type template parameters and ``requires`` expressions, but excludes
-conditions such as ``sizeof(typename T::type)`` after an earlier dependent
+non-type template parameters and `requires` expressions, but excludes
+conditions such as `sizeof(typename T::type)` after an earlier dependent
 condition.
 
-Options
--------
-
-.. option:: AllowUserDefinedBoolConversion
+## Options
 
-   When set to `true`, the check also diagnoses chains whose merged conditions
-   require user-defined conversion to ``bool``. Fix-its insert
-   ``static_cast<bool>(...)`` where needed so the merged condition still uses
-   built-in ``&&`` semantics. Default is `false`.
+```{option} AllowUserDefinedBoolConversion
+When `true`, the check also diagnoses chains whose merged conditions
+require user-defined conversion to `bool`. Fix-its insert
+`static_cast<bool>(...)` where needed so the merged condition still uses
+built-in `&&` semantics. Default is `false`.
+```
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-parentheses.md b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-parentheses.md
index b9c50c5b59889..e187d1bfbc6b3 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-parentheses.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-parentheses.md
@@ -1,7 +1,7 @@
-.. title:: clang-tidy - readability-redundant-parentheses
+```{title} clang-tidy - readability-redundant-parentheses
+```
 
-readability-redundant-parentheses
-=================================
+# readability-redundant-parentheses
 
 Detect redundant parentheses.
 
@@ -9,34 +9,33 @@ When modifying code, one often forgets to remove the corresponding parentheses.
 This results in overly lengthy code. When the expression is complex, finding
 the matching parentheses becomes particularly difficult.
 
-Example
--------
+## Example
 
-.. code-block:: c++
-
-  (1);
-  ((a + 2)) * 3;
-  (a);
-  ("aaa");
+```c++
+(1);
+((a + 2)) * 3;
+(a);
+("aaa");
+```
 
 Currently this check does not take into account the precedence of operations.
 Even if the expression within the parentheses has a higher priority than that
 outside the parentheses. In other words, removing the parentheses will not
 affect the semantics.
 
-.. code-block:: c++
-
-  int a = (1 * 2) + 3; // no warning
-
-Options
--------
+```c++
+int a = (1 * 2) + 3; // no warning
+```
 
-.. option:: AllowedDecls
+## Options
 
-  Semicolon-separated list of regular expressions matching names of declarations
-  to ignore when the parentheses are around. Declarations can include variables
-  or functions. The default is an `std::max;std::min`.
+```{option} AllowedDecls
+Semicolon-separated list of regular expressions matching names of declarations
+to ignore when the parentheses are around. Declarations can include variables
+or functions.
 
-  Some STL library functions may have the same name as widely used function-like
-  macro. For example, ``std::max`` and ``max`` macro. A workaround to distinguish
-  them is adding parentheses around functions to prevent function-like macro.
+Some STL library functions may have the same name as widely used function-like
+macro. For example, `std::max` and `max` macro. A workaround to distinguish
+them is adding parentheses around functions to prevent function-like macro.
+Default is `std::max;std::min`.
+```
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-preprocessor.md b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-preprocessor.md
index f013a3417d3b7..3da66b2fd6523 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-preprocessor.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-preprocessor.md
@@ -1,61 +1,60 @@
-.. title:: clang-tidy - readability-redundant-preprocessor
+```{title} clang-tidy - readability-redundant-preprocessor
+```
 
-readability-redundant-preprocessor
-==================================
+# readability-redundant-preprocessor
 
 Finds potentially redundant preprocessor directives. At the moment the
 following cases are detected:
 
-* `#ifdef` .. `#endif` pairs which are nested inside an outer pair with the
+- `#ifdef` .. `#endif` pairs which are nested inside an outer pair with the
   same condition. For example:
 
-.. code-block:: c++
-
-  #ifdef FOO
-  #ifdef FOO // inner ifdef is considered redundant
-  void f();
-  #endif
-  #endif
-
-* Same for `#ifndef` .. `#endif` pairs. For example:
-
-.. code-block:: c++
-
-  #ifndef FOO
-  #ifndef FOO // inner ifndef is considered redundant
-  void f();
-  #endif
-  #endif
-
-* `#ifndef` inside an `#ifdef` with the same condition:
-
-.. code-block:: c++
-
-  #ifdef FOO
-  #ifndef FOO // inner ifndef is considered redundant
-  void f();
-  #endif
-  #endif
-
-* `#ifdef` inside an `#ifndef` with the same condition:
-
-.. code-block:: c++
-
-  #ifndef FOO
-  #ifdef FOO // inner ifdef is considered redundant
-  void f();
-  #endif
-  #endif
-
-* `#if` .. `#endif` pairs which are nested inside an outer pair with the same
+```c++
+#ifdef FOO
+#ifdef FOO // inner ifdef is considered redundant
+void f();
+#endif
+#endif
+```
+
+- Same for `#ifndef` .. `#endif` pairs. For example:
+
+```c++
+#ifndef FOO
+#ifndef FOO // inner ifndef is considered redundant
+void f();
+#endif
+#endif
+```
+
+- `#ifndef` inside an `#ifdef` with the same condition:
+
+```c++
+#ifdef FOO
+#ifndef FOO // inner ifndef is considered redundant
+void f();
+#endif
+#endif
+```
+
+- `#ifdef` inside an `#ifndef` with the same condition:
+
+```c++
+#ifndef FOO
+#ifdef FOO // inner ifdef is considered redundant
+void f();
+#endif
+#endif
+```
+
+- `#if` .. `#endif` pairs which are nested inside an outer pair with the same
   condition. For example:
 
-.. code-block:: c++
-
-  #define FOO 4
-  #if FOO == 4
-  #if FOO == 4 // inner if is considered redundant
-  void f();
-  #endif
-  #endif
-
+```c++
+#define FOO 4
+#if FOO == 4
+#if FOO == 4 // inner if is considered redundant
+void f();
+#endif
+#endif
+```
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-qualified-alias.md b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-qualified-alias.md
index b1af171ae5093..95dfe58bb1062 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-qualified-alias.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-qualified-alias.md
@@ -1,30 +1,29 @@
-.. title:: clang-tidy - readability-redundant-qualified-alias
+```{title} clang-tidy - readability-redundant-qualified-alias
+```
 
-readability-redundant-qualified-alias
-=====================================
+# readability-redundant-qualified-alias
 
 Finds redundant identity type aliases that re-expose a qualified name and can
-be replaced with a ``using`` declaration.
+be replaced with a `using` declaration.
 
-.. code-block:: c++
+```c++
+using seconds = std::chrono::seconds;
 
-  using seconds = std::chrono::seconds;
+// becomes
 
-  // becomes
-
-  using std::chrono::seconds;
+using std::chrono::seconds;
+```
 
 The check is conservative and only warns when the alias name exactly matches
 the unqualified name of a non-dependent, non-specialized named type written
 with a qualifier. It skips alias templates, dependent forms, elaborated
-keywords (``class``, ``struct``, ``enum``, ``typename``), and cases involving
+keywords (`class`, `struct`, `enum`, `typename`), and cases involving
 macros.
 
-Options
--------
-
-.. option:: OnlyNamespaceScope
+## Options
 
-   When `true`, only consider aliases declared in a namespace or the
-   translation unit. When `false`, also consider aliases declared inside
-   classes, functions, and lambdas. Default is `false`.
+```{option} OnlyNamespaceScope
+When `true`, only consider aliases declared in a namespace or the
+translation unit. When `false`, also consider aliases declared inside
+classes, functions, and lambdas. Default is `false`.
+```
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-string-init.md b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-string-init.md
index dc3dfacb15d51..3e7362b4b4ee1 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-string-init.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-string-init.md
@@ -1,41 +1,38 @@
-.. title:: clang-tidy - readability-redundant-string-init
+```{title} clang-tidy - readability-redundant-string-init
+```
 
-readability-redundant-string-init
-=================================
+# readability-redundant-string-init
 
 Finds unnecessary string initializations.
 
-Examples
---------
+## Examples
 
-.. code-block:: c++
+```c++
+// Initializing string with empty string literal is unnecessary.
+std::string a = "";
+std::string b("");
 
-  // Initializing string with empty string literal is unnecessary.
-  std::string a = "";
-  std::string b("");
+// becomes
 
-  // becomes
+std::string a;
+std::string b;
 
-  std::string a;
-  std::string b;
+// Initializing a string_view with an empty string literal produces an
+// instance that compares equal to string_view().
+std::string_view a = "";
+std::string_view b("");
 
-  // Initializing a string_view with an empty string literal produces an
-  // instance that compares equal to string_view().
-  std::string_view a = "";
-  std::string_view b("");
+// becomes
+std::string_view a;
+std::string_view b;
+```
 
-  // becomes
-  std::string_view a;
-  std::string_view b;
+## Options
 
-Options
--------
-
-.. option:: StringNames
-
-    Default is `::std::basic_string;::std::basic_string_view`.
-
-    Semicolon-delimited list of class names to apply this check to.
-    By default `::std::basic_string` applies to ``std::string`` and
-    ``std::wstring``. Set to e.g. `::std::basic_string;llvm::StringRef;QString`
-    to perform this check on custom classes.
+```{option} StringNames
+Semicolon-delimited list of class names to apply this check to.
+By default `::std::basic_string` applies to `std::string` and
+`std::wstring`. Set to e.g. `::std::basic_string;llvm::StringRef;QString`
+to perform this check on custom classes.
+Default is `::std::basic_string;::std::basic_string_view`.
+```
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-typename.md b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-typename.md
index 3f3e5de94d594..bc3800b4805fd 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-typename.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-typename.md
@@ -1,31 +1,31 @@
-.. title:: clang-tidy - readability-redundant-typename
+```{title} clang-tidy - readability-redundant-typename
+```
 
-readability-redundant-typename
-==============================
+# readability-redundant-typename
 
-Finds redundant uses of the ``typename`` keyword.
+Finds redundant uses of the `typename` keyword.
 
-``typename`` is redundant in two cases. First, before non-dependent names:
+`typename` is redundant in two cases. First, before non-dependent names:
 
-.. code-block:: c++
-
-  /*typename*/ std::vector<int>::size_type size;
+```c++
+/*typename*/ std::vector<int>::size_type size;
+```
 
 And second, since C++20, before dependent names that appear in a context
 where only a type is allowed (the following example shows just a few of them):
 
-.. code-block:: c++
-
-  template <typename T>
-  using trait = /*typename*/ T::type;
-
-  template <typename T>
-  /*typename*/ T::underlying_type as_underlying(T n) {
-    return static_cast</*typename*/ T::underlying_type>(n);
-  }
-
-  template <typename T>
-  struct S {
-    /*typename*/ T::type variable;
-    /*typename*/ T::type function(/*typename*/ T::type);
-  };
+```c++
+template <typename T>
+using trait = /*typename*/ T::type;
+
+template <typename T>
+/*typename*/ T::underlying_type as_underlying(T n) {
+  return static_cast</*typename*/ T::underlying_type>(n);
+}
+
+template <typename T>
+struct S {
+  /*typename*/ T::type variable;
+  /*typename*/ T::type function(/*typename*/ T::type);
+};
+```
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/reference-to-constructed-temporary.md b/clang-tools-extra/docs/clang-tidy/checks/readability/reference-to-constructed-temporary.md
index 5f1aea1a7ba5c..85a55c2988430 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/reference-to-constructed-temporary.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/reference-to-constructed-temporary.md
@@ -1,7 +1,7 @@
-.. title:: clang-tidy - readability-reference-to-constructed-temporary
+```{title} clang-tidy - readability-reference-to-constructed-temporary
+```
 
-readability-reference-to-constructed-temporary
-==============================================
+# readability-reference-to-constructed-temporary
 
 Detects C++ code where a reference variable is used to extend the lifetime of
 a temporary object that has just been constructed.
@@ -13,20 +13,20 @@ extending the lifetime of a temporary object.
 
 Examples of problematic code include:
 
-.. code-block:: c++
+```c++
+const std::string& str("hello");
 
-   const std::string& str("hello");
+struct Point { int x; int y; };
+const Point& p = { 1, 2 };
+```
 
-   struct Point { int x; int y; };
-   const Point& p = { 1, 2 };
-
-In the first example, a ``const std::string&`` reference variable ``str`` is
-assigned a temporary object created by the ``std::string("hello")``
-constructor. In the second example, a ``const Point&`` reference variable ``p``
+In the first example, a `const std::string&` reference variable `str` is
+assigned a temporary object created by the `std::string("hello")`
+constructor. In the second example, a `const Point&` reference variable `p`
 is assigned an object that is constructed from an initializer list
-``{ 1, 2 }``. Both of these examples extend the lifetime of the temporary
+`{ 1, 2 }`. Both of these examples extend the lifetime of the temporary
 object to the lifetime of the reference variable, which can make it difficult
 to reason about and may lead to subtle bugs or misunderstanding.
 
 To avoid these issues, it is recommended to change the reference variable to a
-(``const``) value variable.
+(`const`) value variable.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/simplify-boolean-expr.md b/clang-tools-extra/docs/clang-tidy/checks/readability/simplify-boolean-expr.md
index 5b733e5eaf4d7..6e6ed16ccba60 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/simplify-boolean-expr.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/simplify-boolean-expr.md
@@ -1,125 +1,119 @@
-.. title:: clang-tidy - readability-simplify-boolean-expr
+```{title} clang-tidy - readability-simplify-boolean-expr
+```
 
-readability-simplify-boolean-expr
-=================================
+# readability-simplify-boolean-expr
 
 Looks for boolean expressions involving boolean constants and simplifies
-them to use the appropriate boolean expression directly.  Simplifies
+them to use the appropriate boolean expression directly. Simplifies
 boolean expressions by application of DeMorgan's Theorem.
 
 Examples:
 
-===========================================  ================
-Initial expression                           Result
--------------------------------------------  ----------------
-``if (b == true)``                             ``if (b)``
-``if (b == false)``                            ``if (!b)``
-``if (b && true)``                             ``if (b)``
-``if (b && false)``                            ``if (false)``
-``if (b || true)``                             ``if (true)``
-``if (b || false)``                            ``if (b)``
-``e ? true : false``                           ``e``
-``e ? false : true``                           ``!e``
-``if (true) t(); else f();``                   ``t();``
-``if (false) t(); else f();``                  ``f();``
-``if (e) return true; else return false;``     ``return e;``
-``if (e) return false; else return true;``     ``return !e;``
-``if (e) b = true; else b = false;``           ``b = e;``
-``if (e) b = false; else b = true;``           ``b = !e;``
-``if (e) return true; return false;``          ``return e;``
-``if (e) return false; return true;``          ``return !e;``
-``!(!a || b)``                                 ``a && !b``
-``!(a || !b)``                                 ``!a && b``
-``!(!a || !b)``                                ``a && b``
-``!(!a && b)``                                 ``a || !b``
-``!(a && !b)``                                 ``!a || b``
-``!(!a && !b)``                                ``a || b``
-===========================================  ================
-
-The resulting expression ``e`` is modified as follows:
-  1. Unnecessary parentheses around the expression are removed.
-  2. Negated applications of ``!`` are eliminated.
-  3. Negated applications of comparison operators are changed to use the
-     opposite condition.
-  4. Implicit conversions of pointers, including pointers to members, to
-     ``bool`` are replaced with explicit comparisons to ``nullptr`` in C++11
-     or ``NULL`` in C++98/03.
-  5. Implicit casts to ``bool`` are replaced with explicit casts to ``bool``.
-  6. Object expressions with ``explicit operator bool`` conversion operators
-     are replaced with explicit casts to ``bool``.
-  7. Implicit conversions of integral types to ``bool`` are replaced with
-     explicit comparisons to ``0``.
+| Initial expression                         | Result        |
+| ------------------------------------------ | ------------- |
+| `if (b == true)`                           | `if (b)`      |
+| `if (b == false)`                          | `if (!b)`     |
+| `if (b && true)`                           | `if (b)`      |
+| `if (b && false)`                          | `if (false)`  |
+| `if (b \|\| true)`                         | `if (true)`   |
+| `if (b \|\| false)`                        | `if (b)`      |
+| `e ? true : false`                         | `e`           |
+| `e ? false : true`                         | `!e`          |
+| `if (true) t(); else f();`                 | `t();`        |
+| `if (false) t(); else f();`                | `f();`        |
+| `if (e) return true; else return false;`   | `return e;`   |
+| `if (e) return false; else return true;`   | `return !e;`  |
+| `if (e) b = true; else b = false;`         | `b = e;`      |
+| `if (e) b = false; else b = true;`         | `b = !e;`     |
+| `if (e) return true; return false;`        | `return e;`   |
+| `if (e) return false; return true;`        | `return !e;`  |
+| `!(!a \|\| b)`                             | `a && !b`     |
+| `!(a \|\| !b)`                             | `!a && b`     |
+| `!(!a \|\| !b)`                            | `a && b`      |
+| `!(!a && b)`                               | `a \|\| !b`  |
+| `!(a && !b)`                               | `!a \|\| b`  |
+| `!(!a && !b)`                              | `a \|\| b`   |
+
+The resulting expression `e` is modified as follows:
+
+1. Unnecessary parentheses around the expression are removed.
+2. Negated applications of `!` are eliminated.
+3. Negated applications of comparison operators are changed to use the
+   opposite condition.
+4. Implicit conversions of pointers, including pointers to members, to
+   `bool` are replaced with explicit comparisons to `nullptr` in C++11
+   or `NULL` in C++98/03.
+5. Implicit casts to `bool` are replaced with explicit casts to `bool`.
+6. Object expressions with `explicit operator bool` conversion operators
+   are replaced with explicit casts to `bool`.
+7. Implicit conversions of integral types to `bool` are replaced with
+   explicit comparisons to `0`.
 
 Examples:
-  1. The ternary assignment ``bool b = (i < 0) ? true : false;`` has redundant
-     parentheses and becomes ``bool b = i < 0;``.
 
-  2. The conditional return ``if (!b) return false; return true;`` has an
-     implied double negation and becomes ``return b;``.
-
-  3. The conditional return ``if (i < 0) return false; return true;`` becomes
-     ``return i >= 0;``.
-
-     The conditional return ``if (i != 0) return false; return true;`` becomes
-     ``return i == 0;``.
-
-  4. The conditional return ``if (p) return true; return false;`` has an
-     implicit conversion of a pointer to ``bool`` and becomes
-     ``return p != nullptr;``.
-
-     The ternary assignment ``bool b = (i & 1) ? true : false;`` has an
-     implicit conversion of ``i & 1`` to ``bool`` and becomes
-     ``bool b = (i & 1) != 0;``.
-
-  5. The conditional return ``if (i & 1) return true; else return false;`` has
-     an implicit conversion of an integer quantity ``i & 1`` to ``bool`` and
-     becomes ``return (i & 1) != 0;``
-
-  6. Given ``struct X { explicit operator bool(); };``, and an instance ``x``
-     of ``struct X``, the conditional return
-     ``if (x) return true; return false;``
-     becomes ``return static_cast<bool>(x);``
-
-Options
--------
-
-.. option:: IgnoreMacros
-
-   If `true`, ignore boolean expressions originating from expanded macros.
-   Default is `false`.
-
-.. option:: ChainedConditionalReturn
-
-   If `true`, conditional boolean return statements at the end of an
-   ``if/else if`` chain will be transformed. Default is `false`.
-
-.. option:: ChainedConditionalAssignment
-
-   If `true`, conditional boolean assignments at the end of an ``if/else
-   if`` chain will be transformed. Default is `false`.
-
-.. option:: SimplifyDeMorgan
-
-   If `true`, DeMorgan's Theorem will be applied to simplify negated
-   conjunctions and disjunctions.  Default is `true`.
-
-.. option:: SimplifyDeMorganRelaxed
-
-   If `true`, :option:`SimplifyDeMorgan` will also transform negated
-   conjunctions and disjunctions where there is no negation on either operand.
-   This option has no effect if :option:`SimplifyDeMorgan` is `false`.
-   Default is `false`.
-
-   When Enabled:
-
-   .. code-block::
-
-      bool X = !(A && B)
-      bool Y = !(A || B)
-
-   Would be transformed to:
-
-   .. code-block::
-
-      bool X = !A || !B
-      bool Y = !A && !B
+1. The ternary assignment `bool b = (i < 0) ? true : false;` has redundant
+   parentheses and becomes `bool b = i < 0;`.
+2. The conditional return `if (!b) return false; return true;` has an
+   implied double negation and becomes `return b;`.
+3. The conditional return `if (i < 0) return false; return true;` becomes
+   `return i >= 0;`.
+
+   The conditional return `if (i != 0) return false; return true;` becomes
+   `return i == 0;`.
+4. The conditional return `if (p) return true; return false;` has an
+   implicit conversion of a pointer to `bool` and becomes
+   `return p != nullptr;`.
+
+   The ternary assignment `bool b = (i & 1) ? true : false;` has an
+   implicit conversion of `i & 1` to `bool` and becomes
+   `bool b = (i & 1) != 0;`.
+5. The conditional return `if (i & 1) return true; else return false;` has
+   an implicit conversion of an integer quantity `i & 1` to `bool` and
+   becomes `return (i & 1) != 0;`
+6. Given `struct X { explicit operator bool(); };`, and an instance `x`
+   of `struct X`, the conditional return
+   `if (x) return true; return false;`
+   becomes `return static_cast<bool>(x);`
+
+## Options
+
+```{option} IgnoreMacros
+If `true`, ignore boolean expressions originating from expanded macros.
+Default is `false`.
+```
+
+```{option} ChainedConditionalReturn
+If `true`, conditional boolean return statements at the end of an
+`if/else if` chain will be transformed. Default is `false`.
+```
+
+```{option} ChainedConditionalAssignment
+If `true`, conditional boolean assignments at the end of an `if/else
+if` chain will be transformed. Default is `false`.
+```
+
+```{option} SimplifyDeMorgan
+If `true`, DeMorgan's Theorem will be applied to simplify negated
+conjunctions and disjunctions. Default is `true`.
+```
+
+````{option} SimplifyDeMorganRelaxed
+If `true`, {option}`SimplifyDeMorgan` will also transform negated
+conjunctions and disjunctions where there is no negation on either operand.
+This option has no effect if {option}`SimplifyDeMorgan` is `false`.
+Default is `false`.
+
+When enabled:
+
+```
+bool X = !(A && B)
+bool Y = !(A || B)
+```
+
+Would be transformed to:
+
+```
+bool X = !A || !B
+bool Y = !A && !B
+```
+````



More information about the llvm-branch-commits mailing list