Alexander Kornienko | 1ca3b83 | 2015-03-02 10:46:43 +0000 | [diff] [blame] | 1 | //===--- StaticAssertCheck.h - clang-tidy -----------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Alexander Kornienko | 6658055 | 2015-03-09 16:52:33 +0000 | [diff] [blame] | 10 | #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_STATICASSERTCHECK_H |
| 11 | #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_STATICASSERTCHECK_H |
Alexander Kornienko | 1ca3b83 | 2015-03-02 10:46:43 +0000 | [diff] [blame] | 12 | |
| 13 | #include "../ClangTidy.h" |
| 14 | #include "llvm/ADT/StringRef.h" |
| 15 | #include <string> |
| 16 | |
| 17 | namespace clang { |
| 18 | namespace tidy { |
Kirill Bobyrev | 11cea45 | 2016-08-01 12:06:18 +0000 | [diff] [blame] | 19 | namespace misc { |
Alexander Kornienko | 1ca3b83 | 2015-03-02 10:46:43 +0000 | [diff] [blame] | 20 | |
Alexander Kornienko | f8ed0a8 | 2015-08-27 18:01:58 +0000 | [diff] [blame] | 21 | /// Replaces `assert()` with `static_assert()` if the condition is evaluatable |
| 22 | /// at compile time. |
Alexander Kornienko | 1ca3b83 | 2015-03-02 10:46:43 +0000 | [diff] [blame] | 23 | /// |
Alexander Kornienko | f8ed0a8 | 2015-08-27 18:01:58 +0000 | [diff] [blame] | 24 | /// The condition of `static_assert()` is evaluated at compile time which is |
Alexander Kornienko | 1ca3b83 | 2015-03-02 10:46:43 +0000 | [diff] [blame] | 25 | /// safer and more efficient. |
| 26 | class StaticAssertCheck : public ClangTidyCheck { |
| 27 | public: |
| 28 | StaticAssertCheck(StringRef Name, ClangTidyContext *Context); |
| 29 | void registerMatchers(ast_matchers::MatchFinder *Finder) override; |
| 30 | void check(const ast_matchers::MatchFinder::MatchResult &Result) override; |
| 31 | |
| 32 | private: |
| 33 | SourceLocation getLastParenLoc(const ASTContext *ASTCtx, |
| 34 | SourceLocation AssertLoc); |
| 35 | }; |
| 36 | |
Etienne Bergeron | 456177b | 2016-05-02 18:00:29 +0000 | [diff] [blame] | 37 | } // namespace misc |
Alexander Kornienko | 1ca3b83 | 2015-03-02 10:46:43 +0000 | [diff] [blame] | 38 | } // namespace tidy |
| 39 | } // namespace clang |
| 40 | |
Alexander Kornienko | 6658055 | 2015-03-09 16:52:33 +0000 | [diff] [blame] | 41 | #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_STATICASSERTCHECK_H |