Skip to content

Commit 29ecd6d

Browse files
authored
[clang-format] Revert breaking stream operators to previous default (#89016)
Reverts commit d68826d, which changes the previous default behavior of always breaking before a stream insertion operator `<<` if both operands are string literals. Also reverts the related commits 27f5479 and bf05be5. See the discussion in #88483.
1 parent 0ee260e commit 29ecd6d

File tree

5 files changed

+9
-26
lines changed

5 files changed

+9
-26
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5595,12 +5595,8 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
55955595
return true;
55965596
if (Left.IsUnterminatedLiteral)
55975597
return true;
5598-
// FIXME: Breaking after newlines seems useful in general. Turn this into an
5599-
// option and recognize more cases like endl etc, and break independent of
5600-
// what comes after operator lessless.
5601-
if (Right.is(tok::lessless) && Right.Next &&
5602-
Right.Next->is(tok::string_literal) && Left.is(tok::string_literal) &&
5603-
Left.TokenText.ends_with("\\n\"")) {
5598+
if (Right.is(tok::lessless) && Right.Next && Left.is(tok::string_literal) &&
5599+
Right.Next->is(tok::string_literal)) {
56045600
return true;
56055601
}
56065602
if (Right.is(TT_RequiresClause)) {

clang/unittests/Format/FormatTest.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27339,12 +27339,6 @@ TEST_F(FormatTest, PPDirectivesAndCommentsInBracedInit) {
2733927339
getLLVMStyleWithColumns(30));
2734027340
}
2734127341

27342-
TEST_F(FormatTest, StreamOutputOperator) {
27343-
verifyFormat("std::cout << \"foo\" << \"bar\" << baz;");
27344-
verifyFormat("std::cout << \"foo\\n\"\n"
27345-
" << \"bar\";");
27346-
}
27347-
2734827342
TEST_F(FormatTest, BreakAdjacentStringLiterals) {
2734927343
constexpr StringRef Code{
2735027344
"return \"Code\" \"\\0\\52\\26\\55\\55\\0\" \"x013\" \"\\02\\xBA\";"};
@@ -27359,6 +27353,7 @@ TEST_F(FormatTest, BreakAdjacentStringLiterals) {
2735927353
Style.BreakAdjacentStringLiterals = false;
2736027354
verifyFormat(Code, Style);
2736127355
}
27356+
2736227357
} // namespace
2736327358
} // namespace test
2736427359
} // namespace format

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2841,15 +2841,6 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
28412841
EXPECT_BRACE_KIND(Tokens[16], BK_BracedInit);
28422842
}
28432843

2844-
TEST_F(TokenAnnotatorTest, StreamOperator) {
2845-
auto Tokens = annotate("\"foo\\n\" << aux << \"foo\\n\" << \"foo\";");
2846-
ASSERT_EQ(Tokens.size(), 9u) << Tokens;
2847-
EXPECT_FALSE(Tokens[1]->MustBreakBefore);
2848-
EXPECT_FALSE(Tokens[3]->MustBreakBefore);
2849-
// Only break between string literals if the former ends with \n.
2850-
EXPECT_TRUE(Tokens[5]->MustBreakBefore);
2851-
}
2852-
28532844
TEST_F(TokenAnnotatorTest, UnderstandsElaboratedTypeSpecifier) {
28542845
auto Tokens = annotate("auto foo() -> enum En {}");
28552846
ASSERT_EQ(Tokens.size(), 10u) << Tokens;

polly/lib/Analysis/DependenceInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,8 @@ class DependenceInfoPrinterLegacyPass final : public ScopPass {
951951
bool runOnScop(Scop &S) override {
952952
DependenceInfo &P = getAnalysis<DependenceInfo>();
953953

954-
OS << "Printing analysis '" << P.getPassName() << "' for " << "region: '"
955-
<< S.getRegion().getNameStr() << "' in function '"
954+
OS << "Printing analysis '" << P.getPassName() << "' for "
955+
<< "region: '" << S.getRegion().getNameStr() << "' in function '"
956956
<< S.getFunction().getName() << "':\n";
957957
P.printScop(OS, S);
958958

polly/lib/Analysis/ScopBuilder.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2715,9 +2715,10 @@ void ScopBuilder::addUserContext() {
27152715
if (NameContext != NameUserContext) {
27162716
std::string SpaceStr = stringFromIslObj(Space, "null");
27172717
errs() << "Error: the name of dimension " << i
2718-
<< " provided in -polly-context " << "is '" << NameUserContext
2719-
<< "', but the name in the computed " << "context is '"
2720-
<< NameContext << "'. Due to this name mismatch, "
2718+
<< " provided in -polly-context "
2719+
<< "is '" << NameUserContext << "', but the name in the computed "
2720+
<< "context is '" << NameContext
2721+
<< "'. Due to this name mismatch, "
27212722
<< "the -polly-context option is ignored. Please provide "
27222723
<< "the context in the parameter space: " << SpaceStr << ".\n";
27232724
return;

0 commit comments

Comments
 (0)