forked from OSchip/llvm-project
[clang-tidy] Move misc-use-override and readability-shrink-to-fit to "modernize/"
These checks are focusing on migrating the code from C++98/03 to C++11, so they belong to the modernize module. llvm-svn: 246437
This commit is contained in:
parent
f3ded811b2
commit
0ed6c478a4
|
@ -19,7 +19,6 @@ add_clang_library(clangTidyMiscModule
|
|||
UnusedParametersCheck.cpp
|
||||
UnusedRAIICheck.cpp
|
||||
UniqueptrResetReleaseCheck.cpp
|
||||
UseOverrideCheck.cpp
|
||||
|
||||
LINK_LIBS
|
||||
clangAST
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include "UnusedAliasDeclsCheck.h"
|
||||
#include "UnusedParametersCheck.h"
|
||||
#include "UnusedRAIICheck.h"
|
||||
#include "UseOverrideCheck.h"
|
||||
|
||||
namespace clang {
|
||||
namespace tidy {
|
||||
|
@ -68,7 +67,6 @@ public:
|
|||
CheckFactories.registerCheck<UnusedParametersCheck>(
|
||||
"misc-unused-parameters");
|
||||
CheckFactories.registerCheck<UnusedRAIICheck>("misc-unused-raii");
|
||||
CheckFactories.registerCheck<UseOverrideCheck>("misc-use-override");
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -6,8 +6,10 @@ add_clang_library(clangTidyModernizeModule
|
|||
ModernizeTidyModule.cpp
|
||||
PassByValueCheck.cpp
|
||||
ReplaceAutoPtrCheck.cpp
|
||||
ShrinkToFitCheck.cpp
|
||||
UseAutoCheck.cpp
|
||||
UseNullptrCheck.cpp
|
||||
UseOverrideCheck.cpp
|
||||
|
||||
LINK_LIBS
|
||||
clangAST
|
||||
|
|
|
@ -13,8 +13,10 @@
|
|||
#include "LoopConvertCheck.h"
|
||||
#include "PassByValueCheck.h"
|
||||
#include "ReplaceAutoPtrCheck.h"
|
||||
#include "ShrinkToFitCheck.h"
|
||||
#include "UseAutoCheck.h"
|
||||
#include "UseNullptrCheck.h"
|
||||
#include "UseOverrideCheck.h"
|
||||
|
||||
using namespace clang::ast_matchers;
|
||||
|
||||
|
@ -29,8 +31,10 @@ public:
|
|||
CheckFactories.registerCheck<PassByValueCheck>("modernize-pass-by-value");
|
||||
CheckFactories.registerCheck<ReplaceAutoPtrCheck>(
|
||||
"modernize-replace-auto-ptr");
|
||||
CheckFactories.registerCheck<ShrinkToFitCheck>("modernize-shrink-to-fit");
|
||||
CheckFactories.registerCheck<UseAutoCheck>("modernize-use-auto");
|
||||
CheckFactories.registerCheck<UseNullptrCheck>("modernize-use-nullptr");
|
||||
CheckFactories.registerCheck<UseOverrideCheck>("modernize-use-override");
|
||||
}
|
||||
|
||||
ClangTidyOptions getModuleOptions() override {
|
||||
|
|
|
@ -33,7 +33,7 @@ AST_MATCHER(NamedDecl, stlShrinkableContainer) {
|
|||
} // namespace
|
||||
|
||||
namespace tidy {
|
||||
namespace readability {
|
||||
namespace modernize {
|
||||
|
||||
void ShrinkToFitCheck::registerMatchers(MatchFinder *Finder) {
|
||||
// Swap as a function need not to be considered, because rvalue can not
|
||||
|
@ -99,6 +99,6 @@ void ShrinkToFitCheck::check(const MatchFinder::MatchResult &Result) {
|
|||
<< Hint;
|
||||
}
|
||||
|
||||
} // namespace readability
|
||||
} // namespace modernize
|
||||
} // namespace tidy
|
||||
} // namespace clang
|
|
@ -7,14 +7,14 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_SHRINKTOFITCHECK_H
|
||||
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_SHRINKTOFITCHECK_H
|
||||
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_SHRINKTOFITCHECK_H
|
||||
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_SHRINKTOFITCHECK_H
|
||||
|
||||
#include "../ClangTidy.h"
|
||||
|
||||
namespace clang {
|
||||
namespace tidy {
|
||||
namespace readability {
|
||||
namespace modernize {
|
||||
|
||||
/// Replace copy and swap tricks on shrinkable containers with the
|
||||
/// `shrink_to_fit()` method call.
|
||||
|
@ -30,8 +30,8 @@ public:
|
|||
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
|
||||
};
|
||||
|
||||
} // namespace readability
|
||||
} // namespace modernize
|
||||
} // namespace tidy
|
||||
} // namespace clang
|
||||
|
||||
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_SHRINKTOFITCHECK_H
|
||||
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_SHRINKTOFITCHECK_H
|
|
@ -16,7 +16,7 @@ using namespace clang::ast_matchers;
|
|||
|
||||
namespace clang {
|
||||
namespace tidy {
|
||||
namespace misc {
|
||||
namespace modernize {
|
||||
|
||||
void UseOverrideCheck::registerMatchers(MatchFinder *Finder) {
|
||||
// Only register the matcher for C++11.
|
||||
|
@ -192,6 +192,6 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) {
|
|||
}
|
||||
}
|
||||
|
||||
} // namespace misc
|
||||
} // namespace modernize
|
||||
} // namespace tidy
|
||||
} // namespace clang
|
|
@ -7,14 +7,14 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_USEOVERRIDECHECK_H
|
||||
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_USEOVERRIDECHECK_H
|
||||
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEOVERRIDECHECK_H
|
||||
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEOVERRIDECHECK_H
|
||||
|
||||
#include "../ClangTidy.h"
|
||||
|
||||
namespace clang {
|
||||
namespace tidy {
|
||||
namespace misc {
|
||||
namespace modernize {
|
||||
|
||||
/// Use C++11's `override` and remove `virtual` where applicable.
|
||||
class UseOverrideCheck : public ClangTidyCheck {
|
||||
|
@ -25,8 +25,8 @@ public:
|
|||
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
|
||||
};
|
||||
|
||||
} // namespace misc
|
||||
} // namespace modernize
|
||||
} // namespace tidy
|
||||
} // namespace clang
|
||||
|
||||
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_USEOVERRIDECHECK_H
|
||||
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEOVERRIDECHECK_H
|
|
@ -11,7 +11,6 @@ add_clang_library(clangTidyReadabilityModule
|
|||
ReadabilityTidyModule.cpp
|
||||
RedundantStringCStrCheck.cpp
|
||||
RedundantSmartptrGetCheck.cpp
|
||||
ShrinkToFitCheck.cpp
|
||||
SimplifyBooleanExprCheck.cpp
|
||||
|
||||
LINK_LIBS
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include "NamedParameterCheck.h"
|
||||
#include "RedundantSmartptrGetCheck.h"
|
||||
#include "RedundantStringCStrCheck.h"
|
||||
#include "ShrinkToFitCheck.h"
|
||||
#include "SimplifyBooleanExprCheck.h"
|
||||
|
||||
namespace clang {
|
||||
|
@ -44,8 +43,6 @@ public:
|
|||
"readability-redundant-smartptr-get");
|
||||
CheckFactories.registerCheck<RedundantStringCStrCheck>(
|
||||
"readability-redundant-string-cstr");
|
||||
CheckFactories.registerCheck<ShrinkToFitCheck>(
|
||||
"readability-shrink-to-fit");
|
||||
CheckFactories.registerCheck<SimplifyBooleanExprCheck>(
|
||||
"readability-simplify-boolean-expr");
|
||||
}
|
||||
|
|
|
@ -38,10 +38,11 @@ List of clang-tidy Checks
|
|||
misc-unused-alias-decls
|
||||
misc-unused-parameters
|
||||
misc-unused-raii
|
||||
misc-use-override
|
||||
modernize-loop-convert
|
||||
modernize-pass-by-value
|
||||
modernize-shrink-to-fit
|
||||
modernize-use-nullptr
|
||||
modernize-use-override
|
||||
readability-braces-around-statements
|
||||
readability-container-size-empty
|
||||
readability-else-after-return
|
||||
|
@ -50,5 +51,4 @@ List of clang-tidy Checks
|
|||
readability-named-parameter
|
||||
readability-redundant-smartptr-get
|
||||
readability-redundant-string-cstr
|
||||
readability-shrink-to-fit
|
||||
readability-simplify-boolean-expr
|
||||
readability-simplify-boolean-expr
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
misc-use-override
|
||||
=================
|
||||
modernize-use-override
|
||||
======================
|
||||
|
||||
|
||||
Use C++11's ``override`` and remove ``virtual`` where applicable.
|
|
@ -53,8 +53,14 @@ There are currently the following groups of checks:
|
|||
* Checks related to the Google coding conventions have names starting with
|
||||
``google-``.
|
||||
|
||||
* Checks with names starting with ``misc-`` don't relate to any particular
|
||||
coding style.
|
||||
* Checks named ``modernize-*`` advocate the usage of modern (currently "modern"
|
||||
means "C++11") language constructs.
|
||||
|
||||
* The ``readability-`` checks target readability-related issues that don't
|
||||
relate to any particular coding style.
|
||||
|
||||
* Checks with names starting with ``misc-`` the checks that we didn't have a
|
||||
better category for.
|
||||
|
||||
* Clang static analyzer checks are named starting with ``clang-analyzer-``.
|
||||
|
||||
|
@ -494,8 +500,8 @@ The script provides multiple configuration flags.
|
|||
|
||||
* The default set of checks can be overridden using the ``-checks`` argument,
|
||||
taking the identical format as :program:`clang-tidy` does. For example
|
||||
``-checks=-*,misc-use-override`` will run the ``misc-use-override``
|
||||
checker only.
|
||||
``-checks=-*,modernize-use-override`` will run the ``modernize-use-override``
|
||||
check only.
|
||||
|
||||
* To restrict the files examined you can provide one or more regex arguments
|
||||
that the file names are matched against.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// RUN: sed 's/placeholder_for_f/f/' %s > %t.cpp
|
||||
// RUN: clang-tidy -checks=-*,misc-use-override %t.cpp -- -std=c++11 | FileCheck -check-prefix=CHECK-SANITY %s
|
||||
// RUN: not diff -U0 %s %t.cpp | %python %S/../../clang-tidy/tool/clang-tidy-diff.py -checks=-*,misc-use-override -- -std=c++11 2>&1 | FileCheck %s
|
||||
// RUN: clang-tidy -checks=-*,modernize-use-override %t.cpp -- -std=c++11 | FileCheck -check-prefix=CHECK-SANITY %s
|
||||
// RUN: not diff -U0 %s %t.cpp | %python %S/../../clang-tidy/tool/clang-tidy-diff.py -checks=-*,modernize-use-override -- -std=c++11 2>&1 | FileCheck %s
|
||||
struct A {
|
||||
virtual void f() {}
|
||||
virtual void g() {}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// RUN: clang-tidy -checks='-*,misc-use-override' %s.nonexistent.cpp -- | FileCheck -check-prefix=CHECK1 %s
|
||||
// RUN: clang-tidy -checks='-*,modernize-use-override' %s.nonexistent.cpp -- | FileCheck -check-prefix=CHECK1 %s
|
||||
// RUN: clang-tidy -checks='-*,clang-diagnostic-*,google-explicit-constructor' %s -- -fan-unknown-option | FileCheck -check-prefix=CHECK2 %s
|
||||
// RUN: clang-tidy -checks='-*,google-explicit-constructor,clang-diagnostic-literal-conversion' %s -- -fan-unknown-option | FileCheck -check-prefix=CHECK3 %s
|
||||
// RUN: clang-tidy -checks='-*,misc-use-override,clang-diagnostic-macro-redefined' %s -- -DMACRO_FROM_COMMAND_LINE | FileCheck -check-prefix=CHECK4 %s
|
||||
// RUN: clang-tidy -checks='-*,modernize-use-override,clang-diagnostic-macro-redefined' %s -- -DMACRO_FROM_COMMAND_LINE | FileCheck -check-prefix=CHECK4 %s
|
||||
|
||||
// CHECK1-NOT: warning
|
||||
// CHECK2-NOT: warning
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// RUN: %python %S/check_clang_tidy.py %s readability-shrink-to-fit %t
|
||||
// RUN: %python %S/check_clang_tidy.py %s modernize-shrink-to-fit %t
|
||||
|
||||
namespace std {
|
||||
template <typename T> struct vector { void swap(vector &other); };
|
||||
|
@ -8,7 +8,7 @@ void f() {
|
|||
std::vector<int> v;
|
||||
|
||||
std::vector<int>(v).swap(v);
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the shrink_to_fit method should be used to reduce the capacity of a shrinkable container [readability-shrink-to-fit]
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the shrink_to_fit method should be used to reduce the capacity of a shrinkable container [modernize-shrink-to-fit]
|
||||
// CHECK-FIXES: {{^ }}v.shrink_to_fit();{{$}}
|
||||
|
||||
std::vector<int> &vref = v;
|
|
@ -1,4 +1,4 @@
|
|||
// RUN: %python %S/check_clang_tidy.py %s misc-use-override %t -- -std=c++98
|
||||
// RUN: %python %S/check_clang_tidy.py %s modernize-use-override %t -- -std=c++98
|
||||
|
||||
struct Base {
|
||||
virtual ~Base() {}
|
|
@ -1,4 +1,4 @@
|
|||
// RUN: %python %S/check_clang_tidy.py %s misc-use-override %t
|
||||
// RUN: %python %S/check_clang_tidy.py %s modernize-use-override %t
|
||||
|
||||
#define ABSTRACT = 0
|
||||
|
||||
|
@ -42,7 +42,7 @@ struct Base {
|
|||
struct SimpleCases : public Base {
|
||||
public:
|
||||
virtual ~SimpleCases();
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: prefer using 'override' or (rarely) 'final' instead of 'virtual'
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [modernize-use-override]
|
||||
// CHECK-FIXES: {{^}} ~SimpleCases() override;
|
||||
|
||||
void a();
|
Loading…
Reference in New Issue