Coverage Report

Created: 2019-07-24 05:18

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