Coverage Report

Created: 2018-07-19 20:53

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