[llvm-branch-commits] [clang-tools-extra] [clang-tidy][docs] Rewrite readability check docs to Markdown [4/5] (PR #221641)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sun Sep 6 22:51:56 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tidy
Author: Zeyi Xu (zeyi2)
<details>
<summary>Changes</summary>
<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>
---
Patch is 30.78 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/221641.diff
10 Files Affected:
- (modified) clang-tools-extra/docs/clang-tidy/checks/readability/redundant-lambda-parameter-list.md (+28-28)
- (modified) clang-tools-extra/docs/clang-tidy/checks/readability/redundant-member-init.md (+44-46)
- (modified) clang-tools-extra/docs/clang-tidy/checks/readability/redundant-nested-if.md (+37-38)
- (modified) clang-tools-extra/docs/clang-tidy/checks/readability/redundant-parentheses.md (+23-24)
- (modified) clang-tools-extra/docs/clang-tidy/checks/readability/redundant-preprocessor.md (+51-52)
- (modified) clang-tools-extra/docs/clang-tidy/checks/readability/redundant-qualified-alias.md (+16-17)
- (modified) clang-tools-extra/docs/clang-tidy/checks/readability/redundant-string-init.md (+27-30)
- (modified) clang-tools-extra/docs/clang-tidy/checks/readability/redundant-typename.md (+23-23)
- (modified) clang-tools-extra/docs/clang-tidy/checks/readability/reference-to-constructed-temporary.md (+13-13)
- (modified) clang-tools-extra/docs/clang-tidy/checks/readability/simplify-boolean-expr.md (+109-115)
``````````diff
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::...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/221641
More information about the llvm-branch-commits
mailing list