diff --git a/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp b/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp --- a/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp +++ b/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp @@ -45,8 +45,12 @@ // Objective-C categories have a `+suffix` format, but should be grouped // with the file they are a category of. + size_t start_index = Canonical.find_last_of('/'); + if (start_index == StringRef::npos) { + start_index = 0; + } return Canonical.substr( - 0, Canonical.find_first_of('+', Canonical.find_last_of('/'))); + 0, Canonical.find_first_of('+', start_index)); } return RemoveFirstSuffix( RemoveFirstSuffix(Str, {".cc", ".cpp", ".c", ".h", ".hpp"}),