[PATCH] D88640: [Format] Don't treat compound extension headers (foo.proto.h) as foo.cc main file.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 1 02:00:48 PDT 2020
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added a project: clang.
hokein requested review of this revision.
We receive internal bugs about this false positives after D86597 <https://reviews.llvm.org/D86597>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D88640
Files:
clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
clang/unittests/Format/SortIncludesTest.cpp
Index: clang/unittests/Format/SortIncludesTest.cpp
===================================================================
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -151,6 +151,16 @@
EXPECT_TRUE(sortIncludes(FmtStyle, Code, GetCodeRange(Code), "a.cc").empty());
}
+TEST_F(SortIncludesTest, NoMainFileHeader) {
+ std::string Code = "#include <string>\n"
+ "\n"
+ "#include \"a/extra_action.proto.h\"\n";
+ FmtStyle = getGoogleStyle(FormatStyle::LK_Cpp);
+ EXPECT_TRUE(
+ sortIncludes(FmtStyle, Code, GetCodeRange(Code), "a/extra_action.cc")
+ .empty());
+}
+
TEST_F(SortIncludesTest, SortedIncludesInMultipleBlocksAreMerged) {
Style.IncludeBlocks = tooling::IncludeStyle::IBS_Merge;
EXPECT_EQ("#include \"a.h\"\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===================================================================
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -233,7 +233,10 @@
bool IncludeCategoryManager::isMainHeader(StringRef IncludeName) const {
if (!IncludeName.startswith("\""))
return false;
- StringRef HeaderStem = matchingStem(IncludeName.drop_front(1).drop_back(1));
+
+ StringRef HeaderStem =
+ llvm::sys::path::stem(IncludeName.drop_front(1).drop_back(
+ 1) /* remove the surrounding "" or <> */);
if (FileStem.startswith(HeaderStem) ||
FileStem.startswith_lower(HeaderStem)) {
llvm::Regex MainIncludeRegex(HeaderStem.str() + Style.IncludeIsMainRegex,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88640.295494.patch
Type: text/x-patch
Size: 1612 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201001/d00c06c3/attachment-0001.bin>
More information about the cfe-commits
mailing list