Coverage Report

Created: 2022-05-14 11:35

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