├── .arcconfig ├── .gitignore ├── CMakeLists.txt ├── CODE_OWNERS.TXT ├── LICENSE.TXT ├── README.txt ├── SECURITY.md ├── clang-apply-replacements ├── CMakeLists.txt ├── include │ └── clang-apply-replacements │ │ └── Tooling │ │ └── ApplyReplacements.h ├── lib │ └── Tooling │ │ └── ApplyReplacements.cpp └── tool │ ├── CMakeLists.txt │ └── ClangApplyReplacementsMain.cpp ├── clang-query ├── CMakeLists.txt ├── Query.cpp ├── Query.h ├── QueryParser.cpp ├── QueryParser.h ├── QuerySession.h └── tool │ ├── CMakeLists.txt │ └── ClangQuery.cpp ├── clang-rename ├── CMakeLists.txt ├── RenamingAction.cpp ├── RenamingAction.h ├── USRFinder.cpp ├── USRFinder.h ├── USRFindingAction.cpp ├── USRFindingAction.h ├── USRLocFinder.cpp ├── USRLocFinder.h └── tool │ ├── CMakeLists.txt │ └── ClangRename.cpp ├── clang-tidy ├── CMakeLists.txt ├── ClangTidy.cpp ├── ClangTidy.h ├── ClangTidyDiagnosticConsumer.cpp ├── ClangTidyDiagnosticConsumer.h ├── ClangTidyModule.cpp ├── ClangTidyModule.h ├── ClangTidyModuleRegistry.h ├── ClangTidyOptions.cpp ├── ClangTidyOptions.h ├── add_new_check.py ├── boost │ ├── BoostTidyModule.cpp │ ├── CMakeLists.txt │ ├── UseToStringCheck.cpp │ └── UseToStringCheck.h ├── cert │ ├── CERTTidyModule.cpp │ ├── CMakeLists.txt │ ├── CommandProcessorCheck.cpp │ ├── CommandProcessorCheck.h │ ├── FloatLoopCounter.cpp │ ├── FloatLoopCounter.h │ ├── LICENSE.TXT │ ├── SetLongJmpCheck.cpp │ ├── SetLongJmpCheck.h │ ├── StaticObjectExceptionCheck.cpp │ ├── StaticObjectExceptionCheck.h │ ├── StrToNumCheck.cpp │ ├── StrToNumCheck.h │ ├── ThrownExceptionTypeCheck.cpp │ ├── ThrownExceptionTypeCheck.h │ ├── VariadicFunctionDefCheck.cpp │ └── VariadicFunctionDefCheck.h ├── cppcoreguidelines │ ├── CMakeLists.txt │ ├── CppCoreGuidelinesTidyModule.cpp │ ├── InterfacesGlobalInitCheck.cpp │ ├── InterfacesGlobalInitCheck.h │ ├── ProBoundsArrayToPointerDecayCheck.cpp │ ├── ProBoundsArrayToPointerDecayCheck.h │ ├── ProBoundsConstantArrayIndexCheck.cpp │ ├── ProBoundsConstantArrayIndexCheck.h │ ├── ProBoundsPointerArithmeticCheck.cpp │ ├── ProBoundsPointerArithmeticCheck.h │ ├── ProTypeConstCastCheck.cpp │ ├── ProTypeConstCastCheck.h │ ├── ProTypeCstyleCastCheck.cpp │ ├── ProTypeCstyleCastCheck.h │ ├── ProTypeMemberInitCheck.cpp │ ├── ProTypeMemberInitCheck.h │ ├── ProTypeReinterpretCastCheck.cpp │ ├── ProTypeReinterpretCastCheck.h │ ├── ProTypeStaticCastDowncastCheck.cpp │ ├── ProTypeStaticCastDowncastCheck.h │ ├── ProTypeUnionAccessCheck.cpp │ ├── ProTypeUnionAccessCheck.h │ ├── ProTypeVarargCheck.cpp │ └── ProTypeVarargCheck.h ├── google │ ├── AvoidCStyleCastsCheck.cpp │ ├── AvoidCStyleCastsCheck.h │ ├── CMakeLists.txt │ ├── DefaultArgumentsCheck.cpp │ ├── DefaultArgumentsCheck.h │ ├── ExplicitConstructorCheck.cpp │ ├── ExplicitConstructorCheck.h │ ├── ExplicitMakePairCheck.cpp │ ├── ExplicitMakePairCheck.h │ ├── GlobalNamesInHeadersCheck.cpp │ ├── GlobalNamesInHeadersCheck.h │ ├── GoogleTidyModule.cpp │ ├── IntegerTypesCheck.cpp │ ├── IntegerTypesCheck.h │ ├── MemsetZeroLengthCheck.cpp │ ├── MemsetZeroLengthCheck.h │ ├── NonConstReferences.cpp │ ├── NonConstReferences.h │ ├── OverloadedUnaryAndCheck.cpp │ ├── OverloadedUnaryAndCheck.h │ ├── StringReferenceMemberCheck.cpp │ ├── StringReferenceMemberCheck.h │ ├── TodoCommentCheck.cpp │ ├── TodoCommentCheck.h │ ├── UnnamedNamespaceInHeaderCheck.cpp │ ├── UnnamedNamespaceInHeaderCheck.h │ ├── UsingNamespaceDirectiveCheck.cpp │ └── UsingNamespaceDirectiveCheck.h ├── llvm │ ├── CMakeLists.txt │ ├── HeaderGuardCheck.cpp │ ├── HeaderGuardCheck.h │ ├── IncludeOrderCheck.cpp │ ├── IncludeOrderCheck.h │ ├── LLVMTidyModule.cpp │ ├── TwineLocalCheck.cpp │ └── TwineLocalCheck.h ├── misc │ ├── ArgumentCommentCheck.cpp │ ├── ArgumentCommentCheck.h │ ├── AssertSideEffectCheck.cpp │ ├── AssertSideEffectCheck.h │ ├── BoolPointerImplicitConversionCheck.cpp │ ├── BoolPointerImplicitConversionCheck.h │ ├── CMakeLists.txt │ ├── DanglingHandleCheck.cpp │ ├── DanglingHandleCheck.h │ ├── DefinitionsInHeadersCheck.cpp │ ├── DefinitionsInHeadersCheck.h │ ├── FoldInitTypeCheck.cpp │ ├── FoldInitTypeCheck.h │ ├── ForwardDeclarationNamespaceCheck.cpp │ ├── ForwardDeclarationNamespaceCheck.h │ ├── InaccurateEraseCheck.cpp │ ├── InaccurateEraseCheck.h │ ├── IncorrectRoundings.cpp │ ├── IncorrectRoundings.h │ ├── InefficientAlgorithmCheck.cpp │ ├── InefficientAlgorithmCheck.h │ ├── MacroParenthesesCheck.cpp │ ├── MacroParenthesesCheck.h │ ├── MacroRepeatedSideEffectsCheck.cpp │ ├── MacroRepeatedSideEffectsCheck.h │ ├── MiscTidyModule.cpp │ ├── MisplacedWideningCastCheck.cpp │ ├── MisplacedWideningCastCheck.h │ ├── MoveConstantArgumentCheck.cpp │ ├── MoveConstantArgumentCheck.h │ ├── MoveConstructorInitCheck.cpp │ ├── MoveConstructorInitCheck.h │ ├── MultipleStatementMacroCheck.cpp │ ├── MultipleStatementMacroCheck.h │ ├── NewDeleteOverloadsCheck.cpp │ ├── NewDeleteOverloadsCheck.h │ ├── NoexceptMoveConstructorCheck.cpp │ ├── NoexceptMoveConstructorCheck.h │ ├── NonCopyableObjects.cpp │ ├── NonCopyableObjects.h │ ├── PointerAndIntegralOperationCheck.cpp │ ├── PointerAndIntegralOperationCheck.h │ ├── RedundantExpressionCheck.cpp │ ├── RedundantExpressionCheck.h │ ├── SizeofContainerCheck.cpp │ ├── SizeofContainerCheck.h │ ├── SizeofExpressionCheck.cpp │ ├── SizeofExpressionCheck.h │ ├── StaticAssertCheck.cpp │ ├── StaticAssertCheck.h │ ├── StringConstructorCheck.cpp │ ├── StringConstructorCheck.h │ ├── StringIntegerAssignmentCheck.cpp │ ├── StringIntegerAssignmentCheck.h │ ├── StringLiteralWithEmbeddedNulCheck.cpp │ ├── StringLiteralWithEmbeddedNulCheck.h │ ├── SuspiciousMissingCommaCheck.cpp │ ├── SuspiciousMissingCommaCheck.h │ ├── SuspiciousSemicolonCheck.cpp │ ├── SuspiciousSemicolonCheck.h │ ├── SuspiciousStringCompareCheck.cpp │ ├── SuspiciousStringCompareCheck.h │ ├── SwappedArgumentsCheck.cpp │ ├── SwappedArgumentsCheck.h │ ├── ThrowByValueCatchByReferenceCheck.cpp │ ├── ThrowByValueCatchByReferenceCheck.h │ ├── UnconventionalAssignOperatorCheck.cpp │ ├── UnconventionalAssignOperatorCheck.h │ ├── UndelegatedConstructor.cpp │ ├── UndelegatedConstructor.h │ ├── UniqueptrResetReleaseCheck.cpp │ ├── UniqueptrResetReleaseCheck.h │ ├── UnusedAliasDeclsCheck.cpp │ ├── UnusedAliasDeclsCheck.h │ ├── UnusedParametersCheck.cpp │ ├── UnusedParametersCheck.h │ ├── UnusedRAIICheck.cpp │ ├── UnusedRAIICheck.h │ ├── UnusedUsingDeclsCheck.cpp │ ├── UnusedUsingDeclsCheck.h │ ├── VirtualNearMissCheck.cpp │ └── VirtualNearMissCheck.h ├── modernize │ ├── AvoidBindCheck.cpp │ ├── AvoidBindCheck.h │ ├── CMakeLists.txt │ ├── DeprecatedHeadersCheck.cpp │ ├── DeprecatedHeadersCheck.h │ ├── LoopConvertCheck.cpp │ ├── LoopConvertCheck.h │ ├── LoopConvertUtils.cpp │ ├── LoopConvertUtils.h │ ├── MakeSharedCheck.cpp │ ├── MakeSharedCheck.h │ ├── MakeSmartPtrCheck.cpp │ ├── MakeSmartPtrCheck.h │ ├── MakeUniqueCheck.cpp │ ├── MakeUniqueCheck.h │ ├── ModernizeTidyModule.cpp │ ├── PassByValueCheck.cpp │ ├── PassByValueCheck.h │ ├── RawStringLiteralCheck.cpp │ ├── RawStringLiteralCheck.h │ ├── RedundantVoidArgCheck.cpp │ ├── RedundantVoidArgCheck.h │ ├── ReplaceAutoPtrCheck.cpp │ ├── ReplaceAutoPtrCheck.h │ ├── ShrinkToFitCheck.cpp │ ├── ShrinkToFitCheck.h │ ├── UseAutoCheck.cpp │ ├── UseAutoCheck.h │ ├── UseBoolLiteralsCheck.cpp │ ├── UseBoolLiteralsCheck.h │ ├── UseDefaultCheck.cpp │ ├── UseDefaultCheck.h │ ├── UseNullptrCheck.cpp │ ├── UseNullptrCheck.h │ ├── UseOverrideCheck.cpp │ └── UseOverrideCheck.h ├── performance │ ├── CMakeLists.txt │ ├── FasterStringFindCheck.cpp │ ├── FasterStringFindCheck.h │ ├── ForRangeCopyCheck.cpp │ ├── ForRangeCopyCheck.h │ ├── ImplicitCastInLoopCheck.cpp │ ├── ImplicitCastInLoopCheck.h │ ├── PerformanceTidyModule.cpp │ ├── UnnecessaryCopyInitialization.cpp │ ├── UnnecessaryCopyInitialization.h │ ├── UnnecessaryValueParamCheck.cpp │ └── UnnecessaryValueParamCheck.h ├── plugin │ ├── CMakeLists.txt │ └── ClangTidyPlugin.cpp ├── readability │ ├── AvoidConstParamsInDecls.cpp │ ├── AvoidConstParamsInDecls.h │ ├── BracesAroundStatementsCheck.cpp │ ├── BracesAroundStatementsCheck.h │ ├── CMakeLists.txt │ ├── ContainerSizeEmptyCheck.cpp │ ├── ContainerSizeEmptyCheck.h │ ├── DeletedDefaultCheck.cpp │ ├── DeletedDefaultCheck.h │ ├── ElseAfterReturnCheck.cpp │ ├── ElseAfterReturnCheck.h │ ├── FunctionSizeCheck.cpp │ ├── FunctionSizeCheck.h │ ├── IdentifierNamingCheck.cpp │ ├── IdentifierNamingCheck.h │ ├── ImplicitBoolCastCheck.cpp │ ├── ImplicitBoolCastCheck.h │ ├── InconsistentDeclarationParameterNameCheck.cpp │ ├── InconsistentDeclarationParameterNameCheck.h │ ├── NamedParameterCheck.cpp │ ├── NamedParameterCheck.h │ ├── NamespaceCommentCheck.cpp │ ├── NamespaceCommentCheck.h │ ├── ReadabilityTidyModule.cpp │ ├── RedundantControlFlowCheck.cpp │ ├── RedundantControlFlowCheck.h │ ├── RedundantSmartptrGetCheck.cpp │ ├── RedundantSmartptrGetCheck.h │ ├── RedundantStringCStrCheck.cpp │ ├── RedundantStringCStrCheck.h │ ├── RedundantStringInitCheck.cpp │ ├── RedundantStringInitCheck.h │ ├── SimplifyBooleanExprCheck.cpp │ ├── SimplifyBooleanExprCheck.h │ ├── StaticDefinitionInAnonymousNamespaceCheck.cpp │ ├── StaticDefinitionInAnonymousNamespaceCheck.h │ ├── UniqueptrDeleteReleaseCheck.cpp │ └── UniqueptrDeleteReleaseCheck.h ├── rename_check.py ├── tool │ ├── CMakeLists.txt │ ├── ClangTidyMain.cpp │ ├── clang-tidy-diff.py │ └── run-clang-tidy.py └── utils │ ├── CMakeLists.txt │ ├── DeclRefExprUtils.cpp │ ├── DeclRefExprUtils.h │ ├── FixItHintUtils.cpp │ ├── FixItHintUtils.h │ ├── HeaderFileExtensionsUtils.cpp │ ├── HeaderFileExtensionsUtils.h │ ├── HeaderGuard.cpp │ ├── HeaderGuard.h │ ├── IncludeInserter.cpp │ ├── IncludeInserter.h │ ├── IncludeSorter.cpp │ ├── IncludeSorter.h │ ├── LexerUtils.cpp │ ├── LexerUtils.h │ ├── Matchers.h │ ├── OptionsUtils.cpp │ ├── OptionsUtils.h │ ├── TypeTraits.cpp │ └── TypeTraits.h ├── docs ├── CMakeLists.txt ├── Doxyfile ├── ModularizeUsage.rst ├── README.txt ├── ReleaseNotes.rst ├── clang-modernize.rst ├── clang-tidy.rst ├── clang-tidy │ ├── checks │ │ ├── boost-use-to-string.rst │ │ ├── cert-dcl03-c.rst │ │ ├── cert-dcl50-cpp.rst │ │ ├── cert-dcl54-cpp.rst │ │ ├── cert-dcl59-cpp.rst │ │ ├── cert-env33-c.rst │ │ ├── cert-err34-c.rst │ │ ├── cert-err52-cpp.rst │ │ ├── cert-err58-cpp.rst │ │ ├── cert-err60-cpp.rst │ │ ├── cert-err61-cpp.rst │ │ ├── cert-fio38-c.rst │ │ ├── cert-flp30-c.rst │ │ ├── cert-oop11-cpp.rst │ │ ├── cppcoreguidelines-interfaces-global-init.rst │ │ ├── cppcoreguidelines-pro-bounds-array-to-pointer-decay.rst │ │ ├── cppcoreguidelines-pro-bounds-constant-array-index.rst │ │ ├── cppcoreguidelines-pro-bounds-pointer-arithmetic.rst │ │ ├── cppcoreguidelines-pro-type-const-cast.rst │ │ ├── cppcoreguidelines-pro-type-cstyle-cast.rst │ │ ├── cppcoreguidelines-pro-type-member-init.rst │ │ ├── cppcoreguidelines-pro-type-reinterpret-cast.rst │ │ ├── cppcoreguidelines-pro-type-static-cast-downcast.rst │ │ ├── cppcoreguidelines-pro-type-union-access.rst │ │ ├── cppcoreguidelines-pro-type-vararg.rst │ │ ├── google-build-explicit-make-pair.rst │ │ ├── google-build-namespaces.rst │ │ ├── google-build-using-namespace.rst │ │ ├── google-default-arguments.rst │ │ ├── google-explicit-constructor.rst │ │ ├── google-global-names-in-headers.rst │ │ ├── google-readability-braces-around-statements.rst │ │ ├── google-readability-casting.rst │ │ ├── google-readability-function-size.rst │ │ ├── google-readability-namespace-comments.rst │ │ ├── google-readability-redundant-smartptr-get.rst │ │ ├── google-readability-todo.rst │ │ ├── google-runtime-int.rst │ │ ├── google-runtime-member-string-references.rst │ │ ├── google-runtime-memset.rst │ │ ├── google-runtime-operator.rst │ │ ├── google-runtime-references.rst │ │ ├── list.rst │ │ ├── llvm-header-guard.rst │ │ ├── llvm-include-order.rst │ │ ├── llvm-namespace-comment.rst │ │ ├── llvm-twine-local.rst │ │ ├── misc-argument-comment.rst │ │ ├── misc-assert-side-effect.rst │ │ ├── misc-bool-pointer-implicit-conversion.rst │ │ ├── misc-dangling-handle.rst │ │ ├── misc-definitions-in-headers.rst │ │ ├── misc-fold-init-type.rst │ │ ├── misc-forward-declaration-namespace.rst │ │ ├── misc-inaccurate-erase.rst │ │ ├── misc-incorrect-roundings.rst │ │ ├── misc-inefficient-algorithm.rst │ │ ├── misc-macro-parentheses.rst │ │ ├── misc-macro-repeated-side-effects.rst │ │ ├── misc-misplaced-widening-cast.rst │ │ ├── misc-move-const-arg.rst │ │ ├── misc-move-constructor-init.rst │ │ ├── misc-multiple-statement-macro.rst │ │ ├── misc-new-delete-overloads.rst │ │ ├── misc-noexcept-move-constructor.rst │ │ ├── misc-non-copyable-objects.rst │ │ ├── misc-pointer-and-integral-operation.rst │ │ ├── misc-redundant-expression.rst │ │ ├── misc-sizeof-container.rst │ │ ├── misc-sizeof-expression.rst │ │ ├── misc-static-assert.rst │ │ ├── misc-string-constructor.rst │ │ ├── misc-string-integer-assignment.rst │ │ ├── misc-string-literal-with-embedded-nul.rst │ │ ├── misc-suspicious-missing-comma.rst │ │ ├── misc-suspicious-semicolon.rst │ │ ├── misc-suspicious-string-compare.rst │ │ ├── misc-swapped-arguments.rst │ │ ├── misc-throw-by-value-catch-by-reference.rst │ │ ├── misc-unconventional-assign-operator.rst │ │ ├── misc-undelegated-constructor.rst │ │ ├── misc-uniqueptr-reset-release.rst │ │ ├── misc-unused-alias-decls.rst │ │ ├── misc-unused-parameters.rst │ │ ├── misc-unused-raii.rst │ │ ├── misc-unused-using-decls.rst │ │ ├── misc-virtual-near-miss.rst │ │ ├── modernize-avoid-bind.rst │ │ ├── modernize-deprecated-headers.rst │ │ ├── modernize-loop-convert.rst │ │ ├── modernize-make-shared.rst │ │ ├── modernize-make-unique.rst │ │ ├── modernize-pass-by-value.rst │ │ ├── modernize-raw-string-literal.rst │ │ ├── modernize-redundant-void-arg.rst │ │ ├── modernize-replace-auto-ptr.rst │ │ ├── modernize-shrink-to-fit.rst │ │ ├── modernize-use-auto.rst │ │ ├── modernize-use-bool-literals.rst │ │ ├── modernize-use-default.rst │ │ ├── modernize-use-nullptr.rst │ │ ├── modernize-use-override.rst │ │ ├── performance-faster-string-find.rst │ │ ├── performance-for-range-copy.rst │ │ ├── performance-implicit-cast-in-loop.rst │ │ ├── performance-unnecessary-copy-initialization.rst │ │ ├── performance-unnecessary-value-param.rst │ │ ├── readability-avoid-const-params-in-decls.rst │ │ ├── readability-braces-around-statements.rst │ │ ├── readability-container-size-empty.rst │ │ ├── readability-deleted-default.rst │ │ ├── readability-else-after-return.rst │ │ ├── readability-function-size.rst │ │ ├── readability-identifier-naming.rst │ │ ├── readability-implicit-bool-cast.rst │ │ ├── readability-inconsistent-declaration-parameter-name.rst │ │ ├── readability-named-parameter.rst │ │ ├── readability-redundant-control-flow.rst │ │ ├── readability-redundant-smartptr-get.rst │ │ ├── readability-redundant-string-cstr.rst │ │ ├── readability-redundant-string-init.rst │ │ ├── readability-simplify-boolean-expr.rst │ │ ├── readability-static-definition-in-anonymous-namespace.rst │ │ └── readability-uniqueptr-delete-release.rst │ ├── index.rst │ └── tools │ │ └── dump_check_docs.py ├── conf.py ├── cpp11-migrate.rst ├── doxygen-mainpage.dox ├── doxygen.cfg.in ├── include-fixer.rst ├── index.rst ├── make.bat ├── modularize.rst └── pp-trace.rst ├── include-fixer ├── CMakeLists.txt ├── InMemorySymbolIndex.cpp ├── InMemorySymbolIndex.h ├── IncludeFixer.cpp ├── IncludeFixer.h ├── SymbolIndex.h ├── SymbolIndexManager.cpp ├── SymbolIndexManager.h ├── YamlSymbolIndex.cpp ├── YamlSymbolIndex.h ├── find-all-symbols │ ├── CMakeLists.txt │ ├── FindAllMacros.cpp │ ├── FindAllMacros.h │ ├── FindAllSymbols.cpp │ ├── FindAllSymbols.h │ ├── FindAllSymbolsAction.cpp │ ├── FindAllSymbolsAction.h │ ├── HeaderMapCollector.cpp │ ├── HeaderMapCollector.h │ ├── PragmaCommentHandler.cpp │ ├── PragmaCommentHandler.h │ ├── STLPostfixHeaderMap.cpp │ ├── STLPostfixHeaderMap.h │ ├── SymbolInfo.cpp │ ├── SymbolInfo.h │ ├── SymbolReporter.h │ └── tool │ │ ├── CMakeLists.txt │ │ ├── FindAllSymbolsMain.cpp │ │ └── run-find-all-symbols.py └── tool │ ├── CMakeLists.txt │ ├── ClangIncludeFixer.cpp │ └── clang-include-fixer.py ├── modularize ├── CMakeLists.txt ├── CoverageChecker.cpp ├── CoverageChecker.h ├── Modularize.cpp ├── Modularize.h ├── ModularizeUtilities.cpp ├── ModularizeUtilities.h ├── ModuleAssistant.cpp ├── PreprocessorTracker.cpp └── PreprocessorTracker.h ├── pp-trace ├── CMakeLists.txt ├── PPCallbacksTracker.cpp ├── PPCallbacksTracker.h └── PPTrace.cpp ├── test ├── .clang-format ├── CMakeLists.txt ├── Unit │ ├── lit.cfg │ └── lit.site.cfg.in ├── clang-apply-replacements │ ├── Inputs │ │ ├── basic │ │ │ ├── basic.h │ │ │ ├── file1.yaml │ │ │ └── file2.yaml │ │ ├── conflict │ │ │ ├── common.h │ │ │ ├── expected.txt │ │ │ ├── file1.yaml │ │ │ ├── file2.yaml │ │ │ └── file3.yaml │ │ ├── crlf │ │ │ ├── crlf.cpp │ │ │ ├── crlf.cpp.expected │ │ │ └── file1.yaml │ │ └── format │ │ │ ├── no.cpp │ │ │ ├── no.yaml │ │ │ ├── yes.cpp │ │ │ └── yes.yaml │ ├── basic.cpp │ ├── conflict.cpp │ ├── crlf.cpp │ └── format.cpp ├── clang-query │ ├── Inputs │ │ └── foo.script │ ├── errors.c │ └── function-decl.c ├── clang-rename │ ├── ClassTest.cpp │ ├── CtorDefTest.cpp │ ├── CtorInitializerTest.cpp │ ├── DeclRefExpr.cpp │ ├── FieldTest.cpp │ ├── MemberExprMacro.cpp │ └── VarTest.cpp ├── clang-tidy │ ├── Inputs │ │ ├── Headers │ │ │ ├── a.h │ │ │ ├── b.h │ │ │ ├── clang-c │ │ │ │ └── c.h │ │ │ ├── clang │ │ │ │ └── b.h │ │ │ ├── gtest │ │ │ │ └── foo.h │ │ │ ├── i.h │ │ │ ├── j.h │ │ │ ├── llvm-c │ │ │ │ └── d.h │ │ │ ├── llvm │ │ │ │ └── a.h │ │ │ └── s.h │ │ ├── compilation-database │ │ │ └── template.json │ │ ├── config-files │ │ │ ├── 1 │ │ │ │ └── .clang-tidy │ │ │ └── .clang-tidy │ │ ├── explain-config │ │ │ └── .clang-tidy │ │ ├── file-filter │ │ │ ├── header1.h │ │ │ ├── header2.h │ │ │ └── system │ │ │ │ └── system-header.h │ │ ├── google-namespaces.h │ │ ├── line-filter │ │ │ ├── header1.h │ │ │ ├── header2.h │ │ │ └── header3.h │ │ ├── modernize-deprecated-headers │ │ │ ├── assert.h │ │ │ ├── complex.h │ │ │ ├── ctype.h │ │ │ ├── errno.h │ │ │ ├── fenv.h │ │ │ ├── float.h │ │ │ ├── inttypes.h │ │ │ ├── iso646.h │ │ │ ├── limits.h │ │ │ ├── locale.h │ │ │ ├── math.h │ │ │ ├── setjmp.h │ │ │ ├── signal.h │ │ │ ├── stdalign.h │ │ │ ├── stdarg.h │ │ │ ├── stdbool.h │ │ │ ├── stddef.h │ │ │ ├── stdint.h │ │ │ ├── stdio.h │ │ │ ├── stdlib.h │ │ │ ├── string.h │ │ │ ├── tgmath.h │ │ │ ├── time.h │ │ │ ├── uchar.h │ │ │ ├── wchar.h │ │ │ └── wctype.h │ │ ├── modernize-loop-convert │ │ │ └── structures.h │ │ ├── modernize-pass-by-value │ │ │ └── header.h │ │ ├── modernize-replace-auto-ptr │ │ │ └── memory.h │ │ ├── modernize-use-auto │ │ │ └── containers.h │ │ ├── overlapping │ │ │ └── o.h │ │ └── readability-identifier-naming │ │ │ ├── system │ │ │ └── system-header.h │ │ │ └── user-header.h │ ├── basic.cpp │ ├── boost-use-to-string.cpp │ ├── cert-env33-c.c │ ├── cert-err34-c.c │ ├── cert-err34-c.cpp │ ├── cert-flp30-c.c │ ├── cert-oop11-cpp.cpp │ ├── cert-setlongjmp.cpp │ ├── cert-static-object-exception.cpp │ ├── cert-throw-exception-type.cpp │ ├── cert-variadic-function-def.cpp │ ├── check_clang_tidy.py │ ├── clang-tidy-diff.cpp │ ├── clang-tidy-run-with-database.cpp │ ├── config-files.cpp │ ├── cppcoreguidelines-interfaces-global-init.cpp │ ├── cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp │ ├── cppcoreguidelines-pro-bounds-constant-array-index-gslheader.cpp │ ├── cppcoreguidelines-pro-bounds-constant-array-index.cpp │ ├── cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp │ ├── cppcoreguidelines-pro-type-const-cast.cpp │ ├── cppcoreguidelines-pro-type-cstyle-cast.cpp │ ├── cppcoreguidelines-pro-type-member-init-cxx98.cpp │ ├── cppcoreguidelines-pro-type-member-init-delayed.cpp │ ├── cppcoreguidelines-pro-type-member-init.cpp │ ├── cppcoreguidelines-pro-type-reinterpret-cast.cpp │ ├── cppcoreguidelines-pro-type-static-cast-downcast.cpp │ ├── cppcoreguidelines-pro-type-union-access.cpp │ ├── cppcoreguidelines-pro-type-vararg.cpp │ ├── custom-diagnostics.cpp │ ├── deduplication.cpp │ ├── diagnostic.cpp │ ├── explain-checks.cpp │ ├── file-filter.cpp │ ├── fix-errors.cpp │ ├── fix.cpp │ ├── google-build-explicit-make-pair.cpp │ ├── google-default-arguments.cpp │ ├── google-explicit-constructor.cpp │ ├── google-module.cpp │ ├── google-namespaces.cpp │ ├── google-overloaded-unary-and.cpp │ ├── google-readability-casting.c │ ├── google-readability-casting.cpp │ ├── google-readability-namespace-comments.cpp │ ├── google-readability-todo.cpp │ ├── google-runtime-int-std.cpp │ ├── google-runtime-int.c │ ├── google-runtime-int.cpp │ ├── google-runtime-member-string-references.cpp │ ├── google-runtime-memset-zero-length.cpp │ ├── google-runtime-references.cpp │ ├── line-filter.cpp │ ├── llvm-include-order.cpp │ ├── llvm-twine-local.cpp │ ├── macros.cpp │ ├── misc-argument-comment.cpp │ ├── misc-assert-side-effect.cpp │ ├── misc-bool-pointer-implicit-conversion.cpp │ ├── misc-dangling-handle.cpp │ ├── misc-definitions-in-headers.hpp │ ├── misc-fold-init-type.cpp │ ├── misc-forward-declaration-namespace.cpp │ ├── misc-inaccurate-erase.cpp │ ├── misc-incorrect-roundings.cpp │ ├── misc-inefficient-algorithm.cpp │ ├── misc-macro-parentheses-cmdline.cpp │ ├── misc-macro-parentheses.cpp │ ├── misc-macro-repeated-side-effects.c │ ├── misc-misplaced-widening-cast-explicit-only.cpp │ ├── misc-misplaced-widening-cast.cpp │ ├── misc-move-const-arg.cpp │ ├── misc-move-constructor-init.cpp │ ├── misc-multiple-statement-macro.cpp │ ├── misc-new-delete-overloads-sized-dealloc.cpp │ ├── misc-new-delete-overloads.cpp │ ├── misc-noexcept-move-constructor.cpp │ ├── misc-non-copyable-objects.c │ ├── misc-non-copyable-objects.cpp │ ├── misc-pointer-and-integral-operation-cxx98.cpp │ ├── misc-pointer-and-integral-operation.cpp │ ├── misc-redundant-expression.cpp │ ├── misc-sizeof-container.cpp │ ├── misc-sizeof-expression.cpp │ ├── misc-static-assert.c │ ├── misc-static-assert.cpp │ ├── misc-string-constructor.cpp │ ├── misc-string-integer-assignment.cpp │ ├── misc-string-literal-with-embedded-nul.cpp │ ├── misc-suspicious-missing-comma.cpp │ ├── misc-suspicious-semicolon-fail.cpp │ ├── misc-suspicious-semicolon.cpp │ ├── misc-suspicious-string-compare.c │ ├── misc-suspicious-string-compare.cpp │ ├── misc-swapped-arguments.cpp │ ├── misc-throw-by-value-catch-by-reference.cpp │ ├── misc-unconventional-assign-operator.cpp │ ├── misc-undelegated-constructor-cxx98.cpp │ ├── misc-undelegated-constructor.cpp │ ├── misc-uniqueptr-reset-release.cpp │ ├── misc-unused-alias-decls.cpp │ ├── misc-unused-parameters.c │ ├── misc-unused-parameters.cpp │ ├── misc-unused-raii.cpp │ ├── misc-unused-using-decls.cpp │ ├── misc-virtual-near-miss.cpp │ ├── modernize-avoid-bind.cpp │ ├── modernize-deprecated-headers-cxx03.cpp │ ├── modernize-deprecated-headers-cxx11.cpp │ ├── modernize-loop-convert-assert-failure.cpp │ ├── modernize-loop-convert-basic.cpp │ ├── modernize-loop-convert-camelback.cpp │ ├── modernize-loop-convert-const.cpp │ ├── modernize-loop-convert-extra.cpp │ ├── modernize-loop-convert-lowercase.cpp │ ├── modernize-loop-convert-negative.cpp │ ├── modernize-loop-convert-uppercase.cpp │ ├── modernize-loop-convert.c │ ├── modernize-make-shared.cpp │ ├── modernize-make-unique.cpp │ ├── modernize-pass-by-value-header.cpp │ ├── modernize-pass-by-value-macro-header.cpp │ ├── modernize-pass-by-value.cpp │ ├── modernize-raw-string-literal-delimiter.cpp │ ├── modernize-raw-string-literal.cpp │ ├── modernize-redundant-void-arg-delayed.cpp │ ├── modernize-redundant-void-arg.c │ ├── modernize-redundant-void-arg.cpp │ ├── modernize-replace-auto-ptr.cpp │ ├── modernize-shrink-to-fit.cpp │ ├── modernize-use-auto-iterator.cpp │ ├── modernize-use-auto-new.cpp │ ├── modernize-use-bool-literals.cpp │ ├── modernize-use-default-copy.cpp │ ├── modernize-use-default-delayed.cpp │ ├── modernize-use-default.cpp │ ├── modernize-use-nullptr-basic.cpp │ ├── modernize-use-nullptr.c │ ├── modernize-use-nullptr.cpp │ ├── modernize-use-override-cxx98.cpp │ ├── modernize-use-override-ms.cpp │ ├── modernize-use-override.cpp │ ├── nolint.cpp │ ├── overlapping.cpp │ ├── performance-faster-string-find.cpp │ ├── performance-for-range-copy-warn-on-all-auto-copies.cpp │ ├── performance-for-range-copy.cpp │ ├── performance-implicit-cast-in-loop.cpp │ ├── performance-unnecessary-copy-initialization.cpp │ ├── performance-unnecessary-value-param-delayed.cpp │ ├── performance-unnecessary-value-param.cpp │ ├── readability-avoid-const-params-in-decls.cpp │ ├── readability-braces-around-statements-assert-failure.cpp │ ├── readability-braces-around-statements-few-lines.cpp │ ├── readability-braces-around-statements-same-line.cpp │ ├── readability-braces-around-statements-single-line.cpp │ ├── readability-braces-around-statements.cpp │ ├── readability-container-size-empty.cpp │ ├── readability-deleted-default.cpp │ ├── readability-else-after-return.cpp │ ├── readability-function-size.cpp │ ├── readability-identifier-naming.cpp │ ├── readability-implicit-bool-cast-allow-conditional-casts.cpp │ ├── readability-implicit-bool-cast-cxx98.cpp │ ├── readability-implicit-bool-cast.cpp │ ├── readability-inconsistent-declaration-parameter-name.cpp │ ├── readability-named-parameter.cpp │ ├── readability-redundant-control-flow.cpp │ ├── readability-redundant-smartptr-get.cpp │ ├── readability-redundant-string-cstr-msvc.cpp │ ├── readability-redundant-string-cstr.cpp │ ├── readability-redundant-string-init-msvc.cpp │ ├── readability-redundant-string-init.cpp │ ├── readability-simplify-bool-expr-chained-conditional-assignment.cpp │ ├── readability-simplify-bool-expr-chained-conditional-return.cpp │ ├── readability-simplify-bool-expr.cpp │ ├── readability-static-definition-in-anonymous-namespace.cpp │ ├── readability-uniqueptr-delete-release.cpp │ ├── select-checks.cpp │ ├── serialize-diagnostics.cpp │ ├── static-analyzer-config.cpp │ ├── static-analyzer.cpp │ ├── temporaries.cpp │ ├── validate-check-names.cpp │ ├── werrors-diagnostics.cpp │ ├── werrors-plural.cpp │ └── werrors.cpp ├── include-fixer │ ├── Inputs │ │ ├── database_template.json │ │ └── fake_yaml_db.yaml │ ├── exit_on_fatal.cpp │ ├── fixeddb.cpp │ ├── include_path.cpp │ ├── yamldb.cpp │ └── yamldb_autodetect.cpp ├── lit.cfg ├── lit.site.cfg.in ├── modularize │ ├── Inputs │ │ ├── Anonymous.h │ │ ├── CompileError │ │ │ ├── HasError.h │ │ │ ├── Level1A.h │ │ │ └── module.modulemap │ │ ├── CoverageNoProblems │ │ │ ├── Includes1 │ │ │ │ ├── .hidden │ │ │ │ │ └── DontFindMe.h │ │ │ │ └── Level1A.h │ │ │ ├── Includes2 │ │ │ │ └── Level2A.h │ │ │ ├── NonIncludes │ │ │ │ └── Level3A.h │ │ │ └── module.modulemap │ │ ├── CoverageProblems │ │ │ ├── Level1A.h │ │ │ ├── Level1B.h │ │ │ ├── Level2A.h │ │ │ ├── Level2B.h │ │ │ ├── Level3A.h │ │ │ ├── Level3B │ │ │ ├── Sub │ │ │ │ └── Level3B.h │ │ │ ├── UmbrellaFile.h │ │ │ ├── UmbrellaInclude1.h │ │ │ ├── UmbrellaInclude2.h │ │ │ ├── UmbrellaSub │ │ │ │ ├── Umbrell1.h │ │ │ │ └── Umbrell2.h │ │ │ └── module.modulemap │ │ ├── DuplicateHeader1.h │ │ ├── DuplicateHeader2.h │ │ ├── Empty.h │ │ ├── HeaderGuard.h │ │ ├── HeaderGuardSub1.h │ │ ├── HeaderGuardSub2.h │ │ ├── HeaderGuardSubSub.h │ │ ├── HeaderGuardSubSubDefined.h │ │ ├── IncludeInExtern.h │ │ ├── IncludeInNamespace.h │ │ ├── InconsistentHeader1.h │ │ ├── InconsistentHeader2.h │ │ ├── InconsistentSubHeader.h │ │ ├── IsDependent.h │ │ ├── MissingHeader │ │ │ ├── Level1A.h │ │ │ └── module.modulemap │ │ ├── NamespaceClasses.h │ │ ├── NestedMacro.h │ │ ├── NoProblems.modulemap │ │ ├── ProblemsDuplicate.modulemap │ │ ├── SomeDecls.h │ │ ├── SomeOtherTypes.h │ │ ├── SomeTypes.h │ │ ├── SubModule1 │ │ │ ├── Header1.h │ │ │ └── Header2.h │ │ ├── SubModule2 │ │ │ ├── Header3.h │ │ │ └── Header4.h │ │ └── TemplateClasses.h │ ├── NoProblems.modularize │ ├── NoProblemsAnonymous.modularize │ ├── NoProblemsAssistant.modularize │ ├── NoProblemsCoverage.modularize │ ├── NoProblemsDependencies.modularize │ ├── NoProblemsGuard.modularize │ ├── NoProblemsList.modularize │ ├── NoProblemsNamespace.modularize │ ├── NoProblemsNamespaceClasses.modularize │ ├── NoProblemsNestedMacro.modularize │ ├── NoProblemsTemplateClasses.modularize │ ├── ProblemsCompileError.modularize │ ├── ProblemsCoverage.modularize │ ├── ProblemsDisplayLists.modularize │ ├── ProblemsDuplicate.modularize │ ├── ProblemsExternC.modularize │ ├── ProblemsInconsistent.modularize │ ├── ProblemsMissingHeader.modularize │ ├── ProblemsNamespace.modularize │ └── SubModule2.h └── pp-trace │ ├── Inputs │ ├── Level1A.h │ ├── Level1B.h │ ├── Level2A.h │ ├── Level2B.h │ ├── ModularizeList.txt │ └── module.map │ ├── pp-trace-conditional.cpp │ ├── pp-trace-ident.cpp │ ├── pp-trace-include.cpp │ ├── pp-trace-macro.cpp │ ├── pp-trace-modules.cpp │ ├── pp-trace-pragma-general.cpp │ ├── pp-trace-pragma-ms.cpp │ └── pp-trace-pragma-opencl.cpp ├── tool-template ├── CMakeLists.txt └── ToolTemplate.cpp └── unittests ├── CMakeLists.txt ├── clang-apply-replacements ├── CMakeLists.txt └── ReformattingTest.cpp ├── clang-query ├── CMakeLists.txt ├── QueryEngineTest.cpp └── QueryParserTest.cpp ├── clang-rename ├── CMakeLists.txt └── USRLocFindingTest.cpp ├── clang-tidy ├── CMakeLists.txt ├── ClangTidyDiagnosticConsumerTest.cpp ├── ClangTidyOptionsTest.cpp ├── ClangTidyTest.h ├── GoogleModuleTest.cpp ├── IncludeInserterTest.cpp ├── LLVMModuleTest.cpp ├── MiscModuleTest.cpp ├── OverlappingReplacementsTest.cpp └── ReadabilityModuleTest.cpp ├── include-fixer ├── CMakeLists.txt ├── IncludeFixerTest.cpp └── find-all-symbols │ ├── CMakeLists.txt │ └── FindAllSymbolsTests.cpp └── include └── common └── VirtualFileHelper.h /.arcconfig: -------------------------------------------------------------------------------- 1 | { 2 | "project_id" : "clang-tools-extra", 3 | "conduit_uri" : "http://reviews.llvm.org/" 4 | } 5 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(clang-apply-replacements) 2 | add_subdirectory(clang-rename) 3 | add_subdirectory(modularize) 4 | if(CLANG_ENABLE_STATIC_ANALYZER) 5 | add_subdirectory(clang-tidy) 6 | endif() 7 | 8 | add_subdirectory(clang-query) 9 | add_subdirectory(include-fixer) 10 | add_subdirectory(pp-trace) 11 | add_subdirectory(tool-template) 12 | 13 | # Add the common testsuite after all the tools. 14 | # TODO: Support tests with more granularity when features are off? 15 | if(CLANG_ENABLE_STATIC_ANALYZER AND CLANG_INCLUDE_TESTS) 16 | add_subdirectory(test) 17 | add_subdirectory(unittests) 18 | endif() 19 | 20 | option(CLANG_TOOLS_EXTRA_INCLUDE_DOCS "Generate build targets for the Clang Extra Tools docs." 21 | ${LLVM_INCLUDE_DOCS}) 22 | if( CLANG_TOOLS_EXTRA_INCLUDE_DOCS ) 23 | add_subdirectory(docs) 24 | endif() 25 | 26 | -------------------------------------------------------------------------------- /CODE_OWNERS.TXT: -------------------------------------------------------------------------------- 1 | This file is a list of the people responsible for ensuring that patches for a 2 | particular tool are reviewed, either by themself or by someone else. They are 3 | also the gatekeepers for their part of Clang, with the final word on what goes 4 | in or not. 5 | 6 | The list is sorted by surname and formatted to allow easy grepping and 7 | beautification by scripts. The fields are: name (N), email (E), web-address 8 | (W), PGP key ID and fingerprint (P), description (D), and snail-mail address 9 | (S). 10 | 11 | N: Peter Collingbourne 12 | E: peter@pcc.me.uk 13 | D: clang-query 14 | 15 | N: Manuel Klimek 16 | E: klimek@google.com 17 | D: clang-rename, all parts of clang-tools-extra not covered by someone else 18 | 19 | N: Alexander Kornienko 20 | E: alexfh@google.com 21 | D: clang-tidy 22 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Clang Tools repository 3 | //===----------------------------------------------------------------------===// 4 | 5 | Welcome to the repository of extra Clang Tools. This repository holds tools 6 | that are developed as part of the LLVM compiler infrastructure project and the 7 | Clang frontend. These tools are kept in a separate "extra" repository to 8 | allow lighter weight checkouts of the core Clang codebase. 9 | 10 | This repository is only intended to be checked out inside of a full LLVM+Clang 11 | tree, and in the 'tools/extra' subdirectory of the Clang checkout. 12 | 13 | All discussion regarding Clang, Clang-based tools, and code in this repository 14 | should be held using the standard Clang mailing lists: 15 | http://lists.llvm.org/mailman/listinfo/cfe-dev 16 | 17 | Code review for this tree should take place on the standard Clang patch and 18 | commit lists: 19 | http://lists.llvm.org/mailman/listinfo/cfe-commits 20 | 21 | If you find a bug in these tools, please file it in the LLVM bug tracker: 22 | http://llvm.org/bugs/ 23 | -------------------------------------------------------------------------------- /clang-apply-replacements/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS 2 | Support 3 | ) 4 | 5 | add_clang_library(clangApplyReplacements 6 | lib/Tooling/ApplyReplacements.cpp 7 | 8 | LINK_LIBS 9 | clangAST 10 | clangBasic 11 | clangRewrite 12 | clangToolingCore 13 | ) 14 | 15 | include_directories( 16 | ${CMAKE_CURRENT_SOURCE_DIR} 17 | include 18 | ) 19 | add_subdirectory(tool) 20 | -------------------------------------------------------------------------------- /clang-apply-replacements/tool/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS 2 | Support 3 | ) 4 | 5 | add_clang_executable(clang-apply-replacements 6 | ClangApplyReplacementsMain.cpp 7 | ) 8 | target_link_libraries(clang-apply-replacements 9 | clangApplyReplacements 10 | clangBasic 11 | clangFormat 12 | clangRewrite 13 | clangToolingCore 14 | ) 15 | 16 | install(TARGETS clang-apply-replacements 17 | RUNTIME DESTINATION bin) 18 | -------------------------------------------------------------------------------- /clang-query/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS 2 | lineeditor 3 | support 4 | ) 5 | 6 | add_clang_library(clangQuery 7 | Query.cpp 8 | QueryParser.cpp 9 | 10 | LINK_LIBS 11 | clangAST 12 | clangASTMatchers 13 | clangBasic 14 | clangDynamicASTMatchers 15 | clangFrontend 16 | ) 17 | 18 | add_subdirectory(tool) 19 | -------------------------------------------------------------------------------- /clang-query/tool/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) 2 | 3 | add_clang_executable(clang-query ClangQuery.cpp) 4 | target_link_libraries(clang-query 5 | clangAST 6 | clangASTMatchers 7 | clangBasic 8 | clangDynamicASTMatchers 9 | clangFrontend 10 | clangQuery 11 | clangTooling 12 | ) 13 | 14 | install(TARGETS clang-query RUNTIME DESTINATION bin) 15 | -------------------------------------------------------------------------------- /clang-rename/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS support) 2 | 3 | add_clang_library(clangRename 4 | USRFinder.cpp 5 | USRFindingAction.cpp 6 | USRLocFinder.cpp 7 | RenamingAction.cpp 8 | 9 | LINK_LIBS 10 | clangAST 11 | clangBasic 12 | clangIndex 13 | clangLex 14 | clangToolingCore 15 | ) 16 | 17 | add_subdirectory(tool) 18 | -------------------------------------------------------------------------------- /clang-rename/tool/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_clang_executable(clang-rename ClangRename.cpp) 2 | 3 | target_link_libraries(clang-rename 4 | clangBasic 5 | clangFrontend 6 | clangRename 7 | clangRewrite 8 | clangTooling 9 | ) 10 | 11 | install(TARGETS clang-rename RUNTIME DESTINATION bin) 12 | -------------------------------------------------------------------------------- /clang-tidy/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS 2 | Support 3 | ) 4 | 5 | add_clang_library(clangTidy 6 | ClangTidy.cpp 7 | ClangTidyModule.cpp 8 | ClangTidyDiagnosticConsumer.cpp 9 | ClangTidyOptions.cpp 10 | 11 | DEPENDS 12 | ClangSACheckers 13 | 14 | LINK_LIBS 15 | clangAST 16 | clangASTMatchers 17 | clangBasic 18 | clangFrontend 19 | clangLex 20 | clangRewrite 21 | clangSema 22 | clangStaticAnalyzerCore 23 | clangStaticAnalyzerFrontend 24 | clangTooling 25 | clangToolingCore 26 | ) 27 | 28 | add_subdirectory(tool) 29 | add_subdirectory(plugin) 30 | add_subdirectory(boost) 31 | add_subdirectory(cert) 32 | add_subdirectory(llvm) 33 | add_subdirectory(cppcoreguidelines) 34 | add_subdirectory(google) 35 | add_subdirectory(misc) 36 | add_subdirectory(modernize) 37 | add_subdirectory(performance) 38 | add_subdirectory(readability) 39 | add_subdirectory(utils) 40 | -------------------------------------------------------------------------------- /clang-tidy/ClangTidyModuleRegistry.h: -------------------------------------------------------------------------------- 1 | //===--- ClangTidyModuleRegistry.h - clang-tidy -----------------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYMODULEREGISTRY_H 11 | #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYMODULEREGISTRY_H 12 | 13 | #include "ClangTidyModule.h" 14 | #include "llvm/Support/Registry.h" 15 | 16 | extern template class llvm::Registry; 17 | 18 | namespace clang { 19 | namespace tidy { 20 | 21 | typedef llvm::Registry ClangTidyModuleRegistry; 22 | 23 | } // end namespace tidy 24 | } // end namespace clang 25 | 26 | #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYMODULEREGISTRY_H 27 | -------------------------------------------------------------------------------- /clang-tidy/boost/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS support) 2 | 3 | add_clang_library(clangTidyBoostModule 4 | BoostTidyModule.cpp 5 | UseToStringCheck.cpp 6 | 7 | LINK_LIBS 8 | clangAST 9 | clangASTMatchers 10 | clangBasic 11 | clangLex 12 | clangTidy 13 | clangTidyUtils 14 | ) 15 | -------------------------------------------------------------------------------- /clang-tidy/cert/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS support) 2 | 3 | add_clang_library(clangTidyCERTModule 4 | CERTTidyModule.cpp 5 | CommandProcessorCheck.cpp 6 | FloatLoopCounter.cpp 7 | SetLongJmpCheck.cpp 8 | StaticObjectExceptionCheck.cpp 9 | StrToNumCheck.cpp 10 | ThrownExceptionTypeCheck.cpp 11 | VariadicFunctionDefCheck.cpp 12 | 13 | LINK_LIBS 14 | clangAnalysis 15 | clangAST 16 | clangASTMatchers 17 | clangBasic 18 | clangLex 19 | clangTidy 20 | clangTidyGoogleModule 21 | clangTidyMiscModule 22 | clangTidyUtils 23 | ) 24 | -------------------------------------------------------------------------------- /clang-tidy/cppcoreguidelines/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS support) 2 | 3 | add_clang_library(clangTidyCppCoreGuidelinesModule 4 | CppCoreGuidelinesTidyModule.cpp 5 | InterfacesGlobalInitCheck.cpp 6 | ProBoundsArrayToPointerDecayCheck.cpp 7 | ProBoundsConstantArrayIndexCheck.cpp 8 | ProBoundsPointerArithmeticCheck.cpp 9 | ProTypeConstCastCheck.cpp 10 | ProTypeCstyleCastCheck.cpp 11 | ProTypeMemberInitCheck.cpp 12 | ProTypeReinterpretCastCheck.cpp 13 | ProTypeStaticCastDowncastCheck.cpp 14 | ProTypeUnionAccessCheck.cpp 15 | ProTypeVarargCheck.cpp 16 | 17 | LINK_LIBS 18 | clangAST 19 | clangASTMatchers 20 | clangBasic 21 | clangLex 22 | clangTidy 23 | clangTidyMiscModule 24 | clangTidyUtils 25 | clangTooling 26 | ) 27 | -------------------------------------------------------------------------------- /clang-tidy/google/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS support) 2 | 3 | add_clang_library(clangTidyGoogleModule 4 | AvoidCStyleCastsCheck.cpp 5 | DefaultArgumentsCheck.cpp 6 | ExplicitConstructorCheck.cpp 7 | ExplicitMakePairCheck.cpp 8 | GlobalNamesInHeadersCheck.cpp 9 | GoogleTidyModule.cpp 10 | IntegerTypesCheck.cpp 11 | MemsetZeroLengthCheck.cpp 12 | NonConstReferences.cpp 13 | OverloadedUnaryAndCheck.cpp 14 | StringReferenceMemberCheck.cpp 15 | TodoCommentCheck.cpp 16 | UnnamedNamespaceInHeaderCheck.cpp 17 | UsingNamespaceDirectiveCheck.cpp 18 | 19 | LINK_LIBS 20 | clangAST 21 | clangASTMatchers 22 | clangBasic 23 | clangLex 24 | clangTidy 25 | clangTidyReadabilityModule 26 | clangTidyUtils 27 | ) 28 | -------------------------------------------------------------------------------- /clang-tidy/llvm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS support) 2 | 3 | add_clang_library(clangTidyLLVMModule 4 | HeaderGuardCheck.cpp 5 | IncludeOrderCheck.cpp 6 | LLVMTidyModule.cpp 7 | TwineLocalCheck.cpp 8 | 9 | LINK_LIBS 10 | clangAST 11 | clangASTMatchers 12 | clangBasic 13 | clangLex 14 | clangTidy 15 | clangTidyReadabilityModule 16 | clangTidyUtils 17 | clangTooling 18 | ) 19 | -------------------------------------------------------------------------------- /clang-tidy/misc/MoveConstantArgumentCheck.h: -------------------------------------------------------------------------------- 1 | //===--- MoveConstandArgumentCheck.h - clang-tidy -------------------------===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MOVECONTANTARGUMENTCHECK_H 11 | #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MOVECONTANTARGUMENTCHECK_H 12 | 13 | #include "../ClangTidy.h" 14 | 15 | namespace clang { 16 | namespace tidy { 17 | namespace misc { 18 | 19 | class MoveConstantArgumentCheck : public ClangTidyCheck { 20 | public: 21 | MoveConstantArgumentCheck(StringRef Name, ClangTidyContext *Context) 22 | : ClangTidyCheck(Name, Context) {} 23 | void registerMatchers(ast_matchers::MatchFinder *Finder) override; 24 | void check(const ast_matchers::MatchFinder::MatchResult &Result) override; 25 | }; 26 | 27 | } // namespace misc 28 | } // namespace tidy 29 | } // namespace clang 30 | 31 | #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MOVECONTANTARGUMENTCHECK_H 32 | -------------------------------------------------------------------------------- /clang-tidy/modernize/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS support) 2 | 3 | add_clang_library(clangTidyModernizeModule 4 | AvoidBindCheck.cpp 5 | DeprecatedHeadersCheck.cpp 6 | LoopConvertCheck.cpp 7 | LoopConvertUtils.cpp 8 | MakeSmartPtrCheck.cpp 9 | MakeSharedCheck.cpp 10 | MakeUniqueCheck.cpp 11 | ModernizeTidyModule.cpp 12 | PassByValueCheck.cpp 13 | RawStringLiteralCheck.cpp 14 | RedundantVoidArgCheck.cpp 15 | ReplaceAutoPtrCheck.cpp 16 | ShrinkToFitCheck.cpp 17 | UseAutoCheck.cpp 18 | UseBoolLiteralsCheck.cpp 19 | UseDefaultCheck.cpp 20 | UseNullptrCheck.cpp 21 | UseOverrideCheck.cpp 22 | 23 | LINK_LIBS 24 | clangAST 25 | clangASTMatchers 26 | clangBasic 27 | clangLex 28 | clangTidy 29 | clangTidyReadabilityModule 30 | clangTidyUtils 31 | ) 32 | -------------------------------------------------------------------------------- /clang-tidy/modernize/MakeSharedCheck.cpp: -------------------------------------------------------------------------------- 1 | //===--- MakeSharedCheck.cpp - clang-tidy----------------------------------===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #include "MakeSharedCheck.h" 11 | 12 | using namespace clang::ast_matchers; 13 | 14 | namespace clang { 15 | namespace tidy { 16 | namespace modernize { 17 | 18 | MakeSharedCheck::MakeSharedCheck(StringRef Name, ClangTidyContext *Context) 19 | : MakeSmartPtrCheck(Name, Context, "std::make_shared") {} 20 | 21 | MakeSharedCheck::SmartPtrTypeMatcher 22 | MakeSharedCheck::getSmartPointerTypeMatcher() const { 23 | return qualType(hasDeclaration(classTemplateSpecializationDecl( 24 | matchesName("::std::shared_ptr"), templateArgumentCountIs(1), 25 | hasTemplateArgument( 26 | 0, templateArgument(refersToType(qualType().bind(PointerType))))))); 27 | } 28 | 29 | } // namespace modernize 30 | } // namespace tidy 31 | } // namespace clang 32 | -------------------------------------------------------------------------------- /clang-tidy/performance/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS support) 2 | 3 | add_clang_library(clangTidyPerformanceModule 4 | FasterStringFindCheck.cpp 5 | ForRangeCopyCheck.cpp 6 | ImplicitCastInLoopCheck.cpp 7 | PerformanceTidyModule.cpp 8 | UnnecessaryCopyInitialization.cpp 9 | UnnecessaryValueParamCheck.cpp 10 | 11 | LINK_LIBS 12 | clangAST 13 | clangASTMatchers 14 | clangBasic 15 | clangLex 16 | clangTidy 17 | clangTidyUtils 18 | ) 19 | -------------------------------------------------------------------------------- /clang-tidy/plugin/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_clang_library(clangTidyPlugin 2 | ClangTidyPlugin.cpp 3 | 4 | LINK_LIBS 5 | clangAST 6 | clangASTMatchers 7 | clangBasic 8 | clangFrontend 9 | clangSema 10 | clangTidy 11 | clangTidyBoostModule 12 | clangTidyCERTModule 13 | clangTidyCppCoreGuidelinesModule 14 | clangTidyGoogleModule 15 | clangTidyLLVMModule 16 | clangTidyMiscModule 17 | clangTidyModernizeModule 18 | clangTidyPerformanceModule 19 | clangTidyReadabilityModule 20 | clangTooling 21 | ) 22 | -------------------------------------------------------------------------------- /clang-tidy/readability/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS support) 2 | 3 | add_clang_library(clangTidyReadabilityModule 4 | AvoidConstParamsInDecls.cpp 5 | BracesAroundStatementsCheck.cpp 6 | ContainerSizeEmptyCheck.cpp 7 | DeletedDefaultCheck.cpp 8 | ElseAfterReturnCheck.cpp 9 | FunctionSizeCheck.cpp 10 | IdentifierNamingCheck.cpp 11 | ImplicitBoolCastCheck.cpp 12 | InconsistentDeclarationParameterNameCheck.cpp 13 | NamedParameterCheck.cpp 14 | NamespaceCommentCheck.cpp 15 | ReadabilityTidyModule.cpp 16 | RedundantControlFlowCheck.cpp 17 | RedundantStringCStrCheck.cpp 18 | RedundantSmartptrGetCheck.cpp 19 | RedundantStringInitCheck.cpp 20 | SimplifyBooleanExprCheck.cpp 21 | StaticDefinitionInAnonymousNamespaceCheck.cpp 22 | UniqueptrDeleteReleaseCheck.cpp 23 | 24 | LINK_LIBS 25 | clangAST 26 | clangASTMatchers 27 | clangBasic 28 | clangLex 29 | clangTidy 30 | clangTidyUtils 31 | clangTooling 32 | ) 33 | -------------------------------------------------------------------------------- /clang-tidy/tool/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS 2 | support 3 | ) 4 | 5 | add_clang_executable(clang-tidy 6 | ClangTidyMain.cpp 7 | ) 8 | target_link_libraries(clang-tidy 9 | clangAST 10 | clangASTMatchers 11 | clangBasic 12 | clangTidy 13 | clangTidyBoostModule 14 | clangTidyCERTModule 15 | clangTidyCppCoreGuidelinesModule 16 | clangTidyGoogleModule 17 | clangTidyLLVMModule 18 | clangTidyMiscModule 19 | clangTidyModernizeModule 20 | clangTidyPerformanceModule 21 | clangTidyReadabilityModule 22 | clangTooling 23 | ) 24 | 25 | install(TARGETS clang-tidy 26 | RUNTIME DESTINATION bin) 27 | 28 | install(PROGRAMS clang-tidy-diff.py DESTINATION share/clang) 29 | install(PROGRAMS run-clang-tidy.py DESTINATION share/clang) 30 | -------------------------------------------------------------------------------- /clang-tidy/utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS support) 2 | 3 | add_clang_library(clangTidyUtils 4 | DeclRefExprUtils.cpp 5 | FixItHintUtils.cpp 6 | HeaderFileExtensionsUtils.cpp 7 | HeaderGuard.cpp 8 | IncludeInserter.cpp 9 | IncludeSorter.cpp 10 | LexerUtils.cpp 11 | OptionsUtils.cpp 12 | TypeTraits.cpp 13 | 14 | LINK_LIBS 15 | clangAST 16 | clangASTMatchers 17 | clangBasic 18 | clangLex 19 | clangTidy 20 | ) 21 | -------------------------------------------------------------------------------- /clang-tidy/utils/FixItHintUtils.h: -------------------------------------------------------------------------------- 1 | //===--- FixItHintUtils.h - clang-tidy---------------------------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_FIXITHINTUTILS_H 11 | #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_FIXITHINTUTILS_H 12 | 13 | #include "clang/AST/ASTContext.h" 14 | #include "clang/AST/Decl.h" 15 | 16 | namespace clang { 17 | namespace tidy { 18 | namespace utils { 19 | namespace fixit { 20 | 21 | /// \brief Creates fix to make VarDecl a reference by adding '&'. 22 | FixItHint changeVarDeclToReference(const VarDecl &Var, ASTContext &Context); 23 | 24 | /// \brief Creates fix to make VarDecl const qualified. 25 | FixItHint changeVarDeclToConst(const VarDecl &Var); 26 | 27 | } // namespace fixit 28 | } // namespace utils 29 | } // namespace tidy 30 | } // namespace clang 31 | 32 | #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_FIXITHINTUTILS_H 33 | -------------------------------------------------------------------------------- /clang-tidy/utils/LexerUtils.h: -------------------------------------------------------------------------------- 1 | //===--- LexerUtils.h - clang-tidy-------------------------------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_LEXER_UTILS_H 11 | #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_LEXER_UTILS_H 12 | 13 | #include "clang/AST/ASTContext.h" 14 | #include "clang/Lex/Lexer.h" 15 | 16 | namespace clang { 17 | namespace tidy { 18 | namespace utils { 19 | namespace lexer { 20 | 21 | // Returns previous non-comment token skipping over any comment text or 22 | // tok::unknown if not found. 23 | Token getPreviousNonCommentToken(const ASTContext &Context, 24 | SourceLocation Location); 25 | 26 | } // namespace lexer 27 | } // namespace utils 28 | } // namespace tidy 29 | } // namespace clang 30 | 31 | #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_LEXER_UTILS_H 32 | -------------------------------------------------------------------------------- /clang-tidy/utils/OptionsUtils.h: -------------------------------------------------------------------------------- 1 | //===--- DanglingHandleCheck.h - clang-tidy----------------------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_OPTIONUTILS_H 11 | #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_OPTIONUTILS_H 12 | 13 | #include "../ClangTidy.h" 14 | 15 | namespace clang { 16 | namespace tidy { 17 | namespace utils { 18 | namespace options { 19 | 20 | /// \brief Parse a semicolon separated list of strings. 21 | std::vector parseStringList(StringRef Option); 22 | 23 | /// \brief Serialize a sequence of names that can be parsed by 24 | /// 'parseStringList'. 25 | std::string serializeStringList(ArrayRef Strings); 26 | 27 | } // namespace options 28 | } // namespace utils 29 | } // namespace tidy 30 | } // namespace clang 31 | 32 | #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_OPTIONUTILS_H 33 | -------------------------------------------------------------------------------- /docs/README.txt: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------- 2 | Documentation for the tools of clang-tools-extra repo project 3 | ------------------------------------------------------------- 4 | 5 | Sphinx and doxygen documentation is generated by executing make. 6 | 7 | Sphinx html files can be generated separately using make html. 8 | 9 | Doxygen html files can also be generated using make doxygen. 10 | 11 | The generated documentation will be placed in _build/html. 12 | -------------------------------------------------------------------------------- /docs/clang-modernize.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | All :program:`clang-modernize` transforms have moved to :doc:`clang-tidy/index` 4 | (see the ``modernize`` module). 5 | -------------------------------------------------------------------------------- /docs/clang-tidy.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | .. meta:: 4 | :http-equiv=refresh: 0;URL='clang-tidy/' 5 | 6 | clang-tidy documentation has moved here: http://clang.llvm.org/extra/clang-tidy/ 7 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/boost-use-to-string.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - boost-use-to-string 2 | 3 | boost-use-to-string 4 | =================== 5 | 6 | This check finds conversion from integer type like ``int`` to ``std::string`` or 7 | ``std::wstring`` using ``boost::lexical_cast``, and replace it with calls to 8 | ``std::to_string`` and ``std::to_wstring``. 9 | 10 | It doesn't replace conversion from floating points despite the ``to_string`` 11 | overloads, because it would change the behaviour. 12 | 13 | 14 | .. code-block:: c++ 15 | 16 | auto str = boost::lexical_cast(42); 17 | auto wstr = boost::lexical_cast(2137LL); 18 | 19 | // Will be changed to 20 | auto str = std::to_string(42); 21 | auto wstr = std::to_wstring(2137LL); 22 | 23 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/cert-dcl03-c.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - cert-dcl03-c 2 | .. meta:: 3 | :http-equiv=refresh: 5;URL=misc-static-assert.html 4 | 5 | cert-dcl03-c 6 | ============ 7 | 8 | The cert-dcl03-c check is an alias, please see 9 | `misc-static-assert `_ for more information. 10 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/cert-dcl50-cpp.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - cert-dcl50-cpp 2 | 3 | cert-dcl50-cpp 4 | ============== 5 | 6 | This check flags all function definitions (but not declarations) of C-style 7 | variadic functions. 8 | 9 | This check corresponds to the CERT C++ Coding Standard rule 10 | `DCL50-CPP. Do not define a C-style variadic function 11 | `_. 12 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/cert-dcl54-cpp.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - cert-dcl54-cpp 2 | .. meta:: 3 | :http-equiv=refresh: 5;URL=misc-new-delete-overloads.html 4 | 5 | cert-dcl54-cpp 6 | ============== 7 | 8 | The cert-dcl54-cpp check is an alias, please see 9 | `misc-new-delete-overloads `_ for more 10 | information. 11 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/cert-dcl59-cpp.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - cert-dcl59-cpp 2 | .. meta:: 3 | :http-equiv=refresh: 5;URL=google-build-namespaces.html 4 | 5 | cert-dcl59-cpp 6 | ============== 7 | 8 | The cert-dcl59-cpp check is an alias, please see 9 | `google-build-namespaces `_ for more information. 10 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/cert-env33-c.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - cert-env33-c 2 | 3 | cert-env33-c 4 | ============ 5 | 6 | This check flags calls to ``system()``, ``popen()``, and ``_popen()``, which 7 | execute a command processor. It does not flag calls to ``system()`` with a null 8 | pointer argument, as such a call checks for the presence of a command processor 9 | but does not actually attempt to execute a command. 10 | 11 | This check corresponds to the CERT C Coding Standard rule 12 | `ENV33-C. Do not call system() 13 | `_. 14 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/cert-err34-c.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - cert-err34-c 2 | 3 | cert-err34-c 4 | ============ 5 | 6 | This check flags calls to string-to-number conversion functions that do not 7 | verify the validity of the conversion, such as ``atoi()`` or ``scanf()``. It 8 | does not flag calls to ``strtol()``, or other, related conversion functions that 9 | do perform better error checking. 10 | 11 | .. code:: c 12 | 13 | #include 14 | 15 | void func(const char *buff) { 16 | int si; 17 | 18 | if (buff) { 19 | si = atoi(buff); /* 'atoi' used to convert a string to an integer, but function will 20 | not report conversion errors; consider using 'strtol' instead. */ 21 | } else { 22 | /* Handle error */ 23 | } 24 | } 25 | 26 | This check corresponds to the CERT C Coding Standard rule 27 | `ERR34-C. Detect errors when converting a string to a number 28 | `_. 29 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/cert-err52-cpp.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - cert-err52-cpp 2 | 3 | cert-err52-cpp 4 | ============== 5 | 6 | This check flags all call expressions involving ``setjmp()`` and ``longjmp()``. 7 | 8 | This check corresponds to the CERT C++ Coding Standard rule 9 | `ERR52-CPP. Do not use setjmp() or longjmp() 10 | `_. 11 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/cert-err58-cpp.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - cert-err58-cpp 2 | 3 | cert-err58-cpp 4 | ============== 5 | 6 | This check flags all ``static`` or ``thread_local`` variable declarations where 7 | the constructor for the object may throw an exception. 8 | 9 | This check corresponds to the CERT C++ Coding Standard rule 10 | `ERR58-CPP. Constructors of objects with static or thread storage duration must not throw exceptions 11 | `_. 12 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/cert-err60-cpp.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - cert-err60-cpp 2 | 3 | cert-err60-cpp 4 | ============== 5 | 6 | This check flags all throw expressions where the exception object is not nothrow 7 | copy constructible. 8 | 9 | This check corresponds to the CERT C++ Coding Standard rule 10 | `ERR60-CPP. Exception objects must be nothrow copy constructible 11 | `_. 12 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/cert-err61-cpp.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - cert-err61-cpp 2 | .. meta:: 3 | :http-equiv=refresh: 5;URL=misc-throw-by-value-catch-by-reference.html 4 | 5 | cert-err61-cpp 6 | ============== 7 | 8 | The cert-err61-cpp check is an alias, please see 9 | `misc-throw-by-value-catch-by-reference `_ 10 | for more information. 11 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/cert-fio38-c.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - cert-fio38-c 2 | .. meta:: 3 | :http-equiv=refresh: 5;URL=misc-non-copyable-objects.html 4 | 5 | cert-fio38-c 6 | ============ 7 | 8 | The cert-fio38-c check is an alias, please see 9 | `misc-non-copyable-objects `_ for more 10 | information. 11 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/cert-flp30-c.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - cert-flp30-c 2 | 3 | cert-flp30-c 4 | ============ 5 | 6 | This check flags ``for`` loops where the induction expression has a 7 | floating-point type. 8 | 9 | This check corresponds to the CERT C Coding Standard rule 10 | `FLP30-C. Do not use floating-point variables as loop counters 11 | `_. 12 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/cert-oop11-cpp.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - cert-oop11-cpp 2 | .. meta:: 3 | :http-equiv=refresh: 5;URL=misc-move-constructor-init.html 4 | 5 | cert-oop11-cpp 6 | ============== 7 | 8 | The cert-oop11-cpp check is an alias, please see 9 | `misc-move-constructor-init `_ for more 10 | information. 11 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/cppcoreguidelines-interfaces-global-init.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - cppcoreguidelines-interfaces-global-init 2 | 3 | cppcoreguidelines-interfaces-global-init 4 | ======================================== 5 | 6 | This check flags initializers of globals that access extern objects, 7 | and therefore can lead to order-of-initialization problems. 8 | 9 | This rule is part of the "Interfaces" profile of the C++ Core Guidelines, see 10 | https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Ri-global-init 11 | 12 | Note that currently this does not flag calls to non-constexpr functions, and 13 | therefore globals could still be accessed from functions themselves. 14 | 15 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/cppcoreguidelines-pro-bounds-array-to-pointer-decay.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - cppcoreguidelines-pro-bounds-array-to-pointer-decay 2 | 3 | cppcoreguidelines-pro-bounds-array-to-pointer-decay 4 | =================================================== 5 | 6 | This check flags all array to pointer decays. 7 | 8 | Pointers should not be used as arrays. ``span`` is a bounds-checked, safe 9 | alternative to using pointers to access arrays. 10 | 11 | This rule is part of the "Bounds safety" profile of the C++ Core Guidelines, see 12 | https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Pro-bounds-decay. 13 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/cppcoreguidelines-pro-bounds-constant-array-index.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - cppcoreguidelines-pro-bounds-constant-array-index 2 | 3 | cppcoreguidelines-pro-bounds-constant-array-index 4 | ================================================= 5 | 6 | This check flags all array subscript expressions on static arrays and 7 | ``std::arrays`` that either do not have a constant integer expression index or 8 | are out of bounds (for ``std::array``). For out-of-bounds checking of static 9 | arrays, see the clang-diagnostic-array-bounds check. 10 | 11 | The check can generate fixes after the option :option:`GslHeader` has been set 12 | to the name of the include file that contains ``gsl::at()``, e.g. `"gsl/gsl.h"`. 13 | 14 | This rule is part of the "Bounds safety" profile of the C++ Core Guidelines, see 15 | https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Pro-bounds-arrayindex. 16 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/cppcoreguidelines-pro-bounds-pointer-arithmetic.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - cppcoreguidelines-pro-bounds-pointer-arithmetic 2 | 3 | cppcoreguidelines-pro-bounds-pointer-arithmetic 4 | =============================================== 5 | 6 | This check flags all usage of pointer arithmetic, because it could lead to an 7 | invalid pointer. Subtraction of two pointers is not flagged by this check. 8 | 9 | Pointers should only refer to single objects, and pointer arithmetic is fragile 10 | and easy to get wrong. ``span`` is a bounds-checked, safe type for accessing 11 | arrays of data. 12 | 13 | This rule is part of the "Bounds safety" profile of the C++ Core Guidelines, see 14 | https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Pro-bounds-arithmetic. 15 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/cppcoreguidelines-pro-type-const-cast.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - cppcoreguidelines-pro-type-const-cast 2 | 3 | cppcoreguidelines-pro-type-const-cast 4 | ===================================== 5 | 6 | This check flags all uses of ``const_cast`` in C++ code. 7 | 8 | Modifying a variable that was declared const is undefined behavior, even with 9 | ``const_cast``. 10 | 11 | This rule is part of the "Type safety" profile of the C++ Core Guidelines, see 12 | https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Pro-type-constcast. 13 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/cppcoreguidelines-pro-type-cstyle-cast.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - cppcoreguidelines-pro-type-cstyle-cast 2 | 3 | cppcoreguidelines-pro-type-cstyle-cast 4 | ====================================== 5 | 6 | This check flags all use of C-style casts that perform a ``static_cast`` 7 | downcast, ``const_cast``, or ``reinterpret_cast``. 8 | 9 | Use of these casts can violate type safety and cause the program to access a 10 | variable that is actually of type X to be accessed as if it were of an unrelated 11 | type Z. Note that a C-style ``(T)expression`` cast means to perform the first of 12 | the following that is possible: a ``const_cast``, a ``static_cast``, a 13 | ``static_cast`` followed by a ``const_cast``, a ``reinterpret_cast``, or a 14 | ``reinterpret_cast`` followed by a ``const_cast``. This rule bans 15 | ``(T)expression`` only when used to perform an unsafe cast. 16 | 17 | This rule is part of the "Type safety" profile of the C++ Core Guidelines, see 18 | https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Pro-type-cstylecast. 19 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/cppcoreguidelines-pro-type-reinterpret-cast.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - cppcoreguidelines-pro-type-reinterpret-cast 2 | 3 | cppcoreguidelines-pro-type-reinterpret-cast 4 | =========================================== 5 | 6 | This check flags all uses of ``reinterpret_cast`` in C++ code. 7 | 8 | Use of these casts can violate type safety and cause the program to access a 9 | variable that is actually of type ``X`` to be accessed as if it were of an 10 | unrelated type ``Z``. 11 | 12 | This rule is part of the "Type safety" profile of the C++ Core Guidelines, see 13 | https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Pro-type-reinterpretcast. 14 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/cppcoreguidelines-pro-type-static-cast-downcast.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - cppcoreguidelines-pro-type-static-cast-downcast 2 | 3 | cppcoreguidelines-pro-type-static-cast-downcast 4 | =============================================== 5 | 6 | This check flags all usages of ``static_cast``, where a base class is casted to 7 | a derived class. In those cases, a fixit is provided to convert the cast to a 8 | ``dynamic_cast``. 9 | 10 | Use of these casts can violate type safety and cause the program to access a 11 | variable that is actually of type ``X`` to be accessed as if it were of an 12 | unrelated type ``Z``. 13 | 14 | This rule is part of the "Type safety" profile of the C++ Core Guidelines, see 15 | https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Pro-type-downcast. 16 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/cppcoreguidelines-pro-type-union-access.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - cppcoreguidelines-pro-type-union-access 2 | 3 | cppcoreguidelines-pro-type-union-access 4 | ======================================= 5 | 6 | This check flags all access to members of unions. Passing unions as a whole is 7 | not flagged. 8 | 9 | Reading from a union member assumes that member was the last one written, and 10 | writing to a union member assumes another member with a nontrivial destructor 11 | had its destructor called. This is fragile because it cannot generally be 12 | enforced to be safe in the language and so relies on programmer discipline to 13 | get it right. 14 | 15 | This rule is part of the "Type safety" profile of the C++ Core Guidelines, see 16 | https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Pro-type-unions. 17 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/cppcoreguidelines-pro-type-vararg.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - cppcoreguidelines-pro-type-vararg 2 | 3 | cppcoreguidelines-pro-type-vararg 4 | ================================= 5 | 6 | This check flags all calls to c-style vararg functions and all use of 7 | ``va_arg``. 8 | 9 | To allow for SFINAE use of vararg functions, a call is not flagged if a literal 10 | 0 is passed as the only vararg argument. 11 | 12 | Passing to varargs assumes the correct type will be read. This is fragile 13 | because it cannot generally be enforced to be safe in the language and so relies 14 | on programmer discipline to get it right. 15 | 16 | This rule is part of the "Type safety" profile of the C++ Core Guidelines, see 17 | https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Pro-type-varargs. 18 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/google-build-explicit-make-pair.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - google-build-explicit-make-pair 2 | 3 | google-build-explicit-make-pair 4 | =============================== 5 | 6 | Check that ``make_pair``'s template arguments are deduced. 7 | 8 | G++ 4.6 in C++11 mode fails badly if ``make_pair``'s template arguments are 9 | specified explicitly, and such use isn't intended in any case. 10 | 11 | Corresponding cpplint.py check name: `build/explicit_make_pair`. 12 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/google-build-namespaces.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - google-build-namespaces 2 | 3 | google-build-namespaces 4 | ======================= 5 | 6 | `cert-dcl59-cpp` redirects here as an alias for this check. 7 | 8 | Finds anonymous namespaces in headers. 9 | 10 | https://google.github.io/styleguide/cppguide.html#Namespaces 11 | 12 | Corresponding cpplint.py check name: `build/namespaces`. 13 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/google-build-using-namespace.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - google-build-using-namespace 2 | 3 | google-build-using-namespace 4 | ============================ 5 | 6 | Finds ``using namespace`` directives. 7 | 8 | https://google.github.io/styleguide/cppguide.html#Namespaces 9 | 10 | The check implements the following rule of the Google C++ Style Guide: 11 | 12 | You may not use a using-directive to make all names from a namespace 13 | available. 14 | 15 | .. code:: c++ 16 | 17 | // Forbidden -- This pollutes the namespace. 18 | using namespace foo; 19 | 20 | Corresponding cpplint.py check name: `build/namespaces`. 21 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/google-default-arguments.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - google-default-arguments 2 | 3 | google-default-arguments 4 | ======================== 5 | 6 | Checks that default arguments are not given for virtual methods. 7 | 8 | See https://google.github.io/styleguide/cppguide.html#Default_Arguments 9 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/google-explicit-constructor.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - google-explicit-constructor 2 | 3 | google-explicit-constructor 4 | =========================== 5 | 6 | 7 | Checks that all single-argument constructors are explicit. 8 | 9 | See https://google.github.io/styleguide/cppguide.html#Explicit_Constructors 10 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/google-global-names-in-headers.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - google-global-names-in-headers 2 | 3 | google-global-names-in-headers 4 | ============================== 5 | 6 | Flag global namespace pollution in header files. 7 | Right now it only triggers on ``using`` declarations and directives. 8 | 9 | The check supports these options: 10 | - `HeaderFileExtensions`: a comma-separated list of filename extensions 11 | of header files (the filename extensions should not contain "." prefix). 12 | "h" by default. 13 | For extension-less header files, using an empty string or leaving an 14 | empty string between "," if there are other filename extensions. 15 | 16 | The relevant style guide section is 17 | https://google.github.io/styleguide/cppguide.html#Namespaces. 18 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/google-readability-braces-around-statements.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - google-readability-braces-around-statements 2 | .. meta:: 3 | :http-equiv=refresh: 5;URL=readability-braces-around-statements.html 4 | 5 | google-readability-braces-around-statements 6 | =========================================== 7 | 8 | The google-readability-braces-around-statements check is an alias, please see 9 | `readability-braces-around-statements `_ 10 | for more information. 11 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/google-readability-casting.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - google-readability-casting 2 | 3 | google-readability-casting 4 | ========================== 5 | 6 | Finds usages of C-style casts. 7 | 8 | https://google.github.io/styleguide/cppguide.html#Casting 9 | 10 | Corresponding cpplint.py check name: `readability/casting`. 11 | 12 | This check is similar to `-Wold-style-cast`, but it suggests automated fixes 13 | in some cases. The reported locations should not be different from the 14 | ones generated by `-Wold-style-cast`. 15 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/google-readability-function-size.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - google-readability-function-size 2 | .. meta:: 3 | :http-equiv=refresh: 5;URL=readability-function-size.html 4 | 5 | google-readability-function-size 6 | ================================ 7 | 8 | The google-readability-function-size check is an alias, please see 9 | `readability-function-size `_ for more 10 | information. 11 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/google-readability-namespace-comments.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - google-readability-namespace-comments 2 | 3 | google-readability-namespace-comments 4 | ===================================== 5 | 6 | 7 | Checks that long namespaces have a closing comment. 8 | 9 | http://llvm.org/docs/CodingStandards.html#namespace-indentation 10 | 11 | https://google.github.io/styleguide/cppguide.html#Namespaces 12 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/google-readability-redundant-smartptr-get.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - google-readability-redundant-smartptr-get 2 | 3 | google-readability-redundant-smartptr-get 4 | ========================================= 5 | 6 | 7 | Find and remove redundant calls to smart pointer's ``.get()`` method. 8 | 9 | Examples: 10 | 11 | .. code:: c++ 12 | 13 | ptr.get()->Foo() ==> ptr->Foo() 14 | *ptr.get() ==> *ptr 15 | *ptr->get() ==> **ptr 16 | 17 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/google-readability-todo.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - google-readability-todo 2 | 3 | google-readability-todo 4 | ======================= 5 | 6 | Finds TODO comments without a username or bug number. 7 | 8 | The relevant style guide section is 9 | https://google.github.io/styleguide/cppguide.html#TODO_Comments. 10 | 11 | Corresponding cpplint.py check: `readability/todo` 12 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/google-runtime-int.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - google-runtime-int 2 | 3 | google-runtime-int 4 | ================== 5 | 6 | Finds uses of ``short``, ``long`` and ``long long`` and suggest replacing them 7 | with ``u?intXX(_t)?``. 8 | 9 | The corresponding style guide rule: 10 | https://google.github.io/styleguide/cppguide.html#Integer_Types. 11 | 12 | Correspondig cpplint.py check: `runtime/int`. 13 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/google-runtime-member-string-references.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - google-runtime-member-string-references 2 | 3 | google-runtime-member-string-references 4 | ======================================= 5 | 6 | Finds members of type ``const string&``. 7 | 8 | const string reference members are generally considered unsafe as they can 9 | be created from a temporary quite easily. 10 | 11 | .. code:: c++ 12 | 13 | struct S { 14 | S(const string &Str) : Str(Str) {} 15 | const string &Str; 16 | }; 17 | S instance("string"); 18 | 19 | In the constructor call a string temporary is created from ``const char *`` 20 | and destroyed immediately after the call. This leaves around a dangling 21 | reference. 22 | 23 | This check emit warnings for both ``std::string`` and ``::string`` const 24 | reference members. 25 | 26 | Corresponding cpplint.py check name: `runtime/member_string_reference`. 27 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/google-runtime-memset.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - google-runtime-memset 2 | 3 | google-runtime-memset 4 | ===================== 5 | 6 | Finds calls to ``memset`` with a literal zero in the length argument. 7 | 8 | This is most likely unintended and the length and value arguments are swapped. 9 | 10 | Corresponding cpplint.py check name: `runtime/memset`. 11 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/google-runtime-operator.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - google-runtime-operator 2 | 3 | google-runtime-operator 4 | ======================= 5 | 6 | Finds overloads of unary ``operator &``. 7 | 8 | https://google.github.io/styleguide/cppguide.html#Operator_Overloading 9 | 10 | Corresponding cpplint.py check name: `runtime/operator`. 11 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/google-runtime-references.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - google-runtime-references 2 | 3 | google-runtime-references 4 | ========================= 5 | 6 | Checks the usage of non-constant references in function parameters. 7 | 8 | The corresponding style guide rule: 9 | https://google.github.io/styleguide/cppguide.html#Reference_Arguments 10 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/llvm-header-guard.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - llvm-header-guard 2 | 3 | llvm-header-guard 4 | ================= 5 | 6 | TODO: add docs 7 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/llvm-include-order.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - llvm-include-order 2 | 3 | llvm-include-order 4 | ================== 5 | 6 | 7 | Checks the correct order of ``#includes``. 8 | 9 | See http://llvm.org/docs/CodingStandards.html#include-style 10 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/llvm-namespace-comment.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - llvm-namespace-comment 2 | 3 | llvm-namespace-comment 4 | ====================== 5 | 6 | 7 | Checks that long namespaces have a closing comment. 8 | 9 | http://llvm.org/docs/CodingStandards.html#namespace-indentation 10 | 11 | https://google.github.io/styleguide/cppguide.html#Namespaces 12 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/llvm-twine-local.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - llvm-twine-local 2 | 3 | llvm-twine-local 4 | ================ 5 | 6 | 7 | Looks for local ``Twine`` variables which are prone to use after frees and 8 | should be generally avoided. 9 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-argument-comment.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-argument-comment 2 | 3 | misc-argument-comment 4 | ===================== 5 | 6 | 7 | Checks that argument comments match parameter names. 8 | 9 | The check understands argument comments in the form ``/*parameter_name=*/`` 10 | that are placed right before the argument. 11 | 12 | .. code:: c++ 13 | 14 | void f(bool foo); 15 | 16 | ... 17 | f(/*bar=*/true); 18 | // warning: argument name 'bar' in comment does not match parameter name 'foo' 19 | 20 | The check tries to detect typos and suggest automated fixes for them. 21 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-assert-side-effect.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-assert-side-effect 2 | 3 | misc-assert-side-effect 4 | ======================= 5 | 6 | Finds ``assert()`` with side effect. 7 | 8 | The condition of ``assert()`` is evaluated only in debug builds so a 9 | condition with side effect can cause different behavior in debug / release 10 | builds. 11 | 12 | There are two options: 13 | 14 | - :option:`AssertMacros`: A comma-separated list of the names of assert macros 15 | to be checked. 16 | - :option:`CheckFunctionCalls`: Whether to treat non-const member and 17 | non-member functions as they produce side effects. Disabled by default 18 | because it can increase the number of false positive warnings. 19 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-bool-pointer-implicit-conversion.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-bool-pointer-implicit-conversion 2 | 3 | misc-bool-pointer-implicit-conversion 4 | ===================================== 5 | 6 | Checks for conditions based on implicit conversion from a ``bool`` pointer to 7 | ``bool``. 8 | 9 | Example: 10 | 11 | .. code:: c++ 12 | 13 | bool *p; 14 | if (p) { 15 | // Never used in a pointer-specific way. 16 | } 17 | 18 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-dangling-handle.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-dangling-handle 2 | 3 | misc-dangling-handle 4 | ==================== 5 | 6 | Detect dangling references in value handlers like 7 | ``std::experimental::string_view``. 8 | These dangling references can come from constructing handles from temporary 9 | values, where the temporary is destroyed soon after the handle is created. 10 | 11 | By default only ``std::experimental::basic_string_view`` is considered. 12 | This list can be modified by passing a `;` separated list of class names using 13 | the HandleClasses option. 14 | 15 | Examples: 16 | 17 | .. code-block:: c++ 18 | 19 | string_view View = string(); // View will dangle. 20 | string A; 21 | View = A + "A"; // still dangle. 22 | 23 | vector V; 24 | V.push_back(string()); // V[0] is dangling. 25 | V.resize(3, string()); // V[1] and V[2] will also dangle. 26 | 27 | string_view f() { 28 | // All these return values will dangle. 29 | return string(); 30 | string S; 31 | return S; 32 | char Array[10]{}; 33 | return Array; 34 | } 35 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-fold-init-type.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-fold-init-type 2 | 3 | misc-fold-init-type 4 | =================== 5 | 6 | The check flags type mismatches in 7 | `folds `_ 8 | like ``std::accumulate`` that might result in loss of precision. 9 | ``std::accumulate`` folds an input range into an initial value using the type of 10 | the latter, with ``operator+`` by default. This can cause loss of precision 11 | through: 12 | 13 | - Truncation: The following code uses a floating point range and an int 14 | initial value, so trucation wil happen at every application of ``operator+`` 15 | and the result will be `0`, which might not be what the user expected. 16 | 17 | .. code:: c++ 18 | 19 | auto a = {0.5f, 0.5f, 0.5f, 0.5f}; 20 | return std::accumulate(std::begin(a), std::end(a), 0); 21 | 22 | - Overflow: The following code also returns `0`. 23 | 24 | .. code:: c++ 25 | 26 | auto a = {65536LL * 65536 * 65536}; 27 | return std::accumulate(std::begin(a), std::end(a), 0); 28 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-forward-declaration-namespace.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-forward-declaration-namespace 2 | 3 | misc-forward-declaration-namespace 4 | ================================== 5 | 6 | Checks if an unused forward declaration is in a wrong namespace. 7 | 8 | The check inspects all unused forward declarations and checks if there is any 9 | declaration/definition with the same name existing, which could indicate that 10 | the forward declaration is in a potentially wrong namespace. 11 | 12 | .. code:: c++ 13 | 14 | namespace na { struct A; } 15 | namespace nb { struct A {}; } 16 | nb::A a; 17 | // warning : no definition found for 'A', but a definition with the same name 18 | // 'A' found in another namespace 'nb::' 19 | 20 | This check can only generate warnings, but it can't suggest a fix at this point. 21 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-inaccurate-erase.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-inaccurate-erase 2 | 3 | misc-inaccurate-erase 4 | ===================== 5 | 6 | 7 | Checks for inaccurate use of the ``erase()`` method. 8 | 9 | Algorithms like ``remove()`` do not actually remove any element from the 10 | container but return an iterator to the first redundant element at the end 11 | of the container. These redundant elements must be removed using the 12 | ``erase()`` method. This check warns when not all of the elements will be 13 | removed due to using an inappropriate overload. 14 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-incorrect-roundings.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-incorrect-roundings 2 | 3 | misc-incorrect-roundings 4 | ======================== 5 | 6 | Checks the usage of patterns known to produce incorrect rounding. 7 | Programmers often use:: 8 | 9 | (int)(double_expression + 0.5) 10 | 11 | to round the double expression to an integer. The problem with this: 12 | 13 | 1. It is unnecessarily slow. 14 | 2. It is incorrect. The number 0.499999975 (smallest representable float 15 | number below 0.5) rounds to 1.0. Even worse behavior for negative 16 | numbers where both -0.5f and -1.4f both round to 0.0. 17 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-inefficient-algorithm.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-inefficient-algorithm 2 | 3 | misc-inefficient-algorithm 4 | ========================== 5 | 6 | 7 | Warns on inefficient use of STL algorithms on associative containers. 8 | 9 | Associative containers implements some of the algorithms as methods which 10 | should be preferred to the algorithms in the algorithm header. The methods 11 | can take advanatage of the order of the elements. 12 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-macro-parentheses.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-macro-parentheses 2 | 3 | misc-macro-parentheses 4 | ====================== 5 | 6 | 7 | Finds macros that can have unexpected behaviour due to missing parentheses. 8 | 9 | Macros are expanded by the preprocessor as-is. As a result, there can be 10 | unexpected behaviour; operators may be evaluated in unexpected order and 11 | unary operators may become binary operators, etc. 12 | 13 | When the replacement list has an expression, it is recommended to surround 14 | it with parentheses. This ensures that the macro result is evaluated 15 | completely before it is used. 16 | 17 | It is also recommended to surround macro arguments in the replacement list 18 | with parentheses. This ensures that the argument value is calculated 19 | properly. 20 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-macro-repeated-side-effects.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-macro-repeated-side-effects 2 | 3 | misc-macro-repeated-side-effects 4 | ================================ 5 | 6 | 7 | Checks for repeated argument with side effects in macros. 8 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-move-const-arg.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-move-const-arg 2 | 3 | misc-move-const-arg 4 | =================== 5 | 6 | The check warns if ``std::move()`` is called with a constant argument or an 7 | argument of a trivially-copyable type, e.g.: 8 | 9 | .. code:: c++ 10 | 11 | const string s; 12 | return std::move(s); // Warning: std::move of the const variable has no effect 13 | 14 | int x; 15 | return std::move(x); // Warning: std::move of the variable of a trivially-copyable type has no effect 16 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-move-constructor-init.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-move-constructor-init 2 | 3 | misc-move-constructor-init 4 | ========================== 5 | 6 | "cert-oop11-cpp" redirects here as an alias for this check. 7 | 8 | The check flags user-defined move constructors that have a ctor-initializer 9 | initializing a member or base class through a copy constructor instead of a 10 | move constructor. 11 | 12 | It also flags constructor arguments that are passed by value, have a non-deleted 13 | move-constructor and are assigned to a class field by copy construction. 14 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-multiple-statement-macro.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-multiple-statement-macro 2 | 3 | misc-multiple-statement-macro 4 | ============================= 5 | 6 | Detect multiple statement macros that are used in unbraced conditionals. 7 | Only the first statement of the macro will be inside the conditional and the other ones will be executed unconditionally. 8 | 9 | Example: 10 | 11 | .. code:: c++ 12 | 13 | #define INCREMENT_TWO(x, y) (x)++; (y)++ 14 | if (do_increment) 15 | INCREMENT_TWO(a, b); // `(b)++;` will be executed unconditionally. 16 | 17 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-new-delete-overloads.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-new-delete-overloads 2 | 3 | misc-new-delete-overloads 4 | ========================= 5 | 6 | `cert-dcl54-cpp` redirects here as an alias for this check. 7 | 8 | The check flags overloaded operator ``new()`` and operator ``delete()`` 9 | functions that do not have a corresponding free store function defined within 10 | the same scope. 11 | For instance, the check will flag a class implementation of a non-placement 12 | operator ``new()`` when the class does not also define a non-placement operator 13 | ``delete()`` function as well. 14 | 15 | The check does not flag implicitly-defined operators, deleted or private 16 | operators, or placement operators. 17 | 18 | This check corresponds to CERT C++ Coding Standard rule `DCL54-CPP. Overload allocation and deallocation functions as a pair in the same scope 19 | `_. 20 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-noexcept-move-constructor.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-noexcept-move-constructor 2 | 3 | misc-noexcept-move-constructor 4 | ============================== 5 | 6 | 7 | The check flags user-defined move constructors and assignment operators not 8 | marked with ``noexcept`` or marked with ``noexcept(expr)`` where ``expr`` 9 | evaluates to ``false`` (but is not a ``false`` literal itself). 10 | 11 | Move constructors of all the types used with STL containers, for example, 12 | need to be declared ``noexcept``. Otherwise STL will choose copy constructors 13 | instead. The same is valid for move assignment operations. 14 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-non-copyable-objects.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-non-copyable-objects 2 | 3 | misc-non-copyable-objects 4 | ========================= 5 | 6 | `cert-fio38-c` redirects here as an alias for this check. 7 | 8 | The check flags dereferences and non-pointer declarations of objects that are 9 | not meant to be passed by value, such as C FILE objects or POSIX 10 | ``pthread_mutex_t`` objects. 11 | 12 | This check corresponds to CERT C++ Coding Standard rule `FIO38-C. Do not copy a FILE object 13 | `_. 14 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-pointer-and-integral-operation.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-pointer-and-integral-operation 2 | 3 | misc-pointer-and-integral-operation 4 | =================================== 5 | 6 | Looks for operation involving pointers and integral types. A common mistake is 7 | to forget to dereference a pointer. These errors may be detected when a pointer 8 | object is compare to an object with integral type. 9 | 10 | Examples: 11 | 12 | .. code:: c++ 13 | 14 | char* ptr; 15 | if ((ptr = malloc(...)) < nullptr) // Pointer comparison with operator '<' 16 | ... // Should probably be '!=' 17 | 18 | if (ptr == '\0') // Should probably be *ptr 19 | ... 20 | 21 | void Process(std::string path, bool* error) { 22 | [...] 23 | if (error != false) // Should probably be *error 24 | ... 25 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-redundant-expression.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-redundant-expression 2 | 3 | misc-redundant-expression 4 | ========================= 5 | 6 | Detect redundant expressions which are typically errors due to copy-paste. 7 | 8 | Depending on the operator expressions may be 9 | * redundant, 10 | * always be `true`, 11 | * always be `false`, 12 | * always be a constant (zero or one) 13 | 14 | Example: 15 | 16 | .. code:: c++ 17 | 18 | ((x+1) | (x+1)) // (x+1) is redundant 19 | (p->x == p->x) // always true 20 | (p->x < p->x) // always false 21 | (speed - speed + 1 == 12) // speed - speed is always zero 22 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-sizeof-container.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-sizeof-container 2 | 3 | misc-sizeof-container 4 | ===================== 5 | 6 | The check finds usages of ``sizeof`` on expressions of STL container types. Most 7 | likely the user wanted to use ``.size()`` instead. 8 | 9 | All class/struct types declared in namespace ``std::`` having a const ``size()`` 10 | method are considered containers, with the exception of ``std::bitset`` and 11 | ``std::array``. 12 | 13 | Examples: 14 | 15 | .. code:: c++ 16 | 17 | std::string s; 18 | int a = 47 + sizeof(s); // warning: sizeof() doesn't return the size of the container. Did you mean .size()? 19 | 20 | int b = sizeof(std::string); // no warning, probably intended. 21 | 22 | std::string array_of_strings[10]; 23 | int c = sizeof(array_of_strings) / sizeof(array_of_strings[0]); // no warning, definitely intended. 24 | 25 | std::array std_array; 26 | int d = sizeof(std_array); // no warning, probably intended. 27 | 28 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-static-assert.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-static-assert 2 | 3 | misc-static-assert 4 | ================== 5 | 6 | `cert-dcl03-c` redirects here as an alias for this check. 7 | 8 | Replaces ``assert()`` with ``static_assert()`` if the condition is evaluatable 9 | at compile time. 10 | 11 | The condition of ``static_assert()`` is evaluated at compile time which is 12 | safer and more efficient. 13 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-string-constructor.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-string-constructor 2 | 3 | misc-string-constructor 4 | ======================= 5 | 6 | Finds string constructors that are suspicious and probably errors. 7 | 8 | A common mistake is to swap parameters to the 'fill' string-constructor. 9 | 10 | Examples: 11 | 12 | .. code:: c++ 13 | 14 | std::string('x', 50) str; // should be std::string(50, 'x') 15 | 16 | 17 | Calling the string-literal constructor with a length bigger than the literal is 18 | suspicious and adds extra random characters to the string. 19 | 20 | Examples: 21 | 22 | .. code:: c++ 23 | 24 | std::string("test", 200); // Will include random characters after "test". 25 | 26 | 27 | Creating an empty string from constructors with parameters is considered 28 | suspicious. The programmer should use the empty constructor instead. 29 | 30 | Examples: 31 | 32 | .. code:: c++ 33 | 34 | std::string("test", 0); // Creation of an empty string. 35 | 36 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-string-integer-assignment.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-string-integer-assignment 2 | 3 | misc-string-integer-assignment 4 | ============================== 5 | 6 | The check finds assignments of an integer to ``std::basic_string`` 7 | (``std::string``, ``std::wstring``, etc.). The source of the problem is the 8 | following assignment operator of ``std::basic_string``: 9 | 10 | .. code:: c++ 11 | 12 | basic_string& operator=( CharT ch ); 13 | 14 | Numeric types can be implicitly casted to character types. 15 | 16 | .. code:: c++ 17 | 18 | std::string s; 19 | int x = 5965; 20 | s = 6; 21 | s = x; 22 | 23 | Use the appropriate conversion functions or character literals. 24 | 25 | .. code:: c++ 26 | 27 | std::string s; 28 | int x = 5965; 29 | s = '6'; 30 | s = std::to_string(x); 31 | 32 | In order to suppress false positives, use an explicit cast. 33 | 34 | .. code:: c++ 35 | 36 | std::string s; 37 | s = static_cast(6); 38 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-swapped-arguments.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-swapped-arguments 2 | 3 | misc-swapped-arguments 4 | ====================== 5 | 6 | 7 | Finds potentially swapped arguments by looking at implicit conversions. 8 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-unconventional-assign-operator.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-unconventional-assign-operator 2 | 3 | misc-unconventional-assign-operator 4 | =================================== 5 | 6 | 7 | Finds declarations of assign operators with the wrong return and/or argument 8 | types and definitions with good return type but wrong return statements. 9 | 10 | * The return type must be ``Class&``. 11 | * Works with move-assign and assign by value. 12 | * Private and deleted operators are ignored. 13 | * The operator must always return ``*this``. 14 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-undelegated-constructor.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-undelegated-constructor 2 | 3 | misc-undelegated-constructor 4 | ============================ 5 | 6 | 7 | Finds creation of temporary objects in constructors that look like a 8 | function call to another constructor of the same class. 9 | 10 | The user most likely meant to use a delegating constructor or base class 11 | initializer. 12 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-uniqueptr-reset-release.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-uniqueptr-reset-release 2 | 3 | misc-uniqueptr-reset-release 4 | ============================ 5 | 6 | 7 | Find and replace ``unique_ptr::reset(release())`` with ``std::move()``. 8 | 9 | Example: 10 | 11 | .. code:: c++ 12 | 13 | std::unique_ptr x, y; 14 | x.reset(y.release()); -> x = std::move(y); 15 | 16 | If ``y`` is already rvalue, ``std::move()`` is not added. ``x`` and ``y`` can also 17 | be ``std::unique_ptr*``. 18 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-unused-alias-decls.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-unused-alias-decls 2 | 3 | misc-unused-alias-decls 4 | ======================= 5 | 6 | 7 | Finds unused namespace alias declarations. 8 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-unused-parameters.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-unused-parameters 2 | 3 | misc-unused-parameters 4 | ====================== 5 | 6 | Finds unused parameters and fixes them, so that `-Wunused-parameter` can be 7 | turned on. 8 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-unused-raii.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-unused-raii 2 | 3 | misc-unused-raii 4 | ================ 5 | 6 | 7 | Finds temporaries that look like RAII objects. 8 | 9 | The canonical example for this is a scoped lock. 10 | 11 | .. code:: c++ 12 | 13 | { 14 | scoped_lock(&global_mutex); 15 | critical_section(); 16 | } 17 | 18 | The destructor of the scoped_lock is called before the ``critical_section`` is 19 | entered, leaving it unprotected. 20 | 21 | We apply a number of heuristics to reduce the false positive count of this 22 | check: 23 | 24 | * Ignore code expanded from macros. Testing frameworks make heavy use of this. 25 | * Ignore types with trivial destructors. They are very unlikely to be RAII 26 | objects and there's no difference when they are deleted. 27 | * Ignore objects at the end of a compound statement (doesn't change behavior). 28 | * Ignore objects returned from a call. 29 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-unused-using-decls.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-unused-using-decls 2 | 3 | misc-unused-using-decls 4 | ======================= 5 | 6 | Finds unused ``using`` declarations. 7 | 8 | Example: 9 | 10 | .. code:: c++ 11 | 12 | namespace n { class C; } 13 | using n::C; // Never actually used. 14 | 15 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/misc-virtual-near-miss.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - misc-virtual-near-miss 2 | 3 | misc-virtual-near-miss 4 | ====================== 5 | 6 | Warn if a function is a near miss (ie. the name is very similar and the function 7 | signiture is the same) to a virtual function from a base class. 8 | 9 | Example: 10 | 11 | .. code-block:: c++ 12 | 13 | struct Base { 14 | virtual void func(); 15 | }; 16 | 17 | struct Derived : Base { 18 | virtual funk(); 19 | // warning: 'Derived::funk' has a similar name and the same signature as virtual method 'Base::func'; did you mean to override it? 20 | }; 21 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/modernize-avoid-bind.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - modernize-avoid-bind 2 | 3 | modernize-avoid-bind 4 | ==================== 5 | 6 | The check finds uses of ``std::bind`` and replaces simple uses with lambdas. 7 | Lambdas will use value-capture where required. 8 | 9 | Right now it only handles free functions, not member functions. 10 | 11 | Given: 12 | 13 | .. code:: c++ 14 | 15 | int add(int x, int y) { return x + y; } 16 | 17 | Then: 18 | 19 | .. code:: c++ 20 | 21 | void f() { 22 | int x = 2; 23 | auto clj = std::bind(add, x, _1); 24 | } 25 | 26 | is replaced by: 27 | 28 | .. code:: c++ 29 | 30 | void f() { 31 | int x = 2; 32 | auto clj = [=](auto && arg1) { return add(x, arg1); }; 33 | } 34 | 35 | ``std::bind`` can be hard to read and can result in larger object files and 36 | binaries due to type information that will not be produced by equivalent 37 | lambdas. 38 | 39 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/modernize-make-shared.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - modernize-make-shared 2 | 3 | modernize-make-shared 4 | ===================== 5 | 6 | This check finds the creation of ``std::shared_ptr`` objects by explicitly 7 | calling the constructor and a ``new`` expression, and replaces it with a call 8 | to ``std::make_shared``. 9 | 10 | .. code-block:: c++ 11 | 12 | auto my_ptr = std::shared_ptr(new MyPair(1, 2)); 13 | 14 | // becomes 15 | 16 | auto my_ptr = std::make_shared(1, 2); 17 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/modernize-make-unique.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - modernize-make-unique 2 | 3 | modernize-make-unique 4 | ===================== 5 | 6 | This check finds the creation of ``std::unique_ptr`` objects by explicitly 7 | calling the constructor and a ``new`` expression, and replaces it with a call 8 | to ``std::make_unique``, introduced in C++14. 9 | 10 | .. code-block:: c++ 11 | 12 | auto my_ptr = std::unique_ptr(new MyPair(1, 2)); 13 | 14 | // becomes 15 | 16 | auto my_ptr = std::make_unique(1, 2); 17 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/modernize-redundant-void-arg.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - modernize-redundant-void-arg 2 | 3 | modernize-redundant-void-arg 4 | ============================ 5 | 6 | Find and remove redundant ``void`` argument lists. 7 | 8 | Examples: 9 | =================================== =========================== 10 | Initial code Code with applied fixes 11 | =================================== =========================== 12 | ``int f(void);`` ``int f();`` 13 | ``int (*f(void))(void);`` ``int (*f())();`` 14 | ``typedef int (*f_t(void))(void);`` ``typedef int (*f_t())();`` 15 | ``void (C::*p)(void);`` ``void (C::*p)();`` 16 | ``C::C(void) {}`` ``C::C() {}`` 17 | ``C::~C(void) {}`` ``C::~C() {}`` 18 | =================================== =========================== 19 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/modernize-shrink-to-fit.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - modernize-shrink-to-fit 2 | 3 | modernize-shrink-to-fit 4 | ======================= 5 | 6 | 7 | Replace copy and swap tricks on shrinkable containers with the 8 | ``shrink_to_fit()`` method call. 9 | 10 | The ``shrink_to_fit()`` method is more readable and more effective than 11 | the copy and swap trick to reduce the capacity of a shrinkable container. 12 | Note that, the ``shrink_to_fit()`` method is only available in C++11 and up. 13 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/modernize-use-bool-literals.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - modernize-use-bool-literals 2 | 3 | modernize-use-bool-literals 4 | =========================== 5 | 6 | Finds integer literals which are cast to ``bool``. 7 | 8 | .. code-block:: c++ 9 | 10 | bool p = 1; 11 | bool f = static_cast(1); 12 | std::ios_base::sync_with_stdio(0); 13 | 14 | // transforms to 15 | 16 | bool p = true; 17 | bool f = true; 18 | std::ios_base::sync_with_stdio(false); 19 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/modernize-use-default.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - modernize-use-default 2 | 3 | modernize-use-default 4 | ===================== 5 | 6 | This check replaces default bodies of special member functions with ``= 7 | default;``. The explicitly defaulted function declarations enable more 8 | opportunities in optimization, because the compiler might treat explicitly 9 | defaulted functions as trivial. 10 | 11 | .. code-block:: c++ 12 | 13 | struct A { 14 | A() {} 15 | ~A(); 16 | }; 17 | A::~A() {} 18 | 19 | // becomes 20 | 21 | struct A { 22 | A() = default; 23 | ~A(); 24 | }; 25 | A::~A() = default; 26 | 27 | .. note:: 28 | Copy-constructor, copy-assignment operator, move-constructor and 29 | move-assignment operator are not supported yet. 30 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/modernize-use-override.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - modernize-use-override 2 | 3 | modernize-use-override 4 | ====================== 5 | 6 | 7 | Use C++11's ``override`` and remove ``virtual`` where applicable. 8 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/performance-faster-string-find.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - performance-faster-string-find 2 | 3 | performance-faster-string-find 4 | ============================== 5 | 6 | Optimize calls to ``std::string::find()`` and friends when the needle passed is 7 | a single character string literal. 8 | The character literal overload is more efficient. 9 | 10 | By default only ``std::basic_string`` is considered. This list can be modified by 11 | passing a `;` separated list of class names using the `StringLikeClasses` 12 | option. The methods to consired are fixed, though. 13 | 14 | Examples: 15 | 16 | .. code-block:: c++ 17 | 18 | str.find("A"); 19 | 20 | // becomes 21 | 22 | str.find('A'); 23 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/performance-for-range-copy.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - performance-for-range-copy 2 | 3 | performance-for-range-copy 4 | ========================== 5 | 6 | Finds C++11 for ranges where the loop variable is copied in each iteration but 7 | it would suffice to obtain it by const reference. 8 | 9 | The check is only applied to loop variables of types that are expensive to copy 10 | which means they are not trivially copyable or have a non-trivial copy 11 | constructor or destructor. 12 | 13 | To ensure that it is safe to replace the copy with a const reference the 14 | following heuristic is employed: 15 | 16 | 1. The loop variable is const qualified. 17 | 2. The loop variable is not const, but only const methods or operators are 18 | invoked on it, or it is used as const reference or value argument in 19 | constructors or function calls. 20 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/performance-implicit-cast-in-loop.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - performance-implicit-cast-in-loop 2 | 3 | performance-implicit-cast-in-loop 4 | ================================= 5 | 6 | This warning appears in a range-based loop with a loop variable of const ref 7 | type where the type of the variable does not match the one returned by the 8 | iterator. 9 | This means that an implicit cast has been added, which can for example result in 10 | expensive deep copies. 11 | 12 | Example: 13 | 14 | .. code:: c++ 15 | 16 | map> my_map; 17 | for (const pair>& p : my_map) {} 18 | // The iterator type is in fact pair>, which means 19 | // that the compiler added a cast, resulting in a copy of the vectors. 20 | 21 | The easiest solution is usually to use ``const auto&`` instead of writing the type 22 | manually. 23 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/readability-avoid-const-params-in-decls.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - readability-avoid-const-params-in-decls 2 | 3 | readability-avoid-const-params-in-decls 4 | ======================================= 5 | 6 | Checks whether a function declaration has parameters that are top level const. 7 | 8 | `const` values in declarations do not affect the signature of a function, so 9 | they should not be put there. For example: 10 | 11 | Examples: 12 | 13 | .. code:: c++ 14 | 15 | void f(const string); // Bad: const is top level. 16 | void f(const string&); // Good: const is not top level. 17 | 18 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/readability-braces-around-statements.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - readability-braces-around-statements 2 | 3 | readability-braces-around-statements 4 | ==================================== 5 | 6 | `google-readability-braces-around-statements` redirects here as an alias for 7 | this check. 8 | 9 | Checks that bodies of ``if`` statements and loops (``for``, ``range-for``, 10 | ``do-while``, and ``while``) are inside braces 11 | 12 | Before: 13 | 14 | .. code:: c++ 15 | 16 | if (condition) 17 | statement; 18 | 19 | After: 20 | 21 | .. code:: c++ 22 | 23 | if (condition) { 24 | statement; 25 | } 26 | 27 | Additionally, one can define an option :option:`ShortStatementLines` defining 28 | the minimal number of lines that the statement should have in order to trigger 29 | this check. 30 | 31 | The number of lines is counted from the end of condition or initial keyword 32 | (``do``/``else``) until the last line of the inner statement. Default value 0 33 | means that braces will be added to all statements (not having them already). 34 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/readability-container-size-empty.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - readability-container-size-empty 2 | 3 | readability-container-size-empty 4 | ================================ 5 | 6 | 7 | Checks whether a call to the ``size()`` method can be replaced with a call to 8 | ``empty()``. 9 | 10 | The emptiness of a container should be checked using the ``empty()`` method 11 | instead of the ``size()`` method. It is not guaranteed that ``size()`` is a 12 | constant-time function, and it is generally more efficient and also shows 13 | clearer intent to use ``empty()``. Furthermore some containers may implement 14 | the ``empty()`` method but not implement the ``size()`` method. Using ``empty()`` 15 | whenever possible makes it easier to switch to another container in the 16 | future. 17 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/readability-deleted-default.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - readability-deleted-default 2 | 3 | readability-deleted-default 4 | =========================== 5 | 6 | Checks that constructors and assignment operators marked as ``= default`` are 7 | not actually deleted by the compiler. 8 | 9 | .. code:: c++ 10 | 11 | class Example { 12 | public: 13 | // This constructor is deleted because I is missing a default value. 14 | Example() = default; 15 | // This is fine. 16 | Example(const Example& Other) = default; 17 | // This operator is deleted because I cannot be assigned (it is const). 18 | Example& operator=(const Example& Other) = default; 19 | private: 20 | const int I; 21 | }; 22 | 23 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/readability-else-after-return.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - readability-else-after-return 2 | 3 | readability-else-after-return 4 | ============================= 5 | 6 | 7 | Flags the usages of ``else`` after ``return``. 8 | 9 | http://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return 10 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/readability-function-size.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - readability-function-size 2 | 3 | readability-function-size 4 | ========================= 5 | 6 | `google-readability-function-size` redirects here as an alias for this check. 7 | 8 | Checks for large functions based on various metrics. 9 | 10 | These options are supported: 11 | 12 | * :option:`LineThreshold` - flag functions exceeding this number of lines. The 13 | default is `-1` (ignore the number of lines). 14 | * :option:`StatementThreshold` - flag functions exceeding this number of 15 | statements. This may differ significantly from the number of lines for 16 | macro-heavy code. The default is `800`. 17 | * :option:`BranchThreshold` - flag functions exceeding this number of control 18 | statements. The default is `-1` (ignore the number of branches). 19 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/readability-identifier-naming.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - readability-identifier-naming 2 | 3 | readability-identifier-naming 4 | ============================= 5 | 6 | Checks for identifiers naming style mismatch. 7 | 8 | This check will try to enforce coding guidelines on the identifiers naming. 9 | It supports `lower_case`, `UPPER_CASE`, `camelBack` and `CamelCase` casing and 10 | tries to convert from one to another if a mismatch is detected. 11 | 12 | It also supports a fixed prefix and suffix that will be prepended or 13 | appended to the identifiers, regardless of the casing. 14 | 15 | Many configuration options are available, in order to be able to create 16 | different rules for different kind of identifier. In general, the 17 | rules are falling back to a more generic rule if the specific case is not 18 | configured. 19 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/readability-named-parameter.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - readability-named-parameter 2 | 3 | readability-named-parameter 4 | =========================== 5 | 6 | Find functions with unnamed arguments. 7 | 8 | The check implements the following rule originating in the Google C++ Style 9 | Guide: 10 | 11 | https://google.github.io/styleguide/cppguide.html#Function_Declarations_and_Definitions 12 | 13 | All parameters should be named, with identical names in the declaration and 14 | implementation. 15 | 16 | Corresponding cpplint.py check name: `readability/function`. 17 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/readability-redundant-control-flow.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - readability-redundant-control-flow 2 | 3 | readability-redundant-control-flow 4 | ================================== 5 | 6 | This check looks for procedures (functions returning no value) with ``return`` 7 | statements at the end of the function. Such ``return`` statements are 8 | redundant. 9 | 10 | Loop statements (``for``, ``while``, ``do while``) are checked for redundant 11 | ``continue`` statements at the end of the loop body. 12 | 13 | Examples: 14 | 15 | The following function `f` contains a redundant `return` statement: 16 | 17 | .. code:: c++ 18 | 19 | extern void g(); 20 | void f() { 21 | g(); 22 | return; 23 | } 24 | 25 | becomes 26 | 27 | .. code:: c++ 28 | 29 | extern void g(); 30 | void f() { 31 | g(); 32 | } 33 | 34 | The following function `k` contains a redundant `continue` statement: 35 | 36 | .. code:: c++ 37 | 38 | void k() { 39 | for (int i = 0; i < 10; ++i) { 40 | continue; 41 | } 42 | } 43 | 44 | becomes 45 | 46 | .. code:: c++ 47 | 48 | void k() { 49 | for (int i = 0; i < 10; ++i) { 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/readability-redundant-smartptr-get.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - readability-redundant-smartptr-get 2 | 3 | readability-redundant-smartptr-get 4 | ================================== 5 | 6 | 7 | Find and remove redundant calls to smart pointer's ``.get()`` method. 8 | 9 | Examples: 10 | 11 | .. code:: c++ 12 | 13 | ptr.get()->Foo() ==> ptr->Foo() 14 | *ptr.get() ==> *ptr 15 | *ptr->get() ==> **ptr 16 | 17 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/readability-redundant-string-cstr.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - readability-redundant-string-cstr 2 | 3 | readability-redundant-string-cstr 4 | ================================= 5 | 6 | 7 | Finds unnecessary calls to ``std::string::c_str()``. 8 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/readability-redundant-string-init.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - readability-redundant-string-init 2 | 3 | readability-redundant-string-init 4 | ================================= 5 | 6 | 7 | Finds unnecessary string initializations. 8 | 9 | Examples: 10 | 11 | .. code:: c++ 12 | 13 | // Initializing string with empty string literal is unnecessary. 14 | std::string a = ""; 15 | std::string b(""); 16 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/readability-static-definition-in-anonymous-namespace.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - readability-static-definition-in-anonymous-namespace 2 | 3 | readability-static-definition-in-anonymous-namespace 4 | ==================================================== 5 | 6 | Finds static function and variable definitions in anonymous namespace. 7 | 8 | In this case, ``static`` is redundant, because anonymous namespace limits the 9 | visibility of definitions to a single translation unit. 10 | 11 | .. code:: c++ 12 | 13 | namespace { 14 | static int a = 1; // Warning. 15 | static const b = 1; // Warning. 16 | } 17 | 18 | The check will apply a fix by removing the redundant ``static`` qualifier. 19 | -------------------------------------------------------------------------------- /docs/clang-tidy/checks/readability-uniqueptr-delete-release.rst: -------------------------------------------------------------------------------- 1 | .. title:: clang-tidy - readability-uniqueptr-delete-release 2 | 3 | readability-uniqueptr-delete-release 4 | ==================================== 5 | 6 | Replace ``delete .release()`` with `` = nullptr``. 7 | The latter is shorter, simpler and does not require use of raw pointer APIs. 8 | -------------------------------------------------------------------------------- /docs/cpp11-migrate.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | All :program:`clang-modernize` transforms have moved to :doc:`clang-tidy/index` 4 | (see the ``modernize`` module). 5 | -------------------------------------------------------------------------------- /docs/doxygen-mainpage.dox: -------------------------------------------------------------------------------- 1 | /// \mainpage clang-tools 2 | /// 3 | /// \section main_intro Introduction 4 | /// Welcome to clang tools. 5 | /// 6 | /// This documentation describes the **internal** software that makes 7 | /// up clang tools, not the **external** use of clang tools. For 8 | /// usage instructions, please see the programmer's guide or reference 9 | /// manual. 10 | -------------------------------------------------------------------------------- /include-fixer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS 2 | support 3 | ) 4 | 5 | add_clang_library(clangIncludeFixer 6 | IncludeFixer.cpp 7 | InMemorySymbolIndex.cpp 8 | SymbolIndexManager.cpp 9 | YamlSymbolIndex.cpp 10 | 11 | LINK_LIBS 12 | clangAST 13 | clangBasic 14 | clangFormat 15 | clangFrontend 16 | clangLex 17 | clangParse 18 | clangSema 19 | clangTooling 20 | clangToolingCore 21 | findAllSymbols 22 | ) 23 | 24 | add_subdirectory(tool) 25 | add_subdirectory(find-all-symbols) 26 | -------------------------------------------------------------------------------- /include-fixer/InMemorySymbolIndex.cpp: -------------------------------------------------------------------------------- 1 | //===-- InMemorySymbolIndex.cpp--------------------------------------------===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #include "InMemorySymbolIndex.h" 11 | 12 | using clang::find_all_symbols::SymbolInfo; 13 | 14 | namespace clang { 15 | namespace include_fixer { 16 | 17 | InMemorySymbolIndex::InMemorySymbolIndex( 18 | const std::vector &Symbols) { 19 | for (const auto &Symbol : Symbols) 20 | LookupTable[Symbol.getName()].push_back(Symbol); 21 | } 22 | 23 | std::vector 24 | InMemorySymbolIndex::search(llvm::StringRef Identifier) { 25 | auto I = LookupTable.find(Identifier); 26 | if (I != LookupTable.end()) 27 | return I->second; 28 | return {}; 29 | } 30 | 31 | } // namespace include_fixer 32 | } // namespace clang 33 | -------------------------------------------------------------------------------- /include-fixer/find-all-symbols/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS 2 | Support 3 | ) 4 | 5 | add_clang_library(findAllSymbols 6 | FindAllSymbols.cpp 7 | FindAllSymbolsAction.cpp 8 | FindAllMacros.cpp 9 | HeaderMapCollector.cpp 10 | PragmaCommentHandler.cpp 11 | STLPostfixHeaderMap.cpp 12 | SymbolInfo.cpp 13 | 14 | LINK_LIBS 15 | clangAST 16 | clangASTMatchers 17 | clangBasic 18 | clangFrontend 19 | clangLex 20 | clangTooling 21 | ) 22 | 23 | add_subdirectory(tool) 24 | -------------------------------------------------------------------------------- /include-fixer/find-all-symbols/STLPostfixHeaderMap.h: -------------------------------------------------------------------------------- 1 | //===-- STLPostfixHeaderMap.h - hardcoded header map for STL ----*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_TOOL_STL_POSTFIX_HEADER_MAP_H 11 | #define LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_TOOL_STL_POSTFIX_HEADER_MAP_H 12 | 13 | #include "HeaderMapCollector.h" 14 | 15 | namespace clang { 16 | namespace find_all_symbols { 17 | 18 | const HeaderMapCollector::HeaderMap* getSTLPostfixHeaderMap(); 19 | 20 | } // namespace find_all_symbols 21 | } // namespace clang 22 | 23 | #endif // LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_TOOL_STL_POSTFIX_HEADER_MAP_H 24 | -------------------------------------------------------------------------------- /include-fixer/find-all-symbols/SymbolReporter.h: -------------------------------------------------------------------------------- 1 | //===--- SymbolReporter.h - Symbol Reporter ---------------------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | 10 | #ifndef LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_SYMBOL_REPORTER_H 11 | #define LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_SYMBOL_REPORTER_H 12 | 13 | #include "SymbolInfo.h" 14 | 15 | namespace clang { 16 | namespace find_all_symbols { 17 | 18 | /// \brief An interface for classes that collect symbols. 19 | class SymbolReporter { 20 | public: 21 | virtual ~SymbolReporter() = default; 22 | 23 | virtual void reportSymbol(llvm::StringRef FileName, 24 | const SymbolInfo &Symbol) = 0; 25 | }; 26 | 27 | } // namespace find_all_symbols 28 | } // namespace clang 29 | 30 | #endif // LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_SYMBOL_REPORTER_H 31 | -------------------------------------------------------------------------------- /include-fixer/find-all-symbols/tool/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) 2 | 3 | add_clang_executable(find-all-symbols FindAllSymbolsMain.cpp) 4 | target_link_libraries(find-all-symbols 5 | 6 | clangAST 7 | clangASTMatchers 8 | clangBasic 9 | clangFrontend 10 | clangLex 11 | clangTooling 12 | findAllSymbols 13 | ) 14 | -------------------------------------------------------------------------------- /include-fixer/tool/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) 2 | 3 | add_clang_executable(clang-include-fixer ClangIncludeFixer.cpp) 4 | target_link_libraries(clang-include-fixer 5 | clangBasic 6 | clangFrontend 7 | clangIncludeFixer 8 | clangRewrite 9 | clangTooling 10 | clangToolingCore 11 | findAllSymbols 12 | ) 13 | -------------------------------------------------------------------------------- /modularize/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS 2 | Option 3 | Support 4 | ) 5 | 6 | add_clang_executable(modularize 7 | Modularize.cpp 8 | ModuleAssistant.cpp 9 | ModularizeUtilities.cpp 10 | CoverageChecker.cpp 11 | PreprocessorTracker.cpp 12 | ) 13 | 14 | target_link_libraries(modularize 15 | clangAST 16 | clangBasic 17 | clangDriver 18 | clangFrontend 19 | clangLex 20 | clangTooling 21 | ) 22 | 23 | install(TARGETS modularize 24 | RUNTIME DESTINATION bin 25 | COMPONENT clang-extras) 26 | -------------------------------------------------------------------------------- /pp-trace/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS 2 | Support 3 | ) 4 | 5 | add_clang_executable(pp-trace 6 | PPTrace.cpp 7 | PPCallbacksTracker.cpp 8 | ) 9 | 10 | target_link_libraries(pp-trace 11 | clangAST 12 | clangBasic 13 | clangFrontend 14 | clangLex 15 | clangTooling 16 | ) 17 | -------------------------------------------------------------------------------- /test/.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: LLVM 2 | ColumnLimit: 0 3 | -------------------------------------------------------------------------------- /test/Unit/lit.site.cfg.in: -------------------------------------------------------------------------------- 1 | @LIT_SITE_CFG_IN_HEADER@ 2 | 3 | config.extra_tools_obj_dir = "@CLANG_TOOLS_BINARY_DIR@/unittests" 4 | config.extra_tools_src_dir = "@CLANG_TOOLS_SOURCE_DIR@/unittests" 5 | config.llvm_libs_dir = "@LLVM_LIBS_DIR@" 6 | config.shlibdir = "@SHLIBDIR@" 7 | config.target_triple = "@TARGET_TRIPLE@" 8 | 9 | lit_config.load_config(config, "@CLANG_TOOLS_SOURCE_DIR@/test/Unit/lit.cfg") 10 | -------------------------------------------------------------------------------- /test/clang-apply-replacements/Inputs/basic/basic.h: -------------------------------------------------------------------------------- 1 | #ifndef BASIC_H 2 | #define BASIC_H 3 | 4 | 5 | class Parent { 6 | public: 7 | virtual void func() {} 8 | }; 9 | 10 | class Derived : public Parent { 11 | public: 12 | virtual void func() {} 13 | // CHECK: virtual void func() override {} 14 | }; 15 | 16 | extern void ext(int (&)[5], const Parent &); 17 | 18 | void func(int t) { 19 | int ints[5]; 20 | for (unsigned i = 0; i < 5; ++i) { 21 | int &e = ints[i]; 22 | e = t; 23 | // CHECK: for (auto & elem : ints) { 24 | // CHECK-NEXT: elem = t; 25 | } 26 | 27 | Derived d; 28 | 29 | ext(ints, d); 30 | } 31 | 32 | #endif // BASIC_H 33 | -------------------------------------------------------------------------------- /test/clang-apply-replacements/Inputs/basic/file1.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | MainSourceFile: source1.cpp 3 | Replacements: 4 | - FilePath: $(path)/basic.h 5 | Offset: 242 6 | Length: 26 7 | ReplacementText: 'auto & elem : ints' 8 | - FilePath: $(path)/basic.h 9 | Offset: 276 10 | Length: 22 11 | ReplacementText: '' 12 | - FilePath: $(path)/basic.h 13 | Offset: 298 14 | Length: 1 15 | ReplacementText: elem 16 | - FilePath: $(path)/../basic/basic.h 17 | Offset: 148 18 | Length: 0 19 | ReplacementText: 'override ' 20 | ... 21 | -------------------------------------------------------------------------------- /test/clang-apply-replacements/Inputs/basic/file2.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | MainSourceFile: source2.cpp 3 | Replacements: 4 | - FilePath: $(path)/basic.h 5 | Offset: 148 6 | Length: 0 7 | ReplacementText: 'override ' 8 | ... 9 | -------------------------------------------------------------------------------- /test/clang-apply-replacements/Inputs/conflict/common.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_H 2 | #define COMMON_H 3 | 4 | extern void ext(int (&)[5]); 5 | 6 | void func(int t) { 7 | int ints[5]; 8 | for (unsigned i = 0; i < 5; ++i) { 9 | ints[i] = t; 10 | } 11 | 12 | int *i = 0; 13 | 14 | ext(ints); 15 | } 16 | 17 | #endif // COMMON_H 18 | -------------------------------------------------------------------------------- /test/clang-apply-replacements/Inputs/conflict/expected.txt: -------------------------------------------------------------------------------- 1 | There are conflicting changes to $(path)/common.h: 2 | The following changes conflict: 3 | Replace 8:8-8:33 with "auto & i : ints" 4 | Replace 8:8-8:33 with "int & elem : ints" 5 | The following changes conflict: 6 | Replace 9:5-9:11 with "elem" 7 | Replace 9:5-9:11 with "i" 8 | The following changes conflict: 9 | Remove 12:3-12:14 10 | Insert at 12:12 (int*) 11 | Replace 12:12-12:12 with "nullptr" 12 | -------------------------------------------------------------------------------- /test/clang-apply-replacements/Inputs/conflict/file1.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | MainSourceFile: source1.cpp 3 | Replacements: 4 | - FilePath: $(path)/common.h 5 | Offset: 106 6 | Length: 26 7 | ReplacementText: 'auto & i : ints' 8 | - FilePath: $(path)/common.h 9 | Offset: 140 10 | Length: 7 11 | ReplacementText: i 12 | - FilePath: $(path)/common.h 13 | Offset: 160 14 | Length: 12 15 | ReplacementText: '' 16 | ... 17 | -------------------------------------------------------------------------------- /test/clang-apply-replacements/Inputs/conflict/file2.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | MainSourceFile: source2.cpp 3 | Replacements: 4 | - FilePath: $(path)/common.h 5 | Offset: 106 6 | Length: 26 7 | ReplacementText: 'int & elem : ints' 8 | - FilePath: $(path)/common.h 9 | Offset: 140 10 | Length: 7 11 | ReplacementText: elem 12 | - FilePath: $(path)/common.h 13 | Offset: 169 14 | Length: 1 15 | ReplacementText: nullptr 16 | ... 17 | -------------------------------------------------------------------------------- /test/clang-apply-replacements/Inputs/conflict/file3.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | MainSourceFile: source1.cpp 3 | Replacements: 4 | - FilePath: $(path)/common.h 5 | Offset: 169 6 | Length: 0 7 | ReplacementText: "(int*)" 8 | ... 9 | -------------------------------------------------------------------------------- /test/clang-apply-replacements/Inputs/crlf/crlf.cpp: -------------------------------------------------------------------------------- 1 | 2 | // This file intentionally uses a CRLF newlines! 3 | 4 | void foo() { 5 | int *x = 0; 6 | } 7 | -------------------------------------------------------------------------------- /test/clang-apply-replacements/Inputs/crlf/crlf.cpp.expected: -------------------------------------------------------------------------------- 1 | 2 | // This file intentionally uses a CRLF newlines! 3 | 4 | void foo() { 5 | int *x = nullptr; 6 | } 7 | -------------------------------------------------------------------------------- /test/clang-apply-replacements/Inputs/crlf/file1.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | MainSourceFile: source1.cpp 3 | Replacements: 4 | - FilePath: $(path)/crlf.cpp 5 | Offset: 79 6 | Length: 1 7 | ReplacementText: nullptr 8 | ... 9 | -------------------------------------------------------------------------------- /test/clang-apply-replacements/Inputs/format/no.cpp: -------------------------------------------------------------------------------- 1 | class C {}; 2 | 3 | void f() { // This comment necessary to prevent formatting as void f() { ... } 4 | C *a = new C(); 5 | // CHECK: {{^\ \ auto\ a\ \=\ new\ C\(\);}} 6 | } 7 | -------------------------------------------------------------------------------- /test/clang-apply-replacements/Inputs/format/no.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | MainSourceFile: no.cpp 3 | Replacements: 4 | - FilePath: $(path)/no.cpp 5 | Offset: 94 6 | Length: 3 7 | ReplacementText: 'auto ' 8 | ... 9 | -------------------------------------------------------------------------------- /test/clang-apply-replacements/Inputs/format/yes.cpp: -------------------------------------------------------------------------------- 1 | class MyType012345678901234567890123456789 {}; 2 | 3 | void g(int, int*, int, int*, int, int*, int); 4 | 5 | void f() { 6 | MyType012345678901234567890123456789 *a = 7 | new MyType012345678901234567890123456789(); 8 | // CHECK: {{^\ \ auto\ a\ \=\ new\ MyType012345678901234567890123456789\(\);}} 9 | 10 | int iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii; 11 | int jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj; 12 | int kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk; 13 | int mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm; 14 | g(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii, 0, jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj, 15 | 0, kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk, 0, mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm); 16 | // CHECK: g(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii, nullptr, 17 | // CHECK-NEXT: jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj, nullptr, 18 | // CHECK-NEXT: kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk, nullptr, 19 | // CHECK-NEXT: mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm); 20 | 21 | delete a; 22 | } 23 | -------------------------------------------------------------------------------- /test/clang-apply-replacements/Inputs/format/yes.yaml: -------------------------------------------------------------------------------- 1 | # These replacements are out of order on purpose to test that they get sorted 2 | # so that formatting happens correctly. 3 | --- 4 | MainSourceFile: yes.cpp 5 | Replacements: 6 | - FilePath: $(path)/yes.cpp 7 | Offset: 494 8 | Length: 1 9 | ReplacementText: nullptr 10 | - FilePath: $(path)/yes.cpp 11 | Offset: 410 12 | Length: 1 13 | ReplacementText: nullptr 14 | - FilePath: $(path)/yes.cpp 15 | Offset: 454 16 | Length: 1 17 | ReplacementText: nullptr 18 | - FilePath: $(path)/yes.cpp 19 | Offset: 108 20 | Length: 38 21 | ReplacementText: 'auto ' 22 | ... 23 | -------------------------------------------------------------------------------- /test/clang-apply-replacements/basic.cpp: -------------------------------------------------------------------------------- 1 | // RUN: mkdir -p %T/Inputs/basic 2 | // RUN: grep -Ev "// *[A-Z-]+:" %S/Inputs/basic/basic.h > %T/Inputs/basic/basic.h 3 | // RUN: sed "s#\$(path)#%/T/Inputs/basic#" %S/Inputs/basic/file1.yaml > %T/Inputs/basic/file1.yaml 4 | // RUN: sed "s#\$(path)#%/T/Inputs/basic#" %S/Inputs/basic/file2.yaml > %T/Inputs/basic/file2.yaml 5 | // RUN: clang-apply-replacements %T/Inputs/basic 6 | // RUN: FileCheck -input-file=%T/Inputs/basic/basic.h %S/Inputs/basic/basic.h 7 | // 8 | // Check that the yaml files are *not* deleted after running clang-apply-replacements without remove-change-desc-files. 9 | // RUN: ls -1 %T/Inputs/basic | FileCheck %s --check-prefix=YAML 10 | // 11 | // Check that the yaml files *are* deleted after running clang-apply-replacements with remove-change-desc-files. 12 | // RUN: grep -Ev "// *[A-Z-]+:" %S/Inputs/basic/basic.h > %T/Inputs/basic/basic.h 13 | // RUN: clang-apply-replacements -remove-change-desc-files %T/Inputs/basic 14 | // RUN: ls -1 %T/Inputs/basic | FileCheck %s --check-prefix=NO_YAML 15 | // 16 | // YAML: {{^file.\.yaml$}} 17 | // NO_YAML-NOT: {{^file.\.yaml$}} 18 | -------------------------------------------------------------------------------- /test/clang-apply-replacements/crlf.cpp: -------------------------------------------------------------------------------- 1 | // RUN: mkdir -p %T/Inputs/crlf 2 | // RUN: cp %S/Inputs/crlf/crlf.cpp %T/Inputs/crlf/crlf.cpp 3 | // RUN: sed "s#\$(path)#%/T/Inputs/crlf#" %S/Inputs/crlf/file1.yaml > %T/Inputs/crlf/file1.yaml 4 | // RUN: clang-apply-replacements %T/Inputs/crlf 5 | // RUN: diff %T/Inputs/crlf/crlf.cpp %S/Inputs/crlf/crlf.cpp.expected 6 | -------------------------------------------------------------------------------- /test/clang-apply-replacements/format.cpp: -------------------------------------------------------------------------------- 1 | // RUN: mkdir -p %T/Inputs/format 2 | // 3 | // yes.cpp requires formatting after replacements are applied. no.cpp does not. 4 | // The presence of no.cpp ensures that files that don't need formatting still 5 | // have their new state written to disk after applying replacements. 6 | // 7 | // RUN: grep -Ev "// *[A-Z-]+:" %S/Inputs/format/yes.cpp > %T/Inputs/format/yes.cpp 8 | // RUN: grep -Ev "// *[A-Z-]+:" %S/Inputs/format/no.cpp > %T/Inputs/format/no.cpp 9 | // RUN: sed "s#\$(path)#%/T/Inputs/format#" %S/Inputs/format/yes.yaml > %T/Inputs/format/yes.yaml 10 | // RUN: sed "s#\$(path)#%/T/Inputs/format#" %S/Inputs/format/no.yaml > %T/Inputs/format/no.yaml 11 | // RUN: clang-apply-replacements -format %T/Inputs/format 12 | // RUN: FileCheck --strict-whitespace -input-file=%T/Inputs/format/yes.cpp %S/Inputs/format/yes.cpp 13 | // RUN: FileCheck --strict-whitespace -input-file=%T/Inputs/format/no.cpp %S/Inputs/format/no.cpp 14 | // 15 | // RUN not clang-apply-replacements -format=blah %T/Inputs/format 16 | -------------------------------------------------------------------------------- /test/clang-query/Inputs/foo.script: -------------------------------------------------------------------------------- 1 | foo 2 | bar 3 | -------------------------------------------------------------------------------- /test/clang-query/errors.c: -------------------------------------------------------------------------------- 1 | // RUN: not clang-query -c foo -c bar %s -- | FileCheck %s 2 | // RUN: not clang-query -f %S/Inputs/foo.script %s -- | FileCheck %s 3 | // RUN: not clang-query -f %S/Inputs/nonexistent.script %s -- 2>&1 | FileCheck --check-prefix=CHECK-NONEXISTENT %s 4 | // RUN: not clang-query -c foo -f foo %s -- 2>&1 | FileCheck --check-prefix=CHECK-BOTH %s 5 | 6 | // CHECK: unknown command: foo 7 | // CHECK-NOT: unknown command: bar 8 | 9 | // CHECK-NONEXISTENT: cannot open {{.*}}nonexistent.script 10 | // CHECK-BOTH: cannot specify both -c and -f 11 | -------------------------------------------------------------------------------- /test/clang-query/function-decl.c: -------------------------------------------------------------------------------- 1 | // RUN: clang-query -c "match functionDecl()" %s -- | FileCheck %s 2 | 3 | // CHECK: function-decl.c:4:1: note: "root" binds here 4 | void foo(void) {} 5 | -------------------------------------------------------------------------------- /test/clang-rename/ClassTest.cpp: -------------------------------------------------------------------------------- 1 | // RUN: cat %s > %t.cpp 2 | // RUN: clang-rename -offset=138 -new-name=Hector %t.cpp -i -- 3 | // RUN: sed 's,//.*,,' %t.cpp | FileCheck %s 4 | class Cla // CHECK: class Hector 5 | { 6 | }; 7 | 8 | int main() 9 | { 10 | Cla *Pointer = 0; // CHECK: Hector *Pointer = 0; 11 | return 0; 12 | } 13 | 14 | // Use grep -FUbo 'Cla' to get the correct offset of Cla when changing 15 | // this file. 16 | -------------------------------------------------------------------------------- /test/clang-rename/CtorDefTest.cpp: -------------------------------------------------------------------------------- 1 | // RUN: cat %s > %t.cpp 2 | // RUN: clang-rename -offset=133 -new-name=D %t.cpp -i -- 3 | // RUN: sed 's,//.*,,' %t.cpp | FileCheck %s 4 | class C 5 | { 6 | public: 7 | C(); 8 | }; 9 | 10 | C::C() // CHECK: D::D() 11 | { 12 | } 13 | 14 | // Use grep -FUbo 'C' to get the correct offset of foo when changing 15 | // this file. 16 | -------------------------------------------------------------------------------- /test/clang-rename/CtorInitializerTest.cpp: -------------------------------------------------------------------------------- 1 | // RUN: cat %s > %t.cpp 2 | // RUN: clang-rename -offset=162 -new-name=hector %t.cpp -i -- 3 | // RUN: sed 's,//.*,,' %t.cpp | FileCheck %s 4 | class A 5 | { 6 | }; 7 | 8 | class Cla 9 | { 10 | A foo; // CHECK: hector; 11 | public: 12 | Cla(); 13 | }; 14 | 15 | Cla::Cla() // CHECK: Cla::Cla() 16 | { 17 | } 18 | 19 | // Use grep -FUbo 'foo' to get the correct offset of foo when changing 20 | // this file. 21 | -------------------------------------------------------------------------------- /test/clang-rename/DeclRefExpr.cpp: -------------------------------------------------------------------------------- 1 | // RUN: cat %s > %t.cpp 2 | // RUN: clang-rename -offset=158 -new-name=Y %t.cpp -i -- 3 | // RUN: sed 's,//.*,,' %t.cpp | FileCheck %s 4 | class C 5 | { 6 | public: 7 | static int X; 8 | }; 9 | 10 | int foo(int x) 11 | { 12 | return 0; 13 | } 14 | #define FOO(a) foo(a) 15 | 16 | int main() 17 | { 18 | C::X = 1; // CHECK: C::Y 19 | FOO(C::X); // CHECK: C::Y 20 | int y = C::X; // CHECK: C::Y 21 | } 22 | 23 | // Use grep -FUbo 'X' to get the correct offset of foo when changing 24 | // this file. 25 | -------------------------------------------------------------------------------- /test/clang-rename/FieldTest.cpp: -------------------------------------------------------------------------------- 1 | // RUN: cat %s > %t.cpp 2 | // RUN: clang-rename -offset=150 -new-name=hector %t.cpp -i -- 3 | // RUN: sed 's,//.*,,' %t.cpp | FileCheck %s 4 | class Cla 5 | { 6 | int foo; // CHECK: hector; 7 | public: 8 | Cla(); 9 | }; 10 | 11 | Cla::Cla() 12 | : foo(0) // CHECK: hector(0) 13 | { 14 | } 15 | 16 | // Use grep -FUbo 'foo' to get the correct offset of foo when changing 17 | // this file. 18 | -------------------------------------------------------------------------------- /test/clang-rename/MemberExprMacro.cpp: -------------------------------------------------------------------------------- 1 | // RUN: cat %s > %t.cpp 2 | // RUN: clang-rename -offset=151 -new-name=Y %t.cpp -i -- 3 | // RUN: sed 's,//.*,,' %t.cpp | FileCheck %s 4 | class C 5 | { 6 | public: 7 | int X; 8 | }; 9 | 10 | int foo(int x) 11 | { 12 | return 0; 13 | } 14 | #define FOO(a) foo(a) 15 | 16 | int main() 17 | { 18 | C C; 19 | C.X = 1; // CHECK: C.Y 20 | FOO(C.X); // CHECK: C.Y 21 | int y = C.X; // CHECK: C.Y 22 | } 23 | 24 | // Use grep -FUbo 'C' to get the correct offset of foo when changing 25 | // this file. 26 | -------------------------------------------------------------------------------- /test/clang-rename/VarTest.cpp: -------------------------------------------------------------------------------- 1 | // RUN: cat %s > %t.cpp 2 | // RUN: clang-rename -offset=150 -new-name=hector %t.cpp -i -- 3 | // RUN: sed 's,//.*,,' %t.cpp | FileCheck %s 4 | namespace A { int foo; // CHECK: int hector; 5 | } 6 | int foo; // CHECK: int foo; 7 | int bar = foo; // CHECK: bar = foo; 8 | int baz = A::foo; // CHECK: baz = A::hector; 9 | void fun1() { 10 | struct { 11 | int foo; // CHECK: int foo; 12 | } b = { 100 }; 13 | int foo = 100; // CHECK: int foo 14 | baz = foo; // CHECK: baz = foo; 15 | { 16 | extern int foo; // CHECK: int foo; 17 | baz = foo; // CHECK: baz = foo; 18 | foo = A::foo + baz; // CHECK: foo = A::hector + baz; 19 | A::foo = b.foo; // CHECK: A::hector = b.foo; 20 | } 21 | foo = b.foo; // CHECK: foo = b.foo; 22 | } 23 | // Use grep -FUbo 'foo;' to get the correct offset of foo when changing 24 | // this file. 25 | -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/Headers/a.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/Headers/a.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/Headers/b.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/Headers/b.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/Headers/clang-c/c.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/Headers/clang-c/c.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/Headers/clang/b.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/Headers/clang/b.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/Headers/gtest/foo.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/Headers/gtest/foo.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/Headers/i.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/Headers/i.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/Headers/j.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/Headers/j.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/Headers/llvm-c/d.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/Headers/llvm-c/d.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/Headers/llvm/a.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/Headers/llvm/a.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/Headers/s.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/Headers/s.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/compilation-database/template.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "directory": "test_dir/a", 4 | "command": "clang++ -o test.o test_dir/a/a.cpp", 5 | "file": "test_dir/a/a.cpp" 6 | }, 7 | { 8 | "directory": "test_dir/a", 9 | "command": "clang++ -o test.o test_dir/a/b.cpp", 10 | "file": "test_dir/a/b.cpp" 11 | }, 12 | { 13 | "directory": "test_dir/", 14 | "command": "clang++ -o test.o test_dir/b/b.cpp", 15 | "file": "test_dir/b/b.cpp" 16 | }, 17 | { 18 | "directory": "test_dir/b", 19 | "command": "clang++ -o test.o ../b/c.cpp", 20 | "file": "test_dir/b/c.cpp" 21 | }, 22 | { 23 | "directory": "test_dir/b", 24 | "command": "clang++ -I../include -o test.o ../b/d.cpp", 25 | "file": "test_dir/b/d.cpp" 26 | }, 27 | { 28 | "directory": "test_dir/", 29 | "command": "clang++ -o test.o test_dir/b/not-exist.cpp", 30 | "file": "test_dir/b/not-exist.cpp" 31 | } 32 | ] 33 | -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/config-files/.clang-tidy: -------------------------------------------------------------------------------- 1 | Checks: 'from-parent' 2 | HeaderFilterRegex: 'parent' 3 | -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/config-files/1/.clang-tidy: -------------------------------------------------------------------------------- 1 | Checks: 'from-child1' 2 | HeaderFilterRegex: 'child1' 3 | -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/explain-config/.clang-tidy: -------------------------------------------------------------------------------- 1 | Checks: '-*,modernize-use-nullptr' 2 | -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/file-filter/header1.h: -------------------------------------------------------------------------------- 1 | class A1 { A1(int); }; 2 | -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/file-filter/header2.h: -------------------------------------------------------------------------------- 1 | class A2 { A2(int); }; 2 | -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/file-filter/system/system-header.h: -------------------------------------------------------------------------------- 1 | class A0 { A0(int); }; 2 | -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/google-namespaces.h: -------------------------------------------------------------------------------- 1 | namespace { 2 | int x; 3 | } 4 | 5 | namespace spaaaace { 6 | class core; 7 | } 8 | -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/line-filter/header1.h: -------------------------------------------------------------------------------- 1 | class A1 { A1(int); }; 2 | class B1 { B1(int); }; 3 | class C1 { C1(int); }; 4 | -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/line-filter/header2.h: -------------------------------------------------------------------------------- 1 | class A2 { A2(int); }; 2 | class B2 { B2(int); }; 3 | class C2 { C2(int); }; 4 | -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/line-filter/header3.h: -------------------------------------------------------------------------------- 1 | class A3 { A3(int); }; 2 | -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/assert.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/assert.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/complex.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/complex.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/ctype.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/ctype.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/errno.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/errno.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/fenv.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/fenv.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/float.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/float.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/inttypes.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/inttypes.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/iso646.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/iso646.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/limits.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/limits.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/locale.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/locale.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/math.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/math.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/setjmp.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/setjmp.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/signal.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/signal.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/stdalign.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/stdalign.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/stdarg.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/stdarg.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/stdbool.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/stdbool.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/stddef.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/stddef.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/stdint.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/stdint.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/stdio.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/stdio.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/stdlib.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/stdlib.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/string.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/string.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/tgmath.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/tgmath.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/time.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/time.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/uchar.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/uchar.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/wchar.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/wchar.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-deprecated-headers/wctype.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/clang-tools-extra/21506e9a4a0bd107ca8ced5df052e4a3b16cfdfc/test/clang-tidy/Inputs/modernize-deprecated-headers/wctype.h -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/modernize-pass-by-value/header.h: -------------------------------------------------------------------------------- 1 | class ThreadId { 2 | }; 3 | 4 | struct A { 5 | A(const ThreadId &tid) : threadid(tid) {} 6 | ThreadId threadid; 7 | }; 8 | -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/overlapping/o.h: -------------------------------------------------------------------------------- 1 | // run: clang-tidy -checks=-*,llvm-include-order -header-filter=.* %s \ 2 | // run: -- -isystem %S/Inputs/Headers -I %S/Inputs/overlapping | \ 3 | // run: not grep "note: this fix will not be applied because it overlaps with another fix" 4 | 5 | #include "b.h" 6 | #include "a.h" 7 | 8 | // The comments above are there to match the offset of the #include with the 9 | // offset of the #includes in the .cpp file. 10 | -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/readability-identifier-naming/system/system-header.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSTEM_HEADER_H 2 | #define SYSTEM_HEADER_H 3 | 4 | #define SYSTEM_MACRO(m) int m = 0 5 | 6 | namespace SYSTEM_NS { 7 | class structure { 8 | int member; 9 | }; 10 | 11 | float global; 12 | 13 | void function() { 14 | } 15 | } 16 | 17 | #endif // SYSTEM_HEADER_H 18 | -------------------------------------------------------------------------------- /test/clang-tidy/Inputs/readability-identifier-naming/user-header.h: -------------------------------------------------------------------------------- 1 | #ifndef USER_HEADER_H 2 | #define USER_HEADER_H 3 | 4 | #define USER_MACRO(m) int m = 0 5 | 6 | namespace USER_NS { 7 | class object { 8 | int member; 9 | }; 10 | 11 | float global; 12 | 13 | void function() { 14 | } 15 | } 16 | 17 | #endif // USER_HEADER_H 18 | -------------------------------------------------------------------------------- /test/clang-tidy/basic.cpp: -------------------------------------------------------------------------------- 1 | // RUN: clang-tidy %s -checks='-*,llvm-namespace-comment' -- | FileCheck %s 2 | // RUN: c-index-test -test-load-source-reparse 2 all %s -Xclang -add-plugin -Xclang clang-tidy -Xclang -plugin-arg-clang-tidy -Xclang -checks='-*,llvm-namespace-comment' 2>&1 | FileCheck %s 3 | 4 | namespace i { 5 | } 6 | // CHECK: warning: namespace 'i' not terminated with a closing comment [llvm-namespace-comment] 7 | -------------------------------------------------------------------------------- /test/clang-tidy/cert-env33-c.c: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s cert-env33-c %t 2 | 3 | typedef struct FILE {} FILE; 4 | 5 | extern int system(const char *); 6 | extern FILE *popen(const char *, const char *); 7 | extern FILE *_popen(const char *, const char *); 8 | 9 | void f(void) { 10 | // It is permissible to check for the presence of a command processor. 11 | system(0); 12 | 13 | system("test"); 14 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: calling 'system' uses a command processor [cert-env33-c] 15 | 16 | popen("test", "test"); 17 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: calling 'popen' uses a command processor 18 | _popen("test", "test"); 19 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: calling '_popen' uses a command processor 20 | } 21 | -------------------------------------------------------------------------------- /test/clang-tidy/cert-flp30-c.c: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s cert-flp30-c %t 2 | 3 | float g(void); 4 | 5 | void func(void) { 6 | for (float x = 0.1f; x <= 1.0f; x += 0.1f) {} 7 | // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: loop induction expression should not have floating-point type [cert-flp30-c] 8 | 9 | float f = 1.0f; 10 | for (; f > 0; --f) {} 11 | // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: loop induction expression 12 | 13 | for (;;g()) {} 14 | // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: loop induction expression 15 | 16 | for (int i = 0; i < 10; i += 1.0f) {} 17 | 18 | for (int i = 0; i < 10; ++i) {} 19 | } 20 | -------------------------------------------------------------------------------- /test/clang-tidy/cert-oop11-cpp.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s cert-oop11-cpp %t -- -- -std=c++11 2 | 3 | struct B { 4 | B(B&&) noexcept = default; 5 | 6 | B(const B &) = default; 7 | B& operator=(const B&) = default; 8 | ~B() {} 9 | }; 10 | 11 | struct D { 12 | B b; 13 | 14 | // CHECK-MESSAGES: :[[@LINE+1]]:14: warning: move constructor initializes class member by calling a copy constructor [cert-oop11-cpp] 15 | D(D &&d) : b(d.b) {} 16 | 17 | // This should not produce a diagnostic because it is not covered under 18 | // the CERT guideline for OOP11-CPP. However, this will produce a diagnostic 19 | // under misc-move-constructor-init. 20 | D(B b) : b(b) {} 21 | }; 22 | -------------------------------------------------------------------------------- /test/clang-tidy/cert-setlongjmp.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s cert-err52-cpp %t -- -- -std=c++11 2 | 3 | typedef void *jmp_buf; 4 | extern int __setjmpimpl(jmp_buf); 5 | #define setjmp(x) __setjmpimpl(x) 6 | [[noreturn]] extern void longjmp(jmp_buf, int); 7 | 8 | namespace std { 9 | using ::jmp_buf; 10 | using ::longjmp; 11 | } 12 | 13 | static jmp_buf env; 14 | void g() { 15 | std::longjmp(env, 1); 16 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not call 'longjmp'; consider using exception handling instead [cert-err52-cpp] 17 | ::longjmp(env, 1); 18 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not call 'longjmp'; consider using exception handling instead 19 | longjmp(env, 1); 20 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not call 'longjmp'; consider using exception handling instead 21 | } 22 | 23 | void f() { 24 | (void)setjmp(env); 25 | // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: do not call 'setjmp'; consider using exception handling instead 26 | } 27 | -------------------------------------------------------------------------------- /test/clang-tidy/cert-variadic-function-def.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s cert-dcl50-cpp %t 2 | 3 | // Variadic function definitions are diagnosed. 4 | void f1(int, ...) {} 5 | // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: do not define a C-style variadic function; consider using a function parameter pack or currying instead [cert-dcl50-cpp] 6 | 7 | // Variadic function *declarations* are not diagnosed. 8 | void f2(int, ...); // ok 9 | 10 | // Function parameter packs are good, however. 11 | template 12 | void f3(Arg F, Ts... Rest) {} 13 | 14 | struct S { 15 | void f(int, ...); // ok 16 | void f1(int, ...) {} 17 | // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: do not define a C-style variadic function; consider using a function parameter pack or currying instead 18 | }; 19 | 20 | // Function definitions that are extern "C" are good. 21 | extern "C" void f4(int, ...) {} // ok 22 | extern "C" { 23 | void f5(int, ...) {} // ok 24 | } 25 | -------------------------------------------------------------------------------- /test/clang-tidy/clang-tidy-diff.cpp: -------------------------------------------------------------------------------- 1 | // RUN: sed 's/placeholder_for_f/f/' %s > %t.cpp 2 | // RUN: clang-tidy -checks=-*,modernize-use-override %t.cpp -- -std=c++11 | FileCheck -check-prefix=CHECK-SANITY %s 3 | // RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -- -std=c++11 2>&1 | FileCheck %s 4 | struct A { 5 | virtual void f() {} 6 | virtual void g() {} 7 | }; 8 | // CHECK-NOT: warning: 9 | struct B : public A { 10 | void placeholder_for_f() {} 11 | // CHECK-SANITY: [[@LINE-1]]:8: warning: annotate this 12 | // CHECK: [[@LINE-2]]:8: warning: annotate this 13 | void g() {} 14 | // CHECK-SANITY: [[@LINE-1]]:8: warning: annotate this 15 | // CHECK-NOT: warning: 16 | }; 17 | // CHECK-SANITY-NOT: Suppressed 18 | // CHECK: Suppressed 1 warnings (1 due to line filter). 19 | -------------------------------------------------------------------------------- /test/clang-tidy/config-files.cpp: -------------------------------------------------------------------------------- 1 | // RUN: clang-tidy -dump-config %S/Inputs/config-files/- -- | FileCheck %s -check-prefix=CHECK-BASE 2 | // CHECK-BASE: Checks: {{.*}}from-parent 3 | // CHECK-BASE: HeaderFilterRegex: parent 4 | // RUN: clang-tidy -dump-config %S/Inputs/config-files/1/- -- | FileCheck %s -check-prefix=CHECK-CHILD1 5 | // CHECK-CHILD1: Checks: {{.*}}from-child1 6 | // CHECK-CHILD1: HeaderFilterRegex: child1 7 | // RUN: clang-tidy -dump-config %S/Inputs/config-files/2/- -- | FileCheck %s -check-prefix=CHECK-CHILD2 8 | // CHECK-CHILD2: Checks: {{.*}}from-parent 9 | // CHECK-CHILD2: HeaderFilterRegex: parent 10 | // RUN: clang-tidy -dump-config -checks='from-command-line' -header-filter='from command line' %S/Inputs/config-files/- -- | FileCheck %s -check-prefix=CHECK-COMMAND-LINE 11 | // CHECK-COMMAND-LINE: Checks: {{.*}}from-parent,from-command-line 12 | // CHECK-COMMAND-LINE: HeaderFilterRegex: from command line 13 | -------------------------------------------------------------------------------- /test/clang-tidy/cppcoreguidelines-pro-type-const-cast.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-const-cast %t 2 | 3 | const int *i; 4 | int *j; 5 | void f() { j = const_cast(i); } 6 | // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast] 7 | -------------------------------------------------------------------------------- /test/clang-tidy/cppcoreguidelines-pro-type-reinterpret-cast.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-reinterpret-cast %t 2 | 3 | int i = 0; 4 | void *j; 5 | void f() { j = reinterpret_cast(i); } 6 | // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: do not use reinterpret_cast [cppcoreguidelines-pro-type-reinterpret-cast] 7 | -------------------------------------------------------------------------------- /test/clang-tidy/custom-diagnostics.cpp: -------------------------------------------------------------------------------- 1 | // RUN: clang-tidy -checks='-*,modernize-use-override,clang-diagnostic-shadow,clang-diagnostic-float-conversion' %s -- | count 0 2 | // RUN: clang-tidy -checks='-*,modernize-use-override,clang-diagnostic-shadow,clang-diagnostic-float-conversion' \ 3 | // RUN: -config='{ExtraArgs: ["-Wshadow","-Wno-unused-variable"], ExtraArgsBefore: ["-Wno-shadow","-Wfloat-conversion","-Wunused-variable"]}' %s -- \ 4 | // RUN: | FileCheck -implicit-check-not='{{warning:|error:}}' %s 5 | 6 | void f(float x) { 7 | int a; 8 | { int a; } 9 | // CHECK: :[[@LINE-1]]:9: warning: declaration shadows a local variable [clang-diagnostic-shadow] 10 | int b = x; 11 | // CHECK: :[[@LINE-1]]:11: warning: implicit conversion turns floating-point number into integer: 'float' to 'int' [clang-diagnostic-float-conversion] 12 | } 13 | -------------------------------------------------------------------------------- /test/clang-tidy/deduplication.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s google-explicit-constructor %t 2 | 3 | template 4 | struct A { A(T); }; 5 | // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: single-argument constructors must be marked explicit 6 | 7 | void f() { 8 | A a(0); 9 | A b(0); 10 | } 11 | -------------------------------------------------------------------------------- /test/clang-tidy/fix-errors.cpp: -------------------------------------------------------------------------------- 1 | // RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp 2 | // RUN: clang-tidy %t.cpp -checks='-*,google-explicit-constructor' -fix -- > %t.msg 2>&1 3 | // RUN: FileCheck -input-file=%t.cpp -check-prefix=CHECK-FIX %s 4 | // RUN: FileCheck -input-file=%t.msg -check-prefix=CHECK-MESSAGES %s 5 | // RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp 6 | // RUN: clang-tidy %t.cpp -checks='-*,google-explicit-constructor' -fix-errors -- > %t.msg 2>&1 7 | // RUN: FileCheck -input-file=%t.cpp -check-prefix=CHECK-FIX2 %s 8 | // RUN: FileCheck -input-file=%t.msg -check-prefix=CHECK-MESSAGES2 %s 9 | 10 | class A { A(int i); } 11 | // CHECK-FIX: class A { A(int i); }{{$}} 12 | // CHECK-MESSAGES: Fixes have NOT been applied. 13 | // CHECK-FIX2: class A { explicit A(int i); }; 14 | // CHECK-MESSAGES2: note: FIX-IT applied suggested code changes 15 | // CHECK-MESSAGES2: clang-tidy applied 2 of 2 suggested fixes. 16 | -------------------------------------------------------------------------------- /test/clang-tidy/fix.cpp: -------------------------------------------------------------------------------- 1 | // RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp 2 | // RUN: clang-tidy %t.cpp -checks='-*,google-explicit-constructor,llvm-namespace-comment' -fix -export-fixes=%t.yaml -- > %t.msg 2>&1 3 | // RUN: FileCheck -input-file=%t.cpp %s 4 | // RUN: FileCheck -input-file=%t.msg -check-prefix=CHECK-MESSAGES %s 5 | // RUN: FileCheck -input-file=%t.yaml -check-prefix=CHECK-YAML %s 6 | 7 | namespace i { 8 | } 9 | // CHECK: } // namespace i 10 | // CHECK-MESSAGES: note: FIX-IT applied suggested code changes 11 | // CHECK-YAML: ReplacementText: ' // namespace i' 12 | 13 | class A { A(int i); }; 14 | // CHECK: class A { explicit A(int i); }; 15 | // CHECK-MESSAGES: note: FIX-IT applied suggested code changes 16 | // CHECK-MESSAGES: clang-tidy applied 2 of 2 suggested fixes. 17 | // CHECK-YAML: ReplacementText: 'explicit ' 18 | -------------------------------------------------------------------------------- /test/clang-tidy/google-default-arguments.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s google-default-arguments %t 2 | 3 | struct A { 4 | virtual void f(int I, int J = 3); 5 | // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: default arguments on virtual or override methods are prohibited [google-default-arguments] 6 | }; 7 | 8 | struct B : public A { 9 | void f(int I, int J = 5); 10 | // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: default arguments on virtual or override methods are prohibited 11 | }; 12 | 13 | struct C : public B { 14 | void f(int I, int J = 5) override; 15 | // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: default arguments on virtual or override methods are prohibited 16 | }; 17 | 18 | // Negatives. 19 | struct D : public B { 20 | void f(int I, int J) override; 21 | }; 22 | 23 | struct X { 24 | void f(int I, int J = 3); 25 | }; 26 | 27 | struct Y : public X { 28 | void f(int I, int J = 5); 29 | }; 30 | -------------------------------------------------------------------------------- /test/clang-tidy/google-module.cpp: -------------------------------------------------------------------------------- 1 | // RUN: clang-tidy -checks='-*,google*' -config='{}' -dump-config - -- | FileCheck %s 2 | // CHECK: CheckOptions: 3 | // CHECK: {{- key: *google-readability-braces-around-statements.ShortStatementLines}} 4 | // CHECK-NEXT: {{value: *'1'}} 5 | // CHECK: {{- key: *google-readability-function-size.StatementThreshold}} 6 | // CHECK-NEXT: {{value: *'800'}} 7 | // CHECK: {{- key: *google-readability-namespace-comments.ShortNamespaceLines}} 8 | // CHECK-NEXT: {{value: *'10'}} 9 | // CHECK: {{- key: *google-readability-namespace-comments.SpacesBeforeComments}} 10 | // CHECK-NEXT: {{value: *'2'}} 11 | -------------------------------------------------------------------------------- /test/clang-tidy/google-namespaces.cpp: -------------------------------------------------------------------------------- 1 | // RUN: clang-tidy %s -checks='-*,google-build-namespaces,google-build-using-namespace' -header-filter='.*' -- | FileCheck %s -implicit-check-not="{{warning|error}}:" 2 | #include "Inputs/google-namespaces.h" 3 | // CHECK: warning: do not use unnamed namespaces in header files [google-build-namespaces] 4 | 5 | using namespace spaaaace; 6 | // CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace] 7 | 8 | using spaaaace::core; // no-warning 9 | -------------------------------------------------------------------------------- /test/clang-tidy/google-overloaded-unary-and.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s google-runtime-operator %t 2 | 3 | struct Foo { 4 | void *operator&(); 5 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not overload unary operator&, it is dangerous. [google-runtime-operator] 6 | }; 7 | 8 | template 9 | struct TFoo { 10 | T *operator&(); 11 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not overload unary operator& 12 | }; 13 | 14 | TFoo tfoo; 15 | 16 | struct Bar; 17 | void *operator&(Bar &b); 18 | // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: do not overload unary operator& 19 | 20 | // No warnings on binary operators. 21 | struct Qux { 22 | void *operator&(Qux &q); 23 | }; 24 | 25 | void *operator&(Qux &q, Qux &r); 26 | -------------------------------------------------------------------------------- /test/clang-tidy/google-readability-casting.c: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s google-readability-casting %t -- -- -x c 2 | // The testing script always adds .cpp extension to the input file name, so we 3 | // need to run clang-tidy directly in order to verify handling of .c files: 4 | // RUN: clang-tidy --checks=-*,google-readability-casting %s -- -x c++ | FileCheck %s -check-prefix=CHECK-MESSAGES -implicit-check-not='{{warning|error}}:' 5 | // RUN: cp %s %t.main_file.cpp 6 | // RUN: clang-tidy --checks=-*,google-readability-casting -header-filter='.*' %t.main_file.cpp -- -I%S -DTEST_INCLUDE -x c++ | FileCheck %s -check-prefix=CHECK-MESSAGES -implicit-check-not='{{warning|error}}:' 7 | 8 | #ifdef TEST_INCLUDE 9 | 10 | #undef TEST_INCLUDE 11 | #include "google-readability-casting.c" 12 | 13 | #else 14 | 15 | void f(const char *cpc) { 16 | const char *cpc2 = (const char*)cpc; 17 | // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: redundant cast to the same type [google-readability-casting] 18 | // CHECK-FIXES: const char *cpc2 = cpc; 19 | char *pc = (char*)cpc; 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /test/clang-tidy/google-readability-namespace-comments.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s google-readability-namespace-comments %t 2 | 3 | namespace n1 { 4 | namespace n2 { 5 | 6 | 7 | 8 | 9 | 10 | // CHECK-MESSAGES: :[[@LINE+4]]:2: warning: namespace 'n2' not terminated with a closing comment [google-readability-namespace-comments] 11 | // CHECK-MESSAGES: :[[@LINE-7]]:11: note: namespace 'n2' starts here 12 | // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: namespace 'n1' not terminated with 13 | // CHECK-MESSAGES: :[[@LINE-10]]:11: note: namespace 'n1' starts here 14 | }} 15 | // CHECK-FIXES: } // namespace n2 16 | // CHECK-FIXES: } // namespace n1 17 | 18 | 19 | namespace short1 { 20 | namespace short2 { 21 | // Namespaces covering 10 lines or fewer are exempt from this rule. 22 | 23 | 24 | 25 | 26 | 27 | } 28 | } 29 | 30 | namespace n3 { 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | }; // namespace n3 41 | -------------------------------------------------------------------------------- /test/clang-tidy/google-readability-todo.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s google-readability-todo %t -- -config="{User: 'some user'}" -- 2 | 3 | // TODOfix this1 4 | // CHECK-MESSAGES: [[@LINE-1]]:1: warning: missing username/bug in TODO 5 | // CHECK-FIXES: // TODO(some user): fix this1 6 | 7 | // TODO fix this2 8 | // CHECK-MESSAGES: [[@LINE-1]]:1: warning: missing username/bug in TODO 9 | // CHECK-FIXES: // TODO(some user): fix this2 10 | 11 | // TODO fix this3 12 | // CHECK-MESSAGES: [[@LINE-1]]:1: warning: missing username/bug in TODO 13 | // CHECK-FIXES: // TODO(some user): fix this3 14 | 15 | // TODO: fix this4 16 | // CHECK-MESSAGES: [[@LINE-1]]:1: warning: missing username/bug in TODO 17 | // CHECK-FIXES: // TODO(some user): fix this4 18 | 19 | // TODO(clang)fix this5 20 | 21 | // TODO(foo):shave yaks 22 | // TODO(bar): 23 | // TODO(foo): paint bikeshed 24 | // TODO(b/12345): find the holy grail 25 | // TODO (b/12345): allow spaces before parentheses 26 | // TODO(asdf) allow missing semicolon 27 | -------------------------------------------------------------------------------- /test/clang-tidy/google-runtime-int.c: -------------------------------------------------------------------------------- 1 | // RUN: clang-tidy -checks=-*,google-runtime-int %s -- -x c 2>&1 | not grep 'warning:\|error:' 2 | 3 | long a(); 4 | 5 | long b(long x); 6 | 7 | short bar(const short q, unsigned short w) { 8 | long double foo; 9 | unsigned short port; 10 | 11 | const unsigned short bar; 12 | long long *baar; 13 | const unsigned short bara; 14 | long const long moo; 15 | long volatile long wat; 16 | unsigned long y; 17 | unsigned long long **const *tmp; 18 | unsigned short porthole; 19 | 20 | unsigned cast; 21 | cast = (short)42; 22 | return q; 23 | } 24 | 25 | void qux() { 26 | short port; 27 | } 28 | -------------------------------------------------------------------------------- /test/clang-tidy/google-runtime-member-string-references.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s google-runtime-member-string-references %t 2 | 3 | namespace std { 4 | template 5 | class basic_string {}; 6 | 7 | typedef basic_string string; 8 | } 9 | 10 | class string {}; 11 | 12 | 13 | struct A { 14 | const std::string &s; 15 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: const string& members are dangerous; it is much better to use alternatives, such as pointers or simple constants [google-runtime-member-string-references] 16 | }; 17 | 18 | struct B { 19 | std::string &s; 20 | }; 21 | 22 | struct C { 23 | const std::string s; 24 | }; 25 | 26 | template 27 | struct D { 28 | D(); 29 | const T &s; 30 | const std::string &s2; 31 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: const string& members are dangerous 32 | }; 33 | 34 | D d; 35 | 36 | struct AA { 37 | const string &s; 38 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: const string& members are dangerous 39 | }; 40 | 41 | struct BB { 42 | string &s; 43 | }; 44 | 45 | struct CC { 46 | const string s; 47 | }; 48 | 49 | D dd; 50 | -------------------------------------------------------------------------------- /test/clang-tidy/llvm-include-order.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s llvm-include-order %t -- -- -isystem %S/Inputs/Headers 2 | 3 | // CHECK-MESSAGES: [[@LINE+2]]:1: warning: #includes are not sorted properly 4 | #include "j.h" 5 | #include "gtest/foo.h" 6 | #include "i.h" 7 | #include 8 | #include "llvm/a.h" 9 | #include "clang/b.h" 10 | #include "clang-c/c.h" // hi 11 | #include "llvm-c/d.h" // -c 12 | 13 | // CHECK-FIXES: #include "j.h" 14 | // CHECK-FIXES-NEXT: #include "i.h" 15 | // CHECK-FIXES-NEXT: #include "clang-c/c.h" // hi 16 | // CHECK-FIXES-NEXT: #include "clang/b.h" 17 | // CHECK-FIXES-NEXT: #include "llvm-c/d.h" // -c 18 | // CHECK-FIXES-NEXT: #include "llvm/a.h" 19 | // CHECK-FIXES-NEXT: #include "gtest/foo.h" 20 | // CHECK-FIXES-NEXT: #include 21 | 22 | #include "b.h" 23 | #ifdef FOO 24 | #include "a.h" 25 | #endif 26 | 27 | // CHECK-FIXES: #include "b.h" 28 | // CHECK-FIXES-NEXT: #ifdef FOO 29 | // CHECK-FIXES-NEXT: #include "a.h" 30 | // CHECK-FIXES-NEXT: #endif 31 | 32 | // CHECK-MESSAGES: [[@LINE+1]]:1: warning: #includes are not sorted properly 33 | #include "b.h" 34 | #include "a.h" 35 | 36 | // CHECK-FIXES: #include "a.h" 37 | // CHECK-FIXES-NEXT: #include "b.h" 38 | -------------------------------------------------------------------------------- /test/clang-tidy/macros.cpp: -------------------------------------------------------------------------------- 1 | // RUN: clang-tidy -checks='-*,google-explicit-constructor' %s -- | FileCheck %s 2 | 3 | #define Q(name) class name { name(int i); } 4 | 5 | Q(A); 6 | // CHECK: :[[@LINE-1]]:3: warning: single-argument constructors must be marked explicit 7 | // CHECK: :3:30: note: expanded from macro 'Q' 8 | -------------------------------------------------------------------------------- /test/clang-tidy/misc-macro-parentheses-cmdline.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s misc-macro-parentheses %t -- -- -DVAL=0+0 2 | 3 | // The previous command-line is producing warnings and fixes with the source 4 | // locations from a virtual buffer. VAL is replaced by '0+0'. 5 | // Fixes could not be applied and should not be reported. 6 | int foo() { return VAL; } 7 | 8 | #define V 0+0 9 | int bar() { return V; } 10 | // CHECK-FIXES: #define V (0+0) 11 | -------------------------------------------------------------------------------- /test/clang-tidy/misc-new-delete-overloads-sized-dealloc.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s misc-new-delete-overloads %t -- -- -std=c++14 -fsized-deallocation 2 | 3 | typedef decltype(sizeof(int)) size_t; 4 | 5 | struct S { 6 | // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: declaration of 'operator delete' has no matching declaration of 'operator new' at the same scope [misc-new-delete-overloads] 7 | void operator delete(void *ptr, size_t) noexcept; // not a placement delete 8 | }; 9 | 10 | struct T { 11 | // Because we have enabled sized deallocations explicitly, this new/delete 12 | // pair matches. 13 | void *operator new(size_t size) noexcept; 14 | void operator delete(void *ptr, size_t) noexcept; // ok because sized deallocation is enabled 15 | }; 16 | 17 | // While we're here, check that global operator delete with no operator new 18 | // is also matched. 19 | // CHECK-MESSAGES: :[[@LINE+1]]:6: warning: declaration of 'operator delete' has no matching declaration of 'operator new' at the same scope 20 | void operator delete(void *ptr) noexcept; 21 | -------------------------------------------------------------------------------- /test/clang-tidy/misc-pointer-and-integral-operation.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s misc-pointer-and-integral-operation %t 2 | 3 | bool* pb; 4 | char* pc; 5 | int* pi; 6 | 7 | int Test() { 8 | if (pi < 0) return 0; 9 | // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious comparison of pointer with zero [misc-pointer-and-integral-operation] 10 | if (pi <= 0) return 0; 11 | // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious comparison of pointer with zero 12 | 13 | if (nullptr <= pb) return 0; 14 | // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: suspicious comparison of pointer with null 15 | if (pc < nullptr) return 0; 16 | // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious comparison of pointer with null 17 | if (pi > nullptr) return 0; 18 | // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious comparison of pointer with null 19 | 20 | return 1; 21 | } 22 | 23 | int Valid() { 24 | *pb = false; 25 | *pc = '\0'; 26 | 27 | pi += (pi != nullptr); 28 | pi -= (pi == nullptr); 29 | pc += (pb != nullptr); 30 | } 31 | -------------------------------------------------------------------------------- /test/clang-tidy/misc-static-assert.c: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s misc-static-assert %t -- -- -std=c11 2 | // RUN: clang-tidy %s -checks=-*,misc-static-assert -- -std=c99 | count 0 3 | 4 | void abort() {} 5 | #ifdef NDEBUG 6 | #define assert(x) 1 7 | #else 8 | #define assert(x) \ 9 | if (!(x)) \ 10 | abort() 11 | #endif 12 | 13 | void f(void) { 14 | int x = 1; 15 | assert(x == 0); 16 | // CHECK-FIXES: {{^ }}assert(x == 0); 17 | 18 | #define static_assert(x, msg) _Static_assert(x, msg) 19 | assert(11 == 5 + 6); 20 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be 21 | // CHECK-FIXES: {{^ }}static_assert(11 == 5 + 6, ""); 22 | #undef static_assert 23 | 24 | assert(10 == 5 + 5); 25 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be 26 | // CHECK-FIXES: {{^ }}static_assert(10 == 5 + 5, ""); 27 | } 28 | -------------------------------------------------------------------------------- /test/clang-tidy/misc-suspicious-semicolon-fail.cpp: -------------------------------------------------------------------------------- 1 | // RUN: clang-tidy %s -checks="-*,misc-suspicious-semicolon" -- 2>&1 | FileCheck %s 2 | 3 | // Note: This test verifies that, the checker does not emit any warning for 4 | // files that do not compile. 5 | 6 | bool g(); 7 | 8 | void f() { 9 | if (g()); 10 | // CHECK-NOT: [misc-suspicious-semicolon] 11 | int a 12 | } 13 | -------------------------------------------------------------------------------- /test/clang-tidy/misc-undelegated-constructor-cxx98.cpp: -------------------------------------------------------------------------------- 1 | // RUN: clang-tidy %s -checks=-*,misc-undelegated-constructor -- -std=c++98 | count 0 2 | 3 | // Note: this test expects no diagnostics, but FileCheck cannot handle that, 4 | // hence the use of | count 0. 5 | 6 | struct Ctor; 7 | Ctor foo(); 8 | 9 | struct Ctor { 10 | Ctor(); 11 | Ctor(int); 12 | Ctor(int, int); 13 | Ctor(Ctor *i) { 14 | Ctor(); 15 | Ctor(0); 16 | Ctor(1, 2); 17 | foo(); 18 | } 19 | }; 20 | 21 | Ctor::Ctor() { 22 | Ctor(1); 23 | } 24 | -------------------------------------------------------------------------------- /test/clang-tidy/misc-unused-alias-decls.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s misc-unused-alias-decls %t 2 | 3 | namespace my_namespace { 4 | class C {}; 5 | } 6 | 7 | namespace unused_alias = ::my_namespace; // eol-comments aren't removed (yet) 8 | // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: namespace alias decl 'unused_alias' is unused 9 | // CHECK-FIXES: {{^}}// eol-comments aren't removed (yet) 10 | 11 | namespace used_alias = ::my_namespace; 12 | void f() { used_alias::C c; } 13 | -------------------------------------------------------------------------------- /test/clang-tidy/misc-unused-parameters.c: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s misc-unused-parameters %t -- -- -xc 2 | 3 | // Basic removal 4 | // ============= 5 | void a(int i) {} 6 | // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused [misc-unused-parameters] 7 | // CHECK-FIXES: {{^}}void a(int /*i*/) {}{{$}} 8 | 9 | static void b(); // In C, forward declarations can leave out parameters. 10 | static void b(int i) {} 11 | // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: parameter 'i' is unused [misc-unused-parameters] 12 | // CHECK-FIXES: {{^}}static void b() {}{{$}} 13 | 14 | // Unchanged cases 15 | // =============== 16 | void h(i, c, d) int i; char *c, *d; {} // Don't mess with K&R style 17 | 18 | -------------------------------------------------------------------------------- /test/clang-tidy/modernize-loop-convert-assert-failure.cpp: -------------------------------------------------------------------------------- 1 | // RUN: clang-tidy %s -checks=-*,modernize-loop-convert -- 2 | 3 | // Note: this test expects no assert failure happened in clang-tidy. 4 | 5 | class LinguisticItem { 6 | LinguisticItem *x0; 7 | class x1 { 8 | bool operator!= ( const x1 &; 9 | operator* ( ; 10 | LinguisticItem * &operator-> ( ; 11 | operator++ ( 12 | } begin() const; 13 | x1 end() const { 14 | LinguisticStream x2; 15 | for (x1 x3 = x2.begin x3 != x2.end; ++x3) 16 | x3->x0 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /test/clang-tidy/modernize-loop-convert.c: -------------------------------------------------------------------------------- 1 | // RUN: clang-tidy %s -checks=-*,modernize-loop-convert -- -std=c11 | count 0 2 | 3 | // Note: this test expects no diagnostics, but FileCheck cannot handle that, 4 | // hence the use of | count 0. 5 | 6 | int arr[6] = {1, 2, 3, 4, 5, 6}; 7 | 8 | void f(void) { 9 | for (int i = 0; i < 6; ++i) { 10 | (void)arr[i]; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/clang-tidy/modernize-pass-by-value-header.cpp: -------------------------------------------------------------------------------- 1 | // RUN: cp %S/Inputs/modernize-pass-by-value/header.h %T/pass-by-value-header.h 2 | // RUN: clang-tidy %s -checks='-*,modernize-pass-by-value' -header-filter='.*' -fix -- -std=c++11 -I %T | FileCheck %s -check-prefix=CHECK-MESSAGES -implicit-check-not="{{warning|error}}:" 3 | // RUN: FileCheck -input-file=%T/pass-by-value-header.h %s -check-prefix=CHECK-FIXES 4 | 5 | #include "pass-by-value-header.h" 6 | // CHECK-MESSAGES: :5:5: warning: pass by value and use std::move [modernize-pass-by-value] 7 | // CHECK-FIXES: #include 8 | // CHECK-FIXES: A(ThreadId tid) : threadid(std::move(tid)) {} 9 | -------------------------------------------------------------------------------- /test/clang-tidy/modernize-pass-by-value-macro-header.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s modernize-pass-by-value %t -- -- -std=c++11 -isystem %S/Inputs/Headers 2 | 3 | // CHECK-FIXES: #include 4 | 5 | #define HEADER <./a.h> 6 | #include HEADER 7 | 8 | struct A { 9 | }; 10 | 11 | struct B { 12 | B(const A &a) : a(a) {} 13 | // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: pass by value and use std::move [modernize-pass-by-value] 14 | // CHECK-FIXES: B(A a) : a(std::move(a)) {} 15 | A a; 16 | }; 17 | -------------------------------------------------------------------------------- /test/clang-tidy/modernize-raw-string-literal-delimiter.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s modernize-raw-string-literal %t -- -config='{CheckOptions: [{key: "modernize-raw-string-literal.DelimiterStem", value: "str"}]}' -- -std=c++11 2 | 3 | char const *const ContainsSentinel{"who\\ops)\""}; 4 | // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: {{.*}} can be written as a raw string literal 5 | // CHECK-FIXES: {{^}}char const *const ContainsSentinel{R"str(who\ops)")str"};{{$}} 6 | 7 | //char const *const ContainsDelim{"whoops)\")lit\""}; 8 | // CHECK-XMESSAGES: :[[@LINE-1]]:33: warning: {{.*}} can be written as a raw string literal 9 | // CHECK-XFIXES: {{^}}char const *const ContainsDelim{R"lit1(whoops)")lit")lit1"};{{$}} 10 | -------------------------------------------------------------------------------- /test/clang-tidy/modernize-redundant-void-arg-delayed.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s modernize-redundant-void-arg %t -- -- -fdelayed-template-parsing 2 | 3 | int foo(void) { 4 | // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: redundant void argument list in function definition [modernize-redundant-void-arg] 5 | // CHECK-FIXES: {{^}}int foo() {{{$}} 6 | return 0; 7 | } 8 | 9 | template 10 | struct MyFoo { 11 | int foo(void) { 12 | // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: redundant void argument list in function definition [modernize-redundant-void-arg] 13 | // CHECK-FIXES: {{^}} int foo() {{{$}} 14 | return 0; 15 | } 16 | }; 17 | // Explicit instantiation. 18 | template class MyFoo; 19 | 20 | template 21 | struct MyBar { 22 | // This declaration isn't instantiated and won't be parsed 'delayed-template-parsing'. 23 | int foo(void) { 24 | // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: redundant void argument list in function definition [modernize-redundant-void-arg] 25 | // CHECK-FIXES: {{^}} int foo() {{{$}} 26 | return 0; 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /test/clang-tidy/modernize-use-default-delayed.cpp: -------------------------------------------------------------------------------- 1 | // RUN: clang-tidy %s -checks=-*,modernize-use-default -- -std=c++11 -fdelayed-template-parsing -fexceptions | count 0 2 | // Note: this test expects no diagnostics, but FileCheck cannot handle that, 3 | // hence the use of | count 0. 4 | 5 | template 6 | struct S { 7 | S& operator=(const S&) { return *this; } 8 | }; 9 | -------------------------------------------------------------------------------- /test/clang-tidy/modernize-use-nullptr.c: -------------------------------------------------------------------------------- 1 | // RUN: clang-tidy %s -checks=-*,modernize-use-nullptr -- | count 0 2 | 3 | // Note: this test expects no diagnostics, but FileCheck cannot handle that, 4 | // hence the use of | count 0. 5 | 6 | #define NULL 0 7 | void f(void) { 8 | char *str = NULL; // ok 9 | (void)str; 10 | } 11 | -------------------------------------------------------------------------------- /test/clang-tidy/modernize-use-override-cxx98.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s modernize-use-override %t -- -- -std=c++98 2 | 3 | struct Base { 4 | virtual ~Base() {} 5 | virtual void a(); 6 | virtual void b(); 7 | }; 8 | 9 | struct SimpleCases : public Base { 10 | public: 11 | virtual ~SimpleCases(); 12 | // CHECK-FIXES: {{^}} virtual ~SimpleCases(); 13 | 14 | void a(); 15 | // CHECK-FIXES: {{^}} void a(); 16 | 17 | virtual void b(); 18 | // CHECK-FIXES: {{^}} virtual void b(); 19 | }; 20 | -------------------------------------------------------------------------------- /test/clang-tidy/modernize-use-override-ms.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s modernize-use-override %t -- -- -fms-extensions -std=c++11 2 | 3 | // This test is designed to test ms-extension __declspec(dllexport) attributes. 4 | #define EXPORT __declspec(dllexport) 5 | 6 | class Base { 7 | virtual EXPORT void a(); 8 | }; 9 | 10 | class EXPORT InheritedBase { 11 | virtual void a(); 12 | }; 13 | 14 | class Derived : public Base { 15 | virtual EXPORT void a(); 16 | // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [modernize-use-override] 17 | // CHECK-FIXES: {{^}} EXPORT void a() override; 18 | }; 19 | 20 | class EXPORT InheritedDerived : public InheritedBase { 21 | virtual void a(); 22 | // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [modernize-use-override] 23 | // CHECK-FIXES: {{^}} void a() override; 24 | }; 25 | 26 | -------------------------------------------------------------------------------- /test/clang-tidy/nolint.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s google-explicit-constructor,clang-diagnostic-unused-variable %t -- -extra-arg=-Wunused-variable -- 2 | 3 | class A { A(int i); }; 4 | // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit 5 | 6 | class B { B(int i); }; // NOLINT 7 | 8 | class C { C(int i); }; // NOLINT(we-dont-care-about-categories-yet) 9 | 10 | void f() { 11 | int i; 12 | // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: unused variable 'i' [clang-diagnostic-unused-variable] 13 | int j; // NOLINT 14 | } 15 | 16 | // CHECK-MESSAGES: Suppressed 3 warnings (3 NOLINT) 17 | -------------------------------------------------------------------------------- /test/clang-tidy/overlapping.cpp: -------------------------------------------------------------------------------- 1 | // RUN: clang-tidy -checks=-*,llvm-include-order -header-filter=.* %s \ 2 | // RUN: -- -isystem %S/Inputs/Headers -I %S/Inputs/overlapping | \ 3 | // RUN: not grep "note: this fix will not be applied because it overlaps with another fix" 4 | 5 | #include 6 | #include "o.h" 7 | 8 | // Test that clang-tidy takes into account in which file we are doing the 9 | // replacements to determine if they overlap or not. In the file "o.h" there is 10 | // a similar error at the same file offset, but they do not overlap. 11 | -------------------------------------------------------------------------------- /test/clang-tidy/readability-braces-around-statements-assert-failure.cpp: -------------------------------------------------------------------------------- 1 | // RUN: clang-tidy -checks='-*,readability-braces-around-statements' %s -- 2 | 3 | // Note: this test expects no assert failure happened in clang-tidy. 4 | 5 | int test_failure() { 6 | if (std::rand()) { 7 | } 8 | } 9 | 10 | void test_failure2() { 11 | for (a b c;; 12 | } 13 | -------------------------------------------------------------------------------- /test/clang-tidy/readability-braces-around-statements-few-lines.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s readability-braces-around-statements %t -- -config="{CheckOptions: [{key: readability-braces-around-statements.ShortStatementLines, value: 4}]}" -- 2 | 3 | void do_something(const char *) {} 4 | 5 | bool cond(const char *) { 6 | return false; 7 | } 8 | 9 | void test() { 10 | if (cond("if1") /*comment*/) do_something("same-line"); 11 | 12 | if (cond("if2")) 13 | do_something("single-line"); 14 | 15 | if (cond("if3") /*comment*/) 16 | // some comment 17 | do_something("three" 18 | "lines"); 19 | 20 | if (cond("if4") /*comment*/) 21 | // some comment 22 | do_something("many" 23 | "many" 24 | "many" 25 | "many" 26 | "lines"); 27 | // CHECK-MESSAGES: :[[@LINE-7]]:31: warning: statement should be inside braces 28 | // CHECK-FIXES: if (cond("if4") /*comment*/) { 29 | // CHECK-FIXES: } 30 | } 31 | -------------------------------------------------------------------------------- /test/clang-tidy/readability-braces-around-statements-single-line.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s readability-braces-around-statements %t -- -config="{CheckOptions: [{key: readability-braces-around-statements.ShortStatementLines, value: 2}]}" -- 2 | 3 | void do_something(const char *) {} 4 | 5 | bool cond(const char *) { 6 | return false; 7 | } 8 | 9 | void test() { 10 | if (cond("if1") /*comment*/) do_something("same-line"); 11 | 12 | if (cond("if2")) 13 | do_something("single-line"); 14 | 15 | if (cond("if3") /*comment*/) 16 | // some comment 17 | do_something("three" 18 | "lines"); 19 | // CHECK-MESSAGES: :[[@LINE-4]]:31: warning: statement should be inside braces 20 | // CHECK-FIXES: if (cond("if3") /*comment*/) { 21 | // CHECK-FIXES: } 22 | 23 | if (cond("if4") /*comment*/) 24 | // some comment 25 | do_something("many" 26 | "many" 27 | "many" 28 | "many" 29 | "lines"); 30 | // CHECK-MESSAGES: :[[@LINE-7]]:31: warning: statement should be inside braces 31 | // CHECK-FIXES: if (cond("if4") /*comment*/) { 32 | // CHECK-FIXES: } 33 | } 34 | -------------------------------------------------------------------------------- /test/clang-tidy/readability-else-after-return.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %check_clang_tidy %s readability-else-after-return %t 2 | 3 | void f(int a) { 4 | if (a > 0) 5 | return; 6 | else // comment 7 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: don't use else after return 8 | // CHECK-FIXES: {{^}} // comment 9 | return; 10 | 11 | if (a > 0) { 12 | return; 13 | } else { // comment 14 | // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: don't use else after return 15 | // CHECK-FIXES: } // comment 16 | return; 17 | } 18 | 19 | if (a > 0) { 20 | f(0); 21 | if (a > 10) 22 | return; 23 | } else { 24 | return; 25 | } 26 | 27 | if (a > 0) 28 | f(0); 29 | else if (a > 10) 30 | return; 31 | else 32 | f(0); 33 | } 34 | 35 | -------------------------------------------------------------------------------- /test/clang-tidy/select-checks.cpp: -------------------------------------------------------------------------------- 1 | // RUN: clang-tidy %s -checks='-*,llvm-namespace-*' -- 2>&1 | FileCheck -implicit-check-not='{{warning:|error:}}' %s 2 | // RUN: clang-tidy %s -checks='-*,an-unknown-check' -- 2>&1 | FileCheck -implicit-check-not='{{warning:|error:}}' -check-prefix=CHECK2 %s 3 | 4 | // CHECK2: Error: no checks enabled. 5 | 6 | namespace i { 7 | } 8 | // CHECK: :[[@LINE-1]]:2: warning: namespace 'i' not terminated with a closing comment [llvm-namespace-comment] 9 | 10 | // Expect no warnings from the google-explicit-constructor check: 11 | class A { A(int i); }; 12 | -------------------------------------------------------------------------------- /test/clang-tidy/serialize-diagnostics.cpp: -------------------------------------------------------------------------------- 1 | // RUN: clang-tidy -checks=-*,llvm-namespace-comment %s -- -serialize-diagnostics %t | FileCheck %s 2 | // CHECK: :[[@LINE+1]]:12: error: expected ';' after struct [clang-diagnostic-error] 3 | struct A {} 4 | -------------------------------------------------------------------------------- /test/clang-tidy/static-analyzer-config.cpp: -------------------------------------------------------------------------------- 1 | // RUN: clang-tidy %s -checks='-*,clang-analyzer-unix.Malloc' -config='{CheckOptions: [{ key: "clang-analyzer-unix.Malloc:Optimistic", value: true}]}' -- | FileCheck %s 2 | typedef __typeof(sizeof(int)) size_t; 3 | void *malloc(size_t); 4 | void free(void *); 5 | void __attribute((ownership_returns(malloc))) *my_malloc(size_t); 6 | void __attribute((ownership_takes(malloc, 1))) my_free(void *); 7 | 8 | void f1() { 9 | void *p = malloc(12); 10 | return; 11 | // CHECK: warning: Potential leak of memory pointed to by 'p' [clang-analyzer-unix.Malloc] 12 | } 13 | 14 | void af2() { 15 | void *p = my_malloc(12); 16 | my_free(p); 17 | free(p); 18 | // CHECK: warning: Attempt to free released memory [clang-analyzer-unix.Malloc] 19 | } 20 | -------------------------------------------------------------------------------- /test/clang-tidy/static-analyzer.cpp: -------------------------------------------------------------------------------- 1 | // RUN: clang-tidy %s -checks='-*,clang-analyzer-*,-clang-analyzer-alpha*' -- | FileCheck %s 2 | extern void *malloc(unsigned long); 3 | extern void free(void *); 4 | 5 | void f() { 6 | int *p = new int(42); 7 | delete p; 8 | delete p; 9 | // CHECK: warning: Attempt to free released memory [clang-analyzer-cplusplus.NewDelete] 10 | } 11 | 12 | void g() { 13 | void *q = malloc(132); 14 | free(q); 15 | free(q); 16 | // CHECK: warning: Attempt to free released memory [clang-analyzer-unix.Malloc] 17 | } 18 | -------------------------------------------------------------------------------- /test/clang-tidy/temporaries.cpp: -------------------------------------------------------------------------------- 1 | // RUN: clang-tidy -checks='-*,clang-analyzer-core.NullDereference' -analyze-temporary-dtors %s -- | FileCheck %s 2 | 3 | struct NoReturnDtor { 4 | ~NoReturnDtor() __attribute__((noreturn)); 5 | }; 6 | 7 | extern bool check(const NoReturnDtor &); 8 | 9 | // CHECK-NOT: warning 10 | void testNullPointerDereferencePositive() { 11 | int *value = 0; 12 | // CHECK: [[@LINE+1]]:10: warning: Dereference of null pointer (loaded from variable 'value') [clang-analyzer-core.NullDereference] 13 | *value = 1; 14 | } 15 | 16 | // CHECK-NOT: warning 17 | void testNullPointerDereference() { 18 | int *value = 0; 19 | if (check(NoReturnDtor())) { 20 | // This unreachable code causes a warning if we don't run with -analyze-temporary-dtors 21 | *value = 1; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /test/clang-tidy/validate-check-names.cpp: -------------------------------------------------------------------------------- 1 | // Check names may only contain alphanumeric characters, '-', '_', and '.'. 2 | // RUN: clang-tidy -checks=* -list-checks | grep '^ ' | cut -b5- | not grep -v '^[a-zA-Z0-9_.\-]\+$' 3 | -------------------------------------------------------------------------------- /test/clang-tidy/werrors-diagnostics.cpp: -------------------------------------------------------------------------------- 1 | // RUN: clang-tidy %s -checks='-*,llvm-namespace-comment,clang-diagnostic*' \ 2 | // RUN: -- -Wunused-variable 2>&1 \ 3 | // RUN: | FileCheck %s --check-prefix=CHECK-WARN -implicit-check-not='{{warning|error}}:' 4 | // RUN: not clang-tidy %s -checks='-*,llvm-namespace-comment,clang-diagnostic*' \ 5 | // RUN: -warnings-as-errors='clang-diagnostic*' -- -Wunused-variable 2>&1 \ 6 | // RUN: | FileCheck %s --check-prefix=CHECK-WERR -implicit-check-not='{{warning|error}}:' 7 | 8 | void f() { int i; } 9 | // CHECK-WARN: warning: unused variable 'i' [clang-diagnostic-unused-variable] 10 | // CHECK-WERR: error: unused variable 'i' [clang-diagnostic-unused-variable,-warnings-as-errors] 11 | 12 | // CHECK-WARN-NOT: treated as 13 | // CHECK-WERR: 1 warning treated as error 14 | -------------------------------------------------------------------------------- /test/clang-tidy/werrors-plural.cpp: -------------------------------------------------------------------------------- 1 | // RUN: clang-tidy %s -checks='-*,llvm-namespace-comment,clang-diagnostic*' -- 2>&1 \ 2 | // RUN: | FileCheck %s --check-prefix=CHECK-WARN -implicit-check-not='{{warning|error}}:' 3 | // RUN: not clang-tidy %s -checks='-*,llvm-namespace-comment,clang-diagnostic*' \ 4 | // RUN: -warnings-as-errors='llvm-namespace-comment' -- 2>&1 \ 5 | // RUN: | FileCheck %s --check-prefix=CHECK-WERR -implicit-check-not='{{warning|error}}:' 6 | 7 | namespace j { 8 | } 9 | // CHECK-WARN: warning: namespace 'j' not terminated with a closing comment [llvm-namespace-comment] 10 | // CHECK-WERR: error: namespace 'j' not terminated with a closing comment [llvm-namespace-comment,-warnings-as-errors] 11 | 12 | namespace k { 13 | } 14 | // CHECK-WARN: warning: namespace 'k' not terminated with a closing comment [llvm-namespace-comment] 15 | // CHECK-WERR: error: namespace 'k' not terminated with a closing comment [llvm-namespace-comment,-warnings-as-errors] 16 | 17 | // CHECK-WARN-NOT: treated as 18 | // CHECK-WERR: 2 warnings treated as errors 19 | -------------------------------------------------------------------------------- /test/clang-tidy/werrors.cpp: -------------------------------------------------------------------------------- 1 | // RUN: clang-tidy %s -checks='-*,llvm-namespace-comment' -- 2>&1 | FileCheck %s --check-prefix=CHECK-WARN -implicit-check-not='{{warning|error}}:' 2 | // RUN: not clang-tidy %s -checks='-*,llvm-namespace-comment' -warnings-as-errors='llvm-namespace-comment' -- 2>&1 | FileCheck %s --check-prefix=CHECK-WERR -implicit-check-not='{{warning|error}}:' 3 | 4 | namespace i { 5 | } 6 | // CHECK-WARN: warning: namespace 'i' not terminated with a closing comment [llvm-namespace-comment] 7 | // CHECK-WERR: error: namespace 'i' not terminated with a closing comment [llvm-namespace-comment,-warnings-as-errors] 8 | 9 | // CHECK-WARN-NOT: treated as 10 | // CHECK-WERR: 1 warning treated as error 11 | -------------------------------------------------------------------------------- /test/include-fixer/Inputs/database_template.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "directory": "test_dir/build", 4 | "command": "clang++ -I../include -o bar.o test_dir/src/bar.cpp", 5 | "file": "test_dir/src/bar.cpp" 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /test/include-fixer/Inputs/fake_yaml_db.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | Name: foo 3 | Contexts: 4 | - ContextType: Namespace 5 | ContextName: a 6 | - ContextType: Namespace 7 | ContextName: b 8 | FilePath: foo.h 9 | LineNumber: 1 10 | Type: Class 11 | ... 12 | --- 13 | Name: bar 14 | Contexts: 15 | - ContextType: Namespace 16 | ContextName: a 17 | - ContextType: Namespace 18 | ContextName: b 19 | FilePath: ../include/bar.h 20 | LineNumber: 1 21 | Type: Class 22 | ... 23 | -------------------------------------------------------------------------------- /test/include-fixer/exit_on_fatal.cpp: -------------------------------------------------------------------------------- 1 | // REQUIRES: shell 2 | // RUN: sed -e 's#//.*$##' %s > %t.cpp 3 | // RUN: not clang-include-fixer -db=fixed -input='foo= "foo.h"' %t.cpp -- 4 | // RUN: FileCheck %s -input-file=%t.cpp 5 | 6 | // CHECK-NOT: #include 7 | // CHECK: #include "doesnotexist.h" 8 | // CHECK-NEXT: foo f; 9 | 10 | #include "doesnotexist.h" 11 | foo f; 12 | -------------------------------------------------------------------------------- /test/include-fixer/fixeddb.cpp: -------------------------------------------------------------------------------- 1 | // REQUIRES: shell 2 | // RUN: sed -e 's#//.*$##' %s > %t.cpp 3 | // RUN: clang-include-fixer -db=fixed -input='foo= "foo.h","bar.h"' %t.cpp -- 4 | // RUN: FileCheck %s -input-file=%t.cpp 5 | 6 | // CHECK: #include "foo.h" 7 | // CHECK: foo f; 8 | 9 | foo f; 10 | -------------------------------------------------------------------------------- /test/include-fixer/include_path.cpp: -------------------------------------------------------------------------------- 1 | // REQUIRES: shell 2 | // RUN: mkdir -p %T/include-fixer/include 3 | // RUN: mkdir -p %T/include-fixer/build 4 | // RUN: mkdir -p %T/include-fixer/src 5 | // RUN: sed 's|test_dir|%T/include-fixer|g' %S/Inputs/database_template.json > %T/include-fixer/build/compile_commands.json 6 | // RUN: cp %S/Inputs/fake_yaml_db.yaml %T/include-fixer/build/fake_yaml_db.yaml 7 | // RUN: echo 'b::a::bar f;' > %T/include-fixer/src/bar.cpp 8 | // RUN: touch %T/include-fixer/include/bar.h 9 | // RUN: cd %T/include-fixer/build 10 | // RUN: clang-include-fixer -db=yaml -input=fake_yaml_db.yaml -p=. %T/include-fixer/src/bar.cpp 11 | // RUN: FileCheck -input-file=%T/include-fixer/src/bar.cpp %s 12 | 13 | // CHECK: #include "bar.h" 14 | // CHECK: b::a::bar f; 15 | -------------------------------------------------------------------------------- /test/include-fixer/yamldb.cpp: -------------------------------------------------------------------------------- 1 | // REQUIRES: shell 2 | // RUN: sed -e 's#//.*$##' %s > %t.cpp 3 | // RUN: clang-include-fixer -db=yaml -input=%p/Inputs/fake_yaml_db.yaml %t.cpp -- 4 | // RUN: FileCheck %s -input-file=%t.cpp 5 | 6 | // CHECK: #include "foo.h" 7 | // CHECK: b::a::foo f; 8 | 9 | b::a::foo f; 10 | -------------------------------------------------------------------------------- /test/include-fixer/yamldb_autodetect.cpp: -------------------------------------------------------------------------------- 1 | // REQUIRES: shell 2 | // RUN: mkdir -p %T/foo/bar 3 | // RUN: cp %p/Inputs/fake_yaml_db.yaml %T/find_all_symbols_db.yaml 4 | // RUN: cd %T/foo 5 | // RUN: sed -e 's#//.*$##' %s > bar/test.cpp 6 | // RUN: clang-include-fixer -db=yaml bar/test.cpp -- 7 | // RUN: FileCheck %s -input-file=bar/test.cpp 8 | 9 | // CHECK: #include "foo.h" 10 | // CHECK: b::a::foo f; 11 | 12 | b::a::foo f; 13 | -------------------------------------------------------------------------------- /test/lit.site.cfg.in: -------------------------------------------------------------------------------- 1 | @LIT_SITE_CFG_IN_HEADER@ 2 | 3 | import sys 4 | 5 | config.llvm_tools_dir = "@LLVM_TOOLS_DIR@" 6 | config.llvm_libs_dir = "@LLVM_LIBS_DIR@" 7 | config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@" 8 | config.clang_tools_binary_dir = "@CLANG_TOOLS_BINARY_DIR@" 9 | config.clang_tools_dir = "@CLANG_TOOLS_DIR@" 10 | config.python_executable = "@PYTHON_EXECUTABLE@" 11 | config.target_triple = "@TARGET_TRIPLE@" 12 | 13 | # Support substitution of the tools and libs dirs with user parameters. This is 14 | # used when we can't determine the tool dir at configuration time. 15 | try: 16 | config.clang_tools_dir = config.clang_tools_dir % lit_config.params 17 | config.llvm_tools_dir = config.llvm_tools_dir % lit_config.params 18 | config.llvm_libs_dir = config.llvm_libs_dir % lit_config.params 19 | except KeyError: 20 | e = sys.exc_info()[1] 21 | key, = e.args 22 | lit_config.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key,key)) 23 | 24 | # Let the main config do the real work. 25 | lit_config.load_config(config, "@CLANG_TOOLS_SOURCE_DIR@/test/lit.cfg") 26 | -------------------------------------------------------------------------------- /test/modularize/Inputs/Anonymous.h: -------------------------------------------------------------------------------- 1 | // Exercise some anonymous type issues. 2 | 3 | // Anonymous enum. 4 | enum { 5 | Tag1 6 | }; 7 | 8 | // Anonymous enum typedef. 9 | typedef enum { 10 | Tag2 11 | } AnonymousEnum; 12 | -------------------------------------------------------------------------------- /test/modularize/Inputs/CompileError/HasError.h: -------------------------------------------------------------------------------- 1 | typedef WithoutDep BadType; 2 | 3 | -------------------------------------------------------------------------------- /test/modularize/Inputs/CompileError/Level1A.h: -------------------------------------------------------------------------------- 1 | #define MACRO_1A 1 2 | -------------------------------------------------------------------------------- /test/modularize/Inputs/CompileError/module.modulemap: -------------------------------------------------------------------------------- 1 | // module.map 2 | 3 | module Level1A { 4 | header "Level1A.h" 5 | export * 6 | } 7 | module HasError { 8 | header "HasError.h" 9 | export * 10 | } 11 | -------------------------------------------------------------------------------- /test/modularize/Inputs/CoverageNoProblems/Includes1/.hidden/DontFindMe.h: -------------------------------------------------------------------------------- 1 | #error DontFindMe.h shouldn't be found. 2 | 3 | 4 | -------------------------------------------------------------------------------- /test/modularize/Inputs/CoverageNoProblems/Includes1/Level1A.h: -------------------------------------------------------------------------------- 1 | #define MACRO_1A 1 2 | -------------------------------------------------------------------------------- /test/modularize/Inputs/CoverageNoProblems/Includes2/Level2A.h: -------------------------------------------------------------------------------- 1 | #define MACRO_2A 1 2 | -------------------------------------------------------------------------------- /test/modularize/Inputs/CoverageNoProblems/NonIncludes/Level3A.h: -------------------------------------------------------------------------------- 1 | #define MACRO_3A 1 2 | -------------------------------------------------------------------------------- /test/modularize/Inputs/CoverageNoProblems/module.modulemap: -------------------------------------------------------------------------------- 1 | // module.map 2 | 3 | module Level1A { 4 | header "Includes1/Level1A.h" 5 | export * 6 | } 7 | module Level2A { 8 | header "Includes2/Level2A.h" 9 | export * 10 | } 11 | -------------------------------------------------------------------------------- /test/modularize/Inputs/CoverageProblems/Level1A.h: -------------------------------------------------------------------------------- 1 | #include "Level2A.h" 2 | #define MACRO_1A 1 3 | -------------------------------------------------------------------------------- /test/modularize/Inputs/CoverageProblems/Level1B.h: -------------------------------------------------------------------------------- 1 | #include "Level2B.h" 2 | #define MACRO_1B 1 3 | -------------------------------------------------------------------------------- /test/modularize/Inputs/CoverageProblems/Level2A.h: -------------------------------------------------------------------------------- 1 | #define MACRO_2A 1 2 | -------------------------------------------------------------------------------- /test/modularize/Inputs/CoverageProblems/Level2B.h: -------------------------------------------------------------------------------- 1 | #define MACRO_2B 1 2 | -------------------------------------------------------------------------------- /test/modularize/Inputs/CoverageProblems/Level3A.h: -------------------------------------------------------------------------------- 1 | #include "Sub/Level3B.h" 2 | #define MACRO_3A 1 3 | -------------------------------------------------------------------------------- /test/modularize/Inputs/CoverageProblems/Level3B: -------------------------------------------------------------------------------- 1 | #define MACRO_3B 1 2 | -------------------------------------------------------------------------------- /test/modularize/Inputs/CoverageProblems/Sub/Level3B.h: -------------------------------------------------------------------------------- 1 | #define MACRO_3B 1 2 | -------------------------------------------------------------------------------- /test/modularize/Inputs/CoverageProblems/UmbrellaFile.h: -------------------------------------------------------------------------------- 1 | #define UMBRELLA_HEADER 1 2 | #include "UmbrellaInclude1.h" 3 | #include "UmbrellaInclude2.h" 4 | -------------------------------------------------------------------------------- /test/modularize/Inputs/CoverageProblems/UmbrellaInclude1.h: -------------------------------------------------------------------------------- 1 | #define UMBRELLA_INCLUDE_1 1 2 | -------------------------------------------------------------------------------- /test/modularize/Inputs/CoverageProblems/UmbrellaInclude2.h: -------------------------------------------------------------------------------- 1 | #define UMBRELLA_INCLUDE_2 1 2 | -------------------------------------------------------------------------------- /test/modularize/Inputs/CoverageProblems/UmbrellaSub/Umbrell1.h: -------------------------------------------------------------------------------- 1 | #define UMBRELLA_1 1 2 | -------------------------------------------------------------------------------- /test/modularize/Inputs/CoverageProblems/UmbrellaSub/Umbrell2.h: -------------------------------------------------------------------------------- 1 | #define UMBRELLA_2 1 2 | -------------------------------------------------------------------------------- /test/modularize/Inputs/CoverageProblems/module.modulemap: -------------------------------------------------------------------------------- 1 | // module.map 2 | 3 | module Level1A { 4 | header "Level1A.h" 5 | export * 6 | } 7 | module Level1B { 8 | header "Level1B.h" 9 | export * 10 | module Level2B { 11 | header "Level2B.h" 12 | export * 13 | } 14 | } 15 | module Level2A { 16 | header "Level2A.h" 17 | export * 18 | } 19 | module UmbrellaDirectoryModule { 20 | umbrella "UmbrellaSub" 21 | } 22 | module UmbrellaHeaderModule { 23 | umbrella header "UmbrellaFile.h" 24 | } 25 | /* 26 | module NoHeader { 27 | header "NoHeader.h" 28 | export * 29 | } 30 | */ 31 | -------------------------------------------------------------------------------- /test/modularize/Inputs/DuplicateHeader1.h: -------------------------------------------------------------------------------- 1 | // Same decl as in DuplicateHeader2.h. 2 | typedef int TypeInt; 3 | -------------------------------------------------------------------------------- /test/modularize/Inputs/DuplicateHeader2.h: -------------------------------------------------------------------------------- 1 | // Same decl as in DuplicateHeader1.h. 2 | typedef int TypeInt; 3 | -------------------------------------------------------------------------------- /test/modularize/Inputs/Empty.h: -------------------------------------------------------------------------------- 1 | // Empty header for testing #include directives in blocks. 2 | -------------------------------------------------------------------------------- /test/modularize/Inputs/HeaderGuard.h: -------------------------------------------------------------------------------- 1 | #ifndef _HEADERGUARD_H_ 2 | #define _HEADERGUARD_H_ 3 | #include "HeaderGuardSub1.h" 4 | #include "HeaderGuardSub2.h" 5 | #include "HeaderGuardSubSub.h" 6 | #endif // _HEADERGUARD_H_ 7 | -------------------------------------------------------------------------------- /test/modularize/Inputs/HeaderGuardSub1.h: -------------------------------------------------------------------------------- 1 | #ifndef _HEADERGUARDSUB1_H_ 2 | #define _HEADERGUARDSUB1_H_ 3 | #include "HeaderGuardSubSub.h" 4 | #include "HeaderGuardSubSubDefined.h" 5 | #endif // _HEADERGUARDSUB1_H_ 6 | -------------------------------------------------------------------------------- /test/modularize/Inputs/HeaderGuardSub2.h: -------------------------------------------------------------------------------- 1 | #ifndef _HEADERGUARDSUB2_H_ 2 | #define _HEADERGUARDSUB2_H_ 3 | #include "HeaderGuardSubSub.h" 4 | #include "HeaderGuardSubSubDefined.h" 5 | #endif // _HEADERGUARDSUB2_H_ 6 | -------------------------------------------------------------------------------- /test/modularize/Inputs/HeaderGuardSubSub.h: -------------------------------------------------------------------------------- 1 | #ifndef _HEADERGUARDSUBSUB_H_ 2 | #define _HEADERGUARDSUBSUB_H_ 3 | 4 | #define SOMETHING 1 5 | 6 | // Nest include. Header guard should not confuse modularize. 7 | #include "HeaderGuard.h" 8 | 9 | #endif // _HEADERGUARDSUBSUB_H_ 10 | -------------------------------------------------------------------------------- /test/modularize/Inputs/HeaderGuardSubSubDefined.h: -------------------------------------------------------------------------------- 1 | #if !defined(_HEADERGUARDSUBSUBDEFINED_H_) 2 | #define _HEADERGUARDSUBSUBDEFINED_H_ 3 | 4 | #define SOMETHING_OTHER 1 5 | 6 | // Nest include. Header guard should not confuse modularize. 7 | #include "HeaderGuard.h" 8 | 9 | #endif // _HEADERGUARDSUBSUBDEFINED_H_ 10 | -------------------------------------------------------------------------------- /test/modularize/Inputs/IncludeInExtern.h: -------------------------------------------------------------------------------- 1 | extern "C" { 2 | #include "Empty.h" 3 | } 4 | -------------------------------------------------------------------------------- /test/modularize/Inputs/IncludeInNamespace.h: -------------------------------------------------------------------------------- 1 | namespace MyNamespace { 2 | #include "Empty.h" 3 | } 4 | -------------------------------------------------------------------------------- /test/modularize/Inputs/InconsistentHeader1.h: -------------------------------------------------------------------------------- 1 | // Define symbol such that a declaration exists when this header 2 | // is included, but not when InconsistentHeader2.h is included. 3 | #define SYMBOL1 1 4 | #include "InconsistentSubHeader.h" 5 | -------------------------------------------------------------------------------- /test/modularize/Inputs/InconsistentHeader2.h: -------------------------------------------------------------------------------- 1 | // Set up so the declaration in InconsistentSubHeader.h is not defined. 2 | #define SYMBOL2 1 3 | #include "InconsistentSubHeader.h" 4 | -------------------------------------------------------------------------------- /test/modularize/Inputs/InconsistentSubHeader.h: -------------------------------------------------------------------------------- 1 | // Set up so TypeInt only defined during InconsistentHeader1.h include. 2 | #ifdef SYMBOL1 3 | #define SYMBOL 1 4 | #define FUNC_STYLE(a, b) a||b 5 | #endif 6 | #ifdef SYMBOL2 7 | #define SYMBOL 2 8 | #define FUNC_STYLE(a, b) a&&b 9 | #endif 10 | 11 | #if SYMBOL == 1 12 | typedef int TypeInt; 13 | #endif 14 | 15 | int var = FUNC_STYLE(1, 0); 16 | 17 | #if defined(SYMBOL1) 18 | #endif 19 | -------------------------------------------------------------------------------- /test/modularize/Inputs/IsDependent.h: -------------------------------------------------------------------------------- 1 | // This header depends on SomeTypes.h for the TypeInt typedef. 2 | 3 | typedef TypeInt NewTypeInt; 4 | typedef OtherTypeInt OtherNewTypeInt; 5 | -------------------------------------------------------------------------------- /test/modularize/Inputs/MissingHeader/Level1A.h: -------------------------------------------------------------------------------- 1 | #define MACRO_1A 1 2 | -------------------------------------------------------------------------------- /test/modularize/Inputs/MissingHeader/module.modulemap: -------------------------------------------------------------------------------- 1 | // module.map 2 | 3 | module Level1A { 4 | header "Level1A.h" 5 | export * 6 | } 7 | module Missing { 8 | header "Missing.h" 9 | export * 10 | } 11 | -------------------------------------------------------------------------------- /test/modularize/Inputs/NamespaceClasses.h: -------------------------------------------------------------------------------- 1 | // Define same class name in different namespaces. 2 | 3 | namespace Namespace1 { 4 | class NamespaceClass { 5 | public: 6 | NamespaceClass() : Member(0) {} 7 | private: 8 | int Member; 9 | }; 10 | } 11 | 12 | namespace Namespace2 { 13 | class NamespaceClass { 14 | public: 15 | NamespaceClass() : Member(0) {} 16 | private: 17 | int Member; 18 | }; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /test/modularize/Inputs/NestedMacro.h: -------------------------------------------------------------------------------- 1 | // Verification of fix for nested macro. 2 | 3 | #define FUNCMACROINNER(a) a 4 | #define FUNCMACROOUTER(b, c) FUNCMACROINNER(b) + FUNCMACROINNER(c) 5 | int FuncMacroValue = FUNCMACROOUTER(1, 2); 6 | -------------------------------------------------------------------------------- /test/modularize/Inputs/NoProblems.modulemap: -------------------------------------------------------------------------------- 1 | // NoProblems.modulemap 2 | module SomeTypes { 3 | header "SomeTypes.h" 4 | export * 5 | } 6 | module SomeDecls { 7 | header "SomeDecls.h" 8 | export * 9 | } 10 | -------------------------------------------------------------------------------- /test/modularize/Inputs/ProblemsDuplicate.modulemap: -------------------------------------------------------------------------------- 1 | // ProblemsDuplicate.modulemap 2 | module DuplicateHeader1 { 3 | header "DuplicateHeader1.h" 4 | export * 5 | } 6 | module DuplicateHeader2 { 7 | header "DuplicateHeader2.h" 8 | export * 9 | } 10 | -------------------------------------------------------------------------------- /test/modularize/Inputs/SomeDecls.h: -------------------------------------------------------------------------------- 1 | // Declare a couple of functions - no modules problems. 2 | 3 | void FuncOne(); 4 | 5 | int FuncTwo(int arg); 6 | 7 | void FuncOverload(int arg) {} 8 | void FuncOverload(char *arg) {} 9 | 10 | namespace Namespace1 { 11 | void FuncNameSpace() {} 12 | } 13 | 14 | namespace Namespace2 { 15 | void FuncNameSpace() {} 16 | } 17 | -------------------------------------------------------------------------------- /test/modularize/Inputs/SomeOtherTypes.h: -------------------------------------------------------------------------------- 1 | // Declare another type for the dependency check. 2 | // This file dependent on SomeTypes.h being included first. 3 | 4 | typedef TypeInt OtherTypeInt; 5 | -------------------------------------------------------------------------------- /test/modularize/Inputs/SomeTypes.h: -------------------------------------------------------------------------------- 1 | // Define a few different kinds of types - no modules problems. 2 | 3 | typedef int TypeInt; 4 | 5 | typedef TypeInt NestedTypeInt; 6 | 7 | struct TypeStruct { 8 | int Member; 9 | }; 10 | 11 | class TypeClass { 12 | public: 13 | TypeClass() : Member(0) {} 14 | private: 15 | int Member; 16 | }; 17 | -------------------------------------------------------------------------------- /test/modularize/Inputs/SubModule1/Header1.h: -------------------------------------------------------------------------------- 1 | // Header1.h - Empty. 2 | -------------------------------------------------------------------------------- /test/modularize/Inputs/SubModule1/Header2.h: -------------------------------------------------------------------------------- 1 | // Header2.h - Empty. 2 | -------------------------------------------------------------------------------- /test/modularize/Inputs/SubModule2/Header3.h: -------------------------------------------------------------------------------- 1 | // Header3.h - Empty. 2 | -------------------------------------------------------------------------------- /test/modularize/Inputs/SubModule2/Header4.h: -------------------------------------------------------------------------------- 1 | // Header4.h - Empty. 2 | -------------------------------------------------------------------------------- /test/modularize/Inputs/TemplateClasses.h: -------------------------------------------------------------------------------- 1 | // Exercise some template issues. Should not produce errors. 2 | 3 | // Forward declaration. 4 | template class TemplateClass; 5 | 6 | // Full declaration. 7 | templateclass TemplateClass { 8 | public: 9 | TemplateClass() {} 10 | private: 11 | T Member; 12 | }; 13 | 14 | // Template alias. 15 | template using TemplateClassAlias = TemplateClass; 16 | -------------------------------------------------------------------------------- /test/modularize/NoProblems.modularize: -------------------------------------------------------------------------------- 1 | # RUN: modularize %s -x c++ 2 | # RUN: modularize -prefix=%p %s -x c++ 3 | # RUN: modularize -no-coverage-check %S/Inputs/NoProblems.modulemap -x c++ 4 | 5 | Inputs/SomeTypes.h 6 | Inputs/SomeDecls.h 7 | -------------------------------------------------------------------------------- /test/modularize/NoProblemsAnonymous.modularize: -------------------------------------------------------------------------------- 1 | # RUN: modularize %s -x c++ 2 | 3 | Inputs/Anonymous.h 4 | -------------------------------------------------------------------------------- /test/modularize/NoProblemsCoverage.modularize: -------------------------------------------------------------------------------- 1 | # RUN: modularize -I Includes1 -I Includes2 %S/Inputs/CoverageNoProblems/module.modulemap 2 | -------------------------------------------------------------------------------- /test/modularize/NoProblemsDependencies.modularize: -------------------------------------------------------------------------------- 1 | # RUN: modularize %s -x c++ 2 | 3 | Inputs/IsDependent.h: Inputs/SomeTypes.h Inputs/SomeOtherTypes.h 4 | -------------------------------------------------------------------------------- /test/modularize/NoProblemsGuard.modularize: -------------------------------------------------------------------------------- 1 | # RUN: modularize %s -x c++ 2 | 3 | Inputs/HeaderGuardSub1.h 4 | Inputs/HeaderGuardSub2.h 5 | Inputs/HeaderGuard.h 6 | -------------------------------------------------------------------------------- /test/modularize/NoProblemsList.modularize: -------------------------------------------------------------------------------- 1 | # RUN: modularize %S/NoProblems.modularize,%S/NoProblemsAnonymous.modularize -x c++ 2 | # RUN: modularize -prefix=%p %S/NoProblems.modularize,%S/NoProblemsAnonymous.modularize -x c++ 3 | -------------------------------------------------------------------------------- /test/modularize/NoProblemsNamespace.modularize: -------------------------------------------------------------------------------- 1 | # RUN: modularize -block-check-header-list-only 2 | 3 | Inputs/IncludeInNamespace.h 4 | -------------------------------------------------------------------------------- /test/modularize/NoProblemsNamespaceClasses.modularize: -------------------------------------------------------------------------------- 1 | # RUN: modularize %s -x c++ 2 | 3 | Inputs/NamespaceClasses.h 4 | -------------------------------------------------------------------------------- /test/modularize/NoProblemsNestedMacro.modularize: -------------------------------------------------------------------------------- 1 | # RUN: modularize %s -x c++ 2 | 3 | Inputs/NestedMacro.h 4 | -------------------------------------------------------------------------------- /test/modularize/NoProblemsTemplateClasses.modularize: -------------------------------------------------------------------------------- 1 | # RUN: modularize %s -x c++ 2 | 3 | Inputs/TemplateClasses.h 4 | -------------------------------------------------------------------------------- /test/modularize/ProblemsCompileError.modularize: -------------------------------------------------------------------------------- 1 | # RUN: not modularize %S/Inputs/CompileError/module.modulemap 2>&1 | FileCheck %s 2 | 3 | # CHECK: {{.*}}{{[/\\]}}Inputs{{[/\\]}}CompileError{{[/\\]}}HasError.h:1:9: error: unknown type name 'WithoutDep' 4 | -------------------------------------------------------------------------------- /test/modularize/ProblemsCoverage.modularize: -------------------------------------------------------------------------------- 1 | # RUN: not modularize %S/Inputs/CoverageProblems/module.modulemap 2>&1 | FileCheck %s 2 | 3 | # CHECK: warning: {{.*}}{{[/\\]}}Inputs/CoverageProblems/module.modulemap does not account for file: {{.*}}{{[/\\]}}Inputs/CoverageProblems/Level3A.h 4 | # CHECK-NEXT: warning: {{.*}}{{[/\\]}}Inputs/CoverageProblems/module.modulemap does not account for file: {{.*}}{{[/\\]}}Inputs/CoverageProblems/Level3B 5 | # CHECK-NEXT: warning: {{.*}}{{[/\\]}}Inputs/CoverageProblems/module.modulemap does not account for file: {{.*}}{{[/\\]}}Inputs/CoverageProblems/Sub/Level3B.h 6 | -------------------------------------------------------------------------------- /test/modularize/ProblemsDisplayLists.modularize: -------------------------------------------------------------------------------- 1 | # RUN: not modularize -display-file-lists %S/Inputs/CompileError/module.modulemap 2>&1 | FileCheck %s 2 | 3 | # CHECK: {{.*}}{{[/\\]}}Inputs{{[/\\]}}CompileError{{[/\\]}}HasError.h:1:9: error: unknown type name 'WithoutDep' 4 | 5 | # CHECK: These are the files with possible errors: 6 | 7 | # CHECK: Inputs/CompileError/HasError.h 8 | 9 | # CHECK: These are the files with no detected errors: 10 | 11 | # CHECK: Inputs/CompileError/Level1A.h 12 | 13 | # CHECK: These are the combined files, with problem files preceded by #: 14 | 15 | # CHECK: {{.*}}Inputs/CompileError/HasError.h 16 | # CHECK: Inputs/CompileError/Level1A.h 17 | -------------------------------------------------------------------------------- /test/modularize/ProblemsDuplicate.modularize: -------------------------------------------------------------------------------- 1 | # RUN: not modularize %s -x c++ 2>&1 | FileCheck %s 2 | # RUN: not modularize %S/Inputs/ProblemsDuplicate.modulemap -x c++ 2>&1 | FileCheck %s 3 | 4 | Inputs/DuplicateHeader1.h 5 | Inputs/DuplicateHeader2.h 6 | 7 | # CHECK: error: value 'TypeInt' defined at multiple locations: 8 | # CHECK-NEXT: {{.*}}{{[/\\]}}Inputs{{[/\\]}}DuplicateHeader1.h:2:13 9 | # CHECK-NEXT: {{.*}}{{[/\\]}}Inputs{{[/\\]}}DuplicateHeader2.h:2:13 -------------------------------------------------------------------------------- /test/modularize/ProblemsExternC.modularize: -------------------------------------------------------------------------------- 1 | # RUN: not modularize %s -x c++ 2>&1 | FileCheck %s 2 | 3 | Inputs/IncludeInExtern.h 4 | 5 | # CHECK: {{.*}}{{[/\\]}}Inputs{{[/\\]}}IncludeInExtern.h:2:3: 6 | # CHECK-NEXT: #include "Empty.h" 7 | # CHECK-NEXT: ^ 8 | # CHECK-NEXT: error: Include directive within extern "C" {}. 9 | # CHECK-NEXT: {{.*}}{{[/\\]}}Inputs{{[/\\]}}IncludeInExtern.h:1:1: 10 | # CHECK-NEXT: extern "C" { 11 | # CHECK-NEXT: ^ 12 | # CHECK-NEXT: The "extern "C" {}" block is here. 13 | -------------------------------------------------------------------------------- /test/modularize/ProblemsMissingHeader.modularize: -------------------------------------------------------------------------------- 1 | # RUN: not modularize %S/Inputs/MissingHeader/module.modulemap 2>&1 | FileCheck %s 2 | 3 | # CHECK: {{.*}}{{[/\\]}}Inputs/MissingHeader/module.modulemap:8:10: error : Header not found: Missing.h 4 | -------------------------------------------------------------------------------- /test/modularize/ProblemsNamespace.modularize: -------------------------------------------------------------------------------- 1 | # RUN: not modularize %s -x c++ 2>&1 | FileCheck %s 2 | 3 | Inputs/IncludeInNamespace.h 4 | 5 | # CHECK: {{.*}}{{[/\\]}}Inputs{{[/\\]}}IncludeInNamespace.h:2:3: 6 | # CHECK-NEXT: #include "Empty.h" 7 | # CHECK-NEXT: ^ 8 | # CHECK-NEXT: error: Include directive within namespace MyNamespace {}. 9 | # CHECK-NEXT: {{.*}}{{[/\\]}}Inputs{{[/\\]}}IncludeInNamespace.h:1:1: 10 | # CHECK-NEXT: namespace MyNamespace { 11 | # CHECK-NEXT: ^ 12 | # CHECK-NEXT: The "namespace MyNamespace {}" block is here. 13 | -------------------------------------------------------------------------------- /test/modularize/SubModule2.h: -------------------------------------------------------------------------------- 1 | // SubModule2.h - Master header with same name as directory. 2 | #include "SubModule2/Header3.h" 3 | #include "SubModule2/Header4.h" 4 | -------------------------------------------------------------------------------- /test/pp-trace/Inputs/Level1A.h: -------------------------------------------------------------------------------- 1 | #include "Level2A.h" 2 | #define MACRO_1A 1 3 | -------------------------------------------------------------------------------- /test/pp-trace/Inputs/Level1B.h: -------------------------------------------------------------------------------- 1 | #include "Level2B.h" 2 | #define MACRO_1B 1 3 | -------------------------------------------------------------------------------- /test/pp-trace/Inputs/Level2A.h: -------------------------------------------------------------------------------- 1 | #define MACRO_2A 1 2 | -------------------------------------------------------------------------------- /test/pp-trace/Inputs/Level2B.h: -------------------------------------------------------------------------------- 1 | #define MACRO_2B 1 2 | -------------------------------------------------------------------------------- /test/pp-trace/Inputs/ModularizeList.txt: -------------------------------------------------------------------------------- 1 | Level1A.h 2 | Level1B.h 3 | Level2A.h 4 | Level2B.h 5 | -------------------------------------------------------------------------------- /test/pp-trace/Inputs/module.map: -------------------------------------------------------------------------------- 1 | // module.map 2 | 3 | module Level1A { 4 | header "Level1A.h" 5 | export * 6 | } 7 | module Level1B { 8 | header "Level1B.h" 9 | export * 10 | module Level2B { 11 | header "Level2B.h" 12 | export * 13 | } 14 | } 15 | module Level2A { 16 | header "Level2A.h" 17 | export * 18 | } 19 | -------------------------------------------------------------------------------- /test/pp-trace/pp-trace-ident.cpp: -------------------------------------------------------------------------------- 1 | // RUN: pp-trace -ignore FileChanged,MacroDefined %s -undef -target x86_64 -std=c++11 | FileCheck --strict-whitespace %s 2 | 3 | #ident "$Id$" 4 | 5 | // CHECK: --- 6 | // CHECK-NEXT: - Callback: Ident 7 | // CHECK-NEXT: Loc: "{{.*}}{{[/\\]}}pp-trace-ident.cpp:3:2" 8 | // CHECK-NEXT: Str: "$Id$" 9 | // CHECK-NEXT: - Callback: EndOfMainFile 10 | // CHECK-NEXT: ... 11 | -------------------------------------------------------------------------------- /test/pp-trace/pp-trace-modules.cpp: -------------------------------------------------------------------------------- 1 | // RUN: rm -rf %t 2 | // RUN: pp-trace -ignore FileChanged,MacroDefined %s -x objective-c++ -undef -target x86_64 -std=c++11 -fmodules -fcxx-modules -fmodules-cache-path=%t -I%S -I%S/Input | FileCheck --strict-whitespace %s 3 | 4 | // CHECK: --- 5 | 6 | @import Level1A; 7 | 8 | // CHECK-NEXT: - Callback: moduleImport 9 | // CHECK-NEXT: ImportLoc: "{{.*}}{{[/\\]}}pp-trace-modules.cpp:[[@LINE-3]]:2" 10 | // CHECK-NEXT: Path: [{Name: Level1A, Loc: "{{.*}}{{[/\\]}}pp-trace-modules.cpp:[[@LINE-4]]:9"}] 11 | // CHECK-NEXT: Imported: Level1A 12 | 13 | @import Level1B.Level2B; 14 | 15 | // CHECK-NEXT: - Callback: moduleImport 16 | // CHECK-NEXT: ImportLoc: "{{.*}}{{[/\\]}}pp-trace-modules.cpp:[[@LINE-3]]:2" 17 | // CHECK-NEXT: Path: [{Name: Level1B, Loc: "{{.*}}{{[/\\]}}pp-trace-modules.cpp:[[@LINE-4]]:9"}, {Name: Level2B, Loc: "{{.*}}{{[/\\]}}pp-trace-modules.cpp:[[@LINE-4]]:17"}] 18 | // CHECK-NEXT: Imported: Level2B 19 | // CHECK-NEXT: - Callback: EndOfMainFile 20 | // CHECK-NEXT: ... 21 | -------------------------------------------------------------------------------- /tool-template/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS 2 | Support 3 | ) 4 | 5 | add_clang_executable(tool-template 6 | ToolTemplate.cpp 7 | ) 8 | 9 | target_link_libraries(tool-template 10 | clangAST 11 | clangASTMatchers 12 | clangBasic 13 | clangFrontend 14 | clangTooling 15 | ) 16 | -------------------------------------------------------------------------------- /unittests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_custom_target(ExtraToolsUnitTests) 2 | set_target_properties(ExtraToolsUnitTests PROPERTIES FOLDER "Extra Tools Unit Tests") 3 | 4 | function(add_extra_unittest test_dirname) 5 | add_unittest(ExtraToolsUnitTests ${test_dirname} ${ARGN}) 6 | endfunction() 7 | 8 | add_subdirectory(clang-apply-replacements) 9 | add_subdirectory(clang-rename) 10 | add_subdirectory(clang-query) 11 | add_subdirectory(clang-tidy) 12 | add_subdirectory(include-fixer) 13 | -------------------------------------------------------------------------------- /unittests/clang-apply-replacements/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | get_filename_component(ClangApplyReplacementsLocation 2 | "${CMAKE_CURRENT_SOURCE_DIR}/../../clang-apply-replacements/include" REALPATH) 3 | get_filename_component(CommonIncLocation 4 | "${CMAKE_CURRENT_SOURCE_DIR}/../include" REALPATH) 5 | include_directories( 6 | ${ClangApplyReplacementsLocation} 7 | ${CommonIncLocation} 8 | ) 9 | 10 | add_extra_unittest(ClangApplyReplacementsTests 11 | ReformattingTest.cpp 12 | ) 13 | 14 | target_link_libraries(ClangApplyReplacementsTests 15 | clangApplyReplacements 16 | clangToolingCore 17 | ) 18 | -------------------------------------------------------------------------------- /unittests/clang-query/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS 2 | support 3 | ) 4 | 5 | include_directories( 6 | ${CMAKE_CURRENT_SOURCE_DIR}/../../clang-query 7 | ) 8 | 9 | add_extra_unittest(ClangQueryTests 10 | QueryEngineTest.cpp 11 | QueryParserTest.cpp 12 | ) 13 | 14 | target_link_libraries(ClangQueryTests 15 | clangAST 16 | clangASTMatchers 17 | clangBasic 18 | clangDynamicASTMatchers 19 | clangFrontend 20 | clangQuery 21 | clangTooling 22 | ) 23 | -------------------------------------------------------------------------------- /unittests/clang-rename/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS 2 | support 3 | ) 4 | 5 | get_filename_component(CLANG_RENAME_SOURCE_DIR 6 | ${CMAKE_CURRENT_SOURCE_DIR}/../../clang-rename REALPATH) 7 | include_directories( 8 | ${CLANG_RENAME_SOURCE_DIR} 9 | ) 10 | 11 | add_extra_unittest(ClangRenameTests 12 | USRLocFindingTest.cpp 13 | ${CLANG_RENAME_SOURCE_DIR}/USRFinder.cpp 14 | ${CLANG_RENAME_SOURCE_DIR}/USRFindingAction.cpp 15 | ) 16 | 17 | target_link_libraries(ClangRenameTests 18 | clangAST 19 | clangBasic 20 | clangFrontend 21 | clangIndex 22 | clangTooling 23 | ) 24 | -------------------------------------------------------------------------------- /unittests/clang-tidy/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS 2 | support 3 | ) 4 | 5 | get_filename_component(CLANG_LINT_SOURCE_DIR 6 | ${CMAKE_CURRENT_SOURCE_DIR}/../../clang-tidy REALPATH) 7 | include_directories(${CLANG_LINT_SOURCE_DIR}) 8 | 9 | add_extra_unittest(ClangTidyTests 10 | ClangTidyDiagnosticConsumerTest.cpp 11 | ClangTidyOptionsTest.cpp 12 | IncludeInserterTest.cpp 13 | GoogleModuleTest.cpp 14 | LLVMModuleTest.cpp 15 | MiscModuleTest.cpp 16 | OverlappingReplacementsTest.cpp 17 | ReadabilityModuleTest.cpp) 18 | 19 | target_link_libraries(ClangTidyTests 20 | clangAST 21 | clangASTMatchers 22 | clangBasic 23 | clangFrontend 24 | clangLex 25 | clangTidy 26 | clangTidyGoogleModule 27 | clangTidyLLVMModule 28 | clangTidyMiscModule 29 | clangTidyReadabilityModule 30 | clangTidyUtils 31 | clangTooling 32 | clangToolingCore 33 | ) 34 | -------------------------------------------------------------------------------- /unittests/include-fixer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS 2 | support 3 | ) 4 | 5 | get_filename_component(INCLUDE_FIXER_SOURCE_DIR 6 | ${CMAKE_CURRENT_SOURCE_DIR}/../../include-fixer REALPATH) 7 | include_directories( 8 | ${INCLUDE_FIXER_SOURCE_DIR} 9 | ) 10 | 11 | # We'd like to clang/unittests/Tooling/RewriterTestContext.h in the test. 12 | include_directories(${CLANG_SOURCE_DIR}) 13 | 14 | add_extra_unittest(IncludeFixerTests 15 | IncludeFixerTest.cpp 16 | ) 17 | 18 | target_link_libraries(IncludeFixerTests 19 | clangBasic 20 | clangFrontend 21 | clangIncludeFixer 22 | clangRewrite 23 | clangTooling 24 | clangToolingCore 25 | findAllSymbols 26 | ) 27 | 28 | add_subdirectory(find-all-symbols) 29 | -------------------------------------------------------------------------------- /unittests/include-fixer/find-all-symbols/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS 2 | support 3 | ) 4 | 5 | get_filename_component(INCLUDE_FIXER_SOURCE_DIR 6 | ${CMAKE_CURRENT_SOURCE_DIR}/../../../include-fixer/find-all-symbols REALPATH) 7 | include_directories( 8 | ${INCLUDE_FIXER_SOURCE_DIR} 9 | ) 10 | 11 | add_extra_unittest(FindAllSymbolsTests 12 | FindAllSymbolsTests.cpp 13 | ) 14 | 15 | target_link_libraries(FindAllSymbolsTests 16 | clangAST 17 | clangASTMatchers 18 | clangBasic 19 | clangFrontend 20 | clangLex 21 | clangTooling 22 | findAllSymbols 23 | ) 24 | --------------------------------------------------------------------------------