38 lines · plain
1.. title:: clang-tidy - readability-redundant-casting2 3readability-redundant-casting4=============================5 6Detects explicit type casting operations that involve the same source and7destination types, and subsequently recommend their removal. Covers a range of8explicit casting operations, including ``static_cast``, ``const_cast``, C-style9casts, and ``reinterpret_cast``. Its primary objective is to enhance code10readability and maintainability by eliminating unnecessary type casting.11 12.. code-block:: c++13 14 int value = 42;15 int result = static_cast<int>(value);16 17In this example, the ``static_cast<int>(value)`` is redundant, as it performs18a cast from an ``int`` to another ``int``.19 20Casting operations involving constructor conversions, user-defined conversions,21functional casts, type-dependent casts, casts between distinct type aliases22that refer to the same underlying type, as well as bitfield-related casts and23casts directly from lvalue to rvalue, are all disregarded by the check.24 25Options26-------27 28.. option:: IgnoreMacros29 30 If set to `true`, the check will not give warnings inside macros. Default31 is `true`.32 33.. option:: IgnoreTypeAliases34 35 When set to `false`, the check will consider type aliases, and when set to36 `true`, it will resolve all type aliases and operate on the underlying37 types. Default is `false`.38