MyDeveloperDay created this revision. MyDeveloperDay added reviewers: krasimir, sammccall, klimek, curdeius, JakeMerdichAMD, Abpostelnicu. MyDeveloperDay added projects: clang, clang-format. Herald added a reviewer: bollu.
https://bugs.llvm.org/show_bug.cgi?id=44542 https://bugs.llvm.org/show_bug.cgi?id=38872 (I'm sure I've seen others) Users really don't like clang-format going off on one and breaking lines without their control, this piece of code which I'm removing dates all the way back to 2013, I think it was added because it people think os << "from" << "asdf" << "def" << "ghi" << "ghi"; is more pleasing.. however, when you start using other types, then this just becomes crazy... and leaves the user wondering why. (see bugs for other odd cases) os << "from" << "def" << 1 << "ghi" << "lmn" << "opq" << endl << "abc" << "ghi"; The rules I'm removing was to FORCE (MustBreak) a line break between `"<String>" << "<String>"` but not between `"<String>" << AnyOtherType` or `AnyOtherType << "<String>"` This might be considered too much for a change, somehow breaking compatibility but I feel it's wrong and really plays to the contempt people have towards `clang-format` that it goes off and formats things how it wants to without obeying its own line limit rules. This may need a configuration switch as it's likely to cause clang-format changes in already formatted code (as here with UnwrappedLineParser) (Polly also breaks) ...I also noticed no unit tests broke when I made this change... Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D80950 Files: clang/lib/Format/TokenAnnotator.cpp clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -15597,6 +15597,13 @@ "aaaallvm::outs()\n <<"); } +TEST_F(FormatTest, TreatLessLessStringNormally) { + verifyFormat("os << \"from\" << \"asdf\";"); + verifyFormat("os << \"from\" << 1;"); + verifyFormat("os << \"from\" << 1 << \"foo\";"); + verifyFormat("os << \"from\" << 1 << \"foo\" << \"bar\";"); +} + TEST_F(FormatTest, HandleUnbalancedImplicitBracesAcrossPPBranches) { std::string code = "#if A\n" "#if B\n" Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2741,8 +2741,7 @@ for (std::list<UnwrappedLineNode>::const_iterator I = Line.Tokens.begin(), E = Line.Tokens.end(); I != E; ++I) { - llvm::dbgs() << I->Tok->Tok.getName() << "[" - << "T=" << I->Tok->getType() + llvm::dbgs() << I->Tok->Tok.getName() << "[" << "T=" << I->Tok->getType() << ", OC=" << I->Tok->OriginalColumn << "] "; } for (std::list<UnwrappedLineNode>::const_iterator I = Line.Tokens.begin(), Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -3479,10 +3479,6 @@ return true; if (Right.Previous->IsUnterminatedLiteral) return true; - if (Right.is(tok::lessless) && Right.Next && - Right.Previous->is(tok::string_literal) && - Right.Next->is(tok::string_literal)) - return true; if (Right.Previous->ClosesTemplateDeclaration && Right.Previous->MatchingParen && Right.Previous->MatchingParen->NestingLevel == 0 &&
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -15597,6 +15597,13 @@ "aaaallvm::outs()\n <<"); } +TEST_F(FormatTest, TreatLessLessStringNormally) { + verifyFormat("os << \"from\" << \"asdf\";"); + verifyFormat("os << \"from\" << 1;"); + verifyFormat("os << \"from\" << 1 << \"foo\";"); + verifyFormat("os << \"from\" << 1 << \"foo\" << \"bar\";"); +} + TEST_F(FormatTest, HandleUnbalancedImplicitBracesAcrossPPBranches) { std::string code = "#if A\n" "#if B\n" Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2741,8 +2741,7 @@ for (std::list<UnwrappedLineNode>::const_iterator I = Line.Tokens.begin(), E = Line.Tokens.end(); I != E; ++I) { - llvm::dbgs() << I->Tok->Tok.getName() << "[" - << "T=" << I->Tok->getType() + llvm::dbgs() << I->Tok->Tok.getName() << "[" << "T=" << I->Tok->getType() << ", OC=" << I->Tok->OriginalColumn << "] "; } for (std::list<UnwrappedLineNode>::const_iterator I = Line.Tokens.begin(), Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -3479,10 +3479,6 @@ return true; if (Right.Previous->IsUnterminatedLiteral) return true; - if (Right.is(tok::lessless) && Right.Next && - Right.Previous->is(tok::string_literal) && - Right.Next->is(tok::string_literal)) - return true; if (Right.Previous->ClosesTemplateDeclaration && Right.Previous->MatchingParen && Right.Previous->MatchingParen->NestingLevel == 0 &&
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits