clang-tools
11.0.0
clang-tools-extra
clang-tidy
cppcoreguidelines
ProTypeMemberInitCheck.h
Go to the documentation of this file.
1
//===--- ProTypeMemberInitCheck.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_CPPCOREGUIDELINES_PRO_TYPE_MEMBER_INIT_H
10
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_MEMBER_INIT_H
11
12
#include "../ClangTidyCheck.h"
13
14
namespace
clang
{
15
namespace
tidy {
16
namespace
cppcoreguidelines {
17
18
/// Implements C++ Core Guidelines Type.6.
19
///
20
/// Checks that every user-provided constructor value-initializes all class
21
/// members and base classes that would have undefined behavior otherwise. Also
22
/// check that any record types without user-provided default constructors are
23
/// value-initialized where used.
24
///
25
/// Members initialized through function calls in the body of the constructor
26
/// will result in false positives.
27
///
28
/// For the user-facing documentation see:
29
/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.html
30
/// TODO: See if 'fixes' for false positives are optimized away by the compiler.
31
/// TODO: For classes with multiple constructors, make sure that we don't offer
32
/// multiple in-class initializer fixits for the same member.
33
class
ProTypeMemberInitCheck
:
public
ClangTidyCheck
{
34
public
:
35
ProTypeMemberInitCheck
(StringRef
Name
,
ClangTidyContext
*Context);
36
bool
isLanguageVersionSupported
(
const
LangOptions &LangOpts)
const override
{
37
return
LangOpts.CPlusPlus;
38
}
39
void
registerMatchers
(ast_matchers::MatchFinder *Finder)
override
;
40
void
check
(
const
ast_matchers::MatchFinder::MatchResult &Result)
override
;
41
void
storeOptions
(
ClangTidyOptions::OptionMap
&Opts)
override
;
42
43
private
:
44
// Checks Type.6 part 1:
45
// Issue a diagnostic for any constructor of a non-trivially-constructible
46
// type that does not initialize all member variables.
47
//
48
// To fix: Write a data member initializer, or mention it in the member
49
// initializer list.
50
void
checkMissingMemberInitializer(ASTContext &Context,
51
const
CXXRecordDecl &ClassDecl,
52
const
CXXConstructorDecl *Ctor);
53
54
// A subtle side effect of Type.6 part 2:
55
// Make sure to initialize trivially constructible base classes.
56
void
checkMissingBaseClassInitializer(
const
ASTContext &Context,
57
const
CXXRecordDecl &ClassDecl,
58
const
CXXConstructorDecl *Ctor);
59
60
// Checks Type.6 part 2:
61
// Issue a diagnostic when constructing an object of a trivially constructible
62
// type without () or {} to initialize its members.
63
//
64
// To fix: Add () or {}.
65
void
checkUninitializedTrivialType(
const
ASTContext &Context,
66
const
VarDecl *Var);
67
68
// Whether arrays need to be initialized or not. Default is false.
69
bool
IgnoreArrays;
70
71
// Whether fix-its for initialization of fundamental type use assignment
72
// instead of brace initialization. Only effective in C++11 mode. Default is
73
// false.
74
bool
UseAssignment;
75
};
76
77
}
// namespace cppcoreguidelines
78
}
// namespace tidy
79
}
// namespace clang
80
81
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_PRO_TYPE_MEMBER_INIT_H
clang::tidy::cppcoreguidelines::ProTypeMemberInitCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
Definition:
ProTypeMemberInitCheck.cpp:313
clang::tidy::cppcoreguidelines::ProTypeMemberInitCheck::ProTypeMemberInitCheck
ProTypeMemberInitCheck(StringRef Name, ClangTidyContext *Context)
Definition:
ProTypeMemberInitCheck.cpp:250
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition:
ClangTidyCheck.h:114
clang::tidy::cppcoreguidelines::ProTypeMemberInitCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition:
ProTypeMemberInitCheck.cpp:295
clang::tidy::cppcoreguidelines::ProTypeMemberInitCheck
Implements C++ Core Guidelines Type.6.
Definition:
ProTypeMemberInitCheck.h:33
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition:
ClangTidyDiagnosticConsumer.h:76
Name
static constexpr llvm::StringLiteral Name
Definition:
UppercaseLiteralSuffixCheck.cpp:27
clang::tidy::cppcoreguidelines::ProTypeMemberInitCheck::isLanguageVersionSupported
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Override this to disable registering matchers and PP callbacks if an invalid language version is bein...
Definition:
ProTypeMemberInitCheck.h:36
clang::tidy::cppcoreguidelines::ProTypeMemberInitCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition:
ProTypeMemberInitCheck.cpp:256
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition:
ApplyReplacements.h:27
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, ClangTidyValue > OptionMap
Definition:
ClangTidyOptions.h:111
Generated on Tue Jul 28 2020 16:14:03 for clang-tools by
1.8.16