[clang-tidy] Added -system-headers option.
Added -system-headers option to allow display of warnings from system headers. This is needed for testing libcxx, for example. git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@220826 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
68a2a6dfc7
Коммит
4960433ea5
|
@ -367,7 +367,8 @@ void ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location) {
|
|||
}
|
||||
|
||||
const SourceManager &Sources = Diags->getSourceManager();
|
||||
if (Sources.isInSystemHeader(Location))
|
||||
if (!*Context.getOptions().SystemHeaders &&
|
||||
Sources.isInSystemHeader(Location))
|
||||
return;
|
||||
|
||||
// FIXME: We start with a conservative approach here, but the actual type of
|
||||
|
|
|
@ -101,6 +101,7 @@ ClangTidyOptions ClangTidyOptions::getDefaults() {
|
|||
ClangTidyOptions Options;
|
||||
Options.Checks = "";
|
||||
Options.HeaderFilterRegex = "";
|
||||
Options.SystemHeaders = false;
|
||||
Options.AnalyzeTemporaryDtors = false;
|
||||
Options.User = llvm::None;
|
||||
for (ClangTidyModuleRegistry::iterator I = ClangTidyModuleRegistry::begin(),
|
||||
|
@ -122,6 +123,8 @@ ClangTidyOptions::mergeWith(const ClangTidyOptions &Other) const {
|
|||
|
||||
if (Other.HeaderFilterRegex)
|
||||
Result.HeaderFilterRegex = Other.HeaderFilterRegex;
|
||||
if (Other.SystemHeaders)
|
||||
Result.SystemHeaders = Other.SystemHeaders;
|
||||
if (Other.AnalyzeTemporaryDtors)
|
||||
Result.AnalyzeTemporaryDtors = Other.AnalyzeTemporaryDtors;
|
||||
if (Other.User)
|
||||
|
|
|
@ -66,6 +66,9 @@ struct ClangTidyOptions {
|
|||
/// main files will always be displayed.
|
||||
llvm::Optional<std::string> HeaderFilterRegex;
|
||||
|
||||
/// \brief Output warnings from system headers matching \c HeaderFilterRegex.
|
||||
llvm::Optional<bool> SystemHeaders;
|
||||
|
||||
/// \brief Turns on temporary destructor-based analysis.
|
||||
llvm::Optional<bool> AnalyzeTemporaryDtors;
|
||||
|
||||
|
|
|
@ -63,6 +63,10 @@ HeaderFilter("header-filter",
|
|||
".clang-tidy file."),
|
||||
cl::init(""), cl::cat(ClangTidyCategory));
|
||||
|
||||
static cl::opt<bool>
|
||||
SystemHeaders("system-headers",
|
||||
cl::desc("Display the errors from system headers"),
|
||||
cl::init(false), cl::cat(ClangTidyCategory));
|
||||
static cl::opt<std::string>
|
||||
LineFilter("line-filter",
|
||||
cl::desc("List of files with line ranges to filter the\n"
|
||||
|
@ -198,6 +202,7 @@ std::unique_ptr<ClangTidyOptionsProvider> createOptionsProvider() {
|
|||
ClangTidyOptions DefaultOptions;
|
||||
DefaultOptions.Checks = DefaultChecks;
|
||||
DefaultOptions.HeaderFilterRegex = HeaderFilter;
|
||||
DefaultOptions.SystemHeaders = SystemHeaders;
|
||||
DefaultOptions.AnalyzeTemporaryDtors = AnalyzeTemporaryDtors;
|
||||
DefaultOptions.User = llvm::sys::Process::GetEnv("USER");
|
||||
// USERNAME is used on Windows.
|
||||
|
@ -209,6 +214,8 @@ std::unique_ptr<ClangTidyOptionsProvider> createOptionsProvider() {
|
|||
OverrideOptions.Checks = Checks;
|
||||
if (HeaderFilter.getNumOccurrences() > 0)
|
||||
OverrideOptions.HeaderFilterRegex = HeaderFilter;
|
||||
if (SystemHeaders.getNumOccurrences() > 0)
|
||||
OverrideOptions.SystemHeaders = SystemHeaders;
|
||||
if (AnalyzeTemporaryDtors.getNumOccurrences() > 0)
|
||||
OverrideOptions.AnalyzeTemporaryDtors = AnalyzeTemporaryDtors;
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
class A0 { A0(int); };
|
|
@ -1,29 +1,42 @@
|
|||
// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='' %s -- -I %S/Inputs/file-filter 2>&1 | FileCheck %s
|
||||
// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' %s -- -I %S/Inputs/file-filter 2>&1 | FileCheck --check-prefix=CHECK2 %s
|
||||
// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='header2\.h' %s -- -I %S/Inputs/file-filter 2>&1 | FileCheck --check-prefix=CHECK3 %s
|
||||
// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='' %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck %s
|
||||
// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK2 %s
|
||||
// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='header2\.h' %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK3 %s
|
||||
// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' -system-headers %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK4 %s
|
||||
|
||||
#include "header1.h"
|
||||
// CHECK-NOT: warning:
|
||||
// CHECK2: header1.h:1:12: warning: Single-argument constructors must be explicit [google-explicit-constructor]
|
||||
// CHECK3-NOT: warning:
|
||||
// CHECK4: header1.h:1:12: warning: Single-argument constructors
|
||||
|
||||
#include "header2.h"
|
||||
// CHECK-NOT: warning:
|
||||
// CHECK2: header2.h:1:12: warning: Single-argument constructors {{.*}}
|
||||
// CHECK3: header2.h:1:12: warning: Single-argument constructors {{.*}}
|
||||
// CHECK2: header2.h:1:12: warning: Single-argument constructors
|
||||
// CHECK3: header2.h:1:12: warning: Single-argument constructors
|
||||
// CHECK4: header2.h:1:12: warning: Single-argument constructors
|
||||
|
||||
#include <system-header.h>
|
||||
// CHECK-NOT: warning:
|
||||
// CHECK2-NOT: warning:
|
||||
// CHECK3-NOT: warning:
|
||||
// CHECK4: system-header.h:1:12: warning: Single-argument constructors
|
||||
|
||||
class A { A(int); };
|
||||
// CHECK: :[[@LINE-1]]:11: warning: Single-argument constructors {{.*}}
|
||||
// CHECK2: :[[@LINE-2]]:11: warning: Single-argument constructors {{.*}}
|
||||
// CHECK3: :[[@LINE-3]]:11: warning: Single-argument constructors {{.*}}
|
||||
// CHECK: :[[@LINE-1]]:11: warning: Single-argument constructors
|
||||
// CHECK2: :[[@LINE-2]]:11: warning: Single-argument constructors
|
||||
// CHECK3: :[[@LINE-3]]:11: warning: Single-argument constructors
|
||||
// CHECK4: :[[@LINE-4]]:11: warning: Single-argument constructors
|
||||
|
||||
// CHECK-NOT: warning:
|
||||
// CHECK2-NOT: warning:
|
||||
// CHECK3-NOT: warning:
|
||||
// CHECK4-NOT: warning:
|
||||
|
||||
// CHECK: Suppressed 2 warnings (2 in non-user code)
|
||||
// CHECK: Suppressed 3 warnings (3 in non-user code)
|
||||
// CHECK: Use -header-filter='.*' to display errors from all non-system headers.
|
||||
// CHECK2-NOT: Suppressed {{.*}} warnings
|
||||
// CHECK2-NOT: Use -header-filter='.*' {{.*}}
|
||||
// CHECK3: Suppressed 1 warnings (1 in non-user code)
|
||||
// CHECK2: Suppressed 1 warnings (1 in non-user code)
|
||||
// CHECK2: Use -header-filter='.*' {{.*}}
|
||||
// CHECK3: Suppressed 2 warnings (2 in non-user code)
|
||||
// CHECK3: Use -header-filter='.*' {{.*}}
|
||||
// CHECK4-NOT: Suppressed {{.*}} warnings
|
||||
// CHECK4-NOT: Use -header-filter='.*' {{.*}}
|
||||
|
|
Загрузка…
Ссылка в новой задаче