<div dir="ltr">The previous code didn't have a conditional for Iter != End - was that a bug? Should there be a test case for that bug?<br><br>If that's not an actual change in behavior, could it be an assert instead of a condition?</div><br><div class="gmail_quote"><div dir="ltr">On Tue, Nov 6, 2018 at 1:14 PM Aaron Ballman via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: aaronballman<br>
Date: Tue Nov  6 13:12:44 2018<br>
New Revision: 346266<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=346266&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=346266&view=rev</a><br>
Log:<br>
Don't use std::next() on an input iterator; NFC.<br>
<br>
Instead, advance the old-fashioned way, as std::next() cannot be used on an input iterator until C++17.<br>
<br>
Modified:<br>
    cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp<br>
<br>
Modified: cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp?rev=346266&r1=346265&r2=346266&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp?rev=346266&r1=346265&r2=346266&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp (original)<br>
+++ cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp Tue Nov  6 13:12:44 2018<br>
@@ -82,25 +82,27 @@ static std::string fileNameToURI(StringR<br>
     Ret += Twine("/" + Root).str();<br>
   }<br>
<br>
-  // Add the rest of the path components, encoding any reserved characters.<br>
-  std::for_each(std::next(sys::path::begin(Filename)), sys::path::end(Filename),<br>
-                [&Ret](StringRef Component) {<br>
-                  // For reasons unknown to me, we may get a backslash with<br>
-                  // Windows native paths for the initial backslash following<br>
-                  // the drive component, which we need to ignore as a URI path<br>
-                  // part.<br>
-                  if (Component == "\\")<br>
-                    return;<br>
+  auto Iter = sys::path::begin(Filename), End = sys::path::end(Filename);<br>
+  if (Iter != End) {<br>
+    // Add the rest of the path components, encoding any reserved characters;<br>
+    // we skip past the first path component, as it was handled it above.<br>
+    std::for_each(++Iter, End, [&Ret](StringRef Component) {<br>
+      // For reasons unknown to me, we may get a backslash with Windows native<br>
+      // paths for the initial backslash following the drive component, which<br>
+      // we need to ignore as a URI path part.<br>
+      if (Component == "\\")<br>
+        return;<br>
<br>
-                  // Add the separator between the previous path part and the<br>
-                  // one being currently processed.<br>
-                  Ret += "/";<br>
+      // Add the separator between the previous path part and the one being<br>
+      // currently processed.<br>
+      Ret += "/";<br>
<br>
-                  // URI encode the part.<br>
-                  for (char C : Component) {<br>
-                    Ret += percentEncodeURICharacter(C);<br>
-                  }<br>
-                });<br>
+      // URI encode the part.<br>
+      for (char C : Component) {<br>
+        Ret += percentEncodeURICharacter(C);<br>
+      }<br>
+    });<br>
+  }<br>
<br>
   return Ret.str().str();<br>
 }<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>