[clang-format] Do not format raw string literals inside a recognized function with a non-recognized delimiter

Summary:
This stops clang-format from touching raw string contents with unrecognized delimiters inside recognized functions.
Unrecognized delimiters signal that the string might be special.

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D48728

llvm-svn: 335876
This commit is contained in:
Krasimir Georgiev 2018-06-28 16:58:24 +00:00
parent cefbf9aca1
commit 2d69f5d82e
2 changed files with 27 additions and 1 deletions

View File

@ -1648,7 +1648,7 @@ ContinuationIndenter::getRawStringStyle(const FormatToken &Current,
if (!Delimiter)
return None;
auto RawStringStyle = RawStringFormats.getDelimiterStyle(*Delimiter);
if (!RawStringStyle)
if (!RawStringStyle && Delimiter->empty())
RawStringStyle = RawStringFormats.getEnclosingFunctionStyle(
getEnclosingFunctionName(Current));
if (!RawStringStyle)

View File

@ -862,6 +862,32 @@ int f() {
Style));
}
TEST_F(FormatTestRawStrings,
DoNotFormatUnrecognizedDelimitersInRecognizedFunctions) {
FormatStyle Style = getRawStringPbStyleWithColumns(60);
Style.RawStringFormats[0].EnclosingFunctions.push_back(
"EqualsProto");
// EqualsProto is a recognized function, but the Raw delimiter is
// unrecognized. Do not touch the string in this case, since it might be
// special.
expect_eq(R"test(
void f() {
aaaaaaaaa(bbbbbbbbb, EqualsProto(R"Raw(
item {
key: value
}
)Raw"));
})test",
format(R"test(
void f() {
aaaaaaaaa(bbbbbbbbb, EqualsProto(R"Raw(
item {
key: value
}
)Raw"));
})test",
Style));
}
} // end namespace
} // end namespace format