Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ ClangTidyOptions ClangTidyOptions::getDefaults() {
Options.WarningsAsErrors = "";
Options.HeaderFileExtensions = {"", "h", "hh", "hpp", "hxx"};
Options.ImplementationFileExtensions = {"c", "cc", "cpp", "cxx"};
Options.HeaderFilterRegex = "";
Options.HeaderFilterRegex = ".*";
Options.ExcludeHeaderFilterRegex = "";
Options.SystemHeaders = false;
Options.FormatStyle = "none";
Expand Down
16 changes: 9 additions & 7 deletions clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Configuration files:
WarningsAsErrors: ''
HeaderFileExtensions: ['', 'h','hh','hpp','hxx']
ImplementationFileExtensions: ['c','cc','cpp','cxx']
HeaderFilterRegex: ''
HeaderFilterRegex: '.*'
FormatStyle: none
InheritParentConfig: true
User: user
Expand Down Expand Up @@ -133,13 +133,15 @@ file, if any.
static cl::opt<std::string> HeaderFilter("header-filter", desc(R"(
Regular expression matching the names of the
headers to output diagnostics from. Diagnostics
from the main file of each translation unit are
always displayed.
from the main file and all non-system headers
of each translation unit are always displayed.
Set this option to an empty string to disable
diagnostics from non-system headers.
Comment on lines +136 to +139
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wording is a bit confusing to me. Warnings from non-system headers are not always displayed, the point is that you can disable them with this option, right? Something like this seems more accurate to me:

Suggested change
from the main file and all non-system headers
of each translation unit are always displayed.
Set this option to an empty string to disable
diagnostics from non-system headers.
from the main file of each translation unit
are always displayed. Diagnostics from
non-system headers it includes are displayed
by default, but can be disabled with this option.

(Also applies in other places where the wording is repeated)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would simply keep the original text as-is and document what the default value for this option is (if it's not already stated somewhere else).

Can be used together with -line-filter.
This option overrides the 'HeaderFilterRegex'
option in .clang-tidy file, if any.
)"),
cl::init(""),
cl::init(".*"),
cl::cat(ClangTidyCategory));

static cl::opt<std::string> ExcludeHeaderFilter("exclude-header-filter",
Expand Down Expand Up @@ -379,9 +381,9 @@ static void printStats(const ClangTidyStats &Stats) {
<< " with check filters";
llvm::errs() << ").\n";
if (Stats.ErrorsIgnoredNonUserCode)
llvm::errs() << "Use -header-filter=.* to display errors from all "
"non-system headers. Use -system-headers to display "
"errors from system headers as well.\n";
llvm::errs() << "Use -header-filter=.* or leave it as default to display "
"errors from all non-system headers. Use -system-headers "
"to display errors from system headers as well.\n";
}
}

Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,8 @@ async def main() -> None:
default=None,
help="Regular expression matching the names of the "
"headers to output diagnostics from. Diagnostics from "
"the main file of each translation unit are always "
"displayed.",
"the main file and all non-system headers of each "
"translation unit are always displayed.",
)
parser.add_argument(
"-source-filter",
Expand Down
10 changes: 10 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ Potentially Breaking Changes
:doc:`bugprone-signed-char-misuse
<clang-tidy/checks/bugprone/signed-char-misuse>`

- :program:`clang-tidy` now displays warnings from all non-system headers by
default. Previously, users had to explicitly opt-in to header warnings using
`-header-filter='.*'`. To disable warnings from non-system, set `-header-filter`
to an empty string.

Improvements to clangd
----------------------

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

- :program:`clang-tidy` now displays warnings from all non-system headers by
default. Previously, users had to explicitly opt-in to header warnings using
`-header-filter='.*'`. To disable warnings from non-system, set `-header-filter`
to an empty string.

- :program:`clang-tidy` no longer attemps to analyze code from system headers
by default, greatly improving performance. This behavior is disabled if the
`SystemHeaders` option is enabled.
Expand Down
8 changes: 5 additions & 3 deletions clang-tools-extra/docs/clang-tidy/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,10 @@ An overview of all the command-line options:
.clang-tidy file, if any.
--header-filter=<string> - Regular expression matching the names of the
headers to output diagnostics from. Diagnostics
from the main file of each translation unit are
always displayed.
from the main file and all non-system headers
of each translation unit are always displayed.
Set this option to an empty string to disable
diagnostics from non-system headers.
Can be used together with -line-filter.
This option overrides the 'HeaderFilterRegex'
option in .clang-tidy file, if any.
Expand Down Expand Up @@ -338,7 +340,7 @@ An overview of all the command-line options:
WarningsAsErrors: ''
HeaderFileExtensions: ['', 'h','hh','hpp','hxx']
ImplementationFileExtensions: ['c','cc','cpp','cxx']
HeaderFilterRegex: ''
HeaderFilterRegex: '.*'
FormatStyle: none
InheritParentConfig: true
User: user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s abseil-no-internal-dependencies %t, -- -- -I %S/Inputs
// RUN: %check_clang_tidy %s abseil-no-internal-dependencies %t, -- -header-filter='' -- -I %S/Inputs
// RUN: clang-tidy -checks='-*, abseil-no-internal-dependencies' -header-filter='.*' %s -- -I %S/Inputs 2>&1 | FileCheck %s

#include "absl/strings/internal-file.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s abseil-no-namespace %t -- -- -I %S/Inputs
// RUN: %check_clang_tidy %s abseil-no-namespace %t -- -header-filter='' -- -I %S/Inputs
// RUN: clang-tidy -checks='-*, abseil-no-namespace' -header-filter='.*' %s -- -I %S/Inputs 2>&1 | FileCheck %s

/// Warning will not be triggered on internal Abseil code that is included.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// RUN: %check_clang_tidy %s bugprone-reserved-identifier %t -- -- \
// RUN: %check_clang_tidy %s bugprone-reserved-identifier %t -- \
// RUN: -header-filter='' -- \
// RUN: -I%S/Inputs/reserved-identifier \
// RUN: -isystem %S/Inputs/reserved-identifier/system

// no warnings expected without -header-filter=
// no warnings expected with -header-filter=''
#include "user-header.h"
#include <system-header.h>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %check_clang_tidy %s google-upgrade-googletest-case %t -- -- -I%S/Inputs
// RUN: %check_clang_tidy -check-suffix=NOSUITE %s google-upgrade-googletest-case %t -- -- -DNOSUITE -I%S/Inputs/gtest/nosuite
// RUN: %check_clang_tidy %s google-upgrade-googletest-case %t -- -- -isystem%S/Inputs
// RUN: %check_clang_tidy -check-suffix=NOSUITE %s google-upgrade-googletest-case %t -- -- -DNOSUITE -isystem%S/Inputs/gtest/nosuite

#include "gtest/gtest.h"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s modernize-replace-auto-ptr %t -- -- -I %S/Inputs/replace-auto-ptr
// RUN: %check_clang_tidy %s modernize-replace-auto-ptr %t -- -- -isystem %S/Inputs/replace-auto-ptr

// CHECK-FIXES: #include <utility>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s modernize-use-using %t -- -- -fno-delayed-template-parsing -I %S/Inputs/use-using/
// RUN: %check_clang_tidy %s modernize-use-using %t -- -- -fno-delayed-template-parsing -isystem %S/Inputs/use-using/

typedef int Type;
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' [modernize-use-using]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// RUN: %check_clang_tidy %s readability-duplicate-include %t -- -- -isystem %S/Inputs/duplicate-include/system -I %S/Inputs/duplicate-include
// RUN: %check_clang_tidy %s readability-duplicate-include %t -- \
// RUN: -header-filter='' \
// RUN: -- -isystem %S/Inputs/duplicate-include/system -I %S/Inputs/duplicate-include

int a;
#include <string.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@
// RUN: readability-identifier-naming.LocalPointerPrefix: 'l_', \
// RUN: readability-identifier-naming.LocalConstantPointerCase: CamelCase, \
// RUN: readability-identifier-naming.LocalConstantPointerPrefix: 'lc_', \
// RUN: }}' -- -fno-delayed-template-parsing -Dbad_macro \
// RUN: }}' \
// RUN: -header-filter='' \
// RUN: -- -fno-delayed-template-parsing -Dbad_macro \
// RUN: -I%S/Inputs/identifier-naming \
// RUN: -isystem %S/Inputs/identifier-naming/system

Expand All @@ -91,8 +93,7 @@
#include <system-header.h>
#include <coroutines.h>
#include "user-header.h"
// NO warnings or fixes expected from declarations within header files without
// the -header-filter= option
// NO warnings or fixes expected from declarations with the -header-filter='' option

namespace FOO_NS {
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for namespace 'FOO_NS' [readability-identifier-naming]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

// RUN: clang-tidy -checks='-*,google-explicit-constructor' --config='{}' %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK-DEFAULT %s
// RUN: clang-tidy -checks='-*,google-explicit-constructor' --config='{}' -header-filter='' %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK-EMPTY %s
// RUN: clang-tidy -checks='-*,google-explicit-constructor' --config='{}' -header-filter='.*' %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK-EXPLICIT %s
// RUN: clang-tidy -checks='-*,google-explicit-constructor' --config='{}' %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK-NO-SYSTEM %s
// RUN: clang-tidy -checks='-*,google-explicit-constructor' --config='{}' -system-headers %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK-WITH-SYSTEM %s

#include "header1.h"
// CHECK-DEFAULT: header1.h:1:12: warning: single-argument constructors must be marked explicit
// CHECK-EMPTY-NOT: header1.h:1:12: warning:
// CHECK-EXPLICIT: header1.h:1:12: warning: single-argument constructors must be marked explicit
// CHECK-NO-SYSTEM: header1.h:1:12: warning: single-argument constructors must be marked explicit
// CHECK-WITH-SYSTEM: header1.h:1:12: warning: single-argument constructors must be marked explicit

#include <system-header.h>
// CHECK-DEFAULT-NOT: system-header.h:1:12: warning:
// CHECK-EMPTY-NOT: system-header.h:1:12: warning:
// CHECK-EXPLICIT-NOT: system-header.h:1:12: warning:
// CHECK-NO-SYSTEM-NOT: system-header.h:1:12: warning:
// CHECK-WITH-SYSTEM: system-header.h:1:12: warning: single-argument constructors must be marked explicit

class A { A(int); };
// CHECK-DEFAULT: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit
// CHECK-EMPTY: :[[@LINE-2]]:11: warning: single-argument constructors must be marked explicit
// CHECK-EXPLICIT: :[[@LINE-3]]:11: warning: single-argument constructors must be marked explicit
// CHECK-NO-SYSTEM: :[[@LINE-4]]:11: warning: single-argument constructors must be marked explicit
// CHECK-WITH-SYSTEM: :[[@LINE-5]]:11: warning: single-argument constructors must be marked explicit
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class A { A(int); };
// CHECK4-NOT: warning:
// CHECK4-QUIET-NOT: warning:

// CHECK: Use -header-filter=.* to display errors from all non-system headers.
// CHECK: Use -header-filter=.* or leave it as default to display errors from all non-system headers.
// CHECK-QUIET-NOT: Suppressed
// CHECK2-QUIET-NOT: Suppressed
// CHECK3: Use -header-filter=.* {{.*}}
Expand Down
Loading