diff --git a/lib/Sema/SemaCUDA.cpp b/lib/Sema/SemaCUDA.cpp
index 7e201f4dae672f8baae9040437440bb159eff2bc..90af6d5a927ff40ccc803c85dd22773c74730415 100644
--- a/lib/Sema/SemaCUDA.cpp
+++ b/lib/Sema/SemaCUDA.cpp
@@ -163,8 +163,10 @@ static void EraseUnwantedCUDAMatchesImpl(
       [&](const T &M1, const T &M2) { return GetCFP(M1) < GetCFP(M2); }));
 
   // Erase all functions with lower priority.
-  Matches.erase(llvm::remove_if(
-      Matches, [&](const T &Match) { return GetCFP(Match) < BestCFP; }));
+  Matches.erase(
+      llvm::remove_if(Matches,
+                      [&](const T &Match) { return GetCFP(Match) < BestCFP; }),
+      Matches.end());
 }
 
 void Sema::EraseUnwantedCUDAMatches(const FunctionDecl *Caller,