[clang-tools-extra] [clang-tidy][docs] Rewrite modernize check docs to Markdown [2/4] (PR #232214)
Zeyi Xu via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 12 21:03:57 PST 2026
https://github.com/zeyi2 updated https://github.com/llvm/llvm-project/pull/232214
>From 948329ec0949a683e1b24aa49b781856164e9c2b Mon Sep 17 00:00:00 2001
From: Zeyi Xu <mitchell.xu2 at gmail.com>
Date: Thu, 15 Oct 2026 15:44:30 +0800
Subject: [PATCH 1/2] [clang-tidy][docs] Rewrite modernize check docs to
Markdown [2/4]
---
.../checks/modernize/pass-by-value.md | 201 ++++++------
.../checks/modernize/raw-string-literal.md | 71 ++--
.../checks/modernize/replace-auto-ptr.md | 105 +++---
.../replace-disallow-copy-and-assign-macro.md | 61 ++--
.../modernize/replace-random-shuffle.md | 58 ++--
.../checks/modernize/type-traits.md | 72 ++--
.../clang-tidy/checks/modernize/use-auto.md | 309 +++++++++---------
.../checks/modernize/use-constraints.md | 105 +++---
.../modernize/use-default-member-init.md | 117 ++++---
.../modernize/use-designated-initializers.md | 79 +++--
10 files changed, 593 insertions(+), 585 deletions(-)
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/pass-by-value.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/pass-by-value.md
index 0f5758dc097e6..d09cf81282a69 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/pass-by-value.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/pass-by-value.md
@@ -1,7 +1,7 @@
-.. title:: clang-tidy - modernize-pass-by-value
+```{title} clang-tidy - modernize-pass-by-value
+```
-modernize-pass-by-value
-=======================
+# modernize-pass-by-value
With move semantics added to the language and the standard library updated with
move constructors added for many types it is now interesting to take an
@@ -13,159 +13,154 @@ The transformation is usually beneficial when the calling code passes an
*rvalue* and assumes the move construction is a cheap operation. This short
example illustrates how the construction of the value happens:
-.. code-block:: c++
+```c++
+void foo(std::string s);
+std::string get_str();
- void foo(std::string s);
- std::string get_str();
+void f(const std::string &str) {
+ foo(str); // lvalue -> copy construction
+ foo(get_str()); // prvalue -> move construction
+}
+```
- void f(const std::string &str) {
- foo(str); // lvalue -> copy construction
- foo(get_str()); // prvalue -> move construction
- }
+```{note}
+Currently, only constructors are transformed to make use of pass-by-value.
+Contributions that handle other situations are welcome!
+```
-.. note::
-
- Currently, only constructors are transformed to make use of pass-by-value.
- Contributions that handle other situations are welcome!
-
-
-Pass-by-value in constructors
------------------------------
+## Pass-by-value in constructors
Replaces the uses of const-references constructor parameters that are copied
into class fields. The parameter is then moved with `std::move()`.
-Since ``std::move()`` is a library function declared in `<utility>` it may be
+Since `std::move()` is a library function declared in `<utility>` it may be
necessary to add this include. The check will add the include directive when
necessary.
-.. code-block:: c++
-
- #include <string>
+```c++
+ #include <string>
- class Foo {
- public:
- - Foo(const std::string &Copied, const std::string &ReadOnly)
- - : Copied(Copied), ReadOnly(ReadOnly)
- + Foo(std::string Copied, const std::string &ReadOnly)
- + : Copied(std::move(Copied)), ReadOnly(ReadOnly)
- {}
+ class Foo {
+ public:
+- Foo(const std::string &Copied, const std::string &ReadOnly)
+- : Copied(Copied), ReadOnly(ReadOnly)
++ Foo(std::string Copied, const std::string &ReadOnly)
++ : Copied(std::move(Copied)), ReadOnly(ReadOnly)
+ {}
- private:
- std::string Copied;
- const std::string &ReadOnly;
- };
+ private:
+ std::string Copied;
+ const std::string &ReadOnly;
+ };
- std::string get_cwd();
-
- void f(const std::string &Path) {
- // The parameter corresponding to 'get_cwd()' is move-constructed. By
- // using pass-by-value in the Foo constructor we managed to avoid a
- // copy-construction.
- Foo foo(get_cwd(), Path);
- }
+ std::string get_cwd();
+ void f(const std::string &Path) {
+ // The parameter corresponding to 'get_cwd()' is move-constructed. By
+ // using pass-by-value in the Foo constructor we managed to avoid a
+ // copy-construction.
+ Foo foo(get_cwd(), Path);
+ }
+```
If the parameter is used more than once no transformation is performed since
moved objects have an undefined state. It means the following code will be left
untouched:
-.. code-block:: c++
-
- #include <string>
+```c++
+#include <string>
- void pass(const std::string &S);
+void pass(const std::string &S);
- struct Foo {
- Foo(const std::string &S) : Str(S) {
- pass(S);
- }
-
- std::string Str;
- };
+struct Foo {
+ Foo(const std::string &S) : Str(S) {
+ pass(S);
+ }
+ std::string Str;
+};
+```
-Limitations
------------
+## Limitations
A situation where the generated code can be wrong is when the object referenced
is modified before the assignment in the init-list through a "hidden" reference.
Example:
-.. code-block:: c++
+```c++
+ std::string s("foo");
- std::string s("foo");
-
- struct Base {
- Base() {
- s = "bar";
- }
- };
-
- struct Derived : Base {
- - Derived(const std::string &S) : Field(S)
- + Derived(std::string S) : Field(std::move(S))
- { }
+ struct Base {
+ Base() {
+ s = "bar";
+ }
+ };
- std::string Field;
- };
+ struct Derived : Base {
+- Derived(const std::string &S) : Field(S)
++ Derived(std::string S) : Field(std::move(S))
+ { }
- void f() {
- - Derived d(s); // d.Field holds "bar"
- + Derived d(s); // d.Field holds "foo"
- }
+ std::string Field;
+ };
+ void f() {
+- Derived d(s); // d.Field holds "bar"
++ Derived d(s); // d.Field holds "foo"
+ }
+```
-Note about delayed template parsing
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+### Note about delayed template parsing
When delayed template parsing is enabled, constructors part of templated
contexts; templated constructors, constructors in class templates, constructors
of inner classes of template classes, etc., are not transformed. Delayed
template parsing is enabled by default on Windows as a Microsoft extension:
-`Clang Compiler User's Manual - Microsoft extensions`_.
+[Clang Compiler User's Manual - Microsoft extensions][clang compiler user's manual - microsoft extensions].
Delayed template parsing can be enabled using the `-fdelayed-template-parsing`
flag and disabled using `-fno-delayed-template-parsing`.
Example:
-.. code-block:: c++
+```c++
+ template <typename T> class C {
+ std::string S;
- template <typename T> class C {
- std::string S;
+ public:
+= // using -fdelayed-template-parsing (default on Windows)
+= C(const std::string &S) : S(S) {}
- public:
- = // using -fdelayed-template-parsing (default on Windows)
- = C(const std::string &S) : S(S) {}
-
- + // using -fno-delayed-template-parsing (default on non-Windows systems)
- + C(std::string S) : S(std::move(S)) {}
- };
-
-.. _Clang Compiler User's Manual - Microsoft extensions: https://clang.llvm.org/docs/UsersManual.html#microsoft-extensions
-
-.. seealso::
++ // using -fno-delayed-template-parsing (default on non-Windows systems)
++ C(std::string S) : S(std::move(S)) {}
+ };
+```
- For more information about the pass-by-value idiom, read: `Want Speed? Pass by Value`_.
+```{seealso}
+For more information about the pass-by-value idiom, read: [Want Speed? Pass by Value](https://web.archive.org/web/20140205194657/http://cpp-next.com/archive/2009/08/want-speed-pass-by-value/).
+```
- .. _Want Speed? Pass by Value: https://web.archive.org/web/20140205194657/http://cpp-next.com/archive/2009/08/want-speed-pass-by-value/
+## Options
-Options
--------
+(modernize-pass-by-value-include-style)=
-.. option:: IncludeStyle
+```{option} IncludeStyle
+A string specifying which include-style is used, `llvm` or `google`. Default is `llvm`.
+```
- A string specifying which include-style is used, `llvm` or `google`. Default
- is `llvm`.
+(modernize-pass-by-value-values-only)=
-.. option:: ValuesOnly
+```{option} ValuesOnly
+When `true`, the check only warns about copied parameters that are already
+passed by value. Default is `false`.
+```
- When `true`, the check only warns about copied parameters that are already
- passed by value. Default is `false`.
+(modernize-pass-by-value-ignore-macros)=
-.. option:: IgnoreMacros
+```{option} IgnoreMacros
+When `true`, the check will not give warnings inside macros. Default is
+`false`.
+```
- When `true`, the check will not give warnings inside macros. Default is
- `false`.
+[clang compiler user's manual - microsoft extensions]: https://clang.llvm.org/docs/UsersManual.html#microsoft-extensions
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.md
index 66e50e80fa70b..23174a7a2e9f4 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.md
@@ -1,39 +1,39 @@
-.. title:: clang-tidy - modernize-raw-string-literal
+```{title} clang-tidy - modernize-raw-string-literal
+```
-modernize-raw-string-literal
-============================
+# modernize-raw-string-literal
This check selectively replaces string literals containing escaped characters
with raw string literals.
Example:
-.. code-block:: c++
-
- const char *const Quotes{"embedded \"quotes\""};
- const char *const Paragraph{"Line one.\nLine two.\nLine three.\n"};
- const char *const SingleLine{"Single line.\n"};
- const char *const TrailingSpace{"Look here -> \n"};
- const char *const Tab{"One\tTwo\n"};
- const char *const Bell{"Hello!\a And welcome!"};
- const char *const Path{"C:\\Program Files\\Vendor\\Application.exe"};
- const char *const RegEx{"\\w\\([a-z]\\)"};
+```c++
+const char *const Quotes{"embedded \"quotes\""};
+const char *const Paragraph{"Line one.\nLine two.\nLine three.\n"};
+const char *const SingleLine{"Single line.\n"};
+const char *const TrailingSpace{"Look here -> \n"};
+const char *const Tab{"One\tTwo\n"};
+const char *const Bell{"Hello!\a And welcome!"};
+const char *const Path{"C:\\Program Files\\Vendor\\Application.exe"};
+const char *const RegEx{"\\w\\([a-z]\\)"};
+```
becomes
-.. code-block:: c++
-
- const char *const Quotes{R"(embedded "quotes")"};
- const char *const Paragraph{"Line one.\nLine two.\nLine three.\n"};
- const char *const SingleLine{"Single line.\n"};
- const char *const TrailingSpace{"Look here -> \n"};
- const char *const Tab{"One\tTwo\n"};
- const char *const Bell{"Hello!\a And welcome!"};
- const char *const Path{R"(C:\Program Files\Vendor\Application.exe)"};
- const char *const RegEx{R"(\w\([a-z]\))"};
+```c++
+const char *const Quotes{R"(embedded "quotes")"};
+const char *const Paragraph{"Line one.\nLine two.\nLine three.\n"};
+const char *const SingleLine{"Single line.\n"};
+const char *const TrailingSpace{"Look here -> \n"};
+const char *const Tab{"One\tTwo\n"};
+const char *const Bell{"Hello!\a And welcome!"};
+const char *const Path{R"(C:\Program Files\Vendor\Application.exe)"};
+const char *const RegEx{R"(\w\([a-z]\))"};
+```
The presence of any of the following escapes can cause the string to be
-converted to a raw string literal: ``\\``, ``\'``, ``\"``, ``\?``,
+converted to a raw string literal: `\\`, `\'`, `\"`, `\?`,
and octal or hexadecimal escapes for printable ASCII characters.
A string literal containing only escaped newlines is a common way of
@@ -45,17 +45,20 @@ An escaped horizontal tab, form feed, or vertical tab prevents the string
literal from being converted. The presence of a horizontal tab, form feed or
vertical tab in source code is not visually obvious.
-Options
--------
+## Options
-.. option:: DelimiterStem
+(modernize-raw-string-literal-delimiter-stem)=
- Custom delimiter to escape characters in raw string literals. It is used in
- the following construction: ``R"stem_delimiter(contents)stem_delimiter"``.
- The default value is `lit`.
+```{option} DelimiterStem
+Custom delimiter to escape characters in raw string literals. It is used in
+the following construction: `R"stem_delimiter(contents)stem_delimiter"`.
+Default is `lit`.
+```
-.. option:: ReplaceShorterLiterals
+(modernize-raw-string-literal-replace-shorter-literals)=
- Controls replacing shorter non-raw string literals with longer raw string
- literals. Setting this option to `true` enables the replacement.
- The default value is `false` (shorter literals are not replaced).
+```{option} ReplaceShorterLiterals
+Controls replacing shorter non-raw string literals with longer raw string
+literals. Setting this option to `true` enables the replacement.
+When `false`, shorter literals are not replaced. Default is `false`.
+```
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-auto-ptr.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-auto-ptr.md
index 8a8c30e6c15a3..27e4e68b1d681 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-auto-ptr.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-auto-ptr.md
@@ -1,81 +1,78 @@
-.. title:: clang-tidy - modernize-replace-auto-ptr
+```{title} clang-tidy - modernize-replace-auto-ptr
+```
-modernize-replace-auto-ptr
-==========================
+# modernize-replace-auto-ptr
-This check replaces the uses of the deprecated class ``std::auto_ptr`` by
-``std::unique_ptr`` (introduced in C++11). The transfer of ownership, done
+This check replaces the uses of the deprecated class `std::auto_ptr` by
+`std::unique_ptr` (introduced in C++11). The transfer of ownership, done
by the copy-constructor and the assignment operator, is changed to match
-``std::unique_ptr`` usage by using explicit calls to ``std::move()``.
+`std::unique_ptr` usage by using explicit calls to `std::move()`.
Migration example:
-.. code-block:: c++
+```c++
+-void take_ownership_fn(std::auto_ptr<int> int_ptr);
++void take_ownership_fn(std::unique_ptr<int> int_ptr);
- -void take_ownership_fn(std::auto_ptr<int> int_ptr);
- +void take_ownership_fn(std::unique_ptr<int> int_ptr);
+ void f(int x) {
+- std::auto_ptr<int> a(new int(x));
+- std::auto_ptr<int> b;
++ std::unique_ptr<int> a(new int(x));
++ std::unique_ptr<int> b;
- void f(int x) {
- - std::auto_ptr<int> a(new int(x));
- - std::auto_ptr<int> b;
- + std::unique_ptr<int> a(new int(x));
- + std::unique_ptr<int> b;
+- b = a;
+- take_ownership_fn(b);
++ b = std::move(a);
++ take_ownership_fn(std::move(b));
+ }
+```
- - b = a;
- - take_ownership_fn(b);
- + b = std::move(a);
- + take_ownership_fn(std::move(b));
- }
-
-Since ``std::move()`` is a library function declared in ``<utility>`` it may be
+Since `std::move()` is a library function declared in `<utility>` it may be
necessary to add this include. The check will add the include directive when
necessary.
+## Limitations
-Limitations
------------
-
-* If headers modification is not activated or if a header is not allowed to be
+- If headers modification is not activated or if a header is not allowed to be
changed this check will produce broken code (compilation error), where the
headers' code will stay unchanged while the code using them will be changed.
-
-* Client code that declares a reference to an ``std::auto_ptr`` coming from
- code that can't be migrated (such as a header coming from a 3\ :sup:`rd`
+- Client code that declares a reference to an `std::auto_ptr` coming from
+ code that can't be migrated (such as a header coming from a 3{sup}`rd`
party library) will produce a compilation error after migration. This is
- because the type of the reference will be changed to ``std::unique_ptr`` but
+ because the type of the reference will be changed to `std::unique_ptr` but
the type returned by the library won't change, binding a reference to
- ``std::unique_ptr`` from an ``std::auto_ptr``. This pattern doesn't make much
- sense and usually ``std::auto_ptr`` are stored by value (otherwise what is
+ `std::unique_ptr` from an `std::auto_ptr`. This pattern doesn't make much
+ sense and usually `std::auto_ptr` are stored by value (otherwise what is
the point in using them instead of a reference or a pointer?).
-.. code-block:: c++
-
- // <3rd-party header...>
- std::auto_ptr<int> get_value();
- const std::auto_ptr<int> & get_ref();
-
- // <calling code (with migration)...>
- -std::auto_ptr<int> a(get_value());
- +std::unique_ptr<int> a(get_value()); // ok, unique_ptr constructed from auto_ptr
+```c++
+ // <3rd-party header...>
+ std::auto_ptr<int> get_value();
+ const std::auto_ptr<int> & get_ref();
- -const std::auto_ptr<int> & p = get_ptr();
- +const std::unique_ptr<int> & p = get_ptr(); // won't compile
+ // <calling code (with migration)...>
+-std::auto_ptr<int> a(get_value());
++std::unique_ptr<int> a(get_value()); // ok, unique_ptr constructed from auto_ptr
-* Non-instantiated templates aren't modified.
+-const std::auto_ptr<int> & p = get_ptr();
++const std::unique_ptr<int> & p = get_ptr(); // won't compile
+```
-.. code-block:: c++
+- Non-instantiated templates aren't modified.
- template <typename X>
- void f() {
- std::auto_ptr<X> p;
- }
+```c++
+template <typename X>
+void f() {
+ std::auto_ptr<X> p;
+}
- // only 'f<int>()' (or similar) will trigger the replacement.
+// only 'f<int>()' (or similar) will trigger the replacement.
+```
-Options
--------
+## Options
-.. option:: IncludeStyle
+(modernize-replace-auto-ptr-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`.
+```
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-disallow-copy-and-assign-macro.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-disallow-copy-and-assign-macro.md
index 485abca339050..ec0b17778ad48 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-disallow-copy-and-assign-macro.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-disallow-copy-and-assign-macro.md
@@ -1,53 +1,52 @@
-.. title:: clang-tidy - modernize-replace-disallow-copy-and-assign-macro
+```{title} clang-tidy - modernize-replace-disallow-copy-and-assign-macro
+```
-modernize-replace-disallow-copy-and-assign-macro
-================================================
+# modernize-replace-disallow-copy-and-assign-macro
-Finds macro expansions of ``DISALLOW_COPY_AND_ASSIGN(Type)`` and replaces them
+Finds macro expansions of `DISALLOW_COPY_AND_ASSIGN(Type)` and replaces them
with a deleted copy constructor and a deleted assignment operator.
-Before the ``delete`` keyword was introduced in C++11 it was common practice to
+Before the `delete` keyword was introduced in C++11 it was common practice to
declare a copy constructor and an assignment operator as private members. This
effectively makes them unusable to the public API of a class.
-With the advent of the ``delete`` keyword in C++11 we can abandon the
-``private`` access of the copy constructor and the assignment operator and
+With the advent of the `delete` keyword in C++11 we can abandon the
+`private` access of the copy constructor and the assignment operator and
delete the methods entirely.
When running this check on a code like this:
-.. code-block:: c++
-
- class Foo {
- private:
- DISALLOW_COPY_AND_ASSIGN(Foo);
- };
+```c++
+class Foo {
+private:
+ DISALLOW_COPY_AND_ASSIGN(Foo);
+};
+```
It will be transformed to this:
-.. code-block:: c++
-
- class Foo {
- private:
- Foo(const Foo &) = delete;
- const Foo &operator=(const Foo &) = delete;
- };
-
+```c++
+class Foo {
+private:
+ Foo(const Foo &) = delete;
+ const Foo &operator=(const Foo &) = delete;
+};
+```
-Limitations
------------
+## Limitations
-* Notice that the migration example above leaves the ``private`` access
+- Notice that the migration example above leaves the `private` access
specification untouched. You might want to run the check
- :doc:`modernize-use-equals-delete <../modernize/use-equals-delete>`
+ {doc}`modernize-use-equals-delete <../modernize/use-equals-delete>`
to get warnings for deleted functions in private sections.
-Options
--------
+## Options
-.. option:: MacroName
+(modernize-replace-disallow-copy-and-assign-macro-macro-name)=
- A string specifying the macro name whose expansion will be replaced.
- Default is `DISALLOW_COPY_AND_ASSIGN`.
+```{option} MacroName
+A string specifying the macro name whose expansion will be replaced.
+Default is `DISALLOW_COPY_AND_ASSIGN`.
+```
-See: https://en.cppreference.com/w/cpp/language/function#Deleted_functions
+See: <https://en.cppreference.com/w/cpp/language/function#Deleted_functions>
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-random-shuffle.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-random-shuffle.md
index c6dcd722d7ad7..c19ee107d00eb 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-random-shuffle.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-random-shuffle.md
@@ -1,52 +1,52 @@
-.. title:: clang-tidy - modernize-replace-random-shuffle
+```{title} clang-tidy - modernize-replace-random-shuffle
+```
-modernize-replace-random-shuffle
-================================
+# modernize-replace-random-shuffle
-This check will find occurrences of ``std::random_shuffle`` and replace it with
-``std::shuffle``. In C++17 ``std::random_shuffle`` will no longer be available
+This check will find occurrences of `std::random_shuffle` and replace it with
+`std::shuffle`. In C++17 `std::random_shuffle` will no longer be available
and thus we need to replace it.
Below are two examples of what kind of occurrences will be found and two
examples of what it will be replaced with.
-.. code-block:: c++
+```c++
+std::vector<int> v;
- std::vector<int> v;
+// First example
+std::random_shuffle(vec.begin(), vec.end());
- // First example
- std::random_shuffle(vec.begin(), vec.end());
-
- // Second example
- std::random_shuffle(vec.begin(), vec.end(), randomFunc);
+// Second example
+std::random_shuffle(vec.begin(), vec.end(), randomFunc);
+```
Both of these examples will be replaced with:
-.. code-block:: c++
-
- std::shuffle(vec.begin(), vec.end(), std::mt19937(std::random_device()()));
+```c++
+std::shuffle(vec.begin(), vec.end(), std::mt19937(std::random_device()()));
+```
-The second example will also receive a warning that ``randomFunc`` is no longer
+The second example will also receive a warning that `randomFunc` is no longer
supported in the same way as before so if the user wants the same
functionality, the user will need to change the implementation of the
-``randomFunc``.
+`randomFunc`.
-One thing to be aware of here is that ``std::random_device`` is quite expensive
+One thing to be aware of here is that `std::random_device` is quite expensive
to initialize. So if you are using the code in a performance critical place,
you probably want to initialize it elsewhere.
Another thing is that the seeding quality of the suggested fix is quite poor:
-``std::mt19937`` has an internal state of 624 32-bit integers, but is only
+`std::mt19937` has an internal state of 624 32-bit integers, but is only
seeded with a single integer. So if you require
higher quality randomness, you should consider seeding better, for example:
-.. code-block:: c++
-
- std::shuffle(v.begin(), v.end(), []() {
- std::mt19937::result_type seeds[std::mt19937::state_size];
- std::random_device device;
- std::uniform_int_distribution<typename std::mt19937::result_type> dist;
- std::generate(std::begin(seeds), std::end(seeds), [&] { return dist(device); });
- std::seed_seq seq(std::begin(seeds), std::end(seeds));
- return std::mt19937(seq);
- }());
+```c++
+std::shuffle(v.begin(), v.end(), []() {
+ std::mt19937::result_type seeds[std::mt19937::state_size];
+ std::random_device device;
+ std::uniform_int_distribution<typename std::mt19937::result_type> dist;
+ std::generate(std::begin(seeds), std::end(seeds), [&] { return dist(device); });
+ std::seed_seq seq(std::begin(seeds), std::end(seeds));
+ return std::mt19937(seq);
+}());
+```
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.md
index 3871c6ae3934b..5c2abd5b1460a 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.md
@@ -1,57 +1,55 @@
-.. title:: clang-tidy - modernize-type-traits
+```{title} clang-tidy - modernize-type-traits
+```
-modernize-type-traits
-=====================
+# modernize-type-traits
-Converts standard library type traits of the form ``traits<...>::type`` and
-``traits<...>::value`` into ``traits_t<...>`` and
-``traits_v<...>`` respectively.
+Converts standard library type traits of the form `traits<...>::type` and
+`traits<...>::value` into `traits_t<...>` and
+`traits_v<...>` respectively.
-Also suggests converting ``std::remove_cv_t<std::remove_reference_t<...>`` into
-``std::remove_cvref_t<...>`` when targeting C++20 or above.
+Also suggests converting `std::remove_cv_t<std::remove_reference_t<...>` into
+`std::remove_cvref_t<...>` when targeting C++20 or above.
For example:
-.. code-block:: c++
+```c++
+std::is_integral<T>::value
+std::is_same<int, float>::value
+typename std::add_const<T>::type
+std::make_signed<unsigned>::type
- std::is_integral<T>::value
- std::is_same<int, float>::value
- typename std::add_const<T>::type
- std::make_signed<unsigned>::type
-
- std::remove_cv_t<std::remove_reference_t<int>>
+std::remove_cv_t<std::remove_reference_t<int>>
+```
Would be converted into:
-.. code-block:: c++
-
- std::is_integral_v<T>
- std::is_same_v<int, float>
- std::add_const_t<T>
- std::make_signed_t<unsigned>
-
- std::remove_cvref_t<int>
-
-
-Options
--------
+```c++
+std::is_integral_v<T>
+std::is_same_v<int, float>
+std::add_const_t<T>
+std::make_signed_t<unsigned>
-.. option:: IgnoreMacros
+std::remove_cvref_t<int>
+```
- If `true` don't diagnose traits defined in macros.
+## Options
- Note: Fixes will never be emitted for code inside of macros.
+(modernize-type-traits-ignore-macros)=
- .. code-block:: c++
+````{option} IgnoreMacros
+If `true` don't diagnose traits defined in macros.
- #define IS_SIGNED(T) std::is_signed<T>::value
+Note: Fixes will never be emitted for code inside of macros.
- Defaults to `false`.
+```c++
+#define IS_SIGNED(T) std::is_signed<T>::value
+```
+Default is `false`.
+````
-Limitations
------------
+## Limitations
Does not currently diagnose uses of type traits with nested name
-specifiers (e.g. ``std::chrono::is_clock``,
-``std::chrono::treat_as_floating_point``).
+specifiers (e.g. `std::chrono::is_clock`,
+`std::chrono::treat_as_floating_point`).
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-auto.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-auto.md
index 3cd37e0eac50a..c309d91dcc895 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-auto.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-auto.md
@@ -1,234 +1,233 @@
-.. title:: clang-tidy - modernize-use-auto
+```{title} clang-tidy - modernize-use-auto
+```
-modernize-use-auto
-==================
+# modernize-use-auto
-This check is responsible for using the ``auto`` type specifier for variable
+This check is responsible for using the `auto` type specifier for variable
declarations to *improve code readability and maintainability*. For example:
-.. code-block:: c++
+```c++
+std::vector<int>::iterator I = my_container.begin();
- std::vector<int>::iterator I = my_container.begin();
+// transforms to:
- // transforms to:
+auto I = my_container.begin();
+```
- auto I = my_container.begin();
-
-The ``auto`` type specifier will only be introduced in situations where the
+The `auto` type specifier will only be introduced in situations where the
variable type matches the type of the initializer expression. In other words
-``auto`` should deduce the same type that was originally spelled in the source.
+`auto` should deduce the same type that was originally spelled in the source.
However, not every situation should be transformed:
-.. code-block:: c++
-
- int val = 42;
- InfoStruct &I = SomeObject.getInfo();
+```c++
+int val = 42;
+InfoStruct &I = SomeObject.getInfo();
- // Should not become:
+// Should not become:
- auto val = 42;
- auto &I = SomeObject.getInfo();
+auto val = 42;
+auto &I = SomeObject.getInfo();
+```
-In this example using ``auto`` for builtins doesn't improve readability. In
+In this example using `auto` for builtins doesn't improve readability. In
other situations it makes the code less self-documenting impairing readability
-and maintainability. As a result, ``auto`` is used only introduced in specific
+and maintainability. As a result, `auto` is used only introduced in specific
situations described below.
-Iterators
----------
+## Iterators
Iterator type specifiers tend to be long and used frequently, especially in
loop constructs. Since the functions generating iterators have a common format,
the type specifier can be replaced without obscuring the meaning of code while
improving readability and maintainability.
-.. code-block:: c++
-
- for (std::vector<int>::iterator I = my_container.begin(),
- E = my_container.end();
- I != E; ++I) {
- }
+```c++
+for (std::vector<int>::iterator I = my_container.begin(),
+ E = my_container.end();
+ I != E; ++I) {
+}
- // becomes
+// becomes
- for (auto I = my_container.begin(), E = my_container.end(); I != E; ++I) {
- }
+for (auto I = my_container.begin(), E = my_container.end(); I != E; ++I) {
+}
+```
The check will only replace iterator type-specifiers when all of the following
conditions are satisfied:
-* The iterator is for one of the standard containers in ``std`` namespace:
-
- * ``array``
- * ``deque``
- * ``forward_list``
- * ``list``
- * ``vector``
- * ``map``
- * ``multimap``
- * ``set``
- * ``multiset``
- * ``unordered_map``
- * ``unordered_multimap``
- * ``unordered_set``
- * ``unordered_multiset``
- * ``queue``
- * ``priority_queue``
- * ``stack``
-
-* The iterator is one of the possible iterator types for standard containers:
-
- * ``iterator``
- * ``reverse_iterator``
- * ``const_iterator``
- * ``const_reverse_iterator``
-
-* In addition to using iterator types directly, typedefs or other ways of
+- The iterator is for one of the standard containers in `std` namespace:
+
+ - `array`
+ - `deque`
+ - `forward_list`
+ - `list`
+ - `vector`
+ - `map`
+ - `multimap`
+ - `set`
+ - `multiset`
+ - `unordered_map`
+ - `unordered_multimap`
+ - `unordered_set`
+ - `unordered_multiset`
+ - `queue`
+ - `priority_queue`
+ - `stack`
+
+- The iterator is one of the possible iterator types for standard containers:
+
+ - `iterator`
+ - `reverse_iterator`
+ - `const_iterator`
+ - `const_reverse_iterator`
+
+- In addition to using iterator types directly, typedefs or other ways of
referring to those types are also allowed. However, implementation-specific
- types for which a type like ``std::vector<int>::iterator`` is itself a
+ types for which a type like `std::vector<int>::iterator` is itself a
typedef will not be transformed. Consider the following examples:
-.. code-block:: c++
+```c++
+// The following direct uses of iterator types will be transformed.
+std::vector<int>::iterator I = MyVec.begin();
+{
+ using namespace std;
+ list<int>::iterator I = MyList.begin();
+}
- // The following direct uses of iterator types will be transformed.
- std::vector<int>::iterator I = MyVec.begin();
- {
- using namespace std;
- list<int>::iterator I = MyList.begin();
- }
+// The type specifier for J would transform to auto since it's a typedef
+// to a standard iterator type.
+typedef std::map<int, std::string>::const_iterator map_iterator;
+map_iterator J = MyMap.begin();
- // The type specifier for J would transform to auto since it's a typedef
- // to a standard iterator type.
- typedef std::map<int, std::string>::const_iterator map_iterator;
- map_iterator J = MyMap.begin();
+// The following implementation-specific iterator type for which
+// std::vector<int>::iterator could be a typedef would not be transformed.
+__gnu_cxx::__normal_iterator<int*, std::vector> K = MyVec.begin();
+```
- // The following implementation-specific iterator type for which
- // std::vector<int>::iterator could be a typedef would not be transformed.
- __gnu_cxx::__normal_iterator<int*, std::vector> K = MyVec.begin();
+- The initializer for the variable being declared is not a braced initializer
+ list. Otherwise, use of `auto` would cause the type of the variable to be
+ deduced as `std::initializer_list`.
-* The initializer for the variable being declared is not a braced initializer
- list. Otherwise, use of ``auto`` would cause the type of the variable to be
- deduced as ``std::initializer_list``.
+## New expressions
-New expressions
----------------
-
-Frequently, when a pointer is declared and initialized with ``new``, the
+Frequently, when a pointer is declared and initialized with `new`, the
pointee type is written twice: in the declaration type and in the
-``new`` expression. In this case, the declaration type can be replaced with
-``auto`` improving readability and maintainability.
-
-.. code-block:: c++
+`new` expression. In this case, the declaration type can be replaced with
+`auto` improving readability and maintainability.
- TypeName *my_pointer = new TypeName(my_param);
+```c++
+TypeName *my_pointer = new TypeName(my_param);
- // becomes
+// becomes
- auto *my_pointer = new TypeName(my_param);
+auto *my_pointer = new TypeName(my_param);
+```
The check will also replace the declaration type in multiple declarations, if
the following conditions are satisfied:
-* All declared variables have the same type (i.e. all of them are pointers to
+- All declared variables have the same type (i.e. all of them are pointers to
the same type).
-* All declared variables are initialized with a ``new`` expression.
-* The types of all the new expressions are the same than the pointee of the
+- All declared variables are initialized with a `new` expression.
+- The types of all the new expressions are the same than the pointee of the
declaration type.
-.. code-block:: c++
-
- TypeName *my_first_pointer = new TypeName, *my_second_pointer = new TypeName;
+```c++
+TypeName *my_first_pointer = new TypeName, *my_second_pointer = new TypeName;
- // becomes
+// becomes
- auto *my_first_pointer = new TypeName, *my_second_pointer = new TypeName;
+auto *my_first_pointer = new TypeName, *my_second_pointer = new TypeName;
+```
-Cast expressions
-----------------
+## Cast expressions
Frequently, when a variable is declared and initialized with a cast, the
variable type is written twice: in the declaration type and in the
cast expression. In this case, the declaration type can be replaced with
-``auto`` improving readability and maintainability.
+`auto` improving readability and maintainability.
-.. code-block:: c++
+```c++
+TypeName *my_pointer = static_cast<TypeName>(my_param);
- TypeName *my_pointer = static_cast<TypeName>(my_param);
+// becomes
- // becomes
+auto *my_pointer = static_cast<TypeName>(my_param);
+```
- auto *my_pointer = static_cast<TypeName>(my_param);
-
-The check handles ``static_cast``, ``dynamic_cast``, ``const_cast``,
-``reinterpret_cast``, functional casts, C-style casts and function templates
-that behave as casts, such as ``llvm::dyn_cast``, ``boost::lexical_cast`` and
-``gsl::narrow_cast``. Calls to function templates are considered to behave as
+The check handles `static_cast`, `dynamic_cast`, `const_cast`,
+`reinterpret_cast`, functional casts, C-style casts and function templates
+that behave as casts, such as `llvm::dyn_cast`, `boost::lexical_cast` and
+`gsl::narrow_cast`. Calls to function templates are considered to behave as
casts if the first template argument is explicit and is a type, and the
function returns that type, or a pointer or reference to it.
+## Limitations
-Limitations
------------
-
-* If the initializer is an explicit conversion constructor, the check will not
+- If the initializer is an explicit conversion constructor, the check will not
replace the type specifier even though it would be safe to do so.
+- User-defined iterators are not handled at this time.
-* User-defined iterators are not handled at this time.
-
-Options
--------
-
-.. option:: MinTypeNameLength
-
- If the option is set to non-zero (default `5`), the check will ignore type
- names having a length less than the option value. The option affects
- expressions only, not iterators.
- Spaces between multi-lexeme type names (``long int``) are considered as one.
- If the :option:`RemoveStars` option (see below) is set to `true`, then ``*s``
- in the type are also counted as a part of the type name.
+## Options
-.. code-block:: c++
+(modernize-use-auto-min-type-name-length)=
- // MinTypeNameLength = 0, RemoveStars=0
+````{option} MinTypeNameLength
+If the option is set to non-zero, the check will ignore type
+names having a length less than the option value. The option affects
+expressions only, not iterators.
+Spaces between multi-lexeme type names (`long int`) are considered as one.
+If the [`RemoveStars`](#modernize-use-auto-remove-stars) option (see below) is set to `true`, then `*s`
+in the type are also counted as a part of the type name.
- int a = static_cast<int>(foo()); // ---> auto a = ...
- // length(bool *) = 4
- bool *b = new bool; // ---> auto *b = ...
- unsigned c = static_cast<unsigned>(foo()); // ---> auto c = ...
+```c++
+// MinTypeNameLength = 0, RemoveStars=0
- // MinTypeNameLength = 5, RemoveStars=0
+int a = static_cast<int>(foo()); // ---> auto a = ...
+// length(bool *) = 4
+bool *b = new bool; // ---> auto *b = ...
+unsigned c = static_cast<unsigned>(foo()); // ---> auto c = ...
- int a = static_cast<int>(foo()); // ---> int a = ...
- bool b = static_cast<bool>(foo()); // ---> bool b = ...
- bool *pb = static_cast<bool*>(foo()); // ---> bool *pb = ...
- unsigned c = static_cast<unsigned>(foo()); // ---> auto c = ...
- // length(long <on-or-more-spaces> int) = 8
- long int d = static_cast<long int>(foo()); // ---> auto d = ...
+// MinTypeNameLength = 5, RemoveStars=0
- // MinTypeNameLength = 5, RemoveStars=1
+int a = static_cast<int>(foo()); // ---> int a = ...
+bool b = static_cast<bool>(foo()); // ---> bool b = ...
+bool *pb = static_cast<bool*>(foo()); // ---> bool *pb = ...
+unsigned c = static_cast<unsigned>(foo()); // ---> auto c = ...
+// length(long <on-or-more-spaces> int) = 8
+long int d = static_cast<long int>(foo()); // ---> auto d = ...
- int a = static_cast<int>(foo()); // ---> int a = ...
- // length(int * * ) = 5
- int **pa = static_cast<int**>(foo()); // ---> auto pa = ...
- bool b = static_cast<bool>(foo()); // ---> bool b = ...
- bool *pb = static_cast<bool*>(foo()); // ---> auto pb = ...
- unsigned c = static_cast<unsigned>(foo()); // ---> auto c = ...
- long int d = static_cast<long int>(foo()); // ---> auto d = ...
+// MinTypeNameLength = 5, RemoveStars=1
-.. option:: RemoveStars
+int a = static_cast<int>(foo()); // ---> int a = ...
+// length(int * * ) = 5
+int **pa = static_cast<int**>(foo()); // ---> auto pa = ...
+bool b = static_cast<bool>(foo()); // ---> bool b = ...
+bool *pb = static_cast<bool*>(foo()); // ---> auto pb = ...
+unsigned c = static_cast<unsigned>(foo()); // ---> auto c = ...
+long int d = static_cast<long int>(foo()); // ---> auto d = ...
+```
+Default is `5`.
+````
- If the option is set to `true` (default is `false`), the check will remove
- stars from the non-typedef pointer types when replacing type names with
- ``auto``. Otherwise, the check will leave stars. For example:
+(modernize-use-auto-remove-stars)=
-.. code-block:: c++
+````{option} RemoveStars
+If the option is set to `true`, the check will remove
+stars from the non-typedef pointer types when replacing type names with
+`auto`. Otherwise, the check will leave stars. For example:
- TypeName *my_first_pointer = new TypeName, *my_second_pointer = new TypeName;
+```c++
+TypeName *my_first_pointer = new TypeName, *my_second_pointer = new TypeName;
- // RemoveStars = 0
+// RemoveStars = 0
- auto *my_first_pointer = new TypeName, *my_second_pointer = new TypeName;
+auto *my_first_pointer = new TypeName, *my_second_pointer = new TypeName;
- // RemoveStars = 1
+// RemoveStars = 1
- auto my_first_pointer = new TypeName, my_second_pointer = new TypeName;
+auto my_first_pointer = new TypeName, my_second_pointer = new TypeName;
+```
+Default is `false`.
+````
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-constraints.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-constraints.md
index 232cd01dc22d1..93cd864c8de7d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-constraints.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-constraints.md
@@ -1,74 +1,73 @@
-.. title:: clang-tidy - modernize-use-constraints
+```{title} clang-tidy - modernize-use-constraints
+```
-modernize-use-constraints
-=========================
+# modernize-use-constraints
-Replace ``std::enable_if`` with C++20 requires clauses.
+Replace `std::enable_if` with C++20 requires clauses.
-``std::enable_if`` is a SFINAE mechanism for selecting the desired function or
-class template based on type traits or other requirements. ``enable_if``
+`std::enable_if` is a SFINAE mechanism for selecting the desired function or
+class template based on type traits or other requirements. `enable_if`
changes the meta-arity of the template, and has other
-`adverse side effects
-<https://open-std.org/JTC1/SC22/WG21/docs/papers/2016/p0225r0.html>`_
+[adverse side effects](https://open-std.org/JTC1/SC22/WG21/docs/papers/2016/p0225r0.html)
in the code. C++20 introduces concepts and constraints as a cleaner language
provided solution to achieve the same outcome.
-This check finds some common ``std::enable_if`` patterns that can be replaced
+This check finds some common `std::enable_if` patterns that can be replaced
by C++20 requires clauses. The tool can replace some of these patterns
automatically, otherwise, the tool will emit a diagnostic without a
-replacement. The tool can detect the following ``std::enable_if`` patterns
+replacement. The tool can detect the following `std::enable_if` patterns
-1. ``std::enable_if`` in the return type of a function
-2. ``std::enable_if`` as the trailing template parameter for function templates
+1. `std::enable_if` in the return type of a function
+2. `std::enable_if` as the trailing template parameter for function templates
Other uses, for example, in class templates for function parameters, are not
-currently supported by this tool. Other variants such as ``boost::enable_if``
+currently supported by this tool. Other variants such as `boost::enable_if`
are not currently supported by this tool.
-Below are some examples of code using ``std::enable_if``.
+Below are some examples of code using `std::enable_if`.
-.. code-block:: c++
+```c++
+// enable_if in function return type
+template <typename T>
+std::enable_if_t<T::some_trait, int> only_if_t_has_the_trait() { ... }
- // enable_if in function return type
- template <typename T>
- std::enable_if_t<T::some_trait, int> only_if_t_has_the_trait() { ... }
+// enable_if in the trailing template parameter
+template <typename T, std::enable_if_t<T::some_trait, int> = 0>
+void another_version() { ... }
- // enable_if in the trailing template parameter
- template <typename T, std::enable_if_t<T::some_trait, int> = 0>
- void another_version() { ... }
+template <typename T>
+typename std::enable_if<T::some_value, Obj>::type existing_constraint() requires (T::another_value) {
+ return Obj{};
+}
- template <typename T>
- typename std::enable_if<T::some_value, Obj>::type existing_constraint() requires (T::another_value) {
- return Obj{};
- }
-
- template <typename T, std::enable_if_t<T::some_trait, int> = 0>
- struct my_class {};
+template <typename T, std::enable_if_t<T::some_trait, int> = 0>
+struct my_class {};
+```
The tool will replace the above code with,
-.. code-block:: c++
-
- // warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints]
- template <typename T>
- int only_if_t_has_the_trait() requires T::some_trait { ... }
-
- // warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints]
- template <typename T>
- void another_version() requires T::some_trait { ... }
-
- // The tool will emit a diagnostic for the following, but will
- // not attempt to replace the code.
- // warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints]
- template <typename T>
- typename std::enable_if<T::some_value, Obj>::type existing_constraint() requires (T::another_value) {
- return Obj{};
- }
-
- // The tool will not emit a diagnostic or attempt to replace the code.
- template <typename T, std::enable_if_t<T::some_trait, int> = 0>
- struct my_class {};
-
-.. note::
-
- System headers are not analyzed by this check.
+```c++
+// warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints]
+template <typename T>
+int only_if_t_has_the_trait() requires T::some_trait { ... }
+
+// warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints]
+template <typename T>
+void another_version() requires T::some_trait { ... }
+
+// The tool will emit a diagnostic for the following, but will
+// not attempt to replace the code.
+// warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints]
+template <typename T>
+typename std::enable_if<T::some_value, Obj>::type existing_constraint() requires (T::another_value) {
+ return Obj{};
+}
+
+// The tool will not emit a diagnostic or attempt to replace the code.
+template <typename T, std::enable_if_t<T::some_trait, int> = 0>
+struct my_class {};
+```
+
+```{note}
+System headers are not analyzed by this check.
+```
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-default-member-init.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-default-member-init.md
index 08721cac7ab5c..c58161381057f 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-default-member-init.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-default-member-init.md
@@ -1,61 +1,70 @@
-.. title:: clang-tidy - modernize-use-default-member-init
+```{title} clang-tidy - modernize-use-default-member-init
+```
-modernize-use-default-member-init
-=================================
+# modernize-use-default-member-init
This check converts constructors' member initializers into the new
default member initializers in C++11. Other member initializers that match the
default member initializer are removed. This can reduce repeated code or allow
use of '= default'.
-.. code-block:: c++
-
- struct A {
- A() : i(5), j(10.0) {}
- A(int i) : i(i), j(10.0) {}
- int i;
- double j;
- };
-
- // becomes
-
- struct A {
- A() {}
- A(int i) : i(i) {}
- int i{5};
- double j{10.0};
- };
-
-.. note::
- Only converts member initializers for built-in types, enums, and pointers.
- The `readability-redundant-member-init` check will remove redundant member
- initializers for classes.
-
-Options
--------
-
-.. option:: UseAssignment
-
- If this option is set to `true` (default is `false`), the check will initialize
- members with an assignment. For example:
-
-.. code-block:: c++
-
- struct A {
- A() {}
- A(int i) : i(i) {}
- int i = 5;
- double j = 10.0;
- };
-
-.. option:: IgnoreMacros
-
- If this option is set to `true` (default is `true`), the check will not warn
- about members declared inside macros.
-
-.. option:: IgnoreNonVisibleReferences
-
- If this option is set to `true` (default is `true`), the check will not warn
- about member initializers that refer to declarations that would not be
- visible from the default member initializer created by the fix-it. If set to
- `false`, the check will warn about these cases without emitting fix-its.
+```c++
+struct A {
+ A() : i(5), j(10.0) {}
+ A(int i) : i(i), j(10.0) {}
+ int i;
+ double j;
+};
+
+// becomes
+
+struct A {
+ A() {}
+ A(int i) : i(i) {}
+ int i{5};
+ double j{10.0};
+};
+```
+
+```{note}
+Only converts member initializers for built-in types, enums, and pointers.
+The {doc}`readability-redundant-member-init <../readability/redundant-member-init>` check will remove redundant member
+initializers for classes.
+```
+
+## Options
+
+(modernize-use-default-member-init-use-assignment)=
+
+````{option} UseAssignment
+If this option is set to `true`, the check will initialize
+members with an assignment. For example:
+
+```c++
+struct A {
+ A() {}
+ A(int i) : i(i) {}
+ int i = 5;
+ double j = 10.0;
+};
+```
+Default is `false`.
+````
+
+(modernize-use-default-member-init-ignore-macros)=
+
+```{option} IgnoreMacros
+If this option is set to `true`, the check will not warn
+about members declared inside macros.
+Default is `true`.
+```
+
+(modernize-use-default-member-init-ignore-non-visible-references)=
+
+```{option} IgnoreNonVisibleReferences
+If this option is set to `true`, the check will not warn
+about member initializers that refer to declarations that would not be
+visible from the default member initializer created by the fix-it. If set to
+`false`, the check will warn about these cases without emitting fix-its.
+Default is `true`.
+```
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.md
index 1b8c9c39c0e03..7577ebcc35805 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.md
@@ -1,7 +1,7 @@
-.. title:: clang-tidy - modernize-use-designated-initializers
+```{title} clang-tidy - modernize-use-designated-initializers
+```
-modernize-use-designated-initializers
-=====================================
+# modernize-use-designated-initializers
Finds initializer lists for aggregate types which could be written as
designated initializers instead.
@@ -16,24 +16,24 @@ because every variable being initialized is referenced by its name.
Example:
-.. code-block::
-
- struct S { int i, j; };
+```
+struct S { int i, j; };
+```
is an aggregate type that should be initialized as
-.. code-block::
-
- S s{.i = 1, .j = 2};
+```
+S s{.i = 1, .j = 2};
+```
instead of
-.. code-block::
-
- S s{1, 2};
+```
+S s{1, 2};
+```
-which could easily become an issue when ``i`` and ``j`` are swapped in the
-declaration of ``S``.
+which could easily become an issue when `i` and `j` are swapped in the
+declaration of `S`.
Even when compiling in a language version older than C++20, depending on your
compiler, designated initializers are potentially supported. Therefore, the
@@ -42,34 +42,43 @@ check is by default restricted to C99/C++20 and above. Check out the options
in C and `-Wc++20-designator` for support of designated initializers in older
C++ language modes.
-Options
--------
+## Options
-.. option:: IgnoreMacros
+(modernize-use-designated-initializers-ignore-macros)=
- The value `false` specifies that components of initializer lists expanded from
- macros are not checked. The default value is `true`.
+```{option} IgnoreMacros
+The value `false` specifies that components of initializer lists expanded from
+macros are not checked. Default is `true`.
+```
-.. option:: IgnoreSingleElementAggregates
+(modernize-use-designated-initializers-ignore-single-element-aggregates)=
- The value `false` specifies that even initializers for aggregate types with
- only a single element should be checked. The default value is `true`.
- ``std::array`` initializations are always excluded, as the type is a
- standard library abstraction and not intended to be initialized with
- designated initializers.
+```{option} IgnoreSingleElementAggregates
+The value `false` specifies that even initializers for aggregate types with
+only a single element should be checked.
+`std::array` initializations are always excluded, as the type is a
+standard library abstraction and not intended to be initialized with
+designated initializers.
+Default is `true`.
+```
-.. option:: RestrictToPODTypes
+(modernize-use-designated-initializers-restrict-to-pod-types)=
- The value `true` specifies that only Plain Old Data (POD) types shall be
- checked. This makes the check applicable to even older C++ standards. The
- default value is `false`.
+```{option} RestrictToPODTypes
+The value `true` specifies that only Plain Old Data (POD) types shall be
+checked. This makes the check applicable to even older C++ standards. Default is `false`.
+```
-.. option:: StrictCStandardCompliance
+(modernize-use-designated-initializers-strict-c-standard-compliance)=
- When set to `false`, the check will not restrict itself to C99 and above.
- The default value is `true`.
+```{option} StrictCStandardCompliance
+When set to `false`, the check will not restrict itself to C99 and above.
+Default is `true`.
+```
-.. option:: StrictCppStandardCompliance
+(modernize-use-designated-initializers-strict-cpp-standard-compliance)=
- When set to `false`, the check will not restrict itself to C++20 and above.
- The default value is `true`.
+```{option} StrictCppStandardCompliance
+When set to `false`, the check will not restrict itself to C++20 and above.
+Default is `true`.
+```
>From 848dbc843659657f3be3eb1bf5dda45b8c3a09ed Mon Sep 17 00:00:00 2001
From: Zeyi Xu <mitchell.xu2 at gmail.com>
Date: Wed, 11 Nov 2026 14:05:48 +0800
Subject: [PATCH 2/2] ~
---
.../docs/clang-tidy/checks/modernize/pass-by-value.md | 6 ------
.../clang-tidy/checks/modernize/raw-string-literal.md | 4 ----
.../clang-tidy/checks/modernize/replace-auto-ptr.md | 4 +---
.../replace-disallow-copy-and-assign-macro.md | 4 +---
.../docs/clang-tidy/checks/modernize/type-traits.md | 2 --
.../docs/clang-tidy/checks/modernize/use-auto.md | 6 +-----
.../checks/modernize/use-default-member-init.md | 6 ------
.../checks/modernize/use-designated-initializers.md | 10 ----------
8 files changed, 3 insertions(+), 39 deletions(-)
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/pass-by-value.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/pass-by-value.md
index d09cf81282a69..7567c04ac39e0 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/pass-by-value.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/pass-by-value.md
@@ -143,21 +143,15 @@ For more information about the pass-by-value idiom, read: [Want Speed? Pass by V
## Options
-(modernize-pass-by-value-include-style)=
-
```{option} IncludeStyle
A string specifying which include-style is used, `llvm` or `google`. Default is `llvm`.
```
-(modernize-pass-by-value-values-only)=
-
```{option} ValuesOnly
When `true`, the check only warns about copied parameters that are already
passed by value. Default is `false`.
```
-(modernize-pass-by-value-ignore-macros)=
-
```{option} IgnoreMacros
When `true`, the check will not give warnings inside macros. Default is
`false`.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.md
index 23174a7a2e9f4..b03f207d8a75b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.md
@@ -47,16 +47,12 @@ vertical tab in source code is not visually obvious.
## Options
-(modernize-raw-string-literal-delimiter-stem)=
-
```{option} DelimiterStem
Custom delimiter to escape characters in raw string literals. It is used in
the following construction: `R"stem_delimiter(contents)stem_delimiter"`.
Default is `lit`.
```
-(modernize-raw-string-literal-replace-shorter-literals)=
-
```{option} ReplaceShorterLiterals
Controls replacing shorter non-raw string literals with longer raw string
literals. Setting this option to `true` enables the replacement.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-auto-ptr.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-auto-ptr.md
index 27e4e68b1d681..b2fd1b79c57b3 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-auto-ptr.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-auto-ptr.md
@@ -3,7 +3,7 @@
# modernize-replace-auto-ptr
-This check replaces the uses of the deprecated class `std::auto_ptr` by
+Replaces the uses of the deprecated class `std::auto_ptr` by
`std::unique_ptr` (introduced in C++11). The transfer of ownership, done
by the copy-constructor and the assignment operator, is changed to match
`std::unique_ptr` usage by using explicit calls to `std::move()`.
@@ -71,8 +71,6 @@ void f() {
## Options
-(modernize-replace-auto-ptr-include-style)=
-
```{option} IncludeStyle
A string specifying which include-style is used, `llvm` or `google`. Default is `llvm`.
```
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-disallow-copy-and-assign-macro.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-disallow-copy-and-assign-macro.md
index ec0b17778ad48..6f40b05f2f36e 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-disallow-copy-and-assign-macro.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-disallow-copy-and-assign-macro.md
@@ -37,13 +37,11 @@ private:
- Notice that the migration example above leaves the `private` access
specification untouched. You might want to run the check
- {doc}`modernize-use-equals-delete <../modernize/use-equals-delete>`
+ {doc}`modernize-use-equals-delete <use-equals-delete>`
to get warnings for deleted functions in private sections.
## Options
-(modernize-replace-disallow-copy-and-assign-macro-macro-name)=
-
```{option} MacroName
A string specifying the macro name whose expansion will be replaced.
Default is `DISALLOW_COPY_AND_ASSIGN`.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.md
index 5c2abd5b1460a..d0c0013cc1224 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.md
@@ -34,8 +34,6 @@ std::remove_cvref_t<int>
## Options
-(modernize-type-traits-ignore-macros)=
-
````{option} IgnoreMacros
If `true` don't diagnose traits defined in macros.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-auto.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-auto.md
index c309d91dcc895..87d520bebbfec 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-auto.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-auto.md
@@ -171,14 +171,12 @@ function returns that type, or a pointer or reference to it.
## Options
-(modernize-use-auto-min-type-name-length)=
-
````{option} MinTypeNameLength
If the option is set to non-zero, the check will ignore type
names having a length less than the option value. The option affects
expressions only, not iterators.
Spaces between multi-lexeme type names (`long int`) are considered as one.
-If the [`RemoveStars`](#modernize-use-auto-remove-stars) option (see below) is set to `true`, then `*s`
+If the {option}`RemoveStars` option (see below) is set to `true`, then `*s`
in the type are also counted as a part of the type name.
```c++
@@ -211,8 +209,6 @@ long int d = static_cast<long int>(foo()); // ---> auto d = ...
Default is `5`.
````
-(modernize-use-auto-remove-stars)=
-
````{option} RemoveStars
If the option is set to `true`, the check will remove
stars from the non-typedef pointer types when replacing type names with
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-default-member-init.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-default-member-init.md
index c58161381057f..43feebef03131 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-default-member-init.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-default-member-init.md
@@ -34,8 +34,6 @@ initializers for classes.
## Options
-(modernize-use-default-member-init-use-assignment)=
-
````{option} UseAssignment
If this option is set to `true`, the check will initialize
members with an assignment. For example:
@@ -51,16 +49,12 @@ struct A {
Default is `false`.
````
-(modernize-use-default-member-init-ignore-macros)=
-
```{option} IgnoreMacros
If this option is set to `true`, the check will not warn
about members declared inside macros.
Default is `true`.
```
-(modernize-use-default-member-init-ignore-non-visible-references)=
-
```{option} IgnoreNonVisibleReferences
If this option is set to `true`, the check will not warn
about member initializers that refer to declarations that would not be
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.md b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.md
index 7577ebcc35805..5b6402a092c35 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.md
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.md
@@ -44,15 +44,11 @@ C++ language modes.
## Options
-(modernize-use-designated-initializers-ignore-macros)=
-
```{option} IgnoreMacros
The value `false` specifies that components of initializer lists expanded from
macros are not checked. Default is `true`.
```
-(modernize-use-designated-initializers-ignore-single-element-aggregates)=
-
```{option} IgnoreSingleElementAggregates
The value `false` specifies that even initializers for aggregate types with
only a single element should be checked.
@@ -62,22 +58,16 @@ designated initializers.
Default is `true`.
```
-(modernize-use-designated-initializers-restrict-to-pod-types)=
-
```{option} RestrictToPODTypes
The value `true` specifies that only Plain Old Data (POD) types shall be
checked. This makes the check applicable to even older C++ standards. Default is `false`.
```
-(modernize-use-designated-initializers-strict-c-standard-compliance)=
-
```{option} StrictCStandardCompliance
When set to `false`, the check will not restrict itself to C99 and above.
Default is `true`.
```
-(modernize-use-designated-initializers-strict-cpp-standard-compliance)=
-
```{option} StrictCppStandardCompliance
When set to `false`, the check will not restrict itself to C++20 and above.
Default is `true`.
More information about the cfe-commits
mailing list