7
7
// ===----------------------------------------------------------------------===//
8
8
9
9
#include " ClangTidyCheck.h"
10
- #include " llvm/ADT/SmallString.h"
11
10
#include " llvm/ADT/StringRef.h"
12
- #include " llvm/Support/Error .h"
11
+ #include " llvm/ADT/StringSet .h"
13
12
#include " llvm/Support/YAMLParser.h"
14
13
#include < optional>
14
+ #include < string>
15
15
16
16
namespace clang ::tidy {
17
17
@@ -62,16 +62,29 @@ ClangTidyCheck::OptionsView::get(StringRef LocalName) const {
62
62
return std::nullopt;
63
63
}
64
64
65
+ static const llvm::StringSet<> DeprecatedGlobalOptions{
66
+ " StrictMode" ,
67
+ " IgnoreMacros" ,
68
+ };
69
+
65
70
static ClangTidyOptions::OptionMap::const_iterator
66
71
findPriorityOption (const ClangTidyOptions::OptionMap &Options,
67
72
StringRef NamePrefix, StringRef LocalName,
68
- llvm::StringSet<> *Collector) {
73
+ ClangTidyContext *Context) {
74
+ llvm::StringSet<> *Collector = Context->getOptionsCollector ();
69
75
if (Collector) {
70
76
Collector->insert ((NamePrefix + LocalName).str ());
71
77
Collector->insert (LocalName);
72
78
}
73
79
auto IterLocal = Options.find ((NamePrefix + LocalName).str ());
74
80
auto IterGlobal = Options.find (LocalName);
81
+ // FIXME: temporary solution for deprecation warnings, should be removed
82
+ // after 22.x. Warn configuration deps on deprecation global options.
83
+ if (IterLocal == Options.end () && IterGlobal != Options.end () &&
84
+ DeprecatedGlobalOptions.contains (LocalName))
85
+ Context->configurationDiag (
86
+ " global option '%0' is deprecated, please use '%1%0' instead." )
87
+ << LocalName << NamePrefix;
75
88
if (IterLocal == Options.end ())
76
89
return IterGlobal;
77
90
if (IterGlobal == Options.end ())
@@ -83,8 +96,7 @@ findPriorityOption(const ClangTidyOptions::OptionMap &Options,
83
96
84
97
std::optional<StringRef>
85
98
ClangTidyCheck::OptionsView::getLocalOrGlobal (StringRef LocalName) const {
86
- auto Iter = findPriorityOption (CheckOptions, NamePrefix, LocalName,
87
- Context->getOptionsCollector ());
99
+ auto Iter = findPriorityOption (CheckOptions, NamePrefix, LocalName, Context);
88
100
if (Iter != CheckOptions.end ())
89
101
return StringRef (Iter->getValue ().Value );
90
102
return std::nullopt;
@@ -117,8 +129,7 @@ ClangTidyCheck::OptionsView::get<bool>(StringRef LocalName) const {
117
129
template <>
118
130
std::optional<bool >
119
131
ClangTidyCheck::OptionsView::getLocalOrGlobal<bool >(StringRef LocalName) const {
120
- auto Iter = findPriorityOption (CheckOptions, NamePrefix, LocalName,
121
- Context->getOptionsCollector ());
132
+ auto Iter = findPriorityOption (CheckOptions, NamePrefix, LocalName, Context);
122
133
if (Iter != CheckOptions.end ()) {
123
134
if (auto Result = getAsBool (Iter->getValue ().Value , Iter->getKey ()))
124
135
return Result;
@@ -157,10 +168,9 @@ std::optional<int64_t> ClangTidyCheck::OptionsView::getEnumInt(
157
168
bool IgnoreCase) const {
158
169
if (!CheckGlobal && Context->getOptionsCollector ())
159
170
Context->getOptionsCollector ()->insert ((NamePrefix + LocalName).str ());
160
- auto Iter = CheckGlobal
161
- ? findPriorityOption (CheckOptions, NamePrefix, LocalName,
162
- Context->getOptionsCollector ())
163
- : CheckOptions.find ((NamePrefix + LocalName).str ());
171
+ auto Iter = CheckGlobal ? findPriorityOption (CheckOptions, NamePrefix,
172
+ LocalName, Context)
173
+ : CheckOptions.find ((NamePrefix + LocalName).str ());
164
174
if (Iter == CheckOptions.end ())
165
175
return std::nullopt;
166
176
0 commit comments