r318216 - [AST] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).

Eugene Zelenko via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 14 15:13:33 PST 2017


Author: eugenezelenko
Date: Tue Nov 14 15:13:32 2017
New Revision: 318216

URL: http://llvm.org/viewvc/llvm-project?rev=318216&view=rev
Log:
[AST] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).

Modified:
    cfe/trunk/include/clang/AST/DeclCXX.h
    cfe/trunk/lib/AST/DeclCXX.cpp

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=318216&r1=318215&r2=318216&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Tue Nov 14 15:13:32 2017
@@ -1,4 +1,4 @@
-//===-- DeclCXX.h - Classes for representing C++ declarations -*- C++ -*-=====//
+//===- DeclCXX.h - Classes for representing C++ declarations --*- C++ -*-=====//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -6,11 +6,11 @@
 // License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
-///
+//
 /// \file
 /// \brief Defines the C++ Decl subclasses, other than those for templates
 /// (found in DeclTemplate.h) and friends (in DeclFriend.h).
-///
+//
 //===----------------------------------------------------------------------===//
 
 #ifndef LLVM_CLANG_AST_DECLCXX_H
@@ -20,29 +20,56 @@
 #include "clang/AST/ASTUnresolvedSet.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclarationName.h"
 #include "clang/AST/Expr.h"
+#include "clang/AST/ExternalASTSource.h"
 #include "clang/AST/LambdaCapture.h"
+#include "clang/AST/NestedNameSpecifier.h"
+#include "clang/AST/Redeclarable.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/AST/TypeLoc.h"
+#include "clang/AST/UnresolvedSet.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/Lambda.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/OperatorKinds.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/Specifiers.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/PointerIntPair.h"
+#include "llvm/ADT/PointerUnion.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/iterator_range.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/Compiler.h"
+#include "llvm/Support/PointerLikeTypeTraits.h"
+#include "llvm/Support/TrailingObjects.h"
+#include <cassert>
+#include <cstddef>
+#include <iterator>
+#include <memory>
+#include <vector>
 
 namespace clang {
 
 class ClassTemplateDecl;
-class ClassTemplateSpecializationDecl;
 class ConstructorUsingShadowDecl;
 class CXXBasePath;
 class CXXBasePaths;
 class CXXConstructorDecl;
-class CXXConversionDecl;
 class CXXDestructorDecl;
-class CXXMethodDecl;
-class CXXRecordDecl;
-class CXXMemberLookupCriteria;
 class CXXFinalOverriderMap;
 class CXXIndirectPrimaryBaseSet;
+class CXXMethodDecl;
+class DiagnosticBuilder;
 class FriendDecl;
-class LambdaExpr;
+class FunctionTemplateDecl;
+class IdentifierInfo;
+class MemberSpecializationInfo;
+class TemplateDecl;
+class TemplateParameterList;
 class UsingDecl;
 
 /// \brief Represents any kind of function declaration, whether it is a
@@ -50,10 +77,10 @@ class UsingDecl;
 class AnyFunctionDecl {
   NamedDecl *Function;
 
-  AnyFunctionDecl(NamedDecl *ND) : Function(ND) { }
+  AnyFunctionDecl(NamedDecl *ND) : Function(ND) {}
 
 public:
-  AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { }
+  AnyFunctionDecl(FunctionDecl *FD) : Function(FD) {}
   AnyFunctionDecl(FunctionTemplateDecl *FTD);
 
   /// \brief Implicily converts any function or function template into a
@@ -68,16 +95,18 @@ public:
   }
 };
 
-} // end namespace clang
+} // namespace clang
 
 namespace llvm {
+
   // Provide PointerLikeTypeTraits for non-cvr pointers.
   template<>
   struct PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
-    static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
+    static void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
       return F.get();
     }
-    static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
+
+    static ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
       return ::clang::AnyFunctionDecl::getFromNamedDecl(
                                       static_cast< ::clang::NamedDecl*>(P));
     }
@@ -85,7 +114,7 @@ namespace llvm {
     enum { NumLowBitsAvailable = 2 };
   };
 
-} // end namespace llvm
+} // namespace llvm
 
 namespace clang {
 
@@ -100,7 +129,6 @@ namespace clang {
 /// Also note that this class has nothing to do with so-called
 /// "access declarations" (C++98 11.3 [class.access.dcl]).
 class AccessSpecDecl : public Decl {
-  virtual void anchor();
   /// \brief The location of the ':'.
   SourceLocation ColonLoc;
 
@@ -109,16 +137,21 @@ class AccessSpecDecl : public Decl {
     : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) {
     setAccess(AS);
   }
-  AccessSpecDecl(EmptyShell Empty)
-    : Decl(AccessSpec, Empty) { }
+
+  AccessSpecDecl(EmptyShell Empty) : Decl(AccessSpec, Empty) {}
+
+  virtual void anchor();
+
 public:
   /// \brief The location of the access specifier.
   SourceLocation getAccessSpecifierLoc() const { return getLocation(); }
+
   /// \brief Sets the location of the access specifier.
   void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); }
 
   /// \brief The location of the colon following the access specifier.
   SourceLocation getColonLoc() const { return ColonLoc; }
+
   /// \brief Sets the location of the colon.
   void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; }
 
@@ -131,6 +164,7 @@ public:
                                 SourceLocation ColonLoc) {
     return new (C, DC) AccessSpecDecl(AS, DC, ASLoc, ColonLoc);
   }
+
   static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
 
   // Implement isa/cast/dyncast/etc.
@@ -190,12 +224,11 @@ class CXXBaseSpecifier {
   TypeSourceInfo *BaseTypeInfo;
 
 public:
-  CXXBaseSpecifier() { }
-
+  CXXBaseSpecifier() = default;
   CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A,
                    TypeSourceInfo *TInfo, SourceLocation EllipsisLoc)
     : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC),
-      Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) { }
+      Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) {}
 
   /// \brief Retrieves the source range that contains the entire base specifier.
   SourceRange getSourceRange() const LLVM_READONLY { return Range; }
@@ -264,7 +297,16 @@ public:
 
 /// \brief Represents a C++ struct/union/class.
 class CXXRecordDecl : public RecordDecl {
+  friend class ASTDeclReader;
+  friend class ASTDeclWriter;
+  friend class ASTNodeImporter;
+  friend class ASTReader;
+  friend class ASTRecordWriter;
+  friend class ASTWriter;
+  friend class DeclContext;
+  friend class LambdaExpr;
 
+  friend void FunctionDecl::setPure(bool);
   friend void TagDecl::startDefinition();
 
   /// Values used in DefinitionData fields to represent special members.
@@ -279,8 +321,6 @@ class CXXRecordDecl : public RecordDecl
   };
 
   struct DefinitionData {
-    DefinitionData(CXXRecordDecl *D);
-
     /// \brief True if this class has any user-declared constructors.
     unsigned UserDeclaredConstructor : 1;
 
@@ -474,13 +514,13 @@ class CXXRecordDecl : public RecordDecl
     unsigned HasODRHash : 1;
 
     /// \brief A hash of parts of the class to help in ODR checking.
-    unsigned ODRHash;
+    unsigned ODRHash = 0;
 
     /// \brief The number of base class specifiers in Bases.
-    unsigned NumBases;
+    unsigned NumBases = 0;
 
     /// \brief The number of virtual base class specifiers in VBases.
-    unsigned NumVBases;
+    unsigned NumVBases = 0;
 
     /// \brief Base classes of this class.
     ///
@@ -512,6 +552,8 @@ class CXXRecordDecl : public RecordDecl
     /// This is actually currently stored in reverse order.
     LazyDeclPtr FirstFriend;
 
+    DefinitionData(CXXRecordDecl *D);
+
     /// \brief Retrieve the set of direct base classes.
     CXXBaseSpecifier *getBases() const {
       if (!Bases.isOffset())
@@ -529,6 +571,7 @@ class CXXRecordDecl : public RecordDecl
     ArrayRef<CXXBaseSpecifier> bases() const {
       return llvm::makeArrayRef(getBases(), NumBases);
     }
+
     ArrayRef<CXXBaseSpecifier> vbases() const {
       return llvm::makeArrayRef(getVBases(), NumVBases);
     }
@@ -542,22 +585,7 @@ class CXXRecordDecl : public RecordDecl
 
   /// \brief Describes a C++ closure type (generated by a lambda expression).
   struct LambdaDefinitionData : public DefinitionData {
-    typedef LambdaCapture Capture;
-
-    LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info, 
-                         bool Dependent, bool IsGeneric, 
-                         LambdaCaptureDefault CaptureDefault) 
-      : DefinitionData(D), Dependent(Dependent), IsGenericLambda(IsGeneric), 
-        CaptureDefault(CaptureDefault), NumCaptures(0), NumExplicitCaptures(0), 
-        ManglingNumber(0), ContextDecl(nullptr), Captures(nullptr),
-        MethodTyInfo(Info) {
-      IsLambda = true;
-
-      // C++1z [expr.prim.lambda]p4:
-      //   This class type is not an aggregate type.
-      Aggregate = false;
-      PlainOldData = false;
-    }
+    using Capture = LambdaCapture;
 
     /// \brief Whether this lambda is known to be dependent, even if its
     /// context isn't dependent.
@@ -583,7 +611,7 @@ class CXXRecordDecl : public RecordDecl
 
     /// \brief The number used to indicate this lambda expression for name 
     /// mangling in the Itanium C++ ABI.
-    unsigned ManglingNumber;
+    unsigned ManglingNumber = 0;
     
     /// \brief The declaration that provides context for this lambda, if the
     /// actual DeclContext does not suffice. This is used for lambdas that
@@ -593,11 +621,24 @@ class CXXRecordDecl : public RecordDecl
     
     /// \brief The list of captures, both explicit and implicit, for this 
     /// lambda.
-    Capture *Captures;
+    Capture *Captures = nullptr;
 
     /// \brief The type of the call method.
     TypeSourceInfo *MethodTyInfo;
-       
+
+    LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info, 
+                         bool Dependent, bool IsGeneric, 
+                         LambdaCaptureDefault CaptureDefault) 
+      : DefinitionData(D), Dependent(Dependent), IsGenericLambda(IsGeneric), 
+        CaptureDefault(CaptureDefault), NumCaptures(0), NumExplicitCaptures(0), 
+        MethodTyInfo(Info) {
+      IsLambda = true;
+
+      // C++1z [expr.prim.lambda]p4:
+      //   This class type is not an aggregate type.
+      Aggregate = false;
+      PlainOldData = false;
+    }
   };
 
   struct DefinitionData *dataPtr() const {
@@ -629,11 +670,8 @@ class CXXRecordDecl : public RecordDecl
   /// classes of class template specializations, this will be the
   /// MemberSpecializationInfo referring to the member class that was
   /// instantiated or specialized.
-  llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*>
-    TemplateOrInstantiation;
-
-  friend class DeclContext;
-  friend class LambdaExpr;
+  llvm::PointerUnion<ClassTemplateDecl *, MemberSpecializationInfo *>
+      TemplateOrInstantiation;
 
   /// \brief Called from setBases and addedMember to notify the class that a
   /// direct or virtual base class or a member of class type has been added.
@@ -647,9 +685,6 @@ class CXXRecordDecl : public RecordDecl
   void addedMember(Decl *D);
 
   void markedVirtualFunctionPure();
-  friend void FunctionDecl::setPure(bool);
-
-  friend class ASTNodeImporter;
 
   /// \brief Get the head of our list of friend declarations, possibly
   /// deserializing the friends from an external AST source.
@@ -662,14 +697,15 @@ protected:
 
 public:
   /// \brief Iterator that traverses the base classes of a class.
-  typedef CXXBaseSpecifier*       base_class_iterator;
+  using base_class_iterator = CXXBaseSpecifier *;
 
   /// \brief Iterator that traverses the base classes of a class.
-  typedef const CXXBaseSpecifier* base_class_const_iterator;
+  using base_class_const_iterator = const CXXBaseSpecifier *;
 
   CXXRecordDecl *getCanonicalDecl() override {
     return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
   }
+
   const CXXRecordDecl *getCanonicalDecl() const {
     return const_cast<CXXRecordDecl*>(this)->getCanonicalDecl();
   }
@@ -678,6 +714,7 @@ public:
     return cast_or_null<CXXRecordDecl>(
             static_cast<RecordDecl *>(this)->getPreviousDecl());
   }
+
   const CXXRecordDecl *getPreviousDecl() const {
     return const_cast<CXXRecordDecl*>(this)->getPreviousDecl();
   }
@@ -729,9 +766,9 @@ public:
   /// \brief Retrieves the number of base classes of this class.
   unsigned getNumBases() const { return data().NumBases; }
 
-  typedef llvm::iterator_range<base_class_iterator> base_class_range;
-  typedef llvm::iterator_range<base_class_const_iterator>
-    base_class_const_range;
+  using base_class_range = llvm::iterator_range<base_class_iterator>;
+  using base_class_const_range =
+      llvm::iterator_range<base_class_const_iterator>;
 
   base_class_range bases() {
     return base_class_range(bases_begin(), bases_end());
@@ -771,9 +808,9 @@ public:
   /// Iterator access to method members.  The method iterator visits
   /// all method members of the class, including non-instance methods,
   /// special methods, etc.
-  typedef specific_decl_iterator<CXXMethodDecl> method_iterator;
-  typedef llvm::iterator_range<specific_decl_iterator<CXXMethodDecl>>
-    method_range;
+  using method_iterator = specific_decl_iterator<CXXMethodDecl>;
+  using method_range =
+      llvm::iterator_range<specific_decl_iterator<CXXMethodDecl>>;
 
   method_range methods() const {
     return method_range(method_begin(), method_end());
@@ -784,21 +821,23 @@ public:
   method_iterator method_begin() const {
     return method_iterator(decls_begin());
   }
+
   /// \brief Method past-the-end iterator.
   method_iterator method_end() const {
     return method_iterator(decls_end());
   }
 
   /// Iterator access to constructor members.
-  typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator;
-  typedef llvm::iterator_range<specific_decl_iterator<CXXConstructorDecl>>
-    ctor_range;
+  using ctor_iterator = specific_decl_iterator<CXXConstructorDecl>;
+  using ctor_range =
+      llvm::iterator_range<specific_decl_iterator<CXXConstructorDecl>>;
 
   ctor_range ctors() const { return ctor_range(ctor_begin(), ctor_end()); }
 
   ctor_iterator ctor_begin() const {
     return ctor_iterator(decls_begin());
   }
+
   ctor_iterator ctor_end() const {
     return ctor_iterator(decls_end());
   }
@@ -806,7 +845,7 @@ public:
   /// An iterator over friend declarations.  All of these are defined
   /// in DeclFriend.h.
   class friend_iterator;
-  typedef llvm::iterator_range<friend_iterator> friend_range;
+  using friend_range = llvm::iterator_range<friend_iterator>;
 
   friend_range friends() const;
   friend_iterator friend_begin() const;
@@ -1155,24 +1194,28 @@ public:
   void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures,
                         FieldDecl *&ThisCapture) const;
 
-  typedef const LambdaCapture *capture_const_iterator;
-  typedef llvm::iterator_range<capture_const_iterator> capture_const_range;
+  using capture_const_iterator = const LambdaCapture *;
+  using capture_const_range = llvm::iterator_range<capture_const_iterator>;
 
   capture_const_range captures() const {
     return capture_const_range(captures_begin(), captures_end());
   }
+
   capture_const_iterator captures_begin() const {
     return isLambda() ? getLambdaData().Captures : nullptr;
   }
+
   capture_const_iterator captures_end() const {
     return isLambda() ? captures_begin() + getLambdaData().NumCaptures
                       : nullptr;
   }
 
-  typedef UnresolvedSetIterator conversion_iterator;
+  using conversion_iterator = UnresolvedSetIterator;
+
   conversion_iterator conversion_begin() const {
     return data().Conversions.get(getASTContext()).begin();
   }
+
   conversion_iterator conversion_end() const {
     return data().Conversions.get(getASTContext()).end();
   }
@@ -1596,8 +1639,8 @@ public:
   /// \param BaseDefinition the definition of the base class
   ///
   /// \returns true if this base matched the search criteria
-  typedef llvm::function_ref<bool(const CXXRecordDecl *BaseDefinition)>
-      ForallBasesCallback;
+  using ForallBasesCallback =
+      llvm::function_ref<bool(const CXXRecordDecl *BaseDefinition)>;
 
   /// \brief Determines if the given callback holds for all the direct
   /// or indirect base classes of this type.
@@ -1625,8 +1668,9 @@ public:
   /// base named by the \p Specifier.
   ///
   /// \returns true if this base matched the search criteria, false otherwise.
-  typedef llvm::function_ref<bool(const CXXBaseSpecifier *Specifier,
-                                  CXXBasePath &Path)> BaseMatchesCallback;
+  using BaseMatchesCallback =
+      llvm::function_ref<bool(const CXXBaseSpecifier *Specifier,
+                              CXXBasePath &Path)>;
 
   /// \brief Look for entities within the base classes of this C++ class,
   /// transitively searching all base class subobjects.
@@ -1805,6 +1849,7 @@ public:
 
   /// \brief Returns the inheritance model used for this record.
   MSInheritanceAttr::Spelling getMSInheritanceModel() const;
+
   /// \brief Calculate what the inheritance model would be for this class.
   MSInheritanceAttr::Spelling calculateInheritanceModel() const;
 
@@ -1851,12 +1896,6 @@ public:
   static bool classofKind(Kind K) {
     return K >= firstCXXRecord && K <= lastCXXRecord;
   }
-
-  friend class ASTDeclReader;
-  friend class ASTDeclWriter;
-  friend class ASTRecordWriter;
-  friend class ASTReader;
-  friend class ASTWriter;
 };
 
 /// \brief Represents a C++ deduction guide declaration.
@@ -1871,6 +1910,7 @@ public:
 /// the constructors of \c A.
 class CXXDeductionGuideDecl : public FunctionDecl {
   void anchor() override;
+
 private:
   CXXDeductionGuideDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
                         bool IsExplicit, const DeclarationNameInfo &NameInfo,
@@ -1884,6 +1924,9 @@ private:
   }
 
 public:
+  friend class ASTDeclReader;
+  friend class ASTDeclWriter;
+
   static CXXDeductionGuideDecl *Create(ASTContext &C, DeclContext *DC,
                                        SourceLocation StartLoc, bool IsExplicit,
                                        const DeclarationNameInfo &NameInfo,
@@ -1912,9 +1955,6 @@ public:
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classofKind(Kind K) { return K == CXXDeductionGuide; }
-
-  friend class ASTDeclReader;
-  friend class ASTDeclWriter;
 };
 
 /// \brief Represents a static or instance method of a struct/union/class.
@@ -1923,6 +1963,7 @@ public:
 /// non-static) member functions, whether virtual or not.
 class CXXMethodDecl : public FunctionDecl {
   void anchor() override;
+
 protected:
   CXXMethodDecl(Kind DK, ASTContext &C, CXXRecordDecl *RD,
                 SourceLocation StartLoc, const DeclarationNameInfo &NameInfo,
@@ -2023,15 +2064,16 @@ public:
     return !(isDeleted() || getCanonicalDecl()->isDefaulted());
   }
 
-  ///
   void addOverriddenMethod(const CXXMethodDecl *MD);
 
-  typedef const CXXMethodDecl *const* method_iterator;
+  using method_iterator = const CXXMethodDecl *const *;
 
   method_iterator begin_overridden_methods() const;
   method_iterator end_overridden_methods() const;
   unsigned size_overridden_methods() const;
-  typedef ASTContext::overridden_method_range overridden_method_range;
+
+  using overridden_method_range= ASTContext::overridden_method_range;
+
   overridden_method_range overridden_methods() const;
 
   /// Returns the parent of this method declaration, which
@@ -2261,6 +2303,7 @@ public:
       return Initializee.get<FieldDecl*>();
     return nullptr;
   }
+
   FieldDecl *getAnyMember() const {
     if (isMemberInitializer())
       return Initializee.get<FieldDecl*>();
@@ -2322,11 +2365,11 @@ public:
 
 /// Description of a constructor that was inherited from a base class.
 class InheritedConstructor {
-  ConstructorUsingShadowDecl *Shadow;
-  CXXConstructorDecl *BaseCtor;
+  ConstructorUsingShadowDecl *Shadow = nullptr;
+  CXXConstructorDecl *BaseCtor = nullptr;
 
 public:
-  InheritedConstructor() : Shadow(), BaseCtor() {}
+  InheritedConstructor() = default;
   InheritedConstructor(ConstructorUsingShadowDecl *Shadow,
                        CXXConstructorDecl *BaseCtor)
       : Shadow(Shadow), BaseCtor(BaseCtor) {}
@@ -2350,8 +2393,6 @@ public:
 class CXXConstructorDecl final
     : public CXXMethodDecl,
       private llvm::TrailingObjects<CXXConstructorDecl, InheritedConstructor> {
-  void anchor() override;
-
   /// \name Support for base and member initializers.
   /// \{
   /// \brief The arguments used to initialize the base or member.
@@ -2371,15 +2412,20 @@ class CXXConstructorDecl final
                      InheritedConstructor Inherited)
     : CXXMethodDecl(CXXConstructor, C, RD, StartLoc, NameInfo, T, TInfo,
                     SC_None, isInline, isConstexpr, SourceLocation()),
-      CtorInitializers(nullptr), NumCtorInitializers(0),
-      IsInheritingConstructor((bool)Inherited) {
+      NumCtorInitializers(0), IsInheritingConstructor((bool)Inherited) {
     setImplicit(isImplicitlyDeclared);
     if (Inherited)
       *getTrailingObjects<InheritedConstructor>() = Inherited;
     IsExplicitSpecified = isExplicitSpecified;
   }
 
+  void anchor() override;
+
 public:
+  friend class ASTDeclReader;
+  friend class ASTDeclWriter;
+  friend TrailingObjects;
+
   static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID,
                                                 bool InheritsConstructor);
   static CXXConstructorDecl *
@@ -2390,13 +2436,13 @@ public:
          InheritedConstructor Inherited = InheritedConstructor());
 
   /// \brief Iterates through the member/base initializer list.
-  typedef CXXCtorInitializer **init_iterator;
+  using init_iterator = CXXCtorInitializer **;
 
   /// \brief Iterates through the member/base initializer list.
-  typedef CXXCtorInitializer *const *init_const_iterator;
+  using init_const_iterator = CXXCtorInitializer *const *;
 
-  typedef llvm::iterator_range<init_iterator> init_range;
-  typedef llvm::iterator_range<init_const_iterator> init_const_range;
+  using init_range = llvm::iterator_range<init_iterator>;
+  using init_const_range = llvm::iterator_range<init_const_iterator>;
 
   init_range inits() { return init_range(init_begin(), init_end()); }
   init_const_range inits() const {
@@ -2408,6 +2454,7 @@ public:
     const auto *ConstThis = this;
     return const_cast<init_iterator>(ConstThis->init_begin());
   }
+
   /// \brief Retrieve an iterator to the first initializer.
   init_const_iterator init_begin() const;
 
@@ -2415,14 +2462,15 @@ public:
   init_iterator       init_end()       {
     return init_begin() + NumCtorInitializers;
   }
+
   /// \brief Retrieve an iterator past the last initializer.
   init_const_iterator init_end() const {
     return init_begin() + NumCtorInitializers;
   }
 
-  typedef std::reverse_iterator<init_iterator> init_reverse_iterator;
-  typedef std::reverse_iterator<init_const_iterator>
-          init_const_reverse_iterator;
+  using init_reverse_iterator = std::reverse_iterator<init_iterator>;
+  using init_const_reverse_iterator =
+      std::reverse_iterator<init_const_iterator>;
 
   init_reverse_iterator init_rbegin() {
     return init_reverse_iterator(init_end());
@@ -2553,10 +2601,6 @@ public:
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classofKind(Kind K) { return K == CXXConstructor; }
-
-  friend class ASTDeclReader;
-  friend class ASTDeclWriter;
-  friend TrailingObjects;
 };
 
 /// \brief Represents a C++ destructor within a class.
@@ -2570,23 +2614,26 @@ public:
 /// };
 /// \endcode
 class CXXDestructorDecl : public CXXMethodDecl {
-  void anchor() override;
+  friend class ASTDeclReader;
+  friend class ASTDeclWriter;
 
   // FIXME: Don't allocate storage for these except in the first declaration
   // of a virtual destructor.
-  FunctionDecl *OperatorDelete;
-  Expr *OperatorDeleteThisArg;
+  FunctionDecl *OperatorDelete = nullptr;
+  Expr *OperatorDeleteThisArg = nullptr;
 
   CXXDestructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
                     const DeclarationNameInfo &NameInfo,
                     QualType T, TypeSourceInfo *TInfo,
                     bool isInline, bool isImplicitlyDeclared)
     : CXXMethodDecl(CXXDestructor, C, RD, StartLoc, NameInfo, T, TInfo,
-                    SC_None, isInline, /*isConstexpr=*/false, SourceLocation()),
-      OperatorDelete(nullptr), OperatorDeleteThisArg(nullptr) {
+                    SC_None, isInline, /*isConstexpr=*/false, SourceLocation())
+  {
     setImplicit(isImplicitlyDeclared);
   }
 
+  void anchor() override;
+
 public:
   static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
                                    SourceLocation StartLoc,
@@ -2597,9 +2644,11 @@ public:
   static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID);
 
   void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg);
+
   const FunctionDecl *getOperatorDelete() const {
     return getCanonicalDecl()->OperatorDelete;
   }
+
   Expr *getOperatorDeleteThisArg() const {
     return getCanonicalDecl()->OperatorDeleteThisArg;
   }
@@ -2614,9 +2663,6 @@ public:
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classofKind(Kind K) { return K == CXXDestructor; }
-
-  friend class ASTDeclReader;
-  friend class ASTDeclWriter;
 };
 
 /// \brief Represents a C++ conversion function within a class.
@@ -2630,8 +2676,6 @@ public:
 /// };
 /// \endcode
 class CXXConversionDecl : public CXXMethodDecl {
-  void anchor() override;
-
   CXXConversionDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
                     const DeclarationNameInfo &NameInfo, QualType T,
                     TypeSourceInfo *TInfo, bool isInline,
@@ -2642,7 +2686,12 @@ class CXXConversionDecl : public CXXMeth
     IsExplicitSpecified = isExplicitSpecified;
   }
 
+  void anchor() override;
+
 public:
+  friend class ASTDeclReader;
+  friend class ASTDeclWriter;
+
   static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
                                    SourceLocation StartLoc,
                                    const DeclarationNameInfo &NameInfo,
@@ -2679,9 +2728,6 @@ public:
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classofKind(Kind K) { return K == CXXConversion; }
-
-  friend class ASTDeclReader;
-  friend class ASTDeclWriter;
 };
 
 /// \brief Represents a linkage specification. 
@@ -2692,6 +2738,7 @@ public:
 /// \endcode
 class LinkageSpecDecl : public Decl, public DeclContext {
   virtual void anchor();
+
 public:
   /// \brief Represents the language in a linkage specification.
   ///
@@ -2703,25 +2750,29 @@ public:
     lang_c = /* DW_LANG_C */ 0x0002,
     lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004
   };
+
 private:
   /// \brief The language for this linkage specification.
   unsigned Language : 3;
+
   /// \brief True if this linkage spec has braces.
   ///
   /// This is needed so that hasBraces() returns the correct result while the
   /// linkage spec body is being parsed.  Once RBraceLoc has been set this is
   /// not used, so it doesn't need to be serialized.
   unsigned HasBraces : 1;
+
   /// \brief The source location for the extern keyword.
   SourceLocation ExternLoc;
+
   /// \brief The source location for the right brace (if valid).
   SourceLocation RBraceLoc;
 
   LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
                   SourceLocation LangLoc, LanguageIDs lang, bool HasBraces)
-    : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec),
-      Language(lang), HasBraces(HasBraces), ExternLoc(ExternLoc),
-      RBraceLoc(SourceLocation()) { }
+      : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec),
+        Language(lang), HasBraces(HasBraces), ExternLoc(ExternLoc),
+        RBraceLoc(SourceLocation()) {}
 
 public:
   static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
@@ -2732,6 +2783,7 @@ public:
   
   /// \brief Return the language specified by this linkage specification.
   LanguageIDs getLanguage() const { return LanguageIDs(Language); }
+
   /// \brief Set the language specified by this linkage specification.
   void setLanguage(LanguageIDs L) { Language = L; }
 
@@ -2764,9 +2816,11 @@ public:
 
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classofKind(Kind K) { return K == LinkageSpec; }
+
   static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
     return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
   }
+
   static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
     return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
   }
@@ -2783,7 +2837,6 @@ public:
 /// artificial names for all using-directives in order to store
 /// them in DeclContext effectively.
 class UsingDirectiveDecl : public NamedDecl {
-  void anchor() override;
   /// \brief The location of the \c using keyword.
   SourceLocation UsingLoc;
 
@@ -2800,6 +2853,16 @@ class UsingDirectiveDecl : public NamedD
   /// namespace.
   DeclContext *CommonAncestor;
 
+  UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc,
+                     SourceLocation NamespcLoc,
+                     NestedNameSpecifierLoc QualifierLoc,
+                     SourceLocation IdentLoc,
+                     NamedDecl *Nominated,
+                     DeclContext *CommonAncestor)
+      : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc),
+        NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc),
+        NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) {}
+
   /// \brief Returns special DeclarationName used by using-directives.
   ///
   /// This is only used by DeclContext for storing UsingDirectiveDecls in
@@ -2808,17 +2871,14 @@ class UsingDirectiveDecl : public NamedD
     return DeclarationName::getUsingDirectiveName();
   }
 
-  UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc,
-                     SourceLocation NamespcLoc,
-                     NestedNameSpecifierLoc QualifierLoc,
-                     SourceLocation IdentLoc,
-                     NamedDecl *Nominated,
-                     DeclContext *CommonAncestor)
-    : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc),
-      NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc),
-      NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) { }
+  void anchor() override;
 
 public:
+  friend class ASTDeclReader;
+
+  // Friend for getUsingDirectiveName.
+  friend class DeclContext;
+
   /// \brief Retrieve the nested-name-specifier that qualifies the
   /// name of the namespace, with source-location information.
   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
@@ -2871,11 +2931,6 @@ public:
 
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classofKind(Kind K) { return K == UsingDirective; }
-
-  // Friend for getUsingDirectiveName.
-  friend class DeclContext;
-
-  friend class ASTDeclReader;
 };
 
 /// \brief Represents a C++ namespace alias.
@@ -2887,7 +2942,7 @@ public:
 /// \endcode
 class NamespaceAliasDecl : public NamedDecl,
                            public Redeclarable<NamespaceAliasDecl> {
-  void anchor() override;
+  friend class ASTDeclReader;
 
   /// \brief The location of the \c namespace keyword.
   SourceLocation NamespaceLoc;
@@ -2912,13 +2967,14 @@ class NamespaceAliasDecl : public NamedD
         NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc),
         QualifierLoc(QualifierLoc), Namespace(Namespace) {}
 
-  typedef Redeclarable<NamespaceAliasDecl> redeclarable_base;
+  void anchor() override;
+
+  using redeclarable_base = Redeclarable<NamespaceAliasDecl>;
+
   NamespaceAliasDecl *getNextRedeclarationImpl() override;
   NamespaceAliasDecl *getPreviousDeclImpl() override;
   NamespaceAliasDecl *getMostRecentDeclImpl() override;
 
-  friend class ASTDeclReader;
-
 public:
   static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
                                     SourceLocation NamespaceLoc,
@@ -2930,8 +2986,9 @@ public:
 
   static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
 
-  typedef redeclarable_base::redecl_range redecl_range;
-  typedef redeclarable_base::redecl_iterator redecl_iterator;
+  using redecl_range = redeclarable_base::redecl_range;
+  using redecl_iterator = redeclarable_base::redecl_iterator;
+
   using redeclarable_base::redecls_begin;
   using redeclarable_base::redecls_end;
   using redeclarable_base::redecls;
@@ -3003,23 +3060,27 @@ public:
 /// }
 /// \endcode
 class UsingShadowDecl : public NamedDecl, public Redeclarable<UsingShadowDecl> {
-  void anchor() override;
+  friend class UsingDecl;
 
   /// The referenced declaration.
-  NamedDecl *Underlying;
+  NamedDecl *Underlying = nullptr;
 
   /// \brief The using declaration which introduced this decl or the next using
   /// shadow declaration contained in the aforementioned using declaration.
-  NamedDecl *UsingOrNextShadow;
-  friend class UsingDecl;
+  NamedDecl *UsingOrNextShadow = nullptr;
+
+  void anchor() override;
+
+  using redeclarable_base = Redeclarable<UsingShadowDecl>;
 
-  typedef Redeclarable<UsingShadowDecl> redeclarable_base;
   UsingShadowDecl *getNextRedeclarationImpl() override {
     return getNextRedeclaration();
   }
+
   UsingShadowDecl *getPreviousDeclImpl() override {
     return getPreviousDecl();
   }
+
   UsingShadowDecl *getMostRecentDeclImpl() override {
     return getMostRecentDecl();
   }
@@ -3030,6 +3091,9 @@ protected:
   UsingShadowDecl(Kind K, ASTContext &C, EmptyShell);
 
 public:
+  friend class ASTDeclReader;
+  friend class ASTDeclWriter;
+
   static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
                                  SourceLocation Loc, UsingDecl *Using,
                                  NamedDecl *Target) {
@@ -3038,8 +3102,9 @@ public:
 
   static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID);
 
-  typedef redeclarable_base::redecl_range redecl_range;
-  typedef redeclarable_base::redecl_iterator redecl_iterator;
+  using redecl_range = redeclarable_base::redecl_range;
+  using redecl_iterator = redeclarable_base::redecl_iterator;
+
   using redeclarable_base::redecls_begin;
   using redeclarable_base::redecls_end;
   using redeclarable_base::redecls;
@@ -3079,9 +3144,6 @@ public:
   static bool classofKind(Kind K) {
     return K == Decl::UsingShadow || K == Decl::ConstructorUsingShadow;
   }
-
-  friend class ASTDeclReader;
-  friend class ASTDeclWriter;
 };
 
 /// \brief Represents a shadow constructor declaration introduced into a
@@ -3095,18 +3157,16 @@ public:
 /// };
 /// \endcode
 class ConstructorUsingShadowDecl final : public UsingShadowDecl {
-  void anchor() override;
-
   /// \brief If this constructor using declaration inherted the constructor
   /// from an indirect base class, this is the ConstructorUsingShadowDecl
   /// in the named direct base class from which the declaration was inherited.
-  ConstructorUsingShadowDecl *NominatedBaseClassShadowDecl;
+  ConstructorUsingShadowDecl *NominatedBaseClassShadowDecl = nullptr;
 
   /// \brief If this constructor using declaration inherted the constructor
   /// from an indirect base class, this is the ConstructorUsingShadowDecl
   /// that will be used to construct the unique direct or virtual base class
   /// that receives the constructor arguments.
-  ConstructorUsingShadowDecl *ConstructedBaseClassShadowDecl;
+  ConstructorUsingShadowDecl *ConstructedBaseClassShadowDecl = nullptr;
 
   /// \brief \c true if the constructor ultimately named by this using shadow
   /// declaration is within a virtual base class subobject of the class that
@@ -3132,12 +3192,16 @@ class ConstructorUsingShadowDecl final :
       IsVirtual = true;
     }
   }
+
   ConstructorUsingShadowDecl(ASTContext &C, EmptyShell Empty)
-      : UsingShadowDecl(ConstructorUsingShadow, C, Empty),
-        NominatedBaseClassShadowDecl(), ConstructedBaseClassShadowDecl(),
-        IsVirtual(false) {}
+      : UsingShadowDecl(ConstructorUsingShadow, C, Empty), IsVirtual(false) {}
+
+  void anchor() override;
 
 public:
+  friend class ASTDeclReader;
+  friend class ASTDeclWriter;
+
   static ConstructorUsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
                                             SourceLocation Loc,
                                             UsingDecl *Using, NamedDecl *Target,
@@ -3196,9 +3260,6 @@ public:
 
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classofKind(Kind K) { return K == ConstructorUsingShadow; }
-
-  friend class ASTDeclReader;
-  friend class ASTDeclWriter;
 };
 
 /// \brief Represents a C++ using-declaration.
@@ -3208,8 +3269,6 @@ public:
 ///    using someNameSpace::someIdentifier;
 /// \endcode
 class UsingDecl : public NamedDecl, public Mergeable<UsingDecl> {
-  void anchor() override;
-
   /// \brief The source location of the 'using' keyword itself.
   SourceLocation UsingLocation;
 
@@ -3235,7 +3294,12 @@ class UsingDecl : public NamedDecl, publ
       DNLoc(NameInfo.getInfo()), FirstUsingShadow(nullptr, HasTypenameKeyword) {
   }
 
+  void anchor() override;
+
 public:
+  friend class ASTDeclReader;
+  friend class ASTDeclWriter;
+
   /// \brief Return the source location of the 'using' keyword.
   SourceLocation getUsingLoc() const { return UsingLocation; }
 
@@ -3268,17 +3332,17 @@ public:
   /// this using declaration.
   class shadow_iterator {
     /// \brief The current using shadow declaration.
-    UsingShadowDecl *Current;
+    UsingShadowDecl *Current = nullptr;
 
   public:
-    typedef UsingShadowDecl*          value_type;
-    typedef UsingShadowDecl*          reference;
-    typedef UsingShadowDecl*          pointer;
-    typedef std::forward_iterator_tag iterator_category;
-    typedef std::ptrdiff_t            difference_type;
+    using value_type = UsingShadowDecl *;
+    using reference = UsingShadowDecl *;
+    using pointer = UsingShadowDecl *;
+    using iterator_category = std::forward_iterator_tag;
+    using difference_type = std::ptrdiff_t;
 
-    shadow_iterator() : Current(nullptr) { }
-    explicit shadow_iterator(UsingShadowDecl *C) : Current(C) { }
+    shadow_iterator() = default;
+    explicit shadow_iterator(UsingShadowDecl *C) : Current(C) {}
 
     reference operator*() const { return Current; }
     pointer operator->() const { return Current; }
@@ -3302,14 +3366,16 @@ public:
     }
   };
 
-  typedef llvm::iterator_range<shadow_iterator> shadow_range;
+  using shadow_range = llvm::iterator_range<shadow_iterator>;
 
   shadow_range shadows() const {
     return shadow_range(shadow_begin(), shadow_end());
   }
+
   shadow_iterator shadow_begin() const {
     return shadow_iterator(FirstUsingShadow.getPointer());
   }
+
   shadow_iterator shadow_end() const { return shadow_iterator(); }
 
   /// \brief Return the number of shadowed declarations associated with this
@@ -3337,9 +3403,6 @@ public:
 
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classofKind(Kind K) { return K == Using; }
-
-  friend class ASTDeclReader;
-  friend class ASTDeclWriter;
 };
 
 /// Represents a pack of using declarations that a single
@@ -3358,8 +3421,6 @@ public:
 class UsingPackDecl final
     : public NamedDecl, public Mergeable<UsingPackDecl>,
       private llvm::TrailingObjects<UsingPackDecl, NamedDecl *> {
-  void anchor() override;
-
   /// The UnresolvedUsingValueDecl or UnresolvedUsingTypenameDecl from
   /// which this waas instantiated.
   NamedDecl *InstantiatedFrom;
@@ -3379,7 +3440,13 @@ class UsingPackDecl final
                             getTrailingObjects<NamedDecl *>());
   }
 
+  void anchor() override;
+
 public:
+  friend class ASTDeclReader;
+  friend class ASTDeclWriter;
+  friend TrailingObjects;
+
   /// Get the using declaration from which this was instantiated. This will
   /// always be an UnresolvedUsingValueDecl or an UnresolvedUsingTypenameDecl
   /// that is a pack expansion.
@@ -3407,10 +3474,6 @@ public:
 
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classofKind(Kind K) { return K == UsingPack; }
-
-  friend class ASTDeclReader;
-  friend class ASTDeclWriter;
-  friend TrailingObjects;
 };
 
 /// \brief Represents a dependent using declaration which was not marked with
@@ -3426,8 +3489,6 @@ public:
 /// \endcode
 class UnresolvedUsingValueDecl : public ValueDecl,
                                  public Mergeable<UnresolvedUsingValueDecl> {
-  void anchor() override;
-
   /// \brief The source location of the 'using' keyword
   SourceLocation UsingLocation;
 
@@ -3446,13 +3507,17 @@ class UnresolvedUsingValueDecl : public
                            NestedNameSpecifierLoc QualifierLoc,
                            const DeclarationNameInfo &NameInfo,
                            SourceLocation EllipsisLoc)
-    : ValueDecl(UnresolvedUsingValue, DC,
-                NameInfo.getLoc(), NameInfo.getName(), Ty),
-      UsingLocation(UsingLoc), EllipsisLoc(EllipsisLoc),
-      QualifierLoc(QualifierLoc), DNLoc(NameInfo.getInfo())
-  { }
+      : ValueDecl(UnresolvedUsingValue, DC,
+                  NameInfo.getLoc(), NameInfo.getName(), Ty),
+        UsingLocation(UsingLoc), EllipsisLoc(EllipsisLoc),
+        QualifierLoc(QualifierLoc), DNLoc(NameInfo.getInfo()) {}
+
+  void anchor() override;
 
 public:
+  friend class ASTDeclReader;
+  friend class ASTDeclWriter;
+
   /// \brief Returns the source location of the 'using' keyword.
   SourceLocation getUsingLoc() const { return UsingLocation; }
 
@@ -3505,9 +3570,6 @@ public:
 
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classofKind(Kind K) { return K == UnresolvedUsingValue; }
-
-  friend class ASTDeclReader;
-  friend class ASTDeclWriter;
 };
 
 /// \brief Represents a dependent using declaration which was marked with
@@ -3524,7 +3586,7 @@ public:
 class UnresolvedUsingTypenameDecl
     : public TypeDecl,
       public Mergeable<UnresolvedUsingTypenameDecl> {
-  void anchor() override;
+  friend class ASTDeclReader;
 
   /// \brief The source location of the 'typename' keyword
   SourceLocation TypenameLocation;
@@ -3544,9 +3606,9 @@ class UnresolvedUsingTypenameDecl
     : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName,
                UsingLoc),
       TypenameLocation(TypenameLoc), EllipsisLoc(EllipsisLoc),
-      QualifierLoc(QualifierLoc) { }
+      QualifierLoc(QualifierLoc) {}
 
-  friend class ASTDeclReader;
+  void anchor() override;
 
 public:
   /// \brief Returns the source location of the 'using' keyword.
@@ -3601,7 +3663,6 @@ public:
 
 /// \brief Represents a C++11 static_assert declaration.
 class StaticAssertDecl : public Decl {
-  virtual void anchor();
   llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed;
   StringLiteral *Message;
   SourceLocation RParenLoc;
@@ -3609,11 +3670,15 @@ class StaticAssertDecl : public Decl {
   StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc,
                    Expr *AssertExpr, StringLiteral *Message,
                    SourceLocation RParenLoc, bool Failed)
-    : Decl(StaticAssert, DC, StaticAssertLoc),
-      AssertExprAndFailed(AssertExpr, Failed), Message(Message),
-      RParenLoc(RParenLoc) { }
+      : Decl(StaticAssert, DC, StaticAssertLoc),
+        AssertExprAndFailed(AssertExpr, Failed), Message(Message),
+        RParenLoc(RParenLoc) {}
+
+  virtual void anchor();
 
 public:
+  friend class ASTDeclReader;
+
   static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
                                   SourceLocation StaticAssertLoc,
                                   Expr *AssertExpr, StringLiteral *Message,
@@ -3636,8 +3701,6 @@ public:
 
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classofKind(Kind K) { return K == StaticAssert; }
-
-  friend class ASTDeclReader;
 };
 
 /// A binding in a decomposition declaration. For instance, given:
@@ -3649,18 +3712,20 @@ public:
 /// x[0], x[1], and x[2] respectively, where x is the implicit
 /// DecompositionDecl of type 'int (&)[3]'.
 class BindingDecl : public ValueDecl {
-  void anchor() override;
-
   /// The binding represented by this declaration. References to this
   /// declaration are effectively equivalent to this expression (except
   /// that it is only evaluated once at the point of declaration of the
   /// binding).
-  Expr *Binding;
+  Expr *Binding = nullptr;
 
   BindingDecl(DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id)
-      : ValueDecl(Decl::Binding, DC, IdLoc, Id, QualType()), Binding(nullptr) {}
+      : ValueDecl(Decl::Binding, DC, IdLoc, Id, QualType()) {}
+
+  void anchor() override;
 
 public:
+  friend class ASTDeclReader;
+
   static BindingDecl *Create(ASTContext &C, DeclContext *DC,
                              SourceLocation IdLoc, IdentifierInfo *Id);
   static BindingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
@@ -3684,8 +3749,6 @@ public:
 
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classofKind(Kind K) { return K == Decl::Binding; }
-
-  friend class ASTDeclReader;
 };
 
 /// A decomposition declaration. For instance, given:
@@ -3699,8 +3762,6 @@ public:
 class DecompositionDecl final
     : public VarDecl,
       private llvm::TrailingObjects<DecompositionDecl, BindingDecl *> {
-  void anchor() override;
-
   /// The number of BindingDecl*s following this object.
   unsigned NumBindings;
 
@@ -3715,7 +3776,12 @@ class DecompositionDecl final
                             getTrailingObjects<BindingDecl *>());
   }
 
+  void anchor() override;
+
 public:
+  friend class ASTDeclReader;
+  friend TrailingObjects;
+
   static DecompositionDecl *Create(ASTContext &C, DeclContext *DC,
                                    SourceLocation StartLoc,
                                    SourceLocation LSquareLoc,
@@ -3733,9 +3799,6 @@ public:
 
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classofKind(Kind K) { return K == Decomposition; }
-
-  friend TrailingObjects;
-  friend class ASTDeclReader;
 };
 
 /// An instance of this class represents the declaration of a property
@@ -3775,6 +3838,8 @@ class MSPropertyDecl : public Declarator
         GetterId(Getter), SetterId(Setter) {}
 
 public:
+  friend class ASTDeclReader;
+
   static MSPropertyDecl *Create(ASTContext &C, DeclContext *DC,
                                 SourceLocation L, DeclarationName N, QualType T,
                                 TypeSourceInfo *TInfo, SourceLocation StartL,
@@ -3787,8 +3852,6 @@ public:
   IdentifierInfo* getGetterId() const { return GetterId; }
   bool hasSetter() const { return SetterId != nullptr; }
   IdentifierInfo* getSetterId() const { return SetterId; }
-
-  friend class ASTDeclReader;
 };
 
 /// Insertion operator for diagnostics.  This allows sending an AccessSpecifier
@@ -3799,6 +3862,6 @@ const DiagnosticBuilder &operator<<(cons
 const PartialDiagnostic &operator<<(const PartialDiagnostic &DB,
                                     AccessSpecifier AS);
 
-} // end namespace clang
+} // namespace clang
 
-#endif
+#endif // LLVM_CLANG_AST_DECLCXX_H

Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=318216&r1=318215&r2=318216&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Tue Nov 14 15:13:32 2017
@@ -1,4 +1,4 @@
-//===--- DeclCXX.cpp - C++ Declaration AST Node Implementation ------------===//
+//===- DeclCXX.cpp - C++ Declaration AST Node Implementation --------------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -10,26 +10,51 @@
 // This file implements the C++ related Decl classes.
 //
 //===----------------------------------------------------------------------===//
+
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTLambda.h"
 #include "clang/AST/ASTMutationListener.h"
+#include "clang/AST/ASTUnresolvedSet.h"
 #include "clang/AST/CXXInheritance.h"
+#include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclTemplate.h"
+#include "clang/AST/DeclarationName.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
+#include "clang/AST/LambdaCapture.h"
+#include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/ODRHash.h"
+#include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
+#include "clang/AST/UnresolvedSet.h"
+#include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/IdentifierTable.h"
-#include "llvm/ADT/STLExtras.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/OperatorKinds.h"
+#include "clang/Basic/PartialDiagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/Specifiers.h"
+#include "llvm/ADT/None.h"
 #include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/iterator_range.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/raw_ostream.h"
+#include <algorithm>
+#include <cassert>
+#include <cstddef>
+#include <cstdint>
+
 using namespace clang;
 
 //===----------------------------------------------------------------------===//
 // Decl Allocation/Deallocation Method Implementations
 //===----------------------------------------------------------------------===//
 
-void AccessSpecDecl::anchor() { }
+void AccessSpecDecl::anchor() {}
 
 AccessSpecDecl *AccessSpecDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
   return new (C, ID) AccessSpecDecl(EmptyShell());
@@ -76,9 +101,7 @@ CXXRecordDecl::DefinitionData::Definitio
       ImplicitCopyAssignmentHasConstParam(true),
       HasDeclaredCopyConstructorWithConstParam(false),
       HasDeclaredCopyAssignmentWithConstParam(false), IsLambda(false),
-      IsParsingBaseSpecifiers(false), HasODRHash(false), ODRHash(0),
-      NumBases(0), NumVBases(0), Bases(), VBases(), Definition(D),
-      FirstFriend() {}
+      IsParsingBaseSpecifiers(false), HasODRHash(false), Definition(D) {}
 
 CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getBasesSlowCase() const {
   return Bases.get(Definition->getASTContext().getExternalSource());
@@ -94,8 +117,7 @@ CXXRecordDecl::CXXRecordDecl(Kind K, Tag
                              CXXRecordDecl *PrevDecl)
     : RecordDecl(K, TK, C, DC, StartLoc, IdLoc, Id, PrevDecl),
       DefinitionData(PrevDecl ? PrevDecl->DefinitionData
-                              : nullptr),
-      TemplateOrInstantiation() {}
+                              : nullptr) {}
 
 CXXRecordDecl *CXXRecordDecl::Create(const ASTContext &C, TagKind TK,
                                      DeclContext *DC, SourceLocation StartLoc,
@@ -403,7 +425,6 @@ unsigned CXXRecordDecl::getODRHash() con
   return DefinitionData->ODRHash;
 }
 
-
 void CXXRecordDecl::addedClassSubobject(CXXRecordDecl *Subobj) {
   // C++11 [class.copy]p11:
   //   A defaulted copy/move constructor for a class X is defined as
@@ -1590,7 +1611,7 @@ bool CXXRecordDecl::mayBeAbstract() cons
   return false;
 }
 
-void CXXDeductionGuideDecl::anchor() { }
+void CXXDeductionGuideDecl::anchor() {}
 
 CXXDeductionGuideDecl *CXXDeductionGuideDecl::Create(
     ASTContext &C, DeclContext *DC, SourceLocation StartLoc, bool IsExplicit,
@@ -1607,7 +1628,7 @@ CXXDeductionGuideDecl *CXXDeductionGuide
                                            nullptr, SourceLocation());
 }
 
-void CXXMethodDecl::anchor() { }
+void CXXMethodDecl::anchor() {}
 
 bool CXXMethodDecl::isStatic() const {
   const CXXMethodDecl *MD = getCanonicalDecl();
@@ -1954,43 +1975,34 @@ CXXCtorInitializer::CXXCtorInitializer(A
                                        SourceLocation L, Expr *Init,
                                        SourceLocation R,
                                        SourceLocation EllipsisLoc)
-  : Initializee(TInfo), MemberOrEllipsisLocation(EllipsisLoc), Init(Init), 
-    LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(IsVirtual), 
-    IsWritten(false), SourceOrder(0)
-{
-}
+    : Initializee(TInfo), MemberOrEllipsisLocation(EllipsisLoc), Init(Init),
+      LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(IsVirtual),
+      IsWritten(false), SourceOrder(0) {}
 
 CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context,
                                        FieldDecl *Member,
                                        SourceLocation MemberLoc,
                                        SourceLocation L, Expr *Init,
                                        SourceLocation R)
-  : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init),
-    LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
-    IsWritten(false), SourceOrder(0)
-{
-}
+    : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init),
+      LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
+      IsWritten(false), SourceOrder(0) {}
 
 CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context,
                                        IndirectFieldDecl *Member,
                                        SourceLocation MemberLoc,
                                        SourceLocation L, Expr *Init,
                                        SourceLocation R)
-  : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init),
-    LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
-    IsWritten(false), SourceOrder(0)
-{
-}
+    : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init),
+      LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
+      IsWritten(false), SourceOrder(0) {}
 
 CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context,
                                        TypeSourceInfo *TInfo,
                                        SourceLocation L, Expr *Init, 
                                        SourceLocation R)
-  : Initializee(TInfo), MemberOrEllipsisLocation(), Init(Init),
-    LParenLoc(L), RParenLoc(R), IsDelegating(true), IsVirtual(false),
-    IsWritten(false), SourceOrder(0)
-{
-}
+    : Initializee(TInfo), Init(Init), LParenLoc(L), RParenLoc(R),
+      IsDelegating(true), IsVirtual(false), IsWritten(false), SourceOrder(0) {}
 
 TypeLoc CXXCtorInitializer::getBaseClassLoc() const {
   if (isBaseInitializer())
@@ -2030,7 +2042,7 @@ SourceRange CXXCtorInitializer::getSourc
   return SourceRange(getSourceLocation(), getRParenLoc());
 }
 
-void CXXConstructorDecl::anchor() { }
+void CXXConstructorDecl::anchor() {}
 
 CXXConstructorDecl *CXXConstructorDecl::CreateDeserialized(ASTContext &C,
                                                            unsigned ID,
@@ -2173,7 +2185,7 @@ bool CXXConstructorDecl::isSpecializatio
   return true;  
 }
 
-void CXXDestructorDecl::anchor() { }
+void CXXDestructorDecl::anchor() {}
 
 CXXDestructorDecl *
 CXXDestructorDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
@@ -2205,7 +2217,7 @@ void CXXDestructorDecl::setOperatorDelet
   }
 }
 
-void CXXConversionDecl::anchor() { }
+void CXXConversionDecl::anchor() {}
 
 CXXConversionDecl *
 CXXConversionDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
@@ -2235,7 +2247,7 @@ bool CXXConversionDecl::isLambdaToBlockP
          getConversionType()->isBlockPointerType();
 }
 
-void LinkageSpecDecl::anchor() { }
+void LinkageSpecDecl::anchor() {}
 
 LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C,
                                          DeclContext *DC,
@@ -2252,7 +2264,7 @@ LinkageSpecDecl *LinkageSpecDecl::Create
                                      SourceLocation(), lang_c, false);
 }
 
-void UsingDirectiveDecl::anchor() { }
+void UsingDirectiveDecl::anchor() {}
 
 UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC,
                                                SourceLocation L,
@@ -2286,7 +2298,7 @@ NamespaceDecl::NamespaceDecl(ASTContext
                              SourceLocation StartLoc, SourceLocation IdLoc,
                              IdentifierInfo *Id, NamespaceDecl *PrevDecl)
     : NamedDecl(Namespace, DC, IdLoc, Id), DeclContext(Namespace),
-      redeclarable_base(C), LocStart(StartLoc), RBraceLoc(),
+      redeclarable_base(C), LocStart(StartLoc),
       AnonOrFirstNamespaceAndInline(nullptr, Inline) {
   setPreviousDecl(PrevDecl);
 
@@ -2326,21 +2338,25 @@ bool NamespaceDecl::isOriginalNamespace(
 NamespaceDecl *NamespaceDecl::getNextRedeclarationImpl() {
   return getNextRedeclaration();
 }
+
 NamespaceDecl *NamespaceDecl::getPreviousDeclImpl() {
   return getPreviousDecl();
 }
+
 NamespaceDecl *NamespaceDecl::getMostRecentDeclImpl() {
   return getMostRecentDecl();
 }
 
-void NamespaceAliasDecl::anchor() { }
+void NamespaceAliasDecl::anchor() {}
 
 NamespaceAliasDecl *NamespaceAliasDecl::getNextRedeclarationImpl() {
   return getNextRedeclaration();
 }
+
 NamespaceAliasDecl *NamespaceAliasDecl::getPreviousDeclImpl() {
   return getPreviousDecl();
 }
+
 NamespaceAliasDecl *NamespaceAliasDecl::getMostRecentDeclImpl() {
   return getMostRecentDecl();
 }
@@ -2367,7 +2383,7 @@ NamespaceAliasDecl::CreateDeserialized(A
                                         SourceLocation(), nullptr);
 }
 
-void UsingShadowDecl::anchor() { }
+void UsingShadowDecl::anchor() {}
 
 UsingShadowDecl::UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC,
                                  SourceLocation Loc, UsingDecl *Using,
@@ -2382,7 +2398,7 @@ UsingShadowDecl::UsingShadowDecl(Kind K,
 
 UsingShadowDecl::UsingShadowDecl(Kind K, ASTContext &C, EmptyShell Empty)
     : NamedDecl(K, nullptr, SourceLocation(), DeclarationName()),
-      redeclarable_base(C), Underlying(), UsingOrNextShadow() {}
+      redeclarable_base(C) {}
 
 UsingShadowDecl *
 UsingShadowDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
@@ -2397,7 +2413,7 @@ UsingDecl *UsingShadowDecl::getUsingDecl
   return cast<UsingDecl>(Shadow->UsingOrNextShadow);
 }
 
-void ConstructorUsingShadowDecl::anchor() { }
+void ConstructorUsingShadowDecl::anchor() {}
 
 ConstructorUsingShadowDecl *
 ConstructorUsingShadowDecl::Create(ASTContext &C, DeclContext *DC,
@@ -2416,7 +2432,7 @@ CXXRecordDecl *ConstructorUsingShadowDec
   return getUsingDecl()->getQualifier()->getAsRecordDecl();
 }
 
-void UsingDecl::anchor() { }
+void UsingDecl::anchor() {}
 
 void UsingDecl::addShadowDecl(UsingShadowDecl *S) {
   assert(std::find(shadow_begin(), shadow_end(), S) == shadow_end() &&
@@ -2468,7 +2484,7 @@ SourceRange UsingDecl::getSourceRange()
   return SourceRange(Begin, getNameInfo().getEndLoc());
 }
 
-void UsingPackDecl::anchor() { }
+void UsingPackDecl::anchor() {}
 
 UsingPackDecl *UsingPackDecl::Create(ASTContext &C, DeclContext *DC,
                                      NamedDecl *InstantiatedFrom,
@@ -2488,7 +2504,7 @@ UsingPackDecl *UsingPackDecl::CreateDese
   return Result;
 }
 
-void UnresolvedUsingValueDecl::anchor() { }
+void UnresolvedUsingValueDecl::anchor() {}
 
 UnresolvedUsingValueDecl *
 UnresolvedUsingValueDecl::Create(ASTContext &C, DeclContext *DC,
@@ -2516,7 +2532,7 @@ SourceRange UnresolvedUsingValueDecl::ge
   return SourceRange(Begin, getNameInfo().getEndLoc());
 }
 
-void UnresolvedUsingTypenameDecl::anchor() { }
+void UnresolvedUsingTypenameDecl::anchor() {}
 
 UnresolvedUsingTypenameDecl *
 UnresolvedUsingTypenameDecl::Create(ASTContext &C, DeclContext *DC,
@@ -2538,7 +2554,7 @@ UnresolvedUsingTypenameDecl::CreateDeser
       SourceLocation(), nullptr, SourceLocation());
 }
 
-void StaticAssertDecl::anchor() { }
+void StaticAssertDecl::anchor() {}
 
 StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC,
                                            SourceLocation StaticAssertLoc,




More information about the cfe-commits mailing list