Coverage Report

Created: 2024-01-17 10:31

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