1313#include " ClangTidyOptions.h"
1414#include " clang/ASTMatchers/ASTMatchFinder.h"
1515#include " clang/Basic/Diagnostic.h"
16- #include " llvm/ADT/Optional.h "
16+ #include < optional >
1717#include < type_traits>
1818#include < utility>
1919#include < vector>
@@ -154,8 +154,8 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
154154 // /
155155 // / Reads the option with the check-local name \p LocalName from the
156156 // / ``CheckOptions``. If the corresponding key is not present, return
157- // / ``None ``.
158- llvm::Optional <StringRef> get (StringRef LocalName) const ;
157+ // / ``std::nullopt ``.
158+ std::optional <StringRef> get (StringRef LocalName) const ;
159159
160160 // / Read a named option from the ``Context``.
161161 // /
@@ -169,8 +169,8 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
169169 // / Reads the option with the check-local name \p LocalName from local or
170170 // / global ``CheckOptions``. Gets local option first. If local is not
171171 // / present, falls back to get global option. If global option is not
172- // / present either, return ``None ``.
173- llvm::Optional <StringRef> getLocalOrGlobal (StringRef LocalName) const ;
172+ // / present either, return ``std::nullopt ``.
173+ std::optional <StringRef> getLocalOrGlobal (StringRef LocalName) const ;
174174
175175 // / Read a named option from the ``Context``.
176176 // /
@@ -185,20 +185,20 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
185185 // /
186186 // / Reads the option with the check-local name \p LocalName from the
187187 // / ``CheckOptions``. If the corresponding key is not present, return
188- // / ``None ``.
188+ // / ``std::nullopt ``.
189189 // /
190190 // / If the corresponding key can't be parsed as a ``T``, emit a
191- // / diagnostic and return ``None ``.
191+ // / diagnostic and return ``std::nullopt ``.
192192 template <typename T>
193- std::enable_if_t <std::is_integral<T>::value, llvm::Optional <T>>
193+ std::enable_if_t <std::is_integral<T>::value, std::optional <T>>
194194 get (StringRef LocalName) const {
195- if (llvm::Optional <StringRef> Value = get (LocalName)) {
195+ if (std::optional <StringRef> Value = get (LocalName)) {
196196 T Result{};
197197 if (!StringRef (*Value).getAsInteger (10 , Result))
198198 return Result;
199199 diagnoseBadIntegerOption (NamePrefix + LocalName, *Value);
200200 }
201- return None ;
201+ return std:: nullopt ;
202202 }
203203
204204 // / Read a named option from the ``Context`` and parse it as an
@@ -222,27 +222,27 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
222222 // / Reads the option with the check-local name \p LocalName from local or
223223 // / global ``CheckOptions``. Gets local option first. If local is not
224224 // / present, falls back to get global option. If global option is not
225- // / present either, return ``None ``.
225+ // / present either, return ``std::nullopt ``.
226226 // /
227227 // / If the corresponding key can't be parsed as a ``T``, emit a
228- // / diagnostic and return ``None ``.
228+ // / diagnostic and return ``std::nullopt ``.
229229 template <typename T>
230- std::enable_if_t <std::is_integral<T>::value, llvm::Optional <T>>
230+ std::enable_if_t <std::is_integral<T>::value, std::optional <T>>
231231 getLocalOrGlobal (StringRef LocalName) const {
232- llvm::Optional <StringRef> ValueOr = get (LocalName);
232+ std::optional <StringRef> ValueOr = get (LocalName);
233233 bool IsGlobal = false ;
234234 if (!ValueOr) {
235235 IsGlobal = true ;
236236 ValueOr = getLocalOrGlobal (LocalName);
237237 if (!ValueOr)
238- return None ;
238+ return std:: nullopt ;
239239 }
240240 T Result{};
241241 if (!StringRef (*ValueOr).getAsInteger (10 , Result))
242242 return Result;
243243 diagnoseBadIntegerOption (
244244 IsGlobal ? Twine (LocalName) : NamePrefix + LocalName, *ValueOr);
245- return None ;
245+ return std:: nullopt ;
246246 }
247247
248248 // / Read a named option from the ``Context`` and parse it as an
@@ -266,20 +266,20 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
266266 // /
267267 // / Reads the option with the check-local name \p LocalName from the
268268 // / ``CheckOptions``. If the corresponding key is not present, return
269- // / ``None ``.
269+ // / ``std::nullopt ``.
270270 // /
271271 // / If the corresponding key can't be parsed as a ``T``, emit a
272- // / diagnostic and return ``None ``.
272+ // / diagnostic and return ``std::nullopt ``.
273273 // /
274274 // / \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
275275 // / supply the mapping required to convert between ``T`` and a string.
276276 template <typename T>
277- std::enable_if_t <std::is_enum<T>::value, llvm::Optional <T>>
277+ std::enable_if_t <std::is_enum<T>::value, std::optional <T>>
278278 get (StringRef LocalName, bool IgnoreCase = false ) const {
279- if (llvm::Optional <int64_t > ValueOr =
279+ if (std::optional <int64_t > ValueOr =
280280 getEnumInt (LocalName, typeEraseMapping<T>(), false , IgnoreCase))
281281 return static_cast <T>(*ValueOr);
282- return None ;
282+ return std:: nullopt ;
283283 }
284284
285285 // / Read a named option from the ``Context`` and parse it as an
@@ -306,20 +306,20 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
306306 // / Reads the option with the check-local name \p LocalName from local or
307307 // / global ``CheckOptions``. Gets local option first. If local is not
308308 // / present, falls back to get global option. If global option is not
309- // / present either, returns ``None ``.
309+ // / present either, returns ``std::nullopt ``.
310310 // /
311311 // / If the corresponding key can't be parsed as a ``T``, emit a
312- // / diagnostic and return ``None ``.
312+ // / diagnostic and return ``std::nullopt ``.
313313 // /
314314 // / \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
315315 // / supply the mapping required to convert between ``T`` and a string.
316316 template <typename T>
317- std::enable_if_t <std::is_enum<T>::value, llvm::Optional <T>>
317+ std::enable_if_t <std::is_enum<T>::value, std::optional <T>>
318318 getLocalOrGlobal (StringRef LocalName, bool IgnoreCase = false ) const {
319- if (llvm::Optional <int64_t > ValueOr =
319+ if (std::optional <int64_t > ValueOr =
320320 getEnumInt (LocalName, typeEraseMapping<T>(), true , IgnoreCase))
321321 return static_cast <T>(*ValueOr);
322- return None ;
322+ return std:: nullopt ;
323323 }
324324
325325 // / Read a named option from the ``Context`` and parse it as an
@@ -378,9 +378,9 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
378378 private:
379379 using NameAndValue = std::pair<int64_t , StringRef>;
380380
381- llvm::Optional <int64_t > getEnumInt (StringRef LocalName,
382- ArrayRef<NameAndValue> Mapping,
383- bool CheckGlobal, bool IgnoreCase) const ;
381+ std::optional <int64_t > getEnumInt (StringRef LocalName,
382+ ArrayRef<NameAndValue> Mapping,
383+ bool CheckGlobal, bool IgnoreCase) const ;
384384
385385 template <typename T>
386386 std::enable_if_t <std::is_enum<T>::value, std::vector<NameAndValue>>
@@ -407,7 +407,6 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
407407
408408private:
409409 void run (const ast_matchers::MatchFinder::MatchResult &Result) override ;
410- StringRef getID () const override { return CheckName; }
411410 std::string CheckName;
412411 ClangTidyContext *Context;
413412
@@ -422,18 +421,19 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
422421 bool areDiagsSelfContained () const {
423422 return Context->areDiagsSelfContained ();
424423 }
424+ StringRef getID () const override { return CheckName; }
425425};
426426
427427// / Read a named option from the ``Context`` and parse it as a bool.
428428// /
429429// / Reads the option with the check-local name \p LocalName from the
430430// / ``CheckOptions``. If the corresponding key is not present, return
431- // / ``None ``.
431+ // / ``std::nullopt ``.
432432// /
433433// / If the corresponding key can't be parsed as a bool, emit a
434- // / diagnostic and return ``None ``.
434+ // / diagnostic and return ``std::nullopt ``.
435435template <>
436- llvm::Optional <bool >
436+ std::optional <bool >
437437ClangTidyCheck::OptionsView::get<bool >(StringRef LocalName) const ;
438438
439439// / Read a named option from the ``Context`` and parse it as a bool.
@@ -445,7 +445,7 @@ ClangTidyCheck::OptionsView::get<bool>(StringRef LocalName) const;
445445// / If the corresponding key can't be parsed as a bool, emit a
446446// / diagnostic and return \p Default.
447447template <>
448- llvm::Optional <bool >
448+ std::optional <bool >
449449ClangTidyCheck::OptionsView::getLocalOrGlobal<bool >(StringRef LocalName) const ;
450450
451451// / Stores an option with the check-local name \p LocalName with
0 commit comments