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