Coverage Report

Created: 2018-11-16 02:38

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/AST/DeclCXX.h
Line
Count
Source (jump to first uncovered line)
1
//===- DeclCXX.h - Classes for representing C++ declarations --*- C++ -*-=====//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
/// \file
11
/// Defines the C++ Decl subclasses, other than those for templates
12
/// (found in DeclTemplate.h) and friends (in DeclFriend.h).
13
//
14
//===----------------------------------------------------------------------===//
15
16
#ifndef LLVM_CLANG_AST_DECLCXX_H
17
#define LLVM_CLANG_AST_DECLCXX_H
18
19
#include "clang/AST/ASTContext.h"
20
#include "clang/AST/ASTUnresolvedSet.h"
21
#include "clang/AST/Attr.h"
22
#include "clang/AST/Decl.h"
23
#include "clang/AST/DeclBase.h"
24
#include "clang/AST/DeclarationName.h"
25
#include "clang/AST/Expr.h"
26
#include "clang/AST/ExternalASTSource.h"
27
#include "clang/AST/LambdaCapture.h"
28
#include "clang/AST/NestedNameSpecifier.h"
29
#include "clang/AST/Redeclarable.h"
30
#include "clang/AST/Stmt.h"
31
#include "clang/AST/Type.h"
32
#include "clang/AST/TypeLoc.h"
33
#include "clang/AST/UnresolvedSet.h"
34
#include "clang/Basic/LLVM.h"
35
#include "clang/Basic/Lambda.h"
36
#include "clang/Basic/LangOptions.h"
37
#include "clang/Basic/OperatorKinds.h"
38
#include "clang/Basic/SourceLocation.h"
39
#include "clang/Basic/Specifiers.h"
40
#include "llvm/ADT/ArrayRef.h"
41
#include "llvm/ADT/DenseMap.h"
42
#include "llvm/ADT/PointerIntPair.h"
43
#include "llvm/ADT/PointerUnion.h"
44
#include "llvm/ADT/STLExtras.h"
45
#include "llvm/ADT/iterator_range.h"
46
#include "llvm/Support/Casting.h"
47
#include "llvm/Support/Compiler.h"
48
#include "llvm/Support/PointerLikeTypeTraits.h"
49
#include "llvm/Support/TrailingObjects.h"
50
#include <cassert>
51
#include <cstddef>
52
#include <iterator>
53
#include <memory>
54
#include <vector>
55
56
namespace clang {
57
58
class ClassTemplateDecl;
59
class ConstructorUsingShadowDecl;
60
class CXXBasePath;
61
class CXXBasePaths;
62
class CXXConstructorDecl;
63
class CXXDestructorDecl;
64
class CXXFinalOverriderMap;
65
class CXXIndirectPrimaryBaseSet;
66
class CXXMethodDecl;
67
class DiagnosticBuilder;
68
class FriendDecl;
69
class FunctionTemplateDecl;
70
class IdentifierInfo;
71
class MemberSpecializationInfo;
72
class TemplateDecl;
73
class TemplateParameterList;
74
class UsingDecl;
75
76
/// Represents any kind of function declaration, whether it is a
77
/// concrete function or a function template.
78
class AnyFunctionDecl {
79
  NamedDecl *Function;
80
81
  AnyFunctionDecl(NamedDecl *ND) : Function(ND) {}
82
83
public:
84
  AnyFunctionDecl(FunctionDecl *FD) : Function(FD) {}
85
  AnyFunctionDecl(FunctionTemplateDecl *FTD);
86
87
  /// Implicily converts any function or function template into a
88
  /// named declaration.
89
  operator NamedDecl *() const { return Function; }
90
91
  /// Retrieve the underlying function or function template.
92
  NamedDecl *get() const { return Function; }
93
94
  static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) {
95
    return AnyFunctionDecl(ND);
96
  }
97
};
98
99
} // namespace clang
100
101
namespace llvm {
102
103
  // Provide PointerLikeTypeTraits for non-cvr pointers.
104
  template<>
105
  struct PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
106
    static void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
107
      return F.get();
108
    }
109
110
    static ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
111
      return ::clang::AnyFunctionDecl::getFromNamedDecl(
112
                                      static_cast< ::clang::NamedDecl*>(P));
113
    }
114
115
    enum { NumLowBitsAvailable = 2 };
116
  };
117
118
} // namespace llvm
119
120
namespace clang {
121
122
/// Represents an access specifier followed by colon ':'.
123
///
124
/// An objects of this class represents sugar for the syntactic occurrence
125
/// of an access specifier followed by a colon in the list of member
126
/// specifiers of a C++ class definition.
127
///
128
/// Note that they do not represent other uses of access specifiers,
129
/// such as those occurring in a list of base specifiers.
130
/// Also note that this class has nothing to do with so-called
131
/// "access declarations" (C++98 11.3 [class.access.dcl]).
132
class AccessSpecDecl : public Decl {
133
  /// The location of the ':'.
134
  SourceLocation ColonLoc;
135
136
  AccessSpecDecl(AccessSpecifier AS, DeclContext *DC,
137
                 SourceLocation ASLoc, SourceLocation ColonLoc)
138
477k
    : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) {
139
477k
    setAccess(AS);
140
477k
  }
141
142
516
  AccessSpecDecl(EmptyShell Empty) : Decl(AccessSpec, Empty) {}
143
144
  virtual void anchor();
145
146
public:
147
  /// The location of the access specifier.
148
214k
  SourceLocation getAccessSpecifierLoc() const { return getLocation(); }
149
150
  /// Sets the location of the access specifier.
151
0
  void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); }
152
153
  /// The location of the colon following the access specifier.
154
215k
  SourceLocation getColonLoc() const { return ColonLoc; }
155
156
  /// Sets the location of the colon.
157
516
  void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; }
158
159
396
  SourceRange getSourceRange() const override LLVM_READONLY {
160
396
    return SourceRange(getAccessSpecifierLoc(), getColonLoc());
161
396
  }
162
163
  static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS,
164
                                DeclContext *DC, SourceLocation ASLoc,
165
477k
                                SourceLocation ColonLoc) {
166
477k
    return new (C, DC) AccessSpecDecl(AS, DC, ASLoc, ColonLoc);
167
477k
  }
168
169
  static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
170
171
  // Implement isa/cast/dyncast/etc.
172
13.6k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
173
13.6k
  static bool classofKind(Kind K) { return K == AccessSpec; }
174
};
175
176
/// Represents a base class of a C++ class.
177
///
178
/// Each CXXBaseSpecifier represents a single, direct base class (or
179
/// struct) of a C++ class (or struct). It specifies the type of that
180
/// base class, whether it is a virtual or non-virtual base, and what
181
/// level of access (public, protected, private) is used for the
182
/// derivation. For example:
183
///
184
/// \code
185
///   class A { };
186
///   class B { };
187
///   class C : public virtual A, protected B { };
188
/// \endcode
189
///
190
/// In this code, C will have two CXXBaseSpecifiers, one for "public
191
/// virtual A" and the other for "protected B".
192
class CXXBaseSpecifier {
193
  /// The source code range that covers the full base
194
  /// specifier, including the "virtual" (if present) and access
195
  /// specifier (if present).
196
  SourceRange Range;
197
198
  /// The source location of the ellipsis, if this is a pack
199
  /// expansion.
200
  SourceLocation EllipsisLoc;
201
202
  /// Whether this is a virtual base class or not.
203
  unsigned Virtual : 1;
204
205
  /// Whether this is the base of a class (true) or of a struct (false).
206
  ///
207
  /// This determines the mapping from the access specifier as written in the
208
  /// source code to the access specifier used for semantic analysis.
209
  unsigned BaseOfClass : 1;
210
211
  /// Access specifier as written in the source code (may be AS_none).
212
  ///
213
  /// The actual type of data stored here is an AccessSpecifier, but we use
214
  /// "unsigned" here to work around a VC++ bug.
215
  unsigned Access : 2;
216
217
  /// Whether the class contains a using declaration
218
  /// to inherit the named class's constructors.
219
  unsigned InheritConstructors : 1;
220
221
  /// The type of the base class.
222
  ///
223
  /// This will be a class or struct (or a typedef of such). The source code
224
  /// range does not include the \c virtual or the access specifier.
225
  TypeSourceInfo *BaseTypeInfo;
226
227
public:
228
777k
  CXXBaseSpecifier() = default;
229
  CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A,
230
                   TypeSourceInfo *TInfo, SourceLocation EllipsisLoc)
231
    : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC),
232
543k
      Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) {}
233
234
  /// Retrieves the source range that contains the entire base specifier.
235
613k
  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
236
165k
  SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
237
8
  SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
238
239
  /// Get the location at which the base class type was written.
240
78.4k
  SourceLocation getBaseTypeLoc() const LLVM_READONLY {
241
78.4k
    return BaseTypeInfo->getTypeLoc().getBeginLoc();
242
78.4k
  }
243
244
  /// Determines whether the base class is a virtual base class (or not).
245
13.6M
  bool isVirtual() const { return Virtual; }
246
247
  /// Determine whether this base class is a base of a class declared
248
  /// with the 'class' keyword (vs. one declared with the 'struct' keyword).
249
1.25k
  bool isBaseOfClass() const { return BaseOfClass; }
250
251
  /// Determine whether this base specifier is a pack expansion.
252
294k
  bool isPackExpansion() const { return EllipsisLoc.isValid(); }
253
254
  /// Determine whether this base class's constructors get inherited.
255
1.22k
  bool getInheritConstructors() const { return InheritConstructors; }
256
257
  /// Set that this base class's constructors should be inherited.
258
1.29k
  void setInheritConstructors(bool Inherit = true) {
259
1.29k
    InheritConstructors = Inherit;
260
1.29k
  }
261
262
  /// For a pack expansion, determine the location of the ellipsis.
263
322
  SourceLocation getEllipsisLoc() const {
264
322
    return EllipsisLoc;
265
322
  }
266
267
  /// Returns the access specifier for this base specifier.
268
  ///
269
  /// This is the actual base specifier as used for semantic analysis, so
270
  /// the result can never be AS_none. To retrieve the access specifier as
271
  /// written in the source code, use getAccessSpecifierAsWritten().
272
5.34M
  AccessSpecifier getAccessSpecifier() const {
273
5.34M
    if ((AccessSpecifier)Access == AS_none)
274
514k
      return BaseOfClass? 
AS_private10.5k
:
AS_public504k
;
275
4.82M
    else
276
4.82M
      return (AccessSpecifier)Access;
277
5.34M
  }
278
279
  /// Retrieves the access specifier as written in the source code
280
  /// (which may mean that no access specifier was explicitly written).
281
  ///
282
  /// Use getAccessSpecifier() to retrieve the access specifier for use in
283
  /// semantic analysis.
284
295k
  AccessSpecifier getAccessSpecifierAsWritten() const {
285
295k
    return (AccessSpecifier)Access;
286
295k
  }
287
288
  /// Retrieves the type of the base class.
289
  ///
290
  /// This type will always be an unqualified class type.
291
21.5M
  QualType getType() const {
292
21.5M
    return BaseTypeInfo->getType().getUnqualifiedType();
293
21.5M
  }
294
295
  /// Retrieves the type and source location of the base class.
296
299k
  TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; }
297
};
298
299
/// Represents a C++ struct/union/class.
300
class CXXRecordDecl : public RecordDecl {
301
  friend class ASTDeclReader;
302
  friend class ASTDeclWriter;
303
  friend class ASTNodeImporter;
304
  friend class ASTReader;
305
  friend class ASTRecordWriter;
306
  friend class ASTWriter;
307
  friend class DeclContext;
308
  friend class LambdaExpr;
309
310
  friend void FunctionDecl::setPure(bool);
311
  friend void TagDecl::startDefinition();
312
313
  /// Values used in DefinitionData fields to represent special members.
314
  enum SpecialMemberFlags {
315
    SMF_DefaultConstructor = 0x1,
316
    SMF_CopyConstructor = 0x2,
317
    SMF_MoveConstructor = 0x4,
318
    SMF_CopyAssignment = 0x8,
319
    SMF_MoveAssignment = 0x10,
320
    SMF_Destructor = 0x20,
321
    SMF_All = 0x3f
322
  };
323
324
  struct DefinitionData {
325
    /// True if this class has any user-declared constructors.
326
    unsigned UserDeclaredConstructor : 1;
327
328
    /// The user-declared special members which this class has.
329
    unsigned UserDeclaredSpecialMembers : 6;
330
331
    /// True when this class is an aggregate.
332
    unsigned Aggregate : 1;
333
334
    /// True when this class is a POD-type.
335
    unsigned PlainOldData : 1;
336
337
    /// true when this class is empty for traits purposes,
338
    /// i.e. has no data members other than 0-width bit-fields, has no
339
    /// virtual function/base, and doesn't inherit from a non-empty
340
    /// class. Doesn't take union-ness into account.
341
    unsigned Empty : 1;
342
343
    /// True when this class is polymorphic, i.e., has at
344
    /// least one virtual member or derives from a polymorphic class.
345
    unsigned Polymorphic : 1;
346
347
    /// True when this class is abstract, i.e., has at least
348
    /// one pure virtual function, (that can come from a base class).
349
    unsigned Abstract : 1;
350
351
    /// True when this class is standard-layout, per the applicable
352
    /// language rules (including DRs).
353
    unsigned IsStandardLayout : 1;
354
355
    /// True when this class was standard-layout under the C++11
356
    /// definition.
357
    ///
358
    /// C++11 [class]p7.  A standard-layout class is a class that:
359
    /// * has no non-static data members of type non-standard-layout class (or
360
    ///   array of such types) or reference,
361
    /// * has no virtual functions (10.3) and no virtual base classes (10.1),
362
    /// * has the same access control (Clause 11) for all non-static data
363
    ///   members
364
    /// * has no non-standard-layout base classes,
365
    /// * either has no non-static data members in the most derived class and at
366
    ///   most one base class with non-static data members, or has no base
367
    ///   classes with non-static data members, and
368
    /// * has no base classes of the same type as the first non-static data
369
    ///   member.
370
    unsigned IsCXX11StandardLayout : 1;
371
372
    /// True when any base class has any declared non-static data
373
    /// members or bit-fields.
374
    /// This is a helper bit of state used to implement IsStandardLayout more
375
    /// efficiently.
376
    unsigned HasBasesWithFields : 1;
377
378
    /// True when any base class has any declared non-static data
379
    /// members.
380
    /// This is a helper bit of state used to implement IsCXX11StandardLayout
381
    /// more efficiently.
382
    unsigned HasBasesWithNonStaticDataMembers : 1;
383
384
    /// True when there are private non-static data members.
385
    unsigned HasPrivateFields : 1;
386
387
    /// True when there are protected non-static data members.
388
    unsigned HasProtectedFields : 1;
389
390
    /// True when there are private non-static data members.
391
    unsigned HasPublicFields : 1;
392
393
    /// True if this class (or any subobject) has mutable fields.
394
    unsigned HasMutableFields : 1;
395
396
    /// True if this class (or any nested anonymous struct or union)
397
    /// has variant members.
398
    unsigned HasVariantMembers : 1;
399
400
    /// True if there no non-field members declared by the user.
401
    unsigned HasOnlyCMembers : 1;
402
403
    /// True if any field has an in-class initializer, including those
404
    /// within anonymous unions or structs.
405
    unsigned HasInClassInitializer : 1;
406
407
    /// True if any field is of reference type, and does not have an
408
    /// in-class initializer.
409
    ///
410
    /// In this case, value-initialization of this class is illegal in C++98
411
    /// even if the class has a trivial default constructor.
412
    unsigned HasUninitializedReferenceMember : 1;
413
414
    /// True if any non-mutable field whose type doesn't have a user-
415
    /// provided default ctor also doesn't have an in-class initializer.
416
    unsigned HasUninitializedFields : 1;
417
418
    /// True if there are any member using-declarations that inherit
419
    /// constructors from a base class.
420
    unsigned HasInheritedConstructor : 1;
421
422
    /// True if there are any member using-declarations named
423
    /// 'operator='.
424
    unsigned HasInheritedAssignment : 1;
425
426
    /// These flags are \c true if a defaulted corresponding special
427
    /// member can't be fully analyzed without performing overload resolution.
428
    /// @{
429
    unsigned NeedOverloadResolutionForCopyConstructor : 1;
430
    unsigned NeedOverloadResolutionForMoveConstructor : 1;
431
    unsigned NeedOverloadResolutionForMoveAssignment : 1;
432
    unsigned NeedOverloadResolutionForDestructor : 1;
433
    /// @}
434
435
    /// These flags are \c true if an implicit defaulted corresponding
436
    /// special member would be defined as deleted.
437
    /// @{
438
    unsigned DefaultedCopyConstructorIsDeleted : 1;
439
    unsigned DefaultedMoveConstructorIsDeleted : 1;
440
    unsigned DefaultedMoveAssignmentIsDeleted : 1;
441
    unsigned DefaultedDestructorIsDeleted : 1;
442
    /// @}
443
444
    /// The trivial special members which this class has, per
445
    /// C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25,
446
    /// C++11 [class.dtor]p5, or would have if the member were not suppressed.
447
    ///
448
    /// This excludes any user-declared but not user-provided special members
449
    /// which have been declared but not yet defined.
450
    unsigned HasTrivialSpecialMembers : 6;
451
452
    /// These bits keep track of the triviality of special functions for the
453
    /// purpose of calls. Only the bits corresponding to SMF_CopyConstructor,
454
    /// SMF_MoveConstructor, and SMF_Destructor are meaningful here.
455
    unsigned HasTrivialSpecialMembersForCall : 6;
456
457
    /// The declared special members of this class which are known to be
458
    /// non-trivial.
459
    ///
460
    /// This excludes any user-declared but not user-provided special members
461
    /// which have been declared but not yet defined, and any implicit special
462
    /// members which have not yet been declared.
463
    unsigned DeclaredNonTrivialSpecialMembers : 6;
464
465
    /// These bits keep track of the declared special members that are
466
    /// non-trivial for the purpose of calls.
467
    /// Only the bits corresponding to SMF_CopyConstructor,
468
    /// SMF_MoveConstructor, and SMF_Destructor are meaningful here.
469
    unsigned DeclaredNonTrivialSpecialMembersForCall : 6;
470
471
    /// True when this class has a destructor with no semantic effect.
472
    unsigned HasIrrelevantDestructor : 1;
473
474
    /// True when this class has at least one user-declared constexpr
475
    /// constructor which is neither the copy nor move constructor.
476
    unsigned HasConstexprNonCopyMoveConstructor : 1;
477
478
    /// True if this class has a (possibly implicit) defaulted default
479
    /// constructor.
480
    unsigned HasDefaultedDefaultConstructor : 1;
481
482
    /// True if a defaulted default constructor for this class would
483
    /// be constexpr.
484
    unsigned DefaultedDefaultConstructorIsConstexpr : 1;
485
486
    /// True if this class has a constexpr default constructor.
487
    ///
488
    /// This is true for either a user-declared constexpr default constructor
489
    /// or an implicitly declared constexpr default constructor.
490
    unsigned HasConstexprDefaultConstructor : 1;
491
492
    /// True when this class contains at least one non-static data
493
    /// member or base class of non-literal or volatile type.
494
    unsigned HasNonLiteralTypeFieldsOrBases : 1;
495
496
    /// True when visible conversion functions are already computed
497
    /// and are available.
498
    unsigned ComputedVisibleConversions : 1;
499
500
    /// Whether we have a C++11 user-provided default constructor (not
501
    /// explicitly deleted or defaulted).
502
    unsigned UserProvidedDefaultConstructor : 1;
503
504
    /// The special members which have been declared for this class,
505
    /// either by the user or implicitly.
506
    unsigned DeclaredSpecialMembers : 6;
507
508
    /// Whether an implicit copy constructor could have a const-qualified
509
    /// parameter, for initializing virtual bases and for other subobjects.
510
    unsigned ImplicitCopyConstructorCanHaveConstParamForVBase : 1;
511
    unsigned ImplicitCopyConstructorCanHaveConstParamForNonVBase : 1;
512
513
    /// Whether an implicit copy assignment operator would have a
514
    /// const-qualified parameter.
515
    unsigned ImplicitCopyAssignmentHasConstParam : 1;
516
517
    /// Whether any declared copy constructor has a const-qualified
518
    /// parameter.
519
    unsigned HasDeclaredCopyConstructorWithConstParam : 1;
520
521
    /// Whether any declared copy assignment operator has either a
522
    /// const-qualified reference parameter or a non-reference parameter.
523
    unsigned HasDeclaredCopyAssignmentWithConstParam : 1;
524
525
    /// Whether this class describes a C++ lambda.
526
    unsigned IsLambda : 1;
527
528
    /// Whether we are currently parsing base specifiers.
529
    unsigned IsParsingBaseSpecifiers : 1;
530
531
    unsigned HasODRHash : 1;
532
533
    /// A hash of parts of the class to help in ODR checking.
534
    unsigned ODRHash = 0;
535
536
    /// The number of base class specifiers in Bases.
537
    unsigned NumBases = 0;
538
539
    /// The number of virtual base class specifiers in VBases.
540
    unsigned NumVBases = 0;
541
542
    /// Base classes of this class.
543
    ///
544
    /// FIXME: This is wasted space for a union.
545
    LazyCXXBaseSpecifiersPtr Bases;
546
547
    /// direct and indirect virtual base classes of this class.
548
    LazyCXXBaseSpecifiersPtr VBases;
549
550
    /// The conversion functions of this C++ class (but not its
551
    /// inherited conversion functions).
552
    ///
553
    /// Each of the entries in this overload set is a CXXConversionDecl.
554
    LazyASTUnresolvedSet Conversions;
555
556
    /// The conversion functions of this C++ class and all those
557
    /// inherited conversion functions that are visible in this class.
558
    ///
559
    /// Each of the entries in this overload set is a CXXConversionDecl or a
560
    /// FunctionTemplateDecl.
561
    LazyASTUnresolvedSet VisibleConversions;
562
563
    /// The declaration which defines this record.
564
    CXXRecordDecl *Definition;
565
566
    /// The first friend declaration in this class, or null if there
567
    /// aren't any.
568
    ///
569
    /// This is actually currently stored in reverse order.
570
    LazyDeclPtr FirstFriend;
571
572
    DefinitionData(CXXRecordDecl *D);
573
574
    /// Retrieve the set of direct base classes.
575
51.8M
    CXXBaseSpecifier *getBases() const {
576
51.8M
      if (!Bases.isOffset())
577
51.8M
        return Bases.get(nullptr);
578
328
      return getBasesSlowCase();
579
328
    }
580
581
    /// Retrieve the set of virtual base classes.
582
3.74M
    CXXBaseSpecifier *getVBases() const {
583
3.74M
      if (!VBases.isOffset())
584
3.74M
        return VBases.get(nullptr);
585
9
      return getVBasesSlowCase();
586
9
    }
587
588
791
    ArrayRef<CXXBaseSpecifier> bases() const {
589
791
      return llvm::makeArrayRef(getBases(), NumBases);
590
791
    }
591
592
22
    ArrayRef<CXXBaseSpecifier> vbases() const {
593
22
      return llvm::makeArrayRef(getVBases(), NumVBases);
594
22
    }
595
596
  private:
597
    CXXBaseSpecifier *getBasesSlowCase() const;
598
    CXXBaseSpecifier *getVBasesSlowCase() const;
599
  };
600
601
  struct DefinitionData *DefinitionData;
602
603
  /// Describes a C++ closure type (generated by a lambda expression).
604
  struct LambdaDefinitionData : public DefinitionData {
605
    using Capture = LambdaCapture;
606
607
    /// Whether this lambda is known to be dependent, even if its
608
    /// context isn't dependent.
609
    ///
610
    /// A lambda with a non-dependent context can be dependent if it occurs
611
    /// within the default argument of a function template, because the
612
    /// lambda will have been created with the enclosing context as its
613
    /// declaration context, rather than function. This is an unfortunate
614
    /// artifact of having to parse the default arguments before.
615
    unsigned Dependent : 1;
616
617
    /// Whether this lambda is a generic lambda.
618
    unsigned IsGenericLambda : 1;
619
620
    /// The Default Capture.
621
    unsigned CaptureDefault : 2;
622
623
    /// The number of captures in this lambda is limited 2^NumCaptures.
624
    unsigned NumCaptures : 15;
625
626
    /// The number of explicit captures in this lambda.
627
    unsigned NumExplicitCaptures : 13;
628
629
    /// The number used to indicate this lambda expression for name
630
    /// mangling in the Itanium C++ ABI.
631
    unsigned ManglingNumber = 0;
632
633
    /// The declaration that provides context for this lambda, if the
634
    /// actual DeclContext does not suffice. This is used for lambdas that
635
    /// occur within default arguments of function parameters within the class
636
    /// or within a data member initializer.
637
    LazyDeclPtr ContextDecl;
638
639
    /// The list of captures, both explicit and implicit, for this
640
    /// lambda.
641
    Capture *Captures = nullptr;
642
643
    /// The type of the call method.
644
    TypeSourceInfo *MethodTyInfo;
645
646
    LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info,
647
                         bool Dependent, bool IsGeneric,
648
                         LambdaCaptureDefault CaptureDefault)
649
      : DefinitionData(D), Dependent(Dependent), IsGenericLambda(IsGeneric),
650
        CaptureDefault(CaptureDefault), NumCaptures(0), NumExplicitCaptures(0),
651
6.30k
        MethodTyInfo(Info) {
652
6.30k
      IsLambda = true;
653
6.30k
654
6.30k
      // C++1z [expr.prim.lambda]p4:
655
6.30k
      //   This class type is not an aggregate type.
656
6.30k
      Aggregate = false;
657
6.30k
      PlainOldData = false;
658
6.30k
    }
659
  };
660
661
316M
  struct DefinitionData *dataPtr() const {
662
316M
    // Complete the redecl chain (if necessary).
663
316M
    getMostRecentDecl();
664
316M
    return DefinitionData;
665
316M
  }
666
667
316M
  struct DefinitionData &data() const {
668
316M
    auto *DD = dataPtr();
669
316M
    assert(DD && "queried property of class with no definition");
670
316M
    return *DD;
671
316M
  }
672
673
316k
  struct LambdaDefinitionData &getLambdaData() const {
674
316k
    // No update required: a merged definition cannot change any lambda
675
316k
    // properties.
676
316k
    auto *DD = DefinitionData;
677
316k
    assert(DD && DD->IsLambda && "queried lambda property of non-lambda class");
678
316k
    return static_cast<LambdaDefinitionData&>(*DD);
679
316k
  }
680
681
  /// The template or declaration that this declaration
682
  /// describes or was instantiated from, respectively.
683
  ///
684
  /// For non-templates, this value will be null. For record
685
  /// declarations that describe a class template, this will be a
686
  /// pointer to a ClassTemplateDecl. For member
687
  /// classes of class template specializations, this will be the
688
  /// MemberSpecializationInfo referring to the member class that was
689
  /// instantiated or specialized.
690
  llvm::PointerUnion<ClassTemplateDecl *, MemberSpecializationInfo *>
691
      TemplateOrInstantiation;
692
693
  /// Called from setBases and addedMember to notify the class that a
694
  /// direct or virtual base class or a member of class type has been added.
695
  void addedClassSubobject(CXXRecordDecl *Base);
696
697
  /// Notify the class that member has been added.
698
  ///
699
  /// This routine helps maintain information about the class based on which
700
  /// members have been added. It will be invoked by DeclContext::addDecl()
701
  /// whenever a member is added to this record.
702
  void addedMember(Decl *D);
703
704
  void markedVirtualFunctionPure();
705
706
  /// Get the head of our list of friend declarations, possibly
707
  /// deserializing the friends from an external AST source.
708
  FriendDecl *getFirstFriend() const;
709
710
  /// Determine whether this class has an empty base class subobject of type X
711
  /// or of one of the types that might be at offset 0 within X (per the C++
712
  /// "standard layout" rules).
713
  bool hasSubobjectAtOffsetZeroOfEmptyBaseType(ASTContext &Ctx,
714
                                               const CXXRecordDecl *X);
715
716
protected:
717
  CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C, DeclContext *DC,
718
                SourceLocation StartLoc, SourceLocation IdLoc,
719
                IdentifierInfo *Id, CXXRecordDecl *PrevDecl);
720
721
public:
722
  /// Iterator that traverses the base classes of a class.
723
  using base_class_iterator = CXXBaseSpecifier *;
724
725
  /// Iterator that traverses the base classes of a class.
726
  using base_class_const_iterator = const CXXBaseSpecifier *;
727
728
38.0M
  CXXRecordDecl *getCanonicalDecl() override {
729
38.0M
    return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
730
38.0M
  }
731
732
9.64M
  const CXXRecordDecl *getCanonicalDecl() const {
733
9.64M
    return const_cast<CXXRecordDecl*>(this)->getCanonicalDecl();
734
9.64M
  }
735
736
2.95M
  CXXRecordDecl *getPreviousDecl() {
737
2.95M
    return cast_or_null<CXXRecordDecl>(
738
2.95M
            static_cast<RecordDecl *>(this)->getPreviousDecl());
739
2.95M
  }
740
741
1.31M
  const CXXRecordDecl *getPreviousDecl() const {
742
1.31M
    return const_cast<CXXRecordDecl*>(this)->getPreviousDecl();
743
1.31M
  }
744
745
319M
  CXXRecordDecl *getMostRecentDecl() {
746
319M
    return cast<CXXRecordDecl>(
747
319M
            static_cast<RecordDecl *>(this)->getMostRecentDecl());
748
319M
  }
749
750
316M
  const CXXRecordDecl *getMostRecentDecl() const {
751
316M
    return const_cast<CXXRecordDecl*>(this)->getMostRecentDecl();
752
316M
  }
753
754
2.18M
  CXXRecordDecl *getMostRecentNonInjectedDecl() {
755
2.18M
    CXXRecordDecl *Recent =
756
2.18M
        static_cast<CXXRecordDecl *>(this)->getMostRecentDecl();
757
3.32M
    while (Recent->isInjectedClassName()) {
758
1.14M
      // FIXME: Does injected class name need to be in the redeclarations chain?
759
1.14M
      assert(Recent->getPreviousDecl());
760
1.14M
      Recent = Recent->getPreviousDecl();
761
1.14M
    }
762
2.18M
    return Recent;
763
2.18M
  }
764
765
3.37k
  const CXXRecordDecl *getMostRecentNonInjectedDecl() const {
766
3.37k
    return const_cast<CXXRecordDecl*>(this)->getMostRecentNonInjectedDecl();
767
3.37k
  }
768
769
78.7M
  CXXRecordDecl *getDefinition() const {
770
78.7M
    // We only need an update if we don't already know which
771
78.7M
    // declaration is the definition.
772
78.7M
    auto *DD = DefinitionData ? 
DefinitionData78.3M
:
dataPtr()402k
;
773
78.7M
    return DD ? 
DD->Definition78.3M
:
nullptr402k
;
774
78.7M
  }
775
776
1.67M
  bool hasDefinition() const { return DefinitionData || 
dataPtr()650
; }
777
778
  static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
779
                               SourceLocation StartLoc, SourceLocation IdLoc,
780
                               IdentifierInfo *Id,
781
                               CXXRecordDecl *PrevDecl = nullptr,
782
                               bool DelayTypeCreation = false);
783
  static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC,
784
                                     TypeSourceInfo *Info, SourceLocation Loc,
785
                                     bool DependentLambda, bool IsGeneric,
786
                                     LambdaCaptureDefault CaptureDefault);
787
  static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
788
789
5.47M
  bool isDynamicClass() const {
790
5.47M
    return data().Polymorphic || 
data().NumVBases != 05.24M
;
791
5.47M
  }
792
793
  /// @returns true if class is dynamic or might be dynamic because the
794
  /// definition is incomplete of dependent.
795
26
  bool mayBeDynamicClass() const {
796
26
    return !hasDefinition() || 
isDynamicClass()16
||
hasAnyDependentBases()3
;
797
26
  }
798
799
  /// @returns true if class is non dynamic or might be non dynamic because the
800
  /// definition is incomplete of dependent.
801
13
  bool mayBeNonDynamicClass() const {
802
13
    return !hasDefinition() || 
!isDynamicClass()5
||
hasAnyDependentBases()3
;
803
13
  }
804
805
250k
  void setIsParsingBaseSpecifiers() { data().IsParsingBaseSpecifiers = true; }
806
807
962
  bool isParsingBaseSpecifiers() const {
808
962
    return data().IsParsingBaseSpecifiers;
809
962
  }
810
811
  unsigned getODRHash() const;
812
813
  /// Sets the base classes of this struct or class.
814
  void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
815
816
  /// Retrieves the number of base classes of this class.
817
275k
  unsigned getNumBases() const { return data().NumBases; }
818
819
  using base_class_range = llvm::iterator_range<base_class_iterator>;
820
  using base_class_const_range =
821
      llvm::iterator_range<base_class_const_iterator>;
822
823
3.93M
  base_class_range bases() {
824
3.93M
    return base_class_range(bases_begin(), bases_end());
825
3.93M
  }
826
18.2M
  base_class_const_range bases() const {
827
18.2M
    return base_class_const_range(bases_begin(), bases_end());
828
18.2M
  }
829
830
14.4M
  base_class_iterator bases_begin() { return data().getBases(); }
831
36.6M
  base_class_const_iterator bases_begin() const { return data().getBases(); }
832
7.22M
  base_class_iterator bases_end() { return bases_begin() + data().NumBases; }
833
18.3M
  base_class_const_iterator bases_end() const {
834
18.3M
    return bases_begin() + data().NumBases;
835
18.3M
  }
836
837
  /// Retrieves the number of virtual base classes of this class.
838
3.08M
  unsigned getNumVBases() const { return data().NumVBases; }
839
840
1.61M
  base_class_range vbases() {
841
1.61M
    return base_class_range(vbases_begin(), vbases_end());
842
1.61M
  }
843
254k
  base_class_const_range vbases() const {
844
254k
    return base_class_const_range(vbases_begin(), vbases_end());
845
254k
  }
846
847
3.22M
  base_class_iterator vbases_begin() { return data().getVBases(); }
848
509k
  base_class_const_iterator vbases_begin() const { return data().getVBases(); }
849
1.61M
  base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; }
850
254k
  base_class_const_iterator vbases_end() const {
851
254k
    return vbases_begin() + data().NumVBases;
852
254k
  }
853
854
  /// Determine whether this class has any dependent base classes which
855
  /// are not the current instantiation.
856
  bool hasAnyDependentBases() const;
857
858
  /// Iterator access to method members.  The method iterator visits
859
  /// all method members of the class, including non-instance methods,
860
  /// special methods, etc.
861
  using method_iterator = specific_decl_iterator<CXXMethodDecl>;
862
  using method_range =
863
      llvm::iterator_range<specific_decl_iterator<CXXMethodDecl>>;
864
865
4.66M
  method_range methods() const {
866
4.66M
    return method_range(method_begin(), method_end());
867
4.66M
  }
868
869
  /// Method begin iterator.  Iterates in the order the methods
870
  /// were declared.
871
4.67M
  method_iterator method_begin() const {
872
4.67M
    return method_iterator(decls_begin());
873
4.67M
  }
874
875
  /// Method past-the-end iterator.
876
4.67M
  method_iterator method_end() const {
877
4.67M
    return method_iterator(decls_end());
878
4.67M
  }
879
880
  /// Iterator access to constructor members.
881
  using ctor_iterator = specific_decl_iterator<CXXConstructorDecl>;
882
  using ctor_range =
883
      llvm::iterator_range<specific_decl_iterator<CXXConstructorDecl>>;
884
885
3.13k
  ctor_range ctors() const { return ctor_range(ctor_begin(), ctor_end()); }
886
887
3.13k
  ctor_iterator ctor_begin() const {
888
3.13k
    return ctor_iterator(decls_begin());
889
3.13k
  }
890
891
3.13k
  ctor_iterator ctor_end() const {
892
3.13k
    return ctor_iterator(decls_end());
893
3.13k
  }
894
895
  /// An iterator over friend declarations.  All of these are defined
896
  /// in DeclFriend.h.
897
  class friend_iterator;
898
  using friend_range = llvm::iterator_range<friend_iterator>;
899
900
  friend_range friends() const;
901
  friend_iterator friend_begin() const;
902
  friend_iterator friend_end() const;
903
  void pushFriendDecl(FriendDecl *FD);
904
905
  /// Determines whether this record has any friends.
906
29
  bool hasFriends() const {
907
29
    return data().FirstFriend.isValid();
908
29
  }
909
910
  /// \c true if a defaulted copy constructor for this class would be
911
  /// deleted.
912
1.30M
  bool defaultedCopyConstructorIsDeleted() const {
913
1.30M
    assert((!needsOverloadResolutionForCopyConstructor() ||
914
1.30M
            (data().DeclaredSpecialMembers & SMF_CopyConstructor)) &&
915
1.30M
           "this property has not yet been computed by Sema");
916
1.30M
    return data().DefaultedCopyConstructorIsDeleted;
917
1.30M
  }
918
919
  /// \c true if a defaulted move constructor for this class would be
920
  /// deleted.
921
1.25M
  bool defaultedMoveConstructorIsDeleted() const {
922
1.25M
    assert((!needsOverloadResolutionForMoveConstructor() ||
923
1.25M
            (data().DeclaredSpecialMembers & SMF_MoveConstructor)) &&
924
1.25M
           "this property has not yet been computed by Sema");
925
1.25M
    return data().DefaultedMoveConstructorIsDeleted;
926
1.25M
  }
927
928
  /// \c true if a defaulted destructor for this class would be deleted.
929
1.29M
  bool defaultedDestructorIsDeleted() const {
930
1.29M
    assert((!needsOverloadResolutionForDestructor() ||
931
1.29M
            (data().DeclaredSpecialMembers & SMF_Destructor)) &&
932
1.29M
           "this property has not yet been computed by Sema");
933
1.29M
    return data().DefaultedDestructorIsDeleted;
934
1.29M
  }
935
936
  /// \c true if we know for sure that this class has a single,
937
  /// accessible, unambiguous copy constructor that is not deleted.
938
1.00M
  bool hasSimpleCopyConstructor() const {
939
1.00M
    return !hasUserDeclaredCopyConstructor() &&
940
1.00M
           
!data().DefaultedCopyConstructorIsDeleted964k
;
941
1.00M
  }
942
943
  /// \c true if we know for sure that this class has a single,
944
  /// accessible, unambiguous move constructor that is not deleted.
945
1.00M
  bool hasSimpleMoveConstructor() const {
946
1.00M
    return !hasUserDeclaredMoveConstructor() && 
hasMoveConstructor()984k
&&
947
1.00M
           
!data().DefaultedMoveConstructorIsDeleted929k
;
948
1.00M
  }
949
950
  /// \c true if we know for sure that this class has a single,
951
  /// accessible, unambiguous move assignment operator that is not deleted.
952
1.00M
  bool hasSimpleMoveAssignment() const {
953
1.00M
    return !hasUserDeclaredMoveAssignment() && 
hasMoveAssignment()985k
&&
954
1.00M
           
!data().DefaultedMoveAssignmentIsDeleted929k
;
955
1.00M
  }
956
957
  /// \c true if we know for sure that this class has an accessible
958
  /// destructor that is not deleted.
959
1.00M
  bool hasSimpleDestructor() const {
960
1.00M
    return !hasUserDeclaredDestructor() &&
961
1.00M
           
!data().DefaultedDestructorIsDeleted938k
;
962
1.00M
  }
963
964
  /// Determine whether this class has any default constructors.
965
1.38M
  bool hasDefaultConstructor() const {
966
1.38M
    return (data().DeclaredSpecialMembers & SMF_DefaultConstructor) ||
967
1.38M
           
needsImplicitDefaultConstructor()782k
;
968
1.38M
  }
969
970
  /// Determine if we need to declare a default constructor for
971
  /// this class.
972
  ///
973
  /// This value is used for lazy creation of default constructors.
974
4.15M
  bool needsImplicitDefaultConstructor() const {
975
4.15M
    return !data().UserDeclaredConstructor &&
976
4.15M
           
!(data().DeclaredSpecialMembers & SMF_DefaultConstructor)3.15M
&&
977
4.15M
           
(3.04M
!isLambda()3.04M
||
lambdaIsDefaultConstructibleAndAssignable()10.1k
);
978
4.15M
  }
979
980
  /// Determine whether this class has any user-declared constructors.
981
  ///
982
  /// When true, a default constructor will not be implicitly declared.
983
1.82M
  bool hasUserDeclaredConstructor() const {
984
1.82M
    return data().UserDeclaredConstructor;
985
1.82M
  }
986
987
  /// Whether this class has a user-provided default constructor
988
  /// per C++11.
989
537
  bool hasUserProvidedDefaultConstructor() const {
990
537
    return data().UserProvidedDefaultConstructor;
991
537
  }
992
993
  /// Determine whether this class has a user-declared copy constructor.
994
  ///
995
  /// When false, a copy constructor will be implicitly declared.
996
10.8M
  bool hasUserDeclaredCopyConstructor() const {
997
10.8M
    return data().UserDeclaredSpecialMembers & SMF_CopyConstructor;
998
10.8M
  }
999
1000
  /// Determine whether this class needs an implicit copy
1001
  /// constructor to be lazily declared.
1002
4.13M
  bool needsImplicitCopyConstructor() const {
1003
4.13M
    return !(data().DeclaredSpecialMembers & SMF_CopyConstructor);
1004
4.13M
  }
1005
1006
  /// Determine whether we need to eagerly declare a defaulted copy
1007
  /// constructor for this class.
1008
1.66M
  bool needsOverloadResolutionForCopyConstructor() const {
1009
1.66M
    // C++17 [class.copy.ctor]p6:
1010
1.66M
    //   If the class definition declares a move constructor or move assignment
1011
1.66M
    //   operator, the implicitly declared copy constructor is defined as
1012
1.66M
    //   deleted.
1013
1.66M
    // In MSVC mode, sometimes a declared move assignment does not delete an
1014
1.66M
    // implicit copy constructor, so defer this choice to Sema.
1015
1.66M
    if (data().UserDeclaredSpecialMembers &
1016
1.66M
        (SMF_MoveConstructor | SMF_MoveAssignment))
1017
5.62k
      return true;
1018
1.65M
    return data().NeedOverloadResolutionForCopyConstructor;
1019
1.65M
  }
1020
1021
  /// Determine whether an implicit copy constructor for this type
1022
  /// would have a parameter with a const-qualified reference type.
1023
733k
  bool implicitCopyConstructorHasConstParam() const {
1024
733k
    return data().ImplicitCopyConstructorCanHaveConstParamForNonVBase &&
1025
733k
           
(733k
isAbstract()733k
||
1026
733k
            
data().ImplicitCopyConstructorCanHaveConstParamForVBase726k
);
1027
733k
  }
1028
1029
  /// Determine whether this class has a copy constructor with
1030
  /// a parameter type which is a reference to a const-qualified type.
1031
998k
  bool hasCopyConstructorWithConstParam() const {
1032
998k
    return data().HasDeclaredCopyConstructorWithConstParam ||
1033
998k
           
(578k
needsImplicitCopyConstructor()578k
&&
1034
578k
            
implicitCopyConstructorHasConstParam()578k
);
1035
998k
  }
1036
1037
  /// Whether this class has a user-declared move constructor or
1038
  /// assignment operator.
1039
  ///
1040
  /// When false, a move constructor and assignment operator may be
1041
  /// implicitly declared.
1042
0
  bool hasUserDeclaredMoveOperation() const {
1043
0
    return data().UserDeclaredSpecialMembers &
1044
0
             (SMF_MoveConstructor | SMF_MoveAssignment);
1045
0
  }
1046
1047
  /// Determine whether this class has had a move constructor
1048
  /// declared by the user.
1049
4.62M
  bool hasUserDeclaredMoveConstructor() const {
1050
4.62M
    return data().UserDeclaredSpecialMembers & SMF_MoveConstructor;
1051
4.62M
  }
1052
1053
  /// Determine whether this class has a move constructor.
1054
4.41M
  bool hasMoveConstructor() const {
1055
4.41M
    return (data().DeclaredSpecialMembers & SMF_MoveConstructor) ||
1056
4.41M
           
needsImplicitMoveConstructor()3.32M
;
1057
4.41M
  }
1058
1059
  /// Set that we attempted to declare an implicit copy
1060
  /// constructor, but overload resolution failed so we deleted it.
1061
20.6k
  void setImplicitCopyConstructorIsDeleted() {
1062
20.6k
    assert((data().DefaultedCopyConstructorIsDeleted ||
1063
20.6k
            needsOverloadResolutionForCopyConstructor()) &&
1064
20.6k
           "Copy constructor should not be deleted");
1065
20.6k
    data().DefaultedCopyConstructorIsDeleted = true;
1066
20.6k
  }
1067
1068
  /// Set that we attempted to declare an implicit move
1069
  /// constructor, but overload resolution failed so we deleted it.
1070
5.76k
  void setImplicitMoveConstructorIsDeleted() {
1071
5.76k
    assert((data().DefaultedMoveConstructorIsDeleted ||
1072
5.76k
            needsOverloadResolutionForMoveConstructor()) &&
1073
5.76k
           "move constructor should not be deleted");
1074
5.76k
    data().DefaultedMoveConstructorIsDeleted = true;
1075
5.76k
  }
1076
1077
  /// Set that we attempted to declare an implicit destructor,
1078
  /// but overload resolution failed so we deleted it.
1079
323
  void setImplicitDestructorIsDeleted() {
1080
323
    assert((data().DefaultedDestructorIsDeleted ||
1081
323
            needsOverloadResolutionForDestructor()) &&
1082
323
           "destructor should not be deleted");
1083
323
    data().DefaultedDestructorIsDeleted = true;
1084
323
  }
1085
1086
  /// Determine whether this class should get an implicit move
1087
  /// constructor or if any existing special member function inhibits this.
1088
6.87M
  bool needsImplicitMoveConstructor() const {
1089
6.87M
    return !(data().DeclaredSpecialMembers & SMF_MoveConstructor) &&
1090
6.87M
           
!hasUserDeclaredCopyConstructor()6.37M
&&
1091
6.87M
           
!hasUserDeclaredCopyAssignment()6.15M
&&
1092
6.87M
           
!hasUserDeclaredMoveAssignment()6.14M
&&
1093
6.87M
           
!hasUserDeclaredDestructor()6.14M
;
1094
6.87M
  }
1095
1096
  /// Determine whether we need to eagerly declare a defaulted move
1097
  /// constructor for this class.
1098
1.52M
  bool needsOverloadResolutionForMoveConstructor() const {
1099
1.52M
    return data().NeedOverloadResolutionForMoveConstructor;
1100
1.52M
  }
1101
1102
  /// Determine whether this class has a user-declared copy assignment
1103
  /// operator.
1104
  ///
1105
  /// When false, a copy assignment operator will be implicitly declared.
1106
9.58M
  bool hasUserDeclaredCopyAssignment() const {
1107
9.58M
    return data().UserDeclaredSpecialMembers & SMF_CopyAssignment;
1108
9.58M
  }
1109
1110
  /// Determine whether this class needs an implicit copy
1111
  /// assignment operator to be lazily declared.
1112
2.39M
  bool needsImplicitCopyAssignment() const {
1113
2.39M
    return !(data().DeclaredSpecialMembers & SMF_CopyAssignment);
1114
2.39M
  }
1115
1116
  /// Determine whether we need to eagerly declare a defaulted copy
1117
  /// assignment operator for this class.
1118
1.39M
  bool needsOverloadResolutionForCopyAssignment() const {
1119
1.39M
    return data().HasMutableFields;
1120
1.39M
  }
1121
1122
  /// Determine whether an implicit copy assignment operator for this
1123
  /// type would have a parameter with a const-qualified reference type.
1124
979k
  bool implicitCopyAssignmentHasConstParam() const {
1125
979k
    return data().ImplicitCopyAssignmentHasConstParam;
1126
979k
  }
1127
1128
  /// Determine whether this class has a copy assignment operator with
1129
  /// a parameter type which is a reference to a const-qualified type or is not
1130
  /// a reference.
1131
996k
  bool hasCopyAssignmentWithConstParam() const {
1132
996k
    return data().HasDeclaredCopyAssignmentWithConstParam ||
1133
996k
           
(907k
needsImplicitCopyAssignment()907k
&&
1134
907k
            
implicitCopyAssignmentHasConstParam()906k
);
1135
996k
  }
1136
1137
  /// Determine whether this class has had a move assignment
1138
  /// declared by the user.
1139
7.35M
  bool hasUserDeclaredMoveAssignment() const {
1140
7.35M
    return data().UserDeclaredSpecialMembers & SMF_MoveAssignment;
1141
7.35M
  }
1142
1143
  /// Determine whether this class has a move assignment operator.
1144
2.01M
  bool hasMoveAssignment() const {
1145
2.01M
    return (data().DeclaredSpecialMembers & SMF_MoveAssignment) ||
1146
2.01M
           
needsImplicitMoveAssignment()1.94M
;
1147
2.01M
  }
1148
1149
  /// Set that we attempted to declare an implicit move assignment
1150
  /// operator, but overload resolution failed so we deleted it.
1151
8.53k
  void setImplicitMoveAssignmentIsDeleted() {
1152
8.53k
    assert((data().DefaultedMoveAssignmentIsDeleted ||
1153
8.53k
            needsOverloadResolutionForMoveAssignment()) &&
1154
8.53k
           "move assignment should not be deleted");
1155
8.53k
    data().DefaultedMoveAssignmentIsDeleted = true;
1156
8.53k
  }
1157
1158
  /// Determine whether this class should get an implicit move
1159
  /// assignment operator or if any existing special member function inhibits
1160
  /// this.
1161
3.56M
  bool needsImplicitMoveAssignment() const {
1162
3.56M
    return !(data().DeclaredSpecialMembers & SMF_MoveAssignment) &&
1163
3.56M
           
!hasUserDeclaredCopyConstructor()3.50M
&&
1164
3.56M
           
!hasUserDeclaredCopyAssignment()3.41M
&&
1165
3.56M
           
!hasUserDeclaredMoveConstructor()3.41M
&&
1166
3.56M
           
!hasUserDeclaredDestructor()3.41M
&&
1167
3.56M
           
(3.28M
!isLambda()3.28M
||
lambdaIsDefaultConstructibleAndAssignable()7.19k
);
1168
3.56M
  }
1169
1170
  /// Determine whether we need to eagerly declare a move assignment
1171
  /// operator for this class.
1172
1.32M
  bool needsOverloadResolutionForMoveAssignment() const {
1173
1.32M
    return data().NeedOverloadResolutionForMoveAssignment;
1174
1.32M
  }
1175
1176
  /// Determine whether this class has a user-declared destructor.
1177
  ///
1178
  /// When false, a destructor will be implicitly declared.
1179
10.5M
  bool hasUserDeclaredDestructor() const {
1180
10.5M
    return data().UserDeclaredSpecialMembers & SMF_Destructor;
1181
10.5M
  }
1182
1183
  /// Determine whether this class needs an implicit destructor to
1184
  /// be lazily declared.
1185
3.03M
  bool needsImplicitDestructor() const {
1186
3.03M
    return !(data().DeclaredSpecialMembers & SMF_Destructor);
1187
3.03M
  }
1188
1189
  /// Determine whether we need to eagerly declare a destructor for this
1190
  /// class.
1191
1.31M
  bool needsOverloadResolutionForDestructor() const {
1192
1.31M
    return data().NeedOverloadResolutionForDestructor;
1193
1.31M
  }
1194
1195
  /// Determine whether this class describes a lambda function object.
1196
83.2M
  bool isLambda() const {
1197
83.2M
    // An update record can't turn a non-lambda into a lambda.
1198
83.2M
    auto *DD = DefinitionData;
1199
83.2M
    return DD && 
DD->IsLambda77.2M
;
1200
83.2M
  }
1201
1202
  /// Determine whether this class describes a generic
1203
  /// lambda function object (i.e. function call operator is
1204
  /// a template).
1205
  bool isGenericLambda() const;
1206
1207
  /// Determine whether this lambda should have an implicit default constructor
1208
  /// and copy and move assignment operators.
1209
  bool lambdaIsDefaultConstructibleAndAssignable() const;
1210
1211
  /// Retrieve the lambda call operator of the closure type
1212
  /// if this is a closure type.
1213
  CXXMethodDecl *getLambdaCallOperator() const;
1214
1215
  /// Retrieve the lambda static invoker, the address of which
1216
  /// is returned by the conversion operator, and the body of which
1217
  /// is forwarded to the lambda call operator.
1218
  CXXMethodDecl *getLambdaStaticInvoker() const;
1219
1220
  /// Retrieve the generic lambda's template parameter list.
1221
  /// Returns null if the class does not represent a lambda or a generic
1222
  /// lambda.
1223
  TemplateParameterList *getGenericLambdaTemplateParameterList() const;
1224
1225
28.9k
  LambdaCaptureDefault getLambdaCaptureDefault() const {
1226
28.9k
    assert(isLambda());
1227
28.9k
    return static_cast<LambdaCaptureDefault>(getLambdaData().CaptureDefault);
1228
28.9k
  }
1229
1230
  /// For a closure type, retrieve the mapping from captured
1231
  /// variables and \c this to the non-static data members that store the
1232
  /// values or references of the captures.
1233
  ///
1234
  /// \param Captures Will be populated with the mapping from captured
1235
  /// variables to the corresponding fields.
1236
  ///
1237
  /// \param ThisCapture Will be set to the field declaration for the
1238
  /// \c this capture.
1239
  ///
1240
  /// \note No entries will be added for init-captures, as they do not capture
1241
  /// variables.
1242
  void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures,
1243
                        FieldDecl *&ThisCapture) const;
1244
1245
  using capture_const_iterator = const LambdaCapture *;
1246
  using capture_const_range = llvm::iterator_range<capture_const_iterator>;
1247
1248
1.33k
  capture_const_range captures() const {
1249
1.33k
    return capture_const_range(captures_begin(), captures_end());
1250
1.33k
  }
1251
1252
2.84k
  capture_const_iterator captures_begin() const {
1253
2.84k
    return isLambda() ? getLambdaData().Captures : 
nullptr0
;
1254
2.84k
  }
1255
1256
1.35k
  capture_const_iterator captures_end() const {
1257
1.35k
    return isLambda() ? captures_begin() + getLambdaData().NumCaptures
1258
1.35k
                      : 
nullptr0
;
1259
1.35k
  }
1260
1261
  using conversion_iterator = UnresolvedSetIterator;
1262
1263
3.95M
  conversion_iterator conversion_begin() const {
1264
3.95M
    return data().Conversions.get(getASTContext()).begin();
1265
3.95M
  }
1266
1267
3.95M
  conversion_iterator conversion_end() const {
1268
3.95M
    return data().Conversions.get(getASTContext()).end();
1269
3.95M
  }
1270
1271
  /// Removes a conversion function from this class.  The conversion
1272
  /// function must currently be a member of this class.  Furthermore,
1273
  /// this class must currently be in the process of being defined.
1274
  void removeConversion(const NamedDecl *Old);
1275
1276
  /// Get all conversion functions visible in current class,
1277
  /// including conversion function templates.
1278
  llvm::iterator_range<conversion_iterator> getVisibleConversionFunctions();
1279
1280
  /// Determine whether this class is an aggregate (C++ [dcl.init.aggr]),
1281
  /// which is a class with no user-declared constructors, no private
1282
  /// or protected non-static data members, no base classes, and no virtual
1283
  /// functions (C++ [dcl.init.aggr]p1).
1284
2.57M
  bool isAggregate() const { return data().Aggregate; }
1285
1286
  /// Whether this class has any in-class initializers
1287
  /// for non-static data members (including those in anonymous unions or
1288
  /// structs).
1289
26.0k
  bool hasInClassInitializer() const { return data().HasInClassInitializer; }
1290
1291
  /// Whether this class or any of its subobjects has any members of
1292
  /// reference type which would make value-initialization ill-formed.
1293
  ///
1294
  /// Per C++03 [dcl.init]p5:
1295
  ///  - if T is a non-union class type without a user-declared constructor,
1296
  ///    then every non-static data member and base-class component of T is
1297
  ///    value-initialized [...] A program that calls for [...]
1298
  ///    value-initialization of an entity of reference type is ill-formed.
1299
996k
  bool hasUninitializedReferenceMember() const {
1300
996k
    return !isUnion() && 
!hasUserDeclaredConstructor()985k
&&
1301
996k
           
data().HasUninitializedReferenceMember877k
;
1302
996k
  }
1303
1304
  /// Whether this class is a POD-type (C++ [class]p4)
1305
  ///
1306
  /// For purposes of this function a class is POD if it is an aggregate
1307
  /// that has no non-static non-POD data members, no reference data
1308
  /// members, no user-defined copy assignment operator and no
1309
  /// user-defined destructor.
1310
  ///
1311
  /// Note that this is the C++ TR1 definition of POD.
1312
497k
  bool isPOD() const { return data().PlainOldData; }
1313
1314
  /// True if this class is C-like, without C++-specific features, e.g.
1315
  /// it contains only public fields, no bases, tag kind is not 'class', etc.
1316
  bool isCLike() const;
1317
1318
  /// Determine whether this is an empty class in the sense of
1319
  /// (C++11 [meta.unary.prop]).
1320
  ///
1321
  /// The CXXRecordDecl is a class type, but not a union type,
1322
  /// with no non-static data members other than bit-fields of length 0,
1323
  /// no virtual member functions, no virtual base classes,
1324
  /// and no base class B for which is_empty<B>::value is false.
1325
  ///
1326
  /// \note This does NOT include a check for union-ness.
1327
2.06M
  bool isEmpty() const { return data().Empty; }
1328
1329
  /// Determine whether this class has direct non-static data members.
1330
625k
  bool hasDirectFields() const {
1331
625k
    auto &D = data();
1332
625k
    return D.HasPublicFields || 
D.HasProtectedFields617k
||
D.HasPrivateFields613k
;
1333
625k
  }
1334
1335
  /// Whether this class is polymorphic (C++ [class.virtual]),
1336
  /// which means that the class contains or inherits a virtual function.
1337
2.55M
  bool isPolymorphic() const { return data().Polymorphic; }
1338
1339
  /// Determine whether this class has a pure virtual function.
1340
  ///
1341
  /// The class is is abstract per (C++ [class.abstract]p2) if it declares
1342
  /// a pure virtual function or inherits a pure virtual function that is
1343
  /// not overridden.
1344
6.19M
  bool isAbstract() const { return data().Abstract; }
1345
1346
  /// Determine whether this class is standard-layout per
1347
  /// C++ [class]p7.
1348
1.03M
  bool isStandardLayout() const { return data().IsStandardLayout; }
1349
1350
  /// Determine whether this class was standard-layout per
1351
  /// C++11 [class]p7, specifically using the C++11 rules without any DRs.
1352
1.02M
  bool isCXX11StandardLayout() const { return data().IsCXX11StandardLayout; }
1353
1354
  /// Determine whether this class, or any of its class subobjects,
1355
  /// contains a mutable field.
1356
1.00M
  bool hasMutableFields() const { return data().HasMutableFields; }
1357
1358
  /// Determine whether this class has any variant members.
1359
366k
  bool hasVariantMembers() const { return data().HasVariantMembers; }
1360
1361
  /// Determine whether this class has a trivial default constructor
1362
  /// (C++11 [class.ctor]p5).
1363
1.38M
  bool hasTrivialDefaultConstructor() const {
1364
1.38M
    return hasDefaultConstructor() &&
1365
1.38M
           
(data().HasTrivialSpecialMembers & SMF_DefaultConstructor)1.33M
;
1366
1.38M
  }
1367
1368
  /// Determine whether this class has a non-trivial default constructor
1369
  /// (C++11 [class.ctor]p5).
1370
4.29k
  bool hasNonTrivialDefaultConstructor() const {
1371
4.29k
    return (data().DeclaredNonTrivialSpecialMembers & SMF_DefaultConstructor) ||
1372
4.29k
           
(1.04k
needsImplicitDefaultConstructor()1.04k
&&
1373
1.04k
            
!(data().HasTrivialSpecialMembers & SMF_DefaultConstructor)440
);
1374
4.29k
  }
1375
1376
  /// Determine whether this class has at least one constexpr constructor
1377
  /// other than the copy or move constructors.
1378
304k
  bool hasConstexprNonCopyMoveConstructor() const {
1379
304k
    return data().HasConstexprNonCopyMoveConstructor ||
1380
304k
           
(267k
needsImplicitDefaultConstructor()267k
&&
1381
267k
            
defaultedDefaultConstructorIsConstexpr()136k
);
1382
304k
  }
1383
1384
  /// Determine whether a defaulted default constructor for this class
1385
  /// would be constexpr.
1386
759k
  bool defaultedDefaultConstructorIsConstexpr() const {
1387
759k
    return data().DefaultedDefaultConstructorIsConstexpr &&
1388
759k
           
(425k
!isUnion()425k
||
hasInClassInitializer()15.6k
||
!hasVariantMembers()15.5k
);
1389
759k
  }
1390
1391
  /// Determine whether this class has a constexpr default constructor.
1392
992k
  bool hasConstexprDefaultConstructor() const {
1393
992k
    return data().HasConstexprDefaultConstructor ||
1394
992k
           
(653k
needsImplicitDefaultConstructor()653k
&&
1395
653k
            
defaultedDefaultConstructorIsConstexpr()554k
);
1396
992k
  }
1397
1398
  /// Determine whether this class has a trivial copy constructor
1399
  /// (C++ [class.copy]p6, C++11 [class.copy]p12)
1400
1.44M
  bool hasTrivialCopyConstructor() const {
1401
1.44M
    return data().HasTrivialSpecialMembers & SMF_CopyConstructor;
1402
1.44M
  }
1403
1404
2.44M
  bool hasTrivialCopyConstructorForCall() const {
1405
2.44M
    return data().HasTrivialSpecialMembersForCall & SMF_CopyConstructor;
1406
2.44M
  }
1407
1408
  /// Determine whether this class has a non-trivial copy constructor
1409
  /// (C++ [class.copy]p6, C++11 [class.copy]p12)
1410
283k
  bool hasNonTrivialCopyConstructor() const {
1411
283k
    return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor ||
1412
283k
           
!hasTrivialCopyConstructor()232k
;
1413
283k
  }
1414
1415
93
  bool hasNonTrivialCopyConstructorForCall() const {
1416
93
    return (data().DeclaredNonTrivialSpecialMembersForCall &
1417
93
            SMF_CopyConstructor) ||
1418
93
           
!hasTrivialCopyConstructorForCall()83
;
1419
93
  }
1420
1421
  /// Determine whether this class has a trivial move constructor
1422
  /// (C++11 [class.copy]p12)
1423
1.09M
  bool hasTrivialMoveConstructor() const {
1424
1.09M
    return hasMoveConstructor() &&
1425
1.09M
           
(data().HasTrivialSpecialMembers & SMF_MoveConstructor)1.03M
;
1426
1.09M
  }
1427
1428
2.34M
  bool hasTrivialMoveConstructorForCall() const {
1429
2.34M
    return hasMoveConstructor() &&
1430
2.34M
           
(data().HasTrivialSpecialMembersForCall & SMF_MoveConstructor)2.28M
;
1431
2.34M
  }
1432
1433
  /// Determine whether this class has a non-trivial move constructor
1434
  /// (C++11 [class.copy]p12)
1435
178k
  bool hasNonTrivialMoveConstructor() const {
1436
178k
    return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveConstructor) ||
1437
178k
           
(175k
needsImplicitMoveConstructor()175k
&&
1438
175k
            
!(data().HasTrivialSpecialMembers & SMF_MoveConstructor)101k
);
1439
178k
  }
1440
1441
0
  bool hasNonTrivialMoveConstructorForCall() const {
1442
0
    return (data().DeclaredNonTrivialSpecialMembersForCall &
1443
0
            SMF_MoveConstructor) ||
1444
0
           (needsImplicitMoveConstructor() &&
1445
0
            !(data().HasTrivialSpecialMembersForCall & SMF_MoveConstructor));
1446
0
  }
1447
1448
  /// Determine whether this class has a trivial copy assignment operator
1449
  /// (C++ [class.copy]p11, C++11 [class.copy]p25)
1450
1.24M
  bool hasTrivialCopyAssignment() const {
1451
1.24M
    return data().HasTrivialSpecialMembers & SMF_CopyAssignment;
1452
1.24M
  }
1453
1454
  /// Determine whether this class has a non-trivial copy assignment
1455
  /// operator (C++ [class.copy]p11, C++11 [class.copy]p25)
1456
174k
  bool hasNonTrivialCopyAssignment() const {
1457
174k
    return data().DeclaredNonTrivialSpecialMembers & SMF_CopyAssignment ||
1458
174k
           
!hasTrivialCopyAssignment()172k
;
1459
174k
  }
1460
1461
  /// Determine whether this class has a trivial move assignment operator
1462
  /// (C++11 [class.copy]p25)
1463
1.02M
  bool hasTrivialMoveAssignment() const {
1464
1.02M
    return hasMoveAssignment() &&
1465
1.02M
           
(data().HasTrivialSpecialMembers & SMF_MoveAssignment)972k
;
1466
1.02M
  }
1467
1468
  /// Determine whether this class has a non-trivial move assignment
1469
  /// operator (C++11 [class.copy]p25)
1470
173k
  bool hasNonTrivialMoveAssignment() const {
1471
173k
    return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveAssignment) ||
1472
173k
           
(173k
needsImplicitMoveAssignment()173k
&&
1473
173k
            
!(data().HasTrivialSpecialMembers & SMF_MoveAssignment)137k
);
1474
173k
  }
1475
1476
  /// Determine whether this class has a trivial destructor
1477
  /// (C++ [class.dtor]p3)
1478
3.02M
  bool hasTrivialDestructor() const {
1479
3.02M
    return data().HasTrivialSpecialMembers & SMF_Destructor;
1480
3.02M
  }
1481
1482
2.40M
  bool hasTrivialDestructorForCall() const {
1483
2.40M
    return data().HasTrivialSpecialMembersForCall & SMF_Destructor;
1484
2.40M
  }
1485
1486
  /// Determine whether this class has a non-trivial destructor
1487
  /// (C++ [class.dtor]p3)
1488
1.89M
  bool hasNonTrivialDestructor() const {
1489
1.89M
    return !(data().HasTrivialSpecialMembers & SMF_Destructor);
1490
1.89M
  }
1491
1492
99
  bool hasNonTrivialDestructorForCall() const {
1493
99
    return !(data().HasTrivialSpecialMembersForCall & SMF_Destructor);
1494
99
  }
1495
1496
16
  void setHasTrivialSpecialMemberForCall() {
1497
16
    data().HasTrivialSpecialMembersForCall =
1498
16
        (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor);
1499
16
  }
1500
1501
  /// Determine whether declaring a const variable with this type is ok
1502
  /// per core issue 253.
1503
996k
  bool allowConstDefaultInit() const {
1504
996k
    return !data().HasUninitializedFields ||
1505
996k
           
!(358k
data().HasDefaultedDefaultConstructor358k
||
1506
358k
             
needsImplicitDefaultConstructor()347k
);
1507
996k
  }
1508
1509
  /// Determine whether this class has a destructor which has no
1510
  /// semantic effect.
1511
  ///
1512
  /// Any such destructor will be trivial, public, defaulted and not deleted,
1513
  /// and will call only irrelevant destructors.
1514
1.33M
  bool hasIrrelevantDestructor() const {
1515
1.33M
    return data().HasIrrelevantDestructor;
1516
1.33M
  }
1517
1518
  /// Determine whether this class has a non-literal or/ volatile type
1519
  /// non-static data member or base class.
1520
1.86M
  bool hasNonLiteralTypeFieldsOrBases() const {
1521
1.86M
    return data().HasNonLiteralTypeFieldsOrBases;
1522
1.86M
  }
1523
1524
  /// Determine whether this class has a using-declaration that names
1525
  /// a user-declared base class constructor.
1526
3.84M
  bool hasInheritedConstructor() const {
1527
3.84M
    return data().HasInheritedConstructor;
1528
3.84M
  }
1529
1530
  /// Determine whether this class has a using-declaration that names
1531
  /// a base class assignment operator.
1532
2.57M
  bool hasInheritedAssignment() const {
1533
2.57M
    return data().HasInheritedAssignment;
1534
2.57M
  }
1535
1536
  /// Determine whether this class is considered trivially copyable per
1537
  /// (C++11 [class]p6).
1538
  bool isTriviallyCopyable() const;
1539
1540
  /// Determine whether this class is considered trivial.
1541
  ///
1542
  /// C++11 [class]p6:
1543
  ///    "A trivial class is a class that has a trivial default constructor and
1544
  ///    is trivially copiable."
1545
175k
  bool isTrivial() const {
1546
175k
    return isTriviallyCopyable() && 
hasTrivialDefaultConstructor()101k
;
1547
175k
  }
1548
1549
  /// Determine whether this class is a literal type.
1550
  ///
1551
  /// C++11 [basic.types]p10:
1552
  ///   A class type that has all the following properties:
1553
  ///     - it has a trivial destructor
1554
  ///     - every constructor call and full-expression in the
1555
  ///       brace-or-equal-intializers for non-static data members (if any) is
1556
  ///       a constant expression.
1557
  ///     - it is an aggregate type or has at least one constexpr constructor
1558
  ///       or constructor template that is not a copy or move constructor, and
1559
  ///     - all of its non-static data members and base classes are of literal
1560
  ///       types
1561
  ///
1562
  /// We resolve DR1361 by ignoring the second bullet. We resolve DR1452 by
1563
  /// treating types with trivial default constructors as literal types.
1564
  ///
1565
  /// Only in C++17 and beyond, are lambdas literal types.
1566
1.40M
  bool isLiteral() const {
1567
1.40M
    return hasTrivialDestructor() &&
1568
1.40M
           
(1.22M
!isLambda()1.22M
||
getASTContext().getLangOpts().CPlusPlus173.87k
) &&
1569
1.40M
           
!hasNonLiteralTypeFieldsOrBases()1.22M
&&
1570
1.40M
           
(1.12M
isAggregate()1.12M
||
isLambda()304k
||
1571
1.12M
            
hasConstexprNonCopyMoveConstructor()303k
||
1572
1.12M
            
hasTrivialDefaultConstructor()143k
);
1573
1.40M
  }
1574
1575
  /// If this record is an instantiation of a member class,
1576
  /// retrieves the member class from which it was instantiated.
1577
  ///
1578
  /// This routine will return non-null for (non-templated) member
1579
  /// classes of class templates. For example, given:
1580
  ///
1581
  /// \code
1582
  /// template<typename T>
1583
  /// struct X {
1584
  ///   struct A { };
1585
  /// };
1586
  /// \endcode
1587
  ///
1588
  /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
1589
  /// whose parent is the class template specialization X<int>. For
1590
  /// this declaration, getInstantiatedFromMemberClass() will return
1591
  /// the CXXRecordDecl X<T>::A. When a complete definition of
1592
  /// X<int>::A is required, it will be instantiated from the
1593
  /// declaration returned by getInstantiatedFromMemberClass().
1594
  CXXRecordDecl *getInstantiatedFromMemberClass() const;
1595
1596
  /// If this class is an instantiation of a member class of a
1597
  /// class template specialization, retrieves the member specialization
1598
  /// information.
1599
  MemberSpecializationInfo *getMemberSpecializationInfo() const;
1600
1601
  /// Specify that this record is an instantiation of the
1602
  /// member class \p RD.
1603
  void setInstantiationOfMemberClass(CXXRecordDecl *RD,
1604
                                     TemplateSpecializationKind TSK);
1605
1606
  /// Retrieves the class template that is described by this
1607
  /// class declaration.
1608
  ///
1609
  /// Every class template is represented as a ClassTemplateDecl and a
1610
  /// CXXRecordDecl. The former contains template properties (such as
1611
  /// the template parameter lists) while the latter contains the
1612
  /// actual description of the template's
1613
  /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
1614
  /// CXXRecordDecl that from a ClassTemplateDecl, while
1615
  /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
1616
  /// a CXXRecordDecl.
1617
  ClassTemplateDecl *getDescribedClassTemplate() const;
1618
1619
  void setDescribedClassTemplate(ClassTemplateDecl *Template);
1620
1621
  /// Determine whether this particular class is a specialization or
1622
  /// instantiation of a class template or member class of a class template,
1623
  /// and how it was instantiated or specialized.
1624
  TemplateSpecializationKind getTemplateSpecializationKind() const;
1625
1626
  /// Set the kind of specialization or template instantiation this is.
1627
  void setTemplateSpecializationKind(TemplateSpecializationKind TSK);
1628
1629
  /// Retrieve the record declaration from which this record could be
1630
  /// instantiated. Returns null if this class is not a template instantiation.
1631
  const CXXRecordDecl *getTemplateInstantiationPattern() const;
1632
1633
29.2k
  CXXRecordDecl *getTemplateInstantiationPattern() {
1634
29.2k
    return const_cast<CXXRecordDecl *>(const_cast<const CXXRecordDecl *>(this)
1635
29.2k
                                           ->getTemplateInstantiationPattern());
1636
29.2k
  }
1637
1638
  /// Returns the destructor decl for this class.
1639
  CXXDestructorDecl *getDestructor() const;
1640
1641
  /// Returns true if the class destructor, or any implicitly invoked
1642
  /// destructors are marked noreturn.
1643
  bool isAnyDestructorNoReturn() const;
1644
1645
  /// If the class is a local class [class.local], returns
1646
  /// the enclosing function declaration.
1647
7.41M
  const FunctionDecl *isLocalClass() const {
1648
7.41M
    if (const auto *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
1649
1.31M
      return RD->isLocalClass();
1650
6.09M
1651
6.09M
    return dyn_cast<FunctionDecl>(getDeclContext());
1652
6.09M
  }
1653
1654
1.75M
  FunctionDecl *isLocalClass() {
1655
1.75M
    return const_cast<FunctionDecl*>(
1656
1.75M
        const_cast<const CXXRecordDecl*>(this)->isLocalClass());
1657
1.75M
  }
1658
1659
  /// Determine whether this dependent class is a current instantiation,
1660
  /// when viewed from within the given context.
1661
  bool isCurrentInstantiation(const DeclContext *CurContext) const;
1662
1663
  /// Determine whether this class is derived from the class \p Base.
1664
  ///
1665
  /// This routine only determines whether this class is derived from \p Base,
1666
  /// but does not account for factors that may make a Derived -> Base class
1667
  /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1668
  /// base class subobjects.
1669
  ///
1670
  /// \param Base the base class we are searching for.
1671
  ///
1672
  /// \returns true if this class is derived from Base, false otherwise.
1673
  bool isDerivedFrom(const CXXRecordDecl *Base) const;
1674
1675
  /// Determine whether this class is derived from the type \p Base.
1676
  ///
1677
  /// This routine only determines whether this class is derived from \p Base,
1678
  /// but does not account for factors that may make a Derived -> Base class
1679
  /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1680
  /// base class subobjects.
1681
  ///
1682
  /// \param Base the base class we are searching for.
1683
  ///
1684
  /// \param Paths will contain the paths taken from the current class to the
1685
  /// given \p Base class.
1686
  ///
1687
  /// \returns true if this class is derived from \p Base, false otherwise.
1688
  ///
1689
  /// \todo add a separate parameter to configure IsDerivedFrom, rather than
1690
  /// tangling input and output in \p Paths
1691
  bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const;
1692
1693
  /// Determine whether this class is virtually derived from
1694
  /// the class \p Base.
1695
  ///
1696
  /// This routine only determines whether this class is virtually
1697
  /// derived from \p Base, but does not account for factors that may
1698
  /// make a Derived -> Base class ill-formed, such as
1699
  /// private/protected inheritance or multiple, ambiguous base class
1700
  /// subobjects.
1701
  ///
1702
  /// \param Base the base class we are searching for.
1703
  ///
1704
  /// \returns true if this class is virtually derived from Base,
1705
  /// false otherwise.
1706
  bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const;
1707
1708
  /// Determine whether this class is provably not derived from
1709
  /// the type \p Base.
1710
  bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
1711
1712
  /// Function type used by forallBases() as a callback.
1713
  ///
1714
  /// \param BaseDefinition the definition of the base class
1715
  ///
1716
  /// \returns true if this base matched the search criteria
1717
  using ForallBasesCallback =
1718
      llvm::function_ref<bool(const CXXRecordDecl *BaseDefinition)>;
1719
1720
  /// Determines if the given callback holds for all the direct
1721
  /// or indirect base classes of this type.
1722
  ///
1723
  /// The class itself does not count as a base class.  This routine
1724
  /// returns false if the class has non-computable base classes.
1725
  ///
1726
  /// \param BaseMatches Callback invoked for each (direct or indirect) base
1727
  /// class of this type, or if \p AllowShortCircuit is true then until a call
1728
  /// returns false.
1729
  ///
1730
  /// \param AllowShortCircuit if false, forces the callback to be called
1731
  /// for every base class, even if a dependent or non-matching base was
1732
  /// found.
1733
  bool forallBases(ForallBasesCallback BaseMatches,
1734
                   bool AllowShortCircuit = true) const;
1735
1736
  /// Function type used by lookupInBases() to determine whether a
1737
  /// specific base class subobject matches the lookup criteria.
1738
  ///
1739
  /// \param Specifier the base-class specifier that describes the inheritance
1740
  /// from the base class we are trying to match.
1741
  ///
1742
  /// \param Path the current path, from the most-derived class down to the
1743
  /// base named by the \p Specifier.
1744
  ///
1745
  /// \returns true if this base matched the search criteria, false otherwise.
1746
  using BaseMatchesCallback =
1747
      llvm::function_ref<bool(const CXXBaseSpecifier *Specifier,
1748
                              CXXBasePath &Path)>;
1749
1750
  /// Look for entities within the base classes of this C++ class,
1751
  /// transitively searching all base class subobjects.
1752
  ///
1753
  /// This routine uses the callback function \p BaseMatches to find base
1754
  /// classes meeting some search criteria, walking all base class subobjects
1755
  /// and populating the given \p Paths structure with the paths through the
1756
  /// inheritance hierarchy that resulted in a match. On a successful search,
1757
  /// the \p Paths structure can be queried to retrieve the matching paths and
1758
  /// to determine if there were any ambiguities.
1759
  ///
1760
  /// \param BaseMatches callback function used to determine whether a given
1761
  /// base matches the user-defined search criteria.
1762
  ///
1763
  /// \param Paths used to record the paths from this class to its base class
1764
  /// subobjects that match the search criteria.
1765
  ///
1766
  /// \param LookupInDependent can be set to true to extend the search to
1767
  /// dependent base classes.
1768
  ///
1769
  /// \returns true if there exists any path from this class to a base class
1770
  /// subobject that matches the search criteria.
1771
  bool lookupInBases(BaseMatchesCallback BaseMatches, CXXBasePaths &Paths,
1772
                     bool LookupInDependent = false) const;
1773
1774
  /// Base-class lookup callback that determines whether the given
1775
  /// base class specifier refers to a specific class declaration.
1776
  ///
1777
  /// This callback can be used with \c lookupInBases() to determine whether
1778
  /// a given derived class has is a base class subobject of a particular type.
1779
  /// The base record pointer should refer to the canonical CXXRecordDecl of the
1780
  /// base class that we are searching for.
1781
  static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
1782
                            CXXBasePath &Path, const CXXRecordDecl *BaseRecord);
1783
1784
  /// Base-class lookup callback that determines whether the
1785
  /// given base class specifier refers to a specific class
1786
  /// declaration and describes virtual derivation.
1787
  ///
1788
  /// This callback can be used with \c lookupInBases() to determine
1789
  /// whether a given derived class has is a virtual base class
1790
  /// subobject of a particular type.  The base record pointer should
1791
  /// refer to the canonical CXXRecordDecl of the base class that we
1792
  /// are searching for.
1793
  static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
1794
                                   CXXBasePath &Path,
1795
                                   const CXXRecordDecl *BaseRecord);
1796
1797
  /// Base-class lookup callback that determines whether there exists
1798
  /// a tag with the given name.
1799
  ///
1800
  /// This callback can be used with \c lookupInBases() to find tag members
1801
  /// of the given name within a C++ class hierarchy.
1802
  static bool FindTagMember(const CXXBaseSpecifier *Specifier,
1803
                            CXXBasePath &Path, DeclarationName Name);
1804
1805
  /// Base-class lookup callback that determines whether there exists
1806
  /// a member with the given name.
1807
  ///
1808
  /// This callback can be used with \c lookupInBases() to find members
1809
  /// of the given name within a C++ class hierarchy.
1810
  static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
1811
                                 CXXBasePath &Path, DeclarationName Name);
1812
1813
  /// Base-class lookup callback that determines whether there exists
1814
  /// a member with the given name.
1815
  ///
1816
  /// This callback can be used with \c lookupInBases() to find members
1817
  /// of the given name within a C++ class hierarchy, including dependent
1818
  /// classes.
1819
  static bool
1820
  FindOrdinaryMemberInDependentClasses(const CXXBaseSpecifier *Specifier,
1821
                                       CXXBasePath &Path, DeclarationName Name);
1822
1823
  /// Base-class lookup callback that determines whether there exists
1824
  /// an OpenMP declare reduction member with the given name.
1825
  ///
1826
  /// This callback can be used with \c lookupInBases() to find members
1827
  /// of the given name within a C++ class hierarchy.
1828
  static bool FindOMPReductionMember(const CXXBaseSpecifier *Specifier,
1829
                                     CXXBasePath &Path, DeclarationName Name);
1830
1831
  /// Base-class lookup callback that determines whether there exists
1832
  /// a member with the given name that can be used in a nested-name-specifier.
1833
  ///
1834
  /// This callback can be used with \c lookupInBases() to find members of
1835
  /// the given name within a C++ class hierarchy that can occur within
1836
  /// nested-name-specifiers.
1837
  static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier,
1838
                                            CXXBasePath &Path,
1839
                                            DeclarationName Name);
1840
1841
  /// Retrieve the final overriders for each virtual member
1842
  /// function in the class hierarchy where this class is the
1843
  /// most-derived class in the class hierarchy.
1844
  void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const;
1845
1846
  /// Get the indirect primary bases for this class.
1847
  void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const;
1848
1849
  /// Performs an imprecise lookup of a dependent name in this class.
1850
  ///
1851
  /// This function does not follow strict semantic rules and should be used
1852
  /// only when lookup rules can be relaxed, e.g. indexing.
1853
  std::vector<const NamedDecl *>
1854
  lookupDependentName(const DeclarationName &Name,
1855
                      llvm::function_ref<bool(const NamedDecl *ND)> Filter);
1856
1857
  /// Renders and displays an inheritance diagram
1858
  /// for this C++ class and all of its base classes (transitively) using
1859
  /// GraphViz.
1860
  void viewInheritance(ASTContext& Context) const;
1861
1862
  /// Calculates the access of a decl that is reached
1863
  /// along a path.
1864
  static AccessSpecifier MergeAccess(AccessSpecifier PathAccess,
1865
2.35M
                                     AccessSpecifier DeclAccess) {
1866
2.35M
    assert(DeclAccess != AS_none);
1867
2.35M
    if (DeclAccess == AS_private) 
return AS_none70.1k
;
1868
2.28M
    return (PathAccess > DeclAccess ? 
PathAccess212k
:
DeclAccess2.07M
);
1869
2.28M
  }
1870
1871
  /// Indicates that the declaration of a defaulted or deleted special
1872
  /// member function is now complete.
1873
  void finishedDefaultedOrDeletedMember(CXXMethodDecl *MD);
1874
1875
  void setTrivialForCallFlags(CXXMethodDecl *MD);
1876
1877
  /// Indicates that the definition of this class is now complete.
1878
  void completeDefinition() override;
1879
1880
  /// Indicates that the definition of this class is now complete,
1881
  /// and provides a final overrider map to help determine
1882
  ///
1883
  /// \param FinalOverriders The final overrider map for this class, which can
1884
  /// be provided as an optimization for abstract-class checking. If NULL,
1885
  /// final overriders will be computed if they are needed to complete the
1886
  /// definition.
1887
  void completeDefinition(CXXFinalOverriderMap *FinalOverriders);
1888
1889
  /// Determine whether this class may end up being abstract, even though
1890
  /// it is not yet known to be abstract.
1891
  ///
1892
  /// \returns true if this class is not known to be abstract but has any
1893
  /// base classes that are abstract. In this case, \c completeDefinition()
1894
  /// will need to compute final overriders to determine whether the class is
1895
  /// actually abstract.
1896
  bool mayBeAbstract() const;
1897
1898
  /// If this is the closure type of a lambda expression, retrieve the
1899
  /// number to be used for name mangling in the Itanium C++ ABI.
1900
  ///
1901
  /// Zero indicates that this closure type has internal linkage, so the
1902
  /// mangling number does not matter, while a non-zero value indicates which
1903
  /// lambda expression this is in this particular context.
1904
16.0k
  unsigned getLambdaManglingNumber() const {
1905
16.0k
    assert(isLambda() && "Not a lambda closure type!");
1906
16.0k
    return getLambdaData().ManglingNumber;
1907
16.0k
  }
1908
1909
  /// Retrieve the declaration that provides additional context for a
1910
  /// lambda, when the normal declaration context is not specific enough.
1911
  ///
1912
  /// Certain contexts (default arguments of in-class function parameters and
1913
  /// the initializers of data members) have separate name mangling rules for
1914
  /// lambdas within the Itanium C++ ABI. For these cases, this routine provides
1915
  /// the declaration in which the lambda occurs, e.g., the function parameter
1916
  /// or the non-static data member. Otherwise, it returns NULL to imply that
1917
  /// the declaration context suffices.
1918
  Decl *getLambdaContextDecl() const;
1919
1920
  /// Set the mangling number and context declaration for a lambda
1921
  /// class.
1922
3.60k
  void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl) {
1923
3.60k
    getLambdaData().ManglingNumber = ManglingNumber;
1924
3.60k
    getLambdaData().ContextDecl = ContextDecl;
1925
3.60k
  }
1926
1927
  /// Returns the inheritance model used for this record.
1928
  MSInheritanceAttr::Spelling getMSInheritanceModel() const;
1929
1930
  /// Calculate what the inheritance model would be for this class.
1931
  MSInheritanceAttr::Spelling calculateInheritanceModel() const;
1932
1933
  /// In the Microsoft C++ ABI, use zero for the field offset of a null data
1934
  /// member pointer if we can guarantee that zero is not a valid field offset,
1935
  /// or if the member pointer has multiple fields.  Polymorphic classes have a
1936
  /// vfptr at offset zero, so we can use zero for null.  If there are multiple
1937
  /// fields, we can use zero even if it is a valid field offset because
1938
  /// null-ness testing will check the other fields.
1939
105
  bool nullFieldOffsetIsZero() const {
1940
105
    return !MSInheritanceAttr::hasOnlyOneField(/*IsMemberFunction=*/false,
1941
105
                                               getMSInheritanceModel()) ||
1942
105
           
(67
hasDefinition()67
&&
isPolymorphic()65
);
1943
105
  }
1944
1945
  /// Controls when vtordisps will be emitted if this record is used as a
1946
  /// virtual base.
1947
  MSVtorDispAttr::Mode getMSVtorDispMode() const;
1948
1949
  /// Determine whether this lambda expression was known to be dependent
1950
  /// at the time it was created, even if its context does not appear to be
1951
  /// dependent.
1952
  ///
1953
  /// This flag is a workaround for an issue with parsing, where default
1954
  /// arguments are parsed before their enclosing function declarations have
1955
  /// been created. This means that any lambda expressions within those
1956
  /// default arguments will have as their DeclContext the context enclosing
1957
  /// the function declaration, which may be non-dependent even when the
1958
  /// function declaration itself is dependent. This flag indicates when we
1959
  /// know that the lambda is dependent despite that.
1960
40.3M
  bool isDependentLambda() const {
1961
40.3M
    return isLambda() && 
getLambdaData().Dependent165k
;
1962
40.3M
  }
1963
1964
1.28k
  TypeSourceInfo *getLambdaTypeInfo() const {
1965
1.28k
    return getLambdaData().MethodTyInfo;
1966
1.28k
  }
1967
1968
  // Determine whether this type is an Interface Like type for
1969
  // __interface inheritance purposes.
1970
  bool isInterfaceLike() const;
1971
1972
195M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1973
424M
  static bool classofKind(Kind K) {
1974
424M
    return K >= firstCXXRecord && 
K <= lastCXXRecord320M
;
1975
424M
  }
1976
};
1977
1978
/// Represents a C++ deduction guide declaration.
1979
///
1980
/// \code
1981
/// template<typename T> struct A { A(); A(T); };
1982
/// A() -> A<int>;
1983
/// \endcode
1984
///
1985
/// In this example, there will be an explicit deduction guide from the
1986
/// second line, and implicit deduction guide templates synthesized from
1987
/// the constructors of \c A.
1988
class CXXDeductionGuideDecl : public FunctionDecl {
1989
  void anchor() override;
1990
1991
private:
1992
  CXXDeductionGuideDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1993
                        bool IsExplicit, const DeclarationNameInfo &NameInfo,
1994
                        QualType T, TypeSourceInfo *TInfo,
1995
                        SourceLocation EndLocation)
1996
      : FunctionDecl(CXXDeductionGuide, C, DC, StartLoc, NameInfo, T, TInfo,
1997
434
                     SC_None, false, false) {
1998
434
    if (EndLocation.isValid())
1999
431
      setRangeEnd(EndLocation);
2000
434
    setExplicitSpecified(IsExplicit);
2001
434
    setIsCopyDeductionCandidate(false);
2002
434
  }
2003
2004
public:
2005
  friend class ASTDeclReader;
2006
  friend class ASTDeclWriter;
2007
2008
  static CXXDeductionGuideDecl *Create(ASTContext &C, DeclContext *DC,
2009
                                       SourceLocation StartLoc, bool IsExplicit,
2010
                                       const DeclarationNameInfo &NameInfo,
2011
                                       QualType T, TypeSourceInfo *TInfo,
2012
                                       SourceLocation EndLocation);
2013
2014
  static CXXDeductionGuideDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2015
2016
  /// Whether this deduction guide is explicit.
2017
333
  bool isExplicit() const { return isExplicitSpecified(); }
2018
2019
  /// Get the template for which this guide performs deduction.
2020
518
  TemplateDecl *getDeducedTemplate() const {
2021
518
    return getDeclName().getCXXDeductionGuideTemplate();
2022
518
  }
2023
2024
533
  void setIsCopyDeductionCandidate(bool isCDC = true) {
2025
533
    FunctionDeclBits.IsCopyDeductionCandidate = isCDC;
2026
533
  }
2027
2028
131
  bool isCopyDeductionCandidate() const {
2029
131
    return FunctionDeclBits.IsCopyDeductionCandidate;
2030
131
  }
2031
2032
  // Implement isa/cast/dyncast/etc.
2033
11.0M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2034
11.0M
  static bool classofKind(Kind K) { return K == CXXDeductionGuide; }
2035
};
2036
2037
/// Represents a static or instance method of a struct/union/class.
2038
///
2039
/// In the terminology of the C++ Standard, these are the (static and
2040
/// non-static) member functions, whether virtual or not.
2041
class CXXMethodDecl : public FunctionDecl {
2042
  void anchor() override;
2043
2044
protected:
2045
  CXXMethodDecl(Kind DK, ASTContext &C, CXXRecordDecl *RD,
2046
                SourceLocation StartLoc, const DeclarationNameInfo &NameInfo,
2047
                QualType T, TypeSourceInfo *TInfo,
2048
                StorageClass SC, bool isInline,
2049
                bool isConstexpr, SourceLocation EndLocation)
2050
    : FunctionDecl(DK, C, RD, StartLoc, NameInfo, T, TInfo,
2051
3.83M
                   SC, isInline, isConstexpr) {
2052
3.83M
    if (EndLocation.isValid())
2053
1.18M
      setRangeEnd(EndLocation);
2054
3.83M
  }
2055
2056
public:
2057
  static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2058
                               SourceLocation StartLoc,
2059
                               const DeclarationNameInfo &NameInfo,
2060
                               QualType T, TypeSourceInfo *TInfo,
2061
                               StorageClass SC,
2062
                               bool isInline,
2063
                               bool isConstexpr,
2064
                               SourceLocation EndLocation);
2065
2066
  static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2067
2068
  bool isStatic() const;
2069
9.85M
  bool isInstance() const { return !isStatic(); }
2070
2071
  /// Returns true if the given operator is implicitly static in a record
2072
  /// context.
2073
25.4M
  static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK) {
2074
25.4M
    // [class.free]p1:
2075
25.4M
    // Any allocation function for a class T is a static member
2076
25.4M
    // (even if not explicitly declared static).
2077
25.4M
    // [class.free]p6 Any deallocation function for a class X is a static member
2078
25.4M
    // (even if not explicitly declared static).
2079
25.4M
    return OOK == OO_New || 
OOK == OO_Array_New25.4M
||
OOK == OO_Delete25.4M
||
2080
25.4M
           
OOK == OO_Array_Delete25.4M
;
2081
25.4M
  }
2082
2083
24.4k
  bool isConst() const { return getType()->castAs<FunctionType>()->isConst(); }
2084
10.6k
  bool isVolatile() const { return getType()->castAs<FunctionType>()->isVolatile(); }
2085
2086
9.40M
  bool isVirtual() const {
2087
9.40M
    CXXMethodDecl *CD = const_cast<CXXMethodDecl*>(this)->getCanonicalDecl();
2088
9.40M
2089
9.40M
    // Member function is virtual if it is marked explicitly so, or if it is
2090
9.40M
    // declared in __interface -- then it is automatically pure virtual.
2091
9.40M
    if (CD->isVirtualAsWritten() || 
CD->isPure()8.64M
)
2092
769k
      return true;
2093
8.63M
2094
8.63M
    return CD->size_overridden_methods() != 0;
2095
8.63M
  }
2096
2097
  /// If it's possible to devirtualize a call to this method, return the called
2098
  /// function. Otherwise, return null.
2099
2100
  /// \param Base The object on which this virtual function is called.
2101
  /// \param IsAppleKext True if we are compiling for Apple kext.
2102
  CXXMethodDecl *getDevirtualizedMethod(const Expr *Base, bool IsAppleKext);
2103
2104
  const CXXMethodDecl *getDevirtualizedMethod(const Expr *Base,
2105
13.2k
                                              bool IsAppleKext) const {
2106
13.2k
    return const_cast<CXXMethodDecl *>(this)->getDevirtualizedMethod(
2107
13.2k
        Base, IsAppleKext);
2108
13.2k
  }
2109
2110
  /// Determine whether this is a usual deallocation function (C++
2111
  /// [basic.stc.dynamic.deallocation]p2), which is an overloaded delete or
2112
  /// delete[] operator with a particular signature. Populates \p PreventedBy
2113
  /// with the declarations of the functions of the same kind if they were the
2114
  /// reason for this function returning false. This is used by
2115
  /// Sema::isUsualDeallocationFunction to reconsider the answer based on the
2116
  /// context.
2117
  bool isUsualDeallocationFunction(
2118
      SmallVectorImpl<const FunctionDecl *> &PreventedBy) const;
2119
2120
  /// Determine whether this is a copy-assignment operator, regardless
2121
  /// of whether it was declared implicitly or explicitly.
2122
  bool isCopyAssignmentOperator() const;
2123
2124
  /// Determine whether this is a move assignment operator.
2125
  bool isMoveAssignmentOperator() const;
2126
2127
87.4M
  CXXMethodDecl *getCanonicalDecl() override {
2128
87.4M
    return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
2129
87.4M
  }
2130
46.4M
  const CXXMethodDecl *getCanonicalDecl() const {
2131
46.4M
    return const_cast<CXXMethodDecl*>(this)->getCanonicalDecl();
2132
46.4M
  }
2133
2134
17.5k
  CXXMethodDecl *getMostRecentDecl() {
2135
17.5k
    return cast<CXXMethodDecl>(
2136
17.5k
            static_cast<FunctionDecl *>(this)->getMostRecentDecl());
2137
17.5k
  }
2138
0
  const CXXMethodDecl *getMostRecentDecl() const {
2139
0
    return const_cast<CXXMethodDecl*>(this)->getMostRecentDecl();
2140
0
  }
2141
2142
  /// True if this method is user-declared and was not
2143
  /// deleted or defaulted on its first declaration.
2144
8.42M
  bool isUserProvided() const {
2145
8.42M
    auto *DeclAsWritten = this;
2146
8.42M
    if (auto *Pattern = getTemplateInstantiationPattern())
2147
3.52M
      DeclAsWritten = cast<CXXMethodDecl>(Pattern);
2148
8.42M
    return !(DeclAsWritten->isDeleted() ||
2149
8.42M
             
DeclAsWritten->getCanonicalDecl()->isDefaulted()8.17M
);
2150
8.42M
  }
2151
2152
  void addOverriddenMethod(const CXXMethodDecl *MD);
2153
2154
  using method_iterator = const CXXMethodDecl *const *;
2155
2156
  method_iterator begin_overridden_methods() const;
2157
  method_iterator end_overridden_methods() const;
2158
  unsigned size_overridden_methods() const;
2159
2160
  using overridden_method_range= ASTContext::overridden_method_range;
2161
2162
  overridden_method_range overridden_methods() const;
2163
2164
  /// Returns the parent of this method declaration, which
2165
  /// is the class in which this method is defined.
2166
37.9M
  const CXXRecordDecl *getParent() const {
2167
37.9M
    return cast<CXXRecordDecl>(FunctionDecl::getParent());
2168
37.9M
  }
2169
2170
  /// Returns the parent of this method declaration, which
2171
  /// is the class in which this method is defined.
2172
14.7M
  CXXRecordDecl *getParent() {
2173
14.7M
    return const_cast<CXXRecordDecl *>(
2174
14.7M
             cast<CXXRecordDecl>(FunctionDecl::getParent()));
2175
14.7M
  }
2176
2177
  /// Returns the type of the \c this pointer.
2178
  ///
2179
  /// Should only be called for instance (i.e., non-static) methods. Note
2180
  /// that for the call operator of a lambda closure type, this returns the
2181
  /// desugared 'this' type (a pointer to the closure type), not the captured
2182
  /// 'this' type.
2183
  QualType getThisType(ASTContext &C) const;
2184
2185
12.0M
  unsigned getTypeQualifiers() const {
2186
12.0M
    return getType()->getAs<FunctionProtoType>()->getTypeQuals();
2187
12.0M
  }
2188
2189
  /// Retrieve the ref-qualifier associated with this method.
2190
  ///
2191
  /// In the following example, \c f() has an lvalue ref-qualifier, \c g()
2192
  /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier.
2193
  /// @code
2194
  /// struct X {
2195
  ///   void f() &;
2196
  ///   void g() &&;
2197
  ///   void h();
2198
  /// };
2199
  /// @endcode
2200
8.61M
  RefQualifierKind getRefQualifier() const {
2201
8.61M
    return getType()->getAs<FunctionProtoType>()->getRefQualifier();
2202
8.61M
  }
2203
2204
  bool hasInlineBody() const;
2205
2206
  /// Determine whether this is a lambda closure type's static member
2207
  /// function that is used for the result of the lambda's conversion to
2208
  /// function pointer (for a lambda with no captures).
2209
  ///
2210
  /// The function itself, if used, will have a placeholder body that will be
2211
  /// supplied by IR generation to either forward to the function call operator
2212
  /// or clone the function call operator.
2213
  bool isLambdaStaticInvoker() const;
2214
2215
  /// Find the method in \p RD that corresponds to this one.
2216
  ///
2217
  /// Find if \p RD or one of the classes it inherits from override this method.
2218
  /// If so, return it. \p RD is assumed to be a subclass of the class defining
2219
  /// this method (or be the class itself), unless \p MayBeBase is set to true.
2220
  CXXMethodDecl *
2221
  getCorrespondingMethodInClass(const CXXRecordDecl *RD,
2222
                                bool MayBeBase = false);
2223
2224
  const CXXMethodDecl *
2225
  getCorrespondingMethodInClass(const CXXRecordDecl *RD,
2226
547
                                bool MayBeBase = false) const {
2227
547
    return const_cast<CXXMethodDecl *>(this)
2228
547
              ->getCorrespondingMethodInClass(RD, MayBeBase);
2229
547
  }
2230
2231
  // Implement isa/cast/dyncast/etc.
2232
217M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2233
307M
  static bool classofKind(Kind K) {
2234
307M
    return K >= firstCXXMethod && 
K <= lastCXXMethod159M
;
2235
307M
  }
2236
};
2237
2238
/// Represents a C++ base or member initializer.
2239
///
2240
/// This is part of a constructor initializer that
2241
/// initializes one non-static member variable or one base class. For
2242
/// example, in the following, both 'A(a)' and 'f(3.14159)' are member
2243
/// initializers:
2244
///
2245
/// \code
2246
/// class A { };
2247
/// class B : public A {
2248
///   float f;
2249
/// public:
2250
///   B(A& a) : A(a), f(3.14159) { }
2251
/// };
2252
/// \endcode
2253
class CXXCtorInitializer final {
2254
  /// Either the base class name/delegating constructor type (stored as
2255
  /// a TypeSourceInfo*), an normal field (FieldDecl), or an anonymous field
2256
  /// (IndirectFieldDecl*) being initialized.
2257
  llvm::PointerUnion3<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *>
2258
    Initializee;
2259
2260
  /// The source location for the field name or, for a base initializer
2261
  /// pack expansion, the location of the ellipsis.
2262
  ///
2263
  /// In the case of a delegating
2264
  /// constructor, it will still include the type's source location as the
2265
  /// Initializee points to the CXXConstructorDecl (to allow loop detection).
2266
  SourceLocation MemberOrEllipsisLocation;
2267
2268
  /// The argument used to initialize the base or member, which may
2269
  /// end up constructing an object (when multiple arguments are involved).
2270
  Stmt *Init;
2271
2272
  /// Location of the left paren of the ctor-initializer.
2273
  SourceLocation LParenLoc;
2274
2275
  /// Location of the right paren of the ctor-initializer.
2276
  SourceLocation RParenLoc;
2277
2278
  /// If the initializee is a type, whether that type makes this
2279
  /// a delegating initialization.
2280
  unsigned IsDelegating : 1;
2281
2282
  /// If the initializer is a base initializer, this keeps track
2283
  /// of whether the base is virtual or not.
2284
  unsigned IsVirtual : 1;
2285
2286
  /// Whether or not the initializer is explicitly written
2287
  /// in the sources.
2288
  unsigned IsWritten : 1;
2289
2290
  /// If IsWritten is true, then this number keeps track of the textual order
2291
  /// of this initializer in the original sources, counting from 0.
2292
  unsigned SourceOrder : 13;
2293
2294
public:
2295
  /// Creates a new base-class initializer.
2296
  explicit
2297
  CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual,
2298
                     SourceLocation L, Expr *Init, SourceLocation R,
2299
                     SourceLocation EllipsisLoc);
2300
2301
  /// Creates a new member initializer.
2302
  explicit
2303
  CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
2304
                     SourceLocation MemberLoc, SourceLocation L, Expr *Init,
2305
                     SourceLocation R);
2306
2307
  /// Creates a new anonymous field initializer.
2308
  explicit
2309
  CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member,
2310
                     SourceLocation MemberLoc, SourceLocation L, Expr *Init,
2311
                     SourceLocation R);
2312
2313
  /// Creates a new delegating initializer.
2314
  explicit
2315
  CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo,
2316
                     SourceLocation L, Expr *Init, SourceLocation R);
2317
2318
  /// Determine whether this initializer is initializing a base class.
2319
524k
  bool isBaseInitializer() const {
2320
524k
    return Initializee.is<TypeSourceInfo*>() && 
!IsDelegating214k
;
2321
524k
  }
2322
2323
  /// Determine whether this initializer is initializing a non-static
2324
  /// data member.
2325
1.95M
  bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); }
2326
2327
849k
  bool isAnyMemberInitializer() const {
2328
849k
    return isMemberInitializer() || 
isIndirectMemberInitializer()127k
;
2329
849k
  }
2330
2331
297k
  bool isIndirectMemberInitializer() const {
2332
297k
    return Initializee.is<IndirectFieldDecl*>();
2333
297k
  }
2334
2335
  /// Determine whether this initializer is an implicit initializer
2336
  /// generated for a field with an initializer defined on the member
2337
  /// declaration.
2338
  ///
2339
  /// In-class member initializers (also known as "non-static data member
2340
  /// initializations", NSDMIs) were introduced in C++11.
2341
183k
  bool isInClassMemberInitializer() const {
2342
183k
    return Init->getStmtClass() == Stmt::CXXDefaultInitExprClass;
2343
183k
  }
2344
2345
  /// Determine whether this initializer is creating a delegating
2346
  /// constructor.
2347
68.0k
  bool isDelegatingInitializer() const {
2348
68.0k
    return Initializee.is<TypeSourceInfo*>() && 
IsDelegating16.3k
;
2349
68.0k
  }
2350
2351
  /// Determine whether this initializer is a pack expansion.
2352
43.1k
  bool isPackExpansion() const {
2353
43.1k
    return isBaseInitializer() && 
MemberOrEllipsisLocation.isValid()8.98k
;
2354
43.1k
  }
2355
2356
  // For a pack expansion, returns the location of the ellipsis.
2357
567
  SourceLocation getEllipsisLoc() const {
2358
567
    assert(isPackExpansion() && "Initializer is not a pack expansion");
2359
567
    return MemberOrEllipsisLocation;
2360
567
  }
2361
2362
  /// If this is a base class initializer, returns the type of the
2363
  /// base class with location information. Otherwise, returns an NULL
2364
  /// type location.
2365
  TypeLoc getBaseClassLoc() const;
2366
2367
  /// If this is a base class initializer, returns the type of the base class.
2368
  /// Otherwise, returns null.
2369
  const Type *getBaseClass() const;
2370
2371
  /// Returns whether the base is virtual or not.
2372
25.9k
  bool isBaseVirtual() const {
2373
25.9k
    assert(isBaseInitializer() && "Must call this on base initializer!");
2374
25.9k
2375
25.9k
    return IsVirtual;
2376
25.9k
  }
2377
2378
  /// Returns the declarator information for a base class or delegating
2379
  /// initializer.
2380
17.5k
  TypeSourceInfo *getTypeSourceInfo() const {
2381
17.5k
    return Initializee.dyn_cast<TypeSourceInfo *>();
2382
17.5k
  }
2383
2384
  /// If this is a member initializer, returns the declaration of the
2385
  /// non-static data member being initialized. Otherwise, returns null.
2386
183k
  FieldDecl *getMember() const {
2387
183k
    if (isMemberInitializer())
2388
182k
      return Initializee.get<FieldDecl*>();
2389
689
    return nullptr;
2390
689
  }
2391
2392
887k
  FieldDecl *getAnyMember() const {
2393
887k
    if (isMemberInitializer())
2394
868k
      return Initializee.get<FieldDecl*>();
2395
19.7k
    if (isIndirectMemberInitializer())
2396
5.83k
      return Initializee.get<IndirectFieldDecl*>()->getAnonField();
2397
13.9k
    return nullptr;
2398
13.9k
  }
2399
2400
114k
  IndirectFieldDecl *getIndirectMember() const {
2401
114k
    if (isIndirectMemberInitializer())
2402
1.94k
      return Initializee.get<IndirectFieldDecl*>();
2403
112k
    return nullptr;
2404
112k
  }
2405
2406
183k
  SourceLocation getMemberLocation() const {
2407
183k
    return MemberOrEllipsisLocation;
2408
183k
  }
2409
2410
  /// Determine the source location of the initializer.
2411
  SourceLocation getSourceLocation() const;
2412
2413
  /// Determine the source range covering the entire initializer.
2414
  SourceRange getSourceRange() const LLVM_READONLY;
2415
2416
  /// Determine whether this initializer is explicitly written
2417
  /// in the source code.
2418
55.0k
  bool isWritten() const { return IsWritten; }
2419
2420
  /// Return the source position of the initializer, counting from 0.
2421
  /// If the initializer was implicit, -1 is returned.
2422
2.12k
  int getSourceOrder() const {
2423
2.12k
    return IsWritten ? static_cast<int>(SourceOrder) : 
-10
;
2424
2.12k
  }
2425
2426
  /// Set the source order of this initializer.
2427
  ///
2428
  /// This can only be called once for each initializer; it cannot be called
2429
  /// on an initializer having a positive number of (implicit) array indices.
2430
  ///
2431
  /// This assumes that the initializer was written in the source code, and
2432
  /// ensures that isWritten() returns true.
2433
305k
  void setSourceOrder(int Pos) {
2434
305k
    assert(!IsWritten &&
2435
305k
           "setSourceOrder() used on implicit initializer");
2436
305k
    assert(SourceOrder == 0 &&
2437
305k
           "calling twice setSourceOrder() on the same initializer");
2438
305k
    assert(Pos >= 0 &&
2439
305k
           "setSourceOrder() used to make an initializer implicit");
2440
305k
    IsWritten = true;
2441
305k
    SourceOrder = static_cast<unsigned>(Pos);
2442
305k
  }
2443
2444
2.57k
  SourceLocation getLParenLoc() const { return LParenLoc; }
2445
2.61k
  SourceLocation getRParenLoc() const { return RParenLoc; }
2446
2447
  /// Get the initializer.
2448
510k
  Expr *getInit() const { return static_cast<Expr *>(Init); }
2449
};
2450
2451
/// Description of a constructor that was inherited from a base class.
2452
class InheritedConstructor {
2453
  ConstructorUsingShadowDecl *Shadow = nullptr;
2454
  CXXConstructorDecl *BaseCtor = nullptr;
2455
2456
public:
2457
1.93M
  InheritedConstructor() = default;
2458
  InheritedConstructor(ConstructorUsingShadowDecl *Shadow,
2459
                       CXXConstructorDecl *BaseCtor)
2460
198
      : Shadow(Shadow), BaseCtor(BaseCtor) {}
2461
2462
3.70M
  explicit operator bool() const { return Shadow; }
2463
2464
619
  ConstructorUsingShadowDecl *getShadowDecl() const { return Shadow; }
2465
1.23k
  CXXConstructorDecl *getConstructor() const { return BaseCtor; }
2466
};
2467
2468
/// Represents a C++ constructor within a class.
2469
///
2470
/// For example:
2471
///
2472
/// \code
2473
/// class X {
2474
/// public:
2475
///   explicit X(int); // represented by a CXXConstructorDecl.
2476
/// };
2477
/// \endcode
2478
class CXXConstructorDecl final
2479
    : public CXXMethodDecl,
2480
      private llvm::TrailingObjects<CXXConstructorDecl, InheritedConstructor> {
2481
  // This class stores some data in DeclContext::CXXConstructorDeclBits
2482
  // to save some space. Use the provided accessors to access it.
2483
2484
  /// \name Support for base and member initializers.
2485
  /// \{
2486
  /// The arguments used to initialize the base or member.
2487
  LazyCXXCtorInitializersPtr CtorInitializers;
2488
2489
  CXXConstructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2490
                     const DeclarationNameInfo &NameInfo,
2491
                     QualType T, TypeSourceInfo *TInfo,
2492
                     bool isExplicitSpecified, bool isInline,
2493
                     bool isImplicitlyDeclared, bool isConstexpr,
2494
                     InheritedConstructor Inherited);
2495
2496
  void anchor() override;
2497
2498
public:
2499
  friend class ASTDeclReader;
2500
  friend class ASTDeclWriter;
2501
  friend TrailingObjects;
2502
2503
  static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID,
2504
                                                bool InheritsConstructor);
2505
  static CXXConstructorDecl *
2506
  Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2507
         const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2508
         bool isExplicit, bool isInline, bool isImplicitlyDeclared,
2509
         bool isConstexpr,
2510
         InheritedConstructor Inherited = InheritedConstructor());
2511
2512
  /// Iterates through the member/base initializer list.
2513
  using init_iterator = CXXCtorInitializer **;
2514
2515
  /// Iterates through the member/base initializer list.
2516
  using init_const_iterator = CXXCtorInitializer *const *;
2517
2518
  using init_range = llvm::iterator_range<init_iterator>;
2519
  using init_const_range = llvm::iterator_range<init_const_iterator>;
2520
2521
14.7k
  init_range inits() { return init_range(init_begin(), init_end()); }
2522
149k
  init_const_range inits() const {
2523
149k
    return init_const_range(init_begin(), init_end());
2524
149k
  }
2525
2526
  /// Retrieve an iterator to the first initializer.
2527
29.5k
  init_iterator init_begin() {
2528
29.5k
    const auto *ConstThis = this;
2529
29.5k
    return const_cast<init_iterator>(ConstThis->init_begin());
2530
29.5k
  }
2531
2532
  /// Retrieve an iterator to the first initializer.
2533
  init_const_iterator init_begin() const;
2534
2535
  /// Retrieve an iterator past the last initializer.
2536
14.7k
  init_iterator       init_end()       {
2537
14.7k
    return init_begin() + getNumCtorInitializers();
2538
14.7k
  }
2539
2540
  /// Retrieve an iterator past the last initializer.
2541
180k
  init_const_iterator init_end() const {
2542
180k
    return init_begin() + getNumCtorInitializers();
2543
180k
  }
2544
2545
  using init_reverse_iterator = std::reverse_iterator<init_iterator>;
2546
  using init_const_reverse_iterator =
2547
      std::reverse_iterator<init_const_iterator>;
2548
2549
0
  init_reverse_iterator init_rbegin() {
2550
0
    return init_reverse_iterator(init_end());
2551
0
  }
2552
0
  init_const_reverse_iterator init_rbegin() const {
2553
0
    return init_const_reverse_iterator(init_end());
2554
0
  }
2555
2556
0
  init_reverse_iterator init_rend() {
2557
0
    return init_reverse_iterator(init_begin());
2558
0
  }
2559
0
  init_const_reverse_iterator init_rend() const {
2560
0
    return init_const_reverse_iterator(init_begin());
2561
0
  }
2562
2563
  /// Determine the number of arguments used to initialize the member
2564
  /// or base.
2565
274k
  unsigned getNumCtorInitializers() const {
2566
274k
      return CXXConstructorDeclBits.NumCtorInitializers;
2567
274k
  }
2568
2569
1.12M
  void setNumCtorInitializers(unsigned numCtorInitializers) {
2570
1.12M
    CXXConstructorDeclBits.NumCtorInitializers = numCtorInitializers;
2571
1.12M
    // This assert added because NumCtorInitializers is stored
2572
1.12M
    // in CXXConstructorDeclBits as a bitfield and its width has
2573
1.12M
    // been shrunk from 32 bits to fit into CXXConstructorDeclBitfields.
2574
1.12M
    assert(CXXConstructorDeclBits.NumCtorInitializers ==
2575
1.12M
           numCtorInitializers && "NumCtorInitializers overflow!");
2576
1.12M
  }
2577
2578
236k
  void setCtorInitializers(CXXCtorInitializer **Initializers) {
2579
236k
    CtorInitializers = Initializers;
2580
236k
  }
2581
2582
  /// Whether this function is explicit.
2583
2.37M
  bool isExplicit() const {
2584
2.37M
    return getCanonicalDecl()->isExplicitSpecified();
2585
2.37M
  }
2586
2587
  /// Determine whether this constructor is a delegating constructor.
2588
64.4k
  bool isDelegatingConstructor() const {
2589
64.4k
    return (getNumCtorInitializers() == 1) &&
2590
64.4k
           
init_begin()[0]->isDelegatingInitializer()24.4k
;
2591
64.4k
  }
2592
2593
  /// When this constructor delegates to another, retrieve the target.
2594
  CXXConstructorDecl *getTargetConstructor() const;
2595
2596
  /// Whether this constructor is a default
2597
  /// constructor (C++ [class.ctor]p5), which can be used to
2598
  /// default-initialize a class of this type.
2599
  bool isDefaultConstructor() const;
2600
2601
  /// Whether this constructor is a copy constructor (C++ [class.copy]p2,
2602
  /// which can be used to copy the class.
2603
  ///
2604
  /// \p TypeQuals will be set to the qualifiers on the
2605
  /// argument type. For example, \p TypeQuals would be set to \c
2606
  /// Qualifiers::Const for the following copy constructor:
2607
  ///
2608
  /// \code
2609
  /// class X {
2610
  /// public:
2611
  ///   X(const X&);
2612
  /// };
2613
  /// \endcode
2614
  bool isCopyConstructor(unsigned &TypeQuals) const;
2615
2616
  /// Whether this constructor is a copy
2617
  /// constructor (C++ [class.copy]p2, which can be used to copy the
2618
  /// class.
2619
732k
  bool isCopyConstructor() const {
2620
732k
    unsigned TypeQuals = 0;
2621
732k
    return isCopyConstructor(TypeQuals);
2622
732k
  }
2623
2624
  /// Determine whether this constructor is a move constructor
2625
  /// (C++11 [class.copy]p3), which can be used to move values of the class.
2626
  ///
2627
  /// \param TypeQuals If this constructor is a move constructor, will be set
2628
  /// to the type qualifiers on the referent of the first parameter's type.
2629
  bool isMoveConstructor(unsigned &TypeQuals) const;
2630
2631
  /// Determine whether this constructor is a move constructor
2632
  /// (C++11 [class.copy]p3), which can be used to move values of the class.
2633
822k
  bool isMoveConstructor() const {
2634
822k
    unsigned TypeQuals = 0;
2635
822k
    return isMoveConstructor(TypeQuals);
2636
822k
  }
2637
2638
  /// Determine whether this is a copy or move constructor.
2639
  ///
2640
  /// \param TypeQuals Will be set to the type qualifiers on the reference
2641
  /// parameter, if in fact this is a copy or move constructor.
2642
  bool isCopyOrMoveConstructor(unsigned &TypeQuals) const;
2643
2644
  /// Determine whether this a copy or move constructor.
2645
1.03M
  bool isCopyOrMoveConstructor() const {
2646
1.03M
    unsigned Quals;
2647
1.03M
    return isCopyOrMoveConstructor(Quals);
2648
1.03M
  }
2649
2650
  /// Whether this constructor is a
2651
  /// converting constructor (C++ [class.conv.ctor]), which can be
2652
  /// used for user-defined conversions.
2653
  bool isConvertingConstructor(bool AllowExplicit) const;
2654
2655
  /// Determine whether this is a member template specialization that
2656
  /// would copy the object to itself. Such constructors are never used to copy
2657
  /// an object.
2658
  bool isSpecializationCopyingObject() const;
2659
2660
  /// Determine whether this is an implicit constructor synthesized to
2661
  /// model a call to a constructor inherited from a base class.
2662
1.18M
  bool isInheritingConstructor() const {
2663
1.18M
    return CXXConstructorDeclBits.IsInheritingConstructor;
2664
1.18M
  }
2665
2666
  /// State that this is an implicit constructor synthesized to
2667
  /// model a call to a constructor inherited from a base class.
2668
892k
  void setInheritingConstructor(bool isIC = true) {
2669
892k
    CXXConstructorDeclBits.IsInheritingConstructor = isIC;
2670
892k
  }
2671
2672
  /// Get the constructor that this inheriting constructor is based on.
2673
1.05M
  InheritedConstructor getInheritedConstructor() const {
2674
1.05M
    return isInheritingConstructor() ?
2675
1.05M
      
*getTrailingObjects<InheritedConstructor>()2.48k
: InheritedConstructor();
2676
1.05M
  }
2677
2678
31.7M
  CXXConstructorDecl *getCanonicalDecl() override {
2679
31.7M
    return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
2680
31.7M
  }
2681
2.37M
  const CXXConstructorDecl *getCanonicalDecl() const {
2682
2.37M
    return const_cast<CXXConstructorDecl*>(this)->getCanonicalDecl();
2683
2.37M
  }
2684
2685
  // Implement isa/cast/dyncast/etc.
2686
85.0M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2687
85.5M
  static bool classofKind(Kind K) { return K == CXXConstructor; }
2688
};
2689
2690
/// Represents a C++ destructor within a class.
2691
///
2692
/// For example:
2693
///
2694
/// \code
2695
/// class X {
2696
/// public:
2697
///   ~X(); // represented by a CXXDestructorDecl.
2698
/// };
2699
/// \endcode
2700
class CXXDestructorDecl : public CXXMethodDecl {
2701
  friend class ASTDeclReader;
2702
  friend class ASTDeclWriter;
2703
2704
  // FIXME: Don't allocate storage for these except in the first declaration
2705
  // of a virtual destructor.
2706
  FunctionDecl *OperatorDelete = nullptr;
2707
  Expr *OperatorDeleteThisArg = nullptr;
2708
2709
  CXXDestructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2710
                    const DeclarationNameInfo &NameInfo,
2711
                    QualType T, TypeSourceInfo *TInfo,
2712
                    bool isInline, bool isImplicitlyDeclared)
2713
    : CXXMethodDecl(CXXDestructor, C, RD, StartLoc, NameInfo, T, TInfo,
2714
                    SC_None, isInline, /*isConstexpr=*/false, SourceLocation())
2715
203k
  {
2716
203k
    setImplicit(isImplicitlyDeclared);
2717
203k
  }
2718
2719
  void anchor() override;
2720
2721
public:
2722
  static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2723
                                   SourceLocation StartLoc,
2724
                                   const DeclarationNameInfo &NameInfo,
2725
                                   QualType T, TypeSourceInfo* TInfo,
2726
                                   bool isInline,
2727
                                   bool isImplicitlyDeclared);
2728
  static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID);
2729
2730
  void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg);
2731
2732
35.6k
  const FunctionDecl *getOperatorDelete() const {
2733
35.6k
    return getCanonicalDecl()->OperatorDelete;
2734
35.6k
  }
2735
2736
1.97k
  Expr *getOperatorDeleteThisArg() const {
2737
1.97k
    return getCanonicalDecl()->OperatorDeleteThisArg;
2738
1.97k
  }
2739
2740
8.22M
  CXXDestructorDecl *getCanonicalDecl() override {
2741
8.22M
    return cast<CXXDestructorDecl>(FunctionDecl::getCanonicalDecl());
2742
8.22M
  }
2743
37.5k
  const CXXDestructorDecl *getCanonicalDecl() const {
2744
37.5k
    return const_cast<CXXDestructorDecl*>(this)->getCanonicalDecl();
2745
37.5k
  }
2746
2747
  // Implement isa/cast/dyncast/etc.
2748
42.4M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2749
42.8M
  static bool classofKind(Kind K) { return K == CXXDestructor; }
2750
};
2751
2752
/// Represents a C++ conversion function within a class.
2753
///
2754
/// For example:
2755
///
2756
/// \code
2757
/// class X {
2758
/// public:
2759
///   operator bool();
2760
/// };
2761
/// \endcode
2762
class CXXConversionDecl : public CXXMethodDecl {
2763
  CXXConversionDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2764
                    const DeclarationNameInfo &NameInfo, QualType T,
2765
                    TypeSourceInfo *TInfo, bool isInline,
2766
                    bool isExplicitSpecified, bool isConstexpr,
2767
                    SourceLocation EndLocation)
2768
      : CXXMethodDecl(CXXConversion, C, RD, StartLoc, NameInfo, T, TInfo,
2769
25.4k
                      SC_None, isInline, isConstexpr, EndLocation) {
2770
25.4k
    setExplicitSpecified(isExplicitSpecified);
2771
25.4k
  }
2772
2773
  void anchor() override;
2774
2775
public:
2776
  friend class ASTDeclReader;
2777
  friend class ASTDeclWriter;
2778
2779
  static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2780
                                   SourceLocation StartLoc,
2781
                                   const DeclarationNameInfo &NameInfo,
2782
                                   QualType T, TypeSourceInfo *TInfo,
2783
                                   bool isInline, bool isExplicit,
2784
                                   bool isConstexpr,
2785
                                   SourceLocation EndLocation);
2786
  static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2787
2788
  /// Whether this function is explicit.
2789
3.68M
  bool isExplicit() const {
2790
3.68M
    return getCanonicalDecl()->isExplicitSpecified();
2791
3.68M
  }
2792
2793
  /// Returns the type that this conversion function is converting to.
2794
3.60M
  QualType getConversionType() const {
2795
3.60M
    return getType()->getAs<FunctionType>()->getReturnType();
2796
3.60M
  }
2797
2798
  /// Determine whether this conversion function is a conversion from
2799
  /// a lambda closure type to a block pointer.
2800
  bool isLambdaToBlockPointerConversion() const;
2801
2802
6.24M
  CXXConversionDecl *getCanonicalDecl() override {
2803
6.24M
    return cast<CXXConversionDecl>(FunctionDecl::getCanonicalDecl());
2804
6.24M
  }
2805
3.68M
  const CXXConversionDecl *getCanonicalDecl() const {
2806
3.68M
    return const_cast<CXXConversionDecl*>(this)->getCanonicalDecl();
2807
3.68M
  }
2808
2809
  // Implement isa/cast/dyncast/etc.
2810
10.8M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2811
10.8M
  static bool classofKind(Kind K) { return K == CXXConversion; }
2812
};
2813
2814
/// Represents a linkage specification.
2815
///
2816
/// For example:
2817
/// \code
2818
///   extern "C" void foo();
2819
/// \endcode
2820
class LinkageSpecDecl : public Decl, public DeclContext {
2821
  virtual void anchor();
2822
  // This class stores some data in DeclContext::LinkageSpecDeclBits to save
2823
  // some space. Use the provided accessors to access it.
2824
public:
2825
  /// Represents the language in a linkage specification.
2826
  ///
2827
  /// The values are part of the serialization ABI for
2828
  /// ASTs and cannot be changed without altering that ABI.  To help
2829
  /// ensure a stable ABI for this, we choose the DW_LANG_ encodings
2830
  /// from the dwarf standard.
2831
  enum LanguageIDs {
2832
    lang_c = /* DW_LANG_C */ 0x0002,
2833
    lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004
2834
  };
2835
2836
private:
2837
  /// The source location for the extern keyword.
2838
  SourceLocation ExternLoc;
2839
2840
  /// The source location for the right brace (if valid).
2841
  SourceLocation RBraceLoc;
2842
2843
  LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
2844
                  SourceLocation LangLoc, LanguageIDs lang, bool HasBraces);
2845
2846
public:
2847
  static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
2848
                                 SourceLocation ExternLoc,
2849
                                 SourceLocation LangLoc, LanguageIDs Lang,
2850
                                 bool HasBraces);
2851
  static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2852
2853
  /// Return the language specified by this linkage specification.
2854
12.0M
  LanguageIDs getLanguage() const {
2855
12.0M
    return static_cast<LanguageIDs>(LinkageSpecDeclBits.Language);
2856
12.0M
  }
2857
2858
  /// Set the language specified by this linkage specification.
2859
151k
  void setLanguage(LanguageIDs L) { LinkageSpecDeclBits.Language = L; }
2860
2861
  /// Determines whether this linkage specification had braces in
2862
  /// its syntactic form.
2863
33.1k
  bool hasBraces() const {
2864
33.1k
    assert(!RBraceLoc.isValid() || LinkageSpecDeclBits.HasBraces);
2865
33.1k
    return LinkageSpecDeclBits.HasBraces;
2866
33.1k
  }
2867
2868
111
  SourceLocation getExternLoc() const { return ExternLoc; }
2869
159
  SourceLocation getRBraceLoc() const { return RBraceLoc; }
2870
171
  void setExternLoc(SourceLocation L) { ExternLoc = L; }
2871
46.1k
  void setRBraceLoc(SourceLocation L) {
2872
46.1k
    RBraceLoc = L;
2873
46.1k
    LinkageSpecDeclBits.HasBraces = RBraceLoc.isValid();
2874
46.1k
  }
2875
2876
58
  SourceLocation getEndLoc() const LLVM_READONLY {
2877
58
    if (hasBraces())
2878
52
      return getRBraceLoc();
2879
6
    // No braces: get the end location of the (only) declaration in context
2880
6
    // (if present).
2881
6
    return decls_empty() ? 
getLocation()0
: decls_begin()->getEndLoc();
2882
6
  }
2883
2884
58
  SourceRange getSourceRange() const override LLVM_READONLY {
2885
58
    return SourceRange(ExternLoc, getEndLoc());
2886
58
  }
2887
2888
7.59k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2889
32.1M
  static bool classofKind(Kind K) { return K == LinkageSpec; }
2890
2891
277
  static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
2892
277
    return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
2893
277
  }
2894
2895
0
  static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
2896
0
    return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
2897
0
  }
2898
};
2899
2900
/// Represents C++ using-directive.
2901
///
2902
/// For example:
2903
/// \code
2904
///    using namespace std;
2905
/// \endcode
2906
///
2907
/// \note UsingDirectiveDecl should be Decl not NamedDecl, but we provide
2908
/// artificial names for all using-directives in order to store
2909
/// them in DeclContext effectively.
2910
class UsingDirectiveDecl : public NamedDecl {
2911
  /// The location of the \c using keyword.
2912
  SourceLocation UsingLoc;
2913
2914
  /// The location of the \c namespace keyword.
2915
  SourceLocation NamespaceLoc;
2916
2917
  /// The nested-name-specifier that precedes the namespace.
2918
  NestedNameSpecifierLoc QualifierLoc;
2919
2920
  /// The namespace nominated by this using-directive.
2921
  NamedDecl *NominatedNamespace;
2922
2923
  /// Enclosing context containing both using-directive and nominated
2924
  /// namespace.
2925
  DeclContext *CommonAncestor;
2926
2927
  UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc,
2928
                     SourceLocation NamespcLoc,
2929
                     NestedNameSpecifierLoc QualifierLoc,
2930
                     SourceLocation IdentLoc,
2931
                     NamedDecl *Nominated,
2932
                     DeclContext *CommonAncestor)
2933
      : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc),
2934
        NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc),
2935
24.1k
        NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) {}
2936
2937
  /// Returns special DeclarationName used by using-directives.
2938
  ///
2939
  /// This is only used by DeclContext for storing UsingDirectiveDecls in
2940
  /// its lookup structure.
2941
68.8M
  static DeclarationName getName() {
2942
68.8M
    return DeclarationName::getUsingDirectiveName();
2943
68.8M
  }
2944
2945
  void anchor() override;
2946
2947
public:
2948
  friend class ASTDeclReader;
2949
2950
  // Friend for getUsingDirectiveName.
2951
  friend class DeclContext;
2952
2953
  /// Retrieve the nested-name-specifier that qualifies the
2954
  /// name of the namespace, with source-location information.
2955
86
  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2956
2957
  /// Retrieve the nested-name-specifier that qualifies the
2958
  /// name of the namespace.
2959
6
  NestedNameSpecifier *getQualifier() const {
2960
6
    return QualifierLoc.getNestedNameSpecifier();
2961
6
  }
2962
2963
9
  NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
2964
  const NamedDecl *getNominatedNamespaceAsWritten() const {
2965
    return NominatedNamespace;
2966
  }
2967
2968
  /// Returns the namespace nominated by this using-directive.
2969
  NamespaceDecl *getNominatedNamespace();
2970
2971
47
  const NamespaceDecl *getNominatedNamespace() const {
2972
47
    return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
2973
47
  }
2974
2975
  /// Returns the common ancestor context of this using-directive and
2976
  /// its nominated namespace.
2977
39
  DeclContext *getCommonAncestor() { return CommonAncestor; }
2978
0
  const DeclContext *getCommonAncestor() const { return CommonAncestor; }
2979
2980
  /// Return the location of the \c using keyword.
2981
37
  SourceLocation getUsingLoc() const { return UsingLoc; }
2982
2983
  // FIXME: Could omit 'Key' in name.
2984
  /// Returns the location of the \c namespace keyword.
2985
39
  SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
2986
2987
  /// Returns the location of this using declaration's identifier.
2988
8
  SourceLocation getIdentLocation() const { return getLocation(); }
2989
2990
  static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
2991
                                    SourceLocation UsingLoc,
2992
                                    SourceLocation NamespaceLoc,
2993
                                    NestedNameSpecifierLoc QualifierLoc,
2994
                                    SourceLocation IdentLoc,
2995
                                    NamedDecl *Nominated,
2996
                                    DeclContext *CommonAncestor);
2997
  static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2998
2999
50
  SourceRange getSourceRange() const override LLVM_READONLY {
3000
50
    return SourceRange(UsingLoc, getLocation());
3001
50
  }
3002
3003
297k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3004
297k
  static bool classofKind(Kind K) { return K == UsingDirective; }
3005
};
3006
3007
/// Represents a C++ namespace alias.
3008
///
3009
/// For example:
3010
///
3011
/// \code
3012
/// namespace Foo = Bar;
3013
/// \endcode
3014
class NamespaceAliasDecl : public NamedDecl,
3015
                           public Redeclarable<NamespaceAliasDecl> {
3016
  friend class ASTDeclReader;
3017
3018
  /// The location of the \c namespace keyword.
3019
  SourceLocation NamespaceLoc;
3020
3021
  /// The location of the namespace's identifier.
3022
  ///
3023
  /// This is accessed by TargetNameLoc.
3024
  SourceLocation IdentLoc;
3025
3026
  /// The nested-name-specifier that precedes the namespace.
3027
  NestedNameSpecifierLoc QualifierLoc;
3028
3029
  /// The Decl that this alias points to, either a NamespaceDecl or
3030
  /// a NamespaceAliasDecl.
3031
  NamedDecl *Namespace;
3032
3033
  NamespaceAliasDecl(ASTContext &C, DeclContext *DC,
3034
                     SourceLocation NamespaceLoc, SourceLocation AliasLoc,
3035
                     IdentifierInfo *Alias, NestedNameSpecifierLoc QualifierLoc,
3036
                     SourceLocation IdentLoc, NamedDecl *Namespace)
3037
      : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias), redeclarable_base(C),
3038
        NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc),
3039
258
        QualifierLoc(QualifierLoc), Namespace(Namespace) {}
3040
3041
  void anchor() override;
3042
3043
  using redeclarable_base = Redeclarable<NamespaceAliasDecl>;
3044
3045
  NamespaceAliasDecl *getNextRedeclarationImpl() override;
3046
  NamespaceAliasDecl *getPreviousDeclImpl() override;
3047
  NamespaceAliasDecl *getMostRecentDeclImpl() override;
3048
3049
public:
3050
  static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
3051
                                    SourceLocation NamespaceLoc,
3052
                                    SourceLocation AliasLoc,
3053
                                    IdentifierInfo *Alias,
3054
                                    NestedNameSpecifierLoc QualifierLoc,
3055
                                    SourceLocation IdentLoc,
3056
                                    NamedDecl *Namespace);
3057
3058
  static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3059
3060
  using redecl_range = redeclarable_base::redecl_range;
3061
  using redecl_iterator = redeclarable_base::redecl_iterator;
3062
3063
  using redeclarable_base::redecls_begin;
3064
  using redeclarable_base::redecls_end;
3065
  using redeclarable_base::redecls;
3066
  using redeclarable_base::getPreviousDecl;
3067
  using redeclarable_base::getMostRecentDecl;
3068
3069
265
  NamespaceAliasDecl *getCanonicalDecl() override {
3070
265
    return getFirstDecl();
3071
265
  }
3072
0
  const NamespaceAliasDecl *getCanonicalDecl() const {
3073
0
    return getFirstDecl();
3074
0
  }
3075
3076
  /// Retrieve the nested-name-specifier that qualifies the
3077
  /// name of the namespace, with source-location information.
3078
206
  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3079
3080
  /// Retrieve the nested-name-specifier that qualifies the
3081
  /// name of the namespace.
3082
7
  NestedNameSpecifier *getQualifier() const {
3083
7
    return QualifierLoc.getNestedNameSpecifier();
3084
7
  }
3085
3086
  /// Retrieve the namespace declaration aliased by this directive.
3087
3.02k
  NamespaceDecl *getNamespace() {
3088
3.02k
    if (auto *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
3089
145
      return AD->getNamespace();
3090
2.88k
3091
2.88k
    return cast<NamespaceDecl>(Namespace);
3092
2.88k
  }
3093
3094
14
  const NamespaceDecl *getNamespace() const {
3095
14
    return const_cast<NamespaceAliasDecl *>(this)->getNamespace();
3096
14
  }
3097
3098
  /// Returns the location of the alias name, i.e. 'foo' in
3099
  /// "namespace foo = ns::bar;".
3100
5
  SourceLocation getAliasLoc() const { return getLocation(); }
3101
3102
  /// Returns the location of the \c namespace keyword.
3103
18
  SourceLocation getNamespaceLoc() const { return NamespaceLoc; }
3104
3105
  /// Returns the location of the identifier in the named namespace.
3106
29
  SourceLocation getTargetNameLoc() const { return IdentLoc; }
3107
3108
  /// Retrieve the namespace that this alias refers to, which
3109
  /// may either be a NamespaceDecl or a NamespaceAliasDecl.
3110
29
  NamedDecl *getAliasedNamespace() const { return Namespace; }
3111
3112
37
  SourceRange getSourceRange() const override LLVM_READONLY {
3113
37
    return SourceRange(NamespaceLoc, IdentLoc);
3114
37
  }
3115
3116
47.9M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3117
47.9M
  static bool classofKind(Kind K) { return K == NamespaceAlias; }
3118
};
3119
3120
/// Represents a shadow declaration introduced into a scope by a
3121
/// (resolved) using declaration.
3122
///
3123
/// For example,
3124
/// \code
3125
/// namespace A {
3126
///   void foo();
3127
/// }
3128
/// namespace B {
3129
///   using A::foo; // <- a UsingDecl
3130
///                 // Also creates a UsingShadowDecl for A::foo() in B
3131
/// }
3132
/// \endcode
3133
class UsingShadowDecl : public NamedDecl, public Redeclarable<UsingShadowDecl> {
3134
  friend class UsingDecl;
3135
3136
  /// The referenced declaration.
3137
  NamedDecl *Underlying = nullptr;
3138
3139
  /// The using declaration which introduced this decl or the next using
3140
  /// shadow declaration contained in the aforementioned using declaration.
3141
  NamedDecl *UsingOrNextShadow = nullptr;
3142
3143
  void anchor() override;
3144
3145
  using redeclarable_base = Redeclarable<UsingShadowDecl>;
3146
3147
163k
  UsingShadowDecl *getNextRedeclarationImpl() override {
3148
163k
    return getNextRedeclaration();
3149
163k
  }
3150
3151
36
  UsingShadowDecl *getPreviousDeclImpl() override {
3152
36
    return getPreviousDecl();
3153
36
  }
3154
3155
315k
  UsingShadowDecl *getMostRecentDeclImpl() override {
3156
315k
    return getMostRecentDecl();
3157
315k
  }
3158
3159
protected:
3160
  UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC, SourceLocation Loc,
3161
                  UsingDecl *Using, NamedDecl *Target);
3162
  UsingShadowDecl(Kind K, ASTContext &C, EmptyShell);
3163
3164
public:
3165
  friend class ASTDeclReader;
3166
  friend class ASTDeclWriter;
3167
3168
  static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
3169
                                 SourceLocation Loc, UsingDecl *Using,
3170
159k
                                 NamedDecl *Target) {
3171
159k
    return new (C, DC) UsingShadowDecl(UsingShadow, C, DC, Loc, Using, Target);
3172
159k
  }
3173
3174
  static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3175
3176
  using redecl_range = redeclarable_base::redecl_range;
3177
  using redecl_iterator = redeclarable_base::redecl_iterator;
3178
3179
  using redeclarable_base::redecls_begin;
3180
  using redeclarable_base::redecls_end;
3181
  using redeclarable_base::redecls;
3182
  using redeclarable_base::getPreviousDecl;
3183
  using redeclarable_base::getMostRecentDecl;
3184
  using redeclarable_base::isFirstDecl;
3185
3186
999k
  UsingShadowDecl *getCanonicalDecl() override {
3187
999k
    return getFirstDecl();
3188
999k
  }
3189
0
  const UsingShadowDecl *getCanonicalDecl() const {
3190
0
    return getFirstDecl();
3191
0
  }
3192
3193
  /// Gets the underlying declaration which has been brought into the
3194
  /// local scope.
3195
2.49M
  NamedDecl *getTargetDecl() const { return Underlying; }
3196
3197
  /// Sets the underlying declaration which has been brought into the
3198
  /// local scope.
3199
160k
  void setTargetDecl(NamedDecl *ND) {
3200
160k
    assert(ND && "Target decl is null!");
3201
160k
    Underlying = ND;
3202
160k
    // A UsingShadowDecl is never a friend or local extern declaration, even
3203
160k
    // if it is a shadow declaration for one.
3204
160k
    IdentifierNamespace =
3205
160k
        ND->getIdentifierNamespace() &
3206
160k
        ~(IDNS_OrdinaryFriend | IDNS_TagFriend | IDNS_LocalExtern);
3207
160k
  }
3208
3209
  /// Gets the using declaration to which this declaration is tied.
3210
  UsingDecl *getUsingDecl() const;
3211
3212
  /// The next using shadow declaration contained in the shadow decl
3213
  /// chain of the using declaration which introduced this decl.
3214
602
  UsingShadowDecl *getNextUsingShadowDecl() const {
3215
602
    return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow);
3216
602
  }
3217
3218
40.2M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3219
40.2M
  static bool classofKind(Kind K) {
3220
40.2M
    return K == Decl::UsingShadow || 
K == Decl::ConstructorUsingShadow37.7M
;
3221
40.2M
  }
3222
};
3223
3224
/// Represents a shadow constructor declaration introduced into a
3225
/// class by a C++11 using-declaration that names a constructor.
3226
///
3227
/// For example:
3228
/// \code
3229
/// struct Base { Base(int); };
3230
/// struct Derived {
3231
///    using Base::Base; // creates a UsingDecl and a ConstructorUsingShadowDecl
3232
/// };
3233
/// \endcode
3234
class ConstructorUsingShadowDecl final : public UsingShadowDecl {
3235
  /// If this constructor using declaration inherted the constructor
3236
  /// from an indirect base class, this is the ConstructorUsingShadowDecl
3237
  /// in the named direct base class from which the declaration was inherited.
3238
  ConstructorUsingShadowDecl *NominatedBaseClassShadowDecl = nullptr;
3239
3240
  /// If this constructor using declaration inherted the constructor
3241
  /// from an indirect base class, this is the ConstructorUsingShadowDecl
3242
  /// that will be used to construct the unique direct or virtual base class
3243
  /// that receives the constructor arguments.
3244
  ConstructorUsingShadowDecl *ConstructedBaseClassShadowDecl = nullptr;
3245
3246
  /// \c true if the constructor ultimately named by this using shadow
3247
  /// declaration is within a virtual base class subobject of the class that
3248
  /// contains this declaration.
3249
  unsigned IsVirtual : 1;
3250
3251
  ConstructorUsingShadowDecl(ASTContext &C, DeclContext *DC, SourceLocation Loc,
3252
                             UsingDecl *Using, NamedDecl *Target,
3253
                             bool TargetInVirtualBase)
3254
      : UsingShadowDecl(ConstructorUsingShadow, C, DC, Loc, Using,
3255
                        Target->getUnderlyingDecl()),
3256
        NominatedBaseClassShadowDecl(
3257
            dyn_cast<ConstructorUsingShadowDecl>(Target)),
3258
        ConstructedBaseClassShadowDecl(NominatedBaseClassShadowDecl),
3259
1.16k
        IsVirtual(TargetInVirtualBase) {
3260
1.16k
    // If we found a constructor that chains to a constructor for a virtual
3261
1.16k
    // base, we should directly call that virtual base constructor instead.
3262
1.16k
    // FIXME: This logic belongs in Sema.
3263
1.16k
    if (NominatedBaseClassShadowDecl &&
3264
1.16k
        
NominatedBaseClassShadowDecl->constructsVirtualBase()186
) {
3265
79
      ConstructedBaseClassShadowDecl =
3266
79
          NominatedBaseClassShadowDecl->ConstructedBaseClassShadowDecl;
3267
79
      IsVirtual = true;
3268
79
    }
3269
1.16k
  }
3270
3271
  ConstructorUsingShadowDecl(ASTContext &C, EmptyShell Empty)
3272
62
      : UsingShadowDecl(ConstructorUsingShadow, C, Empty), IsVirtual(false) {}
3273
3274
  void anchor() override;
3275
3276
public:
3277
  friend class ASTDeclReader;
3278
  friend class ASTDeclWriter;
3279
3280
  static ConstructorUsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
3281
                                            SourceLocation Loc,
3282
                                            UsingDecl *Using, NamedDecl *Target,
3283
                                            bool IsVirtual);
3284
  static ConstructorUsingShadowDecl *CreateDeserialized(ASTContext &C,
3285
                                                        unsigned ID);
3286
3287
  /// Returns the parent of this using shadow declaration, which
3288
  /// is the class in which this is declared.
3289
  //@{
3290
0
  const CXXRecordDecl *getParent() const {
3291
0
    return cast<CXXRecordDecl>(getDeclContext());
3292
0
  }
3293
2.26k
  CXXRecordDecl *getParent() {
3294
2.26k
    return cast<CXXRecordDecl>(getDeclContext());
3295
2.26k
  }
3296
  //@}
3297
3298
  /// Get the inheriting constructor declaration for the direct base
3299
  /// class from which this using shadow declaration was inherited, if there is
3300
  /// one. This can be different for each redeclaration of the same shadow decl.
3301
645
  ConstructorUsingShadowDecl *getNominatedBaseClassShadowDecl() const {
3302
645
    return NominatedBaseClassShadowDecl;
3303
645
  }
3304
3305
  /// Get the inheriting constructor declaration for the base class
3306
  /// for which we don't have an explicit initializer, if there is one.
3307
159
  ConstructorUsingShadowDecl *getConstructedBaseClassShadowDecl() const {
3308
159
    return ConstructedBaseClassShadowDecl;
3309
159
  }
3310
3311
  /// Get the base class that was named in the using declaration. This
3312
  /// can be different for each redeclaration of this same shadow decl.
3313
  CXXRecordDecl *getNominatedBaseClass() const;
3314
3315
  /// Get the base class whose constructor or constructor shadow
3316
  /// declaration is passed the constructor arguments.
3317
597
  CXXRecordDecl *getConstructedBaseClass() const {
3318
597
    return cast<CXXRecordDecl>((ConstructedBaseClassShadowDecl
3319
597
                                    ? 
ConstructedBaseClassShadowDecl79
3320
597
                                    : 
getTargetDecl()518
)
3321
597
                                   ->getDeclContext());
3322
597
  }
3323
3324
  /// Returns \c true if the constructed base class is a virtual base
3325
  /// class subobject of this declaration's class.
3326
1.17k
  bool constructsVirtualBase() const {
3327
1.17k
    return IsVirtual;
3328
1.17k
  }
3329
3330
  /// Get the constructor or constructor template in the derived class
3331
  /// correspnding to this using shadow declaration, if it has been implicitly
3332
  /// declared already.
3333
  CXXConstructorDecl *getConstructor() const;
3334
  void setConstructor(NamedDecl *Ctor);
3335
3336
3.23M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3337
3.23M
  static bool classofKind(Kind K) { return K == ConstructorUsingShadow; }
3338
};
3339
3340
/// Represents a C++ using-declaration.
3341
///
3342
/// For example:
3343
/// \code
3344
///    using someNameSpace::someIdentifier;
3345
/// \endcode
3346
class UsingDecl : public NamedDecl, public Mergeable<UsingDecl> {
3347
  /// The source location of the 'using' keyword itself.
3348
  SourceLocation UsingLocation;
3349
3350
  /// The nested-name-specifier that precedes the name.
3351
  NestedNameSpecifierLoc QualifierLoc;
3352
3353
  /// Provides source/type location info for the declaration name
3354
  /// embedded in the ValueDecl base class.
3355
  DeclarationNameLoc DNLoc;
3356
3357
  /// The first shadow declaration of the shadow decl chain associated
3358
  /// with this using declaration.
3359
  ///
3360
  /// The bool member of the pair store whether this decl has the \c typename
3361
  /// keyword.
3362
  llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow;
3363
3364
  UsingDecl(DeclContext *DC, SourceLocation UL,
3365
            NestedNameSpecifierLoc QualifierLoc,
3366
            const DeclarationNameInfo &NameInfo, bool HasTypenameKeyword)
3367
    : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()),
3368
      UsingLocation(UL), QualifierLoc(QualifierLoc),
3369
111k
      DNLoc(NameInfo.getInfo()), FirstUsingShadow(nullptr, HasTypenameKeyword) {
3370
111k
  }
3371
3372
  void anchor() override;
3373
3374
public:
3375
  friend class ASTDeclReader;
3376
  friend class ASTDeclWriter;
3377
3378
  /// Return the source location of the 'using' keyword.
3379
917
  SourceLocation getUsingLoc() const { return UsingLocation; }
3380
3381
  /// Set the source location of the 'using' keyword.
3382
300
  void setUsingLoc(SourceLocation L) { UsingLocation = L; }
3383
3384
  /// Retrieve the nested-name-specifier that qualifies the name,
3385
  /// with source-location information.
3386
663
  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3387
3388
  /// Retrieve the nested-name-specifier that qualifies the name.
3389
13.7k
  NestedNameSpecifier *getQualifier() const {
3390
13.7k
    return QualifierLoc.getNestedNameSpecifier();
3391
13.7k
  }
3392
3393
411
  DeclarationNameInfo getNameInfo() const {
3394
411
    return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
3395
411
  }
3396
3397
  /// Return true if it is a C++03 access declaration (no 'using').
3398
178
  bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
3399
3400
  /// Return true if the using declaration has 'typename'.
3401
1.07k
  bool hasTypename() const { return FirstUsingShadow.getInt(); }
3402
3403
  /// Sets whether the using declaration has 'typename'.
3404
300
  void setTypename(bool TN) { FirstUsingShadow.setInt(TN); }
3405
3406
  /// Iterates through the using shadow declarations associated with
3407
  /// this using declaration.
3408
  class shadow_iterator {
3409
    /// The current using shadow declaration.
3410
    UsingShadowDecl *Current = nullptr;
3411
3412
  public:
3413
    using value_type = UsingShadowDecl *;
3414
    using reference = UsingShadowDecl *;
3415
    using pointer = UsingShadowDecl *;
3416
    using iterator_category = std::forward_iterator_tag;
3417
    using difference_type = std::ptrdiff_t;
3418
3419
508
    shadow_iterator() = default;
3420
582
    explicit shadow_iterator(UsingShadowDecl *C) : Current(C) {}
3421
3422
661
    reference operator*() const { return Current; }
3423
    pointer operator->() const { return Current; }
3424
3425
602
    shadow_iterator& operator++() {
3426
602
      Current = Current->getNextUsingShadowDecl();
3427
602
      return *this;
3428
602
    }
3429
3430
0
    shadow_iterator operator++(int) {
3431
0
      shadow_iterator tmp(*this);
3432
0
      ++(*this);
3433
0
      return tmp;
3434
0
    }
3435
3436
0
    friend bool operator==(shadow_iterator x, shadow_iterator y) {
3437
0
      return x.Current == y.Current;
3438
0
    }
3439
1.10k
    friend bool operator!=(shadow_iterator x, shadow_iterator y) {
3440
1.10k
      return x.Current != y.Current;
3441
1.10k
    }
3442
  };
3443
3444
  using shadow_range = llvm::iterator_range<shadow_iterator>;
3445
3446
468
  shadow_range shadows() const {
3447
468
    return shadow_range(shadow_begin(), shadow_end());
3448
468
  }
3449
3450
582
  shadow_iterator shadow_begin() const {
3451
582
    return shadow_iterator(FirstUsingShadow.getPointer());
3452
582
  }
3453
3454
508
  shadow_iterator shadow_end() const { return shadow_iterator(); }
3455
3456
  /// Return the number of shadowed declarations associated with this
3457
  /// using declaration.
3458
  unsigned shadow_size() const {
3459
    return std::distance(shadow_begin(), shadow_end());
3460
  }
3461
3462
  void addShadowDecl(UsingShadowDecl *S);
3463
  void removeShadowDecl(UsingShadowDecl *S);
3464
3465
  static UsingDecl *Create(ASTContext &C, DeclContext *DC,
3466
                           SourceLocation UsingL,
3467
                           NestedNameSpecifierLoc QualifierLoc,
3468
                           const DeclarationNameInfo &NameInfo,
3469
                           bool HasTypenameKeyword);
3470
3471
  static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3472
3473
  SourceRange getSourceRange() const override LLVM_READONLY;
3474
3475
  /// Retrieves the canonical declaration of this declaration.
3476
222k
  UsingDecl *getCanonicalDecl() override { return getFirstDecl(); }
3477
0
  const UsingDecl *getCanonicalDecl() const { return getFirstDecl(); }
3478
3479
28.5M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3480
28.5M
  static bool classofKind(Kind K) { return K == Using; }
3481
};
3482
3483
/// Represents a pack of using declarations that a single
3484
/// using-declarator pack-expanded into.
3485
///
3486
/// \code
3487
/// template<typename ...T> struct X : T... {
3488
///   using T::operator()...;
3489
///   using T::operator T...;
3490
/// };
3491
/// \endcode
3492
///
3493
/// In the second case above, the UsingPackDecl will have the name
3494
/// 'operator T' (which contains an unexpanded pack), but the individual
3495
/// UsingDecls and UsingShadowDecls will have more reasonable names.
3496
class UsingPackDecl final
3497
    : public NamedDecl, public Mergeable<UsingPackDecl>,
3498
      private llvm::TrailingObjects<UsingPackDecl, NamedDecl *> {
3499
  /// The UnresolvedUsingValueDecl or UnresolvedUsingTypenameDecl from
3500
  /// which this waas instantiated.
3501
  NamedDecl *InstantiatedFrom;
3502
3503
  /// The number of using-declarations created by this pack expansion.
3504
  unsigned NumExpansions;
3505
3506
  UsingPackDecl(DeclContext *DC, NamedDecl *InstantiatedFrom,
3507
                ArrayRef<NamedDecl *> UsingDecls)
3508
      : NamedDecl(UsingPack, DC,
3509
                  InstantiatedFrom ? InstantiatedFrom->getLocation()
3510
                                   : SourceLocation(),
3511
                  InstantiatedFrom ? InstantiatedFrom->getDeclName()
3512
                                   : DeclarationName()),
3513
45
        InstantiatedFrom(InstantiatedFrom), NumExpansions(UsingDecls.size()) {
3514
45
    std::uninitialized_copy(UsingDecls.begin(), UsingDecls.end(),
3515
45
                            getTrailingObjects<NamedDecl *>());
3516
45
  }
3517
3518
  void anchor() override;
3519
3520
public:
3521
  friend class ASTDeclReader;
3522
  friend class ASTDeclWriter;
3523
  friend TrailingObjects;
3524
3525
  /// Get the using declaration from which this was instantiated. This will
3526
  /// always be an UnresolvedUsingValueDecl or an UnresolvedUsingTypenameDecl
3527
  /// that is a pack expansion.
3528
33
  NamedDecl *getInstantiatedFromUsingDecl() const { return InstantiatedFrom; }
3529
3530
  /// Get the set of using declarations that this pack expanded into. Note that
3531
  /// some of these may still be unresolved.
3532
40
  ArrayRef<NamedDecl *> expansions() const {
3533
40
    return llvm::makeArrayRef(getTrailingObjects<NamedDecl *>(), NumExpansions);
3534
40
  }
3535
3536
  static UsingPackDecl *Create(ASTContext &C, DeclContext *DC,
3537
                               NamedDecl *InstantiatedFrom,
3538
                               ArrayRef<NamedDecl *> UsingDecls);
3539
3540
  static UsingPackDecl *CreateDeserialized(ASTContext &C, unsigned ID,
3541
                                           unsigned NumExpansions);
3542
3543
0
  SourceRange getSourceRange() const override LLVM_READONLY {
3544
0
    return InstantiatedFrom->getSourceRange();
3545
0
  }
3546
3547
3
  UsingPackDecl *getCanonicalDecl() override { return getFirstDecl(); }
3548
0
  const UsingPackDecl *getCanonicalDecl() const { return getFirstDecl(); }
3549
3550
1.78M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3551
1.78M
  static bool classofKind(Kind K) { return K == UsingPack; }
3552
};
3553
3554
/// Represents a dependent using declaration which was not marked with
3555
/// \c typename.
3556
///
3557
/// Unlike non-dependent using declarations, these *only* bring through
3558
/// non-types; otherwise they would break two-phase lookup.
3559
///
3560
/// \code
3561
/// template \<class T> class A : public Base<T> {
3562
///   using Base<T>::foo;
3563
/// };
3564
/// \endcode
3565
class UnresolvedUsingValueDecl : public ValueDecl,
3566
                                 public Mergeable<UnresolvedUsingValueDecl> {
3567
  /// The source location of the 'using' keyword
3568
  SourceLocation UsingLocation;
3569
3570
  /// If this is a pack expansion, the location of the '...'.
3571
  SourceLocation EllipsisLoc;
3572
3573
  /// The nested-name-specifier that precedes the name.
3574
  NestedNameSpecifierLoc QualifierLoc;
3575
3576
  /// Provides source/type location info for the declaration name
3577
  /// embedded in the ValueDecl base class.
3578
  DeclarationNameLoc DNLoc;
3579
3580
  UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
3581
                           SourceLocation UsingLoc,
3582
                           NestedNameSpecifierLoc QualifierLoc,
3583
                           const DeclarationNameInfo &NameInfo,
3584
                           SourceLocation EllipsisLoc)
3585
      : ValueDecl(UnresolvedUsingValue, DC,
3586
                  NameInfo.getLoc(), NameInfo.getName(), Ty),
3587
        UsingLocation(UsingLoc), EllipsisLoc(EllipsisLoc),
3588
408
        QualifierLoc(QualifierLoc), DNLoc(NameInfo.getInfo()) {}
3589
3590
  void anchor() override;
3591
3592
public:
3593
  friend class ASTDeclReader;
3594
  friend class ASTDeclWriter;
3595
3596
  /// Returns the source location of the 'using' keyword.
3597
401
  SourceLocation getUsingLoc() const { return UsingLocation; }
3598
3599
  /// Set the source location of the 'using' keyword.
3600
39
  void setUsingLoc(SourceLocation L) { UsingLocation = L; }
3601
3602
  /// Return true if it is a C++03 access declaration (no 'using').
3603
91
  bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
3604
3605
  /// Retrieve the nested-name-specifier that qualifies the name,
3606
  /// with source-location information.
3607
453
  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3608
3609
  /// Retrieve the nested-name-specifier that qualifies the name.
3610
111
  NestedNameSpecifier *getQualifier() const {
3611
111
    return QualifierLoc.getNestedNameSpecifier();
3612
111
  }
3613
3614
462
  DeclarationNameInfo getNameInfo() const {
3615
462
    return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
3616
462
  }
3617
3618
  /// Determine whether this is a pack expansion.
3619
655
  bool isPackExpansion() const {
3620
655
    return EllipsisLoc.isValid();
3621
655
  }
3622
3623
  /// Get the location of the ellipsis if this is a pack expansion.
3624
741
  SourceLocation getEllipsisLoc() const {
3625
741
    return EllipsisLoc;
3626
741
  }
3627
3628
  static UnresolvedUsingValueDecl *
3629
    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
3630
           NestedNameSpecifierLoc QualifierLoc,
3631
           const DeclarationNameInfo &NameInfo, SourceLocation EllipsisLoc);
3632
3633
  static UnresolvedUsingValueDecl *
3634
  CreateDeserialized(ASTContext &C, unsigned ID);
3635
3636
  SourceRange getSourceRange() const override LLVM_READONLY;
3637
3638
  /// Retrieves the canonical declaration of this declaration.
3639
915
  UnresolvedUsingValueDecl *getCanonicalDecl() override {
3640
915
    return getFirstDecl();
3641
915
  }
3642
0
  const UnresolvedUsingValueDecl *getCanonicalDecl() const {
3643
0
    return getFirstDecl();
3644
0
  }
3645
3646
140M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3647
140M
  static bool classofKind(Kind K) { return K == UnresolvedUsingValue; }
3648
};
3649
3650
/// Represents a dependent using declaration which was marked with
3651
/// \c typename.
3652
///
3653
/// \code
3654
/// template \<class T> class A : public Base<T> {
3655
///   using typename Base<T>::foo;
3656
/// };
3657
/// \endcode
3658
///
3659
/// The type associated with an unresolved using typename decl is
3660
/// currently always a typename type.
3661
class UnresolvedUsingTypenameDecl
3662
    : public TypeDecl,
3663
      public Mergeable<UnresolvedUsingTypenameDecl> {
3664
  friend class ASTDeclReader;
3665
3666
  /// The source location of the 'typename' keyword
3667
  SourceLocation TypenameLocation;
3668
3669
  /// If this is a pack expansion, the location of the '...'.
3670
  SourceLocation EllipsisLoc;
3671
3672
  /// The nested-name-specifier that precedes the name.
3673
  NestedNameSpecifierLoc QualifierLoc;
3674
3675
  UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
3676
                              SourceLocation TypenameLoc,
3677
                              NestedNameSpecifierLoc QualifierLoc,
3678
                              SourceLocation TargetNameLoc,
3679
                              IdentifierInfo *TargetName,
3680
                              SourceLocation EllipsisLoc)
3681
    : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName,
3682
               UsingLoc),
3683
      TypenameLocation(TypenameLoc), EllipsisLoc(EllipsisLoc),
3684
147
      QualifierLoc(QualifierLoc) {}
3685
3686
  void anchor() override;
3687
3688
public:
3689
  /// Returns the source location of the 'using' keyword.
3690
103
  SourceLocation getUsingLoc() const { return getBeginLoc(); }
3691
3692
  /// Returns the source location of the 'typename' keyword.
3693
157
  SourceLocation getTypenameLoc() const { return TypenameLocation; }
3694
3695
  /// Retrieve the nested-name-specifier that qualifies the name,
3696
  /// with source-location information.
3697
174
  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3698
3699
  /// Retrieve the nested-name-specifier that qualifies the name.
3700
44
  NestedNameSpecifier *getQualifier() const {
3701
44
    return QualifierLoc.getNestedNameSpecifier();
3702
44
  }
3703
3704
112
  DeclarationNameInfo getNameInfo() const {
3705
112
    return DeclarationNameInfo(getDeclName(), getLocation());
3706
112
  }
3707
3708
  /// Determine whether this is a pack expansion.
3709
147
  bool isPackExpansion() const {
3710
147
    return EllipsisLoc.isValid();
3711
147
  }
3712
3713
  /// Get the location of the ellipsis if this is a pack expansion.
3714
256
  SourceLocation getEllipsisLoc() const {
3715
256
    return EllipsisLoc;
3716
256
  }
3717
3718
  static UnresolvedUsingTypenameDecl *
3719
    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
3720
           SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc,
3721
           SourceLocation TargetNameLoc, DeclarationName TargetName,
3722
           SourceLocation EllipsisLoc);
3723
3724
  static UnresolvedUsingTypenameDecl *
3725
  CreateDeserialized(ASTContext &C, unsigned ID);
3726
3727
  /// Retrieves the canonical declaration of this declaration.
3728
377
  UnresolvedUsingTypenameDecl *getCanonicalDecl() override {
3729
377
    return getFirstDecl();
3730
377
  }
3731
0
  const UnresolvedUsingTypenameDecl *getCanonicalDecl() const {
3732
0
    return getFirstDecl();
3733
0
  }
3734
3735
3.86M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3736
3.86M
  static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; }
3737
};
3738
3739
/// Represents a C++11 static_assert declaration.
3740
class StaticAssertDecl : public Decl {
3741
  llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed;
3742
  StringLiteral *Message;
3743
  SourceLocation RParenLoc;
3744
3745
  StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc,
3746
                   Expr *AssertExpr, StringLiteral *Message,
3747
                   SourceLocation RParenLoc, bool Failed)
3748
      : Decl(StaticAssert, DC, StaticAssertLoc),
3749
        AssertExprAndFailed(AssertExpr, Failed), Message(Message),
3750
64.7k
        RParenLoc(RParenLoc) {}
3751
3752
  virtual void anchor();
3753
3754
public:
3755
  friend class ASTDeclReader;
3756
3757
  static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
3758
                                  SourceLocation StaticAssertLoc,
3759
                                  Expr *AssertExpr, StringLiteral *Message,
3760
                                  SourceLocation RParenLoc, bool Failed);
3761
  static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3762
3763
31.4k
  Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); }
3764
53
  const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); }
3765
3766
31.4k
  StringLiteral *getMessage() { return Message; }
3767
50
  const StringLiteral *getMessage() const { return Message; }
3768
3769
60.7k
  bool isFailed() const { return AssertExprAndFailed.getInt(); }
3770
3771
31.3k
  SourceLocation getRParenLoc() const { return RParenLoc; }
3772
3773
28
  SourceRange getSourceRange() const override LLVM_READONLY {
3774
28
    return SourceRange(getLocation(), getRParenLoc());
3775
28
  }
3776
3777
3.54M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3778
3.54M
  static bool classofKind(Kind K) { return K == StaticAssert; }
3779
};
3780
3781
/// A binding in a decomposition declaration. For instance, given:
3782
///
3783
///   int n[3];
3784
///   auto &[a, b, c] = n;
3785
///
3786
/// a, b, and c are BindingDecls, whose bindings are the expressions
3787
/// x[0], x[1], and x[2] respectively, where x is the implicit
3788
/// DecompositionDecl of type 'int (&)[3]'.
3789
class BindingDecl : public ValueDecl {
3790
  /// The binding represented by this declaration. References to this
3791
  /// declaration are effectively equivalent to this expression (except
3792
  /// that it is only evaluated once at the point of declaration of the
3793
  /// binding).
3794
  Expr *Binding = nullptr;
3795
3796
  BindingDecl(DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id)
3797
499
      : ValueDecl(Decl::Binding, DC, IdLoc, Id, QualType()) {}
3798
3799
  void anchor() override;
3800
3801
public:
3802
  friend class ASTDeclReader;
3803
3804
  static BindingDecl *Create(ASTContext &C, DeclContext *DC,
3805
                             SourceLocation IdLoc, IdentifierInfo *Id);
3806
  static BindingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3807
3808
  /// Get the expression to which this declaration is bound. This may be null
3809
  /// in two different cases: while parsing the initializer for the
3810
  /// decomposition declaration, and when the initializer is type-dependent.
3811
679
  Expr *getBinding() const { return Binding; }
3812
3813
  /// Get the variable (if any) that holds the value of evaluating the binding.
3814
  /// Only present for user-defined bindings for tuple-like types.
3815
  VarDecl *getHoldingVar() const;
3816
3817
  /// Set the binding for this BindingDecl, along with its declared type (which
3818
  /// should be a possibly-cv-qualified form of the type of the binding, or a
3819
  /// reference to such a type).
3820
398
  void setBinding(QualType DeclaredType, Expr *Binding) {
3821
398
    setType(DeclaredType);
3822
398
    this->Binding = Binding;
3823
398
  }
3824
3825
22.7M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3826
22.7M
  static bool classofKind(Kind K) { return K == Decl::Binding; }
3827
};
3828
3829
/// A decomposition declaration. For instance, given:
3830
///
3831
///   int n[3];
3832
///   auto &[a, b, c] = n;
3833
///
3834
/// the second line declares a DecompositionDecl of type 'int (&)[3]', and
3835
/// three BindingDecls (named a, b, and c). An instance of this class is always
3836
/// unnamed, but behaves in almost all other respects like a VarDecl.
3837
class DecompositionDecl final
3838
    : public VarDecl,
3839
      private llvm::TrailingObjects<DecompositionDecl, BindingDecl *> {
3840
  /// The number of BindingDecl*s following this object.
3841
  unsigned NumBindings;
3842
3843
  DecompositionDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3844
                    SourceLocation LSquareLoc, QualType T,
3845
                    TypeSourceInfo *TInfo, StorageClass SC,
3846
                    ArrayRef<BindingDecl *> Bindings)
3847
      : VarDecl(Decomposition, C, DC, StartLoc, LSquareLoc, nullptr, T, TInfo,
3848
                SC),
3849
280
        NumBindings(Bindings.size()) {
3850
280
    std::uninitialized_copy(Bindings.begin(), Bindings.end(),
3851
280
                            getTrailingObjects<BindingDecl *>());
3852
280
  }
3853
3854
  void anchor() override;
3855
3856
public:
3857
  friend class ASTDeclReader;
3858
  friend TrailingObjects;
3859
3860
  static DecompositionDecl *Create(ASTContext &C, DeclContext *DC,
3861
                                   SourceLocation StartLoc,
3862
                                   SourceLocation LSquareLoc,
3863
                                   QualType T, TypeSourceInfo *TInfo,
3864
                                   StorageClass S,
3865
                                   ArrayRef<BindingDecl *> Bindings);
3866
  static DecompositionDecl *CreateDeserialized(ASTContext &C, unsigned ID,
3867
                                               unsigned NumBindings);
3868
3869
932
  ArrayRef<BindingDecl *> bindings() const {
3870
932
    return llvm::makeArrayRef(getTrailingObjects<BindingDecl *>(), NumBindings);
3871
932
  }
3872
3873
  void printName(raw_ostream &os) const override;
3874
3875
45.2M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3876
45.2M
  static bool classofKind(Kind K) { return K == Decomposition; }
3877
};
3878
3879
/// An instance of this class represents the declaration of a property
3880
/// member.  This is a Microsoft extension to C++, first introduced in
3881
/// Visual Studio .NET 2003 as a parallel to similar features in C#
3882
/// and Managed C++.
3883
///
3884
/// A property must always be a non-static class member.
3885
///
3886
/// A property member superficially resembles a non-static data
3887
/// member, except preceded by a property attribute:
3888
///   __declspec(property(get=GetX, put=PutX)) int x;
3889
/// Either (but not both) of the 'get' and 'put' names may be omitted.
3890
///
3891
/// A reference to a property is always an lvalue.  If the lvalue
3892
/// undergoes lvalue-to-rvalue conversion, then a getter name is
3893
/// required, and that member is called with no arguments.
3894
/// If the lvalue is assigned into, then a setter name is required,
3895
/// and that member is called with one argument, the value assigned.
3896
/// Both operations are potentially overloaded.  Compound assignments
3897
/// are permitted, as are the increment and decrement operators.
3898
///
3899
/// The getter and putter methods are permitted to be overloaded,
3900
/// although their return and parameter types are subject to certain
3901
/// restrictions according to the type of the property.
3902
///
3903
/// A property declared using an incomplete array type may
3904
/// additionally be subscripted, adding extra parameters to the getter
3905
/// and putter methods.
3906
class MSPropertyDecl : public DeclaratorDecl {
3907
  IdentifierInfo *GetterId, *SetterId;
3908
3909
  MSPropertyDecl(DeclContext *DC, SourceLocation L, DeclarationName N,
3910
                 QualType T, TypeSourceInfo *TInfo, SourceLocation StartL,
3911
                 IdentifierInfo *Getter, IdentifierInfo *Setter)
3912
      : DeclaratorDecl(MSProperty, DC, L, N, T, TInfo, StartL),
3913
135
        GetterId(Getter), SetterId(Setter) {}
3914
3915
public:
3916
  friend class ASTDeclReader;
3917
3918
  static MSPropertyDecl *Create(ASTContext &C, DeclContext *DC,
3919
                                SourceLocation L, DeclarationName N, QualType T,
3920
                                TypeSourceInfo *TInfo, SourceLocation StartL,
3921
                                IdentifierInfo *Getter, IdentifierInfo *Setter);
3922
  static MSPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3923
3924
6.68M
  static bool classof(const Decl *D) { return D->getKind() == MSProperty; }
3925
3926
176
  bool hasGetter() const { return GetterId != nullptr; }
3927
213
  IdentifierInfo* getGetterId() const { return GetterId; }
3928
99
  bool hasSetter() const { return SetterId != nullptr; }
3929
123
  IdentifierInfo* getSetterId() const { return SetterId; }
3930
};
3931
3932
/// Insertion operator for diagnostics.  This allows sending an AccessSpecifier
3933
/// into a diagnostic with <<.
3934
const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
3935
                                    AccessSpecifier AS);
3936
3937
const PartialDiagnostic &operator<<(const PartialDiagnostic &DB,
3938
                                    AccessSpecifier AS);
3939
3940
} // namespace clang
3941
3942
#endif // LLVM_CLANG_AST_DECLCXX_H