MisplacedWideningCastCheck.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //===--- MisplacedWideningCastCheck.h - clang-tidy---------------*- C++ -*-===//
  2. //
  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
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACEDWIDENINGCASTCHECK_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACEDWIDENINGCASTCHECK_H
  10. #include "../ClangTidyCheck.h"
  11. namespace clang::tidy::bugprone {
  12. /// Find casts of calculation results to bigger type. Typically from int to
  13. /// long. If the intention of the cast is to avoid loss of precision then
  14. /// the cast is misplaced, and there can be loss of precision. Otherwise
  15. /// such cast is ineffective.
  16. ///
  17. /// There is one option:
  18. ///
  19. /// - `CheckImplicitCasts`: Whether to check implicit casts as well which may
  20. // be the most common case. Enabled by default.
  21. ///
  22. /// For the user-facing documentation see:
  23. /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/misplaced-widening-cast.html
  24. class MisplacedWideningCastCheck : public ClangTidyCheck {
  25. public:
  26. MisplacedWideningCastCheck(StringRef Name, ClangTidyContext *Context);
  27. void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
  28. void registerMatchers(ast_matchers::MatchFinder *Finder) override;
  29. void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
  30. private:
  31. const bool CheckImplicitCasts;
  32. };
  33. } // namespace clang::tidy::bugprone
  34. #endif