Coverage Report

Created: 2018-09-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
464k
    : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) {
139
464k
    setAccess(AS);
140
464k
  }
141
142
0
  AccessSpecDecl(EmptyShell Empty) : Decl(AccessSpec, Empty) {}
143
144
  virtual void anchor();
145
146
public:
147
  /// The location of the access specifier.
148
212k
  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
212k
  SourceLocation getColonLoc() const { return ColonLoc; }
155
156
  /// Sets the location of the colon.
157
0
  void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; }
158
159
0
  SourceRange getSourceRange() const override LLVM_READONLY {
160
0
    return SourceRange(getAccessSpecifierLoc(), getColonLoc());
161
0
  }
162
163
  static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS,
164
                                DeclContext *DC, SourceLocation ASLoc,
165
464k
                                SourceLocation ColonLoc) {
166
464k
    return new (C, DC) AccessSpecDecl(AS, DC, ASLoc, ColonLoc);
167
464k
  }
168
169
  static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
170
171
  // Implement isa/cast/dyncast/etc.
172
8
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
173
8
  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
758k
  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
528k
      Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) {}
233
234
  /// Retrieves the source range that contains the entire base specifier.
235
602k
  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
236
157k
  SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
237
0
  SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
238
239
  /// Get the location at which the base class type was written.
240
72.1k
  SourceLocation getBaseTypeLoc() const LLVM_READONLY {
241
72.1k
    return BaseTypeInfo->getTypeLoc().getBeginLoc();
242
72.1k
  }
243
244
  /// Determines whether the base class is a virtual base class (or not).
245
12.6M
  bool isVirtual() const { return Virtual; }
246
247
  /// Determine whether this base class is a base of a class declared
248
  /// with the 'class' keyword (vs. one declared with the 'struct' keyword).
249
0
  bool isBaseOfClass() const { return BaseOfClass; }
250
251
  /// Determine whether this base specifier is a pack expansion.
252
289k
  bool isPackExpansion() const { return EllipsisLoc.isValid(); }
253
254
  /// Determine whether this base class's constructors get inherited.
255
0
  bool getInheritConstructors() const { return InheritConstructors; }
256
257
  /// Set that this base class's constructors should be inherited.
258
0
  void setInheritConstructors(bool Inherit = true) {
259
0
    InheritConstructors = Inherit;
260
0
  }
261
262
  /// For a pack expansion, determine the location of the ellipsis.
263
262
  SourceLocation getEllipsisLoc() const {
264
262
    return EllipsisLoc;
265
262
  }
266
267
  /// Returns the access specifier for this base specifier.
268
  ///
269
  /// This is the actual base specifier as used for semantic analysis, so
270
  /// the result can never be AS_none. To retrieve the access specifier as
271
  /// written in the source code, use getAccessSpecifierAsWritten().
272
5.17M
  AccessSpecifier getAccessSpecifier() const {
273
5.17M
    if ((AccessSpecifier)Access == AS_none)
274
401k
      return BaseOfClass? 
AS_private357
:
AS_public401k
;
275
4.76M
    else
276
4.76M
      return (AccessSpecifier)Access;
277
5.17M
  }
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
289k
  AccessSpecifier getAccessSpecifierAsWritten() const {
285
289k
    return (AccessSpecifier)Access;
286
289k
  }
287
288
  /// Retrieves the type of the base class.
289
  ///
290
  /// This type will always be an unqualified class type.
291
19.8M
  QualType getType() const {
292
19.8M
    return BaseTypeInfo->getType().getUnqualifiedType();
293
19.8M
  }
294
295
  /// Retrieves the type and source location of the base class.
296
290k
  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
44.7M
    CXXBaseSpecifier *getBases() const {
576
44.7M
      if (!Bases.isOffset())
577
44.7M
        return Bases.get(nullptr);
578
0
      return getBasesSlowCase();
579
0
    }
580
581
    /// Retrieve the set of virtual base classes.
582
3.19M
    CXXBaseSpecifier *getVBases() const {
583
3.19M
      if (!VBases.isOffset())
584
3.19M
        return VBases.get(nullptr);
585
0
      return getVBasesSlowCase();
586
0
    }
587
588
0
    ArrayRef<CXXBaseSpecifier> bases() const {
589
0
      return llvm::makeArrayRef(getBases(), NumBases);
590
0
    }
591
592
0
    ArrayRef<CXXBaseSpecifier> vbases() const {
593
0
      return llvm::makeArrayRef(getVBases(), NumVBases);
594
0
    }
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
611
        MethodTyInfo(Info) {
652
611
      IsLambda = true;
653
611
654
611
      // C++1z [expr.prim.lambda]p4:
655
611
      //   This class type is not an aggregate type.
656
611
      Aggregate = false;
657
611
      PlainOldData = false;
658
611
    }
659
  };
660
661
283M
  struct DefinitionData *dataPtr() const {
662
283M
    // Complete the redecl chain (if necessary).
663
283M
    getMostRecentDecl();
664
283M
    return DefinitionData;
665
283M
  }
666
667
282M
  struct DefinitionData &data() const {
668
282M
    auto *DD = dataPtr();
669
282M
    assert(DD && "queried property of class with no definition");
670
282M
    return *DD;
671
282M
  }
672
673
41.7k
  struct LambdaDefinitionData &getLambdaData() const {
674
41.7k
    // No update required: a merged definition cannot change any lambda
675
41.7k
    // properties.
676
41.7k
    auto *DD = DefinitionData;
677
41.7k
    assert(DD && DD->IsLambda && "queried lambda property of non-lambda class");
678
41.7k
    return static_cast<LambdaDefinitionData&>(*DD);
679
41.7k
  }
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
36.2M
  CXXRecordDecl *getCanonicalDecl() override {
729
36.2M
    return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
730
36.2M
  }
731
732
9.27M
  const CXXRecordDecl *getCanonicalDecl() const {
733
9.27M
    return const_cast<CXXRecordDecl*>(this)->getCanonicalDecl();
734
9.27M
  }
735
736
2.84M
  CXXRecordDecl *getPreviousDecl() {
737
2.84M
    return cast_or_null<CXXRecordDecl>(
738
2.84M
            static_cast<RecordDecl *>(this)->getPreviousDecl());
739
2.84M
  }
740
741
1.26M
  const CXXRecordDecl *getPreviousDecl() const {
742
1.26M
    return const_cast<CXXRecordDecl*>(this)->getPreviousDecl();
743
1.26M
  }
744
745
285M
  CXXRecordDecl *getMostRecentDecl() {
746
285M
    return cast<CXXRecordDecl>(
747
285M
            static_cast<RecordDecl *>(this)->getMostRecentDecl());
748
285M
  }
749
750
283M
  const CXXRecordDecl *getMostRecentDecl() const {
751
283M
    return const_cast<CXXRecordDecl*>(this)->getMostRecentDecl();
752
283M
  }
753
754
2.12M
  CXXRecordDecl *getMostRecentNonInjectedDecl() {
755
2.12M
    CXXRecordDecl *Recent =
756
2.12M
        static_cast<CXXRecordDecl *>(this)->getMostRecentDecl();
757
3.22M
    while (Recent->isInjectedClassName()) {
758
1.10M
      // FIXME: Does injected class name need to be in the redeclarations chain?
759
1.10M
      assert(Recent->getPreviousDecl());
760
1.10M
      Recent = Recent->getPreviousDecl();
761
1.10M
    }
762
2.12M
    return Recent;
763
2.12M
  }
764
765
0
  const CXXRecordDecl *getMostRecentNonInjectedDecl() const {
766
0
    return const_cast<CXXRecordDecl*>(this)->getMostRecentNonInjectedDecl();
767
0
  }
768
769
75.3M
  CXXRecordDecl *getDefinition() const {
770
75.3M
    // We only need an update if we don't already know which
771
75.3M
    // declaration is the definition.
772
75.3M
    auto *DD = DefinitionData ? 
DefinitionData74.9M
:
dataPtr()379k
;
773
75.3M
    return DD ? 
DD->Definition74.9M
:
nullptr379k
;
774
75.3M
  }
775
776
1.52M
  bool hasDefinition() const { return DefinitionData || 
dataPtr()3
; }
777
778
  static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
779
                               SourceLocation StartLoc, SourceLocation IdLoc,
780
                               IdentifierInfo *Id,
781
                               CXXRecordDecl *PrevDecl = nullptr,
782
                               bool DelayTypeCreation = false);
783
  static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC,
784
                                     TypeSourceInfo *Info, SourceLocation Loc,
785
                                     bool DependentLambda, bool IsGeneric,
786
                                     LambdaCaptureDefault CaptureDefault);
787
  static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
788
789
5.06M
  bool isDynamicClass() const {
790
5.06M
    return data().Polymorphic || 
data().NumVBases != 04.86M
;
791
5.06M
  }
792
793
  /// @returns true if class is dynamic or might be dynamic because the
794
  /// definition is incomplete of dependent.
795
0
  bool mayBeDynamicClass() const {
796
0
    return !hasDefinition() || isDynamicClass() || hasAnyDependentBases();
797
0
  }
798
799
  /// @returns true if class is non dynamic or might be non dynamic because the
800
  /// definition is incomplete of dependent.
801
0
  bool mayBeNonDynamicClass() const {
802
0
    return !hasDefinition() || !isDynamicClass() || hasAnyDependentBases();
803
0
  }
804
805
238k
  void setIsParsingBaseSpecifiers() { data().IsParsingBaseSpecifiers = true; }
806
807
0
  bool isParsingBaseSpecifiers() const {
808
0
    return data().IsParsingBaseSpecifiers;
809
0
  }
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
200k
  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.49M
  base_class_range bases() {
824
3.49M
    return base_class_range(bases_begin(), bases_end());
825
3.49M
  }
826
16.2M
  base_class_const_range bases() const {
827
16.2M
    return base_class_const_range(bases_begin(), bases_end());
828
16.2M
  }
829
830
11.3M
  base_class_iterator bases_begin() { return data().getBases(); }
831
32.6M
  base_class_const_iterator bases_begin() const { return data().getBases(); }
832
5.67M
  base_class_iterator bases_end() { return bases_begin() + data().NumBases; }
833
16.3M
  base_class_const_iterator bases_end() const {
834
16.3M
    return bases_begin() + data().NumBases;
835
16.3M
  }
836
837
  /// Retrieves the number of virtual base classes of this class.
838
2.21M
  unsigned getNumVBases() const { return data().NumVBases; }
839
840
1.39M
  base_class_range vbases() {
841
1.39M
    return base_class_range(vbases_begin(), vbases_end());
842
1.39M
  }
843
200k
  base_class_const_range vbases() const {
844
200k
    return base_class_const_range(vbases_begin(), vbases_end());
845
200k
  }
846
847
2.79M
  base_class_iterator vbases_begin() { return data().getVBases(); }
848
400k
  base_class_const_iterator vbases_begin() const { return data().getVBases(); }
849
1.39M
  base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; }
850
200k
  base_class_const_iterator vbases_end() const {
851
200k
    return vbases_begin() + data().NumVBases;
852
200k
  }
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.40M
  method_range methods() const {
866
4.40M
    return method_range(method_begin(), method_end());
867
4.40M
  }
868
869
  /// Method begin iterator.  Iterates in the order the methods
870
  /// were declared.
871
4.40M
  method_iterator method_begin() const {
872
4.40M
    return method_iterator(decls_begin());
873
4.40M
  }
874
875
  /// Method past-the-end iterator.
876
4.40M
  method_iterator method_end() const {
877
4.40M
    return method_iterator(decls_end());
878
4.40M
  }
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
1.06k
  ctor_range ctors() const { return ctor_range(ctor_begin(), ctor_end()); }
886
887
1.06k
  ctor_iterator ctor_begin() const {
888
1.06k
    return ctor_iterator(decls_begin());
889
1.06k
  }
890
891
1.06k
  ctor_iterator ctor_end() const {
892
1.06k
    return ctor_iterator(decls_end());
893
1.06k
  }
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
0
  bool hasFriends() const {
907
0
    return data().FirstFriend.isValid();
908
0
  }
909
910
  /// \c true if a defaulted copy constructor for this class would be
911
  /// deleted.
912
1.23M
  bool defaultedCopyConstructorIsDeleted() const {
913
1.23M
    assert((!needsOverloadResolutionForCopyConstructor() ||
914
1.23M
            (data().DeclaredSpecialMembers & SMF_CopyConstructor)) &&
915
1.23M
           "this property has not yet been computed by Sema");
916
1.23M
    return data().DefaultedCopyConstructorIsDeleted;
917
1.23M
  }
918
919
  /// \c true if a defaulted move constructor for this class would be
920
  /// deleted.
921
1.20M
  bool defaultedMoveConstructorIsDeleted() const {
922
1.20M
    assert((!needsOverloadResolutionForMoveConstructor() ||
923
1.20M
            (data().DeclaredSpecialMembers & SMF_MoveConstructor)) &&
924
1.20M
           "this property has not yet been computed by Sema");
925
1.20M
    return data().DefaultedMoveConstructorIsDeleted;
926
1.20M
  }
927
928
  /// \c true if a defaulted destructor for this class would be deleted.
929
1.23M
  bool defaultedDestructorIsDeleted() const {
930
1.23M
    assert((!needsOverloadResolutionForDestructor() ||
931
1.23M
            (data().DeclaredSpecialMembers & SMF_Destructor)) &&
932
1.23M
           "this property has not yet been computed by Sema");
933
1.23M
    return data().DefaultedDestructorIsDeleted;
934
1.23M
  }
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
977k
  bool hasSimpleCopyConstructor() const {
939
977k
    return !hasUserDeclaredCopyConstructor() &&
940
977k
           
!data().DefaultedCopyConstructorIsDeleted941k
;
941
977k
  }
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
977k
  bool hasSimpleMoveConstructor() const {
946
977k
    return !hasUserDeclaredMoveConstructor() && 
hasMoveConstructor()961k
&&
947
977k
           
!data().DefaultedMoveConstructorIsDeleted908k
;
948
977k
  }
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
977k
  bool hasSimpleMoveAssignment() const {
953
977k
    return !hasUserDeclaredMoveAssignment() && 
hasMoveAssignment()962k
&&
954
977k
           
!data().DefaultedMoveAssignmentIsDeleted908k
;
955
977k
  }
956
957
  /// \c true if we know for sure that this class has an accessible
958
  /// destructor that is not deleted.
959
977k
  bool hasSimpleDestructor() const {
960
977k
    return !hasUserDeclaredDestructor() &&
961
977k
           
!data().DefaultedDestructorIsDeleted916k
;
962
977k
  }
963
964
  /// Determine whether this class has any default constructors.
965
1.26M
  bool hasDefaultConstructor() const {
966
1.26M
    return (data().DeclaredSpecialMembers & SMF_DefaultConstructor) ||
967
1.26M
           
needsImplicitDefaultConstructor()736k
;
968
1.26M
  }
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.79M
  bool needsImplicitDefaultConstructor() const {
975
3.79M
    return !data().UserDeclaredConstructor &&
976
3.79M
           
!(data().DeclaredSpecialMembers & SMF_DefaultConstructor)2.96M
&&
977
3.79M
           // C++14 [expr.prim.lambda]p20:
978
3.79M
           //   The closure type associated with a lambda-expression has no
979
3.79M
           //   default constructor.
980
3.79M
           
!isLambda()2.88M
;
981
3.79M
  }
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.73M
  bool hasUserDeclaredConstructor() const {
987
1.73M
    return data().UserDeclaredConstructor;
988
1.73M
  }
989
990
  /// Whether this class has a user-provided default constructor
991
  /// per C++11.
992
0
  bool hasUserProvidedDefaultConstructor() const {
993
0
    return data().UserProvidedDefaultConstructor;
994
0
  }
995
996
  /// Determine whether this class has a user-declared copy constructor.
997
  ///
998
  /// When false, a copy constructor will be implicitly declared.
999
10.3M
  bool hasUserDeclaredCopyConstructor() const {
1000
10.3M
    return data().UserDeclaredSpecialMembers & SMF_CopyConstructor;
1001
10.3M
  }
1002
1003
  /// Determine whether this class needs an implicit copy
1004
  /// constructor to be lazily declared.
1005
3.82M
  bool needsImplicitCopyConstructor() const {
1006
3.82M
    return !(data().DeclaredSpecialMembers & SMF_CopyConstructor);
1007
3.82M
  }
1008
1009
  /// Determine whether we need to eagerly declare a defaulted copy
1010
  /// constructor for this class.
1011
1.51M
  bool needsOverloadResolutionForCopyConstructor() const {
1012
1.51M
    // C++17 [class.copy.ctor]p6:
1013
1.51M
    //   If the class definition declares a move constructor or move assignment
1014
1.51M
    //   operator, the implicitly declared copy constructor is defined as
1015
1.51M
    //   deleted.
1016
1.51M
    // In MSVC mode, sometimes a declared move assignment does not delete an
1017
1.51M
    // implicit copy constructor, so defer this choice to Sema.
1018
1.51M
    if (data().UserDeclaredSpecialMembers &
1019
1.51M
        (SMF_MoveConstructor | SMF_MoveAssignment))
1020
4.84k
      return true;
1021
1.50M
    return data().NeedOverloadResolutionForCopyConstructor;
1022
1.50M
  }
1023
1024
  /// Determine whether an implicit copy constructor for this type
1025
  /// would have a parameter with a const-qualified reference type.
1026
683k
  bool implicitCopyConstructorHasConstParam() const {
1027
683k
    return data().ImplicitCopyConstructorCanHaveConstParamForNonVBase &&
1028
683k
           
(683k
isAbstract()683k
||
1029
683k
            
data().ImplicitCopyConstructorCanHaveConstParamForVBase676k
);
1030
683k
  }
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
976k
  bool hasCopyConstructorWithConstParam() const {
1035
976k
    return data().HasDeclaredCopyConstructorWithConstParam ||
1036
976k
           
(561k
needsImplicitCopyConstructor()561k
&&
1037
561k
            
implicitCopyConstructorHasConstParam()561k
);
1038
976k
  }
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.42M
  bool hasUserDeclaredMoveConstructor() const {
1053
4.42M
    return data().UserDeclaredSpecialMembers & SMF_MoveConstructor;
1054
4.42M
  }
1055
1056
  /// Determine whether this class has a move constructor.
1057
4.26M
  bool hasMoveConstructor() const {
1058
4.26M
    return (data().DeclaredSpecialMembers & SMF_MoveConstructor) ||
1059
4.26M
           
needsImplicitMoveConstructor()3.17M
;
1060
4.26M
  }
1061
1062
  /// Set that we attempted to declare an implicit copy
1063
  /// constructor, but overload resolution failed so we deleted it.
1064
19.9k
  void setImplicitCopyConstructorIsDeleted() {
1065
19.9k
    assert((data().DefaultedCopyConstructorIsDeleted ||
1066
19.9k
            needsOverloadResolutionForCopyConstructor()) &&
1067
19.9k
           "Copy constructor should not be deleted");
1068
19.9k
    data().DefaultedCopyConstructorIsDeleted = true;
1069
19.9k
  }
1070
1071
  /// Set that we attempted to declare an implicit move
1072
  /// constructor, but overload resolution failed so we deleted it.
1073
5.36k
  void setImplicitMoveConstructorIsDeleted() {
1074
5.36k
    assert((data().DefaultedMoveConstructorIsDeleted ||
1075
5.36k
            needsOverloadResolutionForMoveConstructor()) &&
1076
5.36k
           "move constructor should not be deleted");
1077
5.36k
    data().DefaultedMoveConstructorIsDeleted = true;
1078
5.36k
  }
1079
1080
  /// Set that we attempted to declare an implicit destructor,
1081
  /// but overload resolution failed so we deleted it.
1082
183
  void setImplicitDestructorIsDeleted() {
1083
183
    assert((data().DefaultedDestructorIsDeleted ||
1084
183
            needsOverloadResolutionForDestructor()) &&
1085
183
           "destructor should not be deleted");
1086
183
    data().DefaultedDestructorIsDeleted = true;
1087
183
  }
1088
1089
  /// Determine whether this class should get an implicit move
1090
  /// constructor or if any existing special member function inhibits this.
1091
6.45M
  bool needsImplicitMoveConstructor() const {
1092
6.45M
    return !(data().DeclaredSpecialMembers & SMF_MoveConstructor) &&
1093
6.45M
           
!hasUserDeclaredCopyConstructor()6.00M
&&
1094
6.45M
           
!hasUserDeclaredCopyAssignment()5.82M
&&
1095
6.45M
           
!hasUserDeclaredMoveAssignment()5.82M
&&
1096
6.45M
           
!hasUserDeclaredDestructor()5.82M
;
1097
6.45M
  }
1098
1099
  /// Determine whether we need to eagerly declare a defaulted move
1100
  /// constructor for this class.
1101
1.39M
  bool needsOverloadResolutionForMoveConstructor() const {
1102
1.39M
    return data().NeedOverloadResolutionForMoveConstructor;
1103
1.39M
  }
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
9.11M
  bool hasUserDeclaredCopyAssignment() const {
1110
9.11M
    return data().UserDeclaredSpecialMembers & SMF_CopyAssignment;
1111
9.11M
  }
1112
1113
  /// Determine whether this class needs an implicit copy
1114
  /// assignment operator to be lazily declared.
1115
2.27M
  bool needsImplicitCopyAssignment() const {
1116
2.27M
    return !(data().DeclaredSpecialMembers & SMF_CopyAssignment);
1117
2.27M
  }
1118
1119
  /// Determine whether we need to eagerly declare a defaulted copy
1120
  /// assignment operator for this class.
1121
1.30M
  bool needsOverloadResolutionForCopyAssignment() const {
1122
1.30M
    return data().HasMutableFields;
1123
1.30M
  }
1124
1125
  /// Determine whether an implicit copy assignment operator for this
1126
  /// type would have a parameter with a const-qualified reference type.
1127
952k
  bool implicitCopyAssignmentHasConstParam() const {
1128
952k
    return data().ImplicitCopyAssignmentHasConstParam;
1129
952k
  }
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
976k
  bool hasCopyAssignmentWithConstParam() const {
1135
976k
    return data().HasDeclaredCopyAssignmentWithConstParam ||
1136
976k
           
(893k
needsImplicitCopyAssignment()893k
&&
1137
893k
            
implicitCopyAssignmentHasConstParam()893k
);
1138
976k
  }
1139
1140
  /// Determine whether this class has had a move assignment
1141
  /// declared by the user.
1142
6.96M
  bool hasUserDeclaredMoveAssignment() const {
1143
6.96M
    return data().UserDeclaredSpecialMembers & SMF_MoveAssignment;
1144
6.96M
  }
1145
1146
  /// Determine whether this class has a move assignment operator.
1147
1.96M
  bool hasMoveAssignment() const {
1148
1.96M
    return (data().DeclaredSpecialMembers & SMF_MoveAssignment) ||
1149
1.96M
           
needsImplicitMoveAssignment()1.90M
;
1150
1.96M
  }
1151
1152
  /// Set that we attempted to declare an implicit move assignment
1153
  /// operator, but overload resolution failed so we deleted it.
1154
8.21k
  void setImplicitMoveAssignmentIsDeleted() {
1155
8.21k
    assert((data().DefaultedMoveAssignmentIsDeleted ||
1156
8.21k
            needsOverloadResolutionForMoveAssignment()) &&
1157
8.21k
           "move assignment should not be deleted");
1158
8.21k
    data().DefaultedMoveAssignmentIsDeleted = true;
1159
8.21k
  }
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.40M
  bool needsImplicitMoveAssignment() const {
1165
3.40M
    return !(data().DeclaredSpecialMembers & SMF_MoveAssignment) &&
1166
3.40M
           
!hasUserDeclaredCopyConstructor()3.35M
&&
1167
3.40M
           
!hasUserDeclaredCopyAssignment()3.28M
&&
1168
3.40M
           
!hasUserDeclaredMoveConstructor()3.28M
&&
1169
3.40M
           
!hasUserDeclaredDestructor()3.28M
&&
1170
3.40M
           // C++1z [expr.prim.lambda]p21: "the closure type has a deleted copy
1171
3.40M
           // assignment operator". The intent is that this counts as a user
1172
3.40M
           // declared copy assignment, but we do not model it that way.
1173
3.40M
           
!isLambda()3.16M
;
1174
3.40M
  }
1175
1176
  /// Determine whether we need to eagerly declare a move assignment
1177
  /// operator for this class.
1178
1.25M
  bool needsOverloadResolutionForMoveAssignment() const {
1179
1.25M
    return data().NeedOverloadResolutionForMoveAssignment;
1180
1.25M
  }
1181
1182
  /// Determine whether this class has a user-declared destructor.
1183
  ///
1184
  /// When false, a destructor will be implicitly declared.
1185
10.0M
  bool hasUserDeclaredDestructor() const {
1186
10.0M
    return data().UserDeclaredSpecialMembers & SMF_Destructor;
1187
10.0M
  }
1188
1189
  /// Determine whether this class needs an implicit destructor to
1190
  /// be lazily declared.
1191
2.84M
  bool needsImplicitDestructor() const {
1192
2.84M
    return !(data().DeclaredSpecialMembers & SMF_Destructor);
1193
2.84M
  }
1194
1195
  /// Determine whether we need to eagerly declare a destructor for this
1196
  /// class.
1197
1.23M
  bool needsOverloadResolutionForDestructor() const {
1198
1.23M
    return data().NeedOverloadResolutionForDestructor;
1199
1.23M
  }
1200
1201
  /// Determine whether this class describes a lambda function object.
1202
75.6M
  bool isLambda() const {
1203
75.6M
    // An update record can't turn a non-lambda into a lambda.
1204
75.6M
    auto *DD = DefinitionData;
1205
75.6M
    return DD && 
DD->IsLambda70.5M
;
1206
75.6M
  }
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
302
  LambdaCaptureDefault getLambdaCaptureDefault() const {
1228
302
    assert(isLambda());
1229
302
    return static_cast<LambdaCaptureDefault>(getLambdaData().CaptureDefault);
1230
302
  }
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
0
  capture_const_range captures() const {
1251
0
    return capture_const_range(captures_begin(), captures_end());
1252
0
  }
1253
1254
5
  capture_const_iterator captures_begin() const {
1255
5
    return isLambda() ? getLambdaData().Captures : 
nullptr0
;
1256
5
  }
1257
1258
0
  capture_const_iterator captures_end() const {
1259
0
    return isLambda() ? captures_begin() + getLambdaData().NumCaptures
1260
0
                      : nullptr;
1261
0
  }
1262
1263
  using conversion_iterator = UnresolvedSetIterator;
1264
1265
3.43M
  conversion_iterator conversion_begin() const {
1266
3.43M
    return data().Conversions.get(getASTContext()).begin();
1267
3.43M
  }
1268
1269
3.43M
  conversion_iterator conversion_end() const {
1270
3.43M
    return data().Conversions.get(getASTContext()).end();
1271
3.43M
  }
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.36M
  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
23.4k
  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
976k
  bool hasUninitializedReferenceMember() const {
1302
976k
    return !isUnion() && 
!hasUserDeclaredConstructor()966k
&&
1303
976k
           
data().HasUninitializedReferenceMember863k
;
1304
976k
  }
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
440k
  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
946k
  bool isEmpty() const { return data().Empty; }
1330
1331
  /// Determine whether this class has direct non-static data members.
1332
614k
  bool hasDirectFields() const {
1333
614k
    auto &D = data();
1334
614k
    return D.HasPublicFields || 
D.HasProtectedFields609k
||
D.HasPrivateFields606k
;
1335
614k
  }
1336
1337
  /// Whether this class is polymorphic (C++ [class.virtual]),
1338
  /// which means that the class contains or inherits a virtual function.
1339
2.39M
  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.64M
  bool isAbstract() const { return data().Abstract; }
1347
1348
  /// Determine whether this class is standard-layout per
1349
  /// C++ [class]p7.
1350
1.00M
  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
1.00M
  bool isCXX11StandardLayout() const { return data().IsCXX11StandardLayout; }
1355
1356
  /// Determine whether this class, or any of its class subobjects,
1357
  /// contains a mutable field.
1358
982k
  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.26M
  bool hasTrivialDefaultConstructor() const {
1366
1.26M
    return hasDefaultConstructor() &&
1367
1.26M
           
(data().HasTrivialSpecialMembers & SMF_DefaultConstructor)1.22M
;
1368
1.26M
  }
1369
1370
  /// Determine whether this class has a non-trivial default constructor
1371
  /// (C++11 [class.ctor]p5).
1372
3
  bool hasNonTrivialDefaultConstructor() const {
1373
3
    return (data().DeclaredNonTrivialSpecialMembers & SMF_DefaultConstructor) ||
1374
3
           
(1
needsImplicitDefaultConstructor()1
&&
1375
1
            
!(data().HasTrivialSpecialMembers & SMF_DefaultConstructor)0
);
1376
3
  }
1377
1378
  /// Determine whether this class has at least one constexpr constructor
1379
  /// other than the copy or move constructors.
1380
224k
  bool hasConstexprNonCopyMoveConstructor() const {
1381
224k
    return data().HasConstexprNonCopyMoveConstructor ||
1382
224k
           
(195k
needsImplicitDefaultConstructor()195k
&&
1383
195k
            
defaultedDefaultConstructorIsConstexpr()127k
);
1384
224k
  }
1385
1386
  /// Determine whether a defaulted default constructor for this class
1387
  /// would be constexpr.
1388
718k
  bool defaultedDefaultConstructorIsConstexpr() const {
1389
718k
    return data().DefaultedDefaultConstructorIsConstexpr &&
1390
718k
           
(398k
!isUnion()398k
||
hasInClassInitializer()14.4k
||
!hasVariantMembers()14.4k
);
1391
718k
  }
1392
1393
  /// Determine whether this class has a constexpr default constructor.
1394
975k
  bool hasConstexprDefaultConstructor() const {
1395
975k
    return data().HasConstexprDefaultConstructor ||
1396
975k
           
(637k
needsImplicitDefaultConstructor()637k
&&
1397
637k
            
defaultedDefaultConstructorIsConstexpr()542k
);
1398
975k
  }
1399
1400
  /// Determine whether this class has a trivial copy constructor
1401
  /// (C++ [class.copy]p6, C++11 [class.copy]p12)
1402
1.37M
  bool hasTrivialCopyConstructor() const {
1403
1.37M
    return data().HasTrivialSpecialMembers & SMF_CopyConstructor;
1404
1.37M
  }
1405
1406
2.32M
  bool hasTrivialCopyConstructorForCall() const {
1407
2.32M
    return data().HasTrivialSpecialMembersForCall & SMF_CopyConstructor;
1408
2.32M
  }
1409
1410
  /// Determine whether this class has a non-trivial copy constructor
1411
  /// (C++ [class.copy]p6, C++11 [class.copy]p12)
1412
256k
  bool hasNonTrivialCopyConstructor() const {
1413
256k
    return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor ||
1414
256k
           
!hasTrivialCopyConstructor()214k
;
1415
256k
  }
1416
1417
0
  bool hasNonTrivialCopyConstructorForCall() const {
1418
0
    return (data().DeclaredNonTrivialSpecialMembersForCall &
1419
0
            SMF_CopyConstructor) ||
1420
0
           !hasTrivialCopyConstructorForCall();
1421
0
  }
1422
1423
  /// Determine whether this class has a trivial move constructor
1424
  /// (C++11 [class.copy]p12)
1425
1.04M
  bool hasTrivialMoveConstructor() const {
1426
1.04M
    return hasMoveConstructor() &&
1427
1.04M
           
(data().HasTrivialSpecialMembers & SMF_MoveConstructor)998k
;
1428
1.04M
  }
1429
1430
2.24M
  bool hasTrivialMoveConstructorForCall() const {
1431
2.24M
    return hasMoveConstructor() &&
1432
2.24M
           
(data().HasTrivialSpecialMembersForCall & SMF_MoveConstructor)2.19M
;
1433
2.24M
  }
1434
1435
  /// Determine whether this class has a non-trivial move constructor
1436
  /// (C++11 [class.copy]p12)
1437
160k
  bool hasNonTrivialMoveConstructor() const {
1438
160k
    return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveConstructor) ||
1439
160k
           
(158k
needsImplicitMoveConstructor()158k
&&
1440
158k
            
!(data().HasTrivialSpecialMembers & SMF_MoveConstructor)97.1k
);
1441
160k
  }
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.20M
  bool hasTrivialCopyAssignment() const {
1453
1.20M
    return data().HasTrivialSpecialMembers & SMF_CopyAssignment;
1454
1.20M
  }
1455
1456
  /// Determine whether this class has a non-trivial copy assignment
1457
  /// operator (C++ [class.copy]p11, C++11 [class.copy]p25)
1458
157k
  bool hasNonTrivialCopyAssignment() const {
1459
157k
    return data().DeclaredNonTrivialSpecialMembers & SMF_CopyAssignment ||
1460
157k
           
!hasTrivialCopyAssignment()155k
;
1461
157k
  }
1462
1463
  /// Determine whether this class has a trivial move assignment operator
1464
  /// (C++11 [class.copy]p25)
1465
1.00M
  bool hasTrivialMoveAssignment() const {
1466
1.00M
    return hasMoveAssignment() &&
1467
1.00M
           
(data().HasTrivialSpecialMembers & SMF_MoveAssignment)949k
;
1468
1.00M
  }
1469
1470
  /// Determine whether this class has a non-trivial move assignment
1471
  /// operator (C++11 [class.copy]p25)
1472
156k
  bool hasNonTrivialMoveAssignment() const {
1473
156k
    return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveAssignment) ||
1474
156k
           (needsImplicitMoveAssignment() &&
1475
156k
            
!(data().HasTrivialSpecialMembers & SMF_MoveAssignment)126k
);
1476
156k
  }
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.30M
  bool hasTrivialDestructorForCall() const {
1485
2.30M
    return data().HasTrivialSpecialMembersForCall & SMF_Destructor;
1486
2.30M
  }
1487
1488
  /// Determine whether this class has a non-trivial destructor
1489
  /// (C++ [class.dtor]p3)
1490
1.80M
  bool hasNonTrivialDestructor() const {
1491
1.80M
    return !(data().HasTrivialSpecialMembers & SMF_Destructor);
1492
1.80M
  }
1493
1494
0
  bool hasNonTrivialDestructorForCall() const {
1495
0
    return !(data().HasTrivialSpecialMembersForCall & SMF_Destructor);
1496
0
  }
1497
1498
0
  void setHasTrivialSpecialMemberForCall() {
1499
0
    data().HasTrivialSpecialMembersForCall =
1500
0
        (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor);
1501
0
  }
1502
1503
  /// Determine whether declaring a const variable with this type is ok
1504
  /// per core issue 253.
1505
975k
  bool allowConstDefaultInit() const {
1506
975k
    return !data().HasUninitializedFields ||
1507
975k
           
!(349k
data().HasDefaultedDefaultConstructor349k
||
1508
349k
             
needsImplicitDefaultConstructor()339k
);
1509
975k
  }
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.25M
  bool hasIrrelevantDestructor() const {
1517
1.25M
    return data().HasIrrelevantDestructor;
1518
1.25M
  }
1519
1520
  /// Determine whether this class has a non-literal or/ volatile type
1521
  /// non-static data member or base class.
1522
1.72M
  bool hasNonLiteralTypeFieldsOrBases() const {
1523
1.72M
    return data().HasNonLiteralTypeFieldsOrBases;
1524
1.72M
  }
1525
1526
  /// Determine whether this class has a using-declaration that names
1527
  /// a user-declared base class constructor.
1528
3.63M
  bool hasInheritedConstructor() const {
1529
3.63M
    return data().HasInheritedConstructor;
1530
3.63M
  }
1531
1532
  /// Determine whether this class has a using-declaration that names
1533
  /// a base class assignment operator.
1534
2.44M
  bool hasInheritedAssignment() const {
1535
2.44M
    return data().HasInheritedAssignment;
1536
2.44M
  }
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
152k
  bool isTrivial() const {
1548
152k
    return isTriviallyCopyable() && 
hasTrivialDefaultConstructor()90.3k
;
1549
152k
  }
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.24M
  bool isLiteral() const {
1569
1.24M
    return hasTrivialDestructor() &&
1570
1.24M
           
(1.09M
!isLambda()1.09M
||
getASTContext().getLangOpts().CPlusPlus17958
) &&
1571
1.24M
           
!hasNonLiteralTypeFieldsOrBases()1.09M
&&
1572
1.24M
           
(1.00M
isAggregate()1.00M
||
isLambda()224k
||
1573
1.00M
            
hasConstexprNonCopyMoveConstructor()224k
||
1574
1.00M
            
hasTrivialDefaultConstructor()77.5k
);
1575
1.24M
  }
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
304
  CXXRecordDecl *getTemplateInstantiationPattern() {
1636
304
    return const_cast<CXXRecordDecl *>(const_cast<const CXXRecordDecl *>(this)
1637
304
                                           ->getTemplateInstantiationPattern());
1638
304
  }
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
7.08M
  const FunctionDecl *isLocalClass() const {
1650
7.08M
    if (const auto *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
1651
1.27M
      return RD->isLocalClass();
1652
5.80M
1653
5.80M
    return dyn_cast<FunctionDecl>(getDeclContext());
1654
5.80M
  }
1655
1656
1.69M
  FunctionDecl *isLocalClass() {
1657
1.69M
    return const_cast<FunctionDecl*>(
1658
1.69M
        const_cast<const CXXRecordDecl*>(this)->isLocalClass());
1659
1.69M
  }
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.26M
                                     AccessSpecifier DeclAccess) {
1868
2.26M
    assert(DeclAccess != AS_none);
1869
2.26M
    if (DeclAccess == AS_private) 
return AS_none64.4k
;
1870
2.20M
    return (PathAccess > DeclAccess ? 
PathAccess208k
:
DeclAccess1.99M
);
1871
2.20M
  }
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
4.82k
  unsigned getLambdaManglingNumber() const {
1907
4.82k
    assert(isLambda() && "Not a lambda closure type!");
1908
4.82k
    return getLambdaData().ManglingNumber;
1909
4.82k
  }
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
417
  void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl) {
1925
417
    getLambdaData().ManglingNumber = ManglingNumber;
1926
417
    getLambdaData().ContextDecl = ContextDecl;
1927
417
  }
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
0
  bool nullFieldOffsetIsZero() const {
1942
0
    return !MSInheritanceAttr::hasOnlyOneField(/*IsMemberFunction=*/false,
1943
0
                                               getMSInheritanceModel()) ||
1944
0
           (hasDefinition() && isPolymorphic());
1945
0
  }
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
37.1M
  bool isDependentLambda() const {
1963
37.1M
    return isLambda() && 
getLambdaData().Dependent17.6k
;
1964
37.1M
  }
1965
1966
509
  TypeSourceInfo *getLambdaTypeInfo() const {
1967
509
    return getLambdaData().MethodTyInfo;
1968
509
  }
1969
1970
  // Determine whether this type is an Interface Like type for
1971
  // __interface inheritance purposes.
1972
  bool isInterfaceLike() const;
1973
1974
177M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1975
370M
  static bool classofKind(Kind K) {
1976
370M
    return K >= firstCXXRecord && 
K <= lastCXXRecord276M
;
1977
370M
  }
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
0
                     SC_None, false, false) {
2000
0
    if (EndLocation.isValid())
2001
0
      setRangeEnd(EndLocation);
2002
0
    setExplicitSpecified(IsExplicit);
2003
0
    setIsCopyDeductionCandidate(false);
2004
0
  }
2005
2006
public:
2007
  friend class ASTDeclReader;
2008
  friend class ASTDeclWriter;
2009
2010
  static CXXDeductionGuideDecl *Create(ASTContext &C, DeclContext *DC,
2011
                                       SourceLocation StartLoc, bool IsExplicit,
2012
                                       const DeclarationNameInfo &NameInfo,
2013
                                       QualType T, TypeSourceInfo *TInfo,
2014
                                       SourceLocation EndLocation);
2015
2016
  static CXXDeductionGuideDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2017
2018
  /// Whether this deduction guide is explicit.
2019
0
  bool isExplicit() const { return isExplicitSpecified(); }
2020
2021
  /// Get the template for which this guide performs deduction.
2022
0
  TemplateDecl *getDeducedTemplate() const {
2023
0
    return getDeclName().getCXXDeductionGuideTemplate();
2024
0
  }
2025
2026
0
  void setIsCopyDeductionCandidate(bool isCDC = true) {
2027
0
    FunctionDeclBits.IsCopyDeductionCandidate = isCDC;
2028
0
  }
2029
2030
0
  bool isCopyDeductionCandidate() const {
2031
0
    return FunctionDeclBits.IsCopyDeductionCandidate;
2032
0
  }
2033
2034
  // Implement isa/cast/dyncast/etc.
2035
10.1M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2036
10.1M
  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.55M
                   SC, isInline, isConstexpr) {
2054
3.55M
    if (EndLocation.isValid())
2055
1.15M
      setRangeEnd(EndLocation);
2056
3.55M
  }
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
9.59M
  bool isInstance() const { return !isStatic(); }
2072
2073
  /// Returns true if the given operator is implicitly static in a record
2074
  /// context.
2075
24.3M
  static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK) {
2076
24.3M
    // [class.free]p1:
2077
24.3M
    // Any allocation function for a class T is a static member
2078
24.3M
    // (even if not explicitly declared static).
2079
24.3M
    // [class.free]p6 Any deallocation function for a class X is a static member
2080
24.3M
    // (even if not explicitly declared static).
2081
24.3M
    return OOK == OO_New || 
OOK == OO_Array_New24.3M
||
OOK == OO_Delete24.2M
||
2082
24.3M
           
OOK == OO_Array_Delete24.2M
;
2083
24.3M
  }
2084
2085
617
  bool isConst() const { return getType()->castAs<FunctionType>()->isConst(); }
2086
0
  bool isVolatile() const { return getType()->castAs<FunctionType>()->isVolatile(); }
2087
2088
8.54M
  bool isVirtual() const {
2089
8.54M
    CXXMethodDecl *CD = const_cast<CXXMethodDecl*>(this)->getCanonicalDecl();
2090
8.54M
2091
8.54M
    // Member function is virtual if it is marked explicitly so, or if it is
2092
8.54M
    // declared in __interface -- then it is automatically pure virtual.
2093
8.54M
    if (CD->isVirtualAsWritten() || 
CD->isPure()7.85M
)
2094
704k
      return true;
2095
7.84M
2096
7.84M
    return CD->size_overridden_methods() != 0;
2097
7.84M
  }
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
12.3k
                                              bool IsAppleKext) const {
2108
12.3k
    return const_cast<CXXMethodDecl *>(this)->getDevirtualizedMethod(
2109
12.3k
        Base, IsAppleKext);
2110
12.3k
  }
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
84.1M
  CXXMethodDecl *getCanonicalDecl() override {
2125
84.1M
    return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
2126
84.1M
  }
2127
43.8M
  const CXXMethodDecl *getCanonicalDecl() const {
2128
43.8M
    return const_cast<CXXMethodDecl*>(this)->getCanonicalDecl();
2129
43.8M
  }
2130
2131
0
  CXXMethodDecl *getMostRecentDecl() {
2132
0
    return cast<CXXMethodDecl>(
2133
0
            static_cast<FunctionDecl *>(this)->getMostRecentDecl());
2134
0
  }
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.77M
  bool isUserProvided() const {
2142
7.77M
    auto *DeclAsWritten = this;
2143
7.77M
    if (auto *Pattern = getTemplateInstantiationPattern())
2144
3.39M
      DeclAsWritten = cast<CXXMethodDecl>(Pattern);
2145
7.77M
    return !(DeclAsWritten->isDeleted() ||
2146
7.77M
             
DeclAsWritten->getCanonicalDecl()->isDefaulted()7.53M
);
2147
7.77M
  }
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.9M
  const CXXRecordDecl *getParent() const {
2164
34.9M
    return cast<CXXRecordDecl>(FunctionDecl::getParent());
2165
34.9M
  }
2166
2167
  /// Returns the parent of this method declaration, which
2168
  /// is the class in which this method is defined.
2169
11.4M
  CXXRecordDecl *getParent() {
2170
11.4M
    return const_cast<CXXRecordDecl *>(
2171
11.4M
             cast<CXXRecordDecl>(FunctionDecl::getParent()));
2172
11.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
11.2M
  unsigned getTypeQualifiers() const {
2183
11.2M
    return getType()->getAs<FunctionProtoType>()->getTypeQuals();
2184
11.2M
  }
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.41M
  RefQualifierKind getRefQualifier() const {
2198
7.41M
    return getType()->getAs<FunctionProtoType>()->getRefQualifier();
2199
7.41M
  }
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
89
                                bool MayBeBase = false) const {
2224
89
    return const_cast<CXXMethodDecl *>(this)
2225
89
              ->getCorrespondingMethodInClass(RD, MayBeBase);
2226
89
  }
2227
2228
  // Implement isa/cast/dyncast/etc.
2229
144M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2230
209M
  static bool classofKind(Kind K) {
2231
209M
    return K >= firstCXXMethod && 
K <= lastCXXMethod126M
;
2232
209M
  }
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
459k
  bool isBaseInitializer() const {
2317
459k
    return Initializee.is<TypeSourceInfo*>() && 
!IsDelegating198k
;
2318
459k
  }
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
777k
  bool isAnyMemberInitializer() const {
2325
777k
    return isMemberInitializer() || 
isIndirectMemberInitializer()122k
;
2326
777k
  }
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
155k
  bool isInClassMemberInitializer() const {
2339
155k
    return Init->getStmtClass() == Stmt::CXXDefaultInitExprClass;
2340
155k
  }
2341
2342
  /// Determine whether this initializer is creating a delegating
2343
  /// constructor.
2344
54.0k
  bool isDelegatingInitializer() const {
2345
54.0k
    return Initializee.is<TypeSourceInfo*>() && 
IsDelegating15.1k
;
2346
54.0k
  }
2347
2348
  /// Determine whether this initializer is a pack expansion.
2349
38.0k
  bool isPackExpansion() const {
2350
38.0k
    return isBaseInitializer() && 
MemberOrEllipsisLocation.isValid()8.48k
;
2351
38.0k
  }
2352
2353
  // For a pack expansion, returns the location of the ellipsis.
2354
524
  SourceLocation getEllipsisLoc() const {
2355
524
    assert(isPackExpansion() && "Initializer is not a pack expansion");
2356
524
    return MemberOrEllipsisLocation;
2357
524
  }
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
22.3k
  bool isBaseVirtual() const {
2370
22.3k
    assert(isBaseInitializer() && "Must call this on base initializer!");
2371
22.3k
2372
22.3k
    return IsVirtual;
2373
22.3k
  }
2374
2375
  /// Returns the declarator information for a base class or delegating
2376
  /// initializer.
2377
8.95k
  TypeSourceInfo *getTypeSourceInfo() const {
2378
8.95k
    return Initializee.dyn_cast<TypeSourceInfo *>();
2379
8.95k
  }
2380
2381
  /// If this is a member initializer, returns the declaration of the
2382
  /// non-static data member being initialized. Otherwise, returns null.
2383
150k
  FieldDecl *getMember() const {
2384
150k
    if (isMemberInitializer())
2385
150k
      return Initializee.get<FieldDecl*>();
2386
200
    return nullptr;
2387
200
  }
2388
2389
803k
  FieldDecl *getAnyMember() const {
2390
803k
    if (isMemberInitializer())
2391
790k
      return Initializee.get<FieldDecl*>();
2392
13.6k
    if (isIndirectMemberInitializer())
2393
5.05k
      return Initializee.get<IndirectFieldDecl*>()->getAnonField();
2394
8.58k
    return nullptr;
2395
8.58k
  }
2396
2397
100k
  IndirectFieldDecl *getIndirectMember() const {
2398
100k
    if (isIndirectMemberInitializer())
2399
1.25k
      return Initializee.get<IndirectFieldDecl*>();
2400
99.4k
    return nullptr;
2401
99.4k
  }
2402
2403
153k
  SourceLocation getMemberLocation() const {
2404
153k
    return MemberOrEllipsisLocation;
2405
153k
  }
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
38.0k
  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
0
  int getSourceOrder() const {
2420
0
    return IsWritten ? static_cast<int>(SourceOrder) : -1;
2421
0
  }
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
284k
  void setSourceOrder(int Pos) {
2431
284k
    assert(!IsWritten &&
2432
284k
           "setSourceOrder() used on implicit initializer");
2433
284k
    assert(SourceOrder == 0 &&
2434
284k
           "calling twice setSourceOrder() on the same initializer");
2435
284k
    assert(Pos >= 0 &&
2436
284k
           "setSourceOrder() used to make an initializer implicit");
2437
284k
    IsWritten = true;
2438
284k
    SourceOrder = static_cast<unsigned>(Pos);
2439
284k
  }
2440
2441
0
  SourceLocation getLParenLoc() const { return LParenLoc; }
2442
0
  SourceLocation getRParenLoc() const { return RParenLoc; }
2443
2444
  /// Get the initializer.
2445
415k
  Expr *getInit() const { return static_cast<Expr *>(Init); }
2446
};
2447
2448
/// Description of a constructor that was inherited from a base class.
2449
class InheritedConstructor {
2450
  ConstructorUsingShadowDecl *Shadow = nullptr;
2451
  CXXConstructorDecl *BaseCtor = nullptr;
2452
2453
public:
2454
1.63M
  InheritedConstructor() = default;
2455
  InheritedConstructor(ConstructorUsingShadowDecl *Shadow,
2456
                       CXXConstructorDecl *BaseCtor)
2457
0
      : Shadow(Shadow), BaseCtor(BaseCtor) {}
2458
2459
3.16M
  explicit operator bool() const { return Shadow; }
2460
2461
0
  ConstructorUsingShadowDecl *getShadowDecl() const { return Shadow; }
2462
0
  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
  // This class stores some data in DeclContext::CXXConstructorDeclBits
2479
  // to save some space. Use the provided accessors to access it.
2480
2481
  /// \name Support for base and member initializers.
2482
  /// \{
2483
  /// The arguments used to initialize the base or member.
2484
  LazyCXXCtorInitializersPtr CtorInitializers;
2485
2486
  CXXConstructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2487
                     const DeclarationNameInfo &NameInfo,
2488
                     QualType T, TypeSourceInfo *TInfo,
2489
                     bool isExplicitSpecified, bool isInline,
2490
                     bool isImplicitlyDeclared, bool isConstexpr,
2491
                     InheritedConstructor Inherited);
2492
2493
  void anchor() override;
2494
2495
public:
2496
  friend class ASTDeclReader;
2497
  friend class ASTDeclWriter;
2498
  friend TrailingObjects;
2499
2500
  static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID,
2501
                                                bool InheritsConstructor);
2502
  static CXXConstructorDecl *
2503
  Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2504
         const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2505
         bool isExplicit, bool isInline, bool isImplicitlyDeclared,
2506
         bool isConstexpr,
2507
         InheritedConstructor Inherited = InheritedConstructor());
2508
2509
  /// Iterates through the member/base initializer list.
2510
  using init_iterator = CXXCtorInitializer **;
2511
2512
  /// Iterates through the member/base initializer list.
2513
  using init_const_iterator = CXXCtorInitializer *const *;
2514
2515
  using init_range = llvm::iterator_range<init_iterator>;
2516
  using init_const_range = llvm::iterator_range<init_const_iterator>;
2517
2518
0
  init_range inits() { return init_range(init_begin(), init_end()); }
2519
114k
  init_const_range inits() const {
2520
114k
    return init_const_range(init_begin(), init_end());
2521
114k
  }
2522
2523
  /// Retrieve an iterator to the first initializer.
2524
0
  init_iterator init_begin() {
2525
0
    const auto *ConstThis = this;
2526
0
    return const_cast<init_iterator>(ConstThis->init_begin());
2527
0
  }
2528
2529
  /// Retrieve an iterator to the first initializer.
2530
  init_const_iterator init_begin() const;
2531
2532
  /// Retrieve an iterator past the last initializer.
2533
0
  init_iterator       init_end()       {
2534
0
    return init_begin() + getNumCtorInitializers();
2535
0
  }
2536
2537
  /// Retrieve an iterator past the last initializer.
2538
136k
  init_const_iterator init_end() const {
2539
136k
    return init_begin() + getNumCtorInitializers();
2540
136k
  }
2541
2542
  using init_reverse_iterator = std::reverse_iterator<init_iterator>;
2543
  using init_const_reverse_iterator =
2544
      std::reverse_iterator<init_const_iterator>;
2545
2546
0
  init_reverse_iterator init_rbegin() {
2547
0
    return init_reverse_iterator(init_end());
2548
0
  }
2549
0
  init_const_reverse_iterator init_rbegin() const {
2550
0
    return init_const_reverse_iterator(init_end());
2551
0
  }
2552
2553
0
  init_reverse_iterator init_rend() {
2554
0
    return init_reverse_iterator(init_begin());
2555
0
  }
2556
0
  init_const_reverse_iterator init_rend() const {
2557
0
    return init_const_reverse_iterator(init_begin());
2558
0
  }
2559
2560
  /// Determine the number of arguments used to initialize the member
2561
  /// or base.
2562
188k
  unsigned getNumCtorInitializers() const {
2563
188k
      return CXXConstructorDeclBits.NumCtorInitializers;
2564
188k
  }
2565
2566
977k
  void setNumCtorInitializers(unsigned numCtorInitializers) {
2567
977k
    CXXConstructorDeclBits.NumCtorInitializers = numCtorInitializers;
2568
977k
    // This assert added because NumCtorInitializers is stored
2569
977k
    // in CXXConstructorDeclBits as a bitfield and its width has
2570
977k
    // been shrunk from 32 bits to fit into CXXConstructorDeclBitfields.
2571
977k
    assert(CXXConstructorDeclBits.NumCtorInitializers ==
2572
977k
           numCtorInitializers && "NumCtorInitializers overflow!");
2573
977k
  }
2574
2575
213k
  void setCtorInitializers(CXXCtorInitializer **Initializers) {
2576
213k
    CtorInitializers = Initializers;
2577
213k
  }
2578
2579
  /// Whether this function is explicit.
2580
2.13M
  bool isExplicit() const {
2581
2.13M
    return getCanonicalDecl()->isExplicitSpecified();
2582
2.13M
  }
2583
2584
  /// Determine whether this constructor is a delegating constructor.
2585
48.3k
  bool isDelegatingConstructor() const {
2586
48.3k
    return (getNumCtorInitializers() == 1) &&
2587
48.3k
           
init_begin()[0]->isDelegatingInitializer()16.5k
;
2588
48.3k
  }
2589
2590
  /// When this constructor delegates to another, retrieve the target.
2591
  CXXConstructorDecl *getTargetConstructor() const;
2592
2593
  /// Whether this constructor is a default
2594
  /// constructor (C++ [class.ctor]p5), which can be used to
2595
  /// default-initialize a class of this type.
2596
  bool isDefaultConstructor() const;
2597
2598
  /// Whether this constructor is a copy constructor (C++ [class.copy]p2,
2599
  /// which can be used to copy the class.
2600
  ///
2601
  /// \p TypeQuals will be set to the qualifiers on the
2602
  /// argument type. For example, \p TypeQuals would be set to \c
2603
  /// Qualifiers::Const for the following copy constructor:
2604
  ///
2605
  /// \code
2606
  /// class X {
2607
  /// public:
2608
  ///   X(const X&);
2609
  /// };
2610
  /// \endcode
2611
  bool isCopyConstructor(unsigned &TypeQuals) const;
2612
2613
  /// Whether this constructor is a copy
2614
  /// constructor (C++ [class.copy]p2, which can be used to copy the
2615
  /// class.
2616
605k
  bool isCopyConstructor() const {
2617
605k
    unsigned TypeQuals = 0;
2618
605k
    return isCopyConstructor(TypeQuals);
2619
605k
  }
2620
2621
  /// Determine whether this constructor is a move constructor
2622
  /// (C++11 [class.copy]p3), which can be used to move values of the class.
2623
  ///
2624
  /// \param TypeQuals If this constructor is a move constructor, will be set
2625
  /// to the type qualifiers on the referent of the first parameter's type.
2626
  bool isMoveConstructor(unsigned &TypeQuals) const;
2627
2628
  /// Determine whether this constructor is a move constructor
2629
  /// (C++11 [class.copy]p3), which can be used to move values of the class.
2630
700k
  bool isMoveConstructor() const {
2631
700k
    unsigned TypeQuals = 0;
2632
700k
    return isMoveConstructor(TypeQuals);
2633
700k
  }
2634
2635
  /// Determine whether this is a copy or move constructor.
2636
  ///
2637
  /// \param TypeQuals Will be set to the type qualifiers on the reference
2638
  /// parameter, if in fact this is a copy or move constructor.
2639
  bool isCopyOrMoveConstructor(unsigned &TypeQuals) const;
2640
2641
  /// Determine whether this a copy or move constructor.
2642
821k
  bool isCopyOrMoveConstructor() const {
2643
821k
    unsigned Quals;
2644
821k
    return isCopyOrMoveConstructor(Quals);
2645
821k
  }
2646
2647
  /// Whether this constructor is a
2648
  /// converting constructor (C++ [class.conv.ctor]), which can be
2649
  /// used for user-defined conversions.
2650
  bool isConvertingConstructor(bool AllowExplicit) const;
2651
2652
  /// Determine whether this is a member template specialization that
2653
  /// would copy the object to itself. Such constructors are never used to copy
2654
  /// an object.
2655
  bool isSpecializationCopyingObject() const;
2656
2657
  /// Determine whether this is an implicit constructor synthesized to
2658
  /// model a call to a constructor inherited from a base class.
2659
947k
  bool isInheritingConstructor() const {
2660
947k
    return CXXConstructorDeclBits.IsInheritingConstructor;
2661
947k
  }
2662
2663
  /// State that this is an implicit constructor synthesized to
2664
  /// model a call to a constructor inherited from a base class.
2665
764k
  void setInheritingConstructor(bool isIC = true) {
2666
764k
    CXXConstructorDeclBits.IsInheritingConstructor = isIC;
2667
764k
  }
2668
2669
  /// Get the constructor that this inheriting constructor is based on.
2670
868k
  InheritedConstructor getInheritedConstructor() const {
2671
868k
    return isInheritingConstructor() ?
2672
868k
      
*getTrailingObjects<InheritedConstructor>()0
: InheritedConstructor();
2673
868k
  }
2674
2675
27.4M
  CXXConstructorDecl *getCanonicalDecl() override {
2676
27.4M
    return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
2677
27.4M
  }
2678
2.13M
  const CXXConstructorDecl *getCanonicalDecl() const {
2679
2.13M
    return const_cast<CXXConstructorDecl*>(this)->getCanonicalDecl();
2680
2.13M
  }
2681
2682
  // Implement isa/cast/dyncast/etc.
2683
70.5M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2684
71.0M
  static bool classofKind(Kind K) { return K == CXXConstructor; }
2685
};
2686
2687
/// Represents a C++ destructor within a class.
2688
///
2689
/// For example:
2690
///
2691
/// \code
2692
/// class X {
2693
/// public:
2694
///   ~X(); // represented by a CXXDestructorDecl.
2695
/// };
2696
/// \endcode
2697
class CXXDestructorDecl : public CXXMethodDecl {
2698
  friend class ASTDeclReader;
2699
  friend class ASTDeclWriter;
2700
2701
  // FIXME: Don't allocate storage for these except in the first declaration
2702
  // of a virtual destructor.
2703
  FunctionDecl *OperatorDelete = nullptr;
2704
  Expr *OperatorDeleteThisArg = nullptr;
2705
2706
  CXXDestructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2707
                    const DeclarationNameInfo &NameInfo,
2708
                    QualType T, TypeSourceInfo *TInfo,
2709
                    bool isInline, bool isImplicitlyDeclared)
2710
    : CXXMethodDecl(CXXDestructor, C, RD, StartLoc, NameInfo, T, TInfo,
2711
                    SC_None, isInline, /*isConstexpr=*/false, SourceLocation())
2712
170k
  {
2713
170k
    setImplicit(isImplicitlyDeclared);
2714
170k
  }
2715
2716
  void anchor() override;
2717
2718
public:
2719
  static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2720
                                   SourceLocation StartLoc,
2721
                                   const DeclarationNameInfo &NameInfo,
2722
                                   QualType T, TypeSourceInfo* TInfo,
2723
                                   bool isInline,
2724
                                   bool isImplicitlyDeclared);
2725
  static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID);
2726
2727
  void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg);
2728
2729
24.7k
  const FunctionDecl *getOperatorDelete() const {
2730
24.7k
    return getCanonicalDecl()->OperatorDelete;
2731
24.7k
  }
2732
2733
1.51k
  Expr *getOperatorDeleteThisArg() const {
2734
1.51k
    return getCanonicalDecl()->OperatorDeleteThisArg;
2735
1.51k
  }
2736
2737
6.96M
  CXXDestructorDecl *getCanonicalDecl() override {
2738
6.96M
    return cast<CXXDestructorDecl>(FunctionDecl::getCanonicalDecl());
2739
6.96M
  }
2740
26.2k
  const CXXDestructorDecl *getCanonicalDecl() const {
2741
26.2k
    return const_cast<CXXDestructorDecl*>(this)->getCanonicalDecl();
2742
26.2k
  }
2743
2744
  // Implement isa/cast/dyncast/etc.
2745
36.0M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2746
36.5M
  static bool classofKind(Kind K) { return K == CXXDestructor; }
2747
};
2748
2749
/// Represents a C++ conversion function within a class.
2750
///
2751
/// For example:
2752
///
2753
/// \code
2754
/// class X {
2755
/// public:
2756
///   operator bool();
2757
/// };
2758
/// \endcode
2759
class CXXConversionDecl : public CXXMethodDecl {
2760
  CXXConversionDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2761
                    const DeclarationNameInfo &NameInfo, QualType T,
2762
                    TypeSourceInfo *TInfo, bool isInline,
2763
                    bool isExplicitSpecified, bool isConstexpr,
2764
                    SourceLocation EndLocation)
2765
      : CXXMethodDecl(CXXConversion, C, RD, StartLoc, NameInfo, T, TInfo,
2766
17.5k
                      SC_None, isInline, isConstexpr, EndLocation) {
2767
17.5k
    setExplicitSpecified(isExplicitSpecified);
2768
17.5k
  }
2769
2770
  void anchor() override;
2771
2772
public:
2773
  friend class ASTDeclReader;
2774
  friend class ASTDeclWriter;
2775
2776
  static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2777
                                   SourceLocation StartLoc,
2778
                                   const DeclarationNameInfo &NameInfo,
2779
                                   QualType T, TypeSourceInfo *TInfo,
2780
                                   bool isInline, bool isExplicit,
2781
                                   bool isConstexpr,
2782
                                   SourceLocation EndLocation);
2783
  static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2784
2785
  /// Whether this function is explicit.
2786
3.13M
  bool isExplicit() const {
2787
3.13M
    return getCanonicalDecl()->isExplicitSpecified();
2788
3.13M
  }
2789
2790
  /// Returns the type that this conversion function is converting to.
2791
3.00M
  QualType getConversionType() const {
2792
3.00M
    return getType()->getAs<FunctionType>()->getReturnType();
2793
3.00M
  }
2794
2795
  /// Determine whether this conversion function is a conversion from
2796
  /// a lambda closure type to a block pointer.
2797
  bool isLambdaToBlockPointerConversion() const;
2798
2799
4.94M
  CXXConversionDecl *getCanonicalDecl() override {
2800
4.94M
    return cast<CXXConversionDecl>(FunctionDecl::getCanonicalDecl());
2801
4.94M
  }
2802
3.13M
  const CXXConversionDecl *getCanonicalDecl() const {
2803
3.13M
    return const_cast<CXXConversionDecl*>(this)->getCanonicalDecl();
2804
3.13M
  }
2805
2806
  // Implement isa/cast/dyncast/etc.
2807
9.95M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2808
9.95M
  static bool classofKind(Kind K) { return K == CXXConversion; }
2809
};
2810
2811
/// Represents a linkage specification.
2812
///
2813
/// For example:
2814
/// \code
2815
///   extern "C" void foo();
2816
/// \endcode
2817
class LinkageSpecDecl : public Decl, public DeclContext {
2818
  virtual void anchor();
2819
  // This class stores some data in DeclContext::LinkageSpecDeclBits to save
2820
  // some space. Use the provided accessors to access it.
2821
public:
2822
  /// Represents the language in a linkage specification.
2823
  ///
2824
  /// The values are part of the serialization ABI for
2825
  /// ASTs and cannot be changed without altering that ABI.  To help
2826
  /// ensure a stable ABI for this, we choose the DW_LANG_ encodings
2827
  /// from the dwarf standard.
2828
  enum LanguageIDs {
2829
    lang_c = /* DW_LANG_C */ 0x0002,
2830
    lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004
2831
  };
2832
2833
private:
2834
  /// The source location for the extern keyword.
2835
  SourceLocation ExternLoc;
2836
2837
  /// The source location for the right brace (if valid).
2838
  SourceLocation RBraceLoc;
2839
2840
  LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
2841
                  SourceLocation LangLoc, LanguageIDs lang, bool HasBraces);
2842
2843
public:
2844
  static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
2845
                                 SourceLocation ExternLoc,
2846
                                 SourceLocation LangLoc, LanguageIDs Lang,
2847
                                 bool HasBraces);
2848
  static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2849
2850
  /// Return the language specified by this linkage specification.
2851
11.2M
  LanguageIDs getLanguage() const {
2852
11.2M
    return static_cast<LanguageIDs>(LinkageSpecDeclBits.Language);
2853
11.2M
  }
2854
2855
  /// Set the language specified by this linkage specification.
2856
128k
  void setLanguage(LanguageIDs L) { LinkageSpecDeclBits.Language = L; }
2857
2858
  /// Determines whether this linkage specification had braces in
2859
  /// its syntactic form.
2860
28.6k
  bool hasBraces() const {
2861
28.6k
    assert(!RBraceLoc.isValid() || LinkageSpecDeclBits.HasBraces);
2862
28.6k
    return LinkageSpecDeclBits.HasBraces;
2863
28.6k
  }
2864
2865
0
  SourceLocation getExternLoc() const { return ExternLoc; }
2866
0
  SourceLocation getRBraceLoc() const { return RBraceLoc; }
2867
0
  void setExternLoc(SourceLocation L) { ExternLoc = L; }
2868
45.4k
  void setRBraceLoc(SourceLocation L) {
2869
45.4k
    RBraceLoc = L;
2870
45.4k
    LinkageSpecDeclBits.HasBraces = RBraceLoc.isValid();
2871
45.4k
  }
2872
2873
0
  SourceLocation getEndLoc() const LLVM_READONLY {
2874
0
    if (hasBraces())
2875
0
      return getRBraceLoc();
2876
0
    // No braces: get the end location of the (only) declaration in context
2877
0
    // (if present).
2878
0
    return decls_empty() ? getLocation() : decls_begin()->getEndLoc();
2879
0
  }
2880
2881
0
  SourceRange getSourceRange() const override LLVM_READONLY {
2882
0
    return SourceRange(ExternLoc, getEndLoc());
2883
0
  }
2884
2885
0
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2886
25.9M
  static bool classofKind(Kind K) { return K == LinkageSpec; }
2887
2888
0
  static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
2889
0
    return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
2890
0
  }
2891
2892
0
  static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
2893
0
    return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
2894
0
  }
2895
};
2896
2897
/// Represents C++ using-directive.
2898
///
2899
/// For example:
2900
/// \code
2901
///    using namespace std;
2902
/// \endcode
2903
///
2904
/// \note UsingDirectiveDecl should be Decl not NamedDecl, but we provide
2905
/// artificial names for all using-directives in order to store
2906
/// them in DeclContext effectively.
2907
class UsingDirectiveDecl : public NamedDecl {
2908
  /// The location of the \c using keyword.
2909
  SourceLocation UsingLoc;
2910
2911
  /// The location of the \c namespace keyword.
2912
  SourceLocation NamespaceLoc;
2913
2914
  /// The nested-name-specifier that precedes the namespace.
2915
  NestedNameSpecifierLoc QualifierLoc;
2916
2917
  /// The namespace nominated by this using-directive.
2918
  NamedDecl *NominatedNamespace;
2919
2920
  /// Enclosing context containing both using-directive and nominated
2921
  /// namespace.
2922
  DeclContext *CommonAncestor;
2923
2924
  UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc,
2925
                     SourceLocation NamespcLoc,
2926
                     NestedNameSpecifierLoc QualifierLoc,
2927
                     SourceLocation IdentLoc,
2928
                     NamedDecl *Nominated,
2929
                     DeclContext *CommonAncestor)
2930
      : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc),
2931
        NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc),
2932
23.3k
        NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) {}
2933
2934
  /// Returns special DeclarationName used by using-directives.
2935
  ///
2936
  /// This is only used by DeclContext for storing UsingDirectiveDecls in
2937
  /// its lookup structure.
2938
66.5M
  static DeclarationName getName() {
2939
66.5M
    return DeclarationName::getUsingDirectiveName();
2940
66.5M
  }
2941
2942
  void anchor() override;
2943
2944
public:
2945
  friend class ASTDeclReader;
2946
2947
  // Friend for getUsingDirectiveName.
2948
  friend class DeclContext;
2949
2950
  /// Retrieve the nested-name-specifier that qualifies the
2951
  /// name of the namespace, with source-location information.
2952
0
  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2953
2954
  /// Retrieve the nested-name-specifier that qualifies the
2955
  /// name of the namespace.
2956
0
  NestedNameSpecifier *getQualifier() const {
2957
0
    return QualifierLoc.getNestedNameSpecifier();
2958
0
  }
2959
2960
0
  NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
2961
0
  const NamedDecl *getNominatedNamespaceAsWritten() const {
2962
0
    return NominatedNamespace;
2963
0
  }
2964
2965
  /// Returns the namespace nominated by this using-directive.
2966
  NamespaceDecl *getNominatedNamespace();
2967
2968
0
  const NamespaceDecl *getNominatedNamespace() const {
2969
0
    return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
2970
0
  }
2971
2972
  /// Returns the common ancestor context of this using-directive and
2973
  /// its nominated namespace.
2974
0
  DeclContext *getCommonAncestor() { return CommonAncestor; }
2975
0
  const DeclContext *getCommonAncestor() const { return CommonAncestor; }
2976
2977
  /// Return the location of the \c using keyword.
2978
0
  SourceLocation getUsingLoc() const { return UsingLoc; }
2979
2980
  // FIXME: Could omit 'Key' in name.
2981
  /// Returns the location of the \c namespace keyword.
2982
0
  SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
2983
2984
  /// Returns the location of this using declaration's identifier.
2985
0
  SourceLocation getIdentLocation() const { return getLocation(); }
2986
2987
  static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
2988
                                    SourceLocation UsingLoc,
2989
                                    SourceLocation NamespaceLoc,
2990
                                    NestedNameSpecifierLoc QualifierLoc,
2991
                                    SourceLocation IdentLoc,
2992
                                    NamedDecl *Nominated,
2993
                                    DeclContext *CommonAncestor);
2994
  static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2995
2996
0
  SourceRange getSourceRange() const override LLVM_READONLY {
2997
0
    return SourceRange(UsingLoc, getLocation());
2998
0
  }
2999
3000
256k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3001
256k
  static bool classofKind(Kind K) { return K == UsingDirective; }
3002
};
3003
3004
/// Represents a C++ namespace alias.
3005
///
3006
/// For example:
3007
///
3008
/// \code
3009
/// namespace Foo = Bar;
3010
/// \endcode
3011
class NamespaceAliasDecl : public NamedDecl,
3012
                           public Redeclarable<NamespaceAliasDecl> {
3013
  friend class ASTDeclReader;
3014
3015
  /// The location of the \c namespace keyword.
3016
  SourceLocation NamespaceLoc;
3017
3018
  /// The location of the namespace's identifier.
3019
  ///
3020
  /// This is accessed by TargetNameLoc.
3021
  SourceLocation IdentLoc;
3022
3023
  /// The nested-name-specifier that precedes the namespace.
3024
  NestedNameSpecifierLoc QualifierLoc;
3025
3026
  /// The Decl that this alias points to, either a NamespaceDecl or
3027
  /// a NamespaceAliasDecl.
3028
  NamedDecl *Namespace;
3029
3030
  NamespaceAliasDecl(ASTContext &C, DeclContext *DC,
3031
                     SourceLocation NamespaceLoc, SourceLocation AliasLoc,
3032
                     IdentifierInfo *Alias, NestedNameSpecifierLoc QualifierLoc,
3033
                     SourceLocation IdentLoc, NamedDecl *Namespace)
3034
      : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias), redeclarable_base(C),
3035
        NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc),
3036
17
        QualifierLoc(QualifierLoc), Namespace(Namespace) {}
3037
3038
  void anchor() override;
3039
3040
  using redeclarable_base = Redeclarable<NamespaceAliasDecl>;
3041
3042
  NamespaceAliasDecl *getNextRedeclarationImpl() override;
3043
  NamespaceAliasDecl *getPreviousDeclImpl() override;
3044
  NamespaceAliasDecl *getMostRecentDeclImpl() override;
3045
3046
public:
3047
  static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
3048
                                    SourceLocation NamespaceLoc,
3049
                                    SourceLocation AliasLoc,
3050
                                    IdentifierInfo *Alias,
3051
                                    NestedNameSpecifierLoc QualifierLoc,
3052
                                    SourceLocation IdentLoc,
3053
                                    NamedDecl *Namespace);
3054
3055
  static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3056
3057
  using redecl_range = redeclarable_base::redecl_range;
3058
  using redecl_iterator = redeclarable_base::redecl_iterator;
3059
3060
  using redeclarable_base::redecls_begin;
3061
  using redeclarable_base::redecls_end;
3062
  using redeclarable_base::redecls;
3063
  using redeclarable_base::getPreviousDecl;
3064
  using redeclarable_base::getMostRecentDecl;
3065
3066
16
  NamespaceAliasDecl *getCanonicalDecl() override {
3067
16
    return getFirstDecl();
3068
16
  }
3069
0
  const NamespaceAliasDecl *getCanonicalDecl() const {
3070
0
    return getFirstDecl();
3071
0
  }
3072
3073
  /// Retrieve the nested-name-specifier that qualifies the
3074
  /// name of the namespace, with source-location information.
3075
0
  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3076
3077
  /// Retrieve the nested-name-specifier that qualifies the
3078
  /// name of the namespace.
3079
0
  NestedNameSpecifier *getQualifier() const {
3080
0
    return QualifierLoc.getNestedNameSpecifier();
3081
0
  }
3082
3083
  /// Retrieve the namespace declaration aliased by this directive.
3084
1.55k
  NamespaceDecl *getNamespace() {
3085
1.55k
    if (auto *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
3086
0
      return AD->getNamespace();
3087
1.55k
3088
1.55k
    return cast<NamespaceDecl>(Namespace);
3089
1.55k
  }
3090
3091
0
  const NamespaceDecl *getNamespace() const {
3092
0
    return const_cast<NamespaceAliasDecl *>(this)->getNamespace();
3093
0
  }
3094
3095
  /// Returns the location of the alias name, i.e. 'foo' in
3096
  /// "namespace foo = ns::bar;".
3097
0
  SourceLocation getAliasLoc() const { return getLocation(); }
3098
3099
  /// Returns the location of the \c namespace keyword.
3100
0
  SourceLocation getNamespaceLoc() const { return NamespaceLoc; }
3101
3102
  /// Returns the location of the identifier in the named namespace.
3103
0
  SourceLocation getTargetNameLoc() const { return IdentLoc; }
3104
3105
  /// Retrieve the namespace that this alias refers to, which
3106
  /// may either be a NamespaceDecl or a NamespaceAliasDecl.
3107
0
  NamedDecl *getAliasedNamespace() const { return Namespace; }
3108
3109
0
  SourceRange getSourceRange() const override LLVM_READONLY {
3110
0
    return SourceRange(NamespaceLoc, IdentLoc);
3111
0
  }
3112
3113
47.7M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3114
47.7M
  static bool classofKind(Kind K) { return K == NamespaceAlias; }
3115
};
3116
3117
/// Represents a shadow declaration introduced into a scope by a
3118
/// (resolved) using declaration.
3119
///
3120
/// For example,
3121
/// \code
3122
/// namespace A {
3123
///   void foo();
3124
/// }
3125
/// namespace B {
3126
///   using A::foo; // <- a UsingDecl
3127
///                 // Also creates a UsingShadowDecl for A::foo() in B
3128
/// }
3129
/// \endcode
3130
class UsingShadowDecl : public NamedDecl, public Redeclarable<UsingShadowDecl> {
3131
  friend class UsingDecl;
3132
3133
  /// The referenced declaration.
3134
  NamedDecl *Underlying = nullptr;
3135
3136
  /// The using declaration which introduced this decl or the next using
3137
  /// shadow declaration contained in the aforementioned using declaration.
3138
  NamedDecl *UsingOrNextShadow = nullptr;
3139
3140
  void anchor() override;
3141
3142
  using redeclarable_base = Redeclarable<UsingShadowDecl>;
3143
3144
161k
  UsingShadowDecl *getNextRedeclarationImpl() override {
3145
161k
    return getNextRedeclaration();
3146
161k
  }
3147
3148
0
  UsingShadowDecl *getPreviousDeclImpl() override {
3149
0
    return getPreviousDecl();
3150
0
  }
3151
3152
310k
  UsingShadowDecl *getMostRecentDeclImpl() override {
3153
310k
    return getMostRecentDecl();
3154
310k
  }
3155
3156
protected:
3157
  UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC, SourceLocation Loc,
3158
                  UsingDecl *Using, NamedDecl *Target);
3159
  UsingShadowDecl(Kind K, ASTContext &C, EmptyShell);
3160
3161
public:
3162
  friend class ASTDeclReader;
3163
  friend class ASTDeclWriter;
3164
3165
  static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
3166
                                 SourceLocation Loc, UsingDecl *Using,
3167
157k
                                 NamedDecl *Target) {
3168
157k
    return new (C, DC) UsingShadowDecl(UsingShadow, C, DC, Loc, Using, Target);
3169
157k
  }
3170
3171
  static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3172
3173
  using redecl_range = redeclarable_base::redecl_range;
3174
  using redecl_iterator = redeclarable_base::redecl_iterator;
3175
3176
  using redeclarable_base::redecls_begin;
3177
  using redeclarable_base::redecls_end;
3178
  using redeclarable_base::redecls;
3179
  using redeclarable_base::getPreviousDecl;
3180
  using redeclarable_base::getMostRecentDecl;
3181
  using redeclarable_base::isFirstDecl;
3182
3183
983k
  UsingShadowDecl *getCanonicalDecl() override {
3184
983k
    return getFirstDecl();
3185
983k
  }
3186
0
  const UsingShadowDecl *getCanonicalDecl() const {
3187
0
    return getFirstDecl();
3188
0
  }
3189
3190
  /// Gets the underlying declaration which has been brought into the
3191
  /// local scope.
3192
2.44M
  NamedDecl *getTargetDecl() const { return Underlying; }
3193
3194
  /// Sets the underlying declaration which has been brought into the
3195
  /// local scope.
3196
157k
  void setTargetDecl(NamedDecl *ND) {
3197
157k
    assert(ND && "Target decl is null!");
3198
157k
    Underlying = ND;
3199
157k
    // A UsingShadowDecl is never a friend or local extern declaration, even
3200
157k
    // if it is a shadow declaration for one.
3201
157k
    IdentifierNamespace =
3202
157k
        ND->getIdentifierNamespace() &
3203
157k
        ~(IDNS_OrdinaryFriend | IDNS_TagFriend | IDNS_LocalExtern);
3204
157k
  }
3205
3206
  /// Gets the using declaration to which this declaration is tied.
3207
  UsingDecl *getUsingDecl() const;
3208
3209
  /// The next using shadow declaration contained in the shadow decl
3210
  /// chain of the using declaration which introduced this decl.
3211
215
  UsingShadowDecl *getNextUsingShadowDecl() const {
3212
215
    return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow);
3213
215
  }
3214
3215
32.3M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3216
32.3M
  static bool classofKind(Kind K) {
3217
32.3M
    return K == Decl::UsingShadow || 
K == Decl::ConstructorUsingShadow29.9M
;
3218
32.3M
  }
3219
};
3220
3221
/// Represents a shadow constructor declaration introduced into a
3222
/// class by a C++11 using-declaration that names a constructor.
3223
///
3224
/// For example:
3225
/// \code
3226
/// struct Base { Base(int); };
3227
/// struct Derived {
3228
///    using Base::Base; // creates a UsingDecl and a ConstructorUsingShadowDecl
3229
/// };
3230
/// \endcode
3231
class ConstructorUsingShadowDecl final : public UsingShadowDecl {
3232
  /// If this constructor using declaration inherted the constructor
3233
  /// from an indirect base class, this is the ConstructorUsingShadowDecl
3234
  /// in the named direct base class from which the declaration was inherited.
3235
  ConstructorUsingShadowDecl *NominatedBaseClassShadowDecl = nullptr;
3236
3237
  /// If this constructor using declaration inherted the constructor
3238
  /// from an indirect base class, this is the ConstructorUsingShadowDecl
3239
  /// that will be used to construct the unique direct or virtual base class
3240
  /// that receives the constructor arguments.
3241
  ConstructorUsingShadowDecl *ConstructedBaseClassShadowDecl = nullptr;
3242
3243
  /// \c true if the constructor ultimately named by this using shadow
3244
  /// declaration is within a virtual base class subobject of the class that
3245
  /// contains this declaration.
3246
  unsigned IsVirtual : 1;
3247
3248
  ConstructorUsingShadowDecl(ASTContext &C, DeclContext *DC, SourceLocation Loc,
3249
                             UsingDecl *Using, NamedDecl *Target,
3250
                             bool TargetInVirtualBase)
3251
      : UsingShadowDecl(ConstructorUsingShadow, C, DC, Loc, Using,
3252
                        Target->getUnderlyingDecl()),
3253
        NominatedBaseClassShadowDecl(
3254
            dyn_cast<ConstructorUsingShadowDecl>(Target)),
3255
        ConstructedBaseClassShadowDecl(NominatedBaseClassShadowDecl),
3256
0
        IsVirtual(TargetInVirtualBase) {
3257
0
    // If we found a constructor that chains to a constructor for a virtual
3258
0
    // base, we should directly call that virtual base constructor instead.
3259
0
    // FIXME: This logic belongs in Sema.
3260
0
    if (NominatedBaseClassShadowDecl &&
3261
0
        NominatedBaseClassShadowDecl->constructsVirtualBase()) {
3262
0
      ConstructedBaseClassShadowDecl =
3263
0
          NominatedBaseClassShadowDecl->ConstructedBaseClassShadowDecl;
3264
0
      IsVirtual = true;
3265
0
    }
3266
0
  }
3267
3268
  ConstructorUsingShadowDecl(ASTContext &C, EmptyShell Empty)
3269
0
      : UsingShadowDecl(ConstructorUsingShadow, C, Empty), IsVirtual(false) {}
3270
3271
  void anchor() override;
3272
3273
public:
3274
  friend class ASTDeclReader;
3275
  friend class ASTDeclWriter;
3276
3277
  static ConstructorUsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
3278
                                            SourceLocation Loc,
3279
                                            UsingDecl *Using, NamedDecl *Target,
3280
                                            bool IsVirtual);
3281
  static ConstructorUsingShadowDecl *CreateDeserialized(ASTContext &C,
3282
                                                        unsigned ID);
3283
3284
  /// Returns the parent of this using shadow declaration, which
3285
  /// is the class in which this is declared.
3286
  //@{
3287
0
  const CXXRecordDecl *getParent() const {
3288
0
    return cast<CXXRecordDecl>(getDeclContext());
3289
0
  }
3290
0
  CXXRecordDecl *getParent() {
3291
0
    return cast<CXXRecordDecl>(getDeclContext());
3292
0
  }
3293
  //@}
3294
3295
  /// Get the inheriting constructor declaration for the direct base
3296
  /// class from which this using shadow declaration was inherited, if there is
3297
  /// one. This can be different for each redeclaration of the same shadow decl.
3298
0
  ConstructorUsingShadowDecl *getNominatedBaseClassShadowDecl() const {
3299
0
    return NominatedBaseClassShadowDecl;
3300
0
  }
3301
3302
  /// Get the inheriting constructor declaration for the base class
3303
  /// for which we don't have an explicit initializer, if there is one.
3304
0
  ConstructorUsingShadowDecl *getConstructedBaseClassShadowDecl() const {
3305
0
    return ConstructedBaseClassShadowDecl;
3306
0
  }
3307
3308
  /// Get the base class that was named in the using declaration. This
3309
  /// can be different for each redeclaration of this same shadow decl.
3310
  CXXRecordDecl *getNominatedBaseClass() const;
3311
3312
  /// Get the base class whose constructor or constructor shadow
3313
  /// declaration is passed the constructor arguments.
3314
0
  CXXRecordDecl *getConstructedBaseClass() const {
3315
0
    return cast<CXXRecordDecl>((ConstructedBaseClassShadowDecl
3316
0
                                    ? ConstructedBaseClassShadowDecl
3317
0
                                    : getTargetDecl())
3318
0
                                   ->getDeclContext());
3319
0
  }
3320
3321
  /// Returns \c true if the constructed base class is a virtual base
3322
  /// class subobject of this declaration's class.
3323
0
  bool constructsVirtualBase() const {
3324
0
    return IsVirtual;
3325
0
  }
3326
3327
  /// Get the constructor or constructor template in the derived class
3328
  /// correspnding to this using shadow declaration, if it has been implicitly
3329
  /// declared already.
3330
  CXXConstructorDecl *getConstructor() const;
3331
  void setConstructor(NamedDecl *Ctor);
3332
3333
2.35M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3334
2.35M
  static bool classofKind(Kind K) { return K == ConstructorUsingShadow; }
3335
};
3336
3337
/// Represents a C++ using-declaration.
3338
///
3339
/// For example:
3340
/// \code
3341
///    using someNameSpace::someIdentifier;
3342
/// \endcode
3343
class UsingDecl : public NamedDecl, public Mergeable<UsingDecl> {
3344
  /// The source location of the 'using' keyword itself.
3345
  SourceLocation UsingLocation;
3346
3347
  /// The nested-name-specifier that precedes the name.
3348
  NestedNameSpecifierLoc QualifierLoc;
3349
3350
  /// Provides source/type location info for the declaration name
3351
  /// embedded in the ValueDecl base class.
3352
  DeclarationNameLoc DNLoc;
3353
3354
  /// The first shadow declaration of the shadow decl chain associated
3355
  /// with this using declaration.
3356
  ///
3357
  /// The bool member of the pair store whether this decl has the \c typename
3358
  /// keyword.
3359
  llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow;
3360
3361
  UsingDecl(DeclContext *DC, SourceLocation UL,
3362
            NestedNameSpecifierLoc QualifierLoc,
3363
            const DeclarationNameInfo &NameInfo, bool HasTypenameKeyword)
3364
    : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()),
3365
      UsingLocation(UL), QualifierLoc(QualifierLoc),
3366
109k
      DNLoc(NameInfo.getInfo()), FirstUsingShadow(nullptr, HasTypenameKeyword) {
3367
109k
  }
3368
3369
  void anchor() override;
3370
3371
public:
3372
  friend class ASTDeclReader;
3373
  friend class ASTDeclWriter;
3374
3375
  /// Return the source location of the 'using' keyword.
3376
12
  SourceLocation getUsingLoc() const { return UsingLocation; }
3377
3378
  /// Set the source location of the 'using' keyword.
3379
0
  void setUsingLoc(SourceLocation L) { UsingLocation = L; }
3380
3381
  /// Retrieve the nested-name-specifier that qualifies the name,
3382
  /// with source-location information.
3383
6
  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3384
3385
  /// Retrieve the nested-name-specifier that qualifies the name.
3386
11.0k
  NestedNameSpecifier *getQualifier() const {
3387
11.0k
    return QualifierLoc.getNestedNameSpecifier();
3388
11.0k
  }
3389
3390
6
  DeclarationNameInfo getNameInfo() const {
3391
6
    return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
3392
6
  }
3393
3394
  /// Return true if it is a C++03 access declaration (no 'using').
3395
0
  bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
3396
3397
  /// Return true if the using declaration has 'typename'.
3398
12
  bool hasTypename() const { return FirstUsingShadow.getInt(); }
3399
3400
  /// Sets whether the using declaration has 'typename'.
3401
0
  void setTypename(bool TN) { FirstUsingShadow.setInt(TN); }
3402
3403
  /// Iterates through the using shadow declarations associated with
3404
  /// this using declaration.
3405
  class shadow_iterator {
3406
    /// The current using shadow declaration.
3407
    UsingShadowDecl *Current = nullptr;
3408
3409
  public:
3410
    using value_type = UsingShadowDecl *;
3411
    using reference = UsingShadowDecl *;
3412
    using pointer = UsingShadowDecl *;
3413
    using iterator_category = std::forward_iterator_tag;
3414
    using difference_type = std::ptrdiff_t;
3415
3416
167
    shadow_iterator() = default;
3417
167
    explicit shadow_iterator(UsingShadowDecl *C) : Current(C) {}
3418
3419
215
    reference operator*() const { return Current; }
3420
    pointer operator->() const { return Current; }
3421
3422
215
    shadow_iterator& operator++() {
3423
215
      Current = Current->getNextUsingShadowDecl();
3424
215
      return *this;
3425
215
    }
3426
3427
0
    shadow_iterator operator++(int) {
3428
0
      shadow_iterator tmp(*this);
3429
0
      ++(*this);
3430
0
      return tmp;
3431
0
    }
3432
3433
0
    friend bool operator==(shadow_iterator x, shadow_iterator y) {
3434
0
      return x.Current == y.Current;
3435
0
    }
3436
382
    friend bool operator!=(shadow_iterator x, shadow_iterator y) {
3437
382
      return x.Current != y.Current;
3438
382
    }
3439
  };
3440
3441
  using shadow_range = llvm::iterator_range<shadow_iterator>;
3442
3443
167
  shadow_range shadows() const {
3444
167
    return shadow_range(shadow_begin(), shadow_end());
3445
167
  }
3446
3447
167
  shadow_iterator shadow_begin() const {
3448
167
    return shadow_iterator(FirstUsingShadow.getPointer());
3449
167
  }
3450
3451
167
  shadow_iterator shadow_end() const { return shadow_iterator(); }
3452
3453
  /// Return the number of shadowed declarations associated with this
3454
  /// using declaration.
3455
0
  unsigned shadow_size() const {
3456
0
    return std::distance(shadow_begin(), shadow_end());
3457
0
  }
3458
3459
  void addShadowDecl(UsingShadowDecl *S);
3460
  void removeShadowDecl(UsingShadowDecl *S);
3461
3462
  static UsingDecl *Create(ASTContext &C, DeclContext *DC,
3463
                           SourceLocation UsingL,
3464
                           NestedNameSpecifierLoc QualifierLoc,
3465
                           const DeclarationNameInfo &NameInfo,
3466
                           bool HasTypenameKeyword);
3467
3468
  static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3469
3470
  SourceRange getSourceRange() const override LLVM_READONLY;
3471
3472
  /// Retrieves the canonical declaration of this declaration.
3473
218k
  UsingDecl *getCanonicalDecl() override { return getFirstDecl(); }
3474
0
  const UsingDecl *getCanonicalDecl() const { return getFirstDecl(); }
3475
3476
19.3M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3477
19.3M
  static bool classofKind(Kind K) { return K == Using; }
3478
};
3479
3480
/// Represents a pack of using declarations that a single
3481
/// using-declarator pack-expanded into.
3482
///
3483
/// \code
3484
/// template<typename ...T> struct X : T... {
3485
///   using T::operator()...;
3486
///   using T::operator T...;
3487
/// };
3488
/// \endcode
3489
///
3490
/// In the second case above, the UsingPackDecl will have the name
3491
/// 'operator T' (which contains an unexpanded pack), but the individual
3492
/// UsingDecls and UsingShadowDecls will have more reasonable names.
3493
class UsingPackDecl final
3494
    : public NamedDecl, public Mergeable<UsingPackDecl>,
3495
      private llvm::TrailingObjects<UsingPackDecl, NamedDecl *> {
3496
  /// The UnresolvedUsingValueDecl or UnresolvedUsingTypenameDecl from
3497
  /// which this waas instantiated.
3498
  NamedDecl *InstantiatedFrom;
3499
3500
  /// The number of using-declarations created by this pack expansion.
3501
  unsigned NumExpansions;
3502
3503
  UsingPackDecl(DeclContext *DC, NamedDecl *InstantiatedFrom,
3504
                ArrayRef<NamedDecl *> UsingDecls)
3505
      : NamedDecl(UsingPack, DC,
3506
                  InstantiatedFrom ? InstantiatedFrom->getLocation()
3507
                                   : SourceLocation(),
3508
                  InstantiatedFrom ? InstantiatedFrom->getDeclName()
3509
                                   : DeclarationName()),
3510
0
        InstantiatedFrom(InstantiatedFrom), NumExpansions(UsingDecls.size()) {
3511
0
    std::uninitialized_copy(UsingDecls.begin(), UsingDecls.end(),
3512
0
                            getTrailingObjects<NamedDecl *>());
3513
0
  }
3514
3515
  void anchor() override;
3516
3517
public:
3518
  friend class ASTDeclReader;
3519
  friend class ASTDeclWriter;
3520
  friend TrailingObjects;
3521
3522
  /// Get the using declaration from which this was instantiated. This will
3523
  /// always be an UnresolvedUsingValueDecl or an UnresolvedUsingTypenameDecl
3524
  /// that is a pack expansion.
3525
0
  NamedDecl *getInstantiatedFromUsingDecl() const { return InstantiatedFrom; }
3526
3527
  /// Get the set of using declarations that this pack expanded into. Note that
3528
  /// some of these may still be unresolved.
3529
0
  ArrayRef<NamedDecl *> expansions() const {
3530
0
    return llvm::makeArrayRef(getTrailingObjects<NamedDecl *>(), NumExpansions);
3531
0
  }
3532
3533
  static UsingPackDecl *Create(ASTContext &C, DeclContext *DC,
3534
                               NamedDecl *InstantiatedFrom,
3535
                               ArrayRef<NamedDecl *> UsingDecls);
3536
3537
  static UsingPackDecl *CreateDeserialized(ASTContext &C, unsigned ID,
3538
                                           unsigned NumExpansions);
3539
3540
0
  SourceRange getSourceRange() const override LLVM_READONLY {
3541
0
    return InstantiatedFrom->getSourceRange();
3542
0
  }
3543
3544
0
  UsingPackDecl *getCanonicalDecl() override { return getFirstDecl(); }
3545
0
  const UsingPackDecl *getCanonicalDecl() const { return getFirstDecl(); }
3546
3547
1.78M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3548
1.78M
  static bool classofKind(Kind K) { return K == UsingPack; }
3549
};
3550
3551
/// Represents a dependent using declaration which was not marked with
3552
/// \c typename.
3553
///
3554
/// Unlike non-dependent using declarations, these *only* bring through
3555
/// non-types; otherwise they would break two-phase lookup.
3556
///
3557
/// \code
3558
/// template \<class T> class A : public Base<T> {
3559
///   using Base<T>::foo;
3560
/// };
3561
/// \endcode
3562
class UnresolvedUsingValueDecl : public ValueDecl,
3563
                                 public Mergeable<UnresolvedUsingValueDecl> {
3564
  /// The source location of the 'using' keyword
3565
  SourceLocation UsingLocation;
3566
3567
  /// If this is a pack expansion, the location of the '...'.
3568
  SourceLocation EllipsisLoc;
3569
3570
  /// The nested-name-specifier that precedes the name.
3571
  NestedNameSpecifierLoc QualifierLoc;
3572
3573
  /// Provides source/type location info for the declaration name
3574
  /// embedded in the ValueDecl base class.
3575
  DeclarationNameLoc DNLoc;
3576
3577
  UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
3578
                           SourceLocation UsingLoc,
3579
                           NestedNameSpecifierLoc QualifierLoc,
3580
                           const DeclarationNameInfo &NameInfo,
3581
                           SourceLocation EllipsisLoc)
3582
      : ValueDecl(UnresolvedUsingValue, DC,
3583
                  NameInfo.getLoc(), NameInfo.getName(), Ty),
3584
        UsingLocation(UsingLoc), EllipsisLoc(EllipsisLoc),
3585
126
        QualifierLoc(QualifierLoc), DNLoc(NameInfo.getInfo()) {}
3586
3587
  void anchor() override;
3588
3589
public:
3590
  friend class ASTDeclReader;
3591
  friend class ASTDeclWriter;
3592
3593
  /// Returns the source location of the 'using' keyword.
3594
120
  SourceLocation getUsingLoc() const { return UsingLocation; }
3595
3596
  /// Set the source location of the 'using' keyword.
3597
0
  void setUsingLoc(SourceLocation L) { UsingLocation = L; }
3598
3599
  /// Return true if it is a C++03 access declaration (no 'using').
3600
0
  bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
3601
3602
  /// Retrieve the nested-name-specifier that qualifies the name,
3603
  /// with source-location information.
3604
120
  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3605
3606
  /// Retrieve the nested-name-specifier that qualifies the name.
3607
0
  NestedNameSpecifier *getQualifier() const {
3608
0
    return QualifierLoc.getNestedNameSpecifier();
3609
0
  }
3610
3611
120
  DeclarationNameInfo getNameInfo() const {
3612
120
    return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
3613
120
  }
3614
3615
  /// Determine whether this is a pack expansion.
3616
281
  bool isPackExpansion() const {
3617
281
    return EllipsisLoc.isValid();
3618
281
  }
3619
3620
  /// Get the location of the ellipsis if this is a pack expansion.
3621
240
  SourceLocation getEllipsisLoc() const {
3622
240
    return EllipsisLoc;
3623
240
  }
3624
3625
  static UnresolvedUsingValueDecl *
3626
    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
3627
           NestedNameSpecifierLoc QualifierLoc,
3628
           const DeclarationNameInfo &NameInfo, SourceLocation EllipsisLoc);
3629
3630
  static UnresolvedUsingValueDecl *
3631
  CreateDeserialized(ASTContext &C, unsigned ID);
3632
3633
  SourceRange getSourceRange() const override LLVM_READONLY;
3634
3635
  /// Retrieves the canonical declaration of this declaration.
3636
252
  UnresolvedUsingValueDecl *getCanonicalDecl() override {
3637
252
    return getFirstDecl();
3638
252
  }
3639
0
  const UnresolvedUsingValueDecl *getCanonicalDecl() const {
3640
0
    return getFirstDecl();
3641
0
  }
3642
3643
110M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3644
110M
  static bool classofKind(Kind K) { return K == UnresolvedUsingValue; }
3645
};
3646
3647
/// Represents a dependent using declaration which was marked with
3648
/// \c typename.
3649
///
3650
/// \code
3651
/// template \<class T> class A : public Base<T> {
3652
///   using typename Base<T>::foo;
3653
/// };
3654
/// \endcode
3655
///
3656
/// The type associated with an unresolved using typename decl is
3657
/// currently always a typename type.
3658
class UnresolvedUsingTypenameDecl
3659
    : public TypeDecl,
3660
      public Mergeable<UnresolvedUsingTypenameDecl> {
3661
  friend class ASTDeclReader;
3662
3663
  /// The source location of the 'typename' keyword
3664
  SourceLocation TypenameLocation;
3665
3666
  /// If this is a pack expansion, the location of the '...'.
3667
  SourceLocation EllipsisLoc;
3668
3669
  /// The nested-name-specifier that precedes the name.
3670
  NestedNameSpecifierLoc QualifierLoc;
3671
3672
  UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
3673
                              SourceLocation TypenameLoc,
3674
                              NestedNameSpecifierLoc QualifierLoc,
3675
                              SourceLocation TargetNameLoc,
3676
                              IdentifierInfo *TargetName,
3677
                              SourceLocation EllipsisLoc)
3678
    : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName,
3679
               UsingLoc),
3680
      TypenameLocation(TypenameLoc), EllipsisLoc(EllipsisLoc),
3681
0
      QualifierLoc(QualifierLoc) {}
3682
3683
  void anchor() override;
3684
3685
public:
3686
  /// Returns the source location of the 'using' keyword.
3687
0
  SourceLocation getUsingLoc() const { return getBeginLoc(); }
3688
3689
  /// Returns the source location of the 'typename' keyword.
3690
0
  SourceLocation getTypenameLoc() const { return TypenameLocation; }
3691
3692
  /// Retrieve the nested-name-specifier that qualifies the name,
3693
  /// with source-location information.
3694
0
  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3695
3696
  /// Retrieve the nested-name-specifier that qualifies the name.
3697
0
  NestedNameSpecifier *getQualifier() const {
3698
0
    return QualifierLoc.getNestedNameSpecifier();
3699
0
  }
3700
3701
0
  DeclarationNameInfo getNameInfo() const {
3702
0
    return DeclarationNameInfo(getDeclName(), getLocation());
3703
0
  }
3704
3705
  /// Determine whether this is a pack expansion.
3706
0
  bool isPackExpansion() const {
3707
0
    return EllipsisLoc.isValid();
3708
0
  }
3709
3710
  /// Get the location of the ellipsis if this is a pack expansion.
3711
0
  SourceLocation getEllipsisLoc() const {
3712
0
    return EllipsisLoc;
3713
0
  }
3714
3715
  static UnresolvedUsingTypenameDecl *
3716
    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
3717
           SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc,
3718
           SourceLocation TargetNameLoc, DeclarationName TargetName,
3719
           SourceLocation EllipsisLoc);
3720
3721
  static UnresolvedUsingTypenameDecl *
3722
  CreateDeserialized(ASTContext &C, unsigned ID);
3723
3724
  /// Retrieves the canonical declaration of this declaration.
3725
0
  UnresolvedUsingTypenameDecl *getCanonicalDecl() override {
3726
0
    return getFirstDecl();
3727
0
  }
3728
0
  const UnresolvedUsingTypenameDecl *getCanonicalDecl() const {
3729
0
    return getFirstDecl();
3730
0
  }
3731
3732
3.84M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3733
3.84M
  static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; }
3734
};
3735
3736
/// Represents a C++11 static_assert declaration.
3737
class StaticAssertDecl : public Decl {
3738
  llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed;
3739
  StringLiteral *Message;
3740
  SourceLocation RParenLoc;
3741
3742
  StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc,
3743
                   Expr *AssertExpr, StringLiteral *Message,
3744
                   SourceLocation RParenLoc, bool Failed)
3745
      : Decl(StaticAssert, DC, StaticAssertLoc),
3746
        AssertExprAndFailed(AssertExpr, Failed), Message(Message),
3747
58.8k
        RParenLoc(RParenLoc) {}
3748
3749
  virtual void anchor();
3750
3751
public:
3752
  friend class ASTDeclReader;
3753
3754
  static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
3755
                                  SourceLocation StaticAssertLoc,
3756
                                  Expr *AssertExpr, StringLiteral *Message,
3757
                                  SourceLocation RParenLoc, bool Failed);
3758
  static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3759
3760
30.8k
  Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); }
3761
0
  const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); }
3762
3763
30.8k
  StringLiteral *getMessage() { return Message; }
3764
0
  const StringLiteral *getMessage() const { return Message; }
3765
3766
60.0k
  bool isFailed() const { return AssertExprAndFailed.getInt(); }
3767
3768
30.7k
  SourceLocation getRParenLoc() const { return RParenLoc; }
3769
3770
0
  SourceRange getSourceRange() const override LLVM_READONLY {
3771
0
    return SourceRange(getLocation(), getRParenLoc());
3772
0
  }
3773
3774
3.48M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3775
3.48M
  static bool classofKind(Kind K) { return K == StaticAssert; }
3776
};
3777
3778
/// A binding in a decomposition declaration. For instance, given:
3779
///
3780
///   int n[3];
3781
///   auto &[a, b, c] = n;
3782
///
3783
/// a, b, and c are BindingDecls, whose bindings are the expressions
3784
/// x[0], x[1], and x[2] respectively, where x is the implicit
3785
/// DecompositionDecl of type 'int (&)[3]'.
3786
class BindingDecl : public ValueDecl {
3787
  /// The binding represented by this declaration. References to this
3788
  /// declaration are effectively equivalent to this expression (except
3789
  /// that it is only evaluated once at the point of declaration of the
3790
  /// binding).
3791
  Expr *Binding = nullptr;
3792
3793
  BindingDecl(DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id)
3794
0
      : ValueDecl(Decl::Binding, DC, IdLoc, Id, QualType()) {}
3795
3796
  void anchor() override;
3797
3798
public:
3799
  friend class ASTDeclReader;
3800
3801
  static BindingDecl *Create(ASTContext &C, DeclContext *DC,
3802
                             SourceLocation IdLoc, IdentifierInfo *Id);
3803
  static BindingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3804
3805
  /// Get the expression to which this declaration is bound. This may be null
3806
  /// in two different cases: while parsing the initializer for the
3807
  /// decomposition declaration, and when the initializer is type-dependent.
3808
0
  Expr *getBinding() const { return Binding; }
3809
3810
  /// Get the variable (if any) that holds the value of evaluating the binding.
3811
  /// Only present for user-defined bindings for tuple-like types.
3812
  VarDecl *getHoldingVar() const;
3813
3814
  /// Set the binding for this BindingDecl, along with its declared type (which
3815
  /// should be a possibly-cv-qualified form of the type of the binding, or a
3816
  /// reference to such a type).
3817
0
  void setBinding(QualType DeclaredType, Expr *Binding) {
3818
0
    setType(DeclaredType);
3819
0
    this->Binding = Binding;
3820
0
  }
3821
3822
16.1M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3823
16.1M
  static bool classofKind(Kind K) { return K == Decl::Binding; }
3824
};
3825
3826
/// A decomposition declaration. For instance, given:
3827
///
3828
///   int n[3];
3829
///   auto &[a, b, c] = n;
3830
///
3831
/// the second line declares a DecompositionDecl of type 'int (&)[3]', and
3832
/// three BindingDecls (named a, b, and c). An instance of this class is always
3833
/// unnamed, but behaves in almost all other respects like a VarDecl.
3834
class DecompositionDecl final
3835
    : public VarDecl,
3836
      private llvm::TrailingObjects<DecompositionDecl, BindingDecl *> {
3837
  /// The number of BindingDecl*s following this object.
3838
  unsigned NumBindings;
3839
3840
  DecompositionDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3841
                    SourceLocation LSquareLoc, QualType T,
3842
                    TypeSourceInfo *TInfo, StorageClass SC,
3843
                    ArrayRef<BindingDecl *> Bindings)
3844
      : VarDecl(Decomposition, C, DC, StartLoc, LSquareLoc, nullptr, T, TInfo,
3845
                SC),
3846
0
        NumBindings(Bindings.size()) {
3847
0
    std::uninitialized_copy(Bindings.begin(), Bindings.end(),
3848
0
                            getTrailingObjects<BindingDecl *>());
3849
0
  }
3850
3851
  void anchor() override;
3852
3853
public:
3854
  friend class ASTDeclReader;
3855
  friend TrailingObjects;
3856
3857
  static DecompositionDecl *Create(ASTContext &C, DeclContext *DC,
3858
                                   SourceLocation StartLoc,
3859
                                   SourceLocation LSquareLoc,
3860
                                   QualType T, TypeSourceInfo *TInfo,
3861
                                   StorageClass S,
3862
                                   ArrayRef<BindingDecl *> Bindings);
3863
  static DecompositionDecl *CreateDeserialized(ASTContext &C, unsigned ID,
3864
                                               unsigned NumBindings);
3865
3866
0
  ArrayRef<BindingDecl *> bindings() const {
3867
0
    return llvm::makeArrayRef(getTrailingObjects<BindingDecl *>(), NumBindings);
3868
0
  }
3869
3870
  void printName(raw_ostream &os) const override;
3871
3872
37.2M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3873
37.2M
  static bool classofKind(Kind K) { return K == Decomposition; }
3874
};
3875
3876
/// An instance of this class represents the declaration of a property
3877
/// member.  This is a Microsoft extension to C++, first introduced in
3878
/// Visual Studio .NET 2003 as a parallel to similar features in C#
3879
/// and Managed C++.
3880
///
3881
/// A property must always be a non-static class member.
3882
///
3883
/// A property member superficially resembles a non-static data
3884
/// member, except preceded by a property attribute:
3885
///   __declspec(property(get=GetX, put=PutX)) int x;
3886
/// Either (but not both) of the 'get' and 'put' names may be omitted.
3887
///
3888
/// A reference to a property is always an lvalue.  If the lvalue
3889
/// undergoes lvalue-to-rvalue conversion, then a getter name is
3890
/// required, and that member is called with no arguments.
3891
/// If the lvalue is assigned into, then a setter name is required,
3892
/// and that member is called with one argument, the value assigned.
3893
/// Both operations are potentially overloaded.  Compound assignments
3894
/// are permitted, as are the increment and decrement operators.
3895
///
3896
/// The getter and putter methods are permitted to be overloaded,
3897
/// although their return and parameter types are subject to certain
3898
/// restrictions according to the type of the property.
3899
///
3900
/// A property declared using an incomplete array type may
3901
/// additionally be subscripted, adding extra parameters to the getter
3902
/// and putter methods.
3903
class MSPropertyDecl : public DeclaratorDecl {
3904
  IdentifierInfo *GetterId, *SetterId;
3905
3906
  MSPropertyDecl(DeclContext *DC, SourceLocation L, DeclarationName N,
3907
                 QualType T, TypeSourceInfo *TInfo, SourceLocation StartL,
3908
                 IdentifierInfo *Getter, IdentifierInfo *Setter)
3909
      : DeclaratorDecl(MSProperty, DC, L, N, T, TInfo, StartL),
3910
0
        GetterId(Getter), SetterId(Setter) {}
3911
3912
public:
3913
  friend class ASTDeclReader;
3914
3915
  static MSPropertyDecl *Create(ASTContext &C, DeclContext *DC,
3916
                                SourceLocation L, DeclarationName N, QualType T,
3917
                                TypeSourceInfo *TInfo, SourceLocation StartL,
3918
                                IdentifierInfo *Getter, IdentifierInfo *Setter);
3919
  static MSPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3920
3921
6.62M
  static bool classof(const Decl *D) { return D->getKind() == MSProperty; }
3922
3923
0
  bool hasGetter() const { return GetterId != nullptr; }
3924
0
  IdentifierInfo* getGetterId() const { return GetterId; }
3925
0
  bool hasSetter() const { return SetterId != nullptr; }
3926
0
  IdentifierInfo* getSetterId() const { return SetterId; }
3927
};
3928
3929
/// Insertion operator for diagnostics.  This allows sending an AccessSpecifier
3930
/// into a diagnostic with <<.
3931
const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
3932
                                    AccessSpecifier AS);
3933
3934
const PartialDiagnostic &operator<<(const PartialDiagnostic &DB,
3935
                                    AccessSpecifier AS);
3936
3937
} // namespace clang
3938
3939
#endif // LLVM_CLANG_AST_DECLCXX_H