Coverage Report

Created: 2021-09-21 08:58

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