0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

clang-tidy の modernize

0
Posted at

1. Variables & Types (変数と型)

  • modernize-use-auto

  • EN: Uses auto for variable declarations where the type is already explicitly stated or obvious (e.g., iterators, new).

  • JP: 型が明白または右辺で明示されている変数の宣言に auto を使用します(例: イテレータ、newによる割り当て)。

  • modernize-use-bool-literals

  • EN: Replaces integer literals (0, 1) with boolean literals (false, true) for bool types.

  • JP: bool 型に対して、整数リテラル (0, 1) を真偽値リテラル (false, true) に置き換えます。

  • modernize-use-using

  • EN: Replaces old-style C typedef with C++11 using aliases.

  • JP: 従来の C 言語スタイルの typedef を C++11 の using エイリアスに置き換えます。

  • modernize-use-trailing-return-type

  • EN: Rewrites function signatures to use C++11 trailing return types (e.g., auto func() -> int;). Note: Many codebases disable this as it is a stylistic choice.

  • JP: 関数のシグネチャを C++11 の後置戻り値型 (auto func() -> int; の形式) を使用するように書き換えます。※好みが分かれるため無効にされることが多いです。

  • modernize-type-traits

  • EN: Replaces typename std::...::type or std::...::value with C++14/17 variable and alias templates (std::..._t and std::..._v).

  • JP: 従来の型特性(traits)を C++14/17 のエイリアス/変数テンプレート (_t_v) に置き換えます。

2. Classes & Objects (クラスとオブジェクト)

  • modernize-use-default-member-init

  • EN: Converts constructor initializers to C++11 in-class default member initializers.

  • JP: コンストラクタでの初期化を、C++11 のクラス内デフォルトメンバー初期化に変換します。

  • modernize-use-equals-default

  • EN: Uses = default instead of empty default constructors, destructors, or copy/move operators.

  • JP: 空のデフォルトコンストラクタやデストラクタなどの代わりに = default を使用します。

  • modernize-use-equals-delete

  • EN: Uses = delete instead of unimplemented private special member functions to prevent copying.

  • JP: コピーを禁止するために未実装の private 関数を用意する古い手法の代わりに、 = delete を使用します。

  • modernize-use-override

  • EN: Adds the override specifier to overriding virtual functions to ensure compile-time safety.

  • JP: オーバーライドする仮想関数に override 指定子を追加し、コンパイル時の安全性を高めます。

  • modernize-use-designated-initializers (Newer)

  • EN: Uses C++20 designated initializers ({.x = 1, .y = 2}) for struct initialization.

  • JP: 構造体の初期化に C++20 の指示初期化子 (designated initializers: {.x = 1, .y = 2}) を使用します。

  • modernize-return-braced-init-list

  • EN: Replaces explicit type construction in return statements with braced initializer lists {}.

  • JP: return 文での明示的な型の構築を、波括弧による初期化リスト {} に置き換えます。

3. Memory & Pointers (メモリとポインタ)

  • modernize-use-nullptr

  • EN: Replaces C-style NULL or 0 pointers with C++11 nullptr.

  • JP: C言語スタイルの NULL0 ポインタを C++11 の nullptr に置き換えます。

  • modernize-make-shared

  • EN: Replaces std::shared_ptr creation via new with the safer and more efficient std::make_shared.

  • JP: new を使った std::shared_ptr の作成を、安全で効率的な std::make_shared に置き換えます。

  • modernize-make-unique

  • EN: Replaces std::unique_ptr creation via new with std::make_unique (C++14).

  • JP: new を使った std::unique_ptr の作成を、std::make_unique (C++14) に置き換えます。

  • modernize-replace-auto-ptr

  • EN: Replaces the deprecated (and removed) std::auto_ptr with std::unique_ptr.

  • JP: 非推奨(現在は削除済み)の std::auto_ptrstd::unique_ptr に置き換えます。

4. Loops, Algorithms & STL (ループ・アルゴリズム・STL)

  • modernize-loop-convert

  • EN: Converts traditional for (int i = 0; ...) and iterator loops to C++11 range-based for loops.

  • JP: 従来のインデックスやイテレータを使った for ループを、C++11 の範囲ベース (range-based) for ループに変換します。

  • modernize-avoid-bind

  • EN: Replaces std::bind with C++14 lambda expressions for better readability and performance.

  • JP: 読みやすさとパフォーマンス向上のため、std::bind を C++14 のラムダ式に置き換えます。

  • modernize-avoid-c-arrays

  • EN: Replaces C-style arrays (int arr[10]) with std::array or std::vector.

  • JP: C言語スタイルの配列 (int arr[10]) を std::arraystd::vector に置き換えます。

  • modernize-use-emplace

  • EN: Replaces push_back/insert with emplace_back/emplace where it avoids unnecessary temporary object creation.

  • JP: 不要な一時オブジェクトの作成を避けられる場合、push_backinsertemplace_backemplace に置き換えます。

  • modernize-shrink-to-fit

  • EN: Replaces the old "copy-and-swap" trick used to clear capacity with std::vector::shrink_to_fit().

  • JP: メモリ解放のための古い「コピー&スワップ」テクニックを std::vector::shrink_to_fit() に置き換えます。

  • modernize-replace-random-shuffle

  • EN: Replaces deprecated std::random_shuffle with C++11 std::shuffle.

  • JP: 非推奨の std::random_shuffle を C++11 の std::shuffle に置き換えます。

  • modernize-use-transparent-functors

  • EN: Prefers transparent functors (e.g., std::less<>) over explicitly typed ones (std::less<int>).

  • JP: 明示的に型指定された関数オブジェクト (std::less<int>) より、透過的な関数オブジェクト (std::less<>) を優先します。

5. String Formatting & Output (文字列・出力)

  • modernize-raw-string-literal

  • EN: Converts heavily escaped string literals into C++11 raw string literals (R"(...)").

  • JP: エスケープ文字が多い文字列リテラルを、C++11 の生文字列 (raw string) リテラル (R"(...)") に変換します。

  • modernize-use-starts-ends-with (C++20)

  • EN: Replaces verbose find or compare methods with C++20 starts_with and ends_with.

  • JP: 冗長な findcompare メソッドを C++20 の starts_with および ends_with に置き換えます。

  • modernize-use-std-format (C++20)

  • EN: Converts old string formatting logic (like absl::StrFormat) to C++20 std::format.

  • JP: 古い文字列フォーマットを C++20 の std::format に変換します。

  • modernize-use-std-print (C++23)

  • EN: Replaces C-style printf with C++23 std::print.

  • JP: C言語スタイルの printf を C++23 の std::print に置き換えます。

6. Macros & Preprocessor (マクロ・プリプロセッサ)

  • modernize-macro-to-enum

  • EN: Replaces groups of adjacent integer macros (#define A 1, #define B 2) with C++11 scoped enums (enum class).

  • JP: 隣接する整数のマクログループ (#define A 1など) を C++11 のスコープ付き列挙型 (enum class) に置き換えます。

  • modernize-replace-disallow-copy-and-assign-macro

  • EN: Replaces old Google-style DISALLOW_COPY_AND_ASSIGN macros with explicitly deleted special member functions.

  • JP: 古い Google スタイルの DISALLOW_COPY_AND_ASSIGN マクロを、明示的に delete された特殊メンバー関数に置き換えます。

  • modernize-deprecated-headers

  • EN: Replaces C standard library headers (e.g., <math.h>, <stdio.h>) with their C++ equivalents (<cmath>, <cstdio>).

  • JP: C言語の標準ライブラリヘッダ (<math.h>, <stdio.h>など) を C++ 用のヘッダ (<cmath>, <cstdio>) に置き換えます。

7. Modern C++ Features & Attributes (モダン機能・属性)

  • modernize-concat-nested-namespaces

  • EN: Replaces nested namespaces (namespace A { namespace B {) with C++17 concise syntax (namespace A::B {).

  • JP: ネストされた名前空間 (namespace A { namespace B {) を C++17 の簡潔な構文 (namespace A::B {) に置き換えます。

  • modernize-use-nodiscard

  • EN: Adds the [[nodiscard]] attribute to functions that return values representing state, errors, or allocated memory.

  • JP: 状態、エラー、または割り当てられたメモリを返す関数(無視すべきでない戻り値)に [[nodiscard]] 属性を追加します。

  • modernize-use-noexcept

  • EN: Replaces deprecated throw() exception specifications with the C++11 noexcept specifier.

  • JP: 非推奨の throw() 例外指定を C++11 の noexcept 指定子に置き換えます。

  • modernize-use-uncaught-exceptions

  • EN: Replaces the deprecated std::uncaught_exception() with C++17 std::uncaught_exceptions().

  • JP: 非推奨の std::uncaught_exception() を C++17 の std::uncaught_exceptions() (複数形) に置き換えます。

  • modernize-use-constraints (C++20)

  • EN: Replaces SFINAE (std::enable_if) with C++20 requires clauses (Concepts).

  • JP: SFINAE (std::enable_ifなど) を C++20 の requires 句 (コンセプト) に置き換えます。

  • modernize-use-std-numbers (C++20)

  • EN: Replaces math constant macros (like M_PI) with C++20 <numbers> library constants (like std::numbers::pi).

  • JP: 数学定数のマクロ (M_PI など) を C++20 の <numbers> ライブラリ定数 (std::numbers::pi など) に置き換えます。

8. Miscellaneous (その他)

  • modernize-pass-by-value

  • EN: Suggests replacing const-reference parameters with pass-by-value and std::move when the parameter is unconditionally copied inside the function.

  • JP: 関数内で必ずコピーされるパラメータに対し、const参照渡しではなく値渡しと std::move を使用するように提案します。

  • modernize-redundant-void-arg

  • EN: Removes redundant void from C-style function declarations without parameters (int f(void) -> int f()).

  • JP: 引数のない関数の宣言から、C言語スタイルの不要な void を削除します (int f(void) -> int f())。

  • modernize-unary-static-assert

  • EN: Removes the redundant empty string message from C++17 single-argument static_assert.

  • JP: C++17 の単一引数 static_assert から、不要な空のメッセージ文字列 "" を削除します。

  • modernize-min-max-use-initializer-list

  • EN: Replaces nested std::min or std::max calls with a single call using an initializer list (e.g., std::max({a, b, c})).

  • JP: ネストされた std::minstd::max の呼び出しを、初期化子リストを使用した単一の呼び出し(例:std::max({a, b, c}))に置き換えます。

  • modernize-deprecated-ios-base-aliases

  • EN: Replaces deprecated std::ios_base aliases (like std::ios_base::io_state) with newer, standard ones.

  • JP: 非推奨の std::ios_base 関連の型エイリアスを標準の新しいものに置き換えます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?