Skip to content

Commit 1bd0fdf

Browse files
authored
[clang-tidy] Emit warnings from user headers by default (#164165)
Closes #158132.
1 parent 2f97761 commit 1bd0fdf

File tree

14 files changed

+67
-22
lines changed

14 files changed

+67
-22
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: 8 additions & 6 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
@@ -132,14 +132,16 @@ file, if any.
132132

133133
static cl::opt<std::string> HeaderFilter("header-filter", desc(R"(
134134
Regular expression matching the names of the
135-
headers to output diagnostics from. Diagnostics
135+
headers to output diagnostics from. The default
136+
value is '.*', i.e. diagnostics from all non-system
137+
headers are displayed by default. Diagnostics
136138
from the main file of each translation unit are
137139
always displayed.
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/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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ An overview of all the command-line options:
215215
This option overrides the 'FormatStyle` option in
216216
.clang-tidy file, if any.
217217
--header-filter=<string> - Regular expression matching the names of the
218-
headers to output diagnostics from. Diagnostics
218+
headers to output diagnostics from. The default
219+
value is '.*', i.e. diagnostics from all non-system
220+
headers are displayed by default. Diagnostics
219221
from the main file of each translation unit are
220222
always displayed.
221223
Can be used together with -line-filter.
@@ -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

clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.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-use-using %t -- -- -fno-delayed-template-parsing -I %S/Inputs/use-using/
1+
// RUN: %check_clang_tidy %s modernize-use-using %t -- -- -fno-delayed-template-parsing -isystem %S/Inputs/use-using/
22

33
typedef int Type;
44
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' [modernize-use-using]

0 commit comments

Comments
 (0)