IO.mapOptional("ExtraArgsBefore", Options.ExtraArgsBefore);
IO.mapOptional("InheritParentConfig", Options.InheritParentConfig);
IO.mapOptional("UseColor", Options.UseColor);
+ IO.mapOptional("SystemHeaders", Options.SystemHeaders);
}
};
cl::init(""),
cl::cat(ClangTidyCategory));
-static cl::opt<bool>
- SystemHeaders("system-headers",
- desc("Display the errors from system headers."),
- cl::init(false), cl::cat(ClangTidyCategory));
+static cl::opt<bool> SystemHeaders("system-headers", desc(R"(
+Display the errors from system headers.
+This option overrides the 'SystemHeaders' option
+in .clang-tidy file, if any.
+)"),
+ cl::init(false), cl::cat(ClangTidyCategory));
+
static cl::opt<std::string> LineFilter("line-filter", desc(R"(
List of files with line ranges to filter the
warnings. Can be used together with
- Fix a potential crash when using the `--dump-config` option.
+- Support specifying `SystemHeaders` in the `.clang-tidy` configuration file,
+ with the same functionality as the command-line option `--system-headers`.
+
New checks
^^^^^^^^^^
format to stderr. When this option is passed,
these per-TU profiles are instead stored as JSON.
--system-headers - Display the errors from system headers.
+ This option overrides the 'SystemHeaders' option
+ in .clang-tidy file, if any.
--use-color - Use colors in diagnostics. If not set, colors
will be used if the terminal connected to
standard output supports colors.
--- /dev/null
+class Foo { Foo(int); };
--- /dev/null
+// RUN: clang-tidy -dump-config -system-headers=true | FileCheck -check-prefix=CHECK-CONFIG-SYSTEM-HEADERS %s
+// RUN: clang-tidy -dump-config -system-headers=false | FileCheck -check-prefix=CHECK-CONFIG-NO-SYSTEM-HEADERS %s
+// RUN: clang-tidy -config='SystemHeaders: true' -dump-config | FileCheck -check-prefix=CHECK-CONFIG-SYSTEM-HEADERS %s
+// RUN: clang-tidy -config='SystemHeaders: false' -dump-config | FileCheck -check-prefix=CHECK-CONFIG-NO-SYSTEM-HEADERS %s
+
+// RUN: clang-tidy -system-headers=true -config='SystemHeaders: true' -dump-config | FileCheck -check-prefix=CHECK-CONFIG-SYSTEM-HEADERS %s
+// RUN: clang-tidy -system-headers=true -config='SystemHeaders: false' -dump-config | FileCheck -check-prefix=CHECK-CONFIG-SYSTEM-HEADERS %s
+// RUN: clang-tidy -system-headers=false -config='SystemHeaders: true' -dump-config | FileCheck -check-prefix=CHECK-CONFIG-NO-SYSTEM-HEADERS %s
+// RUN: clang-tidy -system-headers=false -config='SystemHeaders: false' -dump-config | FileCheck -check-prefix=CHECK-CONFIG-NO-SYSTEM-HEADERS %s
+
+// RUN: clang-tidy -help | FileCheck -check-prefix=CHECK-OPT-PRESENT %s
+
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' -system-headers=true %s -- -isystem %S/Inputs/system-headers 2>&1 | FileCheck -check-prefix=CHECK-SYSTEM-HEADERS %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' -system-headers=false %s -- -isystem %S/Inputs/system-headers 2>&1 | FileCheck -check-prefix=CHECK-NO-SYSTEM-HEADERS %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' -config='SystemHeaders: true' %s -- -isystem %S/Inputs/system-headers 2>&1 | FileCheck -check-prefix=CHECK-SYSTEM-HEADERS %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' -config='SystemHeaders: false' %s -- -isystem %S/Inputs/system-headers 2>&1 | FileCheck -check-prefix=CHECK-NO-SYSTEM-HEADERS %s
+
+#include <system_header.h>
+// CHECK-SYSTEM-HEADERS: system_header.h:1:13: warning: single-argument constructors must be marked explicit
+// CHECK-NO-SYSTEM-HEADERS-NOT: system_header.h:1:13: warning: single-argument constructors must be marked explicit
+
+// CHECK-CONFIG-NO-SYSTEM-HEADERS: SystemHeaders: false
+// CHECK-CONFIG-SYSTEM-HEADERS: SystemHeaders: true
+// CHECK-OPT-PRESENT: --system-headers
ExtraArgs: ['arg1', 'arg2']
ExtraArgsBefore: ['arg-before1', 'arg-before2']
UseColor: false
+ SystemHeaders: false
)",
"Options1"));
ASSERT_TRUE(!!Options1);
ExtraArgs: ['arg3', 'arg4']
ExtraArgsBefore: ['arg-before3', 'arg-before4']
UseColor: true
+ SystemHeaders: true
)",
"Options2"));
ASSERT_TRUE(!!Options2);
Options.ExtraArgsBefore->end(), ","));
ASSERT_TRUE(Options.UseColor.has_value());
EXPECT_TRUE(*Options.UseColor);
+
+ ASSERT_TRUE(Options.SystemHeaders.has_value());
+ EXPECT_TRUE(*Options.SystemHeaders);
}
namespace {
DiagKind(llvm::SourceMgr::DK_Error),
DiagPos(Options.range().Begin),
DiagRange(Options.range()))));
+
+ Options = llvm::Annotations(R"(
+ SystemHeaders: [[NotABool]]
+ )");
+ ParsedOpt = ParseWithDiags(Options.code());
+ EXPECT_TRUE(!ParsedOpt);
+ EXPECT_THAT(Collector.getDiags(),
+ testing::ElementsAre(AllOf(DiagMessage("invalid boolean"),
+ DiagKind(llvm::SourceMgr::DK_Error),
+ DiagPos(Options.range().Begin),
+ DiagRange(Options.range()))));
}
namespace {