blob: faefce1723d559d72c0e852be0e09d2567c8bb58 [file] [log] [blame]
Alexander Kornienko1ca3b832015-03-02 10:46:43 +00001//===--- 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 Kornienko66580552015-03-09 16:52:33 +000010#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_STATICASSERTCHECK_H
11#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_STATICASSERTCHECK_H
Alexander Kornienko1ca3b832015-03-02 10:46:43 +000012
13#include "../ClangTidy.h"
14#include "llvm/ADT/StringRef.h"
15#include <string>
16
17namespace clang {
18namespace tidy {
Kirill Bobyrev11cea452016-08-01 12:06:18 +000019namespace misc {
Alexander Kornienko1ca3b832015-03-02 10:46:43 +000020
Alexander Kornienkof8ed0a82015-08-27 18:01:58 +000021/// Replaces `assert()` with `static_assert()` if the condition is evaluatable
22/// at compile time.
Alexander Kornienko1ca3b832015-03-02 10:46:43 +000023///
Alexander Kornienkof8ed0a82015-08-27 18:01:58 +000024/// The condition of `static_assert()` is evaluated at compile time which is
Alexander Kornienko1ca3b832015-03-02 10:46:43 +000025/// safer and more efficient.
26class StaticAssertCheck : public ClangTidyCheck {
27public:
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
32private:
33 SourceLocation getLastParenLoc(const ASTContext *ASTCtx,
34 SourceLocation AssertLoc);
35};
36
Etienne Bergeron456177b2016-05-02 18:00:29 +000037} // namespace misc
Alexander Kornienko1ca3b832015-03-02 10:46:43 +000038} // namespace tidy
39} // namespace clang
40
Alexander Kornienko66580552015-03-09 16:52:33 +000041#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_STATICASSERTCHECK_H