aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra')
-rw-r--r--clang-tools-extra/Maintainers.rst (renamed from clang-tools-extra/Maintainers.txt)11
-rw-r--r--clang-tools-extra/clang-doc/BitcodeReader.cpp74
-rw-r--r--clang-tools-extra/clang-doc/BitcodeReader.h8
-rw-r--r--clang-tools-extra/clang-doc/BitcodeWriter.cpp6
-rw-r--r--clang-tools-extra/clang-doc/BitcodeWriter.h9
-rw-r--r--clang-tools-extra/clang-doc/CMakeLists.txt1
-rw-r--r--clang-tools-extra/clang-doc/ClangDoc.cpp4
-rw-r--r--clang-tools-extra/clang-doc/ClangDoc.h2
-rw-r--r--clang-tools-extra/clang-doc/Generators.cpp145
-rw-r--r--clang-tools-extra/clang-doc/Generators.h89
-rw-r--r--clang-tools-extra/clang-doc/HTMLGenerator.cpp1217
-rw-r--r--clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp305
-rw-r--r--clang-tools-extra/clang-doc/JSONGenerator.cpp73
-rw-r--r--clang-tools-extra/clang-doc/MDGenerator.cpp13
-rw-r--r--clang-tools-extra/clang-doc/Mapper.cpp4
-rw-r--r--clang-tools-extra/clang-doc/Mapper.h1
-rw-r--r--clang-tools-extra/clang-doc/Representation.cpp21
-rw-r--r--clang-tools-extra/clang-doc/Representation.h150
-rw-r--r--clang-tools-extra/clang-doc/Serialize.cpp71
-rw-r--r--clang-tools-extra/clang-doc/Serialize.h5
-rw-r--r--clang-tools-extra/clang-doc/YAMLGenerator.cpp13
-rw-r--r--clang-tools-extra/clang-doc/assets/class-template.mustache99
-rw-r--r--clang-tools-extra/clang-doc/assets/comment-template.mustache85
-rw-r--r--clang-tools-extra/clang-doc/assets/enum-template.mustache20
-rw-r--r--clang-tools-extra/clang-doc/assets/function-template.mustache6
-rw-r--r--clang-tools-extra/clang-doc/assets/namespace-template.mustache38
-rw-r--r--clang-tools-extra/clang-doc/support/File.h2
-rw-r--r--clang-tools-extra/clang-doc/support/Utils.cpp23
-rw-r--r--clang-tools-extra/clang-doc/support/Utils.h4
-rw-r--r--clang-tools-extra/clang-doc/tool/ClangDocMain.cpp153
-rw-r--r--clang-tools-extra/clang-tidy/.clang-format7
-rw-r--r--clang-tools-extra/clang-tidy/.clang-tidy12
-rw-r--r--clang-tools-extra/clang-tidy/ClangTidy.cpp45
-rw-r--r--clang-tools-extra/clang-tidy/ClangTidyCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/ClangTidyCheck.h2
-rw-r--r--clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp71
-rw-r--r--clang-tools-extra/clang-tidy/ClangTidyOptions.cpp12
-rw-r--r--clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp3
-rw-r--r--clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp5
-rw-r--r--clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h13
-rw-r--r--clang-tools-extra/clang-tidy/FileExtensionsSet.h6
-rw-r--r--clang-tools-extra/clang-tidy/GlobList.cpp9
-rw-r--r--clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp11
-rw-r--r--clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h9
-rw-r--r--clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/abseil/DurationComparisonCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/abseil/DurationConversionCastCheck.cpp8
-rw-r--r--clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/abseil/DurationSubtractionCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp8
-rw-r--r--clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp10
-rw-r--r--clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp14
-rw-r--r--clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.h4
-rw-r--r--clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp5
-rw-r--r--clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/altera/SingleWorkItemBarrierCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp37
-rw-r--r--clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp20
-rw-r--r--clang-tools-extra/clang-tidy/android/CloexecAccept4Check.h6
-rw-r--r--clang-tools-extra/clang-tidy/android/CloexecAcceptCheck.cpp9
-rw-r--r--clang-tools-extra/clang-tidy/android/CloexecAcceptCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/android/CloexecCheck.cpp11
-rw-r--r--clang-tools-extra/clang-tidy/android/CloexecCheck.h12
-rw-r--r--clang-tools-extra/clang-tidy/android/CloexecCreatCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/android/CloexecDupCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/android/CloexecDupCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/android/CloexecEpollCreate1Check.h6
-rw-r--r--clang-tools-extra/clang-tidy/android/CloexecEpollCreateCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/android/CloexecFopenCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/android/CloexecInotifyInit1Check.h6
-rw-r--r--clang-tools-extra/clang-tidy/android/CloexecInotifyInitCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/android/CloexecMemfdCreateCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/android/CloexecOpenCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/android/CloexecOpenCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/android/CloexecPipe2Check.h6
-rw-r--r--clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/android/CloexecPipeCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/android/CloexecSocketCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/boost/UseRangesCheck.cpp8
-rw-r--r--clang-tools-extra/clang-tidy/boost/UseToStringCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp43
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp18
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp21
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt7
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/CapturingThisInMemberVariableCheck.cpp23
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/ChainedComparisonCheck.cpp1
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/ComparePointerToMemberVirtualFunctionCheck.cpp1
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/CopyConstructorMutatesArgumentCheck.cpp (renamed from clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.cpp)12
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/CopyConstructorMutatesArgumentCheck.h (renamed from clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.h)16
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp7
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp3
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/DefaultOperatorNewOnOveralignedTypeCheck.cpp (renamed from clang-tools-extra/clang-tidy/cert/DefaultOperatorNewAlignmentCheck.cpp)25
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/DefaultOperatorNewOnOveralignedTypeCheck.h (renamed from clang-tools-extra/clang-tidy/cert/DefaultOperatorNewAlignmentCheck.h)17
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp111
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/ExceptionCopyConstructorThrowsCheck.cpp (renamed from clang-tools-extra/clang-tidy/cert/ThrownExceptionTypeCheck.cpp)12
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/ExceptionCopyConstructorThrowsCheck.h (renamed from clang-tools-extra/clang-tidy/cert/ThrownExceptionTypeCheck.h)16
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp43
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.h13
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.cpp (renamed from clang-tools-extra/clang-tidy/cert/FloatLoopCounter.cpp)11
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.h (renamed from clang-tools-extra/clang-tidy/cert/FloatLoopCounter.h)16
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/FoldInitTypeCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp9
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp25
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/IncDecInConditionsCheck.cpp1
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp24
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/IntegerDivisionCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/MacroParenthesesCheck.cpp1
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/MacroRepeatedSideEffectsCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/MisplacedPointerArithmeticInAllocCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp12
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/MoveForwardingReferenceCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.cpp5
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp5
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/MultipleStatementMacroCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp40
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp1
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerIterationOrderCheck.cpp5
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerIterationOrderCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp94
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/PosixReturnCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/PosixReturnCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/RandomGeneratorSeedCheck.cpp (renamed from clang-tools-extra/clang-tidy/cert/ProperlySeededRandomGeneratorCheck.cpp)22
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/RandomGeneratorSeedCheck.h (renamed from clang-tools-extra/clang-tidy/cert/ProperlySeededRandomGeneratorCheck.h)16
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/RawMemoryCallOnNonTrivialTypeCheck.cpp (renamed from clang-tools-extra/clang-tidy/cert/NonTrivialTypesLibcMemoryCallsCheck.cpp)22
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/RawMemoryCallOnNonTrivialTypeCheck.h (renamed from clang-tools-extra/clang-tidy/cert/NonTrivialTypesLibcMemoryCallsCheck.h)19
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp10
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp19
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h9
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/SignedCharMisuseCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.cpp26
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp7
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp30
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/StdNamespaceModificationCheck.cpp (renamed from clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.cpp)14
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/StdNamespaceModificationCheck.h (renamed from clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.h)16
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp8
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp22
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/SuspiciousMissingCommaCheck.cpp22
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp11
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp18
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.cpp8
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/SuspiciousStringviewDataUsageCheck.cpp1
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/TaggedUnionMemberCountCheck.cpp1
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/ThrowingStaticInitializationCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp32
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.h4
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.cpp7
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/UndelegatedConstructorCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/UnhandledExceptionAtNewCheck.cpp5
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/UnintendedCharOstreamOutputCheck.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp14
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp3
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp82
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.h7
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp40
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp45
-rw-r--r--clang-tools-extra/clang-tidy/cert/CMakeLists.txt8
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt2
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/InterfacesGlobalInitCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp17
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/NoMallocCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/NoSuspendWithLockCheck.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp12
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp11
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccessCheck.cpp (renamed from clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccess.cpp)18
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccessCheck.h (renamed from clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccess.h)16
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp52
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeReinterpretCastCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeStaticCastDowncastCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeStaticCastDowncastCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp9
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/SlicingCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp16
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h10
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp13
-rw-r--r--clang-tools-extra/clang-tidy/custom/QueryCheck.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp132
-rw-r--r--clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.h13
-rw-r--r--clang-tools-extra/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/fuchsia/OverloadedOperatorCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/fuchsia/TemporaryObjectsCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/fuchsia/VirtualInheritanceCheck.cpp7
-rw-r--r--clang-tools-extra/clang-tidy/fuchsia/VirtualInheritanceCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/google/AvoidNSObjectNewCheck.cpp10
-rw-r--r--clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp3
-rw-r--r--clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp9
-rw-r--r--clang-tools-extra/clang-tidy/google/CMakeLists.txt2
-rw-r--r--clang-tools-extra/clang-tidy/google/DefaultArgumentsCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp12
-rw-r--r--clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp16
-rw-r--r--clang-tools-extra/clang-tidy/google/FunctionNamingCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp87
-rw-r--r--clang-tools-extra/clang-tidy/google/TodoCommentCheck.h2
-rw-r--r--clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp12
-rw-r--r--clang-tools-extra/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/hicpp/NoAssemblerCheck.cpp9
-rw-r--r--clang-tools-extra/clang-tidy/hicpp/NoAssemblerCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/llvm/.clang-tidy5
-rw-r--r--clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.cpp8
-rw-r--r--clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp10
-rw-r--r--clang-tools-extra/clang-tidy/llvm/PreferIsaOrDynCastInConditionalsCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/llvm/PreferStaticOverAnonymousNamespaceCheck.cpp1
-rw-r--r--clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/llvm/UseNewMLIROpBuilderCheck.cpp77
-rw-r--r--clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp3
-rw-r--r--clang-tools-extra/clang-tidy/llvmlibc/NamespaceConstants.h5
-rw-r--r--clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp10
-rw-r--r--clang-tools-extra/clang-tidy/misc/CMakeLists.txt7
-rw-r--r--clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp12
-rw-r--r--clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp8
-rw-r--r--clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp18
-rw-r--r--clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.h9
-rw-r--r--clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp3
-rw-r--r--clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp12
-rw-r--r--clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp12
-rw-r--r--clang-tools-extra/clang-tidy/misc/MisleadingBidirectionalCheck.cpp (renamed from clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp)19
-rw-r--r--clang-tools-extra/clang-tidy/misc/MisleadingBidirectionalCheck.h (renamed from clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.h)4
-rw-r--r--clang-tools-extra/clang-tidy/misc/MisleadingIdentifierCheck.cpp (renamed from clang-tools-extra/clang-tidy/misc/MisleadingIdentifier.cpp)11
-rw-r--r--clang-tools-extra/clang-tidy/misc/MisleadingIdentifierCheck.h (renamed from clang-tools-extra/clang-tidy/misc/MisleadingIdentifier.h)6
-rw-r--r--clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/misc/NewDeleteOverloadsCheck.cpp14
-rw-r--r--clang-tools-extra/clang-tidy/misc/NewDeleteOverloadsCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp15
-rw-r--r--clang-tools-extra/clang-tidy/misc/NonCopyableObjectsCheck.cpp (renamed from clang-tools-extra/clang-tidy/misc/NonCopyableObjects.cpp)2
-rw-r--r--clang-tools-extra/clang-tidy/misc/NonCopyableObjectsCheck.h (renamed from clang-tools-extra/clang-tidy/misc/NonCopyableObjects.h)11
-rw-r--r--clang-tools-extra/clang-tidy/misc/PredictableRandCheck.cpp (renamed from clang-tools-extra/clang-tidy/cert/LimitedRandomnessCheck.cpp)10
-rw-r--r--clang-tools-extra/clang-tidy/misc/PredictableRandCheck.h (renamed from clang-tools-extra/clang-tidy/cert/LimitedRandomnessCheck.h)16
-rw-r--r--clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp95
-rw-r--r--clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp11
-rw-r--r--clang-tools-extra/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/misc/UnconventionalAssignOperatorCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/misc/UnusedAliasDeclsCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp14
-rw-r--r--clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp3
-rw-r--r--clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp18
-rw-r--r--clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp23
-rw-r--r--clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp16
-rw-r--r--clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.cpp (renamed from clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp)29
-rw-r--r--clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.h (renamed from clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h)16
-rw-r--r--clang-tools-extra/clang-tidy/modernize/CMakeLists.txt1
-rw-r--r--clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp18
-rw-r--r--clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp7
-rw-r--r--clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.h6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp70
-rw-r--r--clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp38
-rw-r--r--clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp36
-rw-r--r--clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp40
-rw-r--r--clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/MakeUniqueCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp1
-rw-r--r--clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp3
-rw-r--r--clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp21
-rw-r--r--clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp10
-rw-r--r--clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp24
-rw-r--r--clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp7
-rw-r--r--clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp98
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseAutoCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseBoolLiteralsCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseBoolLiteralsCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp35
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp10
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp15
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp43
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp10
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseNodiscardCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp27
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp32
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp1
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp5
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp13
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp5
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.h8
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp63
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseTransparentFunctorsCheck.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseTransparentFunctorsCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseUncaughtExceptionsCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseUncaughtExceptionsCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp7
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h7
-rw-r--r--clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.cpp74
-rw-r--r--clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/objc/AssertEqualsCheck.cpp (renamed from clang-tools-extra/clang-tidy/objc/AssertEquals.cpp)44
-rw-r--r--clang-tools-extra/clang-tidy/objc/AssertEqualsCheck.h (renamed from clang-tools-extra/clang-tidy/objc/AssertEquals.h)12
-rw-r--r--clang-tools-extra/clang-tidy/objc/CMakeLists.txt2
-rw-r--r--clang-tools-extra/clang-tidy/objc/ForbiddenSubclassingCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/objc/MissingHashCheck.cpp8
-rw-r--r--clang-tools-extra/clang-tidy/objc/NSDateFormatterCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/objc/NSInvocationArgumentLifetimeCheck.cpp12
-rw-r--r--clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp11
-rw-r--r--clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/openmp/UseDefaultNoneCheck.cpp5
-rw-r--r--clang-tools-extra/clang-tidy/performance/CMakeLists.txt2
-rw-r--r--clang-tools-extra/clang-tidy/performance/FasterStringFindCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/performance/ImplicitConversionInLoopCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/performance/ImplicitConversionInLoopCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp14
-rw-r--r--clang-tools-extra/clang-tidy/performance/InefficientStringConcatenationCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.cpp12
-rw-r--r--clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp19
-rw-r--r--clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/performance/MoveConstructorInitCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/performance/NoexceptFunctionBaseCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp1
-rw-r--r--clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/performance/TriviallyDestructibleCheck.cpp11
-rw-r--r--clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitializationCheck.cpp (renamed from clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp)28
-rw-r--r--clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitializationCheck.h (renamed from clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h)13
-rw-r--r--clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp5
-rw-r--r--clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h10
-rw-r--r--clang-tools-extra/clang-tidy/portability/SIMDIntrinsicsCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/portability/SIMDIntrinsicsCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/readability/AmbiguousSmartptrResetCallCheck.cpp9
-rw-r--r--clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDeclsCheck.cpp (renamed from clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp)13
-rw-r--r--clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDeclsCheck.h (renamed from clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.h)13
-rw-r--r--clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/readability/AvoidUnconditionalPreprocessorIfCheck.cpp3
-rw-r--r--clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp18
-rw-r--r--clang-tools-extra/clang-tidy/readability/CMakeLists.txt4
-rw-r--r--clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp12
-rw-r--r--clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp9
-rw-r--r--clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp11
-rw-r--r--clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStaticCheck.cpp (renamed from clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp)27
-rw-r--r--clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStaticCheck.h (renamed from clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.h)12
-rw-r--r--clang-tools-extra/clang-tidy/readability/DeleteNullPointerCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp48
-rw-r--r--clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.h15
-rw-r--r--clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp27
-rw-r--r--clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp11
-rw-r--r--clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/readability/IdentifierLengthCheck.cpp8
-rw-r--r--clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp99
-rw-r--r--clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp36
-rw-r--r--clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp16
-rw-r--r--clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/readability/IsolateDeclarationCheck.cpp16
-rw-r--r--clang-tools-extra/clang-tidy/readability/IsolateDeclarationCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp7
-rw-r--r--clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp10
-rw-r--r--clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/readability/MisplacedArrayIndexCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp22
-rw-r--r--clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/readability/OperatorsRepresentationCheck.cpp25
-rw-r--r--clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp38
-rw-r--r--clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp8
-rw-r--r--clang-tools-extra/clang-tidy/readability/RedundantAccessSpecifiersCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp7
-rw-r--r--clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp9
-rw-r--r--clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/readability/RedundantFunctionPtrDereferenceCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp7
-rw-r--r--clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/readability/RedundantPreprocessorCheck.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp8
-rw-r--r--clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp10
-rw-r--r--clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/readability/ReferenceToConstructedTemporaryCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp51
-rw-r--r--clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp61
-rw-r--r--clang-tools-extra/clang-tidy/readability/UniqueptrDeleteReleaseCheck.cpp1
-rw-r--r--clang-tools-extra/clang-tidy/readability/UniqueptrDeleteReleaseCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/readability/UseConcisePreprocessorDirectivesCheck.cpp5
-rw-r--r--clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp78
-rw-r--r--clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp49
-rw-r--r--clang-tools-extra/clang-tidy/tool/ClangTidyMain.h5
-rw-r--r--clang-tools-extra/clang-tidy/tool/check_alphabetical_order.py421
-rw-r--r--clang-tools-extra/clang-tidy/tool/check_alphabetical_order_test.py401
-rw-r--r--clang-tools-extra/clang-tidy/utils/ASTUtils.cpp2
-rw-r--r--clang-tools-extra/clang-tidy/utils/ASTUtils.h6
-rw-r--r--clang-tools-extra/clang-tidy/utils/Aliasing.cpp12
-rw-r--r--clang-tools-extra/clang-tidy/utils/BracesAroundStatement.cpp14
-rw-r--r--clang-tools-extra/clang-tidy/utils/BracesAroundStatement.h9
-rw-r--r--clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp7
-rw-r--r--clang-tools-extra/clang-tidy/utils/DesignatedInitializers.h5
-rw-r--r--clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp73
-rw-r--r--clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h6
-rw-r--r--clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp8
-rw-r--r--clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.h6
-rw-r--r--clang-tools-extra/clang-tidy/utils/ExprSequence.cpp16
-rw-r--r--clang-tools-extra/clang-tidy/utils/ExprSequence.h6
-rw-r--r--clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp10
-rw-r--r--clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h6
-rw-r--r--clang-tools-extra/clang-tidy/utils/FixItHintUtils.cpp8
-rw-r--r--clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp18
-rw-r--r--clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp41
-rw-r--r--clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp4
-rw-r--r--clang-tools-extra/clang-tidy/utils/IncludeInserter.h6
-rw-r--r--clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp24
-rw-r--r--clang-tools-extra/clang-tidy/utils/IncludeSorter.h6
-rw-r--r--clang-tools-extra/clang-tidy/utils/LexerUtils.cpp12
-rw-r--r--clang-tools-extra/clang-tidy/utils/LexerUtils.h10
-rw-r--r--clang-tools-extra/clang-tidy/utils/Matchers.cpp1
-rw-r--r--clang-tools-extra/clang-tidy/utils/Matchers.h2
-rw-r--r--clang-tools-extra/clang-tidy/utils/NamespaceAliaser.cpp6
-rw-r--r--clang-tools-extra/clang-tidy/utils/NamespaceAliaser.h6
-rw-r--r--clang-tools-extra/clang-tidy/utils/OptionsUtils.h6
-rw-r--r--clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp42
-rw-r--r--clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h6
-rw-r--r--clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp7
-rw-r--r--clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h11
-rw-r--r--clang-tools-extra/clang-tidy/utils/TypeTraits.cpp22
-rw-r--r--clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp20
-rw-r--r--clang-tools-extra/clang-tidy/utils/UsingInserter.cpp14
-rw-r--r--clang-tools-extra/clang-tidy/utils/UsingInserter.h6
-rw-r--r--clang-tools-extra/clangd/CMakeLists.txt1
-rw-r--r--clang-tools-extra/clangd/ClangdLSPServer.cpp3
-rw-r--r--clang-tools-extra/clangd/ClangdServer.h5
-rw-r--r--clang-tools-extra/clangd/CompileCommands.cpp30
-rw-r--r--clang-tools-extra/clangd/Compiler.cpp1
-rw-r--r--clang-tools-extra/clangd/FileDistance.cpp1
-rw-r--r--clang-tools-extra/clangd/FuzzyMatch.cpp3
-rw-r--r--clang-tools-extra/clangd/GlobalCompilationDatabase.cpp41
-rw-r--r--clang-tools-extra/clangd/GlobalCompilationDatabase.h26
-rw-r--r--clang-tools-extra/clangd/ScanningProjectModules.cpp12
-rw-r--r--clang-tools-extra/clangd/Selection.cpp12
-rw-r--r--clang-tools-extra/clangd/SemanticSelection.cpp160
-rw-r--r--clang-tools-extra/clangd/SemanticSelection.h4
-rw-r--r--clang-tools-extra/clangd/SourceCode.cpp20
-rw-r--r--clang-tools-extra/clangd/SourceCode.h5
-rw-r--r--clang-tools-extra/clangd/index/SymbolLocation.cpp3
-rw-r--r--clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp294
-rw-r--r--clang-tools-extra/clangd/refactor/tweaks/OverridePureVirtuals.cpp5
-rw-r--r--clang-tools-extra/clangd/support/DirectiveTree.cpp4
-rw-r--r--clang-tools-extra/clangd/test/CMakeLists.txt4
-rw-r--r--clang-tools-extra/clangd/test/include-cleaner-batch-fix.test4
-rw-r--r--clang-tools-extra/clangd/test/index-tools.test9
-rw-r--r--clang-tools-extra/clangd/test/lit.cfg.py19
-rw-r--r--clang-tools-extra/clangd/test/lit.site.cfg.py.in1
-rw-r--r--clang-tools-extra/clangd/test/system-include-extractor.test3
-rw-r--r--clang-tools-extra/clangd/tool/Check.cpp8
-rw-r--r--clang-tools-extra/clangd/tool/ClangdMain.cpp12
-rw-r--r--clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp14
-rw-r--r--clang-tools-extra/clangd/unittests/SelectionTests.cpp13
-rw-r--r--clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp92
-rw-r--r--clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp194
-rw-r--r--clang-tools-extra/clangd/unittests/tweaks/OverridePureVirtualsTests.cpp39
-rw-r--r--clang-tools-extra/docs/Maintainers.rst1
-rw-r--r--clang-tools-extra/docs/ReleaseNotes.rst160
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/abseil/duration-addition.rst8
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/abseil/duration-division.rst6
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/abseil/faster-strsplit-delimiter.rst6
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/abseil/string-find-str-contains.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/abseil/upgrade-duration-conversions.rst10
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/android/cloexec-inotify-init1.rst7
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/android/cloexec-pipe.rst7
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/android/cloexec-pipe2.rst5
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/android/comparison-in-temp-failure-retry.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/boost/use-ranges.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/boost/use-to-string.rst6
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/assignment-in-if-condition.rst10
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/bitwise-pointer-cast.rst6
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/capturing-this-in-member-variable.rst12
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/casting-through-void.rst17
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/compare-pointer-to-member-virtual-function.rst20
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/copy-constructor-mutates-argument.rst11
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/crtp-constructor-accessibility.rst6
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/dangling-handle.rst5
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/default-operator-new-on-overaligned-type.rst20
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/derived-method-shadowing-base-method.rst11
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/dynamic-static-initializers.rst16
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/easily-swappable-parameters.rst6
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst8
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-copy-constructor-throws.rst31
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst31
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/float-loop-counter.rst13
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/fold-init-type.rst11
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/forward-declaration-namespace.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/forwarding-reference-overload.rst16
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/inc-dec-in-conditions.rst25
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/incorrect-enable-shared-from-this.rst10
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/infinite-loop.rst8
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/invalid-enum-default-initialization.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/misplaced-operator-in-strlen-in-alloc.rst16
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/multiple-new-in-one-expression.rst16
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/narrowing-conversions.rst27
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/no-escape.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/non-zero-enum-to-bool-conversion.rst20
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/not-null-terminated-result.rst22
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/posix-return.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/random-generator-seed.rst44
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/raw-memory-call-on-non-trivial-type.rst35
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/redundant-branch-condition.rst14
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/return-const-ref-from-parameter.rst18
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/signal-handler.rst16
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/signed-char-misuse.rst34
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-container.rst10
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst6
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/std-namespace-modification.rst68
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/string-constructor.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/string-literal-with-embedded-nul.rst6
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-enum-usage.rst22
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-memory-comparison.rst6
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-realloc-usage.rst11
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-semicolon.rst10
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-string-compare.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/swapped-arguments.rst8
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/tagged-union-member-count.rst46
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/throw-keyword-missing.rst7
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/throwing-static-initialization.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/too-small-loop-variable.rst12
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/unchecked-optional-access.rst34
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/unchecked-string-to-number-conversion.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/unhandled-self-assignment.rst13
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/unintended-char-ostream-output.rst29
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/unsafe-functions.rst68
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/use-after-move.rst48
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/bugprone/virtual-near-miss.rst5
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/con36-c.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/con54-cpp.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/ctr56-cpp.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/dcl16-c.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/dcl50-cpp.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/dcl58-cpp.rst55
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/dcl59-cpp.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/env33-c.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/err09-cpp.rst10
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/err33-c.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/err34-c.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/err52-cpp.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/err58-cpp.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/err60-cpp.rst10
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/err61-cpp.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/exp42-c.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/fio38-c.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/flp30-c.rst5
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/flp37-c.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/mem57-cpp.rst11
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/msc30-c.rst8
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/msc32-c.rst9
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/msc50-cpp.rst14
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/msc51-cpp.rst43
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/oop54-cpp.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/oop57-cpp.rst36
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/oop58-cpp.rst14
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/pos44-c.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cert/pos47-c.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/security.SetgidSetuidOrder.rst13
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/security.insecureAPI.decodeValueOfObjCType.rst8
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/unix.StdCLibraryFunctions.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-c-arrays.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-capturing-lambda-coroutines.rst8
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-do-while.rst9
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-magic-numbers.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-non-const-global-variables.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-reference-coroutine-parameters.rst7
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/c-copy-assignment-signature.rst6
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/explicit-virtual-functions.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/init-variables.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/interfaces-global-init.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/macro-to-enum.rst5
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/narrowing-conversions.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/no-malloc.rst10
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/no-suspend-with-lock.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/noexcept-move-operations.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/non-private-member-variables-in-classes.rst7
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/owning-memory.rst38
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-array-to-pointer-decay.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-avoid-unchecked-container-access.rst20
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-constant-array-index.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-pointer-arithmetic.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-const-cast.rst10
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-cstyle-cast.rst14
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-member-init.rst8
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-reinterpret-cast.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-static-cast-downcast.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-union-access.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-vararg.rst6
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/special-member-functions.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-default-member-init.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-enum-class.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/virtual-class-destructor.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/fuchsia/statically-constructed-objects.rst6
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/google/explicit-constructor.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/google/objc-avoid-throwing-exception.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/google/objc-global-variable-declaration.rst10
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/google/readability-avoid-underscore-in-googletest-name.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/google/readability-braces-around-statements.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/google/readability-casting.rst8
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/google/readability-todo.rst11
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/google/upgrade-googletest-case.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/hicpp/braces-around-statements.rst6
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/hicpp/explicit-conversions.rst26
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/hicpp/function-size.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/hicpp/invalid-access-moved.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/hicpp/move-const-arg.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/hicpp/multiway-paths-covered.rst14
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/hicpp/named-parameter.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/hicpp/no-array-decay.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/hicpp/uppercase-literal-suffix.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/linuxkernel/must-check-errs.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/list.rst31
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/llvm/prefer-static-over-anonymous-namespace.rst6
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/llvm/twine-local.rst18
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/llvm/use-ranges.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst25
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/misc/coroutine-hostile-raii.rst46
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/misc/header-include-cycle.rst16
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/misc/misleading-bidirectional.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/misc/misleading-identifier.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/misc/no-recursion.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/misc/non-copyable-objects.rst5
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/misc/override-with-different-visibility.rst13
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/misc/predictable-rand.rst20
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/misc/throw-by-value-catch-by-reference.rst8
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/misc/unused-parameters.rst6
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/misc/unused-using-decls.rst7
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst12
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/misc/use-internal-linkage.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-style-cast.rst36
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-setjmp-longjmp.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-variadic-functions.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/modernize/concat-nested-namespaces.rst6
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst9
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/modernize/min-max-use-initializer-list.rst8
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/modernize/replace-disallow-copy-and-assign-macro.rst6
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/modernize/replace-random-shuffle.rst21
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.rst5
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/modernize/unary-static-assert.rst5
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/modernize/use-auto.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/modernize/use-constraints.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.rst10
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/modernize/use-emplace.rst23
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst6
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/modernize/use-scoped-lock.rst6
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/modernize/use-starts-ends-with.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst14
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst40
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/modernize/use-trailing-return-type.rst12
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/mpi/buffer-deref.rst7
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/mpi/type-mismatch.rst9
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/objc/forbidden-subclassing.rst8
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/objc/nsdate-formatter.rst116
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/objc/property-declaration.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/performance/no-int-to-ptr.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/performance/noexcept-swap.rst14
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-initialization.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/portability/simd-intrinsics.rst16
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/portability/std-allocator-const.rst8
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/portability/template-virtual-member-function.rst26
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/ambiguous-smartptr-reset-call.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/container-data-pointer.rst8
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst10
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/convert-member-functions-to-static.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/delete-null-pointer.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/duplicate-include.rst9
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/else-after-return.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/function-cognitive-complexity.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/identifier-length.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst306
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/implicit-bool-conversion.rst6
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/magic-numbers.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/make-member-function-const.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/math-missing-parentheses.rst17
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst5
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/operators-representation.rst7
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/redundant-casting.rst6
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/redundant-control-flow.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/redundant-inline-specifier.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/redundant-parentheses.rst2
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/redundant-string-cstr.rst17
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/reference-to-constructed-temporary.rst8
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/simplify-boolean-expr.rst5
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/string-compare.rst10
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/suspicious-call-argument.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/uppercase-literal-suffix.rst4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability/use-anyofallof.rst6
-rw-r--r--clang-tools-extra/docs/index.rst1
-rw-r--r--clang-tools-extra/include-cleaner/test/lit.cfg.py15
-rw-r--r--clang-tools-extra/modularize/CMakeLists.txt1
-rw-r--r--clang-tools-extra/modularize/CoverageChecker.cpp6
-rw-r--r--clang-tools-extra/modularize/Modularize.cpp4
-rw-r--r--clang-tools-extra/modularize/ModularizeUtilities.cpp6
-rw-r--r--clang-tools-extra/pp-trace/CMakeLists.txt1
-rw-r--r--clang-tools-extra/pp-trace/PPTrace.cpp2
-rw-r--r--clang-tools-extra/test/clang-doc/assets.cpp16
-rw-r--r--clang-tools-extra/test/clang-doc/basic-project.mustache.test737
-rw-r--r--clang-tools-extra/test/clang-doc/basic-project.test267
-rw-r--r--clang-tools-extra/test/clang-doc/comments-in-macros.cpp17
-rw-r--r--clang-tools-extra/test/clang-doc/conversion_function.cpp7
-rw-r--r--clang-tools-extra/test/clang-doc/enum.cpp187
-rw-r--r--clang-tools-extra/test/clang-doc/json/class-requires.cpp2
-rw-r--r--clang-tools-extra/test/clang-doc/json/class-specialization.cpp4
-rw-r--r--clang-tools-extra/test/clang-doc/json/class-template.cpp2
-rw-r--r--clang-tools-extra/test/clang-doc/json/class.cpp7
-rw-r--r--clang-tools-extra/test/clang-doc/json/compound-constraints.cpp2
-rw-r--r--clang-tools-extra/test/clang-doc/json/concept.cpp2
-rw-r--r--clang-tools-extra/test/clang-doc/json/function-requires.cpp2
-rw-r--r--clang-tools-extra/test/clang-doc/json/function-specifiers.cpp2
-rw-r--r--clang-tools-extra/test/clang-doc/json/method-template.cpp2
-rw-r--r--clang-tools-extra/test/clang-doc/json/multiple-namespaces.cpp4
-rw-r--r--clang-tools-extra/test/clang-doc/json/namespace.cpp2
-rw-r--r--clang-tools-extra/test/clang-doc/json/nested-namespace.cpp4
-rw-r--r--clang-tools-extra/test/clang-doc/long-name.cpp6
-rw-r--r--clang-tools-extra/test/clang-doc/mustache-index.cpp50
-rw-r--r--clang-tools-extra/test/clang-doc/mustache-separate-namespace.cpp24
-rw-r--r--clang-tools-extra/test/clang-doc/namespace.cpp235
-rw-r--r--clang-tools-extra/test/clang-doc/test-path-abs.cpp7
-rw-r--r--clang-tools-extra/test/clang-tidy/.clang-tidy1
-rwxr-xr-xclang-tools-extra/test/clang-tidy/check_clang_tidy.py2
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-header-simulation.h2
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/bugprone/copy-constructor-mutates-argument.cpp (renamed from clang-tools-extra/test/clang-tidy/checkers/cert/oop58-cpp.cpp)2
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/bugprone/default-operator-new-on-overaligned-type-cpp17.cpp12
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/bugprone/default-operator-new-on-overaligned-type.cpp (renamed from clang-tools-extra/test/clang-tidy/checkers/cert/mem57-cpp.cpp)6
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-copy-constructor-throws.cpp (renamed from clang-tools-extra/test/clang-tidy/checkers/cert/throw-exception-type.cpp)4
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-options.cpp47
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp53
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/bugprone/float-loop-counter.c (renamed from clang-tools-extra/test/clang-tidy/checkers/cert/flp30-c.c)10
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/bugprone/random-generator-seed.c (renamed from clang-tools-extra/test/clang-tidy/checkers/cert/msc32-c.c)9
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/bugprone/random-generator-seed.cpp (renamed from clang-tools-extra/test/clang-tidy/checkers/cert/msc51-cpp.cpp)106
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/bugprone/raw-memory-call-on-non-trivial-type.cpp (renamed from clang-tools-extra/test/clang-tidy/checkers/cert/oop57-cpp.cpp)8
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/bugprone/std-namespace-modification.cpp (renamed from clang-tools-extra/test/clang-tidy/checkers/cert/dcl58-cpp.cpp)4
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access-ignore-value.cpp25
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions-custom.c6
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp62
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/cert/mem57-cpp-cpp17.cpp12
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.ignorearrays.cpp36
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/fuchsia/multiple-inheritance.cpp15
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.c24
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/google/readability-todo-hyphen.cpp40
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/google/readability-todo-parentheses.cpp (renamed from clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp)16
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/llvm/use-new-mlir-op-builder.cpp53
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp15
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp19
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/misc/predictable-rand.c (renamed from clang-tools-extra/test/clang-tidy/checkers/cert/limited-randomness.c)4
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/misc/predictable-rand.cpp (renamed from clang-tools-extra/test/clang-tidy/checkers/cert/limited-randomness.cpp)8
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-style-cast.c24
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-style-cast.cpp (renamed from clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp)18
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp12
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/duplicate-include/pack_begin.h1
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/duplicate-include/pack_end.h1
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp23
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability/duplicate-include-ignored-files.cpp24
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability/inconsistent-declaration-parameter-name.cpp23
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability/redundant-casting.cpp10
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability/redundant-control-flow.cpp50
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability/redundant-typename.cpp24
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability/use-concise-preprocessor-directives.cpp8
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability/use-std-min-max.cpp96
-rw-r--r--clang-tools-extra/test/clang-tidy/infrastructure/Inputs/param/parameters.txt2
-rw-r--r--clang-tools-extra/test/clang-tidy/infrastructure/alphabetical-order.test5
-rw-r--r--clang-tools-extra/test/clang-tidy/infrastructure/empty-database.cpp2
-rw-r--r--clang-tools-extra/test/clang-tidy/infrastructure/invalid-database.cpp2
-rw-r--r--clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-LIFO.cpp6
-rw-r--r--clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-multiple-end-single.cpp6
-rw-r--r--clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-single-end-multiple.cpp6
-rw-r--r--clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-check-names.cpp4
-rw-r--r--clang-tools-extra/test/lit.cfg.py1
-rw-r--r--clang-tools-extra/test/pp-trace/pp-trace-include.cpp1
-rw-r--r--clang-tools-extra/test/pp-trace/pp-trace-macro.cpp1
-rw-r--r--clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp86
-rw-r--r--clang-tools-extra/unittests/clang-doc/CMakeLists.txt1
-rw-r--r--clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp15
-rw-r--r--clang-tools-extra/unittests/clang-doc/ClangDocTest.h17
-rw-r--r--clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp506
-rw-r--r--clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp55
-rw-r--r--clang-tools-extra/unittests/clang-doc/JSONGeneratorTest.cpp14
-rw-r--r--clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp22
-rw-r--r--clang-tools-extra/unittests/clang-doc/MergeTest.cpp10
-rw-r--r--clang-tools-extra/unittests/clang-doc/SerializeTest.cpp124
-rw-r--r--clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp30
906 files changed, 8933 insertions, 7966 deletions
diff --git a/clang-tools-extra/Maintainers.txt b/clang-tools-extra/Maintainers.rst
index 43dfd48..094f115 100644
--- a/clang-tools-extra/Maintainers.txt
+++ b/clang-tools-extra/Maintainers.rst
@@ -2,9 +2,13 @@
Clang Tools Extra Maintainers
=============================
-This file is a list of the maintainers
-(https://llvm.org/docs/DeveloperPolicy.html#maintainers) for clang-tools-extra.
+This file is a list of the
+`maintainers <https://llvm.org/docs/DeveloperPolicy.html#maintainers>`_
+for `Extra Clang Tools <https://clang.llvm.org/extra/index.html>`_ project.
+.. contents::
+ :depth: 2
+ :local:
Active Maintainers
==================
@@ -29,6 +33,9 @@ clang-tidy
| Piotr Zegar
| me@piotrzegar.pl (email), PiotrZSL (GitHub), PiotrZSL (Discourse), PiotrZSL (Discord)
+| Victor Baranov
+| bar.victor.2002@gmail.com (email), vbvictor (GitHub), vbvictor (Discourse), vbvictor (Discord)
+
clang-query
-----------
diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp
index 4efbbd3..817981a 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "BitcodeReader.h"
-#include "llvm/ADT/IndexedMap.h"
#include "llvm/Support/Error.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/TimeProfiler.h"
#include "llvm/Support/raw_ostream.h"
#include <optional>
@@ -16,6 +16,8 @@
namespace clang {
namespace doc {
+static llvm::ExitOnError ExitOnErr("clang-doc error: ");
+
using Record = llvm::SmallVector<uint64_t, 1024>;
// This implements decode for SmallString.
@@ -717,8 +719,8 @@ llvm::Error addReference(FriendInfo *Friend, Reference &&R, FieldId F) {
template <typename T, typename ChildInfoType>
static void addChild(T I, ChildInfoType &&R) {
- llvm::errs() << "invalid child type for info";
- exit(1);
+ ExitOnErr(llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "invalid child type for info"));
}
// Namespace children:
@@ -767,8 +769,9 @@ template <> void addChild(BaseRecordInfo *I, FunctionInfo &&R) {
// parameters) or TemplateSpecializationInfo (for the specialization's
// parameters).
template <typename T> static void addTemplateParam(T I, TemplateParamInfo &&P) {
- llvm::errs() << "invalid container for template parameter";
- exit(1);
+ ExitOnErr(
+ llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "invalid container for template parameter"));
}
template <> void addTemplateParam(TemplateInfo *I, TemplateParamInfo &&P) {
I->Params.emplace_back(std::move(P));
@@ -780,8 +783,8 @@ void addTemplateParam(TemplateSpecializationInfo *I, TemplateParamInfo &&P) {
// Template info. These apply to either records or functions.
template <typename T> static void addTemplate(T I, TemplateInfo &&P) {
- llvm::errs() << "invalid container for template info";
- exit(1);
+ ExitOnErr(llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "invalid container for template info"));
}
template <> void addTemplate(RecordInfo *I, TemplateInfo &&P) {
I->Template.emplace(std::move(P));
@@ -799,8 +802,9 @@ template <> void addTemplate(FriendInfo *I, TemplateInfo &&P) {
// Template specializations go only into template records.
template <typename T>
static void addTemplateSpecialization(T I, TemplateSpecializationInfo &&TSI) {
- llvm::errs() << "invalid container for template specialization info";
- exit(1);
+ ExitOnErr(llvm::createStringError(
+ llvm::inconvertibleErrorCode(),
+ "invalid container for template specialization info"));
}
template <>
void addTemplateSpecialization(TemplateInfo *I,
@@ -809,8 +813,8 @@ void addTemplateSpecialization(TemplateInfo *I,
}
template <typename T> static void addConstraint(T I, ConstraintInfo &&C) {
- llvm::errs() << "invalid container for constraint info";
- exit(1);
+ ExitOnErr(llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "invalid container for constraint info"));
}
template <> void addConstraint(TemplateInfo *I, ConstraintInfo &&C) {
I->Constraints.emplace_back(std::move(C));
@@ -847,9 +851,11 @@ llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, T I) {
while (true) {
unsigned BlockOrCode = 0;
- Cursor Res = skipUntilRecordOrBlock(BlockOrCode);
+ llvm::Expected<Cursor> C = skipUntilRecordOrBlock(BlockOrCode);
+ if (!C)
+ return C.takeError();
- switch (Res) {
+ switch (*C) {
case Cursor::BadBlock:
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"bad block found");
@@ -985,45 +991,39 @@ llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) {
}
}
-ClangDocBitcodeReader::Cursor
+llvm::Expected<ClangDocBitcodeReader::Cursor>
ClangDocBitcodeReader::skipUntilRecordOrBlock(unsigned &BlockOrRecordID) {
llvm::TimeTraceScope("Reducing infos", "skipUntilRecordOrBlock");
BlockOrRecordID = 0;
while (!Stream.AtEndOfStream()) {
- Expected<unsigned> MaybeCode = Stream.ReadCode();
- if (!MaybeCode) {
- // FIXME this drops the error on the floor.
- consumeError(MaybeCode.takeError());
- return Cursor::BadBlock;
- }
+ Expected<unsigned> Code = Stream.ReadCode();
+ if (!Code)
+ return Code.takeError();
- unsigned Code = MaybeCode.get();
- if (Code >= static_cast<unsigned>(llvm::bitc::FIRST_APPLICATION_ABBREV)) {
- BlockOrRecordID = Code;
+ if (*Code >= static_cast<unsigned>(llvm::bitc::FIRST_APPLICATION_ABBREV)) {
+ BlockOrRecordID = *Code;
return Cursor::Record;
}
- switch (static_cast<llvm::bitc::FixedAbbrevIDs>(Code)) {
+ switch (static_cast<llvm::bitc::FixedAbbrevIDs>(*Code)) {
case llvm::bitc::ENTER_SUBBLOCK:
if (Expected<unsigned> MaybeID = Stream.ReadSubBlockID())
BlockOrRecordID = MaybeID.get();
- else {
- // FIXME this drops the error on the floor.
- consumeError(MaybeID.takeError());
- }
+ else
+ return MaybeID.takeError();
return Cursor::BlockBegin;
case llvm::bitc::END_BLOCK:
if (Stream.ReadBlockEnd())
- return Cursor::BadBlock;
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "error at end of block");
return Cursor::BlockEnd;
case llvm::bitc::DEFINE_ABBREV:
- if (llvm::Error Err = Stream.ReadAbbrevRecord()) {
- // FIXME this drops the error on the floor.
- consumeError(std::move(Err));
- }
+ if (llvm::Error Err = Stream.ReadAbbrevRecord())
+ return std::move(Err);
continue;
case llvm::bitc::UNABBREV_RECORD:
- return Cursor::BadBlock;
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "found unabbreviated record");
case llvm::bitc::FIRST_APPLICATION_ABBREV:
llvm_unreachable("Unexpected abbrev id.");
}
@@ -1149,10 +1149,8 @@ ClangDocBitcodeReader::readBitcode() {
return std::move(Err);
continue;
default:
- if (llvm::Error Err = Stream.SkipBlock()) {
- // FIXME this drops the error on the floor.
- consumeError(std::move(Err));
- }
+ if (llvm::Error Err = Stream.SkipBlock())
+ return std::move(Err);
continue;
}
}
diff --git a/clang-tools-extra/clang-doc/BitcodeReader.h b/clang-tools-extra/clang-doc/BitcodeReader.h
index 4947721..8c1f9d6 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.h
+++ b/clang-tools-extra/clang-doc/BitcodeReader.h
@@ -17,8 +17,6 @@
#include "BitcodeWriter.h"
#include "Representation.h"
-#include "clang/AST/AST.h"
-#include "llvm/ADT/SmallVector.h"
#include "llvm/Bitstream/BitstreamReader.h"
#include "llvm/Support/Error.h"
#include <optional>
@@ -29,7 +27,8 @@ namespace doc {
// Class to read bitstream into an InfoSet collection
class ClangDocBitcodeReader {
public:
- ClangDocBitcodeReader(llvm::BitstreamCursor &Stream) : Stream(Stream) {}
+ ClangDocBitcodeReader(llvm::BitstreamCursor &Stream, DiagnosticsEngine &Diags)
+ : Stream(Stream), Diags(Diags) {}
// Main entry point, calls readBlock to read each block in the given stream.
llvm::Expected<std::vector<std::unique_ptr<Info>>> readBitcode();
@@ -59,7 +58,7 @@ private:
// Helper function to step through blocks to find and dispatch the next record
// or block to be read.
- Cursor skipUntilRecordOrBlock(unsigned &BlockOrRecordID);
+ llvm::Expected<Cursor> skipUntilRecordOrBlock(unsigned &BlockOrRecordID);
// Helper function to set up the appropriate type of Info.
llvm::Expected<std::unique_ptr<Info>> readBlockToInfo(unsigned ID);
@@ -74,6 +73,7 @@ private:
llvm::BitstreamCursor &Stream;
std::optional<llvm::BitstreamBlockInfo> BlockInfo;
FieldId CurrentReferenceField;
+ DiagnosticsEngine &Diags;
};
} // namespace doc
diff --git a/clang-tools-extra/clang-doc/BitcodeWriter.cpp b/clang-tools-extra/clang-doc/BitcodeWriter.cpp
index e23511b..650501d 100644
--- a/clang-tools-extra/clang-doc/BitcodeWriter.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeWriter.cpp
@@ -303,8 +303,6 @@ static const std::vector<std::pair<BlockId, std::vector<RecordId>>>
// AbbreviationMap
-constexpr unsigned char BitCodeConstants::Signature[];
-
void ClangDocBitcodeWriter::AbbreviationMap::add(RecordId RID,
unsigned AbbrevID) {
assert(RecordIdNameMap[RID] && "Unknown RecordId.");
@@ -771,7 +769,9 @@ bool ClangDocBitcodeWriter::dispatchInfoForWrite(Info *I) {
emitBlock(*static_cast<FriendInfo *>(I));
break;
case InfoType::IT_default:
- llvm::errs() << "Unexpected info, unable to write.\n";
+ unsigned ID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
+ "Unexpected info, unable to write.");
+ Diags.Report(ID);
return true;
}
return false;
diff --git a/clang-tools-extra/clang-doc/BitcodeWriter.h b/clang-tools-extra/clang-doc/BitcodeWriter.h
index 688f886..6d1b9e9 100644
--- a/clang-tools-extra/clang-doc/BitcodeWriter.h
+++ b/clang-tools-extra/clang-doc/BitcodeWriter.h
@@ -16,12 +16,9 @@
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_BITCODEWRITER_H
#include "Representation.h"
-#include "clang/AST/AST.h"
+#include "clang/Basic/Diagnostic.h"
#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringRef.h"
#include "llvm/Bitstream/BitstreamWriter.h"
-#include <initializer_list>
#include <vector>
namespace clang {
@@ -179,7 +176,8 @@ enum class FieldId {
class ClangDocBitcodeWriter {
public:
- ClangDocBitcodeWriter(llvm::BitstreamWriter &Stream) : Stream(Stream) {
+ ClangDocBitcodeWriter(llvm::BitstreamWriter &Stream, DiagnosticsEngine &Diags)
+ : Stream(Stream), Diags(Diags) {
emitHeader();
emitBlockInfoBlock();
emitVersionBlock();
@@ -264,6 +262,7 @@ private:
SmallVector<uint32_t, BitCodeConstants::RecordSize> Record;
llvm::BitstreamWriter &Stream;
AbbreviationMap Abbrevs;
+ DiagnosticsEngine &Diags;
};
} // namespace doc
diff --git a/clang-tools-extra/clang-doc/CMakeLists.txt b/clang-tools-extra/clang-doc/CMakeLists.txt
index 5989e5f..7a375d7 100644
--- a/clang-tools-extra/clang-doc/CMakeLists.txt
+++ b/clang-tools-extra/clang-doc/CMakeLists.txt
@@ -16,7 +16,6 @@ add_clang_library(clangDoc STATIC
Representation.cpp
Serialize.cpp
YAMLGenerator.cpp
- HTMLMustacheGenerator.cpp
JSONGenerator.cpp
DEPENDS
diff --git a/clang-tools-extra/clang-doc/ClangDoc.cpp b/clang-tools-extra/clang-doc/ClangDoc.cpp
index da4165a..ec802d6 100644
--- a/clang-tools-extra/clang-doc/ClangDoc.cpp
+++ b/clang-tools-extra/clang-doc/ClangDoc.cpp
@@ -15,13 +15,9 @@
#include "ClangDoc.h"
#include "Mapper.h"
#include "Representation.h"
-#include "clang/AST/AST.h"
#include "clang/AST/ASTConsumer.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Frontend/ASTConsumers.h"
#include "clang/Frontend/CompilerInstance.h"
-#include "clang/Frontend/FrontendActions.h"
namespace clang {
namespace doc {
diff --git a/clang-tools-extra/clang-doc/ClangDoc.h b/clang-tools-extra/clang-doc/ClangDoc.h
index 1f0c43d..860b670 100644
--- a/clang-tools-extra/clang-doc/ClangDoc.h
+++ b/clang-tools-extra/clang-doc/ClangDoc.h
@@ -17,8 +17,6 @@
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_CLANGDOC_H
#include "Representation.h"
-#include "clang/Tooling/Execution.h"
-#include "clang/Tooling/StandaloneExecution.h"
#include "clang/Tooling/Tooling.h"
namespace clang {
diff --git a/clang-tools-extra/clang-doc/Generators.cpp b/clang-tools-extra/clang-doc/Generators.cpp
index a5f6f1c..d6c1cc9 100644
--- a/clang-tools-extra/clang-doc/Generators.cpp
+++ b/clang-tools-extra/clang-doc/Generators.cpp
@@ -7,9 +7,15 @@
//===----------------------------------------------------------------------===//
#include "Generators.h"
+#include "support/File.h"
+#include "llvm/Support/TimeProfiler.h"
LLVM_INSTANTIATE_REGISTRY(clang::doc::GeneratorRegistry)
+using namespace llvm;
+using namespace llvm::json;
+using namespace llvm::mustache;
+
namespace clang {
namespace doc {
@@ -42,6 +48,143 @@ std::string getTagType(TagTypeKind AS) {
llvm_unreachable("Unknown TagTypeKind");
}
+Error createFileOpenError(StringRef FileName, std::error_code EC) {
+ return createFileError("cannot open file " + FileName, EC);
+}
+
+Error MustacheGenerator::setupTemplate(
+ std::unique_ptr<MustacheTemplateFile> &Template, StringRef TemplatePath,
+ std::vector<std::pair<StringRef, StringRef>> Partials) {
+ auto T = MustacheTemplateFile::createMustacheFile(TemplatePath);
+ if (Error Err = T.takeError())
+ return Err;
+ Template = std::move(T.get());
+ for (const auto &[Name, FileName] : Partials)
+ if (auto Err = Template->registerPartialFile(Name, FileName))
+ return Err;
+ return Error::success();
+}
+
+Error MustacheGenerator::generateDocumentation(
+ StringRef RootDir, StringMap<std::unique_ptr<doc::Info>> Infos,
+ const clang::doc::ClangDocContext &CDCtx, std::string DirName) {
+ {
+ llvm::TimeTraceScope TS("Setup Templates");
+ if (auto Err = setupTemplateFiles(CDCtx))
+ return Err;
+ }
+
+ {
+ llvm::TimeTraceScope TS("Generate JSON for Mustache");
+ if (auto JSONGenerator = findGeneratorByName("json")) {
+ if (Error Err = JSONGenerator.get()->generateDocumentation(
+ RootDir, std::move(Infos), CDCtx))
+ return Err;
+ } else
+ return JSONGenerator.takeError();
+ }
+
+ SmallString<128> JSONDirPath(RootDir);
+ SmallString<128> DocsDirPath(RootDir);
+ {
+ TimeTraceScope TS("Create Output Directories");
+ sys::path::append(JSONDirPath, "json");
+ if (auto EC = sys::fs::create_directories(JSONDirPath))
+ return createFileError(JSONDirPath, EC);
+ sys::path::append(DocsDirPath, DirName);
+ if (auto EC = sys::fs::create_directories(DocsDirPath))
+ return createFileError(DocsDirPath, EC);
+ }
+
+ {
+ llvm::TimeTraceScope TS("Iterate JSON files");
+ std::error_code EC;
+ sys::fs::recursive_directory_iterator JSONIter(JSONDirPath, EC);
+ std::vector<json::Value> JSONFiles;
+ JSONFiles.reserve(Infos.size());
+ if (EC)
+ return createStringError("Failed to create directory iterator.");
+
+ while (JSONIter != sys::fs::recursive_directory_iterator()) {
+ // create the same directory structure in the docs format dir
+ if (JSONIter->type() == sys::fs::file_type::directory_file) {
+ SmallString<128> DocsClonedPath(JSONIter->path());
+ sys::path::replace_path_prefix(DocsClonedPath, JSONDirPath,
+ DocsDirPath);
+ if (auto EC = sys::fs::create_directories(DocsClonedPath)) {
+ return createFileError(DocsClonedPath, EC);
+ }
+ }
+
+ if (EC)
+ return createFileError("Failed to iterate: " + JSONIter->path(), EC);
+
+ auto Path = StringRef(JSONIter->path());
+ if (!Path.ends_with(".json")) {
+ JSONIter.increment(EC);
+ continue;
+ }
+
+ auto File = MemoryBuffer::getFile(Path);
+ if (EC = File.getError(); EC) {
+ unsigned ID = CDCtx.Diags.getCustomDiagID(DiagnosticsEngine::Warning,
+ "Failed to open file: %0 %1");
+ CDCtx.Diags.Report(ID) << Path << EC.message();
+ JSONIter.increment(EC);
+ continue;
+ }
+
+ auto Parsed = json::parse((*File)->getBuffer());
+ if (!Parsed)
+ return Parsed.takeError();
+ auto ValidJSON = Parsed.get();
+
+ std::error_code FileErr;
+ SmallString<128> DocsFilePath(JSONIter->path());
+ sys::path::replace_path_prefix(DocsFilePath, JSONDirPath, DocsDirPath);
+ sys::path::replace_extension(DocsFilePath, DirName);
+ raw_fd_ostream InfoOS(DocsFilePath, FileErr, sys::fs::OF_None);
+ if (FileErr)
+ return createFileOpenError(Path, FileErr);
+
+ auto RelativeRootPath = getRelativePathToRoot(DocsFilePath, DocsDirPath);
+ auto InfoTypeStr =
+ getInfoTypeStr(Parsed->getAsObject(), sys::path::stem(DocsFilePath));
+ if (!InfoTypeStr)
+ return InfoTypeStr.takeError();
+ if (Error Err = generateDocForJSON(*Parsed, InfoOS, CDCtx,
+ InfoTypeStr.get(), RelativeRootPath))
+ return Err;
+ JSONIter.increment(EC);
+ }
+ }
+
+ return Error::success();
+}
+
+Expected<std::string> MustacheGenerator::getInfoTypeStr(Object *Info,
+ StringRef Filename) {
+ auto StrValue = (*Info)["InfoType"];
+ if (StrValue.kind() != json::Value::Kind::String)
+ return createStringError("JSON file '%s' does not contain key: 'InfoType'.",
+ Filename.str().c_str());
+ auto ObjTypeStr = StrValue.getAsString();
+ if (!ObjTypeStr.has_value())
+ return createStringError(
+ "JSON file '%s' does not contain 'InfoType' field as a string.",
+ Filename.str().c_str());
+ return ObjTypeStr.value().str();
+}
+
+SmallString<128>
+MustacheGenerator::getRelativePathToRoot(StringRef PathToFile,
+ StringRef DocsRootPath) {
+ SmallString<128> PathVec(PathToFile);
+ // Remove filename, or else the relative path will have an extra "../"
+ sys::path::remove_filename(PathVec);
+ return computeRelativePath(DocsRootPath, PathVec);
+}
+
llvm::Error Generator::createResources(ClangDocContext &CDCtx) {
return llvm::Error::success();
}
@@ -100,8 +243,6 @@ void Generator::addInfoToIndex(Index &Idx, const doc::Info *Info) {
[[maybe_unused]] static int YAMLGeneratorAnchorDest = YAMLGeneratorAnchorSource;
[[maybe_unused]] static int MDGeneratorAnchorDest = MDGeneratorAnchorSource;
[[maybe_unused]] static int HTMLGeneratorAnchorDest = HTMLGeneratorAnchorSource;
-[[maybe_unused]] static int MHTMLGeneratorAnchorDest =
- MHTMLGeneratorAnchorSource;
[[maybe_unused]] static int JSONGeneratorAnchorDest = JSONGeneratorAnchorSource;
} // namespace doc
} // namespace clang
diff --git a/clang-tools-extra/clang-doc/Generators.h b/clang-tools-extra/clang-doc/Generators.h
index 92d3006..a50f1ac 100644
--- a/clang-tools-extra/clang-doc/Generators.h
+++ b/clang-tools-extra/clang-doc/Generators.h
@@ -14,6 +14,8 @@
#include "Representation.h"
#include "llvm/Support/Error.h"
+#include "llvm/Support/JSON.h"
+#include "llvm/Support/Mustache.h"
#include "llvm/Support/Registry.h"
namespace clang {
@@ -27,10 +29,9 @@ public:
// Write out the decl info for the objects in the given map in the specified
// format.
- virtual llvm::Error
- generateDocs(StringRef RootDir,
- llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
- const ClangDocContext &CDCtx) = 0;
+ virtual llvm::Error generateDocumentation(
+ StringRef RootDir, llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
+ const ClangDocContext &CDCtx, std::string DirName = "") = 0;
// This function writes a file with the index previously constructed.
// It can be overwritten by any of the inherited generators.
@@ -52,12 +53,90 @@ findGeneratorByName(llvm::StringRef Format);
std::string getTagType(TagTypeKind AS);
+llvm::Error createFileOpenError(StringRef FileName, std::error_code EC);
+
+class MustacheTemplateFile {
+ llvm::BumpPtrAllocator Allocator;
+ llvm::StringSaver Saver;
+ llvm::mustache::MustacheContext Ctx;
+ llvm::mustache::Template T;
+ std::unique_ptr<llvm::MemoryBuffer> Buffer;
+
+public:
+ static Expected<std::unique_ptr<MustacheTemplateFile>>
+ createMustacheFile(StringRef FileName) {
+ llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> BufferOrError =
+ llvm::MemoryBuffer::getFile(FileName);
+ if (auto EC = BufferOrError.getError())
+ return createFileOpenError(FileName, EC);
+ return std::make_unique<MustacheTemplateFile>(
+ std::move(BufferOrError.get()));
+ }
+
+ llvm::Error registerPartialFile(StringRef Name, StringRef FileName) {
+ llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> BufferOrError =
+ llvm::MemoryBuffer::getFile(FileName);
+ if (auto EC = BufferOrError.getError())
+ return createFileOpenError(FileName, EC);
+
+ std::unique_ptr<llvm::MemoryBuffer> Buffer = std::move(BufferOrError.get());
+ StringRef FileContent = Buffer->getBuffer();
+ T.registerPartial(Name.str(), FileContent.str());
+ return llvm::Error::success();
+ }
+
+ void render(llvm::json::Value &V, raw_ostream &OS) { T.render(V, OS); }
+
+ MustacheTemplateFile(std::unique_ptr<llvm::MemoryBuffer> &&B)
+ : Saver(Allocator), Ctx(Allocator, Saver), T(B->getBuffer(), Ctx),
+ Buffer(std::move(B)) {}
+};
+
+struct MustacheGenerator : public Generator {
+ Expected<std::string> getInfoTypeStr(llvm::json::Object *Info,
+ StringRef Filename);
+
+ /// Used to find the relative path from the file to the format's docs root.
+ /// Mainly used for the HTML resource paths.
+ SmallString<128> getRelativePathToRoot(StringRef PathToFile,
+ StringRef DocsRootPath);
+ virtual ~MustacheGenerator() = default;
+
+ /// Initializes the template files from disk and calls setupTemplate to
+ /// register partials
+ virtual llvm::Error setupTemplateFiles(const ClangDocContext &CDCtx) = 0;
+
+ /// Populates templates with data from JSON and calls any specifics for the
+ /// format. For example, for HTML it will render the paths for CSS and JS.
+ virtual llvm::Error generateDocForJSON(llvm::json::Value &JSON,
+ llvm::raw_fd_ostream &OS,
+ const ClangDocContext &CDCtx,
+ StringRef ObjectTypeStr,
+ StringRef RelativeRootPath) = 0;
+
+ /// Registers partials to templates.
+ llvm::Error
+ setupTemplate(std::unique_ptr<MustacheTemplateFile> &Template,
+ StringRef TemplatePath,
+ std::vector<std::pair<StringRef, StringRef>> Partials);
+
+ /// \brief The main orchestrator for Mustache-based documentation.
+ ///
+ /// 1. Initializes templates files from disk by calling setupTemplateFiles.
+ /// 2. Calls the JSON generator to write JSON to disk.
+ /// 3. Iterates over the JSON files, recreates the directory structure from
+ /// JSON, and calls generateDocForJSON for each file.
+ /// 4. A file of the desired format is created.
+ llvm::Error generateDocumentation(
+ StringRef RootDir, llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
+ const clang::doc::ClangDocContext &CDCtx, std::string DirName) override;
+};
+
// This anchor is used to force the linker to link in the generated object file
// and thus register the generators.
extern volatile int YAMLGeneratorAnchorSource;
extern volatile int MDGeneratorAnchorSource;
extern volatile int HTMLGeneratorAnchorSource;
-extern volatile int MHTMLGeneratorAnchorSource;
extern volatile int JSONGeneratorAnchorSource;
} // namespace doc
diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index 8294ff9..6f58c3d 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -5,1146 +5,169 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains the implementation of the HTMLGenerator class,
+/// which is a Clang-Doc generator for HTML using Mustache templates.
+///
+//===----------------------------------------------------------------------===//
#include "Generators.h"
#include "Representation.h"
#include "support/File.h"
-#include "clang/Basic/Version.h"
-#include "llvm/ADT/StringExtras.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/StringSet.h"
-#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/JSON.h"
+#include "llvm/Support/Error.h"
#include "llvm/Support/Path.h"
-#include "llvm/Support/raw_ostream.h"
-#include <algorithm>
-#include <optional>
-#include <string>
using namespace llvm;
+using namespace llvm::json;
+using namespace llvm::mustache;
namespace clang {
namespace doc {
-namespace {
-
-class HTMLTag {
-public:
- // Any other tag can be added if required
- enum TagType {
- TAG_A,
- TAG_DIV,
- TAG_FOOTER,
- TAG_H1,
- TAG_H2,
- TAG_H3,
- TAG_HEADER,
- TAG_LI,
- TAG_LINK,
- TAG_MAIN,
- TAG_META,
- TAG_OL,
- TAG_P,
- TAG_SCRIPT,
- TAG_SPAN,
- TAG_TITLE,
- TAG_UL,
- TAG_TABLE,
- TAG_THEAD,
- TAG_TBODY,
- TAG_TR,
- TAG_TD,
- TAG_TH
- };
-
- HTMLTag() = default;
- constexpr HTMLTag(TagType Value) : Value(Value) {}
-
- operator TagType() const { return Value; }
- operator bool() = delete;
-
- bool isSelfClosing() const;
- StringRef toString() const;
-
-private:
- TagType Value;
-};
-
-enum NodeType {
- NODE_TEXT,
- NODE_TAG,
-};
-
-struct HTMLNode {
- HTMLNode(NodeType Type) : Type(Type) {}
- virtual ~HTMLNode() = default;
-
- virtual void render(llvm::raw_ostream &OS, int IndentationLevel) = 0;
- NodeType Type; // Type of node
-};
-
-struct TextNode : public HTMLNode {
- TextNode(const Twine &Text)
- : HTMLNode(NodeType::NODE_TEXT), Text(Text.str()) {}
-
- std::string Text; // Content of node
- void render(llvm::raw_ostream &OS, int IndentationLevel) override;
-};
-
-struct TagNode : public HTMLNode {
- TagNode(HTMLTag Tag) : HTMLNode(NodeType::NODE_TAG), Tag(Tag) {}
- TagNode(HTMLTag Tag, const Twine &Text) : TagNode(Tag) {
- Children.emplace_back(std::make_unique<TextNode>(Text.str()));
- }
-
- HTMLTag Tag; // Name of HTML Tag (p, div, h1)
- std::vector<std::unique_ptr<HTMLNode>> Children; // List of child nodes
- std::vector<std::pair<std::string, std::string>>
- Attributes; // List of key-value attributes for tag
-
- void render(llvm::raw_ostream &OS, int IndentationLevel) override;
-};
-
-struct HTMLFile {
- std::vector<std::unique_ptr<HTMLNode>> Children; // List of child nodes
- void render(llvm::raw_ostream &OS) {
- OS << "<!DOCTYPE html>\n";
- for (const auto &C : Children) {
- C->render(OS, 0);
- OS << "\n";
- }
- }
-};
-
-} // namespace
-
-bool HTMLTag::isSelfClosing() const {
- switch (Value) {
- case HTMLTag::TAG_META:
- case HTMLTag::TAG_LINK:
- return true;
- case HTMLTag::TAG_A:
- case HTMLTag::TAG_DIV:
- case HTMLTag::TAG_FOOTER:
- case HTMLTag::TAG_H1:
- case HTMLTag::TAG_H2:
- case HTMLTag::TAG_H3:
- case HTMLTag::TAG_HEADER:
- case HTMLTag::TAG_LI:
- case HTMLTag::TAG_MAIN:
- case HTMLTag::TAG_OL:
- case HTMLTag::TAG_P:
- case HTMLTag::TAG_SCRIPT:
- case HTMLTag::TAG_SPAN:
- case HTMLTag::TAG_TITLE:
- case HTMLTag::TAG_UL:
- case HTMLTag::TAG_TABLE:
- case HTMLTag::TAG_THEAD:
- case HTMLTag::TAG_TBODY:
- case HTMLTag::TAG_TR:
- case HTMLTag::TAG_TD:
- case HTMLTag::TAG_TH:
- return false;
- }
- llvm_unreachable("Unhandled HTMLTag::TagType");
-}
-
-StringRef HTMLTag::toString() const {
- switch (Value) {
- case HTMLTag::TAG_A:
- return "a";
- case HTMLTag::TAG_DIV:
- return "div";
- case HTMLTag::TAG_FOOTER:
- return "footer";
- case HTMLTag::TAG_H1:
- return "h1";
- case HTMLTag::TAG_H2:
- return "h2";
- case HTMLTag::TAG_H3:
- return "h3";
- case HTMLTag::TAG_HEADER:
- return "header";
- case HTMLTag::TAG_LI:
- return "li";
- case HTMLTag::TAG_LINK:
- return "link";
- case HTMLTag::TAG_MAIN:
- return "main";
- case HTMLTag::TAG_META:
- return "meta";
- case HTMLTag::TAG_OL:
- return "ol";
- case HTMLTag::TAG_P:
- return "p";
- case HTMLTag::TAG_SCRIPT:
- return "script";
- case HTMLTag::TAG_SPAN:
- return "span";
- case HTMLTag::TAG_TITLE:
- return "title";
- case HTMLTag::TAG_UL:
- return "ul";
- case HTMLTag::TAG_TABLE:
- return "table";
- case HTMLTag::TAG_THEAD:
- return "thead";
- case HTMLTag::TAG_TBODY:
- return "tbody";
- case HTMLTag::TAG_TR:
- return "tr";
- case HTMLTag::TAG_TD:
- return "td";
- case HTMLTag::TAG_TH:
- return "th";
- }
- llvm_unreachable("Unhandled HTMLTag::TagType");
-}
-
-void TextNode::render(llvm::raw_ostream &OS, int IndentationLevel) {
- OS.indent(IndentationLevel * 2);
- printHTMLEscaped(Text, OS);
-}
-
-void TagNode::render(llvm::raw_ostream &OS, int IndentationLevel) {
- // Children nodes are rendered in the same line if all of them are text nodes
- bool InlineChildren = true;
- for (const auto &C : Children)
- if (C->Type == NodeType::NODE_TAG) {
- InlineChildren = false;
- break;
- }
- OS.indent(IndentationLevel * 2);
- OS << "<" << Tag.toString();
- for (const auto &A : Attributes)
- OS << " " << A.first << "=\"" << A.second << "\"";
- if (Tag.isSelfClosing()) {
- OS << "/>";
- return;
- }
- OS << ">";
- if (!InlineChildren)
- OS << "\n";
- bool NewLineRendered = true;
- for (const auto &C : Children) {
- int ChildrenIndentation =
- InlineChildren || !NewLineRendered ? 0 : IndentationLevel + 1;
- C->render(OS, ChildrenIndentation);
- if (!InlineChildren && (C == Children.back() ||
- (C->Type != NodeType::NODE_TEXT ||
- (&C + 1)->get()->Type != NodeType::NODE_TEXT))) {
- OS << "\n";
- NewLineRendered = true;
- } else
- NewLineRendered = false;
- }
- if (!InlineChildren)
- OS.indent(IndentationLevel * 2);
- OS << "</" << Tag.toString() << ">";
-}
-
-template <typename Derived, typename Base,
- typename = std::enable_if<std::is_base_of<Derived, Base>::value>>
-static void appendVector(std::vector<Derived> &&New,
- std::vector<Base> &Original) {
- std::move(New.begin(), New.end(), std::back_inserter(Original));
-}
-
-// HTML generation
-
-static std::vector<std::unique_ptr<TagNode>>
-genStylesheetsHTML(StringRef InfoPath, const ClangDocContext &CDCtx) {
- std::vector<std::unique_ptr<TagNode>> Out;
- for (const auto &FilePath : CDCtx.UserStylesheets) {
- auto LinkNode = std::make_unique<TagNode>(HTMLTag::TAG_LINK);
- LinkNode->Attributes.emplace_back("rel", "stylesheet");
- SmallString<128> StylesheetPath = computeRelativePath("", InfoPath);
- llvm::sys::path::append(StylesheetPath,
- llvm::sys::path::filename(FilePath));
- // Paths in HTML must be in posix-style
- llvm::sys::path::native(StylesheetPath, llvm::sys::path::Style::posix);
- LinkNode->Attributes.emplace_back("href", std::string(StylesheetPath));
- Out.emplace_back(std::move(LinkNode));
- }
- return Out;
-}
-
-static std::vector<std::unique_ptr<TagNode>>
-genJsScriptsHTML(StringRef InfoPath, const ClangDocContext &CDCtx) {
- std::vector<std::unique_ptr<TagNode>> Out;
-
- // index_json.js is part of every generated HTML file
- SmallString<128> IndexJSONPath = computeRelativePath("", InfoPath);
- auto IndexJSONNode = std::make_unique<TagNode>(HTMLTag::TAG_SCRIPT);
- llvm::sys::path::append(IndexJSONPath, "index_json.js");
- llvm::sys::path::native(IndexJSONPath, llvm::sys::path::Style::posix);
- IndexJSONNode->Attributes.emplace_back("src", std::string(IndexJSONPath));
- Out.emplace_back(std::move(IndexJSONNode));
-
- for (const auto &FilePath : CDCtx.JsScripts) {
- SmallString<128> ScriptPath = computeRelativePath("", InfoPath);
- auto ScriptNode = std::make_unique<TagNode>(HTMLTag::TAG_SCRIPT);
- llvm::sys::path::append(ScriptPath, llvm::sys::path::filename(FilePath));
- // Paths in HTML must be in posix-style
- llvm::sys::path::native(ScriptPath, llvm::sys::path::Style::posix);
- ScriptNode->Attributes.emplace_back("src", std::string(ScriptPath));
- Out.emplace_back(std::move(ScriptNode));
- }
- return Out;
-}
-
-static std::unique_ptr<TagNode> genLink(const Twine &Text, const Twine &Link) {
- auto LinkNode = std::make_unique<TagNode>(HTMLTag::TAG_A, Text);
- LinkNode->Attributes.emplace_back("href", Link.str());
- return LinkNode;
-}
-
-static std::unique_ptr<HTMLNode>
-genReference(const Reference &Type, StringRef CurrentDirectory,
- std::optional<StringRef> JumpToSection = std::nullopt) {
- if (Type.Path.empty()) {
- if (!JumpToSection)
- return std::make_unique<TextNode>(Type.Name);
- return genLink(Type.Name, "#" + *JumpToSection);
- }
- llvm::SmallString<64> Path = Type.getRelativeFilePath(CurrentDirectory);
- llvm::sys::path::append(Path, Type.getFileBaseName() + ".html");
-
- // Paths in HTML must be in posix-style
- llvm::sys::path::native(Path, llvm::sys::path::Style::posix);
- if (JumpToSection)
- Path += ("#" + *JumpToSection).str();
- return genLink(Type.Name, Path);
-}
-
-static std::vector<std::unique_ptr<HTMLNode>>
-genReferenceList(const llvm::SmallVectorImpl<Reference> &Refs,
- const StringRef &CurrentDirectory) {
- std::vector<std::unique_ptr<HTMLNode>> Out;
- for (const auto &R : Refs) {
- if (&R != Refs.begin())
- Out.emplace_back(std::make_unique<TextNode>(", "));
- Out.emplace_back(genReference(R, CurrentDirectory));
- }
- return Out;
-}
-
-static std::vector<std::unique_ptr<TagNode>>
-genHTML(const EnumInfo &I, const ClangDocContext &CDCtx);
-static std::vector<std::unique_ptr<TagNode>>
-genHTML(const FunctionInfo &I, const ClangDocContext &CDCtx,
- StringRef ParentInfoDir);
-static std::unique_ptr<TagNode> genHTML(const std::vector<CommentInfo> &C);
-
-static std::vector<std::unique_ptr<TagNode>>
-genEnumsBlock(const std::vector<EnumInfo> &Enums,
- const ClangDocContext &CDCtx) {
- if (Enums.empty())
- return {};
-
- std::vector<std::unique_ptr<TagNode>> Out;
- Out.emplace_back(std::make_unique<TagNode>(HTMLTag::TAG_H2, "Enums"));
- Out.back()->Attributes.emplace_back("id", "Enums");
- Out.emplace_back(std::make_unique<TagNode>(HTMLTag::TAG_DIV));
- auto &DivBody = Out.back();
- for (const auto &E : Enums) {
- std::vector<std::unique_ptr<TagNode>> Nodes = genHTML(E, CDCtx);
- appendVector(std::move(Nodes), DivBody->Children);
- }
- return Out;
-}
-
-static std::unique_ptr<TagNode>
-genEnumMembersBlock(const llvm::SmallVector<EnumValueInfo, 4> &Members) {
- if (Members.empty())
- return nullptr;
-
- auto List = std::make_unique<TagNode>(HTMLTag::TAG_TBODY);
-
- for (const auto &M : Members) {
- auto TRNode = std::make_unique<TagNode>(HTMLTag::TAG_TR);
- TRNode->Children.emplace_back(
- std::make_unique<TagNode>(HTMLTag::TAG_TD, M.Name));
- // Use user supplied value if it exists, otherwise use the value
- if (!M.ValueExpr.empty()) {
- TRNode->Children.emplace_back(
- std::make_unique<TagNode>(HTMLTag::TAG_TD, M.ValueExpr));
- } else {
- TRNode->Children.emplace_back(
- std::make_unique<TagNode>(HTMLTag::TAG_TD, M.Value));
- }
- if (!M.Description.empty()) {
- auto TD = std::make_unique<TagNode>(HTMLTag::TAG_TD);
- TD->Children.emplace_back(genHTML(M.Description));
- TRNode->Children.emplace_back(std::move(TD));
- }
- List->Children.emplace_back(std::move(TRNode));
- }
- return List;
-}
-
-static std::vector<std::unique_ptr<TagNode>>
-genFunctionsBlock(const std::vector<FunctionInfo> &Functions,
- const ClangDocContext &CDCtx, StringRef ParentInfoDir) {
- if (Functions.empty())
- return {};
-
- std::vector<std::unique_ptr<TagNode>> Out;
- Out.emplace_back(std::make_unique<TagNode>(HTMLTag::TAG_H2, "Functions"));
- Out.back()->Attributes.emplace_back("id", "Functions");
- Out.emplace_back(std::make_unique<TagNode>(HTMLTag::TAG_DIV));
- auto &DivBody = Out.back();
- for (const auto &F : Functions) {
- std::vector<std::unique_ptr<TagNode>> Nodes =
- genHTML(F, CDCtx, ParentInfoDir);
- appendVector(std::move(Nodes), DivBody->Children);
- }
- return Out;
-}
-
-static std::vector<std::unique_ptr<TagNode>>
-genRecordMembersBlock(const llvm::SmallVector<MemberTypeInfo, 4> &Members,
- StringRef ParentInfoDir) {
- if (Members.empty())
- return {};
-
- std::vector<std::unique_ptr<TagNode>> Out;
- Out.emplace_back(std::make_unique<TagNode>(HTMLTag::TAG_H2, "Members"));
- Out.back()->Attributes.emplace_back("id", "Members");
- Out.emplace_back(std::make_unique<TagNode>(HTMLTag::TAG_UL));
- auto &ULBody = Out.back();
- for (const auto &M : Members) {
- StringRef Access = getAccessSpelling(M.Access);
- auto LIBody = std::make_unique<TagNode>(HTMLTag::TAG_LI);
- auto MemberDecl = std::make_unique<TagNode>(HTMLTag::TAG_DIV);
- if (!Access.empty())
- MemberDecl->Children.emplace_back(
- std::make_unique<TextNode>(Access + " "));
- if (M.IsStatic)
- MemberDecl->Children.emplace_back(std::make_unique<TextNode>("static "));
- MemberDecl->Children.emplace_back(genReference(M.Type, ParentInfoDir));
- MemberDecl->Children.emplace_back(std::make_unique<TextNode>(" " + M.Name));
- if (!M.Description.empty())
- LIBody->Children.emplace_back(genHTML(M.Description));
- LIBody->Children.emplace_back(std::move(MemberDecl));
- ULBody->Children.emplace_back(std::move(LIBody));
- }
- return Out;
-}
-
-static std::vector<std::unique_ptr<TagNode>>
-genReferencesBlock(const std::vector<Reference> &References,
- llvm::StringRef Title, StringRef ParentPath) {
- if (References.empty())
- return {};
-
- std::vector<std::unique_ptr<TagNode>> Out;
- Out.emplace_back(std::make_unique<TagNode>(HTMLTag::TAG_H2, Title));
- Out.back()->Attributes.emplace_back("id", std::string(Title));
- Out.emplace_back(std::make_unique<TagNode>(HTMLTag::TAG_UL));
- auto &ULBody = Out.back();
- for (const auto &R : References) {
- auto LiNode = std::make_unique<TagNode>(HTMLTag::TAG_LI);
- LiNode->Children.emplace_back(genReference(R, ParentPath));
- ULBody->Children.emplace_back(std::move(LiNode));
- }
- return Out;
-}
-static std::unique_ptr<TagNode> writeSourceFileRef(const ClangDocContext &CDCtx,
- const Location &L) {
-
- if (!L.IsFileInRootDir && !CDCtx.RepositoryUrl)
- return std::make_unique<TagNode>(
- HTMLTag::TAG_P, "Defined at line " + std::to_string(L.StartLineNumber) +
- " of file " + L.Filename);
-
- SmallString<128> FileURL(CDCtx.RepositoryUrl.value_or(""));
- llvm::sys::path::append(
- FileURL, llvm::sys::path::Style::posix,
- // If we're on Windows, the file name will be in the wrong format, and
- // append won't convert the full path being appended to the correct
- // format, so we need to do that here.
- llvm::sys::path::convert_to_slash(
- L.Filename,
- // The style here is the current style of the path, not the one we're
- // targeting. If the string is already in the posix style, it will do
- // nothing.
- llvm::sys::path::Style::windows));
- auto Node = std::make_unique<TagNode>(HTMLTag::TAG_P);
- Node->Children.emplace_back(std::make_unique<TextNode>("Defined at line "));
- auto LocNumberNode = std::make_unique<TagNode>(
- HTMLTag::TAG_A, std::to_string(L.StartLineNumber));
- // The links to a specific line in the source code use the github /
- // googlesource notation so it won't work for all hosting pages.
- LocNumberNode->Attributes.emplace_back(
- "href",
- formatv("{0}#{1}{2}", FileURL, CDCtx.RepositoryLinePrefix.value_or(""),
- L.StartLineNumber));
- Node->Children.emplace_back(std::move(LocNumberNode));
- Node->Children.emplace_back(std::make_unique<TextNode>(" of file "));
- auto LocFileNode = std::make_unique<TagNode>(
- HTMLTag::TAG_A, llvm::sys::path::filename(FileURL));
- LocFileNode->Attributes.emplace_back("href", std::string(FileURL));
- Node->Children.emplace_back(std::move(LocFileNode));
- return Node;
-}
-
-static void maybeWriteSourceFileRef(std::vector<std::unique_ptr<TagNode>> &Out,
- const ClangDocContext &CDCtx,
- const std::optional<Location> &DefLoc) {
- if (DefLoc)
- Out.emplace_back(writeSourceFileRef(CDCtx, *DefLoc));
-}
-
-static std::vector<std::unique_ptr<TagNode>>
-genHTML(const Index &Index, StringRef InfoPath, bool IsOutermostList);
-
-// Generates a list of child nodes for the HTML head tag
-// It contains a meta node, link nodes to import CSS files, and script nodes to
-// import JS files
-static std::vector<std::unique_ptr<TagNode>>
-genFileHeadNodes(StringRef Title, StringRef InfoPath,
- const ClangDocContext &CDCtx) {
- std::vector<std::unique_ptr<TagNode>> Out;
- auto MetaNode = std::make_unique<TagNode>(HTMLTag::TAG_META);
- MetaNode->Attributes.emplace_back("charset", "utf-8");
- Out.emplace_back(std::move(MetaNode));
- Out.emplace_back(std::make_unique<TagNode>(HTMLTag::TAG_TITLE, Title));
- std::vector<std::unique_ptr<TagNode>> StylesheetsNodes =
- genStylesheetsHTML(InfoPath, CDCtx);
- appendVector(std::move(StylesheetsNodes), Out);
- std::vector<std::unique_ptr<TagNode>> JsNodes =
- genJsScriptsHTML(InfoPath, CDCtx);
- appendVector(std::move(JsNodes), Out);
- return Out;
-}
-
-// Generates a header HTML node that can be used for any file
-// It contains the project name
-static std::unique_ptr<TagNode> genFileHeaderNode(StringRef ProjectName) {
- auto HeaderNode = std::make_unique<TagNode>(HTMLTag::TAG_HEADER, ProjectName);
- HeaderNode->Attributes.emplace_back("id", "project-title");
- return HeaderNode;
-}
-
-// Generates a main HTML node that has all the main content of an info file
-// It contains both indexes and the info's documented information
-// This function should only be used for the info files (not for the file that
-// only has the general index)
-static std::unique_ptr<TagNode> genInfoFileMainNode(
- StringRef InfoPath,
- std::vector<std::unique_ptr<TagNode>> &MainContentInnerNodes,
- const Index &InfoIndex) {
- auto MainNode = std::make_unique<TagNode>(HTMLTag::TAG_MAIN);
-
- auto LeftSidebarNode = std::make_unique<TagNode>(HTMLTag::TAG_DIV);
- LeftSidebarNode->Attributes.emplace_back("id", "sidebar-left");
- LeftSidebarNode->Attributes.emplace_back("path", std::string(InfoPath));
- LeftSidebarNode->Attributes.emplace_back(
- "class", "col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas-left");
-
- auto MainContentNode = std::make_unique<TagNode>(HTMLTag::TAG_DIV);
- MainContentNode->Attributes.emplace_back("id", "main-content");
- MainContentNode->Attributes.emplace_back(
- "class", "col-xs-12 col-sm-9 col-md-8 main-content");
- appendVector(std::move(MainContentInnerNodes), MainContentNode->Children);
-
- auto RightSidebarNode = std::make_unique<TagNode>(HTMLTag::TAG_DIV);
- RightSidebarNode->Attributes.emplace_back("id", "sidebar-right");
- RightSidebarNode->Attributes.emplace_back(
- "class", "col-xs-6 col-sm-6 col-md-2 sidebar sidebar-offcanvas-right");
- std::vector<std::unique_ptr<TagNode>> InfoIndexHTML =
- genHTML(InfoIndex, InfoPath, true);
- appendVector(std::move(InfoIndexHTML), RightSidebarNode->Children);
-
- MainNode->Children.emplace_back(std::move(LeftSidebarNode));
- MainNode->Children.emplace_back(std::move(MainContentNode));
- MainNode->Children.emplace_back(std::move(RightSidebarNode));
-
- return MainNode;
-}
-
-// Generates a footer HTML node that can be used for any file
-// It contains clang-doc's version
-static std::unique_ptr<TagNode> genFileFooterNode() {
- auto FooterNode = std::make_unique<TagNode>(HTMLTag::TAG_FOOTER);
- auto SpanNode = std::make_unique<TagNode>(
- HTMLTag::TAG_SPAN, clang::getClangToolFullVersion("clang-doc"));
- SpanNode->Attributes.emplace_back("class", "no-break");
- FooterNode->Children.emplace_back(std::move(SpanNode));
- return FooterNode;
-}
-
-// Generates a complete HTMLFile for an Info
-static HTMLFile
-genInfoFile(StringRef Title, StringRef InfoPath,
- std::vector<std::unique_ptr<TagNode>> &MainContentNodes,
- const Index &InfoIndex, const ClangDocContext &CDCtx) {
- HTMLFile F;
-
- std::vector<std::unique_ptr<TagNode>> HeadNodes =
- genFileHeadNodes(Title, InfoPath, CDCtx);
- std::unique_ptr<TagNode> HeaderNode = genFileHeaderNode(CDCtx.ProjectName);
- std::unique_ptr<TagNode> MainNode =
- genInfoFileMainNode(InfoPath, MainContentNodes, InfoIndex);
- std::unique_ptr<TagNode> FooterNode = genFileFooterNode();
-
- appendVector(std::move(HeadNodes), F.Children);
- F.Children.emplace_back(std::move(HeaderNode));
- F.Children.emplace_back(std::move(MainNode));
- F.Children.emplace_back(std::move(FooterNode));
-
- return F;
-}
-
-template <typename T,
- typename = std::enable_if<std::is_base_of<T, Info>::value>>
-static Index genInfoIndexItem(const std::vector<T> &Infos, StringRef Title) {
- Index Idx(Title, Title);
- for (const auto &C : Infos)
- Idx.Children.emplace_back(C.extractName(),
- llvm::toHex(llvm::toStringRef(C.USR)));
- return Idx;
-}
-
-static std::vector<std::unique_ptr<TagNode>>
-genHTML(const Index &Index, StringRef InfoPath, bool IsOutermostList) {
- std::vector<std::unique_ptr<TagNode>> Out;
- if (!Index.Name.empty()) {
- Out.emplace_back(std::make_unique<TagNode>(HTMLTag::TAG_SPAN));
- auto &SpanBody = Out.back();
- if (!Index.JumpToSection)
- SpanBody->Children.emplace_back(genReference(Index, InfoPath));
- else
- SpanBody->Children.emplace_back(
- genReference(Index, InfoPath, Index.JumpToSection->str()));
- }
- if (Index.Children.empty())
- return Out;
- // Only the outermost list should use ol, the others should use ul
- HTMLTag ListHTMLTag = IsOutermostList ? HTMLTag::TAG_OL : HTMLTag::TAG_UL;
- Out.emplace_back(std::make_unique<TagNode>(ListHTMLTag));
- const auto &UlBody = Out.back();
- for (const auto &C : Index.Children) {
- auto LiBody = std::make_unique<TagNode>(HTMLTag::TAG_LI);
- std::vector<std::unique_ptr<TagNode>> Nodes = genHTML(C, InfoPath, false);
- appendVector(std::move(Nodes), LiBody->Children);
- UlBody->Children.emplace_back(std::move(LiBody));
- }
- return Out;
-}
-
-static std::unique_ptr<HTMLNode> genHTML(const CommentInfo &I) {
- switch (I.Kind) {
- case CommentKind::CK_FullComment: {
- auto FullComment = std::make_unique<TagNode>(HTMLTag::TAG_DIV);
- for (const auto &Child : I.Children) {
- std::unique_ptr<HTMLNode> Node = genHTML(*Child);
- if (Node)
- FullComment->Children.emplace_back(std::move(Node));
- }
- return std::move(FullComment);
- }
-
- case CommentKind::CK_ParagraphComment: {
- auto ParagraphComment = std::make_unique<TagNode>(HTMLTag::TAG_P);
- for (const auto &Child : I.Children) {
- std::unique_ptr<HTMLNode> Node = genHTML(*Child);
- if (Node)
- ParagraphComment->Children.emplace_back(std::move(Node));
- }
- if (ParagraphComment->Children.empty())
- return nullptr;
- return std::move(ParagraphComment);
- }
-
- case CommentKind::CK_BlockCommandComment: {
- auto BlockComment = std::make_unique<TagNode>(HTMLTag::TAG_DIV);
- BlockComment->Children.emplace_back(
- std::make_unique<TagNode>(HTMLTag::TAG_DIV, I.Name));
- for (const auto &Child : I.Children) {
- std::unique_ptr<HTMLNode> Node = genHTML(*Child);
- if (Node)
- BlockComment->Children.emplace_back(std::move(Node));
- }
- if (BlockComment->Children.empty())
- return nullptr;
- return std::move(BlockComment);
- }
-
- case CommentKind::CK_TextComment: {
- if (I.Text.empty())
- return nullptr;
- return std::make_unique<TextNode>(I.Text);
- }
-
- // For now, return nullptr for unsupported comment kinds
- case CommentKind::CK_InlineCommandComment:
- case CommentKind::CK_HTMLStartTagComment:
- case CommentKind::CK_HTMLEndTagComment:
- case CommentKind::CK_ParamCommandComment:
- case CommentKind::CK_TParamCommandComment:
- case CommentKind::CK_VerbatimBlockComment:
- case CommentKind::CK_VerbatimBlockLineComment:
- case CommentKind::CK_VerbatimLineComment:
- case CommentKind::CK_Unknown:
- return nullptr;
- }
- llvm_unreachable("Unhandled CommentKind");
-}
-
-static std::unique_ptr<TagNode> genHTML(const std::vector<CommentInfo> &C) {
- auto CommentBlock = std::make_unique<TagNode>(HTMLTag::TAG_DIV);
- for (const auto &Child : C) {
- if (std::unique_ptr<HTMLNode> Node = genHTML(Child))
- CommentBlock->Children.emplace_back(std::move(Node));
- }
- return CommentBlock;
-}
-
-static std::vector<std::unique_ptr<TagNode>>
-genHTML(const EnumInfo &I, const ClangDocContext &CDCtx) {
- std::vector<std::unique_ptr<TagNode>> Out;
- std::string EnumType = I.Scoped ? "enum class " : "enum ";
- // Determine if enum members have comments attached
- bool HasComments = llvm::any_of(
- I.Members, [](const EnumValueInfo &M) { return !M.Description.empty(); });
- std::unique_ptr<TagNode> Table =
- std::make_unique<TagNode>(HTMLTag::TAG_TABLE);
- std::unique_ptr<TagNode> THead =
- std::make_unique<TagNode>(HTMLTag::TAG_THEAD);
- std::unique_ptr<TagNode> TRow = std::make_unique<TagNode>(HTMLTag::TAG_TR);
- std::unique_ptr<TagNode> TD =
- std::make_unique<TagNode>(HTMLTag::TAG_TH, EnumType + I.Name);
- // Span 3 columns if enum has comments
- TD->Attributes.emplace_back("colspan", HasComments ? "3" : "2");
-
- Table->Attributes.emplace_back("id", llvm::toHex(llvm::toStringRef(I.USR)));
- TRow->Children.emplace_back(std::move(TD));
- THead->Children.emplace_back(std::move(TRow));
- Table->Children.emplace_back(std::move(THead));
-
- if (std::unique_ptr<TagNode> Node = genEnumMembersBlock(I.Members))
- Table->Children.emplace_back(std::move(Node));
+static std::unique_ptr<MustacheTemplateFile> NamespaceTemplate = nullptr;
- Out.emplace_back(std::move(Table));
-
- maybeWriteSourceFileRef(Out, CDCtx, I.DefLoc);
-
- if (!I.Description.empty())
- Out.emplace_back(genHTML(I.Description));
-
- return Out;
-}
-
-static std::vector<std::unique_ptr<TagNode>>
-genHTML(const FunctionInfo &I, const ClangDocContext &CDCtx,
- StringRef ParentInfoDir) {
- std::vector<std::unique_ptr<TagNode>> Out;
- Out.emplace_back(std::make_unique<TagNode>(HTMLTag::TAG_H3, I.Name));
- // USR is used as id for functions instead of name to disambiguate function
- // overloads.
- Out.back()->Attributes.emplace_back("id",
- llvm::toHex(llvm::toStringRef(I.USR)));
-
- Out.emplace_back(std::make_unique<TagNode>(HTMLTag::TAG_P));
- auto &FunctionHeader = Out.back();
-
- std::string Access = getAccessSpelling(I.Access).str();
- if (Access != "")
- FunctionHeader->Children.emplace_back(
- std::make_unique<TextNode>(Access + " "));
- if (I.IsStatic)
- FunctionHeader->Children.emplace_back(
- std::make_unique<TextNode>("static "));
- if (I.ReturnType.Type.Name != "") {
- FunctionHeader->Children.emplace_back(
- genReference(I.ReturnType.Type, ParentInfoDir));
- FunctionHeader->Children.emplace_back(std::make_unique<TextNode>(" "));
- }
- FunctionHeader->Children.emplace_back(
- std::make_unique<TextNode>(I.Name + "("));
-
- for (const auto &P : I.Params) {
- if (&P != I.Params.begin())
- FunctionHeader->Children.emplace_back(std::make_unique<TextNode>(", "));
- FunctionHeader->Children.emplace_back(genReference(P.Type, ParentInfoDir));
- FunctionHeader->Children.emplace_back(
- std::make_unique<TextNode>(" " + P.Name));
- }
- FunctionHeader->Children.emplace_back(std::make_unique<TextNode>(")"));
-
- maybeWriteSourceFileRef(Out, CDCtx, I.DefLoc);
-
- if (!I.Description.empty())
- Out.emplace_back(genHTML(I.Description));
-
- return Out;
-}
+static std::unique_ptr<MustacheTemplateFile> RecordTemplate = nullptr;
-static std::vector<std::unique_ptr<TagNode>>
-genHTML(const NamespaceInfo &I, Index &InfoIndex, const ClangDocContext &CDCtx,
- std::string &InfoTitle) {
- std::vector<std::unique_ptr<TagNode>> Out;
- if (I.Name.str() == "")
- InfoTitle = "Global Namespace";
- else
- InfoTitle = ("namespace " + I.Name).str();
-
- Out.emplace_back(std::make_unique<TagNode>(HTMLTag::TAG_H1, InfoTitle));
-
- if (!I.Description.empty())
- Out.emplace_back(genHTML(I.Description));
-
- llvm::SmallString<64> BasePath = I.getRelativeFilePath("");
-
- std::vector<std::unique_ptr<TagNode>> ChildNamespaces =
- genReferencesBlock(I.Children.Namespaces, "Namespaces", BasePath);
- appendVector(std::move(ChildNamespaces), Out);
- std::vector<std::unique_ptr<TagNode>> ChildRecords =
- genReferencesBlock(I.Children.Records, "Records", BasePath);
- appendVector(std::move(ChildRecords), Out);
-
- std::vector<std::unique_ptr<TagNode>> ChildFunctions =
- genFunctionsBlock(I.Children.Functions, CDCtx, BasePath);
- appendVector(std::move(ChildFunctions), Out);
- std::vector<std::unique_ptr<TagNode>> ChildEnums =
- genEnumsBlock(I.Children.Enums, CDCtx);
- appendVector(std::move(ChildEnums), Out);
-
- if (!I.Children.Namespaces.empty())
- InfoIndex.Children.emplace_back("Namespaces", "Namespaces");
- if (!I.Children.Records.empty())
- InfoIndex.Children.emplace_back("Records", "Records");
- if (!I.Children.Functions.empty())
- InfoIndex.Children.emplace_back(
- genInfoIndexItem(I.Children.Functions, "Functions"));
- if (!I.Children.Enums.empty())
- InfoIndex.Children.emplace_back(
- genInfoIndexItem(I.Children.Enums, "Enums"));
-
- return Out;
-}
-
-static std::vector<std::unique_ptr<TagNode>>
-genHTML(const RecordInfo &I, Index &InfoIndex, const ClangDocContext &CDCtx,
- std::string &InfoTitle) {
- std::vector<std::unique_ptr<TagNode>> Out;
- InfoTitle = (getTagType(I.TagType) + " " + I.Name).str();
- Out.emplace_back(std::make_unique<TagNode>(HTMLTag::TAG_H1, InfoTitle));
-
- maybeWriteSourceFileRef(Out, CDCtx, I.DefLoc);
-
- if (!I.Description.empty())
- Out.emplace_back(genHTML(I.Description));
-
- std::vector<std::unique_ptr<HTMLNode>> Parents =
- genReferenceList(I.Parents, I.Path);
- std::vector<std::unique_ptr<HTMLNode>> VParents =
- genReferenceList(I.VirtualParents, I.Path);
- if (!Parents.empty() || !VParents.empty()) {
- Out.emplace_back(std::make_unique<TagNode>(HTMLTag::TAG_P));
- auto &PBody = Out.back();
- PBody->Children.emplace_back(std::make_unique<TextNode>("Inherits from "));
- if (Parents.empty())
- appendVector(std::move(VParents), PBody->Children);
- else if (VParents.empty())
- appendVector(std::move(Parents), PBody->Children);
- else {
- appendVector(std::move(Parents), PBody->Children);
- PBody->Children.emplace_back(std::make_unique<TextNode>(", "));
- appendVector(std::move(VParents), PBody->Children);
- }
- }
-
- std::vector<std::unique_ptr<TagNode>> Members =
- genRecordMembersBlock(I.Members, I.Path);
- appendVector(std::move(Members), Out);
- std::vector<std::unique_ptr<TagNode>> ChildRecords =
- genReferencesBlock(I.Children.Records, "Records", I.Path);
- appendVector(std::move(ChildRecords), Out);
-
- std::vector<std::unique_ptr<TagNode>> ChildFunctions =
- genFunctionsBlock(I.Children.Functions, CDCtx, I.Path);
- appendVector(std::move(ChildFunctions), Out);
- std::vector<std::unique_ptr<TagNode>> ChildEnums =
- genEnumsBlock(I.Children.Enums, CDCtx);
- appendVector(std::move(ChildEnums), Out);
-
- if (!I.Members.empty())
- InfoIndex.Children.emplace_back("Members", "Members");
- if (!I.Children.Records.empty())
- InfoIndex.Children.emplace_back("Records", "Records");
- if (!I.Children.Functions.empty())
- InfoIndex.Children.emplace_back(
- genInfoIndexItem(I.Children.Functions, "Functions"));
- if (!I.Children.Enums.empty())
- InfoIndex.Children.emplace_back(
- genInfoIndexItem(I.Children.Enums, "Enums"));
-
- return Out;
-}
-
-static std::vector<std::unique_ptr<TagNode>>
-genHTML(const TypedefInfo &I, const ClangDocContext &CDCtx,
- std::string &InfoTitle) {
- // TODO support typedefs in HTML.
- return {};
-}
-
-/// Generator for HTML documentation.
-class HTMLGenerator : public Generator {
+class HTMLGenerator : public MustacheGenerator {
public:
static const char *Format;
-
- llvm::Error generateDocs(StringRef RootDir,
- llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
+ Error createResources(ClangDocContext &CDCtx) override;
+ Error generateDocForInfo(Info *I, raw_ostream &OS,
const ClangDocContext &CDCtx) override;
- llvm::Error createResources(ClangDocContext &CDCtx) override;
- llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream &OS,
- const ClangDocContext &CDCtx) override;
+ Error setupTemplateFiles(const ClangDocContext &CDCtx) override;
+ Error generateDocForJSON(json::Value &JSON, raw_fd_ostream &OS,
+ const ClangDocContext &CDCtx, StringRef ObjTypeStr,
+ StringRef RelativeRootPath) override;
+ // Populates templates with CSS stylesheets, JS scripts paths.
+ Error setupTemplateResources(const ClangDocContext &CDCtx, json::Value &V,
+ SmallString<128> RelativeRootPath);
+ llvm::Error generateDocumentation(
+ StringRef RootDir, llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
+ const ClangDocContext &CDCtx, std::string DirName) override;
};
-const char *HTMLGenerator::Format = "html";
-
-llvm::Error
-HTMLGenerator::generateDocs(StringRef RootDir,
- llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
- const ClangDocContext &CDCtx) {
- // Track which directories we already tried to create.
- llvm::StringSet<> CreatedDirs;
+Error HTMLGenerator::setupTemplateFiles(const ClangDocContext &CDCtx) {
+ // Template files need to use the native path when they're opened,
+ // but have to be used in POSIX style when used in HTML.
+ auto ConvertToNative = [](std::string &&Path) -> std::string {
+ SmallString<128> PathBuf(Path);
+ llvm::sys::path::native(PathBuf);
+ return PathBuf.str().str();
+ };
- // Collect all output by file name and create the nexessary directories.
- llvm::StringMap<std::vector<doc::Info *>> FileToInfos;
- for (const auto &Group : Infos) {
- doc::Info *Info = Group.getValue().get();
+ std::string NamespaceFilePath =
+ ConvertToNative(CDCtx.MustacheTemplates.lookup("namespace-template"));
+ std::string ClassFilePath =
+ ConvertToNative(CDCtx.MustacheTemplates.lookup("class-template"));
+ std::string CommentFilePath =
+ ConvertToNative(CDCtx.MustacheTemplates.lookup("comment-template"));
+ std::string FunctionFilePath =
+ ConvertToNative(CDCtx.MustacheTemplates.lookup("function-template"));
+ std::string EnumFilePath =
+ ConvertToNative(CDCtx.MustacheTemplates.lookup("enum-template"));
+ std::vector<std::pair<StringRef, StringRef>> Partials = {
+ {"Comments", CommentFilePath},
+ {"FunctionPartial", FunctionFilePath},
+ {"EnumPartial", EnumFilePath}};
+
+ if (Error Err = setupTemplate(NamespaceTemplate, NamespaceFilePath, Partials))
+ return Err;
- llvm::SmallString<128> Path;
- llvm::sys::path::native(RootDir, Path);
- llvm::sys::path::append(Path, Info->getRelativeFilePath(""));
- if (!CreatedDirs.contains(Path)) {
- if (std::error_code Err = llvm::sys::fs::create_directories(Path);
- Err != std::error_code()) {
- return llvm::createStringError(Err, "Failed to create directory '%s'.",
- Path.c_str());
- }
- CreatedDirs.insert(Path);
- }
+ if (Error Err = setupTemplate(RecordTemplate, ClassFilePath, Partials))
+ return Err;
- llvm::sys::path::append(Path, Info->getFileBaseName() + ".html");
- FileToInfos[Path].push_back(Info);
- }
+ return Error::success();
+}
- for (const auto &Group : FileToInfos) {
- std::error_code FileErr;
- llvm::raw_fd_ostream InfoOS(Group.getKey(), FileErr,
- llvm::sys::fs::OF_Text);
- if (FileErr) {
- return llvm::createStringError(FileErr, "Error opening file '%s'",
- Group.getKey().str().c_str());
- }
+Error HTMLGenerator::setupTemplateResources(const ClangDocContext &CDCtx,
+ json::Value &V,
+ SmallString<128> RelativeRootPath) {
+ V.getAsObject()->insert({"ProjectName", CDCtx.ProjectName});
+ json::Value StylesheetArr = Array();
+ sys::path::native(RelativeRootPath, sys::path::Style::posix);
- // TODO: https://github.com/llvm/llvm-project/issues/59073
- // If there are multiple Infos for this file name (for example, template
- // specializations), this will generate multiple complete web pages (with
- // <DOCTYPE> and <title>, etc.) concatenated together. This generator needs
- // some refactoring to be able to output the headers separately from the
- // contents.
- for (const auto &Info : Group.getValue()) {
- if (llvm::Error Err = generateDocForInfo(Info, InfoOS, CDCtx)) {
- return Err;
- }
- }
+ auto *SSA = StylesheetArr.getAsArray();
+ SSA->reserve(CDCtx.UserStylesheets.size());
+ for (const auto &FilePath : CDCtx.UserStylesheets) {
+ SmallString<128> StylesheetPath = RelativeRootPath;
+ sys::path::append(StylesheetPath, sys::path::Style::posix,
+ sys::path::filename(FilePath));
+ SSA->emplace_back(StylesheetPath);
+ }
+ V.getAsObject()->insert({"Stylesheets", StylesheetArr});
+
+ json::Value ScriptArr = Array();
+ auto *SCA = ScriptArr.getAsArray();
+ SCA->reserve(CDCtx.JsScripts.size());
+ for (auto Script : CDCtx.JsScripts) {
+ SmallString<128> JsPath = RelativeRootPath;
+ sys::path::append(JsPath, sys::path::Style::posix,
+ sys::path::filename(Script));
+ SCA->emplace_back(JsPath);
+ }
+ V.getAsObject()->insert({"Scripts", ScriptArr});
+ return Error::success();
+}
+
+Error HTMLGenerator::generateDocForJSON(json::Value &JSON, raw_fd_ostream &OS,
+ const ClangDocContext &CDCtx,
+ StringRef ObjTypeStr,
+ StringRef RelativeRootPath) {
+ if (ObjTypeStr == "namespace") {
+ if (auto Err = setupTemplateResources(CDCtx, JSON, RelativeRootPath))
+ return Err;
+ assert(NamespaceTemplate && "NamespaceTemplate is nullptr.");
+ NamespaceTemplate->render(JSON, OS);
+ } else if (ObjTypeStr == "record") {
+ if (auto Err = setupTemplateResources(CDCtx, JSON, RelativeRootPath))
+ return Err;
+ assert(RecordTemplate && "RecordTemplate is nullptr.");
+ RecordTemplate->render(JSON, OS);
}
-
- return llvm::Error::success();
+ return Error::success();
}
-llvm::Error HTMLGenerator::generateDocForInfo(Info *I, llvm::raw_ostream &OS,
- const ClangDocContext &CDCtx) {
- std::string InfoTitle;
- std::vector<std::unique_ptr<TagNode>> MainContentNodes;
- Index InfoIndex;
+Error HTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
+ const ClangDocContext &CDCtx) {
switch (I->IT) {
- case InfoType::IT_namespace:
- MainContentNodes = genHTML(*static_cast<clang::doc::NamespaceInfo *>(I),
- InfoIndex, CDCtx, InfoTitle);
- break;
- case InfoType::IT_record:
- MainContentNodes = genHTML(*static_cast<clang::doc::RecordInfo *>(I),
- InfoIndex, CDCtx, InfoTitle);
- break;
case InfoType::IT_enum:
- MainContentNodes = genHTML(*static_cast<clang::doc::EnumInfo *>(I), CDCtx);
- break;
case InfoType::IT_function:
- MainContentNodes =
- genHTML(*static_cast<clang::doc::FunctionInfo *>(I), CDCtx, "");
- break;
case InfoType::IT_typedef:
- MainContentNodes =
- genHTML(*static_cast<clang::doc::TypedefInfo *>(I), CDCtx, InfoTitle);
- break;
- case InfoType::IT_concept:
- case InfoType::IT_variable:
- case InfoType::IT_friend:
- break;
- case InfoType::IT_default:
- return llvm::createStringError(llvm::inconvertibleErrorCode(),
- "unexpected info type");
- }
-
- HTMLFile F = genInfoFile(InfoTitle, I->getRelativeFilePath(""),
- MainContentNodes, InfoIndex, CDCtx);
- F.render(OS);
-
- return llvm::Error::success();
-}
-
-static std::string getRefType(InfoType IT) {
- switch (IT) {
- case InfoType::IT_default:
- return "default";
case InfoType::IT_namespace:
- return "namespace";
case InfoType::IT_record:
- return "record";
- case InfoType::IT_function:
- return "function";
- case InfoType::IT_enum:
- return "enum";
- case InfoType::IT_typedef:
- return "typedef";
case InfoType::IT_concept:
- return "concept";
case InfoType::IT_variable:
- return "variable";
case InfoType::IT_friend:
- return "friend";
- }
- llvm_unreachable("Unknown InfoType");
-}
-
-static llvm::Error serializeIndex(ClangDocContext &CDCtx) {
- std::error_code OK;
- std::error_code FileErr;
- llvm::SmallString<128> FilePath;
- llvm::sys::path::native(CDCtx.OutDirectory, FilePath);
- llvm::sys::path::append(FilePath, "index_json.js");
- llvm::raw_fd_ostream OS(FilePath, FileErr, llvm::sys::fs::OF_Text);
- if (FileErr != OK) {
- return llvm::createStringError(llvm::inconvertibleErrorCode(),
- "error creating index file: " +
- FileErr.message());
- }
- llvm::SmallString<128> RootPath(CDCtx.OutDirectory);
- if (llvm::sys::path::is_relative(RootPath)) {
- llvm::sys::fs::make_absolute(RootPath);
+ break;
+ case InfoType::IT_default:
+ return createStringError(inconvertibleErrorCode(), "unexpected InfoType");
}
- // Replace the escaped characters with a forward slash. It shouldn't matter
- // when rendering the webpage in a web browser. This helps to prevent the
- // JavaScript from escaping characters incorrectly, and introducing bad paths
- // in the URLs.
- std::string RootPathEscaped = RootPath.str().str();
- llvm::replace(RootPathEscaped, '\\', '/');
- OS << "var RootPath = \"" << RootPathEscaped << "\";\n";
-
- llvm::SmallString<128> Base(CDCtx.Base);
- std::string BaseEscaped = Base.str().str();
- llvm::replace(BaseEscaped, '\\', '/');
- OS << "var Base = \"" << BaseEscaped << "\";\n";
-
- CDCtx.Idx.sort();
- llvm::json::OStream J(OS, 2);
- std::function<void(Index)> IndexToJSON = [&](const Index &I) {
- J.object([&] {
- J.attribute("USR", toHex(llvm::toStringRef(I.USR)));
- J.attribute("Name", I.Name);
- J.attribute("RefType", getRefType(I.RefType));
- J.attribute("Path", I.getRelativeFilePath(""));
- J.attributeArray("Children", [&] {
- for (const Index &C : I.Children)
- IndexToJSON(C);
- });
- });
- };
- OS << "async function LoadIndex() {\nreturn";
- IndexToJSON(CDCtx.Idx);
- OS << ";\n}";
- return llvm::Error::success();
+ return Error::success();
}
-// Generates a main HTML node that has the main content of the file that shows
-// only the general index
-// It contains the general index with links to all the generated files
-static std::unique_ptr<TagNode> genIndexFileMainNode() {
- auto MainNode = std::make_unique<TagNode>(HTMLTag::TAG_MAIN);
-
- auto LeftSidebarNode = std::make_unique<TagNode>(HTMLTag::TAG_DIV);
- LeftSidebarNode->Attributes.emplace_back("id", "sidebar-left");
- LeftSidebarNode->Attributes.emplace_back("path", "");
- LeftSidebarNode->Attributes.emplace_back(
- "class", "col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas-left");
- LeftSidebarNode->Attributes.emplace_back("style", "flex: 0 100%;");
-
- MainNode->Children.emplace_back(std::move(LeftSidebarNode));
-
- return MainNode;
+Error HTMLGenerator::createResources(ClangDocContext &CDCtx) {
+ std::string ResourcePath(CDCtx.OutDirectory + "/html");
+ for (const auto &FilePath : CDCtx.UserStylesheets)
+ if (Error Err = copyFile(FilePath, ResourcePath))
+ return Err;
+ for (const auto &FilePath : CDCtx.JsScripts)
+ if (Error Err = copyFile(FilePath, ResourcePath))
+ return Err;
+ return Error::success();
}
-static llvm::Error genIndex(const ClangDocContext &CDCtx) {
- std::error_code FileErr, OK;
- llvm::SmallString<128> IndexPath;
- llvm::sys::path::native(CDCtx.OutDirectory, IndexPath);
- llvm::sys::path::append(IndexPath, "index.html");
- llvm::raw_fd_ostream IndexOS(IndexPath, FileErr, llvm::sys::fs::OF_Text);
- if (FileErr != OK) {
- return llvm::createStringError(llvm::inconvertibleErrorCode(),
- "error creating main index: " +
- FileErr.message());
- }
-
- HTMLFile F;
-
- std::vector<std::unique_ptr<TagNode>> HeadNodes =
- genFileHeadNodes("Index", "", CDCtx);
- std::unique_ptr<TagNode> HeaderNode = genFileHeaderNode(CDCtx.ProjectName);
- std::unique_ptr<TagNode> MainNode = genIndexFileMainNode();
- std::unique_ptr<TagNode> FooterNode = genFileFooterNode();
-
- appendVector(std::move(HeadNodes), F.Children);
- F.Children.emplace_back(std::move(HeaderNode));
- F.Children.emplace_back(std::move(MainNode));
- F.Children.emplace_back(std::move(FooterNode));
-
- F.render(IndexOS);
-
- return llvm::Error::success();
+Error HTMLGenerator::generateDocumentation(
+ StringRef RootDir, llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
+ const ClangDocContext &CDCtx, std::string DirName) {
+ return MustacheGenerator::generateDocumentation(RootDir, std::move(Infos),
+ CDCtx, "html");
}
-llvm::Error HTMLGenerator::createResources(ClangDocContext &CDCtx) {
- auto Err = serializeIndex(CDCtx);
- if (Err)
- return Err;
- Err = genIndex(CDCtx);
- if (Err)
- return Err;
-
- for (const auto &FilePath : CDCtx.UserStylesheets) {
- Err = copyFile(FilePath, CDCtx.OutDirectory);
- if (Err)
- return Err;
- }
- for (const auto &FilePath : CDCtx.JsScripts) {
- Err = copyFile(FilePath, CDCtx.OutDirectory);
- if (Err)
- return Err;
- }
- return llvm::Error::success();
-}
+const char *HTMLGenerator::Format = "html";
-static GeneratorRegistry::Add<HTMLGenerator> HTML(HTMLGenerator::Format,
- "Generator for HTML output.");
+static GeneratorRegistry::Add<HTMLGenerator>
+ HTML(HTMLGenerator::Format, "Generator for mustache HTML output.");
// This anchor is used to force the linker to link in the generated object
// file and thus register the generator.
diff --git a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
deleted file mode 100644
index b4b9322..0000000
--- a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
+++ /dev/null
@@ -1,305 +0,0 @@
-///===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-///
-/// \file
-/// This file contains the implementation of the MustacheHTMLGenerator class,
-/// which is Clang-Doc generator for HTML using Mustache templates.
-///
-//===----------------------------------------------------------------------===//
-
-#include "Generators.h"
-#include "Representation.h"
-#include "support/File.h"
-#include "llvm/Support/Error.h"
-#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/Mustache.h"
-#include "llvm/Support/Path.h"
-#include "llvm/Support/TimeProfiler.h"
-
-using namespace llvm;
-using namespace llvm::json;
-using namespace llvm::mustache;
-
-namespace clang {
-namespace doc {
-static Error generateDocForJSON(json::Value &JSON, StringRef Filename,
- StringRef Path, raw_fd_ostream &OS,
- const ClangDocContext &CDCtx);
-
-static Error createFileOpenError(StringRef FileName, std::error_code EC) {
- return createFileError("cannot open file " + FileName, EC);
-}
-
-class MustacheHTMLGenerator : public Generator {
-public:
- static const char *Format;
- Error generateDocs(StringRef RootDir,
- StringMap<std::unique_ptr<doc::Info>> Infos,
- const ClangDocContext &CDCtx) override;
- Error createResources(ClangDocContext &CDCtx) override;
- Error generateDocForInfo(Info *I, raw_ostream &OS,
- const ClangDocContext &CDCtx) override;
-};
-
-class MustacheTemplateFile {
- BumpPtrAllocator Allocator;
- StringSaver Saver;
- MustacheContext Ctx;
- Template T;
- std::unique_ptr<MemoryBuffer> Buffer;
-
-public:
- static Expected<std::unique_ptr<MustacheTemplateFile>>
- createMustacheFile(StringRef FileName) {
- ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrError =
- MemoryBuffer::getFile(FileName);
- if (auto EC = BufferOrError.getError())
- return createFileOpenError(FileName, EC);
- return std::make_unique<MustacheTemplateFile>(
- std::move(BufferOrError.get()));
- }
-
- Error registerPartialFile(StringRef Name, StringRef FileName) {
- ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrError =
- MemoryBuffer::getFile(FileName);
- if (auto EC = BufferOrError.getError())
- return createFileOpenError(FileName, EC);
-
- std::unique_ptr<MemoryBuffer> Buffer = std::move(BufferOrError.get());
- StringRef FileContent = Buffer->getBuffer();
- T.registerPartial(Name.str(), FileContent.str());
- return Error::success();
- }
-
- void render(json::Value &V, raw_ostream &OS) { T.render(V, OS); }
-
- MustacheTemplateFile(std::unique_ptr<MemoryBuffer> &&B)
- : Saver(Allocator), Ctx(Allocator, Saver), T(B->getBuffer(), Ctx),
- Buffer(std::move(B)) {}
-};
-
-static std::unique_ptr<MustacheTemplateFile> NamespaceTemplate = nullptr;
-
-static std::unique_ptr<MustacheTemplateFile> RecordTemplate = nullptr;
-
-static Error
-setupTemplate(std::unique_ptr<MustacheTemplateFile> &Template,
- StringRef TemplatePath,
- std::vector<std::pair<StringRef, StringRef>> Partials) {
- auto T = MustacheTemplateFile::createMustacheFile(TemplatePath);
- if (Error Err = T.takeError())
- return Err;
- Template = std::move(T.get());
- for (const auto &[Name, FileName] : Partials)
- if (auto Err = Template->registerPartialFile(Name, FileName))
- return Err;
- return Error::success();
-}
-
-static Error setupTemplateFiles(const clang::doc::ClangDocContext &CDCtx) {
- // Template files need to use the native path when they're opened,
- // but have to be used in POSIX style when used in HTML.
- auto ConvertToNative = [](std::string &&Path) -> std::string {
- SmallString<128> PathBuf(Path);
- llvm::sys::path::native(PathBuf);
- return PathBuf.str().str();
- };
-
- std::string NamespaceFilePath =
- ConvertToNative(CDCtx.MustacheTemplates.lookup("namespace-template"));
- std::string ClassFilePath =
- ConvertToNative(CDCtx.MustacheTemplates.lookup("class-template"));
- std::string CommentFilePath =
- ConvertToNative(CDCtx.MustacheTemplates.lookup("comment-template"));
- std::string FunctionFilePath =
- ConvertToNative(CDCtx.MustacheTemplates.lookup("function-template"));
- std::string EnumFilePath =
- ConvertToNative(CDCtx.MustacheTemplates.lookup("enum-template"));
- std::vector<std::pair<StringRef, StringRef>> Partials = {
- {"Comments", CommentFilePath},
- {"FunctionPartial", FunctionFilePath},
- {"EnumPartial", EnumFilePath}};
-
- if (Error Err = setupTemplate(NamespaceTemplate, NamespaceFilePath, Partials))
- return Err;
-
- if (Error Err = setupTemplate(RecordTemplate, ClassFilePath, Partials))
- return Err;
-
- return Error::success();
-}
-
-Error MustacheHTMLGenerator::generateDocs(
- StringRef RootDir, StringMap<std::unique_ptr<doc::Info>> Infos,
- const clang::doc::ClangDocContext &CDCtx) {
- {
- llvm::TimeTraceScope TS("Setup Templates");
- if (auto Err = setupTemplateFiles(CDCtx))
- return Err;
- }
-
- {
- llvm::TimeTraceScope TS("Generate JSON for Mustache");
- if (auto JSONGenerator = findGeneratorByName("json")) {
- if (Error Err = JSONGenerator.get()->generateDocs(
- RootDir, std::move(Infos), CDCtx))
- return Err;
- } else
- return JSONGenerator.takeError();
- }
- SmallString<128> JSONPath;
- sys::path::native(RootDir.str() + "/json", JSONPath);
-
- StringMap<json::Value> JSONFileMap;
- {
- llvm::TimeTraceScope TS("Iterate JSON files");
- std::error_code EC;
- sys::fs::directory_iterator JSONIter(JSONPath, EC);
- std::vector<json::Value> JSONFiles;
- JSONFiles.reserve(Infos.size());
- if (EC)
- return createStringError("Failed to create directory iterator.");
-
- SmallString<128> HTMLDirPath(RootDir.str() + "/html/");
- if (auto EC = sys::fs::create_directories(HTMLDirPath))
- return createFileError(HTMLDirPath, EC);
- while (JSONIter != sys::fs::directory_iterator()) {
- if (EC)
- return createFileError("Failed to iterate: " + JSONIter->path(), EC);
-
- auto Path = StringRef(JSONIter->path());
- if (!Path.ends_with(".json")) {
- JSONIter.increment(EC);
- continue;
- }
-
- auto File = MemoryBuffer::getFile(Path);
- if (EC = File.getError(); EC)
- // TODO: Buffer errors to report later, look into using Clang
- // diagnostics.
- llvm::errs() << "Failed to open file: " << Path << " " << EC.message()
- << '\n';
-
- auto Parsed = json::parse((*File)->getBuffer());
- if (!Parsed)
- return Parsed.takeError();
-
- std::error_code FileErr;
- SmallString<128> HTMLFilePath(HTMLDirPath);
- sys::path::append(HTMLFilePath, sys::path::filename(Path));
- sys::path::replace_extension(HTMLFilePath, "html");
- raw_fd_ostream InfoOS(HTMLFilePath, FileErr, sys::fs::OF_None);
- if (FileErr)
- return createFileOpenError(Path, FileErr);
-
- if (Error Err = generateDocForJSON(*Parsed, sys::path::stem(HTMLFilePath),
- HTMLFilePath, InfoOS, CDCtx))
- return Err;
- JSONIter.increment(EC);
- }
- }
-
- return Error::success();
-}
-
-static Error setupTemplateValue(const ClangDocContext &CDCtx, json::Value &V) {
- V.getAsObject()->insert({"ProjectName", CDCtx.ProjectName});
- json::Value StylesheetArr = Array();
- SmallString<128> RelativePath("./");
- sys::path::native(RelativePath, sys::path::Style::posix);
-
- auto *SSA = StylesheetArr.getAsArray();
- SSA->reserve(CDCtx.UserStylesheets.size());
- for (const auto &FilePath : CDCtx.UserStylesheets) {
- SmallString<128> StylesheetPath = RelativePath;
- sys::path::append(StylesheetPath, sys::path::Style::posix,
- sys::path::filename(FilePath));
- SSA->emplace_back(StylesheetPath);
- }
- V.getAsObject()->insert({"Stylesheets", StylesheetArr});
-
- json::Value ScriptArr = Array();
- auto *SCA = ScriptArr.getAsArray();
- SCA->reserve(CDCtx.JsScripts.size());
- for (auto Script : CDCtx.JsScripts) {
- SmallString<128> JsPath = RelativePath;
- sys::path::append(JsPath, sys::path::Style::posix,
- sys::path::filename(Script));
- SCA->emplace_back(JsPath);
- }
- V.getAsObject()->insert({"Scripts", ScriptArr});
- return Error::success();
-}
-
-static Error generateDocForJSON(json::Value &JSON, StringRef Filename,
- StringRef Path, raw_fd_ostream &OS,
- const ClangDocContext &CDCtx) {
- auto StrValue = (*JSON.getAsObject())["InfoType"];
- if (StrValue.kind() != json::Value::Kind::String)
- return createStringError("JSON file '%s' does not contain key: 'InfoType'.",
- Filename.str().c_str());
- auto ObjTypeStr = StrValue.getAsString();
- if (!ObjTypeStr.has_value())
- return createStringError(
- "JSON file '%s' does not contain 'InfoType' field as a string.",
- Filename.str().c_str());
-
- if (ObjTypeStr.value() == "namespace") {
- if (auto Err = setupTemplateValue(CDCtx, JSON))
- return Err;
- assert(NamespaceTemplate && "NamespaceTemplate is nullptr.");
- NamespaceTemplate->render(JSON, OS);
- } else if (ObjTypeStr.value() == "record") {
- if (auto Err = setupTemplateValue(CDCtx, JSON))
- return Err;
- assert(RecordTemplate && "RecordTemplate is nullptr.");
- RecordTemplate->render(JSON, OS);
- }
- return Error::success();
-}
-
-Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
- const ClangDocContext &CDCtx) {
- switch (I->IT) {
- case InfoType::IT_enum:
- case InfoType::IT_function:
- case InfoType::IT_typedef:
- case InfoType::IT_namespace:
- case InfoType::IT_record:
- case InfoType::IT_concept:
- case InfoType::IT_variable:
- case InfoType::IT_friend:
- break;
- case InfoType::IT_default:
- return createStringError(inconvertibleErrorCode(), "unexpected InfoType");
- }
- return Error::success();
-}
-
-Error MustacheHTMLGenerator::createResources(ClangDocContext &CDCtx) {
- std::string ResourcePath(CDCtx.OutDirectory + "/html");
- for (const auto &FilePath : CDCtx.UserStylesheets)
- if (Error Err = copyFile(FilePath, ResourcePath))
- return Err;
- for (const auto &FilePath : CDCtx.JsScripts)
- if (Error Err = copyFile(FilePath, ResourcePath))
- return Err;
- return Error::success();
-}
-
-const char *MustacheHTMLGenerator::Format = "mustache";
-
-static GeneratorRegistry::Add<MustacheHTMLGenerator>
- MHTML(MustacheHTMLGenerator::Format, "Generator for mustache HTML output.");
-
-// This anchor is used to force the linker to link in the generated object
-// file and thus register the generator.
-volatile int MHTMLGeneratorAnchorSource = 0;
-
-} // namespace doc
-} // namespace clang
diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp
index b17cc80..77aa879 100644
--- a/clang-tools-extra/clang-doc/JSONGenerator.cpp
+++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp
@@ -12,9 +12,10 @@ class JSONGenerator : public Generator {
public:
static const char *Format;
- Error generateDocs(StringRef RootDir,
- llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
- const ClangDocContext &CDCtx) override;
+ Error generateDocumentation(StringRef RootDir,
+ llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
+ const ClangDocContext &CDCtx,
+ std::string DirName) override;
Error createResources(ClangDocContext &CDCtx) override;
Error generateDocForInfo(Info *I, llvm::raw_ostream &OS,
const ClangDocContext &CDCtx) override;
@@ -83,8 +84,23 @@ serializeLocation(const Location &Loc,
return LocationObj;
}
+/// Insert comments into a key in the Description object.
+///
+/// \param Comment Either an Object or Array, depending on the comment type
+/// \param Key The type (Brief, Code, etc.) of comment to be inserted
static void insertComment(Object &Description, json::Value &Comment,
StringRef Key) {
+ // The comment has a Children array for the actual text, with meta attributes
+ // alongside it in the Object.
+ if (auto *Obj = Comment.getAsObject()) {
+ if (auto *Children = Obj->getArray("Children"); Children->empty())
+ return;
+ }
+ // The comment is just an array of text comments.
+ else if (auto *Array = Comment.getAsArray(); Array->empty()) {
+ return;
+ }
+
auto DescriptionIt = Description.find(Key);
if (DescriptionIt == Description.end()) {
@@ -97,10 +113,28 @@ static void insertComment(Object &Description, json::Value &Comment,
}
}
+/// Takes the nested "Children" array from a comment Object.
+///
+/// \return a json::Array of comments, possible json::Value::Kind::Null
static json::Value extractTextComments(Object *ParagraphComment) {
if (!ParagraphComment)
- return json::Object();
- return *ParagraphComment->get("Children");
+ return json::Value(nullptr);
+ json::Value *Children = ParagraphComment->get("Children");
+ if (!Children)
+ return json::Value(nullptr);
+ auto ChildrenArray = *Children->getAsArray();
+ auto ChildrenIt = ChildrenArray.begin();
+ while (ChildrenIt != ChildrenArray.end()) {
+ auto *ChildObj = ChildrenIt->getAsObject();
+ assert(ChildObj && "Invalid JSON object in Comment");
+ auto TextComment = ChildObj->getString("TextComment");
+ if (!TextComment || TextComment->empty()) {
+ ChildrenIt = ChildrenArray.erase(ChildrenIt);
+ continue;
+ }
+ ++ChildrenIt;
+ }
+ return ChildrenArray;
}
static json::Value extractVerbatimComments(json::Array VerbatimLines) {
@@ -130,7 +164,8 @@ static Object serializeComment(const CommentInfo &I, Object &Description) {
switch (I.Kind) {
case CommentKind::CK_TextComment: {
- Obj.insert({commentKindToString(I.Kind), I.Text});
+ if (!I.Text.empty())
+ Obj.insert({commentKindToString(I.Kind), I.Text});
return Obj;
}
@@ -140,6 +175,13 @@ static Object serializeComment(const CommentInfo &I, Object &Description) {
insertComment(Description, TextCommentsArray, "BriefComments");
else if (I.Name == "return")
insertComment(Description, TextCommentsArray, "ReturnComments");
+ else if (I.Name == "throws" || I.Name == "throw") {
+ json::Value ThrowsVal = Object();
+ auto &ThrowsObj = *ThrowsVal.getAsObject();
+ ThrowsObj["Exception"] = I.Args.front();
+ ThrowsObj["Children"] = TextCommentsArray;
+ insertComment(Description, ThrowsVal, "ThrowsComments");
+ }
return Obj;
}
@@ -257,6 +299,9 @@ serializeCommonAttributes(const Info &I, json::Object &Obj,
if (auto *ParagraphComment = Comment.getAsObject();
ParagraphComment->get("ParagraphComment")) {
auto TextCommentsArray = extractTextComments(ParagraphComment);
+ if (TextCommentsArray.kind() == json::Value::Null ||
+ TextCommentsArray.getAsArray()->empty())
+ continue;
insertComment(Description, TextCommentsArray, "ParagraphComments");
}
}
@@ -468,7 +513,6 @@ static void insertArray(Object &Obj, json::Value &Array, StringRef Key) {
static void serializeInfo(const RecordInfo &I, json::Object &Obj,
const std::optional<StringRef> &RepositoryUrl) {
serializeCommonAttributes(I, Obj, RepositoryUrl);
- Obj["FullName"] = I.FullName;
Obj["TagType"] = getTagType(I.TagType);
Obj["IsTypedef"] = I.IsTypeDef;
Obj["MangledName"] = I.MangledName;
@@ -582,25 +626,17 @@ static SmallString<16> determineFileName(Info *I, SmallString<128> &Path) {
if (I->IT == InfoType::IT_record) {
auto *RecordSymbolInfo = static_cast<SymbolInfo *>(I);
FileName = RecordSymbolInfo->MangledName;
- } else if (I->USR == GlobalNamespaceID)
+ } else if (I->IT == InfoType::IT_namespace) {
FileName = "index";
- else if (I->IT == InfoType::IT_namespace) {
- for (const auto &NS : I->Namespace) {
- FileName += NS.Name;
- FileName += "_";
- }
- FileName += I->Name;
} else
FileName = I->Name;
sys::path::append(Path, FileName + ".json");
return FileName;
}
-// FIXME: Revert back to creating nested directories for namespaces instead of
-// putting everything in a flat directory structure.
-Error JSONGenerator::generateDocs(
+Error JSONGenerator::generateDocumentation(
StringRef RootDir, llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
- const ClangDocContext &CDCtx) {
+ const ClangDocContext &CDCtx, std::string DirName) {
StringSet<> CreatedDirs;
StringMap<std::vector<doc::Info *>> FileToInfos;
for (const auto &Group : Infos) {
@@ -610,6 +646,7 @@ Error JSONGenerator::generateDocs(
auto RootDirStr = RootDir.str() + "/json";
StringRef JSONDir = StringRef(RootDirStr);
sys::path::native(JSONDir, Path);
+ sys::path::append(Path, Info->getRelativeFilePath(""));
if (!CreatedDirs.contains(Path)) {
if (std::error_code Err = sys::fs::create_directories(Path);
Err != std::error_code())
diff --git a/clang-tools-extra/clang-doc/MDGenerator.cpp b/clang-tools-extra/clang-doc/MDGenerator.cpp
index 6f16f5b..fcb75af 100644
--- a/clang-tools-extra/clang-doc/MDGenerator.cpp
+++ b/clang-tools-extra/clang-doc/MDGenerator.cpp
@@ -398,9 +398,9 @@ class MDGenerator : public Generator {
public:
static const char *Format;
- llvm::Error generateDocs(StringRef RootDir,
- llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
- const ClangDocContext &CDCtx) override;
+ llvm::Error generateDocumentation(
+ StringRef RootDir, llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
+ const ClangDocContext &CDCtx, std::string DirName) override;
llvm::Error createResources(ClangDocContext &CDCtx) override;
llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream &OS,
const ClangDocContext &CDCtx) override;
@@ -408,10 +408,9 @@ public:
const char *MDGenerator::Format = "md";
-llvm::Error
-MDGenerator::generateDocs(StringRef RootDir,
- llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
- const ClangDocContext &CDCtx) {
+llvm::Error MDGenerator::generateDocumentation(
+ StringRef RootDir, llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
+ const ClangDocContext &CDCtx, std::string DirName) {
// Track which directories we already tried to create.
llvm::StringSet<> CreatedDirs;
diff --git a/clang-tools-extra/clang-doc/Mapper.cpp b/clang-tools-extra/clang-doc/Mapper.cpp
index 497b80c..24e798a 100644
--- a/clang-tools-extra/clang-doc/Mapper.cpp
+++ b/clang-tools-extra/clang-doc/Mapper.cpp
@@ -95,10 +95,10 @@ bool MapASTVisitor::mapDecl(const T *D, bool IsDefinition) {
// this decl for some reason (e.g. we're only reporting public decls).
if (Child)
CDCtx.ECtx->reportResult(llvm::toHex(llvm::toStringRef(Child->USR)),
- serialize::serialize(Child));
+ serialize::serialize(Child, CDCtx.Diags));
if (Parent)
CDCtx.ECtx->reportResult(llvm::toHex(llvm::toStringRef(Parent->USR)),
- serialize::serialize(Parent));
+ serialize::serialize(Parent, CDCtx.Diags));
}
return true;
}
diff --git a/clang-tools-extra/clang-doc/Mapper.h b/clang-tools-extra/clang-doc/Mapper.h
index 322df6d..91e9668 100644
--- a/clang-tools-extra/clang-doc/Mapper.h
+++ b/clang-tools-extra/clang-doc/Mapper.h
@@ -19,7 +19,6 @@
#include "Representation.h"
#include "clang/AST/RecursiveASTVisitor.h"
-#include "clang/Tooling/Execution.h"
using namespace clang::comments;
using namespace clang::tooling;
diff --git a/clang-tools-extra/clang-doc/Representation.cpp b/clang-tools-extra/clang-doc/Representation.cpp
index 929112f..8eab5fb 100644
--- a/clang-tools-extra/clang-doc/Representation.cpp
+++ b/clang-tools-extra/clang-doc/Representation.cpp
@@ -82,12 +82,10 @@ llvm::StringRef commentKindToString(CommentKind Kind) {
llvm_unreachable("Unhandled CommentKind");
}
-namespace {
-
const SymbolID EmptySID = SymbolID();
template <typename T>
-llvm::Expected<std::unique_ptr<Info>>
+static llvm::Expected<std::unique_ptr<Info>>
reduce(std::vector<std::unique_ptr<Info>> &Values) {
if (Values.empty() || !Values[0])
return llvm::createStringError(llvm::inconvertibleErrorCode(),
@@ -102,7 +100,7 @@ reduce(std::vector<std::unique_ptr<Info>> &Values) {
// Return the index of the matching child in the vector, or -1 if merge is not
// necessary.
template <typename T>
-int getChildIndexIfExists(std::vector<T> &Children, T &ChildToMerge) {
+static int getChildIndexIfExists(std::vector<T> &Children, T &ChildToMerge) {
for (unsigned long I = 0; I < Children.size(); I++) {
if (ChildToMerge.USR == Children[I].USR)
return I;
@@ -111,8 +109,8 @@ int getChildIndexIfExists(std::vector<T> &Children, T &ChildToMerge) {
}
template <typename T>
-void reduceChildren(std::vector<T> &Children,
- std::vector<T> &&ChildrenToMerge) {
+static void reduceChildren(std::vector<T> &Children,
+ std::vector<T> &&ChildrenToMerge) {
for (auto &ChildToMerge : ChildrenToMerge) {
int MergeIdx = getChildIndexIfExists(Children, ChildToMerge);
if (MergeIdx == -1) {
@@ -123,8 +121,6 @@ void reduceChildren(std::vector<T> &Children,
}
}
-} // namespace
-
// Dispatch function.
llvm::Expected<std::unique_ptr<Info>>
mergeInfos(std::vector<std::unique_ptr<Info>> &Values) {
@@ -402,7 +398,7 @@ BaseRecordInfo::BaseRecordInfo() : RecordInfo() {}
BaseRecordInfo::BaseRecordInfo(SymbolID USR, StringRef Name, StringRef Path,
bool IsVirtual, AccessSpecifier Access,
bool IsParent)
- : RecordInfo(USR, Name, Path), IsVirtual(IsVirtual), Access(Access),
+ : RecordInfo(USR, Name, Path), Access(Access), IsVirtual(IsVirtual),
IsParent(IsParent) {}
llvm::SmallString<16> Info::extractName() const {
@@ -481,10 +477,11 @@ ClangDocContext::ClangDocContext(tooling::ExecutionContext *ECtx,
StringRef RepositoryUrl,
StringRef RepositoryLinePrefix, StringRef Base,
std::vector<std::string> UserStylesheets,
+ clang::DiagnosticsEngine &Diags,
bool FTimeTrace)
- : ECtx(ECtx), ProjectName(ProjectName), PublicOnly(PublicOnly),
- FTimeTrace(FTimeTrace), OutDirectory(OutDirectory),
- UserStylesheets(UserStylesheets), Base(Base) {
+ : ECtx(ECtx), ProjectName(ProjectName), OutDirectory(OutDirectory),
+ SourceRoot(std::string(SourceRoot)), UserStylesheets(UserStylesheets),
+ Base(Base), Diags(Diags), PublicOnly(PublicOnly), FTimeTrace(FTimeTrace) {
llvm::SmallString<128> SourceRootDir(SourceRoot);
if (SourceRoot.empty())
// If no SourceRoot was provided the current path is used as the default
diff --git a/clang-tools-extra/clang-doc/Representation.h b/clang-tools-extra/clang-doc/Representation.h
index d8c2b9c..a3e779a 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -15,11 +15,10 @@
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_REPRESENTATION_H
#include "clang/AST/Type.h"
+#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/Specifiers.h"
-#include "clang/Tooling/StandaloneExecution.h"
-#include "llvm/ADT/APSInt.h"
+#include "clang/Tooling/Execution.h"
#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringExtras.h"
#include <array>
#include <optional>
#include <string>
@@ -87,29 +86,29 @@ struct CommentInfo {
// the vector.
bool operator<(const CommentInfo &Other) const;
- CommentKind Kind = CommentKind::
- CK_Unknown; // Kind of comment (FullComment, ParagraphComment,
- // TextComment, InlineCommandComment, HTMLStartTagComment,
- // HTMLEndTagComment, BlockCommandComment,
- // ParamCommandComment, TParamCommandComment,
- // VerbatimBlockComment, VerbatimBlockLineComment,
- // VerbatimLineComment).
- SmallString<64> Text; // Text of the comment.
- SmallString<16> Name; // Name of the comment (for Verbatim and HTML).
+ std::vector<std::unique_ptr<CommentInfo>>
+ Children; // List of child comments for this CommentInfo.
SmallString<8> Direction; // Parameter direction (for (T)ParamCommand).
+ SmallString<16> Name; // Name of the comment (for Verbatim and HTML).
SmallString<16> ParamName; // Parameter name (for (T)ParamCommand).
SmallString<16> CloseName; // Closing tag name (for VerbatimBlock).
- bool SelfClosing = false; // Indicates if tag is self-closing (for HTML).
- bool Explicit = false; // Indicates if the direction of a param is explicit
- // (for (T)ParamCommand).
+ SmallString<64> Text; // Text of the comment.
llvm::SmallVector<SmallString<16>, 4>
AttrKeys; // List of attribute keys (for HTML).
llvm::SmallVector<SmallString<16>, 4>
AttrValues; // List of attribute values for each key (for HTML).
llvm::SmallVector<SmallString<16>, 4>
Args; // List of arguments to commands (for InlineCommand).
- std::vector<std::unique_ptr<CommentInfo>>
- Children; // List of child comments for this CommentInfo.
+ CommentKind Kind = CommentKind::
+ CK_Unknown; // Kind of comment (FullComment, ParagraphComment,
+ // TextComment, InlineCommandComment, HTMLStartTagComment,
+ // HTMLEndTagComment, BlockCommandComment,
+ // ParamCommandComment, TParamCommandComment,
+ // VerbatimBlockComment, VerbatimBlockLineComment,
+ // VerbatimLineComment).
+ bool SelfClosing = false; // Indicates if tag is self-closing (for HTML).
+ bool Explicit = false; // Indicates if the direction of a param is explicit
+ // (for (T)ParamCommand).
};
struct Reference {
@@ -120,13 +119,13 @@ struct Reference {
// "GlobalNamespace" as the name, but an empty QualName).
Reference(SymbolID USR = SymbolID(), StringRef Name = StringRef(),
InfoType IT = InfoType::IT_default)
- : USR(USR), Name(Name), QualName(Name), RefType(IT) {}
+ : USR(USR), RefType(IT), Name(Name), QualName(Name) {}
Reference(SymbolID USR, StringRef Name, InfoType IT, StringRef QualName,
StringRef Path = StringRef())
- : USR(USR), Name(Name), QualName(QualName), RefType(IT), Path(Path) {}
+ : USR(USR), RefType(IT), Name(Name), QualName(QualName), Path(Path) {}
Reference(SymbolID USR, StringRef Name, InfoType IT, StringRef QualName,
StringRef Path, SmallString<16> DocumentationFileName)
- : USR(USR), Name(Name), QualName(QualName), RefType(IT), Path(Path),
+ : USR(USR), RefType(IT), Name(Name), QualName(QualName), Path(Path),
DocumentationFileName(DocumentationFileName) {}
bool operator==(const Reference &Other) const {
@@ -146,6 +145,10 @@ struct Reference {
SymbolID USR = SymbolID(); // Unique identifier for referenced decl
+ InfoType RefType = InfoType::IT_default; // Indicates the type of this
+ // Reference (namespace, record,
+ // function, enum, default).
+
// Name of type (possibly unresolved). Not including namespaces or template
// parameters (so for a std::vector<int> this would be "vector"). See also
// QualName.
@@ -156,9 +159,6 @@ struct Reference {
// Name.
SmallString<16> QualName;
- InfoType RefType = InfoType::IT_default; // Indicates the type of this
- // Reference (namespace, record,
- // function, enum, default).
// Path of directory where the clang-doc generated file will be saved
// (possibly unresolved)
llvm::SmallString<128> Path;
@@ -278,21 +278,21 @@ struct MemberTypeInfo : public FieldTypeInfo {
Other.Description);
}
+ std::vector<CommentInfo> Description;
+
// Access level associated with this info (public, protected, private, none).
// AS_public is set as default because the bitcode writer requires the enum
// with value 0 to be used as the default.
// (AS_public = 0, AS_protected = 1, AS_private = 2, AS_none = 3)
AccessSpecifier Access = AccessSpecifier::AS_public;
-
- std::vector<CommentInfo> Description; // Comment description of this field.
bool IsStatic = false;
};
struct Location {
Location(int StartLineNumber = 0, int EndLineNumber = 0,
StringRef Filename = StringRef(), bool IsFileInRootDir = false)
- : StartLineNumber(StartLineNumber), EndLineNumber(EndLineNumber),
- Filename(Filename), IsFileInRootDir(IsFileInRootDir) {}
+ : Filename(Filename), StartLineNumber(StartLineNumber),
+ EndLineNumber(EndLineNumber), IsFileInRootDir(IsFileInRootDir) {}
bool operator==(const Location &Other) const {
return std::tie(StartLineNumber, EndLineNumber, Filename) ==
@@ -310,40 +310,24 @@ struct Location {
std::tie(Other.StartLineNumber, Other.EndLineNumber, Other.Filename);
}
- int StartLineNumber = 0; // Line number of this Location.
+ SmallString<32> Filename;
+ int StartLineNumber = 0;
int EndLineNumber = 0;
- SmallString<32> Filename; // File for this Location.
- bool IsFileInRootDir = false; // Indicates if file is inside root directory
+ bool IsFileInRootDir = false;
};
/// A base struct for Infos.
struct Info {
Info(InfoType IT = InfoType::IT_default, SymbolID USR = SymbolID(),
StringRef Name = StringRef(), StringRef Path = StringRef())
- : USR(USR), IT(IT), Name(Name), Path(Path) {}
+ : Path(Path), Name(Name), USR(USR), IT(IT) {}
Info(const Info &Other) = delete;
Info(Info &&Other) = default;
-
virtual ~Info() = default;
Info &operator=(Info &&Other) = default;
- SymbolID USR =
- SymbolID(); // Unique identifier for the decl described by this Info.
- InfoType IT = InfoType::IT_default; // InfoType of this particular Info.
- SmallString<16> Name; // Unqualified name of the decl.
- llvm::SmallVector<Reference, 4>
- Namespace; // List of parent namespaces for this decl.
- std::vector<CommentInfo> Description; // Comment description of this decl.
- llvm::SmallString<128> Path; // Path of directory where the clang-doc
- // generated file will be saved
-
- // The name used for the file that this info is documented in.
- // In the JSON generator, infos are documented in files with mangled names.
- // Thus, we keep track of the physical filename for linking purposes.
- SmallString<16> DocumentationFileName;
-
void mergeBase(Info &&I);
bool mergeable(const Info &Other);
@@ -354,6 +338,29 @@ struct Info {
/// Returns the basename that should be used for this Info.
llvm::SmallString<16> getFileBaseName() const;
+
+ // Path of directory where the clang-doc generated file will be saved.
+ llvm::SmallString<128> Path;
+
+ // Unqualified name of the decl.
+ SmallString<16> Name;
+
+ // The name used for the file that this info is documented in.
+ // In the JSON generator, infos are documented in files with mangled names.
+ // Thus, we keep track of the physical filename for linking purposes.
+ SmallString<16> DocumentationFileName;
+
+ // List of parent namespaces for this decl.
+ llvm::SmallVector<Reference, 4> Namespace;
+
+ // Unique identifier for the decl described by this Info.
+ SymbolID USR = SymbolID();
+
+ // InfoType of this particular Info.
+ InfoType IT = InfoType::IT_default;
+
+ // Comment description of this decl.
+ std::vector<CommentInfo> Description;
};
// Info for namespaces.
@@ -427,25 +434,21 @@ struct FunctionInfo : public SymbolInfo {
void merge(FunctionInfo &&I);
- bool IsMethod = false; // Indicates whether this function is a class method.
- Reference Parent; // Reference to the parent class decl for this method.
- TypeInfo ReturnType; // Info about the return type of this function.
- llvm::SmallVector<FieldTypeInfo, 4> Params; // List of parameters.
+ Reference Parent;
+ TypeInfo ReturnType;
+ llvm::SmallVector<FieldTypeInfo, 4> Params;
+ SmallString<256> Prototype;
+
+ // When present, this function is a template or specialization.
+ std::optional<TemplateInfo> Template;
+
// Access level for this method (public, private, protected, none).
// AS_public is set as default because the bitcode writer requires the enum
// with value 0 to be used as the default.
// (AS_public = 0, AS_protected = 1, AS_private = 2, AS_none = 3)
AccessSpecifier Access = AccessSpecifier::AS_public;
- // Full qualified name of this function, including namespaces and template
- // specializations.
- SmallString<16> FullName;
-
- // Function Prototype
- SmallString<256> Prototype;
-
- // When present, this function is a template or specialization.
- std::optional<TemplateInfo> Template;
+ bool IsMethod = false;
};
// TODO: Expand to allow for documenting templating, inheritance access,
@@ -460,19 +463,15 @@ struct RecordInfo : public SymbolInfo {
// Type of this record (struct, class, union, interface).
TagTypeKind TagType = TagTypeKind::Struct;
- // Full qualified name of this record, including namespaces and template
- // specializations.
- SmallString<16> FullName;
-
- // When present, this record is a template or specialization.
- std::optional<TemplateInfo> Template;
-
// Indicates if the record was declared using a typedef. Things like anonymous
// structs in a typedef:
// typedef struct { ... } foo_t;
// are converted into records with the typedef as the Name + this flag set.
bool IsTypeDef = false;
+ // When present, this record is a template or specialization.
+ std::optional<TemplateInfo> Template;
+
llvm::SmallVector<MemberTypeInfo, 4>
Members; // List of info about record members.
llvm::SmallVector<Reference, 4> Parents; // List of base/parent records
@@ -517,11 +516,11 @@ struct BaseRecordInfo : public RecordInfo {
BaseRecordInfo(SymbolID USR, StringRef Name, StringRef Path, bool IsVirtual,
AccessSpecifier Access, bool IsParent);
- // Indicates if base corresponds to a virtual inheritance
- bool IsVirtual = false;
// Access level associated with this inherited info (public, protected,
// private).
AccessSpecifier Access = AccessSpecifier::AS_public;
+ // Indicates if base corresponds to a virtual inheritance
+ bool IsVirtual = false;
bool IsParent = false; // Indicates if this base is a direct parent
};
@@ -608,17 +607,13 @@ llvm::Expected<std::unique_ptr<Info>>
mergeInfos(std::vector<std::unique_ptr<Info>> &Values);
struct ClangDocContext {
- ClangDocContext() = default;
ClangDocContext(tooling::ExecutionContext *ECtx, StringRef ProjectName,
bool PublicOnly, StringRef OutDirectory, StringRef SourceRoot,
StringRef RepositoryUrl, StringRef RepositoryCodeLinePrefix,
StringRef Base, std::vector<std::string> UserStylesheets,
- bool FTimeTrace = false);
+ clang::DiagnosticsEngine &Diags, bool FTimeTrace = false);
tooling::ExecutionContext *ECtx;
- std::string ProjectName; // Name of project clang-doc is documenting.
- bool PublicOnly; // Indicates if only public declarations are documented.
- bool FTimeTrace; // Indicates if ftime trace is turned on
- int Granularity; // Granularity of ftime trace
+ std::string ProjectName; // Name of project clang-doc is documenting.
std::string OutDirectory; // Directory for outputting generated files.
std::string SourceRoot; // Directory where processed files are stored. Links
// to definition locations will only be generated if
@@ -637,7 +632,12 @@ struct ClangDocContext {
// Maps mustache template types to specific mustache template files.
// Ex. comment-template -> /path/to/comment-template.mustache
llvm::StringMap<std::string> MustacheTemplates;
+ // A pointer to a DiagnosticsEngine for error reporting.
+ clang::DiagnosticsEngine &Diags;
Index Idx;
+ int Granularity; // Granularity of ftime trace
+ bool PublicOnly; // Indicates if only public declarations are documented.
+ bool FTimeTrace; // Indicates if ftime trace is turned on
};
} // namespace doc
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp
index 186f634..29f8faf 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -11,7 +11,9 @@
#include "clang/AST/Attr.h"
#include "clang/AST/Comment.h"
+#include "clang/AST/CommentVisitor.h"
#include "clang/AST/DeclFriend.h"
+#include "clang/AST/ExprConcepts.h"
#include "clang/AST/Mangle.h"
#include "clang/Index/USRGeneration.h"
#include "clang/Lex/Lexer.h"
@@ -178,55 +180,6 @@ static llvm::SmallString<16> getTypeAlias(const TypeAliasDecl *Alias) {
return Result;
}
-// extract full syntax for record declaration
-static llvm::SmallString<16> getRecordPrototype(const CXXRecordDecl *CXXRD) {
- llvm::SmallString<16> Result;
- LangOptions LangOpts;
- PrintingPolicy Policy(LangOpts);
- Policy.SuppressTagKeyword = false;
- Policy.FullyQualifiedName = true;
- Policy.IncludeNewlines = false;
- llvm::raw_svector_ostream OS(Result);
- if (const auto *TD = CXXRD->getDescribedClassTemplate()) {
- OS << "template <";
- bool FirstParam = true;
- for (const auto *Param : *TD->getTemplateParameters()) {
- if (!FirstParam)
- OS << ", ";
- Param->print(OS, Policy);
- FirstParam = false;
- }
- OS << ">\n";
- }
-
- if (CXXRD->isStruct())
- OS << "struct ";
- else if (CXXRD->isClass())
- OS << "class ";
- else if (CXXRD->isUnion())
- OS << "union ";
-
- OS << CXXRD->getNameAsString();
-
- // We need to make sure we have a good enough declaration to check. In the
- // case where the class is a forward declaration, we'll fail assertions in
- // DeclCXX.
- if (CXXRD->isCompleteDefinition() && CXXRD->getNumBases() > 0) {
- OS << " : ";
- bool FirstBase = true;
- for (const auto &Base : CXXRD->bases()) {
- if (!FirstBase)
- OS << ", ";
- if (Base.isVirtual())
- OS << "virtual ";
- OS << getAccessSpelling(Base.getAccessSpecifier()) << " ";
- OS << Base.getType().getAsString(Policy);
- FirstBase = false;
- }
- }
- return Result;
-}
-
// A function to extract the appropriate relative path for a given info's
// documentation. The path returned is a composite of the parent namespaces.
//
@@ -384,28 +337,29 @@ static std::string getSourceCode(const Decl *D, const SourceRange &R) {
.str();
}
-template <typename T> static std::string serialize(T &I) {
+template <typename T>
+static std::string serialize(T &I, DiagnosticsEngine &Diags) {
SmallString<2048> Buffer;
llvm::BitstreamWriter Stream(Buffer);
- ClangDocBitcodeWriter Writer(Stream);
+ ClangDocBitcodeWriter Writer(Stream, Diags);
Writer.emitBlock(I);
return Buffer.str().str();
}
-std::string serialize(std::unique_ptr<Info> &I) {
+std::string serialize(std::unique_ptr<Info> &I, DiagnosticsEngine &Diags) {
switch (I->IT) {
case InfoType::IT_namespace:
- return serialize(*static_cast<NamespaceInfo *>(I.get()));
+ return serialize(*static_cast<NamespaceInfo *>(I.get()), Diags);
case InfoType::IT_record:
- return serialize(*static_cast<RecordInfo *>(I.get()));
+ return serialize(*static_cast<RecordInfo *>(I.get()), Diags);
case InfoType::IT_enum:
- return serialize(*static_cast<EnumInfo *>(I.get()));
+ return serialize(*static_cast<EnumInfo *>(I.get()), Diags);
case InfoType::IT_function:
- return serialize(*static_cast<FunctionInfo *>(I.get()));
+ return serialize(*static_cast<FunctionInfo *>(I.get()), Diags);
case InfoType::IT_concept:
- return serialize(*static_cast<ConceptInfo *>(I.get()));
+ return serialize(*static_cast<ConceptInfo *>(I.get()), Diags);
case InfoType::IT_variable:
- return serialize(*static_cast<VarInfo *>(I.get()));
+ return serialize(*static_cast<VarInfo *>(I.get()), Diags);
case InfoType::IT_friend:
case InfoType::IT_typedef:
case InfoType::IT_default:
@@ -1033,7 +987,6 @@ emitInfo(const RecordDecl *D, const FullComment *FC, Location Loc,
parseFields(*RI, D, PublicOnly);
if (const auto *C = dyn_cast<CXXRecordDecl>(D)) {
- RI->FullName = getRecordPrototype(C);
if (const TypedefNameDecl *TD = C->getTypedefNameForAnonDecl()) {
RI->Name = TD->getNameAsString();
RI->IsTypeDef = true;
diff --git a/clang-tools-extra/clang-doc/Serialize.h b/clang-tools-extra/clang-doc/Serialize.h
index 06c4d64..cfba5c9 100644
--- a/clang-tools-extra/clang-doc/Serialize.h
+++ b/clang-tools-extra/clang-doc/Serialize.h
@@ -16,10 +16,7 @@
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_SERIALIZE_H
#include "Representation.h"
-#include "clang/AST/AST.h"
-#include "clang/AST/CommentVisitor.h"
#include <string>
-#include <vector>
using namespace clang::comments;
@@ -83,7 +80,7 @@ emitInfo(const VarDecl *D, const FullComment *FC, const Location &Loc,
// memory (vs storing USRs directly).
SymbolID hashUSR(llvm::StringRef USR);
-std::string serialize(std::unique_ptr<Info> &I);
+std::string serialize(std::unique_ptr<Info> &I, DiagnosticsEngine &Diags);
} // namespace serialize
} // namespace doc
diff --git a/clang-tools-extra/clang-doc/YAMLGenerator.cpp b/clang-tools-extra/clang-doc/YAMLGenerator.cpp
index eeccdd8..ce4ef58 100644
--- a/clang-tools-extra/clang-doc/YAMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/YAMLGenerator.cpp
@@ -347,19 +347,18 @@ class YAMLGenerator : public Generator {
public:
static const char *Format;
- llvm::Error generateDocs(StringRef RootDir,
- llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
- const ClangDocContext &CDCtx) override;
+ llvm::Error generateDocumentation(
+ StringRef RootDir, llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
+ const ClangDocContext &CDCtx, std::string DirName) override;
llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream &OS,
const ClangDocContext &CDCtx) override;
};
const char *YAMLGenerator::Format = "yaml";
-llvm::Error
-YAMLGenerator::generateDocs(StringRef RootDir,
- llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
- const ClangDocContext &CDCtx) {
+llvm::Error YAMLGenerator::generateDocumentation(
+ StringRef RootDir, llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
+ const ClangDocContext &CDCtx, std::string DirName) {
for (const auto &Group : Infos) {
doc::Info *Info = Group.getValue().get();
diff --git a/clang-tools-extra/clang-doc/assets/class-template.mustache b/clang-tools-extra/clang-doc/assets/class-template.mustache
index b1a7470..bbac3ff 100644
--- a/clang-tools-extra/clang-doc/assets/class-template.mustache
+++ b/clang-tools-extra/clang-doc/assets/class-template.mustache
@@ -50,18 +50,21 @@
<li class="sidebar-section">
<a class="sidebar-item" href="#PublicMembers">Public Members</a>
</li>
- <ul>
- {{#PublicMembers}}
- <li class="sidebar-item-container">
- <a class="sidebar-item" href="#{{Name}}">{{Name}}</a>
- </li>
- {{/PublicMembers}}
- </ul>
+ <li>
+ <ul>
+ {{#PublicMembers}}
+ <li class="sidebar-item-container">
+ <a class="sidebar-item" href="#{{Name}}">{{Name}}</a>
+ </li>
+ {{/PublicMembers}}
+ </ul>
+ </li>
{{/HasPublicMembers}}
{{#ProtectedMembers}}
- <li class="sidebar-section">
- <a class="sidebar-item" href="#PublicMethods">Protected Members</a>
- </li>
+ <li class="sidebar-section">
+ <a class="sidebar-item" href="#PublicMethods">Protected Members</a>
+ </li>
+ <li>
<ul>
{{#Obj}}
<li class="sidebar-item-container">
@@ -69,42 +72,49 @@
</li>
{{/Obj}}
</ul>
+ </li>
{{/ProtectedMembers}}
{{#HasPublicFunctions}}
<li class="sidebar-section">
<a class="sidebar-item" href="#PublicMethods">Public Method</a>
</li>
- <ul>
- {{#PublicFunctions}}
- <li class="sidebar-item-container">
- <a class="sidebar-item" href="#{{USR}}">{{Name}}</a>
- </li>
- {{/PublicFunctions}}
- </ul>
+ <li>
+ <ul>
+ {{#PublicFunctions}}
+ <li class="sidebar-item-container">
+ <a class="sidebar-item" href="#{{USR}}">{{Name}}</a>
+ </li>
+ {{/PublicFunctions}}
+ </ul>
+ </li>
{{/HasPublicFunctions}}
{{#ProtectedFunction}}
<li class="sidebar-section">
<a class="sidebar-item" href="#ProtectedFunction">Protected Method</a>
</li>
- <ul>
- {{#Obj}}
- <li class="sidebar-item-container">
- <a class="sidebar-item" href="#{{ID}}">{{Name}}</a>
- </li>
- {{/Obj}}
- </ul>
+ <li>
+ <ul>
+ {{#Obj}}
+ <li class="sidebar-item-container">
+ <a class="sidebar-item" href="#{{ID}}">{{Name}}</a>
+ </li>
+ {{/Obj}}
+ </ul>
+ </li>
{{/ProtectedFunction}}
{{#Enums}}
<li class="sidebar-section">
<a class="sidebar-item" href="#Enums">Enums</a>
</li>
- <ul>
- {{#Obj}}
- <li class="sidebar-item-container">
- <a class="sidebar-item" href="#{{USR}}">{{EnumName}}</a>
- </li>
- {{/Obj}}
- </ul>
+ <li>
+ <ul>
+ {{#Obj}}
+ <li class="sidebar-item-container">
+ <a class="sidebar-item" href="#{{USR}}">{{EnumName}}</a>
+ </li>
+ {{/Obj}}
+ </ul>
+ </li>
{{/Enums}}
{{#Typedef}}
<li class="sidebar-section">Typedef</li>
@@ -113,13 +123,15 @@
<li class="sidebar-section">
<a class="sidebar-item" href="#Classes">Inner Classes</a>
</li>
- <ul>
- {{#Links}}
- <li class="sidebar-item-container">
- <a class="sidebar-item" href="#{{ID}}">{{Name}}</a>
- </li>
- {{/Links}}
- </ul>
+ <li>
+ <ul>
+ {{#Links}}
+ <li class="sidebar-item-container">
+ <a class="sidebar-item" href="#{{ID}}">{{Name}}</a>
+ </li>
+ {{/Links}}
+ </ul>
+ </li>
{{/Record}}
</ul>
</div>
@@ -128,6 +140,7 @@
<section class="hero section-container">
<div class="hero__title">
<h1 class="hero__title-large">{{TagType}} {{Name}}</h1>
+ <p>Defined at line {{Location.LineNumber}} of file {{Location.Filename}}</p>
{{#Description}}
<div class="hero__subtitle">
{{>Comments}}
@@ -141,9 +154,7 @@
<div>
{{#PublicMembers}}
<div id="{{Name}}" class="delimiter-container">
- <pre>
- <code class="language-cpp code-clang-doc" >{{Type}} {{Name}}</code>
- </pre>
+ <pre><code class="language-cpp code-clang-doc" >{{Type}} {{Name}}</code></pre>
{{#MemberComments}}
<div>
{{>Comments}}
@@ -160,9 +171,7 @@
<div>
{{#Obj}}
<div id="{{Name}}" class="delimiter-container">
- <pre>
-<code class="language-cpp code-clang-doc" >{{Type}} {{Name}}</code>
- </pre>
+ <pre><code class="language-cpp code-clang-doc" >{{Type}} {{Name}}</code></pre>
{{#MemberComments}}
<div>
{{>Comments}}
@@ -178,7 +187,7 @@
<h2>Public Methods</h2>
<div>
{{#PublicFunctions}}
-{{>FunctionPartial}}
+ {{>FunctionPartial}}
{{/PublicFunctions}}
</div>
</section>
diff --git a/clang-tools-extra/clang-doc/assets/comment-template.mustache b/clang-tools-extra/clang-doc/assets/comment-template.mustache
index 4e38e5f..1f40333 100644
--- a/clang-tools-extra/clang-doc/assets/comment-template.mustache
+++ b/clang-tools-extra/clang-doc/assets/comment-template.mustache
@@ -6,54 +6,62 @@
This file defines templates for generating comments
}}
{{#BriefComments}}
- <div>
- {{#.}}
- <p>{{TextComment}}</p>
- {{/.}}
- </div>
+<div>
+{{#.}}
+ <p>{{TextComment}}</p>
+{{/.}}
+</div>
{{/BriefComments}}
{{#ParagraphComments}}
- <div>
- {{#.}}
- <p>{{TextComment}}</p>
- {{/.}}
- </div>
+<div>
+{{#.}}
+ <p>{{TextComment}}</p>
+{{/.}}
+</div>
{{/ParagraphComments}}
{{#ParagraphComment}}
- {{#Children}}
- {{>Comments}}
- {{/Children}}
+{{#Children}}
+{{TextComment}}
+{{/Children}}
{{/ParagraphComment}}
{{#HasParamComments}}
- <h3>Parameters</h3>
- {{#ParamComments}}
- <div>
- <b>{{ParamName}}</b> {{#Explicit}}{{Direction}}{{/Explicit}} {{#Children}}{{>Comments}}{{/Children}}
- </div>
- {{/ParamComments}}
+<h3>Parameters</h3>
+{{#ParamComments}}
+<div>
+ <b>{{ParamName}}</b> {{#Explicit}}{{Direction}}{{/Explicit}} {{#Children}}{{TextComment}}{{/Children}}
+</div>
+{{/ParamComments}}
{{/HasParamComments}}
{{#HasReturnComments}}
- <h3>Returns</h3>
- {{#ReturnComments}}
- {{#.}}
- <p>{{TextComment}}</p>
- {{/.}}
- {{/ReturnComments}}
+<h3>Returns</h3>
+{{#ReturnComments}}
+{{#.}}
+<p>{{TextComment}}</p>
+{{/.}}
+{{/ReturnComments}}
{{/HasReturnComments}}
{{#HasCodeComments}}
- <h3>Code</h3>
- {{#CodeComments}}
- <div>
- <pre class="code-block">
- <code>
- {{#.}}
+<h3>Code</h3>
+{{#CodeComments}}
+<div>
+ <pre class="code-block">
+ <code>
+ {{#.}}
{{.}}
- {{/.}}
- </code>
- </pre>
- </div>
- {{/CodeComments}}
+ {{/.}}
+ </code>
+ </pre>
+</div>
+{{/CodeComments}}
{{/HasCodeComments}}
+{{#HasThrowsComments}}
+<h3>Throws</h3>
+{{#ThrowsComments}}
+<div>
+ <b>{{Exception}}</b> {{#Children}}{{TextComment}}{{/Children}}
+</div>
+{{/ThrowsComments}}
+{{/HasThrowsComments}}
{{#BlockCommandComment}}
<div class="block-command-comment__command">
<div class="block-command-command">
@@ -66,8 +74,3 @@
</div>
</div>
{{/BlockCommandComment}}
-{{#TextComment}}
- <div>
- <p>{{TextComment}}</p>
- </div>
-{{/TextComment}}
diff --git a/clang-tools-extra/clang-doc/assets/enum-template.mustache b/clang-tools-extra/clang-doc/assets/enum-template.mustache
index 53da466..ec42df9 100644
--- a/clang-tools-extra/clang-doc/assets/enum-template.mustache
+++ b/clang-tools-extra/clang-doc/assets/enum-template.mustache
@@ -7,22 +7,18 @@
}}
<div id="{{ID}}" class="delimiter-container">
<div>
- <pre>
- <code class="language-cpp code-clang-doc">
-enum {{Name}}
- </code>
- </pre>
+ <pre><code class="language-cpp code-clang-doc">enum {{Name}}</code></pre>
</div>
{{! Enum Values }}
<table class="table-wrapper">
<tbody>
- <tr>
- <th>Name</th>
- <th>Value</th>
- {{#HasComment}}
+ <tr>
+ <th>Name</th>
+ <th>Value</th>
+ {{#HasComment}}
<th>Comment</th>
- {{/HasComment}}
- </tr>
+ {{/HasComment}}
+ </tr>
{{#Members}}
<tr>
<td>{{Name}}</td>
@@ -34,7 +30,7 @@ enum {{Name}}
<td>{{ValueExpr}}</td>
{{/Value}}
{{#EnumValueComments}}
- <td>{{>Comments}}</td>
+ <td>{{>Comments}}</td>
{{/EnumValueComments}}
</tr>
{{/Members}}
diff --git a/clang-tools-extra/clang-doc/assets/function-template.mustache b/clang-tools-extra/clang-doc/assets/function-template.mustache
index 2510a4d..dc787bf 100644
--- a/clang-tools-extra/clang-doc/assets/function-template.mustache
+++ b/clang-tools-extra/clang-doc/assets/function-template.mustache
@@ -8,11 +8,7 @@
<div class="delimiter-container">
<div id="{{USR}}">
{{! Function Prototype }}
- <pre>
- <code class="language-cpp code-clang-doc">
-{{ReturnType.Name}} {{Name}} ({{#Params}}{{^End}}{{Type}} {{Name}}, {{/End}}{{#End}}{{Type}} {{Name}}{{/End}}{{/Params}})
- </code>
- </pre>
+ <pre><code class="language-cpp code-clang-doc">{{ReturnType.Name}} {{Name}} ({{#Params}}{{^End}}{{Type}} {{Name}}, {{/End}}{{#End}}{{Type}} {{Name}}{{/End}}{{/Params}})</code></pre>
{{! Function Comments }}
{{#Description}}
<div>
diff --git a/clang-tools-extra/clang-doc/assets/namespace-template.mustache b/clang-tools-extra/clang-doc/assets/namespace-template.mustache
index d96bc5c..8a5be46 100644
--- a/clang-tools-extra/clang-doc/assets/namespace-template.mustache
+++ b/clang-tools-extra/clang-doc/assets/namespace-template.mustache
@@ -50,25 +50,29 @@
<li class="sidebar-section">
<a class="sidebar-item" href="#Enums">Enums</a>
</li>
- <ul>
- {{#Enums}}
- <li class="sidebar-item-container">
- <a class="sidebar-item" href="#{{USR}}">{{Name}}</a>
- </li>
- {{/Enums}}
- </ul>
+ <li>
+ <ul>
+ {{#Enums}}
+ <li class="sidebar-item-container">
+ <a class="sidebar-item" href="#{{USR}}">{{Name}}</a>
+ </li>
+ {{/Enums}}
+ </ul>
+ </li>
{{/HasEnums}}
{{#HasRecords}}
<li class="sidebar-section">
<a class="sidebar-item" href="#Classes">Inner Classes</a>
</li>
- <ul>
- {{#Records}}
- <li class="sidebar-item-container">
- <a class="sidebar-item" href="#{{USR}}">{{Name}}</a>
- </li>
- {{/Records}}
- </ul>
+ <li>
+ <ul>
+ {{#Records}}
+ <li class="sidebar-item-container">
+ <a class="sidebar-item" href="#{{USR}}">{{Name}}</a>
+ </li>
+ {{/Records}}
+ </ul>
+ </li>
{{/HasRecrods}}
</ul>
</div>
@@ -92,15 +96,13 @@
{{#Records}}
<li id="{{USR}}" style="max-height: 40px;">
<a href="{{DocumentationFileName}}.html">
- <pre>
- <code class="language-cpp code-clang-doc">class {{Name}}</code>
- </pre>
+ <pre><code class="language-cpp code-clang-doc">class {{Name}}</code></pre>
</a>
</li>
{{/Records}}
</ul>
- {{/HasRecords}}
</section>
+ {{/HasRecords}}
</div>
</div>
</main>
diff --git a/clang-tools-extra/clang-doc/support/File.h b/clang-tools-extra/clang-doc/support/File.h
index 7036d5e6..bab988f 100644
--- a/clang-tools-extra/clang-doc/support/File.h
+++ b/clang-tools-extra/clang-doc/support/File.h
@@ -8,7 +8,7 @@
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_FILE_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_FILE_H
-#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/SmallString.h"
#include "llvm/Support/Error.h"
namespace clang {
diff --git a/clang-tools-extra/clang-doc/support/Utils.cpp b/clang-tools-extra/clang-doc/support/Utils.cpp
index 6ed5603..f410bfc 100644
--- a/clang-tools-extra/clang-doc/support/Utils.cpp
+++ b/clang-tools-extra/clang-doc/support/Utils.cpp
@@ -28,13 +28,24 @@ SmallString<128> appendPathPosix(StringRef Base, StringRef Path) {
return Default;
}
-void getMustacheHtmlFiles(StringRef AssetsPath,
- clang::doc::ClangDocContext &CDCtx) {
+void getHtmlFiles(StringRef AssetsPath, clang::doc::ClangDocContext &CDCtx) {
assert(!AssetsPath.empty());
assert(sys::fs::is_directory(AssetsPath));
- SmallString<128> DefaultStylesheet =
- appendPathPosix(AssetsPath, "clang-doc-mustache.css");
+ // TODO: Allow users to override default templates with their own. We would
+ // similarly have to check if a template file already exists in CDCtx.
+ if (CDCtx.UserStylesheets.empty()) {
+ SmallString<128> DefaultStylesheet =
+ appendPathPosix(AssetsPath, "clang-doc-mustache.css");
+ CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(),
+ DefaultStylesheet.c_str());
+ }
+
+ if (CDCtx.JsScripts.empty()) {
+ SmallString<128> IndexJS = appendPathPosix(AssetsPath, "mustache-index.js");
+ CDCtx.JsScripts.insert(CDCtx.JsScripts.begin(), IndexJS.c_str());
+ }
+
SmallString<128> NamespaceTemplate =
appendPathPosix(AssetsPath, "namespace-template.mustache");
SmallString<128> ClassTemplate =
@@ -45,11 +56,7 @@ void getMustacheHtmlFiles(StringRef AssetsPath,
appendPathPosix(AssetsPath, "function-template.mustache");
SmallString<128> CommentTemplate =
appendPathPosix(AssetsPath, "comment-template.mustache");
- SmallString<128> IndexJS = appendPathPosix(AssetsPath, "mustache-index.js");
- CDCtx.JsScripts.insert(CDCtx.JsScripts.begin(), IndexJS.c_str());
- CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(),
- DefaultStylesheet.c_str());
CDCtx.MustacheTemplates.insert(
{"namespace-template", NamespaceTemplate.c_str()});
CDCtx.MustacheTemplates.insert({"class-template", ClassTemplate.c_str()});
diff --git a/clang-tools-extra/clang-doc/support/Utils.h b/clang-tools-extra/clang-doc/support/Utils.h
index 8161c37..f4ed9ec4 100644
--- a/clang-tools-extra/clang-doc/support/Utils.h
+++ b/clang-tools-extra/clang-doc/support/Utils.h
@@ -20,7 +20,7 @@ llvm::SmallString<128> appendPathNative(llvm::StringRef Base,
llvm::SmallString<128> appendPathPosix(llvm::StringRef Base,
llvm::StringRef Path);
-void getMustacheHtmlFiles(llvm::StringRef AssetsPath,
- clang::doc::ClangDocContext &CDCtx);
+void getHtmlFiles(llvm::StringRef AssetsPath,
+ clang::doc::ClangDocContext &CDCtx);
#endif
diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 3bb67ba..ee4c4497 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -22,7 +22,9 @@
#include "Generators.h"
#include "Representation.h"
#include "support/Utils.h"
-#include "clang/ASTMatchers/ASTMatchersInternal.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "clang/Tooling/AllTUsExecution.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Execution.h"
@@ -41,7 +43,6 @@
#include <mutex>
#include <string>
-using namespace clang::ast_matchers;
using namespace clang::tooling;
using namespace clang;
@@ -110,21 +111,20 @@ Turn on time profiler. Generates clang-doc-tracing.json)"),
llvm::cl::init(false),
llvm::cl::cat(ClangDocCategory));
-enum OutputFormatTy { md, yaml, html, mustache, json };
-
-static llvm::cl::opt<OutputFormatTy> FormatEnum(
- "format", llvm::cl::desc("Format for outputted docs."),
- llvm::cl::values(clEnumValN(OutputFormatTy::yaml, "yaml",
- "Documentation in YAML format."),
- clEnumValN(OutputFormatTy::md, "md",
- "Documentation in MD format."),
- clEnumValN(OutputFormatTy::html, "html",
- "Documentation in HTML format."),
- clEnumValN(OutputFormatTy::mustache, "mustache",
- "Documentation in mustache HTML format"),
- clEnumValN(OutputFormatTy::json, "json",
- "Documentation in JSON format")),
- llvm::cl::init(OutputFormatTy::yaml), llvm::cl::cat(ClangDocCategory));
+enum OutputFormatTy { md, yaml, html, json };
+
+static llvm::cl::opt<OutputFormatTy>
+ FormatEnum("format", llvm::cl::desc("Format for outputted docs."),
+ llvm::cl::values(clEnumValN(OutputFormatTy::yaml, "yaml",
+ "Documentation in YAML format."),
+ clEnumValN(OutputFormatTy::md, "md",
+ "Documentation in MD format."),
+ clEnumValN(OutputFormatTy::html, "html",
+ "Documentation in HTML format."),
+ clEnumValN(OutputFormatTy::json, "json",
+ "Documentation in JSON format")),
+ llvm::cl::init(OutputFormatTy::yaml),
+ llvm::cl::cat(ClangDocCategory));
static llvm::ExitOnError ExitOnErr;
@@ -136,8 +136,6 @@ static std::string getFormatString() {
return "md";
case OutputFormatTy::html:
return "html";
- case OutputFormatTy::mustache:
- return "mustache";
case OutputFormatTy::json:
return "json";
}
@@ -153,6 +151,7 @@ static std::string getExecutablePath(const char *Argv0, void *MainAddr) {
return llvm::sys::fs::getMainExecutable(Argv0, MainAddr);
}
+// TODO: Rename this, since it only gets custom CSS/JS
static llvm::Error getAssetFiles(clang::doc::ClangDocContext &CDCtx) {
using DirIt = llvm::sys::fs::directory_iterator;
std::error_code FileErr;
@@ -173,58 +172,15 @@ static llvm::Error getAssetFiles(clang::doc::ClangDocContext &CDCtx) {
return llvm::Error::success();
}
-static llvm::Error getDefaultAssetFiles(const char *Argv0,
- clang::doc::ClangDocContext &CDCtx) {
- void *MainAddr = (void *)(intptr_t)getExecutablePath;
- std::string ClangDocPath = getExecutablePath(Argv0, MainAddr);
- llvm::SmallString<128> NativeClangDocPath;
- llvm::sys::path::native(ClangDocPath, NativeClangDocPath);
-
- llvm::SmallString<128> AssetsPath;
- AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath);
- llvm::sys::path::append(AssetsPath, "..", "share", "clang-doc");
- llvm::SmallString<128> DefaultStylesheet =
- appendPathNative(AssetsPath, "clang-doc-default-stylesheet.css");
- llvm::SmallString<128> IndexJS = appendPathNative(AssetsPath, "index.js");
-
- if (!llvm::sys::fs::is_regular_file(IndexJS))
- return llvm::createStringError(llvm::inconvertibleErrorCode(),
- "default index.js file missing at " +
- IndexJS + "\n");
-
- if (!llvm::sys::fs::is_regular_file(DefaultStylesheet))
- return llvm::createStringError(
- llvm::inconvertibleErrorCode(),
- "default clang-doc-default-stylesheet.css file missing at " +
- DefaultStylesheet + "\n");
-
- CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(),
- std::string(DefaultStylesheet));
- CDCtx.JsScripts.emplace_back(IndexJS.str());
-
- return llvm::Error::success();
-}
-
-static llvm::Error getHtmlAssetFiles(const char *Argv0,
- clang::doc::ClangDocContext &CDCtx) {
- if (!UserAssetPath.empty() &&
- !llvm::sys::fs::is_directory(std::string(UserAssetPath)))
- llvm::outs() << "Asset path supply is not a directory: " << UserAssetPath
- << " falling back to default\n";
- if (llvm::sys::fs::is_directory(std::string(UserAssetPath)))
- return getAssetFiles(CDCtx);
- return getDefaultAssetFiles(Argv0, CDCtx);
-}
-
-static llvm::Error getMustacheHtmlFiles(const char *Argv0,
- clang::doc::ClangDocContext &CDCtx) {
+static llvm::Error getHtmlFiles(const char *Argv0,
+ clang::doc::ClangDocContext &CDCtx) {
bool IsDir = llvm::sys::fs::is_directory(UserAssetPath);
if (!UserAssetPath.empty() && !IsDir)
llvm::outs() << "Asset path supply is not a directory: " << UserAssetPath
<< " falling back to default\n";
if (IsDir) {
- getMustacheHtmlFiles(UserAssetPath, CDCtx);
- return llvm::Error::success();
+ if (auto Err = getAssetFiles(CDCtx))
+ return Err;
}
void *MainAddr = (void *)(intptr_t)getExecutablePath;
std::string ClangDocPath = getExecutablePath(Argv0, MainAddr);
@@ -235,7 +191,7 @@ static llvm::Error getMustacheHtmlFiles(const char *Argv0,
AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath);
llvm::sys::path::append(AssetsPath, "..", "share", "clang-doc");
- getMustacheHtmlFiles(AssetsPath, CDCtx);
+ getHtmlFiles(AssetsPath, CDCtx);
return llvm::Error::success();
}
@@ -257,13 +213,16 @@ sortUsrToInfo(llvm::StringMap<std::unique_ptr<doc::Info>> &USRToInfo) {
}
}
-static llvm::Error handleMappingFailures(llvm::Error Err) {
+static llvm::Error handleMappingFailures(DiagnosticsEngine &Diags,
+ llvm::Error Err) {
if (!Err)
return llvm::Error::success();
if (IgnoreMappingFailures) {
- llvm::errs() << "Error mapping decls in files. Clang-doc will ignore these "
- "files and continue:\n"
- << toString(std::move(Err)) << "\n";
+ unsigned ID = Diags.getCustomDiagID(
+ DiagnosticsEngine::Warning,
+ "Error mapping decls in files. Clang-doc will ignore these files and "
+ "continue:\n%0");
+ Diags.Report(ID) << toString(std::move(Err));
return llvm::Error::success();
}
return Err;
@@ -315,28 +274,25 @@ Example usage for a project using a compile commands database:
tooling::ArgumentInsertPosition::END),
ArgAdjuster);
- clang::doc::ClangDocContext CDCtx = {
- Executor->getExecutionContext(),
- ProjectName,
- PublicOnly,
- OutDirectory,
- SourceRoot,
- RepositoryUrl,
- RepositoryCodeLinePrefix,
- BaseDirectory,
- {UserStylesheets.begin(), UserStylesheets.end()},
- FTimeTrace};
-
- if (Format == "html") {
- ExitOnErr(getHtmlAssetFiles(argv[0], CDCtx));
- } else if (Format == "mustache") {
- ExitOnErr(getMustacheHtmlFiles(argv[0], CDCtx));
- }
+ auto DiagOpts = std::make_unique<DiagnosticOptions>();
+ TextDiagnosticPrinter *DiagClient =
+ new TextDiagnosticPrinter(llvm::errs(), *DiagOpts);
+ IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
+ DiagnosticsEngine Diags(DiagID, *DiagOpts, DiagClient);
+
+ clang::doc::ClangDocContext CDCtx(
+ Executor->getExecutionContext(), ProjectName, PublicOnly, OutDirectory,
+ SourceRoot, RepositoryUrl, RepositoryCodeLinePrefix, BaseDirectory,
+ {UserStylesheets.begin(), UserStylesheets.end()}, Diags, FTimeTrace);
+
+ if (Format == "html")
+ ExitOnErr(getHtmlFiles(argv[0], CDCtx));
llvm::timeTraceProfilerBegin("Executor Launch", "total runtime");
// Mapping phase
llvm::outs() << "Mapping decls...\n";
ExitOnErr(handleMappingFailures(
+ Diags,
Executor->execute(doc::newMapperActionFactory(CDCtx), ArgAdjuster)));
llvm::timeTraceProfilerEnd();
@@ -362,13 +318,18 @@ Example usage for a project using a compile commands database:
std::atomic<bool> Error;
Error = false;
llvm::sys::Mutex IndexMutex;
+ llvm::sys::Mutex DiagMutex;
+ unsigned DiagIDBitcodeReading = Diags.getCustomDiagID(
+ DiagnosticsEngine::Error, "error reading bitcode: %0");
+ unsigned DiagIDBitcodeMerging = Diags.getCustomDiagID(
+ DiagnosticsEngine::Error, "error merging bitcode: %0");
// ExecutorConcurrency is a flag exposed by AllTUsExecution.h
llvm::DefaultThreadPool Pool(
llvm::hardware_concurrency(ExecutorConcurrency));
{
llvm::TimeTraceScope TS("Reduce");
for (auto &Group : USRToBitcode) {
- Pool.async([&]() { // time trace decoding bitcode
+ Pool.async([&, &Diags = Diags]() { // time trace decoding bitcode
if (FTimeTrace)
llvm::timeTraceProfilerInitialize(200, "clang-doc");
@@ -377,10 +338,13 @@ Example usage for a project using a compile commands database:
llvm::TimeTraceScope Red("decoding bitcode");
for (auto &Bitcode : Group.getValue()) {
llvm::BitstreamCursor Stream(Bitcode);
- doc::ClangDocBitcodeReader Reader(Stream);
+ doc::ClangDocBitcodeReader Reader(Stream, Diags);
auto ReadInfos = Reader.readBitcode();
if (!ReadInfos) {
- llvm::errs() << toString(ReadInfos.takeError()) << "\n";
+ std::lock_guard<llvm::sys::Mutex> Guard(DiagMutex);
+
+ Diags.Report(DiagIDBitcodeReading)
+ << toString(ReadInfos.takeError());
Error = true;
return;
}
@@ -396,7 +360,9 @@ Example usage for a project using a compile commands database:
auto ExpReduced = doc::mergeInfos(Infos);
if (!ExpReduced) {
- llvm::errs() << llvm::toString(ExpReduced.takeError());
+ std::lock_guard<llvm::sys::Mutex> Guard(DiagMutex);
+ Diags.Report(DiagIDBitcodeMerging)
+ << toString(ExpReduced.takeError());
return;
}
Reduced = std::move(*ExpReduced);
@@ -438,7 +404,8 @@ Example usage for a project using a compile commands database:
// Run the generator.
llvm::outs() << "Generating docs...\n";
- ExitOnErr(G->generateDocs(OutDirectory, std::move(USRToInfo), CDCtx));
+ ExitOnErr(
+ G->generateDocumentation(OutDirectory, std::move(USRToInfo), CDCtx));
llvm::outs() << "Generating assets for docs...\n";
ExitOnErr(G->createResources(CDCtx));
llvm::timeTraceProfilerEnd();
diff --git a/clang-tools-extra/clang-tidy/.clang-format b/clang-tools-extra/clang-tidy/.clang-format
index 5b50661..fe94ed1 100644
--- a/clang-tools-extra/clang-tidy/.clang-format
+++ b/clang-tools-extra/clang-tidy/.clang-format
@@ -1,3 +1,8 @@
BasedOnStyle: LLVM
-QualifierAlignment: Left
+InsertNewlineAtEOF: true
+KeepEmptyLines:
+ AtEndOfFile: false
+ AtStartOfBlock: false
+ AtStartOfFile: false
LineEnding: LF
+QualifierAlignment: Left
diff --git a/clang-tools-extra/clang-tidy/.clang-tidy b/clang-tools-extra/clang-tidy/.clang-tidy
index 0c2f34b..70d5731 100644
--- a/clang-tools-extra/clang-tidy/.clang-tidy
+++ b/clang-tools-extra/clang-tidy/.clang-tidy
@@ -1,4 +1,6 @@
InheritParentConfig: true
+HeaderFilterRegex: 'clang-tools-extra/clang-tidy'
+ExcludeHeaderFilterRegex: 'include-cleaner|clang-query'
Checks: >
bugprone-*,
-bugprone-assignment-in-if-condition,
@@ -7,6 +9,12 @@ Checks: >
-bugprone-narrowing-conversions,
-bugprone-unchecked-optional-access,
-bugprone-unused-return-value,
+ cppcoreguidelines-init-variables,
+ cppcoreguidelines-missing-std-forward,
+ cppcoreguidelines-rvalue-reference-param-not-moved,
+ cppcoreguidelines-virtual-class-destructor,
+ google-readability-casting,
+ misc-const-correctness,
modernize-*,
-modernize-avoid-c-arrays,
-modernize-pass-by-value,
@@ -15,7 +23,6 @@ Checks: >
performance-*,
-performance-enum-size,
-performance-no-int-to-ptr,
- -performance-unnecessary-value-param,
readability-*,
-readability-avoid-nested-conditional-operator,
-readability-braces-around-statements,
@@ -30,8 +37,7 @@ Checks: >
-readability-qualified-auto,
-readability-simplify-boolean-expr,
-readability-static-definition-in-anonymous-namespace,
- -readability-suspicious-call-argument,
- -readability-use-anyofallof
+ -readability-suspicious-call-argument
CheckOptions:
- key: performance-move-const-arg.CheckTriviallyCopyableMove
diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index 7e18f38..4af328c 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -23,10 +23,10 @@
#include "clang-tidy-config.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Basic/DiagnosticFrontend.h"
#include "clang/Format/Format.h"
#include "clang/Frontend/ASTConsumers.h"
#include "clang/Frontend/CompilerInstance.h"
-#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Frontend/MultiplexConsumer.h"
#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "clang/Lex/Preprocessor.h"
@@ -117,7 +117,8 @@ public:
void reportDiagnostic(const ClangTidyError &Error) {
const tooling::DiagnosticMessage &Message = Error.Message;
- SourceLocation Loc = getLocation(Message.FilePath, Message.FileOffset);
+ const SourceLocation Loc =
+ getLocation(Message.FilePath, Message.FileOffset);
// Contains a pair for each attempted fix: location and whether the fix was
// applied successfully.
SmallVector<std::pair<SourceLocation, bool>, 4> FixLocations;
@@ -157,11 +158,11 @@ public:
// FIXME: Implement better conflict handling.
llvm::errs() << "Trying to resolve conflict: "
<< llvm::toString(std::move(Err)) << "\n";
- unsigned NewOffset =
+ const unsigned NewOffset =
Replacements.getShiftedCodePosition(R.getOffset());
- unsigned NewLength = Replacements.getShiftedCodePosition(
- R.getOffset() + R.getLength()) -
- NewOffset;
+ const unsigned NewLength = Replacements.getShiftedCodePosition(
+ R.getOffset() + R.getLength()) -
+ NewOffset;
if (NewLength == R.getLength()) {
R = Replacement(R.getFilePath(), NewOffset, NewLength,
R.getReplacementText());
@@ -200,7 +201,7 @@ public:
for (const auto &FileAndReplacements : FileReplacements) {
Rewriter Rewrite(SourceMgr, LangOpts);
- StringRef File = FileAndReplacements.first();
+ const StringRef File = FileAndReplacements.first();
VFS.setCurrentWorkingDirectory(FileAndReplacements.second.BuildDir);
llvm::ErrorOr<std::unique_ptr<MemoryBuffer>> Buffer =
SourceMgr.getFileManager().getBufferForFile(File);
@@ -210,7 +211,7 @@ public:
// FIXME: Maybe don't apply fixes for other files as well.
continue;
}
- StringRef Code = Buffer.get()->getBuffer();
+ const StringRef Code = Buffer.get()->getBuffer();
auto Style = format::getStyle(
*Context.getOptionsForFile(File).FormatStyle, File, "none");
if (!Style) {
@@ -262,7 +263,7 @@ private:
if (!File)
return {};
- FileID ID = SourceMgr.getOrCreateFileID(*File, SrcMgr::C_User);
+ const FileID ID = SourceMgr.getOrCreateFileID(*File, SrcMgr::C_User);
return SourceMgr.getLocForStartOfFile(ID).getLocWithOffset(Offset);
}
@@ -284,7 +285,8 @@ private:
}
void reportNote(const tooling::DiagnosticMessage &Message) {
- SourceLocation Loc = getLocation(Message.FilePath, Message.FileOffset);
+ const SourceLocation Loc =
+ getLocation(Message.FilePath, Message.FileOffset);
auto Diag =
Diags.Report(Loc, Diags.getCustomDiagID(DiagnosticsEngine::Note, "%0"))
<< Message.Message;
@@ -296,8 +298,9 @@ private:
CharSourceRange getRange(const FileByteRange &Range) {
SmallString<128> AbsoluteFilePath{Range.FilePath};
Files.makeAbsolutePath(AbsoluteFilePath);
- SourceLocation BeginLoc = getLocation(AbsoluteFilePath, Range.FileOffset);
- SourceLocation EndLoc = BeginLoc.getLocWithOffset(Range.Length);
+ const SourceLocation BeginLoc =
+ getLocation(AbsoluteFilePath, Range.FileOffset);
+ const SourceLocation EndLoc = BeginLoc.getLocWithOffset(Range.Length);
// Retrieve the source range for applicable highlights and fixes. Macro
// definition on the command line have locations in a virtual buffer and
// don't have valid file paths and are therefore not applicable.
@@ -353,7 +356,8 @@ ClangTidyASTConsumerFactory::ClangTidyASTConsumerFactory(
if (Context.canExperimentalCustomChecks() && custom::RegisterCustomChecks)
custom::RegisterCustomChecks(Context.getOptions(), *CheckFactories);
#endif
- for (ClangTidyModuleRegistry::entry E : ClangTidyModuleRegistry::entries()) {
+ for (const ClangTidyModuleRegistry::entry E :
+ ClangTidyModuleRegistry::entries()) {
std::unique_ptr<ClangTidyModule> Module = E.instantiate();
Module->addCheckFactories(*CheckFactories);
}
@@ -394,8 +398,9 @@ static CheckersList getAnalyzerCheckersAndPackages(ClangTidyContext &Context,
// Always add all core checkers if any other static analyzer check is enabled.
// This is currently necessary, as other path sensitive checks rely on the
// core checkers.
- for (StringRef CheckName : RegisteredCheckers) {
- std::string ClangTidyCheckName((AnalyzerCheckNamePrefix + CheckName).str());
+ for (const StringRef CheckName : RegisteredCheckers) {
+ const std::string ClangTidyCheckName(
+ (AnalyzerCheckNamePrefix + CheckName).str());
if (CheckName.starts_with("core") ||
Context.isCheckEnabled(ClangTidyCheckName)) {
@@ -450,8 +455,8 @@ ClangTidyASTConsumerFactory::createASTConsumer(
if (Context.canEnableModuleHeadersParsing() &&
Context.getLangOpts().Modules && OverlayFS != nullptr) {
- auto ModuleExpander =
- std::make_unique<ExpandModularHeadersPPCallbacks>(&Compiler, OverlayFS);
+ auto ModuleExpander = std::make_unique<ExpandModularHeadersPPCallbacks>(
+ &Compiler, *OverlayFS);
ModuleExpanderPP = ModuleExpander->getPreprocessor();
PP->addPPCallbacks(std::move(ModuleExpander));
}
@@ -504,7 +509,7 @@ std::vector<std::string> ClangTidyASTConsumerFactory::getCheckNames() {
ClangTidyOptions::OptionMap ClangTidyASTConsumerFactory::getCheckOptions() {
ClangTidyOptions::OptionMap Options;
- std::vector<std::unique_ptr<ClangTidyCheck>> Checks =
+ const std::vector<std::unique_ptr<ClangTidyCheck>> Checks =
CheckFactories->createChecks(&Context);
for (const auto &Check : Checks)
Check->storeOptions(Options);
@@ -564,7 +569,7 @@ runClangTidy(clang::tidy::ClangTidyContext &Context,
std::make_shared<PCHContainerOperations>(), BaseFS);
// Add extra arguments passed by the clang-tidy command-line.
- ArgumentsAdjuster PerFileExtraArgumentsInserter =
+ const ArgumentsAdjuster PerFileExtraArgumentsInserter =
[&Context](const CommandLineArguments &Args, StringRef Filename) {
ClangTidyOptions Opts = Context.getOptionsForFile(Filename);
CommandLineArguments AdjustedArgs = Args;
@@ -703,7 +708,7 @@ ChecksAndOptions getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers,
#if CLANG_TIDY_ENABLE_STATIC_ANALYZER
SmallString<64> Buffer(AnalyzerCheckNamePrefix);
- size_t DefSize = Buffer.size();
+ const size_t DefSize = Buffer.size();
for (const auto &AnalyzerCheck : AnalyzerOptions::getRegisteredCheckers(
AllowEnablingAnalyzerAlphaCheckers)) {
Buffer.truncate(DefSize);
diff --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
index 6e0c252..b747657 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
@@ -161,7 +161,7 @@ ClangTidyCheck::OptionsView::getEnumInt(StringRef LocalName,
if (Iter == CheckOptions.end())
return std::nullopt;
- StringRef Value = Iter->getValue().Value;
+ const StringRef Value = Iter->getValue().Value;
StringRef Closest;
unsigned EditDistance = 3;
for (const auto &NameAndEnum : Mapping) {
@@ -173,7 +173,7 @@ ClangTidyCheck::OptionsView::getEnumInt(StringRef LocalName,
EditDistance = 0;
continue;
}
- unsigned Distance =
+ const unsigned Distance =
Value.edit_distance(NameAndEnum.second, true, EditDistance);
if (Distance < EditDistance) {
EditDistance = Distance;
diff --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.h b/clang-tools-extra/clang-tidy/ClangTidyCheck.h
index e53ae53..905e419 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyCheck.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.h
@@ -458,7 +458,7 @@ public:
template <typename T>
std::enable_if_t<std::is_enum_v<T>, std::vector<NameAndValue>>
typeEraseMapping() const {
- ArrayRef<std::pair<T, StringRef>> Mapping =
+ const ArrayRef<std::pair<T, StringRef>> Mapping =
OptionEnumMapping<T>::getEnumMapping();
std::vector<NameAndValue> Result;
Result.reserve(Mapping.size());
diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 65fd09f..16a4d13 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -61,7 +61,7 @@ protected:
// FIXME: Remove this once there's a better way to pass check names than
// appending the check name to the message in ClangTidyContext::diag and
// using getCustomDiagID.
- std::string CheckNameInMessage = " [" + Error.DiagnosticName + "]";
+ const std::string CheckNameInMessage = " [" + Error.DiagnosticName + "]";
Message.consume_back(CheckNameInMessage);
auto TidyMessage =
@@ -77,7 +77,7 @@ protected:
if (SourceRange.isCharRange())
return SourceRange;
assert(SourceRange.isTokenRange());
- SourceLocation End = Lexer::getLocForEndOfToken(
+ const SourceLocation End = Lexer::getLocForEndOfToken(
SourceRange.getEnd(), 0, Loc.getManager(), LangOpts);
return CharSourceRange::getCharRange(SourceRange.getBegin(), End);
};
@@ -114,14 +114,14 @@ protected:
Level == DiagnosticsEngine::Note ? &Error.Notes.back() : &Error.Message;
for (const auto &FixIt : Hints) {
- CharSourceRange Range = FixIt.RemoveRange;
+ const CharSourceRange Range = FixIt.RemoveRange;
assert(Range.getBegin().isValid() && Range.getEnd().isValid() &&
"Invalid range in the fix-it hint.");
assert(Range.getBegin().isFileID() && Range.getEnd().isFileID() &&
"Only file locations supported in fix-it hints.");
- tooling::Replacement Replacement(Loc.getManager(), Range,
- FixIt.CodeToInsert);
+ const tooling::Replacement Replacement(Loc.getManager(), Range,
+ FixIt.CodeToInsert);
llvm::Error Err =
DiagWithFix->Fix[Replacement.getFilePath()].add(Replacement);
// FIXME: better error handling (at least, don't let other replacements be
@@ -177,7 +177,7 @@ DiagnosticBuilder ClangTidyContext::diag(
StringRef CheckName, SourceLocation Loc, StringRef Description,
DiagnosticIDs::Level Level /* = DiagnosticIDs::Warning*/) {
assert(Loc.isValid());
- unsigned ID = DiagEngine->getDiagnosticIDs()->getCustomDiagID(
+ const unsigned ID = DiagEngine->getDiagnosticIDs()->getCustomDiagID(
Level, (Description + " [" + CheckName + "]").str());
CheckNamesByDiagnosticID.try_emplace(ID, CheckName);
return DiagEngine->Report(Loc, ID);
@@ -186,7 +186,7 @@ DiagnosticBuilder ClangTidyContext::diag(
DiagnosticBuilder ClangTidyContext::diag(
StringRef CheckName, StringRef Description,
DiagnosticIDs::Level Level /* = DiagnosticIDs::Warning*/) {
- unsigned ID = DiagEngine->getDiagnosticIDs()->getCustomDiagID(
+ const unsigned ID = DiagEngine->getDiagnosticIDs()->getCustomDiagID(
Level, (Description + " [" + CheckName + "]").str());
CheckNamesByDiagnosticID.try_emplace(ID, CheckName);
return DiagEngine->Report(ID);
@@ -195,10 +195,11 @@ DiagnosticBuilder ClangTidyContext::diag(
DiagnosticBuilder ClangTidyContext::diag(const tooling::Diagnostic &Error) {
SourceManager &SM = DiagEngine->getSourceManager();
FileManager &FM = SM.getFileManager();
- FileEntryRef File = llvm::cantFail(FM.getFileRef(Error.Message.FilePath));
- FileID ID = SM.getOrCreateFileID(File, SrcMgr::C_User);
- SourceLocation FileStartLoc = SM.getLocForStartOfFile(ID);
- SourceLocation Loc = FileStartLoc.getLocWithOffset(
+ const FileEntryRef File =
+ llvm::cantFail(FM.getFileRef(Error.Message.FilePath));
+ const FileID ID = SM.getOrCreateFileID(File, SrcMgr::C_User);
+ const SourceLocation FileStartLoc = SM.getLocForStartOfFile(ID);
+ const SourceLocation Loc = FileStartLoc.getLocWithOffset(
static_cast<SourceLocation::IntTy>(Error.Message.FileOffset));
return diag(Error.DiagnosticName, Loc, Error.Message.Message,
static_cast<DiagnosticIDs::Level>(Error.DiagLevel));
@@ -214,7 +215,7 @@ bool ClangTidyContext::shouldSuppressDiagnostic(
DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info,
SmallVectorImpl<tooling::Diagnostic> &NoLintErrors, bool AllowIO,
bool EnableNoLintBlocks) {
- std::string CheckName = getCheckName(Info.getID());
+ const std::string CheckName = getCheckName(Info.getID());
return NoLintHandler.shouldSuppress(DiagLevel, Info, CheckName, NoLintErrors,
AllowIO, EnableNoLintBlocks);
}
@@ -226,7 +227,7 @@ void ClangTidyContext::setSourceManager(SourceManager *SourceMgr) {
static bool parseFileExtensions(llvm::ArrayRef<std::string> AllFileExtensions,
FileExtensionsSet &FileExtensions) {
FileExtensions.clear();
- for (StringRef Suffix : AllFileExtensions) {
+ for (const StringRef Suffix : AllFileExtensions) {
StringRef Extension = Suffix.trim();
if (!llvm::all_of(Extension, isAlphanumeric))
return false;
@@ -294,11 +295,11 @@ bool ClangTidyContext::treatAsError(StringRef CheckName) const {
}
std::string ClangTidyContext::getCheckName(unsigned DiagnosticID) const {
- std::string ClangWarningOption = std::string(
+ const std::string ClangWarningOption = std::string(
DiagEngine->getDiagnosticIDs()->getWarningOptionForDiag(DiagnosticID));
if (!ClangWarningOption.empty())
return "clang-diagnostic-" + ClangWarningOption;
- llvm::DenseMap<unsigned, std::string>::const_iterator I =
+ const llvm::DenseMap<unsigned, std::string>::const_iterator I =
CheckNamesByDiagnosticID.find(DiagnosticID);
if (I != CheckNamesByDiagnosticID.end())
return I->second;
@@ -316,7 +317,7 @@ ClangTidyDiagnosticConsumer::ClangTidyDiagnosticConsumer(
void ClangTidyDiagnosticConsumer::finalizeLastError() {
if (!Errors.empty()) {
- ClangTidyError &Error = Errors.back();
+ const ClangTidyError &Error = Errors.back();
if (Error.DiagnosticName == "clang-tidy-config") {
// Never ignore these.
} else if (!Context.isCheckEnabled(Error.DiagnosticName) &&
@@ -436,8 +437,8 @@ void ClangTidyDiagnosticConsumer::HandleDiagnostic(
Level = ClangTidyError::Remark;
}
- bool IsWarningAsError = DiagLevel == DiagnosticsEngine::Warning &&
- Context.treatAsError(CheckName);
+ const bool IsWarningAsError = DiagLevel == DiagnosticsEngine::Warning &&
+ Context.treatAsError(CheckName);
Errors.emplace_back(CheckName, Level, Context.getCurrentBuildDirectory(),
IsWarningAsError);
}
@@ -477,11 +478,10 @@ bool ClangTidyDiagnosticConsumer::passesLineFilter(StringRef FileName,
if (FileName.ends_with(Filter.Name)) {
if (Filter.LineRanges.empty())
return true;
- for (const FileFilter::LineRange &Range : Filter.LineRanges) {
- if (Range.first <= LineNumber && LineNumber <= Range.second)
- return true;
- }
- return false;
+ return llvm::any_of(
+ Filter.LineRanges, [&](const FileFilter::LineRange &Range) {
+ return Range.first <= LineNumber && LineNumber <= Range.second;
+ });
}
}
return false;
@@ -491,8 +491,9 @@ void ClangTidyDiagnosticConsumer::forwardDiagnostic(const Diagnostic &Info) {
// Acquire a diagnostic ID also in the external diagnostics engine.
auto DiagLevelAndFormatString =
Context.getDiagLevelAndFormatString(Info.getID(), Info.getLocation());
- unsigned ExternalID = ExternalDiagEngine->getDiagnosticIDs()->getCustomDiagID(
- DiagLevelAndFormatString.first, DiagLevelAndFormatString.second);
+ const unsigned ExternalID =
+ ExternalDiagEngine->getDiagnosticIDs()->getCustomDiagID(
+ DiagLevelAndFormatString.first, DiagLevelAndFormatString.second);
// Forward the details.
auto Builder = ExternalDiagEngine->Report(Info.getLocation(), ExternalID);
@@ -501,7 +502,7 @@ void ClangTidyDiagnosticConsumer::forwardDiagnostic(const Diagnostic &Info) {
for (auto Range : Info.getRanges())
Builder << Range;
for (unsigned Index = 0; Index < Info.getNumArgs(); ++Index) {
- DiagnosticsEngine::ArgumentKind Kind = Info.getArgKind(Index);
+ const DiagnosticsEngine::ArgumentKind Kind = Info.getArgKind(Index);
switch (Kind) {
case clang::DiagnosticsEngine::ak_std_string:
Builder << Info.getArgStdStr(Index);
@@ -525,7 +526,8 @@ void ClangTidyDiagnosticConsumer::forwardDiagnostic(const Diagnostic &Info) {
Builder << Qualifiers::fromOpaqueValue(Info.getRawArg(Index));
break;
case clang::DiagnosticsEngine::ak_qualtype:
- Builder << QualType::getFromOpaquePtr((void *)Info.getRawArg(Index));
+ Builder << QualType::getFromOpaquePtr(
+ reinterpret_cast<void *>(Info.getRawArg(Index)));
break;
case clang::DiagnosticsEngine::ak_declarationname:
Builder << DeclarationName::getFromOpaqueInteger(Info.getRawArg(Index));
@@ -574,7 +576,7 @@ void ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location,
// FIXME: We start with a conservative approach here, but the actual type of
// location needed depends on the check (in particular, where this check wants
// to apply fixes).
- FileID FID = Sources.getDecomposedExpansionLoc(Location).first;
+ const FileID FID = Sources.getDecomposedExpansionLoc(Location).first;
OptionalFileEntryRef File = Sources.getFileEntryRefForID(FID);
// -DMACRO definitions on the command line have locations in a virtual buffer
@@ -585,13 +587,13 @@ void ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location,
return;
}
- StringRef FileName(File->getName());
+ const StringRef FileName(File->getName());
LastErrorRelatesToUserCode = LastErrorRelatesToUserCode ||
Sources.isInMainFile(Location) ||
(getHeaderFilter()->match(FileName) &&
!getExcludeHeaderFilter()->match(FileName));
- unsigned LineNumber = Sources.getExpansionLineNumber(Location);
+ const unsigned LineNumber = Sources.getExpansionLineNumber(Location);
LastErrorPassesLineFilter =
LastErrorPassesLineFilter || passesLineFilter(FileName, LineNumber);
}
@@ -707,8 +709,8 @@ void ClangTidyDiagnosticConsumer::removeIncompatibleErrors() {
for (unsigned I = 0; I < ErrorFixes.size(); ++I) {
for (const auto &FileAndReplace : *ErrorFixes[I].second) {
for (const auto &Replace : FileAndReplace.second) {
- unsigned Begin = Replace.getOffset();
- unsigned End = Begin + Replace.getLength();
+ const unsigned Begin = Replace.getOffset();
+ const unsigned End = Begin + Replace.getLength();
auto &Events = FileEvents[Replace.getFilePath()];
if (Begin == End) {
Events.emplace_back(Begin, End, Event::ET_Insert, I, Sizes[I]);
@@ -767,7 +769,7 @@ struct LessClangTidyError {
};
struct EqualClangTidyError {
bool operator()(const ClangTidyError &LHS, const ClangTidyError &RHS) const {
- LessClangTidyError Less;
+ const LessClangTidyError Less;
return !Less(LHS, RHS) && !Less(RHS, LHS);
}
};
@@ -803,7 +805,7 @@ void ClangTidyDiagnosticConsumer::removeDuplicatedDiagnosticsOfAliasCheckers() {
auto IT = Errors.begin();
while (IT != Errors.end()) {
ClangTidyError &Error = *IT;
- std::pair<UniqueErrorSet::iterator, bool> Inserted =
+ const std::pair<UniqueErrorSet::iterator, bool> Inserted =
UniqueErrors.insert(&Error);
// Unique error, we keep it and move along.
@@ -817,7 +819,6 @@ void ClangTidyDiagnosticConsumer::removeDuplicatedDiagnosticsOfAliasCheckers() {
(*Inserted.first)->Message.Fix;
if (CandidateFix != ExistingFix) {
-
// In case of a conflict, don't suggest any fix-it.
ExistingError.Message.Fix.clear();
ExistingError.Notes.emplace_back(
diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index c4b47a4..550f780 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -119,7 +119,7 @@ void yamlize(IO &IO, ClangTidyOptions::OptionMap &Val, bool,
yamlize(IO, NOpts->Options, true, Ctx);
} else if (isa<MappingNode>(I.getCurrentNode())) {
IO.beginMapping();
- for (StringRef Key : IO.keys()) {
+ for (const StringRef Key : IO.keys()) {
// Requires 'llvm::yaml::IO' to accept 'StringRef'
// NOLINTNEXTLINE(bugprone-suspicious-stringview-data-usage)
IO.mapRequired(Key.data(), Val[Key].Value);
@@ -392,7 +392,7 @@ llvm::ErrorOr<llvm::SmallString<128>>
FileOptionsBaseProvider::getNormalizedAbsolutePath(llvm::StringRef Path) {
assert(FS && "FS must be set.");
llvm::SmallString<128> NormalizedAbsolutePath = {Path};
- std::error_code Err = FS->makeAbsolute(NormalizedAbsolutePath);
+ const std::error_code Err = FS->makeAbsolute(NormalizedAbsolutePath);
if (Err)
return Err;
llvm::sys::path::remove_dots(NormalizedAbsolutePath, /*remove_dot_dot=*/true);
@@ -463,7 +463,7 @@ FileOptionsProvider::getRawOptions(StringRef FileName) {
LLVM_DEBUG(llvm::dbgs() << "Getting options for file " << FileName
<< "...\n");
- llvm::ErrorOr<llvm::SmallString<128>> AbsoluteFilePath =
+ const llvm::ErrorOr<llvm::SmallString<128>> AbsoluteFilePath =
getNormalizedAbsolutePath(FileName);
if (!AbsoluteFilePath)
return {};
@@ -471,8 +471,8 @@ FileOptionsProvider::getRawOptions(StringRef FileName) {
std::vector<OptionsSource> RawOptions =
DefaultOptionsProvider::getRawOptions(AbsoluteFilePath->str());
addRawFileOptions(AbsoluteFilePath->str(), RawOptions);
- OptionsSource CommandLineOptions(OverrideOptions,
- OptionsSourceTypeCheckCommandLineOption);
+ const OptionsSource CommandLineOptions(
+ OverrideOptions, OptionsSourceTypeCheckCommandLineOption);
RawOptions.push_back(CommandLineOptions);
return RawOptions;
@@ -502,7 +502,7 @@ FileOptionsBaseProvider::tryReadConfigFile(StringRef Directory) {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text =
FS->getBufferForFile(ConfigFile);
- if (std::error_code EC = Text.getError()) {
+ if (const std::error_code EC = Text.getError()) {
llvm::errs() << "Can't read " << ConfigFile << ": " << EC.message()
<< "\n";
continue;
diff --git a/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp b/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp
index 8ea6b76..6fee154 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp
@@ -59,7 +59,8 @@ void ClangTidyProfiling::storeProfileData(llvm::TimerGroup &TG) {
llvm::SmallString<256> OutputDirectory(Storage->StoreFilename);
llvm::sys::path::remove_filename(OutputDirectory);
- if (std::error_code EC = llvm::sys::fs::create_directories(OutputDirectory)) {
+ if (const std::error_code EC =
+ llvm::sys::fs::create_directories(OutputDirectory)) {
llvm::errs() << "Unable to create output directory '" << OutputDirectory
<< "': " << EC.message() << "\n";
return;
diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
index 487e5e2..9a4fc7a3 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -65,8 +65,7 @@ private:
};
ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
- CompilerInstance *CI,
- IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFS)
+ CompilerInstance *CI, llvm::vfs::OverlayFileSystem &OverlayFS)
: Recorder(std::make_unique<FileRecorder>()), Compiler(*CI),
InMemoryFs(new llvm::vfs::InMemoryFileSystem),
Sources(Compiler.getSourceManager()),
@@ -76,7 +75,7 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
LangOpts(Compiler.getLangOpts()), HSOpts(Compiler.getHeaderSearchOpts()) {
// Add a FileSystem containing the extra files needed in place of modular
// headers.
- OverlayFS->pushOverlay(InMemoryFs);
+ OverlayFS.pushOverlay(InMemoryFs);
Diags.setSourceManager(&Sources);
// FIXME: Investigate whatever is there better way to initialize DiagEngine
diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
index aaa0410..d72d021 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLING_EXPANDMODULARHEADERSPPCALLBACKS_H_
-#define LLVM_CLANG_TOOLING_EXPANDMODULARHEADERSPPCALLBACKS_H_
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_EXPANDMODULARHEADERSPPCALLBACKS_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_EXPANDMODULARHEADERSPPCALLBACKS_H
#include "clang/Lex/HeaderSearchOptions.h"
#include "clang/Lex/PPCallbacks.h"
@@ -41,9 +41,8 @@ namespace tooling {
/// non-modular way.
class ExpandModularHeadersPPCallbacks : public PPCallbacks {
public:
- ExpandModularHeadersPPCallbacks(
- CompilerInstance *CI,
- IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFS);
+ ExpandModularHeadersPPCallbacks(CompilerInstance *CI,
+ llvm::vfs::OverlayFileSystem &OverlayFS);
~ExpandModularHeadersPPCallbacks() override;
/// Returns the preprocessor that provides callbacks for the whole
@@ -138,10 +137,10 @@ private:
std::unique_ptr<Preprocessor> PP;
bool EnteredMainFile = false;
bool StartedLexing = false;
- Token CurrentToken;
+ Token CurrentToken = Token();
};
} // namespace tooling
} // namespace clang
-#endif // LLVM_CLANG_TOOLING_EXPANDMODULARHEADERSPPCALLBACKS_H_
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_EXPANDMODULARHEADERSPPCALLBACKS_H
diff --git a/clang-tools-extra/clang-tidy/FileExtensionsSet.h b/clang-tools-extra/clang-tidy/FileExtensionsSet.h
index 95c221c..f97bb64 100644
--- a/clang-tools-extra/clang-tidy/FileExtensionsSet.h
+++ b/clang-tools-extra/clang-tidy/FileExtensionsSet.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FILE_EXTENSIONS_SET_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FILE_EXTENSIONS_SET_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FILEEXTENSIONSSET_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FILEEXTENSIONSSET_H
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/StringRef.h"
@@ -16,4 +16,4 @@ namespace clang::tidy {
using FileExtensionsSet = llvm::SmallSet<llvm::StringRef, 5>;
} // namespace clang::tidy
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FILE_EXTENSIONS_SET_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FILEEXTENSIONSSET_H
diff --git a/clang-tools-extra/clang-tidy/GlobList.cpp b/clang-tools-extra/clang-tidy/GlobList.cpp
index 667a256..5d5a5f2 100644
--- a/clang-tools-extra/clang-tidy/GlobList.cpp
+++ b/clang-tools-extra/clang-tidy/GlobList.cpp
@@ -23,16 +23,17 @@ static bool consumeNegativeIndicator(StringRef &GlobList) {
// removes it and the trailing comma from the GlobList and
// returns the extracted glob.
static llvm::StringRef extractNextGlob(StringRef &GlobList) {
- StringRef UntrimmedGlob = GlobList.substr(0, GlobList.find_first_of(",\n"));
- StringRef Glob = UntrimmedGlob.trim();
+ const StringRef UntrimmedGlob =
+ GlobList.substr(0, GlobList.find_first_of(",\n"));
+ const StringRef Glob = UntrimmedGlob.trim();
GlobList = GlobList.substr(UntrimmedGlob.size() + 1);
return Glob;
}
static llvm::Regex createRegexFromGlob(StringRef &Glob) {
SmallString<128> RegexText("^");
- StringRef MetaChars("()^$|*+?.[]\\{}");
- for (char C : Glob) {
+ const StringRef MetaChars("()^$|*+?.[]\\{}");
+ for (const char C : Glob) {
if (C == '*')
RegexText.push_back('.');
else if (MetaChars.contains(C))
diff --git a/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp b/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
index ef20ee1..b552ae8 100644
--- a/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
+++ b/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
@@ -19,7 +19,6 @@
#include "clang/Basic/SourceManager.h"
#include "clang/Tooling/Core/Diagnostic.h"
#include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringSwitch.h"
@@ -134,7 +133,7 @@ static SmallVector<NoLintToken> getNoLints(StringRef Buffer) {
// Get checks, if specified.
std::optional<StringRef> Checks;
if (Pos < Buffer.size() && Buffer[Pos] == '(') {
- size_t ClosingBracket = Buffer.find_first_of("\n)", ++Pos);
+ const size_t ClosingBracket = Buffer.find_first_of("\n)", ++Pos);
if (ClosingBracket != StringRef::npos && Buffer[ClosingBracket] == ')') {
Checks = Buffer.slice(Pos, ClosingBracket);
Pos = ClosingBracket + 1;
@@ -183,13 +182,13 @@ static tooling::Diagnostic makeNoLintError(const SourceManager &SrcMgr,
tooling::Diagnostic Error;
Error.DiagLevel = tooling::Diagnostic::Error;
Error.DiagnosticName = "clang-tidy-nolint";
- StringRef Message =
+ const StringRef Message =
(NoLint.Type == NoLintType::NoLintBegin)
? ("unmatched 'NOLINTBEGIN' comment without a subsequent 'NOLINT"
"END' comment")
: ("unmatched 'NOLINTEND' comment without a previous 'NOLINT"
"BEGIN' comment");
- SourceLocation Loc = SrcMgr.getComposedLoc(File, NoLint.Pos);
+ const SourceLocation Loc = SrcMgr.getComposedLoc(File, NoLint.Pos);
Error.Message = tooling::DiagnosticMessage(Message, SrcMgr, Loc);
return Error;
}
@@ -294,8 +293,8 @@ bool NoLintDirectiveHandler::Impl::diagHasNoLintInMacro(
// this line.
static std::pair<size_t, size_t> getLineStartAndEnd(StringRef Buffer,
size_t From) {
- size_t StartPos = Buffer.find_last_of('\n', From) + 1;
- size_t EndPos = std::min(Buffer.find('\n', From), Buffer.size());
+ const size_t StartPos = Buffer.find_last_of('\n', From) + 1;
+ const size_t EndPos = std::min(Buffer.find('\n', From), Buffer.size());
return {StartPos, EndPos};
}
diff --git a/clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h b/clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h
index 2ae3c00..982774c 100644
--- a/clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h
+++ b/clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h
@@ -6,6 +6,9 @@
//
//===----------------------------------------------------------------------===//
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_ABSEILMATCHER_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_ABSEILMATCHER_H
+
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include <algorithm>
@@ -31,7 +34,7 @@ AST_POLYMORPHIC_MATCHER(
isInAbseilFile, AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc,
NestedNameSpecifierLoc)) {
auto &SourceManager = Finder->getASTContext().getSourceManager();
- SourceLocation Loc = SourceManager.getSpellingLoc(Node.getBeginLoc());
+ const SourceLocation Loc = SourceManager.getSpellingLoc(Node.getBeginLoc());
if (Loc.isInvalid())
return false;
OptionalFileEntryRef FileEntry =
@@ -42,7 +45,7 @@ AST_POLYMORPHIC_MATCHER(
// [absl-library] is AbseilLibraries list entry.
StringRef Path = FileEntry->getName();
static constexpr llvm::StringLiteral AbslPrefix("absl/");
- size_t PrefixPosition = Path.find(AbslPrefix);
+ const size_t PrefixPosition = Path.find(AbslPrefix);
if (PrefixPosition == StringRef::npos)
return false;
Path = Path.drop_front(PrefixPosition + AbslPrefix.size());
@@ -57,3 +60,5 @@ AST_POLYMORPHIC_MATCHER(
}
} // namespace clang::ast_matchers
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_ABSEILMATCHER_H
diff --git a/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.cpp
index 03f78f1..421e5973 100644
--- a/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.cpp
@@ -41,7 +41,7 @@ void DurationAdditionCheck::check(const MatchFinder::MatchResult &Result) {
if (!Scale)
return;
- llvm::StringRef TimeFactory = getTimeInverseForScale(*Scale);
+ const llvm::StringRef TimeFactory = getTimeInverseForScale(*Scale);
FixItHint Hint;
if (Call == Binop->getLHS()->IgnoreParenImpCasts()) {
diff --git a/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.h b/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.h
index b728118..f5bab53 100644
--- a/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.h
+++ b/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEADDITIONCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEADDITIONCHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONADDITIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONADDITIONCHECK_H
#include "../ClangTidyCheck.h"
@@ -31,4 +31,4 @@ public:
} // namespace clang::tidy::abseil
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEADDITIONCHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONADDITIONCHECK_H
diff --git a/clang-tools-extra/clang-tidy/abseil/DurationComparisonCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationComparisonCheck.cpp
index 16a244b..f008777 100644
--- a/clang-tools-extra/clang-tidy/abseil/DurationComparisonCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/DurationComparisonCheck.cpp
@@ -38,9 +38,9 @@ void DurationComparisonCheck::check(const MatchFinder::MatchResult &Result) {
// if nothing needs to be done.
if (isInMacro(Result, Binop->getLHS()) || isInMacro(Result, Binop->getRHS()))
return;
- std::string LhsReplacement =
+ const std::string LhsReplacement =
rewriteExprFromNumberToDuration(Result, *Scale, Binop->getLHS());
- std::string RhsReplacement =
+ const std::string RhsReplacement =
rewriteExprFromNumberToDuration(Result, *Scale, Binop->getRHS());
diag(Binop->getBeginLoc(), "perform comparison in the duration domain")
diff --git a/clang-tools-extra/clang-tidy/abseil/DurationConversionCastCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationConversionCastCheck.cpp
index 11d6017..ef06a9e 100644
--- a/clang-tools-extra/clang-tidy/abseil/DurationConversionCastCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/DurationConversionCastCheck.cpp
@@ -41,7 +41,7 @@ void DurationConversionCastCheck::check(
const auto *FuncDecl = Result.Nodes.getNodeAs<FunctionDecl>("func_decl");
const auto *Arg = Result.Nodes.getNodeAs<Expr>("arg");
- StringRef ConversionFuncName = FuncDecl->getName();
+ const StringRef ConversionFuncName = FuncDecl->getName();
std::optional<DurationScale> Scale =
getScaleForDurationInverse(ConversionFuncName);
@@ -51,7 +51,8 @@ void DurationConversionCastCheck::check(
// Casting a double to an integer.
if (MatchedCast->getTypeAsWritten()->isIntegerType() &&
ConversionFuncName.contains("Double")) {
- llvm::StringRef NewFuncName = getDurationInverseForScale(*Scale).second;
+ const llvm::StringRef NewFuncName =
+ getDurationInverseForScale(*Scale).second;
diag(MatchedCast->getBeginLoc(),
"duration should be converted directly to an integer rather than "
@@ -66,7 +67,8 @@ void DurationConversionCastCheck::check(
// Casting an integer to a double.
if (MatchedCast->getTypeAsWritten()->isRealFloatingType() &&
ConversionFuncName.contains("Int64")) {
- llvm::StringRef NewFuncName = getDurationInverseForScale(*Scale).first;
+ const llvm::StringRef NewFuncName =
+ getDurationInverseForScale(*Scale).first;
diag(MatchedCast->getBeginLoc(), "duration should be converted directly to "
"a floating-point number rather than "
diff --git a/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp
index 3346297..9e403fb8 100644
--- a/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp
@@ -158,7 +158,7 @@ void DurationFactoryScaleCheck::check(const MatchFinder::MatchResult &Result) {
if (!MaybeScale)
return;
- DurationScale Scale = *MaybeScale;
+ const DurationScale Scale = *MaybeScale;
const Expr *Remainder = nullptr;
std::optional<DurationScale> NewScale;
diff --git a/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp b/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp
index ee19796..a78d07d 100644
--- a/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp
@@ -20,7 +20,7 @@ namespace clang::tidy::abseil {
/// Returns an integer if the fractional part of a `FloatingLiteral` is `0`.
static std::optional<llvm::APSInt>
truncateIfIntegral(const FloatingLiteral &FloatLiteral) {
- double Value = FloatLiteral.getValueAsApproximateDouble();
+ const double Value = FloatLiteral.getValueAsApproximateDouble();
if (std::fmod(Value, 1) == 0) {
if (Value >= static_cast<double>(1U << 31))
return std::nullopt;
@@ -69,7 +69,7 @@ rewriteInverseDurationCall(const MatchFinder::MatchResult &Result,
static std::optional<std::string>
rewriteInverseTimeCall(const MatchFinder::MatchResult &Result,
DurationScale Scale, const Expr &Node) {
- llvm::StringRef InverseFunction = getTimeInverseForScale(Scale);
+ const llvm::StringRef InverseFunction = getTimeInverseForScale(Scale);
if (const auto *MaybeCallArg = selectFirst<const Expr>(
"e", match(callExpr(callee(functionDecl(hasName(InverseFunction))),
hasArgument(0, expr().bind("e"))),
diff --git a/clang-tools-extra/clang-tidy/abseil/DurationSubtractionCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationSubtractionCheck.cpp
index c5d93ad..42a7df4 100644
--- a/clang-tools-extra/clang-tidy/abseil/DurationSubtractionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/DurationSubtractionCheck.cpp
@@ -41,7 +41,7 @@ void DurationSubtractionCheck::check(const MatchFinder::MatchResult &Result) {
if (!Scale)
return;
- std::string RhsReplacement =
+ const std::string RhsReplacement =
rewriteExprFromNumberToDuration(Result, *Scale, Binop->getRHS());
const Expr *LhsArg = Result.Nodes.getNodeAs<Expr>("lhs_arg");
diff --git a/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
index 805d7da..5867fb6 100644
--- a/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
@@ -19,10 +19,10 @@ namespace clang::tidy::abseil {
void DurationUnnecessaryConversionCheck::registerMatchers(MatchFinder *Finder) {
for (const auto &Scale : {"Hours", "Minutes", "Seconds", "Milliseconds",
"Microseconds", "Nanoseconds"}) {
- std::string DurationFactory = (llvm::Twine("::absl::") + Scale).str();
- std::string FloatConversion =
+ const std::string DurationFactory = (llvm::Twine("::absl::") + Scale).str();
+ const std::string FloatConversion =
(llvm::Twine("::absl::ToDouble") + Scale).str();
- std::string IntegerConversion =
+ const std::string IntegerConversion =
(llvm::Twine("::absl::ToInt64") + Scale).str();
// Matcher which matches the current scale's factory with a `1` argument,
diff --git a/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.h b/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.h
index 59af8968..f5d2511 100644
--- a/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.h
+++ b/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEDOUBLECONVERSIONCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEDOUBLECONVERSIONCHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONUNNECESSARYCONVERSIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONUNNECESSARYCONVERSIONCHECK_H
#include "../ClangTidyCheck.h"
@@ -31,4 +31,4 @@ public:
} // namespace clang::tidy::abseil
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEDOUBLECONVERSIONCHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONUNNECESSARYCONVERSIONCHECK_H
diff --git a/clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp b/clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
index d9f6551..0827526 100644
--- a/clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
@@ -29,7 +29,7 @@ makeCharacterLiteral(const StringLiteral *Literal, const ASTContext &Context) {
assert(Literal->getCharByteWidth() == 1 &&
"StrSplit doesn't support wide char");
std::string Result = clang::tooling::fixit::getText(*Literal, Context).str();
- bool IsRawStringLiteral = StringRef(Result).starts_with(R"(R")");
+ const bool IsRawStringLiteral = StringRef(Result).starts_with(R"(R")");
// Since raw string literal might contain unescaped non-printable characters,
// we normalize them using `StringLiteral::outputString`.
if (IsRawStringLiteral) {
diff --git a/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.cpp b/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.cpp
index c090e5a..5f4cb66 100644
--- a/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.cpp
@@ -32,7 +32,7 @@ void NoInternalDependenciesCheck::check(
const auto *InternalDependency =
Result.Nodes.getNodeAs<NestedNameSpecifierLoc>("InternalDep");
- SourceLocation LocAtFault =
+ const SourceLocation LocAtFault =
Result.SourceManager->getSpellingLoc(InternalDependency->getBeginLoc());
if (!LocAtFault.isValid())
diff --git a/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.h b/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.h
index 2911a1a..2291831 100644
--- a/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.h
+++ b/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_NOINTERNALDEPSCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_NOINTERNALDEPSCHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_NOINTERNALDEPENDENCIESCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_NOINTERNALDEPENDENCIESCHECK_H
#include "../ClangTidyCheck.h"
@@ -31,4 +31,4 @@ public:
} // namespace clang::tidy::abseil
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_NOINTERNALDEPSCHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_NOINTERNALDEPENDENCIESCHECK_H
diff --git a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
index 92d6305..e1063c4f 100644
--- a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
@@ -92,7 +92,7 @@ void StringFindStartswithCheck::check(const MatchFinder::MatchResult &Result) {
const auto *FindFun = Result.Nodes.getNodeAs<CXXMethodDecl>("findfun");
assert(FindFun != nullptr);
- bool Rev = FindFun->getName().contains("rfind");
+ const bool Rev = FindFun->getName().contains("rfind");
if (ComparisonExpr->getBeginLoc().isMacroID())
return;
@@ -107,7 +107,7 @@ void StringFindStartswithCheck::check(const MatchFinder::MatchResult &Result) {
Context.getLangOpts());
// Create the StartsWith string, negating if comparison was "!=".
- bool Neg = ComparisonExpr->getOpcode() == BO_NE;
+ const bool Neg = ComparisonExpr->getOpcode() == BO_NE;
// Create the warning message and a FixIt hint replacing the original expr.
auto Diagnostic =
diff --git a/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.cpp b/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.cpp
index 7a97a18..5d80b16 100644
--- a/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.cpp
@@ -39,9 +39,9 @@ void TimeComparisonCheck::check(const MatchFinder::MatchResult &Result) {
// want to handle the case of rewriting both sides. This is much simpler if
// we unconditionally try and rewrite both, and let the rewriter determine
// if nothing needs to be done.
- std::string LhsReplacement =
+ const std::string LhsReplacement =
rewriteExprFromNumberToTime(Result, *Scale, Binop->getLHS());
- std::string RhsReplacement =
+ const std::string RhsReplacement =
rewriteExprFromNumberToTime(Result, *Scale, Binop->getRHS());
diag(Binop->getBeginLoc(), "perform comparison in the time domain")
diff --git a/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.h b/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.h
index 703d951..74a877a 100644
--- a/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.h
+++ b/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMECOMPARECHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMECOMPARECHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMECOMPARISONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMECOMPARISONCHECK_H
#include "../ClangTidyCheck.h"
@@ -31,4 +31,4 @@ public:
} // namespace clang::tidy::abseil
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMECOMPARECHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMECOMPARISONCHECK_H
diff --git a/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp b/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
index 228d974..4ae49d2 100644
--- a/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
@@ -93,7 +93,7 @@ void TimeSubtractionCheck::emitDiagnostic(const Expr *Node,
void TimeSubtractionCheck::registerMatchers(MatchFinder *Finder) {
for (const char *ScaleName :
{"Hours", "Minutes", "Seconds", "Millis", "Micros", "Nanos"}) {
- std::string TimeInverse = (llvm::Twine("ToUnix") + ScaleName).str();
+ const std::string TimeInverse = (llvm::Twine("ToUnix") + ScaleName).str();
std::optional<DurationScale> Scale = getScaleForTimeInverse(TimeInverse);
assert(Scale && "Unknown scale encountered");
@@ -127,7 +127,7 @@ void TimeSubtractionCheck::registerMatchers(MatchFinder *Finder) {
void TimeSubtractionCheck::check(const MatchFinder::MatchResult &Result) {
const auto *BinOp = Result.Nodes.getNodeAs<BinaryOperator>("binop");
- std::string InverseName =
+ const std::string InverseName =
Result.Nodes.getNodeAs<FunctionDecl>("func_decl")->getNameAsString();
if (insideMacroDefinition(Result, BinOp->getSourceRange()))
return;
@@ -144,7 +144,7 @@ void TimeSubtractionCheck::check(const MatchFinder::MatchResult &Result) {
// We're working with the first case of matcher, and need to replace the
// entire 'Duration' factory call. (Which also means being careful about
// our order-of-operations and optionally putting in some parenthesis.
- bool NeedParens = parensRequired(Result, OuterCall);
+ const bool NeedParens = parensRequired(Result, OuterCall);
emitDiagnostic(
OuterCall,
@@ -169,7 +169,7 @@ void TimeSubtractionCheck::check(const MatchFinder::MatchResult &Result) {
// converts it from the inverse to a Duration. In this case, we replace
// the outer with just the subtraction expression, which gives the right
// type and scale, taking care again about parenthesis.
- bool NeedParens = parensRequired(Result, MaybeCallArg);
+ const bool NeedParens = parensRequired(Result, MaybeCallArg);
emitDiagnostic(
MaybeCallArg,
diff --git a/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp b/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
index 8b197e5b..1a6ff30 100644
--- a/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
@@ -117,10 +117,10 @@ void UpgradeDurationConversionsCheck::check(
"implicit conversion to 'int64_t' is deprecated in this context; use an "
"explicit cast instead";
- TraversalKindScope RAII(*Result.Context, TK_AsIs);
+ const TraversalKindScope RAII(*Result.Context, TK_AsIs);
const auto *ArgExpr = Result.Nodes.getNodeAs<Expr>("arg");
- SourceLocation Loc = ArgExpr->getBeginLoc();
+ const SourceLocation Loc = ArgExpr->getBeginLoc();
const auto *OuterExpr = Result.Nodes.getNodeAs<Expr>("OuterExpr");
@@ -139,13 +139,13 @@ void UpgradeDurationConversionsCheck::check(
// We gather source locations from template matches not in template
// instantiations for future matches.
- internal::Matcher<Stmt> IsInsideTemplate =
+ const internal::Matcher<Stmt> IsInsideTemplate =
hasAncestor(decl(anyOf(classTemplateDecl(), functionTemplateDecl())));
if (!match(IsInsideTemplate, *ArgExpr, *Result.Context).empty())
MatchedTemplateLocations.insert(Loc);
- DiagnosticBuilder Diag = diag(Loc, Message);
- CharSourceRange SourceRange = Lexer::makeFileCharRange(
+ const DiagnosticBuilder Diag = diag(Loc, Message);
+ const CharSourceRange SourceRange = Lexer::makeFileCharRange(
CharSourceRange::getTokenRange(ArgExpr->getSourceRange()),
*Result.SourceManager, Result.Context->getLangOpts());
if (SourceRange.isInvalid())
diff --git a/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp b/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
index 49ba17c..519d909 100644
--- a/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
+++ b/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
@@ -76,7 +76,7 @@ void IdDependentBackwardBranchCheck::registerMatchers(MatchFinder *Finder) {
this);
}
-IdDependentBackwardBranchCheck::IdDependencyRecord *
+const IdDependentBackwardBranchCheck::IdDependencyRecord *
IdDependentBackwardBranchCheck::hasIdDepVar(const Expr *Expression) {
if (!Expression)
return nullptr;
@@ -94,12 +94,12 @@ IdDependentBackwardBranchCheck::hasIdDepVar(const Expr *Expression) {
}
for (const auto *Child : Expression->children())
if (const auto *ChildExpression = dyn_cast_if_present<Expr>(Child))
- if (IdDependencyRecord *Result = hasIdDepVar(ChildExpression))
+ if (const IdDependencyRecord *Result = hasIdDepVar(ChildExpression))
return Result;
return nullptr;
}
-IdDependentBackwardBranchCheck::IdDependencyRecord *
+const IdDependentBackwardBranchCheck::IdDependencyRecord *
IdDependentBackwardBranchCheck::hasIdDepField(const Expr *Expression) {
if (!Expression)
return nullptr;
@@ -116,7 +116,7 @@ IdDependentBackwardBranchCheck::hasIdDepField(const Expr *Expression) {
}
for (const auto *Child : Expression->children())
if (const auto *ChildExpression = dyn_cast_if_present<Expr>(Child))
- if (IdDependencyRecord *Result = hasIdDepField(ChildExpression))
+ if (const IdDependencyRecord *Result = hasIdDepField(ChildExpression))
return Result;
return nullptr;
}
@@ -239,7 +239,7 @@ void IdDependentBackwardBranchCheck::check(
const auto *Loop = Result.Nodes.getNodeAs<Stmt>("backward_branch");
if (!Loop)
return;
- LoopType Type = getLoopType(Loop);
+ const LoopType Type = getLoopType(Loop);
if (CondExpr) {
if (IDCall) { // Conditional expression calls an ID function directly.
diag(CondExpr->getBeginLoc(),
@@ -249,8 +249,8 @@ void IdDependentBackwardBranchCheck::check(
return;
}
// Conditional expression has DeclRefExpr(s), check ID-dependency.
- IdDependencyRecord *IdDepVar = hasIdDepVar(CondExpr);
- IdDependencyRecord *IdDepField = hasIdDepField(CondExpr);
+ const IdDependencyRecord *IdDepVar = hasIdDepVar(CondExpr);
+ const IdDependencyRecord *IdDepField = hasIdDepField(CondExpr);
if (IdDepVar) {
diag(CondExpr->getBeginLoc(),
"backward branch (%select{do|while|for}0 loop) is ID-dependent due "
diff --git a/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.h b/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.h
index b777918..297e775 100644
--- a/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.h
+++ b/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.h
@@ -44,10 +44,10 @@ private:
std::map<const FieldDecl *, IdDependencyRecord> IdDepFieldsMap;
/// Returns an IdDependencyRecord if the Expression contains an ID-dependent
/// variable, returns a nullptr otherwise.
- IdDependencyRecord *hasIdDepVar(const Expr *Expression);
+ const IdDependencyRecord *hasIdDepVar(const Expr *Expression);
/// Returns an IdDependencyRecord if the Expression contains an ID-dependent
/// field, returns a nullptr otherwise.
- IdDependencyRecord *hasIdDepField(const Expr *Expression);
+ const IdDependencyRecord *hasIdDepField(const Expr *Expression);
/// Stores the location an ID-dependent variable is created from a call to
/// an ID function in IdDepVarsMap.
void saveIdDepVar(const Stmt *Statement, const VarDecl *Variable);
diff --git a/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp b/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp
index 4c740e3..ea98d01 100644
--- a/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp
@@ -74,10 +74,9 @@ bool KernelNameRestrictionPPCallbacks::fileNameIsRestricted(
}
void KernelNameRestrictionPPCallbacks::EndOfMainFile() {
-
// Check main file for restricted names.
OptionalFileEntryRef Entry = SM.getFileEntryRefForID(SM.getMainFileID());
- StringRef FileName = llvm::sys::path::filename(Entry->getName());
+ const StringRef FileName = llvm::sys::path::filename(Entry->getName());
if (fileNameIsRestricted(FileName))
Check.diag(SM.getLocForStartOfFile(SM.getMainFileID()),
"compiling '%0' may cause additional compilation errors due "
@@ -90,7 +89,7 @@ void KernelNameRestrictionPPCallbacks::EndOfMainFile() {
// Check included files for restricted names.
for (const IncludeDirective &ID : IncludeDirectives) {
- StringRef FileName = llvm::sys::path::filename(ID.FileName);
+ const StringRef FileName = llvm::sys::path::filename(ID.FileName);
if (fileNameIsRestricted(FileName))
Check.diag(ID.Loc,
"including '%0' may cause additional compilation errors due "
diff --git a/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.h b/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.h
index 182d10b..441cf36 100644
--- a/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.h
+++ b/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_KERNEL_NAME_RESTRICTION_CHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_KERNEL_NAME_RESTRICTION_CHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_KERNELNAMERESTRICTIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_KERNELNAMERESTRICTIONCHECK_H
#include "../ClangTidyCheck.h"
@@ -28,4 +28,4 @@ public:
} // namespace clang::tidy::altera
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_KERNEL_NAME_RESTRICTION_CHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_KERNELNAMERESTRICTIONCHECK_H
diff --git a/clang-tools-extra/clang-tidy/altera/SingleWorkItemBarrierCheck.h b/clang-tools-extra/clang-tidy/altera/SingleWorkItemBarrierCheck.h
index dab3dbc..dcfefcb 100644
--- a/clang-tools-extra/clang-tidy/altera/SingleWorkItemBarrierCheck.h
+++ b/clang-tools-extra/clang-tidy/altera/SingleWorkItemBarrierCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_SINGLE_WORK_ITEM_BARRIER_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_SINGLE_WORK_ITEM_BARRIER_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_SINGLEWORKITEMBARRIERCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_SINGLEWORKITEMBARRIERCHECK_H
#include "../ClangTidyCheck.h"
@@ -33,4 +33,4 @@ public:
} // namespace clang::tidy::altera
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_SINGLE_WORK_ITEM_BARRIER_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_SINGLEWORKITEMBARRIERCHECK_H
diff --git a/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp b/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
index 0a19378..d90305d 100644
--- a/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
+++ b/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
@@ -60,33 +60,33 @@ void StructPackAlignCheck::check(const MatchFinder::MatchResult &Result) {
// For each StructField, record how big it is (in bits).
// Would be good to use a pair of <offset, size> to advise a better
// packing order.
- QualType StructFieldTy = StructField->getType();
+ const QualType StructFieldTy = StructField->getType();
if (StructFieldTy->isIncompleteType())
return;
- unsigned int StructFieldWidth =
- (unsigned int)Result.Context->getTypeInfo(StructFieldTy.getTypePtr())
- .Width;
+ const unsigned int StructFieldWidth = static_cast<unsigned int>(
+ Result.Context->getTypeInfo(StructFieldTy.getTypePtr()).Width);
FieldSizes.emplace_back(StructFieldWidth, StructField->getFieldIndex());
// FIXME: Recommend a reorganization of the struct (sort by StructField
// size, largest to smallest).
TotalBitSize += StructFieldWidth;
}
- uint64_t CharSize = Result.Context->getCharWidth();
- CharUnits CurrSize = Result.Context->getASTRecordLayout(Struct).getSize();
- CharUnits MinByteSize =
+ const uint64_t CharSize = Result.Context->getCharWidth();
+ const CharUnits CurrSize =
+ Result.Context->getASTRecordLayout(Struct).getSize();
+ const CharUnits MinByteSize =
CharUnits::fromQuantity(std::max<clang::CharUnits::QuantityType>(
std::ceil(static_cast<float>(TotalBitSize) / CharSize), 1));
- CharUnits MaxAlign = CharUnits::fromQuantity(
- std::ceil((float)Struct->getMaxAlignment() / CharSize));
- CharUnits CurrAlign =
+ const CharUnits MaxAlign = CharUnits::fromQuantity(
+ std::ceil(static_cast<float>(Struct->getMaxAlignment()) / CharSize));
+ const CharUnits CurrAlign =
Result.Context->getASTRecordLayout(Struct).getAlignment();
- CharUnits NewAlign = computeRecommendedAlignment(MinByteSize);
+ const CharUnits NewAlign = computeRecommendedAlignment(MinByteSize);
- bool IsPacked = Struct->hasAttr<PackedAttr>();
- bool NeedsPacking = (MinByteSize < CurrSize) && (MaxAlign != NewAlign) &&
- (CurrSize != NewAlign);
- bool NeedsAlignment = CurrAlign.getQuantity() != NewAlign.getQuantity();
+ const bool IsPacked = Struct->hasAttr<PackedAttr>();
+ const bool NeedsPacking = (MinByteSize < CurrSize) &&
+ (MaxAlign != NewAlign) && (CurrSize != NewAlign);
+ const bool NeedsAlignment = CurrAlign.getQuantity() != NewAlign.getQuantity();
if (!NeedsAlignment && !NeedsPacking)
return;
@@ -98,8 +98,7 @@ void StructPackAlignCheck::check(const MatchFinder::MatchResult &Result) {
diag(Struct->getLocation(),
"accessing fields in struct %0 is inefficient due to padding; only "
"needs %1 bytes but is using %2 bytes")
- << Struct << (int)MinByteSize.getQuantity()
- << (int)CurrSize.getQuantity()
+ << Struct << MinByteSize.getQuantity() << CurrSize.getQuantity()
<< FixItHint::CreateInsertion(Struct->getEndLoc().getLocWithOffset(1),
" __attribute__((packed))");
diag(Struct->getLocation(),
@@ -111,7 +110,7 @@ void StructPackAlignCheck::check(const MatchFinder::MatchResult &Result) {
FixItHint FixIt;
auto *Attribute = Struct->getAttr<AlignedAttr>();
- std::string NewAlignQuantity = std::to_string((int)NewAlign.getQuantity());
+ const std::string NewAlignQuantity = std::to_string(NewAlign.getQuantity());
if (Attribute) {
FixIt = FixItHint::CreateReplacement(
Attribute->getRange(),
@@ -128,7 +127,7 @@ void StructPackAlignCheck::check(const MatchFinder::MatchResult &Result) {
diag(Struct->getLocation(),
"accessing fields in struct %0 is inefficient due to poor alignment; "
"currently aligned to %1 bytes, but recommended alignment is %2 bytes")
- << Struct << (int)CurrAlign.getQuantity() << NewAlignQuantity << FixIt;
+ << Struct << CurrAlign.getQuantity() << NewAlignQuantity << FixIt;
diag(Struct->getLocation(),
"use \"__attribute__((aligned(%0)))\" to align struct %1 to %0 bytes",
diff --git a/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp b/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
index e90cdd0..c759e5b 100644
--- a/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
@@ -127,7 +127,7 @@ bool UnrollLoopsCheck::hasKnownBounds(const Stmt *Statement,
if (const auto *InitDeclStatement = dyn_cast<DeclStmt>(Initializer)) {
if (const auto *VariableDecl =
dyn_cast<VarDecl>(InitDeclStatement->getSingleDecl())) {
- APValue *Evaluation = VariableDecl->evaluateValue();
+ const APValue *Evaluation = VariableDecl->evaluateValue();
if (!Evaluation || !Evaluation->hasValue())
return false;
}
@@ -208,20 +208,22 @@ bool UnrollLoopsCheck::hasLargeNumIterations(const Stmt *Statement,
return true;
switch (Op->getOpcode()) {
case (BO_AddAssign):
- Iterations = std::ceil(float(EndValue - InitValue) / ConstantValue);
+ Iterations =
+ std::ceil(static_cast<float>(EndValue - InitValue) / ConstantValue);
break;
case (BO_SubAssign):
- Iterations = std::ceil(float(InitValue - EndValue) / ConstantValue);
+ Iterations =
+ std::ceil(static_cast<float>(InitValue - EndValue) / ConstantValue);
break;
case (BO_MulAssign):
- Iterations =
- 1 + ((std::log((double)EndValue) - std::log((double)InitValue)) /
- std::log((double)ConstantValue));
+ Iterations = 1 + ((std::log(static_cast<double>(EndValue)) -
+ std::log(static_cast<double>(InitValue))) /
+ std::log(static_cast<double>(ConstantValue)));
break;
case (BO_DivAssign):
- Iterations =
- 1 + ((std::log((double)InitValue) - std::log((double)EndValue)) /
- std::log((double)ConstantValue));
+ Iterations = 1 + ((std::log(static_cast<double>(InitValue)) -
+ std::log(static_cast<double>(EndValue))) /
+ std::log(static_cast<double>(ConstantValue)));
break;
default:
// All other operators are not handled; assume large bounds.
diff --git a/clang-tools-extra/clang-tidy/android/CloexecAccept4Check.h b/clang-tools-extra/clang-tidy/android/CloexecAccept4Check.h
index 02c4e00..5637fc8 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecAccept4Check.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecAccept4Check.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT4_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT4_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECACCEPT4CHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECACCEPT4CHECK_H
#include "CloexecCheck.h"
@@ -27,4 +27,4 @@ public:
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT4_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECACCEPT4CHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecAcceptCheck.cpp b/clang-tools-extra/clang-tidy/android/CloexecAcceptCheck.cpp
index 9cd888c..a624523 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecAcceptCheck.cpp
+++ b/clang-tools-extra/clang-tidy/android/CloexecAcceptCheck.cpp
@@ -26,10 +26,11 @@ void CloexecAcceptCheck::registerMatchers(MatchFinder *Finder) {
}
void CloexecAcceptCheck::check(const MatchFinder::MatchResult &Result) {
- std::string ReplacementText = (Twine("accept4(") + getSpellingArg(Result, 0) +
- ", " + getSpellingArg(Result, 1) + ", " +
- getSpellingArg(Result, 2) + ", SOCK_CLOEXEC)")
- .str();
+ const std::string ReplacementText =
+ (Twine("accept4(") + getSpellingArg(Result, 0) + ", " +
+ getSpellingArg(Result, 1) + ", " + getSpellingArg(Result, 2) +
+ ", SOCK_CLOEXEC)")
+ .str();
replaceFunc(
Result,
diff --git a/clang-tools-extra/clang-tidy/android/CloexecAcceptCheck.h b/clang-tools-extra/clang-tidy/android/CloexecAcceptCheck.h
index 4540f93..332a97a 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecAcceptCheck.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecAcceptCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECACCEPTCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECACCEPTCHECK_H
#include "CloexecCheck.h"
@@ -27,4 +27,4 @@ public:
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECACCEPTCHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecCheck.cpp b/clang-tools-extra/clang-tidy/android/CloexecCheck.cpp
index 48c54c0..ff86fc5 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecCheck.cpp
+++ b/clang-tools-extra/clang-tidy/android/CloexecCheck.cpp
@@ -30,12 +30,13 @@ static std::string buildFixMsgForStringFlag(const Expr *Arg,
" \"" + Twine(Mode) + "\"")
.str();
- StringRef SR = cast<StringLiteral>(Arg->IgnoreParenCasts())->getString();
+ const StringRef SR =
+ cast<StringLiteral>(Arg->IgnoreParenCasts())->getString();
return ("\"" + SR + Twine(Mode) + "\"").str();
}
void CloexecCheck::registerMatchersImpl(
- MatchFinder *Finder, internal::Matcher<FunctionDecl> Function) {
+ MatchFinder *Finder, const internal::Matcher<FunctionDecl> &Function) {
// We assume all the checked APIs are C functions.
Finder->addMatcher(
callExpr(
@@ -49,14 +50,14 @@ void CloexecCheck::insertMacroFlag(const MatchFinder::MatchResult &Result,
const auto *MatchedCall = Result.Nodes.getNodeAs<CallExpr>(FuncBindingStr);
const auto *FlagArg = MatchedCall->getArg(ArgPos);
const auto *FD = Result.Nodes.getNodeAs<FunctionDecl>(FuncDeclBindingStr);
- SourceManager &SM = *Result.SourceManager;
+ const SourceManager &SM = *Result.SourceManager;
if (utils::exprHasBitFlagWithSpelling(FlagArg->IgnoreParenCasts(), SM,
Result.Context->getLangOpts(),
MacroFlag))
return;
- SourceLocation EndLoc =
+ const SourceLocation EndLoc =
Lexer::getLocForEndOfToken(SM.getFileLoc(FlagArg->getEndLoc()), 0, SM,
Result.Context->getLangOpts());
@@ -84,7 +85,7 @@ void CloexecCheck::insertStringFlag(
if (!ModeStr || ModeStr->getString().contains(Mode))
return;
- std::string ReplacementText = buildFixMsgForStringFlag(
+ const std::string ReplacementText = buildFixMsgForStringFlag(
ModeArg, *Result.SourceManager, Result.Context->getLangOpts(), Mode);
diag(ModeArg->getBeginLoc(), "use %0 mode '%1' to set O_CLOEXEC")
diff --git a/clang-tools-extra/clang-tidy/android/CloexecCheck.h b/clang-tools-extra/clang-tidy/android/CloexecCheck.h
index 858d96a..a6dcb57 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecCheck.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecCheck.h
@@ -12,8 +12,8 @@
///
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECCHECK_H
#include "../ClangTidyCheck.h"
@@ -29,9 +29,9 @@ public:
: ClangTidyCheck(Name, Context) {}
protected:
- void
- registerMatchersImpl(ast_matchers::MatchFinder *Finder,
- ast_matchers::internal::Matcher<FunctionDecl> Function);
+ void registerMatchersImpl(
+ ast_matchers::MatchFinder *Finder,
+ const ast_matchers::internal::Matcher<FunctionDecl> &Function);
/// Currently, we have three types of fixes.
///
@@ -97,4 +97,4 @@ protected:
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECCHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecCreatCheck.h b/clang-tools-extra/clang-tidy/android/CloexecCreatCheck.h
index ee2f51a..d7d2b42 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecCreatCheck.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecCreatCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_CREAT_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_CREAT_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECCREATCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECCREATCHECK_H
#include "CloexecCheck.h"
@@ -27,4 +27,4 @@ public:
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_CREAT_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECCREATCHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecDupCheck.cpp b/clang-tools-extra/clang-tidy/android/CloexecDupCheck.cpp
index 5ac1b6f..5db5746 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecDupCheck.cpp
+++ b/clang-tools-extra/clang-tidy/android/CloexecDupCheck.cpp
@@ -20,7 +20,7 @@ void CloexecDupCheck::registerMatchers(MatchFinder *Finder) {
}
void CloexecDupCheck::check(const MatchFinder::MatchResult &Result) {
- std::string ReplacementText =
+ const std::string ReplacementText =
(Twine("fcntl(") + getSpellingArg(Result, 0) + ", F_DUPFD_CLOEXEC)")
.str();
diff --git a/clang-tools-extra/clang-tidy/android/CloexecDupCheck.h b/clang-tools-extra/clang-tidy/android/CloexecDupCheck.h
index f569968..4eae507 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecDupCheck.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecDupCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_DUP_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_DUP_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECDUPCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECDUPCHECK_H
#include "CloexecCheck.h"
@@ -28,4 +28,4 @@ public:
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_DUP_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECDUPCHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecEpollCreate1Check.h b/clang-tools-extra/clang-tidy/android/CloexecEpollCreate1Check.h
index f467b87..03a529f 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecEpollCreate1Check.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecEpollCreate1Check.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE1_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE1_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECEPOLLCREATE1CHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECEPOLLCREATE1CHECK_H
#include "CloexecCheck.h"
@@ -27,4 +27,4 @@ public:
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE1_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECEPOLLCREATE1CHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecEpollCreateCheck.h b/clang-tools-extra/clang-tidy/android/CloexecEpollCreateCheck.h
index a8d17c8..243b9bd 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecEpollCreateCheck.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecEpollCreateCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECEPOLLCREATECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECEPOLLCREATECHECK_H
#include "CloexecCheck.h"
@@ -27,4 +27,4 @@ public:
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECEPOLLCREATECHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecFopenCheck.h b/clang-tools-extra/clang-tidy/android/CloexecFopenCheck.h
index 646b237..a018fc5 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecFopenCheck.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecFopenCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_FOPEN_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_FOPEN_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECFOPENCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECFOPENCHECK_H
#include "CloexecCheck.h"
@@ -30,4 +30,4 @@ public:
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_FOPEN_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECFOPENCHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecInotifyInit1Check.h b/clang-tools-extra/clang-tidy/android/CloexecInotifyInit1Check.h
index 3960d05..c2e4533 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecInotifyInit1Check.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecInotifyInit1Check.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_INOTIFY_INIT1_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_INOTIFY_INIT1_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECINOTIFYINIT1CHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECINOTIFYINIT1CHECK_H
#include "CloexecCheck.h"
@@ -27,4 +27,4 @@ public:
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_INOTIFY_INIT1_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECINOTIFYINIT1CHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecInotifyInitCheck.h b/clang-tools-extra/clang-tidy/android/CloexecInotifyInitCheck.h
index cb9e682..cd202c2 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecInotifyInitCheck.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecInotifyInitCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_INOTIFY_INIT_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_INOTIFY_INIT_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECINOTIFYINITCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECINOTIFYINITCHECK_H
#include "CloexecCheck.h"
@@ -27,4 +27,4 @@ public:
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_INOTIFY_INIT_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECINOTIFYINITCHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecMemfdCreateCheck.h b/clang-tools-extra/clang-tidy/android/CloexecMemfdCreateCheck.h
index dd96ee9..1a77c7f 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecMemfdCreateCheck.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecMemfdCreateCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_MEMFD_CREATE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_MEMFD_CREATE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECMEMFDCREATECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECMEMFDCREATECHECK_H
#include "CloexecCheck.h"
@@ -27,4 +27,4 @@ public:
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_MEMFD_CREATE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECMEMFDCREATECHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecOpenCheck.cpp b/clang-tools-extra/clang-tidy/android/CloexecOpenCheck.cpp
index 8c24482..9938027 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecOpenCheck.cpp
+++ b/clang-tools-extra/clang-tidy/android/CloexecOpenCheck.cpp
@@ -30,7 +30,7 @@ void CloexecOpenCheck::registerMatchers(MatchFinder *Finder) {
void CloexecOpenCheck::check(const MatchFinder::MatchResult &Result) {
const auto *FD = Result.Nodes.getNodeAs<FunctionDecl>(FuncDeclBindingStr);
assert(FD->param_size() > 1);
- int ArgPos = (FD->param_size() > 2) ? 2 : 1;
+ const int ArgPos = (FD->param_size() > 2) ? 2 : 1;
insertMacroFlag(Result, /*MacroFlag=*/"O_CLOEXEC", ArgPos);
}
diff --git a/clang-tools-extra/clang-tidy/android/CloexecOpenCheck.h b/clang-tools-extra/clang-tidy/android/CloexecOpenCheck.h
index d95fe21..d30b456 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecOpenCheck.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecOpenCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_OPEN_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_OPEN_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECOPENCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECOPENCHECK_H
#include "CloexecCheck.h"
@@ -32,4 +32,4 @@ public:
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_OPEN_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECOPENCHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecPipe2Check.h b/clang-tools-extra/clang-tidy/android/CloexecPipe2Check.h
index 496bd6b..3165308 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecPipe2Check.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecPipe2Check.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_PIPE2_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_PIPE2_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECPIPE2CHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECPIPE2CHECK_H
#include "CloexecCheck.h"
@@ -27,4 +27,4 @@ public:
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_PIPE2_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECPIPE2CHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp b/clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp
index a475dff..37e3c56 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp
@@ -20,7 +20,7 @@ void CloexecPipeCheck::registerMatchers(MatchFinder *Finder) {
}
void CloexecPipeCheck::check(const MatchFinder::MatchResult &Result) {
- std::string ReplacementText =
+ const std::string ReplacementText =
(Twine("pipe2(") + getSpellingArg(Result, 0) + ", O_CLOEXEC)").str();
replaceFunc(Result,
diff --git a/clang-tools-extra/clang-tidy/android/CloexecPipeCheck.h b/clang-tools-extra/clang-tidy/android/CloexecPipeCheck.h
index f0145e1..721a688 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecPipeCheck.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecPipeCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_PIPE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_PIPE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECPIPECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECPIPECHECK_H
#include "CloexecCheck.h"
@@ -27,4 +27,4 @@ public:
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_PIPE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECPIPECHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecSocketCheck.h b/clang-tools-extra/clang-tidy/android/CloexecSocketCheck.h
index 0a29d72..8865db3a 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecSocketCheck.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecSocketCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_SOCKET_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_SOCKET_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECSOCKETCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECSOCKETCHECK_H
#include "CloexecCheck.h"
@@ -27,4 +27,4 @@ public:
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_SOCKET_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECSOCKETCHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.cpp b/clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.cpp
index 36ac9a4..c42f069 100644
--- a/clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.cpp
+++ b/clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.cpp
@@ -64,7 +64,7 @@ void ComparisonInTempFailureRetryCheck::check(
const LangOptions &Opts = Result.Context->getLangOpts();
SourceLocation LocStart = Node.getBeginLoc();
while (LocStart.isMacroID()) {
- SourceLocation Invocation = SM.getImmediateMacroCallerLoc(LocStart);
+ const SourceLocation Invocation = SM.getImmediateMacroCallerLoc(LocStart);
Token Tok;
if (!Lexer::getRawToken(SM.getSpellingLoc(Invocation), Tok, SM, Opts,
/*IgnoreWhiteSpace=*/true)) {
diff --git a/clang-tools-extra/clang-tidy/boost/UseRangesCheck.cpp b/clang-tools-extra/clang-tidy/boost/UseRangesCheck.cpp
index 34ecee5..970cbd9 100644
--- a/clang-tools-extra/clang-tidy/boost/UseRangesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/boost/UseRangesCheck.cpp
@@ -18,6 +18,7 @@
#include <initializer_list>
#include <optional>
#include <string>
+#include <utility>
// FixItHint - Let the docs script know that this class does provide fixits
@@ -200,7 +201,6 @@ private:
} // namespace
utils::UseRangesCheck::ReplacerMap UseRangesCheck::getReplacerMap() const {
-
ReplacerMap Results;
static const Signature SingleSig = {{0}};
static const Signature TwoSig = {{0}, {2}};
@@ -217,11 +217,11 @@ utils::UseRangesCheck::ReplacerMap UseRangesCheck::getReplacerMap() const {
const auto AddFromStd =
[&](llvm::IntrusiveRefCntPtr<UseRangesCheck::Replacer> Replacer,
std::initializer_list<StringRef> Names) {
- AddFrom(Replacer, Names, "std");
+ AddFrom(std::move(Replacer), Names, "std");
};
const auto AddFromBoost =
- [&](llvm::IntrusiveRefCntPtr<UseRangesCheck::Replacer> Replacer,
+ [&](const llvm::IntrusiveRefCntPtr<UseRangesCheck::Replacer> &Replacer,
std::initializer_list<
std::pair<StringRef, std::initializer_list<StringRef>>>
NamespaceAndNames) {
@@ -341,7 +341,7 @@ void UseRangesCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
}
DiagnosticBuilder UseRangesCheck::createDiag(const CallExpr &Call) {
- DiagnosticBuilder D =
+ const DiagnosticBuilder D =
diag(Call.getBeginLoc(), "use a %0 version of this algorithm");
D << (Call.getDirectCallee()->isInStdNamespace() ? "boost" : "ranged");
return D;
diff --git a/clang-tools-extra/clang-tidy/boost/UseToStringCheck.h b/clang-tools-extra/clang-tidy/boost/UseToStringCheck.h
index af87f15..dae3f7c 100644
--- a/clang-tools-extra/clang-tidy/boost/UseToStringCheck.h
+++ b/clang-tools-extra/clang-tidy/boost/UseToStringCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BOOST_USE_TO_STRING_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BOOST_USE_TO_STRING_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BOOST_USETOSTRINGCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BOOST_USETOSTRINGCHECK_H
#include "../ClangTidyCheck.h"
@@ -32,4 +32,4 @@ public:
} // namespace clang::tidy::boost
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BOOST_USE_TO_STRING_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BOOST_USETOSTRINGCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
index c0a778a..ed30d01 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
@@ -81,14 +81,16 @@ static std::vector<std::pair<SourceLocation, StringRef>>
getCommentsInRange(ASTContext *Ctx, CharSourceRange Range) {
std::vector<std::pair<SourceLocation, StringRef>> Comments;
auto &SM = Ctx->getSourceManager();
- std::pair<FileID, unsigned> BeginLoc = SM.getDecomposedLoc(Range.getBegin()),
- EndLoc = SM.getDecomposedLoc(Range.getEnd());
+ const std::pair<FileID, unsigned> BeginLoc =
+ SM.getDecomposedLoc(Range.getBegin()),
+ EndLoc =
+ SM.getDecomposedLoc(Range.getEnd());
if (BeginLoc.first != EndLoc.first)
return Comments;
bool Invalid = false;
- StringRef Buffer = SM.getBufferData(BeginLoc.first, &Invalid);
+ const StringRef Buffer = SM.getBufferData(BeginLoc.first, &Invalid);
if (Invalid)
return Comments;
@@ -106,7 +108,7 @@ getCommentsInRange(ASTContext *Ctx, CharSourceRange Range) {
break;
if (Tok.is(tok::comment)) {
- std::pair<FileID, unsigned> CommentLoc =
+ const std::pair<FileID, unsigned> CommentLoc =
SM.getDecomposedLoc(Tok.getLocation());
assert(CommentLoc.first == BeginLoc.first);
Comments.emplace_back(
@@ -125,7 +127,7 @@ static std::vector<std::pair<SourceLocation, StringRef>>
getCommentsBeforeLoc(ASTContext *Ctx, SourceLocation Loc) {
std::vector<std::pair<SourceLocation, StringRef>> Comments;
while (Loc.isValid()) {
- clang::Token Tok = utils::lexer::getPreviousToken(
+ const clang::Token Tok = utils::lexer::getPreviousToken(
Loc, Ctx->getSourceManager(), Ctx->getLangOpts(),
/*SkipComments=*/false);
if (Tok.isNot(tok::comment))
@@ -142,11 +144,11 @@ getCommentsBeforeLoc(ASTContext *Ctx, SourceLocation Loc) {
static bool isLikelyTypo(llvm::ArrayRef<ParmVarDecl *> Params,
StringRef ArgName, unsigned ArgIndex) {
- std::string ArgNameLowerStr = ArgName.lower();
- StringRef ArgNameLower = ArgNameLowerStr;
+ const std::string ArgNameLowerStr = ArgName.lower();
+ const StringRef ArgNameLower = ArgNameLowerStr;
// The threshold is arbitrary.
- unsigned UpperBound = ((ArgName.size() + 2) / 3) + 1;
- unsigned ThisED = ArgNameLower.edit_distance(
+ const unsigned UpperBound = ((ArgName.size() + 2) / 3) + 1;
+ const unsigned ThisED = ArgNameLower.edit_distance(
Params[ArgIndex]->getIdentifier()->getName().lower(),
/*AllowReplacements=*/true, UpperBound);
if (ThisED >= UpperBound)
@@ -155,7 +157,7 @@ static bool isLikelyTypo(llvm::ArrayRef<ParmVarDecl *> Params,
for (unsigned I = 0, E = Params.size(); I != E; ++I) {
if (I == ArgIndex)
continue;
- IdentifierInfo *II = Params[I]->getIdentifier();
+ const IdentifierInfo *II = Params[I]->getIdentifier();
if (!II)
continue;
@@ -163,9 +165,9 @@ static bool isLikelyTypo(llvm::ArrayRef<ParmVarDecl *> Params,
// Other parameters must be an edit distance at least Threshold more away
// from this parameter. This gives us greater confidence that this is a
// typo of this parameter and not one with a similar name.
- unsigned OtherED = ArgNameLower.edit_distance(II->getName().lower(),
- /*AllowReplacements=*/true,
- ThisED + Threshold);
+ const unsigned OtherED = ArgNameLower.edit_distance(
+ II->getName().lower(),
+ /*AllowReplacements=*/true, ThisED + Threshold);
if (OtherED < ThisED + Threshold)
return false;
}
@@ -267,7 +269,8 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
return;
Callee = Callee->getFirstDecl();
- unsigned NumArgs = std::min<unsigned>(Args.size(), Callee->getNumParams());
+ const unsigned NumArgs =
+ std::min<unsigned>(Args.size(), Callee->getNumParams());
if ((NumArgs == 0) || (IgnoreSingleArgument && NumArgs == 1))
return;
@@ -279,7 +282,7 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
for (unsigned I = 0; I < NumArgs; ++I) {
const ParmVarDecl *PVD = Callee->getParamDecl(I);
- IdentifierInfo *II = PVD->getIdentifier();
+ const IdentifierInfo *II = PVD->getIdentifier();
if (!II)
continue;
if (FunctionDecl *Template = Callee->getTemplateInstantiationPattern()) {
@@ -293,7 +296,7 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
}
}
- CharSourceRange BeforeArgument =
+ const CharSourceRange BeforeArgument =
MakeFileCharRange(ArgBeginLoc, Args[I]->getBeginLoc());
ArgBeginLoc = Args[I]->getEndLoc();
@@ -302,7 +305,7 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
Comments = getCommentsInRange(Ctx, BeforeArgument);
} else {
// Fall back to parsing back from the start of the argument.
- CharSourceRange ArgsRange =
+ const CharSourceRange ArgsRange =
MakeFileCharRange(Args[I]->getBeginLoc(), Args[I]->getEndLoc());
Comments = getCommentsBeforeLoc(Ctx, ArgsRange.getBegin());
}
@@ -312,7 +315,7 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
if (IdentRE.match(Comment.second, &Matches) &&
!sameName(Matches[2], II->getName(), StrictMode)) {
{
- DiagnosticBuilder Diag =
+ const DiagnosticBuilder Diag =
diag(Comment.first, "argument name '%0' in comment does not "
"match parameter name %1")
<< Matches[2] << II;
@@ -332,9 +335,9 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
// If the argument comments are missing for literals add them.
if (Comments.empty() && shouldAddComment(Args[I])) {
- std::string ArgComment =
+ const std::string ArgComment =
(llvm::Twine("/*") + II->getName() + "=*/").str();
- DiagnosticBuilder Diag =
+ const DiagnosticBuilder Diag =
diag(Args[I]->getBeginLoc(),
"argument comment missing for literal argument %0")
<< II
diff --git a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
index 1700502..a29aa55 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
@@ -29,7 +29,7 @@ AST_MATCHER_P2(Expr, hasSideEffect, bool, CheckFunctionCalls,
const Expr *E = &Node;
if (const auto *Op = dyn_cast<UnaryOperator>(E)) {
- UnaryOperator::Opcode OC = Op->getOpcode();
+ const UnaryOperator::Opcode OC = Op->getOpcode();
return OC == UO_PostInc || OC == UO_PostDec || OC == UO_PreInc ||
OC == UO_PreDec;
}
@@ -44,7 +44,7 @@ AST_MATCHER_P2(Expr, hasSideEffect, bool, CheckFunctionCalls,
if (MethodDecl->isConst())
return false;
- OverloadedOperatorKind OpKind = OpCallExpr->getOperator();
+ const OverloadedOperatorKind OpKind = OpCallExpr->getOperator();
return OpKind == OO_Equal || OpKind == OO_PlusEqual ||
OpKind == OO_MinusEqual || OpKind == OO_StarEqual ||
OpKind == OO_SlashEqual || OpKind == OO_AmpEqual ||
@@ -130,7 +130,7 @@ void AssertSideEffectCheck::check(const MatchFinder::MatchResult &Result) {
StringRef AssertMacroName;
while (Loc.isValid() && Loc.isMacroID()) {
- StringRef MacroName = Lexer::getImmediateMacroName(Loc, SM, LangOpts);
+ const StringRef MacroName = Lexer::getImmediateMacroName(Loc, SM, LangOpts);
Loc = SM.getImmediateMacroCallerLoc(Loc);
// Check if this macro is an assert.
diff --git a/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
index 2c88562..d5d8a29 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
@@ -66,7 +66,7 @@ void AssignmentInIfConditionCheck::check(
}
void AssignmentInIfConditionCheck::report(const Expr *AssignmentExpr) {
- SourceLocation OpLoc =
+ const SourceLocation OpLoc =
isa<BinaryOperator>(AssignmentExpr)
? cast<BinaryOperator>(AssignmentExpr)->getOperatorLoc()
: cast<CXXOperatorCallExpr>(AssignmentExpr)->getOperatorLoc();
diff --git a/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp
index e1d0538a..3e1188d 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp
@@ -40,7 +40,7 @@ void BadSignalToKillThreadCheck::check(const MatchFinder::MatchResult &Result) {
const Token &T = MI->tokens().back();
if (!T.isLiteral() || !T.getLiteralData())
return std::nullopt;
- StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
+ const StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
llvm::APInt IntValue;
constexpr unsigned AutoSenseRadix = 0;
diff --git a/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
index 07bb081..4f33670 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
@@ -75,12 +75,9 @@ static bool isFallthroughSwitchBranch(const SwitchBranch &Branch) {
if (!S)
return true;
- for (const Attr *A : S->getAttrs()) {
- if (isa<FallThroughAttr>(A))
- return false;
- }
-
- return true;
+ return llvm::all_of(S->getAttrs(), [](const Attr *A) {
+ return !isa<FallThroughAttr>(A);
+ });
}
} Visitor;
@@ -117,7 +114,6 @@ void BranchCloneCheck::registerMatchers(MatchFinder *Finder) {
///
static bool isIdenticalStmt(const ASTContext &Ctx, const Stmt *Stmt1,
const Stmt *Stmt2, bool IgnoreSideEffects) {
-
if (!Stmt1 || !Stmt2)
return !Stmt1 && !Stmt2;
@@ -281,8 +277,8 @@ static bool isIdenticalStmt(const ASTContext &Ctx, const Stmt *Stmt1,
const auto *IntLit1 = cast<IntegerLiteral>(Stmt1);
const auto *IntLit2 = cast<IntegerLiteral>(Stmt2);
- llvm::APInt I1 = IntLit1->getValue();
- llvm::APInt I2 = IntLit2->getValue();
+ const llvm::APInt I1 = IntLit1->getValue();
+ const llvm::APInt I2 = IntLit2->getValue();
if (I1.getBitWidth() != I2.getBitWidth())
return false;
return I1 == I2;
@@ -352,7 +348,7 @@ void BranchCloneCheck::check(const MatchFinder::MatchResult &Result) {
}
}
- size_t N = Branches.size();
+ const size_t N = Branches.size();
llvm::BitVector KnownAsClone(N);
for (size_t I = 0; I + 1 < N; I++) {
@@ -375,7 +371,7 @@ void BranchCloneCheck::check(const MatchFinder::MatchResult &Result) {
// We report the first occurrence only when we find the second one.
diag(Branches[I]->getBeginLoc(),
"repeated branch body in conditional chain");
- SourceLocation End =
+ const SourceLocation End =
Lexer::getLocForEndOfToken(Branches[I]->getEndLoc(), 0,
*Result.SourceManager, getLangOpts());
if (End.isValid()) {
diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index e6115f6..6859dc9 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -22,13 +22,17 @@
#include "CommandProcessorCheck.h"
#include "ComparePointerToMemberVirtualFunctionCheck.h"
#include "CopyConstructorInitCheck.h"
+#include "CopyConstructorMutatesArgumentCheck.h"
#include "CrtpConstructorAccessibilityCheck.h"
#include "DanglingHandleCheck.h"
+#include "DefaultOperatorNewOnOveralignedTypeCheck.h"
#include "DerivedMethodShadowingBaseMethodCheck.h"
#include "DynamicStaticInitializersCheck.h"
#include "EasilySwappableParametersCheck.h"
#include "EmptyCatchCheck.h"
+#include "ExceptionCopyConstructorThrowsCheck.h"
#include "ExceptionEscapeCheck.h"
+#include "FloatLoopCounterCheck.h"
#include "FoldInitTypeCheck.h"
#include "ForwardDeclarationNamespaceCheck.h"
#include "ForwardingReferenceOverloadCheck.h"
@@ -61,6 +65,8 @@
#include "ParentVirtualCallCheck.h"
#include "PointerArithmeticOnPolymorphicObjectCheck.h"
#include "PosixReturnCheck.h"
+#include "RandomGeneratorSeedCheck.h"
+#include "RawMemoryCallOnNonTrivialTypeCheck.h"
#include "RedundantBranchConditionCheck.h"
#include "ReservedIdentifierCheck.h"
#include "ReturnConstRefFromParameterCheck.h"
@@ -71,6 +77,7 @@
#include "SizeofExpressionCheck.h"
#include "SpuriouslyWakeUpFunctionsCheck.h"
#include "StandaloneEmptyCheck.h"
+#include "StdNamespaceModificationCheck.h"
#include "StringConstructorCheck.h"
#include "StringIntegerAssignmentCheck.h"
#include "StringLiteralWithEmbeddedNulCheck.h"
@@ -137,8 +144,12 @@ public:
"bugprone-compare-pointer-to-member-virtual-function");
CheckFactories.registerCheck<CopyConstructorInitCheck>(
"bugprone-copy-constructor-init");
+ CheckFactories.registerCheck<CopyConstructorMutatesArgumentCheck>(
+ "bugprone-copy-constructor-mutates-argument");
CheckFactories.registerCheck<DanglingHandleCheck>(
"bugprone-dangling-handle");
+ CheckFactories.registerCheck<DefaultOperatorNewOnOveralignedTypeCheck>(
+ "bugprone-default-operator-new-on-overaligned-type");
CheckFactories.registerCheck<DerivedMethodShadowingBaseMethodCheck>(
"bugprone-derived-method-shadowing-base-method");
CheckFactories.registerCheck<DynamicStaticInitializersCheck>(
@@ -146,8 +157,12 @@ public:
CheckFactories.registerCheck<EasilySwappableParametersCheck>(
"bugprone-easily-swappable-parameters");
CheckFactories.registerCheck<EmptyCatchCheck>("bugprone-empty-catch");
+ CheckFactories.registerCheck<ExceptionCopyConstructorThrowsCheck>(
+ "bugprone-exception-copy-constructor-throws");
CheckFactories.registerCheck<ExceptionEscapeCheck>(
"bugprone-exception-escape");
+ CheckFactories.registerCheck<FloatLoopCounterCheck>(
+ "bugprone-float-loop-counter");
CheckFactories.registerCheck<FoldInitTypeCheck>("bugprone-fold-init-type");
CheckFactories.registerCheck<ForwardDeclarationNamespaceCheck>(
"bugprone-forward-declaration-namespace");
@@ -216,6 +231,10 @@ public:
CheckFactories.registerCheck<ParentVirtualCallCheck>(
"bugprone-parent-virtual-call");
CheckFactories.registerCheck<PosixReturnCheck>("bugprone-posix-return");
+ CheckFactories.registerCheck<RandomGeneratorSeedCheck>(
+ "bugprone-random-generator-seed");
+ CheckFactories.registerCheck<RawMemoryCallOnNonTrivialTypeCheck>(
+ "bugprone-raw-memory-call-on-non-trivial-type");
CheckFactories.registerCheck<ReservedIdentifierCheck>(
"bugprone-reserved-identifier");
CheckFactories.registerCheck<SharedPtrArrayMismatchCheck>(
@@ -231,6 +250,8 @@ public:
"bugprone-spuriously-wake-up-functions");
CheckFactories.registerCheck<StandaloneEmptyCheck>(
"bugprone-standalone-empty");
+ CheckFactories.registerCheck<StdNamespaceModificationCheck>(
+ "bugprone-std-namespace-modification");
CheckFactories.registerCheck<StringConstructorCheck>(
"bugprone-string-constructor");
CheckFactories.registerCheck<StringIntegerAssignmentCheck>(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index c8943e5..db1256d 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -18,13 +18,17 @@ add_clang_library(clangTidyBugproneModule STATIC
CommandProcessorCheck.cpp
ComparePointerToMemberVirtualFunctionCheck.cpp
CopyConstructorInitCheck.cpp
+ CopyConstructorMutatesArgumentCheck.cpp
CrtpConstructorAccessibilityCheck.cpp
DanglingHandleCheck.cpp
+ DefaultOperatorNewOnOveralignedTypeCheck.cpp
DerivedMethodShadowingBaseMethodCheck.cpp
DynamicStaticInitializersCheck.cpp
EasilySwappableParametersCheck.cpp
EmptyCatchCheck.cpp
+ ExceptionCopyConstructorThrowsCheck.cpp
ExceptionEscapeCheck.cpp
+ FloatLoopCounterCheck.cpp
FoldInitTypeCheck.cpp
ForwardDeclarationNamespaceCheck.cpp
ForwardingReferenceOverloadCheck.cpp
@@ -62,6 +66,8 @@ add_clang_library(clangTidyBugproneModule STATIC
ParentVirtualCallCheck.cpp
PointerArithmeticOnPolymorphicObjectCheck.cpp
PosixReturnCheck.cpp
+ RandomGeneratorSeedCheck.cpp
+ RawMemoryCallOnNonTrivialTypeCheck.cpp
RedundantBranchConditionCheck.cpp
ReservedIdentifierCheck.cpp
ReturnConstRefFromParameterCheck.cpp
@@ -73,6 +79,7 @@ add_clang_library(clangTidyBugproneModule STATIC
SmartPtrArrayMismatchCheck.cpp
SpuriouslyWakeUpFunctionsCheck.cpp
StandaloneEmptyCheck.cpp
+ StdNamespaceModificationCheck.cpp
StringConstructorCheck.cpp
StringIntegerAssignmentCheck.cpp
StringLiteralWithEmbeddedNulCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/bugprone/CapturingThisInMemberVariableCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/CapturingThisInMemberVariableCheck.cpp
index a376de5..6aed454 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CapturingThisInMemberVariableCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/CapturingThisInMemberVariableCheck.cpp
@@ -44,18 +44,17 @@ AST_MATCHER(CXXRecordDecl, correctHandleCaptureThisLambda) {
if (Node.hasSimpleMoveAssignment())
return false;
- for (const CXXConstructorDecl *C : Node.ctors()) {
- if (C->isCopyOrMoveConstructor() && C->isDefaulted() && !C->isDeleted())
- return false;
- }
- for (const CXXMethodDecl *M : Node.methods()) {
- if (M->isCopyAssignmentOperator())
- llvm::errs() << M->isDeleted() << "\n";
- if (M->isCopyAssignmentOperator() && M->isDefaulted() && !M->isDeleted())
- return false;
- if (M->isMoveAssignmentOperator() && M->isDefaulted() && !M->isDeleted())
- return false;
- }
+ if (llvm::any_of(Node.ctors(), [](const CXXConstructorDecl *C) {
+ return C->isCopyOrMoveConstructor() && C->isDefaulted() &&
+ !C->isDeleted();
+ }))
+ return false;
+ if (llvm::any_of(Node.methods(), [](const CXXMethodDecl *M) {
+ return (M->isCopyAssignmentOperator() ||
+ M->isMoveAssignmentOperator()) &&
+ M->isDefaulted() && !M->isDeleted();
+ }))
+ return false;
// FIXME: find ways to identifier correct handle capture this lambda
return true;
}
diff --git a/clang-tools-extra/clang-tidy/bugprone/ChainedComparisonCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ChainedComparisonCheck.cpp
index 3d3fc78..47acc21 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ChainedComparisonCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ChainedComparisonCheck.cpp
@@ -11,7 +11,6 @@
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
-#include <algorithm>
using namespace clang::ast_matchers;
diff --git a/clang-tools-extra/clang-tidy/bugprone/ComparePointerToMemberVirtualFunctionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ComparePointerToMemberVirtualFunctionCheck.cpp
index 602b63e..9067f43 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ComparePointerToMemberVirtualFunctionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ComparePointerToMemberVirtualFunctionCheck.cpp
@@ -34,7 +34,6 @@ static constexpr llvm::StringLiteral ErrorMsg =
void ComparePointerToMemberVirtualFunctionCheck::registerMatchers(
MatchFinder *Finder) {
-
auto DirectMemberVirtualFunctionPointer = unaryOperator(
allOf(hasOperatorName("&"),
hasUnaryOperand(declRefExpr(to(cxxMethodDecl(isVirtual()))))));
diff --git a/clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.cpp
index 76bcbbb..ccbc86a 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.cpp
@@ -31,7 +31,7 @@ void CopyConstructorInitCheck::registerMatchers(MatchFinder *Finder) {
void CopyConstructorInitCheck::check(const MatchFinder::MatchResult &Result) {
const auto *Ctor = Result.Nodes.getNodeAs<CXXConstructorDecl>("ctor");
- std::string ParamName = Ctor->getParamDecl(0)->getNameAsString();
+ const std::string ParamName = Ctor->getParamDecl(0)->getNameAsString();
// We want only one warning (and FixIt) for each ctor.
std::string FixItInitList;
@@ -40,7 +40,7 @@ void CopyConstructorInitCheck::check(const MatchFinder::MatchResult &Result) {
bool HasWrittenInitializer = false;
SmallVector<FixItHint, 2> SafeFixIts;
for (const auto *Init : Ctor->inits()) {
- bool CtorInitIsWritten = Init->isWritten();
+ const bool CtorInitIsWritten = Init->isWritten();
HasWrittenInitializer = HasWrittenInitializer || CtorInitIsWritten;
if (!Init->isBaseInitializer())
continue;
diff --git a/clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.h b/clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.h
index cba1a25..e977bc2 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_COPY_CONSTRUCTOR_INIT_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_COPY_CONSTRUCTOR_INIT_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_COPYCONSTRUCTORINITCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_COPYCONSTRUCTORINITCHECK_H
#include "../ClangTidyCheck.h"
@@ -31,4 +31,4 @@ public:
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_COPY_CONSTRUCTOR_INIT_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_COPYCONSTRUCTORINITCHECK_H
diff --git a/clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/CopyConstructorMutatesArgumentCheck.cpp
index fb9d72c..cbbb1a0 100644
--- a/clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/CopyConstructorMutatesArgumentCheck.cpp
@@ -6,19 +6,20 @@
//
//===----------------------------------------------------------------------===//
-#include "MutatingCopyCheck.h"
+#include "CopyConstructorMutatesArgumentCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
using namespace clang::ast_matchers;
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
static constexpr llvm::StringLiteral SourceDeclName = "ChangedPVD";
static constexpr llvm::StringLiteral MutatingOperatorName = "MutatingOp";
static constexpr llvm::StringLiteral MutatingCallName = "MutatingCall";
-void MutatingCopyCheck::registerMatchers(MatchFinder *Finder) {
+void CopyConstructorMutatesArgumentCheck::registerMatchers(
+ MatchFinder *Finder) {
const auto MemberExprOrSourceObject = anyOf(
memberExpr(),
declRefExpr(to(decl(equalsBoundNode(std::string(SourceDeclName))))));
@@ -60,7 +61,8 @@ void MutatingCopyCheck::registerMatchers(MatchFinder *Finder) {
this);
}
-void MutatingCopyCheck::check(const MatchFinder::MatchResult &Result) {
+void CopyConstructorMutatesArgumentCheck::check(
+ const MatchFinder::MatchResult &Result) {
if (const auto *MemberCall =
Result.Nodes.getNodeAs<CXXMemberCallExpr>(MutatingCallName))
diag(MemberCall->getBeginLoc(), "call mutates copied object");
@@ -69,4 +71,4 @@ void MutatingCopyCheck::check(const MatchFinder::MatchResult &Result) {
diag(Assignment->getBeginLoc(), "mutating copied object");
}
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.h b/clang-tools-extra/clang-tidy/bugprone/CopyConstructorMutatesArgumentCheck.h
index c211fa0..0fed572 100644
--- a/clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/CopyConstructorMutatesArgumentCheck.h
@@ -6,21 +6,21 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_MUTATINGCOPYCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_MUTATINGCOPYCHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_COPYCONSTRUCTORMUTATESARGUMENTCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_COPYCONSTRUCTORMUTATESARGUMENTCHECK_H
#include "../ClangTidyCheck.h"
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
/// Finds assignments to the copied object and its direct or indirect members
/// in copy constructors and copy assignment operators.
///
/// For the user-facing documentation see:
-/// https://clang.llvm.org/extra/clang-tidy/checks/cert/oop58-cpp.html
-class MutatingCopyCheck : public ClangTidyCheck {
+/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/copy-constructor-mutates-argument.html
+class CopyConstructorMutatesArgumentCheck : public ClangTidyCheck {
public:
- MutatingCopyCheck(StringRef Name, ClangTidyContext *Context)
+ CopyConstructorMutatesArgumentCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
@@ -29,6 +29,6 @@ public:
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_MUTATINGCOPYCHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_COPYCONSTRUCTORMUTATESARGUMENTCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp
index 60f7be8..5ef72ea 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp
@@ -116,9 +116,10 @@ void CrtpConstructorAccessibilityCheck::check(
assert(DerivedTemplateParameter &&
"No template parameter corresponds to the derived class of the CRTP.");
- bool NeedsFriend = !isDerivedParameterBefriended(CRTPDeclaration,
- DerivedTemplateParameter) &&
- !isDerivedClassBefriended(CRTPDeclaration, DerivedRecord);
+ const bool NeedsFriend =
+ !isDerivedParameterBefriended(CRTPDeclaration,
+ DerivedTemplateParameter) &&
+ !isDerivedClassBefriended(CRTPDeclaration, DerivedRecord);
const FixItHint HintFriend = FixItHint::CreateInsertion(
CRTPDeclaration->getBraceRange().getEnd(),
diff --git a/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
index 9f8e885..c95ad2b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
@@ -7,13 +7,11 @@
//===----------------------------------------------------------------------===//
#include "DanglingHandleCheck.h"
-#include "../utils/Matchers.h"
#include "../utils/OptionsUtils.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
using namespace clang::ast_matchers;
-using namespace clang::tidy::matchers;
namespace clang::tidy::bugprone {
@@ -31,7 +29,6 @@ handleFrom(const ast_matchers::internal::Matcher<RecordDecl> &IsAHandle,
static ast_matchers::internal::Matcher<Stmt> handleFromTemporaryValue(
const ast_matchers::internal::Matcher<RecordDecl> &IsAHandle) {
-
const auto TemporaryExpr = anyOf(
cxxBindTemporaryExpr(),
cxxFunctionalCastExpr(
diff --git a/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.h b/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.h
index 486562c..0b71bc4 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DANGLING_HANDLE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DANGLING_HANDLE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DANGLINGHANDLECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DANGLINGHANDLECHECK_H
#include "../ClangTidyCheck.h"
@@ -37,4 +37,4 @@ private:
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DANGLING_HANDLE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DANGLINGHANDLECHECK_H
diff --git a/clang-tools-extra/clang-tidy/cert/DefaultOperatorNewAlignmentCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/DefaultOperatorNewOnOveralignedTypeCheck.cpp
index 45c170e..cb4f69a 100644
--- a/clang-tools-extra/clang-tidy/cert/DefaultOperatorNewAlignmentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/DefaultOperatorNewOnOveralignedTypeCheck.cpp
@@ -6,26 +6,27 @@
//
//===----------------------------------------------------------------------===//
-#include "DefaultOperatorNewAlignmentCheck.h"
+#include "DefaultOperatorNewOnOveralignedTypeCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Basic/TargetInfo.h"
using namespace clang::ast_matchers;
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
-void DefaultOperatorNewAlignmentCheck::registerMatchers(MatchFinder *Finder) {
+void DefaultOperatorNewOnOveralignedTypeCheck::registerMatchers(
+ MatchFinder *Finder) {
Finder->addMatcher(
cxxNewExpr(unless(hasAnyPlacementArg(anything()))).bind("new"), this);
}
-void DefaultOperatorNewAlignmentCheck::check(
+void DefaultOperatorNewOnOveralignedTypeCheck::check(
const MatchFinder::MatchResult &Result) {
// Get the found 'new' expression.
const auto *NewExpr = Result.Nodes.getNodeAs<CXXNewExpr>("new");
- QualType T = NewExpr->getAllocatedType();
+ const QualType T = NewExpr->getAllocatedType();
// Dependent types do not have fixed alignment.
if (T->isDependentType())
return;
@@ -34,25 +35,25 @@ void DefaultOperatorNewAlignmentCheck::check(
if (!D || !D->isCompleteDefinition())
return;
- ASTContext &Context = D->getASTContext();
+ const ASTContext &Context = D->getASTContext();
// Check if no alignment was specified for the type.
if (!Context.isAlignmentRequired(T))
return;
// The user-specified alignment (in bits).
- unsigned SpecifiedAlignment = D->getMaxAlignment();
+ const unsigned SpecifiedAlignment = D->getMaxAlignment();
// Double-check if no alignment was specified.
if (!SpecifiedAlignment)
return;
// The alignment used by default 'operator new' (in bits).
- unsigned DefaultNewAlignment = Context.getTargetInfo().getNewAlign();
+ const unsigned DefaultNewAlignment = Context.getTargetInfo().getNewAlign();
- bool OverAligned = SpecifiedAlignment > DefaultNewAlignment;
- bool HasDefaultOperatorNew =
+ const bool OverAligned = SpecifiedAlignment > DefaultNewAlignment;
+ const bool HasDefaultOperatorNew =
!NewExpr->getOperatorNew() || NewExpr->getOperatorNew()->isImplicit();
- unsigned CharWidth = Context.getTargetInfo().getCharWidth();
+ const unsigned CharWidth = Context.getTargetInfo().getCharWidth();
if (HasDefaultOperatorNew && OverAligned)
diag(NewExpr->getBeginLoc(),
"allocation function returns a pointer with alignment %0 but the "
@@ -61,4 +62,4 @@ void DefaultOperatorNewAlignmentCheck::check(
<< (SpecifiedAlignment / CharWidth);
}
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/cert/DefaultOperatorNewAlignmentCheck.h b/clang-tools-extra/clang-tidy/bugprone/DefaultOperatorNewOnOveralignedTypeCheck.h
index 8f9d0e4..b5b365b 100644
--- a/clang-tools-extra/clang-tidy/cert/DefaultOperatorNewAlignmentCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/DefaultOperatorNewOnOveralignedTypeCheck.h
@@ -6,21 +6,22 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_DEFAULTOPERATORNEWALIGNMENTCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_DEFAULTOPERATORNEWALIGNMENTCHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DEFAULTOPERATORNEWONOVERALIGNEDTYPECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DEFAULTOPERATORNEWONOVERALIGNEDTYPECHECK_H
#include "../ClangTidyCheck.h"
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
/// Checks if an object of type with extended alignment is allocated by using
/// the default operator new.
///
/// For the user-facing documentation see:
-/// https://clang.llvm.org/extra/clang-tidy/checks/cert/mem57-cpp.html
-class DefaultOperatorNewAlignmentCheck : public ClangTidyCheck {
+/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/bugprone-default-operator-new-on-overaligned-type.html
+class DefaultOperatorNewOnOveralignedTypeCheck : public ClangTidyCheck {
public:
- DefaultOperatorNewAlignmentCheck(StringRef Name, ClangTidyContext *Context)
+ DefaultOperatorNewOnOveralignedTypeCheck(StringRef Name,
+ ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return !LangOpts.CPlusPlus17;
@@ -29,6 +30,6 @@ public:
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_DEFAULTOPERATORNEWALIGNMENTCHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DEFAULTOPERATORNEWONOVERALIGNEDTYPECHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp
index 743e6cd..7c58676 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp
@@ -65,7 +65,7 @@ AST_MATCHER(CXXMethodDecl, nameCollidesWithMethodInBase) {
for (const auto &BaseMethod : CurrentRecord->methods()) {
if (namesCollide(*BaseMethod, Node)) {
- ast_matchers::internal::BoundNodesTreeBuilder Result(*Builder);
+ const ast_matchers::internal::BoundNodesTreeBuilder Result(*Builder);
Builder->setBinding("base_method",
clang::DynTypedNode::create(*BaseMethod));
return true;
diff --git a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
index 4d0428e..48de7fb 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
@@ -43,7 +43,7 @@ void DynamicStaticInitializersCheck::registerMatchers(MatchFinder *Finder) {
void DynamicStaticInitializersCheck::check(
const MatchFinder::MatchResult &Result) {
const auto *Var = Result.Nodes.getNodeAs<VarDecl>("var");
- SourceLocation Loc = Var->getLocation();
+ const SourceLocation Loc = Var->getLocation();
if (!Loc.isValid() || !utils::isPresumedLocInHeaderFile(
Loc, *Result.SourceManager, HeaderFileExtensions))
return;
diff --git a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
index e02c62a..00e4bb1 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DYNAMIC_STATIC_INITIALIZERS_CHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DYNAMIC_STATIC_INITIALIZERS_CHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DYNAMICSTATICINITIALIZERSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DYNAMICSTATICINITIALIZERSCHECK_H
#include "../ClangTidyCheck.h"
#include "../FileExtensionsSet.h"
@@ -30,4 +30,4 @@ private:
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DYNAMIC_STATIC_INITIALIZERS_CHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DYNAMICSTATICINITIALIZERSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
index b4ee351..496f3e5 100644
--- a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
@@ -417,7 +417,7 @@ struct MixData {
void sanitize() {
assert(Flags != MixFlags::Invalid && "sanitize() called on invalid bitvec");
- MixFlags CanonicalAndWorkaround =
+ const MixFlags CanonicalAndWorkaround =
MixFlags::Canonical | MixFlags::WorkaroundDisableCanonicalEquivalence;
if ((Flags & CanonicalAndWorkaround) == CanonicalAndWorkaround) {
// A workaround for too eagerly equivalent canonical types was requested,
@@ -483,7 +483,7 @@ struct MixData {
if (CommonType.isNull())
return *this;
- QualType NewCommonType = Func(CommonType);
+ const QualType NewCommonType = Func(CommonType);
if (CreatedFromOneWayConversion) {
MixData M{Flags, Conversion};
@@ -761,7 +761,7 @@ calculateMixability(const TheCheck &Check, QualType LType, QualType RType,
return {MixFlags::None};
}
- MixData UnqualifiedMixability =
+ const MixData UnqualifiedMixability =
calculateMixability(Check, LType.getLocalUnqualifiedType(),
RType.getLocalUnqualifiedType(), Ctx, ImplicitMode)
.withCommonTypeTransformed([&AdditionalQuals, &Ctx](QualType QT) {
@@ -813,7 +813,7 @@ calculateMixability(const TheCheck &Check, QualType LType, QualType RType,
if (ImplicitMode > ImplicitConversionModellingMode::None) {
LLVM_DEBUG(llvm::dbgs() << "--- calculateMixability. Start implicit...\n");
- MixData MixLTR =
+ const MixData MixLTR =
approximateImplicitConversion(Check, LType, RType, Ctx, ImplicitMode);
LLVM_DEBUG(
if (hasFlag(MixLTR.Flags, MixFlags::ImplicitConversion)) llvm::dbgs()
@@ -833,7 +833,7 @@ calculateMixability(const TheCheck &Check, QualType LType, QualType RType,
// Otherwise if the invoker requested a full modelling, do the other
// direction as well.
- MixData MixRTL =
+ const MixData MixRTL =
approximateImplicitConversion(Check, RType, LType, Ctx, ImplicitMode);
LLVM_DEBUG(
if (hasFlag(MixRTL.Flags, MixFlags::ImplicitConversion)) llvm::dbgs()
@@ -868,7 +868,7 @@ calculateMixability(const TheCheck &Check, QualType LType, QualType RType,
// If none of the previous logic found a match, try if Clang otherwise
// believes the types to be the same.
- QualType LCanonical = LType.getCanonicalType();
+ const QualType LCanonical = LType.getCanonicalType();
if (LCanonical == RType.getCanonicalType()) {
LLVM_DEBUG(llvm::dbgs()
<< "<<< calculateMixability. Same CanonicalType.\n");
@@ -983,9 +983,9 @@ approximateStandardConversionSequence(const TheCheck &Check, QualType From,
// Numeric promotions and conversions.
const auto *FromBuiltin = WorkType->getAs<BuiltinType>();
const auto *ToBuiltin = To->getAs<BuiltinType>();
- bool FromNumeric = FromBuiltin && (FromBuiltin->isIntegerType() ||
- FromBuiltin->isFloatingType());
- bool ToNumeric =
+ const bool FromNumeric = FromBuiltin && (FromBuiltin->isIntegerType() ||
+ FromBuiltin->isFloatingType());
+ const bool ToNumeric =
ToBuiltin && (ToBuiltin->isIntegerType() || ToBuiltin->isFloatingType());
if (FromNumeric && ToNumeric) {
// If both are integral types, the numeric conversion is performed.
@@ -1150,9 +1150,9 @@ public:
continue;
}
- bool BestConversionHasImplicit =
+ const bool BestConversionHasImplicit =
hasFlag(BestConversion->Flags, MixFlags::ImplicitConversion);
- bool ThisConversionHasImplicit =
+ const bool ThisConversionHasImplicit =
hasFlag(Prepared.Flags, MixFlags::ImplicitConversion);
if (!BestConversionHasImplicit && ThisConversionHasImplicit)
// This is a worse conversion, because a better one was found earlier.
@@ -1221,7 +1221,7 @@ tryConversionOperators(const TheCheck &Check, const CXXRecordDecl *RD,
if (std::optional<UserDefinedConversionSelector::PreparedConversion>
SelectedConversion = ConversionSet()) {
- CanQualType RecordType = RD->getASTContext().getCanonicalTagType(RD);
+ const CanQualType RecordType = RD->getASTContext().getCanonicalTagType(RD);
ConversionSequence Result{RecordType, ToType};
// The conversion from the operator call's return type to ToType was
@@ -1272,7 +1272,7 @@ tryConvertingConstructors(const TheCheck &Check, QualType FromType,
if (std::optional<UserDefinedConversionSelector::PreparedConversion>
SelectedConversion = ConversionSet()) {
- CanQualType RecordType = RD->getASTContext().getCanonicalTagType(RD);
+ const CanQualType RecordType = RD->getASTContext().getCanonicalTagType(RD);
ConversionSequence Result{FromType, RecordType};
Result.AfterFirstStandard = SelectedConversion->Seq.AfterFirstStandard;
@@ -1385,7 +1385,7 @@ approximateImplicitConversion(const TheCheck &Check, QualType LType,
LLVM_DEBUG(
llvm::dbgs()
<< "--- approximateImplicitConversion. Try to find post-conversion.\n");
- MixData SecondStdConv = approximateImplicitConversion(
+ const MixData SecondStdConv = approximateImplicitConversion(
Check, WorkType, RType, Ctx,
ImplicitConversionModellingMode::OneWaySingleStandardOnly);
if (SecondStdConv.indicatesMixability()) {
@@ -1414,7 +1414,7 @@ approximateImplicitConversion(const TheCheck &Check, QualType LType,
static MixableParameterRange modelMixingRange(
const TheCheck &Check, const FunctionDecl *FD, std::size_t StartIndex,
const filter::SimilarlyUsedParameterPairSuppressor &UsageBasedSuppressor) {
- std::size_t NumParams = FD->getNumParams();
+ const std::size_t NumParams = FD->getNumParams();
assert(StartIndex < NumParams && "out of bounds for start");
const ASTContext &Ctx = FD->getASTContext();
@@ -1424,7 +1424,7 @@ static MixableParameterRange modelMixingRange(
for (std::size_t I = StartIndex + 1; I < NumParams; ++I) {
const ParmVarDecl *Ith = FD->getParamDecl(I);
- StringRef ParamName = Ith->getName();
+ const StringRef ParamName = Ith->getName();
LLVM_DEBUG(llvm::dbgs()
<< "Check param #" << I << " '" << ParamName << "'...\n");
if (filter::isIgnoredParameter(Check, Ith)) {
@@ -1432,7 +1432,7 @@ static MixableParameterRange modelMixingRange(
break;
}
- StringRef PrevParamName = FD->getParamDecl(I - 1)->getName();
+ const StringRef PrevParamName = FD->getParamDecl(I - 1)->getName();
if (!ParamName.empty() && !PrevParamName.empty() &&
filter::prefixSuffixCoverUnderThreshold(
Check.NamePrefixSuffixSilenceDissimilarityThreshold, PrevParamName,
@@ -1518,18 +1518,18 @@ static bool isIgnoredParameter(const TheCheck &Check, const ParmVarDecl *Node) {
if (!Node->getIdentifier())
return llvm::is_contained(Check.IgnoredParameterNames, "\"\"");
- StringRef NodeName = Node->getName();
+ const StringRef NodeName = Node->getName();
if (llvm::is_contained(Check.IgnoredParameterNames, NodeName)) {
LLVM_DEBUG(llvm::dbgs() << "\tName ignored.\n");
return true;
}
- StringRef NodeTypeName = [Node] {
+ const StringRef NodeTypeName = [Node] {
const ASTContext &Ctx = Node->getASTContext();
const SourceManager &SM = Ctx.getSourceManager();
SourceLocation B = Node->getTypeSpecStartLoc();
SourceLocation E = Node->getTypeSpecEndLoc();
- LangOptions LO;
+ const LangOptions LO;
LLVM_DEBUG(llvm::dbgs() << "\tType name code is '"
<< Lexer::getSourceText(
@@ -1589,11 +1589,9 @@ static bool lazyMapOfSetsIntersectionExists(const MapTy &Map, const ElemTy &E1,
if (E1Iterator == Map.end() || E2Iterator == Map.end())
return false;
- for (const auto &E1SetElem : E1Iterator->second)
- if (E2Iterator->second.contains(E1SetElem))
- return true;
-
- return false;
+ return llvm::any_of(E1Iterator->second, [&E2Iterator](const auto &E1SetElem) {
+ return E2Iterator->second.contains(E1SetElem);
+ });
}
/// Implements the heuristic that marks two parameters related if there is
@@ -1633,7 +1631,7 @@ public:
RootSetInCurrentStackFrame = true;
}
- bool Ret = Base::TraverseStmt(S);
+ const bool Ret = Base::TraverseStmt(S);
if (RootSetInCurrentStackFrame)
CurrentExprOnlyTreeRoot = nullptr;
@@ -1684,7 +1682,7 @@ public:
continue;
std::optional<unsigned> TargetIdx;
- unsigned NumFnParams = CalledFn->getNumParams();
+ const unsigned NumFnParams = CalledFn->getNumParams();
for (unsigned Idx = 0; Idx < NumFnParams; ++Idx)
if (CalledFn->getParamDecl(Idx) == PassedToParam)
TargetIdx.emplace(Idx);
@@ -1837,16 +1835,16 @@ static void padStringAtBegin(SmallVectorImpl<char> &Str, std::size_t ToLen) {
static bool isCommonPrefixWithoutSomeCharacters(std::size_t N, StringRef S1,
StringRef S2) {
assert(S1.size() >= N && S2.size() >= N);
- StringRef S1Prefix = S1.take_front(S1.size() - N),
- S2Prefix = S2.take_front(S2.size() - N);
+ const StringRef S1Prefix = S1.take_front(S1.size() - N),
+ S2Prefix = S2.take_front(S2.size() - N);
return S1Prefix == S2Prefix && !S1Prefix.empty();
}
static bool isCommonSuffixWithoutSomeCharacters(std::size_t N, StringRef S1,
StringRef S2) {
assert(S1.size() >= N && S2.size() >= N);
- StringRef S1Suffix = S1.take_back(S1.size() - N),
- S2Suffix = S2.take_back(S2.size() - N);
+ const StringRef S1Suffix = S1.take_back(S1.size() - N),
+ S2Suffix = S2.take_back(S2.size() - N);
return S1Suffix == S2Suffix && !S1Suffix.empty();
}
@@ -1858,7 +1856,7 @@ static bool prefixSuffixCoverUnderThreshold(std::size_t Threshold,
return false;
// Pad the two strings to the longer length.
- std::size_t BiggerLength = std::max(Str1.size(), Str2.size());
+ const std::size_t BiggerLength = std::max(Str1.size(), Str2.size());
if (BiggerLength <= Threshold)
// If the length of the strings is still smaller than the threshold, they
@@ -1980,7 +1978,7 @@ struct FormattedConversionSequence {
// However, the parameter's defined type might not be what the implicit
// conversion started with, e.g. if a typedef is found to convert.
- std::string SeqBeginTypeStr = Conv.Begin.getAsString(PP);
+ const std::string SeqBeginTypeStr = Conv.Begin.getAsString(PP);
std::string SeqEndTypeStr = Conv.End.getAsString(PP);
if (StartTypeAsDiagnosed != SeqBeginTypeStr) {
OS << " (as '" << SeqBeginTypeStr << "')";
@@ -1995,7 +1993,7 @@ struct FormattedConversionSequence {
++NumElementsAdded;
}
};
- for (QualType InvolvedType : Conv.getInvolvedTypesInSequence())
+ for (const QualType InvolvedType : Conv.getInvolvedTypesInSequence())
// Print every type that's unique in the sequence into the diagnosis.
AddType(InvolvedType.getAsString(PP));
@@ -2073,12 +2071,14 @@ public:
if (CommonType.isNull() || CommonType == LHSType || CommonType == RHSType)
return Base::operator()({LHSType, RHSType, {}});
- TypeAliasDiagnosticTuple ThreeTuple{LHSType, RHSType, CommonType};
+ const TypeAliasDiagnosticTuple ThreeTuple{LHSType, RHSType, CommonType};
if (!Base::operator()(ThreeTuple))
return false;
- bool AlreadySaidLHSAndCommonIsSame = calledWith({LHSType, CommonType, {}});
- bool AlreadySaidRHSAndCommonIsSame = calledWith({RHSType, CommonType, {}});
+ const bool AlreadySaidLHSAndCommonIsSame =
+ calledWith({LHSType, CommonType, {}});
+ const bool AlreadySaidRHSAndCommonIsSame =
+ calledWith({RHSType, CommonType, {}});
if (AlreadySaidLHSAndCommonIsSame && AlreadySaidRHSAndCommonIsSame) {
// "SomeInt == int" && "SomeOtherInt == int" => "Common(SomeInt,
// SomeOtherInt) == int", no need to diagnose it. Save the 3-tuple only
@@ -2154,12 +2154,12 @@ void EasilySwappableParametersCheck::check(
assert(FD);
const PrintingPolicy &PP = FD->getASTContext().getPrintingPolicy();
- std::size_t NumParams = FD->getNumParams();
+ const std::size_t NumParams = FD->getNumParams();
std::size_t MixableRangeStartIndex = 0;
// Spawn one suppressor and if the user requested, gather information from
// the AST for the parameters' usages.
- filter::SimilarlyUsedParameterPairSuppressor UsageBasedSuppressor{
+ const filter::SimilarlyUsedParameterPairSuppressor UsageBasedSuppressor{
FD, SuppressParametersUsedTogether};
LLVM_DEBUG(llvm::dbgs() << "Begin analysis of " << getName(FD) << " with "
@@ -2182,11 +2182,13 @@ void EasilySwappableParametersCheck::check(
continue;
}
- bool NeedsAnyTypeNote = llvm::any_of(R.Mixes, needsToPrintTypeInDiagnostic);
- bool HasAnyImplicits =
+ const bool NeedsAnyTypeNote =
+ llvm::any_of(R.Mixes, needsToPrintTypeInDiagnostic);
+ const bool HasAnyImplicits =
llvm::any_of(R.Mixes, needsToElaborateImplicitConversion);
const ParmVarDecl *First = R.getFirstParam(), *Last = R.getLastParam();
- std::string FirstParamTypeAsWritten = First->getType().getAsString(PP);
+ const std::string FirstParamTypeAsWritten =
+ First->getType().getAsString(PP);
{
StringRef DiagText;
@@ -2205,7 +2207,7 @@ void EasilySwappableParametersCheck::check(
if (!NeedsAnyTypeNote)
Diag << FirstParamTypeAsWritten;
- CharSourceRange HighlightRange = CharSourceRange::getTokenRange(
+ const CharSourceRange HighlightRange = CharSourceRange::getTokenRange(
First->getBeginLoc(), Last->getEndLoc());
Diag << HighlightRange;
}
@@ -2240,12 +2242,12 @@ void EasilySwappableParametersCheck::check(
// emitted to a note diagnostic, so prepare it.
const ParmVarDecl *LVar = M.First;
const ParmVarDecl *RVar = M.Second;
- QualType LType = LVar->getType();
- QualType RType = RVar->getType();
- QualType CommonType = M.commonUnderlyingType();
- std::string LTypeStr = LType.getAsString(PP);
- std::string RTypeStr = RType.getAsString(PP);
- std::string CommonTypeStr = CommonType.getAsString(PP);
+ const QualType LType = LVar->getType();
+ const QualType RType = RVar->getType();
+ const QualType CommonType = M.commonUnderlyingType();
+ const std::string LTypeStr = LType.getAsString(PP);
+ const std::string RTypeStr = RType.getAsString(PP);
+ const std::string CommonTypeStr = CommonType.getAsString(PP);
if (hasFlag(M.flags(), MixFlags::TypeAlias) &&
UniqueTypeAlias(LType, RType, CommonType)) {
@@ -2274,8 +2276,9 @@ void EasilySwappableParametersCheck::check(
if ((hasFlag(M.flags(), MixFlags::ReferenceBind) ||
hasFlag(M.flags(), MixFlags::Qualifiers)) &&
UniqueBindPower({LType, RType})) {
- StringRef DiagText = "'%0' and '%1' parameters accept and bind the "
- "same kind of values";
+ const StringRef DiagText =
+ "'%0' and '%1' parameters accept and bind the "
+ "same kind of values";
diag(RVar->getOuterLocStart(), DiagText, DiagnosticIDs::Note)
<< LTypeStr << RTypeStr;
}
@@ -2286,8 +2289,8 @@ void EasilySwappableParametersCheck::check(
M.leftToRightConversionSequence();
const model::ConversionSequence &RTL =
M.rightToLeftConversionSequence();
- FormattedConversionSequence LTRFmt{PP, LTypeStr, LTR, RTypeStr};
- FormattedConversionSequence RTLFmt{PP, RTypeStr, RTL, LTypeStr};
+ const FormattedConversionSequence LTRFmt{PP, LTypeStr, LTR, RTypeStr};
+ const FormattedConversionSequence RTLFmt{PP, RTypeStr, RTL, LTypeStr};
StringRef DiagText = "'%0' and '%1' may be implicitly converted";
if (!LTRFmt.Trivial || !RTLFmt.Trivial)
@@ -2302,7 +2305,7 @@ void EasilySwappableParametersCheck::check(
Diag << LTRFmt.DiagnosticText << RTLFmt.DiagnosticText;
}
- StringRef ConversionFunctionDiagText =
+ const StringRef ConversionFunctionDiagText =
"the implicit conversion involves the "
"%select{|converting constructor|conversion operator}0 "
"declared here";
diff --git a/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
index eebab84..5dd2f62 100644
--- a/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
@@ -25,7 +25,7 @@ AST_MATCHER(CXXCatchStmt, isInMacro) {
}
AST_MATCHER_P(CXXCatchStmt, hasHandler, Matcher<Stmt>, InnerMatcher) {
- Stmt *Handler = Node.getHandlerBlock();
+ const Stmt *Handler = Node.getHandlerBlock();
if (!Handler)
return false;
return InnerMatcher.matches(*Handler, Finder, Builder);
@@ -41,7 +41,7 @@ AST_MATCHER_P(CompoundStmt, hasAnyTextFromList, std::vector<llvm::StringRef>,
return false;
ASTContext &Context = Finder->getASTContext();
- SourceManager &SM = Context.getSourceManager();
+ const SourceManager &SM = Context.getSourceManager();
StringRef Text = Lexer::getSourceText(
CharSourceRange::getTokenRange(Node.getSourceRange()), SM,
Context.getLangOpts());
diff --git a/clang-tools-extra/clang-tidy/cert/ThrownExceptionTypeCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ExceptionCopyConstructorThrowsCheck.cpp
index 2225a90..7365845 100644
--- a/clang-tools-extra/clang-tidy/cert/ThrownExceptionTypeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ExceptionCopyConstructorThrowsCheck.cpp
@@ -6,15 +6,16 @@
//
//===----------------------------------------------------------------------===//
-#include "ThrownExceptionTypeCheck.h"
+#include "ExceptionCopyConstructorThrowsCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
using namespace clang::ast_matchers;
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
-void ThrownExceptionTypeCheck::registerMatchers(MatchFinder *Finder) {
+void ExceptionCopyConstructorThrowsCheck::registerMatchers(
+ MatchFinder *Finder) {
Finder->addMatcher(
traverse(
TK_AsIs,
@@ -25,10 +26,11 @@ void ThrownExceptionTypeCheck::registerMatchers(MatchFinder *Finder) {
this);
}
-void ThrownExceptionTypeCheck::check(const MatchFinder::MatchResult &Result) {
+void ExceptionCopyConstructorThrowsCheck::check(
+ const MatchFinder::MatchResult &Result) {
const auto *E = Result.Nodes.getNodeAs<Expr>("expr");
diag(E->getExprLoc(),
"thrown exception type is not nothrow copy constructible");
}
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/cert/ThrownExceptionTypeCheck.h b/clang-tools-extra/clang-tidy/bugprone/ExceptionCopyConstructorThrowsCheck.h
index 41a51452..f1d7cca 100644
--- a/clang-tools-extra/clang-tidy/cert/ThrownExceptionTypeCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/ExceptionCopyConstructorThrowsCheck.h
@@ -6,20 +6,20 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_THROWNEXCEPTIONTYPECHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_THROWNEXCEPTIONTYPECHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONCOPYCONSTRUCTORTHROWSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONCOPYCONSTRUCTORTHROWSCHECK_H
#include "../ClangTidyCheck.h"
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
/// Checks whether a thrown object is nothrow copy constructible.
///
/// For the user-facing documentation see:
-/// https://clang.llvm.org/extra/clang-tidy/checks/cert/err60-cpp.html
-class ThrownExceptionTypeCheck : public ClangTidyCheck {
+/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/exception-copy-constructor-throws.html
+class ExceptionCopyConstructorThrowsCheck : public ClangTidyCheck {
public:
- ThrownExceptionTypeCheck(StringRef Name, ClangTidyContext *Context)
+ ExceptionCopyConstructorThrowsCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
@@ -28,6 +28,6 @@ public:
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_THROWNEXCEPTIONTYPECHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONCOPYCONSTRUCTORTHROWSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
index 837a86f..1cfb151 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
@@ -36,13 +36,22 @@ ExceptionEscapeCheck::ExceptionEscapeCheck(StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context), RawFunctionsThatShouldNotThrow(Options.get(
"FunctionsThatShouldNotThrow", "")),
- RawIgnoredExceptions(Options.get("IgnoredExceptions", "")) {
+ RawIgnoredExceptions(Options.get("IgnoredExceptions", "")),
+ RawCheckedSwapFunctions(
+ Options.get("CheckedSwapFunctions", "swap,iter_swap,iter_move")),
+ CheckDestructors(Options.get("CheckDestructors", true)),
+ CheckMoveMemberFunctions(Options.get("CheckMoveMemberFunctions", true)),
+ CheckMain(Options.get("CheckMain", true)),
+ CheckNothrowFunctions(Options.get("CheckNothrowFunctions", true)) {
llvm::SmallVector<StringRef, 8> FunctionsThatShouldNotThrowVec,
- IgnoredExceptionsVec;
+ IgnoredExceptionsVec, CheckedSwapFunctionsVec;
RawFunctionsThatShouldNotThrow.split(FunctionsThatShouldNotThrowVec, ",", -1,
false);
FunctionsThatShouldNotThrow.insert_range(FunctionsThatShouldNotThrowVec);
+ RawCheckedSwapFunctions.split(CheckedSwapFunctionsVec, ",", -1, false);
+ CheckedSwapFunctions.insert_range(CheckedSwapFunctionsVec);
+
llvm::StringSet<> IgnoredExceptions;
RawIgnoredExceptions.split(IgnoredExceptionsVec, ",", -1, false);
IgnoredExceptions.insert_range(IgnoredExceptionsVec);
@@ -54,20 +63,34 @@ void ExceptionEscapeCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "FunctionsThatShouldNotThrow",
RawFunctionsThatShouldNotThrow);
Options.store(Opts, "IgnoredExceptions", RawIgnoredExceptions);
+ Options.store(Opts, "CheckedSwapFunctions", RawCheckedSwapFunctions);
+ Options.store(Opts, "CheckDestructors", CheckDestructors);
+ Options.store(Opts, "CheckMoveMemberFunctions", CheckMoveMemberFunctions);
+ Options.store(Opts, "CheckMain", CheckMain);
+ Options.store(Opts, "CheckNothrowFunctions", CheckNothrowFunctions);
}
void ExceptionEscapeCheck::registerMatchers(MatchFinder *Finder) {
+ auto MatchIf = [](bool Enabled, const auto &Matcher) {
+ const ast_matchers::internal::Matcher<FunctionDecl> Nothing =
+ unless(anything());
+ return Enabled ? Matcher : Nothing;
+ };
Finder->addMatcher(
functionDecl(
isDefinition(),
- anyOf(isNoThrow(),
- allOf(anyOf(cxxDestructorDecl(),
- cxxConstructorDecl(isMoveConstructor()),
- cxxMethodDecl(isMoveAssignmentOperator()), isMain(),
- allOf(hasAnyName("swap", "iter_swap", "iter_move"),
- hasAtLeastOneParameter())),
- unless(isExplicitThrow())),
- isEnabled(FunctionsThatShouldNotThrow)))
+ anyOf(
+ MatchIf(CheckNothrowFunctions, isNoThrow()),
+ allOf(anyOf(MatchIf(CheckDestructors, cxxDestructorDecl()),
+ MatchIf(
+ CheckMoveMemberFunctions,
+ anyOf(cxxConstructorDecl(isMoveConstructor()),
+ cxxMethodDecl(isMoveAssignmentOperator()))),
+ MatchIf(CheckMain, isMain()),
+ allOf(isEnabled(CheckedSwapFunctions),
+ hasAtLeastOneParameter())),
+ unless(isExplicitThrow())),
+ isEnabled(FunctionsThatShouldNotThrow)))
.bind("thrower"),
this);
}
diff --git a/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.h b/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.h
index bd1e7ba..c3bf4a4 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTION_ESCAPE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTION_ESCAPE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONESCAPECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONESCAPECHECK_H
#include "../ClangTidyCheck.h"
#include "../utils/ExceptionAnalyzer.h"
@@ -35,11 +35,18 @@ public:
private:
StringRef RawFunctionsThatShouldNotThrow;
StringRef RawIgnoredExceptions;
+ StringRef RawCheckedSwapFunctions;
+
+ const bool CheckDestructors;
+ const bool CheckMoveMemberFunctions;
+ const bool CheckMain;
+ const bool CheckNothrowFunctions;
llvm::StringSet<> FunctionsThatShouldNotThrow;
+ llvm::StringSet<> CheckedSwapFunctions;
utils::ExceptionAnalyzer Tracer;
};
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTION_ESCAPE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONESCAPECHECK_H
diff --git a/clang-tools-extra/clang-tidy/cert/FloatLoopCounter.cpp b/clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.cpp
index 01299e0..38a0234 100644
--- a/clang-tools-extra/clang-tidy/cert/FloatLoopCounter.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.cpp
@@ -6,16 +6,16 @@
//
//===----------------------------------------------------------------------===//
-#include "FloatLoopCounter.h"
+#include "FloatLoopCounterCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
using namespace clang::ast_matchers;
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
-void FloatLoopCounter::registerMatchers(MatchFinder *Finder) {
+void FloatLoopCounterCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
forStmt(hasIncrement(forEachDescendant(
declRefExpr(hasType(realFloatingPointType()),
@@ -29,8 +29,9 @@ void FloatLoopCounter::registerMatchers(MatchFinder *Finder) {
this);
}
-void FloatLoopCounter::check(const MatchFinder::MatchResult &Result) {
+void FloatLoopCounterCheck::check(const MatchFinder::MatchResult &Result) {
const auto *FS = Result.Nodes.getNodeAs<ForStmt>("for");
+ assert(FS && "FS should not be null");
diag(FS->getInc()->getBeginLoc(), "loop induction expression should not have "
"floating-point type")
@@ -43,4 +44,4 @@ void FloatLoopCounter::check(const MatchFinder::MatchResult &Result) {
DiagnosticIDs::Note);
}
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/cert/FloatLoopCounter.h b/clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.h
index d00c036..43dd9c2 100644
--- a/clang-tools-extra/clang-tidy/cert/FloatLoopCounter.h
+++ b/clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.h
@@ -6,27 +6,27 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_FLOAT_LOOP_COUNTER_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_FLOAT_LOOP_COUNTER_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FLOATLOOPCOUNTERCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FLOATLOOPCOUNTERCHECK_H
#include "../ClangTidyCheck.h"
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
/// This check diagnoses when the loop induction expression of a for loop has
/// floating-point type. The check corresponds to:
/// https://www.securecoding.cert.org/confluence/display/c/FLP30-C.+Do+not+use+floating-point+variables+as+loop+counters
///
/// For the user-facing documentation see:
-/// https://clang.llvm.org/extra/clang-tidy/checks/cert/flp30-c.html
-class FloatLoopCounter : public ClangTidyCheck {
+/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/float-loop-counter.html
+class FloatLoopCounterCheck : public ClangTidyCheck {
public:
- FloatLoopCounter(StringRef Name, ClangTidyContext *Context)
+ FloatLoopCounterCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_FLOAT_LOOP_COUNTER_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FLOATLOOPCOUNTERCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/FoldInitTypeCheck.h b/clang-tools-extra/clang-tidy/bugprone/FoldInitTypeCheck.h
index 119728d..ef8b4d1 100644
--- a/clang-tools-extra/clang-tidy/bugprone/FoldInitTypeCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/FoldInitTypeCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FOLD_INIT_TYPE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FOLD_INIT_TYPE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FOLDINITTYPECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FOLDINITTYPECHECK_H
#include "../ClangTidyCheck.h"
@@ -39,4 +39,4 @@ private:
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FOLD_INIT_TYPE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FOLDINITTYPECHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
index c3db8fa..11270e7 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
@@ -46,7 +46,7 @@ void ForwardDeclarationNamespaceCheck::check(
const MatchFinder::MatchResult &Result) {
if (const auto *RecordDecl =
Result.Nodes.getNodeAs<CXXRecordDecl>("record_decl")) {
- StringRef DeclName = RecordDecl->getName();
+ const StringRef DeclName = RecordDecl->getName();
if (RecordDecl->isThisDeclarationADefinition()) {
DeclNameToDefinitions[DeclName].push_back(RecordDecl);
} else {
diff --git a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
index d372cbd..c1e66f2 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
@@ -40,7 +40,7 @@ AST_MATCHER(QualType, isEnableIf) {
if (CheckTemplate(BaseType->getAs<TemplateSpecializationType>()))
return true; // Case: enable_if_t< >.
if (const auto *TT = BaseType->getAs<TypedefType>())
- if (NestedNameSpecifier Q = TT->getQualifier();
+ if (const NestedNameSpecifier Q = TT->getQualifier();
Q.getKind() == NestedNameSpecifier::Kind::Type)
if (CheckTemplate(Q.getAsType()->getAs<TemplateSpecializationType>()))
return true; // Case: enable_if< >::type.
@@ -67,7 +67,7 @@ void ForwardingReferenceOverloadCheck::registerMatchers(MatchFinder *Finder) {
unless(references(isConstQualified())))))
.bind("parm-var");
- DeclarationMatcher FindOverload =
+ const DeclarationMatcher FindOverload =
cxxConstructorDecl(
hasParameter(0, ForwardingRefParm), unless(isDeleted()),
unless(hasAnyParameter(
@@ -128,8 +128,9 @@ void ForwardingReferenceOverloadCheck::check(
(OtherCtor->isCopyConstructor() ? EnabledCopy : EnabledMove) = true;
}
}
- bool Copy = (!EnabledMove && !DisabledMove && !DisabledCopy) || EnabledCopy;
- bool Move = !DisabledMove || EnabledMove;
+ const bool Copy =
+ (!EnabledMove && !DisabledMove && !DisabledCopy) || EnabledCopy;
+ const bool Move = !DisabledMove || EnabledMove;
if (!Copy && !Move)
return;
diag(Ctor->getLocation(),
diff --git a/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
index 2211a0b..634d54c 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
@@ -71,18 +71,18 @@ ImplicitWideningOfMultiplicationResultCheck::includeStddefHeader(
void ImplicitWideningOfMultiplicationResultCheck::handleImplicitCastExpr(
const ImplicitCastExpr *ICE) {
- ASTContext *Context = Result->Context;
+ const ASTContext *Context = Result->Context;
const Expr *E = ICE->getSubExpr()->IgnoreParens();
- QualType Ty = ICE->getType();
- QualType ETy = E->getType();
+ const QualType Ty = ICE->getType();
+ const QualType ETy = E->getType();
assert(!ETy->isDependentType() && !Ty->isDependentType() &&
"Don't expect to ever get here in template Context.");
// This must be a widening cast. Else we do not care.
- unsigned SrcWidth = Context->getIntWidth(ETy);
- unsigned TgtWidth = Context->getIntWidth(Ty);
+ const unsigned SrcWidth = Context->getIntWidth(ETy);
+ const unsigned TgtWidth = Context->getIntWidth(Ty);
if (TgtWidth <= SrcWidth)
return;
@@ -92,7 +92,7 @@ void ImplicitWideningOfMultiplicationResultCheck::handleImplicitCastExpr(
!ETy->isUnsignedIntegerType()) {
if (const auto ConstExprResult = E->getIntegerConstantExpr(*Context)) {
const auto TypeSize = Context->getTypeSize(ETy);
- llvm::APSInt WidenedResult = ConstExprResult->extOrTrunc(TypeSize);
+ const llvm::APSInt WidenedResult = ConstExprResult->extOrTrunc(TypeSize);
if (WidenedResult <= llvm::APSInt::getMaxValue(TypeSize, false) &&
WidenedResult >= llvm::APSInt::getMinValue(TypeSize, false))
return;
@@ -168,7 +168,7 @@ void ImplicitWideningOfMultiplicationResultCheck::handleImplicitCastExpr(
void ImplicitWideningOfMultiplicationResultCheck::handlePointerOffsetting(
const Expr *E) {
- ASTContext *Context = Result->Context;
+ const ASTContext *Context = Result->Context;
// We are looking for a pointer offset operation,
// with one hand being a pointer, and another one being an offset.
@@ -191,19 +191,20 @@ void ImplicitWideningOfMultiplicationResultCheck::handlePointerOffsetting(
IndexExpr = IndexExpr->IgnoreParens();
- QualType IndexExprType = IndexExpr->getType();
+ const QualType IndexExprType = IndexExpr->getType();
// If the index expression's type is not known (i.e. we are in a template),
// we can't do anything here.
if (IndexExprType->isDependentType())
return;
- QualType SSizeTy = Context->getPointerDiffType();
- QualType USizeTy = Context->getSizeType();
- QualType SizeTy = IndexExprType->isSignedIntegerType() ? SSizeTy : USizeTy;
+ const QualType SSizeTy = Context->getPointerDiffType();
+ const QualType USizeTy = Context->getSizeType();
+ const QualType SizeTy =
+ IndexExprType->isSignedIntegerType() ? SSizeTy : USizeTy;
// FIXME: is there a way to actually get the QualType for size_t/ptrdiff_t?
// Note that SizeTy.getAsString() will be unsigned long/..., NOT size_t!
- StringRef TyAsString =
+ const StringRef TyAsString =
IndexExprType->isSignedIntegerType() ? "ptrdiff_t" : "size_t";
// So, is size_t actually wider than the result of the multiplication?
diff --git a/clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp
index b0dd901..12fa365 100644
--- a/clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp
@@ -43,7 +43,7 @@ void InaccurateEraseCheck::check(const MatchFinder::MatchResult &Result) {
if (!Loc.isMacroID() && EndExpr) {
const auto *AlgCall = Result.Nodes.getNodeAs<CallExpr>("alg");
- std::string ReplacementText = std::string(Lexer::getSourceText(
+ const std::string ReplacementText = std::string(Lexer::getSourceText(
CharSourceRange::getTokenRange(EndExpr->getSourceRange()),
*Result.SourceManager, getLangOpts()));
const SourceLocation EndLoc = Lexer::getLocForEndOfToken(
diff --git a/clang-tools-extra/clang-tidy/bugprone/IncDecInConditionsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/IncDecInConditionsCheck.cpp
index 9ce6d42..553c45c 100644
--- a/clang-tools-extra/clang-tidy/bugprone/IncDecInConditionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/IncDecInConditionsCheck.cpp
@@ -64,7 +64,6 @@ void IncDecInConditionsCheck::registerMatchers(MatchFinder *Finder) {
}
void IncDecInConditionsCheck::check(const MatchFinder::MatchResult &Result) {
-
SourceLocation ExprLoc;
bool IsIncrementOp = false;
diff --git a/clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp
index 84a99c3..6181ac8 100644
--- a/clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp
@@ -22,7 +22,7 @@ AST_MATCHER_P(TemplateTypeParmDecl, hasUnnamedDefaultArgument,
Node.getDefaultArgument().getArgument().isNull())
return false;
- TypeLoc DefaultArgTypeLoc =
+ const TypeLoc DefaultArgTypeLoc =
Node.getDefaultArgument().getTypeSourceInfo()->getTypeLoc();
return InnerMatcher.matches(DefaultArgTypeLoc, Finder, Builder);
}
@@ -51,7 +51,7 @@ void IncorrectEnableIfCheck::check(const MatchFinder::MatchResult &Result) {
return;
const SourceManager &SM = *Result.SourceManager;
- SourceLocation RAngleLoc =
+ const SourceLocation RAngleLoc =
SM.getExpansionLoc(EnableIfSpecializationLoc->getRAngleLoc());
auto Diag = diag(EnableIf->getBeginLoc(),
diff --git a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
index 1e516c1..6749c59 100644
--- a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
@@ -34,7 +34,7 @@ AST_MATCHER(FunctionType, typeHasNoReturnAttr) {
} // namespace
static Matcher<Stmt> loopEndingStmt(Matcher<Stmt> Internal) {
- Matcher<QualType> IsNoReturnFunType =
+ const Matcher<QualType> IsNoReturnFunType =
ignoringParens(functionType(typeHasNoReturnAttr()));
Matcher<Decl> IsNoReturnDecl =
anyOf(declHasNoReturnAttr(), functionDecl(hasType(IsNoReturnFunType)),
@@ -119,14 +119,9 @@ static bool isAtLeastOneCondVarChanged(const Decl *Func, const Stmt *LoopStmt,
if (isVarThatIsPossiblyChanged(Func, LoopStmt, Cond, Context))
return true;
- for (const Stmt *Child : Cond->children()) {
- if (!Child)
- continue;
-
- if (isAtLeastOneCondVarChanged(Func, LoopStmt, Child, Context))
- return true;
- }
- return false;
+ return llvm::any_of(Cond->children(), [&](const Stmt *Child) {
+ return Child && isAtLeastOneCondVarChanged(Func, LoopStmt, Child, Context);
+ });
}
/// Return the variable names in `Cond`.
@@ -145,7 +140,7 @@ static std::string getCondVarNames(const Stmt *Cond) {
if (!Child)
continue;
- std::string NewNames = getCondVarNames(Child);
+ const std::string NewNames = getCondVarNames(Child);
if (!Result.empty() && !NewNames.empty())
Result += ", ";
Result += NewNames;
@@ -240,10 +235,9 @@ static bool hasStaticLocalVariable(const Stmt *Cond) {
return true;
}
- for (const Stmt *Child : Cond->children())
- if (Child && hasStaticLocalVariable(Child))
- return true;
- return false;
+ return llvm::any_of(Cond->children(), [](const Stmt *Child) {
+ return Child && hasStaticLocalVariable(Child);
+ });
}
/// Tests if the loop condition `Cond` involves static local variables and
@@ -332,7 +326,7 @@ void InfiniteLoopCheck::check(const MatchFinder::MatchResult &Result) {
Result.Context))
return;
- std::string CondVarNames = getCondVarNames(Cond);
+ const std::string CondVarNames = getCondVarNames(Cond);
if (ShouldHaveConditionVariables && CondVarNames.empty())
return;
diff --git a/clang-tools-extra/clang-tidy/bugprone/IntegerDivisionCheck.h b/clang-tools-extra/clang-tidy/bugprone/IntegerDivisionCheck.h
index 777e3186..acab7be 100644
--- a/clang-tools-extra/clang-tidy/bugprone/IntegerDivisionCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/IntegerDivisionCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_INTEGER_DIVISION_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_INTEGER_DIVISION_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_INTEGERDIVISIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_INTEGERDIVISIONCHECK_H
#include "../ClangTidyCheck.h"
@@ -28,4 +28,4 @@ public:
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_INTEGER_DIVISION_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_INTEGERDIVISIONCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp
index 76df992..f3e94b6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp
@@ -20,6 +20,8 @@ namespace clang::tidy::bugprone {
namespace {
+// Preserve same name as AST_MATCHER(isCompleteAndHasNoZeroValue)
+// NOLINTNEXTLINE(llvm-prefer-static-over-anonymous-namespace)
bool isCompleteAndHasNoZeroValue(const EnumDecl *D) {
const EnumDecl *Definition = D->getDefinition();
return Definition && Definition->isComplete() &&
@@ -149,7 +151,7 @@ void InvalidEnumDefaultInitializationCheck::check(
SourceLocation Loc = InitExpr->getExprLoc();
if (Loc.isInvalid()) {
if (isa<ImplicitValueInitExpr, InitListExpr>(InitExpr)) {
- DynTypedNodeList Parents = ACtx.getParents(*InitExpr);
+ const DynTypedNodeList Parents = ACtx.getParents(*InitExpr);
if (Parents.empty())
return;
@@ -168,7 +170,7 @@ void InvalidEnumDefaultInitializationCheck::check(
// The expression may be implicitly generated for an initialization.
// Search for a parent initialization list with valid source location.
while (InitList->getExprLoc().isInvalid()) {
- DynTypedNodeList Parents = ACtx.getParents(*InitList);
+ const DynTypedNodeList Parents = ACtx.getParents(*InitList);
if (Parents.empty())
return;
InitList = Parents[0].get<InitListExpr>();
diff --git a/clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp
index fb73e89..1f666d2 100644
--- a/clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp
@@ -40,7 +40,7 @@ public:
bool HasLine = false;
for (const Token &T : MD.getMacroInfo()->tokens()) {
if (T.is(tok::identifier)) {
- StringRef IdentName = T.getIdentifierInfo()->getName();
+ const StringRef IdentName = T.getIdentifierInfo()->getName();
if (IdentName == "__FILE__") {
HasFile = true;
} else if (IdentName == "__LINE__") {
diff --git a/clang-tools-extra/clang-tidy/bugprone/MacroParenthesesCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MacroParenthesesCheck.cpp
index b16119d..6467fb5 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MacroParenthesesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/MacroParenthesesCheck.cpp
@@ -152,7 +152,6 @@ void MacroParenthesesPPCallbacks::replacementList(const Token &MacroNameTok,
void MacroParenthesesPPCallbacks::argument(const Token &MacroNameTok,
const MacroInfo *MI) {
-
// Skip variable declaration.
bool VarDecl = possibleVarDecl(MI, MI->tokens_begin());
diff --git a/clang-tools-extra/clang-tidy/bugprone/MacroRepeatedSideEffectsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MacroRepeatedSideEffectsCheck.cpp
index 78a53d1..c79320f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MacroRepeatedSideEffectsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/MacroRepeatedSideEffectsCheck.cpp
@@ -127,7 +127,7 @@ unsigned MacroRepeatedPPCallbacks::countArgumentExpansions(
continue;
}
- IdentifierInfo *TII = T.getIdentifierInfo();
+ const IdentifierInfo *TII = T.getIdentifierInfo();
// If not existent, skip it.
if (TII == nullptr)
continue;
diff --git a/clang-tools-extra/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.h b/clang-tools-extra/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.h
index f650145..c40aef3 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACED_OPERATOR_IN_STRLEN_IN_ALLOC_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACED_OPERATOR_IN_STRLEN_IN_ALLOC_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACEDOPERATORINSTRLENINALLOCCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACEDOPERATORINSTRLENINALLOCCHECK_H
#include "../ClangTidyCheck.h"
@@ -30,4 +30,4 @@ public:
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACED_OPERATOR_IN_STRLEN_IN_ALLOC_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACEDOPERATORINSTRLENINALLOCCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/MisplacedPointerArithmeticInAllocCheck.h b/clang-tools-extra/clang-tidy/bugprone/MisplacedPointerArithmeticInAllocCheck.h
index e78c30cb..9f6504f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MisplacedPointerArithmeticInAllocCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/MisplacedPointerArithmeticInAllocCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACED_OPERATOR_IN_ALLOC_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACED_OPERATOR_IN_ALLOC_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACEDPOINTERARITHMETICINALLOCCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACEDPOINTERARITHMETICINALLOCCHECK_H
#include "../ClangTidyCheck.h"
@@ -29,4 +29,4 @@ public:
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACED_OPERATOR_IN_ALLOC_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACEDPOINTERARITHMETICINALLOCCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
index d508e2a..f040235 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
@@ -52,8 +52,8 @@ static unsigned getMaxCalculationWidth(const ASTContext &Context,
E = E->IgnoreParenImpCasts();
if (const auto *Bop = dyn_cast<BinaryOperator>(E)) {
- unsigned LHSWidth = getMaxCalculationWidth(Context, Bop->getLHS());
- unsigned RHSWidth = getMaxCalculationWidth(Context, Bop->getRHS());
+ const unsigned LHSWidth = getMaxCalculationWidth(Context, Bop->getLHS());
+ const unsigned RHSWidth = getMaxCalculationWidth(Context, Bop->getRHS());
if (Bop->getOpcode() == BO_Mul)
return LHSWidth + RHSWidth;
if (Bop->getOpcode() == BO_Add)
@@ -79,7 +79,7 @@ static unsigned getMaxCalculationWidth(const ASTContext &Context,
if (Uop->getOpcode() == UO_Not)
return 1024U;
- QualType T = Uop->getType();
+ const QualType T = Uop->getType();
return T->isIntegerType() ? Context.getIntWidth(T) : 1024U;
} else if (const auto *I = dyn_cast<IntegerLiteral>(E)) {
return I->getValue().getActiveBits();
@@ -190,10 +190,10 @@ void MisplacedWideningCastCheck::check(const MatchFinder::MatchResult &Result) {
Calc->isTypeDependent() || Calc->isValueDependent())
return;
- ASTContext &Context = *Result.Context;
+ const ASTContext &Context = *Result.Context;
- QualType CastType = Cast->getType();
- QualType CalcType = Calc->getType();
+ const QualType CastType = Cast->getType();
+ const QualType CalcType = Calc->getType();
// Explicit truncation using cast.
if (Context.getIntWidth(CastType) < Context.getIntWidth(CalcType))
diff --git a/clang-tools-extra/clang-tidy/bugprone/MoveForwardingReferenceCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MoveForwardingReferenceCheck.cpp
index 66559a0..e182df7 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MoveForwardingReferenceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/MoveForwardingReferenceCheck.cpp
@@ -21,7 +21,7 @@ static void replaceMoveWithForward(const UnresolvedLookupExpr *Callee,
const SourceManager &SM = Context.getSourceManager();
const LangOptions &LangOpts = Context.getLangOpts();
- CharSourceRange CallRange =
+ const CharSourceRange CallRange =
Lexer::makeFileCharRange(CharSourceRange::getTokenRange(
Callee->getBeginLoc(), Callee->getEndLoc()),
SM, LangOpts);
@@ -39,7 +39,7 @@ static void replaceMoveWithForward(const UnresolvedLookupExpr *Callee,
// std::move(). This will hopefully prevent erroneous replacements if the
// code does unusual things (e.g. create an alias for std::move() in
// another namespace).
- NestedNameSpecifier NNS = Callee->getQualifier();
+ const NestedNameSpecifier NNS = Callee->getQualifier();
switch (NNS.getKind()) {
case NestedNameSpecifier::Kind::Null:
// Called as "move" (i.e. presumably the code had a "using std::move;").
diff --git a/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.cpp
index 2eff013..78f2017 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.cpp
@@ -86,8 +86,9 @@ MultiLevelImplicitPointerConversionCheck::getCheckTraversalKind() const {
void MultiLevelImplicitPointerConversionCheck::check(
const MatchFinder::MatchResult &Result) {
const auto *MatchedExpr = Result.Nodes.getNodeAs<ImplicitCastExpr>("expr");
- QualType Target = MatchedExpr->getType().getDesugaredType(*Result.Context);
- QualType Source =
+ const QualType Target =
+ MatchedExpr->getType().getDesugaredType(*Result.Context);
+ const QualType Source =
MatchedExpr->getSubExpr()->getType().getDesugaredType(*Result.Context);
diag(MatchedExpr->getExprLoc(), "multilevel pointer conversion from %0 to "
diff --git a/clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp
index 17aea93..b81d2b4 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp
@@ -51,7 +51,8 @@ namespace {
AST_MATCHER_P(CXXTryStmt, hasHandlerFor,
ast_matchers::internal::Matcher<QualType>, InnerMatcher) {
- for (unsigned NH = Node.getNumHandlers(), I = 0; I < NH; ++I) {
+ const unsigned NH = Node.getNumHandlers();
+ for (unsigned I = 0; I < NH; ++I) {
const CXXCatchStmt *CatchS = Node.getHandler(I);
// Check for generic catch handler (match anything).
if (CatchS->getCaughtType().isNull())
@@ -66,7 +67,7 @@ AST_MATCHER_P(CXXTryStmt, hasHandlerFor,
}
AST_MATCHER(CXXNewExpr, mayThrow) {
- FunctionDecl *OperatorNew = Node.getOperatorNew();
+ const FunctionDecl *OperatorNew = Node.getOperatorNew();
if (!OperatorNew)
return false;
return !OperatorNew->getType()->castAs<FunctionProtoType>()->isNothrow();
diff --git a/clang-tools-extra/clang-tidy/bugprone/MultipleStatementMacroCheck.h b/clang-tools-extra/clang-tidy/bugprone/MultipleStatementMacroCheck.h
index 1a2d4a4..1c3679a 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MultipleStatementMacroCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/MultipleStatementMacroCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MULTIPLE_STATEMENT_MACRO_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MULTIPLE_STATEMENT_MACRO_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MULTIPLESTATEMENTMACROCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MULTIPLESTATEMENTMACROCHECK_H
#include "../ClangTidyCheck.h"
@@ -29,4 +29,4 @@ public:
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MULTIPLE_STATEMENT_MACRO_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MULTIPLESTATEMENTMACROCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
index 287ee95..501a82d 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
@@ -29,15 +29,15 @@ AST_MATCHER_P(QualType, hasAnyType, std::vector<StringRef>, Names) {
if (Names.empty())
return false;
- std::string Name = Node.getLocalUnqualifiedType().getAsString();
+ const std::string Name = Node.getLocalUnqualifiedType().getAsString();
return llvm::is_contained(Names, Name);
}
AST_MATCHER(FieldDecl, hasIntBitwidth) {
assert(Node.isBitField());
const ASTContext &Ctx = Node.getASTContext();
- unsigned IntBitWidth = Ctx.getIntWidth(Ctx.IntTy);
- unsigned CurrentBitWidth = Node.getBitWidthValue();
+ const unsigned IntBitWidth = Ctx.getIntWidth(Ctx.IntTy);
+ const unsigned CurrentBitWidth = Node.getBitWidthValue();
return IntBitWidth == CurrentBitWidth;
}
@@ -79,7 +79,7 @@ void NarrowingConversionsCheck::registerMatchers(MatchFinder *Finder) {
const auto IsCeilFloorCallExpr = expr(callExpr(callee(functionDecl(
hasAnyName("::ceil", "::std::ceil", "::floor", "::std::floor")))));
- std::vector<StringRef> IgnoreConversionFromTypesVec =
+ const std::vector<StringRef> IgnoreConversionFromTypesVec =
utils::options::parseStringList(IgnoreConversionFromTypes);
// We may want to exclude other types from the checks, such as `size_type`
@@ -243,7 +243,7 @@ struct IntegerRange {
static IntegerRange createFromType(const ASTContext &Context,
const BuiltinType &T) {
if (T.isFloatingPoint()) {
- unsigned PrecisionBits = llvm::APFloatBase::semanticsPrecision(
+ const unsigned PrecisionBits = llvm::APFloatBase::semanticsPrecision(
Context.getFloatTypeSemantics(T.desugar()));
// Contrary to two's complement integer, floating point values are
// symmetric and have the same number of positive and negative values.
@@ -262,8 +262,8 @@ static IntegerRange createFromType(const ASTContext &Context,
return {LowerValue, UpperValue};
}
assert(T.isInteger() && "Unexpected builtin type");
- uint64_t TypeSize = Context.getTypeSize(&T);
- bool IsUnsignedInteger = T.isUnsignedInteger();
+ const uint64_t TypeSize = Context.getTypeSize(&T);
+ const bool IsUnsignedInteger = T.isUnsignedInteger();
return {llvm::APSInt::getMinValue(TypeSize, IsUnsignedInteger),
llvm::APSInt::getMaxValue(TypeSize, IsUnsignedInteger)};
}
@@ -271,15 +271,15 @@ static IntegerRange createFromType(const ASTContext &Context,
static bool isWideEnoughToHold(const ASTContext &Context,
const BuiltinType &FromType,
const BuiltinType &ToType) {
- IntegerRange FromIntegerRange = createFromType(Context, FromType);
- IntegerRange ToIntegerRange = createFromType(Context, ToType);
+ const IntegerRange FromIntegerRange = createFromType(Context, FromType);
+ const IntegerRange ToIntegerRange = createFromType(Context, ToType);
return ToIntegerRange.contains(FromIntegerRange);
}
static bool isWideEnoughToHold(const ASTContext &Context,
const llvm::APSInt &IntegerConstant,
const BuiltinType &ToType) {
- IntegerRange ToIntegerRange = createFromType(Context, ToType);
+ const IntegerRange ToIntegerRange = createFromType(Context, ToType);
return ToIntegerRange.contains(IntegerConstant);
}
@@ -289,13 +289,13 @@ static bool isWideEnoughToHold(const ASTContext &Context,
static bool isFloatExactlyRepresentable(const ASTContext &Context,
const llvm::APFloat &FloatConstant,
const QualType &DestType) {
- unsigned DestWidth = Context.getIntWidth(DestType);
- bool DestSigned = DestType->isSignedIntegerOrEnumerationType();
+ const unsigned DestWidth = Context.getIntWidth(DestType);
+ const bool DestSigned = DestType->isSignedIntegerOrEnumerationType();
llvm::APSInt Result = llvm::APSInt(DestWidth, !DestSigned);
bool IsExact = false;
- bool Overflows = FloatConstant.convertToInteger(
- Result, llvm::APFloat::rmTowardZero, &IsExact) &
- llvm::APFloat::opInvalidOp;
+ const bool Overflows = FloatConstant.convertToInteger(
+ Result, llvm::APFloat::rmTowardZero, &IsExact) &
+ llvm::APFloat::opInvalidOp;
return !Overflows && IsExact;
}
@@ -321,8 +321,8 @@ bool NarrowingConversionsCheck::isWarningInhibitedByEquivalentSize(
// With this option, we don't warn on conversions that have equivalent width
// in bits. eg. uint32 <-> int32.
if (!WarnOnEquivalentBitWidth) {
- uint64_t FromTypeSize = Context.getTypeSize(&FromType);
- uint64_t ToTypeSize = Context.getTypeSize(&ToType);
+ const uint64_t FromTypeSize = Context.getTypeSize(&FromType);
+ const uint64_t ToTypeSize = Context.getTypeSize(&ToType);
if (FromTypeSize == ToTypeSize) {
return true;
}
@@ -406,8 +406,8 @@ void NarrowingConversionsCheck::handleIntegralCast(const ASTContext &Context,
// With this option, we don't warn on conversions that have equivalent width
// in bits. eg. uint32 <-> int32.
if (!WarnOnEquivalentBitWidth) {
- uint64_t FromTypeSize = Context.getTypeSize(FromType);
- uint64_t ToTypeSize = Context.getTypeSize(ToType);
+ const uint64_t FromTypeSize = Context.getTypeSize(FromType);
+ const uint64_t ToTypeSize = Context.getTypeSize(ToType);
if (FromTypeSize == ToTypeSize)
return;
}
@@ -583,7 +583,7 @@ void NarrowingConversionsCheck::handleImplicitCast(
return;
if (handleConditionalOperator(Context, Lhs, Rhs))
return;
- SourceLocation SourceLoc = Lhs.getExprLoc();
+ const SourceLocation SourceLoc = Lhs.getExprLoc();
switch (Cast.getCastKind()) {
case CK_BooleanToSignedIntegral:
handleBooleanToSignedIntegral(Context, SourceLoc, Lhs, Rhs);
diff --git a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h
index 9631c71..e506e5b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NARROWING_CONVERSIONS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NARROWING_CONVERSIONS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NARROWINGCONVERSIONSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NARROWINGCONVERSIONSCHECK_H
#include "../ClangTidyCheck.h"
@@ -108,4 +108,4 @@ private:
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NARROWING_CONVERSIONS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NARROWINGCONVERSIONSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp
index 067577f..127af27 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp
@@ -11,7 +11,6 @@
#include "../utils/OptionsUtils.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include <algorithm>
using namespace clang::ast_matchers;
diff --git a/clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerIterationOrderCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerIterationOrderCheck.cpp
index abde115..fdb903a 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerIterationOrderCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerIterationOrderCheck.cpp
@@ -15,7 +15,6 @@ namespace clang::tidy::bugprone {
void NondeterministicPointerIterationOrderCheck::registerMatchers(
MatchFinder *Finder) {
-
auto LoopVariable = varDecl(hasType(
qualType(hasCanonicalType(anyOf(referenceType(), pointerType())))));
@@ -60,7 +59,7 @@ void NondeterministicPointerIterationOrderCheck::check(
TemplateArgs[0].getAsType()->isPointerType();
if (IsAlgoArgPointer) {
- SourceRange R = RangeInit->getSourceRange();
+ const SourceRange R = RangeInit->getSourceRange();
diag(R.getBegin(), "iteration of pointers is nondeterministic") << R;
}
}
@@ -69,7 +68,7 @@ void NondeterministicPointerIterationOrderCheck::check(
const auto *SortPointers = Result.Nodes.getNodeAs<Stmt>("sortsemantic");
if ((SortPointers) && !(SortPointers->getBeginLoc().isMacroID())) {
- SourceRange R = SortPointers->getSourceRange();
+ const SourceRange R = SortPointers->getSourceRange();
diag(R.getBegin(), "sorting pointers is nondeterministic") << R;
}
}
diff --git a/clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerIterationOrderCheck.h b/clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerIterationOrderCheck.h
index 054d580..46b4e12 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerIterationOrderCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerIterationOrderCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NONDETERMINISTIC_POINTER_ITERATION_ORDER_CHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NONDETERMINISTIC_POINTER_ITERATION_ORDER_CHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NONDETERMINISTICPOINTERITERATIONORDERCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NONDETERMINISTICPOINTERITERATIONORDERCHECK_H
#include "../ClangTidyCheck.h"
@@ -36,4 +36,4 @@ public:
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NONDETERMINISTIC_POINTER_ITERATION_ORDER_CHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NONDETERMINISTICPOINTERITERATIONORDERCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
index 08fae7b..7198c1b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
@@ -120,18 +120,18 @@ static int getGivenLength(const MatchFinder::MatchResult &Result) {
if (Result.Nodes.getNodeAs<Expr>(UnknownLengthName))
return 0;
- if (int Length =
+ if (const int Length =
getLength(Result.Nodes.getNodeAs<Expr>(WrongLengthExprName), Result))
return Length;
- if (int Length =
+ if (const int Length =
getLength(Result.Nodes.getNodeAs<Expr>(LengthExprName), Result))
return Length;
// Special case, for example 'strlen("foo")'.
if (const CallExpr *StrlenCE = getStrlenExpr(Result))
if (const Expr *Arg = StrlenCE->getArg(0)->IgnoreImpCasts())
- if (int ArgLength = getLength(Arg, Result))
+ if (const int ArgLength = getLength(Arg, Result))
return ArgLength;
return 0;
@@ -174,9 +174,9 @@ static bool isKnownDest(const MatchFinder::MatchResult &Result) {
// True if the capacity of the destination array is based on the given length,
// therefore we assume that it cannot overflow (e.g. 'malloc(given_length + 1)'
static bool isDestBasedOnGivenLength(const MatchFinder::MatchResult &Result) {
- StringRef DestCapacityExprStr =
+ const StringRef DestCapacityExprStr =
exprToStr(getDestCapacityExpr(Result), Result).trim();
- StringRef LengthExprStr =
+ const StringRef LengthExprStr =
exprToStr(Result.Nodes.getNodeAs<Expr>(LengthExprName), Result).trim();
return !DestCapacityExprStr.empty() && !LengthExprStr.empty() &&
@@ -226,8 +226,9 @@ isGivenLengthEqualToSrcLength(const MatchFinder::MatchResult &Result) {
if (isStringDataAndLength(Result))
return true;
- int GivenLength = getGivenLength(Result);
- int SrcLength = getLength(Result.Nodes.getNodeAs<Expr>(SrcExprName), Result);
+ const int GivenLength = getGivenLength(Result);
+ const int SrcLength =
+ getLength(Result.Nodes.getNodeAs<Expr>(SrcExprName), Result);
if (GivenLength != 0 && SrcLength != 0 && GivenLength == SrcLength)
return true;
@@ -261,15 +262,15 @@ static bool isDestCapacityOverflows(const MatchFinder::MatchResult &Result) {
return true;
const Expr *DestCapacityExpr = getDestCapacityExpr(Result);
- int DestCapacity = getLength(DestCapacityExpr, Result);
- int GivenLength = getGivenLength(Result);
+ const int DestCapacity = getLength(DestCapacityExpr, Result);
+ const int GivenLength = getGivenLength(Result);
if (GivenLength != 0 && DestCapacity != 0)
return isGivenLengthEqualToSrcLength(Result) && DestCapacity == GivenLength;
// Assume that the destination array's capacity cannot overflow if the
// expression of the memory allocation contains '+ 1'.
- StringRef DestCapacityExprStr = exprToStr(DestCapacityExpr, Result);
+ const StringRef DestCapacityExprStr = exprToStr(DestCapacityExpr, Result);
if (DestCapacityExprStr.contains("+1") || DestCapacityExprStr.contains("+ 1"))
return false;
@@ -297,7 +298,7 @@ static void lengthExprHandle(const Expr *LengthExpr,
// See whether we work with a macro.
bool IsMacroDefinition = false;
- StringRef LengthExprStr = exprToStr(LengthExpr, Result);
+ const StringRef LengthExprStr = exprToStr(LengthExpr, Result);
Preprocessor::macro_iterator It = PP->macro_begin();
while (It != PP->macro_end() && !IsMacroDefinition) {
if (It->first->getName() == LengthExprStr)
@@ -309,7 +310,7 @@ static void lengthExprHandle(const Expr *LengthExpr,
// Try to obtain an 'IntegerLiteral' and adjust it.
if (!IsMacroDefinition) {
if (const auto *LengthIL = dyn_cast<IntegerLiteral>(LengthExpr)) {
- uint64_t NewLength =
+ const uint64_t NewLength =
LengthIL->getValue().getZExtValue() +
(LengthHandle == LengthHandleKind::Increase ? 1 : -1);
@@ -347,7 +348,7 @@ static void lengthExprHandle(const Expr *LengthExpr,
}
// Try to inject the '+ 1'/'- 1' string.
- bool NeedInnerParen = BO && BO->getOpcode() != BO_Add;
+ const bool NeedInnerParen = BO && BO->getOpcode() != BO_Add;
if (NeedInnerParen)
Diag << FixItHint::CreateInsertion(LengthExpr->getBeginLoc(), "(");
@@ -384,8 +385,8 @@ static bool isDestExprFix(const MatchFinder::MatchResult &Result,
if (!Dest)
return false;
- std::string TempTyStr = Dest->getType().getAsString();
- StringRef TyStr = TempTyStr;
+ const std::string TempTyStr = Dest->getType().getAsString();
+ const StringRef TyStr = TempTyStr;
if (TyStr.starts_with("char") || TyStr.starts_with("wchar_t"))
return false;
@@ -397,7 +398,7 @@ static bool isDestExprFix(const MatchFinder::MatchResult &Result,
// increase the capacity by one to create space for the null terminator.
static bool isDestCapacityFix(const MatchFinder::MatchResult &Result,
DiagnosticBuilder &Diag) {
- bool IsOverflows = isDestCapacityOverflows(Result);
+ const bool IsOverflows = isDestCapacityOverflows(Result);
if (IsOverflows)
if (const Expr *CapacityExpr = getDestCapacityExpr(Result))
lengthExprHandle(CapacityExpr, LengthHandleKind::Increase, Result, Diag);
@@ -424,9 +425,9 @@ static void renameFunc(StringRef NewFuncName,
const MatchFinder::MatchResult &Result,
DiagnosticBuilder &Diag) {
const auto *FunctionExpr = Result.Nodes.getNodeAs<CallExpr>(FunctionExprName);
- int FuncNameLength =
+ const int FuncNameLength =
FunctionExpr->getDirectCallee()->getIdentifier()->getLength();
- SourceRange FuncNameRange(
+ const SourceRange FuncNameRange(
FunctionExpr->getBeginLoc(),
FunctionExpr->getBeginLoc().getLocWithOffset(FuncNameLength - 1));
@@ -451,7 +452,7 @@ static void insertDestCapacityArg(bool IsOverflows, StringRef Name,
const auto *FunctionExpr = Result.Nodes.getNodeAs<CallExpr>(FunctionExprName);
SmallString<64> NewSecondArg;
- if (int DestLength = getDestCapacity(Result)) {
+ if (const int DestLength = getDestCapacity(Result)) {
NewSecondArg = Twine(IsOverflows ? DestLength + 1 : DestLength).str();
} else {
NewSecondArg =
@@ -470,12 +471,12 @@ static void insertNullTerminatorExpr(StringRef Name,
const MatchFinder::MatchResult &Result,
DiagnosticBuilder &Diag) {
const auto *FunctionExpr = Result.Nodes.getNodeAs<CallExpr>(FunctionExprName);
- int FuncLocStartColumn = Result.SourceManager->getPresumedColumnNumber(
+ const int FuncLocStartColumn = Result.SourceManager->getPresumedColumnNumber(
FunctionExpr->getBeginLoc());
- SourceRange SpaceRange(
+ const SourceRange SpaceRange(
FunctionExpr->getBeginLoc().getLocWithOffset(-FuncLocStartColumn + 1),
FunctionExpr->getBeginLoc());
- StringRef SpaceBeforeStmtStr = Lexer::getSourceText(
+ const StringRef SpaceBeforeStmtStr = Lexer::getSourceText(
CharSourceRange::getCharRange(SpaceRange), *Result.SourceManager,
Result.Context->getLangOpts(), nullptr);
@@ -717,10 +718,10 @@ void NotNullTerminatedResultCheck::registerMatchers(MatchFinder *Finder) {
};
auto MatchCall = [=](CallContext CC) {
- std::string CharHandlerFuncName = "::" + CC.Name.str();
+ const std::string CharHandlerFuncName = "::" + CC.Name.str();
// Try to match with 'wchar_t' based function calls.
- std::string WcharHandlerFuncName =
+ const std::string WcharHandlerFuncName =
"::" + (CC.Name.starts_with("mem") ? "w" + CC.Name.str()
: "wcs" + CC.Name.substr(3).str());
@@ -804,7 +805,8 @@ void NotNullTerminatedResultCheck::check(
if (MI) {
const auto &T = MI->tokens().back();
if (T.isLiteral() && T.getLiteralData()) {
- StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
+ const StringRef ValueStr =
+ StringRef(T.getLiteralData(), T.getLength());
llvm::APInt IntValue;
ValueStr.getAsInteger(10, IntValue);
AreSafeFunctionsWanted = IntValue.getZExtValue();
@@ -819,7 +821,7 @@ void NotNullTerminatedResultCheck::check(
UseSafeFunctions = *AreSafeFunctionsWanted;
}
- StringRef Name = FunctionExpr->getDirectCallee()->getName();
+ const StringRef Name = FunctionExpr->getDirectCallee()->getName();
if (Name.starts_with("mem") || Name.starts_with("wmem"))
memoryHandlerFunctionFix(Name, Result);
else if (Name == "strerror_s")
@@ -864,16 +866,16 @@ void NotNullTerminatedResultCheck::memoryHandlerFunctionFix(
void NotNullTerminatedResultCheck::memcpyFix(
StringRef Name, const MatchFinder::MatchResult &Result,
DiagnosticBuilder &Diag) {
- bool IsOverflows = isDestCapacityFix(Result, Diag);
- bool IsDestFixed = isDestExprFix(Result, Diag);
+ const bool IsOverflows = isDestCapacityFix(Result, Diag);
+ const bool IsDestFixed = isDestExprFix(Result, Diag);
- bool IsCopy =
+ const bool IsCopy =
isGivenLengthEqualToSrcLength(Result) || isDestBasedOnGivenLength(Result);
- bool IsSafe = UseSafeFunctions && IsOverflows && isKnownDest(Result) &&
- !isDestBasedOnGivenLength(Result);
+ const bool IsSafe = UseSafeFunctions && IsOverflows && isKnownDest(Result) &&
+ !isDestBasedOnGivenLength(Result);
- bool IsDestLengthNotRequired =
+ const bool IsDestLengthNotRequired =
IsSafe && getLangOpts().CPlusPlus &&
Result.Nodes.getNodeAs<ArrayType>(DestArrayTyName) && !IsDestFixed;
@@ -892,14 +894,14 @@ void NotNullTerminatedResultCheck::memcpyFix(
void NotNullTerminatedResultCheck::memcpySFix(
StringRef Name, const MatchFinder::MatchResult &Result,
DiagnosticBuilder &Diag) {
- bool IsOverflows = isDestCapacityFix(Result, Diag);
- bool IsDestFixed = isDestExprFix(Result, Diag);
+ const bool IsOverflows = isDestCapacityFix(Result, Diag);
+ const bool IsDestFixed = isDestExprFix(Result, Diag);
- bool RemoveDestLength = getLangOpts().CPlusPlus &&
- Result.Nodes.getNodeAs<ArrayType>(DestArrayTyName) &&
- !IsDestFixed;
- bool IsCopy = isGivenLengthEqualToSrcLength(Result);
- bool IsSafe = IsOverflows;
+ const bool RemoveDestLength =
+ getLangOpts().CPlusPlus &&
+ Result.Nodes.getNodeAs<ArrayType>(DestArrayTyName) && !IsDestFixed;
+ const bool IsCopy = isGivenLengthEqualToSrcLength(Result);
+ const bool IsSafe = IsOverflows;
renameMemcpy(Name, IsCopy, IsSafe, Result, Diag);
@@ -932,7 +934,7 @@ void NotNullTerminatedResultCheck::memchrFix(
Diag << CastRemoveFix;
}
- StringRef NewFuncName = (Name[0] != 'w') ? "strchr" : "wcschr";
+ const StringRef NewFuncName = (Name[0] != 'w') ? "strchr" : "wcschr";
renameFunc(NewFuncName, Result, Diag);
removeArg(2, Result, Diag);
}
@@ -940,7 +942,7 @@ void NotNullTerminatedResultCheck::memchrFix(
void NotNullTerminatedResultCheck::memmoveFix(
StringRef Name, const MatchFinder::MatchResult &Result,
DiagnosticBuilder &Diag) const {
- bool IsOverflows = isDestCapacityFix(Result, Diag);
+ const bool IsOverflows = isDestCapacityFix(Result, Diag);
if (UseSafeFunctions && isKnownDest(Result)) {
renameFunc((Name[0] != 'w') ? "memmove_s" : "wmemmove_s", Result, Diag);
@@ -970,15 +972,15 @@ void NotNullTerminatedResultCheck::ncmpFix(
if (const CallExpr *StrlenExpr = getStrlenExpr(Result)) {
const Expr *LengthExprArg = StrlenExpr->getArg(0);
- StringRef FirstExprStr = exprToStr(FirstArgExpr, Result).trim();
- StringRef SecondExprStr = exprToStr(SecondArgExpr, Result).trim();
- StringRef LengthArgStr = exprToStr(LengthExprArg, Result).trim();
+ const StringRef FirstExprStr = exprToStr(FirstArgExpr, Result).trim();
+ const StringRef SecondExprStr = exprToStr(SecondArgExpr, Result).trim();
+ const StringRef LengthArgStr = exprToStr(LengthExprArg, Result).trim();
IsLengthTooLong =
LengthArgStr == FirstExprStr || LengthArgStr == SecondExprStr;
} else {
- int SrcLength =
+ const int SrcLength =
getLength(Result.Nodes.getNodeAs<Expr>(SrcExprName), Result);
- int GivenLength = getGivenLength(Result);
+ const int GivenLength = getGivenLength(Result);
if (SrcLength != 0 && GivenLength != 0)
IsLengthTooLong = GivenLength > SrcLength;
}
diff --git a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.h b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.h
index a8f4ca3..cf61eb5 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NOT_NULL_TERMINATED_RESULT_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NOT_NULL_TERMINATED_RESULT_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NOTNULLTERMINATEDRESULTCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NOTNULLTERMINATEDRESULTCHECK_H
#include "../ClangTidyCheck.h"
@@ -60,4 +60,4 @@ private:
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NOT_NULL_TERMINATED_RESULT_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NOTNULLTERMINATEDRESULTCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp
index 1b1e0401..19b4fc1 100644
--- a/clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp
@@ -101,11 +101,9 @@ void OptionalValueConversionCheck::registerMatchers(MatchFinder *Finder) {
hasName(MakeOptional),
returns(BindOptionalType)))),
hasArgument(0, OptionalDerefMatcher)),
- callExpr(
-
- argumentCountIs(1),
+ callExpr(argumentCountIs(1),
- hasArgument(0, OptionalDerefMatcher))),
+ hasArgument(0, OptionalDerefMatcher))),
unless(anyOf(hasAncestor(typeLoc()),
hasAncestor(expr(matchers::hasUnevaluatedContext())))))
.bind("expr"),
diff --git a/clang-tools-extra/clang-tidy/bugprone/PosixReturnCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/PosixReturnCheck.cpp
index 57196ad..0084ace 100644
--- a/clang-tools-extra/clang-tidy/bugprone/PosixReturnCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/PosixReturnCheck.cpp
@@ -66,8 +66,8 @@ void PosixReturnCheck::registerMatchers(MatchFinder *Finder) {
void PosixReturnCheck::check(const MatchFinder::MatchResult &Result) {
if (const auto *LessThanZeroOp =
Result.Nodes.getNodeAs<BinaryOperator>("ltzop")) {
- SourceLocation OperatorLoc = LessThanZeroOp->getOperatorLoc();
- StringRef NewBinOp =
+ const SourceLocation OperatorLoc = LessThanZeroOp->getOperatorLoc();
+ const StringRef NewBinOp =
LessThanZeroOp->getOpcode() == BinaryOperator::Opcode::BO_LT ? ">"
: "<";
diag(OperatorLoc, "the comparison always evaluates to false because %0 "
diff --git a/clang-tools-extra/clang-tidy/bugprone/PosixReturnCheck.h b/clang-tools-extra/clang-tidy/bugprone/PosixReturnCheck.h
index d72c86c..a9cb7a6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/PosixReturnCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/PosixReturnCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_POSIX_RETURN_CHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_POSIX_RETURN_CHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_POSIXRETURNCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_POSIXRETURNCHECK_H
#include "../ClangTidyCheck.h"
@@ -23,4 +23,4 @@ public:
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_POSIX_RETURN_CHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_POSIXRETURNCHECK_H
diff --git a/clang-tools-extra/clang-tidy/cert/ProperlySeededRandomGeneratorCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/RandomGeneratorSeedCheck.cpp
index b8bca72..3e32e9b 100644
--- a/clang-tools-extra/clang-tidy/cert/ProperlySeededRandomGeneratorCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/RandomGeneratorSeedCheck.cpp
@@ -6,29 +6,28 @@
//
//===----------------------------------------------------------------------===//
-#include "ProperlySeededRandomGeneratorCheck.h"
+#include "RandomGeneratorSeedCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "llvm/ADT/STLExtras.h"
using namespace clang::ast_matchers;
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
-ProperlySeededRandomGeneratorCheck::ProperlySeededRandomGeneratorCheck(
- StringRef Name, ClangTidyContext *Context)
+RandomGeneratorSeedCheck::RandomGeneratorSeedCheck(StringRef Name,
+ ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
RawDisallowedSeedTypes(
Options.get("DisallowedSeedTypes", "time_t,std::time_t")) {
RawDisallowedSeedTypes.split(DisallowedSeedTypes, ',');
}
-void ProperlySeededRandomGeneratorCheck::storeOptions(
- ClangTidyOptions::OptionMap &Opts) {
+void RandomGeneratorSeedCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "DisallowedSeedTypes", RawDisallowedSeedTypes);
}
-void ProperlySeededRandomGeneratorCheck::registerMatchers(MatchFinder *Finder) {
+void RandomGeneratorSeedCheck::registerMatchers(MatchFinder *Finder) {
auto RandomGeneratorEngineDecl = cxxRecordDecl(hasAnyName(
"::std::linear_congruential_engine", "::std::mersenne_twister_engine",
"::std::subtract_with_carry_engine", "::std::discard_block_engine",
@@ -75,8 +74,7 @@ void ProperlySeededRandomGeneratorCheck::registerMatchers(MatchFinder *Finder) {
this);
}
-void ProperlySeededRandomGeneratorCheck::check(
- const MatchFinder::MatchResult &Result) {
+void RandomGeneratorSeedCheck::check(const MatchFinder::MatchResult &Result) {
const auto *Ctor = Result.Nodes.getNodeAs<CXXConstructExpr>("ctor");
if (Ctor)
checkSeed(Result, Ctor);
@@ -91,8 +89,8 @@ void ProperlySeededRandomGeneratorCheck::check(
}
template <class T>
-void ProperlySeededRandomGeneratorCheck::checkSeed(
- const MatchFinder::MatchResult &Result, const T *Func) {
+void RandomGeneratorSeedCheck::checkSeed(const MatchFinder::MatchResult &Result,
+ const T *Func) {
if (Func->getNumArgs() == 0 || Func->getArg(0)->isDefaultArgument()) {
diag(Func->getExprLoc(),
"random number generator seeded with a default argument will generate "
@@ -118,4 +116,4 @@ void ProperlySeededRandomGeneratorCheck::checkSeed(
}
}
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/cert/ProperlySeededRandomGeneratorCheck.h b/clang-tools-extra/clang-tidy/bugprone/RandomGeneratorSeedCheck.h
index 7da01cc..c9c54ea 100644
--- a/clang-tools-extra/clang-tidy/cert/ProperlySeededRandomGeneratorCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/RandomGeneratorSeedCheck.h
@@ -6,13 +6,13 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_PROPERLY_SEEDED_RANDOM_GENERATOR_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_PROPERLY_SEEDED_RANDOM_GENERATOR_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_RANDOMGENERATORSEEDCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_RANDOMGENERATORSEEDCHECK_H
#include "../ClangTidyCheck.h"
#include <string>
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
/// Random number generator must be seeded properly.
///
@@ -20,10 +20,10 @@ namespace clang::tidy::cert {
/// constant expression is a security vulnerability.
///
/// For the user-facing documentation see:
-/// https://clang.llvm.org/extra/clang-tidy/checks/cert/msc51-cpp.html
-class ProperlySeededRandomGeneratorCheck : public ClangTidyCheck {
+/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/random-generator-seed.html
+class RandomGeneratorSeedCheck : public ClangTidyCheck {
public:
- ProperlySeededRandomGeneratorCheck(StringRef Name, ClangTidyContext *Context);
+ RandomGeneratorSeedCheck(StringRef Name, ClangTidyContext *Context);
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
@@ -37,6 +37,6 @@ private:
SmallVector<StringRef, 5> DisallowedSeedTypes;
};
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_PROPERLY_SEEDED_RANDOM_GENERATOR_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_RANDOMGENERATORSEEDCHECK_H
diff --git a/clang-tools-extra/clang-tidy/cert/NonTrivialTypesLibcMemoryCallsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/RawMemoryCallOnNonTrivialTypeCheck.cpp
index e266cf9..e212301 100644
--- a/clang-tools-extra/clang-tidy/cert/NonTrivialTypesLibcMemoryCallsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/RawMemoryCallOnNonTrivialTypeCheck.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "NonTrivialTypesLibcMemoryCallsCheck.h"
+#include "RawMemoryCallOnNonTrivialTypeCheck.h"
#include "../utils/OptionsUtils.h"
#include "clang/AST/Decl.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -17,7 +17,7 @@
using namespace clang::ast_matchers;
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
namespace {
AST_MATCHER(CXXRecordDecl, isTriviallyDefaultConstructible) {
@@ -48,24 +48,24 @@ static constexpr llvm::StringRef ComparisonOperators[] = {
"operator==", "operator!=", "operator<",
"operator>", "operator<=", "operator>="};
-NonTrivialTypesLibcMemoryCallsCheck::NonTrivialTypesLibcMemoryCallsCheck(
+RawMemoryCallOnNonTrivialTypeCheck::RawMemoryCallOnNonTrivialTypeCheck(
StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
MemSetNames(Options.get("MemSetNames", "")),
MemCpyNames(Options.get("MemCpyNames", "")),
MemCmpNames(Options.get("MemCmpNames", "")) {}
-void NonTrivialTypesLibcMemoryCallsCheck::storeOptions(
+void RawMemoryCallOnNonTrivialTypeCheck::storeOptions(
ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "MemSetNames", MemSetNames);
Options.store(Opts, "MemCpyNames", MemCpyNames);
Options.store(Opts, "MemCmpNames", MemCmpNames);
}
-void NonTrivialTypesLibcMemoryCallsCheck::registerMatchers(
- MatchFinder *Finder) {
+void RawMemoryCallOnNonTrivialTypeCheck::registerMatchers(MatchFinder *Finder) {
using namespace ast_matchers::internal;
- auto IsStructPointer = [](Matcher<CXXRecordDecl> Constraint = anything(),
+ auto IsStructPointer = [](const Matcher<CXXRecordDecl> &Constraint =
+ anything(),
bool Bind = false) {
return expr(unaryOperator(
hasOperatorName("&"),
@@ -75,8 +75,8 @@ void NonTrivialTypesLibcMemoryCallsCheck::registerMatchers(
};
auto IsRecordSizeOf =
expr(sizeOfExpr(hasArgumentOfType(equalsBoundNode("Record"))));
- auto ArgChecker = [&](Matcher<CXXRecordDecl> RecordConstraint,
- BindableMatcher<Stmt> SecondArg = expr()) {
+ auto ArgChecker = [&](const Matcher<CXXRecordDecl> &RecordConstraint,
+ const BindableMatcher<Stmt> &SecondArg = expr()) {
return allOf(argumentCountIs(3),
hasArgument(0, IsStructPointer(RecordConstraint, true)),
hasArgument(1, SecondArg), hasArgument(2, IsRecordSizeOf));
@@ -103,7 +103,7 @@ void NonTrivialTypesLibcMemoryCallsCheck::registerMatchers(
this);
}
-void NonTrivialTypesLibcMemoryCallsCheck::check(
+void RawMemoryCallOnNonTrivialTypeCheck::check(
const MatchFinder::MatchResult &Result) {
if (const auto *Caller = Result.Nodes.getNodeAs<CallExpr>("lazyConstruct")) {
diag(Caller->getBeginLoc(), "calling %0 on a non-trivially default "
@@ -122,4 +122,4 @@ void NonTrivialTypesLibcMemoryCallsCheck::check(
}
}
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/cert/NonTrivialTypesLibcMemoryCallsCheck.h b/clang-tools-extra/clang-tidy/bugprone/RawMemoryCallOnNonTrivialTypeCheck.h
index 4589ce4..002aac6 100644
--- a/clang-tools-extra/clang-tidy/cert/NonTrivialTypesLibcMemoryCallsCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/RawMemoryCallOnNonTrivialTypeCheck.h
@@ -6,22 +6,21 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_NONTRIVIALTYPESLIBCMEMORYCALLSCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_NONTRIVIALTYPESLIBCMEMORYCALLSCHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_RAWMEMORYCALLONNONTRIVIALTYPECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_RAWMEMORYCALLONNONTRIVIALTYPECHECK_H
#include "../ClangTidyCheck.h"
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
-/// Flags use of the `C` standard library functions 'memset', 'memcpy' and
+/// Flags use of the C standard library functions 'memset', 'memcpy' and
/// 'memcmp' and similar derivatives on non-trivial types.
///
/// For the user-facing documentation see:
-/// https://clang.llvm.org/extra/clang-tidy/checks/cert/oop57-cpp.html
-class NonTrivialTypesLibcMemoryCallsCheck : public ClangTidyCheck {
+/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/raw-memory-call-on-non-trivial-type.html
+class RawMemoryCallOnNonTrivialTypeCheck : public ClangTidyCheck {
public:
- NonTrivialTypesLibcMemoryCallsCheck(StringRef Name,
- ClangTidyContext *Context);
+ RawMemoryCallOnNonTrivialTypeCheck(StringRef Name, ClangTidyContext *Context);
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus && !LangOpts.ObjC;
}
@@ -35,6 +34,6 @@ private:
const StringRef MemCmpNames;
};
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_NONTRIVIALTYPESLIBCMEMORYCALLSCHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_RAWMEMORYCALLONNONTRIVIALTYPECHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
index 6abe53f..528c254 100644
--- a/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
@@ -112,7 +112,7 @@ void RedundantBranchConditionCheck::check(
if (isa<DeclRefExpr>(InnerIf->getCond()->IgnoreParenImpCasts()) ||
(BinOpCond && BinOpCond->getOpcode() == BO_LOr)) {
- SourceLocation IfBegin = InnerIf->getBeginLoc();
+ const SourceLocation IfBegin = InnerIf->getBeginLoc();
const Stmt *Body = InnerIf->getThen();
const Expr *OtherSide = nullptr;
if (BinOpCond) {
@@ -132,9 +132,9 @@ void RedundantBranchConditionCheck::check(
// If the other side has side effects then keep it.
if (OtherSide && OtherSide->HasSideEffects(*Result.Context)) {
- SourceLocation BeforeOtherSide =
+ const SourceLocation BeforeOtherSide =
OtherSide->getBeginLoc().getLocWithOffset(-1);
- SourceLocation AfterOtherSide =
+ const SourceLocation AfterOtherSide =
Lexer::findNextToken(OtherSide->getEndLoc(), *Result.SourceManager,
getLangOpts())
->getLocation();
@@ -161,12 +161,12 @@ void RedundantBranchConditionCheck::check(
const auto *LeftDRE =
dyn_cast<DeclRefExpr>(CondOp->getLHS()->IgnoreParenImpCasts());
if (LeftDRE && LeftDRE->getDecl() == CondVar) {
- SourceLocation BeforeRHS =
+ const SourceLocation BeforeRHS =
CondOp->getRHS()->getBeginLoc().getLocWithOffset(-1);
Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
CondOp->getLHS()->getBeginLoc(), BeforeRHS));
} else {
- SourceLocation AfterLHS =
+ const SourceLocation AfterLHS =
Lexer::findNextToken(CondOp->getLHS()->getEndLoc(),
*Result.SourceManager, getLangOpts())
->getLocation();
diff --git a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp
index a3265293..1107cef 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp
@@ -83,7 +83,7 @@ static const Decl *findRVRefOverload(const FunctionDecl &FD,
// FIXME:
// 1. overload in anonymous namespace
// 2. forward reference
- DeclContext::lookup_result LookupResult =
+ const DeclContext::lookup_result LookupResult =
FD.getParent()->lookup(FD.getNameInfo().getName());
if (LookupResult.isSingleResult()) {
return nullptr;
diff --git a/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
index c262b1c..282a3b2 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
@@ -283,7 +283,7 @@ static bool isStandardFunction(const FunctionDecl *FD) {
/// This includes all statements that have a class name with "CXX" prefix
/// and every other statement that is declared in file ExprCXX.h.
static bool isCXXOnlyStmt(const Stmt *S) {
- StringRef Name = S->getStmtClassName();
+ const StringRef Name = S->getStmtClassName();
if (Name.starts_with("CXX"))
return true;
// Check for all other class names in ExprCXX.h that have no 'CXX' prefix.
@@ -317,7 +317,7 @@ static SourceRange getSourceRangeOfStmt(const Stmt *S, ASTContext &Ctx) {
ParentMapContext &PM = Ctx.getParentMapContext();
DynTypedNode P = DynTypedNode::create(*S);
while (P.getSourceRange().isInvalid()) {
- DynTypedNodeList PL = PM.getParents(P);
+ const DynTypedNodeList PL = PM.getParents(P);
if (PL.size() != 1)
return {};
P = PL[0];
@@ -401,14 +401,15 @@ void SignalHandlerCheck::check(const MatchFinder::MatchResult &Result) {
}
// FIXME: Update CallGraph::getNode to use canonical decl?
- CallGraphNode *HandlerNode = CG.getNode(HandlerDecl->getCanonicalDecl());
+ const CallGraphNode *HandlerNode =
+ CG.getNode(HandlerDecl->getCanonicalDecl());
assert(HandlerNode &&
"Handler with body should be present in the call graph.");
// Start from signal handler and visit every function call.
auto Itr = llvm::df_begin(HandlerNode), ItrE = llvm::df_end(HandlerNode);
while (Itr != ItrE) {
const auto *CallF = dyn_cast<FunctionDecl>((*Itr)->getDecl());
- unsigned int PathL = Itr.getPathLength();
+ const unsigned int PathL = Itr.getPathLength();
if (CallF) {
// A signal handler or a function transitively reachable from the signal
// handler was found to be unsafe.
@@ -434,8 +435,8 @@ void SignalHandlerCheck::check(const MatchFinder::MatchResult &Result) {
bool SignalHandlerCheck::checkFunction(
const FunctionDecl *FD, const Expr *CallOrRef,
- std::function<void(bool)> ChainReporter) {
- bool FunctionIsCalled = isa<CallExpr>(CallOrRef);
+ llvm::function_ref<void(bool)> ChainReporter) {
+ const bool FunctionIsCalled = isa<CallExpr>(CallOrRef);
if (isStandardFunction(FD)) {
if (!isStandardFunctionAsyncSafe(FD)) {
@@ -470,7 +471,7 @@ bool SignalHandlerCheck::checkFunction(
bool SignalHandlerCheck::checkFunctionCPP14(
const FunctionDecl *FD, const Expr *CallOrRef,
- std::function<void(bool)> ChainReporter) {
+ llvm::function_ref<void(bool)> ChainReporter) {
if (!FD->isExternC()) {
diag(CallOrRef->getBeginLoc(),
"functions without C linkage are not allowed as signal "
@@ -492,7 +493,7 @@ bool SignalHandlerCheck::checkFunctionCPP14(
for (const auto &Match : Matches) {
const auto *FoundS = Match.getNodeAs<Stmt>("stmt");
if (isCXXOnlyStmt(FoundS)) {
- SourceRange R = getSourceRangeOfStmt(FoundS, Ctx);
+ const SourceRange R = getSourceRangeOfStmt(FoundS, Ctx);
if (R.isInvalid())
continue;
diag(R.getBegin(),
@@ -531,7 +532,7 @@ bool SignalHandlerCheck::isStandardFunctionAsyncSafe(
}
void SignalHandlerCheck::reportHandlerChain(
- const llvm::df_iterator<clang::CallGraphNode *> &Itr,
+ const llvm::df_iterator<const clang::CallGraphNode *> &Itr,
const DeclRefExpr *HandlerRef, bool SkipPathEnd) {
int CallLevel = Itr.getPathLength() - 2;
assert(CallLevel >= -1 && "Empty iterator?");
diff --git a/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h b/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h
index b5317793..324b2c8 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h
@@ -48,10 +48,10 @@ private:
/// The bool parameter is used like \c SkipPathEnd in \c reportHandlerChain .
/// \return Returns true if a diagnostic was emitted for this function.
bool checkFunction(const FunctionDecl *FD, const Expr *CallOrRef,
- std::function<void(bool)> ChainReporter);
+ llvm::function_ref<void(bool)> ChainReporter);
/// Similar as \c checkFunction but only check for C++14 rules.
bool checkFunctionCPP14(const FunctionDecl *FD, const Expr *CallOrRef,
- std::function<void(bool)> ChainReporter);
+ llvm::function_ref<void(bool)> ChainReporter);
/// Returns true if a standard library function is considered
/// asynchronous-safe.
bool isStandardFunctionAsyncSafe(const FunctionDecl *FD) const;
@@ -65,8 +65,9 @@ private:
/// registered as signal handler.
/// @param SkipPathEnd If true the last item of the call chain (farthest away
/// from the \c signal call) is omitted from note generation.
- void reportHandlerChain(const llvm::df_iterator<clang::CallGraphNode *> &Itr,
- const DeclRefExpr *HandlerRef, bool SkipPathEnd);
+ void
+ reportHandlerChain(const llvm::df_iterator<const clang::CallGraphNode *> &Itr,
+ const DeclRefExpr *HandlerRef, bool SkipPathEnd);
clang::CallGraph CG;
diff --git a/clang-tools-extra/clang-tidy/bugprone/SignedCharMisuseCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SignedCharMisuseCheck.cpp
index 742d85b..31c5413 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SignedCharMisuseCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SignedCharMisuseCheck.cpp
@@ -140,7 +140,7 @@ void SignedCharMisuseCheck::check(const MatchFinder::MatchResult &Result) {
if (!SignedCastExpression->isValueDependent() &&
SignedCastExpression->getSubExpr()->EvaluateAsInt(EVResult,
*Result.Context)) {
- llvm::APSInt Value = EVResult.Val.getInt();
+ const llvm::APSInt Value = EVResult.Val.getInt();
if (Value.isNonNegative())
return;
}
@@ -154,7 +154,7 @@ void SignedCharMisuseCheck::check(const MatchFinder::MatchResult &Result) {
if (!UnSignedCastExpression->isValueDependent() &&
UnSignedCastExpression->getSubExpr()->EvaluateAsInt(EVResult,
*Result.Context)) {
- llvm::APSInt Value = EVResult.Val.getInt();
+ const llvm::APSInt Value = EVResult.Val.getInt();
if (Value <= UnsignedASCIIUpperBound)
return;
}
diff --git a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
index 2672dc7..49ba3b8 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
@@ -407,9 +407,9 @@ void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) {
const auto *ElementTy = Result.Nodes.getNodeAs<Type>("elem-type");
const auto *PointedTy = Result.Nodes.getNodeAs<Type>("elem-ptr-type");
- CharUnits NumeratorSize = getSizeOfType(Ctx, NumTy);
- CharUnits DenominatorSize = getSizeOfType(Ctx, DenomTy);
- CharUnits ElementSize = getSizeOfType(Ctx, ElementTy);
+ const CharUnits NumeratorSize = getSizeOfType(Ctx, NumTy);
+ const CharUnits DenominatorSize = getSizeOfType(Ctx, DenomTy);
+ const CharUnits ElementSize = getSizeOfType(Ctx, ElementTy);
if (DenominatorSize > CharUnits::Zero() &&
!NumeratorSize.isMultipleOf(DenominatorSize)) {
diff --git a/clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.cpp
index ee797ec..af478b1 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.cpp
@@ -15,13 +15,11 @@ using namespace clang::ast_matchers;
namespace clang::tidy::bugprone {
-namespace {
+static constexpr char ConstructExprN[] = "found_construct_expr";
+static constexpr char NewExprN[] = "found_new_expr";
+static constexpr char ConstructorN[] = "found_constructor";
-constexpr char ConstructExprN[] = "found_construct_expr";
-constexpr char NewExprN[] = "found_new_expr";
-constexpr char ConstructorN[] = "found_constructor";
-
-bool isInSingleDeclStmt(const DeclaratorDecl *D) {
+static bool isInSingleDeclStmt(const DeclaratorDecl *D) {
const DynTypedNodeList Parents =
D->getASTContext().getParentMapContext().getParents(*D);
for (const DynTypedNode &PNode : Parents)
@@ -30,8 +28,8 @@ bool isInSingleDeclStmt(const DeclaratorDecl *D) {
return false;
}
-const DeclaratorDecl *getConstructedVarOrField(const Expr *FoundConstructExpr,
- ASTContext &Ctx) {
+static const DeclaratorDecl *
+getConstructedVarOrField(const Expr *FoundConstructExpr, ASTContext &Ctx) {
const DynTypedNodeList ConstructParents =
Ctx.getParentMapContext().getParents(*FoundConstructExpr);
if (ConstructParents.size() != 1)
@@ -43,8 +41,6 @@ const DeclaratorDecl *getConstructedVarOrField(const Expr *FoundConstructExpr,
return nullptr;
}
-} // namespace
-
const char SmartPtrArrayMismatchCheck::PointerTypeN[] = "pointer_type";
SmartPtrArrayMismatchCheck::SmartPtrArrayMismatchCheck(
@@ -97,10 +93,10 @@ void SmartPtrArrayMismatchCheck::check(const MatchFinder::MatchResult &Result) {
assert(TSTypeLoc.getNumArgs() >= 1 &&
"Matched type should have at least 1 template argument.");
- SourceRange TemplateArgumentRange = TSTypeLoc.getArgLoc(0)
- .getTypeSourceInfo()
- ->getTypeLoc()
- .getSourceRange();
+ const SourceRange TemplateArgumentRange = TSTypeLoc.getArgLoc(0)
+ .getTypeSourceInfo()
+ ->getTypeLoc()
+ .getSourceRange();
D << TemplateArgumentRange;
if (isInSingleDeclStmt(VarOrField)) {
@@ -108,7 +104,7 @@ void SmartPtrArrayMismatchCheck::check(const MatchFinder::MatchResult &Result) {
if (!utils::rangeCanBeFixed(TemplateArgumentRange, &SM))
return;
- SourceLocation InsertLoc = Lexer::getLocForEndOfToken(
+ const SourceLocation InsertLoc = Lexer::getLocForEndOfToken(
TemplateArgumentRange.getEnd(), 0, SM, Ctx.getLangOpts());
D << FixItHint::CreateInsertion(InsertLoc, "[]");
}
diff --git a/clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp
index 1e8058b..fd82b1c 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp
@@ -15,7 +15,6 @@ using namespace clang::ast_matchers;
namespace clang::tidy::bugprone {
void SpuriouslyWakeUpFunctionsCheck::registerMatchers(MatchFinder *Finder) {
-
auto HasUniqueLock = hasDescendant(declRefExpr(
hasDeclaration(varDecl(hasType(recordDecl(classTemplateSpecializationDecl(
hasName("::std::unique_lock"),
@@ -45,9 +44,7 @@ void SpuriouslyWakeUpFunctionsCheck::registerMatchers(MatchFinder *Finder) {
onImplicitObjectArgument(
declRefExpr(to(varDecl(hasType(references(recordDecl(
hasName("::std::condition_variable")))))))),
- HasUniqueLock)
-
- ))
+ HasUniqueLock)))
.bind("wait"));
auto HasWaitDescendantC = hasDescendant(
@@ -77,7 +74,7 @@ void SpuriouslyWakeUpFunctionsCheck::registerMatchers(MatchFinder *Finder) {
void SpuriouslyWakeUpFunctionsCheck::check(
const MatchFinder::MatchResult &Result) {
const auto *MatchedWait = Result.Nodes.getNodeAs<CallExpr>("wait");
- StringRef WaitName = MatchedWait->getDirectCallee()->getName();
+ const StringRef WaitName = MatchedWait->getDirectCallee()->getName();
diag(MatchedWait->getExprLoc(),
"'%0' should be placed inside a while statement %select{|or used with a "
"conditional parameter}1")
diff --git a/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
index a7958cc..056ae4b8 100644
--- a/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
@@ -117,12 +117,13 @@ void StandaloneEmptyCheck::check(const MatchFinder::MatchResult &Result) {
if (ParentReturnStmt)
return;
- SourceLocation MemberLoc = MemberCall->getBeginLoc();
- SourceLocation ReplacementLoc = MemberCall->getExprLoc();
- SourceRange ReplacementRange = SourceRange(ReplacementLoc, ReplacementLoc);
+ const SourceLocation MemberLoc = MemberCall->getBeginLoc();
+ const SourceLocation ReplacementLoc = MemberCall->getExprLoc();
+ const SourceRange ReplacementRange =
+ SourceRange(ReplacementLoc, ReplacementLoc);
ASTContext &Context = MemberCall->getRecordDecl()->getASTContext();
- DeclarationName Name =
+ const DeclarationName Name =
Context.DeclarationNames.getIdentifier(&Context.Idents.get("clear"));
auto Candidates = HeuristicResolver(Context).lookupDependentName(
@@ -133,11 +134,12 @@ void StandaloneEmptyCheck::check(const MatchFinder::MatchResult &Result) {
!llvm::cast<CXXMethodDecl>(ND)->isConst();
});
- bool HasClear = !Candidates.empty();
+ const bool HasClear = !Candidates.empty();
if (HasClear) {
const auto *Clear = llvm::cast<CXXMethodDecl>(Candidates.at(0));
- QualType RangeType = MemberCall->getImplicitObjectArgument()->getType();
- bool QualifierIncompatible =
+ const QualType RangeType =
+ MemberCall->getImplicitObjectArgument()->getType();
+ const bool QualifierIncompatible =
(!Clear->isVolatile() && RangeType.isVolatileQualified()) ||
RangeType.isConstQualified();
if (!QualifierIncompatible) {
@@ -162,8 +164,8 @@ void StandaloneEmptyCheck::check(const MatchFinder::MatchResult &Result) {
if (NonMemberCall->getNumArgs() != 1)
return;
- SourceLocation NonMemberLoc = NonMemberCall->getExprLoc();
- SourceLocation NonMemberEndLoc = NonMemberCall->getEndLoc();
+ const SourceLocation NonMemberLoc = NonMemberCall->getExprLoc();
+ const SourceLocation NonMemberEndLoc = NonMemberCall->getEndLoc();
const Expr *Arg = NonMemberCall->getArg(0);
CXXRecordDecl *ArgRecordDecl = Arg->getType()->getAsCXXRecordDecl();
@@ -171,7 +173,7 @@ void StandaloneEmptyCheck::check(const MatchFinder::MatchResult &Result) {
return;
ASTContext &Context = ArgRecordDecl->getASTContext();
- DeclarationName Name =
+ const DeclarationName Name =
Context.DeclarationNames.getIdentifier(&Context.Idents.get("clear"));
auto Candidates = HeuristicResolver(Context).lookupDependentName(
@@ -182,20 +184,20 @@ void StandaloneEmptyCheck::check(const MatchFinder::MatchResult &Result) {
!llvm::cast<CXXMethodDecl>(ND)->isConst();
});
- bool HasClear = !Candidates.empty();
+ const bool HasClear = !Candidates.empty();
if (HasClear) {
const auto *Clear = llvm::cast<CXXMethodDecl>(Candidates.at(0));
- bool QualifierIncompatible =
+ const bool QualifierIncompatible =
(!Clear->isVolatile() && Arg->getType().isVolatileQualified()) ||
Arg->getType().isConstQualified();
if (!QualifierIncompatible) {
- std::string ReplacementText =
+ const std::string ReplacementText =
std::string(Lexer::getSourceText(
CharSourceRange::getTokenRange(Arg->getSourceRange()),
*Result.SourceManager, getLangOpts())) +
".clear()";
- SourceRange ReplacementRange =
+ const SourceRange ReplacementRange =
SourceRange(NonMemberLoc, NonMemberEndLoc);
diag(NonMemberLoc,
"ignoring the result of '%0'; did you mean 'clear()'?")
diff --git a/clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/StdNamespaceModificationCheck.cpp
index 79fbc66..1dff741 100644
--- a/clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/StdNamespaceModificationCheck.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "DontModifyStdNamespaceCheck.h"
+#include "StdNamespaceModificationCheck.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchersInternal.h"
@@ -20,12 +20,12 @@ AST_POLYMORPHIC_MATCHER_P(
AST_POLYMORPHIC_SUPPORTED_TYPES(ClassTemplateSpecializationDecl,
TemplateSpecializationType, FunctionDecl),
clang::ast_matchers::internal::Matcher<TemplateArgument>, InnerMatcher) {
- ArrayRef<TemplateArgument> Args =
+ const ArrayRef<TemplateArgument> Args =
clang::ast_matchers::internal::getTemplateSpecializationArgs(Node);
for (const auto &Arg : Args) {
if (Arg.getKind() != TemplateArgument::Pack)
continue;
- ArrayRef<TemplateArgument> PackArgs = Arg.getPackAsArray();
+ const ArrayRef<TemplateArgument> PackArgs = Arg.getPackAsArray();
if (matchesFirstInRange(InnerMatcher, PackArgs.begin(), PackArgs.end(),
Finder, Builder) != PackArgs.end())
return true;
@@ -36,9 +36,9 @@ AST_POLYMORPHIC_MATCHER_P(
} // namespace
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
-void DontModifyStdNamespaceCheck::registerMatchers(MatchFinder *Finder) {
+void StdNamespaceModificationCheck::registerMatchers(MatchFinder *Finder) {
auto HasStdParent =
hasDeclContext(namespaceDecl(hasAnyName("std", "posix"),
unless(hasParent(namespaceDecl())))
@@ -96,7 +96,7 @@ void DontModifyStdNamespaceCheck::registerMatchers(MatchFinder *Finder) {
.bind("decl"),
this);
}
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
static const NamespaceDecl *getTopLevelLexicalNamespaceDecl(const Decl *D) {
const NamespaceDecl *LastNS = nullptr;
@@ -108,7 +108,7 @@ static const NamespaceDecl *getTopLevelLexicalNamespaceDecl(const Decl *D) {
return LastNS;
}
-void clang::tidy::cert::DontModifyStdNamespaceCheck::check(
+void clang::tidy::bugprone::StdNamespaceModificationCheck::check(
const MatchFinder::MatchResult &Result) {
const auto *D = Result.Nodes.getNodeAs<Decl>("decl");
const auto *NS = Result.Nodes.getNodeAs<NamespaceDecl>("nmspc");
diff --git a/clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.h b/clang-tools-extra/clang-tidy/bugprone/StdNamespaceModificationCheck.h
index cfcd8786..0f62dc3 100644
--- a/clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/StdNamespaceModificationCheck.h
@@ -6,21 +6,21 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_DONT_MODIFY_STD_NAMESPACE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_DONT_MODIFY_STD_NAMESPACE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_STDNAMESPACEMODIFICATIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_STDNAMESPACEMODIFICATIONCHECK_H
#include "../ClangTidyCheck.h"
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
/// Modification of the std or posix namespace can result in undefined behavior.
/// This check warns for such modifications.
///
/// For the user-facing documentation see:
-/// https://clang.llvm.org/extra/clang-tidy/checks/cert/dcl58-cpp.html
-class DontModifyStdNamespaceCheck : public ClangTidyCheck {
+/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/std-namespace-modification.html
+class StdNamespaceModificationCheck : public ClangTidyCheck {
public:
- DontModifyStdNamespaceCheck(StringRef Name, ClangTidyContext *Context)
+ StdNamespaceModificationCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
@@ -29,6 +29,6 @@ public:
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_DONT_MODIFY_STD_NAMESPACE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_STDNAMESPACEMODIFICATIONCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
index 832377e..d2e631e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
@@ -29,8 +29,8 @@ static std::vector<StringRef>
removeNamespaces(const std::vector<StringRef> &Names) {
std::vector<StringRef> Result;
Result.reserve(Names.size());
- for (StringRef Name : Names) {
- std::string::size_type ColonPos = Name.rfind(':');
+ for (const StringRef Name : Names) {
+ const std::string::size_type ColonPos = Name.rfind(':');
Result.push_back(
Name.substr(ColonPos == std::string::npos ? 0 : ColonPos + 1));
}
@@ -168,7 +168,7 @@ void StringConstructorCheck::check(const MatchFinder::MatchResult &Result) {
const ASTContext &Ctx = *Result.Context;
const auto *E = Result.Nodes.getNodeAs<CXXConstructExpr>("constructor");
assert(E && "missing constructor expression");
- SourceLocation Loc = E->getBeginLoc();
+ const SourceLocation Loc = E->getBeginLoc();
if (Result.Nodes.getNodeAs<Expr>("swapped-parameter")) {
const Expr *P0 = E->getArg(0);
diff --git a/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h b/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
index 0d7a203..9c08e4b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_STRING_CONSTRUCTOR_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_STRING_CONSTRUCTOR_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_STRINGCONSTRUCTORCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_STRINGCONSTRUCTORCHECK_H
#include "../ClangTidyCheck.h"
@@ -36,4 +36,4 @@ private:
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_STRING_CONSTRUCTOR_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_STRINGCONSTRUCTORCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
index 93a55ef54..8454fd1 100644
--- a/clang-tools-extra/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
@@ -129,7 +129,7 @@ void StringIntegerAssignmentCheck::check(
const auto *Argument = Result.Nodes.getNodeAs<Expr>("expr");
const auto CharType =
Result.Nodes.getNodeAs<QualType>("type")->getCanonicalType();
- SourceLocation Loc = Argument->getBeginLoc();
+ const SourceLocation Loc = Argument->getBeginLoc();
// Try to detect a few common expressions to reduce false positives.
if (CharExpressionDetector(CharType, *Result.Context)
@@ -145,7 +145,7 @@ void StringIntegerAssignmentCheck::check(
if (Loc.isMacroID())
return;
- bool IsWideCharType = CharType->isWideCharType();
+ const bool IsWideCharType = CharType->isWideCharType();
if (!CharType->isCharType() && !IsWideCharType)
return;
bool IsOneDigit = false;
@@ -155,7 +155,7 @@ void StringIntegerAssignmentCheck::check(
IsLiteral = true;
}
- SourceLocation EndLoc = Lexer::getLocForEndOfToken(
+ const SourceLocation EndLoc = Lexer::getLocForEndOfToken(
Argument->getEndLoc(), 0, *Result.SourceManager, getLangOpts());
if (IsOneDigit) {
Diag << FixItHint::CreateInsertion(Loc, IsWideCharType ? "L'" : "'")
diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
index 8dbe1c0..ef7f0b5 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
@@ -54,7 +54,7 @@ static int enumLength(const EnumDecl *EnumDec) {
static bool hasDisjointValueRange(const EnumDecl *Enum1,
const EnumDecl *Enum2) {
- ValueRange Range1(Enum1), Range2(Enum2);
+ const ValueRange Range1(Enum1), Range2(Enum2);
return llvm::APSInt::compareValues(Range1.MaxVal, Range2.MinVal) < 0 ||
llvm::APSInt::compareValues(Range2.MaxVal, Range1.MinVal) < 0;
}
@@ -94,9 +94,9 @@ static int countNonPowOfTwoLiteralNum(const EnumDecl *EnumDec) {
/// last enumerator is the sum of the lesser values (and initialized by a
/// literal) or when it could contain consecutive values.
static bool isPossiblyBitMask(const EnumDecl *EnumDec) {
- ValueRange VR(EnumDec);
- int EnumLen = enumLength(EnumDec);
- int NonPowOfTwoCounter = countNonPowOfTwoLiteralNum(EnumDec);
+ const ValueRange VR(EnumDec);
+ const int EnumLen = enumLength(EnumDec);
+ const int NonPowOfTwoCounter = countNonPowOfTwoLiteralNum(EnumDec);
return NonPowOfTwoCounter >= 1 && NonPowOfTwoCounter <= 2 &&
NonPowOfTwoCounter < EnumLen / 2 &&
(VR.MaxVal - VR.MinVal != EnumLen - 1) &&
diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
index aaf0594..5abbada 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
@@ -66,7 +66,7 @@ void SuspiciousIncludePPCallbacks::InclusionDirective(
if (!Check.IgnoredRegexString.empty() && Check.IgnoredRegex.match(FileName))
return;
- SourceLocation DiagLoc = FilenameRange.getBegin().getLocWithOffset(1);
+ const SourceLocation DiagLoc = FilenameRange.getBegin().getLocWithOffset(1);
const std::optional<StringRef> IFE =
utils::getFileExtension(FileName, Check.ImplementationFileExtensions);
@@ -81,7 +81,7 @@ void SuspiciousIncludePPCallbacks::InclusionDirective(
llvm::sys::path::replace_extension(GuessedFileName,
(!HFE.empty() ? "." : "") + HFE);
- OptionalFileEntryRef File =
+ const OptionalFileEntryRef File =
PP->LookupFile(DiagLoc, GuessedFileName, IsAngled, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
if (File) {
diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.cpp
index d1df2a8..7890afb 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.cpp
@@ -44,10 +44,10 @@ void SuspiciousMemoryComparisonCheck::check(
for (unsigned int ArgIndex = 0; ArgIndex < 2; ++ArgIndex) {
const Expr *ArgExpr = CE->getArg(ArgIndex);
- QualType ArgType = ArgExpr->IgnoreImplicit()->getType();
+ const QualType ArgType = ArgExpr->IgnoreImplicit()->getType();
const Type *PointeeType = ArgType->getPointeeOrArrayElementType();
assert(PointeeType != nullptr && "PointeeType should always be available.");
- QualType PointeeQualifiedType(PointeeType, 0);
+ const QualType PointeeQualifiedType(PointeeType, 0);
if (PointeeType->isRecordType()) {
if (const RecordDecl *RD =
@@ -65,7 +65,7 @@ void SuspiciousMemoryComparisonCheck::check(
}
if (!PointeeType->isIncompleteType()) {
- uint64_t PointeeSize = Ctx.getTypeSize(PointeeType);
+ const uint64_t PointeeSize = Ctx.getTypeSize(PointeeType);
if (ComparedBits && *ComparedBits >= PointeeSize &&
!Ctx.hasUniqueObjectRepresentations(PointeeQualifiedType)) {
diag(CE->getBeginLoc(),
diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
index b1d12ba..63ba2ed 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
@@ -60,7 +60,7 @@ void SuspiciousMemsetUsageCheck::check(const MatchFinder::MatchResult &Result) {
// Case 1: fill_char of memset() is a character '0'. Probably an
// integer zero was intended.
- SourceRange CharRange = CharZeroFill->getSourceRange();
+ const SourceRange CharRange = CharZeroFill->getSourceRange();
auto Diag =
diag(CharZeroFill->getBeginLoc(), "memset fill value is char '0', "
"potentially mistaken for int 0");
@@ -70,10 +70,8 @@ void SuspiciousMemsetUsageCheck::check(const MatchFinder::MatchResult &Result) {
return;
Diag << FixItHint::CreateReplacement(
CharSourceRange::getTokenRange(CharRange), "0");
- }
-
- else if (const auto *NumFill =
- Result.Nodes.getNodeAs<IntegerLiteral>("num-fill")) {
+ } else if (const auto *NumFill =
+ Result.Nodes.getNodeAs<IntegerLiteral>("num-fill")) {
// Case 2: fill_char of memset() is larger in size than an unsigned char
// so it gets truncated during conversion.
@@ -82,15 +80,13 @@ void SuspiciousMemsetUsageCheck::check(const MatchFinder::MatchResult &Result) {
if (!NumFill->EvaluateAsInt(EVResult, *Result.Context))
return;
- llvm::APSInt NumValue = EVResult.Val.getInt();
+ const llvm::APSInt NumValue = EVResult.Val.getInt();
if (NumValue >= 0 && NumValue <= UCharMax)
return;
diag(NumFill->getBeginLoc(), "memset fill value is out of unsigned "
"character range, gets truncated");
- }
-
- else if (const auto *Call = Result.Nodes.getNodeAs<CallExpr>("call")) {
+ } else if (const auto *Call = Result.Nodes.getNodeAs<CallExpr>("call")) {
// Case 3: byte_count of memset() is zero. This is most likely an
// argument swap.
@@ -110,7 +106,7 @@ void SuspiciousMemsetUsageCheck::check(const MatchFinder::MatchResult &Result) {
Expr::EvalResult EVResult;
if (!FillChar->isValueDependent() &&
FillChar->EvaluateAsInt(EVResult, *Result.Context)) {
- llvm::APSInt Value1 = EVResult.Val.getInt();
+ const llvm::APSInt Value1 = EVResult.Val.getInt();
if (Value1 == 0 || Value1.isNegative())
return;
}
@@ -120,8 +116,10 @@ void SuspiciousMemsetUsageCheck::check(const MatchFinder::MatchResult &Result) {
// and fix-its to swap the arguments.
auto D = diag(Call->getBeginLoc(),
"memset of size zero, potentially swapped arguments");
- StringRef RHSString = tooling::fixit::getText(*ByteCount, *Result.Context);
- StringRef LHSString = tooling::fixit::getText(*FillChar, *Result.Context);
+ const StringRef RHSString =
+ tooling::fixit::getText(*ByteCount, *Result.Context);
+ const StringRef LHSString =
+ tooling::fixit::getText(*FillChar, *Result.Context);
if (LHSString.empty() || RHSString.empty())
return;
diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.h b/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.h
index a1f5f2b..c45f332 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SUSPICIOUS_MEMSET_USAGE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SUSPICIOUS_MEMSET_USAGE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SUSPICIOUSMEMSETUSAGECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SUSPICIOUSMEMSETUSAGECHECK_H
#include "../ClangTidyCheck.h"
@@ -30,4 +30,4 @@ public:
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SUSPICIOUS_MEMSET_USAGE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SUSPICIOUSMEMSETUSAGECHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousMissingCommaCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousMissingCommaCheck.cpp
index a41f650..4f0d819 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousMissingCommaCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousMissingCommaCheck.cpp
@@ -19,7 +19,7 @@ static bool isConcatenatedLiteralsOnPurpose(ASTContext *Ctx,
// String literals surrounded by parentheses are assumed to be on purpose.
// i.e.: const char* Array[] = { ("a" "b" "c"), "d", [...] };
- TraversalKindScope RAII(*Ctx, TK_AsIs);
+ const TraversalKindScope RAII(*Ctx, TK_AsIs);
auto Parents = Ctx->getParents(*Lit);
if (Parents.size() == 1 && Parents[0].get<ParenExpr>() != nullptr)
return true;
@@ -35,15 +35,15 @@ static bool isConcatenatedLiteralsOnPurpose(ASTContext *Ctx,
// };
const SourceManager &SM = Ctx->getSourceManager();
bool IndentedCorrectly = true;
- SourceLocation FirstToken = Lit->getStrTokenLoc(0);
- FileID BaseFID = SM.getFileID(FirstToken);
- unsigned int BaseIndent = SM.getSpellingColumnNumber(FirstToken);
- unsigned int BaseLine = SM.getSpellingLineNumber(FirstToken);
+ const SourceLocation FirstToken = Lit->getStrTokenLoc(0);
+ const FileID BaseFID = SM.getFileID(FirstToken);
+ const unsigned int BaseIndent = SM.getSpellingColumnNumber(FirstToken);
+ const unsigned int BaseLine = SM.getSpellingLineNumber(FirstToken);
for (unsigned int TokNum = 1; TokNum < Lit->getNumConcatenated(); ++TokNum) {
- SourceLocation Token = Lit->getStrTokenLoc(TokNum);
- FileID FID = SM.getFileID(Token);
- unsigned int Indent = SM.getSpellingColumnNumber(Token);
- unsigned int Line = SM.getSpellingLineNumber(Token);
+ const SourceLocation Token = Lit->getStrTokenLoc(TokNum);
+ const FileID FID = SM.getFileID(Token);
+ const unsigned int Indent = SM.getSpellingColumnNumber(Token);
+ const unsigned int Line = SM.getSpellingLineNumber(Token);
if (FID != BaseFID || Line != BaseLine + TokNum || Indent <= BaseIndent) {
IndentedCorrectly = false;
break;
@@ -100,7 +100,7 @@ void SuspiciousMissingCommaCheck::check(
assert(InitializerList && ConcatenatedLiteral);
// Skip small arrays as they often generate false-positive.
- unsigned int Size = InitializerList->getNumInits();
+ const unsigned int Size = InitializerList->getNumInits();
if (Size < SizeThreshold)
return;
@@ -116,7 +116,7 @@ void SuspiciousMissingCommaCheck::check(
// Warn only when concatenation is not common in this initializer list.
// The current threshold is set to less than 1/5 of the string literals.
- if (double(Count) / Size > RatioThreshold)
+ if (static_cast<double>(Count) / Size > RatioThreshold)
return;
diag(ConcatenatedLiteral->getBeginLoc(),
diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
index b5da801..bf31218 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
@@ -44,7 +44,7 @@ public:
return false;
if (!check(E1->getBase(), E2->getBase()))
return false;
- DeclAccessPair FD = E1->getFoundDecl();
+ const DeclAccessPair FD = E1->getFoundDecl();
return isa<FieldDecl>(FD.getDecl()) && FD == E2->getFoundDecl();
}
@@ -92,10 +92,9 @@ public:
return false;
}
bool VisitStmt(const Stmt *S) {
- for (const Stmt *Child : S->children())
- if (Child && Visit(Child))
- return true;
- return false;
+ return llvm::any_of(S->children(), [this](const Stmt *Child) {
+ return Child && Visit(Child);
+ });
}
};
@@ -145,7 +144,7 @@ void SuspiciousReallocUsageCheck::check(
if (FindAssignToVarBefore{Var, DeclRef, SM}.Visit(Func->getBody()))
return;
- StringRef CodeOfAssignedExpr = Lexer::getSourceText(
+ const StringRef CodeOfAssignedExpr = Lexer::getSourceText(
CharSourceRange::getTokenRange(PtrResultExpr->getSourceRange()), SM,
getLangOpts());
diag(Call->getBeginLoc(), "'%0' may be set to null if 'realloc' fails, which "
diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp
index 543d312..9d37fc1 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp
@@ -31,7 +31,7 @@ void SuspiciousSemicolonCheck::check(const MatchFinder::MatchResult &Result) {
return;
const auto *Semicolon = Result.Nodes.getNodeAs<NullStmt>("semi");
- SourceLocation LocStart = Semicolon->getBeginLoc();
+ const SourceLocation LocStart = Semicolon->getBeginLoc();
if (LocStart.isMacroID())
return;
@@ -40,7 +40,7 @@ void SuspiciousSemicolonCheck::check(const MatchFinder::MatchResult &Result) {
auto Token = utils::lexer::getPreviousToken(LocStart, Ctxt.getSourceManager(),
Ctxt.getLangOpts());
auto &SM = *Result.SourceManager;
- unsigned SemicolonLine = SM.getSpellingLineNumber(LocStart);
+ const unsigned SemicolonLine = SM.getSpellingLineNumber(LocStart);
const auto *Statement = Result.Nodes.getNodeAs<Stmt>("stmt");
const bool IsIfStmt = isa<IfStmt>(Statement);
@@ -49,18 +49,20 @@ void SuspiciousSemicolonCheck::check(const MatchFinder::MatchResult &Result) {
SM.getSpellingLineNumber(Token.getLocation()) != SemicolonLine)
return;
- SourceLocation LocEnd = Semicolon->getEndLoc();
- FileID FID = SM.getFileID(LocEnd);
- llvm::MemoryBufferRef Buffer = SM.getBufferOrFake(FID, LocEnd);
+ const SourceLocation LocEnd = Semicolon->getEndLoc();
+ const FileID FID = SM.getFileID(LocEnd);
+ const llvm::MemoryBufferRef Buffer = SM.getBufferOrFake(FID, LocEnd);
Lexer Lexer(SM.getLocForStartOfFile(FID), Ctxt.getLangOpts(),
Buffer.getBufferStart(), SM.getCharacterData(LocEnd) + 1,
Buffer.getBufferEnd());
if (Lexer.LexFromRawLexer(Token))
return;
- unsigned BaseIndent = SM.getSpellingColumnNumber(Statement->getBeginLoc());
- unsigned NewTokenIndent = SM.getSpellingColumnNumber(Token.getLocation());
- unsigned NewTokenLine = SM.getSpellingLineNumber(Token.getLocation());
+ const unsigned BaseIndent =
+ SM.getSpellingColumnNumber(Statement->getBeginLoc());
+ const unsigned NewTokenIndent =
+ SM.getSpellingColumnNumber(Token.getLocation());
+ const unsigned NewTokenLine = SM.getSpellingLineNumber(Token.getLocation());
if (!IsIfStmt && NewTokenIndent <= BaseIndent &&
Token.getKind() != tok::l_brace && NewTokenLine != SemicolonLine)
diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.cpp
index 7519685..5da9240 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.cpp
@@ -88,7 +88,7 @@ void SuspiciousStringCompareCheck::registerMatchers(MatchFinder *Finder) {
// Add the list of known string compare-like functions and add user-defined
// functions.
- std::vector<StringRef> FunctionNames = utils::options::parseListPair(
+ const std::vector<StringRef> FunctionNames = utils::options::parseListPair(
KnownStringCompareFunctions, StringCompareLikeFunctions);
// Match a call to a string compare functions.
@@ -163,7 +163,7 @@ void SuspiciousStringCompareCheck::check(
assert(Decl != nullptr && Call != nullptr);
if (Result.Nodes.getNodeAs<Stmt>("missing-comparison")) {
- SourceLocation EndLoc = Lexer::getLocForEndOfToken(
+ const SourceLocation EndLoc = Lexer::getLocForEndOfToken(
Call->getRParenLoc(), 0, Result.Context->getSourceManager(),
getLangOpts());
@@ -173,10 +173,10 @@ void SuspiciousStringCompareCheck::check(
}
if (const auto *E = Result.Nodes.getNodeAs<Expr>("logical-not-comparison")) {
- SourceLocation EndLoc = Lexer::getLocForEndOfToken(
+ const SourceLocation EndLoc = Lexer::getLocForEndOfToken(
Call->getRParenLoc(), 0, Result.Context->getSourceManager(),
getLangOpts());
- SourceLocation NotLoc = E->getBeginLoc();
+ const SourceLocation NotLoc = E->getBeginLoc();
diag(Call->getBeginLoc(),
"function %0 is compared using logical not operator")
diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringviewDataUsageCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringviewDataUsageCheck.cpp
index d239cbe..cb37976 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringviewDataUsageCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringviewDataUsageCheck.cpp
@@ -43,7 +43,6 @@ SuspiciousStringviewDataUsageCheck::getCheckTraversalKind() const {
}
void SuspiciousStringviewDataUsageCheck::registerMatchers(MatchFinder *Finder) {
-
auto AncestorCall = anyOf(
cxxConstructExpr(), callExpr(unless(cxxOperatorCallExpr())), lambdaExpr(),
initListExpr(
diff --git a/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp
index bcedff5..152c0cb 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp
@@ -70,7 +70,7 @@ static bool areArgumentsPotentiallySwapped(const QualType LTo,
if (LTo == RFrom && REq)
return true;
- bool LEq = areTypesSemiEqual(LTo, RFrom);
+ const bool LEq = areTypesSemiEqual(LTo, RFrom);
if (RTo == LFrom && LEq)
return true;
diff --git a/clang-tools-extra/clang-tidy/bugprone/TaggedUnionMemberCountCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/TaggedUnionMemberCountCheck.cpp
index a85a136..c0d38dc 100644
--- a/clang-tools-extra/clang-tidy/bugprone/TaggedUnionMemberCountCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/TaggedUnionMemberCountCheck.cpp
@@ -104,7 +104,6 @@ void TaggedUnionMemberCountCheck::storeOptions(
}
void TaggedUnionMemberCountCheck::registerMatchers(MatchFinder *Finder) {
-
auto NotFromSystemHeaderOrStdNamespace =
unless(anyOf(isExpansionInSystemHeader(), isInStdNamespace()));
diff --git a/clang-tools-extra/clang-tidy/bugprone/ThrowingStaticInitializationCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ThrowingStaticInitializationCheck.cpp
index 56ec5a5..80905e2 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ThrowingStaticInitializationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ThrowingStaticInitializationCheck.cpp
@@ -44,7 +44,7 @@ void ThrowingStaticInitializationCheck::check(
"duration may throw an exception that cannot be caught")
<< VD << (VD->getStorageDuration() == SD_Static ? 0 : 1);
- SourceLocation FuncLocation = Func->getLocation();
+ const SourceLocation FuncLocation = Func->getLocation();
if (FuncLocation.isValid()) {
diag(FuncLocation,
"possibly throwing %select{constructor|function}0 declared here",
diff --git a/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
index 536b680..71b785f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
@@ -67,21 +67,21 @@ void TooSmallLoopVariableCheck::storeOptions(
/// LoopName: The entire for loop (as a ForStmt)
///
void TooSmallLoopVariableCheck::registerMatchers(MatchFinder *Finder) {
- StatementMatcher LoopVarMatcher =
+ const StatementMatcher LoopVarMatcher =
expr(ignoringParenImpCasts(
anyOf(declRefExpr(to(varDecl(hasType(isInteger())))),
memberExpr(member(fieldDecl(hasType(isInteger())))))))
.bind(LoopVarName);
// We need to catch only those comparisons which contain any integer cast.
- StatementMatcher LoopVarConversionMatcher = traverse(
+ const StatementMatcher LoopVarConversionMatcher = traverse(
TK_AsIs, implicitCastExpr(hasImplicitDestinationType(isInteger()),
has(ignoringParenImpCasts(LoopVarMatcher)))
.bind(LoopVarCastName));
// We are interested in only those cases when the loop bound is a variable
// value (not const, enum, etc.).
- StatementMatcher LoopBoundMatcher =
+ const StatementMatcher LoopBoundMatcher =
expr(ignoringParenImpCasts(allOf(
hasType(isInteger()), unless(integerLiteral()),
unless(allOf(
@@ -94,7 +94,7 @@ void TooSmallLoopVariableCheck::registerMatchers(MatchFinder *Finder) {
// We use the loop increment expression only to make sure we found the right
// loop variable.
- StatementMatcher IncrementMatcher =
+ const StatementMatcher IncrementMatcher =
expr(ignoringParenImpCasts(hasType(isInteger()))).bind(LoopIncrementName);
Finder->addMatcher(
@@ -121,14 +121,14 @@ static MagnitudeBits calcMagnitudeBits(const ASTContext &Context,
const Expr *IntExpr) {
assert(IntExprType->isIntegerType());
- unsigned SignedBits = IntExprType->isUnsignedIntegerType() ? 0U : 1U;
+ const unsigned SignedBits = IntExprType->isUnsignedIntegerType() ? 0U : 1U;
if (const auto *BitField = IntExpr->getSourceBitField()) {
- unsigned BitFieldWidth = BitField->getBitWidthValue();
+ const unsigned BitFieldWidth = BitField->getBitWidthValue();
return {BitFieldWidth - SignedBits, BitFieldWidth};
}
- unsigned IntWidth = Context.getIntWidth(IntExprType);
+ const unsigned IntWidth = Context.getIntWidth(IntExprType);
return {IntWidth - SignedBits, 0U};
}
@@ -143,18 +143,18 @@ calcUpperBoundMagnitudeBits(const ASTContext &Context, const Expr *UpperBound,
const Expr *RHSE = BinOperator->getRHS()->IgnoreParenImpCasts();
const Expr *LHSE = BinOperator->getLHS()->IgnoreParenImpCasts();
- QualType RHSEType = RHSE->getType();
- QualType LHSEType = LHSE->getType();
+ const QualType RHSEType = RHSE->getType();
+ const QualType LHSEType = LHSE->getType();
if (!RHSEType->isIntegerType() || !LHSEType->isIntegerType())
return {};
- bool RHSEIsConstantValue = RHSEType->isEnumeralType() ||
- RHSEType.isConstQualified() ||
- isa<IntegerLiteral>(RHSE);
- bool LHSEIsConstantValue = LHSEType->isEnumeralType() ||
- LHSEType.isConstQualified() ||
- isa<IntegerLiteral>(LHSE);
+ const bool RHSEIsConstantValue = RHSEType->isEnumeralType() ||
+ RHSEType.isConstQualified() ||
+ isa<IntegerLiteral>(RHSE);
+ const bool LHSEIsConstantValue = LHSEType->isEnumeralType() ||
+ LHSEType.isConstQualified() ||
+ isa<IntegerLiteral>(LHSE);
// Avoid false positives produced by two constant values.
if (RHSEIsConstantValue && LHSEIsConstantValue)
@@ -193,7 +193,7 @@ void TooSmallLoopVariableCheck::check(const MatchFinder::MatchResult &Result) {
if (LoopVar->getType() != LoopIncrement->getType())
return;
- ASTContext &Context = *Result.Context;
+ const ASTContext &Context = *Result.Context;
const QualType LoopVarType = LoopVar->getType();
const MagnitudeBits LoopVarMagnitudeBits =
diff --git a/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.h b/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.h
index 11086fb..62bf42d 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.h
@@ -25,7 +25,8 @@ class UncheckedOptionalAccessCheck : public ClangTidyCheck {
public:
UncheckedOptionalAccessCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
- ModelOptions{Options.get("IgnoreSmartPointerDereference", false)} {}
+ ModelOptions{Options.get("IgnoreSmartPointerDereference", false),
+ Options.get("IgnoreValueCalls", false)} {}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
@@ -34,6 +35,7 @@ public:
void storeOptions(ClangTidyOptions::OptionMap &Opts) override {
Options.store(Opts, "IgnoreSmartPointerDereference",
ModelOptions.IgnoreSmartPointerDereference);
+ Options.store(Opts, "IgnoreValueCalls", ModelOptions.IgnoreValueCalls);
}
private:
diff --git a/clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.cpp
index d1e7b89..b82c9d3 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.cpp
@@ -51,7 +51,7 @@ enum class ConversionKind {
static ConversionKind classifyConversionFunc(const FunctionDecl *FD) {
return llvm::StringSwitch<ConversionKind>(FD->getName())
- .Cases("atoi", "atol", ConversionKind::ToInt)
+ .Cases({"atoi", "atol"}, ConversionKind::ToInt)
.Case("atoll", ConversionKind::ToLongInt)
.Case("atof", ConversionKind::ToDouble)
.Default(ConversionKind::None);
@@ -76,7 +76,8 @@ static ConversionKind classifyFormatString(StringRef Fmt, const LangOptions &LO,
// Get the conversion specifier and use it to determine the conversion
// kind.
- analyze_scanf::ScanfConversionSpecifier SCS = FS.getConversionSpecifier();
+ const analyze_scanf::ScanfConversionSpecifier SCS =
+ FS.getConversionSpecifier();
if (SCS.isIntArg()) {
switch (FS.getLengthModifier().getKind()) {
case analyze_scanf::LengthModifier::AsLongLong:
@@ -194,7 +195,7 @@ void UncheckedStringToNumberConversionCheck::check(
// The format string comes from the call expression and depends on which
// flavor of scanf is called.
// Index 0: scanf, vscanf, Index 1: fscanf, sscanf, vfscanf, vsscanf.
- unsigned Idx =
+ const unsigned Idx =
(FFD->getName() == "scanf" || FFD->getName() == "vscanf") ? 0 : 1;
// Given the index, see if the call expression argument at that index is
diff --git a/clang-tools-extra/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.h b/clang-tools-extra/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.h
index c9a232a..409122f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNDEFINED_MEMORY_MANIPULATION_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNDEFINED_MEMORY_MANIPULATION_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNDEFINEDMEMORYMANIPULATIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNDEFINEDMEMORYMANIPULATIONCHECK_H
#include "../ClangTidyCheck.h"
@@ -29,4 +29,4 @@ public:
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNDEFINED_MEMORY_MANIPULATION_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNDEFINEDMEMORYMANIPULATIONCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/UndelegatedConstructorCheck.h b/clang-tools-extra/clang-tidy/bugprone/UndelegatedConstructorCheck.h
index 18465f7..c7cadbf6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UndelegatedConstructorCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/UndelegatedConstructorCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNDELEGATEDCONSTRUCTOR_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNDELEGATEDCONSTRUCTOR_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNDELEGATEDCONSTRUCTORCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNDELEGATEDCONSTRUCTORCHECK_H
#include "../ClangTidyCheck.h"
@@ -31,4 +31,4 @@ public:
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNDELEGATEDCONSTRUCTOR_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNDELEGATEDCONSTRUCTORCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/UnhandledExceptionAtNewCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnhandledExceptionAtNewCheck.cpp
index bf30753..340b136 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnhandledExceptionAtNewCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnhandledExceptionAtNewCheck.cpp
@@ -16,7 +16,8 @@ namespace {
AST_MATCHER_P(CXXTryStmt, hasHandlerFor,
ast_matchers::internal::Matcher<QualType>, InnerMatcher) {
- for (unsigned NH = Node.getNumHandlers(), I = 0; I < NH; ++I) {
+ const unsigned NH = Node.getNumHandlers();
+ for (unsigned I = 0; I < NH; ++I) {
const CXXCatchStmt *CatchS = Node.getHandler(I);
// Check for generic catch handler (match anything).
if (CatchS->getCaughtType().isNull())
@@ -31,7 +32,7 @@ AST_MATCHER_P(CXXTryStmt, hasHandlerFor,
}
AST_MATCHER(CXXNewExpr, mayThrow) {
- FunctionDecl *OperatorNew = Node.getOperatorNew();
+ const FunctionDecl *OperatorNew = Node.getOperatorNew();
if (!OperatorNew)
return false;
return !OperatorNew->getType()->castAs<FunctionProtoType>()->isNothrow();
diff --git a/clang-tools-extra/clang-tidy/bugprone/UnintendedCharOstreamOutputCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnintendedCharOstreamOutputCheck.cpp
index bce4657..e10b17c 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnintendedCharOstreamOutputCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnintendedCharOstreamOutputCheck.cpp
@@ -80,17 +80,17 @@ void UnintendedCharOstreamOutputCheck::check(
const Expr *Value = Call->getArg(1);
const SourceRange SourceRange = Value->getSourceRange();
- DiagnosticBuilder Builder =
+ const DiagnosticBuilder Builder =
diag(Call->getOperatorLoc(),
"%0 passed to 'operator<<' outputs as character instead of integer. "
"cast to 'unsigned int' to print numeric value or cast to 'char' to "
"print as character")
<< Value->getType() << SourceRange;
- QualType T = Value->getType();
+ const QualType T = Value->getType();
const Type *UnqualifiedDesugaredType = T->getUnqualifiedDesugaredType();
- llvm::StringRef CastType = CastTypeName.value_or(
+ const llvm::StringRef CastType = CastTypeName.value_or(
UnqualifiedDesugaredType->isSpecificBuiltinType(BuiltinType::SChar)
? "int"
: "unsigned int");
diff --git a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp
index 61ccd26..0a7467a 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp
@@ -141,7 +141,7 @@ parseCheckedFunctions(StringRef Option, ClangTidyContext *Context) {
std::vector<UnsafeFunctionsCheck::CheckedFunction> Result;
Result.reserve(Functions.size());
- for (StringRef Function : Functions) {
+ for (const StringRef Function : Functions) {
if (Function.empty())
continue;
@@ -266,8 +266,8 @@ void UnsafeFunctionsCheck::registerMatchers(MatchFinder *Finder) {
}
void UnsafeFunctionsCheck::check(const MatchFinder::MatchResult &Result) {
- const Expr *SourceExpr;
- const FunctionDecl *FuncDecl;
+ const Expr *SourceExpr = nullptr;
+ const FunctionDecl *FuncDecl = nullptr;
if (const auto *DeclRef = Result.Nodes.getNodeAs<DeclRefExpr>(DeclRefId)) {
SourceExpr = DeclRef;
@@ -304,11 +304,17 @@ void UnsafeFunctionsCheck::check(const MatchFinder::MatchResult &Result) {
StringRef Reason =
Entry.Reason.empty() ? "is marked as unsafe" : Entry.Reason.c_str();
- if (Entry.Replacement.empty()) {
+ // Omit the replacement, when a fully-custom reason is given.
+ if (Reason.consume_front(">")) {
+ diag(SourceExpr->getExprLoc(), "function %0 %1")
+ << FuncDecl << Reason.trim() << SourceExpr->getSourceRange();
+ // Do not recommend a replacement when it is not present.
+ } else if (Entry.Replacement.empty()) {
diag(SourceExpr->getExprLoc(),
"function %0 %1; it should not be used")
<< FuncDecl << Reason << Entry.Replacement
<< SourceExpr->getSourceRange();
+ // Otherwise, emit the replacement.
} else {
diag(SourceExpr->getExprLoc(),
"function %0 %1; '%2' should be used instead")
diff --git a/clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
index dae679b..6502fc9 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
@@ -37,8 +37,8 @@ void UnusedRaiiCheck::registerMatchers(MatchFinder *Finder) {
}
template <typename T>
-static void reportDiagnostic(DiagnosticBuilder D, const T *Node, SourceRange SR,
- bool DefaultConstruction) {
+static void reportDiagnostic(const DiagnosticBuilder &D, const T *Node,
+ SourceRange SR, bool DefaultConstruction) {
const char *Replacement = " give_me_a_name";
// If this is a default ctor we have to remove the parens or we'll introduce a
diff --git a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
index c2fc4af..6fbd392 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -25,7 +25,8 @@ namespace {
// member function are matched directly with InnerMatcher.
AST_MATCHER_P(FunctionDecl, isInstantiatedFrom, Matcher<FunctionDecl>,
InnerMatcher) {
- FunctionDecl *InstantiatedFrom = Node.getInstantiatedFromMemberFunction();
+ const FunctionDecl *InstantiatedFrom =
+ Node.getInstantiatedFromMemberFunction();
return InnerMatcher.matches(InstantiatedFrom ? *InstantiatedFrom : Node,
Finder, Builder);
}
diff --git a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
index efb5ec6..b2e08fe 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
@@ -19,6 +19,7 @@
#include "../utils/ExprSequence.h"
#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
#include <optional>
using namespace clang::ast_matchers;
@@ -48,7 +49,8 @@ struct UseAfterMove {
/// various internal helper functions).
class UseAfterMoveFinder {
public:
- UseAfterMoveFinder(ASTContext *TheContext);
+ UseAfterMoveFinder(ASTContext *TheContext,
+ llvm::ArrayRef<StringRef> InvalidationFunctions);
// Within the given code block, finds the first use of 'MovedVariable' that
// occurs after 'MovingCall' (the expression that performs the move). If a
@@ -71,6 +73,7 @@ private:
llvm::SmallPtrSetImpl<const DeclRefExpr *> *DeclRefs);
ASTContext *Context;
+ llvm::ArrayRef<StringRef> InvalidationFunctions;
std::unique_ptr<ExprSequence> Sequence;
std::unique_ptr<StmtToBlockMap> BlockMap;
llvm::SmallPtrSet<const CFGBlock *, 8> Visited;
@@ -78,6 +81,11 @@ private:
} // namespace
+static auto getNameMatcher(llvm::ArrayRef<StringRef> InvalidationFunctions) {
+ return anyOf(hasAnyName("::std::move", "::std::forward"),
+ matchers::matchesAnyListedName(InvalidationFunctions));
+}
+
// Matches nodes that are
// - Part of a decltype argument or class template argument (we check this by
// seeing if they are children of a TypeLoc), or
@@ -92,8 +100,9 @@ static StatementMatcher inDecltypeOrTemplateArg() {
hasAncestor(expr(hasUnevaluatedContext())));
}
-UseAfterMoveFinder::UseAfterMoveFinder(ASTContext *TheContext)
- : Context(TheContext) {}
+UseAfterMoveFinder::UseAfterMoveFinder(
+ ASTContext *TheContext, llvm::ArrayRef<StringRef> InvalidationFunctions)
+ : Context(TheContext), InvalidationFunctions(InvalidationFunctions) {}
std::optional<UseAfterMove>
UseAfterMoveFinder::find(Stmt *CodeBlock, const Expr *MovingCall,
@@ -255,7 +264,7 @@ static bool isStandardSmartPointer(const ValueDecl *VD) {
if (!ID)
return false;
- StringRef Name = ID->getName();
+ const StringRef Name = ID->getName();
if (Name != "unique_ptr" && Name != "shared_ptr" && Name != "weak_ptr")
return false;
@@ -359,7 +368,7 @@ void UseAfterMoveFinder::getReinits(
unless(parmVarDecl(hasType(
references(qualType(isConstQualified())))))),
unless(callee(functionDecl(
- hasAnyName("::std::move", "::std::forward")))))))
+ getNameMatcher(InvalidationFunctions)))))))
.bind("reinit");
Stmts->clear();
@@ -369,7 +378,7 @@ void UseAfterMoveFinder::getReinits(
if (!S)
continue;
- SmallVector<BoundNodes, 1> Matches =
+ const SmallVector<BoundNodes, 1> Matches =
match(findAll(ReinitMatcher), *S->getStmt(), *Context);
for (const auto &Match : Matches) {
@@ -388,18 +397,21 @@ void UseAfterMoveFinder::getReinits(
}
}
-enum class MoveType {
- Move, // std::move
- Forward, // std::forward
+enum MoveType {
+ Forward = 0, // std::forward
+ Move = 1, // std::move
+ Invalidation = 2, // other
};
static MoveType determineMoveType(const FunctionDecl *FuncDecl) {
- if (FuncDecl->getName() == "move")
- return MoveType::Move;
- if (FuncDecl->getName() == "forward")
- return MoveType::Forward;
+ if (FuncDecl->isInStdNamespace()) {
+ if (FuncDecl->getName() == "move")
+ return MoveType::Move;
+ if (FuncDecl->getName() == "forward")
+ return MoveType::Forward;
+ }
- llvm_unreachable("Invalid move type");
+ return MoveType::Invalidation;
}
static void emitDiagnostic(const Expr *MovingCall, const DeclRefExpr *MoveArg,
@@ -408,29 +420,38 @@ static void emitDiagnostic(const Expr *MovingCall, const DeclRefExpr *MoveArg,
const SourceLocation UseLoc = Use.DeclRef->getExprLoc();
const SourceLocation MoveLoc = MovingCall->getExprLoc();
- const bool IsMove = (Type == MoveType::Move);
-
- Check->diag(UseLoc, "'%0' used after it was %select{forwarded|moved}1")
- << MoveArg->getDecl()->getName() << IsMove;
- Check->diag(MoveLoc, "%select{forward|move}0 occurred here",
+ Check->diag(UseLoc,
+ "'%0' used after it was %select{forwarded|moved|invalidated}1")
+ << MoveArg->getDecl()->getName() << Type;
+ Check->diag(MoveLoc, "%select{forward|move|invalidation}0 occurred here",
DiagnosticIDs::Note)
- << IsMove;
+ << Type;
if (Use.EvaluationOrderUndefined) {
Check->diag(
UseLoc,
- "the use and %select{forward|move}0 are unsequenced, i.e. "
+ "the use and %select{forward|move|invalidation}0 are unsequenced, i.e. "
"there is no guarantee about the order in which they are evaluated",
DiagnosticIDs::Note)
- << IsMove;
+ << Type;
} else if (Use.UseHappensInLaterLoopIteration) {
Check->diag(UseLoc,
"the use happens in a later loop iteration than the "
- "%select{forward|move}0",
+ "%select{forward|move|invalidation}0",
DiagnosticIDs::Note)
- << IsMove;
+ << Type;
}
}
+UseAfterMoveCheck::UseAfterMoveCheck(StringRef Name, ClangTidyContext *Context)
+ : ClangTidyCheck(Name, Context),
+ InvalidationFunctions(utils::options::parseStringList(
+ Options.get("InvalidationFunctions", ""))) {}
+
+void UseAfterMoveCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+ Options.store(Opts, "InvalidationFunctions",
+ utils::options::serializeStringList(InvalidationFunctions));
+}
+
void UseAfterMoveCheck::registerMatchers(MatchFinder *Finder) {
// try_emplace is a common maybe-moving function that returns a
// bool to tell callers whether it moved. Ignore std::move inside
@@ -438,11 +459,14 @@ void UseAfterMoveCheck::registerMatchers(MatchFinder *Finder) {
// the bool.
auto TryEmplaceMatcher =
cxxMemberCallExpr(callee(cxxMethodDecl(hasName("try_emplace"))));
+ auto Arg = declRefExpr().bind("arg");
+ auto IsMemberCallee = callee(functionDecl(unless(isStaticStorageClass())));
auto CallMoveMatcher =
- callExpr(argumentCountIs(1),
- callee(functionDecl(hasAnyName("::std::move", "::std::forward"))
+ callExpr(callee(functionDecl(getNameMatcher(InvalidationFunctions))
.bind("move-decl")),
- hasArgument(0, declRefExpr().bind("arg")),
+ anyOf(cxxMemberCallExpr(IsMemberCallee, on(Arg)),
+ callExpr(unless(cxxMemberCallExpr(IsMemberCallee)),
+ hasArgument(0, Arg))),
unless(inDecltypeOrTemplateArg()),
unless(hasParent(TryEmplaceMatcher)), expr().bind("call-move"),
anyOf(hasAncestor(compoundStmt(
@@ -506,7 +530,7 @@ void UseAfterMoveCheck::check(const MatchFinder::MatchResult &Result) {
if (ContainingCtorInit) {
// Collect the constructor initializer expressions.
bool BeforeMove{true};
- for (CXXCtorInitializer *Init : ContainingCtor->inits()) {
+ for (const CXXCtorInitializer *Init : ContainingCtor->inits()) {
if (BeforeMove && Init->getInit()->IgnoreImplicit() ==
ContainingCtorInit->IgnoreImplicit())
BeforeMove = false;
@@ -521,7 +545,7 @@ void UseAfterMoveCheck::check(const MatchFinder::MatchResult &Result) {
}
for (Stmt *CodeBlock : CodeBlocks) {
- UseAfterMoveFinder Finder(Result.Context);
+ UseAfterMoveFinder Finder(Result.Context, InvalidationFunctions);
if (auto Use = Finder.find(CodeBlock, MovingCall, Arg))
emitDiagnostic(MovingCall, Arg, *Use, this, Result.Context,
determineMoveType(MoveDecl));
diff --git a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.h b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.h
index d38b29e..1bbf5c0 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.h
@@ -20,13 +20,16 @@ namespace clang::tidy::bugprone {
/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/use-after-move.html
class UseAfterMoveCheck : public ClangTidyCheck {
public:
- UseAfterMoveCheck(StringRef Name, ClangTidyContext *Context)
- : ClangTidyCheck(Name, Context) {}
+ UseAfterMoveCheck(StringRef Name, ClangTidyContext *Context);
+ void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus11;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+
+private:
+ std::vector<StringRef> InvalidationFunctions;
};
} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
index cef8b4d..0d69b9f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
@@ -37,14 +37,14 @@ static bool isOverrideMethod(const CXXMethodDecl *MD) {
static bool checkOverridingFunctionReturnType(const ASTContext *Context,
const CXXMethodDecl *BaseMD,
const CXXMethodDecl *DerivedMD) {
- QualType BaseReturnTy = BaseMD->getType()
- ->castAs<FunctionType>()
- ->getReturnType()
- .getCanonicalType();
- QualType DerivedReturnTy = DerivedMD->getType()
- ->castAs<FunctionType>()
- ->getReturnType()
- .getCanonicalType();
+ const QualType BaseReturnTy = BaseMD->getType()
+ ->castAs<FunctionType>()
+ ->getReturnType()
+ .getCanonicalType();
+ const QualType DerivedReturnTy = DerivedMD->getType()
+ ->castAs<FunctionType>()
+ ->getReturnType()
+ .getCanonicalType();
if (DerivedReturnTy->isDependentType() || BaseReturnTy->isDependentType())
return false;
@@ -63,8 +63,8 @@ static bool checkOverridingFunctionReturnType(const ASTContext *Context,
/// BTy is the class type in return type of BaseMD. For example,
/// B* Base::md()
/// While BRD is the declaration of B.
- QualType DTy = DerivedReturnTy->getPointeeType().getCanonicalType();
- QualType BTy = BaseReturnTy->getPointeeType().getCanonicalType();
+ const QualType DTy = DerivedReturnTy->getPointeeType().getCanonicalType();
+ const QualType BTy = BaseReturnTy->getPointeeType().getCanonicalType();
const CXXRecordDecl *DRD = DTy->getAsCXXRecordDecl();
const CXXRecordDecl *BRD = BTy->getAsCXXRecordDecl();
@@ -94,7 +94,7 @@ static bool checkOverridingFunctionReturnType(const ASTContext *Context,
// Check accessibility.
// FIXME: We currently only support checking if B is accessible base class
// of D, or D is the same class which DerivedMD is in.
- bool IsItself =
+ const bool IsItself =
DRD->getCanonicalDecl() == DerivedMD->getParent()->getCanonicalDecl();
bool HasPublicAccess = false;
for (const auto &Path : Paths) {
@@ -129,8 +129,8 @@ static QualType getDecayedType(QualType Type) {
/// \returns true if the param types are the same.
static bool checkParamTypes(const CXXMethodDecl *BaseMD,
const CXXMethodDecl *DerivedMD) {
- unsigned NumParamA = BaseMD->getNumParams();
- unsigned NumParamB = DerivedMD->getNumParams();
+ const unsigned NumParamA = BaseMD->getNumParams();
+ const unsigned NumParamB = DerivedMD->getNumParams();
if (NumParamA != NumParamB)
return false;
@@ -184,10 +184,10 @@ bool VirtualNearMissCheck::isPossibleToBeOverridden(
if (!Inserted)
return Iter->second;
- bool IsPossible = !BaseMD->isImplicit() && !isa<CXXConstructorDecl>(BaseMD) &&
- !isa<CXXDestructorDecl>(BaseMD) && BaseMD->isVirtual() &&
- !BaseMD->isOverloadedOperator() &&
- !isa<CXXConversionDecl>(BaseMD);
+ const bool IsPossible =
+ !BaseMD->isImplicit() && !isa<CXXConstructorDecl>(BaseMD) &&
+ !isa<CXXDestructorDecl>(BaseMD) && BaseMD->isVirtual() &&
+ !BaseMD->isOverloadedOperator() && !isa<CXXConversionDecl>(BaseMD);
Iter->second = IsPossible;
return IsPossible;
}
@@ -241,7 +241,7 @@ void VirtualNearMissCheck::check(const MatchFinder::MatchResult &Result) {
if (isOverriddenByDerivedClass(BaseMD, DerivedRD))
continue;
- unsigned EditDistance = BaseMD->getName().edit_distance(
+ const unsigned EditDistance = BaseMD->getName().edit_distance(
DerivedMD->getName(), EditDistanceThreshold);
if (EditDistance > 0 && EditDistance <= EditDistanceThreshold) {
if (checkOverrideWithoutName(Context, BaseMD, DerivedMD)) {
@@ -249,8 +249,8 @@ void VirtualNearMissCheck::check(const MatchFinder::MatchResult &Result) {
auto Range = CharSourceRange::getTokenRange(
SourceRange(DerivedMD->getLocation()));
- bool ApplyFix = !BaseMD->isTemplateInstantiation() &&
- !DerivedMD->isTemplateInstantiation();
+ const bool ApplyFix = !BaseMD->isTemplateInstantiation() &&
+ !DerivedMD->isTemplateInstantiation();
auto Diag =
diag(DerivedMD->getBeginLoc(),
"method '%0' has a similar name and the same signature as "
diff --git a/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.h b/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.h
index 71d302f4..2278817 100644
--- a/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_VIRTUAL_NEAR_MISS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_VIRTUAL_NEAR_MISS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_VIRTUALNEARMISSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_VIRTUALNEARMISSCHECK_H
#include "../ClangTidyCheck.h"
#include "llvm/ADT/DenseMap.h"
@@ -60,4 +60,4 @@ private:
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_VIRTUAL_NEAR_MISS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_VIRTUALNEARMISSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
index c1ca2ce..16d4be98 100644
--- a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
@@ -11,12 +11,19 @@
#include "../ClangTidyModuleRegistry.h"
#include "../bugprone/BadSignalToKillThreadCheck.h"
#include "../bugprone/CommandProcessorCheck.h"
+#include "../bugprone/CopyConstructorMutatesArgumentCheck.h"
+#include "../bugprone/DefaultOperatorNewOnOveralignedTypeCheck.h"
+#include "../bugprone/ExceptionCopyConstructorThrowsCheck.h"
+#include "../bugprone/FloatLoopCounterCheck.h"
#include "../bugprone/PointerArithmeticOnPolymorphicObjectCheck.h"
+#include "../bugprone/RandomGeneratorSeedCheck.h"
+#include "../bugprone/RawMemoryCallOnNonTrivialTypeCheck.h"
#include "../bugprone/ReservedIdentifierCheck.h"
#include "../bugprone/SignalHandlerCheck.h"
#include "../bugprone/SignedCharMisuseCheck.h"
#include "../bugprone/SizeofExpressionCheck.h"
#include "../bugprone/SpuriouslyWakeUpFunctionsCheck.h"
+#include "../bugprone/StdNamespaceModificationCheck.h"
#include "../bugprone/SuspiciousMemoryComparisonCheck.h"
#include "../bugprone/ThrowingStaticInitializationCheck.h"
#include "../bugprone/UncheckedStringToNumberConversionCheck.h"
@@ -26,7 +33,8 @@
#include "../concurrency/ThreadCanceltypeAsynchronousCheck.h"
#include "../google/UnnamedNamespaceInHeaderCheck.h"
#include "../misc/NewDeleteOverloadsCheck.h"
-#include "../misc/NonCopyableObjects.h"
+#include "../misc/NonCopyableObjectsCheck.h"
+#include "../misc/PredictableRandCheck.h"
#include "../misc/StaticAssertCheck.h"
#include "../misc/ThrowByValueCatchByReferenceCheck.h"
#include "../modernize/AvoidSetjmpLongjmpCheck.h"
@@ -34,14 +42,6 @@
#include "../performance/MoveConstructorInitCheck.h"
#include "../readability/EnumInitialValueCheck.h"
#include "../readability/UppercaseLiteralSuffixCheck.h"
-#include "DefaultOperatorNewAlignmentCheck.h"
-#include "DontModifyStdNamespaceCheck.h"
-#include "FloatLoopCounter.h"
-#include "LimitedRandomnessCheck.h"
-#include "MutatingCopyCheck.h"
-#include "NonTrivialTypesLibcMemoryCallsCheck.h"
-#include "ProperlySeededRandomGeneratorCheck.h"
-#include "ThrownExceptionTypeCheck.h"
namespace {
@@ -251,7 +251,8 @@ public:
"cert-dcl51-cpp");
CheckFactories.registerCheck<misc::NewDeleteOverloadsCheck>(
"cert-dcl54-cpp");
- CheckFactories.registerCheck<DontModifyStdNamespaceCheck>("cert-dcl58-cpp");
+ CheckFactories.registerCheck<bugprone::StdNamespaceModificationCheck>(
+ "cert-dcl58-cpp");
CheckFactories.registerCheck<google::build::UnnamedNamespaceInHeaderCheck>(
"cert-dcl59-cpp");
// ERR
@@ -261,15 +262,17 @@ public:
"cert-err52-cpp");
CheckFactories.registerCheck<bugprone::ThrowingStaticInitializationCheck>(
"cert-err58-cpp");
- CheckFactories.registerCheck<ThrownExceptionTypeCheck>("cert-err60-cpp");
+ CheckFactories.registerCheck<bugprone::ExceptionCopyConstructorThrowsCheck>(
+ "cert-err60-cpp");
CheckFactories.registerCheck<misc::ThrowByValueCatchByReferenceCheck>(
"cert-err61-cpp");
// MEM
- CheckFactories.registerCheck<DefaultOperatorNewAlignmentCheck>(
- "cert-mem57-cpp");
+ CheckFactories
+ .registerCheck<bugprone::DefaultOperatorNewOnOveralignedTypeCheck>(
+ "cert-mem57-cpp");
// MSC
- CheckFactories.registerCheck<LimitedRandomnessCheck>("cert-msc50-cpp");
- CheckFactories.registerCheck<ProperlySeededRandomGeneratorCheck>(
+ CheckFactories.registerCheck<misc::PredictableRandCheck>("cert-msc50-cpp");
+ CheckFactories.registerCheck<bugprone::RandomGeneratorSeedCheck>(
"cert-msc51-cpp");
CheckFactories.registerCheck<bugprone::SignalHandlerCheck>(
"cert-msc54-cpp");
@@ -278,9 +281,10 @@ public:
"cert-oop11-cpp");
CheckFactories.registerCheck<bugprone::UnhandledSelfAssignmentCheck>(
"cert-oop54-cpp");
- CheckFactories.registerCheck<NonTrivialTypesLibcMemoryCallsCheck>(
+ CheckFactories.registerCheck<bugprone::RawMemoryCallOnNonTrivialTypeCheck>(
"cert-oop57-cpp");
- CheckFactories.registerCheck<MutatingCopyCheck>("cert-oop58-cpp");
+ CheckFactories.registerCheck<bugprone::CopyConstructorMutatesArgumentCheck>(
+ "cert-oop58-cpp");
// C checkers
// ARR
@@ -308,7 +312,8 @@ public:
CheckFactories.registerCheck<bugprone::SuspiciousMemoryComparisonCheck>(
"cert-exp42-c");
// FLP
- CheckFactories.registerCheck<FloatLoopCounter>("cert-flp30-c");
+ CheckFactories.registerCheck<bugprone::FloatLoopCounterCheck>(
+ "cert-flp30-c");
CheckFactories.registerCheck<bugprone::SuspiciousMemoryComparisonCheck>(
"cert-flp37-c");
// FIO
@@ -319,8 +324,8 @@ public:
// MSC
CheckFactories.registerCheck<bugprone::UnsafeFunctionsCheck>(
"cert-msc24-c");
- CheckFactories.registerCheck<LimitedRandomnessCheck>("cert-msc30-c");
- CheckFactories.registerCheck<ProperlySeededRandomGeneratorCheck>(
+ CheckFactories.registerCheck<misc::PredictableRandCheck>("cert-msc30-c");
+ CheckFactories.registerCheck<bugprone::RandomGeneratorSeedCheck>(
"cert-msc32-c");
CheckFactories.registerCheck<bugprone::UnsafeFunctionsCheck>(
"cert-msc33-c");
diff --git a/clang-tools-extra/clang-tidy/cert/CMakeLists.txt b/clang-tools-extra/clang-tidy/cert/CMakeLists.txt
index 453d1d3..3137903 100644
--- a/clang-tools-extra/clang-tidy/cert/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/cert/CMakeLists.txt
@@ -5,14 +5,6 @@ set(LLVM_LINK_COMPONENTS
add_clang_library(clangTidyCERTModule STATIC
CERTTidyModule.cpp
- DefaultOperatorNewAlignmentCheck.cpp
- DontModifyStdNamespaceCheck.cpp
- FloatLoopCounter.cpp
- LimitedRandomnessCheck.cpp
- MutatingCopyCheck.cpp
- NonTrivialTypesLibcMemoryCallsCheck.cpp
- ProperlySeededRandomGeneratorCheck.cpp
- ThrownExceptionTypeCheck.cpp
LINK_LIBS
clangTidy
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt b/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
index 0abb000..4b3330d 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
@@ -21,7 +21,7 @@ add_clang_library(clangTidyCppCoreGuidelinesModule STATIC
OwningMemoryCheck.cpp
PreferMemberInitializerCheck.cpp
ProBoundsArrayToPointerDecayCheck.cpp
- ProBoundsAvoidUncheckedContainerAccess.cpp
+ ProBoundsAvoidUncheckedContainerAccessCheck.cpp
ProBoundsConstantArrayIndexCheck.cpp
ProBoundsPointerArithmeticCheck.cpp
ProTypeConstCastCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
index 5f4c9b4..6663955 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
@@ -36,7 +36,7 @@
#include "OwningMemoryCheck.h"
#include "PreferMemberInitializerCheck.h"
#include "ProBoundsArrayToPointerDecayCheck.h"
-#include "ProBoundsAvoidUncheckedContainerAccess.h"
+#include "ProBoundsAvoidUncheckedContainerAccessCheck.h"
#include "ProBoundsConstantArrayIndexCheck.h"
#include "ProBoundsPointerArithmeticCheck.h"
#include "ProTypeConstCastCheck.h"
@@ -108,7 +108,7 @@ public:
"cppcoreguidelines-prefer-member-initializer");
CheckFactories.registerCheck<ProBoundsArrayToPointerDecayCheck>(
"cppcoreguidelines-pro-bounds-array-to-pointer-decay");
- CheckFactories.registerCheck<ProBoundsAvoidUncheckedContainerAccess>(
+ CheckFactories.registerCheck<ProBoundsAvoidUncheckedContainerAccessCheck>(
"cppcoreguidelines-pro-bounds-avoid-unchecked-container-access");
CheckFactories.registerCheck<ProBoundsConstantArrayIndexCheck>(
"cppcoreguidelines-pro-bounds-constant-array-index");
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
index 2545548..93b5b96 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
@@ -37,7 +37,7 @@ void InitVariablesCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
}
void InitVariablesCheck::registerMatchers(MatchFinder *Finder) {
- std::string BadDecl = "badDecl";
+ const std::string BadDecl = "badDecl";
Finder->addMatcher(
varDecl(unless(hasInitializer(anything())), unless(isInstantiated()),
isLocalVarDecl(), unless(isStaticLocal()), isDefinition(),
@@ -82,7 +82,7 @@ void InitVariablesCheck::check(const MatchFinder::MatchResult &Result) {
if (MatchedDecl->getEndLoc().isMacroID())
return;
- QualType TypePtr = MatchedDecl->getType();
+ const QualType TypePtr = MatchedDecl->getType();
std::optional<const char *> InitializationString;
bool AddMathInclude = false;
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/InterfacesGlobalInitCheck.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/InterfacesGlobalInitCheck.h
index 780b4b3..dc91854 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/InterfacesGlobalInitCheck.h
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/InterfacesGlobalInitCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_INTERFACES_GLOBAL_INIT_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_INTERFACES_GLOBAL_INIT_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_INTERFACESGLOBALINITCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_INTERFACESGLOBALINITCHECK_H
#include "../ClangTidyCheck.h"
@@ -27,4 +27,4 @@ public:
} // namespace clang::tidy::cppcoreguidelines
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_INTERFACES_GLOBAL_INIT_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_INTERFACESGLOBALINITCHECK_H
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
index 0836a5c..b301a2b 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
@@ -47,7 +47,7 @@ public:
SM.isWrittenInCommandLineFile(MD->getLocation()))
return;
- StringRef MacroName = MacroNameTok.getIdentifierInfo()->getName();
+ const StringRef MacroName = MacroNameTok.getIdentifierInfo()->getName();
if (MacroName == "__GCC_HAVE_DWARF2_CFI_ASM")
return;
if (!CheckCapsOnly && !RegExp.match(MacroName))
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.cpp
index 57d98ee..366bd12 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.cpp
@@ -81,7 +81,7 @@ void MisleadingCaptureDefaultByValueCheck::check(
return;
if (Lambda->getCaptureDefault() == LCD_ByCopy) {
- bool IsThisImplicitlyCaptured = std::any_of(
+ const bool IsThisImplicitlyCaptured = std::any_of(
Lambda->implicit_capture_begin(), Lambda->implicit_capture_end(),
[](const LambdaCapture &Capture) { return Capture.capturesThis(); });
auto Diag = diag(Lambda->getCaptureDefaultLoc(),
@@ -89,8 +89,8 @@ void MisleadingCaptureDefaultByValueCheck::check(
"should not specify a by-value capture default")
<< IsThisImplicitlyCaptured;
- std::string ReplacementText = createReplacementText(Lambda);
- SourceLocation DefaultCaptureEnd =
+ const std::string ReplacementText = createReplacementText(Lambda);
+ const SourceLocation DefaultCaptureEnd =
findDefaultCaptureEnd(Lambda, *Result.Context);
Diag << FixItHint::CreateReplacement(
CharSourceRange::getCharRange(Lambda->getCaptureDefaultLoc(),
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
index 090ab2f..d1d81d5 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
@@ -26,11 +26,12 @@ AST_MATCHER_P(QualType, possiblyPackExpansionOf,
}
AST_MATCHER(ParmVarDecl, isTemplateTypeParameter) {
- ast_matchers::internal::Matcher<QualType> Inner = possiblyPackExpansionOf(
- qualType(rValueReferenceType(),
- references(templateTypeParmType(
- hasDeclaration(templateTypeParmDecl()))),
- unless(references(qualType(isConstQualified())))));
+ const ast_matchers::internal::Matcher<QualType> Inner =
+ possiblyPackExpansionOf(
+ qualType(rValueReferenceType(),
+ references(templateTypeParmType(
+ hasDeclaration(templateTypeParmDecl()))),
+ unless(references(qualType(isConstQualified())))));
if (!Inner.matches(Node.getType(), Finder, Builder))
return false;
@@ -43,7 +44,7 @@ AST_MATCHER(ParmVarDecl, isTemplateTypeParameter) {
if (!FuncTemplate)
return false;
- QualType ParamType =
+ const QualType ParamType =
Node.getType().getNonPackExpansionType()->getPointeeType();
const auto *TemplateType = ParamType->getAsCanonical<TemplateTypeParmType>();
if (!TemplateType)
@@ -54,10 +55,10 @@ AST_MATCHER(ParmVarDecl, isTemplateTypeParameter) {
}
AST_MATCHER_P(NamedDecl, hasSameNameAsBoundNode, std::string, BindingID) {
- IdentifierInfo *II = Node.getIdentifier();
+ const IdentifierInfo *II = Node.getIdentifier();
if (nullptr == II)
return false;
- StringRef Name = II->getName();
+ const StringRef Name = II->getName();
return Builder->removeBindings(
[this, Name](const ast_matchers::internal::BoundNodesMap &Nodes) {
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/NoMallocCheck.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/NoMallocCheck.h
index e4dece6..da35b53 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/NoMallocCheck.h
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/NoMallocCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_NO_MALLOC_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_NO_MALLOC_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_NOMALLOCCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_NOMALLOCCHECK_H
#include "../ClangTidyCheck.h"
@@ -56,4 +56,4 @@ private:
} // namespace clang::tidy::cppcoreguidelines
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_NO_MALLOC_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_NOMALLOCCHECK_H
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/NoSuspendWithLockCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/NoSuspendWithLockCheck.cpp
index 43df277..8ecbccd 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/NoSuspendWithLockCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/NoSuspendWithLockCheck.cpp
@@ -27,7 +27,7 @@ void NoSuspendWithLockCheck::registerMatchers(MatchFinder *Finder) {
hasDeclaration(namedDecl(matchers::matchesAnyListedName(
utils::options::parseStringList(LockGuards)))));
- StatementMatcher Lock =
+ const StatementMatcher Lock =
declStmt(has(varDecl(hasType(LockType)).bind("lock-decl")))
.bind("lock-decl-stmt");
Finder->addMatcher(
@@ -55,12 +55,12 @@ void NoSuspendWithLockCheck::check(const MatchFinder::MatchResult &Result) {
Options.AddImplicitDtors = true;
Options.AddTemporaryDtors = true;
- std::unique_ptr<CFG> TheCFG = CFG::buildCFG(
+ const std::unique_ptr<CFG> TheCFG = CFG::buildCFG(
nullptr, const_cast<clang::CompoundStmt *>(Block), &Context, Options);
if (!TheCFG)
return;
- utils::ExprSequence Sequence(TheCFG.get(), Block, &Context);
+ const utils::ExprSequence Sequence(TheCFG.get(), Block, &Context);
const Stmt *LastBlockStmt = Block->body_back();
if (Sequence.inSequence(LockStmt, Suspend) &&
(Suspend == LastBlockStmt ||
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.h
index 462e986..248b5c2 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.h
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNING_MEMORY_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNING_MEMORY_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNINGMEMORYCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNINGMEMORYCHECK_H
#include "../ClangTidyCheck.h"
@@ -61,4 +61,4 @@ private:
} // namespace clang::tidy::cppcoreguidelines
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNING_MEMORY_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNINGMEMORYCHECK_H
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
index 9913671..51a1468 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -164,12 +164,12 @@ void PreferMemberInitializerCheck::check(
llvm::DenseMap<const FieldDecl *, AssignedLevel> AssignedFields{};
for (const CXXCtorInitializer *Init : Ctor->inits())
- if (FieldDecl *Field = Init->getMember())
+ if (const FieldDecl *Field = Init->getMember())
updateAssignmentLevel(Field, Init->getInit(), Ctor, AssignedFields);
for (const Stmt *S : Body->body()) {
if (S->getBeginLoc().isMacroID()) {
- StringRef MacroName = Lexer::getImmediateMacroName(
+ const StringRef MacroName = Lexer::getImmediateMacroName(
S->getBeginLoc(), *Result.SourceManager, getLangOpts());
if (MacroName.contains_insensitive("assert"))
return;
@@ -206,7 +206,7 @@ void PreferMemberInitializerCheck::check(
bool AddComma = false;
bool AddBrace = false;
bool InvalidFix = false;
- unsigned Index = Field->getFieldIndex();
+ const unsigned Index = Field->getFieldIndex();
const CXXCtorInitializer *LastInListInit = nullptr;
for (const CXXCtorInitializer *Init : Ctor->inits()) {
if (!Init->isWritten() || Init->isInClassMemberInitializer())
@@ -276,7 +276,7 @@ void PreferMemberInitializerCheck::check(
<< Field;
if (InvalidFix)
continue;
- StringRef NewInit = Lexer::getSourceText(
+ const StringRef NewInit = Lexer::getSourceText(
Result.SourceManager->getExpansionRange(InitValue->getSourceRange()),
*Result.SourceManager, getLangOpts());
if (HasInitAlready) {
@@ -288,8 +288,8 @@ void PreferMemberInitializerCheck::check(
else
Diag << FixItHint::CreateReplacement(ReplaceRange, NewInit);
} else {
- SmallString<128> Insertion({InsertPrefix, Field->getName(), "(", NewInit,
- AddComma ? "), " : ")"});
+ const SmallString<128> Insertion({InsertPrefix, Field->getName(), "(",
+ NewInit, AddComma ? "), " : ")"});
Diag << FixItHint::CreateInsertion(InsertPos, Insertion,
FirstToCtorInits);
FirstToCtorInits = areDiagsSelfContained();
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
index f3237f4..1c5c854 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
@@ -19,10 +19,11 @@ namespace clang::tidy::cppcoreguidelines {
namespace {
AST_MATCHER_P(CXXForRangeStmt, hasRangeBeginEndStmt,
ast_matchers::internal::Matcher<DeclStmt>, InnerMatcher) {
- for (const DeclStmt *Stmt : {Node.getBeginStmt(), Node.getEndStmt()})
- if (Stmt != nullptr && InnerMatcher.matches(*Stmt, Finder, Builder))
- return true;
- return false;
+ return llvm::any_of(llvm::ArrayRef{Node.getBeginStmt(), Node.getEndStmt()},
+ [&](const DeclStmt *Stmt) {
+ return Stmt &&
+ InnerMatcher.matches(*Stmt, Finder, Builder);
+ });
}
AST_MATCHER(Stmt, isInsideOfRangeBeginEndStmt) {
@@ -35,7 +36,7 @@ AST_MATCHER_P(Expr, hasParentIgnoringImpCasts,
ast_matchers::internal::Matcher<Expr>, InnerMatcher) {
const Expr *E = &Node;
do {
- DynTypedNodeList Parents = Finder->getASTContext().getParents(*E);
+ const DynTypedNodeList Parents = Finder->getASTContext().getParents(*E);
if (Parents.size() != 1)
return false;
E = Parents[0].get<Expr>();
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.h
index cea4bfa..2d4b40b 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.h
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_BOUNDS_ARRAY_TO_POINTER_DECAY_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_BOUNDS_ARRAY_TO_POINTER_DECAY_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROBOUNDSARRAYTOPOINTERDECAYCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROBOUNDSARRAYTOPOINTERDECAYCHECK_H
#include "../ClangTidyCheck.h"
@@ -30,4 +30,4 @@ public:
} // namespace clang::tidy::cppcoreguidelines
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_BOUNDS_ARRAY_TO_POINTER_DECAY_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROBOUNDSARRAYTOPOINTERDECAYCHECK_H
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccess.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccessCheck.cpp
index dd7b2b5..cf4b445 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccess.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccessCheck.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "ProBoundsAvoidUncheckedContainerAccess.h"
+#include "ProBoundsAvoidUncheckedContainerAccessCheck.h"
#include "../utils/Matchers.h"
#include "../utils/OptionsUtils.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -19,8 +19,9 @@ namespace clang::tidy::cppcoreguidelines {
static constexpr llvm::StringRef DefaultExclusionStr =
"::std::map;::std::unordered_map;::std::flat_map";
-ProBoundsAvoidUncheckedContainerAccess::ProBoundsAvoidUncheckedContainerAccess(
- StringRef Name, ClangTidyContext *Context)
+ProBoundsAvoidUncheckedContainerAccessCheck::
+ ProBoundsAvoidUncheckedContainerAccessCheck(StringRef Name,
+ ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
ExcludedClasses(utils::options::parseStringList(
Options.get("ExcludeClasses", DefaultExclusionStr))),
@@ -28,7 +29,7 @@ ProBoundsAvoidUncheckedContainerAccess::ProBoundsAvoidUncheckedContainerAccess(
FixFunction(Options.get("FixFunction", "gsl::at")),
FixFunctionEmptyArgs(Options.get("FixFunctionEmptyArgs", FixFunction)) {}
-void ProBoundsAvoidUncheckedContainerAccess::storeOptions(
+void ProBoundsAvoidUncheckedContainerAccessCheck::storeOptions(
ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "ExcludeClasses",
utils::options::serializeStringList(ExcludedClasses));
@@ -86,7 +87,7 @@ findAlternativeAt(const CXXMethodDecl *MatchedOperator) {
return nullptr;
}
-void ProBoundsAvoidUncheckedContainerAccess::registerMatchers(
+void ProBoundsAvoidUncheckedContainerAccessCheck::registerMatchers(
MatchFinder *Finder) {
Finder->addMatcher(
mapAnyOf(cxxOperatorCallExpr, cxxMemberCallExpr)
@@ -100,9 +101,8 @@ void ProBoundsAvoidUncheckedContainerAccess::registerMatchers(
this);
}
-void ProBoundsAvoidUncheckedContainerAccess::check(
+void ProBoundsAvoidUncheckedContainerAccessCheck::check(
const MatchFinder::MatchResult &Result) {
-
const auto *MatchedExpr = Result.Nodes.getNodeAs<CallExpr>("caller");
if (FixMode == None) {
@@ -176,7 +176,7 @@ void ProBoundsAvoidUncheckedContainerAccess::check(
}
} else if (const auto *MCE = dyn_cast<CXXMemberCallExpr>(MatchedExpr)) {
// Case: a.operator[](i) or a->operator[](i)
- const auto *Callee = dyn_cast<MemberExpr>(MCE->getCallee());
+ const auto *Callee = cast<MemberExpr>(MCE->getCallee());
if (FixMode == At) {
// Cases: a.operator[](i) => a.at(i) and a->operator[](i) => a->at(i)
@@ -251,7 +251,7 @@ void ProBoundsAvoidUncheckedContainerAccess::check(
} // namespace clang::tidy::cppcoreguidelines
namespace clang::tidy {
-using P = cppcoreguidelines::ProBoundsAvoidUncheckedContainerAccess;
+using P = cppcoreguidelines::ProBoundsAvoidUncheckedContainerAccessCheck;
llvm::ArrayRef<std::pair<P::FixModes, StringRef>>
OptionEnumMapping<P::FixModes>::getEnumMapping() {
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccess.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccessCheck.h
index 0755da7..85b5a93 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccess.h
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccessCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_BOUNDS_AVOID_UNCHECKED_CONTAINER_ACCESS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_BOUNDS_AVOID_UNCHECKED_CONTAINER_ACCESS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROBOUNDSAVOIDUNCHECKEDCONTAINERACCESSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROBOUNDSAVOIDUNCHECKEDCONTAINERACCESSCHECK_H
#include "../ClangTidyCheck.h"
@@ -20,10 +20,10 @@ namespace clang::tidy::cppcoreguidelines {
/// https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#slcon3-avoid-bounds-errors
/// For the user-facing documentation see:
/// https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/pro-bounds-avoid-unchecked-container-access.html
-class ProBoundsAvoidUncheckedContainerAccess : public ClangTidyCheck {
+class ProBoundsAvoidUncheckedContainerAccessCheck : public ClangTidyCheck {
public:
- ProBoundsAvoidUncheckedContainerAccess(StringRef Name,
- ClangTidyContext *Context);
+ ProBoundsAvoidUncheckedContainerAccessCheck(StringRef Name,
+ ClangTidyContext *Context);
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
@@ -46,11 +46,11 @@ private:
namespace clang::tidy {
template <>
struct OptionEnumMapping<
- cppcoreguidelines::ProBoundsAvoidUncheckedContainerAccess::FixModes> {
+ cppcoreguidelines::ProBoundsAvoidUncheckedContainerAccessCheck::FixModes> {
static ArrayRef<std::pair<
- cppcoreguidelines::ProBoundsAvoidUncheckedContainerAccess::FixModes,
+ cppcoreguidelines::ProBoundsAvoidUncheckedContainerAccessCheck::FixModes,
StringRef>>
getEnumMapping();
};
} // namespace clang::tidy
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_BOUNDS_AVOID_UNCHECKED_CONTAINER_ACCESS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROBOUNDSAVOIDUNCHECKEDCONTAINERACCESSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
index 634ec18..82fc9f2 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
@@ -78,7 +78,7 @@ void ProBoundsConstantArrayIndexCheck::check(
else
BaseRange =
cast<CXXOperatorCallExpr>(Matched)->getArg(0)->getSourceRange();
- SourceRange IndexRange = IndexExpr->getSourceRange();
+ const SourceRange IndexRange = IndexExpr->getSourceRange();
auto Diag = diag(Matched->getExprLoc(),
"do not use array subscript when the index is "
@@ -115,7 +115,7 @@ void ProBoundsConstantArrayIndexCheck::check(
const auto &SizeArg = TemplateArgs[1];
if (SizeArg.getKind() != TemplateArgument::Integral)
return;
- llvm::APInt ArraySize = SizeArg.getAsIntegral();
+ const llvm::APInt ArraySize = SizeArg.getAsIntegral();
// Get uint64_t values, because different bitwidths would lead to an assertion
// in APInt::uge.
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.h
index 73f1855..7c8fec0 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.h
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_BOUNDS_CONSTANT_ARRAY_INDEX_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_BOUNDS_CONSTANT_ARRAY_INDEX_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROBOUNDSCONSTANTARRAYINDEXCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROBOUNDSCONSTANTARRAYINDEXCHECK_H
#include "../ClangTidyCheck.h"
#include "../utils/IncludeInserter.h"
@@ -37,4 +37,4 @@ public:
} // namespace clang::tidy::cppcoreguidelines
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_BOUNDS_CONSTANT_ARRAY_INDEX_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROBOUNDSCONSTANTARRAYINDEXCHECK_H
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.h
index 45b7985..4f6b17f 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.h
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_BOUNDS_POINTER_ARITHMETIC_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_BOUNDS_POINTER_ARITHMETIC_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROBOUNDSPOINTERARITHMETICCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROBOUNDSPOINTERARITHMETICCHECK_H
#include "../ClangTidyCheck.h"
@@ -35,4 +35,4 @@ private:
} // namespace clang::tidy::cppcoreguidelines
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_BOUNDS_POINTER_ARITHMETIC_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROBOUNDSPOINTERARITHMETICCHECK_H
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.h
index 0b8cfc8..a0a368c 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.h
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_CONST_CAST_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_CONST_CAST_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROTYPECONSTCASTCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROTYPECONSTCASTCHECK_H
#include "../ClangTidyCheck.h"
@@ -36,4 +36,4 @@ private:
} // namespace clang::tidy::cppcoreguidelines
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_CONST_CAST_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROTYPECONSTCASTCHECK_H
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp
index b9867c2..fcd9c6d 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp
@@ -45,7 +45,7 @@ void ProTypeCstyleCastCheck::check(const MatchFinder::MatchResult &Result) {
return;
}
- QualType SourceType = MatchedCast->getSubExpr()->getType();
+ const QualType SourceType = MatchedCast->getSubExpr()->getType();
if (MatchedCast->getCastKind() == CK_BaseToDerived) {
const auto *SourceDecl = SourceType->getPointeeCXXRecordDecl();
@@ -58,7 +58,7 @@ void ProTypeCstyleCastCheck::check(const MatchFinder::MatchResult &Result) {
// Leave type spelling exactly as it was (unlike
// getTypeAsWritten().getAsString() which would spell enum types 'enum
// X').
- StringRef DestTypeString = Lexer::getSourceText(
+ const StringRef DestTypeString = Lexer::getSourceText(
CharSourceRange::getTokenRange(
MatchedCast->getLParenLoc().getLocWithOffset(1),
MatchedCast->getRParenLoc().getLocWithOffset(-1)),
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.h
index f8e1d5a..5fd0208 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.h
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_CSTYLE_CAST_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_CSTYLE_CAST_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROTYPECSTYLECASTCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROTYPECSTYLECASTCHECK_H
#include "../ClangTidyCheck.h"
@@ -31,4 +31,4 @@ public:
} // namespace clang::tidy::cppcoreguidelines
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_CSTYLE_CAST_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROTYPECSTYLECASTCHECK_H
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
index 1ac9b8b..f267646 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -173,7 +173,7 @@ struct InitializerInsertion {
assert(!Initializers.empty() && "No initializers to insert");
std::string Code;
llvm::raw_string_ostream Stream(Code);
- std::string Joined =
+ const std::string Joined =
llvm::join(Initializers.begin(), Initializers.end(), "(), ");
switch (Placement) {
case InitializerPlacement::New:
@@ -361,7 +361,8 @@ void ProTypeMemberInitCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
}
// FIXME: Copied from clang/lib/Sema/SemaDeclCXX.cpp.
-static bool isIncompleteOrZeroLengthArrayType(ASTContext &Context, QualType T) {
+static bool isIncompleteOrZeroLengthArrayType(const ASTContext &Context,
+ QualType T) {
if (T->isIncompleteArrayType())
return true;
@@ -375,7 +376,7 @@ static bool isIncompleteOrZeroLengthArrayType(ASTContext &Context, QualType T) {
return false;
}
-static bool isEmpty(ASTContext &Context, const QualType &Type) {
+static bool isEmpty(const ASTContext &Context, const QualType &Type) {
if (const CXXRecordDecl *ClassDecl = Type->getAsCXXRecordDecl()) {
return ClassDecl->isEmpty();
}
@@ -431,19 +432,13 @@ static llvm::StringLiteral getInitializer(QualType QT, bool UseAssignment) {
}
}
-void ProTypeMemberInitCheck::checkMissingMemberInitializer(
- ASTContext &Context, const CXXRecordDecl &ClassDecl,
- const CXXConstructorDecl *Ctor) {
- bool IsUnion = ClassDecl.isUnion();
-
- if (IsUnion && ClassDecl.hasInClassInitializer())
- return;
-
- // Gather all fields (direct and indirect) that need to be initialized.
- SmallPtrSet<const FieldDecl *, 16> FieldsToInit;
+static void
+computeFieldsToInit(const ASTContext &Context, const RecordDecl &Record,
+ bool IgnoreArrays,
+ SmallPtrSetImpl<const FieldDecl *> &FieldsToInit) {
bool AnyMemberHasInitPerUnion = false;
forEachFieldWithFilter(
- ClassDecl, ClassDecl.fields(), AnyMemberHasInitPerUnion,
+ Record, Record.fields(), AnyMemberHasInitPerUnion,
[&](const FieldDecl *F) {
if (IgnoreArrays && F->getType()->isArrayType())
return;
@@ -458,6 +453,19 @@ void ProTypeMemberInitCheck::checkMissingMemberInitializer(
!AnyMemberHasInitPerUnion)
FieldsToInit.insert(F);
});
+}
+
+void ProTypeMemberInitCheck::checkMissingMemberInitializer(
+ ASTContext &Context, const CXXRecordDecl &ClassDecl,
+ const CXXConstructorDecl *Ctor) {
+ const bool IsUnion = ClassDecl.isUnion();
+
+ if (IsUnion && ClassDecl.hasInClassInitializer())
+ return;
+
+ // Gather all fields (direct and indirect) that need to be initialized.
+ SmallPtrSet<const FieldDecl *, 16> FieldsToInit;
+ computeFieldsToInit(Context, ClassDecl, IgnoreArrays, FieldsToInit);
if (FieldsToInit.empty())
return;
@@ -507,7 +515,7 @@ void ProTypeMemberInitCheck::checkMissingMemberInitializer(
// Collect all fields but only suggest a fix for the first member of unions,
// as initializing more than one union member is an error.
SmallPtrSet<const FieldDecl *, 16> FieldsToFix;
- AnyMemberHasInitPerUnion = false;
+ bool AnyMemberHasInitPerUnion = false;
forEachFieldWithFilter(ClassDecl, ClassDecl.fields(),
AnyMemberHasInitPerUnion, [&](const FieldDecl *F) {
if (!FieldsToInit.contains(F))
@@ -541,7 +549,6 @@ void ProTypeMemberInitCheck::checkMissingMemberInitializer(
void ProTypeMemberInitCheck::checkMissingBaseClassInitializer(
const ASTContext &Context, const CXXRecordDecl &ClassDecl,
const CXXConstructorDecl *Ctor) {
-
// Gather any base classes that need to be initialized.
SmallVector<const RecordDecl *, 4> AllBases;
SmallPtrSet<const RecordDecl *, 4> BasesToInit;
@@ -583,7 +590,18 @@ void ProTypeMemberInitCheck::checkMissingBaseClassInitializer(
void ProTypeMemberInitCheck::checkUninitializedTrivialType(
const ASTContext &Context, const VarDecl *Var) {
- DiagnosticBuilder Diag =
+ // Verify that the record actually needs initialization
+ const CXXRecordDecl *Record = Var->getType()->getAsCXXRecordDecl();
+ if (!Record)
+ return;
+
+ SmallPtrSet<const FieldDecl *, 16> FieldsToInit;
+ computeFieldsToInit(Context, *Record, IgnoreArrays, FieldsToInit);
+
+ if (FieldsToInit.empty())
+ return;
+
+ const DiagnosticBuilder Diag =
diag(Var->getBeginLoc(), "uninitialized record type: %0") << Var;
Diag << FixItHint::CreateInsertion(
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
index 8beaab3..89d3074 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_MEMBER_INIT_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_MEMBER_INIT_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROTYPEMEMBERINITCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROTYPEMEMBERINITCHECK_H
#include "../ClangTidyCheck.h"
#include "llvm/ADT/DenseSet.h"
@@ -79,4 +79,4 @@ private:
} // namespace clang::tidy::cppcoreguidelines
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_MEMBER_INIT_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROTYPEMEMBERINITCHECK_H
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeReinterpretCastCheck.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeReinterpretCastCheck.h
index 4948d0a..566944d 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeReinterpretCastCheck.h
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeReinterpretCastCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_REINTERPRETCAST_CHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_REINTERPRETCAST_CHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROTYPEREINTERPRETCASTCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROTYPEREINTERPRETCASTCHECK_H
#include "../ClangTidyCheck.h"
@@ -30,4 +30,4 @@ public:
} // namespace clang::tidy::cppcoreguidelines
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_REINTERPRETCAST_CHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROTYPEREINTERPRETCASTCHECK_H
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeStaticCastDowncastCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeStaticCastDowncastCheck.cpp
index c200a79..e7b92fc 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeStaticCastDowncastCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeStaticCastDowncastCheck.cpp
@@ -33,7 +33,7 @@ void ProTypeStaticCastDowncastCheck::check(
const MatchFinder::MatchResult &Result) {
const auto *MatchedCast = Result.Nodes.getNodeAs<CXXStaticCastExpr>("cast");
- QualType SourceType = MatchedCast->getSubExpr()->getType();
+ const QualType SourceType = MatchedCast->getSubExpr()->getType();
const auto *SourceDecl = SourceType->getPointeeCXXRecordDecl();
if (!SourceDecl) // The cast is from object to reference
SourceDecl = SourceType->getAsCXXRecordDecl();
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeStaticCastDowncastCheck.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeStaticCastDowncastCheck.h
index 3d01fb9..02d54a5 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeStaticCastDowncastCheck.h
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeStaticCastDowncastCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_STATIC_CAST_DOWNCAST_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_STATIC_CAST_DOWNCAST_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROTYPESTATICCASTDOWNCASTCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROTYPESTATICCASTDOWNCASTCHECK_H
#include "../ClangTidyCheck.h"
@@ -37,4 +37,4 @@ private:
} // namespace clang::tidy::cppcoreguidelines
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_STATIC_CAST_DOWNCAST_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROTYPESTATICCASTDOWNCASTCHECK_H
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.h
index fe82ce96..41154e8 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.h
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeUnionAccessCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_UNION_ACCESS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_UNION_ACCESS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROTYPEUNIONACCESSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROTYPEUNIONACCESSCHECK_H
#include "../ClangTidyCheck.h"
@@ -31,4 +31,4 @@ public:
} // namespace clang::tidy::cppcoreguidelines
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_UNION_ACCESS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROTYPEUNIONACCESSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
index 431b2a7..c223ed1 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
@@ -65,9 +65,9 @@ static constexpr StringRef VaArgWarningMessage =
namespace {
AST_MATCHER(QualType, isVAList) {
- ASTContext &Context = Finder->getASTContext();
- QualType Desugar = Node.getDesugaredType(Context);
- QualType NodeTy = Node.getUnqualifiedType();
+ const ASTContext &Context = Finder->getASTContext();
+ const QualType Desugar = Node.getDesugaredType(Context);
+ const QualType NodeTy = Node.getUnqualifiedType();
auto CheckVaList = [](QualType NodeTy, QualType Expected,
const ASTContext &Context) {
@@ -88,7 +88,8 @@ AST_MATCHER(QualType, isVAList) {
// type. Some targets implements va_list as 'char *' or 'void *'.
// In these cases we need to remove all typedefs one by one to check this.
using BuiltinVaListKind = TargetInfo::BuiltinVaListKind;
- BuiltinVaListKind VaListKind = Context.getTargetInfo().getBuiltinVaListKind();
+ const BuiltinVaListKind VaListKind =
+ Context.getTargetInfo().getBuiltinVaListKind();
if (VaListKind == BuiltinVaListKind::CharPtrBuiltinVaList ||
VaListKind == BuiltinVaListKind::VoidPtrBuiltinVaList) {
if (CheckVaList(NodeTy, Context.getBuiltinVaListType(), Context))
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.h
index b28d365..5be6163 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.h
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_VARARG_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_VARARG_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROTYPEVARARGCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROTYPEVARARGCHECK_H
#include "../ClangTidyCheck.h"
@@ -33,4 +33,4 @@ public:
} // namespace clang::tidy::cppcoreguidelines
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_VARARG_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PROTYPEVARARGCHECK_H
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
index c40ac7a..28bfe57 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
@@ -39,7 +39,7 @@ AST_MATCHER_P2(Stmt, argumentOf, bool, AllowPartialMove, StatementMatcher,
void RvalueReferenceParamNotMovedCheck::registerMatchers(MatchFinder *Finder) {
auto ToParam = hasAnyParameter(parmVarDecl(equalsBoundNode("param")));
- StatementMatcher MoveCallMatcher =
+ const StatementMatcher MoveCallMatcher =
callExpr(
argumentCountIs(1),
anyOf(callee(functionDecl(hasName(MoveFunction))),
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/SlicingCheck.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/SlicingCheck.h
index 61990e6..520a763 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/SlicingCheck.h
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/SlicingCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_SLICING_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_SLICING_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_SLICINGCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_SLICINGCHECK_H
#include "../ClangTidyCheck.h"
@@ -36,4 +36,4 @@ private:
} // namespace clang::tidy::cppcoreguidelines
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_SLICING_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_SLICINGCHECK_H
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
index b38a0c6..851392f 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
@@ -102,14 +102,13 @@ toString(SpecialMemberFunctionsCheck::SpecialMemberFunctionKind K) {
static std::string
join(ArrayRef<SpecialMemberFunctionsCheck::SpecialMemberFunctionKind> SMFS,
llvm::StringRef AndOr) {
-
assert(!SMFS.empty() &&
"List of defined or undefined members should never be empty.");
std::string Buffer;
llvm::raw_string_ostream Stream(Buffer);
Stream << toString(SMFS[0]);
- size_t LastIndex = SMFS.size() - 1;
+ const size_t LastIndex = SMFS.size() - 1;
for (size_t I = 1; I < LastIndex; ++I) {
Stream << ", " << toString(SMFS[I]);
}
@@ -146,7 +145,7 @@ void SpecialMemberFunctionsCheck::check(
StoreMember({DestructorType, Dtor->isDeleted()});
}
- std::initializer_list<std::pair<std::string, SpecialMemberFunctionKind>>
+ const std::initializer_list<std::pair<std::string, SpecialMemberFunctionKind>>
Matchers = {{"copy-ctor", SpecialMemberFunctionKind::CopyConstructor},
{"copy-assign", SpecialMemberFunctionKind::CopyAssignment},
{"move-ctor", SpecialMemberFunctionKind::MoveConstructor},
@@ -202,7 +201,7 @@ void SpecialMemberFunctionsCheck::checkForMissingMembers(
MissingMembers.push_back(Kind2);
};
- bool RequireThree =
+ const bool RequireThree =
HasMember(SpecialMemberFunctionKind::NonDefaultDestructor) ||
(!AllowSoleDefaultDtor &&
(HasMember(SpecialMemberFunctionKind::Destructor) ||
@@ -212,10 +211,11 @@ void SpecialMemberFunctionsCheck::checkForMissingMembers(
HasMember(SpecialMemberFunctionKind::MoveConstructor) ||
HasMember(SpecialMemberFunctionKind::MoveAssignment);
- bool RequireFive = (!AllowMissingMoveFunctions && RequireThree &&
- getLangOpts().CPlusPlus11) ||
- HasMember(SpecialMemberFunctionKind::MoveConstructor) ||
- HasMember(SpecialMemberFunctionKind::MoveAssignment);
+ const bool RequireFive =
+ (!AllowMissingMoveFunctions && RequireThree &&
+ getLangOpts().CPlusPlus11) ||
+ HasMember(SpecialMemberFunctionKind::MoveConstructor) ||
+ HasMember(SpecialMemberFunctionKind::MoveAssignment);
if (RequireThree) {
if (!HasMember(SpecialMemberFunctionKind::Destructor) &&
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
index 507aaa1..6d76e07 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_SPECIAL_MEMBER_FUNCTIONS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_SPECIAL_MEMBER_FUNCTIONS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_SPECIALMEMBERFUNCTIONSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_SPECIALMEMBERFUNCTIONSCHECK_H
#include "../ClangTidyCheck.h"
@@ -93,11 +93,11 @@ struct DenseMapInfo<
"TOMBSTONE"};
}
- static unsigned getHashValue(ClassDefId Val) {
+ static unsigned getHashValue(const ClassDefId &Val) {
assert(Val != getEmptyKey() && "Cannot hash the empty key!");
assert(Val != getTombstoneKey() && "Cannot hash the tombstone key!");
- std::hash<ClassDefId::second_type> SecondHash;
+ const std::hash<ClassDefId::second_type> SecondHash;
return Val.first.getHashValue() + SecondHash(Val.second);
}
@@ -112,4 +112,4 @@ struct DenseMapInfo<
} // namespace llvm
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_SPECIAL_MEMBER_FUNCTIONS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_SPECIALMEMBERFUNCTIONSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
index 7700889..bfa9ce3 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
@@ -56,10 +56,10 @@ getVirtualKeywordRange(const CXXDestructorDecl &Destructor,
if (Destructor.getLocation().isMacroID())
return std::nullopt;
- SourceLocation VirtualBeginLoc = Destructor.getBeginLoc();
- SourceLocation VirtualBeginSpellingLoc =
+ const SourceLocation VirtualBeginLoc = Destructor.getBeginLoc();
+ const SourceLocation VirtualBeginSpellingLoc =
SM.getSpellingLoc(Destructor.getBeginLoc());
- SourceLocation VirtualEndLoc = VirtualBeginSpellingLoc.getLocWithOffset(
+ const SourceLocation VirtualEndLoc = VirtualBeginSpellingLoc.getLocWithOffset(
Lexer::MeasureTokenLength(VirtualBeginSpellingLoc, SM, LangOpts));
/// Range ends with \c StartOfNextToken so that any whitespace after \c
@@ -68,7 +68,7 @@ getVirtualKeywordRange(const CXXDestructorDecl &Destructor,
Lexer::findNextToken(VirtualEndLoc, SM, LangOpts);
if (!NextToken)
return std::nullopt;
- SourceLocation StartOfNextToken = NextToken->getLocation();
+ const SourceLocation StartOfNextToken = NextToken->getLocation();
return CharSourceRange::getCharRange(VirtualBeginLoc, StartOfNextToken);
}
@@ -79,7 +79,7 @@ getPublicASDecl(const CXXRecordDecl &StructOrClass) {
AS{StructOrClass.decls_begin()},
ASEnd{StructOrClass.decls_end()};
AS != ASEnd; ++AS) {
- AccessSpecDecl *ASDecl = *AS;
+ const AccessSpecDecl *ASDecl = *AS;
if (ASDecl->getAccess() == AccessSpecifier::AS_public)
return ASDecl;
}
@@ -125,7 +125,7 @@ static std::string getSourceText(const CXXDestructorDecl &Destructor) {
static std::string eraseKeyword(std::string &DestructorString,
const std::string &Keyword) {
- size_t KeywordIndex = DestructorString.find(Keyword);
+ const size_t KeywordIndex = DestructorString.find(Keyword);
if (KeywordIndex != std::string::npos)
DestructorString.erase(KeywordIndex, Keyword.length());
return DestructorString;
@@ -167,7 +167,6 @@ static FixItHint changePrivateDestructorVisibilityTo(
void VirtualClassDestructorCheck::check(
const MatchFinder::MatchResult &Result) {
-
const auto *MatchedClassOrStruct =
Result.Nodes.getNodeAs<CXXRecordDecl>("ProblematicClassOrStruct");
diff --git a/clang-tools-extra/clang-tidy/custom/QueryCheck.cpp b/clang-tools-extra/clang-tidy/custom/QueryCheck.cpp
index f83c138f..315ce58 100644
--- a/clang-tools-extra/clang-tidy/custom/QueryCheck.cpp
+++ b/clang-tools-extra/clang-tidy/custom/QueryCheck.cpp
@@ -33,7 +33,7 @@ parseQuery(const ClangTidyOptions::CustomCheckValue &V,
clang::query::QuerySession QS({});
llvm::StringRef QueryStringRef{V.Query};
while (!QueryStringRef.empty()) {
- query::QueryRef Q = query::QueryParser::parse(QueryStringRef, QS);
+ const query::QueryRef Q = query::QueryParser::parse(QueryStringRef, QS);
switch (Q->Kind) {
case query::QK_Match: {
const auto &MatchQuery = llvm::cast<query::MatchQuery>(*Q);
@@ -126,11 +126,11 @@ void QueryCheck::registerMatchers(MatchFinder *Finder) {
void QueryCheck::check(const MatchFinder::MatchResult &Result) {
auto Emit = [this](const DiagMaps &DiagMaps, const std::string &BindName,
const DynTypedNode &Node, DiagnosticIDs::Level Level) {
- DiagMaps::const_iterator DiagMapIt = DiagMaps.find(Level);
+ const DiagMaps::const_iterator DiagMapIt = DiagMaps.find(Level);
if (DiagMapIt == DiagMaps.end())
return;
const BindNameMapToDiagMessage &BindNameMap = DiagMapIt->second;
- BindNameMapToDiagMessage::const_iterator BindNameMapIt =
+ const BindNameMapToDiagMessage::const_iterator BindNameMapIt =
BindNameMap.find(BindName);
if (BindNameMapIt == BindNameMap.end())
return;
diff --git a/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.h b/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.h
index 51bb153..ee08b76 100644
--- a/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.h
+++ b/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULT_ARGUMENTS_CALLS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULT_ARGUMENTS_CALLS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULTARGUMENTSCALLSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULTARGUMENTSCALLSCHECK_H
#include "../ClangTidyCheck.h"
@@ -30,4 +30,4 @@ public:
} // namespace clang::tidy::fuchsia
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULT_ARGUMENTS_CALLS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULTARGUMENTSCALLSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.cpp b/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.cpp
index d80511e..b22aff1 100644
--- a/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.cpp
@@ -24,7 +24,7 @@ void DefaultArgumentsDeclarationsCheck::check(
if (!D)
return;
- SourceRange DefaultArgRange = D->getDefaultArgRange();
+ const SourceRange DefaultArgRange = D->getDefaultArgRange();
if (DefaultArgRange.getEnd() != D->getEndLoc())
return;
@@ -35,10 +35,10 @@ void DefaultArgumentsDeclarationsCheck::check(
return;
}
- SourceLocation StartLocation =
+ const SourceLocation StartLocation =
D->getName().empty() ? D->getBeginLoc() : D->getLocation();
- SourceRange RemovalRange(
+ const SourceRange RemovalRange(
Lexer::getLocForEndOfToken(StartLocation, 0, *Result.SourceManager,
Result.Context->getLangOpts()),
DefaultArgRange.getEnd());
diff --git a/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.h b/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.h
index 1b0e3dd..aa991f8 100644
--- a/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.h
+++ b/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULT_ARGUMENTS_DECLARATIONS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULT_ARGUMENTS_DECLARATIONS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULTARGUMENTSDECLARATIONSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULTARGUMENTSDECLARATIONSCHECK_H
#include "../ClangTidyCheck.h"
@@ -30,4 +30,4 @@ public:
} // namespace clang::tidy::fuchsia
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULT_ARGUMENTS_DECLARATIONS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULTARGUMENTSDECLARATIONSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp b/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
index 80de028..4a10cb4 100644
--- a/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
@@ -17,113 +17,61 @@ namespace clang::tidy::fuchsia {
namespace {
AST_MATCHER(CXXRecordDecl, hasBases) {
- if (Node.hasDefinition())
- return Node.getNumBases() > 0;
- return false;
+ return Node.hasDefinition() && Node.getNumBases() > 0;
}
} // namespace
-// Adds a node (by name) to the interface map, if it was not present in the map
-// previously.
-void MultipleInheritanceCheck::addNodeToInterfaceMap(const CXXRecordDecl *Node,
- bool IsInterface) {
- assert(Node->getIdentifier());
- StringRef Name = Node->getIdentifier()->getName();
- InterfaceMap.insert(std::make_pair(Name, IsInterface));
-}
-
-// Returns "true" if the boolean "isInterface" has been set to the
-// interface status of the current Node. Return "false" if the
-// interface status for the current node is not yet known.
-bool MultipleInheritanceCheck::getInterfaceStatus(const CXXRecordDecl *Node,
- bool &IsInterface) const {
- assert(Node->getIdentifier());
- StringRef Name = Node->getIdentifier()->getName();
- auto Pair = InterfaceMap.find(Name);
- if (Pair == InterfaceMap.end())
- return false;
- IsInterface = Pair->second;
- return true;
-}
-
-bool MultipleInheritanceCheck::isCurrentClassInterface(
- const CXXRecordDecl *Node) const {
- // Interfaces should have no fields.
- if (!Node->field_empty())
- return false;
-
- // Interfaces should have exclusively pure methods.
- return llvm::none_of(Node->methods(), [](const CXXMethodDecl *M) {
- return M->isUserProvided() && !M->isPureVirtual() && !M->isStatic();
- });
-}
+bool MultipleInheritanceCheck::isInterface(const CXXBaseSpecifier &Base) {
+ const CXXRecordDecl *const Node = Base.getType()->getAsCXXRecordDecl();
+ if (!Node)
+ return true;
-bool MultipleInheritanceCheck::isInterface(const CXXRecordDecl *Node) {
- if (!Node->getIdentifier())
- return false;
+ assert(Node->isCompleteDefinition());
// Short circuit the lookup if we have analyzed this record before.
- bool PreviousIsInterfaceResult = false;
- if (getInterfaceStatus(Node, PreviousIsInterfaceResult))
- return PreviousIsInterfaceResult;
-
- // To be an interface, all base classes must be interfaces as well.
- for (const auto &I : Node->bases()) {
- if (I.isVirtual())
- continue;
- const auto *Base = I.getType()->getAsCXXRecordDecl();
- if (!Base)
- continue;
- assert(Base->isCompleteDefinition());
- if (!isInterface(Base)) {
- addNodeToInterfaceMap(Node, false);
- return false;
- }
- }
-
- bool CurrentClassIsInterface = isCurrentClassInterface(Node);
- addNodeToInterfaceMap(Node, CurrentClassIsInterface);
+ if (const auto CachedValue = InterfaceMap.find(Node);
+ CachedValue != InterfaceMap.end())
+ return CachedValue->second;
+
+ // To be an interface, a class must have...
+ const bool CurrentClassIsInterface =
+ // ...no bases that aren't interfaces...
+ llvm::none_of(Node->bases(),
+ [&](const CXXBaseSpecifier &I) {
+ return !I.isVirtual() && !isInterface(I);
+ }) &&
+ // ...no fields, and...
+ Node->field_empty() &&
+ // ...no methods that aren't pure virtual.
+ llvm::none_of(Node->methods(), [](const CXXMethodDecl *M) {
+ return M->isUserProvided() && !M->isPureVirtual() && !M->isStatic();
+ });
+
+ InterfaceMap.try_emplace(Node, CurrentClassIsInterface);
return CurrentClassIsInterface;
}
void MultipleInheritanceCheck::registerMatchers(MatchFinder *Finder) {
- // Match declarations which have bases.
Finder->addMatcher(cxxRecordDecl(hasBases(), isDefinition()).bind("decl"),
this);
}
void MultipleInheritanceCheck::check(const MatchFinder::MatchResult &Result) {
- if (const auto *D = Result.Nodes.getNodeAs<CXXRecordDecl>("decl")) {
- // Check against map to see if the class inherits from multiple
- // concrete classes
- unsigned NumConcrete = 0;
- for (const auto &I : D->bases()) {
- if (I.isVirtual())
- continue;
- const auto *Base = I.getType()->getAsCXXRecordDecl();
- if (!Base)
- continue;
- assert(Base->isCompleteDefinition());
- if (!isInterface(Base))
- NumConcrete++;
- }
-
- // Check virtual bases to see if there is more than one concrete
- // non-virtual base.
- for (const auto &V : D->vbases()) {
- const auto *Base = V.getType()->getAsCXXRecordDecl();
- if (!Base)
- continue;
- assert(Base->isCompleteDefinition());
- if (!isInterface(Base))
- NumConcrete++;
- }
-
- if (NumConcrete > 1) {
- diag(D->getBeginLoc(), "inheriting multiple classes that aren't "
- "pure virtual is discouraged");
- }
- }
+ const auto &D = *Result.Nodes.getNodeAs<CXXRecordDecl>("decl");
+ // Check to see if the class inherits from multiple concrete classes.
+ unsigned NumConcrete =
+ llvm::count_if(D.bases(), [&](const CXXBaseSpecifier &I) {
+ return !I.isVirtual() && !isInterface(I);
+ });
+
+ // Check virtual bases to see if there is more than one concrete
+ // non-virtual base.
+ NumConcrete += llvm::count_if(
+ D.vbases(), [&](const CXXBaseSpecifier &V) { return !isInterface(V); });
+
+ if (NumConcrete > 1)
+ diag(D.getBeginLoc(), "inheriting multiple classes that aren't "
+ "pure virtual is discouraged");
}
} // namespace clang::tidy::fuchsia
diff --git a/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.h b/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.h
index 66be182..4dcbd0c 100644
--- a/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.h
+++ b/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_MULTIPLE_INHERITANCE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_MULTIPLE_INHERITANCE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_MULTIPLEINHERITANCECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_MULTIPLEINHERITANCECHECK_H
#include "../ClangTidyCheck.h"
@@ -30,17 +30,14 @@ public:
void onEndOfTranslationUnit() override { InterfaceMap.clear(); }
private:
- void addNodeToInterfaceMap(const CXXRecordDecl *Node, bool IsInterface);
- bool getInterfaceStatus(const CXXRecordDecl *Node, bool &IsInterface) const;
- bool isCurrentClassInterface(const CXXRecordDecl *Node) const;
- bool isInterface(const CXXRecordDecl *Node);
+ bool isInterface(const CXXBaseSpecifier &Base);
// Contains the identity of each named CXXRecord as an interface. This is
// used to memoize lookup speeds and improve performance from O(N^2) to O(N),
// where N is the number of classes.
- llvm::StringMap<bool> InterfaceMap;
+ llvm::DenseMap<const CXXRecordDecl *, bool> InterfaceMap;
};
} // namespace clang::tidy::fuchsia
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_MULTIPLE_INHERITANCE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_MULTIPLEINHERITANCECHECK_H
diff --git a/clang-tools-extra/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp b/clang-tools-extra/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
index e202c288..4a498fb 100644
--- a/clang-tools-extra/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
+++ b/clang-tools-extra/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
@@ -34,7 +34,7 @@ void OverloadedOperatorCheck::check(const MatchFinder::MatchResult &Result) {
const auto *D = Result.Nodes.getNodeAs<FunctionDecl>("decl");
assert(D && "No FunctionDecl captured!");
- SourceLocation Loc = D->getBeginLoc();
+ const SourceLocation Loc = D->getBeginLoc();
if (Loc.isValid())
diag(Loc, "overloading %0 is disallowed") << D;
}
diff --git a/clang-tools-extra/clang-tidy/fuchsia/OverloadedOperatorCheck.h b/clang-tools-extra/clang-tidy/fuchsia/OverloadedOperatorCheck.h
index d91ecf8..4945ad2 100644
--- a/clang-tools-extra/clang-tidy/fuchsia/OverloadedOperatorCheck.h
+++ b/clang-tools-extra/clang-tidy/fuchsia/OverloadedOperatorCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_OVERLOADED_OPERATOR_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_OVERLOADED_OPERATOR_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_OVERLOADEDOPERATORCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_OVERLOADEDOPERATORCHECK_H
#include "../ClangTidyCheck.h"
@@ -30,4 +30,4 @@ public:
} // namespace clang::tidy::fuchsia
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_OVERLOADED_OPERATOR_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_OVERLOADEDOPERATORCHECK_H
diff --git a/clang-tools-extra/clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.h b/clang-tools-extra/clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.h
index 42d643e..d2403b0 100644
--- a/clang-tools-extra/clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.h
+++ b/clang-tools-extra/clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_STATICALLY_CONSTRUCTED_OBJECTS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_STATICALLY_CONSTRUCTED_OBJECTS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_STATICALLYCONSTRUCTEDOBJECTSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_STATICALLYCONSTRUCTEDOBJECTSCHECK_H
#include "../ClangTidyCheck.h"
@@ -32,4 +32,4 @@ public:
} // namespace clang::tidy::fuchsia
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_STATICALLY_CONSTRUCTED_OBJECTS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_STATICALLYCONSTRUCTEDOBJECTSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/fuchsia/TemporaryObjectsCheck.cpp b/clang-tools-extra/clang-tidy/fuchsia/TemporaryObjectsCheck.cpp
index 7b910b1..3acd5fb 100644
--- a/clang-tools-extra/clang-tidy/fuchsia/TemporaryObjectsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/fuchsia/TemporaryObjectsCheck.cpp
@@ -20,7 +20,7 @@ namespace clang::tidy::fuchsia {
namespace {
AST_MATCHER_P(CXXRecordDecl, matchesAnyName, ArrayRef<StringRef>, Names) {
- std::string QualifiedName = Node.getQualifiedNameAsString();
+ const std::string QualifiedName = Node.getQualifiedNameAsString();
return llvm::is_contained(Names, QualifiedName);
}
diff --git a/clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.h b/clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.h
index c644e87..ba1dbeb 100644
--- a/clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.h
+++ b/clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_TRAILING_RETURN_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_TRAILING_RETURN_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_TRAILINGRETURNCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_TRAILINGRETURNCHECK_H
#include "../ClangTidyCheck.h"
@@ -32,4 +32,4 @@ public:
} // namespace clang::tidy::fuchsia
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_TRAILING_RETURN_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_TRAILINGRETURNCHECK_H
diff --git a/clang-tools-extra/clang-tidy/fuchsia/VirtualInheritanceCheck.cpp b/clang-tools-extra/clang-tidy/fuchsia/VirtualInheritanceCheck.cpp
index b6fb22c..9c98b49 100644
--- a/clang-tools-extra/clang-tidy/fuchsia/VirtualInheritanceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/fuchsia/VirtualInheritanceCheck.cpp
@@ -20,10 +20,9 @@ AST_MATCHER(CXXRecordDecl, hasDirectVirtualBaseClass) {
return false;
if (!Node.getNumVBases())
return false;
- for (const CXXBaseSpecifier &Base : Node.bases())
- if (Base.isVirtual())
- return true;
- return false;
+ return llvm::any_of(Node.bases(), [](const CXXBaseSpecifier &Base) {
+ return Base.isVirtual();
+ });
}
} // namespace
diff --git a/clang-tools-extra/clang-tidy/fuchsia/VirtualInheritanceCheck.h b/clang-tools-extra/clang-tidy/fuchsia/VirtualInheritanceCheck.h
index 45c6019..e940602 100644
--- a/clang-tools-extra/clang-tidy/fuchsia/VirtualInheritanceCheck.h
+++ b/clang-tools-extra/clang-tidy/fuchsia/VirtualInheritanceCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_VIRTUAL_INHERITANCE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_VIRTUAL_INHERITANCE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_VIRTUALINHERITANCECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_VIRTUALINHERITANCECHECK_H
#include "../ClangTidyCheck.h"
@@ -30,4 +30,4 @@ public:
} // namespace clang::tidy::fuchsia
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_VIRTUAL_INHERITANCE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_VIRTUALINHERITANCECHECK_H
diff --git a/clang-tools-extra/clang-tidy/google/AvoidNSObjectNewCheck.cpp b/clang-tools-extra/clang-tidy/google/AvoidNSObjectNewCheck.cpp
index daf4948..5221e4b 100644
--- a/clang-tools-extra/clang-tidy/google/AvoidNSObjectNewCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/AvoidNSObjectNewCheck.cpp
@@ -22,11 +22,11 @@ using namespace clang::ast_matchers;
namespace clang::tidy::google::objc {
static bool isMessageExpressionInsideMacro(const ObjCMessageExpr *Expr) {
- SourceLocation ReceiverLocation = Expr->getReceiverRange().getBegin();
+ const SourceLocation ReceiverLocation = Expr->getReceiverRange().getBegin();
if (ReceiverLocation.isMacroID())
return true;
- SourceLocation SelectorLocation = Expr->getSelectorStartLoc();
+ const SourceLocation SelectorLocation = Expr->getSelectorStartLoc();
if (SelectorLocation.isMacroID())
return true;
@@ -58,7 +58,7 @@ static bool isInitMethodAvailable(const ObjCInterfaceDecl *ClassDecl) {
static StringRef getReceiverString(SourceRange ReceiverRange,
const SourceManager &SM,
const LangOptions &LangOpts) {
- CharSourceRange CharRange = Lexer::makeFileCharRange(
+ const CharSourceRange CharRange = Lexer::makeFileCharRange(
CharSourceRange::getTokenRange(ReceiverRange), SM, LangOpts);
return Lexer::getSourceText(CharRange, SM, LangOpts);
}
@@ -77,13 +77,13 @@ static FixItHint getCallFixItHint(const ObjCMessageExpr *Expr,
if (FoundClassFactory != ClassToFactoryMethodMap.end()) {
StringRef ClassName = FoundClassFactory->first;
StringRef FactorySelector = FoundClassFactory->second;
- std::string NewCall =
+ const std::string NewCall =
std::string(llvm::formatv("[{0} {1}]", ClassName, FactorySelector));
return FixItHint::CreateReplacement(Expr->getSourceRange(), NewCall);
}
if (isInitMethodAvailable(Expr->getReceiverInterface())) {
- std::string NewCall =
+ const std::string NewCall =
std::string(llvm::formatv("[[{0} alloc] init]", Receiver));
return FixItHint::CreateReplacement(Expr->getSourceRange(), NewCall);
}
diff --git a/clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp b/clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
index 7347657..92d590c 100644
--- a/clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
@@ -14,7 +14,6 @@ using namespace clang::ast_matchers;
namespace clang::tidy::google::objc {
void AvoidThrowingObjCExceptionCheck::registerMatchers(MatchFinder *Finder) {
-
Finder->addMatcher(objcThrowStmt().bind("throwStmt"), this);
Finder->addMatcher(
objcMessageExpr(anyOf(hasSelector("raise:format:"),
@@ -40,7 +39,7 @@ void AvoidThrowingObjCExceptionCheck::check(
// If the match location was in a macro, check if the macro was in a system
// header.
if (SourceLoc.isMacroID()) {
- SourceManager &SM = *Result.SourceManager;
+ const SourceManager &SM = *Result.SourceManager;
auto MacroLoc = SM.getImmediateMacroCallerLoc(SourceLoc);
// Matches in system header macros should be ignored.
diff --git a/clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.h b/clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.h
index 26a0465..417bb8f 100644
--- a/clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.h
+++ b/clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_OBJC_AVOID_THROWING_EXCEPTION_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_OBJC_AVOID_THROWING_EXCEPTION_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_AVOIDTHROWINGOBJCEXCEPTIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_AVOIDTHROWINGOBJCEXCEPTIONCHECK_H
#include "../ClangTidyCheck.h"
@@ -32,4 +32,4 @@ public:
} // namespace clang::tidy::google::objc
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_OBJC_AVOID_THROWING_EXCEPTION_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_AVOIDTHROWINGOBJCEXCEPTIONCHECK_H
diff --git a/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp b/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp
index b335463..b156d75 100644
--- a/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp
@@ -39,10 +39,11 @@ public:
void MacroExpands(const Token &MacroNameToken,
const MacroDefinition &MacroDefinition, SourceRange Range,
const MacroArgs *Args) override {
- IdentifierInfo *NameIdentifierInfo = MacroNameToken.getIdentifierInfo();
+ const IdentifierInfo *NameIdentifierInfo =
+ MacroNameToken.getIdentifierInfo();
if (!NameIdentifierInfo)
return;
- StringRef MacroName = NameIdentifierInfo->getName();
+ const StringRef MacroName = NameIdentifierInfo->getName();
if (!isGoogletestTestMacro(MacroName) || !Args ||
Args->getNumMacroArguments() < 2)
return;
@@ -50,7 +51,7 @@ public:
const Token *TestNameToken = Args->getUnexpArgument(1);
if (!TestSuiteNameToken || !TestNameToken)
return;
- std::string TestSuiteNameMaybeDisabled =
+ const std::string TestSuiteNameMaybeDisabled =
PP->getSpelling(*TestSuiteNameToken);
StringRef TestSuiteName = TestSuiteNameMaybeDisabled;
TestSuiteName.consume_front(KDisabledTestPrefix);
@@ -60,7 +61,7 @@ public:
"Googletest FAQ")
<< TestSuiteName;
- std::string TestNameMaybeDisabled = PP->getSpelling(*TestNameToken);
+ const std::string TestNameMaybeDisabled = PP->getSpelling(*TestNameToken);
StringRef TestName = TestNameMaybeDisabled;
TestName.consume_front(KDisabledTestPrefix);
if (TestName.contains('_'))
diff --git a/clang-tools-extra/clang-tidy/google/CMakeLists.txt b/clang-tools-extra/clang-tidy/google/CMakeLists.txt
index 1d4229e..982a188 100644
--- a/clang-tools-extra/clang-tidy/google/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/google/CMakeLists.txt
@@ -4,7 +4,6 @@ set(LLVM_LINK_COMPONENTS
)
add_clang_library(clangTidyGoogleModule STATIC
- AvoidCStyleCastsCheck.cpp
AvoidNSObjectNewCheck.cpp
AvoidThrowingObjCExceptionCheck.cpp
AvoidUnderscoreInGoogletestNameCheck.cpp
@@ -25,6 +24,7 @@ add_clang_library(clangTidyGoogleModule STATIC
LINK_LIBS
clangTidy
+ clangTidyModernizeModule
clangTidyReadabilityModule
clangTidyUtils
diff --git a/clang-tools-extra/clang-tidy/google/DefaultArgumentsCheck.h b/clang-tools-extra/clang-tidy/google/DefaultArgumentsCheck.h
index 1d1e4e3..0f397b4 100644
--- a/clang-tools-extra/clang-tidy/google/DefaultArgumentsCheck.h
+++ b/clang-tools-extra/clang-tidy/google/DefaultArgumentsCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_DEFAULT_ARGUMENTS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_DEFAULT_ARGUMENTS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_DEFAULTARGUMENTSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_DEFAULTARGUMENTSCHECK_H
#include "../ClangTidyCheck.h"
@@ -32,4 +32,4 @@ public:
} // namespace clang::tidy::google
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_DEFAULT_ARGUMENTS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_DEFAULTARGUMENTSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp b/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
index 6d5182d..ac604b7 100644
--- a/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
@@ -39,8 +39,8 @@ static SourceRange findToken(const SourceManager &Sources,
bool (*Pred)(const Token &)) {
if (StartLoc.isMacroID() || EndLoc.isMacroID())
return {};
- FileID File = Sources.getFileID(Sources.getSpellingLoc(StartLoc));
- StringRef Buf = Sources.getBufferData(File);
+ const FileID File = Sources.getFileID(Sources.getSpellingLoc(StartLoc));
+ const StringRef Buf = Sources.getBufferData(File);
const char *StartChar = Sources.getCharacterData(StartLoc);
Lexer Lex(StartLoc, LangOpts, StartChar, StartChar, Buf.end());
Lex.SetCommentRetentionState(true);
@@ -88,7 +88,7 @@ void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) {
Result.Nodes.getNodeAs<CXXConversionDecl>("conversion")) {
if (Conversion->isOutOfLine())
return;
- SourceLocation Loc = Conversion->getLocation();
+ const SourceLocation Loc = Conversion->getLocation();
// Ignore all macros until we learn to ignore specific ones (e.g. used in
// gmock to define matchers).
if (Loc.isMacroID())
@@ -105,7 +105,7 @@ void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) {
const ExplicitSpecifier ExplicitSpec = Ctor->getExplicitSpecifier();
- bool TakesInitializerList = isStdInitializerList(
+ const bool TakesInitializerList = isStdInitializerList(
Ctor->getParamDecl(0)->getType().getNonReferenceType());
if (ExplicitSpec.isExplicit() &&
(Ctor->isCopyOrMoveConstructor() || TakesInitializerList)) {
@@ -113,7 +113,7 @@ void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) {
return Tok.is(tok::raw_identifier) &&
Tok.getRawIdentifier() == "explicit";
};
- SourceRange ExplicitTokenRange =
+ const SourceRange ExplicitTokenRange =
findToken(*Result.SourceManager, getLangOpts(),
Ctor->getOuterLocStart(), Ctor->getEndLoc(), IsKwExplicit);
StringRef ConstructorDescription;
@@ -149,7 +149,7 @@ void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) {
const bool SingleArgument =
Ctor->getNumParams() == 1 && !Ctor->getParamDecl(0)->isParameterPack();
- SourceLocation Loc = Ctor->getLocation();
+ const SourceLocation Loc = Ctor->getLocation();
auto Diag =
diag(Loc, ExplicitExpr ? WithExpressionWarningMessage
: NoExpressionWarningMessage)
diff --git a/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp b/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp
index 3d75f4d..2b9183c 100644
--- a/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp
@@ -14,9 +14,7 @@ using namespace clang::ast_matchers;
namespace clang::tidy::google::objc {
-namespace {
-
-std::string validFunctionNameRegex(bool RequirePrefix) {
+static std::string validFunctionNameRegex(bool RequirePrefix) {
// Allow the following name patterns for all functions:
// • ABFoo (prefix + UpperCamelCase)
// • ABURL (prefix + capitalized acronym/initialism)
@@ -35,7 +33,7 @@ std::string validFunctionNameRegex(bool RequirePrefix) {
// If a prefix is required, the regex checks for a capital letter followed by
// another capital letter or number that is part of the prefix and another
// capital letter or number that begins the name following the prefix.
- std::string FunctionNameMatcher =
+ const std::string FunctionNameMatcher =
std::string(RequirePrefix ? "[A-Z][A-Z0-9]+" : "") + "[A-Z][a-zA-Z0-9]*";
return std::string("::(") + FunctionNameMatcher + ")$";
}
@@ -43,20 +41,20 @@ std::string validFunctionNameRegex(bool RequirePrefix) {
/// For now we will only fix functions of static storage class with names like
/// 'functionName' or 'function_name' and convert them to 'FunctionName'. For
/// other cases the user must determine an appropriate name on their own.
-FixItHint generateFixItHint(const FunctionDecl *Decl) {
+static FixItHint generateFixItHint(const FunctionDecl *Decl) {
// A fixit can be generated for functions of static storage class but
// otherwise the check cannot determine the appropriate function name prefix
// to use.
if (Decl->getStorageClass() != SC_Static)
return {};
- StringRef Name = Decl->getName();
+ const StringRef Name = Decl->getName();
std::string NewName = Decl->getName().str();
size_t Index = 0;
bool AtWordBoundary = true;
while (Index < NewName.size()) {
- char Ch = NewName[Index];
+ const char Ch = NewName[Index];
if (isalnum(Ch)) {
// Capitalize the first letter after every word boundary.
if (AtWordBoundary) {
@@ -82,8 +80,6 @@ FixItHint generateFixItHint(const FunctionDecl *Decl) {
return {};
}
-} // namespace
-
void FunctionNamingCheck::registerMatchers(MatchFinder *Finder) {
// Enforce Objective-C function naming conventions on all functions except:
// • Functions defined in system headers.
@@ -105,7 +101,7 @@ void FunctionNamingCheck::registerMatchers(MatchFinder *Finder) {
void FunctionNamingCheck::check(const MatchFinder::MatchResult &Result) {
const auto *MatchedDecl = Result.Nodes.getNodeAs<FunctionDecl>("function");
- bool IsGlobal = MatchedDecl->getStorageClass() != SC_Static;
+ const bool IsGlobal = MatchedDecl->getStorageClass() != SC_Static;
diag(MatchedDecl->getLocation(),
"%select{static function|function in global namespace}1 named %0 must "
"%select{be in|have an appropriate prefix followed by}1 Pascal case as "
diff --git a/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.h b/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.h
index e4efadf..6acc184 100644
--- a/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.h
+++ b/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_OBJC_FUNCTION_NAMING_CHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_OBJC_FUNCTION_NAMING_CHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_FUNCTIONNAMINGCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_FUNCTIONNAMINGCHECK_H
#include "../ClangTidyCheck.h"
#include "llvm/ADT/StringRef.h"
@@ -36,4 +36,4 @@ public:
} // namespace clang::tidy::google::objc
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_OBJC_FUNCTION_NAMING_CHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_FUNCTIONNAMINGCHECK_H
diff --git a/clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp b/clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
index a4c76be9..7470b1eb 100644
--- a/clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
@@ -30,7 +30,7 @@ static FixItHint generateFixItHint(const VarDecl *Decl, bool IsConst) {
return {};
}
- char FC = Decl->getName()[0];
+ const char FC = Decl->getName()[0];
if (!llvm::isAlpha(FC) || Decl->getName().size() == 1) {
// No fix available if first character is not alphabetical character, or it
// is a single-character variable, since it is difficult to determine the
@@ -38,7 +38,7 @@ static FixItHint generateFixItHint(const VarDecl *Decl, bool IsConst) {
// their own.
return {};
}
- char SC = Decl->getName()[1];
+ const char SC = Decl->getName()[1];
if ((FC == 'k' || FC == 'g') && !llvm::isAlpha(SC)) {
// No fix available if the prefix is correct but the second character is
// not alphabetical, since it is difficult to determine the proper fix in
diff --git a/clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.h b/clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.h
index 9b55855..e0693d4 100644
--- a/clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.h
+++ b/clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_OBJC_GLOBAL_VARIABLE_DECLARATION_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_OBJC_GLOBAL_VARIABLE_DECLARATION_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_GLOBALVARIABLEDECLARATIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_GLOBALVARIABLEDECLARATIONCHECK_H
#include "../ClangTidyCheck.h"
@@ -32,4 +32,4 @@ public:
} // namespace clang::tidy::google::objc
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_OBJC_GLOBAL_VARIABLE_DECLARATION_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_GLOBALVARIABLEDECLARATIONCHECK_H
diff --git a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
index aff8b45..ce46b3f 100644
--- a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
@@ -9,10 +9,10 @@
#include "../ClangTidy.h"
#include "../ClangTidyModule.h"
#include "../ClangTidyModuleRegistry.h"
+#include "../modernize/AvoidCStyleCastCheck.h"
#include "../readability/BracesAroundStatementsCheck.h"
#include "../readability/FunctionSizeCheck.h"
#include "../readability/NamespaceCommentCheck.h"
-#include "AvoidCStyleCastsCheck.h"
#include "AvoidNSObjectNewCheck.h"
#include "AvoidThrowingObjCExceptionCheck.h"
#include "AvoidUnderscoreInGoogletestNameCheck.h"
@@ -67,7 +67,7 @@ public:
CheckFactories
.registerCheck<readability::AvoidUnderscoreInGoogletestNameCheck>(
"google-readability-avoid-underscore-in-googletest-name");
- CheckFactories.registerCheck<readability::AvoidCStyleCastsCheck>(
+ CheckFactories.registerCheck<modernize::AvoidCStyleCastCheck>(
"google-readability-casting");
CheckFactories.registerCheck<readability::TodoCommentCheck>(
"google-readability-todo");
diff --git a/clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp b/clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp
index 52777fa..52bcf1b 100644
--- a/clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp
@@ -103,7 +103,7 @@ void IntegerTypesCheck::registerMatchers(MatchFinder *Finder) {
void IntegerTypesCheck::check(const MatchFinder::MatchResult &Result) {
auto TL = *Result.Nodes.getNodeAs<TypeLoc>("tl");
- SourceLocation Loc = TL.getBeginLoc();
+ const SourceLocation Loc = TL.getBeginLoc();
// Look through qualification.
if (auto QualLoc = TL.getAs<QualifiedTypeLoc>())
@@ -113,7 +113,7 @@ void IntegerTypesCheck::check(const MatchFinder::MatchResult &Result) {
if (!BuiltinLoc)
return;
- Token Tok = getTokenAtLoc(Loc, Result, *IdentTable);
+ const Token Tok = getTokenAtLoc(Loc, Result, *IdentTable);
// Ensure the location actually points to one of the builting integral type
// names we're interested in. Otherwise, we might be getting this match from
// implicit code (e.g. an implicit assignment operator of a class containing
@@ -164,7 +164,7 @@ void IntegerTypesCheck::check(const MatchFinder::MatchResult &Result) {
!isAsciiIdentifierContinue(Data[Port.size()]))
return;
- std::string Replacement =
+ const std::string Replacement =
((IsSigned ? SignedTypePrefix : UnsignedTypePrefix) + Twine(Width) +
TypeSuffix)
.str();
diff --git a/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp b/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp
index 8554870..2789e4d 100644
--- a/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp
@@ -11,41 +11,102 @@
#include "clang/Lex/Preprocessor.h"
#include <optional>
-namespace clang::tidy::google::readability {
+namespace clang::tidy {
+
+namespace google::readability {
+
+enum class StyleKind { Parentheses, Hyphen };
+
+} // namespace google::readability
+
+template <> struct OptionEnumMapping<google::readability::StyleKind> {
+ static ArrayRef<std::pair<google::readability::StyleKind, StringRef>>
+ getEnumMapping() {
+ static constexpr std::pair<google::readability::StyleKind, StringRef>
+ Mapping[] = {
+ {google::readability::StyleKind::Hyphen, "Hyphen"},
+ {google::readability::StyleKind::Parentheses, "Parentheses"},
+ };
+ return {Mapping};
+ }
+};
+
+} // namespace clang::tidy
+namespace clang::tidy::google::readability {
class TodoCommentCheck::TodoCommentHandler : public CommentHandler {
public:
TodoCommentHandler(TodoCommentCheck &Check, std::optional<std::string> User)
: Check(Check), User(User ? *User : "unknown"),
- TodoMatch("^// *TODO *(\\(.*\\))?:?( )?(.*)$") {}
+ TodoMatch(R"(^// *TODO *((\((.*)\))?:?( )?|: *(.*) *- *)?(.*)$)") {
+ const llvm::StringRef TodoStyleString =
+ Check.Options.get("Style", "Hyphen");
+ for (const auto &[Value, Name] :
+ OptionEnumMapping<StyleKind>::getEnumMapping()) {
+ if (Name == TodoStyleString) {
+ TodoStyle = Value;
+ return;
+ }
+ }
+ Check.configurationDiag(
+ "invalid value '%0' for "
+ "google-readability-todo.Style; valid values are "
+ "'Parentheses' and 'Hyphen'. Defaulting to 'Hyphen'")
+ << TodoStyleString;
+ }
bool HandleComment(Preprocessor &PP, SourceRange Range) override {
- StringRef Text =
+ const StringRef Text =
Lexer::getSourceText(CharSourceRange::getCharRange(Range),
PP.getSourceManager(), PP.getLangOpts());
- SmallVector<StringRef, 4> Matches;
+ SmallVector<StringRef, 7> Matches;
if (!TodoMatch.match(Text, &Matches))
return false;
- StringRef Username = Matches[1];
- StringRef Comment = Matches[3];
+ const StyleKind ParsedStyle =
+ !Matches[3].empty() ? StyleKind::Parentheses : StyleKind::Hyphen;
+ const StringRef Username =
+ ParsedStyle == StyleKind::Parentheses ? Matches[3] : Matches[5];
+ const StringRef Comment = Matches[6];
- if (!Username.empty())
+ if (!Username.empty() &&
+ (ParsedStyle == StyleKind::Parentheses || !Comment.empty())) {
return false;
+ }
- std::string NewText = ("// TODO(" + Twine(User) + "): " + Comment).str();
+ if (Username.empty()) {
+ Check.diag(Range.getBegin(), "missing username/bug in TODO")
+ << FixItHint::CreateReplacement(
+ CharSourceRange::getCharRange(Range),
+ createReplacementString(Username, Comment));
+ }
+
+ if (Comment.empty())
+ Check.diag(Range.getBegin(), "missing details in TODO");
- Check.diag(Range.getBegin(), "missing username/bug in TODO")
- << FixItHint::CreateReplacement(CharSourceRange::getCharRange(Range),
- NewText);
return false;
}
+ std::string createReplacementString(const StringRef Username,
+ const StringRef Comment) const {
+ if (TodoStyle == StyleKind::Parentheses) {
+ return ("// TODO(" + Twine(User) +
+ "): " + (Comment.empty() ? "some details" : Comment))
+ .str();
+ }
+ return ("// TODO: " + Twine(User) + " - " +
+ (Comment.empty() ? "some details" : Comment))
+ .str();
+ }
+
+ StyleKind getTodoStyle() const { return TodoStyle; }
+
private:
TodoCommentCheck &Check;
std::string User;
llvm::Regex TodoMatch;
+ StyleKind TodoStyle = StyleKind::Hyphen;
};
TodoCommentCheck::TodoCommentCheck(StringRef Name, ClangTidyContext *Context)
@@ -61,4 +122,8 @@ void TodoCommentCheck::registerPPCallbacks(const SourceManager &SM,
PP->addCommentHandler(Handler.get());
}
+void TodoCommentCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+ Options.store(Opts, "Style", Handler->getTodoStyle());
+}
+
} // namespace clang::tidy::google::readability
diff --git a/clang-tools-extra/clang-tidy/google/TodoCommentCheck.h b/clang-tools-extra/clang-tidy/google/TodoCommentCheck.h
index 08cea13..800bc0f 100644
--- a/clang-tools-extra/clang-tidy/google/TodoCommentCheck.h
+++ b/clang-tools-extra/clang-tidy/google/TodoCommentCheck.h
@@ -27,6 +27,8 @@ public:
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override;
+ void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+
private:
class TodoCommentHandler;
std::unique_ptr<TodoCommentHandler> Handler;
diff --git a/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp b/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
index 3066dd0..054bdc8 100644
--- a/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
@@ -28,7 +28,7 @@ void UnnamedNamespaceInHeaderCheck::registerMatchers(
void UnnamedNamespaceInHeaderCheck::check(
const MatchFinder::MatchResult &Result) {
const auto *N = Result.Nodes.getNodeAs<NamespaceDecl>("anonymousNamespace");
- SourceLocation Loc = N->getBeginLoc();
+ const SourceLocation Loc = N->getBeginLoc();
if (!Loc.isValid())
return;
diff --git a/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp b/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp
index 9da1915..87fd046 100644
--- a/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp
@@ -64,7 +64,7 @@ public:
// We check if the newly defined macro is one of the target replacements.
// This ensures that the check creates warnings only if it is including a
// recent enough version of Google Test.
- llvm::StringRef FileName = PP->getSourceManager().getFilename(
+ const llvm::StringRef FileName = PP->getSourceManager().getFilename(
MD->getMacroInfo()->getDefinitionLoc());
ReplacementFound = FileName.ends_with("gtest/gtest-typed-test.h") &&
PP->getSpelling(MacroNameTok) == "TYPED_TEST_SUITE";
@@ -94,18 +94,18 @@ private:
if (!ReplacementFound)
return;
- std::string Name = PP->getSpelling(MacroNameTok);
+ const std::string Name = PP->getSpelling(MacroNameTok);
std::optional<llvm::StringRef> Replacement = getNewMacroName(Name);
if (!Replacement)
return;
- llvm::StringRef FileName = PP->getSourceManager().getFilename(
+ const llvm::StringRef FileName = PP->getSourceManager().getFilename(
MD.getMacroInfo()->getDefinitionLoc());
if (!FileName.ends_with("gtest/gtest-typed-test.h"))
return;
- DiagnosticBuilder Diag = Check->diag(Loc, RenameCaseToSuiteMessage);
+ const DiagnosticBuilder Diag = Check->diag(Loc, RenameCaseToSuiteMessage);
if (Action == CheckAction::Rename)
Diag << FixItHint::CreateReplacement(
@@ -234,7 +234,7 @@ static bool isInInstantiation(const NodeType &Node,
template <typename NodeType>
static bool isInTemplate(const NodeType &Node,
const MatchFinder::MatchResult &Result) {
- internal::Matcher<NodeType> IsInsideTemplate =
+ const internal::Matcher<NodeType> IsInsideTemplate =
hasAncestor(decl(anyOf(classTemplateDecl(), functionTemplateDecl())));
return !match(IsInsideTemplate, Node, *Result.Context).empty();
}
@@ -340,7 +340,7 @@ void UpgradeGoogletestCaseCheck::check(const MatchFinder::MatchResult &Result) {
// will only be instantiated with the true type name, `TestSuite`.
}
- DiagnosticBuilder Diag =
+ const DiagnosticBuilder Diag =
diag(ReplacementRange.getBegin(), RenameCaseToSuiteMessage);
ReplacementRange = Lexer::makeFileCharRange(
diff --git a/clang-tools-extra/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp b/clang-tools-extra/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp
index fbfd5d34..00446dc 100644
--- a/clang-tools-extra/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp
@@ -22,7 +22,7 @@ void UsingNamespaceDirectiveCheck::registerMatchers(
void UsingNamespaceDirectiveCheck::check(
const MatchFinder::MatchResult &Result) {
const auto *U = Result.Nodes.getNodeAs<UsingDirectiveDecl>("usingNamespace");
- SourceLocation Loc = U->getBeginLoc();
+ const SourceLocation Loc = U->getBeginLoc();
if (U->isImplicit() || !Loc.isValid())
return;
diff --git a/clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.h b/clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.h
index 12fe7f7..800e7ac 100644
--- a/clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.h
+++ b/clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_EXCEPTION_BASECLASS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_EXCEPTION_BASECLASS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_EXCEPTIONBASECLASSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_EXCEPTIONBASECLASSCHECK_H
#include "../ClangTidyCheck.h"
@@ -31,4 +31,4 @@ public:
} // namespace clang::tidy::hicpp
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_EXCEPTION_BASECLASS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_EXCEPTIONBASECLASSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
index e610d99..e9a5819 100644
--- a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
+++ b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
@@ -152,7 +152,7 @@ void MultiwayPathsCoveredCheck::handleSwitchWithoutDefault(
assert(CaseCount > 0 && "Switch statement without any case found. This case "
"should be excluded by the matcher and is handled "
"separately.");
- std::size_t MaxPathsPossible = [&]() {
+ const std::size_t MaxPathsPossible = [&]() {
if (const auto *GeneralCondition =
Result.Nodes.getNodeAs<DeclRefExpr>("non-enum-condition")) {
return getNumberOfPossibleValues(GeneralCondition->getType(),
diff --git a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.h b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.h
index 902be2d..e22e31a 100644
--- a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.h
+++ b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_MULTIWAY_PATHS_COVERED_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_MULTIWAY_PATHS_COVERED_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_MULTIWAYPATHSCOVEREDCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_MULTIWAYPATHSCOVEREDCHECK_H
#include "../ClangTidyCheck.h"
@@ -41,4 +41,4 @@ private:
} // namespace clang::tidy::hicpp
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_MULTIWAY_PATHS_COVERED_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_MULTIWAYPATHSCOVEREDCHECK_H
diff --git a/clang-tools-extra/clang-tidy/hicpp/NoAssemblerCheck.cpp b/clang-tools-extra/clang-tidy/hicpp/NoAssemblerCheck.cpp
index a89a896..e7d97b2 100644
--- a/clang-tools-extra/clang-tidy/hicpp/NoAssemblerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/hicpp/NoAssemblerCheck.cpp
@@ -13,17 +13,10 @@ using namespace clang::ast_matchers;
namespace clang::tidy::hicpp {
-namespace {
-AST_MATCHER(VarDecl, isAsm) { return Node.hasAttr<clang::AsmLabelAttr>(); }
-const ast_matchers::internal::VariadicDynCastAllOfMatcher<Decl,
- FileScopeAsmDecl>
- fileScopeAsmDecl; // NOLINT(readability-identifier-*) preserve clang style
-} // namespace
-
void NoAssemblerCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(asmStmt().bind("asm-stmt"), this);
Finder->addMatcher(fileScopeAsmDecl().bind("asm-file-scope"), this);
- Finder->addMatcher(varDecl(isAsm()).bind("asm-var"), this);
+ Finder->addMatcher(varDecl(hasAttr(attr::AsmLabel)).bind("asm-var"), this);
}
void NoAssemblerCheck::check(const MatchFinder::MatchResult &Result) {
diff --git a/clang-tools-extra/clang-tidy/hicpp/NoAssemblerCheck.h b/clang-tools-extra/clang-tidy/hicpp/NoAssemblerCheck.h
index 1ff40ea..15d646f 100644
--- a/clang-tools-extra/clang-tidy/hicpp/NoAssemblerCheck.h
+++ b/clang-tools-extra/clang-tidy/hicpp/NoAssemblerCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_NO_ASSEMBLER_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_NO_ASSEMBLER_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_NOASSEMBLERCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_NOASSEMBLERCHECK_H
#include "../ClangTidyCheck.h"
@@ -27,4 +27,4 @@ public:
} // namespace clang::tidy::hicpp
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_NO_ASSEMBLER_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_NOASSEMBLERCHECK_H
diff --git a/clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.h b/clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.h
index 499a4e7..ef92a4d 100644
--- a/clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.h
+++ b/clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_SIGNED_BITWISE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_SIGNED_BITWISE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_SIGNEDBITWISECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_SIGNEDBITWISECHECK_H
#include "../ClangTidyCheck.h"
@@ -31,4 +31,4 @@ private:
} // namespace clang::tidy::hicpp
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_SIGNED_BITWISE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_SIGNEDBITWISECHECK_H
diff --git a/clang-tools-extra/clang-tidy/llvm/.clang-tidy b/clang-tools-extra/clang-tidy/llvm/.clang-tidy
new file mode 100644
index 0000000..08c2c1d
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/llvm/.clang-tidy
@@ -0,0 +1,5 @@
+InheritParentConfig: true
+# FIXME(vbvictor) enable this check when https://github.com/llvm/llvm-project/issues/166750 is fixed
+# and github runners are updated to include the fix
+Checks: >
+ -llvm-header-guard
diff --git a/clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.cpp b/clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.cpp
index 8737c1e..ef8b6b1 100644
--- a/clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.cpp
@@ -28,24 +28,24 @@ std::string LLVMHeaderGuardCheck::getHeaderGuard(StringRef Filename,
// style in include/llvm and include/clang which we want to preserve.
// We don't want _INCLUDE_ in our guards.
- size_t PosInclude = Guard.rfind("include/");
+ const size_t PosInclude = Guard.rfind("include/");
if (PosInclude != StringRef::npos)
Guard = Guard.substr(PosInclude + std::strlen("include/"));
// For clang we drop the _TOOLS_.
- size_t PosToolsClang = Guard.rfind("tools/clang/");
+ const size_t PosToolsClang = Guard.rfind("tools/clang/");
if (PosToolsClang != StringRef::npos)
Guard = Guard.substr(PosToolsClang + std::strlen("tools/"));
// Unlike LLVM svn, LLVM git monorepo is named llvm-project, so we replace
// "/llvm-project/" with the canonical "/llvm/".
const static StringRef LLVMProject = "/llvm-project/";
- size_t PosLLVMProject = Guard.rfind(LLVMProject);
+ const size_t PosLLVMProject = Guard.rfind(LLVMProject);
if (PosLLVMProject != StringRef::npos)
Guard = Guard.replace(PosLLVMProject, LLVMProject.size(), "/llvm/");
// The remainder is LLVM_FULL_PATH_TO_HEADER_H
- size_t PosLLVM = Guard.rfind("llvm/");
+ const size_t PosLLVM = Guard.rfind("llvm/");
if (PosLLVM != StringRef::npos)
Guard = Guard.substr(PosLLVM);
diff --git a/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp b/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp
index f34e3a6..416aca1 100644
--- a/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp
@@ -162,15 +162,15 @@ void IncludeOrderPPCallbacks::EndOfMainFile() {
continue;
const IncludeDirective &CopyFrom = FileDirectives[IncludeIndices[I]];
- SourceLocation FromLoc = CopyFrom.Range.getBegin();
+ const SourceLocation FromLoc = CopyFrom.Range.getBegin();
const char *FromData = SM.getCharacterData(FromLoc);
- unsigned FromLen = std::strcspn(FromData, "\n");
+ const unsigned FromLen = std::strcspn(FromData, "\n");
- StringRef FixedName(FromData, FromLen);
+ const StringRef FixedName(FromData, FromLen);
- SourceLocation ToLoc = FileDirectives[I].Range.getBegin();
+ const SourceLocation ToLoc = FileDirectives[I].Range.getBegin();
const char *ToData = SM.getCharacterData(ToLoc);
- unsigned ToLen = std::strcspn(ToData, "\n");
+ const unsigned ToLen = std::strcspn(ToData, "\n");
auto ToRange =
CharSourceRange::getCharRange(ToLoc, ToLoc.getLocWithOffset(ToLen));
diff --git a/clang-tools-extra/clang-tidy/llvm/PreferIsaOrDynCastInConditionalsCheck.cpp b/clang-tools-extra/clang-tidy/llvm/PreferIsaOrDynCastInConditionalsCheck.cpp
index f4f3543..8966745 100644
--- a/clang-tools-extra/clang-tidy/llvm/PreferIsaOrDynCastInConditionalsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvm/PreferIsaOrDynCastInConditionalsCheck.cpp
@@ -68,8 +68,8 @@ void PreferIsaOrDynCastInConditionalsCheck::check(
// llvm::cast<T>(x)
// ^ ^
// StartLoc EndLoc
- SourceLocation StartLoc = Callee->getLocation();
- SourceLocation EndLoc = Callee->getNameInfo().getEndLoc();
+ const SourceLocation StartLoc = Callee->getLocation();
+ const SourceLocation EndLoc = Callee->getNameInfo().getEndLoc();
if (Result.Nodes.getNodeAs<VarDecl>("var")) {
diag(StartLoc,
diff --git a/clang-tools-extra/clang-tidy/llvm/PreferStaticOverAnonymousNamespaceCheck.cpp b/clang-tools-extra/clang-tidy/llvm/PreferStaticOverAnonymousNamespaceCheck.cpp
index ea81c7c..d720986 100644
--- a/clang-tools-extra/clang-tidy/llvm/PreferStaticOverAnonymousNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvm/PreferStaticOverAnonymousNamespaceCheck.cpp
@@ -77,7 +77,6 @@ void PreferStaticOverAnonymousNamespaceCheck::registerMatchers(
void PreferStaticOverAnonymousNamespaceCheck::check(
const MatchFinder::MatchResult &Result) {
-
if (const auto *Func = Result.Nodes.getNodeAs<FunctionDecl>("function")) {
if (Func->isCXXClassMember())
diag(Func->getLocation(),
diff --git a/clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.cpp b/clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.cpp
index b8b7c41..7dea845 100644
--- a/clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.cpp
@@ -40,13 +40,13 @@ void TwineLocalCheck::check(const MatchFinder::MatchResult &Result) {
C = cast<CXXConstructExpr>(C)->getArg(0)->IgnoreParenImpCasts();
}
- SourceRange TypeRange =
+ const SourceRange TypeRange =
VD->getTypeSourceInfo()->getTypeLoc().getSourceRange();
// A real Twine, turn it into a std::string.
if (VD->getType()->getCanonicalTypeUnqualified() ==
C->getType()->getCanonicalTypeUnqualified()) {
- SourceLocation EndLoc = Lexer::getLocForEndOfToken(
+ const SourceLocation EndLoc = Lexer::getLocForEndOfToken(
VD->getInit()->getEndLoc(), 0, *Result.SourceManager, getLangOpts());
Diag << FixItHint::CreateReplacement(TypeRange, "std::string")
<< FixItHint::CreateInsertion(VD->getInit()->getBeginLoc(), "(")
diff --git a/clang-tools-extra/clang-tidy/llvm/UseNewMLIROpBuilderCheck.cpp b/clang-tools-extra/clang-tidy/llvm/UseNewMLIROpBuilderCheck.cpp
index bd51cc5..16f8786 100644
--- a/clang-tools-extra/clang-tidy/llvm/UseNewMLIROpBuilderCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvm/UseNewMLIROpBuilderCheck.cpp
@@ -12,24 +12,20 @@
#include "clang/Lex/Lexer.h"
#include "clang/Tooling/Transformer/RangeSelector.h"
#include "clang/Tooling/Transformer/RewriteRule.h"
-#include "clang/Tooling/Transformer/SourceCode.h"
#include "clang/Tooling/Transformer/Stencil.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FormatVariadic.h"
namespace clang::tidy::llvm_check {
-namespace {
using namespace ::clang::ast_matchers;
using namespace ::clang::transformer;
-EditGenerator rewrite(RangeSelector Call, RangeSelector Builder,
- RangeSelector CallArgs) {
+static EditGenerator rewrite(RangeSelector Call, RangeSelector Builder) {
// This is using an EditGenerator rather than ASTEdit as we want to warn even
// if in macro.
- return [Call = std::move(Call), Builder = std::move(Builder),
- CallArgs =
- std::move(CallArgs)](const MatchFinder::MatchResult &Result)
+ return [Call = std::move(Call),
+ Builder = std::move(Builder)](const MatchFinder::MatchResult &Result)
-> Expected<SmallVector<transformer::Edit, 1>> {
Expected<CharSourceRange> CallRange = Call(Result);
if (!CallRange)
@@ -39,7 +35,7 @@ EditGenerator rewrite(RangeSelector Call, RangeSelector Builder,
SourceLocation Begin = CallRange->getBegin();
// This will result in just a warning and no edit.
- bool InMacro = CallRange->getBegin().isMacroID();
+ const bool InMacro = CallRange->getBegin().isMacroID();
if (InMacro) {
while (SM.isMacroArgExpansion(Begin))
Begin = SM.getImmediateExpansionRange(Begin).getBegin();
@@ -54,7 +50,7 @@ EditGenerator rewrite(RangeSelector Call, RangeSelector Builder,
auto NextToken = [&](std::optional<Token> CurrentToken) {
if (!CurrentToken)
return CurrentToken;
- if (CurrentToken->getEndLoc() >= CallRange->getEnd())
+ if (CurrentToken->is(clang::tok::eof))
return std::optional<Token>();
return clang::Lexer::findNextToken(CurrentToken->getLocation(), SM,
LangOpts);
@@ -68,9 +64,10 @@ EditGenerator rewrite(RangeSelector Call, RangeSelector Builder,
return llvm::make_error<llvm::StringError>(llvm::errc::invalid_argument,
"missing '<' token");
}
+
std::optional<Token> EndToken = NextToken(LessToken);
- for (std::optional<Token> GreaterToken = NextToken(EndToken);
- GreaterToken && GreaterToken->getKind() != clang::tok::greater;
+ std::optional<Token> GreaterToken = NextToken(EndToken);
+ for (; GreaterToken && GreaterToken->getKind() != clang::tok::greater;
GreaterToken = NextToken(GreaterToken)) {
EndToken = GreaterToken;
}
@@ -79,12 +76,21 @@ EditGenerator rewrite(RangeSelector Call, RangeSelector Builder,
"missing '>' token");
}
+ std::optional<Token> ArgStart = NextToken(GreaterToken);
+ if (!ArgStart || ArgStart->getKind() != clang::tok::l_paren) {
+ return llvm::make_error<llvm::StringError>(llvm::errc::invalid_argument,
+ "missing '(' token");
+ }
+ std::optional<Token> Arg = NextToken(ArgStart);
+ if (!Arg) {
+ return llvm::make_error<llvm::StringError>(llvm::errc::invalid_argument,
+ "unexpected end of file");
+ }
+ const bool HasArgs = Arg->getKind() != clang::tok::r_paren;
+
Expected<CharSourceRange> BuilderRange = Builder(Result);
if (!BuilderRange)
return BuilderRange.takeError();
- Expected<CharSourceRange> CallArgsRange = CallArgs(Result);
- if (!CallArgsRange)
- return CallArgsRange.takeError();
// Helper for concatting below.
auto GetText = [&](const CharSourceRange &Range) {
@@ -93,43 +99,42 @@ EditGenerator rewrite(RangeSelector Call, RangeSelector Builder,
Edit Replace;
Replace.Kind = EditKind::Range;
- Replace.Range = *CallRange;
- std::string CallArgsStr;
- // Only emit args if there are any.
- if (auto CallArgsText = GetText(*CallArgsRange).ltrim();
- !CallArgsText.rtrim().empty()) {
- CallArgsStr = llvm::formatv(", {}", CallArgsText);
+ Replace.Range.setBegin(CallRange->getBegin());
+ Replace.Range.setEnd(ArgStart->getEndLoc());
+ const Expr *BuilderExpr = Result.Nodes.getNodeAs<Expr>("builder");
+ std::string BuilderText = GetText(*BuilderRange).str();
+ if (BuilderExpr->getType()->isPointerType()) {
+ BuilderText = BuilderExpr->isImplicitCXXThis()
+ ? "*this"
+ : llvm::formatv("*{}", BuilderText).str();
}
- Replace.Replacement =
- llvm::formatv("{}::create({}{})",
- GetText(CharSourceRange::getTokenRange(
- LessToken->getEndLoc(), EndToken->getLastLoc())),
- GetText(*BuilderRange), CallArgsStr);
+ const StringRef OpType = GetText(CharSourceRange::getTokenRange(
+ LessToken->getEndLoc(), EndToken->getLastLoc()));
+ Replace.Replacement = llvm::formatv("{}::create({}{}", OpType, BuilderText,
+ HasArgs ? ", " : "");
return SmallVector<Edit, 1>({Replace});
};
}
-RewriteRuleWith<std::string> useNewMlirOpBuilderCheckRule() {
- Stencil Message = cat("use 'OpType::create(builder, ...)' instead of "
- "'builder.create<OpType>(...)'");
+static RewriteRuleWith<std::string> useNewMlirOpBuilderCheckRule() {
+ const Stencil Message = cat("use 'OpType::create(builder, ...)' instead of "
+ "'builder.create<OpType>(...)'");
// Match a create call on an OpBuilder.
- ast_matchers::internal::Matcher<Stmt> Base =
+ auto BuilderType = cxxRecordDecl(isSameOrDerivedFrom("::mlir::OpBuilder"));
+ const ast_matchers::internal::Matcher<Stmt> Base =
cxxMemberCallExpr(
- on(expr(hasType(
- cxxRecordDecl(isSameOrDerivedFrom("::mlir::OpBuilder"))))
+ on(expr(anyOf(hasType(BuilderType), hasType(pointsTo(BuilderType))))
.bind("builder")),
- callee(cxxMethodDecl(hasTemplateArgument(0, templateArgument()))),
- callee(cxxMethodDecl(hasName("create"))))
+ callee(cxxMethodDecl(hasTemplateArgument(0, templateArgument()),
+ hasName("create"))))
.bind("call");
return applyFirst(
// Attempt rewrite given an lvalue builder, else just warn.
{makeRule(cxxMemberCallExpr(unless(on(cxxTemporaryObjectExpr())), Base),
- rewrite(node("call"), node("builder"), callArgs("call")),
- Message),
+ rewrite(node("call"), node("builder")), Message),
makeRule(Base, noopEdit(node("call")), Message)});
}
-} // namespace
UseNewMlirOpBuilderCheck::UseNewMlirOpBuilderCheck(StringRef Name,
ClangTidyContext *Context)
diff --git a/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp b/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
index 091e4fe..9f09947 100644
--- a/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
@@ -78,7 +78,8 @@ void InlineFunctionDeclCheck::check(const MatchFinder::MatchResult &Result) {
// Check if decl starts with LIBC_INLINE
auto Loc = FullSourceLoc(Result.SourceManager->getFileLoc(SrcBegin),
*Result.SourceManager);
- llvm::StringRef SrcText = Loc.getBufferData().drop_front(Loc.getFileOffset());
+ const llvm::StringRef SrcText =
+ Loc.getBufferData().drop_front(Loc.getFileOffset());
if (SrcText.starts_with("LIBC_INLINE"))
return;
diff --git a/clang-tools-extra/clang-tidy/llvmlibc/NamespaceConstants.h b/clang-tools-extra/clang-tidy/llvmlibc/NamespaceConstants.h
index 50669dc..8b8b719 100644
--- a/clang-tools-extra/clang-tidy/llvmlibc/NamespaceConstants.h
+++ b/clang-tools-extra/clang-tidy/llvmlibc/NamespaceConstants.h
@@ -6,6 +6,9 @@
//
//===----------------------------------------------------------------------===//
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVMLIBC_NAMESPACECONSTANTS_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVMLIBC_NAMESPACECONSTANTS_H
+
#include "llvm/ADT/StringRef.h"
namespace clang::tidy::llvm_libc {
@@ -18,3 +21,5 @@ const static llvm::StringRef RequiredNamespaceDeclMacroName =
"LIBC_NAMESPACE_DECL";
} // namespace clang::tidy::llvm_libc
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVMLIBC_NAMESPACECONSTANTS_H
diff --git a/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp b/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
index 129b8a9..ecd8e19 100644
--- a/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
@@ -22,11 +22,11 @@ namespace {
class RestrictedIncludesPPCallbacks
: public portability::RestrictedIncludesPPCallbacks {
public:
- explicit RestrictedIncludesPPCallbacks(
- RestrictSystemLibcHeadersCheck &Check, const SourceManager &SM,
- const SmallString<128> CompilerIncudeDir)
+ explicit RestrictedIncludesPPCallbacks(RestrictSystemLibcHeadersCheck &Check,
+ const SourceManager &SM,
+ SmallString<128> CompilerIncudeDir)
: portability::RestrictedIncludesPPCallbacks(Check, SM),
- CompilerIncudeDir(CompilerIncudeDir) {}
+ CompilerIncudeDir(std::move(CompilerIncudeDir)) {}
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
@@ -61,7 +61,7 @@ void RestrictSystemLibcHeadersCheck::registerPPCallbacks(
StringRef(PP->getHeaderSearchInfo().getHeaderSearchOpts().ResourceDir);
llvm::sys::path::append(CompilerIncudeDir, "include");
PP->addPPCallbacks(std::make_unique<RestrictedIncludesPPCallbacks>(
- *this, SM, CompilerIncudeDir));
+ *this, SM, std::move(CompilerIncudeDir)));
}
} // namespace clang::tidy::llvm_libc
diff --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
index 2cfee5f..e8705aa 100644
--- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
@@ -25,14 +25,15 @@ add_clang_library(clangTidyMiscModule STATIC
HeaderIncludeCycleCheck.cpp
IncludeCleanerCheck.cpp
MiscTidyModule.cpp
- MisleadingBidirectional.cpp
- MisleadingIdentifier.cpp
+ MisleadingBidirectionalCheck.cpp
+ MisleadingIdentifierCheck.cpp
MisplacedConstCheck.cpp
NewDeleteOverloadsCheck.cpp
NoRecursionCheck.cpp
- NonCopyableObjects.cpp
+ NonCopyableObjectsCheck.cpp
NonPrivateMemberVariablesInClassesCheck.cpp
OverrideWithDifferentVisibilityCheck.cpp
+ PredictableRandCheck.cpp
RedundantExpressionCheck.cpp
StaticAssertCheck.cpp
ThrowByValueCatchByReferenceCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp b/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
index b05fd04..418b8ae 100644
--- a/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
@@ -53,10 +53,9 @@ static llvm::SmallString<64U> skeleton(StringRef Name) {
const char *Curr = Name.data();
const char *End = Curr + Name.size();
while (Curr < End) {
-
const char *Prev = Curr;
UTF32 CodePoint = 0;
- ConversionResult Result = convertUTF8Sequence(
+ const ConversionResult Result = convertUTF8Sequence(
reinterpret_cast<const UTF8 **>(&Curr),
reinterpret_cast<const UTF8 *>(End), &CodePoint, strictConversion);
if (Result != conversionOK) {
@@ -64,7 +63,7 @@ static llvm::SmallString<64U> skeleton(StringRef Name) {
break;
}
- StringRef Key(Prev, Curr - Prev);
+ const StringRef Key(Prev, Curr - Prev);
auto *Where = llvm::lower_bound(ConfusableEntries, CodePoint,
[](decltype(ConfusableEntries[0]) X,
UTF32 Y) { return X.codepoint < Y; });
@@ -82,7 +81,8 @@ static llvm::SmallString<64U> skeleton(StringRef Name) {
errs() << "Unicode conversion issue\n";
break;
}
- Skeleton.append((char *)BufferStart, (char *)IBuffer);
+ Skeleton.append(reinterpret_cast<char *>(BufferStart),
+ reinterpret_cast<char *>(IBuffer));
}
}
return Skeleton;
@@ -183,7 +183,7 @@ void ConfusableIdentifierCheck::addDeclToCheck(const NamedDecl *ND,
if (!NDII)
return;
- StringRef NDName = NDII->getName();
+ const StringRef NDName = NDII->getName();
if (NDName.empty())
return;
@@ -216,7 +216,7 @@ void ConfusableIdentifierCheck::onEndOfTranslationUnit() {
// the same skeleton.
for (const IdentifierInfo *II : Idents) {
for (auto [OuterND, OuterParent] : NameToDecls[II]) {
- for (Entry Inner : DeclsWithinContext[OuterParent]) {
+ for (const Entry Inner : DeclsWithinContext[OuterParent]) {
// Don't complain if the identifiers are the same.
if (OuterND->getIdentifier() == Inner.ND->getIdentifier())
continue;
diff --git a/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.h b/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.h
index b341d03..5b98d48 100644
--- a/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_CONFUSABLE_IDENTIFIER_CHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_CONFUSABLE_IDENTIFIER_CHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_CONFUSABLEIDENTIFIERCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_CONFUSABLEIDENTIFIERCHECK_H
#include "../ClangTidyCheck.h"
#include "llvm/ADT/DenseMap.h"
@@ -41,4 +41,4 @@ private:
} // namespace clang::tidy::misc
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_CONFUSABLE_IDENTIFIER_CHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_CONFUSABLEIDENTIFIERCHECK_H
diff --git a/clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp b/clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp
index 6a07902..f5dcc7f 100644
--- a/clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp
@@ -26,7 +26,7 @@ int main(int argc, char *argv[]) {
std::vector<std::pair<llvm::UTF32, SmallVector<llvm::UTF32>>> Entries;
SmallVector<StringRef> Values;
- for (StringRef Line : Lines) {
+ for (const StringRef Line : Lines) {
if (Line.starts_with("#"))
continue;
@@ -37,14 +37,14 @@ int main(int argc, char *argv[]) {
return 2;
}
- llvm::StringRef From = Values[0].trim();
+ const llvm::StringRef From = Values[0].trim();
llvm::UTF32 CodePoint = 0;
From.getAsInteger(16, CodePoint);
SmallVector<llvm::UTF32> To;
SmallVector<StringRef> ToN;
Values[1].split(ToN, ' ', -1, false);
- for (StringRef ToI : ToN) {
+ for (const StringRef ToI : ToN) {
llvm::UTF32 ToCodePoint = 0;
ToI.trim().getAsInteger(16, ToCodePoint);
To.push_back(ToCodePoint);
@@ -56,7 +56,7 @@ int main(int argc, char *argv[]) {
}
llvm::sort(Entries);
- unsigned LargestValue =
+ const unsigned LargestValue =
llvm::max_element(Entries, [](const auto &Entry0, const auto &Entry1) {
return Entry0.second.size() < Entry1.second.size();
})->second.size();
diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
index 3b9b8e0..75693a0 100644
--- a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
@@ -56,7 +56,7 @@ AST_MATCHER_P(Stmt, forEachPrevStmt, ast_matchers::internal::Matcher<Stmt>,
// Matches the expression awaited by the `co_await`.
AST_MATCHER_P(CoawaitExpr, awaitable, ast_matchers::internal::Matcher<Expr>,
InnerMatcher) {
- if (Expr *E = Node.getOperand())
+ if (const Expr *E = Node.getOperand())
return InnerMatcher.matches(*E, Finder, Builder);
return false;
}
@@ -67,13 +67,20 @@ static auto typeWithNameIn(const std::vector<StringRef> &Names) {
hasCanonicalType(hasDeclaration(namedDecl(hasAnyName(Names)))));
}
+static auto functionWithNameIn(const std::vector<StringRef> &Names) {
+ auto Call = callExpr(callee(functionDecl(hasAnyName(Names))));
+ return anyOf(expr(cxxBindTemporaryExpr(has(Call))), expr(Call));
+}
+
CoroutineHostileRAIICheck::CoroutineHostileRAIICheck(StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
RAIITypesList(utils::options::parseStringList(
Options.get("RAIITypesList", "std::lock_guard;std::scoped_lock"))),
AllowedAwaitablesList(utils::options::parseStringList(
- Options.get("AllowedAwaitablesList", ""))) {}
+ Options.get("AllowedAwaitablesList", ""))),
+ AllowedCallees(
+ utils::options::parseStringList(Options.get("AllowedCallees", ""))) {}
void CoroutineHostileRAIICheck::registerMatchers(MatchFinder *Finder) {
// A suspension happens with co_await or co_yield.
@@ -81,7 +88,8 @@ void CoroutineHostileRAIICheck::registerMatchers(MatchFinder *Finder) {
hasAttr(attr::Kind::ScopedLockable)))))
.bind("scoped-lockable");
auto OtherRAII = varDecl(typeWithNameIn(RAIITypesList)).bind("raii");
- auto AllowedSuspend = awaitable(typeWithNameIn(AllowedAwaitablesList));
+ auto AllowedSuspend = awaitable(anyOf(typeWithNameIn(AllowedAwaitablesList),
+ functionWithNameIn(AllowedCallees)));
Finder->addMatcher(
expr(anyOf(coawaitExpr(unless(AllowedSuspend)), coyieldExpr()),
forEachPrevStmt(
@@ -109,7 +117,9 @@ void CoroutineHostileRAIICheck::storeOptions(
ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "RAIITypesList",
utils::options::serializeStringList(RAIITypesList));
- Options.store(Opts, "SafeAwaitableList",
+ Options.store(Opts, "AllowedAwaitablesList",
utils::options::serializeStringList(AllowedAwaitablesList));
+ Options.store(Opts, "AllowedCallees",
+ utils::options::serializeStringList(AllowedCallees));
}
} // namespace clang::tidy::misc
diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.h b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.h
index e100509..12ad1b1 100644
--- a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.h
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_COROUTINESHOSTILERAIICHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_COROUTINESHOSTILERAIICHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_COROUTINEHOSTILERAIICHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_COROUTINEHOSTILERAIICHECK_H
#include "../ClangTidyCheck.h"
#include "clang/AST/ASTTypeTraits.h"
@@ -46,8 +46,11 @@ private:
// List of fully qualified awaitable types which are considered safe to
// co_await.
std::vector<StringRef> AllowedAwaitablesList;
+ // List of callees whose return values are considered safe to directly
+ // co_await.
+ std::vector<StringRef> AllowedCallees;
};
} // namespace clang::tidy::misc
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_COROUTINESHOSTILERAIICHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_COROUTINEHOSTILERAIICHECK_H
diff --git a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
index 714af11..c10ee1d 100644
--- a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -93,7 +93,8 @@ void DefinitionsInHeadersCheck::check(const MatchFinder::MatchResult &Result) {
}
}
- bool IsFullSpec = FD->getTemplateSpecializationKind() != TSK_Undeclared;
+ const bool IsFullSpec =
+ FD->getTemplateSpecializationKind() != TSK_Undeclared;
diag(FD->getLocation(),
"%select{function|full function template specialization}0 %1 defined "
"in a header file; function definitions in header files can lead to "
diff --git a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h
index 0c162cc..e52fa20 100644
--- a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_DEFINITIONS_IN_HEADERS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_DEFINITIONS_IN_HEADERS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_DEFINITIONSINHEADERSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_DEFINITIONSINHEADERSCHECK_H
#include "../ClangTidyCheck.h"
#include "../utils/FileExtensionsUtils.h"
@@ -38,4 +38,4 @@ private:
} // namespace clang::tidy::misc
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_DEFINITIONS_IN_HEADERS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_DEFINITIONSINHEADERSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
index 1a5aa4b..558c368 100644
--- a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
@@ -200,7 +200,7 @@ void IncludeCleanerCheck::check(const MatchFinder::MatchResult &Result) {
Unused.push_back(&I);
}
- llvm::StringRef Code = SM->getBufferData(SM->getMainFileID());
+ const llvm::StringRef Code = SM->getBufferData(SM->getMainFileID());
auto FileStyle =
format::getStyle(format::DefaultFormatStyle, getCurrentMainFile(),
format::DefaultFallbackStyle, Code,
@@ -220,14 +220,14 @@ void IncludeCleanerCheck::check(const MatchFinder::MatchResult &Result) {
}
if (MissingIncludes) {
- tooling::HeaderIncludes HeaderIncludes(getCurrentMainFile(), Code,
- FileStyle->IncludeStyle);
+ const tooling::HeaderIncludes HeaderIncludes(getCurrentMainFile(), Code,
+ FileStyle->IncludeStyle);
// Deduplicate insertions when running in bulk fix mode.
llvm::StringSet<> InsertedHeaders{};
for (const auto &Inc : Missing) {
- std::string Spelling = include_cleaner::spellHeader(
+ const std::string Spelling = include_cleaner::spellHeader(
{Inc.Missing, PP->getHeaderSearchInfo(), MainFile});
- bool Angled = llvm::StringRef{Spelling}.starts_with("<");
+ const bool Angled = llvm::StringRef{Spelling}.starts_with("<");
// We might suggest insertion of an existing include in edge cases, e.g.,
// include is present in a PP-disabled region, or spelling of the header
// turns out to be the same as one of the unresolved includes in the
@@ -235,7 +235,7 @@ void IncludeCleanerCheck::check(const MatchFinder::MatchResult &Result) {
if (auto Replacement = HeaderIncludes.insert(
llvm::StringRef{Spelling}.trim("\"<>"), Angled,
tooling::IncludeDirective::Include)) {
- DiagnosticBuilder DB =
+ const DiagnosticBuilder DB =
diag(SM->getSpellingLoc(Inc.SymRef.RefLocation),
"no header providing \"%0\" is directly included")
<< Inc.SymRef.Target.name();
diff --git a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h
index 43e1ed8..619d819 100644
--- a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_INCLUDECLEANER_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_INCLUDECLEANER_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_INCLUDECLEANERCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_INCLUDECLEANERCHECK_H
#include "../ClangTidyCheck.h"
#include "../ClangTidyDiagnosticConsumer.h"
@@ -57,4 +57,4 @@ private:
} // namespace clang::tidy::misc
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_INCLUDECLEANER_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_INCLUDECLEANERCHECK_H
diff --git a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
index 6f4af6c..03f2577 100644
--- a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
@@ -15,14 +15,15 @@
#include "DefinitionsInHeadersCheck.h"
#include "HeaderIncludeCycleCheck.h"
#include "IncludeCleanerCheck.h"
-#include "MisleadingBidirectional.h"
-#include "MisleadingIdentifier.h"
+#include "MisleadingBidirectionalCheck.h"
+#include "MisleadingIdentifierCheck.h"
#include "MisplacedConstCheck.h"
#include "NewDeleteOverloadsCheck.h"
#include "NoRecursionCheck.h"
-#include "NonCopyableObjects.h"
+#include "NonCopyableObjectsCheck.h"
#include "NonPrivateMemberVariablesInClassesCheck.h"
#include "OverrideWithDifferentVisibilityCheck.h"
+#include "PredictableRandCheck.h"
#include "RedundantExpressionCheck.h"
#include "StaticAssertCheck.h"
#include "ThrowByValueCatchByReferenceCheck.h"
@@ -63,6 +64,9 @@ public:
"misc-non-copyable-objects");
CheckFactories.registerCheck<NonPrivateMemberVariablesInClassesCheck>(
"misc-non-private-member-variables-in-classes");
+ CheckFactories.registerCheck<OverrideWithDifferentVisibilityCheck>(
+ "misc-override-with-different-visibility");
+ CheckFactories.registerCheck<PredictableRandCheck>("misc-predictable-rand");
CheckFactories.registerCheck<RedundantExpressionCheck>(
"misc-redundant-expression");
CheckFactories.registerCheck<StaticAssertCheck>("misc-static-assert");
@@ -82,8 +86,6 @@ public:
"misc-use-anonymous-namespace");
CheckFactories.registerCheck<UseInternalLinkageCheck>(
"misc-use-internal-linkage");
- CheckFactories.registerCheck<OverrideWithDifferentVisibilityCheck>(
- "misc-override-with-different-visibility");
}
};
diff --git a/clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp b/clang-tools-extra/clang-tidy/misc/MisleadingBidirectionalCheck.cpp
index f89c539..8a10f70 100644
--- a/clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
+++ b/clang-tools-extra/clang-tidy/misc/MisleadingBidirectionalCheck.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "MisleadingBidirectional.h"
+#include "MisleadingBidirectionalCheck.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Lex/Preprocessor.h"
@@ -40,20 +40,21 @@ static bool containsMisleadingBidi(StringRef Buffer,
//
// Warn if we end up with an unclosed context.
while (CurPtr < Buffer.end()) {
- unsigned char C = *CurPtr;
+ const unsigned char C = *CurPtr;
if (isASCII(C)) {
++CurPtr;
- bool IsParagrapSep =
+ const bool IsParagrapSep =
(C == 0xA || C == 0xD || (0x1C <= C && C <= 0x1E) || C == 0x85);
- bool IsSegmentSep = (C == 0x9 || C == 0xB || C == 0x1F);
+ const bool IsSegmentSep = (C == 0x9 || C == 0xB || C == 0x1F);
if (IsParagrapSep || IsSegmentSep)
BidiContexts.clear();
continue;
}
llvm::UTF32 CodePoint = 0;
- llvm::ConversionResult Result = llvm::convertUTF8Sequence(
- (const llvm::UTF8 **)&CurPtr, (const llvm::UTF8 *)Buffer.end(),
- &CodePoint, llvm::strictConversion);
+ const llvm::ConversionResult Result = llvm::convertUTF8Sequence(
+ reinterpret_cast<const llvm::UTF8 **>(&CurPtr),
+ reinterpret_cast<const llvm::UTF8 *>(Buffer.end()), &CodePoint,
+ llvm::strictConversion);
// If conversion fails, utf-8 is designed so that we can just try next char.
if (Result != llvm::conversionOK) {
@@ -94,7 +95,7 @@ public:
bool HandleComment(Preprocessor &PP, SourceRange Range) override {
// FIXME: check that we are in a /* */ comment
- StringRef Text =
+ const StringRef Text =
Lexer::getSourceText(CharSourceRange::getCharRange(Range),
PP.getSourceManager(), PP.getLangOpts());
@@ -124,7 +125,7 @@ void MisleadingBidirectionalCheck::registerPPCallbacks(
void MisleadingBidirectionalCheck::check(
const ast_matchers::MatchFinder::MatchResult &Result) {
if (const auto *SL = Result.Nodes.getNodeAs<StringLiteral>("strlit")) {
- StringRef Literal = SL->getBytes();
+ const StringRef Literal = SL->getBytes();
if (containsMisleadingBidi(Literal, false))
diag(SL->getBeginLoc(), "string literal contains misleading "
"bidirectional Unicode characters");
diff --git a/clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.h b/clang-tools-extra/clang-tidy/misc/MisleadingBidirectionalCheck.h
index ba895b9..7c7577f 100644
--- a/clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.h
+++ b/clang-tools-extra/clang-tidy/misc/MisleadingBidirectionalCheck.h
@@ -13,6 +13,10 @@
namespace clang::tidy::misc {
+/// Warns about unterminated bidirectional unicode sequence.
+///
+/// For the user-facing documentation see:
+/// https://clang.llvm.org/extra/clang-tidy/checks/misc/misleading-bidirectional.html
class MisleadingBidirectionalCheck : public ClangTidyCheck {
public:
MisleadingBidirectionalCheck(StringRef Name, ClangTidyContext *Context);
diff --git a/clang-tools-extra/clang-tidy/misc/MisleadingIdentifier.cpp b/clang-tools-extra/clang-tidy/misc/MisleadingIdentifierCheck.cpp
index ce04fb6..9c0de87 100644
--- a/clang-tools-extra/clang-tidy/misc/MisleadingIdentifier.cpp
+++ b/clang-tools-extra/clang-tidy/misc/MisleadingIdentifierCheck.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "MisleadingIdentifier.h"
+#include "MisleadingIdentifierCheck.h"
#include "llvm/Support/ConvertUTF.h"
@@ -124,8 +124,9 @@ static bool hasRTLCharacters(StringRef Buffer) {
const char *EndPtr = Buffer.end();
while (CurPtr < EndPtr) {
llvm::UTF32 CodePoint = 0;
- llvm::ConversionResult Result = llvm::convertUTF8Sequence(
- (const llvm::UTF8 **)&CurPtr, (const llvm::UTF8 *)EndPtr, &CodePoint,
+ const llvm::ConversionResult Result = llvm::convertUTF8Sequence(
+ reinterpret_cast<const llvm::UTF8 **>(&CurPtr),
+ reinterpret_cast<const llvm::UTF8 *>(EndPtr), &CodePoint,
llvm::strictConversion);
if (Result != llvm::conversionOK)
break;
@@ -144,9 +145,9 @@ MisleadingIdentifierCheck::~MisleadingIdentifierCheck() = default;
void MisleadingIdentifierCheck::check(
const ast_matchers::MatchFinder::MatchResult &Result) {
if (const auto *ND = Result.Nodes.getNodeAs<NamedDecl>("nameddecl")) {
- IdentifierInfo *II = ND->getIdentifier();
+ const IdentifierInfo *II = ND->getIdentifier();
if (II) {
- StringRef NDName = II->getName();
+ const StringRef NDName = II->getName();
if (hasRTLCharacters(NDName))
diag(ND->getBeginLoc(), "identifier has right-to-left codepoints");
}
diff --git a/clang-tools-extra/clang-tidy/misc/MisleadingIdentifier.h b/clang-tools-extra/clang-tidy/misc/MisleadingIdentifierCheck.h
index 06b83d56..9f8eb40 100644
--- a/clang-tools-extra/clang-tidy/misc/MisleadingIdentifier.h
+++ b/clang-tools-extra/clang-tidy/misc/MisleadingIdentifierCheck.h
@@ -13,6 +13,12 @@
namespace clang::tidy::misc {
+/// Finds identifiers that contain Unicode characters with right-to-left
+/// direction, which can be confusing as they may change the understanding of a
+/// whole statement line.
+///
+/// For the user-facing documentation see:
+/// https://clang.llvm.org/extra/clang-tidy/checks/misc/misleading-identifier.html
class MisleadingIdentifierCheck : public ClangTidyCheck {
public:
MisleadingIdentifierCheck(StringRef Name, ClangTidyContext *Context);
diff --git a/clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp b/clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp
index afa59f3..c8c0cfd 100644
--- a/clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp
@@ -40,7 +40,7 @@ static QualType guessAlternateQualification(ASTContext &Context, QualType QT) {
Qualifiers Quals = QT.getLocalQualifiers();
Quals.removeConst();
- QualType NewQT = Context.getPointerType(
+ const QualType NewQT = Context.getPointerType(
QualType(QT->getPointeeType().getTypePtr(), Qualifiers::Const));
return NewQT.withCVRQualifiers(Quals.getCVRQualifiers());
}
@@ -48,7 +48,7 @@ static QualType guessAlternateQualification(ASTContext &Context, QualType QT) {
void MisplacedConstCheck::check(const MatchFinder::MatchResult &Result) {
const auto *Var = Result.Nodes.getNodeAs<ValueDecl>("decl");
ASTContext &Ctx = *Result.Context;
- QualType CanQT = Var->getType().getCanonicalType();
+ const QualType CanQT = Var->getType().getCanonicalType();
SourceLocation AliasLoc;
const char *AliasType = nullptr;
diff --git a/clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.h b/clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.h
index 2b8a05d..5f5a4cfd 100644
--- a/clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MISPLACED_CONST_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MISPLACED_CONST_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MISPLACEDCONSTCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MISPLACEDCONSTCHECK_H
#include "../ClangTidyCheck.h"
@@ -28,4 +28,4 @@ public:
} // namespace clang::tidy::misc
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MISPLACED_CONST_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MISPLACEDCONSTCHECK_H
diff --git a/clang-tools-extra/clang-tidy/misc/NewDeleteOverloadsCheck.cpp b/clang-tools-extra/clang-tidy/misc/NewDeleteOverloadsCheck.cpp
index 9801c9e..0471ba8 100644
--- a/clang-tools-extra/clang-tidy/misc/NewDeleteOverloadsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/NewDeleteOverloadsCheck.cpp
@@ -51,7 +51,7 @@ AST_MATCHER(FunctionDecl, isPlacementOverload) {
return true;
const auto *FPT = Node.getType()->castAs<FunctionProtoType>();
- ASTContext &Ctx = Node.getASTContext();
+ const ASTContext &Ctx = Node.getASTContext();
if (Ctx.getLangOpts().SizedDeallocation &&
ASTContext::hasSameType(FPT->getParamType(1), Ctx.getSizeType()))
return false;
@@ -114,17 +114,15 @@ hasCorrespondingOverloadInBaseClass(const CXXMethodDecl *MD,
RD = MD->getParent();
}
- for (const auto &BS : RD->bases()) {
+ return llvm::any_of(RD->bases(), [&](const CXXBaseSpecifier &BS) {
// We can't say much about a dependent base class, but to avoid false
// positives assume it can have a corresponding overload.
if (BS.getType()->isDependentType())
return true;
- if (const auto *BaseRD = BS.getType()->getAsCXXRecordDecl())
- if (hasCorrespondingOverloadInBaseClass(MD, BaseRD))
- return true;
- }
-
- return false;
+ if (const CXXRecordDecl *BaseRD = BS.getType()->getAsCXXRecordDecl())
+ return hasCorrespondingOverloadInBaseClass(MD, BaseRD);
+ return false;
+ });
}
void NewDeleteOverloadsCheck::registerMatchers(MatchFinder *Finder) {
diff --git a/clang-tools-extra/clang-tidy/misc/NewDeleteOverloadsCheck.h b/clang-tools-extra/clang-tidy/misc/NewDeleteOverloadsCheck.h
index 93c39fc..9c7aff0 100644
--- a/clang-tools-extra/clang-tidy/misc/NewDeleteOverloadsCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/NewDeleteOverloadsCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NEWDELETEOVERLOADS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NEWDELETEOVERLOADS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NEWDELETEOVERLOADSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NEWDELETEOVERLOADSCHECK_H
#include "../ClangTidyCheck.h"
#include "llvm/ADT/SmallVector.h"
@@ -33,4 +33,4 @@ public:
} // namespace clang::tidy::misc
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NEWDELETEOVERLOADS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NEWDELETEOVERLOADSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp b/clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp
index 035598d..8bcbb61 100644
--- a/clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp
@@ -122,7 +122,7 @@ private:
}
// Set time!
// Note that this must be after `populateSet()` might have been called.
- bool SetInsertionSucceeded = Set.insert(V).second;
+ const bool SetInsertionSucceeded = Set.insert(V).second;
(void)SetInsertionSucceeded;
assert(SetInsertionSucceeded && "We did check that no such value existed");
return true;
@@ -132,7 +132,7 @@ public:
/// Insert a new element into the SmartSmallSetVector.
/// \returns true if the element was inserted into the SmartSmallSetVector.
bool insert(const T &X) {
- bool Result = setInsert(X);
+ const bool Result = setInsert(X);
if (Result)
Vector.push_back(X);
return Result;
@@ -200,8 +200,8 @@ void NoRecursionCheck::handleSCC(ArrayRef<CallGraphNode *> SCC) {
assert(!SCC.empty() && "Empty SCC does not make sense.");
// First of all, call out every strongly connected function.
- for (CallGraphNode *N : SCC) {
- FunctionDecl *D = N->getDefinition();
+ for (const CallGraphNode *N : SCC) {
+ const FunctionDecl *D = N->getDefinition();
diag(D->getLocation(), "function %0 is within a recursive call chain") << D;
}
@@ -224,7 +224,8 @@ void NoRecursionCheck::handleSCC(ArrayRef<CallGraphNode *> SCC) {
assert(CyclicCallStack.size() >= 2 && "Cycle requires at least 2 frames");
// Which function we decided to be the entry point that lead to the recursion?
- FunctionDecl *CycleEntryFn = CyclicCallStack.front().Callee->getDefinition();
+ const FunctionDecl *CycleEntryFn =
+ CyclicCallStack.front().Callee->getDefinition();
// And now, for ease of understanding, let's print the call sequence that
// forms the cycle in question.
diag(CycleEntryFn->getLocation(),
@@ -233,8 +234,8 @@ void NoRecursionCheck::handleSCC(ArrayRef<CallGraphNode *> SCC) {
<< CycleEntryFn;
for (int CurFrame = 1, NumFrames = CyclicCallStack.size();
CurFrame != NumFrames; ++CurFrame) {
- CallGraphNode::CallRecord PrevNode = CyclicCallStack[CurFrame - 1];
- CallGraphNode::CallRecord CurrNode = CyclicCallStack[CurFrame];
+ const CallGraphNode::CallRecord PrevNode = CyclicCallStack[CurFrame - 1];
+ const CallGraphNode::CallRecord CurrNode = CyclicCallStack[CurFrame];
Decl *PrevDecl = PrevNode.Callee->getDecl();
Decl *CurrDecl = CurrNode.Callee->getDecl();
diff --git a/clang-tools-extra/clang-tidy/misc/NonCopyableObjects.cpp b/clang-tools-extra/clang-tidy/misc/NonCopyableObjectsCheck.cpp
index b33e266..bfeb5fa 100644
--- a/clang-tools-extra/clang-tidy/misc/NonCopyableObjects.cpp
+++ b/clang-tools-extra/clang-tidy/misc/NonCopyableObjectsCheck.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "NonCopyableObjects.h"
+#include "NonCopyableObjectsCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
diff --git a/clang-tools-extra/clang-tidy/misc/NonCopyableObjects.h b/clang-tools-extra/clang-tidy/misc/NonCopyableObjectsCheck.h
index 2fcbf41..608e078 100644
--- a/clang-tools-extra/clang-tidy/misc/NonCopyableObjects.h
+++ b/clang-tools-extra/clang-tidy/misc/NonCopyableObjectsCheck.h
@@ -6,15 +6,18 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NONCOPYABLEOBJECTS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NONCOPYABLEOBJECTS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NONCOPYABLEOBJECTSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NONCOPYABLEOBJECTSCHECK_H
#include "../ClangTidyCheck.h"
namespace clang::tidy::misc {
-/// The check flags dereferences and non-pointer declarations of objects that
+/// Flags dereferences and non-pointer declarations of objects that
/// are not meant to be passed by value, such as C FILE objects.
+///
+/// For the user-facing documentation see:
+/// https://clang.llvm.org/extra/clang-tidy/checks/misc/non-copyable-objects.html
class NonCopyableObjectsCheck : public ClangTidyCheck {
public:
NonCopyableObjectsCheck(StringRef Name, ClangTidyContext *Context)
@@ -25,4 +28,4 @@ public:
} // namespace clang::tidy::misc
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NONCOPYABLEOBJECTS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NONCOPYABLEOBJECTSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/cert/LimitedRandomnessCheck.cpp b/clang-tools-extra/clang-tidy/misc/PredictableRandCheck.cpp
index 4fe9c6c..eed80e0 100644
--- a/clang-tools-extra/clang-tidy/cert/LimitedRandomnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/PredictableRandCheck.cpp
@@ -6,22 +6,22 @@
//
//===----------------------------------------------------------------------===//
-#include "LimitedRandomnessCheck.h"
+#include "PredictableRandCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
using namespace clang::ast_matchers;
-namespace clang::tidy::cert {
+namespace clang::tidy::misc {
-void LimitedRandomnessCheck::registerMatchers(MatchFinder *Finder) {
+void PredictableRandCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(callExpr(callee(functionDecl(namedDecl(hasName("::rand")),
parameterCountIs(0))))
.bind("randomGenerator"),
this);
}
-void LimitedRandomnessCheck::check(const MatchFinder::MatchResult &Result) {
+void PredictableRandCheck::check(const MatchFinder::MatchResult &Result) {
std::string Msg;
if (getLangOpts().CPlusPlus)
Msg = "; use C++11 random library instead";
@@ -30,4 +30,4 @@ void LimitedRandomnessCheck::check(const MatchFinder::MatchResult &Result) {
diag(MatchedDecl->getBeginLoc(), "rand() has limited randomness" + Msg);
}
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::misc
diff --git a/clang-tools-extra/clang-tidy/cert/LimitedRandomnessCheck.h b/clang-tools-extra/clang-tidy/misc/PredictableRandCheck.h
index a9d6076..2237e7e 100644
--- a/clang-tools-extra/clang-tidy/cert/LimitedRandomnessCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/PredictableRandCheck.h
@@ -6,12 +6,12 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_LIMITED_RANDOMNESS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_LIMITED_RANDOMNESS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_PREDICTABLERANDCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_PREDICTABLERANDCHECK_H
#include "../ClangTidyCheck.h"
-namespace clang::tidy::cert {
+namespace clang::tidy::misc {
/// Pseudorandom number generators are not genuinely random. The result of the
/// std::rand() function makes no guarantees as to the quality of the random
@@ -19,15 +19,15 @@ namespace clang::tidy::cert {
/// This check warns for the usage of std::rand() function.
///
/// For the user-facing documentation see:
-/// https://clang.llvm.org/extra/clang-tidy/checks/cert/msc50-cpp.html
-class LimitedRandomnessCheck : public ClangTidyCheck {
+/// https://clang.llvm.org/extra/clang-tidy/checks/misc/predictable-rand.html
+class PredictableRandCheck : public ClangTidyCheck {
public:
- LimitedRandomnessCheck(StringRef Name, ClangTidyContext *Context)
+ PredictableRandCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::misc
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_LIMITED_RANDOMNESS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_PREDICTABLERANDCHECK_H
diff --git a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
index 6baa12a..2b63dab 100644
--- a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -77,8 +77,8 @@ static bool areEquivalentExpr(const Expr *Left, const Expr *Right) {
return cast<CharacterLiteral>(Left)->getValue() ==
cast<CharacterLiteral>(Right)->getValue();
case Stmt::IntegerLiteralClass: {
- llvm::APInt LeftLit = cast<IntegerLiteral>(Left)->getValue();
- llvm::APInt RightLit = cast<IntegerLiteral>(Right)->getValue();
+ const llvm::APInt LeftLit = cast<IntegerLiteral>(Left)->getValue();
+ const llvm::APInt RightLit = cast<IntegerLiteral>(Right)->getValue();
return LeftLit.getBitWidth() == RightLit.getBitWidth() &&
LeftLit == RightLit;
}
@@ -256,7 +256,7 @@ static bool rangeSubsumesRange(BinaryOperatorKind OpcodeLHS,
const APSInt &ValueLHS,
BinaryOperatorKind OpcodeRHS,
const APSInt &ValueRHS) {
- int Comparison = APSInt::compareValues(ValueLHS, ValueRHS);
+ const int Comparison = APSInt::compareValues(ValueLHS, ValueRHS);
switch (OpcodeLHS) {
case BO_EQ:
return OpcodeRHS == BO_EQ && Comparison == 0;
@@ -352,11 +352,11 @@ static bool hasSameOperatorParent(const Expr *TheExpr,
ASTContext &Context) {
// IgnoreParenImpCasts logic in reverse: skip surrounding uninteresting nodes
const DynTypedNodeList Parents = Context.getParents(*TheExpr);
- for (DynTypedNode DynParent : Parents) {
+ for (const DynTypedNode DynParent : Parents) {
if (const auto *Parent = DynParent.get<Expr>()) {
- bool Skip = isa<ParenExpr>(Parent) || isa<ImplicitCastExpr>(Parent) ||
- isa<FullExpr>(Parent) ||
- isa<MaterializeTemporaryExpr>(Parent);
+ const bool Skip =
+ isa<ParenExpr>(Parent) || isa<ImplicitCastExpr>(Parent) ||
+ isa<FullExpr>(Parent) || isa<MaterializeTemporaryExpr>(Parent);
if (Skip && hasSameOperatorParent<TExpr>(Parent, OpKind, Context))
return true;
if (checkOpKind<TExpr>(Parent, OpKind))
@@ -392,7 +392,7 @@ markDuplicateOperands(const TExpr *TheExpr,
return false;
if (collectOperands<TExpr>(Operands.second, AllOperands, OpKind))
return false;
- size_t NumOperands = AllOperands.size();
+ const size_t NumOperands = AllOperands.size();
llvm::SmallBitVector Duplicates(NumOperands);
for (size_t I = 0; I < NumOperands; I++) {
if (Duplicates[I])
@@ -463,7 +463,7 @@ AST_MATCHER_P(Expr, expandedByMacro, ArrayRef<llvm::StringLiteral>, Names) {
const LangOptions &LO = Finder->getASTContext().getLangOpts();
SourceLocation Loc = Node.getExprLoc();
while (Loc.isMacroID()) {
- StringRef MacroName = Lexer::getImmediateMacroName(Loc, SM, LO);
+ const StringRef MacroName = Lexer::getImmediateMacroName(Loc, SM, LO);
if (llvm::is_contained(Names, MacroName))
return true;
Loc = SM.getImmediateMacroCallerLoc(Loc);
@@ -476,7 +476,7 @@ AST_MATCHER_P(Expr, expandedByMacro, ArrayRef<llvm::StringLiteral>, Names) {
// Returns a matcher for integer constant expressions.
static ast_matchers::internal::Matcher<Expr>
matchIntegerConstantExpr(StringRef Id) {
- std::string CstId = (Id + "-const").str();
+ const std::string CstId = (Id + "-const").str();
return expr(isIntegerConstantExpr()).bind(CstId);
}
@@ -486,7 +486,7 @@ matchIntegerConstantExpr(StringRef Id) {
static bool retrieveIntegerConstantExpr(const MatchFinder::MatchResult &Result,
StringRef Id, APSInt &Value,
const Expr *&ConstExpr) {
- std::string CstId = (Id + "-const").str();
+ const std::string CstId = (Id + "-const").str();
ConstExpr = Result.Nodes.getNodeAs<Expr>(CstId);
if (!ConstExpr)
return false;
@@ -508,7 +508,7 @@ static bool retrieveIntegerConstantExpr(const MatchFinder::MatchResult &Result,
// Returns a matcher for symbolic expressions (matches every expression except
// ingeter constant expressions).
static ast_matchers::internal::Matcher<Expr> matchSymbolicExpr(StringRef Id) {
- std::string SymId = (Id + "-sym").str();
+ const std::string SymId = (Id + "-sym").str();
return ignoringParenImpCasts(
expr(unless(isIntegerConstantExpr())).bind(SymId));
}
@@ -517,7 +517,7 @@ static ast_matchers::internal::Matcher<Expr> matchSymbolicExpr(StringRef Id) {
// stores it into 'SymExpr'.
static bool retrieveSymbolicExpr(const MatchFinder::MatchResult &Result,
StringRef Id, const Expr *&SymExpr) {
- std::string SymId = (Id + "-sym").str();
+ const std::string SymId = (Id + "-sym").str();
if (const auto *Node = Result.Nodes.getNodeAs<Expr>(SymId)) {
SymExpr = Node;
return true;
@@ -557,11 +557,11 @@ retrieveBinOpIntegerConstantExpr(const MatchFinder::MatchResult &Result,
// Matches relational expressions: 'Expr <op> k' (i.e. x < 2, x != 3, 12 <= x).
static ast_matchers::internal::Matcher<Expr>
matchRelationalIntegerConstantExpr(StringRef Id) {
- std::string CastId = (Id + "-cast").str();
- std::string SwapId = (Id + "-swap").str();
- std::string NegateId = (Id + "-negate").str();
- std::string OverloadId = (Id + "-overload").str();
- std::string ConstId = (Id + "-const").str();
+ const std::string CastId = (Id + "-cast").str();
+ const std::string SwapId = (Id + "-swap").str();
+ const std::string NegateId = (Id + "-negate").str();
+ const std::string OverloadId = (Id + "-overload").str();
+ const std::string ConstId = (Id + "-const").str();
const auto RelationalExpr = ignoringParenImpCasts(binaryOperator(
isComparisonOperator(), expr().bind(Id),
@@ -625,7 +625,7 @@ canOverloadedOperatorArgsBeModified(const CXXOperatorCallExpr *OperatorCall,
if (!OperatorDecl)
return true;
- unsigned ParamCount = OperatorDecl->getNumParams();
+ const unsigned ParamCount = OperatorDecl->getNumParams();
// Overloaded operators declared inside a class have only one param.
// These functions must be declared const in order to not be able to modify
@@ -647,10 +647,10 @@ static bool retrieveRelationalIntegerConstantExpr(
const MatchFinder::MatchResult &Result, StringRef Id,
const Expr *&OperandExpr, BinaryOperatorKind &Opcode, const Expr *&Symbol,
APSInt &Value, const Expr *&ConstExpr) {
- std::string CastId = (Id + "-cast").str();
- std::string SwapId = (Id + "-swap").str();
- std::string NegateId = (Id + "-negate").str();
- std::string OverloadId = (Id + "-overload").str();
+ const std::string CastId = (Id + "-cast").str();
+ const std::string SwapId = (Id + "-swap").str();
+ const std::string NegateId = (Id + "-negate").str();
+ const std::string OverloadId = (Id + "-overload").str();
if (const auto *Bin = Result.Nodes.getNodeAs<BinaryOperator>(Id)) {
// Operand received with explicit comparator.
@@ -829,11 +829,11 @@ static bool areExprsFromDifferentMacros(const Expr *LhsExpr,
const SourceManager &SM = AstCtx->getSourceManager();
const LangOptions &LO = AstCtx->getLangOpts();
- std::pair<FileID, unsigned> LsrLocInfo =
+ const std::pair<FileID, unsigned> LsrLocInfo =
SM.getDecomposedLoc(SM.getExpansionLoc(Lsr.getBegin()));
- std::pair<FileID, unsigned> RsrLocInfo =
+ const std::pair<FileID, unsigned> RsrLocInfo =
SM.getDecomposedLoc(SM.getExpansionLoc(Rsr.getBegin()));
- llvm::MemoryBufferRef MB = SM.getBufferOrFake(LsrLocInfo.first);
+ const llvm::MemoryBufferRef MB = SM.getBufferOrFake(LsrLocInfo.first);
const char *LTokenPos = MB.getBufferStart() + LsrLocInfo.second;
const char *RTokenPos = MB.getBufferStart() + RsrLocInfo.second;
@@ -890,7 +890,6 @@ static bool areStringsSameIgnoreSpaces(const llvm::StringRef Left,
static bool areExprsSameMacroOrLiteral(const BinaryOperator *BinOp,
const ASTContext *Context) {
-
if (!BinOp)
return false;
@@ -1097,7 +1096,7 @@ void RedundantExpressionCheck::checkArithmeticExpr(
if (const auto *ComparisonOperator = Result.Nodes.getNodeAs<BinaryOperator>(
"binop-const-compare-to-sym")) {
- BinaryOperatorKind Opcode = ComparisonOperator->getOpcode();
+ const BinaryOperatorKind Opcode = ComparisonOperator->getOpcode();
if (!retrieveBinOpIntegerConstantExpr(Result, "lhs", LhsOpcode, LhsSymbol,
LhsValue) ||
!retrieveSymbolicExpr(Result, "rhs", RhsSymbol) ||
@@ -1118,7 +1117,7 @@ void RedundantExpressionCheck::checkArithmeticExpr(
} else if (const auto *ComparisonOperator =
Result.Nodes.getNodeAs<BinaryOperator>(
"binop-const-compare-to-binop-const")) {
- BinaryOperatorKind Opcode = ComparisonOperator->getOpcode();
+ const BinaryOperatorKind Opcode = ComparisonOperator->getOpcode();
if (!retrieveBinOpIntegerConstantExpr(Result, "lhs", LhsOpcode, LhsSymbol,
LhsValue) ||
@@ -1147,16 +1146,18 @@ void RedundantExpressionCheck::checkArithmeticExpr(
}
}
-static bool exprEvaluatesToZero(BinaryOperatorKind Opcode, APSInt Value) {
+static bool exprEvaluatesToZero(BinaryOperatorKind Opcode,
+ const APSInt &Value) {
return (Opcode == BO_And || Opcode == BO_AndAssign) && Value == 0;
}
static bool exprEvaluatesToBitwiseNegatedZero(BinaryOperatorKind Opcode,
- APSInt Value) {
+ const APSInt &Value) {
return (Opcode == BO_Or || Opcode == BO_OrAssign) && ~Value == 0;
}
-static bool exprEvaluatesToSymbolic(BinaryOperatorKind Opcode, APSInt Value) {
+static bool exprEvaluatesToSymbolic(BinaryOperatorKind Opcode,
+ const APSInt &Value) {
return ((Opcode == BO_Or || Opcode == BO_OrAssign) && Value == 0) ||
((Opcode == BO_And || Opcode == BO_AndAssign) && ~Value == 0);
}
@@ -1165,7 +1166,7 @@ void RedundantExpressionCheck::checkBitwiseExpr(
const MatchFinder::MatchResult &Result) {
if (const auto *ComparisonOperator = Result.Nodes.getNodeAs<BinaryOperator>(
"binop-const-compare-to-const")) {
- BinaryOperatorKind Opcode = ComparisonOperator->getOpcode();
+ const BinaryOperatorKind Opcode = ComparisonOperator->getOpcode();
APSInt LhsValue, RhsValue;
const Expr *LhsSymbol = nullptr;
@@ -1175,9 +1176,9 @@ void RedundantExpressionCheck::checkBitwiseExpr(
!retrieveIntegerConstantExpr(Result, "rhs", RhsValue))
return;
- uint64_t LhsConstant = LhsValue.getZExtValue();
- uint64_t RhsConstant = RhsValue.getZExtValue();
- SourceLocation Loc = ComparisonOperator->getOperatorLoc();
+ const uint64_t LhsConstant = LhsValue.getZExtValue();
+ const uint64_t RhsConstant = RhsValue.getZExtValue();
+ const SourceLocation Loc = ComparisonOperator->getOperatorLoc();
// Check expression: x & k1 == k2 (i.e. x & 0xFF == 0xF00)
if (LhsOpcode == BO_And && (LhsConstant & RhsConstant) != RhsConstant) {
@@ -1208,24 +1209,24 @@ void RedundantExpressionCheck::checkBitwiseExpr(
if ((Value != 0 && ~Value != 0) || Sym->getExprLoc().isMacroID())
return;
- SourceLocation Loc = IneffectiveOperator->getOperatorLoc();
+ const SourceLocation Loc = IneffectiveOperator->getOperatorLoc();
- BinaryOperatorKind Opcode = IneffectiveOperator->getOpcode();
+ const BinaryOperatorKind Opcode = IneffectiveOperator->getOpcode();
if (exprEvaluatesToZero(Opcode, Value)) {
diag(Loc, "expression always evaluates to 0");
} else if (exprEvaluatesToBitwiseNegatedZero(Opcode, Value)) {
- SourceRange ConstExprRange(ConstExpr->getBeginLoc(),
- ConstExpr->getEndLoc());
- StringRef ConstExprText = Lexer::getSourceText(
+ const SourceRange ConstExprRange(ConstExpr->getBeginLoc(),
+ ConstExpr->getEndLoc());
+ const StringRef ConstExprText = Lexer::getSourceText(
CharSourceRange::getTokenRange(ConstExprRange), *Result.SourceManager,
Result.Context->getLangOpts());
diag(Loc, "expression always evaluates to '%0'") << ConstExprText;
} else if (exprEvaluatesToSymbolic(Opcode, Value)) {
- SourceRange SymExprRange(Sym->getBeginLoc(), Sym->getEndLoc());
+ const SourceRange SymExprRange(Sym->getBeginLoc(), Sym->getEndLoc());
- StringRef ExprText = Lexer::getSourceText(
+ const StringRef ExprText = Lexer::getSourceText(
CharSourceRange::getTokenRange(SymExprRange), *Result.SourceManager,
Result.Context->getLangOpts());
@@ -1240,7 +1241,7 @@ void RedundantExpressionCheck::checkRelationalExpr(
"comparisons-of-symbol-and-const")) {
// Matched expressions are: (x <op> k1) <REL> (x <op> k2).
// E.g.: (X < 2) && (X > 4)
- BinaryOperatorKind Opcode = ComparisonOperator->getOpcode();
+ const BinaryOperatorKind Opcode = ComparisonOperator->getOpcode();
const Expr *LhsExpr = nullptr, *RhsExpr = nullptr;
const Expr *LhsSymbol = nullptr, *RhsSymbol = nullptr;
@@ -1392,7 +1393,7 @@ void RedundantExpressionCheck::check(const MatchFinder::MatchResult &Result) {
if (Call && canOverloadedOperatorArgsBeModified(Call, true))
return;
- StringRef Message =
+ const StringRef Message =
Call ? "overloaded operator has equivalent nested operands"
: "operator has equivalent nested operands";
@@ -1405,12 +1406,12 @@ void RedundantExpressionCheck::check(const MatchFinder::MatchResult &Result) {
if (const auto *NegateOperator =
Result.Nodes.getNodeAs<UnaryOperator>("logical-bitwise-confusion")) {
- SourceLocation OperatorLoc = NegateOperator->getOperatorLoc();
+ const SourceLocation OperatorLoc = NegateOperator->getOperatorLoc();
auto Diag =
diag(OperatorLoc,
"ineffective logical negation operator used; did you mean '~'?");
- SourceLocation LogicalNotLocation = OperatorLoc.getLocWithOffset(1);
+ const SourceLocation LogicalNotLocation = OperatorLoc.getLocWithOffset(1);
if (!LogicalNotLocation.isMacroID())
Diag << FixItHint::CreateReplacement(
diff --git a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.h b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.h
index 57289c39..f127007 100644
--- a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_REDUNDANT_EXPRESSION_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_REDUNDANT_EXPRESSION_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_REDUNDANTEXPRESSIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_REDUNDANTEXPRESSIONCHECK_H
#include "../ClangTidyCheck.h"
@@ -33,4 +33,4 @@ private:
} // namespace clang::tidy::misc
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_REDUNDANT_EXPRESSION_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_REDUNDANTEXPRESSIONCHECK_H
diff --git a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
index 5ac5300..ff866e9 100644
--- a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
@@ -84,12 +84,12 @@ void StaticAssertCheck::check(const MatchFinder::MatchResult &Result) {
const auto *AssertExprRoot =
Result.Nodes.getNodeAs<BinaryOperator>("assertExprRoot");
const auto *CastExpr = Result.Nodes.getNodeAs<CStyleCastExpr>("castExpr");
- SourceLocation AssertExpansionLoc = CondStmt->getBeginLoc();
+ const SourceLocation AssertExpansionLoc = CondStmt->getBeginLoc();
if (!AssertExpansionLoc.isValid() || !AssertExpansionLoc.isMacroID())
return;
- StringRef MacroName =
+ const StringRef MacroName =
Lexer::getImmediateMacroName(AssertExpansionLoc, SM, Opts);
if (MacroName != "assert" || Condition->isValueDependent() ||
@@ -99,19 +99,20 @@ void StaticAssertCheck::check(const MatchFinder::MatchResult &Result) {
// False literal is not the result of macro expansion.
if (IsAlwaysFalse && (!CastExpr || CastExpr->getType()->isPointerType())) {
- SourceLocation FalseLiteralLoc =
+ const SourceLocation FalseLiteralLoc =
SM.getImmediateSpellingLoc(IsAlwaysFalse->getExprLoc());
if (!FalseLiteralLoc.isMacroID())
return;
- StringRef FalseMacroName =
+ const StringRef FalseMacroName =
Lexer::getImmediateMacroName(FalseLiteralLoc, SM, Opts);
if (FalseMacroName.compare_insensitive("false") == 0 ||
FalseMacroName.compare_insensitive("null") == 0)
return;
}
- SourceLocation AssertLoc = SM.getImmediateMacroCallerLoc(AssertExpansionLoc);
+ const SourceLocation AssertLoc =
+ SM.getImmediateMacroCallerLoc(AssertExpansionLoc);
SmallVector<FixItHint, 4> FixItHints;
SourceLocation LastParenLoc;
diff --git a/clang-tools-extra/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.h b/clang-tools-extra/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.h
index 15c17e7..56e4c12 100644
--- a/clang-tools-extra/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_THROW_BY_VALUE_CATCH_BY_REFERENCE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_THROW_BY_VALUE_CATCH_BY_REFERENCE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_THROWBYVALUECATCHBYREFERENCECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_THROWBYVALUECATCHBYREFERENCECHECK_H
#include "../ClangTidyCheck.h"
@@ -49,4 +49,4 @@ private:
} // namespace clang::tidy::misc
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_THROW_BY_VALUE_CATCH_BY_REFERENCE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_THROWBYVALUECATCHBYREFERENCECHECK_H
diff --git a/clang-tools-extra/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
index 8a85e79..a14a559 100644
--- a/clang-tools-extra/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
@@ -18,7 +18,7 @@ namespace {
AST_MATCHER_P(CXXMethodDecl, firstParameter,
ast_matchers::internal::Matcher<ParmVarDecl>, InnerMatcher) {
- unsigned N = Node.isExplicitObjectMemberFunction() ? 1 : 0;
+ const unsigned N = Node.isExplicitObjectMemberFunction() ? 1 : 0;
return (N < Node.parameters().size() &&
InnerMatcher.matches(*Node.parameters()[N], Finder, Builder));
}
diff --git a/clang-tools-extra/clang-tidy/misc/UnconventionalAssignOperatorCheck.h b/clang-tools-extra/clang-tidy/misc/UnconventionalAssignOperatorCheck.h
index be9e7b9..941fe72 100644
--- a/clang-tools-extra/clang-tidy/misc/UnconventionalAssignOperatorCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/UnconventionalAssignOperatorCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_ASSIGNOPERATORSIGNATURECHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_ASSIGNOPERATORSIGNATURECHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNCONVENTIONALASSIGNOPERATORCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNCONVENTIONALASSIGNOPERATORCHECK_H
#include "../ClangTidyCheck.h"
@@ -37,4 +37,4 @@ public:
} // namespace clang::tidy::misc
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_ASSIGNOPERATORSIGNATURECHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNCONVENTIONALASSIGNOPERATORCHECK_H
diff --git a/clang-tools-extra/clang-tidy/misc/UnusedAliasDeclsCheck.h b/clang-tools-extra/clang-tidy/misc/UnusedAliasDeclsCheck.h
index ffe82ca..b9d85c1 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedAliasDeclsCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/UnusedAliasDeclsCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_ALIAS_DECLS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_ALIAS_DECLS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSEDALIASDECLSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSEDALIASDECLSCHECK_H
#include "../ClangTidyCheck.h"
#include "llvm/ADT/DenseMap.h"
@@ -32,4 +32,4 @@ private:
} // namespace clang::tidy::misc
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_ALIAS_DECLS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSEDALIASDECLSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
index f2189f5..9c38bb1 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
@@ -30,13 +30,10 @@ static bool isOverrideMethod(const FunctionDecl *Function) {
static bool hasAttrAfterParam(const SourceManager *SourceManager,
const ParmVarDecl *Param) {
- for (const auto *Attr : Param->attrs()) {
- if (SourceManager->isBeforeInTranslationUnit(Param->getLocation(),
- Attr->getLocation())) {
- return true;
- }
- }
- return false;
+ return llvm::any_of(Param->attrs(), [&](const Attr *Attr) {
+ return SourceManager->isBeforeInTranslationUnit(Param->getLocation(),
+ Attr->getLocation());
+ });
}
void UnusedParametersCheck::registerMatchers(MatchFinder *Finder) {
@@ -160,12 +157,11 @@ void UnusedParametersCheck::warnOnUnusedParameter(
!Result.SourceManager->isInMainFile(Function->getLocation()) ||
!Indexer->getOtherRefs(Function).empty() || isOverrideMethod(Function) ||
isLambdaCallOperator(Function)) {
-
// It is illegal to omit parameter name here in C code, so early-out.
if (!Result.Context->getLangOpts().CPlusPlus)
return;
- SourceRange RemovalRange(Param->getLocation());
+ const SourceRange RemovalRange(Param->getLocation());
// Note: We always add a space before the '/*' to not accidentally create
// a '*/*' for pointer types, which doesn't start a comment. clang-format
// will clean this up afterwards.
diff --git a/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.h b/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.h
index 877fc4d..fe2cc6e 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_PARAMETERS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_PARAMETERS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSEDPARAMETERSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSEDPARAMETERSCHECK_H
#include "../ClangTidyCheck.h"
@@ -36,4 +36,4 @@ private:
} // namespace clang::tidy::misc
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_PARAMETERS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSEDPARAMETERSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h
index 96d8d9d..986bf37 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_USING_DECLS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_USING_DECLS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSEDUSINGDECLSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSEDUSINGDECLSCHECK_H
#include "../ClangTidyCheck.h"
#include "../utils/FileExtensionsUtils.h"
@@ -56,4 +56,4 @@ private:
} // namespace clang::tidy::misc
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_USING_DECLS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSEDUSINGDECLSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp b/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
index aa0cc1e..ed36d48 100644
--- a/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
@@ -52,7 +52,8 @@ void UseAnonymousNamespaceCheck::registerMatchers(MatchFinder *Finder) {
void UseAnonymousNamespaceCheck::check(const MatchFinder::MatchResult &Result) {
if (const auto *MatchedDecl = Result.Nodes.getNodeAs<NamedDecl>("x")) {
- StringRef Type = llvm::isa<VarDecl>(MatchedDecl) ? "variable" : "function";
+ const StringRef Type =
+ llvm::isa<VarDecl>(MatchedDecl) ? "variable" : "function";
diag(MatchedDecl->getLocation(),
"%0 %1 declared 'static', move to anonymous namespace instead")
<< Type << MatchedDecl;
diff --git a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
index 415852d..bad51c60 100644
--- a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
@@ -43,12 +43,6 @@ struct OptionEnumMapping<misc::UseInternalLinkageCheck::FixModeKind> {
namespace clang::tidy::misc {
-namespace {
-
-AST_MATCHER(Decl, isFirstDecl) { return Node.isFirstDecl(); }
-
-AST_MATCHER(FunctionDecl, hasBody) { return Node.hasBody(); }
-
static bool isInMainFile(SourceLocation L, SourceManager &SM,
const FileExtensionsSet &HeaderFileExtensions) {
for (;;) {
@@ -65,6 +59,12 @@ static bool isInMainFile(SourceLocation L, SourceManager &SM,
}
}
+namespace {
+
+AST_MATCHER(Decl, isFirstDecl) { return Node.isFirstDecl(); }
+
+AST_MATCHER(FunctionDecl, hasBody) { return Node.hasBody(); }
+
AST_MATCHER_P(Decl, isAllRedeclsInMainFile, FileExtensionsSet,
HeaderFileExtensions) {
return llvm::all_of(Node.redecls(), [&](const Decl *D) {
@@ -142,7 +142,8 @@ static constexpr StringRef Message =
void UseInternalLinkageCheck::check(const MatchFinder::MatchResult &Result) {
if (const auto *FD = Result.Nodes.getNodeAs<FunctionDecl>("fn")) {
- DiagnosticBuilder DB = diag(FD->getLocation(), Message) << "function" << FD;
+ const DiagnosticBuilder DB = diag(FD->getLocation(), Message)
+ << "function" << FD;
const SourceLocation FixLoc = FD->getInnerLocStart();
if (FixLoc.isInvalid() || FixLoc.isMacroID())
return;
@@ -157,7 +158,8 @@ void UseInternalLinkageCheck::check(const MatchFinder::MatchResult &Result) {
if (getLangOpts().CPlusPlus && VD->getType().isConstQualified())
return;
- DiagnosticBuilder DB = diag(VD->getLocation(), Message) << "variable" << VD;
+ const DiagnosticBuilder DB = diag(VD->getLocation(), Message)
+ << "variable" << VD;
const SourceLocation FixLoc = VD->getInnerLocStart();
if (FixLoc.isInvalid() || FixLoc.isMacroID())
return;
diff --git a/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp b/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
index 1c0043b..7663f37 100644
--- a/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
@@ -252,14 +252,13 @@ static SmallVector<BindArgument, 4>
buildBindArguments(const MatchFinder::MatchResult &Result,
const CallableInfo &Callable) {
SmallVector<BindArgument, 4> BindArguments;
- static llvm::Regex MatchPlaceholder("^_([0-9]+)$");
+ static const llvm::Regex MatchPlaceholder("^_([0-9]+)$");
const auto *BindCall = Result.Nodes.getNodeAs<CallExpr>("bind");
// Start at index 1 as first argument to bind is the function name.
unsigned CaptureIndex = 0;
for (size_t I = 1, ArgCount = BindCall->getNumArgs(); I < ArgCount; ++I) {
-
const Expr *E = BindCall->getArg(I);
BindArgument &B = BindArguments.emplace_back();
@@ -267,7 +266,7 @@ buildBindArguments(const MatchFinder::MatchResult &Result,
if (Callable.Type == CT_MemberFunction)
--ArgIndex;
- bool IsObjectPtr = (I == 1 && Callable.Type == CT_MemberFunction);
+ const bool IsObjectPtr = (I == 1 && Callable.Type == CT_MemberFunction);
B.E = E;
B.SourceTokens = getSourceTextForExpr(Result, E);
@@ -327,7 +326,6 @@ static int findPositionOfPlaceholderUse(ArrayRef<BindArgument> Args,
static void addPlaceholderArgs(const LambdaProperties &LP,
llvm::raw_ostream &Stream,
bool PermissiveParameterList) {
-
ArrayRef<BindArgument> Args = LP.BindArguments;
const auto *MaxPlaceholderIt = llvm::max_element(
@@ -340,13 +338,13 @@ static void addPlaceholderArgs(const LambdaProperties &LP,
MaxPlaceholderIt->PlaceHolderIndex == 0))
return;
- size_t PlaceholderCount = MaxPlaceholderIt->PlaceHolderIndex;
+ const size_t PlaceholderCount = MaxPlaceholderIt->PlaceHolderIndex;
Stream << "(";
StringRef Delimiter = "";
for (size_t I = 1; I <= PlaceholderCount; ++I) {
Stream << Delimiter << "auto &&";
- int ArgIndex = findPositionOfPlaceholderUse(Args, I);
+ const int ArgIndex = findPositionOfPlaceholderUse(Args, I);
if (ArgIndex != -1 && Args[ArgIndex].IsUsed)
Stream << " " << Args[ArgIndex].UsageIdentifier;
@@ -392,7 +390,7 @@ findCandidateCallOperators(const CXXRecordDecl *RecordDecl, size_t NumArgs) {
std::vector<const FunctionDecl *> Candidates;
for (const clang::CXXMethodDecl *Method : RecordDecl->methods()) {
- OverloadedOperatorKind OOK = Method->getOverloadedOperator();
+ const OverloadedOperatorKind OOK = Method->getOverloadedOperator();
if (OOK != OverloadedOperatorKind::OO_Call)
continue;
@@ -410,7 +408,7 @@ findCandidateCallOperators(const CXXRecordDecl *RecordDecl, size_t NumArgs) {
continue;
const FunctionDecl *FD = FTD->getTemplatedDecl();
- OverloadedOperatorKind OOK = FD->getOverloadedOperator();
+ const OverloadedOperatorKind OOK = FD->getOverloadedOperator();
if (OOK != OverloadedOperatorKind::OO_Call)
continue;
@@ -465,13 +463,12 @@ static const FunctionDecl *getCallOperator(const CXXRecordDecl *Callable,
static const FunctionDecl *
getCallMethodDecl(const MatchFinder::MatchResult &Result, CallableType Type,
CallableMaterializationKind Materialization) {
-
const Expr *Callee = Result.Nodes.getNodeAs<Expr>("ref");
const Expr *CallExpression = ignoreTemporariesAndPointers(Callee);
if (Type == CT_Object) {
const auto *BindCall = Result.Nodes.getNodeAs<CallExpr>("bind");
- size_t NumArgs = BindCall->getNumArgs() - 1;
+ const size_t NumArgs = BindCall->getNumArgs() - 1;
return getCallOperator(Callee->getType()->getAsCXXRecordDecl(), NumArgs);
}
@@ -488,7 +485,7 @@ getCallMethodDecl(const MatchFinder::MatchResult &Result, CallableType Type,
static CallableType getCallableType(const MatchFinder::MatchResult &Result) {
const auto *CallableExpr = Result.Nodes.getNodeAs<Expr>("ref");
- QualType QT = CallableExpr->getType();
+ const QualType QT = CallableExpr->getType();
if (QT->isMemberFunctionPointerType())
return CT_MemberFunction;
@@ -614,7 +611,7 @@ static void emitCaptureList(const LambdaProperties &LP,
if (B.CM == CM_None || !B.IsUsed)
continue;
- StringRef Delimiter = AnyCapturesEmitted ? ", " : "";
+ const StringRef Delimiter = AnyCapturesEmitted ? ", " : "";
if (emitCapture(CaptureSet, Delimiter, B.CM, B.CE, B.CaptureIdentifier,
B.SourceTokens, Stream))
@@ -669,7 +666,7 @@ void AvoidBindCheck::check(const MatchFinder::MatchResult &Result) {
emitCaptureList(LP, Result, Stream);
Stream << "]";
- ArrayRef<BindArgument> FunctionCallArgs = ArrayRef(LP.BindArguments);
+ const ArrayRef<BindArgument> FunctionCallArgs = ArrayRef(LP.BindArguments);
addPlaceholderArgs(LP, Stream, PermissiveParameterList);
diff --git a/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.h b/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.h
index 94838cb..22e629f 100644
--- a/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_AVOID_BIND_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_AVOID_BIND_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_AVOIDBINDCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_AVOIDBINDCHECK_H
#include "../ClangTidyCheck.h"
@@ -34,4 +34,4 @@ private:
};
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_AVOID_BIND_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_AVOIDBINDCHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp b/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp
index 9290019..71d89d3 100644
--- a/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp
@@ -15,6 +15,14 @@ using namespace clang::ast_matchers;
namespace clang::tidy::modernize {
+template <typename TargetType, typename NodeType>
+static const TargetType *getAs(const NodeType *Node) {
+ if constexpr (std::is_same_v<NodeType, clang::DynTypedNode>)
+ return Node->template get<TargetType>();
+ else
+ return llvm::dyn_cast<TargetType>(Node);
+}
+
namespace {
AST_MATCHER(clang::TypeLoc, hasValidBeginLoc) {
@@ -39,14 +47,6 @@ AST_MATCHER(clang::ParmVarDecl, isArgvOfMain) {
return FD ? FD->isMain() : false;
}
-template <typename TargetType, typename NodeType>
-const TargetType *getAs(const NodeType *Node) {
- if constexpr (std::is_same_v<NodeType, clang::DynTypedNode>)
- return Node->template get<TargetType>();
- else
- return llvm::dyn_cast<TargetType>(Node);
-}
-
AST_MATCHER(clang::TypeLoc, isWithinImplicitTemplateInstantiation) {
const auto IsImplicitTemplateInstantiation = [](const auto *Node) {
const auto IsImplicitInstantiation = [](const auto *Node) {
diff --git a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp b/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.cpp
index 174ecb0..7f9bf63 100644
--- a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "AvoidCStyleCastsCheck.h"
+#include "AvoidCStyleCastCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
@@ -14,10 +14,9 @@
using namespace clang::ast_matchers;
-namespace clang::tidy::google::readability {
+namespace clang::tidy::modernize {
-void AvoidCStyleCastsCheck::registerMatchers(
- ast_matchers::MatchFinder *Finder) {
+void AvoidCStyleCastCheck::registerMatchers(ast_matchers::MatchFinder *Finder) {
Finder->addMatcher(
cStyleCastExpr(
// Filter out (EnumType)IntegerLiteral construct, which is generated
@@ -113,7 +112,7 @@ static bool sameTypeAsWritten(QualType X, QualType Y) {
}
}
-void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {
+void AvoidCStyleCastCheck::check(const MatchFinder::MatchResult &Result) {
const auto *CastExpr = Result.Nodes.getNodeAs<ExplicitCastExpr>("cast");
// Ignore casts in macros.
@@ -140,7 +139,7 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {
CharSourceRange ReplaceRange = getReplaceRange(CastExpr);
- bool FnToFnCast =
+ const bool FnToFnCast =
IsFunction(SourceTypeAsWritten) && IsFunction(DestTypeAsWritten);
const bool ConstructorCast = !CastExpr->getTypeAsWritten().hasQualifiers() &&
@@ -239,8 +238,8 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {
return;
}
if (DestType->isReferenceType()) {
- QualType Dest = DestType.getNonReferenceType();
- QualType Source = SourceType.getNonReferenceType();
+ const QualType Dest = DestType.getNonReferenceType();
+ const QualType Source = SourceType.getNonReferenceType();
if (Source == Dest.withConst() ||
SourceType.getNonReferenceType() == DestType.getNonReferenceType()) {
ReplaceWithNamedCast("const_cast");
@@ -248,6 +247,12 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {
}
break;
}
+ if (DestType->isVoidPointerType() && SourceType->isPointerType() &&
+ !SourceType->getPointeeType()->isPointerType()) {
+ ReplaceWithNamedCast("reinterpret_cast");
+ return;
+ }
+
[[fallthrough]];
case clang::CK_IntegralCast:
// Convert integral and no-op casts between builtin types and enums to
@@ -269,6 +274,12 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {
return;
}
break;
+ case CK_BaseToDerived:
+ if (!needsConstCast(SourceType, DestType)) {
+ ReplaceWithNamedCast("static_cast");
+ return;
+ }
+ break;
default:
break;
}
@@ -276,4 +287,4 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {
Diag << "static_cast/const_cast/reinterpret_cast";
}
-} // namespace clang::tidy::google::readability
+} // namespace clang::tidy::modernize
diff --git a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h b/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.h
index a305bd5..123d524 100644
--- a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.h
@@ -6,12 +6,12 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_AVOIDCSTYLECASTSCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_AVOIDCSTYLECASTSCHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_AVOIDCSTYLECASTCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_AVOIDCSTYLECASTCHECK_H
#include "../ClangTidyCheck.h"
-namespace clang::tidy::google::readability {
+namespace clang::tidy::modernize {
/// Finds usages of C-style casts.
///
@@ -24,10 +24,10 @@ namespace clang::tidy::google::readability {
/// ones generated by `-Wold-style-cast`.
///
/// For the user-facing documentation see:
-/// https://clang.llvm.org/extra/clang-tidy/checks/google/readability-casting.html
-class AvoidCStyleCastsCheck : public ClangTidyCheck {
+/// https://clang.llvm.org/extra/clang-tidy/checks/modernize/avoid-c-style-cast.html
+class AvoidCStyleCastCheck : public ClangTidyCheck {
public:
- AvoidCStyleCastsCheck(StringRef Name, ClangTidyContext *Context)
+ AvoidCStyleCastCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
@@ -36,6 +36,6 @@ public:
}
};
-} // namespace clang::tidy::google::readability
+} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_AVOIDCSTYLECASTSCHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_AVOIDCSTYLECASTCHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 882f2dc..488c359 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -6,6 +6,7 @@ set(LLVM_LINK_COMPONENTS
add_clang_library(clangTidyModernizeModule STATIC
AvoidBindCheck.cpp
AvoidCArraysCheck.cpp
+ AvoidCStyleCastCheck.cpp
AvoidSetjmpLongjmpCheck.cpp
AvoidVariadicFunctionsCheck.cpp
ConcatNestedNamespacesCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp b/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
index 6e28cb2..7c82e9e 100644
--- a/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -25,7 +25,8 @@ static bool locationsInSameFile(const SourceManager &Sources,
static StringRef getRawStringRef(const SourceRange &Range,
const SourceManager &Sources,
const LangOptions &LangOpts) {
- CharSourceRange TextRange = Lexer::getAsCharRange(Range, Sources, LangOpts);
+ const CharSourceRange TextRange =
+ Lexer::getAsCharRange(Range, Sources, LangOpts);
return Lexer::getSourceText(TextRange, Sources, LangOpts);
}
@@ -56,15 +57,16 @@ SourceRange NS::getDefaultNamespaceBackRange() const {
SourceRange NS::getNamespaceBackRange(const SourceManager &SM,
const LangOptions &LangOpts) const {
// Back from '}' to conditional '// namespace xxx'
- SourceLocation Loc = front()->getRBraceLoc();
+ const SourceLocation Loc = front()->getRBraceLoc();
std::optional<Token> Tok =
utils::lexer::findNextTokenIncludingComments(Loc, SM, LangOpts);
if (!Tok)
return getDefaultNamespaceBackRange();
if (Tok->getKind() != tok::TokenKind::comment)
return getDefaultNamespaceBackRange();
- SourceRange TokRange = SourceRange{Tok->getLocation(), Tok->getEndLoc()};
- StringRef TokText = getRawStringRef(TokRange, SM, LangOpts);
+ const SourceRange TokRange =
+ SourceRange{Tok->getLocation(), Tok->getEndLoc()};
+ const StringRef TokText = getRawStringRef(TokRange, SM, LangOpts);
NamespaceName CloseComment{"namespace "};
appendCloseComment(CloseComment);
// current fix hint in readability/NamespaceCommentCheck.cpp use single line
@@ -98,7 +100,7 @@ bool ConcatNestedNamespacesCheck::unsupportedNamespace(const NamespaceDecl &ND,
return true;
if (getLangOpts().CPlusPlus20) {
// C++20 support inline nested namespace
- bool IsFirstNS = IsChild || !Namespaces.empty();
+ const bool IsFirstNS = IsChild || !Namespaces.empty();
return ND.isInlineNamespace() && !IsFirstNS;
}
return ND.isInlineNamespace();
@@ -106,7 +108,7 @@ bool ConcatNestedNamespacesCheck::unsupportedNamespace(const NamespaceDecl &ND,
bool ConcatNestedNamespacesCheck::singleNamedNamespaceChild(
const NamespaceDecl &ND) const {
- NamespaceDecl::decl_range Decls = ND.decls();
+ const NamespaceDecl::decl_range Decls = ND.decls();
if (std::distance(Decls.begin(), Decls.end()) != 1)
return false;
@@ -121,7 +123,7 @@ void ConcatNestedNamespacesCheck::registerMatchers(
void ConcatNestedNamespacesCheck::reportDiagnostic(
const SourceManager &SM, const LangOptions &LangOpts) {
- DiagnosticBuilder DB =
+ const DiagnosticBuilder DB =
diag(Namespaces.front().front()->getBeginLoc(),
"nested namespaces can be concatenated", DiagnosticIDs::Warning);
@@ -143,7 +145,7 @@ void ConcatNestedNamespacesCheck::reportDiagnostic(
// the last one should be handled specially
Fronts.pop_back();
- SourceRange LastRBrace = Backs.pop_back_val();
+ const SourceRange LastRBrace = Backs.pop_back_val();
NamespaceName ConcatNameSpace{"namespace "};
for (const NS &NS : Namespaces) {
diff --git a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
index 1de9e13..eff7c2f 100644
--- a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
@@ -135,7 +135,6 @@ IncludeModernizePPCallbacks::IncludeModernizePPCallbacks(
const LangOptions &LangOpts, const SourceManager &SM, bool CheckHeaderFile)
: IncludesToBeProcessed(IncludesToBeProcessed), SM(SM),
CheckHeaderFile(CheckHeaderFile) {
-
static constexpr std::pair<StringRef, StringRef> CXX98Headers[] = {
{"assert.h", "cassert"}, {"complex.h", "complex"},
{"ctype.h", "cctype"}, {"errno.h", "cerrno"},
@@ -167,7 +166,6 @@ void IncludeModernizePPCallbacks::InclusionDirective(
bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
StringRef SearchPath, StringRef RelativePath, const Module *SuggestedModule,
bool ModuleImported, SrcMgr::CharacteristicKind FileType) {
-
// If we don't want to warn for non-main file reports and this is one, skip
// it.
if (!CheckHeaderFile && !SM.isInMainFile(HashLoc))
@@ -184,7 +182,7 @@ void IncludeModernizePPCallbacks::InclusionDirective(
// 1. Insert std prefix for every such symbol occurrence.
// 2. Insert `using namespace std;` to the beginning of TU.
// 3. Do nothing and let the user deal with the migration himself.
- SourceLocation DiagLoc = FilenameRange.getBegin();
+ const SourceLocation DiagLoc = FilenameRange.getBegin();
if (auto It = CStyledHeaderToCxx.find(FileName);
It != CStyledHeaderToCxx.end()) {
IncludesToBeProcessed.emplace_back(IncludeMarker{
diff --git a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.h b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.h
index badb2b4..015404e 100644
--- a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_C_HEADERS_TO_CXX_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_C_HEADERS_TO_CXX_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_DEPRECATEDHEADERSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_DEPRECATEDHEADERSCHECK_H
#include "../ClangTidyCheck.h"
@@ -57,4 +57,4 @@ private:
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_C_HEADERS_TO_CXX_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_DEPRECATEDHEADERSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp b/clang-tools-extra/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp
index 5e25437..7e43165 100644
--- a/clang-tools-extra/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp
@@ -36,10 +36,10 @@ void DeprecatedIosBaseAliasesCheck::registerMatchers(MatchFinder *Finder) {
void DeprecatedIosBaseAliasesCheck::check(
const MatchFinder::MatchResult &Result) {
- SourceManager &SM = *Result.SourceManager;
+ const SourceManager &SM = *Result.SourceManager;
const auto *Typedef = Result.Nodes.getNodeAs<TypedefDecl>("TypeDecl");
- StringRef TypeName = Typedef->getName();
+ const StringRef TypeName = Typedef->getName();
auto Replacement = getReplacementType(TypeName);
TypeLoc TL = *Result.Nodes.getNodeAs<TypeLoc>("TypeLoc");
@@ -55,7 +55,8 @@ void DeprecatedIosBaseAliasesCheck::check(
Fix = false;
}
- SourceLocation EndLoc = IoStateLoc.getLocWithOffset(TypeName.size() - 1);
+ const SourceLocation EndLoc =
+ IoStateLoc.getLocWithOffset(TypeName.size() - 1);
if (Replacement) {
const char *FixName = *Replacement;
diff --git a/clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.cpp b/clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.cpp
index 05cf51a..862ca18 100644
--- a/clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.cpp
@@ -95,7 +95,7 @@ bool IntegralLiteralExpressionMatcher::unaryOperator() {
}
static LiteralSize literalTokenSize(const Token &Tok) {
- unsigned int Length = Tok.getLength();
+ const unsigned int Length = Tok.getLength();
if (Length <= 1)
return LiteralSize::Int;
diff --git a/clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.h b/clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.h
index d495087..ce0d7c0 100644
--- a/clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.h
+++ b/clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_INTEGRAL_LITERAL_EXPRESSION_MATCHER_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_INTEGRAL_LITERAL_EXPRESSION_MATCHER_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_INTEGRALLITERALEXPRESSIONMATCHER_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_INTEGRALLITERALEXPRESSIONMATCHER_H
#include <clang/Lex/Token.h>
#include <llvm/ADT/ArrayRef.h>
@@ -73,4 +73,4 @@ private:
} // namespace clang::tidy::modernize
-#endif
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_INTEGRALLITERALEXPRESSIONMATCHER_H
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index fea5ac6..19b406f 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -92,7 +92,7 @@ static StatementMatcher incrementVarMatcher() {
}
static StatementMatcher
-arrayConditionMatcher(internal::Matcher<Expr> LimitExpr) {
+arrayConditionMatcher(const internal::Matcher<Expr> &LimitExpr) {
return binaryOperator(
anyOf(allOf(hasOperatorName("<"), hasLHS(integerComparisonMatcher()),
hasRHS(LimitExpr)),
@@ -115,7 +115,7 @@ arrayConditionMatcher(internal::Matcher<Expr> LimitExpr) {
/// - The index variable is only used as an array index.
/// - All arrays indexed by the loop are the same.
static StatementMatcher makeArrayLoopMatcher() {
- StatementMatcher ArrayBoundMatcher =
+ const StatementMatcher ArrayBoundMatcher =
expr(hasType(isInteger())).bind(ConditionBoundName);
return forStmt(unless(isInTemplateInstantiation()),
@@ -156,7 +156,6 @@ static StatementMatcher makeArrayLoopMatcher() {
/// Client code will need to make sure that:
/// - The two containers on which 'begin' and 'end' are called are the same.
static StatementMatcher makeIteratorLoopMatcher(bool IsReverse) {
-
auto BeginNameMatcher = IsReverse ? hasAnyName("rbegin", "crbegin")
: hasAnyName("begin", "cbegin");
auto BeginNameMatcherStd = IsReverse
@@ -168,7 +167,7 @@ static StatementMatcher makeIteratorLoopMatcher(bool IsReverse) {
auto EndNameMatcherStd = IsReverse ? hasAnyName("::std::rend", "::std::crend")
: hasAnyName("::std::end", "::std::cend");
- StatementMatcher BeginCallMatcher =
+ const StatementMatcher BeginCallMatcher =
expr(anyOf(cxxMemberCallExpr(argumentCountIs(0),
callee(cxxMethodDecl(BeginNameMatcher))),
callExpr(argumentCountIs(1),
@@ -177,37 +176,37 @@ static StatementMatcher makeIteratorLoopMatcher(bool IsReverse) {
callee(functionDecl(BeginNameMatcherStd)))))
.bind(BeginCallName);
- DeclarationMatcher InitDeclMatcher =
+ const DeclarationMatcher InitDeclMatcher =
varDecl(hasInitializer(anyOf(ignoringParenImpCasts(BeginCallMatcher),
materializeTemporaryExpr(
ignoringParenImpCasts(BeginCallMatcher)),
hasDescendant(BeginCallMatcher))))
.bind(InitVarName);
- DeclarationMatcher EndDeclMatcher =
+ const DeclarationMatcher EndDeclMatcher =
varDecl(hasInitializer(anything())).bind(EndVarName);
- StatementMatcher EndCallMatcher = expr(anyOf(
+ const StatementMatcher EndCallMatcher = expr(anyOf(
cxxMemberCallExpr(argumentCountIs(0),
callee(cxxMethodDecl(EndNameMatcher))),
callExpr(argumentCountIs(1), callee(functionDecl(EndNameMatcher)),
usesADL()),
callExpr(argumentCountIs(1), callee(functionDecl(EndNameMatcherStd)))));
- StatementMatcher IteratorBoundMatcher =
+ const StatementMatcher IteratorBoundMatcher =
expr(anyOf(ignoringParenImpCasts(
declRefExpr(to(varDecl(equalsBoundNode(EndVarName))))),
ignoringParenImpCasts(expr(EndCallMatcher).bind(EndCallName)),
materializeTemporaryExpr(ignoringParenImpCasts(
expr(EndCallMatcher).bind(EndCallName)))));
- StatementMatcher IteratorComparisonMatcher = expr(ignoringParenImpCasts(
+ const StatementMatcher IteratorComparisonMatcher = expr(ignoringParenImpCasts(
declRefExpr(to(varDecl(equalsBoundNode(InitVarName))))));
// This matcher tests that a declaration is a CXXRecordDecl that has an
// overloaded operator*(). If the operator*() returns by value instead of by
// reference then the return type is tagged with DerefByValueResultName.
- internal::Matcher<VarDecl> TestDerefReturnsByValue =
+ const internal::Matcher<VarDecl> TestDerefReturnsByValue =
hasType(hasUnqualifiedDesugaredType(
recordType(hasDeclaration(cxxRecordDecl(hasMethod(cxxMethodDecl(
hasOverloadedOperatorName("*"),
@@ -280,7 +279,7 @@ static StatementMatcher makePseudoArrayLoopMatcher() {
// FIXME: Also, a record doesn't necessarily need begin() and end(). Free
// functions called begin() and end() taking the container as an argument
// are also allowed.
- TypeMatcher RecordWithBeginEnd = qualType(anyOf(
+ const TypeMatcher RecordWithBeginEnd = qualType(anyOf(
qualType(isConstQualified(),
hasUnqualifiedDesugaredType(recordType(hasDeclaration(
cxxRecordDecl(isSameOrDerivedFrom(cxxRecordDecl(
@@ -295,7 +294,7 @@ static StatementMatcher makePseudoArrayLoopMatcher() {
hasMethod(hasName("end"))))))))) // qualType
));
- StatementMatcher SizeCallMatcher = expr(anyOf(
+ const StatementMatcher SizeCallMatcher = expr(anyOf(
cxxMemberCallExpr(argumentCountIs(0),
callee(cxxMethodDecl(hasAnyName("size", "length"))),
on(anyOf(hasType(pointsTo(RecordWithBeginEnd)),
@@ -310,10 +309,10 @@ static StatementMatcher makePseudoArrayLoopMatcher() {
explicitCastExpr(hasSourceExpression(ignoringParenImpCasts(
expr(SizeCallMatcher).bind(EndCallName))))));
- DeclarationMatcher EndDeclMatcher =
+ const DeclarationMatcher EndDeclMatcher =
varDecl(hasInitializer(EndInitMatcher)).bind(EndVarName);
- StatementMatcher IndexBoundMatcher =
+ const StatementMatcher IndexBoundMatcher =
expr(anyOf(ignoringParenImpCasts(
declRefExpr(to(varDecl(equalsBoundNode(EndVarName))))),
EndInitMatcher));
@@ -511,27 +510,24 @@ static bool canBeModified(ASTContext *Context, const Expr *E) {
/// Returns true when it can be guaranteed that the elements of the
/// container are not being modified.
static bool usagesAreConst(ASTContext *Context, const UsageResult &Usages) {
- for (const Usage &U : Usages) {
+ return llvm::none_of(Usages, [&Context](const Usage &U) {
// Lambda captures are just redeclarations (VarDecl) of the same variable,
// not expressions. If we want to know if a variable that is captured by
// reference can be modified in an usage inside the lambda's body, we need
// to find the expression corresponding to that particular usage, later in
// this loop.
- if (U.Kind != Usage::UK_CaptureByCopy && U.Kind != Usage::UK_CaptureByRef &&
- canBeModified(Context, U.Expression))
- return false;
- }
- return true;
+ return U.Kind != Usage::UK_CaptureByCopy &&
+ U.Kind != Usage::UK_CaptureByRef &&
+ canBeModified(Context, U.Expression);
+ });
}
/// Returns true if the elements of the container are never accessed
/// by reference.
static bool usagesReturnRValues(const UsageResult &Usages) {
- for (const auto &U : Usages) {
- if (U.Expression && !U.Expression->isPRValue())
- return false;
- }
- return true;
+ return llvm::all_of(Usages, [](const Usage &U) {
+ return !U.Expression || U.Expression->isPRValue();
+ });
}
/// Returns true if the container is const-qualified.
@@ -563,7 +559,6 @@ LoopConvertCheck::LoopConvertCheck(StringRef Name, ClangTidyContext *Context)
UseCxx20IfAvailable(Options.get("UseCxx20ReverseRanges", true)),
ReverseFunction(Options.get("MakeReverseRangeFunction", "")),
ReverseHeader(Options.get("MakeReverseRangeHeader", "")) {
-
if (ReverseFunction.empty() && !ReverseHeader.empty()) {
configurationDiag(
"modernize-loop-convert: 'MakeReverseRangeHeader' is set but "
@@ -620,7 +615,7 @@ void LoopConvertCheck::getAliasRange(SourceManager &SM, SourceRange &Range) {
SM.getCharacterData(Range.getEnd().getLocWithOffset(1), &Invalid);
if (Invalid)
return;
- unsigned Offset = std::strspn(TextAfter, " \t\r\n");
+ const unsigned Offset = std::strspn(TextAfter, " \t\r\n");
Range =
SourceRange(Range.getBegin(), Range.getEnd().getLocWithOffset(Offset));
}
@@ -633,7 +628,7 @@ void LoopConvertCheck::doConversion(
const DeclStmt *AliasDecl, bool AliasUseRequired, bool AliasFromForInit,
const ForStmt *Loop, RangeDescriptor Descriptor) {
std::string VarNameOrStructuredBinding;
- bool VarNameFromAlias = (Usages.size() == 1) && AliasDecl;
+ const bool VarNameFromAlias = (Usages.size() == 1) && AliasDecl;
bool AliasVarIsRef = false;
bool CanCopy = true;
std::vector<FixItHint> FixIts;
@@ -743,7 +738,7 @@ void LoopConvertCheck::doConversion(
}
// Now, we need to construct the new range expression.
- SourceRange ParenRange(Loop->getLParenLoc(), Loop->getRParenLoc());
+ const SourceRange ParenRange(Loop->getLParenLoc(), Loop->getRParenLoc());
QualType Type = Context->getAutoDeductType();
if (!Descriptor.ElemType.isNull() && Descriptor.ElemType->isFundamentalType())
@@ -753,14 +748,15 @@ void LoopConvertCheck::doConversion(
// If the new variable name is from the aliased variable, then the reference
// type for the new variable should only be used if the aliased variable was
// declared as a reference.
- bool IsCheapToCopy =
+ const bool IsCheapToCopy =
!Descriptor.ElemType.isNull() &&
Descriptor.ElemType.isTriviallyCopyableType(*Context) &&
!Descriptor.ElemType->isDependentSizedArrayType() &&
// TypeInfo::Width is in bits.
Context->getTypeInfo(Descriptor.ElemType).Width <= 8 * MaxCopySize;
- bool UseCopy = CanCopy && ((VarNameFromAlias && !AliasVarIsRef) ||
- (Descriptor.DerefByConstRef && IsCheapToCopy));
+ const bool UseCopy =
+ CanCopy && ((VarNameFromAlias && !AliasVarIsRef) ||
+ (Descriptor.DerefByConstRef && IsCheapToCopy));
if (!UseCopy) {
if (Descriptor.DerefByConstRef) {
@@ -866,7 +862,7 @@ void LoopConvertCheck::getIteratorLoopQualifiers(ASTContext *Context,
// The matchers for iterator loops provide bound nodes to obtain this
// information.
const auto *InitVar = Nodes.getNodeAs<VarDecl>(InitVarName);
- QualType CanonicalInitVarType = InitVar->getType().getCanonicalType();
+ const QualType CanonicalInitVarType = InitVar->getType().getCanonicalType();
const auto *DerefByValueType =
Nodes.getNodeAs<QualType>(DerefByValueResultName);
Descriptor.DerefByValue = DerefByValueType;
@@ -934,12 +930,12 @@ bool LoopConvertCheck::isConvertible(ASTContext *Context,
// FIXME: Try to put most of this logic inside a matcher.
if (FixerKind == LFK_Iterator || FixerKind == LFK_ReverseIterator) {
- QualType InitVarType = InitVar->getType();
- QualType CanonicalInitVarType = InitVarType.getCanonicalType();
+ const QualType InitVarType = InitVar->getType();
+ const QualType CanonicalInitVarType = InitVarType.getCanonicalType();
const auto *BeginCall = Nodes.getNodeAs<CallExpr>(BeginCallName);
assert(BeginCall && "Bad Callback. No begin call expression");
- QualType CanonicalBeginType =
+ const QualType CanonicalBeginType =
BeginCall->getDirectCallee()->getReturnType().getCanonicalType();
if (CanonicalBeginType->isPointerType() &&
CanonicalInitVarType->isPointerType()) {
@@ -1054,7 +1050,7 @@ void LoopConvertCheck::check(const MatchFinder::MatchResult &Result) {
}
// Find out which qualifiers we have to use in the loop range.
- TraversalKindScope RAII(*Context, TK_AsIs);
+ const TraversalKindScope RAII(*Context, TK_AsIs);
const UsageResult &Usages = Finder.getUsages();
determineRangeDescriptor(Context, Nodes, Loop, FixerKind, ContainerExpr,
Usages, Descriptor);
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.h b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.h
index 5548782..958b4eb 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOP_CONVERT_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOP_CONVERT_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOPCONVERTCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOPCONVERTCHECK_H
#include "../ClangTidyCheck.h"
#include "../utils/IncludeInserter.h"
@@ -85,4 +85,4 @@ private:
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOP_CONVERT_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOPCONVERTCHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
index 6fb7808..f6685dd 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
@@ -89,19 +89,18 @@ bool DependencyFinderASTVisitor::VisitVarDecl(VarDecl *V) {
// Next, check if the variable was removed from existence by an earlier
// iteration.
- for (const auto &I : *ReplacedVars) {
- if (I.second == V) {
- DependsOnInsideVariable = true;
- return false;
- }
- }
- return true;
+ if (llvm::none_of(*ReplacedVars,
+ [&](const auto &I) { return I.second == V; }))
+ return true;
+ DependsOnInsideVariable = true;
+ return false;
}
/// If we already created a variable for TheLoop, check to make sure
/// that the name was not already taken.
bool DeclFinderASTVisitor::VisitForStmt(ForStmt *TheLoop) {
- StmtGeneratedVarNameMap::const_iterator I = GeneratedDecls->find(TheLoop);
+ const StmtGeneratedVarNameMap::const_iterator I =
+ GeneratedDecls->find(TheLoop);
if (I != GeneratedDecls->end() && I->second == Name) {
Found = true;
return false;
@@ -131,7 +130,7 @@ bool DeclFinderASTVisitor::VisitDeclRefExpr(DeclRefExpr *DeclRef) {
/// If the new variable name conflicts with any type used in the loop,
/// then we mark that variable name as taken.
bool DeclFinderASTVisitor::VisitTypeLoc(TypeLoc TL) {
- QualType QType = TL.getType();
+ const QualType QType = TL.getType();
// Check if our name conflicts with a type, to handle for typedefs.
if (QType.getAsString() == Name) {
@@ -233,11 +232,8 @@ static bool containsExpr(ASTContext *Context, const ContainerT *Container,
const Expr *E) {
llvm::FoldingSetNodeID ID;
E->Profile(ID, *Context, true);
- for (const auto &I : *Container) {
- if (ID == I.second)
- return true;
- }
- return false;
+ return llvm::any_of(*Container,
+ [&](const auto &I) { return ID == I.second; });
}
/// Returns true when the index expression is a declaration reference to
@@ -364,7 +360,7 @@ static bool isAliasDecl(ASTContext *Context, const Decl *TheDecl,
// Check that the declared type is the same as (or a reference to) the
// container type.
if (!OnlyCasts) {
- QualType InitType = Init->getType();
+ const QualType InitType = Init->getType();
QualType DeclarationType = VDecl->getType();
if (!DeclarationType.isNull() && DeclarationType->isReferenceType())
DeclarationType = DeclarationType.getNonReferenceType();
@@ -440,7 +436,7 @@ static bool arrayMatchesBoundExpr(ASTContext *Context,
ConditionExpr->getIntegerConstantExpr(*Context);
if (!ConditionSize)
return false;
- llvm::APSInt ArraySize(ConstType->getSize());
+ const llvm::APSInt ArraySize(ConstType->getSize());
return llvm::APSInt::isSameValue(*ConditionSize, ArraySize);
}
@@ -571,7 +567,7 @@ bool ForLoopIndexUseVisitor::TraverseMemberExpr(MemberExpr *Member) {
// FIXME: This works around not having the location of the arrow operator.
// Consider adding OperatorLoc to MemberExpr?
- SourceLocation ArrowLoc = Lexer::getLocForEndOfToken(
+ const SourceLocation ArrowLoc = Lexer::getLocForEndOfToken(
Base->getExprLoc(), 0, Context->getSourceManager(),
Context->getLangOpts());
// If something complicated is happening (i.e. the next token isn't an
@@ -821,7 +817,7 @@ bool ForLoopIndexUseVisitor::traverseStmtImpl(Stmt *S) {
const Stmt *OldNextParent = NextStmtParent;
CurrStmtParent = NextStmtParent;
NextStmtParent = S;
- bool Result = VisitorBase::TraverseStmt(S);
+ const bool Result = VisitorBase::TraverseStmt(S);
NextStmtParent = OldNextParent;
return Result;
}
@@ -850,7 +846,7 @@ std::string VariableNamer::createIndexName() {
if (TheContainer)
ContainerName = TheContainer->getName();
- size_t Len = ContainerName.size();
+ const size_t Len = ContainerName.size();
if (Len > 1 && ContainerName.ends_with(Style == NS_UpperCase ? "S" : "s")) {
IteratorName = std::string(ContainerName.substr(0, Len - 1));
// E.g.: (auto thing : things)
@@ -876,7 +872,7 @@ std::string VariableNamer::createIndexName() {
/// converter in a loop nested within SourceStmt.
bool VariableNamer::declarationExists(StringRef Symbol) {
assert(Context != nullptr && "Expected an ASTContext");
- IdentifierInfo &Ident = Context->Idents.get(Symbol);
+ const IdentifierInfo &Ident = Context->Idents.get(Symbol);
// Check if the symbol is not an identifier (ie. is a keyword or alias).
if (!isAnyIdentifier(Ident.getTokenID()))
@@ -888,7 +884,7 @@ bool VariableNamer::declarationExists(StringRef Symbol) {
// Determine if the symbol was generated in a parent context.
for (const Stmt *S = SourceStmt; S != nullptr; S = ReverseAST->lookup(S)) {
- StmtGeneratedVarNameMap::const_iterator I = GeneratedDecls->find(S);
+ const StmtGeneratedVarNameMap::const_iterator I = GeneratedDecls->find(S);
if (I != GeneratedDecls->end() && I->second == Symbol)
return true;
}
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h
index 0a0db5e..5d0800d 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOP_CONVERT_UTILS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOP_CONVERT_UTILS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOPCONVERTUTILS_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOPCONVERTUTILS_H
#include "clang/AST/ASTContext.h"
#include "clang/AST/RecursiveASTVisitor.h"
@@ -466,4 +466,4 @@ private:
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOP_CONVERT_UTILS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOPCONVERTUTILS_H
diff --git a/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp b/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
index 2669aa2..098d46c 100644
--- a/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
@@ -23,7 +23,7 @@ static bool hasOnlyComments(SourceLocation Loc, const LangOptions &Options,
StringRef Text) {
// Use a lexer to look for tokens; if we find something other than a single
// hash, then there were intervening tokens between macro definitions.
- std::string Buffer{Text};
+ const std::string Buffer{Text};
Lexer Lex(Loc, Options, Buffer.c_str(), Buffer.c_str(),
Buffer.c_str() + Buffer.size());
Token Tok;
@@ -47,7 +47,7 @@ static bool hasOnlyComments(SourceLocation Loc, const LangOptions &Options,
};
WhiteSpace State = WhiteSpace::Nothing;
- for (char C : Text) {
+ for (const char C : Text) {
switch (C) {
case '\r':
if (State == WhiteSpace::CR)
@@ -227,17 +227,17 @@ bool MacroToEnumCallbacks::isConsecutiveMacro(const MacroDirective *MD) const {
if (CurrentFile->LastMacroLocation.isInvalid())
return false;
- SourceLocation Loc = MD->getLocation();
+ const SourceLocation Loc = MD->getLocation();
if (CurrentFile->LastLine + 1 == SM.getSpellingLineNumber(Loc))
return true;
- SourceLocation Define =
+ const SourceLocation Define =
SM.translateLineCol(SM.getFileID(Loc), SM.getSpellingLineNumber(Loc), 1);
- CharSourceRange BetweenMacros{
+ const CharSourceRange BetweenMacros{
SourceRange{CurrentFile->LastMacroLocation, Define}, true};
- CharSourceRange CharRange =
+ const CharSourceRange CharRange =
Lexer::makeFileCharRange(BetweenMacros, SM, LangOpts);
- StringRef BetweenText = Lexer::getSourceText(CharRange, SM, LangOpts);
+ const StringRef BetweenText = Lexer::getSourceText(CharRange, SM, LangOpts);
return hasOnlyComments(Define, LangOpts, BetweenText);
}
@@ -258,7 +258,7 @@ void MacroToEnumCallbacks::conditionStart(const SourceLocation &Loc) {
}
void MacroToEnumCallbacks::checkCondition(SourceRange Range) {
- CharSourceRange CharRange = Lexer::makeFileCharRange(
+ const CharSourceRange CharRange = Lexer::makeFileCharRange(
CharSourceRange::getTokenRange(Range), SM, LangOpts);
std::string Text = Lexer::getSourceText(CharRange, SM, LangOpts).str();
Lexer Lex(CharRange.getBegin(), LangOpts, Text.data(), Text.data(),
@@ -285,7 +285,7 @@ void MacroToEnumCallbacks::checkName(const Token &MacroNameTok) {
}
void MacroToEnumCallbacks::rememberExpressionName(const Token &Tok) {
- std::string Id = getTokenName(Tok).str();
+ const std::string Id = getTokenName(Tok).str();
auto Pos = llvm::lower_bound(ExpressionNames, Id);
if (Pos == ExpressionNames.end() || *Pos != Id) {
ExpressionNames.insert(Pos, Id);
@@ -294,7 +294,7 @@ void MacroToEnumCallbacks::rememberExpressionName(const Token &Tok) {
void MacroToEnumCallbacks::rememberExpressionTokens(
ArrayRef<Token> MacroTokens) {
- for (Token Tok : MacroTokens) {
+ for (const Token Tok : MacroTokens) {
if (Tok.isAnyIdentifier())
rememberExpressionName(Tok);
}
@@ -318,8 +318,8 @@ void MacroToEnumCallbacks::FileChanged(SourceLocation Loc,
bool MacroToEnumCallbacks::isInitializer(ArrayRef<Token> MacroTokens) {
IntegralLiteralExpressionMatcher Matcher(MacroTokens, LangOpts.C99 == 0);
- bool Matched = Matcher.match();
- bool IsC = !LangOpts.CPlusPlus;
+ const bool Matched = Matcher.match();
+ const bool IsC = !LangOpts.CPlusPlus;
if (IsC && (Matcher.largestLiteralSize() != LiteralSize::Int &&
Matcher.largestLiteralSize() != LiteralSize::UnsignedInt))
return false;
@@ -344,7 +344,7 @@ void MacroToEnumCallbacks::MacroDefined(const Token &MacroNameTok,
return;
const MacroInfo *Info = MD->getMacroInfo();
- ArrayRef<Token> MacroTokens = Info->tokens();
+ const ArrayRef<Token> MacroTokens = Info->tokens();
if (Info->isBuiltinMacro() || MacroTokens.empty())
return;
if (Info->isFunctionLike()) {
@@ -474,26 +474,26 @@ void MacroToEnumCallbacks::fixEnumMacro(const MacroList &MacroList) const {
MacroList.front().Directive->getMacroInfo()->getDefinitionLoc();
Begin = SM.translateLineCol(SM.getFileID(Begin),
SM.getSpellingLineNumber(Begin), 1);
- DiagnosticBuilder Diagnostic =
+ const DiagnosticBuilder Diagnostic =
Check->diag(Begin, "replace macro with enum")
<< FixItHint::CreateInsertion(Begin, "enum {\n");
for (size_t I = 0U; I < MacroList.size(); ++I) {
const EnumMacro &Macro = MacroList[I];
- SourceLocation DefineEnd =
+ const SourceLocation DefineEnd =
Macro.Directive->getMacroInfo()->getDefinitionLoc();
- SourceLocation DefineBegin = SM.translateLineCol(
+ const SourceLocation DefineBegin = SM.translateLineCol(
SM.getFileID(DefineEnd), SM.getSpellingLineNumber(DefineEnd), 1);
CharSourceRange DefineRange;
DefineRange.setBegin(DefineBegin);
DefineRange.setEnd(DefineEnd);
Diagnostic << FixItHint::CreateRemoval(DefineRange);
- SourceLocation NameEnd = Lexer::getLocForEndOfToken(
+ const SourceLocation NameEnd = Lexer::getLocForEndOfToken(
Macro.Directive->getMacroInfo()->getDefinitionLoc(), 0, SM, LangOpts);
Diagnostic << FixItHint::CreateInsertion(NameEnd, " =");
- SourceLocation ValueEnd = Lexer::getLocForEndOfToken(
+ const SourceLocation ValueEnd = Lexer::getLocForEndOfToken(
Macro.Directive->getMacroInfo()->getDefinitionEndLoc(), 0, SM,
LangOpts);
if (I < MacroList.size() - 1)
diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h
index 063b35fc..4b7f625 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKE_SHARED_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKE_SHARED_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKESHAREDCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKESHAREDCHECK_H
#include "MakeSmartPtrCheck.h"
@@ -35,4 +35,4 @@ protected:
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKE_SHARED_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKESHAREDCHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
index 9d01e27..39c5def 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
+#include "MakeSmartPtrCheck.h"
#include "../utils/TypeTraits.h"
-#include "MakeSharedCheck.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Lex/Lexer.h"
#include "clang/Lex/Preprocessor.h"
@@ -24,7 +24,7 @@ static constexpr char NewExpression[] = "newExpression";
static std::string getNewExprName(const CXXNewExpr *NewExpr,
const SourceManager &SM,
const LangOptions &Lang) {
- StringRef WrittenName = Lexer::getSourceText(
+ const StringRef WrittenName = Lexer::getSourceText(
CharSourceRange::getTokenRange(
NewExpr->getAllocatedTypeSourceInfo()->getTypeLoc().getSourceRange()),
SM, Lang);
@@ -134,9 +134,9 @@ void MakeSmartPtrCheck::check(const MatchFinder::MatchResult &Result) {
//
// The fix of the check has side effect, it introduces value initialization
// which maybe unexpected and cause performance regression.
- bool Initializes = New->hasInitializer() ||
- !utils::type_traits::isTriviallyDefaultConstructible(
- New->getAllocatedType(), *Result.Context);
+ const bool Initializes = New->hasInitializer() ||
+ !utils::type_traits::isTriviallyDefaultConstructible(
+ New->getAllocatedType(), *Result.Context);
if (!Initializes && IgnoreDefaultInitialization)
return;
if (Construct)
@@ -150,15 +150,15 @@ void MakeSmartPtrCheck::checkConstruct(SourceManager &SM, ASTContext *Ctx,
const VarDecl *DVar,
const QualType *Type,
const CXXNewExpr *New) {
- SourceLocation ConstructCallStart = Construct->getExprLoc();
- bool InMacro = ConstructCallStart.isMacroID();
+ const SourceLocation ConstructCallStart = Construct->getExprLoc();
+ const bool InMacro = ConstructCallStart.isMacroID();
if (InMacro && IgnoreMacros) {
return;
}
bool Invalid = false;
- StringRef ExprStr = Lexer::getSourceText(
+ const StringRef ExprStr = Lexer::getSourceText(
CharSourceRange::getCharRange(
ConstructCallStart, Construct->getParenOrBraceRange().getBegin()),
SM, getLangOpts(), &Invalid);
@@ -178,7 +178,7 @@ void MakeSmartPtrCheck::checkConstruct(SourceManager &SM, ASTContext *Ctx,
}
// Find the location of the template's left angle.
- size_t LAngle = ExprStr.find('<');
+ const size_t LAngle = ExprStr.find('<');
SourceLocation ConstructCallEnd;
if (LAngle == StringRef::npos) {
// If the template argument is missing (because it is part of the alias)
@@ -202,7 +202,7 @@ void MakeSmartPtrCheck::checkConstruct(SourceManager &SM, ASTContext *Ctx,
// If the smart_ptr is built with brace enclosed direct initialization, use
// parenthesis instead.
if (Construct->isListInitialization()) {
- SourceRange BraceRange = Construct->getParenOrBraceRange();
+ const SourceRange BraceRange = Construct->getParenOrBraceRange();
Diag << FixItHint::CreateReplacement(
CharSourceRange::getCharRange(
BraceRange.getBegin(), BraceRange.getBegin().getLocWithOffset(1)),
@@ -220,13 +220,13 @@ void MakeSmartPtrCheck::checkReset(SourceManager &SM, ASTContext *Ctx,
const CXXMemberCallExpr *Reset,
const CXXNewExpr *New) {
const auto *Expr = cast<MemberExpr>(Reset->getCallee());
- SourceLocation OperatorLoc = Expr->getOperatorLoc();
- SourceLocation ResetCallStart = Reset->getExprLoc();
- SourceLocation ExprStart = Expr->getBeginLoc();
- SourceLocation ExprEnd =
+ const SourceLocation OperatorLoc = Expr->getOperatorLoc();
+ const SourceLocation ResetCallStart = Reset->getExprLoc();
+ const SourceLocation ExprStart = Expr->getBeginLoc();
+ const SourceLocation ExprEnd =
Lexer::getLocForEndOfToken(Expr->getEndLoc(), 0, SM, getLangOpts());
- bool InMacro = ExprStart.isMacroID();
+ const bool InMacro = ExprStart.isMacroID();
if (InMacro && IgnoreMacros) {
return;
@@ -267,7 +267,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
const CXXNewExpr *New, SourceManager &SM,
ASTContext *Ctx) {
auto SkipParensParents = [&](const Expr *E) {
- TraversalKindScope RAII(*Ctx, TK_AsIs);
+ const TraversalKindScope RAII(*Ctx, TK_AsIs);
for (const Expr *OldE = nullptr; E != OldE;) {
OldE = E;
@@ -281,9 +281,9 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
return E;
};
- SourceRange NewRange = SkipParensParents(New)->getSourceRange();
- SourceLocation NewStart = NewRange.getBegin();
- SourceLocation NewEnd = NewRange.getEnd();
+ const SourceRange NewRange = SkipParensParents(New)->getSourceRange();
+ const SourceLocation NewStart = NewRange.getBegin();
+ const SourceLocation NewEnd = NewRange.getEnd();
// Skip when the source location of the new expression is invalid.
if (NewStart.isInvalid() || NewEnd.isInvalid())
@@ -362,7 +362,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
return false;
}
if (ArraySizeExpr.empty()) {
- SourceRange InitRange = New->getDirectInitRange();
+ const SourceRange InitRange = New->getDirectInitRange();
Diag << FixItHint::CreateRemoval(
SourceRange(NewStart, InitRange.getBegin()));
Diag << FixItHint::CreateRemoval(SourceRange(InitRange.getEnd(), NewEnd));
diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.h b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.h
index 28d5b45..1d70f62 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKE_SMART_PTR_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKE_SMART_PTR_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKESMARTPTRCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKESMARTPTRCHECK_H
#include "../ClangTidyCheck.h"
#include "../utils/IncludeInserter.h"
@@ -64,4 +64,4 @@ private:
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKE_SMART_PTR_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKESMARTPTRCHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/MakeUniqueCheck.h b/clang-tools-extra/clang-tidy/modernize/MakeUniqueCheck.h
index 9c4f6bc..170343b9 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeUniqueCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/MakeUniqueCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKE_UNIQUE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKE_UNIQUE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKEUNIQUECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKEUNIQUECHECK_H
#include "MakeSmartPtrCheck.h"
@@ -37,4 +37,4 @@ private:
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKE_UNIQUE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKEUNIQUECHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp b/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp
index b5a985b..f459295 100644
--- a/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp
@@ -243,7 +243,6 @@ void MinMaxUseInitializerListCheck::registerPPCallbacks(
void MinMaxUseInitializerListCheck::check(
const MatchFinder::MatchResult &Match) {
-
const auto *TopCall = Match.Nodes.getNodeAs<CallExpr>("topCall");
const FindArgsResult Result = findArgs(TopCall);
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 360e2b8..a410f8d 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -11,6 +11,7 @@
#include "../ClangTidyModuleRegistry.h"
#include "AvoidBindCheck.h"
#include "AvoidCArraysCheck.h"
+#include "AvoidCStyleCastCheck.h"
#include "AvoidSetjmpLongjmpCheck.h"
#include "AvoidVariadicFunctionsCheck.h"
#include "ConcatNestedNamespacesCheck.h"
@@ -65,6 +66,8 @@ public:
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
CheckFactories.registerCheck<AvoidBindCheck>("modernize-avoid-bind");
CheckFactories.registerCheck<AvoidCArraysCheck>("modernize-avoid-c-arrays");
+ CheckFactories.registerCheck<AvoidCStyleCastCheck>(
+ "modernize-avoid-c-style-cast");
CheckFactories.registerCheck<AvoidSetjmpLongjmpCheck>(
"modernize-avoid-setjmp-longjmp");
CheckFactories.registerCheck<AvoidVariadicFunctionsCheck>(
diff --git a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
index d5ccbb7..09d98ee 100644
--- a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
@@ -24,7 +24,8 @@ static bool isFirstFriendOfSecond(const CXXRecordDecl *Friend,
const CXXRecordDecl *Class) {
return llvm::any_of(
Class->friends(), [Friend](FriendDecl *FriendDecl) -> bool {
- if (TypeSourceInfo *FriendTypeSource = FriendDecl->getFriendType()) {
+ if (const TypeSourceInfo *FriendTypeSource =
+ FriendDecl->getFriendType()) {
const QualType FriendType = FriendTypeSource->getType();
return FriendType->getAsCXXRecordDecl() == Friend;
}
@@ -195,11 +196,7 @@ static bool hasRValueOverload(const CXXConstructorDecl *Ctor,
return true;
};
- for (const auto *Candidate : Record->ctors()) {
- if (IsRValueOverload(Candidate))
- return true;
- }
- return false;
+ return llvm::any_of(Record->ctors(), IsRValueOverload);
}
/// Find all references to \p ParamDecl across all of the
@@ -208,7 +205,7 @@ static SmallVector<const ParmVarDecl *, 2>
collectParamDecls(const CXXConstructorDecl *Ctor,
const ParmVarDecl *ParamDecl) {
SmallVector<const ParmVarDecl *, 2> Results;
- unsigned ParamIdx = ParamDecl->getFunctionScopeIndex();
+ const unsigned ParamIdx = ParamDecl->getFunctionScopeIndex();
for (const FunctionDecl *Redecl : Ctor->redecls())
Results.push_back(Redecl->getParamDecl(ParamIdx));
@@ -275,7 +272,7 @@ void PassByValueCheck::check(const MatchFinder::MatchResult &Result) {
const auto *ParamDecl = Result.Nodes.getNodeAs<ParmVarDecl>("Param");
const auto *Initializer =
Result.Nodes.getNodeAs<CXXCtorInitializer>("Initializer");
- SourceManager &SM = *Result.SourceManager;
+ const SourceManager &SM = *Result.SourceManager;
// If the parameter is used or anything other than the copy, do not apply
// the changes.
@@ -299,7 +296,7 @@ void PassByValueCheck::check(const MatchFinder::MatchResult &Result) {
if (ParamDecl->getType()->isLValueReferenceType()) {
// Check if we can succesfully rewrite all declarations of the constructor.
for (const ParmVarDecl *ParmDecl : collectParamDecls(Ctor, ParamDecl)) {
- TypeLoc ParamTL = ParmDecl->getTypeSourceInfo()->getTypeLoc();
+ const TypeLoc ParamTL = ParmDecl->getTypeSourceInfo()->getTypeLoc();
auto RefTL = ParamTL.getAs<ReferenceTypeLoc>();
if (RefTL.isNull()) {
// We cannot rewrite this instance. The type is probably hidden behind
@@ -309,11 +306,11 @@ void PassByValueCheck::check(const MatchFinder::MatchResult &Result) {
}
// Rewrite all declarations.
for (const ParmVarDecl *ParmDecl : collectParamDecls(Ctor, ParamDecl)) {
- TypeLoc ParamTL = ParmDecl->getTypeSourceInfo()->getTypeLoc();
+ const TypeLoc ParamTL = ParmDecl->getTypeSourceInfo()->getTypeLoc();
auto RefTL = ParamTL.getAs<ReferenceTypeLoc>();
- TypeLoc ValueTL = RefTL.getPointeeLoc();
- CharSourceRange TypeRange = CharSourceRange::getTokenRange(
+ const TypeLoc ValueTL = RefTL.getPointeeLoc();
+ const CharSourceRange TypeRange = CharSourceRange::getTokenRange(
ParmDecl->getBeginLoc(), ParamTL.getEndLoc());
std::string ValueStr =
Lexer::getSourceText(
diff --git a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h
index f27871c..eb51f4a 100644
--- a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_PASS_BY_VALUE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_PASS_BY_VALUE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_PASSBYVALUECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_PASSBYVALUECHECK_H
#include "../ClangTidyCheck.h"
#include "../utils/IncludeInserter.h"
@@ -33,4 +33,4 @@ private:
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_PASS_BY_VALUE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_PASSBYVALUECHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp b/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
index 8e514e4..2c4bddf 100644
--- a/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
@@ -51,11 +51,11 @@ static bool containsEscapedCharacters(const MatchFinder::MatchResult &Result,
if (DisallowedChars.test(C))
return false;
- CharSourceRange CharRange = Lexer::makeFileCharRange(
+ const CharSourceRange CharRange = Lexer::makeFileCharRange(
CharSourceRange::getTokenRange(Literal->getSourceRange()),
*Result.SourceManager, Result.Context->getLangOpts());
- StringRef Text = Lexer::getSourceText(CharRange, *Result.SourceManager,
- Result.Context->getLangOpts());
+ const StringRef Text = Lexer::getSourceText(CharRange, *Result.SourceManager,
+ Result.Context->getLangOpts());
if (Text.empty() || isRawStringLiteral(Text))
return false;
@@ -116,7 +116,7 @@ createUserDefinedSuffix(const StringLiteral *Literal, const SourceManager &SM,
const CharSourceRange CharRange =
Lexer::makeFileCharRange(TokenRange, SM, LangOpts);
if (T.hasUDSuffix()) {
- StringRef Text = Lexer::getSourceText(CharRange, SM, LangOpts);
+ const StringRef Text = Lexer::getSourceText(CharRange, SM, LangOpts);
const size_t UDSuffixPos = Text.find_last_of('"');
if (UDSuffixPos == StringRef::npos)
return std::nullopt;
@@ -135,7 +135,7 @@ static std::string createRawStringLiteral(const StringLiteral *Literal,
Delimiter = (I == 0) ? DelimiterStem : DelimiterStem + std::to_string(I);
}
- std::optional<StringRef> UserDefinedSuffix =
+ const std::optional<StringRef> UserDefinedSuffix =
createUserDefinedSuffix(Literal, SM, LangOpts);
if (Delimiter.empty())
diff --git a/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.h b/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.h
index 8ce6ec0..5be38dd 100644
--- a/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_RAW_STRING_LITERAL_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_RAW_STRING_LITERAL_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_RAWSTRINGLITERALCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_RAWSTRINGLITERALCHECK_H
#include "../ClangTidyCheck.h"
#include <bitset>
@@ -40,4 +40,4 @@ private:
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_RAW_STRING_LITERAL_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_RAWSTRINGLITERALCHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp b/clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
index 38b30f7..aa2db21 100644
--- a/clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -89,9 +89,9 @@ void RedundantVoidArgCheck::check(const MatchFinder::MatchResult &Result) {
void RedundantVoidArgCheck::processFunctionDecl(
const MatchFinder::MatchResult &Result, const FunctionDecl *Function) {
const auto *Method = dyn_cast<CXXMethodDecl>(Function);
- SourceLocation Start = Method && Method->getParent()->isLambda()
- ? Method->getBeginLoc()
- : Function->getLocation();
+ const SourceLocation Start = Method && Method->getParent()->isLambda()
+ ? Method->getBeginLoc()
+ : Function->getLocation();
SourceLocation End = Function->getEndLoc();
if (Function->isThisDeclarationADefinition()) {
if (const Stmt *Body = Function->getBody()) {
@@ -113,7 +113,8 @@ static bool isMacroIdentifier(const IdentifierTable &Idents,
if (!ProtoToken.is(tok::TokenKind::raw_identifier))
return false;
- IdentifierTable::iterator It = Idents.find(ProtoToken.getRawIdentifier());
+ const IdentifierTable::iterator It =
+ Idents.find(ProtoToken.getRawIdentifier());
if (It == Idents.end())
return false;
@@ -123,7 +124,7 @@ static bool isMacroIdentifier(const IdentifierTable &Idents,
void RedundantVoidArgCheck::removeVoidArgumentTokens(
const ast_matchers::MatchFinder::MatchResult &Result, SourceRange Range,
StringRef GrammarLocation) {
- CharSourceRange CharRange =
+ const CharSourceRange CharRange =
Lexer::makeFileCharRange(CharSourceRange::getTokenRange(Range),
*Result.SourceManager, getLangOpts());
@@ -145,7 +146,7 @@ void RedundantVoidArgCheck::removeVoidArgumentTokens(
Token ProtoToken;
const IdentifierTable &Idents = Result.Context->Idents;
int MacroLevel = 0;
- std::string Diagnostic =
+ const std::string Diagnostic =
("redundant void argument list in " + GrammarLocation).str();
while (!PrototypeLexer.LexFromRawLexer(ProtoToken)) {
@@ -216,7 +217,7 @@ void RedundantVoidArgCheck::removeVoidArgumentTokens(
void RedundantVoidArgCheck::removeVoidToken(Token VoidToken,
StringRef Diagnostic) {
- SourceLocation VoidLoc = VoidToken.getLocation();
+ const SourceLocation VoidLoc = VoidToken.getLocation();
diag(VoidLoc, Diagnostic) << FixItHint::CreateRemoval(VoidLoc);
}
@@ -239,9 +240,9 @@ void RedundantVoidArgCheck::processFieldDecl(
void RedundantVoidArgCheck::processVarDecl(
const MatchFinder::MatchResult &Result, const VarDecl *Var) {
if (protoTypeHasNoParms(Var->getType())) {
- SourceLocation Begin = Var->getBeginLoc();
+ const SourceLocation Begin = Var->getBeginLoc();
if (Var->hasInit()) {
- SourceLocation InitStart =
+ const SourceLocation InitStart =
Result.SourceManager->getExpansionLoc(Var->getInit()->getBeginLoc())
.getLocWithOffset(-1);
removeVoidArgumentTokens(Result, SourceRange(Begin, InitStart),
@@ -273,8 +274,9 @@ void RedundantVoidArgCheck::processLambdaExpr(
const MatchFinder::MatchResult &Result, const LambdaExpr *Lambda) {
if (Lambda->getLambdaClass()->getLambdaCallOperator()->getNumParams() == 0 &&
Lambda->hasExplicitParameters()) {
- SourceManager *SM = Result.SourceManager;
- TypeLoc TL = Lambda->getLambdaClass()->getLambdaTypeInfo()->getTypeLoc();
+ const SourceManager *SM = Result.SourceManager;
+ const TypeLoc TL =
+ Lambda->getLambdaClass()->getLambdaTypeInfo()->getTypeLoc();
removeVoidArgumentTokens(Result,
{SM->getSpellingLoc(TL.getBeginLoc()),
SM->getSpellingLoc(TL.getEndLoc())},
diff --git a/clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.h b/clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.h
index 53de74b..d6edd99 100644
--- a/clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REDUNDANT_VOID_ARG_CHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REDUNDANT_VOID_ARG_CHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REDUNDANTVOIDARGCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REDUNDANTVOIDARGCHECK_H
#include "../ClangTidyCheck.h"
#include "clang/Lex/Token.h"
@@ -73,4 +73,4 @@ private:
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REDUNDANT_VOID_ARG_CHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REDUNDANTVOIDARGCHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
index b562ae8..d0577ae 100644
--- a/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
@@ -96,10 +96,10 @@ void ReplaceAutoPtrCheck::registerPPCallbacks(const SourceManager &SM,
}
void ReplaceAutoPtrCheck::check(const MatchFinder::MatchResult &Result) {
- SourceManager &SM = *Result.SourceManager;
+ const SourceManager &SM = *Result.SourceManager;
if (const auto *E =
Result.Nodes.getNodeAs<Expr>(AutoPtrOwnershipTransferId)) {
- CharSourceRange Range = Lexer::makeFileCharRange(
+ const CharSourceRange Range = Lexer::makeFileCharRange(
CharSourceRange::getTokenRange(E->getSourceRange()), SM, LangOptions());
if (Range.isInvalid())
@@ -140,7 +140,8 @@ void ReplaceAutoPtrCheck::check(const MatchFinder::MatchResult &Result) {
"auto_ptr")
return;
- SourceLocation EndLoc = AutoPtrLoc.getLocWithOffset(strlen("auto_ptr") - 1);
+ const SourceLocation EndLoc =
+ AutoPtrLoc.getLocWithOffset(strlen("auto_ptr") - 1);
diag(AutoPtrLoc, "auto_ptr is deprecated, use unique_ptr instead")
<< FixItHint::CreateReplacement(SourceRange(AutoPtrLoc, EndLoc),
"unique_ptr");
diff --git a/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.h b/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.h
index 9a6e2bb..18f4740 100644
--- a/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_AUTO_PTR_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_AUTO_PTR_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACEAUTOPTRCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACEAUTOPTRCHECK_H
#include "../ClangTidyCheck.h"
#include "../utils/IncludeInserter.h"
@@ -56,4 +56,4 @@ private:
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_AUTO_PTR_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACEAUTOPTRCHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp b/clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp
index 64b0029..be5e21d 100644
--- a/clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp
@@ -26,7 +26,7 @@ public:
void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD,
SourceRange Range, const MacroArgs *Args) override {
- IdentifierInfo *Info = MacroNameTok.getIdentifierInfo();
+ const IdentifierInfo *Info = MacroNameTok.getIdentifierInfo();
if (!Info || !Args || Args->getNumMacroArguments() != 1)
return;
if (Info->getName() != Check.getMacroName())
@@ -38,11 +38,11 @@ public:
// For now we only support simple argument that don't need to be
// pre-expanded.
return;
- clang::IdentifierInfo *ClassIdent = ClassNameTok->getIdentifierInfo();
+ const clang::IdentifierInfo *ClassIdent = ClassNameTok->getIdentifierInfo();
if (!ClassIdent)
return;
- std::string Replacement = llvm::formatv(
+ const std::string Replacement = llvm::formatv(
R"cpp({0}(const {0} &) = delete;
const {0} &operator=(const {0} &) = delete{1})cpp",
ClassIdent->getName(), shouldAppendSemi(Range) ? ";" : "");
diff --git a/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp b/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
index 3d7b3ea..cfc546a 100644
--- a/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
@@ -78,7 +78,7 @@ void ReplaceRandomShuffleCheck::check(const MatchFinder::MatchResult &Result) {
}();
std::string NewName = "shuffle";
- StringRef ContainerText = Lexer::getSourceText(
+ const StringRef ContainerText = Lexer::getSourceText(
CharSourceRange::getTokenRange(MatchedDecl->getSourceRange()),
*Result.SourceManager, getLangOpts());
if (ContainerText.starts_with("std::"))
diff --git a/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.h b/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.h
index 5f2be10..3ffa387 100644
--- a/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_RANDOM_SHUFFLE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_RANDOM_SHUFFLE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACERANDOMSHUFFLECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACERANDOMSHUFFLECHECK_H
#include "../ClangTidyCheck.h"
#include "../utils/IncludeInserter.h"
@@ -37,4 +37,4 @@ private:
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_RANDOM_SHUFFLE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACERANDOMSHUFFLECHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp b/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
index eba2445..15b64bc 100644
--- a/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
@@ -54,7 +54,7 @@ void ReturnBracedInitListCheck::check(const MatchFinder::MatchResult &Result) {
Result.Nodes.getNodeAs<CXXConstructExpr>("ctor");
// Don't make replacements in macro.
- SourceLocation Loc = MatchedConstructExpr->getExprLoc();
+ const SourceLocation Loc = MatchedConstructExpr->getExprLoc();
if (Loc.isMacroID())
return;
@@ -88,7 +88,7 @@ void ReturnBracedInitListCheck::check(const MatchFinder::MatchResult &Result) {
}
// Range for constructor name and opening brace.
- CharSourceRange CtorCallSourceRange = CharSourceRange::getTokenRange(
+ const CharSourceRange CtorCallSourceRange = CharSourceRange::getTokenRange(
Loc, CallParensRange.getBegin().getLocWithOffset(-1));
Diag << FixItHint::CreateRemoval(CtorCallSourceRange)
diff --git a/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h b/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h
index ef465ea..be78571 100644
--- a/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_RETURN_BRACED_INIT_LIST_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_RETURN_BRACED_INIT_LIST_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_RETURNBRACEDINITLISTCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_RETURNBRACEDINITLISTCHECK_H
#include "../ClangTidyCheck.h"
@@ -34,4 +34,4 @@ public:
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_RETURN_BRACED_INIT_LIST_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_RETURNBRACEDINITLISTCHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp b/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
index 6078013..06982b8 100644
--- a/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
@@ -286,7 +286,7 @@ void TypeTraitsCheck::check(const MatchFinder::MatchResult &Result) {
if (const auto *TL = Result.Nodes.getNodeAs<TypedefTypeLoc>(Bind)) {
const NestedNameSpecifierLoc QualLoc = TL->getQualifierLoc();
- NestedNameSpecifier NNS = QualLoc.getNestedNameSpecifier();
+ const NestedNameSpecifier NNS = QualLoc.getNestedNameSpecifier();
if (const auto *CTSD = dyn_cast_if_present<ClassTemplateSpecializationDecl>(
NNS.getAsRecordDecl())) {
if (isNamedDeclInStdTraitsSet(CTSD, TypeTraits))
@@ -304,7 +304,7 @@ void TypeTraitsCheck::check(const MatchFinder::MatchResult &Result) {
}
if (const auto *DNTL = Result.Nodes.getNodeAs<DependentNameTypeLoc>(Bind)) {
- NestedNameSpecifierLoc QualLoc = DNTL->getQualifierLoc();
+ const NestedNameSpecifierLoc QualLoc = DNTL->getQualifierLoc();
if (checkTemplatedDecl(QualLoc.getNestedNameSpecifier(), TypeTraits))
EmitTypeWarning(QualLoc, DNTL->getEndLoc(),
DNTL->getElaboratedKeywordLoc());
diff --git a/clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp
index 4e4817f..28d8f75 100644
--- a/clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp
@@ -23,7 +23,7 @@ void UnaryStaticAssertCheck::check(const MatchFinder::MatchResult &Result) {
const auto *AssertMessage =
dyn_cast_if_present<StringLiteral>(MatchedDecl->getMessage());
- SourceLocation Loc = MatchedDecl->getLocation();
+ const SourceLocation Loc = MatchedDecl->getLocation();
if (!AssertMessage || AssertMessage->getLength() ||
AssertMessage->getBeginLoc().isMacroID() || Loc.isMacroID())
diff --git a/clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.h b/clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.h
index 95611c9..ebe77b9 100644
--- a/clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_UNARY_STATIC_ASSERT_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_UNARY_STATIC_ASSERT_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_UNARYSTATICASSERTCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_UNARYSTATICASSERTCHECK_H
#include "../ClangTidyCheck.h"
@@ -31,4 +31,4 @@ public:
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_UNARY_STATIC_ASSERT_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_UNARYSTATICASSERTCHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
index 01796a6..977ade1 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
@@ -20,14 +20,13 @@ using namespace clang::ast_matchers;
using namespace clang::ast_matchers::internal;
namespace clang::tidy::modernize {
-namespace {
-const char IteratorDeclStmtId[] = "iterator_decl";
-const char DeclWithNewId[] = "decl_new";
-const char DeclWithCastId[] = "decl_cast";
-const char DeclWithTemplateCastId[] = "decl_template";
+static const char IteratorDeclStmtId[] = "iterator_decl";
+static const char DeclWithNewId[] = "decl_new";
+static const char DeclWithCastId[] = "decl_cast";
+static const char DeclWithTemplateCastId[] = "decl_template";
-size_t getTypeNameLength(bool RemoveStars, StringRef Text) {
+static size_t getTypeNameLength(bool RemoveStars, StringRef Text) {
enum CharType { Space, Alpha, Punctuation };
CharType LastChar = Space, BeforeSpace = Punctuation;
size_t NumChars = 0;
@@ -54,6 +53,7 @@ size_t getTypeNameLength(bool RemoveStars, StringRef Text) {
return NumChars;
}
+namespace {
/// Matches variable declarations that have explicit initializers that
/// are not initializer lists.
///
@@ -65,7 +65,7 @@ size_t getTypeNameLength(bool RemoveStars, StringRef Text) {
/// MyType C;
/// \endcode
///
-/// varDecl(hasWrittenNonListInitializer()) maches \c I and \c A but not \c B
+/// varDecl(hasWrittenNonListInitializer()) matches \c I and \c A but not \c B
/// or \c C.
AST_MATCHER(VarDecl, hasWrittenNonListInitializer) {
const Expr *Init = Node.getAnyInitializer();
@@ -101,13 +101,23 @@ AST_MATCHER_P(QualType, isSugarFor, Matcher<QualType>, SugarMatcher) {
if (SugarMatcher.matches(QT, Finder, Builder))
return true;
- QualType NewQT = QT.getSingleStepDesugaredType(Finder->getASTContext());
+ const QualType NewQT =
+ QT.getSingleStepDesugaredType(Finder->getASTContext());
if (NewQT == QT)
return false;
QT = NewQT;
}
}
+/// Matches declaration reference or member expressions with explicit template
+/// arguments.
+AST_POLYMORPHIC_MATCHER(hasExplicitTemplateArgs,
+ AST_POLYMORPHIC_SUPPORTED_TYPES(DeclRefExpr,
+ MemberExpr)) {
+ return Node.hasExplicitTemplateArgs();
+}
+} // namespace
+
/// Matches named declarations that have one of the standard iterator
/// names: iterator, reverse_iterator, const_iterator, const_reverse_iterator.
///
@@ -118,7 +128,7 @@ AST_MATCHER_P(QualType, isSugarFor, Matcher<QualType>, SugarMatcher) {
/// \endcode
///
/// namedDecl(hasStdIteratorName()) matches \c I and \c CI.
-Matcher<NamedDecl> hasStdIteratorName() {
+static Matcher<NamedDecl> hasStdIteratorName() {
static const StringRef IteratorNames[] = {"iterator", "reverse_iterator",
"const_iterator",
"const_reverse_iterator"};
@@ -137,34 +147,27 @@ Matcher<NamedDecl> hasStdIteratorName() {
///
/// recordDecl(hasStdContainerName()) matches \c vector and \c forward_list
/// but not \c my_vec.
-Matcher<NamedDecl> hasStdContainerName() {
- static StringRef ContainerNames[] = {"array", "deque",
- "forward_list", "list",
- "vector",
+static Matcher<NamedDecl> hasStdContainerName() {
+ static const StringRef ContainerNames[] = {
+ "array", "deque",
+ "forward_list", "list",
+ "vector",
- "map", "multimap",
- "set", "multiset",
+ "map", "multimap",
+ "set", "multiset",
- "unordered_map", "unordered_multimap",
- "unordered_set", "unordered_multiset",
+ "unordered_map", "unordered_multimap",
+ "unordered_set", "unordered_multiset",
- "queue", "priority_queue",
- "stack"};
+ "queue", "priority_queue",
+ "stack"};
return hasAnyName(ContainerNames);
}
-/// Matches declaration reference or member expressions with explicit template
-/// arguments.
-AST_POLYMORPHIC_MATCHER(hasExplicitTemplateArgs,
- AST_POLYMORPHIC_SUPPORTED_TYPES(DeclRefExpr,
- MemberExpr)) {
- return Node.hasExplicitTemplateArgs();
-}
-
/// Returns a DeclarationMatcher that matches standard iterators nested
/// inside records with a standard container name.
-DeclarationMatcher standardIterator() {
+static DeclarationMatcher standardIterator() {
return decl(
namedDecl(hasStdIteratorName()),
hasDeclContext(recordDecl(hasStdContainerName(), isInStdNamespace())));
@@ -172,19 +175,19 @@ DeclarationMatcher standardIterator() {
/// Returns a TypeMatcher that matches typedefs for standard iterators
/// inside records with a standard container name.
-TypeMatcher typedefIterator() {
+static TypeMatcher typedefIterator() {
return typedefType(hasDeclaration(standardIterator()));
}
/// Returns a TypeMatcher that matches records named for standard
/// iterators nested inside records named for standard containers.
-TypeMatcher nestedIterator() {
+static TypeMatcher nestedIterator() {
return recordType(hasDeclaration(standardIterator()));
}
/// Returns a TypeMatcher that matches types declared with using
/// declarations and which name standard iterators for standard containers.
-TypeMatcher iteratorFromUsingDeclaration() {
+static TypeMatcher iteratorFromUsingDeclaration() {
auto HasIteratorDecl = hasDeclaration(namedDecl(hasStdIteratorName()));
// Unwrap the nested name specifier to test for one of the standard
// containers.
@@ -198,7 +201,7 @@ TypeMatcher iteratorFromUsingDeclaration() {
/// This matcher returns declaration statements that contain variable
/// declarations with written non-list initializer for standard iterators.
-StatementMatcher makeIteratorDeclMatcher() {
+static StatementMatcher makeIteratorDeclMatcher() {
return declStmt(unless(has(
varDecl(anyOf(unless(hasWrittenNonListInitializer()),
unless(hasType(isSugarFor(anyOf(
@@ -207,7 +210,7 @@ StatementMatcher makeIteratorDeclMatcher() {
.bind(IteratorDeclStmtId);
}
-StatementMatcher makeDeclWithNewMatcher() {
+static StatementMatcher makeDeclWithNewMatcher() {
return declStmt(
unless(has(varDecl(anyOf(
unless(hasInitializer(ignoringParenImpCasts(cxxNewExpr()))),
@@ -225,13 +228,13 @@ StatementMatcher makeDeclWithNewMatcher() {
.bind(DeclWithNewId);
}
-StatementMatcher makeDeclWithCastMatcher() {
+static StatementMatcher makeDeclWithCastMatcher() {
return declStmt(
unless(has(varDecl(unless(hasInitializer(explicitCastExpr()))))))
.bind(DeclWithCastId);
}
-StatementMatcher makeDeclWithTemplateCastMatcher() {
+static StatementMatcher makeDeclWithTemplateCastMatcher() {
auto ST =
substTemplateTypeParmType(hasReplacementType(equalsBoundNode("arg")));
@@ -252,7 +255,7 @@ StatementMatcher makeDeclWithTemplateCastMatcher() {
.bind(DeclWithTemplateCastId);
}
-StatementMatcher makeCombinedMatcher() {
+static StatementMatcher makeCombinedMatcher() {
return declStmt(
// At least one varDecl should be a child of the declStmt to ensure
// it's a declaration list and avoid matching other declarations,
@@ -265,8 +268,6 @@ StatementMatcher makeCombinedMatcher() {
makeDeclWithCastMatcher(), makeDeclWithTemplateCastMatcher()));
}
-} // namespace
-
UseAutoCheck::UseAutoCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
MinTypeNameLength(Options.get("MinTypeNameLength", 5)),
@@ -327,7 +328,8 @@ void UseAutoCheck::replaceIterators(const DeclStmt *D, ASTContext *Context) {
// like function pointers. Not a concern since this action only works with
// iterators but something to keep in mind in the future.
- SourceRange Range(V->getTypeSourceInfo()->getTypeLoc().getSourceRange());
+ const SourceRange Range(
+ V->getTypeSourceInfo()->getTypeLoc().getSourceRange());
diag(Range.getBegin(), "use auto when declaring iterators")
<< FixItHint::CreateReplacement(Range, "auto");
}
@@ -343,7 +345,7 @@ static bool isMultiLevelPointerToTypeLocClasses(
TypeLoc Loc,
const std::initializer_list<TypeLoc::TypeLocClass> &LocClasses) {
ignoreTypeLocClasses(Loc, {TypeLoc::Paren, TypeLoc::Qualified});
- TypeLoc::TypeLocClass TLC = Loc.getTypeLocClass();
+ const TypeLoc::TypeLocClass TLC = Loc.getTypeLocClass();
if (TLC != TypeLoc::Pointer && TLC != TypeLoc::MemberPointer)
return false;
ignoreTypeLocClasses(Loc, {TypeLoc::Paren, TypeLoc::Qualified,
@@ -360,7 +362,7 @@ void UseAutoCheck::replaceExpr(
return;
const QualType FirstDeclType = FirstDecl->getType().getCanonicalType();
- TypeSourceInfo *TSI = FirstDecl->getTypeSourceInfo();
+ const TypeSourceInfo *TSI = FirstDecl->getTypeSourceInfo();
if (TSI == nullptr)
return;
@@ -410,7 +412,7 @@ void UseAutoCheck::replaceExpr(
ignoreTypeLocClasses(Loc, {TypeLoc::Pointer, TypeLoc::Qualified});
ignoreTypeLocClasses(Loc, {TypeLoc::LValueReference, TypeLoc::RValueReference,
TypeLoc::Qualified});
- SourceRange Range(Loc.getSourceRange());
+ const SourceRange Range(Loc.getSourceRange());
if (MinTypeNameLength != 0 &&
getTypeNameLength(RemoveStars,
@@ -421,17 +423,17 @@ void UseAutoCheck::replaceExpr(
auto Diag = diag(Range.getBegin(), Message);
- bool ShouldReplenishVariableName = isMultiLevelPointerToTypeLocClasses(
+ const bool ShouldReplenishVariableName = isMultiLevelPointerToTypeLocClasses(
TSI->getTypeLoc(), {TypeLoc::FunctionProto, TypeLoc::ConstantArray});
// Space after 'auto' to handle cases where the '*' in the pointer type is
// next to the identifier. This avoids changing 'int *p' into 'autop'.
- llvm::StringRef Auto = ShouldReplenishVariableName
- ? (RemoveStars ? "auto " : "auto *")
- : (RemoveStars ? "auto " : "auto");
- std::string ReplenishedVariableName =
+ const llvm::StringRef Auto = ShouldReplenishVariableName
+ ? (RemoveStars ? "auto " : "auto *")
+ : (RemoveStars ? "auto " : "auto");
+ const std::string ReplenishedVariableName =
ShouldReplenishVariableName ? FirstDecl->getQualifiedNameAsString() : "";
- std::string Replacement =
+ const std::string Replacement =
(Auto + llvm::StringRef{ReplenishedVariableName}).str();
Diag << FixItHint::CreateReplacement(Range, Replacement) << StarRemovals;
}
diff --git a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.h b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.h
index dc39077..85e87fe 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_AUTO_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_AUTO_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEAUTOCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEAUTOCHECK_H
#include "../ClangTidyCheck.h"
@@ -35,4 +35,4 @@ private:
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_AUTO_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEAUTOCHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/UseBoolLiteralsCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseBoolLiteralsCheck.cpp
index 8b5ffe8..6e21187 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseBoolLiteralsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseBoolLiteralsCheck.cpp
@@ -50,14 +50,14 @@ void UseBoolLiteralsCheck::registerMatchers(MatchFinder *Finder) {
void UseBoolLiteralsCheck::check(const MatchFinder::MatchResult &Result) {
const auto *Literal = Result.Nodes.getNodeAs<IntegerLiteral>("literal");
const auto *Cast = Result.Nodes.getNodeAs<Expr>("cast");
- bool LiteralBooleanValue = Literal->getValue().getBoolValue();
+ const bool LiteralBooleanValue = Literal->getValue().getBoolValue();
if (Literal->isInstantiationDependent())
return;
const Expr *Expression = Cast ? Cast : Literal;
- bool InMacro = Expression->getBeginLoc().isMacroID();
+ const bool InMacro = Expression->getBeginLoc().isMacroID();
if (InMacro && IgnoreMacros)
return;
diff --git a/clang-tools-extra/clang-tidy/modernize/UseBoolLiteralsCheck.h b/clang-tools-extra/clang-tidy/modernize/UseBoolLiteralsCheck.h
index 64aff84..95bce07 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseBoolLiteralsCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseBoolLiteralsCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_BOOL_LITERALS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_BOOL_LITERALS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEBOOLLITERALSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEBOOLLITERALSCHECK_H
#include "../ClangTidyCheck.h"
@@ -33,4 +33,4 @@ private:
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_BOOL_LITERALS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEBOOLLITERALSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp
index d5342a1..14874e3 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp
@@ -55,7 +55,7 @@ static std::optional<TemplateSpecializationTypeLoc>
matchEnableIfSpecializationImplTypename(TypeLoc TheType) {
if (const auto Dep = TheType.getAs<DependentNameTypeLoc>()) {
const IdentifierInfo *Identifier = Dep.getTypePtr()->getIdentifier();
- ElaboratedTypeKeyword Keyword = Dep.getTypePtr()->getKeyword();
+ const ElaboratedTypeKeyword Keyword = Dep.getTypePtr()->getKeyword();
if (!Identifier || Identifier->getName() != "type" ||
(Keyword != ElaboratedTypeKeyword::Typename &&
Keyword != ElaboratedTypeKeyword::None)) {
@@ -70,7 +70,6 @@ matchEnableIfSpecializationImplTypename(TypeLoc TheType) {
if (const auto SpecializationLoc =
TheType.getAs<TemplateSpecializationTypeLoc>()) {
-
const auto *Specialization =
dyn_cast<TemplateSpecializationType>(SpecializationLoc.getTypePtr());
if (!Specialization)
@@ -88,7 +87,7 @@ matchEnableIfSpecializationImplTypename(TypeLoc TheType) {
if (!FirstParam || !FirstParam->getType()->isBooleanType())
return std::nullopt;
- int NumArgs = SpecializationLoc.getNumArgs();
+ const int NumArgs = SpecializationLoc.getNumArgs();
if (NumArgs != 1 && NumArgs != 2)
return std::nullopt;
@@ -101,7 +100,6 @@ static std::optional<TemplateSpecializationTypeLoc>
matchEnableIfSpecializationImplTrait(TypeLoc TheType) {
if (const auto SpecializationLoc =
TheType.getAs<TemplateSpecializationTypeLoc>()) {
-
const auto *Specialization =
dyn_cast<TemplateSpecializationType>(SpecializationLoc.getTypePtr());
if (!Specialization)
@@ -124,7 +122,7 @@ matchEnableIfSpecializationImplTrait(TypeLoc TheType) {
if (const auto *AliasedType =
dyn_cast<DependentNameType>(Specialization->getAliasedType())) {
- ElaboratedTypeKeyword Keyword = AliasedType->getKeyword();
+ const ElaboratedTypeKeyword Keyword = AliasedType->getKeyword();
if (AliasedType->getIdentifier()->getName() != "type" ||
(Keyword != ElaboratedTypeKeyword::Typename &&
Keyword != ElaboratedTypeKeyword::None)) {
@@ -133,7 +131,7 @@ matchEnableIfSpecializationImplTrait(TypeLoc TheType) {
} else {
return std::nullopt;
}
- int NumArgs = SpecializationLoc.getNumArgs();
+ const int NumArgs = SpecializationLoc.getNumArgs();
if (NumArgs != 1 && NumArgs != 2)
return std::nullopt;
@@ -182,7 +180,6 @@ matchTrailingTemplateParam(const FunctionTemplateDecl *FunctionTemplate) {
TemplateParams->getParam(TemplateParams->size() - 1);
if (const auto *LastTemplateParam =
dyn_cast<NonTypeTemplateParmDecl>(LastParam)) {
-
if (!LastTemplateParam->hasDefaultArgument() ||
!LastTemplateParam->getName().empty())
return {};
@@ -223,7 +220,7 @@ getConditionRange(ASTContext &Context,
const LangOptions &LangOpts = Context.getLangOpts();
const SourceManager &SM = Context.getSourceManager();
if (EnableIf.getNumArgs() > 1) {
- TemplateArgumentLoc NextArg = EnableIf.getArgLoc(1);
+ const TemplateArgumentLoc NextArg = EnableIf.getArgLoc(1);
return {EnableIf.getLAngleLoc().getLocWithOffset(1),
utils::lexer::findPreviousTokenKind(
NextArg.getSourceRange().getBegin(), SM, LangOpts, tok::comma)};
@@ -235,7 +232,7 @@ getConditionRange(ASTContext &Context,
static SourceRange getTypeRange(ASTContext &Context,
const TemplateSpecializationTypeLoc &EnableIf) {
- TemplateArgumentLoc Arg = EnableIf.getArgLoc(1);
+ const TemplateArgumentLoc Arg = EnableIf.getArgLoc(1);
const LangOptions &LangOpts = Context.getLangOpts();
const SourceManager &SM = Context.getSourceManager();
return {utils::lexer::findPreviousTokenKind(Arg.getSourceRange().getBegin(),
@@ -269,7 +266,7 @@ getTypeText(ASTContext &Context,
static std::optional<SourceLocation>
findInsertionForConstraint(const FunctionDecl *Function, ASTContext &Context) {
- SourceManager &SM = Context.getSourceManager();
+ const SourceManager &SM = Context.getSourceManager();
const LangOptions &LangOpts = Context.getLangOpts();
if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(Function)) {
@@ -282,7 +279,7 @@ findInsertionForConstraint(const FunctionDecl *Function, ASTContext &Context) {
return std::nullopt;
}
if (Function->isDeleted()) {
- SourceLocation FunctionEnd = Function->getSourceRange().getEnd();
+ const SourceLocation FunctionEnd = Function->getSourceRange().getEnd();
return utils::lexer::findNextAnyTokenKind(FunctionEnd, SM, LangOpts,
tok::equal, tok::equal);
}
@@ -314,7 +311,7 @@ static bool isPrimaryExpression(const Expr *Expression) {
static std::optional<std::string> getConditionText(const Expr *ConditionExpr,
SourceRange ConditionRange,
ASTContext &Context) {
- SourceManager &SM = Context.getSourceManager();
+ const SourceManager &SM = Context.getSourceManager();
const LangOptions &LangOpts = Context.getLangOpts();
SourceLocation PrevTokenLoc = ConditionRange.getEnd();
@@ -325,14 +322,14 @@ static std::optional<std::string> getConditionText(const Expr *ConditionExpr,
Token PrevToken;
std::tie(PrevToken, PrevTokenLoc) = utils::lexer::getPreviousTokenAndStart(
PrevTokenLoc, SM, LangOpts, SkipComments);
- bool EndsWithDoubleSlash =
+ const bool EndsWithDoubleSlash =
PrevToken.is(tok::comment) &&
Lexer::getSourceText(CharSourceRange::getCharRange(
PrevTokenLoc, PrevTokenLoc.getLocWithOffset(2)),
SM, LangOpts) == "//";
bool Invalid = false;
- llvm::StringRef ConditionText = Lexer::getSourceText(
+ const llvm::StringRef ConditionText = Lexer::getSourceText(
CharSourceRange::getCharRange(ConditionRange), SM, LangOpts, &Invalid);
if (Invalid)
return std::nullopt;
@@ -361,9 +358,9 @@ static std::vector<FixItHint> handleReturnType(const FunctionDecl *Function,
const TypeLoc &ReturnType,
const EnableIfData &EnableIf,
ASTContext &Context) {
- TemplateArgumentLoc EnableCondition = EnableIf.Loc.getArgLoc(0);
+ const TemplateArgumentLoc EnableCondition = EnableIf.Loc.getArgLoc(0);
- SourceRange ConditionRange = getConditionRange(Context, EnableIf.Loc);
+ const SourceRange ConditionRange = getConditionRange(Context, EnableIf.Loc);
std::optional<std::string> ConditionText = getConditionText(
EnableCondition.getSourceExpression(), ConditionRange, Context);
@@ -410,12 +407,12 @@ handleTrailingTemplateType(const FunctionTemplateDecl *FunctionTemplate,
const FunctionDecl *Function,
const Decl *LastTemplateParam,
const EnableIfData &EnableIf, ASTContext &Context) {
- SourceManager &SM = Context.getSourceManager();
+ const SourceManager &SM = Context.getSourceManager();
const LangOptions &LangOpts = Context.getLangOpts();
- TemplateArgumentLoc EnableCondition = EnableIf.Loc.getArgLoc(0);
+ const TemplateArgumentLoc EnableCondition = EnableIf.Loc.getArgLoc(0);
- SourceRange ConditionRange = getConditionRange(Context, EnableIf.Loc);
+ const SourceRange ConditionRange = getConditionRange(Context, EnableIf.Loc);
std::optional<std::string> ConditionText = getConditionText(
EnableCondition.getSourceExpression(), ConditionRange, Context);
diff --git a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
index 0d2c3a7..cc6b7bf 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
@@ -163,7 +163,7 @@ static bool isZero(const Expr *E) {
case Stmt::IntegerLiteralClass:
return !cast<IntegerLiteral>(E)->getValue();
case Stmt::FloatingLiteralClass: {
- llvm::APFloat Value = cast<FloatingLiteral>(E)->getValue();
+ const llvm::APFloat Value = cast<FloatingLiteral>(E)->getValue();
return Value.isZero() && !Value.isNegative();
}
default:
@@ -297,16 +297,16 @@ void UseDefaultMemberInitCheck::checkDefaultInit(
}) > 1)
return;
- SourceLocation StartLoc = Field->getBeginLoc();
+ const SourceLocation StartLoc = Field->getBeginLoc();
if (StartLoc.isMacroID() && IgnoreMacros)
return;
- SourceLocation FieldEnd =
+ const SourceLocation FieldEnd =
Lexer::getLocForEndOfToken(Field->getSourceRange().getEnd(), 0,
*Result.SourceManager, getLangOpts());
- SourceLocation LParenEnd = Lexer::getLocForEndOfToken(
+ const SourceLocation LParenEnd = Lexer::getLocForEndOfToken(
Init->getLParenLoc(), 0, *Result.SourceManager, getLangOpts());
- CharSourceRange InitRange =
+ const CharSourceRange InitRange =
CharSourceRange::getCharRange(LParenEnd, Init->getRParenLoc());
const Expr *InitExpression = Init->getInit();
diff --git a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.h b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.h
index be6a18a..f379214 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_DEFAULT_MEMBER_INIT_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_DEFAULT_MEMBER_INIT_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEDEFAULTMEMBERINITCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEDEFAULTMEMBERINITCHECK_H
#include "../ClangTidyCheck.h"
@@ -44,4 +44,4 @@ private:
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_DEFAULT_MEMBER_INIT_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEDEFAULTMEMBERINITCHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
index cc7c2d1..e798f6f 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
@@ -40,10 +40,15 @@ static constexpr char StrictCppStandardComplianceName[] =
"StrictCppStandardCompliance";
static constexpr bool StrictCppStandardComplianceDefault = true;
+static unsigned getNumberOfDesignated(const InitListExpr *SyntacticInitList) {
+ return llvm::count_if(*SyntacticInitList, [](auto *InitExpr) {
+ return isa<DesignatedInitExpr>(InitExpr);
+ });
+}
+
namespace {
struct Designators {
-
Designators(const InitListExpr *InitList) : InitList(InitList) {
assert(InitList->isSyntacticForm());
};
@@ -74,12 +79,6 @@ private:
}
};
-unsigned getNumberOfDesignated(const InitListExpr *SyntacticInitList) {
- return llvm::count_if(*SyntacticInitList, [](auto *InitExpr) {
- return isa<DesignatedInitExpr>(InitExpr);
- });
-}
-
AST_MATCHER(CXXRecordDecl, isAggregate) {
return Node.hasDefinition() && Node.isAggregate();
}
@@ -152,7 +151,7 @@ void UseDesignatedInitializersCheck::check(
if (IgnoreMacros && InitList->getBeginLoc().isMacroID())
return;
{
- DiagnosticBuilder Diag =
+ const DiagnosticBuilder Diag =
diag(InitList->getLBraceLoc(),
"use designated initializer list to initialize %0");
Diag << InitList->getType() << InitList->getSourceRange();
diff --git a/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
index ade0085..ca97b11 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
@@ -44,17 +44,12 @@ AST_MATCHER_P(NamedDecl, hasAnyNameIgnoringTemplates, std::vector<StringRef>,
// clang/lib/ASTMatchers/ASTMatchersInternal.cpp and checks whether
// FullNameTrimmed matches any of the given Names.
const StringRef FullNameTrimmedRef = FullNameTrimmed;
- for (const StringRef Pattern : Names) {
- if (Pattern.starts_with("::")) {
- if (FullNameTrimmed == Pattern)
- return true;
- } else if (FullNameTrimmedRef.ends_with(Pattern) &&
- FullNameTrimmedRef.drop_back(Pattern.size()).ends_with("::")) {
- return true;
- }
- }
-
- return false;
+ return llvm::any_of(Names, [&](const StringRef Pattern) {
+ if (Pattern.starts_with("::"))
+ return FullNameTrimmed == Pattern;
+ return FullNameTrimmedRef.ends_with(Pattern) &&
+ FullNameTrimmedRef.drop_back(Pattern.size()).ends_with("::");
+ });
}
// Checks if the given matcher is the last argument of the given CallExpr.
@@ -81,41 +76,44 @@ AST_MATCHER(CXXMemberCallExpr, hasSameNumArgsAsDeclNumParams) {
AST_MATCHER(DeclRefExpr, hasExplicitTemplateArgs) {
return Node.hasExplicitTemplateArgs();
}
+} // namespace
// Helper Matcher which applies the given QualType Matcher either directly or by
// resolving a pointer type to its pointee. Used to match v.push_back() as well
// as p->push_back().
-auto hasTypeOrPointeeType(
+static auto hasTypeOrPointeeType(
const ast_matchers::internal::Matcher<QualType> &TypeMatcher) {
return anyOf(hasType(TypeMatcher),
hasType(pointerType(pointee(TypeMatcher))));
}
// Matches if the node has canonical type matching any of the given names.
-auto hasWantedType(llvm::ArrayRef<StringRef> TypeNames) {
+static auto hasWantedType(llvm::ArrayRef<StringRef> TypeNames) {
return hasCanonicalType(hasDeclaration(cxxRecordDecl(hasAnyName(TypeNames))));
}
// Matches member call expressions of the named method on the listed container
// types.
-auto cxxMemberCallExprOnContainer(StringRef MethodName,
- llvm::ArrayRef<StringRef> ContainerNames) {
+static auto
+cxxMemberCallExprOnContainer(StringRef MethodName,
+ llvm::ArrayRef<StringRef> ContainerNames) {
return cxxMemberCallExpr(
hasDeclaration(functionDecl(hasName(MethodName))),
on(hasTypeOrPointeeType(hasWantedType(ContainerNames))));
}
-const auto DefaultContainersWithPushBack =
+static const auto DefaultContainersWithPushBack =
"::std::vector; ::std::list; ::std::deque";
-const auto DefaultContainersWithPush =
+static const auto DefaultContainersWithPush =
"::std::stack; ::std::queue; ::std::priority_queue";
-const auto DefaultContainersWithPushFront =
+static const auto DefaultContainersWithPushFront =
"::std::forward_list; ::std::list; ::std::deque";
-const auto DefaultSmartPointers =
+static const auto DefaultSmartPointers =
"::std::shared_ptr; ::std::unique_ptr; ::std::auto_ptr; ::std::weak_ptr";
-const auto DefaultTupleTypes = "::std::pair; ::std::tuple";
-const auto DefaultTupleMakeFunctions = "::std::make_pair; ::std::make_tuple";
-const auto DefaultEmplacyFunctions =
+static const auto DefaultTupleTypes = "::std::pair; ::std::tuple";
+static const auto DefaultTupleMakeFunctions =
+ "::std::make_pair; ::std::make_tuple";
+static const auto DefaultEmplacyFunctions =
"vector::emplace_back; vector::emplace;"
"deque::emplace; deque::emplace_front; deque::emplace_back;"
"forward_list::emplace_after; forward_list::emplace_front;"
@@ -129,7 +127,6 @@ const auto DefaultEmplacyFunctions =
"unordered_multiset::emplace; unordered_multiset::emplace_hint;"
"unordered_multimap::emplace; unordered_multimap::emplace_hint;"
"stack::emplace; queue::emplace; priority_queue::emplace";
-} // namespace
UseEmplaceCheck::UseEmplaceCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context), IgnoreImplicitConstructors(Options.get(
diff --git a/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.h b/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.h
index 87ebf6f..a7ad5bb 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_EMPLACE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_EMPLACE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEEMPLACECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEEMPLACECHECK_H
#include "../ClangTidyCheck.h"
#include <string>
@@ -45,4 +45,4 @@ private:
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_EMPLACE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEEMPLACECHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
index d6ddbb6..fde9c73 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
@@ -200,7 +200,7 @@ static bool isCopyAssignmentAndCanBeDefaulted(ASTContext *Context,
/// Returns false if the body has any non-whitespace character.
static bool bodyEmpty(const ASTContext *Context, const CompoundStmt *Body) {
bool Invalid = false;
- StringRef Text = Lexer::getSourceText(
+ const StringRef Text = Lexer::getSourceText(
CharSourceRange::getCharRange(Body->getLBracLoc().getLocWithOffset(1),
Body->getRBracLoc()),
Context->getSourceManager(), Context->getLangOpts(), &Invalid);
@@ -306,8 +306,8 @@ void UseEqualsDefaultCheck::check(const MatchFinder::MatchResult &Result) {
return;
// If there are comments inside the body, don't do the change.
- bool ApplyFix = SpecialFunctionDecl->isCopyAssignmentOperator() ||
- bodyEmpty(Result.Context, Body);
+ const bool ApplyFix = SpecialFunctionDecl->isCopyAssignmentOperator() ||
+ bodyEmpty(Result.Context, Body);
std::vector<FixItHint> RemoveInitializers;
unsigned MemberType = 0;
@@ -345,14 +345,14 @@ void UseEqualsDefaultCheck::check(const MatchFinder::MatchResult &Result) {
Diag << MemberType;
if (ApplyFix) {
- SourceLocation UnifiedEnd = utils::lexer::getUnifiedEndLoc(
+ const SourceLocation UnifiedEnd = utils::lexer::getUnifiedEndLoc(
*Body, Result.Context->getSourceManager(),
Result.Context->getLangOpts());
// Skipping comments, check for a semicolon after Body->getSourceRange()
std::optional<Token> Token = utils::lexer::findNextTokenSkippingComments(
UnifiedEnd, Result.Context->getSourceManager(),
Result.Context->getLangOpts());
- StringRef Replacement =
+ const StringRef Replacement =
Token && Token->is(tok::semi) ? "= default" : "= default;";
Diag << FixItHint::CreateReplacement(Body->getSourceRange(), Replacement)
<< RemoveInitializers;
diff --git a/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.h b/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.h
index 519f189..a17d3d8 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_EQUALS_DEFAULT_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_EQUALS_DEFAULT_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEEQUALSDEFAULTCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEEQUALSDEFAULTCHECK_H
#include "../ClangTidyCheck.h"
@@ -48,4 +48,4 @@ private:
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_EQUALS_DEFAULT_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEEQUALSDEFAULTCHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.cpp
index ab2d41a..a19d2ec 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.cpp
@@ -74,7 +74,7 @@ void UseEqualsDeleteCheck::registerMatchers(MatchFinder *Finder) {
void UseEqualsDeleteCheck::check(const MatchFinder::MatchResult &Result) {
if (const auto *Func =
Result.Nodes.getNodeAs<CXXMethodDecl>(SpecialFunction)) {
- SourceLocation EndLoc = Lexer::getLocForEndOfToken(
+ const SourceLocation EndLoc = Lexer::getLocForEndOfToken(
Func->getEndLoc(), 0, *Result.SourceManager, getLangOpts());
if (IgnoreMacros && Func->getLocation().isMacroID())
diff --git a/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.h b/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.h
index 31a956b..17155fe 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_EQUALS_DELETE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_EQUALS_DELETE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEEQUALSDELETECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEEQUALSDELETECHECK_H
#include "../ClangTidyCheck.h"
@@ -38,4 +38,4 @@ private:
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_EQUALS_DELETE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEEQUALSDELETECHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
index 35320e8..574cbea 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
@@ -146,7 +146,7 @@ void UseIntegerSignComparisonCheck::check(
R3.setBegin(Lexer::getLocForEndOfToken(
SubExprRHS->getEndLoc(), 0, *Result.SourceManager, getLangOpts()));
}
- DiagnosticBuilder Diag =
+ const DiagnosticBuilder Diag =
diag(BinaryOp->getBeginLoc(),
"comparison between 'signed' and 'unsigned' integers");
StringRef CmpNamespace;
diff --git a/clang-tools-extra/clang-tidy/modernize/UseNodiscardCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseNodiscardCheck.cpp
index d22c993..7e8d982 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNodiscardCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseNodiscardCheck.cpp
@@ -110,11 +110,11 @@ void UseNodiscardCheck::registerMatchers(MatchFinder *Finder) {
void UseNodiscardCheck::check(const MatchFinder::MatchResult &Result) {
const auto *MatchedDecl = Result.Nodes.getNodeAs<CXXMethodDecl>("no_discard");
// Don't make replacements if the location is invalid or in a macro.
- SourceLocation Loc = MatchedDecl->getLocation();
+ const SourceLocation Loc = MatchedDecl->getLocation();
if (Loc.isInvalid() || Loc.isMacroID())
return;
- SourceLocation RetLoc = MatchedDecl->getInnerLocStart();
+ const SourceLocation RetLoc = MatchedDecl->getInnerLocStart();
ASTContext &Context = *Result.Context;
diff --git a/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp
index d1388dc..6bd5485 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp
@@ -81,12 +81,12 @@ void UseNoexceptCheck::check(const MatchFinder::MatchResult &Result) {
assert(Range.isValid() && "Exception Source Range is invalid.");
- CharSourceRange CRange = Lexer::makeFileCharRange(
+ const CharSourceRange CRange = Lexer::makeFileCharRange(
CharSourceRange::getTokenRange(Range), *Result.SourceManager,
Result.Context->getLangOpts());
- bool IsNoThrow = FnTy->isNothrow();
- StringRef ReplacementStr =
+ const bool IsNoThrow = FnTy->isNothrow();
+ const StringRef ReplacementStr =
IsNoThrow ? NoexceptMacro.empty() ? "noexcept" : NoexceptMacro
: NoexceptMacro.empty()
? (DtorOrOperatorDel || UseNoexceptFalse) ? "noexcept(false)" : ""
diff --git a/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.h b/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.h
index 30b5d4e..a97b39b 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_NOEXCEPT_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_NOEXCEPT_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USENOEXCEPTCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USENOEXCEPTCHECK_H
#include "../ClangTidyCheck.h"
@@ -44,4 +44,4 @@ private:
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_NOEXCEPT_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USENOEXCEPTCHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
index b6834c6..928a007 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
@@ -92,12 +92,13 @@ static bool isReplaceableRange(SourceLocation StartLoc, SourceLocation EndLoc,
/// Returns true if and only if a replacement was made.
static void replaceWithNullptr(ClangTidyCheck &Check, SourceManager &SM,
SourceLocation StartLoc, SourceLocation EndLoc) {
- CharSourceRange Range(SourceRange(StartLoc, EndLoc), true);
+ const CharSourceRange Range(SourceRange(StartLoc, EndLoc), true);
// Add a space if nullptr follows an alphanumeric character. This happens
// whenever there is an c-style explicit cast to nullptr not surrounded by
// parentheses and right beside a return statement.
- SourceLocation PreviousLocation = StartLoc.getLocWithOffset(-1);
- bool NeedsSpace = isAlphanumeric(*SM.getCharacterData(PreviousLocation));
+ const SourceLocation PreviousLocation = StartLoc.getLocWithOffset(-1);
+ const bool NeedsSpace =
+ isAlphanumeric(*SM.getCharacterData(PreviousLocation));
Check.diag(Range.getBegin(), "use nullptr") << FixItHint::CreateReplacement(
Range, NeedsSpace ? " nullptr" : "nullptr");
}
@@ -136,7 +137,7 @@ public:
}
bool TraverseStmt(Stmt *S) {
- bool VisitedPreviously = Visited;
+ const bool VisitedPreviously = Visited;
if (!RecursiveASTVisitor<MacroArgUsageVisitor>::TraverseStmt(S))
return false;
@@ -258,8 +259,8 @@ public:
// If the location comes from a macro body expansion, check to see if its
// coming from one of the allowed 'NULL' macros.
if (SM.isMacroArgExpansion(StartLoc) && SM.isMacroArgExpansion(EndLoc)) {
- SourceLocation FileLocStart = SM.getFileLoc(StartLoc),
- FileLocEnd = SM.getFileLoc(EndLoc);
+ const SourceLocation FileLocStart = SM.getFileLoc(StartLoc),
+ FileLocEnd = SM.getFileLoc(EndLoc);
SourceLocation ImmediateMacroArgLoc, MacroLoc;
// Skip NULL macros used in macro.
if (!getMacroAndArgLocations(StartLoc, ImmediateMacroArgLoc, MacroLoc) ||
@@ -274,7 +275,7 @@ public:
}
if (SM.isMacroBodyExpansion(StartLoc) && SM.isMacroBodyExpansion(EndLoc)) {
- StringRef OutermostMacroName =
+ const StringRef OutermostMacroName =
getOutermostMacroName(StartLoc, SM, Context.getLangOpts());
// Check to see if the user wants to replace the macro being expanded.
@@ -302,7 +303,7 @@ private:
/// Tests that all expansions of a macro arg, one of which expands to
/// result in \p CE, yield NullTo(Member)Pointer casts.
bool allArgUsesValid(const CastExpr *CE) {
- SourceLocation CastLoc = CE->getBeginLoc();
+ const SourceLocation CastLoc = CE->getBeginLoc();
// Step 1: Get location of macro arg and location of the macro the arg was
// provided to.
@@ -348,17 +349,17 @@ private:
// Find the location of the immediate macro expansion.
while (true) {
- std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(ArgLoc);
+ const std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(ArgLoc);
const SrcMgr::SLocEntry *E = &SM.getSLocEntry(LocInfo.first);
const SrcMgr::ExpansionInfo &Expansion = E->getExpansion();
- SourceLocation OldArgLoc = ArgLoc;
+ const SourceLocation OldArgLoc = ArgLoc;
ArgLoc = Expansion.getExpansionLocStart();
if (!Expansion.isMacroArgExpansion()) {
if (!MacroLoc.isFileID())
return false;
- StringRef Name =
+ const StringRef Name =
Lexer::getImmediateMacroName(OldArgLoc, SM, Context.getLangOpts());
return llvm::is_contained(NullMacros, Name);
}
@@ -371,7 +372,7 @@ private:
// If spelling location resides in the same FileID as macro expansion
// location, it means there is no inner macro.
- FileID MacroFID = SM.getFileID(MacroLoc);
+ const FileID MacroFID = SM.getFileID(MacroLoc);
if (SM.isInFileID(ArgLoc, MacroFID)) {
// Don't transform this case. If the characters that caused the
// null-conversion come from within a macro, they can't be changed.
@@ -401,7 +402,7 @@ private:
SourceLocation Loc = TestLoc, MacroLoc;
while (true) {
- std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc);
+ const std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc);
const SrcMgr::SLocEntry *E = &SM.getSLocEntry(LocInfo.first);
const SrcMgr::ExpansionInfo &Expansion = E->getExpansion();
diff --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
index 7c7b5ae..1caa07a 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_NULLPTR_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_NULLPTR_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USENULLPTRCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USENULLPTRCHECK_H
#include "../ClangTidyCheck.h"
@@ -31,4 +31,4 @@ private:
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_NULLPTR_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USENULLPTRCHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
index 6a19183..e2e7bba 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
@@ -35,7 +35,6 @@ void UseOverrideCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
}
void UseOverrideCheck::registerMatchers(MatchFinder *Finder) {
-
auto IgnoreDestructorMatcher =
IgnoreDestructors ? cxxMethodDecl(unless(cxxDestructorDecl()))
: cxxMethodDecl();
@@ -55,9 +54,9 @@ void UseOverrideCheck::registerMatchers(MatchFinder *Finder) {
static SmallVector<Token, 16>
parseTokens(CharSourceRange Range, const MatchFinder::MatchResult &Result) {
const SourceManager &Sources = *Result.SourceManager;
- std::pair<FileID, unsigned> LocInfo =
+ const std::pair<FileID, unsigned> LocInfo =
Sources.getDecomposedLoc(Range.getBegin());
- StringRef File = Sources.getBufferData(LocInfo.first);
+ const StringRef File = Sources.getBufferData(LocInfo.first);
const char *TokenBegin = File.data() + LocInfo.second;
Lexer RawLexer(Sources.getLocForStartOfFile(LocInfo.first),
Result.Context->getLangOpts(), File.begin(), TokenBegin,
@@ -103,12 +102,12 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) {
Method->isOutOfLine())
return;
- bool HasVirtual = Method->isVirtualAsWritten();
- bool HasOverride = Method->getAttr<OverrideAttr>();
- bool HasFinal = Method->getAttr<FinalAttr>();
+ const bool HasVirtual = Method->isVirtualAsWritten();
+ const bool HasOverride = Method->getAttr<OverrideAttr>();
+ const bool HasFinal = Method->getAttr<FinalAttr>();
- bool OnlyVirtualSpecified = HasVirtual && !HasOverride && !HasFinal;
- unsigned KeywordCount = HasVirtual + HasOverride + HasFinal;
+ const bool OnlyVirtualSpecified = HasVirtual && !HasOverride && !HasFinal;
+ const unsigned KeywordCount = HasVirtual + HasOverride + HasFinal;
if ((!OnlyVirtualSpecified && KeywordCount == 1) ||
(!HasVirtual && HasOverride && HasFinal && AllowOverrideAndFinal))
@@ -120,12 +119,12 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) {
} else if (KeywordCount == 0) {
Message = "annotate this function with '%0' or (rarely) '%1'";
} else {
- StringRef Redundant =
+ const StringRef Redundant =
HasVirtual ? (HasOverride && HasFinal && !AllowOverrideAndFinal
? "'virtual' and '%0' are"
: "'virtual' is")
: "'%0' is";
- StringRef Correct = HasFinal ? "'%1'" : "'%0'";
+ const StringRef Correct = HasFinal ? "'%1'" : "'%0'";
Message = (llvm::Twine(Redundant) +
" redundant since the function is already declared " + Correct)
@@ -135,7 +134,7 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) {
auto Diag = diag(Method->getLocation(), Message)
<< OverrideSpelling << FinalSpelling;
- CharSourceRange FileRange = Lexer::makeFileCharRange(
+ const CharSourceRange FileRange = Lexer::makeFileCharRange(
CharSourceRange::getTokenRange(Method->getSourceRange()), Sources,
getLangOpts());
@@ -151,9 +150,9 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) {
if (!HasFinal && !HasOverride) {
SourceLocation InsertLoc;
std::string ReplacementText = (OverrideSpelling + " ").str();
- SourceLocation MethodLoc = Method->getLocation();
+ const SourceLocation MethodLoc = Method->getLocation();
- for (Token T : Tokens) {
+ for (const Token T : Tokens) {
if (T.is(tok::kw___attribute) &&
!Sources.isBeforeInTranslationUnit(T.getLocation(), MethodLoc)) {
InsertLoc = T.getLocation();
@@ -164,7 +163,7 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) {
if (Method->hasAttrs()) {
for (const clang::Attr *A : Method->getAttrs()) {
if (!A->isImplicit() && !A->isInherited()) {
- SourceLocation Loc =
+ const SourceLocation Loc =
Sources.getExpansionLoc(A->getRange().getBegin());
if ((!InsertLoc.isValid() ||
Sources.isBeforeInTranslationUnit(Loc, InsertLoc)) &&
@@ -221,13 +220,14 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) {
}
if (HasFinal && HasOverride && !AllowOverrideAndFinal) {
- SourceLocation OverrideLoc = Method->getAttr<OverrideAttr>()->getLocation();
+ const SourceLocation OverrideLoc =
+ Method->getAttr<OverrideAttr>()->getLocation();
Diag << FixItHint::CreateRemoval(
CharSourceRange::getTokenRange(OverrideLoc, OverrideLoc));
}
if (HasVirtual) {
- for (Token Tok : Tokens) {
+ for (const Token Tok : Tokens) {
if (Tok.is(tok::kw_virtual)) {
std::optional<Token> NextToken =
utils::lexer::findNextTokenIncludingComments(
diff --git a/clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp
index 2e2f25f..529b5a43 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp
@@ -135,7 +135,6 @@ class StdNumericReplacer : public StdReplacer {
} // namespace
utils::UseRangesCheck::ReplacerMap UseRangesCheck::getReplacerMap() const {
-
utils::UseRangesCheck::ReplacerMap Result;
// template<typename Iter> Func(Iter first, Iter last,...).
diff --git a/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp
index 9bf3169..8849c33 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp
@@ -74,7 +74,8 @@ findLocksInCompoundStmt(const CompoundStmt *Block,
for (const Stmt *Stmt : Block->body()) {
if (const auto *DS = dyn_cast<DeclStmt>(Stmt)) {
- llvm::SmallVector<const VarDecl *> LockGuards = getLockGuardsFromDecl(DS);
+ const llvm::SmallVector<const VarDecl *> LockGuards =
+ getLockGuardsFromDecl(DS);
if (!LockGuards.empty()) {
CurrentLockGuardGroup.append(LockGuards);
@@ -176,7 +177,7 @@ void UseScopedLockCheck::registerMatchers(MatchFinder *Finder) {
void UseScopedLockCheck::check(const MatchFinder::MatchResult &Result) {
if (const auto *DS = Result.Nodes.getNodeAs<DeclStmt>("lock-decl-single")) {
- llvm::SmallVector<const VarDecl *> Decls = getLockGuardsFromDecl(DS);
+ const llvm::SmallVector<const VarDecl *> Decls = getLockGuardsFromDecl(DS);
diagOnMultipleLocks({Decls}, Result);
return;
}
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
index 414aa86..0315728 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
@@ -81,16 +81,17 @@ AST_MATCHER_P(clang::Expr, anyOfExhaustive, std::vector<Matcher<clang::Stmt>>,
// literals.
struct MatchBuilder {
auto
- ignoreParenAndArithmeticCasting(const Matcher<clang::Expr> Matcher) const {
+ ignoreParenAndArithmeticCasting(const Matcher<clang::Expr> &Matcher) const {
return expr(hasType(qualType(isArithmetic())), ignoringParenCasts(Matcher));
}
- auto ignoreParenAndFloatingCasting(const Matcher<clang::Expr> Matcher) const {
+ auto
+ ignoreParenAndFloatingCasting(const Matcher<clang::Expr> &Matcher) const {
return expr(hasType(qualType(isFloating())), ignoringParenCasts(Matcher));
}
auto matchMathCall(const StringRef FunctionName,
- const Matcher<clang::Expr> ArgumentMatcher) const {
+ const Matcher<clang::Expr> &ArgumentMatcher) const {
auto HasAnyPrecisionName = hasAnyName(
FunctionName, (FunctionName + "l").str(),
(FunctionName + "f").str()); // Support long double(l) and float(f).
@@ -100,7 +101,7 @@ struct MatchBuilder {
hasArgument(0, ArgumentMatcher))));
}
- auto matchSqrt(const Matcher<clang::Expr> ArgumentMatcher) const {
+ auto matchSqrt(const Matcher<clang::Expr> &ArgumentMatcher) const {
return matchMathCall("sqrt", ArgumentMatcher);
}
@@ -148,7 +149,7 @@ struct MatchBuilder {
return expr(anyOf(Int, Float, Dref));
}
- auto match1Div(const Matcher<clang::Expr> Match) const {
+ auto match1Div(const Matcher<clang::Expr> &Match) const {
return binaryOperator(hasOperatorName("/"), hasLHS(matchValue(1)),
hasRHS(Match));
}
@@ -307,7 +308,7 @@ UseStdNumbersCheck::UseStdNumbersCheck(const StringRef Name,
void UseStdNumbersCheck::registerMatchers(MatchFinder *const Finder) {
const auto Matches = MatchBuilder{DiffThreshold};
- std::vector<Matcher<clang::Stmt>> ConstantMatchers = {
+ const std::vector<Matcher<clang::Stmt>> ConstantMatchers = {
Matches.matchLog2Euler(), Matches.matchLog10Euler(),
Matches.matchEulerTopLevel(), Matches.matchEgamma(),
Matches.matchInvSqrtPi(), Matches.matchInvPi(),
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
index 99ade04..1ab9576 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
@@ -36,7 +36,6 @@ UseStdPrintCheck::UseStdPrintCheck(StringRef Name, ClangTidyContext *Context)
utils::IncludeSorter::IS_LLVM),
areDiagsSelfContained()),
MaybeHeaderToInclude(Options.get("PrintHeader")) {
-
if (PrintfLikeFunctions.empty() && FprintfLikeFunctions.empty()) {
PrintfLikeFunctions.emplace_back("::printf");
PrintfLikeFunctions.emplace_back("absl::PrintF");
@@ -70,8 +69,8 @@ void UseStdPrintCheck::registerPPCallbacks(const SourceManager &SM,
this->PP = PP;
}
-static clang::ast_matchers::StatementMatcher
-unusedReturnValue(clang::ast_matchers::StatementMatcher MatchedCallExpr) {
+static clang::ast_matchers::StatementMatcher unusedReturnValue(
+ const clang::ast_matchers::StatementMatcher &MatchedCallExpr) {
auto UnusedInCompoundStmt =
compoundStmt(forEach(MatchedCallExpr),
// The checker can't currently differentiate between the
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.h b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.h
index f5b3f71..7d771c4 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_USESTDPRINTCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_USESTDPRINTCHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDPRINTCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDPRINTCHECK_H
#include "../ClangTidyCheck.h"
#include "../utils/IncludeInserter.h"
@@ -36,7 +36,7 @@ public:
}
private:
- Preprocessor *PP;
+ Preprocessor *PP = nullptr;
bool StrictMode;
std::vector<StringRef> PrintfLikeFunctions;
std::vector<StringRef> FprintfLikeFunctions;
@@ -48,4 +48,4 @@ private:
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_USESTDPRINTCHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDPRINTCHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
index d623ec4..02865b6 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
@@ -55,13 +55,12 @@ public:
bool visitUnqualName(StringRef UnqualName) {
// Check for collisions with function arguments.
- for (ParmVarDecl *Param : F.parameters())
+ Collision = llvm::any_of(F.parameters(), [&](const ParmVarDecl *Param) {
if (const IdentifierInfo *Ident = Param->getIdentifier())
- if (Ident->getName() == UnqualName) {
- Collision = true;
- return true;
- }
- return false;
+ return Ident->getName() == UnqualName;
+ return false;
+ });
+ return Collision;
}
bool TraverseTypeLoc(TypeLoc TL, bool TraverseQualifier = true) {
@@ -126,7 +125,7 @@ public:
}
bool VisitDeclRefExpr(DeclRefExpr *S) {
- DeclarationName Name = S->getNameInfo().getName();
+ const DeclarationName Name = S->getNameInfo().getName();
return S->getQualifierLoc() || Name.isEmpty() || !Name.isIdentifier() ||
!visitUnqualName(Name.getAsIdentifierInfo()->getName());
}
@@ -159,14 +158,14 @@ static SourceLocation findTrailingReturnTypeSourceLocation(
const FunctionDecl &F, const FunctionTypeLoc &FTL, const ASTContext &Ctx,
const SourceManager &SM, const LangOptions &LangOpts) {
// We start with the location of the closing parenthesis.
- SourceRange ExceptionSpecRange = F.getExceptionSpecSourceRange();
+ const SourceRange ExceptionSpecRange = F.getExceptionSpecSourceRange();
if (ExceptionSpecRange.isValid())
return Lexer::getLocForEndOfToken(ExceptionSpecRange.getEnd(), 0, SM,
LangOpts);
// If the function argument list ends inside of a macro, it is dangerous to
// start lexing from here - bail out.
- SourceLocation ClosingParen = FTL.getRParenLoc();
+ const SourceLocation ClosingParen = FTL.getRParenLoc();
if (ClosingParen.isMacroID())
return {};
@@ -174,8 +173,8 @@ static SourceLocation findTrailingReturnTypeSourceLocation(
Lexer::getLocForEndOfToken(ClosingParen, 0, SM, LangOpts);
// Skip subsequent CV and ref qualifiers.
- std::pair<FileID, unsigned> Loc = SM.getDecomposedLoc(Result);
- StringRef File = SM.getBufferData(Loc.first);
+ const std::pair<FileID, unsigned> Loc = SM.getDecomposedLoc(Result);
+ const StringRef File = SM.getBufferData(Loc.first);
const char *TokenBegin = File.data() + Loc.second;
Lexer Lexer(SM.getLocForStartOfFile(Loc.first), LangOpts, File.begin(),
TokenBegin, File.end());
@@ -220,7 +219,7 @@ classifyToken(const FunctionDecl &F, Preprocessor &PP, Token Tok) {
Token End;
End.startToken();
End.setKind(tok::eof);
- SmallVector<Token, 2> Stream{Tok, End};
+ const SmallVector<Token, 2> Stream{Tok, End};
// FIXME: do not report these token to Preprocessor.TokenWatcher.
PP.EnterTokenStream(Stream, false, /*IsReinject=*/false);
@@ -230,8 +229,8 @@ classifyToken(const FunctionDecl &F, Preprocessor &PP, Token Tok) {
if (T.is(tok::eof))
break;
- bool Qual = isCvr(T);
- bool Spec = isSpecifier(T);
+ const bool Qual = isCvr(T);
+ const bool Spec = isSpecifier(T);
CT.IsQualifier &= Qual;
CT.IsSpecifier &= Spec;
ContainsQualifiers |= Qual;
@@ -252,12 +251,12 @@ classifyTokensBeforeFunctionName(const FunctionDecl &F, const ASTContext &Ctx,
const SourceManager &SM,
const LangOptions &LangOpts,
Preprocessor *PP) {
- SourceLocation BeginF = expandIfMacroId(F.getBeginLoc(), SM);
- SourceLocation BeginNameF = expandIfMacroId(F.getLocation(), SM);
+ const SourceLocation BeginF = expandIfMacroId(F.getBeginLoc(), SM);
+ const SourceLocation BeginNameF = expandIfMacroId(F.getLocation(), SM);
// Create tokens for everything before the name of the function.
- std::pair<FileID, unsigned> Loc = SM.getDecomposedLoc(BeginF);
- StringRef File = SM.getBufferData(Loc.first);
+ const std::pair<FileID, unsigned> Loc = SM.getDecomposedLoc(BeginF);
+ const StringRef File = SM.getBufferData(Loc.first);
const char *TokenBegin = File.data() + Loc.second;
Lexer Lexer(SM.getLocForStartOfFile(Loc.first), LangOpts, File.begin(),
TokenBegin, File.end());
@@ -305,7 +304,6 @@ static SourceRange
findReturnTypeAndCVSourceRange(const FunctionDecl &F, const TypeLoc &ReturnLoc,
const ASTContext &Ctx, const SourceManager &SM,
const LangOptions &LangOpts, Preprocessor *PP) {
-
// We start with the range of the return type and expand to neighboring
// qualifiers (const, volatile and restrict).
SourceRange ReturnTypeRange = F.getReturnTypeSourceRange();
@@ -369,9 +367,9 @@ static SourceLocation findLambdaTrailingReturnInsertLoc(
else
ParamEndLoc = Method->getParametersSourceRange().getEnd();
- std::pair<FileID, unsigned> ParamEndLocInfo =
+ const std::pair<FileID, unsigned> ParamEndLocInfo =
SM.getDecomposedLoc(ParamEndLoc);
- StringRef Buffer = SM.getBufferData(ParamEndLocInfo.first);
+ const StringRef Buffer = SM.getBufferData(ParamEndLocInfo.first);
Lexer Lexer(SM.getLocForStartOfFile(ParamEndLocInfo.first), LangOpts,
Buffer.begin(), Buffer.data() + ParamEndLocInfo.second,
@@ -421,11 +419,11 @@ static void keepSpecifiers(std::string &ReturnType, std::string &Auto,
return;
// Find specifiers, remove them from the return type, add them to 'auto'.
- unsigned int ReturnTypeBeginOffset =
+ const unsigned int ReturnTypeBeginOffset =
SM.getDecomposedLoc(ReturnTypeCVRange.getBegin()).second;
- size_t InitialAutoLength = Auto.size();
+ const size_t InitialAutoLength = Auto.size();
unsigned int DeletedChars = 0;
- for (ClassifiedToken CT : *MaybeTokens) {
+ for (const ClassifiedToken CT : *MaybeTokens) {
if (SM.isBeforeInTranslationUnit(CT.T.getLocation(),
ReturnTypeCVRange.getBegin()) ||
SM.isBeforeInTranslationUnit(ReturnTypeCVRange.getEnd(),
@@ -436,10 +434,11 @@ static void keepSpecifiers(std::string &ReturnType, std::string &Auto,
// Add the token to 'auto' and remove it from the return type, including
// any whitespace following the token.
- unsigned int TOffset = SM.getDecomposedLoc(CT.T.getLocation()).second;
+ const unsigned int TOffset = SM.getDecomposedLoc(CT.T.getLocation()).second;
assert(TOffset >= ReturnTypeBeginOffset &&
"Token location must be after the beginning of the return type");
- unsigned int TOffsetInRT = TOffset - ReturnTypeBeginOffset - DeletedChars;
+ const unsigned int TOffsetInRT =
+ TOffset - ReturnTypeBeginOffset - DeletedChars;
unsigned int TLengthWithWS = CT.T.getLength();
while (TOffsetInRT + TLengthWithWS < ReturnType.size() &&
llvm::isSpace(ReturnType[TOffsetInRT + TLengthWithWS]))
@@ -458,7 +457,6 @@ UseTrailingReturnTypeCheck::UseTrailingReturnTypeCheck(
: ClangTidyCheck(Name, Context),
TransformFunctions(Options.get("TransformFunctions", true)),
TransformLambdas(Options.get("TransformLambdas", TransformLambda::All)) {
-
if (TransformFunctions == false && TransformLambdas == TransformLambda::None)
this->configurationDiag(
"The check 'modernize-use-trailing-return-type' will not perform any "
@@ -548,7 +546,7 @@ void UseTrailingReturnTypeCheck::check(const MatchFinder::MatchResult &Result) {
return;
}
- SourceLocation InsertionLoc =
+ const SourceLocation InsertionLoc =
findTrailingReturnTypeSourceLocation(*F, FTL, Ctx, SM, LangOpts);
if (InsertionLoc.isInvalid()) {
diag(F->getLocation(), ErrorMessageOnFunction);
@@ -558,7 +556,7 @@ void UseTrailingReturnTypeCheck::check(const MatchFinder::MatchResult &Result) {
// Using the declared return type via F->getDeclaredReturnType().getAsString()
// discards user formatting and order of const, volatile, type, whitespace,
// space before & ... .
- SourceRange ReturnTypeCVRange = findReturnTypeAndCVSourceRange(
+ const SourceRange ReturnTypeCVRange = findReturnTypeAndCVSourceRange(
*F, FTL.getReturnLoc(), Ctx, SM, LangOpts, PP);
if (ReturnTypeCVRange.isInvalid()) {
diag(F->getLocation(), ErrorMessageOnFunction);
@@ -580,13 +578,13 @@ void UseTrailingReturnTypeCheck::check(const MatchFinder::MatchResult &Result) {
return;
}
- SourceLocation ReturnTypeEnd =
+ const SourceLocation ReturnTypeEnd =
Lexer::getLocForEndOfToken(ReturnTypeCVRange.getEnd(), 0, SM, LangOpts);
- StringRef CharAfterReturnType = Lexer::getSourceText(
+ const StringRef CharAfterReturnType = Lexer::getSourceText(
CharSourceRange::getCharRange(ReturnTypeEnd,
ReturnTypeEnd.getLocWithOffset(1)),
SM, LangOpts);
- bool NeedSpaceAfterAuto =
+ const bool NeedSpaceAfterAuto =
CharAfterReturnType.empty() || !llvm::isSpace(CharAfterReturnType[0]);
std::string Auto = NeedSpaceAfterAuto ? "auto " : "auto";
@@ -603,7 +601,6 @@ void UseTrailingReturnTypeCheck::check(const MatchFinder::MatchResult &Result) {
void UseTrailingReturnTypeCheck::diagOnLambda(
const LambdaExpr *Lambda,
const ast_matchers::MatchFinder::MatchResult &Result) {
-
const CXXMethodDecl *Method = Lambda->getCallOperator();
if (!Method || Lambda->hasExplicitResultType())
return;
diff --git a/clang-tools-extra/clang-tidy/modernize/UseTransparentFunctorsCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseTransparentFunctorsCheck.cpp
index 03ecec9..e3672f8 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseTransparentFunctorsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseTransparentFunctorsCheck.cpp
@@ -96,7 +96,7 @@ void UseTransparentFunctorsCheck::check(
FunctorParentType->template_arguments()[ArgNum];
if (Arg.getKind() != TemplateArgument::Type)
continue;
- QualType ParentArgType = Arg.getAsType();
+ const QualType ParentArgType = Arg.getAsType();
if (ParentArgType->isRecordType() &&
ParentArgType->getAsCXXRecordDecl() ==
Functor->getAsType()->getAsCXXRecordDecl())
@@ -105,13 +105,13 @@ void UseTransparentFunctorsCheck::check(
// Functor is a default template argument.
if (ArgNum == FunctorParentType->template_arguments().size())
return;
- TemplateArgumentLoc FunctorLoc = FunctorParentLoc.getArgLoc(ArgNum);
+ const TemplateArgumentLoc FunctorLoc = FunctorParentLoc.getArgLoc(ArgNum);
auto FunctorTypeLoc = getInnerTypeLocAs<TemplateSpecializationTypeLoc>(
FunctorLoc.getTypeSourceInfo()->getTypeLoc());
if (FunctorTypeLoc.isNull())
return;
- SourceLocation ReportLoc = FunctorLoc.getLocation();
+ const SourceLocation ReportLoc = FunctorLoc.getLocation();
if (ReportLoc.isInvalid())
return;
diag(ReportLoc, Message) << FuncClass->getName()
diff --git a/clang-tools-extra/clang-tidy/modernize/UseTransparentFunctorsCheck.h b/clang-tools-extra/clang-tidy/modernize/UseTransparentFunctorsCheck.h
index 0af729b..936eaf1 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseTransparentFunctorsCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseTransparentFunctorsCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_TRANSPARENT_FUNCTORS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_TRANSPARENT_FUNCTORS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USETRANSPARENTFUNCTORSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USETRANSPARENTFUNCTORSCHECK_H
#include "../ClangTidyCheck.h"
@@ -33,4 +33,4 @@ private:
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_TRANSPARENT_FUNCTORS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USETRANSPARENTFUNCTORSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/UseUncaughtExceptionsCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseUncaughtExceptionsCheck.cpp
index eef9d39..08c40d4 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUncaughtExceptionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseUncaughtExceptionsCheck.cpp
@@ -15,7 +15,7 @@ using namespace clang::ast_matchers;
namespace clang::tidy::modernize {
void UseUncaughtExceptionsCheck::registerMatchers(MatchFinder *Finder) {
- std::string MatchText = "::std::uncaught_exception";
+ const std::string MatchText = "::std::uncaught_exception";
// Using declaration: warning and fix-it.
Finder->addMatcher(
@@ -78,7 +78,7 @@ void UseUncaughtExceptionsCheck::check(const MatchFinder::MatchResult &Result) {
*Result.SourceManager, getLangOpts());
Text.consume_back("()");
- int TextLength = Text.size();
+ const int TextLength = Text.size();
if (WarnOnly) {
return;
diff --git a/clang-tools-extra/clang-tidy/modernize/UseUncaughtExceptionsCheck.h b/clang-tools-extra/clang-tidy/modernize/UseUncaughtExceptionsCheck.h
index 772133d..09b0ba5 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUncaughtExceptionsCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseUncaughtExceptionsCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_UNCAUGHT_EXCEPTIONS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_UNCAUGHT_EXCEPTIONS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEUNCAUGHTEXCEPTIONSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEUNCAUGHTEXCEPTIONSCHECK_H
#include "../ClangTidyCheck.h"
@@ -33,4 +33,4 @@ public:
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_UNCAUGHT_EXCEPTIONS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEUNCAUGHTEXCEPTIONSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
index 7267375..38b3689 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -114,7 +114,7 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
if (ExternCDecl && IgnoreExternC)
return;
- SourceLocation StartLoc = MatchedDecl->getBeginLoc();
+ const SourceLocation StartLoc = MatchedDecl->getBeginLoc();
if (StartLoc.isMacroID() && IgnoreMacros)
return;
@@ -172,7 +172,7 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
.str(),
ExtraReference.str()};
}();
- StringRef Name = MatchedDecl->getName();
+ const StringRef Name = MatchedDecl->getName();
SourceRange ReplaceRange = MatchedDecl->getSourceRange();
// typedefs with multiple comma-separated definitions produce multiple
@@ -223,7 +223,8 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
return;
}
- std::string Replacement = (Using + Name + " = " + Type + QualifierStr).str();
+ const std::string Replacement =
+ (Using + Name + " = " + Type + QualifierStr).str();
Diag << FixItHint::CreateReplacement(ReplaceRange, Replacement);
}
} // namespace clang::tidy::modernize
diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h
index 5ecabc7..07d15fa 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_USING_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_USING_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEUSINGCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEUSINGCHECK_H
#include "../ClangTidyCheck.h"
@@ -18,7 +18,6 @@ namespace clang::tidy::modernize {
/// For the user-facing documentation see:
/// https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-using.html
class UseUsingCheck : public ClangTidyCheck {
-
const bool IgnoreMacros;
const bool IgnoreExternC;
SourceLocation LastReplacementEnd;
@@ -40,4 +39,4 @@ public:
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_USING_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEUSINGCHECK_H
diff --git a/clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.h b/clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.h
index 07ee68a..a44ef31 100644
--- a/clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.h
+++ b/clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MPI_BUFFER_DEREF_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MPI_BUFFER_DEREF_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MPI_BUFFERDEREFCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MPI_BUFFERDEREFCHECK_H
#include "../ClangTidyCheck.h"
#include "clang/StaticAnalyzer/Checkers/MPIFunctionClassifier.h"
@@ -48,4 +48,4 @@ private:
} // namespace clang::tidy::mpi
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MPI_BUFFER_DEREF_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MPI_BUFFERDEREFCHECK_H
diff --git a/clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.cpp b/clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.cpp
index 17c1283b..370a54d 100644
--- a/clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.cpp
+++ b/clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.cpp
@@ -41,39 +41,39 @@ isMPITypeMatching(const std::multimap<BuiltinType::Kind, StringRef> &MultiMap,
///
/// \returns true if the type is a standard type
static bool isStandardMPIDatatype(StringRef MPIDatatype) {
- static llvm::StringSet<> AllTypes = {"MPI_C_BOOL",
- "MPI_CHAR",
- "MPI_SIGNED_CHAR",
- "MPI_UNSIGNED_CHAR",
- "MPI_WCHAR",
- "MPI_INT",
- "MPI_LONG",
- "MPI_SHORT",
- "MPI_LONG_LONG",
- "MPI_LONG_LONG_INT",
- "MPI_UNSIGNED",
- "MPI_UNSIGNED_SHORT",
- "MPI_UNSIGNED_LONG",
- "MPI_UNSIGNED_LONG_LONG",
- "MPI_FLOAT",
- "MPI_DOUBLE",
- "MPI_LONG_DOUBLE",
- "MPI_C_COMPLEX",
- "MPI_C_FLOAT_COMPLEX",
- "MPI_C_DOUBLE_COMPLEX",
- "MPI_C_LONG_DOUBLE_COMPLEX",
- "MPI_INT8_T",
- "MPI_INT16_T",
- "MPI_INT32_T",
- "MPI_INT64_T",
- "MPI_UINT8_T",
- "MPI_UINT16_T",
- "MPI_UINT32_T",
- "MPI_UINT64_T",
- "MPI_CXX_BOOL",
- "MPI_CXX_FLOAT_COMPLEX",
- "MPI_CXX_DOUBLE_COMPLEX",
- "MPI_CXX_LONG_DOUBLE_COMPLEX"};
+ static const llvm::StringSet<> AllTypes = {"MPI_C_BOOL",
+ "MPI_CHAR",
+ "MPI_SIGNED_CHAR",
+ "MPI_UNSIGNED_CHAR",
+ "MPI_WCHAR",
+ "MPI_INT",
+ "MPI_LONG",
+ "MPI_SHORT",
+ "MPI_LONG_LONG",
+ "MPI_LONG_LONG_INT",
+ "MPI_UNSIGNED",
+ "MPI_UNSIGNED_SHORT",
+ "MPI_UNSIGNED_LONG",
+ "MPI_UNSIGNED_LONG_LONG",
+ "MPI_FLOAT",
+ "MPI_DOUBLE",
+ "MPI_LONG_DOUBLE",
+ "MPI_C_COMPLEX",
+ "MPI_C_FLOAT_COMPLEX",
+ "MPI_C_DOUBLE_COMPLEX",
+ "MPI_C_LONG_DOUBLE_COMPLEX",
+ "MPI_INT8_T",
+ "MPI_INT16_T",
+ "MPI_INT32_T",
+ "MPI_INT64_T",
+ "MPI_UINT8_T",
+ "MPI_UINT16_T",
+ "MPI_UINT32_T",
+ "MPI_UINT64_T",
+ "MPI_CXX_BOOL",
+ "MPI_CXX_FLOAT_COMPLEX",
+ "MPI_CXX_DOUBLE_COMPLEX",
+ "MPI_CXX_LONG_DOUBLE_COMPLEX"};
return AllTypes.contains(MPIDatatype);
}
@@ -90,7 +90,7 @@ static bool isBuiltinTypeMatching(const BuiltinType *Builtin,
std::string &BufferTypeName,
StringRef MPIDatatype,
const LangOptions &LO) {
- static std::multimap<BuiltinType::Kind, StringRef> BuiltinMatches = {
+ static const std::multimap<BuiltinType::Kind, StringRef> BuiltinMatches = {
// On some systems like PPC or ARM, 'char' is unsigned by default which is
// why distinct signedness for the buffer and MPI type is tolerated.
{BuiltinType::SChar, "MPI_CHAR"},
@@ -143,7 +143,7 @@ static bool isCComplexTypeMatching(const ComplexType *const Complex,
std::string &BufferTypeName,
StringRef MPIDatatype,
const LangOptions &LO) {
- static std::multimap<BuiltinType::Kind, StringRef> ComplexCMatches = {
+ static const std::multimap<BuiltinType::Kind, StringRef> ComplexCMatches = {
{BuiltinType::Float, "MPI_C_COMPLEX"},
{BuiltinType::Float, "MPI_C_FLOAT_COMPLEX"},
{BuiltinType::Double, "MPI_C_DOUBLE_COMPLEX"},
@@ -173,7 +173,7 @@ static bool
isCXXComplexTypeMatching(const TemplateSpecializationType *const Template,
std::string &BufferTypeName, StringRef MPIDatatype,
const LangOptions &LO) {
- static std::multimap<BuiltinType::Kind, StringRef> ComplexCXXMatches = {
+ static const std::multimap<BuiltinType::Kind, StringRef> ComplexCXXMatches = {
{BuiltinType::Float, "MPI_CXX_FLOAT_COMPLEX"},
{BuiltinType::Double, "MPI_CXX_DOUBLE_COMPLEX"},
{BuiltinType::LongDouble, "MPI_CXX_LONG_DOUBLE_COMPLEX"}};
@@ -264,7 +264,7 @@ void TypeMismatchCheck::check(const MatchFinder::MatchResult &Result) {
"MPI_IN_PLACE")
return;
- StringRef MPIDatatype =
+ const StringRef MPIDatatype =
tooling::fixit::getText(*CE->getArg(DatatypeIdx), *Result.Context);
const Type *ArgType = argumentType(CE, BufferIdx);
diff --git a/clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.h b/clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.h
index 5a7db17..043f99e 100644
--- a/clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.h
+++ b/clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MPI_TYPE_MISMATCH_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MPI_TYPE_MISMATCH_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MPI_TYPEMISMATCHCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MPI_TYPEMISMATCHCHECK_H
#include "../ClangTidyCheck.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -49,4 +49,4 @@ private:
} // namespace clang::tidy::mpi
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MPI_TYPE_MISMATCH_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MPI_TYPEMISMATCHCHECK_H
diff --git a/clang-tools-extra/clang-tidy/objc/AssertEquals.cpp b/clang-tools-extra/clang-tidy/objc/AssertEqualsCheck.cpp
index 3f1bc17..a9e6a4b 100644
--- a/clang-tools-extra/clang-tidy/objc/AssertEquals.cpp
+++ b/clang-tools-extra/clang-tidy/objc/AssertEqualsCheck.cpp
@@ -6,9 +6,9 @@
//
//===----------------------------------------------------------------------===//
-#include "AssertEquals.h"
+#include "AssertEqualsCheck.h"
+#include "llvm/ADT/StringMap.h"
-#include <map>
#include <string>
using namespace clang::ast_matchers;
@@ -16,44 +16,40 @@ using namespace clang::ast_matchers;
namespace clang::tidy::objc {
// Mapping from `XCTAssert*Equal` to `XCTAssert*EqualObjects` name.
-static const std::map<std::string, std::string> &nameMap() {
- static std::map<std::string, std::string> Map{
- {"XCTAssertEqual", "XCTAssertEqualObjects"},
- {"XCTAssertNotEqual", "XCTAssertNotEqualObjects"},
+static const llvm::StringMap<StringRef> NameMap{
+ {"XCTAssertEqual", "XCTAssertEqualObjects"},
+ {"XCTAssertNotEqual", "XCTAssertNotEqualObjects"},
+};
- };
- return Map;
-}
-
-void AssertEquals::registerMatchers(MatchFinder *Finder) {
- for (const auto &Pair : nameMap()) {
+void AssertEqualsCheck::registerMatchers(MatchFinder *Finder) {
+ for (const auto &[CurrName, _] : NameMap) {
Finder->addMatcher(
binaryOperator(anyOf(hasOperatorName("!="), hasOperatorName("==")),
- isExpandedFromMacro(Pair.first),
+ isExpandedFromMacro(std::string(CurrName)),
anyOf(hasLHS(hasType(qualType(
hasCanonicalType(asString("NSString *"))))),
hasRHS(hasType(qualType(
- hasCanonicalType(asString("NSString *"))))))
-
- )
- .bind(Pair.first),
+ hasCanonicalType(asString("NSString *")))))))
+ .bind(CurrName),
this);
}
}
-void AssertEquals::check(const ast_matchers::MatchFinder::MatchResult &Result) {
- for (const auto &Pair : nameMap()) {
- if (const auto *Root = Result.Nodes.getNodeAs<BinaryOperator>(Pair.first)) {
- SourceManager *Sm = Result.SourceManager;
+void AssertEqualsCheck::check(
+ const ast_matchers::MatchFinder::MatchResult &Result) {
+ for (const auto &[CurrName, TargetName] : NameMap) {
+ if (const auto *Root = Result.Nodes.getNodeAs<BinaryOperator>(CurrName)) {
+ const SourceManager *Sm = Result.SourceManager;
// The macros are nested two levels, so going up twice.
auto MacroCallsite = Sm->getImmediateMacroCallerLoc(
Sm->getImmediateMacroCallerLoc(Root->getBeginLoc()));
- diag(MacroCallsite, "use " + Pair.second + " for comparing objects")
+ diag(MacroCallsite,
+ (Twine("use ") + TargetName + " for comparing objects").str())
<< FixItHint::CreateReplacement(
clang::CharSourceRange::getCharRange(
MacroCallsite,
- MacroCallsite.getLocWithOffset(Pair.first.length())),
- Pair.second);
+ MacroCallsite.getLocWithOffset(CurrName.size())),
+ TargetName);
}
}
}
diff --git a/clang-tools-extra/clang-tidy/objc/AssertEquals.h b/clang-tools-extra/clang-tidy/objc/AssertEqualsCheck.h
index 8c21f9b..237daba 100644
--- a/clang-tools-extra/clang-tidy/objc/AssertEquals.h
+++ b/clang-tools-extra/clang-tidy/objc/AssertEqualsCheck.h
@@ -6,22 +6,22 @@
//
//===----------------------------------------------------------------------===//
-#ifndef THIRD_PARTY_LLVM_LLVM_PROJECT_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_OBJCASSERTEQUALS_H_
-#define THIRD_PARTY_LLVM_LLVM_PROJECT_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_OBJCASSERTEQUALS_H_
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_ASSERTEQUALSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_ASSERTEQUALSCHECK_H
#include "../ClangTidyCheck.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
namespace clang::tidy::objc {
-/// Warn if XCTAssertEqual() or XCTAssertNotEqual() is used with at least one
+/// Warns if XCTAssertEqual() or XCTAssertNotEqual() is used with at least one
/// operands of type NSString*.
///
/// For the user-facing documentation see:
/// https://clang.llvm.org/extra/clang-tidy/checks/objc/assert-equals.html
-class AssertEquals final : public ClangTidyCheck {
+class AssertEqualsCheck final : public ClangTidyCheck {
public:
- AssertEquals(StringRef Name, ClangTidyContext *Context)
+ AssertEqualsCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.ObjC;
@@ -32,4 +32,4 @@ public:
} // namespace clang::tidy::objc
-#endif // THIRD_PARTY_LLVM_LLVM_PROJECT_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_OBJCASSERTEQUALS_H_
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_ASSERTEQUALSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/objc/CMakeLists.txt b/clang-tools-extra/clang-tidy/objc/CMakeLists.txt
index e28d25d..2908d11 100644
--- a/clang-tools-extra/clang-tidy/objc/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/objc/CMakeLists.txt
@@ -4,7 +4,7 @@ set(LLVM_LINK_COMPONENTS
)
add_clang_library(clangTidyObjCModule STATIC
- AssertEquals.cpp
+ AssertEqualsCheck.cpp
AvoidNSErrorInitCheck.cpp
DeallocInCategoryCheck.cpp
ForbiddenSubclassingCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/objc/ForbiddenSubclassingCheck.h b/clang-tools-extra/clang-tidy/objc/ForbiddenSubclassingCheck.h
index 2d23869..6e0a12a 100644
--- a/clang-tools-extra/clang-tidy/objc/ForbiddenSubclassingCheck.h
+++ b/clang-tools-extra/clang-tidy/objc/ForbiddenSubclassingCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_FORBIDDEN_SUBCLASSING_CHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_FORBIDDEN_SUBCLASSING_CHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_FORBIDDENSUBCLASSINGCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_FORBIDDENSUBCLASSINGCHECK_H
#include "../ClangTidyCheck.h"
#include "llvm/ADT/StringRef.h"
@@ -36,4 +36,4 @@ private:
} // namespace clang::tidy::objc
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_FORBIDDEN_SUBCLASSING_CHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_FORBIDDENSUBCLASSINGCHECK_H
diff --git a/clang-tools-extra/clang-tidy/objc/MissingHashCheck.cpp b/clang-tools-extra/clang-tidy/objc/MissingHashCheck.cpp
index 7b48fd9..b8010e0 100644
--- a/clang-tools-extra/clang-tidy/objc/MissingHashCheck.cpp
+++ b/clang-tools-extra/clang-tidy/objc/MissingHashCheck.cpp
@@ -25,11 +25,9 @@ AST_MATCHER_P(ObjCImplementationDecl, hasInterface,
AST_MATCHER_P(ObjCContainerDecl, hasInstanceMethod,
ast_matchers::internal::Matcher<ObjCMethodDecl>, Base) {
// Check each instance method against the provided matcher.
- for (const auto *I : Node.instance_methods()) {
- if (Base.matches(*I, Finder, Builder))
- return true;
- }
- return false;
+ return llvm::any_of(Node.instance_methods(), [&](const ObjCMethodDecl *I) {
+ return Base.matches(*I, Finder, Builder);
+ });
}
} // namespace
diff --git a/clang-tools-extra/clang-tidy/objc/NSDateFormatterCheck.cpp b/clang-tools-extra/clang-tidy/objc/NSDateFormatterCheck.cpp
index 1481b2b..31d098e 100644
--- a/clang-tools-extra/clang-tidy/objc/NSDateFormatterCheck.cpp
+++ b/clang-tools-extra/clang-tidy/objc/NSDateFormatterCheck.cpp
@@ -49,7 +49,7 @@ void NSDateFormatterCheck::check(const MatchFinder::MatchResult &Result) {
// Callback implementation.
const auto *StrExpr = Result.Nodes.getNodeAs<ObjCStringLiteral>("str_lit");
const StringLiteral *SL = cast<ObjCStringLiteral>(StrExpr)->getString();
- StringRef SR = SL->getString();
+ const StringRef SR = SL->getString();
if (!isValidDatePattern(SR)) {
diag(StrExpr->getExprLoc(), "invalid date format specifier");
diff --git a/clang-tools-extra/clang-tidy/objc/NSInvocationArgumentLifetimeCheck.cpp b/clang-tools-extra/clang-tidy/objc/NSInvocationArgumentLifetimeCheck.cpp
index 8a32c38..69caaed 100644
--- a/clang-tools-extra/clang-tidy/objc/NSInvocationArgumentLifetimeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/objc/NSInvocationArgumentLifetimeCheck.cpp
@@ -43,7 +43,7 @@ AST_POLYMORPHIC_MATCHER(isObjCManagedLifetime,
AST_POLYMORPHIC_SUPPORTED_TYPES(ObjCIvarRefExpr,
DeclRefExpr,
MemberExpr)) {
- QualType QT = Node.getType();
+ const QualType QT = Node.getType();
return QT->isScalarType() &&
(QT->getScalarTypeKind() == Type::STK_ObjCObjectPointer ||
QT->getScalarTypeKind() == Type::STK_BlockPointer) &&
@@ -55,12 +55,12 @@ AST_POLYMORPHIC_MATCHER(isObjCManagedLifetime,
static std::optional<FixItHint>
fixItHintReplacementForOwnershipString(StringRef Text, CharSourceRange Range,
StringRef Ownership) {
- size_t Index = Text.find(Ownership);
+ const size_t Index = Text.find(Ownership);
if (Index == StringRef::npos)
return std::nullopt;
- SourceLocation Begin = Range.getBegin().getLocWithOffset(Index);
- SourceLocation End = Begin.getLocWithOffset(Ownership.size());
+ const SourceLocation Begin = Range.getBegin().getLocWithOffset(Index);
+ const SourceLocation End = Begin.getLocWithOffset(Ownership.size());
return FixItHint::CreateReplacement(SourceRange(Begin, End),
UnsafeUnretainedText);
}
@@ -76,7 +76,7 @@ fixItHintForVarDecl(const VarDecl *VD, const SourceManager &SM,
// Currently there is no way to directly get the source range for the
// __weak/__strong ObjC lifetime qualifiers, so it's necessary to string
// search in the source code.
- CharSourceRange Range = Lexer::makeFileCharRange(
+ const CharSourceRange Range = Lexer::makeFileCharRange(
CharSourceRange::getTokenRange(VD->getSourceRange()), SM, LangOpts);
if (Range.isInvalid()) {
// An invalid range likely means inside a macro, in which case don't supply
@@ -84,7 +84,7 @@ fixItHintForVarDecl(const VarDecl *VD, const SourceManager &SM,
return std::nullopt;
}
- StringRef VarDeclText = Lexer::getSourceText(Range, SM, LangOpts);
+ const StringRef VarDeclText = Lexer::getSourceText(Range, SM, LangOpts);
if (std::optional<FixItHint> Hint =
fixItHintReplacementForOwnershipString(VarDeclText, Range, WeakText))
return Hint;
diff --git a/clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp b/clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp
index c21b459..411d252 100644
--- a/clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp
@@ -9,7 +9,7 @@
#include "../ClangTidy.h"
#include "../ClangTidyModule.h"
#include "../ClangTidyModuleRegistry.h"
-#include "AssertEquals.h"
+#include "AssertEqualsCheck.h"
#include "AvoidNSErrorInitCheck.h"
#include "DeallocInCategoryCheck.h"
#include "ForbiddenSubclassingCheck.h"
@@ -29,7 +29,7 @@ public:
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
CheckFactories.registerCheck<AvoidNSErrorInitCheck>(
"objc-avoid-nserror-init");
- CheckFactories.registerCheck<AssertEquals>("objc-assert-equals");
+ CheckFactories.registerCheck<AssertEqualsCheck>("objc-assert-equals");
CheckFactories.registerCheck<DeallocInCategoryCheck>(
"objc-dealloc-in-category");
diff --git a/clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp b/clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp
index 4a586c8..690572f 100644
--- a/clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -39,7 +39,7 @@ static FixItHint generateFixItHint(const ObjCPropertyDecl *Decl,
auto NewName = Decl->getName().str();
size_t Index = 0;
if (Style == CategoryProperty) {
- size_t UnderScorePos = Name.find_first_of('_');
+ const size_t UnderScorePos = Name.find_first_of('_');
if (UnderScorePos != llvm::StringRef::npos) {
Index = UnderScorePos + 1;
NewName.replace(0, Index - 1, Name.substr(0, Index - 1).lower());
@@ -74,7 +74,7 @@ static std::string validPropertyNameRegex(bool UsedInMatcher) {
//
// aRbITRaRyCapS is allowed to avoid generating false positives for names
// like isVitaminBSupplement, CProgrammingLanguage, and isBeforeM.
- std::string StartMatcher = UsedInMatcher ? "::" : "^";
+ const std::string StartMatcher = UsedInMatcher ? "::" : "^";
return StartMatcher + "([a-z]|[A-Z][A-Z0-9])[a-z0-9A-Z]*$";
}
@@ -85,7 +85,7 @@ static bool hasCategoryPropertyPrefix(llvm::StringRef PropertyName) {
}
static bool prefixedPropertyNameValid(llvm::StringRef PropertyName) {
- size_t Start = PropertyName.find_first_of('_');
+ const size_t Start = PropertyName.find_first_of('_');
assert(Start != llvm::StringRef::npos && Start + 1 < PropertyName.size());
auto Prefix = PropertyName.substr(0, Start);
if (Prefix.lower() != Prefix) {
@@ -115,8 +115,9 @@ void PropertyDeclarationCheck::check(const MatchFinder::MatchResult &Result) {
hasCategoryPropertyPrefix(MatchedDecl->getName())) {
if (!prefixedPropertyNameValid(MatchedDecl->getName()) ||
CategoryDecl->IsClassExtension()) {
- NamingStyle Style = CategoryDecl->IsClassExtension() ? StandardProperty
- : CategoryProperty;
+ const NamingStyle Style = CategoryDecl->IsClassExtension()
+ ? StandardProperty
+ : CategoryProperty;
diag(MatchedDecl->getLocation(),
"property name '%0' not using lowerCamelCase style or not prefixed "
"in a category, according to the Apple Coding Guidelines")
diff --git a/clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.h b/clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.h
index daaebb1..1e185b9 100644
--- a/clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.h
+++ b/clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_PROPERTY_DECLARATION_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_PROPERTY_DECLARATION_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_PROPERTYDECLARATIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_PROPERTYDECLARATIONCHECK_H
#include "../ClangTidyCheck.h"
@@ -34,4 +34,4 @@ public:
} // namespace clang::tidy::objc
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_PROPERTY_DECLARATION_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_PROPERTYDECLARATIONCHECK_H
diff --git a/clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp b/clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp
index 3c133ad..3887afe7 100644
--- a/clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp
+++ b/clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp
@@ -90,11 +90,11 @@ void SuperSelfCheck::check(const MatchFinder::MatchResult &Result) {
"invoke a superclass initializer?")
<< Message->getMethodDecl();
- SourceLocation ReceiverLoc = Message->getReceiverRange().getBegin();
+ const SourceLocation ReceiverLoc = Message->getReceiverRange().getBegin();
if (ReceiverLoc.isMacroID() || ReceiverLoc.isInvalid())
return;
- SourceLocation SelectorLoc = Message->getSelectorStartLoc();
+ const SourceLocation SelectorLoc = Message->getSelectorStartLoc();
if (SelectorLoc.isMacroID() || SelectorLoc.isInvalid())
return;
diff --git a/clang-tools-extra/clang-tidy/openmp/UseDefaultNoneCheck.cpp b/clang-tools-extra/clang-tidy/openmp/UseDefaultNoneCheck.cpp
index d02ab72..5bd842b 100644
--- a/clang-tools-extra/clang-tidy/openmp/UseDefaultNoneCheck.cpp
+++ b/clang-tools-extra/clang-tidy/openmp/UseDefaultNoneCheck.cpp
@@ -37,8 +37,9 @@ void UseDefaultNoneCheck::check(const MatchFinder::MatchResult &Result) {
"OpenMP directive '%0' specifies 'default(%1)' clause, consider using "
"'default(none)' clause instead")
<< getOpenMPDirectiveName(Directive->getDirectiveKind())
- << getOpenMPSimpleClauseTypeName(Clause->getClauseKind(),
- unsigned(Clause->getDefaultKind()));
+ << getOpenMPSimpleClauseTypeName(
+ Clause->getClauseKind(),
+ llvm::to_underlying(Clause->getDefaultKind()));
diag(Clause->getBeginLoc(), "existing 'default' clause specified here",
DiagnosticIDs::Note);
return;
diff --git a/clang-tools-extra/clang-tidy/performance/CMakeLists.txt b/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
index c6e547c..9a2f900 100644
--- a/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
@@ -23,7 +23,7 @@ add_clang_library(clangTidyPerformanceModule STATIC
PerformanceTidyModule.cpp
TriviallyDestructibleCheck.cpp
TypePromotionInMathFnCheck.cpp
- UnnecessaryCopyInitialization.cpp
+ UnnecessaryCopyInitializationCheck.cpp
UnnecessaryValueParamCheck.cpp
LINK_LIBS
diff --git a/clang-tools-extra/clang-tidy/performance/FasterStringFindCheck.h b/clang-tools-extra/clang-tidy/performance/FasterStringFindCheck.h
index 2452d2e..74067c1 100644
--- a/clang-tools-extra/clang-tidy/performance/FasterStringFindCheck.h
+++ b/clang-tools-extra/clang-tidy/performance/FasterStringFindCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_FASTER_STRING_FIND_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_FASTER_STRING_FIND_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_FASTERSTRINGFINDCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_FASTERSTRINGFINDCHECK_H
#include "../ClangTidyCheck.h"
@@ -38,4 +38,4 @@ private:
} // namespace clang::tidy::performance
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_FASTER_STRING_FIND_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_FASTERSTRINGFINDCHECK_H
diff --git a/clang-tools-extra/clang-tidy/performance/ImplicitConversionInLoopCheck.cpp b/clang-tools-extra/clang-tidy/performance/ImplicitConversionInLoopCheck.cpp
index a558954b..74a76fa 100644
--- a/clang-tools-extra/clang-tidy/performance/ImplicitConversionInLoopCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/ImplicitConversionInLoopCheck.cpp
@@ -87,8 +87,8 @@ void ImplicitConversionInLoopCheck::reportAndFix(const ASTContext *Context,
const Expr *OperatorCall) {
// We only match on const ref, so we should print a const ref version of the
// type.
- QualType ConstType = OperatorCall->getType().withConst();
- QualType ConstRefType = Context->getLValueReferenceType(ConstType);
+ const QualType ConstType = OperatorCall->getType().withConst();
+ const QualType ConstRefType = Context->getLValueReferenceType(ConstType);
const char Message[] =
"the type of the loop variable %0 is different from the one returned "
"by the iterator and generates an implicit conversion; you can either "
diff --git a/clang-tools-extra/clang-tidy/performance/ImplicitConversionInLoopCheck.h b/clang-tools-extra/clang-tidy/performance/ImplicitConversionInLoopCheck.h
index 786081a..4690caa 100644
--- a/clang-tools-extra/clang-tidy/performance/ImplicitConversionInLoopCheck.h
+++ b/clang-tools-extra/clang-tidy/performance/ImplicitConversionInLoopCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_IMPLICIT_CONVERSION_IN_LOOP_CHECK_H_
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_IMPLICIT_CONVERSION_IN_LOOP_CHECK_H_
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_IMPLICITCONVERSIONINLOOPCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_IMPLICITCONVERSIONINLOOPCHECK_H
#include "../ClangTidyCheck.h"
@@ -33,4 +33,4 @@ private:
} // namespace clang::tidy::performance
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_IMPLICIT_CONVERSION_IN_LOOP_CHECK_H_
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_IMPLICITCONVERSIONINLOOPCHECK_H
diff --git a/clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp b/clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp
index cd128c3..b57fdb2 100644
--- a/clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp
@@ -71,8 +71,8 @@ void InefficientAlgorithmCheck::check(const MatchFinder::MatchResult &Result) {
// Store if the key type of the container is compatible with the value
// that is searched for.
- QualType ValueType = AlgCall->getArg(2)->getType();
- QualType KeyType =
+ const QualType ValueType = AlgCall->getArg(2)->getType();
+ const QualType KeyType =
IneffCont->getTemplateArgs()[0].getAsType().getCanonicalType();
const bool CompatibleTypes = areTypesCompatible(KeyType, ValueType);
@@ -104,8 +104,8 @@ void InefficientAlgorithmCheck::check(const MatchFinder::MatchResult &Result) {
const auto *IneffContExpr = Result.Nodes.getNodeAs<Expr>("IneffContExpr");
FixItHint Hint;
- SourceManager &SM = *Result.SourceManager;
- LangOptions LangOpts = getLangOpts();
+ const SourceManager &SM = *Result.SourceManager;
+ const LangOptions LangOpts = getLangOpts();
CharSourceRange CallRange =
CharSourceRange::getTokenRange(AlgCall->getSourceRange());
@@ -128,13 +128,13 @@ void InefficientAlgorithmCheck::check(const MatchFinder::MatchResult &Result) {
}
if (!CallRange.getBegin().isMacroID() && !Maplike && CompatibleTypes) {
- StringRef ContainerText = Lexer::getSourceText(
+ const StringRef ContainerText = Lexer::getSourceText(
CharSourceRange::getTokenRange(IneffContExpr->getSourceRange()), SM,
LangOpts);
- StringRef ParamText = Lexer::getSourceText(
+ const StringRef ParamText = Lexer::getSourceText(
CharSourceRange::getTokenRange(AlgParam->getSourceRange()), SM,
LangOpts);
- std::string ReplacementText =
+ const std::string ReplacementText =
(llvm::Twine(ContainerText) + (PtrToContainer ? "->" : ".") +
AlgDecl->getName() + "(" + ParamText + ")")
.str();
diff --git a/clang-tools-extra/clang-tidy/performance/InefficientStringConcatenationCheck.h b/clang-tools-extra/clang-tidy/performance/InefficientStringConcatenationCheck.h
index b82a838..0fae10f 100644
--- a/clang-tools-extra/clang-tidy/performance/InefficientStringConcatenationCheck.h
+++ b/clang-tools-extra/clang-tidy/performance/InefficientStringConcatenationCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENTSTRINGCONCATENATION_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENTSTRINGCONCATENATION_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENTSTRINGCONCATENATIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENTSTRINGCONCATENATIONCHECK_H
#include "../ClangTidyCheck.h"
@@ -35,4 +35,4 @@ private:
} // namespace clang::tidy::performance
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENTSTRINGCONCATENATION_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENTSTRINGCONCATENATIONCHECK_H
diff --git a/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.cpp b/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.cpp
index 4a8f292..a59ab33 100644
--- a/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.cpp
@@ -208,7 +208,7 @@ void InefficientVectorOperationCheck::check(
if (!TargetVarDecl)
TargetVarDecl = ProtoVarDecl;
- llvm::SmallPtrSet<const DeclRefExpr *, 16> AllVarRefs =
+ const llvm::SmallPtrSet<const DeclRefExpr *, 16> AllVarRefs =
utils::decl_ref_expr::allDeclRefExprs(*TargetVarDecl, *LoopParent,
*Context);
for (const auto *Ref : AllVarRefs) {
@@ -231,12 +231,12 @@ void InefficientVectorOperationCheck::check(
} else {
llvm::StringRef FieldName = ProtoAddFieldCall->getMethodDecl()->getName();
FieldName.consume_front("add_");
- std::string MutableFieldName = ("mutable_" + FieldName).str();
+ const std::string MutableFieldName = ("mutable_" + FieldName).str();
PartialReserveStmt = "." + MutableFieldName +
"()->Reserve"; // e.g., ".mutable_xxx()->Reserve"
}
- llvm::StringRef VarName = Lexer::getSourceText(
+ const llvm::StringRef VarName = Lexer::getSourceText(
CharSourceRange::getTokenRange(
AppendCall->getImplicitObjectArgument()->getSourceRange()),
SM, Context->getLangOpts());
@@ -246,14 +246,14 @@ void InefficientVectorOperationCheck::check(
if (RangeLoop) {
// Get the range-expression in a for-range statement represented as
// `for (range-declarator: range-expression)`.
- StringRef RangeInitExpName =
+ const StringRef RangeInitExpName =
Lexer::getSourceText(CharSourceRange::getTokenRange(
RangeLoop->getRangeInit()->getSourceRange()),
SM, Context->getLangOpts());
ReserveSize = (RangeInitExpName + ".size()").str();
} else if (ForLoop) {
// Handle counter-based loop cases.
- StringRef LoopEndSource = Lexer::getSourceText(
+ const StringRef LoopEndSource = Lexer::getSourceText(
CharSourceRange::getTokenRange(LoopEndExpr->getSourceRange()), SM,
Context->getLangOpts());
ReserveSize = std::string(LoopEndSource);
@@ -264,7 +264,7 @@ void InefficientVectorOperationCheck::check(
"container capacity before the loop")
<< AppendCall->getMethodDecl()->getDeclName();
if (!ReserveSize.empty()) {
- std::string ReserveStmt =
+ const std::string ReserveStmt =
(VarName + PartialReserveStmt + "(" + ReserveSize + ");\n").str();
Diag << FixItHint::CreateInsertion(LoopStmt->getBeginLoc(), ReserveStmt);
}
diff --git a/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.h b/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.h
index 18f7c19..5f3b88f 100644
--- a/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.h
+++ b/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENT_VECTOR_OPERATION_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENT_VECTOR_OPERATION_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENTVECTOROPERATIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENTVECTOROPERATIONCHECK_H
#include "../ClangTidyCheck.h"
@@ -44,4 +44,4 @@ private:
} // namespace clang::tidy::performance
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENT_VECTOR_OPERATION_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_INEFFICIENTVECTOROPERATIONCHECK_H
diff --git a/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp b/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
index 854f09a..4d26c39 100644
--- a/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
@@ -19,10 +19,10 @@ static void replaceCallWithArg(const CallExpr *Call, DiagnosticBuilder &Diag,
const LangOptions &LangOpts) {
const Expr *Arg = Call->getArg(0);
- CharSourceRange BeforeArgumentsRange = Lexer::makeFileCharRange(
+ const CharSourceRange BeforeArgumentsRange = Lexer::makeFileCharRange(
CharSourceRange::getCharRange(Call->getBeginLoc(), Arg->getBeginLoc()),
SM, LangOpts);
- CharSourceRange AfterArgumentsRange = Lexer::makeFileCharRange(
+ const CharSourceRange AfterArgumentsRange = Lexer::makeFileCharRange(
CharSourceRange::getCharRange(Call->getEndLoc(),
Call->getEndLoc().getLocWithOffset(1)),
SM, LangOpts);
@@ -114,17 +114,18 @@ void MoveConstArgCheck::check(const MatchFinder::MatchResult &Result) {
const Expr *Arg = CallMove->getArg(0);
const QualType ArgType = Arg->getType().getCanonicalType();
- SourceManager &SM = Result.Context->getSourceManager();
+ const SourceManager &SM = Result.Context->getSourceManager();
- CharSourceRange MoveRange =
+ const CharSourceRange MoveRange =
CharSourceRange::getCharRange(CallMove->getSourceRange());
- CharSourceRange FileMoveRange =
+ const CharSourceRange FileMoveRange =
Lexer::makeFileCharRange(MoveRange, SM, getLangOpts());
if (!FileMoveRange.isValid())
return;
- bool IsConstArg = ArgType.isConstQualified();
- bool IsTriviallyCopyable = ArgType.isTriviallyCopyableType(*Result.Context);
+ const bool IsConstArg = ArgType.isConstQualified();
+ const bool IsTriviallyCopyable =
+ ArgType.isTriviallyCopyableType(*Result.Context);
if (IsConstArg || IsTriviallyCopyable) {
if (const CXXRecordDecl *R = ArgType->getAsCXXRecordDecl()) {
@@ -143,10 +144,10 @@ void MoveConstArgCheck::check(const MatchFinder::MatchResult &Result) {
if (!IsConstArg && IsTriviallyCopyable && !CheckTriviallyCopyableMove)
return;
- bool IsVariable = isa<DeclRefExpr>(Arg);
+ const bool IsVariable = isa<DeclRefExpr>(Arg);
// std::move shouldn't be removed when an lvalue wrapped by std::move is
// passed to the function with an rvalue reference parameter.
- bool IsRVRefParam =
+ const bool IsRVRefParam =
isRValueReferenceParam(ReceivingExpr, InvocationParmType, Arg);
const auto *Var =
IsVariable ? dyn_cast<DeclRefExpr>(Arg)->getDecl() : nullptr;
diff --git a/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.h b/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.h
index 9f67f64..ff1d67b 100644
--- a/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.h
+++ b/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MOVECONSTANTARGUMENTCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MOVECONSTANTARGUMENTCHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_MOVECONSTARGCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_MOVECONSTARGCHECK_H
#include "../ClangTidyCheck.h"
#include "llvm/ADT/DenseSet.h"
@@ -43,4 +43,4 @@ private:
} // namespace clang::tidy::performance
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MOVECONSTANTARGUMENTCHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_MOVECONSTARGCHECK_H
diff --git a/clang-tools-extra/clang-tidy/performance/MoveConstructorInitCheck.cpp b/clang-tools-extra/clang-tidy/performance/MoveConstructorInitCheck.cpp
index 44f6d20..d8cdc0d 100644
--- a/clang-tools-extra/clang-tidy/performance/MoveConstructorInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/MoveConstructorInitCheck.cpp
@@ -39,7 +39,7 @@ void MoveConstructorInitCheck::check(const MatchFinder::MatchResult &Result) {
// Do not diagnose if the expression used to perform the initialization is a
// trivially-copyable type.
- QualType QT = Initializer->getInit()->getType();
+ const QualType QT = Initializer->getInit()->getType();
if (QT.isTriviallyCopyableType(*Result.Context))
return;
diff --git a/clang-tools-extra/clang-tidy/performance/NoexceptFunctionBaseCheck.h b/clang-tools-extra/clang-tidy/performance/NoexceptFunctionBaseCheck.h
index 56a1e4a..6ed3025 100644
--- a/clang-tools-extra/clang-tidy/performance/NoexceptFunctionBaseCheck.h
+++ b/clang-tools-extra/clang-tidy/performance/NoexceptFunctionBaseCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTFUNCTIONCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTFUNCTIONCHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTFUNCTIONBASECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTFUNCTIONBASECHECK_H
#include "../ClangTidyCheck.h"
#include "../utils/ExceptionSpecAnalyzer.h"
@@ -46,4 +46,4 @@ private:
} // namespace clang::tidy::performance
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTFUNCTIONCHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTFUNCTIONBASECHECK_H
diff --git a/clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp b/clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
index 29faf9f..9ab6608 100644
--- a/clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
@@ -17,7 +17,6 @@ using namespace clang::ast_matchers;
namespace clang::tidy::performance {
void NoexceptSwapCheck::registerMatchers(MatchFinder *Finder) {
-
// Match non-const method with single argument that is non-const reference to
// a class type that owns method and return void.
// Matches: void Class::swap(Class&)
diff --git a/clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp b/clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
index ae15208..3497ea7 100644
--- a/clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
@@ -26,7 +26,7 @@
#include "NoexceptSwapCheck.h"
#include "TriviallyDestructibleCheck.h"
#include "TypePromotionInMathFnCheck.h"
-#include "UnnecessaryCopyInitialization.h"
+#include "UnnecessaryCopyInitializationCheck.h"
#include "UnnecessaryValueParamCheck.h"
namespace clang::tidy {
@@ -66,7 +66,7 @@ public:
"performance-trivially-destructible");
CheckFactories.registerCheck<TypePromotionInMathFnCheck>(
"performance-type-promotion-in-math-fn");
- CheckFactories.registerCheck<UnnecessaryCopyInitialization>(
+ CheckFactories.registerCheck<UnnecessaryCopyInitializationCheck>(
"performance-unnecessary-copy-initialization");
CheckFactories.registerCheck<UnnecessaryValueParamCheck>(
"performance-unnecessary-value-param");
diff --git a/clang-tools-extra/clang-tidy/performance/TriviallyDestructibleCheck.cpp b/clang-tools-extra/clang-tidy/performance/TriviallyDestructibleCheck.cpp
index 0db66c0..416c41d 100644
--- a/clang-tools-extra/clang-tidy/performance/TriviallyDestructibleCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/TriviallyDestructibleCheck.cpp
@@ -23,12 +23,9 @@ namespace {
AST_MATCHER(Decl, isFirstDecl) { return Node.isFirstDecl(); }
AST_MATCHER_P(CXXRecordDecl, hasBase, Matcher<QualType>, InnerMatcher) {
- for (const CXXBaseSpecifier &BaseSpec : Node.bases()) {
- QualType BaseType = BaseSpec.getType();
- if (InnerMatcher.matches(BaseType, Finder, Builder))
- return true;
- }
- return false;
+ return llvm::any_of(Node.bases(), [&](const CXXBaseSpecifier &BaseSpec) {
+ return InnerMatcher.matches(BaseSpec.getType(), Finder, Builder);
+ });
}
} // namespace
@@ -50,7 +47,7 @@ void TriviallyDestructibleCheck::check(const MatchFinder::MatchResult &Result) {
const auto *MatchedDecl = Result.Nodes.getNodeAs<CXXDestructorDecl>("decl");
// Get locations of both first and out-of-line declarations.
- SourceManager &SM = *Result.SourceManager;
+ const SourceManager &SM = *Result.SourceManager;
const auto *FirstDecl = cast<CXXMethodDecl>(MatchedDecl->getFirstDecl());
const SourceLocation FirstDeclEnd = utils::lexer::findNextTerminator(
FirstDecl->getEndLoc(), SM, getLangOpts());
diff --git a/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp b/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
index 096ca57e..a462c55 100644
--- a/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
@@ -155,18 +155,18 @@ void TypePromotionInMathFnCheck::check(const MatchFinder::MatchResult &Result) {
const auto *Call = Result.Nodes.getNodeAs<CallExpr>("call");
assert(Call != nullptr);
- StringRef OldFnName = Call->getDirectCallee()->getName();
+ const StringRef OldFnName = Call->getDirectCallee()->getName();
// In C++ mode, we prefer std::foo to ::foof. But some of these suggestions
// are only valid in C++11 and newer.
- static llvm::StringSet<> Cpp11OnlyFns = {
+ static const llvm::StringSet<> Cpp11OnlyFns = {
"acosh", "asinh", "atanh", "cbrt", "copysign", "erf",
"erfc", "exp2", "expm1", "fdim", "fma", "fmax",
"fmin", "hypot", "ilogb", "lgamma", "llrint", "llround",
"log1p", "log2", "logb", "lrint", "lround", "nearbyint",
"nextafter", "nexttoward", "remainder", "remquo", "rint", "round",
"scalbln", "scalbn", "tgamma", "trunc"};
- bool StdFnRequiresCpp11 = Cpp11OnlyFns.contains(OldFnName);
+ const bool StdFnRequiresCpp11 = Cpp11OnlyFns.contains(OldFnName);
std::string NewFnName;
bool FnInCmath = false;
diff --git a/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.h b/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.h
index cf74f80..21a7f4d 100644
--- a/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.h
+++ b/clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_TYPE_PROMOTION_IN_MATH_FN_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_TYPE_PROMOTION_IN_MATH_FN_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_TYPEPROMOTIONINMATHFNCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_TYPEPROMOTIONINMATHFNCHECK_H
#include "../ClangTidyCheck.h"
#include "../utils/IncludeInserter.h"
@@ -39,4 +39,4 @@ private:
} // namespace clang::tidy::performance
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_TYPE_PROMOTION_IN_MATH_FN_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_TYPEPROMOTIONINMATHFNCHECK_H
diff --git a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitializationCheck.cpp
index 5918366..e6fe857 100644
--- a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
+++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitializationCheck.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "UnnecessaryCopyInitialization.h"
+#include "UnnecessaryCopyInitializationCheck.h"
#include "../utils/DeclRefExprUtils.h"
#include "../utils/FixItHintUtils.h"
#include "../utils/LexerUtils.h"
@@ -46,7 +46,7 @@ static std::optional<SourceLocation> firstLocAfterNewLine(SourceLocation Loc,
if (Invalid) {
return std::nullopt;
}
- size_t Offset = std::strcspn(TextAfter, "\n");
+ const size_t Offset = std::strcspn(TextAfter, "\n");
return Loc.getLocWithOffset(TextAfter[Offset] == '\0' ? Offset : Offset + 1);
}
@@ -148,7 +148,7 @@ AST_MATCHER_FUNCTION_P(StatementMatcher, initializerReturnsReferenceToConst,
static bool isInitializingVariableImmutable(
const VarDecl &InitializingVar, const Stmt &BlockStmt, ASTContext &Context,
const std::vector<StringRef> &ExcludedContainerTypes) {
- QualType T = InitializingVar.getType().getCanonicalType();
+ const QualType T = InitializingVar.getType().getCanonicalType();
if (!isOnlyUsedAsConst(InitializingVar, BlockStmt, Context,
T->isPointerType() ? 1 : 0))
return false;
@@ -227,7 +227,7 @@ static QualType constructorArgumentType(const VarDecl *OldVar,
return MethodDecl->getReturnType();
}
-UnnecessaryCopyInitialization::UnnecessaryCopyInitialization(
+UnnecessaryCopyInitializationCheck::UnnecessaryCopyInitializationCheck(
StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
AllowedTypes(
@@ -235,7 +235,7 @@ UnnecessaryCopyInitialization::UnnecessaryCopyInitialization(
ExcludedContainerTypes(utils::options::parseStringList(
Options.get("ExcludedContainerTypes", ""))) {}
-void UnnecessaryCopyInitialization::registerMatchers(MatchFinder *Finder) {
+void UnnecessaryCopyInitializationCheck::registerMatchers(MatchFinder *Finder) {
auto LocalVarCopiedFrom =
[this](const ast_matchers::internal::Matcher<Expr> &CopyCtorArg) {
return compoundStmt(
@@ -276,7 +276,7 @@ void UnnecessaryCopyInitialization::registerMatchers(MatchFinder *Finder) {
this);
}
-void UnnecessaryCopyInitialization::check(
+void UnnecessaryCopyInitializationCheck::check(
const MatchFinder::MatchResult &Result) {
const auto &NewVar = *Result.Nodes.getNodeAs<VarDecl>("newVarDecl");
const auto &BlockStmt = *Result.Nodes.getNodeAs<Stmt>("blockStmt");
@@ -297,7 +297,7 @@ void UnnecessaryCopyInitialization::check(
const auto *ObjectArg = Result.Nodes.getNodeAs<VarDecl>(ObjectArgId);
const auto *CtorCall = Result.Nodes.getNodeAs<CXXConstructExpr>("ctorCall");
- TraversalKindScope RAII(*Result.Context, TK_AsIs);
+ const TraversalKindScope RAII(*Result.Context, TK_AsIs);
// A constructor that looks like T(const T& t, bool arg = false) counts as a
// copy only when it is called with default arguments for the arguments after
@@ -325,9 +325,9 @@ void UnnecessaryCopyInitialization::check(
}
}
-void UnnecessaryCopyInitialization::handleCopyFromMethodReturn(
+void UnnecessaryCopyInitializationCheck::handleCopyFromMethodReturn(
const CheckContext &Ctx, const VarDecl *ObjectArg) {
- bool IsConstQualified = Ctx.Var.getType().isConstQualified();
+ const bool IsConstQualified = Ctx.Var.getType().isConstQualified();
if (!IsConstQualified && !Ctx.IsVarOnlyUsedAsConst)
return;
if (ObjectArg != nullptr &&
@@ -337,7 +337,7 @@ void UnnecessaryCopyInitialization::handleCopyFromMethodReturn(
diagnoseCopyFromMethodReturn(Ctx);
}
-void UnnecessaryCopyInitialization::handleCopyFromLocalVar(
+void UnnecessaryCopyInitializationCheck::handleCopyFromLocalVar(
const CheckContext &Ctx, const VarDecl &OldVar) {
if (!Ctx.IsVarOnlyUsedAsConst ||
!isInitializingVariableImmutable(OldVar, Ctx.BlockStmt, Ctx.ASTCtx,
@@ -346,7 +346,7 @@ void UnnecessaryCopyInitialization::handleCopyFromLocalVar(
diagnoseCopyFromLocalVar(Ctx, OldVar);
}
-void UnnecessaryCopyInitialization::diagnoseCopyFromMethodReturn(
+void UnnecessaryCopyInitializationCheck::diagnoseCopyFromMethodReturn(
const CheckContext &Ctx) {
auto Diagnostic =
diag(Ctx.Var.getLocation(),
@@ -360,7 +360,7 @@ void UnnecessaryCopyInitialization::diagnoseCopyFromMethodReturn(
maybeIssueFixes(Ctx, Diagnostic);
}
-void UnnecessaryCopyInitialization::diagnoseCopyFromLocalVar(
+void UnnecessaryCopyInitializationCheck::diagnoseCopyFromLocalVar(
const CheckContext &Ctx, const VarDecl &OldVar) {
auto Diagnostic =
diag(Ctx.Var.getLocation(),
@@ -372,7 +372,7 @@ void UnnecessaryCopyInitialization::diagnoseCopyFromLocalVar(
maybeIssueFixes(Ctx, Diagnostic);
}
-void UnnecessaryCopyInitialization::maybeIssueFixes(
+void UnnecessaryCopyInitializationCheck::maybeIssueFixes(
const CheckContext &Ctx, DiagnosticBuilder &Diagnostic) {
if (Ctx.IssueFix) {
if (Ctx.IsVarUnused)
@@ -382,7 +382,7 @@ void UnnecessaryCopyInitialization::maybeIssueFixes(
}
}
-void UnnecessaryCopyInitialization::storeOptions(
+void UnnecessaryCopyInitializationCheck::storeOptions(
ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "AllowedTypes",
utils::options::serializeStringList(AllowedTypes));
diff --git a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitializationCheck.h
index 6623188..89957a5 100644
--- a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h
+++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitializationCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_COPY_INITIALIZATION_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_COPY_INITIALIZATION_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARYCOPYINITIALIZATIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARYCOPYINITIALIZATIONCHECK_H
#include "../ClangTidyCheck.h"
#include "clang/AST/Decl.h"
@@ -22,9 +22,12 @@ namespace clang::tidy::performance {
// The check currently only understands a subset of variables that are
// guaranteed to outlive the const reference returned, namely: const variables,
// const references, and const pointers to const.
-class UnnecessaryCopyInitialization : public ClangTidyCheck {
+//
+// For the user-facing documentation see:
+// https://clang.llvm.org/extra/clang-tidy/checks/performance/unnecessary-copy-initialization.html
+class UnnecessaryCopyInitializationCheck : public ClangTidyCheck {
public:
- UnnecessaryCopyInitialization(StringRef Name, ClangTidyContext *Context);
+ UnnecessaryCopyInitializationCheck(StringRef Name, ClangTidyContext *Context);
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
@@ -64,4 +67,4 @@ private:
} // namespace clang::tidy::performance
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_COPY_INITIALIZATION_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARYCOPYINITIALIZATIONCHECK_H
diff --git a/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp b/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
index 3f5b43f..d626297 100644
--- a/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -73,7 +73,7 @@ void UnnecessaryValueParamCheck::check(const MatchFinder::MatchResult &Result) {
const auto *Param = Result.Nodes.getNodeAs<ParmVarDecl>("param");
const auto *Function = Result.Nodes.getNodeAs<FunctionDecl>("functionDecl");
- TraversalKindScope RAII(*Result.Context, TK_AsIs);
+ const TraversalKindScope RAII(*Result.Context, TK_AsIs);
FunctionParmMutationAnalyzer *Analyzer =
FunctionParmMutationAnalyzer::getFunctionParmMutationAnalyzer(
diff --git a/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.h b/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.h
index d59fb41..22df689 100644
--- a/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.h
+++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_VALUE_PARAM_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_VALUE_PARAM_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARYVALUEPARAMCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARYVALUEPARAMCHECK_H
#include "../ClangTidyCheck.h"
#include "../utils/IncludeInserter.h"
@@ -51,4 +51,4 @@ private:
} // namespace clang::tidy::performance
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_VALUE_PARAM_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARYVALUEPARAMCHECK_H
diff --git a/clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp b/clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp
index 195418d..172b918 100644
--- a/clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp
+++ b/clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp
@@ -55,13 +55,13 @@ public:
bool ParseArgs(const CompilerInstance &,
const std::vector<std::string> &Args) override {
- ClangTidyGlobalOptions GlobalOptions;
- ClangTidyOptions DefaultOptions;
+ const ClangTidyGlobalOptions GlobalOptions;
+ const ClangTidyOptions DefaultOptions;
ClangTidyOptions OverrideOptions;
// Parse the extra command line args.
// FIXME: This is very limited at the moment.
- for (StringRef Arg : Args)
+ for (const StringRef Arg : Args)
if (Arg.starts_with("-checks="))
OverrideOptions.Checks = std::string(Arg.substr(strlen("-checks=")));
diff --git a/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp b/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp
index 5174f56..4225c3e 100644
--- a/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp
@@ -43,8 +43,9 @@ void RestrictedIncludesPPCallbacks::EndOfMainFile() {
for (const auto &Include : FileDirectives) {
// Fetch the length of the include statement from the start to just after
// the newline, for finding the end (including the newline).
- unsigned ToLen = std::strcspn(SM.getCharacterData(Include.Loc), "\n") + 1;
- CharSourceRange ToRange = CharSourceRange::getCharRange(
+ const unsigned ToLen =
+ std::strcspn(SM.getCharacterData(Include.Loc), "\n") + 1;
+ const CharSourceRange ToRange = CharSourceRange::getCharRange(
Include.Loc, Include.Loc.getLocWithOffset(ToLen));
if (!Include.IsInMainFile) {
diff --git a/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h b/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
index e37f8933..d66149a 100644
--- a/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
+++ b/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_RESTRICTINCLUDESSCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_RESTRICTINCLUDESSCHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_RESTRICTSYSTEMINCLUDESCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_RESTRICTSYSTEMINCLUDESCHECK_H
#include "../ClangTidyCheck.h"
#include "../GlobList.h"
@@ -23,7 +23,7 @@ namespace clang::tidy::portability {
class RestrictSystemIncludesCheck : public ClangTidyCheck {
public:
RestrictSystemIncludesCheck(StringRef Name, ClangTidyContext *Context,
- std::string DefaultAllowedIncludes = "*")
+ StringRef DefaultAllowedIncludes = "*")
: ClangTidyCheck(Name, Context),
AllowedIncludes(Options.get("Includes", DefaultAllowedIncludes)),
AllowedIncludesGlobList(AllowedIncludes) {}
@@ -36,7 +36,7 @@ public:
}
private:
- std::string AllowedIncludes;
+ StringRef AllowedIncludes;
GlobList AllowedIncludesGlobList;
};
@@ -79,4 +79,4 @@ private:
} // namespace clang::tidy::portability
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_RESTRICTINCLUDESSCHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_RESTRICTSYSTEMINCLUDESCHECK_H
diff --git a/clang-tools-extra/clang-tidy/portability/SIMDIntrinsicsCheck.cpp b/clang-tools-extra/clang-tidy/portability/SIMDIntrinsicsCheck.cpp
index d90b09a..fb4b22c 100644
--- a/clang-tools-extra/clang-tidy/portability/SIMDIntrinsicsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/portability/SIMDIntrinsicsCheck.cpp
@@ -104,9 +104,9 @@ void SIMDIntrinsicsCheck::check(const MatchFinder::MatchResult &Result) {
if (!Callee)
return;
- StringRef Old = Callee->getName();
+ const StringRef Old = Callee->getName();
StringRef New;
- llvm::Triple::ArchType Arch =
+ const llvm::Triple::ArchType Arch =
Result.Context->getTargetInfo().getTriple().getArch();
// We warn or suggest if this SIMD intrinsic function has a std::simd
diff --git a/clang-tools-extra/clang-tidy/portability/SIMDIntrinsicsCheck.h b/clang-tools-extra/clang-tidy/portability/SIMDIntrinsicsCheck.h
index db2d230..addcecbc 100644
--- a/clang-tools-extra/clang-tidy/portability/SIMDIntrinsicsCheck.h
+++ b/clang-tools-extra/clang-tidy/portability/SIMDIntrinsicsCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_SIMDINTRINSICSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_SIMDINTRINSICSCHECK_H
#include "../ClangTidyCheck.h"
@@ -37,4 +37,4 @@ private:
} // namespace clang::tidy::portability
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_SIMDINTRINSICSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/readability/AmbiguousSmartptrResetCallCheck.cpp b/clang-tools-extra/clang-tidy/readability/AmbiguousSmartptrResetCallCheck.cpp
index 22ff5ce..ef9263b 100644
--- a/clang-tools-extra/clang-tidy/readability/AmbiguousSmartptrResetCallCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/AmbiguousSmartptrResetCallCheck.cpp
@@ -20,12 +20,9 @@ namespace clang::tidy::readability {
namespace {
AST_MATCHER(CXXMethodDecl, hasOnlyDefaultParameters) {
- for (const auto *Param : Node.parameters()) {
- if (!Param->hasDefaultArg())
- return false;
- }
-
- return true;
+ return llvm::all_of(Node.parameters(), [](const ParmVarDecl *Param) {
+ return Param->hasDefaultArg();
+ });
}
const auto DefaultSmartPointers = "::std::shared_ptr;::std::unique_ptr;"
diff --git a/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp b/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDeclsCheck.cpp
index 02fe913..506f8e2 100644
--- a/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
+++ b/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDeclsCheck.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "AvoidConstParamsInDecls.h"
+#include "AvoidConstParamsInDeclsCheck.h"
#include "../utils/LexerUtils.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
@@ -26,8 +26,7 @@ static SourceRange getTypeRange(const ParmVarDecl &Param) {
static std::optional<Token>
findConstToRemove(const ParmVarDecl &Param,
const MatchFinder::MatchResult &Result) {
-
- CharSourceRange FileRange = Lexer::makeFileCharRange(
+ const CharSourceRange FileRange = Lexer::makeFileCharRange(
CharSourceRange::getTokenRange(getTypeRange(Param)),
*Result.SourceManager, Result.Context->getLangOpts());
@@ -38,11 +37,12 @@ findConstToRemove(const ParmVarDecl &Param,
tok::kw_const, FileRange, *Result.Context, *Result.SourceManager);
}
-void AvoidConstParamsInDecls::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+void AvoidConstParamsInDeclsCheck::storeOptions(
+ ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "IgnoreMacros", IgnoreMacros);
}
-void AvoidConstParamsInDecls::registerMatchers(MatchFinder *Finder) {
+void AvoidConstParamsInDeclsCheck::registerMatchers(MatchFinder *Finder) {
const auto ConstParamDecl =
parmVarDecl(hasType(qualType(isConstQualified()))).bind("param");
Finder->addMatcher(functionDecl(unless(isDefinition()),
@@ -51,7 +51,8 @@ void AvoidConstParamsInDecls::registerMatchers(MatchFinder *Finder) {
this);
}
-void AvoidConstParamsInDecls::check(const MatchFinder::MatchResult &Result) {
+void AvoidConstParamsInDeclsCheck::check(
+ const MatchFinder::MatchResult &Result) {
const auto *Func = Result.Nodes.getNodeAs<FunctionDecl>("func");
const auto *Param = Result.Nodes.getNodeAs<ParmVarDecl>("param");
diff --git a/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.h b/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDeclsCheck.h
index 1dd28fd..467a9a4 100644
--- a/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.h
+++ b/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDeclsCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOID_CONST_PARAMS_IN_DECLS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOID_CONST_PARAMS_IN_DECLS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOIDCONSTPARAMSINDECLSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOIDCONSTPARAMSINDECLSCHECK_H
#include "../ClangTidyCheck.h"
@@ -15,9 +15,12 @@ namespace clang::tidy::readability {
// Detect function declarations that have const value parameters and discourage
// them.
-class AvoidConstParamsInDecls : public ClangTidyCheck {
+//
+// For the user-facing documentation see:
+// https://clang.llvm.org/extra/clang-tidy/checks/readability/avoid-const-params-in-decls.html
+class AvoidConstParamsInDeclsCheck : public ClangTidyCheck {
public:
- AvoidConstParamsInDecls(StringRef Name, ClangTidyContext *Context)
+ AvoidConstParamsInDeclsCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
IgnoreMacros(Options.get("IgnoreMacros", true)) {}
@@ -34,4 +37,4 @@ private:
} // namespace clang::tidy::readability
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOID_CONST_PARAMS_IN_DECLS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOIDCONSTPARAMSINDECLSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.h b/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.h
index 260c843..0e729ec 100644
--- a/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOID_NESTED_CONDITIONAL_OPERATOR_CHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOID_NESTED_CONDITIONAL_OPERATOR_CHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOIDNESTEDCONDITIONALOPERATORCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOIDNESTEDCONDITIONALOPERATORCHECK_H
#include "../ClangTidyCheck.h"
@@ -30,4 +30,4 @@ public:
} // namespace clang::tidy::readability
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOID_NESTED_CONDITIONAL_OPERATOR_CHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOIDNESTEDCONDITIONALOPERATORCHECK_H
diff --git a/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp b/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp
index 40a4fa1..2b31281 100644
--- a/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp
@@ -47,9 +47,9 @@ void AvoidReturnWithVoidValueCheck::check(
Result.Nodes.getNodeAs<CompoundStmt>("compound_parent");
if (!StrictMode && !SurroundingBlock)
return;
- DiagnosticBuilder Diag = diag(VoidReturn->getBeginLoc(),
- "return statement within a void function "
- "should not have a specified return value");
+ const DiagnosticBuilder Diag = diag(
+ VoidReturn->getBeginLoc(), "return statement within a void function "
+ "should not have a specified return value");
const SourceLocation SemicolonPos = utils::lexer::findNextTerminator(
VoidReturn->getEndLoc(), *Result.SourceManager, getLangOpts());
if (SemicolonPos.isInvalid())
diff --git a/clang-tools-extra/clang-tidy/readability/AvoidUnconditionalPreprocessorIfCheck.cpp b/clang-tools-extra/clang-tidy/readability/AvoidUnconditionalPreprocessorIfCheck.cpp
index c53c706..9fc8185 100644
--- a/clang-tools-extra/clang-tidy/readability/AvoidUnconditionalPreprocessorIfCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/AvoidUnconditionalPreprocessorIfCheck.cpp
@@ -17,7 +17,6 @@ namespace clang::tidy::readability {
namespace {
struct AvoidUnconditionalPreprocessorIfPPCallbacks : public PPCallbacks {
-
explicit AvoidUnconditionalPreprocessorIfPPCallbacks(ClangTidyCheck &Check,
Preprocessor &PP)
: Check(Check), PP(PP) {}
@@ -40,7 +39,7 @@ struct AvoidUnconditionalPreprocessorIfPPCallbacks : public PPCallbacks {
bool isImmutable(SourceManager &SM, const LangOptions &LangOpts,
SourceRange ConditionRange) {
- SourceLocation Loc = ConditionRange.getBegin();
+ const SourceLocation Loc = ConditionRange.getBegin();
if (Loc.isMacroID())
return false;
diff --git a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
index 1952e14..2b55bb8 100644
--- a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
@@ -20,7 +20,8 @@ namespace clang::tidy::readability {
static tok::TokenKind getTokenKind(SourceLocation Loc, const SourceManager &SM,
const LangOptions &LangOpts) {
Token Tok;
- SourceLocation Beginning = Lexer::GetBeginningOfToken(Loc, SM, LangOpts);
+ const SourceLocation Beginning =
+ Lexer::GetBeginningOfToken(Loc, SM, LangOpts);
const bool Invalid = Lexer::getRawToken(Beginning, Tok, SM, LangOpts);
assert(!Invalid && "Expected a valid token.");
@@ -38,7 +39,7 @@ forwardSkipWhitespaceAndComments(SourceLocation Loc, const SourceManager &SM,
while (isWhitespace(*SM.getCharacterData(Loc)))
Loc = Loc.getLocWithOffset(1);
- tok::TokenKind TokKind = getTokenKind(Loc, SM, LangOpts);
+ const tok::TokenKind TokKind = getTokenKind(Loc, SM, LangOpts);
if (TokKind != tok::comment)
return Loc;
@@ -80,7 +81,8 @@ void BracesAroundStatementsCheck::check(
} else if (const auto *S = Result.Nodes.getNodeAs<DoStmt>("do")) {
checkStmt(Result, S->getBody(), S->getDoLoc(), S->getWhileLoc());
} else if (const auto *S = Result.Nodes.getNodeAs<WhileStmt>("while")) {
- SourceLocation StartLoc = findRParenLoc(S, SM, Context->getLangOpts());
+ const SourceLocation StartLoc =
+ findRParenLoc(S, SM, Context->getLangOpts());
if (StartLoc.isInvalid())
return;
checkStmt(Result, S->getBody(), StartLoc);
@@ -89,12 +91,14 @@ void BracesAroundStatementsCheck::check(
if (S->isConsteval())
return;
- SourceLocation StartLoc = findRParenLoc(S, SM, Context->getLangOpts());
+ const SourceLocation StartLoc =
+ findRParenLoc(S, SM, Context->getLangOpts());
if (StartLoc.isInvalid())
return;
if (ForceBracesStmts.erase(S))
ForceBracesStmts.insert(S->getThen());
- bool BracedIf = checkStmt(Result, S->getThen(), StartLoc, S->getElseLoc());
+ const bool BracedIf =
+ checkStmt(Result, S->getThen(), StartLoc, S->getElseLoc());
const Stmt *Else = S->getElse();
if (Else && BracedIf)
ForceBracesStmts.insert(Else);
@@ -125,7 +129,7 @@ BracesAroundStatementsCheck::findRParenLoc(const IfOrWhileStmt *S,
return {};
}
- SourceLocation PastCondEndLoc =
+ const SourceLocation PastCondEndLoc =
Lexer::getLocForEndOfToken(CondEndLoc, 0, SM, LangOpts);
if (PastCondEndLoc.isInvalid())
return {};
@@ -133,7 +137,7 @@ BracesAroundStatementsCheck::findRParenLoc(const IfOrWhileStmt *S,
forwardSkipWhitespaceAndComments(PastCondEndLoc, SM, LangOpts);
if (RParenLoc.isInvalid())
return {};
- tok::TokenKind TokKind = getTokenKind(RParenLoc, SM, LangOpts);
+ const tok::TokenKind TokKind = getTokenKind(RParenLoc, SM, LangOpts);
if (TokKind != tok::r_paren)
return {};
return RParenLoc;
diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 91e9354..161a0d9 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -5,7 +5,7 @@ set(LLVM_LINK_COMPONENTS
add_clang_library(clangTidyReadabilityModule STATIC
AmbiguousSmartptrResetCallCheck.cpp
- AvoidConstParamsInDecls.cpp
+ AvoidConstParamsInDeclsCheck.cpp
AvoidNestedConditionalOperatorCheck.cpp
AvoidReturnWithVoidValueCheck.cpp
AvoidUnconditionalPreprocessorIfCheck.cpp
@@ -14,7 +14,7 @@ add_clang_library(clangTidyReadabilityModule STATIC
ContainerContainsCheck.cpp
ContainerDataPointerCheck.cpp
ContainerSizeEmptyCheck.cpp
- ConvertMemberFunctionsToStatic.cpp
+ ConvertMemberFunctionsToStaticCheck.cpp
DeleteNullPointerCheck.cpp
DuplicateIncludeCheck.cpp
ElseAfterReturnCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp b/clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
index 6ccd933..cfdf0e9 100644
--- a/clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
@@ -32,13 +32,13 @@ findConstToRemove(const FunctionDecl *Def,
// written in the source (for out-of-line declarations). A FunctionDecl's
// "location" is the start of its name, so, when the name is unqualified, we
// use `getLocation()`.
- SourceLocation NameBeginLoc = Def->getQualifier()
- ? Def->getQualifierLoc().getBeginLoc()
- : Def->getLocation();
+ const SourceLocation NameBeginLoc = Def->getQualifier()
+ ? Def->getQualifierLoc().getBeginLoc()
+ : Def->getLocation();
// Since either of the locs can be in a macro, use `makeFileCharRange` to be
// sure that we have a consistent `CharSourceRange`, located entirely in the
// source file.
- CharSourceRange FileRange = Lexer::makeFileCharRange(
+ const CharSourceRange FileRange = Lexer::makeFileCharRange(
CharSourceRange::getCharRange(Def->getBeginLoc(), NameBeginLoc),
*Result.SourceManager, Result.Context->getLangOpts());
@@ -118,12 +118,12 @@ void ConstReturnTypeCheck::check(const MatchFinder::MatchResult &Result) {
(Def->getBeginLoc().isMacroID() || Def->getEndLoc().isMacroID()))
return;
- CheckResult CR = checkDef(Def, Result);
+ const CheckResult CR = checkDef(Def, Result);
{
// Clang only supports one in-flight diagnostic at a time. So, delimit the
// scope of `Diagnostic` to allow further diagnostics after the scope. We
// use `getInnerLocStart` to get the start of the return type.
- DiagnosticBuilder Diagnostic =
+ const DiagnosticBuilder Diagnostic =
diag(Def->getInnerLocStart(),
"return type %0 is 'const'-qualified at the top level, which may "
"reduce code readability without improving const correctness")
diff --git a/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp b/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
index 850ef86c..efcf13d 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
@@ -47,9 +47,8 @@ void ContainerContainsCheck::registerMatchers(MatchFinder *Finder) {
const auto StringNpos = anyOf(declRefExpr(to(varDecl(hasName("npos")))),
memberExpr(member(hasName("npos"))));
- auto AddSimpleMatcher = [&](auto Matcher) {
- Finder->addMatcher(
- traverse(TK_IgnoreUnlessSpelledInSource, std::move(Matcher)), this);
+ auto AddSimpleMatcher = [&](const auto &Matcher) {
+ Finder->addMatcher(traverse(TK_IgnoreUnlessSpelledInSource, Matcher), this);
};
// Find membership tests which use `count()`.
@@ -110,7 +109,7 @@ void ContainerContainsCheck::check(const MatchFinder::MatchResult &Result) {
Result.Nodes.getNodeAs<Expr>("negativeComparison");
assert((!PositiveComparison || !NegativeComparison) &&
"only one of PositiveComparison or NegativeComparison should be set");
- bool Negated = NegativeComparison != nullptr;
+ const bool Negated = NegativeComparison != nullptr;
const auto *Comparison = Negated ? NegativeComparison : PositiveComparison;
const StringRef ContainsFunName =
Result.Nodes.getNodeAs<CXXMethodDecl>("contains_fun")->getName();
@@ -121,7 +120,7 @@ void ContainerContainsCheck::check(const MatchFinder::MatchResult &Result) {
<< ContainsFunName;
// Don't fix it if it's in a macro invocation. Leave fixing it to the user.
- SourceLocation FuncCallLoc = Comparison->getEndLoc();
+ const SourceLocation FuncCallLoc = Comparison->getEndLoc();
if (!FuncCallLoc.isValid() || FuncCallLoc.isMacroID())
return;
diff --git a/clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp b/clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp
index 11756d1..e308aef 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp
@@ -101,14 +101,17 @@ void ContainerDataPointerCheck::check(const MatchFinder::MatchResult &Result) {
else if (ACE)
CE = ACE;
- SourceRange SrcRange = CE->getSourceRange();
+ const SourceRange SrcRange = CE->getSourceRange();
std::string ReplacementText{
Lexer::getSourceText(CharSourceRange::getTokenRange(SrcRange),
*Result.SourceManager, getLangOpts())};
- if (!isa<DeclRefExpr, ArraySubscriptExpr, CXXOperatorCallExpr, CallExpr,
- MemberExpr>(CE))
+ const auto *OpCall = dyn_cast<CXXOperatorCallExpr>(CE);
+ const bool NeedsParens =
+ OpCall ? (OpCall->getOperator() != OO_Subscript)
+ : !isa<DeclRefExpr, MemberExpr, ArraySubscriptExpr, CallExpr>(CE);
+ if (NeedsParens)
ReplacementText = "(" + ReplacementText + ")";
if (CE->getType()->isPointerType())
@@ -116,7 +119,7 @@ void ContainerDataPointerCheck::check(const MatchFinder::MatchResult &Result) {
else
ReplacementText += ".data()";
- FixItHint Hint =
+ const FixItHint Hint =
FixItHint::CreateReplacement(UO->getSourceRange(), ReplacementText);
diag(UO->getBeginLoc(),
"'data' should be used for accessing the data pointer instead of taking "
diff --git a/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp b/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStaticCheck.cpp
index 6da4cf7..e6276e3 100644
--- a/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStaticCheck.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "ConvertMemberFunctionsToStatic.h"
+#include "ConvertMemberFunctionsToStaticCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/RecursiveASTVisitor.h"
@@ -78,7 +78,8 @@ AST_MATCHER(CXXMethodDecl, usesThis) {
} // namespace
-void ConvertMemberFunctionsToStatic::registerMatchers(MatchFinder *Finder) {
+void ConvertMemberFunctionsToStaticCheck::registerMatchers(
+ MatchFinder *Finder) {
Finder->addMatcher(
cxxMethodDecl(
isDefinition(), isUserProvided(),
@@ -118,26 +119,26 @@ static SourceRange getLocationOfConst(const TypeSourceInfo *TSI,
const auto FTL = TSI->getTypeLoc().IgnoreParens().getAs<FunctionTypeLoc>();
assert(FTL);
- SourceRange Range{FTL.getRParenLoc().getLocWithOffset(1),
- FTL.getLocalRangeEnd()};
+ const SourceRange Range{FTL.getRParenLoc().getLocWithOffset(1),
+ FTL.getLocalRangeEnd()};
// Inside Range, there might be other keywords and trailing return types.
// Find the exact position of "const".
- StringRef Text = getStringFromRange(SourceMgr, LangOpts, Range);
- size_t Offset = Text.find("const");
+ const StringRef Text = getStringFromRange(SourceMgr, LangOpts, Range);
+ const size_t Offset = Text.find("const");
if (Offset == StringRef::npos)
return {};
- SourceLocation Start = Range.getBegin().getLocWithOffset(Offset);
+ const SourceLocation Start = Range.getBegin().getLocWithOffset(Offset);
return {Start, Start.getLocWithOffset(strlen("const") - 1)};
}
-void ConvertMemberFunctionsToStatic::check(
+void ConvertMemberFunctionsToStaticCheck::check(
const MatchFinder::MatchResult &Result) {
const auto *Definition = Result.Nodes.getNodeAs<CXXMethodDecl>("x");
// TODO: For out-of-line declarations, don't modify the source if the header
// is excluded by the -header-filter option.
- DiagnosticBuilder Diag =
+ const DiagnosticBuilder Diag =
diag(Definition->getLocation(), "method %0 can be made static")
<< Definition;
@@ -152,15 +153,15 @@ void ConvertMemberFunctionsToStatic::check(
if (Definition->isConst()) {
// Make sure that we either remove 'const' on both declaration and
// definition or emit no fix-it at all.
- SourceRange DefConst = getLocationOfConst(Definition->getTypeSourceInfo(),
- *Result.SourceManager,
- Result.Context->getLangOpts());
+ const SourceRange DefConst = getLocationOfConst(
+ Definition->getTypeSourceInfo(), *Result.SourceManager,
+ Result.Context->getLangOpts());
if (DefConst.isInvalid())
return;
if (Declaration != Definition) {
- SourceRange DeclConst = getLocationOfConst(
+ const SourceRange DeclConst = getLocationOfConst(
Declaration->getTypeSourceInfo(), *Result.SourceManager,
Result.Context->getLangOpts());
diff --git a/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.h b/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStaticCheck.h
index 2aab03f1..4f8a1a9 100644
--- a/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.h
+++ b/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStaticCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_CONVERTMEMFUNCTOSTATIC_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_CONVERTMEMFUNCTOSTATIC_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_CONVERTMEMBERFUNCTIONSTOSTATICCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_CONVERTMEMBERFUNCTIONSTOSTATICCHECK_H
#include "../ClangTidyCheck.h"
@@ -18,10 +18,10 @@ namespace clang::tidy::readability {
///
/// For the user-facing documentation see:
/// https://clang.llvm.org/extra/clang-tidy/checks/
-/// readability-convert-member-functions-to-static.html
-class ConvertMemberFunctionsToStatic : public ClangTidyCheck {
+/// readability/convert-member-functions-to-static.html
+class ConvertMemberFunctionsToStaticCheck : public ClangTidyCheck {
public:
- ConvertMemberFunctionsToStatic(StringRef Name, ClangTidyContext *Context)
+ ConvertMemberFunctionsToStaticCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
@@ -32,4 +32,4 @@ public:
} // namespace clang::tidy::readability
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_CONVERTMEMFUNCTOSTATIC_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_CONVERTMEMBERFUNCTIONSTOSTATICCHECK_H
diff --git a/clang-tools-extra/clang-tidy/readability/DeleteNullPointerCheck.h b/clang-tools-extra/clang-tidy/readability/DeleteNullPointerCheck.h
index 52b1b26..b346f68 100644
--- a/clang-tools-extra/clang-tidy/readability/DeleteNullPointerCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/DeleteNullPointerCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_DELETE_NULL_POINTER_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_DELETE_NULL_POINTER_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_DELETENULLPOINTERCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_DELETENULLPOINTERCHECK_H
#include "../ClangTidyCheck.h"
@@ -34,4 +34,4 @@ public:
} // namespace clang::tidy::readability
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_DELETE_NULL_POINTER_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_DELETENULLPOINTERCHECK_H
diff --git a/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp b/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp
index 0237c05..4842fe2 100644
--- a/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp
@@ -7,10 +7,12 @@
//===----------------------------------------------------------------------===//
#include "DuplicateIncludeCheck.h"
+#include "../utils/OptionsUtils.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Lex/Preprocessor.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/Regex.h"
#include <memory>
namespace clang::tidy::readability {
@@ -33,11 +35,8 @@ using FileList = SmallVector<StringRef>;
class DuplicateIncludeCallbacks : public PPCallbacks {
public:
DuplicateIncludeCallbacks(DuplicateIncludeCheck &Check,
- const SourceManager &SM)
- : Check(Check), SM(SM) {
- // The main file doesn't participate in the FileChanged notification.
- Files.emplace_back();
- }
+ const SourceManager &SM,
+ llvm::ArrayRef<StringRef> IgnoredList);
void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
@@ -62,10 +61,31 @@ private:
SmallVector<FileList> Files;
DuplicateIncludeCheck &Check;
const SourceManager &SM;
+ SmallVector<llvm::Regex> AllowedRegexes;
};
} // namespace
+DuplicateIncludeCheck::DuplicateIncludeCheck(StringRef Name,
+ ClangTidyContext *Context)
+ : ClangTidyCheck(Name, Context),
+ IgnoredFilesList(utils::options::parseStringList(
+ Options.get("IgnoredFilesList", ""))) {}
+
+DuplicateIncludeCallbacks::DuplicateIncludeCallbacks(
+ DuplicateIncludeCheck &Check, const SourceManager &SM,
+ llvm::ArrayRef<StringRef> IgnoredList)
+ : Check(Check), SM(SM) {
+ // The main file doesn't participate in the FileChanged notification.
+ Files.emplace_back();
+
+ AllowedRegexes.reserve(IgnoredList.size());
+ for (const StringRef &It : IgnoredList) {
+ if (!It.empty())
+ AllowedRegexes.emplace_back(It);
+ }
+}
+
void DuplicateIncludeCallbacks::FileChanged(SourceLocation Loc,
FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
@@ -78,7 +98,7 @@ void DuplicateIncludeCallbacks::FileChanged(SourceLocation Loc,
void DuplicateIncludeCallbacks::InclusionDirective(
SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
- bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
+ bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef /*File*/,
StringRef SearchPath, StringRef RelativePath, const Module *SuggestedModule,
bool ModuleImported, SrcMgr::CharacteristicKind FileType) {
// Skip includes behind macros
@@ -86,11 +106,15 @@ void DuplicateIncludeCallbacks::InclusionDirective(
FilenameRange.getEnd().isMacroID())
return;
if (llvm::is_contained(Files.back(), FileName)) {
+ if (llvm::any_of(AllowedRegexes, [&FileName](const llvm::Regex &R) {
+ return R.match(FileName);
+ }))
+ return;
// We want to delete the entire line, so make sure that [Start,End] covers
// everything.
- SourceLocation Start =
+ const SourceLocation Start =
advanceBeyondCurrentLine(SM, HashLoc, -1).getLocWithOffset(-1);
- SourceLocation End =
+ const SourceLocation End =
advanceBeyondCurrentLine(SM, FilenameRange.getEnd(), 1);
Check.diag(HashLoc, "duplicate include")
<< FixItHint::CreateRemoval(SourceRange{Start, End});
@@ -111,7 +135,13 @@ void DuplicateIncludeCallbacks::MacroUndefined(const Token &MacroNameTok,
void DuplicateIncludeCheck::registerPPCallbacks(
const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
- PP->addPPCallbacks(std::make_unique<DuplicateIncludeCallbacks>(*this, SM));
+ PP->addPPCallbacks(
+ std::make_unique<DuplicateIncludeCallbacks>(*this, SM, IgnoredFilesList));
+}
+
+void DuplicateIncludeCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+ Options.store(Opts, "IgnoredFilesList",
+ utils::options::serializeStringList(IgnoredFilesList));
}
} // namespace clang::tidy::readability
diff --git a/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.h b/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.h
index 297999c..1ee5b1c 100644
--- a/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_DUPLICATE_INCLUDE_CHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_DUPLICATE_INCLUDE_CHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_DUPLICATEINCLUDECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_DUPLICATEINCLUDECHECK_H
#include "../ClangTidyCheck.h"
@@ -19,13 +19,18 @@ namespace clang::tidy::readability {
/// directives between them are analyzed.
class DuplicateIncludeCheck : public ClangTidyCheck {
public:
- DuplicateIncludeCheck(StringRef Name, ClangTidyContext *Context)
- : ClangTidyCheck(Name, Context) {}
+ DuplicateIncludeCheck(StringRef Name, ClangTidyContext *Context);
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override;
+ void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+
+private:
+ // Semicolon-separated list of regexes or file names to ignore from duplicate
+ // warnings.
+ const std::vector<StringRef> IgnoredFilesList;
};
} // namespace clang::tidy::readability
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_DUPLICATE_INCLUDE_CHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_DUPLICATEINCLUDECHECK_H
diff --git a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
index 6399e7d9..4ef28c8b 100644
--- a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
@@ -124,21 +124,21 @@ static void removeElseAndBrackets(DiagnosticBuilder &Diag, ASTContext &Context,
if (const auto *CS = dyn_cast<CompoundStmt>(Else)) {
Diag << tooling::fixit::createRemoval(ElseLoc);
- SourceLocation LBrace = CS->getLBracLoc();
- SourceLocation RBrace = CS->getRBracLoc();
- SourceLocation RangeStart =
+ const SourceLocation LBrace = CS->getLBracLoc();
+ const SourceLocation RBrace = CS->getRBracLoc();
+ const SourceLocation RangeStart =
Remap(LBrace).getLocWithOffset(TokLen(LBrace) + 1);
- SourceLocation RangeEnd = Remap(RBrace).getLocWithOffset(-1);
+ const SourceLocation RangeEnd = Remap(RBrace).getLocWithOffset(-1);
- llvm::StringRef Repl = Lexer::getSourceText(
+ const llvm::StringRef Repl = Lexer::getSourceText(
CharSourceRange::getTokenRange(RangeStart, RangeEnd),
Context.getSourceManager(), Context.getLangOpts());
Diag << tooling::fixit::createReplacement(CS->getSourceRange(), Repl);
} else {
- SourceLocation ElseExpandedLoc = Remap(ElseLoc);
- SourceLocation EndLoc = Remap(Else->getEndLoc());
+ const SourceLocation ElseExpandedLoc = Remap(ElseLoc);
+ const SourceLocation EndLoc = Remap(Else->getEndLoc());
- llvm::StringRef Repl = Lexer::getSourceText(
+ const llvm::StringRef Repl = Lexer::getSourceText(
CharSourceRange::getTokenRange(
ElseExpandedLoc.getLocWithOffset(TokLen(ElseLoc) + 1), EndLoc),
Context.getSourceManager(), Context.getLangOpts());
@@ -185,9 +185,8 @@ void ElseAfterReturnCheck::registerMatchers(MatchFinder *Finder) {
static bool hasPreprocessorBranchEndBetweenLocations(
const ElseAfterReturnCheck::ConditionalBranchMap &ConditionalBranchMap,
const SourceManager &SM, SourceLocation StartLoc, SourceLocation EndLoc) {
-
- SourceLocation ExpandedStartLoc = SM.getExpansionLoc(StartLoc);
- SourceLocation ExpandedEndLoc = SM.getExpansionLoc(EndLoc);
+ const SourceLocation ExpandedStartLoc = SM.getExpansionLoc(StartLoc);
+ const SourceLocation ExpandedEndLoc = SM.getExpansionLoc(EndLoc);
if (!SM.isWrittenInSameFile(ExpandedStartLoc, ExpandedEndLoc))
return false;
@@ -239,14 +238,14 @@ void ElseAfterReturnCheck::check(const MatchFinder::MatchResult &Result) {
const auto *Else = Result.Nodes.getNodeAs<Stmt>("else");
const auto *OuterScope = Result.Nodes.getNodeAs<CompoundStmt>("cs");
const auto *Interrupt = Result.Nodes.getNodeAs<Stmt>(InterruptingStr);
- SourceLocation ElseLoc = If->getElseLoc();
+ const SourceLocation ElseLoc = If->getElseLoc();
if (hasPreprocessorBranchEndBetweenLocations(
PPConditionals, *Result.SourceManager, Interrupt->getBeginLoc(),
ElseLoc))
return;
- bool IsLastInScope = OuterScope->body_back() == If;
+ const bool IsLastInScope = OuterScope->body_back() == If;
const StringRef ControlFlowInterrupter = getControlFlowString(*Interrupt);
if (!IsLastInScope && containsDeclInScope(Else)) {
@@ -276,7 +275,7 @@ void ElseAfterReturnCheck::check(const MatchFinder::MatchResult &Result) {
}
const DeclStmt *VDeclStmt = If->getConditionVariableDeclStmt();
const VarDecl *VDecl = If->getConditionVariable();
- std::string Repl =
+ const std::string Repl =
(tooling::fixit::getText(*VDeclStmt, *Result.Context) +
llvm::StringRef(";\n") +
tooling::fixit::getText(If->getIfLoc(), *Result.Context))
diff --git a/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp b/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
index a2a5c3e..049ad75 100644
--- a/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
@@ -75,7 +75,7 @@ static void cleanInitialValue(DiagnosticBuilder &Diag,
namespace {
AST_MATCHER(EnumDecl, isMacro) {
- SourceLocation Loc = Node.getBeginLoc();
+ const SourceLocation Loc = Node.getBeginLoc();
return Loc.isMacroID();
}
@@ -165,7 +165,7 @@ void EnumInitialValueCheck::registerMatchers(MatchFinder *Finder) {
void EnumInitialValueCheck::check(const MatchFinder::MatchResult &Result) {
if (const auto *Enum = Result.Nodes.getNodeAs<EnumDecl>("inconsistent")) {
- DiagnosticBuilder Diag =
+ const DiagnosticBuilder Diag =
diag(
Enum->getBeginLoc(),
"initial values in enum '%0' are not consistent, consider explicit "
diff --git a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
index 4791df0..a966f1f 100644
--- a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -229,14 +229,14 @@ public:
bool traverseStmtWithIncreasedNestingLevel(Stmt *Node) {
++CurrentNestingLevel;
- bool ShouldContinue = Base::TraverseStmt(Node);
+ const bool ShouldContinue = Base::TraverseStmt(Node);
--CurrentNestingLevel;
return ShouldContinue;
}
bool traverseDeclWithIncreasedNestingLevel(Decl *Node) {
++CurrentNestingLevel;
- bool ShouldContinue = Base::TraverseDecl(Node);
+ const bool ShouldContinue = Base::TraverseDecl(Node);
--CurrentNestingLevel;
return ShouldContinue;
}
@@ -336,7 +336,7 @@ public:
// Record the operator that we are currently processing and traverse it.
CurrentBinaryOperator = Op->getOpcode();
- bool ShouldContinue = Base::TraverseBinaryOperator(Op);
+ const bool ShouldContinue = Base::TraverseBinaryOperator(Op);
// And restore the previous binary operator, which might be nonexistent.
CurrentBinaryOperator = BinOpCopy;
@@ -354,7 +354,7 @@ public:
// Else, do add [uninitialized] frame to the stack, and traverse call.
BinaryOperatorsStack.emplace();
- bool ShouldContinue = Base::TraverseCallExpr(Node);
+ const bool ShouldContinue = Base::TraverseCallExpr(Node);
// And remove the top frame.
BinaryOperatorsStack.pop();
@@ -519,7 +519,6 @@ void FunctionCognitiveComplexityCheck::registerMatchers(MatchFinder *Finder) {
void FunctionCognitiveComplexityCheck::check(
const MatchFinder::MatchResult &Result) {
-
FunctionASTVisitor Visitor(IgnoreMacros);
SourceLocation Loc;
@@ -558,7 +557,7 @@ void FunctionCognitiveComplexityCheck::check(
// Increase, on the other hand, can be 0.
diag(Detail.Loc, Msgs[MsgId], DiagnosticIDs::Note)
- << (unsigned)Increase << (unsigned)Detail.Nesting << 1 + Detail.Nesting;
+ << Increase << Detail.Nesting << 1 + Detail.Nesting;
}
}
diff --git a/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp b/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp
index 8c58346..2f0949c 100644
--- a/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp
@@ -181,14 +181,14 @@ void FunctionSizeCheck::check(const MatchFinder::MatchResult &Result) {
// Count the lines including whitespace and comments. Really simple.
if (const Stmt *Body = Func->getBody()) {
- SourceManager *SM = Result.SourceManager;
+ const SourceManager *SM = Result.SourceManager;
if (SM->isWrittenInSameFile(Body->getBeginLoc(), Body->getEndLoc())) {
FI.Lines = SM->getSpellingLineNumber(Body->getEndLoc()) -
SM->getSpellingLineNumber(Body->getBeginLoc());
}
}
- unsigned ActualNumberParameters = Func->getNumParams();
+ const unsigned ActualNumberParameters = Func->getNumParams();
if ((LineThreshold && FI.Lines > LineThreshold) ||
(StatementThreshold && FI.Statements > StatementThreshold) ||
diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierLengthCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierLengthCheck.cpp
index 877f0a4..a6204de 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierLengthCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierLengthCheck.cpp
@@ -91,7 +91,7 @@ void IdentifierLengthCheck::check(const MatchFinder::MatchResult &Result) {
if (!StandaloneVar->getIdentifier())
return;
- StringRef VarName = StandaloneVar->getName();
+ const StringRef VarName = StandaloneVar->getName();
if (VarName.size() >= MinimumVariableNameLength ||
IgnoredVariableNames.match(VarName))
@@ -106,7 +106,7 @@ void IdentifierLengthCheck::check(const MatchFinder::MatchResult &Result) {
if (!ExceptionVarName->getIdentifier())
return;
- StringRef VarName = ExceptionVarName->getName();
+ const StringRef VarName = ExceptionVarName->getName();
if (VarName.size() >= MinimumExceptionNameLength ||
IgnoredExceptionVariableNames.match(VarName))
return;
@@ -120,7 +120,7 @@ void IdentifierLengthCheck::check(const MatchFinder::MatchResult &Result) {
if (!LoopVar->getIdentifier())
return;
- StringRef VarName = LoopVar->getName();
+ const StringRef VarName = LoopVar->getName();
if (VarName.size() >= MinimumLoopCounterNameLength ||
IgnoredLoopCounterNames.match(VarName))
@@ -135,7 +135,7 @@ void IdentifierLengthCheck::check(const MatchFinder::MatchResult &Result) {
if (!ParamVar->getIdentifier())
return;
- StringRef VarName = ParamVar->getName();
+ const StringRef VarName = ParamVar->getName();
if (VarName.size() >= MinimumParameterNameLength ||
IgnoredParameterNames.match(VarName))
diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index ef3eac8..79f8437 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -261,7 +261,7 @@ IdentifierNamingCheck::FileStyle IdentifierNamingCheck::getFileStyleFromOptions(
Styles.resize(SK_Count);
SmallString<64> StyleString;
for (unsigned I = 0; I < SK_Count; ++I) {
- size_t StyleSize = StyleNames[I].size();
+ const size_t StyleSize = StyleNames[I].size();
StyleString.assign({StyleNames[I], "HungarianPrefix"});
auto HPTOpt =
@@ -271,13 +271,13 @@ IdentifierNamingCheck::FileStyle IdentifierNamingCheck::getFileStyleFromOptions(
memcpy(&StyleString[StyleSize], "IgnoredRegexp", 13);
StyleString.truncate(StyleSize + 13);
- std::optional<StringRef> IgnoredRegexpStr = Options.get(StyleString);
+ const std::optional<StringRef> IgnoredRegexpStr = Options.get(StyleString);
memcpy(&StyleString[StyleSize], "Prefix", 6);
StyleString.truncate(StyleSize + 6);
- std::optional<StringRef> Prefix(Options.get(StyleString));
+ const std::optional<StringRef> Prefix(Options.get(StyleString));
// Fast replacement of [Pre]fix -> [Suf]fix.
memcpy(&StyleString[StyleSize], "Suf", 3);
- std::optional<StringRef> Postfix(Options.get(StyleString));
+ const std::optional<StringRef> Postfix(Options.get(StyleString));
memcpy(&StyleString[StyleSize], "Case", 4);
StyleString.pop_back_n(2);
std::optional<CaseType> CaseOptional =
@@ -288,8 +288,9 @@ IdentifierNamingCheck::FileStyle IdentifierNamingCheck::getFileStyleFromOptions(
Postfix.value_or(""), IgnoredRegexpStr.value_or(""),
HPTOpt.value_or(IdentifierNamingCheck::HPT_Off));
}
- bool IgnoreMainLike = Options.get("IgnoreMainLikeFunctions", false);
- bool CheckAnonFieldInParent = Options.get("CheckAnonFieldInParent", false);
+ const bool IgnoreMainLike = Options.get("IgnoreMainLikeFunctions", false);
+ const bool CheckAnonFieldInParent =
+ Options.get("CheckAnonFieldInParent", false);
return {std::move(Styles), std::move(HNOption), IgnoreMainLike,
CheckAnonFieldInParent};
}
@@ -317,8 +318,8 @@ std::string IdentifierNamingCheck::HungarianNotation::getDeclTypeName(
if (!EOL)
EOL = Begin + strlen(Begin);
- const char *PosList[] = {strchr(Begin, '='), strchr(Begin, ';'),
- strchr(Begin, ','), strchr(Begin, ')'), EOL};
+ const char *const PosList[] = {strchr(Begin, '='), strchr(Begin, ';'),
+ strchr(Begin, ','), strchr(Begin, ')'), EOL};
for (const auto &Pos : PosList) {
if (Pos > Begin)
EOL = std::min(EOL, Pos);
@@ -340,7 +341,7 @@ std::string IdentifierNamingCheck::HungarianNotation::getDeclTypeName(
"virtual"};
// Remove keywords
- for (StringRef Kw : Keywords) {
+ for (const StringRef Kw : Keywords) {
for (size_t Pos = 0; (Pos = Type.find(Kw, Pos)) != std::string::npos;) {
Type.replace(Pos, Kw.size(), "");
}
@@ -376,7 +377,7 @@ std::string IdentifierNamingCheck::HungarianNotation::getDeclTypeName(
" int", " char", " double", " long", " short"};
bool RedundantRemoved = false;
for (auto Kw : TailsOfMultiWordType) {
- size_t Pos = Type.rfind(Kw);
+ const size_t Pos = Type.rfind(Kw);
if (Pos != std::string::npos) {
const size_t PtrCount = getAsteriskCount(Type, ND);
Type = Type.substr(0, Pos + Kw.size() + PtrCount);
@@ -387,14 +388,14 @@ std::string IdentifierNamingCheck::HungarianNotation::getDeclTypeName(
TypeName = Type.erase(0, Type.find_first_not_of(' '));
if (!RedundantRemoved) {
- std::size_t FoundSpace = Type.find(' ');
+ const std::size_t FoundSpace = Type.find(' ');
if (FoundSpace != std::string::npos)
Type = Type.substr(0, FoundSpace);
}
TypeName = Type.erase(0, Type.find_first_not_of(' '));
- QualType QT = VD->getType();
+ const QualType QT = VD->getType();
if (!QT.isNull() && QT->isArrayType())
TypeName.append("[]");
}
@@ -407,7 +408,6 @@ IdentifierNamingCheck::IdentifierNamingCheck(StringRef Name,
: RenamerClangTidyCheck(Name, Context), Context(Context),
GetConfigPerFile(Options.get("GetConfigPerFile", true)),
IgnoreFailedSplit(Options.get("IgnoreFailedSplit", false)) {
-
auto IterAndInserted = NamingStylesCache.try_emplace(
llvm::sys::path::parent_path(Context->getCurrentFile()),
getFileStyleFromOptions(Options));
@@ -446,19 +446,18 @@ bool IdentifierNamingCheck::HungarianNotation::isOptionEnabled(
void IdentifierNamingCheck::HungarianNotation::loadFileConfig(
const ClangTidyCheck::OptionsView &Options,
IdentifierNamingCheck::HungarianNotationOption &HNOption) const {
-
static constexpr StringRef HNOpts[] = {"TreatStructAsClass"};
static constexpr StringRef HNDerivedTypes[] = {"Array", "Pointer",
"FunctionPointer"};
- StringRef Section = "HungarianNotation.";
+ const StringRef Section = "HungarianNotation.";
SmallString<128> Buffer = {Section, "General."};
size_t DefSize = Buffer.size();
for (const auto &Opt : HNOpts) {
Buffer.truncate(DefSize);
Buffer.append(Opt);
- StringRef Val = Options.get(Buffer, "");
+ const StringRef Val = Options.get(Buffer, "");
if (!Val.empty())
HNOption.General[Opt] = Val.str();
}
@@ -468,7 +467,7 @@ void IdentifierNamingCheck::HungarianNotation::loadFileConfig(
for (const auto &Type : HNDerivedTypes) {
Buffer.truncate(DefSize);
Buffer.append(Type);
- StringRef Val = Options.get(Buffer, "");
+ const StringRef Val = Options.get(Buffer, "");
if (!Val.empty())
HNOption.DerivedType[Type] = Val.str();
}
@@ -484,7 +483,7 @@ void IdentifierNamingCheck::HungarianNotation::loadFileConfig(
for (const auto &CStr : HNCStrings) {
Buffer.truncate(DefSize);
Buffer.append(CStr.first);
- StringRef Val = Options.get(Buffer, "");
+ const StringRef Val = Options.get(Buffer, "");
if (!Val.empty())
HNOption.CString[CStr.second] = Val.str();
}
@@ -494,7 +493,7 @@ void IdentifierNamingCheck::HungarianNotation::loadFileConfig(
for (const auto &PrimType : HungarianNotationPrimitiveTypes) {
Buffer.truncate(DefSize);
Buffer.append(PrimType);
- StringRef Val = Options.get(Buffer, "");
+ const StringRef Val = Options.get(Buffer, "");
if (!Val.empty()) {
std::string Type = PrimType.str();
llvm::replace(Type, '-', ' ');
@@ -507,7 +506,7 @@ void IdentifierNamingCheck::HungarianNotation::loadFileConfig(
for (const auto &Type : HungarianNotationUserDefinedTypes) {
Buffer.truncate(DefSize);
Buffer.append(Type);
- StringRef Val = Options.get(Buffer, "");
+ const StringRef Val = Options.get(Buffer, "");
if (!Val.empty())
HNOption.UserDefinedType[Type] = Val.str();
}
@@ -528,7 +527,7 @@ std::string IdentifierNamingCheck::HungarianNotation::getPrefix(
} else if (const auto *CRD = dyn_cast<CXXRecordDecl>(ND)) {
Prefix = getClassPrefix(CRD, HNOption);
} else if (isa<VarDecl, FieldDecl, RecordDecl>(ND)) {
- std::string TypeName = getDeclTypeName(ND);
+ const std::string TypeName = getDeclTypeName(ND);
if (!TypeName.empty())
Prefix = getDataTypePrefix(TypeName, ND, HNOption);
}
@@ -542,8 +541,8 @@ bool IdentifierNamingCheck::HungarianNotation::removeDuplicatedPrefix(
if (Words.size() <= 1)
return true;
- std::string CorrectName = Words[0].str();
- std::vector<llvm::StringMap<std::string>> MapList = {
+ const std::string CorrectName = Words[0].str();
+ const std::vector<llvm::StringMap<std::string>> MapList = {
HNOption.CString, HNOption.DerivedType, HNOption.PrimitiveType,
HNOption.UserDefinedType};
@@ -570,12 +569,12 @@ std::string IdentifierNamingCheck::HungarianNotation::getDataTypePrefix(
// Derived types
std::string PrefixStr;
if (const auto *TD = dyn_cast<ValueDecl>(ND)) {
- QualType QT = TD->getType();
+ const QualType QT = TD->getType();
if (QT->isFunctionPointerType()) {
PrefixStr = HNOption.DerivedType.lookup("FunctionPointer");
} else if (QT->isPointerType()) {
for (const auto &CStr : HNOption.CString) {
- std::string Key = CStr.getKey().str();
+ const std::string Key = CStr.getKey().str();
if (ModifiedTypeName.find(Key) == 0) {
PrefixStr = CStr.getValue();
ModifiedTypeName = ModifiedTypeName.substr(
@@ -585,7 +584,7 @@ std::string IdentifierNamingCheck::HungarianNotation::getDataTypePrefix(
}
} else if (QT->isArrayType()) {
for (const auto &CStr : HNOption.CString) {
- std::string Key = CStr.getKey().str();
+ const std::string Key = CStr.getKey().str();
if (ModifiedTypeName.find(Key) == 0) {
PrefixStr = CStr.getValue();
break;
@@ -594,14 +593,14 @@ std::string IdentifierNamingCheck::HungarianNotation::getDataTypePrefix(
if (PrefixStr.empty())
PrefixStr = HNOption.DerivedType.lookup("Array");
} else if (QT->isReferenceType()) {
- size_t Pos = ModifiedTypeName.find_last_of('&');
+ const size_t Pos = ModifiedTypeName.find_last_of('&');
if (Pos != std::string::npos)
ModifiedTypeName = ModifiedTypeName.substr(0, Pos);
}
}
// Pointers
- size_t PtrCount = getAsteriskCount(ModifiedTypeName);
+ const size_t PtrCount = getAsteriskCount(ModifiedTypeName);
if (PtrCount > 0) {
ModifiedTypeName = [&](std::string Str, StringRef From, StringRef To) {
size_t StartPos = 0;
@@ -642,7 +641,6 @@ std::string IdentifierNamingCheck::HungarianNotation::getDataTypePrefix(
std::string IdentifierNamingCheck::HungarianNotation::getClassPrefix(
const CXXRecordDecl *CRD,
const IdentifierNamingCheck::HungarianNotationOption &HNOption) const {
-
if (CRD->isUnion())
return {};
@@ -663,10 +661,10 @@ std::string IdentifierNamingCheck::HungarianNotation::getEnumPrefix(
Name = Name.erase(0, Name.find_first_not_of(' '));
}
- static llvm::Regex Splitter(
+ static const llvm::Regex Splitter(
"([a-z0-9A-Z]*)(_+)|([A-Z]?[a-z0-9]+)([A-Z]|$)|([A-Z]+)([A-Z]|$)");
- StringRef EnumName(Name);
+ const StringRef EnumName(Name);
SmallVector<StringRef, 8> Substrs;
EnumName.split(Substrs, "_", -1, false);
@@ -692,7 +690,7 @@ std::string IdentifierNamingCheck::HungarianNotation::getEnumPrefix(
}
std::string Initial;
- for (StringRef Word : Words)
+ for (const StringRef Word : Words)
Initial += tolower(Word[0]);
return Initial;
@@ -713,7 +711,7 @@ size_t IdentifierNamingCheck::HungarianNotation::getAsteriskCount(
const std::string &TypeName, const NamedDecl *ND) const {
size_t PtrCount = 0;
if (const auto *TD = dyn_cast<ValueDecl>(ND)) {
- QualType QT = TD->getType();
+ const QualType QT = TD->getType();
if (QT->isPointerType())
PtrCount = getAsteriskCount(TypeName);
}
@@ -722,7 +720,6 @@ size_t IdentifierNamingCheck::HungarianNotation::getAsteriskCount(
void IdentifierNamingCheck::HungarianNotation::loadDefaultConfig(
IdentifierNamingCheck::HungarianNotationOption &HNOption) const {
-
// Options
static constexpr std::pair<StringRef, StringRef> General[] = {
{"TreatStructAsClass", "false"}};
@@ -834,11 +831,12 @@ void IdentifierNamingCheck::HungarianNotation::loadDefaultConfig(
void IdentifierNamingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
RenamerClangTidyCheck::storeOptions(Opts);
SmallString<64> StyleString;
- ArrayRef<std::optional<NamingStyle>> Styles = MainFileStyle->getStyles();
+ const ArrayRef<std::optional<NamingStyle>> Styles =
+ MainFileStyle->getStyles();
for (size_t I = 0; I < SK_Count; ++I) {
if (!Styles[I])
continue;
- size_t StyleSize = StyleNames[I].size();
+ const size_t StyleSize = StyleNames[I].size();
StyleString.assign({StyleNames[I], "HungarianPrefix"});
Options.store(Opts, StyleString, Styles[I]->HPType);
@@ -871,7 +869,7 @@ bool IdentifierNamingCheck::matchesStyle(
const IdentifierNamingCheck::NamingStyle &Style,
const IdentifierNamingCheck::HungarianNotationOption &HNOption,
const NamedDecl *Decl) const {
- static llvm::Regex Matchers[] = {
+ static const llvm::Regex Matchers[] = {
llvm::Regex("^.*$"),
llvm::Regex("^[a-z][a-z0-9_]*$"),
llvm::Regex("^[a-z][a-zA-Z0-9]*$"),
@@ -887,7 +885,7 @@ bool IdentifierNamingCheck::matchesStyle(
if (!Name.consume_back(Style.Suffix))
return false;
if (IdentifierNamingCheck::HungarianPrefixType::HPT_Off != Style.HPType) {
- std::string HNPrefix = HungarianNotation.getPrefix(Decl, HNOption);
+ const std::string HNPrefix = HungarianNotation.getPrefix(Decl, HNOption);
if (!HNPrefix.empty()) {
if (!Name.consume_front(HNPrefix))
return false;
@@ -914,7 +912,7 @@ std::string IdentifierNamingCheck::fixupWithCase(
const IdentifierNamingCheck::NamingStyle &Style,
const IdentifierNamingCheck::HungarianNotationOption &HNOption,
IdentifierNamingCheck::CaseType Case) const {
- static llvm::Regex Splitter(
+ static const llvm::Regex Splitter(
"([a-z0-9A-Z]*)(_+)|([A-Z]?[a-z0-9]+)([A-Z]|$)|([A-Z]+)([A-Z]|$)");
SmallVector<StringRef, 8> Substrs;
@@ -1070,7 +1068,7 @@ bool IdentifierNamingCheck::isParamInMainLikeFunction(
return false;
if (!IsIntType(FDecl->parameters()[0]->getType()))
return false;
- MainType Type = IsCharPtrPtr(FDecl->parameters()[1]->getType());
+ const MainType Type = IsCharPtrPtr(FDecl->parameters()[1]->getType());
if (Type == None)
return false;
if (FDecl->getNumParams() == 3 &&
@@ -1078,13 +1076,14 @@ bool IdentifierNamingCheck::isParamInMainLikeFunction(
return false;
if (Type == Main) {
- static llvm::Regex Matcher(
+ static const llvm::Regex Matcher(
"(^[Mm]ain([_A-Z]|$))|([a-z0-9_]Main([_A-Z]|$))|(_main(_|$))");
assert(Matcher.isValid() && "Invalid Matcher for main like functions.");
return Matcher.match(FDecl->getName());
}
- static llvm::Regex Matcher("(^((W[Mm])|(wm))ain([_A-Z]|$))|([a-z0-9_]W[Mm]"
- "ain([_A-Z]|$))|(_wmain(_|$))");
+ static const llvm::Regex Matcher(
+ "(^((W[Mm])|(wm))ain([_A-Z]|$))|([a-z0-9_]W[Mm]"
+ "ain([_A-Z]|$))|(_wmain(_|$))");
assert(Matcher.isValid() && "Invalid Matcher for wmain like functions.");
return Matcher.match(FDecl->getName());
}
@@ -1212,7 +1211,7 @@ StyleKind IdentifierNamingCheck::findStyleKind(
if (const auto *Decl = dyn_cast<ParmVarDecl>(D)) {
if (isParamInMainLikeFunction(*Decl, IgnoreMainLikeFunctions))
return SK_Invalid;
- QualType Type = Decl->getType();
+ const QualType Type = Decl->getType();
if (Decl->isConstexpr() && NamingStyles[SK_ConstexprVariable])
return SK_ConstexprVariable;
@@ -1381,7 +1380,7 @@ IdentifierNamingCheck::getDeclFailureInfo(const NamedDecl *Decl,
if (Decl->isImplicit())
return std::nullopt;
- SourceLocation Loc = Decl->getLocation();
+ const SourceLocation Loc = Decl->getLocation();
const FileStyle &FileStyle = getStyleForFile(SM.getFilename(Loc));
if (!FileStyle.isActive())
return std::nullopt;
@@ -1398,7 +1397,7 @@ IdentifierNamingCheck::getDeclFailureInfo(const NamedDecl *Decl,
std::optional<RenamerClangTidyCheck::FailureInfo>
IdentifierNamingCheck::getMacroFailureInfo(const Token &MacroNameTok,
const SourceManager &SM) const {
- SourceLocation Loc = MacroNameTok.getLocation();
+ const SourceLocation Loc = MacroNameTok.getLocation();
const FileStyle &Style = getStyleForFile(SM.getFilename(Loc));
if (!Style.isActive())
return std::nullopt;
@@ -1431,13 +1430,13 @@ IdentifierNamingCheck::getStyleForFile(StringRef FileName) const {
if (!GetConfigPerFile)
return *MainFileStyle;
- StringRef RealFileName = getRealFileName(FileName);
- StringRef Parent = llvm::sys::path::parent_path(RealFileName);
+ const StringRef RealFileName = getRealFileName(FileName);
+ const StringRef Parent = llvm::sys::path::parent_path(RealFileName);
auto Iter = NamingStylesCache.find(Parent);
if (Iter != NamingStylesCache.end())
return Iter->getValue();
- llvm::StringRef CheckName = getID();
+ const llvm::StringRef CheckName = getID();
ClangTidyOptions Options = Context->getOptionsForFile(RealFileName);
if (Options.Checks && GlobList(*Options.Checks).contains(CheckName)) {
auto It = NamingStylesCache.try_emplace(
@@ -1459,7 +1458,7 @@ StyleKind IdentifierNamingCheck::findStyleKindForAnonField(
utils::findOutermostIndirectFieldDeclForField(AnonField);
assert(IFD && "Found an anonymous record field without an IndirectFieldDecl");
- QualType Type = AnonField->getType();
+ const QualType Type = AnonField->getType();
if (const auto *F = dyn_cast<FieldDecl>(IFD->chain().front())) {
return findStyleKindForField(F, Type, NamingStyles);
diff --git a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index 6f6da57..c135b42 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -22,17 +22,19 @@ namespace clang::tidy::readability {
namespace {
AST_MATCHER(Stmt, isMacroExpansion) {
- SourceManager &SM = Finder->getASTContext().getSourceManager();
- SourceLocation Loc = Node.getBeginLoc();
+ const SourceManager &SM = Finder->getASTContext().getSourceManager();
+ const SourceLocation Loc = Node.getBeginLoc();
return SM.isMacroBodyExpansion(Loc) || SM.isMacroArgExpansion(Loc);
}
AST_MATCHER(Stmt, isC23) { return Finder->getASTContext().getLangOpts().C23; }
+// Preserve same name as AST_MATCHER(isNULLMacroExpansion)
+// NOLINTNEXTLINE(llvm-prefer-static-over-anonymous-namespace)
bool isNULLMacroExpansion(const Stmt *Statement, ASTContext &Context) {
- SourceManager &SM = Context.getSourceManager();
+ const SourceManager &SM = Context.getSourceManager();
const LangOptions &LO = Context.getLangOpts();
- SourceLocation Loc = Statement->getBeginLoc();
+ const SourceLocation Loc = Statement->getBeginLoc();
return SM.isMacroBodyExpansion(Loc) &&
Lexer::getImmediateMacroName(Loc, SM, LO) == "NULL";
}
@@ -75,11 +77,11 @@ static void fixGenericExprCastToBool(DiagnosticBuilder &Diag,
bool UseUpperCaseLiteralSuffix) {
// In case of expressions like (! integer), we should remove the redundant not
// operator and use inverted comparison (integer == 0).
- bool InvertComparison =
+ const bool InvertComparison =
Parent != nullptr && isUnaryLogicalNotOperator(Parent);
if (InvertComparison) {
- SourceLocation ParentStartLoc = Parent->getBeginLoc();
- SourceLocation ParentEndLoc =
+ const SourceLocation ParentStartLoc = Parent->getBeginLoc();
+ const SourceLocation ParentEndLoc =
cast<UnaryOperator>(Parent)->getSubExpr()->getBeginLoc();
Diag << FixItHint::CreateRemoval(
CharSourceRange::getCharRange(ParentStartLoc, ParentEndLoc));
@@ -89,9 +91,9 @@ static void fixGenericExprCastToBool(DiagnosticBuilder &Diag,
const Expr *SubExpr = Cast->getSubExpr();
- bool NeedInnerParens =
+ const bool NeedInnerParens =
utils::fixit::areParensNeededForStatement(*SubExpr->IgnoreImpCasts());
- bool NeedOuterParens =
+ const bool NeedOuterParens =
Parent != nullptr && utils::fixit::areParensNeededForStatement(*Parent);
std::string StartLocInsertion;
@@ -131,7 +133,7 @@ static void fixGenericExprCastToBool(DiagnosticBuilder &Diag,
EndLocInsertion += ")";
}
- SourceLocation EndLoc = Lexer::getLocForEndOfToken(
+ const SourceLocation EndLoc = Lexer::getLocForEndOfToken(
Cast->getEndLoc(), 0, Context.getSourceManager(), Context.getLangOpts());
Diag << FixItHint::CreateInsertion(EndLoc, EndLocInsertion);
}
@@ -165,8 +167,8 @@ static StringRef getEquivalentBoolLiteralForExpr(const Expr *Expression,
}
static bool needsSpacePrefix(SourceLocation Loc, ASTContext &Context) {
- SourceRange PrefixRange(Loc.getLocWithOffset(-1), Loc);
- StringRef SpaceBeforeStmtStr = Lexer::getSourceText(
+ const SourceRange PrefixRange(Loc.getLocWithOffset(-1), Loc);
+ const StringRef SpaceBeforeStmtStr = Lexer::getSourceText(
CharSourceRange::getCharRange(PrefixRange), Context.getSourceManager(),
Context.getLangOpts(), nullptr);
if (SpaceBeforeStmtStr.empty())
@@ -196,7 +198,7 @@ static void fixGenericExprCastFromBool(DiagnosticBuilder &Diag,
.str());
if (NeedParens) {
- SourceLocation EndLoc = Lexer::getLocForEndOfToken(
+ const SourceLocation EndLoc = Lexer::getLocForEndOfToken(
Cast->getEndLoc(), 0, Context.getSourceManager(),
Context.getLangOpts());
@@ -232,7 +234,7 @@ static bool isCastAllowedInCondition(const ImplicitCastExpr *Cast,
std::queue<const Stmt *> Q;
Q.push(Cast);
- TraversalKindScope RAII(Context, TK_AsIs);
+ const TraversalKindScope RAII(Context, TK_AsIs);
while (!Q.empty()) {
for (const auto &N : Context.getParents(*Q.front())) {
@@ -360,7 +362,6 @@ void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
void ImplicitBoolConversionCheck::check(
const MatchFinder::MatchResult &Result) {
-
if (const auto *CastToBool =
Result.Nodes.getNodeAs<ImplicitCastExpr>("implicitCastToBool")) {
const auto *Parent = Result.Nodes.getNodeAs<Stmt>("parentStmt");
@@ -394,7 +395,7 @@ void ImplicitBoolConversionCheck::handleCastToBool(const ImplicitCastExpr *Cast,
auto Diag = diag(Cast->getBeginLoc(), "implicit conversion %0 -> 'bool'")
<< Cast->getSubExpr()->getType();
- StringRef EquivalentLiteral =
+ const StringRef EquivalentLiteral =
getEquivalentBoolLiteralForExpr(Cast->getSubExpr(), Context);
if (!EquivalentLiteral.empty()) {
Diag << tooling::fixit::createReplacement(*Cast, EquivalentLiteral);
@@ -407,14 +408,13 @@ void ImplicitBoolConversionCheck::handleCastToBool(const ImplicitCastExpr *Cast,
void ImplicitBoolConversionCheck::handleCastFromBool(
const ImplicitCastExpr *Cast, const ImplicitCastExpr *NextImplicitCast,
ASTContext &Context) {
- QualType DestType =
+ const QualType DestType =
NextImplicitCast ? NextImplicitCast->getType() : Cast->getType();
auto Diag = diag(Cast->getBeginLoc(), "implicit conversion 'bool' -> %0")
<< DestType;
if (const auto *BoolLiteral =
dyn_cast<CXXBoolLiteralExpr>(Cast->getSubExpr()->IgnoreParens())) {
-
const auto EquivalentForBoolLiteral =
getEquivalentForBoolLiteral(BoolLiteral, DestType, Context);
if (UseUpperCaseLiteralSuffix)
diff --git a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h
index f88ceb1..101089c 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_IMPLICIT_BOOL_CONVERSION_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_IMPLICIT_BOOL_CONVERSION_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_IMPLICITBOOLCONVERSIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_IMPLICITBOOLCONVERSIONCHECK_H
#include "../ClangTidyCheck.h"
@@ -41,4 +41,4 @@ private:
} // namespace clang::tidy::readability
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_IMPLICIT_BOOL_CONVERSION_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_IMPLICITBOOLCONVERSIONCHECK_H
diff --git a/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp b/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
index 93580a7..7b27ab9 100644
--- a/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
@@ -107,18 +107,22 @@ findDifferingParamsInDeclaration(const FunctionDecl *ParameterSourceDeclaration,
while (SourceParamIt != ParameterSourceDeclaration->param_end() &&
OtherParamIt != OtherDeclaration->param_end()) {
+ if ((*SourceParamIt)->isParameterPack() !=
+ (*OtherParamIt)->isParameterPack())
+ break;
+
auto SourceParamName = (*SourceParamIt)->getName();
auto OtherParamName = (*OtherParamIt)->getName();
// FIXME: Provide a way to extract commented out parameter name from comment
// next to it.
if (!nameMatch(SourceParamName, OtherParamName, Strict)) {
- SourceRange OtherParamNameRange =
+ const SourceRange OtherParamNameRange =
DeclarationNameInfo((*OtherParamIt)->getDeclName(),
(*OtherParamIt)->getLocation())
.getSourceRange();
- bool GenerateFixItHint = checkIfFixItHintIsApplicable(
+ const bool GenerateFixItHint = checkIfFixItHintIsApplicable(
ParameterSourceDeclaration, *SourceParamIt, OriginalDeclaration);
DifferingParams.emplace_back(SourceParamName, OtherParamName,
@@ -137,11 +141,11 @@ findInconsistentDeclarations(const FunctionDecl *OriginalDeclaration,
const FunctionDecl *ParameterSourceDeclaration,
SourceManager &SM, bool Strict) {
InconsistentDeclarationsContainer InconsistentDeclarations;
- SourceLocation ParameterSourceLocation =
+ const SourceLocation ParameterSourceLocation =
ParameterSourceDeclaration->getLocation();
for (const FunctionDecl *OtherDeclaration : OriginalDeclaration->redecls()) {
- SourceLocation OtherLocation = OtherDeclaration->getLocation();
+ const SourceLocation OtherLocation = OtherDeclaration->getLocation();
if (OtherLocation != ParameterSourceLocation) { // Skip self.
DifferingParamsContainer DifferingParams =
findDifferingParamsInDeclaration(ParameterSourceDeclaration,
@@ -305,7 +309,7 @@ void InconsistentDeclarationParameterNameCheck::check(
const FunctionDecl *ParameterSourceDeclaration =
getParameterSourceDeclaration(OriginalDeclaration);
- InconsistentDeclarationsContainer InconsistentDeclarations =
+ const InconsistentDeclarationsContainer InconsistentDeclarations =
findInconsistentDeclarations(OriginalDeclaration,
ParameterSourceDeclaration,
*Result.SourceManager, Strict);
@@ -315,7 +319,7 @@ void InconsistentDeclarationParameterNameCheck::check(
return;
}
- SourceLocation StartLoc = OriginalDeclaration->getBeginLoc();
+ const SourceLocation StartLoc = OriginalDeclaration->getBeginLoc();
if (StartLoc.isMacroID() && IgnoreMacros) {
markRedeclarationsAsVisited(OriginalDeclaration);
return;
diff --git a/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h b/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h
index 289e131d..32218e1 100644
--- a/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_INCONSISTENT_DECLARATION_PARAMETER_NAME_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_INCONSISTENT_DECLARATION_PARAMETER_NAME_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_INCONSISTENTDECLARATIONPARAMETERNAMECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_INCONSISTENTDECLARATIONPARAMETERNAMECHECK_H
#include "../ClangTidyCheck.h"
@@ -45,4 +45,4 @@ private:
} // namespace clang::tidy::readability
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_INCONSISTENT_DECLARATION_PARAMETER_NAME_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_INCONSISTENTDECLARATIONPARAMETERNAMECHECK_H
diff --git a/clang-tools-extra/clang-tidy/readability/IsolateDeclarationCheck.cpp b/clang-tools-extra/clang-tidy/readability/IsolateDeclarationCheck.cpp
index bc5edec..fa5a0b7 100644
--- a/clang-tools-extra/clang-tidy/readability/IsolateDeclarationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IsolateDeclarationCheck.cpp
@@ -107,7 +107,7 @@ static bool typeIsMemberPointer(const Type *T) {
static std::optional<std::vector<SourceRange>>
declRanges(const DeclStmt *DS, const SourceManager &SM,
const LangOptions &LangOpts) {
- std::size_t DeclCount = std::distance(DS->decl_begin(), DS->decl_end());
+ const std::size_t DeclCount = std::distance(DS->decl_begin(), DS->decl_end());
if (DeclCount < 2)
return std::nullopt;
@@ -157,7 +157,7 @@ declRanges(const DeclStmt *DS, const SourceManager &SM,
if (Start.isInvalid() || Start.isMacroID())
break;
- Token T = getPreviousToken(Start, SM, LangOpts);
+ const Token T = getPreviousToken(Start, SM, LangOpts);
if (T.is(tok::l_paren)) {
Start = findPreviousTokenStart(Start, SM, LangOpts);
continue;
@@ -165,7 +165,7 @@ declRanges(const DeclStmt *DS, const SourceManager &SM,
break;
}
- SourceRange DeclRange(DS->getBeginLoc(), Start);
+ const SourceRange DeclRange(DS->getBeginLoc(), Start);
if (DeclRange.isInvalid() || isMacroID(DeclRange))
return std::nullopt;
@@ -183,13 +183,13 @@ declRanges(const DeclStmt *DS, const SourceManager &SM,
if (typeIsMemberPointer(CurrentDecl->getType().IgnoreParens().getTypePtr()))
return std::nullopt;
- SourceLocation DeclEnd =
+ const SourceLocation DeclEnd =
CurrentDecl->hasInit()
? findNextTerminator(CurrentDecl->getInit()->getEndLoc(), SM,
LangOpts)
: findNextTerminator(CurrentDecl->getEndLoc(), SM, LangOpts);
- SourceRange VarNameRange(DeclBegin, DeclEnd);
+ const SourceRange VarNameRange(DeclBegin, DeclEnd);
if (VarNameRange.isInvalid() || isMacroID(VarNameRange))
return std::nullopt;
@@ -206,7 +206,7 @@ collectSourceRanges(llvm::ArrayRef<SourceRange> Ranges, const SourceManager &SM,
Snippets.reserve(Ranges.size());
for (const auto &Range : Ranges) {
- CharSourceRange CharRange = Lexer::getAsCharRange(
+ const CharSourceRange CharRange = Lexer::getAsCharRange(
CharSourceRange::getCharRange(Range.getBegin(), Range.getEnd()), SM,
LangOpts);
@@ -214,7 +214,7 @@ collectSourceRanges(llvm::ArrayRef<SourceRange> Ranges, const SourceManager &SM,
return std::nullopt;
bool InvalidText = false;
- StringRef Snippet =
+ const StringRef Snippet =
Lexer::getSourceText(CharRange, SM, LangOpts, &InvalidText);
if (InvalidText)
@@ -262,7 +262,7 @@ void IsolateDeclarationCheck::check(const MatchFinder::MatchResult &Result) {
return;
std::vector<std::string> NewDecls = createIsolatedDecls(*PotentialSnippets);
- std::string Replacement = llvm::join(
+ const std::string Replacement = llvm::join(
NewDecls,
(Twine("\n") + Lexer::getIndentationForLine(WholeDecl->getBeginLoc(),
*Result.SourceManager))
diff --git a/clang-tools-extra/clang-tidy/readability/IsolateDeclarationCheck.h b/clang-tools-extra/clang-tidy/readability/IsolateDeclarationCheck.h
index 750b4d8..0bf22e5 100644
--- a/clang-tools-extra/clang-tidy/readability/IsolateDeclarationCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/IsolateDeclarationCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_ISOLATEDECLCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_ISOLATEDECLCHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_ISOLATEDECLARATIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_ISOLATEDECLARATIONCHECK_H
#include "../ClangTidyCheck.h"
@@ -28,4 +28,4 @@ public:
} // namespace clang::tidy::readability
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_ISOLATEDECLCHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_ISOLATEDECLARATIONCHECK_H
diff --git a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
index a38f7bc..6ba1408 100644
--- a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
@@ -25,7 +25,6 @@ namespace clang {
static bool isUsedToInitializeAConstant(const MatchFinder::MatchResult &Result,
const DynTypedNode &Node) {
-
const auto *AsDecl = Node.get<DeclaratorDecl>();
if (AsDecl) {
if (AsDecl->getType().isConstQualified())
@@ -45,7 +44,6 @@ static bool isUsedToInitializeAConstant(const MatchFinder::MatchResult &Result,
static bool isUsedToDefineATypeAlias(const MatchFinder::MatchResult &Result,
const DynTypedNode &Node) {
-
if (Node.get<TypeAliasDecl>() || Node.get<TypedefNameDecl>())
return true;
@@ -144,8 +142,7 @@ void MagicNumbersCheck::registerMatchers(MatchFinder *Finder) {
}
void MagicNumbersCheck::check(const MatchFinder::MatchResult &Result) {
-
- TraversalKindScope RAII(*Result.Context, TK_AsIs);
+ const TraversalKindScope RAII(*Result.Context, TK_AsIs);
checkBoundMatch<IntegerLiteral>(Result, "integer");
checkBoundMatch<FloatingLiteral>(Result, "float");
@@ -248,7 +245,7 @@ bool MagicNumbersCheck::isBitFieldWidth(
bool MagicNumbersCheck::isUserDefinedLiteral(
const clang::ast_matchers::MatchFinder::MatchResult &Result,
const clang::Expr &Literal) const {
- DynTypedNodeList Parents = Result.Context->getParents(Literal);
+ const DynTypedNodeList Parents = Result.Context->getParents(Literal);
if (Parents.empty())
return false;
return Parents[0].get<UserDefinedLiteral>() != nullptr;
diff --git a/clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp b/clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp
index bea6888..ddc92ef 100644
--- a/clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp
@@ -59,7 +59,7 @@ public:
UsageKind Usage = Unused;
template <class T> const T *getParent(const Expr *E) {
- DynTypedNodeList Parents = Ctxt.getParents(*E);
+ const DynTypedNodeList Parents = Ctxt.getParents(*E);
if (Parents.size() != 1)
return nullptr;
@@ -241,7 +241,7 @@ void MakeMemberFunctionConstCheck::registerMatchers(MatchFinder *Finder) {
}
static SourceLocation getConstInsertionPoint(const CXXMethodDecl *M) {
- TypeSourceInfo *TSI = M->getTypeSourceInfo();
+ const TypeSourceInfo *TSI = M->getTypeSourceInfo();
if (!TSI)
return {};
diff --git a/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp b/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
index e15b2ec..69bc554 100644
--- a/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
@@ -56,8 +56,8 @@ static void addParentheses(const BinaryOperator *BinOp,
if (!BinOp)
return;
- int Precedence1 = getPrecedence(BinOp);
- int Precedence2 = getPrecedence(ParentBinOp);
+ const int Precedence1 = getPrecedence(BinOp);
+ const int Precedence2 = getPrecedence(ParentBinOp);
if (ParentBinOp != nullptr && Precedence1 != Precedence2 && Precedence1 > 0 &&
Precedence2 > 0) {
diff --git a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
index 0765d8d..450961c 100644
--- a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
@@ -21,7 +21,7 @@ static const IfStmt *getPrecedingIf(const SourceManager &SM,
if (Parents.size() != 1)
return nullptr;
if (const auto *PrecedingIf = Parents[0].get<IfStmt>()) {
- SourceLocation PreviousElseLoc = PrecedingIf->getElseLoc();
+ const SourceLocation PreviousElseLoc = PrecedingIf->getElseLoc();
if (SM.getExpansionLineNumber(PreviousElseLoc) ==
SM.getExpansionLineNumber(If->getIfLoc()))
return PrecedingIf;
@@ -33,7 +33,7 @@ void MisleadingIndentationCheck::danglingElseCheck(const SourceManager &SM,
ASTContext *Context,
const IfStmt *If) {
SourceLocation IfLoc = If->getIfLoc();
- SourceLocation ElseLoc = If->getElseLoc();
+ const SourceLocation ElseLoc = If->getElseLoc();
if (IfLoc.isMacroID() || ElseLoc.isMacroID())
return;
@@ -89,8 +89,8 @@ void MisleadingIndentationCheck::missingBracesCheck(
if (isa<CompoundStmt>(Inner))
continue;
- SourceLocation InnerLoc = Inner->getBeginLoc();
- SourceLocation OuterLoc = CurrentStmt->getBeginLoc();
+ const SourceLocation InnerLoc = Inner->getBeginLoc();
+ const SourceLocation OuterLoc = CurrentStmt->getBeginLoc();
if (InnerLoc.isInvalid() || InnerLoc.isMacroID() || OuterLoc.isInvalid() ||
OuterLoc.isMacroID())
@@ -101,7 +101,7 @@ void MisleadingIndentationCheck::missingBracesCheck(
continue;
const Stmt *NextStmt = CStmt->body_begin()[I + 1];
- SourceLocation NextLoc = NextStmt->getBeginLoc();
+ const SourceLocation NextLoc = NextStmt->getBeginLoc();
if (NextLoc.isInvalid() || NextLoc.isMacroID())
continue;
diff --git a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.h b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.h
index 8347f1a..edd2b1a 100644
--- a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_MISLEADING_INDENTATION_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_MISLEADING_INDENTATION_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_MISLEADINGINDENTATIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_MISLEADINGINDENTATIONCHECK_H
#include "../ClangTidyCheck.h"
@@ -38,4 +38,4 @@ private:
} // namespace clang::tidy::readability
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_MISLEADING_INDENTATION_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_MISLEADINGINDENTATIONCHECK_H
diff --git a/clang-tools-extra/clang-tidy/readability/MisplacedArrayIndexCheck.h b/clang-tools-extra/clang-tidy/readability/MisplacedArrayIndexCheck.h
index 0a6e0c8..f0c565b 100644
--- a/clang-tools-extra/clang-tidy/readability/MisplacedArrayIndexCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/MisplacedArrayIndexCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_MISPLACED_ARRAY_INDEX_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_MISPLACED_ARRAY_INDEX_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_MISPLACEDARRAYINDEXCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_MISPLACEDARRAYINDEXCHECK_H
#include "../ClangTidyCheck.h"
@@ -28,4 +28,4 @@ public:
} // namespace clang::tidy::readability
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_MISPLACED_ARRAY_INDEX_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_MISPLACEDARRAYINDEXCHECK_H
diff --git a/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp
index 7251d63..1283632 100644
--- a/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp
@@ -79,7 +79,7 @@ void NamedParameterCheck::check(const MatchFinder::MatchResult &Result) {
// void foo(int /*unused*/)
const char *Begin = SM.getCharacterData(Parm->getBeginLoc());
const char *End = SM.getCharacterData(Parm->getLocation());
- StringRef Data(Begin, End - Begin);
+ const StringRef Data(Begin, End - Begin);
if (Data.contains("/*"))
continue;
@@ -104,7 +104,7 @@ void NamedParameterCheck::check(const MatchFinder::MatchResult &Result) {
if (M && M->size_overridden_methods() > 0) {
const ParmVarDecl *OtherParm =
(*M->begin_overridden_methods())->getParamDecl(P.second);
- StringRef Name = OtherParm->getName();
+ const StringRef Name = OtherParm->getName();
if (!Name.empty())
NewName = Name;
}
@@ -112,7 +112,7 @@ void NamedParameterCheck::check(const MatchFinder::MatchResult &Result) {
// If the definition has a named parameter use that name.
if (Definition) {
const ParmVarDecl *DefParm = Definition->getParamDecl(P.second);
- StringRef Name = DefParm->getName();
+ const StringRef Name = DefParm->getName();
if (!Name.empty())
NewName = Name;
}
diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
index 744d23a..dffd7fd 100644
--- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
@@ -70,7 +70,7 @@ getNamespaceNameAsWritten(SourceLocation &Loc, const SourceManager &Sources,
--Nesting;
} else if (Nesting == 0) {
if (T->is(tok::raw_identifier)) {
- StringRef ID = T->getRawIdentifier();
+ const StringRef ID = T->getRawIdentifier();
if (ID != "namespace")
Result.append(std::string(ID));
if (ID == "inline")
@@ -96,13 +96,13 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) {
// Don't require closing comments for namespaces spanning less than certain
// number of lines.
- unsigned StartLine = Sources.getSpellingLineNumber(ND->getBeginLoc());
- unsigned EndLine = Sources.getSpellingLineNumber(ND->getRBraceLoc());
+ const unsigned StartLine = Sources.getSpellingLineNumber(ND->getBeginLoc());
+ const unsigned EndLine = Sources.getSpellingLineNumber(ND->getRBraceLoc());
if (EndLine - StartLine + 1 <= ShortNamespaceLines)
return;
// Find next token after the namespace closing brace.
- SourceLocation AfterRBrace = Lexer::getLocForEndOfToken(
+ const SourceLocation AfterRBrace = Lexer::getLocForEndOfToken(
ND->getRBraceLoc(), /*Offset=*/0, Sources, getLangOpts());
SourceLocation Loc = AfterRBrace;
SourceLocation LBraceLoc = ND->getBeginLoc();
@@ -137,7 +137,8 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) {
if (!locationsInSameFile(Sources, ND->getRBraceLoc(), Loc))
return;
- bool NextTokenIsOnSameLine = Sources.getSpellingLineNumber(Loc) == EndLine;
+ const bool NextTokenIsOnSameLine =
+ Sources.getSpellingLineNumber(Loc) == EndLine;
// If we insert a line comment before the token in the same line, we need
// to insert a line break.
bool NeedLineBreak = NextTokenIsOnSameLine && Tok.isNot(tok::eof);
@@ -148,11 +149,12 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) {
// Try to find existing namespace closing comment on the same line.
if (Tok.is(tok::comment) && NextTokenIsOnSameLine) {
- StringRef Comment(Sources.getCharacterData(Loc), Tok.getLength());
+ const StringRef Comment(Sources.getCharacterData(Loc), Tok.getLength());
SmallVector<StringRef, 7> Groups;
if (NamespaceCommentPattern.match(Comment, &Groups)) {
- StringRef NamespaceNameInComment = Groups.size() > 5 ? Groups[5] : "";
- StringRef Anonymous = Groups.size() > 3 ? Groups[3] : "";
+ const StringRef NamespaceNameInComment =
+ Groups.size() > 5 ? Groups[5] : "";
+ const StringRef Anonymous = Groups.size() > 3 ? Groups[3] : "";
if ((ND->isAnonymousNamespace() && NamespaceNameInComment.empty()) ||
(*NamespaceNameAsWritten == NamespaceNameInComment &&
@@ -186,7 +188,7 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) {
// multi-line or there may be other tokens behind it.
}
- std::string NamespaceNameForDiag =
+ const std::string NamespaceNameForDiag =
ND->isAnonymousNamespace()
? "anonymous namespace"
: ("namespace '" + *NamespaceNameAsWritten + "'");
@@ -203,7 +205,7 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) {
Fix.append("\n");
// Place diagnostic at an old comment, or closing brace if we did not have it.
- SourceLocation DiagLoc =
+ const SourceLocation DiagLoc =
OldCommentRange.getBegin() != OldCommentRange.getEnd()
? OldCommentRange.getBegin()
: ND->getRBraceLoc();
diff --git a/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp b/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
index 29fff39..9fbe3ba 100644
--- a/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -155,7 +155,7 @@ void NonConstParameterCheck::diagnoseNonConstParameters() {
dyn_cast_or_null<const FunctionDecl>(Par->getParentFunctionOrMethod());
if (!Function)
continue;
- unsigned Index = Par->getFunctionScopeIndex();
+ const unsigned Index = Par->getFunctionScopeIndex();
for (FunctionDecl *FnDecl : Function->redecls()) {
if (FnDecl->getNumParams() <= Index)
continue;
diff --git a/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.h b/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.h
index b015618..7dcb16e 100644
--- a/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_NON_CONST_PARAMETER_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_NON_CONST_PARAMETER_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_NONCONSTPARAMETERCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_NONCONSTPARAMETERCHECK_H
#include "../ClangTidyCheck.h"
@@ -59,4 +59,4 @@ private:
} // namespace clang::tidy::readability
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_NON_CONST_PARAMETER_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_NONCONSTPARAMETERCHECK_H
diff --git a/clang-tools-extra/clang-tidy/readability/OperatorsRepresentationCheck.cpp b/clang-tools-extra/clang-tidy/readability/OperatorsRepresentationCheck.cpp
index 196fb31..05f31c7 100644
--- a/clang-tools-extra/clang-tidy/readability/OperatorsRepresentationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/OperatorsRepresentationCheck.cpp
@@ -23,7 +23,7 @@ static StringRef getOperatorSpelling(SourceLocation Loc, ASTContext &Context) {
if (Loc.isInvalid())
return {};
- SourceManager &SM = Context.getSourceManager();
+ const SourceManager &SM = Context.getSourceManager();
Loc = SM.getSpellingLoc(Loc);
if (Loc.isInvalid())
@@ -41,7 +41,7 @@ AST_MATCHER_P2(BinaryOperator, hasInvalidBinaryOperatorRepresentation,
if (Node.getOpcode() != Kind || ExpectedRepresentation.empty())
return false;
- StringRef Spelling =
+ const StringRef Spelling =
getOperatorSpelling(Node.getOperatorLoc(), Finder->getASTContext());
return !Spelling.empty() && Spelling != ExpectedRepresentation;
}
@@ -52,7 +52,7 @@ AST_MATCHER_P2(UnaryOperator, hasInvalidUnaryOperatorRepresentation,
if (Node.getOpcode() != Kind || ExpectedRepresentation.empty())
return false;
- StringRef Spelling =
+ const StringRef Spelling =
getOperatorSpelling(Node.getOperatorLoc(), Finder->getASTContext());
return !Spelling.empty() && Spelling != ExpectedRepresentation;
}
@@ -63,7 +63,7 @@ AST_MATCHER_P2(CXXOperatorCallExpr, hasInvalidOverloadedOperatorRepresentation,
if (Node.getOperator() != Kind || ExpectedRepresentation.empty())
return false;
- StringRef Spelling =
+ const StringRef Spelling =
getOperatorSpelling(Node.getOperatorLoc(), Finder->getASTContext());
return !Spelling.empty() && Spelling != ExpectedRepresentation;
}
@@ -136,11 +136,9 @@ getRepresentation(const std::vector<llvm::StringRef> &Config,
template <typename T>
static bool isAnyOperatorEnabled(const std::vector<llvm::StringRef> &Config,
const T &Operators) {
- for (const auto &[traditional, alternative] : Operators) {
- if (!getRepresentation(Config, traditional, alternative).empty())
- return true;
- }
- return false;
+ return llvm::any_of(Operators, [&](const auto &Op) {
+ return !getRepresentation(Config, Op.first, Op.second).empty();
+ });
}
OperatorsRepresentationCheck::OperatorsRepresentationCheck(
@@ -275,7 +273,6 @@ void OperatorsRepresentationCheck::registerMatchers(MatchFinder *Finder) {
void OperatorsRepresentationCheck::check(
const MatchFinder::MatchResult &Result) {
-
SourceLocation Loc;
if (const auto *Op = Result.Nodes.getNodeAs<BinaryOperator>("binary_op"))
@@ -297,9 +294,9 @@ void OperatorsRepresentationCheck::check(
if (TokenRange.isInvalid())
return;
- StringRef Spelling = Lexer::getSourceText(TokenRange, *Result.SourceManager,
- Result.Context->getLangOpts());
- StringRef TranslatedSpelling = translate(Spelling);
+ const StringRef Spelling = Lexer::getSourceText(
+ TokenRange, *Result.SourceManager, Result.Context->getLangOpts());
+ const StringRef TranslatedSpelling = translate(Spelling);
if (TranslatedSpelling.empty())
return;
@@ -312,7 +309,7 @@ void OperatorsRepresentationCheck::check(
SourceRepresentation = "a traditional";
TargetRepresentation = "an alternative";
- StringRef SpellingEx = Lexer::getSourceText(
+ const StringRef SpellingEx = Lexer::getSourceText(
CharSourceRange::getCharRange(
TokenRange.getBegin().getLocWithOffset(-1),
TokenRange.getBegin().getLocWithOffset(Spelling.size() + 1U)),
diff --git a/clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp b/clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp
index 942a0a8..556f7fe 100644
--- a/clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp
@@ -44,18 +44,18 @@ findQualToken(const VarDecl *Decl, Qualifier Qual,
SourceLocation BeginLoc = Decl->getQualifierLoc().getBeginLoc();
if (BeginLoc.isInvalid())
BeginLoc = Decl->getBeginLoc();
- SourceLocation EndLoc = Decl->getLocation();
+ const SourceLocation EndLoc = Decl->getLocation();
- CharSourceRange FileRange = Lexer::makeFileCharRange(
+ const CharSourceRange FileRange = Lexer::makeFileCharRange(
CharSourceRange::getCharRange(BeginLoc, EndLoc), *Result.SourceManager,
Result.Context->getLangOpts());
if (FileRange.isInvalid())
return std::nullopt;
- tok::TokenKind Tok = Qual == Qualifier::Const ? tok::kw_const
- : Qual == Qualifier::Volatile ? tok::kw_volatile
- : tok::kw_restrict;
+ const tok::TokenKind Tok = Qual == Qualifier::Const ? tok::kw_const
+ : Qual == Qualifier::Volatile ? tok::kw_volatile
+ : tok::kw_restrict;
return utils::lexer::getQualifyingToken(Tok, FileRange, *Result.Context,
*Result.SourceManager);
@@ -90,13 +90,13 @@ mergeReplacementRange(SourceRange &TypeSpecifier, const Token &ConstToken) {
}
static bool isPointerConst(QualType QType) {
- QualType Pointee = QType->getPointeeType();
+ const QualType Pointee = QType->getPointeeType();
assert(!Pointee.isNull() && "can't have a null Pointee");
return Pointee.isConstQualified();
}
static bool isAutoPointerConst(QualType QType) {
- QualType Pointee =
+ const QualType Pointee =
cast<AutoType>(QType->getPointeeType().getTypePtr())->desugar();
assert(!Pointee.isNull() && "can't have a null Pointee");
return Pointee.isConstQualified();
@@ -146,7 +146,6 @@ void QualifiedAutoCheck::registerMatchers(MatchFinder *Finder) {
return qualType(anyOf(qualType(pointerType(pointee(InnerMatchers...))),
qualType(substTemplateTypeParmType(hasReplacementType(
pointerType(pointee(InnerMatchers...)))))));
-
};
auto IsAutoDeducedToPointer =
@@ -223,33 +222,34 @@ void QualifiedAutoCheck::check(const MatchFinder::MatchResult &Result) {
if (Var->getLocation() == TypeSpecifier.getEnd().getLocWithOffset(1))
TypeSpecifier.setEnd(TypeSpecifier.getEnd().getLocWithOffset(1));
- CharSourceRange FixItRange = CharSourceRange::getCharRange(TypeSpecifier);
+ const CharSourceRange FixItRange =
+ CharSourceRange::getCharRange(TypeSpecifier);
if (FixItRange.isInvalid())
return;
SourceLocation FixitLoc = FixItRange.getBegin();
- for (SourceRange &Range : RemoveQualifiersRange) {
+ for (const SourceRange &Range : RemoveQualifiersRange) {
if (Range.getBegin() < FixitLoc)
FixitLoc = Range.getBegin();
}
- std::string ReplStr = [&] {
- llvm::StringRef PtrConst = isPointerConst(Var->getType()) ? "const " : "";
- llvm::StringRef LocalConst = IsLocalConst ? "const " : "";
- llvm::StringRef LocalVol = IsLocalVolatile ? "volatile " : "";
- llvm::StringRef LocalRestrict = IsLocalRestrict ? "__restrict " : "";
+ const std::string ReplStr = [&] {
+ const StringRef PtrConst = isPointerConst(Var->getType()) ? "const " : "";
+ const StringRef LocalConst = IsLocalConst ? "const " : "";
+ const StringRef LocalVol = IsLocalVolatile ? "volatile " : "";
+ const StringRef LocalRestrict = IsLocalRestrict ? "__restrict " : "";
return (PtrConst + "auto *" + LocalConst + LocalVol + LocalRestrict)
.str();
}();
- DiagnosticBuilder Diag =
+ const DiagnosticBuilder Diag =
diag(FixitLoc,
"'%select{|const }0%select{|volatile }1%select{|__restrict }2auto "
"%3' can be declared as '%4%3'")
<< IsLocalConst << IsLocalVolatile << IsLocalRestrict << Var->getName()
<< ReplStr;
- for (SourceRange &Range : RemoveQualifiersRange) {
+ for (const SourceRange &Range : RemoveQualifiersRange) {
Diag << FixItHint::CreateRemoval(CharSourceRange::getCharRange(Range));
}
@@ -286,7 +286,7 @@ void QualifiedAutoCheck::check(const MatchFinder::MatchResult &Result) {
if (TypeSpec->isInvalid() || TypeSpec->getBegin().isMacroID() ||
TypeSpec->getEnd().isMacroID())
return;
- SourceLocation InsertPos = TypeSpec->getBegin();
+ const SourceLocation InsertPos = TypeSpec->getBegin();
diag(InsertPos,
"'auto *%select{|const }0%select{|volatile }1%2' can be declared as "
"'const auto *%select{|const }0%select{|volatile }1%2'")
@@ -308,7 +308,7 @@ void QualifiedAutoCheck::check(const MatchFinder::MatchResult &Result) {
if (TypeSpec->isInvalid() || TypeSpec->getBegin().isMacroID() ||
TypeSpec->getEnd().isMacroID())
return;
- SourceLocation InsertPos = TypeSpec->getBegin();
+ const SourceLocation InsertPos = TypeSpec->getBegin();
diag(InsertPos, "'auto &%0' can be declared as 'const auto &%0'")
<< Var->getName() << FixItHint::CreateInsertion(InsertPos, "const ");
}
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index 569302e..afb6357 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -10,7 +10,7 @@
#include "../ClangTidyModule.h"
#include "../ClangTidyModuleRegistry.h"
#include "AmbiguousSmartptrResetCallCheck.h"
-#include "AvoidConstParamsInDecls.h"
+#include "AvoidConstParamsInDeclsCheck.h"
#include "AvoidNestedConditionalOperatorCheck.h"
#include "AvoidReturnWithVoidValueCheck.h"
#include "AvoidUnconditionalPreprocessorIfCheck.h"
@@ -19,7 +19,7 @@
#include "ContainerContainsCheck.h"
#include "ContainerDataPointerCheck.h"
#include "ContainerSizeEmptyCheck.h"
-#include "ConvertMemberFunctionsToStatic.h"
+#include "ConvertMemberFunctionsToStaticCheck.h"
#include "DeleteNullPointerCheck.h"
#include "DuplicateIncludeCheck.h"
#include "ElseAfterReturnCheck.h"
@@ -74,7 +74,7 @@ public:
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
CheckFactories.registerCheck<AmbiguousSmartptrResetCallCheck>(
"readability-ambiguous-smartptr-reset-call");
- CheckFactories.registerCheck<AvoidConstParamsInDecls>(
+ CheckFactories.registerCheck<AvoidConstParamsInDeclsCheck>(
"readability-avoid-const-params-in-decls");
CheckFactories.registerCheck<AvoidNestedConditionalOperatorCheck>(
"readability-avoid-nested-conditional-operator");
@@ -92,7 +92,7 @@ public:
"readability-container-data-pointer");
CheckFactories.registerCheck<ContainerSizeEmptyCheck>(
"readability-container-size-empty");
- CheckFactories.registerCheck<ConvertMemberFunctionsToStatic>(
+ CheckFactories.registerCheck<ConvertMemberFunctionsToStaticCheck>(
"readability-convert-member-functions-to-static");
CheckFactories.registerCheck<DeleteNullPointerCheck>(
"readability-delete-null-pointer");
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantAccessSpecifiersCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantAccessSpecifiersCheck.cpp
index e93aa16..14580a6 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantAccessSpecifiersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantAccessSpecifiersCheck.cpp
@@ -43,7 +43,7 @@ void RedundantAccessSpecifiersCheck::check(
LastASDecl = ASDecl;
if (CheckFirstDeclaration) {
- AccessSpecifier DefaultSpecifier =
+ const AccessSpecifier DefaultSpecifier =
MatchedDecl->isClass() ? AS_private : AS_public;
if (ASDecl->getAccess() == DefaultSpecifier) {
diag(ASDecl->getLocation(),
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp
index 1ee7522..21f481a 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp
@@ -9,6 +9,7 @@
#include "RedundantCastingCheck.h"
#include "../utils/FixItHintUtils.h"
#include "clang/AST/ASTContext.h"
+#include "clang/AST/TypeBase.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Lex/Lexer.h"
@@ -25,11 +26,11 @@ static bool areTypesEqual(QualType S, QualType D) {
if (TS != TD)
return false;
- QualType PtrS = S->getPointeeType();
- QualType PtrD = D->getPointeeType();
+ const QualType PtrS = S->getPointeeType();
+ const QualType PtrD = D->getPointeeType();
if (!PtrS.isNull() && !PtrD.isNull())
- return areTypesEqual(PtrS, PtrD);
+ return areTypesEqual(PtrS.IgnoreParens(), PtrD.IgnoreParens());
const DeducedType *DT = S->getContainedDeducedType();
if (DT && DT->isDeduced())
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp
index b3b84e2..132b7dd 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp
@@ -50,7 +50,7 @@ void RedundantControlFlowCheck::check(const MatchFinder::MatchResult &Result) {
void RedundantControlFlowCheck::checkRedundantReturn(
const MatchFinder::MatchResult &Result, const CompoundStmt *Block) {
- CompoundStmt::const_reverse_body_iterator Last = Block->body_rbegin();
+ const CompoundStmt::const_reverse_body_iterator Last = Block->body_rbegin();
if (const auto *Return = dyn_cast<ReturnStmt>(*Last))
issueDiagnostic(Result, Block, Return->getSourceRange(),
RedundantReturnDiag);
@@ -58,7 +58,7 @@ void RedundantControlFlowCheck::checkRedundantReturn(
void RedundantControlFlowCheck::checkRedundantContinue(
const MatchFinder::MatchResult &Result, const CompoundStmt *Block) {
- CompoundStmt::const_reverse_body_iterator Last = Block->body_rbegin();
+ const CompoundStmt::const_reverse_body_iterator Last = Block->body_rbegin();
if (const auto *Continue = dyn_cast<ContinueStmt>(*Last))
issueDiagnostic(Result, Block, Continue->getSourceRange(),
RedundantContinueDiag);
@@ -67,11 +67,12 @@ void RedundantControlFlowCheck::checkRedundantContinue(
void RedundantControlFlowCheck::issueDiagnostic(
const MatchFinder::MatchResult &Result, const CompoundStmt *const Block,
const SourceRange &StmtRange, const char *const Diag) {
- SourceManager &SM = *Result.SourceManager;
+ const SourceManager &SM = *Result.SourceManager;
if (isLocationInMacroExpansion(SM, StmtRange.getBegin()))
return;
- CompoundStmt::const_reverse_body_iterator Previous = ++Block->body_rbegin();
+ const CompoundStmt::const_reverse_body_iterator Previous =
+ ++Block->body_rbegin();
SourceLocation Start;
if (Previous != Block->body_rend())
Start = Lexer::findLocationAfterToken(
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.h b/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.h
index 3018b1f..fde3050 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_CONTROL_FLOW_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_CONTROL_FLOW_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTCONTROLFLOWCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTCONTROLFLOWCHECK_H
#include "../ClangTidyCheck.h"
@@ -47,4 +47,4 @@ private:
} // namespace clang::tidy::readability
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_CONTROL_FLOW_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTCONTROLFLOWCHECK_H
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp
index cf6e92d..0f12b8b 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp
@@ -79,7 +79,7 @@ void RedundantDeclarationCheck::check(const MatchFinder::MatchResult &Result) {
}
}
- SourceLocation EndLoc = Lexer::getLocForEndOfToken(
+ const SourceLocation EndLoc = Lexer::getLocForEndOfToken(
D->getSourceRange().getEnd(), 0, SM, Result.Context->getLangOpts());
{
auto Diag = diag(D->getLocation(), "redundant %0 declaration") << D;
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.h b/clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.h
index b22cef9..9b1b09f 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_DECLARATION_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_DECLARATION_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTDECLARATIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTDECLARATIONCHECK_H
#include "../ClangTidyCheck.h"
@@ -30,4 +30,4 @@ private:
} // namespace clang::tidy::readability
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_DECLARATION_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTDECLARATIONCHECK_H
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantFunctionPtrDereferenceCheck.h b/clang-tools-extra/clang-tidy/readability/RedundantFunctionPtrDereferenceCheck.h
index 5c82a5e..49cbf69 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantFunctionPtrDereferenceCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/RedundantFunctionPtrDereferenceCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_FUNCTION_PTR_DEREFERENCE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_FUNCTION_PTR_DEREFERENCE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTFUNCTIONPTRDEREFERENCECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTFUNCTIONPTRDEREFERENCECHECK_H
#include "../ClangTidyCheck.h"
@@ -28,4 +28,4 @@ public:
} // namespace clang::tidy::readability
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_FUNCTION_PTR_DEREFERENCE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTFUNCTIONPTRDEREFERENCECHECK_H
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
index 2053b89..7b6eb34 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
@@ -16,10 +16,9 @@
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Lexer.h"
#include "clang/Lex/Token.h"
-#include "../utils/LexerUtils.h"
-
using namespace clang::ast_matchers;
namespace clang::tidy::readability {
@@ -52,7 +51,7 @@ AST_POLYMORPHIC_MATCHER_P(isInternalLinkage,
static SourceLocation getInlineTokenLocation(SourceRange RangeLocation,
const SourceManager &Sources,
const LangOptions &LangOpts) {
- SourceLocation Loc = RangeLocation.getBegin();
+ const SourceLocation Loc = RangeLocation.getBegin();
if (Loc.isMacroID())
return {};
@@ -106,7 +105,7 @@ template <typename T>
void RedundantInlineSpecifierCheck::handleMatchedDecl(
const T *MatchedDecl, const SourceManager &Sources,
const MatchFinder::MatchResult &Result, StringRef Message) {
- SourceLocation Loc = getInlineTokenLocation(
+ const SourceLocation Loc = getInlineTokenLocation(
MatchedDecl->getSourceRange(), Sources, Result.Context->getLangOpts());
if (Loc.isValid())
diag(Loc, Message) << MatchedDecl << FixItHint::CreateRemoval(Loc);
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.h b/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.h
index 64d365d..ff8b02d 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_MEMBER_INIT_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_MEMBER_INIT_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTMEMBERINITCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTMEMBERINITCHECK_H
#include "../ClangTidyCheck.h"
@@ -40,4 +40,4 @@ private:
} // namespace clang::tidy::readability
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_MEMBER_INIT_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTMEMBERINITCHECK_H
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantPreprocessorCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantPreprocessorCheck.cpp
index 931126a154..4c50371 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantPreprocessorCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantPreprocessorCheck.cpp
@@ -36,7 +36,7 @@ public:
void If(SourceLocation Loc, SourceRange ConditionRange,
ConditionValueKind ConditionValue) override {
- StringRef Condition =
+ const StringRef Condition =
Lexer::getSourceText(CharSourceRange::getTokenRange(ConditionRange),
PP.getSourceManager(), PP.getLangOpts());
checkMacroRedundancy(Loc, Condition, IfStack, DK_If, DK_If, true);
@@ -44,7 +44,7 @@ public:
void Ifdef(SourceLocation Loc, const Token &MacroNameTok,
const MacroDefinition &MacroDefinition) override {
- std::string MacroName = PP.getSpelling(MacroNameTok);
+ const std::string MacroName = PP.getSpelling(MacroNameTok);
checkMacroRedundancy(Loc, MacroName, IfdefStack, DK_Ifdef, DK_Ifdef, true);
checkMacroRedundancy(Loc, MacroName, IfndefStack, DK_Ifdef, DK_Ifndef,
false);
@@ -52,7 +52,7 @@ public:
void Ifndef(SourceLocation Loc, const Token &MacroNameTok,
const MacroDefinition &MacroDefinition) override {
- std::string MacroName = PP.getSpelling(MacroNameTok);
+ const std::string MacroName = PP.getSpelling(MacroNameTok);
checkMacroRedundancy(Loc, MacroName, IfndefStack, DK_Ifndef, DK_Ifndef,
true);
checkMacroRedundancy(Loc, MacroName, IfdefStack, DK_Ifndef, DK_Ifdef,
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
index 1106523..a458ae3 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
@@ -149,8 +149,9 @@ void RedundantSmartptrGetCheck::check(const MatchFinder::MatchResult &Result) {
if (!allReturnTypesMatch(Result))
return;
- bool IsPtrToPtr = Result.Nodes.getNodeAs<Decl>("ptr_to_ptr") != nullptr;
- bool IsMemberExpr = Result.Nodes.getNodeAs<Expr>("memberExpr") != nullptr;
+ const bool IsPtrToPtr = Result.Nodes.getNodeAs<Decl>("ptr_to_ptr") != nullptr;
+ const bool IsMemberExpr =
+ Result.Nodes.getNodeAs<Expr>("memberExpr") != nullptr;
const auto *GetCall = Result.Nodes.getNodeAs<Expr>("redundant_get");
if (GetCall->getBeginLoc().isMacroID() && IgnoreMacros)
return;
@@ -178,7 +179,8 @@ void RedundantSmartptrGetCheck::check(const MatchFinder::MatchResult &Result) {
SmartptrText = SmartptrText.drop_back(2);
}
// Replace foo->get() with *foo, and foo.get() with foo.
- std::string Replacement = Twine(IsPtrToPtr ? "*" : "", SmartptrText).str();
+ const std::string Replacement =
+ Twine(IsPtrToPtr ? "*" : "", SmartptrText).str();
diag(GetCall->getBeginLoc(), "redundant get() call on smart pointer")
<< FixItHint::CreateReplacement(SR, Replacement);
}
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
index c90d152..e4d08cb 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
@@ -171,10 +171,10 @@ void RedundantStringCStrCheck::check(const MatchFinder::MatchResult &Result) {
const auto *Call = Result.Nodes.getNodeAs<CallExpr>("call");
const auto *Arg = Result.Nodes.getNodeAs<Expr>("arg");
const auto *Member = Result.Nodes.getNodeAs<MemberExpr>("member");
- bool Arrow = Member->isArrow();
+ const bool Arrow = Member->isArrow();
// Replace the "call" node with the "arg" node, prefixed with '*'
// if the call was using '->' rather than '.'.
- std::string ArgText =
+ const std::string ArgText =
Arrow ? utils::fixit::formatDereference(*Arg, *Result.Context)
: tooling::fixit::getText(*Arg, *Result.Context).str();
if (ArgText.empty())
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp
index b579aaf..5cbbbca 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp
@@ -7,13 +7,11 @@
//===----------------------------------------------------------------------===//
#include "RedundantStringInitCheck.h"
-#include "../utils/Matchers.h"
#include "../utils/OptionsUtils.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include <optional>
using namespace clang::ast_matchers;
-using namespace clang::tidy::matchers;
namespace clang::tidy::readability {
@@ -23,8 +21,8 @@ const char DefaultStringNames[] =
static std::vector<StringRef> removeNamespaces(ArrayRef<StringRef> Names) {
std::vector<StringRef> Result;
Result.reserve(Names.size());
- for (StringRef Name : Names) {
- StringRef::size_type ColonPos = Name.rfind(':');
+ for (const StringRef Name : Names) {
+ const StringRef::size_type ColonPos = Name.rfind(':');
Result.push_back(
Name.drop_front(ColonPos == StringRef::npos ? 0 : ColonPos + 1));
}
@@ -125,14 +123,14 @@ void RedundantStringInitCheck::check(const MatchFinder::MatchResult &Result) {
if (const auto *VDecl = Result.Nodes.getNodeAs<VarDecl>("vardecl")) {
// VarDecl's getSourceRange() spans 'string foo = ""' or 'string bar("")'.
// So start at getLocation() to span just 'foo = ""' or 'bar("")'.
- SourceRange ReplaceRange(VDecl->getLocation(), VDecl->getEndLoc());
+ const SourceRange ReplaceRange(VDecl->getLocation(), VDecl->getEndLoc());
diag(VDecl->getLocation(), "redundant string initialization")
<< FixItHint::CreateReplacement(ReplaceRange, VDecl->getName());
}
if (const auto *FDecl = Result.Nodes.getNodeAs<FieldDecl>("fieldDecl")) {
// FieldDecl's getSourceRange() spans 'string foo = ""'.
// So start at getLocation() to span just 'foo = ""'.
- SourceRange ReplaceRange(FDecl->getLocation(), FDecl->getEndLoc());
+ const SourceRange ReplaceRange(FDecl->getLocation(), FDecl->getEndLoc());
diag(FDecl->getLocation(), "redundant string initialization")
<< FixItHint::CreateReplacement(ReplaceRange, FDecl->getName());
}
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.h b/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.h
index 853ea2f..5c4b744 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_STRING_INIT_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_STRING_INIT_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTSTRINGINITCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTSTRINGINITCHECK_H
#include "../ClangTidyCheck.h"
#include <string>
@@ -32,4 +32,4 @@ private:
} // namespace clang::tidy::readability
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_STRING_INIT_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTSTRINGINITCHECK_H
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp
index a4edd2b..5f2519c 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp
@@ -47,6 +47,9 @@ void RedundantTypenameCheck::check(const MatchFinder::MatchResult &Result) {
const SourceLocation ElaboratedKeywordLoc = [&] {
if (const auto *NonDependentTypeLoc =
Result.Nodes.getNodeAs<TypeLoc>("nonDependentTypeLoc")) {
+ if (NonDependentTypeLoc->getType()->isDependentType())
+ return SourceLocation();
+
if (const auto TL = NonDependentTypeLoc->getAs<TypedefTypeLoc>())
return TL.getElaboratedKeywordLoc();
@@ -59,8 +62,7 @@ void RedundantTypenameCheck::check(const MatchFinder::MatchResult &Result) {
if (const auto TL =
NonDependentTypeLoc->getAs<TemplateSpecializationTypeLoc>())
- if (!TL.getType()->isDependentType())
- return TL.getElaboratedKeywordLoc();
+ return TL.getElaboratedKeywordLoc();
} else {
TypeLoc InnermostTypeLoc =
*Result.Nodes.getNodeAs<TypeLoc>("dependentTypeLoc");
diff --git a/clang-tools-extra/clang-tidy/readability/ReferenceToConstructedTemporaryCheck.cpp b/clang-tools-extra/clang-tidy/readability/ReferenceToConstructedTemporaryCheck.cpp
index 5d3fd14..398bee1 100644
--- a/clang-tools-extra/clang-tidy/readability/ReferenceToConstructedTemporaryCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReferenceToConstructedTemporaryCheck.cpp
@@ -37,7 +37,7 @@ struct NotExtendedByDeclBoundToPredicate {
AST_MATCHER_P(MaterializeTemporaryExpr, isExtendedByDeclBoundTo, StringRef,
ID) {
- NotExtendedByDeclBoundToPredicate Predicate{
+ const NotExtendedByDeclBoundToPredicate Predicate{
ID, ::clang::DynTypedNode::create(Node)};
return Builder->removeBindings(Predicate);
}
diff --git a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
index 9f3f26b..1a9c161 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -203,7 +203,7 @@ static std::string replacementExpression(const ASTContext &Context,
.str(),
NeedsStaticCast));
- StringRef Text = getText(Context, *E);
+ const StringRef Text = getText(Context, *E);
if (!NeedsStaticCast && needsParensAfterUnaryNegation(E))
return ("!(" + Text + ")").str();
@@ -366,7 +366,7 @@ public:
* if (false) ThenStmt(); -> <Empty>;
* if (false) ThenStmt(); else ElseStmt() -> ElseStmt();
*/
- Expr *Cond = If->getCond()->IgnoreImplicit();
+ const Expr *Cond = If->getCond()->IgnoreImplicit();
if (std::optional<bool> Bool = getAsBoolLiteral(Cond, true)) {
if (*Bool)
Check->replaceWithThenStatement(Context, If, Cond);
@@ -379,9 +379,9 @@ public:
* if (Cond) return true; else return false; -> return Cond;
* if (Cond) return false; else return true; -> return !Cond;
*/
- if (ExprAndBool ThenReturnBool =
+ if (const ExprAndBool ThenReturnBool =
checkSingleStatement(If->getThen(), parseReturnLiteralBool)) {
- ExprAndBool ElseReturnBool =
+ const ExprAndBool ElseReturnBool =
checkSingleStatement(If->getElse(), parseReturnLiteralBool);
if (ElseReturnBool && ThenReturnBool.Bool != ElseReturnBool.Bool) {
if (Check->ChainedConditionalReturn ||
@@ -418,9 +418,9 @@ public:
return {ME->getMemberDecl(), *RightasBool};
return {};
};
- if (DeclAndBool ThenAssignment =
+ if (const DeclAndBool ThenAssignment =
checkSingleStatement(If->getThen(), VarBoolAssignmentMatcher)) {
- DeclAndBool ElseAssignment =
+ const DeclAndBool ElseAssignment =
checkSingleStatement(If->getElse(), VarBoolAssignmentMatcher);
if (ElseAssignment.Item == ThenAssignment.Item &&
ElseAssignment.Bool != ThenAssignment.Bool) {
@@ -461,7 +461,7 @@ public:
Second != End; ++Second, ++First) {
PrevIf = CurIf;
CurIf = isa<IfStmt>(*First);
- ExprAndBool TrailingReturnBool = parseReturnLiteralBool(*Second);
+ const ExprAndBool TrailingReturnBool = parseReturnLiteralBool(*Second);
if (!TrailingReturnBool)
continue;
@@ -473,7 +473,7 @@ public:
auto *If = cast<IfStmt>(*First);
if (!If->hasInitStorage() && !If->hasVarStorage() &&
!If->isConsteval()) {
- ExprAndBool ThenReturnBool =
+ const ExprAndBool ThenReturnBool =
checkSingleStatement(If->getThen(), parseReturnLiteralBool);
if (ThenReturnBool &&
ThenReturnBool.Bool != TrailingReturnBool.Bool) {
@@ -497,7 +497,7 @@ public:
auto *SubIf = dyn_cast<IfStmt>(SubStmt);
if (SubIf && !SubIf->getElse() && !SubIf->hasInitStorage() &&
!SubIf->hasVarStorage() && !SubIf->isConsteval()) {
- ExprAndBool ThenReturnBool =
+ const ExprAndBool ThenReturnBool =
checkSingleStatement(SubIf->getThen(), parseReturnLiteralBool);
if (ThenReturnBool &&
ThenReturnBool.Bool != TrailingReturnBool.Bool) {
@@ -574,7 +574,7 @@ public:
if (Check->reportDeMorgan(Context, Op, BinaryOp, !IsProcessing, parent(),
Parens) &&
!Check->areDiagsSelfContained()) {
- llvm::SaveAndRestore RAII(IsProcessing, true);
+ const llvm::SaveAndRestore RAII(IsProcessing, true);
return Base::TraverseUnaryOperator(Op);
}
}
@@ -638,13 +638,13 @@ void SimplifyBooleanExprCheck::reportBinOp(const ASTContext &Context,
if (!isa<CXXBoolLiteralExpr>(Other) && containsBoolLiteral(Other))
return;
- bool BoolValue = Bool->getValue();
+ const bool BoolValue = Bool->getValue();
auto ReplaceWithExpression = [this, &Context, LHS, RHS,
Bool](const Expr *ReplaceWith, bool Negated) {
- std::string Replacement =
+ const std::string Replacement =
replacementExpression(Context, Negated, ReplaceWith);
- SourceRange Range(LHS->getBeginLoc(), RHS->getEndLoc());
+ const SourceRange Range(LHS->getBeginLoc(), RHS->getEndLoc());
issueDiag(Context, Bool->getBeginLoc(), SimplifyOperatorDiagnostic, Range,
Replacement);
};
@@ -706,11 +706,11 @@ bool SimplifyBooleanExprCheck::issueDiag(const ASTContext &Context,
StringRef Description,
SourceRange ReplacementRange,
StringRef Replacement) {
- CharSourceRange CharRange =
+ const CharSourceRange CharRange =
Lexer::makeFileCharRange(CharSourceRange::getTokenRange(ReplacementRange),
Context.getSourceManager(), getLangOpts());
- DiagnosticBuilder Diag = diag(Loc, Description);
+ const DiagnosticBuilder Diag = diag(Loc, Description);
const bool HasReplacement = !containsDiscardedTokens(Context, CharRange);
if (HasReplacement)
Diag << FixItHint::CreateReplacement(CharRange, Replacement);
@@ -737,7 +737,7 @@ void SimplifyBooleanExprCheck::replaceWithElseStatement(
void SimplifyBooleanExprCheck::replaceWithCondition(
const ASTContext &Context, const ConditionalOperator *Ternary,
bool Negated) {
- std::string Replacement =
+ const std::string Replacement =
replacementExpression(Context, Negated, Ternary->getCond());
issueDiag(Context, Ternary->getTrueExpr()->getBeginLoc(),
"redundant boolean literal in ternary expression result",
@@ -747,11 +747,11 @@ void SimplifyBooleanExprCheck::replaceWithCondition(
void SimplifyBooleanExprCheck::replaceWithReturnCondition(
const ASTContext &Context, const IfStmt *If, const Expr *BoolLiteral,
bool Negated) {
- StringRef Terminator = isa<CompoundStmt>(If->getElse()) ? ";" : "";
- std::string Condition =
+ const StringRef Terminator = isa<CompoundStmt>(If->getElse()) ? ";" : "";
+ const std::string Condition =
replacementExpression(Context, Negated, If->getCond());
- std::string Replacement = ("return " + Condition + Terminator).str();
- SourceLocation Start = BoolLiteral->getBeginLoc();
+ const std::string Replacement = ("return " + Condition + Terminator).str();
+ const SourceLocation Start = BoolLiteral->getBeginLoc();
const bool HasReplacement =
issueDiag(Context, Start, SimplifyConditionalReturnDiagnostic,
@@ -795,12 +795,13 @@ void SimplifyBooleanExprCheck::replaceWithAssignment(const ASTContext &Context,
const Expr *Var,
SourceLocation Loc,
bool Negated) {
- SourceRange Range = IfAssign->getSourceRange();
- StringRef VariableName = getText(Context, *Var);
- StringRef Terminator = isa<CompoundStmt>(IfAssign->getElse()) ? ";" : "";
- std::string Condition =
+ const SourceRange Range = IfAssign->getSourceRange();
+ const StringRef VariableName = getText(Context, *Var);
+ const StringRef Terminator =
+ isa<CompoundStmt>(IfAssign->getElse()) ? ";" : "";
+ const std::string Condition =
replacementExpression(Context, Negated, IfAssign->getCond());
- std::string Replacement =
+ const std::string Replacement =
(VariableName + " = " + Condition + Terminator).str();
issueDiag(Context, Loc, "redundant boolean literal in conditional assignment",
Range, Replacement);
diff --git a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
index 466bc41..99520d7 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_SIMPLIFY_BOOLEAN_EXPR_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_SIMPLIFY_BOOLEAN_EXPR_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_SIMPLIFYBOOLEANEXPRCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_SIMPLIFYBOOLEANEXPRCHECK_H
#include "../ClangTidyCheck.h"
@@ -75,4 +75,4 @@ private:
} // namespace clang::tidy::readability
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_SIMPLIFY_BOOLEAN_EXPR_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_SIMPLIFYBOOLEANEXPRCHECK_H
diff --git a/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.h b/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.h
index c376806..38a2ea6 100644
--- a/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_STATIC_ACCESSED_THROUGH_INSTANCE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_STATIC_ACCESSED_THROUGH_INSTANCE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_STATICACCESSEDTHROUGHINSTANCECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_STATICACCESSEDTHROUGHINSTANCECHECK_H
#include "../ClangTidyCheck.h"
@@ -41,4 +41,4 @@ private:
} // namespace clang::tidy::readability
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_STATIC_ACCESSED_THROUGH_INSTANCE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_STATICACCESSEDTHROUGHINSTANCECHECK_H
diff --git a/clang-tools-extra/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp b/clang-tools-extra/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp
index e9a2eae..abc9f67 100644
--- a/clang-tools-extra/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp
@@ -45,8 +45,8 @@ void StaticDefinitionInAnonymousNamespaceCheck::check(
while (Loc < Def->getSourceRange().getEnd() &&
!Lexer::getRawToken(Loc, Tok, *Result.SourceManager, getLangOpts(),
true)) {
- SourceRange TokenRange(Tok.getLocation(), Tok.getEndLoc());
- StringRef SourceText =
+ const SourceRange TokenRange(Tok.getLocation(), Tok.getEndLoc());
+ const StringRef SourceText =
Lexer::getSourceText(CharSourceRange::getTokenRange(TokenRange),
*Result.SourceManager, getLangOpts());
if (SourceText == "static") {
diff --git a/clang-tools-extra/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.h b/clang-tools-extra/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.h
index 5530655..e096682 100644
--- a/clang-tools-extra/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_STATIC_DEFINITION_IN_ANONYMOUS_NAMESPACE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_STATIC_DEFINITION_IN_ANONYMOUS_NAMESPACE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_STATICDEFINITIONINANONYMOUSNAMESPACECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_STATICDEFINITIONINANONYMOUSNAMESPACECHECK_H
#include "../ClangTidyCheck.h"
@@ -34,4 +34,4 @@ public:
} // namespace clang::tidy::readability
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_STATIC_DEFINITION_IN_ANONYMOUS_NAMESPACE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_STATICDEFINITIONINANONYMOUSNAMESPACECHECK_H
diff --git a/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp b/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
index feb248d..0b52a96 100644
--- a/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
@@ -150,8 +150,8 @@ static bool applyAbbreviationHeuristic(
/// Check whether the shorter String is a prefix of the longer String.
static bool applyPrefixHeuristic(StringRef Arg, StringRef Param,
int8_t Threshold) {
- StringRef Shorter = Arg.size() < Param.size() ? Arg : Param;
- StringRef Longer = Arg.size() >= Param.size() ? Arg : Param;
+ const StringRef Shorter = Arg.size() < Param.size() ? Arg : Param;
+ const StringRef Longer = Arg.size() >= Param.size() ? Arg : Param;
if (Longer.starts_with_insensitive(Shorter))
return percentage(Shorter.size(), Longer.size()) > Threshold;
@@ -162,8 +162,8 @@ static bool applyPrefixHeuristic(StringRef Arg, StringRef Param,
/// Check whether the shorter String is a suffix of the longer String.
static bool applySuffixHeuristic(StringRef Arg, StringRef Param,
int8_t Threshold) {
- StringRef Shorter = Arg.size() < Param.size() ? Arg : Param;
- StringRef Longer = Arg.size() >= Param.size() ? Arg : Param;
+ const StringRef Shorter = Arg.size() < Param.size() ? Arg : Param;
+ const StringRef Longer = Arg.size() >= Param.size() ? Arg : Param;
if (Longer.ends_with_insensitive(Shorter))
return percentage(Shorter.size(), Longer.size()) > Threshold;
@@ -173,7 +173,6 @@ static bool applySuffixHeuristic(StringRef Arg, StringRef Param,
static bool applySubstringHeuristic(StringRef Arg, StringRef Param,
int8_t Threshold) {
-
std::size_t MaxLength = 0;
SmallVector<std::size_t, SmallVectorSize> Current(Param.size());
SmallVector<std::size_t, SmallVectorSize> Previous(Param.size());
@@ -196,13 +195,13 @@ static bool applySubstringHeuristic(StringRef Arg, StringRef Param,
Current.swap(Previous);
}
- size_t LongerLength = std::max(Arg.size(), Param.size());
+ const size_t LongerLength = std::max(Arg.size(), Param.size());
return percentage(MaxLength, LongerLength) > Threshold;
}
static bool applyLevenshteinHeuristic(StringRef Arg, StringRef Param,
int8_t Threshold) {
- std::size_t LongerLength = std::max(Arg.size(), Param.size());
+ const std::size_t LongerLength = std::max(Arg.size(), Param.size());
double Dist = Arg.edit_distance(Param);
Dist = (1.0 - Dist / LongerLength) * 100.0;
return Dist > Threshold;
@@ -212,11 +211,11 @@ static bool applyLevenshteinHeuristic(StringRef Arg, StringRef Param,
static bool applyJaroWinklerHeuristic(StringRef Arg, StringRef Param,
int8_t Threshold) {
std::size_t Match = 0, Transpos = 0;
- std::ptrdiff_t ArgLen = Arg.size();
- std::ptrdiff_t ParamLen = Param.size();
+ const std::ptrdiff_t ArgLen = Arg.size();
+ const std::ptrdiff_t ParamLen = Param.size();
SmallVector<int, SmallVectorSize> ArgFlags(ArgLen);
SmallVector<int, SmallVectorSize> ParamFlags(ParamLen);
- std::ptrdiff_t Range =
+ const std::ptrdiff_t Range =
std::max(std::ptrdiff_t{0}, (std::max(ArgLen, ParamLen) / 2) - 1);
// Calculate matching characters.
@@ -252,7 +251,7 @@ static bool applyJaroWinklerHeuristic(StringRef Arg, StringRef Param,
Transpos /= 2;
// Jaro distance.
- double MatchD = Match;
+ const double MatchD = Match;
double Dist = ((MatchD / ArgLen) + (MatchD / ParamLen) +
((MatchD - Transpos) / Match)) /
3.0;
@@ -347,7 +346,7 @@ static bool arePointersStillQualCompatible(QualType ArgType, QualType ParamType,
// The types are compatible, if the parameter is at least as qualified as the
// argument, and if it is more qualified, it has to be const on upper pointer
// levels.
- bool AreTypesQualCompatible =
+ const bool AreTypesQualCompatible =
ParamType.isAtLeastAsQualifiedAs(ArgType, Ctx) &&
(!ParamType.hasQualifiers() || IsParamContinuouslyConst);
// Check whether the parameter's constness continues at the current pointer
@@ -401,7 +400,7 @@ static bool areTypesCompatible(QualType ArgType, QualType ParamType,
if (!areRefAndQualCompatible(ArgType, ParamType, Ctx))
return false;
- bool IsParamReference = ParamType->isReferenceType();
+ const bool IsParamReference = ParamType->isReferenceType();
// Reference-ness has already been checked and should be removed
// before further checking.
@@ -438,7 +437,7 @@ static bool areTypesCompatible(QualType ArgType, QualType ParamType,
if (IsParamReference && ParamType->isArrayType())
return isCompatibleWithArrayReference(ArgType, ParamType, Ctx);
- bool IsParamContinuouslyConst =
+ const bool IsParamContinuouslyConst =
!IsParamReference || ParamType.getNonReferenceType().isConstQualified();
// Remove the first level of indirection.
@@ -513,9 +512,9 @@ SuspiciousCallArgumentCheck::SuspiciousCallArgumentCheck(
SmallString<32> Key = HeuristicToString[Idx];
Key.append(BK == BoundKind::DissimilarBelow ? "DissimilarBelow"
: "SimilarAbove");
- int8_t Default = BK == BoundKind::DissimilarBelow
- ? Defaults[Idx].DissimilarBelow
- : Defaults[Idx].SimilarAbove;
+ const int8_t Default = BK == BoundKind::DissimilarBelow
+ ? Defaults[Idx].DissimilarBelow
+ : Defaults[Idx].SimilarAbove;
return Options.get(Key, Default);
};
for (std::size_t Idx = 0; Idx < HeuristicCount; ++Idx) {
@@ -527,7 +526,7 @@ SuspiciousCallArgumentCheck::SuspiciousCallArgumentCheck(
GetBoundOpt(H, BoundKind::SimilarAbove)));
}
- for (StringRef Abbreviation : optutils::parseStringList(
+ for (const StringRef Abbreviation : optutils::parseStringList(
Options.get("Abbreviations", DefaultAbbreviations))) {
auto KeyAndValue = Abbreviation.split("=");
assert(!KeyAndValue.first.empty() && !KeyAndValue.second.empty());
@@ -652,7 +651,7 @@ void SuspiciousCallArgumentCheck::check(
if (ArgNames.empty())
return;
- std::size_t ParamCount = ParamNames.size();
+ const std::size_t ParamCount = ParamNames.size();
// Check similarity.
for (std::size_t I = 0; I < ParamCount; ++I) {
@@ -673,9 +672,9 @@ void SuspiciousCallArgumentCheck::check(
<< MatchedCallExpr->getArg(J)->getSourceRange();
// Note at the functions declaration.
- SourceLocation IParNameLoc =
+ const SourceLocation IParNameLoc =
CalleeFuncDecl->getParamDecl(I)->getLocation();
- SourceLocation JParNameLoc =
+ const SourceLocation JParNameLoc =
CalleeFuncDecl->getParamDecl(J)->getLocation();
diag(CalleeFuncDecl->getLocation(), "in the call to %0, declared here",
@@ -697,7 +696,7 @@ void SuspiciousCallArgumentCheck::setParamNamesAndTypes(
for (const ParmVarDecl *Param : CalleeFuncDecl->parameters()) {
ParamTypes.push_back(Param->getType());
- if (IdentifierInfo *II = Param->getIdentifier())
+ if (const IdentifierInfo *II = Param->getIdentifier())
ParamNames.push_back(II->getName());
else
ParamNames.push_back(StringRef());
@@ -759,24 +758,22 @@ bool SuspiciousCallArgumentCheck::areParamAndArgComparable(
bool SuspiciousCallArgumentCheck::areArgsSwapped(std::size_t Position1,
std::size_t Position2) const {
- for (Heuristic H : AppliedHeuristics) {
- bool A1ToP2Similar = areNamesSimilar(
+ return llvm::any_of(AppliedHeuristics, [&](Heuristic H) {
+ const bool A1ToP2Similar = areNamesSimilar(
ArgNames[Position2], ParamNames[Position1], H, BoundKind::SimilarAbove);
- bool A2ToP1Similar = areNamesSimilar(
+ const bool A2ToP1Similar = areNamesSimilar(
ArgNames[Position1], ParamNames[Position2], H, BoundKind::SimilarAbove);
- bool A1ToP1Dissimilar =
+ const bool A1ToP1Dissimilar =
!areNamesSimilar(ArgNames[Position1], ParamNames[Position1], H,
BoundKind::DissimilarBelow);
- bool A2ToP2Dissimilar =
+ const bool A2ToP2Dissimilar =
!areNamesSimilar(ArgNames[Position2], ParamNames[Position2], H,
BoundKind::DissimilarBelow);
- if ((A1ToP2Similar || A2ToP1Similar) && A1ToP1Dissimilar &&
- A2ToP2Dissimilar)
- return true;
- }
- return false;
+ return (A1ToP2Similar || A2ToP1Similar) && A1ToP1Dissimilar &&
+ A2ToP2Dissimilar;
+ });
}
bool SuspiciousCallArgumentCheck::areNamesSimilar(StringRef Arg,
diff --git a/clang-tools-extra/clang-tidy/readability/UniqueptrDeleteReleaseCheck.cpp b/clang-tools-extra/clang-tidy/readability/UniqueptrDeleteReleaseCheck.cpp
index c9d7041..1dff8089 100644
--- a/clang-tools-extra/clang-tidy/readability/UniqueptrDeleteReleaseCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/UniqueptrDeleteReleaseCheck.cpp
@@ -28,7 +28,6 @@ UniqueptrDeleteReleaseCheck::UniqueptrDeleteReleaseCheck(
PreferResetCall(Options.get("PreferResetCall", false)) {}
void UniqueptrDeleteReleaseCheck::registerMatchers(MatchFinder *Finder) {
-
auto UniquePtrWithDefaultDelete = classTemplateSpecializationDecl(
hasName("::std::unique_ptr"),
hasTemplateArgument(1, refersToType(hasDeclaration(cxxRecordDecl(
diff --git a/clang-tools-extra/clang-tidy/readability/UniqueptrDeleteReleaseCheck.h b/clang-tools-extra/clang-tidy/readability/UniqueptrDeleteReleaseCheck.h
index ab6449e..2874208 100644
--- a/clang-tools-extra/clang-tidy/readability/UniqueptrDeleteReleaseCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/UniqueptrDeleteReleaseCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_UNIQUEPTR_DELETE_RELEASE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_UNIQUEPTR_DELETE_RELEASE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_UNIQUEPTRDELETERELEASECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_UNIQUEPTRDELETERELEASECHECK_H
#include "../ClangTidyCheck.h"
@@ -37,4 +37,4 @@ private:
} // namespace clang::tidy::readability
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_UNIQUEPTR_DELETE_RELEASE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_UNIQUEPTRDELETERELEASECHECK_H
diff --git a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
index 740a68d..db226f9 100644
--- a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
@@ -110,7 +110,7 @@ shouldReplaceLiteralSuffix(const Expr &Literal,
ReplacementDsc.LiteralLocation = L.getSourceRange();
// Was this literal fully spelled or is it a product of macro expansion?
- bool RangeCanBeFixed =
+ const bool RangeCanBeFixed =
utils::rangeCanBeFixed(ReplacementDsc.LiteralLocation, &SM);
// The literal may have macro expansion, we need the final expanded src range.
diff --git a/clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp b/clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp
index 82eb6de..6364915 100644
--- a/clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp
@@ -20,7 +20,7 @@ namespace {
/// followed by a Stmt matching the inner matcher.
AST_MATCHER_P(Stmt, nextStmt, ast_matchers::internal::Matcher<Stmt>,
InnerMatcher) {
- DynTypedNodeList Parents = Finder->getASTContext().getParents(Node);
+ const DynTypedNodeList Parents = Finder->getASTContext().getParents(Node);
if (Parents.size() != 1)
return false;
@@ -71,7 +71,6 @@ void UseAnyOfAllOfCheck::registerMatchers(MatchFinder *Finder) {
}
static bool isViableLoop(const CXXForRangeStmt &S, ASTContext &Context) {
-
ExprMutationAnalyzer Mutations(*S.getBody(), Context);
if (Mutations.isMutated(S.getLoopVariable()))
return false;
@@ -86,7 +85,6 @@ static bool isViableLoop(const CXXForRangeStmt &S, ASTContext &Context) {
}
void UseAnyOfAllOfCheck::check(const MatchFinder::MatchResult &Result) {
-
if (const auto *S = Result.Nodes.getNodeAs<CXXForRangeStmt>("any_of_loop")) {
if (!isViableLoop(*S, *Result.Context))
return;
diff --git a/clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.h b/clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.h
index f431311b..32983e4 100644
--- a/clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_USEALGORITHMCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_USEALGORITHMCHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_USEANYOFALLOFCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_USEANYOFALLOFCHECK_H
#include "../ClangTidyCheck.h"
#include "../utils/IncludeInserter.h"
@@ -33,4 +33,4 @@ public:
} // namespace clang::tidy::readability
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_USEALGORITHMCHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_USEANYOFALLOFCHECK_H
diff --git a/clang-tools-extra/clang-tidy/readability/UseConcisePreprocessorDirectivesCheck.cpp b/clang-tools-extra/clang-tidy/readability/UseConcisePreprocessorDirectivesCheck.cpp
index 40aaff4..ef495d3 100644
--- a/clang-tools-extra/clang-tidy/readability/UseConcisePreprocessorDirectivesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/UseConcisePreprocessorDirectivesCheck.cpp
@@ -91,7 +91,10 @@ private:
Check.diag(
DirectiveLoc,
"preprocessor condition can be written more concisely using '#%0'")
- << FixItHint::CreateReplacement(DirectiveLoc, Replacements[Inverted])
+ << FixItHint::CreateReplacement(
+ CharSourceRange::getCharRange(DirectiveLoc,
+ ConditionRange.getBegin()),
+ (Replacements[Inverted].str() + " "))
<< FixItHint::CreateReplacement(ConditionRange, Macro)
<< Replacements[Inverted];
}
diff --git a/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp b/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp
index 8052e04..ee0810b 100644
--- a/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp
@@ -77,11 +77,11 @@ static QualType getNonTemplateAlias(QualType QT) {
static QualType getReplacementCastType(const Expr *CondLhs, const Expr *CondRhs,
QualType ComparedType) {
- QualType LhsType = CondLhs->getType();
- QualType RhsType = CondRhs->getType();
- QualType LhsCanonicalType =
+ const QualType LhsType = CondLhs->getType();
+ const QualType RhsType = CondRhs->getType();
+ const QualType LhsCanonicalType =
LhsType.getCanonicalType().getNonReferenceType().getUnqualifiedType();
- QualType RhsCanonicalType =
+ const QualType RhsCanonicalType =
RhsType.getCanonicalType().getNonReferenceType().getUnqualifiedType();
QualType GlobalImplicitCastType;
if (LhsCanonicalType != RhsCanonicalType) {
@@ -96,12 +96,11 @@ static QualType getReplacementCastType(const Expr *CondLhs, const Expr *CondRhs,
return GlobalImplicitCastType;
}
-static std::string createReplacement(const Expr *CondLhs, const Expr *CondRhs,
- const Expr *AssignLhs,
- const SourceManager &Source,
- const LangOptions &LO,
- StringRef FunctionName,
- const BinaryOperator *BO) {
+static std::string
+createReplacement(const Expr *CondLhs, const Expr *CondRhs,
+ const Expr *AssignLhs, const SourceManager &Source,
+ const LangOptions &LO, StringRef FunctionName,
+ const BinaryOperator *BO, StringRef Comment = "") {
const llvm::StringRef CondLhsStr = Lexer::getSourceText(
Source.getExpansionRange(CondLhs->getSourceRange()), Source, LO);
const llvm::StringRef CondRhsStr = Lexer::getSourceText(
@@ -109,14 +108,15 @@ static std::string createReplacement(const Expr *CondLhs, const Expr *CondRhs,
const llvm::StringRef AssignLhsStr = Lexer::getSourceText(
Source.getExpansionRange(AssignLhs->getSourceRange()), Source, LO);
- QualType GlobalImplicitCastType =
+ const QualType GlobalImplicitCastType =
getReplacementCastType(CondLhs, CondRhs, BO->getLHS()->getType());
return (AssignLhsStr + " = " + FunctionName +
(!GlobalImplicitCastType.isNull()
? "<" + GlobalImplicitCastType.getAsString() + ">("
: "(") +
- CondLhsStr + ", " + CondRhsStr + ");")
+ CondLhsStr + ", " + CondRhsStr + ");" + (Comment.empty() ? "" : " ") +
+ Comment)
.str();
}
@@ -172,13 +172,65 @@ void UseStdMinMaxCheck::check(const MatchFinder::MatchResult &Result) {
auto ReplaceAndDiagnose = [&](const llvm::StringRef FunctionName) {
const SourceManager &Source = *Result.SourceManager;
+ llvm::SmallString<64> Comment;
+
+ const auto AppendNormalized = [&](llvm::StringRef Text) {
+ Text = Text.ltrim();
+ if (!Text.empty()) {
+ if (!Comment.empty())
+ Comment += " ";
+ Comment += Text;
+ }
+ };
+
+ const auto GetSourceText = [&](SourceLocation StartLoc,
+ SourceLocation EndLoc) {
+ return Lexer::getSourceText(
+ CharSourceRange::getCharRange(
+ Lexer::getLocForEndOfToken(StartLoc, 0, Source, LO), EndLoc),
+ Source, LO);
+ };
+
+ // Captures:
+ // if (cond) // Comment A
+ // if (cond) /* Comment A */ { ... }
+ // if (cond) /* Comment A */ x = y;
+ AppendNormalized(
+ GetSourceText(If->getRParenLoc(), If->getThen()->getBeginLoc()));
+
+ if (const auto *CS = dyn_cast<CompoundStmt>(If->getThen())) {
+ const Stmt *Inner = CS->body_front();
+
+ // Captures:
+ // if (cond) { // Comment B
+ // ...
+ // }
+ // if (cond) { /* Comment B */ x = y; }
+ AppendNormalized(GetSourceText(CS->getBeginLoc(), Inner->getBeginLoc()));
+
+ // Captures:
+ // if (cond) { x = y; // Comment C }
+ // if (cond) { x = y; /* Comment C */ }
+ llvm::StringRef PostInner =
+ GetSourceText(Inner->getEndLoc(), CS->getEndLoc());
+
+ // Strip the trailing semicolon to avoid fixes like:
+ // x = std::min(x, y);; // comment
+ const size_t Semi = PostInner.find(';');
+ if (Semi != llvm::StringRef::npos &&
+ PostInner.take_front(Semi).trim().empty()) {
+ PostInner = PostInner.drop_front(Semi + 1);
+ }
+ AppendNormalized(PostInner);
+ }
+
diag(IfLocation, "use `%0` instead of `%1`")
<< FunctionName << BinaryOp->getOpcodeStr()
<< FixItHint::CreateReplacement(
SourceRange(IfLocation, Lexer::getLocForEndOfToken(
ThenLocation, 0, Source, LO)),
createReplacement(CondLhs, CondRhs, AssignLhs, Source, LO,
- FunctionName, BinaryOp))
+ FunctionName, BinaryOp, Comment))
<< IncludeInserter.createIncludeInsertion(
Source.getFileID(If->getBeginLoc()), AlgorithmHeader);
};
diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index 1ae8756..6a1f61d 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -104,8 +104,7 @@ Configuration files:
)");
const char DefaultChecks[] = // Enable these checks by default:
- "clang-diagnostic-*," // * compiler diagnostics
- "clang-analyzer-*"; // * Static Analyzer checks
+ "clang-diagnostic-*"; // * compiler diagnostics
static cl::opt<std::string> Checks("checks", desc(R"(
Comma-separated list of globs with optional '-'
@@ -390,7 +389,7 @@ static void printStats(const ClangTidyStats &Stats) {
static std::unique_ptr<ClangTidyOptionsProvider>
createOptionsProvider(llvm::IntrusiveRefCntPtr<vfs::FileSystem> FS) {
ClangTidyGlobalOptions GlobalOptions;
- if (std::error_code Err = parseLineFilter(LineFilter, GlobalOptions)) {
+ if (const std::error_code Err = parseLineFilter(LineFilter, GlobalOptions)) {
llvm::errs() << "Invalid LineFilter: " << Err.message() << "\n\nUsage:\n";
llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
return nullptr;
@@ -448,7 +447,7 @@ createOptionsProvider(llvm::IntrusiveRefCntPtr<vfs::FileSystem> FS) {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text =
llvm::MemoryBuffer::getFile(ConfigFile);
- if (std::error_code EC = Text.getError()) {
+ if (const std::error_code EC = Text.getError()) {
llvm::errs() << "Error: can't read config-file '" << ConfigFile
<< "': " << EC.message() << "\n";
return nullptr;
@@ -466,10 +465,9 @@ createOptionsProvider(llvm::IntrusiveRefCntPtr<vfs::FileSystem> FS) {
}
static llvm::IntrusiveRefCntPtr<vfs::FileSystem>
-getVfsFromFile(const std::string &OverlayFile,
- llvm::IntrusiveRefCntPtr<vfs::FileSystem> BaseFS) {
+getVfsFromFile(const std::string &OverlayFile, vfs::FileSystem &BaseFS) {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buffer =
- BaseFS->getBufferForFile(OverlayFile);
+ BaseFS.getBufferForFile(OverlayFile);
if (!Buffer) {
llvm::errs() << "Can't load virtual filesystem overlay file '"
<< OverlayFile << "': " << Buffer.getError().message()
@@ -491,7 +489,7 @@ static StringRef closest(StringRef Value, const StringSet<> &Allowed) {
unsigned MaxEdit = 5U;
StringRef Closest;
for (auto Item : Allowed.keys()) {
- unsigned Cur = Value.edit_distance_insensitive(Item, true, MaxEdit);
+ const unsigned Cur = Value.edit_distance_insensitive(Item, true, MaxEdit);
if (Cur < MaxEdit) {
Closest = Item;
MaxEdit = Cur;
@@ -504,7 +502,7 @@ static constexpr StringLiteral VerifyConfigWarningEnd = " [-verify-config]\n";
static bool verifyChecks(const StringSet<> &AllChecks, StringRef CheckGlob,
StringRef Source) {
- GlobList Globs(CheckGlob);
+ const GlobList Globs(CheckGlob);
bool AnyInvalid = false;
for (const auto &Item : Globs.getItems()) {
if (Item.Text.starts_with("clang-diagnostic"))
@@ -520,7 +518,7 @@ static bool verifyChecks(const StringSet<> &AllChecks, StringRef CheckGlob,
llvm::raw_ostream &Output =
llvm::WithColor::warning(llvm::errs(), Source)
<< "unknown check '" << Item.Text << '\'';
- llvm::StringRef Closest = closest(Item.Text, AllChecks);
+ const llvm::StringRef Closest = closest(Item.Text, AllChecks);
if (!Closest.empty())
Output << "; did you mean '" << Closest << '\'';
Output << VerifyConfigWarningEnd;
@@ -560,7 +558,7 @@ static bool verifyOptions(const llvm::StringSet<> &ValidOptions,
AnyInvalid = true;
auto &Output = llvm::WithColor::warning(llvm::errs(), Source)
<< "unknown check option '" << Key << '\'';
- llvm::StringRef Closest = closest(Key, ValidOptions);
+ const llvm::StringRef Closest = closest(Key, ValidOptions);
if (!Closest.empty())
Output << "; did you mean '" << Closest << '\'';
Output << VerifyConfigWarningEnd;
@@ -572,7 +570,7 @@ static SmallString<256> makeAbsolute(llvm::StringRef Input) {
if (Input.empty())
return {};
SmallString<256> AbsolutePath(Input);
- if (std::error_code EC = llvm::sys::fs::make_absolute(AbsolutePath)) {
+ if (const std::error_code EC = llvm::sys::fs::make_absolute(AbsolutePath)) {
llvm::errs() << "Can't make absolute path from " << Input << ": "
<< EC.message() << "\n";
}
@@ -585,7 +583,7 @@ static llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> createBaseFS() {
if (!VfsOverlay.empty()) {
IntrusiveRefCntPtr<vfs::FileSystem> VfsFromFile =
- getVfsFromFile(VfsOverlay, BaseFS);
+ getVfsFromFile(VfsOverlay, *BaseFS);
if (!VfsFromFile)
return nullptr;
BaseFS->pushOverlay(std::move(VfsFromFile));
@@ -594,7 +592,7 @@ static llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> createBaseFS() {
}
int clangTidyMain(int argc, const char **argv) {
- llvm::InitLLVM X(argc, argv);
+ const llvm::InitLLVM X(argc, argv);
SmallVector<const char *> Args{argv, argv + argc};
// expand parameters file to argc and argv.
@@ -623,7 +621,8 @@ int clangTidyMain(int argc, const char **argv) {
return 1;
}
- llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> BaseFS = createBaseFS();
+ const llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> BaseFS =
+ createBaseFS();
if (!BaseFS)
return 1;
@@ -632,7 +631,7 @@ int clangTidyMain(int argc, const char **argv) {
if (!OptionsProvider)
return 1;
- SmallString<256> ProfilePrefix = makeAbsolute(StoreCheckProfile);
+ const SmallString<256> ProfilePrefix = makeAbsolute(StoreCheckProfile);
StringRef FileName("dummy");
auto PathList = OptionsParser->getSourcePathList();
@@ -640,10 +639,10 @@ int clangTidyMain(int argc, const char **argv) {
FileName = PathList.front();
}
- SmallString<256> FilePath = makeAbsolute(FileName);
+ const SmallString<256> FilePath = makeAbsolute(FileName);
ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FilePath);
- std::vector<std::string> EnabledChecks =
+ const std::vector<std::string> EnabledChecks =
getCheckNames(EffectiveOptions, AllowEnablingAnalyzerAlphaCheckers,
ExperimentalCustomChecks);
@@ -687,9 +686,9 @@ int clangTidyMain(int argc, const char **argv) {
}
if (VerifyConfig) {
- std::vector<ClangTidyOptionsProvider::OptionsSource> RawOptions =
+ const std::vector<ClangTidyOptionsProvider::OptionsSource> RawOptions =
OptionsProvider->getRawOptions(FileName);
- ChecksAndOptions Valid = getAllChecksAndOptions(
+ const ChecksAndOptions Valid = getAllChecksAndOptions(
AllowEnablingAnalyzerAlphaCheckers, ExperimentalCustomChecks);
bool AnyInvalid = false;
for (const auto &[Opts, Source] : RawOptions) {
@@ -733,14 +732,14 @@ int clangTidyMain(int argc, const char **argv) {
std::vector<ClangTidyError> Errors =
runClangTidy(Context, OptionsParser->getCompilations(), PathList, BaseFS,
FixNotes, EnableCheckProfile, ProfilePrefix, Quiet);
- bool FoundErrors = llvm::any_of(Errors, [](const ClangTidyError &E) {
+ const bool FoundErrors = llvm::any_of(Errors, [](const ClangTidyError &E) {
return E.DiagLevel == ClangTidyError::Error;
});
// --fix-errors and --fix-notes imply --fix.
- FixBehaviour Behaviour = FixNotes ? FB_FixNotes
- : (Fix || FixErrors) ? FB_Fix
- : FB_NoFix;
+ const FixBehaviour Behaviour = FixNotes ? FB_FixNotes
+ : (Fix || FixErrors) ? FB_Fix
+ : FB_NoFix;
const bool DisableFixes = FoundErrors && !FixErrors;
@@ -769,7 +768,7 @@ int clangTidyMain(int argc, const char **argv) {
if (WErrorCount) {
if (!Quiet) {
- StringRef Plural = WErrorCount == 1 ? "" : "s";
+ const StringRef Plural = WErrorCount == 1 ? "" : "s";
llvm::errs() << WErrorCount << " warning" << Plural << " treated as error"
<< Plural << "\n";
}
diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.h b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.h
index f86828e..44b7a37 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.h
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.h
@@ -14,8 +14,13 @@
///
//===----------------------------------------------------------------------===//
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_TOOL_CLANGTIDYMAIN_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_TOOL_CLANGTIDYMAIN_H
+
namespace clang::tidy {
int clangTidyMain(int argc, const char **argv);
} // namespace clang::tidy
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_TOOL_CLANGTIDYMAIN_H
diff --git a/clang-tools-extra/clang-tidy/tool/check_alphabetical_order.py b/clang-tools-extra/clang-tidy/tool/check_alphabetical_order.py
new file mode 100644
index 0000000..66819ab
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/tool/check_alphabetical_order.py
@@ -0,0 +1,421 @@
+#!/usr/bin/env python3
+#
+# ===-----------------------------------------------------------------------===#
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+# ===-----------------------------------------------------------------------===#
+
+"""
+
+Clang-Tidy Alphabetical Order Checker
+=====================================
+
+Normalize Clang-Tidy documentation with deterministic sorting for linting/tests.
+
+Behavior:
+- Sort entries in docs/clang-tidy/checks/list.rst csv-table.
+- Sort key sections in docs/ReleaseNotes.rst.
+- Detect duplicated entries in 'Changes in existing checks'.
+
+Flags:
+ -o/--output Write normalized content to this path instead of updating docs.
+"""
+
+import argparse
+from collections import defaultdict
+import io
+from operator import itemgetter
+import os
+import re
+import sys
+from typing import (
+ DefaultDict,
+ Final,
+ Iterable,
+ List,
+ NamedTuple,
+ Optional,
+ Sequence,
+ Tuple,
+)
+
+# Matches a :doc:`label <path>` or :doc:`label` reference anywhere in text and
+# captures the label. Used to sort bullet items alphabetically in ReleaseNotes
+# items by their label.
+DOC_LABEL_RN_RE: Final = re.compile(r":doc:`(?P<label>[^`<]+)\s*(?:<[^>]+>)?`")
+
+# Matches a single csv-table row line in list.rst that begins with a :doc:
+# reference, capturing the label. Used to extract the sort key per row.
+DOC_LINE_RE: Final = re.compile(r"^\s*:doc:`(?P<label>[^`<]+?)\s*<[^>]+>`.*$")
+
+
+EXTRA_DIR: Final = os.path.join(os.path.dirname(__file__), "../..")
+DOCS_DIR: Final = os.path.join(EXTRA_DIR, "docs")
+CLANG_TIDY_DOCS_DIR: Final = os.path.join(DOCS_DIR, "clang-tidy")
+CHECKS_DOCS_DIR: Final = os.path.join(CLANG_TIDY_DOCS_DIR, "checks")
+LIST_DOC: Final = os.path.join(CHECKS_DOCS_DIR, "list.rst")
+RELEASE_NOTES_DOC: Final = os.path.join(DOCS_DIR, "ReleaseNotes.rst")
+
+
+# Label extracted from :doc:`...`.
+CheckLabel = str
+Lines = List[str]
+BulletBlock = List[str]
+
+# Pair of the extracted label and its block
+BulletItem = Tuple[CheckLabel, BulletBlock]
+
+# Index of the first line of a bullet block within the full lines list.
+BulletStart = int
+
+# All occurrences for a given label.
+DuplicateOccurrences = List[Tuple[BulletStart, BulletBlock]]
+
+
+class BulletBlocks(NamedTuple):
+ """Structured result of parsing a bullet-list section.
+
+ - prefix: lines before the first bullet within the section range.
+ - blocks: list of (label, block-lines) pairs for each bullet block.
+ - suffix: lines after the last bullet within the section range.
+ """
+
+ prefix: Lines
+ blocks: List[BulletItem]
+ suffix: Lines
+
+
+class ScannedBlocks(NamedTuple):
+ """Result of scanning bullet blocks within a section range.
+
+ - blocks_with_pos: list of (start_index, block_lines) for each bullet block.
+ - next_index: index where scanning stopped; start of the suffix region.
+ """
+
+ blocks_with_pos: List[Tuple[BulletStart, BulletBlock]]
+ next_index: int
+
+
+def _scan_bullet_blocks(lines: Sequence[str], start: int, end: int) -> ScannedBlocks:
+ """Scan consecutive bullet blocks and return (blocks_with_pos, next_index).
+
+ Each entry in blocks_with_pos is a tuple of (start_index, block_lines).
+ next_index is the index where scanning stopped (start of suffix).
+ """
+ i = start
+ n = end
+ blocks_with_pos: List[Tuple[BulletStart, BulletBlock]] = []
+ while i < n:
+ if not _is_bullet_start(lines[i]):
+ break
+ bstart = i
+ i += 1
+ while i < n and not _is_bullet_start(lines[i]):
+ if (
+ i + 1 < n
+ and set(lines[i + 1].rstrip("\n")) == {"^"}
+ and lines[i].strip()
+ ):
+ break
+ i += 1
+ block: BulletBlock = list(lines[bstart:i])
+ blocks_with_pos.append((bstart, block))
+ return ScannedBlocks(blocks_with_pos, i)
+
+
+def read_text(path: str) -> str:
+ with io.open(path, "r", encoding="utf-8") as f:
+ return f.read()
+
+
+def write_text(path: str, content: str) -> None:
+ with io.open(path, "w", encoding="utf-8", newline="") as f:
+ f.write(content)
+
+
+def _normalize_list_rst_lines(lines: Sequence[str]) -> List[str]:
+ """Return normalized content of checks list.rst as a list of lines."""
+ out: List[str] = []
+ i = 0
+ n = len(lines)
+
+ def check_name(line: str) -> Tuple[int, CheckLabel]:
+ if m := DOC_LINE_RE.match(line):
+ return (0, m.group("label"))
+ return (1, "")
+
+ while i < n:
+ line = lines[i]
+ if line.lstrip().startswith(".. csv-table::"):
+ out.append(line)
+ i += 1
+
+ while i < n and (lines[i].startswith(" ") or lines[i].strip() == ""):
+ if DOC_LINE_RE.match(lines[i]):
+ break
+ out.append(lines[i])
+ i += 1
+
+ entries: List[str] = []
+ while i < n and lines[i].startswith(" "):
+ entries.append(lines[i])
+ i += 1
+
+ entries_sorted = sorted(entries, key=check_name)
+ out.extend(entries_sorted)
+ continue
+
+ out.append(line)
+ i += 1
+
+ return out
+
+
+def normalize_list_rst(data: str) -> str:
+ """Normalize list.rst content and return a string."""
+ lines = data.splitlines(True)
+ return "".join(_normalize_list_rst_lines(lines))
+
+
+def find_heading(lines: Sequence[str], title: str) -> Optional[int]:
+ """Find heading start index for a section underlined with ^ characters.
+
+ The function looks for a line equal to `title` followed by a line that
+ consists solely of ^, which matches the ReleaseNotes style for subsection
+ headings used here.
+
+ Returns index of the title line, or None if not found.
+ """
+ for i in range(len(lines) - 1):
+ if lines[i].rstrip("\n") == title:
+ if (
+ (underline := lines[i + 1].rstrip("\n"))
+ and set(underline) == {"^"}
+ and len(underline) == len(title)
+ ):
+ return i
+ return None
+
+
+def extract_label(text: str) -> str:
+ if m := DOC_LABEL_RN_RE.search(text):
+ return m.group("label")
+ return text
+
+
+def _is_bullet_start(line: str) -> bool:
+ return line.startswith("- ")
+
+
+def _parse_bullet_blocks(lines: Sequence[str], start: int, end: int) -> BulletBlocks:
+ i = start
+ n = end
+ first_bullet = i
+ while first_bullet < n and not _is_bullet_start(lines[first_bullet]):
+ first_bullet += 1
+ prefix: Lines = list(lines[i:first_bullet])
+
+ blocks: List[BulletItem] = []
+ res = _scan_bullet_blocks(lines, first_bullet, n)
+ for _, block in res.blocks_with_pos:
+ key: CheckLabel = extract_label(block[0])
+ blocks.append((key, block))
+
+ suffix: Lines = list(lines[res.next_index : n])
+ return BulletBlocks(prefix, blocks, suffix)
+
+
+def sort_blocks(blocks: Iterable[BulletItem]) -> List[BulletBlock]:
+ """Return blocks sorted deterministically by their extracted label.
+
+ Duplicates are preserved; merging is left to authors to handle manually.
+ """
+ return list(map(itemgetter(1), sorted(blocks, key=itemgetter(0))))
+
+
+def find_duplicate_entries(
+ lines: Sequence[str], title: str
+) -> List[Tuple[CheckLabel, DuplicateOccurrences]]:
+ """Return detailed duplicate info as (key, [(start_idx, block_lines), ...]).
+
+ start_idx is the 0-based index of the first line of the bullet block in
+ the original lines list. Only keys with more than one occurrence are
+ returned, and occurrences are listed in the order they appear.
+ """
+ bounds = _find_section_bounds(lines, title, None)
+ if bounds is None:
+ return []
+ _, sec_start, sec_end = bounds
+
+ i = sec_start
+ n = sec_end
+
+ while i < n and not _is_bullet_start(lines[i]):
+ i += 1
+
+ blocks_with_pos: List[Tuple[CheckLabel, BulletStart, BulletBlock]] = []
+ res = _scan_bullet_blocks(lines, i, n)
+ for bstart, block in res.blocks_with_pos:
+ key = extract_label(block[0])
+ blocks_with_pos.append((key, bstart, block))
+
+ grouped: DefaultDict[CheckLabel, DuplicateOccurrences] = defaultdict(list)
+ for key, start, block in blocks_with_pos:
+ grouped[key].append((start, block))
+
+ result: List[Tuple[CheckLabel, DuplicateOccurrences]] = []
+ for key, occs in grouped.items():
+ if len(occs) > 1:
+ result.append((key, occs))
+
+ result.sort(key=itemgetter(0))
+ return result
+
+
+def _find_section_bounds(
+ lines: Sequence[str], title: str, next_title: Optional[str]
+) -> Optional[Tuple[int, int, int]]:
+ """Return (h_start, sec_start, sec_end) for section `title`.
+
+ - h_start: index of the section title line
+ - sec_start: index of the first content line after underline
+ - sec_end: index of the first line of the next section title (or end)
+ """
+ if (h_start := find_heading(lines, title)) is None:
+ return None
+
+ sec_start = h_start + 2
+
+ # Determine end of section either from next_title or by scanning.
+ if next_title is not None:
+ if (h_end := find_heading(lines, next_title)) is None:
+ # Scan forward to the next heading-like underline.
+ h_end = sec_start
+ while h_end + 1 < len(lines):
+ if lines[h_end].strip() and set(lines[h_end + 1].rstrip("\n")) == {"^"}:
+ break
+ h_end += 1
+ sec_end = h_end
+ else:
+ # Scan to end or until a heading underline is found.
+ h_end = sec_start
+ while h_end + 1 < len(lines):
+ if lines[h_end].strip() and set(lines[h_end + 1].rstrip("\n")) == {"^"}:
+ break
+ h_end += 1
+ sec_end = h_end
+
+ return h_start, sec_start, sec_end
+
+
+def _normalize_release_notes_section(
+ lines: Sequence[str], title: str, next_title: Optional[str]
+) -> List[str]:
+ """Normalize a single release-notes section and return updated lines."""
+ if (bounds := _find_section_bounds(lines, title, next_title)) is None:
+ return list(lines)
+ _, sec_start, sec_end = bounds
+
+ prefix, blocks, suffix = _parse_bullet_blocks(lines, sec_start, sec_end)
+ sorted_blocks = sort_blocks(blocks)
+
+ new_section: List[str] = []
+ new_section.extend(prefix)
+ for i_b, b in enumerate(sorted_blocks):
+ if i_b > 0 and (
+ not new_section or (new_section and new_section[-1].strip() != "")
+ ):
+ new_section.append("\n")
+ new_section.extend(b)
+ new_section.extend(suffix)
+
+ return list(lines[:sec_start]) + new_section + list(lines[sec_end:])
+
+
+def normalize_release_notes(lines: Sequence[str]) -> str:
+ sections = ["New checks", "New check aliases", "Changes in existing checks"]
+
+ out = list(lines)
+
+ for idx in range(len(sections) - 1, -1, -1):
+ title = sections[idx]
+ next_title = sections[idx + 1] if idx + 1 < len(sections) else None
+ out = _normalize_release_notes_section(out, title, next_title)
+
+ return "".join(out)
+
+
+def _emit_duplicate_report(lines: Sequence[str], title: str) -> Optional[str]:
+ if not (dups_detail := find_duplicate_entries(lines, title)):
+ return None
+ out: List[str] = []
+ out.append(f"Error: Duplicate entries in '{title}':\n")
+ for key, occs in dups_detail:
+ out.append(f"\n-- Duplicate: {key}\n")
+ for start_idx, block in occs:
+ out.append(f"- At line {start_idx + 1}:\n")
+ out.append("".join(block))
+ if not (block and block[-1].endswith("\n")):
+ out.append("\n")
+ return "".join(out)
+
+
+def process_release_notes(out_path: str, rn_doc: str) -> int:
+ text = read_text(rn_doc)
+ lines = text.splitlines(True)
+ normalized = normalize_release_notes(lines)
+ write_text(out_path, normalized)
+
+ # Prefer reporting ordering issues first; let diff fail the test.
+ if text != normalized:
+ sys.stderr.write(
+ "\nEntries in 'clang-tools-extra/docs/ReleaseNotes.rst' are not alphabetically sorted.\n"
+ "Fix the ordering by applying diff printed below.\n\n"
+ )
+ return 0
+
+ # Ordering is clean then enforce duplicates.
+ if report := _emit_duplicate_report(lines, "Changes in existing checks"):
+ sys.stderr.write(report)
+ return 3
+ return 0
+
+
+def process_checks_list(out_path: str, list_doc: str) -> int:
+ text = read_text(list_doc)
+ normalized = normalize_list_rst(text)
+
+ if text != normalized:
+ sys.stderr.write(
+ "\nChecks in 'clang-tools-extra/docs/clang-tidy/checks/list.rst' csv-table are not alphabetically sorted.\n"
+ "Fix the ordering by applying diff printed below.\n\n"
+ )
+
+ write_text(out_path, normalized)
+ return 0
+
+
+def main(argv: Sequence[str]) -> int:
+ ap = argparse.ArgumentParser()
+ ap.add_argument("-o", "--output", dest="out", default=None)
+ args = ap.parse_args(argv)
+
+ list_doc, rn_doc = (os.path.normpath(LIST_DOC), os.path.normpath(RELEASE_NOTES_DOC))
+
+ if args.out:
+ out_path = args.out
+ out_lower = os.path.basename(out_path).lower()
+ if "release" in out_lower:
+ return process_release_notes(out_path, rn_doc)
+ else:
+ return process_checks_list(out_path, list_doc)
+
+ process_checks_list(list_doc, list_doc)
+ return process_release_notes(rn_doc, rn_doc)
+
+
+if __name__ == "__main__":
+ sys.exit(main(sys.argv[1:]))
diff --git a/clang-tools-extra/clang-tidy/tool/check_alphabetical_order_test.py b/clang-tools-extra/clang-tidy/tool/check_alphabetical_order_test.py
new file mode 100644
index 0000000..48a3c76
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/tool/check_alphabetical_order_test.py
@@ -0,0 +1,401 @@
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+# To run these tests:
+# python3 check_alphabetical_order_test.py -v
+
+import check_alphabetical_order as _mod
+from contextlib import redirect_stderr
+import io
+import os
+import tempfile
+import textwrap
+from typing import cast
+import unittest
+
+
+class TestAlphabeticalOrderCheck(unittest.TestCase):
+ def test_normalize_list_rst_sorts_rows(self) -> None:
+ input_text = textwrap.dedent(
+ """\
+ .. csv-table:: Clang-Tidy checks
+ :header: "Name", "Offers fixes"
+
+ :doc:`bugprone-virtual-near-miss <bugprone/virtual-near-miss>`, "Yes"
+ :doc:`cert-flp30-c <cert/flp30-c>`,
+ :doc:`abseil-cleanup-ctad <abseil/cleanup-ctad>`, "Yes"
+ A non-doc row that should stay after docs
+ """
+ )
+
+ expected_text = textwrap.dedent(
+ """\
+ .. csv-table:: Clang-Tidy checks
+ :header: "Name", "Offers fixes"
+
+ :doc:`abseil-cleanup-ctad <abseil/cleanup-ctad>`, "Yes"
+ :doc:`bugprone-virtual-near-miss <bugprone/virtual-near-miss>`, "Yes"
+ :doc:`cert-flp30-c <cert/flp30-c>`,
+ A non-doc row that should stay after docs
+ """
+ )
+
+ out_str = _mod.normalize_list_rst(input_text)
+ self.assertEqual(out_str, expected_text)
+
+ def test_find_heading(self) -> None:
+ text = textwrap.dedent(
+ """\
+ - Deprecated the :program:`clang-tidy` ``zircon`` module. All checks have been
+ moved to the ``fuchsia`` module instead. The ``zircon`` module will be removed
+ in the 24th release.
+
+ New checks
+ ^^^^^^^^^^
+ - New :doc:`bugprone-derived-method-shadowing-base-method
+ <clang-tidy/checks/bugprone/derived-method-shadowing-base-method>` check.
+ """
+ )
+ lines = text.splitlines(True)
+ idx = _mod.find_heading(lines, "New checks")
+ self.assertEqual(idx, 4)
+
+ def test_duplicate_detection_and_report(self) -> None:
+ # Ensure duplicate detection works properly when sorting is incorrect.
+ text = textwrap.dedent(
+ """\
+ Changes in existing checks
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+ - Improved :doc:`bugprone-easily-swappable-parameters
+ <clang-tidy/checks/bugprone/easily-swappable-parameters>` check by
+ correcting a spelling mistake on its option
+ ``NamePrefixSuffixSilenceDissimilarityTreshold``.
+
+ - Improved :doc:`bugprone-exception-escape
+ <clang-tidy/checks/bugprone/exception-escape>` check's handling of lambdas:
+ exceptions from captures are now diagnosed, exceptions in the bodies of
+ lambdas that aren't actually invoked are not.
+
+ - Improved :doc:`bugprone-easily-swappable-parameters
+ <clang-tidy/checks/bugprone/easily-swappable-parameters>` check by
+ correcting a spelling mistake on its option
+ ``NamePrefixSuffixSilenceDissimilarityTreshold``.
+
+ """
+ )
+ lines = text.splitlines(True)
+ report = _mod._emit_duplicate_report(lines, "Changes in existing checks")
+ self.assertIsNotNone(report)
+ report_str = cast(str, report)
+
+ expected_report = textwrap.dedent(
+ """\
+ Error: Duplicate entries in 'Changes in existing checks':
+
+ -- Duplicate: - Improved :doc:`bugprone-easily-swappable-parameters
+
+ - At line 4:
+ - Improved :doc:`bugprone-easily-swappable-parameters
+ <clang-tidy/checks/bugprone/easily-swappable-parameters>` check by
+ correcting a spelling mistake on its option
+ ``NamePrefixSuffixSilenceDissimilarityTreshold``.
+
+ - At line 14:
+ - Improved :doc:`bugprone-easily-swappable-parameters
+ <clang-tidy/checks/bugprone/easily-swappable-parameters>` check by
+ correcting a spelling mistake on its option
+ ``NamePrefixSuffixSilenceDissimilarityTreshold``.
+ """
+ )
+ self.assertEqual(report_str, expected_report)
+
+ def test_process_release_notes_with_unsorted_content(self) -> None:
+ # When content is not normalized, the function writes normalized text and returns 0.
+ rn_text = textwrap.dedent(
+ """\
+ New checks
+ ^^^^^^^^^^
+
+ - New :doc:`readability-redundant-parentheses
+ <clang-tidy/checks/readability/redundant-parentheses>` check.
+
+ Detect redundant parentheses.
+
+ - New :doc:`bugprone-derived-method-shadowing-base-method
+ <clang-tidy/checks/bugprone/derived-method-shadowing-base-method>` check.
+
+ Finds derived class methods that shadow a (non-virtual) base class method.
+
+ """
+ )
+ with tempfile.TemporaryDirectory() as td:
+ rn_doc = os.path.join(td, "ReleaseNotes.rst")
+ out_path = os.path.join(td, "out.rst")
+ with open(rn_doc, "w", encoding="utf-8") as f:
+ f.write(rn_text)
+
+ buf = io.StringIO()
+ with redirect_stderr(buf):
+ rc = _mod.process_release_notes(out_path, rn_doc)
+
+ self.assertEqual(rc, 0)
+ with open(out_path, "r", encoding="utf-8") as f:
+ out = f.read()
+
+ expected_out = textwrap.dedent(
+ """\
+ New checks
+ ^^^^^^^^^^
+
+ - New :doc:`bugprone-derived-method-shadowing-base-method
+ <clang-tidy/checks/bugprone/derived-method-shadowing-base-method>` check.
+
+ Finds derived class methods that shadow a (non-virtual) base class method.
+
+ - New :doc:`readability-redundant-parentheses
+ <clang-tidy/checks/readability/redundant-parentheses>` check.
+
+ Detect redundant parentheses.
+
+
+ """
+ )
+
+ self.assertEqual(out, expected_out)
+ self.assertIn("not alphabetically sorted", buf.getvalue())
+
+ def test_process_release_notes_prioritizes_sorting_over_duplicates(self) -> None:
+ # Sorting is incorrect and duplicates exist, should report ordering issues first.
+ rn_text = textwrap.dedent(
+ """\
+ Changes in existing checks
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+ - Improved :doc:`bugprone-easily-swappable-parameters
+ <clang-tidy/checks/bugprone/easily-swappable-parameters>` check by
+ correcting a spelling mistake on its option
+ ``NamePrefixSuffixSilenceDissimilarityTreshold``.
+
+ - Improved :doc:`bugprone-exception-escape
+ <clang-tidy/checks/bugprone/exception-escape>` check's handling of lambdas:
+ exceptions from captures are now diagnosed, exceptions in the bodies of
+ lambdas that aren't actually invoked are not.
+
+ - Improved :doc:`bugprone-easily-swappable-parameters
+ <clang-tidy/checks/bugprone/easily-swappable-parameters>` check by
+ correcting a spelling mistake on its option
+ ``NamePrefixSuffixSilenceDissimilarityTreshold``.
+
+ """
+ )
+ with tempfile.TemporaryDirectory() as td:
+ rn_doc = os.path.join(td, "ReleaseNotes.rst")
+ out_path = os.path.join(td, "out.rst")
+ with open(rn_doc, "w", encoding="utf-8") as f:
+ f.write(rn_text)
+
+ buf = io.StringIO()
+ with redirect_stderr(buf):
+ rc = _mod.process_release_notes(out_path, rn_doc)
+ self.assertEqual(rc, 0)
+ self.assertIn(
+ "Entries in 'clang-tools-extra/docs/ReleaseNotes.rst' are not alphabetically sorted.",
+ buf.getvalue(),
+ )
+
+ with open(out_path, "r", encoding="utf-8") as f:
+ out = f.read()
+ expected_out = textwrap.dedent(
+ """\
+ Changes in existing checks
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+ - Improved :doc:`bugprone-easily-swappable-parameters
+ <clang-tidy/checks/bugprone/easily-swappable-parameters>` check by
+ correcting a spelling mistake on its option
+ ``NamePrefixSuffixSilenceDissimilarityTreshold``.
+
+ - Improved :doc:`bugprone-easily-swappable-parameters
+ <clang-tidy/checks/bugprone/easily-swappable-parameters>` check by
+ correcting a spelling mistake on its option
+ ``NamePrefixSuffixSilenceDissimilarityTreshold``.
+
+ - Improved :doc:`bugprone-exception-escape
+ <clang-tidy/checks/bugprone/exception-escape>` check's handling of lambdas:
+ exceptions from captures are now diagnosed, exceptions in the bodies of
+ lambdas that aren't actually invoked are not.
+
+
+ """
+ )
+ self.assertEqual(out, expected_out)
+
+ def test_process_release_notes_with_duplicates_fails(self) -> None:
+ # Sorting is already correct but duplicates exist, should return 3 and report.
+ rn_text = textwrap.dedent(
+ """\
+ Changes in existing checks
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+ - Improved :doc:`bugprone-easily-swappable-parameters
+ <clang-tidy/checks/bugprone/easily-swappable-parameters>` check by
+ correcting a spelling mistake on its option
+ ``NamePrefixSuffixSilenceDissimilarityTreshold``.
+
+ - Improved :doc:`bugprone-easily-swappable-parameters
+ <clang-tidy/checks/bugprone/easily-swappable-parameters>` check by
+ correcting a spelling mistake on its option
+ ``NamePrefixSuffixSilenceDissimilarityTreshold``.
+
+ - Improved :doc:`bugprone-exception-escape
+ <clang-tidy/checks/bugprone/exception-escape>` check's handling of lambdas:
+ exceptions from captures are now diagnosed, exceptions in the bodies of
+ lambdas that aren't actually invoked are not.
+
+ """
+ )
+ with tempfile.TemporaryDirectory() as td:
+ rn_doc = os.path.join(td, "ReleaseNotes.rst")
+ out_path = os.path.join(td, "out.rst")
+ with open(rn_doc, "w", encoding="utf-8") as f:
+ f.write(rn_text)
+
+ buf = io.StringIO()
+ with redirect_stderr(buf):
+ rc = _mod.process_release_notes(out_path, rn_doc)
+
+ self.assertEqual(rc, 3)
+ expected_report = textwrap.dedent(
+ """\
+ Error: Duplicate entries in 'Changes in existing checks':
+
+ -- Duplicate: - Improved :doc:`bugprone-easily-swappable-parameters
+
+ - At line 4:
+ - Improved :doc:`bugprone-easily-swappable-parameters
+ <clang-tidy/checks/bugprone/easily-swappable-parameters>` check by
+ correcting a spelling mistake on its option
+ ``NamePrefixSuffixSilenceDissimilarityTreshold``.
+
+ - At line 9:
+ - Improved :doc:`bugprone-easily-swappable-parameters
+ <clang-tidy/checks/bugprone/easily-swappable-parameters>` check by
+ correcting a spelling mistake on its option
+ ``NamePrefixSuffixSilenceDissimilarityTreshold``.
+
+ """
+ )
+ self.assertEqual(buf.getvalue(), expected_report)
+
+ with open(out_path, "r", encoding="utf-8") as f:
+ out = f.read()
+ self.assertEqual(out, rn_text)
+
+ def test_release_notes_handles_nested_sub_bullets(self) -> None:
+ rn_text = textwrap.dedent(
+ """\
+ Changes in existing checks
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+ - Improved :doc:`bugprone-easily-swappable-parameters
+ <clang-tidy/checks/bugprone/easily-swappable-parameters>` check by
+ correcting a spelling mistake on its option
+ ``NamePrefixSuffixSilenceDissimilarityTreshold``.
+
+ - Improved :doc:`llvm-prefer-isa-or-dyn-cast-in-conditionals
+ <clang-tidy/checks/llvm/prefer-isa-or-dyn-cast-in-conditionals>` check:
+
+ - Fix-it handles callees with nested-name-specifier correctly.
+
+ - ``if`` statements with init-statement (``if (auto X = ...; ...)``) are
+ handled correctly.
+
+ - ``for`` loops are supported.
+
+ - Improved :doc:`bugprone-exception-escape
+ <clang-tidy/checks/bugprone/exception-escape>` check's handling of lambdas:
+ exceptions from captures are now diagnosed, exceptions in the bodies of
+ lambdas that aren't actually invoked are not.
+
+ """
+ )
+
+ out = _mod.normalize_release_notes(rn_text.splitlines(True))
+
+ expected_out = textwrap.dedent(
+ """\
+ Changes in existing checks
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+ - Improved :doc:`bugprone-easily-swappable-parameters
+ <clang-tidy/checks/bugprone/easily-swappable-parameters>` check by
+ correcting a spelling mistake on its option
+ ``NamePrefixSuffixSilenceDissimilarityTreshold``.
+
+ - Improved :doc:`bugprone-exception-escape
+ <clang-tidy/checks/bugprone/exception-escape>` check's handling of lambdas:
+ exceptions from captures are now diagnosed, exceptions in the bodies of
+ lambdas that aren't actually invoked are not.
+
+ - Improved :doc:`llvm-prefer-isa-or-dyn-cast-in-conditionals
+ <clang-tidy/checks/llvm/prefer-isa-or-dyn-cast-in-conditionals>` check:
+
+ - Fix-it handles callees with nested-name-specifier correctly.
+
+ - ``if`` statements with init-statement (``if (auto X = ...; ...)``) are
+ handled correctly.
+
+ - ``for`` loops are supported.
+
+
+ """
+ )
+ self.assertEqual(out, expected_out)
+
+ def test_process_checks_list_normalizes_output(self) -> None:
+ list_text = textwrap.dedent(
+ """\
+ .. csv-table:: List
+ :header: "Name", "Redirect", "Offers fixes"
+
+ :doc:`cert-dcl16-c <cert/dcl16-c>`, :doc:`readability-uppercase-literal-suffix <readability/uppercase-literal-suffix>`, "Yes"
+ :doc:`cert-con36-c <cert/con36-c>`, :doc:`bugprone-spuriously-wake-up-functions <bugprone/spuriously-wake-up-functions>`,
+ :doc:`cert-dcl37-c <cert/dcl37-c>`, :doc:`bugprone-reserved-identifier <bugprone/reserved-identifier>`, "Yes"
+ :doc:`cert-arr39-c <cert/arr39-c>`, :doc:`bugprone-sizeof-expression <bugprone/sizeof-expression>`,
+ """
+ )
+ with tempfile.TemporaryDirectory() as td:
+ in_doc = os.path.join(td, "list.rst")
+ out_doc = os.path.join(td, "out.rst")
+ with open(in_doc, "w", encoding="utf-8") as f:
+ f.write(list_text)
+ buf = io.StringIO()
+ with redirect_stderr(buf):
+ rc = _mod.process_checks_list(out_doc, in_doc)
+ self.assertEqual(rc, 0)
+ self.assertIn(
+ "Checks in 'clang-tools-extra/docs/clang-tidy/checks/list.rst' csv-table are not alphabetically sorted.",
+ buf.getvalue(),
+ )
+ self.assertEqual(rc, 0)
+ with open(out_doc, "r", encoding="utf-8") as f:
+ out = f.read()
+
+ expected_out = textwrap.dedent(
+ """\
+ .. csv-table:: List
+ :header: "Name", "Redirect", "Offers fixes"
+
+ :doc:`cert-arr39-c <cert/arr39-c>`, :doc:`bugprone-sizeof-expression <bugprone/sizeof-expression>`,
+ :doc:`cert-con36-c <cert/con36-c>`, :doc:`bugprone-spuriously-wake-up-functions <bugprone/spuriously-wake-up-functions>`,
+ :doc:`cert-dcl16-c <cert/dcl16-c>`, :doc:`readability-uppercase-literal-suffix <readability/uppercase-literal-suffix>`, "Yes"
+ :doc:`cert-dcl37-c <cert/dcl37-c>`, :doc:`bugprone-reserved-identifier <bugprone/reserved-identifier>`, "Yes"
+ """
+ )
+ self.assertEqual(out, expected_out)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/clang-tools-extra/clang-tidy/utils/ASTUtils.cpp b/clang-tools-extra/clang-tidy/utils/ASTUtils.cpp
index d5deb99..2627813 100644
--- a/clang-tools-extra/clang-tidy/utils/ASTUtils.cpp
+++ b/clang-tools-extra/clang-tidy/utils/ASTUtils.cpp
@@ -67,7 +67,7 @@ bool rangeIsEntirelyWithinMacroArgument(SourceRange Range,
// Check if the range is entirely contained within a macro argument.
SourceLocation MacroArgExpansionStartForRangeBegin;
SourceLocation MacroArgExpansionStartForRangeEnd;
- bool RangeIsEntirelyWithinMacroArgument =
+ const bool RangeIsEntirelyWithinMacroArgument =
SM &&
SM->isMacroArgExpansion(Range.getBegin(),
&MacroArgExpansionStartForRangeBegin) &&
diff --git a/clang-tools-extra/clang-tidy/utils/ASTUtils.h b/clang-tools-extra/clang-tidy/utils/ASTUtils.h
index c2127f0..808cd4a 100644
--- a/clang-tools-extra/clang-tidy/utils/ASTUtils.h
+++ b/clang-tools-extra/clang-tidy/utils/ASTUtils.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ASTUTILS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ASTUTILS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_ASTUTILS_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_ASTUTILS_H
#include "clang/AST/AST.h"
@@ -47,4 +47,4 @@ findOutermostIndirectFieldDeclForField(const FieldDecl *FD);
} // namespace clang::tidy::utils
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ASTUTILS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_ASTUTILS_H
diff --git a/clang-tools-extra/clang-tidy/utils/Aliasing.cpp b/clang-tools-extra/clang-tidy/utils/Aliasing.cpp
index a22d235..1b12859 100644
--- a/clang-tools-extra/clang-tidy/utils/Aliasing.cpp
+++ b/clang-tools-extra/clang-tidy/utils/Aliasing.cpp
@@ -65,15 +65,9 @@ static bool hasPtrOrReferenceInStmt(const Stmt *S, const ValueDecl *Var) {
if (isPtrOrReferenceForVar(S, Var))
return true;
- for (const Stmt *Child : S->children()) {
- if (!Child)
- continue;
-
- if (hasPtrOrReferenceInStmt(Child, Var))
- return true;
- }
-
- return false;
+ return llvm::any_of(S->children(), [&](const Stmt *Child) {
+ return Child && hasPtrOrReferenceInStmt(Child, Var);
+ });
}
static bool refersToEnclosingLambdaCaptureByRef(const Decl *Func,
diff --git a/clang-tools-extra/clang-tidy/utils/BracesAroundStatement.cpp b/clang-tools-extra/clang-tidy/utils/BracesAroundStatement.cpp
index 14770c4..d0659ad 100644
--- a/clang-tools-extra/clang-tidy/utils/BracesAroundStatement.cpp
+++ b/clang-tools-extra/clang-tidy/utils/BracesAroundStatement.cpp
@@ -48,7 +48,8 @@ FixItHint BraceInsertionHints::closingBraceFixIt() const {
static tok::TokenKind getTokenKind(SourceLocation Loc, const SourceManager &SM,
const LangOptions &LangOpts) {
Token Tok;
- SourceLocation Beginning = Lexer::GetBeginningOfToken(Loc, SM, LangOpts);
+ const SourceLocation Beginning =
+ Lexer::GetBeginningOfToken(Loc, SM, LangOpts);
const bool Invalid = Lexer::getRawToken(Beginning, Tok, SM, LangOpts);
assert(!Invalid && "Expected a valid token.");
@@ -77,15 +78,16 @@ static SourceLocation findEndLocation(const Stmt &S, const SourceManager &SM,
// EOL, insert brace before.
break;
}
- tok::TokenKind TokKind = getTokenKind(Loc, SM, LangOpts);
+ const tok::TokenKind TokKind = getTokenKind(Loc, SM, LangOpts);
if (TokKind != tok::comment) {
// Non-comment token, insert brace before.
break;
}
- SourceLocation TokEndLoc = Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts);
- SourceRange TokRange(Loc, TokEndLoc);
- StringRef Comment = Lexer::getSourceText(
+ const SourceLocation TokEndLoc =
+ Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts);
+ const SourceRange TokRange(Loc, TokEndLoc);
+ const StringRef Comment = Lexer::getSourceText(
CharSourceRange::getTokenRange(TokRange), SM, LangOpts);
if (Comment.starts_with("/*") && Comment.contains('\n')) {
// Multi-line block comment, insert brace before.
@@ -139,7 +141,7 @@ BraceInsertionHints getBraceInsertionsHints(const Stmt *const S,
// StartLoc points at the location of the opening brace to be inserted.
SourceLocation EndLoc;
- std::string ClosingInsertion;
+ StringRef ClosingInsertion;
if (EndLocHint.isValid()) {
EndLoc = EndLocHint;
ClosingInsertion = "} ";
diff --git a/clang-tools-extra/clang-tidy/utils/BracesAroundStatement.h b/clang-tools-extra/clang-tidy/utils/BracesAroundStatement.h
index 53ce2e0..2b2d71f 100644
--- a/clang-tools-extra/clang-tidy/utils/BracesAroundStatement.h
+++ b/clang-tools-extra/clang-tidy/utils/BracesAroundStatement.h
@@ -11,6 +11,9 @@
///
//===----------------------------------------------------------------------===//
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_BRACESAROUNDSTATEMENT_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_BRACESAROUNDSTATEMENT_H
+
#include "clang/AST/Stmt.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/SourceLocation.h"
@@ -36,7 +39,7 @@ struct BraceInsertionHints {
/// Constructor for a hint offering fix-its for brace insertion. Both
/// positions must be valid.
BraceInsertionHints(SourceLocation OpeningBracePos,
- SourceLocation ClosingBracePos, std::string ClosingBrace)
+ SourceLocation ClosingBracePos, StringRef ClosingBrace)
: DiagnosticPos(OpeningBracePos), OpeningBracePos(OpeningBracePos),
ClosingBracePos(ClosingBracePos), ClosingBrace(ClosingBrace) {
assert(offersFixIts());
@@ -61,7 +64,7 @@ struct BraceInsertionHints {
private:
SourceLocation OpeningBracePos;
SourceLocation ClosingBracePos;
- std::string ClosingBrace;
+ StringRef ClosingBrace;
};
/// Create fix-it hints for braces that wrap the given statement when applied.
@@ -73,3 +76,5 @@ getBraceInsertionsHints(const Stmt *S, const LangOptions &LangOpts,
SourceLocation EndLocHint = SourceLocation());
} // namespace clang::tidy::utils
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_BRACESAROUNDSTATEMENT_H
diff --git a/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp b/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
index a5b0883..a807c95 100644
--- a/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
+++ b/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
@@ -21,10 +21,7 @@ using llvm::SmallPtrSet;
template <typename S>
static bool isSetDifferenceEmpty(const S &S1, const S &S2) {
- for (auto E : S1)
- if (S2.count(E) == 0)
- return false;
- return true;
+ return llvm::none_of(S1, [&S2](const auto &E) { return !S2.contains(E); });
}
// Extracts all Nodes keyed by ID from Matches and inserts them into Nodes.
@@ -63,7 +60,7 @@ static bool hasSameParameterTypes(const CXXMethodDecl &D,
static const CXXMethodDecl *findConstOverload(const CXXMethodDecl &D) {
assert(!D.isConst());
- DeclContext::lookup_result LookupResult =
+ const DeclContext::lookup_result LookupResult =
D.getParent()->lookup(D.getNameInfo().getName());
if (LookupResult.isSingleResult()) {
// No overload.
diff --git a/clang-tools-extra/clang-tidy/utils/DesignatedInitializers.h b/clang-tools-extra/clang-tidy/utils/DesignatedInitializers.h
index 9109601..1960eab 100644
--- a/clang-tools-extra/clang-tidy/utils/DesignatedInitializers.h
+++ b/clang-tools-extra/clang-tidy/utils/DesignatedInitializers.h
@@ -11,6 +11,9 @@
///
//===----------------------------------------------------------------------===//
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DESIGNATEDINITIALIZERS_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DESIGNATEDINITIALIZERS_H
+
#include "clang/AST/Expr.h"
#include "clang/Basic/SourceLocation.h"
#include "llvm/ADT/DenseMap.h"
@@ -40,3 +43,5 @@ llvm::DenseMap<clang::SourceLocation, std::string>
getUnwrittenDesignators(const clang::InitListExpr *Syn);
} // namespace clang::tidy::utils
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DESIGNATEDINITIALIZERS_H
diff --git a/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp b/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
index fd4320e..f766a1bc 100644
--- a/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
+++ b/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
@@ -44,10 +44,9 @@ ExceptionAnalyzer::ExceptionInfo &ExceptionAnalyzer::ExceptionInfo::merge(
}
// FIXME: This could be ported to clang later.
-namespace {
-bool isUnambiguousPublicBaseClass(const Type *DerivedType,
- const Type *BaseType) {
+static bool isUnambiguousPublicBaseClass(const Type *DerivedType,
+ const Type *BaseType) {
const auto *DerivedClass =
DerivedType->getCanonicalTypeUnqualified()->getAsCXXRecordDecl();
const auto *BaseClass =
@@ -78,11 +77,11 @@ bool isUnambiguousPublicBaseClass(const Type *DerivedType,
IsPublicBaseClass;
}
-inline bool isPointerOrPointerToMember(const Type *T) {
+static bool isPointerOrPointerToMember(const Type *T) {
return T->isPointerType() || T->isMemberPointerType();
}
-std::optional<QualType> getPointeeOrArrayElementQualType(QualType T) {
+static std::optional<QualType> getPointeeOrArrayElementQualType(QualType T) {
if (T->isAnyPointerType() || T->isMemberPointerType())
return T->getPointeeType();
@@ -92,7 +91,7 @@ std::optional<QualType> getPointeeOrArrayElementQualType(QualType T) {
return std::nullopt;
}
-bool isBaseOf(const Type *DerivedType, const Type *BaseType) {
+static bool isBaseOf(const Type *DerivedType, const Type *BaseType) {
const auto *DerivedClass = DerivedType->getAsCXXRecordDecl();
const auto *BaseClass = BaseType->getAsCXXRecordDecl();
if (!DerivedClass || !BaseClass)
@@ -103,12 +102,12 @@ bool isBaseOf(const Type *DerivedType, const Type *BaseType) {
}
// Check if T1 is more or Equally qualified than T2.
-bool moreOrEquallyQualified(QualType T1, QualType T2) {
+static bool moreOrEquallyQualified(QualType T1, QualType T2) {
return T1.getQualifiers().isStrictSupersetOf(T2.getQualifiers()) ||
T1.getQualifiers() == T2.getQualifiers();
}
-bool isStandardPointerConvertible(QualType From, QualType To) {
+static bool isStandardPointerConvertible(QualType From, QualType To) {
assert((From->isPointerType() || From->isMemberPointerType()) &&
(To->isPointerType() || To->isMemberPointerType()) &&
"Pointer conversion should be performed on pointer types only.");
@@ -150,7 +149,7 @@ bool isStandardPointerConvertible(QualType From, QualType To) {
return false;
}
-bool isFunctionPointerConvertible(QualType From, QualType To) {
+static bool isFunctionPointerConvertible(QualType From, QualType To) {
if (!From->isFunctionPointerType() && !From->isFunctionType() &&
!From->isMemberFunctionPointerType())
return false;
@@ -192,9 +191,8 @@ bool isFunctionPointerConvertible(QualType From, QualType To) {
// from the C rules.
//
// The function should only be called in C++ mode.
-bool isQualificationConvertiblePointer(QualType From, QualType To,
- LangOptions LangOpts) {
-
+static bool isQualificationConvertiblePointer(QualType From, QualType To,
+ const LangOptions &LangOpts) {
// [N4659 7.5 (1)]
// A cv-decomposition of a type T is a sequence of cv_i and P_i such that T is
// cv_0 P_0 cv_1 P_1 ... cv_n−1 P_n−1 cv_n U” for n > 0,
@@ -320,7 +318,6 @@ bool isQualificationConvertiblePointer(QualType From, QualType To,
return From.getTypePtr() == To.getTypePtr();
}
-} // namespace
static bool canThrow(const FunctionDecl *Func) {
// consteval specifies that every call to the function must produce a
@@ -362,8 +359,9 @@ ExceptionAnalyzer::ExceptionInfo::filterByCatch(const Type *HandlerTy,
llvm::SmallVector<const Type *, 8> TypesToDelete;
for (const auto &ThrownException : ThrownExceptions) {
const Type *ExceptionTy = ThrownException.getFirst();
- CanQualType ExceptionCanTy = ExceptionTy->getCanonicalTypeUnqualified();
- CanQualType HandlerCanTy = HandlerTy->getCanonicalTypeUnqualified();
+ const CanQualType ExceptionCanTy =
+ ExceptionTy->getCanonicalTypeUnqualified();
+ const CanQualType HandlerCanTy = HandlerTy->getCanonicalTypeUnqualified();
// The handler is of type cv T or cv T& and E and T are the same type
// (ignoring the top-level cv-qualifiers) ...
@@ -478,7 +476,7 @@ ExceptionAnalyzer::ExceptionInfo ExceptionAnalyzer::throwsException(
// For a constructor, we also have to check the initializers.
if (const auto *Ctor = dyn_cast<CXXConstructorDecl>(Func)) {
for (const CXXCtorInitializer *Init : Ctor->inits()) {
- ExceptionInfo Excs =
+ const ExceptionInfo Excs =
throwsException(Init->getInit(), Caught, CallStack);
Result.merge(Excs);
}
@@ -535,7 +533,7 @@ ExceptionAnalyzer::throwsException(const Stmt *St,
// Everything is caught through 'catch(...)'.
if (!Catch->getExceptionDecl()) {
- ExceptionInfo Rethrown = throwsException(
+ const ExceptionInfo Rethrown = throwsException(
Catch->getHandlerBlock(), Uncaught.getExceptions(), CallStack);
Results.merge(Rethrown);
Uncaught.clear();
@@ -556,53 +554,60 @@ ExceptionAnalyzer::throwsException(const Stmt *St,
Uncaught.filterByCatch(CaughtType,
Catch->getExceptionDecl()->getASTContext());
if (!FilteredExceptions.empty()) {
- ExceptionInfo Rethrown = throwsException(
+ const ExceptionInfo Rethrown = throwsException(
Catch->getHandlerBlock(), FilteredExceptions, CallStack);
Results.merge(Rethrown);
}
}
}
Results.merge(Uncaught);
- } else if (const auto *Call = dyn_cast<CallExpr>(St)) {
- if (const FunctionDecl *Func = Call->getDirectCallee()) {
- ExceptionInfo Excs =
- throwsException(Func, Caught, CallStack, Call->getBeginLoc());
- Results.merge(Excs);
- }
- } else if (const auto *Construct = dyn_cast<CXXConstructExpr>(St)) {
- ExceptionInfo Excs = throwsException(Construct->getConstructor(), Caught,
- CallStack, Construct->getBeginLoc());
- Results.merge(Excs);
} else if (const auto *DefaultInit = dyn_cast<CXXDefaultInitExpr>(St)) {
- ExceptionInfo Excs =
+ const ExceptionInfo Excs =
throwsException(DefaultInit->getExpr(), Caught, CallStack);
Results.merge(Excs);
} else if (const auto *Coro = dyn_cast<CoroutineBodyStmt>(St)) {
for (const Stmt *Child : Coro->childrenExclBody()) {
if (Child != Coro->getExceptionHandler()) {
- ExceptionInfo Excs = throwsException(Child, Caught, CallStack);
+ const ExceptionInfo Excs = throwsException(Child, Caught, CallStack);
Results.merge(Excs);
}
}
- ExceptionInfo Excs = throwsException(Coro->getBody(), Caught, CallStack);
+ const ExceptionInfo Excs =
+ throwsException(Coro->getBody(), Caught, CallStack);
Results.merge(throwsException(Coro->getExceptionHandler(),
Excs.getExceptions(), CallStack));
for (const auto &Exception : Excs.getExceptions()) {
const Type *ExcType = Exception.getFirst();
if (const CXXRecordDecl *ThrowableRec = ExcType->getAsCXXRecordDecl()) {
- ExceptionInfo DestructorExcs = throwsException(
+ const ExceptionInfo DestructorExcs = throwsException(
ThrowableRec->getDestructor(), Caught, CallStack, SourceLocation{});
Results.merge(DestructorExcs);
}
}
} else if (const auto *Lambda = dyn_cast<LambdaExpr>(St)) {
for (const Stmt *Init : Lambda->capture_inits()) {
- ExceptionInfo Excs = throwsException(Init, Caught, CallStack);
+ const ExceptionInfo Excs = throwsException(Init, Caught, CallStack);
Results.merge(Excs);
}
} else {
+ // Check whether any of this node's subexpressions throws.
for (const Stmt *Child : St->children()) {
- ExceptionInfo Excs = throwsException(Child, Caught, CallStack);
+ const ExceptionInfo Excs = throwsException(Child, Caught, CallStack);
+ Results.merge(Excs);
+ }
+
+ // If this node is a call to a function or constructor, also check
+ // whether the call itself throws.
+ if (const auto *Call = dyn_cast<CallExpr>(St)) {
+ if (const FunctionDecl *Func = Call->getDirectCallee()) {
+ const ExceptionInfo Excs =
+ throwsException(Func, Caught, CallStack, Call->getBeginLoc());
+ Results.merge(Excs);
+ }
+ } else if (const auto *Construct = dyn_cast<CXXConstructExpr>(St)) {
+ const ExceptionInfo Excs =
+ throwsException(Construct->getConstructor(), Caught, CallStack,
+ Construct->getBeginLoc());
Results.merge(Excs);
}
}
diff --git a/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h b/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h
index 1ab6dcb..1a277c8 100644
--- a/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h
+++ b/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_EXCEPTION_ANALYZER_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_EXCEPTION_ANALYZER_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_EXCEPTIONANALYZER_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_EXCEPTIONANALYZER_H
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -158,4 +158,4 @@ private:
} // namespace clang::tidy::utils
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_EXCEPTION_ANALYZER_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_EXCEPTIONANALYZER_H
diff --git a/clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp b/clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp
index b1d6b19..2da0966 100644
--- a/clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp
+++ b/clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp
@@ -20,7 +20,7 @@ ExceptionSpecAnalyzer::analyze(const FunctionDecl *FuncDecl) {
const auto [CacheEntry, NotFound] =
FunctionCache.try_emplace(FuncDecl, State::NotThrowing);
if (NotFound) {
- ExceptionSpecAnalyzer::State State = analyzeImpl(FuncDecl);
+ const ExceptionSpecAnalyzer::State State = analyzeImpl(FuncDecl);
// Update result with calculated value
FunctionCache[FuncDecl] = State;
return State;
@@ -87,20 +87,20 @@ ExceptionSpecAnalyzer::analyzeRecord(const CXXRecordDecl *RecordDecl,
return analyze(MethodDecl);
for (const auto &BaseSpec : RecordDecl->bases()) {
- State Result = analyzeBase(BaseSpec, Kind);
+ const State Result = analyzeBase(BaseSpec, Kind);
if (Result == State::Throwing || Result == State::Unknown)
return Result;
}
for (const auto &BaseSpec : RecordDecl->vbases()) {
- State Result = analyzeBase(BaseSpec, Kind);
+ const State Result = analyzeBase(BaseSpec, Kind);
if (Result == State::Throwing || Result == State::Unknown)
return Result;
}
for (const auto *FDecl : RecordDecl->fields())
if (!FDecl->isInvalidDecl() && !FDecl->isUnnamedBitField()) {
- State Result = analyzeFieldDecl(FDecl, Kind);
+ const State Result = analyzeFieldDecl(FDecl, Kind);
if (Result == State::Throwing || Result == State::Unknown)
return Result;
}
diff --git a/clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.h b/clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.h
index 3fd6fe1..06d11c8 100644
--- a/clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.h
+++ b/clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_EXCEPTION_SPEC_ANALYZER_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_EXCEPTION_SPEC_ANALYZER_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_EXCEPTIONSPECANALYZER_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_EXCEPTIONSPECANALYZER_H
#include "clang/AST/DeclCXX.h"
#include "llvm/ADT/DenseMap.h"
@@ -86,4 +86,4 @@ private:
} // namespace clang::tidy::utils
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_EXCEPTION_SPEC_ANALYZER_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_EXCEPTIONSPECANALYZER_H
diff --git a/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp b/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
index 46eebf4..45fcacf 100644
--- a/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
+++ b/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
@@ -29,13 +29,13 @@ static SmallVector<const Stmt *, 1> getParentStmts(const Stmt *S,
ASTContext *Context) {
SmallVector<const Stmt *, 1> Result;
- TraversalKindScope RAII(*Context, TK_AsIs);
+ const TraversalKindScope RAII(*Context, TK_AsIs);
DynTypedNodeList Parents = Context->getParents(*S);
SmallVector<DynTypedNode, 1> NodesToProcess(Parents.begin(), Parents.end());
while (!NodesToProcess.empty()) {
- DynTypedNode Node = NodesToProcess.back();
+ const DynTypedNode Node = NodesToProcess.back();
NodesToProcess.pop_back();
if (const auto *S = Node.get<Stmt>()) {
@@ -95,7 +95,8 @@ bool ExprSequence::inSequence(const Stmt *Before, const Stmt *After) const {
return true;
}
- SmallVector<const Stmt *, 1> BeforeParents = getParentStmts(Before, Context);
+ const SmallVector<const Stmt *, 1> BeforeParents =
+ getParentStmts(Before, Context);
// Since C++17, the callee of a call expression is guaranteed to be sequenced
// before all of the arguments.
@@ -147,12 +148,9 @@ bool ExprSequence::inSequence(const Stmt *Before, const Stmt *After) const {
// If 'After' is a parent of 'Before' or is sequenced after one of these
// parents, we know that it is sequenced after 'Before'.
- for (const Stmt *Parent : BeforeParents) {
- if (Parent == After || inSequence(Parent, After))
- return true;
- }
-
- return false;
+ return llvm::any_of(BeforeParents, [&](const Stmt *Parent) {
+ return Parent == After || inSequence(Parent, After);
+ });
}
bool ExprSequence::potentiallyAfter(const Stmt *After,
diff --git a/clang-tools-extra/clang-tidy/utils/ExprSequence.h b/clang-tools-extra/clang-tidy/utils/ExprSequence.h
index 9ef94e0..2aea99e 100644
--- a/clang-tools-extra/clang-tidy/utils/ExprSequence.h
+++ b/clang-tools-extra/clang-tidy/utils/ExprSequence.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_EXPRSEQUENCE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_EXPRSEQUENCE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_EXPRSEQUENCE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_EXPRSEQUENCE_H
#include "clang/Analysis/CFG.h"
#include "clang/Lex/Lexer.h"
@@ -117,4 +117,4 @@ private:
} // namespace clang::tidy::utils
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_EXPRSEQUENCE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_EXPRSEQUENCE_H
diff --git a/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp b/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp
index 41d5131..97be36a 100644
--- a/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp
+++ b/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp
@@ -15,19 +15,19 @@ namespace clang::tidy::utils {
bool isExpansionLocInHeaderFile(SourceLocation Loc, const SourceManager &SM,
const FileExtensionsSet &HeaderFileExtensions) {
- SourceLocation ExpansionLoc = SM.getExpansionLoc(Loc);
+ const SourceLocation ExpansionLoc = SM.getExpansionLoc(Loc);
return isFileExtension(SM.getFilename(ExpansionLoc), HeaderFileExtensions);
}
bool isPresumedLocInHeaderFile(SourceLocation Loc, SourceManager &SM,
const FileExtensionsSet &HeaderFileExtensions) {
- PresumedLoc PresumedLocation = SM.getPresumedLoc(Loc);
+ const PresumedLoc PresumedLocation = SM.getPresumedLoc(Loc);
return isFileExtension(PresumedLocation.getFilename(), HeaderFileExtensions);
}
bool isSpellingLocInHeaderFile(SourceLocation Loc, SourceManager &SM,
const FileExtensionsSet &HeaderFileExtensions) {
- SourceLocation SpellingLoc = SM.getSpellingLoc(Loc);
+ const SourceLocation SpellingLoc = SM.getSpellingLoc(Loc);
return isFileExtension(SM.getFilename(SpellingLoc), HeaderFileExtensions);
}
@@ -35,7 +35,7 @@ bool parseFileExtensions(StringRef AllFileExtensions,
FileExtensionsSet &FileExtensions,
StringRef Delimiters) {
SmallVector<StringRef, 5> Suffixes;
- for (char Delimiter : Delimiters) {
+ for (const char Delimiter : Delimiters) {
if (AllFileExtensions.contains(Delimiter)) {
AllFileExtensions.split(Suffixes, Delimiter);
break;
@@ -43,7 +43,7 @@ bool parseFileExtensions(StringRef AllFileExtensions,
}
FileExtensions.clear();
- for (StringRef Suffix : Suffixes) {
+ for (const StringRef Suffix : Suffixes) {
StringRef Extension = Suffix.trim();
if (!llvm::all_of(Extension, isAlphanumeric))
return false;
diff --git a/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h b/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h
index dfab141..425c29c 100644
--- a/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h
+++ b/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_FILE_EXTENSIONS_UTILS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_FILE_EXTENSIONS_UTILS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_FILEEXTENSIONSUTILS_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_FILEEXTENSIONSUTILS_H
#include "../FileExtensionsSet.h"
#include "clang/Basic/SourceLocation.h"
@@ -60,4 +60,4 @@ bool isFileExtension(StringRef FileName,
} // namespace clang::tidy::utils
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_FILE_EXTENSIONS_UTILS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_FILEEXTENSIONSUTILS_H
diff --git a/clang-tools-extra/clang-tidy/utils/FixItHintUtils.cpp b/clang-tools-extra/clang-tidy/utils/FixItHintUtils.cpp
index b30c83e..c4cdf0d 100644
--- a/clang-tools-extra/clang-tidy/utils/FixItHintUtils.cpp
+++ b/clang-tools-extra/clang-tidy/utils/FixItHintUtils.cpp
@@ -140,7 +140,7 @@ changePointer(const VarDecl &Var, Qualifiers::TQ Qualifier, const Type *Pointee,
// the `*` token and placing the `const` left of it.
// (`int const* p = nullptr;`)
if (QualPolicy == QualifierPolicy::Right) {
- SourceLocation BeforeStar = lexer::findPreviousTokenKind(
+ const SourceLocation BeforeStar = lexer::findPreviousTokenKind(
Var.getLocation(), Context.getSourceManager(), Context.getLangOpts(),
tok::star);
if (locDangerous(BeforeStar))
@@ -161,7 +161,7 @@ changePointer(const VarDecl &Var, Qualifiers::TQ Qualifier, const Type *Pointee,
// is the same as 'QualPolicy == Right && isValueType(Pointee)'.
// The `const` must be left of the last `*` token.
// (`int * const* p = nullptr;`)
- SourceLocation BeforeStar = lexer::findPreviousTokenKind(
+ const SourceLocation BeforeStar = lexer::findPreviousTokenKind(
Var.getLocation(), Context.getSourceManager(), Context.getLangOpts(),
tok::star);
return fixIfNotDangerous(BeforeStar, buildQualifier(Qualifier, true));
@@ -178,7 +178,7 @@ changeReferencee(const VarDecl &Var, Qualifiers::TQ Qualifier, QualType Pointee,
return fixIfNotDangerous(Var.getTypeSpecStartLoc(),
buildQualifier(Qualifier));
- SourceLocation BeforeRef = lexer::findPreviousAnyTokenKind(
+ const SourceLocation BeforeRef = lexer::findPreviousAnyTokenKind(
Var.getLocation(), Context.getSourceManager(), Context.getLangOpts(),
tok::amp, tok::ampamp);
std::optional<SourceLocation> IgnoredParens =
@@ -201,7 +201,7 @@ std::optional<FixItHint> addQualifierToVarDecl(const VarDecl &Var,
QualTarget == QualifierTarget::Value) &&
"Unexpected Target");
- QualType ParenStrippedType = Var.getType().IgnoreParens();
+ const QualType ParenStrippedType = Var.getType().IgnoreParens();
if (isValueType(ParenStrippedType))
return changeValue(Var, Qualifier, QualTarget, QualPolicy, Context);
diff --git a/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp b/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
index f4945b2..d210b00 100644
--- a/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
+++ b/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
@@ -245,7 +245,7 @@ FormatStringConverter::formatStringContainsUnreplaceableMacro(
// inhibit conversion. The whole format string will appear to come from that
// macro, as will the function call.
std::optional<StringRef> MaybeSurroundingMacroName;
- if (SourceLocation BeginCallLoc = Call->getBeginLoc();
+ if (const SourceLocation BeginCallLoc = Call->getBeginLoc();
BeginCallLoc.isMacroID())
MaybeSurroundingMacroName =
Lexer::getImmediateMacroName(BeginCallLoc, SM, PP.getLangOpts());
@@ -283,7 +283,8 @@ FormatStringConverter::formatStringContainsUnreplaceableMacro(
void FormatStringConverter::emitAlignment(const PrintfSpecifier &FS,
std::string &FormatSpec) {
- ConversionSpecifier::Kind ArgKind = FS.getConversionSpecifier().getKind();
+ const ConversionSpecifier::Kind ArgKind =
+ FS.getConversionSpecifier().getKind();
// We only care about alignment if a field width is specified
if (FS.getFieldWidth().getHowSpecified() != OptionalAmount::NotSpecified) {
@@ -499,7 +500,8 @@ bool FormatStringConverter::emitIntegerArgument(
/// @returns true on success, false on failure
bool FormatStringConverter::emitType(const PrintfSpecifier &FS, const Expr *Arg,
std::string &FormatSpec) {
- ConversionSpecifier::Kind ArgKind = FS.getConversionSpecifier().getKind();
+ const ConversionSpecifier::Kind ArgKind =
+ FS.getConversionSpecifier().getKind();
switch (ArgKind) {
case ConversionSpecifier::Kind::sArg:
emitStringArgument(FS.getArgIndex() + ArgsOffset, Arg);
@@ -622,7 +624,6 @@ bool FormatStringConverter::HandlePrintfSpecifier(const PrintfSpecifier &FS,
const char *StartSpecifier,
unsigned SpecifierLen,
const TargetInfo &Target) {
-
const size_t StartSpecifierPos = StartSpecifier - PrintfFormatString.data();
assert(StartSpecifierPos + SpecifierLen <= PrintfFormatString.size());
@@ -699,6 +700,7 @@ void FormatStringConverter::finalizeFormatText() {
/// Append literal parts of the format text, reinstating escapes as required.
void FormatStringConverter::appendFormatText(const StringRef Text) {
for (const char Ch : Text) {
+ const auto UCh = static_cast<unsigned char>(Ch);
if (Ch == '\a')
StandardFormatString += "\\a";
else if (Ch == '\b')
@@ -723,10 +725,10 @@ void FormatStringConverter::appendFormatText(const StringRef Text) {
} else if (Ch == '}') {
StandardFormatString += "}}";
FormatStringNeededRewriting = true;
- } else if (Ch < 32) {
+ } else if (UCh < 32) {
StandardFormatString += "\\x";
- StandardFormatString += llvm::hexdigit(Ch >> 4, true);
- StandardFormatString += llvm::hexdigit(Ch & 0xf, true);
+ StandardFormatString += llvm::hexdigit(UCh >> 4, true);
+ StandardFormatString += llvm::hexdigit(UCh & 0xf, true);
} else
StandardFormatString += Ch;
}
@@ -798,7 +800,7 @@ void FormatStringConverter::applyFixes(DiagnosticBuilder &Diag,
}
for (const auto &[ArgIndex, Replacement] : ArgFixes) {
- SourceLocation AfterOtherSide =
+ const SourceLocation AfterOtherSide =
Lexer::findNextToken(Args[ArgIndex]->getEndLoc(), SM, LangOpts)
->getLocation();
diff --git a/clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp b/clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
index e1d1387..d36b187 100644
--- a/clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
+++ b/clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
@@ -32,11 +32,11 @@ public:
FileID PrevFID) override {
// Record all files we enter. We'll need them to diagnose headers without
// guards.
- SourceManager &SM = PP->getSourceManager();
+ const SourceManager &SM = PP->getSourceManager();
if (Reason == EnterFile && FileType == SrcMgr::C_User) {
if (OptionalFileEntryRef FE =
SM.getFileEntryRefForID(SM.getFileID(Loc))) {
- std::string FileName = cleanPath(FE->getName());
+ const std::string FileName = cleanPath(FE->getName());
Files[FileName] = *FE;
}
}
@@ -66,7 +66,7 @@ public:
void EndOfMainFile() override {
// Now that we have all this information from the preprocessor, use it!
- SourceManager &SM = PP->getSourceManager();
+ const SourceManager &SM = PP->getSourceManager();
for (const auto &MacroEntry : Macros) {
const MacroInfo *MI = MacroEntry.second;
@@ -79,7 +79,7 @@ public:
OptionalFileEntryRef FE =
SM.getFileEntryRefForID(SM.getFileID(MI->getDefinitionLoc()));
- std::string FileName = cleanPath(FE->getName());
+ const std::string FileName = cleanPath(FE->getName());
Files.erase(FileName);
// See if we should check and fix this header guard.
@@ -88,16 +88,16 @@ public:
// Look up Locations for this guard.
const auto &Locs = Ifndefs[MacroEntry.first.getIdentifierInfo()];
- SourceLocation Ifndef = Locs.second;
- SourceLocation Define = MacroEntry.first.getLocation();
- SourceLocation EndIf = EndIfs[Locs.first];
+ const SourceLocation Ifndef = Locs.second;
+ const SourceLocation Define = MacroEntry.first.getLocation();
+ const SourceLocation EndIf = EndIfs[Locs.first];
// If the macro Name is not equal to what we can compute, correct it in
// the #ifndef and #define.
- StringRef CurHeaderGuard =
+ const StringRef CurHeaderGuard =
MacroEntry.first.getIdentifierInfo()->getName();
std::vector<FixItHint> FixIts;
- std::string NewGuard = checkHeaderGuardDefinition(
+ const std::string NewGuard = checkHeaderGuardDefinition(
Ifndef, Define, EndIf, FileName, CurHeaderGuard, FixIts);
// Now look at the #endif. We want a comment with the header guard. Fix it
@@ -129,7 +129,7 @@ public:
if (!EndIf.isValid())
return false;
const char *EndIfData = PP->getSourceManager().getCharacterData(EndIf);
- size_t EndIfLen = std::strcspn(EndIfData, "\r\n");
+ const size_t EndIfLen = std::strcspn(EndIfData, "\r\n");
if (EndIfLenPtr)
*EndIfLenPtr = EndIfLen;
@@ -137,12 +137,12 @@ public:
EndIfStr = EndIfStr.substr(EndIfStr.find_first_not_of("#endif \t"));
// Give up if there's an escaped newline.
- size_t FindEscapedNewline = EndIfStr.find_last_not_of(' ');
+ const size_t FindEscapedNewline = EndIfStr.find_last_not_of(' ');
if (FindEscapedNewline != StringRef::npos &&
EndIfStr[FindEscapedNewline] == '\\')
return false;
- bool IsLineComment =
+ const bool IsLineComment =
EndIfStr.consume_front("//") ||
(EndIfStr.consume_front("/*") && EndIfStr.consume_back("*/"));
if (!IsLineComment)
@@ -162,7 +162,7 @@ public:
std::vector<FixItHint> &FixIts) {
std::string CPPVar = Check->getHeaderGuard(FileName, CurHeaderGuard);
CPPVar = Check->sanitizeHeaderGuard(CPPVar);
- std::string CPPVarUnder = CPPVar + '_';
+ const std::string CPPVarUnder = CPPVar + '_';
// Allow a trailing underscore if and only if we don't have to change the
// endif comment too.
@@ -203,19 +203,20 @@ public:
// fix-its to add the guard.
// TODO: Insert the guard after top comments.
for (const auto &FE : Files) {
- StringRef FileName = FE.getKey();
+ const StringRef FileName = FE.getKey();
if (!Check->shouldSuggestToAddHeaderGuard(FileName))
continue;
- SourceManager &SM = PP->getSourceManager();
- FileID FID = SM.translateFile(FE.getValue());
- SourceLocation StartLoc = SM.getLocForStartOfFile(FID);
+ const SourceManager &SM = PP->getSourceManager();
+ const FileID FID = SM.translateFile(FE.getValue());
+ const SourceLocation StartLoc = SM.getLocForStartOfFile(FID);
if (StartLoc.isInvalid())
continue;
std::string CPPVar = Check->getHeaderGuard(FileName);
CPPVar = Check->sanitizeHeaderGuard(CPPVar);
- std::string CPPVarUnder = CPPVar + '_'; // Allow a trailing underscore.
+ const std::string CPPVarUnder =
+ CPPVar + '_'; // Allow a trailing underscore.
// If there's a macro with a name that follows the header guard convention
// but was not recognized by the preprocessor as a header guard there must
// be code outside of the guarded area. Emit a plain warning without
@@ -223,8 +224,8 @@ public:
// FIXME: Can we move it into the right spot?
bool SeenMacro = false;
for (const auto &MacroEntry : Macros) {
- StringRef Name = MacroEntry.first.getIdentifierInfo()->getName();
- SourceLocation DefineLoc = MacroEntry.first.getLocation();
+ const StringRef Name = MacroEntry.first.getIdentifierInfo()->getName();
+ const SourceLocation DefineLoc = MacroEntry.first.getLocation();
if ((Name == CPPVar || Name == CPPVarUnder) &&
SM.isWrittenInSameFile(StartLoc, DefineLoc)) {
Check->diag(DefineLoc, "code/includes outside of area guarded by "
diff --git a/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp b/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
index 0b67cba..81bb8de 100644
--- a/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
+++ b/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
@@ -69,7 +69,7 @@ IncludeSorter &IncludeInserter::getOrCreate(FileID FileID) {
std::optional<FixItHint>
IncludeInserter::createIncludeInsertion(FileID FileID, llvm::StringRef Header) {
- bool IsAngled = Header.consume_front("<");
+ const bool IsAngled = Header.consume_front("<");
if (IsAngled != Header.consume_back(">"))
return std::nullopt;
// We assume the same Header will never be included both angled and not
@@ -94,7 +94,7 @@ void IncludeInserter::addInclude(StringRef FileName, bool IsAngled,
SourceLocation EndLocation) {
assert(SourceMgr && "SourceMgr shouldn't be null; did you remember to call "
"registerPreprocessor()?");
- FileID FileID = SourceMgr->getFileID(HashLocation);
+ const FileID FileID = SourceMgr->getFileID(HashLocation);
getOrCreate(FileID).addInclude(FileName, IsAngled, HashLocation, EndLocation);
}
diff --git a/clang-tools-extra/clang-tidy/utils/IncludeInserter.h b/clang-tools-extra/clang-tidy/utils/IncludeInserter.h
index f6ca7d6..9dbf2a7 100644
--- a/clang-tools-extra/clang-tidy/utils/IncludeInserter.h
+++ b/clang-tools-extra/clang-tidy/utils/IncludeInserter.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INCLUDEINSERTER_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INCLUDEINSERTER_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_INCLUDEINSERTER_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_INCLUDEINSERTER_H
#include "IncludeSorter.h"
#include "clang/Basic/Diagnostic.h"
@@ -100,4 +100,4 @@ private:
} // namespace tidy::utils
} // namespace clang
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INCLUDEINSERTER_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_INCLUDEINSERTER_H
diff --git a/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp b/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
index 7e2aad9..f113f8c 100644
--- a/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
+++ b/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
@@ -17,7 +17,7 @@ namespace utils {
static StringRef removeFirstSuffix(StringRef Str,
ArrayRef<const char *> Suffixes) {
- for (StringRef Suffix : Suffixes) {
+ for (const StringRef Suffix : Suffixes) {
if (Str.consume_back(Suffix))
return Str;
}
@@ -37,7 +37,7 @@ static StringRef makeCanonicalName(StringRef Str,
removeFirstSuffix(Str, {".cc", ".cpp", ".c", ".h", ".hpp"}), {"Test"});
}
if (Style == IncludeSorter::IS_Google_ObjC) {
- StringRef Canonical =
+ const StringRef Canonical =
removeFirstSuffix(removeFirstSuffix(Str, {".cc", ".cpp", ".c", ".h",
".hpp", ".mm", ".m"}),
{"_unittest", "_regtest", "_test", "Test"});
@@ -57,7 +57,7 @@ static StringRef makeCanonicalName(StringRef Str,
// Scan to the end of the line and return the offset of the next line.
static size_t findNextLine(const char *Text) {
- size_t EOLIndex = std::strcspn(Text, "\n");
+ const size_t EOLIndex = std::strcspn(Text, "\n");
return Text[EOLIndex] == '\0' ? EOLIndex : EOLIndex + 1;
}
@@ -74,14 +74,15 @@ determineIncludeKind(StringRef CanonicalFile, StringRef IncludeFile,
return IncludeFile.ends_with(".h") ? IncludeSorter::IK_CSystemInclude
: IncludeSorter::IK_CXXSystemInclude;
}
- StringRef CanonicalInclude = makeCanonicalName(IncludeFile, Style);
+ const StringRef CanonicalInclude = makeCanonicalName(IncludeFile, Style);
if (CanonicalFile.ends_with(CanonicalInclude) ||
CanonicalInclude.ends_with(CanonicalFile)) {
return IncludeSorter::IK_MainTUInclude;
}
if ((Style == IncludeSorter::IS_Google) ||
(Style == IncludeSorter::IS_Google_ObjC)) {
- std::pair<StringRef, StringRef> Parts = CanonicalInclude.split("/public/");
+ const std::pair<StringRef, StringRef> Parts =
+ CanonicalInclude.split("/public/");
StringRef FileCopy = CanonicalFile;
if (FileCopy.consume_front(Parts.first) &&
FileCopy.consume_back(Parts.second)) {
@@ -126,7 +127,7 @@ IncludeSorter::IncludeSorter(const SourceManager *SourceMgr, FileID FileID,
void IncludeSorter::addInclude(StringRef FileName, bool IsAngled,
SourceLocation HashLocation,
SourceLocation EndLocation) {
- int Offset = findNextLine(SourceMgr->getCharacterData(EndLocation));
+ const int Offset = findNextLine(SourceMgr->getCharacterData(EndLocation));
// Record the relevant location information for this inclusion directive.
auto &IncludeLocation = IncludeLocations[FileName];
@@ -139,7 +140,7 @@ void IncludeSorter::addInclude(StringRef FileName, bool IsAngled,
return;
// Add the included file's name to the appropriate bucket.
- IncludeKinds Kind =
+ const IncludeKinds Kind =
determineIncludeKind(CanonicalFile, FileName, IsAngled, Style);
if (Kind != IK_InvalidInclude)
IncludeBucket[Kind].push_back(FileName.str());
@@ -181,7 +182,8 @@ IncludeSorter::createIncludeInsertion(StringRef FileName, bool IsAngled) {
// FileName comes after all include entries in bucket, insert it after
// last.
const std::string &LastInclude = IncludeBucket[IncludeKind].back();
- SourceRange LastIncludeLocation = IncludeLocations[LastInclude].back();
+ const SourceRange LastIncludeLocation =
+ IncludeLocations[LastInclude].back();
return FixItHint::CreateInsertion(LastIncludeLocation.getEnd(),
IncludeStmt);
}
@@ -205,14 +207,16 @@ IncludeSorter::createIncludeInsertion(StringRef FileName, bool IsAngled) {
if (NonEmptyKind < IncludeKind) {
// Create a block after.
const std::string &LastInclude = IncludeBucket[NonEmptyKind].back();
- SourceRange LastIncludeLocation = IncludeLocations[LastInclude].back();
+ const SourceRange LastIncludeLocation =
+ IncludeLocations[LastInclude].back();
IncludeStmt = '\n' + IncludeStmt;
return FixItHint::CreateInsertion(LastIncludeLocation.getEnd(),
IncludeStmt);
}
// Create a block before.
const std::string &FirstInclude = IncludeBucket[NonEmptyKind][0];
- SourceRange FirstIncludeLocation = IncludeLocations[FirstInclude].back();
+ const SourceRange FirstIncludeLocation =
+ IncludeLocations[FirstInclude].back();
IncludeStmt.append("\n");
return FixItHint::CreateInsertion(FirstIncludeLocation.getBegin(),
IncludeStmt);
diff --git a/clang-tools-extra/clang-tidy/utils/IncludeSorter.h b/clang-tools-extra/clang-tidy/utils/IncludeSorter.h
index 66830ee..6efec97 100644
--- a/clang-tools-extra/clang-tidy/utils/IncludeSorter.h
+++ b/clang-tools-extra/clang-tidy/utils/IncludeSorter.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INCLUDESORTER_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INCLUDESORTER_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_INCLUDESORTER_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_INCLUDESORTER_H
#include "../ClangTidyCheck.h"
#include <optional>
@@ -73,4 +73,4 @@ template <> struct OptionEnumMapping<utils::IncludeSorter::IncludeStyle> {
getEnumMapping();
};
} // namespace clang::tidy
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INCLUDESORTER_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_INCLUDESORTER_H
diff --git a/clang-tools-extra/clang-tidy/utils/LexerUtils.cpp b/clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
index 7222f64..06d6caa 100644
--- a/clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
+++ b/clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "LexerUtils.h"
-#include "clang/AST/AST.h"
#include "clang/Basic/SourceManager.h"
#include <optional>
#include <utility>
@@ -42,7 +41,7 @@ SourceLocation findPreviousTokenStart(SourceLocation Start,
if (Start.isInvalid() || Start.isMacroID())
return {};
- SourceLocation BeforeStart = Start.getLocWithOffset(-1);
+ const SourceLocation BeforeStart = Start.getLocWithOffset(-1);
if (BeforeStart.isInvalid() || BeforeStart.isMacroID())
return {};
@@ -57,7 +56,7 @@ SourceLocation findPreviousTokenKind(SourceLocation Start,
return {};
while (true) {
- SourceLocation L = findPreviousTokenStart(Start, SM, LangOpts);
+ const SourceLocation L = findPreviousTokenStart(Start, SM, LangOpts);
if (L.isInvalid() || L.isMacroID())
return {};
@@ -123,8 +122,9 @@ std::optional<Token> getQualifyingToken(tok::TokenKind TK,
assert((TK == tok::kw_const || TK == tok::kw_volatile ||
TK == tok::kw_restrict) &&
"TK is not a qualifier keyword");
- std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Range.getBegin());
- StringRef File = SM.getBufferData(LocInfo.first);
+ const std::pair<FileID, unsigned> LocInfo =
+ SM.getDecomposedLoc(Range.getBegin());
+ const StringRef File = SM.getBufferData(LocInfo.first);
Lexer RawLexer(SM.getLocForStartOfFile(LocInfo.first), Context.getLangOpts(),
File.begin(), File.data() + LocInfo.second, File.end());
std::optional<Token> LastMatchBeforeTemplate;
@@ -169,7 +169,6 @@ static bool breakAndReturnEndPlus1Token(const Stmt &S) {
static SourceLocation getSemicolonAfterStmtEndLoc(const SourceLocation &EndLoc,
const SourceManager &SM,
const LangOptions &LangOpts) {
-
if (EndLoc.isMacroID()) {
// Assuming EndLoc points to a function call foo within macro F.
// This method is supposed to return location of the semicolon within
@@ -205,7 +204,6 @@ static SourceLocation getSemicolonAfterStmtEndLoc(const SourceLocation &EndLoc,
SourceLocation getUnifiedEndLoc(const Stmt &S, const SourceManager &SM,
const LangOptions &LangOpts) {
-
const Stmt *LastChild = &S;
while (!LastChild->children().empty() && !breakAndReturnEnd(*LastChild) &&
!breakAndReturnEndPlus1Token(*LastChild)) {
diff --git a/clang-tools-extra/clang-tidy/utils/LexerUtils.h b/clang-tools-extra/clang-tidy/utils/LexerUtils.h
index b76a378..c5fb646 100644
--- a/clang-tools-extra/clang-tidy/utils/LexerUtils.h
+++ b/clang-tools-extra/clang-tidy/utils/LexerUtils.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_LEXER_UTILS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_LEXER_UTILS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_LEXERUTILS_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_LEXERUTILS_H
#include "clang/AST/ASTContext.h"
#include "clang/Basic/TokenKinds.h"
@@ -48,7 +48,7 @@ SourceLocation findPreviousAnyTokenKind(SourceLocation Start,
if (Start.isInvalid() || Start.isMacroID())
return {};
while (true) {
- SourceLocation L = findPreviousTokenStart(Start, SM, LangOpts);
+ const SourceLocation L = findPreviousTokenStart(Start, SM, LangOpts);
if (L.isInvalid() || L.isMacroID())
return {};
@@ -76,7 +76,7 @@ SourceLocation findNextAnyTokenKind(SourceLocation Start,
if (!CurrentToken)
return {};
- Token PotentialMatch = *CurrentToken;
+ const Token PotentialMatch = *CurrentToken;
if (PotentialMatch.isOneOf(TK, TKs...))
return PotentialMatch.getLocation();
@@ -130,4 +130,4 @@ SourceLocation getLocationForNoexceptSpecifier(const FunctionDecl *FuncDecl,
} // namespace tidy::utils::lexer
} // namespace clang
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_LEXER_UTILS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_LEXERUTILS_H
diff --git a/clang-tools-extra/clang-tidy/utils/Matchers.cpp b/clang-tools-extra/clang-tidy/utils/Matchers.cpp
index 4382745..b1591fb 100644
--- a/clang-tools-extra/clang-tidy/utils/Matchers.cpp
+++ b/clang-tools-extra/clang-tidy/utils/Matchers.cpp
@@ -27,7 +27,6 @@ MatchesAnyListedTypeNameMatcher::~MatchesAnyListedTypeNameMatcher() = default;
bool MatchesAnyListedTypeNameMatcher::matches(
const QualType &Node, ast_matchers::internal::ASTMatchFinder *Finder,
ast_matchers::internal::BoundNodesTreeBuilder *Builder) const {
-
if (NameMatchers.empty())
return false;
diff --git a/clang-tools-extra/clang-tidy/utils/Matchers.h b/clang-tools-extra/clang-tidy/utils/Matchers.h
index 4eac065..a444ab62 100644
--- a/clang-tools-extra/clang-tidy/utils/Matchers.h
+++ b/clang-tools-extra/clang-tidy/utils/Matchers.h
@@ -162,7 +162,7 @@ struct NotIdenticalStatementsPredicate {
// Checks if statement is identical (utils::areStatementsIdentical) to one bound
// to ID node.
AST_MATCHER_P(Stmt, isStatementIdenticalToBoundNode, std::string, ID) {
- NotIdenticalStatementsPredicate Predicate{
+ const NotIdenticalStatementsPredicate Predicate{
ID, ::clang::DynTypedNode::create(Node), &(Finder->getASTContext())};
return Builder->removeBindings(Predicate);
}
diff --git a/clang-tools-extra/clang-tidy/utils/NamespaceAliaser.cpp b/clang-tools-extra/clang-tidy/utils/NamespaceAliaser.cpp
index 3af7f8d..c862364 100644
--- a/clang-tools-extra/clang-tidy/utils/NamespaceAliaser.cpp
+++ b/clang-tools-extra/clang-tidy/utils/NamespaceAliaser.cpp
@@ -55,7 +55,7 @@ NamespaceAliaser::createAlias(ASTContext &Context, const Stmt &Statement,
}
for (const auto &Abbreviation : Abbreviations) {
- DeclarationMatcher ConflictMatcher = namedDecl(hasName(Abbreviation));
+ const DeclarationMatcher ConflictMatcher = namedDecl(hasName(Abbreviation));
const auto HasConflictingChildren =
!match(findAll(ConflictMatcher), *Function, Context).empty();
const auto HasConflictingAncestors =
@@ -65,10 +65,10 @@ NamespaceAliaser::createAlias(ASTContext &Context, const Stmt &Statement,
if (HasConflictingAncestors || HasConflictingChildren)
continue;
- std::string Declaration =
+ const std::string Declaration =
(llvm::Twine("\nnamespace ") + Abbreviation + " = " + Namespace + ";")
.str();
- SourceLocation Loc =
+ const SourceLocation Loc =
Lexer::getLocForEndOfToken(Function->getBody()->getBeginLoc(), 0,
SourceMgr, Context.getLangOpts());
AddedAliases[Function][Namespace.str()] = Abbreviation;
diff --git a/clang-tools-extra/clang-tidy/utils/NamespaceAliaser.h b/clang-tools-extra/clang-tidy/utils/NamespaceAliaser.h
index 497b67e..fbf0ade 100644
--- a/clang-tools-extra/clang-tidy/utils/NamespaceAliaser.h
+++ b/clang-tools-extra/clang-tidy/utils/NamespaceAliaser.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_NAMESPACEALIASER_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_NAMESPACEALIASER_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_NAMESPACEALIASER_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_NAMESPACEALIASER_H
#include "clang/AST/ASTContext.h"
#include "clang/AST/Stmt.h"
@@ -45,4 +45,4 @@ private:
} // namespace clang::tidy::utils
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_NAMESPACEALIASER_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_NAMESPACEALIASER_H
diff --git a/clang-tools-extra/clang-tidy/utils/OptionsUtils.h b/clang-tools-extra/clang-tidy/utils/OptionsUtils.h
index aec24ab..3a12348 100644
--- a/clang-tools-extra/clang-tidy/utils/OptionsUtils.h
+++ b/clang-tools-extra/clang-tidy/utils/OptionsUtils.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_OPTIONUTILS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_OPTIONUTILS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_OPTIONSUTILS_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_OPTIONSUTILS_H
#include "clang/Basic/LLVM.h"
#include <string>
@@ -26,4 +26,4 @@ std::string serializeStringList(ArrayRef<StringRef> Strings);
} // namespace clang::tidy::utils::options
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_OPTIONUTILS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_OPTIONSUTILS_H
diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
index 6bd6d98..bc6de97 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -103,7 +103,7 @@ static const CXXMethodDecl *getOverrideMethod(const CXXMethodDecl *Method) {
while (true) {
Method = *Method->begin_overridden_methods();
assert(Method && "Overridden method shouldn't be null");
- unsigned NumOverrides = Method->size_overridden_methods();
+ const unsigned NumOverrides = Method->size_overridden_methods();
if (NumOverrides == 0)
return Method;
if (NumOverrides > 1)
@@ -148,7 +148,7 @@ static NameLookup findDeclInBases(const CXXRecordDecl &Parent,
return NameLookup(InClassRef);
const NamedDecl *Found = nullptr;
- for (CXXBaseSpecifier Base : Parent.bases()) {
+ for (const CXXBaseSpecifier Base : Parent.bases()) {
const auto *Record = Base.getType()->getAsCXXRecordDecl();
if (!Record && AggressiveTemplateLookup) {
if (const auto *TST =
@@ -269,7 +269,7 @@ public:
}
bool VisitNamedDecl(NamedDecl *Decl) {
- SourceRange UsageRange =
+ const SourceRange UsageRange =
DeclarationNameInfo(Decl->getDeclName(), Decl->getLocation())
.getSourceRange();
Check->addUsage(Decl, UsageRange, SM);
@@ -277,13 +277,13 @@ public:
}
bool VisitDeclRefExpr(DeclRefExpr *DeclRef) {
- SourceRange Range = DeclRef->getNameInfo().getSourceRange();
+ const SourceRange Range = DeclRef->getNameInfo().getSourceRange();
Check->addUsage(DeclRef->getDecl(), Range, SM);
return true;
}
bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc Loc) {
- if (NestedNameSpecifier Spec = Loc.getNestedNameSpecifier();
+ if (const NestedNameSpecifier Spec = Loc.getNestedNameSpecifier();
Spec.getKind() == NestedNameSpecifier::Kind::Namespace) {
if (const auto *Decl =
dyn_cast<NamespaceDecl>(Spec.getAsNamespaceAndPrefix().Namespace))
@@ -295,27 +295,28 @@ public:
}
bool VisitMemberExpr(MemberExpr *MemberRef) {
- SourceRange Range = MemberRef->getMemberNameInfo().getSourceRange();
+ const SourceRange Range = MemberRef->getMemberNameInfo().getSourceRange();
Check->addUsage(MemberRef->getMemberDecl(), Range, SM);
return true;
}
bool
VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *DepMemberRef) {
- QualType BaseType = DepMemberRef->isArrow()
- ? DepMemberRef->getBaseType()->getPointeeType()
- : DepMemberRef->getBaseType();
+ const QualType BaseType =
+ DepMemberRef->isArrow() ? DepMemberRef->getBaseType()->getPointeeType()
+ : DepMemberRef->getBaseType();
if (BaseType.isNull())
return true;
const CXXRecordDecl *Base = BaseType.getTypePtr()->getAsCXXRecordDecl();
if (!Base)
return true;
- DeclarationName DeclName = DepMemberRef->getMemberNameInfo().getName();
+ const DeclarationName DeclName =
+ DepMemberRef->getMemberNameInfo().getName();
if (!DeclName.isIdentifier())
return true;
- StringRef DependentName = DeclName.getAsIdentifierInfo()->getName();
+ const StringRef DependentName = DeclName.getAsIdentifierInfo()->getName();
- if (NameLookup Resolved = findDeclInBases(
+ if (const NameLookup Resolved = findDeclInBases(
*Base, DependentName, AggressiveDependentMemberLookup)) {
if (*Resolved)
Check->addUsage(*Resolved,
@@ -370,7 +371,7 @@ public:
const IdentifierInfo *II = FD->getIdentifier();
if (!II)
continue;
- SourceRange FixLocation{D.getFieldLoc(), D.getFieldLoc()};
+ const SourceRange FixLocation{D.getFieldLoc(), D.getFieldLoc()};
Check->addUsage(FD, FixLocation, SM);
}
@@ -473,7 +474,8 @@ void RenamerClangTidyCheck::addUsage(const NamedDecl *Decl,
if (!MaybeFailure)
return;
- NamingCheckId FailureId(FailureDecl->getLocation(), FailureDecl->getName());
+ const NamingCheckId FailureId(FailureDecl->getLocation(),
+ FailureDecl->getName());
auto [FailureIter, NewFailure] = addUsage(FailureId, UsageRange, SourceMgr);
@@ -527,10 +529,10 @@ void RenamerClangTidyCheck::checkMacro(const Token &MacroNameTok,
if (!MaybeFailure)
return;
FailureInfo &Info = *MaybeFailure;
- StringRef Name = MacroNameTok.getIdentifierInfo()->getName();
- NamingCheckId ID(MI->getDefinitionLoc(), Name);
+ const StringRef Name = MacroNameTok.getIdentifierInfo()->getName();
+ const NamingCheckId ID(MI->getDefinitionLoc(), Name);
NamingCheckFailure &Failure = NamingCheckFailures[ID];
- SourceRange Range(MacroNameTok.getLocation(), MacroNameTok.getEndLoc());
+ const SourceRange Range(MacroNameTok.getLocation(), MacroNameTok.getEndLoc());
if (!isValidAsciiIdentifier(Info.Fixup))
Failure.FixStatus = ShouldFixStatus::FixInvalidIdentifier;
@@ -542,14 +544,14 @@ void RenamerClangTidyCheck::checkMacro(const Token &MacroNameTok,
void RenamerClangTidyCheck::expandMacro(const Token &MacroNameTok,
const MacroInfo *MI,
const SourceManager &SourceMgr) {
- StringRef Name = MacroNameTok.getIdentifierInfo()->getName();
- NamingCheckId ID(MI->getDefinitionLoc(), Name);
+ const StringRef Name = MacroNameTok.getIdentifierInfo()->getName();
+ const NamingCheckId ID(MI->getDefinitionLoc(), Name);
auto Failure = NamingCheckFailures.find(ID);
if (Failure == NamingCheckFailures.end())
return;
- SourceRange Range(MacroNameTok.getLocation(), MacroNameTok.getEndLoc());
+ const SourceRange Range(MacroNameTok.getLocation(), MacroNameTok.getEndLoc());
addUsage(ID, Range, SourceMgr);
}
diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h
index b38bc08..fe1059d5 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_RENAMERCLANGTIDYCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_RENAMERCLANGTIDYCHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_RENAMERCLANGTIDYCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_RENAMERCLANGTIDYCHECK_H
#include "../ClangTidyCheck.h"
#include "llvm/ADT/DenseMap.h"
@@ -167,4 +167,4 @@ private:
} // namespace tidy
} // namespace clang
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_RENAMERCLANGTIDYCHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_RENAMERCLANGTIDYCHECK_H
diff --git a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
index 87602d1..6fa62302 100644
--- a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
@@ -9,7 +9,6 @@
#include "TransformerClangTidyCheck.h"
#include "clang/Basic/DiagnosticIDs.h"
#include "clang/Lex/Preprocessor.h"
-#include "llvm/ADT/STLExtras.h"
#include <optional>
namespace clang::tidy::utils {
@@ -66,7 +65,7 @@ TransformerClangTidyCheck::TransformerClangTidyCheck(StringRef Name,
// we would be accessing `getLangOpts` and `Options` before the underlying
// `ClangTidyCheck` instance was properly initialized.
TransformerClangTidyCheck::TransformerClangTidyCheck(
- std::function<std::optional<RewriteRuleWith<std::string>>(
+ llvm::function_ref<std::optional<RewriteRuleWith<std::string>>(
const LangOptions &, const OptionsView &)>
MakeRule,
StringRef Name, ClangTidyContext *Context)
@@ -105,7 +104,7 @@ void TransformerClangTidyCheck::check(
if (Result.Context->getDiagnostics().hasErrorOccurred())
return;
- size_t I = transformer::detail::findSelectedCase(Result, Rule);
+ const size_t I = transformer::detail::findSelectedCase(Result, Rule);
Expected<SmallVector<transformer::Edit, 1>> Edits =
Rule.Cases[I].Edits(Result);
if (!Edits) {
@@ -127,7 +126,7 @@ void TransformerClangTidyCheck::check(
// Associate the diagnostic with the location of the first change.
{
- DiagnosticBuilder Diag =
+ const DiagnosticBuilder Diag =
diag((*Edits)[0].Range.getBegin(), escapeForDiagnostic(*Explanation));
for (const auto &T : *Edits) {
switch (T.Kind) {
diff --git a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
index ad20fbd..da8606f 100644
--- a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
+++ b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_TRANSFORMER_CLANG_TIDY_CHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_TRANSFORMER_CLANG_TIDY_CHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_TRANSFORMERCLANGTIDYCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_TRANSFORMERCLANGTIDYCHECK_H
#include "../ClangTidyCheck.h"
#include "IncludeInserter.h"
@@ -48,8 +48,9 @@ public:
///
/// See \c setRule for constraints on the rule.
TransformerClangTidyCheck(
- std::function<std::optional<transformer::RewriteRuleWith<std::string>>(
- const LangOptions &, const OptionsView &)>
+ llvm::function_ref<
+ std::optional<transformer::RewriteRuleWith<std::string>>(
+ const LangOptions &, const OptionsView &)>
MakeRule,
StringRef Name, ClangTidyContext *Context);
@@ -83,4 +84,4 @@ private:
} // namespace clang::tidy::utils
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_TRANSFORMER_CLANG_TIDY_CHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_TRANSFORMERCLANGTIDYCHECK_H
diff --git a/clang-tools-extra/clang-tidy/utils/TypeTraits.cpp b/clang-tools-extra/clang-tidy/utils/TypeTraits.cpp
index d4e079f..dde6e9a 100644
--- a/clang-tools-extra/clang-tidy/utils/TypeTraits.cpp
+++ b/clang-tools-extra/clang-tidy/utils/TypeTraits.cpp
@@ -24,11 +24,9 @@ static bool hasDeletedCopyConstructor(QualType Type) {
auto *Record = Type->getAsCXXRecordDecl();
if (!Record || !Record->hasDefinition())
return false;
- for (const auto *Constructor : Record->ctors()) {
- if (Constructor->isCopyConstructor() && Constructor->isDeleted())
- return true;
- }
- return false;
+ return llvm::any_of(Record->ctors(), [](const auto *Constructor) {
+ return Constructor->isCopyConstructor() && Constructor->isDeleted();
+ });
}
std::optional<bool> isExpensiveToCopy(QualType Type,
@@ -70,14 +68,10 @@ bool recordIsTriviallyDefaultConstructible(const RecordDecl &RecordDecl,
return false;
}
// If all its direct bases are trivially constructible.
- for (const CXXBaseSpecifier &Base : ClassDecl->bases()) {
- if (!isTriviallyDefaultConstructible(Base.getType(), Context))
- return false;
- if (Base.isVirtual())
- return false;
- }
-
- return true;
+ return llvm::all_of(ClassDecl->bases(), [&](const CXXBaseSpecifier &Base) {
+ return isTriviallyDefaultConstructible(Base.getType(), Context) &&
+ !Base.isVirtual();
+ });
}
// Based on QualType::isTrivial.
@@ -111,7 +105,7 @@ bool isTriviallyDefaultConstructible(QualType Type, const ASTContext &Context) {
}
}
- QualType CanonicalType = Type.getCanonicalType();
+ const QualType CanonicalType = Type.getCanonicalType();
if (CanonicalType->isDependentType())
return false;
diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
index cb14951..ab584cb 100644
--- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
@@ -55,7 +55,7 @@ AST_MATCHER(Expr, hasSideEffects) {
} // namespace
static auto
-makeExprMatcher(ast_matchers::internal::Matcher<Expr> ArgumentMatcher,
+makeExprMatcher(const ast_matchers::internal::Matcher<Expr> &ArgumentMatcher,
ArrayRef<StringRef> MethodNames,
ArrayRef<StringRef> FreeNames) {
return expr(
@@ -73,7 +73,7 @@ makeMatcherPair(StringRef State, const UseRangesCheck::Indexes &Indexes,
const std::optional<UseRangesCheck::ReverseIteratorDescriptor>
&ReverseDescriptor) {
std::string ArgBound = (ArgName + llvm::Twine(Indexes.BeginArg)).str();
- SmallString<64> ID = {BoundCall, State};
+ const SmallString<64> ID = {BoundCall, State};
ast_matchers::internal::Matcher<CallExpr> ArgumentMatcher = allOf(
hasArgument(Indexes.BeginArg,
makeExprMatcher(expr(unless(hasSideEffects())).bind(ArgBound),
@@ -84,9 +84,9 @@ makeMatcherPair(StringRef State, const UseRangesCheck::Indexes &Indexes,
{"end", "cend"}, EndFreeNames)));
if (ReverseDescriptor) {
ArgBound.push_back('R');
- SmallVector<StringRef> RBegin{
+ const SmallVector<StringRef> RBegin{
llvm::make_first_range(ReverseDescriptor->FreeReverseNames)};
- SmallVector<StringRef> REnd{
+ const SmallVector<StringRef> REnd{
llvm::make_second_range(ReverseDescriptor->FreeReverseNames)};
ArgumentMatcher = anyOf(
ArgumentMatcher,
@@ -110,9 +110,9 @@ void UseRangesCheck::registerMatchers(MatchFinder *Finder) {
auto Replaces = getReplacerMap();
ReverseDescriptor = getReverseDescriptor();
auto BeginEndNames = getFreeBeginEndMethods();
- llvm::SmallVector<StringRef, 4> BeginNames{
+ const llvm::SmallVector<StringRef, 4> BeginNames{
llvm::make_first_range(BeginEndNames)};
- llvm::SmallVector<StringRef, 4> EndNames{
+ const llvm::SmallVector<StringRef, 4> EndNames{
llvm::make_second_range(BeginEndNames)};
Replacers.clear();
llvm::DenseSet<Replacer *> SeenRepl;
@@ -169,7 +169,7 @@ static void removeFunctionArgs(DiagnosticBuilder &Diag, const CallExpr &Call,
llvm::SmallBitVector Commas(Call.getNumArgs());
// The first comma is actually the '(' which we can't remove
Commas[0] = true;
- for (unsigned Index : Sorted) {
+ for (const unsigned Index : Sorted) {
const Expr *Arg = Call.getArg(Index);
if (Commas[Index]) {
if (Index >= Commas.size()) {
@@ -192,14 +192,14 @@ static void removeFunctionArgs(DiagnosticBuilder &Diag, const CallExpr &Call,
}
void UseRangesCheck::check(const MatchFinder::MatchResult &Result) {
- Replacer *Replacer = nullptr;
+ const Replacer *Replacer = nullptr;
const FunctionDecl *Function = nullptr;
for (const auto &[Node, Value] : Result.Nodes.getMap()) {
StringRef NodeStr(Node);
if (!NodeStr.consume_front(FuncDecl))
continue;
Function = Value.get<FunctionDecl>();
- size_t Index;
+ size_t Index = 0;
if (NodeStr.getAsInteger(10, Index)) {
llvm_unreachable("Unable to extract replacer index");
}
@@ -254,7 +254,7 @@ void UseRangesCheck::check(const MatchFinder::MatchResult &Result) {
Diag << Inserter.createIncludeInsertion(
Result.SourceManager->getFileID(Call->getBeginLoc()),
*ReverseDescriptor->ReverseHeader);
- StringRef ArgText = Lexer::getSourceText(
+ const StringRef ArgText = Lexer::getSourceText(
CharSourceRange::getTokenRange(ArgExpr->getSourceRange()),
Result.Context->getSourceManager(), Result.Context->getLangOpts());
SmallString<128> ReplaceText;
diff --git a/clang-tools-extra/clang-tidy/utils/UsingInserter.cpp b/clang-tools-extra/clang-tidy/utils/UsingInserter.cpp
index e4c71aa..6a591c1 100644
--- a/clang-tools-extra/clang-tidy/utils/UsingInserter.cpp
+++ b/clang-tools-extra/clang-tidy/utils/UsingInserter.cpp
@@ -19,7 +19,7 @@ namespace clang::tidy::utils {
using namespace ast_matchers;
static StringRef getUnqualifiedName(StringRef QualifiedName) {
- size_t LastSeparatorPos = QualifiedName.rfind("::");
+ const size_t LastSeparatorPos = QualifiedName.rfind("::");
if (LastSeparatorPos == StringRef::npos)
return QualifiedName;
return QualifiedName.drop_front(LastSeparatorPos + 2);
@@ -30,7 +30,7 @@ UsingInserter::UsingInserter(const SourceManager &SourceMgr)
std::optional<FixItHint> UsingInserter::createUsingDeclaration(
ASTContext &Context, const Stmt &Statement, StringRef QualifiedName) {
- StringRef UnqualifiedName = getUnqualifiedName(QualifiedName);
+ const StringRef UnqualifiedName = getUnqualifiedName(QualifiedName);
const FunctionDecl *Function = getSurroundingFunction(Context, Statement);
if (!Function)
return std::nullopt;
@@ -38,7 +38,7 @@ std::optional<FixItHint> UsingInserter::createUsingDeclaration(
if (AddedUsing.count(std::make_pair(Function, QualifiedName.str())) != 0)
return std::nullopt;
- SourceLocation InsertLoc = Lexer::getLocForEndOfToken(
+ const SourceLocation InsertLoc = Lexer::getLocForEndOfToken(
Function->getBody()->getBeginLoc(), 0, SourceMgr, Context.getLangOpts());
// Only use using declarations in the main file, not in includes.
@@ -47,7 +47,7 @@ std::optional<FixItHint> UsingInserter::createUsingDeclaration(
// FIXME: This declaration could be masked. Investigate if
// there is a way to avoid using Sema.
- bool AlreadyHasUsingDecl =
+ const bool AlreadyHasUsingDecl =
!match(stmt(hasAncestor(decl(has(usingDecl(hasAnyUsingShadowDecl(
hasTargetDecl(hasName(QualifiedName.str())))))))),
Statement, Context)
@@ -58,15 +58,15 @@ std::optional<FixItHint> UsingInserter::createUsingDeclaration(
}
// Find conflicting declarations and references.
auto ConflictingDecl = namedDecl(hasName(UnqualifiedName));
- bool HasConflictingDeclaration =
+ const bool HasConflictingDeclaration =
!match(findAll(ConflictingDecl), *Function, Context).empty();
- bool HasConflictingDeclRef =
+ const bool HasConflictingDeclRef =
!match(findAll(declRefExpr(to(ConflictingDecl))), *Function, Context)
.empty();
if (HasConflictingDeclaration || HasConflictingDeclRef)
return std::nullopt;
- std::string Declaration =
+ const std::string Declaration =
(llvm::Twine("\nusing ") + QualifiedName + ";").str();
AddedUsing.emplace(Function, QualifiedName.str());
diff --git a/clang-tools-extra/clang-tidy/utils/UsingInserter.h b/clang-tools-extra/clang-tidy/utils/UsingInserter.h
index 23c3175..3e94356 100644
--- a/clang-tools-extra/clang-tidy/utils/UsingInserter.h
+++ b/clang-tools-extra/clang-tidy/utils/UsingInserter.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_USINGINSERTER_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_USINGINSERTER_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_USINGINSERTER_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_USINGINSERTER_H
#include "clang/AST/Decl.h"
#include "clang/AST/Stmt.h"
@@ -43,4 +43,4 @@ private:
};
} // namespace clang::tidy::utils
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_USINGINSERTER_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_USINGINSERTER_H
diff --git a/clang-tools-extra/clangd/CMakeLists.txt b/clang-tools-extra/clangd/CMakeLists.txt
index fb3f053..d7ec853 100644
--- a/clang-tools-extra/clangd/CMakeLists.txt
+++ b/clang-tools-extra/clangd/CMakeLists.txt
@@ -165,6 +165,7 @@ clang_target_link_libraries(clangDaemon
clangBasic
clangDependencyScanning
clangDriver
+ clangOptions
clangFormat
clangFrontend
clangIndex
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 0f765e9..1518f17 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -456,7 +456,6 @@ private:
ClangdLSPServer &Server;
};
-constexpr int ClangdLSPServer::MessageHandler::MaxReplayCallbacks;
// call(), notify(), and reply() wrap the Transport, adding logging and locking.
void ClangdLSPServer::callMethod(StringRef Method, llvm::json::Value Params,
@@ -555,6 +554,8 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
if (const auto &Dir = Params.initializationOptions.compilationDatabasePath)
CDBOpts.CompileCommandsDir = Dir;
CDBOpts.ContextProvider = Opts.ContextProvider;
+ if (Opts.StrongWorkspaceMode)
+ CDBOpts.applyFallbackWorkingDirectory(Opts.WorkspaceRoot);
BaseCDB =
std::make_unique<DirectoryBasedGlobalCompilationDatabase>(CDBOpts);
}
diff --git a/clang-tools-extra/clangd/ClangdServer.h b/clang-tools-extra/clangd/ClangdServer.h
index 4a1eae1..d45d13f 100644
--- a/clang-tools-extra/clangd/ClangdServer.h
+++ b/clang-tools-extra/clangd/ClangdServer.h
@@ -152,6 +152,11 @@ public:
/// FIXME: If not set, should use the current working directory.
std::optional<std::string> WorkspaceRoot;
+ /// Sets an alternate mode of operation. Current effects are:
+ /// - Using the current working directory as the working directory for
+ /// fallback commands
+ bool StrongWorkspaceMode;
+
/// The resource directory is used to find internal headers, overriding
/// defaults and -resource-dir compiler flag).
/// If std::nullopt, ClangdServer calls
diff --git a/clang-tools-extra/clangd/CompileCommands.cpp b/clang-tools-extra/clangd/CompileCommands.cpp
index c1be937..4eda330 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -11,8 +11,8 @@
#include "support/Logger.h"
#include "support/Trace.h"
#include "clang/Driver/Driver.h"
-#include "clang/Driver/Options.h"
#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Options/Options.h"
#include "clang/Tooling/CompilationDatabase.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/ADT/ArrayRef.h"
@@ -132,8 +132,7 @@ std::optional<std::string> detectSysroot() {
std::string detectStandardResourceDir() {
static int StaticForMainAddr; // Just an address in this process.
- return CompilerInvocation::GetResourcesPath("clangd",
- (void *)&StaticForMainAddr);
+ return GetResourcesPath("clangd", (void *)&StaticForMainAddr);
}
// The path passed to argv[0] is important:
@@ -206,7 +205,7 @@ void CommandMangler::operator()(tooling::CompileCommand &Command,
if (Cmd.empty())
return;
- auto &OptTable = clang::driver::getDriverOptTable();
+ auto &OptTable = getDriverOptTable();
// OriginalArgs needs to outlive ArgList.
llvm::SmallVector<const char *, 16> OriginalArgs;
OriginalArgs.reserve(Cmd.size());
@@ -222,8 +221,8 @@ void CommandMangler::operator()(tooling::CompileCommand &Command,
llvm::opt::InputArgList ArgList;
ArgList = OptTable.ParseArgs(
llvm::ArrayRef(OriginalArgs).drop_front(), IgnoredCount, IgnoredCount,
- llvm::opt::Visibility(IsCLMode ? driver::options::CLOption
- : driver::options::ClangOption));
+ llvm::opt::Visibility(IsCLMode ? options::CLOption
+ : options::ClangOption));
llvm::SmallVector<unsigned, 1> IndicesToDrop;
// Having multiple architecture options (e.g. when building fat binaries)
@@ -232,7 +231,7 @@ void CommandMangler::operator()(tooling::CompileCommand &Command,
// As there are no signals to figure out which one user actually wants. They
// can explicitly specify one through `CompileFlags.Add` if need be.
unsigned ArchOptCount = 0;
- for (auto *Input : ArgList.filtered(driver::options::OPT_arch)) {
+ for (auto *Input : ArgList.filtered(options::OPT_arch)) {
++ArchOptCount;
for (auto I = 0U; I <= Input->getNumValues(); ++I)
IndicesToDrop.push_back(Input->getIndex() + I);
@@ -262,13 +261,12 @@ void CommandMangler::operator()(tooling::CompileCommand &Command,
// explicitly at the end of the flags. This ensures modifications done in the
// following steps apply in more cases (like setting -x, which only affects
// inputs that come after it).
- for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT)) {
+ for (auto *Input : ArgList.filtered(options::OPT_INPUT)) {
SawInput(Input->getValue(0));
IndicesToDrop.push_back(Input->getIndex());
}
// Anything after `--` is also treated as input, drop them as well.
- if (auto *DashDash =
- ArgList.getLastArgNoClaim(driver::options::OPT__DASH_DASH)) {
+ if (auto *DashDash = ArgList.getLastArgNoClaim(options::OPT__DASH_DASH)) {
auto DashDashIndex = DashDash->getIndex() + 1; // +1 accounts for Cmd[0]
// Another +1 so we don't treat the `--` itself as an input.
for (unsigned I = DashDashIndex + 1; I < Cmd.size(); ++I)
@@ -424,11 +422,11 @@ DriverMode getDriverMode(const std::vector<std::string> &Args) {
// Returns the set of DriverModes where an option may be used.
unsigned char getModes(const llvm::opt::Option &Opt) {
unsigned char Result = DM_None;
- if (Opt.hasVisibilityFlag(driver::options::ClangOption))
+ if (Opt.hasVisibilityFlag(options::ClangOption))
Result |= DM_GCC;
- if (Opt.hasVisibilityFlag(driver::options::CC1Option))
+ if (Opt.hasVisibilityFlag(options::CC1Option))
Result |= DM_CC1;
- if (Opt.hasVisibilityFlag(driver::options::CLOption))
+ if (Opt.hasVisibilityFlag(options::CLOption))
Result |= DM_CL;
return Result;
}
@@ -442,8 +440,8 @@ llvm::ArrayRef<ArgStripper::Rule> ArgStripper::rulesFor(llvm::StringRef Arg) {
using TableTy =
llvm::StringMap<llvm::SmallVector<Rule, 4>, llvm::BumpPtrAllocator>;
static TableTy *Table = [] {
- auto &DriverTable = driver::getDriverOptTable();
- using DriverID = clang::driver::options::ID;
+ auto &DriverTable = getDriverOptTable();
+ using DriverID = clang::options::ID;
// Collect sets of aliases, so we can treat -foo and -foo= as synonyms.
// Conceptually a double-linked list: PrevAlias[I] -> I -> NextAlias[I].
@@ -468,7 +466,7 @@ llvm::ArrayRef<ArgStripper::Rule> ArgStripper::rulesFor(llvm::StringRef Arg) {
FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS, \
METAVAR, VALUES, SUBCOMMANDIDS_OFFSET) \
{DriverID::OPT_##ID, DriverID::OPT_##ALIAS, ALIASARGS},
-#include "clang/Driver/Options.inc"
+#include "clang/Options/Options.inc"
#undef OPTION
};
for (auto &E : AliasTable)
diff --git a/clang-tools-extra/clangd/Compiler.cpp b/clang-tools-extra/clangd/Compiler.cpp
index 6ebc2ea..9ea7df13 100644
--- a/clang-tools-extra/clangd/Compiler.cpp
+++ b/clang-tools-extra/clangd/Compiler.cpp
@@ -9,6 +9,7 @@
#include "Compiler.h"
#include "support/Logger.h"
#include "clang/Basic/TargetInfo.h"
+#include "clang/Driver/CreateInvocationFromArgs.h"
#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Lex/PreprocessorOptions.h"
#include "clang/Serialization/PCHContainerOperations.h"
diff --git a/clang-tools-extra/clangd/FileDistance.cpp b/clang-tools-extra/clangd/FileDistance.cpp
index 06c1a8b..d587c26 100644
--- a/clang-tools-extra/clangd/FileDistance.cpp
+++ b/clang-tools-extra/clangd/FileDistance.cpp
@@ -54,7 +54,6 @@ static llvm::SmallString<128> canonicalize(llvm::StringRef Path) {
return Result;
}
-constexpr const unsigned FileDistance::Unreachable;
const llvm::hash_code FileDistance::RootHash =
llvm::hash_value(llvm::StringRef("/"));
diff --git a/clang-tools-extra/clangd/FuzzyMatch.cpp b/clang-tools-extra/clangd/FuzzyMatch.cpp
index de7280d..cf5182b 100644
--- a/clang-tools-extra/clangd/FuzzyMatch.cpp
+++ b/clang-tools-extra/clangd/FuzzyMatch.cpp
@@ -62,9 +62,6 @@
namespace clang {
namespace clangd {
-constexpr int FuzzyMatcher::MaxPat;
-constexpr int FuzzyMatcher::MaxWord;
-
static char lower(char C) { return C >= 'A' && C <= 'Z' ? C + ('a' - 'A') : C; }
// A "negative infinity" score that won't overflow.
// We use this to mark unreachable states and forbidden solutions.
diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
index c6afd0b..d229a71 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -64,7 +64,9 @@ GlobalCompilationDatabase::getFallbackCommand(PathRef File) const {
if (FileExtension.empty() || FileExtension == ".h")
Argv.push_back("-xobjective-c++-header");
Argv.push_back(std::string(File));
- tooling::CompileCommand Cmd(llvm::sys::path::parent_path(File),
+ tooling::CompileCommand Cmd(FallbackWorkingDirectory
+ ? *FallbackWorkingDirectory
+ : llvm::sys::path::parent_path(File),
llvm::sys::path::filename(File), std::move(Argv),
/*Output=*/"");
Cmd.Heuristic = "clangd fallback";
@@ -349,7 +351,8 @@ bool DirectoryBasedGlobalCompilationDatabase::DirectoryCache::load(
DirectoryBasedGlobalCompilationDatabase::
DirectoryBasedGlobalCompilationDatabase(const Options &Opts)
- : Opts(Opts), Broadcaster(std::make_unique<BroadcastThread>(*this)) {
+ : GlobalCompilationDatabase(Opts.FallbackWorkingDirectory), Opts(Opts),
+ Broadcaster(std::make_unique<BroadcastThread>(*this)) {
if (!this->Opts.ContextProvider)
this->Opts.ContextProvider = [](llvm::StringRef) {
return Context::current().clone();
@@ -460,6 +463,21 @@ DirectoryBasedGlobalCompilationDatabase::lookupCDB(
return Result;
}
+void DirectoryBasedGlobalCompilationDatabase::Options::
+ applyFallbackWorkingDirectory(
+ std::optional<std::string> FallbackWorkingDirectory) {
+ if (FallbackWorkingDirectory)
+ this->FallbackWorkingDirectory = *FallbackWorkingDirectory;
+ else {
+ // Clangd is running in strong workspace mode but the client didn't
+ // specify a workspace path in the `initialize` request.
+ // Fallback to current working directory.
+ SmallString<256> CWD;
+ llvm::sys::fs::current_path(CWD);
+ this->FallbackWorkingDirectory = std::string(CWD);
+ }
+}
+
// The broadcast thread announces files with new compile commands to the world.
// Primarily this is used to enqueue them for background indexing.
//
@@ -759,9 +777,10 @@ DirectoryBasedGlobalCompilationDatabase::getProjectModules(PathRef File) const {
OverlayCDB::OverlayCDB(const GlobalCompilationDatabase *Base,
std::vector<std::string> FallbackFlags,
- CommandMangler Mangler)
- : DelegatingCDB(Base), Mangler(std::move(Mangler)),
- FallbackFlags(std::move(FallbackFlags)) {}
+ CommandMangler Mangler,
+ std::optional<std::string> FallbackWorkingDirectory)
+ : DelegatingCDB(Base, FallbackWorkingDirectory),
+ Mangler(std::move(Mangler)), FallbackFlags(std::move(FallbackFlags)) {}
std::optional<tooling::CompileCommand>
OverlayCDB::getCompileCommand(PathRef File) const {
@@ -844,16 +863,20 @@ OverlayCDB::getProjectModules(PathRef File) const {
return MDB;
}
-DelegatingCDB::DelegatingCDB(const GlobalCompilationDatabase *Base)
- : Base(Base) {
+DelegatingCDB::DelegatingCDB(
+ const GlobalCompilationDatabase *Base,
+ std::optional<std::string> FallbackWorkingDirectory)
+ : GlobalCompilationDatabase(FallbackWorkingDirectory), Base(Base) {
if (Base)
BaseChanged = Base->watch([this](const std::vector<std::string> Changes) {
OnCommandChanged.broadcast(Changes);
});
}
-DelegatingCDB::DelegatingCDB(std::unique_ptr<GlobalCompilationDatabase> Base)
- : DelegatingCDB(Base.get()) {
+DelegatingCDB::DelegatingCDB(
+ std::unique_ptr<GlobalCompilationDatabase> Base,
+ std::optional<std::string> FallbackWorkingDirectory)
+ : DelegatingCDB(Base.get(), FallbackWorkingDirectory) {
BaseOwner = std::move(Base);
}
diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.h b/clang-tools-extra/clangd/GlobalCompilationDatabase.h
index 1d636d7..415c7f5 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.h
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.h
@@ -35,6 +35,9 @@ struct ProjectInfo {
/// Provides compilation arguments used for parsing C and C++ files.
class GlobalCompilationDatabase {
public:
+ GlobalCompilationDatabase(
+ std::optional<std::string> FallbackWorkingDirectory = std::nullopt)
+ : FallbackWorkingDirectory(FallbackWorkingDirectory) {}
virtual ~GlobalCompilationDatabase() = default;
/// If there are any known-good commands for building this file, returns one.
@@ -69,14 +72,19 @@ public:
}
protected:
+ std::optional<std::string> FallbackWorkingDirectory;
mutable CommandChanged OnCommandChanged;
};
// Helper class for implementing GlobalCompilationDatabases that wrap others.
class DelegatingCDB : public GlobalCompilationDatabase {
public:
- DelegatingCDB(const GlobalCompilationDatabase *Base);
- DelegatingCDB(std::unique_ptr<GlobalCompilationDatabase> Base);
+ DelegatingCDB(
+ const GlobalCompilationDatabase *Base,
+ std::optional<std::string> FallbackWorkingDirectory = std::nullopt);
+ DelegatingCDB(
+ std::unique_ptr<GlobalCompilationDatabase> Base,
+ std::optional<std::string> FallbackWorkingDirectory = std::nullopt);
std::optional<tooling::CompileCommand>
getCompileCommand(PathRef File) const override;
@@ -117,6 +125,12 @@ public:
// Only look for a compilation database in this one fixed directory.
// FIXME: fold this into config/context mechanism.
std::optional<Path> CompileCommandsDir;
+ // Working directory for fallback commands
+ // If unset, parent directory of file should be used
+ std::optional<std::string> FallbackWorkingDirectory;
+
+ void applyFallbackWorkingDirectory(
+ std::optional<std::string> FallbackWorkingDirectory);
};
DirectoryBasedGlobalCompilationDatabase(const Options &Opts);
@@ -194,9 +208,11 @@ public:
// Base may be null, in which case no entries are inherited.
// FallbackFlags are added to the fallback compile command.
// Adjuster is applied to all commands, fallback or not.
- OverlayCDB(const GlobalCompilationDatabase *Base,
- std::vector<std::string> FallbackFlags = {},
- CommandMangler Mangler = nullptr);
+ OverlayCDB(
+ const GlobalCompilationDatabase *Base,
+ std::vector<std::string> FallbackFlags = {},
+ CommandMangler Mangler = nullptr,
+ std::optional<std::string> FallbackWorkingDirectory = std::nullopt);
std::optional<tooling::CompileCommand>
getCompileCommand(PathRef File) const override;
diff --git a/clang-tools-extra/clangd/ScanningProjectModules.cpp b/clang-tools-extra/clangd/ScanningProjectModules.cpp
index 672e996..e1b6cbe1 100644
--- a/clang-tools-extra/clangd/ScanningProjectModules.cpp
+++ b/clang-tools-extra/clangd/ScanningProjectModules.cpp
@@ -8,8 +8,8 @@
#include "ProjectModules.h"
#include "support/Logger.h"
-#include "clang/Tooling/DependencyScanning/DependencyScanningService.h"
-#include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
+#include "clang/DependencyScanning/DependencyScanningService.h"
+#include "clang/Tooling/DependencyScanningTool.h"
namespace clang::clangd {
namespace {
@@ -36,8 +36,8 @@ public:
std::shared_ptr<const clang::tooling::CompilationDatabase> CDB,
const ThreadsafeFS &TFS)
: CDB(CDB), TFS(TFS),
- Service(tooling::dependencies::ScanningMode::CanonicalPreprocessing,
- tooling::dependencies::ScanningOutputFormat::P1689) {}
+ Service(dependencies::ScanningMode::CanonicalPreprocessing,
+ dependencies::ScanningOutputFormat::P1689) {}
/// The scanned modules dependency information for a specific source file.
struct ModuleDependencyInfo {
@@ -81,7 +81,7 @@ private:
// Whether the scanner has scanned the project globally.
bool GlobalScanned = false;
- clang::tooling::dependencies::DependencyScanningService Service;
+ clang::dependencies::DependencyScanningService Service;
// TODO: Add a scanning cache.
@@ -104,7 +104,7 @@ ModuleDependencyScanner::scan(PathRef FilePath,
if (Mangler)
Mangler(Cmd, FilePath);
- using namespace clang::tooling::dependencies;
+ using namespace clang::tooling;
llvm::SmallString<128> FilePathDir(FilePath);
llvm::sys::path::remove_filename(FilePathDir);
diff --git a/clang-tools-extra/clangd/Selection.cpp b/clang-tools-extra/clangd/Selection.cpp
index 06165df..faa00d2 100644
--- a/clang-tools-extra/clangd/Selection.cpp
+++ b/clang-tools-extra/clangd/Selection.cpp
@@ -958,6 +958,18 @@ private:
claimRange(SourceRange(FTL.getLParenLoc(), FTL.getEndLoc()), Result);
return;
}
+ if (auto ATL = TL->getAs<AttributedTypeLoc>()) {
+ // For attributed function types like `int foo() [[attr]]`, the
+ // AttributedTypeLoc's range includes the function name. We want to
+ // allow the function name to be associated with the FunctionDecl
+ // rather than the AttributedTypeLoc, so we only claim the attribute
+ // range itself.
+ if (ATL.getModifiedLoc().getAs<FunctionTypeLoc>()) {
+ // Only claim the attribute's source range, not the whole type.
+ claimRange(ATL.getLocalSourceRange(), Result);
+ return;
+ }
+ }
}
claimRange(getSourceRange(N), Result);
}
diff --git a/clang-tools-extra/clangd/SemanticSelection.cpp b/clang-tools-extra/clangd/SemanticSelection.cpp
index 3353121..71ebf00 100644
--- a/clang-tools-extra/clangd/SemanticSelection.cpp
+++ b/clang-tools-extra/clangd/SemanticSelection.cpp
@@ -11,9 +11,13 @@
#include "Protocol.h"
#include "Selection.h"
#include "SourceCode.h"
+#include "support/Bracket.h"
+#include "support/DirectiveTree.h"
+#include "support/Token.h"
#include "clang/AST/DeclBase.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TokenKinds.h"
#include "clang/Tooling/Syntax/BuildTree.h"
#include "clang/Tooling/Syntax/Nodes.h"
#include "clang/Tooling/Syntax/TokenBufferTokenManager.h"
@@ -22,9 +26,6 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Error.h"
-#include "support/Bracket.h"
-#include "support/DirectiveTree.h"
-#include "support/Token.h"
#include <optional>
#include <queue>
#include <vector>
@@ -41,72 +42,6 @@ void addIfDistinct(const Range &R, std::vector<Range> &Result) {
}
}
-std::optional<FoldingRange> toFoldingRange(SourceRange SR,
- const SourceManager &SM) {
- const auto Begin = SM.getDecomposedLoc(SR.getBegin()),
- End = SM.getDecomposedLoc(SR.getEnd());
- // Do not produce folding ranges if either range ends is not within the main
- // file. Macros have their own FileID so this also checks if locations are not
- // within the macros.
- if ((Begin.first != SM.getMainFileID()) || (End.first != SM.getMainFileID()))
- return std::nullopt;
- FoldingRange Range;
- Range.startCharacter = SM.getColumnNumber(Begin.first, Begin.second) - 1;
- Range.startLine = SM.getLineNumber(Begin.first, Begin.second) - 1;
- Range.endCharacter = SM.getColumnNumber(End.first, End.second) - 1;
- Range.endLine = SM.getLineNumber(End.first, End.second) - 1;
- return Range;
-}
-
-std::optional<FoldingRange>
-extractFoldingRange(const syntax::Node *Node,
- const syntax::TokenBufferTokenManager &TM) {
- if (const auto *Stmt = dyn_cast<syntax::CompoundStatement>(Node)) {
- const auto *LBrace = cast_or_null<syntax::Leaf>(
- Stmt->findChild(syntax::NodeRole::OpenParen));
- // FIXME(kirillbobyrev): This should find the last child. Compound
- // statements have only one pair of braces so this is valid but for other
- // node kinds it might not be correct.
- const auto *RBrace = cast_or_null<syntax::Leaf>(
- Stmt->findChild(syntax::NodeRole::CloseParen));
- if (!LBrace || !RBrace)
- return std::nullopt;
- // Fold the entire range within braces, including whitespace.
- const SourceLocation LBraceLocInfo =
- TM.getToken(LBrace->getTokenKey())->endLocation(),
- RBraceLocInfo =
- TM.getToken(RBrace->getTokenKey())->location();
- auto Range = toFoldingRange(SourceRange(LBraceLocInfo, RBraceLocInfo),
- TM.sourceManager());
- // Do not generate folding range for compound statements without any
- // nodes and newlines.
- if (Range && Range->startLine != Range->endLine)
- return Range;
- }
- return std::nullopt;
-}
-
-// Traverse the tree and collect folding ranges along the way.
-std::vector<FoldingRange>
-collectFoldingRanges(const syntax::Node *Root,
- const syntax::TokenBufferTokenManager &TM) {
- std::queue<const syntax::Node *> Nodes;
- Nodes.push(Root);
- std::vector<FoldingRange> Result;
- while (!Nodes.empty()) {
- const syntax::Node *Node = Nodes.front();
- Nodes.pop();
- const auto Range = extractFoldingRange(Node, TM);
- if (Range)
- Result.push_back(*Range);
- if (const auto *T = dyn_cast<syntax::Tree>(Node))
- for (const auto *NextNode = T->getFirstChild(); NextNode;
- NextNode = NextNode->getNextSibling())
- Nodes.push(NextNode);
- }
- return Result;
-}
-
} // namespace
llvm::Expected<SelectionRange> getSemanticRanges(ParsedAST &AST, Position Pos) {
@@ -163,17 +98,71 @@ llvm::Expected<SelectionRange> getSemanticRanges(ParsedAST &AST, Position Pos) {
return std::move(Head);
}
-// FIXME(kirillbobyrev): Collect comments, PP conditional regions, includes and
-// other code regions (e.g. public/private/protected sections of classes,
-// control flow statement bodies).
-// Related issue: https://github.com/clangd/clangd/issues/310
-llvm::Expected<std::vector<FoldingRange>> getFoldingRanges(ParsedAST &AST) {
- syntax::Arena A;
- syntax::TokenBufferTokenManager TM(AST.getTokens(), AST.getLangOpts(),
- AST.getSourceManager());
- const auto *SyntaxTree = syntax::buildSyntaxTree(A, TM, AST.getASTContext());
- return collectFoldingRanges(SyntaxTree, TM);
-}
+class PragmaRegionFinder {
+ // Record the token range of a region:
+ //
+ // #pragma region name[[
+ // ...
+ // ]]#pragma endregion
+ std::vector<Token::Range> &Ranges;
+ const TokenStream &Code;
+ // Stack of starting token (the name of the region) indices for nested #pragma
+ // region.
+ std::vector<unsigned> Stack;
+
+public:
+ PragmaRegionFinder(std::vector<Token::Range> &Ranges, const TokenStream &Code)
+ : Ranges(Ranges), Code(Code) {}
+
+ void walk(const DirectiveTree &T) {
+ for (const auto &C : T.Chunks)
+ std::visit(*this, C);
+ }
+
+ void operator()(const DirectiveTree::Code &C) {}
+
+ void operator()(const DirectiveTree::Directive &D) {
+ // Get the tokens that make up this directive.
+ auto Tokens = Code.tokens(D.Tokens);
+ if (Tokens.empty())
+ return;
+ const Token &HashToken = Tokens.front();
+ assert(HashToken.Kind == tok::hash);
+ const Token &Pragma = HashToken.nextNC();
+ if (Pragma.text() != "pragma")
+ return;
+ const Token &Value = Pragma.nextNC();
+
+ // Handle "#pragma region name"
+ if (Value.text() == "region") {
+ // Find the last token at the same line.
+ const Token *T = &Value.next();
+ while (T < Tokens.end() && T->Line == Pragma.Line)
+ T = &T->next();
+ --T;
+ Stack.push_back(T->OriginalIndex);
+ return;
+ }
+
+ // Handle "#pragma endregion"
+ if (Value.text() == "endregion") {
+ if (Stack.empty())
+ return; // unmatched end region; ignore.
+
+ unsigned StartIdx = Stack.back();
+ Stack.pop_back();
+ Ranges.push_back(Token::Range{StartIdx, HashToken.OriginalIndex});
+ }
+ }
+
+ void operator()(const DirectiveTree::Conditional &C) {
+ // C.Branches needs to see the DirectiveTree definition, otherwise build
+ // fails in C++20.
+ [[maybe_unused]] DirectiveTree Dummy;
+ for (const auto &[_, SubTree] : C.Branches)
+ walk(SubTree);
+ }
+};
// FIXME( usaxena95): Collect includes and other code regions (e.g.
// public/private/protected sections of classes, control flow statement bodies).
@@ -286,6 +275,17 @@ getFoldingRanges(const std::string &Code, bool LineFoldingOnly) {
}
AddFoldingRange(Start, End, FoldingRange::COMMENT_KIND);
}
+
+ // #pragma region
+ std::vector<Token::Range> Ranges;
+ PragmaRegionFinder(Ranges, OrigStream).walk(DirectiveStructure);
+ auto Ts = OrigStream.tokens();
+ for (const auto &R : Ranges) {
+ auto End = StartPosition(Ts[R.End]);
+ if (LineFoldingOnly)
+ End.line--;
+ AddFoldingRange(EndPosition(Ts[R.Begin]), End, FoldingRange::REGION_KIND);
+ }
return Result;
}
diff --git a/clang-tools-extra/clangd/SemanticSelection.h b/clang-tools-extra/clangd/SemanticSelection.h
index dd9d3ea..4e19397 100644
--- a/clang-tools-extra/clangd/SemanticSelection.h
+++ b/clang-tools-extra/clangd/SemanticSelection.h
@@ -27,10 +27,6 @@ namespace clangd {
llvm::Expected<SelectionRange> getSemanticRanges(ParsedAST &AST, Position Pos);
/// Returns a list of ranges whose contents might be collapsible in an editor.
-/// This should include large scopes, preprocessor blocks etc.
-llvm::Expected<std::vector<FoldingRange>> getFoldingRanges(ParsedAST &AST);
-
-/// Returns a list of ranges whose contents might be collapsible in an editor.
/// This version uses the pseudoparser which does not require the AST.
llvm::Expected<std::vector<FoldingRange>>
getFoldingRanges(const std::string &Code, bool LineFoldingOnly);
diff --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp
index 1e1f7c6..21c078f 100644
--- a/clang-tools-extra/clangd/SourceCode.cpp
+++ b/clang-tools-extra/clangd/SourceCode.cpp
@@ -1217,6 +1217,26 @@ EligibleRegion getEligiblePoints(llvm::StringRef Code,
return ER;
}
+std::string getNamespaceAtPosition(StringRef Code, const Position &Pos,
+ const LangOptions &LangOpts) {
+ std::vector<std::string> Enclosing = {""};
+ parseNamespaceEvents(Code, LangOpts, [&](NamespaceEvent Event) {
+ if (Pos < Event.Pos)
+ return;
+ if (Event.Trigger == NamespaceEvent::UsingDirective)
+ return;
+ if (!Event.Payload.empty())
+ Event.Payload.append("::");
+ if (Event.Trigger == NamespaceEvent::BeginNamespace) {
+ Enclosing.emplace_back(std::move(Event.Payload));
+ } else {
+ Enclosing.pop_back();
+ assert(Enclosing.back() == Event.Payload);
+ }
+ });
+ return Enclosing.back();
+}
+
bool isHeaderFile(llvm::StringRef FileName,
std::optional<LangOptions> LangOpts) {
// Respect the langOpts, for non-file-extension cases, e.g. standard library
diff --git a/clang-tools-extra/clangd/SourceCode.h b/clang-tools-extra/clangd/SourceCode.h
index 028549f..274099f 100644
--- a/clang-tools-extra/clangd/SourceCode.h
+++ b/clang-tools-extra/clangd/SourceCode.h
@@ -309,6 +309,11 @@ EligibleRegion getEligiblePoints(llvm::StringRef Code,
llvm::StringRef FullyQualifiedName,
const LangOptions &LangOpts);
+/// Returns the fully qualified name of the namespace at \p Pos in the \p Code.
+/// Employs pseudo-parsing to determine the start and end of namespaces.
+std::string getNamespaceAtPosition(llvm::StringRef Code, const Position &Pos,
+ const LangOptions &LangOpts);
+
struct DefinedMacro {
llvm::StringRef Name;
const MacroInfo *Info;
diff --git a/clang-tools-extra/clangd/index/SymbolLocation.cpp b/clang-tools-extra/clangd/index/SymbolLocation.cpp
index 61da267..058cb1e 100644
--- a/clang-tools-extra/clangd/index/SymbolLocation.cpp
+++ b/clang-tools-extra/clangd/index/SymbolLocation.cpp
@@ -11,9 +11,6 @@
namespace clang {
namespace clangd {
-constexpr uint32_t SymbolLocation::Position::MaxLine;
-constexpr uint32_t SymbolLocation::Position::MaxColumn;
-
void SymbolLocation::Position::setLine(uint32_t L) {
if (L > MaxLine)
L = MaxLine;
diff --git a/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp b/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
index e4eef22..45e7ade 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "AST.h"
+#include "FindSymbols.h"
#include "FindTarget.h"
#include "HeaderSourceSwitch.h"
#include "ParsedAST.h"
@@ -34,6 +35,7 @@
#include <cstddef>
#include <optional>
#include <string>
+#include <tuple>
namespace clang {
namespace clangd {
@@ -362,6 +364,12 @@ struct InsertionPoint {
size_t Offset;
};
+enum class RelativeInsertPos { Before, After };
+struct InsertionAnchor {
+ Location Loc;
+ RelativeInsertPos RelInsertPos = RelativeInsertPos::Before;
+};
+
// Returns the range that should be deleted from declaration, which always
// contains function body. In addition to that it might contain constructor
// initializers.
@@ -489,8 +497,14 @@ public:
Expected<Effect> apply(const Selection &Sel) override {
const SourceManager &SM = Sel.AST->getSourceManager();
- auto CCFile = SameFile ? Sel.AST->tuPath().str()
- : getSourceFile(Sel.AST->tuPath(), Sel);
+ std::optional<Path> CCFile;
+ auto Anchor = getDefinitionOfAdjacentDecl(Sel);
+ if (Anchor) {
+ CCFile = Anchor->Loc.uri.file();
+ } else {
+ CCFile = SameFile ? Sel.AST->tuPath().str()
+ : getSourceFile(Sel.AST->tuPath(), Sel);
+ }
if (!CCFile)
return error("Couldn't find a suitable implementation file.");
assert(Sel.FS && "FS Must be set in apply");
@@ -499,21 +513,62 @@ public:
// doesn't exist?
if (!Buffer)
return llvm::errorCodeToError(Buffer.getError());
+
auto Contents = Buffer->get()->getBuffer();
- auto InsertionPoint = getInsertionPoint(Contents, Sel);
- if (!InsertionPoint)
- return InsertionPoint.takeError();
+ SourceManagerForFile SMFF(*CCFile, Contents);
+
+ std::optional<Position> InsertionPos;
+ if (Anchor) {
+ if (auto P = getInsertionPointFromExistingDefinition(
+ SMFF, **Buffer, Anchor->Loc, Anchor->RelInsertPos, Sel.AST)) {
+ InsertionPos = *P;
+ }
+ }
+
+ std::optional<std::size_t> Offset;
+ const DeclContext *EnclosingNamespace = nullptr;
+ std::string EnclosingNamespaceName;
+
+ if (InsertionPos) {
+ EnclosingNamespaceName = getNamespaceAtPosition(Contents, *InsertionPos,
+ Sel.AST->getLangOpts());
+ } else if (SameFile) {
+ auto P = getInsertionPointInMainFile(Sel.AST);
+ if (!P)
+ return P.takeError();
+ Offset = P->Offset;
+ EnclosingNamespace = P->EnclosingNamespace;
+ } else {
+ auto Region = getEligiblePoints(
+ Contents, Source->getQualifiedNameAsString(), Sel.AST->getLangOpts());
+ assert(!Region.EligiblePoints.empty());
+ EnclosingNamespaceName = Region.EnclosingNamespace;
+ InsertionPos = Region.EligiblePoints.back();
+ }
+
+ if (InsertionPos) {
+ auto O = positionToOffset(Contents, *InsertionPos);
+ if (!O)
+ return O.takeError();
+ Offset = *O;
+ auto TargetContext =
+ findContextForNS(EnclosingNamespaceName, Source->getDeclContext());
+ if (!TargetContext)
+ return error("define outline: couldn't find a context for target");
+ EnclosingNamespace = *TargetContext;
+ }
+
+ assert(Offset);
+ assert(EnclosingNamespace);
auto FuncDef = getFunctionSourceCode(
- Source, InsertionPoint->EnclosingNamespace, Sel.AST->getTokens(),
+ Source, EnclosingNamespace, Sel.AST->getTokens(),
Sel.AST->getHeuristicResolver(),
SameFile && isHeaderFile(Sel.AST->tuPath(), Sel.AST->getLangOpts()));
if (!FuncDef)
return FuncDef.takeError();
- SourceManagerForFile SMFF(*CCFile, Contents);
- const tooling::Replacement InsertFunctionDef(
- *CCFile, InsertionPoint->Offset, 0, *FuncDef);
+ const tooling::Replacement InsertFunctionDef(*CCFile, *Offset, 0, *FuncDef);
auto Effect = Effect::mainFileEdit(
SMFF.get(), tooling::Replacements(InsertFunctionDef));
if (!Effect)
@@ -548,59 +603,188 @@ public:
return std::move(*Effect);
}
- // Returns the most natural insertion point for \p QualifiedName in \p
- // Contents. This currently cares about only the namespace proximity, but in
- // feature it should also try to follow ordering of declarations. For example,
- // if decls come in order `foo, bar, baz` then this function should return
- // some point between foo and baz for inserting bar.
- // FIXME: The selection can be made smarter by looking at the definition
- // locations for adjacent decls to Source. Unfortunately pseudo parsing in
- // getEligibleRegions only knows about namespace begin/end events so we
- // can't match function start/end positions yet.
- llvm::Expected<InsertionPoint> getInsertionPoint(llvm::StringRef Contents,
- const Selection &Sel) {
- // If the definition goes to the same file and there is a namespace,
- // we should (and, in the case of anonymous namespaces, need to)
- // put the definition into the original namespace block.
- if (SameFile) {
- auto *Klass = Source->getDeclContext()->getOuterLexicalRecordContext();
- if (!Klass)
- return error("moving to same file not supported for free functions");
- const SourceLocation EndLoc = Klass->getBraceRange().getEnd();
- const auto &TokBuf = Sel.AST->getTokens();
- auto Tokens = TokBuf.expandedTokens();
- auto It = llvm::lower_bound(
- Tokens, EndLoc, [](const syntax::Token &Tok, SourceLocation EndLoc) {
- return Tok.location() < EndLoc;
- });
- while (It != Tokens.end()) {
- if (It->kind() != tok::semi) {
- ++It;
- continue;
+ std::optional<InsertionAnchor>
+ getDefinitionOfAdjacentDecl(const Selection &Sel) {
+ if (!Sel.Index)
+ return {};
+ std::optional<Location> Anchor;
+ std::string TuURI = URI::createFile(Sel.AST->tuPath()).toString();
+ auto CheckCandidate = [&](Decl *Candidate) {
+ assert(Candidate != Source);
+ if (auto Func = llvm::dyn_cast_or_null<FunctionDecl>(Candidate);
+ !Func || Func->isThisDeclarationADefinition()) {
+ return;
+ }
+ std::optional<Location> CandidateLoc;
+ Sel.Index->lookup({{getSymbolID(Candidate)}}, [&](const Symbol &S) {
+ if (S.Definition) {
+ if (auto Loc = indexToLSPLocation(S.Definition, Sel.AST->tuPath()))
+ CandidateLoc = *Loc;
+ else
+ log("getDefinitionOfAdjacentDecl: {0}", Loc.takeError());
}
- unsigned Offset = Sel.AST->getSourceManager()
- .getDecomposedLoc(It->endLocation())
- .second;
- return InsertionPoint{Klass->getEnclosingNamespaceContext(), Offset};
+ });
+ if (!CandidateLoc)
+ return;
+
+ // If our definition is constrained to the same file, ignore
+ // definitions that are not located there.
+ // If our definition is not constrained to the same file, but
+ // our anchor definition is in the same file, then we also put our
+ // definition there, because that appears to be the user preference.
+ // Exception: If the existing definition is a template, then the
+ // location is likely due to technical necessity rather than preference,
+ // so ignore that definition.
+ bool CandidateSameFile = TuURI == CandidateLoc->uri.uri();
+ if (SameFile && !CandidateSameFile)
+ return;
+ if (!SameFile && CandidateSameFile) {
+ if (Candidate->isTemplateDecl())
+ return;
+ SameFile = true;
}
- return error(
- "failed to determine insertion location: no end of class found");
+ Anchor = *CandidateLoc;
+ };
+
+ // Try to find adjacent function declarations.
+ // Determine the closest one by alternatingly going "up" and "down"
+ // from our function in increasing steps.
+ const DeclContext *ParentContext = Source->getParent();
+ const auto SourceIt = llvm::find_if(
+ ParentContext->decls(), [this](const Decl *D) { return D == Source; });
+ if (SourceIt == ParentContext->decls_end())
+ return {};
+ const int Preceding = std::distance(ParentContext->decls_begin(), SourceIt);
+ const int Following =
+ std::distance(SourceIt, ParentContext->decls_end()) - 1;
+ for (int Offset = 1; Offset <= Preceding || Offset <= Following; ++Offset) {
+ if (Offset <= Preceding)
+ CheckCandidate(
+ *std::next(ParentContext->decls_begin(), Preceding - Offset));
+ if (Anchor)
+ return InsertionAnchor{*Anchor, RelativeInsertPos::After};
+ if (Offset <= Following)
+ CheckCandidate(*std::next(SourceIt, Offset));
+ if (Anchor)
+ return InsertionAnchor{*Anchor, RelativeInsertPos::Before};
}
+ return {};
+ }
- auto Region = getEligiblePoints(
- Contents, Source->getQualifiedNameAsString(), Sel.AST->getLangOpts());
+ // We don't know the actual start or end of the definition, only the position
+ // of the name. Therefore, we heuristically try to locate the last token
+ // before or in this function, respectively. Adapt as required by user code.
+ std::optional<Position> getInsertionPointFromExistingDefinition(
+ SourceManagerForFile &SMFF, const llvm::MemoryBuffer &Buffer,
+ const Location &Loc, RelativeInsertPos RelInsertPos, ParsedAST *AST) {
+ auto StartOffset = positionToOffset(Buffer.getBuffer(), Loc.range.start);
+ if (!StartOffset)
+ return {};
+ SourceLocation InsertionLoc;
+ SourceManager &SM = SMFF.get();
+
+ auto InsertBefore = [&] {
+ // Go backwards until we encounter one of the following:
+ // - An opening brace (of a namespace).
+ // - A closing brace (of a function definition).
+ // - A semicolon (of a declaration).
+ // If no such token was found, then the first token in the file starts the
+ // definition.
+ auto Tokens = syntax::tokenize(
+ syntax::FileRange(SM.getMainFileID(), 0, *StartOffset), SM,
+ AST->getLangOpts());
+ if (Tokens.empty())
+ return;
+ for (auto I = std::rbegin(Tokens);
+ InsertionLoc.isInvalid() && I != std::rend(Tokens); ++I) {
+ switch (I->kind()) {
+ case tok::l_brace:
+ case tok::r_brace:
+ case tok::semi:
+ if (I != std::rbegin(Tokens))
+ InsertionLoc = std::prev(I)->location();
+ else
+ InsertionLoc = I->endLocation();
+ break;
+ default:
+ break;
+ }
+ }
+ if (InsertionLoc.isInvalid())
+ InsertionLoc = Tokens.front().location();
+ };
- assert(!Region.EligiblePoints.empty());
- auto Offset = positionToOffset(Contents, Region.EligiblePoints.back());
- if (!Offset)
- return Offset.takeError();
+ if (RelInsertPos == RelativeInsertPos::Before) {
+ InsertBefore();
+ } else {
+ // Skip over one top-level pair of parentheses (for the parameter list)
+ // and one pair of curly braces (for the code block).
+ // If that fails, insert before the function instead.
+ auto Tokens =
+ syntax::tokenize(syntax::FileRange(SM.getMainFileID(), *StartOffset,
+ Buffer.getBuffer().size()),
+ SM, AST->getLangOpts());
+ bool SkippedParams = false;
+ int OpenParens = 0;
+ int OpenBraces = 0;
+ std::optional<syntax::Token> Tok;
+ for (const auto &T : Tokens) {
+ tok::TokenKind StartKind = SkippedParams ? tok::l_brace : tok::l_paren;
+ tok::TokenKind EndKind = SkippedParams ? tok::r_brace : tok::r_paren;
+ int &Count = SkippedParams ? OpenBraces : OpenParens;
+ if (T.kind() == StartKind) {
+ ++Count;
+ } else if (T.kind() == EndKind) {
+ if (--Count == 0) {
+ if (SkippedParams) {
+ Tok = T;
+ break;
+ }
+ SkippedParams = true;
+ } else if (Count < 0) {
+ break;
+ }
+ }
+ }
+ if (Tok)
+ InsertionLoc = Tok->endLocation();
+ else
+ InsertBefore();
+ }
- auto TargetContext =
- findContextForNS(Region.EnclosingNamespace, Source->getDeclContext());
- if (!TargetContext)
- return error("define outline: couldn't find a context for target");
+ if (!InsertionLoc.isValid())
+ return {};
+ return sourceLocToPosition(SM, InsertionLoc);
+ }
- return InsertionPoint{*TargetContext, *Offset};
+ // Returns the most natural insertion point in this file.
+ // This is a fallback for when we failed to find an existing definition to
+ // place the new one next to. It only considers namespace proximity.
+ llvm::Expected<InsertionPoint> getInsertionPointInMainFile(ParsedAST *AST) {
+ // If the definition goes to the same file and there is a namespace,
+ // we should (and, in the case of anonymous namespaces, need to)
+ // put the definition into the original namespace block.
+ auto *Klass = Source->getDeclContext()->getOuterLexicalRecordContext();
+ if (!Klass)
+ return error("moving to same file not supported for free functions");
+ const SourceLocation EndLoc = Klass->getBraceRange().getEnd();
+ const auto &TokBuf = AST->getTokens();
+ auto Tokens = TokBuf.expandedTokens();
+ auto It = llvm::lower_bound(
+ Tokens, EndLoc, [](const syntax::Token &Tok, SourceLocation EndLoc) {
+ return Tok.location() < EndLoc;
+ });
+ while (It != Tokens.end()) {
+ if (It->kind() != tok::semi) {
+ ++It;
+ continue;
+ }
+ unsigned Offset =
+ AST->getSourceManager().getDecomposedLoc(It->endLocation()).second;
+ return InsertionPoint{Klass->getEnclosingNamespaceContext(), Offset};
+ }
+ return error(
+ "failed to determine insertion location: no end of class found");
}
private:
diff --git a/clang-tools-extra/clangd/refactor/tweaks/OverridePureVirtuals.cpp b/clang-tools-extra/clangd/refactor/tweaks/OverridePureVirtuals.cpp
index 16febec..b557066 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/OverridePureVirtuals.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/OverridePureVirtuals.cpp
@@ -79,7 +79,7 @@
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclCXX.h"
-#include "clang/AST/Type.h"
+#include "clang/AST/TypeBase.h"
#include "clang/AST/TypeLoc.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/SourceLocation.h"
@@ -116,7 +116,8 @@ std::string removePureVirtualSyntax(const std::string &MethodDecl,
DeclString += Tk.text();
if (Tk.Kind != tok::l_paren && Next.Kind != tok::comma &&
- Next.Kind != tok::r_paren && Next.Kind != tok::l_paren)
+ Next.Kind != tok::r_paren && Next.Kind != tok::l_paren &&
+ Tk.Kind != tok::coloncolon && Next.Kind != tok::coloncolon)
DeclString += ' ';
}
// Trim the last whitespace.
diff --git a/clang-tools-extra/clangd/support/DirectiveTree.cpp b/clang-tools-extra/clangd/support/DirectiveTree.cpp
index 97b0598..16d12f3 100644
--- a/clang-tools-extra/clangd/support/DirectiveTree.cpp
+++ b/clang-tools-extra/clangd/support/DirectiveTree.cpp
@@ -305,8 +305,8 @@ private:
if (&Value >= Tokens.end() || &Value.nextNC() < Tokens.end())
return std::nullopt;
return llvm::StringSwitch<std::optional<bool>>(Value.text())
- .Cases("true", "1", true)
- .Cases("false", "0", false)
+ .Cases({"true", "1"}, true)
+ .Cases({"false", "0"}, false)
.Default(std::nullopt);
}
diff --git a/clang-tools-extra/clangd/test/CMakeLists.txt b/clang-tools-extra/clangd/test/CMakeLists.txt
index 42fc350..eef8f52 100644
--- a/clang-tools-extra/clangd/test/CMakeLists.txt
+++ b/clang-tools-extra/clangd/test/CMakeLists.txt
@@ -5,6 +5,10 @@ set(CLANGD_TEST_DEPS
split-file
)
+if (LLVM_INCLUDE_BENCHMARKS)
+ list(APPEND CLANGD_TEST_DEPS IndexBenchmark)
+endif()
+
if(CLANGD_BUILD_XPC)
list(APPEND CLANGD_TEST_DEPS clangd-xpc-test-client)
list(APPEND CLANGD_TEST_DEPS ClangdXpcUnitTests)
diff --git a/clang-tools-extra/clangd/test/include-cleaner-batch-fix.test b/clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
index 07ebe10..5a87a87 100644
--- a/clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
+++ b/clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
@@ -7,7 +7,9 @@
# RUN: cp -r %S/Inputs/include-cleaner %t/include
# RUN: echo '-I%t/include' > %t/compile_flags.txt
# Create a config file enabling include-cleaner features.
-# RUN: echo $'Diagnostics:\n UnusedIncludes: Strict\n MissingIncludes: Strict' >> %t/clangd/config.yaml
+# RUN: echo 'Diagnostics:' > %t/clangd/config.yaml
+# RUN: echo ' UnusedIncludes: Strict' >> %t/clangd/config.yaml
+# RUN: echo ' MissingIncludes: Strict' >> %t/clangd/config.yaml
# RUN: env XDG_CONFIG_HOME=%t clangd -lit-test -enable-config --compile-commands-dir=%t < %s | FileCheck -strict-whitespace %s
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{"workspace":{"workspaceEdit":{"documentChanges":true, "changeAnnotationSupport":{"groupsOnLabel":true}}}},"trace":"off"}}
diff --git a/clang-tools-extra/clangd/test/index-tools.test b/clang-tools-extra/clangd/test/index-tools.test
index 93cf56f..cc01e19 100644
--- a/clang-tools-extra/clangd/test/index-tools.test
+++ b/clang-tools-extra/clangd/test/index-tools.test
@@ -1,6 +1,7 @@
+# Paths are not constructed correctly for the test to run on Windows.
+# UNSUPPORTED: system-windows
+# REQUIRES: have-benchmarks
# RUN: clangd-indexer %p/Inputs/BenchmarkSource.cpp -- -I%p/Inputs > %t.index
-# FIXME: By default, benchmarks are excluded from the list of default targets hence not built. Find a way to depend on benchmarks to run the next command.
-# REQUIRES: shell
-# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.json --benchmark_min_time=0.01 ; fi
+# RUN: %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.json --benchmark_min_time=0.01
# Pass invalid JSON file and check that IndexBenchmark fails to parse it.
-# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then not %clangd-benchmark-dir/IndexBenchmark %t.index %t --benchmark_min_time=0.01 ; fi
+# RUN: not %clangd-benchmark-dir/IndexBenchmark %t.index %t --benchmark_min_time=0.01
diff --git a/clang-tools-extra/clangd/test/lit.cfg.py b/clang-tools-extra/clangd/test/lit.cfg.py
index 8ab4309..bd721c4 100644
--- a/clang-tools-extra/clangd/test/lit.cfg.py
+++ b/clang-tools-extra/clangd/test/lit.cfg.py
@@ -1,13 +1,27 @@
+import os
+
import lit.llvm
+import lit.util
lit.llvm.initialize(lit_config, config)
lit.llvm.llvm_config.clang_setup()
lit.llvm.llvm_config.use_default_substitutions()
+# TODO: Consolidate the logic for turning on the internal shell by default for all LLVM test suites.
+# See https://github.com/llvm/llvm-project/issues/106636 for more details.
+#
+# We prefer the lit internal shell which provides a better user experience on failures
+# and is faster unless the user explicitly disables it with LIT_USE_INTERNAL_SHELL=0
+# env var.
+use_lit_shell = True
+lit_shell_env = os.environ.get("LIT_USE_INTERNAL_SHELL")
+if lit_shell_env:
+ use_lit_shell = lit.util.pythonize_bool(lit_shell_env)
+
config.name = "Clangd"
config.suffixes = [".test"]
config.excludes = ["Inputs"]
-config.test_format = lit.formats.ShTest(not lit.llvm.llvm_config.use_lit_shell)
+config.test_format = lit.formats.ShTest(not use_lit_shell)
config.test_source_root = config.clangd_source_dir + "/test"
config.test_exec_root = config.clangd_binary_dir + "/test"
@@ -37,6 +51,9 @@ if config.clangd_tidy_checks:
if config.have_zlib:
config.available_features.add("zlib")
+if lit.util.pythonize_bool(config.have_benchmarks):
+ config.available_features.add("have-benchmarks")
+
# It is not realistically possible to account for all options that could
# possibly be present in system and user configuration files, so disable
# default configs for the test runs.
diff --git a/clang-tools-extra/clangd/test/lit.site.cfg.py.in b/clang-tools-extra/clangd/test/lit.site.cfg.py.in
index a0bb356..f5ae3eb 100644
--- a/clang-tools-extra/clangd/test/lit.site.cfg.py.in
+++ b/clang-tools-extra/clangd/test/lit.site.cfg.py.in
@@ -19,6 +19,7 @@ config.clangd_build_dexp = @CLANGD_BUILD_DEXP@
config.clangd_enable_remote = @CLANGD_ENABLE_REMOTE@
config.clangd_tidy_checks = @CLANGD_TIDY_CHECKS@
config.have_zlib = @LLVM_ENABLE_ZLIB@
+config.have_benchmarks = "@LLVM_INCLUDE_BENCHMARKS@"
# Delegate logic to lit.cfg.py.
lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg.py")
diff --git a/clang-tools-extra/clangd/test/system-include-extractor.test b/clang-tools-extra/clangd/test/system-include-extractor.test
index 83a8c28bf..861d2e1 100644
--- a/clang-tools-extra/clangd/test/system-include-extractor.test
+++ b/clang-tools-extra/clangd/test/system-include-extractor.test
@@ -5,7 +5,8 @@
# Create a bin directory to store the mock-driver and add it to the path
# RUN: mkdir -p %t.dir/bin
-# RUN: export PATH=%t.dir/bin:$PATH
+# RUN: %python -c "print(__import__('os').environ['PATH'])" | tr -d '\n' > %t.path
+# RUN: export PATH=%t.dir/bin:%{readfile:%t.path}
# Generate a mock-driver that will print %temp_dir%/my/dir and
# %temp_dir%/my/dir2 as include search paths.
# RUN: echo '#!/bin/sh' >> %t.dir/bin/my_driver.sh
diff --git a/clang-tools-extra/clangd/tool/Check.cpp b/clang-tools-extra/clangd/tool/Check.cpp
index df8d075..9c6de40 100644
--- a/clang-tools-extra/clangd/tool/Check.cpp
+++ b/clang-tools-extra/clangd/tool/Check.cpp
@@ -169,6 +169,8 @@ public:
bool buildCommand(const ThreadsafeFS &TFS) {
log("Loading compilation database...");
DirectoryBasedGlobalCompilationDatabase::Options CDBOpts(TFS);
+ if (Opts.StrongWorkspaceMode)
+ CDBOpts.applyFallbackWorkingDirectory(Opts.WorkspaceRoot);
CDBOpts.CompileCommandsDir =
Config::current().CompileFlags.CDBSearch.FixedCDBPath;
BaseCDB =
@@ -178,8 +180,10 @@ public:
getSystemIncludeExtractor(llvm::ArrayRef(Opts.QueryDriverGlobs));
if (Opts.ResourceDir)
Mangler.ResourceDir = *Opts.ResourceDir;
+
CDB = std::make_unique<OverlayCDB>(
- BaseCDB.get(), std::vector<std::string>{}, std::move(Mangler));
+ BaseCDB.get(), std::vector<std::string>{}, std::move(Mangler),
+ CDBOpts.FallbackWorkingDirectory);
if (auto TrueCmd = CDB->getCompileCommand(File)) {
Cmd = std::move(*TrueCmd);
@@ -502,7 +506,7 @@ bool check(llvm::StringRef File, const ThreadsafeFS &TFS,
config::DiagnosticCallback Diag) const override {
config::Fragment F;
// If we're timing clang-tidy checks, implicitly disabling the slow ones
- // is counterproductive!
+ // is counterproductive!
if (CheckTidyTime.getNumOccurrences())
F.Diagnostics.ClangTidy.FastCheckFilter.emplace("None");
return {std::move(F).compile(Diag)};
diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index 4a990f8..54af366 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -500,6 +500,17 @@ opt<bool> EnableConfig{
init(true),
};
+opt<bool> StrongWorkspaceMode{
+ "strong-workspace-mode",
+ cat(Features),
+ desc("An alternate mode of operation for clangd, where the clangd instance "
+ "is used to edit a single workspace.\n"
+ "When enabled, fallback commands use the workspace directory as their "
+ "working directory instead of the parent folder."),
+ init(false),
+ Hidden,
+};
+
opt<bool> UseDirtyHeaders{"use-dirty-headers", cat(Misc),
desc("Use files open in the editor when parsing "
"headers instead of reading from the disk"),
@@ -907,6 +918,7 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
}
if (!ResourceDir.empty())
Opts.ResourceDir = ResourceDir;
+ Opts.StrongWorkspaceMode = StrongWorkspaceMode;
Opts.BuildDynamicSymbolIndex = true;
#if CLANGD_ENABLE_REMOTE
if (RemoteIndexAddress.empty() != ProjectRoot.empty()) {
diff --git a/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp b/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
index c9e01e5..39ab144 100644
--- a/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
+++ b/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
@@ -55,6 +55,20 @@ TEST(GlobalCompilationDatabaseTest, FallbackCommand) {
testPath("foo/bar")));
}
+TEST(GlobalCompilationDatabaseTest, FallbackWorkingDirectory) {
+ MockFS TFS;
+ DirectoryBasedGlobalCompilationDatabase::Options CDBOpts(TFS);
+ CDBOpts.applyFallbackWorkingDirectory(testPath("foo"));
+ EXPECT_EQ(CDBOpts.FallbackWorkingDirectory, testPath("foo"));
+
+ DirectoryBasedGlobalCompilationDatabase DB(CDBOpts);
+ auto Cmd = DB.getFallbackCommand(testPath("foo/src/bar.cc"));
+ EXPECT_EQ(Cmd.Directory, testPath("foo"));
+ EXPECT_THAT(Cmd.CommandLine,
+ ElementsAre("clang", testPath("foo/src/bar.cc")));
+ EXPECT_EQ(Cmd.Output, "");
+}
+
static tooling::CompileCommand cmd(llvm::StringRef File, llvm::StringRef Arg) {
return tooling::CompileCommand(
testRoot(), File, {"clang", std::string(Arg), std::string(File)}, "");
diff --git a/clang-tools-extra/clangd/unittests/SelectionTests.cpp b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
index 3df19d8..63c0403 100644
--- a/clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -311,6 +311,19 @@ TEST(SelectionTest, CommonAncestor) {
{"[[void foo^()]];", "FunctionProtoTypeLoc"},
{"[[^void foo^()]];", "FunctionDecl"},
{"[[void ^foo()]];", "FunctionDecl"},
+ // Tricky case: with function attributes, the AttributedTypeLoc's range
+ // includes the function name, but we want the name to be associated with
+ // the CXXMethodDecl.
+ {"struct X { [[const int* ^Get() const <:[clang::lifetimebound]:> "
+ "{return nullptr;}]]; };",
+ "CXXMethodDecl"},
+ // When the cursor is on the attribute itself, we should select the
+ // AttributedTypeLoc. Note: Due to a bug or deliberate quirk in the AST
+ // modeling of AttributedTypeLoc, its range ends at the attribute name
+ // token, not including the closing brackets ":>:>".
+ {"struct X { const [[int* Foo() const <:<:clang::life^timebound]]:>:> "
+ "{return nullptr;}; };",
+ "AttributedTypeLoc"},
// Tricky case: two VarDecls share a specifier.
{"[[int ^a]], b;", "VarDecl"},
{"[[int a, ^b]];", "VarDecl"},
diff --git a/clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp b/clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
index 4efae25..31bb794 100644
--- a/clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
@@ -196,76 +196,6 @@ TEST(SemanticSelection, RunViaClangdServer) {
ElementsAre(SourceAnnotations.range("empty")));
}
-TEST(FoldingRanges, ASTAll) {
- const char *Tests[] = {
- R"cpp(
- #define FOO int foo() {\
- int Variable = 42; \
- return 0; \
- }
-
- // Do not generate folding range for braces within macro expansion.
- FOO
-
- // Do not generate folding range within macro arguments.
- #define FUNCTOR(functor) functor
- void func() {[[
- FUNCTOR([](){});
- ]]}
-
- // Do not generate folding range with a brace coming from macro.
- #define LBRACE {
- void bar() LBRACE
- int X = 42;
- }
- )cpp",
- R"cpp(
- void func() {[[
- int Variable = 100;
-
- if (Variable > 5) {[[
- Variable += 42;
- ]]} else if (Variable++)
- ++Variable;
- else {[[
- Variable--;
- ]]}
-
- // Do not generate FoldingRange for empty CompoundStmts.
- for (;;) {}
-
- // If there are newlines between {}, we should generate one.
- for (;;) {[[
-
- ]]}
- ]]}
- )cpp",
- R"cpp(
- class Foo {
- public:
- Foo() {[[
- int X = 1;
- ]]}
-
- private:
- int getBar() {[[
- return 42;
- ]]}
-
- // Braces are located at the same line: no folding range here.
- void getFooBar() { }
- };
- )cpp",
- };
- for (const char *Test : Tests) {
- auto T = Annotations(Test);
- auto AST = TestTU::withCode(T.code()).build();
- EXPECT_THAT(gatherFoldingRanges(llvm::cantFail(getFoldingRanges(AST))),
- UnorderedElementsAreArray(T.ranges()))
- << Test;
- }
-}
-
TEST(FoldingRanges, PseudoParserWithoutLineFoldings) {
const char *Tests[] = {
R"cpp(
@@ -410,6 +340,22 @@ TEST(FoldingRanges, PseudoParserWithoutLineFoldings) {
Variable = 3;
#
)cpp",
+ R"cpp(
+ #pragma region R1[[
+
+ #pragma region R2[[
+ constexpr int a = 2;
+ ]]#pragma endregion
+
+ ]]#pragma endregion
+ )cpp",
+ R"cpp(
+ #pragma region[[
+ ]]#pragma endregion
+
+ #pragma /*comment1*/ region /*comment2*/name[[
+ ]]#pragma endregion
+ )cpp",
};
for (const char *Test : Tests) {
auto T = Annotations(Test);
@@ -470,6 +416,12 @@ TEST(FoldingRanges, PseudoParserLineFoldingsOnly) {
//[[ foo
/* bar */]]
)cpp",
+ R"cpp(
+ #pragma region abc[[
+ constexpr int a = 2;
+ ]]
+ #pragma endregion
+ )cpp",
// FIXME: Support folding template arguments.
// R"cpp(
// template <[[typename foo, class bar]]> struct baz {};
diff --git a/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp b/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
index 02133ec..7689bf3 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
@@ -448,7 +448,6 @@ inline T Foo<T>::bar(const T& t, const U& u) { return {}; }
TEST_F(DefineOutlineTest, InCppFile) {
FileName = "Test.cpp";
-
struct {
llvm::StringRef Test;
llvm::StringRef ExpectedSource;
@@ -773,8 +772,8 @@ class A {
)cpp";
std::string SourceAfter = R"cpp(
#include "a.hpp"
-void A::bar(){}
-void A::foo(){}
+void A::bar(){}void A::foo(){}
+
)cpp";
Workspace.addSource("a.hpp", HeaderBefore.code());
Workspace.addMainFile("a.cpp", SourceBefore);
@@ -786,6 +785,195 @@ void A::foo(){}
FileWithContents(testPath("a.cpp"), SourceAfter)))));
}
+// Test that the definition is inserted in a sensible location
+// under various circumstances.
+// Note that the formatting looks a little off here and there,
+// which is because in contrast to the actual tweak, the test procedure
+// does not run clang-format on the resulting code.
+TEST_F(DefineOutlineWorkspaceTest, SensibleInsertionLocations) {
+ const struct {
+ llvm::StringRef HeaderBefore;
+ llvm::StringRef SourceBefore;
+ llvm::StringRef HeaderAfter;
+ llvm::StringRef SourceAfter;
+ } Cases[] = {
+ // Criterion 1: Distance
+ {
+ R"cpp(
+struct Foo {
+ void ignored1(); // Too far away
+ void ignored2(); // No definition
+ void ignored3() {} // Defined inline
+ void fo^o() {}
+ void neighbor();
+};
+)cpp",
+ R"cpp(
+#include "a.hpp"
+void Foo::ignored1() {}
+void Foo::neighbor() {}
+)cpp",
+ R"cpp(
+struct Foo {
+ void ignored1(); // Too far away
+ void ignored2(); // No definition
+ void ignored3() {} // Defined inline
+ void foo() ;
+ void neighbor();
+};
+)cpp",
+ R"cpp(
+#include "a.hpp"
+void Foo::ignored1() {}
+void Foo::foo() {}
+void Foo::neighbor() {}
+)cpp"},
+
+ // Criterion 2: Prefer preceding
+ {
+ R"cpp(
+struct Foo {
+ void neighbor();
+ void fo^o() {}
+ void ignored();
+};
+)cpp",
+ R"cpp(
+#include "a.hpp"
+void Foo::neighbor() {}
+void Foo::ignored() {}
+)cpp",
+ R"cpp(
+struct Foo {
+ void neighbor();
+ void foo() ;
+ void ignored();
+};
+)cpp",
+ R"cpp(
+#include "a.hpp"
+void Foo::neighbor() {}void Foo::foo() {}
+
+void Foo::ignored() {}
+)cpp"},
+
+ // Like above, but with a namespace
+ {
+ R"cpp(
+namespace NS {
+struct Foo {
+ void neighbor();
+ void fo^o() {}
+ void ignored();
+};
+}
+)cpp",
+ R"cpp(
+#include "a.hpp"
+namespace NS {
+void Foo::neighbor() {}
+void Foo::ignored() {}
+}
+)cpp",
+ R"cpp(
+namespace NS {
+struct Foo {
+ void neighbor();
+ void foo() ;
+ void ignored();
+};
+}
+)cpp",
+ R"cpp(
+#include "a.hpp"
+namespace NS {
+void Foo::neighbor() {}void Foo::foo() {}
+
+void Foo::ignored() {}
+}
+)cpp"},
+
+ // Like above, but there is no namespace at the definition site
+ {
+ R"cpp(
+namespace NS {
+struct Foo {
+ void neighbor();
+ void fo^o() {}
+ void ignored();
+};
+}
+)cpp",
+ R"cpp(
+#include "a.hpp"
+void NS::Foo::neighbor() {}
+void NS::Foo::ignored() {}
+)cpp",
+ R"cpp(
+namespace NS {
+struct Foo {
+ void neighbor();
+ void foo() ;
+ void ignored();
+};
+}
+)cpp",
+ R"cpp(
+#include "a.hpp"
+void NS::Foo::neighbor() {}void NS::Foo::foo() {}
+
+void NS::Foo::ignored() {}
+)cpp"},
+
+ // Neighbor's definition is in header
+ {
+ R"cpp(
+struct Foo {
+ void fo^o() {}
+ void neighbor();
+ void ignored();
+};
+inline void Foo::neighbor() {}
+)cpp",
+ R"cpp(
+#include "a.hpp"
+void Foo::ignored() {}
+)cpp",
+ R"cpp(
+struct Foo {
+ void foo() ;
+ void neighbor();
+ void ignored();
+};
+inline void Foo::foo() {}
+inline void Foo::neighbor() {}
+)cpp",
+ {}},
+
+ };
+
+ for (const auto &Case : Cases) {
+ Workspace = {};
+ llvm::Annotations Hdr(Case.HeaderBefore);
+ Workspace.addSource("a.hpp", Hdr.code());
+ Workspace.addMainFile("a.cpp", Case.SourceBefore);
+ auto Result = apply("a.hpp", {Hdr.point(), Hdr.point()});
+ if (Case.SourceAfter.empty()) {
+ EXPECT_THAT(Result,
+ AllOf(withStatus("success"),
+ editedFiles(UnorderedElementsAre(FileWithContents(
+ testPath("a.hpp"), Case.HeaderAfter)))));
+
+ } else {
+ EXPECT_THAT(
+ Result,
+ AllOf(withStatus("success"),
+ editedFiles(UnorderedElementsAre(
+ FileWithContents(testPath("a.hpp"), Case.HeaderAfter),
+ FileWithContents(testPath("a.cpp"), Case.SourceAfter)))));
+ }
+ }
+}
} // namespace
} // namespace clangd
} // namespace clang
diff --git a/clang-tools-extra/clangd/unittests/tweaks/OverridePureVirtualsTests.cpp b/clang-tools-extra/clangd/unittests/tweaks/OverridePureVirtualsTests.cpp
index b7dcbee..72095ab 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/OverridePureVirtualsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/OverridePureVirtualsTests.cpp
@@ -715,6 +715,45 @@ public:
EXPECT_EQ(Expected, Applied) << "Applied result:\n" << Applied;
}
+TEST_F(OverridePureVirtualsTests, QualifiedNames) {
+ constexpr auto Before = R"cpp(
+namespace foo { struct S{}; namespace bar { struct S2{}; } }
+
+class B {
+public:
+ virtual foo::S foo(int var = 0) = 0;
+ virtual foo::bar::S2 bar(int var = 0) = 0;
+};
+
+class ^D : public B {};
+)cpp";
+
+ constexpr auto Expected = R"cpp(
+namespace foo { struct S{}; namespace bar { struct S2{}; } }
+
+class B {
+public:
+ virtual foo::S foo(int var = 0) = 0;
+ virtual foo::bar::S2 bar(int var = 0) = 0;
+};
+
+class D : public B {
+public:
+ foo::S foo(int var = 0) override {
+ // TODO: Implement this pure virtual method.
+ static_assert(false, "Method `foo` is not implemented.");
+ }
+
+ foo::bar::S2 bar(int var = 0) override {
+ // TODO: Implement this pure virtual method.
+ static_assert(false, "Method `bar` is not implemented.");
+ }
+};
+)cpp";
+ auto Applied = apply(Before);
+ EXPECT_EQ(Expected, Applied) << "Applied result:\n" << Applied;
+}
+
} // namespace
} // namespace clangd
} // namespace clang
diff --git a/clang-tools-extra/docs/Maintainers.rst b/clang-tools-extra/docs/Maintainers.rst
new file mode 100644
index 0000000..f78e9ec
--- /dev/null
+++ b/clang-tools-extra/docs/Maintainers.rst
@@ -0,0 +1 @@
+.. include:: ../Maintainers.rst \ No newline at end of file
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 6701bf2..6d3da61 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -58,6 +58,10 @@ Potentially Breaking Changes
:program:`clang-tidy-20`. Users should use the check-specific options of the
same name instead.
+- Removed `clang-analyzer-*` checks from default checks in :program:`clang-tidy`.
+ From now on, users should specify explicitly that they want CSA checks to run
+ in :program:`clang-tidy` via `clang-analyzer-*`.
+
- Renamed a few :program:`clang-tidy` check options, as they
were misspelled:
@@ -70,6 +74,13 @@ Potentially Breaking Changes
:doc:`bugprone-signed-char-misuse
<clang-tidy/checks/bugprone/signed-char-misuse>`
+- Modified the custom message format of :doc:`bugprone-unsafe-functions
+ <clang-tidy/checks/bugprone/unsafe-functions>` by assigning a special meaning
+ to the character ``>`` at the start of the value of the option
+ ``CustomFunctions``. If the option value starts with ``>``, then the
+ replacement suggestion part of the message (which would be included by
+ default) is omitted. (This does not change the warning locations.)
+
- :program:`clang-tidy` now displays warnings from all non-system headers by
default. Previously, users had to explicitly opt-in to header warnings using
`-header-filter='.*'`. To disable warnings from non-system, set `-header-filter`
@@ -177,6 +188,10 @@ Improvements to clang-tidy
scripts by adding the `-hide-progress` option to suppress progress and
informational messages.
+- Removed `clang-analyzer-*` check from default checks in :program:`clang-tidy`.
+ From now on, users should specify explicitly that they want CSA checks to run
+ in :program:`clang-tidy`.
+
- Deprecated the :program:`clang-tidy` ``zircon`` module. All checks have been
moved to the ``fuchsia`` module instead. The ``zircon`` module will be removed
in the 24th release.
@@ -184,17 +199,17 @@ Improvements to clang-tidy
New checks
^^^^^^^^^^
+- New :doc:`bugprone-derived-method-shadowing-base-method
+ <clang-tidy/checks/bugprone/derived-method-shadowing-base-method>` check.
+
+ Finds derived class methods that shadow a (non-virtual) base class method.
+
- New :doc:`bugprone-invalid-enum-default-initialization
<clang-tidy/checks/bugprone/invalid-enum-default-initialization>` check.
Detects default initialization (to 0) of variables with ``enum`` type where
the enum has no enumerator with value of 0.
-- New :doc:`bugprone-derived-method-shadowing-base-method
- <clang-tidy/checks/bugprone/derived-method-shadowing-base-method>` check.
-
- Finds derived class methods that shadow a (non-virtual) base class method.
-
- New :doc:`cppcoreguidelines-pro-bounds-avoid-unchecked-container-access
<clang-tidy/checks/cppcoreguidelines/pro-bounds-avoid-unchecked-container-access>`
check.
@@ -244,6 +259,11 @@ New check aliases
<clang-tidy/checks/modernize/avoid-variadic-functions>`
keeping initial check as an alias to the new one.
+- Renamed :doc:`cert-dcl58-cpp <clang-tidy/checks/cert/dcl58-cpp>` to
+ :doc:`bugprone-std-namespace-modification
+ <clang-tidy/checks/bugprone/std-namespace-modification>`
+ keeping initial check as an alias to the new one.
+
- Renamed :doc:`cert-env33-c <clang-tidy/checks/cert/env33-c>` to
:doc:`bugprone-command-processor
<clang-tidy/checks/bugprone/command-processor>`
@@ -264,6 +284,55 @@ New check aliases
<clang-tidy/checks/bugprone/throwing-static-initialization>`
keeping initial check as an alias to the new one.
+- Renamed :doc:`cert-err60-cpp <clang-tidy/checks/cert/err60-cpp>` to
+ :doc:`bugprone-exception-copy-constructor-throws
+ <clang-tidy/checks/bugprone/exception-copy-constructor-throws>`
+
+- Renamed :doc:`cert-flp30-c <clang-tidy/checks/cert/flp30-c>` to
+ :doc:`bugprone-float-loop-counter
+ <clang-tidy/checks/bugprone/float-loop-counter>`
+ keeping initial check as an alias to the new one.
+
+- Renamed :doc:`cert-mem57-cpp <clang-tidy/checks/cert/mem57-cpp>` to
+ :doc:`bugprone-default-operator-new-on-overaligned-type
+ <clang-tidy/checks/bugprone/default-operator-new-on-overaligned-type>`
+ keeping initial check as an alias to the new one.
+
+- Renamed :doc:`cert-msc30-c <clang-tidy/checks/cert/msc30-c>` to
+ :doc:`misc-predictable-rand
+ <clang-tidy/checks/misc/predictable-rand>`
+ keeping initial check as an alias to the new one.
+
+- Renamed :doc:`cert-msc32-c <clang-tidy/checks/cert/msc32-c>` to
+ :doc:`bugprone-random-generator-seed
+ <clang-tidy/checks/bugprone/random-generator-seed>`
+ keeping initial check as an alias to the new one.
+
+- Renamed :doc:`cert-msc50-cpp <clang-tidy/checks/cert/msc50-cpp>` to
+ :doc:`misc-predictable-rand
+ <clang-tidy/checks/misc/predictable-rand>`
+ keeping initial check as an alias to the new one.
+
+- Renamed :doc:`cert-msc51-cpp <clang-tidy/checks/cert/msc51-cpp>` to
+ :doc:`bugprone-random-generator-seed
+ <clang-tidy/checks/bugprone/random-generator-seed>`
+ keeping initial check as an alias to the new one.
+
+- Renamed :doc:`cert-oop57-cpp <clang-tidy/checks/cert/oop57-cpp>` to
+ :doc:`bugprone-raw-memory-call-on-non-trivial-type
+ <clang-tidy/checks/bugprone/raw-memory-call-on-non-trivial-type>`
+ keeping initial check as an alias to the new one.
+
+- Renamed :doc:`cert-oop58-cpp <clang-tidy/checks/cert/oop58-cpp>` to
+ :doc:`bugprone-copy-constructor-mutates-argument
+ <clang-tidy/checks/bugprone/copy-constructor-mutates-argument>`
+ keeping initial check as an alias to the new one.
+
+- Renamed :doc:`google-readability-casting <clang-tidy/checks/google/readability-casting>` to
+ :doc:`modernize-avoid-c-style-cast
+ <clang-tidy/checks/modernize/avoid-c-style-cast>`
+ keeping initial check as an alias to the new one.
+
Changes in existing checks
^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -275,7 +344,11 @@ Changes in existing checks
- Improved :doc:`bugprone-exception-escape
<clang-tidy/checks/bugprone/exception-escape>` check's handling of lambdas:
exceptions from captures are now diagnosed, exceptions in the bodies of
- lambdas that aren't actually invoked are not.
+ lambdas that aren't actually invoked are not. Additionally, fixed an issue
+ where the check wouldn't diagnose throws in arguments to functions or
+ constructors. Added fine-grained configuration via options
+ `CheckDestructors`, `CheckMoveMemberFunctions`, `CheckMain`,
+ `CheckedSwapFunctions`, and `CheckNothrowFunctions`.
- Improved :doc:`bugprone-infinite-loop
<clang-tidy/checks/bugprone/infinite-loop>` check by adding detection for
@@ -324,13 +397,26 @@ Changes in existing checks
- Improved :doc:`bugprone-unchecked-optional-access
<clang-tidy/checks/bugprone/unchecked-optional-access>` check by supporting
``NullableValue::makeValue`` and ``NullableValue::makeValueInplace`` to
- prevent false-positives for ``BloombergLP::bdlb::NullableValue`` type.
+ prevent false-positives for ``BloombergLP::bdlb::NullableValue`` type, and by
+ adding the `IgnoreValueCalls` option to suppress diagnostics for
+ ``optional::value()`` and the `IgnoreSmartPointerDereference` option to
+ ignore optionals reached via smart-pointer-like dereference, while still
+ diagnosing UB-prone dereferences via ``operator*`` and ``operator->``.
- Improved :doc:`bugprone-unhandled-self-assignment
<clang-tidy/checks/bugprone/unhandled-self-assignment>` check by adding
an additional matcher that generalizes the copy-and-swap idiom pattern
detection.
+- Improved :doc:`bugprone-unsafe-functions
+ <clang-tidy/checks/bugprone/unsafe-functions>` check by hiding the default
+ suffix when the reason starts with the character `>` in the `CustomFunctions`
+ option.
+
+- Improved :doc:`bugprone-use-after-move
+ <clang-tidy/checks/bugprone/use-after-move>` check by adding
+ `InvalidationFunctions` option to support custom invalidation functions.
+
- Improved :doc:`cppcoreguidelines-avoid-non-const-global-variables
<clang-tidy/checks/cppcoreguidelines/avoid-non-const-global-variables>` check
by adding a new option `AllowThreadLocal` that suppresses warnings on
@@ -355,6 +441,25 @@ Changes in existing checks
adding an option to allow pointer arithmetic via prefix/postfix increment or
decrement operators.
+- Improved :doc:`cppcoreguidelines-pro-type-member-init
+ <clang-tidy/checks/cppcoreguidelines/pro-type-member-init>` check to
+ correctly ignore ``std::array`` and other array-like containers when
+ `IgnoreArrays` option is set to `true`.
+
+- Improved :doc:`fuchsia-multiple-inheritance
+ <clang-tidy/checks/fuchsia/multiple-inheritance>`
+ by fixing an issue where the check would only analyze the first class with
+ a given name in the program, missing any subsequent classes with that same
+ name (declared in a different scope).
+
+- Improved :doc:`google-readability-casting
+ <clang-tidy/checks/google/readability-casting>` check by adding fix-it
+ notes for downcasts and casts to void pointer.
+
+- Improved :doc:`google-readability-todo
+ <clang-tidy/checks/google/readability-todo>` check to accept the new TODO
+ format from the Google Style Guide.
+
- Improved :doc:`llvm-prefer-isa-or-dyn-cast-in-conditionals
<clang-tidy/checks/llvm/prefer-isa-or-dyn-cast-in-conditionals>` check:
@@ -367,9 +472,16 @@ Changes in existing checks
- Improved :doc:`misc-const-correctness
<clang-tidy/checks/misc/const-correctness>` check to avoid false
- positives when pointers is transferred to non-const references
+ positives when pointers is transferred to non-const references
and avoid false positives of function pointer and fix false
- positives on return of non-const pointer.
+ positives on return of non-const pointer and fix false positives on
+ pointer-to-member operator and avoid false positives when the address
+ of a variable is taken to be passed to a function.
+
+- Improved :doc:`misc-coroutine-hostile-raii
+ <clang-tidy/checks/misc/coroutine-hostile-raii>` check by adding the option
+ `AllowedCallees`, that allows exempting safely awaitable callees from the
+ check.
- Improved :doc:`misc-header-include-cycle
<clang-tidy/checks/misc/header-include-cycle>` check performance.
@@ -414,7 +526,8 @@ Changes in existing checks
- Improved :doc:`modernize-use-std-print
<clang-tidy/checks/modernize/use-std-print>` check to correctly match
when the format string is converted to a different type by an implicit
- constructor call.
+ constructor call, and fixed a crash when handling format strings
+ containing non-ASCII characters.
- Improved :doc:`performance-unnecessary-copy-initialization
<clang-tidy/checks/performance/unnecessary-copy-initialization>` by printing
@@ -434,12 +547,21 @@ Changes in existing checks
comparisons to ``npos``. Internal changes may cause new rare false positives
in non-standard containers.
+- Improved :doc:`readability-container-data-pointer
+ <clang-tidy/checks/readability/container-data-pointer>` check by correctly
+ adding parentheses when the container expression is a dereference.
+
- Improved :doc:`readability-container-size-empty
<clang-tidy/checks/readability/container-size-empty>` check by correctly
generating fix-it hints when size method is called from implicit ``this``,
ignoring default constructors with user provided arguments and adding
detection in container's method except ``empty``.
+- Improved :doc:`readability-duplicate-include
+ <clang-tidy/checks/readability/duplicate-include>` check by adding
+ the ``IgnoredFilesList`` option (semicolon-separated list of regexes or
+ filenames) to allow intentional duplicates.
+
- Improved :doc:`readability-identifier-naming
<clang-tidy/checks/readability/identifier-naming>` check by ignoring
declarations and macros in system headers. The documentation is also improved
@@ -451,14 +573,32 @@ Changes in existing checks
adding parentheses when the inner expression are implicitly converted
multiple times.
+- Improved :doc:`readability-inconsistent-declaration-parameter-name
+ <clang-tidy/checks/readability/inconsistent-declaration-parameter-name>` check
+ by not enforcing parameter name consistency between a variadic parameter pack
+ in the primary template and specific parameters in its specializations.
+
- Improved :doc:`readability-qualified-auto
<clang-tidy/checks/readability/qualified-auto>` check by adding the option
`IgnoreAliasing`, that allows not looking at underlying types of type aliases.
+- Improved :doc:`readability-redundant-casting
+ <clang-tidy/checks/readability/redundant-casting>` check by fixing false
+ negatives when explicitly cast from function pointer.
+
- Improved :doc:`readability-uppercase-literal-suffix
<clang-tidy/checks/readability/uppercase-literal-suffix>` check to recognize
literal suffixes added in C++23 and C23.
+- Improved :doc:`readability-use-concise-preprocessor-directives
+ <clang-tidy/checks/readability/use-concise-preprocessor-directives>` check to
+ generate correct fix-its for forms without a space after the directive.
+
+- Improved :doc:`readability-use-std-min-max
+ <clang-tidy/checks/readability/use-std-min-max>` check by ensuring that
+ comments between the ``if`` condition and the ``then`` block are preserved
+ when applying the fix.
+
Removed checks
^^^^^^^^^^^^^^
diff --git a/clang-tools-extra/docs/clang-tidy/checks/abseil/duration-addition.rst b/clang-tools-extra/docs/clang-tidy/checks/abseil/duration-addition.rst
index ce2eefd..e8e3da0 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/abseil/duration-addition.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/abseil/duration-addition.rst
@@ -3,10 +3,10 @@
abseil-duration-addition
========================
-Check for cases where addition should be performed in the ``absl::Time`` domain.
-When adding two values, and one is known to be an ``absl::Time``, we can infer
-that the other should be interpreted as an ``absl::Duration`` of a similar
-scale, and make that inference explicit.
+Checks for cases where addition should be performed in the ``absl::Time``
+domain. When adding two values, and one is known to be an ``absl::Time``,
+we can infer that the other should be interpreted as an ``absl::Duration``
+of a similar scale, and make that inference explicit.
Examples:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/abseil/duration-division.rst b/clang-tools-extra/docs/clang-tidy/checks/abseil/duration-division.rst
index b7c8635..40c12d4 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/abseil/duration-division.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/abseil/duration-division.rst
@@ -4,8 +4,10 @@ abseil-duration-division
========================
``absl::Duration`` arithmetic works like it does with integers. That means that
-division of two ``absl::Duration`` objects returns an ``int64`` with any fractional
-component truncated toward 0. See `this link <https://github.com/abseil/abseil-cpp/blob/29ff6d4860070bf8fcbd39c8805d0c32d56628a3/absl/time/time.h#L137>`_ for more information on arithmetic with ``absl::Duration``.
+division of two ``absl::Duration`` objects returns an ``int64`` with any
+fractional component truncated toward 0.
+See `this link <https://github.com/abseil/abseil-cpp/blob/29ff6d4860070bf8fcbd39c8805d0c32d56628a3/absl/time/time.h#L137>`_
+for more information on arithmetic with ``absl::Duration``.
For example:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/abseil/faster-strsplit-delimiter.rst b/clang-tools-extra/docs/clang-tidy/checks/abseil/faster-strsplit-delimiter.rst
index fe91156..b5b79d4 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/abseil/faster-strsplit-delimiter.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/abseil/faster-strsplit-delimiter.rst
@@ -5,9 +5,9 @@ abseil-faster-strsplit-delimiter
Finds instances of ``absl::StrSplit()`` or ``absl::MaxSplits()`` where the
delimiter is a single character string literal and replaces with a character.
-The check will offer a suggestion to change the string literal into a character.
-It will also catch code using ``absl::ByAnyChar()`` for just a single character
-and will transform that into a single character as well.
+The check will offer a suggestion to change the string literal into a
+character. It will also catch code using ``absl::ByAnyChar()`` for just a
+single character and will transform that into a single character as well.
These changes will give the same result, but using characters rather than
single character string literals is more efficient and readable.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/abseil/string-find-str-contains.rst b/clang-tools-extra/docs/clang-tidy/checks/abseil/string-find-str-contains.rst
index 042fbdb..418df19 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/abseil/string-find-str-contains.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/abseil/string-find-str-contains.rst
@@ -3,8 +3,8 @@
abseil-string-find-str-contains
===============================
-Finds ``s.find(...) == string::npos`` comparisons (for various string-like types)
-and suggests replacing with ``absl::StrContains()``.
+Finds ``s.find(...) == string::npos`` comparisons (for various string-like
+types) and suggests replacing with ``absl::StrContains()``.
This improves readability and reduces the likelihood of accidentally mixing
``find()`` and ``npos`` from different string-like types.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/abseil/upgrade-duration-conversions.rst b/clang-tools-extra/docs/clang-tidy/checks/abseil/upgrade-duration-conversions.rst
index 24e557d..3abdd40b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/abseil/upgrade-duration-conversions.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/abseil/upgrade-duration-conversions.rst
@@ -8,17 +8,17 @@ argument needs an explicit cast to continue compiling after upcoming API
changes.
The operators ``*=``, ``/=``, ``*``, and ``/`` for ``absl::Duration`` currently
-accept an argument of class type that is convertible to an arithmetic type. Such
-a call currently converts the value to an ``int64_t``, even in a case such as
-``std::atomic<float>`` that would result in lossy conversion.
+accept an argument of class type that is convertible to an arithmetic type.
+Such a call currently converts the value to an ``int64_t``, even in a case such
+as ``std::atomic<float>`` that would result in lossy conversion.
Additionally, the ``absl::Duration`` factory functions (``absl::Hours``,
``absl::Minutes``, etc) currently accept an ``int64_t`` or a floating-point
type. Similar to the arithmetic operators, calls with an argument of class type
that is convertible to an arithmetic type go through the ``int64_t`` path.
-These operators and factories will be changed to only accept arithmetic types to
-prevent unintended behavior. After these changes are released, passing an
+These operators and factories will be changed to only accept arithmetic types
+to prevent unintended behavior. After these changes are released, passing an
argument of class type will no longer compile, even if the type is implicitly
convertible to an arithmetic type.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/android/cloexec-inotify-init1.rst b/clang-tools-extra/docs/clang-tidy/checks/android/cloexec-inotify-init1.rst
index 827598c..7411589 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/android/cloexec-inotify-init1.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/android/cloexec-inotify-init1.rst
@@ -3,9 +3,10 @@
android-cloexec-inotify-init1
=============================
-``inotify_init1()`` should include ``IN_CLOEXEC`` in its type argument to avoid the
-file descriptor leakage. Without this flag, an opened sensitive file would
-remain open across a fork+exec to a lower-privileged SELinux domain.
+``inotify_init1()`` should include ``IN_CLOEXEC`` in its type argument
+to avoid the file descriptor leakage. Without this flag, an opened
+sensitive file would remain open across a fork+exec to a
+lower-privileged SELinux domain.
Examples:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/android/cloexec-pipe.rst b/clang-tools-extra/docs/clang-tidy/checks/android/cloexec-pipe.rst
index b0504e9..c19e07f 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/android/cloexec-pipe.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/android/cloexec-pipe.rst
@@ -3,9 +3,10 @@
android-cloexec-pipe
====================
-This check detects usage of ``pipe()``. Using ``pipe()`` is not recommended, ``pipe2()`` is the
-suggested replacement. The check also adds the O_CLOEXEC flag that marks the file descriptor to
-be closed in child processes. Without this flag a sensitive file descriptor can be leaked to a
+This check detects usage of ``pipe()``. Using ``pipe()`` is not recommended,
+``pipe2()`` is the suggested replacement. The check also adds the ``O_CLOEXEC``
+flag that marks the file descriptor to be closed in child processes.
+Without this flag a sensitive file descriptor can be leaked to a
child process, potentially into a lower-privileged SELinux domain.
Examples:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/android/cloexec-pipe2.rst b/clang-tools-extra/docs/clang-tidy/checks/android/cloexec-pipe2.rst
index 9fb54be..dc9c6fc 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/android/cloexec-pipe2.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/android/cloexec-pipe2.rst
@@ -3,8 +3,9 @@
android-cloexec-pipe2
=====================
-This check ensures that pipe2() is called with the O_CLOEXEC flag. The check also
-adds the O_CLOEXEC flag that marks the file descriptor to be closed in child processes.
+This check ensures that ``pipe2()`` is called with the ``O_CLOEXEC`` flag.
+The check also adds the ``O_CLOEXEC`` flag that marks the file descriptor
+to be closed in child processes.
Without this flag a sensitive file descriptor can be leaked to a child process,
potentially into a lower-privileged SELinux domain.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/android/comparison-in-temp-failure-retry.rst b/clang-tools-extra/docs/clang-tidy/checks/android/comparison-in-temp-failure-retry.rst
index 31cc72b..42e8dd9 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/android/comparison-in-temp-failure-retry.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/android/comparison-in-temp-failure-retry.rst
@@ -22,8 +22,8 @@ Example buggy usage looks like:
// Do something with cs.
}
-Because TEMP_FAILURE_RETRY will check for whether the result *of the comparison*
-is ``-1``, and retry if so.
+Because ``TEMP_FAILURE_RETRY`` will check for whether the result
+*of the comparison* is ``-1``, and retry if so.
If you encounter this, the fix is simple: lift the comparison out of the
``TEMP_FAILURE_RETRY`` argument, like so:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/boost/use-ranges.rst b/clang-tools-extra/docs/clang-tidy/checks/boost/use-ranges.rst
index 01b0024..6cf5434 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/boost/use-ranges.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/boost/use-ranges.rst
@@ -146,7 +146,7 @@ If calls are made using reverse iterators on containers, The code will be
fixed using the ``boost::adaptors::reverse`` adaptor.
.. code-block:: c++
-
+
auto AreSame = std::equal(Items1.rbegin(), Items1.rend(),
std::crbegin(Items2), std::crend(Items2));
@@ -166,7 +166,7 @@ Options
is `llvm`.
.. option:: IncludeBoostSystem
-
+
If `true` (default value) the boost headers are included as system headers
with angle brackets (`#include <boost.hpp>`), otherwise quotes are used
(`#include "boost.hpp"`).
diff --git a/clang-tools-extra/docs/clang-tidy/checks/boost/use-to-string.rst b/clang-tools-extra/docs/clang-tidy/checks/boost/use-to-string.rst
index 8365e80..9a5bb88 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/boost/use-to-string.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/boost/use-to-string.rst
@@ -3,9 +3,9 @@
boost-use-to-string
===================
-This check finds conversion from integer type like ``int`` to ``std::string`` or
-``std::wstring`` using ``boost::lexical_cast``, and replace it with calls to
-``std::to_string`` and ``std::to_wstring``.
+This check finds conversion from integer type like ``int`` to
+``std::string`` or ``std::wstring`` using ``boost::lexical_cast``,
+and replace it with calls to ``std::to_string`` and ``std::to_wstring``.
It doesn't replace conversion from floating points despite the ``to_string``
overloads, because it would change the behavior.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/assignment-in-if-condition.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/assignment-in-if-condition.rst
index 9fa37c0..980e814 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/assignment-in-if-condition.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/assignment-in-if-condition.rst
@@ -4,11 +4,13 @@ bugprone-assignment-in-if-condition
===================================
Finds assignments within conditions of `if` statements.
-Such assignments are bug-prone because they may have been intended as equality tests.
+Such assignments are bug-prone because they may have been intended as
+equality tests.
-This check finds all assignments within `if` conditions, including ones that are not flagged
-by `-Wparentheses` due to an extra set of parentheses, and including assignments that call
-an overloaded `operator=()`. The identified assignments violate
+This check finds all assignments within `if` conditions, including ones that
+are not flagged by `-Wparentheses` due to an extra set of parentheses, and
+including assignments that call an overloaded ``operator=()``. The identified
+assignments violate
`BARR group "Rule 8.2.c" <https://barrgroup.com/embedded-systems/books/embedded-c-coding-standard/statement-rules/if-else-statements>`_.
.. code-block:: c++
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/bitwise-pointer-cast.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/bitwise-pointer-cast.rst
index ac58654..171e6e6 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/bitwise-pointer-cast.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/bitwise-pointer-cast.rst
@@ -31,9 +31,9 @@ not on pointer types:
int x{};
float y = std::bit_cast<float>(x);
-This way, the bytes of the input object are copied into the output object, which
-is much safer. Do note that Undefined Behavior can still occur, if there is no
-value of type ``To`` corresponding to the value representation produced.
+This way, the bytes of the input object are copied into the output object,
+which is much safer. Do note that Undefined Behavior can still occur, if there
+is no value of type ``To`` corresponding to the value representation produced.
Compilers may be able to optimize this copy and generate identical assembly to
the original ``reinterpret_cast`` version.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/capturing-this-in-member-variable.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/capturing-this-in-member-variable.rst
index dfc2ca1..6a6ad73 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/capturing-this-in-member-variable.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/capturing-this-in-member-variable.rst
@@ -6,11 +6,11 @@ bugprone-capturing-this-in-member-variable
Finds lambda captures that capture the ``this`` pointer and store it as class
members without handle the copy and move constructors and the assignments.
-Capture this in a lambda and store it as a class member is dangerous because the
-lambda can outlive the object it captures. Especially when the object is copied
-or moved, the captured ``this`` pointer will be implicitly propagated to the
-new object. Most of the time, people will believe that the captured ``this``
-pointer points to the new object, which will lead to bugs.
+Capture this in a lambda and store it as a class member is dangerous because
+the lambda can outlive the object it captures. Especially when the object is
+copied or moved, the captured ``this`` pointer will be implicitly propagated
+to the new object. Most of the time, people will believe that the captured
+``this`` pointer points to the new object, which will lead to bugs.
.. code-block:: c++
@@ -30,7 +30,7 @@ Possible fixes:
- marking copy and move constructors and assignment operators deleted.
- using class member method instead of class member variable with function
object types.
- - passing ``this`` pointer as parameter
+ - passing ``this`` pointer as parameter.
Options
-------
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/casting-through-void.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/casting-through-void.rst
index 21efda4..3c0b52a 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/casting-through-void.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/casting-through-void.rst
@@ -13,16 +13,19 @@ Two-step type conversions via ``void*`` are discouraged for several reasons.
- These conversions bypass valuable compiler support, erasing warnings related
to pointer alignment. It may violate strict aliasing rule and leading to
undefined behavior.
-- In scenarios involving multiple inheritance, ambiguity and unexpected outcomes
- can arise due to the loss of type information, posing runtime issues.
+- In scenarios involving multiple inheritance, ambiguity and unexpected
+ outcomes can arise due to the loss of type information, posing runtime
+ issues.
-In summary, avoiding two-step type conversions through ``void*`` ensures clearer code,
-maintains essential compiler warnings, and prevents ambiguity and potential runtime
-errors, particularly in complex inheritance scenarios. If such a cast is wanted,
-it shall be done via ``reinterpret_cast``, to express the intent more clearly.
+In summary, avoiding two-step type conversions through ``void*`` ensures
+clearer code, maintains essential compiler warnings, and prevents ambiguity
+and potential runtime errors, particularly in complex inheritance scenarios.
+If such a cast is wanted, it shall be done via ``reinterpret_cast``,
+to express the intent more clearly.
Note: it is expected that, after applying the suggested fix and using
-``reinterpret_cast``, the check :doc:`cppcoreguidelines-pro-type-reinterpret-cast
+``reinterpret_cast``, the check
+:doc:`cppcoreguidelines-pro-type-reinterpret-cast
<../cppcoreguidelines/pro-type-reinterpret-cast>` will emit a warning.
This is intentional: ``reinterpret_cast`` is a dangerous operation that can
easily break the strict aliasing rules when dereferencing the casted pointer,
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/compare-pointer-to-member-virtual-function.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/compare-pointer-to-member-virtual-function.rst
index cc711d6..6b2a82f 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/compare-pointer-to-member-virtual-function.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/compare-pointer-to-member-virtual-function.rst
@@ -3,8 +3,8 @@
bugprone-compare-pointer-to-member-virtual-function
===================================================
-Detects unspecified behavior about equality comparison between pointer to member
-virtual function and anything other than null-pointer-constant.
+Detects unspecified behavior about equality comparison between pointer to
+member virtual function and anything other than null-pointer-constant.
.. code-block:: c++
@@ -47,11 +47,11 @@ becomes particularly challenging when dealing with pointers to pure virtual
functions, as they may not even have a valid address, further complicating
comparisons.
-Instead, it is recommended to utilize the ``typeid`` operator or other appropriate
-mechanisms for comparing objects to ensure robust and predictable behavior in
-your codebase. By heeding this detection and adopting a more reliable comparison
-method, you can mitigate potential issues related to unspecified behavior,
-especially when dealing with pointers to member virtual functions or pure
+Instead, it is recommended to utilize the ``typeid`` operator or other
+appropriate mechanisms for comparing objects to ensure robust and predictable
+behavior in your codebase. By heeding this detection and adopting a more reliable
+comparison method, you can mitigate potential issues related to unspecified
+behavior, especially when dealing with pointers to member virtual functions or pure
virtual functions, thereby improving the overall stability and maintainability
of your code. In scenarios involving pointers to member virtual functions, it's
only advisable to employ ``nullptr`` for comparisons.
@@ -60,6 +60,6 @@ only advisable to employ ``nullptr`` for comparisons.
Limitations
-----------
-Does not analyze values stored in a variable. For variable, only analyze all virtual
-methods in the same ``class`` or ``struct`` and diagnose when assigning a pointer
-to member virtual function to this variable is possible.
+Does not analyze values stored in a variable. For variable, only analyze all
+virtual methods in the same ``class`` or ``struct`` and diagnose when assigning
+a pointer to member virtual function to this variable is possible.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/copy-constructor-mutates-argument.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/copy-constructor-mutates-argument.rst
new file mode 100644
index 0000000..e45a94a
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/copy-constructor-mutates-argument.rst
@@ -0,0 +1,11 @@
+.. title:: clang-tidy - bugprone-copy-constructor-mutates-argument
+
+bugprone-copy-constructor-mutates-argument
+==========================================
+
+Finds assignments to the copied object and its direct or indirect members
+in copy constructors and copy assignment operators.
+
+This check corresponds to the CERT C Coding Standard rule
+`OOP58-CPP. Copy operations must not mutate the source object
+<https://wiki.sei.cmu.edu/confluence/display/cplusplus/OOP58-CPP.+Copy+operations+must+not+mutate+the+source+object>`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/crtp-constructor-accessibility.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/crtp-constructor-accessibility.rst
index f24abfd..53082f4 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/crtp-constructor-accessibility.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/crtp-constructor-accessibility.rst
@@ -6,7 +6,7 @@ bugprone-crtp-constructor-accessibility
Detects error-prone Curiously Recurring Template Pattern usage, when the CRTP
can be constructed outside itself and the derived class.
-The CRTP is an idiom, in which a class derives from a template class, where
+The CRTP is an idiom, in which a class derives from a template class, where
itself is the template argument. It should be ensured that if a class is
intended to be a base class in this idiom, it can only be instantiated if
the derived class is its template argument.
@@ -23,7 +23,7 @@ Example:
class Derived : CRTP<Derived> {};
-Below can be seen some common mistakes that will allow the breaking of the
+Below can be seen some common mistakes that will allow the breaking of the
idiom.
If the constructor of a class intended to be used in a CRTP is public, then
@@ -62,7 +62,7 @@ Example:
class Bad : CRTP<Good> {};
Bad BadInstance;
-To ensure that no accidental instantiation happens, the best practice is to
+To ensure that no accidental instantiation happens, the best practice is to
make the constructor private and declare the derived class as friend. Note
that as a tradeoff, this also gives the derived class access to every other
private members of the CRTP. However, constructors can still be public or
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/dangling-handle.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/dangling-handle.rst
index 752b711..c25f8c4 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/dangling-handle.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/dangling-handle.rst
@@ -4,8 +4,9 @@ bugprone-dangling-handle
========================
Detect dangling references in value handles like ``std::string_view``.
-These dangling references can be a result of constructing handles from temporary
-values, where the temporary is destroyed soon after the handle is created.
+These dangling references can be a result of constructing handles from
+temporary values, where the temporary is destroyed soon after the handle
+is created.
Examples:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/default-operator-new-on-overaligned-type.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/default-operator-new-on-overaligned-type.rst
new file mode 100644
index 0000000..c991812
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/default-operator-new-on-overaligned-type.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - bugprone-default-operator-new-on-overaligned-type
+
+bugprone-default-operator-new-on-overaligned-type
+=================================================
+
+Flags uses of default ``operator new`` where the type has extended
+alignment (an alignment greater than the fundamental alignment).
+
+The default ``operator new`` is guaranteed to provide the correct alignment
+if the requested alignment is less or equal to the fundamental alignment.
+Only cases are detected (by design) where the ``operator new`` is not
+user-defined and is not a placement new (the reason is that in these cases we
+assume that the user provided the correct memory allocation).
+
+References
+----------
+
+This check corresponds to the CERT C++ Coding Standard rule
+`MEM57-CPP. Avoid using default operator new for over-aligned types
+<https://wiki.sei.cmu.edu/confluence/display/cplusplus/MEM57-CPP.+Avoid+using+default+operator+new+for+over-aligned+types>`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/derived-method-shadowing-base-method.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/derived-method-shadowing-base-method.rst
index f544abc..4906b50 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/derived-method-shadowing-base-method.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/derived-method-shadowing-base-method.rst
@@ -7,14 +7,15 @@ Finds derived class methods that shadow a (non-virtual) base class method.
In order to be considered "shadowing", methods must have the same signature
(i.e. the same name, same number of parameters, same parameter types, etc).
-Only checks public, non-templated methods.
+Only checks public, non-templated methods.
The below example is bugprone because consumers of the ``Derived`` class will
-expect the ``reset`` method to do the work of ``Base::reset()`` in addition to extra
-work required to reset the ``Derived`` class. Common fixes include:
+expect the ``reset`` method to do the work of ``Base::reset()`` in addition to
+extra work required to reset the ``Derived`` class. Common fixes include:
- Making the ``reset`` method polymorphic
-- Re-naming ``Derived::reset`` if it's not meant to intersect with ``Base::reset``
+- Re-naming ``Derived::reset`` if it's not meant to intersect with
+ ``Base::reset``
- Using ``using Base::reset`` to change the access specifier
This is also a violation of the Liskov Substitution Principle.
@@ -27,4 +28,4 @@ This is also a violation of the Liskov Substitution Principle.
struct Derived : public Base {
void reset() {/* reset the derived class, but not the base class */};
- }; \ No newline at end of file
+ };
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/dynamic-static-initializers.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/dynamic-static-initializers.rst
index b4d5f750..93d403c 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/dynamic-static-initializers.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/dynamic-static-initializers.rst
@@ -8,12 +8,12 @@ in header files.
This can pose problems in certain multithreaded contexts. For example,
when disabling compiler generated synchronization instructions for
-static variables initialized at runtime (e.g. by ``-fno-threadsafe-statics``), even if a particular project
-takes the necessary precautions to prevent race conditions during
-initialization by providing their own synchronization, header files included from other projects may
-not. Therefore, such a check is helpful for ensuring that disabling
-compiler generated synchronization for static variable initialization will not cause
-problems.
+static variables initialized at runtime (e.g. by ``-fno-threadsafe-statics``),
+even if a particular project takes the necessary precautions to prevent race
+conditions during initialization by providing their own synchronization, header
+files included from other projects may not. Therefore, such a check is helpful
+for ensuring that disabling compiler generated synchronization for static
+variable initialization will not cause problems.
Consider the following code:
@@ -24,4 +24,6 @@ Consider the following code:
return k;
}
-When synchronization of static initialization is disabled, if two threads both call `foo` for the first time, there is the possibility that `k` will be double initialized, creating a race condition.
+When synchronization of static initialization is disabled, if two threads both
+call `foo` for the first time, there is the possibility that `k` will be double
+initialized, creating a race condition.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/easily-swappable-parameters.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/easily-swappable-parameters.rst
index a96d7f60..59ccab4 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/easily-swappable-parameters.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/easily-swappable-parameters.rst
@@ -12,9 +12,9 @@ swapped (or badly ordered) arguments.
void drawPoint(int X, int Y) { /* ... */ }
FILE *open(const char *Dir, const char *Name, Flags Mode) { /* ... */ }
-A potential call like ``drawPoint(-2, 5)`` or ``openPath("a.txt", "tmp", Read)``
-is perfectly legal from the language's perspective, but might not be what the
-developer of the function intended.
+A potential call like ``drawPoint(-2, 5)`` or
+``openPath("a.txt", "tmp", Read)`` is perfectly legal from the language's
+perspective, but might not be what the developer of the function intended.
More elaborate and type-safe constructs, such as opaque typedefs or strong
types should be used instead, to prevent a mistaken order of arguments.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst
index fd1db59..87c7edc 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst
@@ -118,10 +118,10 @@ Here is an example:
it->second.callFunction();
}
-In conclusion, empty catch statements are a bad practice that can lead to hidden
-bugs, security issues, poor code quality, and unreliable code. By handling
-exceptions properly, developers can ensure that their code is robust, secure,
-and maintainable.
+In conclusion, empty catch statements are a bad practice that can lead to
+hidden bugs, security issues, poor code quality, and unreliable code. By
+handling exceptions properly, developers can ensure that their code is
+robust, secure, and maintainable.
Options
-------
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-copy-constructor-throws.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-copy-constructor-throws.rst
new file mode 100644
index 0000000..7170501
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-copy-constructor-throws.rst
@@ -0,0 +1,31 @@
+.. title:: clang-tidy - bugprone-exception-copy-constructor-throws
+
+bugprone-exception-copy-constructor-throws
+==========================================
+
+Checks whether a thrown object's copy constructor can throw.
+
+Exception objects are required to be copy constructible in C++. However, an
+exception's copy constructor should not throw to avoid potential issues when
+unwinding the stack. If an exception is thrown during stack unwinding (such
+as from a copy constructor of an exception object), the program will
+terminate via ``std::terminate``.
+
+.. code-block:: c++
+
+ class SomeException {
+ public:
+ SomeException() = default;
+ SomeException(const SomeException&) { /* may throw */ }
+ };
+
+ void f() {
+ throw SomeException(); // warning: thrown exception type's copy constructor can throw
+ }
+
+References
+----------
+
+This check corresponds to the CERT C++ Coding Standard rule
+`ERR60-CPP. Exception objects must be nothrow copy constructible
+<https://wiki.sei.cmu.edu/confluence/display/cplusplus/ERR60-CPP.+Exception+objects+must+be+nothrow+copy+constructible>`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
index 182fade..7d724a4 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
@@ -26,15 +26,40 @@ function also results in unexpected termination.
Functions declared explicitly with ``noexcept(false)`` or ``throw(exception)``
will be excluded from the analysis, as even though it is not recommended for
-functions like ``swap()``, ``main()``, move constructors, move assignment operators
-and destructors, it is a clear indication of the developer's intention and
-should be respected.
+functions like ``swap()``, ``main()``, move constructors, move assignment
+operators and destructors, it is a clear indication of the developer's
+intention and should be respected.
WARNING! This check may be expensive on large source files.
Options
-------
+.. option:: CheckDestructors
+
+ When `true`, destructors are analyzed to not throw exceptions.
+ Default value is `true`.
+
+.. option:: CheckMoveMemberFunctions
+
+ When `true`, move constructors and move assignment operators are analyzed
+ to not throw exceptions. Default value is `true`.
+
+.. option:: CheckMain
+
+ When `true`, the ``main()`` function is analyzed to not throw exceptions.
+ Default value is `true`.
+
+.. option:: CheckNothrowFunctions
+
+ When `true`, functions marked with ``noexcept`` or ``throw()`` exception
+ specifications are analyzed to not throw exceptions. Default value is `true`.
+
+.. option:: CheckedSwapFunctions
+
+ Comma-separated list of swap function names which should not throw exceptions.
+ Default value is `swap,iter_swap,iter_move`.
+
.. option:: FunctionsThatShouldNotThrow
Comma separated list containing function names which should not throw. An
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/float-loop-counter.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/float-loop-counter.rst
new file mode 100644
index 0000000..e663b40
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/float-loop-counter.rst
@@ -0,0 +1,13 @@
+.. title:: clang-tidy - bugprone-float-loop-counter
+
+bugprone-float-loop-counter
+===========================
+
+Flags ``for`` loops where the induction expression has a floating-point type.
+
+References
+----------
+
+This check corresponds to the CERT C Coding Standard rule
+`FLP30-C. Do not use floating-point variables as loop counters
+<https://www.securecoding.cert.org/confluence/display/c/FLP30-C.+Do+not+use+floating-point+variables+as+loop+counters>`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/fold-init-type.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/fold-init-type.rst
index 8c6872d..fefad9f 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/fold-init-type.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/fold-init-type.rst
@@ -6,13 +6,14 @@ bugprone-fold-init-type
The check flags type mismatches in
`folds <https://en.wikipedia.org/wiki/Fold_(higher-order_function)>`_
like ``std::accumulate`` that might result in loss of precision.
-``std::accumulate`` folds an input range into an initial value using the type of
-the latter, with ``operator+`` by default. This can cause loss of precision
-through:
+``std::accumulate`` folds an input range into an initial value using
+the type of the latter, with ``operator+`` by default. This can cause
+loss of precision through:
- Truncation: The following code uses a floating point range and an int
- initial value, so truncation will happen at every application of ``operator+``
- and the result will be `0`, which might not be what the user expected.
+ initial value, so truncation will happen at every application of
+ ``operator+`` and the result will be `0`, which might not be what the
+ user expected.
.. code-block:: c++
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/forward-declaration-namespace.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/forward-declaration-namespace.rst
index 99ecb63..5e04f66 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/forward-declaration-namespace.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/forward-declaration-namespace.rst
@@ -17,4 +17,5 @@ the forward declaration is in a potentially wrong namespace.
// warning : no definition found for 'A', but a definition with the same name
// 'A' found in another namespace 'nb::'
-This check can only generate warnings, but it can't suggest a fix at this point.
+This check can only generate warnings, but it can't suggest a fix at this
+point.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/forwarding-reference-overload.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/forwarding-reference-overload.rst
index 6d70a50..cd079a3 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/forwarding-reference-overload.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/forwarding-reference-overload.rst
@@ -6,8 +6,8 @@ bugprone-forwarding-reference-overload
The check looks for perfect forwarding constructors that can hide copy or move
constructors. If a non const lvalue reference is passed to the constructor, the
forwarding reference parameter will be a better match than the const reference
-parameter of the copy constructor, so the perfect forwarding constructor will be
-called, which can be confusing.
+parameter of the copy constructor, so the perfect forwarding constructor will
+be called, which can be confusing.
For detailed description of this issue see: Scott Meyers, Effective Modern C++,
Item 26.
@@ -47,12 +47,12 @@ Consider the following example:
Person(const Person& rhs);
};
-The check warns for constructors C1 and C2, because those can hide copy and move
-constructors. We suppress warnings if the copy and the move constructors are both
-disabled (deleted or private), because there is nothing the perfect forwarding
-constructor could hide in this case. We also suppress warnings for constructors
-like C3-C6 that are guarded with an ``enable_if`` or a concept, assuming the
-programmer was aware of the possible hiding.
+The check warns for constructors C1 and C2, because those can hide copy and
+move constructors. We suppress warnings if the copy and the move constructors
+are both disabled (deleted or private), because there is nothing the perfect
+forwarding constructor could hide in this case. We also suppress warnings for
+constructors like C3-C6 that are guarded with an ``enable_if`` or a concept,
+assuming the programmer was aware of the possible hiding.
Background
----------
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/inc-dec-in-conditions.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/inc-dec-in-conditions.rst
index 380033f..f3f0331 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/inc-dec-in-conditions.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/inc-dec-in-conditions.rst
@@ -7,9 +7,9 @@ Detects when a variable is both incremented/decremented and referenced inside a
complex condition and suggests moving them outside to avoid ambiguity in the
variable's value.
-When a variable is modified and also used in a complex condition, it can lead to
-unexpected behavior. The side-effect of changing the variable's value within the
-condition can make the code difficult to reason about. Additionally, the
+When a variable is modified and also used in a complex condition, it can lead
+to unexpected behavior. The side-effect of changing the variable's value within
+the condition can make the code difficult to reason about. Additionally, the
developer's intended timing for the modification of the variable may not be
clear, leading to misunderstandings and errors. This can be particularly
problematic when the condition involves logical operators like ``&&`` and
@@ -44,8 +44,8 @@ throughout the code.
// do something
}
-Another common issue occurs when multiple increments or decrements are performed
-on the same variable inside a complex condition. For example:
+Another common issue occurs when multiple increments or decrements are
+performed on the same variable inside a complex condition. For example:
.. code-block:: c++
@@ -55,13 +55,14 @@ on the same variable inside a complex condition. For example:
// do something
}
-There is a potential issue with this code due to the order of evaluation in C++.
-The ``||`` operator used in the condition statement guarantees that if the first
-operand evaluates to ``true``, the second operand will not be evaluated. This
-means that if ``i`` were initially ``4``, the first operand ``i < 5`` would
-evaluate to ``true`` and the second operand ``i > 2`` would not be evaluated.
-As a result, the decrement operation ``--i`` would not be executed and ``i``
-would hold value ``5``, which may not be the intended behavior for the developer.
+There is a potential issue with this code due to the order of evaluation in
+C++. The ``||`` operator used in the condition statement guarantees that if
+the first operand evaluates to ``true``, the second operand will not be
+evaluated. This means that if ``i`` were initially ``4``, the first operand
+``i < 5`` would evaluate to ``true`` and the second operand ``i > 2`` would
+not be evaluated. As a result, the decrement operation ``--i`` would not be
+executed and ``i`` would hold value ``5``, which may not be the intended
+behavior for the developer.
To avoid this potential issue, the both increment and decrement operation on
``i`` should be moved outside the condition statement.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/incorrect-enable-shared-from-this.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/incorrect-enable-shared-from-this.rst
index cc9e7be..968340a 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/incorrect-enable-shared-from-this.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/incorrect-enable-shared-from-this.rst
@@ -3,8 +3,8 @@
bugprone-incorrect-enable-shared-from-this
==========================================
-Detect classes or structs that do not publicly inherit from
-``std::enable_shared_from_this``, because unintended behavior will
+Detect classes or structs that do not publicly inherit from
+``std::enable_shared_from_this``, because unintended behavior will
otherwise occur when calling ``shared_from_this``.
Consider the following code:
@@ -15,7 +15,7 @@ Consider the following code:
// private inheritance
class BadExample : std::enable_shared_from_this<BadExample> {
-
+
// ``shared_from_this``` unintended behaviour
// `libstdc++` implementation returns uninitialized ``weak_ptr``
public:
@@ -29,6 +29,6 @@ Consider the following code:
b_ex->bar();
}
-Using `libstdc++` implementation, ``shared_from_this`` will throw
-``std::bad_weak_ptr``. When ``using_not_public()`` is called, this code will
+Using `libstdc++` implementation, ``shared_from_this`` will throw
+``std::bad_weak_ptr``. When ``using_not_public()`` is called, this code will
crash without exception handling.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/infinite-loop.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/infinite-loop.rst
index 89502c1..bbbc877 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/infinite-loop.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/infinite-loop.rst
@@ -11,15 +11,15 @@ However, it is possible to detect some obvious infinite loops, for example, if
the loop condition is not changed. This check detects such loops. A loop is
considered infinite if it does not have any loop exit statement (``break``,
``continue``, ``goto``, ``return``, ``throw`` or a call to a function called as
-``[[noreturn]]``) and all of the following conditions hold for every variable in
-the condition:
+``[[noreturn]]``) and all of the following conditions hold for every variable
+in the condition:
- It is a local variable.
- It has no reference or pointer aliases.
- It is not a structure or class member.
-Furthermore, the condition must not contain a function call to consider the loop
-infinite since functions may return different values for different calls.
+Furthermore, the condition must not contain a function call to consider the
+loop infinite since functions may return different values for different calls.
For example, the following loop is considered infinite `i` is not changed in
the body:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/invalid-enum-default-initialization.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/invalid-enum-default-initialization.rst
index 45cb878..fcbfce7 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/invalid-enum-default-initialization.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/invalid-enum-default-initialization.rst
@@ -19,8 +19,8 @@ The check emits a warning only if an ``enum`` variable is default-initialized
value of 0. The type can be a scoped or non-scoped ``enum``. Unions are not
handled by the check (if it contains a member of enumeration type).
-Note that the ``enum`` ``std::errc`` is always ignored because it is expected to
-be default initialized, despite not defining an enumerator with the value 0.
+Note that the ``enum`` ``std::errc`` is always ignored because it is expected
+to be default initialized, despite not defining an enumerator with the value 0.
.. code-block:: c++
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/misplaced-operator-in-strlen-in-alloc.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/misplaced-operator-in-strlen-in-alloc.rst
index 38df480..c9a2a648 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/misplaced-operator-in-strlen-in-alloc.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/misplaced-operator-in-strlen-in-alloc.rst
@@ -4,14 +4,14 @@ bugprone-misplaced-operator-in-strlen-in-alloc
==============================================
Finds cases where ``1`` is added to the string in the argument to ``strlen()``,
-``strnlen()``, ``strnlen_s()``, ``wcslen()``, ``wcsnlen()``, and ``wcsnlen_s()``
-instead of the result and the value is used as an argument to a memory
-allocation function (``malloc()``, ``calloc()``, ``realloc()``, ``alloca()``) or
-the ``new[]`` operator in `C++`. The check detects error cases even if one of
-these functions (except the ``new[]`` operator) is called by a constant function
-pointer. Cases where ``1`` is added both to the parameter and the result of the
-``strlen()``-like function are ignored, as are cases where the whole addition is
-surrounded by extra parentheses.
+``strnlen()``, ``strnlen_s()``, ``wcslen()``, ``wcsnlen()``, and
+``wcsnlen_s()`` instead of the result and the value is used as an argument to a
+memory allocation function (``malloc()``, ``calloc()``, ``realloc()``,
+``alloca()``) or the ``new[]`` operator in `C++`. The check detects error cases
+even if one of these functions (except the ``new[]`` operator) is called by a
+constant function pointer. Cases where ``1`` is added both to the parameter and
+the result of the ``strlen()``-like function are ignored, as are cases where
+the whole addition is surrounded by extra parentheses.
`C` example code:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/multiple-new-in-one-expression.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/multiple-new-in-one-expression.rst
index b9b8984..154013d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/multiple-new-in-one-expression.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/multiple-new-in-one-expression.rst
@@ -10,11 +10,11 @@ and throws exception.
C++ does often not specify the exact order of evaluation of the operands of an
operator or arguments of a function. Therefore if a first allocation succeeds
and a second fails, in an exception handler it is not possible to tell which
-allocation has failed and free the memory. Even if the order is fixed the result
-of a first ``new`` may be stored in a temporary location that is not reachable
-at the time when a second allocation fails. It is best to avoid any expression
-that contains more than one ``operator new`` call, if exception handling is
-used to check for allocation errors.
+allocation has failed and free the memory. Even if the order is fixed the
+result of a first ``new`` may be stored in a temporary location that is not
+reachable at the time when a second allocation fails. It is best to avoid any
+expression that contains more than one ``operator new`` call, if exception
+handling is used to check for allocation errors.
Different rules apply for are the short-circuit operators ``||`` and ``&&`` and
the ``,`` operator, where evaluation of one side must be completed before the
@@ -31,9 +31,9 @@ For any warning to be emitted the ``new`` calls should be in a code block where
exception handling is used with catch for ``std::bad_alloc`` or
``std::exception``. At ``||``, ``&&``, ``,``, ``?`` (condition and one branch)
operators no warning is emitted. No warning is emitted if both of the memory
-allocations are not assigned to a variable or not passed directly to a function.
-The reason is that in this case the memory may be intentionally not freed or the
-allocated objects can be self-destructing objects.
+allocations are not assigned to a variable or not passed directly to a
+function. The reason is that in this case the memory may be intentionally not
+freed or the allocated objects can be self-destructing objects.
Examples:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/narrowing-conversions.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/narrowing-conversions.rst
index 1a1217e..4327bc0 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/narrowing-conversions.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/narrowing-conversions.rst
@@ -3,7 +3,8 @@
bugprone-narrowing-conversions
==============================
-`cppcoreguidelines-narrowing-conversions` redirects here as an alias for this check.
+`cppcoreguidelines-narrowing-conversions` redirects here as an alias for
+this check.
Checks for silent narrowing conversions, e.g: ``int i = 0; i += 0.1;``. While
the issue is obvious in this former example, it might not be so in the
@@ -19,8 +20,8 @@ We flag narrowing conversions from:
if WarnOnFloatingPointNarrowingConversion Option is set.
This check will flag:
- - All narrowing conversions that are not marked by an explicit cast (c-style or
- ``static_cast``). For example: ``int i = 0; i += 0.1;``,
+ - All narrowing conversions that are not marked by an explicit cast (c-style
+ or ``static_cast``). For example: ``int i = 0; i += 0.1;``,
``void f(int); f(0.1);``,
- All applications of binary operators with a narrowing conversions.
For example: ``int i; i+= 0.1;``.
@@ -110,17 +111,17 @@ FAQ
- What does "narrowing conversion from 'int' to 'float'" mean?
An IEEE754 Floating Point number can represent all integer values in the range
-[-2^PrecisionBits, 2^PrecisionBits] where PrecisionBits is the number of bits in
-the mantissa.
+[-2^PrecisionBits, 2^PrecisionBits] where PrecisionBits is the number of bits
+in the mantissa.
-For ``float`` this would be [-2^23, 2^23], where ``int`` can represent values in
-the range [-2^31, 2^31-1].
+For ``float`` this would be [-2^23, 2^23], where ``int`` can represent values
+in the range [-2^31, 2^31-1].
- What does "implementation-defined" mean?
-You may have encountered messages like "narrowing conversion from 'unsigned int'
-to signed type 'int' is implementation-defined".
-The C/C++ standard does not mandate two's complement for signed integers, and so
-the compiler is free to define what the semantics are for converting an unsigned
-integer to signed integer. Clang's implementation uses the two's complement
-format.
+You may have encountered messages like "narrowing conversion from 'unsigned
+int' to signed type 'int' is implementation-defined".
+The C/C++ standard does not mandate two's complement for signed integers, and
+so the compiler is free to define what the semantics are for converting an
+unsigned integer to signed integer. Clang's implementation uses the two's
+complement format.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/no-escape.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/no-escape.rst
index 770a71c..850b01c 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/no-escape.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/no-escape.rst
@@ -5,8 +5,8 @@ bugprone-no-escape
Finds pointers with the ``noescape`` attribute that are captured by an
asynchronously-executed block. The block arguments in ``dispatch_async()`` and
-``dispatch_after()`` are guaranteed to escape, so it is an error if a pointer with the
-``noescape`` attribute is captured by one of these blocks.
+``dispatch_after()`` are guaranteed to escape, so it is an error if a pointer
+with the ``noescape`` attribute is captured by one of these blocks.
The following is an example of an invalid use of the ``noescape`` attribute.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/non-zero-enum-to-bool-conversion.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/non-zero-enum-to-bool-conversion.rst
index 168ed71..0ae950d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/non-zero-enum-to-bool-conversion.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/non-zero-enum-to-bool-conversion.rst
@@ -3,24 +3,24 @@
bugprone-non-zero-enum-to-bool-conversion
=========================================
-Detect implicit and explicit casts of ``enum`` type into ``bool`` where ``enum``
-type doesn't have a zero-value enumerator. If the ``enum`` is used only to hold
-values equal to its enumerators, then conversion to ``bool`` will always result
-in ``true`` value. This can lead to unnecessary code that reduces readability
-and maintainability and can result in bugs.
+Detect implicit and explicit casts of ``enum`` type into ``bool`` where
+``enum`` type doesn't have a zero-value enumerator. If the ``enum`` is used
+only to hold values equal to its enumerators, then conversion to ``bool`` will
+always result in ``true`` value. This can lead to unnecessary code that reduces
+readability and maintainability and can result in bugs.
May produce false positives if the ``enum`` is used to store other values
(used as a bit-mask or zero-initialized on purpose). To deal with them,
-``// NOLINT`` or casting first to the underlying type before casting to ``bool``
-can be used.
+``// NOLINT`` or casting first to the underlying type before casting to
+``bool`` can be used.
It is important to note that this check will not generate warnings if the
definition of the enumeration type is not available.
Additionally, C++11 enumeration classes are supported by this check.
-Overall, this check serves to improve code quality and readability by identifying
-and flagging instances where implicit or explicit casts from enumeration types to
-boolean could cause potential issues.
+Overall, this check serves to improve code quality and readability by
+identifying and flagging instances where implicit or explicit casts from
+enumeration types to boolean could cause potential issues.
Example
-------
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/not-null-terminated-result.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/not-null-terminated-result.rst
index ed7d65c..db86e94 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/not-null-terminated-result.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/not-null-terminated-result.rst
@@ -3,10 +3,11 @@
bugprone-not-null-terminated-result
===================================
-Finds function calls where it is possible to cause a not null-terminated result.
-Usually the proper length of a string is ``strlen(src) + 1`` or equal length of
-this expression, because the null terminator needs an extra space. Without the
-null terminator it can result in undefined behavior when the string is read.
+Finds function calls where it is possible to cause a not null-terminated
+result. Usually the proper length of a string is ``strlen(src) + 1`` or equal
+length of this expression, because the null terminator needs an extra space.
+Without the null terminator it can result in undefined behavior when the
+string is read.
The following and their respective ``wchar_t`` based functions are checked:
@@ -25,8 +26,8 @@ of the allocated memory is not enough to hold the null terminator.
return result;
}
-In addition to issuing warnings, fix-it rewrites all the necessary code. It also
-tries to adjust the capacity of the destination array:
+In addition to issuing warnings, fix-it rewrites all the necessary code.
+It also tries to adjust the capacity of the destination array:
.. code-block:: c
@@ -62,8 +63,8 @@ Rewrite based on the destination array
the safe version (ending with ``cpy_s``).
- If the new function is could be safe version and C++ files are analyzed and
- the destination array is plain ``char``/``wchar_t`` without ``un/signed`` then
- the length of the destination array can be omitted.
+ the destination array is plain ``char``/``wchar_t`` without ``un/signed``
+ then the length of the destination array can be omitted.
- If the new function is could be safe version and the destination array is
``un/signed`` it needs to be casted to plain ``char *``/``wchar_t *``.
@@ -76,8 +77,9 @@ Rewrite based on the length of the source string
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- If the given length is ``strlen(source)`` or equal length of this expression
- then the new function should be the older copy function (ending with ``cpy``),
- as it is more efficient than the safe version (ending with ``cpy_s``).
+ then the new function should be the older copy function (ending with
+ ``cpy``), as it is more efficient than the safe version (ending with
+ ``cpy_s``).
- Otherwise we assume that the programmer wanted to copy 'N' characters, so the
new function is ``ncpy``-like which copies 'N' characters.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
index 95509ef..2641cfe 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.rst
@@ -54,7 +54,7 @@ Options
Default: `false`.
.. code-block:: c++
-
+
void bar(Base b[], Derived d[]) {
b += 1; // warning, as Base declares a virtual destructor
d += 1; // warning only if IgnoreVirtualDeclarationsOnly is set to false
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/posix-return.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/posix-return.rst
index a5c4ccb..1a4a3ed 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/posix-return.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/posix-return.rst
@@ -13,7 +13,8 @@ Example buggy usage looks like:
if (posix_fadvise(...) < 0) {
-This will never happen as the return value is always non-negative. A simple fix could be:
+This will never happen as the return value is always non-negative.
+A simple fix could be:
.. code-block:: c
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/random-generator-seed.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/random-generator-seed.rst
new file mode 100644
index 0000000..2568099
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/random-generator-seed.rst
@@ -0,0 +1,44 @@
+.. title:: clang-tidy - bugprone-random-generator-seed
+
+bugprone-random-generator-seed
+==============================
+
+Flags all pseudo-random number engines, engine adaptor
+instantiations and ``srand()`` when initialized or seeded with default
+argument, constant expression or any user-configurable type. Pseudo-random
+number engines seeded with a predictable value may cause vulnerabilities
+e.g. in security protocols.
+
+Examples:
+
+.. code-block:: c++
+
+ void foo() {
+ std::mt19937 engine1; // Diagnose, always generate the same sequence
+ std::mt19937 engine2(1); // Diagnose
+ engine1.seed(); // Diagnose
+ engine2.seed(1); // Diagnose
+
+ std::time_t t;
+ engine1.seed(std::time(&t)); // Diagnose, system time might be controlled by user
+
+ int x = atoi(argv[1]);
+ std::mt19937 engine3(x); // Will not warn
+ }
+
+Options
+-------
+
+.. option:: DisallowedSeedTypes
+
+ A comma-separated list of the type names which are disallowed.
+ Default value is `time_t,std::time_t`.
+
+References
+----------
+
+This check corresponds to the CERT C++ Coding Standard rules
+`MSC51-CPP. Ensure your random number generator is properly seeded
+<https://wiki.sei.cmu.edu/confluence/display/cplusplus/MSC51-CPP.+Ensure+your+random+number+generator+is+properly+seeded>`_ and
+`MSC32-C. Properly seed pseudorandom number generators
+<https://wiki.sei.cmu.edu/confluence/display/c/MSC32-C.+Properly+seed+pseudorandom+number+generators>`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/raw-memory-call-on-non-trivial-type.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/raw-memory-call-on-non-trivial-type.rst
new file mode 100644
index 0000000..db38444
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/raw-memory-call-on-non-trivial-type.rst
@@ -0,0 +1,35 @@
+.. title:: clang-tidy - bugprone-raw-memory-call-on-non-trivial-type
+
+bugprone-raw-memory-call-on-non-trivial-type
+============================================
+
+Flags use of the C standard library functions ``memset``, ``memcpy`` and
+``memcmp`` and similar derivatives on non-trivial types.
+
+The check will detect the following functions: ``memset``, ``std::memset``,
+``std::memcpy``, ``memcpy``, ``std::memmove``, ``memmove``, ``std::strcpy``,
+``strcpy``, ``memccpy``, ``stpncpy``, ``strncpy``, ``std::memcmp``, ``memcmp``,
+``std::strcmp``, ``strcmp``, ``strncmp``.
+
+Options
+-------
+
+.. option:: MemSetNames
+
+ Specify extra functions to flag that act similarly to ``memset``. Specify
+ names in a semicolon-delimited list. Default is an empty string.
+
+.. option:: MemCpyNames
+
+ Specify extra functions to flag that act similarly to ``memcpy``. Specify
+ names in a semicolon-delimited list. Default is an empty string.
+
+.. option:: MemCmpNames
+
+ Specify extra functions to flag that act similarly to ``memcmp``. Specify
+ names in a semicolon-delimited list. Default is an empty string.
+
+This check corresponds to the CERT C++ Coding Standard rule
+`OOP57-CPP. Prefer special member functions and overloaded operators to C
+Standard Library functions
+<https://wiki.sei.cmu.edu/confluence/display/cplusplus/OOP57-CPP.+Prefer+special+member+functions+and+overloaded+operators+to+C+Standard+Library+functions>`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/redundant-branch-condition.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/redundant-branch-condition.rst
index c2efff8..7a321bd 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/redundant-branch-condition.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/redundant-branch-condition.rst
@@ -16,9 +16,9 @@ Simple example:
scream();
}
-Here `onFire` is checked both in the outer ``if`` and the inner ``if`` statement
-without a possible change between the two checks. The check warns for this code
-and suggests removal of the second checking of variable `onFire`.
+Here `onFire` is checked both in the outer ``if`` and the inner ``if``
+statement without a possible change between the two checks. The check warns for
+this code and suggests removal of the second checking of variable `onFire`.
The checker also detects redundant condition checks if the condition variable
is an operand of a logical "and" (``&&``) or a logical "or" (``||``) operator:
@@ -44,8 +44,8 @@ condition variable and keep the other side of the ``&&``. In the second case
(logical "or") the whole ``if`` is removed similarly to the simple case on the
top.
-The condition of the outer ``if`` statement may also be a logical "and" (``&&``)
-expression:
+The condition of the outer ``if`` statement may also be a logical "and"
+(``&&``) expression:
.. code-block:: c
@@ -62,8 +62,8 @@ The error is also detected if both the outer statement is a logical "and"
The inner ``if`` statement does not have to be a direct descendant of the outer
one.
-No error is detected if the condition variable may have been changed between the
-two checks:
+No error is detected if the condition variable may have been changed between
+the two checks:
.. code-block:: c
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/return-const-ref-from-parameter.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/return-const-ref-from-parameter.rst
index 325a0a2..663e214 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/return-const-ref-from-parameter.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/return-const-ref-from-parameter.rst
@@ -3,14 +3,14 @@
bugprone-return-const-ref-from-parameter
========================================
-Detects return statements that return a constant reference parameter as constant
-reference. This may cause use-after-free errors if the caller uses xvalues as
-arguments.
+Detects return statements that return a constant reference parameter as
+constant reference. This may cause use-after-free errors if the caller
+uses xvalues as arguments.
-In C++, constant reference parameters can accept xvalues which will be destructed
-after the call. When the function returns such a parameter also as constant reference,
-then the returned reference can be used after the object it refers to has been
-destroyed.
+In C++, constant reference parameters can accept xvalues which will be
+destructed after the call. When the function returns such a parameter also
+as constant reference, then the returned reference can be used after the
+object it refers to has been destroyed.
Example
-------
@@ -22,7 +22,7 @@ Example
S(int);
~S();
};
-
+
const S &fn(const S &a) {
return a;
}
@@ -35,7 +35,7 @@ This issue can be resolved by declaring an overload of the problematic function
where the ``const &`` parameter is instead declared as ``&&``. The developer has
to ensure that the implementation of that function does not produce a
use-after-free, the exact error that this check is warning against.
-Marking such an ``&&`` overload as ``deleted``, will silence the warning as
+Marking such an ``&&`` overload as ``deleted``, will silence the warning as
well. In the case of different ``const &`` parameters being returned depending
on the control flow of the function, an overload where all problematic
``const &`` parameters have been declared as ``&&`` will resolve the issue.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/signal-handler.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/signal-handler.rst
index 658b6555..42cfdf0 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/signal-handler.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/signal-handler.rst
@@ -20,10 +20,10 @@ Checked signal handler rules for up to and including C++14:
The check is disabled on C++17 and later.
-Asynchronous-safety is determined by comparing the function's name against a set
-of known functions. In addition, the function must come from a system header
-include and in a global namespace. The (possible) arguments passed to the
-function are not checked. Any function that cannot be determined to be
+Asynchronous-safety is determined by comparing the function's name against a
+set of known functions. In addition, the function must come from a system
+header include and in a global namespace. The (possible) arguments passed to
+the function are not checked. Any function that cannot be determined to be
asynchronous-safe is assumed to be non-asynchronous-safe by the check,
including user functions for which only the declaration is visible.
Calls to user-defined functions with visible definitions are checked
@@ -44,12 +44,12 @@ Options
Selects which set of functions is considered as asynchronous-safe
(and therefore allowed in signal handlers). It can be set to the following values:
-
- ``minimal``
+
+ - `minimal`
Selects a minimal set that is defined in the CERT SIG30-C rule.
and includes functions ``abort()``, ``_Exit()``, ``quick_exit()`` and
``signal()``.
- ``POSIX``
+ - `POSIX`
Selects a larger set of functions that is listed in POSIX.1-2017 (see `this
link
<https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04_03>`_
@@ -94,4 +94,4 @@ Options
The function ``quick_exit`` is not included in the POSIX list but it
is included here in the set of safe functions.
- The default value is ``POSIX``.
+ The default value is `POSIX`.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/signed-char-misuse.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/signed-char-misuse.rst
index 3e06e11..4b98c36 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/signed-char-misuse.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/signed-char-misuse.rst
@@ -17,30 +17,34 @@ human programmer probably expects that the converted value matches with the
character code (a value from [0..255]), however, the actual value is in
[-128..127] interval. To avoid this kind of misinterpretation, the desired way
of converting from a ``signed char`` to an integer value is converting to
-``unsigned char`` first, which stores all the characters in the positive [0..255]
-interval which matches the known character codes.
+``unsigned char`` first, which stores all the characters in the positive
+[0..255] interval which matches the known character codes.
In case of implicit conversion, the programmer might not actually be aware
that a conversion happened and char value is used as an integer. There are
-some use cases when this unawareness might lead to a functionally imperfect code.
-For example, checking the equality of a ``signed char`` and an ``unsigned char``
-variable is something we should avoid in C++ code. During this comparison,
-the two variables are converted to integers which have different value ranges.
-For ``signed char``, the non-ASCII characters are stored as a value in [-128..-1]
-interval, while the same characters are stored in the [128..255] interval for
-an ``unsigned char``.
-
-It depends on the actual platform whether plain ``char`` is handled as ``signed char``
-by default and so it is caught by this check or not. To change the default behavior
-you can use ``-funsigned-char`` and ``-fsigned-char`` compilation options.
+some use cases when this unawareness might lead to a functionally imperfect
+code. For example, checking the equality of a ``signed char`` and an
+``unsigned char`` variable is something we should avoid in C++ code. During
+this comparison, the two variables are converted to integers which have
+different value ranges. For ``signed char``, the non-ASCII characters are
+stored as a value in [-128..-1] interval, while the same characters are
+stored in the [128..255] interval for an ``unsigned char``.
+
+It depends on the actual platform whether plain ``char`` is handled as
+``signed char`` by default and so it is caught by this check or not.
+To change the default behavior you can use ``-funsigned-char`` and
+``-fsigned-char`` compilation options.
Currently, this check warns in the following cases:
+
- ``signed char`` is assigned to an integer variable
-- ``signed char`` and ``unsigned char`` are compared with equality/inequality operator
+- ``signed char`` and ``unsigned char`` are compared with
+ equality/inequality operator
- ``signed char`` is converted to an integer in the array subscript
See also:
-`STR34-C. Cast characters to unsigned char before converting to larger integer sizes
+`STR34-C. Cast characters to unsigned char before converting to larger
+integer sizes
<https://wiki.sei.cmu.edu/confluence/display/c/STR34-C.+Cast+characters+to+unsigned+char+before+converting+to+larger+integer+sizes>`_
A good example from the CERT description when a ``char`` variable is used to
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-container.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-container.rst
index fb2f0b2..5d70d45 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-container.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-container.rst
@@ -3,12 +3,12 @@
bugprone-sizeof-container
=========================
-The check finds usages of ``sizeof`` on expressions of STL container types. Most
-likely the user wanted to use ``.size()`` instead.
+The check finds usages of ``sizeof`` on expressions of STL container types.
+Most likely the user wanted to use ``.size()`` instead.
-All class/struct types declared in namespace ``std::`` having a const ``size()``
-method are considered containers, with the exception of ``std::bitset`` and
-``std::array``.
+All class/struct types declared in namespace ``std::`` having a const
+``size()`` method are considered containers, with the exception of
+``std::bitset`` and ``std::array``.
Examples:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst
index 09be75c..aa2e529 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst
@@ -73,9 +73,9 @@ Suspicious usage of 'sizeof(char*)'
There is a subtle difference between declaring a string literal with
``char* A = ""`` and ``char A[] = ""``. The first case has the type ``char*``
-instead of the aggregate type ``char[]``. Using ``sizeof`` on an object declared
-with ``char*`` type is returning the size of a pointer instead of the number of
-characters (bytes) in the string literal.
+instead of the aggregate type ``char[]``. Using ``sizeof`` on an object
+declared with ``char*`` type is returning the size of a pointer instead of
+the number of characters (bytes) in the string literal.
.. code-block:: c++
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/std-namespace-modification.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/std-namespace-modification.rst
new file mode 100644
index 0000000..56d2559
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/std-namespace-modification.rst
@@ -0,0 +1,68 @@
+.. title:: clang-tidy - bugprone-std-namespace-modification
+
+bugprone-std-namespace-modification
+===================================
+
+Warns on modifications of the ``std`` or ``posix`` namespaces which can
+result in undefined behavior.
+
+The ``std`` (or ``posix``) namespace is allowed to be extended with (class or
+function) template specializations that depend on an user-defined type (a type
+that is not defined in the standard system headers).
+
+The check detects the following (user provided) declarations in namespace
+``std`` or ``posix``:
+
+- Anything that is not a template specialization.
+- Explicit specializations of any standard library function template or class
+ template, if it does not have any user-defined type as template argument.
+- Explicit specializations of any member function of a standard library class
+ template.
+- Explicit specializations of any member function template of a standard
+ library class or class template.
+- Explicit or partial specialization of any member class template of a standard
+ library class or class template.
+
+Examples:
+
+.. code-block:: c++
+
+ namespace std {
+ int x; // warning: modification of 'std' namespace can result in undefined behavior [bugprone-dont-modify-std-namespace]
+ }
+
+ namespace posix::a { // warning: modification of 'posix' namespace can result in undefined behavior
+ }
+
+ template <>
+ struct ::std::hash<long> { // warning: modification of 'std' namespace can result in undefined behavior
+ unsigned long operator()(const long &K) const {
+ return K;
+ }
+ };
+
+ struct MyData { long data; };
+
+ template <>
+ struct ::std::hash<MyData> { // no warning: specialization with user-defined type
+ unsigned long operator()(const MyData &K) const {
+ return K.data;
+ }
+ };
+
+ namespace std {
+ template <>
+ void swap<bool>(bool &a, bool &b); // warning: modification of 'std' namespace can result in undefined behavior
+
+ template <>
+ bool less<void>::operator()<MyData &&, MyData &&>(MyData &&, MyData &&) const { // warning: modification of 'std' namespace can result in undefined behavior
+ return true;
+ }
+ }
+
+References
+----------
+
+This check corresponds to the CERT C++ Coding Standard rule
+`DCL58-CPP. Do not modify the standard namespaces
+<https://www.securecoding.cert.org/confluence/display/cplusplus/DCL58-CPP.+Do+not+modify+the+standard+namespaces>`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/string-constructor.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/string-constructor.rst
index a0bd1d7..ad4ed89 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/string-constructor.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/string-constructor.rst
@@ -36,7 +36,7 @@ Examples:
std::string_view("test", 0);
Passing an invalid first character position parameter to constructor will
-cause ``std::out_of_range`` exception at runtime.
+cause ``std::out_of_range`` exception at runtime.
Examples:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/string-literal-with-embedded-nul.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/string-literal-with-embedded-nul.rst
index c1c4d32..bc5f2ce 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/string-literal-with-embedded-nul.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/string-literal-with-embedded-nul.rst
@@ -21,9 +21,9 @@ like this ``\0x42`` where the ``\0`` stands for the NUL character.
Truncated literal
-----------------
-String-like classes can manipulate strings with embedded NUL as they are keeping
-track of the bytes and the length. This is not the case for a ``char*``
-(NUL-terminated) string.
+String-like classes can manipulate strings with embedded NUL as they are
+keeping track of the bytes and the length. This is not the case for a
+``char*`` (NUL-terminated) string.
A common mistake is to pass a string-literal with embedded NUL to a string
constructor expecting a NUL-terminated string. The bytes after the first NUL
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-enum-usage.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-enum-usage.rst
index 94f29ee..94e3db9 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-enum-usage.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-enum-usage.rst
@@ -3,11 +3,11 @@
bugprone-suspicious-enum-usage
==============================
-The checker detects various cases when an enum is probably misused (as a bitmask
-).
+The checker detects various cases when an enum is probably misused
+(as a bitmask).
-1. When "ADD" or "bitwise OR" is used between two enum which come from different
- types and these types value ranges are not disjoint.
+1. When "ADD" or "bitwise OR" is used between two enum which come
+ from different types and these types value ranges are not disjoint.
The following cases will be investigated only using :option:`StrictMode`. We
regard the enum as a (suspicious)
@@ -17,17 +17,17 @@ bitmask if the three conditions below are true at the same time:
short enumerations)
* there is another non pow-of-2 number than the enum constant representing all
choices (the result "bitwise OR" operation of all enum elements)
-* enum type variable/enumconstant is used as an argument of a `+` or "bitwise OR
- " operator
+* enum type variable/enumconstant is used as an argument of a `+` or "bitwise
+ OR" operator
So whenever the non pow-of-2 element is used as a bitmask element we diagnose a
misuse and give a warning.
-2. Investigating the right hand side of `+=` and `|=` operator.
-3. Check only the enum value side of a `|` and `+` operator if one of them is not
- enum val.
-4. Check both side of `|` or `+` operator where the enum values are from the
- same enum type.
+2. Investigating the right hand side of ``+=`` and ``|=`` operator.
+3. Check only the enum value side of a ``|`` and ``+`` operator if one of
+ them is not enum val.
+4. Check both side of ``|`` or ``+`` operator where the enum values are from
+ the same enum type.
Examples:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-memory-comparison.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-memory-comparison.rst
index f82863f..317f8e1 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-memory-comparison.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-memory-comparison.rst
@@ -24,10 +24,12 @@ and
<https://wiki.sei.cmu.edu/confluence/display/c/FLP37-C.+Do+not+use+object+representations+to+compare+floating-point+values>`_
This check is also related to and partially overlaps the CERT C++ Coding Standard rules
-`OOP57-CPP. Prefer special member functions and overloaded operators to C Standard Library functions
+`OOP57-CPP. Prefer special member functions and overloaded operators to
+C Standard Library functions
<https://wiki.sei.cmu.edu/confluence/display/cplusplus/OOP57-CPP.+Prefer+special+member+functions+and+overloaded+operators+to+C+Standard+Library+functions>`_
and
-`EXP62-CPP. Do not access the bits of an object representation that are not part of the object's value representation
+`EXP62-CPP. Do not access the bits of an object representation that are not
+part of the object's value representation
<https://wiki.sei.cmu.edu/confluence/display/cplusplus/EXP62-CPP.+Do+not+access+the+bits+of+an+object+representation+that+are+not+part+of+the+object%27s+value+representation>`_
`cert-exp42-c` redirects here as an alias of this check.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-realloc-usage.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-realloc-usage.rst
index 67e416b..9885d9c 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-realloc-usage.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-realloc-usage.rst
@@ -3,17 +3,18 @@
bugprone-suspicious-realloc-usage
=================================
-This check finds usages of ``realloc`` where the return value is assigned to the
-same expression as passed to the first argument:
+This check finds usages of ``realloc`` where the return value is assigned to
+the same expression as passed to the first argument:
``p = realloc(p, size);``
The problem with this construct is that if ``realloc`` fails it returns a
null pointer but does not deallocate the original memory. If no other variable
is pointing to it, the original memory block is not available any more for the
program to use or free. In either case ``p = realloc(p, size);`` indicates bad
-coding style and can be replaced by ``q = realloc(p, size);``.
+coding style and can be replaced by ``q = realloc(p, size);``.
-The pointer expression (used at ``realloc``) can be a variable or a field member
-of a data structure, but can not contain function calls or unresolved types.
+The pointer expression (used at ``realloc``) can be a variable or a field
+member of a data structure, but can not contain function calls or unresolved
+types.
In obvious cases when the pointer used at realloc is assigned to another
variable before the ``realloc`` call, no warning is emitted. This happens only
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-semicolon.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-semicolon.rst
index 76c891f..56e23d77 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-semicolon.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-semicolon.rst
@@ -5,9 +5,9 @@ bugprone-suspicious-semicolon
Finds most instances of stray semicolons that unexpectedly alter the meaning of
the code. More specifically, it looks for ``if``, ``while``, ``for`` and
-``for-range`` statements whose body is a single semicolon, and then analyzes the
-context of the code (e.g. indentation) in an attempt to determine whether that
-is intentional.
+``for-range`` statements whose body is a single semicolon, and then analyzes
+the context of the code (e.g. indentation) in an attempt to determine whether
+that is intentional.
.. code-block:: c++
@@ -26,8 +26,8 @@ of the first line, and `x` will be incremented regardless of the condition.
processLine(line);
As a result of this code, `processLine()` will only be called once, when the
-``while`` loop with the empty body exits with `line == NULL`. The indentation of
-the code indicates the intention of the programmer.
+``while`` loop with the empty body exits with ``line == NULL``. The indentation
+of the code indicates the intention of the programmer.
.. code-block:: c++
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-string-compare.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-string-compare.rst
index 85e1796..973b703 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-string-compare.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-string-compare.rst
@@ -30,8 +30,8 @@ A common mistake is to compare the result to `1` or `-1`.
if (strcmp(...) == -1) // Incorrect usage of the returned value.
Additionally, the check warns if the results value is implicitly cast to a
-*suspicious* non-integer type. It's happening when the returned value is used in
-a wrong context.
+*suspicious* non-integer type. It's happening when the returned value is
+used in a wrong context.
.. code-block:: c++
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/swapped-arguments.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/swapped-arguments.rst
index 674108f..e798b67 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/swapped-arguments.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/swapped-arguments.rst
@@ -34,8 +34,8 @@ dealing with floating-point arguments, implicit casts between different
floating-point types are considered acceptable.
To avoid confusion, swaps where both swapped arguments are of integral types or
-both are of floating-point types do not trigger the warning. In such cases, it's
-assumed that the developer intentionally used different integral or
+both are of floating-point types do not trigger the warning. In such cases,
+it's assumed that the developer intentionally used different integral or
floating-point types and does not raise a warning. This approach prevents false
-positives and provides flexibility in handling situations where varying integral
-or floating-point types are intentionally utilized.
+positives and provides flexibility in handling situations where varying
+integral or floating-point types are intentionally utilized.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst
index 3ce862f..0f0e549 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst
@@ -51,6 +51,6 @@ Example:
on non-enum types where the compiler warnings may not be present.
.. seealso::
- The `CppCoreGuideline ES.79 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-default>`_
+ The `CppCoreGuideline ES.79 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#res-default>`_
provide guidelines on switch statements, including the recommendation to
always provide a default case.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/tagged-union-member-count.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/tagged-union-member-count.rst
index 072b5a3..5ac5e32 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/tagged-union-member-count.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/tagged-union-member-count.rst
@@ -9,7 +9,7 @@ different from the number of data members inside the union.
A struct or a class is considered to be a tagged union if it has
exactly one union data member and exactly one enum data member and
any number of other data members that are neither unions or enums.
-Furthermore, the types of the union and the enum members must
+Furthermore, the types of the union and the enum members must
not come from system header files nor the ``std`` namespace.
Example:
@@ -53,10 +53,10 @@ How enum constants are counted
------------------------------
The main complicating factor when counting the number of enum constants is that
-some of them might be auxiliary values that purposefully don't have a corresponding union
-data member and are used for something else. For example the last enum constant
-sometimes explicitly "points to" the last declared valid enum constant or
-tracks how many enum constants have been declared.
+some of them might be auxiliary values that purposefully don't have a
+corresponding union data member and are used for something else. For example
+the last enum constant sometimes explicitly "points to" the last declared valid
+enum constant or tracks how many enum constants have been declared.
For an illustration:
@@ -76,23 +76,24 @@ For an illustration:
TagCount, // is 3
};
-The check counts the number of distinct values among the enum constants and not the enum
-constants themselves. This way the enum constants that are essentially just aliases of other
-enum constants are not included in the final count.
+The check counts the number of distinct values among the enum constants and not
+the enum constants themselves. This way the enum constants that are essentially
+just aliases of other enum constants are not included in the final count.
-Handling of counting enum constants (ones like :code:`TagCount` in the previous code example)
-is done by decreasing the number of enum values by one if the name of the last enum constant
-starts with a prefix or ends with a suffix specified in :option:`CountingEnumPrefixes`,
-:option:`CountingEnumSuffixes` and it's value is one less than the total number of distinct
-values in the enum.
+Handling of counting enum constants (ones like :code:`TagCount` in the previous
+code example) is done by decreasing the number of enum values by one if the name
+of the last enum constant starts with a prefix or ends with a suffix specified in
+:option:`CountingEnumPrefixes`, :option:`CountingEnumSuffixes` and it's value is
+one less than the total number of distinct values in the enum.
-When the final count is adjusted based on this heuristic then a diagnostic note is emitted
-that shows which enum constant matched the criteria.
+When the final count is adjusted based on this heuristic then a diagnostic note
+is emitted that shows which enum constant matched the criteria.
-The heuristic can be disabled entirely (:option:`EnableCountingEnumHeuristic`) or
-configured to follow your naming convention (:option:`CountingEnumPrefixes`, :option:`CountingEnumSuffixes`).
-The strings specified in :option:`CountingEnumPrefixes`, :option:`CountingEnumSuffixes` are matched
-case insensitively.
+The heuristic can be disabled entirely (:option:`EnableCountingEnumHeuristic`)
+or configured to follow your naming convention (:option:`CountingEnumPrefixes`,
+:option:`CountingEnumSuffixes`).
+The strings specified in :option:`CountingEnumPrefixes`,
+:option:`CountingEnumSuffixes` are matched case insensitively.
Example counts:
@@ -184,8 +185,8 @@ If :option:`EnableCountingEnumHeuristic` is `false` then these options do nothin
The default value of :option:`CountingEnumSuffixes` is `count` and of
:option:`CountingEnumPrefixes` is the empty string.
-When :option:`EnableCountingEnumHeuristic` is `true` and :option:`CountingEnumSuffixes`
-is `count;size`:
+When :option:`EnableCountingEnumHeuristic` is `true` and
+:option:`CountingEnumSuffixes` is `count;size`:
.. code-block:: c++
@@ -223,7 +224,8 @@ is `count;size`:
} Data;
};
-When :option:`EnableCountingEnumHeuristic` is `true` and :option:`CountingEnumPrefixes` is `maxsize;last_`
+When :option:`EnableCountingEnumHeuristic` is `true` and
+:option:`CountingEnumPrefixes` is `maxsize;last_`
.. code-block:: c++
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/throw-keyword-missing.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/throw-keyword-missing.rst
index 240a62e..be80fc8 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/throw-keyword-missing.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/throw-keyword-missing.rst
@@ -3,9 +3,10 @@
bugprone-throw-keyword-missing
==============================
-Warns about a potentially missing ``throw`` keyword. If a temporary object is created, but the
-object's type derives from (or is the same as) a class that has 'EXCEPTION', 'Exception' or
-'exception' in its name, we can assume that the programmer's intention was to throw that object.
+Warns about a potentially missing ``throw`` keyword. If a temporary object
+is created, but the object's type derives from (or is the same as) a class
+that has 'EXCEPTION', 'Exception' or 'exception' in its name, we can assume
+that the programmer's intention was to throw that object.
Example:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/throwing-static-initialization.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/throwing-static-initialization.rst
index 5e320a1..4f88719 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/throwing-static-initialization.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/throwing-static-initialization.rst
@@ -11,4 +11,4 @@ References
This check corresponds to the CERT C++ Coding Standard rule
`ERR58-CPP. Handle all exceptions thrown before main() begins executing
-<https://www.securecoding.cert.org/confluence/display/cplusplus/ERR58-CPP.+Handle+all+exceptions+thrown+before+main%28%29+begins+executing>`_. \ No newline at end of file
+<https://www.securecoding.cert.org/confluence/display/cplusplus/ERR58-CPP.+Handle+all+exceptions+thrown+before+main%28%29+begins+executing>`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/too-small-loop-variable.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/too-small-loop-variable.rst
index 077abf0..efba0cc 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/too-small-loop-variable.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/too-small-loop-variable.rst
@@ -14,10 +14,11 @@ iteration range.
for (short i = 0; i < size; ++i) {}
}
-This ``for`` loop is an infinite loop because the ``short`` type can't represent
-all values in the ``[0..size]`` interval.
+This ``for`` loop is an infinite loop because the ``short`` type can't
+represent all values in the ``[0..size]`` interval.
-In a real use case size means a container's size which depends on the user input.
+In a real use case size means a container's size which depends on the
+user input.
.. code-block:: c++
@@ -29,8 +30,9 @@ This algorithm works for a small amount of objects, but will lead to freeze for
a larger user input.
It's recommended to enable the compiler warning
-`-Wtautological-constant-out-of-range-compare` as well, since check does not
-inspect compile-time constant loop boundaries to avoid overlaps with the warning.
+`-Wtautological-constant-out-of-range-compare` as well, since check does
+not inspect compile-time constant loop boundaries to avoid overlaps with
+the warning.
Options
-------
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unchecked-optional-access.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unchecked-optional-access.rst
index 552e6db..3423eaa 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unchecked-optional-access.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unchecked-optional-access.rst
@@ -15,9 +15,10 @@ types collectively as ``optional<T>``.
An access to the value of an ``optional<T>`` occurs when one of its ``value``,
``operator*``, or ``operator->`` member functions is invoked. To align with
-common misconceptions, the check considers these member functions as equivalent,
-even though there are subtle differences related to exceptions versus undefined
-behavior. See *Additional notes*, below, for more information on this topic.
+common misconceptions, the check considers these member functions as
+equivalent, even though there are subtle differences related to exceptions
+versus undefined behavior. See *Additional notes*, below, for more information
+on this topic.
An access to the value of an ``optional<T>`` is considered safe if and only if
code in the local scope (for example, a function body) ensures that the
@@ -208,8 +209,8 @@ local variable and use that variable to access the value. For example:
Do not rely on uncommon-API invariants
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-When uncommon APIs guarantee that an optional has contents, do not rely on it --
-instead, check explicitly that the optional object has a value. For example:
+When uncommon APIs guarantee that an optional has contents, do not rely on it
+-- instead, check explicitly that the optional object has a value. For example:
.. code-block:: c++
@@ -293,8 +294,8 @@ or terminating the program), why treat it the same as ``operator*()`` which
causes undefined behavior (UB)? That is, why is it considered unsafe to access
an optional with ``value()``, if it's not provably populated with a value? For
that matter, why is ``CHECK()`` followed by ``operator*()`` any better than
-``value()``, given that they are semantically equivalent (on configurations that
-disable exceptions)?
+``value()``, given that they are semantically equivalent (on configurations
+that disable exceptions)?
The answer is that we assume most users do not realize the difference between
``value()`` and ``operator*()``. Shifting to ``operator*()`` and some form of
@@ -308,3 +309,22 @@ advantages:
* Performance. A single check can cover many or even all accesses within
scope. This gives the user the best of both worlds -- the safety of a
dynamic check, but without incurring redundant costs.
+
+Options
+-------
+
+.. option:: IgnoreSmartPointerDereference
+
+ If set to `true`, the check ignores optionals that
+ are reached through overloaded smart-pointer-like dereference (``operator*``,
+ ``operator->``) on classes other than the optional type itself. This helps
+ avoid false positives where the analysis cannot equate results across such
+ calls. This does not cover access through ``operator[]``. Default is `false`.
+
+.. option:: IgnoreValueCalls
+
+ If set to `true`, the check does not diagnose calls
+ to ``optional::value()``. Diagnostics for ``operator*()`` and
+ ``operator->()`` remain enabled. This is useful for codebases that
+ intentionally rely on ``value()`` for defined, guarded access while still
+ flagging UB-prone operator dereferences. Default is `false`.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unchecked-string-to-number-conversion.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unchecked-string-to-number-conversion.rst
index c3ea196..e38b298 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unchecked-string-to-number-conversion.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unchecked-string-to-number-conversion.rst
@@ -5,8 +5,8 @@ bugprone-unchecked-string-to-number-conversion
This check flags calls to string-to-number conversion functions that do not
verify the validity of the conversion, such as ``atoi()`` or ``scanf()``. It
-does not flag calls to ``strtol()``, or other, related conversion functions that
-do perform better error checking.
+does not flag calls to ``strtol()``, or other, related conversion functions
+that do perform better error checking.
.. code-block:: c
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unhandled-self-assignment.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unhandled-self-assignment.rst
index 3a6245d..07c4b33 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unhandled-self-assignment.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unhandled-self-assignment.rst
@@ -10,9 +10,10 @@ Finds user-defined copy assignment operators which do not protect the code
against self-assignment either by checking self-assignment explicitly or
using the copy-and-swap or the copy-and-move method.
-By default, this check searches only those classes which have any pointer or C array field
-to avoid false positives. In case of a pointer or a C array, it's likely that self-copy
-assignment breaks the object if the copy assignment operator was not written with care.
+By default, this check searches only those classes which have any pointer or C
+array field to avoid false positives. In case of a pointer or a C array, it's
+likely that self-copy assignment breaks the object if the copy assignment
+operator was not written with care.
See also:
`OOP54-CPP. Gracefully handle self-copy assignment
@@ -90,9 +91,9 @@ The second one is the copy-and-swap method when we create a temporary copy
}
};
-There is a third pattern which is less common. Let's call it the copy-and-move method
-when we create a temporary copy (using the copy constructor) and then move this
-temporary object into ``this`` (needs a move assignment operator):
+There is a third pattern which is less common. Let's call it the copy-and-move
+method when we create a temporary copy (using the copy constructor) and then move
+this temporary object into ``this`` (needs a move assignment operator):
.. code-block:: c++
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unintended-char-ostream-output.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unintended-char-ostream-output.rst
index 29254c4..da510c4 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unintended-char-ostream-output.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unintended-char-ostream-output.rst
@@ -3,14 +3,14 @@
bugprone-unintended-char-ostream-output
=======================================
-Finds unintended character output from ``unsigned char`` and ``signed char`` to an
-``ostream``.
+Finds unintended character output from ``unsigned char`` and ``signed char`` to
+an ``ostream``.
-Normally, when ``unsigned char (uint8_t)`` or ``signed char (int8_t)`` is used, it
-is more likely a number than a character. However, when it is passed directly to
-``std::ostream``'s ``operator<<``, the result is the character output instead
-of the numeric value. This often contradicts the developer's intent to print
-integer values.
+Normally, when ``unsigned char (uint8_t)`` or ``signed char (int8_t)`` is used,
+it is more likely a number than a character. However, when it is passed
+directly to ``std::ostream``'s ``operator<<``, the result is the character
+output instead of the numeric value. This often contradicts the developer's
+intent to print integer values.
.. code-block:: c++
@@ -26,8 +26,9 @@ intent, by default, it will cast to ``unsigned int`` for ``unsigned char`` and
std::cout << static_cast<unsigned int>(v); // when v is unsigned char
std::cout << static_cast<int>(v); // when v is signed char
-To avoid lengthy cast statements, add prefix ``+`` to the variable can also
-suppress warnings because unary expression will promote the value to an ``int``.
+To avoid lengthy cast statements, add prefix ``+`` to the variable can
+also suppress warnings because unary expression will promote the value
+to an ``int``.
.. code-block:: c++
@@ -44,11 +45,11 @@ Options
.. option:: AllowedTypes
- A semicolon-separated list of type names that will be treated like the ``char``
- type: the check will not report variables declared with with these types or
- explicit cast expressions to these types. Note that this distinguishes type
- aliases from the original type, so specifying e.g. ``unsigned char`` here
- will not suppress reports about ``uint8_t`` even if it is defined as a
+ A semicolon-separated list of type names that will be treated like the ``char``
+ type: the check will not report variables declared with with these types or
+ explicit cast expressions to these types. Note that this distinguishes type
+ aliases from the original type, so specifying e.g. ``unsigned char`` here
+ will not suppress reports about ``uint8_t`` even if it is defined as a
``typedef`` alias for ``unsigned char``.
Default is `unsigned char;signed char`.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unsafe-functions.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unsafe-functions.rst
index 317db9c..cb7ea41 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unsafe-functions.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unsafe-functions.rst
@@ -19,7 +19,8 @@ The check implements the following rules from the CERT C Coding Standard:
Unsafe functions
----------------
-The following functions are reported if :option:`ReportDefaultFunctions` is enabled.
+The following functions are reported if :option:`ReportDefaultFunctions`
+is enabled.
If *Annex K.* is available, a replacement from *Annex K.* is suggested for the
following functions:
@@ -42,7 +43,8 @@ following functions from the previous list:
- ``asctime``, ``asctime_r``, suggested replacement: ``strftime``
- ``gets``, suggested replacement: ``fgets``
-The following functions are always checked, regardless of *Annex K* availability:
+The following functions are always checked, regardless of *Annex K*
+availability:
- ``rewind``, suggested replacement: ``fseek``
- ``setbuf``, suggested replacement: ``setvbuf``
@@ -80,13 +82,13 @@ including any system headers.
Custom functions
----------------
-The option :option:`CustomFunctions` allows the user to define custom functions to be
-checked. The format is the following, without newlines:
+The option :option:`CustomFunctions` allows the user to define custom functions
+to be checked. The format is the following, without newlines:
.. code::
bugprone-unsafe-functions.CustomFunctions="
- functionRegex1[, replacement1[, reason1]];
+ functionRegex1[, replacement1[, reason1]];
functionRegex2[, replacement2[, reason2]];
...
"
@@ -94,36 +96,62 @@ checked. The format is the following, without newlines:
The functions are matched using POSIX extended regular expressions.
*(Note: The regular expressions do not support negative* ``(?!)`` *matches.)*
-The `reason` is optional and is used to provide additional information about the
-reasoning behind the replacement. The default reason is `is marked as unsafe`.
+The ``reason`` is optional and is used to provide additional information about the
+reasoning behind the replacement. The default reason is ``is marked as unsafe``.
-If `replacement` is empty, the text `it should not be used` will be shown
-instead of the suggestion for a replacement.
+If ``replacement`` is empty, the default text ``it should not be used`` will be
+shown instead of the suggestion for a replacement.
-As an example, the configuration `^original$, replacement, is deprecated;`
-will produce the following diagnostic message.
+If the ``reason`` starts with the character ``>``, the reason becomes fully custom.
+The default suffix is disabled even if a ``replacement`` is present, and only the
+reason message is shown after the matched function, to allow better control over
+the suggestions. (The starting ``>`` and whitespace directly after it are
+trimmed from the message.)
+
+As an example, the following configuration matches only the function ``original``
+in the default namespace. A similar diagnostic can also be printed using a fully
+custom reason.
.. code:: c
-
+
+ // bugprone-unsafe-functions.CustomFunctions:
+ // ^original$, replacement, is deprecated;
+ // Using the fully custom message syntax:
+ // ^suspicious$,,> should be avoided if possible.
original(); // warning: function 'original' is deprecated; 'replacement' should be used instead.
+ suspicious(); // warning: function 'suspicious' should be avoided if possible.
::std::original(); // no-warning
original_function(); // no-warning
-If the regular expression contains the character `:`, it is matched against the
-qualified name (i.e. ``std::original``), otherwise the regex is matched against the unqualified name (``original``).
-If the regular expression starts with `::` (or `^::`), it is matched against the
-fully qualified name (``::std::original``).
+If the regular expression contains the character ``:``, it is matched against the
+qualified name (i.e. ``std::original``), otherwise the regex is matched against
+the unqualified name (``original``). If the regular expression starts with ``::``
+(or ``^::``), it is matched against the fully qualified name
+(``::std::original``).
+
+One of the use cases for fully custom messages is suggesting compiler options
+and warning flags:
+
+.. code:: c
+
+ // bugprone-unsafe-functions.CustomFunctions:
+ // ^memcpy$,,>is recommended to have compiler hardening using '_FORTIFY_SOURCE';
+ // ^printf$,,>is recommended to have the '-Werror=format-security' compiler warning flag;
+
+ memcpy(dest, src, 999'999); // warning: function 'memcpy' is recommended to have compiler hardening using '_FORTIFY_SOURCE'
+ printf(raw_str); // warning: function 'printf' is recommended to have the '-Werror=format-security' compiler warning flag
.. note::
- Fully qualified names can contain template parameters on certain C++ classes, but not on C++ functions.
- Type aliases are resolved before matching.
+ Fully qualified names can contain template parameters on certain C++ classes,
+ but not on C++ functions. Type aliases are resolved before matching.
As an example, the member function ``open`` in the class ``std::ifstream``
has a fully qualified name of ``::std::basic_ifstream<char>::open``.
- The example could also be matched with the regex ``::std::basic_ifstream<[^>]*>::open``, which matches all potential
- template parameters, but does not match nested template classes.
+ The example could also be matched with the regex
+ ``::std::basic_ifstream<[^>]*>::open``, which matches all potential template
+ parameters, but does not match nested template classes.
Options
-------
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
index 10ae0fe..725403a 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
@@ -3,7 +3,8 @@
bugprone-unused-return-value
============================
-Warns on unused function return values. The checked functions can be configured.
+Warns on unused function return values. The checked functions can be
+configured.
Operator overloading with assignment semantics are ignored.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/use-after-move.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/use-after-move.rst
index 965fc2d..77424d3 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/use-after-move.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/use-after-move.rst
@@ -83,9 +83,9 @@ move:
std::cout << str;
}
-If you want to avoid the overhead of actually reinitializing the object, you can
-create a dummy function that causes the check to assume the object was
-reinitialized:
+If you want to avoid the overhead of actually reinitializing the object,
+you can create a dummy function that causes the check to assume the object
+was reinitialized:
.. code-block:: c++
@@ -104,9 +104,9 @@ You can use this as follows:
std::cout << str;
}
-The check will not output a warning in this case because passing the object to a
-function as a non-const pointer or reference counts as a reinitialization (see section
-`Reinitialization`_ below).
+The check will not output a warning in this case because passing the object
+to a function as a non-const pointer or reference counts as a reinitialization
+(see section `Reinitialization`_ below).
Unsequenced moves, uses, and reinitializations
----------------------------------------------
@@ -143,10 +143,10 @@ reference parameter.
This means that the check will flag a use-after-move even on a type that does
not define a move constructor or move assignment operator. This is intentional.
-Developers may use ``std::move`` on such a type in the expectation that the type
-will add move semantics in the future. If such a ``std::move`` has the potential
-to cause a use-after-move, we want to warn about it even if the type does not
-implement move semantics yet.
+Developers may use ``std::move`` on such a type in the expectation that the
+type will add move semantics in the future. If such a ``std::move`` has the
+potential to cause a use-after-move, we want to warn about it even if the type
+does not implement move semantics yet.
Furthermore, if the result of ``std::move`` *is* passed to an rvalue reference
parameter, this will always be considered to cause a move, even if the function
@@ -169,9 +169,9 @@ that a move always takes place:
The check will assume that the last line causes a move, even though, in this
particular case, it does not. Again, this is intentional.
-There is one special case: A call to ``std::move`` inside a ``try_emplace`` call
-is conservatively assumed not to move. This is to avoid spurious warnings, as
-the check has no way to reason about the ``bool`` returned by ``try_emplace``.
+There is one special case: A call to ``std::move`` inside a ``try_emplace``
+call is conservatively assumed not to move. This is to avoid spurious warnings,
+as the check has no way to reason about the ``bool`` returned by ``try_emplace``.
When analyzing the order in which moves, uses and reinitializations happen (see
section `Unsequenced moves, uses, and reinitializations`_), the move is assumed
@@ -198,8 +198,8 @@ is considered to be a use.
An exception to this are objects of type ``std::unique_ptr``,
``std::shared_ptr``, ``std::weak_ptr``, ``std::optional``, and ``std::any``.
An exception to this are objects of type ``std::unique_ptr``,
-``std::shared_ptr``, ``std::weak_ptr``, ``std::optional``, and ``std::any``, which
-can be reinitialized via ``reset``. For smart pointers specifically, the
+``std::shared_ptr``, ``std::weak_ptr``, ``std::optional``, and ``std::any``,
+which can be reinitialized via ``reset``. For smart pointers specifically, the
moved-from objects have a well-defined state of being ``nullptr``s, and only
``operator*``, ``operator->`` and ``operator[]`` are considered bad accesses as
they would be dereferencing a ``nullptr``.
@@ -217,10 +217,10 @@ The check considers a variable to be reinitialized in the following cases:
lvalue reference. (It is assumed that the variable may be an out-parameter
for the function.)
- - ``clear()`` or ``assign()`` is called on the variable and the variable is of
- one of the standard container types ``basic_string``, ``vector``, ``deque``,
- ``forward_list``, ``list``, ``set``, ``map``, ``multiset``, ``multimap``,
- ``unordered_set``, ``unordered_map``, ``unordered_multiset``,
+ - ``clear()`` or ``assign()`` is called on the variable and the variable is
+ of one of the standard container types ``basic_string``, ``vector``,
+ ``deque``, ``forward_list``, ``list``, ``set``, ``map``, ``multiset``,
+ ``multimap``, ``unordered_set``, ``unordered_map``, ``unordered_multiset``,
``unordered_multimap``.
- ``reset()`` is called on the variable and the variable is of type
@@ -253,3 +253,13 @@ For example, if an additional member variable is added to ``S``, it is easy to
forget to add the reinitialization for this additional member. Instead, it is
safer to assign to the entire struct in one go, and this will also avoid the
use-after-move warning.
+
+Options
+-------
+
+.. option:: InvalidationFunctions
+
+ A semicolon-separated list of names of functions that cause their first
+ arguments to be invalidated (e.g., closing a handle).
+ For member functions, the first argument is considered to be the implicit
+ object argument (``this``). Default value is an empty string.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/virtual-near-miss.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/virtual-near-miss.rst
index b3f02b8..d422684 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/virtual-near-miss.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/virtual-near-miss.rst
@@ -3,8 +3,9 @@
bugprone-virtual-near-miss
==========================
-Warn if a function is a near miss (i.e. the name is very similar and the function
-signature is the same) to a virtual function from a base class.
+Warn if a function is a near miss (i.e. the name is very similar and
+the function signature is the same) to a virtual function from a base
+class.
Example:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/con36-c.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/con36-c.rst
index 2a1d517..95f70d8 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/con36-c.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/con36-c.rst
@@ -6,5 +6,6 @@ cert-con36-c
============
The `cert-con36-c` check is an alias, please see
-:doc:`bugprone-spuriously-wake-up-functions <../bugprone/spuriously-wake-up-functions>`
+:doc:`bugprone-spuriously-wake-up-functions
+<../bugprone/spuriously-wake-up-functions>`
for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/con54-cpp.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/con54-cpp.rst
index 3b4039d..c8cc8bd 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/con54-cpp.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/con54-cpp.rst
@@ -6,5 +6,6 @@ cert-con54-cpp
==============
The `cert-con54-cpp` check is an alias, please see
-:doc:`bugprone-spuriously-wake-up-functions <../bugprone/spuriously-wake-up-functions>`
+:doc:`bugprone-spuriously-wake-up-functions
+<../bugprone/spuriously-wake-up-functions>`
for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/ctr56-cpp.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/ctr56-cpp.rst
index e42acbe..78afc2f 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/ctr56-cpp.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/ctr56-cpp.rst
@@ -7,4 +7,4 @@ cert-ctr56-cpp
The `cert-ctr56-cpp` check is an alias, please see
:doc:`bugprone-pointer-arithmetic-on-polymorphic-object
-<../bugprone/pointer-arithmetic-on-polymorphic-object>` for more information. \ No newline at end of file
+<../bugprone/pointer-arithmetic-on-polymorphic-object>` for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/dcl16-c.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/dcl16-c.rst
index 7a5b63d..977a0a5 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/dcl16-c.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/dcl16-c.rst
@@ -6,4 +6,5 @@ cert-dcl16-c
============
The `cert-dcl16-c` check is an alias, please see
-:doc:`readability-uppercase-literal-suffix <../readability/uppercase-literal-suffix>` for more information.
+:doc:`readability-uppercase-literal-suffix
+<../readability/uppercase-literal-suffix>` for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/dcl50-cpp.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/dcl50-cpp.rst
index 719e03d..dd4bd30 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/dcl50-cpp.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/dcl50-cpp.rst
@@ -6,7 +6,8 @@ cert-dcl50-cpp
==============
The `cert-dcl50-cpp` check is an alias, please see
-`modernize-avoid-variadic-functions <../modernize/avoid-variadic-functions.html>`_
+:doc:`modernize-avoid-variadic-functions
+<../modernize/avoid-variadic-functions>`
for more information.
This check corresponds to the CERT C++ Coding Standard rule
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/dcl58-cpp.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/dcl58-cpp.rst
index fbcc6281..f584e88 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/dcl58-cpp.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/dcl58-cpp.rst
@@ -3,57 +3,10 @@
cert-dcl58-cpp
==============
-Modification of the ``std`` or ``posix`` namespace can result in undefined
-behavior.
-This check warns for such modifications.
-The ``std`` (or ``posix``) namespace is allowed to be extended with (class or
-function) template specializations that depend on an user-defined type (a type
-that is not defined in the standard system headers).
-
-The check detects the following (user provided) declarations in namespace ``std`` or ``posix``:
-
-- Anything that is not a template specialization.
-- Explicit specializations of any standard library function template or class template, if it does not have any user-defined type as template argument.
-- Explicit specializations of any member function of a standard library class template.
-- Explicit specializations of any member function template of a standard library class or class template.
-- Explicit or partial specialization of any member class template of a standard library class or class template.
-
-Examples:
-
-.. code-block:: c++
-
- namespace std {
- int x; // warning: modification of 'std' namespace can result in undefined behavior [cert-dcl58-cpp]
- }
-
- namespace posix::a { // warning: modification of 'posix' namespace can result in undefined behavior
- }
-
- template <>
- struct ::std::hash<long> { // warning: modification of 'std' namespace can result in undefined behavior
- unsigned long operator()(const long &K) const {
- return K;
- }
- };
-
- struct MyData { long data; };
-
- template <>
- struct ::std::hash<MyData> { // no warning: specialization with user-defined type
- unsigned long operator()(const MyData &K) const {
- return K.data;
- }
- };
-
- namespace std {
- template <>
- void swap<bool>(bool &a, bool &b); // warning: modification of 'std' namespace can result in undefined behavior
-
- template <>
- bool less<void>::operator()<MyData &&, MyData &&>(MyData &&, MyData &&) const { // warning: modification of 'std' namespace can result in undefined behavior
- return true;
- }
- }
+The `cert-dcl58-cpp` is an alias, please see
+:doc:`bugprone-std-namespace-modification
+<../bugprone/std-namespace-modification>`
+for more information.
This check corresponds to the CERT C++ Coding Standard rule
`DCL58-CPP. Do not modify the standard namespaces
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/dcl59-cpp.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/dcl59-cpp.rst
index 9aeed14..027d2ec 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/dcl59-cpp.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/dcl59-cpp.rst
@@ -6,4 +6,5 @@ cert-dcl59-cpp
==============
The `cert-dcl59-cpp` check is an alias, please see
-:doc:`google-build-namespaces <../google/build-namespaces>` for more information.
+:doc:`google-build-namespaces <../google/build-namespaces>`
+for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/env33-c.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/env33-c.rst
index 751bccf..33fa7f1 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/env33-c.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/env33-c.rst
@@ -4,7 +4,7 @@ cert-env33-c
============
The `cert-env33-c` check is an alias, please see
-`bugprone-command-processor <../bugprone/command-processor.html>`_
+:doc:`bugprone-command-processor <../bugprone/command-processor>`
for more information.
This check corresponds to the CERT C Coding Standard rule
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/err09-cpp.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/err09-cpp.rst
index 1a9c0f9..65d3a60 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/err09-cpp.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/err09-cpp.rst
@@ -6,10 +6,12 @@ cert-err09-cpp
==============
The `cert-err09-cpp` check is an alias, please see
-:doc:`misc-throw-by-value-catch-by-reference <../misc/throw-by-value-catch-by-reference>`
+:doc:`misc-throw-by-value-catch-by-reference
+<../misc/throw-by-value-catch-by-reference>`
for more information.
This check corresponds to the CERT C++ Coding Standard recommendation
-ERR09-CPP. Throw anonymous temporaries. However, all of the CERT recommendations
-have been removed from public view, and so their justification for the behavior
-of this check requires an account on their wiki to view.
+ERR09-CPP. Throw anonymous temporaries. However, all of the CERT
+recommendations have been removed from public view, and so their
+justification for the behavior of this check requires an account on
+their wiki to view.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/err33-c.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/err33-c.rst
index 9bcc5f9..75da669 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/err33-c.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/err33-c.rst
@@ -186,8 +186,8 @@ functions are checked:
* wscanf()
* wscanf_s()
-This check is an alias of check :doc:`bugprone-unused-return-value <../bugprone/unused-return-value>`
-with a fixed set of functions.
+This check is an alias of check :doc:`bugprone-unused-return-value
+<../bugprone/unused-return-value>` with a fixed set of functions.
Suppressing issues by casting to ``void`` is enabled by default and can be
disabled by setting `AllowCastToVoid` option to `false`.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/err34-c.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/err34-c.rst
index dc3f632..5f0dc80 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/err34-c.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/err34-c.rst
@@ -6,5 +6,6 @@ cert-err34-c
============
The cert-err34-c check is an alias, please see
-`bugprone-unchecked-string-to-number-conversion <../bugprone/unchecked-string-to-number-conversion.html>`_
+:doc:`bugprone-unchecked-string-to-number-conversion
+<../bugprone/unchecked-string-to-number-conversion>`
for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/err52-cpp.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/err52-cpp.rst
index 144d209b..4b726d81 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/err52-cpp.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/err52-cpp.rst
@@ -4,7 +4,7 @@ cert-err52-cpp
==============
The `cert-err52-cpp` check is an alias, please see
-`modernize-avoid-setjmp-longjmp <../modernize/avoid-setjmp-longjmp.html>`_
+:doc:`modernize-avoid-setjmp-longjmp <../modernize/avoid-setjmp-longjmp>`
for more information.
This check corresponds to the CERT C++ Coding Standard rule
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/err58-cpp.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/err58-cpp.rst
index 4db0727..c5e2850 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/err58-cpp.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/err58-cpp.rst
@@ -6,7 +6,8 @@ cert-err58-cpp
==============
The `cert-err58-cpp` check is an alias, please see
-`bugprone-throwing-static-initialization <../bugprone/throwing-static-initialization.html>`_
+:doc:`bugprone-throwing-static-initialization
+<../bugprone/throwing-static-initialization>`
for more information.
This check corresponds to the CERT C++ Coding Standard rule
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/err60-cpp.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/err60-cpp.rst
index 9fcb840..f5ed313 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/err60-cpp.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/err60-cpp.rst
@@ -1,11 +1,15 @@
.. title:: clang-tidy - cert-err60-cpp
+.. meta::
+ :http-equiv=refresh: 5;URL=../bugprone/exception-copy-constructor-throws.html
cert-err60-cpp
==============
-This check flags all throw expressions where the exception object is not nothrow
-copy constructible.
+The `cert-err60-cpp` check is an alias, please see
+:doc:`bugprone-exception-copy-constructor-throws
+<../bugprone/exception-copy-constructor-throws>`
+for more information.
This check corresponds to the CERT C++ Coding Standard rule
`ERR60-CPP. Exception objects must be nothrow copy constructible
-<https://www.securecoding.cert.org/confluence/display/cplusplus/ERR60-CPP.+Exception+objects+must+be+nothrow+copy+constructible>`_.
+<https://wiki.sei.cmu.edu/confluence/display/cplusplus/ERR60-CPP.+Exception+objects+must+be+nothrow+copy+constructible>`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/err61-cpp.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/err61-cpp.rst
index 9600795..2cf7813 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/err61-cpp.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/err61-cpp.rst
@@ -6,5 +6,6 @@ cert-err61-cpp
==============
The `cert-err61-cpp` check is an alias, please see
-:doc:`misc-throw-by-value-catch-by-reference <../misc/throw-by-value-catch-by-reference>`
+:doc:`misc-throw-by-value-catch-by-reference
+<../misc/throw-by-value-catch-by-reference>`
for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/exp42-c.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/exp42-c.rst
index 03a3679..69f9c7a 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/exp42-c.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/exp42-c.rst
@@ -5,4 +5,5 @@ cert-exp42-c
============
The `cert-exp42-c` check is an alias, please see
-:doc:`bugprone-suspicious-memory-comparison <../bugprone/suspicious-memory-comparison>` for more information.
+:doc:`bugprone-suspicious-memory-comparison
+<../bugprone/suspicious-memory-comparison>` for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/fio38-c.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/fio38-c.rst
index aeaaad7..9eaa12f 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/fio38-c.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/fio38-c.rst
@@ -8,3 +8,6 @@ cert-fio38-c
The `cert-fio38-c` check is an alias, please see
:doc:`misc-non-copyable-objects <../misc/non-copyable-objects>` for more
information.
+
+This check corresponds to CERT C++ Coding Standard rule `FIO38-C. Do not copy a FILE object
+<https://www.securecoding.cert.org/confluence/display/c/FIO38-C.+Do+not+copy+a+FILE+object>`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/flp30-c.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/flp30-c.rst
index c37b639..8bd23f6c 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/flp30-c.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/flp30-c.rst
@@ -3,8 +3,9 @@
cert-flp30-c
============
-This check flags ``for`` loops where the induction expression has a
-floating-point type.
+The `cert-flp30-c` check is an alias, please see
+:doc:`bugprone-float-loop-counter <../bugprone/float-loop-counter>`
+for more information
This check corresponds to the CERT C Coding Standard rule
`FLP30-C. Do not use floating-point variables as loop counters
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/flp37-c.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/flp37-c.rst
index 05277ef..01c3544 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/flp37-c.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/flp37-c.rst
@@ -5,4 +5,5 @@ cert-flp37-c
============
The `cert-flp37-c` check is an alias, please see
-:doc:`bugprone-suspicious-memory-comparison <../bugprone/suspicious-memory-comparison>` for more information.
+:doc:`bugprone-suspicious-memory-comparison
+<../bugprone/suspicious-memory-comparison>` for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/mem57-cpp.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/mem57-cpp.rst
index 135cfb8..aeeffec 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/mem57-cpp.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/mem57-cpp.rst
@@ -3,13 +3,10 @@
cert-mem57-cpp
==============
-This check flags uses of default ``operator new`` where the type has extended
-alignment (an alignment greater than the fundamental alignment). (The default
-``operator new`` is guaranteed to provide the correct alignment if the
-requested alignment is less or equal to the fundamental alignment).
-Only cases are detected (by design) where the ``operator new`` is not
-user-defined and is not a placement new (the reason is that in these cases we
-assume that the user provided the correct memory allocation).
+The `cert-mem57-cpp` is an alias, please see
+:doc:`bugprone-default-operator-new-on-overaligned-type
+<../bugprone/default-operator-new-on-overaligned-type>`
+for more information.
This check corresponds to the CERT C++ Coding Standard rule
`MEM57-CPP. Avoid using default operator new for over-aligned types
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/msc30-c.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/msc30-c.rst
index a2898f1..27f92a8 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/msc30-c.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/msc30-c.rst
@@ -1,9 +1,13 @@
.. title:: clang-tidy - cert-msc30-c
.. meta::
- :http-equiv=refresh: 5;URL=../cert/msc50-cpp.html
+ :http-equiv=refresh: 5;URL=../misc/predictable-rand.html
cert-msc30-c
============
The `cert-msc30-c` check is an alias, please see
-:doc:`cert-msc50-cpp <../cert/msc50-cpp>` for more information.
+:doc:`misc-predictable-rand <../misc/predictable-rand>` for more information.
+
+This check corresponds to the CERT C Coding Standard rule
+`MSC30-C. Do not use the rand() function for generating pseudorandom numbers
+<https://wiki.sei.cmu.edu/confluence/display/c/MSC30-C.+Do+not+use+the+rand%28%29+function+for+generating+pseudorandom+numbers>`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/msc32-c.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/msc32-c.rst
index 6e453ed..e0ed807 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/msc32-c.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/msc32-c.rst
@@ -1,9 +1,14 @@
.. title:: clang-tidy - cert-msc32-c
.. meta::
- :http-equiv=refresh: 5;URL=../cert/msc51-cpp.html
+ :http-equiv=refresh: 5;URL=../bugprone/random-generator-seed.html
cert-msc32-c
============
The `cert-msc32-c` check is an alias, please see
-:doc:`cert-msc51-cpp <../cert/msc51-cpp>` for more information.
+:doc:`bugprone-random-generator-seed <../bugprone/random-generator-seed>`
+for more information.
+
+This check corresponds to the CERT C Coding Standard rule
+`MSC32-C. Properly seed pseudorandom number generators
+<https://wiki.sei.cmu.edu/confluence/display/c/MSC32-C.+Properly+seed+pseudorandom+number+generators>`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/msc50-cpp.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/msc50-cpp.rst
index debf01c..59738f5b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/msc50-cpp.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/msc50-cpp.rst
@@ -1,11 +1,13 @@
.. title:: clang-tidy - cert-msc50-cpp
+.. meta::
+ :http-equiv=refresh: 5;URL=../misc/predictable-rand.html
cert-msc50-cpp
==============
-Pseudorandom number generators use mathematical algorithms to produce a sequence
-of numbers with good statistical properties, but the numbers produced are not
-genuinely random. The ``std::rand()`` function takes a seed (number), runs a
-mathematical operation on it and returns the result. By manipulating the seed
-the result can be predictable. This check warns for the usage of
-``std::rand()``.
+The `cert-msc50-cpp` check is an alias, please see
+:doc:`misc-predictable-rand <../misc/predictable-rand>` for more information.
+
+This check corresponds to the CERT C Coding Standard rule
+`MSC50-CPP. Do not use std::rand() for generating pseudorandom numbers
+<https://wiki.sei.cmu.edu/confluence/display/cplusplus/MSC50-CPP.+Do+not+use+std%3A%3Arand%28%29+for+generating+pseudorandom+numbers>`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/msc51-cpp.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/msc51-cpp.rst
index 99e550a..dbaed1d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/msc51-cpp.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/msc51-cpp.rst
@@ -1,40 +1,15 @@
.. title:: clang-tidy - cert-msc51-cpp
+.. meta::
+ :http-equiv=refresh: 5;URL=../bugprone/random-generator-seed.html
cert-msc51-cpp
==============
-This check flags all pseudo-random number engines, engine adaptor
-instantiations and ``srand()`` when initialized or seeded with default argument,
-constant expression or any user-configurable type. Pseudo-random number
-engines seeded with a predictable value may cause vulnerabilities e.g. in
-security protocols.
-This is a CERT security rule, see
-`MSC51-CPP. Ensure your random number generator is properly seeded
-<https://wiki.sei.cmu.edu/confluence/display/cplusplus/MSC51-CPP.+Ensure+your+random+number+generator+is+properly+seeded>`_ and
-`MSC32-C. Properly seed pseudorandom number generators
-<https://wiki.sei.cmu.edu/confluence/display/c/MSC32-C.+Properly+seed+pseudorandom+number+generators>`_.
-
-Examples:
-
-.. code-block:: c++
-
- void foo() {
- std::mt19937 engine1; // Diagnose, always generate the same sequence
- std::mt19937 engine2(1); // Diagnose
- engine1.seed(); // Diagnose
- engine2.seed(1); // Diagnose
-
- std::time_t t;
- engine1.seed(std::time(&t)); // Diagnose, system time might be controlled by user
+The `cert-msc51-cpp` check is an alias, please see
+:doc:`bugprone-random-generator-seed
+<../bugprone/random-generator-seed>`
+for more information.
- int x = atoi(argv[1]);
- std::mt19937 engine3(x); // Will not warn
- }
-
-Options
--------
-
-.. option:: DisallowedSeedTypes
-
- A comma-separated list of the type names which are disallowed.
- Default value is `time_t,std::time_t`.
+This check corresponds to the CERT C++ Coding Standard rule
+`MSC51-CPP. Ensure your random number generator is properly seeded
+<https://wiki.sei.cmu.edu/confluence/display/cplusplus/MSC51-CPP.+Ensure+your+random+number+generator+is+properly+seeded>`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/oop54-cpp.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/oop54-cpp.rst
index e7c9574..1e8b7bb 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/oop54-cpp.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/oop54-cpp.rst
@@ -6,5 +6,6 @@ cert-oop54-cpp
==============
The `cert-oop54-cpp` check is an alias, please see
-:doc:`bugprone-unhandled-self-assignment <../bugprone/unhandled-self-assignment>`
+:doc:`bugprone-unhandled-self-assignment
+<../bugprone/unhandled-self-assignment>`
for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/oop57-cpp.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/oop57-cpp.rst
index 4787abf..9a0f38b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/oop57-cpp.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/oop57-cpp.rst
@@ -1,38 +1,14 @@
.. title:: clang-tidy - cert-oop57-cpp
+.. meta::
+ :http-equiv=refresh: 5;URL=../bugprone/raw-memory-call-on-non-trivial-type.html
cert-oop57-cpp
==============
- Flags use of the `C` standard library functions ``memset``, ``memcpy`` and
- ``memcmp`` and similar derivatives on non-trivial types.
-
-Options
--------
-
-.. option:: MemSetNames
-
- Specify extra functions to flag that act similarly to ``memset``.
- Specify names in a semicolon delimited list.
- Default is an empty string.
- The check will detect the following functions:
- `memset`, `std::memset`.
-
-.. option:: MemCpyNames
-
- Specify extra functions to flag that act similarly to ``memcpy``.
- Specify names in a semicolon delimited list.
- Default is an empty string.
- The check will detect the following functions:
- `std::memcpy`, `memcpy`, `std::memmove`, `memmove`, `std::strcpy`,
- `strcpy`, `memccpy`, `stpncpy`, `strncpy`.
-
-.. option:: MemCmpNames
-
- Specify extra functions to flag that act similarly to ``memcmp``.
- Specify names in a semicolon delimited list.
- Default is an empty string.
- The check will detect the following functions:
- `std::memcmp`, `memcmp`, `std::strcmp`, `strcmp`, `strncmp`.
+The `cert-oop57-cpp` check is an alias, please see
+:doc:`bugprone-raw-memory-call-on-non-trivial-type
+<../bugprone/raw-memory-call-on-non-trivial-type>`
+for more information.
This check corresponds to the CERT C++ Coding Standard rule
`OOP57-CPP. Prefer special member functions and overloaded operators to C
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/oop58-cpp.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/oop58-cpp.rst
index 399fb1b..2efa68f 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/oop58-cpp.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/oop58-cpp.rst
@@ -1,11 +1,11 @@
-.. title:: clang-tidy - cert-mutating-copy
+.. title:: clang-tidy - cert-oop58-cpp
+.. meta::
+ :http-equiv=refresh: 5;URL=../bugprone/copy-constructor-mutates-argument.html
cert-oop58-cpp
==============
-Finds assignments to the copied object and its direct or indirect members
-in copy constructors and copy assignment operators.
-
-This check corresponds to the CERT C Coding Standard rule
-`OOP58-CPP. Copy operations must not mutate the source object
-<https://wiki.sei.cmu.edu/confluence/display/cplusplus/OOP58-CPP.+Copy+operations+must+not+mutate+the+source+object>`_.
+The `cert-oop58-cpp` check is an alias, please see
+:doc:`bugprone-copy-constructor-mutates-argument
+<../bugprone/copy-constructor-mutates-argument>`
+for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/pos44-c.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/pos44-c.rst
index 2fd6c5c..c5141b9 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/pos44-c.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/pos44-c.rst
@@ -6,4 +6,5 @@ cert-pos44-c
============
The `cert-pos44-c` check is an alias, please see
-:doc:`bugprone-bad-signal-to-kill-thread <../bugprone/bad-signal-to-kill-thread>` for more information.
+:doc:`bugprone-bad-signal-to-kill-thread
+<../bugprone/bad-signal-to-kill-thread>` for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/pos47-c.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/pos47-c.rst
index 9b62a3a..ad5570ab 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/pos47-c.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/pos47-c.rst
@@ -6,4 +6,5 @@ cert-pos47-c
============
The `cert-pos47-c` check is an alias, please see
-:doc:`concurrency-thread-canceltype-asynchronous <../concurrency/thread-canceltype-asynchronous>` for more information.
+:doc:`concurrency-thread-canceltype-asynchronous
+<../concurrency/thread-canceltype-asynchronous>` for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/security.SetgidSetuidOrder.rst b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/security.SetgidSetuidOrder.rst
index b3ba785..bb1f5d7 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/security.SetgidSetuidOrder.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/security.SetgidSetuidOrder.rst
@@ -5,12 +5,13 @@
clang-analyzer-security.SetgidSetuidOrder
=========================================
-The checker checks for sequences of ``setuid(getuid())`` and ``setgid(getgid())``
-calls (in this order). If such a sequence is found and there is no other
-privilege-changing function call (``seteuid``, ``setreuid``, ``setresuid`` and
-the GID versions of these) in between, a warning is generated. The checker finds
-only exactly ``setuid(getuid())`` calls (and the GID versions), not for example
-if the result of ``getuid()`` is stored in a variable.
+The checker checks for sequences of ``setuid(getuid())`` and
+``setgid(getgid())`` calls (in this order). If such a sequence is found and
+there is no other privilege-changing function call (``seteuid``, ``setreuid``,
+``setresuid`` and the GID versions of these) in between, a warning is
+generated. The checker finds only exactly ``setuid(getuid())`` calls (and the
+GID versions), not for example if the result of ``getuid()`` is stored in
+a variable.
The `clang-analyzer-security.SetgidSetuidOrder` check is an alias, please see
`Clang Static Analyzer Available Checkers
diff --git a/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/security.insecureAPI.decodeValueOfObjCType.rst b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/security.insecureAPI.decodeValueOfObjCType.rst
index 4405f721..6b926f3 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/security.insecureAPI.decodeValueOfObjCType.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/security.insecureAPI.decodeValueOfObjCType.rst
@@ -1,9 +1,13 @@
.. title:: clang-tidy - clang-analyzer-security.insecureAPI.decodeValueOfObjCType
+.. meta::
+ :http-equiv=refresh: 5;URL=https://clang.llvm.org/docs/analyzer/checkers.html#security-insecureapi-decodevalueofobjctype
clang-analyzer-security.insecureAPI.decodeValueOfObjCType
=========================================================
Warn on uses of the '-decodeValueOfObjCType:at:' method.
-The clang-analyzer-security.insecureAPI.decodeValueOfObjCType check is an alias of
-Clang Static Analyzer security.insecureAPI.decodeValueOfObjCType.
+The `clang-analyzer-security.insecureAPI.decodeValueOfObjCType` check is an alias, please see
+`Clang Static Analyzer security.insecureAPI.decodeValueOfObjCType
+<https://clang.llvm.org/docs/analyzer/checkers.html#security-insecureapi-decodevalueofobjctype>`_
+for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/unix.StdCLibraryFunctions.rst b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/unix.StdCLibraryFunctions.rst
index 1790673..0415dab 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/unix.StdCLibraryFunctions.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/unix.StdCLibraryFunctions.rst
@@ -5,8 +5,8 @@
clang-analyzer-unix.StdCLibraryFunctions
========================================
-Check for invalid arguments of C standard library functions, and apply relations
-between arguments and return value.
+Check for invalid arguments of C standard library functions, and apply
+relations between arguments and return value.
The `clang-analyzer-unix.StdCLibraryFunctions` check is an alias, please see
`Clang Static Analyzer Available Checkers
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-c-arrays.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-c-arrays.rst
index f3fba94..be9b80a 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-c-arrays.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-c-arrays.rst
@@ -5,6 +5,6 @@
cppcoreguidelines-avoid-c-arrays
================================
-The cppcoreguidelines-avoid-c-arrays check is an alias, please see
+The `cppcoreguidelines-avoid-c-arrays` check is an alias, please see
:doc:`modernize-avoid-c-arrays <../modernize/avoid-c-arrays>`
for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-capturing-lambda-coroutines.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-capturing-lambda-coroutines.rst
index 74ec504..58bfc35 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-capturing-lambda-coroutines.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-capturing-lambda-coroutines.rst
@@ -8,7 +8,7 @@ use-after-free errors and suggests avoiding captures or ensuring the lambda
closure object has a guaranteed lifetime.
This check implements `CP.51
-<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rcoro-capture>`_
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#rcoro-capture>`_
from the C++ Core Guidelines.
Using coroutine lambdas with non-empty capture lists can be risky, as capturing
@@ -17,9 +17,9 @@ This issue can occur even with refcounted smart pointers and copyable types.
When a lambda expression creates a coroutine, it results in a closure object
with storage, which is often on the stack and will eventually go out of scope.
When the closure object goes out of scope, its captures also go out of scope.
-While normal lambdas finish executing before this happens, coroutine lambdas may
-resume from suspension after the closure object has been destructed, resulting
-in use-after-free memory access for all captures.
+While normal lambdas finish executing before this happens, coroutine lambdas
+may resume from suspension after the closure object has been destructed,
+resulting in use-after-free memory access for all captures.
Consider the following example:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.rst
index 57c4829..82bd337 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.rst
@@ -44,7 +44,7 @@ Examples:
};
This check implements `C.12
-<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-constref>`_
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#rc-constref>`_
from the C++ Core Guidelines.
Further reading:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-do-while.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-do-while.rst
index 4b195c9..8b0ee30 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-do-while.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-do-while.rst
@@ -3,12 +3,13 @@
cppcoreguidelines-avoid-do-while
================================
-Warns when using ``do-while`` loops. They are less readable than plain ``while``
-loops, since the termination condition is at the end and the condition is not
-checked prior to the first iteration. This can lead to subtle bugs.
+Warns when using ``do-while`` loops. They are less readable than plain
+``while`` loops, since the termination condition is at the end and the
+condition is not checked prior to the first iteration.
+This can lead to subtle bugs.
This check implements `ES.75
-<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-do>`_
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#res-do>`_
from the C++ Core Guidelines.
Examples:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-magic-numbers.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-magic-numbers.rst
index 119b1fd..22e4b95 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-magic-numbers.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-magic-numbers.rst
@@ -5,6 +5,6 @@
cppcoreguidelines-avoid-magic-numbers
=====================================
-The cppcoreguidelines-avoid-magic-numbers check is an alias, please see
+The `cppcoreguidelines-avoid-magic-numbers` check is an alias, please see
:doc:`readability-magic-numbers <../readability/magic-numbers>`
for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-non-const-global-variables.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-non-const-global-variables.rst
index 3d5fef3..b7d2dc8 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-non-const-global-variables.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-non-const-global-variables.rst
@@ -6,7 +6,7 @@ cppcoreguidelines-avoid-non-const-global-variables
Finds non-const global variables as described in `I.2
<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#i2-avoid-non-const-global-variables>`_
of C++ Core Guidelines.
-As `R.6 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rr-global>`_
+As `R.6 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#rr-global>`_
of C++ Core Guidelines is a duplicate of rule `I.2
<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#i2-avoid-non-const-global-variables>`_
it also covers that rule.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-reference-coroutine-parameters.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-reference-coroutine-parameters.rst
index b44430a1..887bdc6 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-reference-coroutine-parameters.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-reference-coroutine-parameters.rst
@@ -3,8 +3,9 @@
cppcoreguidelines-avoid-reference-coroutine-parameters
======================================================
-Warns when a coroutine accepts reference parameters. After a coroutine suspend point,
-references could be dangling and no longer valid. Instead, pass parameters as values.
+Warns when a coroutine accepts reference parameters. After a coroutine suspend
+point, references could be dangling and no longer valid. Instead, pass
+parameters as values.
Examples:
@@ -17,5 +18,5 @@ Examples:
}
This check implements `CP.53
-<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rcoro-reference-parameters>`_
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#rcoro-reference-parameters>`_
from the C++ Core Guidelines.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/c-copy-assignment-signature.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/c-copy-assignment-signature.rst
index 986b63b..4631198 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/c-copy-assignment-signature.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/c-copy-assignment-signature.rst
@@ -5,6 +5,6 @@
cppcoreguidelines-c-copy-assignment-signature
=============================================
-The `cppcoreguidelines-c-copy-assignment-signature` check is an alias, please see
-:doc:`misc-unconventional-assign-operator <../misc/unconventional-assign-operator>`
-for more information.
+The `cppcoreguidelines-c-copy-assignment-signature` check is an alias,
+please see :doc:`misc-unconventional-assign-operator
+<../misc/unconventional-assign-operator>` for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/explicit-virtual-functions.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/explicit-virtual-functions.rst
index e9a703c..a7069d2 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/explicit-virtual-functions.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/explicit-virtual-functions.rst
@@ -5,6 +5,6 @@
cppcoreguidelines-explicit-virtual-functions
============================================
-The `cppcoreguidelines-explicit-virtual-functions` check is an alias, please see
-:doc:`modernize-use-override <../modernize/use-override>`
+The `cppcoreguidelines-explicit-virtual-functions` check is an alias,
+please see :doc:`modernize-use-override <../modernize/use-override>`
for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/init-variables.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/init-variables.rst
index 0465436..e8ca823 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/init-variables.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/init-variables.rst
@@ -8,8 +8,8 @@ value. These may lead to unexpected behavior if there is a code path that reads
the variable before assigning to it.
This rule is part of the `Type safety (Type.5)
-<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Pro-type-init>`_
-profile and `ES.20 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-always>`_
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#pro-type-init>`_
+profile and `ES.20 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#res-always>`_
from the C++ Core Guidelines.
Only integers, booleans, floats, doubles and pointers are checked. The fix
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/interfaces-global-init.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/interfaces-global-init.rst
index f8e9da9..65ff1db 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/interfaces-global-init.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/interfaces-global-init.rst
@@ -7,7 +7,7 @@ This check flags initializers of globals that access extern objects,
and therefore can lead to order-of-initialization problems.
This check implements `I.22
-<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Ri-global-init>`_
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#ri-global-init>`_
from the C++ Core Guidelines.
Note that currently this does not flag calls to non-constexpr functions, and
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/macro-to-enum.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/macro-to-enum.rst
index e64f030..5686624 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/macro-to-enum.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/macro-to-enum.rst
@@ -5,5 +5,6 @@
cppcoreguidelines-macro-to-enum
===============================
-The cppcoreguidelines-macro-to-enum check is an alias, please see
-:doc:`modernize-macro-to-enum <../modernize/macro-to-enum>` for more information.
+The `cppcoreguidelines-macro-to-enum` check is an alias, please see
+:doc:`modernize-macro-to-enum <../modernize/macro-to-enum>`
+for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
index 62e38fc..c2af123 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst
@@ -43,5 +43,5 @@ Options
Specify the function used for forwarding. Default is `::std::forward`.
This check implements `F.19
-<http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-forward>`_
+<http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#rf-forward>`_
from the C++ Core Guidelines.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/narrowing-conversions.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/narrowing-conversions.rst
index ea24e87..b1d3e40 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/narrowing-conversions.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/narrowing-conversions.rst
@@ -9,6 +9,6 @@ This check implements part of `ES.46
<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es46-avoid-lossy-narrowing-truncating-arithmetic-conversions>`_
from the C++ Core Guidelines.
-The cppcoreguidelines-narrowing-conversions check is an alias, please see
+The `cppcoreguidelines-narrowing-conversions` check is an alias, please see
:doc:`bugprone-narrowing-conversions <../bugprone/narrowing-conversions>`
for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/no-malloc.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/no-malloc.rst
index e3a1620..6b95604 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/no-malloc.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/no-malloc.rst
@@ -4,13 +4,13 @@ cppcoreguidelines-no-malloc
===========================
This check handles C-Style memory management using ``malloc()``, ``realloc()``,
-``calloc()`` and ``free()``. It warns about its use and tries to suggest the use
-of an appropriate RAII object.
-Furthermore, it can be configured to check against a user-specified list of functions
-that are used for memory management (e.g. ``posix_memalign()``).
+``calloc()`` and ``free()``. It warns about its use and tries to suggest the
+use of an appropriate RAII object.
+Furthermore, it can be configured to check against a user-specified list of
+functions that are used for memory management (e.g. ``posix_memalign()``).
This check implements `R.10
-<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rr-mallocfree>`_
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#rr-mallocfree>`_
from the C++ Core Guidelines.
There is no attempt made to provide fix-it hints, since manual resource
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/no-suspend-with-lock.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/no-suspend-with-lock.rst
index 59981f2..81b88e3 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/no-suspend-with-lock.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/no-suspend-with-lock.rst
@@ -36,5 +36,5 @@ Examples:
}
This check implements `CP.52
-<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rcoro-locks>`_
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#rcoro-locks>`_
from the C++ Core Guidelines.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/noexcept-move-operations.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/noexcept-move-operations.rst
index a4b0f7d..ca6b92c 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/noexcept-move-operations.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/noexcept-move-operations.rst
@@ -9,5 +9,5 @@ This check implements `C.66 <https://isocpp.github.io/CppCoreGuidelines/CppCoreG
from the C++ Core Guidelines.
The `cppcoreguidelines-noexcept-move-operations` check is an alias, please see
-:doc:`performance-noexcept-move-constructor <../performance/noexcept-move-constructor>`
-for more information.
+:doc:`performance-noexcept-move-constructor
+<../performance/noexcept-move-constructor>` for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/non-private-member-variables-in-classes.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/non-private-member-variables-in-classes.rst
index 7f18c17..a08bb5c 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/non-private-member-variables-in-classes.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/non-private-member-variables-in-classes.rst
@@ -5,7 +5,6 @@
cppcoreguidelines-non-private-member-variables-in-classes
=========================================================
-The cppcoreguidelines-non-private-member-variables-in-classes check is an alias,
-please see
-:doc:`misc-non-private-member-variables-in-classes <../misc/non-private-member-variables-in-classes>`
-for more information.
+The `cppcoreguidelines-non-private-member-variables-in-classes` check is
+an alias, please see :doc:`misc-non-private-member-variables-in-classes
+<../misc/non-private-member-variables-in-classes>` for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/owning-memory.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/owning-memory.rst
index 4fc49f8..218de55 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/owning-memory.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/owning-memory.rst
@@ -3,9 +3,9 @@
cppcoreguidelines-owning-memory
===============================
-This check implements the type-based semantics of ``gsl::owner<T*>``, which allows
-static analysis on code, that uses raw pointers to handle resources like
-dynamic memory, but won't introduce RAII concepts.
+This check implements the type-based semantics of ``gsl::owner<T*>``, which
+allows static analysis on code, that uses raw pointers to handle resources
+like dynamic memory, but won't introduce RAII concepts.
This check implements `I.11
<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#i11-never-transfer-ownership-by-a-raw-pointer-t-or-reference-t>`_,
@@ -14,7 +14,7 @@ This check implements `I.11
`R.3
<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#r3-a-raw-pointer-a-t-is-non-owning>`_
and `GSL.Views
-<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#SS-views>`_
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#ss-views>`_
from the C++ Core Guidelines.
The definition of a ``gsl::owner<T*>`` is straight forward
@@ -23,13 +23,14 @@ The definition of a ``gsl::owner<T*>`` is straight forward
namespace gsl { template <typename T> owner = T; }
It is therefore simple to introduce the owner even without using an implementation of
-the `Guideline Support Library <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#S-gsl>`_.
+the `Guideline Support Library <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#s-gsl>`_.
All checks are purely type based and not (yet) flow sensitive.
-The following examples will demonstrate the correct and incorrect initializations
-of owners, assignment is handled the same way. Note that both ``new`` and
-``malloc()``-like resource functions are considered to produce resources.
+The following examples will demonstrate the correct and incorrect
+initializations of owners, assignment is handled the same way.
+Note that both ``new`` and ``malloc()``-like resource functions are
+considered to produce resources.
.. code-block:: c++
@@ -62,8 +63,9 @@ to be deleted.
gsl::owner<int*> Owner = new int(42); // Good
delete Owner; // Good as well, statically enforced, that only owners get deleted
-The check will furthermore ensure, that functions, that expect a ``gsl::owner<T*>`` as
-argument get called with either a ``gsl::owner<T*>`` or a newly created resource.
+The check will furthermore ensure, that functions, that expect a
+``gsl::owner<T*>`` as argument get called with either a ``gsl::owner<T*>`` or
+a newly created resource.
.. code-block:: c++
@@ -164,8 +166,8 @@ Known code constructs that do not get diagnosed correctly are:
// False positive, getValue returns int* and not gsl::owner<int*>
gsl::owner<int*> OwnedInt = Owner.getValue();
-Another limitation of the current implementation is only the type based checking.
-Suppose you have code like the following:
+Another limitation of the current implementation is only the type based
+checking. Suppose you have code like the following:
.. code-block:: c++
@@ -176,9 +178,9 @@ Suppose you have code like the following:
Owner2 = Owner1; // Conceptual Leak of initial resource of Owner2!
Owner1 = nullptr;
-The semantic of a ``gsl::owner<T*>`` is mostly like a ``std::unique_ptr<T>``, therefore
-assignment of two ``gsl::owner<T*>`` is considered a move, which requires that the
-resource ``Owner2`` must have been released before the assignment.
-This kind of condition could be caught in later improvements of this check with
-flowsensitive analysis. Currently, the `Clang Static Analyzer` catches this bug
-for dynamic memory, but not for general types of resources.
+The semantic of a ``gsl::owner<T*>`` is mostly like a ``std::unique_ptr<T>``,
+therefore assignment of two ``gsl::owner<T*>`` is considered a move, which
+requires that the resource ``Owner2`` must have been released before the
+assignment. This kind of condition could be caught in later improvements of
+this check with flowsensitive analysis. Currently, the `Clang Static Analyzer`
+catches this bug for dynamic memory, but not for general types of resources.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
index 6d1bdb93..12aeaa8 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
@@ -16,7 +16,8 @@ from the C++ Core Guidelines.
Please note, that this check does not enforce rule `C.48
<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c48-prefer-in-class-initializers-to-member-initializers-in-constructors-for-constant-initializers>`_
from the C++ Core Guidelines. For that purpose
-see check :doc:`modernize-use-default-member-init <../modernize/use-default-member-init>`.
+see check :doc:`modernize-use-default-member-init
+<../modernize/use-default-member-init>`.
Example 1
---------
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-array-to-pointer-decay.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-array-to-pointer-decay.rst
index c890e16..06de6fc 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-array-to-pointer-decay.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-array-to-pointer-decay.rst
@@ -9,5 +9,5 @@ Pointers should not be used as arrays. ``span<T>`` is a bounds-checked, safe
alternative to using pointers to access arrays.
This rule is part of the `Bounds safety (Bounds 3)
-<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Pro-bounds-decay>`_
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#pro-bounds-decay>`_
profile from the C++ Core Guidelines.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-avoid-unchecked-container-access.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-avoid-unchecked-container-access.rst
index 556d902..38143c9 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-avoid-unchecked-container-access.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-avoid-unchecked-container-access.rst
@@ -25,13 +25,13 @@ and
will generate a warning.
-STL containers for which ``operator[]`` is well-defined for all inputs are excluded
-from this check (e.g.: ``std::map::operator[]``).
+STL containers for which ``operator[]`` is well-defined for all inputs are
+excluded from this check (e.g.: ``std::map::operator[]``).
This check enforces part of the `SL.con.3
-<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#slcon3-avoid-bounds-errors>`
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#slcon3-avoid-bounds-errors>`_
guideline and is part of the `Bounds Safety (Bounds 4)
-<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Pro-bounds-arrayindex>`
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#pro-bounds-arrayindex>`_
profile from the C++ Core Guidelines.
Options
@@ -39,14 +39,14 @@ Options
.. option:: ExcludeClasses
- Semicolon-delimited list of class names for overwriting the default
- exclusion list. The default is:
+ Semicolon-separated list of regular expressions matching class names that
+ overwrites the default exclusion list. The default is:
`::std::map;::std::unordered_map;::std::flat_map`.
-
+
.. option:: FixMode
- Determines what fixes are suggested. Either `none`, `at` (use
- ``a.at(index)`` if a fitting function exists) or `function` (use a
+ Determines what fixes are suggested. Either `none`, `at` (use
+ ``a.at(index)`` if a fitting function exists) or `function` (use a
function ``f(a, index)``). The default is `none`.
.. option:: FixFunction
@@ -54,7 +54,7 @@ Options
The function to use in the `function` mode. For C++23 and beyond, the
passed function must support the empty subscript operator, i.e., the case
where ``a[]`` becomes ``f(a)``. :option:`FixFunctionEmptyArgs` can be
- used to override the suggested function in that case. The default is `gsl::at`.
+ used to override the suggested function in that case. The default is `gsl::at`.
.. option:: FixFunctionEmptyArgs
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-constant-array-index.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-constant-array-index.rst
index 9b82e0c..4eddeb4 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-constant-array-index.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-constant-array-index.rst
@@ -9,7 +9,7 @@ are out of bounds (for ``std::array``). For out-of-bounds checking of static
arrays, see the `-Warray-bounds` Clang diagnostic.
This rule is part of the `Bounds safety (Bounds 2)
-<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Pro-bounds-arrayindex>`_
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#pro-bounds-arrayindex>`_
profile from the C++ Core Guidelines.
Optionally, this check can generate fixes using ``gsl::at`` for indexing.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-pointer-arithmetic.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-pointer-arithmetic.rst
index a3f1371..3f02009 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-pointer-arithmetic.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-pointer-arithmetic.rst
@@ -11,7 +11,7 @@ and easy to get wrong. ``span<T>`` is a bounds-checked, safe type for accessing
arrays of data.
This rule is part of the `Bounds safety (Bounds 1)
-<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Pro-bounds-arithmetic>`_
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#pro-bounds-arithmetic>`_
profile from the C++ Core Guidelines.
Options
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-const-cast.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-const-cast.rst
index 961a591..b5cc486 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-const-cast.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-const-cast.rst
@@ -16,13 +16,13 @@ attempts to change the value of that variable.
Removing the ``volatile`` qualifier in C++ can have serious consequences. This
qualifier indicates that a variable's value can change unpredictably, and
-removing it may lead to undefined behavior, optimization problems, and debugging
-challenges. It's essential to retain the ``volatile`` qualifier in situations
-where the variable's volatility is a crucial aspect of program correctness and
-reliability.
+removing it may lead to undefined behavior, optimization problems, and
+debugging challenges. It's essential to retain the ``volatile`` qualifier in
+situations where the variable's volatility is a crucial aspect of program
+correctness and reliability.
This rule is part of the `Type safety (Type 3)
-<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Pro-type-constcast>`_
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#pro-type-constcast>`_
profile and `ES.50: Don’t cast away const
<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es50-dont-cast-away-const>`_
rule from the C++ Core Guidelines.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-cstyle-cast.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-cstyle-cast.rst
index daa93c6..a94115e 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-cstyle-cast.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-cstyle-cast.rst
@@ -7,13 +7,13 @@ This check flags all use of C-style casts that perform a ``static_cast``
downcast, ``const_cast``, or ``reinterpret_cast``.
Use of these casts can violate type safety and cause the program to access a
-variable that is actually of type X to be accessed as if it were of an unrelated
-type Z. Note that a C-style ``(T)expression`` cast means to perform the first of
-the following that is possible: a ``const_cast``, a ``static_cast``, a
-``static_cast`` followed by a ``const_cast``, a ``reinterpret_cast``, or a
-``reinterpret_cast`` followed by a ``const_cast``. This rule bans
-``(T)expression`` only when used to perform an unsafe cast.
+variable that is actually of type X to be accessed as if it were of an
+unrelated type Z. Note that a C-style ``(T)expression`` cast means to perform
+the first of the following that is possible: a ``const_cast``, a
+``static_cast``, a ``static_cast`` followed by a ``const_cast``, a
+``reinterpret_cast``, or a ``reinterpret_cast`` followed by a ``const_cast``.
+This rule bans ``(T)expression`` only when used to perform an unsafe cast.
This rule is part of the `Type safety (Type.4)
-<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Pro-type-cstylecast>`_
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#pro-type-cstylecast>`_
profile from the C++ Core Guidelines.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-member-init.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-member-init.rst
index 3c6797b..b86083f 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-member-init.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-member-init.rst
@@ -20,9 +20,9 @@ account but generates false positives for fields initialized in
methods invoked in the constructor body.
The check also flags variables with automatic storage duration that have record
-types without a user-provided constructor and are not initialized. The suggested
-fix is to zero initialize the variable via ``{}`` for C++11 and beyond or ``=
-{}`` for older language versions.
+types without a user-provided constructor and are not initialized. The
+suggested fix is to zero initialize the variable via ``{}`` for C++11 and
+beyond or ``= {}`` for older language versions.
Options
-------
@@ -40,5 +40,5 @@ Options
Default is `false`.
This rule is part of the `Type safety (Type.6)
-<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Pro-type-memberinit>`_
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#pro-type-memberinit>`_
profile from the C++ Core Guidelines.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-reinterpret-cast.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-reinterpret-cast.rst
index a094682..c2e4170 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-reinterpret-cast.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-reinterpret-cast.rst
@@ -10,5 +10,5 @@ variable that is actually of type ``X`` to be accessed as if it were of an
unrelated type ``Z``.
This rule is part of the `Type safety (Type.1.1)
-<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Pro-type-reinterpretcast>`_
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#pro-type-reinterpretcast>`_
profile from the C++ Core Guidelines.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-static-cast-downcast.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-static-cast-downcast.rst
index 333e6db..21c0145 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-static-cast-downcast.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-static-cast-downcast.rst
@@ -12,7 +12,7 @@ variable that is actually of type ``X`` to be accessed as if it were of an
unrelated type ``Z``.
This rule is part of the `Type safety (Type.2)
-<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Pro-type-downcast>`_
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#pro-type-downcast>`_
profile from the C++ Core Guidelines.
Options
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-union-access.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-union-access.rst
index 3a5af53..db726a2 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-union-access.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-union-access.rst
@@ -13,5 +13,5 @@ enforced to be safe in the language and so relies on programmer discipline to
get it right.
This rule is part of the `Type safety (Type.7)
-<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Pro-type-unions>`_
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#pro-type-unions>`_
profile from the C++ Core Guidelines.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-vararg.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-vararg.rst
index e74b006..09809c2 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-vararg.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-vararg.rst
@@ -11,9 +11,9 @@ To allow for SFINAE use of vararg functions, a call is not flagged if a literal
context.
Passing to varargs assumes the correct type will be read. This is fragile
-because it cannot generally be enforced to be safe in the language and so relies
-on programmer discipline to get it right.
+because it cannot generally be enforced to be safe in the language and so
+relies on programmer discipline to get it right.
This rule is part of the `Type safety (Type.8)
-<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Pro-type-varargs>`_
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#pro-type-varargs>`_
profile from the C++ Core Guidelines.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/special-member-functions.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/special-member-functions.rst
index 982d16fc..1b050a5 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/special-member-functions.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/special-member-functions.rst
@@ -16,7 +16,7 @@ Note that defining a function with ``= delete`` is considered to be a
definition.
This check implements `C.21
-<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-five>`_
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#rc-five>`_
from the C++ Core Guidelines.
Options
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-default-member-init.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-default-member-init.rst
index e785f31..55661c0 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-default-member-init.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-default-member-init.rst
@@ -5,7 +5,7 @@
cppcoreguidelines-use-default-member-init
=========================================
-This check implements `C.48 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-in-class-initializer>`_
+This check implements `C.48 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#rc-in-class-initializer>`_
from the C++ Core Guidelines.
The `cppcoreguidelines-use-default-member-init` check is an alias, please see
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-enum-class.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-enum-class.rst
index 9e9f4c9..9358996a 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-enum-class.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-enum-class.rst
@@ -7,7 +7,7 @@ Finds unscoped (non-class) ``enum`` declarations and suggests using
``enum class`` instead.
This check implements `Enum.3
-<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Renum-class>`_
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#renum-class>`_
from the C++ Core Guidelines."
Example:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/virtual-class-destructor.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/virtual-class-destructor.rst
index 752fd81..80932c4 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/virtual-class-destructor.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/virtual-class-destructor.rst
@@ -8,7 +8,7 @@ nor protected and non-virtual. A virtual class's destructor should be specified
in one of these ways to prevent undefined behavior.
This check implements
-`C.35 <http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-dtor-virtual>`_
+`C.35 <http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#rc-dtor-virtual>`_
from the C++ Core Guidelines.
Note that this check will diagnose a class with a virtual method regardless of
diff --git a/clang-tools-extra/docs/clang-tidy/checks/fuchsia/statically-constructed-objects.rst b/clang-tools-extra/docs/clang-tidy/checks/fuchsia/statically-constructed-objects.rst
index bed9e5a..ad87283 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/fuchsia/statically-constructed-objects.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/fuchsia/statically-constructed-objects.rst
@@ -3,9 +3,9 @@
fuchsia-statically-constructed-objects
======================================
-Warns if global, non-trivial objects with static storage are constructed, unless
-the object is statically initialized with a ``constexpr`` constructor or has no
-explicit constructor.
+Warns if global, non-trivial objects with static storage are constructed,
+unless the object is statically initialized with a ``constexpr`` constructor
+or has no explicit constructor.
For example:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/google/explicit-constructor.rst b/clang-tools-extra/docs/clang-tidy/checks/google/explicit-constructor.rst
index acafc1a..1bef268 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/google/explicit-constructor.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/google/explicit-constructor.rst
@@ -23,8 +23,8 @@ Consider this example:
return a == b;
}
-The function will return ``true``, since the objects are implicitly converted to
-``bool`` before comparison, which is unlikely to be the intent.
+The function will return ``true``, since the objects are implicitly converted
+to ``bool`` before comparison, which is unlikely to be the intent.
The check will suggest inserting ``explicit`` before the constructor or
conversion operator declaration. However, copy and move constructors should not
diff --git a/clang-tools-extra/docs/clang-tidy/checks/google/objc-avoid-throwing-exception.rst b/clang-tools-extra/docs/clang-tidy/checks/google/objc-avoid-throwing-exception.rst
index 50441f7..bd099c4 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/google/objc-avoid-throwing-exception.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/google/objc-avoid-throwing-exception.rst
@@ -11,7 +11,8 @@ exceptions from Objective-C code.
The corresponding C++ style guide rule:
https://google.github.io/styleguide/cppguide.html#Exceptions
-Instead, prefer passing in ``NSError **`` and return ``BOOL`` to indicate success or failure.
+Instead, prefer passing in ``NSError **`` and return ``BOOL`` to indicate
+success or failure.
A counterexample:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/google/objc-global-variable-declaration.rst b/clang-tools-extra/docs/clang-tidy/checks/google/objc-global-variable-declaration.rst
index 84c9776..105b4ff 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/google/objc-global-variable-declaration.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/google/objc-global-variable-declaration.rst
@@ -9,9 +9,9 @@ pattern of variable names in Google's Objective-C Style Guide.
The corresponding style guide rule:
https://google.github.io/styleguide/objcguide.html#variable-names
-All the global variables should follow the pattern of ``g[A-Z].*`` (variables) or
-``k[A-Z].*`` (constants). The check will suggest a variable name that follows the
-pattern if it can be inferred from the original name.
+All the global variables should follow the pattern of ``g[A-Z].*`` (variables)
+or ``k[A-Z].*`` (constants). The check will suggest a variable name that
+follows the pattern if it can be inferred from the original name.
For code:
@@ -43,5 +43,5 @@ However for code that prefixed with non-alphabetical characters like:
static NSString* __anotherString = @"world";
-The check will give a warning message but will not be able to suggest a fix. The
-user needs to fix it on their own.
+The check will give a warning message but will not be able to suggest
+a fix. The user needs to fix it on their own.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/google/readability-avoid-underscore-in-googletest-name.rst b/clang-tools-extra/docs/clang-tidy/checks/google/readability-avoid-underscore-in-googletest-name.rst
index e667fd1..a1da79d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/google/readability-avoid-underscore-in-googletest-name.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/google/readability-avoid-underscore-in-googletest-name.rst
@@ -25,8 +25,8 @@ would trigger the check. `Underscores are not allowed`_ in test suite name nor
test names.
The ``DISABLED_`` prefix, which may be used to
-`disable test suites and individual tests`_, is removed from the test suite name
-and test name before checking for underscores.
+`disable test suites and individual tests`_, is removed from the test suite
+name and test name before checking for underscores.
This check does not propose any fixes.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/google/readability-braces-around-statements.rst b/clang-tools-extra/docs/clang-tidy/checks/google/readability-braces-around-statements.rst
index 6130609..764694e 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/google/readability-braces-around-statements.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/google/readability-braces-around-statements.rst
@@ -6,5 +6,6 @@ google-readability-braces-around-statements
===========================================
The `google-readability-braces-around-statements` check is an alias, please see
-:doc:`readability-braces-around-statements <../readability/braces-around-statements>`
+:doc:`readability-braces-around-statements
+<../readability/braces-around-statements>`
for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/google/readability-casting.rst b/clang-tools-extra/docs/clang-tidy/checks/google/readability-casting.rst
index d927e1c..31ee3bd 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/google/readability-casting.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/google/readability-casting.rst
@@ -3,12 +3,12 @@
google-readability-casting
==========================
+The `google-readability-casting` check is an alias, please see
+:doc:`modernize-avoid-c-style-cast <../modernize/avoid-c-style-cast>`
+for more information.
+
Finds usages of C-style casts.
https://google.github.io/styleguide/cppguide.html#Casting
Corresponding cpplint.py check name: `readability/casting`.
-
-This check is similar to ``-Wold-style-cast``, but it suggests automated fixes
-in some cases. The reported locations should not be different from the
-ones generated by ``-Wold-style-cast``.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/google/readability-todo.rst b/clang-tools-extra/docs/clang-tidy/checks/google/readability-todo.rst
index 159d2b4..fccfa81 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/google/readability-todo.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/google/readability-todo.rst
@@ -9,3 +9,14 @@ The relevant style guide section is
https://google.github.io/styleguide/cppguide.html#TODO_Comments.
Corresponding cpplint.py check: `readability/todo`
+
+Options
+-------
+
+.. option:: Style
+
+ A string specifying the TODO style for fix-it hints. Accepted values are
+ `Hyphen` and `Parentheses`. Default is `Hyphen`.
+
+ * `Hyphen` will format the fix-it as: ``// TODO: username - details``.
+ * `Parentheses` will format the fix-it as: ``// TODO(username): details``.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/google/upgrade-googletest-case.rst b/clang-tools-extra/docs/clang-tidy/checks/google/upgrade-googletest-case.rst
index 8759283..df98369 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/google/upgrade-googletest-case.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/google/upgrade-googletest-case.rst
@@ -17,8 +17,8 @@ check to remove deprecated names.
The affected APIs are:
- Member functions of ``testing::Test``, ``testing::TestInfo``,
- ``testing::TestEventListener``, ``testing::UnitTest``, and any type inheriting
- from these types
+ ``testing::TestEventListener``, ``testing::UnitTest``, and any type
+ inheriting from these types
- The macros ``TYPED_TEST_CASE``, ``TYPED_TEST_CASE_P``,
``REGISTER_TYPED_TEST_CASE_P``, and ``INSTANTIATE_TYPED_TEST_CASE_P``
- The type alias ``testing::TestCase``
diff --git a/clang-tools-extra/docs/clang-tidy/checks/hicpp/braces-around-statements.rst b/clang-tools-extra/docs/clang-tidy/checks/hicpp/braces-around-statements.rst
index 15a410e..aef9975 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/hicpp/braces-around-statements.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/braces-around-statements.rst
@@ -6,6 +6,8 @@ hicpp-braces-around-statements
==============================
The `hicpp-braces-around-statements` check is an alias, please see
-:doc:`readability-braces-around-statements <../readability/braces-around-statements>`
+:doc:`readability-braces-around-statements
+<../readability/braces-around-statements>`
for more information.
-It enforces the `rule 6.1.1 <https://www.perforce.com/resources/qac/high-integrity-cpp-coding-standard/statements>`_.
+It enforces the `rule 6.1.1
+<https://www.perforce.com/resources/qac/high-integrity-cpp-coding-standard/statements>`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/hicpp/explicit-conversions.rst b/clang-tools-extra/docs/clang-tidy/checks/hicpp/explicit-conversions.rst
index d8c6939..6072527b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/hicpp/explicit-conversions.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/explicit-conversions.rst
@@ -5,13 +5,21 @@
hicpp-explicit-conversions
==========================
-This check is an alias for :doc:`google-explicit-constructor <../google/explicit-constructor>`.
-Used to enforce parts of `rule 5.4.1 <https://www.perforce.com/resources/qac/high-integrity-cpp-coding-standard-expressions>`_.
-This check will enforce that constructors and conversion operators are marked `explicit`.
-Other forms of casting checks are implemented in other places.
-The following checks can be used to check for more forms of casting:
+This check is an alias for
+:doc:`google-explicit-constructor <../google/explicit-constructor>`.
-- :doc:`cppcoreguidelines-pro-type-static-cast-downcast <../cppcoreguidelines/pro-type-static-cast-downcast>`
-- :doc:`cppcoreguidelines-pro-type-reinterpret-cast <../cppcoreguidelines/pro-type-reinterpret-cast>`
-- :doc:`cppcoreguidelines-pro-type-const-cast <../cppcoreguidelines/pro-type-const-cast>`
-- :doc:`cppcoreguidelines-pro-type-cstyle-cast <../cppcoreguidelines/pro-type-cstyle-cast>`
+Used to enforce parts of `rule 5.4.1
+<https://www.perforce.com/resources/qac/high-integrity-cpp-coding-standard-expressions>`_.
+This check will enforce that constructors and conversion operators are
+marked ``explicit``. Other forms of casting checks are implemented in
+other places. The following checks can be used to check for more forms
+of casting:
+
+- :doc:`cppcoreguidelines-pro-type-static-cast-downcast
+ <../cppcoreguidelines/pro-type-static-cast-downcast>`
+- :doc:`cppcoreguidelines-pro-type-reinterpret-cast
+ <../cppcoreguidelines/pro-type-reinterpret-cast>`
+- :doc:`cppcoreguidelines-pro-type-const-cast
+ <../cppcoreguidelines/pro-type-const-cast>`
+- :doc:`cppcoreguidelines-pro-type-cstyle-cast
+ <../cppcoreguidelines/pro-type-cstyle-cast>`
diff --git a/clang-tools-extra/docs/clang-tidy/checks/hicpp/function-size.rst b/clang-tools-extra/docs/clang-tidy/checks/hicpp/function-size.rst
index 5ccf670..ad91c25 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/hicpp/function-size.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/function-size.rst
@@ -5,7 +5,8 @@
hicpp-function-size
===================
-This check is an alias for :doc:`readability-function-size <../readability/function-size>`.
+This check is an alias for
+:doc:`readability-function-size <../readability/function-size>`.
Useful to enforce multiple sections on function complexity.
- `rule 8.2.2 <https://www.perforce.com/resources/qac/high-integrity-cpp-coding-standard/definitions>`_
diff --git a/clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst b/clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst
index 6ca704a..4a89949c 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst
@@ -13,7 +13,8 @@ operating over. On completion, they return an iterator to the last valid
element. In the majority of cases the correct behavior is to use this result as
the first operand in a call to ``std::erase``.
-This check is a subset of :doc:`bugprone-unused-return-value <../bugprone/unused-return-value>`
+This check is a subset of :doc:`bugprone-unused-return-value
+<../bugprone/unused-return-value>`
and depending on used options it can be superfluous to enable both checks.
Options
diff --git a/clang-tools-extra/docs/clang-tidy/checks/hicpp/invalid-access-moved.rst b/clang-tools-extra/docs/clang-tidy/checks/hicpp/invalid-access-moved.rst
index 13184d4..fd2e04a 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/hicpp/invalid-access-moved.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/invalid-access-moved.rst
@@ -5,6 +5,7 @@
hicpp-invalid-access-moved
==========================
-This check is an alias for :doc:`bugprone-use-after-move <../bugprone/use-after-move>`.
+This check is an alias for
+:doc:`bugprone-use-after-move <../bugprone/use-after-move>`.
Implements parts of the `rule 8.4.1 <https://www.perforce.com/resources/qac/high-integrity-cpp-coding-standard/definitions>`_ to check if moved-from objects are accessed.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/hicpp/move-const-arg.rst b/clang-tools-extra/docs/clang-tidy/checks/hicpp/move-const-arg.rst
index b43c233..7af8401 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/hicpp/move-const-arg.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/move-const-arg.rst
@@ -6,5 +6,6 @@ hicpp-move-const-arg
====================
The `hicpp-move-const-arg` check is an alias, please see
-:doc:`performance-move-const-arg <../performance/move-const-arg>` for more information.
+:doc:`performance-move-const-arg <../performance/move-const-arg>`
+for more information.
It enforces the `rule 17.3.1 <https://www.perforce.com/resources/qac/high-integrity-cpp-coding-standard/standard-library>`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/hicpp/multiway-paths-covered.rst b/clang-tools-extra/docs/clang-tidy/checks/hicpp/multiway-paths-covered.rst
index 983de34..f164f4c 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/hicpp/multiway-paths-covered.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/multiway-paths-covered.rst
@@ -4,15 +4,16 @@ hicpp-multiway-paths-covered
============================
This check discovers situations where code paths are not fully-covered.
-It furthermore suggests using ``if`` instead of ``switch`` if the code will be more clear.
+It furthermore suggests using ``if`` instead of ``switch`` if the code
+will be more clear.
The `rule 6.1.2 <https://www.perforce.com/resources/qac/high-integrity-cpp-coding-standard/statements>`_
and `rule 6.1.4 <https://www.perforce.com/resources/qac/high-integrity-cpp-coding-standard/statements>`_
of the High Integrity C++ Coding Standard are enforced.
-``if-else if`` chains that miss a final ``else`` branch might lead to unexpected
-program execution and be the result of a logical error.
-If the missing ``else`` branch is intended you can leave it empty with a clarifying
-comment.
+``if-else if`` chains that miss a final ``else`` branch might lead to
+unexpected program execution and be the result of a logical error.
+If the missing ``else`` branch is intended you can leave it empty with
+a clarifying comment.
This warning can be noisy on some code bases, so it is disabled by default.
.. code-block:: c++
@@ -28,7 +29,8 @@ This warning can be noisy on some code bases, so it is disabled by default.
// ...
}
-Similar arguments hold for ``switch`` statements which do not cover all possible code paths.
+Similar arguments hold for ``switch`` statements which do not cover all
+possible code paths.
.. code-block:: c++
diff --git a/clang-tools-extra/docs/clang-tidy/checks/hicpp/named-parameter.rst b/clang-tools-extra/docs/clang-tidy/checks/hicpp/named-parameter.rst
index 7f894b1..4506596 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/hicpp/named-parameter.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/named-parameter.rst
@@ -5,6 +5,7 @@
hicpp-named-parameter
=====================
-This check is an alias for :doc:`readability-named-parameter <../readability/named-parameter>`.
+This check is an alias for :doc:`readability-named-parameter
+<../readability/named-parameter>`.
Implements `rule 8.2.1 <https://www.perforce.com/resources/qac/high-integrity-cpp-coding-standard/definitions>`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/hicpp/no-array-decay.rst b/clang-tools-extra/docs/clang-tidy/checks/hicpp/no-array-decay.rst
index 85b93cb..715a1b7 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/hicpp/no-array-decay.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/no-array-decay.rst
@@ -6,6 +6,7 @@ hicpp-no-array-decay
====================
The `hicpp-no-array-decay` check is an alias, please see
-:doc:`cppcoreguidelines-pro-bounds-array-to-pointer-decay <../cppcoreguidelines/pro-bounds-array-to-pointer-decay>`
+:doc:`cppcoreguidelines-pro-bounds-array-to-pointer-decay
+<../cppcoreguidelines/pro-bounds-array-to-pointer-decay>`
for more information.
It enforces the `rule 4.1.1 <https://www.perforce.com/resources/qac/high-integrity-cpp-coding-standard/standard-conversions>`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/hicpp/uppercase-literal-suffix.rst b/clang-tools-extra/docs/clang-tidy/checks/hicpp/uppercase-literal-suffix.rst
index 994363a..34b9f25 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/hicpp/uppercase-literal-suffix.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/uppercase-literal-suffix.rst
@@ -6,7 +6,8 @@ hicpp-uppercase-literal-suffix
==============================
The hicpp-uppercase-literal-suffix check is an alias, please see
-:doc:`readability-uppercase-literal-suffix <../readability/uppercase-literal-suffix>` for more information.
+:doc:`readability-uppercase-literal-suffix
+<../readability/uppercase-literal-suffix>` for more information.
Partially implements `rule 4.2.1 <https://www.perforce.com/resources/qac/high-integrity-cpp-coding-standard/standard-conversions>`_
to ensure that the ``U`` suffix is writeln properly.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/linuxkernel/must-check-errs.rst b/clang-tools-extra/docs/clang-tidy/checks/linuxkernel/must-check-errs.rst
index cef5a70..6a4b743 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/linuxkernel/must-check-errs.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/linuxkernel/must-check-errs.rst
@@ -4,8 +4,8 @@ linuxkernel-must-check-errs
===========================
Checks Linux kernel code to see if it uses the results from the functions in
-``linux/err.h``. Also checks to see if code uses the results from functions that
-directly return a value from one of these error functions.
+``linux/err.h``. Also checks to see if code uses the results from functions
+that directly return a value from one of these error functions.
This is important in the Linux kernel because ``ERR_PTR``, ``PTR_ERR``,
``IS_ERR``, ``IS_ERR_OR_NULL``, ``ERR_CAST``, and ``PTR_ERR_OR_ZERO`` return
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index d3c89e4..865a2d3 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -90,13 +90,17 @@ Clang-Tidy Checks
:doc:`bugprone-command-processor <bugprone/command-processor>`,
:doc:`bugprone-compare-pointer-to-member-virtual-function <bugprone/compare-pointer-to-member-virtual-function>`,
:doc:`bugprone-copy-constructor-init <bugprone/copy-constructor-init>`, "Yes"
+ :doc:`bugprone-copy-constructor-mutates-argument <bugprone/copy-constructor-mutates-argument>`,
:doc:`bugprone-crtp-constructor-accessibility <bugprone/crtp-constructor-accessibility>`, "Yes"
:doc:`bugprone-dangling-handle <bugprone/dangling-handle>`,
+ :doc:`bugprone-default-operator-new-on-overaligned-type <bugprone/default-operator-new-on-overaligned-type>`,
:doc:`bugprone-derived-method-shadowing-base-method <bugprone/derived-method-shadowing-base-method>`,
:doc:`bugprone-dynamic-static-initializers <bugprone/dynamic-static-initializers>`,
:doc:`bugprone-easily-swappable-parameters <bugprone/easily-swappable-parameters>`,
:doc:`bugprone-empty-catch <bugprone/empty-catch>`,
+ :doc:`bugprone-exception-copy-constructor-throws <bugprone/exception-copy-constructor-throws>`,
:doc:`bugprone-exception-escape <bugprone/exception-escape>`,
+ :doc:`bugprone-float-loop-counter <bugprone/float-loop-counter>`,
:doc:`bugprone-fold-init-type <bugprone/fold-init-type>`,
:doc:`bugprone-forward-declaration-namespace <bugprone/forward-declaration-namespace>`,
:doc:`bugprone-forwarding-reference-overload <bugprone/forwarding-reference-overload>`,
@@ -129,6 +133,8 @@ Clang-Tidy Checks
:doc:`bugprone-parent-virtual-call <bugprone/parent-virtual-call>`, "Yes"
:doc:`bugprone-pointer-arithmetic-on-polymorphic-object <bugprone/pointer-arithmetic-on-polymorphic-object>`,
:doc:`bugprone-posix-return <bugprone/posix-return>`, "Yes"
+ :doc:`bugprone-random-generator-seed <bugprone/random-generator-seed>`,
+ :doc:`bugprone-raw-memory-call-on-non-trivial-type <bugprone/raw-memory-call-on-non-trivial-type>`,
:doc:`bugprone-redundant-branch-condition <bugprone/redundant-branch-condition>`, "Yes"
:doc:`bugprone-reserved-identifier <bugprone/reserved-identifier>`, "Yes"
:doc:`bugprone-return-const-ref-from-parameter <bugprone/return-const-ref-from-parameter>`,
@@ -139,6 +145,7 @@ Clang-Tidy Checks
:doc:`bugprone-sizeof-expression <bugprone/sizeof-expression>`,
:doc:`bugprone-spuriously-wake-up-functions <bugprone/spuriously-wake-up-functions>`,
:doc:`bugprone-standalone-empty <bugprone/standalone-empty>`, "Yes"
+ :doc:`bugprone-std-namespace-modification <bugprone/std-namespace-modification>`,
:doc:`bugprone-string-constructor <bugprone/string-constructor>`, "Yes"
:doc:`bugprone-string-integer-assignment <bugprone/string-integer-assignment>`, "Yes"
:doc:`bugprone-string-literal-with-embedded-nul <bugprone/string-literal-with-embedded-nul>`,
@@ -173,14 +180,10 @@ Clang-Tidy Checks
:doc:`bugprone-unused-return-value <bugprone/unused-return-value>`,
:doc:`bugprone-use-after-move <bugprone/use-after-move>`,
:doc:`bugprone-virtual-near-miss <bugprone/virtual-near-miss>`, "Yes"
- :doc:`cert-dcl58-cpp <cert/dcl58-cpp>`,
:doc:`cert-err33-c <cert/err33-c>`,
:doc:`cert-err60-cpp <cert/err60-cpp>`,
:doc:`cert-flp30-c <cert/flp30-c>`,
- :doc:`cert-mem57-cpp <cert/mem57-cpp>`,
:doc:`cert-msc50-cpp <cert/msc50-cpp>`,
- :doc:`cert-msc51-cpp <cert/msc51-cpp>`,
- :doc:`cert-oop57-cpp <cert/oop57-cpp>`,
:doc:`cert-oop58-cpp <cert/oop58-cpp>`,
:doc:`concurrency-mt-unsafe <concurrency/mt-unsafe>`,
:doc:`concurrency-thread-canceltype-asynchronous <concurrency/thread-canceltype-asynchronous>`,
@@ -236,7 +239,6 @@ Clang-Tidy Checks
:doc:`google-objc-function-naming <google/objc-function-naming>`,
:doc:`google-objc-global-variable-declaration <google/objc-global-variable-declaration>`,
:doc:`google-readability-avoid-underscore-in-googletest-name <google/readability-avoid-underscore-in-googletest-name>`,
- :doc:`google-readability-casting <google/readability-casting>`,
:doc:`google-readability-todo <google/readability-todo>`,
:doc:`google-runtime-float <google/runtime-float>`,
:doc:`google-runtime-int <google/runtime-int>`,
@@ -275,6 +277,7 @@ Clang-Tidy Checks
:doc:`misc-non-copyable-objects <misc/non-copyable-objects>`,
:doc:`misc-non-private-member-variables-in-classes <misc/non-private-member-variables-in-classes>`,
:doc:`misc-override-with-different-visibility <misc/override-with-different-visibility>`,
+ :doc:`misc-predictable-rand <misc/predictable-rand>`,
:doc:`misc-redundant-expression <misc/redundant-expression>`, "Yes"
:doc:`misc-static-assert <misc/static-assert>`, "Yes"
:doc:`misc-throw-by-value-catch-by-reference <misc/throw-by-value-catch-by-reference>`,
@@ -287,6 +290,7 @@ Clang-Tidy Checks
:doc:`misc-use-internal-linkage <misc/use-internal-linkage>`, "Yes"
:doc:`modernize-avoid-bind <modernize/avoid-bind>`, "Yes"
:doc:`modernize-avoid-c-arrays <modernize/avoid-c-arrays>`,
+ :doc:`modernize-avoid-c-style-cast <modernize/avoid-c-style-cast>`,
:doc:`modernize-avoid-setjmp-longjmp <modernize/avoid-setjmp-longjmp>`,
:doc:`modernize-avoid-variadic-functions <modernize/avoid-variadic-functions>`,
:doc:`modernize-concat-nested-namespaces <modernize/concat-nested-namespaces>`, "Yes"
@@ -441,24 +445,32 @@ Check aliases
:doc:`cert-dcl50-cpp <cert/dcl50-cpp>`, :doc:`modernize-avoid-variadic-functions <modernize/avoid-variadic-functions>`,
:doc:`cert-dcl51-cpp <cert/dcl51-cpp>`, :doc:`bugprone-reserved-identifier <bugprone/reserved-identifier>`, "Yes"
:doc:`cert-dcl54-cpp <cert/dcl54-cpp>`, :doc:`misc-new-delete-overloads <misc/new-delete-overloads>`,
+ :doc:`cert-dcl58-cpp <cert/dcl58-cpp>`, :doc:`bugprone-std-namespace-modification <bugprone/std-namespace-modification>`,
:doc:`cert-dcl59-cpp <cert/dcl59-cpp>`, :doc:`google-build-namespaces <google/build-namespaces>`,
- :doc:`cert-err09-cpp <cert/err09-cpp>`, :doc:`misc-throw-by-value-catch-by-reference <misc/throw-by-value-catch-by-reference>`,
:doc:`cert-env33-c <cert/env33-c>`, :doc:`bugprone-command-processor <bugprone/command-processor>`,
+ :doc:`cert-err09-cpp <cert/err09-cpp>`, :doc:`misc-throw-by-value-catch-by-reference <misc/throw-by-value-catch-by-reference>`,
:doc:`cert-err34-c <cert/err34-c>`, :doc:`bugprone-unchecked-string-to-number-conversion <bugprone/unchecked-string-to-number-conversion>`,
:doc:`cert-err52-cpp <cert/err52-cpp>`, :doc:`modernize-avoid-setjmp-longjmp <modernize/avoid-setjmp-longjmp>`,
:doc:`cert-err58-cpp <cert/err58-cpp>`, :doc:`bugprone-throwing-static-initialization <bugprone/throwing-static-initialization>`,
+ :doc:`cert-err60-cpp <cert/err60-cpp>`, :doc:`bugprone-exception-copy-constructor-throws <bugprone/exception-copy-constructor-throws>`,
:doc:`cert-err61-cpp <cert/err61-cpp>`, :doc:`misc-throw-by-value-catch-by-reference <misc/throw-by-value-catch-by-reference>`,
:doc:`cert-exp42-c <cert/exp42-c>`, :doc:`bugprone-suspicious-memory-comparison <bugprone/suspicious-memory-comparison>`,
:doc:`cert-fio38-c <cert/fio38-c>`, :doc:`misc-non-copyable-objects <misc/non-copyable-objects>`,
+ :doc:`cert-flp30-c <cert/flp30-c>`, :doc:`bugprone-float-loop-counter <bugprone/float-loop-counter>`,
:doc:`cert-flp37-c <cert/flp37-c>`, :doc:`bugprone-suspicious-memory-comparison <bugprone/suspicious-memory-comparison>`,
:doc:`cert-int09-c <cert/int09-c>`, :doc:`readability-enum-initial-value <readability/enum-initial-value>`, "Yes"
+ :doc:`cert-mem57-cpp <cert/mem57-cpp>`, :doc:`bugprone-default-operator-new-on-overaligned-type <bugprone/default-operator-new-on-overaligned-type>`,
:doc:`cert-msc24-c <cert/msc24-c>`, :doc:`bugprone-unsafe-functions <bugprone/unsafe-functions>`,
- :doc:`cert-msc30-c <cert/msc30-c>`, :doc:`cert-msc50-cpp <cert/msc50-cpp>`,
- :doc:`cert-msc32-c <cert/msc32-c>`, :doc:`cert-msc51-cpp <cert/msc51-cpp>`,
+ :doc:`cert-msc30-c <cert/msc30-c>`, :doc:`misc-predictable-rand <misc/predictable-rand>`,
+ :doc:`cert-msc32-c <cert/msc32-c>`, :doc:`bugprone-random-generator-seed <bugprone/random-generator-seed>`,
:doc:`cert-msc33-c <cert/msc33-c>`, :doc:`bugprone-unsafe-functions <bugprone/unsafe-functions>`,
+ :doc:`cert-msc50-cpp <cert/msc50-cpp>`, :doc:`misc-predictable-rand <misc/predictable-rand>`,
+ :doc:`cert-msc51-cpp <cert/msc51-cpp>`, :doc:`bugprone-random-generator-seed <bugprone/random-generator-seed>`,
:doc:`cert-msc54-cpp <cert/msc54-cpp>`, :doc:`bugprone-signal-handler <bugprone/signal-handler>`,
:doc:`cert-oop11-cpp <cert/oop11-cpp>`, :doc:`performance-move-constructor-init <performance/move-constructor-init>`,
:doc:`cert-oop54-cpp <cert/oop54-cpp>`, :doc:`bugprone-unhandled-self-assignment <bugprone/unhandled-self-assignment>`,
+ :doc:`cert-oop57-cpp <cert/oop57-cpp>`, :doc:`bugprone-raw-memory-call-on-non-trivial-type <bugprone/raw-memory-call-on-non-trivial-type>`,
+ :doc:`cert-oop58-cpp <cert/oop58-cpp>`, :doc:`bugprone-copy-constructor-mutates-argument <bugprone/copy-constructor-mutates-argument>`,
:doc:`cert-pos44-c <cert/pos44-c>`, :doc:`bugprone-bad-signal-to-kill-thread <bugprone/bad-signal-to-kill-thread>`,
:doc:`cert-pos47-c <cert/pos47-c>`, :doc:`concurrency-thread-canceltype-asynchronous <concurrency/thread-canceltype-asynchronous>`,
:doc:`cert-sig30-c <cert/sig30-c>`, :doc:`bugprone-signal-handler <bugprone/signal-handler>`,
@@ -538,7 +550,7 @@ Check aliases
:doc:`clang-analyzer-security.insecureAPI.bcmp <clang-analyzer/security.insecureAPI.bcmp>`, `Clang Static Analyzer security.insecureAPI.bcmp <https://clang.llvm.org/docs/analyzer/checkers.html#security-insecureapi-bcmp>`_,
:doc:`clang-analyzer-security.insecureAPI.bcopy <clang-analyzer/security.insecureAPI.bcopy>`, `Clang Static Analyzer security.insecureAPI.bcopy <https://clang.llvm.org/docs/analyzer/checkers.html#security-insecureapi-bcopy>`_,
:doc:`clang-analyzer-security.insecureAPI.bzero <clang-analyzer/security.insecureAPI.bzero>`, `Clang Static Analyzer security.insecureAPI.bzero <https://clang.llvm.org/docs/analyzer/checkers.html#security-insecureapi-bzero>`_,
- :doc:`clang-analyzer-security.insecureAPI.decodeValueOfObjCType <clang-analyzer/security.insecureAPI.decodeValueOfObjCType>`, Clang Static Analyzer security.insecureAPI.decodeValueOfObjCType,
+ :doc:`clang-analyzer-security.insecureAPI.decodeValueOfObjCType <clang-analyzer/security.insecureAPI.decodeValueOfObjCType>`, `Clang Static Analyzer security.insecureAPI.decodeValueOfObjCType <https://clang.llvm.org/docs/analyzer/checkers.html#security-insecureapi-decodevalueofobjctype>`_,
:doc:`clang-analyzer-security.insecureAPI.getpw <clang-analyzer/security.insecureAPI.getpw>`, `Clang Static Analyzer security.insecureAPI.getpw <https://clang.llvm.org/docs/analyzer/checkers.html#security-insecureapi-getpw>`_,
:doc:`clang-analyzer-security.insecureAPI.gets <clang-analyzer/security.insecureAPI.gets>`, `Clang Static Analyzer security.insecureAPI.gets <https://clang.llvm.org/docs/analyzer/checkers.html#security-insecureapi-gets>`_,
:doc:`clang-analyzer-security.insecureAPI.mkstemp <clang-analyzer/security.insecureAPI.mkstemp>`, `Clang Static Analyzer security.insecureAPI.mkstemp <https://clang.llvm.org/docs/analyzer/checkers.html#security-insecureapi-mkstemp>`_,
@@ -573,6 +585,7 @@ Check aliases
:doc:`cppcoreguidelines-use-default-member-init <cppcoreguidelines/use-default-member-init>`, :doc:`modernize-use-default-member-init <modernize/use-default-member-init>`, "Yes"
:doc:`fuchsia-header-anon-namespaces <fuchsia/header-anon-namespaces>`, :doc:`google-build-namespaces <google/build-namespaces>`,
:doc:`google-readability-braces-around-statements <google/readability-braces-around-statements>`, :doc:`readability-braces-around-statements <readability/braces-around-statements>`, "Yes"
+ :doc:`google-readability-casting <google/readability-casting>`, :doc:`modernize-avoid-c-style-cast <modernize/avoid-c-style-cast>`,
:doc:`google-readability-function-size <google/readability-function-size>`, :doc:`readability-function-size <readability/function-size>`,
:doc:`google-readability-namespace-comments <google/readability-namespace-comments>`, :doc:`llvm-namespace-comment <llvm/namespace-comment>`,
:doc:`hicpp-avoid-c-arrays <hicpp/avoid-c-arrays>`, :doc:`modernize-avoid-c-arrays <modernize/avoid-c-arrays>`,
diff --git a/clang-tools-extra/docs/clang-tidy/checks/llvm/prefer-static-over-anonymous-namespace.rst b/clang-tools-extra/docs/clang-tidy/checks/llvm/prefer-static-over-anonymous-namespace.rst
index 85579ca..79179ce 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/llvm/prefer-static-over-anonymous-namespace.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/llvm/prefer-static-over-anonymous-namespace.rst
@@ -37,7 +37,7 @@ For example non-compliant code:
Should become:
.. code-block:: c++
-
+
// Small anonymous namespace for class declaration
namespace {
@@ -48,7 +48,7 @@ Should become:
};
}
-
+
// placed method definition outside of the anonymous namespace
bool StringSort::operator<(const char *RHS) const {}
@@ -70,4 +70,4 @@ Options
.. option:: AllowMemberFunctionsInClass
When `true`, only methods defined in anonymous namespace outside of the
- corresponding class will be warned. Default value is `true`. \ No newline at end of file
+ corresponding class will be warned. Default value is `true`.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/llvm/twine-local.rst b/clang-tools-extra/docs/clang-tidy/checks/llvm/twine-local.rst
index ec9ef1c..6c994a4 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/llvm/twine-local.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/llvm/twine-local.rst
@@ -14,3 +14,21 @@ should be generally avoided.
// becomes
static std::string Moo = (Twine("bark") + "bah").str();
+
+The ``Twine`` does not own the memory of its contents, so it is not
+recommended to use ``Twine`` created from temporary strings or string literals.
+
+.. code-block:: c++
+
+ static Twine getModuleIdentifier(StringRef moduleName) {
+ return moduleName + "_module";
+ }
+ void foo() {
+ Twine result = getModuleIdentifier(std::string{"abc"} + "def");
+ // temporary std::string is destroyed here, result is dangling
+ }
+
+After applying this fix-it hints, the code will use ``std::string`` instead of
+``Twine`` for local variables. However, ``Twine`` has lots of methods that
+are incompatible with ``std::string``, so the user may need to adjust the code
+manually after applying the fix-it hints.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/llvm/use-ranges.rst b/clang-tools-extra/docs/clang-tidy/checks/llvm/use-ranges.rst
index fffa2ff..1a04547 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/llvm/use-ranges.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/llvm/use-ranges.rst
@@ -12,7 +12,7 @@ Example
.. code-block:: c++
auto it = std::find(vec.begin(), vec.end(), value);
- bool all = std::all_of(vec.begin(), vec.end(),
+ bool all = std::all_of(vec.begin(), vec.end(),
[](int x) { return x > 0; });
Transforms to:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
index 93a5762..01f3b75 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
@@ -4,14 +4,14 @@ misc-const-correctness
======================
This check implements detection of local variables which could be declared as
-``const`` but are not. Declaring variables as ``const`` is required or recommended by many
-coding guidelines, such as:
+``const`` but are not. Declaring variables as ``const`` is required or
+recommended by many coding guidelines, such as:
`ES.25 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es25-declare-an-object-const-or-constexpr-unless-you-want-to-modify-its-value-later-on>`_
from the C++ Core Guidelines.
-Please note that this check's analysis is type-based only. Variables that are not modified
-but used to create a non-const handle that might escape the scope are not diagnosed
-as potential ``const``.
+Please note that this check's analysis is type-based only. Variables that are
+not modified but used to create a non-const handle that might escape the scope
+are not diagnosed as potential ``const``.
.. code-block:: c++
@@ -44,8 +44,8 @@ The check can analyze values, pointers and references and pointees:
int const*const pointer_variable = &potential_const_int; // After transformation, both pointer itself and pointee are supported.
int last_copy = *pointer_variable;
-The automatic code transformation is only applied to variables that are declared in single
-declarations. You may want to prepare your code base with
+The automatic code transformation is only applied to variables that are
+declared in single declarations. You may want to prepare your code base with
:doc:`readability-isolate-declaration <../readability/isolate-declaration>` first.
Note that there is the check
@@ -58,10 +58,11 @@ Limitations
The check does not run on `C` code.
-The check will not analyze templated variables or variables that are instantiation dependent.
-Different instantiations can result in different ``const`` correctness properties and in general it
-is not possible to find all instantiations of a template. The template might be used differently in
-an independent translation unit.
+The check will not analyze templated variables or variables that are
+instantiation dependent. Different instantiations can result in
+different ``const`` correctness properties and in general it is not
+possible to find all instantiations of a template. The template might
+be used differently in an independent translation unit.
Options
-------
@@ -99,7 +100,7 @@ Options
.. option:: AnalyzePointers
Enable or disable the analysis of pointers variables, like
- ``int *ptr = &i;``. For specific checks, see
+ ``int *ptr = &i;``. For specific checks, see
:option:`WarnPointersAsValues` and :option:`WarnPointersAsPointers`.
Default is `true`.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/coroutine-hostile-raii.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/coroutine-hostile-raii.rst
index 0b054e4..fc67634 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/coroutine-hostile-raii.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/coroutine-hostile-raii.rst
@@ -7,21 +7,23 @@ Detects when objects of certain hostile RAII types persists across suspension
points in a coroutine. Such hostile types include scoped-lockable types and
types belonging to a configurable denylist.
-Some objects require that they be destroyed on the same thread that created them.
-Traditionally this requirement was often phrased as "must be a local variable",
-under the assumption that local variables always work this way. However this is
-incorrect with C++20 coroutines, since an intervening ``co_await`` may cause the
-coroutine to suspend and later be resumed on another thread.
-
-The lifetime of an object that requires being destroyed on the same thread must
-not encompass a ``co_await`` or ``co_yield`` point. If you create/destroy an object,
-you must do so without allowing the coroutine to suspend in the meantime.
+Some objects require that they be destroyed on the same thread that created
+them. Traditionally this requirement was often phrased as "must be a local
+variable", under the assumption that local variables always work this way.
+However this is incorrect with C++20 coroutines, since an intervening
+``co_await`` may cause the coroutine to suspend and later be resumed on
+another thread.
+
+The lifetime of an object that requires being destroyed on the same thread
+must not encompass a ``co_await`` or ``co_yield`` point. If you create/destroy
+an object, you must do so without allowing the coroutine to suspend in the
+meantime.
Following types are considered as hostile:
- - Scoped-lockable types: A scoped-lockable object persisting across a suspension
- point is problematic as the lock held by this object could be unlocked by a
- different thread. This would be undefined behaviour.
+ - Scoped-lockable types: A scoped-lockable object persisting across a
+ suspension point is problematic as the lock held by this object could
+ be unlocked by a different thread. This would be undefined behaviour.
This includes all types annotated with the ``scoped_lockable`` attribute.
- Types belonging to a configurable denylist.
@@ -81,3 +83,23 @@ Options
Eg: `my::safe::awaitable;other::awaitable`
Default is an empty string.
+.. option:: AllowedCallees
+
+ A semicolon-separated list of callee function names which can
+ be safely awaited while having hostile RAII objects in scope.
+ Example usage:
+
+ .. code-block:: c++
+
+ // Consider option AllowedCallees = "noop"
+ task noop() { co_return; }
+
+ task coro() {
+ // This persists across the co_await but is not flagged
+ // because the awaitable is considered safe to await on.
+ const std::lock_guard l(&mu_);
+ co_await noop();
+ }
+
+ Eg: `my::safe::await;other::await`
+ Default is an empty string.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/header-include-cycle.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/header-include-cycle.rst
index de08f0d..d0ae0ea 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/header-include-cycle.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/header-include-cycle.rst
@@ -47,18 +47,18 @@ quality, and a more maintainable codebase overall. Additionally, by ensuring
that header files are organized in a way that avoids cyclic dependencies,
developers can make their code easier to understand and modify over time.
-It's worth noting that only user-defined headers their dependencies are analyzed,
-System includes such as standard library headers and third-party library headers
-are excluded. System includes are usually well-designed and free of include
-cycles, and ignoring them helps to focus on potential issues within the
-project's own codebase. This limitation doesn't diminish the ability to detect
-``#include`` cycles within the analyzed code.
+It's worth noting that only user-defined headers their dependencies are
+analyzed, system includes such as standard library headers and third-party
+library headers are excluded. System includes are usually well-designed and
+free of include cycles, and ignoring them helps to focus on potential issues
+within the project's own codebase. This limitation doesn't diminish the
+ability to detect ``#include`` cycles within the analyzed code.
Developers should carefully review any warnings or feedback provided by this
solution. While the analysis aims to identify and prevent include cycles, there
may be situations where exceptions or modifications are necessary. It's
-important to exercise judgment and consider the specific context of the codebase
-when making adjustments.
+important to exercise judgment and consider the specific context of the
+codebase when making adjustments.
Options
-------
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
index 34833a3..4364610 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
@@ -10,7 +10,7 @@ Findings correspond to https://clangd.llvm.org/design/include-cleaner.
Example:
.. code-block:: c++
-
+
// foo.h
class Foo{};
// bar.h
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/misleading-bidirectional.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/misleading-bidirectional.rst
index 16ffc97..e9bc19a 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/misleading-bidirectional.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/misleading-bidirectional.rst
@@ -3,7 +3,7 @@
misc-misleading-bidirectional
=============================
-Warn about unterminated bidirectional unicode sequence, detecting potential attack
+Warns about unterminated bidirectional unicode sequence, detecting potential attack
as described in the `Trojan Source <https://www.trojansource.codes>`_ attack.
Example:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/misleading-identifier.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/misleading-identifier.rst
index 1e2b61a..5941d1c 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/misleading-identifier.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/misleading-identifier.rst
@@ -4,8 +4,8 @@ misc-misleading-identifier
==========================
Finds identifiers that contain Unicode characters with right-to-left direction,
-which can be confusing as they may change the understanding of a whole statement
-line, as described in `Trojan Source <https://trojansource.codes>`_.
+which can be confusing as they may change the understanding of a whole
+statement line, as described in `Trojan Source <https://trojansource.codes>`_.
An example of such misleading code follows:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/no-recursion.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/no-recursion.rst
index 1c04dbf..53753f1 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/no-recursion.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/no-recursion.rst
@@ -11,7 +11,8 @@ and displays one example of a possible call graph loop (recursion).
References:
* CERT C++ Coding Standard rule `DCL56-CPP. Avoid cycles during initialization of static objects <https://wiki.sei.cmu.edu/confluence/display/cplusplus/DCL56-CPP.+Avoid+cycles+during+initialization+of+static+objects>`_.
-* JPL Institutional Coding Standard for the C Programming Language (JPL DOCID D-60411) rule `2.4 Do not use direct or indirect recursion`.
+* JPL Institutional Coding Standard for the C Programming Language
+ (JPL DOCID D-60411) rule `2.4 Do not use direct or indirect recursion`.
* OpenCL Specification, Version 1.2 rule `6.9 Restrictions: i. Recursion is not supported. <https://www.khronos.org/registry/OpenCL/specs/opencl-1.2.pdf>`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/non-copyable-objects.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/non-copyable-objects.rst
index d1f7bba..d3190e1 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/non-copyable-objects.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/non-copyable-objects.rst
@@ -5,9 +5,12 @@ misc-non-copyable-objects
`cert-fio38-c` redirects here as an alias for this check.
-The check flags dereferences and non-pointer declarations of objects that are
+Flags dereferences and non-pointer declarations of objects that are
not meant to be passed by value, such as C FILE objects or POSIX
``pthread_mutex_t`` objects.
+References
+----------
+
This check corresponds to CERT C++ Coding Standard rule `FIO38-C. Do not copy a FILE object
<https://www.securecoding.cert.org/confluence/display/c/FIO38-C.+Do+not+copy+a+FILE+object>`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/override-with-different-visibility.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/override-with-different-visibility.rst
index 310bfe2..9958df5 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/override-with-different-visibility.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/override-with-different-visibility.rst
@@ -5,11 +5,12 @@ misc-override-with-different-visibility
Finds virtual function overrides with different visibility than the function
in the base class. This includes for example if a virtual function declared as
-``private`` is overridden and declared as ``public`` in a subclass. The detected
-change is the modification of visibility resulting from keywords ``public``,
-``protected``, ``private`` at overridden virtual functions. The check applies to
-any normal virtual function and optionally to destructors or operators. Use of
-the ``using`` keyword is not considered as visibility change by this check.
+``private`` is overridden and declared as ``public`` in a subclass. The
+detected change is the modification of visibility resulting from keywords
+``public``, ``protected``, ``private`` at overridden virtual functions. The
+check applies to any normal virtual function and optionally to destructors or
+operators. Use of the ``using`` keyword is not considered as visibility
+change by this check.
.. code-block:: c++
@@ -20,7 +21,7 @@ the ``using`` keyword is not considered as visibility change by this check.
private:
virtual void f_priv();
};
-
+
class B: public A {
public:
void f_priv(); // warning: changed visibility from private to public
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/predictable-rand.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/predictable-rand.rst
new file mode 100644
index 0000000..0015664
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/predictable-rand.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - misc-predictable-rand
+
+misc-predictable-rand
+=====================
+
+Warns for the usage of ``std::rand()``. Pseudorandom number generators use
+mathematical algorithms to produce a sequence of numbers with good
+statistical properties, but the numbers produced are not genuinely random.
+The ``std::rand()`` function takes a seed (number), runs a mathematical
+operation on it and returns the result. By manipulating the seed the result
+can be predictable.
+
+References
+----------
+
+This check corresponds to the CERT C Coding Standard rules
+`MSC30-C. Do not use the rand() function for generating pseudorandom numbers
+<https://wiki.sei.cmu.edu/confluence/display/c/MSC30-C.+Do+not+use+the+rand%28%29+function+for+generating+pseudorandom+numbers>`_.
+`MSC50-CPP. Do not use std::rand() for generating pseudorandom numbers
+<https://wiki.sei.cmu.edu/confluence/display/cplusplus/MSC50-CPP.+Do+not+use+std%3A%3Arand%28%29+for+generating+pseudorandom+numbers>`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/throw-by-value-catch-by-reference.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/throw-by-value-catch-by-reference.rst
index b89fbe8..cfea1c8 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/throw-by-value-catch-by-reference.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/throw-by-value-catch-by-reference.rst
@@ -7,16 +7,16 @@ misc-throw-by-value-catch-by-reference
Finds violations of the rule "Throw by value, catch by reference" presented for
example in "C++ Coding Standards" by H. Sutter and A. Alexandrescu, as well as
-the CERT C++ Coding Standard rule `ERR61-CPP. Catch exceptions by lvalue reference
-<https://wiki.sei.cmu.edu/confluence/display/cplusplus/ERR61-CPP.+Catch+exceptions+by+lvalue+reference>`_.
+the CERT C++ Coding Standard rule `ERR61-CPP. Catch exceptions by lvalue
+reference <https://wiki.sei.cmu.edu/confluence/display/cplusplus/ERR61-CPP.+Catch+exceptions+by+lvalue+reference>`_.
Exceptions:
* Throwing string literals will not be flagged despite being a pointer. They
are not susceptible to slicing and the usage of string literals is
idiomatic.
- * Catching character pointers (``char``, ``wchar_t``, unicode character types)
- will not be flagged to allow catching string literals.
+ * Catching character pointers (``char``, ``wchar_t``, unicode character
+ types) will not be flagged to allow catching string literals.
* Moved named values will not be flagged as not throwing an anonymous
temporary. In this case we can be sure that the user knows that the object
can't be accessed outside catch blocks handling the error.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/unused-parameters.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/unused-parameters.rst
index 9321f65..3d90245 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/unused-parameters.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/unused-parameters.rst
@@ -8,9 +8,9 @@ code (e.g. when a different parameter is used instead). The suggested fixes
either comment parameter name out or remove the parameter completely, if all
callers of the function are in the same translation unit and can be updated.
-The check is similar to the ``-Wunused-parameter`` compiler diagnostic and can be
-used to prepare a codebase to enabling of that diagnostic. By default the check
-is more permissive (see :option:`StrictMode`).
+The check is similar to the `-Wunused-parameter` compiler diagnostic and
+can be used to prepare a codebase to enabling of that diagnostic. By default
+the check is more permissive (see :option:`StrictMode`).
.. code-block:: c++
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/unused-using-decls.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/unused-using-decls.rst
index 29cd5a23..1754465 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/unused-using-decls.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/unused-using-decls.rst
@@ -5,9 +5,10 @@ misc-unused-using-decls
Finds unused ``using`` declarations.
-Unused ``using``` declarations in header files will not be diagnosed since these
-using declarations are part of the header's public API. Allowed header file
-extensions can be configured via the global option `HeaderFileExtensions`.
+Unused ``using`` declarations in header files will not be diagnosed
+since these using declarations are part of the header's public API.
+Allowed header file extensions can be configured via the global
+option `HeaderFileExtensions`.
Example:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
index 0950127..102052d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
@@ -8,16 +8,16 @@ that could instead be moved into an anonymous namespace.
Anonymous namespaces are the "superior alternative" according to the C++
Standard. ``static`` was proposed for deprecation, but later un-deprecated to
-keep C compatibility [1]. ``static`` is an overloaded term with different meanings in
-different contexts, so it can create confusion.
+keep C compatibility [1]. ``static`` is an overloaded term with different
+meanings in different contexts, so it can create confusion.
The following uses of ``static`` will *not* be diagnosed:
* Functions or variables in header files, since anonymous namespaces in headers
- is considered an antipattern. Allowed header file extensions can be configured
- via the global option `HeaderFileExtensions`.
-* ``const`` or ``constexpr`` variables, since they already have implicit internal
- linkage in C++.
+ is considered an antipattern. Allowed header file extensions can be
+ configured via the global option `HeaderFileExtensions`.
+* ``const`` or ``constexpr`` variables, since they already have implicit
+ internal linkage in C++.
Examples:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/use-internal-linkage.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/use-internal-linkage.rst
index 508b0ca..224ad21 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/use-internal-linkage.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/use-internal-linkage.rst
@@ -41,8 +41,8 @@ Options
Selects what kind of a fix the check should provide. The default is `UseStatic`.
- ``None``
+ - `None`
Don't fix automatically.
- ``UseStatic``
+ - `UseStatic`
Add ``static`` for internal linkage variable and function.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-style-cast.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-style-cast.rst
new file mode 100644
index 0000000..c43fb00
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-style-cast.rst
@@ -0,0 +1,36 @@
+.. title:: clang-tidy - modernize-avoid-c-style-cast
+
+modernize-avoid-c-style-cast
+============================
+
+Finds usages of C-style casts.
+
+C-style casts can perform a variety of different conversions (``const_cast``,
+``static_cast``, ``reinterpret_cast``, or a combination). This makes them
+dangerous as the intent is not clear, and they can silently perform unsafe
+conversions between incompatible types.
+
+This check is similar to `-Wold-style-cast`, but it suggests automated fixes
+in some cases. The reported locations should not be different from the ones
+generated by `-Wold-style-cast`.
+
+Examples
+--------
+
+.. code-block:: c++
+
+ class A {
+ public:
+ std::string v;
+ };
+
+ A a;
+ double *num = (double*)(&a); // Compiles! Hides danger
+ // num = static_cast<double*>(&a); // Won't compile (good!)
+ num = reinterpret_cast<double*>(&a); // Compiles, danger is explicit
+
+
+References
+----------
+
+Corresponding cpplint.py check name: `readability/casting`.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-setjmp-longjmp.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-setjmp-longjmp.rst
index ae45619..744a12c 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-setjmp-longjmp.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-setjmp-longjmp.rst
@@ -3,7 +3,8 @@
modernize-avoid-setjmp-longjmp
==============================
-Flags all call expressions involving ``setjmp()`` and ``longjmp()`` in C++ code.
+Flags all call expressions involving ``setjmp()`` and
+``longjmp()`` in C++ code.
Exception handling with ``throw`` and ``catch`` should be used instead.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-variadic-functions.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-variadic-functions.rst
index 1c93c6b3..5b1da41 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-variadic-functions.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-variadic-functions.rst
@@ -15,4 +15,4 @@ References
This check corresponds to the CERT C++ Coding Standard rule
`DCL50-CPP. Do not define a C-style variadic function
-<https://www.securecoding.cert.org/confluence/display/cplusplus/DCL50-CPP.+Do+not+define+a+C-style+variadic+function>`_. \ No newline at end of file
+<https://www.securecoding.cert.org/confluence/display/cplusplus/DCL50-CPP.+Do+not+define+a+C-style+variadic+function>`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/concat-nested-namespaces.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/concat-nested-namespaces.rst
index af2378e..6e1f505 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/concat-nested-namespaces.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/concat-nested-namespaces.rst
@@ -3,8 +3,10 @@
modernize-concat-nested-namespaces
==================================
-Checks for use of nested namespaces such as ``namespace a { namespace b { ... } }``
-and suggests changing to the more concise syntax introduced in C++17: ``namespace a::b { ... }``.
+Checks for use of nested namespaces such as
+``namespace a { namespace b { ... } }``
+and suggests changing to the more concise syntax introduced
+in C++17: ``namespace a::b { ... }``.
Inline namespaces are not modified.
For example:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst
index 58d61d1..e11ced7 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst
@@ -107,7 +107,8 @@ Original:
for (int i = 0; i < size(v); ++i)
cout << v[i];
-After applying the check with minimum confidence level set to `reasonable` (default):
+After applying the check with minimum confidence level set to
+`reasonable` (default):
.. code-block:: c++
@@ -320,6 +321,6 @@ not be used on code with a compatibility requirement of OpenMP prior to
version 5. It is **intentional** that this check does not make any attempts to
exclude incorrect diagnostics on OpenMP for loops prior to OpenMP 5.
-To prevent this check to be applied (and to break) OpenMP for loops but still be
-applied to non-OpenMP for loops the usage of ``NOLINT`` (see
-:ref:`clang-tidy-nolint`) on the specific for loops is recommended.
+To prevent this check to be applied (and to break) OpenMP for loops
+but still be applied to non-OpenMP for loops the usage of ``NOLINT``
+(see :ref:`clang-tidy-nolint`) on the specific for loops is recommended.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/min-max-use-initializer-list.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/min-max-use-initializer-list.rst
index d6721a2..157c447 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/min-max-use-initializer-list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/min-max-use-initializer-list.rst
@@ -3,7 +3,7 @@
modernize-min-max-use-initializer-list
======================================
-Replaces nested ``std::min`` and ``std::max`` calls with an initializer list
+Replaces nested ``std::min`` and ``std::max`` calls with an initializer list
where applicable.
For instance, consider the following code:
@@ -21,8 +21,8 @@ The check will transform the above code to:
Performance Considerations
==========================
-While this check simplifies the code and makes it more readable, it may cause
-performance degradation for non-trivial types due to the need to copy objects
+While this check simplifies the code and makes it more readable, it may cause
+performance degradation for non-trivial types due to the need to copy objects
into the initializer list.
To avoid this, it is recommended to use `std::ref` or `std::cref` for
@@ -47,4 +47,4 @@ Options
.. option:: IgnoreTrivialTypesOfSizeAbove
An integer specifying the size (in bytes) above which trivial types are
- ignored. Default is `32`. \ No newline at end of file
+ ignored. Default is `32`.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-disallow-copy-and-assign-macro.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-disallow-copy-and-assign-macro.rst
index 5ef6ae7..485abca 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-disallow-copy-and-assign-macro.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-disallow-copy-and-assign-macro.rst
@@ -38,9 +38,9 @@ Limitations
-----------
* Notice that the migration example above leaves the ``private`` access
- specification untouched. You might want to run the check :doc:`modernize-use-equals-delete
- <../modernize/use-equals-delete>` to get warnings for deleted functions in
- private sections.
+ specification untouched. You might want to run the check
+ :doc:`modernize-use-equals-delete <../modernize/use-equals-delete>`
+ to get warnings for deleted functions in private sections.
Options
-------
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-random-shuffle.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-random-shuffle.rst
index 546de84..c6dcd72 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-random-shuffle.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/replace-random-shuffle.rst
@@ -3,9 +3,12 @@
modernize-replace-random-shuffle
================================
-This check will find occurrences of ``std::random_shuffle`` and replace it with ``std::shuffle``. In C++17 ``std::random_shuffle`` will no longer be available and thus we need to replace it.
+This check will find occurrences of ``std::random_shuffle`` and replace it with
+``std::shuffle``. In C++17 ``std::random_shuffle`` will no longer be available
+and thus we need to replace it.
-Below are two examples of what kind of occurrences will be found and two examples of what it will be replaced with.
+Below are two examples of what kind of occurrences will be found and two
+examples of what it will be replaced with.
.. code-block:: c++
@@ -23,10 +26,18 @@ Both of these examples will be replaced with:
std::shuffle(vec.begin(), vec.end(), std::mt19937(std::random_device()()));
-The second example will also receive a warning that ``randomFunc`` is no longer supported in the same way as before so if the user wants the same functionality, the user will need to change the implementation of the ``randomFunc``.
+The second example will also receive a warning that ``randomFunc`` is no longer
+supported in the same way as before so if the user wants the same
+functionality, the user will need to change the implementation of the
+``randomFunc``.
-One thing to be aware of here is that ``std::random_device`` is quite expensive to initialize. So if you are using the code in a performance critical place, you probably want to initialize it elsewhere.
-Another thing is that the seeding quality of the suggested fix is quite poor: ``std::mt19937`` has an internal state of 624 32-bit integers, but is only seeded with a single integer. So if you require
+One thing to be aware of here is that ``std::random_device`` is quite expensive
+to initialize. So if you are using the code in a performance critical place,
+you probably want to initialize it elsewhere.
+
+Another thing is that the seeding quality of the suggested fix is quite poor:
+``std::mt19937`` has an internal state of 624 32-bit integers, but is only
+seeded with a single integer. So if you require
higher quality randomness, you should consider seeding better, for example:
.. code-block:: c++
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.rst
index 91be4fb..fbe2b85 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.rst
@@ -4,7 +4,8 @@ modernize-type-traits
=====================
Converts standard library type traits of the form ``traits<...>::type`` and
-``traits<...>::value`` into ``traits_t<...>`` and ``traits_v<...>`` respectively.
+``traits<...>::value`` into ``traits_t<...>`` and
+``traits_v<...>`` respectively.
For example:
@@ -37,7 +38,7 @@ Options
#define IS_SIGNED(T) std::is_signed<T>::value
- Defaults to `false`.
+ Defaults to `false`.
Limitations
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/unary-static-assert.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/unary-static-assert.rst
index 31ece10..9a0de6c 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/unary-static-assert.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/unary-static-assert.rst
@@ -3,8 +3,9 @@
modernize-unary-static-assert
=============================
-The check diagnoses any ``static_assert`` declaration with an empty string literal
-and provides a fix-it to replace the declaration with a single-argument ``static_assert`` declaration.
+The check diagnoses any ``static_assert`` declaration with an
+empty string literal and provides a fix-it note to replace the
+declaration with a single-argument ``static_assert`` declaration.
The check is only applicable for C++17 and later code.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-auto.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-auto.rst
index 6753617..3cd37e0 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-auto.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-auto.rst
@@ -163,8 +163,8 @@ The check handles ``static_cast``, ``dynamic_cast``, ``const_cast``,
``reinterpret_cast``, functional casts, C-style casts and function templates
that behave as casts, such as ``llvm::dyn_cast``, ``boost::lexical_cast`` and
``gsl::narrow_cast``. Calls to function templates are considered to behave as
-casts if the first template argument is explicit and is a type, and the function
-returns that type, or a pointer or reference to it.
+casts if the first template argument is explicit and is a type, and the
+function returns that type, or a pointer or reference to it.
Limitations
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-constraints.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-constraints.rst
index a8b31b8..232cd01 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-constraints.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-constraints.rst
@@ -6,8 +6,8 @@ modernize-use-constraints
Replace ``std::enable_if`` with C++20 requires clauses.
``std::enable_if`` is a SFINAE mechanism for selecting the desired function or
-class template based on type traits or other requirements. ``enable_if`` changes
-the meta-arity of the template, and has other
+class template based on type traits or other requirements. ``enable_if``
+changes the meta-arity of the template, and has other
`adverse side effects
<https://open-std.org/JTC1/SC22/WG21/docs/papers/2016/p0225r0.html>`_
in the code. C++20 introduces concepts and constraints as a cleaner language
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.rst
index 62ea906..1b8c9c3 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.rst
@@ -3,8 +3,8 @@
modernize-use-designated-initializers
=====================================
-Finds initializer lists for aggregate types which could be written as designated
-initializers instead.
+Finds initializer lists for aggregate types which could be written as
+designated initializers instead.
With plain initializer lists, it is very easy to introduce bugs when adding new
fields in the middle of a struct or class type. The same confusion might arise
@@ -38,9 +38,9 @@ declaration of ``S``.
Even when compiling in a language version older than C++20, depending on your
compiler, designated initializers are potentially supported. Therefore, the
check is by default restricted to C99/C++20 and above. Check out the options
-``-Wc99-designator`` to get support for mixed designators in initializer list in
-C and ``-Wc++20-designator`` for support of designated initializers in older C++
-language modes.
+`-Wc99-designator` to get support for mixed designators in initializer list
+in C and `-Wc++20-designator` for support of designated initializers in older
+C++ language modes.
Options
-------
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-emplace.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-emplace.rst
index e020ece..f1031f6 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-emplace.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-emplace.rst
@@ -17,19 +17,22 @@ The :option:`ContainersWithPushBack`, :option:`ContainersWithPush`, and
types that support the ``push_back``, ``push``, and ``push_front`` operations
respectively. The default values for these options are as follows:
-* :option:`ContainersWithPushBack`: ``std::vector``, ``std::deque``, and ``std::list``.
-* :option:`ContainersWithPush`: ``std::stack``, ``std::queue``, and ``std::priority_queue``.
-* :option:`ContainersWithPushFront`: ``std::forward_list``, ``std::list``, and ``std::deque``.
+* :option:`ContainersWithPushBack`: ``std::vector``, ``std::deque``,
+ and ``std::list``.
+* :option:`ContainersWithPush`: ``std::stack``, ``std::queue``,
+ and ``std::priority_queue``.
+* :option:`ContainersWithPushFront`: ``std::forward_list``,
+ ``std::list``, and ``std::deque``.
This check also reports when an ``emplace``-like method is improperly used,
for example using ``emplace_back`` while also calling a constructor. This
-creates a temporary that requires at best a move and at worst a copy. Almost all
-``emplace``-like functions in the STL are covered by this, with ``try_emplace``
-on ``std::map`` and ``std::unordered_map`` being the exception as it behaves
-slightly differently than all the others. More containers can be added with the
-:option:`EmplacyFunctions` option, so long as the container defines a
-``value_type`` type, and the ``emplace``-like functions construct a
-``value_type`` object.
+creates a temporary that requires at best a move and at worst a copy. Almost
+all ``emplace``-like functions in the STL are covered by this, with
+``try_emplace`` on ``std::map`` and ``std::unordered_map`` being the
+exception as it behaves slightly differently than all the others. More
+containers can be added with the :option:`EmplacyFunctions` option, so long
+as the container defines a ``value_type`` type, and the ``emplace``-like
+functions construct a ``value_type`` object.
Before:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
index d354fcc..f632c81 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-delete.rst
@@ -13,9 +13,9 @@ definition. This approach would result in either a compiler error (when
attempting to call a private function) or a linker error (due to an undefined
reference).
-However, subsequent to the advent of C++11, a more conventional approach emerged
-for achieving this purpose. It involves flagging functions as ``= delete`` and
-keeping them in the ``public`` section of the class.
+However, subsequent to the advent of C++11, a more conventional approach
+emerged for achieving this purpose. It involves flagging functions as
+``= delete`` and keeping them in the ``public`` section of the class.
To prevent false positives, this check is only active within a translation
unit where all other member functions have been implemented. The check will
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst
index 912b42b3..98779d8 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst
@@ -114,7 +114,7 @@ If calls are made using reverse iterators on containers, The code will be
fixed using the ``std::views::reverse`` adaptor.
.. code-block:: c++
-
+
auto AreSame = std::equal(Items1.rbegin(), Items1.rend(),
std::crbegin(Items2), std::crend(Items2));
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-scoped-lock.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-scoped-lock.rst
index 7cf24b4..9235d42 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-scoped-lock.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-scoped-lock.rst
@@ -93,9 +93,9 @@ Options
template <typename T>
using Lock = std::lock_guard<T>; // warning: use 'std::scoped_lock' instead of 'std::lock_guard'
-
+
using LockMutex = std::lock_guard<std::mutex>; // warning: use 'std::scoped_lock' instead of 'std::lock_guard'
-
+
typedef std::lock_guard<std::mutex> LockDef; // warning: use 'std::scoped_lock' instead of 'std::lock_guard'
- using std::lock_guard; // warning: use 'std::scoped_lock' instead of 'std::lock_guard' \ No newline at end of file
+ using std::lock_guard; // warning: use 'std::scoped_lock' instead of 'std::lock_guard'
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-starts-ends-with.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-starts-ends-with.rst
index 1babc2d..fd89b78 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-starts-ends-with.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-starts-ends-with.rst
@@ -4,7 +4,7 @@ modernize-use-starts-ends-with
==============================
Checks for common roundabout ways to express ``starts_with`` and ``ends_with``
-and suggests replacing with the simpler method when it is available. Notably,
+and suggests replacing with the simpler method when it is available. Notably,
this will work with ``std::string`` and ``std::string_view``.
Covered scenarios:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst
index cfa11d3..e87825f 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst
@@ -22,7 +22,7 @@ into:
return std::format("The {} is {:3}", description, value);
The check uses the same format-string-conversion algorithm as
-`modernize-use-std-print <../modernize/use-std-print.html>`_ and its
+:doc:`modernize-use-std-print <../modernize/use-std-print>` and its
shortcomings and behaviour in combination with macros are described in the
documentation for that check.
@@ -62,12 +62,12 @@ Options
.. option:: StrFormatLikeFunctions
- A semicolon-separated list of (fully qualified) function names to
- replace, with the requirement that the first parameter contains the
- printf-style format string and the arguments to be formatted follow
- immediately afterwards. Qualified member function names are supported,
- but the replacement function name must be unqualified. The default value
- for this option is `absl::StrFormat`.
+ A semicolon-separated list of regular expressions matching the
+ (fully qualified) names of functions to replace, with the requirement that
+ the first parameter contains the printf-style format string and the
+ arguments to be formatted follow immediately afterwards. Qualified member
+ function names are supported, but the replacement function name must be
+ unqualified. The default value is `absl::StrFormat`.
.. option:: ReplacementFormatFunction
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
index 0cf51e3..4641975 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
@@ -7,9 +7,11 @@ Converts calls to ``printf``, ``fprintf``, ``absl::PrintF`` and
``absl::FPrintf`` to equivalent calls to C++23's ``std::print`` or
``std::println`` as appropriate, modifying the format string appropriately.
The replaced and replacement functions can be customised by configuration
-options. Each argument that is the result of a call to ``std::string::c_str()`` and
-``std::string::data()`` will have that now-unnecessary call removed in a
-similar manner to the `readability-redundant-string-cstr` check.
+options. Each argument that is the result of a call to
+``std::string::c_str()`` and ``std::string::data()`` will have that
+now-unnecessary call removed in a similar manner to the
+:doc:`readability-redundant-string-cstr
+<../readability/redundant-string-cstr>` check.
In other words, it turns lines like:
@@ -122,25 +124,27 @@ Options
.. option:: PrintfLikeFunctions
- A semicolon-separated list of (fully qualified) function names to
- replace, with the requirement that the first parameter contains the
- printf-style format string and the arguments to be formatted follow
- immediately afterwards. Qualified member function names are supported,
- but the replacement function name must be unqualified. If neither this
- option nor `FprintfLikeFunctions` are set then the default value for
- this option is `printf; absl::PrintF`, otherwise it is empty.
+ A semicolon-separated list of regular expressions matching the
+ (fully qualified) names of functions to replace, with the requirement
+ that the first parameter contains the printf-style format string and the
+ arguments to be formatted follow immediately afterwards. Qualified member
+ function names are supported, but the replacement function name must be
+ unqualified. If neither this option nor `FprintfLikeFunctions` are set then
+ the default value is `printf; absl::PrintF`, otherwise it is the empty
+ string.
.. option:: FprintfLikeFunctions
- A semicolon-separated list of (fully qualified) function names to
- replace, with the requirement that the first parameter is retained, the
- second parameter contains the printf-style format string and the
- arguments to be formatted follow immediately afterwards. Qualified
- member function names are supported, but the replacement function name
- must be unqualified. If neither this option nor `PrintfLikeFunctions`
- are set then the default value for this option is `fprintf;
- absl::FPrintF`, otherwise it is empty.
+ A semicolon-separated list of regular expressions matching the
+ (fully qualified) names of functions to replace, with the requirement
+ that the first parameter is retained, the second parameter contains the
+ printf-style format string and the arguments to be formatted follow
+ immediately afterwards. Qualified member function names are supported,
+ but the replacement function name must be unqualified. If neither this
+ option nor `PrintfLikeFunctions` are set then the default value is
+ `fprintf;absl::FPrintF`, otherwise it is the empty string.
+
.. option:: ReplacementPrintFunction
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-trailing-return-type.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-trailing-return-type.rst
index 63b8885..f74158b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-trailing-return-type.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-trailing-return-type.rst
@@ -37,9 +37,12 @@ The following categories of return types cannot be rewritten currently:
* member function pointers
* member pointers
-Unqualified names in the return type might erroneously refer to different entities after the rewrite.
-Preventing such errors requires a full lookup of all unqualified names present in the return type in the scope of the trailing return type location.
-This location includes e.g. function parameter names and members of the enclosing class (including all inherited classes).
+Unqualified names in the return type might erroneously refer to different
+entities after the rewrite.
+Preventing such errors requires a full lookup of all unqualified names
+present in the return type in the scope of the trailing return type location.
+This location includes e.g. function parameter names and members of the
+enclosing class (including all inherited classes).
Such a lookup is currently not implemented.
Given the following piece of code
@@ -66,7 +69,8 @@ a careless rewrite would produce the following output:
};
auto CC::m() -> S { return {0}; } // error
-This code fails to compile because the S in the context of f refers to the equally named function parameter.
+This code fails to compile because the S in the context of f refers to the
+equally named function parameter.
Similarly, the S in the context of m refers to the equally named class member.
The check can currently only detect and avoid a clash with a function parameter name.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst
index 32272a0..9eedf20 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst
@@ -48,5 +48,5 @@ Options
.. option:: IgnoreExternC
- If set to `true`, the check will not give warning inside `extern "C"`scope.
- Default is `false` \ No newline at end of file
+ If set to `true`, the check will not give warning inside ``extern "C"``
+ scope. Default is `false`
diff --git a/clang-tools-extra/docs/clang-tidy/checks/mpi/buffer-deref.rst b/clang-tools-extra/docs/clang-tidy/checks/mpi/buffer-deref.rst
index ef9f391..9658246 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/mpi/buffer-deref.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/mpi/buffer-deref.rst
@@ -5,9 +5,10 @@ mpi-buffer-deref
This check verifies if a buffer passed to an MPI (Message Passing Interface)
function is sufficiently dereferenced. Buffers should be passed as a single
-pointer or array. As MPI function signatures specify ``void *`` for their buffer
-types, insufficiently dereferenced buffers can be passed, like for example as
-double pointers or multidimensional arrays, without a compiler warning emitted.
+pointer or array. As MPI function signatures specify ``void *`` for their
+buffer types, insufficiently dereferenced buffers can be passed, like for
+example as double pointers or multidimensional arrays, without a compiler
+warning emitted.
Examples:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/mpi/type-mismatch.rst b/clang-tools-extra/docs/clang-tidy/checks/mpi/type-mismatch.rst
index 10752ef..e5d174c3 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/mpi/type-mismatch.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/mpi/type-mismatch.rst
@@ -3,10 +3,11 @@
mpi-type-mismatch
=================
-This check verifies if buffer type and MPI (Message Passing Interface) datatype
-pairs match for used MPI functions. All MPI datatypes defined by the MPI
-standard (3.1) are verified by this check. User defined typedefs, custom MPI
-datatypes and null pointer constants are skipped, in the course of verification.
+This check verifies if buffer type and MPI (Message Passing Interface)
+datatype pairs match for used MPI functions. All MPI datatypes defined
+by the MPI standard (3.1) are verified by this check. User defined typedefs,
+custom MPI datatypes and null pointer constants are skipped, in the course
+of verification.
Example:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/objc/forbidden-subclassing.rst b/clang-tools-extra/docs/clang-tidy/checks/objc/forbidden-subclassing.rst
index 4bb023c..3894094 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/objc/forbidden-subclassing.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/objc/forbidden-subclassing.rst
@@ -3,11 +3,11 @@
objc-forbidden-subclassing
==========================
-Finds Objective-C classes which are subclasses of classes which are not designed
-to be subclassed.
+Finds Objective-C classes which are subclasses of classes which are
+not designed to be subclassed.
-By default, includes a list of Objective-C classes which are publicly documented
-as not supporting subclassing.
+By default, includes a list of Objective-C classes which are publicly
+documented as not supporting subclassing.
.. note::
diff --git a/clang-tools-extra/docs/clang-tidy/checks/objc/nsdate-formatter.rst b/clang-tools-extra/docs/clang-tidy/checks/objc/nsdate-formatter.rst
index cff493b..ea54a05 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/objc/nsdate-formatter.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/objc/nsdate-formatter.rst
@@ -3,71 +3,93 @@
objc-nsdate-formatter
=====================
-When ``NSDateFormatter`` is used to convert an ``NSDate`` type to a ``String`` type, the user
-can specify a custom format string. Certain format specifiers are undesirable
-despite being legal. See http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns for all legal date patterns.
+When ``NSDateFormatter`` is used to convert an ``NSDate`` type to a ``String``
+type, the user can specify a custom format string. Certain format specifiers
+are undesirable despite being legal.
+See http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns
+for all legal date patterns.
-This checker reports as warnings the following string patterns in a date format specifier:
+This checker reports as warnings the following string patterns in a date
+format specifier:
-#. yyyy + ww : Calendar year specified with week of a week year (unless YYYY is also specified).
-
- * | **Example 1:** Input Date: `29 December 2014` ; Format String: `yyyy-ww`;
+#. yyyy + ww : Calendar year specified with week of a week year
+ (unless YYYY is also specified).
+
+ * | **Example 1:** Input Date: `29 December 2014` ;
+ | Format String: `yyyy-ww`;
| Output string: `2014-01` (Wrong because it’s not the first week of 2014)
-
- * | **Example 2:** Input Date: `29 December 2014` ; Format String: `dd-MM-yyyy (ww-YYYY)`;
+
+ * | **Example 2:** Input Date: `29 December 2014` ;
+ | Format String: `dd-MM-yyyy (ww-YYYY)`;
| Output string: `29-12-2014 (01-2015)` (This is correct)
-
+
#. F without ee/EE : Numeric day of week in a month without actual day.
-
- * | **Example:** Input Date: `29 December 2014` ; Format String: `F-MM`;
- | Output string: `5-12` (Wrong because it reads as *5th ___ of Dec* in English)
-
+
+ * | **Example:** Input Date: `29 December 2014` ; Format String: `F-MM`;
+ | Output string: `5-12` (Wrong because it reads as *5th ___ of Dec* in
+ | English)
+
#. F without MM : Numeric day of week in a month without month.
-
+
* | **Example:** Input Date: `29 December 2014` ; Format String: `F-EE`
- | Output string: `5-Mon` (Wrong because it reads as *5th Mon of ___* in English)
-
+ | Output string: `5-Mon` (Wrong because it reads as *5th Mon of ___* in
+ | English)
+
#. WW without MM : Week of the month without the month.
-
+
* | **Example:** Input Date: `29 December 2014` ; Format String: `WW-yyyy`
- | Output string: `05-2014` (Wrong because it reads as *5th Week of ___* in English)
-
-#. YYYY + QQ : Week year specified with quarter of normal year (unless yyyy is also specified).
-
+ | Output string: `05-2014` (Wrong because it reads as *5th Week of ___* in
+ | English)
+
+#. YYYY + QQ : Week year specified with quarter of normal year
+ (unless yyyy is also specified).
+
* | **Example 1:** Input Date: `29 December 2014` ; Format String: `YYYY-QQ`
- | Output string: `2015-04` (Wrong because it’s not the 4th quarter of 2015)
-
- * | **Example 2:** Input Date: `29 December 2014` ; Format String: `ww-YYYY (QQ-yyyy)`
+ | Output string: `2015-04` (Wrong because it’s not the 4th quarter of
+ | 2015)
+
+ * | **Example 2:** Input Date: `29 December 2014` ;
+ | Format String: `ww-YYYY (QQ-yyyy)`
| Output string: `01-2015 (04-2014)` (This is correct)
-
-#. YYYY + MM : Week year specified with Month of a calendar year (unless yyyy is also specified).
-
+
+#. YYYY + MM : Week year specified with Month of a calendar year
+ (unless yyyy is also specified).
+
* | **Example 1:** Input Date: `29 December 2014` ; Format String: `YYYY-MM`
| Output string: `2015-12` (Wrong because it’s not the 12th month of 2015)
-
- * | **Example 2:** Input Date: `29 December 2014` ; Format String: `ww-YYYY (MM-yyyy)`
+
+ * | **Example 2:** Input Date: `29 December 2014` ;
+ | Format String: `ww-YYYY (MM-yyyy)`
| Output string: `01-2015 (12-2014)` (This is correct)
-
-#. YYYY + DD : Week year with day of a calendar year (unless yyyy is also specified).
-
+
+#. YYYY + DD : Week year with day of a calendar year
+ (unless yyyy is also specified).
+
* | **Example 1:** Input Date: `29 December 2014` ; Format String: `YYYY-DD`
| Output string: `2015-363` (Wrong because it’s not the 363rd day of 2015)
-
- * | **Example 2:** Input Date: `29 December 2014` ; Format String: `ww-YYYY (DD-yyyy)`
+
+ * | **Example 2:** Input Date: `29 December 2014` ;
+ | Format String: `ww-YYYY (DD-yyyy)`
| Output string: `01-2015 (363-2014)` (This is correct)
-
-#. YYYY + WW : Week year with week of a calendar year (unless yyyy is also specified).
-
+
+#. YYYY + WW : Week year with week of a calendar year
+ (unless yyyy is also specified).
+
* | **Example 1:** Input Date: `29 December 2014` ; Format String: `YYYY-WW`
| Output string: `2015-05` (Wrong because it’s not the 5th week of 2015)
-
- * | **Example 2:** Input Date: `29 December 2014` ; Format String: `ww-YYYY (WW-MM-yyyy)`
+
+ * | **Example 2:** Input Date: `29 December 2014` ;
+ | Format String: `ww-YYYY (WW-MM-yyyy)`
| Output string: `01-2015 (05-12-2014)` (This is correct)
-
-#. YYYY + F : Week year with day of week in a calendar month (unless yyyy is also specified).
-
- * | **Example 1:** Input Date: `29 December 2014` ; Format String: `YYYY-ww-F-EE`
- | Output string: `2015-01-5-Mon` (Wrong because it’s not the 5th Monday of January in 2015)
-
- * | **Example 2:** Input Date: `29 December 2014` ; Format String: `ww-YYYY (F-EE-MM-yyyy)`
+
+#. YYYY + F : Week year with day of week in a calendar month
+ (unless yyyy is also specified).
+
+ * | **Example 1:** Input Date: `29 December 2014` ;
+ | Format String: `YYYY-ww-F-EE`
+ | Output string: `2015-01-5-Mon` (Wrong because it’s not the 5th Monday of
+ | January in 2015)
+
+ * | **Example 2:** Input Date: `29 December 2014` ;
+ | Format String: `ww-YYYY (F-EE-MM-yyyy)`
| Output string: `01-2015 (5-Mon-12-2014)` (This is correct)
diff --git a/clang-tools-extra/docs/clang-tidy/checks/objc/property-declaration.rst b/clang-tools-extra/docs/clang-tidy/checks/objc/property-declaration.rst
index 60b9c82..53f9453 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/objc/property-declaration.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/objc/property-declaration.rst
@@ -23,8 +23,8 @@ The check will only fix 'CamelCase' to 'camelCase'. In some other cases we will
only provide warning messages since the property name could be complicated.
Users will need to come up with a proper name by their own.
-This check also accepts special acronyms as prefixes or suffixes. Such prefixes or suffixes
-will suppress the Lower Camel Case check according to the guide:
+This check also accepts special acronyms as prefixes or suffixes. Such prefixes
+or suffixes will suppress the Lower Camel Case check according to the guide:
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingBasics.html#//apple_ref/doc/uid/20001281-1002931-BBCFHEAB
For a full list of well-known acronyms:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/performance/no-int-to-ptr.rst b/clang-tools-extra/docs/clang-tidy/checks/performance/no-int-to-ptr.rst
index 8233ea1..dc69f20 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/performance/no-int-to-ptr.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/performance/no-int-to-ptr.rst
@@ -7,8 +7,8 @@ Diagnoses every integer to pointer cast.
While casting an (integral) pointer to an integer is obvious - you just get
the integral value of the pointer, casting an integer to an (integral) pointer
-is deceivingly different. While you will get a pointer with that integral value,
-if you got that integral value via a pointer-to-integer cast originally,
+is deceivingly different. While you will get a pointer with that integral
+value, if you got that integral value via a pointer-to-integer cast originally,
the new pointer will lack the provenance information from the original pointer.
So while (integral) pointer to integer casts are effectively no-ops,
diff --git a/clang-tools-extra/docs/clang-tidy/checks/performance/noexcept-swap.rst b/clang-tools-extra/docs/clang-tidy/checks/performance/noexcept-swap.rst
index 2901d72..e6d25d9 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/performance/noexcept-swap.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/performance/noexcept-swap.rst
@@ -3,11 +3,11 @@
performance-noexcept-swap
=========================
-The check flags user-defined swap and iter_swap functions not marked with ``noexcept`` or
-marked with ``noexcept(expr)`` where ``expr`` evaluates to ``false``
-(but is not a ``false`` literal itself).
+The check flags user-defined swap and iter_swap functions not marked with
+``noexcept`` or marked with ``noexcept(expr)`` where ``expr`` evaluates to
+``false`` (but is not a ``false`` literal itself).
-When a swap or iter_swap function is marked as ``noexcept``, it assures the compiler that
-no exceptions will be thrown during the swapping of two objects, which allows
-the compiler to perform certain optimizations such as omitting exception
-handling code.
+When a swap or iter_swap function is marked as ``noexcept``, it assures the
+compiler that no exceptions will be thrown during the swapping of two objects,
+which allows the compiler to perform certain optimizations such as omitting
+exception handling code.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-initialization.rst b/clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-initialization.rst
index 0e9d547..00581b1 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-initialization.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-initialization.rst
@@ -9,8 +9,8 @@ const reference.
The check is only applied if it is safe to replace the copy by a const
reference. This is the case when the variable is const qualified or when it is
-only used as a const, i.e. only const methods or operators are invoked on it, or
-it is used as const reference or value argument in constructors or function
+only used as a const, i.e. only const methods or operators are invoked on it,
+or it is used as const reference or value argument in constructors or function
calls.
Example:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/portability/simd-intrinsics.rst b/clang-tools-extra/docs/clang-tidy/checks/portability/simd-intrinsics.rst
index ab43c2f..7ba3a1d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/portability/simd-intrinsics.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/portability/simd-intrinsics.rst
@@ -19,18 +19,18 @@ objects.
Otherwise, it just complains the intrinsics are non-portable (and there are
`P0214`_ alternatives).
-Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
-ARM NEON). It is common that SIMD code implementing the same algorithm, is
-written in multiple target-dispatching pieces to optimize for different
-architectures or micro-architectures.
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power
+AltiVec/VSX, ARM NEON). It is common that SIMD code implementing the same
+algorithm, is written in multiple target-dispatching pieces to optimize for
+different architectures or micro-architectures.
The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
operations. By migrating from target-dependent intrinsics to `P0214`_
-operations, the SIMD code can be simplified and pieces for different targets can
-be unified.
+operations, the SIMD code can be simplified and pieces for different targets
+can be unified.
-Refer to `P0214`_ for introduction and motivation for the data-parallel standard
-library.
+Refer to `P0214`_ for introduction and motivation for the data-parallel
+standard library.
Options
-------
diff --git a/clang-tools-extra/docs/clang-tidy/checks/portability/std-allocator-const.rst b/clang-tools-extra/docs/clang-tidy/checks/portability/std-allocator-const.rst
index 31463c2..fdde552 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/portability/std-allocator-const.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/portability/std-allocator-const.rst
@@ -9,11 +9,11 @@ elements). These are not allowed in standard C++, and should usually be
Per C++ ``[allocator.requirements.general]``: "T is any cv-unqualified object
type", ``std::allocator<const T>`` is undefined. Many standard containers use
-``std::allocator`` by default and therefore their ``const T`` instantiations are
-undefined.
+``std::allocator`` by default and therefore their ``const T`` instantiations
+are undefined.
-libc++ defines ``std::allocator<const T>`` as an extension which will be removed
-in the future.
+libc++ defines ``std::allocator<const T>`` as an extension which will be
+removed in the future.
libstdc++ and MSVC do not support ``std::allocator<const T>``:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/portability/template-virtual-member-function.rst b/clang-tools-extra/docs/clang-tidy/checks/portability/template-virtual-member-function.rst
index aa3ed66..e21dedf 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/portability/template-virtual-member-function.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/portability/template-virtual-member-function.rst
@@ -3,23 +3,24 @@
portability-template-virtual-member-function
============================================
-Finds cases when an uninstantiated virtual member function in a template class causes
-cross-compiler incompatibility.
+Finds cases when an uninstantiated virtual member function in a template class
+causes cross-compiler incompatibility.
-Upon instantiating a template class, non-virtual member functions don't have to be
-instantiated unless they are used. Virtual member function instantiation on the other hand
-is unspecified and depends on the implementation of the compiler.
+Upon instantiating a template class, non-virtual member functions don't have
+to be instantiated unless they are used. Virtual member function instantiation
+on the other hand is unspecified and depends on the implementation of the
+compiler.
-In the following snippets the virtual member function is not instantiated by GCC and Clang,
-but it is instantiated by MSVC, so while the snippet is accepted by the former compilers,
-it is rejected by the latter.
+In the following snippets the virtual member function is not instantiated by
+GCC and Clang, but it is instantiated by MSVC, so while the snippet is accepted
+by the former compilers, it is rejected by the latter.
.. code:: c++
template<typename T>
struct CrossPlatformError {
virtual ~CrossPlatformError() = default;
-
+
static void used() {}
virtual void unused() {
@@ -32,6 +33,7 @@ it is rejected by the latter.
return 0;
}
-Cross-platform projects that need to support MSVC on Windows might see compiler errors
-because certain virtual member functions are instantiated, which are not instantiated
-by other compilers on other platforms. This check highlights such virtual member functions.
+Cross-platform projects that need to support MSVC on Windows might see compiler
+errors because certain virtual member functions are instantiated, which are not
+instantiated by other compilers on other platforms. This check highlights such
+virtual member functions.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/ambiguous-smartptr-reset-call.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/ambiguous-smartptr-reset-call.rst
index cf73839..f8df02d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/ambiguous-smartptr-reset-call.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/ambiguous-smartptr-reset-call.rst
@@ -40,14 +40,14 @@ other smart pointers or other classes use the :option:`SmartPointers` option.
.. note::
-
+
The check may emit invalid fix-its and misleading warning messages when
specifying custom smart pointers or other classes in the
:option:`SmartPointers` option. For example, ``boost::scoped_ptr`` does not
have an ``operator=`` which makes fix-its invalid.
.. note::
-
+
Automatic fix-its are enabled only if :program:`clang-tidy` is invoked with
the `--fix-notes` option.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst
index 9f5b263f..120d360 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst
@@ -30,5 +30,5 @@ Initial expression Result
This check will apply to any class that has a ``contains`` method, notably
including ``std::set``, ``std::unordered_set``, ``std::map``, and
-``std::unordered_map`` as of C++20, and ``std::string`` and ``std::string_view``
-as of C++23.
+``std::unordered_map`` as of C++20, and ``std::string`` and
+``std::string_view`` as of C++23.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/container-data-pointer.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/container-data-pointer.rst
index a4eff16..4b2ef6e 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/container-data-pointer.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/container-data-pointer.rst
@@ -6,11 +6,11 @@ readability-container-data-pointer
Finds cases where code could use ``data()`` rather than the address of the
element at index 0 in a container. This pattern is commonly used to materialize
a pointer to the backing data of a container. ``std::vector`` and
-``std::string`` provide a ``data()`` accessor to retrieve the data pointer which
-should be preferred.
+``std::string`` provide a ``data()`` accessor to retrieve the data pointer
+which should be preferred.
-This also ensures that in the case that the container is empty, the data pointer
-access does not perform an errant memory access.
+This also ensures that in the case that the container is empty, the data
+pointer access does not perform an errant memory access.
Options
-------
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst
index da6f770..cc012fd 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst
@@ -30,8 +30,8 @@ Options
.. option:: ExcludedComparisonTypes
- A semicolon-separated list of class names for which the check will ignore
- comparisons of objects with default-constructed objects of the same type.
- If a class is listed here, the check will not suggest using ``empty()``
- instead of such comparisons for objects of that class.
- Default value is: `::std::array`.
+ A semicolon-separated list of regular expressions matching class names for
+ which the check will ignore comparisons of objects with default-constructed
+ objects of the same type. If a class is listed here, the check will not
+ suggest using ``empty()`` instead of such comparisons for objects of that
+ class. Default value is: `::std::array`.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/convert-member-functions-to-static.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/convert-member-functions-to-static.rst
index 641cb83..59f4632 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/convert-member-functions-to-static.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/convert-member-functions-to-static.rst
@@ -10,5 +10,6 @@ After applying modifications as suggested by the check, running the check again
might find more opportunities to mark member functions ``static``.
After making a member function ``static``, you might want to run the check
-:doc:`readability-static-accessed-through-instance <../readability/static-accessed-through-instance>` to replace calls like
+:doc:`readability-static-accessed-through-instance
+<../readability/static-accessed-through-instance>` to replace calls like
``Instance.method()`` by ``Class::method()``.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/delete-null-pointer.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/delete-null-pointer.rst
index 21c91b4..0877915 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/delete-null-pointer.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/delete-null-pointer.rst
@@ -3,7 +3,8 @@
readability-delete-null-pointer
===============================
-Checks the ``if`` statements where a pointer's existence is checked and then deletes the pointer.
+Checks the ``if`` statements where a pointer's existence is checked and
+then deletes the pointer.
The check is unnecessary as deleting a null pointer has no effect.
.. code:: c++
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/duplicate-include.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/duplicate-include.rst
index 45df7e1..28a4991a 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/duplicate-include.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/duplicate-include.rst
@@ -33,3 +33,12 @@ Because of the intervening macro definitions, this code remains unchanged:
#define NDEBUG
#include "assertion.h"
// ...code with assertions disabled
+
+Options
+-------
+
+.. option:: IgnoredFilesList
+
+ A semicolon-separated list of regular expressions or filenames that are
+ allowed to be included multiple times without diagnostics. Matching is
+ performed against the textual include name. Default is an empty string.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/else-after-return.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/else-after-return.rst
index 25fb408..569fa24 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/else-after-return.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/else-after-return.rst
@@ -9,7 +9,8 @@ Early exit is one of the suggested enforcements of that. Please do not use
``else`` or ``else if`` after something that interrupts control flow - like
``return``, ``break``, ``continue``, ``throw``.
-The following piece of code illustrates how the check works. This piece of code:
+The following piece of code illustrates how the check works.
+This piece of code:
.. code-block:: c++
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/function-cognitive-complexity.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/function-cognitive-complexity.rst
index 3710917..430006e 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/function-cognitive-complexity.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/function-cognitive-complexity.rst
@@ -68,8 +68,8 @@ Nesting level
^^^^^^^^^^^^^
While by itself the nesting level does not change the function's Cognitive
-Complexity metric, it is tracked, and is used by the next, third building block.
-The following structures increase the nesting level (by `1`):
+Complexity metric, it is tracked, and is used by the next, third building
+block. The following structures increase the nesting level (by `1`):
* Conditional operators:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-length.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-length.rst
index 271970c2..c4d39a2 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-length.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-length.rst
@@ -16,7 +16,8 @@ The following options are described below:
- :option:`MinimumVariableNameLength`, :option:`IgnoredVariableNames`
- :option:`MinimumParameterNameLength`, :option:`IgnoredParameterNames`
- :option:`MinimumLoopCounterNameLength`, :option:`IgnoredLoopCounterNames`
- - :option:`MinimumExceptionNameLength`, :option:`IgnoredExceptionVariableNames`
+ - :option:`MinimumExceptionNameLength`,
+ :option:`IgnoredExceptionVariableNames`
.. option:: MinimumVariableNameLength
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst
index 6c4e0b7..2c0d69f 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst
@@ -31,12 +31,13 @@ The naming of virtual methods is reported where they occur in the base class,
but not where they are overridden, as it can't be fixed locally there.
This also applies for pseudo-override patterns like CRTP.
-``Leading_upper_snake_case`` is a naming convention where the first word is capitalized
-followed by lower case word(s) separated by underscore(s) '_'. Examples include:
-`Cap_snake_case`, `Cobra_case`, `Foo_bar_baz`, and `Master_copy_8gb`.
+``Leading_upper_snake_case`` is a naming convention where the first word is
+capitalized followed by lower case word(s) separated by underscore(s) '_'.
+Examples include: `Cap_snake_case`, `Cobra_case`, `Foo_bar_baz`,
+and `Master_copy_8gb`.
-Hungarian notation can be customized using different *HungarianPrefix* settings.
-The options and their corresponding values are:
+Hungarian notation can be customized using different *HungarianPrefix*
+settings. The options and their corresponding values are:
- ``Off`` - the default setting
- ``On`` - example: ``int iVariable``
@@ -57,62 +58,164 @@ The available options are summarized below:
**Specific options**
- - :option:`AbstractClassCase`, :option:`AbstractClassPrefix`, :option:`AbstractClassSuffix`, :option:`AbstractClassIgnoredRegexp`, :option:`AbstractClassHungarianPrefix`
- - :option:`ClassCase`, :option:`ClassPrefix`, :option:`ClassSuffix`, :option:`ClassIgnoredRegexp`, :option:`ClassHungarianPrefix`
- - :option:`ClassConstexprCase`, :option:`ClassConstexprPrefix`, :option:`ClassConstexprSuffix`, :option:`ClassConstexprIgnoredRegexp`, :option:`ClassConstexprHungarianPrefix`
- - :option:`ClassConstantCase`, :option:`ClassConstantPrefix`, :option:`ClassConstantSuffix`, :option:`ClassConstantIgnoredRegexp`, :option:`ClassConstantHungarianPrefix`
- - :option:`ClassMemberCase`, :option:`ClassMemberPrefix`, :option:`ClassMemberSuffix`, :option:`ClassMemberIgnoredRegexp`, :option:`ClassMemberHungarianPrefix`
- - :option:`ClassMethodCase`, :option:`ClassMethodPrefix`, :option:`ClassMethodSuffix`, :option:`ClassMethodIgnoredRegexp`
- - :option:`ConceptCase`, :option:`ConceptPrefix`, :option:`ConceptSuffix`, :option:`ConceptIgnoredRegexp`
- - :option:`ConstantCase`, :option:`ConstantPrefix`, :option:`ConstantSuffix`, :option:`ConstantIgnoredRegexp`, :option:`ConstantHungarianPrefix`
- - :option:`ConstantMemberCase`, :option:`ConstantMemberPrefix`, :option:`ConstantMemberSuffix`, :option:`ConstantMemberIgnoredRegexp`, :option:`ConstantMemberHungarianPrefix`
- - :option:`ConstantParameterCase`, :option:`ConstantParameterPrefix`, :option:`ConstantParameterSuffix`, :option:`ConstantParameterIgnoredRegexp`, :option:`ConstantParameterHungarianPrefix`
- - :option:`ConstantPointerParameterCase`, :option:`ConstantPointerParameterPrefix`, :option:`ConstantPointerParameterSuffix`, :option:`ConstantPointerParameterIgnoredRegexp`, :option:`ConstantPointerParameterHungarianPrefix`
- - :option:`ConstexprFunctionCase`, :option:`ConstexprFunctionPrefix`, :option:`ConstexprFunctionSuffix`, :option:`ConstexprFunctionIgnoredRegexp`
- - :option:`ConstexprMethodCase`, :option:`ConstexprMethodPrefix`, :option:`ConstexprMethodSuffix`, :option:`ConstexprMethodIgnoredRegexp`
- - :option:`ConstexprVariableCase`, :option:`ConstexprVariablePrefix`, :option:`ConstexprVariableSuffix`, :option:`ConstexprVariableIgnoredRegexp`, :option:`ConstexprVariableHungarianPrefix`
- - :option:`EnumCase`, :option:`EnumPrefix`, :option:`EnumSuffix`, :option:`EnumIgnoredRegexp`
- - :option:`EnumConstantCase`, :option:`EnumConstantPrefix`, :option:`EnumConstantSuffix`, :option:`EnumConstantIgnoredRegexp`, :option:`EnumConstantHungarianPrefix`
- - :option:`FunctionCase`, :option:`FunctionPrefix`, :option:`FunctionSuffix`, :option:`FunctionIgnoredRegexp`
- - :option:`GlobalConstexprVariableCase`, :option:`GlobalConstexprVariablePrefix`, :option:`GlobalConstexprVariableSuffix`, :option:`GlobalConstexprVariableIgnoredRegexp`, :option:`GlobalConstexprVariableHungarianPrefix`
- - :option:`GlobalConstantCase`, :option:`GlobalConstantPrefix`, :option:`GlobalConstantSuffix`, :option:`GlobalConstantIgnoredRegexp`, :option:`GlobalConstantHungarianPrefix`
- - :option:`GlobalConstantPointerCase`, :option:`GlobalConstantPointerPrefix`, :option:`GlobalConstantPointerSuffix`, :option:`GlobalConstantPointerIgnoredRegexp`, :option:`GlobalConstantPointerHungarianPrefix`
- - :option:`GlobalFunctionCase`, :option:`GlobalFunctionPrefix`, :option:`GlobalFunctionSuffix`, :option:`GlobalFunctionIgnoredRegexp`
- - :option:`GlobalPointerCase`, :option:`GlobalPointerPrefix`, :option:`GlobalPointerSuffix`, :option:`GlobalPointerIgnoredRegexp`, :option:`GlobalPointerHungarianPrefix`
- - :option:`GlobalVariableCase`, :option:`GlobalVariablePrefix`, :option:`GlobalVariableSuffix`, :option:`GlobalVariableIgnoredRegexp`, :option:`GlobalVariableHungarianPrefix`
- - :option:`InlineNamespaceCase`, :option:`InlineNamespacePrefix`, :option:`InlineNamespaceSuffix`, :option:`InlineNamespaceIgnoredRegexp`
- - :option:`LocalConstexprVariableCase`, :option:`LocalConstexprVariablePrefix`, :option:`LocalConstexprVariableSuffix`, :option:`LocalConstexprVariableIgnoredRegexp`, :option:`LocalConstexprVariableHungarianPrefix`
- - :option:`LocalConstantCase`, :option:`LocalConstantPrefix`, :option:`LocalConstantSuffix`, :option:`LocalConstantIgnoredRegexp`, :option:`LocalConstantHungarianPrefix`
- - :option:`LocalConstantPointerCase`, :option:`LocalConstantPointerPrefix`, :option:`LocalConstantPointerSuffix`, :option:`LocalConstantPointerIgnoredRegexp`, :option:`LocalConstantPointerHungarianPrefix`
- - :option:`LocalPointerCase`, :option:`LocalPointerPrefix`, :option:`LocalPointerSuffix`, :option:`LocalPointerIgnoredRegexp`, :option:`LocalPointerHungarianPrefix`
- - :option:`LocalVariableCase`, :option:`LocalVariablePrefix`, :option:`LocalVariableSuffix`, :option:`LocalVariableIgnoredRegexp`, :option:`LocalVariableHungarianPrefix`
- - :option:`MacroDefinitionCase`, :option:`MacroDefinitionPrefix`, :option:`MacroDefinitionSuffix`, :option:`MacroDefinitionIgnoredRegexp`
- - :option:`MemberCase`, :option:`MemberPrefix`, :option:`MemberSuffix`, :option:`MemberIgnoredRegexp`, :option:`MemberHungarianPrefix`
- - :option:`MethodCase`, :option:`MethodPrefix`, :option:`MethodSuffix`, :option:`MethodIgnoredRegexp`
- - :option:`NamespaceCase`, :option:`NamespacePrefix`, :option:`NamespaceSuffix`, :option:`NamespaceIgnoredRegexp`
- - :option:`ParameterCase`, :option:`ParameterPrefix`, :option:`ParameterSuffix`, :option:`ParameterIgnoredRegexp`, :option:`ParameterHungarianPrefix`
- - :option:`ParameterPackCase`, :option:`ParameterPackPrefix`, :option:`ParameterPackSuffix`, :option:`ParameterPackIgnoredRegexp`
- - :option:`PointerParameterCase`, :option:`PointerParameterPrefix`, :option:`PointerParameterSuffix`, :option:`PointerParameterIgnoredRegexp`, :option:`PointerParameterHungarianPrefix`
- - :option:`PrivateMemberCase`, :option:`PrivateMemberPrefix`, :option:`PrivateMemberSuffix`, :option:`PrivateMemberIgnoredRegexp`, :option:`PrivateMemberHungarianPrefix`
- - :option:`PrivateMethodCase`, :option:`PrivateMethodPrefix`, :option:`PrivateMethodSuffix`, :option:`PrivateMethodIgnoredRegexp`
- - :option:`ProtectedMemberCase`, :option:`ProtectedMemberPrefix`, :option:`ProtectedMemberSuffix`, :option:`ProtectedMemberIgnoredRegexp`, :option:`ProtectedMemberHungarianPrefix`
- - :option:`ProtectedMethodCase`, :option:`ProtectedMethodPrefix`, :option:`ProtectedMethodSuffix`, :option:`ProtectedMethodIgnoredRegexp`
- - :option:`PublicMemberCase`, :option:`PublicMemberPrefix`, :option:`PublicMemberSuffix`, :option:`PublicMemberIgnoredRegexp`, :option:`PublicMemberHungarianPrefix`
- - :option:`PublicMethodCase`, :option:`PublicMethodPrefix`, :option:`PublicMethodSuffix`, :option:`PublicMethodIgnoredRegexp`
- - :option:`ScopedEnumConstantCase`, :option:`ScopedEnumConstantPrefix`, :option:`ScopedEnumConstantSuffix`, :option:`ScopedEnumConstantIgnoredRegexp`
- - :option:`StaticConstexprVariableCase`, :option:`StaticConstexprVariablePrefix`, :option:`StaticConstexprVariableSuffix`, :option:`StaticConstexprVariableIgnoredRegexp`, :option:`StaticConstexprVariableHungarianPrefix`
- - :option:`StaticConstantCase`, :option:`StaticConstantPrefix`, :option:`StaticConstantSuffix`, :option:`StaticConstantIgnoredRegexp`, :option:`StaticConstantHungarianPrefix`
- - :option:`StaticVariableCase`, :option:`StaticVariablePrefix`, :option:`StaticVariableSuffix`, :option:`StaticVariableIgnoredRegexp`, :option:`StaticVariableHungarianPrefix`
- - :option:`StructCase`, :option:`StructPrefix`, :option:`StructSuffix`, :option:`StructIgnoredRegexp`
- - :option:`TemplateParameterCase`, :option:`TemplateParameterPrefix`, :option:`TemplateParameterSuffix`, :option:`TemplateParameterIgnoredRegexp`
- - :option:`TemplateTemplateParameterCase`, :option:`TemplateTemplateParameterPrefix`, :option:`TemplateTemplateParameterSuffix`, :option:`TemplateTemplateParameterIgnoredRegexp`
- - :option:`TypeAliasCase`, :option:`TypeAliasPrefix`, :option:`TypeAliasSuffix`, :option:`TypeAliasIgnoredRegexp`
- - :option:`TypedefCase`, :option:`TypedefPrefix`, :option:`TypedefSuffix`, :option:`TypedefIgnoredRegexp`
- - :option:`TypeTemplateParameterCase`, :option:`TypeTemplateParameterPrefix`, :option:`TypeTemplateParameterSuffix`, :option:`TypeTemplateParameterIgnoredRegexp`
- - :option:`UnionCase`, :option:`UnionPrefix`, :option:`UnionSuffix`, :option:`UnionIgnoredRegexp`
- - :option:`ValueTemplateParameterCase`, :option:`ValueTemplateParameterPrefix`, :option:`ValueTemplateParameterSuffix`, :option:`ValueTemplateParameterIgnoredRegexp`
- - :option:`VariableCase`, :option:`VariablePrefix`, :option:`VariableSuffix`, :option:`VariableIgnoredRegexp`, :option:`VariableHungarianPrefix`
- - :option:`VirtualMethodCase`, :option:`VirtualMethodPrefix`, :option:`VirtualMethodSuffix`, :option:`VirtualMethodIgnoredRegexp`
+ - :option:`AbstractClassCase`, :option:`AbstractClassPrefix`,
+ :option:`AbstractClassSuffix`, :option:`AbstractClassIgnoredRegexp`,
+ :option:`AbstractClassHungarianPrefix`
+ - :option:`ClassCase`, :option:`ClassPrefix`, :option:`ClassSuffix`,
+ :option:`ClassIgnoredRegexp`, :option:`ClassHungarianPrefix`
+ - :option:`ClassConstexprCase`, :option:`ClassConstexprPrefix`,
+ :option:`ClassConstexprSuffix`, :option:`ClassConstexprIgnoredRegexp`,
+ :option:`ClassConstexprHungarianPrefix`
+ - :option:`ClassConstantCase`, :option:`ClassConstantPrefix`,
+ :option:`ClassConstantSuffix`, :option:`ClassConstantIgnoredRegexp`,
+ :option:`ClassConstantHungarianPrefix`
+ - :option:`ClassMemberCase`, :option:`ClassMemberPrefix`,
+ :option:`ClassMemberSuffix`, :option:`ClassMemberIgnoredRegexp`,
+ :option:`ClassMemberHungarianPrefix`
+ - :option:`ClassMethodCase`, :option:`ClassMethodPrefix`,
+ :option:`ClassMethodSuffix`, :option:`ClassMethodIgnoredRegexp`
+ - :option:`ConceptCase`, :option:`ConceptPrefix`, :option:`ConceptSuffix`,
+ :option:`ConceptIgnoredRegexp`
+ - :option:`ConstantCase`, :option:`ConstantPrefix`, :option:`ConstantSuffix`,
+ :option:`ConstantIgnoredRegexp`, :option:`ConstantHungarianPrefix`
+ - :option:`ConstantMemberCase`, :option:`ConstantMemberPrefix`,
+ :option:`ConstantMemberSuffix`, :option:`ConstantMemberIgnoredRegexp`,
+ :option:`ConstantMemberHungarianPrefix`
+ - :option:`ConstantParameterCase`, :option:`ConstantParameterPrefix`,
+ :option:`ConstantParameterSuffix`, :option:`ConstantParameterIgnoredRegexp`,
+ :option:`ConstantParameterHungarianPrefix`
+ - :option:`ConstantPointerParameterCase`,
+ :option:`ConstantPointerParameterPrefix`,
+ :option:`ConstantPointerParameterSuffix`,
+ :option:`ConstantPointerParameterIgnoredRegexp`,
+ :option:`ConstantPointerParameterHungarianPrefix`
+ - :option:`ConstexprFunctionCase`, :option:`ConstexprFunctionPrefix`,
+ :option:`ConstexprFunctionSuffix`, :option:`ConstexprFunctionIgnoredRegexp`
+ - :option:`ConstexprMethodCase`, :option:`ConstexprMethodPrefix`,
+ :option:`ConstexprMethodSuffix`, :option:`ConstexprMethodIgnoredRegexp`
+ - :option:`ConstexprVariableCase`, :option:`ConstexprVariablePrefix`,
+ :option:`ConstexprVariableSuffix`, :option:`ConstexprVariableIgnoredRegexp`,
+ :option:`ConstexprVariableHungarianPrefix`
+ - :option:`EnumCase`, :option:`EnumPrefix`, :option:`EnumSuffix`,
+ :option:`EnumIgnoredRegexp`
+ - :option:`EnumConstantCase`, :option:`EnumConstantPrefix`,
+ :option:`EnumConstantSuffix`, :option:`EnumConstantIgnoredRegexp`,
+ :option:`EnumConstantHungarianPrefix`
+ - :option:`FunctionCase`, :option:`FunctionPrefix`, :option:`FunctionSuffix`,
+ :option:`FunctionIgnoredRegexp`
+ - :option:`GlobalConstexprVariableCase`,
+ :option:`GlobalConstexprVariablePrefix`,
+ :option:`GlobalConstexprVariableSuffix`,
+ :option:`GlobalConstexprVariableIgnoredRegexp`,
+ :option:`GlobalConstexprVariableHungarianPrefix`
+ - :option:`GlobalConstantCase`, :option:`GlobalConstantPrefix`,
+ :option:`GlobalConstantSuffix`, :option:`GlobalConstantIgnoredRegexp`,
+ :option:`GlobalConstantHungarianPrefix`
+ - :option:`GlobalConstantPointerCase`,
+ :option:`GlobalConstantPointerPrefix`,
+ :option:`GlobalConstantPointerSuffix`,
+ :option:`GlobalConstantPointerIgnoredRegexp`,
+ :option:`GlobalConstantPointerHungarianPrefix`
+ - :option:`GlobalFunctionCase`, :option:`GlobalFunctionPrefix`,
+ :option:`GlobalFunctionSuffix`, :option:`GlobalFunctionIgnoredRegexp`
+ - :option:`GlobalPointerCase`, :option:`GlobalPointerPrefix`,
+ :option:`GlobalPointerSuffix`, :option:`GlobalPointerIgnoredRegexp`,
+ :option:`GlobalPointerHungarianPrefix`
+ - :option:`GlobalVariableCase`, :option:`GlobalVariablePrefix`,
+ :option:`GlobalVariableSuffix`, :option:`GlobalVariableIgnoredRegexp`,
+ :option:`GlobalVariableHungarianPrefix`
+ - :option:`InlineNamespaceCase`, :option:`InlineNamespacePrefix`,
+ :option:`InlineNamespaceSuffix`, :option:`InlineNamespaceIgnoredRegexp`
+ - :option:`LocalConstexprVariableCase`,
+ :option:`LocalConstexprVariablePrefix`,
+ :option:`LocalConstexprVariableSuffix`,
+ :option:`LocalConstexprVariableIgnoredRegexp`,
+ :option:`LocalConstexprVariableHungarianPrefix`
+ - :option:`LocalConstantCase`, :option:`LocalConstantPrefix`,
+ :option:`LocalConstantSuffix`, :option:`LocalConstantIgnoredRegexp`,
+ :option:`LocalConstantHungarianPrefix`
+ - :option:`LocalConstantPointerCase`,
+ :option:`LocalConstantPointerPrefix`,
+ :option:`LocalConstantPointerSuffix`,
+ :option:`LocalConstantPointerIgnoredRegexp`,
+ :option:`LocalConstantPointerHungarianPrefix`
+ - :option:`LocalPointerCase`, :option:`LocalPointerPrefix`,
+ :option:`LocalPointerSuffix`, :option:`LocalPointerIgnoredRegexp`,
+ :option:`LocalPointerHungarianPrefix`
+ - :option:`LocalVariableCase`, :option:`LocalVariablePrefix`,
+ :option:`LocalVariableSuffix`, :option:`LocalVariableIgnoredRegexp`,
+ :option:`LocalVariableHungarianPrefix`
+ - :option:`MacroDefinitionCase`, :option:`MacroDefinitionPrefix`,
+ :option:`MacroDefinitionSuffix`, :option:`MacroDefinitionIgnoredRegexp`
+ - :option:`MemberCase`, :option:`MemberPrefix`, :option:`MemberSuffix`,
+ :option:`MemberIgnoredRegexp`, :option:`MemberHungarianPrefix`
+ - :option:`MethodCase`, :option:`MethodPrefix`, :option:`MethodSuffix`,
+ :option:`MethodIgnoredRegexp`
+ - :option:`NamespaceCase`, :option:`NamespacePrefix`,
+ :option:`NamespaceSuffix`, :option:`NamespaceIgnoredRegexp`
+ - :option:`ParameterCase`, :option:`ParameterPrefix`,
+ :option:`ParameterSuffix`, :option:`ParameterIgnoredRegexp`,
+ :option:`ParameterHungarianPrefix`
+ - :option:`ParameterPackCase`, :option:`ParameterPackPrefix`,
+ :option:`ParameterPackSuffix`, :option:`ParameterPackIgnoredRegexp`
+ - :option:`PointerParameterCase`, :option:`PointerParameterPrefix`,
+ :option:`PointerParameterSuffix`, :option:`PointerParameterIgnoredRegexp`,
+ :option:`PointerParameterHungarianPrefix`
+ - :option:`PrivateMemberCase`, :option:`PrivateMemberPrefix`,
+ :option:`PrivateMemberSuffix`, :option:`PrivateMemberIgnoredRegexp`,
+ :option:`PrivateMemberHungarianPrefix`
+ - :option:`PrivateMethodCase`, :option:`PrivateMethodPrefix`,
+ :option:`PrivateMethodSuffix`, :option:`PrivateMethodIgnoredRegexp`
+ - :option:`ProtectedMemberCase`, :option:`ProtectedMemberPrefix`,
+ :option:`ProtectedMemberSuffix`, :option:`ProtectedMemberIgnoredRegexp`,
+ :option:`ProtectedMemberHungarianPrefix`
+ - :option:`ProtectedMethodCase`, :option:`ProtectedMethodPrefix`,
+ :option:`ProtectedMethodSuffix`, :option:`ProtectedMethodIgnoredRegexp`
+ - :option:`PublicMemberCase`, :option:`PublicMemberPrefix`,
+ :option:`PublicMemberSuffix`, :option:`PublicMemberIgnoredRegexp`,
+ :option:`PublicMemberHungarianPrefix`
+ - :option:`PublicMethodCase`, :option:`PublicMethodPrefix`,
+ :option:`PublicMethodSuffix`, :option:`PublicMethodIgnoredRegexp`
+ - :option:`ScopedEnumConstantCase`, :option:`ScopedEnumConstantPrefix`,
+ :option:`ScopedEnumConstantSuffix`,
+ :option:`ScopedEnumConstantIgnoredRegexp`
+ - :option:`StaticConstexprVariableCase`,
+ :option:`StaticConstexprVariablePrefix`,
+ :option:`StaticConstexprVariableSuffix`,
+ :option:`StaticConstexprVariableIgnoredRegexp`,
+ :option:`StaticConstexprVariableHungarianPrefix`
+ - :option:`StaticConstantCase`, :option:`StaticConstantPrefix`,
+ :option:`StaticConstantSuffix`, :option:`StaticConstantIgnoredRegexp`,
+ :option:`StaticConstantHungarianPrefix`
+ - :option:`StaticVariableCase`, :option:`StaticVariablePrefix`,
+ :option:`StaticVariableSuffix`, :option:`StaticVariableIgnoredRegexp`,
+ :option:`StaticVariableHungarianPrefix`
+ - :option:`StructCase`, :option:`StructPrefix`, :option:`StructSuffix`,
+ :option:`StructIgnoredRegexp`
+ - :option:`TemplateParameterCase`, :option:`TemplateParameterPrefix`,
+ :option:`TemplateParameterSuffix`, :option:`TemplateParameterIgnoredRegexp`
+ - :option:`TemplateTemplateParameterCase`,
+ :option:`TemplateTemplateParameterPrefix`,
+ :option:`TemplateTemplateParameterSuffix`,
+ :option:`TemplateTemplateParameterIgnoredRegexp`
+ - :option:`TypeAliasCase`, :option:`TypeAliasPrefix`,
+ :option:`TypeAliasSuffix`, :option:`TypeAliasIgnoredRegexp`
+ - :option:`TypedefCase`, :option:`TypedefPrefix`, :option:`TypedefSuffix`,
+ :option:`TypedefIgnoredRegexp`
+ - :option:`TypeTemplateParameterCase`,
+ :option:`TypeTemplateParameterPrefix`,
+ :option:`TypeTemplateParameterSuffix`,
+ :option:`TypeTemplateParameterIgnoredRegexp`
+ - :option:`UnionCase`, :option:`UnionPrefix`, :option:`UnionSuffix`,
+ :option:`UnionIgnoredRegexp`
+ - :option:`ValueTemplateParameterCase`,
+ :option:`ValueTemplateParameterPrefix`,
+ :option:`ValueTemplateParameterSuffix`,
+ :option:`ValueTemplateParameterIgnoredRegexp`
+ - :option:`VariableCase`, :option:`VariablePrefix`, :option:`VariableSuffix`,
+ :option:`VariableIgnoredRegexp`, :option:`VariableHungarianPrefix`
+ - :option:`VirtualMethodCase`, :option:`VirtualMethodPrefix`,
+ :option:`VirtualMethodSuffix`, :option:`VirtualMethodIgnoredRegexp`
Options description
@@ -1608,8 +1711,8 @@ After:
#define pre_my_macro_definition_post
-Note: This will not warn on builtin macros or macros defined on the command line
-using the ``-D`` flag.
+Note: This will not warn on builtin macros or macros defined on the
+command line using the ``-D`` flag.
.. option:: MemberCase
@@ -2804,44 +2907,45 @@ distinguished as the given name. The first character of the given name can be
capitalized to separate it from the type indicators (see also CamelCase).
Otherwise the case of this character denotes scope.
-The following table is the default mapping table of Hungarian Notation which
-maps Decl to its prefix string. You can also have your own style in config file.
-
-================= ============== ====================== ============== ============== ==============
-Primitive Type Microsoft Type
------------------ -------------- ---------------------- -------------- -------------- --------------
- Type Prefix Type Prefix Type Prefix
-================= ============== ====================== ============== ============== ==============
-int8_t i8 signed int si BOOL b
-int16_t i16 signed short ss BOOLEAN b
-int32_t i32 signed short int ssi BYTE by
-int64_t i64 signed long long int slli CHAR c
-uint8_t u8 signed long long sll UCHAR uc
-uint16_t u16 signed long int sli SHORT s
-uint32_t u32 signed long sl USHORT us
-uint64_t u64 signed s WORD w
-char8_t c8 unsigned long long int ulli DWORD dw
-char16_t c16 unsigned long long ull DWORD32 dw32
-char32_t c32 unsigned long int uli DWORD64 dw64
-float f unsigned long ul LONG l
-double d unsigned short int usi ULONG ul
-char c unsigned short us ULONG32 ul32
-bool b unsigned int ui ULONG64 ul64
-_Bool b unsigned char uc ULONGLONG ull
-int i unsigned u HANDLE h
-size_t n long long int lli INT i
-short s long double ld INT8 i8
-signed i long long ll INT16 i16
-unsigned u long int li INT32 i32
-long l long l INT64 i64
-long long ll ptrdiff_t p UINT ui
-unsigned long ul void *none* UINT8 u8
-long double ld UINT16 u16
-ptrdiff_t p UINT32 u32
-wchar_t wc UINT64 u64
-short int si PVOID p
-short s
-================= ============== ====================== ============== ============== ==============
+The following table is the default mapping table of Hungarian Notation
+which maps Decl to its prefix string. You can also have your own style
+in config file.
+
+============== ======== ====================== ======== ============== ========
+Primitive Type Microsoft Type
+-------------- -------- ---------------------- -------- -------------- --------
+ Type Prefix Type Prefix Type Prefix
+============== ======== ====================== ======== ============== ========
+int8_t i8 signed int si BOOL b
+int16_t i16 signed short ss BOOLEAN b
+int32_t i32 signed short int ssi BYTE by
+int64_t i64 signed long long int slli CHAR c
+uint8_t u8 signed long long sll UCHAR uc
+uint16_t u16 signed long int sli SHORT s
+uint32_t u32 signed long sl USHORT us
+uint64_t u64 signed s WORD w
+char8_t c8 unsigned long long int ulli DWORD dw
+char16_t c16 unsigned long long ull DWORD32 dw32
+char32_t c32 unsigned long int uli DWORD64 dw64
+float f unsigned long ul LONG l
+double d unsigned short int usi ULONG ul
+char c unsigned short us ULONG32 ul32
+bool b unsigned int ui ULONG64 ul64
+_Bool b unsigned char uc ULONGLONG ull
+int i unsigned u HANDLE h
+size_t n long long int lli INT i
+short s long double ld INT8 i8
+signed i long long ll INT16 i16
+unsigned u long int li INT32 i32
+long l long l INT64 i64
+long long ll ptrdiff_t p UINT ui
+unsigned long ul void *none* UINT8 u8
+long double ld UINT16 u16
+ptrdiff_t p UINT32 u32
+wchar_t wc UINT64 u64
+short int si PVOID p
+short s
+============== ======== ====================== ======== ============== ========
**There are more trivial options for Hungarian Notation:**
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/implicit-bool-conversion.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/implicit-bool-conversion.rst
index 88cff38..3a37b25 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/implicit-bool-conversion.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/implicit-bool-conversion.rst
@@ -4,9 +4,9 @@ readability-implicit-bool-conversion
====================================
This check can be used to find implicit conversions between built-in types and
-booleans. Depending on use case, it may simply help with readability of the code,
-or in some cases, point to potential bugs which remain unnoticed due to implicit
-conversions.
+booleans. Depending on use case, it may simply help with readability of the
+code, or in some cases, point to potential bugs which remain unnoticed due to
+implicit conversions.
The following is a real-world example of bug which was hiding behind implicit
``bool`` conversion:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/magic-numbers.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/magic-numbers.rst
index 0b2d819..55d47d5 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/magic-numbers.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/magic-numbers.rst
@@ -9,7 +9,7 @@ code and not introduced via constants or symbols.
Many coding guidelines advise replacing the magic values with symbolic
constants to improve readability. Here are a few references:
- * `Rule ES.45: Avoid "magic constants"; use symbolic constants in C++ Core Guidelines <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-magic>`_
+ * `Rule ES.45: Avoid "magic constants"; use symbolic constants in C++ Core Guidelines <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#res-magic>`_
* `Rule 5.1.1 Use symbolic names instead of literal values in code in High Integrity C++ <https://www.perforce.com/resources/qac/high-integrity-cpp-coding-standard-expressions>`_
* Item 17 in "C++ Coding Standards: 101 Rules, Guidelines and Best
Practices" by Herb Sutter and Andrei Alexandrescu
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/make-member-function-const.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/make-member-function-const.rst
index 5d1f8d1..73059e2 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/make-member-function-const.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/make-member-function-const.rst
@@ -37,7 +37,8 @@ In addition, this check ignores functions that
* are templated or part of a class template
* have an empty body
* do not (implicitly) use ``this`` at all
- (see :doc:`readability-convert-member-functions-to-static <../readability/convert-member-functions-to-static>`).
+ (see :doc:`readability-convert-member-functions-to-static
+ <../readability/convert-member-functions-to-static>`).
The following real-world examples will be preserved by the check:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/math-missing-parentheses.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/math-missing-parentheses.rst
index 21d66da..9bc98d5 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/math-missing-parentheses.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/math-missing-parentheses.rst
@@ -3,15 +3,16 @@
readability-math-missing-parentheses
====================================
-Check for missing parentheses in mathematical expressions that involve operators
-of different priorities.
+Check for missing parentheses in mathematical expressions that involve
+operators of different priorities.
Parentheses in mathematical expressions clarify the order
-of operations, especially with different-priority operators. Lengthy or multiline
-expressions can obscure this order, leading to coding errors. IDEs can aid clarity
-by highlighting parentheses. Explicitly using parentheses also clarifies what the
-developer had in mind when writing the expression. Ensuring their presence reduces
-ambiguity and errors, promoting clearer and more maintainable code.
+of operations, especially with different-priority operators. Lengthy or
+multiline expressions can obscure this order, leading to coding errors.
+IDEs can aid clarity by highlighting parentheses. Explicitly using parentheses
+also clarifies what the developer had in mind when writing the expression.
+Ensuring their presence reduces ambiguity and errors, promoting clearer and
+more maintainable code.
Before:
@@ -24,4 +25,4 @@ After:
.. code-block:: c++
- int x = 1 + (2 * 3) - (4 / 5); \ No newline at end of file
+ int x = 1 + (2 * 3) - (4 / 5);
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst
index 48b7e84..0dd25e2 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst
@@ -10,8 +10,9 @@ Guide:
https://google.github.io/styleguide/cppguide.html#Function_Declarations_and_Definitions
-All parameters should have the same name in both the function declaration and definition.
-If a parameter is not utilized, its name can be commented out in a function definition.
+All parameters should have the same name in both the function declaration and
+definition. If a parameter is not utilized, its name can be commented out in a
+function definition.
.. code-block:: c++
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/operators-representation.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/operators-representation.rst
index b84f7a1..70cf75b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/operators-representation.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/operators-representation.rst
@@ -69,9 +69,10 @@ To configure check to enforce Alternative Token Representation for all
operators set options to
`and;and_eq;bitand;bitor;compl;not;not_eq;or;or_eq;xor;xor_eq`.
-Developers do not need to enforce all operators, and can mix the representations
-as desired by specifying a semicolon-separated list of both traditional and
-alternative tokens in the configuration, such as `and;||;not`.
+Developers do not need to enforce all operators, and can mix the
+representations as desired by specifying a semicolon-separated list of
+both traditional and alternative tokens in the configuration,
+such as `and;||;not`.
.. option:: BinaryOperators
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-casting.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-casting.rst
index 23eaa22..4b6c14b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-casting.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-casting.rst
@@ -18,9 +18,9 @@ In this example, the ``static_cast<int>(value)`` is redundant, as it performs
a cast from an ``int`` to another ``int``.
Casting operations involving constructor conversions, user-defined conversions,
-functional casts, type-dependent casts, casts between distinct type aliases that
-refer to the same underlying type, as well as bitfield-related casts and casts
-directly from lvalue to rvalue, are all disregarded by the check.
+functional casts, type-dependent casts, casts between distinct type aliases
+that refer to the same underlying type, as well as bitfield-related casts and
+casts directly from lvalue to rvalue, are all disregarded by the check.
Options
-------
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-control-flow.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-control-flow.rst
index aeaf345..ac435af 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-control-flow.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-control-flow.rst
@@ -4,7 +4,8 @@ readability-redundant-control-flow
==================================
This check looks for procedures (functions returning no value) with ``return``
-statements at the end of the function. Such ``return`` statements are redundant.
+statements at the end of the function. Such ``return`` statements are
+redundant.
Loop statements (``for``, ``while``, ``do while``) are checked for redundant
``continue`` statements at the end of the loop body.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-inline-specifier.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-inline-specifier.rst
index c33c05b..5ae80d5 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-inline-specifier.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-inline-specifier.rst
@@ -15,7 +15,7 @@ In the example above the keyword ``inline`` is redundant since constexpr
functions are implicitly inlined
.. code-block:: c++
-
+
class MyClass {
inline void myMethod() {}
};
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-parentheses.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-parentheses.rst
index 20e3891..b9c50c5 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-parentheses.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-parentheses.rst
@@ -36,7 +36,7 @@ Options
Semicolon-separated list of regular expressions matching names of declarations
to ignore when the parentheses are around. Declarations can include variables
or functions. The default is an `std::max;std::min`.
-
+
Some STL library functions may have the same name as widely used function-like
macro. For example, ``std::max`` and ``max`` macro. A workaround to distinguish
them is adding parentheses around functions to prevent function-like macro.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-string-cstr.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-string-cstr.rst
index 2789f9c..84495a5 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-string-cstr.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-string-cstr.rst
@@ -4,17 +4,18 @@ readability-redundant-string-cstr
=================================
-Finds unnecessary calls to ``std::string::c_str()`` and ``std::string::data()``.
+Finds unnecessary calls to ``std::string::c_str()`` and
+``std::string::data()``.
Options
-------
.. option:: StringParameterFunctions
- A semicolon-separated list of (fully qualified) function/method/operator
- names, with the requirement that any parameter currently accepting a
- ``const char*`` input should also be able to accept ``std::string``
- inputs, or proper overload candidates that can do so should exist. This
- can be used to configure functions such as ``fmt::format``,
- ``spdlog::logger::info``, or wrappers around these and similar
- functions. The default value is the empty string.
+ A semicolon-separated list of regular expressions matching the
+ (fully qualified) names of function/method/operator, with the requirement
+ that any parameter currently accepting a ``const char*`` input should also
+ be able to accept ``std::string`` inputs, or proper overload candidates that
+ can do so should exist. This can be used to configure functions such as
+ ``fmt::format``, ``spdlog::logger::info``, or wrappers around these and
+ similar functions. The default value is the empty string.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/reference-to-constructed-temporary.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/reference-to-constructed-temporary.rst
index 09fd0c7..5f1aea1 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/reference-to-constructed-temporary.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/reference-to-constructed-temporary.rst
@@ -23,10 +23,10 @@ Examples of problematic code include:
In the first example, a ``const std::string&`` reference variable ``str`` is
assigned a temporary object created by the ``std::string("hello")``
constructor. In the second example, a ``const Point&`` reference variable ``p``
-is assigned an object that is constructed from an initializer list ``{ 1, 2 }``.
-Both of these examples extend the lifetime of the temporary object to the
-lifetime of the reference variable, which can make it difficult to reason about
-and may lead to subtle bugs or misunderstanding.
+is assigned an object that is constructed from an initializer list
+``{ 1, 2 }``. Both of these examples extend the lifetime of the temporary
+object to the lifetime of the reference variable, which can make it difficult
+to reason about and may lead to subtle bugs or misunderstanding.
To avoid these issues, it is recommended to change the reference variable to a
(``const``) value variable.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/simplify-boolean-expr.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/simplify-boolean-expr.rst
index 3d00d5b..5b733e5 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/simplify-boolean-expr.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/simplify-boolean-expr.rst
@@ -75,8 +75,9 @@ Examples:
an implicit conversion of an integer quantity ``i & 1`` to ``bool`` and
becomes ``return (i & 1) != 0;``
- 6. Given ``struct X { explicit operator bool(); };``, and an instance ``x`` of
- ``struct X``, the conditional return ``if (x) return true; return false;``
+ 6. Given ``struct X { explicit operator bool(); };``, and an instance ``x``
+ of ``struct X``, the conditional return
+ ``if (x) return true; return false;``
becomes ``return static_cast<bool>(x);``
Options
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/string-compare.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/string-compare.rst
index 4be2473..db9bec2 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/string-compare.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/string-compare.rst
@@ -8,11 +8,11 @@ Finds string comparisons using the compare method.
A common mistake is to use the string's ``compare`` method instead of using the
equality or inequality operators. The compare method is intended for sorting
functions and thus returns a negative number, a positive number or
-zero depending on the lexicographical relationship between the strings compared.
-If an equality or inequality check can suffice, that is recommended. This is
-recommended to avoid the risk of incorrect interpretation of the return value
-and to simplify the code. The string equality and inequality operators can
-also be faster than the ``compare`` method due to early termination.
+zero depending on the lexicographical relationship between the strings
+compared. If an equality or inequality check can suffice, that is recommended.
+This is recommended to avoid the risk of incorrect interpretation of the return
+value and to simplify the code. The string equality and inequality operators
+can also be faster than the ``compare`` method due to early termination.
Example
-------
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/suspicious-call-argument.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/suspicious-call-argument.rst
index 03d9bba..2b3a265 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/suspicious-call-argument.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/suspicious-call-argument.rst
@@ -235,8 +235,8 @@ Parameter names are the identifiers as written in the source code.
Argument names are:
* If a variable is passed, the variable's name.
- * If a subsequent function call's return value is used as argument, the called
- function's name.
+ * If a subsequent function call's return value is used as argument, the
+ called function's name.
* Otherwise, empty string.
Empty argument or parameter names are ignored by the heuristics.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/uppercase-literal-suffix.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/uppercase-literal-suffix.rst
index f2809db..dcedfb1 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/uppercase-literal-suffix.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/uppercase-literal-suffix.rst
@@ -10,8 +10,8 @@ By default, only the suffixes that begin with ``l`` (``l``, ``ll``, ``lu``,
`hicpp-uppercase-literal-suffix` redirects here as an alias for this check.
Detects when the integral literal or floating point (decimal or hexadecimal)
-literal has a non-uppercase suffix and provides a fix-it hint with the uppercase
-suffix.
+literal has a non-uppercase suffix and provides a fix-it hint with the
+uppercase suffix.
All valid combinations of suffixes are supported.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/use-anyofallof.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/use-anyofallof.rst
index 6e58766..cfbc551 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/use-anyofallof.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/use-anyofallof.rst
@@ -3,9 +3,9 @@
readability-use-anyofallof
==========================
-Finds range-based for loops that can be replaced by a call to ``std::any_of`` or
-``std::all_of``. In C++20 mode, suggests ``std::ranges::any_of`` or
-``std::ranges::all_of``.
+Finds range-based for loops that can be replaced by a call to
+``std::any_of`` or ``std::all_of``. In C++20 mode, suggests
+``std::ranges::any_of`` or ``std::ranges::all_of``.
Example:
diff --git a/clang-tools-extra/docs/index.rst b/clang-tools-extra/docs/index.rst
index 3f3a99d..eba4a2c 100644
--- a/clang-tools-extra/docs/index.rst
+++ b/clang-tools-extra/docs/index.rst
@@ -22,6 +22,7 @@ Contents
pp-trace
clangd <https://clangd.llvm.org/>
clang-doc
+ Maintainers
Doxygen Documentation
diff --git a/clang-tools-extra/include-cleaner/test/lit.cfg.py b/clang-tools-extra/include-cleaner/test/lit.cfg.py
index fc67250..52f81bf 100644
--- a/clang-tools-extra/include-cleaner/test/lit.cfg.py
+++ b/clang-tools-extra/include-cleaner/test/lit.cfg.py
@@ -1,12 +1,25 @@
+import os
+
import lit.llvm
lit.llvm.initialize(lit_config, config)
lit.llvm.llvm_config.use_default_substitutions()
+# TODO: Consolidate the logic for turning on the internal shell by default for all LLVM test suites.
+# See https://github.com/llvm/llvm-project/issues/106636 for more details.
+#
+# We prefer the lit internal shell which provides a better user experience on failures
+# and is faster unless the user explicitly disables it with LIT_USE_INTERNAL_SHELL=0
+# env var.
+use_lit_shell = True
+lit_shell_env = os.environ.get("LIT_USE_INTERNAL_SHELL")
+if lit_shell_env:
+ use_lit_shell = lit.util.pythonize_bool(lit_shell_env)
+
config.name = "ClangIncludeCleaner"
config.suffixes = [".test", ".c", ".cpp"]
config.excludes = ["Inputs"]
-config.test_format = lit.formats.ShTest(not lit.llvm.llvm_config.use_lit_shell)
+config.test_format = lit.formats.ShTest(not use_lit_shell)
config.test_source_root = config.clang_include_cleaner_source_dir + "/test"
config.test_exec_root = config.clang_include_cleaner_binary_dir + "/test"
diff --git a/clang-tools-extra/modularize/CMakeLists.txt b/clang-tools-extra/modularize/CMakeLists.txt
index eb5383c..a775b79 100644
--- a/clang-tools-extra/modularize/CMakeLists.txt
+++ b/clang-tools-extra/modularize/CMakeLists.txt
@@ -20,6 +20,7 @@ clang_target_link_libraries(modularize
clangAST
clangBasic
clangDriver
+ clangOptions
clangFrontend
clangLex
clangSerialization
diff --git a/clang-tools-extra/modularize/CoverageChecker.cpp b/clang-tools-extra/modularize/CoverageChecker.cpp
index 1345a6e..d80d78c 100644
--- a/clang-tools-extra/modularize/CoverageChecker.cpp
+++ b/clang-tools-extra/modularize/CoverageChecker.cpp
@@ -50,18 +50,18 @@
//
//===----------------------------------------------------------------------===//
+#include "CoverageChecker.h"
#include "ModularizeUtilities.h"
#include "clang/AST/ASTConsumer.h"
-#include "CoverageChecker.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Basic/SourceManager.h"
-#include "clang/Driver/Options.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendAction.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Lex/PPCallbacks.h"
#include "clang/Lex/Preprocessor.h"
+#include "clang/Options/Options.h"
#include "clang/Tooling/CompilationDatabase.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/Option/Option.h"
@@ -73,7 +73,7 @@
using namespace Modularize;
using namespace clang;
using namespace clang::driver;
-using namespace clang::driver::options;
+using namespace clang::options;
using namespace clang::tooling;
namespace cl = llvm::cl;
namespace sys = llvm::sys;
diff --git a/clang-tools-extra/modularize/Modularize.cpp b/clang-tools-extra/modularize/Modularize.cpp
index 376ad0c..33966b4 100644
--- a/clang-tools-extra/modularize/Modularize.cpp
+++ b/clang-tools-extra/modularize/Modularize.cpp
@@ -231,11 +231,11 @@
#include "clang/AST/ASTContext.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Basic/SourceManager.h"
-#include "clang/Driver/Options.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendAction.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Lex/Preprocessor.h"
+#include "clang/Options/Options.h"
#include "clang/Tooling/CompilationDatabase.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/Option/Arg.h"
@@ -254,7 +254,7 @@
using namespace clang;
using namespace clang::driver;
-using namespace clang::driver::options;
+using namespace clang::options;
using namespace clang::tooling;
using namespace llvm;
using namespace llvm::opt;
diff --git a/clang-tools-extra/modularize/ModularizeUtilities.cpp b/clang-tools-extra/modularize/ModularizeUtilities.cpp
index 4dd84fe..6978a6b 100644
--- a/clang-tools-extra/modularize/ModularizeUtilities.cpp
+++ b/clang-tools-extra/modularize/ModularizeUtilities.cpp
@@ -12,17 +12,17 @@
//
//===----------------------------------------------------------------------===//
+#include "ModularizeUtilities.h"
+#include "CoverageChecker.h"
#include "clang/Basic/SourceManager.h"
-#include "clang/Driver/Options.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendActions.h"
-#include "CoverageChecker.h"
+#include "clang/Options/Options.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
-#include "ModularizeUtilities.h"
using namespace clang;
using namespace llvm;
diff --git a/clang-tools-extra/pp-trace/CMakeLists.txt b/clang-tools-extra/pp-trace/CMakeLists.txt
index 1323adb..da36582 100644
--- a/clang-tools-extra/pp-trace/CMakeLists.txt
+++ b/clang-tools-extra/pp-trace/CMakeLists.txt
@@ -14,6 +14,7 @@ clang_target_link_libraries(pp-trace
PRIVATE
clangAST
clangBasic
+ clangOptions
clangFrontend
clangLex
clangSerialization
diff --git a/clang-tools-extra/pp-trace/PPTrace.cpp b/clang-tools-extra/pp-trace/PPTrace.cpp
index 0b078c4..ba5a06a 100644
--- a/clang-tools-extra/pp-trace/PPTrace.cpp
+++ b/clang-tools-extra/pp-trace/PPTrace.cpp
@@ -28,11 +28,11 @@
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/Basic/SourceManager.h"
-#include "clang/Driver/Options.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendAction.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Lex/Preprocessor.h"
+#include "clang/Options/Options.h"
#include "clang/Tooling/Execution.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/Option/Arg.h"
diff --git a/clang-tools-extra/test/clang-doc/assets.cpp b/clang-tools-extra/test/clang-doc/assets.cpp
index c5933e5..853dfe5 100644
--- a/clang-tools-extra/test/clang-doc/assets.cpp
+++ b/clang-tools-extra/test/clang-doc/assets.cpp
@@ -1,19 +1,7 @@
// RUN: rm -rf %t && mkdir %t
// RUN: clang-doc --format=html --output=%t --asset=%S/Inputs/test-assets --executor=standalone %s --base base_dir
-// RUN: FileCheck %s -input-file=%t/index.html -check-prefix=INDEX
-// RUN: FileCheck %s -input-file=%t/test.css -check-prefix=CSS
-// RUN: FileCheck %s -input-file=%t/test.js -check-prefix=JS
-
-// INDEX: <!DOCTYPE html>
-// INDEX-NEXT: <meta charset="utf-8"/>
-// INDEX-NEXT: <title>Index</title>
-// INDEX-NEXT: <link rel="stylesheet" href="test.css"/>
-// INDEX-NEXT: <script src="index_json.js"></script>
-// INDEX-NEXT: <script src="test.js"></script>
-// INDEX-NEXT: <header id="project-title"></header>
-// INDEX-NEXT: <main>
-// INDEX-NEXT: <div id="sidebar-left" path="" class="col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas-left" style="flex: 0 100%;"></div>
-// INDEX-NEXT: </main>
+// RUN: FileCheck %s -input-file=%t/html/test.css -check-prefix=CSS
+// RUN: FileCheck %s -input-file=%t/html/test.js -check-prefix=JS
// CSS: body {
// CSS-NEXT: padding: 0;
diff --git a/clang-tools-extra/test/clang-doc/basic-project.mustache.test b/clang-tools-extra/test/clang-doc/basic-project.mustache.test
index 5509951..b985a392 100644
--- a/clang-tools-extra/test/clang-doc/basic-project.mustache.test
+++ b/clang-tools-extra/test/clang-doc/basic-project.mustache.test
@@ -1,18 +1,18 @@
// RUN: rm -rf %t && mkdir -p %t/docs %t/build
// RUN: sed 's|$test_dir|%/S|g' %S/Inputs/basic-project/database_template.json > %t/build/compile_commands.json
-// RUN: clang-doc --format=mustache --output=%t/docs --executor=all-TUs %t/build/compile_commands.json
-// RUN: FileCheck %s -input-file=%t/docs/html/_ZTV5Shape.html -check-prefix=HTML-SHAPE
-// RUN: FileCheck %s -input-file=%t/docs/html/_ZTV10Calculator.html -check-prefix=HTML-CALC
-// RUN: FileCheck %s -input-file=%t/docs/html/_ZTV9Rectangle.html -check-prefix=HTML-RECTANGLE
-// RUN: FileCheck %s -input-file=%t/docs/html/_ZTV6Circle.html -check-prefix=HTML-CIRCLE
+// RUN: clang-doc --format=html --output=%t/docs --executor=all-TUs %t/build/compile_commands.json
+// RUN: FileCheck %s -input-file=%t/docs/html/GlobalNamespace/_ZTV5Shape.html -check-prefix=HTML-SHAPE
+// RUN: FileCheck %s -input-file=%t/docs/html/GlobalNamespace/_ZTV10Calculator.html -check-prefix=HTML-CALC
+// RUN: FileCheck %s -input-file=%t/docs/html/GlobalNamespace/_ZTV9Rectangle.html -check-prefix=HTML-RECTANGLE
+// RUN: FileCheck %s -input-file=%t/docs/html/GlobalNamespace/_ZTV6Circle.html -check-prefix=HTML-CIRCLE
HTML-SHAPE: <html lang="en-US">
HTML-SHAPE: <head>
HTML-SHAPE: <meta charset="utf-8"/>
HTML-SHAPE: <title>Shape</title>
-HTML-SHAPE: <link rel="stylesheet" type="text/css" href="./clang-doc-mustache.css"/>
-HTML-SHAPE: <script src="./mustache-index.js"></script>
+HTML-SHAPE: <link rel="stylesheet" type="text/css" href="../clang-doc-mustache.css"/>
+HTML-SHAPE: <script src="../mustache-index.js"></script>
HTML-SHAPE: <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css">
HTML-SHAPE: <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
HTML-SHAPE: <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/cpp.min.js"></script>
@@ -60,84 +60,54 @@ HTML-SHAPE: <div class="content">
HTML-SHAPE: <section class="hero section-container">
HTML-SHAPE: <div class="hero__title">
HTML-SHAPE: <h1 class="hero__title-large">class Shape</h1>
-HTML-SHAPE: <div class="hero__subtitle">
-HTML-SHAPE: <div>
-HTML-SHAPE: <p> Abstract base class for shapes.</p>
-HTML-SHAPE: </div>
-HTML-SHAPE: <div>
-HTML-SHAPE: <p></p>
-HTML-SHAPE: </div>
-HTML-SHAPE: <div>
-HTML-SHAPE: <p> Provides a common interface for different types of shapes.</p>
-HTML-SHAPE: </div>
-HTML-SHAPE: </div>
+HTML-SHAPE: <div class="hero__subtitle">
+HTML-SHAPE: <div>
+HTML-SHAPE: <p> Abstract base class for shapes.</p>
+HTML-SHAPE: </div>
+HTML-SHAPE: <div>
+HTML-SHAPE: <p> Provides a common interface for different types of shapes.</p>
+HTML-SHAPE: </div>
+HTML-SHAPE: </div>
HTML-SHAPE: </div>
HTML-SHAPE: </section>
HTML-SHAPE: <section id="PublicMethods" class="section-container">
HTML-SHAPE: <h2>Public Methods</h2>
HTML-SHAPE: <div>
-HTML-SHAPE: <div class="delimiter-container">
-HTML-SHAPE: <div id="{{([0-9A-F]{40})}}">
-HTML-SHAPE: <pre>
-HTML-SHAPE: <code class="language-cpp code-clang-doc">
-HTML-SHAPE: double area ()
-HTML-SHAPE: </code>
-HTML-SHAPE: </pre>
-HTML-SHAPE: <div>
-HTML-SHAPE: <div>
-HTML-SHAPE: <p> Calculates the area of the shape.</p>
-HTML-SHAPE: </div>
-HTML-SHAPE: <div>
-HTML-SHAPE: <p></p>
-HTML-SHAPE: </div>
-HTML-SHAPE: <div>
-HTML-SHAPE: <p></p>
-HTML-SHAPE: </div>
-HTML-SHAPE: <h3>Returns</h3>
-HTML-SHAPE: <p> double The area of the shape.</p>
-HTML-SHAPE: </div>
-HTML-SHAPE: </div>
-HTML-SHAPE: </div>
-HTML-SHAPE: <div class="delimiter-container">
-HTML-SHAPE: <div id="{{([0-9A-F]{40})}}">
-HTML-SHAPE: <pre>
-HTML-SHAPE: <code class="language-cpp code-clang-doc">
-HTML-SHAPE: double perimeter ()
-HTML-SHAPE: </code>
-HTML-SHAPE: </pre>
-HTML-SHAPE: <div>
-HTML-SHAPE: <div>
-HTML-SHAPE: <p> Calculates the perimeter of the shape.</p>
-HTML-SHAPE: </div>
-HTML-SHAPE: <div>
-HTML-SHAPE: <p></p>
-HTML-SHAPE: </div>
-HTML-SHAPE: <div>
-HTML-SHAPE: <p></p>
-HTML-SHAPE: </div>
-HTML-SHAPE: <h3>Returns</h3>
-HTML-SHAPE: <p> double The perimeter of the shape.</p>
-HTML-SHAPE: </div>
-HTML-SHAPE: </div>
-HTML-SHAPE: </div>
-HTML-SHAPE: <div class="delimiter-container">
-HTML-SHAPE: <div id="{{([0-9A-F]{40})}}">
-HTML-SHAPE: <pre>
-HTML-SHAPE: <code class="language-cpp code-clang-doc">
-HTML-SHAPE: void ~Shape ()
-HTML-SHAPE: </code>
-HTML-SHAPE: </pre>
-HTML-SHAPE: <div>
-HTML-SHAPE: <div>
-HTML-SHAPE: <p> Virtual destructor.</p>
-HTML-SHAPE: </div>
-HTML-SHAPE: <div>
-HTML-SHAPE: <p></p>
-HTML-SHAPE: </div>
-HTML-SHAPE: </div>
-HTML-SHAPE: </div>
-HTML-SHAPE: </div>
-HTML-SHAPE: </div>
+HTML-SHAPE: <div class="delimiter-container">
+HTML-SHAPE: <div id="{{([0-9A-F]{40})}}">
+HTML-SHAPE: <pre><code class="language-cpp code-clang-doc">double area ()</code></pre>
+HTML-SHAPE: <div>
+HTML-SHAPE: <div>
+HTML-SHAPE: <p> Calculates the area of the shape.</p>
+HTML-SHAPE: </div>
+HTML-SHAPE: <h3>Returns</h3>
+HTML-SHAPE: <p> double The area of the shape.</p>
+HTML-SHAPE: </div>
+HTML-SHAPE: </div>
+HTML-SHAPE: </div>
+HTML-SHAPE: <div class="delimiter-container">
+HTML-SHAPE: <div id="{{([0-9A-F]{40})}}">
+HTML-SHAPE: <pre><code class="language-cpp code-clang-doc">double perimeter ()</code></pre>
+HTML-SHAPE: <div>
+HTML-SHAPE: <div>
+HTML-SHAPE: <p> Calculates the perimeter of the shape.</p>
+HTML-SHAPE: </div>
+HTML-SHAPE: <h3>Returns</h3>
+HTML-SHAPE: <p> double The perimeter of the shape.</p>
+HTML-SHAPE: </div>
+HTML-SHAPE: </div>
+HTML-SHAPE: </div>
+HTML-SHAPE: <div class="delimiter-container">
+HTML-SHAPE: <div id="{{([0-9A-F]{40})}}">
+HTML-SHAPE: <pre><code class="language-cpp code-clang-doc">void ~Shape ()</code></pre>
+HTML-SHAPE: <div>
+HTML-SHAPE: <div>
+HTML-SHAPE: <p> Virtual destructor.</p>
+HTML-SHAPE: </div>
+HTML-SHAPE: </div>
+HTML-SHAPE: </div>
+HTML-SHAPE: </div>
+HTML-SHAPE: </div>
HTML-SHAPE: </section>
HTML-SHAPE: </div>
HTML-SHAPE: </div>
@@ -151,8 +121,8 @@ HTML-CALC: <html lang="en-US">
HTML-CALC: <head>
HTML-CALC: <meta charset="utf-8"/>
HTML-CALC: <title>Calculator</title>
-HTML-CALC: <link rel="stylesheet" type="text/css" href="./clang-doc-mustache.css"/>
-HTML-CALC: <script src="./mustache-index.js"></script>
+HTML-CALC: <link rel="stylesheet" type="text/css" href="../clang-doc-mustache.css"/>
+HTML-CALC: <script src="../mustache-index.js"></script>
HTML-CALC: <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css">
HTML-CALC: <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
HTML-CALC: <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/cpp.min.js"></script>
@@ -217,216 +187,130 @@ HTML-CALC: <div class="content">
HTML-CALC: <section class="hero section-container">
HTML-CALC: <div class="hero__title">
HTML-CALC: <h1 class="hero__title-large">class Calculator</h1>
-HTML-CALC: <div>
-HTML-CALC: <p> A simple calculator class.</p>
-HTML-CALC: </div>
-HTML-CALC: <div>
-HTML-CALC: <p></p>
-HTML-CALC: </div>
-HTML-CALC: <div>
-HTML-CALC: <p> Provides basic arithmetic operations.</p>
-HTML-CALC: </div>
-HTML-CALC: </div>
+HTML-CALC: <div class="hero__subtitle">
+HTML-CALC: <div>
+HTML-CALC: <p> A simple calculator class.</p>
+HTML-CALC: </div>
+HTML-CALC: <div>
+HTML-CALC: <p> Provides basic arithmetic operations.</p>
+HTML-CALC: </div>
+HTML-CALC: </div>
HTML-CALC: </div>
HTML-CALC: </section>
HTML-CALC: <section id="PublicMembers" class="section-container">
HTML-CALC: <h2>Public Members</h2>
HTML-CALC: <div>
HTML-CALC: <div id="public_val" class="delimiter-container">
-HTML-CALC: <pre>
-HTML-CALC: <code class="language-cpp code-clang-doc" >int public_val</code>
-HTML-CALC: </pre>
+HTML-CALC: <pre><code class="language-cpp code-clang-doc" >int public_val</code></pre>
HTML-CALC: </div>
HTML-CALC: <div id="static_val" class="delimiter-container">
-HTML-CALC: <pre>
-HTML-CALC: <code class="language-cpp code-clang-doc" >const int static_val</code>
-HTML-CALC: </pre>
+HTML-CALC: <pre><code class="language-cpp code-clang-doc" >const int static_val</code></pre>
HTML-CALC: </div>
HTML-CALC: </div>
HTML-CALC: </section>
HTML-CALC: <section id="PublicMethods" class="section-container">
HTML-CALC: <h2>Public Methods</h2>
HTML-CALC: <div>
-HTML-CALC: <div class="delimiter-container">
-HTML-CALC: <div id="{{([0-9A-F]{40})}}">
-HTML-CALC: <pre>
-HTML-CALC: <code class="language-cpp code-clang-doc">
-HTML-CALC: int add (int a, int b)
-HTML-CALC: </code>
-HTML-CALC: </pre>
-HTML-CALC: <div>
-HTML-CALC: <div>
-HTML-CALC: <p> Adds two integers.</p>
-HTML-CALC: </div>
-HTML-CALC: <div>
-HTML-CALC: <p></p>
-HTML-CALC: </div>
-HTML-CALC: <div>
-HTML-CALC: <p></p>
-HTML-CALC: </div>
-HTML-CALC: <h3>Parameters</h3>
-HTML-CALC: <div>
-HTML-CALC: <b>a</b> <div>
-HTML-CALC: <p> First integer.</p>
-HTML-CALC: </div>
-HTML-CALC: <div>
-HTML-CALC: <p></p>
-HTML-CALC: </div>
-HTML-CALC: </div>
-HTML-CALC: <div>
-HTML-CALC: <b>b</b> <div>
-HTML-CALC: <p> Second integer.</p>
-HTML-CALC: </div>
-HTML-CALC: <div>
-HTML-CALC: <p></p>
-HTML-CALC: </div>
-HTML-CALC: </div>
-HTML-CALC: <h3>Returns</h3>
-HTML-CALC: <p> int The sum of a and b.</p>
-HTML-CALC: </div>
-HTML-CALC: </div>
-HTML-CALC: </div>
-HTML-CALC: <div class="delimiter-container">
-HTML-CALC: <div id="{{([0-9A-F]{40})}}">
-HTML-CALC: <pre>
-HTML-CALC: <code class="language-cpp code-clang-doc">
-HTML-CALC: int subtract (int a, int b)
-HTML-CALC: </code>
-HTML-CALC: </pre>
-HTML-CALC: <div>
-HTML-CALC: <div>
-HTML-CALC: <p> Subtracts the second integer from the first.</p>
-HTML-CALC: </div>
-HTML-CALC: <div>
-HTML-CALC: <p></p>
-HTML-CALC: </div>
-HTML-CALC: <div>
-HTML-CALC: <p></p>
-HTML-CALC: </div>
-HTML-CALC: <h3>Returns</h3>
-HTML-CALC: <p> int The result of a - b.</p>
-HTML-CALC: </div>
-HTML-CALC: </div>
-HTML-CALC: </div>
-HTML-CALC: <div class="delimiter-container">
-HTML-CALC: <div id="{{([0-9A-F]{40})}}">
-HTML-CALC: <pre>
-HTML-CALC: <code class="language-cpp code-clang-doc">
-HTML-CALC: int multiply (int a, int b)
-HTML-CALC: </code>
-HTML-CALC: </pre>
-HTML-CALC: <div>
-HTML-CALC: <div>
-HTML-CALC: <p> Multiplies two integers.</p>
-HTML-CALC: </div>
-HTML-CALC: <div>
-HTML-CALC: <p></p>
-HTML-CALC: </div>
-HTML-CALC: <div>
-HTML-CALC: <p></p>
-HTML-CALC: </div>
-HTML-CALC: <h3>Parameters</h3>
-HTML-CALC: <div>
-HTML-CALC: <b>a</b> <div>
-HTML-CALC: <p> First integer.</p>
-HTML-CALC: </div>
-HTML-CALC: <div>
-HTML-CALC: <p></p>
-HTML-CALC: </div>
-HTML-CALC: </div>
-HTML-CALC: <div>
-HTML-CALC: <b>b</b> <div>
-HTML-CALC: <p> Second integer.</p>
-HTML-CALC: </div>
-HTML-CALC: <div>
-HTML-CALC: <p></p>
-HTML-CALC: </div>
-HTML-CALC: </div>
-HTML-CALC: <h3>Returns</h3>
-HTML-CALC: <p> int The product of a and b.</p>
-HTML-CALC: </div>
-HTML-CALC: </div>
-HTML-CALC: </div>
-HTML-CALC: <div class="delimiter-container">
-HTML-CALC: <div id="{{([0-9A-F]{40})}}">
-HTML-CALC: <pre>
-HTML-CALC: <code class="language-cpp code-clang-doc">
-HTML-CALC: double divide (int a, int b)
-HTML-CALC: </code>
-HTML-CALC: </pre>
-HTML-CALC: <div>
-HTML-CALC: <div>
-HTML-CALC: <p> Divides the first integer by the second.</p>
-HTML-CALC: </div>
-HTML-CALC: <div>
-HTML-CALC: <p></p>
-HTML-CALC: </div>
-HTML-CALC: <div>
-HTML-CALC: <p></p>
-HTML-CALC: </div>
-HTML-CALC: <h3>Parameters</h3>
-HTML-CALC: <div>
-HTML-CALC: <b>a</b> <div>
-HTML-CALC: <p> First integer.</p>
-HTML-CALC: </div>
-HTML-CALC: <div>
-HTML-CALC: <p></p>
-HTML-CALC: </div>
-HTML-CALC: </div>
-HTML-CALC: <div>
-HTML-CALC: <b>b</b> <div>
-HTML-CALC: <p> Second integer.</p>
-HTML-CALC: </div>
-HTML-CALC: <div>
-HTML-CALC: <p></p>
-HTML-CALC: </div>
-HTML-CALC: </div>
-HTML-CALC: <h3>Returns</h3>
-HTML-CALC: <p> double The result of a / b.</p>
-HTML-CALC: <p></p>
-HTML-CALC: </div>
-HTML-CALC: </div>
-HTML-CALC: </div>
-HTML-CALC: <div class="delimiter-container">
-HTML-CALC: <div id="{{([0-9A-F]{40})}}">
-HTML-CALC: <pre>
-HTML-CALC: <code class="language-cpp code-clang-doc">
-HTML-CALC: int mod (int a, int b)
-HTML-CALC: </code>
-HTML-CALC: </pre>
-HTML-CALC: <div>
-HTML-CALC: <div>
-HTML-CALC: <p> Performs the mod operation on integers.</p>
-HTML-CALC: </div>
-HTML-CALC: <div>
-HTML-CALC: <p></p>
-HTML-CALC: </div>
-HTML-CALC: <div>
-HTML-CALC: <p></p>
-HTML-CALC: </div>
-HTML-CALC: <h3>Parameters</h3>
-HTML-CALC: <div>
-HTML-CALC: <b>a</b> <div>
-HTML-CALC: <p> First integer.</p>
-HTML-CALC: </div>
-HTML-CALC: <div>
-HTML-CALC: <p></p>
-HTML-CALC: </div>
-HTML-CALC: </div>
-HTML-CALC: <div>
-HTML-CALC: <b>b</b> <div>
-HTML-CALC: <p> Second integer.</p>
-HTML-CALC: </div>
-HTML-CALC: <div>
-HTML-CALC: <p></p>
-HTML-CALC: </div>
-HTML-CALC: </div>
-HTML-CALC: <h3>Returns</h3>
-HTML-CALC: <p> The result of a % b.</p>
-HTML-CALC: </div>
-HTML-CALC: </div>
-HTML-CALC: </div>
-HTML-CALC: </div>
+HTML-CALC: <div class="delimiter-container">
+HTML-CALC: <div id="{{([0-9A-F]{40})}}">
+HTML-CALC: <pre><code class="language-cpp code-clang-doc">int add (int a, int b)</code></pre>
+HTML-CALC: <div>
+HTML-CALC: <div>
+HTML-CALC: <p> Adds two integers.</p>
+HTML-CALC: </div>
+HTML-CALC: <h3>Parameters</h3>
+HTML-CALC: <div>
+HTML-CALC: <b>a</b> First integer.
+HTML-CALC: </div>
+HTML-CALC: <div>
+HTML-CALC: <b>b</b> Second integer.
+HTML-CALC: </div>
+HTML-CALC: <h3>Returns</h3>
+HTML-CALC: <p> int The sum of a and b.</p>
+HTML-CALC: </div>
+HTML-CALC: </div>
+HTML-CALC: </div>
+HTML-CALC: <div class="delimiter-container">
+HTML-CALC: <div id="{{([0-9A-F]{40})}}">
+HTML-CALC: <pre><code class="language-cpp code-clang-doc">int subtract (int a, int b)</code></pre>
+HTML-CALC: <div>
+HTML-CALC: <div>
+HTML-CALC: <p> Subtracts the second integer from the first.</p>
+HTML-CALC: </div>
+HTML-CALC: <h3>Parameters</h3>
+HTML-CALC: <div>
+HTML-CALC: <b>a</b> First integer.
+HTML-CALC: </div>
+HTML-CALC: <div>
+HTML-CALC: <b>b</b> Second integer.
+HTML-CALC: </div>
+HTML-CALC: <h3>Returns</h3>
+HTML-CALC: <p> int The result of a - b.</p>
+HTML-CALC: </div>
+HTML-CALC: </div>
+HTML-CALC: </div>
+HTML-CALC: <div class="delimiter-container">
+HTML-CALC: <div id="{{([0-9A-F]{40})}}">
+HTML-CALC: <pre><code class="language-cpp code-clang-doc">int multiply (int a, int b)</code></pre>
+HTML-CALC: <div>
+HTML-CALC: <div>
+HTML-CALC: <p> Multiplies two integers.</p>
+HTML-CALC: </div>
+HTML-CALC: <h3>Parameters</h3>
+HTML-CALC: <div>
+HTML-CALC: <b>a</b> First integer.
+HTML-CALC: </div>
+HTML-CALC: <div>
+HTML-CALC: <b>b</b> Second integer.
+HTML-CALC: </div>
+HTML-CALC: <h3>Returns</h3>
+HTML-CALC: <p> int The product of a and b.</p>
+HTML-CALC: </div>
+HTML-CALC: </div>
+HTML-CALC: </div>
+HTML-CALC: <div class="delimiter-container">
+HTML-CALC: <div id="{{([0-9A-F]{40})}}">
+HTML-CALC: <pre><code class="language-cpp code-clang-doc">double divide (int a, int b)</code></pre>
+HTML-CALC: <div>
+HTML-CALC: <div>
+HTML-CALC: <p> Divides the first integer by the second.</p>
+HTML-CALC: </div>
+HTML-CALC: <h3>Parameters</h3>
+HTML-CALC: <div>
+HTML-CALC: <b>a</b> First integer.
+HTML-CALC: </div>
+HTML-CALC: <div>
+HTML-CALC: <b>b</b> Second integer.
+HTML-CALC: </div>
+HTML-CALC: <h3>Returns</h3>
+HTML-CALC: <p> double The result of a / b.</p>
+HTML-CALC: <h3>Throws</h3>
+HTML-CALC: <div>
+HTML-CALC: <b>std::invalid_argument</b> if b is zero.
+HTML-CALC: </div>
+HTML-CALC: </div>
+HTML-CALC: </div>
+HTML-CALC: </div>
+HTML-CALC: <div class="delimiter-container">
+HTML-CALC: <div id="{{([0-9A-F]{40})}}">
+HTML-CALC: <pre><code class="language-cpp code-clang-doc">int mod (int a, int b)</code></pre>
+HTML-CALC: <div>
+HTML-CALC: <div>
+HTML-CALC: <p> Performs the mod operation on integers.</p>
+HTML-CALC: </div>
+HTML-CALC: <h3>Parameters</h3>
+HTML-CALC: <div>
+HTML-CALC: <b>a</b> First integer.
+HTML-CALC: </div>
+HTML-CALC: <div>
+HTML-CALC: <b>b</b> Second integer.
+HTML-CALC: </div>
+HTML-CALC: <h3>Returns</h3>
+HTML-CALC: <p> The result of a % b.</p>
+HTML-CALC: </div>
+HTML-CALC: </div>
+HTML-CALC: </div>
+HTML-CALC: </div>
HTML-CALC: </section>
HTML-CALC: </div>
HTML-CALC: </div>
@@ -435,13 +319,14 @@ HTML-CALC: </body>
HTML-CALC: </html>
+
HTML-RECTANGLE: <!DOCTYPE html>
HTML-RECTANGLE: <html lang="en-US">
HTML-RECTANGLE: <head>
HTML-RECTANGLE: <meta charset="utf-8"/>
HTML-RECTANGLE: <title>Rectangle</title>
-HTML-RECTANGLE: <link rel="stylesheet" type="text/css" href="./clang-doc-mustache.css"/>
-HTML-RECTANGLE: <script src="./mustache-index.js"></script>
+HTML-RECTANGLE: <link rel="stylesheet" type="text/css" href="../clang-doc-mustache.css"/>
+HTML-RECTANGLE: <script src="../mustache-index.js"></script>
HTML-RECTANGLE: <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css">
HTML-RECTANGLE: <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
HTML-RECTANGLE: <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/cpp.min.js"></script>
@@ -489,101 +374,61 @@ HTML-RECTANGLE: <div class="content">
HTML-RECTANGLE: <section class="hero section-container">
HTML-RECTANGLE: <div class="hero__title">
HTML-RECTANGLE: <h1 class="hero__title-large">class Rectangle</h1>
-HTML-RECTANGLE: <div class="hero__subtitle">
-HTML-RECTANGLE: <div>
-HTML-RECTANGLE: <p> Rectangle class derived from Shape.</p>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: <div>
-HTML-RECTANGLE: <p></p>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: <div>
-HTML-RECTANGLE: <p> Represents a rectangle with a given width and height.</p>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: </div>
+HTML-RECTANGLE: <div class="hero__subtitle">
+HTML-RECTANGLE: <div>
+HTML-RECTANGLE: <p> Rectangle class derived from Shape.</p>
+HTML-RECTANGLE: </div>
+HTML-RECTANGLE: <div>
+HTML-RECTANGLE: <p> Represents a rectangle with a given width and height.</p>
+HTML-RECTANGLE: </div>
+HTML-RECTANGLE: </div>
HTML-RECTANGLE: </div>
HTML-RECTANGLE: </section>
HTML-RECTANGLE: <section id="PublicMethods" class="section-container">
HTML-RECTANGLE: <h2>Public Methods</h2>
HTML-RECTANGLE: <div>
-HTML-RECTANGLE: <div class="delimiter-container">
-HTML-RECTANGLE: <div id="{{([0-9A-F]{40})}}">
-HTML-RECTANGLE: <pre>
-HTML-RECTANGLE: <code class="language-cpp code-clang-doc">
-HTML-RECTANGLE: void Rectangle (double width, double height)
-HTML-RECTANGLE: </code>
-HTML-RECTANGLE: </pre>
-HTML-RECTANGLE: <div>
-HTML-RECTANGLE: <div>
-HTML-RECTANGLE: <p> Constructs a new Rectangle object.</p>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: <div>
-HTML-RECTANGLE: <p></p>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: <div>
-HTML-RECTANGLE: <p></p>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: <h3>Parameters</h3>
-HTML-RECTANGLE: <div>
-HTML-RECTANGLE: <b>width</b> <div>
-HTML-RECTANGLE: <p> Width of the rectangle.</p>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: <div>
-HTML-RECTANGLE: <p></p>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: <div>
-HTML-RECTANGLE: <b>height</b> <div>
-HTML-RECTANGLE: <p> Height of the rectangle.</p>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: <div class="delimiter-container">
-HTML-RECTANGLE: <div id="{{([0-9A-F]{40})}}">
-HTML-RECTANGLE: <pre>
-HTML-RECTANGLE: <code class="language-cpp code-clang-doc">
-HTML-RECTANGLE: double area ()
-HTML-RECTANGLE: </code>
-HTML-RECTANGLE: </pre>
-HTML-RECTANGLE: <div>
-HTML-RECTANGLE: <div>
-HTML-RECTANGLE: <p> Calculates the area of the rectangle.</p>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: <div>
-HTML-RECTANGLE: <p></p>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: <div>
-HTML-RECTANGLE: <p></p>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: <h3>Returns</h3>
-HTML-RECTANGLE: <p> double The area of the rectangle.</p>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: <div class="delimiter-container">
-HTML-RECTANGLE: <div id="{{([0-9A-F]{40})}}">
-HTML-RECTANGLE: <pre>
-HTML-RECTANGLE: <code class="language-cpp code-clang-doc">
-HTML-RECTANGLE: double perimeter ()
-HTML-RECTANGLE: </code>
-HTML-RECTANGLE: </pre>
-HTML-RECTANGLE: <div>
-HTML-RECTANGLE: <div>
-HTML-RECTANGLE: <p> Calculates the perimeter of the rectangle.</p>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: <div>
-HTML-RECTANGLE: <p></p>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: <div>
-HTML-RECTANGLE: <p></p>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: <h3>Returns</h3>
-HTML-RECTANGLE: <p> double The perimeter of the rectangle.</p>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: </div>
-HTML-RECTANGLE: </div>
+HTML-RECTANGLE: <div class="delimiter-container">
+HTML-RECTANGLE: <div id="{{([0-9A-F]{40})}}">
+HTML-RECTANGLE: <pre><code class="language-cpp code-clang-doc">void Rectangle (double width, double height)</code></pre>
+HTML-RECTANGLE: <div>
+HTML-RECTANGLE: <div>
+HTML-RECTANGLE: <p> Constructs a new Rectangle object.</p>
+HTML-RECTANGLE: </div>
+HTML-RECTANGLE: <h3>Parameters</h3>
+HTML-RECTANGLE: <div>
+HTML-RECTANGLE: <b>width</b> Width of the rectangle.
+HTML-RECTANGLE: </div>
+HTML-RECTANGLE: <div>
+HTML-RECTANGLE: <b>height</b> Height of the rectangle.
+HTML-RECTANGLE: </div>
+HTML-RECTANGLE: </div>
+HTML-RECTANGLE: </div>
+HTML-RECTANGLE: </div>
+HTML-RECTANGLE: <div class="delimiter-container">
+HTML-RECTANGLE: <div id="{{([0-9A-F]{40})}}">
+HTML-RECTANGLE: <pre><code class="language-cpp code-clang-doc">double area ()</code></pre>
+HTML-RECTANGLE: <div>
+HTML-RECTANGLE: <div>
+HTML-RECTANGLE: <p> Calculates the area of the rectangle.</p>
+HTML-RECTANGLE: </div>
+HTML-RECTANGLE: <h3>Returns</h3>
+HTML-RECTANGLE: <p> double The area of the rectangle.</p>
+HTML-RECTANGLE: </div>
+HTML-RECTANGLE: </div>
+HTML-RECTANGLE: </div>
+HTML-RECTANGLE: <div class="delimiter-container">
+HTML-RECTANGLE: <div id="{{([0-9A-F]{40})}}">
+HTML-RECTANGLE: <pre><code class="language-cpp code-clang-doc">double perimeter ()</code></pre>
+HTML-RECTANGLE: <div>
+HTML-RECTANGLE: <div>
+HTML-RECTANGLE: <p> Calculates the perimeter of the rectangle.</p>
+HTML-RECTANGLE: </div>
+HTML-RECTANGLE: <h3>Returns</h3>
+HTML-RECTANGLE: <p> double The perimeter of the rectangle.</p>
+HTML-RECTANGLE: </div>
+HTML-RECTANGLE: </div>
+HTML-RECTANGLE: </div>
+HTML-RECTANGLE: </div>
HTML-RECTANGLE: </section>
HTML-RECTANGLE: </div>
HTML-RECTANGLE: </div>
@@ -592,13 +437,14 @@ HTML-RECTANGLE: </body>
HTML-RECTANGLE: </html>
+
HTML-CIRCLE: <!DOCTYPE html>
HTML-CIRCLE: <html lang="en-US">
HTML-CIRCLE: <head>
HTML-CIRCLE: <meta charset="utf-8"/>
HTML-CIRCLE: <title>Circle</title>
-HTML-CIRCLE: <link rel="stylesheet" type="text/css" href="./clang-doc-mustache.css"/>
-HTML-CIRCLE: <script src="./mustache-index.js"></script>
+HTML-CIRCLE: <link rel="stylesheet" type="text/css" href="../clang-doc-mustache.css"/>
+HTML-CIRCLE: <script src="../mustache-index.js"></script>
HTML-CIRCLE: <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css">
HTML-CIRCLE: <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
HTML-CIRCLE: <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/cpp.min.js"></script>
@@ -646,102 +492,67 @@ HTML-CIRCLE: <div class="content">
HTML-CIRCLE: <section class="hero section-container">
HTML-CIRCLE: <div class="hero__title">
HTML-CIRCLE: <h1 class="hero__title-large">class Circle</h1>
-HTML-CIRCLE: <div class="hero__subtitle">
-HTML-CIRCLE: <div>
-HTML-CIRCLE: <p> Circle class derived from Shape.</p>
-HTML-CIRCLE: </div>
-HTML-CIRCLE: <div>
-HTML-CIRCLE: <p></p>
-HTML-CIRCLE: </div>
-HTML-CIRCLE: <div>
-HTML-CIRCLE: <p> Represents a circle with a given radius.</p>
-HTML-CIRCLE: </div>
-HTML-CIRCLE: </div>
+HTML-CIRCLE: <div class="hero__subtitle">
+HTML-CIRCLE: <div>
+HTML-CIRCLE: <p> Circle class derived from Shape.</p>
+HTML-CIRCLE: </div>
+HTML-CIRCLE: <div>
+HTML-CIRCLE: <p> Represents a circle with a given radius.</p>
+HTML-CIRCLE: </div>
+HTML-CIRCLE: </div>
HTML-CIRCLE: </div>
HTML-CIRCLE: </section>
HTML-CIRCLE: <section id="PublicMethods" class="section-container">
HTML-CIRCLE: <h2>Public Methods</h2>
HTML-CIRCLE: <div>
-HTML-CIRCLE: <div class="delimiter-container">
-HTML-CIRCLE: <div id="{{([0-9A-F]{40})}}">
-HTML-CIRCLE: <pre>
-HTML-CIRCLE: <code class="language-cpp code-clang-doc">
-HTML-CIRCLE: void Circle (double radius)
-HTML-CIRCLE: </code>
-HTML-CIRCLE: </pre>
-HTML-CIRCLE: <div>
-HTML-CIRCLE: <div>
-HTML-CIRCLE: <p> Constructs a new Circle object.</p>
-HTML-CIRCLE: </div>
-HTML-CIRCLE: <div>
-HTML-CIRCLE: <p></p>
-HTML-CIRCLE: </div>
-HTML-CIRCLE: <div>
-HTML-CIRCLE: <p></p>
-HTML-CIRCLE: </div>
-HTML-CIRCLE: <h3>Parameters</h3>
-HTML-CIRCLE: <div>
-HTML-CIRCLE: <b>radius</b> <div>
-HTML-CIRCLE: <p> Radius of the circle.</p>
-HTML-CIRCLE: </div>
-HTML-CIRCLE: </div>
-HTML-CIRCLE: </div>
-HTML-CIRCLE: </div>
-HTML-CIRCLE: </div>
-HTML-CIRCLE: <div class="delimiter-container">
-HTML-CIRCLE: <div id="{{([0-9A-F]{40})}}">
-HTML-CIRCLE: <pre>
-HTML-CIRCLE: <code class="language-cpp code-clang-doc">
-HTML-CIRCLE: double area ()
-HTML-CIRCLE: </code>
-HTML-CIRCLE: </pre>
-HTML-CIRCLE: <div>
-HTML-CIRCLE: <div>
-HTML-CIRCLE: <p> Calculates the area of the circle.</p>
-HTML-CIRCLE: </div>
-HTML-CIRCLE: <div>
-HTML-CIRCLE: <p></p>
-HTML-CIRCLE: </div>
-HTML-CIRCLE: <div>
-HTML-CIRCLE: <p></p>
-HTML-CIRCLE: </div>
-HTML-CIRCLE: <h3>Returns</h3>
-HTML-CIRCLE: <p> double The area of the circle.</p>
-HTML-CIRCLE: </div>
-HTML-CIRCLE: </div>
-HTML-CIRCLE: </div>
-HTML-CIRCLE: <div class="delimiter-container">
-HTML-CIRCLE: <div id="{{([0-9A-F]{40})}}">
-HTML-CIRCLE: <pre>
-HTML-CIRCLE: <code class="language-cpp code-clang-doc">
-HTML-CIRCLE: double perimeter ()
-HTML-CIRCLE: </code>
-HTML-CIRCLE: </pre>
-HTML-CIRCLE: <div>
-HTML-CIRCLE: <div>
-HTML-CIRCLE: <p> Calculates the perimeter of the circle.</p>
-HTML-CIRCLE: </div>
-HTML-CIRCLE: <div>
-HTML-CIRCLE: <p></p>
-HTML-CIRCLE: </div>
-HTML-CIRCLE: <div>
-HTML-CIRCLE: <p></p>
-HTML-CIRCLE: </div>
-HTML-CIRCLE: <h3>Returns</h3>
-HTML-CIRCLE: <p> double The perimeter of the circle.</p>
-HTML-CIRCLE: <h3>Code</h3>
-HTML-CIRCLE: <div>
-HTML-CIRCLE: <pre class="code-block">
-HTML-CIRCLE: <code>
-HTML-CIRCLE: Circle circle(5.0);
-HTML-CIRCLE: double perimeter = circle.perimeter();
-HTML-CIRCLE: </code>
-HTML-CIRCLE: </pre>
-HTML-CIRCLE: </div>
-HTML-CIRCLE: </div>
-HTML-CIRCLE: </div>
-HTML-CIRCLE: </div>
-HTML-CIRCLE: </div>
+HTML-CIRCLE: <div class="delimiter-container">
+HTML-CIRCLE: <div id="{{([0-9A-F]{40})}}">
+HTML-CIRCLE: <pre><code class="language-cpp code-clang-doc">void Circle (double radius)</code></pre>
+HTML-CIRCLE: <div>
+HTML-CIRCLE: <div>
+HTML-CIRCLE: <p> Constructs a new Circle object.</p>
+HTML-CIRCLE: </div>
+HTML-CIRCLE: <h3>Parameters</h3>
+HTML-CIRCLE: <div>
+HTML-CIRCLE: <b>radius</b> Radius of the circle.
+HTML-CIRCLE: </div>
+HTML-CIRCLE: </div>
+HTML-CIRCLE: </div>
+HTML-CIRCLE: </div>
+HTML-CIRCLE: <div class="delimiter-container">
+HTML-CIRCLE: <div id="{{([0-9A-F]{40})}}">
+HTML-CIRCLE: <pre><code class="language-cpp code-clang-doc">double area ()</code></pre>
+HTML-CIRCLE: <div>
+HTML-CIRCLE: <div>
+HTML-CIRCLE: <p> Calculates the area of the circle.</p>
+HTML-CIRCLE: </div>
+HTML-CIRCLE: <h3>Returns</h3>
+HTML-CIRCLE: <p> double The area of the circle.</p>
+HTML-CIRCLE: </div>
+HTML-CIRCLE: </div>
+HTML-CIRCLE: </div>
+HTML-CIRCLE: <div class="delimiter-container">
+HTML-CIRCLE: <div id="{{([0-9A-F]{40})}}">
+HTML-CIRCLE: <pre><code class="language-cpp code-clang-doc">double perimeter ()</code></pre>
+HTML-CIRCLE: <div>
+HTML-CIRCLE: <div>
+HTML-CIRCLE: <p> Calculates the perimeter of the circle.</p>
+HTML-CIRCLE: </div>
+HTML-CIRCLE: <h3>Returns</h3>
+HTML-CIRCLE: <p> double The perimeter of the circle.</p>
+HTML-CIRCLE: <h3>Code</h3>
+HTML-CIRCLE: <div>
+HTML-CIRCLE: <pre class="code-block">
+HTML-CIRCLE: <code>
+HTML-CIRCLE: Circle circle(5.0);
+HTML-CIRCLE: double perimeter = circle.perimeter();
+HTML-CIRCLE: </code>
+HTML-CIRCLE: </pre>
+HTML-CIRCLE: </div>
+HTML-CIRCLE: </div>
+HTML-CIRCLE: </div>
+HTML-CIRCLE: </div>
+HTML-CIRCLE: </div>
HTML-CIRCLE: </section>
HTML-CIRCLE: </div>
HTML-CIRCLE: </div>
diff --git a/clang-tools-extra/test/clang-doc/basic-project.test b/clang-tools-extra/test/clang-doc/basic-project.test
index 9c1ed29..9220dc6 100644
--- a/clang-tools-extra/test/clang-doc/basic-project.test
+++ b/clang-tools-extra/test/clang-doc/basic-project.test
@@ -1,31 +1,6 @@
// RUN: rm -rf %t && mkdir -p %t/docs %t/build
// RUN: sed 's|$test_dir|%/S|g' %S/Inputs/basic-project/database_template.json > %t/build/compile_commands.json
-// RUN: clang-doc --format=html --output=%t/docs --executor=all-TUs %t/build/compile_commands.json
-// RUN: FileCheck %s -input-file=%t/docs/index_json.js -check-prefix=JSON-INDEX
-// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Shape.html -check-prefix=HTML-SHAPE
-// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Calculator.html -check-prefix=HTML-CALC
-// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Rectangle.html -check-prefix=HTML-RECTANGLE
-// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Circle.html -check-prefix=HTML-CIRCLE
-
-// RUN: clang-doc --format=html --output=%t/docs-with-prefix --executor=all-TUs %t/build/compile_commands.json --repository=https://repository.com --repository-line-prefix=L
-// RUN: FileCheck %s -input-file=%t/docs-with-prefix/GlobalNamespace/Shape.html -check-prefixes=HTML-SHAPE,SHAPE-LINE-PREFIX
-// RUN: FileCheck %s -input-file=%t/docs-with-prefix/GlobalNamespace/Calculator.html -check-prefixes=HTML-CALC,CALC-LINE-PREFIX
-// RUN: FileCheck %s -input-file=%t/docs-with-prefix/GlobalNamespace/Rectangle.html -check-prefixes=HTML-RECTANGLE,RECTANGLE-LINE-PREFIX
-// RUN: FileCheck %s -input-file=%t/docs-with-prefix/GlobalNamespace/Circle.html -check-prefixes=HTML-CIRCLE,CIRCLE-LINE-PREFIX
-
-// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Shape.html -check-prefixes=HTML-SHAPE,SHAPE-NO-REPOSITORY
-// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Calculator.html -check-prefixes=HTML-CALC,CALC-NO-REPOSITORY
-// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Rectangle.html -check-prefixes=HTML-RECTANGLE,RECTANGLE-NO-REPOSITORY
-// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Circle.html -check-prefixes=HTML-CIRCLE,CIRCLE-NO-REPOSITORY
-
-// RUN: clang-doc --format=html --output=%t/docs --executor=all-TUs %t/build/compile_commands.json --repository=https://repository.com
-// RUN: FileCheck %s -input-file=%t/docs/index_json.js -check-prefixes=JSON-INDEX
-// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Shape.html -check-prefixes=HTML-SHAPE,SHAPE-REPOSITORY
-// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Calculator.html -check-prefixes=HTML-CALC,CALC-REPOSITORY
-// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Rectangle.html -check-prefixes=HTML-RECTANGLE,RECTANGLE-REPOSITORY
-// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Circle.html -check-prefixes=HTML-CIRCLE,CIRCLE-REPOSITORY
-
// RUN: clang-doc --format=md --output=%t/docs --executor=all-TUs %t/build/compile_commands.json
// RUN: FileCheck %s -input-file=%t/docs/all_files.md -check-prefixes=MD-ALL-FILES
// RUN: FileCheck %s -input-file=%t/docs/index.md -check-prefixes=MD-INDEX
@@ -81,248 +56,6 @@
// JSON-INDEX-NEXT: };
// JSON-INDEX-NEXT: }
-// HTML-SHAPE: <h1>class Shape</h1>
-// SHAPE-NO-REPOSITORY: <p>Defined at line 8 of file .{{.}}include{{.}}Shape.h</p>
-// SHAPE-REPOSITORY: <p>
-// SHAPE-REPOSITORY-NEXT: Defined at line
-// SHAPE-REPOSITORY-NEXT: <a href="https://repository.com/./include/Shape.h#8">8</a>
-// SHAPE-LINE-PREFIX: <a href="https://repository.com/./include/Shape.h#L8">8</a>
-// SHAPE-REPOSITORY-NEXT: of file
-// SHAPE-REPOSITORY-NEXT: <a href="https://repository.com/./include/Shape.h">Shape.h</a>
-// SHAPE-REPOSITORY-NEXT: </p>
-// HTML-SHAPE: <div>brief</div>
-// HTML-SHAPE: <p> Abstract base class for shapes.</p>
-// HTML-SHAPE: <p> Provides a common interface for different types of shapes.</p>
-// HTML-SHAPE: <h2 id="Functions">Functions</h2>
-// HTML-SHAPE: <h3 id="{{([0-9A-F]{40})}}">area</h3>
-// HTML-SHAPE: <p>public double area()</p>
-// HTML-SHAPE: <div>brief</div>
-// HTML-SHAPE: <p> Calculates the area of the shape.</p>
-// HTML-SHAPE: <h3 id="{{([0-9A-F]{40})}}">perimeter</h3>
-// HTML-SHAPE: <p>public double perimeter()</p>
-// HTML-SHAPE: <div>brief</div>
-// HTML-SHAPE: <p> Calculates the perimeter of the shape.</p>
-// HTML-SHAPE: <div>return</div>
-// HTML-SHAPE: <p> double The perimeter of the shape.</p>
-// HTML-SHAPE: <h3 id="{{([0-9A-F]{40})}}">~Shape</h3>
-// HTML-SHAPE: <p>public void ~Shape()</p>
-
-// SHAPE-NO-REPOSITORY: Defined at line 13 of file .{{.}}include{{.}}Shape.h
-// SHAPE-REPOSITORY: Defined at line
-// SHAPE-REPOSITORY-NEXT: <a href="https://repository.com/./include/Shape.h#13">13</a>
-// SHAPE-LINE-PREFIX: <a href="https://repository.com/./include/Shape.h#L13">13</a>
-// SHAPE-REPOSITORY-NEXT: of file
-// SHAPE-REPOSITORY-NEXT: <a href="https://repository.com/./include/Shape.h">Shape.h</a>
-
-// HTML-SHAPE: <div>brief</div>
-// HTML-SHAPE: <p> Virtual destructor.</p>
-
-// HTML-CALC: <h1>class Calculator</h1>
-// CALC-NO-REPOSITORY: <p>Defined at line 8 of file .{{.}}include{{.}}Calculator.h</p>
-// CALC-REPOSITORY: <p>
-// CALC-REPOSITORY-NEXT: Defined at line
-// CALC-REPOSITORY-NEXT: <a href="https://repository.com/./include/Calculator.h#8">8</a>
-// CALC-LINE-PREFIX: <a href="https://repository.com/./include/Calculator.h#L8">8</a>
-// CALC-REPOSITORY-NEXT: of file
-// CALC-REPOSITORY-NEXT: <a href="https://repository.com/./include/Calculator.h">Calculator.h</a>
-// CALC-REPOSITORY-NEXT: </p>
-// HTML-CALC: <div>brief</div>
-// HTML-CALC: <p> A simple calculator class.</p>
-// HTML-CALC: <p> Provides basic arithmetic operations.</p>
-
-// HTML-CALC: <h2 id="Members">Members</h2>
-// HTML-CALC: <div>brief</div>
-// HTML-CALC: <p> Holds a public value.</p>
-// HTML-CALC: <div>public int public_val</div>
-// HTML-CALC: <div>brief</div>
-// HTML-CALC: <p> A static value.</p>
-// HTML-CALC: <div>public static const int static_val</div>
-
-// HTML-CALC: <h2 id="Functions">Functions</h2>
-// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">add</h3>
-// HTML-CALC: <p>public int add(int a, int b)</p>
-// CALC-NO-REPOSITORY: Defined at line 3 of file .{{.}}src{{.}}Calculator.cpp
-// CALC-REPOSITORY: Defined at line
-// CALC-REPOSITORY-NEXT: <a href="https://repository.com/./src/Calculator.cpp#3">3</a>
-// CALC-LINE-PREFIX: <a href="https://repository.com/./src/Calculator.cpp#L3">3</a>
-// CALC-REPOSITORY-NEXT: of file
-// CALC-REPOSITORY-NEXT: <a href="https://repository.com/./src/Calculator.cpp">Calculator.cpp</a>
-
-// HTML-CALC: <div>brief</div>
-// HTML-CALC: <p> Adds two integers.</p>
-// HTML-CALC: <div>return</div>
-// HTML-CALC: <p> int The sum of a and b.</p>
-// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">subtract</h3>
-// HTML-CALC: <p>public int subtract(int a, int b)</p>
-// CALC-NO-REPOSITORY: Defined at line 7 of file .{{.}}src{{.}}Calculator.cpp
-// CALC-REPOSITORY: Defined at line
-// CALC-REPOSITORY-NEXT: <a href="https://repository.com/./src/Calculator.cpp#7">7</a>
-// CALC-LINE-PREFIX: <a href="https://repository.com/./src/Calculator.cpp#L7">7</a>
-// CALC-REPOSITORY-NEXT: of file
-// CALC-REPOSITORY-NEXT: <a href="https://repository.com/./src/Calculator.cpp">Calculator.cpp</a>
-
-// HTML-CALC: <div>brief</div>
-// HTML-CALC: <p> Subtracts the second integer from the first.</p>
-// HTML-CALC: <div>return</div>
-// HTML-CALC: <p> int The result of a - b.</p>
-// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">multiply</h3>
-// HTML-CALC: <p>public int multiply(int a, int b)</p>
-// CALC-NO-REPOSITORY: Defined at line 11 of file .{{.}}src{{.}}Calculator.cpp
-// CALC-REPOSITORY: Defined at line
-// CALC-REPOSITORY-NEXT: <a href="https://repository.com/./src/Calculator.cpp#11">11</a>
-// CALC-LINE-PREFIX: <a href="https://repository.com/./src/Calculator.cpp#L11">11</a>
-// CALC-REPOSITORY-NEXT: of file
-// CALC-REPOSITORY-NEXT: <a href="https://repository.com/./src/Calculator.cpp">Calculator.cpp</a>
-
-// HTML-CALC: <div>brief</div>
-// HTML-CALC: <p> Multiplies two integers.</p>
-// HTML-CALC: <div>return</div>
-// HTML-CALC: <p> int The product of a and b.</p>
-// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">divide</h3>
-// HTML-CALC: <p>public double divide(int a, int b)</p>
-// CALC-NO-REPOSITORY: Defined at line 15 of file .{{.}}src{{.}}Calculator.cpp
-// CALC-REPOSITORY: Defined at line
-// CALC-REPOSITORY-NEXT: <a href="https://repository.com/./src/Calculator.cpp#15">15</a>
-// CALC-LINE-PREFIX: <a href="https://repository.com/./src/Calculator.cpp#L15">15</a>
-// CALC-REPOSITORY-NEXT: of file
-// CALC-REPOSITORY-NEXT: <a href="https://repository.com/./src/Calculator.cpp">Calculator.cpp</a>
-
-// HTML-CALC: <div>brief</div>
-// HTML-CALC: <p> Divides the first integer by the second.</p>
-// HTML-CALC: <div>return</div>
-// HTML-CALC: <p> double The result of a / b.</p>
-// HTML-CALC: <div>throw</div>
-// HTML-CALC: <p>if b is zero.</p>
-
-// HTML-CALC: <p>public static int mod(int a, int b)</p>
-// CALC-NO-REPOSITORY: Defined at line 54 of file .{{.}}include{{.}}Calculator.h
-// CALC-REPOSITORY: Defined at line
-// CALC-REPOSITORY-NEXT: <a href="https://repository.com/./include/Calculator.h#54">54</a>
-// CALC-LINE-PREFIX: <a href="https://repository.com/./include/Calculator.h#L54">54</a>
-// CALC-REPOSITORY-NEXT: of file
-// CALC-REPOSITORY-NEXT: <a href="https://repository.com/./include/Calculator.h">Calculator.h</a>
-// HTML-CALC: <div>brief</div>
-// HTML-CALC: <p> Performs the mod operation on integers.</p>
-// HTML-CALC: <div>return</div>
-// HTML-CALC: <p> The result of a % b.</p>
-
-// HTML-RECTANGLE: <h1>class Rectangle</h1>
-// RECTANGLE-NO-REPOSITORY: <p>Defined at line 10 of file .{{.}}include{{.}}Rectangle.h</p>
-// RECTANGLE-REPOSITORY: <p>
-// RECTANGLE-REPOSITORY-NEXT: Defined at line
-// RECTANGLE-REPOSITORY-NEXT: <a href="https://repository.com/./include/Rectangle.h#10">10</a>
-// RECTANGLE-LINE-PREFIX: <a href="https://repository.com/./include/Rectangle.h#L10">10</a>
-// RECTANGLE-REPOSITORY-NEXT: of file
-// RECTANGLE-REPOSITORY-NEXT: <a href="https://repository.com/./include/Rectangle.h">Rectangle.h</a>
-// RECTANGLE-REPOSITORY-NEXT: </p>
-
-// HTML-RECTANGLE: <p> Represents a rectangle with a given width and height.</p>
-// HTML-RECTANGLE: <p>
-// HTML-RECTANGLE: Inherits from
-// HTML-RECTANGLE: <a href="Shape.html">Shape</a>
-// HTML-RECTANGLE: </p>
-// HTML-RECTANGLE: <h2 id="Members">Members</h2>
-// HTML-RECTANGLE: <p> Width of the rectangle.</p>
-// HTML-RECTANGLE: <div>private double width_</div>
-// HTML-RECTANGLE: <p> Height of the rectangle.</p>
-// HTML-RECTANGLE: <div>private double height_</div>
-// HTML-RECTANGLE: <h2 id="Functions">Functions</h2>
-// HTML-RECTANGLE: <h3 id="{{([0-9A-F]{40})}}">Rectangle</h3>
-// HTML-RECTANGLE: <p>public void Rectangle(double width, double height)</p>
-// RECTANGLE-NO-REPOSITORY: Defined at line 3 of file .{{.}}src{{.}}Rectangle.cpp
-// RECTANGLE-REPOSITORY: Defined at line
-// RECTANGLE-REPOSITORY-NEXT: <a href="https://repository.com/./src/Rectangle.cpp#3">3</a>
-// RECTANGLE-LINE-PREFIX: <a href="https://repository.com/./src/Rectangle.cpp#L3">3</a>
-// RECTANGLE-REPOSITORY-NEXT: of file
-// RECTANGLE-REPOSITORY-NEXT: <a href="https://repository.com/./src/Rectangle.cpp">Rectangle.cpp</a>
-
-// HTML-RECTANGLE: <div>brief</div>
-// HTML-RECTANGLE: <p> Constructs a new Rectangle object.</p>
-// HTML-RECTANGLE: <h3 id="{{([0-9A-F]{40})}}">area</h3>
-// HTML-RECTANGLE: <p>public double area()</p>
-// RECTANGLE-NO-REPOSITORY: Defined at line 6 of file .{{.}}src{{.}}Rectangle.cpp
-// RECTANGLE-REPOSITORY: Defined at line
-// RECTANGLE-REPOSITORY-NEXT: <a href="https://repository.com/./src/Rectangle.cpp#6">6</a>
-// RECTANGLE-LINE-PREFIX: <a href="https://repository.com/./src/Rectangle.cpp#L6">6</a>
-// RECTANGLE-REPOSITORY-NEXT: of file
-// RECTANGLE-REPOSITORY-NEXT: <a href="https://repository.com/./src/Rectangle.cpp">Rectangle.cpp</a>
-
-// HTML-RECTANGLE: <div>brief</div>
-// HTML-RECTANGLE: <p> Calculates the area of the rectangle.</p>
-// HTML-RECTANGLE: <div>return</div>
-// HTML-RECTANGLE: <p> double The area of the rectangle.</p>
-// HTML-RECTANGLE: <h3 id="{{([0-9A-F]{40})}}">perimeter</h3>
-// HTML-RECTANGLE: <p>public double perimeter()</p>
-// RECTANGLE-NO-REPOSITORY: Defined at line 10 of file .{{.}}src{{.}}Rectangle.cpp
-// RECTANGLE-REPOSITORY: Defined at line
-// RECTANGLE-REPOSITORY-NEXT: <a href="https://repository.com/./src/Rectangle.cpp#10">10</a>
-// RECTANGLE-LINE-PREFIX: <a href="https://repository.com/./src/Rectangle.cpp#L10">10</a>
-// RECTANGLE-REPOSITORY-NEXT: of file
-// RECTANGLE-REPOSITORY-NEXT: <a href="https://repository.com/./src/Rectangle.cpp">Rectangle.cpp</a>
-// HTML-RECTANGLE: <div>brief</div>
-// HTML-RECTANGLE: <p> Calculates the perimeter of the rectangle.</p>
-// HTML-RECTANGLE: <div>return</div>
-// HTML-RECTANGLE: <p> double The perimeter of the rectangle.</p>
-
-// HTML-CIRCLE: <h1>class Circle</h1>
-// CIRCLE-NO-REPOSITORY: <p>Defined at line 10 of file .{{.}}include{{.}}Circle.h</p>
-// CIRCLE-REPOSITORY: <p>
-// CIRCLE-REPOSITORY-NEXT: Defined at line
-// CIRCLE-REPOSITORY-NEXT: <a href="https://repository.com/./include/Circle.h#10">10</a>
-// CIRCLE-LINE-PREFIX: <a href="https://repository.com/./include/Circle.h#L10">10</a>
-// CIRCLE-REPOSITORY-NEXT: of file
-// CIRCLE-REPOSITORY-NEXT: <a href="https://repository.com/./include/Circle.h">Circle.h</a>
-// CIRCLE-REPOSITORY-NEXT: </p>
-
-// HTML-CIRCLE: <div>brief</div>
-// HTML-CIRCLE: <p> Circle class derived from Shape.</p>
-// HTML-CIRCLE: <p> Represents a circle with a given radius.</p>
-// HTML-CIRCLE: <p>
-// HTML-CIRCLE: Inherits from
-// HTML-CIRCLE: <a href="Shape.html">Shape</a>
-// HTML-CIRCLE: </p>
-// HTML-CIRCLE: <h2 id="Members">Members</h2>
-// HTML-CIRCLE: <p> Radius of the circle.</p>
-// HTML-CIRCLE: <div>private double radius_</div>
-// HTML-CIRCLE: <h2 id="Functions">Functions</h2>
-// HTML-CIRCLE: <h3 id="{{([0-9A-F]{40})}}">Circle</h3>
-// HTML-CIRCLE: <p>public void Circle(double radius)</p>
-// CIRCLE-NO-REPOSITORY: Defined at line 3 of file .{{.}}src{{.}}Circle.cpp
-// CIRCLE-REPOSITORY: Defined at line
-// CIRCLE-REPOSITORY-NEXT: <a href="https://repository.com/./src/Circle.cpp#3">3</a>
-// CIRCLE-LINE-PREFIX: <a href="https://repository.com/./src/Circle.cpp#L3">3</a>
-// CIRCLE-REPOSITORY-NEXT: of file
-// CIRCLE-REPOSITORY-NEXT: <a href="https://repository.com/./src/Circle.cpp">Circle.cpp</a>
-
-// HTML-CIRCLE: <div>brief</div>
-// HTML-CIRCLE: <p> Constructs a new Circle object.</p>
-// HTML-CIRCLE: <h3 id="{{([0-9A-F]{40})}}">area</h3>
-// HTML-CIRCLE: <p>public double area()</p>
-// CIRCLE-NO-REPOSITORY: Defined at line 5 of file .{{.}}src{{.}}Circle.cpp
-// CIRCLE-REPOSITORY: Defined at line
-// CIRCLE-REPOSITORY-NEXT: <a href="https://repository.com/./src/Circle.cpp#5">5</a>
-// CIRCLE-LINE-PREFIX: <a href="https://repository.com/./src/Circle.cpp#L5">5</a>
-// CIRCLE-REPOSITORY-NEXT: of file
-// CIRCLE-REPOSITORY-NEXT: <a href="https://repository.com/./src/Circle.cpp">Circle.cpp</a>
-
-// HTML-CIRCLE: <div>brief</div>
-// HTML-CIRCLE: <p> Calculates the area of the circle.</p>
-// HTML-CIRCLE: <div>return</div>
-// HTML-CIRCLE: <p> double The area of the circle.</p>
-// HTML-CIRCLE: <h3 id="{{([0-9A-F]{40})}}">perimeter</h3>
-// HTML-CIRCLE: <p>public double perimeter()</p>
-// CIRCLE-NO-REPOSITORY: Defined at line 9 of file .{{.}}src{{.}}Circle.cpp
-// CIRCLE-REPOSITORY: Defined at line
-// CIRCLE-REPOSITORY-NEXT: <a href="https://repository.com/./src/Circle.cpp#9">9</a>
-// CIRCLE-LINE-PREFIX: <a href="https://repository.com/./src/Circle.cpp#L9">9</a>
-// CIRCLE-REPOSITORY-NEXT: of file
-// CIRCLE-REPOSITORY-NEXT: <a href="https://repository.com/./src/Circle.cpp">Circle.cpp</a>
-
-// HTML-CIRCLE: <div>brief</div>
-// HTML-CIRCLE: <p> Calculates the perimeter of the circle.</p>
-// HTML-CIRCLE: <div>return</div>
-// HTML-CIRCLE: <p> double The perimeter of the circle.</p>
-
// MD-CALC: # class Calculator
// MD-CALC: *Defined at .{{[\/]}}include{{[\/]}}Calculator.h#8*
// MD-CALC: **brief** A simple calculator class.
diff --git a/clang-tools-extra/test/clang-doc/comments-in-macros.cpp b/clang-tools-extra/test/clang-doc/comments-in-macros.cpp
index 0c70fad..bc0ec46 100644
--- a/clang-tools-extra/test/clang-doc/comments-in-macros.cpp
+++ b/clang-tools-extra/test/clang-doc/comments-in-macros.cpp
@@ -6,8 +6,8 @@
// RUN: FileCheck %s < %t/GlobalNamespace/MyClass.md --check-prefix=MD-MYCLASS
// RUN: clang-doc --format=html --doxygen --output=%t --executor=standalone %s
-// RUN: FileCheck %s < %t/GlobalNamespace/MyClass.html --check-prefix=HTML-MYCLASS-LINE
-// RUN: FileCheck %s < %t/GlobalNamespace/MyClass.html --check-prefix=HTML-MYCLASS
+// RUN: FileCheck %s < %t/html/GlobalNamespace/_ZTV7MyClass.html --check-prefix=HTML-MYCLASS-LINE
+// RUN: FileCheck %s < %t/html/GlobalNamespace/_ZTV7MyClass.html --check-prefix=HTML-MYCLASS
#define DECLARE_METHODS \
/**
@@ -21,15 +21,18 @@
// MD-MYCLASS: *public int Add(int a, int b)*
// MD-MYCLASS: **brief** Declare a method to calculate the sum of two numbers
-// HTML-MYCLASS: <p>public int Add(int a, int b)</p>
-// HTML-MYCLASS: <div>brief</div>
-// HTML-MYCLASS: <p> Declare a method to calculate the sum of two numbers</p>
+
+// HTML-MYCLASS: <pre><code class="language-cpp code-clang-doc">int Add (int a, int b)</code></pre>
+// HTML-MYCLASS: <div>
+// HTML-MYCLASS: <div>
+// HTML-MYCLASS: <p> Declare a method to calculate the sum of two numbers</p>
+// HTML-MYCLASS: </div>
class MyClass {
public:
-// MD-MYCLASS-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}comments-in-macros.cpp#[[@LINE+2]]*
-// HTML-MYCLASS-LINE: <p>Defined at line [[@LINE+1]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}comments-in-macros.cpp</p>
+// MD-MYCLASS-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}comments-in-macros.cpp#[[@LINE-2]]*
+// HTML-MYCLASS-LINE: <p>Defined at line [[@LINE-3]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}comments-in-macros.cpp</p>
DECLARE_METHODS
};
diff --git a/clang-tools-extra/test/clang-doc/conversion_function.cpp b/clang-tools-extra/test/clang-doc/conversion_function.cpp
index 0200a57..63df5d6 100644
--- a/clang-tools-extra/test/clang-doc/conversion_function.cpp
+++ b/clang-tools-extra/test/clang-doc/conversion_function.cpp
@@ -4,7 +4,7 @@
// RUN: find %t/ -regex ".*/[0-9A-F]*.yaml" -exec cat {} ";" | FileCheck %s --check-prefix=CHECK-YAML
// RUN: clang-doc --format=html --output=%t --executor=standalone %s
-// RUN: FileCheck %s < %t/GlobalNamespace/MyStruct.html --check-prefix=CHECK-HTML
+// RUN: FileCheck %s < %t/html/GlobalNamespace/_ZTV8MyStruct.html --check-prefix=CHECK-HTML
template <typename T>
struct MyStruct {
@@ -14,5 +14,6 @@ struct MyStruct {
// Output correct conversion names.
// CHECK-YAML: Name: 'operator T'
-// CHECK-HTML: <h3 id="{{[0-9A-F]*}}">operator T</h3>
-// CHECK-HTML: <p>public T operator T()</p>
+// CHECK-HTML: <div id="{{([0-9A-F]{40})}}">
+// CHECK-HTML: <pre><code class="language-cpp code-clang-doc">T operator T ()</code></pre>
+// CHECK-HTML: </div>
diff --git a/clang-tools-extra/test/clang-doc/enum.cpp b/clang-tools-extra/test/clang-doc/enum.cpp
index b05d8e2..bb0d51f 100644
--- a/clang-tools-extra/test/clang-doc/enum.cpp
+++ b/clang-tools-extra/test/clang-doc/enum.cpp
@@ -1,12 +1,12 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --format=html --doxygen --output=%t --executor=standalone %s
// RUN: clang-doc --format=md --doxygen --output=%t --executor=standalone %s
-// RUN: FileCheck %s < %t/GlobalNamespace/index.html --check-prefix=HTML-INDEX-LINE
-// RUN: FileCheck %s < %t/GlobalNamespace/index.html --check-prefix=HTML-INDEX
-// RUN: FileCheck %s < %t/GlobalNamespace/Animals.html --check-prefix=HTML-ANIMAL-LINE
-// RUN: FileCheck %s < %t/GlobalNamespace/Animals.html --check-prefix=HTML-ANIMAL
-// RUN: FileCheck %s < %t/Vehicles/index.html --check-prefix=HTML-VEHICLES-LINE
-// RUN: FileCheck %s < %t/Vehicles/index.html --check-prefix=HTML-VEHICLES
+// RUN: FileCheck %s < %t/html/GlobalNamespace/index.html --check-prefix=HTML-INDEX-LINE
+// RUN: FileCheck %s < %t/html/GlobalNamespace/index.html --check-prefix=HTML-INDEX
+// RUN: FileCheck %s < %t/html/GlobalNamespace/_ZTV7Animals.html --check-prefix=HTML-ANIMAL-LINE
+// RUN: FileCheck %s < %t/html/GlobalNamespace/_ZTV7Animals.html --check-prefix=HTML-ANIMAL
+// RUN: FileCheck %s < %t/html/Vehicles/index.html --check-prefix=HTML-VEHICLES-LINE
+// RUN: FileCheck %s < %t/html/Vehicles/index.html --check-prefix=HTML-VEHICLES
// RUN: FileCheck %s < %t/GlobalNamespace/index.md --check-prefix=MD-INDEX-LINE
// RUN: FileCheck %s < %t/GlobalNamespace/index.md --check-prefix=MD-INDEX
// RUN: FileCheck %s < %t/GlobalNamespace/Animals.md --check-prefix=MD-ANIMAL-LINE
@@ -14,12 +14,14 @@
// RUN: FileCheck %s < %t/Vehicles/index.md --check-prefix=MD-VEHICLES-LINE
// RUN: FileCheck %s < %t/Vehicles/index.md --check-prefix=MD-VEHICLES
+// COM: FIXME: Add enum value comments to template
+
/**
* @brief For specifying RGB colors
*/
enum Color {
// MD-INDEX-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp#[[@LINE-1]]*
- // HTML-INDEX-LINE: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp</p>
+ // HTML-INDEX-LINE-NOT: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp</p>
Red, ///< Comment 1
Green, ///< Comment 2
Blue ///< Comment 3
@@ -33,23 +35,36 @@ enum Color {
// MD-INDEX: | Blue |
// MD-INDEX: **brief** For specifying RGB colors
-// HTML-INDEX: <th colspan="3">enum Color</th>
-// HTML-INDEX: <td>Red</td>
-// HTML-INDEX: <td>0</td>
-// HTML-INDEX: <p> Comment 1</p>
-// HTML-INDEX: <td>Green</td>
-// HTML-INDEX: <td>1</td>
-// HTML-INDEX: <p> Comment 2</p>
-// HTML-INDEX: <td>Blue</td>
-// HTML-INDEX: <td>2</td>
-// HTML-INDEX: <p> Comment 3</p>
+// HTML-INDEX: <div>
+// HTML-INDEX: <pre><code class="language-cpp code-clang-doc">enum Color</code></pre>
+// HTML-INDEX: </div>
+// HTML-INDEX: <table class="table-wrapper">
+// HTML-INDEX: <tbody>
+// HTML-INDEX: <tr>
+// HTML-INDEX: <th>Name</th>
+// HTML-INDEX: <th>Value</th>
+// HTML-INDEX: </tr>
+// HTML-INDEX: <tr>
+// HTML-INDEX: <td>Red</td>
+// HTML-INDEX: <td>0</td>
+// HTML-INDEX: </tr>
+// HTML-INDEX: <tr>
+// HTML-INDEX: <td>Green</td>
+// HTML-INDEX: <td>1</td>
+// HTML-INDEX: </tr>
+// HTML-INDEX: <tr>
+// HTML-INDEX: <td>Blue</td>
+// HTML-INDEX: <td>2</td>
+// HTML-INDEX: </tr>
+// HTML-INDEX: </tbody>
+// HTML-INDEX: </table>
/**
* @brief Shape Types
*/
enum class Shapes {
// MD-INDEX-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp#[[@LINE-1]]*
- // HTML-INDEX-LINE: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp</p>
+ // HTML-INDEX-LINE-NOT: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp</p>
/// Comment 1
Circle,
@@ -65,17 +80,32 @@ enum class Shapes {
// MD-INDEX: | Triangle |
// MD-INDEX: **brief** Shape Types
-// HTML-INDEX: <th colspan="3">enum class Shapes</th>
-// HTML-INDEX: <td>Circle</td>
-// HTML-INDEX: <td>0</td>
-// HTML-INDEX: <p> Comment 1</p>
-// HTML-INDEX: <td>Rectangle</td>
-// HTML-INDEX: <td>1</td>
-// HTML-INDEX: <p> Comment 2</p>
-// HTML-INDEX: <td>Triangle</td>
-// HTML-INDEX: <td>2</td>
-// HTML-INDEX: <p> Comment 3</p>
-
+// COM: FIXME: Serialize "enum class" in template
+// HTML-INDEX: <div>
+// HTML-INDEX: <pre><code class="language-cpp code-clang-doc">enum Shapes</code></pre>
+// HTML-INDEX: </div>
+// HTML-INDEX: <table class="table-wrapper">
+// HTML-INDEX: <tbody>
+// HTML-INDEX: <tr>
+// HTML-INDEX: <th>Name</th>
+// HTML-INDEX: <th>Value</th>
+// HTML-INDEX: </tr>
+// HTML-INDEX: <tr>
+// HTML-INDEX: <td>Circle</td>
+// HTML-INDEX: <td>0</td>
+// HTML-INDEX: </tr>
+// HTML-INDEX: <tr>
+// HTML-INDEX: <td>Rectangle</td>
+// HTML-INDEX: <td>1</td>
+// HTML-INDEX: </tr>
+// HTML-INDEX: <tr>
+// HTML-INDEX: <td>Triangle</td>
+// HTML-INDEX: <td>2</td>
+// HTML-INDEX: </tr>
+// HTML-INDEX: </tbody>
+// HTML-INDEX: </table>
+
+// COM: FIXME: Add enums declared inside of classes to class template
class Animals {
// MD-ANIMAL-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp#[[@LINE-1]]*
// HTML-ANIMAL-LINE: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp</p>
@@ -85,25 +115,25 @@ public:
*/
enum AnimalType {
// MD-ANIMAL-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp#[[@LINE-1]]*
- // HTML-ANIMAL-LINE: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp</p>
+ // HTML-ANIMAL-LINE-NOT: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp</p>
Dog, ///< Man's best friend
Cat, ///< Man's other best friend
Iguana ///< A lizard
};
};
-// HTML-ANIMAL: <h1>class Animals</h1>
-// HTML-ANIMAL: <h2 id="Enums">Enums</h2>
-// HTML-ANIMAL: <th colspan="3">enum AnimalType</th>
-// HTML-ANIMAL: <td>Dog</td>
-// HTML-ANIMAL: <td>0</td>
-// HTML-ANIMAL: <p> Man&apos;s best friend</p>
-// HTML-ANIMAL: <td>Cat</td>
-// HTML-ANIMAL: <td>1</td>
-// HTML-ANIMAL: <p> Man&apos;s other best friend</p>
-// HTML-ANIMAL: <td>Iguana</td>
-// HTML-ANIMAL: <td>2</td>
-// HTML-ANIMAL: <p> A lizard</p>
+// HTML-ANIMAL-NOT: <h1>class Animals</h1>
+// HTML-ANIMAL-NOT: <h2 id="Enums">Enums</h2>
+// HTML-ANIMAL-NOT: <th colspan="3">enum AnimalType</th>
+// HTML-ANIMAL-NOT: <td>Dog</td>
+// HTML-ANIMAL-NOT: <td>0</td>
+// HTML-ANIMAL-NOT: <p> Man&apos;s best friend</p>
+// HTML-ANIMAL-NOT: <td>Cat</td>
+// HTML-ANIMAL-NOT: <td>1</td>
+// HTML-ANIMAL-NOT: <p> Man&apos;s other best friend</p>
+// HTML-ANIMAL-NOT: <td>Iguana</td>
+// HTML-ANIMAL-NOT: <td>2</td>
+// HTML-ANIMAL-NOT: <p> A lizard</p>
// MD-ANIMAL: # class Animals
// MD-ANIMAL: ## Enums
@@ -120,7 +150,7 @@ namespace Vehicles {
*/
enum Car {
// MD-VEHICLES-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp#[[@LINE-1]]*
- // HTML-VEHICLES-LINE: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp</p>
+ // HTML-VEHICLES-LINE: Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp
Sedan, ///< Comment 1
SUV, ///< Comment 2
@@ -139,20 +169,33 @@ enum Car {
// MD-VEHICLES: | Hatchback |
// MD-VEHICLES: **brief** specify type of car
-// HTML-VEHICLES: <h1>namespace Vehicles</h1>
-// HTML-VEHICLES: <th colspan="3">enum Car</th>
-// HTML-VEHICLES: <td>Sedan</td>
-// HTML-VEHICLES: <td>0</td>
-// HTML-VEHICLES: <p> Comment 1</p>
-// HTML-VEHICLES: <td>SUV</td>
-// HTML-VEHICLES: <td>1</td>
-// HTML-VEHICLES: <p> Comment 2</p>
-// HTML-VEHICLES: <td>Pickup</td>
-// HTML-VEHICLES: <td>2</td>
-// HTML-VEHICLES: <p> Comment 3</p>
-// HTML-VEHICLES: <td>Hatchback</td>
-// HTML-VEHICLES: <td>3</td>
-// HTML-VEHICLES: <p> Comment 4</p>
+// HTML-VEHICLES: <div>
+// HTML-VEHICLES: <pre><code class="language-cpp code-clang-doc">enum Car</code></pre>
+// HTML-VEHICLES: </div>
+// HTML-VEHICLES: <table class="table-wrapper">
+// HTML-VEHICLES: <tbody>
+// HTML-VEHICLES: <tr>
+// HTML-VEHICLES: <th>Name</th>
+// HTML-VEHICLES: <th>Value</th>
+// HTML-VEHICLES: </tr>
+// HTML-VEHICLES: <tr>
+// HTML-VEHICLES: <td>Sedan</td>
+// HTML-VEHICLES: <td>0</td>
+// HTML-VEHICLES: </tr>
+// HTML-VEHICLES: <tr>
+// HTML-VEHICLES: <td>SUV</td>
+// HTML-VEHICLES: <td>1</td>
+// HTML-VEHICLES: </tr>
+// HTML-VEHICLES: <tr>
+// HTML-VEHICLES: <td>Pickup</td>
+// HTML-VEHICLES: <td>2</td>
+// HTML-VEHICLES: </tr>
+// HTML-VEHICLES: <tr>
+// HTML-VEHICLES: <td>Hatchback</td>
+// HTML-VEHICLES: <td>3</td>
+// HTML-VEHICLES: </tr>
+// HTML-VEHICLES: </tbody>
+// HTML-VEHICLES: </table>
enum ColorUserSpecified {
RedUserSpecified = 'A',
@@ -166,10 +209,26 @@ enum ColorUserSpecified {
// MD-INDEX: | GreenUserSpecified |
// MD-INDEX: | BlueUserSpecified |
-// HTML-INDEX: <th colspan="2">enum ColorUserSpecified</th>
-// HTML-INDEX: <td>RedUserSpecified</td>
-// HTML-INDEX: <td>&apos;A&apos;</td>
-// HTML-INDEX: <td>GreenUserSpecified</td>
-// HTML-INDEX: <td>2</td>
-// HTML-INDEX: <td>BlueUserSpecified</td>
-// HTML-INDEX: <td>&apos;C&apos;</td>
+// HTML-INDEX: <div>
+// HTML-INDEX: <pre><code class="language-cpp code-clang-doc">enum ColorUserSpecified</code></pre>
+// HTML-INDEX: </div>
+// HTML-INDEX: <table class="table-wrapper">
+// HTML-INDEX: <tbody>
+// HTML-INDEX: <tr>
+// HTML-INDEX: <th>Name</th>
+// HTML-INDEX: <th>Value</th>
+// HTML-INDEX: </tr>
+// HTML-INDEX: <tr>
+// HTML-INDEX: <td>RedUserSpecified</td>
+// HTML-INDEX: <td>&#39;A&#39;</td>
+// HTML-INDEX: </tr>
+// HTML-INDEX: <tr>
+// HTML-INDEX: <td>GreenUserSpecified</td>
+// HTML-INDEX: <td>2</td>
+// HTML-INDEX: </tr>
+// HTML-INDEX: <tr>
+// HTML-INDEX: <td>BlueUserSpecified</td>
+// HTML-INDEX: <td>&#39;C&#39;</td>
+// HTML-INDEX: </tr>
+// HTML-INDEX: </tbody>
+// HTML-INDEX: </table>
diff --git a/clang-tools-extra/test/clang-doc/json/class-requires.cpp b/clang-tools-extra/test/clang-doc/json/class-requires.cpp
index 5139617..4e5ec3a 100644
--- a/clang-tools-extra/test/clang-doc/json/class-requires.cpp
+++ b/clang-tools-extra/test/clang-doc/json/class-requires.cpp
@@ -1,6 +1,6 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --extra-arg -std=c++20 --output=%t --format=json --executor=standalone %s
-// RUN: FileCheck %s < %t/json/_ZTV7MyClass.json
+// RUN: FileCheck %s < %t/json/GlobalNamespace/_ZTV7MyClass.json
template<typename T>
concept Addable = requires(T a, T b) {
diff --git a/clang-tools-extra/test/clang-doc/json/class-specialization.cpp b/clang-tools-extra/test/clang-doc/json/class-specialization.cpp
index d3ad695..60f3b44 100644
--- a/clang-tools-extra/test/clang-doc/json/class-specialization.cpp
+++ b/clang-tools-extra/test/clang-doc/json/class-specialization.cpp
@@ -1,7 +1,7 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
-// RUN: FileCheck %s < %t/json/_ZTV7MyClass.json --check-prefix=BASE
-// RUN: FileCheck %s < %t/json/_ZTV7MyClassIiE.json --check-prefix=SPECIALIZATION
+// RUN: FileCheck %s < %t/json/GlobalNamespace/_ZTV7MyClass.json --check-prefix=BASE
+// RUN: FileCheck %s < %t/json/GlobalNamespace/_ZTV7MyClassIiE.json --check-prefix=SPECIALIZATION
template<typename T> struct MyClass {};
diff --git a/clang-tools-extra/test/clang-doc/json/class-template.cpp b/clang-tools-extra/test/clang-doc/json/class-template.cpp
index 5ef78f54..de52064 100644
--- a/clang-tools-extra/test/clang-doc/json/class-template.cpp
+++ b/clang-tools-extra/test/clang-doc/json/class-template.cpp
@@ -1,6 +1,6 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
-// RUN: FileCheck %s < %t/json/_ZTV7MyClass.json
+// RUN: FileCheck %s < %t/json/GlobalNamespace/_ZTV7MyClass.json
template<typename T> struct MyClass {
T MemberTemplate;
diff --git a/clang-tools-extra/test/clang-doc/json/class.cpp b/clang-tools-extra/test/clang-doc/json/class.cpp
index 20a9f21..8bf9402 100644
--- a/clang-tools-extra/test/clang-doc/json/class.cpp
+++ b/clang-tools-extra/test/clang-doc/json/class.cpp
@@ -1,6 +1,6 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
-// RUN: FileCheck %s < %t/json/_ZTV7MyClass.json
+// RUN: FileCheck %s < %t/json/GlobalNamespace/_ZTV7MyClass.json
struct Foo;
@@ -47,9 +47,6 @@ protected:
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "TextComment": " It has some nice methods and fields."
-// CHECK-NEXT: },
-// CHECK-NEXT: {
-// CHECK-NEXT: "TextComment": ""
// CHECK-NEXT: }
// CHECK: "DocumentationFileName": "_ZTV7MyClass",
// CHECK: "Enums": [
@@ -124,8 +121,6 @@ protected:
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: ],
-// COM: FIXME: FullName is not emitted correctly.
-// CHECK-NEXT: "FullName": "",
// CHECK-NEXT: "HasEnums": true,
// CHECK-NEXT: "HasPublicFunctions": true,
// CHECK-NEXT: "HasPublicMembers": true,
diff --git a/clang-tools-extra/test/clang-doc/json/compound-constraints.cpp b/clang-tools-extra/test/clang-doc/json/compound-constraints.cpp
index 1a73a0d..5b15a88 100644
--- a/clang-tools-extra/test/clang-doc/json/compound-constraints.cpp
+++ b/clang-tools-extra/test/clang-doc/json/compound-constraints.cpp
@@ -1,6 +1,6 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --extra-arg -std=c++20 --output=%t --format=json --executor=standalone %s
-// RUN: FileCheck %s < %t/json/index.json
+// RUN: FileCheck %s < %t/json/GlobalNamespace/index.json
template<typename T> concept Incrementable = requires (T a) {
a++;
diff --git a/clang-tools-extra/test/clang-doc/json/concept.cpp b/clang-tools-extra/test/clang-doc/json/concept.cpp
index e96ec14..5d8c47e 100644
--- a/clang-tools-extra/test/clang-doc/json/concept.cpp
+++ b/clang-tools-extra/test/clang-doc/json/concept.cpp
@@ -1,6 +1,6 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --extra-arg -std=c++20 --output=%t --format=json --executor=standalone %s
-// RUN: FileCheck %s < %t/json/index.json
+// RUN: FileCheck %s < %t/json/GlobalNamespace/index.json
// Requires that T suports post and pre-incrementing.
template<typename T>
diff --git a/clang-tools-extra/test/clang-doc/json/function-requires.cpp b/clang-tools-extra/test/clang-doc/json/function-requires.cpp
index 9427146..8ba6adc 100644
--- a/clang-tools-extra/test/clang-doc/json/function-requires.cpp
+++ b/clang-tools-extra/test/clang-doc/json/function-requires.cpp
@@ -1,6 +1,6 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --extra-arg -std=c++20 --output=%t --format=json --executor=standalone %s
-// RUN: FileCheck %s < %t/json/index.json
+// RUN: FileCheck %s < %t/json/GlobalNamespace/index.json
template<typename T>
concept Incrementable = requires(T x) {
diff --git a/clang-tools-extra/test/clang-doc/json/function-specifiers.cpp b/clang-tools-extra/test/clang-doc/json/function-specifiers.cpp
index faaccb7..6630d9e 100644
--- a/clang-tools-extra/test/clang-doc/json/function-specifiers.cpp
+++ b/clang-tools-extra/test/clang-doc/json/function-specifiers.cpp
@@ -1,6 +1,6 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
-// RUN: FileCheck %s < %t/json/index.json
+// RUN: FileCheck %s < %t/json/GlobalNamespace/index.json
static void myFunction() {}
diff --git a/clang-tools-extra/test/clang-doc/json/method-template.cpp b/clang-tools-extra/test/clang-doc/json/method-template.cpp
index 87977f8..f4885d9 100644
--- a/clang-tools-extra/test/clang-doc/json/method-template.cpp
+++ b/clang-tools-extra/test/clang-doc/json/method-template.cpp
@@ -1,6 +1,6 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
-// RUN: FileCheck %s < %t/json/_ZTV7MyClass.json
+// RUN: FileCheck %s < %t/json/GlobalNamespace/_ZTV7MyClass.json
struct MyClass {
template<class T> T methodTemplate(T param) {
diff --git a/clang-tools-extra/test/clang-doc/json/multiple-namespaces.cpp b/clang-tools-extra/test/clang-doc/json/multiple-namespaces.cpp
index 04fcfc1..6926998 100644
--- a/clang-tools-extra/test/clang-doc/json/multiple-namespaces.cpp
+++ b/clang-tools-extra/test/clang-doc/json/multiple-namespaces.cpp
@@ -1,7 +1,7 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
-// RUN: FileCheck %s < %t/json/foo_tools.json --check-prefix=CHECK-FOO
-// RUN: FileCheck %s < %t/json/bar_tools.json --check-prefix=CHECK-BAR
+// RUN: FileCheck %s < %t/json/foo/tools/index.json --check-prefix=CHECK-FOO
+// RUN: FileCheck %s < %t/json/bar/tools/index.json --check-prefix=CHECK-BAR
namespace foo {
namespace tools {
diff --git a/clang-tools-extra/test/clang-doc/json/namespace.cpp b/clang-tools-extra/test/clang-doc/json/namespace.cpp
index dcf8323..dd7a9af 100644
--- a/clang-tools-extra/test/clang-doc/json/namespace.cpp
+++ b/clang-tools-extra/test/clang-doc/json/namespace.cpp
@@ -1,6 +1,6 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
-// RUN: FileCheck %s < %t/json/index.json
+// RUN: FileCheck %s < %t/json/GlobalNamespace/index.json
class MyClass {};
diff --git a/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp b/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp
index cf19e1e..5baca7f 100644
--- a/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp
+++ b/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp
@@ -1,7 +1,7 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
-// RUN: FileCheck %s < %t/json/nested.json --check-prefix=NESTED
-// RUN: FileCheck %s < %t/json/nested_inner.json --check-prefix=INNER
+// RUN: FileCheck %s < %t/json/nested/index.json --check-prefix=NESTED
+// RUN: FileCheck %s < %t/json/nested/inner/index.json --check-prefix=INNER
namespace nested {
int Global;
diff --git a/clang-tools-extra/test/clang-doc/long-name.cpp b/clang-tools-extra/test/clang-doc/long-name.cpp
index e29c468..e4a5e29 100644
--- a/clang-tools-extra/test/clang-doc/long-name.cpp
+++ b/clang-tools-extra/test/clang-doc/long-name.cpp
@@ -1,9 +1,9 @@
// FIXME: This test seems to break on windows, so disable it for now.
// UNSUPPORTED: system-windows
// RUN: rm -rf %t && mkdir -p %t
-// RUN: clang-doc --output=%t --format=mustache --executor=standalone %s
-// RUN: ls %t/json | FileCheck %s -check-prefix=CHECK-JSON
-// RUN: ls %t/html | FileCheck %s -check-prefix=CHECK-HTML
+// RUN: clang-doc --output=%t --format=html --executor=standalone %s
+// RUN: ls %t/json/GlobalNamespace | FileCheck %s -check-prefix=CHECK-JSON
+// RUN: ls %t/html/GlobalNamespace | FileCheck %s -check-prefix=CHECK-HTML
struct ThisStructHasANameThatResultsInAMangledNameThatIsExactly250CharactersLongThatIsSupposedToTestTheFilenameLengthLimitsWithinClangDocInOrdertoSeeifclangdocwillcrashornotdependingonthelengthofthestructIfTheLengthIsTooLongThenClangDocWillCrashAnd12 {};
diff --git a/clang-tools-extra/test/clang-doc/mustache-index.cpp b/clang-tools-extra/test/clang-doc/mustache-index.cpp
index f9aad19..0aa6e21 100644
--- a/clang-tools-extra/test/clang-doc/mustache-index.cpp
+++ b/clang-tools-extra/test/clang-doc/mustache-index.cpp
@@ -1,6 +1,6 @@
// RUN: rm -rf %t && mkdir -p %t
-// RUN: clang-doc --format=mustache --output=%t --executor=standalone %s
-// RUN: FileCheck %s < %t/html/index.html
+// RUN: clang-doc --format=html --output=%t --executor=standalone %s
+// RUN: FileCheck %s < %t/html/GlobalNamespace/index.html
enum Color {
RED,
@@ -13,49 +13,47 @@ class Foo;
// CHECK: <li class="sidebar-section">
// CHECK-NEXT: <a class="sidebar-item" href="#Enums">Enums</a>
// CHECK-NEXT: </li>
-// CHECK-NEXT: <ul>
-// CHECK-NEXT: <li class="sidebar-item-container">
-// CHECK-NEXT: <a class="sidebar-item" href="#{{[0-9A-F]*}}">Color</a>
-// CHECK-NEXT: </li>
-// CHECK-NEXT: </ul>
+// CHECK-NEXT: <li>
+// CHECK-NEXT: <ul>
+// CHECK-NEXT: <li class="sidebar-item-container">
+// CHECK-NEXT: <a class="sidebar-item" href="#{{[0-9A-F]*}}">Color</a>
+// CHECK-NEXT: </li>
+// CHECK-NEXT: </ul>
// CHECK: <li class="sidebar-section">
// CHECK-NEXT: <a class="sidebar-item" href="#Classes">Inner Classes</a>
// CHECK-NEXT: </li>
-// CHECK-NEXT: <ul>
-// CHECK-NEXT: <li class="sidebar-item-container">
-// CHECK-NEXT: <a class="sidebar-item" href="#{{[0-9A-F]*}}">Foo</a>
-// CHECK-NEXT: </li>
-// CHECK-NEXT: </ul>
+// CHECK-NEXT: <li>
+// CHECK-NEXT: <ul>
+// CHECK-NEXT: <li class="sidebar-item-container">
+// CHECK-NEXT: <a class="sidebar-item" href="#{{[0-9A-F]*}}">Foo</a>
+// CHECK-NEXT: </li>
+// CHECK-NEXT: </ul>
// CHECK: <section id="Enums" class="section-container">
// CHECK-NEXT: <h2>Enumerations</h2>
// CHECK-NEXT: <div>
// CHECK-NEXT: <div id="{{[0-9A-F]*}}" class="delimiter-container">
// CHECK-NEXT: <div>
-// CHECK-NEXT: <pre>
-// CHECK-NEXT: <code class="language-cpp code-clang-doc">
-// CHECK-NEXT: enum Color
-// CHECK-NEXT: </code>
-// CHECK-NEXT: </pre>
+// CHECK-NEXT: <pre><code class="language-cpp code-clang-doc">enum Color</code></pre>
// CHECK-NEXT: </div>
// CHECK-NEXT: <table class="table-wrapper">
// CHECK-NEXT: <tbody>
-// CHECK-NEXT: <tr>
-// CHECK-NEXT: <th>Name</th>
-// CHECK-NEXT: <th>Value</th>
-// CHECK: </tr>
+// CHECK-NEXT: <tr>
+// CHECK-NEXT: <th>Name</th>
+// CHECK-NEXT: <th>Value</th>
+// CHECK-NEXT: </tr>
// CHECK-NEXT: <tr>
// CHECK-NEXT: <td>RED</td>
// CHECK-NEXT: <td>0</td>
-// CHECK: </tr>
+// CHECK-NEXT: </tr>
// CHECK-NEXT: <tr>
// CHECK-NEXT: <td>BLUE</td>
// CHECK-NEXT: <td>1</td>
-// CHECK: </tr>
+// CHECK-NEXT: </tr>
// CHECK-NEXT: <tr>
// CHECK-NEXT: <td>GREEN</td>
// CHECK-NEXT: <td>2</td>
-// CHECK: </tr>
+// CHECK-NEXT: </tr>
// CHECK-NEXT: </tbody>
// CHECK-NEXT: </table>
// CHECK-NEXT: <div>
@@ -70,9 +68,7 @@ class Foo;
// CHECK-NEXT: <ul class="class-container">
// CHECK-NEXT: <li id="{{[0-9A-F]*}}" style="max-height: 40px;">
// CHECK-NEXT: <a href="_ZTV3Foo.html">
-// CHECK-NEXT: <pre>
-// CHECK-NEXT: <code class="language-cpp code-clang-doc">class Foo</code>
-// CHECK-NEXT: </pre>
+// CHECK-NEXT: <pre><code class="language-cpp code-clang-doc">class Foo</code></pre>
// CHECK-NEXT: </a>
// CHECK-NEXT: </li>
// CHECK-NEXT: </ul>
diff --git a/clang-tools-extra/test/clang-doc/mustache-separate-namespace.cpp b/clang-tools-extra/test/clang-doc/mustache-separate-namespace.cpp
index a73a5ab..add8a22 100644
--- a/clang-tools-extra/test/clang-doc/mustache-separate-namespace.cpp
+++ b/clang-tools-extra/test/clang-doc/mustache-separate-namespace.cpp
@@ -1,6 +1,7 @@
// RUN: rm -rf %t && mkdir -p %t
-// RUN: clang-doc --format=mustache --output=%t --executor=standalone %s
-// RUN: FileCheck %s < %t/html/MyNamespace.html
+// RUN: clang-doc --format=html --output=%t --executor=standalone %s
+// RUN: FileCheck %s < %t/html/MyNamespace/index.html
+// RUN: FileCheck %s < %t/html/GlobalNamespace/index.html --check-prefix=CHECK-GLOBAL
namespace MyNamespace {
class Foo;
@@ -9,9 +10,22 @@ namespace MyNamespace {
// CHECK: <ul class="class-container">
// CHECK-NEXT: <li id="{{[0-9A-F]*}}" style="max-height: 40px;">
// CHECK-NEXT: <a href="_ZTVN11MyNamespace3FooE.html">
-// CHECK-NEXT: <pre>
-// CHECK-NEXT: <code class="language-cpp code-clang-doc">class Foo</code>
-// CHECK-NEXT: </pre>
+// CHECK-NEXT: <pre><code class="language-cpp code-clang-doc">class Foo</code></pre>
// CHECK-NEXT: </a>
// CHECK-NEXT: </li>
// CHECK-NEXT: </ul>
+
+// COM: Check that the empty global namespace doesn't contain tag mismatches.
+// CHECK-GLOBAL: <main>
+// CHECK-GLOBAL-NEXT: <div class="container">
+// CHECK-GLOBAL-NEXT: <div class="sidebar">
+// CHECK-GLOBAL-NEXT: <h2> </h2>
+// CHECK-GLOBAL-NEXT: <ul>
+// CHECK-GLOBAL-NEXT: </ul>
+// CHECK-GLOBAL-NEXT: </div>
+// CHECK-GLOBAL-NEXT: <div class="resizer" id="resizer"></div>
+// CHECK-GLOBAL-NEXT: <div class="content">
+// CHECK-GLOBAL-EMPTY:
+// CHECK-GLOBAL-NEXT: </div>
+// CHECK-GLOBAL-NEXT: </div>
+// CHECK-GLOBAL-NEXT: </main>
diff --git a/clang-tools-extra/test/clang-doc/namespace.cpp b/clang-tools-extra/test/clang-doc/namespace.cpp
index 4fa11c7..029f997 100644
--- a/clang-tools-extra/test/clang-doc/namespace.cpp
+++ b/clang-tools-extra/test/clang-doc/namespace.cpp
@@ -1,23 +1,6 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --format=html --output=%t --executor=standalone %s
// RUN: clang-doc --format=md --output=%t --executor=standalone %s
-// RUN: FileCheck %s < %t/index_json.js -check-prefix=JSON-INDEX
-// RUN: FileCheck %s < %t/@nonymous_namespace/AnonClass.html -check-prefix=HTML-ANON-CLASS-LINE
-// RUN: FileCheck %s < %t/@nonymous_namespace/AnonClass.html -check-prefix=HTML-ANON-CLASS
-// RUN: FileCheck %s < %t/@nonymous_namespace/index.html -check-prefix=HTML-ANON-INDEX-LINE
-// RUN: FileCheck %s < %t/@nonymous_namespace/index.html -check-prefix=HTML-ANON-INDEX
-// RUN: FileCheck %s < %t/AnotherNamespace/ClassInAnotherNamespace.html -check-prefix=HTML-ANOTHER-CLASS-LINE
-// RUN: FileCheck %s < %t/AnotherNamespace/ClassInAnotherNamespace.html -check-prefix=HTML-ANOTHER-CLASS
-// RUN: FileCheck %s < %t/AnotherNamespace/index.html -check-prefix=HTML-ANOTHER-INDEX-LINE
-// RUN: FileCheck %s < %t/AnotherNamespace/index.html -check-prefix=HTML-ANOTHER-INDEX
-// RUN: FileCheck %s < %t/PrimaryNamespace/NestedNamespace/ClassInNestedNamespace.html -check-prefix=HTML-NESTED-CLASS-LINE
-// RUN: FileCheck %s < %t/PrimaryNamespace/NestedNamespace/ClassInNestedNamespace.html -check-prefix=HTML-NESTED-CLASS
-// RUN: FileCheck %s < %t/PrimaryNamespace/NestedNamespace/index.html -check-prefix=HTML-NESTED-INDEX-LINE
-// RUN: FileCheck %s < %t/PrimaryNamespace/NestedNamespace/index.html -check-prefix=HTML-NESTED-INDEX
-// RUN: FileCheck %s < %t/PrimaryNamespace/index.html -check-prefix=HTML-PRIMARY-INDEX-LINE
-// RUN: FileCheck %s < %t/PrimaryNamespace/index.html -check-prefix=HTML-PRIMARY-INDEX
-// RUN: FileCheck %s < %t/PrimaryNamespace/ClassInPrimaryNamespace.html -check-prefix=HTML-PRIMARY-CLASS-LINE
-// RUN: FileCheck %s < %t/PrimaryNamespace/ClassInPrimaryNamespace.html -check-prefix=HTML-PRIMARY-CLASS
// RUN: FileCheck %s < %t/@nonymous_namespace/AnonClass.md -check-prefix=MD-ANON-CLASS-LINE
// RUN: FileCheck %s < %t/@nonymous_namespace/AnonClass.md -check-prefix=MD-ANON-CLASS
// RUN: FileCheck %s < %t/@nonymous_namespace/index.md -check-prefix=MD-ANON-INDEX-LINE
@@ -34,23 +17,42 @@
// RUN: FileCheck %s < %t/PrimaryNamespace/index.md -check-prefix=MD-PRIMARY-INDEX
// RUN: FileCheck %s < %t/PrimaryNamespace/ClassInPrimaryNamespace.md -check-prefix=MD-PRIMARY-CLASS-LINE
// RUN: FileCheck %s < %t/PrimaryNamespace/ClassInPrimaryNamespace.md -check-prefix=MD-PRIMARY-CLASS
-// RUN: FileCheck %s < %t/GlobalNamespace/index.html -check-prefix=HTML-GLOBAL-INDEX
+// RUN: FileCheck %s < %t/html/GlobalNamespace/index.html -check-prefix=HTML-GLOBAL-INDEX
// RUN: FileCheck %s < %t/GlobalNamespace/index.md -check-prefix=MD-GLOBAL-INDEX
// RUN: FileCheck %s < %t/all_files.md -check-prefix=MD-ALL-FILES
// RUN: FileCheck %s < %t/index.md -check-prefix=MD-INDEX
+// RUN: FileCheck %s < %t/html/@nonymous_namespace/_ZTVN12_GLOBAL__N_19AnonClassE.html -check-prefix=HTML-ANON-CLASS-LINE
+// RUN: FileCheck %s < %t/html/@nonymous_namespace/_ZTVN12_GLOBAL__N_19AnonClassE.html -check-prefix=HTML-ANON-CLASS
+// RUN: FileCheck %s < %t/html/@nonymous_namespace/index.html -check-prefix=HTML-ANON-INDEX-LINE
+// RUN: FileCheck %s < %t/html/@nonymous_namespace/index.html -check-prefix=HTML-ANON-INDEX
+// RUN: FileCheck %s < %t/html/AnotherNamespace/_ZTVN16AnotherNamespace23ClassInAnotherNamespaceE.html -check-prefix=HTML-ANOTHER-CLASS-LINE
+// RUN: FileCheck %s < %t/html/AnotherNamespace/_ZTVN16AnotherNamespace23ClassInAnotherNamespaceE.html -check-prefix=HTML-ANOTHER-CLASS
+// RUN: FileCheck %s < %t/html/AnotherNamespace/index.html -check-prefix=HTML-ANOTHER-INDEX-LINE
+// RUN: FileCheck %s < %t/html/AnotherNamespace/index.html -check-prefix=HTML-ANOTHER-INDEX
+// RUN: FileCheck %s < %t/html/PrimaryNamespace/NestedNamespace/_ZTVN16PrimaryNamespace15NestedNamespace22ClassInNestedNamespaceE.html -check-prefix=HTML-NESTED-CLASS-LINE
+// RUN: FileCheck %s < %t/html/PrimaryNamespace/NestedNamespace/_ZTVN16PrimaryNamespace15NestedNamespace22ClassInNestedNamespaceE.html -check-prefix=HTML-NESTED-CLASS
+// RUN: FileCheck %s < %t/html/PrimaryNamespace/NestedNamespace/index.html -check-prefix=HTML-NESTED-INDEX-LINE
+// RUN: FileCheck %s < %t/html/PrimaryNamespace/NestedNamespace/index.html -check-prefix=HTML-NESTED-INDEX
+// RUN: FileCheck %s < %t/html/PrimaryNamespace/index.html -check-prefix=HTML-PRIMARY-INDEX-LINE
+// RUN: FileCheck %s < %t/html/PrimaryNamespace/index.html -check-prefix=HTML-PRIMARY-INDEX
+// RUN: FileCheck %s < %t/html/PrimaryNamespace/_ZTVN16PrimaryNamespace23ClassInPrimaryNamespaceE.html -check-prefix=HTML-PRIMARY-CLASS-LINE
+// RUN: FileCheck %s < %t/html/PrimaryNamespace/_ZTVN16PrimaryNamespace23ClassInPrimaryNamespaceE.html -check-prefix=HTML-PRIMARY-CLASS
+
+// COM: FIXME: Add global functions to the namespace template
+// COM: FIXME: Add namespaces to the namespace template
// Anonymous Namespace
namespace {
void anonFunction() {}
// MD-ANON-INDEX-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp#[[@LINE-1]]*
-// HTML-ANON-INDEX-LINE: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp</p>
+// HTML-ANON-INDEX-LINE-NOT: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp</p>
class AnonClass {};
// MD-ANON-CLASS-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp#[[@LINE-1]]*
// HTML-ANON-CLASS-LINE: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp</p>
// MD-ANON-CLASS: # class AnonClass
-// HTML-ANON-CLASS: <h1>class AnonClass</h1>
+// HTML-ANON-CLASS: <h1 class="hero__title-large">class AnonClass</h1>
} // namespace
// MD-ANON-INDEX: # namespace @nonymous_namespace
@@ -61,20 +63,24 @@ class AnonClass {};
// MD-ANON-INDEX: ### anonFunction
// MD-ANON-INDEX: *void anonFunction()*
-// HTML-ANON-INDEX: <h1>namespace @nonymous_namespace</h1>
-// HTML-ANON-INDEX: <p> Anonymous Namespace</p>
-// HTML-ANON-INDEX: <h2 id="Records">Records</h2>
-// HTML-ANON-INDEX: <a href="AnonClass.html">AnonClass</a>
-// HTML-ANON-INDEX: <h2 id="Functions">Functions</h2>
-// HTML-ANON-INDEX: <h3 id="{{([0-9A-F]{40})}}">anonFunction</h3>
-// HTML-ANON-INDEX: <p>void anonFunction()</p>
+// HTML-ANON-INDEX: <h2> @nonymous_namespace</h2>
+// HTML-ANON-INDEX: <h2>Inner Classes</h2>
+// HTML-ANON-INDEX: <ul class="class-container">
+// HTML-ANON-INDEX: <li id="{{([0-9A-F]{40})}}" style="max-height: 40px;">
+// HTML-ANON-INDEX: <a href="_ZTVN12_GLOBAL__N_19AnonClassE.html">
+// HTML-ANON-INDEX: <pre><code class="language-cpp code-clang-doc">class AnonClass</code></pre>
+// HTML-ANON-INDEX: </a>
+// HTML-ANON-INDEX: </li>
+// HTML-ANON-INDEX-NOT: <h2 id="Functions">Functions</h2>
+// HTML-ANON-INDEX-NOT: <h3 id="{{([0-9A-F]{40})}}">anonFunction</h3>
+// HTML-ANON-INDEX-NOT: <p>void anonFunction()</p>
// Primary Namespace
namespace PrimaryNamespace {
// Function in PrimaryNamespace
void functionInPrimaryNamespace() {}
// MD-PRIMARY-INDEX-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp#[[@LINE-1]]*
-// HTML-PRIMARY-INDEX-LINE: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp</p>
+// HTML-PRIMARY-INDEX-LINE-NOT: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp</p>
// Class in PrimaryNamespace
class ClassInPrimaryNamespace {};
@@ -84,15 +90,14 @@ class ClassInPrimaryNamespace {};
// MD-PRIMARY-CLASS: # class ClassInPrimaryNamespace
// MD-PRIMARY-CLASS: Class in PrimaryNamespace
-// HTML-PRIMARY-CLASS: <h1>class ClassInPrimaryNamespace</h1>
-// HTML-PRIMARY-CLASS: <p> Class in PrimaryNamespace</p>
+// HTML-PRIMARY-CLASS: <h1 class="hero__title-large">class ClassInPrimaryNamespace</h1>
// Nested namespace
namespace NestedNamespace {
// Function in NestedNamespace
void functionInNestedNamespace() {}
// MD-NESTED-INDEX-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp#[[@LINE-1]]*
-// HTML-NESTED-INDEX-LINE: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp</p>
+// HTML-NESTED-INDEX-LINE-NOT: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp</p>
// Class in NestedNamespace
class ClassInNestedNamespace {};
@@ -102,8 +107,7 @@ class ClassInNestedNamespace {};
// MD-NESTED-CLASS: # class ClassInNestedNamespace
// MD-NESTED-CLASS: Class in NestedNamespace
-// HTML-NESTED-CLASS: <h1>class ClassInNestedNamespace</h1>
-// HTML-NESTED-CLASS: <p> Class in NestedNamespace</p>
+// HTML-NESTED-CLASS: <h1 class="hero__title-large">class ClassInNestedNamespace</h1>
} // namespace NestedNamespace
// MD-NESTED-INDEX: # namespace NestedNamespace
@@ -115,14 +119,19 @@ class ClassInNestedNamespace {};
// MD-NESTED-INDEX: *void functionInNestedNamespace()*
// MD-NESTED-INDEX: Function in NestedNamespace
-// HTML-NESTED-INDEX: <h1>namespace NestedNamespace</h1>
-// HTML-NESTED-INDEX: <p> Nested namespace</p>
-// HTML-NESTED-INDEX: <h2 id="Records">Records</h2>
-// HTML-NESTED-INDEX: <a href="ClassInNestedNamespace.html">ClassInNestedNamespace</a>
-// HTML-NESTED-INDEX: <h2 id="Functions">Functions</h2>
-// HTML-NESTED-INDEX: <h3 id="{{([0-9A-F]{40})}}">functionInNestedNamespace</h3>
-// HTML-NESTED-INDEX: <p>void functionInNestedNamespace()</p>
-// HTML-NESTED-INDEX: <p> Function in NestedNamespace</p>
+// HTML-NESTED-INDEX: <h2> NestedNamespace</h2>
+// HTML-NESTED-INDEX: <h2>Inner Classes</h2>
+// HTML-NESTED-INDEX: <ul class="class-container">
+// HTML-NESTED-INDEX: <li id="{{([0-9A-F]{40})}}" style="max-height: 40px;">
+// HTML-NESTED-INDEX: <a href="_ZTVN16PrimaryNamespace15NestedNamespace22ClassInNestedNamespaceE.html">
+// HTML-NESTED-INDEX: <pre><code class="language-cpp code-clang-doc">class ClassInNestedNamespace</code></pre>
+// HTML-NESTED-INDEX: </a>
+// HTML-NESTED-INDEX: </li>
+// HTML-NESTED-INDEX: </ul>
+// HTML-NESTED-INDEX-NOT: <h2 id="Functions">Functions</h2>
+// HTML-NESTED-INDEX-NOT: <h3 id="{{([0-9A-F]{40})}}">functionInNestedNamespace</h3>
+// HTML-NESTED-INDEX-NOT: <p>void functionInNestedNamespace()</p>
+// HTML-NESTED-INDEX-NOT: <p> Function in NestedNamespace</p>
} // namespace PrimaryNamespace
// MD-PRIMARY-INDEX: # namespace PrimaryNamespace
@@ -136,23 +145,28 @@ class ClassInNestedNamespace {};
// MD-PRIMARY-INDEX: *void functionInPrimaryNamespace()*
// MD-PRIMARY-INDEX: Function in PrimaryNamespace
-// HTML-PRIMARY-INDEX: <h1>namespace PrimaryNamespace</h1>
-// HTML-PRIMARY-INDEX: <p> Primary Namespace</p>
-// HTML-PRIMARY-INDEX: <h2 id="Namespaces">Namespaces</h2>
-// HTML-PRIMARY-INDEX: <a href="NestedNamespace{{[\/]}}index.html">NestedNamespace</a>
-// HTML-PRIMARY-INDEX: <h2 id="Records">Records</h2>
-// HTML-PRIMARY-INDEX: <a href="ClassInPrimaryNamespace.html">ClassInPrimaryNamespace</a>
-// HTML-PRIMARY-INDEX: <h2 id="Functions">Functions</h2>
-// HTML-PRIMARY-INDEX: <h3 id="{{([0-9A-F]{40})}}">functionInPrimaryNamespace</h3>
-// HTML-PRIMARY-INDEX: <p>void functionInPrimaryNamespace()</p>
-// HTML-PRIMARY-INDEX: <p> Function in PrimaryNamespace</p>
+// HTML-PRIMARY-INDEX: <h2> PrimaryNamespace</h2>
+// HTML-PRIMARY-INDEX-NOT: <h2 id="Namespaces">Namespaces</h2>
+// HTML-PRIMARY-INDEX-NOT: <a href="NestedNamespace{{[\/]}}index.html">NestedNamespace</a>
+// HTML-PRIMARY-INDEX <h2>Inner Classes</h2>
+// HTML-PRIMARY-INDEX <ul class="class-container">
+// HTML-PRIMARY-INDEX <li id="{{([0-9A-F]{40})}}" style="max-height: 40px;">
+// HTML-PRIMARY-INDEX <a href="_ZTVN16PrimaryNamespace23ClassInPrimaryNamespaceE.html">
+// HTML-PRIMARY-INDEX <pre><code class="language-cpp code-clang-doc">class ClassInPrimaryNamespace</code></pre>
+// HTML-PRIMARY-INDEX </a>
+// HTML-PRIMARY-INDEX </li>
+// HTML-PRIMARY-INDEX </ul>
+// HTML-PRIMARY-INDEX-NOT: <h2 id="Functions">Functions</h2>
+// HTML-PRIMARY-INDEX-NOT: <h3 id="{{([0-9A-F]{40})}}">functionInPrimaryNamespace</h3>
+// HTML-PRIMARY-INDEX-NOT: <p>void functionInPrimaryNamespace()</p>
+// HTML-PRIMARY-INDEX-NOT: <p> Function in PrimaryNamespace</p>
// AnotherNamespace
namespace AnotherNamespace {
// Function in AnotherNamespace
void functionInAnotherNamespace() {}
// MD-ANOTHER-INDEX-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp#[[@LINE-1]]*
-// HTML-ANOTHER-INDEX-LINE: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp</p>
+// HTML-ANOTHER-INDEX-LINE-NOT: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}namespace.cpp</p>
// Class in AnotherNamespace
class ClassInAnotherNamespace {};
@@ -162,8 +176,7 @@ class ClassInAnotherNamespace {};
// MD-ANOTHER-CLASS: # class ClassInAnotherNamespace
// MD-ANOTHER-CLASS: Class in AnotherNamespace
-// HTML-ANOTHER-CLASS: <h1>class ClassInAnotherNamespace</h1>
-// HTML-ANOTHER-CLASS: <p> Class in AnotherNamespace</p>
+// HTML-ANOTHER-CLASS: <h1 class="hero__title-large">class ClassInAnotherNamespace</h1>
} // namespace AnotherNamespace
@@ -176,99 +189,27 @@ class ClassInAnotherNamespace {};
// MD-ANOTHER-INDEX: *void functionInAnotherNamespace()*
// MD-ANOTHER-INDEX: Function in AnotherNamespace
-// HTML-ANOTHER-INDEX: <h1>namespace AnotherNamespace</h1>
-// HTML-ANOTHER-INDEX: <p> AnotherNamespace</p>
-// HTML-ANOTHER-INDEX: <h2 id="Records">Records</h2>
-// HTML-ANOTHER-INDEX: <a href="ClassInAnotherNamespace.html">ClassInAnotherNamespace</a>
-// HTML-ANOTHER-INDEX: <h2 id="Functions">Functions</h2>
-// HTML-ANOTHER-INDEX: <h3 id="{{([0-9A-F]{40})}}">functionInAnotherNamespace</h3>
-// HTML-ANOTHER-INDEX: <p>void functionInAnotherNamespace()</p>
-// HTML-ANOTHER-INDEX: <p> Function in AnotherNamespace</p>
-
-// JSON-INDEX: async function LoadIndex() {
-// JSON-INDEX-NEXT: return{
-// JSON-INDEX-NEXT: "USR": "{{([0-9A-F]{40})}}",
-// JSON-INDEX-NEXT: "Name": "",
-// JSON-INDEX-NEXT: "RefType": "default",
-// JSON-INDEX-NEXT: "Path": "",
-// JSON-INDEX-NEXT: "Children": [
-// JSON-INDEX-NEXT: {
-// JSON-INDEX-NEXT: "USR": "{{([0-9A-F]{40})}}",
-// JSON-INDEX-NEXT: "Name": "@nonymous_namespace",
-// JSON-INDEX-NEXT: "RefType": "namespace",
-// JSON-INDEX-NEXT: "Path": "@nonymous_namespace",
-// JSON-INDEX-NEXT: "Children": [
-// JSON-INDEX-NEXT: {
-// JSON-INDEX-NEXT: "USR": "{{([0-9A-F]{40})}}",
-// JSON-INDEX-NEXT: "Name": "AnonClass",
-// JSON-INDEX-NEXT: "RefType": "record",
-// JSON-INDEX-NEXT: "Path": "@nonymous_namespace",
-// JSON-INDEX-NEXT: "Children": []
-// JSON-INDEX-NEXT: }
-// JSON-INDEX-NEXT: ]
-// JSON-INDEX-NEXT: },
-// JSON-INDEX-NEXT: {
-// JSON-INDEX-NEXT: "USR": "{{([0-9A-F]{40})}}",
-// JSON-INDEX-NEXT: "Name": "AnotherNamespace",
-// JSON-INDEX-NEXT: "RefType": "namespace",
-// JSON-INDEX-NEXT: "Path": "AnotherNamespace",
-// JSON-INDEX-NEXT: "Children": [
-// JSON-INDEX-NEXT: {
-// JSON-INDEX-NEXT: "USR": "{{([0-9A-F]{40})}}",
-// JSON-INDEX-NEXT: "Name": "ClassInAnotherNamespace",
-// JSON-INDEX-NEXT: "RefType": "record",
-// JSON-INDEX-NEXT: "Path": "AnotherNamespace",
-// JSON-INDEX-NEXT: "Children": []
-// JSON-INDEX-NEXT: }
-// JSON-INDEX-NEXT: ]
-// JSON-INDEX-NEXT: },
-// JSON-INDEX-NEXT: {
-// JSON-INDEX-NEXT: "USR": "{{([0-9A-F]{40})}}",
-// JSON-INDEX-NEXT: "Name": "GlobalNamespace",
-// JSON-INDEX-NEXT: "RefType": "namespace",
-// JSON-INDEX-NEXT: "Path": "GlobalNamespace",
-// JSON-INDEX-NEXT: "Children": []
-// JSON-INDEX-NEXT: },
-// JSON-INDEX-NEXT: {
-// JSON-INDEX-NEXT: "USR": "{{([0-9A-F]{40})}}",
-// JSON-INDEX-NEXT: "Name": "PrimaryNamespace",
-// JSON-INDEX-NEXT: "RefType": "namespace",
-// JSON-INDEX-NEXT: "Path": "PrimaryNamespace",
-// JSON-INDEX-NEXT: "Children": [
-// JSON-INDEX-NEXT: {
-// JSON-INDEX-NEXT: "USR": "{{([0-9A-F]{40})}}",
-// JSON-INDEX-NEXT: "Name": "ClassInPrimaryNamespace",
-// JSON-INDEX-NEXT: "RefType": "record",
-// JSON-INDEX-NEXT: "Path": "PrimaryNamespace",
-// JSON-INDEX-NEXT: "Children": []
-// JSON-INDEX-NEXT: },
-// JSON-INDEX-NEXT: {
-// JSON-INDEX-NEXT: "USR": "{{([0-9A-F]{40})}}",
-// JSON-INDEX-NEXT: "Name": "NestedNamespace",
-// JSON-INDEX-NEXT: "RefType": "namespace",
-// JSON-INDEX-NEXT: "Path": "PrimaryNamespace{{[\/]+}}NestedNamespace",
-// JSON-INDEX-NEXT: "Children": [
-// JSON-INDEX-NEXT: {
-// JSON-INDEX-NEXT: "USR": "{{([0-9A-F]{40})}}",
-// JSON-INDEX-NEXT: "Name": "ClassInNestedNamespace",
-// JSON-INDEX-NEXT: "RefType": "record",
-// JSON-INDEX-NEXT: "Path": "PrimaryNamespace{{[\/]+}}NestedNamespace",
-// JSON-INDEX-NEXT: "Children": []
-// JSON-INDEX-NEXT: }
-// JSON-INDEX-NEXT: ]
-// JSON-INDEX-NEXT: }
-// JSON-INDEX-NEXT: ]
-// JSON-INDEX-NEXT: }
-// JSON-INDEX-NEXT: ]
-// JSON-INDEX-NEXT: };
-// JSON-INDEX-NEXT: }
-
-// HTML-GLOBAL-INDEX: <div id="main-content" class="col-xs-12 col-sm-9 col-md-8 main-content">
-// HTML-GLOBAL-INDEX: <h1>Global Namespace</h1>
-// HTML-GLOBAL-INDEX: <h2 id="Namespaces">Namespaces</h2>
-// HTML-GLOBAL-INDEX: <li>@nonymous_namespace</li>
-// HTML-GLOBAL-INDEX: <li>AnotherNamespace</li>
-// HTML-GLOBAL-INDEX: <li>PrimaryNamespace</li>
+// HTML-ANOTHER-INDEX: <h2> AnotherNamespace</h2>
+// HTML-ANOTHER-INDEX: <h2>Inner Classes</h2>
+// HTML-ANOTHER-INDEX: <ul class="class-container">
+// HTML-ANOTHER-INDEX: <li id="{{([0-9A-F]{40})}}" style="max-height: 40px;">
+// HTML-ANOTHER-INDEX: <a href="_ZTVN16AnotherNamespace23ClassInAnotherNamespaceE.html">
+// HTML-ANOTHER-INDEX: <pre><code class="language-cpp code-clang-doc">class ClassInAnotherNamespace</code></pre>
+// HTML-ANOTHER-INDEX: </a>
+// HTML-ANOTHER-INDEX: </li>
+// HTML-ANOTHER-INDEX: </ul>
+// HTML-ANOTHER-INDEX-NOT: <h2 id="Functions">Functions</h2>
+// HTML-ANOTHER-INDEX-NOT: <h3 id="{{([0-9A-F]{40})}}">functionInAnotherNamespace</h3>
+// HTML-ANOTHER-INDEX-NOT: <p>void functionInAnotherNamespace()</p>
+// HTML-ANOTHER-INDEX-NOT: <p> Function in AnotherNamespace</p>
+
+// COM: FIXME: Add namespaces to namespace template
+// HTML-GLOBAL-INDEX-NOT: <div id="main-content" class="col-xs-12 col-sm-9 col-md-8 main-content">
+// HTML-GLOBAL-INDEX-NOT: <h1>Global Namespace</h1>
+// HTML-GLOBAL-INDEX-NOT: <h2 id="Namespaces">Namespaces</h2>
+// HTML-GLOBAL-INDEX-NOT: <li>@nonymous_namespace</li>
+// HTML-GLOBAL-INDEX-NOT: <li>AnotherNamespace</li>
+// HTML-GLOBAL-INDEX-NOT: <li>PrimaryNamespace</li>
// MD-GLOBAL-INDEX: # Global Namespace
// MD-GLOBAL-INDEX: ## Namespaces
diff --git a/clang-tools-extra/test/clang-doc/test-path-abs.cpp b/clang-tools-extra/test/clang-doc/test-path-abs.cpp
deleted file mode 100644
index 8875a3a..0000000
--- a/clang-tools-extra/test/clang-doc/test-path-abs.cpp
+++ /dev/null
@@ -1,7 +0,0 @@
-// RUN: rm -rf %t && mkdir -p %t
-// RUN: clang-doc --format=html --executor=standalone %s --output=%t --base base_dir
-// RUN: FileCheck %s -input-file=%t/index_json.js -check-prefix=JSON-INDEX
-
-// JSON-INDEX: var RootPath = "{{.*}}test-path-abs.cpp.tmp";
-// JSON-INDEX-NEXT: var Base = "base_dir";
-
diff --git a/clang-tools-extra/test/clang-tidy/.clang-tidy b/clang-tools-extra/test/clang-tidy/.clang-tidy
new file mode 100644
index 0000000..612bd0e
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/.clang-tidy
@@ -0,0 +1 @@
+Checks: '-*'
diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
index 183b33f..b173ecf 100755
--- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -398,6 +398,8 @@ def parse_arguments() -> Tuple[argparse.Namespace, List[str]]:
def main() -> None:
+ sys.stdout.reconfigure(encoding="utf-8")
+ sys.stderr.reconfigure(encoding="utf-8")
args, extra_args = parse_arguments()
abbreviated_stds = args.std
diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-header-simulation.h b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-header-simulation.h
index b6977cd..0870f60 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-header-simulation.h
+++ b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-header-simulation.h
@@ -59,7 +59,7 @@ struct X {};
} // namespace std
// Template specializations that are in a system-header file.
-// The purpose is to test cert-dcl58-cpp (no warnings here).
+// The purpose is to test bugprone-std-namespace-modification (no warnings here).
namespace std {
template <>
void swap<short>(short &, short &){};
diff --git a/clang-tools-extra/test/clang-tidy/checkers/cert/oop58-cpp.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/copy-constructor-mutates-argument.cpp
index 223248c..9fdbb7a 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/cert/oop58-cpp.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/copy-constructor-mutates-argument.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s cert-oop58-cpp %t
+// RUN: %check_clang_tidy %s bugprone-copy-constructor-mutates-argument %t
// Example test cases from CERT rule
// https://wiki.sei.cmu.edu/confluence/display/cplusplus/OOP58-CPP.+Copy+operations+must+not+mutate+the+source+object
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/default-operator-new-on-overaligned-type-cpp17.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/default-operator-new-on-overaligned-type-cpp17.cpp
new file mode 100644
index 0000000..b05108c
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/default-operator-new-on-overaligned-type-cpp17.cpp
@@ -0,0 +1,12 @@
+// RUN: %check_clang_tidy %s -std=c++14 bugprone-default-operator-new-on-overaligned-type %t
+// RUN: clang-tidy -checks='-*,bugprone-default-operator-new-on-overaligned-type' --extra-arg=-Wno-unused-variable --warnings-as-errors='*' %s -- -std=c++17 -faligned-allocation
+// RUN: clang-tidy -checks='-*,bugprone-default-operator-new-on-overaligned-type' --extra-arg=-Wno-unused-variable --warnings-as-errors='*' %s -- -std=c++17 -faligned-allocation
+
+struct alignas(128) Vector {
+ char Elems[128];
+};
+
+void f() {
+ auto *V1 = new Vector; // CHECK-MESSAGES: warning: allocation function returns a pointer with alignment {{[0-9]+}} but the over-aligned type being allocated requires alignment 128 [bugprone-default-operator-new-on-overaligned-type]
+ auto *V1_Arr = new Vector[2]; // CHECK-MESSAGES: warning: allocation function returns a pointer with alignment {{[0-9]+}} but the over-aligned type being allocated requires alignment 128 [bugprone-default-operator-new-on-overaligned-type]
+}
diff --git a/clang-tools-extra/test/clang-tidy/checkers/cert/mem57-cpp.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/default-operator-new-on-overaligned-type.cpp
index e0300e3..379d8a2 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/cert/mem57-cpp.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/default-operator-new-on-overaligned-type.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s -std=c++14 cert-mem57-cpp %t
+// RUN: %check_clang_tidy %s -std=c++14 bugprone-default-operator-new-on-overaligned-type %t
namespace std {
typedef __typeof(sizeof(int)) size_t;
@@ -30,10 +30,10 @@ struct alignas(8) Vector4 {
void f() {
auto *V1 = new Vector1;
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: allocation function returns a pointer with alignment {{[0-9]+}} but the over-aligned type being allocated requires alignment 128 [cert-mem57-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: allocation function returns a pointer with alignment {{[0-9]+}} but the over-aligned type being allocated requires alignment 128 [bugprone-default-operator-new-on-overaligned-type]
auto *V2 = new Vector2;
auto *V3 = new Vector3;
auto *V4 = new Vector4;
auto *V1_Arr = new Vector1[2];
- // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: allocation function returns a pointer with alignment {{[0-9]+}} but the over-aligned type being allocated requires alignment 128 [cert-mem57-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: allocation function returns a pointer with alignment {{[0-9]+}} but the over-aligned type being allocated requires alignment 128 [bugprone-default-operator-new-on-overaligned-type]
}
diff --git a/clang-tools-extra/test/clang-tidy/checkers/cert/throw-exception-type.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-copy-constructor-throws.cpp
index 34ca837..7e2d586 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/cert/throw-exception-type.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-copy-constructor-throws.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s cert-err60-cpp %t -- -- -fcxx-exceptions
+// RUN: %check_clang_tidy -std=c++11,c++14 %s bugprone-exception-copy-constructor-throws %t -- -- -fcxx-exceptions
// FIXME: Split off parts of this test that rely on dynamic exception
// specifications, and run this test in all language modes.
// FIXME: Fix the checker to work in C++17 or later mode.
@@ -92,7 +92,7 @@ void f() {
throw U(); // ok
throw V(); // ok
throw W(); // match, noexcept(false)
- // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: thrown exception type is not nothrow copy constructible [cert-err60-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: thrown exception type is not nothrow copy constructible [bugprone-exception-copy-constructor-throws]
throw X(); // match, no noexcept clause, nontrivial
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: thrown exception type is not nothrow copy constructible
throw Y(); // ok
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-options.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-options.cpp
new file mode 100644
index 0000000..48c9bac
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-options.cpp
@@ -0,0 +1,47 @@
+// RUN: %check_clang_tidy -std=c++11-or-later %s bugprone-exception-escape %t -- \
+// RUN: -config="{CheckOptions: { \
+// RUN: bugprone-exception-escape.CheckDestructors: false, \
+// RUN: bugprone-exception-escape.CheckMoveMemberFunctions: false, \
+// RUN: bugprone-exception-escape.CheckMain: false, \
+// RUN: bugprone-exception-escape.CheckedSwapFunctions: '', \
+// RUN: bugprone-exception-escape.CheckNothrowFunctions: false \
+// RUN: }}" \
+// RUN: -- -fexceptions
+
+// CHECK-MESSAGES-NOT: warning:
+
+struct destructor {
+ ~destructor() {
+ throw 1;
+ }
+};
+
+struct move {
+ move(move&&) { throw 42; }
+ move& operator=(move&&) { throw 42; }
+};
+
+void swap(int&, int&) {
+ throw 1;
+}
+
+void iter_swap(int&, int&) {
+ throw 1;
+}
+
+void iter_move(int&) {
+ throw 1;
+}
+
+void nothrow_func() throw() {
+ throw 1;
+}
+
+void noexcept_func() noexcept {
+ throw 1;
+}
+
+int main() {
+ throw 1;
+ return 0;
+}
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
index a52bbe2..140c93f 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
@@ -948,7 +948,7 @@ const auto throw_in_noexcept_lambda = [] () noexcept { throw 42; };
// CHECK-MESSAGES: :[[@LINE-1]]:39: warning: an exception may be thrown in function 'operator()' which should not throw exceptions
// CHECK-MESSAGES: :[[@LINE-2]]:56: note: frame #0: unhandled exception of type 'int' may be thrown in function 'operator()' here
-void thrower() {
+int thrower() {
throw 42;
}
@@ -956,3 +956,54 @@ const auto indirect_throw_in_noexcept_lambda = [] () noexcept { thrower(); };
// CHECK-MESSAGES: :[[@LINE-1]]:48: warning: an exception may be thrown in function 'operator()' which should not throw exceptions
// CHECK-MESSAGES: :[[@LINE-5]]:3: note: frame #0: unhandled exception of type 'int' may be thrown in function 'thrower' here
// CHECK-MESSAGES: :[[@LINE-3]]:65: note: frame #1: function 'operator()' calls function 'thrower' here
+
+int f(int);
+void throw_in_function_arg() noexcept {
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_in_function_arg' which should not throw exceptions
+ f(false ? 0 : throw 1);
+}
+// CHECK-MESSAGES: :[[@LINE-2]]:17: note: frame #0: unhandled exception of type 'int' may be thrown in function 'throw_in_function_arg' here
+
+int g(int, int, int);
+void throw_in_last_function_arg() noexcept {
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_in_last_function_arg' which should not throw exceptions
+ g(42, 67, false ? 0 : throw 1);
+}
+// CHECK-MESSAGES: :[[@LINE-2]]:25: note: frame #0: unhandled exception of type 'int' may be thrown in function 'throw_in_last_function_arg' here
+
+void indirect_throw_in_function_arg() noexcept {
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'indirect_throw_in_function_arg' which should not throw exceptions
+ f(thrower());
+}
+// CHECK-MESSAGES: :[[@LINE-26]]:3: note: frame #0: unhandled exception of type 'int' may be thrown in function 'thrower' here
+// CHECK-MESSAGES: :[[@LINE-3]]:5: note: frame #1: function 'indirect_throw_in_function_arg' calls function 'thrower' here
+
+void indirect_throw_from_lambda_in_function_arg() noexcept {
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'indirect_throw_from_lambda_in_function_arg' which should not throw exceptions
+ f([] { throw 1; return 0; }());
+}
+// CHECK-MESSAGES: :[[@LINE-2]]:10: note: frame #0: unhandled exception of type 'int' may be thrown in function 'operator()' here
+// CHECK-MESSAGES: :[[@LINE-3]]:30: note: frame #1: function 'indirect_throw_from_lambda_in_function_arg' calls function 'operator()' here
+
+struct S {
+ S(int) noexcept {}
+};
+
+void throw_in_constructor_arg() noexcept {
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_in_constructor_arg' which should not throw exceptions
+ S s(false ? 0 : throw 1);
+}
+// CHECK-MESSAGES: :[[@LINE-2]]:19: note: frame #0: unhandled exception of type 'int' may be thrown in function 'throw_in_constructor_arg' here
+
+void indirect_throw_in_constructor_arg() noexcept {
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'indirect_throw_in_constructor_arg' which should not throw exceptions
+ S s = thrower();
+}
+// CHECK-MESSAGES: :[[@LINE-50]]:3: note: frame #0: unhandled exception of type 'int' may be thrown in function 'thrower' here
+// CHECK-MESSAGES: :[[@LINE-3]]:9: note: frame #1: function 'indirect_throw_in_constructor_arg' calls function 'thrower' here
+
+void weird_throw_in_call_subexpression() noexcept {
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'weird_throw_in_call_subexpression' which should not throw exceptions
+ (false ? []{} : throw 1)();
+}
+// CHECK-MESSAGES: :[[@LINE-2]]:19: note: frame #0: unhandled exception of type 'int' may be thrown in function 'weird_throw_in_call_subexpression' here
diff --git a/clang-tools-extra/test/clang-tidy/checkers/cert/flp30-c.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/float-loop-counter.c
index b998588..77812f0 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/cert/flp30-c.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/float-loop-counter.c
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s cert-flp30-c %t
+// RUN: %check_clang_tidy %s bugprone-float-loop-counter %t
float g(void);
int c(float);
@@ -7,16 +7,16 @@ float f = 1.0f;
void match(void) {
for (float x = 0.1f; x <= 1.0f; x += 0.1f) {}
- // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: loop induction expression should not have floating-point type [cert-flp30-c]
+ // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: loop induction expression should not have floating-point type [bugprone-float-loop-counter]
for (; f > 0; --f) {}
- // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: loop induction expression should not have floating-point type [cert-flp30-c]
+ // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: loop induction expression should not have floating-point type [bugprone-float-loop-counter]
for (float x = 0.0f; c(x); x = g()) {}
- // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: loop induction expression should not have floating-point type [cert-flp30-c]
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: loop induction expression should not have floating-point type [bugprone-float-loop-counter]
for (int i=0; i < 10 && f < 2.0f; f++, i++) {}
- // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: loop induction expression should not have floating-point type [cert-flp30-c]
+ // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: loop induction expression should not have floating-point type [bugprone-float-loop-counter]
// CHECK-MESSAGES: :5:1: note: floating-point type loop induction variable
}
diff --git a/clang-tools-extra/test/clang-tidy/checkers/cert/msc32-c.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/random-generator-seed.c
index 0a1d79b..7f2a068 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/cert/msc32-c.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/random-generator-seed.c
@@ -1,4 +1,5 @@
-// RUN: %check_clang_tidy %s cert-msc32-c %t -- -config="{CheckOptions: {cert-msc32-c.DisallowedSeedTypes: 'some_type,time_t'}}" -- -std=c99
+// RUN: %check_clang_tidy %s bugprone-random-generator-seed %t -- \
+// RUN: -config="{CheckOptions: {bugprone-random-generator-seed.DisallowedSeedTypes: 'some_type,time_t'}}"
void srand(int seed);
typedef int time_t;
@@ -6,15 +7,15 @@ time_t time(time_t *t);
void f(void) {
srand(1);
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc32-c]
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
const int a = 1;
srand(a);
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc32-c]
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
time_t t;
srand(time(&t)); // Disallowed seed type
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc32-c]
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [bugprone-random-generator-seed]
}
void g(void) {
diff --git a/clang-tools-extra/test/clang-tidy/checkers/cert/msc51-cpp.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/random-generator-seed.cpp
index 637ba58..c8818d6 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/cert/msc51-cpp.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/random-generator-seed.cpp
@@ -1,5 +1,5 @@
-// RUN: %check_clang_tidy %s cert-msc51-cpp %t -- \
-// RUN: -config="{CheckOptions: {cert-msc51-cpp.DisallowedSeedTypes: 'some_type,time_t'}}"
+// RUN: %check_clang_tidy %s bugprone-random-generator-seed %t -- \
+// RUN: -config="{CheckOptions: {bugprone-random-generator-seed.DisallowedSeedTypes: 'some_type,time_t'}}"
namespace std {
@@ -71,114 +71,114 @@ void f() {
time_t t;
std::srand(0);
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
std::srand(seed);
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
std::srand(time(&t));
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [bugprone-random-generator-seed]
// One instantiation for every engine
std::default_random_engine engine1;
- // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: random number generator seeded with a default argument will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: random number generator seeded with a default argument will generate a predictable sequence of values [bugprone-random-generator-seed]
std::default_random_engine engine2(1);
- // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
std::default_random_engine engine3(seed);
- // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
std::default_random_engine engine4(time(&t));
- // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [bugprone-random-generator-seed]
engine1.seed();
- // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a default argument will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a default argument will generate a predictable sequence of values [bugprone-random-generator-seed]
engine1.seed(1);
- // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
engine1.seed(seed);
- // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
engine1.seed(time(&t));
- // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [bugprone-random-generator-seed]
std::mt19937 engine5;
- // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: random number generator seeded with a default argument will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: random number generator seeded with a default argument will generate a predictable sequence of values [bugprone-random-generator-seed]
std::mt19937 engine6(1);
- // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
std::mt19937 engine7(seed);
- // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
std::mt19937 engine8(time(&t));
- // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [bugprone-random-generator-seed]
engine5.seed();
- // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a default argument will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a default argument will generate a predictable sequence of values [bugprone-random-generator-seed]
engine5.seed(1);
- // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
engine5.seed(seed);
- // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
engine5.seed(time(&t));
- // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [bugprone-random-generator-seed]
std::ranlux24_base engine9;
- // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: random number generator seeded with a default argument will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: random number generator seeded with a default argument will generate a predictable sequence of values [bugprone-random-generator-seed]
std::ranlux24_base engine10(1);
- // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
std::ranlux24_base engine11(seed);
- // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
std::ranlux24_base engine12(time(&t));
- // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [bugprone-random-generator-seed]
engine9.seed();
- // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a default argument will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a default argument will generate a predictable sequence of values [bugprone-random-generator-seed]
engine9.seed(1);
- // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
engine9.seed(seed);
- // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
engine9.seed(time(&t));
- // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [bugprone-random-generator-seed]
std::ranlux24 engine13;
- // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: random number generator seeded with a default argument will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: random number generator seeded with a default argument will generate a predictable sequence of values [bugprone-random-generator-seed]
std::ranlux24 engine14(1);
- // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
std::ranlux24 engine15(seed);
- // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
std::ranlux24 engine16(time(&t));
- // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [bugprone-random-generator-seed]
engine13.seed();
- // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a default argument will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a default argument will generate a predictable sequence of values [bugprone-random-generator-seed]
engine13.seed(1);
- // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
engine13.seed(seed);
- // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
engine13.seed(time(&t));
- // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [bugprone-random-generator-seed]
std::independent_bits engine17;
- // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: random number generator seeded with a default argument will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: random number generator seeded with a default argument will generate a predictable sequence of values [bugprone-random-generator-seed]
std::independent_bits engine18(1);
- // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
std::independent_bits engine19(seed);
- // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
std::independent_bits engine20(time(&t));
- // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [bugprone-random-generator-seed]
engine17.seed();
- // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a default argument will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a default argument will generate a predictable sequence of values [bugprone-random-generator-seed]
engine17.seed(1);
- // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
engine17.seed(seed);
- // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
engine17.seed(time(&t));
- // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [bugprone-random-generator-seed]
std::shuffle_order engine21;
- // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: random number generator seeded with a default argument will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: random number generator seeded with a default argument will generate a predictable sequence of values [bugprone-random-generator-seed]
std::shuffle_order engine22(1);
- // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
std::shuffle_order engine23(seed);
- // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
std::shuffle_order engine24(time(&t));
- // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [bugprone-random-generator-seed]
engine21.seed();
- // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a default argument will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a default argument will generate a predictable sequence of values [bugprone-random-generator-seed]
engine21.seed(1);
- // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
engine21.seed(seed);
- // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a constant value will generate a predictable sequence of values [bugprone-random-generator-seed]
engine21.seed(time(&t));
- // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [bugprone-random-generator-seed]
}
struct A {
diff --git a/clang-tools-extra/test/clang-tidy/checkers/cert/oop57-cpp.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/raw-memory-call-on-non-trivial-type.cpp
index e34315f..41a86ff 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/cert/oop57-cpp.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/raw-memory-call-on-non-trivial-type.cpp
@@ -1,8 +1,8 @@
-// RUN: %check_clang_tidy %s cert-oop57-cpp %t -- \
+// RUN: %check_clang_tidy %s bugprone-raw-memory-call-on-non-trivial-type %t -- \
// RUN: -config='{CheckOptions: \
-// RUN: {cert-oop57-cpp.MemSetNames: mymemset, \
-// RUN: cert-oop57-cpp.MemCpyNames: mymemcpy, \
-// RUN: cert-oop57-cpp.MemCmpNames: mymemcmp}}' \
+// RUN: {bugprone-raw-memory-call-on-non-trivial-type.MemSetNames: mymemset, \
+// RUN: bugprone-raw-memory-call-on-non-trivial-type.MemCpyNames: mymemcpy, \
+// RUN: bugprone-raw-memory-call-on-non-trivial-type.MemCmpNames: mymemcmp}}' \
// RUN: --
void mymemset(void *, unsigned char, decltype(sizeof(int)));
diff --git a/clang-tools-extra/test/clang-tidy/checkers/cert/dcl58-cpp.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/std-namespace-modification.cpp
index 01964e7..32bcbca 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/cert/dcl58-cpp.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/std-namespace-modification.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++17-or-later %s cert-dcl58-cpp %t -- -- -I %clang_tidy_headers
+// RUN: %check_clang_tidy -std=c++17-or-later %s bugprone-std-namespace-modification %t -- -- -I %clang_tidy_headers
#include "system-header-simulation.h"
@@ -15,7 +15,7 @@ namespace A {
}
namespace posix {
-// CHECK-MESSAGES: :[[@LINE+2]]:11: warning: modification of 'posix' namespace can result in undefined behavior [cert-dcl58-cpp]
+// CHECK-MESSAGES: :[[@LINE+2]]:11: warning: modification of 'posix' namespace can result in undefined behavior [bugprone-std-namespace-modification]
// CHECK-MESSAGES: :[[@LINE-2]]:11: note: 'posix' namespace opened here
namespace foo {
int foobar;
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access-ignore-value.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access-ignore-value.cpp
new file mode 100644
index 0000000..f546212
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access-ignore-value.cpp
@@ -0,0 +1,25 @@
+// RUN: %check_clang_tidy %s bugprone-unchecked-optional-access %t -- \
+// RUN: -config="{CheckOptions: \
+// RUN: {bugprone-unchecked-optional-access.IgnoreValueCalls: true}}" -- \
+// RUN: -I %S/Inputs/unchecked-optional-access
+
+#include "absl/types/optional.h"
+
+struct Foo {
+ void foo() const {}
+};
+
+void unchecked_value_access(const absl::optional<int> &opt) {
+ opt.value(); // no-warning
+}
+
+void unchecked_deref_operator_access(const absl::optional<int> &opt) {
+ *opt;
+ // CHECK-MESSAGES: :[[@LINE-1]]:4: warning: unchecked access to optional value
+}
+
+void unchecked_arrow_operator_access(const absl::optional<Foo> &opt) {
+ opt->foo();
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: unchecked access to optional value
+}
+
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions-custom.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions-custom.c
index 7fd71ec..7eaf015 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions-custom.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions-custom.c
@@ -1,5 +1,5 @@
// RUN: %check_clang_tidy -check-suffix=NON-STRICT-REGEX %s bugprone-unsafe-functions %t --\
-// RUN: -config="{CheckOptions: {bugprone-unsafe-functions.CustomFunctions: '::name_match,replacement,is a qualname match;^::prefix_match,,is matched on qualname prefix'}}"
+// RUN: -config="{CheckOptions: {bugprone-unsafe-functions.CustomFunctions: \"::name_match,,>is a qualname match, but with a fully 'custom' message;^::prefix_match,,is matched on qualname prefix\"}}"
// RUN: %check_clang_tidy -check-suffix=STRICT-REGEX %s bugprone-unsafe-functions %t --\
// RUN: -config="{CheckOptions: {bugprone-unsafe-functions.CustomFunctions: '^name_match$,replacement,is matched on function name only;^::prefix_match$,,is a full qualname match'}}"
@@ -11,14 +11,14 @@ void prefix_match_regex();
void f1() {
name_match();
- // CHECK-MESSAGES-NON-STRICT-REGEX: :[[@LINE-1]]:3: warning: function 'name_match' is a qualname match; 'replacement' should be used instead
+ // CHECK-MESSAGES-NON-STRICT-REGEX: :[[@LINE-1]]:3: warning: function 'name_match' is a qualname match, but with a fully 'custom' message
// CHECK-MESSAGES-STRICT-REGEX: :[[@LINE-2]]:3: warning: function 'name_match' is matched on function name only; 'replacement' should be used instead
prefix_match();
// CHECK-MESSAGES-NON-STRICT-REGEX: :[[@LINE-1]]:3: warning: function 'prefix_match' is matched on qualname prefix; it should not be used
// CHECK-MESSAGES-STRICT-REGEX: :[[@LINE-2]]:3: warning: function 'prefix_match' is a full qualname match; it should not be used
name_match_regex();
- // CHECK-MESSAGES-NON-STRICT-REGEX: :[[@LINE-1]]:3: warning: function 'name_match_regex' is a qualname match; 'replacement' should be used instead
+ // CHECK-MESSAGES-NON-STRICT-REGEX: :[[@LINE-1]]:3: warning: function 'name_match_regex' is a qualname match, but with a fully 'custom' message
// no-warning STRICT-REGEX
prefix_match_regex();
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp
index 87dfec4..b2df263 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp
@@ -1,5 +1,13 @@
-// RUN: %check_clang_tidy -std=c++11 -check-suffixes=,CXX11 %s bugprone-use-after-move %t -- -- -fno-delayed-template-parsing
-// RUN: %check_clang_tidy -std=c++17-or-later %s bugprone-use-after-move %t -- -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -std=c++11 -check-suffixes=,CXX11 %s bugprone-use-after-move %t -- \
+// RUN: -config='{CheckOptions: { \
+// RUN: bugprone-use-after-move.InvalidationFunctions: "::Database<>::StaticCloseConnection;Database<>::CloseConnection;FriendCloseConnection" \
+// RUN: }}' -- \
+// RUN: -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -std=c++17-or-later %s bugprone-use-after-move %t -- \
+// RUN: -config='{CheckOptions: { \
+// RUN: bugprone-use-after-move.InvalidationFunctions: "::Database<>::StaticCloseConnection;Database<>::CloseConnection;FriendCloseConnection" \
+// RUN: }}' -- \
+// RUN: -fno-delayed-template-parsing
typedef decltype(nullptr) nullptr_t;
@@ -1645,3 +1653,53 @@ void create() {
}
} // namespace issue82023
+
+namespace custom_invalidation
+{
+
+template<class T = int>
+struct Database {
+ template<class...>
+ void CloseConnection(T = T()) {}
+ template<class...>
+ static void StaticCloseConnection(Database&, T = T()) {}
+ template<class...>
+ friend void FriendCloseConnection(Database&, T = T()) {}
+ void Query();
+};
+
+void Run() {
+ using DB = Database<>;
+
+ DB db1;
+ db1.CloseConnection();
+ db1.Query();
+ // CHECK-NOTES: [[@LINE-1]]:3: warning: 'db1' used after it was invalidated
+ // CHECK-NOTES: [[@LINE-3]]:7: note: invalidation occurred here
+
+ DB db2;
+ DB::StaticCloseConnection(db2);
+ db2.Query();
+ // CHECK-NOTES: [[@LINE-1]]:3: warning: 'db2' used after it was invalidated
+ // CHECK-NOTES: [[@LINE-3]]:3: note: invalidation occurred here
+
+ DB db3;
+ DB().StaticCloseConnection(db3);
+ db3.Query();
+ // CHECK-NOTES: [[@LINE-1]]:3: warning: 'db3' used after it was invalidated
+ // CHECK-NOTES: [[@LINE-3]]:3: note: invalidation occurred here
+
+ DB db4;
+ FriendCloseConnection(db4);
+ db4.Query();
+ // CHECK-NOTES: [[@LINE-1]]:3: warning: 'db4' used after it was invalidated
+ // CHECK-NOTES: [[@LINE-3]]:3: note: invalidation occurred here
+
+ DB db5;
+ FriendCloseConnection(db5, /*disconnect timeout*/ 5);
+ db5.Query();
+ // CHECK-NOTES: [[@LINE-1]]:3: warning: 'db5' used after it was invalidated
+ // CHECK-NOTES: [[@LINE-3]]:3: note: invalidation occurred here
+}
+
+} // namespace custom_invalidation
diff --git a/clang-tools-extra/test/clang-tidy/checkers/cert/mem57-cpp-cpp17.cpp b/clang-tools-extra/test/clang-tidy/checkers/cert/mem57-cpp-cpp17.cpp
deleted file mode 100644
index 38ffcbd..0000000
--- a/clang-tools-extra/test/clang-tidy/checkers/cert/mem57-cpp-cpp17.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
-// RUN: %check_clang_tidy %s -std=c++14 cert-mem57-cpp %t
-// RUN: clang-tidy -checks='-*,cert-mem57-cpp' --extra-arg=-Wno-unused-variable --warnings-as-errors='*' %s -- -std=c++17 -faligned-allocation
-// RUN: clang-tidy -checks='-*,cert-mem57-cpp' --extra-arg=-Wno-unused-variable --warnings-as-errors='*' %s -- -std=c++17 -faligned-allocation
-
-struct alignas(128) Vector {
- char Elems[128];
-};
-
-void f() {
- auto *V1 = new Vector; // CHECK-MESSAGES: warning: allocation function returns a pointer with alignment {{[0-9]+}} but the over-aligned type being allocated requires alignment 128 [cert-mem57-cpp]
- auto *V1_Arr = new Vector[2]; // CHECK-MESSAGES: warning: allocation function returns a pointer with alignment {{[0-9]+}} but the over-aligned type being allocated requires alignment 128 [cert-mem57-cpp]
-}
diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.ignorearrays.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.ignorearrays.cpp
index 01859b3..e4cfe67 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.ignorearrays.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.ignorearrays.cpp
@@ -14,3 +14,39 @@ struct HasArrayMember {
int RawArray[4];
int Number;
};
+
+namespace std {
+template <typename T, int N>
+struct array {
+ T _Elems[N];
+ void fill(const T &);
+};
+}
+
+void test_local_std_array() {
+ std::array<int, 4> a;
+}
+
+struct OnlyArray {
+ int a[4];
+};
+
+void test_local_only_array() {
+ OnlyArray a;
+}
+
+struct Mixed {
+ int a[4];
+ int b;
+};
+
+void test_local_mixed() {
+ Mixed m;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: uninitialized record type: 'm'
+}
+
+void test_std_array_fill() {
+ std::array<char, 10> someArray;
+ // CHECK-MESSAGES-NOT: warning: uninitialized record type: 'someArray'
+ someArray.fill('n');
+}
diff --git a/clang-tools-extra/test/clang-tidy/checkers/fuchsia/multiple-inheritance.cpp b/clang-tools-extra/test/clang-tidy/checkers/fuchsia/multiple-inheritance.cpp
index d53b3fd..c60649f 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/fuchsia/multiple-inheritance.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/fuchsia/multiple-inheritance.cpp
@@ -148,3 +148,18 @@ void test_no_crash() {
auto foo = []() {};
WithTemplBase<decltype(foo)>();
}
+
+struct S1 {};
+struct S2 {};
+
+struct S3 : S1, S2 {};
+
+namespace N {
+
+struct S1 { int i; };
+struct S2 { int i; };
+
+// CHECK-MESSAGES: [[@LINE+1]]:1: warning: inheriting multiple classes that aren't pure virtual is discouraged [fuchsia-multiple-inheritance]
+struct S3 : S1, S2 {};
+
+} // namespace N
diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.c b/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.c
deleted file mode 100644
index f0d5339..0000000
--- a/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.c
+++ /dev/null
@@ -1,24 +0,0 @@
-// RUN: %check_clang_tidy %s google-readability-casting %t -- -- -x c
-// The testing script always adds .cpp extension to the input file name, so we
-// need to run clang-tidy directly in order to verify handling of .c files:
-// RUN: clang-tidy --checks=-*,google-readability-casting %s -- -x c++ | FileCheck %s -check-prefix=CHECK-MESSAGES -implicit-check-not='{{warning|error}}:'
-// RUN: cp %s %t.main_file.cpp
-// 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}}:'
-
-#ifdef TEST_INCLUDE
-
-#undef TEST_INCLUDE
-#include "readability-casting.c"
-
-#else
-
-void f(const char *cpc) {
- const char *cpc2 = (const char*)cpc;
- // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: redundant cast to the same type [google-readability-casting]
- // CHECK-FIXES: const char *cpc2 = cpc;
- char *pc = (char*)cpc;
- typedef const char *Typedef1;
- (Typedef1)cpc;
-}
-
-#endif
diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo-hyphen.cpp b/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo-hyphen.cpp
new file mode 100644
index 0000000..5701b30
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo-hyphen.cpp
@@ -0,0 +1,40 @@
+// RUN: %check_clang_tidy %s google-readability-todo %t -- -config="{User: 'some user'}" --
+
+// TODOfix this1
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: missing username/bug in TODO
+// CHECK-FIXES: // TODO: some user - fix this1
+
+// TODO fix this2
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: missing username/bug in TODO
+// CHECK-FIXES: // TODO: some user - fix this2
+
+// TODO fix this3
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: missing username/bug in TODO
+// CHECK-FIXES: // TODO: some user - fix this3
+
+// TODO: fix this4
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: missing username/bug in TODO
+// CHECK-FIXES: // TODO: some user - fix this4
+
+// TODO: bug 12345 -
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: missing details in TODO
+
+// TODO: a message without a reference
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: missing username/bug in TODO
+// CHECK-FIXES: // TODO: some user - a message without a reference
+
+// TODO(clang)fix this5
+
+// TODO: foo - shave yaks
+// TODO:foo - no space bewteen semicolon and username
+// TODO: foo- no space bewteen username and dash
+// TODO: foo - extra spaces between semicolon and username
+// TODO: foo - extra spaces between username and dash
+// TODO: b/12345 - use a b/ prefix
+// TODO: bug 12345 - use a space in username/bug reference
+// TODO(foo):shave yaks
+// TODO(bar):
+// TODO(foo): paint bikeshed
+// TODO(b/12345): find the holy grail
+// TODO (b/12345): allow spaces before parentheses
+// TODO(asdf) allow missing semicolon
diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp b/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo-parentheses.cpp
index 6b900aa..f97e395 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo-parentheses.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s google-readability-todo %t -- -config="{User: 'some user'}" --
+// RUN: %check_clang_tidy %s google-readability-todo %t -- -config="{User: 'some user', CheckOptions: {google-readability-todo.Style: 'Parentheses'}}" --
// TODOfix this1
// CHECK-MESSAGES: [[@LINE-1]]:1: warning: missing username/bug in TODO
@@ -16,8 +16,22 @@
// CHECK-MESSAGES: [[@LINE-1]]:1: warning: missing username/bug in TODO
// CHECK-FIXES: // TODO(some user): fix this4
+// TODO: bug 12345 -
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: missing details in TODO
+
+// TODO: a message without a reference
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: missing username/bug in TODO
+// CHECK-FIXES: // TODO(some user): a message without a reference
+
// TODO(clang)fix this5
+// TODO: foo - shave yaks
+// TODO:foo - no space bewteen semicolon and username
+// TODO: foo- no space bewteen username and dash
+// TODO: foo - extra spaces between semicolon and username
+// TODO: foo - extra spaces between username and dash
+// TODO: b/12345 - use a b/ prefix
+// TODO: bug 12345 - use a space in username/bug reference
// TODO(foo):shave yaks
// TODO(bar):
// TODO(foo): paint bikeshed
diff --git a/clang-tools-extra/test/clang-tidy/checkers/llvm/use-new-mlir-op-builder.cpp b/clang-tools-extra/test/clang-tidy/checkers/llvm/use-new-mlir-op-builder.cpp
index b57eab0..c4a1d8d 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/llvm/use-new-mlir-op-builder.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/llvm/use-new-mlir-op-builder.cpp
@@ -2,6 +2,7 @@
namespace mlir {
class Location {};
+class Value {};
class OpBuilder {
public:
template <typename OpTy, typename... Args>
@@ -28,6 +29,13 @@ struct NamedOp {
static NamedOp create(OpBuilder &builder, Location location, const char* name) {
return NamedOp(name);
}
+ Value getResult() { return Value(); }
+};
+struct OperandOp {
+ OperandOp(Value val) {}
+ static OperandOp create(OpBuilder &builder, Location location, Value val) {
+ return OperandOp(val);
+ }
};
} // namespace mlir
@@ -40,6 +48,22 @@ void g(mlir::OpBuilder &b) {
b.create<T>(b.getUnknownLoc(), "gaz");
}
+class CustomBuilder : public mlir::ImplicitLocOpBuilder {
+public:
+ mlir::NamedOp f(const char *name) {
+ // CHECK-MESSAGES: :[[@LINE+2]]:12: warning: use 'OpType::create(builder, ...)'
+ // CHECK-FIXES: return mlir::NamedOp::create(*this, name);
+ return create<mlir::NamedOp>(name);
+ }
+
+ mlir::NamedOp g(const char *name) {
+ using mlir::NamedOp;
+ // CHECK-MESSAGES: :[[@LINE+2]]:12: warning: use 'OpType::create(builder, ...)'
+ // CHECK-FIXES: return NamedOp::create(*this, name);
+ return create<NamedOp>(name);
+ }
+};
+
void f() {
mlir::OpBuilder builder;
// CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use 'OpType::create(builder, ...)' instead of 'builder.create<OpType>(...)' [llvm-use-new-mlir-op-builder]
@@ -47,15 +71,18 @@ void f() {
builder.create<mlir:: ModuleOp>(builder.getUnknownLoc());
using mlir::NamedOp;
+ using mlir::OperandOp;
+
// CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use 'OpType::create(builder, ...)' instead of 'builder.create<OpType>(...)' [llvm-use-new-mlir-op-builder]
// CHECK-FIXES: NamedOp::create(builder, builder.getUnknownLoc(), "baz");
builder.create<NamedOp>(builder.getUnknownLoc(), "baz");
- // CHECK-MESSAGES: :[[@LINE+3]]:3: warning: use 'OpType::create(builder, ...)' instead of 'builder.create<OpType>(...)' [llvm-use-new-mlir-op-builder]
- // CHECK-FIXES: NamedOp::create(builder, builder.getUnknownLoc(),
- // CHECK-FIXES: "caz");
+ // CHECK-MESSAGES: :[[@LINE+4]]:3: warning: use 'OpType::create(builder, ...)' instead of 'builder.create<OpType>(...)' [llvm-use-new-mlir-op-builder]
+ // CHECK-FIXES: NamedOp::create(builder,
+ // CHECK-FIXES: builder.getUnknownLoc(),
+ // CHECK-FIXES: "caz");
builder.
- create<NamedOp>(
+ create<NamedOp> (
builder.getUnknownLoc(),
"caz");
@@ -66,10 +93,26 @@ void f() {
mlir::ImplicitLocOpBuilder ib;
// CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use 'OpType::create(builder, ...)' instead of 'builder.create<OpType>(...)' [llvm-use-new-mlir-op-builder]
- // CHECK-FIXES: mlir::ModuleOp::create(ib);
+ // CHECK-FIXES: mlir::ModuleOp::create(ib );
ib.create<mlir::ModuleOp>( );
// CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use 'OpType::create(builder, ...)' instead of 'builder.create<OpType>(...)' [llvm-use-new-mlir-op-builder]
// CHECK-FIXES: mlir::OpBuilder().create<mlir::ModuleOp>(builder.getUnknownLoc());
mlir::OpBuilder().create<mlir::ModuleOp>(builder.getUnknownLoc());
+
+ auto *p = &builder;
+ // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use 'OpType::create(builder, ...)'
+ // CHECK-FIXES: NamedOp::create(*p, builder.getUnknownLoc(), "eaz");
+ p->create<NamedOp>(builder.getUnknownLoc(), "eaz");
+
+ CustomBuilder cb;
+ cb.f("faz");
+ cb.g("gaz");
+
+ // CHECK-FIXES: OperandOp::create(builder, builder.getUnknownLoc(),
+ // CHECK-FIXES-NEXT: NamedOp::create(builder, builder.getUnknownLoc(), "haz").getResult());
+ // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use 'OpType::create(builder, ...)' instead of 'builder.create<OpType>(...)' [llvm-use-new-mlir-op-builder]
+ // CHECK-MESSAGES: :[[@LINE+2]]:5: warning: use 'OpType::create(builder, ...)' instead of 'builder.create<OpType>(...)' [llvm-use-new-mlir-op-builder]
+ builder.create<OperandOp>(builder.getUnknownLoc(),
+ builder.create<NamedOp>(builder.getUnknownLoc(), "haz").getResult());
}
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp
index 4c847b5..0cb58c2 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp
@@ -73,3 +73,18 @@ void ignoreNonConstRefOps() {
int* p2 {nullptr};
int*& r2 = (int*&)p2;
}
+
+void pointer_to_pointer_param(int**);
+void pass_address_to_pointer_to_pointer() {
+ int i = 0;
+ int* ip = &i;
+ // CHECK-NOT: warning
+ pointer_to_pointer_param(&ip);
+}
+
+void void_pointer_to_pointer_param(void**);
+void pass_address_to_void_pointer_to_pointer() {
+ void* ptr = nullptr;
+ // CHECK-NOT: warning
+ void_pointer_to_pointer_param(&ptr);
+}
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp
index c23c355..dff73ae 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp
@@ -1,7 +1,8 @@
// RUN: %check_clang_tidy -std=c++20 %s misc-coroutine-hostile-raii %t \
// RUN: -config="{CheckOptions: {\
// RUN: misc-coroutine-hostile-raii.RAIITypesList: 'my::Mutex; ::my::other::Mutex', \
-// RUN: misc-coroutine-hostile-raii.AllowedAwaitablesList: 'safe::awaitable; ::transformable::awaitable' \
+// RUN: misc-coroutine-hostile-raii.AllowedAwaitablesList: 'safe::awaitable; ::transformable::awaitable', \
+// RUN: misc-coroutine-hostile-raii.AllowedCallees: 'safe::AwaitFunc; ::safe::Obj::AwaitMethod; retExemptedAwaitable' \
// RUN: }}"
namespace std {
@@ -145,18 +146,27 @@ namespace safe {
void await_suspend(std::coroutine_handle<>) noexcept {}
void await_resume() noexcept {}
};
+ std::suspend_always AwaitFunc();
+ struct Obj {
+ std::suspend_always AwaitMethod();
+ };
} // namespace safe
ReturnObject RAIISafeSuspendTest() {
absl::Mutex a;
co_await safe::awaitable{};
using other = safe::awaitable;
co_await other{};
+ co_await safe::AwaitFunc();
+ co_await safe::Obj().AwaitMethod();
}
// ================================================================================
// Safe transformable awaitable
// ================================================================================
-struct transformable { struct awaitable{}; };
+struct transformable {
+ struct awaitable{};
+ struct unsafe_awaitable{};
+};
using alias_transformable_awaitable = transformable::awaitable;
struct UseTransformAwaitable {
struct promise_type {
@@ -165,13 +175,18 @@ struct UseTransformAwaitable {
std::suspend_always final_suspend() noexcept { return {}; }
void unhandled_exception() {}
std::suspend_always await_transform(transformable::awaitable) { return {}; }
+ std::suspend_always await_transform(transformable::unsafe_awaitable) {
+ return {};
+ }
};
};
auto retAwaitable() { return transformable::awaitable{}; }
+auto retExemptedAwaitable() { return transformable::unsafe_awaitable{}; }
UseTransformAwaitable RAIISafeSuspendTest2() {
absl::Mutex a;
co_await retAwaitable();
+ co_await retExemptedAwaitable();
co_await transformable::awaitable{};
co_await alias_transformable_awaitable{};
}
diff --git a/clang-tools-extra/test/clang-tidy/checkers/cert/limited-randomness.c b/clang-tools-extra/test/clang-tidy/checkers/misc/predictable-rand.c
index 32e4a07..d823309 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/cert/limited-randomness.c
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/predictable-rand.c
@@ -1,11 +1,11 @@
-// RUN: %check_clang_tidy %s cert-msc30-c %t
+// RUN: %check_clang_tidy %s misc-predictable-rand %t
extern int rand(void);
int nonrand(void);
int cTest(void) {
int i = rand();
- // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: rand() has limited randomness [cert-msc30-c]
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: rand() has limited randomness [misc-predictable-rand]
int k = nonrand();
diff --git a/clang-tools-extra/test/clang-tidy/checkers/cert/limited-randomness.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/predictable-rand.cpp
index 845b735..8f00186 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/cert/limited-randomness.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/predictable-rand.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s cert-msc50-cpp %t
+// RUN: %check_clang_tidy %s misc-predictable-rand %t
int rand();
int rand(int);
@@ -13,16 +13,16 @@ namespace nonstd {
void testFunction1() {
int i = std::rand();
- // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: rand() has limited randomness; use C++11 random library instead [cert-msc50-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: rand() has limited randomness; use C++11 random library instead [misc-predictable-rand]
int j = ::rand();
- // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: rand() has limited randomness; use C++11 random library instead [cert-msc50-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: rand() has limited randomness; use C++11 random library instead [misc-predictable-rand]
int k = rand(i);
int l = nonstd::rand();
int m = rand();
- // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: rand() has limited randomness; use C++11 random library instead [cert-msc50-cpp]
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: rand() has limited randomness; use C++11 random library instead [misc-predictable-rand]
}
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-style-cast.c b/clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-style-cast.c
new file mode 100644
index 0000000..7dfdc7b
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-style-cast.c
@@ -0,0 +1,24 @@
+// RUN: %check_clang_tidy %s modernize-avoid-c-style-cast %t -- -- -x c
+// The testing script always adds .cpp extension to the input file name, so we
+// need to run clang-tidy directly in order to verify handling of .c files:
+// RUN: clang-tidy --checks=-*,modernize-avoid-c-style-cast %s -- -x c++ | FileCheck %s -check-prefix=CHECK-MESSAGES -implicit-check-not='{{warning|error}}:'
+// RUN: cp %s %t.main_file.cpp
+// RUN: clang-tidy --checks=-*,modernize-avoid-c-style-cast -header-filter='.*' %t.main_file.cpp -- -I%S -DTEST_INCLUDE -x c++ | FileCheck %s -check-prefix=CHECK-MESSAGES -implicit-check-not='{{warning|error}}:'
+
+#ifdef TEST_INCLUDE
+
+#undef TEST_INCLUDE
+#include "avoid-c-style-cast.c"
+
+#else
+
+void f(const char *cpc) {
+ const char *cpc2 = (const char*)cpc;
+ // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: redundant cast to the same type [modernize-avoid-c-style-cast]
+ // CHECK-FIXES: const char *cpc2 = cpc;
+ char *pc = (char*)cpc;
+ typedef const char *Typedef1;
+ (Typedef1)cpc;
+}
+
+#endif
diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-style-cast.cpp
index 7ccdf70..52b4d47 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-style-cast.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11-or-later %s google-readability-casting %t -- -- -fexceptions
+// RUN: %check_clang_tidy -std=c++11-or-later %s modernize-avoid-c-style-cast %t -- -- -fexceptions
bool g() { return false; }
@@ -8,14 +8,14 @@ struct Y : public X {};
void f(int a, double b, const char *cpc, const void *cpv, X *pX) {
const char *cpc2 = (const char*)cpc;
- // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: redundant cast to the same type [google-readability-casting]
+ // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: redundant cast to the same type [modernize-avoid-c-style-cast]
// CHECK-FIXES: const char *cpc2 = cpc;
typedef const char *Typedef1;
typedef const char *Typedef2;
Typedef1 t1;
(Typedef2)t1;
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: C-style casts are discouraged; use static_cast (if needed, the cast may be redundant) [google-readability-casting]
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: C-style casts are discouraged; use static_cast (if needed, the cast may be redundant) [modernize-avoid-c-style-cast]
// CHECK-FIXES: static_cast<Typedef2>(t1);
(const char*)t1;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: {{.*}}; use static_cast (if needed
@@ -28,7 +28,7 @@ void f(int a, double b, const char *cpc, const void *cpv, X *pX) {
// CHECK-FIXES: t1;
char *pc = (char*)cpc;
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: C-style casts are discouraged; use const_cast [google-readability-casting]
+ // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: C-style casts are discouraged; use const_cast [modernize-avoid-c-style-cast]
// CHECK-FIXES: char *pc = const_cast<char*>(cpc);
typedef char Char;
Char *pChar = (Char*)pc;
@@ -102,9 +102,15 @@ void f(int a, double b, const char *cpc, const void *cpv, X *pX) {
// CHECK-FIXES: b1 = static_cast<int>(b);
Y *pB = (Y*)pX;
- // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}}; use static_cast/const_cast/reinterpret_cast [
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}}; use static_cast {{.*}}
+ // CHECK-FIXES: Y *pB = static_cast<Y*>(pX);
Y &rB = (Y&)*pX;
- // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}}; use static_cast/const_cast/reinterpret_cast [
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}}; use static_cast {{.*}}
+ // CHECK-FIXES: Y &rB = static_cast<Y&>(*pX);
+
+ void *vp = (void *) pX;
+ // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: {{.*}}; use reinterpret_cast
+ // CHECK-FIXES: void *vp = reinterpret_cast<void *>(pX);
const char *pc3 = (const char*)cpv;
// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: {{.*}}; use static_cast [
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp
index ec37f07..63972cc 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp
@@ -54,6 +54,12 @@ void printf_deceptive_newline() {
// CHECK-FIXES: std::println("Hello");
}
+void printf_utf8_text() {
+ printf("你好世界\n");
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+ // CHECK-FIXES: std::println("你好世界");
+}
+
void printf_crlf_newline() {
printf("Hello\r\n");
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::print' instead of 'printf' [modernize-use-std-print]
@@ -303,6 +309,12 @@ void fprintf_simple() {
// CHECK-FIXES: std::print(stderr, "Hello");
}
+void fprintf_utf8_text() {
+ fprintf(stderr, "你好世界\n");
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::println' instead of 'fprintf' [modernize-use-std-print]
+ // CHECK-FIXES: std::println(stderr, "你好世界");
+}
+
void std_printf_simple() {
std::printf("std::Hello");
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::print' instead of 'printf' [modernize-use-std-print]
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/duplicate-include/pack_begin.h b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/duplicate-include/pack_begin.h
new file mode 100644
index 0000000..fc9369c
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/duplicate-include/pack_begin.h
@@ -0,0 +1 @@
+// Intentionally unguarded begin-pack header used in tests
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/duplicate-include/pack_end.h b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/duplicate-include/pack_end.h
new file mode 100644
index 0000000..78fd0a9
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/duplicate-include/pack_end.h
@@ -0,0 +1 @@
+// Intentionally unguarded end-pack header used in tests
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
index a8e0eb6..2ed1e93 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
@@ -35,6 +35,12 @@ template <typename T>
struct enable_if<true, T> {
typedef T type;
};
+
+template <typename T>
+struct unique_ptr {
+ T &operator*() const;
+ T *operator->() const;
+};
}
template <typename T>
@@ -144,3 +150,20 @@ int *r() {
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: 'data' should be used for accessing the data pointer instead of taking the address of the 0-th element [readability-container-data-pointer]
// CHECK-FIXES: return holder.v.data();
}
+
+void s(std::unique_ptr<std::vector<unsigned char>> p) {
+ f(&(*p)[0]);
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'data' should be used for accessing the data pointer instead of taking the address of the 0-th element [readability-container-data-pointer]
+ // CHECK-FIXES: f((*p).data());
+}
+
+void t(std::unique_ptr<container_without_data<unsigned char>> p) {
+ // p has no "data" member function, so no warning
+ f(&(*p)[0]);
+}
+
+template <typename T>
+void u(std::unique_ptr<T> p) {
+ // we don't know if 'T' will always have "data" member function, so no warning
+ f(&(*p)[0]);
+}
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/duplicate-include-ignored-files.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/duplicate-include-ignored-files.cpp
new file mode 100644
index 0000000..cdc2f44
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/duplicate-include-ignored-files.cpp
@@ -0,0 +1,24 @@
+// RUN: %check_clang_tidy %s readability-duplicate-include %t -- \
+// RUN: -config="{CheckOptions: {readability-duplicate-include.IgnoredFilesList: 'pack_.*\\.h'}}" \
+// RUN: -header-filter='' -- -I %S/Inputs/duplicate-include
+
+int g;
+#include "duplicate-include.h"
+int h;
+#include "duplicate-include.h"
+int i;
+// CHECK-MESSAGES: :[[@LINE-2]]:1: warning: duplicate include [readability-duplicate-include]
+// CHECK-FIXES: int g;
+// CHECK-FIXES-NEXT: #include "duplicate-include.h"
+// CHECK-FIXES-NEXT: int h;
+// CHECK-FIXES-NEXT: int i;
+
+#include "pack_begin.h"
+struct A { int x; };
+#include "pack_end.h"
+
+#include "pack_begin.h"
+struct B { int x; };
+#include "pack_end.h"
+
+// No warning here.
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/inconsistent-declaration-parameter-name.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/inconsistent-declaration-parameter-name.cpp
index 9822432..119a3c85 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/inconsistent-declaration-parameter-name.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/inconsistent-declaration-parameter-name.cpp
@@ -191,3 +191,26 @@ struct S {
void S::f(int y)
{
}
+
+//////////////////////////////////////////////////////
+
+template<typename... Args>
+void variadicFunctionNoWarning(Args... args);
+
+template<>
+void variadicFunctionNoWarning(int a) {}
+
+template<>
+void variadicFunctionNoWarning(int a, int b) {}
+
+template<typename... Args>
+void variadicFunction2WithWarning(int fixed, Args... args);
+
+template<>
+void variadicFunction2WithWarning(int fixed, int a) {}
+
+template<>
+// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: function template specialization 'variadicFunction2WithWarning<float>' has a primary template
+// CHECK-MESSAGES: :[[@LINE-7]]:6: note: the primary template declaration seen here
+// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('wrong'), in primary template declaration: ('fixed')
+void variadicFunction2WithWarning(int wrong, float a) {}
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-casting.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-casting.cpp
index fa91995..3e723b8 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-casting.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-casting.cpp
@@ -235,3 +235,13 @@ void testRedundantDependentNTTPCasting() {
// CHECK-MESSAGES: :[[@LINE-4]]:25: note: source type originates from referencing this non-type template parameter
// CHECK-FIXES: T a = V;
}
+
+namespace gh170476 {
+int f(void);
+int g1() {
+ int (*fp)() = (int(*)(void))&f;
+ // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: redundant explicit casting to the same type 'int (*)()' as the sub-expression, remove this casting [readability-redundant-casting]
+ // CHECK-FIXES: int (*fp)() = (&f);
+ return fp();
+}
+} // namespace gh170476
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-control-flow.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-control-flow.cpp
index 7764490..94e4fc6 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-control-flow.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-control-flow.cpp
@@ -7,16 +7,16 @@ void f() {
return;
}
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: redundant return statement at the end of a function with a void return type [readability-redundant-control-flow]
-// CHECK-FIXES: void f() {
-// CHECK-FIXES-NEXT: {{^ *}$}}
+// CHECK-FIXES: void f() {
+// CHECK-FIXES-NEXT: }
void g() {
f();
return;
}
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: redundant return statement
-// CHECK-FIXES: f();
-// CHECK-FIXES-NEXT: {{^ *}$}}
+// CHECK-FIXES: f();
+// CHECK-FIXES-NEXT: }
void g(int i) {
if (i < 0) {
@@ -40,8 +40,8 @@ void k() {
}
}
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement at the end of loop statement
-// CHECK-FIXES: for (int i = 0; i < 10; ++i) {
-// CHECK-FIXES-NEXT: {{^ *}$}}
+// CHECK-FIXES: for (int i = 0; i < 10; ++i) {
+// CHECK-FIXES-NEXT: }
void k2() {
int v[10] = { 0 };
@@ -50,8 +50,8 @@ void k2() {
}
}
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement
-// CHECK-FIXES: for (auto i : v) {
-// CHECK-FIXES-NEXT: {{^ *}$}}
+// CHECK-FIXES: for (auto i : v) {
+// CHECK-FIXES-NEXT: }
void m() {
int i = 0;
@@ -61,8 +61,8 @@ void m() {
} while (i < 10);
}
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement
-// CHECK-FIXES: {{^ do {$}}
-// CHECK-FIXES-NEXT: ++i;
+// CHECK-FIXES: do {
+// CHECK-FIXES-NEXT: ++i;
// CHECK-FIXES-NEXT: } while (i < 10);
void p() {
@@ -73,9 +73,9 @@ void p() {
}
}
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement
-// CHECK-FIXES: while (i < 10) {
-// CHECK-FIXES-NEXT: ++i;
-// CHECK-FIXES-NEXT: {{^ *}$}}
+// CHECK-FIXES: while (i < 10) {
+// CHECK-FIXES-NEXT: ++i;
+// CHECK-FIXES-NEXT: }
void im_not_dead(int i) {
if (i > 0) {
@@ -176,10 +176,10 @@ void template_return(T check) {
return;
}
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: redundant return statement
-// CHECK-FIXES: if (check < T(0)) {
-// CHECK-FIXES-NEXT: {{^ return;$}}
-// CHECK-FIXES-NEXT: {{^ *}$}}
-// CHECK-FIXES-NEXT: {{^ *}$}}
+// CHECK-FIXES: if (check < T(0)) {
+// CHECK-FIXES-NEXT: return;
+// CHECK-FIXES-NEXT: }
+// CHECK-FIXES-NEXT: }
template <>
void template_return(int check) {
@@ -189,10 +189,10 @@ void template_return(int check) {
return;
}
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: redundant return statement
-// CHECK-FIXES: if (check < 0) {
-// CHECK-FIXES-NEXT: {{^ return;$}}
-// CHECK-FIXES-NEXT: {{^ *}$}}
-// CHECK-FIXES-NEXT: {{^ *}$}}
+// CHECK-FIXES: if (check < 0) {
+// CHECK-FIXES-NEXT: return;
+// CHECK-FIXES-NEXT: }
+// CHECK-FIXES-NEXT: }
template <typename T>
void template_loop(T end) {
@@ -201,8 +201,8 @@ void template_loop(T end) {
}
}
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement
-// CHECK-FIXES: for (T i = 0; i < end; ++i) {
-// CHECK-FIXES-NEXT: {{^ *}$}}
+// CHECK-FIXES: for (T i = 0; i < end; ++i) {
+// CHECK-FIXES-NEXT: }
template <>
void template_loop(int end) {
@@ -211,8 +211,8 @@ void template_loop(int end) {
}
}
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement
-// CHECK-FIXES: for (int i = 0; i < end; ++i) {
-// CHECK-FIXES-NEXT: {{^ *}$}}
+// CHECK-FIXES: for (int i = 0; i < end; ++i) {
+// CHECK-FIXES-NEXT: }
void call_templates() {
template_return(10);
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-typename.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-typename.cpp
index 2efafd1..e8fcd9b 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-typename.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-typename.cpp
@@ -267,3 +267,27 @@ WHOLE_TYPE_IN_MACRO Macro2;
#define WHOLE_DECLARATION_IN_MACRO typename NotDependent::R Macro3
WHOLE_DECLARATION_IN_MACRO;
+
+template <typename T> struct Wrapper {};
+template <typename T>
+struct ClassWrapper {
+ using R = T;
+ Wrapper<R> f();
+};
+
+template <typename T>
+Wrapper<typename ClassWrapper<T>::R> ClassWrapper<T>::f() {
+ return {};
+}
+
+template <typename T> struct StructWrapper {};
+template <typename T>
+class ClassWithNestedStruct {
+ struct Nested {};
+ StructWrapper<Nested> f();
+};
+
+template <typename T>
+StructWrapper<typename ClassWithNestedStruct<T>::Nested> ClassWithNestedStruct<T>::f() {
+ return {};
+}
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/use-concise-preprocessor-directives.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/use-concise-preprocessor-directives.cpp
index 53e079b..b8a4953 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/use-concise-preprocessor-directives.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/use-concise-preprocessor-directives.cpp
@@ -30,6 +30,14 @@
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifdef' [readability-use-concise-preprocessor-directives]
// CHECK-FIXES: #ifdef FOO
+#if(defined(FOO))
+// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifdef' [readability-use-concise-preprocessor-directives]
+// CHECK-FIXES-23: #elifdef BAR
+#elif(defined(BAR))
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifdef' [readability-use-concise-preprocessor-directives]
+// CHECK-FIXES: #ifdef FOO
#if (defined FOO)
// CHECK-MESSAGES-23: :[[@LINE+2]]:4: warning: preprocessor condition can be written more concisely using '#elifdef' [readability-use-concise-preprocessor-directives]
// CHECK-FIXES-23: # elifdef BAR
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/use-std-min-max.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/use-std-min-max.cpp
index 35ade8a..3557018 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/use-std-min-max.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/use-std-min-max.cpp
@@ -273,3 +273,99 @@ void useRight() {
}
} // namespace gh121676
+
+void testComments() {
+ int box_depth = 10;
+ int max_depth = 5;
+
+ // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use `std::min` instead of `>` [readability-use-std-min-max]
+ // CHECK-FIXES: box_depth = std::min(box_depth, max_depth); // here
+ if (box_depth > max_depth) // here
+ {
+ box_depth = max_depth;
+ }
+
+ // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use `std::min` instead of `>` [readability-use-std-min-max]
+ // CHECK-FIXES: box_depth = std::min(box_depth, max_depth); /* here */
+ if (box_depth > max_depth) /* here */
+ {
+ box_depth = max_depth;
+ }
+
+ // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use `std::min` instead of `>` [readability-use-std-min-max]
+ // CHECK-FIXES: box_depth = std::min(box_depth, max_depth); // here
+ if (box_depth > max_depth)
+ // here
+ {
+ box_depth = max_depth;
+ }
+
+ // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use `std::min` instead of `>` [readability-use-std-min-max]
+ // CHECK-FIXES: box_depth = std::min(box_depth, max_depth); /* here */
+ if (box_depth > max_depth)
+ /* here */
+ {
+ box_depth = max_depth;
+ }
+
+ // CHECK-MESSAGES: :[[@LINE+4]]:3: warning: use `std::min` instead of `>` [readability-use-std-min-max]
+ // CHECK-FIXES: box_depth = std::min(box_depth, max_depth); /* here
+ // CHECK-FIXES-NEXT: and here
+ // CHECK-FIXES-NEXT: */
+ if (box_depth > max_depth) /* here
+ and here
+ */
+ {
+ box_depth = max_depth;
+ }
+
+ // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use `std::min` instead of `>` [readability-use-std-min-max]
+ // CHECK-FIXES: box_depth = std::min(box_depth, max_depth); /* here */
+ if (box_depth > max_depth) { /* here */
+ box_depth = max_depth;
+ }
+
+ // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use `std::min` instead of `>` [readability-use-std-min-max]
+ // CHECK-FIXES: box_depth = std::min(box_depth, max_depth); // here
+ if (box_depth > max_depth) { // here
+ box_depth = max_depth;
+ }
+
+ // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use `std::min` instead of `>` [readability-use-std-min-max]
+ // CHECK-FIXES: box_depth = std::min(box_depth, max_depth); /* here */
+ if (box_depth > max_depth) {
+ box_depth = max_depth; /* here */
+ }
+
+ // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use `std::min` instead of `>` [readability-use-std-min-max]
+ // CHECK-FIXES: box_depth = std::min(box_depth, max_depth); // here
+ if (box_depth > max_depth) {
+ box_depth = max_depth; // here
+ }
+
+ // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use `std::min` instead of `>` [readability-use-std-min-max]
+ // CHECK-FIXES: box_depth = std::min(box_depth, max_depth); /* here */
+ if (box_depth > max_depth) {
+ box_depth = max_depth;
+ /* here */
+ }
+
+ // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use `std::min` instead of `>` [readability-use-std-min-max]
+ // CHECK-FIXES: box_depth = std::min(box_depth, max_depth); // here
+ if (box_depth > max_depth) {
+ box_depth = max_depth;
+ // here
+ }
+
+ // CHECK-MESSAGES: :[[@LINE+5]]:3: warning: use `std::min` instead of `>` [readability-use-std-min-max]
+ // CHECK-FIXES: box_depth = std::min(box_depth, max_depth); // here
+ // CHECK-FIXES-NEXT: // and
+ // CHECK-FIXES-NEXT: /* there
+ // CHECK-FIXES-NEXT: again*/
+ if (box_depth > max_depth) {
+ // here
+ box_depth = max_depth; // and
+ /* there
+ again*/
+ }
+}
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/param/parameters.txt b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/param/parameters.txt
index a6d8fa7e..5cf5693 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/param/parameters.txt
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/param/parameters.txt
@@ -1,2 +1,2 @@
--checks='-*,llvm-namespace-comment'
+-checks=-*,llvm-namespace-comment
--warnings-as-errors=llvm-namespace-comment
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/alphabetical-order.test b/clang-tools-extra/test/clang-tidy/infrastructure/alphabetical-order.test
new file mode 100644
index 0000000..6cb0da7
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/alphabetical-order.test
@@ -0,0 +1,5 @@
+// RUN: %python %S/../../../clang-tidy/tool/check_alphabetical_order.py -o %t.clang-tidy-checks-list.rst
+// RUN: diff --strip-trailing-cr %S/../../../docs/clang-tidy/checks/list.rst %t.clang-tidy-checks-list.rst
+
+// RUN: %python %S/../../../clang-tidy/tool/check_alphabetical_order.py -o %t.ReleaseNotes.rst
+// RUN: diff --strip-trailing-cr %S/../../../docs/ReleaseNotes.rst %t.ReleaseNotes.rst
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/empty-database.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/empty-database.cpp
index c4c504c..0331dcc 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/empty-database.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/empty-database.cpp
@@ -1,5 +1,5 @@
// UNSUPPORTED: system-windows
-// RUN: clang-tidy -p %S/Inputs/empty-database %s 2>&1 | FileCheck %s
+// RUN: clang-tidy -checks='-*,clang-analyzer-*' -p %S/Inputs/empty-database %s 2>&1 | FileCheck %s
// CHECK: 'directory' field of compilation database is empty; using the current working directory instead.
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/invalid-database.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/invalid-database.cpp
index 7935385..ea9e102 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/invalid-database.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/invalid-database.cpp
@@ -1,5 +1,5 @@
// UNSUPPORTED: system-windows
-// RUN: not --crash clang-tidy -p %S/Inputs/invalid-database %s 2>&1 | FileCheck %s
+// RUN: not --crash clang-tidy -checks='-*,clang-analyzer-*' -p %S/Inputs/invalid-database %s 2>&1 | FileCheck %s
// CHECK: LLVM ERROR: Cannot chdir into "/invalid/"!
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-LIFO.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-LIFO.cpp
index ee5b1cc..e86b3df 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-LIFO.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-LIFO.cpp
@@ -1,11 +1,11 @@
-// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor,google-readability-casting' 2>&1 | FileCheck %s
+// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor,modernize-avoid-c-style-cast' 2>&1 | FileCheck %s
// NOLINTBEGIN(google-explicit-constructor)
-// NOLINTBEGIN(google-readability-casting)
+// NOLINTBEGIN(modernize-avoid-c-style-cast)
class A { A(int i); };
auto Num = (unsigned int)(-1);
// NOLINTEND(google-explicit-constructor)
-// NOLINTEND(google-readability-casting)
+// NOLINTEND(modernize-avoid-c-style-cast)
// Note: the expected output has been split over several lines so that clang-tidy
// does not see the "no lint" suppression comment and mistakenly assume it
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-multiple-end-single.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-multiple-end-single.cpp
index 150913c..156a5cb 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-multiple-end-single.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-multiple-end-single.cpp
@@ -1,10 +1,10 @@
-// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor,google-readability-casting' 2>&1 | FileCheck %s
+// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor,modernize-avoid-c-style-cast' 2>&1 | FileCheck %s
-// NOLINTBEGIN(google-explicit-constructor,google-readability-casting)
+// NOLINTBEGIN(google-explicit-constructor,modernize-avoid-c-style-cast)
class B { B(int i); };
// NOLINTEND(google-explicit-constructor)
auto Num2 = (unsigned int)(-1);
-// NOLINTEND(google-readability-casting)
+// NOLINTEND(modernize-avoid-c-style-cast)
// Note: the expected output has been split over several lines so that clang-tidy
// does not see the "no lint" suppression comment and mistakenly assume it
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-single-end-multiple.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-single-end-multiple.cpp
index f9a915c..8372132 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-single-end-multiple.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-single-end-multiple.cpp
@@ -1,10 +1,10 @@
-// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor,google-readability-casting' 2>&1 | FileCheck %s
+// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor,modernize-avoid-c-style-cast' 2>&1 | FileCheck %s
// NOLINTBEGIN(google-explicit-constructor)
-// NOLINTBEGIN(google-readability-casting)
+// NOLINTBEGIN(modernize-avoid-c-style-cast)
class B { B(int i); };
auto Num2 = (unsigned int)(-1);
-// NOLINTEND(google-explicit-constructor,google-readability-casting)
+// NOLINTEND(google-explicit-constructor,modernize-avoid-c-style-cast)
// Note: the expected output has been split over several lines so that clang-tidy
// does not see the "no lint" suppression comment and mistakenly assume it
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-check-names.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-check-names.cpp
index 8d7786f..ddd399d 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-check-names.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-check-names.cpp
@@ -1,9 +1,9 @@
-// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor,google-readability-casting' 2>&1 | FileCheck %s
+// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor,modernize-avoid-c-style-cast' 2>&1 | FileCheck %s
// NOLINTBEGIN(google-explicit-constructor)
class A { A(int i); };
auto Num = (unsigned int)(-1);
-// NOLINTEND(google-readability-casting)
+// NOLINTEND(modernize-avoid-c-style-cast)
// Note: the expected output has been split over several lines so that clang-tidy
// does not see the "no lint" suppression comment and mistakenly assume it
diff --git a/clang-tools-extra/test/lit.cfg.py b/clang-tools-extra/test/lit.cfg.py
index c1da37d..c39ea29 100644
--- a/clang-tools-extra/test/lit.cfg.py
+++ b/clang-tools-extra/test/lit.cfg.py
@@ -57,6 +57,7 @@ if config.clang_tidy_staticanalyzer:
if config.clang_tidy_custom_check:
config.available_features.add("custom-check")
python_exec = shlex.quote(config.python_executable)
+config.substitutions.append(("%python", python_exec))
check_clang_tidy = os.path.join(
config.test_source_root, "clang-tidy", "check_clang_tidy.py"
)
diff --git a/clang-tools-extra/test/pp-trace/pp-trace-include.cpp b/clang-tools-extra/test/pp-trace/pp-trace-include.cpp
index ea9896e..fccbd9b 100644
--- a/clang-tools-extra/test/pp-trace/pp-trace-include.cpp
+++ b/clang-tools-extra/test/pp-trace/pp-trace-include.cpp
@@ -39,7 +39,6 @@
// CHECK-NEXT: Reason: EnterFile
// CHECK-NEXT: FileType: C_User
// CHECK-NEXT: PrevFID: (invalid)
-// CHECK: - Callback: MacroDefined
// CHECK: - Callback: FileChanged
// CHECK-NEXT: Loc: "<built-in>:1:1"
// CHECK-NEXT: Reason: ExitFile
diff --git a/clang-tools-extra/test/pp-trace/pp-trace-macro.cpp b/clang-tools-extra/test/pp-trace/pp-trace-macro.cpp
index 7c2a231..5bd38e0 100644
--- a/clang-tools-extra/test/pp-trace/pp-trace-macro.cpp
+++ b/clang-tools-extra/test/pp-trace/pp-trace-macro.cpp
@@ -40,7 +40,6 @@ X
// CHECK-NEXT: MacroNameTok: __STDC_EMBED_EMPTY__
// CHECK-NEXT: MacroDirective: MD_Define
// CHECK: - Callback: MacroDefined
-// CHECK: - Callback: MacroDefined
// CHECK-NEXT: MacroNameTok: MACRO
// CHECK-NEXT: MacroDirective: MD_Define
// CHECK-NEXT: - Callback: MacroExpands
diff --git a/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp b/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
index d88b0c9..918c7b3 100644
--- a/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
@@ -10,6 +10,8 @@
#include "BitcodeWriter.h"
#include "ClangDocTest.h"
#include "Representation.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticOptions.h"
#include "llvm/Bitstream/BitstreamReader.h"
#include "llvm/Bitstream/BitstreamWriter.h"
#include "gtest/gtest.h"
@@ -17,41 +19,42 @@
namespace clang {
namespace doc {
-template <typename T> static std::string writeInfo(T &I) {
+template <typename T>
+static std::string writeInfo(T &I, DiagnosticsEngine &Diags) {
SmallString<2048> Buffer;
llvm::BitstreamWriter Stream(Buffer);
- ClangDocBitcodeWriter Writer(Stream);
+ ClangDocBitcodeWriter Writer(Stream, Diags);
Writer.emitBlock(I);
return Buffer.str().str();
}
-static std::string writeInfo(Info *I) {
+static std::string writeInfo(Info *I, DiagnosticsEngine &Diags) {
switch (I->IT) {
case InfoType::IT_namespace:
- return writeInfo(*static_cast<NamespaceInfo *>(I));
+ return writeInfo(*static_cast<NamespaceInfo *>(I), Diags);
case InfoType::IT_record:
- return writeInfo(*static_cast<RecordInfo *>(I));
+ return writeInfo(*static_cast<RecordInfo *>(I), Diags);
case InfoType::IT_enum:
- return writeInfo(*static_cast<EnumInfo *>(I));
+ return writeInfo(*static_cast<EnumInfo *>(I), Diags);
case InfoType::IT_function:
- return writeInfo(*static_cast<FunctionInfo *>(I));
+ return writeInfo(*static_cast<FunctionInfo *>(I), Diags);
case InfoType::IT_typedef:
- return writeInfo(*static_cast<TypedefInfo *>(I));
+ return writeInfo(*static_cast<TypedefInfo *>(I), Diags);
case InfoType::IT_concept:
- return writeInfo(*static_cast<ConceptInfo *>(I));
+ return writeInfo(*static_cast<ConceptInfo *>(I), Diags);
case InfoType::IT_variable:
- return writeInfo(*static_cast<VarInfo *>(I));
+ return writeInfo(*static_cast<VarInfo *>(I), Diags);
case InfoType::IT_friend:
- return writeInfo(*static_cast<FriendInfo *>(I));
+ return writeInfo(*static_cast<FriendInfo *>(I), Diags);
case InfoType::IT_default:
return "";
}
}
-static std::vector<std::unique_ptr<Info>> readInfo(StringRef Bitcode,
- size_t NumInfos) {
+static std::vector<std::unique_ptr<Info>>
+readInfo(StringRef Bitcode, size_t NumInfos, DiagnosticsEngine &Diags) {
llvm::BitstreamCursor Stream(Bitcode);
- doc::ClangDocBitcodeReader Reader(Stream);
+ doc::ClangDocBitcodeReader Reader(Stream, Diags);
auto Infos = Reader.readBitcode();
// Check that there was no error in the read.
@@ -60,7 +63,9 @@ static std::vector<std::unique_ptr<Info>> readInfo(StringRef Bitcode,
return std::move(Infos.get());
}
-TEST(BitcodeTest, emitNamespaceInfoBitcode) {
+class BitcodeTest : public ClangDocContextTest {};
+
+TEST_F(BitcodeTest, emitNamespaceInfoBitcode) {
NamespaceInfo I;
I.Name = "r";
I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
@@ -71,14 +76,15 @@ TEST(BitcodeTest, emitNamespaceInfoBitcode) {
I.Children.Functions.emplace_back();
I.Children.Enums.emplace_back();
- std::string WriteResult = writeInfo(&I);
+ std::string WriteResult = writeInfo(&I, this->Diags);
EXPECT_TRUE(WriteResult.size() > 0);
- std::vector<std::unique_ptr<Info>> ReadResults = readInfo(WriteResult, 1);
+ std::vector<std::unique_ptr<Info>> ReadResults =
+ readInfo(WriteResult, 1, this->Diags);
CheckNamespaceInfo(&I, InfoAsNamespace(ReadResults[0].get()));
}
-TEST(BitcodeTest, emitRecordInfoBitcode) {
+TEST_F(BitcodeTest, emitRecordInfoBitcode) {
RecordInfo I;
I.Name = "r";
I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
@@ -113,14 +119,15 @@ TEST(BitcodeTest, emitRecordInfoBitcode) {
I.Children.Functions.emplace_back();
I.Children.Enums.emplace_back();
- std::string WriteResult = writeInfo(&I);
+ std::string WriteResult = writeInfo(&I, this->Diags);
EXPECT_TRUE(WriteResult.size() > 0);
- std::vector<std::unique_ptr<Info>> ReadResults = readInfo(WriteResult, 1);
+ std::vector<std::unique_ptr<Info>> ReadResults =
+ readInfo(WriteResult, 1, this->Diags);
CheckRecordInfo(&I, InfoAsRecord(ReadResults[0].get()));
}
-TEST(BitcodeTest, emitFunctionInfoBitcode) {
+TEST_F(BitcodeTest, emitFunctionInfoBitcode) {
FunctionInfo I;
I.Name = "f";
I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
@@ -133,14 +140,15 @@ TEST(BitcodeTest, emitFunctionInfoBitcode) {
I.Access = AccessSpecifier::AS_none;
- std::string WriteResult = writeInfo(&I);
+ std::string WriteResult = writeInfo(&I, this->Diags);
EXPECT_TRUE(WriteResult.size() > 0);
- std::vector<std::unique_ptr<Info>> ReadResults = readInfo(WriteResult, 1);
+ std::vector<std::unique_ptr<Info>> ReadResults =
+ readInfo(WriteResult, 1, this->Diags);
CheckFunctionInfo(&I, InfoAsFunction(ReadResults[0].get()));
}
-TEST(BitcodeTest, emitMethodInfoBitcode) {
+TEST_F(BitcodeTest, emitMethodInfoBitcode) {
FunctionInfo I;
I.Name = "f";
I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
@@ -155,14 +163,15 @@ TEST(BitcodeTest, emitMethodInfoBitcode) {
I.Access = AccessSpecifier::AS_public;
- std::string WriteResult = writeInfo(&I);
+ std::string WriteResult = writeInfo(&I, this->Diags);
EXPECT_TRUE(WriteResult.size() > 0);
- std::vector<std::unique_ptr<Info>> ReadResults = readInfo(WriteResult, 1);
+ std::vector<std::unique_ptr<Info>> ReadResults =
+ readInfo(WriteResult, 1, this->Diags);
CheckFunctionInfo(&I, InfoAsFunction(ReadResults[0].get()));
}
-TEST(BitcodeTest, emitEnumInfoBitcode) {
+TEST_F(BitcodeTest, emitEnumInfoBitcode) {
EnumInfo I;
I.Name = "e";
I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
@@ -173,14 +182,15 @@ TEST(BitcodeTest, emitEnumInfoBitcode) {
I.Members.emplace_back("X");
I.Scoped = true;
- std::string WriteResult = writeInfo(&I);
+ std::string WriteResult = writeInfo(&I, this->Diags);
EXPECT_TRUE(WriteResult.size() > 0);
- std::vector<std::unique_ptr<Info>> ReadResults = readInfo(WriteResult, 1);
+ std::vector<std::unique_ptr<Info>> ReadResults =
+ readInfo(WriteResult, 1, this->Diags);
CheckEnumInfo(&I, InfoAsEnum(ReadResults[0].get()));
}
-TEST(BitcodeTest, emitTypedefInfoBitcode) {
+TEST_F(BitcodeTest, emitTypedefInfoBitcode) {
TypedefInfo I;
I.Name = "MyInt";
I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
@@ -200,9 +210,10 @@ TEST(BitcodeTest, emitTypedefInfoBitcode) {
I.Description.emplace_back(std::move(Top));
- std::string WriteResult = writeInfo(&I);
+ std::string WriteResult = writeInfo(&I, this->Diags);
EXPECT_TRUE(WriteResult.size() > 0);
- std::vector<std::unique_ptr<Info>> ReadResults = readInfo(WriteResult, 1);
+ std::vector<std::unique_ptr<Info>> ReadResults =
+ readInfo(WriteResult, 1, this->Diags);
CheckTypedefInfo(&I, InfoAsTypedef(ReadResults[0].get()));
@@ -212,13 +223,13 @@ TEST(BitcodeTest, emitTypedefInfoBitcode) {
I2.IsUsing = false;
I2.Underlying = TypeInfo("int");
- WriteResult = writeInfo(&I2);
+ WriteResult = writeInfo(&I2, this->Diags);
EXPECT_TRUE(WriteResult.size() > 0);
- ReadResults = readInfo(WriteResult, 1);
+ ReadResults = readInfo(WriteResult, 1, this->Diags);
CheckTypedefInfo(&I2, InfoAsTypedef(ReadResults[0].get()));
}
-TEST(SerializeTest, emitInfoWithCommentBitcode) {
+TEST_F(BitcodeTest, emitInfoWithCommentBitcode) {
FunctionInfo F;
F.Name = "F";
F.ReturnType = TypeInfo("void");
@@ -329,9 +340,10 @@ TEST(SerializeTest, emitInfoWithCommentBitcode) {
F.Description.emplace_back(std::move(Top));
- std::string WriteResult = writeInfo(&F);
+ std::string WriteResult = writeInfo(&F, this->Diags);
EXPECT_TRUE(WriteResult.size() > 0);
- std::vector<std::unique_ptr<Info>> ReadResults = readInfo(WriteResult, 1);
+ std::vector<std::unique_ptr<Info>> ReadResults =
+ readInfo(WriteResult, 1, this->Diags);
CheckFunctionInfo(&F, InfoAsFunction(ReadResults[0].get()));
}
diff --git a/clang-tools-extra/unittests/clang-doc/CMakeLists.txt b/clang-tools-extra/unittests/clang-doc/CMakeLists.txt
index 18166ac..01b34ec 100644
--- a/clang-tools-extra/unittests/clang-doc/CMakeLists.txt
+++ b/clang-tools-extra/unittests/clang-doc/CMakeLists.txt
@@ -26,7 +26,6 @@ add_extra_unittest(ClangDocTests
ClangDocTest.cpp
GeneratorTest.cpp
HTMLGeneratorTest.cpp
- HTMLMustacheGeneratorTest.cpp
MDGeneratorTest.cpp
MergeTest.cpp
SerializeTest.cpp
diff --git a/clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp b/clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
index f408c91..73891ab 100644
--- a/clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
@@ -9,11 +9,26 @@
#include "ClangDocTest.h"
#include "Representation.h"
#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Basic/DiagnosticOptions.h"
#include "gtest/gtest.h"
namespace clang {
namespace doc {
+ClangDocContextTest::ClangDocContextTest()
+ : DiagID(new DiagnosticIDs()),
+ Diags(DiagID, DiagOpts, new IgnoringDiagConsumer()) {}
+
+ClangDocContextTest::~ClangDocContextTest() = default;
+
+ClangDocContext ClangDocContextTest::getClangDocContext(
+ std::vector<std::string> UserStylesheets, StringRef RepositoryUrl,
+ StringRef RepositoryLinePrefix, StringRef Base) {
+ return ClangDocContext(nullptr, "test-project", false, "", "", RepositoryUrl,
+ RepositoryLinePrefix, Base, UserStylesheets, Diags,
+ false);
+}
+
NamespaceInfo *InfoAsNamespace(Info *I) {
assert(I->IT == InfoType::IT_namespace);
return static_cast<NamespaceInfo *>(I);
diff --git a/clang-tools-extra/unittests/clang-doc/ClangDocTest.h b/clang-tools-extra/unittests/clang-doc/ClangDocTest.h
index 2e189ca..2875cf1c 100644
--- a/clang-tools-extra/unittests/clang-doc/ClangDocTest.h
+++ b/clang-tools-extra/unittests/clang-doc/ClangDocTest.h
@@ -12,6 +12,8 @@
#include "ClangDocTest.h"
#include "Representation.h"
#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticOptions.h"
#include "gtest/gtest.h"
namespace clang {
@@ -49,6 +51,21 @@ void CheckBaseRecordInfo(BaseRecordInfo *Expected, BaseRecordInfo *Actual);
void CheckIndex(Index &Expected, Index &Actual);
+class ClangDocContextTest : public ::testing::Test {
+protected:
+ ClangDocContextTest();
+ ~ClangDocContextTest() override;
+
+ ClangDocContext
+ getClangDocContext(std::vector<std::string> UserStylesheets = {},
+ StringRef RepositoryUrl = "",
+ StringRef RepositoryLinePrefix = "", StringRef Base = "");
+
+ DiagnosticOptions DiagOpts;
+ llvm::IntrusiveRefCntPtr<DiagnosticIDs> DiagID;
+ DiagnosticsEngine Diags;
+};
+
} // namespace doc
} // namespace clang
diff --git a/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp b/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
index 14341435..cf510af 100644
--- a/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -9,484 +9,56 @@
#include "ClangDocTest.h"
#include "Generators.h"
#include "Representation.h"
+#include "config.h"
+#include "support/Utils.h"
#include "clang/Basic/Version.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gmock/gmock.h"
#include "gtest/gtest.h"
-namespace clang {
-namespace doc {
+using namespace llvm;
+using namespace testing;
+using namespace clang;
+using namespace clang::doc;
-static const std::string ClangDocVersion =
- clang::getClangToolFullVersion("clang-doc");
+static const std::string ClangDocVersion = getClangToolFullVersion("clang-doc");
static std::unique_ptr<Generator> getHTMLGenerator() {
- auto G = doc::findGeneratorByName("html");
+ auto G = findGeneratorByName("html");
if (!G)
return nullptr;
return std::move(G.get());
}
-static ClangDocContext
-getClangDocContext(std::vector<std::string> UserStylesheets = {},
- StringRef RepositoryUrl = "",
- StringRef RepositoryLinePrefix = "", StringRef Base = "") {
- ClangDocContext CDCtx{
- {}, "test-project", {}, {}, {}, RepositoryUrl, RepositoryLinePrefix,
- Base, UserStylesheets};
- CDCtx.UserStylesheets.insert(
- CDCtx.UserStylesheets.begin(),
- "../share/clang/clang-doc-default-stylesheet.css");
- CDCtx.JsScripts.emplace_back("index.js");
- return CDCtx;
-}
-
-TEST(HTMLGeneratorTest, emitNamespaceHTML) {
- NamespaceInfo I;
- I.Name = "Namespace";
- I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
-
- I.Children.Namespaces.emplace_back(EmptySID, "ChildNamespace",
- InfoType::IT_namespace,
- "Namespace::ChildNamespace", "Namespace");
- I.Children.Records.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
- "Namespace::ChildStruct", "Namespace");
- I.Children.Functions.emplace_back();
- I.Children.Functions.back().Access = AccessSpecifier::AS_none;
- I.Children.Functions.back().Name = "OneFunction";
- I.Children.Enums.emplace_back();
- I.Children.Enums.back().Name = "OneEnum";
-
- auto G = getHTMLGenerator();
- assert(G);
- std::string Buffer;
- llvm::raw_string_ostream Actual(Buffer);
- ClangDocContext CDCtx = getClangDocContext({"user-provided-stylesheet.css"});
- auto Err = G->generateDocForInfo(&I, Actual, CDCtx);
- assert(!Err);
- std::string Expected = R"raw(<!DOCTYPE html>
-<meta charset="utf-8"/>
-<title>namespace Namespace</title>
-<link rel="stylesheet" href="../clang-doc-default-stylesheet.css"/>
-<link rel="stylesheet" href="../user-provided-stylesheet.css"/>
-<script src="../index_json.js"></script>
-<script src="../index.js"></script>
-<header id="project-title">test-project</header>
-<main>
- <div id="sidebar-left" path="Namespace" class="col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas-left"></div>
- <div id="main-content" class="col-xs-12 col-sm-9 col-md-8 main-content">
- <h1>namespace Namespace</h1>
- <h2 id="Namespaces">Namespaces</h2>
- <ul>
- <li>
- <a href="ChildNamespace/index.html">ChildNamespace</a>
- </li>
- </ul>
- <h2 id="Records">Records</h2>
- <ul>
- <li>
- <a href="ChildStruct.html">ChildStruct</a>
- </li>
- </ul>
- <h2 id="Functions">Functions</h2>
- <div>
- <h3 id="0000000000000000000000000000000000000000">OneFunction</h3>
- <p>OneFunction()</p>
- </div>
- <h2 id="Enums">Enums</h2>
- <div>
- <table id="0000000000000000000000000000000000000000">
- <thead>
- <tr>
- <th colspan="2">enum OneEnum</th>
- </tr>
- </thead>
- </table>
- </div>
- </div>
- <div id="sidebar-right" class="col-xs-6 col-sm-6 col-md-2 sidebar sidebar-offcanvas-right">
- <ol>
- <li>
- <span>
- <a href="#Namespaces">Namespaces</a>
- </span>
- </li>
- <li>
- <span>
- <a href="#Records">Records</a>
- </span>
- </li>
- <li>
- <span>
- <a href="#Functions">Functions</a>
- </span>
- <ul>
- <li>
- <span>
- <a href="#0000000000000000000000000000000000000000">OneFunction</a>
- </span>
- </li>
- </ul>
- </li>
- <li>
- <span>
- <a href="#Enums">Enums</a>
- </span>
- <ul>
- <li>
- <span>
- <a href="#0000000000000000000000000000000000000000">OneEnum</a>
- </span>
- </li>
- </ul>
- </li>
- </ol>
- </div>
-</main>
-<footer>
- <span class="no-break">)raw" +
- ClangDocVersion + R"raw(</span>
-</footer>
-)raw";
-
- EXPECT_EQ(Expected, Actual.str());
-}
-
-TEST(HTMLGeneratorTest, emitRecordHTML) {
- RecordInfo I;
- I.Name = "r";
- I.Path = "X/Y/Z";
- I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
-
- I.DefLoc = Location(10, 10, "dir/test.cpp", true);
- I.Loc.emplace_back(12, 12, "test.cpp");
-
- SmallString<16> PathTo;
- llvm::sys::path::native("path/to", PathTo);
- I.Members.emplace_back(TypeInfo("int"), "X", AccessSpecifier::AS_private);
- I.TagType = TagTypeKind::Class;
- I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record, "F", PathTo);
- I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record);
-
- I.Children.Records.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
- "X::Y::Z::r::ChildStruct", "X/Y/Z/r");
- I.Children.Functions.emplace_back();
- I.Children.Functions.back().Name = "OneFunction";
- I.Children.Enums.emplace_back();
- I.Children.Enums.back().Name = "OneEnum";
-
- auto G = getHTMLGenerator();
- assert(G);
- std::string Buffer;
- llvm::raw_string_ostream Actual(Buffer);
- ClangDocContext CDCtx = getClangDocContext({}, "http://www.repository.com");
- auto Err = G->generateDocForInfo(&I, Actual, CDCtx);
- assert(!Err);
- std::string Expected = R"raw(<!DOCTYPE html>
-<meta charset="utf-8"/>
-<title>class r</title>
-<link rel="stylesheet" href="../../../clang-doc-default-stylesheet.css"/>
-<script src="../../../index_json.js"></script>
-<script src="../../../index.js"></script>
-<header id="project-title">test-project</header>
-<main>
- <div id="sidebar-left" path="X/Y/Z" class="col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas-left"></div>
- <div id="main-content" class="col-xs-12 col-sm-9 col-md-8 main-content">
- <h1>class r</h1>
- <p>
- Defined at line
- <a href="http://www.repository.com/dir/test.cpp#10">10</a>
- of file
- <a href="http://www.repository.com/dir/test.cpp">test.cpp</a>
- </p>
- <p>
- Inherits from
- <a href="../../../path/to/F.html">F</a>
- , G
- </p>
- <h2 id="Members">Members</h2>
- <ul>
- <li>
- <div>private int X</div>
- </li>
- </ul>
- <h2 id="Records">Records</h2>
- <ul>
- <li>
- <a href="../../../X/Y/Z/r/ChildStruct.html">ChildStruct</a>
- </li>
- </ul>
- <h2 id="Functions">Functions</h2>
- <div>
- <h3 id="0000000000000000000000000000000000000000">OneFunction</h3>
- <p>public OneFunction()</p>
- </div>
- <h2 id="Enums">Enums</h2>
- <div>
- <table id="0000000000000000000000000000000000000000">
- <thead>
- <tr>
- <th colspan="2">enum OneEnum</th>
- </tr>
- </thead>
- </table>
- </div>
- </div>
- <div id="sidebar-right" class="col-xs-6 col-sm-6 col-md-2 sidebar sidebar-offcanvas-right">
- <ol>
- <li>
- <span>
- <a href="#Members">Members</a>
- </span>
- </li>
- <li>
- <span>
- <a href="#Records">Records</a>
- </span>
- </li>
- <li>
- <span>
- <a href="#Functions">Functions</a>
- </span>
- <ul>
- <li>
- <span>
- <a href="#0000000000000000000000000000000000000000">OneFunction</a>
- </span>
- </li>
- </ul>
- </li>
- <li>
- <span>
- <a href="#Enums">Enums</a>
- </span>
- <ul>
- <li>
- <span>
- <a href="#0000000000000000000000000000000000000000">OneEnum</a>
- </span>
- </li>
- </ul>
- </li>
- </ol>
- </div>
-</main>
-<footer>
- <span class="no-break">)raw" +
- ClangDocVersion + R"raw(</span>
-</footer>
-)raw";
-
- EXPECT_EQ(Expected, Actual.str());
-}
-
-TEST(HTMLGeneratorTest, emitFunctionHTML) {
- FunctionInfo I;
- I.Name = "f";
- I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
-
- I.DefLoc = Location(10, 10, "dir/test.cpp", true);
- I.Loc.emplace_back(12, 12, "test.cpp");
-
- I.Access = AccessSpecifier::AS_none;
-
- SmallString<16> PathTo;
- llvm::sys::path::native("path/to", PathTo);
- I.ReturnType = TypeInfo(
- Reference(EmptySID, "float", InfoType::IT_default, "float", PathTo));
- I.Params.emplace_back(TypeInfo("int", PathTo), "P");
- I.IsMethod = true;
- I.Parent = Reference(EmptySID, "Parent", InfoType::IT_record);
-
+class HTMLGeneratorTest : public ClangDocContextTest {
+protected:
+ ClangDocContext
+ getClangDocContext(std::vector<std::string> UserStylesheets = {},
+ StringRef RepositoryUrl = "",
+ StringRef RepositoryLinePrefix = "", StringRef Base = "") {
+ ClangDocContext CDCtx{nullptr,
+ "test-project",
+ false,
+ "",
+ "",
+ RepositoryUrl,
+ RepositoryLinePrefix,
+ Base,
+ UserStylesheets,
+ Diags,
+ false};
+ CDCtx.UserStylesheets.insert(
+ CDCtx.UserStylesheets.begin(),
+ "../share/clang/clang-doc-default-stylesheet.css");
+ CDCtx.JsScripts.emplace_back("index.js");
+ return CDCtx;
+ }
+};
+
+TEST_F(HTMLGeneratorTest, createResources) {
auto G = getHTMLGenerator();
- assert(G);
- std::string Buffer;
- llvm::raw_string_ostream Actual(Buffer);
- ClangDocContext CDCtx = getClangDocContext({}, "https://www.repository.com");
- auto Err = G->generateDocForInfo(&I, Actual, CDCtx);
- assert(!Err);
- std::string Expected = R"raw(<!DOCTYPE html>
-<meta charset="utf-8"/>
-<title></title>
-<link rel="stylesheet" href="clang-doc-default-stylesheet.css"/>
-<script src="index_json.js"></script>
-<script src="index.js"></script>
-<header id="project-title">test-project</header>
-<main>
- <div id="sidebar-left" path="" class="col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas-left"></div>
- <div id="main-content" class="col-xs-12 col-sm-9 col-md-8 main-content">
- <h3 id="0000000000000000000000000000000000000000">f</h3>
- <p>
- <a href="path/to/float.html">float</a>
- f(
- <a href="path/to/int.html">int</a>
- P)
- </p>
- <p>
- Defined at line
- <a href="https://www.repository.com/dir/test.cpp#10">10</a>
- of file
- <a href="https://www.repository.com/dir/test.cpp">test.cpp</a>
- </p>
- </div>
- <div id="sidebar-right" class="col-xs-6 col-sm-6 col-md-2 sidebar sidebar-offcanvas-right"></div>
-</main>
-<footer>
- <span class="no-break">)raw" +
- ClangDocVersion + R"raw(</span>
-</footer>
-)raw";
-
- EXPECT_EQ(Expected, Actual.str());
-}
-
-TEST(HTMLGeneratorTest, emitEnumHTML) {
- EnumInfo I;
- I.Name = "e";
- I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
-
- I.DefLoc = Location(10, 10, "test.cpp", true);
- I.Loc.emplace_back(12, 12, "test.cpp");
-
- I.Members.emplace_back("X");
- I.Scoped = true;
-
- auto G = getHTMLGenerator();
- assert(G);
- std::string Buffer;
- llvm::raw_string_ostream Actual(Buffer);
- ClangDocContext CDCtx = getClangDocContext({}, "www.repository.com");
- auto Err = G->generateDocForInfo(&I, Actual, CDCtx);
- assert(!Err);
- std::string Expected = R"raw(<!DOCTYPE html>
-<meta charset="utf-8"/>
-<title></title>
-<link rel="stylesheet" href="clang-doc-default-stylesheet.css"/>
-<script src="index_json.js"></script>
-<script src="index.js"></script>
-<header id="project-title">test-project</header>
-<main>
- <div id="sidebar-left" path="" class="col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas-left"></div>
- <div id="main-content" class="col-xs-12 col-sm-9 col-md-8 main-content">
- <table id="0000000000000000000000000000000000000000">
- <thead>
- <tr>
- <th colspan="2">enum class e</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>X</td>
- <td>0</td>
- </tr>
- </tbody>
- </table>
- <p>
- Defined at line
- <a href="https://www.repository.com/test.cpp#10">10</a>
- of file
- <a href="https://www.repository.com/test.cpp">test.cpp</a>
- </p>
- </div>
- <div id="sidebar-right" class="col-xs-6 col-sm-6 col-md-2 sidebar sidebar-offcanvas-right"></div>
-</main>
-<footer>
- <span class="no-break">)raw" +
- ClangDocVersion + R"raw(</span>
-</footer>
-)raw";
-
- EXPECT_EQ(Expected, Actual.str());
-}
-
-TEST(HTMLGeneratorTest, emitCommentHTML) {
- FunctionInfo I;
- I.Name = "f";
- I.DefLoc = Location(10, 10, "test.cpp", true);
- I.ReturnType = TypeInfo("void");
- I.Params.emplace_back(TypeInfo("int"), "I");
- I.Params.emplace_back(TypeInfo("int"), "J");
- I.Access = AccessSpecifier::AS_none;
-
- CommentInfo Top;
- Top.Kind = CommentKind::CK_FullComment;
-
- Top.Children.emplace_back(std::make_unique<CommentInfo>());
- CommentInfo *BlankLine = Top.Children.back().get();
- BlankLine->Kind = CommentKind::CK_ParagraphComment;
- BlankLine->Children.emplace_back(std::make_unique<CommentInfo>());
- BlankLine->Children.back()->Kind = CommentKind::CK_TextComment;
-
- Top.Children.emplace_back(std::make_unique<CommentInfo>());
- CommentInfo *Brief = Top.Children.back().get();
- Brief->Kind = CommentKind::CK_ParagraphComment;
- Brief->Children.emplace_back(std::make_unique<CommentInfo>());
- Brief->Children.back()->Kind = CommentKind::CK_TextComment;
- Brief->Children.back()->Name = "ParagraphComment";
- Brief->Children.back()->Text = " Brief description.";
-
- Top.Children.emplace_back(std::make_unique<CommentInfo>());
- CommentInfo *Extended = Top.Children.back().get();
- Extended->Kind = CommentKind::CK_ParagraphComment;
- Extended->Children.emplace_back(std::make_unique<CommentInfo>());
- Extended->Children.back()->Kind = CommentKind::CK_TextComment;
- Extended->Children.back()->Text = " Extended description that";
- Extended->Children.emplace_back(std::make_unique<CommentInfo>());
- Extended->Children.back()->Kind = CommentKind::CK_TextComment;
- Extended->Children.back()->Text = " continues onto the next line.";
-
- Top.Children.emplace_back(std::make_unique<CommentInfo>());
- CommentInfo *Entities = Top.Children.back().get();
- Entities->Kind = CommentKind::CK_ParagraphComment;
- Entities->Children.emplace_back(std::make_unique<CommentInfo>());
- Entities->Children.back()->Kind = CommentKind::CK_TextComment;
- Entities->Children.back()->Name = "ParagraphComment";
- Entities->Children.back()->Text =
- " Comment with html entities: &, <, >, \", \'.";
-
- I.Description.emplace_back(std::move(Top));
-
- auto G = getHTMLGenerator();
- assert(G);
- std::string Buffer;
- llvm::raw_string_ostream Actual(Buffer);
+ ASSERT_THAT(G, NotNull()) << "Could not find HTMLGenerator";
ClangDocContext CDCtx = getClangDocContext();
- auto Err = G->generateDocForInfo(&I, Actual, CDCtx);
- assert(!Err);
- std::string Expected = R"raw(<!DOCTYPE html>
-<meta charset="utf-8"/>
-<title></title>
-<link rel="stylesheet" href="clang-doc-default-stylesheet.css"/>
-<script src="index_json.js"></script>
-<script src="index.js"></script>
-<header id="project-title">test-project</header>
-<main>
- <div id="sidebar-left" path="" class="col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas-left"></div>
- <div id="main-content" class="col-xs-12 col-sm-9 col-md-8 main-content">
- <h3 id="0000000000000000000000000000000000000000">f</h3>
- <p>void f(int I, int J)</p>
- <p>
- Defined at line
- <a href="test.cpp#10">10</a>
- of file
- <a href="test.cpp">test.cpp</a>
- </p>
- <div>
- <div>
- <p> Brief description.</p>
- <p> Extended description that continues onto the next line.</p>
- <p> Comment with html entities: &amp;, &lt;, &gt;, &quot;, &apos;.</p>
- </div>
- </div>
- </div>
- <div id="sidebar-right" class="col-xs-6 col-sm-6 col-md-2 sidebar sidebar-offcanvas-right"></div>
-</main>
-<footer>
- <span class="no-break">)raw" +
- ClangDocVersion + R"raw(</span>
-</footer>
-)raw";
-
- EXPECT_EQ(Expected, Actual.str());
+ EXPECT_THAT_ERROR(G->createResources(CDCtx), Failed())
+ << "Empty UserStylesheets or JsScripts should fail!";
}
-
-} // namespace doc
-} // namespace clang
diff --git a/clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp b/clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp
deleted file mode 100644
index c7ac387..0000000
--- a/clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-//===-- clang-doc/HTMLMustacheGeneratorTest.cpp ---------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "ClangDocTest.h"
-#include "Generators.h"
-#include "Representation.h"
-#include "config.h"
-#include "support/Utils.h"
-#include "clang/Basic/Version.h"
-#include "llvm/Testing/Support/Error.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
-
-using namespace llvm;
-using namespace testing;
-using namespace clang;
-using namespace clang::doc;
-
-// FIXME: Don't enable unit tests that can read files. Remove once we can use
-// lit to test these properties.
-#define ENABLE_LOCAL_TEST 0
-
-static const std::string ClangDocVersion = getClangToolFullVersion("clang-doc");
-
-static std::unique_ptr<Generator> getHTMLMustacheGenerator() {
- auto G = findGeneratorByName("mustache");
- if (!G)
- return nullptr;
- return std::move(G.get());
-}
-
-static ClangDocContext
-getClangDocContext(std::vector<std::string> UserStylesheets = {},
- StringRef RepositoryUrl = "",
- StringRef RepositoryLinePrefix = "", StringRef Base = "") {
- ClangDocContext CDCtx{
- {}, "test-project", {}, {}, {}, RepositoryUrl, RepositoryLinePrefix,
- Base, UserStylesheets};
- CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(), "");
- CDCtx.JsScripts.emplace_back("");
- return CDCtx;
-}
-
-TEST(HTMLMustacheGeneratorTest, createResources) {
- auto G = getHTMLMustacheGenerator();
- ASSERT_THAT(G, NotNull()) << "Could not find HTMLMustacheGenerator";
- ClangDocContext CDCtx = getClangDocContext();
- EXPECT_THAT_ERROR(G->createResources(CDCtx), Failed())
- << "Empty UserStylesheets or JsScripts should fail!";
-}
diff --git a/clang-tools-extra/unittests/clang-doc/JSONGeneratorTest.cpp b/clang-tools-extra/unittests/clang-doc/JSONGeneratorTest.cpp
index 07c761f..bd43755 100644
--- a/clang-tools-extra/unittests/clang-doc/JSONGeneratorTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/JSONGeneratorTest.cpp
@@ -13,11 +13,11 @@ static std::unique_ptr<Generator> getJSONGenerator() {
return std::move(G.get());
}
-TEST(JSONGeneratorTest, emitRecordJSON) {
+class JSONGeneratorTest : public ClangDocContextTest {};
+
+TEST_F(JSONGeneratorTest, emitRecordJSON) {
RecordInfo I;
I.Name = "Foo";
- // FIXME: FullName is not emitted correctly.
- I.FullName = "";
I.IsTypeDef = false;
I.Namespace.emplace_back(EmptySID, "GlobalNamespace", InfoType::IT_namespace);
I.Path = "GlobalNamespace";
@@ -57,14 +57,13 @@ TEST(JSONGeneratorTest, emitRecordJSON) {
assert(G);
std::string Buffer;
llvm::raw_string_ostream Actual(Buffer);
- auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
+ auto Err = G->generateDocForInfo(&I, Actual, getClangDocContext());
assert(!Err);
std::string Expected = R"raw({
"Bases": [
{
"Access": "public",
"End": true,
- "FullName": "",
"HasPublicFunctions": true,
"HasPublicMembers": true,
"InfoType": "record",
@@ -115,7 +114,6 @@ TEST(JSONGeneratorTest, emitRecordJSON) {
"USR": "0000000000000000000000000000000000000000"
}
],
- "FullName": "",
"HasEnums": true,
"HasPublicFunctions": true,
"HasRecords": true,
@@ -190,7 +188,7 @@ TEST(JSONGeneratorTest, emitRecordJSON) {
EXPECT_EQ(Expected, Actual.str());
}
-TEST(JSONGeneratorTest, emitNamespaceJSON) {
+TEST_F(JSONGeneratorTest, emitNamespaceJSON) {
NamespaceInfo I;
I.Name = "Namespace";
I.Path = "path/to/A";
@@ -212,7 +210,7 @@ TEST(JSONGeneratorTest, emitNamespaceJSON) {
assert(G);
std::string Buffer;
llvm::raw_string_ostream Actual(Buffer);
- auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
+ auto Err = G->generateDocForInfo(&I, Actual, getClangDocContext());
assert(!Err);
std::string Expected = R"raw({
"Enums": [
diff --git a/clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp b/clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
index f4c69cf..b44b09b 100644
--- a/clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
@@ -21,7 +21,9 @@ static std::unique_ptr<Generator> getMDGenerator() {
return std::move(G.get());
}
-TEST(MDGeneratorTest, emitNamespaceMD) {
+class MDGeneratorTest : public ClangDocContextTest {};
+
+TEST_F(MDGeneratorTest, emitNamespaceMD) {
NamespaceInfo I;
I.Name = "Namespace";
I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
@@ -39,7 +41,7 @@ TEST(MDGeneratorTest, emitNamespaceMD) {
assert(G);
std::string Buffer;
llvm::raw_string_ostream Actual(Buffer);
- auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
+ auto Err = G->generateDocForInfo(&I, Actual, getClangDocContext());
assert(!Err);
std::string Expected = R"raw(# namespace Namespace
@@ -77,7 +79,7 @@ TEST(MDGeneratorTest, emitNamespaceMD) {
EXPECT_EQ(Expected, Actual.str());
}
-TEST(MDGeneratorTest, emitRecordMD) {
+TEST_F(MDGeneratorTest, emitRecordMD) {
RecordInfo I;
I.Name = "r";
I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
@@ -100,7 +102,7 @@ TEST(MDGeneratorTest, emitRecordMD) {
assert(G);
std::string Buffer;
llvm::raw_string_ostream Actual(Buffer);
- auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
+ auto Err = G->generateDocForInfo(&I, Actual, getClangDocContext());
assert(!Err);
std::string Expected = R"raw(# class r
@@ -144,7 +146,7 @@ ChildStruct
EXPECT_EQ(Expected, Actual.str());
}
-TEST(MDGeneratorTest, emitFunctionMD) {
+TEST_F(MDGeneratorTest, emitFunctionMD) {
FunctionInfo I;
I.Name = "f";
I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
@@ -163,7 +165,7 @@ TEST(MDGeneratorTest, emitFunctionMD) {
assert(G);
std::string Buffer;
llvm::raw_string_ostream Actual(Buffer);
- auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
+ auto Err = G->generateDocForInfo(&I, Actual, getClangDocContext());
assert(!Err);
std::string Expected = R"raw(### f
@@ -176,7 +178,7 @@ TEST(MDGeneratorTest, emitFunctionMD) {
EXPECT_EQ(Expected, Actual.str());
}
-TEST(MDGeneratorTest, emitEnumMD) {
+TEST_F(MDGeneratorTest, emitEnumMD) {
EnumInfo I;
I.Name = "e";
I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
@@ -191,7 +193,7 @@ TEST(MDGeneratorTest, emitEnumMD) {
assert(G);
std::string Buffer;
llvm::raw_string_ostream Actual(Buffer);
- auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
+ auto Err = G->generateDocForInfo(&I, Actual, getClangDocContext());
assert(!Err);
std::string Expected = R"raw(| enum class e |
@@ -207,7 +209,7 @@ TEST(MDGeneratorTest, emitEnumMD) {
EXPECT_EQ(Expected, Actual.str());
}
-TEST(MDGeneratorTest, emitCommentMD) {
+TEST_F(MDGeneratorTest, emitCommentMD) {
FunctionInfo I;
I.Name = "f";
@@ -325,7 +327,7 @@ TEST(MDGeneratorTest, emitCommentMD) {
assert(G);
std::string Buffer;
llvm::raw_string_ostream Actual(Buffer);
- auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
+ auto Err = G->generateDocForInfo(&I, Actual, getClangDocContext());
assert(!Err);
std::string Expected =
R"raw(### f
diff --git a/clang-tools-extra/unittests/clang-doc/MergeTest.cpp b/clang-tools-extra/unittests/clang-doc/MergeTest.cpp
index ade744e..6bffd98 100644
--- a/clang-tools-extra/unittests/clang-doc/MergeTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/MergeTest.cpp
@@ -13,7 +13,9 @@
namespace clang {
namespace doc {
-TEST(MergeTest, mergeNamespaceInfos) {
+class MergeTest : public ClangDocContextTest {};
+
+TEST_F(MergeTest, mergeNamespaceInfos) {
NamespaceInfo One;
One.Name = "Namespace";
One.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
@@ -75,7 +77,7 @@ TEST(MergeTest, mergeNamespaceInfos) {
InfoAsNamespace(Actual.get().get()));
}
-TEST(MergeTest, mergeRecordInfos) {
+TEST_F(MergeTest, mergeRecordInfos) {
RecordInfo One;
One.Name = "r";
One.IsTypeDef = true;
@@ -153,7 +155,7 @@ TEST(MergeTest, mergeRecordInfos) {
InfoAsRecord(Actual.get().get()));
}
-TEST(MergeTest, mergeFunctionInfos) {
+TEST_F(MergeTest, mergeFunctionInfos) {
FunctionInfo One;
One.Name = "f";
One.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
@@ -228,7 +230,7 @@ TEST(MergeTest, mergeFunctionInfos) {
InfoAsFunction(Actual.get().get()));
}
-TEST(MergeTest, mergeEnumInfos) {
+TEST_F(MergeTest, mergeEnumInfos) {
EnumInfo One;
One.Name = "e";
One.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
diff --git a/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp b/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
index 6d5e7da6..f59ea02 100644
--- a/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -16,6 +16,8 @@
namespace clang {
namespace doc {
+class SerializeTest : public ClangDocContextTest {};
+
class ClangDocSerializeTestVisitor
: public RecursiveASTVisitor<ClangDocSerializeTestVisitor> {
@@ -32,7 +34,8 @@ class ClangDocSerializeTestVisitor
}
public:
- ClangDocSerializeTestVisitor(EmittedInfoList &EmittedInfos, bool Public)
+ ClangDocSerializeTestVisitor(EmittedInfoList &EmittedInfos, bool Public,
+ DiagnosticsEngine &Diags)
: EmittedInfos(EmittedInfos), Public(Public) {}
template <typename T> bool mapDecl(const T *D) {
@@ -49,7 +52,7 @@ public:
bool VisitFunctionDecl(const FunctionDecl *D) {
// Don't visit CXXMethodDecls twice
- if (dyn_cast<CXXMethodDecl>(D))
+ if (isa<CXXMethodDecl>(D))
return true;
return mapDecl(D);
}
@@ -65,21 +68,24 @@ public:
bool VisitTypeAliasDecl(const TypeAliasDecl *D) { return mapDecl(D); }
};
-void ExtractInfosFromCode(StringRef Code, size_t NumExpectedInfos, bool Public,
- EmittedInfoList &EmittedInfos) {
+static void extractInfosFromCode(StringRef Code, size_t NumExpectedInfos,
+ bool Public, EmittedInfoList &EmittedInfos,
+ DiagnosticsEngine &Diags) {
auto ASTUnit = clang::tooling::buildASTFromCode(Code);
- auto TU = ASTUnit->getASTContext().getTranslationUnitDecl();
- ClangDocSerializeTestVisitor Visitor(EmittedInfos, Public);
+ TranslationUnitDecl *TU = ASTUnit->getASTContext().getTranslationUnitDecl();
+ ClangDocSerializeTestVisitor Visitor(EmittedInfos, Public, Diags);
Visitor.TraverseTranslationUnitDecl(TU);
ASSERT_EQ(NumExpectedInfos, EmittedInfos.size());
}
-void ExtractInfosFromCodeWithArgs(StringRef Code, size_t NumExpectedInfos,
- bool Public, EmittedInfoList &EmittedInfos,
- std::vector<std::string> &Args) {
+static void extractInfosFromCodeWithArgs(StringRef Code,
+ size_t NumExpectedInfos, bool Public,
+ EmittedInfoList &EmittedInfos,
+ std::vector<std::string> &Args,
+ DiagnosticsEngine &Diags) {
auto ASTUnit = clang::tooling::buildASTFromCodeWithArgs(Code, Args);
- auto TU = ASTUnit->getASTContext().getTranslationUnitDecl();
- ClangDocSerializeTestVisitor Visitor(EmittedInfos, Public);
+ TranslationUnitDecl *TU = ASTUnit->getASTContext().getTranslationUnitDecl();
+ ClangDocSerializeTestVisitor Visitor(EmittedInfos, Public, Diags);
Visitor.TraverseTranslationUnitDecl(TU);
ASSERT_EQ(NumExpectedInfos, EmittedInfos.size());
}
@@ -105,10 +111,10 @@ CommentInfo MakeOneLineCommentInfo(const std::string &Text) {
*/
// Test serialization of namespace declarations.
-TEST(SerializeTest, emitNamespaceInfo) {
+TEST_F(SerializeTest, emitNamespaceInfo) {
EmittedInfoList Infos;
- ExtractInfosFromCode("namespace A { namespace B { void f() {} } }", 5,
- /*Public=*/false, Infos);
+ extractInfosFromCode("namespace A { namespace B { void f() {} } }", 5,
+ /*Public=*/false, Infos, this->Diags);
NamespaceInfo *A = InfoAsNamespace(Infos[0].get());
NamespaceInfo ExpectedA(EmptySID, "A");
@@ -132,9 +138,10 @@ TEST(SerializeTest, emitNamespaceInfo) {
CheckNamespaceInfo(&ExpectedBWithFunction, BWithFunction);
}
-TEST(SerializeTest, emitAnonymousNamespaceInfo) {
+TEST_F(SerializeTest, emitAnonymousNamespaceInfo) {
EmittedInfoList Infos;
- ExtractInfosFromCode("namespace { }", 2, /*Public=*/false, Infos);
+ extractInfosFromCode("namespace { }", 2, /*Public=*/false, Infos,
+ this->Diags);
NamespaceInfo *A = InfoAsNamespace(Infos[0].get());
NamespaceInfo ExpectedA(EmptySID);
@@ -142,10 +149,9 @@ TEST(SerializeTest, emitAnonymousNamespaceInfo) {
CheckNamespaceInfo(&ExpectedA, A);
}
-// Test serialization of record declarations.
-TEST(SerializeTest, emitRecordInfo) {
+TEST_F(SerializeTest, emitRecordInfo) {
EmittedInfoList Infos;
- ExtractInfosFromCode(R"raw(class E {
+ extractInfosFromCode(R"raw(class E {
public:
E() {}
@@ -161,7 +167,7 @@ struct F {
template <>
void F<int>::TemplateMethod();
typedef struct {} G;)raw",
- 10, /*Public=*/false, Infos);
+ 10, /*Public=*/false, Infos, this->Diags);
RecordInfo *E = InfoAsRecord(Infos[0].get());
RecordInfo ExpectedE(EmptySID, /*Name=*/"E", /*Path=*/"GlobalNamespace");
@@ -259,10 +265,10 @@ typedef struct {} G;)raw",
}
// Test serialization of enum declarations.
-TEST(SerializeTest, emitEnumInfo) {
+TEST_F(SerializeTest, emitEnumInfo) {
EmittedInfoList Infos;
- ExtractInfosFromCode("enum E { X, Y }; enum class G { A, B };", 2,
- /*Public=*/false, Infos);
+ extractInfosFromCode("enum E { X, Y }; enum class G { A, B };", 2,
+ /*Public=*/false, Infos, this->Diags);
NamespaceInfo *NamespaceWithEnum = InfoAsNamespace(Infos[0].get());
NamespaceInfo ExpectedNamespaceWithEnum(EmptySID);
@@ -286,9 +292,9 @@ TEST(SerializeTest, emitEnumInfo) {
CheckNamespaceInfo(&ExpectedNamespaceWithScopedEnum, NamespaceWithScopedEnum);
}
-TEST(SerializeTest, emitUndefinedRecordInfo) {
+TEST_F(SerializeTest, emitUndefinedRecordInfo) {
EmittedInfoList Infos;
- ExtractInfosFromCode("class E;", 2, /*Public=*/false, Infos);
+ extractInfosFromCode("class E;", 2, /*Public=*/false, Infos, this->Diags);
RecordInfo *E = InfoAsRecord(Infos[0].get());
RecordInfo ExpectedE(EmptySID, /*Name=*/"E", /*Path=*/"GlobalNamespace");
@@ -299,9 +305,10 @@ TEST(SerializeTest, emitUndefinedRecordInfo) {
CheckRecordInfo(&ExpectedE, E);
}
-TEST(SerializeTest, emitRecordMemberInfo) {
+TEST_F(SerializeTest, emitRecordMemberInfo) {
EmittedInfoList Infos;
- ExtractInfosFromCode("struct E { int I; };", 2, /*Public=*/false, Infos);
+ extractInfosFromCode("struct E { int I; };", 2, /*Public=*/false, Infos,
+ this->Diags);
RecordInfo *E = InfoAsRecord(Infos[0].get());
RecordInfo ExpectedE(EmptySID, /*Name=*/"E", /*Path=*/"GlobalNamespace");
@@ -314,9 +321,10 @@ TEST(SerializeTest, emitRecordMemberInfo) {
CheckRecordInfo(&ExpectedE, E);
}
-TEST(SerializeTest, emitInternalRecordInfo) {
+TEST_F(SerializeTest, emitInternalRecordInfo) {
EmittedInfoList Infos;
- ExtractInfosFromCode("class E { class G {}; };", 4, /*Public=*/false, Infos);
+ extractInfosFromCode("class E { class G {}; };", 4, /*Public=*/false, Infos,
+ this->Diags);
RecordInfo *E = InfoAsRecord(Infos[0].get());
RecordInfo ExpectedE(EmptySID, /*Name=*/"E", /*Path=*/"GlobalNamespace");
@@ -338,15 +346,16 @@ TEST(SerializeTest, emitInternalRecordInfo) {
CheckRecordInfo(&ExpectedG, G);
}
-TEST(SerializeTest, emitPublicAnonymousNamespaceInfo) {
+TEST_F(SerializeTest, emitPublicAnonymousNamespaceInfo) {
EmittedInfoList Infos;
- ExtractInfosFromCode("namespace { class A; }", 0, /*Public=*/true, Infos);
+ extractInfosFromCode("namespace { class A; }", 0, /*Public=*/true, Infos,
+ this->Diags);
}
-TEST(SerializeTest, emitPublicFunctionInternalInfo) {
+TEST_F(SerializeTest, emitPublicFunctionInternalInfo) {
EmittedInfoList Infos;
- ExtractInfosFromCode("int F() { class G {}; return 0; };", 1, /*Public=*/true,
- Infos);
+ extractInfosFromCode("int F() { class G {}; return 0; };", 1, /*Public=*/true,
+ Infos, this->Diags);
NamespaceInfo *BWithFunction = InfoAsNamespace(Infos[0].get());
NamespaceInfo ExpectedBWithFunction(EmptySID);
@@ -359,9 +368,10 @@ TEST(SerializeTest, emitPublicFunctionInternalInfo) {
CheckNamespaceInfo(&ExpectedBWithFunction, BWithFunction);
}
-TEST(SerializeTest, emitInlinedFunctionInfo) {
+TEST_F(SerializeTest, emitInlinedFunctionInfo) {
EmittedInfoList Infos;
- ExtractInfosFromCode("inline void F(int I) { };", 1, /*Public=*/true, Infos);
+ extractInfosFromCode("inline void F(int I) { };", 1, /*Public=*/true, Infos,
+ this->Diags);
NamespaceInfo *BWithFunction = InfoAsNamespace(Infos[0].get());
NamespaceInfo ExpectedBWithFunction(EmptySID);
@@ -375,16 +385,16 @@ TEST(SerializeTest, emitInlinedFunctionInfo) {
CheckNamespaceInfo(&ExpectedBWithFunction, BWithFunction);
}
-TEST(SerializeTest, emitInheritedRecordInfo) {
+TEST_F(SerializeTest, emitInheritedRecordInfo) {
EmittedInfoList Infos;
- ExtractInfosFromCode(R"raw(class F { protected: void set(int N); };
+ extractInfosFromCode(R"raw(class F { protected: void set(int N); };
class G { public: int get() { return 1; } protected: int I; };
class E : public F, virtual private G {};
class H : private E {};
template <typename T>
class I {} ;
class J : public I<int> {} ;)raw",
- 14, /*Public=*/false, Infos);
+ 14, /*Public=*/false, Infos, this->Diags);
RecordInfo *F = InfoAsRecord(Infos[0].get());
RecordInfo ExpectedF(EmptySID, /*Name=*/"F", /*Path=*/"GlobalNamespace");
@@ -517,15 +527,15 @@ class J : public I<int> {} ;)raw",
CheckRecordInfo(&ExpectedJ, J);
}
-TEST(SerializeTest, emitModulePublicLFunctions) {
+TEST_F(SerializeTest, emitModulePublicLFunctions) {
EmittedInfoList Infos;
std::vector<std::string> Args;
Args.push_back("-fmodules-ts");
- ExtractInfosFromCodeWithArgs(R"raw(export module M;
+ extractInfosFromCodeWithArgs(R"raw(export module M;
int moduleFunction(int x, double d = 3.2 - 1.0);
static int staticModuleFunction(int x);
export double exportedModuleFunction(double y);)raw",
- 2, /*Public=*/true, Infos, Args);
+ 2, /*Public=*/true, Infos, Args, this->Diags);
NamespaceInfo *BWithFunction = InfoAsNamespace(Infos[0].get());
NamespaceInfo ExpectedBWithFunction(EmptySID);
@@ -555,10 +565,10 @@ export double exportedModuleFunction(double y);)raw",
}
// Test serialization of child records in namespaces and other records
-TEST(SerializeTest, emitChildRecords) {
+TEST_F(SerializeTest, emitChildRecords) {
EmittedInfoList Infos;
- ExtractInfosFromCode("class A { class B {}; }; namespace { class C {}; } ", 8,
- /*Public=*/false, Infos);
+ extractInfosFromCode("class A { class B {}; }; namespace { class C {}; } ", 8,
+ /*Public=*/false, Infos, this->Diags);
NamespaceInfo *ParentA = InfoAsNamespace(Infos[1].get());
NamespaceInfo ExpectedParentA(EmptySID);
@@ -582,10 +592,10 @@ TEST(SerializeTest, emitChildRecords) {
}
// Test serialization of child namespaces
-TEST(SerializeTest, emitChildNamespaces) {
+TEST_F(SerializeTest, emitChildNamespaces) {
EmittedInfoList Infos;
- ExtractInfosFromCode("namespace A { namespace B { } }", 4, /*Public=*/false,
- Infos);
+ extractInfosFromCode("namespace A { namespace B { } }", 4, /*Public=*/false,
+ Infos, this->Diags);
NamespaceInfo *ParentA = InfoAsNamespace(Infos[1].get());
NamespaceInfo ExpectedParentA(EmptySID);
@@ -600,10 +610,10 @@ TEST(SerializeTest, emitChildNamespaces) {
CheckNamespaceInfo(&ExpectedParentB, ParentB);
}
-TEST(SerializeTests, emitTypedefs) {
+TEST_F(SerializeTest, emitTypedefs) {
EmittedInfoList Infos;
- ExtractInfosFromCode("typedef int MyInt; using MyDouble = double;", 2,
- /*Public=*/false, Infos);
+ extractInfosFromCode("typedef int MyInt; using MyDouble = double;", 2,
+ /*Public=*/false, Infos, this->Diags);
// First info will be the global namespace with the typedef in it.
NamespaceInfo *GlobalNS1 = InfoAsNamespace(Infos[0].get());
@@ -627,13 +637,13 @@ TEST(SerializeTests, emitTypedefs) {
EXPECT_EQ("double", SecondTD.Underlying.Type.Name);
}
-TEST(SerializeTests, emitFunctionTemplate) {
+TEST_F(SerializeTest, emitFunctionTemplate) {
EmittedInfoList Infos;
// A template and a specialization.
- ExtractInfosFromCode("template<typename T = int> bool GetFoo(T);\n"
+ extractInfosFromCode("template<typename T = int> bool GetFoo(T);\n"
"template<> bool GetFoo<bool>(bool);",
2,
- /*Public=*/false, Infos);
+ /*Public=*/false, Infos, this->Diags);
// First info will be the global namespace.
NamespaceInfo *GlobalNS1 = InfoAsNamespace(Infos[0].get());
@@ -669,18 +679,18 @@ TEST(SerializeTests, emitFunctionTemplate) {
EXPECT_EQ("bool", Func2.ReturnType.Type.Name);
}
-TEST(SerializeTests, emitClassTemplate) {
+TEST_F(SerializeTest, emitClassTemplate) {
EmittedInfoList Infos;
// This will generate 2x the number of infos: each Record will be followed by
// a copy of the global namespace containing it (this test checks the data
// pre-merge).
- ExtractInfosFromCode(
+ extractInfosFromCode(
"template<int I> class MyTemplate { int i[I]; };\n"
"template<> class MyTemplate<0> {};\n"
"template<typename T, int U = 1> class OtherTemplate {};\n"
"template<int U> class OtherTemplate<MyTemplate<0>, U> {};",
8,
- /*Public=*/false, Infos);
+ /*Public=*/false, Infos, this->Diags);
// First record.
const RecordInfo *Rec1 = InfoAsRecord(Infos[0].get());
diff --git a/clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp b/clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
index a9e7c64..db62c92 100644
--- a/clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -22,7 +22,9 @@ static std::unique_ptr<Generator> getYAMLGenerator() {
return std::move(G.get());
}
-TEST(YAMLGeneratorTest, emitNamespaceYAML) {
+class YAMLGeneratorTest : public ClangDocContextTest {};
+
+TEST_F(YAMLGeneratorTest, emitNamespaceYAML) {
NamespaceInfo I;
I.Name = "Namespace";
I.Path = "path/to/A";
@@ -44,7 +46,7 @@ TEST(YAMLGeneratorTest, emitNamespaceYAML) {
assert(G);
std::string Buffer;
llvm::raw_string_ostream Actual(Buffer);
- auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
+ auto Err = G->generateDocForInfo(&I, Actual, getClangDocContext());
assert(!Err);
std::string Expected =
R"raw(---
@@ -77,7 +79,7 @@ ChildEnums:
EXPECT_EQ(Expected, Actual.str());
}
-TEST(YAMLGeneratorTest, emitRecordYAML) {
+TEST_F(YAMLGeneratorTest, emitRecordYAML) {
RecordInfo I;
I.Name = "r";
I.Path = "path/to/A";
@@ -124,7 +126,7 @@ TEST(YAMLGeneratorTest, emitRecordYAML) {
assert(G);
std::string Buffer;
llvm::raw_string_ostream Actual(Buffer);
- auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
+ auto Err = G->generateDocForInfo(&I, Actual, getClangDocContext());
assert(!Err);
std::string Expected =
R"raw(---
@@ -202,7 +204,7 @@ ChildEnums:
EXPECT_EQ(Expected, Actual.str());
}
-TEST(YAMLGeneratorTest, emitFunctionYAML) {
+TEST_F(YAMLGeneratorTest, emitFunctionYAML) {
FunctionInfo I;
I.Name = "f";
I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
@@ -223,7 +225,7 @@ TEST(YAMLGeneratorTest, emitFunctionYAML) {
assert(G);
std::string Buffer;
llvm::raw_string_ostream Actual(Buffer);
- auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
+ auto Err = G->generateDocForInfo(&I, Actual, getClangDocContext());
assert(!Err);
std::string Expected =
R"raw(---
@@ -267,7 +269,7 @@ ReturnType:
// namespace A {
// enum e { X };
// }
-TEST(YAMLGeneratorTest, emitSimpleEnumYAML) {
+TEST_F(YAMLGeneratorTest, emitSimpleEnumYAML) {
EnumInfo I;
I.Name = "e";
I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
@@ -282,7 +284,7 @@ TEST(YAMLGeneratorTest, emitSimpleEnumYAML) {
assert(G);
std::string Buffer;
llvm::raw_string_ostream Actual(Buffer);
- auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
+ auto Err = G->generateDocForInfo(&I, Actual, getClangDocContext());
assert(!Err);
std::string Expected =
R"raw(---
@@ -308,7 +310,7 @@ Members:
// Tests the equivalent of:
// enum class e : short { X = FOO_BAR + 2 };
-TEST(YAMLGeneratorTest, enumTypedScopedEnumYAML) {
+TEST_F(YAMLGeneratorTest, enumTypedScopedEnumYAML) {
EnumInfo I;
I.Name = "e";
@@ -320,7 +322,7 @@ TEST(YAMLGeneratorTest, enumTypedScopedEnumYAML) {
assert(G);
std::string Buffer;
llvm::raw_string_ostream Actual(Buffer);
- auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
+ auto Err = G->generateDocForInfo(&I, Actual, getClangDocContext());
assert(!Err);
std::string Expected =
R"raw(---
@@ -340,7 +342,7 @@ Members:
EXPECT_EQ(Expected, Actual.str());
}
-TEST(YAMLGeneratorTest, enumTypedefYAML) {
+TEST_F(YAMLGeneratorTest, enumTypedefYAML) {
TypedefInfo I;
I.Name = "MyUsing";
I.Underlying = TypeInfo("int");
@@ -350,7 +352,7 @@ TEST(YAMLGeneratorTest, enumTypedefYAML) {
assert(G);
std::string Buffer;
llvm::raw_string_ostream Actual(Buffer);
- auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
+ auto Err = G->generateDocForInfo(&I, Actual, getClangDocContext());
assert(!Err);
std::string Expected =
R"raw(---
@@ -365,7 +367,7 @@ IsUsing: true
EXPECT_EQ(Expected, Actual.str());
}
-TEST(YAMLGeneratorTest, emitCommentYAML) {
+TEST_F(YAMLGeneratorTest, emitCommentYAML) {
FunctionInfo I;
I.Name = "f";
I.DefLoc = Location(10, 10, "test.cpp");
@@ -482,7 +484,7 @@ TEST(YAMLGeneratorTest, emitCommentYAML) {
assert(G);
std::string Buffer;
llvm::raw_string_ostream Actual(Buffer);
- auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
+ auto Err = G->generateDocForInfo(&I, Actual, getClangDocContext());
assert(!Err);
std::string Expected =
R"raw(---