Skip to content

Commit

Permalink
[clang-format] Revert breaking stream operators to previous default (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
owenca committed Apr 18, 2024
1 parent 0ee260e commit 29ecd6d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 26 deletions.
8 changes: 2 additions & 6 deletions clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5595,12 +5595,8 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
return true;
if (Left.IsUnterminatedLiteral)
return true;
// FIXME: Breaking after newlines seems useful in general. Turn this into an
// option and recognize more cases like endl etc, and break independent of
// what comes after operator lessless.
if (Right.is(tok::lessless) && Right.Next &&
Right.Next->is(tok::string_literal) && Left.is(tok::string_literal) &&
Left.TokenText.ends_with("\\n\"")) {
if (Right.is(tok::lessless) && Right.Next && Left.is(tok::string_literal) &&
Right.Next->is(tok::string_literal)) {
return true;
}
if (Right.is(TT_RequiresClause)) {
Expand Down
7 changes: 1 addition & 6 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27339,12 +27339,6 @@ TEST_F(FormatTest, PPDirectivesAndCommentsInBracedInit) {
getLLVMStyleWithColumns(30));
}

TEST_F(FormatTest, StreamOutputOperator) {
verifyFormat("std::cout << \"foo\" << \"bar\" << baz;");
verifyFormat("std::cout << \"foo\\n\"\n"
" << \"bar\";");
}

TEST_F(FormatTest, BreakAdjacentStringLiterals) {
constexpr StringRef Code{
"return \"Code\" \"\\0\\52\\26\\55\\55\\0\" \"x013\" \"\\02\\xBA\";"};
Expand All @@ -27359,6 +27353,7 @@ TEST_F(FormatTest, BreakAdjacentStringLiterals) {
Style.BreakAdjacentStringLiterals = false;
verifyFormat(Code, Style);
}

} // namespace
} // namespace test
} // namespace format
Expand Down
9 changes: 0 additions & 9 deletions clang/unittests/Format/TokenAnnotatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2841,15 +2841,6 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
EXPECT_BRACE_KIND(Tokens[16], BK_BracedInit);
}

TEST_F(TokenAnnotatorTest, StreamOperator) {
auto Tokens = annotate("\"foo\\n\" << aux << \"foo\\n\" << \"foo\";");
ASSERT_EQ(Tokens.size(), 9u) << Tokens;
EXPECT_FALSE(Tokens[1]->MustBreakBefore);
EXPECT_FALSE(Tokens[3]->MustBreakBefore);
// Only break between string literals if the former ends with \n.
EXPECT_TRUE(Tokens[5]->MustBreakBefore);
}

TEST_F(TokenAnnotatorTest, UnderstandsElaboratedTypeSpecifier) {
auto Tokens = annotate("auto foo() -> enum En {}");
ASSERT_EQ(Tokens.size(), 10u) << Tokens;
Expand Down
4 changes: 2 additions & 2 deletions polly/lib/Analysis/DependenceInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,8 +951,8 @@ class DependenceInfoPrinterLegacyPass final : public ScopPass {
bool runOnScop(Scop &S) override {
DependenceInfo &P = getAnalysis<DependenceInfo>();

OS << "Printing analysis '" << P.getPassName() << "' for " << "region: '"
<< S.getRegion().getNameStr() << "' in function '"
OS << "Printing analysis '" << P.getPassName() << "' for "
<< "region: '" << S.getRegion().getNameStr() << "' in function '"
<< S.getFunction().getName() << "':\n";
P.printScop(OS, S);

Expand Down
7 changes: 4 additions & 3 deletions polly/lib/Analysis/ScopBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2715,9 +2715,10 @@ void ScopBuilder::addUserContext() {
if (NameContext != NameUserContext) {
std::string SpaceStr = stringFromIslObj(Space, "null");
errs() << "Error: the name of dimension " << i
<< " provided in -polly-context " << "is '" << NameUserContext
<< "', but the name in the computed " << "context is '"
<< NameContext << "'. Due to this name mismatch, "
<< " provided in -polly-context "
<< "is '" << NameUserContext << "', but the name in the computed "
<< "context is '" << NameContext
<< "'. Due to this name mismatch, "
<< "the -polly-context option is ignored. Please provide "
<< "the context in the parameter space: " << SpaceStr << ".\n";
return;
Expand Down

0 comments on commit 29ecd6d

Please sign in to comment.