From cdf35e9aba5a5b25ec24e656ce92bba9d9555a02 Mon Sep 17 00:00:00 2001
From: Richard Smith <richard-llvm@metafoo.co.uk>
Date: Thu, 23 Mar 2017 23:17:58 +0000
Subject: [PATCH] Remove all uses of std::mem_fun and std::bind1st removed in
 C++17.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@298657 91177308-0d34-0410-b5e6-96231b3b80d8
---
 include/clang/AST/DeclContextInternals.h             |  2 +-
 include/clang/AST/DeclObjC.h                         | 12 +++++++-----
 .../StaticAnalyzer/Core/PathSensitive/CallEvent.h    | 12 ++++++------
 lib/CodeGen/CGCall.cpp                               |  2 +-
 lib/Sema/Sema.cpp                                    |  4 +++-
 5 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/include/clang/AST/DeclContextInternals.h b/include/clang/AST/DeclContextInternals.h
index ff37758c255..eb86526e8ec 100644
--- a/include/clang/AST/DeclContextInternals.h
+++ b/include/clang/AST/DeclContextInternals.h
@@ -131,7 +131,7 @@ public:
     } else {
       DeclsTy &Vec = *getAsVector();
       Vec.erase(std::remove_if(Vec.begin(), Vec.end(),
-                               std::mem_fun(&Decl::isFromASTFile)),
+                               [](Decl *D) { return D->isFromASTFile(); }),
                 Vec.end());
       // Don't have any external decls any more.
       Data = DeclsAndHasExternalTy(&Vec, false);
diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h
index c2a09cd88a9..26c0cbe82d1 100644
--- a/include/clang/AST/DeclObjC.h
+++ b/include/clang/AST/DeclObjC.h
@@ -381,15 +381,17 @@ public:
                        ArrayRef<SourceLocation> SelLocs = llvm::None);
 
   // Iterator access to parameter types.
-  typedef std::const_mem_fun_t<QualType, ParmVarDecl> deref_fun;
-  typedef llvm::mapped_iterator<param_const_iterator, deref_fun>
-  param_type_iterator;
+  struct GetTypeFn {
+    QualType operator()(const ParmVarDecl *PD) const { return PD->getType(); }
+  };
+  typedef llvm::mapped_iterator<param_const_iterator, GetTypeFn>
+      param_type_iterator;
 
   param_type_iterator param_type_begin() const {
-    return llvm::map_iterator(param_begin(), deref_fun(&ParmVarDecl::getType));
+    return llvm::map_iterator(param_begin(), GetTypeFn());
   }
   param_type_iterator param_type_end() const {
-    return llvm::map_iterator(param_end(), deref_fun(&ParmVarDecl::getType));
+    return llvm::map_iterator(param_end(), GetTypeFn());
   }
 
   /// createImplicitParams - Used to lazily create the self and cmd
diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h b/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
index aaecf38f333..fa7ee62ab70 100644
--- a/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
+++ b/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
@@ -383,7 +383,9 @@ public:
 
   // Iterator access to formal parameters and their types.
 private:
-  typedef std::const_mem_fun_t<QualType, ParmVarDecl> get_type_fun;
+  struct GetTypeFn {
+    QualType operator()(ParmVarDecl *PD) const { return PD->getType(); }
+  };
 
 public:
   /// Return call's formal parameters.
@@ -393,7 +395,7 @@ public:
   /// correspond with the argument value returned by \c getArgSVal(0).
   virtual ArrayRef<ParmVarDecl*> parameters() const = 0;
 
-  typedef llvm::mapped_iterator<ArrayRef<ParmVarDecl*>::iterator, get_type_fun>
+  typedef llvm::mapped_iterator<ArrayRef<ParmVarDecl*>::iterator, GetTypeFn>
     param_type_iterator;
 
   /// Returns an iterator over the types of the call's formal parameters.
@@ -402,13 +404,11 @@ public:
   /// definition because it represents a public interface, and probably has
   /// more annotations.
   param_type_iterator param_type_begin() const {
-    return llvm::map_iterator(parameters().begin(),
-                              get_type_fun(&ParmVarDecl::getType));
+    return llvm::map_iterator(parameters().begin(), GetTypeFn());
   }
   /// \sa param_type_begin()
   param_type_iterator param_type_end() const {
-    return llvm::map_iterator(parameters().end(),
-                              get_type_fun(&ParmVarDecl::getType));
+    return llvm::map_iterator(parameters().end(), GetTypeFn());
   }
 
   // For debugging purposes only
diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp
index e56fe2c1c1d..7e8d5161808 100644
--- a/lib/CodeGen/CGCall.cpp
+++ b/lib/CodeGen/CGCall.cpp
@@ -719,7 +719,7 @@ CodeGenTypes::arrangeLLVMFunctionInfo(CanQualType resultType,
                      ArrayRef<FunctionProtoType::ExtParameterInfo> paramInfos,
                                       RequiredArgs required) {
   assert(std::all_of(argTypes.begin(), argTypes.end(),
-                     std::mem_fun_ref(&CanQualType::isCanonicalAsParam)));
+                     [](CanQualType T) { return T.isCanonicalAsParam(); }));
 
   // Lookup or create unique function info.
   llvm::FoldingSetNodeID ID;
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index 1677d340fb3..057e43f211a 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -744,7 +744,9 @@ void Sema::ActOnEndOfTranslationUnit() {
   UnusedFileScopedDecls.erase(
       std::remove_if(UnusedFileScopedDecls.begin(nullptr, true),
                      UnusedFileScopedDecls.end(),
-                     std::bind1st(std::ptr_fun(ShouldRemoveFromUnused), this)),
+                     [this](const DeclaratorDecl *DD) {
+                       return ShouldRemoveFromUnused(this, DD);
+                     }),
       UnusedFileScopedDecls.end());
 
   if (TUKind == TU_Prefix) {
-- 
GitLab