2015-08-14 21:17:11 +08:00
|
|
|
//===--- ModernizeTidyModule.cpp - clang-tidy -----------------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2015-08-14 21:17:11 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "../ClangTidy.h"
|
|
|
|
#include "../ClangTidyModule.h"
|
|
|
|
#include "../ClangTidyModuleRegistry.h"
|
2016-05-13 04:06:04 +08:00
|
|
|
#include "AvoidBindCheck.h"
|
[clang-tidy] Avoid C arrays check
Summary:
[[ https://bugs.llvm.org/show_bug.cgi?id=39224 | PR39224 ]]
As discussed, we can't always do the transform automatically due to that array-to-pointer decay of C array.
In order to detect whether we can do said transform, we'd need to be able to see all usages of said array,
which is, i would say, rather impossible if e.g. it is in the header.
Thus right now no fixit exists.
Exceptions: `extern "C"` code.
References:
* [[ https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es27-use-stdarray-or-stack_array-for-arrays-on-the-stack | CPPCG ES.27: Use std::array or stack_array for arrays on the stack ]]
* [[ https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#slcon1-prefer-using-stl-array-or-vector-instead-of-a-c-array | CPPCG SL.con.1: Prefer using STL array or vector instead of a C array ]]
* HICPP `4.1.1 Ensure that a function argument does not undergo an array-to-pointer conversion`
* MISRA `5-2-12 An identifier with array type passed as a function argument shall not decay to a pointer`
Reviewers: aaron.ballman, JonasToth, alexfh, hokein, xazax.hun
Reviewed By: JonasToth
Subscribers: Eugene.Zelenko, mgorny, rnkovacs, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D53771
llvm-svn: 346835
2018-11-14 17:01:08 +08:00
|
|
|
#include "AvoidCArraysCheck.h"
|
2018-09-26 02:12:28 +08:00
|
|
|
#include "ConcatNestedNamespacesCheck.h"
|
2016-02-24 21:36:34 +08:00
|
|
|
#include "DeprecatedHeadersCheck.h"
|
2018-10-05 21:36:00 +08:00
|
|
|
#include "DeprecatedIosBaseAliasesCheck.h"
|
2015-08-19 17:11:46 +08:00
|
|
|
#include "LoopConvertCheck.h"
|
2016-05-03 00:56:39 +08:00
|
|
|
#include "MakeSharedCheck.h"
|
2015-09-29 17:36:41 +08:00
|
|
|
#include "MakeUniqueCheck.h"
|
2015-08-14 21:17:11 +08:00
|
|
|
#include "PassByValueCheck.h"
|
2016-03-28 00:43:44 +08:00
|
|
|
#include "RawStringLiteralCheck.h"
|
2015-10-28 09:36:20 +08:00
|
|
|
#include "RedundantVoidArgCheck.h"
|
2015-08-25 21:03:43 +08:00
|
|
|
#include "ReplaceAutoPtrCheck.h"
|
2017-04-24 17:27:20 +08:00
|
|
|
#include "ReplaceRandomShuffleCheck.h"
|
2017-02-16 01:06:06 +08:00
|
|
|
#include "ReturnBracedInitListCheck.h"
|
2015-08-31 21:17:43 +08:00
|
|
|
#include "ShrinkToFitCheck.h"
|
2017-07-12 21:43:35 +08:00
|
|
|
#include "UnaryStaticAssertCheck.h"
|
2015-08-21 23:08:51 +08:00
|
|
|
#include "UseAutoCheck.h"
|
2016-05-11 19:33:16 +08:00
|
|
|
#include "UseBoolLiteralsCheck.h"
|
2016-12-21 05:26:07 +08:00
|
|
|
#include "UseDefaultMemberInitCheck.h"
|
2016-06-21 23:23:27 +08:00
|
|
|
#include "UseEmplaceCheck.h"
|
2016-12-02 01:24:42 +08:00
|
|
|
#include "UseEqualsDefaultCheck.h"
|
2016-11-11 00:46:59 +08:00
|
|
|
#include "UseEqualsDeleteCheck.h"
|
[clang-tidy] Adding a new modernize use nodiscard checker
Summary: Adds a checker to clang-tidy to warn when a non void const member function, taking only parameters passed by value or const reference could be marked as '[[nodiscard]]'
Patch by MyDeveloperDay.
Reviewers: alexfh, stephenkelly, curdeius, aaron.ballman, hokein, JonasToth
Reviewed By: curdeius, JonasToth
Subscribers: Eugene.Zelenko, lefticus, lebedev.ri, mgorny, xazax.hun, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D55433
llvm-svn: 350760
2019-01-10 04:50:50 +08:00
|
|
|
#include "UseNodiscardCheck.h"
|
[clang-tidy] New checker to replace dynamic exception specifications
Summary:
New checker to replace dynamic exception
specifications
This is an alternative to D18575 which relied on reparsing the decl to
find the location of dynamic exception specifications, but couldn't
deal with preprocessor conditionals correctly without reparsing the
entire file.
This approach uses D20428 to find dynamic exception specification
locations and handles all cases correctly.
Reviewers: aaron.ballman, alexfh
Reviewed By: aaron.ballman, alexfh
Subscribers: xazax.hun, mgehre, malcolm.parsons, mgorny, JDevlieghere, cfe-commits, Eugene.Zelenko, etienneb
Patch by Don Hinton!
Differential Revision: https://reviews.llvm.org/D20693
llvm-svn: 304977
2017-06-08 22:04:16 +08:00
|
|
|
#include "UseNoexceptCheck.h"
|
2015-08-20 06:21:37 +08:00
|
|
|
#include "UseNullptrCheck.h"
|
2015-08-31 21:17:43 +08:00
|
|
|
#include "UseOverrideCheck.h"
|
2016-11-16 22:42:10 +08:00
|
|
|
#include "UseTransparentFunctorsCheck.h"
|
2018-02-20 18:48:38 +08:00
|
|
|
#include "UseUncaughtExceptionsCheck.h"
|
2016-06-26 02:37:53 +08:00
|
|
|
#include "UseUsingCheck.h"
|
2015-08-14 21:17:11 +08:00
|
|
|
|
|
|
|
using namespace clang::ast_matchers;
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
|
|
|
namespace modernize {
|
|
|
|
|
|
|
|
class ModernizeModule : public ClangTidyModule {
|
|
|
|
public:
|
|
|
|
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
|
2016-11-08 15:50:19 +08:00
|
|
|
CheckFactories.registerCheck<AvoidBindCheck>("modernize-avoid-bind");
|
[clang-tidy] Avoid C arrays check
Summary:
[[ https://bugs.llvm.org/show_bug.cgi?id=39224 | PR39224 ]]
As discussed, we can't always do the transform automatically due to that array-to-pointer decay of C array.
In order to detect whether we can do said transform, we'd need to be able to see all usages of said array,
which is, i would say, rather impossible if e.g. it is in the header.
Thus right now no fixit exists.
Exceptions: `extern "C"` code.
References:
* [[ https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es27-use-stdarray-or-stack_array-for-arrays-on-the-stack | CPPCG ES.27: Use std::array or stack_array for arrays on the stack ]]
* [[ https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#slcon1-prefer-using-stl-array-or-vector-instead-of-a-c-array | CPPCG SL.con.1: Prefer using STL array or vector instead of a C array ]]
* HICPP `4.1.1 Ensure that a function argument does not undergo an array-to-pointer conversion`
* MISRA `5-2-12 An identifier with array type passed as a function argument shall not decay to a pointer`
Reviewers: aaron.ballman, JonasToth, alexfh, hokein, xazax.hun
Reviewed By: JonasToth
Subscribers: Eugene.Zelenko, mgorny, rnkovacs, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D53771
llvm-svn: 346835
2018-11-14 17:01:08 +08:00
|
|
|
CheckFactories.registerCheck<AvoidCArraysCheck>("modernize-avoid-c-arrays");
|
2018-09-26 02:12:28 +08:00
|
|
|
CheckFactories.registerCheck<ConcatNestedNamespacesCheck>(
|
|
|
|
"modernize-concat-nested-namespaces");
|
2016-02-24 21:36:34 +08:00
|
|
|
CheckFactories.registerCheck<DeprecatedHeadersCheck>(
|
|
|
|
"modernize-deprecated-headers");
|
2018-10-05 21:36:00 +08:00
|
|
|
CheckFactories.registerCheck<DeprecatedIosBaseAliasesCheck>(
|
|
|
|
"modernize-deprecated-ios-base-aliases");
|
2015-08-19 17:11:46 +08:00
|
|
|
CheckFactories.registerCheck<LoopConvertCheck>("modernize-loop-convert");
|
2016-05-03 00:56:39 +08:00
|
|
|
CheckFactories.registerCheck<MakeSharedCheck>("modernize-make-shared");
|
2015-10-21 20:58:15 +08:00
|
|
|
CheckFactories.registerCheck<MakeUniqueCheck>("modernize-make-unique");
|
2015-08-14 21:17:11 +08:00
|
|
|
CheckFactories.registerCheck<PassByValueCheck>("modernize-pass-by-value");
|
2016-03-28 00:43:44 +08:00
|
|
|
CheckFactories.registerCheck<RawStringLiteralCheck>(
|
|
|
|
"modernize-raw-string-literal");
|
2015-10-28 09:36:20 +08:00
|
|
|
CheckFactories.registerCheck<RedundantVoidArgCheck>(
|
|
|
|
"modernize-redundant-void-arg");
|
2015-08-25 21:03:43 +08:00
|
|
|
CheckFactories.registerCheck<ReplaceAutoPtrCheck>(
|
|
|
|
"modernize-replace-auto-ptr");
|
2017-04-24 17:27:20 +08:00
|
|
|
CheckFactories.registerCheck<ReplaceRandomShuffleCheck>(
|
|
|
|
"modernize-replace-random-shuffle");
|
2017-02-16 01:06:06 +08:00
|
|
|
CheckFactories.registerCheck<ReturnBracedInitListCheck>(
|
|
|
|
"modernize-return-braced-init-list");
|
2015-08-31 21:17:43 +08:00
|
|
|
CheckFactories.registerCheck<ShrinkToFitCheck>("modernize-shrink-to-fit");
|
2017-07-12 21:43:35 +08:00
|
|
|
CheckFactories.registerCheck<UnaryStaticAssertCheck>(
|
|
|
|
"modernize-unary-static-assert");
|
2015-08-21 23:08:51 +08:00
|
|
|
CheckFactories.registerCheck<UseAutoCheck>("modernize-use-auto");
|
2016-05-11 19:33:16 +08:00
|
|
|
CheckFactories.registerCheck<UseBoolLiteralsCheck>(
|
|
|
|
"modernize-use-bool-literals");
|
2016-12-21 05:26:07 +08:00
|
|
|
CheckFactories.registerCheck<UseDefaultMemberInitCheck>(
|
|
|
|
"modernize-use-default-member-init");
|
2016-06-21 23:23:27 +08:00
|
|
|
CheckFactories.registerCheck<UseEmplaceCheck>("modernize-use-emplace");
|
2016-12-02 01:24:42 +08:00
|
|
|
CheckFactories.registerCheck<UseEqualsDefaultCheck>("modernize-use-equals-default");
|
2016-11-11 00:46:59 +08:00
|
|
|
CheckFactories.registerCheck<UseEqualsDeleteCheck>(
|
|
|
|
"modernize-use-equals-delete");
|
[clang-tidy] Adding a new modernize use nodiscard checker
Summary: Adds a checker to clang-tidy to warn when a non void const member function, taking only parameters passed by value or const reference could be marked as '[[nodiscard]]'
Patch by MyDeveloperDay.
Reviewers: alexfh, stephenkelly, curdeius, aaron.ballman, hokein, JonasToth
Reviewed By: curdeius, JonasToth
Subscribers: Eugene.Zelenko, lefticus, lebedev.ri, mgorny, xazax.hun, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D55433
llvm-svn: 350760
2019-01-10 04:50:50 +08:00
|
|
|
CheckFactories.registerCheck<UseNodiscardCheck>(
|
|
|
|
"modernize-use-nodiscard");
|
[clang-tidy] New checker to replace dynamic exception specifications
Summary:
New checker to replace dynamic exception
specifications
This is an alternative to D18575 which relied on reparsing the decl to
find the location of dynamic exception specifications, but couldn't
deal with preprocessor conditionals correctly without reparsing the
entire file.
This approach uses D20428 to find dynamic exception specification
locations and handles all cases correctly.
Reviewers: aaron.ballman, alexfh
Reviewed By: aaron.ballman, alexfh
Subscribers: xazax.hun, mgehre, malcolm.parsons, mgorny, JDevlieghere, cfe-commits, Eugene.Zelenko, etienneb
Patch by Don Hinton!
Differential Revision: https://reviews.llvm.org/D20693
llvm-svn: 304977
2017-06-08 22:04:16 +08:00
|
|
|
CheckFactories.registerCheck<UseNoexceptCheck>("modernize-use-noexcept");
|
2015-08-20 06:21:37 +08:00
|
|
|
CheckFactories.registerCheck<UseNullptrCheck>("modernize-use-nullptr");
|
2015-08-31 21:17:43 +08:00
|
|
|
CheckFactories.registerCheck<UseOverrideCheck>("modernize-use-override");
|
2016-11-16 22:42:10 +08:00
|
|
|
CheckFactories.registerCheck<UseTransparentFunctorsCheck>(
|
|
|
|
"modernize-use-transparent-functors");
|
2018-02-20 18:48:38 +08:00
|
|
|
CheckFactories.registerCheck<UseUncaughtExceptionsCheck>(
|
|
|
|
"modernize-use-uncaught-exceptions");
|
2016-06-26 02:37:53 +08:00
|
|
|
CheckFactories.registerCheck<UseUsingCheck>("modernize-use-using");
|
2015-08-14 21:17:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ClangTidyOptions getModuleOptions() override {
|
|
|
|
ClangTidyOptions Options;
|
|
|
|
auto &Opts = Options.CheckOptions;
|
2015-10-30 17:37:57 +08:00
|
|
|
// For types whose size in bytes is above this threshold, we prefer taking a
|
|
|
|
// const-reference than making a copy.
|
|
|
|
Opts["modernize-loop-convert.MaxCopySize"] = "16";
|
|
|
|
|
2015-08-19 17:11:46 +08:00
|
|
|
Opts["modernize-loop-convert.MinConfidence"] = "reasonable";
|
2015-09-25 01:02:19 +08:00
|
|
|
Opts["modernize-loop-convert.NamingStyle"] = "CamelCase";
|
2015-10-21 20:58:15 +08:00
|
|
|
Opts["modernize-pass-by-value.IncludeStyle"] = "llvm"; // Also: "google".
|
2015-08-25 21:03:43 +08:00
|
|
|
Opts["modernize-replace-auto-ptr.IncludeStyle"] = "llvm"; // Also: "google".
|
2015-08-20 06:21:37 +08:00
|
|
|
|
|
|
|
// Comma-separated list of macros that behave like NULL.
|
|
|
|
Opts["modernize-use-nullptr.NullMacros"] = "NULL";
|
2015-08-14 21:17:11 +08:00
|
|
|
return Options;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Register the ModernizeTidyModule using this statically initialized variable.
|
|
|
|
static ClangTidyModuleRegistry::Add<ModernizeModule> X("modernize-module",
|
|
|
|
"Add modernize checks.");
|
|
|
|
|
|
|
|
} // namespace modernize
|
|
|
|
|
|
|
|
// This anchor is used to force the linker to link in the generated object file
|
|
|
|
// and thus register the ModernizeModule.
|
|
|
|
volatile int ModernizeModuleAnchorSource = 0;
|
|
|
|
|
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|