77// ===----------------------------------------------------------------------===//
88
99#include " ClangTidyCheck.h"
10- #include " llvm/ADT/SmallString.h"
1110#include " llvm/ADT/StringRef.h"
12- #include " llvm/Support/Error .h"
11+ #include " llvm/ADT/StringSet .h"
1312#include " llvm/Support/YAMLParser.h"
1413#include < optional>
14+ #include < string>
1515
1616namespace clang ::tidy {
1717
@@ -62,16 +62,29 @@ ClangTidyCheck::OptionsView::get(StringRef LocalName) const {
6262 return std::nullopt ;
6363}
6464
65+ static const llvm::StringSet<> DeprecatedGlobalOptions{
66+ " StrictMode" ,
67+ " IgnoreMacros" ,
68+ };
69+
6570static ClangTidyOptions::OptionMap::const_iterator
6671findPriorityOption (const ClangTidyOptions::OptionMap &Options,
6772 StringRef NamePrefix, StringRef LocalName,
68- llvm::StringSet<> *Collector) {
73+ ClangTidyContext *Context) {
74+ llvm::StringSet<> *Collector = Context->getOptionsCollector ();
6975 if (Collector) {
7076 Collector->insert ((NamePrefix + LocalName).str ());
7177 Collector->insert (LocalName);
7278 }
7379 auto IterLocal = Options.find ((NamePrefix + LocalName).str ());
7480 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;
7588 if (IterLocal == Options.end ())
7689 return IterGlobal;
7790 if (IterGlobal == Options.end ())
@@ -83,8 +96,7 @@ findPriorityOption(const ClangTidyOptions::OptionMap &Options,
8396
8497std::optional<StringRef>
8598ClangTidyCheck::OptionsView::getLocalOrGlobal (StringRef LocalName) const {
86- auto Iter = findPriorityOption (CheckOptions, NamePrefix, LocalName,
87- Context->getOptionsCollector ());
99+ auto Iter = findPriorityOption (CheckOptions, NamePrefix, LocalName, Context);
88100 if (Iter != CheckOptions.end ())
89101 return StringRef (Iter->getValue ().Value );
90102 return std::nullopt ;
@@ -117,8 +129,7 @@ ClangTidyCheck::OptionsView::get<bool>(StringRef LocalName) const {
117129template <>
118130std::optional<bool >
119131ClangTidyCheck::OptionsView::getLocalOrGlobal<bool >(StringRef LocalName) const {
120- auto Iter = findPriorityOption (CheckOptions, NamePrefix, LocalName,
121- Context->getOptionsCollector ());
132+ auto Iter = findPriorityOption (CheckOptions, NamePrefix, LocalName, Context);
122133 if (Iter != CheckOptions.end ()) {
123134 if (auto Result = getAsBool (Iter->getValue ().Value , Iter->getKey ()))
124135 return Result;
@@ -157,10 +168,9 @@ std::optional<int64_t> ClangTidyCheck::OptionsView::getEnumInt(
157168 bool IgnoreCase) const {
158169 if (!CheckGlobal && Context->getOptionsCollector ())
159170 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 ());
164174 if (Iter == CheckOptions.end ())
165175 return std::nullopt ;
166176
0 commit comments