1 //===--- UseStdNumbersCheck.h - clang-tidy ----------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDNUMBERSCHECK_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDNUMBERSCHECK_H
12 #include "../ClangTidyCheck.h"
13 #include "../utils/IncludeInserter.h"
15 namespace clang::tidy::modernize
{
17 /// Finds constants and function calls to math functions that can be replaced
18 /// with c++20's mathematical constants from the ``numbers`` header and
19 /// offers fix-it hints.
20 /// Does not match the use of variables with that value, and instead,
21 /// offers a replacement at the definition of those variables.
23 /// For the user-facing documentation see:
24 /// http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-std-numbers.html
25 class UseStdNumbersCheck
: public ClangTidyCheck
{
27 UseStdNumbersCheck(StringRef Name
, ClangTidyContext
*Context
);
29 bool isLanguageVersionSupported(const LangOptions
&LangOpts
) const override
{
30 return LangOpts
.CPlusPlus20
;
32 void registerMatchers(ast_matchers::MatchFinder
*Finder
) override
;
33 void check(const ast_matchers::MatchFinder::MatchResult
&Result
) override
;
34 void registerPPCallbacks(const SourceManager
&SM
, Preprocessor
*PP
,
35 Preprocessor
*ModuleExpanderPP
) override
;
36 void storeOptions(ClangTidyOptions::OptionMap
&Opts
) override
;
37 std::optional
<TraversalKind
> getCheckTraversalKind() const override
{
38 return TK_IgnoreUnlessSpelledInSource
;
42 utils::IncludeInserter IncludeInserter
;
43 StringRef DiffThresholdString
;
47 } // namespace clang::tidy::modernize
49 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDNUMBERSCHECK_H