njames93 created this revision.
njames93 added reviewers: aaron.ballman, alexfh, gribozavr2.
Herald added subscribers: cfe-commits, arphaman, kbarton, xazax.hun, nemanjai.
Herald added a project: clang.
njames93 marked an inline comment as done.
njames93 added inline comments.
Herald added a subscriber: wuzish.
================
Comment at:
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp:31
Options.store(Opts, "GslHeader", GslHeader);
- Options.store(Opts, "IncludeStyle", IncludeStyle);
+ Options.store(Opts, "IncludeStyle", IncludeStyle,
+ utils::IncludeSorter::getMapping());
----------------
Had to force this to explicitly call the correct function to avoid a compile
error
Following on fcf7cc268fe
<https://reviews.llvm.org/rGfcf7cc268fe4560bc7cd751494beceff45f5dd10> and
672207c319a
<https://reviews.llvm.org/rG672207c319a06f20dc634bcd21678d5dbbe7a6b9> which
granted checks the ability to read boolean configuration arguments as `true` or
`false`.
This enables storing the options back to the configuration file using `true`
and `false`.
This is in line with how clang-format dumps boolean options in its style config.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D83053
Files:
clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
clang-tools-extra/clang-tidy/ClangTidyCheck.h
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
Index: clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
@@ -18,13 +18,13 @@
// RUN: clang-tidy -dump-config %S/Inputs/config-files/4/44/- -- | FileCheck %s -check-prefix=CHECK-CHILD4
// CHECK-CHILD4: Checks: {{.*}}modernize-loop-convert,modernize-use-using,llvm-qualified-auto
// CHECK-CHILD4: - key: llvm-qualified-auto.AddConstToQualified
-// CHECK-CHILD4-NEXT: value: '1'
+// CHECK-CHILD4-NEXT: value: 'true'
// CHECK-CHILD4: - key: modernize-loop-convert.MaxCopySize
// CHECK-CHILD4-NEXT: value: '20'
// CHECK-CHILD4: - key: modernize-loop-convert.MinConfidence
// CHECK-CHILD4-NEXT: value: reasonable
// CHECK-CHILD4: - key: modernize-use-using.IgnoreMacros
-// CHECK-CHILD4-NEXT: value: '0'
+// CHECK-CHILD4-NEXT: value: 'false'
// RUN: clang-tidy --explain-config %S/Inputs/config-files/4/44/- -- | FileCheck %s -check-prefix=CHECK-EXPLAIN
// CHECK-EXPLAIN: 'llvm-qualified-auto' is enabled in the {{.*}}{{[/\\]}}Inputs{{[/\\]}}config-files{{[/\\]}}4{{[/\\]}}44{{[/\\]}}.clang-tidy.
@@ -42,7 +42,7 @@
// CHECK-CHILD5: - key: modernize-loop-convert.MinConfidence
// CHECK-CHILD5-NEXT: value: reasonable
// CHECK-CHILD5: - key: modernize-use-using.IgnoreMacros
-// CHECK-CHILD5-NEXT: value: '0'
+// CHECK-CHILD5-NEXT: value: 'false'
// RUN: clang-tidy -dump-config \
// RUN: --config='{InheritParentConfig: false, \
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
@@ -28,7 +28,8 @@
void ProBoundsConstantArrayIndexCheck::storeOptions(
ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "GslHeader", GslHeader);
- Options.store(Opts, "IncludeStyle", IncludeStyle);
+ Options.store(Opts, "IncludeStyle", IncludeStyle,
+ utils::IncludeSorter::getMapping());
}
void ProBoundsConstantArrayIndexCheck::registerPPCallbacks(
Index: clang-tools-extra/clang-tidy/ClangTidyCheck.h
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidyCheck.h
+++ clang-tools-extra/clang-tidy/ClangTidyCheck.h
@@ -395,9 +395,13 @@
StringRef Value) const;
/// Stores an option with the check-local name \p LocalName with
- /// ``int64_t`` value \p Value to \p Options.
- void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
- int64_t Value) const;
+ /// integer value \p Value to \p Options.
+ template <typename T>
+ std::enable_if_t<std::is_integral<T>::value>
+ store(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
+ T Value) const {
+ storeInt(Options, LocalName, Value);
+ }
/// Stores an option with the check-local name \p LocalName as the string
/// representation of the Enum \p Value using the \p Mapping to \p Options.
@@ -432,6 +436,9 @@
return Result;
}
+ void storeInt(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
+ int64_t Value) const;
+
static void logErrToStdErr(llvm::Error &&Err);
std::string NamePrefix;
@@ -493,6 +500,13 @@
bool ClangTidyCheck::OptionsView::getLocalOrGlobal<bool>(StringRef LocalName,
bool Default) const;
+/// Stores an option with the check-local name \p LocalName with
+/// bool value \p Value to \p Options.
+template <>
+void ClangTidyCheck::OptionsView::store<bool>(
+ ClangTidyOptions::OptionMap &Options, StringRef LocalName,
+ bool Value) const;
+
} // namespace tidy
} // namespace clang
Index: clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
@@ -151,11 +151,17 @@
Options[NamePrefix + LocalName.str()] = Value;
}
-void ClangTidyCheck::OptionsView::store(ClangTidyOptions::OptionMap &Options,
- StringRef LocalName,
- int64_t Value) const {
+void ClangTidyCheck::OptionsView::storeInt(ClangTidyOptions::OptionMap &Options,
+ StringRef LocalName,
+ int64_t Value) const {
store(Options, LocalName, llvm::itostr(Value));
}
+template <>
+void ClangTidyCheck::OptionsView::store<bool>(
+ ClangTidyOptions::OptionMap &Options, StringRef LocalName,
+ bool Value) const {
+ store(Options, LocalName, Value ? StringRef("true") : StringRef("false"));
+}
llvm::Expected<int64_t> ClangTidyCheck::OptionsView::getEnumInt(
StringRef LocalName, ArrayRef<std::pair<StringRef, int64_t>> Mapping,
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits