Coverage Report

Created: 2020-09-22 08:39

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