From: Aaron Ballman Date: Tue, 6 Nov 2018 21:12:44 +0000 (+0000) Subject: Don't use std::next() on an input iterator; NFC. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eb5cc0e34524869507eb693bb4ca5d8855b10656;p=clang Don't use std::next() on an input iterator; NFC. Instead, advance the old-fashioned way, as std::next() cannot be used on an input iterator until C++17. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@346266 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp b/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp index db1550c63f..448faa4a90 100644 --- a/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp +++ b/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp @@ -82,25 +82,27 @@ static std::string fileNameToURI(StringRef Filename) { Ret += Twine("/" + Root).str(); } - // Add the rest of the path components, encoding any reserved characters. - std::for_each(std::next(sys::path::begin(Filename)), sys::path::end(Filename), - [&Ret](StringRef Component) { - // For reasons unknown to me, we may get a backslash with - // Windows native paths for the initial backslash following - // the drive component, which we need to ignore as a URI path - // part. - if (Component == "\\") - return; - - // Add the separator between the previous path part and the - // one being currently processed. - Ret += "/"; - - // URI encode the part. - for (char C : Component) { - Ret += percentEncodeURICharacter(C); - } - }); + auto Iter = sys::path::begin(Filename), End = sys::path::end(Filename); + if (Iter != End) { + // Add the rest of the path components, encoding any reserved characters; + // we skip past the first path component, as it was handled it above. + std::for_each(++Iter, End, [&Ret](StringRef Component) { + // For reasons unknown to me, we may get a backslash with Windows native + // paths for the initial backslash following the drive component, which + // we need to ignore as a URI path part. + if (Component == "\\") + return; + + // Add the separator between the previous path part and the one being + // currently processed. + Ret += "/"; + + // URI encode the part. + for (char C : Component) { + Ret += percentEncodeURICharacter(C); + } + }); + } return Ret.str().str(); }