1 //===--- UnaryStaticAssertCheck.cpp - clang-tidy---------------------------===//
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 #include "UnaryStaticAssertCheck.h"
10 #include "clang/AST/ASTContext.h"
11 #include "clang/ASTMatchers/ASTMatchFinder.h"
13 using namespace clang::ast_matchers
;
15 namespace clang::tidy::modernize
{
17 void UnaryStaticAssertCheck::registerMatchers(MatchFinder
*Finder
) {
18 Finder
->addMatcher(staticAssertDecl().bind("static_assert"), this);
21 void UnaryStaticAssertCheck::check(const MatchFinder::MatchResult
&Result
) {
22 const auto *MatchedDecl
=
23 Result
.Nodes
.getNodeAs
<StaticAssertDecl
>("static_assert");
24 const auto *AssertMessage
=
25 dyn_cast_if_present
<StringLiteral
>(MatchedDecl
->getMessage());
27 SourceLocation Loc
= MatchedDecl
->getLocation();
29 if (!AssertMessage
|| AssertMessage
->getLength() ||
30 AssertMessage
->getBeginLoc().isMacroID() || Loc
.isMacroID())
34 "use unary 'static_assert' when the string literal is an empty string")
35 << FixItHint::CreateRemoval(AssertMessage
->getSourceRange());
38 } // namespace clang::tidy::modernize