Author: djasper Date: Tue Dec 20 09:27:46 2016 New Revision: 290177 URL: http://llvm.org/viewvc/llvm-project?rev=290177&view=rev Log: clang-format: Fix bug in understanding string-label&value analysis.
While for <<-operators often used in log statments, a single key value pair is always on the second operator, e.g. llvm::errs() << "aaaaa=" << aaaaa; It is on the first operator for plus- or comma-concatenated strings: string s = "aaaaaaaaaa: " + aaaaaaaa; (the "=" not counting because that's a different operator precedence) Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp cfe/trunk/unittests/Format/FormatTest.cpp Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=290177&r1=290176&r2=290177&view=diff ============================================================================== --- cfe/trunk/lib/Format/TokenAnnotator.cpp (original) +++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Dec 20 09:27:46 2016 @@ -2000,11 +2000,14 @@ unsigned TokenAnnotator::splitPenalty(co if (Left.isOneOf(tok::plus, tok::comma) && Left.Previous && Left.Previous->isLabelString() && - (Left.NextOperator || Left.OperatorIndex != 1)) + (Left.NextOperator || Left.OperatorIndex != 0)) return 100; + if (Right.is(tok::plus) && Left.isLabelString() && + (Right.NextOperator || Right.OperatorIndex != 0)) + return 25; if (Left.is(tok::comma)) return 1; - if (Right.isOneOf(tok::lessless, tok::plus) && Left.isLabelString() && + if (Right.is(tok::lessless) && Left.isLabelString() && (Right.NextOperator || Right.OperatorIndex != 1)) return 25; if (Right.is(tok::lessless)) { Modified: cfe/trunk/unittests/Format/FormatTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=290177&r1=290176&r2=290177&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp (original) +++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Dec 20 09:27:46 2016 @@ -5214,6 +5214,12 @@ TEST_F(FormatTest, KeepStringLabelValueP verifyFormat("string v = StrCat(\"aaaaaaaaaaaaaaaa: \", aaaaaaaaaaaaaaaa,\n" " \"aaaaaaaaaaaaaaaa: \", aaaaaaaaaaaaaaaa,\n" " \"aaaaaaaaaaaaaaaa: \", aaaaaaaaaaaaaaaa);"); + verifyFormat("string v = \"aaaaaaaaaaaaaaaa: \" +\n" + " (aaaa + aaaa);", + getLLVMStyleWithColumns(40)); + verifyFormat("string v = StrCat(\"aaaaaaaaaaaa: \" +\n" + " (aaaaaaa + aaaaa));", + getLLVMStyleWithColumns(40)); } TEST_F(FormatTest, UnderstandsEquals) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits