clang-tools 20.0.0git
DeprecatedHeadersCheck.h
Go to the documentation of this file.
1//===--- DeprecatedHeadersCheck.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_C_HEADERS_TO_CXX_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_C_HEADERS_TO_CXX_H
11
12#include "../ClangTidyCheck.h"
13
14namespace clang::tidy::modernize {
15
16/// This check replaces deprecated C library headers with their C++ STL
17/// alternatives.
18///
19/// Before:
20/// ~~~{.cpp}
21/// #include <header.h>
22/// ~~~
23///
24/// After:
25/// ~~~{.cpp}
26/// #include <cheader>
27/// ~~~
28///
29/// Example: ``<stdio.h> => <cstdio>``
30///
31/// For the user-facing documentation see:
32/// http://clang.llvm.org/extra/clang-tidy/checks/modernize/deprecated-headers.html
34public:
35 DeprecatedHeadersCheck(StringRef Name, ClangTidyContext *Context);
36 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
37 return LangOpts.CPlusPlus;
38 }
39 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
40 void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
41 Preprocessor *ModuleExpanderPP) override;
42 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
43 void onEndOfTranslationUnit() override;
44 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
45
47 std::string Replacement;
48 StringRef FileName;
49 SourceRange ReplacementRange;
50 SourceLocation DiagLoc;
51 };
52
53private:
54 std::vector<IncludeMarker> IncludesToBeProcessed;
55 bool CheckHeaderFile;
56};
57
58} // namespace clang::tidy::modernize
59
60#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_C_HEADERS_TO_CXX_H
llvm::SmallString< 256U > Name
Base class for all clang-tidy checks.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
This check replaces deprecated C library headers with their C++ STL alternatives.
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
Override this to register PPCallbacks in the preprocessor.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Override this to disable registering matchers and PP callbacks if an invalid language version is bein...
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
llvm::StringMap< ClangTidyValue > OptionMap