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 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(ASTContext &Context, QualType T) {
365 if (T->isIncompleteArrayType())
366 return true;
367
368 while (const ConstantArrayType *ArrayT = Context.getAsConstantArrayType(T)) {
369 if (!ArrayT->getSize())
370 return true;
371
372 T = ArrayT->getElementType();
373 }
374
375 return false;
376}
377
378static bool isEmpty(ASTContext &Context, const QualType &Type) {
379 if (const CXXRecordDecl *ClassDecl = Type->getAsCXXRecordDecl()) {
380 return ClassDecl->isEmpty();
381 }
382 return isIncompleteOrZeroLengthArrayType(Context, Type);
383}
384
385static llvm::StringLiteral getInitializer(QualType QT, bool UseAssignment) {
386 static constexpr llvm::StringLiteral DefaultInitializer = "{}";
387 if (!UseAssignment)
388 return DefaultInitializer;
389
390 if (QT->isPointerType())
391 return " = nullptr";
392
393 const auto *BT = dyn_cast<BuiltinType>(QT.getCanonicalType().getTypePtr());
394 if (!BT)
395 return DefaultInitializer;
396
397 switch (BT->getKind()) {
398 case BuiltinType::Bool:
399 return " = false";
400 case BuiltinType::Float:
401 return " = 0.0F";
402 case BuiltinType::Double:
403 return " = 0.0";
404 case BuiltinType::LongDouble:
405 return " = 0.0L";
406 case BuiltinType::SChar:
407 case BuiltinType::Char_S:
408 case BuiltinType::WChar_S:
409 case BuiltinType::Char16:
410 case BuiltinType::Char32:
411 case BuiltinType::Short:
412 case BuiltinType::Int:
413 return " = 0";
414 case BuiltinType::UChar:
415 case BuiltinType::Char_U:
416 case BuiltinType::WChar_U:
417 case BuiltinType::UShort:
418 case BuiltinType::UInt:
419 return " = 0U";
420 case BuiltinType::Long:
421 return " = 0L";
422 case BuiltinType::ULong:
423 return " = 0UL";
424 case BuiltinType::LongLong:
425 return " = 0LL";
426 case BuiltinType::ULongLong:
427 return " = 0ULL";
428
429 default:
430 return DefaultInitializer;
431 }
432}
433
434void ProTypeMemberInitCheck::checkMissingMemberInitializer(
435 ASTContext &Context, const CXXRecordDecl &ClassDecl,
436 const CXXConstructorDecl *Ctor) {
437 bool IsUnion = ClassDecl.isUnion();
438
439 if (IsUnion && ClassDecl.hasInClassInitializer())
440 return;
441
442 // Gather all fields (direct and indirect) that need to be initialized.
443 SmallPtrSet<const FieldDecl *, 16> FieldsToInit;
444 bool AnyMemberHasInitPerUnion = false;
446 ClassDecl, ClassDecl.fields(), AnyMemberHasInitPerUnion,
447 [&](const FieldDecl *F) {
448 if (IgnoreArrays && F->getType()->isArrayType())
449 return;
450 if (F->hasInClassInitializer() && F->getParent()->isUnion()) {
451 AnyMemberHasInitPerUnion = true;
452 removeFieldInitialized(F, FieldsToInit);
453 }
454 if (!F->hasInClassInitializer() &&
456 Context) &&
457 !isEmpty(Context, F->getType()) && !F->isUnnamedBitField() &&
458 !AnyMemberHasInitPerUnion)
459 FieldsToInit.insert(F);
460 });
461 if (FieldsToInit.empty())
462 return;
463
464 if (Ctor) {
465 for (const CXXCtorInitializer *Init : Ctor->inits()) {
466 // Remove any fields that were explicitly written in the initializer list
467 // or in-class.
468 if (Init->isAnyMemberInitializer() && Init->isWritten()) {
469 if (IsUnion)
470 return; // We can only initialize one member of a union.
471 removeFieldInitialized(Init->getAnyMember(), FieldsToInit);
472 }
473 }
474 removeFieldsInitializedInBody(*Ctor->getBody(), Context, FieldsToInit);
475 }
476
477 // Collect all fields in order, both direct fields and indirect fields from
478 // anonymous record types.
479 SmallVector<const FieldDecl *, 16> OrderedFields;
480 forEachField(ClassDecl, ClassDecl.fields(),
481 [&](const FieldDecl *F) { OrderedFields.push_back(F); });
482
483 // Collect all the fields we need to initialize, including indirect fields.
484 // It only includes fields that have not been fixed
485 SmallPtrSet<const FieldDecl *, 16> AllFieldsToInit;
486 forEachField(ClassDecl, FieldsToInit, [&](const FieldDecl *F) {
487 if (HasRecordClassMemberSet.insert(F).second)
488 AllFieldsToInit.insert(F);
489 });
490 if (FieldsToInit.empty())
491 return;
492
493 DiagnosticBuilder Diag =
494 diag(Ctor ? Ctor->getBeginLoc() : ClassDecl.getLocation(),
495 "%select{|union }0constructor %select{does not|should}0 initialize "
496 "%select{|one of }0these fields: %1")
497 << IsUnion << toCommaSeparatedString(OrderedFields, FieldsToInit);
498
499 if (AllFieldsToInit.empty())
500 return;
501
502 // Do not propose fixes for constructors in macros since we cannot place them
503 // correctly.
504 if (Ctor && Ctor->getBeginLoc().isMacroID())
505 return;
506
507 // Collect all fields but only suggest a fix for the first member of unions,
508 // as initializing more than one union member is an error.
509 SmallPtrSet<const FieldDecl *, 16> FieldsToFix;
510 AnyMemberHasInitPerUnion = false;
511 forEachFieldWithFilter(ClassDecl, ClassDecl.fields(),
512 AnyMemberHasInitPerUnion, [&](const FieldDecl *F) {
513 if (!FieldsToInit.contains(F))
514 return;
515 // Don't suggest fixes for enums because we don't
516 // know a good default. Don't suggest fixes for
517 // bitfields because in-class initialization is not
518 // possible until C++20.
519 if (F->getType()->isEnumeralType() ||
520 (!getLangOpts().CPlusPlus20 && F->isBitField()))
521 return;
522 FieldsToFix.insert(F);
523 AnyMemberHasInitPerUnion = true;
524 });
525 if (FieldsToFix.empty())
526 return;
527
528 // Use in-class initialization if possible.
529 if (Context.getLangOpts().CPlusPlus11) {
530 for (const FieldDecl *Field : FieldsToFix) {
531 Diag << FixItHint::CreateInsertion(
532 getLocationForEndOfToken(Context, Field->getSourceRange().getEnd()),
533 getInitializer(Field->getType(), UseAssignment));
534 }
535 } else if (Ctor) {
536 // Otherwise, rewrite the constructor's initializer list.
537 fixInitializerList(Context, Diag, Ctor, FieldsToFix);
538 }
539}
540
541void ProTypeMemberInitCheck::checkMissingBaseClassInitializer(
542 const ASTContext &Context, const CXXRecordDecl &ClassDecl,
543 const CXXConstructorDecl *Ctor) {
544
545 // Gather any base classes that need to be initialized.
546 SmallVector<const RecordDecl *, 4> AllBases;
547 SmallPtrSet<const RecordDecl *, 4> BasesToInit;
548 for (const CXXBaseSpecifier &Base : ClassDecl.bases()) {
549 if (const auto *BaseClassDecl = getCanonicalRecordDecl(Base.getType())) {
550 AllBases.emplace_back(BaseClassDecl);
551 if (!BaseClassDecl->field_empty() &&
553 Context))
554 BasesToInit.insert(BaseClassDecl);
555 }
556 }
557
558 if (BasesToInit.empty())
559 return;
560
561 // Remove any bases that were explicitly written in the initializer list.
562 if (Ctor) {
563 if (Ctor->isImplicit())
564 return;
565
566 for (const CXXCtorInitializer *Init : Ctor->inits()) {
567 if (Init->isBaseInitializer() && Init->isWritten())
568 BasesToInit.erase(Init->getBaseClass()->getAsCXXRecordDecl());
569 }
570 }
571
572 if (BasesToInit.empty())
573 return;
574
575 DiagnosticBuilder Diag =
576 diag(Ctor ? Ctor->getBeginLoc() : ClassDecl.getLocation(),
577 "constructor does not initialize these bases: %0")
578 << toCommaSeparatedString(AllBases, BasesToInit);
579
580 if (Ctor)
581 fixInitializerList(Context, Diag, Ctor, BasesToInit);
582}
583
584void ProTypeMemberInitCheck::checkUninitializedTrivialType(
585 const ASTContext &Context, const VarDecl *Var) {
586 DiagnosticBuilder Diag =
587 diag(Var->getBeginLoc(), "uninitialized record type: %0") << Var;
588
589 Diag << FixItHint::CreateInsertion(
590 getLocationForEndOfToken(Context, Var->getSourceRange().getEnd()),
591 Context.getLangOpts().CPlusPlus11 ? "{}" : " = {}");
592}
593
594} // 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
static bool isIncompleteOrZeroLengthArrayType(ASTContext &Context, QualType T)
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 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 isEmpty(ASTContext &Context, const QualType &Type)
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)
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