forked from OSchip/llvm-project
[Format] Don't treat compound extension headers (foo.proto.h) as foo.cc main-file header.
We receive internal bugs about this false positives after D86597. Differential Revision: https://reviews.llvm.org/D88640.
This commit is contained in:
parent
ba9b15072c
commit
c1b209cc61
|
@ -233,7 +233,12 @@ int IncludeCategoryManager::getSortIncludePriority(StringRef IncludeName,
|
|||
bool IncludeCategoryManager::isMainHeader(StringRef IncludeName) const {
|
||||
if (!IncludeName.startswith("\""))
|
||||
return false;
|
||||
StringRef HeaderStem = matchingStem(IncludeName.drop_front(1).drop_back(1));
|
||||
|
||||
// Not matchingStem: implementation files may have compound extensions but
|
||||
// headers may not.
|
||||
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,
|
||||
|
|
|
@ -151,6 +151,16 @@ TEST_F(SortIncludesTest, NoReplacementsForValidIncludes) {
|
|||
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"
|
||||
|
|
Loading…
Reference in New Issue