Coverage Report

Created: 2019-02-20 07:29

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