[llvm-branch-commits] [clang-tools-extra] [clang-tidy][docs] Rewrite modernize check docs to Markdown [1/4] (PR #232207)
Zeyi Xu via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Oct 15 00:19:36 PDT 2026
https://github.com/zeyi2 created https://github.com/llvm/llvm-project/pull/232207
Tracking issue: #201242
See the [migration guide] for more information.
[migration guide]:
https://llvm.org/docs/SphinxQuickstartTemplate.html#markdown-migration-guidelines
This is the first part of rewriting check documentations in modernize module from reST to MyST Markdown.
AI Usage: This was prepared with rnk's fork of rst2myst and GPT5.6-assisted (both Codex and AmpCode) cleanup.
I manually verified that the documentation renders as expected.
Preview site:
https://broken.life/llvm-staging/modernize-markdown-port/index.html
>From 3e6086cfd72950491c10a6425152d7e644270858 Mon Sep 17 00:00:00 2001
From: Zeyi Xu <mitchell.xu2 at gmail.com>
Date: Thu, 15 Oct 2026 15:19:18 +0800
Subject: [PATCH] [clang-tidy][docs] Rewrite modernize check docs to Markdown
[1/4]
---
.../clang-tidy/checks/modernize/avoid-bind.md | 119 +++---
.../checks/modernize/avoid-c-arrays.md | 93 ++--
.../checks/modernize/avoid-c-style-cast.md | 37 +-
.../modernize/concat-nested-namespaces.md | 103 +++--
.../checks/modernize/deprecated-headers.md | 115 ++---
.../checks/modernize/loop-convert.md | 397 +++++++++---------
.../checks/modernize/macro-to-enum.md | 97 +++--
.../checks/modernize/make-shared.md | 79 ++--
.../checks/modernize/make-unique.md | 79 ++--
.../modernize/min-max-use-initializer-list.md | 53 +--
10 files changed, 590 insertions(+), 582 deletions(-)
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-bind.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-bind.md
index 90e5b613560ab3..3067f354d768ef 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-bind.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-bind.md
@@ -1,89 +1,90 @@
-.. title:: clang-tidy - modernize-avoid-bind
+```{title} clang-tidy - modernize-avoid-bind
+```
-modernize-avoid-bind
-====================
+# modernize-avoid-bind
-The check finds uses of ``std::bind`` and ``boost::bind`` and replaces them
+The check finds uses of `std::bind` and `boost::bind` and replaces them
with lambdas. Lambdas will use value-capture unless reference capture is
-explicitly requested with ``std::ref`` or ``boost::ref``.
+explicitly requested with `std::ref` or `boost::ref`.
It supports arbitrary callables including member functions, function objects,
and free functions, and all variations thereof. Anything that you can pass
-to the first argument of ``bind`` should be diagnosable. Currently, the only
+to the first argument of `bind` should be diagnosable. Currently, the only
known case where a fix-it is unsupported is when the same placeholder is
specified multiple times in the parameter list.
Given:
-.. code-block:: c++
-
- int add(int x, int y) { return x + y; }
+```c++
+int add(int x, int y) { return x + y; }
+```
Then:
-.. code-block:: c++
-
- void f() {
- int x = 2;
- auto clj = std::bind(add, x, _1);
- }
+```c++
+void f() {
+ int x = 2;
+ auto clj = std::bind(add, x, _1);
+}
+```
is replaced by:
-.. code-block:: c++
+```c++
+void f() {
+ int x = 2;
+ auto clj = [=](auto && arg1) { return add(x, arg1); };
+}
+```
- void f() {
- int x = 2;
- auto clj = [=](auto && arg1) { return add(x, arg1); };
- }
-
-``std::bind`` can be hard to read and can result in larger object files and
+`std::bind` can be hard to read and can result in larger object files and
binaries due to type information that will not be produced by equivalent
lambdas.
-Options
--------
-
-.. option:: PermissiveParameterList
-
- If the option is set to `true`, the check will append ``auto&&...`` to the end
- of every placeholder parameter list. Without this, it is possible for a fix-it
- to perform an incorrect transformation in the case where the result of the ``bind``
- is used in the context of a type erased functor such as ``std::function`` which
- allows mismatched arguments. Default is `false`.
-
-For example:
-
-.. code-block:: c++
+This check requires using C++14 or higher to run.
- int add(int x, int y) { return x + y; }
- int foo() {
- std::function<int(int,int)> ignore_args = std::bind(add, 2, 2);
- return ignore_args(3, 3);
- }
+## Options
-is valid code, and returns `4`. The actual values passed to ``ignore_args`` are
-simply ignored. Without ``PermissiveParameterList``, this would be transformed into
+(modernize-avoid-bind-permissive-parameter-list)=
-.. code-block:: c++
+````{option} PermissiveParameterList
+If the option is set to `true`, the check will append `auto&&...` to the end
+of every placeholder parameter list. Without this, it is possible for a fix-it
+to perform an incorrect transformation in the case where the result of the `bind`
+is used in the context of a type erased functor such as `std::function` which
+allows mismatched arguments. Default is `false`.
- int add(int x, int y) { return x + y; }
- int foo() {
- std::function<int(int,int)> ignore_args = [] { return add(2, 2); }
- return ignore_args(3, 3);
- }
+For example:
-which will *not* compile, since the lambda does not contain an ``operator()``
+```c++
+int add(int x, int y) { return x + y; }
+int foo() {
+ std::function<int(int,int)> ignore_args = std::bind(add, 2, 2);
+ return ignore_args(3, 3);
+}
+```
+
+is valid code, and returns `4`. The actual values passed to `ignore_args` are
+simply ignored. Without [`PermissiveParameterList`](#modernize-avoid-bind-permissive-parameter-list), this would be transformed into
+
+```c++
+int add(int x, int y) { return x + y; }
+int foo() {
+ std::function<int(int,int)> ignore_args = [] { return add(2, 2); }
+ return ignore_args(3, 3);
+}
+```
+
+which will *not* compile, since the lambda does not contain an `operator()`
that accepts 2 arguments. With permissive parameter list, it instead generates
-.. code-block:: c++
-
- int add(int x, int y) { return x + y; }
- int foo() {
- std::function<int(int,int)> ignore_args = [](auto&&...) { return add(2, 2); }
- return ignore_args(3, 3);
- }
+```c++
+int add(int x, int y) { return x + y; }
+int foo() {
+ std::function<int(int,int)> ignore_args = [](auto&&...) { return add(2, 2); }
+ return ignore_args(3, 3);
+}
+```
which is correct.
-
-This check requires using C++14 or higher to run.
+````
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-arrays.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-arrays.md
index fec282740dd53f..7d832eef94c610 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-arrays.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-arrays.md
@@ -1,75 +1,76 @@
-.. title:: clang-tidy - modernize-avoid-c-arrays
+```{title} clang-tidy - modernize-avoid-c-arrays
+```
-modernize-avoid-c-arrays
-========================
+# modernize-avoid-c-arrays
`cppcoreguidelines-avoid-c-arrays` redirects here as an alias for this check.
-Finds C-style array types and recommend to use ``std::array<>`` /
-``std::vector<>``. All types of C arrays are diagnosed.
+Finds C-style array types and recommend to use `std::array<>` /
+`std::vector<>`. All types of C arrays are diagnosed.
For parameters of incomplete C-style array type, it would be better to
-use ``std::span`` / ``gsl::span`` as replacement.
+use `std::span` / `gsl::span` as replacement.
However, fix-it are potentially dangerous in header files and are therefore not
emitted right now.
-.. code:: c++
+```c++
+int a[] = {1, 2}; // warning: do not declare C-style arrays, use 'std::array' instead
- int a[] = {1, 2}; // warning: do not declare C-style arrays, use 'std::array' instead
+int b[1]; // warning: do not declare C-style arrays, use 'std::array' instead
- int b[1]; // warning: do not declare C-style arrays, use 'std::array' instead
+void foo() {
+ int c[b[0]]; // warning: do not declare C VLA arrays, use 'std::vector' instead
+}
- void foo() {
- int c[b[0]]; // warning: do not declare C VLA arrays, use 'std::vector' instead
- }
-
- template <typename T, int Size>
- class array {
- T d[Size]; // warning: do not declare C-style arrays, use 'std::array' instead
-
- int e[1]; // warning: do not declare C-style arrays, use 'std::array' instead
- };
+template <typename T, int Size>
+class array {
+ T d[Size]; // warning: do not declare C-style arrays, use 'std::array' instead
- array<int[4], 2> d; // warning: do not declare C-style arrays, use 'std::array' instead
+ int e[1]; // warning: do not declare C-style arrays, use 'std::array' instead
+};
- using k = int[4]; // warning: do not declare C-style arrays, use 'std::array' instead
+array<int[4], 2> d; // warning: do not declare C-style arrays, use 'std::array' instead
+using k = int[4]; // warning: do not declare C-style arrays, use 'std::array' instead
+```
-However, the ``extern "C"`` code is ignored, since it is common to share
+However, the `extern "C"` code is ignored, since it is common to share
such headers between C code, and C++ code.
-.. code:: c++
+```c++
+// Some header
+extern "C" {
- // Some header
- extern "C" {
+int f[] = {1, 2}; // not diagnosed
- int f[] = {1, 2}; // not diagnosed
-
- int j[1]; // not diagnosed
-
- inline void bar() {
- {
- int j[j[0]]; // not diagnosed
- }
- }
+int j[1]; // not diagnosed
+inline void bar() {
+ {
+ int j[j[0]]; // not diagnosed
}
+}
-Similarly, the ``main()`` function is ignored. Its second and third parameters
-can be either ``char* argv[]`` or ``char** argv``, but cannot be
-``std::array<>``.
+}
+```
-Options
--------
+Similarly, the `main()` function is ignored. Its second and third parameters
+can be either `char* argv[]` or `char** argv`, but cannot be
+`std::array<>`.
-.. option:: AllowStringArrays
+## Options
- When set to `true` (default is `false`), variables of character array type
- with deduced length, initialized directly from string literals, will be ignored.
- This option doesn't affect cases where length can't be deduced, resembling
- pointers, as seen in class members and parameters. Example:
+(modernize-avoid-c-arrays-allow-string-arrays)=
- .. code:: c++
+````{option} AllowStringArrays
+When set to `true`, variables of character array type
+with deduced length, initialized directly from string literals, will be ignored.
+This option doesn't affect cases where length can't be deduced, resembling
+pointers, as seen in class members and parameters. Example:
- const char name[] = "Some name";
+```c++
+const char name[] = "Some name";
+```
+Default is `false`.
+````
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-style-cast.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-style-cast.md
index c43fb00d02d091..8026e7239ebfd3 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-style-cast.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-style-cast.md
@@ -1,12 +1,12 @@
-.. title:: clang-tidy - modernize-avoid-c-style-cast
+```{title} clang-tidy - modernize-avoid-c-style-cast
+```
-modernize-avoid-c-style-cast
-============================
+# modernize-avoid-c-style-cast
Finds usages of C-style casts.
-C-style casts can perform a variety of different conversions (``const_cast``,
-``static_cast``, ``reinterpret_cast``, or a combination). This makes them
+C-style casts can perform a variety of different conversions (`const_cast`,
+`static_cast`, `reinterpret_cast`, or a combination). This makes them
dangerous as the intent is not clear, and they can silently perform unsafe
conversions between incompatible types.
@@ -14,23 +14,20 @@ This check is similar to `-Wold-style-cast`, but it suggests automated fixes
in some cases. The reported locations should not be different from the ones
generated by `-Wold-style-cast`.
-Examples
---------
+## Examples
-.. code-block:: c++
+```c++
+class A {
+ public:
+ std::string v;
+};
- class A {
- public:
- std::string v;
- };
+A a;
+double *num = (double*)(&a); // Compiles! Hides danger
+// num = static_cast<double*>(&a); // Won't compile (good!)
+num = reinterpret_cast<double*>(&a); // Compiles, danger is explicit
+```
- A a;
- double *num = (double*)(&a); // Compiles! Hides danger
- // num = static_cast<double*>(&a); // Won't compile (good!)
- num = reinterpret_cast<double*>(&a); // Compiles, danger is explicit
-
-
-References
-----------
+## References
Corresponding cpplint.py check name: `readability/casting`.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/concat-nested-namespaces.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/concat-nested-namespaces.md
index 6e1f5055b38ecf..5c506db42f00ae 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/concat-nested-namespaces.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/concat-nested-namespaces.md
@@ -1,63 +1,62 @@
-.. title:: clang-tidy - modernize-concat-nested-namespaces
+```{title} clang-tidy - modernize-concat-nested-namespaces
+```
-modernize-concat-nested-namespaces
-==================================
+# modernize-concat-nested-namespaces
Checks for use of nested namespaces such as
-``namespace a { namespace b { ... } }``
+`namespace a { namespace b { ... } }`
and suggests changing to the more concise syntax introduced
-in C++17: ``namespace a::b { ... }``.
+in C++17: `namespace a::b { ... }`.
Inline namespaces are not modified.
For example:
-.. code-block:: c++
-
- namespace n1 {
- namespace n2 {
- void t();
- }
- }
-
- namespace n3 {
- namespace n4 {
- namespace n5 {
- void t();
- }
- }
- namespace n6 {
- namespace n7 {
- void t();
- }
- }
- }
-
- // in c++20
- namespace n8 {
- inline namespace n9 {
- void t();
- }
- }
+```c++
+namespace n1 {
+namespace n2 {
+void t();
+}
+}
+
+namespace n3 {
+namespace n4 {
+namespace n5 {
+void t();
+}
+}
+namespace n6 {
+namespace n7 {
+void t();
+}
+}
+}
+
+// in c++20
+namespace n8 {
+inline namespace n9 {
+void t();
+}
+}
+```
Will be modified to:
-.. code-block:: c++
-
- namespace n1::n2 {
- void t();
- }
-
- namespace n3 {
- namespace n4::n5 {
- void t();
- }
- namespace n6::n7 {
- void t();
- }
- }
-
- // in c++20
- namespace n8::inline n9 {
- void t();
- }
-
+```c++
+namespace n1::n2 {
+void t();
+}
+
+namespace n3 {
+namespace n4::n5 {
+void t();
+}
+namespace n6::n7 {
+void t();
+}
+}
+
+// in c++20
+namespace n8::inline n9 {
+void t();
+}
+```
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.md
index 6c35cd4e53d87a..36ee40c06d1ba5 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.md
@@ -1,7 +1,7 @@
-.. title:: clang-tidy - modernize-deprecated-headers
+```{title} clang-tidy - modernize-deprecated-headers
+```
-modernize-deprecated-headers
-============================
+# modernize-deprecated-headers
Some headers from C library were deprecated in C++ and are no longer welcome in
C++ codebases. Some have no effect in C++. For more details refer to the C++14
@@ -10,44 +10,44 @@ Standard [depr.c.headers] section.
This check replaces C standard library headers with their C++ alternatives and
removes redundant ones.
-.. code-block:: c++
+```c++
+// C++ source file...
+#include <assert.h>
+#include <stdbool.h>
- // C++ source file...
- #include <assert.h>
- #include <stdbool.h>
+// becomes
- // becomes
-
- #include <cassert>
- // No 'stdbool.h' here.
+#include <cassert>
+// No 'stdbool.h' here.
+```
Important note: the Standard doesn't guarantee that the C++ headers declare all
the same functions in the global namespace. The check in its current form can
break the code that uses library symbols from the global namespace.
-* `<assert.h>`
-* `<complex.h>`
-* `<ctype.h>`
-* `<errno.h>`
-* `<fenv.h>` // deprecated since C++11
-* `<float.h>`
-* `<inttypes.h>`
-* `<limits.h>`
-* `<locale.h>`
-* `<math.h>`
-* `<setjmp.h>`
-* `<signal.h>`
-* `<stdarg.h>`
-* `<stddef.h>`
-* `<stdint.h>`
-* `<stdio.h>`
-* `<stdlib.h>`
-* `<string.h>`
-* `<tgmath.h>` // deprecated since C++11
-* `<time.h>`
-* `<uchar.h>` // deprecated since C++11
-* `<wchar.h>`
-* `<wctype.h>`
+- `<assert.h>`
+- `<complex.h>`
+- `<ctype.h>`
+- `<errno.h>`
+- `<fenv.h>` // deprecated since C++11
+- `<float.h>`
+- `<inttypes.h>`
+- `<limits.h>`
+- `<locale.h>`
+- `<math.h>`
+- `<setjmp.h>`
+- `<signal.h>`
+- `<stdarg.h>`
+- `<stddef.h>`
+- `<stdint.h>`
+- `<stdio.h>`
+- `<stdlib.h>`
+- `<string.h>`
+- `<tgmath.h>` // deprecated since C++11
+- `<time.h>`
+- `<uchar.h>` // deprecated since C++11
+- `<wchar.h>`
+- `<wctype.h>`
If the specified standard is older than C++11 the check will only replace
headers deprecated before C++11, otherwise -- every header that appeared in
@@ -55,29 +55,30 @@ the previous list.
These headers don't have effect in C++:
-* `<iso646.h>`
-* `<stdalign.h>`
-* `<stdbool.h>`
+- `<iso646.h>`
+- `<stdalign.h>`
+- `<stdbool.h>`
-The checker ignores `include` directives within `extern "C" { ... }` blocks,
+The check ignores `include` directives within `extern "C" { ... }` blocks,
since a library might want to expose some API for C and C++ libraries.
-.. code-block:: c++
-
- // C++ source file...
- extern "C" {
- #include <assert.h> // Left intact.
- #include <stdbool.h> // Left intact.
- }
-
-Options
--------
-
-.. option:: CheckHeaderFile
-
- `clang-tidy` cannot know if the header file included by the currently
- analyzed C++ source file is not included by any other C source files.
- Hence, to omit false-positives and wrong fixit-hints, we ignore emitting
- reports into header files. One can set this option to `true` if they know
- that the header files in the project are only used by C++ source files.
- Default is `false`.
+```c++
+// C++ source file...
+extern "C" {
+#include <assert.h> // Left intact.
+#include <stdbool.h> // Left intact.
+}
+```
+
+## Options
+
+(modernize-deprecated-headers-check-header-file)=
+
+```{option} CheckHeaderFile
+`clang-tidy` cannot know if the header file included by the currently
+analyzed C++ source file is not included by any other C source files.
+Hence, to omit false-positives and wrong fixit-hints, we ignore emitting
+reports into header files. One can set this option to `true` if they know
+that the header files in the project are only used by C++ source files.
+Default is `false`.
+```
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.md
index 87790db99f4c7d..c20bfb9d7956bd 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.md
@@ -1,22 +1,20 @@
-.. title:: clang-tidy - modernize-loop-convert
+```{title} clang-tidy - modernize-loop-convert
+```
-modernize-loop-convert
-======================
+# modernize-loop-convert
-This check converts ``for(...; ...; ...)`` loops to use the new range-based
+This check converts `for(...; ...; ...)` loops to use the new range-based
loops in C++11.
Three kinds of loops can be converted:
-- Loops over statically allocated arrays.
-- Loops over containers, using iterators.
-- Loops over array-like containers, using ``operator[]`` and ``at()``.
+- Loops over statically allocated arrays.
+- Loops over containers, using iterators.
+- Loops over array-like containers, using `operator[]` and `at()`.
-MinConfidence option
---------------------
+## MinConfidence option
-risky
-^^^^^
+### risky
In loops where the container expression is more complex than just a
reference to a declared expression (a variable, function, enum, etc.),
@@ -25,264 +23,260 @@ in the transformation due to the increased risk of changing semantics.
Transformations for these loops are marked as `risky`, and thus will only
be converted if the minimum required confidence level is set to `risky`.
-.. code-block:: c++
+```c++
+int arr[10][20];
+int l = 5;
- int arr[10][20];
- int l = 5;
+for (int j = 0; j < 20; ++j)
+ int k = arr[l][j] + l; // using l outside arr[l] is considered risky
- for (int j = 0; j < 20; ++j)
- int k = arr[l][j] + l; // using l outside arr[l] is considered risky
-
- for (int i = 0; i < obj.getVector().size(); ++i)
- obj.foo(10); // using 'obj' is considered risky
+for (int i = 0; i < obj.getVector().size(); ++i)
+ obj.foo(10); // using 'obj' is considered risky
+```
See
-:ref:`Range-based loops evaluate end() only once<IncorrectRiskyTransformation>`
+{ref}`Range-based loops evaluate end() only once<IncorrectRiskyTransformation>`
for an example of an incorrect transformation when the minimum required confidence
level is set to `risky`.
-reasonable (Default)
-^^^^^^^^^^^^^^^^^^^^
+### reasonable (Default)
-If a loop calls ``.end()`` or ``.size()`` after each iteration, the
+If a loop calls `.end()` or `.size()` after each iteration, the
transformation for that loop is marked as `reasonable`, and thus will
be converted if the required confidence level is set to `reasonable`
(default) or lower.
-.. code-block:: c++
-
- // using size() is considered reasonable
- for (int i = 0; i < container.size(); ++i)
- cout << container[i];
+```c++
+// using size() is considered reasonable
+for (int i = 0; i < container.size(); ++i)
+ cout << container[i];
+```
-safe
-^^^^
+### safe
Any other loops that do not match the above criteria to be marked as
`risky` or `reasonable` are marked `safe`, and thus will be converted
if the required confidence level is set to `safe` or lower.
-.. code-block:: c++
-
- int arr[] = {1,2,3};
+```c++
+int arr[] = {1,2,3};
- for (int i = 0; i < 3; ++i)
- cout << arr[i];
+for (int i = 0; i < 3; ++i)
+ cout << arr[i];
+```
-Example
--------
+## Example
Original:
-.. code-block:: c++
+```c++
+const int N = 5;
+int arr[] = {1,2,3,4,5};
+vector<int> v;
+v.push_back(1);
+v.push_back(2);
+v.push_back(3);
- const int N = 5;
- int arr[] = {1,2,3,4,5};
- vector<int> v;
- v.push_back(1);
- v.push_back(2);
- v.push_back(3);
+// safe conversion
+for (int i = 0; i < N; ++i)
+ cout << arr[i];
- // safe conversion
- for (int i = 0; i < N; ++i)
- cout << arr[i];
+// reasonable conversion
+for (vector<int>::iterator it = v.begin(); it != v.end(); ++it)
+ cout << *it;
- // reasonable conversion
- for (vector<int>::iterator it = v.begin(); it != v.end(); ++it)
- cout << *it;
+// reasonable conversion
+for (vector<int>::iterator it = begin(v); it != end(v); ++it)
+ cout << *it;
- // reasonable conversion
- for (vector<int>::iterator it = begin(v); it != end(v); ++it)
- cout << *it;
+// reasonable conversion
+for (vector<int>::iterator it = std::begin(v); it != std::end(v); ++it)
+ cout << *it;
- // reasonable conversion
- for (vector<int>::iterator it = std::begin(v); it != std::end(v); ++it)
- cout << *it;
+// reasonable conversion
+for (int i = 0; i < v.size(); ++i)
+ cout << v[i];
- // reasonable conversion
- for (int i = 0; i < v.size(); ++i)
- cout << v[i];
-
- // reasonable conversion
- for (int i = 0; i < size(v); ++i)
- cout << v[i];
+// reasonable conversion
+for (int i = 0; i < size(v); ++i)
+ cout << v[i];
+```
After applying the check with minimum confidence level set to
`reasonable` (default):
-.. code-block:: c++
-
- const int N = 5;
- int arr[] = {1,2,3,4,5};
- vector<int> v;
- v.push_back(1);
- v.push_back(2);
- v.push_back(3);
+```c++
+const int N = 5;
+int arr[] = {1,2,3,4,5};
+vector<int> v;
+v.push_back(1);
+v.push_back(2);
+v.push_back(3);
- // safe conversion
- for (auto & elem : arr)
- cout << elem;
+// safe conversion
+for (auto & elem : arr)
+ cout << elem;
- // reasonable conversion
- for (auto & elem : v)
- cout << elem;
+// reasonable conversion
+for (auto & elem : v)
+ cout << elem;
- // reasonable conversion
- for (auto & elem : v)
- cout << elem;
+// reasonable conversion
+for (auto & elem : v)
+ cout << elem;
+```
-Reverse Iterator Support
-------------------------
+## Reverse Iterator Support
The converter is also capable of transforming iterator loops which use
-``rbegin`` and ``rend`` for looping backwards over a container. Out of the box
-this will automatically happen in C++20 mode using the ``ranges`` library,
+`rbegin` and `rend` for looping backwards over a container. Out of the box
+this will automatically happen in C++20 mode using the `ranges` library,
however the check can be configured to work without C++20 by specifying a
function to reverse a range and optionally the header file where that function
lives.
-Options
--------
+## Options
-.. option:: UseCxx20ReverseRanges
+(modernize-loop-convert-use-cxx20-reverse-ranges)=
- When set to true convert loops when in C++20 or later mode using
- ``std::views::reverse``.
- Default value is `true`.
+```{option} UseCxx20ReverseRanges
+When set to true convert loops when in C++20 or later mode using
+`std::views::reverse`.
+Default is `true`.
+```
-.. option:: MakeReverseRangeFunction
+(modernize-loop-convert-make-reverse-range-function)=
- Specify the function used to reverse an iterator pair, the function should
- accept a class with ``rbegin`` and ``rend`` methods and return a
- class with ``begin`` and ``end`` methods that call the ``rbegin`` and
- ``rend`` methods respectively. Common examples are ``std::views::reverse``
- and ``llvm::reverse``.
- Default value is an empty string.
+```{option} MakeReverseRangeFunction
+Specify the function used to reverse an iterator pair, the function should
+accept a class with `rbegin` and `rend` methods and return a
+class with `begin` and `end` methods that call the `rbegin` and
+`rend` methods respectively. Common examples are `std::views::reverse`
+and `llvm::reverse`.
+Default is an empty string.
+```
-.. option:: MakeReverseRangeHeader
+(modernize-loop-convert-make-reverse-range-header)=
- Specifies the header file where :option:`MakeReverseRangeFunction` is
- declared. For the previous examples this option would be set to
- ``range/v3/view/reverse.hpp`` and ``llvm/ADT/STLExtras.h`` respectively.
- If this is an empty string and :option:`MakeReverseRangeFunction` is set,
- the check will proceed on the assumption that the function is already
- available in the translation unit.
- This can be wrapped in angle brackets to signify to add the include as a
- system include.
- Default value is an empty string.
+```{option} MakeReverseRangeHeader
+Specifies the header file where [`MakeReverseRangeFunction`](#modernize-loop-convert-make-reverse-range-function) is
+declared. For the previous examples this option would be set to
+`range/v3/view/reverse.hpp` and `llvm/ADT/STLExtras.h` respectively.
+If this is an empty string and [`MakeReverseRangeFunction`](#modernize-loop-convert-make-reverse-range-function) is set,
+the check will proceed on the assumption that the function is already
+available in the translation unit.
+This can be wrapped in angle brackets to signify to add the include as a
+system include.
+Default is an empty string.
+```
-.. option:: IncludeStyle
+(modernize-loop-convert-include-style)=
- A string specifying which include-style is used, `llvm` or `google`. Default
- is `llvm`.
+```{option} IncludeStyle
+A string specifying which include-style is used, `llvm` or `google`. Default is `llvm`.
+```
-
-Limitations
------------
+## Limitations
There are certain situations where the tool may erroneously perform
transformations that remove information and change semantics. Users of the tool
should be aware of the behavior and limitations of the check outlined by
the cases below.
-Comments inside loop headers
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+### Comments inside loop headers
Comments inside the original loop header are ignored and deleted when
transformed.
-.. code-block:: c++
-
- for (int i = 0; i < N; /* This will be deleted */ ++i) { }
+```c++
+for (int i = 0; i < N; /* This will be deleted */ ++i) { }
+```
-Range-based loops evaluate end() only once
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+### Range-based loops evaluate end() only once
-The C++11 range-based for loop calls ``.end()`` only once during the
-initialization of the loop. If in the original loop ``.end()`` is called after
+The C++11 range-based for loop calls `.end()` only once during the
+initialization of the loop. If in the original loop `.end()` is called after
each iteration the semantics of the transformed loop may differ.
-.. code-block:: c++
+```c++
+// The following is semantically equivalent to the C++11 range-based for loop,
+// therefore the semantics of the header will not change.
+for (iterator it = container.begin(), e = container.end(); it != e; ++it) { }
- // The following is semantically equivalent to the C++11 range-based for loop,
- // therefore the semantics of the header will not change.
- for (iterator it = container.begin(), e = container.end(); it != e; ++it) { }
+// Instead of calling .end() after each iteration, this loop will be
+// transformed to call .end() only once during the initialization of the loop,
+// which may affect semantics.
+for (iterator it = container.begin(); it != container.end(); ++it) { }
+```
- // Instead of calling .end() after each iteration, this loop will be
- // transformed to call .end() only once during the initialization of the loop,
- // which may affect semantics.
- for (iterator it = container.begin(); it != container.end(); ++it) { }
-
-.. _IncorrectRiskyTransformation:
+(incorrectriskytransformation)=
As explained above, calling member functions of the container in the body
of the loop is considered `risky`. If the called member function modifies the
-container the semantics of the converted loop will differ due to ``.end()``
+container the semantics of the converted loop will differ due to `.end()`
being called only once.
-.. code-block:: c++
-
- bool flag = false;
- for (vector<T>::iterator it = vec.begin(); it != vec.end(); ++it) {
- // Add a copy of the first element to the end of the vector.
- if (!flag) {
- // This line makes this transformation 'risky'.
- vec.push_back(*it);
- flag = true;
- }
- cout << *it;
+```c++
+bool flag = false;
+for (vector<T>::iterator it = vec.begin(); it != vec.end(); ++it) {
+ // Add a copy of the first element to the end of the vector.
+ if (!flag) {
+ // This line makes this transformation 'risky'.
+ vec.push_back(*it);
+ flag = true;
}
+ cout << *it;
+}
+```
The original code above prints out the contents of the container including the
newly added element while the converted loop, shown below, will only print the
original contents and not the newly added element.
-.. code-block:: c++
-
- bool flag = false;
- for (auto & elem : vec) {
- // Add a copy of the first element to the end of the vector.
- if (!flag) {
- // This line makes this transformation 'risky'
- vec.push_back(elem);
- flag = true;
- }
- cout << elem;
- }
-
-Semantics will also be affected if ``.end()`` has side effects. For example, in
-the case where calls to ``.end()`` are logged the semantics will change in the
-transformed loop if ``.end()`` was originally called after each iteration.
-
-.. code-block:: c++
-
- iterator end() {
- num_of_end_calls++;
- return container.end();
+```c++
+bool flag = false;
+for (auto & elem : vec) {
+ // Add a copy of the first element to the end of the vector.
+ if (!flag) {
+ // This line makes this transformation 'risky'
+ vec.push_back(elem);
+ flag = true;
}
-
-Overloaded operator->() with side effects
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-Similarly, if ``operator->()`` was overloaded to have side effects, such as
-logging, the semantics will change. If the iterator's ``operator->()`` was used
-in the original loop it will be replaced with ``<container element>.<member>``
+ cout << elem;
+}
+```
+
+Semantics will also be affected if `.end()` has side effects. For example, in
+the case where calls to `.end()` are logged the semantics will change in the
+transformed loop if `.end()` was originally called after each iteration.
+
+```c++
+iterator end() {
+ num_of_end_calls++;
+ return container.end();
+}
+```
+
+### Overloaded operator->() with side effects
+
+Similarly, if `operator->()` was overloaded to have side effects, such as
+logging, the semantics will change. If the iterator's `operator->()` was used
+in the original loop it will be replaced with `<container element>.<member>`
instead due to the implicit dereference as part of the range-based for loop.
-Therefore any side effect of the overloaded ``operator->()`` will no longer be
+Therefore any side effect of the overloaded `operator->()` will no longer be
performed.
-.. code-block:: c++
+```c++
+for (iterator it = c.begin(); it != c.end(); ++it) {
+ it->func(); // Using operator->()
+}
+// Will be transformed to:
+for (auto & elem : c) {
+ elem.func(); // No longer using operator->()
+}
+```
- for (iterator it = c.begin(); it != c.end(); ++it) {
- it->func(); // Using operator->()
- }
- // Will be transformed to:
- for (auto & elem : c) {
- elem.func(); // No longer using operator->()
- }
-
-Pointers and references to containers
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+### Pointers and references to containers
While most of the check's risk analysis is dedicated to determining whether
the iterator or container was modified within the loop, it is possible to
@@ -296,25 +290,24 @@ The check cannot identify expressions associated with the container that are
different than the one used in the loop header, therefore the transformation
below ends up being performed at the `safe` level.
-.. code-block:: c++
-
- vector<int> vec;
+```c++
+vector<int> vec;
- vector<int> *ptr = &vec;
- vector<int> &ref = vec;
+vector<int> *ptr = &vec;
+vector<int> &ref = vec;
- for (vector<int>::iterator it = vec.begin(), e = vec.end(); it != e; ++it) {
- if (!flag) {
- // Accessing and modifying the container is considered risky, but the risk
- // level is not raised here.
- ptr->push_back(*it);
- ref.push_back(*it);
- flag = true;
- }
+for (vector<int>::iterator it = vec.begin(), e = vec.end(); it != e; ++it) {
+ if (!flag) {
+ // Accessing and modifying the container is considered risky, but the risk
+ // level is not raised here.
+ ptr->push_back(*it);
+ ref.push_back(*it);
+ flag = true;
}
+}
+```
-OpenMP
-^^^^^^
+### OpenMP
As range-based for loops are only available since OpenMP 5, this check should
not be used on code with a compatibility requirement of OpenMP prior to
@@ -322,5 +315,5 @@ version 5. It is **intentional** that this check does not make any attempts to
exclude incorrect diagnostics on OpenMP for loops prior to OpenMP 5.
To prevent this check to be applied (and to break) OpenMP for loops
-but still be applied to non-OpenMP for loops the usage of ``NOLINT``
-(see :ref:`clang-tidy-nolint`) on the specific for loops is recommended.
+but still be applied to non-OpenMP for loops the usage of `NOLINT`
+(see {ref}`clang-tidy-nolint`) on the specific for loops is recommended.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/macro-to-enum.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/macro-to-enum.md
index d56fa7194dd54e..fcc00bb0242c30 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/macro-to-enum.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/macro-to-enum.md
@@ -1,29 +1,28 @@
-.. title:: clang-tidy - modernize-macro-to-enum
+```{title} clang-tidy - modernize-macro-to-enum
+```
-modernize-macro-to-enum
-=======================
+# modernize-macro-to-enum
Replaces groups of adjacent macros with an unscoped anonymous enum.
Using an unscoped anonymous enum ensures that everywhere the macro
token was used previously, the enumerator name may be safely used.
-This check can be used to enforce the C++ core guideline `Enum.1:
-Prefer enumerations over macros
-<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#enum1-prefer-enumerations-over-macros>`_,
+This check can be used to enforce the C++ core guideline [Enum.1:
+Prefer enumerations over macros](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#enum1-prefer-enumerations-over-macros),
within the constraints outlined below.
Potential macros for replacement must meet the following constraints:
- Macros must expand only to integral literal tokens or expressions
- of literal tokens. The expression may contain any of the unary
- operators ``-``, ``+``, ``~`` or ``!``, any of the binary operators
- ``,``, ``-``, ``+``, ``*``, ``/``, ``%``, ``&``, ``|``, ``^``, ``<``,
- ``>``, ``<=``, ``>=``, ``==``, ``!=``, ``||``, ``&&``, ``<<``, ``>>``
- or ``<=>``, the ternary operator ``?:`` and its
- `GNU extension <https://gcc.gnu.org/onlinedocs/gcc/Conditionals.html>`_.
- Parenthesized expressions are also recognized. This recognizes
- most valid expressions. In particular, expressions with the
- ``sizeof`` operator are not recognized.
+ of literal tokens. The expression may contain any of the unary
+ operators `-`, `+`, `~` or `!`, any of the binary operators
+ `,`, `-`, `+`, `*`, `/`, `%`, `&`, `|`, `^`, `<`,
+ `>`, `<=`, `>=`, `==`, `!=`, `||`, `&&`, `<<`, `>>`
+ or `<=>`, the ternary operator `?:` and its
+ [GNU extension](https://gcc.gnu.org/onlinedocs/gcc/Conditionals.html).
+ Parenthesized expressions are also recognized. This recognizes
+ most valid expressions. In particular, expressions with the
+ `sizeof` operator are not recognized.
- Macros must be defined on sequential source file lines, or with
only comment lines in between macro definitions.
- Macros must all be defined in the same source file.
@@ -39,47 +38,47 @@ Potential macros for replacement must meet the following constraints:
Each cluster of macros meeting the above constraints is presumed to
be a set of values suitable for replacement by an anonymous enum.
From there, a developer can give the anonymous enum a name and
-continue refactoring to a scoped enum if desired. Comments on the
+continue refactoring to a scoped enum if desired. Comments on the
same line as a macro definition or between subsequent macro definitions
-are preserved in the output. No formatting is assumed in the provided
+are preserved in the output. No formatting is assumed in the provided
replacements, although clang-tidy can optionally format all fixes.
-.. warning::
-
- Initializing expressions are assumed to be valid initializers for
- an enum. C requires that enum values fit into an ``int``, but
- this may not be the case for some accepted constant expressions.
- For instance ``1 << 40`` will not fit into an ``int`` when the size of
- an ``int`` is 32 bits.
+```{warning}
+Initializing expressions are assumed to be valid initializers for
+an enum. C requires that enum values fit into an `int`, but
+this may not be the case for some accepted constant expressions.
+For instance `1 << 40` will not fit into an `int` when the size of
+an `int` is 32 bits.
+```
Examples:
-.. code-block:: c++
-
- #define RED 0xFF0000
- #define GREEN 0x00FF00
- #define BLUE 0x0000FF
+```c++
+#define RED 0xFF0000
+#define GREEN 0x00FF00
+#define BLUE 0x0000FF
- #define TM_NONE (-1) // No method selected.
- #define TM_ONE 1 // Use tailored method one.
- #define TM_TWO 2 // Use tailored method two. Method two
- // is preferable to method one.
- #define TM_THREE 3 // Use tailored method three.
+#define TM_NONE (-1) // No method selected.
+#define TM_ONE 1 // Use tailored method one.
+#define TM_TWO 2 // Use tailored method two. Method two
+ // is preferable to method one.
+#define TM_THREE 3 // Use tailored method three.
+```
becomes
-.. code-block:: c++
-
- enum {
- RED = 0xFF0000,
- GREEN = 0x00FF00,
- BLUE = 0x0000FF
- };
-
- enum {
- TM_NONE = (-1), // No method selected.
- TM_ONE = 1, // Use tailored method one.
- TM_TWO = 2, // Use tailored method two. Method two
- // is preferable to method one.
- TM_THREE = 3 // Use tailored method three.
- };
+```c++
+enum {
+RED = 0xFF0000,
+GREEN = 0x00FF00,
+BLUE = 0x0000FF
+};
+
+enum {
+TM_NONE = (-1), // No method selected.
+TM_ONE = 1, // Use tailored method one.
+TM_TWO = 2, // Use tailored method two. Method two
+ // is preferable to method one.
+TM_THREE = 3 // Use tailored method three.
+};
+```
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/make-shared.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/make-shared.md
index cd953e7ee394da..952df68c8f2cb4 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/make-shared.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/make-shared.md
@@ -1,56 +1,63 @@
-.. title:: clang-tidy - modernize-make-shared
+```{title} clang-tidy - modernize-make-shared
+```
-modernize-make-shared
-=====================
+# modernize-make-shared
-This check finds the creation of ``std::shared_ptr`` objects by explicitly
-calling the constructor and a ``new`` expression, and replaces it with a call
-to ``std::make_shared``.
+This check finds the creation of `std::shared_ptr` objects by explicitly
+calling the constructor and a `new` expression, and replaces it with a call
+to `std::make_shared`.
-.. code-block:: c++
+```c++
+auto my_ptr = std::shared_ptr<MyPair>(new MyPair(1, 2));
- auto my_ptr = std::shared_ptr<MyPair>(new MyPair(1, 2));
+// becomes
- // becomes
+auto my_ptr = std::make_shared<MyPair>(1, 2);
+```
- auto my_ptr = std::make_shared<MyPair>(1, 2);
+This check also finds calls to `std::shared_ptr::reset()` with a `new`
+expression, and replaces it with a call to `std::make_shared`.
-This check also finds calls to ``std::shared_ptr::reset()`` with a ``new``
-expression, and replaces it with a call to ``std::make_shared``.
+```c++
+my_ptr.reset(new MyPair(1, 2));
-.. code-block:: c++
+// becomes
- my_ptr.reset(new MyPair(1, 2));
+my_ptr = std::make_shared<MyPair>(1, 2);
+```
- // becomes
+## Options
- my_ptr = std::make_shared<MyPair>(1, 2);
+(modernize-make-shared-make-smart-ptr-function)=
-Options
--------
+```{option} MakeSmartPtrFunction
+A string specifying the name of make-shared-ptr function. Default is
+`std::make_shared`.
+```
-.. option:: MakeSmartPtrFunction
+(modernize-make-shared-make-smart-ptr-function-header)=
- A string specifying the name of make-shared-ptr function. Default is
- `std::make_shared`.
+```{option} MakeSmartPtrFunctionHeader
+A string specifying the corresponding header of make-shared-ptr function.
+Default is `<memory>`.
+```
-.. option:: MakeSmartPtrFunctionHeader
+(modernize-make-shared-include-style)=
- A string specifying the corresponding header of make-shared-ptr function.
- Default is `<memory>`.
+```{option} IncludeStyle
+A string specifying which include-style is used, `llvm` or `google`. Default is `llvm`.
+```
-.. option:: IncludeStyle
+(modernize-make-shared-ignore-macros)=
- A string specifying which include-style is used, `llvm` or `google`. Default
- is `llvm`.
+```{option} IgnoreMacros
+If set to `true`, the check will not give warnings inside macros. Default is `true`.
+```
-.. option:: IgnoreMacros
+(modernize-make-shared-ignore-default-initialization)=
- If set to `true`, the check will not give warnings inside macros. Default
- is `true`.
-
-.. option:: IgnoreDefaultInitialization
-
- If set to `false`, the check does not suggest edits that will transform
- default initialization into value initialization, as this can cause
- performance regressions. Default is `true`.
+```{option} IgnoreDefaultInitialization
+If set to `false`, the check does not suggest edits that will transform
+default initialization into value initialization, as this can cause
+performance regressions. Default is `true`.
+```
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/make-unique.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/make-unique.md
index 1aaa8701cd0f10..9ce3687b3359c4 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/make-unique.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/make-unique.md
@@ -1,56 +1,63 @@
-.. title:: clang-tidy - modernize-make-unique
+```{title} clang-tidy - modernize-make-unique
+```
-modernize-make-unique
-=====================
+# modernize-make-unique
-This check finds the creation of ``std::unique_ptr`` objects by explicitly
-calling the constructor and a ``new`` expression, and replaces it with a call
-to ``std::make_unique``, introduced in C++14.
+This check finds the creation of `std::unique_ptr` objects by explicitly
+calling the constructor and a `new` expression, and replaces it with a call
+to `std::make_unique`, introduced in C++14.
-.. code-block:: c++
+```c++
+auto my_ptr = std::unique_ptr<MyPair>(new MyPair(1, 2));
- auto my_ptr = std::unique_ptr<MyPair>(new MyPair(1, 2));
+// becomes
- // becomes
+auto my_ptr = std::make_unique<MyPair>(1, 2);
+```
- auto my_ptr = std::make_unique<MyPair>(1, 2);
+This check also finds calls to `std::unique_ptr::reset()` with a `new`
+expression, and replaces it with a call to `std::make_unique`.
-This check also finds calls to ``std::unique_ptr::reset()`` with a ``new``
-expression, and replaces it with a call to ``std::make_unique``.
+```c++
+my_ptr.reset(new MyPair(1, 2));
-.. code-block:: c++
+// becomes
- my_ptr.reset(new MyPair(1, 2));
+my_ptr = std::make_unique<MyPair>(1, 2);
+```
- // becomes
+## Options
- my_ptr = std::make_unique<MyPair>(1, 2);
+(modernize-make-unique-make-smart-ptr-function)=
-Options
--------
+```{option} MakeSmartPtrFunction
+A string specifying the name of make-unique-ptr function. Default is
+`std::make_unique`.
+```
-.. option:: MakeSmartPtrFunction
+(modernize-make-unique-make-smart-ptr-function-header)=
- A string specifying the name of make-unique-ptr function. Default is
- `std::make_unique`.
+```{option} MakeSmartPtrFunctionHeader
+A string specifying the corresponding header of make-unique-ptr function.
+Default is `<memory>`.
+```
-.. option:: MakeSmartPtrFunctionHeader
+(modernize-make-unique-include-style)=
- A string specifying the corresponding header of make-unique-ptr function.
- Default is `<memory>`.
+```{option} IncludeStyle
+A string specifying which include-style is used, `llvm` or `google`. Default is `llvm`.
+```
-.. option:: IncludeStyle
+(modernize-make-unique-ignore-macros)=
- A string specifying which include-style is used, `llvm` or `google`. Default
- is `llvm`.
+```{option} IgnoreMacros
+If set to `true`, the check will not give warnings inside macros. Default is `true`.
+```
-.. option:: IgnoreMacros
+(modernize-make-unique-ignore-default-initialization)=
- If set to `true`, the check will not give warnings inside macros. Default
- is `true`.
-
-.. option:: IgnoreDefaultInitialization
-
- If set to `false`, the check does not suggest edits that will transform
- default initialization into value initialization, as this can cause
- performance regressions. Default is `true`.
+```{option} IgnoreDefaultInitialization
+If set to `false`, the check does not suggest edits that will transform
+default initialization into value initialization, as this can cause
+performance regressions. Default is `true`.
+```
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/min-max-use-initializer-list.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/min-max-use-initializer-list.md
index 157c447ee4d981..d4621a6165c2f5 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/min-max-use-initializer-list.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/min-max-use-initializer-list.md
@@ -1,25 +1,24 @@
-.. title:: clang-tidy - modernize-min-max-use-initializer-list
+```{title} clang-tidy - modernize-min-max-use-initializer-list
+```
-modernize-min-max-use-initializer-list
-======================================
+# modernize-min-max-use-initializer-list
-Replaces nested ``std::min`` and ``std::max`` calls with an initializer list
+Replaces nested `std::min` and `std::max` calls with an initializer list
where applicable.
For instance, consider the following code:
-.. code-block:: cpp
-
- int a = std::max(std::max(i, j), k);
+```cpp
+int a = std::max(std::max(i, j), k);
+```
The check will transform the above code to:
-.. code-block:: cpp
-
- int a = std::max({i, j, k});
+```cpp
+int a = std::max({i, j, k});
+```
-Performance Considerations
-==========================
+# Performance Considerations
While this check simplifies the code and makes it more readable, it may cause
performance degradation for non-trivial types due to the need to copy objects
@@ -28,23 +27,27 @@ into the initializer list.
To avoid this, it is recommended to use `std::ref` or `std::cref` for
non-trivial types:
-.. code-block:: cpp
-
- std::string b = std::max({std::ref(i), std::ref(j), std::ref(k)});
+```cpp
+std::string b = std::max({std::ref(i), std::ref(j), std::ref(k)});
+```
-Options
-=======
+# Options
-.. option:: IncludeStyle
+(modernize-min-max-use-initializer-list-include-style)=
- A string specifying which include-style is used, `llvm` or `google`. Default
- is `llvm`.
+```{option} IncludeStyle
+A string specifying which include-style is used, `llvm` or `google`. Default is `llvm`.
+```
-.. option:: IgnoreNonTrivialTypes
+(modernize-min-max-use-initializer-list-ignore-non-trivial-types)=
- A boolean specifying whether to ignore non-trivial types. Default is `true`.
+```{option} IgnoreNonTrivialTypes
+A boolean specifying whether to ignore non-trivial types. Default is `true`.
+```
-.. option:: IgnoreTrivialTypesOfSizeAbove
+(modernize-min-max-use-initializer-list-ignore-trivial-types-of-size-above)=
- An integer specifying the size (in bytes) above which trivial types are
- ignored. Default is `32`.
+```{option} IgnoreTrivialTypesOfSizeAbove
+An integer specifying the size (in bytes) above which trivial types are
+ignored. Default is `32`.
+```
More information about the llvm-branch-commits
mailing list