Merge branch 'mingw32-make-backslash-workaround' into release
diff --git a/Modules/InstallRequiredSystemLibraries.cmake b/Modules/InstallRequiredSystemLibraries.cmake
index 5afb517..d8ede1c 100644
--- a/Modules/InstallRequiredSystemLibraries.cmake
+++ b/Modules/InstallRequiredSystemLibraries.cmake
@@ -172,8 +172,12 @@
     if(NOT CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY)
       set(__install__libs
         "${MSVC${v}_CRT_DIR}/msvcp${v}0.dll"
-        "${MSVC${v}_CRT_DIR}/msvcr${v}0.dll"
         )
+      if(NOT v VERSION_LESS 14)
+        list(APPEND __install__libs "${MSVC${v}_CRT_DIR}/vcruntime${v}0.dll")
+      else()
+        list(APPEND __install__libs "${MSVC${v}_CRT_DIR}/msvcr${v}0.dll")
+      endif()
     else()
       set(__install__libs)
     endif()
@@ -183,8 +187,12 @@
         "${MSVC${v}_REDIST_DIR}/Debug_NonRedist/${CMAKE_MSVC_ARCH}/Microsoft.VC${v}0.DebugCRT")
       set(__install__libs ${__install__libs}
         "${MSVC${v}_CRT_DIR}/msvcp${v}0d.dll"
-        "${MSVC${v}_CRT_DIR}/msvcr${v}0d.dll"
         )
+      if(NOT v VERSION_LESS 14)
+        list(APPEND __install__libs "${MSVC${v}_CRT_DIR}/vcruntime${v}0d.dll")
+      else()
+        list(APPEND __install__libs "${MSVC${v}_CRT_DIR}/msvcr${v}0d.dll")
+      endif()
     endif()
   endmacro()
 
diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx
index f941408..0082b3c 100644
--- a/Source/CTest/cmCTestBuildHandler.cxx
+++ b/Source/CTest/cmCTestBuildHandler.cxx
@@ -67,13 +67,13 @@
   "^CMake Error.*:",
   ":[ \\t]cannot find",
   ":[ \\t]can't find",
-  ": \\*\\*\\* No rule to make target \\[`'].*\\'.  Stop",
+  ": \\*\\*\\* No rule to make target [`'].*\\'.  Stop",
   ": \\*\\*\\* No targets specified and no makefile found",
   ": Invalid loader fixup for symbol",
   ": Invalid fixups exist",
   ": Can't find library for",
   ": internal link edit command failed",
-  ": Unrecognized option \\[`'].*\\'",
+  ": Unrecognized option [`'].*\\'",
   "\", line [0-9]+\\.[0-9]+: [0-9]+-[0-9]+ \\([^WI]\\)",
   "ld: 0706-006 Cannot find or open library file: -l ",
   "ild: \\(argument error\\) can't find library argument ::",
diff --git a/Source/cmFunctionCommand.cxx b/Source/cmFunctionCommand.cxx
index c33048c..4a0efc1 100644
--- a/Source/cmFunctionCommand.cxx
+++ b/Source/cmFunctionCommand.cxx
@@ -94,8 +94,8 @@
     }
 
   // we push a scope on the makefile
-  cmMakefile::LexicalPushPop lexScope(this->Makefile);
   cmMakefile::ScopePushPop varScope(this->Makefile);
+  cmMakefile::LexicalPushPop lexScope(this->Makefile);
   static_cast<void>(varScope);
 
   // Push a weak policy scope which restores the policies recorded at
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index ba914e1..61a175c 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -3284,6 +3284,7 @@
     this->FunctionBlockerBarriers.back();
   while(this->FunctionBlockers.size() > barrier)
     {
+    cmMakefile::LoopBlockPop loopBlockPop(this);
     cmsys::auto_ptr<cmFunctionBlocker> fb(this->FunctionBlockers.back());
     this->FunctionBlockers.pop_back();
     if(reportError)
diff --git a/Tests/RunCMake/Syntax/FunctionUnmatchedForeach-result.txt b/Tests/RunCMake/Syntax/FunctionUnmatchedForeach-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/Syntax/FunctionUnmatchedForeach-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/FunctionUnmatchedForeach-stderr.txt b/Tests/RunCMake/Syntax/FunctionUnmatchedForeach-stderr.txt
new file mode 100644
index 0000000..f4ff709
--- /dev/null
+++ b/Tests/RunCMake/Syntax/FunctionUnmatchedForeach-stderr.txt
@@ -0,0 +1,8 @@
+^CMake Error at FunctionUnmatchedForeach.cmake:[0-9]+ \(f\):
+  A logical block opening on the line
+
+    .*/Tests/RunCMake/Syntax/FunctionUnmatchedForeach.cmake:[0-9]+ \(foreach\)
+
+  is not closed.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/Syntax/FunctionUnmatchedForeach.cmake b/Tests/RunCMake/Syntax/FunctionUnmatchedForeach.cmake
new file mode 100644
index 0000000..ee9c184
--- /dev/null
+++ b/Tests/RunCMake/Syntax/FunctionUnmatchedForeach.cmake
@@ -0,0 +1,5 @@
+function(f)
+  foreach(i 1)
+  #endforeach() # missing
+endfunction()
+f()
diff --git a/Tests/RunCMake/Syntax/MacroUnmatchedForeach-result.txt b/Tests/RunCMake/Syntax/MacroUnmatchedForeach-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/Syntax/MacroUnmatchedForeach-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Syntax/MacroUnmatchedForeach-stderr.txt b/Tests/RunCMake/Syntax/MacroUnmatchedForeach-stderr.txt
new file mode 100644
index 0000000..820cd2e
--- /dev/null
+++ b/Tests/RunCMake/Syntax/MacroUnmatchedForeach-stderr.txt
@@ -0,0 +1,8 @@
+^CMake Error at MacroUnmatchedForeach.cmake:[0-9]+ \(m\):
+  A logical block opening on the line
+
+    .*/Tests/RunCMake/Syntax/MacroUnmatchedForeach.cmake:[0-9]+ \(foreach\)
+
+  is not closed.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/Syntax/MacroUnmatchedForeach.cmake b/Tests/RunCMake/Syntax/MacroUnmatchedForeach.cmake
new file mode 100644
index 0000000..be443dd
--- /dev/null
+++ b/Tests/RunCMake/Syntax/MacroUnmatchedForeach.cmake
@@ -0,0 +1,5 @@
+macro(m)
+  foreach(i 1)
+  #endforeach() # missing
+endmacro()
+m()
diff --git a/Tests/RunCMake/Syntax/RunCMakeTest.cmake b/Tests/RunCMake/Syntax/RunCMakeTest.cmake
index cecd338..c431280 100644
--- a/Tests/RunCMake/Syntax/RunCMakeTest.cmake
+++ b/Tests/RunCMake/Syntax/RunCMakeTest.cmake
@@ -108,3 +108,7 @@
 run_cmake(CMP0053-NameWithCarriageReturnQuoted)
 run_cmake(CMP0053-NameWithEscapedSpacesQuoted)
 run_cmake(CMP0053-NameWithEscapedTabsQuoted)
+
+# Function and macro tests.
+run_cmake(FunctionUnmatchedForeach)
+run_cmake(MacroUnmatchedForeach)