summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorKrasimir Georgiev <krasimir@google.com>2019-02-04 09:56:16 +0000
committerKrasimir Georgiev <krasimir@google.com>2019-02-04 09:56:16 +0000
commit20bef459fca6069d5c01d38c5eebf2582930c96f (patch)
tree01cacc65b035973f2a46c33c6cd2308102c12472 /clang/unittests/Format/FormatTest.cpp
parent65970aa24dd32328d00cf6560c21f2c5ff876c2d (diff)
downloadbcm5719-llvm-20bef459fca6069d5c01d38c5eebf2582930c96f.tar.gz
bcm5719-llvm-20bef459fca6069d5c01d38c5eebf2582930c96f.zip
[clang-format] Fix breaking of qualified operator
Summary: From https://bugs.llvm.org/show_bug.cgi?id=40516 ``` $ cat a.cpp const NamespaceName::VeryLongClassName &NamespaceName::VeryLongClassName::myFunction() { // do stuff } const NamespaceName::VeryLongClassName &NamespaceName::VeryLongClassName::operator++() { // do stuff } $ ~/ll/build/opt/bin/clang-format -style=LLVM a.cpp const NamespaceName::VeryLongClassName & NamespaceName::VeryLongClassName::myFunction() { // do stuff } const NamespaceName::VeryLongClassName &NamespaceName::VeryLongClassName:: operator++() { // do stuff } ``` What was happening is that the split penalty before `operator` was being set to a smaller value by a prior if block. Moved checks around to fix this and added a regression test. Reviewers: djasper Reviewed By: djasper Tags: #clang Differential Revision: https://reviews.llvm.org/D57604 llvm-svn: 353033
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r--clang/unittests/Format/FormatTest.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 99b2beadc4a..2b0ef9a9dd5 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -4183,6 +4183,18 @@ TEST_F(FormatTest, BreaksFunctionDeclarations) {
Style);
}
+TEST_F(FormatTest, DontBreakBeforeQualifiedOperator) {
+ // Regression test for https://bugs.llvm.org/show_bug.cgi?id=40516:
+ // Prefer keeping `::` followed by `operator` together.
+ EXPECT_EQ("const aaaa::bbbbbbb &\n"
+ "ccccccccc::operator++() {\n"
+ " stuff();\n"
+ "}",
+ format("const aaaa::bbbbbbb\n"
+ "&ccccccccc::operator++() { stuff(); }",
+ getLLVMStyleWithColumns(40)));
+}
+
TEST_F(FormatTest, TrailingReturnType) {
verifyFormat("auto foo() -> int;\n");
verifyFormat("struct S {\n"
OpenPOWER on IntegriCloud