c++automated-refactoringclang-tidy

Which clang-tidy checks provide automated fixes?


I'd like to find out which of the clang-tidy checks are possible to run with the -fix option, i.e. automatically generate fixed code. I know all the modernize-* checks can do this and some other checks can too (like google-readability-casting) but nowhere did I find a complete list. Is there a list somewhere? Or a method to find out other than reading the source of each and every check?


Solution

  • EDIT: Since clang-tidy 10 the fix option is included in the list of checks in the documentation.

    The rest of my answer is still valid for versions 9 and lower.


    grep --include=\*.cpp -rc './' -e "FixItHint"|grep -v ':0$' > FixItChecks.txt

    I ran this grep command in the clang-tidy source directory. It counts the number of occurences of "FixItHint" string in all .cpp files and filters out files with zero occurences.

    clang::FixItHint is a class that (according to documentation):

    Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the problem.

    I admit the method to obtain the list is somewhat crude however I did check multiple files and the results seem to be correct.

    The cleaned-up and sorted list of checks with fixes:

    abseil/StringFindStartswithCheck
    android/CloexecCheck
    boost/UseToStringCheck
    bugprone/ArgumentCommentCheck
    bugprone/BoolPointerImplicitConversionCheck
    bugprone/CopyConstructorInitCheck
    bugprone/InaccurateEraseCheck
    bugprone/MacroParenthesesCheck
    bugprone/MisplacedOperatorInStrlenInAllocCheck
    bugprone/MoveForwardingReferenceCheck
    bugprone/ParentVirtualCallCheck
    bugprone/StringIntegerAssignmentCheck
    bugprone/SuspiciousMemsetUsageCheck
    bugprone/SuspiciousSemicolonCheck
    bugprone/SuspiciousStringCompareCheck
    bugprone/UnusedRaiiCheck
    bugprone/VirtualNearMissCheck
    cert/PostfixOperatorCheck
    cppcoreguidelines/ProBoundsConstantArrayIndexCheck
    cppcoreguidelines/ProTypeCstyleCastCheck
    cppcoreguidelines/ProTypeMemberInitCheck
    cppcoreguidelines/ProTypeStaticCastDowncastCheck
    fuchsia/DefaultArgumentsCheck
    fuchsia/RestrictSystemIncludesCheck
    google/AvoidCStyleCastsCheck
    google/ExplicitConstructorCheck
    google/ExplicitMakePairCheck
    google/GlobalVariableDeclarationCheck
    google/TodoCommentCheck
    llvm/IncludeOrderCheck
    llvm/TwineLocalCheck
    misc/DefinitionsInHeadersCheck
    misc/RedundantExpressionCheck
    misc/StaticAssertCheck
    misc/UniqueptrResetReleaseCheck
    misc/UnusedAliasDeclsCheck
    misc/UnusedParametersCheck
    misc/UnusedUsingDeclsCheck
    modernize/AvoidBindCheck
    modernize/DeprecatedHeadersCheck
    modernize/LoopConvertCheck
    modernize/MakeSmartPtrCheck
    modernize/PassByValueCheck
    modernize/RawStringLiteralCheck
    modernize/RedundantVoidArgCheck
    modernize/ReplaceAutoPtrCheck
    modernize/ReplaceRandomShuffleCheck
    modernize/ReturnBracedInitListCheck
    modernize/ShrinkToFitCheck
    modernize/UnaryStaticAssertCheck
    modernize/UseAutoCheck
    modernize/UseBoolLiteralsCheck
    modernize/UseDefaultMemberInitCheck
    modernize/UseEmplaceCheck
    modernize/UseEqualsDefaultCheck
    modernize/UseEqualsDeleteCheck
    modernize/UseNoexceptCheck
    modernize/UseNullptrCheck
    modernize/UseOverrideCheck
    modernize/UseTransparentFunctorsCheck
    modernize/UseUncaughtExceptionsCheck
    modernize/UseUsingCheck
    objc/PropertyDeclarationCheck
    performance/FasterStringFindCheck
    performance/ForRangeCopyCheck
    performance/InefficientAlgorithmCheck
    performance/InefficientVectorOperationCheck
    performance/MoveConstArgCheck
    performance/TypePromotionInMathFnCheck
    performance/UnnecessaryCopyInitialization
    performance/UnnecessaryValueParamCheck
    readability/AvoidConstParamsInDecls
    readability/BracesAroundStatementsCheck
    readability/ContainerSizeEmptyCheck
    readability/DeleteNullPointerCheck
    readability/IdentifierNamingCheck
    readability/ImplicitBoolConversionCheck
    readability/InconsistentDeclarationParameterNameCheck
    readability/MisplacedArrayIndexCheck
    readability/NamedParameterCheck
    readability/NamespaceCommentCheck
    readability/NonConstParameterCheck
    readability/RedundantControlFlowCheck
    readability/RedundantDeclarationCheck
    readability/RedundantFunctionPtrDereferenceCheck
    readability/RedundantMemberInitCheck
    readability/RedundantSmartptrGetCheck
    readability/RedundantStringCStrCheck
    readability/RedundantStringInitCheck
    readability/SimplifyBooleanExprCheck
    readability/SimplifySubscriptExprCheck
    readability/StaticAccessedThroughInstanceCheck
    readability/StaticDefinitionInAnonymousNamespaceCheck
    readability/StringCompareCheck
    readability/UniqueptrDeleteReleaseCheck