clang-tools 22.0.0git
ProTypeMemberInitCheck.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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
10#include "../utils/LexerUtils.h"
11#include "../utils/Matchers.h"
12#include "../utils/TypeTraits.h"
13#include "clang/AST/ASTContext.h"
14#include "clang/ASTMatchers/ASTMatchFinder.h"
15#include "clang/Lex/Lexer.h"
16#include "llvm/ADT/SmallPtrSet.h"
17
18using namespace clang::ast_matchers;
19using namespace clang::tidy::matchers;
20using llvm::SmallPtrSet;
21using llvm::SmallPtrSetImpl;
22
24
25namespace {
26
27AST_MATCHER(CXXRecordDecl, hasDefaultConstructor) {
28 return Node.hasDefaultConstructor();
29}
30
31} // namespace
32
33// Iterate over all the fields in a record type, both direct and indirect (e.g.
34// if the record contains an anonymous struct).
35template <typename T, typename Func>
36static void forEachField(const RecordDecl &Record, const T &Fields,
37 const Func &Fn) {
38 for (const FieldDecl *F : Fields) {
39 if (F->isAnonymousStructOrUnion()) {
40 if (const CXXRecordDecl *R = F->getType()->getAsCXXRecordDecl())
41 forEachField(*R, R->fields(), Fn);
42 } else {
43 Fn(F);
44 }
45 }
46}
47
48template <typename T, typename Func>
49static void forEachFieldWithFilter(const RecordDecl &Record, const T &Fields,
50 bool &AnyMemberHasInitPerUnion,
51 const Func &Fn) {
52 for (const FieldDecl *F : Fields) {
53 if (F->isAnonymousStructOrUnion()) {
54 if (const CXXRecordDecl *R = F->getType()->getAsCXXRecordDecl()) {
55 AnyMemberHasInitPerUnion = false;
56 forEachFieldWithFilter(*R, R->fields(), AnyMemberHasInitPerUnion, Fn);
57 }
58 } else {
59 Fn(F);
60 }
61 if (Record.isUnion() && AnyMemberHasInitPerUnion)
62 break;
63 }
64}
65
66static void
67removeFieldInitialized(const FieldDecl *M,
68 SmallPtrSetImpl<const FieldDecl *> &FieldDecls) {
69 const RecordDecl *R = M->getParent();
70 if (R && R->isUnion()) {
71 // Erase all members in a union if any member of it is initialized.
72 for (const auto *F : R->fields())
73 FieldDecls.erase(F);
74 } else
75 FieldDecls.erase(M);
76}
77
78static void
79removeFieldsInitializedInBody(const Stmt &Stmt, ASTContext &Context,
80 SmallPtrSetImpl<const FieldDecl *> &FieldDecls) {
81 auto Matches =
82 match(findAll(binaryOperator(
83 hasOperatorName("="),
84 hasLHS(memberExpr(member(fieldDecl().bind("fieldDecl")))))),
85 Stmt, Context);
86 for (const auto &Match : Matches)
87 removeFieldInitialized(Match.getNodeAs<FieldDecl>("fieldDecl"), FieldDecls);
88}
89
90static StringRef getName(const FieldDecl *Field) { return Field->getName(); }
91
92static StringRef getName(const RecordDecl *Record) {
93 // Get the typedef name if this is a C-style anonymous struct and typedef.
94 if (const TypedefNameDecl *Typedef = Record->getTypedefNameForAnonDecl())
95 return Typedef->getName();
96 return Record->getName();
97}
98
99// Creates comma separated list of decls requiring initialization in order of
100// declaration.
101template <typename R, typename T>
102static std::string
103toCommaSeparatedString(const R &OrderedDecls,
104 const SmallPtrSetImpl<const T *> &DeclsToInit) {
105 SmallVector<StringRef, 16> Names;
106 for (const T *Decl : OrderedDecls) {
107 if (DeclsToInit.contains(Decl))
108 Names.emplace_back(getName(Decl));
109 }
110 return llvm::join(Names.begin(), Names.end(), ", ");
111}
112
113static SourceLocation getLocationForEndOfToken(const ASTContext &Context,
114 SourceLocation Location) {
115 return Lexer::getLocForEndOfToken(Location, 0, Context.getSourceManager(),
116 Context.getLangOpts());
117}
118
119namespace {
120
121// There are 3 kinds of insertion placements:
122enum class InitializerPlacement {
123 // 1. The fields are inserted after an existing CXXCtorInitializer stored in
124 // Where. This will be the case whenever there is a written initializer before
125 // the fields available.
126 After,
127
128 // 2. The fields are inserted before the first existing initializer stored in
129 // Where.
130 Before,
131
132 // 3. There are no written initializers and the fields will be inserted before
133 // the constructor's body creating a new initializer list including the ':'.
134 New
135};
136
137// An InitializerInsertion contains a list of fields and/or base classes to
138// insert into the initializer list of a constructor. We use this to ensure
139// proper absolute ordering according to the class declaration relative to the
140// (perhaps improper) ordering in the existing initializer list, if any.
141struct InitializerInsertion {
142 InitializerInsertion(InitializerPlacement Placement,
143 const CXXCtorInitializer *Where)
144 : Placement(Placement), Where(Where) {}
145
146 SourceLocation getLocation(const ASTContext &Context,
147 const CXXConstructorDecl &Constructor) const {
148 assert((Where != nullptr || Placement == InitializerPlacement::New) &&
149 "Location should be relative to an existing initializer or this "
150 "insertion represents a new initializer list.");
151 SourceLocation Location;
152 switch (Placement) {
153 case InitializerPlacement::New:
155 Constructor.getBody()->getBeginLoc(),
156 Context.getSourceManager(), Context.getLangOpts())
157 .getLocation();
158 break;
159 case InitializerPlacement::Before:
161 Where->getSourceRange().getBegin(),
162 Context.getSourceManager(), Context.getLangOpts())
163 .getLocation();
164 break;
165 case InitializerPlacement::After:
166 Location = Where->getRParenLoc();
167 break;
168 }
169 return getLocationForEndOfToken(Context, Location);
170 }
171
172 std::string codeToInsert() const {
173 assert(!Initializers.empty() && "No initializers to insert");
174 std::string Code;
175 llvm::raw_string_ostream Stream(Code);
176 const std::string Joined =
177 llvm::join(Initializers.begin(), Initializers.end(), "(), ");
178 switch (Placement) {
179 case InitializerPlacement::New:
180 Stream << " : " << Joined << "()";
181 break;
182 case InitializerPlacement::Before:
183 Stream << " " << Joined << "(),";
184 break;
185 case InitializerPlacement::After:
186 Stream << ", " << Joined << "()";
187 break;
188 }
189 return Stream.str();
190 }
191
192 InitializerPlacement Placement;
193 const CXXCtorInitializer *Where;
194 SmallVector<std::string, 4> Initializers;
195};
196
197} // namespace
198
199// Convenience utility to get a RecordDecl from a QualType.
200static const RecordDecl *getCanonicalRecordDecl(const QualType &Type) {
201 if (const auto *RT = Type->getAsCanonical<RecordType>())
202 return RT->getDecl();
203 return nullptr;
204}
205
206template <typename R, typename T>
207static SmallVector<InitializerInsertion, 16>
208computeInsertions(const CXXConstructorDecl::init_const_range &Inits,
209 const R &OrderedDecls,
210 const SmallPtrSetImpl<const T *> &DeclsToInit) {
211 SmallVector<InitializerInsertion, 16> Insertions;
212 Insertions.emplace_back(InitializerPlacement::New, nullptr);
213
214 typename R::const_iterator Decl = std::begin(OrderedDecls);
215 for (const CXXCtorInitializer *Init : Inits) {
216 if (Init->isWritten()) {
217 if (Insertions.size() == 1)
218 Insertions.emplace_back(InitializerPlacement::Before, Init);
219
220 // Gets either the field or base class being initialized by the provided
221 // initializer.
222 const auto *InitDecl =
223 Init->isAnyMemberInitializer()
224 ? static_cast<const NamedDecl *>(Init->getAnyMember())
225 : Init->getBaseClass()->getAsCXXRecordDecl();
226
227 // Add all fields between current field up until the next initializer.
228 for (; Decl != std::end(OrderedDecls) && *Decl != InitDecl; ++Decl) {
229 if (const auto *D = dyn_cast<T>(*Decl)) {
230 if (DeclsToInit.contains(D))
231 Insertions.back().Initializers.emplace_back(getName(D));
232 }
233 }
234
235 Insertions.emplace_back(InitializerPlacement::After, Init);
236 }
237 }
238
239 // Add remaining decls that require initialization.
240 for (; Decl != std::end(OrderedDecls); ++Decl) {
241 if (const auto *D = dyn_cast<T>(*Decl)) {
242 if (DeclsToInit.contains(D))
243 Insertions.back().Initializers.emplace_back(getName(D));
244 }
245 }
246 return Insertions;
247}
248
249// Gets the list of bases and members that could possibly be initialized, in
250// order as they appear in the class declaration.
251static void
252getInitializationsInOrder(const CXXRecordDecl &ClassDecl,
253 SmallVectorImpl<const NamedDecl *> &Decls) {
254 Decls.clear();
255 for (const auto &Base : ClassDecl.bases()) {
256 // Decl may be null if the base class is a template parameter.
257 if (const NamedDecl *Decl = getCanonicalRecordDecl(Base.getType())) {
258 Decls.emplace_back(Decl);
259 }
260 }
261 forEachField(ClassDecl, ClassDecl.fields(),
262 [&](const FieldDecl *F) { Decls.push_back(F); });
263}
264
265template <typename T>
266static void fixInitializerList(const ASTContext &Context,
267 DiagnosticBuilder &Diag,
268 const CXXConstructorDecl *Ctor,
269 const SmallPtrSetImpl<const T *> &DeclsToInit) {
270 // Do not propose fixes in macros since we cannot place them correctly.
271 if (Ctor->getBeginLoc().isMacroID())
272 return;
273
274 SmallVector<const NamedDecl *, 16> OrderedDecls;
275 getInitializationsInOrder(*Ctor->getParent(), OrderedDecls);
276
277 for (const auto &Insertion :
278 computeInsertions(Ctor->inits(), OrderedDecls, DeclsToInit)) {
279 if (!Insertion.Initializers.empty())
280 Diag << FixItHint::CreateInsertion(Insertion.getLocation(Context, *Ctor),
281 Insertion.codeToInsert());
282 }
283}
284
286 ClangTidyContext *Context)
287 : ClangTidyCheck(Name, Context),
288 IgnoreArrays(Options.get("IgnoreArrays", false)),
289 UseAssignment(Options.get("UseAssignment", false)) {}
290
292 auto IsUserProvidedNonDelegatingConstructor =
293 allOf(isUserProvided(), unless(isInstantiated()),
294 unless(isDelegatingConstructor()),
295 ofClass(cxxRecordDecl().bind("parent")),
296 unless(hasAnyConstructorInitializer(cxxCtorInitializer(
297 isWritten(), unless(isMemberInitializer()),
298 hasTypeLoc(loc(
299 qualType(hasDeclaration(equalsBoundNode("parent")))))))));
300
301 auto IsNonTrivialDefaultConstructor = allOf(
302 isDefaultConstructor(), unless(isUserProvided()),
303 hasParent(cxxRecordDecl(unless(isTriviallyDefaultConstructible()))));
304 Finder->addMatcher(
305 cxxConstructorDecl(isDefinition(),
306 anyOf(IsUserProvidedNonDelegatingConstructor,
307 IsNonTrivialDefaultConstructor))
308 .bind("ctor"),
309 this);
310
311 // Match classes with a default constructor that is defaulted or is not in the
312 // AST.
313 Finder->addMatcher(
314 cxxRecordDecl(
315 isDefinition(), unless(isInstantiated()), hasDefaultConstructor(),
316 anyOf(has(cxxConstructorDecl(isDefaultConstructor(), isDefaulted(),
317 unless(isImplicit()))),
318 unless(has(cxxConstructorDecl()))),
319 unless(isTriviallyDefaultConstructible()))
320 .bind("record"),
321 this);
322
323 auto HasDefaultConstructor = hasInitializer(
324 cxxConstructExpr(unless(requiresZeroInitialization()),
325 hasDeclaration(cxxConstructorDecl(
326 isDefaultConstructor(), unless(isUserProvided())))));
327 Finder->addMatcher(
328 varDecl(isDefinition(), HasDefaultConstructor,
329 hasAutomaticStorageDuration(),
330 hasType(recordDecl(has(fieldDecl()),
331 isTriviallyDefaultConstructible())))
332 .bind("var"),
333 this);
334}
335
336void ProTypeMemberInitCheck::check(const MatchFinder::MatchResult &Result) {
337 if (const auto *Ctor = Result.Nodes.getNodeAs<CXXConstructorDecl>("ctor")) {
338 // Skip declarations delayed by late template parsing without a body.
339 if (!Ctor->getBody())
340 return;
341 // Skip out-of-band explicitly defaulted special member functions
342 // (except the default constructor).
343 if (Ctor->isExplicitlyDefaulted() && !Ctor->isDefaultConstructor())
344 return;
345 checkMissingMemberInitializer(*Result.Context, *Ctor->getParent(), Ctor);
346 checkMissingBaseClassInitializer(*Result.Context, *Ctor->getParent(), Ctor);
347 } else if (const auto *Record =
348 Result.Nodes.getNodeAs<CXXRecordDecl>("record")) {
349 assert(Record->hasDefaultConstructor() &&
350 "Matched record should have a default constructor");
351 checkMissingMemberInitializer(*Result.Context, *Record, nullptr);
352 checkMissingBaseClassInitializer(*Result.Context, *Record, nullptr);
353 } else if (const auto *Var = Result.Nodes.getNodeAs<VarDecl>("var")) {
354 checkUninitializedTrivialType(*Result.Context, Var);
355 }
356}
357
359 Options.store(Opts, "IgnoreArrays", IgnoreArrays);
360 Options.store(Opts, "UseAssignment", UseAssignment);
361}
362
363// FIXME: Copied from clang/lib/Sema/SemaDeclCXX.cpp.
364static bool isIncompleteOrZeroLengthArrayType(const ASTContext &Context,
365 QualType T) {
366 if (T->isIncompleteArrayType())
367 return true;
368
369 while (const ConstantArrayType *ArrayT = Context.getAsConstantArrayType(T)) {
370 if (!ArrayT->getSize())
371 return true;
372
373 T = ArrayT->getElementType();
374 }
375
376 return false;
377}
378
379static bool isEmpty(const ASTContext &Context, const QualType &Type) {
380 if (const CXXRecordDecl *ClassDecl = Type->getAsCXXRecordDecl()) {
381 return ClassDecl->isEmpty();
382 }
383 return isIncompleteOrZeroLengthArrayType(Context, Type);
384}
385
386static llvm::StringLiteral getInitializer(QualType QT, bool UseAssignment) {
387 static constexpr llvm::StringLiteral DefaultInitializer = "{}";
388 if (!UseAssignment)
389 return DefaultInitializer;
390
391 if (QT->isPointerType())
392 return " = nullptr";
393
394 const auto *BT = dyn_cast<BuiltinType>(QT.getCanonicalType().getTypePtr());
395 if (!BT)
396 return DefaultInitializer;
397
398 switch (BT->getKind()) {
399 case BuiltinType::Bool:
400 return " = false";
401 case BuiltinType::Float:
402 return " = 0.0F";
403 case BuiltinType::Double:
404 return " = 0.0";
405 case BuiltinType::LongDouble:
406 return " = 0.0L";
407 case BuiltinType::SChar:
408 case BuiltinType::Char_S:
409 case BuiltinType::WChar_S:
410 case BuiltinType::Char16:
411 case BuiltinType::Char32:
412 case BuiltinType::Short:
413 case BuiltinType::Int:
414 return " = 0";
415 case BuiltinType::UChar:
416 case BuiltinType::Char_U:
417 case BuiltinType::WChar_U:
418 case BuiltinType::UShort:
419 case BuiltinType::UInt:
420 return " = 0U";
421 case BuiltinType::Long:
422 return " = 0L";
423 case BuiltinType::ULong:
424 return " = 0UL";
425 case BuiltinType::LongLong:
426 return " = 0LL";
427 case BuiltinType::ULongLong:
428 return " = 0ULL";
429
430 default:
431 return DefaultInitializer;
432 }
433}
434
435static void
436computeFieldsToInit(const ASTContext &Context, const RecordDecl &Record,
437 bool IgnoreArrays,
438 SmallPtrSetImpl<const FieldDecl *> &FieldsToInit) {
439 bool AnyMemberHasInitPerUnion = false;
441 Record, Record.fields(), AnyMemberHasInitPerUnion,
442 [&](const FieldDecl *F) {
443 if (IgnoreArrays && F->getType()->isArrayType())
444 return;
445 if (F->hasInClassInitializer() && F->getParent()->isUnion()) {
446 AnyMemberHasInitPerUnion = true;
447 removeFieldInitialized(F, FieldsToInit);
448 }
449 if (!F->hasInClassInitializer() &&
451 Context) &&
452 !isEmpty(Context, F->getType()) && !F->isUnnamedBitField() &&
453 !AnyMemberHasInitPerUnion)
454 FieldsToInit.insert(F);
455 });
456}
457
458void ProTypeMemberInitCheck::checkMissingMemberInitializer(
459 ASTContext &Context, const CXXRecordDecl &ClassDecl,
460 const CXXConstructorDecl *Ctor) {
461 const bool IsUnion = ClassDecl.isUnion();
462
463 if (IsUnion && ClassDecl.hasInClassInitializer())
464 return;
465
466 // Gather all fields (direct and indirect) that need to be initialized.
467 SmallPtrSet<const FieldDecl *, 16> FieldsToInit;
468 computeFieldsToInit(Context, ClassDecl, IgnoreArrays, FieldsToInit);
469 if (FieldsToInit.empty())
470 return;
471
472 if (Ctor) {
473 for (const CXXCtorInitializer *Init : Ctor->inits()) {
474 // Remove any fields that were explicitly written in the initializer list
475 // or in-class.
476 if (Init->isAnyMemberInitializer() && Init->isWritten()) {
477 if (IsUnion)
478 return; // We can only initialize one member of a union.
479 removeFieldInitialized(Init->getAnyMember(), FieldsToInit);
480 }
481 }
482 removeFieldsInitializedInBody(*Ctor->getBody(), Context, FieldsToInit);
483 }
484
485 // Collect all fields in order, both direct fields and indirect fields from
486 // anonymous record types.
487 SmallVector<const FieldDecl *, 16> OrderedFields;
488 forEachField(ClassDecl, ClassDecl.fields(),
489 [&](const FieldDecl *F) { OrderedFields.push_back(F); });
490
491 // Collect all the fields we need to initialize, including indirect fields.
492 // It only includes fields that have not been fixed
493 SmallPtrSet<const FieldDecl *, 16> AllFieldsToInit;
494 forEachField(ClassDecl, FieldsToInit, [&](const FieldDecl *F) {
495 if (HasRecordClassMemberSet.insert(F).second)
496 AllFieldsToInit.insert(F);
497 });
498 if (FieldsToInit.empty())
499 return;
500
501 DiagnosticBuilder Diag =
502 diag(Ctor ? Ctor->getBeginLoc() : ClassDecl.getLocation(),
503 "%select{|union }0constructor %select{does not|should}0 initialize "
504 "%select{|one of }0these fields: %1")
505 << IsUnion << toCommaSeparatedString(OrderedFields, FieldsToInit);
506
507 if (AllFieldsToInit.empty())
508 return;
509
510 // Do not propose fixes for constructors in macros since we cannot place them
511 // correctly.
512 if (Ctor && Ctor->getBeginLoc().isMacroID())
513 return;
514
515 // Collect all fields but only suggest a fix for the first member of unions,
516 // as initializing more than one union member is an error.
517 SmallPtrSet<const FieldDecl *, 16> FieldsToFix;
518 bool AnyMemberHasInitPerUnion = false;
519 forEachFieldWithFilter(ClassDecl, ClassDecl.fields(),
520 AnyMemberHasInitPerUnion, [&](const FieldDecl *F) {
521 if (!FieldsToInit.contains(F))
522 return;
523 // Don't suggest fixes for enums because we don't
524 // know a good default. Don't suggest fixes for
525 // bitfields because in-class initialization is not
526 // possible until C++20.
527 if (F->getType()->isEnumeralType() ||
528 (!getLangOpts().CPlusPlus20 && F->isBitField()))
529 return;
530 FieldsToFix.insert(F);
531 AnyMemberHasInitPerUnion = true;
532 });
533 if (FieldsToFix.empty())
534 return;
535
536 // Use in-class initialization if possible.
537 if (Context.getLangOpts().CPlusPlus11) {
538 for (const FieldDecl *Field : FieldsToFix) {
539 Diag << FixItHint::CreateInsertion(
540 getLocationForEndOfToken(Context, Field->getSourceRange().getEnd()),
541 getInitializer(Field->getType(), UseAssignment));
542 }
543 } else if (Ctor) {
544 // Otherwise, rewrite the constructor's initializer list.
545 fixInitializerList(Context, Diag, Ctor, FieldsToFix);
546 }
547}
548
549void ProTypeMemberInitCheck::checkMissingBaseClassInitializer(
550 const ASTContext &Context, const CXXRecordDecl &ClassDecl,
551 const CXXConstructorDecl *Ctor) {
552 // Gather any base classes that need to be initialized.
553 SmallVector<const RecordDecl *, 4> AllBases;
554 SmallPtrSet<const RecordDecl *, 4> BasesToInit;
555 for (const CXXBaseSpecifier &Base : ClassDecl.bases()) {
556 if (const auto *BaseClassDecl = getCanonicalRecordDecl(Base.getType())) {
557 AllBases.emplace_back(BaseClassDecl);
558 if (!BaseClassDecl->field_empty() &&
560 Context))
561 BasesToInit.insert(BaseClassDecl);
562 }
563 }
564
565 if (BasesToInit.empty())
566 return;
567
568 // Remove any bases that were explicitly written in the initializer list.
569 if (Ctor) {
570 if (Ctor->isImplicit())
571 return;
572
573 for (const CXXCtorInitializer *Init : Ctor->inits()) {
574 if (Init->isBaseInitializer() && Init->isWritten())
575 BasesToInit.erase(Init->getBaseClass()->getAsCXXRecordDecl());
576 }
577 }
578
579 if (BasesToInit.empty())
580 return;
581
582 DiagnosticBuilder Diag =
583 diag(Ctor ? Ctor->getBeginLoc() : ClassDecl.getLocation(),
584 "constructor does not initialize these bases: %0")
585 << toCommaSeparatedString(AllBases, BasesToInit);
586
587 if (Ctor)
588 fixInitializerList(Context, Diag, Ctor, BasesToInit);
589}
590
591void ProTypeMemberInitCheck::checkUninitializedTrivialType(
592 const ASTContext &Context, const VarDecl *Var) {
593 // Verify that the record actually needs initialization
594 const CXXRecordDecl *Record = Var->getType()->getAsCXXRecordDecl();
595 if (!Record)
596 return;
597
598 SmallPtrSet<const FieldDecl *, 16> FieldsToInit;
599 computeFieldsToInit(Context, *Record, IgnoreArrays, FieldsToInit);
600
601 if (FieldsToInit.empty())
602 return;
603
604 const DiagnosticBuilder Diag =
605 diag(Var->getBeginLoc(), "uninitialized record type: %0") << Var;
606
607 Diag << FixItHint::CreateInsertion(
608 getLocationForEndOfToken(Context, Var->getSourceRange().getEnd()),
609 Context.getLangOpts().CPlusPlus11 ? "{}" : " = {}");
610}
611
612} // namespace clang::tidy::cppcoreguidelines
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
ProTypeMemberInitCheck(StringRef Name, ClangTidyContext *Context)
void registerMatchers(ast_matchers::MatchFinder *Finder) override
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
llvm::SmallVector< uint64_t, 1024 > Record
static SourceLocation getLocationForEndOfToken(const ASTContext &Context, SourceLocation Location)
static void removeFieldsInitializedInBody(const Stmt &Stmt, ASTContext &Context, SmallPtrSetImpl< const FieldDecl * > &FieldDecls)
static std::string toCommaSeparatedString(const R &OrderedDecls, const SmallPtrSetImpl< const T * > &DeclsToInit)
static llvm::StringLiteral getInitializer(QualType QT, bool UseAssignment)
static bool isEmpty(const ASTContext &Context, const QualType &Type)
static void removeFieldInitialized(const FieldDecl *M, SmallPtrSetImpl< const FieldDecl * > &FieldDecls)
static StringRef getName(const FieldDecl *Field)
static void fixInitializerList(const ASTContext &Context, DiagnosticBuilder &Diag, const CXXConstructorDecl *Ctor, const SmallPtrSetImpl< const T * > &DeclsToInit)
static bool isIncompleteOrZeroLengthArrayType(const ASTContext &Context, QualType T)
static void forEachFieldWithFilter(const RecordDecl &Record, const T &Fields, bool &AnyMemberHasInitPerUnion, const Func &Fn)
static void getInitializationsInOrder(const CXXRecordDecl &ClassDecl, SmallVectorImpl< const NamedDecl * > &Decls)
static const RecordDecl * getCanonicalRecordDecl(const QualType &Type)
static void forEachField(const RecordDecl &Record, const T &Fields, const Func &Fn)
static SmallVector< InitializerInsertion, 16 > computeInsertions(const CXXConstructorDecl::init_const_range &Inits, const R &OrderedDecls, const SmallPtrSetImpl< const T * > &DeclsToInit)
static void computeFieldsToInit(const ASTContext &Context, const RecordDecl &Record, bool IgnoreArrays, SmallPtrSetImpl< const FieldDecl * > &FieldsToInit)
AST_MATCHER(BinaryOperator, isRelationalOperator)
Token getPreviousToken(SourceLocation Location, const SourceManager &SM, const LangOptions &LangOpts, bool SkipComments)
Returns previous token or tok::unknown if not found.
bool isTriviallyDefaultConstructible(QualType Type, const ASTContext &Context)
Returns true if Type is trivially default constructible.
llvm::StringMap< ClangTidyValue > OptionMap