Coverage Report

Created: 2020-02-18 08:44

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