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

llvm-svn: 329766
diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp
index b8a837f..eb2e8c5 100644
--- a/clang/lib/AST/ExprCXX.cpp
+++ b/clang/lib/AST/ExprCXX.cpp
@@ -181,7 +181,7 @@
   // For a destroying operator delete, we may have implicitly converted the
   // pointer type to the type of the parameter of the 'operator delete'
   // function.
-  while (auto *ICE = dyn_cast<ImplicitCastExpr>(Arg)) {
+  while (const auto *ICE = dyn_cast<ImplicitCastExpr>(Arg)) {
     if (ICE->getCastKind() == CK_DerivedToBase ||
         ICE->getCastKind() == CK_UncheckedDerivedToBase ||
         ICE->getCastKind() == CK_NoOp) {
@@ -290,7 +290,7 @@
       totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
           HasTemplateKWAndArgsInfo, NumTemplateArgs);
   void *Mem = C.Allocate(Size, alignof(UnresolvedLookupExpr));
-  UnresolvedLookupExpr *E = new (Mem) UnresolvedLookupExpr(EmptyShell());
+  auto *E = new (Mem) UnresolvedLookupExpr(EmptyShell());
   E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
   return E;
 }
@@ -442,8 +442,8 @@
       totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
           HasTemplateKWAndArgsInfo, NumTemplateArgs);
   void *Mem = C.Allocate(Size);
-  DependentScopeDeclRefExpr *E
-    = new (Mem) DependentScopeDeclRefExpr(QualType(), NestedNameSpecifierLoc(),
+  auto *E =
+      new (Mem) DependentScopeDeclRefExpr(QualType(), NestedNameSpecifierLoc(),
                                           SourceLocation(),
                                           DeclarationNameInfo(), nullptr);
   E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
@@ -504,9 +504,9 @@
 
 Expr *CXXMemberCallExpr::getImplicitObjectArgument() const {
   const Expr *Callee = getCallee()->IgnoreParens();
-  if (const MemberExpr *MemExpr = dyn_cast<MemberExpr>(Callee))
+  if (const auto *MemExpr = dyn_cast<MemberExpr>(Callee))
     return MemExpr->getBase();
-  if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(Callee))
+  if (const auto *BO = dyn_cast<BinaryOperator>(Callee))
     if (BO->getOpcode() == BO_PtrMemD || BO->getOpcode() == BO_PtrMemI)
       return BO->getLHS();
 
@@ -515,8 +515,7 @@
 }
 
 CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const {
-  if (const MemberExpr *MemExpr = 
-      dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
+  if (const auto *MemExpr = dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
     return cast<CXXMethodDecl>(MemExpr->getMemberDecl());
 
   // FIXME: Will eventually need to cope with member pointers.
@@ -561,9 +560,9 @@
                                              SourceRange AngleBrackets) {
   unsigned PathSize = (BasePath ? BasePath->size() : 0);
   void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
-  CXXStaticCastExpr *E =
-    new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
-                                   RParenLoc, AngleBrackets);
+  auto *E =
+      new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
+                                     RParenLoc, AngleBrackets);
   if (PathSize)
     std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
                               E->getTrailingObjects<CXXBaseSpecifier *>());
@@ -586,9 +585,9 @@
                                                SourceRange AngleBrackets) {
   unsigned PathSize = (BasePath ? BasePath->size() : 0);
   void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
-  CXXDynamicCastExpr *E =
-    new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
-                                    RParenLoc, AngleBrackets);
+  auto *E =
+      new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
+                                      RParenLoc, AngleBrackets);
   if (PathSize)
     std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
                               E->getTrailingObjects<CXXBaseSpecifier *>());
@@ -614,7 +613,7 @@
   QualType SrcType = getSubExpr()->getType();
   QualType DestType = getType();
 
-  if (const PointerType *SrcPTy = SrcType->getAs<PointerType>()) {
+  if (const auto *SrcPTy = SrcType->getAs<PointerType>()) {
     SrcType = SrcPTy->getPointeeType();
     DestType = DestType->castAs<PointerType>()->getPointeeType();
   }
@@ -622,14 +621,14 @@
   if (DestType->isVoidType())
     return false;
 
-  const CXXRecordDecl *SrcRD = 
-    cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl());
+  const auto *SrcRD =
+      cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl());
 
   if (!SrcRD->hasAttr<FinalAttr>())
     return false;
 
-  const CXXRecordDecl *DestRD = 
-    cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl());
+  const auto *DestRD =
+      cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl());
 
   return !DestRD->isDerivedFrom(SrcRD);
 }
@@ -643,9 +642,9 @@
                                SourceRange AngleBrackets) {
   unsigned PathSize = (BasePath ? BasePath->size() : 0);
   void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
-  CXXReinterpretCastExpr *E =
-    new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
-                                        RParenLoc, AngleBrackets);
+  auto *E =
+      new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
+                                          RParenLoc, AngleBrackets);
   if (PathSize)
     std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
                               E->getTrailingObjects<CXXBaseSpecifier *>());
@@ -678,8 +677,8 @@
                               SourceLocation L, SourceLocation R) {
   unsigned PathSize = (BasePath ? BasePath->size() : 0);
   void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
-  CXXFunctionalCastExpr *E =
-    new (Buffer) CXXFunctionalCastExpr(T, VK, Written, K, Op, PathSize, L, R);
+  auto *E =
+      new (Buffer) CXXFunctionalCastExpr(T, VK, Written, K, Op, PathSize, L, R);
   if (PathSize)
     std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
                               E->getTrailingObjects<CXXBaseSpecifier *>());
@@ -1079,7 +1078,7 @@
            true, true, Type->getType()->containsUnexpandedParameterPack()),
       Type(Type), LParenLoc(LParenLoc), RParenLoc(RParenLoc),
       NumArgs(Args.size()) {
-  Expr **StoredArgs = getTrailingObjects<Expr *>();
+  auto **StoredArgs = getTrailingObjects<Expr *>();
   for (unsigned I = 0; I != Args.size(); ++I) {
     if (Args[I]->containsUnexpandedParameterPack())
       ExprBits.ContainsUnexpandedParameterPack = true;
@@ -1176,12 +1175,12 @@
       totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
           HasTemplateKWAndArgsInfo, NumTemplateArgs);
   void *Mem = C.Allocate(Size, alignof(CXXDependentScopeMemberExpr));
-  CXXDependentScopeMemberExpr *E
-    =  new (Mem) CXXDependentScopeMemberExpr(C, nullptr, QualType(),
-                                             false, SourceLocation(),
-                                             NestedNameSpecifierLoc(),
-                                             SourceLocation(), nullptr,
-                                             DeclarationNameInfo(), nullptr);
+  auto *E =
+      new (Mem) CXXDependentScopeMemberExpr(C, nullptr, QualType(),
+                                            false, SourceLocation(),
+                                            NestedNameSpecifierLoc(),
+                                            SourceLocation(), nullptr,
+                                            DeclarationNameInfo(), nullptr);
   E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
   return E;
 }
@@ -1274,7 +1273,7 @@
           HasTemplateKWAndArgsInfo, NumTemplateArgs);
 
   void *Mem = C.Allocate(Size, alignof(UnresolvedMemberExpr));
-  UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell());
+  auto *E = new (Mem) UnresolvedMemberExpr(EmptyShell());
   E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
   return E;
 }
@@ -1297,7 +1296,7 @@
   else {
     QualType BaseType = getBaseType().getNonReferenceType();
     if (isArrow()) {
-      const PointerType *PT = BaseType->getAs<PointerType>();
+      const auto *PT = BaseType->getAs<PointerType>();
       assert(PT && "base of arrow member access is not pointer");
       BaseType = PT->getPointeeType();
     }
@@ -1379,7 +1378,7 @@
   // We may need to allocate extra storage for the mangling number and the
   // extended-by ValueDecl.
   if (!State.is<ExtraState *>()) {
-    auto ES = new (ExtendedBy->getASTContext()) ExtraState;
+    auto *ES = new (ExtendedBy->getASTContext()) ExtraState;
     ES->Temporary = State.get<Stmt *>();
     State = ES;
   }
@@ -1403,7 +1402,7 @@
   TypeTraitExprBits.Value = Value;
   TypeTraitExprBits.NumArgs = Args.size();
 
-  TypeSourceInfo **ToArgs = getTrailingObjects<TypeSourceInfo *>();
+  auto **ToArgs = getTrailingObjects<TypeSourceInfo *>();
 
   for (unsigned I = 0, N = Args.size(); I != N; ++I) {
     if (Args[I]->getType()->isDependentType())