cmRST: Fix crash on empty markup block
diff --git a/Source/cmRST.cxx b/Source/cmRST.cxx
index b7216b0..2064275 100644
--- a/Source/cmRST.cxx
+++ b/Source/cmRST.cxx
@@ -457,6 +457,12 @@
   size_t trailingEmpty =
     std::distance(rit, cmFindNot(cmReverseRange(lines), std::string()));
 
+  if ((leadingEmpty + trailingEmpty) >= lines.size()) {
+    // All lines are empty.  The markup block is empty.  Leave only one.
+    lines.resize(1);
+    return;
+  }
+
   std::vector<std::string>::iterator contentEnd = cmRotate(
     lines.begin(), lines.begin() + leadingEmpty, lines.end() - trailingEmpty);
   lines.erase(contentEnd, lines.end());
diff --git a/Tests/CMakeLib/testRST.expect b/Tests/CMakeLib/testRST.expect
index d7b91d1..c19ee94 100644
--- a/Tests/CMakeLib/testRST.expect
+++ b/Tests/CMakeLib/testRST.expect
@@ -83,6 +83,10 @@
 but not after a line ending in two colons::
 in the middle of a paragraph.
 
+A literal block can be empty::
+
+
+
 .. productionlist::
  grammar: `production`
  production: "content rendered"
diff --git a/Tests/CMakeLib/testRST.rst b/Tests/CMakeLib/testRST.rst
index 633219f..d2d1140 100644
--- a/Tests/CMakeLib/testRST.rst
+++ b/Tests/CMakeLib/testRST.rst
@@ -90,6 +90,10 @@
 but not after a line ending in two colons::
 in the middle of a paragraph.
 
+A literal block can be empty::
+
+
+
 .. productionlist::
  grammar: `production`
  production: "content rendered"