clang-tools 10.0.0

RedundantVoidArgCheck.h
Go to the documentation of this file.
1 //===--- RedundantVoidArgCheck.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
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REDUNDANT_VOID_ARG_CHECK_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REDUNDANT_VOID_ARG_CHECK_H
11
12 #include "../ClangTidyCheck.h"
13 #include "clang/Lex/Token.h"
14
15 #include <string>
16
17 namespace clang {
18 namespace tidy {
19 namespace modernize {
20
21 /// Find and remove redundant void argument lists.
22 ///
23 /// Examples:
24 /// `int f(void);` becomes `int f();`
25 /// `int (*f(void))(void);` becomes `int (*f())();`
26 /// `typedef int (*f_t(void))(void);` becomes `typedef int (*f_t())();`
27 /// `void (C::*p)(void);` becomes `void (C::*p)();`
28 /// `C::C(void) {}` becomes `C::C() {}`
29 /// `C::~C(void) {}` becomes `C::~C() {}`
30 ///
31 class RedundantVoidArgCheck : public ClangTidyCheck {
32 public:
33 RedundantVoidArgCheck(StringRef Name, ClangTidyContext *Context)
34 : ClangTidyCheck(Name, Context) {}
35
36 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
37
38 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
39
40 private:
41 void processFunctionDecl(const ast_matchers::MatchFinder::MatchResult &Result,
42 const FunctionDecl *Function);
43
44 void
45 processTypedefNameDecl(const ast_matchers::MatchFinder::MatchResult &Result,
46 const TypedefNameDecl *Typedef);
47
48 void processFieldDecl(const ast_matchers::MatchFinder::MatchResult &Result,
49 const FieldDecl *Member);
50
51 void processVarDecl(const ast_matchers::MatchFinder::MatchResult &Result,
52 const VarDecl *Var);
53
54 void
55 processNamedCastExpr(const ast_matchers::MatchFinder::MatchResult &Result,
56 const CXXNamedCastExpr *NamedCast);
57
58 void
59 processExplicitCastExpr(const ast_matchers::MatchFinder::MatchResult &Result,
60 const ExplicitCastExpr *ExplicitCast);
61
62 void processLambdaExpr(const ast_matchers::MatchFinder::MatchResult &Result,
63 const LambdaExpr *Lambda);
64
65 void
66 removeVoidArgumentTokens(const ast_matchers::MatchFinder::MatchResult &Result,
67 SourceRange Range, StringRef GrammarLocation);
68
69 void removeVoidToken(Token VoidToken, StringRef Diagnostic);
70 };
71
72 } // namespace modernize
73 } // namespace tidy
74 } // namespace clang
75
76 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REDUNDANT_VOID_ARG_CHECK_H
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:47
clang::tidy::modernize::RedundantVoidArgCheck::RedundantVoidArgCheck
RedundantVoidArgCheck(StringRef Name, ClangTidyContext *Context)
Definition: RedundantVoidArgCheck.h:33
clang::tidy::modernize::RedundantVoidArgCheck
Find and remove redundant void argument lists.
Definition: RedundantVoidArgCheck.h:31
clang::tidy::modernize::RedundantVoidArgCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: RedundantVoidArgCheck.cpp:46
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:27
clang::tidy::modernize::RedundantVoidArgCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: RedundantVoidArgCheck.cpp:76
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
Range
CharSourceRange Range
SourceRange for the file name.
Definition: IncludeOrderCheck.cpp:38
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:77