Skip to content

Commit 2617825

Browse files
committed
[clang-tidy] Emit warnings from headers by default
1 parent f767f23 commit 2617825

File tree

15 files changed

+71
-26
lines changed

15 files changed

+71
-26
lines changed

clang-tools-extra/clang-tidy/ClangTidyOptions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ ClangTidyOptions ClangTidyOptions::getDefaults() {
247247
Options.WarningsAsErrors = "";
248248
Options.HeaderFileExtensions = {"", "h", "hh", "hpp", "hxx"};
249249
Options.ImplementationFileExtensions = {"c", "cc", "cpp", "cxx"};
250-
Options.HeaderFilterRegex = "";
250+
Options.HeaderFilterRegex = ".*";
251251
Options.ExcludeHeaderFilterRegex = "";
252252
Options.SystemHeaders = false;
253253
Options.FormatStyle = "none";

clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Configuration files:
9393
WarningsAsErrors: ''
9494
HeaderFileExtensions: ['', 'h','hh','hpp','hxx']
9595
ImplementationFileExtensions: ['c','cc','cpp','cxx']
96-
HeaderFilterRegex: ''
96+
HeaderFilterRegex: '.*'
9797
FormatStyle: none
9898
InheritParentConfig: true
9999
User: user
@@ -133,13 +133,15 @@ file, if any.
133133
static cl::opt<std::string> HeaderFilter("header-filter", desc(R"(
134134
Regular expression matching the names of the
135135
headers to output diagnostics from. Diagnostics
136-
from the main file of each translation unit are
137-
always displayed.
136+
from the main file and all non-system headers
137+
of each translation unit are always displayed.
138+
Set this option to an empty string to disable
139+
diagnostics from non-system headers.
138140
Can be used together with -line-filter.
139141
This option overrides the 'HeaderFilterRegex'
140142
option in .clang-tidy file, if any.
141143
)"),
142-
cl::init(""),
144+
cl::init(".*"),
143145
cl::cat(ClangTidyCategory));
144146

145147
static cl::opt<std::string> ExcludeHeaderFilter("exclude-header-filter",
@@ -379,9 +381,9 @@ static void printStats(const ClangTidyStats &Stats) {
379381
<< " with check filters";
380382
llvm::errs() << ").\n";
381383
if (Stats.ErrorsIgnoredNonUserCode)
382-
llvm::errs() << "Use -header-filter=.* to display errors from all "
383-
"non-system headers. Use -system-headers to display "
384-
"errors from system headers as well.\n";
384+
llvm::errs() << "Use -header-filter=.* or leave it as default to display "
385+
"errors from all non-system headers. Use -system-headers "
386+
"to display errors from system headers as well.\n";
385387
}
386388
}
387389

clang-tools-extra/clang-tidy/tool/run-clang-tidy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,8 @@ async def main() -> None:
470470
default=None,
471471
help="Regular expression matching the names of the "
472472
"headers to output diagnostics from. Diagnostics from "
473-
"the main file of each translation unit are always "
474-
"displayed.",
473+
"the main file and all non-system headers of each "
474+
"translation unit are always displayed.",
475475
)
476476
parser.add_argument(
477477
"-source-filter",

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ Potentially Breaking Changes
7070
:doc:`bugprone-signed-char-misuse
7171
<clang-tidy/checks/bugprone/signed-char-misuse>`
7272

73+
- :program:`clang-tidy` now displays warnings from all non-system headers by
74+
default. Previously, users had to explicitly opt-in to header warnings using
75+
`-header-filter='.*'`. To disable warnings from non-system, set `-header-filter`
76+
to an empty string.
77+
7378
Improvements to clangd
7479
----------------------
7580

@@ -132,6 +137,11 @@ Improvements to clang-tidy
132137
when run over C files. If ``-std`` is not specified, it defaults to
133138
``c99-or-later``.
134139

140+
- :program:`clang-tidy` now displays warnings from all non-system headers by
141+
default. Previously, users had to explicitly opt-in to header warnings using
142+
`-header-filter='.*'`. To disable warnings from non-system, set `-header-filter`
143+
to an empty string.
144+
135145
- :program:`clang-tidy` no longer attempts to analyze code from system headers
136146
by default, greatly improving performance. This behavior is disabled if the
137147
`SystemHeaders` option is enabled.

clang-tools-extra/docs/clang-tidy/index.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,10 @@ An overview of all the command-line options:
216216
.clang-tidy file, if any.
217217
--header-filter=<string> - Regular expression matching the names of the
218218
headers to output diagnostics from. Diagnostics
219-
from the main file of each translation unit are
220-
always displayed.
219+
from the main file and all non-system headers
220+
of each translation unit are always displayed.
221+
Set this option to an empty string to disable
222+
diagnostics from non-system headers.
221223
Can be used together with -line-filter.
222224
This option overrides the 'HeaderFilterRegex'
223225
option in .clang-tidy file, if any.
@@ -338,7 +340,7 @@ An overview of all the command-line options:
338340
WarningsAsErrors: ''
339341
HeaderFileExtensions: ['', 'h','hh','hpp','hxx']
340342
ImplementationFileExtensions: ['c','cc','cpp','cxx']
341-
HeaderFilterRegex: ''
343+
HeaderFilterRegex: '.*'
342344
FormatStyle: none
343345
InheritParentConfig: true
344346
User: user

clang-tools-extra/test/clang-tidy/checkers/abseil/no-internal-dependencies.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %check_clang_tidy %s abseil-no-internal-dependencies %t, -- -- -I %S/Inputs
1+
// RUN: %check_clang_tidy %s abseil-no-internal-dependencies %t, -- -header-filter='' -- -I %S/Inputs
22
// RUN: clang-tidy -checks='-*, abseil-no-internal-dependencies' -header-filter='.*' %s -- -I %S/Inputs 2>&1 | FileCheck %s
33

44
#include "absl/strings/internal-file.h"

clang-tools-extra/test/clang-tidy/checkers/abseil/no-namespace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %check_clang_tidy %s abseil-no-namespace %t -- -- -I %S/Inputs
1+
// RUN: %check_clang_tidy %s abseil-no-namespace %t -- -header-filter='' -- -I %S/Inputs
22
// RUN: clang-tidy -checks='-*, abseil-no-namespace' -header-filter='.*' %s -- -I %S/Inputs 2>&1 | FileCheck %s
33

44
/// Warning will not be triggered on internal Abseil code that is included.

clang-tools-extra/test/clang-tidy/checkers/bugprone/reserved-identifier.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// RUN: %check_clang_tidy %s bugprone-reserved-identifier %t -- -- \
1+
// RUN: %check_clang_tidy %s bugprone-reserved-identifier %t -- \
2+
// RUN: -header-filter='' -- \
23
// RUN: -I%S/Inputs/reserved-identifier \
34
// RUN: -isystem %S/Inputs/reserved-identifier/system
45

5-
// no warnings expected without -header-filter=
6+
// no warnings expected with -header-filter=''
67
#include "user-header.h"
78
#include <system-header.h>
89

clang-tools-extra/test/clang-tidy/checkers/google/upgrade-googletest-case.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %check_clang_tidy %s google-upgrade-googletest-case %t -- -- -I%S/Inputs
2-
// RUN: %check_clang_tidy -check-suffix=NOSUITE %s google-upgrade-googletest-case %t -- -- -DNOSUITE -I%S/Inputs/gtest/nosuite
1+
// RUN: %check_clang_tidy %s google-upgrade-googletest-case %t -- -- -isystem%S/Inputs
2+
// RUN: %check_clang_tidy -check-suffix=NOSUITE %s google-upgrade-googletest-case %t -- -- -DNOSUITE -isystem%S/Inputs/gtest/nosuite
33

44
#include "gtest/gtest.h"
55

clang-tools-extra/test/clang-tidy/checkers/modernize/replace-auto-ptr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %check_clang_tidy %s modernize-replace-auto-ptr %t -- -- -I %S/Inputs/replace-auto-ptr
1+
// RUN: %check_clang_tidy %s modernize-replace-auto-ptr %t -- -- -isystem %S/Inputs/replace-auto-ptr
22

33
// CHECK-FIXES: #include <utility>
44

0 commit comments

Comments
 (0)